2022-09-28 02:40:05 +10:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2022-10-07 10:14:34 +11:00
|
|
|
use core::{fmt::Write, mem::size_of_val};
|
2022-09-28 09:57:09 +10:00
|
|
|
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 {}
|
|
|
|
}
|
|
|
|
|
2022-10-07 15:11:13 +11:00
|
|
|
static FRAME_KEYS: GbaCell<KeyInput> = GbaCell::new(KeyInput::new());
|
2022-09-28 03:20:05 +10:00
|
|
|
|
2022-10-07 10:23:32 +11:00
|
|
|
extern "C" fn irq_handler(_: IrqBits) {
|
2022-10-07 15:11:13 +11:00
|
|
|
// We'll read the keys during vblank and store it for later.
|
|
|
|
FRAME_KEYS.write(KEYINPUT.read());
|
2022-09-28 02:40:05 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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-10-07 10:14:34 +11:00
|
|
|
{
|
|
|
|
// get our tile data into memory.
|
2022-10-08 13:52:50 +11:00
|
|
|
let src = CGA_8X8_THICK.as_ptr().cast::<u8>();
|
2022-10-07 10:14:34 +11:00
|
|
|
let dest = CHARBLOCK0_4BPP.index(0).as_usize() as *mut u32;
|
|
|
|
let info = BitUnpackInfo {
|
|
|
|
src_byte_len: size_of_val(&CGA_8X8_THICK) as u16,
|
|
|
|
src_elem_width: 1,
|
|
|
|
dest_elem_width: 4,
|
|
|
|
offset_and_touch_zero: 0,
|
|
|
|
};
|
2022-10-08 13:52:50 +11:00
|
|
|
unsafe { BitUnPack(src, dest, &info) };
|
2022-10-07 10:14:34 +11:00
|
|
|
}
|
|
|
|
|
2022-10-08 13:52:50 +11:00
|
|
|
{
|
|
|
|
// the the tilemap set up
|
2022-10-08 15:16:54 +11:00
|
|
|
let tsb = TextScreenblock::new(31);
|
2022-10-08 13:52:50 +11:00
|
|
|
for row in 0..16_usize {
|
|
|
|
for col in 0..16_usize {
|
|
|
|
let id = row * 16 + col;
|
2022-10-08 15:16:54 +11:00
|
|
|
let entry = TextEntry::new().with_tile_id(id as u16);
|
2022-10-08 13:52:50 +11:00
|
|
|
tsb.row_col(row, col).write(entry);
|
|
|
|
}
|
2022-10-07 15:11:13 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 13:52:50 +11:00
|
|
|
{
|
|
|
|
// Set BG0 to use the tilemap we just made, and set it to be shown.
|
|
|
|
BG0CNT.write(BackgroundControl::new().with_screenblock(31));
|
|
|
|
DISPCNT.write(DisplayControl::new().with_show_bg0(true));
|
|
|
|
}
|
2022-09-28 02:40:05 +10:00
|
|
|
|
2022-10-07 15:11:13 +11:00
|
|
|
let mut x_off = 0_u32;
|
|
|
|
let mut y_off = 0_u32;
|
|
|
|
let mut backdrop_color = Color(0);
|
2022-09-28 02:40:05 +10:00
|
|
|
loop {
|
|
|
|
VBlankIntrWait();
|
2022-10-07 15:11:13 +11:00
|
|
|
// show current frame
|
|
|
|
BACKDROP_COLOR.write(backdrop_color);
|
|
|
|
BG0HOFS.write(x_off as u16);
|
|
|
|
BG0VOFS.write(y_off as u16);
|
2022-09-28 02:40:05 +10:00
|
|
|
|
2022-10-07 15:11:13 +11:00
|
|
|
// prep next frame
|
|
|
|
let k = FRAME_KEYS.read();
|
|
|
|
backdrop_color = Color(k.to_u16());
|
|
|
|
if k.up() {
|
|
|
|
y_off = y_off.wrapping_add(1);
|
|
|
|
}
|
|
|
|
if k.down() {
|
|
|
|
y_off = y_off.wrapping_sub(1);
|
|
|
|
}
|
|
|
|
if k.left() {
|
|
|
|
x_off = x_off.wrapping_add(1);
|
|
|
|
}
|
|
|
|
if k.right() {
|
|
|
|
x_off = x_off.wrapping_sub(1);
|
|
|
|
}
|
2022-09-28 02:40:05 +10:00
|
|
|
}
|
|
|
|
}
|