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