Skip to content

Commit bdff7ab

Browse files
committed
Add palette backup and restore
1 parent 734fee7 commit bdff7ab

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/api/vga/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
use crate::api::fs;
2-
use crate::usr::shell;
32

43
pub fn graphic_mode() {
54
fs::write("/dev/vga/mode", b"320x200").ok();
6-
7-
// TODO: Backup palette
85
}
96

107
pub fn text_mode() {
118
fs::write("/dev/vga/mode", b"80x25").ok();
12-
13-
// TODO: Restore and palette backup instead of this
14-
shell::exec("shell /ini/palettes/gruvbox-dark.sh").ok();
15-
169
print!("\x1b[2J\x1b[1;1H"); // Clear screen and move to top
1710
}

src/sys/vga/palette.rs

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use super::*;
33
use crate::api::fs::{FileIO, IO};
44

55
use core::convert::TryFrom;
6+
use spin::Mutex;
7+
8+
static PALETTE: Mutex<Option<Palette>> = Mutex::new(None);
69

710
const DEFAULT_COLORS: [(u8, u8, u8); 16] = [
811
(0x00, 0x00, 0x00), // DarkBlack
@@ -126,3 +129,13 @@ fn get_palette(i: usize) -> (u8, u8, u8) {
126129
WRITER.lock().palette(i)
127130
)
128131
}
132+
133+
pub fn restore_palette() {
134+
if let Some(ref palette) = *PALETTE.lock() {
135+
palette.set();
136+
}
137+
}
138+
139+
pub fn backup_palette() {
140+
*PALETTE.lock() = Some(Palette::get())
141+
}

src/sys/vga/screen.rs

+5
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ pub fn set_80x25_mode() {
126126
disable_blinking();
127127
disable_underline();
128128
font::restore_font();
129+
palette::restore_palette();
129130
}
130131

131132
pub fn set_320x200_mode() {
133+
// NOTE: Setting a graphic mode twice without going back to text mode will
134+
// overwrite the backup palette.
135+
palette::backup_palette();
132136
set_mode(&G_320_200_256);
133137
// TODO: Clear screen
134138
}
135139

136140
pub fn set_640x480_mode() {
141+
palette::backup_palette();
137142
set_mode(&G_640_480_16);
138143
// TODO: Clear screen
139144
}

0 commit comments

Comments
 (0)