From 0202c51c7767bc3bc9bb3031c6b6cefa87dd5106 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:26:04 +0100 Subject: [PATCH] add affine object --- agb/src/display/object.rs | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 3bda6b0..e347586 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -14,6 +14,24 @@ pub struct ObjectStandard { id: u8, } +pub struct ObjectAffine { + attributes: ObjectAttribute, + id: u8, + aff_id: Option, +} + +pub struct AffineMatrix { + attributes: AffineMatrixAttributes, + id: u8, +} + +pub struct AffineMatrixAttributes { + p_a: i16, + p_b: i16, + p_c: i16, + p_d: i16, +} + pub enum Mode { Normal = 0, Affine = 1, @@ -46,6 +64,32 @@ impl ObjectStandard { } } +impl ObjectAffine { + pub fn commit(&self) { + unsafe { self.attributes.commit(self.id) } + } + + pub fn set_x(&mut self, x: u8) { + self.attributes.set_x(x) + } + pub fn set_y(&mut self, y: u8) { + self.attributes.set_y(y) + } + pub fn set_tile_id(&mut self, id: u16) { + self.attributes.set_tile_id(id) + } + + pub fn show(&mut self) { + if self.aff_id.is_none() { + panic!("affine matrix should be set") + } + self.attributes.set_mode(Mode::Affine) + } + pub fn hide(&mut self) { + self.attributes.set_mode(Mode::Hidden) + } +} + fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 { let mask: u16 = (1 << length) - 1; (current & !(mask << shift)) | ((value & mask) << shift) @@ -83,6 +127,10 @@ impl ObjectAttribute { pub fn set_mode(&mut self, mode: Mode) { self.a0 = set_bits(self.a0, mode as u16, 2, 8); } + + pub fn set_affine(&mut self, aff_id: u8) { + self.a1 = set_bits(self.a1, aff_id as u16, 5, 8); + } } impl ObjectAttribute {