diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 140783c7988cd48b8025e5210997a855ce34bc48..4e8d5dba1b119fdd7945fe81163b8c5f30f0fcf9 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -89,10 +89,10 @@ fn main() { //game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); //game_boy.load_rom_file("../../res/roms/firstwhite.gb"); - //game_boy.load_rom_file("../../res/roms/opus5.gb"); + game_boy.load_rom_file("../../res/roms/opus5.gb"); //game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED - game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); + //game_boy.load_rom_file("../../res/roms/paradius/cpu/02-interrupts.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/03-op sp,hl.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/04-op r,imm.gb"); // PASSED //game_boy.load_rom_file("../../res/roms/paradius/cpu/05-op rp.gb"); // PASSED diff --git a/src/cpu.rs b/src/cpu.rs index 5d3b2c5f49e9660dccaf55c1b4a2c52f8796d491..86f7dc97879bc74470903a99ac69eac1dab194b3 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -109,6 +109,14 @@ impl Cpu { panic!("Invalid PC area at 0x{:04x}", pc); } + //Â @todo this is so bad, need to improve this by an order + // of magnitude + if self.halted { + if ((self.mmu.ie & 0x01 == 0x01) && self.mmu.ppu().int_vblank()) || ((self.mmu.ie & 0x04 == 0x04) && self.mmu.timer().int_tima()) { + self.halted = false; + } + } + if self.ime { // @todo aggregate all of this interrupts in the MMU if (self.mmu.ie & 0x01 == 0x01) && self.mmu.ppu().int_vblank() { @@ -179,7 +187,7 @@ impl Cpu { if *instruction_str == "! UNIMP !" || *instruction_str == "HALT" { if *instruction_str == "HALT" { - println!("Waiting for 0x{:02x} in HALT", self.mmu.ie); + println!("HALT with IE=0x{:02x} IME={}", self.mmu.ie, self.ime); } println!( "{}\t(0x{:02x})\t${:04x} {}", diff --git a/src/ppu.rs b/src/ppu.rs index 2c08177413f1e4f8a73456ef7e7bca50de8c5b9f..55fc2dfd5540fcb68e0197923406312a2012fe51 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -316,10 +316,6 @@ impl Ppu { } pub fn clock(&mut self, cycles: u8) { - if !self.switch_lcd { - return; - } - // increments the current mode clock by the provided amount // of CPU cycles (probably coming from a previous CPU clock) self.mode_clock += cycles as u16; @@ -416,6 +412,13 @@ impl Ppu { self.switch_window = value & 0x20 == 0x20; self.window_map = value & 0x40 == 0x40; self.switch_lcd = value & 0x80 == 0x80; + + // in case the LCD is off takes the opportunity + // to clear the screen, this is the expected + // behaviour for this specific situation + if !self.switch_lcd { + self.clear_frame_buffer(); + } } 0x0041 => { self.stat_hblank = value & 0x04 == 0x04; @@ -579,6 +582,9 @@ impl Ppu { } fn render_line(&mut self) { + if !self.switch_lcd { + return; + } if self.switch_bg { self.render_background(); }