diff --git a/rust_experiments/src/lib.rs b/rust_experiments/src/lib.rs index ca6ebee..c2d037c 100644 --- a/rust_experiments/src/lib.rs +++ b/rust_experiments/src/lib.rs @@ -38,12 +38,14 @@ pub extern fn rust_handle_timer() { } fn timer_callback(count: u64) { - if count % 4 == 0 { + if count % 1000 == 0 { checkerboard(vga_buffer::Color::White); } - if count % 4 == 2 { + if count % 1000 == 500 { checkerboard(vga_buffer::Color::LightCyan); } + + vga_buffer::print_u32(count as u32, 0); } #[no_mangle] diff --git a/rust_experiments/src/long_mode_init.asm b/rust_experiments/src/long_mode_init.asm index 4b187c6..9e8ee43 100644 --- a/rust_experiments/src/long_mode_init.asm +++ b/rust_experiments/src/long_mode_init.asm @@ -170,7 +170,7 @@ setup_IDT: ret setup_PIC: - mov al, 0xfc + mov al, 0xfc ;timer and keyboard, no more out byte 0x21, al mov al, 0xff out byte 0xa1, al @@ -178,6 +178,20 @@ setup_PIC: ret setup_PIT: +%define PIT_CH0 0x40 +%define PIT_MODE_CMD 0x43 +%define TIMER_CONSTANT 1193 ;generates ticks at 1000.15 Hz + cli + + mov al, 0b00_11_010_0 ; channel 0, low-byte/hi-byte, rate generator + out PIT_MODE_CMD, al + + mov ax, TIMER_CONSTANT + out PIT_CH0, al + mov al, ah + out PIT_CH0, al + + sti ret idt64: