Skip to content
Snippets Groups Projects
Verified Commit 23c44222 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: instant boot supprot

parent 2cdf1078
No related branches found
No related tags found
No related merge requests found
Pipeline #1005 passed
......@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
*
* Instant boot support using the `GameBoy.boot()` method
### Changed
......
......@@ -158,7 +158,7 @@ fn main() {
game_boy.load_boot_default();
let mut emulator = Emulator::new(game_boy, SCREEN_SCALE);
emulator.load_rom("../../res/roms.prop/dr_mario.gb");
emulator.load_rom("../../res/roms.prop/super_mario.gb");
emulator.run();
}
......
......@@ -76,6 +76,31 @@ impl Cpu {
self.cycles = 0;
}
/// Sets the CPU registers and some of the memory space to the
/// state expected after the Game Boy boot ROM executes, using
/// these values its possible to skip the boot loading process.
pub fn boot(&mut self) {
self.pc = 0x0100;
self.sp = 0xfffe;
self.a = 0x01;
self.b = 0xff;
self.c = 0x13;
self.d = 0x00;
self.e = 0xc1;
self.h = 0x84;
self.l = 0x03;
self.zero = false;
self.sub = false;
self.half_carry = false;
self.carry = false;
// updates part of the MMU state, disabling the
// boot memory overlap and setting the LCD control
// register to enabled (required by some ROMs)
self.mmu.set_boot_active(false);
self.mmu.write(0xff40, 0x91);
}
pub fn clock(&mut self) -> u8 {
// gathers the PC (program counter) reference that
// is going to be used in the fetching phase
......
......@@ -69,6 +69,10 @@ impl GameBoy {
self.timer().clock(cycles)
}
pub fn boot(&mut self) {
self.cpu.boot();
}
pub fn load_boot(&mut self, data: &[u8]) {
self.cpu.mmu().write_boot(0x0000, data);
}
......
......@@ -17,13 +17,19 @@ pub struct Mmu {
/// the I/O access to this device.
pad: Pad,
/// The timer controller to be used as part of the I/O access
/// that is memory mapped.
timer: Timer,
/// The cartridge ROM that is currently loaded into the system,
/// going to be used to access ROM and external RAM banks.
rom: Cartridge,
/// Flag that control the access to the boot section in the
/// 0x0000-0x00fe memory area, this flag should be unset after
/// the bool sequence has been finished.
boot_active: bool,
boot: [u8; BOOT_SIZE],
ram: [u8; RAM_SIZE],
}
......@@ -66,6 +72,10 @@ impl Mmu {
self.boot_active
}
pub fn set_boot_active(&mut self, value: bool) {
self.boot_active = value;
}
pub fn read(&mut self, addr: u16) -> u8 {
match addr & 0xf000 {
// BOOT (256 B) + ROM0 (4 KB/16 KB)
......
......@@ -303,7 +303,7 @@ impl Ppu {
switch_window: false,
window_map: false,
switch_lcd: false,
first_frame: true,
first_frame: false,
stat_hblank: false,
stat_vblank: false,
stat_oam: false,
......@@ -337,6 +337,7 @@ impl Ppu {
self.switch_window = false;
self.window_map = false;
self.switch_lcd = false;
self.first_frame = false;
self.stat_hblank = false;
self.stat_vblank = false;
self.stat_oam = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment