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
23 #include <sys/types.h>
24 #include <sys/ioctl.h>
27 # include <linux/fd.h>
30 /* #define DEBUG_INT */
31 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
36 /**********************************************************************
37 * INT_Int13Handler (WPROCS.119)
39 * Handler for int 13h (disk I/O).
41 void WINAPI INT_Int13Handler( CONTEXT86 *context )
43 switch(AH_reg(context))
45 case 0x00: /* RESET DISK SYSTEM */
46 break; /* no return ? */
47 case 0x01: /* STATUS OF DISK SYSTEM */
48 AL_reg(context) = 0; /* successful completion */
50 case 0x02: /* READ SECTORS INTO MEMORY */
51 AL_reg(context) = 0; /* number of sectors read */
52 AH_reg(context) = 0; /* status */
54 case 0x03: /* WRITE SECTORS FROM MEMORY */
55 break; /* no return ? */
56 case 0x04: /* VERIFY DISK SECTOR(S) */
57 AL_reg(context) = 0; /* number of sectors verified */
61 case 0x05: /* FORMAT TRACK */
62 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
63 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
64 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
65 * set CFLAG, too (at least my BIOS does that) */
66 AH_reg(context) = 0x0c;
70 case 0x08: /* GET DRIVE PARAMETERS */
71 if (DL_reg(context) & 0x80) { /* hard disk ? */
72 AH_reg(context) = 0x07;
75 else { /* floppy disk */
77 unsigned int i, nr_of_drives = 0;
78 BYTE drive_nr = DL_reg(context);
80 struct floppy_drive_params floppy_parm;
83 AH_reg(context) = 0x00; /* success */
85 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
86 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
87 DL_reg(context) = nr_of_drives;
89 if (drive_nr > 1) { /* invalid drive ? */
96 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
98 WARN("(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
104 ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
107 BL_reg(context) = floppy_parm.cmos;
109 /* CH = low eight bits of max cyl
110 CL = max sec nr (bits 5-0),
111 hi two bits of max cyl (bits 7-6)
113 DH_reg(context) = 0x01;
114 switch (BL_reg(context))
116 case 0: /* no drive */
117 CX_reg(context) = 0x0;
118 DX_reg(context) = 0x0;
121 CX_reg(context) = 0x2709;
124 CX_reg(context) = 0x4f0f;
127 CX_reg(context) = 0x4f09;
130 CX_reg(context) = 0x4f12;
134 CX_reg(context) = 0x4f24;
137 context->SegEs = 0x0000; /* FIXME: drive parameter table */
138 DI_reg(context) = 0x0000;
140 AH_reg(context) = 0x01;
147 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
148 case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */
149 case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */
150 case 0x0c: /* SEEK TO CYLINDER */
151 case 0x0d: /* ALTERNATE RESET HARD DISKS */
152 case 0x10: /* CHECK IF DRIVE READY */
153 case 0x11: /* RECALIBRATE DRIVE */
154 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
158 case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
159 if (DL_reg(context) & 0x80) { /* hard disk ? */
160 AH_reg(context) = 3; /* fixed disk */
163 else { /* floppy disk ? */
164 AH_reg(context) = 2; /* floppy with change detection */
168 case 0x0e: /* READ SECTOR BUFFER (XT only) */
169 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
170 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
171 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
172 AH_reg(context) = 0x01;
176 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
177 AH_reg(context) = 0; /* FIXME - no change */
179 case 0x17: /* SET DISK TYPE FOR FORMAT */
180 if (DL_reg(context) < 4)
181 AH_reg(context) = 0x00; /* successful completion */
183 AH_reg(context) = 0x01; /* error */
185 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
186 if (DL_reg(context) < 4)
187 AH_reg(context) = 0x00; /* successful completion */
189 AH_reg(context) = 0x01; /* error */
191 case 0x19: /* FIXED DISK - PARK HEADS */
193 INT_BARF( context, 0x13 );