Added a few default palette entries for the VGA/MCGA 256-color mode.
[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 "debugtools.h"
11
12 DEFAULT_DEBUG_CHANNEL(int);
13
14 #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
15 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
16
17
18 /**********************************************************************
19  *          INT1A_GetTicksSinceMidnight
20  *
21  * Return number of clock ticks since midnight.
22  */
23 DWORD INT1A_GetTicksSinceMidnight(void)
24 {
25     struct tm *bdtime;
26     struct timeval tvs;
27     time_t seconds;
28
29     /* This should give us the (approximately) correct
30      * 18.206 clock ticks per second since midnight.
31      */
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);
38 }
39
40
41 /**********************************************************************
42  *          INT_Int1aHandler (WPROCS.126)
43  *
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 )
49 {
50     time_t ltime;
51     DWORD ticks;
52     struct tm *bdtime;
53
54     switch(AH_reg(context))
55     {
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;
63                 
64         case 0x02: 
65                 ltime = time(NULL);
66                 bdtime = localtime(&ltime);
67                 
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);
71
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;
80
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;
93
94         case 0xb0: /* Microsoft Real Time Compression */
95                 switch AL_reg(context)
96                 {
97                     case 0x01:
98                         /* not present */
99                         break;
100                     default:
101                         INT_BARF(context, 0x1a);
102                 }
103                 break;
104                 
105         default:
106                 INT_BARF( context, 0x1a );
107     }
108 }