Skip to content

Commit

Permalink
Implement DMA mode 3, some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Nov 27, 2023
1 parent 94be55a commit 7fd64fe
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions src/snes/bus/mainbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,43 +311,33 @@ where
//
// This is due to the fact A-address increment behaves
// differently for HDMA.
match self.dma[ch].mode() {
0 => {
match self.dma[ch].direction() {
DMADirection::CPUToIO => {
let v = self.read(a_addr);
self.write(b_addr, v);
}
DMADirection::IOToCPU => {
let v = self.read(b_addr);
self.write(a_addr, v);
}
}
0
}
1 => {
let b_addr = b_addr + (unit_offset % 2);
match self.dma[ch].direction() {
DMADirection::CPUToIO => {
let v = self.read(a_addr);
self.write(b_addr, v);
}
_ => todo!(),
}
1 - (unit_offset % 2)

// Map b_addr and bytes remaining depending on DMA mode
let (b_addr, remaining) = match self.dma[ch].mode() {
// Transfer 1 byte xx
0 => (b_addr, 0),
// Transfer 2 bytes xx, xx+1
1 => (b_addr.wrapping_add(unit_offset % 2), 1 - (unit_offset % 2)),
// Transfer 2 bytes xx, xx
2 | 6 => (b_addr, 1 - (unit_offset % 2)),
// Transfer 4 bytes xx, xx, xx+1, xx+1
3 | 7 => (b_addr.wrapping_add(unit_offset / 2), 3 - (unit_offset % 4)),
_ => panic!("Unimplemented DMA mode {}", self.dma[ch].mode()),
};

// Transfer the byte in whichever direction
match self.dma[ch].direction() {
DMADirection::CPUToIO => {
let v = self.read(a_addr);
self.write(b_addr, v);
}
2 => {
match self.dma[ch].direction() {
DMADirection::CPUToIO => {
let v = self.read(a_addr);
self.write(b_addr, v);
}
_ => todo!(),
}
1 - (unit_offset % 2)
DMADirection::IOToCPU => {
let v = self.read(b_addr);
self.write(a_addr, v);
}
_ => panic!("Unimplemented DMA mode {}", self.dma[ch].mode()),
}

remaining
}

fn hdma_reset(&mut self) {
Expand Down

0 comments on commit 7fd64fe

Please sign in to comment.