From 7044c08100c27e766699a212b766d7f4b2b0a3df Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 20 Apr 2024 00:07:42 +0100 Subject: [PATCH] large logs get split into multiple prints --- agb/src/mgba.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/agb/src/mgba.rs b/agb/src/mgba.rs index 348df783..9d3aa1fb 100644 --- a/agb/src/mgba.rs +++ b/agb/src/mgba.rs @@ -32,15 +32,13 @@ pub(crate) fn test_runner_measure_cycles() { NUMBER_OF_CYCLES.set(0); } -pub struct Mgba { - bytes_written: usize, -} +pub struct Mgba {} impl Mgba { #[must_use] pub fn new() -> Option { if is_running_in_mgba() { - Some(Mgba { bytes_written: 0 }) + Some(Mgba {}) } else { None } @@ -51,30 +49,32 @@ impl Mgba { output: core::fmt::Arguments, level: DebugLevel, ) -> Result<(), core::fmt::Error> { - write!(self, "{output}")?; + let mut writer = MgbaWriter { bytes_written: 0 }; + write!(&mut writer, "{output}")?; self.set_level(level); Ok(()) } } +struct MgbaWriter { + bytes_written: usize, +} + impl Mgba { pub fn set_level(&mut self, level: DebugLevel) { DEBUG_LEVEL.set(DEBUG_FLAG_CODE | level as u16); - self.bytes_written = 0; } } -impl core::fmt::Write for Mgba { +impl core::fmt::Write for MgbaWriter { fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> { - let mut str_iter = s.bytes(); - while self.bytes_written < 255 { - match str_iter.next() { - Some(byte) => { - OUTPUT_STRING.set(self.bytes_written, byte); - self.bytes_written += 1; - } - None => return Ok(()), + for b in s.bytes() { + if self.bytes_written > 255 { + DEBUG_LEVEL.set(DEBUG_FLAG_CODE | DebugLevel::Info as u16); + self.bytes_written = 0; } + OUTPUT_STRING.set(self.bytes_written, b); + self.bytes_written += 1; } Ok(()) }