From 198ced9cb6b841624abbb144a41901954c9d4839 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 16 Mar 2023 11:04:44 +1100 Subject: [PATCH] serial waits for ime --- gb-vst/src/lib.rs | 2 -- lib/src/processor/memory.rs | 2 +- lib/src/processor/memory/mmio/serial.rs | 11 +++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gb-vst/src/lib.rs b/gb-vst/src/lib.rs index e25a38d..782c64c 100644 --- a/gb-vst/src/lib.rs +++ b/gb-vst/src/lib.rs @@ -124,7 +124,6 @@ impl Plugin for GameboyEmu { velocity: _, } => { if channel < 5 { - println!("noteon: {as_bytes:#?}"); vars.serial_tx.send(0x90 + channel).unwrap(); vars.serial_tx.send(as_bytes[1]).unwrap(); vars.serial_tx.send(as_bytes[2]).unwrap(); @@ -138,7 +137,6 @@ impl Plugin for GameboyEmu { velocity: _, } => { if channel < 5 { - println!("noteoff: {as_bytes:#?}"); vars.serial_tx.send(0x80 + channel).unwrap(); vars.serial_tx.send(as_bytes[1]).unwrap(); vars.serial_tx.send(as_bytes[2]).unwrap(); diff --git a/lib/src/processor/memory.rs b/lib/src/processor/memory.rs index 2090ca1..b9e1a8b 100644 --- a/lib/src/processor/memory.rs +++ b/lib/src/processor/memory.rs @@ -314,7 +314,7 @@ impl + Clone> Cpu { self.memory.apu.tick(steps); - let serial_interrupt = self.memory.serial.tick(steps); + let serial_interrupt = self.memory.serial.tick(steps, self.memory.ime); self.memory .interrupts .set_interrupt(Interrupt::Serial, serial_interrupt); diff --git a/lib/src/processor/memory/mmio/serial.rs b/lib/src/processor/memory/mmio/serial.rs index 1e73062..a5407b9 100644 --- a/lib/src/processor/memory/mmio/serial.rs +++ b/lib/src/processor/memory/mmio/serial.rs @@ -57,7 +57,7 @@ struct InputByte { input_delay: usize, } -const BYTE_DELAY: usize = 20000; +const BYTE_DELAY: usize = 2000; impl InputByte { fn advance(&mut self, rx: &Option>) -> u8 { @@ -154,7 +154,7 @@ impl Serial { !matches!(&self.target, SerialTarget::None) } - pub fn tick(&mut self, steps: usize) -> bool { + pub fn tick(&mut self, steps: usize, ime: bool) -> bool { let mut will_interrupt = false; if !self.is_connected() { return false; @@ -165,11 +165,14 @@ impl Serial { &None }; for _ in 0..steps { - self.input_byte.input_delay = self.input_byte.input_delay.saturating_sub(1); + if ime { + self.input_byte.input_delay = self.input_byte.input_delay.saturating_sub(1); + } if (self.control.transfer_in_progress && self.control.clock_source == ClockSource::Internal) || (self.control.clock_source == ClockSource::External - && self.input_byte.is_ready(rx)) + && self.input_byte.is_ready(rx) + && ime) { self.output_byte = self.output_byte << 1 | self.byte >> 7; self.byte = (self.byte << 1) | self.input_byte.advance(rx);