align sprite data to 2 byte boundaries

This commit is contained in:
Corwin 2022-07-16 13:36:33 +01:00
parent 2026e49569
commit 1be10ba450
2 changed files with 29 additions and 6 deletions

View file

@ -154,7 +154,7 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream {
quote! { quote! {
Sprite::new( Sprite::new(
&PALETTES[#assignment], &PALETTES[#assignment],
#data, align_bytes!(u16, #data),
Size::from_width_height(#width, #height) Size::from_width_height(#width, #height)
) )
} }

View file

@ -135,11 +135,32 @@ pub enum Size {
S32x64 = 0b10_11, S32x64 = 0b10_11,
} }
#[repr(C)] // guarantee 'bytes' comes after '_align'
pub struct AlignedAs<Align, Bytes: ?Sized> {
pub _align: [Align; 0],
pub bytes: Bytes,
}
#[macro_export]
macro_rules! align_bytes {
($align_ty:ty, $data:literal) => {{
use $crate::display::object::AlignedAs;
const ALIGNED: &AlignedAs<$align_ty, [u8]> = &AlignedAs {
_align: [],
bytes: *$data,
};
&ALIGNED.bytes
}};
}
#[macro_export] #[macro_export]
macro_rules! include_aseprite { macro_rules! include_aseprite {
($($aseprite_path: expr),*) => {{ ($($aseprite_path: expr),*) => {{
use $crate::display::object::{Size, Sprite, Tag, TagMap, Graphics}; use $crate::display::object::{Size, Sprite, Tag, TagMap, Graphics};
use $crate::display::palette16::Palette16; use $crate::display::palette16::Palette16;
use $crate::align_bytes;
$crate::include_aseprite_inner!($($aseprite_path),*); $crate::include_aseprite_inner!($($aseprite_path),*);
@ -778,11 +799,13 @@ impl SpriteControllerInner {
}; };
unsafe { unsafe {
dma::dma_copy16( dest.as_ptr()
sprite.data.as_ptr().cast(), .copy_from_nonoverlapping(sprite.data.as_ptr(), sprite.data.len());
dest.as_ptr().cast(), // dma::dma_copy16(
sprite.data.len() / 2, // sprite.data.as_ptr().cast(),
); // dest.as_ptr().cast(),
// sprite.data.len() / 2,
// );
} }
let storage = Storage::from_sprite_ptr(dest); let storage = Storage::from_sprite_ptr(dest);