From 788afa49d4044d22fe6ec51b8e12917ebc481015 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 22 Feb 2023 10:09:32 +1100 Subject: [PATCH] fix serial --- src/processor/memory/mmio/serial.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/processor/memory/mmio/serial.rs b/src/processor/memory/mmio/serial.rs index 606f2f2..1fe785e 100644 --- a/src/processor/memory/mmio/serial.rs +++ b/src/processor/memory/mmio/serial.rs @@ -32,7 +32,8 @@ impl Default for SerialControl { pub struct Serial { byte: u8, - bits_transferred: u8, + output_byte: u8, + bits_remaining: u8, control: SerialControl, } @@ -41,11 +42,13 @@ impl Serial { let mut will_interrupt = false; for _ in 0..steps { if self.control.transfer_in_progress { - let (remainder, finished) = self.bits_transferred.overflowing_sub(1); - self.bits_transferred = if finished { + self.output_byte = self.output_byte << 1 | self.byte >> 7; + self.byte = (self.byte << 1) | 0b1; + let (remainder, finished) = self.bits_remaining.overflowing_sub(1); + self.bits_remaining = if finished { self.control.transfer_in_progress = false; will_interrupt = true; - print!("{}", self.byte as char); + print!("{}", self.output_byte as char); stdout().flush().unwrap(); 7 } else { @@ -91,8 +94,9 @@ impl Serial { impl Default for Serial { fn default() -> Self { Self { - byte: 0, - bits_transferred: 7, + byte: 0xFF, + output_byte: 0, + bits_remaining: 7, control: SerialControl::default(), } }