From cf9ea504f6339a4a03730062c41dda2ab6e11bc1 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 16 Jan 2022 21:38:30 +0000 Subject: [PATCH] Update agb tests and all the examples --- agb/examples/allocation.rs | 2 +- agb/examples/beep.rs | 4 +--- agb/examples/bitmap3.rs | 3 +-- agb/examples/bitmap4.rs | 3 +-- agb/examples/chicken.rs | 3 +-- agb/examples/mixer_basic.rs | 3 +-- agb/examples/multiple_video.rs | 3 +-- agb/examples/output.rs | 2 +- agb/examples/panic.rs | 4 +--- agb/examples/stereo_sound.rs | 3 +-- agb/examples/syscall.rs | 3 +-- agb/examples/test_logo.rs | 3 +-- agb/examples/wave.rs | 3 +-- agb/src/lib.rs | 9 +++++++-- 14 files changed, 20 insertions(+), 28 deletions(-) diff --git a/agb/examples/allocation.rs b/agb/examples/allocation.rs index 67a8e3bf..64f0ddd3 100644 --- a/agb/examples/allocation.rs +++ b/agb/examples/allocation.rs @@ -6,7 +6,7 @@ extern crate alloc; use alloc::boxed::Box; #[agb::entry] -fn main() -> ! { +fn main(_gba: agb::Gba) -> ! { loop { let b = Box::new(1); agb::println!("dynamic allocation made to {:?}", &*b as *const _); diff --git a/agb/examples/beep.rs b/agb/examples/beep.rs index 39518009..dd399d30 100644 --- a/agb/examples/beep.rs +++ b/agb/examples/beep.rs @@ -4,9 +4,7 @@ use agb::sound; #[agb::entry] -fn main() -> ! { - let gba = agb::Gba::new(); - +fn main(gba: agb::Gba) -> ! { gba.sound.enable(); let sweep_settings = sound::dmg::SweepSettings::default(); diff --git a/agb/examples/bitmap3.rs b/agb/examples/bitmap3.rs index 98c668d2..fb4c41f5 100644 --- a/agb/examples/bitmap3.rs +++ b/agb/examples/bitmap3.rs @@ -9,8 +9,7 @@ struct Vector2D { } #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let mut bitmap = gba.display.video.bitmap3(); let vblank = agb::interrupt::VBlank::get(); diff --git a/agb/examples/bitmap4.rs b/agb/examples/bitmap4.rs index 47a8ccbc..a46f6c72 100644 --- a/agb/examples/bitmap4.rs +++ b/agb/examples/bitmap4.rs @@ -4,8 +4,7 @@ use agb::display; #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let mut bitmap = gba.display.video.bitmap4(); let vblank = agb::interrupt::VBlank::get(); diff --git a/agb/examples/chicken.rs b/agb/examples/chicken.rs index aec196fa..359a4811 100644 --- a/agb/examples/chicken.rs +++ b/agb/examples/chicken.rs @@ -35,14 +35,13 @@ fn frame_ranger(count: u32, start: u32, end: u32, delay: u32) -> u16 { } #[agb::entry] -fn main() -> ! { +fn main(mut gba: agb::Gba) -> ! { let map_as_grid: &[[u16; 32]; 32] = unsafe { (&MAP_MAP as *const [u16; 1024] as *const [[u16; 32]; 32]) .as_ref() .unwrap() }; - let mut gba = agb::Gba::new(); let mut gfx = gba.display.video.tiled0(); let vblank = agb::interrupt::VBlank::get(); let mut input = agb::input::ButtonController::new(); diff --git a/agb/examples/mixer_basic.rs b/agb/examples/mixer_basic.rs index fdb39b15..f699dc8a 100644 --- a/agb/examples/mixer_basic.rs +++ b/agb/examples/mixer_basic.rs @@ -10,8 +10,7 @@ use agb::{include_wav, Gba}; const DEAD_CODE: &[u8] = include_wav!("examples/JoshWoodward-DeadCode.wav"); #[agb::entry] -fn main() -> ! { - let mut gba = Gba::new(); +fn main(mut gba: Gba) -> ! { let mut input = ButtonController::new(); let vblank_provider = agb::interrupt::VBlank::get(); diff --git a/agb/examples/multiple_video.rs b/agb/examples/multiple_video.rs index 8de24f16..f37c69c4 100644 --- a/agb/examples/multiple_video.rs +++ b/agb/examples/multiple_video.rs @@ -9,8 +9,7 @@ struct Vector2D { } #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let vblank = agb::interrupt::VBlank::get(); let mut input = agb::input::ButtonController::new(); diff --git a/agb/examples/output.rs b/agb/examples/output.rs index 4a5c06ae..85e9cf65 100644 --- a/agb/examples/output.rs +++ b/agb/examples/output.rs @@ -2,7 +2,7 @@ #![no_main] #[agb::entry] -fn main() -> ! { +fn main(_gba: agb::Gba) -> ! { let count = agb::interrupt::Mutex::new(0); agb::add_interrupt_handler!(agb::interrupt::Interrupt::VBlank, |key| { let mut count = count.lock_with_key(&key); diff --git a/agb/examples/panic.rs b/agb/examples/panic.rs index 0a740826..71ff6e8c 100644 --- a/agb/examples/panic.rs +++ b/agb/examples/panic.rs @@ -4,9 +4,7 @@ use agb::display; #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); - +fn main(mut gba: agb::Gba) -> ! { let mut bitmap = gba.display.video.bitmap3(); let mut input = agb::input::ButtonController::new(); diff --git a/agb/examples/stereo_sound.rs b/agb/examples/stereo_sound.rs index 1667e259..7807673c 100644 --- a/agb/examples/stereo_sound.rs +++ b/agb/examples/stereo_sound.rs @@ -8,8 +8,7 @@ use agb::{include_wav, Gba}; const LET_IT_IN: &[u8] = include_wav!("examples/JoshWoodward-LetItIn.wav"); #[agb::entry] -fn main() -> ! { - let mut gba = Gba::new(); +fn main(mut gba: Gba) -> ! { let vblank_provider = agb::interrupt::VBlank::get(); let mut timer_controller = gba.timers.timers(); diff --git a/agb/examples/syscall.rs b/agb/examples/syscall.rs index 995fda9d..4650f3ef 100644 --- a/agb/examples/syscall.rs +++ b/agb/examples/syscall.rs @@ -4,8 +4,7 @@ use agb::{display, syscall}; #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let mut bitmap = gba.display.video.bitmap3(); for x in 0..display::WIDTH { diff --git a/agb/examples/test_logo.rs b/agb/examples/test_logo.rs index 806678fb..8cfc8164 100644 --- a/agb/examples/test_logo.rs +++ b/agb/examples/test_logo.rs @@ -4,8 +4,7 @@ use agb::display::example_logo; #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let mut gfx = gba.display.video.tiled0(); example_logo::display_logo(&mut gfx); diff --git a/agb/examples/wave.rs b/agb/examples/wave.rs index 239f60c8..79b11081 100644 --- a/agb/examples/wave.rs +++ b/agb/examples/wave.rs @@ -13,8 +13,7 @@ struct BackCosines { } #[agb::entry] -fn main() -> ! { - let mut gba = agb::Gba::new(); +fn main(mut gba: agb::Gba) -> ! { let mut gfx = gba.display.video.tiled0(); example_logo::display_logo(&mut gfx); diff --git a/agb/src/lib.rs b/agb/src/lib.rs index d5204c45..4848eb63 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -283,7 +283,11 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! { loop {} } +#[cfg(test)] +static mut TEST_GBA: Option = None; + #[doc(hidden)] +#[cfg(test)] pub fn test_runner(tests: &[&dyn Testable]) { let mut mgba = mgba::Mgba::new().unwrap(); mgba.print( @@ -292,7 +296,7 @@ pub fn test_runner(tests: &[&dyn Testable]) { ) .unwrap(); - let mut gba = Gba::new(); + let mut gba = unsafe { TEST_GBA.as_mut() }.unwrap(); for test in tests { test.run(&mut gba); @@ -307,7 +311,8 @@ pub fn test_runner(tests: &[&dyn Testable]) { #[cfg(test)] #[entry] -fn agb_test_main() -> ! { +fn agb_test_main(gba: Gba) -> ! { + unsafe { TEST_GBA = Some(gba) }; test_main(); #[allow(clippy::empty_loop)] loop {}