diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index dfde7814..afd81570 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -111,3 +111,10 @@ pub fn busy_wait_for_VBlank() { while VCOUNT.get() >= 160 {} while VCOUNT.get() < 160 {} } + +pub enum Priority { + P0 = 0, + P1 = 1, + P2 = 2, + P3 = 3, +} diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index bad35710..2e1b670d 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -1,6 +1,6 @@ use core::cell::RefCell; -use super::DISPLAY_CONTROL; +use super::{Priority, DISPLAY_CONTROL}; use crate::bitarray::Bitarray; use crate::memory_mapped::MemoryMapped1DArray; use crate::number::Vector2D; @@ -124,6 +124,10 @@ impl ObjectStandard<'_> { self.attributes.set_x(x); self.attributes.set_y(y); } + + pub fn set_priority(&mut self, p: Priority) { + self.attributes.set_priority(p) + } } impl<'a> ObjectAffine<'a> { @@ -176,6 +180,10 @@ impl<'a> ObjectAffine<'a> { self.attributes.set_x(x); self.attributes.set_y(y); } + + pub fn set_priority(&mut self, p: Priority) { + self.attributes.set_priority(p) + } } fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 { @@ -254,6 +262,10 @@ impl ObjectAttribute { fn set_affine(&mut self, aff_id: u8) { self.a1 = set_bits(self.a1, aff_id as u16, 5, 0x9); } + + fn set_priority(&mut self, p: Priority) { + self.a2 = set_bits(self.a2, p as u16, 2, 0x0A); + } } impl AffineMatrix<'_> { diff --git a/agb/src/display/tiled0.rs b/agb/src/display/tiled0.rs index 7cb3da72..79050e49 100644 --- a/agb/src/display/tiled0.rs +++ b/agb/src/display/tiled0.rs @@ -6,7 +6,7 @@ use crate::{ }; use super::{ - palette16, set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, + palette16, set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, Priority, DISPLAY_CONTROL, }; @@ -22,13 +22,6 @@ const TILE_SPRITE: MemoryMapped1DArray = const MAP: *mut [[[u16; 32]; 32]; 32] = 0x0600_0000 as *mut _; -pub enum Prioriry { - P0 = 0, - P1 = 1, - P2 = 2, - P3 = 3, -} - pub enum ColourMode { FourBitPerPixel = 0, EightBitPerPixel = 1, @@ -101,7 +94,7 @@ impl Background { /// Sets priority of the background layer. Backgrounds with higher priority /// are drawn (above/below) backgrounds with lower priority. - pub fn set_priority(&mut self, p: Prioriry) { + pub fn set_priority(&mut self, p: Priority) { unsafe { self.set_bits(0, 2, p as u16) } }