mirror of
https://github.com/italicsjenga/gba.git
synced 2024-12-23 10:51:30 +11:00
example updates
This commit is contained in:
parent
9e7937b956
commit
c360c2dce4
|
@ -1,25 +0,0 @@
|
|||
#![no_std]
|
||||
#![feature(start)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use gba::{
|
||||
io::display::{DisplayControlSetting, DisplayMode, DISPCNT},
|
||||
vram::bitmap::Mode3,
|
||||
Color,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
const SETTING: DisplayControlSetting =
|
||||
DisplayControlSetting::new().with_mode(DisplayMode::Mode3).with_bg2(true);
|
||||
DISPCNT.write(SETTING);
|
||||
Mode3::write_pixel(120, 80, Color::from_rgb(31, 0, 0));
|
||||
Mode3::write_pixel(136, 80, Color::from_rgb(0, 31, 0));
|
||||
Mode3::write_pixel(120, 96, Color::from_rgb(0, 0, 31));
|
||||
loop {}
|
||||
}
|
|
@ -21,8 +21,8 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|||
const SETTING: DisplayControlSetting = DisplayControlSetting::new().with_mode(DisplayMode::Mode3).with_bg2(true);
|
||||
DISPCNT.write(SETTING);
|
||||
|
||||
let mut px = Mode3::SCREEN_WIDTH / 2;
|
||||
let mut py = Mode3::SCREEN_HEIGHT / 2;
|
||||
let mut px = Mode3::WIDTH / 2;
|
||||
let mut py = Mode3::HEIGHT / 2;
|
||||
let mut color = Color::from_rgb(31, 0, 0);
|
||||
|
||||
loop {
|
||||
|
@ -36,24 +36,24 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|||
|
||||
// draw the new game and wait until the next frame starts.
|
||||
const BLACK: Color = Color::from_rgb(0, 0, 0);
|
||||
if px >= Mode3::SCREEN_WIDTH || py >= Mode3::SCREEN_HEIGHT {
|
||||
if px >= Mode3::WIDTH || py >= Mode3::HEIGHT {
|
||||
// out of bounds, reset the screen and position.
|
||||
Mode3::clear_to(BLACK);
|
||||
color = color.rotate_left(5);
|
||||
px = Mode3::SCREEN_WIDTH / 2;
|
||||
py = Mode3::SCREEN_HEIGHT / 2;
|
||||
px = Mode3::WIDTH / 2;
|
||||
py = Mode3::HEIGHT / 2;
|
||||
} else {
|
||||
let color_here = Mode3::read_pixel(px, py);
|
||||
let color_here = Mode3::read(px, py);
|
||||
if color_here != Some(BLACK) {
|
||||
// crashed into our own line, reset the screen
|
||||
Mode3::dma_clear_to(BLACK);
|
||||
color = color.rotate_left(5);
|
||||
} else {
|
||||
// draw the new part of the line
|
||||
Mode3::write_pixel(px, py, color);
|
||||
Mode3::write_pixel(px, py + 1, color);
|
||||
Mode3::write_pixel(px + 1, py, color);
|
||||
Mode3::write_pixel(px + 1, py + 1, color);
|
||||
Mode3::write(px, py, color);
|
||||
Mode3::write(px, py + 1, color);
|
||||
Mode3::write(px + 1, py, color);
|
||||
Mode3::write(px + 1, py + 1, color);
|
||||
}
|
||||
}
|
||||
spin_until_vdraw();
|
||||
|
|
56
examples/hello_world.rs
Normal file
56
examples/hello_world.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
#![no_std]
|
||||
#![feature(start)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use gba::{
|
||||
fatal,
|
||||
io::display::{DisplayControlSetting, DisplayMode, DISPCNT},
|
||||
vram::bitmap::{Mode3, Mode4, Mode5, Page},
|
||||
warn, Color,
|
||||
};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||
fatal!("{}", info);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
const SETTING: DisplayControlSetting =
|
||||
DisplayControlSetting::new().with_mode(DisplayMode::Mode5).with_bg2(true);
|
||||
DISPCNT.write(SETTING);
|
||||
|
||||
use gba::io::timers::*;
|
||||
let tcs0 = TimerControlSetting::new().with_enabled(true);
|
||||
let tcs1 = TimerControlSetting::new().with_tick_rate(TimerTickRate::Cascade).with_enabled(true);
|
||||
|
||||
TM1CNT_H.write(tcs1);
|
||||
TM0CNT_H.write(tcs0);
|
||||
let start = TM0CNT_L.read();
|
||||
Mode5::clear_to(Page::Zero, Color(0));
|
||||
let end0 = TM0CNT_L.read();
|
||||
let end1 = TM1CNT_L.read();
|
||||
warn!("CLEAR_TO: start:{}, end0:{}, end1:{}", start, end0, end1);
|
||||
|
||||
// reset
|
||||
TM1CNT_H.write(TimerControlSetting::new());
|
||||
TM0CNT_H.write(TimerControlSetting::new());
|
||||
|
||||
TM1CNT_H.write(tcs1);
|
||||
TM0CNT_H.write(tcs0);
|
||||
let start = TM0CNT_L.read();
|
||||
Mode5::dma_clear_to(Page::Zero, Color(0));
|
||||
let end0 = TM0CNT_L.read();
|
||||
let end1 = TM1CNT_L.read();
|
||||
warn!("DMA_CLEAR_TO: start:{}, end0:{}, end1:{}", start, end0, end1);
|
||||
|
||||
DISPCNT.write(DisplayControlSetting::new().with_mode(DisplayMode::Mode3).with_bg2(true));
|
||||
loop {
|
||||
let this_frame_keys = gba::io::keypad::read_key_input();
|
||||
gba::io::display::spin_until_vblank();
|
||||
Mode3::dma_clear_to(Color(111));
|
||||
Mode3::draw_line(5, 5, 240, 160, Color(0b0_11111_11111_11111));
|
||||
gba::io::display::spin_until_vdraw();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue