Add VarParseNumFromStr()/VarNumFromParseNum(), use them for
[wine/multimedia.git] / dlls / winedos / int13.c
blob0fa5416da44a5dd03d7be2e78afcf7d1cf9e8d64
1 /*
2 * BIOS interrupt 13h handler
4 * Copyright 1997 Andreas Mohr
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.
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.
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
21 #include "config.h"
22 #include "miscemu.h"
23 #include "wine/debug.h"
24 #include "drive.h"
26 #include <stdlib.h>
27 #include <sys/types.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
32 #ifdef HAVE_SYS_IOCTL_H
33 # include <sys/ioctl.h>
34 #endif
35 #include <fcntl.h>
36 #ifdef linux
37 # include <linux/fd.h>
38 #endif
40 WINE_DEFAULT_DEBUG_CHANNEL(int);
44 * Status of last int13 operation.
46 static BYTE INT13_last_status;
49 /**********************************************************************
50 * INT13_SetStatus
52 * Write status to AH register and set carry flag on error (AH != 0).
54 * Despite what Ralf Brown says, at least functions 0x06 and 0x07
55 * seem to set carry, too.
57 static void INT13_SetStatus( CONTEXT86 *context, BYTE status )
59 INT13_last_status = status;
61 SET_AH( context, status );
63 if (status)
64 SET_CFLAG( context );
65 else
66 RESET_CFLAG( context );
70 /**********************************************************************
71 * INT13_ReadFloppyParams
73 * Read floppy disk parameters.
75 static void INT13_ReadFloppyParams( CONTEXT86 *context )
77 #ifdef linux
78 static const BYTE floppy_params[2][13] =
80 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
81 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
84 static const DWORD drive_type_info[7]={
85 0x0000, /* none */
86 0x2709, /* 360 K */
87 0x4f0f, /* 1.2 M */
88 0x4f09, /* 720 K */
89 0x4f12, /* 1.44 M */
90 0x4f24, /* 2.88 M */
91 0x4f24 /* 2.88 M */
94 unsigned int i;
95 unsigned int nr_of_drives = 0;
96 BYTE drive_nr = DL_reg( context );
97 int floppy_fd;
98 int r;
99 struct floppy_drive_params floppy_parm;
100 char root[] = "A:\\";
102 TRACE("in [ EDX=%08lx ]\n", context->Edx );
104 SET_AL( context, 0 );
105 SET_BX( context, 0 );
106 SET_CX( context, 0 );
107 SET_DH( context, 0 );
109 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
110 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
111 SET_DL( context, nr_of_drives );
113 if (drive_nr > 1) {
114 /* invalid drive ? */
115 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
116 return;
119 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_RDONLY|O_NONBLOCK)) == -1)
121 WARN("Can't determine floppy geometry !\n");
122 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
123 return;
125 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
127 close(floppy_fd);
129 if(r<0)
131 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
132 return;
135 SET_BL( context, floppy_parm.cmos );
138 * CH = low eight bits of max cyl
139 * CL = max sec nr (bits 5-0),
140 * hi two bits of max cyl (bits 7-6)
141 * DH = max head nr
143 if(BL_reg( context ) && BL_reg( context ) < 7)
145 SET_DH( context, 0x01 );
146 SET_CX( context, drive_type_info[BL_reg( context )] );
149 context->Edi = (DWORD)floppy_params[drive_nr];
151 if(!context->Edi)
153 ERR("Get floppy params failed for drive %d\n", drive_nr);
154 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
155 return;
158 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
159 context->Eax, context->Ebx, context->Ecx, context->Edx, context->Edi);
161 INT13_SetStatus( context, 0x00 ); /* success */
163 /* FIXME: Word exits quietly if we return with no error. Why? */
164 FIXME("Returned ERROR!\n");
165 SET_CFLAG( context );
167 #else
168 INT13_SetStatus( context, 0x01 ); /* invalid function */
169 #endif
173 /**********************************************************************
174 * DOSVM_Int13Handler (WINEDOS16.119)
176 * Handler for int 13h (disk I/O).
178 void WINAPI DOSVM_Int13Handler( CONTEXT86 *context )
180 TRACE( "AH=%02x\n", AH_reg( context ) );
182 switch( AH_reg( context ) )
184 case 0x00: /* RESET DISK SYSTEM */
185 INT13_SetStatus( context, 0x00 ); /* success */
186 break;
188 case 0x01: /* STATUS OF DISK SYSTEM */
189 INT13_SetStatus( context, INT13_last_status );
190 break;
192 case 0x02: /* READ SECTORS INTO MEMORY */
193 SET_AL( context, 0 ); /* number of sectors transferred */
194 INT13_SetStatus( context, 0x00 ); /* success */
195 break;
197 case 0x03: /* WRITE SECTORS FROM MEMORY */
198 SET_AL( context, 0 ); /* number of sectors transferred */
199 INT13_SetStatus( context, 0x00 ); /* success */
200 break;
202 case 0x04: /* VERIFY DISK SECTOR(S) */
203 SET_AL( context, 0 ); /* number of sectors verified */
204 INT13_SetStatus( context, 0x00 ); /* success */
205 break;
207 case 0x05: /* FORMAT TRACK */
208 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
209 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
210 INT13_SetStatus( context, 0x0c ); /* unsupported track or invalid media */
211 break;
213 case 0x08: /* GET DRIVE PARAMETERS */
214 if (DL_reg( context ) & 0x80)
216 /* hard disk ? */
217 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
219 else
221 /* floppy disk */
222 INT13_ReadFloppyParams( context );
224 break;
226 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
227 case 0x0a: /* FIXED DISK - READ LONG */
228 case 0x0b: /* FIXED DISK - WRITE LONG */
229 case 0x0c: /* SEEK TO CYLINDER */
230 case 0x0d: /* ALTERNATE RESET HARD DISK */
231 INT13_SetStatus( context, 0x00 ); /* success */
232 break;
234 case 0x0e: /* READ SECTOR BUFFER */
235 case 0x0f: /* WRITE SECTOR BUFFER */
236 INT13_SetStatus( context, 0x01 ); /* invalid function */
237 break;
239 case 0x10: /* CHECK IF DRIVE READY */
240 case 0x11: /* RECALIBRATE DRIVE */
241 INT13_SetStatus( context, 0x00 ); /* success */
242 break;
244 case 0x12: /* CONTROLLER RAM DIAGNOSTIC */
245 case 0x13: /* DRIVE DIAGNOSTIC */
246 INT13_SetStatus( context, 0x01 ); /* invalid function */
247 break;
249 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
250 INT13_SetStatus( context, 0x00 ); /* success */
251 break;
253 case 0x15: /* GET DISK TYPE */
254 if (DL_reg( context ) & 0x80)
256 /* hard disk ? */
257 INT13_SetStatus( context, 0x00 ); /* success */
258 /* type is fixed disk, overwrites status */
259 SET_AH( context, 0x03 );
261 else
263 /* floppy disk */
264 INT13_SetStatus( context, 0x00 ); /* success */
265 /* type is floppy with change detection, overwrites status */
266 SET_AH( context, 0x02 );
268 break;
270 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
271 INT13_SetStatus( context, 0x00 ); /* success */
272 break;
274 case 0x17: /* SET DISK TYPE FOR FORMAT */
275 if (DL_reg( context ) < 4)
276 INT13_SetStatus( context, 0x00 ); /* successful completion */
277 else
278 INT13_SetStatus( context, 0x01 ); /* error */
279 break;
281 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
282 if (DL_reg( context ) < 4)
283 INT13_SetStatus( context, 0x00 ); /* success */
284 else
285 INT13_SetStatus( context, 0x01 ); /* error */
286 break;
288 case 0x19: /* FIXED DISK - PARK HEADS */
289 INT13_SetStatus( context, 0x00 ); /* success */
290 break;
292 default:
293 INT_BARF( context, 0x13 );
294 INT13_SetStatus( context, 0x01 ); /* invalid function */