From f2d1dda0fbf44dfec4e73904d109100034f998e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Sun, 10 Jul 2022 19:01:36 +0100 Subject: [PATCH] fix: more small fixes --- examples/sdl/src/main.rs | 4 ++-- src/cpu.rs | 8 ++++---- src/ppu.rs | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 3782eb14..ad4324cb 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -161,11 +161,11 @@ fn main() { //let rom = game_boy.load_rom_file("../../res/roms.prop/super_mario.gb"); //let rom = game_boy.load_rom_file("../../res/roms.prop/super_mario_2.gb"); - //let rom = game_boy.load_rom_file("../../res/roms/firstwhite.gb"); + let rom = game_boy.load_rom_file("../../res/roms/firstwhite.gb"); //let rom = game_boy.load_rom_file("../../res/roms/opus5.gb"); //let rom = game_boy.load_rom_file("../../res/roms/paradius/cpu/cpu_instrs.gb"); // PASSED - let rom = game_boy.load_rom_file("../../res/roms/paradius/interrupt_time/interrupt_time.gb"); // FAILED + //let rom = game_boy.load_rom_file("../../res/roms/paradius/interrupt_time/interrupt_time.gb"); // FAILED //let rom = game_boy.load_rom_file("../../res/roms/paradius/instr_timing/instr_timing.gb"); // PASSED //let rom = game_boy.load_rom_file("../../res/roms/paradius/mem_timing/mem_timing.gb"); // FAILED //let rom = game_boy.load_rom_file("../../res/roms/paradius/cpu/01-special.gb"); // PASSED diff --git a/src/cpu.rs b/src/cpu.rs index fda81cf9..0d60d5c1 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -118,7 +118,7 @@ impl Cpu { self.halted = false; } - return 20; + return 24; } // @todo aggregate the handling of these interrupts else if (self.mmu.ie & 0x02 == 0x02) && self.mmu.ppu().int_stat() { @@ -138,7 +138,7 @@ impl Cpu { self.halted = false; } - return 20; + return 24; } // @todo aggregate the handling of these interrupts else if (self.mmu.ie & 0x04 == 0x04) && self.mmu.timer().int_tima() { @@ -158,7 +158,7 @@ impl Cpu { self.halted = false; } - return 20; + return 24; } // @todo aggregate the handling of these interrupts else if (self.mmu.ie & 0x10 == 0x10) && self.mmu.pad().int_pad() { @@ -178,7 +178,7 @@ impl Cpu { self.halted = false; } - return 20; + return 24; } } diff --git a/src/ppu.rs b/src/ppu.rs index 85f1d278..6e1d418c 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -334,6 +334,12 @@ impl Ppu { } pub fn clock(&mut self, cycles: u8) { + // in case the LCD is currently off then we skip the current + // clock operation the PPU should not work + 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; @@ -444,6 +450,13 @@ impl Ppu { // to clear the screen, this is the expected // behaviour for this specific situation if !self.switch_lcd { + self.mode = PpuMode::HBlank; + self.mode_clock = 0; + self.ly = 0; + self.int_vblank = false; + self.int_stat = false; + self.clear_frame_buffer(); + } else { self.clear_frame_buffer(); } } @@ -617,9 +630,6 @@ impl Ppu { } fn render_line(&mut self) { - if !self.switch_lcd { - return; - } if self.switch_bg { self.render_map(self.bg_map, self.scx, self.scy, 0, 0); } -- GitLab