add priority

This commit is contained in:
Corwin Kuiper 2021-06-12 13:56:29 +01:00
parent 6268c607c3
commit da5ed768de
3 changed files with 22 additions and 10 deletions

View file

@ -111,3 +111,10 @@ pub fn busy_wait_for_VBlank() {
while VCOUNT.get() >= 160 {} while VCOUNT.get() >= 160 {}
while VCOUNT.get() < 160 {} while VCOUNT.get() < 160 {}
} }
pub enum Priority {
P0 = 0,
P1 = 1,
P2 = 2,
P3 = 3,
}

View file

@ -1,6 +1,6 @@
use core::cell::RefCell; use core::cell::RefCell;
use super::DISPLAY_CONTROL; use super::{Priority, DISPLAY_CONTROL};
use crate::bitarray::Bitarray; use crate::bitarray::Bitarray;
use crate::memory_mapped::MemoryMapped1DArray; use crate::memory_mapped::MemoryMapped1DArray;
use crate::number::Vector2D; use crate::number::Vector2D;
@ -124,6 +124,10 @@ impl ObjectStandard<'_> {
self.attributes.set_x(x); self.attributes.set_x(x);
self.attributes.set_y(y); self.attributes.set_y(y);
} }
pub fn set_priority(&mut self, p: Priority) {
self.attributes.set_priority(p)
}
} }
impl<'a> ObjectAffine<'a> { impl<'a> ObjectAffine<'a> {
@ -176,6 +180,10 @@ impl<'a> ObjectAffine<'a> {
self.attributes.set_x(x); self.attributes.set_x(x);
self.attributes.set_y(y); 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 { 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) { fn set_affine(&mut self, aff_id: u8) {
self.a1 = set_bits(self.a1, aff_id as u16, 5, 0x9); 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<'_> { impl AffineMatrix<'_> {

View file

@ -6,7 +6,7 @@ use crate::{
}; };
use super::{ use super::{
palette16, set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, palette16, set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, Priority,
DISPLAY_CONTROL, DISPLAY_CONTROL,
}; };
@ -22,13 +22,6 @@ const TILE_SPRITE: MemoryMapped1DArray<u32, { 512 * 8 }> =
const MAP: *mut [[[u16; 32]; 32]; 32] = 0x0600_0000 as *mut _; 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 { pub enum ColourMode {
FourBitPerPixel = 0, FourBitPerPixel = 0,
EightBitPerPixel = 1, EightBitPerPixel = 1,
@ -101,7 +94,7 @@ impl Background {
/// Sets priority of the background layer. Backgrounds with higher priority /// Sets priority of the background layer. Backgrounds with higher priority
/// are drawn (above/below) backgrounds with lower 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) } unsafe { self.set_bits(0, 2, p as u16) }
} }