From 9e0afbed72e6c1e0bc2012a0d1093123504adb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Mon, 4 Jul 2022 17:49:11 +0100 Subject: [PATCH] feat: new checking of interrupt level --- examples/sdl/src/main.rs | 4 ++-- src/cpu.rs | 12 ++++++------ src/ppu.rs | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/sdl/src/main.rs b/examples/sdl/src/main.rs index 1250a53a..30a302f3 100644 --- a/examples/sdl/src/main.rs +++ b/examples/sdl/src/main.rs @@ -81,8 +81,8 @@ fn main() { let mut game_boy = GameBoy::new(); game_boy.load_boot_sgb(); //game_boy.load_rom_file("../../res/roms.prop/tetris.gb"); - game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); - //game_boy.load_rom_file("../../res/roms/07-jr,jp,call,ret,rst.gb"); + //game_boy.load_rom_file("../../res/roms.prop/alleyway.gb"); + game_boy.load_rom_file("../../res/roms/07-jr,jp,call,ret,rst.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/ld_r_r.gb"); diff --git a/src/cpu.rs b/src/cpu.rs index ceed42e7..50553ec3 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -108,12 +108,12 @@ impl Cpu { let (instruction_fn, instruction_time, instruction_str) = instruction; - if *instruction_str == "! UNIMP !" { - println!( - "{}\t(0x{:02x})\t${:04x} {}", - instruction_str, opcode, pc, is_prefix - ); - } + //if *instruction_str == "! UNIMP !" { + println!( + "{}\t(0x{:02x})\t${:04x} {}", + instruction_str, opcode, pc, is_prefix + ); + //} // calls the current instruction and increments the number of // cycles executed by the instruction time of the instruction diff --git a/src/ppu.rs b/src/ppu.rs index c1615c02..d8110299 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -94,9 +94,9 @@ pub struct Ppu { stat_lyc: bool, } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub enum PpuMode { - Hblank = 0, + HBlank = 0, VBlank = 1, OamRead = 2, VramRead = 3, @@ -156,10 +156,10 @@ impl Ppu { } self.mode_clock = 0; - self.mode = PpuMode::Hblank; + self.mode = PpuMode::HBlank; } } - PpuMode::Hblank => { + PpuMode::HBlank => { if self.mode_clock >= 204 { self.ly += 1; @@ -396,4 +396,13 @@ impl Ppu { print!("\n"); } } + + /// Obtains the current level of the LCD interrupt by + /// checking the current PPU state in various sections. + fn interrupt_level(&self) -> bool { + self.stat_lyc && self.lyc == self.ly + || self.stat_oam && self.mode == PpuMode::OamRead + || self.stat_vblank && self.mode == PpuMode::VBlank + || self.stat_vblank && self.mode == PpuMode::HBlank + } } -- GitLab