print_int function

Just to print integer outputs of things on the screen
This commit is contained in:
greg
2015-11-10 03:02:30 -08:00
parent 8dcbdc997c
commit 63775eaa7c

View File

@@ -21,6 +21,10 @@ pub extern fn rust_main() {
}
}
vga_buffer::print_int(1, 5);
vga_buffer::print_int(10, 6);
vga_buffer::print_int(765, 6);
loop {}
}
@@ -105,6 +109,26 @@ mod vga_buffer {
}
}
pub fn print_int(i: u32, row: usize) {
let mut val = i;
let mut ptr = BUFFER_PTR + BUFFER_WIDTH*2*(row+1) - 2 as usize;
let color_code = ColorCode::new(Color::White, Color::Black);
loop {
if val < 10 {
let ch: u8 = b'0' + (val as u8);
let data = ScreenChar { ascii_char: ch, color_code: color_code };
unsafe { *(ptr as *mut _) = data; }
break;
} else {
let ch: u8 = b'0' + ((val % 10) as u8) ;
val = val / 10;
let data = ScreenChar { ascii_char: ch, color_code: color_code };
unsafe { *(ptr as *mut _) = data; }
ptr -= 2;
}
}
}
pub fn write_to_coord(x: usize, y: usize, character: u8, color_code: ColorCode) {
let ptr = BUFFER_PTR + (2*x as usize) + (BUFFER_WIDTH*2*y as usize);
let data = ScreenChar {