2021-06-28 01:03:08 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2022-01-17 21:44:25 +00:00
|
|
|
use core::cell::RefCell;
|
|
|
|
|
2021-06-28 01:03:08 +01:00
|
|
|
use agb::{
|
2023-02-24 08:44:47 +00:00
|
|
|
display::{
|
|
|
|
example_logo,
|
|
|
|
tiled::{RegularBackgroundSize, TileFormat},
|
|
|
|
},
|
2022-01-12 22:09:57 +00:00
|
|
|
fixnum::FixedNum,
|
2022-01-17 21:44:25 +00:00
|
|
|
interrupt::{free, Interrupt},
|
2021-06-28 01:03:08 +01:00
|
|
|
};
|
2022-01-17 21:44:25 +00:00
|
|
|
use bare_metal::{CriticalSection, Mutex};
|
2021-06-28 01:03:08 +01:00
|
|
|
|
|
|
|
struct BackCosines {
|
|
|
|
cosines: [u16; 32],
|
|
|
|
row: usize,
|
|
|
|
}
|
|
|
|
|
2023-04-06 21:16:13 +01:00
|
|
|
static BACK: Mutex<RefCell<BackCosines>> = Mutex::new(RefCell::new(BackCosines {
|
|
|
|
cosines: [0; 32],
|
|
|
|
row: 0,
|
|
|
|
}));
|
|
|
|
|
2021-08-07 16:36:41 +01:00
|
|
|
#[agb::entry]
|
2022-01-16 21:38:30 +00:00
|
|
|
fn main(mut gba: agb::Gba) -> ! {
|
2022-01-31 21:23:12 +00:00
|
|
|
let (gfx, mut vram) = gba.display.video.tiled0();
|
2021-06-28 01:03:08 +01:00
|
|
|
|
2022-05-03 22:29:51 +01:00
|
|
|
let mut background = gfx.background(
|
|
|
|
agb::display::Priority::P0,
|
|
|
|
RegularBackgroundSize::Background32x32,
|
2023-02-24 08:44:47 +00:00
|
|
|
TileFormat::FourBpp,
|
2022-05-03 22:29:51 +01:00
|
|
|
);
|
2022-01-23 20:03:59 +00:00
|
|
|
|
2022-01-31 21:23:12 +00:00
|
|
|
example_logo::display_logo(&mut background, &mut vram);
|
2021-06-28 01:03:08 +01:00
|
|
|
|
2023-04-06 21:16:13 +01:00
|
|
|
let _a = unsafe {
|
|
|
|
agb::interrupt::add_interrupt_handler(Interrupt::HBlank, |key: CriticalSection| {
|
|
|
|
let mut back = BACK.borrow(key).borrow_mut();
|
|
|
|
let deflection = back.cosines[back.row % 32];
|
|
|
|
((0x0400_0010) as *mut u16).write_volatile(deflection);
|
|
|
|
back.row += 1;
|
|
|
|
})
|
|
|
|
};
|
2021-06-28 01:03:08 +01:00
|
|
|
|
2021-07-03 18:57:17 +01:00
|
|
|
let vblank = agb::interrupt::VBlank::get();
|
2023-04-06 21:16:13 +01:00
|
|
|
let mut time = 0;
|
2021-06-28 01:03:08 +01:00
|
|
|
|
|
|
|
loop {
|
|
|
|
vblank.wait_for_vblank();
|
2022-01-17 21:44:25 +00:00
|
|
|
free(|key| {
|
2023-04-06 21:16:13 +01:00
|
|
|
let mut back = BACK.borrow(key).borrow_mut();
|
2022-11-17 21:00:51 +00:00
|
|
|
back.row = 0;
|
2022-01-17 21:44:25 +00:00
|
|
|
time += 1;
|
2022-11-17 21:00:51 +00:00
|
|
|
for (r, a) in back.cosines.iter_mut().enumerate() {
|
2022-01-17 21:44:25 +00:00
|
|
|
let n: FixedNum<8> = (FixedNum::new(r as i32) / 32 + FixedNum::new(time) / 128)
|
|
|
|
.cos()
|
|
|
|
* (256 * 4 - 1)
|
|
|
|
/ 256;
|
|
|
|
*a = (n.trunc() % (32 * 8)) as u16;
|
|
|
|
}
|
|
|
|
})
|
2021-06-28 01:03:08 +01:00
|
|
|
}
|
|
|
|
}
|