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 <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
38 ////////////////////////////////////////////////////////////////
\r
40 // class CPicolAppView
\r
42 ////////////////////////////////////////////////////////////////
\r
44 // Creates and constructs the view.
\r
45 CPicolAppView* CPicolAppView::NewLC(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
47 CPicolAppView* self = new (ELeave) CPicolAppView(aAppUi, aCurrentConfig);
\r
48 CleanupStack::PushL(self);
\r
53 Constructor for the view.
\r
54 Passes the application UI reference to the construction of the super class.
\r
56 KNullViewId should normally be passed as parent view for the applications
\r
57 default view. The parent view is the logical view that is normally activated
\r
58 when a go back command is issued. KNullViewId will activate the system
\r
61 @param aAppUi Reference to the application UI
\r
63 CPicolAppView::CPicolAppView(CQikAppUi& aAppUi, TPicoConfig& aCurrentConfig)
\r
64 : CQikViewBase(aAppUi, KNullViewId), iCurrentConfig(aCurrentConfig)
\r
68 void CPicolAppView::ConstructL()
\r
73 CPicolAppView::~CPicolAppView()
\r
79 Inherited from CQikViewBase and called upon by the UI Framework.
\r
80 It creates the view from resource.
\r
82 void CPicolAppView::ViewConstructL()
\r
84 // Loads information about the UI configurations this view supports
\r
85 // together with definition of each view.
\r
86 ViewConstructFromResourceL(R_APP_UI_CONFIGURATIONS);
\r
87 UpdateCommandList();
\r
93 @return Returns the Uid of the view
\r
95 TVwsViewId CPicolAppView::ViewId()const
\r
97 return TVwsViewId(KUidPicolApp, KUidPicolMainView);
\r
101 Handles all commands in the view.
\r
102 Called by the UI framework when a command has been issued.
\r
103 The command Ids are defined in the .hrh file.
\r
105 @param aCommand The command to be executed
\r
106 @see CQikViewBase::HandleCommandL
\r
108 void CPicolAppView::HandleCommandL(CQikCommand& aCommand)
\r
112 switch(aCommand.Id())
\r
114 case EEikCmdPicoLoadState:
\r
116 CEikonEnv::Static()->BusyMsgL(_L("Loading State"));
\r
117 res = CPicoGameSession::Do(PicoMsgLoadState);
\r
118 CEikonEnv::Static()->BusyMsgCancel();
\r
119 // emu doesn't start to run if load fails, so we can display this
\r
120 if(res) CEikonEnv::Static()->InfoMsg(_L("Load Failed"));
\r
124 case EEikCmdPicoSaveState:
\r
126 CEikonEnv::Static()->BusyMsgL(_L("Saving State"));
\r
127 res = CPicoGameSession::Do(PicoMsgSaveState);
\r
128 CEikonEnv::Static()->BusyMsgCancel();
\r
129 if(res) CEikonEnv::Static()->InfoMsg(_L("Save Failed"));
\r
133 case EEikCmdPicoLoadROM:
\r
134 DisplayOpenROMDialogL();
\r
135 DEBUGPRINT(_L("after DisplayOpenROMDialogL()"));
\r
138 case EEikCmdPicoResume:
\r
139 CPicoGameSession::Do(PicoMsgResume);
\r
142 case EEikCmdPicoReset:
\r
143 CPicoGameSession::Do(PicoMsgReset);
\r
146 case EEikCmdPicoSettings:
\r
147 DisplayConfigDialogL();
\r
150 case EEikCmdHelpAbout:
\r
151 DisplayAboutDialogL();
\r
154 case EEikCmdPicoDebugInfo:
\r
155 DisplayDebugDialogL();
\r
158 case EEikCmdPicoKeys:
\r
159 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
160 CPicoGameSession::Do(PicoMsgKeys);
\r
163 case EEikCmdPicoFrameskipAuto:
\r
164 iCurrentConfig.iFrameskip = TPicoConfig::PFSkipAuto;
\r
165 iQikAppUi.Document()->SaveL();
\r
168 case EEikCmdPicoFrameskip0:
\r
169 iCurrentConfig.iFrameskip = 0;
\r
170 iQikAppUi.Document()->SaveL();
\r
173 case EEikCmdPicoFrameskip1:
\r
174 iCurrentConfig.iFrameskip = 1;
\r
175 iQikAppUi.Document()->SaveL();
\r
178 case EEikCmdPicoFrameskip2:
\r
179 iCurrentConfig.iFrameskip = 2;
\r
180 iQikAppUi.Document()->SaveL();
\r
183 case EEikCmdPicoFrameskip4:
\r
184 iCurrentConfig.iFrameskip = 4;
\r
185 iQikAppUi.Document()->SaveL();
\r
188 case EEikCmdPicoFrameskip8:
\r
189 iCurrentConfig.iFrameskip = 8;
\r
190 iQikAppUi.Document()->SaveL();
\r
194 iQikAppUi.Document()->SaveL();
\r
195 CPicoGameSession::freeResources();
\r
196 //break; // this is intentional
\r
199 // Go back and exit command will be passed to the CQikViewBase to handle.
\r
200 CQikViewBase::HandleCommandL(aCommand);
\r
205 void CPicolAppView::DisplayOpenROMDialogL()
\r
207 // Array of mimetypes that the dialog shall filter on, if empty all
\r
208 // mimetypes will be visible.
\r
209 CDesCArray* mimeArray = new (ELeave) CDesCArrayFlat(1);
\r
210 CleanupStack::PushL(mimeArray);
\r
211 // Array that will be filled with the file paths that are choosen
\r
212 // from the dialog.
\r
213 CDesCArray* fileArray = new (ELeave) CDesCArraySeg(3);
\r
214 CleanupStack::PushL(fileArray);
\r
215 _LIT16(KDlgTitle, "Select a ROM file");
\r
217 if( CQikSelectFileDlg::RunDlgLD( *mimeArray, *fileArray, &KDlgTitle, &iCurrentConfig.iLastROMFile) )
\r
219 CEikonEnv::Static()->BusyMsgL(_L("Loading ROM"));
\r
220 TPtrC16 file = (*fileArray)[0];
\r
221 iCurrentConfig.iLastROMFile.Copy(file);
\r
223 // push the config first
\r
224 CPicoGameSession::Do(PicoMsgSetAppView, this);
\r
225 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
227 TInt res = CPicoGameSession::Do(PicoMsgLoadROM, &file);
\r
229 CEikonEnv::Static()->BusyMsgCancel();
\r
231 iROMLoaded = EFalse;
\r
234 case PicoErrRomOpenFailed:
\r
235 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to open file."));
\r
238 case PicoErrOutOfMem:
\r
239 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate memory."));
\r
242 case PicoErrNotRom:
\r
243 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("The file you selected is not a game ROM."));
\r
246 case PicoErrNoRomsInArchive:
\r
247 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("No game ROMs found in zipfile."));
\r
250 case PicoErrUncomp:
\r
251 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed while unzipping ROM."));
\r
254 case PicoErrEmuThread:
\r
255 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to create emulation thread. Try to restart this application."));
\r
259 iROMLoaded = ETrue;
\r
263 // errors which leave ROM loaded
\r
266 case PicoErrOutOfMemSnd:
\r
267 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to allocate sound buffer, disabled sound."));
\r
270 case PicoErrGenSnd:
\r
271 CEikonEnv::Static()->InfoWinL(_L("Error"), _L("Failed to start soundsystem, disabled sound."));
\r
274 if(res == 6 || res == 7) iCurrentConfig.iFlags &= ~4;
\r
278 ViewContext()->ChangeTextL(EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
279 else ViewContext()->AddTextL (EEikCidTitleBarLabel, CPicoGameSession::iRomInternalName);
\r
280 iTitleAdded = ETrue;
\r
281 UpdateCommandList();
\r
284 CleanupStack::PopAndDestroy(2, mimeArray);
\r
288 void CPicolAppView::DisplayConfigDialogL()
\r
290 CPicoConfigDialog* configDialog = new(ELeave)CPicoConfigDialog(iCurrentConfig);
\r
291 configDialog->ExecuteLD(R_PICO_CONFIG);
\r
293 CPicoGameSession::Do(PicoMsgConfigChange, &iCurrentConfig);
\r
294 iQikAppUi.Document()->SaveL();
\r
298 void CPicolAppView::DisplayAboutDialogL()
\r
301 CAboutDialog* dialog = new (ELeave) CAboutDialog;
\r
303 dialog->PrepareLC(R_PICO_ABOUT);
\r
304 iButtonRes = dialog->RunLD();
\r
306 if(iButtonRes == EEikCmdPicoAboutCreditsCmd) {
\r
307 CCreditsDialog *creditsDialog = new (ELeave) CCreditsDialog();
\r
308 creditsDialog->PrepareLC(R_PICO_CREDITS);
\r
309 creditsDialog->RunLD();
\r
313 #ifdef __DEBUG_PRINT
\r
314 extern "C" char *debugString();
\r
317 void CPicolAppView::DisplayDebugDialogL()
\r
319 #ifdef __DEBUG_PRINT
\r
320 CDebugDialog* dialog = new (ELeave) CDebugDialog(debugString());
\r
322 dialog->PrepareLC(R_PICO_DEBUG);
\r
327 void CPicolAppView::UpdateCommandList()
\r
329 CQikCommandManager& commandManager = CQikCommandManager::Static(*iCoeEnv);
\r
330 CQikCommand *cmd_fs[10];
\r
331 Mem::FillZ(cmd_fs, sizeof(CQikCommand*)*10);
\r
333 CQikCommand* cmd_reset = commandManager.Command(*this, EEikCmdPicoReset);
\r
334 CQikCommand* cmd_savest = commandManager.Command(*this, EEikCmdPicoSaveState);
\r
335 CQikCommand* cmd_loadst = commandManager.Command(*this, EEikCmdPicoLoadState);
\r
336 CQikCommand* cmd_resume = commandManager.Command(*this, EEikCmdPicoResume);
\r
337 cmd_fs[0] = commandManager.Command(*this, EEikCmdPicoFrameskipAuto);
\r
338 cmd_fs[1] = commandManager.Command(*this, EEikCmdPicoFrameskip0);
\r
339 cmd_fs[2] = commandManager.Command(*this, EEikCmdPicoFrameskip1);
\r
340 cmd_fs[3] = commandManager.Command(*this, EEikCmdPicoFrameskip2);
\r
341 cmd_fs[5] = commandManager.Command(*this, EEikCmdPicoFrameskip4);
\r
342 cmd_fs[9] = commandManager.Command(*this, EEikCmdPicoFrameskip8);
\r
344 TBool dimmed = !CPicoGameSession::iEmuRunning || !iROMLoaded;
\r
345 cmd_reset ->SetDimmed(dimmed);
\r
346 cmd_savest->SetDimmed(dimmed);
\r
347 cmd_loadst->SetDimmed(dimmed);
\r
348 cmd_resume->SetDimmed(dimmed);
\r
351 TInt fs_index = iCurrentConfig.iFrameskip + 1;
\r
352 if (fs_index >= 0 && fs_index < 10 && cmd_fs[fs_index])
\r
354 cmd_fs[fs_index]->SetChecked(ETrue);
\r
359 ////////////////////////////////////////////////////////////////
\r
361 // class CPicolAppUi
\r
363 ////////////////////////////////////////////////////////////////
\r
366 void CPicolAppUi::ConstructL()
\r
370 // Create the view and add it to the framework
\r
371 iAppView = CPicolAppView::NewLC(*this, ((CPicolDocument *)Document())->iCurrentConfig);
\r
372 AddViewL(*iAppView);
\r
373 CleanupStack::Pop(iAppView);
\r
377 ////////////////////////////////////////////////////////////////
\r
381 ////////////////////////////////////////////////////////////////
\r
384 CPicolDocument::CPicolDocument(CQikApplication& aApp)
\r
385 : CQikDocument(aApp)
\r
387 iCurrentConfig.SetDefaults();
\r
390 CQikAppUi* CPicolDocument::CreateAppUiL()
\r
392 return new(ELeave) CPicolAppUi;
\r
396 Called by the framework when ::SaveL has been called.
\r
398 void CPicolDocument::StoreL(CStreamStore& aStore, CStreamDictionary& aStreamDic) const
\r
400 RStoreWriteStream stream;
\r
402 TStreamId preferenceId = stream.CreateLC(aStore);
\r
403 aStreamDic.AssignL(KUidPicolStore, preferenceId);
\r
405 // Externalize preference
\r
406 stream << iCurrentConfig;
\r
408 // Ensures that any buffered data is written to aStore
\r
410 CleanupStack::PopAndDestroy(); // stream
\r
416 res = logFile.Replace(CEikonEnv::Static()->FsSession(), _L("C:\\Shared\\pico.cfg"), EFileWrite|EFileShareAny);
\r
418 logFile.Write(TPtr8((TUint8 *)&iCurrentConfig, sizeof(iCurrentConfig), sizeof(iCurrentConfig)));
\r
425 Called by the framework on application start.
\r
426 Loads the application data from disk, i.e. domain data and preferences.
\r
428 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 GLDEF_C TInt E32Main()
\r
480 User::SetExceptionHandler(ExceptionHandler, (TUint32) -1);
\r
482 return EikStart::RunApplication(NewApplication);
\r