Release 980201
[wine] / msdos / int25.c
1 /*
2  * DOS interrupt 25h handler
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include "msdos.h"
11 #include "ldt.h"
12 #include "miscemu.h"
13 #include "drive.h"
14 #include "stddebug.h"
15 /* #define DEBUG_INT */
16 #include "debug.h"
17
18 /**********************************************************************
19  *          INT_Int25Handler
20  *
21  * Handler for int 25h (absolute disk read).
22  */
23 void WINAPI INT_Int25Handler( CONTEXT *context )
24 {
25     BYTE *dataptr = PTR_SEG_OFF_TO_LIN( DS_reg(context), BX_reg(context) );
26     DWORD begin, length;
27     int fd;
28
29     if (!DRIVE_IsValid(AL_reg(context)))
30     {
31         SET_CFLAG(context);
32         AX_reg(context) = 0x0101;        /* unknown unit */
33         return;
34     }
35
36     if (CX_reg(context) == 0xffff)
37     {
38         begin   = *(DWORD *)dataptr;
39         length  = *(WORD *)(dataptr + 4);
40         dataptr = (BYTE *)PTR_SEG_TO_LIN( *(SEGPTR *)(dataptr + 6) );
41     }
42     else
43     {
44         begin  = DX_reg(context);
45         length = CX_reg(context);
46     }
47     dprintf_int( stdnimp, "int25: abs diskread, drive %d, sector %ld, "
48                  "count %ld, buffer %d\n",
49                  AL_reg(context), begin, length, (int) dataptr);
50
51     if ((fd = DRIVE_OpenDevice( AL_reg(context), O_RDONLY )) != -1)
52     {
53         lseek( fd, begin * 512, SEEK_SET );
54         /* FIXME: check errors */
55         read( fd, dataptr, length * 512 );
56         close( fd );
57     }
58     else
59     {
60         memset(dataptr, 0, length * 512);
61         if (begin == 0 && length > 1) *(dataptr + 512) = 0xf8;
62         if (begin == 1) *dataptr = 0xf8;
63     }
64     RESET_CFLAG(context);
65 }