mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Revert "Remove lifetime from dma transfer handle"
This commit is contained in:
parent
dc06aabb19
commit
21658b9b15
|
@ -11,10 +11,6 @@ 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,10 +37,12 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
.expect("Should contain colour 0x732b");
|
.expect("Should contain colour 0x732b");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _background_color_transfer = dma.hblank_transfer(
|
let _background_color_transfer = unsafe {
|
||||||
&vram.background_palette_colour_dma(0, background_colour_index),
|
dma.hblank_transfer(
|
||||||
&colours,
|
&vram.background_palette_colour_dma(0, background_colour_index),
|
||||||
);
|
&colours,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
let mut frame = 0;
|
let mut frame = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _x_scroll_transfer = dma.hblank_transfer(&map.x_scroll_dma(), &offsets[frame..]);
|
let _x_scroll_transfer =
|
||||||
|
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 = dmas.dma0.hblank_transfer(&dma_controllable, &circle_poses);
|
let _transfer = unsafe { dmas.dma0.hblank_transfer(&dma_controllable, &circle_poses) };
|
||||||
|
|
||||||
vblank.wait_for_vblank();
|
vblank.wait_for_vblank();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,14 +70,18 @@ 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 fn hblank_transfer<T>(
|
pub unsafe fn hblank_transfer<'a, T>(
|
||||||
&self,
|
&'a self,
|
||||||
location: &DmaControllable<T>,
|
location: &DmaControllable<T>,
|
||||||
values: &[T],
|
values: &'a [T],
|
||||||
) -> DmaTransferHandle<T>
|
) -> DmaTransferHandle<'a, T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
@ -89,13 +93,10 @@ 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[1..].as_ptr() as u32);
|
self.source_addr.set(handle.data.as_ptr().add(1) 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
|
location.memory_location.write_volatile(values[0]);
|
||||||
unsafe {
|
|
||||||
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
|
||||||
|
@ -126,15 +127,17 @@ impl<Item> DmaControllable<Item> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DmaTransferHandle<T>
|
pub struct DmaTransferHandle<'a, T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
number: usize,
|
number: usize,
|
||||||
data: Pin<Box<[T]>>,
|
data: Pin<Box<[T]>>,
|
||||||
|
|
||||||
|
phantom: PhantomData<&'a ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> DmaTransferHandle<T>
|
impl<'a, T> DmaTransferHandle<'a, T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
@ -142,11 +145,12 @@ where
|
||||||
Self {
|
Self {
|
||||||
number,
|
number,
|
||||||
data: Box::into_pin(data.into()),
|
data: Box::into_pin(data.into()),
|
||||||
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Drop for DmaTransferHandle<T>
|
impl<'a, T> Drop for DmaTransferHandle<'a, T>
|
||||||
where
|
where
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue