mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-11 03:21:30 +11:00
cleanup and cleanup designations
This commit is contained in:
parent
71a2de023f
commit
779770a187
|
@ -20,50 +20,17 @@ macro_rules! const_assert {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[panic_handler]
|
#[macro_export]
|
||||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
macro_rules! const_rgb {
|
||||||
loop {}
|
($r:expr, $g:expr, $b:expr) => {{
|
||||||
}
|
const_assert!($r);
|
||||||
|
const_assert!($g);
|
||||||
newtype! {
|
const_assert!($b);
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
Color::new($r, $g, $b)
|
||||||
Color, u16
|
}};
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn rgb(red: u16, green: u16, blue: u16) -> Color {
|
|
||||||
Color(blue << 10 | green << 5 | red)
|
|
||||||
}
|
|
||||||
|
|
||||||
newtype! {
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
DisplayControlSetting, u16
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const DISPLAY_CONTROL: VolatilePtr<DisplayControlSetting> = VolatilePtr(0x04000000 as *mut DisplayControlSetting);
|
|
||||||
pub const JUST_MODE3_AND_BG2: DisplayControlSetting = DisplayControlSetting(3 + 0b100_0000_0000);
|
|
||||||
|
|
||||||
pub struct Mode3;
|
|
||||||
|
|
||||||
impl Mode3 {
|
|
||||||
const SCREEN_WIDTH: isize = 240;
|
|
||||||
const PIXELS: VolatilePtr<Color> = VolatilePtr(0x600_0000 as *mut Color);
|
|
||||||
|
|
||||||
pub unsafe fn draw_pixel_unchecked(col: isize, row: isize, color: Color) {
|
|
||||||
Self::PIXELS.offset(col + row * Self::SCREEN_WIDTH).write(color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[start]
|
|
||||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|
||||||
unsafe {
|
|
||||||
DISPLAY_CONTROL.write(JUST_MODE3_AND_BG2);
|
|
||||||
Mode3::draw_pixel_unchecked(120, 80, rgb(31, 0, 0));
|
|
||||||
Mode3::draw_pixel_unchecked(136, 80, rgb(0, 31, 0));
|
|
||||||
Mode3::draw_pixel_unchecked(120, 96, rgb(0, 0, 31));
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: kill this
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct VolatilePtr<T>(pub *mut T);
|
pub struct VolatilePtr<T>(pub *mut T);
|
||||||
|
@ -78,3 +45,51 @@ impl<T> VolatilePtr<T> {
|
||||||
VolatilePtr(self.0.wrapping_offset(count))
|
VolatilePtr(self.0.wrapping_offset(count))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newtype! {
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
Color, u16
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Color {
|
||||||
|
/// Combines the Red, Blue, and Green provided into a single color value.
|
||||||
|
pub const fn new(red: u16, green: u16, blue: u16) -> Color {
|
||||||
|
Color(blue << 10 | green << 5 | red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newtype! {
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
DisplayControlSetting, u16
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const DISPLAY_CONTROL: VolatilePtr<DisplayControlSetting> = VolatilePtr(0x0400_0000 as *mut DisplayControlSetting);
|
||||||
|
pub const JUST_MODE3: DisplayControlSetting = DisplayControlSetting(3);
|
||||||
|
pub const JUST_BG2: DisplayControlSetting = DisplayControlSetting(0b100_0000_0000);
|
||||||
|
pub const JUST_MODE3_AND_BG2: DisplayControlSetting = DisplayControlSetting(JUST_MODE3.0 | JUST_BG2.0);
|
||||||
|
|
||||||
|
pub struct Mode3;
|
||||||
|
impl Mode3 {
|
||||||
|
const SCREEN_WIDTH: isize = 240;
|
||||||
|
const PIXELS: VolatilePtr<Color> = VolatilePtr(0x600_0000 as *mut Color);
|
||||||
|
|
||||||
|
pub unsafe fn draw_pixel_unchecked(col: isize, row: isize, color: Color) {
|
||||||
|
Self::PIXELS.offset(col + row * Self::SCREEN_WIDTH).write(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[start]
|
||||||
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
|
unsafe {
|
||||||
|
DISPLAY_CONTROL.write(JUST_MODE3_AND_BG2);
|
||||||
|
Mode3::draw_pixel_unchecked(120, 80, const_rgb!(31, 0, 0));
|
||||||
|
Mode3::draw_pixel_unchecked(136, 80, const_rgb!(0, 31, 0));
|
||||||
|
Mode3::draw_pixel_unchecked(120, 96, const_rgb!(0, 0, 31));
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -37,3 +37,6 @@ impl<T> VolatilePtr<T> {
|
||||||
VolatilePtr(self.0 as *mut Z)
|
VolatilePtr(self.0 as *mut Z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: kill all this with fire
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,3 @@ pub mod io_registers;
|
||||||
|
|
||||||
pub mod video_ram;
|
pub mod video_ram;
|
||||||
pub(crate) use crate::video_ram::*;
|
pub(crate) use crate::video_ram::*;
|
||||||
|
|
||||||
/// Combines the Red, Blue, and Green provided into a single color value.
|
|
||||||
pub const fn rgb16(red: u16, green: u16, blue: u16) -> u16 {
|
|
||||||
blue << 10 | green << 5 | red
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
pub use super::*;
|
pub use super::*;
|
||||||
|
|
||||||
|
// TODO: kill all this too
|
||||||
|
|
||||||
/// The physical width in pixels of the GBA screen.
|
/// The physical width in pixels of the GBA screen.
|
||||||
pub const SCREEN_WIDTH: isize = 240;
|
pub const SCREEN_WIDTH: isize = 240;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue