From 300aafd665c1c830b1aa51a6d4cfc12233235b5a Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 29 May 2021 12:24:04 +0100 Subject: [PATCH 01/19] add show / hide implementations --- agb/src/display/object.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 2ae631c1..990a105b 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -37,6 +37,12 @@ impl ObjectStandard { pub fn set_hflip(&mut self, hflip: bool) { self.attributes.set_hflip(hflip) } + pub fn show(&mut self) { + self.attributes.set_mode(Mode::Normal) + } + pub fn hide(&mut self) { + self.attributes.set_mode(Mode::Hidden) + } } pub struct ObjectAttributeStandard { From 06210591e919d668cc88ef07a702777ccf3c47ae Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 29 May 2021 15:20:54 +0100 Subject: [PATCH 02/19] object attribute for all object modes --- agb/src/display/object.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 990a105b..414ad2e0 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -9,7 +9,7 @@ pub struct ObjectControl {} #[non_exhaustive] pub struct ObjectStandard { - attributes: ObjectAttributeStandard, + attributes: ObjectAttribute, id: usize, } @@ -45,12 +45,12 @@ impl ObjectStandard { } } -pub struct ObjectAttributeStandard { +pub struct ObjectAttribute { low: u32, high: u32, } -impl ObjectAttributeStandard { +impl ObjectAttribute { unsafe fn commit(&self, index: usize) { OBJECT_MEMORY_STANDARD.set(index * 2, self.low); OBJECT_MEMORY_STANDARD.set(index * 2 + 1, self.high); @@ -98,9 +98,9 @@ impl ObjectAttributeStandard { } } -impl ObjectAttributeStandard { +impl ObjectAttribute { fn new() -> Self { - ObjectAttributeStandard { low: 0, high: 0 } + ObjectAttribute { low: 0, high: 0 } } } @@ -112,7 +112,7 @@ impl ObjectControl { /// # Safety /// Temporary, do not call if you currently hold an object pub unsafe fn clear_objects(&mut self) { - let mut o = ObjectAttributeStandard::new(); + let mut o = ObjectAttribute::new(); o.set_mode(Mode::Hidden); for index in 0..128 { o.commit(index); @@ -136,7 +136,7 @@ impl ObjectControl { pub unsafe fn get_object(&self, id: usize) -> ObjectStandard { assert!(id < 128, "object id must be less than 128"); ObjectStandard { - attributes: ObjectAttributeStandard::new(), + attributes: ObjectAttribute::new(), id, } } From f3c89cea9c02eb1dc27770df2d36267a985b8b13 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 12:29:34 +0100 Subject: [PATCH 03/19] correct spelling --- agb/src/display/object.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 414ad2e0..055cab21 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -15,9 +15,9 @@ pub struct ObjectStandard { pub enum Mode { Normal = 0, - Affline = 1, + Affine = 1, Hidden = 2, - AfflineDouble = 3, + AffineDouble = 3, } impl ObjectStandard { From 2c14a8454a8edc52aae128854af5762c5b9756e8 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 12:29:51 +0100 Subject: [PATCH 04/19] remove unneeded non_exhaustive --- agb/src/display/object.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 055cab21..5c717138 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -7,7 +7,6 @@ const OBJECT_MEMORY_STANDARD: MemoryMapped1DArray = #[non_exhaustive] pub struct ObjectControl {} -#[non_exhaustive] pub struct ObjectStandard { attributes: ObjectAttribute, id: usize, From c3b81a45850440294268e6d36347e6723b9dedd6 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 12:47:00 +0100 Subject: [PATCH 05/19] don't touch highest 16 bits --- agb/src/display/object.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 5c717138..d7883191 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -52,7 +52,10 @@ pub struct ObjectAttribute { impl ObjectAttribute { unsafe fn commit(&self, index: usize) { OBJECT_MEMORY_STANDARD.set(index * 2, self.low); - OBJECT_MEMORY_STANDARD.set(index * 2 + 1, self.high); + // preserve top set of bits + let high_bits = OBJECT_MEMORY_STANDARD.get(index * 2 + 1); + let new_high_bits = (high_bits & !((1 << 16) - 1)) | self.high; + OBJECT_MEMORY_STANDARD.set(index * 2 + 1, new_high_bits); } pub fn set_hflip(&mut self, hflip: bool) { From 7aa213936ee2ed8bdf60732bfacc6667637c7cbb Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 16:58:34 +0100 Subject: [PATCH 06/19] object attributes in terms of three separate parameters --- agb/src/display/object.rs | 76 +++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index d7883191..a7f1ccab 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -1,15 +1,17 @@ use super::DISPLAY_CONTROL; use crate::memory_mapped::MemoryMapped1DArray; -const OBJECT_MEMORY_STANDARD: MemoryMapped1DArray = +const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray = unsafe { MemoryMapped1DArray::new(0x0700_0000) }; #[non_exhaustive] -pub struct ObjectControl {} +pub struct ObjectControl { + object_count: u8, +} pub struct ObjectStandard { attributes: ObjectAttribute, - id: usize, + id: u8, } pub enum Mode { @@ -30,7 +32,7 @@ impl ObjectStandard { pub fn set_y(&mut self, y: u8) { self.attributes.set_y(y) } - pub fn set_tile_id(&mut self, id: u32) { + pub fn set_tile_id(&mut self, id: u16) { self.attributes.set_tile_id(id) } pub fn set_hflip(&mut self, hflip: bool) { @@ -45,80 +47,78 @@ impl ObjectStandard { } pub struct ObjectAttribute { - low: u32, - high: u32, + a0: u16, + a1: u16, + a2: u16, } impl ObjectAttribute { - unsafe fn commit(&self, index: usize) { - OBJECT_MEMORY_STANDARD.set(index * 2, self.low); - // preserve top set of bits - let high_bits = OBJECT_MEMORY_STANDARD.get(index * 2 + 1); - let new_high_bits = (high_bits & !((1 << 16) - 1)) | self.high; - OBJECT_MEMORY_STANDARD.set(index * 2 + 1, new_high_bits); + unsafe fn commit(&self, index: u8) { + OBJECT_ATTRIBUTE_MEMORY.set(index as usize * 4, self.a0); + OBJECT_ATTRIBUTE_MEMORY.set(index as usize * 4 + 1, self.a1); + OBJECT_ATTRIBUTE_MEMORY.set(index as usize * 4 + 2, self.a2); } pub fn set_hflip(&mut self, hflip: bool) { - let mask = (1 << 0xC) << 16; - let attr = self.low; + let mask = 1 << 0xC; + let attr = self.a1; let attr = attr & !mask; if hflip { - self.low = attr | mask + self.a1 = attr | mask } else { - self.low = attr + self.a1 = attr } } pub fn set_x(&mut self, x: u8) { - let mask = ((1 << 8) - 1) << 16; - let attr1 = self.low; + let mask = (1 << 8) - 1; + let attr1 = self.a1; let attr_without_x = attr1 & !mask; - let attr_with_new_x = attr_without_x | ((x as u32) << 16); - self.low = attr_with_new_x; + let attr_with_new_x = attr_without_x | x as u16; + self.a1 = attr_with_new_x; } pub fn set_y(&mut self, y: u8) { let mask = (1 << 8) - 1; - let attr0 = self.low; + let attr0 = self.a0; let attr_without_y = attr0 & !mask; - let attr_with_new_y = attr_without_y | y as u32; - self.low = attr_with_new_y; + let attr_with_new_y = attr_without_y | y as u16; + self.a0 = attr_with_new_y; } - pub fn set_tile_id(&mut self, id: u32) { + pub fn set_tile_id(&mut self, id: u16) { let mask = (1 << 9) - 1; assert!(id <= mask, "tile id is greater than 9 bits"); - let attr = self.high; + let attr = self.a2; let attr = attr & !mask; let attr = attr | id; - self.high = attr; + self.a2 = attr; } pub fn set_mode(&mut self, mode: Mode) { let mask = 0b11 << 0x8; - self.low = (self.low & !mask) | ((mode as u32) << 0x8); + self.a0 = (self.a0 & !mask) | ((mode as u16) << 0x8); } } impl ObjectAttribute { fn new() -> Self { - ObjectAttribute { low: 0, high: 0 } + ObjectAttribute { + a0: 0, + a1: 0, + a2: 0, + } } } impl ObjectControl { pub(crate) fn new() -> Self { - ObjectControl {} - } - - /// # Safety - /// Temporary, do not call if you currently hold an object - pub unsafe fn clear_objects(&mut self) { let mut o = ObjectAttribute::new(); o.set_mode(Mode::Hidden); for index in 0..128 { - o.commit(index); + unsafe { o.commit(index) }; } + ObjectControl { object_count: 0 } } pub fn enable(&mut self) { @@ -133,9 +133,9 @@ impl ObjectControl { DISPLAY_CONTROL.set(disp); } - /// # Safety - /// Temporary function, you must not get multiple objects with the same id - pub unsafe fn get_object(&self, id: usize) -> ObjectStandard { + pub fn get_object(&mut self) -> ObjectStandard { + let id = self.object_count; + self.object_count += 1; assert!(id < 128, "object id must be less than 128"); ObjectStandard { attributes: ObjectAttribute::new(), From 353fa238763f0452b981731d2371e4f935560495 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 16:58:47 +0100 Subject: [PATCH 07/19] update chicken example to match --- agb/examples/chicken.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/agb/examples/chicken.rs b/agb/examples/chicken.rs index b7129f89..c74a24e4 100644 --- a/agb/examples/chicken.rs +++ b/agb/examples/chicken.rs @@ -31,8 +31,8 @@ fn tile_is_collidable(tile: u16) -> bool { masked == 0 || masked == 4 } -fn frame_ranger(count: u32, start: u32, end: u32, delay: u32) -> u32 { - ((count / delay) % (end + 1 - start)) + start +fn frame_ranger(count: u32, start: u32, end: u32, delay: u32) -> u16 { + (((count / delay) % (end + 1 - start)) + start) as u16 } #[no_mangle] @@ -61,9 +61,8 @@ pub fn main() -> ! { let mut object = gfx.object; object.enable(); - unsafe { object.clear_objects() }; let mut chicken = Character { - object: unsafe { object.get_object(0) }, + object: object.get_object(), position: Vector2D { x: (6 * 8) << 8, y: ((7 * 8) - 4) << 8, From 5cdcfcc0b3eb9a94a04eadeba1262a8475a7c06a Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 17:00:01 +0100 Subject: [PATCH 08/19] add set bits function --- agb/src/display/object.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index a7f1ccab..49f217e0 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -46,6 +46,11 @@ impl ObjectStandard { } } +fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 { + let mask: u16 = (1 << length) - 1; + (current & !(mask << shift)) | ((value & mask) << shift) +} + pub struct ObjectAttribute { a0: u16, a1: u16, From bade37f363947fc672c539b93b0a198542bb7add Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 17:04:30 +0100 Subject: [PATCH 09/19] redo object in terms of set_bits --- agb/src/display/object.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 49f217e0..3bda6b09 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -65,44 +65,23 @@ impl ObjectAttribute { } pub fn set_hflip(&mut self, hflip: bool) { - let mask = 1 << 0xC; - let attr = self.a1; - let attr = attr & !mask; - if hflip { - self.a1 = attr | mask - } else { - self.a1 = attr - } + self.a1 = set_bits(self.a1, hflip as u16, 1, 0xC); } pub fn set_x(&mut self, x: u8) { - let mask = (1 << 8) - 1; - let attr1 = self.a1; - let attr_without_x = attr1 & !mask; - let attr_with_new_x = attr_without_x | x as u16; - self.a1 = attr_with_new_x; + self.a1 = set_bits(self.a1, x as u16, 8, 0); } pub fn set_y(&mut self, y: u8) { - let mask = (1 << 8) - 1; - let attr0 = self.a0; - let attr_without_y = attr0 & !mask; - let attr_with_new_y = attr_without_y | y as u16; - self.a0 = attr_with_new_y; + self.a0 = set_bits(self.a0, y as u16, 8, 0) } pub fn set_tile_id(&mut self, id: u16) { - let mask = (1 << 9) - 1; - assert!(id <= mask, "tile id is greater than 9 bits"); - let attr = self.a2; - let attr = attr & !mask; - let attr = attr | id; - self.a2 = attr; + self.a2 = set_bits(self.a2, id, 9, 0); } pub fn set_mode(&mut self, mode: Mode) { - let mask = 0b11 << 0x8; - self.a0 = (self.a0 & !mask) | ((mode as u16) << 0x8); + self.a0 = set_bits(self.a0, mode as u16, 2, 8); } } From 0202c51c7767bc3bc9bb3031c6b6cefa87dd5106 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:26:04 +0100 Subject: [PATCH 10/19] 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 3bda6b09..e3475863 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 { From 02de6af625f91bc6be39535995f88708f1f0c88f Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:28:00 +0100 Subject: [PATCH 11/19] set affine to affine object --- agb/src/display/object.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index e3475863..cc4f8ef8 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -88,6 +88,9 @@ impl ObjectAffine { pub fn hide(&mut self) { self.attributes.set_mode(Mode::Hidden) } + pub fn set_affine_mat(&mut self, aff: &AffineMatrix) { + self.attributes.set_affine(aff.id); + } } fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 { From dc4bead590b8b7337bd4639b7a15056b11961eb4 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:53:36 +0100 Subject: [PATCH 12/19] write affine to oam --- agb/src/display/object.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index cc4f8ef8..0d5cf9bf 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -136,6 +136,17 @@ impl ObjectAttribute { } } +impl AffineMatrix { + #[allow(clippy::identity_op)] + pub fn commit(&self) { + let id = self.id as usize; + OBJECT_ATTRIBUTE_MEMORY.set((id + 0) * 4 + 3, self.attributes.p_a as u16); + OBJECT_ATTRIBUTE_MEMORY.set((id + 1) * 4 + 3, self.attributes.p_b as u16); + OBJECT_ATTRIBUTE_MEMORY.set((id + 2) * 4 + 3, self.attributes.p_c as u16); + OBJECT_ATTRIBUTE_MEMORY.set((id + 3) * 4 + 3, self.attributes.p_d as u16); + } +} + impl ObjectAttribute { fn new() -> Self { ObjectAttribute { From fbfdd360db3b97904528ca666c268d6c7990879b Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:53:55 +0100 Subject: [PATCH 13/19] remember to add affine id to self --- agb/src/display/object.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 0d5cf9bf..3d9de10e 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -90,6 +90,7 @@ impl ObjectAffine { } pub fn set_affine_mat(&mut self, aff: &AffineMatrix) { self.attributes.set_affine(aff.id); + self.aff_id = Some(aff.id); } } From 4e10e231a7eb02a591855b008bf5ae65bc3aa29d Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:55:02 +0100 Subject: [PATCH 14/19] expose attributes publically --- agb/src/display/object.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 3d9de10e..1a617be1 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -21,15 +21,15 @@ pub struct ObjectAffine { } pub struct AffineMatrix { - attributes: AffineMatrixAttributes, + pub attributes: AffineMatrixAttributes, id: u8, } pub struct AffineMatrixAttributes { - p_a: i16, - p_b: i16, - p_c: i16, - p_d: i16, + pub p_a: i16, + pub p_b: i16, + pub p_c: i16, + pub p_d: i16, } pub enum Mode { From 4a74d885308d3727c56e7b52072b65e18d5e1cf4 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:57:07 +0100 Subject: [PATCH 15/19] affine is gettable --- agb/src/display/object.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 1a617be1..f13bc4f4 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -7,6 +7,7 @@ const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray = #[non_exhaustive] pub struct ObjectControl { object_count: u8, + affine_count: u8, } pub struct ObjectStandard { @@ -165,7 +166,10 @@ impl ObjectControl { for index in 0..128 { unsafe { o.commit(index) }; } - ObjectControl { object_count: 0 } + ObjectControl { + object_count: 0, + affine_count: 0, + } } pub fn enable(&mut self) { @@ -189,4 +193,19 @@ impl ObjectControl { id, } } + + pub fn get_affine(&mut self) -> AffineMatrix { + let id = self.affine_count; + self.affine_count += 1; + assert!(id < 32, "affine id must be less than 32"); + AffineMatrix { + attributes: AffineMatrixAttributes { + p_a: 0, + p_b: 0, + p_c: 0, + p_d: 0, + }, + id, + } + } } From eb596decfcf47b202d5d35533a1dbf28ff4aeea3 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:57:43 +0100 Subject: [PATCH 16/19] affine object is gettable --- agb/src/display/object.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index f13bc4f4..0ab50abe 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -184,7 +184,7 @@ impl ObjectControl { DISPLAY_CONTROL.set(disp); } - pub fn get_object(&mut self) -> ObjectStandard { + pub fn get_object_standard(&mut self) -> ObjectStandard { let id = self.object_count; self.object_count += 1; assert!(id < 128, "object id must be less than 128"); @@ -194,6 +194,17 @@ impl ObjectControl { } } + pub fn get_object_affine(&mut self) -> ObjectAffine { + let id = self.object_count; + self.object_count += 1; + assert!(id < 128, "object id must be less than 128"); + ObjectAffine { + attributes: ObjectAttribute::new(), + id, + aff_id: None, + } + } + pub fn get_affine(&mut self) -> AffineMatrix { let id = self.affine_count; self.affine_count += 1; From 100b69a4f347bc21a59283c8e0def8505ac25780 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 19:58:02 +0100 Subject: [PATCH 17/19] fix chicken with name change --- agb/examples/chicken.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agb/examples/chicken.rs b/agb/examples/chicken.rs index c74a24e4..8fb68d55 100644 --- a/agb/examples/chicken.rs +++ b/agb/examples/chicken.rs @@ -62,7 +62,7 @@ pub fn main() -> ! { object.enable(); let mut chicken = Character { - object: object.get_object(), + object: object.get_object_standard(), position: Vector2D { x: (6 * 8) << 8, y: ((7 * 8) - 4) << 8, From 2b281995705fb9786a6270cb9a44263b15d19cc6 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 20:07:10 +0100 Subject: [PATCH 18/19] affine matrix calculation --- agb/src/syscall.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index fa5d4e2e..9bf5dc5c 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -1,3 +1,5 @@ +use crate::{display::object::AffineMatrixAttributes, Gba}; + #[allow(non_snake_case)] pub fn halt() { @@ -102,3 +104,43 @@ pub fn arc_tan2(x: i16, y: i32) -> i16 { } result } + +pub fn affine_matrix(x_scale: i16, y_scale: i16, rotation: u16) -> AffineMatrixAttributes { + let mut result = AffineMatrixAttributes { + p_a: 0, + p_b: 0, + p_c: 0, + p_d: 0, + }; + + struct Input { + x_scale: i16, + y_scale: i16, + rotation: u16, + } + + let input = Input { + x_scale, + y_scale, + rotation, + }; + + unsafe { + asm!("swi 0x0F", + in("r0") &input as *const Input as usize, + in("r1") &mut result as *mut AffineMatrixAttributes as usize, + in("r2") 1, + in("r3") 2, + ) + } + + result +} + +#[test_case] +fn affine(_gba: &mut Gba) { + // expect identity matrix + let aff = affine_matrix(1 << 8, 1 << 8, 0); + assert_eq!(aff.p_a, 1 << 8); + assert_eq!(aff.p_d, 1 << 8); +} From a98a0d0362c59a847c6e07925a926263f62d3ebc Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 20:08:25 +0100 Subject: [PATCH 19/19] fix warnings --- agb/src/syscall.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index 9bf5dc5c..7797ac3d 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -1,4 +1,4 @@ -use crate::{display::object::AffineMatrixAttributes, Gba}; +use crate::display::object::AffineMatrixAttributes; #[allow(non_snake_case)] @@ -113,6 +113,7 @@ pub fn affine_matrix(x_scale: i16, y_scale: i16, rotation: u16) -> AffineMatrixA p_d: 0, }; + #[allow(dead_code)] struct Input { x_scale: i16, y_scale: i16, @@ -138,7 +139,7 @@ pub fn affine_matrix(x_scale: i16, y_scale: i16, rotation: u16) -> AffineMatrixA } #[test_case] -fn affine(_gba: &mut Gba) { +fn affine(_gba: &mut crate::Gba) { // expect identity matrix let aff = affine_matrix(1 << 8, 1 << 8, 0); assert_eq!(aff.p_a, 1 << 8);