diff --git a/src/devices/graphical_debug/debug.rs b/src/devices/graphical_debug/debug.rs index 93f115d625..5350879a7c 100644 --- a/src/devices/graphical_debug/debug.rs +++ b/src/devices/graphical_debug/debug.rs @@ -1,5 +1,9 @@ +use core::{cmp, ptr}; + use super::Display; +static FONT: &[u8] = include_bytes!("../../../res/unifont.font"); + pub struct DebugDisplay { pub(crate) display: Display, x: usize, @@ -31,7 +35,7 @@ impl DebugDisplay { let new_y = self.h - 1; let d_y = self.y - new_y; - self.display.scroll(d_y * 16); + self.scroll(d_y * 16); unsafe { self.display @@ -42,7 +46,7 @@ impl DebugDisplay { } if c != '\n' { - self.display.char(self.x * 8, self.y * 16, c, 0xFFFFFF); + self.char(self.x * 8, self.y * 16, c, 0xFFFFFF); unsafe { self.display.sync(self.x * 8, self.y * 16, 8, 16); @@ -57,4 +61,38 @@ impl DebugDisplay { self.write_char(b as char); } } + + /// Draw a character + pub fn char(&mut self, x: usize, y: usize, character: char, color: u32) { + if x + 8 <= self.display.width && y + 16 <= self.display.height { + let mut dst = + self.display.data_mut().as_mut_ptr() as usize + (y * self.display.stride + x) * 4; + + let font_i = 16 * (character as usize); + if font_i + 16 <= FONT.len() { + for row in 0..16 { + let row_data = FONT[font_i + row]; + for col in 0..8 { + if (row_data >> (7 - col)) & 1 == 1 { + unsafe { + *((dst + col * 4) as *mut u32) = color; + } + } + } + dst += self.display.stride * 4; + } + } + } + } + + /// Scroll the screen + pub fn scroll(&mut self, lines: usize) { + let offset = cmp::min(self.display.height, lines) * self.display.stride; + let size = (self.display.stride * self.display.height) - offset; + unsafe { + let ptr = self.display.data_mut().as_mut_ptr(); + ptr::copy(ptr.add(offset), ptr, size); + ptr::write_bytes(ptr.add(size), 0, offset); + } + } } diff --git a/src/devices/graphical_debug/display.rs b/src/devices/graphical_debug/display.rs index 2997f4453d..6ed3cad17e 100644 --- a/src/devices/graphical_debug/display.rs +++ b/src/devices/graphical_debug/display.rs @@ -1,7 +1,5 @@ use alloc::boxed::Box; -use core::{cmp, ptr, slice}; - -use super::FONT; +use core::{ptr, slice}; /// A display pub struct Display { @@ -35,39 +33,6 @@ impl Display { } } - /// Draw a character - pub fn char(&mut self, x: usize, y: usize, character: char, color: u32) { - if x + 8 <= self.width && y + 16 <= self.height { - let mut dst = self.data_mut().as_mut_ptr() as usize + (y * self.stride + x) * 4; - - let font_i = 16 * (character as usize); - if font_i + 16 <= FONT.len() { - for row in 0..16 { - let row_data = FONT[font_i + row]; - for col in 0..8 { - if (row_data >> (7 - col)) & 1 == 1 { - unsafe { - *((dst + col * 4) as *mut u32) = color; - } - } - } - dst += self.stride * 4; - } - } - } - } - - /// Scroll the screen - pub fn scroll(&mut self, lines: usize) { - let offset = cmp::min(self.height, lines) * self.stride; - let size = (self.stride * self.height) - offset; - unsafe { - let ptr = self.data_mut().as_mut_ptr(); - ptr::copy(ptr.add(offset), ptr, size); - ptr::write_bytes(ptr.add(size), 0, offset); - } - } - /// Sync from offscreen to onscreen, unsafe because it trusts provided x, y, w, h pub unsafe fn sync(&mut self, x: usize, y: usize, w: usize, mut h: usize) { if let Some(offscreen) = &self.offscreen { diff --git a/src/devices/graphical_debug/mod.rs b/src/devices/graphical_debug/mod.rs index e3cfb62484..19003bf95f 100644 --- a/src/devices/graphical_debug/mod.rs +++ b/src/devices/graphical_debug/mod.rs @@ -7,8 +7,6 @@ use self::display::Display; pub mod debug; pub mod display; -pub static FONT: &[u8] = include_bytes!("../../../res/unifont.font"); - pub static DEBUG_DISPLAY: Mutex> = Mutex::new(None); pub static FRAMEBUFFER: Mutex<(usize, usize, usize)> = Mutex::new((0, 0, 0));