mark creating memory mapped as unsafe

This commit is contained in:
Corwin Kuiper 2021-03-06 20:07:04 +00:00
parent 5935f2a8c6
commit 0613849da9
5 changed files with 20 additions and 24 deletions

View file

@ -5,26 +5,28 @@ use crate::{
use bitflags::bitflags;
use core::convert::TryInto;
const DISPLAY_CONTROL: MemoryMapped<u16> = MemoryMapped::new(0x0400_0000);
const DISPLAY_STATUS: MemoryMapped<u16> = MemoryMapped::new(0x0400_0004);
const VCOUNT: MemoryMapped<u16> = MemoryMapped::new(0x0400_0006);
const DISPLAY_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0000) };
const DISPLAY_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0004) };
const VCOUNT: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0006) };
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> = MemoryMapped1DArray::new(0x0500_0000);
const PALETTE_SPRITE: MemoryMapped1DArray<u16, 256> = MemoryMapped1DArray::new(0x0500_0200);
const PALETTE_BACKGROUND: MemoryMapped1DArray<u16, 256> =
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 }> =
MemoryMapped2DArray::new(0x600_0000);
unsafe { MemoryMapped2DArray::new(0x600_0000) };
const BITMAP_PAGE_FRONT_MODE_4: MemoryMapped2DArray<
u16,
{ (WIDTH / 2) as usize },
{ HEIGHT as usize },
> = MemoryMapped2DArray::new(0x600_0000);
> = unsafe { MemoryMapped2DArray::new(0x600_0000) };
const BITMAP_PAGE_BACK_MODE_4: MemoryMapped2DArray<
u16,
{ (WIDTH / 2) as usize },
{ HEIGHT as usize },
> = MemoryMapped2DArray::new(0x600_A000);
> = unsafe { MemoryMapped2DArray::new(0x600_A000) };
pub const WIDTH: i32 = 240;
pub const HEIGHT: i32 = 160;
@ -64,14 +66,8 @@ pub struct Display {
in_mode: Single,
}
impl Default for Display {
fn default() -> Self {
Self::new()
}
}
impl Display {
pub(crate) const fn new() -> Self {
pub(crate) const unsafe fn new() -> Self {
Display {
in_mode: Single::new(),
}

View file

@ -17,8 +17,8 @@ pub enum Interrupt {
Gamepak,
}
const ENABLED_INTERRUPTS: MemoryMapped<u16> = MemoryMapped::new(0x04000200);
const INTERRUPTS_ENABLED: MemoryMapped<u16> = MemoryMapped::new(0x04000208);
const ENABLED_INTERRUPTS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000200) };
const INTERRUPTS_ENABLED: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x04000208) };
pub fn enable(interrupt: Interrupt) {
let _interrupt_token = temporary_interrupt_disable();

View file

@ -24,7 +24,7 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
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 display: display::Display,
@ -35,7 +35,7 @@ impl Gba {
unsafe { GBASINGLE.take() }
}
const fn single_new() -> Self {
const unsafe fn single_new() -> Self {
Self {
display: display::Display::new(),
}

View file

@ -3,7 +3,7 @@ pub struct MemoryMapped<T> {
}
impl<T> MemoryMapped<T> {
pub const fn new(address: usize) -> Self {
pub const unsafe fn new(address: usize) -> Self {
MemoryMapped {
address: address as *mut T,
}
@ -24,7 +24,7 @@ pub struct MemoryMapped1DArray<T, const N: usize> {
#[allow(dead_code)]
impl<T, const N: usize> MemoryMapped1DArray<T, N> {
pub const fn new(address: usize) -> Self {
pub const unsafe fn new(address: usize) -> Self {
MemoryMapped1DArray {
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> {
pub const fn new(address: usize) -> Self {
pub const unsafe fn new(address: usize) -> Self {
MemoryMapped2DArray {
array: address as *mut [[T; X]; Y],
}

View file

@ -12,12 +12,12 @@ pub enum DebugLevel {
}
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_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;
fn is_running_in_mgba() -> bool {