From c250c57fd60d5023af0362e114b4c547022b9975 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 4 Jun 2017 11:24:51 -0500 Subject: [PATCH] vga_console: add Writer.move_cursor(), make write_str move the cursor --- src/arch/x86_64/device/vga_console.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/arch/x86_64/device/vga_console.rs b/src/arch/x86_64/device/vga_console.rs index d595f3c..4b8ae13 100644 --- a/src/arch/x86_64/device/vga_console.rs +++ b/src/arch/x86_64/device/vga_console.rs @@ -4,6 +4,7 @@ use core::fmt; use core::ptr::Unique; use spin::Mutex; use volatile::Volatile; +use x86::shared::io; pub static WRITER: Mutex = Mutex::new(Writer { column_pos: 0, row_pos: 0, @@ -112,6 +113,18 @@ impl Writer { self.style } + fn move_cursor(&mut self, row: usize, col: usize) { + let pos: u16 = ((row * 80) + col) as u16; + // Lovingly ripped off from wiki.osdev.org/Text_Mode_Cursor + unsafe { + io::outb(0x3d4, 0x0F); + io::outb(0x3d5, (pos & 0xff) as u8); + + io::outb(0x3d4, 0x0e); + io::outb(0x3d5, ((pos>>8) & 0xff) as u8); + } + } + fn new_line(&mut self) { self.column_pos = 0; self.row_pos += 1; @@ -152,6 +165,10 @@ impl fmt::Write for Writer { self.write_byte(byte); } + let row = self.row_pos; + let col = self.column_pos; + self.move_cursor(row, col); + Ok(()) } }