mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
45 lines
857 B
Rust
45 lines
857 B
Rust
#[allow(dead_code)]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
#[repr(u8)]
|
|
pub enum Color {
|
|
Black = 0,
|
|
Blue = 1,
|
|
Green = 2,
|
|
Cyan = 3,
|
|
Red = 4,
|
|
Magenta = 5,
|
|
Brown = 6,
|
|
LightGray = 7,
|
|
DarkGray = 8,
|
|
LightBlue = 9,
|
|
LightGreen = 10,
|
|
LightCyan = 11,
|
|
LightRed = 12,
|
|
Pink = 13,
|
|
Yellow = 14,
|
|
White = 15,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
struct ColorCode(u8);
|
|
|
|
impl ColorCode {
|
|
fn new(foreground: Color, background: Color) -> ColorCode {
|
|
ColorCode((background as u8) << 4 | (foreground as u8))
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
#[repr(C)]
|
|
struct ScreenChar {
|
|
ascii_character: u8,
|
|
color_code: ColorCode,
|
|
}
|
|
|
|
const BUFFER_HEIGHT: usize = 25;
|
|
const BUFFER_WIDTH: usize = 80;
|
|
|
|
struct Buffer {
|
|
chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
|
}
|