Utility function for low, high bits

This commit is contained in:
greg
2015-11-25 02:06:39 -08:00
parent aa9e74299c
commit db8995b15f

View File

@@ -58,10 +58,11 @@ mod PIT {
pub const MILLISECOND_CONSTANT: u16 = 1193; pub const MILLISECOND_CONSTANT: u16 = 1193;
pub fn configure_PIT(timer_divider: u16) { pub fn configure_PIT(timer_divider: u16) {
let (low_bits, high_bits) = ::util::lo_hi_bits(timer_divider);
unsafe { unsafe {
outb(PIT_MODE_CMD, TIMER_CONFIG_SPECIFIER); outb(PIT_MODE_CMD, TIMER_CONFIG_SPECIFIER);
let low_bits = (timer_divider & 0xff) as u8;
let high_bits = (timer_divider >> 8) as u8;
outb(PIT_CH0, low_bits); outb(PIT_CH0, low_bits);
outb(PIT_CH0, high_bits); outb(PIT_CH0, high_bits);
} }
@@ -173,6 +174,11 @@ pub extern fn rust_main() {
// 123 |3,2,1 // 123 |3,2,1
mod util { mod util {
pub fn lo_hi_bits(n: u16) -> (u8, u8) {
( (n & 0xff) as u8, (n >> 8) as u8)
}
pub fn u32_to_chars(n: u32) -> [u8; 10] { pub fn u32_to_chars(n: u32) -> [u8; 10] {
let mut accum = [0; 10]; let mut accum = [0; 10];
let mut i = 0; let mut i = 0;
@@ -325,8 +331,7 @@ mod vga_buffer {
const CURSOR_DATA_PORT: u16 = 0x3d5; const CURSOR_DATA_PORT: u16 = 0x3d5;
let position: u16 = (y as u16)*80 + (x as u16); let position: u16 = (y as u16)*80 + (x as u16);
let low_bits = (position & 0xff) as u8; let (low_bits, high_bits) = ::util::lo_hi_bits(position);
let high_bits = (position >> 8) as u8;
unsafe { unsafe {
outb(CURSOR_COMMAND_PORT, 14); outb(CURSOR_COMMAND_PORT, 14);