X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=platform%2Fsdl.cpp;h=cd540c740a342b733b276c326965a40ea2a4113c;hb=6f057a6bc74f3f422ffc8f8439b1b205ebef66e5;hp=b78b48e621f1297447117eb15ef72d6b867c5642;hpb=64fe843d86ff330bc4b341559e9e4a556d784372;p=drnoksnes diff --git a/platform/sdl.cpp b/platform/sdl.cpp index b78b48e..cd540c7 100644 --- a/platform/sdl.cpp +++ b/platform/sdl.cpp @@ -9,15 +9,18 @@ #include "cpuexec.h" #include "gfx.h" #include "ppu.h" -#include "display.h" #include "memmap.h" #include "soundux.h" #include "hacks.h" #include "snapshot.h" -#include "hgw.h" +#include "screenshot.h" -#define kPollEveryNFrames 5 //Poll input only every this many frames -#define kPollHgwEveryNFrames 10 //Poll dbus only every this many frames +#define kPollEveryNFrames 2 //Poll input only every this many frames + +#if CONF_GUI +#include "osso.h" +#define kPollOssoEveryNFrames 10 //Poll dbus only every this many frames +#endif #define TRACE printf("trace: %s:%s\n", __FILE__, __func__); #define DIE(format, ...) do { \ @@ -31,11 +34,6 @@ void S9xMessage(int type, int number, const char * message) printf("%s\n", message); } -void S9xLoadSDD1Data() -{TRACE - Settings.SDD1Pack=FALSE; -} - void S9xAutoSaveSRAM() { Memory.SaveSRAM(S9xGetFilename(FILE_SRAM)); @@ -119,9 +117,13 @@ static void pauseGame() } /* This comes nearly straight from snes9x */ +/** Calculates framerate, enables frame skip if to low, sleeps if too high, etc. */ static void frameSync() { + Uint32 now = SDL_GetTicks(); + if (Settings.TurboMode) { + // In Turbo mode, just skip as many frames as desired, but don't sleep. if(Settings.SkipFrames == AUTO_FRAMERATE || ++IPPU.FrameSkip >= Settings.SkipFrames) { @@ -134,10 +136,20 @@ static void frameSync() { ++IPPU.SkippedFrames; IPPU.RenderThisFrame = FALSE; } - return; + + // Take care of framerate display + if (Settings.DisplayFrameRate) { + static Uint32 last = 0; + // Update framecounter every second + if (now > last && (now - last > 1000)) { + IPPU.DisplayedRenderedFrameCount = + IPPU.RenderedFramesCount; + IPPU.RenderedFramesCount = 0; + last = now; + } + } } else { static Uint32 next1 = 0; - Uint32 now = SDL_GetTicks(); // If there is no known "next" frame, initialize it now if (next1 == 0) { @@ -178,6 +190,16 @@ static void frameSync() { // Calculate the timestamp of the next frame. next1 += Settings.FrameTime; + + // Take care of framerate display + if (Settings.DisplayFrameRate) { + // Update every theoretical 60 frames + if (IPPU.FrameCount % Memory.ROMFramesPerSecond == 0) { + IPPU.DisplayedRenderedFrameCount = + IPPU.RenderedFramesCount; + IPPU.RenderedFramesCount = 0; + } + } } } @@ -186,32 +208,38 @@ static inline void pollEvents() { static int frames = 0; if (++frames > kPollEveryNFrames) { - S9xProcessEvents(FALSE); + S9xProcessEvents(false); frames = 0; } } -/** Wraps HgwPollEvents, taking care of kPollHgwEveryNFrames */ -static inline void pollHgwEvents() { +#if CONF_GUI +/** Wraps OssoPollEvents, taking care of kPollOssoEveryNFrames */ +static inline void pollOssoEvents() { static int frames = 0; - if (!hgwLaunched) return; + if (!OssoOk()) return; - if (++frames > kPollHgwEveryNFrames) { - HgwPollEvents(); + if (++frames > kPollOssoEveryNFrames) { + OssoPollEvents(); frames = 0; } } +#endif -int main(int argc, const char ** argv) { +int main(int argc, char ** argv) { // Initialise SDL if (SDL_Init(0) < 0) DIE("SDL_Init: %s", SDL_GetError()); // Configure snes9x - HgwInit(); // Hildon-games-wrapper initialization. +#if CONF_GUI + OssoInit(); // Hildon-games-wrapper initialization. +#endif S9xLoadConfig(argc, argv); // Load config files and parse cmd line. - HgwConfig(); // Apply specific hildon-games config. +#if CONF_GUI + OssoConfig(); // Apply specific hildon-games config. +#endif // S9x initialization S9xInitDisplay(argc, argv); @@ -236,7 +264,9 @@ int main(int argc, const char ** argv) { frameSync(); // May block, or set frameskip to true. S9xMainLoop(); // Does CPU things, renders if needed. pollEvents(); - pollHgwEvents(); +#if CONF_GUI + pollOssoEvents(); +#endif } while (!Config.quitting); // Deinitialization @@ -253,7 +283,9 @@ int main(int argc, const char ** argv) { S9xGraphicsDeinit(); Memory.Deinit(); S9xUnloadConfig(); - HgwDeinit(); +#if CONF_GUI + OssoDeinit(); +#endif SDL_Quit(); @@ -267,7 +299,41 @@ void S9xDoAction(unsigned char action) if (action & kActionToggleFullscreen) { S9xVideoToggleFullscreen(); - S9xInputScreenChanged(); + } + +#if CONF_PNG + if (action & kActionScreenshot) { + S9xSaveScreenshot(S9xGetFilename(FILE_SCREENSHOT)); + S9xSetInfoString("Screenshot taken"); + } +#endif + + if (action & kActionQuickLoad1) { + const char * file = S9xGetQuickSaveFilename(1); + int result = S9xUnfreezeGame(file); + S9xSetInfoString("Load slot %u: %s", 1, + (result ? "done" : "failed")); + } + + if (action & kActionQuickSave1) { + const char * file = S9xGetQuickSaveFilename(1); + int result = S9xFreezeGame(file); + S9xSetInfoString("Save slot %u: %s", 1, + (result ? "done" : "failed")); + } + + if (action & kActionQuickLoad2) { + const char * file = S9xGetQuickSaveFilename(2); + int result = S9xUnfreezeGame(file); + S9xSetInfoString("Load slot %u: %s", 2, + (result ? "done" : "failed")); + } + + if (action & kActionQuickSave2) { + const char * file = S9xGetQuickSaveFilename(2); + int result = S9xFreezeGame(file); + S9xSetInfoString("Save slot %u: %s", 2, + (result ? "done" : "failed")); } }