diff --git a/src/snes/bus/mainbus.rs b/src/snes/bus/mainbus.rs index 26491d6..97bc86d 100644 --- a/src/snes/bus/mainbus.rs +++ b/src/snes/bus/mainbus.rs @@ -113,7 +113,7 @@ struct DMAChannel { /// DMA byte-counter / Indirect HDMA address das: u16, - /// DMA byte-counter / Indirect HDMA address (bank) + /// Indirect HDMA address (bank) dasb: u8, /// HDMA Table Current Address @@ -291,6 +291,7 @@ where DMAStep::Fixed => (), }; } + self.dma[ch].das = 0; } } diff --git a/src/snes/ppu/bus.rs b/src/snes/ppu/bus.rs index de56b4f..c772142 100644 --- a/src/snes/ppu/bus.rs +++ b/src/snes/ppu/bus.rs @@ -343,7 +343,11 @@ where } Some(()) } - + // SETINI - Display Control 2 (W) + 0x2133 => { + println!("SETINI = {}", val); + Some(self.setini = val) + } _ => None, }, diff --git a/src/snes/ppu/mod.rs b/src/snes/ppu/mod.rs index f09416b..654c982 100644 --- a/src/snes/ppu/mod.rs +++ b/src/snes/ppu/mod.rs @@ -146,6 +146,7 @@ pub struct PPU { oam_writebuf: u8, inidisp: u8, + setini: u8, // Window settings w1_left: u8, @@ -215,7 +216,6 @@ where { const CYCLES_PER_SCANLINE: usize = 340 * 4; const SCANLINES_PER_FRAME: usize = 262; // including V-blank - const VBLANK_START: usize = 0xE1; const LINE_HBLANK_START: usize = 274 * 4; pub fn new(renderer: TRenderer) -> Self { @@ -253,6 +253,7 @@ where oam_writebuf: 0, inidisp: 0, + setini: 0, w1_left: 0, w1_right: 0, @@ -455,7 +456,11 @@ where } pub fn in_vblank(&self) -> bool { - self.last_scanline >= Self::VBLANK_START + self.last_scanline > if self.setini & (1 << 2) != 0 { + 239 + } else { + 224 + } } pub fn in_hblank(&self) -> bool { diff --git a/src/snes/ppu/tests.rs b/src/snes/ppu/tests.rs index f0cf6bc..5e96b51 100644 --- a/src/snes/ppu/tests.rs +++ b/src/snes/ppu/tests.rs @@ -53,6 +53,26 @@ fn vram_write_inc_high() { assert_eq!(p.vram[0x1236], 0x0000); } +#[test] +fn vram_write_inc_high_2() { + let mut p = ppu(); + p.write(0x2116, 0x34); // VMADDH + p.write(0x2117, 0x12); // VMADDL + p.write(0x2115, 0x80); // VMAIN - high 1 word + + p.vram[0x1234] = 0x1111; + p.vram[0x1235] = 0x2222; + + assert_eq!(p.vmadd.get(), 0x1234); + p.write(0x2119, 0xAA); // VMDATAH + assert_eq!(p.vmadd.get(), 0x1235); + p.write(0x2119, 0xBB); // VMDATAH + assert_eq!(p.vmadd.get(), 0x1236); + + assert_eq!(p.vram[0x1234], 0xAA11); + assert_eq!(p.vram[0x1235], 0xBB22); +} + #[test] fn vram_write_inc_thirtytwo() { let mut p = ppu();