From b5c9cb7b8b208b1dba91fe46624e98fed9192bdb Mon Sep 17 00:00:00 2001 From: Corwin Date: Fri, 29 Sep 2023 00:03:47 +0100 Subject: [PATCH] add unchecked variants --- agb-reg/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/agb-reg/src/lib.rs b/agb-reg/src/lib.rs index a50898258..87873d711 100644 --- a/agb-reg/src/lib.rs +++ b/agb-reg/src/lib.rs @@ -29,18 +29,30 @@ pub const BACKGROUND_CONTROL: *mut [BackgroundControl; 4] = background_control(0 pub const fn background_offset(bg: usize) -> *mut Offset { assert!(bg < 4, "background must be in range 0..=3"); + background_offset_unchecked(bg) +} + +pub const fn background_offset_unchecked(bg: usize) -> *mut Offset { (0x0400_0010 + bg * core::mem::size_of::()) as *mut _ } pub const fn background_offset_horizontal(bg: usize) -> *mut u16 { assert!(bg < 4, "background must be in range 0..=3"); + background_offset_horizontal_unchecked(bg) +} + +pub const fn background_offset_horizontal_unchecked(bg: usize) -> *mut u16 { (0x0400_0010 + bg * core::mem::size_of::()) as *mut u16 } pub const fn background_offset_vertical(bg: usize) -> *mut u16 { assert!(bg < 4, "background must be in range 0..=3"); + background_offset_vertical_unchecked(bg) +} + +pub const fn background_offset_vertical_unchecked(bg: usize) -> *mut u16 { (0x0400_0010 + bg * core::mem::size_of::() + core::mem::size_of::()) as *mut u16 } @@ -60,7 +72,7 @@ pub const BACKGROUND_3_OFFSET: *mut Offset = background_offset(3); pub const BACKGROUND_3_OFFSET_HORIZONTAL: *mut u16 = background_offset_horizontal(3); pub const BACKGROUND_3_OFFSET_VERTICAL: *mut u16 = background_offset_vertical(3); -pub const BACKGROUND_OFFSET: *mut [Offset; 4] = 0x0400_0010 as *mut _; +pub const BACKGROUND_OFFSET: *mut [Offset; 4] = background_offset(0).cast(); #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]