From 9aae1d6f72228b17407a988a81d70b5bc64407aa Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 31 Oct 2019 23:03:27 +0100 Subject: Fix handling of u8 vs usize Those types can't be casted into each other which caused several compilation errors. --- kernel/src/io/vga_text.rs | 12 ++++++------ kernel/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs index b6715fd..34f13a8 100644 --- a/kernel/src/io/vga_text.rs +++ b/kernel/src/io/vga_text.rs @@ -30,7 +30,7 @@ impl CharState { } pub fn set_fg(&mut self, fg: Color) { - self.0 = (self.0 & HEIGHT - 10) | (fg as u8) + self.0 = (self.0 & (HEIGHT as u8) - 10) | (fg as u8) } pub fn set_bg(&mut self, bg: Color) { @@ -52,7 +52,7 @@ impl VgaChar { } pub struct OStream { - pos: (u8, u8), + pos: (usize, usize), cursor: *mut VgaChar, state: CharState, } @@ -74,16 +74,16 @@ impl OStream { self.cursor = Self::at(self.pos.0 as usize + self.pos.1 as usize * WIDTH) } - pub fn set_col(&mut self, col: u8) { + pub fn set_col(&mut self, col: usize) { self.pos.0 = core::cmp::min(col, WIDTH - 1); self.compute_cursor() } - pub fn set_row(&mut self, row: u8) { + pub fn set_row(&mut self, row: usize) { self.pos.1 = core::cmp::min(row, HEIGHT - 1); self.compute_cursor() } - pub fn set_cursor(&mut self, col: u8, row: u8) { + pub fn set_cursor(&mut self, col: usize, row: usize) { self.pos = ( core::cmp::min(col, WIDTH - 1), core::cmp::min(row, HEIGHT - 1), @@ -155,7 +155,7 @@ impl OStream { if b != b'\n' { n += 1 } - self.set_col(((WIDTH - n) / 2) as u8); + self.set_col(((WIDTH - n) / 2) as usize); self.print(&line[..n]); self.new_line(); if i == slast { diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 8d8ec17..4e51d22 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -6,6 +6,7 @@ extern crate compiler_builtins; mod io; +use io::vga_text; use core::fmt::Write; #[no_mangle] -- cgit v1.2.3-70-g09d2