blob: 2ab783d20a0903a30f562d3aa2b247b12e838547 [file] [log] [blame]
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00001/*
2 * BIOS interrupt 1ah handler
3 */
4
Alexandre Julliard0e607781993-11-03 19:23:37 +00005#include <time.h>
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00006#include <sys/time.h>
Alexandre Julliard58199531994-04-21 01:20:00 +00007#include <stdlib.h>
Alexandre Julliard7e50df31994-08-06 11:22:41 +00008#include "options.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +00009#include "miscemu.h"
Alexandre Julliard61fece01999-06-26 19:09:08 +000010#include "debugtools.h"
Alexandre Julliard0e607781993-11-03 19:23:37 +000011
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000012DEFAULT_DEBUG_CHANNEL(int)
13
Alexandre Julliard0e607781993-11-03 19:23:37 +000014#define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
15#define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
16
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000017
18/**********************************************************************
Alexandre Julliardb7258be1995-09-01 15:57:28 +000019 * INT1A_GetTicksSinceMidnight
20 *
21 * Return number of clock ticks since midnight.
22 */
23DWORD INT1A_GetTicksSinceMidnight(void)
24{
25 struct tm *bdtime;
26 struct timeval tvs;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000027 time_t seconds;
Alexandre Julliardb7258be1995-09-01 15:57:28 +000028
29 /* This should give us the (approximately) correct
30 * 18.206 clock ticks per second since midnight.
31 */
32 gettimeofday( &tvs, NULL );
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000033 seconds = tvs.tv_sec;
34 bdtime = localtime( &seconds );
Alexandre Julliardb7258be1995-09-01 15:57:28 +000035 return (((bdtime->tm_hour * 3600 + bdtime->tm_min * 60 +
36 bdtime->tm_sec) * 18206) / 1000) +
37 (tvs.tv_usec / 54927);
38}
39
40
41/**********************************************************************
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000042 * INT_Int1aHandler
43 *
Alexandre Julliarda0d77311998-09-13 16:32:00 +000044 * Handler for int 1ah
45 * 0x00 - 0x07 - date and time
46 * 0x?? - 0x?? - Microsoft Real Time Compression Interface
47 */
Alexandre Julliard617955d1999-06-26 18:40:24 +000048void WINAPI INT_Int1aHandler( CONTEXT86 *context )
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000049{
Alexandre Julliard808cb041995-08-17 17:11:36 +000050 time_t ltime;
51 DWORD ticks;
52 struct tm *bdtime;
Alexandre Julliard0e607781993-11-03 19:23:37 +000053
Alexandre Julliardca22b331996-07-12 19:02:39 +000054 switch(AH_reg(context))
Alexandre Julliard808cb041995-08-17 17:11:36 +000055 {
Alexandre Julliarda0d77311998-09-13 16:32:00 +000056 case 0x00:
Alexandre Julliardb7258be1995-09-01 15:57:28 +000057 ticks = INT1A_GetTicksSinceMidnight();
Alexandre Julliardca22b331996-07-12 19:02:39 +000058 CX_reg(context) = HIWORD(ticks);
59 DX_reg(context) = LOWORD(ticks);
60 AX_reg(context) = 0; /* No midnight rollover */
Alexandre Julliard61fece01999-06-26 19:09:08 +000061 TRACE("int1a: AH=00 -- ticks=%ld\n", ticks);
Alexandre Julliardb7258be1995-09-01 15:57:28 +000062 break;
Alexandre Julliard0e607781993-11-03 19:23:37 +000063
Alexandre Julliarda0d77311998-09-13 16:32:00 +000064 case 0x02:
Alexandre Julliard0e607781993-11-03 19:23:37 +000065 ltime = time(NULL);
66 bdtime = localtime(&ltime);
67
Alexandre Julliardca22b331996-07-12 19:02:39 +000068 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);
Alexandre Julliard0e607781993-11-03 19:23:37 +000071
Alexandre Julliarda0d77311998-09-13 16:32:00 +000072 case 0x04:
Alexandre Julliard0e607781993-11-03 19:23:37 +000073 ltime = time(NULL);
74 bdtime = localtime(&ltime);
Alexandre Julliardca22b331996-07-12 19:02:39 +000075 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);
Alexandre Julliard0e607781993-11-03 19:23:37 +000079 break;
80
81 /* setting the time,date or RTC is not allow -EB */
Alexandre Julliarda0d77311998-09-13 16:32:00 +000082 case 0x01:
Alexandre Julliard0e607781993-11-03 19:23:37 +000083 /* set system time */
Alexandre Julliarda0d77311998-09-13 16:32:00 +000084 case 0x03:
Alexandre Julliard0e607781993-11-03 19:23:37 +000085 /* set RTC time */
Alexandre Julliarda0d77311998-09-13 16:32:00 +000086 case 0x05:
Alexandre Julliard0e607781993-11-03 19:23:37 +000087 /* set RTC date */
Alexandre Julliarda0d77311998-09-13 16:32:00 +000088 case 0x06:
Alexandre Julliard0e607781993-11-03 19:23:37 +000089 /* set ALARM */
Alexandre Julliarda0d77311998-09-13 16:32:00 +000090 case 0x07:
Alexandre Julliard0e607781993-11-03 19:23:37 +000091 /* cancel ALARM */
92 break;
93
Alexandre Julliarda0d77311998-09-13 16:32:00 +000094 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
Alexandre Julliard0e607781993-11-03 19:23:37 +0000105 default:
Alexandre Julliardca22b331996-07-12 19:02:39 +0000106 INT_BARF( context, 0x1a );
Alexandre Julliard808cb041995-08-17 17:11:36 +0000107 }
Alexandre Julliard0e607781993-11-03 19:23:37 +0000108}