Release 960114
[wine/gsoc-2012-control.git] / miscemu / int1a.c
blob738029c923cbe720c7cbca2e9a108c269ddf1280
1 #include <time.h>
2 #include <sys/time.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include "registers.h"
6 #include "wine.h"
7 #include "options.h"
8 #include "miscemu.h"
9 #include "stddebug.h"
10 /* #define DEBUG_INT */
11 #include "debug.h"
13 #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
14 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
17 /**********************************************************************
18 * INT1A_GetTicksSinceMidnight
20 * Return number of clock ticks since midnight.
22 DWORD INT1A_GetTicksSinceMidnight(void)
24 struct tm *bdtime;
25 struct timeval tvs;
26 time_t seconds;
28 /* This should give us the (approximately) correct
29 * 18.206 clock ticks per second since midnight.
31 gettimeofday( &tvs, NULL );
32 seconds = tvs.tv_sec;
33 bdtime = localtime( &seconds );
34 return (((bdtime->tm_hour * 3600 + bdtime->tm_min * 60 +
35 bdtime->tm_sec) * 18206) / 1000) +
36 (tvs.tv_usec / 54927);
40 /**********************************************************************
41 * INT_Int1aHandler
43 * Handler for int 1ah (date and time).
45 void INT_Int1aHandler( struct sigcontext_struct context )
47 time_t ltime;
48 DWORD ticks;
49 struct tm *bdtime;
51 switch(AH_reg(&context))
53 case 0:
54 ticks = INT1A_GetTicksSinceMidnight();
55 CX_reg(&context) = HIWORD(ticks);
56 DX_reg(&context) = LOWORD(ticks);
57 AX_reg(&context) = 0; /* No midnight rollover */
58 dprintf_int(stddeb,"int1a_00 // ticks=%ld\n", ticks);
59 break;
61 case 2:
62 ltime = time(NULL);
63 bdtime = localtime(&ltime);
65 CX_reg(&context) = (BIN_TO_BCD(bdtime->tm_hour)<<8) |
66 BIN_TO_BCD(bdtime->tm_min);
67 DX_reg(&context) = (BIN_TO_BCD(bdtime->tm_sec)<<8);
69 case 4:
70 ltime = time(NULL);
71 bdtime = localtime(&ltime);
72 CX_reg(&context) = (BIN_TO_BCD(bdtime->tm_year/100)<<8) |
73 BIN_TO_BCD((bdtime->tm_year-1900)%100);
74 DX_reg(&context) = (BIN_TO_BCD(bdtime->tm_mon)<<8) |
75 BIN_TO_BCD(bdtime->tm_mday);
76 break;
78 /* setting the time,date or RTC is not allow -EB */
79 case 1:
80 /* set system time */
81 case 3:
82 /* set RTC time */
83 case 5:
84 /* set RTC date */
85 case 6:
86 /* set ALARM */
87 case 7:
88 /* cancel ALARM */
89 break;
91 default:
92 INT_BARF( &context, 0x1a );