From e7edaa1a27869dce8b4ccd84bb61c5ba1f7e3763 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 20:25:47 +0100 Subject: [PATCH 1/3] Accept more sensible arguments in affine_matrix --- agb/src/syscall.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index 7797ac3d..a5cc1ed2 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -1,4 +1,5 @@ use crate::display::object::AffineMatrixAttributes; +use crate::number::Num; #[allow(non_snake_case)] @@ -105,7 +106,7 @@ pub fn arc_tan2(x: i16, y: i32) -> i16 { result } -pub fn affine_matrix(x_scale: i16, y_scale: i16, rotation: u16) -> AffineMatrixAttributes { +pub fn affine_matrix(x_scale: Num<8>, y_scale: Num<8>, rotation: u8) -> AffineMatrixAttributes { let mut result = AffineMatrixAttributes { p_a: 0, p_b: 0, @@ -120,10 +121,12 @@ pub fn affine_matrix(x_scale: i16, y_scale: i16, rotation: u16) -> AffineMatrixA rotation: u16, } + let rotation_for_input = (rotation as u16) << 8; + let input = Input { - x_scale, - y_scale, - rotation, + y_scale: x_scale.to_raw() as i16, + x_scale: y_scale.to_raw() as i16, + rotation: rotation_for_input, }; unsafe { From 6ab644cf7176eba5585d41fcbc585e74f0f00ca7 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 20:29:16 +0100 Subject: [PATCH 2/3] Mark affine matrix input as C and packed --- agb/src/syscall.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index a5cc1ed2..0129daf0 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -115,6 +115,7 @@ pub fn affine_matrix(x_scale: Num<8>, y_scale: Num<8>, rotation: u8) -> AffineMa }; #[allow(dead_code)] + #[repr(C, packed)] struct Input { x_scale: i16, y_scale: i16, From 46562e275c485eda962dd4a59513a35c4c537d02 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 20:31:04 +0100 Subject: [PATCH 3/3] Update test for new interface --- agb/src/syscall.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index 0129daf0..b30cb6a4 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -145,7 +145,9 @@ pub fn affine_matrix(x_scale: Num<8>, y_scale: Num<8>, rotation: u8) -> AffineMa #[test_case] 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); - assert_eq!(aff.p_d, 1 << 8); + let one: Num<8> = 1.into(); + + let aff = affine_matrix(one, one, 0); + assert_eq!(aff.p_a, one.to_raw() as i16); + assert_eq!(aff.p_d, one.to_raw() as i16); }