From a23c772687ff5eb0e3546b9c4b782d83c913a676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Fri, 8 Jul 2022 00:48:08 +0100 Subject: [PATCH] fix: switching of the LCD --- examples/sdl/src/main.rs | 4 ++-- src/cpu.rs | 10 +++++++++- src/ppu.rs | 14 ++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 140783c7..4e8d5dba 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 5d3b2c5f..86f7dc97 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 2c081774..55fc2dfd 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(); } -- GitLab