time.c revision 39441
1/* 2 * mjs copyright 3 */ 4 5#include <stand.h> 6#include <btxv86.h> 7 8/* 9 * Return the time in seconds since the beginning of the day. 10 * 11 * If we pass midnight, don't wrap back to 0. 12 * 13 * XXX uses undocumented BCD support from libstand. 14 */ 15 16time_t 17time(time_t *t) 18{ 19 static time_t lasttime, now; 20 int hr, min, sec; 21 22 v86.ctl = 0; 23 v86.addr = 0x1a; /* int 0x1a, function 2 */ 24 v86.eax = 0x0200; 25 v86int(); 26 27 hr = bcd2bin((v86.ecx & 0xff00) >> 8); /* hour in %ch */ 28 min = bcd2bin(v86.ecx & 0xff); /* minute in %cl */ 29 sec = bcd2bin((v86.edx & 0xff00) >> 8); /* second in %dh */ 30 31 now = hr * 3600 + min * 60 + sec; 32 if (now < lasttime) 33 now += 24 * 3600; 34 lasttime = now; 35 36 if (t != NULL) 37 *t = now; 38 return(now); 39} 40 41/* 42 * Use the BIOS Wait function to pause for (period) microseconds. 43 * 44 * Resolution of this function is variable, but typically around 45 * 1ms. 46 */ 47void 48delay(int period) 49{ 50 v86.ctl = 0; 51 v86.addr = 0x15; /* int 0x1a, function 0x86 */ 52 v86.eax = 0x8600; 53 v86.ecx = period >> 16; 54 v86.edx = period & 0xffff; 55 v86int(); 56} 57