2022-09-28 02:40:05 +10:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2022-09-28 09:57:09 +10:00
|
|
|
use core::fmt::Write;
|
|
|
|
use gba::{
|
|
|
|
mgba::{MgbaBufferedLogger, MgbaMessageLevel},
|
|
|
|
prelude::*,
|
|
|
|
};
|
2022-09-28 02:40:05 +10:00
|
|
|
|
|
|
|
#[panic_handler]
|
2022-09-28 09:57:09 +10:00
|
|
|
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
|
|
|
|
if let Ok(mut logger) = MgbaBufferedLogger::try_new(MgbaMessageLevel::Fatal) {
|
|
|
|
write!(logger, "{info}").ok();
|
|
|
|
}
|
2022-09-28 02:40:05 +10:00
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
|
|
|
static KEYS: GbaCell<KeyInput> = GbaCell::new(KeyInput::new());
|
|
|
|
|
2022-09-28 03:20:05 +10:00
|
|
|
#[link_section = ".ewram"]
|
|
|
|
static VALUE: GbaCell<u16> = GbaCell::new(0);
|
|
|
|
|
2022-09-28 02:40:05 +10:00
|
|
|
extern "C" fn irq_handler(_: u16) {
|
|
|
|
// just as a demo, we'll read the keys during vblank.
|
|
|
|
KEYS.write(KEYINPUT.read());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
extern "C" fn main() -> ! {
|
|
|
|
RUST_IRQ_HANDLER.write(Some(irq_handler));
|
|
|
|
DISPSTAT.write(DisplayStatus::new().with_irq_vblank(true));
|
|
|
|
IE.write(IrqBits::VBLANK);
|
|
|
|
IME.write(true);
|
|
|
|
|
2022-09-28 09:57:09 +10:00
|
|
|
if let Ok(mut logger) = MgbaBufferedLogger::try_new(MgbaMessageLevel::Debug) {
|
|
|
|
writeln!(logger, "hello!").ok();
|
|
|
|
}
|
|
|
|
|
2022-09-28 02:40:05 +10:00
|
|
|
DISPCNT.write(DisplayControl::new().with_show_bg0(true));
|
|
|
|
|
|
|
|
loop {
|
|
|
|
VBlankIntrWait();
|
|
|
|
|
|
|
|
let k = KEYS.read();
|
2022-09-28 03:20:05 +10:00
|
|
|
VALUE.write((k.to_u16() + 3) / k.to_u16()); // force a runtime division
|
2022-09-28 02:40:05 +10:00
|
|
|
BACKDROP_COLOR.write(Color(k.to_u16()));
|
|
|
|
}
|
|
|
|
}
|