Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

e32frodo.cpp

Go to the documentation of this file.
00001 
00014 #define OFFSET_X 0
00015 
00016 #include "sysdeps.h"
00017 #include "e32frodo.h"
00018 #include <e32frodo.rsg>
00019 
00020 #include "Prefs.h"
00021 #include "Display.h"
00022 #include "eikinfo.h"
00023 #include <eikon.rsg>
00024 #include <coeutils.h>
00025 #include <apgtask.h>
00026 #include <apgwgnam.h>
00027 #include <eikdll.h>
00028 #include <eikmenup.h>
00029 #include <eikfnlab.h>
00030 #include <gdi.h>
00031 
00032 #ifndef __SERIES60__
00033 #include <eikcfdlg.h>
00034 #endif
00035 
00036 #if defined(__ER6__)
00037 #include <eikspane.h>
00038 #else
00039 #include <eikmenu.hrh>
00040 #endif // __ER6__
00041 
00042 #include "prefsdialog.h"
00043 #include "version"
00044 
00046 #ifdef _UNICODE
00047 const TUid KE32FrodoUid = { 0x10005f47 };
00048 #else
00049 const TUid KE32FrodoUid = { 0x10005f46 };
00050 #endif
00051 
00053 _LIT(KDefaultSnapshot, "C:\\frodo.snap");
00054 
00055 
00056 //
00057 // EXPORTed functions
00058 //
00059 
00060 EXPORT_C CApaApplication* NewApplication()
00061         {
00062         ELOG1(_L8("#\n"));
00063         ELOG2(_L8("# %s\n"), VERSION);
00064         ELOG1(_L8("#\n"));
00065         ELOG2(_L8("# please go to %s for updates and more info.\n"), HOMEPAGE);
00066         ELOG1(_L8("# your bugreports and patches are welcome.\n"));
00067         ELOG2(_L8("# compiled on %s.\n"), __DATE__);
00068         ELOG1(_L8("#\n"));
00069         return new CE32FrodoApplication;
00070         }
00071 
00072 GLDEF_C TInt E32Dll(TDllReason)
00073         {
00074         return KErrNone;
00075         }
00076 
00078 //
00079 // Application class, CE32FrodoApplication
00080 //
00082 
00083 TUid CE32FrodoApplication::AppDllUid() const
00084         {
00085         return KE32FrodoUid;
00086         }
00087 
00088 
00089 CApaDocument* CE32FrodoApplication::CreateDocumentL()
00095         {
00096         return CE32FrodoDocument::NewL(*this);
00097         }
00098 
00099 
00100 TFileName CE32FrodoApplication::GetDriveAndPath()
00104         {
00105         TParsePtrC parse(DllName());
00106         return parse.DriveAndPath();
00107         }
00108 
00109 
00111 //
00112 // Document class, CE32FrodoDocument
00113 //
00115 
00116 
00117 CE32FrodoDocument::CE32FrodoDocument(CEikApplication& aApp)
00121         :CEikDocument(aApp)
00122         {
00123         }
00124 
00125 
00126 CE32FrodoDocument* CE32FrodoDocument::NewL(CEikApplication& aApp)
00127         {
00128         CE32FrodoDocument* self = new (ELeave) CE32FrodoDocument(aApp);
00129         CleanupStack::PushL(self);
00130         self->ConstructL();
00131         CleanupStack::Pop();
00132         return self;
00133         }
00134 
00135 
00136 void CE32FrodoDocument::ConstructL()
00137         {
00138         CTOR(CE32FrodoDocument);
00139         new C64Starter();
00140         }
00141 
00142 
00143 CE32FrodoDocument::~CE32FrodoDocument()
00148         {
00149         DTOR(CE32FrodoDocument);
00150         CloseSTDLIB();
00151         }
00152 
00153 
00154 CEikAppUi* CE32FrodoDocument::CreateAppUiL()
00155         {
00156         CEikAppUi* tmp = new (ELeave) CE32FrodoAppUi;
00157         iAppUiPtr = (CE32FrodoAppUi*)tmp;
00158         return tmp;
00159         }
00160 
00161 #if 0
00162 void CE32FrodoDocument::ShowError(char* str1, char* str2)
00170         {
00171         TBuf<32> str1d;
00172         str1d.Copy(TPtrC8((TText8*)str1));
00173         TBuf<32> str2d;
00174         str2d.Copy(TPtrC8((TText8*)str2));
00175 
00176         RDebug::Print(_L("%S %S"), &str1d, &str2d );
00177         CEikInfoDialog* info = new CEikInfoDialog(str1d, str2d);
00178         if(info)
00179                 {
00180                 TRAPD(ret, info->ExecuteLD(R_EIK_DIALOG_INFO));
00181                 if(ret != KErrNone)
00182                         RDebug::Print(_L("Hmm.") );
00183                 }
00184         else
00185                 RDebug::Print(_L("Ugg.") );
00186         }
00187 
00188 #endif
00189 
00190 
00192 //
00193 // App UI class, CE32FrodoAppUi
00194 //
00196 
00197 CE32FrodoAppUi::CE32FrodoAppUi()
00201         :iMoveRate(1)
00202         {
00203         }
00204 
00205 
00206 void CE32FrodoAppUi::ConstructL()
00210         {
00211         CTOR(CE32FrodoAppUi);
00212 
00214 #if defined(__ER6__)
00215         // This is to disable heap checking fails in debug builds.
00216         // Heap usage should be investigated and make sure that Frodo do not eat memory when running
00217         iCoeEnv->DisableExitChecks(ETrue);
00218 #endif
00219 
00220         BaseConstructL();
00221         iAppView = new (ELeave) CE32FrodoAppView();
00222 
00223         iAppView->ConstructL(ClientRect());
00224 
00226 #if defined(__ER6__)
00227         AddToStackL(iAppView);
00228 #else
00229         CEikFileNameLabel* filenameLabel=STATIC_CAST(CEikFileNameLabel*, iToolBar->ControlById(ECmdFileName));
00230         filenameLabel->UpdateL();
00231 #endif
00232 
00233         iLastC64KeyBufIx = 0; 
00234         iJoyKey = 0xff;
00235 
00236         // panics because iFrodo == NULL
00237 #if 0
00238         Prefs* prefs = E32FrodoDocPtr()->FrodoPtr()->TheC64->ThePrefs;
00239         __ASSERT_ALWAYS(prefs != NULL, User::Panic(_L("NULL-ptr"), KErrBadHandle) );
00240         iAppView->iFullScreenMode = !prefs->iShowToolbar;
00241         ViewToolbar(prefs->iShowToolbar);
00242 #endif
00243         }
00244 
00245 
00246 CE32FrodoAppUi::~CE32FrodoAppUi()
00250         {
00251         DTOR(CE32FrodoAppUi);
00252 #ifndef __ER6__
00253         TRAPD(error,StopHelpL());
00254 #endif
00255         delete iAppView;
00256         }
00257 
00258 
00259 void CE32FrodoAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane )
00271         {
00272         iAppView->iPauseFromUi = ETrue;
00273         SetPauseState();
00274         iAppView->DrawNow();
00275 
00276         switch (aResourceId)
00277                 {
00278                 case R_E32FRODO_TOOLS_MENU:
00279                         break;
00280 
00281                 case R_E32FRODO_VIEW_MENU:
00282                         if (iAppView->iFullScreenMode)
00283                                 {
00284                                 aMenuPane->SetItemButtonState(ECmdFullScreen, EEikMenuItemSymbolOn);
00285                                 }
00286 #if defined(__ER6__)
00287                         if (iAppView->iIsC64ScreenZoomed)
00288                                 {
00289                                 aMenuPane->SetItemButtonState(ECmdScreenZoomed, EEikMenuItemSymbolOn);
00290                                 }
00291                         if (iAppView->iIsC64ScreenStretched)
00292                                 {
00293                                 aMenuPane->SetItemButtonState(ECmdScreenStretched, EEikMenuItemSymbolOn);
00294                                 }
00295 #endif
00296                         break;
00297                 }
00298         }
00299 
00300 
00301 void CE32FrodoAppUi::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool aEmphasis)
00305         {
00306         iAppView->iPauseFromUi = aEmphasis;
00307         SetPauseState();
00308         }
00309 
00310 
00311 void CE32FrodoAppUi::HandleForegroundEventL(TBool aForeground)
00315         {
00316         iAppView->iPauseFromUi = !aForeground;
00317         SetPauseState();
00318 #if defined(__ER6__)
00319         CEikAppUi::HandleForegroundEventL(aForeground);
00320 #endif
00321         }
00322 
00323 
00324 static const char* const KCmdLiteralTable[] =
00325         {
00326         "ECmdFileName=100",
00327         "ECmdPrefs=101",
00328         "ECmdPause=102",
00329         "ECmdReset=103",
00330         "ECmdLimit=104",
00331         "ECmdFullScreen=105",
00332         "ECmdScreenMoveUp=106",
00333         "ECmdScreenMoveDown=107",
00334         "ECmdScreenMoveLeft=108",
00335         "ECmdScreenMoveRight=109",
00336         "ECmdScreenMoveCenter=110",
00337         "ECmdSnapShotSave=111",
00338         "ECmdSnapShotLoad=112",
00339         "ECmdScreenZoomed=113",
00340         "ECmdScreenStretched=114",
00341 
00342         // Debug
00343         "ECmdDebug1=115"
00344         };
00345 
00346 
00347 //#if ((sizeof(KCmdLiteralTable)/sizeof(KCmdLiteralTable[0])) != (ECmdMax - ECmdMin + 1))
00348 //#error please update KCmdLiteralTable when adding commands in e32frodo.hrh
00349 //#endif
00350 
00351 
00352 void CE32FrodoAppUi::HandleCommandL(TInt aCommand)
00357         {
00358         ELOG(if(ECmdMin <= aCommand && aCommand < ECmdMax))
00359                 ELOG3(_L8("handle command '%s' (%d)\n"), KCmdLiteralTable[aCommand-ECmdMin], aCommand);
00360         ELOG(else)
00361                 ELOG2(_L8("handle command %d\n"), aCommand);
00362 
00366         if(ECmdScreenMoveUp <= aCommand && aCommand <= ECmdScreenMoveRight)
00367                 {
00368                 if(aCommand == iLastCommand)
00369                         iMoveRate++;
00370                 else
00371                         iMoveRate = 1;
00372                 }
00373 
00377         switch (aCommand)
00378                 {
00379         case EEikCmdHelpContents:       // Help contents
00380                 {
00381 #ifdef __ER6__
00382 
00383                 iEikonEnv->InfoMsg(_L("TODO: start browser with \\system\\apps\\e32frodo\\e32frodohtlp.htm") );
00384 #else
00385                 StartHelpL();
00386 #endif
00387                 }
00388                 break;
00389 
00390         case EEikCmdHelpAbout:  // About
00391                 {
00392                 iAppView->iPauseFromUi = ETrue;
00393                 SetPauseState();
00394                 iAppView->DrawNow();
00395 
00396                 CEikDialog* aboutDial = new (ELeave) CEikDialog();
00397                 aboutDial->ExecuteLD(R_E32FRODO_ABOUT_DIALOG);
00398 
00399                 iAppView->iPauseFromUi = EFalse;
00400                 SetPauseState();
00401                 iAppView->DrawNow();
00402                 }
00403                 break;
00404 
00405         case ECmdFullScreen:
00406                 {
00407                 SetFullScreenModeL(!iAppView->iFullScreenMode);
00408                 if (!iAppView->iFullScreenMode)
00409                         {
00410                         // Always disable zooming modes if windowed mode is enabled
00411                         iAppView->iIsC64ScreenStretched = EFalse;
00412                         iAppView->iIsC64ScreenZoomed = EFalse;
00413                         iAppView->iOffset = &iAppView->iNormalScreenOffset;
00414                         }
00415 
00416                 iAppView->UpdateDrawPositions();
00417                 iAppView->DrawNow();
00418                 }
00419                 break;
00420 
00421 #if defined (__ER6__)
00422 
00423         case ECmdScreenZoomed:
00424                 iAppView->iIsC64ScreenZoomed = !iAppView->iIsC64ScreenZoomed;
00425                 if (iAppView->iIsC64ScreenZoomed)
00426                         {
00427                         iAppView->iIsC64ScreenStretched = EFalse;
00428                         if (!iAppView->iFullScreenMode)
00429                                 SetFullScreenModeL(ETrue);
00430                         iAppView->iOffset = &iAppView->iZoomedScreenOffset;
00431                         }
00432                 else
00433                         {
00434                         iAppView->iOffset = &iAppView->iNormalScreenOffset;
00435                         }
00436 
00437                 iAppView->UpdateDrawPositions();
00438                 iAppView->DrawNow();
00439                 break;
00440 
00441         case ECmdScreenStretched:
00442                 iAppView->iIsC64ScreenStretched = !iAppView->iIsC64ScreenStretched;
00443                 if (iAppView->iIsC64ScreenStretched)
00444                         {
00445                         iAppView->iIsC64ScreenZoomed = EFalse;
00446                         if (!iAppView->iFullScreenMode)
00447                                 SetFullScreenModeL(ETrue); // Always in full screen mode
00448                         iAppView->iOffset = &iAppView->iStretchedScreenOffset;
00449                         }
00450                 else
00451                         {
00452                         iAppView->iOffset = &iAppView->iNormalScreenOffset;
00453                         }
00454 
00455                 iAppView->UpdateDrawPositions();
00456                 iAppView->DrawNow();
00457                 break;
00458 
00459 #endif // __ER6__
00460 
00461         // Fixed bug of scrolling out of screen (caused kern-exec in zoom and stretch modes).
00462         // Limits may not be right in all modes, but looks to work good enough...
00463         case ECmdScreenMoveUp:
00464                 iAppView->iOffset->iY -= iMoveRate;
00465                 if (iAppView->iOffset->iY < - (DISPLAY_Y - (iAppView->iScreenSize.iHeight/2)))
00466                         iAppView->iOffset->iY = - (DISPLAY_Y - (iAppView->iScreenSize.iHeight/2));
00467                 break;
00468 
00469         case ECmdScreenMoveDown:
00470                 iAppView->iOffset->iY += iMoveRate;
00471                 if (iAppView->iOffset->iY > 0)
00472                         iAppView->iOffset->iY = 0;
00473                 break;
00474 
00475         case ECmdScreenMoveLeft:
00476                 iAppView->iOffset->iX -= iMoveRate;
00477                 if (iAppView->iOffset->iX < - (DISPLAY_X - (iAppView->iScreenSize.iWidth/2)))
00478                         iAppView->iOffset->iX = - (DISPLAY_X - (iAppView->iScreenSize.iWidth/2));
00479                 break;
00480 
00481         case ECmdScreenMoveRight:
00482                 iAppView->iOffset->iX += iMoveRate;
00483                 if (iAppView->iOffset->iX > 0)
00484                         iAppView->iOffset->iX = 0;
00485                 break;
00486 
00487         case ECmdScreenMoveCenter:
00488                 if (iAppView->iIsC64ScreenZoomed)
00489                 // Works for 9210, but have to recheck these calculations...
00490                         iAppView->iOffset->SetXY(
00491                                                  OFFSET_X + ((iAppView->iScreenSize.iWidth-DISPLAY_X*2)/ 4),
00492                                                  (iAppView->iScreenSize.iHeight-DISPLAY_Y*2) / 4 - 1);
00493                 else if (iAppView->iIsC64ScreenStretched)
00494                   // Works for 9210, but have to recheck these calculations...
00495                         iAppView->iOffset->SetXY(
00496                                                  OFFSET_X + ((iAppView->iScreenSize.iWidth-DISPLAY_X*2)/ 4),
00497                                                  ((iAppView->iScreenSize.iHeight-DISPLAY_Y) / 2) + 1 );
00498                 else
00499                         iAppView->iOffset->SetXY(OFFSET_X, ((iAppView->iScreenSize.iHeight-DISPLAY_Y) / 2) + 1 );
00500                 break;
00501 
00502         case ECmdPrefs: // Prefs
00503                 {
00504                 iAppView->iPauseFromUi = ETrue;
00505                 SetPauseState();
00506                 iAppView->DrawNow();
00507 
00508                 // Open Prefs dialog box
00509                 C64* c64 = E32FrodoDocPtr()->FrodoPtr()->TheC64;
00510 
00511                 CPrefsDialog* prefsDial = new (ELeave) CPrefsDialog(c64);
00512                 prefsDial->ExecuteLD(R_TDLG_DIALOG_FOCUS);
00513 
00514                 iAppView->iPauseFromUi = EFalse;
00515                 SetPauseState();
00516                 iAppView->DrawNow();
00517                 }
00518                 break;
00519 
00520         case ECmdPause: // Pause
00521                 {
00522                 iAppView->iPause = !iAppView->iPause;
00523                 SetPauseState();
00524                 if(iAppView->iPause)
00525                         iEikonEnv->InfoMsg(_L("pause on") );
00526                 else
00527                         iEikonEnv->InfoMsg(_L("pause off") );
00528                 }
00529                 break;
00530 
00531         case ECmdReset: // Reset
00532                 {
00533                 if(E32FrodoDocPtr()->FrodoPtr() == NULL)
00534                         break;
00535 
00536                 // Reset the C64
00537                 E32FrodoDocPtr()->FrodoPtr()->TheC64->Reset();
00538                 _LIT(KResetMessage, "reset");
00539                 iEikonEnv->InfoMsg(KResetMessage);
00540                 iAppView->UpdateDrawPositions();
00541                 }
00542                 break;
00543 
00544         case ECmdLimit: // Toggle Limit
00545                 {
00546                 bool& limit = E32FrodoDocPtr()->FrodoPtr()->TheC64->ThePrefs.LimitSpeed;
00547                 limit = !limit;
00548 
00549                 TBuf<32> txt;
00550                 txt.Format(_L("limit %s"), limit ? "on" : "off");
00551                 iEikonEnv->InfoMsg(txt);
00552                 }
00553                 break;
00554 
00555         case EEikCmdExit:
00556                 // stop the emulation and the destroy all the objects. Goodbye
00557                 if(E32FrodoDocPtr()->FrodoPtr())
00558                         {
00559                         E32FrodoDocPtr()->FrodoPtr()->TheC64->Quit();
00560                         delete E32FrodoDocPtr()->FrodoPtr();
00561                         }
00562                 Exit();
00563                 break;
00564 
00565         case ECmdSnapShotSave:
00566                 {
00567 #ifdef __SERIES60__
00568                 _LIT(KNotYet, "Not yet...");
00569                 iEikonEnv->InfoMsg(KNotYet);
00570 #else
00571                 iAppView->iPauseFromUi = ETrue;
00572                 SetPauseState();
00573 
00574                 TFileName file;
00575                 file.Copy(KDefaultSnapshot);
00576                 CEikFileSaveAsDialog* save = new CEikFileSaveAsDialog(&file);
00577                 if (save->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
00578                         {
00579                         iCurrentFile.Copy(file);
00580                         iSnapState = ESnapShotSave;
00581                         ELOG2(_L8("snapshot saved as '%S'\n"), &iCurrentFile);
00582                         }
00583 
00584                 iAppView->iPauseFromUi = EFalse;
00585                 SetPauseState();
00586 #endif // __SERIES60__
00587                 }
00588                 break;
00589 
00590         case ECmdSnapShotLoad:
00591                 {
00592 #ifdef  __SERIES60__
00593                 _LIT(KNotYet, "Not yet...");
00594                 iEikonEnv->InfoMsg(KNotYet);
00595 #else
00596                 iAppView->iPauseFromUi = ETrue;
00597                 SetPauseState();
00598 
00599                 TFileName file;
00600                 file.Copy(KDefaultSnapshot);
00601                 CEikFileOpenDialog* load = new CEikFileOpenDialog(&file);
00602                 if (load->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
00603                         {
00604                         iCurrentFile.Copy(file);
00605                         iSnapState = ESnapShotLoad;
00606                         ELOG2(_L8("snapshot loaded '%S'\n"), &iCurrentFile);
00607                         }
00608 
00609                 iAppView->iPauseFromUi = EFalse;
00610                 SetPauseState();
00611 #endif // __SERIES60__
00612                 }
00613                 break;
00614 
00615                 // For Debug
00616                 case ECmdDebug1: // Toggle showing debug info
00617 #ifdef _DEBUG
00618                         iAppView->iShowDebugInfo = !iAppView->iShowDebugInfo;
00619 #endif
00620                         break;
00621 
00622         default:
00623                 break;
00624 
00625                 } // switch(aCommand)
00626 
00627 
00631         if(ECmdScreenMoveUp <= aCommand && aCommand <= ECmdScreenMoveCenter)
00632                 {
00633                 iAppView->UpdateDrawPositions();
00634                 TBuf<64> buf;
00635                 buf.AppendFormat(_L("offset (%d,%d)"), iAppView->iOffset->iX, iAppView->iOffset->iY);
00636                 iEikonEnv->InfoMsg(buf);
00637                 }
00638 
00639         iLastCommand = aCommand;
00640         }
00641 
00642 
00643 void CE32FrodoAppUi::SetFullScreenModeL(TBool aFullScreenMode)
00647         {
00648         __ASSERT_DEBUG(E32FrodoDocPtr()->FrodoPtr()->TheC64, User::Panic(_L("NULL-ptr"), KErrBadHandle) );
00649         Prefs& prefs = E32FrodoDocPtr()->FrodoPtr()->TheC64->ThePrefs;
00650         prefs.iShowToolbar = !aFullScreenMode;
00651         iAppView->iFullScreenMode = aFullScreenMode;
00652 
00653 #if defined(__ER6__)
00654         // View the image on the full screen view or on the normal view
00655         iEikonEnv->AppUiFactory()->ToolBar()->MakeVisible(!iAppView->iFullScreenMode);
00656         CEikStatusPane* statusp = iEikonEnv->AppUiFactory()->StatusPane();
00657         if (statusp)
00658                 statusp->MakeVisible(!iAppView->iFullScreenMode);
00659         iAppView->SetRect(iEikonEnv->EikAppUi()->ClientRect());
00660 
00661 #endif
00662         ViewToolbar(prefs.iShowToolbar);
00663         }
00664 
00665 
00666 void CE32FrodoAppUi::OpenFileL(const TDesC& aFileName)
00672         {
00673         TBuf8<256> buf8;
00674         buf8.Copy(aFileName);
00675         ELOG2(_L8("OpenFileL [doc=%S]\n"), &buf8);
00676 
00677         if (ConeUtils::FileExists(aFileName))
00678                 {
00679                 iCurrentFile.Copy(buf8);
00680                 iSnapState = ESnapShotLoad;
00681                 }
00682         }
00683 
00684 
00685 TBool CE32FrodoAppUi::ProcessCommandParametersL(TApaCommand aCommand, TFileName& aDocumentName,const TDesC8& /*aTail*/)
00712         {
00713         TBuf8<256> buf8;
00714         buf8.Copy(aDocumentName);
00715         ELOG3(_L8("ProcessCommandParametersL [cmd=%d, doc=%S]\n"), aCommand, &buf8);
00716 
00717         if(aCommand==EApaCommandOpen && aDocumentName.Length())
00718                 {
00719                 iCurrentFile.Copy(buf8);
00720                 iSnapState = ESnapShotLoad;
00721                 }
00722 
00723         // This prevents unnecessary zero length document files from being created
00724         aDocumentName.Zero();
00725 /*
00726 0       EApaCommandOpen,
00727 1       EApaCommandCreate,
00728 2       EApaCommandRun,
00729 3       EApaCommandBackground,
00730 */
00731         return CEikAppUi::ProcessCommandParametersL(aCommand, aDocumentName);
00732         }
00733 
00734 
00735 #if defined(__ER6__)
00736 TKeyResponse
00737 #else
00738 void
00739 #endif
00740 CE32FrodoAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00746         {
00747         iAppView->iBgUpdate = ETrue;
00748 
00749         if (aKeyEvent.iModifiers&EModifierCapsLock)
00750                 {
00751                 TInt joyDelta=0;
00752                 switch(aKeyEvent.iScanCode)
00753                         {
00754                 case EStdKeyLeftCtrl:
00755                         joyDelta=0x10;
00756                         break;
00757 
00758                 case EStdKeyUpArrow:
00759                         joyDelta=0x1;
00760                         break;
00761 
00762                 case EStdKeyDownArrow:
00763                         joyDelta=0x2;
00764                         break;
00765 
00766                 case EStdKeyLeftArrow:
00767                         joyDelta=0x4;
00768                         break;
00769 
00770                 case EStdKeyRightArrow:
00771                         joyDelta=0x8;
00772                         break;
00773                         }
00774 
00775                 switch( aType )
00776                         {
00777                 case EEventKeyDown:
00778                         iJoyKey&=0xff^joyDelta;
00779                         break;
00780                 case EEventKeyUp:
00781                         iJoyKey|=joyDelta;
00782                         break;
00783                 default:
00784                         break;
00785                         }
00786 
00787                 if (joyDelta!=0)
00788                         {
00789 #if defined (__ER6__)
00790                         return EKeyWasConsumed;
00791 #else
00792                         return;
00793 #endif
00794                         }
00795                 }
00796 
00797         TInt c64Key;
00798 
00799         // if c64key == -1 then skip
00800         if (aType == EEventKey || aType == EEventKeyDown)
00801                 {
00802                 c64Key = C64Display::VirtKey2C64(aKeyEvent, iJoyKey);
00803 
00804                 if(iJoyKey != 0xff)
00805 
00806                 if (c64Key < 0 || c64Key >= 256)        // joykey
00807 #if defined (__ER6__)
00808                         return EKeyWasNotConsumed;
00809 #else
00810                         return;
00811 #endif
00812 
00813                 if (keystate[c64Key])
00814 #if defined (__ER6__)
00815                         return EKeyWasNotConsumed;
00816 #else
00817                         return;
00818 #endif
00819 
00820                 // store key in buf
00821                 if(iLastC64KeyBufIx >= KKeyBufSize)
00822                         {
00823 #if defined (__ER6__)
00824                         return EKeyWasNotConsumed;
00825 #else
00826                         return;
00827 #endif
00828                         }
00829                 else iLastC64KeyBuf[iLastC64KeyBufIx++] = c64Key;
00830 
00831                 keystate[c64Key] = 1;
00832                 int c64_byte = c64Key >> 3;
00833                 int c64_bit = c64Key & 7;
00834                 int shifted = c64Key & 128;
00835                 c64_byte &= 7;
00836                 if (shifted) {
00837                         key_matrix[6] &= 0xef;
00838                         rev_matrix[4] &= 0xbf;
00839                         }
00840                 key_matrix[c64_byte] &= ~(1 << c64_bit);
00841                 rev_matrix[c64_bit] &= ~(1 << c64_byte);
00842 
00843 
00844                 }
00845         else if (aType == EEventKeyUp)
00846                 {
00847 
00848                 iJoyKey = 0xff;
00849 
00850                 if(iLastC64KeyBufIx <= 0)
00851                         {
00852 #if defined (__ER6__)
00853                         return EKeyWasNotConsumed;
00854 #else
00855                         return;
00856 #endif
00857                         }
00858                 else c64Key = iLastC64KeyBuf[--iLastC64KeyBufIx];
00859 
00860                 if (c64Key < 0 || c64Key >= 256) // joykey
00861 #if defined (__ER6__)
00862                         return EKeyWasNotConsumed;
00863 #else
00864                         return;
00865 #endif
00866                 if (!keystate[c64Key])
00867 #if defined (__ER6__)
00868                         return EKeyWasNotConsumed;
00869 #else
00870                         return;
00871 #endif
00872 
00873                 keystate[c64Key] = 0;
00874                 int c64_byte = c64Key >> 3;
00875                 int c64_bit = c64Key & 7;
00876                 int shifted = c64Key & 128;
00877                 c64_byte &= 7;
00878                 if (shifted) {
00879                         key_matrix[6] |= 0x10;
00880                         rev_matrix[4] |= 0x40;
00881                         }
00882                 key_matrix[c64_byte] |= (1 << c64_bit);
00883                 rev_matrix[c64_bit] |= (1 << c64_byte);
00884                 }
00885 
00886 #if defined (__ER6__)
00887         return EKeyWasNotConsumed;
00888 #endif
00889         } // end, CE32FrodoAppUi::HandleKeyEventL
00890 
00891 
00892 void CE32FrodoAppUi::SetPauseState()
00896         {
00897         if (E32FrodoDocPtr() && E32FrodoDocPtr()->FrodoPtr() && E32FrodoDocPtr()->FrodoPtr()->TheC64)
00898                 {
00899                 TBool paused = E32FrodoDocPtr()->FrodoPtr()->TheC64->Paused();
00900                 TBool mustPause = iAppView->iPause || iAppView->iPauseFromUi;
00901                 if ((mustPause && !paused) || (!mustPause && paused))
00902                         E32FrodoDocPtr()->FrodoPtr()->TheC64->TogglePause();
00903                 }
00904         }
00905 
00906 
00907 //
00908 // copied from helloeik.cpp
00909 //
00910 
00911 #ifndef __ER6__
00912 
00913 _LIT(KHelp, ".hlp");
00914 _LIT(KMatch, "- %S");
00915 
00916 void CE32FrodoAppUi::StartHelpL()
00917         {
00918         // get the help filename
00919         TFileName appFileName = Application()->AppFullName();
00920         TParse fileNameParser;
00921         fileNameParser.SetNoWild(KHelp, &appFileName, NULL);
00922         TPtrC helpFileFullName = fileNameParser.FullName();
00923         if (!ConeUtils::FileExists(helpFileFullName))
00924                 User::Leave(KErrNotFound);
00925         // scan through open programs
00926         TPtrC helpFileName=fileNameParser.Name();
00927         HBufC* matchString=HBufC::NewLC(2 + helpFileName.Length());
00928         matchString->Des().Format(KMatch , &helpFileName);
00929         TApaTaskList taskList (iEikonEnv->WsSession());
00930         TInt numGroups = iEikonEnv->WsSession().NumWindowGroups(0);
00931         for (TInt index=0; index < numGroups; index++)
00932                 {
00933                 // get task information
00934                 TApaTask* task= new (ELeave) TApaTask(taskList.FindByPos(index));
00935                 CleanupStack::PushL(task);
00936                 CApaWindowGroupName* wgName=
00937                                 CApaWindowGroupName::NewLC(iEikonEnv->WsSession(),task->WgId());
00938                 TUid uid = wgName->AppUid();
00939                 TPtrC taskCaption = wgName->Caption();
00940                 // check help app, and with right caption
00941                 TBool found =
00942                                 uid.iUid == 0x10000171 && // help app
00943                                 taskCaption.FindF(*matchString)>=0; // matching caption
00944                 // bring to foreground if we found it
00945                 if (found)
00946                         {
00947                         task->BringToForeground();
00948                         CleanupStack::PopAndDestroy(3); // wgName, task, matchString
00949                         return; // exit procedure
00950                         }
00951                 CleanupStack::PopAndDestroy(2); // wgName, task
00952                 }
00953         CleanupStack::PopAndDestroy(); // matchString
00954         // if not found, then open the help database
00955         EikDll::StartDocL(helpFileFullName);
00956         User::After(1000000); // pause 1 second to give a decent time to start
00957         }
00958 
00959 
00960 void CE32FrodoAppUi::StopHelpL()
00961         {
00962         // get the help filename
00963         TFileName appFileName = Application()->AppFullName();
00964         TParse fileNameParser;
00965         fileNameParser.SetNoWild(KHelp, &appFileName, NULL);
00966         TPtrC helpFileFullName = fileNameParser.FullName();
00967         if (!ConeUtils::FileExists(helpFileFullName))
00968                 return;
00969         // scan through open programs
00970         TPtrC helpFileName=fileNameParser.Name();
00971         HBufC* matchString=HBufC::NewLC(2 + helpFileName.Length());
00972         matchString->Des().Format(KMatch, &helpFileName);
00973         TApaTaskList taskList (iEikonEnv->WsSession());
00974         TInt numGroups = iEikonEnv->WsSession().NumWindowGroups(0);
00975         for (TInt index=0; index < numGroups; index++)
00976                 {
00977                 // get task information
00978                 TApaTask* task= new (ELeave) TApaTask(taskList.FindByPos(index));
00979                 CleanupStack::PushL(task);
00980                 CApaWindowGroupName* wgName=
00981                                 CApaWindowGroupName::NewLC(iEikonEnv->WsSession(),task->WgId());
00982                 TUid uid = wgName->AppUid();
00983                 TPtrC taskCaption = wgName->Caption();
00984                 // check help app, and with right caption
00985                 TBool found =
00986                                 uid.iUid == 0x10000171 && // help app
00987                                 taskCaption.FindF(*matchString)>=0; // matching caption
00988                 // bring to foreground if we found it
00989                 if (found)
00990                         {
00991                         task->EndTask();
00992                         CleanupStack::PopAndDestroy(3); // wgName, task, matchString
00993                         return; // exit procedure
00994                         }
00995                 CleanupStack::PopAndDestroy(2); // wgName, task
00996                 }
00997         CleanupStack::PopAndDestroy(); // matchString
00998         }
00999 
01000 #endif // !__ER6__
01001 
01002 
01003 void CE32FrodoAppUi::ViewToolbar(TBool aView)
01007         {
01008 #if defined(__ER6__)
01009         iAppView->SetRect(ClientRect());
01010         (void)aView;
01011 #else
01012         iToolBar->MakeVisible(aView);
01013         TRAPD(ret, iAppView->SetRectL(ClientRect()));
01014         (void)ret;
01015 #endif // __ER6__
01016         }
01017 
01018 
01019 //
01020 // Application view class, CE32FrodoAppView
01021 //
01022 
01023 
01024 void CE32FrodoAppView::ConstructL(const TRect& aRect)
01028         {
01029         CTOR(CE32FrodoAppView);
01030 
01031         CreateWindowL();
01032 #if defined(__ER6__)
01033         SetRect(aRect);
01034 #else
01035         SetRectL(aRect);
01036 #endif
01037         ActivateL();
01038         iBgUpdate = ETrue;
01039 
01040 #ifdef _DEBUG
01041         static const char* const KDispModeTable[] =
01042                 {
01043                 "None",
01044                 "Gray2",
01045                 "Gray4",
01046                 "Gray16",
01047                 "Gray256",
01048                 "Color16",
01049                 "Color256",
01050                 "Color64K",
01051                 "Color16M",
01052                 "Rgb",
01053                 "Color4K"
01054                 };
01055 #endif // _DEBUG
01056 
01057         //
01058         // check graphic capabilities (colors/grey)
01059         //
01060 
01061         iScreenSize = iCoeEnv->ScreenDevice()->SizeInPixels();
01062         ELOG3(_L8("Screen size is %d x %d\n"), iScreenSize.iWidth, iScreenSize.iHeight);
01063 
01064 #if !defined(__WINS__) && defined(__ER6__)
01065         TPckgBuf<TScreenInfoV01> info;
01066         UserSvr::ScreenInfo(info);
01067         iHWScreenAddress = (TUint16*)(info().iScreenAddress);
01068         iHWScreenAddress[0] = TUint16(2 << 12);
01069         iHWScreenAddress += 16;
01070 #endif
01071 
01072         iDispMode = iCoeEnv->ScreenDevice()->DisplayMode();
01073         ELOG3(_L8("Display mode is '%s' (%d)\n"), (size_t)iDispMode > sizeof(KDispModeTable)/sizeof(KDispModeTable[0])
01074                 ? "out of bounds"
01075                 : KDispModeTable[iDispMode], iDispMode );
01076 
01077         iIsColorMachine = (iDispMode >= EColor16);
01078         ELOG2(_L8("Color machine: %s\n"), iIsColorMachine ? "Yes" : "No" );
01079         ELOG2(_L8("COLOR_DEPTH macro is %d\n"), COLOR_DEPTH);
01080 
01081         // Select the right display mode
01082 #if COLOR_DEPTH == 4
01083         iDispMode = iIsColorMachine ? EColor16 : EGray16;
01084 #elif COLOR_DEPTH == 8
01085         iDispMode = iIsColorMachine ? EColor256 : EGray256;
01086 #elif COLOR_DEPTH == 12
01087         Not supported yet!
01088 #elif COLOR_DEPTH == 24
01089         Not supported yet!
01090 #endif
01091 
01092         TInt ret = KErrNone;
01093 
01094 #if defined(__ER5__)
01095         // set the new display type to 16 colors/grey
01096         RDrawableWindow* win = DrawableWindow();
01097         ret = win->SetRequiredDisplayMode(iDispMode);
01098         if(ret != KErrNone)
01099                 {
01100                 ELOG2(_L8("could not set disp mode [ret=%d]"), ret);
01101                 User::Leave(ret);
01102                 }
01103 #endif // __ER5__
01104 
01105         // Create the BitMap
01106 
01107 #if COLOR_DEPTH == 4
01108         ret = iTheBitMap.Create(TSize(DISPLAY_X*2, DISPLAY_Y), iDispMode);      //AEH 991203
01109 #elif COLOR_DEPTH == 8
01110 
01111 #if defined(__ER6__) 
01112 
01113         iMyBufferSize = TSize(DISPLAY_X, DISPLAY_Y);
01114         iMyScreenBuffer = new (ELeave) TUint8[iMyBufferSize.iWidth * iMyBufferSize.iHeight];
01115 
01116         iMyColorTable =  new (ELeave) TUint16[256];
01117         for (TInt i=0; i<256; i++)
01118                 iMyColorTable[i] = 0;
01119 
01120         iMyColorTable[0x00] = 0x000; // black
01121         iMyColorTable[0x0f] = 0xfff; // white
01122         iMyColorTable[0x02] = 0xa00; // dark red
01123         iMyColorTable[0x0a] = 0x0fd; // cyan
01124         iMyColorTable[0x08] = 0xd0d; // purple
01125         iMyColorTable[0x04] = 0x4d4; // dark green
01126         iMyColorTable[0x0c] = 0x10a; // dark blue
01127         iMyColorTable[0x06] = 0xff0; // yellow
01128         iMyColorTable[0x03] = 0xb50; // brown
01129         iMyColorTable[0x0b] = 0x630; // dark brown
01130         iMyColorTable[0x05] = 0xf66; // light red
01131         iMyColorTable[0x01] = 0x444; // dark grey
01132         iMyColorTable[0x0d] = 0x888; // med grey
01133         iMyColorTable[0x07] = 0x6f6; // light green
01134         iMyColorTable[0x09] = 0x77f; // light blue
01135         iMyColorTable[0x0e] = 0xccc; // light grey
01136 
01137 #else // __ER6__
01138 
01139         // for ER5 - NetBook/Series7
01140         ret = iTheBitMap.Create(TSize(DISPLAY_X, DISPLAY_Y), iDispMode);        //AEH 991203
01141 
01142 #endif // __ER6__
01143 
01144 #elif // COLOR_DEPTH
01145 error
01146 #endif // COLOR_DEPTH
01147 
01148         // did it work?
01149         if(ret != KErrNone)
01150                 {
01151                 ELOG2(_L8("could not create BitMap [ret=%d]"), ret);
01152                 User::Leave(ret);
01153                 }
01154 
01155         _LIT(KFrodoFont, "Swiss");
01156         TFontSpec spec(KFrodoFont, 213);
01157         iSpeedFont = iCoeEnv->CreateScreenFontL(spec);
01158 
01159         // calculate screensize and offsets
01160         iNormalScreenOffset.SetXY(OFFSET_X, ((iScreenSize.iHeight-DISPLAY_Y) / 2) +1) ;
01161         iZoomedScreenOffset.SetXY(OFFSET_X - 32, ((iScreenSize.iHeight-DISPLAY_Y) / 2) +1) ;
01162         iStretchedScreenOffset.SetXY(OFFSET_X - 32, ((iScreenSize.iHeight-DISPLAY_Y) / 2) +1) ;
01163         iOffset = &iNormalScreenOffset;
01164 
01165         // rectangle for inner C64 screen
01166         iC64screen.SetRect(TPoint(0x20, 0x23), TPoint(0x160, 0xeb));
01167 
01168 #if defined(__ER6__) 
01169 #ifdef __WINS__
01170 
01171         iWinsScreenBitmap = new (ELeave) CFbsBitmap;
01172         ret = iWinsScreenBitmap->Create(TSize(640, 200/*DISPLAY_X, DISPLAY_Y*/), EColor4K);
01173         if(ret != KErrNone)
01174                 {
01175                 ELOG2(_L8("could not create BitMap [ret=%d]"), ret);
01176                 User::Leave(ret);
01177                 }
01178 
01179 #endif // __WINS__
01180 
01181 #ifdef _DEBUG
01182         iShowDebugInfo = EFalse;
01183 #endif
01184 
01185 #endif // __ER6__
01186 
01188         iFullScreenMode = EFalse;
01189         iPauseFromUi = EFalse;
01190         iPause = EFalse;
01191 
01192         UpdateDrawPositions();
01193 
01194         } // end, CE32FrodoAppView::ConstructL
01195 
01196 
01197 CE32FrodoAppView::~CE32FrodoAppView()
01201         {
01202         DTOR(CE32FrodoAppView);
01203 
01204         // release fonts
01205         iCoeEnv->ReleaseScreenFont(iSpeedFont);
01206 
01207 #if defined(__ER6__)
01208 
01209 #ifdef __WINS__
01210         delete iWinsScreenBitmap;
01211 #endif
01212         delete[] iMyColorTable;
01213         delete[] iMyScreenBuffer;
01214 #endif // __ER6__
01215 
01216         }
01217 
01218 
01219 void CE32FrodoAppView::FocusChanged(TDrawNow aDrawNow)
01223         {
01224         iPauseFromUi = !IsFocused();
01225         CCoeControl::FocusChanged(aDrawNow);
01226         }
01227 
01228 
01229 //
01230 // The following patch from mooz@welho.com for Psion Revo
01231 //
01232 
01233 void CE32FrodoAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
01237         {
01238         ELOG3(_L8("GUI: pointer event [x=%d, y=%d]\n"),
01239                 aPointerEvent.iPosition.iX,
01240                 aPointerEvent.iPosition.iY);
01241 
01242 /* Added for revo by mooz */
01243 
01244         // change offset
01245         iOffset->iX = aPointerEvent.iPosition.iX - (DISPLAY_X/2);
01246         iOffset->iY = aPointerEvent.iPosition.iY - (DISPLAY_Y/2);
01247 
01248         iBgUpdate = ETrue;
01249         UpdateDrawPositions();
01250         }
01251 
01252 
01253 void CE32FrodoAppView::DrawBuf(bool bg_update)
01261         {
01262 
01263         //
01264         // keep the emulation running but dont update the screen
01265         //
01266 //      if(iAppView->iPauseFromUi)
01267 //              return;
01268 
01269 #if defined(__ER6__)
01270 
01271         if (iIsC64ScreenZoomed)
01272                 DrawDirectZoomed(bg_update);
01273         else if (iIsC64ScreenStretched)
01274                 DrawDirectStretched(bg_update);
01275         else
01276                 DrawDirect(bg_update);
01277 
01278 #else // __ER6__
01279 
01280         if(bg_update)
01281                 iBgUpdate = ETrue;
01282 
01283         // Activate Graphics Context and get system
01284         ActivateGc();
01285         CWindowGc& gc = SystemGc();
01286 
01287         if(iBgUpdate)   // draw the whole screen
01288                 {
01289                 // Draw the bitmap here
01290                 gc.BitBlt(*iOffset, &iTheBitMap);
01291                 iBgUpdate = EFalse;
01292                 }
01293         else    // only draw inner screen
01294                 {
01295                 gc.BitBlt(*iOffset+TPoint(0x20, 0x23), &iTheBitMap, iC64screen );
01296                 }
01297 
01298         // Deactivate Graphics Context
01299         DeactivateGc();
01300 
01301 #endif // __ER6__
01302 
01303         }
01304 
01305 
01306 void CE32FrodoAppView::UpdateDrawPositions()
01307         {
01308 
01309 #if defined(__ER6__)
01310 
01311         iMyBufferAddress = iMyScreenBuffer;
01312         iMyBufferAddress2 = iMyScreenBuffer;
01313         TSize zoomedMyBufferSize (iMyBufferSize.iWidth*2, iMyBufferSize.iHeight*2);
01314         TRect zoomedC64screen(iC64screen.iTl, TSize(iC64screen.Width()*2, iC64screen.Height()*2));
01315         TSize stretchedMyBufferSize (iMyBufferSize.iWidth*2, iMyBufferSize.iHeight);
01316         TRect stretchedC64screen(iC64screen.iTl, TSize(iC64screen.Width()*2, iC64screen.Height()));
01317 
01318         // Get the drawable area.
01319         // Start with the whole screen
01320         iDrawableArea = TRect(TPoint(0,0), iScreenSize);
01321         // Shrink area according to view offset
01322         iDrawableArea.iTl += *iOffset + PositionRelativeToScreen();
01323         // Limit area to the window area
01324         iDrawableArea.Intersection(TRect(PositionRelativeToScreen(), Size()));
01325         // Commodore 64 outer and inner screen area
01326         TRect c64OuterScreenArea(*iOffset + PositionRelativeToScreen(), iMyBufferSize);
01327         TRect c64InnerScreenArea(c64OuterScreenArea.iTl + iC64screen.iTl, iC64screen.Size());
01328         TRect zoomedC64OuterScreenArea = c64OuterScreenArea;
01329         TRect zoomedC64InnerScreenArea = c64InnerScreenArea;
01330         if (iIsC64ScreenZoomed)
01331                 {
01332                 //zoomedC64OuterScreenArea = TRect(iOffset + PositionRelativeToScreen() + iScreenMoveOffset, zoomedMyBufferSize);
01333                 zoomedC64OuterScreenArea = TRect(*iOffset + PositionRelativeToScreen(), zoomedMyBufferSize);
01334                 zoomedC64InnerScreenArea = TRect(c64OuterScreenArea.iTl + zoomedC64screen.iTl, zoomedC64screen.Size());
01335                 }
01336         if (iIsC64ScreenStretched)
01337                 {
01338                 zoomedC64OuterScreenArea = TRect(*iOffset + PositionRelativeToScreen(), stretchedMyBufferSize);
01339                 zoomedC64InnerScreenArea = TRect(c64OuterScreenArea.iTl + zoomedC64screen.iTl, stretchedC64screen.Size());
01340                 }
01341 
01342         // *** Calc values for outer bitmap drawing
01343 
01344         iDrawableArea.Intersection(zoomedC64OuterScreenArea);
01345         iDrawableArea.Intersection(TRect(iScreenSize)); //This operation is not needed??
01346 
01347         // Calc starting point in screen
01348         iScreenStartOffset = iDrawableArea.iTl.iY * iScreenSize.iWidth + iDrawableArea.iTl.iX;
01349 
01350         // Calc starting point in buffer
01351         TPoint c64ScreenBufferStartingPoint;
01352         c64ScreenBufferStartingPoint.iX = Max(0, (iDrawableArea.iTl.iX - c64OuterScreenArea.iTl.iX));
01353         c64ScreenBufferStartingPoint.iY = Max(0, (iDrawableArea.iTl.iY - c64OuterScreenArea.iTl.iY));
01354         TInt c64ScreenBufferStartAddress = c64ScreenBufferStartingPoint.iY * iMyBufferSize.iWidth + c64ScreenBufferStartingPoint.iX;
01355         iMyBufferAddress += c64ScreenBufferStartAddress;
01356 
01357         // Calc jump offsets after drawing a line
01358         iJumpInPixelsInScreen = iScreenSize.iWidth - iDrawableArea.Width();
01359         if (iIsC64ScreenZoomed||iIsC64ScreenStretched)
01360                 iJumpInPixelsInBuffer = iMyBufferSize.iWidth -iDrawableArea.Width()/2;
01361         else
01362                 iJumpInPixelsInBuffer = iMyBufferSize.iWidth -iDrawableArea.Width();
01363 
01364 
01365         // *** Calc values for inner bitmap drawing
01366 
01367         // Calc starting point in screen
01368         iDrawableArea2 = iDrawableArea;
01369         iDrawableArea2.Intersection(zoomedC64InnerScreenArea);
01370         iScreenStartOffset2 = iDrawableArea2.iTl.iY * iScreenSize.iWidth + iDrawableArea2.iTl.iX;
01371 
01372         // Calc starting point in buffer
01373         TPoint c64ScreenBufferStartingPoint2;
01374         c64ScreenBufferStartingPoint2.iX = Max(0, (iDrawableArea2.iTl.iX - c64InnerScreenArea.iTl.iX));
01375         c64ScreenBufferStartingPoint2.iY = Max(0, (iDrawableArea2.iTl.iY - c64InnerScreenArea.iTl.iY));
01376         TInt c64ScreenBufferStartAddress2 = c64ScreenBufferStartingPoint2.iY * iMyBufferSize.iWidth + c64ScreenBufferStartingPoint2.iX;
01377         iMyBufferAddress2 += c64ScreenBufferStartAddress2;
01378 
01379         // Calc jump offsets after drawing a line
01380         iJumpInPixelsInScreen2 = iScreenSize.iWidth - iDrawableArea2.Width();
01381         TInt widthInBuffer2 = iDrawableArea2.iBr.iX - c64ScreenBufferStartingPoint2.iX;
01382         if (iIsC64ScreenZoomed||iIsC64ScreenStretched)
01383                 widthInBuffer2 = iDrawableArea2.iBr.iX/2 - c64ScreenBufferStartingPoint2.iX;
01384         iJumpInPixelsInBuffer2 = iMyBufferSize.iWidth - widthInBuffer2;
01385 
01386 
01387 #else // __ER6__
01388 
01390 
01391 #endif // __ER6__
01392 
01393         // clear the screen
01394         ActivateGc();
01395         CWindowGc& gc = SystemGc();
01396         gc.Clear(TRect(0, 0, iScreenSize.iWidth, iScreenSize.iHeight));
01397         DeactivateGc();
01398         }
01399 
01400 
01401 #if defined (__ER6__)
01402 
01403 void CE32FrodoAppView::DrawDirect(bool bg_update)
01412         {
01413         TRect drawableArea;
01414         TUint8* myBufferAddress;
01415         TUint16* screenAddress;
01416         TInt jumpInPixelsInScreen;
01417         TInt jumpInPixelsInBuffer;
01418         TInt screenOffset;
01419 
01420 
01421         if(bg_update)
01422                 {
01423                 drawableArea = iDrawableArea;
01424                 myBufferAddress = iMyBufferAddress;
01425                 screenOffset = iScreenStartOffset;
01426                 jumpInPixelsInScreen = iJumpInPixelsInScreen;
01427                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer;
01428                 }
01429         else
01430                 {
01431                 drawableArea = iDrawableArea2;
01432                 myBufferAddress = iMyBufferAddress2;
01433                 screenOffset = iScreenStartOffset2;
01434                 jumpInPixelsInScreen = iJumpInPixelsInScreen2;
01435                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer2;
01436                 }
01437 
01438 #ifdef __WINS__
01439         CWindowGc& gc = SystemGc();
01440         TBitmapUtil bmUtil(iWinsScreenBitmap);
01441         bmUtil.Begin(TPoint(0,0));
01442         ActivateGc();
01443 
01444         screenAddress = (TUint16*)iWinsScreenBitmap->DataAddress();
01445 
01446         // Clear bitmap
01447         TUint16* tmpScreenAddress = screenAddress;
01448         TInt numTotalPixels = iWinsScreenBitmap->SizeInPixels().iWidth * iWinsScreenBitmap->SizeInPixels().iHeight;
01449         for(TInt k = 0; k < numTotalPixels; k++)
01450                 *tmpScreenAddress++ = 0;
01451 
01452         //screenAddress += screenOffset; /// @todo (alfredh)
01453         drawableArea.Move(-PositionRelativeToScreen()); // !! Useless?
01454 
01455 
01456 #else
01457         screenAddress = iHWScreenAddress;
01458         screenAddress += screenOffset;
01459 #endif
01460 
01461         for(TInt j = drawableArea.iTl.iY; j < drawableArea.iBr.iY; j++)
01462                 {
01463                 for(TInt i = drawableArea.iTl.iX; i < drawableArea.iBr.iX; i++)
01464                         {
01465                         *screenAddress++ = iMyColorTable[*myBufferAddress++];
01466                         }
01467                 screenAddress += (jumpInPixelsInScreen);
01468                 myBufferAddress += (jumpInPixelsInBuffer);
01469                 }
01470 
01471 #ifdef __WINS__
01472 
01473         // Activate Graphics Context and get system
01474 
01475         // Use rect so that speed and debug info is visible
01476         TRect rect(iWinsScreenBitmap->SizeInPixels());
01477         rect.iBr.iX = DISPLAY_X;
01478         gc.BitBlt(TPoint(0,0), iWinsScreenBitmap, rect);
01479         DeactivateGc();
01480         bmUtil.End();
01481 
01482 #endif
01483         }
01484 
01485 void CE32FrodoAppView::DrawDirectStretched(bool bg_update)
01494         {
01495         TRect drawableArea;
01496         TUint8* myBufferAddress;
01497         TUint16* screenAddress;
01498         TInt jumpInPixelsInScreen;
01499         TInt jumpInPixelsInBuffer;
01500         TInt screenOffset;
01501 
01502 
01503         if(bg_update)
01504                 {
01505                 drawableArea = iDrawableArea;
01506                 myBufferAddress = iMyBufferAddress;
01507                 screenOffset = iScreenStartOffset;
01508                 jumpInPixelsInScreen = iJumpInPixelsInScreen;
01509                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer;
01510                 }
01511         else
01512                 {
01513                 drawableArea = iDrawableArea2;
01514                 myBufferAddress = iMyBufferAddress2;
01515                 screenOffset = iScreenStartOffset2;
01516                 jumpInPixelsInScreen = iJumpInPixelsInScreen2;
01517                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer2;
01518                 }
01519 
01520 
01521 #ifdef __WINS__
01522         CWindowGc& gc = SystemGc();
01523         TBitmapUtil bmUtil(iWinsScreenBitmap);
01524         bmUtil.Begin(TPoint(0,0));
01525         ActivateGc();
01526 
01527         screenAddress = (TUint16*)iWinsScreenBitmap->DataAddress();
01528 
01529         // Clear bitmap
01530         TUint16* tmpScreenAddress = screenAddress;
01531         TInt numTotalPixels = iWinsScreenBitmap->SizeInPixels().iWidth * iWinsScreenBitmap->SizeInPixels().iHeight;
01532         for(TInt k = 0; k < numTotalPixels; k++)
01533                 *tmpScreenAddress++ = 0;
01534 
01535         screenAddress += screenOffset;
01536         drawableArea.Move(-PositionRelativeToScreen());
01537 
01538 #else
01539         screenAddress = iHWScreenAddress;
01540         screenAddress += screenOffset;
01541 #endif
01542 
01543         for(TInt j = drawableArea.iTl.iY; j < drawableArea.iBr.iY; j++)
01544                 {
01545                 for(TInt i = drawableArea.iTl.iX; i < drawableArea.iBr.iX; i+=2)
01546                         {
01547                         // Draw double horisontal pixels
01548                         TUint16 colorValue = iMyColorTable[*myBufferAddress++];
01549                         *screenAddress++ = colorValue;
01550                         *screenAddress++ = colorValue;
01551                         }
01552                 screenAddress += (jumpInPixelsInScreen);
01553                 myBufferAddress += (jumpInPixelsInBuffer);
01554                 }
01555 
01556 #ifdef __WINS__
01557 
01558         gc.BitBlt(TPoint(0,0), iWinsScreenBitmap);
01559         DeactivateGc();
01560         bmUtil.End();
01561 
01562 #endif
01563         }
01564 
01565 
01566 void CE32FrodoAppView::DrawDirectZoomed(bool bg_update)
01575         {
01576         TRect drawableArea;
01577         TUint8* myBufferAddress;
01578         TUint16* screenAddress;
01579         TInt jumpInPixelsInScreen;
01580         TInt jumpInPixelsInBuffer;
01581         TInt screenOffset;
01582 
01583         if(bg_update)
01584                 {
01585                 drawableArea = iDrawableArea;
01586                 myBufferAddress = iMyBufferAddress;
01587                 screenOffset = iScreenStartOffset;
01588                 jumpInPixelsInScreen = iJumpInPixelsInScreen;
01589                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer;
01590                 }
01591         else
01592                 {
01593                 drawableArea = iDrawableArea2;
01594                 myBufferAddress = iMyBufferAddress2;
01595                 screenOffset = iScreenStartOffset2;
01596                 jumpInPixelsInScreen = iJumpInPixelsInScreen2;
01597                 jumpInPixelsInBuffer = iJumpInPixelsInBuffer2;
01598                 }
01599 
01600 
01601 #ifdef __WINS__
01602         CWindowGc& gc = SystemGc();
01603         TBitmapUtil bmUtil(iWinsScreenBitmap);
01604         bmUtil.Begin(TPoint(0,0));
01605         ActivateGc();
01606 
01607         screenAddress = (TUint16*)iWinsScreenBitmap->DataAddress();
01608 
01609         // Clear bitmap
01610         TUint16* tmpScreenAddress = screenAddress;
01611         TInt numTotalPixels = iWinsScreenBitmap->SizeInPixels().iWidth * iWinsScreenBitmap->SizeInPixels().iHeight;
01612         for(TInt k = 0; k < numTotalPixels; k++)
01613                 *tmpScreenAddress++ = 0;
01614 
01615         screenAddress += screenOffset;
01616         drawableArea.Move(-PositionRelativeToScreen());
01617 #else
01618         screenAddress = iHWScreenAddress;
01619         screenAddress += screenOffset;
01620 #endif
01621 
01622         TUint32 scanlineLength_Align4 = (drawableArea.Width() << 1) & 0xffffffc;
01623         for(TInt j = drawableArea.iTl.iY; j < drawableArea.iBr.iY; j=j+2)
01624                 {
01625                 TUint16 scanline2x[640]; // For 9210
01626                 TUint16* scanline2xPos = scanline2x;
01627                 TUint16* lineStartAddress = screenAddress;
01628                 for(TInt i = drawableArea.iTl.iX; i < drawableArea.iBr.iX; i=i+2)
01629                         {
01630                         // Draw double horisontal pixels
01631                         TUint16 pixelValue = iMyColorTable[*myBufferAddress++];
01632                         *scanline2xPos++ = pixelValue;
01633                         *scanline2xPos++ = pixelValue;
01634                         screenAddress = screenAddress + 2;
01635                         }
01636                 // draw double scanline
01637                 Mem::Move(lineStartAddress, scanline2x, scanlineLength_Align4);
01638                 screenAddress += (jumpInPixelsInScreen);
01639                 Mem::Move(screenAddress, scanline2x, scanlineLength_Align4);
01640                 screenAddress += (iScreenSize.iWidth);
01641 
01642                 myBufferAddress += (jumpInPixelsInBuffer);
01643                 }
01644 
01645 #ifdef __WINS__
01646 
01647         gc.BitBlt(TPoint(0,0), iWinsScreenBitmap);
01648         DeactivateGc();
01649         bmUtil.End();
01650 
01651 #endif
01652         }
01653 
01654 #endif // (__ER6__)
01655 
01656 
01657 void CE32FrodoAppView::DrawSpeed(int speed, int max_speed)
01658         {
01659 
01660         // Do not draw speed in zoomed modes
01661         if (iIsC64ScreenZoomed || iIsC64ScreenStretched)
01662                 return;
01663 
01664 #define SPEED_TEXT_POS  TPoint(395, 20)
01665 
01666         // Deactivate Graphics Context and get Windows Context and clear
01667         ActivateGc();
01668         CWindowGc& gc = SystemGc();
01669         TRect clearRect;
01670 
01671 #ifdef _DEBUG
01672         if (iShowDebugInfo)
01673                 {
01674                 clearRect = TRect(
01675                                   SPEED_TEXT_POS.iX+20,
01676                                   SPEED_TEXT_POS.iY-15,
01677                                   SPEED_TEXT_POS.iX+180,
01678                                   SPEED_TEXT_POS.iY+170
01679                                   );
01680                 }
01681         else
01682 #endif
01683                 {
01684                 clearRect = TRect(
01685                                   SPEED_TEXT_POS.iX+30,
01686                                   SPEED_TEXT_POS.iY-15,
01687                                   SPEED_TEXT_POS.iX+100,
01688                                   SPEED_TEXT_POS.iY+30
01689                                   );
01690                 }
01691 
01692         gc.Clear(clearRect);
01693         // set color for text
01694         gc.SetPenColor( TRgb::Color16(0) );
01695         gc.UseFont(iSpeedFont);
01696 
01697         // format speed info and print it
01698         TBuf<64> txt;
01699         txt.Format(_L("spd: %d%c"), speed, '%');
01700         gc.DrawText(txt, SPEED_TEXT_POS);
01701 
01702         txt.Format(_L("max: %d%c"), max_speed, '%');
01703         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 20) );
01704 
01705 #ifdef _DEBUG
01706         if (!iShowDebugInfo)
01707                 {
01708                 // Deactivate Graphics Context
01709                 DeactivateGc();
01710                 return;
01711                 }
01712 
01713         // Show audio debug info
01714         if (!iSidDebugData)
01715                 {
01716                 txt.Format(_L("No audio"));
01717                 gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 40) );
01718                 DeactivateGc();
01719                 return;
01720                 }
01721 
01722         TUint elapsedTime_ms = (User::TickCount() - iSidDebugData->iPrevTickCount) * (iSidDebugData->iTickPeriod_ys2/1000);
01723         TInt rateHz = 0;
01724         if (elapsedTime_ms)
01725                 rateHz = (1000 * (iSidDebugData->iCountSamplesCopied - iSidDebugData->iPrevCountSamplesCopied)) / elapsedTime_ms;
01726         txt.Format(_L("Lead:%d"), iSidDebugData->iLeadInBlocks);
01727         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 40) );
01728         txt.Format(_L("smp:%d k"), iSidDebugData->iCountSamplesCopied/1000);
01729         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 60) );
01730         txt.Format(_L("rate:%d Hz"), rateHz);
01731         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 80) );
01732         txt.Format(_L("pcmp:%d,xtra:%d"), iSidDebugData->iPlayCompleteCounter, iSidDebugData->iCountExtraBlocks);
01733         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 100) );
01734         txt.Format(_L("Add:%d,norm:%d,skip:%d"), iSidDebugData->iCountDuplicatedBlocks,
01735                    iSidDebugData->iCountNormalBlocks,
01736                    iSidDebugData->iCountSkippedBlocks);
01737         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 120) );
01738         txt.Format(_L("Vol:%d"), iSidDebugData->iLastVolumeSet);
01739         gc.DrawText(txt, SPEED_TEXT_POS + TPoint(0, 140) );
01740 
01741         iSidDebugData->iPrevTickCount = User::TickCount();
01742         iSidDebugData->iPrevCountSamplesCopied = iSidDebugData->iCountSamplesCopied;
01743 
01744 #endif // _DEBUG
01745 
01746         // Deactivate Graphics Context
01747         DeactivateGc();
01748 
01749         } // end, CE32FrodoAppView::DrawSpeed
01750 
01751 
01755 enum
01756         {
01757         LED_OFF,        
01758         LED_ON,         
01759         LED_ERROR_ON,   
01760         LED_ERROR_OFF   
01761         };
01762 
01763 
01770 void CE32FrodoAppView::DrawLed(TPoint aPos, TInt aState)
01771         {
01772         if (iIsC64ScreenZoomed || iIsC64ScreenStretched)
01773                 return;
01774 
01775         ActivateGc();
01776         CWindowGc& gc = SystemGc();
01777 
01778         gc.SetPenStyle(CGraphicsContext::ENullPen);
01779         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
01780 
01781         TRgb brushColor;
01782 
01783         switch(aState)
01784                 {
01785                 case LED_OFF: brushColor = KRgbDarkGreen; break;
01786                 case LED_ERROR_OFF: brushColor = KRgbDarkRed; break;
01787                 case LED_ON: brushColor = KRgbGreen; break;
01788                 case LED_ERROR_ON: brushColor = KRgbRed; break;
01789                 }
01790 
01791         gc.SetBrushColor(brushColor);
01792         gc.DrawEllipse(TRect(aPos, TSize(8,8)));
01793 
01794         DeactivateGc();
01795         }
01796 
01797 
01798 //
01799 // class C64Starter
01800 //
01801 // This class starts the Emulation asynchronously
01802 //
01803 C64Starter::C64Starter()
01804         :CActive(EPriorityLow)
01805         {
01806         CActiveScheduler::Add(this);
01807         SetActive();
01808         TRequestStatus* ref = &iStatus;
01809         User::RequestComplete(ref, KErrNone);
01810         }
01811 
01812 void C64Starter::RunL()
01813         {
01814         CE32FrodoDocument* doc = (CE32FrodoDocument*)CEikonEnv::Static()->EikAppUi()->Document();
01815 
01816         if (doc->iFrodo==NULL)
01817                 {
01818                 doc->iFrodo = Frodo::NewL(doc);
01819                 }
01820 
01821         if(doc->FrodoPtr() != NULL)
01822                 {
01823                 doc->FrodoPtr()->StartC64();
01824                 }
01825 
01826         Deque();
01827         delete this;
01828         }
01829 
01830 void C64Starter::DoCancel()
01831         {
01832         }
01833 
01834 
01835 // EOF - E32FRODO.CPP

Generated on Tue Feb 8 04:07:52 2005 for E32frodo by doxygen 1.3.3