From c86b2c676075c0731f2e12a82e35558b66114f89 Mon Sep 17 00:00:00 2001 From: Juha Laukkanen Date: Wed, 12 Nov 2014 02:17:35 -0500 Subject: [PATCH] GTK GUI: save oldest & load recent This patch adds load from oldest state slot & load from most recent state slot keys to joypad configuration. Also modifies logic of vOnSaveGameOldest() so that if slot is empty (no ts) it is considered oldest. --- src/System.h | 2 ++ src/gb/GB.cpp | 17 +++++++++++++++++ src/gba/GBA.cpp | 16 ++++++++++++++++ src/gtk/joypadconfig.cpp | 30 ++++++++++++++++-------------- src/gtk/system.cpp | 10 ++++++++++ src/gtk/window.cpp | 34 ++++++++++++++++++---------------- src/gtk/window.h | 5 +++-- src/gtk/windowcallbacks.cpp | 7 +++++-- src/sdl/SDL.cpp | 10 ++++++++++ src/sdl/inputSDL.cpp | 4 ++++ src/sdl/inputSDL.h | 2 ++ 11 files changed, 103 insertions(+), 34 deletions(-) diff --git a/src/System.h b/src/System.h index 30c74e84..1895d6b9 100644 --- a/src/System.h +++ b/src/System.h @@ -47,6 +47,8 @@ extern void log(const char *,...); extern bool systemPauseOnFrame(); extern void systemGbPrint(u8 *,int,int,int,int,int); extern void systemScreenCapture(int); +extern void systemSaveOldest(); +extern void systemLoadRecent(); extern void systemDrawScreen(); // updates the joystick data extern bool systemReadJoypads(); diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index c7176869..1bea49f5 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -198,6 +198,8 @@ bool gbCapture = false; bool gbCapturePrevious = false; int gbJoymask[4] = { 0, 0, 0, 0 }; +bool saveold=false, loadrcn=false, savePrevious=false, loadPrevious=false; + u8 gbRamFill = 0xff; int gbRomSizes[] = { 0x00008000, // 32K @@ -4972,6 +4974,21 @@ void gbEmulate(int ticksToStop) } gbCapturePrevious = gbCapture; +#ifdef ENABLE_GTK // todo: enable for wx also + // todo: generally this is very inefficient way to do this: cmp on every loop + saveold = (newmask & 4) ? true : false; + loadrcn = (newmask & 8) ? true : false; + + if(saveold && !savePrevious) { + systemSaveOldest(); + } + savePrevious = saveold; + if(loadrcn && !loadPrevious) { + systemLoadRecent(); + } + loadPrevious = loadrcn; +#endif + if(gbFrameSkipCount >= framesToSkip) { if(!gbSgbMask) diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index c53ac87a..aad229c0 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -123,6 +123,8 @@ int captureNumber = 0; int armOpcodeCount = 0; int thumbOpcodeCount = 0; +extern bool saveold, loadrcn, savePrevious, loadPrevious; + const int TIMER_TICKS[4] = { 0, 6, @@ -3765,6 +3767,20 @@ void CPULoop(int ticks) } capturePrevious = capture; +#ifdef ENABLE_GTK // todo: enable for wx also + // todo: generally this is very inefficient way to do this: cmp on every loop + saveold = (ext & 4) ? true : false; + loadrcn = (ext & 8) ? true : false; + + if(saveold && !savePrevious) { + systemSaveOldest(); + } + savePrevious = saveold; + if(loadrcn && !loadPrevious) { + systemLoadRecent(); + } + loadPrevious = loadrcn; +#endif DISPSTAT |= 1; DISPSTAT &= 0xFFFD; UPDATE_REG(0x04, DISPSTAT); diff --git a/src/gtk/joypadconfig.cpp b/src/gtk/joypadconfig.cpp index b12e2121..41af26ae 100644 --- a/src/gtk/joypadconfig.cpp +++ b/src/gtk/joypadconfig.cpp @@ -27,20 +27,22 @@ namespace VBA const JoypadConfigDialog::SJoypadKey JoypadConfigDialog::m_astKeys[] = { - { KEY_UP, N_("Up :") }, - { KEY_DOWN, N_("Down :") }, - { KEY_LEFT, N_("Left :") }, - { KEY_RIGHT, N_("Right :") }, - { KEY_BUTTON_A, N_("Button A :") }, - { KEY_BUTTON_B, N_("Button B :") }, - { KEY_BUTTON_L, N_("Button L :") }, - { KEY_BUTTON_R, N_("Button R :") }, - { KEY_BUTTON_SELECT, N_("Select :") }, - { KEY_BUTTON_START, N_("Start :") }, - { KEY_BUTTON_SPEED, N_("Speed :") }, - { KEY_BUTTON_CAPTURE, N_("Capture :") }, - { KEY_BUTTON_AUTO_A, N_("Autofire A :") }, - { KEY_BUTTON_AUTO_B, N_("Autofire B :") } + { KEY_UP, N_("Up :") }, + { KEY_DOWN, N_("Down :") }, + { KEY_LEFT, N_("Left :") }, + { KEY_RIGHT, N_("Right :") }, + { KEY_BUTTON_A, N_("Button A :") }, + { KEY_BUTTON_B, N_("Button B :") }, + { KEY_BUTTON_L, N_("Button L :") }, + { KEY_BUTTON_R, N_("Button R :") }, + { KEY_BUTTON_SELECT, N_("Select :") }, + { KEY_BUTTON_START, N_("Start :") }, + { KEY_BUTTON_SPEED, N_("Speed :") }, + { KEY_BUTTON_SAVE_OLDEST, N_("SaveOldest :") }, + { KEY_BUTTON_LOAD_RECENT, N_("LoadRecent :") }, + { KEY_BUTTON_CAPTURE, N_("Capture :") }, + { KEY_BUTTON_AUTO_A, N_("Autofire A :") }, + { KEY_BUTTON_AUTO_B, N_("Autofire B :") } }; JoypadConfigDialog::JoypadConfigDialog(Config::Section * _poConfig) : diff --git a/src/gtk/system.cpp b/src/gtk/system.cpp index 9f37ced9..3a443b5f 100644 --- a/src/gtk/system.cpp +++ b/src/gtk/system.cpp @@ -93,6 +93,16 @@ void systemScreenCapture(int _iNum) GUI()->vCaptureScreen(_iNum); } +void systemSaveOldest() +{ + GUI()->vOnSaveGameOldest(); +} + +void systemLoadRecent() +{ + GUI()->vOnLoadGameMostRecent(); +} + u32 systemGetClock() { Glib::TimeVal time; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 96b0803a..2a41f286 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -55,22 +55,22 @@ Window * Window::m_poInstance = NULL; const Window::SJoypadKey Window::m_astJoypad[] = { - { "left", KEY_LEFT }, - { "right", KEY_RIGHT }, - { "up", KEY_UP }, - { "down", KEY_DOWN }, - { "A", KEY_BUTTON_A }, - { "B", KEY_BUTTON_B }, - { "select", KEY_BUTTON_SELECT }, - { "start", KEY_BUTTON_START }, - { "L", KEY_BUTTON_L }, - { "R", KEY_BUTTON_R }, - { "speed", KEY_BUTTON_SPEED }, - { "capture", KEY_BUTTON_CAPTURE }, - { "speed", KEY_BUTTON_SPEED }, - { "capture", KEY_BUTTON_CAPTURE }, - { "autoA", KEY_BUTTON_AUTO_A }, - { "autoB", KEY_BUTTON_AUTO_B } + { "left", KEY_LEFT }, + { "right", KEY_RIGHT }, + { "up", KEY_UP }, + { "down", KEY_DOWN }, + { "A", KEY_BUTTON_A }, + { "B", KEY_BUTTON_B }, + { "select", KEY_BUTTON_SELECT }, + { "start", KEY_BUTTON_START }, + { "L", KEY_BUTTON_L }, + { "R", KEY_BUTTON_R }, + { "speed", KEY_BUTTON_SPEED }, + { "save", KEY_BUTTON_SAVE_OLDEST }, + { "load", KEY_BUTTON_LOAD_RECENT }, + { "capture", KEY_BUTTON_CAPTURE }, + { "autoA", KEY_BUTTON_AUTO_A }, + { "autoB", KEY_BUTTON_AUTO_B } }; Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : @@ -480,6 +480,8 @@ void Window::vInitSDL() inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_L, GDK_a); inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_R, GDK_s); inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_SPEED, GDK_space); + inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_SAVE_OLDEST, GDK_k); + inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_LOAD_RECENT, GDK_l); inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_CAPTURE, GDK_F12); inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_AUTO_A, GDK_q); inputSetKeymap(PAD_DEFAULT, KEY_BUTTON_AUTO_B, GDK_w); diff --git a/src/gtk/window.h b/src/gtk/window.h index 77652499..f5d1d621 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -112,6 +112,9 @@ public: void vApplyPerGameConfig(); void vUpdateScreen(); + virtual void vOnSaveGameOldest(); + virtual void vOnLoadGameMostRecent(); + inline ECartridge eGetCartridge() const { return m_eCartridge; } protected: @@ -143,10 +146,8 @@ protected: virtual void vOnFileOpen(); virtual void vOnFileLoad(); virtual void vOnFileSave(); - virtual void vOnLoadGameMostRecent(); virtual void vOnLoadGameAutoToggled(Gtk::CheckMenuItem * _poCMI); void vOnLoadGame(int _iSlot); - virtual void vOnSaveGameOldest(); void vOnSaveGame(int _iSlot); virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFileReset(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 9396b99a..2ba762d2 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -207,8 +207,11 @@ void Window::vOnSaveGameOldest() for (int i = 0; i < 10; i++) { - if (! m_astGameSlot[i].m_bEmpty - && (iOldest < 0 || m_astGameSlot[i].m_uiTime < uiTimeMin)) + if (m_astGameSlot[i].m_bEmpty) { + iOldest = i; + break; + } + else if ( iOldest < 0 || m_astGameSlot[i].m_uiTime < uiTimeMin) { iOldest = i; uiTimeMin = m_astGameSlot[i].m_uiTime; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 910e93e6..68cafd0e 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -2619,6 +2619,16 @@ void systemScreenCapture(int a) systemScreenMessage("Screen capture"); } +void systemSaveOldest() +{ + // I need to be implemented +} + +void systemLoadRecent() +{ + // I need to be implemented +} + u32 systemGetClock() { return SDL_GetTicks(); diff --git a/src/sdl/inputSDL.cpp b/src/sdl/inputSDL.cpp index 6c54e09c..e0ba0ca5 100644 --- a/src/sdl/inputSDL.cpp +++ b/src/sdl/inputSDL.cpp @@ -535,6 +535,10 @@ uint32_t inputReadJoypad(int which) res |= 1024; if(sdlButtons[which][KEY_BUTTON_CAPTURE]) res |= 2048; + if(sdlButtons[which][KEY_BUTTON_SAVE_OLDEST]) + res |= 4096; + if(sdlButtons[which][KEY_BUTTON_LOAD_RECENT]) + res |= 8192; if(realAutoFire) { res &= (~realAutoFire); diff --git a/src/sdl/inputSDL.h b/src/sdl/inputSDL.h index cf930724..dc05c491 100644 --- a/src/sdl/inputSDL.h +++ b/src/sdl/inputSDL.h @@ -32,6 +32,8 @@ enum EKey { KEY_BUTTON_L, KEY_BUTTON_R, KEY_BUTTON_SPEED, + KEY_BUTTON_SAVE_OLDEST, + KEY_BUTTON_LOAD_RECENT, KEY_BUTTON_CAPTURE, KEY_BUTTON_AUTO_A, KEY_BUTTON_AUTO_B