Fix the examples and the games

This commit is contained in:
Gwilym Kuiper 2022-12-09 23:00:28 +00:00
parent 6df06211c6
commit 0f5ce17f75
7 changed files with 17 additions and 32 deletions

View file

@ -12,7 +12,8 @@ opt-level = 3
debug = true debug = true
[profile.release] [profile.release]
lto = true opt-level = "s"
lto = "thin"
debug = true debug = true
[features] [features]

View file

@ -39,7 +39,9 @@ fn main(mut gba: Gba) -> ! {
let timer_controller = gba.timers.timers(); let timer_controller = gba.timers.timers();
let mut timer = timer_controller.timer2; let mut timer = timer_controller.timer2;
let mut timer2 = timer_controller.timer3;
timer.set_enabled(true); timer.set_enabled(true);
timer2.set_cascade(true).set_enabled(true);
let mut mixer = gba.mixer.mixer(Frequency::Hz32768); let mut mixer = gba.mixer.mixer(Frequency::Hz32768);
mixer.enable(); mixer.enable();
@ -56,14 +58,22 @@ fn main(mut gba: Gba) -> ! {
vblank_provider.wait_for_vblank(); vblank_provider.wait_for_vblank();
bg.commit(&mut vram); 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(); 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); frame_counter = frame_counter.wrapping_add(1);
if frame_counter % 128 == 0 && !has_written_frame_time { 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; let percent = (total_cycles * 100) / 280896;

View file

@ -142,7 +142,6 @@ pub fn main(mut gba: agb::Gba) -> ! {
let mut mixer = gba.mixer.mixer(Frequency::Hz32768); let mut mixer = gba.mixer.mixer(Frequency::Hz32768);
mixer.enable(); mixer.enable();
let _interrupt_handler = mixer.setup_interrupt_handler();
let sfx = Sfx::new(&mut mixer); let sfx = Sfx::new(&mut mixer);

View file

@ -832,7 +832,6 @@ pub fn main(mut agb: agb::Gba) -> ! {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
level_display::write_level( level_display::write_level(
&mut world_display, &mut world_display,
@ -848,7 +847,6 @@ pub fn main(mut agb: agb::Gba) -> ! {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
let map_current_level = current_level; let map_current_level = current_level;
let mut background = InfiniteScrolledMap::new( let mut background = InfiniteScrolledMap::new(
@ -894,21 +892,18 @@ pub fn main(mut agb: agb::Gba) -> ! {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
} }
while level.background.init_foreground(&mut vram) != PartialUpdateStatus::Done { while level.background.init_foreground(&mut vram) != PartialUpdateStatus::Done {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
} }
for _ in 0..20 { for _ in 0..20 {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
} }
object.commit(); object.commit();
@ -930,7 +925,6 @@ pub fn main(mut agb: agb::Gba) -> ! {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
object.commit(); object.commit();
} }
break; break;
@ -944,7 +938,6 @@ pub fn main(mut agb: agb::Gba) -> ! {
music_box.before_frame(&mut mixer); music_box.before_frame(&mut mixer);
mixer.frame(); mixer.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
mixer.after_vblank();
object.commit(); object.commit();
} }

View file

@ -41,10 +41,6 @@ pub fn show_splash_screen(
vblank.wait_for_vblank(); vblank.wait_for_vblank();
if let Some(ref mut mixer) = mixer {
mixer.after_vblank();
}
for y in 0..20u16 { for y in 0..20u16 {
for x in 0..30u16 { for x in 0..30u16 {
map.set_tile( map.set_tile(
@ -63,10 +59,6 @@ pub fn show_splash_screen(
} }
vblank.wait_for_vblank(); vblank.wait_for_vblank();
if let Some(ref mut mixer) = mixer {
mixer.after_vblank();
}
} }
map.commit(vram); map.commit(vram);
@ -83,17 +75,13 @@ pub fn show_splash_screen(
) { ) {
break; break;
} }
if let Some(ref mut mixer) = mixer { if let Some(mixer) = &mut mixer {
if let Some(ref mut music_box) = music_box { if let Some(music_box) = &mut music_box {
music_box.before_frame(mixer); music_box.before_frame(mixer);
} }
mixer.frame(); mixer.frame();
} }
vblank.wait_for_vblank(); vblank.wait_for_vblank();
if let Some(ref mut mixer) = mixer {
mixer.after_vblank();
}
} }
map.hide(); map.hide();

View file

@ -85,7 +85,6 @@ impl<'a> Level<'a> {
let mut between_updates = || { let mut between_updates = || {
sfx.frame(); sfx.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
sfx.after_vblank();
}; };
backdrop.init(vram, start_pos, &mut between_updates); backdrop.init(vram, start_pos, &mut between_updates);
@ -2283,7 +2282,6 @@ fn game_with_level(gba: &mut agb::Gba) {
start_at_boss = loop { start_at_boss = loop {
sfx.frame(); sfx.frame();
vblank.wait_for_vblank(); vblank.wait_for_vblank();
sfx.after_vblank();
object.commit(); object.commit();
match game.advance_frame(&object, &mut vram, &mut sfx) { match game.advance_frame(&object, &mut vram, &mut sfx) {
GameStatus::Continue => {} GameStatus::Continue => {}

View file

@ -39,10 +39,6 @@ impl<'a> Sfx<'a> {
self.mixer.frame(); self.mixer.frame();
} }
pub fn after_vblank(&mut self) {
self.mixer.after_vblank();
}
pub fn stop_music(&mut self) { pub fn stop_music(&mut self) {
if let Some(bgm) = &self.bgm { if let Some(bgm) = &self.bgm {
let channel = self.mixer.channel(bgm).unwrap(); let channel = self.mixer.channel(bgm).unwrap();