1 /*******************************************************************
\r
5 * Author: Peter van Sebille (peter@yipton.net)
\r
7 * Modified/adapted for picodriveN by notaz, 2006
\r
9 * (c) Copyright 2006, notaz
\r
10 * (c) Copyright 2002, Peter van Sebille
\r
11 * All Rights Reserved
\r
13 *******************************************************************/
\r
16 // #include "picodriven.mbg" // bitmap identifiers
\r
17 #include "rsc/picodrive.rsg" // resource include
\r
19 #include <qbtselectdlg.h>
\r
20 //#include <gulutil.h>
\r
21 //#include <bautils.h>
\r
22 //#include <eikmenub.h> // CEikMenuBar
\r
23 #include <apgtask.h> // TApaSystemEvent
\r
24 #include <eikstart.h>
\r
25 #include <eikedwin.h>
\r
26 #include <s32strm.h>
\r
28 #include <qikappui.h>
\r
29 #include <qikeditcategoryobserver.h>
\r
30 #include <qikselectfiledlg.h>
\r
31 #include <qikcommand.h>
\r
33 #include "Dialogs.h"
\r
34 #include "engine/debug.h"
\r
35 #include "../common/emu.h"
\r
39 ////////////////////////////////////////////////////////////////
\r
41 // class CPicolAppView
\r
43 ////////////////////////////////////////////////////////////////
\r
45 // Creates and constructs the view.
\r
46 CPicolAppView* CPicolAppView::NewLC(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
48 CPicolAppView* self = new (ELeave) CPicolAppView(aAppUi, aCurrentConfig);
\r
49 CleanupStack::PushL(self);
\r
54 Constructor for the view.
\r
55 Passes the application UI reference to the construction of the super class.
\r
57 KNullViewId should normally be passed as parent view for the applications
\r
58 default view. The parent view is the logical view that is normally activated
\r
59 when a go back command is issued. KNullViewId will activate the system
\r
62 @param aAppUi Reference to the application UI
\r
64 CPicolAppView::CPicolAppView(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
65 : CQikViewBase(aAppUi, KNullViewId), iCurrentConfig(aCurrentConfig)
\r
69 void CPicolAppView::ConstructL()
\r
74 CPicolAppView::~CPicolAppView()
\r
80 Inherited from CQikViewBase and called upon by the UI Framework.
\r
81 It creates the view from resource.
\r
83 void CPicolAppView::ViewConstructL()
\r
85 // Loads information about the UI configurations this view supports
\r
86 // together with definition of each view.
\r
87 ViewConstructFromResourceL(R_APP_UI_CONFIGURATIONS);
\r
88 UpdateCommandList();
\r
94 @return Returns the Uid of the view
\r
96 TVwsViewId CPicolAppView::ViewId()const
\r
98 return TVwsViewId(KUidPicolApp, KUidPicolMainView);
\r
102 Handles all commands in the view.
\r
103 Called by the UI framework when a command has been issued.
\r
104 The command Ids are defined in the .hrh file.
\r
106 @param aCommand The command to be executed
\r
107 @see CQikViewBase::HandleCommandL
\r
109 void CPicolAppView::HandleCommandL(CQikCommand& aCommand)
\r
113 switch(aCommand.Id())
\r
115 case EEikCmdPicoLoadState:
\r
117 CEikonEnv::Static()->BusyMsgL(_L("Loading State"));
\r
118 res = CPicoGameSession::Do(PicoMsgLoadState);
\r
119 CEikonEnv::Static()->BusyMsgCancel();
\r
120 // emu doesn't start to run if load fails, so we can display this
\r
121 if(res) CEikonEnv::Static()->InfoMsg(_L("Load Failed"));
\r
125 case EEikCmdPicoSaveState:
\r
127 CEikonEnv::Static()->BusyMsgL(_L("Saving State"));
\r
128 res = CPicoGameSession::Do(PicoMsgSaveState);
\r
129 CEikonEnv::Static()->BusyMsgCancel();
\r
130 if(res) CEikonEnv::Static()->InfoMsg(_L("Save Failed"));
\r
134 case EEikCmdPicoLoadROM:
\r
135 DisplayOpenROMDialogL();
\r
136 DEBUGPRINT(_L("after DisplayOpenROMDialogL()"));
\r
139 case EEikCmdPicoResume:
\r
140 CPicoGameSession::Do(PicoMsgResume);
\r
143 case EEikCmdPicoReset:
\r
144 CPicoGameSession::Do(PicoMsgReset);
\r
147 case EEikCmdPicoSettings:
\r
148 DisplayConfigDialogL();
\r
151 case EEikCmdHelpAbout:
\r
152 DisplayAboutDialogL();
\r
155 case EEikCmdPicoDebugInfo:
\r
156 DisplayDebugDialogL();
\r
159 case EEikCmdPicoKeys:
\r
160 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
161 CPicoGameSession::Do(PicoMsgKeys);
\r
164 case EEikCmdPicoFrameskipAuto:
\r
165 currentConfig.Frameskip = -1;
\r
166 emu_WriteConfig(0);
\r
169 case EEikCmdPicoFrameskip0:
\r
170 currentConfig.Frameskip = 0;
\r
171 emu_WriteConfig(0);
\r
174 case EEikCmdPicoFrameskip1:
\r
175 currentConfig.Frameskip = 1;
\r
176 emu_WriteConfig(0);
\r
179 case EEikCmdPicoFrameskip2:
\r
180 currentConfig.Frameskip = 2;
\r
181 emu_WriteConfig(0);
\r
184 case EEikCmdPicoFrameskip4:
\r
185 currentConfig.Frameskip = 4;
\r
186 emu_WriteConfig(0);
\r
189 case EEikCmdPicoFrameskip8:
\r
190 currentConfig.Frameskip = 8;
\r
191 emu_WriteConfig(0);
\r
196 CPicoGameSession::freeResources();
\r
197 //break; // this is intentional
\r
200 // Go back and exit command will be passed to the CQikViewBase to handle.
\r
201 CQikViewBase::HandleCommandL(aCommand);
\r
206 void CPicolAppView::DisplayOpenROMDialogL()
\r
208 // Array of mimetypes that the dialog shall filter on, if empty all
\r
209 // mimetypes will be visible.
\r
210 CDesCArray* mimeArray = new (ELeave) CDesCArrayFlat(1);
\r
211 CleanupStack::PushL(mimeArray);
\r
212 // Array that will be filled with the file paths that are choosen
\r
213 // from the dialog.
\r
214 CDesCArray* fileArray = new (ELeave) CDesCArraySeg(3);
\r
215 CleanupStack::PushL(fileArray);
\r
216 _LIT16(KDlgTitle, "Select a ROM file");
\r
218 TPtrC8 text8((TUint8*) loadedRomFName);
\r
219 iCurrentConfig.iLastROMFile.Copy(text8);
\r
221 if( CQikSelectFileDlg::RunDlgLD( *mimeArray, *fileArray, &KDlgTitle, &iCurrentConfig.iLastROMFile) )
\r
223 CEikonEnv::Static()->BusyMsgL(_L("Loading ROM"));
\r
224 TPtrC16 file = (*fileArray)[0];
\r
225 //iCurrentConfig.iLastROMFile.Copy(file);
\r
227 // push the config first
\r
228 CPicoGameSession::Do(PicoMsgSetAppView, this);
\r
229 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
231 TInt res = CPicoGameSession::Do(PicoMsgLoadROM, &file);
\r
233 CEikonEnv::Static()->BusyMsgCancel();
\r
235 iROMLoaded = EFalse;
\r
238 case PicoErrRomOpenFailed:
\r
239 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to open file."));
\r
242 case PicoErrOutOfMem:
\r
243 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate memory."));
\r
246 case PicoErrNotRom:
\r
247 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("The file you selected is not a game ROM."));
\r
250 case PicoErrNoRomsInArchive:
\r
251 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("No game ROMs found in zipfile."));
\r
254 case PicoErrUncomp:
\r
255 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed while unzipping ROM."));
\r
258 case PicoErrEmuThread:
\r
259 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to create emulation thread. Try to restart this application."));
\r
263 iROMLoaded = ETrue;
\r
267 // errors which leave ROM loaded
\r
270 case PicoErrOutOfMemSnd:
\r
271 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate sound buffer, disabled sound."));
\r
274 case PicoErrGenSnd:
\r
275 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to start soundsystem, disabled sound."));
\r
278 if(res == 6 || res == 7) currentConfig.EmuOpt &= ~EOPT_EN_SOUND;
\r
282 ViewContext()->ChangeTextL(EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
283 else ViewContext()->AddTextL (EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
284 iTitleAdded = ETrue;
\r
285 UpdateCommandList();
\r
288 CleanupStack::PopAndDestroy(2, mimeArray);
\r
292 void CPicolAppView::DisplayConfigDialogL()
\r
294 CPicoConfigDialog* configDialog = new(ELeave)CPicoConfigDialog(currentConfig);
\r
296 configDialog->ExecuteLD(R_PICO_CONFIG);
\r
297 emu_unpackConfig();
\r
298 emu_WriteConfig(0);
\r
300 CPicoGameSession::Do(PicoMsgConfigChange, ¤tConfig);
\r
304 void CPicolAppView::DisplayAboutDialogL()
\r
307 CAboutDialog* dialog = new (ELeave) CAboutDialog;
\r
309 dialog->PrepareLC(R_PICO_ABOUT);
\r
310 iButtonRes = dialog->RunLD();
\r
312 if(iButtonRes == EEikCmdPicoAboutCreditsCmd) {
\r
313 CCreditsDialog *creditsDialog = new (ELeave) CCreditsDialog();
\r
314 creditsDialog->PrepareLC(R_PICO_CREDITS);
\r
315 creditsDialog->RunLD();
\r
319 #ifdef __DEBUG_PRINT
\r
320 extern "C" char *PDebugMain();
\r
323 void CPicolAppView::DisplayDebugDialogL()
\r
325 #ifdef __DEBUG_PRINT
\r
326 CDebugDialog* dialog = new (ELeave) CDebugDialog(PDebugMain());
\r
328 dialog->PrepareLC(R_PICO_DEBUG);
\r
333 void CPicolAppView::UpdateCommandList()
\r
335 CQikCommandManager& commandManager = CQikCommandManager::Static(*iCoeEnv);
\r
336 CQikCommand *cmd_fs[10];
\r
337 Mem::FillZ(cmd_fs, sizeof(CQikCommand*)*10);
\r
339 CQikCommand* cmd_reset = commandManager.Command(*this, EEikCmdPicoReset);
\r
340 CQikCommand* cmd_savest = commandManager.Command(*this, EEikCmdPicoSaveState);
\r
341 CQikCommand* cmd_loadst = commandManager.Command(*this, EEikCmdPicoLoadState);
\r
342 CQikCommand* cmd_resume = commandManager.Command(*this, EEikCmdPicoResume);
\r
343 cmd_fs[0] = commandManager.Command(*this, EEikCmdPicoFrameskipAuto);
\r
344 cmd_fs[1] = commandManager.Command(*this, EEikCmdPicoFrameskip0);
\r
345 cmd_fs[2] = commandManager.Command(*this, EEikCmdPicoFrameskip1);
\r
346 cmd_fs[3] = commandManager.Command(*this, EEikCmdPicoFrameskip2);
\r
347 cmd_fs[5] = commandManager.Command(*this, EEikCmdPicoFrameskip4);
\r
348 cmd_fs[9] = commandManager.Command(*this, EEikCmdPicoFrameskip8);
\r
350 TBool dimmed = !CPicoGameSession::iEmuRunning || !iROMLoaded;
\r
351 cmd_reset ->SetDimmed(dimmed);
\r
352 cmd_savest->SetDimmed(dimmed);
\r
353 cmd_loadst->SetDimmed(dimmed);
\r
354 cmd_resume->SetDimmed(dimmed);
\r
357 TInt fs_index = currentConfig.Frameskip + 1;
\r
358 if (fs_index >= 0 && fs_index < 10 && cmd_fs[fs_index])
\r
360 cmd_fs[fs_index]->SetChecked(ETrue);
\r
365 ////////////////////////////////////////////////////////////////
\r
367 // class CPicolAppUi
\r
369 ////////////////////////////////////////////////////////////////
\r
372 void CPicolAppUi::ConstructL()
\r
376 // Create the view and add it to the framework
\r
377 iAppView = CPicolAppView::NewLC(*this, ((CPicolDocument *)Document())->iCurrentConfig);
\r
378 AddViewL(*iAppView);
\r
379 CleanupStack::Pop(iAppView);
\r
383 ////////////////////////////////////////////////////////////////
\r
387 ////////////////////////////////////////////////////////////////
\r
390 CPicolDocument::CPicolDocument(CQikApplication& aApp)
\r
391 : CQikDocument(aApp)
\r
395 CQikAppUi* CPicolDocument::CreateAppUiL()
\r
397 return new(ELeave) CPicolAppUi;
\r
401 Called by the framework when ::SaveL has been called.
\r
403 void CPicolDocument::StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const
\r
406 RStoreWriteStream stream;
\r
408 TStreamId preferenceId = stream.CreateLC(aStore);
\r
409 aStreamDic.AssignL(KUidPicolStore, preferenceId);
\r
411 // Externalize preference
\r
412 stream << iCurrentConfig;
\r
414 // Ensures that any buffered data is written to aStore
\r
416 CleanupStack::PopAndDestroy(); // stream
\r
422 res = logFile.Replace(CEikonEnv::Static()->FsSession(), _L("C:\\Shared\\pico.cfg"), EFileWrite|EFileShareAny);
\r
424 logFile.Write(TPtr8((TUint8 *)&iCurrentConfig, sizeof(iCurrentConfig), sizeof(iCurrentConfig)));
\r
431 Called by the framework on application start.
\r
432 Loads the application data from disk, i.e. domain data and preferences.
\r
434 void CPicolDocument::RestoreL(const CStreamStore& aStore, const CStreamDictionary& aStreamDic)
\r
437 // Find the stream ID of the model data from the stream dictionary:
\r
438 TStreamId preferenceId(aStreamDic.At(KUidPicolStore));
\r
439 RStoreReadStream stream;
\r
440 stream.OpenLC(aStore, preferenceId);
\r
441 if(preferenceId != KNullStreamId)
\r
443 // Interalize preference and model
\r
444 stream >> iCurrentConfig;
\r
447 CleanupStack::PopAndDestroy(); // stream
\r
453 res = logFile.Open(CEikonEnv::Static()->FsSession(), _L("C:\\Shared\\pico.cfg"), EFileRead|EFileShareAny);
\r
455 TPtr8 ptr((TUint8 *)&iCurrentConfig, sizeof(iCurrentConfig), sizeof(iCurrentConfig));
\r
461 ////////////////////////////////////////////////////////////////
\r
465 ////////////////////////////////////////////////////////////////
\r
468 CApaDocument* CPicolApplication::CreateDocumentL()
\r
470 return new (ELeave) CPicolDocument(*this);
\r
473 EXPORT_C CApaApplication* NewApplication()
\r
475 return new CPicolApplication;
\r
479 TUid CPicolApplication::AppDllUid() const
\r
481 return KUidPicolApp;
\r
485 extern "C" TInt my_SetExceptionHandler(TInt, TExceptionHandler, TUint32);
\r
487 GLDEF_C TInt E32Main()
\r
490 User::SetExceptionHandler(ExceptionHandler, (TUint32) -1);
\r
491 // my_SetExceptionHandler(KCurrentThreadHandle, ExceptionHandler, 0xffffffff);
\r
495 return EikStart::RunApplication(NewApplication);
\r