diff --git a/lib/src/processor/memory/mmio/cgb/vram_dma.rs b/lib/src/processor/memory/mmio/cgb/vram_dma.rs index 9432eb1..c098261 100644 --- a/lib/src/processor/memory/mmio/cgb/vram_dma.rs +++ b/lib/src/processor/memory/mmio/cgb/vram_dma.rs @@ -86,22 +86,27 @@ where let returning = if let Some(cgb_peripherals) = &mut self.cgb_peripherals { match cgb_peripherals.vram_dma.mode { DmaMode::Halt(l) => { + let length = 16 * ((l as u16) + 1); copy = Some(( - cgb_peripherals.vram_dma.destination, cgb_peripherals.vram_dma.source, - 16 * ((l as u16) + 1), + cgb_peripherals.vram_dma.destination, + length, )); + cgb_peripherals.vram_dma.source += length; + cgb_peripherals.vram_dma.destination += length; cgb_peripherals.vram_dma.mode = DmaMode::Waiting; ((l as usize) + 1) * 8 } DmaMode::Hblank(l, ref mut progress) => { if self.gpu.get_mode() == DrawMode::HBlank { - let offset = *progress * 16; + let length = 16; copy = Some(( - cgb_peripherals.vram_dma.destination + offset, - cgb_peripherals.vram_dma.source + offset, - 16, + cgb_peripherals.vram_dma.source, + cgb_peripherals.vram_dma.destination, + length, )); + cgb_peripherals.vram_dma.source += length; + cgb_peripherals.vram_dma.destination += length; *progress += 1; if *progress > (l as u16) { cgb_peripherals.vram_dma.mode = DmaMode::Waiting @@ -118,7 +123,7 @@ where }; if let Some((source, dest, length)) = copy { for i in 0..length { - self.set(dest + i, self.get(source + i)); + self.set(source + i, self.get(dest + i)); } } if self.is_double_speed() {