cursor.rs, no more cpuio in vga

This commit is contained in:
Jack Halford 2018-04-12 15:49:37 +02:00
parent b0548384e7
commit 8a3e3a2324
2 changed files with 35 additions and 8 deletions

View file

@ -0,0 +1,30 @@
// https://wiki.osdev.org/Text_Mode_Cursor
// Protected mode cursor abstraction
use io::{Io, Pio};
pub static mut CURSOR: Cursor = Cursor::new(0x3D4);
pub struct Cursor {
cmd: Pio<u8>,
data: Pio<u8>,
}
impl Cursor {
pub const fn new(port: u16) -> Cursor {
Cursor {
cmd: Pio::new(port),
data: Pio::new(port + 1),
}
}
pub fn flush(&mut self, position: usize) {
// 14 awaits the rightmost 8bits
self.cmd.write(14);
self.data.write((position >> 8) as u8 & 0xff);
// 15 awaits the leftmost 8bits
self.cmd.write(15);
self.data.write((position >> 0) as u8 & 0xff);
}
}

View file

@ -1,8 +1,9 @@
pub mod color;
pub mod cursor;
pub use self::color::{Color, ColorCode};
use self::cursor::CURSOR;
use cpuio;
use console;
pub static mut VGA: Writer = self::Writer::new();
@ -156,13 +157,9 @@ impl Writer {
}
fn flush_cursor(&self) {
let cursor_position = self.buffer_pos / 2;
// 14 awaits the rightmost 8bits
cpuio::outb(0x3D4, 14);
cpuio::outb(0x3D5, (cursor_position >> 8) as u8);
// 15 awaits the leftmost 8bits
cpuio::outb(0x3D4, 15);
cpuio::outb(0x3D5, (cursor_position >> 0) as u8 & 0x00ff);
unsafe {
CURSOR.flush(self.buffer_pos / 2);
}
}
pub fn flush(&mut self) {