From 9a48db9bbc913171c62c86ff8649467474533e2d Mon Sep 17 00:00:00 2001 From: gbc dev Date: Fri, 17 Jul 2026 00:27:06 +0200 Subject: gb: boot ROM (BIOS) support Add optional boot ROM emulation. When a boot ROM image is loaded, gb_reset starts execution at PC=0 with power-on register state instead of the documented post-boot state; the ROM overlays low memory (with the CGB 0x0100-0x01FF header hole showing the cartridge through) until the game writes 0xFF50 to hand off. gb_load_bootrom() accepts 256-byte (DMG) or 2304-byte (CGB) images. --- src/gb.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/gb.h') diff --git a/src/gb.h b/src/gb.h index 5192e85..7162b4d 100644 --- a/src/gb.h +++ b/src/gb.h @@ -118,10 +118,20 @@ struct GB { int serial_out_fd; // if >=0, transmitted serial bytes written here (stdout) int serial_in_fd; // if >=0, received serial bytes read here (stdin), else 0xFF bool poweroff; // set by the $ED opcode: request a clean emulator exit + + // Boot ROM (BIOS). When boot_rom is non-NULL, gb_reset starts execution + // inside it (PC=0) with power-on register state; the ROM maps over low + // memory until the game writes 0xFF50 to hand control to the cartridge. + u8 *boot_rom; + int boot_rom_len; // 0x100 = DMG boot rom, 0x900 = CGB boot rom + bool boot_rom_active; // true while the boot ROM is still mapped in }; void gb_init(GB *gb); void gb_reset(GB *gb); +// Load a boot ROM (BIOS) image so the next gb_reset boots through it. Returns +// 0 on success. 256-byte images boot as DMG; 2304-byte images as CGB. +int gb_load_bootrom(GB *gb, const char *path); // Run one full CPU instruction (advancing all subsystems). Returns T-cycles. int gb_step(GB *gb); void gb_run_frame(GB *gb); -- cgit v1.3.1-sl0p