From 0f5ce17f75bec0331158c02196055c8ab70dddf3 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Fri, 9 Dec 2022 23:00:28 +0000 Subject: [PATCH] Fix the examples and the games --- agb/Cargo.toml | 3 ++- agb/examples/mixer_32768.rs | 16 +++++++++++++--- examples/hyperspace-roll/src/lib.rs | 1 - examples/the-hat-chooses-the-wizard/src/lib.rs | 7 ------- .../src/splash_screen.rs | 16 ++-------------- examples/the-purple-night/src/lib.rs | 2 -- examples/the-purple-night/src/sfx.rs | 4 ---- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/agb/Cargo.toml b/agb/Cargo.toml index 65728a32..b3b2c23d 100644 --- a/agb/Cargo.toml +++ b/agb/Cargo.toml @@ -12,7 +12,8 @@ opt-level = 3 debug = true [profile.release] -lto = true +opt-level = "s" +lto = "thin" debug = true [features] diff --git a/agb/examples/mixer_32768.rs b/agb/examples/mixer_32768.rs index 6dc338ae..19182776 100644 --- a/agb/examples/mixer_32768.rs +++ b/agb/examples/mixer_32768.rs @@ -39,7 +39,9 @@ fn main(mut gba: Gba) -> ! { let timer_controller = gba.timers.timers(); let mut timer = timer_controller.timer2; + let mut timer2 = timer_controller.timer3; timer.set_enabled(true); + timer2.set_cascade(true).set_enabled(true); let mut mixer = gba.mixer.mixer(Frequency::Hz32768); mixer.enable(); @@ -56,14 +58,22 @@ fn main(mut gba: Gba) -> ! { vblank_provider.wait_for_vblank(); bg.commit(&mut vram); - let before_mixing_cycles = timer.value(); + let before_mixing_cycles_high = timer2.value(); + let before_mixing_cycles_low = timer.value(); + mixer.frame(); - let after_mixing_cycles = timer.value(); + + let after_mixing_cycles_low = timer.value(); + let after_mixing_cycles_high = timer2.value(); frame_counter = frame_counter.wrapping_add(1); if frame_counter % 128 == 0 && !has_written_frame_time { - let total_cycles = after_mixing_cycles.wrapping_sub(before_mixing_cycles) as u32; + let before_mixing_cycles = + ((before_mixing_cycles_high as u32) << 16) + before_mixing_cycles_low as u32; + let after_mixing_cycles = + ((after_mixing_cycles_high as u32) << 16) + after_mixing_cycles_low as u32; + let total_cycles = after_mixing_cycles.wrapping_sub(before_mixing_cycles); let percent = (total_cycles * 100) / 280896; diff --git a/examples/hyperspace-roll/src/lib.rs b/examples/hyperspace-roll/src/lib.rs index 269f3231..61506591 100644 --- a/examples/hyperspace-roll/src/lib.rs +++ b/examples/hyperspace-roll/src/lib.rs @@ -142,7 +142,6 @@ pub fn main(mut gba: agb::Gba) -> ! { let mut mixer = gba.mixer.mixer(Frequency::Hz32768); mixer.enable(); - let _interrupt_handler = mixer.setup_interrupt_handler(); let sfx = Sfx::new(&mut mixer); diff --git a/examples/the-hat-chooses-the-wizard/src/lib.rs b/examples/the-hat-chooses-the-wizard/src/lib.rs index 26a8c9ca..d7ddd3b0 100644 --- a/examples/the-hat-chooses-the-wizard/src/lib.rs +++ b/examples/the-hat-chooses-the-wizard/src/lib.rs @@ -832,7 +832,6 @@ pub fn main(mut agb: agb::Gba) -> ! { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); level_display::write_level( &mut world_display, @@ -848,7 +847,6 @@ pub fn main(mut agb: agb::Gba) -> ! { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); let map_current_level = current_level; let mut background = InfiniteScrolledMap::new( @@ -894,21 +892,18 @@ pub fn main(mut agb: agb::Gba) -> ! { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); } while level.background.init_foreground(&mut vram) != PartialUpdateStatus::Done { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); } for _ in 0..20 { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); } object.commit(); @@ -930,7 +925,6 @@ pub fn main(mut agb: agb::Gba) -> ! { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); object.commit(); } break; @@ -944,7 +938,6 @@ pub fn main(mut agb: agb::Gba) -> ! { music_box.before_frame(&mut mixer); mixer.frame(); vblank.wait_for_vblank(); - mixer.after_vblank(); object.commit(); } diff --git a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs index 7be40dda..12991514 100644 --- a/examples/the-hat-chooses-the-wizard/src/splash_screen.rs +++ b/examples/the-hat-chooses-the-wizard/src/splash_screen.rs @@ -41,10 +41,6 @@ pub fn show_splash_screen( vblank.wait_for_vblank(); - if let Some(ref mut mixer) = mixer { - mixer.after_vblank(); - } - for y in 0..20u16 { for x in 0..30u16 { map.set_tile( @@ -63,10 +59,6 @@ pub fn show_splash_screen( } vblank.wait_for_vblank(); - - if let Some(ref mut mixer) = mixer { - mixer.after_vblank(); - } } map.commit(vram); @@ -83,17 +75,13 @@ pub fn show_splash_screen( ) { break; } - if let Some(ref mut mixer) = mixer { - if let Some(ref mut music_box) = music_box { + if let Some(mixer) = &mut mixer { + if let Some(music_box) = &mut music_box { music_box.before_frame(mixer); } mixer.frame(); } vblank.wait_for_vblank(); - - if let Some(ref mut mixer) = mixer { - mixer.after_vblank(); - } } map.hide(); diff --git a/examples/the-purple-night/src/lib.rs b/examples/the-purple-night/src/lib.rs index 1dc5513f..f513effc 100644 --- a/examples/the-purple-night/src/lib.rs +++ b/examples/the-purple-night/src/lib.rs @@ -85,7 +85,6 @@ impl<'a> Level<'a> { let mut between_updates = || { sfx.frame(); vblank.wait_for_vblank(); - sfx.after_vblank(); }; backdrop.init(vram, start_pos, &mut between_updates); @@ -2283,7 +2282,6 @@ fn game_with_level(gba: &mut agb::Gba) { start_at_boss = loop { sfx.frame(); vblank.wait_for_vblank(); - sfx.after_vblank(); object.commit(); match game.advance_frame(&object, &mut vram, &mut sfx) { GameStatus::Continue => {} diff --git a/examples/the-purple-night/src/sfx.rs b/examples/the-purple-night/src/sfx.rs index 08f26800..0e8ac5be 100644 --- a/examples/the-purple-night/src/sfx.rs +++ b/examples/the-purple-night/src/sfx.rs @@ -39,10 +39,6 @@ impl<'a> Sfx<'a> { self.mixer.frame(); } - pub fn after_vblank(&mut self) { - self.mixer.after_vblank(); - } - pub fn stop_music(&mut self) { if let Some(bgm) = &self.bgm { let channel = self.mixer.channel(bgm).unwrap();