fix timing and support END_TICKs now that lsdpack is emitting them at all

This commit is contained in:
lif 2024-01-14 00:00:45 -08:00
parent c22c9bcbd8
commit 83f6ffab56

View file

@ -252,21 +252,28 @@ impl Lsdpack {
self.repeat_cmd = None; self.repeat_cmd = None;
} }
} }
let cmd = self.load_new_cmd_from_stream(); let (cmd, flagged_ongoing) = self.load_new_cmd_from_stream();
ongoing = self.apply_cmd(cmd); ongoing = flagged_ongoing;
ongoing &= self.apply_cmd(cmd);
} }
} }
#[link_section = ".iwram"] #[link_section = ".iwram"]
fn load_new_cmd_from_stream(&mut self) -> LsdpackCmd { fn load_new_cmd_from_stream(&mut self) -> (LsdpackCmd, bool) {
let cmd = self.next_byte(); const FLAG_REPEAT: u8 = 0x40;
if cmd & 0x40 != 0 { const FLAG_END_TICK: u8 = 0x80;
self.repeat_cmd = Some((cmd & 0x3f).into()); let mut cmd = self.next_byte();
self.repeat_cmd_counter = self.next_byte() as usize; let mut ongoing = true;
self.repeat_cmd.unwrap() if cmd & FLAG_END_TICK != 0 {
} else { cmd &= !FLAG_END_TICK;
cmd.into() ongoing = false;
} }
if cmd & FLAG_REPEAT != 0 {
cmd &= !FLAG_REPEAT;
self.repeat_cmd = Some(cmd.into());
self.repeat_cmd_counter = self.next_byte() as usize;
}
(cmd.into(), ongoing)
} }
#[link_section = ".iwram"] #[link_section = ".iwram"]
@ -418,12 +425,13 @@ extern "C" fn main() -> ! {
IE.write(IrqBits::VBLANK.with_timer0(true)); IE.write(IrqBits::VBLANK.with_timer0(true));
IME.write(true); IME.write(true);
TIMER0_RELOAD.write((((16777216 / 256) / 6) as u16).wrapping_neg()); //TIMER0_RELOAD.write((((16777216 / 1) / 360) as u16).wrapping_neg());
TIMER0_RELOAD.write((((280896 / 1) / 6) as u16).wrapping_neg());
TIMER0_CONTROL.write( TIMER0_CONTROL.write(
TimerControl::new() TimerControl::new()
.with_overflow_irq(true) .with_overflow_irq(true)
.with_cascade(false) .with_cascade(false)
.with_scale(TimerScale::_256) .with_scale(TimerScale::_1)
.with_enabled(true), .with_enabled(true),
); );