Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * BIOS interrupt 1ah handler |
| 3 | */ |
| 4 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 5 | #include <time.h> |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 6 | #include <sys/time.h> |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 8 | #include "options.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 9 | #include "miscemu.h" |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 10 | #include "debugtools.h" |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 11 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 12 | DEFAULT_DEBUG_CHANNEL(int) |
| 13 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 14 | #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10) |
| 15 | #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4)) |
| 16 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 17 | |
| 18 | /********************************************************************** |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 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; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 27 | time_t seconds; |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 28 | |
| 29 | /* This should give us the (approximately) correct |
| 30 | * 18.206 clock ticks per second since midnight. |
| 31 | */ |
| 32 | gettimeofday( &tvs, NULL ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 33 | seconds = tvs.tv_sec; |
| 34 | bdtime = localtime( &seconds ); |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 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 | /********************************************************************** |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 42 | * INT_Int1aHandler |
| 43 | * |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 44 | * Handler for int 1ah |
| 45 | * 0x00 - 0x07 - date and time |
| 46 | * 0x?? - 0x?? - Microsoft Real Time Compression Interface |
| 47 | */ |
Alexandre Julliard | 617955d | 1999-06-26 18:40:24 +0000 | [diff] [blame] | 48 | void WINAPI INT_Int1aHandler( CONTEXT86 *context ) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 49 | { |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 50 | time_t ltime; |
| 51 | DWORD ticks; |
| 52 | struct tm *bdtime; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 53 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 54 | switch(AH_reg(context)) |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 55 | { |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 56 | case 0x00: |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 57 | ticks = INT1A_GetTicksSinceMidnight(); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 58 | CX_reg(context) = HIWORD(ticks); |
| 59 | DX_reg(context) = LOWORD(ticks); |
| 60 | AX_reg(context) = 0; /* No midnight rollover */ |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 61 | TRACE("int1a: AH=00 -- ticks=%ld\n", ticks); |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 62 | break; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 63 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 64 | case 0x02: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 65 | ltime = time(NULL); |
| 66 | bdtime = localtime(<ime); |
| 67 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 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); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 71 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 72 | case 0x04: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 73 | ltime = time(NULL); |
| 74 | bdtime = localtime(<ime); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 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); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 79 | break; |
| 80 | |
| 81 | /* setting the time,date or RTC is not allow -EB */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 82 | case 0x01: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 83 | /* set system time */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 84 | case 0x03: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 85 | /* set RTC time */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 86 | case 0x05: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 87 | /* set RTC date */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 88 | case 0x06: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 89 | /* set ALARM */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 90 | case 0x07: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 91 | /* cancel ALARM */ |
| 92 | break; |
| 93 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 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 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 105 | default: |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 106 | INT_BARF( context, 0x1a ); |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 107 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 108 | } |