diff options
-rw-r--r-- | src/main.rs | 11 | ||||
-rw-r--r-- | src/ppu.rs | 7 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index c53068b..ca6219f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,9 +228,6 @@ fn main() { cpu.step(); //println!("cpu at 0x{:04x}", cpu.get_pc()); while cpu.cycle > 0 { - if ppu.tick() || ppu.tick() || ppu.tick() { - cpu.trigger_nmi(); - } cnt += 1; if cnt >= CYC_PER_FRAME { win.render(); @@ -239,13 +236,17 @@ fn main() { if duration_per_frame > e { let diff = duration_per_frame - e; sleep(diff); - //println!("{} faster", diff.subsec_nanos() as f64 / 1e6); + println!("{} faster", diff.subsec_nanos() as f64 / 1e6); } else { - //println!("{} slower", (e - duration_per_frame).subsec_nanos() as f64 / 1e6); + println!("{} slower", (e - duration_per_frame).subsec_nanos() as f64 / 1e6); } timer = Instant::now(); cnt -= CYC_PER_FRAME; } + + if ppu.tick() || ppu.tick() || ppu.tick() { + cpu.trigger_nmi(); + } cpu.cycle -= 1; } } @@ -89,7 +89,6 @@ impl<'a> PPU<'a> { #[inline] pub fn write_oamdata(&mut self, data: u8) { self.reg = data; - if self.rendering { return } unsafe { let oam_raw = transmute::<&mut[Sprite; 64], &mut[u8; 256]>(&mut self.oam); oam_raw[self.oamaddr as usize] = data; @@ -109,6 +108,9 @@ impl<'a> PPU<'a> { pub fn write_scroll(&mut self, data: u8) { self.reg = data; let data = data as u16; + if !(!(self.get_show_bg() || self.get_show_sp()) || self.get_flag_vblank()) { + println!("writing to scroll {} {}", self.scanline, self.cycle); + } match self.w { false => { self.t = (self.t & 0x7fe0) | (data >> 3); @@ -491,8 +493,7 @@ impl<'a> PPU<'a> { } let visible_line = self.scanline < 240; let pre_line = self.scanline == 261; - self.rendering = pre_line || visible_line; - if self.rendering && (self.get_show_bg() || self.get_show_sp()) { + if (pre_line || visible_line) && (self.get_show_bg() || self.get_show_sp()) { if pre_line && 279 < cycle && cycle < 305 { self.reset_y(); } else { |