2019-02-13 19:47:12 +11:00
|
|
|
#![no_std]
|
2021-04-09 15:57:30 +10:00
|
|
|
#![no_main]
|
2019-02-13 19:47:12 +11:00
|
|
|
|
2021-04-09 15:57:30 +10:00
|
|
|
use gba::prelude::*;
|
2019-02-13 19:47:12 +11:00
|
|
|
|
|
|
|
#[panic_handler]
|
2021-04-09 15:57:30 +10:00
|
|
|
#[allow(unused)]
|
2019-02-13 19:47:12 +11:00
|
|
|
fn panic(info: &core::panic::PanicInfo) -> ! {
|
2021-02-23 17:19:14 +11:00
|
|
|
// This kills the emulation with a message if we're running inside an
|
|
|
|
// emulator we support (mGBA or NO$GBA), or just crashes the game if we
|
|
|
|
// aren't.
|
2021-04-09 15:57:30 +10:00
|
|
|
//fatal!("{}", info);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
DISPCNT.read();
|
|
|
|
}
|
2019-02-13 19:47:12 +11:00
|
|
|
}
|
|
|
|
|
2019-02-15 15:18:21 +11:00
|
|
|
/// Performs a busy loop until VBlank starts.
|
|
|
|
///
|
|
|
|
/// This is very inefficient, and please keep following the lessons until we
|
|
|
|
/// cover how interrupts work!
|
|
|
|
pub fn spin_until_vblank() {
|
2021-04-09 15:57:30 +10:00
|
|
|
while VCOUNT.read() < 160 {}
|
2019-02-15 15:18:21 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Performs a busy loop until VDraw starts.
|
|
|
|
///
|
|
|
|
/// This is very inefficient, and please keep following the lessons until we
|
|
|
|
/// cover how interrupts work!
|
|
|
|
pub fn spin_until_vdraw() {
|
2021-04-09 15:57:30 +10:00
|
|
|
while VCOUNT.read() >= 160 {}
|
2019-02-15 15:18:21 +11:00
|
|
|
}
|
|
|
|
|
2021-04-09 15:57:30 +10:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn main() -> ! {
|
|
|
|
const SETTING: DisplayControl = DisplayControl::new().with_display_mode(3).with_display_bg2(true);
|
2019-02-13 19:47:12 +11:00
|
|
|
DISPCNT.write(SETTING);
|
|
|
|
|
2021-04-09 15:57:30 +10:00
|
|
|
let mut px = mode3::WIDTH / 2;
|
|
|
|
let mut py = mode3::HEIGHT / 2;
|
|
|
|
let mut color = Color::from_rgb(31, 3, 1);
|
2019-02-13 19:47:12 +11:00
|
|
|
|
|
|
|
loop {
|
2019-02-15 13:16:09 +11:00
|
|
|
// read our keys for this frame
|
2021-04-09 15:57:30 +10:00
|
|
|
let keys: Keys = KEYINPUT.read().into();
|
2019-02-15 13:16:09 +11:00
|
|
|
|
2019-02-15 13:39:34 +11:00
|
|
|
// adjust game state and wait for vblank
|
2021-04-09 15:57:30 +10:00
|
|
|
px = px.wrapping_add((2 * keys.x_signum()) as usize);
|
|
|
|
py = py.wrapping_add((2 * keys.y_signum()) as usize);
|
|
|
|
if keys.l() {
|
2019-02-15 13:39:34 +11:00
|
|
|
color = Color(color.0.rotate_left(5));
|
|
|
|
}
|
2021-04-09 15:57:30 +10:00
|
|
|
if keys.r() {
|
2019-02-15 13:39:34 +11:00
|
|
|
color = Color(color.0.rotate_right(5));
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we wait
|
|
|
|
spin_until_vblank();
|
|
|
|
|
|
|
|
// draw the new game and wait until the next frame starts.
|
2021-04-09 15:57:30 +10:00
|
|
|
if (px + 1) >= mode3::WIDTH || (py + 1) >= mode3::HEIGHT {
|
2019-02-15 13:39:34 +11:00
|
|
|
// out of bounds, reset the screen and position.
|
2021-04-09 15:57:30 +10:00
|
|
|
mode3::dma3_clear_to(Color::from_rgb(0, 0, 0));
|
|
|
|
px = mode3::WIDTH / 2;
|
|
|
|
py = mode3::HEIGHT / 2;
|
|
|
|
color = Color(color.0.rotate_left(7));
|
2019-02-15 13:39:34 +11:00
|
|
|
} else {
|
|
|
|
// draw the new part of the line
|
2021-04-09 15:57:30 +10:00
|
|
|
mode3::bitmap_xy(px, py).write(color);
|
|
|
|
mode3::bitmap_xy(px, py + 1).write(color);
|
|
|
|
mode3::bitmap_xy(px + 1, py).write(color);
|
|
|
|
mode3::bitmap_xy(px + 1, py + 1).write(color);
|
2019-02-15 13:39:34 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// now we wait again
|
|
|
|
spin_until_vdraw();
|
2019-02-13 19:47:12 +11:00
|
|
|
}
|
|
|
|
}
|