mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-25 08:36:40 +11:00
mark creating memory mapped as unsafe
This commit is contained in:
parent
5935f2a8c6
commit
0613849da9
5 changed files with 20 additions and 24 deletions
|
@ -5,26 +5,28 @@ use crate::{
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
|
|
||||||
const DISPLAY_CONTROL: MemoryMapped<u16> = MemoryMapped::new(0x0400_0000);
|
const DISPLAY_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0000) };
|
||||||
const DISPLAY_STATUS: MemoryMapped<u16> = MemoryMapped::new(0x0400_0004);
|
const DISPLAY_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0004) };
|
||||||
const VCOUNT: MemoryMapped<u16> = MemoryMapped::new(0x0400_0006);
|
const VCOUNT: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0006) };
|
||||||
|
|
||||||
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> = MemoryMapped1DArray::new(0x0500_0000);
|
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> =
|
||||||
const PALETTE_SPRITE: MemoryMapped1DArray<u16, 256> = MemoryMapped1DArray::new(0x0500_0200);
|
unsafe { MemoryMapped1DArray::new(0x0500_0000) };
|
||||||
|
const PALETTE_SPRITE: MemoryMapped1DArray<u16, 256> =
|
||||||
|
unsafe { MemoryMapped1DArray::new(0x0500_0200) };
|
||||||
|
|
||||||
const BITMAP_MODE_3: MemoryMapped2DArray<u16, { WIDTH as usize }, { HEIGHT as usize }> =
|
const BITMAP_MODE_3: MemoryMapped2DArray<u16, { WIDTH as usize }, { HEIGHT as usize }> =
|
||||||
MemoryMapped2DArray::new(0x600_0000);
|
unsafe { MemoryMapped2DArray::new(0x600_0000) };
|
||||||
|
|
||||||
const BITMAP_PAGE_FRONT_MODE_4: MemoryMapped2DArray<
|
const BITMAP_PAGE_FRONT_MODE_4: MemoryMapped2DArray<
|
||||||
u16,
|
u16,
|
||||||
{ (WIDTH / 2) as usize },
|
{ (WIDTH / 2) as usize },
|
||||||
{ HEIGHT as usize },
|
{ HEIGHT as usize },
|
||||||
> = MemoryMapped2DArray::new(0x600_0000);
|
> = unsafe { MemoryMapped2DArray::new(0x600_0000) };
|
||||||
const BITMAP_PAGE_BACK_MODE_4: MemoryMapped2DArray<
|
const BITMAP_PAGE_BACK_MODE_4: MemoryMapped2DArray<
|
||||||
u16,
|
u16,
|
||||||
{ (WIDTH / 2) as usize },
|
{ (WIDTH / 2) as usize },
|
||||||
{ HEIGHT as usize },
|
{ HEIGHT as usize },
|
||||||
> = MemoryMapped2DArray::new(0x600_A000);
|
> = unsafe { MemoryMapped2DArray::new(0x600_A000) };
|
||||||
|
|
||||||
pub const WIDTH: i32 = 240;
|
pub const WIDTH: i32 = 240;
|
||||||
pub const HEIGHT: i32 = 160;
|
pub const HEIGHT: i32 = 160;
|
||||||
|
@ -64,14 +66,8 @@ pub struct Display {
|
||||||
in_mode: Single,
|
in_mode: Single,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Display {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display {
|
impl Display {
|
||||||
pub(crate) const fn new() -> Self {
|
pub(crate) const unsafe fn new() -> Self {
|
||||||
Display {
|
Display {
|
||||||
in_mode: Single::new(),
|
in_mode: Single::new(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ pub enum Interrupt {
|
||||||
Gamepak,
|
Gamepak,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENABLED_INTERRUPTS: MemoryMapped<u16> = MemoryMapped::new(0x04000200);
|
const ENABLED_INTERRUPTS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000200) };
|
||||||
const INTERRUPTS_ENABLED: MemoryMapped<u16> = MemoryMapped::new(0x04000208);
|
const INTERRUPTS_ENABLED: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000208) };
|
||||||
|
|
||||||
pub fn enable(interrupt: Interrupt) {
|
pub fn enable(interrupt: Interrupt) {
|
||||||
let _interrupt_token = temporary_interrupt_disable();
|
let _interrupt_token = temporary_interrupt_disable();
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut GBASINGLE: single::Singleton<Gba> = single::Singleton::new(Gba::single_new());
|
static mut GBASINGLE: single::Singleton<Gba> = single::Singleton::new(unsafe { Gba::single_new() });
|
||||||
|
|
||||||
pub struct Gba {
|
pub struct Gba {
|
||||||
pub display: display::Display,
|
pub display: display::Display,
|
||||||
|
@ -35,7 +35,7 @@ impl Gba {
|
||||||
unsafe { GBASINGLE.take() }
|
unsafe { GBASINGLE.take() }
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn single_new() -> Self {
|
const unsafe fn single_new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
display: display::Display::new(),
|
display: display::Display::new(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ pub struct MemoryMapped<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> MemoryMapped<T> {
|
impl<T> MemoryMapped<T> {
|
||||||
pub const fn new(address: usize) -> Self {
|
pub const unsafe fn new(address: usize) -> Self {
|
||||||
MemoryMapped {
|
MemoryMapped {
|
||||||
address: address as *mut T,
|
address: address as *mut T,
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ pub struct MemoryMapped1DArray<T, const N: usize> {
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl<T, const N: usize> MemoryMapped1DArray<T, N> {
|
impl<T, const N: usize> MemoryMapped1DArray<T, N> {
|
||||||
pub const fn new(address: usize) -> Self {
|
pub const unsafe fn new(address: usize) -> Self {
|
||||||
MemoryMapped1DArray {
|
MemoryMapped1DArray {
|
||||||
array: address as *mut [T; N],
|
array: address as *mut [T; N],
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ pub struct MemoryMapped2DArray<T, const X: usize, const Y: usize> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, const X: usize, const Y: usize> MemoryMapped2DArray<T, X, Y> {
|
impl<T, const X: usize, const Y: usize> MemoryMapped2DArray<T, X, Y> {
|
||||||
pub const fn new(address: usize) -> Self {
|
pub const unsafe fn new(address: usize) -> Self {
|
||||||
MemoryMapped2DArray {
|
MemoryMapped2DArray {
|
||||||
array: address as *mut [[T; X]; Y],
|
array: address as *mut [[T; X]; Y],
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ pub enum DebugLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const OUTPUT: *mut u8 = 0x04FF_F600 as *mut u8;
|
const OUTPUT: *mut u8 = 0x04FF_F600 as *mut u8;
|
||||||
const ENABLE: MemoryMapped<u16> = MemoryMapped::new(0x04FF_F780);
|
const ENABLE: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04FF_F780) };
|
||||||
|
|
||||||
const ENABLE_HANDSHAKE_IN: u16 = 0xC0DE;
|
const ENABLE_HANDSHAKE_IN: u16 = 0xC0DE;
|
||||||
const ENABLE_HANDSHAKE_OUT: u16 = 0x1DEA;
|
const ENABLE_HANDSHAKE_OUT: u16 = 0x1DEA;
|
||||||
|
|
||||||
const DEBUG_LEVEL: MemoryMapped<u16> = MemoryMapped::new(0x04FF_F700);
|
const DEBUG_LEVEL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04FF_F700) };
|
||||||
const DEBUG_FLAG_CODE: u16 = 0x0100;
|
const DEBUG_FLAG_CODE: u16 = 0x0100;
|
||||||
|
|
||||||
fn is_running_in_mgba() -> bool {
|
fn is_running_in_mgba() -> bool {
|
||||||
|
|
Loading…
Add table
Reference in a new issue