Michael Abd-El-Malek (Corel)
[wine/multimedia.git] / msdos / int1a.c
blob2ab783d20a0903a30f562d3aa2b247b12e838547
1 /*
2 * BIOS interrupt 1ah handler
3 */
5 #include <time.h>
6 #include <sys/time.h>
7 #include <stdlib.h>
8 #include "options.h"
9 #include "miscemu.h"
10 #include "debugtools.h"
12 DEFAULT_DEBUG_CHANNEL(int)
14 #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
15 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
18 /**********************************************************************
19 * INT1A_GetTicksSinceMidnight
21 * Return number of clock ticks since midnight.
23 DWORD INT1A_GetTicksSinceMidnight(void)
25 struct tm *bdtime;
26 struct timeval tvs;
27 time_t seconds;
29 /* This should give us the (approximately) correct
30 * 18.206 clock ticks per second since midnight.
32 gettimeofday( &tvs, NULL );
33 seconds = tvs.tv_sec;
34 bdtime = localtime( &seconds );
35 return (((bdtime->tm_hour * 3600 + bdtime->tm_min * 60 +
36 bdtime->tm_sec) * 18206) / 1000) +
37 (tvs.tv_usec / 54927);
41 /**********************************************************************
42 * INT_Int1aHandler
44 * Handler for int 1ah
45 * 0x00 - 0x07 - date and time
46 * 0x?? - 0x?? - Microsoft Real Time Compression Interface
47 */
48 void WINAPI INT_Int1aHandler( CONTEXT86 *context )
50 time_t ltime;
51 DWORD ticks;
52 struct tm *bdtime;
54 switch(AH_reg(context))
56 case 0x00:
57 ticks = INT1A_GetTicksSinceMidnight();
58 CX_reg(context) = HIWORD(ticks);
59 DX_reg(context) = LOWORD(ticks);
60 AX_reg(context) = 0; /* No midnight rollover */
61 TRACE("int1a: AH=00 -- ticks=%ld\n", ticks);
62 break;
64 case 0x02:
65 ltime = time(NULL);
66 bdtime = localtime(&ltime);
68 CX_reg(context) = (BIN_TO_BCD(bdtime->tm_hour)<<8) |
69 BIN_TO_BCD(bdtime->tm_min);
70 DX_reg(context) = (BIN_TO_BCD(bdtime->tm_sec)<<8);
72 case 0x04:
73 ltime = time(NULL);
74 bdtime = localtime(&ltime);
75 CX_reg(context) = (BIN_TO_BCD(bdtime->tm_year/100)<<8) |
76 BIN_TO_BCD((bdtime->tm_year-1900)%100);
77 DX_reg(context) = (BIN_TO_BCD(bdtime->tm_mon)<<8) |
78 BIN_TO_BCD(bdtime->tm_mday);
79 break;
81 /* setting the time,date or RTC is not allow -EB */
82 case 0x01:
83 /* set system time */
84 case 0x03:
85 /* set RTC time */
86 case 0x05:
87 /* set RTC date */
88 case 0x06:
89 /* set ALARM */
90 case 0x07:
91 /* cancel ALARM */
92 break;
94 case 0xb0: /* Microsoft Real Time Compression */
95 switch AL_reg(context)
97 case 0x01:
98 /* not present */
99 break;
100 default:
101 INT_BARF(context, 0x1a);
103 break;
105 default:
106 INT_BARF( context, 0x1a );