Write a custom tile copy command

This commit is contained in:
Gwilym Inzani 2023-09-05 23:52:35 +01:00
parent c04d674101
commit e504b93fe3
4 changed files with 37 additions and 11 deletions

View file

@ -4,14 +4,6 @@ global_asm!(include_str!("macros.inc"));
global_asm!(include_str!("memcpy.s")); global_asm!(include_str!("memcpy.s"));
global_asm!(include_str!("memset.s")); global_asm!(include_str!("memset.s"));
extern "C" {
fn __aeabi_memcpy4(dest: *mut u32, src: *const u32, n: usize);
}
pub(crate) unsafe fn memcpy(dest: *mut u32, src: *const u32, n: usize) {
__aeabi_memcpy4(dest, src, n);
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
mod memset { mod memset {

View file

@ -0,0 +1,27 @@
agb_arm_func copy_tile_8bpp
@ Arguments
@ r0 - pointer to the image data beginning
@ r1 - pointer to the target in vram
push {{r4-r8}}
.rept 2
ldmia r0!, {{r2-r8, r12}}
stmia r1!, {{r2-r8, r12}}
.endr
pop {{r4-r8}}
bx lr
agb_arm_end copy_tile_8bpp
agb_arm_func copy_tile_4bpp
@ Arguments
@ r0 - pointer to the image data beginning
@ r1 - pointer to the target in vram
push {{r4-r8}}
ldmia r0!, {{r2-r8, r12}}
stmia r1!, {{r2-r8, r12}}
pop {{r4-r8}}
bx lr
agb_arm_end copy_tile_4bpp

View file

@ -4,7 +4,6 @@ use alloc::{slice, vec::Vec};
use crate::{ use crate::{
agb_alloc::{block_allocator::BlockAllocator, bump_allocator::StartEnd}, agb_alloc::{block_allocator::BlockAllocator, bump_allocator::StartEnd},
agbabi,
display::palette16, display::palette16,
dma::dma_copy16, dma::dma_copy16,
hash_map::{Entry, HashMap}, hash_map::{Entry, HashMap},
@ -381,11 +380,13 @@ impl VRamManager {
let tile_offset = (tile_id as usize) * tile_size; let tile_offset = (tile_id as usize) * tile_size;
let tile_slice = &tile_set.tiles[tile_offset..(tile_offset + tile_size)]; let tile_slice = &tile_set.tiles[tile_offset..(tile_offset + tile_size)];
let tile_size = tile_slice.len();
let target_location = tile_reference.0.as_ptr() as *mut _; let target_location = tile_reference.0.as_ptr() as *mut _;
unsafe { unsafe {
agbabi::memcpy(target_location, tile_slice.as_ptr() as *const _, tile_size); match tile_set.format {
TileFormat::FourBpp => copy_tile_4bpp(tile_slice.as_ptr().cast(), target_location),
TileFormat::EightBpp => copy_tile_8bpp(tile_slice.as_ptr().cast(), target_location),
}
} }
} }
@ -409,3 +410,8 @@ impl VRamManager {
} }
} }
} }
extern "C" {
fn copy_tile_4bpp(src: *const u32, dest: *mut u32);
fn copy_tile_8bpp(src: *const u32, dest: *mut u32);
}

View file

@ -6,3 +6,4 @@ global_asm!(include_str!("crt0.s"));
global_asm!(include_str!("interrupt_handler.s")); global_asm!(include_str!("interrupt_handler.s"));
global_asm!(include_str!("sound/mixer/mixer.s")); global_asm!(include_str!("sound/mixer/mixer.s"));
global_asm!(include_str!("save/asm_routines.s")); global_asm!(include_str!("save/asm_routines.s"));
global_asm!(include_str!("display/tiled/tile_copy.s"));