From 5f0f48fc8bcacb7ef52e3b5301e40b2f467e14ca Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Tue, 29 Oct 2024 22:33:48 -0400 Subject: [PATCH] Implement pause and reset --- emulation.c | 4 ++++ emulation.h | 1 + ui.c | 21 +++++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/emulation.c b/emulation.c index e0daae1..23ed044 100644 --- a/emulation.c +++ b/emulation.c @@ -31,6 +31,10 @@ void emuLoadGame(EmulationContext *emu, uint8_t *rom, uint32_t romSize) { vbSetCartROM(emu->sim, rom, romSize); } +void emuReset(EmulationContext *emu) { + vbReset(emu->sim); +} + #define MAX_STEP_CLOCKS 20000000 void emuTick(EmulationContext *emu) { uint32_t clocks = MAX_STEP_CLOCKS; diff --git a/emulation.h b/emulation.h index da6e849..c931146 100644 --- a/emulation.h +++ b/emulation.h @@ -19,6 +19,7 @@ typedef struct EmulationContext { int emuInit(EmulationContext *emu); void emuDestroy(EmulationContext *emu); void emuLoadGame(EmulationContext *emu, uint8_t *rom, uint32_t romSize); +void emuReset(EmulationContext *emu); void emuTick(EmulationContext *emu); bool emuReadPixels(EmulationContext *emu, uint8_t *left, uint8_t *right); diff --git a/ui.c b/ui.c index f60acf6..f20a013 100644 --- a/ui.c +++ b/ui.c @@ -94,9 +94,15 @@ static const char *MENU_ITEMS[3] = { NULL }; +typedef enum status_t { + status_paused, + status_running +} status_t; + int uiRun(UIContext *ui) { static uint8_t leftEye[384*224]; static uint8_t rightEye[384*224]; + status_t status = status_running; while (1) { struct nk_context *ctx; @@ -105,7 +111,9 @@ int uiRun(UIContext *ui) { uint32_t bytes; ctx = ui->win.nk; - emuTick(&ui->emu); + if (status == status_running) { + emuTick(&ui->emu); + } if (emuReadPixels(&ui->emu, leftEye, rightEye)) { windowUpdate(&ui->win, leftEye, rightEye); @@ -135,12 +143,17 @@ int uiRun(UIContext *ui) { } if (nk_menu_begin_label(ctx, "Emulation", NK_TEXT_ALIGN_CENTERED, nk_vec2(120, windowGetScreenHeight(&ui->win)))) { + const char *label = status == status_paused ? "Resume" : "Pause"; nk_layout_row_dynamic(ctx, MENU_HEIGHT + 2, 1); - if (nk_menu_item_label(ctx, "Pause", NK_TEXT_ALIGN_LEFT)) { - printf("Pause\n"); + if (nk_menu_item_label(ctx, label, NK_TEXT_ALIGN_LEFT)) { + if (status == status_paused) + status = status_running; + else + status = status_paused; } if (nk_menu_item_label(ctx, "Reset", NK_TEXT_ALIGN_LEFT)) { - printf("Reset\n"); + emuReset(&ui->emu); + status = status_running; } nk_menu_end(ctx); }