From e9ce8cd2ad7904357102c2503dc1e03880377b6f Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Mon, 27 May 2024 13:23:49 +0100 Subject: [PATCH] hblack_transfer doesn't need to be unsafe --- agb/src/dma.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/agb/src/dma.rs b/agb/src/dma.rs index b1a3aac9..48e870db 100644 --- a/agb/src/dma.rs +++ b/agb/src/dma.rs @@ -70,14 +70,10 @@ impl Dma { /// drop the DmaTransferHandler return value until the next vblank interrupt to ensure that you /// a continuous effect. /// - /// # Safety - /// - /// While DmaTransferHandle is not dropped, the slice at `values` must not move in memory. - /// /// # Examples /// /// See the `dma_effect_*` examples in the repository to see some ways to use this. - pub unsafe fn hblank_transfer( + pub fn hblank_transfer( &self, location: &DmaControllable, values: &[T], @@ -93,10 +89,13 @@ impl Dma { let n_transfers = (size_of::() / 2) as u32; - self.source_addr.set(handle.data.as_ptr().add(1) as u32); + self.source_addr.set(handle.data[1..].as_ptr() as u32); self.dest_addr.set(location.memory_location as u32); - location.memory_location.write_volatile(values[0]); + // SAFETY: by construction it is safe to write to location.memory_location + unsafe { + location.memory_location.write_volatile(values[0]); + } self.ctrl_addr.set( (0b10 << 0x15) | // keep destination address fixed