aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-09-21 03:42:40 +0200
committerStapleButter <thetotalworm@gmail.com>2017-09-21 03:42:40 +0200
commitf13c3fc90cbc6e15541dca5db998994965ba1c0b (patch)
treecbbbad0ffe81cf40d540b30c0efee67b37adff87
parentb70e08592163f94220c3f48cad344ba96d374f87 (diff)
implement run/pause/reset menus
-rw-r--r--src/libui_sdl/main.cpp100
1 files changed, 96 insertions, 4 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index b40c9d1..be7bca6 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -35,9 +35,15 @@
uiWindow* MainWindow;
uiArea* MainDrawArea;
+uiMenuItem* MenuItem_Pause;
+uiMenuItem* MenuItem_Reset;
+
SDL_Thread* EmuThread;
int EmuRunning;
+bool RunningSomething;
+char ROMPath[1024];
+
bool ScreenDrawInited = false;
SDL_mutex* ScreenMutex;
uiDrawBitmap* ScreenBitmap = NULL;
@@ -253,26 +259,96 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt)
}
+void Run()
+{
+ EmuRunning = 1;
+ RunningSomething = true;
+
+ uiMenuItemEnable(MenuItem_Pause);
+ uiMenuItemEnable(MenuItem_Reset);
+ uiMenuItemSetChecked(MenuItem_Pause, 0);
+}
+
+void Stop()
+{
+ // TODO
+}
+
+
int OnCloseWindow(uiWindow* window, void* blarg)
{
uiQuit();
return 1;
}
+void OnCloseByMenu(uiMenuItem* item, uiWindow* window, void* blarg)
+{
+ uiQuit();
+}
+
void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg)
{
+ int prevstatus = EmuRunning;
EmuRunning = 2;
// TODO: ensure the emu thread has indeed stopped at this point
char* file = uiOpenFile(window, "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", NULL);
- if (!file) return;
+ if (!file)
+ {
+ EmuRunning = prevstatus;
+ return;
+ }
- NDS::LoadROM(file, Config::DirectBoot);
+ strncpy_s(ROMPath, file, 1023);
+ ROMPath[1023] = '\0';
uiFreeText(file);
// TODO: change libui to store strings in stack-allocated buffers?
// so we don't have to free it after use
- EmuRunning = 1;
+ NDS::LoadROM(ROMPath, Config::DirectBoot);
+
+ Run();
+}
+
+void OnRun(uiMenuItem* item, uiWindow* window, void* blarg)
+{
+ if (!RunningSomething)
+ {
+ ROMPath[0] = '\0';
+ NDS::LoadBIOS();
+ }
+
+ Run();
+}
+
+void OnPause(uiMenuItem* item, uiWindow* window, void* blarg)
+{
+ if (!RunningSomething) return;
+
+ if (EmuRunning == 1)
+ {
+ // enable pause
+ EmuRunning = 2;
+ uiMenuItemSetChecked(MenuItem_Pause, 1);
+ }
+ else
+ {
+ // disable pause
+ EmuRunning = 1;
+ uiMenuItemSetChecked(MenuItem_Pause, 0);
+ }
+}
+
+void OnReset(uiMenuItem* item, uiWindow* window, void* blarg)
+{
+ if (!RunningSomething) return;
+
+ if (ROMPath[0] == '\0')
+ NDS::LoadBIOS();
+ else
+ NDS::LoadROM(ROMPath, Config::DirectBoot);
+
+ Run();
}
@@ -313,11 +389,26 @@ int main(int argc, char** argv)
menuitem = uiMenuAppendItem(menu, "Open ROM...");
uiMenuItemOnClicked(menuitem, OnOpenFile, NULL);
uiMenuAppendSeparator(menu);
- uiMenuAppendItem(menu, "Quit");
+ menuitem = uiMenuAppendItem(menu, "Quit");
+ uiMenuItemOnClicked(menuitem, OnCloseByMenu, NULL);
+
+ menu = uiNewMenu("System");
+ menuitem = uiMenuAppendItem(menu, "Run");
+ uiMenuItemOnClicked(menuitem, OnRun, NULL);
+ menuitem = uiMenuAppendItem(menu, "Pause");
+ uiMenuItemOnClicked(menuitem, OnPause, NULL);
+ MenuItem_Pause = menuitem;
+ uiMenuAppendSeparator(menu);
+ menuitem = uiMenuAppendItem(menu, "Reset");
+ uiMenuItemOnClicked(menuitem, OnReset, NULL);
+ MenuItem_Reset = menuitem;
MainWindow = uiNewWindow("melonDS " MELONDS_VERSION, 256, 384, 1);
uiWindowOnClosing(MainWindow, OnCloseWindow, NULL);
+ uiMenuItemDisable(MenuItem_Pause);
+ uiMenuItemDisable(MenuItem_Reset);
+
uiAreaHandler areahandler;
areahandler.Draw = OnAreaDraw;
@@ -330,6 +421,7 @@ int main(int argc, char** argv)
uiWindowSetChild(MainWindow, uiControl(MainDrawArea));
EmuRunning = 2;
+ RunningSomething = false;
EmuThread = SDL_CreateThread(EmuThreadFunc, "melonDS magic", NULL);
uiControlShow(uiControl(MainWindow));