Skip to content

Commit

Permalink
Rename some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc committed Oct 15, 2024
1 parent 7660af0 commit a34cfa2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/sys/vga/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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);
write_font(&font);
Ok(buf.len()) // TODO: Use font.data.len() ?
} else {
Err(())
Expand All @@ -43,14 +43,14 @@ impl FileIO for VgaFont {
}
}

pub fn set_font(font: &Font) {
fn write_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);
write_font(font);
}
}
2 changes: 1 addition & 1 deletion src/sys/vga/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn init() {
set_attr_ctrl_reg(0xE, 0x3E);
set_attr_ctrl_reg(0xF, 0x3F);

Palette::default().set();
Palette::default().write();

disable_blinking();
disable_underline();
Expand Down
22 changes: 10 additions & 12 deletions src/sys/vga/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ impl Palette {
palette
}

pub fn get() -> Self {
pub fn read() -> Self {
let mut palette = Palette::new();
for i in 0..256 {
palette.colors[i] = get_palette(i);
palette.colors[i] = read_palette(i);
}
palette
}

pub fn set(&self) {
pub fn write(&self) {
for (i, (r, g, b)) in self.colors.iter().enumerate() {
set_palette(i, *r, *g, *b);
write_palette(i, *r, *g, *b);
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl TryFrom<&[u8]> for Palette {

impl FileIO for VgaPalette {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, ()> {
let res = Palette::get().to_bytes();
let res = Palette::read().to_bytes();
if buf.len() < res.len() {
return Err(());
}
Expand All @@ -102,7 +102,7 @@ impl FileIO for VgaPalette {

fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
let palette = Palette::try_from(buf)?;
palette.set();
palette.write();
Ok(buf.len())
}

Expand All @@ -116,26 +116,24 @@ impl FileIO for VgaPalette {
}
}

// TODO: Rename to `write_palette_index`
fn set_palette(i: usize, r: u8, g: u8, b: u8) {
fn write_palette(i: usize, r: u8, g: u8, b: u8) {
interrupts::without_interrupts(||
WRITER.lock().set_palette(i, r, g, b)
)
}

// TODO: Rename to `read_palette_index`
fn get_palette(i: usize) -> (u8, u8, u8) {
fn read_palette(i: usize) -> (u8, u8, u8) {
interrupts::without_interrupts(||
WRITER.lock().palette(i)
)
}

pub fn restore_palette() {
if let Some(ref palette) = *PALETTE.lock() {
palette.set();
palette.write();
}
}

pub fn backup_palette() {
*PALETTE.lock() = Some(Palette::get())
*PALETTE.lock() = Some(Palette::read())
}

0 comments on commit a34cfa2

Please sign in to comment.