Skip to content

Commit

Permalink
Reset DMA DAS register after transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Dec 9, 2023
1 parent 6b33c97 commit 5ad4bb9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/snes/bus/mainbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -291,6 +291,7 @@ where
DMAStep::Fixed => (),
};
}
self.dma[ch].das = 0;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/snes/ppu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ where
}
Some(())
}

// SETINI - Display Control 2 (W)
0x2133 => {
println!("SETINI = {}", val);
Some(self.setini = val)
}
_ => None,
},

Expand Down
9 changes: 7 additions & 2 deletions src/snes/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub struct PPU<TRenderer: Renderer> {
oam_writebuf: u8,

inidisp: u8,
setini: u8,

// Window settings
w1_left: u8,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -253,6 +253,7 @@ where
oam_writebuf: 0,

inidisp: 0,
setini: 0,

w1_left: 0,
w1_right: 0,
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions src/snes/ppu/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5ad4bb9

Please sign in to comment.