pull out where to write

This commit is contained in:
Corwin 2023-04-04 17:34:11 +01:00
parent 875d53c040
commit d183b8373d
No known key found for this signature in database
3 changed files with 5 additions and 8 deletions

View file

@ -14,11 +14,11 @@ pub use unmanaged::{AffineMode, OAMIterator, OAMSlot, UnmanagedOAM, UnmanagedObj
use super::DISPLAY_CONTROL;
const OBJECT_ATTRIBUTE_MEMORY: usize = 0x0700_0000;
const OBJECT_ATTRIBUTE_MEMORY: *mut u16 = 0x0700_0000 as *mut u16;
pub(super) unsafe fn initilise_oam() {
for i in 0..128 {
let ptr = (OBJECT_ATTRIBUTE_MEMORY as *mut u16).add(i * 4);
let ptr = (OBJECT_ATTRIBUTE_MEMORY).add(i * 4);
ptr.write_volatile(0b10 << 8);
}

View file

@ -4,8 +4,6 @@ use alloc::rc::Rc;
use crate::display::affine::AffineMatrixObject;
use super::OBJECT_ATTRIBUTE_MEMORY;
#[derive(Debug)]
struct AffineMatrixData {
frame_count: Cell<u32>,
@ -55,13 +53,12 @@ impl AffineMatrixVram {
self.0.location.set(location);
}
pub fn write_to_location(&self) {
pub fn write_to_location(&self, oam: *mut u16) {
let components = self.0.matrix.components();
let location = self.0.location.get() as usize;
for (idx, component) in components.iter().enumerate() {
unsafe {
(OBJECT_ATTRIBUTE_MEMORY as *mut u16)
.add(location * 16 + idx * 4 + 3)
oam.add(location * 16 + idx * 4 + 3)
.write_volatile(*component);
}
}

View file

@ -51,7 +51,7 @@ impl OAMSlot<'_> {
);
affine_matrix.set_location(frame_data.affine_matrix_count);
frame_data.affine_matrix_count += 1;
affine_matrix.write_to_location();
affine_matrix.write_to_location(OBJECT_ATTRIBUTE_MEMORY);
}
attributes.set_affine_matrix(affine_matrix.location() as u16);