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
24 #include <sys/types.h>
29 #ifdef HAVE_SYS_IOCTL_H
30 # include <sys/ioctl.h>
34 # include <linux/fd.h>
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(int);
45 * Status of last int13 operation.
47 static BYTE INT13_last_status;
50 /**********************************************************************
53 * Write status to AH register and set carry flag on error (AH != 0).
55 * Despite what Ralf Brown says, at least functions 0x06 and 0x07
56 * seem to set carry, too.
58 static void INT13_SetStatus( CONTEXT86 *context, BYTE status )
60 INT13_last_status = status;
62 SET_AH( context, status );
67 RESET_CFLAG( context );
71 /**********************************************************************
72 * INT13_ReadFloppyParams
74 * Read floppy disk parameters.
76 static void INT13_ReadFloppyParams( CONTEXT86 *context )
79 static const BYTE floppy_params[2][13] =
81 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 },
82 { 0xaf, 0x02, 0x25, 0x02, 0x12, 0x1b, 0xff, 0x6c, 0xf6, 0x0f, 0x08 }
85 static const DWORD drive_type_info[7]={
96 unsigned int nr_of_drives = 0;
97 BYTE drive_nr = DL_reg( context );
100 struct floppy_drive_params floppy_parm;
101 WCHAR root[] = {'A',':','\\',0}, drive_root[] = {'\\','\\','.','\\','A',':',0};
104 TRACE("in [ EDX=%08lx ]\n", context->Edx );
106 SET_AL( context, 0 );
107 SET_BX( context, 0 );
108 SET_CX( context, 0 );
109 SET_DH( context, 0 );
111 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
112 if (GetDriveTypeW(root) == DRIVE_REMOVABLE) nr_of_drives++;
113 SET_DL( context, nr_of_drives );
116 /* invalid drive ? */
117 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
121 drive_root[4] = 'A' + drive_nr;
122 h = CreateFileW(drive_root, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
123 FILE_FLAG_BACKUP_SEMANTICS, NULL);
124 if (h == INVALID_HANDLE_VALUE ||
125 wine_server_handle_to_fd(h, GENERIC_READ, &floppy_fd, NULL, NULL))
127 WARN("Can't determine floppy geometry !\n");
128 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
131 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
132 wine_server_release_fd( h, floppy_fd );
137 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
141 SET_BL( context, floppy_parm.cmos );
144 * CH = low eight bits of max cyl
145 * CL = max sec nr (bits 5-0),
146 * hi two bits of max cyl (bits 7-6)
149 if(BL_reg( context ) && BL_reg( context ) < 7)
151 SET_DH( context, 0x01 );
152 SET_CX( context, drive_type_info[BL_reg( context )] );
155 context->Edi = (DWORD)floppy_params[drive_nr];
159 ERR("Get floppy params failed for drive %d\n", drive_nr);
160 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
164 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
165 context->Eax, context->Ebx, context->Ecx, context->Edx, context->Edi);
167 INT13_SetStatus( context, 0x00 ); /* success */
169 /* FIXME: Word exits quietly if we return with no error. Why? */
170 FIXME("Returned ERROR!\n");
171 SET_CFLAG( context );
174 INT13_SetStatus( context, 0x01 ); /* invalid function */
179 /**********************************************************************
180 * DOSVM_Int13Handler (WINEDOS16.119)
182 * Handler for int 13h (disk I/O).
184 void WINAPI DOSVM_Int13Handler( CONTEXT86 *context )
186 TRACE( "AH=%02x\n", AH_reg( context ) );
188 switch( AH_reg( context ) )
190 case 0x00: /* RESET DISK SYSTEM */
191 INT13_SetStatus( context, 0x00 ); /* success */
194 case 0x01: /* STATUS OF DISK SYSTEM */
195 INT13_SetStatus( context, INT13_last_status );
198 case 0x02: /* READ SECTORS INTO MEMORY */
199 SET_AL( context, 0 ); /* number of sectors transferred */
200 INT13_SetStatus( context, 0x00 ); /* success */
203 case 0x03: /* WRITE SECTORS FROM MEMORY */
204 SET_AL( context, 0 ); /* number of sectors transferred */
205 INT13_SetStatus( context, 0x00 ); /* success */
208 case 0x04: /* VERIFY DISK SECTOR(S) */
209 SET_AL( context, 0 ); /* number of sectors verified */
210 INT13_SetStatus( context, 0x00 ); /* success */
213 case 0x05: /* FORMAT TRACK */
214 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
215 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
216 INT13_SetStatus( context, 0x0c ); /* unsupported track or invalid media */
219 case 0x08: /* GET DRIVE PARAMETERS */
220 if (DL_reg( context ) & 0x80)
223 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
228 INT13_ReadFloppyParams( context );
232 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
233 case 0x0a: /* FIXED DISK - READ LONG */
234 case 0x0b: /* FIXED DISK - WRITE LONG */
235 case 0x0c: /* SEEK TO CYLINDER */
236 case 0x0d: /* ALTERNATE RESET HARD DISK */
237 INT13_SetStatus( context, 0x00 ); /* success */
240 case 0x0e: /* READ SECTOR BUFFER */
241 case 0x0f: /* WRITE SECTOR BUFFER */
242 INT13_SetStatus( context, 0x01 ); /* invalid function */
245 case 0x10: /* CHECK IF DRIVE READY */
246 case 0x11: /* RECALIBRATE DRIVE */
247 INT13_SetStatus( context, 0x00 ); /* success */
250 case 0x12: /* CONTROLLER RAM DIAGNOSTIC */
251 case 0x13: /* DRIVE DIAGNOSTIC */
252 INT13_SetStatus( context, 0x01 ); /* invalid function */
255 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
256 INT13_SetStatus( context, 0x00 ); /* success */
259 case 0x15: /* GET DISK TYPE */
260 if (DL_reg( context ) & 0x80)
263 INT13_SetStatus( context, 0x00 ); /* success */
264 /* type is fixed disk, overwrites status */
265 SET_AH( context, 0x03 );
270 INT13_SetStatus( context, 0x00 ); /* success */
271 /* type is floppy with change detection, overwrites status */
272 SET_AH( context, 0x02 );
276 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
277 INT13_SetStatus( context, 0x00 ); /* success */
280 case 0x17: /* SET DISK TYPE FOR FORMAT */
281 if (DL_reg( context ) < 4)
282 INT13_SetStatus( context, 0x00 ); /* successful completion */
284 INT13_SetStatus( context, 0x01 ); /* error */
287 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
288 if (DL_reg( context ) < 4)
289 INT13_SetStatus( context, 0x00 ); /* success */
291 INT13_SetStatus( context, 0x01 ); /* error */
294 case 0x19: /* FIXED DISK - PARK HEADS */
295 INT13_SetStatus( context, 0x00 ); /* success */
299 INT_BARF( context, 0x13 );
300 INT13_SetStatus( context, 0x01 ); /* invalid function */