Release 941017
[wine] / miscemu / int1a.c
1 #include <time.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "registers.h"
5 #include "wine.h"
6 #include "options.h"
7 #include "stddebug.h"
8 /* #define DEBUG_INT */
9 /* #undef  DEBUG_INT */
10 #include "debug.h"
11
12 #ifdef linux
13 #define inline __inline__  /* So we can compile with -ansi */
14 #include <linux/sched.h> /* needed for HZ */
15 #undef inline
16 #endif
17
18 #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
19 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
20
21 void IntBarf(int i, struct sigcontext_struct *context);
22
23 int do_int1A(struct sigcontext_struct * context){
24         time_t ltime;
25         struct tm *bdtime;
26         int ticks;
27
28     if (Options.relay_debug) {
29         fprintf(stddeb,"int1A: AX %04x, BX %04x, CX %04x, DX %04x, "
30                "SI %04x, DI %04x, DS %04x, ES %04x\n",
31                AX, BX, CX, DX, SI, DI, DS, ES);
32     }
33
34         switch(AH) {
35         case 0:
36                 ltime = time(NULL);
37                 ticks = (int) (ltime * HZ);
38                 CX = ticks >> 16;
39                 DX = ticks & 0x0000FFFF;
40                 AX = 0;  /* No midnight rollover */
41                 dprintf_int(stddeb,"int1a_00 // ltime=%ld ticks=%ld\n",
42                         ltime, ticks);
43                 break;
44                 
45         case 2: 
46                 ltime = time(NULL);
47                 bdtime = localtime(&ltime);
48                 
49                 CX = (BIN_TO_BCD(bdtime->tm_hour)<<8) | BIN_TO_BCD(bdtime->tm_min);
50                 DX = (BIN_TO_BCD(bdtime->tm_sec)<<8);
51
52         case 4:
53                 ltime = time(NULL);
54                 bdtime = localtime(&ltime);
55                 CX = (BIN_TO_BCD(bdtime->tm_year/100)<<8) | BIN_TO_BCD((bdtime->tm_year-1900)%100);
56                 DX = (BIN_TO_BCD(bdtime->tm_mon)<<8) | BIN_TO_BCD(bdtime->tm_mday);
57                 break;
58
59                 /* setting the time,date or RTC is not allow -EB */
60         case 1:
61                 /* set system time */
62         case 3: 
63                 /* set RTC time */
64         case 5:
65                 /* set RTC date */
66         case 6:
67                 /* set ALARM */
68         case 7:
69                 /* cancel ALARM */
70                 break;
71
72         default:
73                 IntBarf(0x1a, context);
74                 return 1;
75         };
76         return 1;
77 }