Implement pause and reset

This commit is contained in:
Simon Gellis 2024-10-29 22:33:48 -04:00
parent 0fb8d8e59f
commit 5f0f48fc8b
3 changed files with 22 additions and 4 deletions

View File

@ -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;

View File

@ -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);

19
ui.c
View File

@ -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;
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);
}