{
return (GET_BDA(timer_counter) + count + 1) % TICKS_PER_DAY;
}
+
// Return the timer value that is 'msecs' time in the future.
u32
calc_future_timer(u32 msecs)
{
+ if (!msecs)
+ return GET_BDA(timer_counter);
u32 kticks = DIV_ROUND_UP((u64)(msecs * PIT_TICK_RATE), PIT_TICK_INTERVAL);
u32 ticks = DIV_ROUND_UP(kticks, 1000);
return calc_future_timer_ticks(ticks);
}
+
// Check if the given timer value has passed.
int
check_timer(u32 end)
* Keyboard calls
****************************************************************/
-// Wait for 'usec' microseconds using (with irqs enabled) using int 1586.
-void
-biosusleep(u32 usec)
-{
- struct bregs br;
- memset(&br, 0, sizeof(br));
- br.flags = F_IF;
- br.ah = 0x86;
- br.cx = usec >> 16;
- br.dx = usec;
- call16_int(0x15, &br);
-}
-
// See if a keystroke is pending in the keyboard buffer.
static int
check_for_keystroke(void)
memset(&br, 0, sizeof(br));
br.flags = F_IF;
br.ah = 1;
- start_preempt();
call16_int(0x16, &br);
- finish_preempt();
return !(br.flags & F_ZF);
}
struct bregs br;
memset(&br, 0, sizeof(br));
br.flags = F_IF;
- start_preempt();
call16_int(0x16, &br);
- finish_preempt();
return br.ah;
}
int
get_keystroke(int msec)
{
+ u32 end = calc_future_timer(msec);
for (;;) {
if (check_for_keystroke())
return get_raw_keystroke();
- if (msec <= 0)
+ if (check_timer(end))
return -1;
- start_preempt();
- biosusleep(50*1000);
- finish_preempt();
- msec -= 50;
+ wait_irq();
}
}
void iomemcpy(void *d, const void *s, u32 len);
void *memmove(void *d, const void *s, size_t len);
char *strtcpy(char *dest, const char *src, size_t len);
-void biosusleep(u32 usec);
int get_keystroke(int msec);
// stacks.c