From 1e278eebe3328163bc1f6f9f57874e4689fdc0a4 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 12 Feb 2018 17:49:39 +0100 Subject: [PATCH 1/3] colors at startup --- kernel-rs/src/lib.rs | 36 +++++++++++++++++++++--------------- kernel-rs/src/vga/buffer.rs | 4 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 1f0a7fe5..2ef02d66 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -16,6 +16,9 @@ mod vga; mod context; mod keyboard; +use context::CONTEXT; +use vga::{Color, ColorCode}; + #[allow(dead_code)] mod cpuio; @@ -34,21 +37,24 @@ pub extern fn kmain() -> ! { // use vga::color::Color; // use vga::color::ColorCode; - println!(r#" ,--, "#); - println!(r#" ,--.'| ,----, "#); - println!(r#" ,--, | : .' .' \ "#); - println!(r#",---.'| : ' ,----,' | "#); - println!(r#"; : | | ; | : . ; "#); - println!(r#"| | : _' | ; |.' / "#); - println!(r#": : |.' | `----'/ ; "#); - println!(r#"| ' ' ; : / ; / "#); - println!(r#"\ \ .'. | ; / /-, "#); - println!(r#" `---`: | ' / / /.`| "#); - println!(r#" ' ; |./__; : "#); - println!(r#" | : ;| : .' "#); - println!(r#" ' ,/ ; | .' "#); - println!(r#" '--' `---' "#); - println!(">> Kernel startup..."); + unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); } + print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}\n", + format_args!("{: ^80}", r#" ,--, "#), + format_args!("{: ^80}", r#" ,--.'| ,----, "#), + format_args!("{: ^80}", r#" ,--, | : .' .' \ "#), + format_args!("{: ^80}", r#",---.'| : ' ,----,' | "#), + format_args!("{: ^80}", r#"; : | | ; | : . ; "#), + format_args!("{: ^80}", r#"| | : _' | ; |.' / "#), + format_args!("{: ^80}", r#": : |.' | `----'/ ; "#), + format_args!("{: ^80}", r#"| ' ' ; : / ; / "#), + format_args!("{: ^80}", r#"\ \ .'. | ; / /-, "#), + format_args!("{: ^80}", r#" `---`: | ' / / /.`| "#), + format_args!("{: ^80}", r#" ' ; |./__; : "#), + format_args!("{: ^80}", r#" | : ;| : .' "#), + format_args!("{: ^80}", r#" ' ,/ ; | .' "#), + format_args!("{: ^80}", r#" '--' `---' "#)); + unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Black); } + print!(">"); loop { keyboard::kbd_callback(); diff --git a/kernel-rs/src/vga/buffer.rs b/kernel-rs/src/vga/buffer.rs index 9ead4ce9..5e9e6312 100644 --- a/kernel-rs/src/vga/buffer.rs +++ b/kernel-rs/src/vga/buffer.rs @@ -31,6 +31,7 @@ macro_rules! println { pub fn print(args: fmt::Arguments) { use core::fmt::Write; unsafe { CONTEXT.current_term().write_fmt(args).unwrap() }; + unsafe { CONTEXT.current_term().flush() }; } @@ -45,7 +46,7 @@ const BUFFER_COLS: usize = 80 * 2; pub struct Writer { pub position: usize, - color_code: ColorCode, + pub color_code: ColorCode, buffer: [u8; BUFFER_ROWS * BUFFER_COLS], } @@ -120,7 +121,6 @@ impl fmt::Write for Writer { for byte in s.bytes() { self.write_byte(byte) } - self.flush(); Ok(()) } } From bd86aae5368993516fccc033d8cc3b82052faeff Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 12 Feb 2018 18:00:15 +0100 Subject: [PATCH 2/3] lol --- kernel-rs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index 2ef02d66..c1c05fcc 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -38,7 +38,7 @@ pub extern fn kmain() -> ! { // use vga::color::ColorCode; unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); } - print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}\n", + print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}", format_args!("{: ^80}", r#" ,--, "#), format_args!("{: ^80}", r#" ,--.'| ,----, "#), format_args!("{: ^80}", r#" ,--, | : .' .' \ "#), From 6598cbe3eb13ec9ad61e4428ffd1a01288d1893d Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 13 Feb 2018 14:35:17 +0100 Subject: [PATCH 3/3] cursor is now the real VGA buffer cursor --- kernel-rs/src/vga/buffer.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/kernel-rs/src/vga/buffer.rs b/kernel-rs/src/vga/buffer.rs index 5e9e6312..d5491b1d 100644 --- a/kernel-rs/src/vga/buffer.rs +++ b/kernel-rs/src/vga/buffer.rs @@ -9,6 +9,7 @@ use super::{Color, ColorCode}; use ::context::CONTEXT; +use cpuio; #[derive(Debug, Clone, Copy)] #[repr(C)] @@ -34,13 +35,8 @@ pub fn print(args: fmt::Arguments) { unsafe { CONTEXT.current_term().flush() }; } - extern crate core; -// pub const unsafe fn vga_slice() -> &'static [u8] { -// unsafe { core::slice::from_raw_parts_mut(0xb8000 as *mut u8, 4000) } -// } - const BUFFER_ROWS: usize = 25; const BUFFER_COLS: usize = 80 * 2; @@ -70,8 +66,6 @@ impl Writer { match byte { b'\n' => { - //reset cursor - self.buffer[self.position + 1] = ColorCode::new(Color::White, Color::Black).0; let current_line = self.position / (BUFFER_COLS); self.position = (current_line + 1) * BUFFER_COLS; } @@ -86,10 +80,11 @@ impl Writer { self.scroll(); } - // cursor - self.buffer[self.position] = b' '; - self.buffer[self.position + 1] = ColorCode::new(Color::LightGray, Color::LightGray).0; - + let cursor_position = self.position / 2; + cpuio::outb(14, 0x3D4); + cpuio::outb((cursor_position >> 8) as u8, 0x3D5); + cpuio::outb(15, 0x3D4); + cpuio::outb((cursor_position >> 0) as u8 & 0x00ff, 0x3D5); } pub fn flush(&mut self) {