From c692ed2b75ea5d4aac3a0786bb26fd239357b272 Mon Sep 17 00:00:00 2001 From: Assil Ksiksi Date: Thu, 28 Jan 2021 23:32:14 -0500 Subject: [PATCH] Update PPU mode even if LCD is disabled --- emu/src/main.rs | 15 +++++++-------- lib/src/cpu.rs | 2 ++ lib/src/ppu.rs | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/emu/src/main.rs b/emu/src/main.rs index ff0bd7d..fd7ba09 100644 --- a/emu/src/main.rs +++ b/emu/src/main.rs @@ -19,19 +19,19 @@ use structopt::StructOpt; enum Args { #[structopt(about = "Run a ROM on the emulator")] Run { - #[structopt(parse(from_os_str))] + #[structopt(parse(from_os_str), help = "Path to ROM file")] rom_file: PathBuf, - #[structopt(default_value = "6", long)] + #[structopt(default_value = "4", long, help = "Emulation resolution multiplier")] scale: u32, - #[structopt(default_value = "1", long)] + #[structopt(default_value = "1", long, help = "Emulation speed multiplier")] speed: u8, - #[structopt(long)] + #[structopt(long, help = "Boot into the DMG boot ROM")] boot_rom: bool, - #[structopt(long)] + #[structopt(long, help = "Trace all instructions to a file in the current directory")] trace: bool, }, #[structopt(about = "Inspect a ROM")] @@ -248,7 +248,6 @@ fn gui(rom_file: PathBuf, scale: u32, speed: u8, boot_rom: bool, trace: bool) { if !paused { // Render a single frame handle_frame(&mut gameboy, &mut canvas, &mut texture, &mut joypad_events, outline); - } let elapsed = frame_start.elapsed(); @@ -288,8 +287,8 @@ fn main() { Ok(c) => c, }; - println!("\nTitle: {}", cartridge.title().unwrap()); - println!("Manufacturer: {}", cartridge.manufacturer_code().unwrap()); + println!("\nTitle: {}", cartridge.title().unwrap_or("N/A")); + println!("Manufacturer: {}", cartridge.manufacturer_code().unwrap_or("N/A")); println!("GBC support: {}", cartridge.cgb()); println!("Cartridge type: {:?}", cartridge.cartridge_type().unwrap()); println!("ROM size: {:?}", cartridge.rom_size().unwrap()); diff --git a/lib/src/cpu.rs b/lib/src/cpu.rs index 1a89929..1be5a27 100644 --- a/lib/src/cpu.rs +++ b/lib/src/cpu.rs @@ -234,6 +234,8 @@ impl Cpu { // Then write the instruction write!(f, "{:03}:{}:{:#06X} - {}\n\n", bank, memory_type, pc, inst).unwrap(); + + f.flush().unwrap(); } /// Execute a single step of DMA (if active). diff --git a/lib/src/ppu.rs b/lib/src/ppu.rs index b529045..68ba775 100644 --- a/lib/src/ppu.rs +++ b/lib/src/ppu.rs @@ -512,16 +512,14 @@ impl Ppu { self.dot = dot; self.ly = line; - if self.lcdc.lcd_display_enable() { - // Update the internal PPU status - // - // This also returns which interrupts need to be triggered - let stat_mode_change = self.update_status(mode, interrupts); + // Update the internal PPU status + // + // This also returns which interrupts need to be triggered + let stat_mode_change = self.update_status(mode, interrupts); - if stat_mode_change { - // Render data to the frame - self.render(); - } + if self.lcdc.lcd_display_enable() && stat_mode_change { + // Render data to the frame + self.render(); } } @@ -1133,6 +1131,7 @@ impl MemoryRead for Ppu { self.vram.read(addr) } else { // PPU returns 0xFF if VRAM is locked + log::info!("Blocked VRAM read from 0x{:X}", addr); 0xFF } } @@ -1183,6 +1182,8 @@ impl MemoryWrite for Ppu { if !self.oam_locked() { let idx = (addr - Self::OAM_START_ADDR) as usize; self.oam[idx] = value; + } else { + log::info!("Blocked OAM write to 0x{:X}: 0x{:X}", addr, value); } } Self::LCDC_ADDR => {