Added int 0x09 and int 0x33.
[wine] / msdos / int13.c
1 /*
2  * BIOS interrupt 13h handler
3  */
4
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"
18
19 /**********************************************************************
20  *          INT_Int13Handler
21  *
22  * Handler for int 13h (disk I/O).
23  */
24 void WINAPI INT_Int13Handler( CONTEXT *context )
25 {
26     switch(AH_reg(context))
27     {
28         case 0x00:                            /* RESET DISK SYSTEM     */
29                 break; /* no return ? */
30         case 0x01:                            /* STATUS OF DISK SYSTEM */
31                 AL_reg(context) = 0; /* successful completion */
32                 break;
33         case 0x02:                            /* READ SECTORS INTO MEMORY */
34                 AL_reg(context) = 0; /* number of sectors read */
35                 AH_reg(context) = 0; /* status */
36                 break;
37         case 0x03:                            /* WRITE SECTORS FROM MEMORY */
38                 break; /* no return ? */
39         case 0x04:                            /* VERIFY DISK SECTOR(S) */
40                 AL_reg(context) = 0; /* number of sectors verified */
41                 AH_reg(context) = 0;
42                 break;
43                
44         case 0x05:                                     /* FORMAT TRACK */
45         case 0x06:             /* FORMAT TRACK AND SET BAD SECTOR FLAGS */
46         case 0x07:             /* FORMAT DRIVE STARTING AT GIVEN TRACK  */
47             /* despite what Ralf Brown says, 0x06 and 0x07 seem to
48              * set CFLAG, too (at least my BIOS does that) */
49             AH_reg(context) = 0x0c;
50             SET_CFLAG(context);
51             break;
52
53         case 0x08:                              /* GET DRIVE PARAMETERS  */
54                 if (DL_reg(context) & 0x80) { /* hard disk ? */
55                         AH_reg(context) = 0x07;
56                         SET_CFLAG(context);
57                 }
58                 else { /* floppy disk */
59 #ifdef linux
60                         unsigned int i, nr_of_drives = 0;                       
61                         BYTE drive_nr = DL_reg(context);
62                         int floppy_fd;
63                         struct floppy_drive_params floppy_parm;
64
65                         AH_reg(context) = 0x00; /* success */
66
67                         for (i = 0; i < MAX_DOS_DRIVES; i++)
68                         if (DRIVE_GetType(i) == TYPE_FLOPPY) nr_of_drives++;
69                         DL_reg(context) = nr_of_drives;
70
71                         if (drive_nr > 1) { /* invalid drive ? */
72                                 BX_reg(context) = 0;
73                                 CX_reg(context) = 0;
74                                 DH_reg(context) = 0;
75                                 break;
76                         }
77
78                         if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_NONBLOCK)) == -1)
79                         {
80                                 WARN(int, "(GET DRIVE PARAMETERS): Can't determine floppy geometry !\n");
81                                 BX_reg(context) = 0;
82                                 CX_reg(context) = 0;
83                                 DH_reg(context) = 0;
84                                 break;
85                         }
86                         ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
87                         close(floppy_fd);
88
89                         BL_reg(context) = floppy_parm.cmos;
90
91                         /* CH = low eight bits of max cyl
92                            CL = max sec nr (bits 5-0),
93                            hi two bits of max cyl (bits 7-6)
94                            DH = max head nr */ 
95                         DH_reg(context) = 0x01;
96                         switch (BL_reg(context))
97                         {
98                             case 0: /* no drive */
99                                 CX_reg(context) = 0x0;
100                                 DX_reg(context) = 0x0;
101                                 break;
102                             case 1: /* 360 K */
103                                 CX_reg(context) = 0x2709;
104                                 break;
105                             case 2: /* 1.2 M */
106                                 CX_reg(context) = 0x4f0f;
107                                 break;
108                             case 3: /* 720 K */
109                                 CX_reg(context) = 0x4f09;
110                                 break;
111                             case 4: /* 1.44 M */
112                                 CX_reg(context) = 0x4f12;
113                                 break;
114                             case 5:
115                             case 6: /* 2.88 M */
116                                 CX_reg(context) = 0x4f24;
117                                 break;
118                         }
119                         ES_reg(context) = 0x0000; /* FIXME: drive parameter table */
120                         DI_reg(context) = 0x0000;
121 #else
122                         AH_reg(context) = 0x01;
123                         SET_CFLAG(context);
124                         break;
125 #endif
126                 }
127                 break;
128
129         case 0x09:         /* INITIALIZE CONTROLLER WITH DRIVE PARAMETERS */
130         case 0x0a:         /* FIXED DISK - READ LONG (XT,AT,XT286,PS)     */
131         case 0x0b:         /* FIXED DISK - WRITE LONG (XT,AT,XT286,PS)    */
132         case 0x0c:         /* SEEK TO CYLINDER                            */
133         case 0x0d:         /* ALTERNATE RESET HARD DISKS                  */
134         case 0x10:         /* CHECK IF DRIVE READY                        */
135         case 0x11:         /* RECALIBRATE DRIVE                           */
136         case 0x14:         /* CONTROLLER INTERNAL DIAGNOSTIC              */
137                 AH_reg(context) = 0;
138                 break;
139
140         case 0x15:         /* GET DISK TYPE (AT,XT2,XT286,CONV,PS) */
141                 if (DL_reg(context) & 0x80) { /* hard disk ? */
142                         AH_reg(context) = 3; /* fixed disk */
143                         SET_CFLAG(context);
144                 }
145                 else { /* floppy disk ? */
146                         AH_reg(context) = 2; /* floppy with change detection */
147                         SET_CFLAG(context);
148                 }
149                 break;
150         case 0x0e:                    /* READ SECTOR BUFFER (XT only)      */
151         case 0x0f:                    /* WRITE SECTOR BUFFER (XT only)     */
152         case 0x12:                    /* CONTROLLER RAM DIAGNOSTIC (XT,PS) */
153         case 0x13:                    /* DRIVE DIAGNOSTIC (XT,PS)          */
154                 AH_reg(context) = 0x01;
155                 SET_CFLAG(context);
156                 break;
157
158         case 0x16:         /* FLOPPY - CHANGE OF DISK STATUS */
159                 AH_reg(context) = 0; /* FIXME - no change */
160                 break;
161         case 0x17:         /* SET DISK TYPE FOR FORMAT */
162                 if (DL_reg(context) < 4)
163                     AH_reg(context) = 0x00; /* successful completion */
164                 else
165                     AH_reg(context) = 0x01; /* error */
166                 break;
167         case 0x18:         /* SET MEDIA TYPE FOR FORMAT */
168                 if (DL_reg(context) < 4)
169                     AH_reg(context) = 0x00; /* successful completion */
170                 else
171                     AH_reg(context) = 0x01; /* error */
172                 break;
173         case 0x19:         /* FIXED DISK - PARK HEADS */
174         default:
175                 INT_BARF( context, 0x13 );
176     }
177 }