00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00018
00019 #include <eikapp.h>
00020 #include <eikappui.h>
00021
00022 #if defined(__CRYSTAL__) // Crystal / CKON
00023 #include <ckndgopn.h>
00024 #include <ckninfo.h>
00025 #elif defined(__SERIES60__)
00026 #include <aknapp.h>
00027 #include <aknappui.h>
00028 #include <akndoc.h>
00029 #include <aknnotedialog.h>
00030 #include <eikinfo.h>
00031
00032 #elif defined(__QUARTZ__)
00033
00034 #else // ER5
00035 #include <eikbordr.h>
00036 #include <eikcfdlg.hrh>
00037 #include <eikcmds.hrh>
00038 #include <eikdutil.h>
00039 #include <eikfbrow.h>
00040 #endif
00041
00042 #include <eikdef.h>
00043 #include <eikdialg.h>
00044 #include <eikdoc.h>
00045 #include <eikenv.h>
00046
00047 #if defined(__CRYSTAL__) && !defined(__SERIES60__)
00048 #include <eikfsel.h>
00049 #include <eikform.h>
00050 #endif
00051
00052 #include <eiklabel.h>
00053 #include <eikmsg.h>
00054 #include <eikon.rsg>
00055 #include <eiktbar.h>
00056 #include <eikcmbut.h>
00057 #include <eikmenub.h>
00058
00059
00060 #include <coecntrl.h>
00061 #include <coeutils.h>
00062 #if !defined(__ER6__)
00063 #include <coealign.h>
00064 #endif
00065
00066
00067
00068 #include <e32hal.h>
00069 #include <e32keys.h>
00070 #include <basched.h>
00071 #include <apaflrec.h>
00072
00073
00074 #include <sidplay.rsg>
00075 #include "sidplay.hrh"
00076 #include "elog.h"
00077
00078 #include "sidplay_view.h"
00079 #include "sidplayer.h"
00080
00081 #include "6510_.h"
00082
00083
00084
00085
00086
00087 #ifdef __ER6__
00088 #define KMyUid TUid::Uid(0x10009a97);
00089 #else
00090 #define KMyUid TUid::Uid(0x10009a96);
00091 #endif
00092
00093
00097 #if defined(__SERIES60__)
00098 class CSidPlayAppUi : public CAknAppUi
00099 #else
00100 class CSidPlayAppUi : public CEikAppUi
00101 #endif
00102 {
00103 public:
00104 void ConstructL();
00105 ~CSidPlayAppUi();
00106 private:
00107 void DoBrowseFileL();
00108 void DoScanFilesystemL();
00109 void HandleCommandL(TInt aCommand);
00110 #if defined(__ER6__)
00111 virtual TKeyResponse CSidPlayAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
00112 #else
00113 virtual void CSidPlayAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
00114 #endif
00115 TBool ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName, const TDesC8& );
00116 void UpdateCbaL();
00117
00118 public:
00119 CSidPlayer* iPlayer;
00120 CSidPlayAppView* iAppView;
00121 };
00122
00123
00124
00125
00126
00127
00128
00129 void CSidPlayAppUi::ConstructL()
00133 {
00134 Dll::SetTls(this);
00135
00136 BaseConstructL();
00137
00138
00139
00140
00141 _LIT(KSidTune, "c:\\sid\\gameover.sid");
00142 iPlayer = CSidPlayer::NewL(KSidTune);
00143 iPlayer->InitL();
00144
00145
00146
00147
00148 iAppView = new (ELeave) CSidPlayAppView();
00149 iAppView->ConstructL(ClientRect(), iPlayer);
00150
00151 #if !defined(__ER6__)
00152
00153 for (TInt i=ECmdPrev; i<=ECmdNext; i++)
00154 {
00155 CEikCommandButton* button = STATIC_CAST(CEikCommandButton*, iToolBand->ControlById(i));
00156 if(button)
00157 {
00158 CEikLabel* label = button->Label();
00159 label->SetFont(iEikonEnv->SymbolFont());
00160 }
00161 }
00162
00163
00164 iToolBar->DrawNow();
00165 iToolBand->DrawNow();
00166 #endif
00167 }
00168
00169
00170 CSidPlayAppUi::~CSidPlayAppUi()
00174 {
00175 if(iPlayer)
00176 delete iPlayer;
00177 delete iAppView;
00178 }
00179
00180
00181 void CSidPlayAppUi::DoBrowseFileL()
00185 {
00186 ELOG1(_L8("CSidPlayAppUi::DoBrowseFileL\n"));
00187
00188 TFileName path;
00189 _LIT(KDefaultDir, "C:\\sid\\");
00190 path.Append(KDefaultDir);
00191
00192 #if defined(__CRYSTAL__)
00193 const TBool success = CCknOpenFileDialog::RunDlgLD(path);
00194 #elif defined(__SERIES60__)
00195
00196
00197
00198
00199
00200
00201 const TBool success = EFalse;
00202 #elif defined(__QUARTZ__)
00203
00204 const TBool success = EFalse;
00205 #else
00206 CDirContentsListBoxModel::TSortOrder order = CDirContentsListBoxModel::EOrderByName;
00207 CEikFileBrowserDialog* browseDialog = new (ELeave)
00208 CEikFileBrowserDialog(path, CEikFileBrowserDialog::EShowSystem, order);
00209 const TBool success = browseDialog->ExecuteLD(R_EIK_DIALOG_FILE_BROWSE);
00210 #endif // __ER6__
00211
00212 if(success)
00213 {
00214
00215 iEikonEnv->InfoMsg(path);
00216
00217
00218 iPlayer->Stop();
00219 const TInt ret = iPlayer->NewTune(path);
00220 if(ret != KErrNone)
00221 {
00222 iEikonEnv->InfoMsg(_L("not good..."));
00223 }
00224
00225 iPlayer->Play();
00226 UpdateCbaL();
00227 }
00228 }
00229
00230
00231 void CSidPlayAppUi::DoScanFilesystemL()
00235 {
00236 ELOG1(_L8("CSidPlayAppUi::DoScanFilesystemL\n"));
00237
00238 _LIT(KSidExtension, "*.sid");
00239 _LIT(KRootDir, "\\");
00240 RFs& fs = Document()->Process()->FsSession();
00241
00242 TFindFile file_finder(fs);
00243 CDir* file_list;
00244 TInt ret = file_finder.FindWildByDir(KSidExtension, KRootDir, file_list);
00245 while(ret==KErrNone)
00246 {
00247 for(TInt i=0; i<file_list->Count(); i++)
00248 {
00249 TParse fullentry;
00250 fullentry.Set((*file_list)[i].iName, &file_finder.File(), NULL);
00251
00252
00253 }
00254 delete file_list;
00255 ret = file_finder.FindWild(file_list);
00256 }
00257 }
00258
00259
00260 void CSidPlayAppUi::HandleCommandL(TInt aCommand)
00266 {
00267 ELOG2(_L8("CSidPlayAppUi::HandleCommandL [aCommand=0x%02x]\n"), aCommand);
00268
00269 TInt delta = 0;
00270 TBuf<0x40> info_string;
00271
00272 switch (aCommand)
00273 {
00274 case EEikCmdFileOpen:
00275 DoBrowseFileL();
00276 break;
00277
00278 case EEikCmdExit:
00279 CBaActiveScheduler::Exit();
00280 break;
00281
00282 case ECmdPrev:
00283 delta = -2;
00284
00285 case ECmdNext:
00286 {
00287 delta += +1;
00288 const TInt song = iPlayer->SongDelta(delta);
00289 info_string.Format(_L("Song %d"), song);
00290 iEikonEnv->InfoMsg(info_string);
00291 iAppView->iStatusView->DrawNow();
00292 break;
00293 }
00294 case ECmdPlay:
00295 iPlayer->Play();
00296 iEikonEnv->InfoMsg(_L("play") );
00297 break;
00298 case ECmdPause:
00299 iPlayer->Pause();
00300 iEikonEnv->InfoMsg(_L("pause") );
00301 break;
00302 case ECmdStop:
00303 iPlayer->Stop();
00304 iEikonEnv->InfoMsg(_L("stop") );
00305 break;
00306
00307 case ECmdAboutSidPlay:
00308 {
00309 #if defined(__SERIES60__)
00310
00311
00312 #else
00313 TBuf<128> title;
00314 TBuf<512> about;
00315 TBuf<16> ver_epoc;
00316 ver_epoc.Copy(TPtrC8((TUint8*)epoc_version));
00317 TBuf<16> ver_base;
00318 ver_base.Copy(TPtrC8((TUint8*)emu_version));
00319 title.AppendFormat(_L("Sidplay %S for SymbianOS"), &ver_epoc);
00320
00321 _LIT(KAbout, "ported by Alfred E. Heggestad\nhttp://esidplay.sourceforge.net/\nBaseversion is %S");
00322 about.Format(KAbout, &ver_base);
00323 (void)CCknInfoDialog::RunDlgLD(title, about);
00324
00325 #endif
00326 }
00327 break;
00328
00329 case ECmdAboutSidTune:
00330 {
00331 sidTune& tune = iPlayer->CurrentSidTune();
00332 struct sidTuneInfo mySidInfo;
00333 tune.getInfo(mySidInfo);
00334
00335 TBuf<256> buf0;
00336 buf0.Copy(TPtrC8((TUint8*)mySidInfo.nameString));
00337
00338 TBuf<256> buf;
00339 buf.AppendFormat(_L("Load addr: 0x%04x\n"), mySidInfo.loadAddr);
00340 buf.AppendFormat(_L("Init addr: 0x%04x\n"), mySidInfo.initAddr);
00341 buf.AppendFormat(_L("Play addr: 0x%04x\n"), mySidInfo.playAddr);
00342 buf.AppendFormat(_L("C64 size: 0x%04x\n"), mySidInfo.c64dataLen);
00343
00344 #if defined(__CRYSTAL__)
00345 (void)CCknInfoDialog::RunDlgLD(buf0, buf);
00346 #else
00347
00348 #endif
00349 }
00350 break;
00351
00352 case ECmdAboutAudio:
00353 {
00354 #if defined(__SERIES60__)
00355
00356 #else
00357 struct emuConfig myEmuConfig;
00358 iPlayer->iEmuEngine->getConfig(myEmuConfig);
00359
00360 _LIT(KAboutAudio, "Audio settings");
00361
00362 TBuf<256> buf;
00363 buf.AppendFormat(_L("Frequency is %d Hz\n"), myEmuConfig.frequency);
00364 buf.AppendFormat(_L("Bits pr. sample is %d\n"), myEmuConfig.bitsPerSample);
00365 buf.AppendFormat(_L("Number of channels is %d\n"), myEmuConfig.channels);
00366 buf.AppendFormat(_L("SID filter is %S\n"), myEmuConfig.emulateFilter ?
00367 &_L("on") : &_L("off") );
00368 buf.AppendFormat(_L("Memory mode is "));
00369 if (myEmuConfig.memoryMode == MPU_PLAYSID_ENVIRONMENT)
00370 buf.AppendFormat(_L("PlaySID\n"));
00371 else if (myEmuConfig.memoryMode == MPU_TRANSPARENT_ROM)
00372 buf.AppendFormat(_L("transparent ROM\n"));
00373 else if (myEmuConfig.memoryMode == MPU_BANK_SWITCHING)
00374 buf.AppendFormat(_L("bank switching\n"));
00375
00376 (void)CCknInfoDialog::RunDlgLD(KAboutAudio, buf);
00377 #endif
00378 }
00379 break;
00380
00381 case ECmdWavDump:
00382 {
00383 if(iPlayer->iAudio->IsWavDumping())
00384 {
00385 const TInt size = iPlayer->iAudio->StopWavDump();
00386 info_string.Format(_L("%d bytes dumped to %S.wav"), size, &iPlayer->iSongName);
00387 iEikonEnv->InfoMsg(info_string);
00388 }
00389 else
00390 {
00391 if(iPlayer->iSongName.Length())
00392 {
00393 const TInt ret = iPlayer->iAudio->StartWavDump(iPlayer->iSongName);
00394 if(ret)
00395 {
00396 info_string.Format(_L("Could not dump (%d)"), ret);
00397 iEikonEnv->InfoMsg(info_string);
00398 }
00399 else
00400 {
00401 info_string.Format(_L("Now dumping to %S.wav"), &iPlayer->iSongName);
00402 iEikonEnv->InfoMsg(info_string);
00403 }
00404 }
00405 }
00406 }
00407 break;
00408
00409 default:
00410 info_string.Format(_L("cmd: %d"), aCommand);
00411 iEikonEnv->InfoMsg(info_string);
00412 break;
00413 }
00414
00415 UpdateCbaL();
00416 }
00417
00418
00419 #if defined(__ER6__)
00420 TKeyResponse
00421 #else
00422 void
00423 #endif
00424 CSidPlayAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode )
00428 {
00429 ELOG2(_L8("CSidPlayAppUi::HandleKeyEventL [code=%d]\n"), aKeyEvent.iCode);
00430
00431 TInt delta = 0;
00432 TBuf<0x40> info_string;
00433
00434 switch(aKeyEvent.iCode)
00435 {
00436 case EKeyUpArrow:
00437 {
00438 const TInt vol = iPlayer->VolumeDelta(+1);
00439 info_string.Format(_L("Volume++ (%d)"), vol);
00440 iEikonEnv->InfoMsg(info_string);
00441 #if defined(__CRYSTAL__)
00442 iAppView->iVolumeView->SetAndDraw(vol);
00443 #endif
00444 break;
00445 }
00446
00447 case EKeyDownArrow:
00448 {
00449 const TInt vol = iPlayer->VolumeDelta(-1);
00450 info_string.AppendFormat(_L("Volume-- (%d)"), vol);
00451 iEikonEnv->InfoMsg(info_string);
00452 #if defined(__CRYSTAL__)
00453 iAppView->iVolumeView->SetAndDraw(vol);
00454 #endif
00455 break;
00456 }
00457
00458 case EKeyLeftArrow:
00459 delta = -2;
00460
00461 case EKeyRightArrow:
00462 {
00463 delta += +1;
00464 const TInt song = iPlayer->SongDelta(delta);
00465 info_string.AppendFormat(_L("Song %d"), song);
00466 iEikonEnv->InfoMsg(info_string);
00467 iAppView->iStatusView->DrawNow();
00468 break;
00469 }
00470
00471 }
00472
00473
00474
00475
00476 if(aKeyEvent.iCode >= '0' && aKeyEvent.iCode <= '9')
00477 {
00478 TBuf<0x40> string;
00479 TInt song = (TInt)(aKeyEvent.iCode - '0');
00480 const TInt ret = iPlayer->SongSelect(song);
00481 if(ret==KErrNone)
00482 {
00483 string.AppendFormat(_L("Song %d"), song);
00484 iEikonEnv->InfoMsg(string);
00485 }
00486 else
00487 {
00488 string.AppendFormat(_L("no song %d !"), song);
00489 iEikonEnv->InfoMsg(string);
00490 }
00491 iAppView->iStatusView->DrawNow();
00492 }
00493
00494 UpdateCbaL();
00495
00496 #if defined(__ER6__)
00497 return EKeyWasConsumed;
00498 #endif
00499 }
00500
00501
00502 TBool CSidPlayAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName, const TDesC8& )
00529 {
00530 TBuf8<256> buf8;
00531 buf8.Copy(aDocumentName);
00532 ELOG3(_L8("ProcessCommandParametersL [cmd=%d, doc=%S]\n"), aCommand, &buf8);
00533
00534 if(aCommand==EApaCommandOpen && aDocumentName.Length())
00535 {
00536
00537 iPlayer->Stop();
00538 const TInt ret = iPlayer->NewTune(aDocumentName);
00539 if(ret != KErrNone)
00540 {
00541 iEikonEnv->InfoMsg(_L("not good..."));
00542 }
00543
00544 iPlayer->Play();
00545 UpdateCbaL();
00546 }
00547
00548
00549 aDocumentName.Zero();
00550
00551
00552
00553
00554
00555
00556
00557 return CEikAppUi::ProcessCommandParametersL(aCommand, aDocumentName);
00558 }
00559
00560
00561 void CSidPlayAppUi::UpdateCbaL()
00565 {
00566 #if defined(__CRYSTAL__)
00567 CEikButtonGroupContainer* cba = iEikonEnv->AppUiFactory()->ToolBar();
00568 if(!cba)
00569 return;
00570
00571
00572
00573
00574 HBufC* text = NULL;
00575 const TInt play_stop_button = 2;
00576 if(iPlayer->iIdlePlay)
00577 {
00578 text = iEikonEnv->AllocReadResourceLC(R_SIDPLAY_STOP);
00579 cba->SetCommandL(play_stop_button, ECmdStop, *text);
00580 }
00581 else
00582 {
00583 text = iEikonEnv->AllocReadResourceLC(R_SIDPLAY_PLAY);
00584 cba->SetCommandL(play_stop_button, ECmdPlay, *text);
00585 }
00586 CleanupStack::PopAndDestroy(text);
00587
00588
00589
00590
00591 if(iPlayer)
00592 {
00593 struct sidTuneInfo mySidInfo;
00594 iPlayer->CurrentSidTune().getInfo( mySidInfo );
00595
00596 const TBool dimmed = (mySidInfo.songs <= 1);
00597
00598 cba->DimCommand(ECmdPrev, dimmed);
00599 cba->DimCommand(ECmdNext, dimmed);
00600 }
00601
00602 cba->DrawNow();
00603
00604 #endif //__CRYSTAL__
00605 }
00606
00607
00611 #if defined(__SERIES60__)
00612 class CSidPlayDocument : public CAknDocument
00613 #else
00614 class CSidPlayDocument : public CEikDocument
00615 #endif
00616 {
00617 public:
00618 CSidPlayDocument(CEikApplication& aApp)
00619 #if defined(__SERIES60__)
00620 :CAknDocument(aApp)
00621 #else
00622 :CEikDocument(aApp)
00623 #endif
00624 {
00625 }
00626 private:
00627 CEikAppUi* CreateAppUiL();
00628 };
00629
00630
00631 CEikAppUi* CSidPlayDocument::CreateAppUiL()
00635 {
00636 return new (ELeave) CSidPlayAppUi;
00637 }
00638
00639
00643 #if defined(__SERIES60__)
00644 class CSidPlayApplication : public CAknApplication
00645 #else
00646 class CSidPlayApplication : public CEikApplication
00647 #endif
00648 {
00649 public:
00650
00651
00652 private:
00653 CApaDocument* CreateDocumentL();
00654 TUid AppDllUid() const;
00655 };
00656
00657
00658 TUid CSidPlayApplication::AppDllUid() const
00662 {
00663 return KMyUid;
00664 }
00665
00666
00667 CApaDocument* CSidPlayApplication::CreateDocumentL()
00671 {
00672 return new (ELeave) CSidPlayDocument(*this);
00673 }
00674
00675
00676 void SidPlayExceptionHandler(TExcType aExc)
00680 {
00681 const TInt back_trace = 4;
00682
00683 _LIT(KTitle, "Sidplay internal error");
00684 TBuf<256> buf;
00685 buf.AppendFormat(_L("Exception code: %d\n"), aExc);
00686
00687 CSidPlayAppUi* ui = (CSidPlayAppUi*)Dll::Tls();
00688 C6510* cpu = ui->iPlayer->iEmuEngine->iThe6510;
00689 TUint16 pc = cpu->abso();
00690 TUint8 op[back_trace];
00691 op[0] = (TUint8)cpu->my_read_data(pc);
00692 op[1] = (TUint8)cpu->my_read_data(pc-1);
00693 op[2] = (TUint8)cpu->my_read_data(pc-2);
00694 op[3] = (TUint8)cpu->my_read_data(pc-3);
00695
00696 ELOG2(_L8("stackIsOkay=%d\n"), cpu->stackIsOkay);
00697 ELOG4(_L8("ac=0x%02x xr=0x%02x yr=0x%02x\n"), cpu->AC, cpu->XR, cpu->YR);
00698 ELOG3(_L8("pc=0x%04x sp=0x%04x\n"), cpu->PC, cpu->SP);
00699 ELOG2(_L8("pc=0x%04x opcodes:\n"), pc);
00700 for(TInt i = 0;i<back_trace;i++)
00701 ELOG3(_L8("0x%04x: 0x%02x\n"), pc-i, op[i]);
00702
00703 #if defined(__CRYSTAL__)
00704 (void)CCknInfoDialog::RunDlgLD(KTitle, buf);
00705 #else
00706 CEikonEnv::InfoWinL(KTitle, buf);
00707
00708 #endif
00709 }
00710
00711
00712
00713
00714
00715
00716 EXPORT_C CApaApplication* NewApplication()
00717 {
00718 ELOG1(_L8("#\n"));
00719 ELOG2(_L8("# Sidplay for SymbianOS version %s\n"), epoc_version);
00720 ELOG2(_L8("# Based on libsidplay version %s\n"), emu_version);
00721 ELOG1(_L8("#\n"));
00722 ELOG2(_L8("# please go to %s for updates and more info.\n"), HOMEPAGE);
00723 ELOG1(_L8("# your bugreports and patches are welcome.\n"));
00724 ELOG2(_L8("# compiled on %s.\n"), __DATE__);
00725 ELOG1(_L8("#\n"));
00726 ELOG1(_L8("NewApplication: "));
00727
00728
00729
00730
00731
00732
00733
00734 CApaApplication* p = new CSidPlayApplication;
00735 ELOG2(_L8("p=0x%08x\n"), p);
00736 return p;
00737 }
00738
00739
00740 GLDEF_C TInt E32Dll(TDllReason )
00744 {
00745 return KErrNone;
00746 }
00747
00748
00749