vgabios: Add scrolling for linear (packed pixel) graphics mode.
[seabios.git] / src / serial.c
index 493d4213a5ecac83ee099a75d5f23a7f329f515f..21b4bd010586166bc4cfe8453a268147870403aa 100644 (file)
@@ -9,31 +9,6 @@
 #include "util.h" // debug_enter
 #include "bregs.h" // struct bregs
 
-// Timers based on 18.2Hz clock irq.
-struct tick_timer_s {
-    u16 last_tick, remaining;
-};
-
-struct tick_timer_s
-initTickTimer(u16 count)
-{
-    struct tick_timer_s tt = {GET_BDA(timer_counter), count};
-    return tt;
-}
-
-int
-checkTickTimer(struct tick_timer_s *tt)
-{
-    u16 timer = GET_BDA(timer_counter);
-    if (tt->last_tick != timer) {
-        tt->last_tick = timer;
-        tt->last_tick--;
-        if (!tt->last_tick)
-            return 1;
-    }
-    return 0;
-}
-
 
 /****************************************************************
  * COM ports
@@ -57,7 +32,7 @@ detect_serial(u16 port, u8 timeout, u8 count)
 }
 
 void
-serial_setup()
+serial_setup(void)
 {
     if (! CONFIG_SERIAL)
         return;
@@ -117,7 +92,7 @@ handle_1401(struct bregs *regs)
     u16 addr = getComAddr(regs);
     if (!addr)
         return;
-    struct tick_timer_s tt = initTickTimer(GET_BDA(com_timeout[regs->dx]));
+    u32 end = calc_future_timer_ticks(GET_BDA(com_timeout[regs->dx]));
     for (;;) {
         u8 lsr = inb(addr+SEROFF_LSR);
         if ((lsr & 0x60) == 0x60) {
@@ -127,7 +102,7 @@ handle_1401(struct bregs *regs)
             regs->ah = lsr;
             break;
         }
-        if (checkTickTimer(&tt)) {
+        if (check_timer(end)) {
             // Timed out - can't write data.
             regs->ah = lsr | 0x80;
             break;
@@ -144,7 +119,7 @@ handle_1402(struct bregs *regs)
     u16 addr = getComAddr(regs);
     if (!addr)
         return;
-    struct tick_timer_s tt = initTickTimer(GET_BDA(com_timeout[regs->dx]));
+    u32 end = calc_future_timer_ticks(GET_BDA(com_timeout[regs->dx]));
     for (;;) {
         u8 lsr = inb(addr+SEROFF_LSR);
         if (lsr & 0x01) {
@@ -153,7 +128,7 @@ handle_1402(struct bregs *regs)
             regs->ah = lsr;
             break;
         }
-        if (checkTickTimer(&tt)) {
+        if (check_timer(end)) {
             // Timed out - can't read data.
             regs->ah = lsr | 0x80;
             break;
@@ -224,7 +199,7 @@ detect_parport(u16 port, u8 timeout, u8 count)
 }
 
 void
-lpt_setup()
+lpt_setup(void)
 {
     if (! CONFIG_LPT)
         return;
@@ -261,7 +236,7 @@ handle_1700(struct bregs *regs)
     if (!addr)
         return;
 
-    struct tick_timer_s tt = initTickTimer(GET_BDA(lpt_timeout[regs->dx]));
+    u32 end = calc_future_timer_ticks(GET_BDA(lpt_timeout[regs->dx]));
 
     outb(regs->al, addr);
     u8 val8 = inb(addr+2);
@@ -276,7 +251,7 @@ handle_1700(struct bregs *regs)
             regs->ah = v ^ 0x48;
             break;
         }
-        if (checkTickTimer(&tt)) {
+        if (check_timer(end)) {
             // Timeout
             regs->ah = (v ^ 0x48) | 0x01;
             break;