From 486ab96ab2cc681ce1198cd03325051b97658395 Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Thu, 31 Oct 2024 21:56:58 -0400 Subject: [PATCH] Stop rendering uninitialized memory --- emulation.c | 4 ++++ emulation.h | 1 + ui.c | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/emulation.c b/emulation.c index 09d133d..6611a89 100644 --- a/emulation.c +++ b/emulation.c @@ -41,6 +41,10 @@ void emuReset(EmulationContext *emu) { vbReset(emu->sim); } +bool emuIsGameLoaded(EmulationContext *emu) { + return vbGetCartROM(emu->sim, NULL) != NULL; +} + #define MAX_STEP_CLOCKS 20000000 void emuTick(EmulationContext *emu) { uint32_t clocks = MAX_STEP_CLOCKS; diff --git a/emulation.h b/emulation.h index c931146..8721735 100644 --- a/emulation.h +++ b/emulation.h @@ -20,6 +20,7 @@ int emuInit(EmulationContext *emu); void emuDestroy(EmulationContext *emu); void emuLoadGame(EmulationContext *emu, uint8_t *rom, uint32_t romSize); void emuReset(EmulationContext *emu); +bool emuIsGameLoaded(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 c863718..c3cb86e 100644 --- a/ui.c +++ b/ui.c @@ -106,9 +106,10 @@ typedef enum status_t { } status_t; int uiRun(UIContext *ui, bool running) { - static uint8_t leftEye[384*224]; - static uint8_t rightEye[384*224]; + static uint8_t leftEye[384*224] = {0}; + static uint8_t rightEye[384*224] = {0}; status_t status = running ? status_running : status_paused; + windowUpdate(&ui->win, leftEye, rightEye); while (1) { struct nk_context *ctx; @@ -163,7 +164,7 @@ int uiRun(UIContext *ui, bool running) { } if (nk_menu_item_label(ctx, "Reset", NK_TEXT_ALIGN_LEFT)) { emuReset(&ui->emu); - status = status_running; + status = emuIsGameLoaded(&ui->emu) ? status_running : status_paused; } nk_menu_end(ctx); }