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