#include #include unsigned long volatile timer_ticks; void timer_handler(struct cpu_state *r) { timer_ticks++; if(timer_ticks % 1000 == 0) // eine neue Sekunde bricht herein :D { int oldSecs = system_time.tm_sec; int oldMins = system_time.tm_min; int oldHours = system_time.tm_hour; int oldDays = system_time.tm_mday; int oldMonth = system_time.tm_mon; int oldYear = system_time.tm_year; system_time.tm_timestamp++; if(oldSecs < 59) { system_time.tm_sec++; } else { system_time.tm_sec = 0; if(oldMins < 59) { system_time.tm_min++; } else { system_time.tm_min = 0; if(oldHours < 23) { system_time.tm_hour++; } else { system_time.tm_hour = 0; if(oldDays < tage_pro_monat[oldMonth]-1 || (oldMonth == 2 && oldYear%4==0 && (oldYear%100!=0 || oldYear%400==0) && oldDays < 28)) { system_time.tm_mday++; } else { if(oldMonth < 12) { system_time.tm_mon++; } else { system_time.tm_mon = 0; system_time.tm_year++; } } } } } } } void timer_phase(int hz) { int divisor = 1193180 / hz; /* Calculate our divisor */ outb(0x43, 0x36); /* Set our command byte 0x36 */ outb(0x40, divisor & 0xFF); /* Set low byte of divisor */ outb(0x40, divisor >> 8); /* Set high byte of divisor */ } void install_timer() { timer_phase(1000); timer_ticks = 0; irq_install_handler(0, timer_handler); } void timer_wait(int ticks) { long waitTicks = timer_ticks + ticks; while(timer_ticks < waitTicks); }