mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Merge pull request #185 from gwilymk/use-dma-in-objects
Use dma in objects
This commit is contained in:
commit
ec8d692029
|
@ -16,6 +16,7 @@ use super::palette16::Palette16;
|
||||||
use super::{Priority, DISPLAY_CONTROL};
|
use super::{Priority, DISPLAY_CONTROL};
|
||||||
use crate::agb_alloc::block_allocator::BlockAllocator;
|
use crate::agb_alloc::block_allocator::BlockAllocator;
|
||||||
use crate::agb_alloc::bump_allocator::StartEnd;
|
use crate::agb_alloc::bump_allocator::StartEnd;
|
||||||
|
use crate::dma;
|
||||||
use crate::fixnum::Vector2D;
|
use crate::fixnum::Vector2D;
|
||||||
|
|
||||||
use attributes::*;
|
use attributes::*;
|
||||||
|
@ -363,7 +364,7 @@ impl ObjectController {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Object<'b, 'a> {
|
pub fn get_object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Object<'b, 'a> {
|
||||||
self.try_get_object(sprite).expect("No object avaliable")
|
self.try_get_object(sprite).expect("No object available")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_get_object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Option<Object<'b, 'a>> {
|
pub fn try_get_object<'a, 'b>(&'a self, sprite: SpriteBorrow<'b>) -> Option<Object<'b, 'a>> {
|
||||||
|
@ -577,8 +578,11 @@ impl SpriteController {
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
dest.as_ptr()
|
dma::dma_copy16(
|
||||||
.copy_from_nonoverlapping(sprite.data.as_ptr(), sprite.data.len())
|
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);
|
||||||
|
@ -610,9 +614,11 @@ impl SpriteControllerInner {
|
||||||
let dest = unsafe { PALETTE_ALLOCATOR.alloc(Palette16::layout())? };
|
let dest = unsafe { PALETTE_ALLOCATOR.alloc(Palette16::layout())? };
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
dest.as_ptr()
|
dma::dma_copy16(
|
||||||
.cast::<u16>()
|
palette.colours.as_ptr().cast(),
|
||||||
.copy_from_nonoverlapping(palette.colours.as_ptr(), palette.colours.len())
|
dest.as_ptr().cast(),
|
||||||
|
palette.colours.len(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let storage = Storage::from_palette_ptr(dest);
|
let storage = Storage::from_palette_ptr(dest);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use core::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use crate::bitarray::Bitarray;
|
use crate::bitarray::Bitarray;
|
||||||
use crate::display::{Priority, DISPLAY_CONTROL};
|
use crate::display::{Priority, DISPLAY_CONTROL};
|
||||||
use crate::dma::dma_copy;
|
use crate::dma::dma_copy16;
|
||||||
use crate::fixnum::Vector2D;
|
use crate::fixnum::Vector2D;
|
||||||
use crate::memory_mapped::MemoryMapped;
|
use crate::memory_mapped::MemoryMapped;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ impl RegularMap {
|
||||||
let screenblock_memory = self.screenblock_memory();
|
let screenblock_memory = self.screenblock_memory();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
dma_copy(
|
dma_copy16(
|
||||||
self.tiles.as_ptr() as *const u16,
|
self.tiles.as_ptr() as *const u16,
|
||||||
screenblock_memory,
|
screenblock_memory,
|
||||||
32 * 32,
|
32 * 32,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use alloc::vec::Vec;
|
||||||
use crate::{
|
use crate::{
|
||||||
agb_alloc::{block_allocator::BlockAllocator, bump_allocator::StartEnd},
|
agb_alloc::{block_allocator::BlockAllocator, bump_allocator::StartEnd},
|
||||||
display::palette16,
|
display::palette16,
|
||||||
dma::dma_copy,
|
dma::dma_copy16,
|
||||||
memory_mapped::MemoryMapped1DArray,
|
memory_mapped::MemoryMapped1DArray,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ impl<'a> VRamManager<'a> {
|
||||||
let tile_size_in_half_words = TileFormat::FourBpp.tile_size() / 2;
|
let tile_size_in_half_words = TileFormat::FourBpp.tile_size() / 2;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
dma_copy(
|
dma_copy16(
|
||||||
tile_slice.as_ptr() as *const u16,
|
tile_slice.as_ptr() as *const u16,
|
||||||
new_reference.as_ptr() as *mut u16,
|
new_reference.as_ptr() as *mut u16,
|
||||||
tile_size_in_half_words,
|
tile_size_in_half_words,
|
||||||
|
@ -260,14 +260,18 @@ impl<'a> VRamManager<'a> {
|
||||||
|
|
||||||
/// Copies raw palettes to the background palette without any checks.
|
/// Copies raw palettes to the background palette without any checks.
|
||||||
pub fn set_background_palette_raw(&mut self, palette: &[u16]) {
|
pub fn set_background_palette_raw(&mut self, palette: &[u16]) {
|
||||||
for (index, &colour) in palette.iter().enumerate() {
|
unsafe {
|
||||||
PALETTE_BACKGROUND.set(index, colour);
|
dma_copy16(palette.as_ptr(), PALETTE_BACKGROUND.as_ptr(), palette.len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_background_palette(&mut self, pal_index: u8, palette: &palette16::Palette16) {
|
fn set_background_palette(&mut self, pal_index: u8, palette: &palette16::Palette16) {
|
||||||
for (colour_index, &colour) in palette.colours.iter().enumerate() {
|
unsafe {
|
||||||
PALETTE_BACKGROUND.set(pal_index as usize * 16 + colour_index, colour);
|
dma_copy16(
|
||||||
|
palette.colours.as_ptr(),
|
||||||
|
PALETTE_BACKGROUND.as_ptr().add(16 * pal_index as usize),
|
||||||
|
palette.colours.len(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ const DMA3_SOURCE_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_sourc
|
||||||
const DMA3_DEST_ADDR: MemoryMapped<u32> = unsafe { MemoryMapped::new(dma_dest_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)) };
|
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) {
|
pub(crate) unsafe fn dma_copy16(src: *const u16, dest: *mut u16, count: usize) {
|
||||||
assert!(count < u16::MAX as usize);
|
assert!(count < u16::MAX as usize);
|
||||||
|
|
||||||
DMA3_SOURCE_ADDR.set(src as u32);
|
DMA3_SOURCE_ADDR.set(src as u32);
|
||||||
|
|
|
@ -57,6 +57,10 @@ impl<T, const N: usize> MemoryMapped1DArray<T, N> {
|
||||||
pub fn set(&self, n: usize, val: T) {
|
pub fn set(&self, n: usize, val: T) {
|
||||||
unsafe { (&mut (*self.array)[n] as *mut T).write_volatile(val) }
|
unsafe { (&mut (*self.array)[n] as *mut T).write_volatile(val) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_ptr(&self) -> *mut T {
|
||||||
|
self.array.cast()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MemoryMapped2DArray<T, const X: usize, const Y: usize> {
|
pub struct MemoryMapped2DArray<T, const X: usize, const Y: usize> {
|
||||||
|
|
Loading…
Reference in a new issue