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/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 char root[] = "A:\\";
103 TRACE("in [ EDX=%08lx ]\n", context->Edx );
105 SET_AL( context, 0 );
106 SET_BX( context, 0 );
107 SET_CX( context, 0 );
108 SET_DH( context, 0 );
110 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
111 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
112 SET_DL( context, nr_of_drives );
115 /* invalid drive ? */
116 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
120 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_RDONLY|O_NONBLOCK)) == -1)
122 WARN("Can't determine floppy geometry !\n");
123 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
126 r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
132 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
136 SET_BL( context, floppy_parm.cmos );
139 * CH = low eight bits of max cyl
140 * CL = max sec nr (bits 5-0),
141 * hi two bits of max cyl (bits 7-6)
144 if(BL_reg( context ) && BL_reg( context ) < 7)
146 SET_DH( context, 0x01 );
147 SET_CX( context, drive_type_info[BL_reg( context )] );
150 context->Edi = (DWORD)floppy_params[drive_nr];
154 ERR("Get floppy params failed for drive %d\n", drive_nr);
155 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
159 TRACE("out [ EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx EDI=%08lx ]\n",
160 context->Eax, context->Ebx, context->Ecx, context->Edx, context->Edi);
162 INT13_SetStatus( context, 0x00 ); /* success */
164 /* FIXME: Word exits quietly if we return with no error. Why? */
165 FIXME("Returned ERROR!\n");
166 SET_CFLAG( context );
169 INT13_SetStatus( context, 0x01 ); /* invalid function */
174 /**********************************************************************
175 * DOSVM_Int13Handler (WINEDOS16.119)
177 * Handler for int 13h (disk I/O).
179 void WINAPI DOSVM_Int13Handler( CONTEXT86 *context )
181 TRACE( "AH=%02x\n", AH_reg( context ) );
183 switch( AH_reg( context ) )
185 case 0x00: /* RESET DISK SYSTEM */
186 INT13_SetStatus( context, 0x00 ); /* success */
189 case 0x01: /* STATUS OF DISK SYSTEM */
190 INT13_SetStatus( context, INT13_last_status );
193 case 0x02: /* READ SECTORS INTO MEMORY */
194 SET_AL( context, 0 ); /* number of sectors transferred */
195 INT13_SetStatus( context, 0x00 ); /* success */
198 case 0x03: /* WRITE SECTORS FROM MEMORY */
199 SET_AL( context, 0 ); /* number of sectors transferred */
200 INT13_SetStatus( context, 0x00 ); /* success */
203 case 0x04: /* VERIFY DISK SECTOR(S) */
204 SET_AL( context, 0 ); /* number of sectors verified */
205 INT13_SetStatus( context, 0x00 ); /* success */
208 case 0x05: /* FORMAT TRACK */
209 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
210 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
211 INT13_SetStatus( context, 0x0c ); /* unsupported track or invalid media */
214 case 0x08: /* GET DRIVE PARAMETERS */
215 if (DL_reg( context ) & 0x80)
218 INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */
223 INT13_ReadFloppyParams( context );
227 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
228 case 0x0a: /* FIXED DISK - READ LONG */
229 case 0x0b: /* FIXED DISK - WRITE LONG */
230 case 0x0c: /* SEEK TO CYLINDER */
231 case 0x0d: /* ALTERNATE RESET HARD DISK */
232 INT13_SetStatus( context, 0x00 ); /* success */
235 case 0x0e: /* READ SECTOR BUFFER */
236 case 0x0f: /* WRITE SECTOR BUFFER */
237 INT13_SetStatus( context, 0x01 ); /* invalid function */
240 case 0x10: /* CHECK IF DRIVE READY */
241 case 0x11: /* RECALIBRATE DRIVE */
242 INT13_SetStatus( context, 0x00 ); /* success */
245 case 0x12: /* CONTROLLER RAM DIAGNOSTIC */
246 case 0x13: /* DRIVE DIAGNOSTIC */
247 INT13_SetStatus( context, 0x01 ); /* invalid function */
250 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
251 INT13_SetStatus( context, 0x00 ); /* success */
254 case 0x15: /* GET DISK TYPE */
255 if (DL_reg( context ) & 0x80)
258 INT13_SetStatus( context, 0x00 ); /* success */
259 /* type is fixed disk, overwrites status */
260 SET_AH( context, 0x03 );
265 INT13_SetStatus( context, 0x00 ); /* success */
266 /* type is floppy with change detection, overwrites status */
267 SET_AH( context, 0x02 );
271 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
272 INT13_SetStatus( context, 0x00 ); /* success */
275 case 0x17: /* SET DISK TYPE FOR FORMAT */
276 if (DL_reg( context ) < 4)
277 INT13_SetStatus( context, 0x00 ); /* successful completion */
279 INT13_SetStatus( context, 0x01 ); /* error */
282 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
283 if (DL_reg( context ) < 4)
284 INT13_SetStatus( context, 0x00 ); /* success */
286 INT13_SetStatus( context, 0x01 ); /* error */
289 case 0x19: /* FIXED DISK - PARK HEADS */
290 INT13_SetStatus( context, 0x00 ); /* success */
294 INT_BARF( context, 0x13 );
295 INT13_SetStatus( context, 0x01 ); /* invalid function */