diff options
| author | gbc dev <gbc@localhost> | 2026-07-16 12:49:02 +0200 |
|---|---|---|
| committer | gbc dev <gbc@localhost> | 2026-07-16 12:49:02 +0200 |
| commit | ca6f9bb91893cf50c8e09bf7396085a7d69e80ab (patch) | |
| tree | 64ccd983aaf5322f423489caf4c68d4949dab1bb /src/main.c | |
| parent | headless: interactive TTY mode (raw stdin) for driving a guest OS live (diff) | |
| download | sl0pboy-ca6f9bb91893cf50c8e09bf7396085a7d69e80ab.tar.gz sl0pboy-ca6f9bb91893cf50c8e09bf7396085a7d69e80ab.tar.xz sl0pboy-ca6f9bb91893cf50c8e09bf7396085a7d69e80ab.zip | |
headless: $ED opcode = clean power-off (exit + battery save)
The unused SM83 opcode $ED now sets gb->poweroff, which breaks the headless
loop so the normal cart_free()->cart_save() path runs. Lets a guest OS shut the
emulator down cleanly (and flush its .sav) instead of relying on an external
timeout/SIGTERM, which could SIGKILL before the save. run_frame() also stops on
poweroff so exit is immediate.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -24,7 +24,7 @@ static void run_frame(GB *gb) { gb->ppu.frame_ready = false; // safety bound in case LCD is off (no frame_ready) u64 budget = gb->cycles + 70224 * 2; - while (!gb->ppu.frame_ready && gb->cycles < budget) + while (!gb->ppu.frame_ready && gb->cycles < budget && !gb->poweroff) cpu_step(gb); } @@ -120,7 +120,7 @@ int main(int argc, char **argv) { double start_t = now_sec(); u64 start_cyc = gb->cycles; const double HZ = 4194304.0; - while (running) { + while (running && !gb->poweroff) { run_frame(gb); // advance ~a frame's worth of cycles if (!uncapped) { double target = start_t + (gb->cycles - start_cyc) / HZ; |
