cursor.rs, no more cpuio in vga
This commit is contained in:
parent
b0548384e7
commit
8a3e3a2324
2 changed files with 35 additions and 8 deletions
30
kernel-rs/src/vga/cursor.rs
Normal file
30
kernel-rs/src/vga/cursor.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
pub mod color;
|
pub mod color;
|
||||||
|
pub mod cursor;
|
||||||
|
|
||||||
pub use self::color::{Color, ColorCode};
|
pub use self::color::{Color, ColorCode};
|
||||||
|
use self::cursor::CURSOR;
|
||||||
|
|
||||||
use cpuio;
|
|
||||||
use console;
|
use console;
|
||||||
|
|
||||||
pub static mut VGA: Writer = self::Writer::new();
|
pub static mut VGA: Writer = self::Writer::new();
|
||||||
|
|
@ -156,13 +157,9 @@ impl Writer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush_cursor(&self) {
|
fn flush_cursor(&self) {
|
||||||
let cursor_position = self.buffer_pos / 2;
|
unsafe {
|
||||||
// 14 awaits the rightmost 8bits
|
CURSOR.flush(self.buffer_pos / 2);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush(&mut self) {
|
pub fn flush(&mut self) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue