Release 980201
[wine/multimedia.git] / msdos / int13.c
blobb46b6a255aa23274784839581800f59340e53fc1
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 #include "stddebug.h"
17 /* #define DEBUG_INT */
18 #include "debug.h"
19 #include "drive.h"
21 /**********************************************************************
22 * INT_Int13Handler
24 * Handler for int 13h (disk I/O).
26 void WINAPI INT_Int13Handler( CONTEXT *context )
28 switch(AH_reg(context))
30 case 0x00: /* RESET DISK SYSTEM */
31 case 0x04: /* VERIFY DISK SECTOR(S) */
32 AH_reg(context) = 0;
33 break;
35 case 0x05: /* FORMAT TRACK */
36 case 0x06: /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
37 case 0x07: /* FORMAT DRIVE STARTING AT GIVEN TRACK */
38 /* despite what Ralf Brown says, 0x06 and 0x07 seem to
39 * set CFLAG, too (at least my BIOS does that) */
40 AH_reg(context) = 0x0c;
41 SET_CFLAG(context);
42 break;
44 case 0x08: /* GET DRIVE PARAMETERS */
45 if (DL_reg(context) & 0x80) { /* hard disk ? */
46 AH_reg(context) = 0x07;
47 SET_CFLAG(context);
49 else { /* floppy disk */
50 #ifdef linux
51 unsigned int i, nr_of_drives = 0;
52 BYTE drive_nr = DL_reg(context);
53 int floppy_fd;
54 struct floppy_drive_params floppy_parm;
56 AH_reg(context) = 0x00; /* success */
58 for (i = 0; i < MAX_DOS_DRIVES; i++)
59 if (DRIVE_GetType(i) == TYPE_FLOPPY) nr_of_drives++;
60 DL_reg(context) = nr_of_drives;
62 if (drive_nr > 1) { /* invalid drive ? */
63 BX_reg(context) = 0;
64 CX_reg(context) = 0;
65 DH_reg(context) = 0;
66 break;
69 if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
71 fprintf(stderr, "INT 0x13 (GET DRIVE PARAMETERS): can't determine floppy geometry !\n");
72 BX_reg(context) = 0;
73 CX_reg(context) = 0;
74 DH_reg(context) = 0;
75 break;
77 ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
78 close(floppy_fd);
80 BL_reg(context) = floppy_parm.cmos;
82 /* CH = low eight bits of max cyl
83 CL = max sec nr (bits 5-0),
84 hi two bits of max cyl (bits 7-6)
85 DH = max head nr */
86 DH_reg(context) = 0x01;
87 switch (BL_reg(context))
89 case 0: /* no drive */
90 CX_reg(context) = 0x0;
91 DX_reg(context) = 0x0;
92 break;
93 case 1: /* 360 K */
94 CX_reg(context) = 0x2709;
95 break;
96 case 2: /* 1.2 M */
97 CX_reg(context) = 0x4f0f;
98 break;
99 case 3: /* 720 K */
100 CX_reg(context) = 0x4f09;
101 break;
102 case 4: /* 1.44 M */
103 CX_reg(context) = 0x4f12;
104 break;
105 case 5:
106 case 6: /* 2.88 M */
107 CX_reg(context) = 0x4f24;
108 break;
110 ES_reg(context) = 0x0000; /* FIXME: drive parameter table */
111 DI_reg(context) = 0x0000;
112 #else
113 AH_reg(context) = 0x01;
114 SET_CFLAG(context);
115 break;
116 #endif
118 break;
120 case 0x09: /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
121 case 0x0c: /* SEEK TO CYLINDER */
122 case 0x0d: /* RESET HARD DISKS */
123 case 0x10: /* CHECK IF DRIVE READY */
124 case 0x11: /* RECALIBRATE DRIVE */
125 case 0x14: /* CONTROLLER INTERNAL DIAGNOSTIC */
126 AH_reg(context) = 0;
127 break;
129 case 0x0e: /* READ SECTOR BUFFER (XT only) */
130 case 0x0f: /* WRITE SECTOR BUFFER (XT only) */
131 case 0x12: /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
132 case 0x13: /* DRIVE DIAGNOSTIC (XT,PS) */
133 AH_reg(context) = 0x01;
134 SET_CFLAG(context);
135 break;
137 default:
138 INT_BARF( context, 0x13 );