diff --git a/boy-debug/src/bus.rs b/boy-debug/src/bus.rs index 1d826f5..5be8975 100644 --- a/boy-debug/src/bus.rs +++ b/boy-debug/src/bus.rs @@ -1,6 +1,6 @@ //! A dummied out implementation of a Bus, which is filled entirely with RAM -use std::{borrow::Cow, io::Result as IoResult, path::Path}; +use std::{io::Result as IoResult, path::Path}; use boy::memory::io::BusIO; @@ -21,11 +21,7 @@ impl BusIOTools for T { } fn ascii(&mut self) -> AsciiSerial { - AsciiSerial { - data: 0, - buf: vec![], - bus: self, - } + AsciiSerial { data: 0, buf: String::new(), bus: self } } fn read_file(&mut self, path: impl AsRef) -> IoResult<&mut Self> { @@ -81,17 +77,10 @@ impl<'t, T: BusIO + AsMut<[u8]>> AsMut<[u8]> for TracingBus<'t, T> { /// Implements a hacky serial port for extracting data pub struct AsciiSerial<'t, T: BusIO + ?Sized> { data: u8, - buf: Vec, + buf: String, bus: &'t mut T, } -impl<'t, T: BusIO + ?Sized> AsciiSerial<'t, T> { - /// Gets the contents of the data buffer - pub fn string(&self) -> Cow { - String::from_utf8_lossy(&self.buf) - } -} - impl<'t, T: BusIO + ?Sized> BusIO for AsciiSerial<'t, T> { fn read(&self, addr: usize) -> Option { match addr { @@ -104,13 +93,16 @@ impl<'t, T: BusIO + ?Sized> BusIO for AsciiSerial<'t, T> { fn write(&mut self, addr: usize, data: u8) -> Option<()> { match addr { 0xff01 => { - // eprintln!("'{data:02x}'"); - self.buf.push(data); + self.data = data; } 0xff02 => { if data & 0x80 != 0 { - // eprintln!("SERIAL => {:02x}", self.data); - eprintln!("tx: {data:02x}, buf: {:02x?}", self.buf); + if self.data == b'\n' { + println!("dbg> \x1b[1m{}\x1b[0m", self.buf); + self.buf.clear(); + } else { + self.buf.push(self.data as char); + } let interrupt = self.bus.read(0xff0f)? | (1 << 3); self.bus.write(0xff0f, interrupt)?; } @@ -121,8 +113,6 @@ impl<'t, T: BusIO + ?Sized> BusIO for AsciiSerial<'t, T> { } fn diag(&mut self, param: usize) { - println!("debug: '{}'", self.string()); - self.buf.clear(); self.bus.diag(param) } }