From 7431086b14781c82040059e78372c385ec74ce4e Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Thu, 31 Aug 2023 07:53:08 +0100 Subject: [PATCH] Try using memcpy4 for copying the tile data --- agb/src/agbabi/mod.rs | 8 ++++++++ agb/src/display/tiled/vram_manager.rs | 12 ++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/agb/src/agbabi/mod.rs b/agb/src/agbabi/mod.rs index a53823cf..1f3df5a1 100644 --- a/agb/src/agbabi/mod.rs +++ b/agb/src/agbabi/mod.rs @@ -4,6 +4,14 @@ global_asm!(include_str!("macros.inc")); global_asm!(include_str!("memcpy.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)] mod test { mod memset { diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index 3d8c04aa..8ef68717 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -4,6 +4,7 @@ use alloc::{slice, vec::Vec}; use crate::{ agb_alloc::{block_allocator::BlockAllocator, bump_allocator::StartEnd}, + agbabi, display::palette16, dma::dma_copy16, hash_map::{Entry, HashMap}, @@ -380,17 +381,12 @@ impl VRamManager { let tile_offset = (tile_id as usize) * tile_size; let tile_slice = &tile_set.tiles[tile_offset..(tile_offset + tile_size)]; - let tile_size_in_half_words = tile_slice.len() / 2; - + let tile_size = tile_slice.len(); let target_location = tile_reference.0.as_ptr() as *mut _; unsafe { - dma_copy16( - tile_slice.as_ptr() as *const u16, - target_location, - tile_size_in_half_words, - ); - }; + agbabi::memcpy(target_location, tile_slice.as_ptr() as *const _, tile_size); + } } /// Copies raw palettes to the background palette without any checks.