Skip to content

Commit

Permalink
Restore font after mode change
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Oct 14, 2024
1 parent 6f7096d commit c5294e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/api/vga/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion src/sys/vga/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -22,6 +23,7 @@ impl FileIO for VgaFont {

fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
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 {
Expand All @@ -39,9 +41,16 @@ impl FileIO for VgaFont {
}
}

// TODO: Remove this
static FONT: Mutex<Option<Font>> = 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);
}
}
1 change: 1 addition & 0 deletions src/sys/vga/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit c5294e8

Please sign in to comment.