gba/examples/key_demo.rs

43 lines
1,002 B
Rust
Raw Normal View History

2018-11-15 13:54:04 +11:00
#![feature(start)]
#![no_std]
extern crate gba;
use gba::{io_registers::*, video_ram::*};
#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let mode3bg2 = {
let mut setting = DisplayControlSetting::default();
setting.set_display_bg2(true);
setting.set_mode(DisplayControlMode::Bitmap3);
setting
};
set_display_control(mode3bg2);
let red = rgb16(31, 0, 0);
let green = rgb16(0, 31, 0);
loop {
let this_frame_keys = key_input();
let this_frame_key_raw: u16 = unsafe { core::mem::transmute(this_frame_keys) };
wait_until_vblank();
for i in 0..16 {
let key = ((this_frame_key_raw >> i) & 1) > 0;
mode3_draw_pixel(15 - i, 0, if key { green } else { red });
mode3_draw_pixel(15 - i, 1, if key { green } else { red });
2018-11-15 19:23:04 +11:00
mode3_draw_pixel(50 - i, 10 / i, if key { green } else { red });
2018-11-15 13:54:04 +11:00
}
wait_until_vdraw();
}
}