Skip to content

Commit

Permalink
Update PPU mode even if LCD is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
aksiksi committed Jan 29, 2021
1 parent fdaab91 commit c692ed2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
15 changes: 7 additions & 8 deletions emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions lib/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
19 changes: 10 additions & 9 deletions lib/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -1133,6 +1131,7 @@ impl MemoryRead<u16, u8> for Ppu {
self.vram.read(addr)
} else {
// PPU returns 0xFF if VRAM is locked
log::info!("Blocked VRAM read from 0x{:X}", addr);
0xFF
}
}
Expand Down Expand Up @@ -1183,6 +1182,8 @@ impl MemoryWrite<u16, u8> 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 => {
Expand Down

0 comments on commit c692ed2

Please sign in to comment.