blob: dd5fe89d47b7790b047f537109457cbab4912641 [file] [log] [blame]
Alexandre Julliard9ea19e51997-01-01 17:29:55 +00001/*
2 * BIOS interrupt 13h handler
3 */
4
Alexandre Julliard7e50df31994-08-06 11:22:41 +00005#include <stdlib.h>
Alexandre Julliard60ce85c1998-02-01 18:33:27 +00006#include <unistd.h>
7#include <sys/types.h>
Alexandre Julliard60ce85c1998-02-01 18:33:27 +00008#include <sys/ioctl.h>
9#include <fcntl.h>
10#ifdef linux
Marcus Meissner3f1ed522001-05-14 20:09:37 +000011# include <linux/fd.h>
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000012#endif
Alexandre Julliard234bc241994-12-10 13:02:28 +000013#include "miscemu.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000014/* #define DEBUG_INT */
Alexandre Julliard61fece01999-06-26 19:09:08 +000015#include "debugtools.h"
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000016#include "drive.h"
Alexandre Julliarde2abbb11995-03-19 17:39:39 +000017
Dimitrie O. Paun529da542000-11-27 23:54:25 +000018DEFAULT_DEBUG_CHANNEL(int);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000019
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000020/**********************************************************************
Patrik Stridvall3ca98232001-06-20 23:03:14 +000021 * INT_Int13Handler (WPROCS.119)
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000022 *
23 * Handler for int 13h (disk I/O).
24 */
Alexandre Julliard617955d1999-06-26 18:40:24 +000025void WINAPI INT_Int13Handler( CONTEXT86 *context )
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000026{
Alexandre Julliardca22b331996-07-12 19:02:39 +000027 switch(AH_reg(context))
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000028 {
Alexandre Julliard7e50df31994-08-06 11:22:41 +000029 case 0x00: /* RESET DISK SYSTEM */
Joseph Pranevichf217cf51998-10-24 10:35:11 +000030 break; /* no return ? */
31 case 0x01: /* STATUS OF DISK SYSTEM */
32 AL_reg(context) = 0; /* successful completion */
33 break;
34 case 0x02: /* READ SECTORS INTO MEMORY */
35 AL_reg(context) = 0; /* number of sectors read */
36 AH_reg(context) = 0; /* status */
37 break;
38 case 0x03: /* WRITE SECTORS FROM MEMORY */
39 break; /* no return ? */
Alexandre Julliard7e50df31994-08-06 11:22:41 +000040 case 0x04: /* VERIFY DISK SECTOR(S) */
Joseph Pranevichf217cf51998-10-24 10:35:11 +000041 AL_reg(context) = 0; /* number of sectors verified */
Alexandre Julliardca22b331996-07-12 19:02:39 +000042 AH_reg(context) = 0;
Alexandre Julliard7e50df31994-08-06 11:22:41 +000043 break;
44
45 case 0x05: /* FORMAT TRACK */
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000046 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
47 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000048 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
49 * set CFLAG, too (at least my BIOS does that) */
50 AH_reg(context) = 0x0c;
51 SET_CFLAG(context);
52 break;
Alexandre Julliard7e50df31994-08-06 11:22:41 +000053
Alexandre Julliard7e50df31994-08-06 11:22:41 +000054 case 0x08: /* GET DRIVE PARAMETERS */
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000055 if (DL_reg(context) & 0x80) { /* hard disk ? */
56 AH_reg(context) = 0x07;
57 SET_CFLAG(context);
58 }
59 else { /* floppy disk */
60#ifdef linux
61 unsigned int i, nr_of_drives = 0;
62 BYTE drive_nr = DL_reg(context);
63 int floppy_fd;
64 struct floppy_drive_params floppy_parm;
Alexandre Julliardbf672592000-12-12 00:44:42 +000065 char root[] = "A:\\";
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000066
67 AH_reg(context) = 0x00; /* success */
68
Alexandre Julliardbf672592000-12-12 00:44:42 +000069 for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++)
70 if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++;
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000071 DL_reg(context) = nr_of_drives;
72
73 if (drive_nr > 1) { /* invalid drive ? */
74 BX_reg(context) = 0;
75 CX_reg(context) = 0;
76 DH_reg(context) = 0;
77 break;
78 }
79
80 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
81 {
Alexandre Julliard61fece01999-06-26 19:09:08 +000082 WARN("(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
Alexandre Julliard60ce85c1998-02-01 18:33:27 +000083 BX_reg(context) = 0;
84 CX_reg(context) = 0;
85 DH_reg(context) = 0;
86 break;
87 }
88 ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
89 close(floppy_fd);
90
91 BL_reg(context) = floppy_parm.cmos;
92
93 /* CH = low eight bits of max cyl
94 CL = max sec nr (bits 5-0),
95 hi two bits of max cyl (bits 7-6)
96 DH = max head nr */
97 DH_reg(context) = 0x01;
98 switch (BL_reg(context))
99 {
100 case 0: /* no drive */
101 CX_reg(context) = 0x0;
102 DX_reg(context) = 0x0;
103 break;
104 case 1: /* 360 K */
105 CX_reg(context) = 0x2709;
106 break;
107 case 2: /* 1.2 M */
108 CX_reg(context) = 0x4f0f;
109 break;
110 case 3: /* 720 K */
111 CX_reg(context) = 0x4f09;
112 break;
113 case 4: /* 1.44 M */
114 CX_reg(context) = 0x4f12;
115 break;
116 case 5:
117 case 6: /* 2.88 M */
118 CX_reg(context) = 0x4f24;
119 break;
120 }
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000121 context->SegEs = 0x0000; /* FIXME: drive parameter table */
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000122 DI_reg(context) = 0x0000;
123#else
124 AH_reg(context) = 0x01;
125 SET_CFLAG(context);
126 break;
127#endif
128 }
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000129 break;
130
131 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000132 case 0x0a: /* FIXED DISK - READ LONG (XT,AT,XT286,PS) */
133 case 0x0b: /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS) */
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000134 case 0x0c: /* SEEK TO CYLINDER */
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000135 case 0x0d: /* ALTERNATE RESET HARD DISKS */
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000136 case 0x10: /* CHECK IF DRIVE READY */
137 case 0x11: /* RECALIBRATE DRIVE */
138 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
Alexandre Julliardca22b331996-07-12 19:02:39 +0000139 AH_reg(context) = 0;
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000140 break;
141
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000142 case 0x15: /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
143 if (DL_reg(context) & 0x80) { /* hard disk ? */
144 AH_reg(context) = 3; /* fixed disk */
145 SET_CFLAG(context);
146 }
147 else { /* floppy disk ? */
148 AH_reg(context) = 2; /* floppy with change detection */
149 SET_CFLAG(context);
150 }
151 break;
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000152 case 0x0e: /* READ SECTOR BUFFER (XT only) */
153 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
154 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
155 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
Alexandre Julliardca22b331996-07-12 19:02:39 +0000156 AH_reg(context) = 0x01;
157 SET_CFLAG(context);
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000158 break;
159
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000160 case 0x16: /* FLOPPY - CHANGE OF DISK STATUS */
161 AH_reg(context) = 0; /* FIXME - no change */
162 break;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000163 case 0x17: /* SET DISK TYPE FOR FORMAT */
164 if (DL_reg(context) < 4)
165 AH_reg(context) = 0x00; /* successful completion */
166 else
167 AH_reg(context) = 0x01; /* error */
168 break;
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000169 case 0x18: /* SET MEDIA TYPE FOR FORMAT */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000170 if (DL_reg(context) < 4)
171 AH_reg(context) = 0x00; /* successful completion */
172 else
173 AH_reg(context) = 0x01; /* error */
174 break;
Joseph Pranevichf217cf51998-10-24 10:35:11 +0000175 case 0x19: /* FIXED DISK - PARK HEADS */
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000176 default:
Alexandre Julliardca22b331996-07-12 19:02:39 +0000177 INT_BARF( context, 0x13 );
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000178 }
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000179}