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
38 extern "C" char menuErrorMsg[];
\r
40 ////////////////////////////////////////////////////////////////
\r
42 // class CPicolAppView
\r
44 ////////////////////////////////////////////////////////////////
\r
46 // Creates and constructs the view.
\r
47 CPicolAppView* CPicolAppView::NewLC(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
49 CPicolAppView* self = new (ELeave) CPicolAppView(aAppUi, aCurrentConfig);
\r
50 CleanupStack::PushL(self);
\r
55 Constructor for the view.
\r
56 Passes the application UI reference to the construction of the super class.
\r
58 KNullViewId should normally be passed as parent view for the applications
\r
59 default view. The parent view is the logical view that is normally activated
\r
60 when a go back command is issued. KNullViewId will activate the system
\r
63 @param aAppUi Reference to the application UI
\r
65 CPicolAppView::CPicolAppView(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
66 : CQikViewBase(aAppUi, KNullViewId), iCurrentConfig(aCurrentConfig)
\r
70 void CPicolAppView::ConstructL()
\r
75 CPicolAppView::~CPicolAppView()
\r
81 Inherited from CQikViewBase and called upon by the UI Framework.
\r
82 It creates the view from resource.
\r
84 void CPicolAppView::ViewConstructL()
\r
86 // Loads information about the UI configurations this view supports
\r
87 // together with definition of each view.
\r
88 ViewConstructFromResourceL(R_APP_UI_CONFIGURATIONS);
\r
89 UpdateCommandList();
\r
95 @return Returns the Uid of the view
\r
97 TVwsViewId CPicolAppView::ViewId()const
\r
99 return TVwsViewId(KUidPicolApp, KUidPicolMainView);
\r
103 Handles all commands in the view.
\r
104 Called by the UI framework when a command has been issued.
\r
105 The command Ids are defined in the .hrh file.
\r
107 @param aCommand The command to be executed
\r
108 @see CQikViewBase::HandleCommandL
\r
110 void CPicolAppView::HandleCommandL(CQikCommand& aCommand)
\r
114 switch(aCommand.Id())
\r
116 case EEikCmdPicoLoadState:
\r
118 CEikonEnv::Static()->BusyMsgL(_L("Loading State"));
\r
119 res = CPicoGameSession::Do(PicoMsgLoadState);
\r
120 CEikonEnv::Static()->BusyMsgCancel();
\r
121 // emu doesn't start to run if load fails, so we can display this
\r
122 if(res) CEikonEnv::Static()->InfoMsg(_L("Load Failed"));
\r
126 case EEikCmdPicoSaveState:
\r
128 CEikonEnv::Static()->BusyMsgL(_L("Saving State"));
\r
129 res = CPicoGameSession::Do(PicoMsgSaveState);
\r
130 CEikonEnv::Static()->BusyMsgCancel();
\r
131 if(res) CEikonEnv::Static()->InfoMsg(_L("Save Failed"));
\r
135 case EEikCmdPicoLoadROM:
\r
136 DisplayOpenROMDialogL();
\r
137 DEBUGPRINT(_L("after DisplayOpenROMDialogL()"));
\r
140 case EEikCmdPicoResume:
\r
141 CPicoGameSession::Do(PicoMsgResume);
\r
144 case EEikCmdPicoReset:
\r
145 CPicoGameSession::Do(PicoMsgReset);
\r
148 case EEikCmdPicoSettings:
\r
149 DisplayConfigDialogL();
\r
152 case EEikCmdHelpAbout:
\r
153 DisplayAboutDialogL();
\r
156 case EEikCmdPicoDebugInfo:
\r
157 DisplayDebugDialogL();
\r
160 case EEikCmdPicoKeys:
\r
161 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
162 CPicoGameSession::Do(PicoMsgKeys);
\r
165 case EEikCmdPicoFrameskipAuto:
\r
166 currentConfig.Frameskip = -1;
\r
167 emu_WriteConfig(0);
\r
170 case EEikCmdPicoFrameskip0:
\r
171 currentConfig.Frameskip = 0;
\r
172 emu_WriteConfig(0);
\r
175 case EEikCmdPicoFrameskip1:
\r
176 currentConfig.Frameskip = 1;
\r
177 emu_WriteConfig(0);
\r
180 case EEikCmdPicoFrameskip2:
\r
181 currentConfig.Frameskip = 2;
\r
182 emu_WriteConfig(0);
\r
185 case EEikCmdPicoFrameskip4:
\r
186 currentConfig.Frameskip = 4;
\r
187 emu_WriteConfig(0);
\r
190 case EEikCmdPicoFrameskip8:
\r
191 currentConfig.Frameskip = 8;
\r
192 emu_WriteConfig(0);
\r
197 CPicoGameSession::freeResources();
\r
198 //break; // this is intentional
\r
201 // Go back and exit command will be passed to the CQikViewBase to handle.
\r
202 CQikViewBase::HandleCommandL(aCommand);
\r
207 void CPicolAppView::DisplayOpenROMDialogL()
\r
209 // Array of mimetypes that the dialog shall filter on, if empty all
\r
210 // mimetypes will be visible.
\r
211 CDesCArray* mimeArray = new (ELeave) CDesCArrayFlat(1);
\r
212 CleanupStack::PushL(mimeArray);
\r
213 // Array that will be filled with the file paths that are choosen
\r
214 // from the dialog.
\r
215 CDesCArray* fileArray = new (ELeave) CDesCArraySeg(3);
\r
216 CleanupStack::PushL(fileArray);
\r
217 _LIT16(KDlgTitle, "Select a ROM file");
\r
219 TPtrC8 text8((TUint8*) rom_fname_loaded);
\r
220 iCurrentConfig.iLastROMFile.Copy(text8);
\r
222 if( CQikSelectFileDlg::RunDlgLD( *mimeArray, *fileArray, &KDlgTitle, &iCurrentConfig.iLastROMFile) )
\r
224 CEikonEnv::Static()->BusyMsgL(_L("Loading ROM"));
\r
225 TPtrC16 file = (*fileArray)[0];
\r
226 //iCurrentConfig.iLastROMFile.Copy(file);
\r
228 // push the config first
\r
229 CPicoGameSession::Do(PicoMsgSetAppView, this);
\r
230 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
232 TInt res = CPicoGameSession::Do(PicoMsgLoadROM, &file);
\r
234 CEikonEnv::Static()->BusyMsgCancel();
\r
236 iROMLoaded = EFalse;
\r
239 case PicoErrRomOpenFailed: {
\r
240 TBuf<64> mErrorBuff;
\r
241 TPtrC8 buff8((TUint8*) menuErrorMsg);
\r
242 mErrorBuff.Copy(buff8);
\r
243 CEikonEnv::Static()->InfoWinL(_L("Error"), mErrorBuff);
\r
247 case PicoErrOutOfMem:
\r
248 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate memory."));
\r
251 case PicoErrEmuThread:
\r
252 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to create emulation thread. Try to restart this application."));
\r
256 iROMLoaded = ETrue;
\r
260 // errors which leave ROM loaded
\r
263 case PicoErrOutOfMemSnd:
\r
264 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate sound buffer, disabled sound."));
\r
267 case PicoErrGenSnd:
\r
268 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to start soundsystem, disabled sound."));
\r
271 if(res == 6 || res == 7) currentConfig.EmuOpt &= ~EOPT_EN_SOUND;
\r
275 ViewContext()->ChangeTextL(EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
276 else ViewContext()->AddTextL (EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
277 iTitleAdded = ETrue;
\r
278 UpdateCommandList();
\r
281 CleanupStack::PopAndDestroy(2, mimeArray);
\r
285 void CPicolAppView::DisplayConfigDialogL()
\r
287 CPicoConfigDialog* configDialog = new(ELeave)CPicoConfigDialog(currentConfig);
\r
289 configDialog->ExecuteLD(R_PICO_CONFIG);
\r
290 emu_unpackConfig();
\r
291 emu_WriteConfig(0);
\r
293 CPicoGameSession::Do(PicoMsgConfigChange, ¤tConfig);
\r
297 void CPicolAppView::DisplayAboutDialogL()
\r
300 CAboutDialog* dialog = new (ELeave) CAboutDialog;
\r
302 dialog->PrepareLC(R_PICO_ABOUT);
\r
303 iButtonRes = dialog->RunLD();
\r
305 if(iButtonRes == EEikCmdPicoAboutCreditsCmd) {
\r
306 CCreditsDialog *creditsDialog = new (ELeave) CCreditsDialog();
\r
307 creditsDialog->PrepareLC(R_PICO_CREDITS);
\r
308 creditsDialog->RunLD();
\r
312 #ifdef __DEBUG_PRINT
\r
313 extern "C" char *PDebugMain();
\r
316 void CPicolAppView::DisplayDebugDialogL()
\r
318 #ifdef __DEBUG_PRINT
\r
319 CDebugDialog* dialog = new (ELeave) CDebugDialog(PDebugMain());
\r
321 dialog->PrepareLC(R_PICO_DEBUG);
\r
326 void CPicolAppView::UpdateCommandList()
\r
328 CQikCommandManager& commandManager = CQikCommandManager::Static(*iCoeEnv);
\r
329 CQikCommand *cmd_fs[10];
\r
330 Mem::FillZ(cmd_fs, sizeof(CQikCommand*)*10);
\r
332 CQikCommand* cmd_reset = commandManager.Command(*this, EEikCmdPicoReset);
\r
333 CQikCommand* cmd_savest = commandManager.Command(*this, EEikCmdPicoSaveState);
\r
334 CQikCommand* cmd_loadst = commandManager.Command(*this, EEikCmdPicoLoadState);
\r
335 CQikCommand* cmd_resume = commandManager.Command(*this, EEikCmdPicoResume);
\r
336 cmd_fs[0] = commandManager.Command(*this, EEikCmdPicoFrameskipAuto);
\r
337 cmd_fs[1] = commandManager.Command(*this, EEikCmdPicoFrameskip0);
\r
338 cmd_fs[2] = commandManager.Command(*this, EEikCmdPicoFrameskip1);
\r
339 cmd_fs[3] = commandManager.Command(*this, EEikCmdPicoFrameskip2);
\r
340 cmd_fs[5] = commandManager.Command(*this, EEikCmdPicoFrameskip4);
\r
341 cmd_fs[9] = commandManager.Command(*this, EEikCmdPicoFrameskip8);
\r
343 TBool dimmed = !CPicoGameSession::iEmuRunning || !iROMLoaded;
\r
344 cmd_reset ->SetDimmed(dimmed);
\r
345 cmd_savest->SetDimmed(dimmed);
\r
346 cmd_loadst->SetDimmed(dimmed);
\r
347 cmd_resume->SetDimmed(dimmed);
\r
350 TInt fs_index = currentConfig.Frameskip + 1;
\r
351 if (fs_index >= 0 && fs_index < 10 && cmd_fs[fs_index])
\r
353 cmd_fs[fs_index]->SetChecked(ETrue);
\r
358 ////////////////////////////////////////////////////////////////
\r
360 // class CPicolAppUi
\r
362 ////////////////////////////////////////////////////////////////
\r
365 void CPicolAppUi::ConstructL()
\r
369 // Create the view and add it to the framework
\r
370 iAppView = CPicolAppView::NewLC(*this, ((CPicolDocument *)Document())->iCurrentConfig);
\r
371 AddViewL(*iAppView);
\r
372 CleanupStack::Pop(iAppView);
\r
376 ////////////////////////////////////////////////////////////////
\r
380 ////////////////////////////////////////////////////////////////
\r
383 CPicolDocument::CPicolDocument(CQikApplication& aApp)
\r
384 : CQikDocument(aApp)
\r
388 CQikAppUi* CPicolDocument::CreateAppUiL()
\r
390 return new(ELeave) CPicolAppUi;
\r
394 Called by the framework when ::SaveL has been called.
\r
396 void CPicolDocument::StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const
\r
399 RStoreWriteStream stream;
\r
401 TStreamId preferenceId = stream.CreateLC(aStore);
\r
402 aStreamDic.AssignL(KUidPicolStore, preferenceId);
\r
404 // Externalize preference
\r
405 stream << iCurrentConfig;
\r
407 // Ensures that any buffered data is written to aStore
\r
409 CleanupStack::PopAndDestroy(); // stream
\r
415 res = logFile.Replace(CEikonEnv::Static()->FsSession(), _L("C:\\Shared\\pico.cfg"), EFileWrite|EFileShareAny);
\r
417 logFile.Write(TPtr8((TUint8 *)&iCurrentConfig, sizeof(iCurrentConfig), sizeof(iCurrentConfig)));
\r
424 Called by the framework on application start.
\r
425 Loads the application data from disk, i.e. domain data and preferences.
\r
427 void CPicolDocument::RestoreL(const CStreamStore& aStore, const CStreamDictionary& aStreamDic)
\r
430 // Find the stream ID of the model data from the stream dictionary:
\r
431 TStreamId preferenceId(aStreamDic.At(KUidPicolStore));
\r
432 RStoreReadStream stream;
\r
433 stream.OpenLC(aStore, preferenceId);
\r
434 if(preferenceId != KNullStreamId)
\r
436 // Interalize preference and model
\r
437 stream >> iCurrentConfig;
\r
440 CleanupStack::PopAndDestroy(); // stream
\r
446 res = logFile.Open(CEikonEnv::Static()->FsSession(), _L("C:\\Shared\\pico.cfg"), EFileRead|EFileShareAny);
\r
448 TPtr8 ptr((TUint8 *)&iCurrentConfig, sizeof(iCurrentConfig), sizeof(iCurrentConfig));
\r
454 ////////////////////////////////////////////////////////////////
\r
458 ////////////////////////////////////////////////////////////////
\r
461 CApaDocument* CPicolApplication::CreateDocumentL()
\r
463 return new (ELeave) CPicolDocument(*this);
\r
466 EXPORT_C CApaApplication* NewApplication()
\r
468 return new CPicolApplication;
\r
472 TUid CPicolApplication::AppDllUid() const
\r
474 return KUidPicolApp;
\r
478 extern "C" TInt my_SetExceptionHandler(TInt, TExceptionHandler, TUint32);
\r
480 GLDEF_C TInt E32Main()
\r
483 User::SetExceptionHandler(ExceptionHandler, (TUint32) -1);
\r
484 // my_SetExceptionHandler(KCurrentThreadHandle, ExceptionHandler, 0xffffffff);
\r
488 return EikStart::RunApplication(NewApplication);
\r