Bump edition to now stable 2024 edition (shiny!).

This commit is contained in:
2025-02-23 11:52:54 +00:00
parent 9f83c5f295
commit b8aa203c05
14 changed files with 214 additions and 171 deletions
+35 -29
View File
@@ -3,7 +3,7 @@ use spin::{Lazy, Mutex};
use x86_64::instructions::interrupts;
pub use super::framebuffer::screensize_px;
use super::framebuffer::{Color, FRAMEBUFFER_WRITER};
use super::framebuffer::{Colour, FRAMEBUFFER_WRITER};
mod font;
use font::FONT;
@@ -28,32 +28,39 @@ pub struct Writer {
/// 8 pixels wide.
text_col: u32,
fg_color: Color,
bg_color: Color,
fg_color: Colour,
bg_color: Colour,
offset1: usize,
offset2: usize,
}
impl Default for Writer {
fn default() -> Self {
Self::new()
}
}
impl Writer {
pub fn new() -> Self {
if let Some(writer) = FRAMEBUFFER_WRITER.lock().as_mut() {
Self {
screen_width: writer.width() as u32 / 8,
screen_height: writer.height() as u32 / 16,
FRAMEBUFFER_WRITER.lock().as_mut().map_or_else(
|| {
panic!("Framebuffer writer not initialized.");
},
|writer| Self {
screen_width: writer.width() / 8,
screen_height: writer.height() / 16,
text_line: 0,
text_col: 0,
fg_color: Color::White,
bg_color: Color::Black,
fg_color: Colour::White,
bg_color: Colour::Black,
offset1: 16,
offset2: 0,
}
} else {
panic!("Framebuffer writer not initialized");
}
},
)
}
pub fn write_char(&mut self, c: u16) {
pub fn write_glyph(&mut self, c: u16) {
if c as u8 == b'\n' {
self.newline();
return;
@@ -63,8 +70,7 @@ impl Writer {
let data: &[u8] = &FONT[c as usize * 16..(c as usize + 1) * 16];
if let Some(writer) = FRAMEBUFFER_WRITER.lock().as_mut() {
for row in 0..16 {
let line: u8 = data[row];
for (row, line) in data.iter().enumerate().take(16) {
for col in 0..8 {
let pixel_x: u32 = self.text_col * FONT_WIDTH + col;
let pixel_y: u32 = self.text_line * FONT_HEIGHT + row as u32;
@@ -88,20 +94,20 @@ impl Writer {
}
}
pub fn set_offset(&mut self, offset1: usize, offset2: usize) {
pub const fn set_offset(&mut self, offset1: usize, offset2: usize) {
self.offset1 = offset1;
self.offset2 = offset2;
}
pub fn dimensions(&self) -> (u32, u32) {
pub const fn dimensions(&self) -> (u32, u32) {
(self.screen_width, self.screen_height)
}
pub fn next_char(&mut self) {
pub const fn next_char(&mut self) {
self.text_col += 1;
}
pub fn newline(&mut self) {
pub const fn newline(&mut self) {
self.text_col = 0;
if self.text_line + 1 >= self.screen_height {
@@ -113,18 +119,18 @@ impl Writer {
pub fn write_string(&mut self, s: &str) {
for c in s.chars() {
self.write_char(c as u16);
self.write_glyph(c as u16);
}
}
pub fn set_colour(&mut self, fg: Color, bg: Color) {
pub const fn set_colour(&mut self, fg: Colour, bg: Colour) {
self.fg_color = fg;
self.bg_color = bg;
}
pub fn reset_colour(&mut self) {
self.fg_color = Color::White;
self.bg_color = Color::Black;
pub const fn reset_colour(&mut self) {
self.fg_color = Colour::White;
self.bg_color = Colour::Black;
}
}
@@ -135,7 +141,7 @@ impl core::fmt::Write for Writer {
}
}
fn write(args: fmt::Arguments, fg: Color, bg: Color) {
fn write(args: fmt::Arguments, fg: Colour, bg: Colour) {
use core::fmt::Write;
interrupts::without_interrupts(|| {
@@ -148,19 +154,19 @@ fn write(args: fmt::Arguments, fg: Color, bg: Color) {
pub fn _print(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
write(args, Color::White, Color::Black);
write(args, Colour::White, Colour::Black);
})
}
pub fn _print_err(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
write(args, Color::Red, Color::Black);
write(args, Colour::Red, Colour::Black);
})
}
pub fn _print_log(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
write(args, Color::Yellow, Color::Black);
write(args, Colour::Yellow, Colour::Black);
})
}