From 2b281995705fb9786a6270cb9a44263b15d19cc6 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sun, 30 May 2021 20:07:10 +0100 Subject: [PATCH] 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); +}