CTAOS v1
This commit is contained in:
52
timer.c
Normal file
52
timer.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include<system.h>
|
||||
int timer_ticks = 0;
|
||||
int timer_hz;
|
||||
|
||||
void timer_phase(int hz)
|
||||
{
|
||||
int divisor = 1193180/hz; // Calculate the divisor
|
||||
outportb(0x43, 0x36); // Set our command byte 0x36
|
||||
outportb(0x40, divisor&0xFF); // Set low byte
|
||||
outportb(0x40, divisor>>8); // Set high byte
|
||||
timer_hz = hz;
|
||||
}
|
||||
|
||||
void timer_clock (int x, int y, int secs)
|
||||
{
|
||||
int s, m, h;
|
||||
char arr[9] = {0,0,0,0,0,0,0,0,0};
|
||||
|
||||
s = secs%60;
|
||||
m = (secs/60)%60;
|
||||
h = secs/3600;
|
||||
|
||||
arr[0] = (h/10)%10 + '0'; if (arr[0]=='0') arr[0] = ' ';
|
||||
arr[1] = h%10 + '0';
|
||||
|
||||
arr[3] = (m/10) + '0';
|
||||
arr[4] = m%10 + '0';
|
||||
|
||||
arr[6] = s/10 + '0';
|
||||
arr[7] = s%10 + '0';
|
||||
|
||||
if (secs%2 == 0) {
|
||||
arr[2] = ' ';
|
||||
arr[5] = ' ';
|
||||
}
|
||||
else {
|
||||
arr[2] = ':';
|
||||
arr[5] = ':';
|
||||
}
|
||||
|
||||
puts_pos(x, y, arr);
|
||||
}
|
||||
|
||||
|
||||
void timer_handler(regs *r)
|
||||
{
|
||||
timer_ticks++;
|
||||
|
||||
if (timer_ticks % timer_hz) {
|
||||
timer_clock (70, 0, timer_ticks / timer_hz);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user