From 83f6ffab56369d1524c3c046a9f5151587e67f54 Mon Sep 17 00:00:00 2001 From: lif <> Date: Sun, 14 Jan 2024 00:00:45 -0800 Subject: [PATCH] fix timing and support END_TICKs now that lsdpack is emitting them at all --- src/main.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6ce0466..a46a0ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,21 +252,28 @@ impl Lsdpack { self.repeat_cmd = None; } } - let cmd = self.load_new_cmd_from_stream(); - ongoing = self.apply_cmd(cmd); + let (cmd, flagged_ongoing) = self.load_new_cmd_from_stream(); + ongoing = flagged_ongoing; + ongoing &= self.apply_cmd(cmd); } } #[link_section = ".iwram"] - fn load_new_cmd_from_stream(&mut self) -> LsdpackCmd { - let cmd = self.next_byte(); - if cmd & 0x40 != 0 { - self.repeat_cmd = Some((cmd & 0x3f).into()); - self.repeat_cmd_counter = self.next_byte() as usize; - self.repeat_cmd.unwrap() - } else { - cmd.into() + fn load_new_cmd_from_stream(&mut self) -> (LsdpackCmd, bool) { + const FLAG_REPEAT: u8 = 0x40; + const FLAG_END_TICK: u8 = 0x80; + let mut cmd = self.next_byte(); + let mut ongoing = true; + if cmd & FLAG_END_TICK != 0 { + cmd &= !FLAG_END_TICK; + 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"] @@ -418,12 +425,13 @@ extern "C" fn main() -> ! { IE.write(IrqBits::VBLANK.with_timer0(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( TimerControl::new() .with_overflow_irq(true) .with_cascade(false) - .with_scale(TimerScale::_256) + .with_scale(TimerScale::_1) .with_enabled(true), );