diff --git a/src/api/vga/mod.rs b/src/api/vga/mod.rs index 7c575482..da184154 100644 --- a/src/api/vga/mod.rs +++ b/src/api/vga/mod.rs @@ -10,15 +10,14 @@ use crate::usr::shell; pub fn graphic_mode() { fs::write("/dev/vga/mode", b"320x200").ok(); - // TODO: Backup font and palette + // TODO: Backup palette } pub fn text_mode() { fs::write("/dev/vga/mode", b"80x25").ok(); - // TODO: Restore font and palette backup instead of this + // TODO: Restore and palette backup instead of this shell::exec("shell /ini/palettes/gruvbox-dark.sh").ok(); - shell::exec("read /ini/fonts/zap-light-8x16.psf => /dev/vga/font").ok(); print!("\x1b[2J\x1b[1;1H"); // Clear screen and move to top } diff --git a/src/sys/vga/font.rs b/src/sys/vga/font.rs index 2e6710de..f35c6eb1 100644 --- a/src/sys/vga/font.rs +++ b/src/sys/vga/font.rs @@ -4,6 +4,7 @@ use crate::api::font::Font; use crate::api::fs::{FileIO, IO}; use core::convert::TryFrom; +use spin::Mutex; use x86_64::instructions::interrupts; #[derive(Debug, Clone)] @@ -22,6 +23,7 @@ impl FileIO for VgaFont { fn write(&mut self, buf: &[u8]) -> Result { if let Ok(font) = Font::try_from(buf) { + *FONT.lock() = Some(font.clone()); set_font(&font); Ok(buf.len()) // TODO: Use font.data.len() ? } else { @@ -39,9 +41,16 @@ impl FileIO for VgaFont { } } -// TODO: Remove this +static FONT: Mutex> = Mutex::new(None); + pub fn set_font(font: &Font) { interrupts::without_interrupts(|| WRITER.lock().set_font(font) ) } + +pub fn restore_font() { + if let Some(ref font) = *FONT.lock() { + set_font(font); + } +} diff --git a/src/sys/vga/screen.rs b/src/sys/vga/screen.rs index f09ef823..88e2f371 100644 --- a/src/sys/vga/screen.rs +++ b/src/sys/vga/screen.rs @@ -125,6 +125,7 @@ pub fn set_80x25_mode() { set_mode(&T_80_25); disable_blinking(); disable_underline(); + font::restore_font(); } pub fn set_320x200_mode() {