added a static Writer to reuse in the program

This commit is contained in:
clizia 2025-08-26 23:44:17 +02:00
parent 2bd6ba35fc
commit daec1c75bf
3 changed files with 40 additions and 17 deletions

View file

@ -17,3 +17,8 @@ panic = "abort" # disable stack unwinding on panic
[dependencies]
bootloader = "0.9"
volatile = "0.2.6"
spin = "0.5.2"
[dependencies.lazy_static]
version = "1.0"
features = ["spin_no_std"]

View file

@ -11,8 +11,10 @@ static HELLO: &[u8] = b"Hello toto :3";
// looks for a function named `_start` by default
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
vga_buffer::print_something();
use core::fmt::Write;
vga_buffer::WRITER.lock().write_str("TOTOTO !!!! :3").unwrap();
write!(vga_buffer::WRITER.lock(), ", smoking cigarette in the shower when they get wet i just light another :{}", 3).unwrap();
loop {}
}

View file

@ -1,5 +1,15 @@
use core::fmt;
use volatile::Volatile;
use lazy_static::lazy_static;
use spin::Mutex;
lazy_static! {
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
column_position: 0,
color_code: ColorCode::new(Color::Pink, Color::Black),
buffer: unsafe { &mut *(0xB8000 as *mut Buffer) },
});
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -103,20 +113,26 @@ impl Writer {
}
fn new_line(&mut self) {
todo!()
for row in 1..BUFFER_HEIGHT {
for col in 0..BUFFER_WIDTH {
let character = self.buffer.chars[row][col].read();
self.buffer.chars[row - 1][col].write(character);
}
}
self.clear_row(BUFFER_HEIGHT - 1);
self.column_position = 0;
}
// this method clears a row by overwriting all of its
// characters with a space character.
fn clear_row(&mut self, row: usize) {
let blank = ScreenChar {
ascii_carachter: b' ',
color_code: self.color_code,
};
for col in 0..BUFFER_WIDTH {
self.buffer.chars[row][col].write(blank);
}
}
}
// function to test things: to be removed
pub fn print_something() {
use core::fmt::Write;
let mut writer = Writer {
column_position: 0,
color_code: ColorCode::new(Color::Pink, Color::Black),
buffer: unsafe { &mut *(0xB8000 as *mut Buffer) },
};
writer.write_byte(b'H');
writer.write_string("ello ");
write!(writer, "The numbers are {} and {}", 42, 1.0/3.0).unwrap();
}