From 42647b73735960e6b4954c043e03bca66cd9ad73 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 7 Aug 2021 13:21:54 +0100 Subject: [PATCH] add println macro for mgba --- agb/examples/output.rs | 7 +------ agb/src/mgba.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/agb/examples/output.rs b/agb/examples/output.rs index cb2675d..4c8d91e 100644 --- a/agb/examples/output.rs +++ b/agb/examples/output.rs @@ -5,7 +5,6 @@ extern crate agb; #[no_mangle] pub fn main() -> ! { let mut gba = agb::Gba::new(); - let mut mgba = agb::mgba::Mgba::new().unwrap(); let vblank = gba.display.vblank.get(); @@ -13,11 +12,7 @@ pub fn main() -> ! { loop { vblank.wait_for_VBlank(); - mgba.print( - format_args!("Hello, world, frame = {}", count), - agb::mgba::DebugLevel::Info, - ) - .unwrap(); + agb::println!("Hello, world, frame = {}", count); count += 1; } diff --git a/agb/src/mgba.rs b/agb/src/mgba.rs index 380efdf..02481fa 100644 --- a/agb/src/mgba.rs +++ b/agb/src/mgba.rs @@ -78,3 +78,14 @@ impl core::fmt::Write for Mgba { Ok(()) } } + +#[macro_export] +macro_rules! println { + ($( $x:expr ),*) => { + { + if let Some(mut mgba) = $crate::mgba::Mgba::new() { + let _ = mgba.print(format_args!($($x,)*), $crate::mgba::DebugLevel::Info); + } + } + }; +}