From 273a8bd67601384710f12121577aabc95cd3097f Mon Sep 17 00:00:00 2001 From: Lokathor Date: Thu, 14 Feb 2019 19:16:09 -0700 Subject: [PATCH] commit the changes --- Cargo.toml | 2 +- README.md | 7 +++++++ examples/hello_world.rs | 45 ++++++++++++++--------------------------- src/macros.rs | 20 ++++++++++++++++++ 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2801cdd..0483081 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "gba" description = "A crate (and book) for making GBA games with Rust." -version = "0.4.0" +version = "0.4.0-pre" authors = ["Lokathor ", "Thomas Winwood "] repository = "https://github.com/rust-console/gba" readme = "README.md" diff --git a/README.md b/README.md index 412808c..b548081 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,13 @@ However, currently the development focus is leaning towards having minimal coverage of all the parts of the GBA. Until that's done, unfortunately the book will be in a rather messy state. +**Branches:** + +* `master` is the code that's on crates.io, though maybe the book has been + updated since then. +* `dev` is the hopefully more settled parts of the next version. +* Anything else is just stuff scratch space basically. + ## What's Missing The following major GBA features are still missing from the crate: diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 122646b..b6263ec 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -5,52 +5,37 @@ use gba::{ fatal, io::display::{DisplayControlSetting, DisplayMode, DISPCNT}, - vram::bitmap::{Mode3, Mode4, Mode5, Page}, - warn, Color, + vram::bitmap::Mode3, + Color, }; +use gba::io::keypad::read_key_input; #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { + // This kills the emulation with a message if we're running within mGBA. fatal!("{}", info); + // If we're _not_ running within mGBA then we still need to not return, so + // loop forever doing nothing. loop {} } #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { const SETTING: DisplayControlSetting = - DisplayControlSetting::new().with_mode(DisplayMode::Mode5).with_bg2(true); + DisplayControlSetting::new().with_mode(DisplayMode::Mode3).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); + let mut px = Mode3::WIDTH / 2; + let mut py = Mode3::HEIGHT / 2; + let mut color = Color::from_rgb(31, 0, 0); - 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(); + // read our keys for this frame + let this_frame_keys = 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)); + Mode5::dma_clear_to(Page::Zero, Color(111)); + Mode5::draw_line(Page::Zero, 5, 5, 100, 100, Color(0b0_11111_11111_11111)); gba::io::display::spin_until_vdraw(); } } diff --git a/src/macros.rs b/src/macros.rs index 0463992..5cbc981 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -181,3 +181,23 @@ macro_rules! debug { } }}; } + +/// Using timers 0 and 1, performs a crude timing of the expression given. +#[macro_export] +macro_rules! time_this01 { + ($x:expr) => {{ + use $crate::io::timers::*; + const NORMAL_ON: TimerControlSetting = TimerControlSetting::new().with_enabled(true); + const CASCADE_ON: TimerControlSetting = + TimerControlSetting::new().with_enabled(true).with_tick_rate(TimerTickRate::Cascade); + const OFF: TimerControlSetting = TimerControlSetting::new(); + TM1CNT_H.write(CASCADE_ON); + TM0CNT_H.write(NORMAL_ON); + $x; + TM0CNT_H.write(OFF); + TM1CNT_H.write(OFF); + let end_low = TM0CNT_L.read() as u32; + let end_high = TM1CNT_L.read() as u32; + end_high << 16 | end_low + }}; +}