+++ /dev/null
-// mainloop with window server event handling\r
-// event polling mechnism was taken from\r
-// Peter van Sebille's projects\r
-\r
-// (c) Copyright 2006, notaz\r
-// All Rights Reserved\r
-\r
-#include <hal.h>\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <sys/time.h>\r
-\r
-#include "debug.h"\r
-\r
-#include "pico/picoInt.h"\r
-#include "vid.h"\r
-#include "SimpleServer.h"\r
-#include "ClientServer.h"\r
-//#include "polledAS.h"\r
-#include "audio.h"\r
-\r
-#include <EZlib.h>\r
-#include "zlib/gzio_symb.h"\r
-\r
-\r
-#define BENCHMARK\r
-//#define TEST_FRAMEBUFF\r
-\r
-// keycodes we care about\r
-enum TPxxxKeyCodes {\r
- EKeyPxxxPower = EKeyDevice0, //0xF842\r
- EKeyPxxxBrowser = EKeyApplication0,\r
- EKeyPxxxCamera = EKeyApplication1,\r
- EKeyPxxxJogUp = EKeyDevice1,\r
- EKeyPxxxJogDown = EKeyDevice2,\r
- EKeyPxxxJogLeft = EKeyDevice3,\r
- EKeyPxxxJogRight = EKeyDevice9,\r
- EKeyPxxxJogInward= EKeyDevice8,\r
- // FC keys\r
- //EKeyPxxxFcOk = EKeyDevice8, // don't care about FC keycodes\r
-};\r
-// EKeyScreenDimension1 ~ EStdKeyF24 is sent when flip is closed,\r
-// EKeyScreenDimension0 ~ EStdKeyF23 when opened\r
-\r
-enum TMotAKeyCodes {\r
- EKeyMotAUp = EKeyDevice4, //0xF846\r
- EKeyMotADown = EKeyDevice5,\r
- EKeyMotALeft = EKeyDevice6,\r
- EKeyMotARight = EKeyDevice7,\r
- EKeyMotASelect = EKeyDevice8,\r
- EKeyMotAButton1 = EKeyApplicationA,\r
- EKeyMotAButton2 = EKeyApplicationB,\r
- EKeyMotAHome = EKeyApplication0,\r
- EKeyMotAShortcut = EKeyApplication1,\r
- EKeyMotAVoice = EKeyDeviceA,\r
- EKeyMotACamera = EKeyDeviceB,\r
- EKeyMotAVolUp = EKeyIncVolume,\r
- EKeyMotAVolDn = EKeyDecVolume,\r
- EKeyMotASend = EKeyYes,\r
- EKeyMotAEnd = EKeyNo,\r
-};\r
-\r
-// scancodes we care about\r
-enum TPxxxScanCodes {\r
- EScanPxxxPower = EStdKeyDevice0, // 0xa4\r
- EScanPxxxBrowser = EStdKeyApplication0,\r
- EScanPxxxCamera = EStdKeyApplication1,\r
- EScanPxxxJogUp = EStdKeyDevice1,\r
- EScanPxxxJogDown = EStdKeyDevice2,\r
- EScanPxxxJogLeft = EStdKeyDeviceE, // not consistent\r
- EScanPxxxJogRight = EStdKeyDeviceD,\r
- EScanPxxxJogInward= EStdKeyDevice8,\r
- // FC keys\r
- EScanPxxxFcOk = EStdKeyDeviceF,\r
- EScanPxxxFcBack = EStdKeyDevice3,\r
- EScanPxxxFcC = EStdKeyDeviceA,\r
- EScanPxxxFcMenu = EStdKeyDevice9,\r
- EScanPxxxFc0 = '0',\r
- EScanPxxxFc1 = '1',\r
- EScanPxxxFc2 = '2',\r
- EScanPxxxFc3 = '3',\r
- EScanPxxxFc4 = '4',\r
- EScanPxxxFc5 = '5',\r
- EScanPxxxFc6 = '6',\r
- EScanPxxxFc7 = '7',\r
- EScanPxxxFc8 = '8',\r
- EScanPxxxFc9 = '9',\r
- EScanPxxxFcHash = EStdKeyHash,\r
- EScanPxxxFcAsterisk= EStdKeyNkpAsterisk,\r
-};\r
-\r
-enum TMotAScanCodes {\r
- EScanMotAUp = EStdKeyDevice4,\r
- EScanMotADown = EStdKeyDevice5,\r
- EScanMotALeft = EStdKeyDevice6,\r
- EScanMotARight = EStdKeyDevice7,\r
- EScanMotASelect = EStdKeyDevice8,\r
- EScanMotAButton1 = EStdKeyApplicationA,\r
- EScanMotAButton2 = EStdKeyApplicationB,\r
- EScanMotAHome = EStdKeyApplication0,\r
- EScanMotAShortcut = EStdKeyApplication1,\r
- EScanMotAVoice = EStdKeyDeviceA,\r
- EScanMotACamera = EStdKeyDeviceB,\r
- EScanMotAVolUp = EStdKeyIncVolume,\r
- EScanMotAVolDn = EStdKeyDecVolume,\r
- EScanMotASend = EStdKeyYes,\r
- EScanMotAEnd = EStdKeyNo,\r
- // some extra codes, don't know if these are actually used\r
- EScanMotAExtra = EStdKeyApplicationC,\r
- EScanMotAEsc = EStdKeyApplicationD,\r
- EScanMotAStart = EStdKeyApplicationE,\r
- EScanMotASelect2 = EStdKeyApplicationF,\r
-};\r
-\r
-\r
-// list of key names and codes\r
-TPicoKeyConfigEntry keyConfigPXXX[] = {\r
- { EKeyPxxxPower, EScanPxxxPower, 0, -1, -1, "POWER" }, // 0\r
- { EKeyPxxxBrowser, EScanPxxxBrowser, 0, -1, -1, "BROWSER" },\r
- { EKeyPxxxCamera, EScanPxxxCamera, 0, -1, -1, "CAMERA" },\r
- { EKeyPxxxJogUp, EScanPxxxJogUp, 2, -1, -1, "JOG@UP" },\r
- { EKeyPxxxJogDown, EScanPxxxJogDown, 2, -1, -1, "JOG@DOWN" },\r
- { EKeyPxxxJogLeft, EScanPxxxJogLeft, 0, -1, -1, "JOG@LEFT" }, // 5\r
- { EKeyPxxxJogRight, EScanPxxxJogRight, 0, -1, -1, "JOG@RIGHT" },\r
- { 0, EScanPxxxJogInward, 0, -1, -1, "JOG@INWARD" },\r
- { 0, EScanPxxxFcOk, 0, -1, -1, "FC@OK" },\r
- { 0, EScanPxxxFcBack, 0, -1, -1, "FC@BACK" },\r
- { 0, EScanPxxxFcC, 0, -1, -1, "FC@C" }, // 10\r
- { 0, EScanPxxxFcMenu, 0, -1, -1, "FC@MENU" },\r
- { 0, EScanPxxxFc0, 0, -1, -1, "FC@0" },\r
- { 0, EScanPxxxFc1, 0, -1, -1, "FC@1" },\r
- { 0, EScanPxxxFc2, 0, -1, -1, "FC@2" },\r
- { 0, EScanPxxxFc3, 0, -1, -1, "FC@3" },\r
- { 0, EScanPxxxFc4, 0, -1, -1, "FC@4" },\r
- { 0, EScanPxxxFc5, 0, -1, -1, "FC@5" },\r
- { 0, EScanPxxxFc6, 0, -1, -1, "FC@6" },\r
- { 0, EScanPxxxFc7, 0, -1, -1, "FC@7" },\r
- { 0, EScanPxxxFc8, 0, -1, -1, "FC@8" },\r
- { 0, EScanPxxxFc9, 0, -1, -1, "FC@9" },\r
- { 0, EScanPxxxFcHash, 0, -1, -1, "FC@HASH" },\r
- { 0, EScanPxxxFcAsterisk,0, -1, -1, "FC@AST" },\r
- { 0, 0, 0, 0, 0, 0 }\r
-};\r
-\r
-// Motorola A92x & A1000 support\r
-TPicoKeyConfigEntry keyConfigMotA[] = {\r
- { EKeyMotAUp, EScanMotAUp, 0, -1, -1, "UP" }, // 0\r
- { EKeyMotADown, EScanMotADown, 0, -1, -1, "DOWN" },\r
- { EKeyMotALeft, EScanMotALeft, 0, -1, -1, "LEFT" },\r
- { EKeyMotARight, EScanMotARight, 0, -1, -1, "RIGHT" },\r
- { EKeyMotASelect, EScanMotASelect, 0, -1, -1, "SELECT" },\r
- { EKeyMotAButton1, EScanMotAButton1, 0, -1, -1, "BUTTON1" }, // 5\r
- { EKeyMotAButton2, EScanMotAButton2, 0, -1, -1, "BUTTON2" },\r
- { EKeyMotAHome, EScanMotAHome, 0, -1, -1, "HOME" },\r
- { EKeyMotAShortcut, EScanMotAShortcut, 0, -1, -1, "SHORTCUT" },\r
- { EKeyMotAVoice, EScanMotAVoice, 0, -1, -1, "VOICE" },\r
- { EKeyMotACamera, EScanMotACamera, 0, -1, -1, "CAMERA" }, // 10\r
- { EKeyMotAVolUp, EScanMotAVolUp, 0, -1, -1, "VOL@UP" },\r
- { EKeyMotAVolDn, EScanMotAVolDn, 0, -1, -1, "VOL@DOWN" },\r
- { EKeyMotASend, EScanMotASend, 0, -1, -1, "SEND" },\r
- { EKeyMotAEnd, EScanMotAEnd, 0, -1, -1, "END" },\r
- { 0, EScanMotAExtra, 0, -1, -1, "EXTRA" },\r
- { 0, EScanMotAEsc, 0, -1, -1, "ESC" },\r
- { 0, EScanMotAStart, 0, -1, -1, "START" },\r
- { 0, EScanMotASelect2, 0, -1, -1, "SELECT" },\r
- { 0, 0, 0, 0, 0, 0 }\r
-};\r
-\r
-\r
-// list of areas\r
-TPicoAreaConfigEntry areaConfig[] = {\r
- { TRect( 0, 0, 0, 0) },\r
- // small corner bottons\r
- { TRect( 0, 0, 15, 15) },\r
- { TRect(192, 0, 207, 15) },\r
- { TRect( 0, 304, 15, 319) },\r
- { TRect(192, 304, 207, 319) },\r
- // normal buttons\r
- { TRect( 0, 0, 68, 63) },\r
- { TRect( 69, 0, 138, 63) },\r
- { TRect(139, 0, 207, 63) },\r
- { TRect( 0, 64, 68, 127) },\r
- { TRect( 69, 64, 138, 127) },\r
- { TRect(139, 64, 207, 127) },\r
- { TRect( 0, 128, 68, 191) },\r
- { TRect( 69, 128, 138, 191) },\r
- { TRect(139, 128, 207, 191) },\r
- { TRect( 0, 192, 68, 255) },\r
- { TRect( 69, 192, 138, 255) },\r
- { TRect(139, 192, 207, 255) },\r
- { TRect( 0, 256, 68, 319) },\r
- { TRect( 69, 256, 138, 319) },\r
- { TRect(139, 256, 207, 319) },\r
- { TRect( 0, 0, 0, 0) }\r
-};\r
-\r
-// PicoPad[] format: SACB RLDU\r
-const char *actionNames[] = {\r
- "UP", "DOWN", "LEFT", "RIGHT", "B", "C", "A", "START",\r
- 0, 0, 0, 0, 0, 0, 0, 0, // Z, Y, X, MODE (enabled only when needed), ?, ?, ?, ?\r
- 0, 0, 0, 0, 0, 0, "NEXT@SAVE@SLOT", "PREV@SAVE@SLOT", // ?, ?, ?, ?, mot_vol_up, mot_vol_down, next_slot, prev_slot\r
- 0, 0, "PAUSE@EMU", "SAVE@STATE", "LOAD@STATE", "FRAMESKIP@8", "AUTO@FRAMESKIP", "DONE" // ?, switch_renderer\r
-};\r
-\r
-\r
-// globals are allowed, so why not to (ab)use them?\r
-TInt machineUid = 0;\r
-int gamestate = PGS_Paused, gamestate_prev = PGS_Paused;\r
-TPicoConfig currentConfig;\r
-TPicoKeyConfigEntry *keyConfig = 0; // currently used keys\r
-static char noticeMsg[64]; // notice msg to draw\r
-static timeval noticeMsgTime = { 0, 0 }; // when started showing\r
-static RLibrary gameAudioLib; // audio object library\r
-static _gameAudioNew gameAudioNew; // audio object maker\r
-static IGameAudio *gameAudio = 0; // the audio object itself\r
-static TProcessId launcherProcessId;\r
-static int reset_timing, state_slot = 0;\r
-extern const char *RomFileName;\r
-extern int pico_was_reset; \r
-#ifdef TEST_FRAMEBUFF\r
-static TUint8 *iFrameBuffer = 0;\r
-#endif\r
-\r
-// some forward declarations\r
-static void MainInit();\r
-static void MainExit();\r
-static void CheckForLauncher();\r
-static void DumpMemInfo();\r
-\r
-// just for a nicer grouping of WS related stuff\r
-class CGameWindow\r
-{\r
-public:\r
- static void ConstructResourcesL();\r
- static void FreeResources();\r
- static void DoKeys(timeval &time);\r
- static void DoKeysConfig(TUint &which);\r
- static void RunEvents(TUint32 which);\r
- static void SendClientWsEvent(TInt type);\r
-\r
- static RWsSession iWsSession;\r
- static RWindowGroup iWsWindowGroup;\r
- static RWindow iWsWindow;\r
- static CWsScreenDevice* iWsScreen;\r
- static CWindowGc* iWindowGc;\r
- static TRequestStatus iWsEventStatus;\r
- static TThreadId iLauncherThreadId;\r
- static RDirectScreenAccess* iDSA;\r
- static TRequestStatus iDSAstatus;\r
-};\r
-\r
-\r
-void SkipFrame(int do_sound)\r
-{\r
- PicoSkipFrame=1;\r
- PicoFrame();\r
- PicoSkipFrame=0;\r
-\r
- if(do_sound && PsndOut) {\r
- PsndOut = gameAudio->NextFrameL();\r
- if(!PsndOut) { // sound output problems?\r
- strcpy(noticeMsg, "SOUND@OUTPUT@ERROR;@SOUND@DISABLED");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- }\r
-\r
-/*\r
- int total=0;\r
-\r
- // V-Blanking period:\r
- if (Pico.video.reg[1]&0x20) SekInterrupt(6); // Set IRQ\r
- Pico.video.status|=0x88; // V-Int happened / go into vblank\r
- total+=SekRun(18560);\r
-\r
- // Active Scan:\r
- if (Pico.video.reg[1]&0x40) Pico.video.status&=~8; // Come out of vblank if display is enabled\r
- SekInterrupt(0); // Clear IRQ\r
- total+=SekRun(127969-total);\r
-*/\r
-}\r
-\r
-\r
-void TargetEpocGameL()\r
-{\r
- char buff[24]; // fps count c string\r
- struct timeval tval; // timing\r
- int thissec = 0, frames_done = 0, frames_shown = 0;\r
- int target_fps, target_frametime, too_fast, too_fast_time;\r
- int i, underflow;\r
- TRawEvent blevent;\r
-\r
- MainInit();\r
- buff[0] = 0;\r
-\r
- // just to keep the backlight on..\r
- blevent.Set(TRawEvent::EActive);\r
-\r
- // loop?\r
- for(;;) {\r
- if(gamestate == PGS_Running) {\r
- // prepare window and stuff\r
- CGameWindow::ConstructResourcesL();\r
-\r
- // if the system has something to do, it should better do it now\r
- User::After(50000);\r
- //CPolledActiveScheduler::Instance()->Schedule();\r
-\r
- // pal/ntsc might have changed, reset related stuff\r
- if(Pico.m.pal) {\r
- target_fps = 50;\r
- if(!noticeMsgTime.tv_sec) strcpy(noticeMsg, "PAL@SYSTEM@/@50@FPS");\r
- } else {\r
- target_fps = 60;\r
- if(!noticeMsgTime.tv_sec) strcpy(noticeMsg, "NTSC@SYSTEM@/@60@FPS");\r
- }\r
- target_frametime = 1000000/target_fps;\r
- if(!noticeMsgTime.tv_sec && pico_was_reset)\r
- gettimeofday(¬iceMsgTime, 0);\r
-\r
- pico_was_reset = too_fast = 0;\r
- reset_timing = 1;\r
-\r
- while(gamestate == PGS_Running) {\r
- gettimeofday(&tval, 0);\r
- if(reset_timing) {\r
- reset_timing = 0;\r
- thissec = tval.tv_sec;\r
- frames_done = tval.tv_usec/target_frametime;\r
- }\r
-\r
- // show notice message?\r
- char *notice = 0;\r
- if(noticeMsgTime.tv_sec) {\r
- if((tval.tv_sec*1000000+tval.tv_usec) - (noticeMsgTime.tv_sec*1000000+noticeMsgTime.tv_usec) > 2000000) // > 2.0 sec\r
- noticeMsgTime.tv_sec = noticeMsgTime.tv_usec = 0;\r
- else notice = noticeMsg;\r
- }\r
-\r
- // second changed?\r
- if(thissec != tval.tv_sec) {\r
-#ifdef BENCHMARK\r
- static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4];\r
- if(++bench == 10) {\r
- bench = 0;\r
- bench_fps_s = bench_fps;\r
- bf[bfp++ & 3] = bench_fps;\r
- bench_fps = 0;\r
- }\r
- bench_fps += frames_shown;\r
- sprintf(buff, "%02i/%02i/%02i", frames_shown, bench_fps_s, (bf[0]+bf[1]+bf[2]+bf[3])>>2);\r
-#else\r
- if(currentConfig.iFlags & 2) \r
- sprintf(buff, "%02i/%02i", frames_shown, frames_done);\r
-#endif\r
- thissec = tval.tv_sec;\r
- if((thissec & 7) == 7) UserSvr::AddEvent(blevent);\r
- // in is quite common for this implementation to leave 1 fame unfinished\r
- // when second changes. This creates sound clicks, so it's probably better to\r
- // skip that frame and render sound\r
- if(PsndOut && frames_done < target_fps && frames_done > target_fps-5) {\r
- SkipFrame(1); frames_done++;\r
- }\r
- // try to prevent sound buffer underflows by making sure we did _exactly_\r
- // target_fps sound updates and copying last samples over and over again\r
- if(PsndOut && frames_done < target_fps)\r
- for(; frames_done < target_fps; frames_done++) {\r
- PsndOut = gameAudio->DupeFrameL(underflow);\r
- if(!PsndOut) { // sound output problems?\r
- strcpy(noticeMsg, "SOUND@OUTPUT@ERROR;@SOUND@DISABLED");\r
- gettimeofday(¬iceMsgTime, 0);\r
- break;\r
- }\r
- if(underflow) break;\r
- }\r
- frames_done = frames_shown = 0;\r
- }\r
-\r
- if(currentConfig.iFrameskip >= 0) { // frameskip enabled\r
- for(i = 0; i < currentConfig.iFrameskip; i++) {\r
- SkipFrame(frames_done < target_fps); frames_done++;\r
- CGameWindow::DoKeys(tval);\r
- }\r
- } else if(tval.tv_usec > (frames_done+1)*target_frametime) { // auto frameskip\r
- // no time left for this frame - skip\r
- SkipFrame(1); frames_done++;\r
- CGameWindow::DoKeys(tval);\r
- too_fast = 0;\r
- continue;\r
- } else if(tval.tv_usec < (too_fast_time=frames_done*target_frametime)) { // we are too fast\r
- if(++too_fast > 2) { User::After(too_fast_time-tval.tv_usec); too_fast = 0; }// sleep, but only if we are _really_ fast\r
- }\r
-\r
- // draw\r
- vidDrawFrame(notice, buff, frames_shown);\r
- if(PsndOut && frames_done < target_fps) {\r
- PsndOut = gameAudio->NextFrameL();\r
- if(!PsndOut) { // sound output problems?\r
- strcpy(noticeMsg, "SOUND@OUTPUT@ERROR;@SOUND@DISABLED");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- }\r
- frames_done++; frames_shown++;\r
- CGameWindow::DoKeys(tval);\r
- }\r
-\r
- // save SRAM\r
- if((currentConfig.iFlags & 1) && SRam.changed) {\r
- saveLoadGame(0, 1);\r
- SRam.changed = 0;\r
- }\r
- CGameWindow::SendClientWsEvent(EEventGamePaused);\r
- CGameWindow::FreeResources();\r
- } else if(gamestate == PGS_Paused) {\r
- for(i = 0; gamestate == PGS_Paused; i++) {\r
- User::After(250000);\r
- if(!(i & 0x7F)) CheckForLauncher(); // every 32 secs\r
- }\r
- } else if(gamestate == PGS_KeyConfig) {\r
- // prepare window and stuff\r
- CGameWindow::ConstructResourcesL();\r
-\r
- TUint whichAction = 0;\r
- while(gamestate == PGS_KeyConfig) {\r
- vidKeyConfigFrame(whichAction, CGameWindow::iWsScreen->CurrentScreenMode());\r
- CGameWindow::DoKeysConfig(whichAction);\r
- User::After(200000);\r
- }\r
-\r
- CGameWindow::SendClientWsEvent(EEventKeyCfgDone);\r
- CGameWindow::SendClientWsEvent(EEventGamePaused);\r
- CGameWindow::FreeResources();\r
- } else if(gamestate == PGS_DebugHeap) {\r
- #ifdef __DEBUG_PRINT\r
- TInt cells = User::CountAllocCells();\r
- TInt mem;\r
- User::AllocSize(mem);\r
- DEBUGPRINT(_L("worker: cels=%d, size=%d KB"), cells, mem/1024);\r
- gamestate = gamestate_prev;\r
- #endif\r
- } else if(gamestate == PGS_Quit) {\r
- break;\r
- }\r
- }\r
-\r
- MainExit();\r
-}\r
-\r
-\r
-// gameAudio default "maker", which simply leaves\r
-IGameAudio *gameAudioNew_failer(TInt aRate, TBool aStereo, TInt aPcmFrames, TInt aBufferedFrames)\r
-{\r
- User::Leave(1);\r
- return 0; // shouldn't happen\r
-}\r
-\r
-\r
-// main initialization\r
-static void MainInit()\r
-{\r
- RProcess thisProcess, launcherProcess;\r
- TInt err = KErrGeneral;\r
-\r
- DEBUGPRINT(_L("\r\n\r\nstarting.."));\r
-\r
- //CPolledActiveScheduler::NewL(); // create Polled AS for the sound engine\r
-\r
- // get launcher id\r
- if(thisProcess.Owner(launcherProcess) == KErrNone) {\r
- launcherProcessId = launcherProcess.Id();\r
- launcherProcess.Close(); // messing with launcherProcess too much strangely reboots my phone\r
- } else {\r
- DEBUGPRINT(_L("%i: couldn't find owner, terminating.."), thisProcess.Id());\r
- thisProcess.Terminate(1);\r
- }\r
-\r
- // also get launcher thread id (for sending events, nasty way)\r
- TFindThread findThread;\r
- TFullName dummy1;\r
- RThread tmpThread;\r
- RProcess tmpProcess;\r
-\r
- while(findThread.Next(dummy1) == KErrNone)\r
- {\r
- tmpThread.Open(findThread);\r
- tmpThread.Process(tmpProcess);\r
- if(tmpProcess.Id() == launcherProcessId) {\r
- CGameWindow::iLauncherThreadId = tmpThread.Id();\r
- break;\r
- }\r
- tmpThread.Close();\r
- tmpProcess.Close();\r
- }\r
-\r
- // start event listening thread, which waits for GUI commands\r
- if(StartThread() < 0) {\r
- // communication thread failed to start, we serve no purpose now, so suicide\r
- DEBUGPRINT(_L("%i: StartThread() failed, terminating.."), thisProcess.Id());\r
- thisProcess.Terminate(1);\r
- }\r
-\r
- HAL::Get(HALData::EMachineUid, machineUid); // find out the machine UID\r
-\r
- // get current dir\r
- TFileName pfName = thisProcess.FileName();\r
- TParse parse;\r
- parse.Set(pfName, 0, 0);\r
- TPtrC currDir = parse.DriveAndPath();\r
- DEBUGPRINT(_L("current dir: %S"), &currDir);\r
-\r
- static TPtrC audio_dlls[] = { _L("audio_motorola.dll"), _L("audio_mediaserver.dll") };\r
-\r
- // find our audio object maker\r
- for(TInt i=0; i < 2; i++) {\r
- DEBUGPRINT(_L("trying audio DLL: %S"), &audio_dlls[i]);\r
- err = gameAudioLib.Load(audio_dlls[i], currDir);\r
- if(err == KErrNone) { // great, we loaded a dll!\r
- gameAudioNew = (_gameAudioNew) gameAudioLib.Lookup(1);\r
- if(!gameAudioNew) {\r
- gameAudioLib.Close();\r
- err = KErrGeneral;\r
- DEBUGPRINT(_L(" loaded, but Lookup(1) failed."));\r
- } else\r
- break; // done\r
- } else\r
- DEBUGPRINT(_L(" load failed! (%i)"), err);;\r
- }\r
-\r
- if(err != KErrNone)\r
- gameAudioNew = gameAudioNew_failer;\r
- else DEBUGPRINT(_L(" audio dll loaded!"));;\r
-\r
- DumpMemInfo();\r
-\r
- // try to start pico\r
- DEBUGPRINT(_L("PicoInit();"));\r
- PicoInit();\r
-\r
-#ifdef TEST_FRAMEBUFF\r
- iFrameBuffer = (TUint8 *) malloc(208*320*4);\r
-#endif\r
-}\r
-\r
-\r
-// does not return\r
-static void MainExit()\r
-{\r
- RProcess thisProcess;\r
-\r
- DEBUGPRINT(_L("%i: cleaning up.."), thisProcess.Id());\r
-\r
- // save SRAM\r
- if((currentConfig.iFlags & 1) && SRam.changed) {\r
- saveLoadGame(0, 1);\r
- SRam.changed = 0;\r
- }\r
-\r
- PicoExit();\r
-\r
- if(gameAudio) delete gameAudio;\r
-\r
- if(gameAudioLib.Handle()) gameAudioLib.Close();\r
-\r
- // Polled AS\r
- //delete CPolledActiveScheduler::Instance();\r
-\r
- DEBUGPRINT(_L("%i: terminating.."), thisProcess.Id()); \r
- thisProcess.Terminate(0);\r
-}\r
-\r
-\r
-static void CheckForLauncher()\r
-{\r
- RProcess launcherProcess;\r
-\r
- // check for launcher, we are useless without it\r
- if(launcherProcess.Open(launcherProcessId) != KErrNone || launcherProcess.ExitCategory().Length() != 0) {\r
- #ifdef __DEBUG_PRINT\r
- RProcess thisProcess;\r
- DEBUGPRINT(_L("%i: launcher process is gone, terminating.."), thisProcess.Id());\r
- if(launcherProcess.Handle()) {\r
- TExitCategoryName ecn = launcherProcess.ExitCategory();\r
- DEBUGPRINT(_L("%i: launcher exit category: %S"), thisProcess.Id(), &ecn);\r
- launcherProcess.Close();\r
- }\r
- #endif\r
- MainExit();\r
- }\r
- launcherProcess.Close();\r
-}\r
-\r
-\r
-void DumpMemInfo()\r
-{\r
- TInt ramSize, ramSizeFree, romSize;\r
- \r
- HAL::Get(HALData::EMemoryRAM, ramSize);\r
- HAL::Get(HALData::EMemoryRAMFree, ramSizeFree);\r
- HAL::Get(HALData::EMemoryROM, romSize);\r
-\r
- DEBUGPRINT(_L("ram=%dKB, ram_free=%dKB, rom=%dKB"), ramSize/1024, ramSizeFree/1024, romSize/1024);\r
-}\r
-\r
-\r
-\r
-TInt E32Main()\r
-{\r
- // first thing's first\r
- RThread().SetExceptionHandler(&ExceptionHandler, -1);\r
-\r
- //TInt pc, sp;\r
- //asm volatile ("str pc, %0" : "=m" (pc) );\r
- //asm volatile ("str sp, %0" : "=m" (sp) );\r
- //RDebug::Print(_L("executing @ 0x%08x, sp=0x%08x"), pc, sp);\r
-\r
-/*\r
- RDebug::Print(_L("Base Bottom Top Size RW Name"));\r
- TBuf<4> l_r(_L("R")), l_w(_L("W")), l_d(_L("-"));\r
- RChunk chunk;\r
- TFullName chunkname;\r
- TFindChunk findChunk(_L("*"));\r
- while( findChunk.Next(chunkname) != KErrNotFound ) {\r
- chunk.Open(findChunk);\r
- RDebug::Print(_L("%08x %08x %08x %08x %S%S %S"), chunk.Base(), chunk.Base()+chunk.Bottom(), chunk.Base()+chunk.Top(), chunk.Size(), chunk.IsReadable() ? &l_r : &l_d, chunk.IsWritable() ? &l_w : &l_d, &chunkname);\r
- chunk.Close();\r
- }\r
-*/\r
-\r
- CTrapCleanup* cleanup=CTrapCleanup::New();\r
-\r
- TRAPD(error, TargetEpocGameL());\r
-\r
- __ASSERT_ALWAYS(!error, User::Panic(_L("Picosmall"), error));\r
- delete cleanup;\r
-\r
- return 0;\r
-}\r
-\r
-\r
-void CGameWindow::ConstructResourcesL()\r
-{\r
-\r
- // connect to window server\r
- // tried to create it globally and not re-connect everytime,\r
- // but my window started to lose focus strangely\r
- User::LeaveIfError(iWsSession.Connect());\r
-\r
- // * Tell the Window Server not to mess about with our process priority\r
- // * Also, because of the way legacy games are written, they never sleep\r
- // * and thus never voluntarily yield the CPU. We set our process priority\r
- // * to EPriorityForeground and hope that a Telephony application on\r
- // * this device runs at EPriorityForeground as well. If not, tough! ;-)\r
-\r
- CGameWindow::iWsSession.ComputeMode(RWsSession::EPriorityControlDisabled);\r
- RProcess me;\r
- me.SetPriority(EPriorityForeground);\r
-\r
- iWsScreen=new(ELeave) CWsScreenDevice(iWsSession);\r
- User::LeaveIfError(iWsScreen->Construct());\r
-// User::LeaveIfError(iWsScreen->CreateContext(iWindowGc));\r
-\r
- iWsWindowGroup=RWindowGroup(iWsSession);\r
- User::LeaveIfError(iWsWindowGroup.Construct((TUint32)&iWsWindowGroup));\r
- //iWsWindowGroup.SetOrdinalPosition(0);\r
- //iWsWindowGroup.SetName(KServerWGName);\r
- iWsWindowGroup.EnableScreenChangeEvents(); // flip events (EEventScreenDeviceChanged)\r
- iWsWindowGroup.EnableFocusChangeEvents(); // EEventFocusGroupChanged\r
- iWsWindowGroup.SetOrdinalPosition(0, 1); // TInt aPos, TInt aOrdinalPriority\r
-\r
- iWsWindow=RWindow(iWsSession);\r
- User::LeaveIfError(iWsWindow.Construct(iWsWindowGroup, (TUint32)&iWsWindow));\r
- iWsWindow.SetSize(iWsScreen->SizeInPixels());\r
- iWsWindow.PointerFilter(EPointerFilterDrag, 0);\r
- iWsWindow.SetPointerGrab(ETrue);\r
- iWsWindow.SetVisible(ETrue);\r
- iWsWindow.Activate();\r
-\r
- // request access through RDirectScreenAccess api, but don't care about the result\r
- RRegion *dsa_region = 0;\r
- iDSA = new(ELeave) RDirectScreenAccess(iWsSession);\r
- if(iDSA->Construct() == KErrNone)\r
- iDSA->Request(dsa_region, iDSAstatus, iWsWindow);\r
- DEBUGPRINT(_L("DSA: %i"), dsa_region ? dsa_region->Count() : -1);\r
-\r
- // now get the screenbuffer\r
- TScreenInfoV01 screenInfo;\r
- TPckg<TScreenInfoV01> sI(screenInfo);\r
- UserSvr::ScreenInfo(sI);\r
-\r
- if(!screenInfo.iScreenAddressValid)\r
- User::Leave(KErrNotSupported);\r
-\r
-#ifndef TEST_FRAMEBUFF\r
- TUint8 *iFrameBuffer = (TUint8*) screenInfo.iScreenAddress;\r
-#endif\r
- TInt p800 = 0;\r
-\r
- switch(machineUid)\r
- {\r
- case 0x101f6b26: // A9xx & A10xx\r
- case 0x101f6b27: // Chinese A10xx\r
- case 0x101fd279: // P3x\r
- iFrameBuffer += 32;\r
- keyConfig = keyConfigMotA;\r
- break;\r
- case 0x101f408b: // P800\r
- p800 = 1;\r
- //case 0x101fb2ae: // P900\r
- //case 0x10200ac6: // P910\r
- default: \r
- keyConfig = keyConfigPXXX;\r
- break;\r
- }\r
- DEBUGPRINT(_L("framebuffer=0x%08x (%dx%d)"), iFrameBuffer,\r
- screenInfo.iScreenSize.iWidth, screenInfo.iScreenSize.iHeight);\r
-\r
- // vidInit\r
- User::LeaveIfError(vidInit(iWsScreen->DisplayMode(), iFrameBuffer, p800));\r
-\r
- // register for keyevents\r
- for(TPicoKeyConfigEntry *e = keyConfig; e->name; e++) {\r
- // release all keys\r
- e->flags &= ~1;\r
- if(e->flags & 0x80) {\r
- // key disabled\r
- e->handle1 = e->handle2 = -1;\r
- continue;\r
- }\r
- e->handle1 = iWsWindowGroup.CaptureKeyUpAndDowns(e->scanCode, 0, 0, 2);\r
- // although we only use UpAndDown events, register simple events too,\r
- // just to prevent fireing their default actions.\r
- if(e->keyCode) e->handle2 = iWsWindowGroup.CaptureKey(e->keyCode, 0, 0, 2); // priority of 1 is not enough on my phone\r
- }\r
-\r
- // try to start the audio engine\r
- static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
-\r
- if(gamestate == PGS_Running && (currentConfig.iFlags & 4)) {\r
- TInt err = 0;\r
- if(PsndRate != PsndRate_old || (PicoOpt&11) != (PicoOpt_old&11) || Pico.m.pal != pal_old) {\r
- // if rate changed, reset all enabled chips, else reset only those chips, which were recently enabled\r
- //sound_reset(PsndRate != PsndRate_old ? PicoOpt : (PicoOpt&(PicoOpt^PicoOpt_old)));\r
- sound_rerate();\r
- }\r
- if(!gameAudio || PsndRate != PsndRate_old || ((PicoOpt&8) ^ (PicoOpt_old&8)) || Pico.m.pal != pal_old) { // rate or stereo or pal/ntsc changed\r
- if(gameAudio) delete gameAudio; gameAudio = 0;\r
- DEBUGPRINT(_L("starting audio: %i len: %i stereo: %i, pal: %i"), PsndRate, PsndLen, PicoOpt&8, Pico.m.pal);\r
- TRAP(err, gameAudio = gameAudioNew(PsndRate, (PicoOpt&8) ? 1 : 0, PsndLen, Pico.m.pal ? 10 : 12));\r
- }\r
- if( gameAudio)\r
- TRAP(err, PsndOut = gameAudio->ResumeL());\r
- if(err) {\r
- if(gameAudio) delete gameAudio;\r
- gameAudio = 0;\r
- PsndOut = 0;\r
- strcpy(noticeMsg, "SOUND@STARTUP@FAILED");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- PsndRate_old = PsndRate;\r
- PicoOpt_old = PicoOpt;\r
- pal_old = Pico.m.pal;\r
- } else {\r
- if(gameAudio) delete gameAudio;\r
- gameAudio = 0;\r
- PsndOut = 0;\r
- }\r
-\r
- // start key WS event polling\r
- iWsSession.EventReady(&iWsEventStatus);\r
- DEBUGPRINT(_L("CGameWindow::ConstructResourcesL() finished."));\r
-}\r
-\r
-\r
-void CGameWindow::FreeResources()\r
-{\r
- if(gameAudio) gameAudio->Pause();\r
-\r
- // free RDirectScreenAccess stuff\r
- iDSA->Cancel();\r
- iDSA->Close();\r
- delete iDSA;\r
- iDSA = NULL;\r
-\r
- iWsSession.EventReadyCancel();\r
-\r
- for(TPicoKeyConfigEntry *e = keyConfig; e->name; e++) {\r
- if(e->handle2 >= 0) iWsWindowGroup.CancelCaptureKey(e->handle2);\r
- if(e->handle1 >= 0) iWsWindowGroup.CancelCaptureKeyUpAndDowns(e->handle1);\r
- }\r
-\r
- if(iWsWindow.WsHandle())\r
- iWsWindow.Close();\r
-\r
- if(iWsWindowGroup.WsHandle())\r
- iWsWindowGroup.Close();\r
-\r
- // these must be deleted before calling iWsSession.Close()\r
-// delete iWindowGc;\r
-// iWindowGc = NULL;\r
-\r
- delete iWsScreen;\r
- iWsScreen = NULL;\r
-\r
- // emu might change renderer by itself, so we may need to sync config\r
- if(PicoOpt != currentConfig.iPicoOpt) {\r
- currentConfig.iFlags |= 0x80;\r
- CGameWindow::SendClientWsEvent(EEventKeyCfgDone);\r
- }\r
-\r
- if(iWsSession.WsHandle())\r
- iWsSession.Close();\r
- \r
- vidFree();\r
-\r
-#ifdef TEST_FRAMEBUFF\r
- FILE *tmp = fopen("d:\\temp\\screen.raw", "wb");\r
- fwrite(iFrameBuffer, 1, 208*320*4, tmp);\r
- fclose(tmp);\r
-#endif\r
-}\r
-\r
-\r
-void CGameWindow::DoKeys(timeval &time)\r
-{\r
- TWsEvent iWsEvent;\r
- TInt iWsEventType;\r
- unsigned long allActions = 0;\r
- static unsigned long areaActions = 0, forceUpdate = 0;\r
- int i, nEvents;\r
-\r
- // detect if user is holding power button\r
- static timeval powerPushed = { 0, 0 };\r
- if(powerPushed.tv_sec) {\r
- if((time.tv_sec*1000000+time.tv_usec) - (powerPushed.tv_sec*1000000+powerPushed.tv_usec) > 1000000) { // > 1 sec\r
- gamestate = PGS_Paused;\r
- powerPushed.tv_sec = powerPushed.tv_usec = 0;\r
- }\r
- }\r
-\r
- for(nEvents = 0; iWsEventStatus != KRequestPending; nEvents++)\r
- {\r
- iWsSession.GetEvent(iWsEvent);\r
- iWsEventType = iWsEvent.Type();\r
-\r
- // pointer events?\r
- if(iWsEventType == EEventPointer) {\r
- if(iWsEvent.Pointer()->iType == TPointerEvent::EButton1Up) {\r
- areaActions = 0; // remove all directionals\r
- } else { // if(iWsEvent.Pointer()->iType == TPointerEvent::EButton1Down) {\r
- TPoint p = iWsEvent.Pointer()->iPosition;\r
- const TPicoAreaConfigEntry *e = areaConfig + 1;\r
- for(i = 0; !e->rect.IsEmpty(); e++, i++)\r
- if(e->rect.Contains(p)) {\r
- areaActions = currentConfig.iAreaBinds[i];\r
- break;\r
- }\r
- }\r
- }\r
- else if(iWsEventType == EEventKeyDown || iWsEventType == EEventKeyUp) {\r
- TInt iScanCode = iWsEvent.Key()->iScanCode;\r
-\r
- for(TPicoKeyConfigEntry *e = keyConfig; e->name; e++)\r
- if(iScanCode == e->scanCode) {\r
- if(iWsEventType == EEventKeyDown) e->flags |= 1;\r
- else if((e->flags & 2) == 0) e->flags &= ~1;\r
- break;\r
- }\r
-\r
- // power?\r
- if(iScanCode == EScanPxxxPower || iScanCode == EScanMotAEnd) {\r
- if(iWsEventType == EEventKeyDown)\r
- powerPushed = time;\r
- else powerPushed.tv_sec = powerPushed.tv_usec = 0;\r
- }\r
- }\r
- else if(iWsEventType == EEventScreenDeviceChanged) {\r
- // we have the priority, so the launcher will not be able to process this, but it has to\r
- User::After(500000);\r
- reset_timing = 1;\r
- }\r
- else if(iWsEventType == EEventFocusGroupChanged) {\r
- TInt launcherGrpId = iWsSession.FindWindowGroupIdentifier(0, iLauncherThreadId);\r
- TInt focusGrpId = iWsSession.GetFocusWindowGroup();\r
- DEBUGPRINT(_L("EEventFocusGroupChanged: %i, our: %i, launcher: %i"),\r
- focusGrpId, iWsWindowGroup.Identifier(), launcherGrpId);\r
- // if it is not us and not launcher that got focus, pause emu\r
- if(focusGrpId != iWsWindowGroup.Identifier() && focusGrpId != launcherGrpId)\r
- gamestate = PGS_Paused;\r
- }\r
-\r
- iWsEventStatus = KRequestPending;\r
- iWsSession.EventReady(&iWsEventStatus);\r
- }\r
-\r
- if(nEvents || forceUpdate) {\r
- allActions = areaActions;\r
- forceUpdate = 0;\r
-\r
- // add all pushed button actions\r
- i = 0;\r
- for(TPicoKeyConfigEntry *e = keyConfig; e->name; e++, i++) {\r
- if(e->flags & 1) allActions |= currentConfig.iKeyBinds[i];\r
- if((e->flags& 3) == 3) forceUpdate = 1;\r
- if(e->flags & 2) e->flags &= ~1;\r
- }\r
-\r
- PicoPad[0] = (unsigned short) allActions;\r
- if(allActions & 0xFFFF0000) {\r
- RunEvents(allActions >> 16);\r
- areaActions = 0;\r
- }\r
- }\r
-}\r
-\r
-\r
-void CGameWindow::DoKeysConfig(TUint &which)\r
-{\r
- TWsEvent iWsEvent;\r
- int i;\r
-\r
- // to detect if user is holding power button\r
- static int powerIters = 0;\r
-\r
- while(iWsEventStatus != KRequestPending)\r
- {\r
- TUint currentActCode = 1 << which;\r
-\r
- iWsSession.GetEvent(iWsEvent);\r
-\r
- // pointer events?\r
- if(iWsEvent.Type() == EEventPointer) {\r
- TPoint p = iWsEvent.Pointer()->iPosition;\r
- TRect prev(190, 112, 208, 126);\r
- TRect next(190, 194, 208, 208);\r
-\r
- if(iWsEvent.Pointer()->iType == TPointerEvent::EButton1Down) {\r
- if(prev.Contains(p)) do { which = (which-1) & 0x1F; } while(!actionNames[which]);\r
- else if(next.Contains(p)) do { which = (which+1) & 0x1F; } while(!actionNames[which]);\r
- else if(which == 31) gamestate = PGS_Paused; // done\r
- else {\r
- const TPicoAreaConfigEntry *e = areaConfig + 1;\r
- for(i = 0; e->rect != TRect(0,0,0,0); e++, i++)\r
- if(e->rect.Contains(p)) {\r
- currentConfig.iAreaBinds[i] ^= currentActCode;\r
- break;\r
- }\r
- }\r
- }\r
- }\r
- else if(iWsEvent.Type() == EEventKeyDown || iWsEvent.Type() == EEventKeyUp)\r
- {\r
- //if(iWsEvent.Type() == EEventKey)\r
- // DEBUGPRINT(_L("iWsEvent.Key()->iCode=0x%08x"), iWsEvent.Key()->iCode);\r
-\r
- //if(iWsEvent.Type() == EEventKeyDown)\r
- // DEBUGPRINT(_L("EEventKeyDown iScanCode=0x%08x"), iWsEvent.Key()->iScanCode);\r
-\r
- //if(iWsEvent.Type() == EEventKeyUp)\r
- // DEBUGPRINT(_L("EEventKeyUp iScanCode=0x%08x"), iWsEvent.Key()->iScanCode);\r
-\r
- // key events?\r
- if(iWsEvent.Type() == EEventKeyDown) {\r
- if(iWsScreen->CurrentScreenMode() == 1 && iWsEvent.Key()->iScanCode == EScanPxxxJogUp) {\r
- do { which = (which-1) & 0x1F; } while(!actionNames[which]);\r
- } else if(iWsScreen->CurrentScreenMode() == 1 && iWsEvent.Key()->iScanCode == EScanPxxxJogDown) {\r
- do { which = (which+1) & 0x1F; } while(!actionNames[which]);\r
- } else if(which == 31) {\r
- gamestate = PGS_Paused;\r
- if(iWsScreen->CurrentScreenMode()) // flip closed\r
- vidDrawFCconfigDone();\r
- } else {\r
- i = 0;\r
- for(TPicoKeyConfigEntry *e = keyConfig; e->name; e++, i++)\r
- if(iWsEvent.Key()->iScanCode == e->scanCode)\r
- if(!(e->flags&0x40)) currentConfig.iKeyBinds[i] ^= currentActCode;\r
- }\r
- }\r
-\r
- // power?\r
- if(iWsEvent.Key()->iScanCode == EScanPxxxPower || iWsEvent.Key()->iScanCode == EScanMotAEnd)\r
- {\r
- if(iWsEvent.Type() == EEventKeyDown) powerIters = 1;\r
- else if(iWsEvent.Type() == EEventKeyUp) powerIters = 0;\r
- }\r
- }\r
- else if(iWsEvent.Type() == EEventScreenDeviceChanged) {\r
- // trying to fix the P910 problem when something steals focus (and returns it after a while?)\r
- User::After(300000);\r
- }\r
- else if(iWsEvent.Type() == EEventFocusGroupChanged) {\r
- TInt launcherGrpId = iWsSession.FindWindowGroupIdentifier(0, iLauncherThreadId);\r
- TInt focusGrpId = iWsSession.GetFocusWindowGroup();\r
- DEBUGPRINT(_L("EEventFocusGroupChanged: %i, our: %i, launcher: %i"),\r
- focusGrpId, iWsWindowGroup.Identifier(), launcherGrpId);\r
- // if it is not us and not launcher that got focus, exit config mode\r
- if(focusGrpId != iWsWindowGroup.Identifier() && focusGrpId != launcherGrpId) {\r
- // don't give up that easily. May be the focus will be given back.\r
- for (int i = 0; i < 4; i++) {\r
- User::After(200000);\r
- focusGrpId = iWsSession.GetFocusWindowGroup();\r
- if(focusGrpId == iWsWindowGroup.Identifier() || focusGrpId == launcherGrpId) break;\r
- }\r
- if(focusGrpId != iWsWindowGroup.Identifier() && focusGrpId != launcherGrpId) \r
- // we probably should give up now\r
- gamestate = PGS_Paused;\r
- }\r
- }\r
-\r
- iWsEventStatus = KRequestPending;\r
- iWsSession.EventReady(&iWsEventStatus);\r
- }\r
-\r
- if(powerIters) { // iterations when power was down\r
- powerIters++;\r
- if(powerIters > 5) {\r
- gamestate = PGS_Paused;\r
- powerIters = 0;\r
- }\r
- }\r
-}\r
-\r
-\r
-void CGameWindow::RunEvents(TUint32 which)\r
-{\r
- if(which & 0x4000) currentConfig.iFrameskip = -1;\r
- if(which & 0x2000) currentConfig.iFrameskip = 8;\r
- if(which & 0x1800) { // save or load (but not both)\r
- if(PsndOut) gameAudio->Pause(); // this may take a while, so we pause sound output\r
-\r
- vidDrawNotice((which & 0x1000) ? "LOADING@GAME" : "SAVING@GAME");\r
- saveLoadGame(which & 0x1000);\r
-\r
- if(PsndOut) PsndOut = gameAudio->ResumeL();\r
- reset_timing = 1;\r
- }\r
- if(which & 0x0400) gamestate = PGS_Paused;\r
- if(which & 0x0200) { // switch renderer\r
- if(currentConfig.iScreenMode == TPicoConfig::PMCenter && !noticeMsgTime.tv_sec &&\r
- (currentConfig.iScreenRotation == TPicoConfig::PRot90 || currentConfig.iScreenRotation == TPicoConfig::PRot270)) {\r
-\r
- PicoOpt^=0x10;\r
- vidInit(iWsScreen->DisplayMode(), 0, 0, 1);\r
-\r
- strcpy(noticeMsg, (PicoOpt&0x10) ? "ALT@RENDERER" : "DEFAULT@RENDERER");\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- }\r
- if(which & 0x00c0) {\r
- if(which&0x0080) {\r
- state_slot -= 1;\r
- if(state_slot < 0) state_slot = 9;\r
- } else {\r
- state_slot += 1;\r
- if(state_slot > 9) state_slot = 0;\r
- }\r
- sprintf(noticeMsg, "SAVE@SLOT@%i@SELECTED", state_slot);\r
- gettimeofday(¬iceMsgTime, 0);\r
- }\r
- if(which & 0x0020) if(gameAudio) gameAudio->ChangeVolume(0); // for Motorolas (broken?)\r
- if(which & 0x0010) if(gameAudio) gameAudio->ChangeVolume(1);\r
-}\r
-\r
-\r
-// send event to launcher windowgroup (WS session MUST be alive)\r
-void CGameWindow::SendClientWsEvent(TInt type)\r
-{\r
- if(!iWsSession.Handle()) {\r
- DEBUGPRINT(_L("SendClientWsEvent(%i) called on dead iWsSession."), type);\r
- return;\r
- }\r
-\r
- TWsEvent event;\r
- event.SetType(type);\r
- event.SetTimeNow();\r
-\r
- TInt launcherGrpId = iWsSession.FindWindowGroupIdentifier(0, iLauncherThreadId);\r
- if(launcherGrpId != KErrNotFound)\r
- iWsSession.SendEventToWindowGroup(launcherGrpId, event);\r
- else DEBUGPRINT(_L("failed to send event %i to launcher."), event.Type());\r
-}\r
-\r
-\r
-size_t gzRead2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
- return gzread(file, p, _n);\r
-}\r
-\r
-\r
-size_t gzWrite2(void *p, size_t _size, size_t _n, void *file)\r
-{\r
- return gzwrite(file, p, _n);\r
-}\r
-\r
-\r
-// this function is shared between both threads\r
-int saveLoadGame(int load, int sram)\r
-{\r
- int res = 0;\r
-\r
- if(!RomFileName) return -1;\r
-\r
- // make save filename\r
- char saveFname[KMaxFileName];\r
- strcpy(saveFname, RomFileName);\r
- saveFname[KMaxFileName-8] = 0;\r
- if(saveFname[strlen(saveFname)-4] == '.') saveFname[strlen(saveFname)-4] = 0;\r
- if(sram) strcat(saveFname, ".srm");\r
- else {\r
- if(state_slot > 0 && state_slot < 10) sprintf(saveFname, "%s.%i", saveFname, state_slot);\r
- strcat(saveFname, ".mds");\r
- }\r
- \r
- DEBUGPRINT(_L("saveLoad (%i, %i): %S"), load, sram, DO_CONV(saveFname));\r
-\r
- if(sram) {\r
- FILE *sramFile;\r
- int sram_size = SRam.end-SRam.start+1;\r
- if(SRam.reg_back & 4) sram_size=0x2000;\r
- if(!SRam.data) return 0; // SRam forcefully disabled for this game\r
- if(load) {\r
- sramFile = fopen(saveFname, "rb");\r
- if(!sramFile) return -1;\r
- fread(SRam.data, 1, sram_size, sramFile);\r
- fclose(sramFile);\r
- } else {\r
- // sram save needs some special processing\r
- // see if we have anything to save\r
- for(; sram_size > 0; sram_size--)\r
- if(SRam.data[sram_size-1]) break;\r
- \r
- if(sram_size) {\r
- sramFile = fopen(saveFname, "wb");\r
- res = fwrite(SRam.data, 1, sram_size, sramFile);\r
- res = (res != sram_size) ? -1 : 0;\r
- fclose((FILE *) sramFile);\r
- }\r
- }\r
- return res;\r
- } else {\r
- void *PmovFile = NULL;\r
- // try gzip first\r
- if(currentConfig.iFlags & 0x80) {\r
- strcat(saveFname, ".gz");\r
- if( (PmovFile = gzopen(saveFname, load ? "rb" : "wb")) ) {\r
- areaRead = gzRead2;\r
- areaWrite = gzWrite2;\r
- if(!load) gzsetparams(PmovFile, 9, Z_DEFAULT_STRATEGY);\r
- } else\r
- saveFname[strlen(saveFname)-3] = 0;\r
- }\r
- if(!PmovFile) { // gzip failed or was disabled\r
- if( (PmovFile = fopen(saveFname, load ? "rb" : "wb")) ) {\r
- areaRead = fread;\r
- areaWrite = fwrite;\r
- }\r
- }\r
- if(PmovFile) {\r
- PmovState(load ? 6 : 5, PmovFile);\r
- strcpy(noticeMsg, load ? "GAME@LOADED" : "GAME@SAVED");\r
- if(areaRead == gzRead2)\r
- gzclose(PmovFile);\r
- else fclose ((FILE *) PmovFile);\r
- PmovFile = 0;\r
- } else {\r
- strcpy(noticeMsg, load ? "LOAD@FAILED" : "SAVE@FAILED");\r
- res = -1;\r
- }\r
-\r
- gettimeofday(¬iceMsgTime, 0);\r
- return res;\r
- }\r
-}\r
-\r
-// static class members\r
-RWsSession CGameWindow::iWsSession;\r
-RWindowGroup CGameWindow::iWsWindowGroup;\r
-RWindow CGameWindow::iWsWindow;\r
-CWsScreenDevice* CGameWindow::iWsScreen = NULL;\r
-CWindowGc* CGameWindow::iWindowGc = NULL;\r
-TRequestStatus CGameWindow::iWsEventStatus = KRequestPending;\r
-TThreadId CGameWindow::iLauncherThreadId = 0;\r
-RDirectScreenAccess* CGameWindow::iDSA;\r
-TRequestStatus CGameWindow::iDSAstatus = KRequestPending;\r