76 lines
2.5 KiB
C
76 lines
2.5 KiB
C
#include <system.h>
|
|
#include "time.c"
|
|
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 clock_show (int uptime_secs)
|
|
{
|
|
int i;
|
|
for (i=0;i<80;i++) putc_pos_font (i, 0, ' ', 0x02, 0x0F);
|
|
puts_pos_font (64, 0, "Uptime:", 0x02, 0x0E);
|
|
|
|
unsigned int uptime;
|
|
|
|
uptime = uptime_secs%60; // Seconds
|
|
uptime += 100* ((uptime_secs/60)%60); // Minutes
|
|
uptime += 10000*(uptime_secs/3600); // Hours
|
|
|
|
for (i=79;i>71;i--) {
|
|
if (i==77 || i==74) {
|
|
if (uptime_secs%2==0) putc_pos_font(i, 0, ':', 0x02, 0x0F);
|
|
else putc_pos_font(i, 0, ' ', 0x02, 0x0F);
|
|
}
|
|
else {
|
|
putc_pos_font(i, 0, (uptime%10)+'0', 0x02, 0x0F);
|
|
uptime/=10;
|
|
}
|
|
}
|
|
|
|
// PRINT CURRENT TIME
|
|
uptime = clock.seconds; // Seconds
|
|
uptime += 100* clock.minutes; // Minutes
|
|
uptime += 10000*clock.hours; // Hours
|
|
|
|
for (i=9;i>1;i--) {
|
|
if (i==7 || i==4) {
|
|
if (uptime_secs%2==0) putc_pos_font(i, 0, ':', 0x02, 0x0F);
|
|
else putc_pos_font(i, 0, ' ', 0x02, 0x0F);
|
|
}
|
|
else {
|
|
putc_pos_font(i,0, (uptime%10)+'0', 0x02, 0x0F);
|
|
uptime/=10;
|
|
}
|
|
}
|
|
if (clock.am_pm==0) puts_pos_font(10, 0, "am", 0x02, 0x0F);
|
|
else puts_pos_font(10, 0, "pm", 0x02, 0x0F);
|
|
|
|
// PRINT DATE
|
|
putc_pos_font(32, 0, (clock.day/10)+'0', 0x02, 0x0E);
|
|
putc_pos_font(33, 0, (clock.day%10)+'0', 0x02, 0x0E);
|
|
puts_pos_font(35, 0, (char*)clock_months[clock.month], 0x02, 0x0F);
|
|
putc_pos_font(35+strlen(clock_months[clock.month])+1, 0, (clock.century/10)+'0', 0x02, 0x0E);
|
|
putc_pos_font(35+strlen(clock_months[clock.month])+2, 0, (clock.century%10)+'0', 0x02, 0x0E);
|
|
putc_pos_font(35+strlen(clock_months[clock.month])+3, 0, (clock.year/10)+'0', 0x02, 0x0E);
|
|
putc_pos_font(35+strlen(clock_months[clock.month])+4, 0, (clock.year%10)+'0', 0x02, 0x0E);
|
|
|
|
}
|
|
|
|
|
|
void timer_handler(regs *r)
|
|
{
|
|
timer_ticks++;
|
|
|
|
if (timer_ticks % timer_hz == 0) {
|
|
clock_show (timer_ticks / timer_hz);
|
|
clock_inc();
|
|
}
|
|
} |