From f53468a1f507cee6b8105b2ae8672bd76bfa0699 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 9 Feb 2018 17:51:38 +0100 Subject: [PATCH] cursor support :) --- kernel-rs/Makefile | 1 - kernel-rs/src/lib.rs | 5 +---- kernel-rs/src/vga_buffer.rs | 28 +++++++++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/kernel-rs/Makefile b/kernel-rs/Makefile index ff3a4de6..e42f45ee 100644 --- a/kernel-rs/Makefile +++ b/kernel-rs/Makefile @@ -36,7 +36,6 @@ GDB := gdb -q\ -ex \"target remote localhost:$(PORTG)\"\ -ex \"continue\" - all: $(kernel) build/arch/$(arch)/%.o: src/arch/$(arch)/%.asm Makefile diff --git a/kernel-rs/src/lib.rs b/kernel-rs/src/lib.rs index b5ced73a..40486a2d 100644 --- a/kernel-rs/src/lib.rs +++ b/kernel-rs/src/lib.rs @@ -44,10 +44,7 @@ pub extern fn kmain() -> ! { if (control & 1) == 1 { let keycode = unsafe { cpuio::inb(0x60) }; match keyboard::KEY_CODE_TO_ASCII.get(keycode as usize) { - Some(ascii) => { - print!("{}", *ascii as char); - // unsafe { cpuio::outb(28, 0x64) }; - }, + Some(ascii) => print!("{}", *ascii as char), None =>{}, // None => println!("nokey ctrl {:x}", control), } diff --git a/kernel-rs/src/vga_buffer.rs b/kernel-rs/src/vga_buffer.rs index 5217ea6b..5bbaedfb 100644 --- a/kernel-rs/src/vga_buffer.rs +++ b/kernel-rs/src/vga_buffer.rs @@ -21,6 +21,18 @@ pub static WRITER: Mutex = Mutex::new(Writer { vgabuffer: unsafe { Unique::new_unchecked(0xb8000 as *mut _) }, }); +// cursor is lightgray for everyone +static CURSOR: ScreenChar = ScreenChar { + ascii_character: b' ', + color_code: ColorCode::new(Color::LightGray, Color::LightGray), +}; + +// blank is black for everyone, could make screens choose this +static BLANK: ScreenChar = ScreenChar { + ascii_character: b' ', + color_code: ColorCode::new(Color::White, Color::Black), +}; + pub struct Writer { column_position: usize, pub color_code: ColorCode, @@ -67,9 +79,7 @@ impl Writer { } let row = BUFFER_HEIGHT - 1; let col = self.column_position; - let color_code = self.color_code; - self.buffer().chars[row][col].write(ScreenChar { ascii_character: byte, color_code: color_code, @@ -77,6 +87,9 @@ impl Writer { self.column_position += 1; } } + let row = BUFFER_HEIGHT - 1; + let col = self.column_position; + self.buffer().chars[row][col].write(CURSOR); } fn buffer(&mut self) -> &mut Buffer { @@ -84,6 +97,11 @@ impl Writer { } fn new_line(&mut self) { + // remove cursor if newline isnt from end of screen + if self.column_position < BUFFER_WIDTH { + let col = self.column_position; + self.buffer().chars[BUFFER_HEIGHT - 1][col].write(BLANK); + } for row in 1..BUFFER_HEIGHT { for col in 0..BUFFER_WIDTH { let buffer = self.buffer(); @@ -96,12 +114,8 @@ impl Writer { } fn clear_row(&mut self, row: usize) { - let blank = ScreenChar { - ascii_character: b' ', - color_code: ColorCode::new(Color::White, Color::Black), - }; for col in 0..BUFFER_WIDTH { - self.buffer().chars[row][col].write(blank); + self.buffer().chars[row][col].write(BLANK); } } }