Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * BIOS interrupt 1ah handler |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1993 Erik Bos |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 21 | #include <time.h> |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 22 | #include <sys/time.h> |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 24 | #include "options.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 25 | #include "miscemu.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 26 | #include "wine/debug.h" |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 27 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 28 | WINE_DEFAULT_DEBUG_CHANNEL(int); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 29 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 30 | #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10) |
| 31 | #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4)) |
| 32 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 33 | |
| 34 | /********************************************************************** |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 35 | * INT1A_GetTicksSinceMidnight |
| 36 | * |
| 37 | * Return number of clock ticks since midnight. |
| 38 | */ |
| 39 | DWORD INT1A_GetTicksSinceMidnight(void) |
| 40 | { |
| 41 | struct tm *bdtime; |
| 42 | struct timeval tvs; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 43 | time_t seconds; |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 44 | |
| 45 | /* This should give us the (approximately) correct |
| 46 | * 18.206 clock ticks per second since midnight. |
| 47 | */ |
| 48 | gettimeofday( &tvs, NULL ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 49 | seconds = tvs.tv_sec; |
| 50 | bdtime = localtime( &seconds ); |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 51 | return (((bdtime->tm_hour * 3600 + bdtime->tm_min * 60 + |
| 52 | bdtime->tm_sec) * 18206) / 1000) + |
| 53 | (tvs.tv_usec / 54927); |
| 54 | } |
| 55 | |
| 56 | |
| 57 | /********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 58 | * INT_Int1aHandler (WPROCS.126) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 59 | * |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 60 | * Handler for int 1ah |
| 61 | * 0x00 - 0x07 - date and time |
| 62 | * 0x?? - 0x?? - Microsoft Real Time Compression Interface |
| 63 | */ |
Alexandre Julliard | 617955d | 1999-06-26 18:40:24 +0000 | [diff] [blame] | 64 | void WINAPI INT_Int1aHandler( CONTEXT86 *context ) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 65 | { |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 66 | time_t ltime; |
| 67 | DWORD ticks; |
| 68 | struct tm *bdtime; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 69 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 70 | switch(AH_reg(context)) |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 71 | { |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 72 | case 0x00: |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 73 | ticks = INT1A_GetTicksSinceMidnight(); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 74 | CX_reg(context) = HIWORD(ticks); |
| 75 | DX_reg(context) = LOWORD(ticks); |
| 76 | AX_reg(context) = 0; /* No midnight rollover */ |
Alexandre Julliard | 61fece0 | 1999-06-26 19:09:08 +0000 | [diff] [blame] | 77 | TRACE("int1a: AH=00 -- ticks=%ld\n", ticks); |
Alexandre Julliard | b7258be | 1995-09-01 15:57:28 +0000 | [diff] [blame] | 78 | break; |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 79 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 80 | case 0x02: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 81 | ltime = time(NULL); |
| 82 | bdtime = localtime(<ime); |
| 83 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 84 | CX_reg(context) = (BIN_TO_BCD(bdtime->tm_hour)<<8) | |
| 85 | BIN_TO_BCD(bdtime->tm_min); |
| 86 | DX_reg(context) = (BIN_TO_BCD(bdtime->tm_sec)<<8); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 87 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 88 | case 0x04: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 89 | ltime = time(NULL); |
| 90 | bdtime = localtime(<ime); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 91 | CX_reg(context) = (BIN_TO_BCD(bdtime->tm_year/100)<<8) | |
| 92 | BIN_TO_BCD((bdtime->tm_year-1900)%100); |
| 93 | DX_reg(context) = (BIN_TO_BCD(bdtime->tm_mon)<<8) | |
| 94 | BIN_TO_BCD(bdtime->tm_mday); |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 95 | break; |
| 96 | |
| 97 | /* setting the time,date or RTC is not allow -EB */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 98 | case 0x01: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 99 | /* set system time */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 100 | case 0x03: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 101 | /* set RTC time */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 102 | case 0x05: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 103 | /* set RTC date */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 104 | case 0x06: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 105 | /* set ALARM */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 106 | case 0x07: |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 107 | /* cancel ALARM */ |
| 108 | break; |
| 109 | |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 110 | case 0xb0: /* Microsoft Real Time Compression */ |
| 111 | switch AL_reg(context) |
| 112 | { |
| 113 | case 0x01: |
| 114 | /* not present */ |
| 115 | break; |
| 116 | default: |
| 117 | INT_BARF(context, 0x1a); |
| 118 | } |
| 119 | break; |
| 120 | |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 121 | default: |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 122 | INT_BARF( context, 0x1a ); |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 123 | } |
Alexandre Julliard | 0e60778 | 1993-11-03 19:23:37 +0000 | [diff] [blame] | 124 | } |