Extract dma_copy to its own module

This commit is contained in:
Gwilym Kuiper 2022-03-05 19:43:48 +00:00
parent 068bc95fe7
commit 09f6736497
4 changed files with 29 additions and 50 deletions

View file

@ -3,6 +3,7 @@ use core::ops::{Deref, DerefMut};
use crate::bitarray::Bitarray; use crate::bitarray::Bitarray;
use crate::display::{self, Priority, DISPLAY_CONTROL}; use crate::display::{self, Priority, DISPLAY_CONTROL};
use crate::dma::dma_copy;
use crate::fixnum::Vector2D; use crate::fixnum::Vector2D;
use crate::memory_mapped::MemoryMapped; use crate::memory_mapped::MemoryMapped;
@ -190,28 +191,3 @@ fn div_ceil(x: i32, y: i32) -> i32 {
x / y x / y
} }
} }
const fn dma_source_addr(dma: usize) -> usize {
0x0400_00b0 + 0x0c * dma
}
const fn dma_dest_addr(dma: usize) -> usize {
0x0400_00b4 + 0x0c * dma
}
const fn dma_control_addr(dma: usize) -> usize {
0x0400_00b8 + 0x0c * dma
}
const DMA3_SOURCE_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_source_addr(3)) };
const DMA3_DEST_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_dest_addr(3)) };
const DMA3_CONTROL: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_control_addr(3)) };
unsafe fn dma_copy(src: *const u16, dest: *mut u16, count: usize) {
assert!(count < u16::MAX as usize);
DMA3_SOURCE_ADDR.set(src as u32);
DMA3_DEST_ADDR.set(dest as u32);
DMA3_CONTROL.set(count as u32 | (1 << 31));
}

View file

@ -3,6 +3,7 @@ use alloc::vec::Vec;
use crate::{ use crate::{
display::palette16, display::palette16,
dma::dma_copy,
memory_mapped::{MemoryMapped, MemoryMapped1DArray}, memory_mapped::{MemoryMapped, MemoryMapped1DArray},
}; };
@ -291,28 +292,3 @@ impl<'a> VRamManager<'a> {
} }
} }
} }
const fn dma_source_addr(dma: usize) -> usize {
0x0400_00b0 + 0x0c * dma
}
const fn dma_dest_addr(dma: usize) -> usize {
0x0400_00b4 + 0x0c * dma
}
const fn dma_control_addr(dma: usize) -> usize {
0x0400_00b8 + 0x0c * dma
}
const DMA3_SOURCE_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_source_addr(3)) };
const DMA3_DEST_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_dest_addr(3)) };
const DMA3_CONTROL: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_control_addr(3)) };
unsafe fn dma_copy(src: *const u16, dest: *mut u16, count: usize) {
assert!(count < u16::MAX as usize);
DMA3_SOURCE_ADDR.set(src as u32);
DMA3_DEST_ADDR.set(dest as u32);
DMA3_CONTROL.set(count as u32 | (1 << 31));
}

26
agb/src/dma.rs Normal file
View file

@ -0,0 +1,26 @@
use crate::memory_mapped::MemoryMapped;
const fn dma_source_addr(dma: usize) -> usize {
0x0400_00b0 + 0x0c * dma
}
const fn dma_dest_addr(dma: usize) -> usize {
0x0400_00b4 + 0x0c * dma
}
const fn dma_control_addr(dma: usize) -> usize {
0x0400_00b8 + 0x0c * dma
}
const DMA3_SOURCE_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_source_addr(3)) };
const DMA3_DEST_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_dest_addr(3)) };
const DMA3_CONTROL: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_control_addr(3)) };
pub(crate) unsafe fn dma_copy(src: *const u16, dest: *mut u16, count: usize) {
assert!(count < u16::MAX as usize);
DMA3_SOURCE_ADDR.set(src as u32);
DMA3_DEST_ADDR.set(dest as u32);
DMA3_CONTROL.set(count as u32 | (1 << 31));
}

View file

@ -142,6 +142,7 @@ mod arena;
mod bitarray; mod bitarray;
/// Implements everything relating to things that are displayed on screen. /// Implements everything relating to things that are displayed on screen.
pub mod display; pub mod display;
mod dma;
/// Button inputs to the system. /// Button inputs to the system.
pub mod input; pub mod input;
#[doc(hidden)] // hide for now as the implementation in here is unsound #[doc(hidden)] // hide for now as the implementation in here is unsound