Avoid overflow in the read file limit check.
[wine] / dlls / winedos / int1a.c
1 /*
2  * BIOS interrupt 1ah handler
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
19  */
20
21 #include "config.h"
22 #include "wine/debug.h"
23 #include "dosexe.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(int);
26
27 #define BCD_TO_BIN(x) ((x&15) + (x>>4)*10)
28 #define BIN_TO_BCD(x) ((x%10) + ((x/10)<<4))
29
30
31 /**********************************************************************
32  *         DOSVM_Int1aHandler
33  *
34  * Handler for int 1ah.
35  */
36 void WINAPI DOSVM_Int1aHandler( CONTEXT86 *context )
37 {
38     switch(AH_reg(context))
39     {
40     case 0x00: /* GET SYSTEM TIME */
41         {
42             BIOSDATA *data = DOSVM_BiosData();
43             SET_CX( context, HIWORD(data->Ticks) );
44             SET_DX( context, LOWORD(data->Ticks) );
45             SET_AL( context, 0 ); /* FIXME: midnight flag is unsupported */
46             TRACE( "GET SYSTEM TIME - ticks=%ld\n", data->Ticks );
47         }
48         break;
49
50     case 0x01: /* SET SYSTEM TIME */
51         FIXME( "SET SYSTEM TIME - not allowed\n" );
52         break;
53
54     case 0x02: /* GET REAL-TIME CLOCK TIME */
55         TRACE( "GET REAL-TIME CLOCK TIME\n" );
56         {
57             SYSTEMTIME systime;
58             GetLocalTime( &systime );
59             SET_CH( context, BIN_TO_BCD(systime.wHour) );
60             SET_CL( context, BIN_TO_BCD(systime.wMinute) );
61             SET_DH( context, BIN_TO_BCD(systime.wSecond) );
62             SET_DL( context, 0 ); /* FIXME: assume no daylight saving */
63             RESET_CFLAG(context);
64         }
65         break;
66
67     case 0x03: /* SET REAL-TIME CLOCK TIME */
68         FIXME( "SET REAL-TIME CLOCK TIME - not allowed\n" );
69         break;
70
71     case 0x04: /* GET REAL-TIME CLOCK DATE */
72         TRACE( "GET REAL-TIME CLOCK DATE\n" );
73         {
74             SYSTEMTIME systime;
75             GetLocalTime( &systime );
76             SET_CH( context, BIN_TO_BCD(systime.wYear / 100) );
77             SET_CL( context, BIN_TO_BCD(systime.wYear % 100) );
78             SET_DH( context, BIN_TO_BCD(systime.wMonth) );
79             SET_DL( context, BIN_TO_BCD(systime.wDay) );
80             RESET_CFLAG(context);
81         }
82         break;
83
84     case 0x05: /* SET REAL-TIME CLOCK DATE */
85         FIXME( "SET REAL-TIME CLOCK DATE - not allowed\n" );
86         break;
87
88     case 0x06: /* SET ALARM */
89         FIXME( "SET ALARM - unimplemented\n" );
90         break;
91
92     case 0x07: /* CANCEL ALARM */
93         FIXME( "CANCEL ALARM - unimplemented\n" );
94         break;
95
96     case 0x08: /* SET RTC ACTIVATED POWER ON MODE */
97     case 0x09: /* READ RTC ALARM TIME AND STATUS */
98     case 0x0a: /* READ SYSTEM-TIMER DAY COUNTER */
99     case 0x0b: /* SET SYSTEM-TIMER DAY COUNTER */
100     case 0x0c: /* SET RTC DATE/TIME ACTIVATED POWER-ON MODE */
101     case 0x0d: /* RESET RTC DATE/TIME ACTIVATED POWER-ON MODE */
102     case 0x0e: /* GET RTC DATE/TIME ALARM AND STATUS */
103     case 0x0f: /* INITIALIZE REAL-TIME CLOCK */
104         INT_BARF( context, 0x1a );
105         break;
106
107     case 0xb0:
108         if (CX_reg(context) == 0x4d52 && 
109             DX_reg(context) == 0x4349 && 
110             AL_reg(context) == 0x01)
111         {
112             /*
113              * Microsoft Real-Time Compression Interface (MRCI).
114              * Ignoring this call indicates MRCI is not supported.
115              */
116             TRACE( "Microsoft Real-Time Compression Interface - not supported\n" );
117         }
118         else
119         {
120             INT_BARF(context, 0x1a);
121         }
122         break;
123
124     default:
125         INT_BARF( context, 0x1a );
126     }
127 }