mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Remove lifetime from dma transfer handle (#712)
The lifetime here is pointless since we copy the data anyway. And this makes a bunch of stuff not unsafe any more which is really nice. - [x] Changelog updated / no changelog update needed
This commit is contained in:
commit
dc06aabb19
|
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
- Added `find_colour_index_16` and `find_colour_index_256` to the `VRamManager` to find where a colour is in a palette.
|
- Added `find_colour_index_16` and `find_colour_index_256` to the `VRamManager` to find where a colour is in a palette.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `dma.hblank_transfer` is no longer `unsafe`.
|
||||||
|
|
||||||
## [0.20.2] - 2024/05/25
|
## [0.20.2] - 2024/05/25
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -37,12 +37,10 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
.expect("Should contain colour 0x732b");
|
.expect("Should contain colour 0x732b");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _background_color_transfer = unsafe {
|
let _background_color_transfer = dma.hblank_transfer(
|
||||||
dma.hblank_transfer(
|
|
||||||
&vram.background_palette_colour_dma(0, background_colour_index),
|
&vram.background_palette_colour_dma(0, background_colour_index),
|
||||||
&colours,
|
&colours,
|
||||||
)
|
);
|
||||||
};
|
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
let mut frame = 0;
|
let mut frame = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _x_scroll_transfer =
|
let _x_scroll_transfer = dma.hblank_transfer(&map.x_scroll_dma(), &offsets[frame..]);
|
||||||
unsafe { dma.hblank_transfer(&map.x_scroll_dma(), &offsets[frame..]) };
|
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
frame += 1;
|
frame += 1;
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
window.commit();
|
window.commit();
|
||||||
|
|
||||||
let dma_controllable = window.win_in(WinIn::Win0).horizontal_position_dma();
|
let dma_controllable = window.win_in(WinIn::Win0).horizontal_position_dma();
|
||||||
let _transfer = unsafe { dmas.dma0.hblank_transfer(&dma_controllable, &circle_poses) };
|
let _transfer = dmas.dma0.hblank_transfer(&dma_controllable, &circle_poses);
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,18 +70,14 @@ impl Dma {
|
||||||
/// drop the DmaTransferHandler return value until the next vblank interrupt to ensure that you
|
/// drop the DmaTransferHandler return value until the next vblank interrupt to ensure that you
|
||||||
/// a continuous effect.
|
/// a continuous effect.
|
||||||
///
|
///
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// While DmaTransferHandle is not dropped, the slice at `values` must not move in memory.
|
|
||||||
///
|
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// See the `dma_effect_*` examples in the repository to see some ways to use this.
|
/// See the `dma_effect_*` examples in the repository to see some ways to use this.
|
||||||
pub unsafe fn hblank_transfer<'a, T>(
|
pub fn hblank_transfer<T>(
|
||||||
&'a self,
|
&self,
|
||||||
location: &DmaControllable<T>,
|
location: &DmaControllable<T>,
|
||||||
values: &'a [T],
|
values: &[T],
|
||||||
) -> DmaTransferHandle<'a, T>
|
) -> DmaTransferHandle<T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
@ -93,10 +89,13 @@ impl Dma {
|
||||||
|
|
||||||
let n_transfers = (size_of::<T>() / 2) as u32;
|
let n_transfers = (size_of::<T>() / 2) as u32;
|
||||||
|
|
||||||
self.source_addr.set(handle.data.as_ptr().add(1) as u32);
|
self.source_addr.set(handle.data[1..].as_ptr() as u32);
|
||||||
self.dest_addr.set(location.memory_location as u32);
|
self.dest_addr.set(location.memory_location as u32);
|
||||||
|
|
||||||
|
// SAFETY: by construction it is safe to write to location.memory_location
|
||||||
|
unsafe {
|
||||||
location.memory_location.write_volatile(values[0]);
|
location.memory_location.write_volatile(values[0]);
|
||||||
|
}
|
||||||
|
|
||||||
self.ctrl_addr.set(
|
self.ctrl_addr.set(
|
||||||
(0b10 << 0x15) | // keep destination address fixed
|
(0b10 << 0x15) | // keep destination address fixed
|
||||||
|
@ -127,17 +126,15 @@ impl<Item> DmaControllable<Item> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DmaTransferHandle<'a, T>
|
pub struct DmaTransferHandle<T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
number: usize,
|
number: usize,
|
||||||
data: Pin<Box<[T]>>,
|
data: Pin<Box<[T]>>,
|
||||||
|
|
||||||
phantom: PhantomData<&'a ()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> DmaTransferHandle<'a, T>
|
impl<T> DmaTransferHandle<T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
@ -145,12 +142,11 @@ where
|
||||||
Self {
|
Self {
|
||||||
number,
|
number,
|
||||||
data: Box::into_pin(data.into()),
|
data: Box::into_pin(data.into()),
|
||||||
phantom: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> Drop for DmaTransferHandle<'a, T>
|
impl<T> Drop for DmaTransferHandle<T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue