Added a lost entry for last release.
[wine/multimedia.git] / msdos / int13.c
blobdc4211907e573701ddcad1a9a9ebcad4e026ba37
1 /*
2 * BIOS interrupt 13h handler
3 */
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/ioctl.h>
10 #include <fcntl.h>
11 #ifdef linux
12 #include <linux/fd.h>
13 #endif
14 #include "miscemu.h"
15 /* #define DEBUG_INT */
16 #include "debug.h"
17 #include "drive.h"
19 /**********************************************************************
20 * INT_Int13Handler
22 * Handler for int 13h (disk I/O).
24 void WINAPI INT_Int13Handler( CONTEXT *context )
26 switch(AH_reg(context))
28 case 0x00: /* RESET DISK SYSTEM */
29 case 0x04: /* VERIFY DISK SECTOR(S) */
30 AH_reg(context) = 0;
31 break;
33 case 0x05: /* FORMAT TRACK */
34 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
35 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
36 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
37 * set CFLAG, too (at least my BIOS does that) */
38 AH_reg(context) = 0x0c;
39 SET_CFLAG(context);
40 break;
42 case 0x08: /* GET DRIVE PARAMETERS */
43 if (DL_reg(context) & 0x80) { /* hard disk ? */
44 AH_reg(context) = 0x07;
45 SET_CFLAG(context);
47 else { /* floppy disk */
48 #ifdef linux
49 unsigned int i, nr_of_drives = 0;
50 BYTE drive_nr = DL_reg(context);
51 int floppy_fd;
52 struct floppy_drive_params floppy_parm;
54 AH_reg(context) = 0x00; /* success */
56 for (i = 0; i < MAX_DOS_DRIVES; i++)
57 if (DRIVE_GetType(i) == TYPE_FLOPPY) nr_of_drives++;
58 DL_reg(context) = nr_of_drives;
60 if (drive_nr > 1) { /* invalid drive ? */
61 BX_reg(context) = 0;
62 CX_reg(context) = 0;
63 DH_reg(context) = 0;
64 break;
67 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
69 WARN(int, "(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
70 BX_reg(context) = 0;
71 CX_reg(context) = 0;
72 DH_reg(context) = 0;
73 break;
75 ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
76 close(floppy_fd);
78 BL_reg(context) = floppy_parm.cmos;
80 /* CH = low eight bits of max cyl
81 CL = max sec nr (bits 5-0),
82 hi two bits of max cyl (bits 7-6)
83 DH = max head nr */
84 DH_reg(context) = 0x01;
85 switch (BL_reg(context))
87 case 0: /* no drive */
88 CX_reg(context) = 0x0;
89 DX_reg(context) = 0x0;
90 break;
91 case 1: /* 360 K */
92 CX_reg(context) = 0x2709;
93 break;
94 case 2: /* 1.2 M */
95 CX_reg(context) = 0x4f0f;
96 break;
97 case 3: /* 720 K */
98 CX_reg(context) = 0x4f09;
99 break;
100 case 4: /* 1.44 M */
101 CX_reg(context) = 0x4f12;
102 break;
103 case 5:
104 case 6: /* 2.88 M */
105 CX_reg(context) = 0x4f24;
106 break;
108 ES_reg(context) = 0x0000; /* FIXME: drive parameter table */
109 DI_reg(context) = 0x0000;
110 #else
111 AH_reg(context) = 0x01;
112 SET_CFLAG(context);
113 break;
114 #endif
116 break;
118 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
119 case 0x0c: /* SEEK TO CYLINDER */
120 case 0x0d: /* RESET HARD DISKS */
121 case 0x10: /* CHECK IF DRIVE READY */
122 case 0x11: /* RECALIBRATE DRIVE */
123 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
124 AH_reg(context) = 0;
125 break;
127 case 0x0e: /* READ SECTOR BUFFER (XT only) */
128 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
129 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
130 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
131 AH_reg(context) = 0x01;
132 SET_CFLAG(context);
133 break;
135 case 0x17: /* SET DISK TYPE FOR FORMAT */
136 if (DL_reg(context) < 4)
137 AH_reg(context) = 0x00; /* successful completion */
138 else
139 AH_reg(context) = 0x01; /* error */
140 break;
141 case 0x18:
142 if (DL_reg(context) < 4)
143 AH_reg(context) = 0x00; /* successful completion */
144 else
145 AH_reg(context) = 0x01; /* error */
146 break;
147 default:
148 INT_BARF( context, 0x13 );