Add cursor-moving functionality
This commit is contained in:
@@ -135,31 +135,42 @@ mod x86_asm {
|
||||
}
|
||||
|
||||
fn timer_callback(count: u64) {
|
||||
use vga_buffer::{Color, checkerboard};
|
||||
if count % 1000 == 0 {
|
||||
checkerboard(Color::White);
|
||||
}
|
||||
if count % 1000 == 500 {
|
||||
checkerboard(Color::LightCyan);
|
||||
use vga_buffer::{Color, print_u32, checkerboard, clear, move_cursor};
|
||||
|
||||
if count < 10 {
|
||||
clear();
|
||||
}
|
||||
|
||||
vga_buffer::print_u32(count as u32, 0);
|
||||
if count < 3000 {
|
||||
|
||||
move_cursor((count % 80) as u8, 2);
|
||||
|
||||
print_u32(count as u32, 20);
|
||||
|
||||
} else {
|
||||
if count % 1000 == 0 {
|
||||
checkerboard(Color::White);
|
||||
}
|
||||
if count % 1000 == 500 {
|
||||
checkerboard(Color::LightCyan);
|
||||
}
|
||||
move_cursor((count % 80) as u8, 2);
|
||||
}
|
||||
|
||||
print_u32(count as u32, 0);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_main() {
|
||||
use vga_buffer::{clear, checkerboard, Color};
|
||||
clear();
|
||||
checkerboard(Color::Red);
|
||||
//clear();
|
||||
//checkerboard(Color::Red);
|
||||
|
||||
loop {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 123 |3,2,1
|
||||
mod util {
|
||||
pub fn u32_to_chars(n: u32) -> [u8; 10] {
|
||||
@@ -307,6 +318,23 @@ mod vga_buffer {
|
||||
*(ptr as *mut _) = data;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_cursor(x: u8, y: u8) {
|
||||
use x86_asm::{outb};
|
||||
const CURSOR_COMMAND_PORT: u16 = 0x3d4;
|
||||
const CURSOR_DATA_PORT: u16 = 0x3d5;
|
||||
|
||||
let position: u16 = (y as u16)*80 + (x as u16);
|
||||
let low_bits = (position & 0xff) as u8;
|
||||
let high_bits = (position >> 8) as u8;
|
||||
|
||||
unsafe {
|
||||
outb(CURSOR_COMMAND_PORT, 14);
|
||||
outb(CURSOR_DATA_PORT, low_bits);
|
||||
outb(CURSOR_COMMAND_PORT, 15);
|
||||
outb(CURSOR_DATA_PORT, high_bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
|
||||
Reference in New Issue
Block a user