moved things around, still ongoing

This commit is contained in:
Aaro Koivukangas
2026-04-15 10:39:28 +03:00
parent 5eac60973a
commit b43278ab06
14 changed files with 320 additions and 170 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
#![no_std]
#![no_main]
mod vga_buffer;
static HELLO: &[u8] = b"Hello World!";
#[unsafe(no_mangle)]
@@ -12,9 +14,9 @@ pub extern "C" fn _start() -> ! {
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
}
}
loop {}
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
+67
View File
@@ -0,0 +1,67 @@
#[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)]
#[repr(transparent)]
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 TerminalChar {
ascii_char: u8,
color_code: ColorCode,
}
const BUFFER_HEIGHT: usize = 25;
const BUFFER_WIDTH: usize = 80;
#[repr(transparent)]
struct Buffer {
chars: [[TerminalChar; BUFFER_WIDTH]; BUFFER_HEIGHT],
}
pub struct Writer {
column_position: usize,
color_code: ColorCode,
buffer: &'static mut Buffer,
}
impl Writer {
fn write_byte(&mut self, data: u8) {
if self.column_position + 1 < BUFFER_WIDTH {
let terminal_char = TerminalChar {
ascii_char: data,
color_code: self.color_code,
};
self.buffer.chars[BUFFER_HEIGHT - 1][self.column_position + 1] = terminal_char;
self.column_position += 1;
}
}
}
pub fn write_string(data: &str) {}