diff --git a/agb-image-converter/src/rust_generator.rs b/agb-image-converter/src/rust_generator.rs index 4d8b4d5c..a382580f 100644 --- a/agb-image-converter/src/rust_generator.rs +++ b/agb-image-converter/src/rust_generator.rs @@ -131,7 +131,7 @@ pub(crate) fn generate_code( pub bytes: Bytes, } - const ALIGNED: &AlignedAs = &AlignedAs { + const ALIGNED: &AlignedAs = &AlignedAs { _align: [], bytes: *#data, }; diff --git a/agb/src/display/tiled/tile_copy.s b/agb/src/display/tiled/tile_copy.s deleted file mode 100644 index 866c0af8..00000000 --- a/agb/src/display/tiled/tile_copy.s +++ /dev/null @@ -1,27 +0,0 @@ -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 \ No newline at end of file diff --git a/agb/src/display/tiled/vram_manager.rs b/agb/src/display/tiled/vram_manager.rs index c2113983..b92e00de 100644 --- a/agb/src/display/tiled/vram_manager.rs +++ b/agb/src/display/tiled/vram_manager.rs @@ -29,9 +29,10 @@ const fn layout_of(format: TileFormat) -> Layout { } #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(C)] pub enum TileFormat { - FourBpp, - EightBpp, + FourBpp = 0, + EightBpp = 1, } impl TileFormat { @@ -376,17 +377,33 @@ impl VRamManager { tile_id: u16, tile_reference: TileReference, ) { - let tile_size = tile_set.format.tile_size(); + let tile_format = tile_set.format; + let tile_size = tile_format.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_data_start = unsafe { tile_set.tiles.as_ptr().add(tile_offset) }; let target_location = tile_reference.0.as_ptr() as *mut _; unsafe { - 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), - } + core::arch::asm!( + "cmp r2, #0", + "beq 1f", + "ldmia r0!, {{r2-r5}}", + "stmia r1!, {{r2-r5}}", + "ldmia r0!, {{r2-r5}}", + "stmia r1!, {{r2-r5}}", + "1:", + "ldmia r0!, {{r2-r5}}", + "stmia r1!, {{r2-r5}}", + "ldmia r0!, {{r2-r5}}", + "stmia r1!, {{r2-r5}}", + inout("r0") tile_data_start => _, + inout("r1") target_location => _, + inout("r2") tile_format as u32 => _, + out("r3") _, + out("r4") _, + out("r5") _, + ); } } @@ -410,8 +427,3 @@ impl VRamManager { } } } - -extern "C" { - fn copy_tile_4bpp(src: *const u32, dest: *mut u32); - fn copy_tile_8bpp(src: *const u32, dest: *mut u32); -} diff --git a/agb/src/global_asm.rs b/agb/src/global_asm.rs index 0af2e00e..b16f19b2 100644 --- a/agb/src/global_asm.rs +++ b/agb/src/global_asm.rs @@ -6,4 +6,3 @@ global_asm!(include_str!("crt0.s")); global_asm!(include_str!("interrupt_handler.s")); global_asm!(include_str!("sound/mixer/mixer.s")); global_asm!(include_str!("save/asm_routines.s")); -global_asm!(include_str!("display/tiled/tile_copy.s"));