When entering protected mode, V86 flag must be clear.
[wine] / dlls / winedos / int25.c
1 /*
2  * DOS interrupt 25h handler
3  *
4  * Copyright 1997 Andreas Mohr
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include "msdos.h"
30 #include "miscemu.h"
31 #include "drive.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
35
36
37 /***********************************************************************
38  *           DOSVM_RawRead
39  *
40  * Read raw sectors from a device.
41  */
42 BOOL DOSVM_RawRead(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success)
43 {    
44     int fd;
45
46     if ((fd = DRIVE_OpenDevice( drive, O_RDONLY )) != -1)
47     {
48         lseek( fd, begin * 512, SEEK_SET );
49         /* FIXME: check errors */
50         read( fd, dataptr, nr_sect * 512 );
51         close( fd );
52     }
53     else
54     {
55         memset( dataptr, 0, nr_sect * 512 );
56         if (fake_success)
57         {
58             /* FIXME: explain what happens here */
59             if (begin == 0 && nr_sect > 1) *(dataptr + 512) = 0xf8;
60             if (begin == 1) *dataptr = 0xf8;
61         }
62         else
63             return FALSE;
64     }
65
66     return TRUE;
67 }
68
69
70 /**********************************************************************
71  *          DOSVM_Int25Handler (WINEDOS16.137)
72  *
73  * Handler for int 25h (absolute disk read).
74  */
75 void WINAPI DOSVM_Int25Handler( CONTEXT86 *context )
76 {
77     WCHAR drivespec[4] = {'A', ':', '\\', 0};
78     BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegDs, context->Ebx );
79     DWORD begin;
80     DWORD length;
81
82     drivespec[0] += AL_reg( context );
83
84     if (GetDriveTypeW( drivespec ) == DRIVE_NO_ROOT_DIR || 
85         GetDriveTypeW( drivespec ) == DRIVE_UNKNOWN)
86     {
87         SET_CFLAG( context );
88         SET_AX( context, 0x0201 ); /* unknown unit */
89         return;
90     }
91
92     if (CX_reg( context ) == 0xffff)
93     {
94         begin   = *(DWORD *)dataptr;
95         length  = *(WORD *)(dataptr + 4);
96         dataptr = (BYTE *)CTX_SEG_OFF_TO_LIN( context,
97                                               *(WORD *)(dataptr + 8), 
98                                               *(DWORD *)(dataptr + 6) );
99     }
100     else
101     {
102         begin  = DX_reg( context );
103         length = CX_reg( context );
104     }
105
106     TRACE( "abs diskread, drive %d, sector %ld, "
107            "count %ld, buffer %p\n",
108            AL_reg( context ), begin, length, dataptr );
109
110     DOSVM_RawRead( AL_reg( context ), begin, length, dataptr, TRUE );
111     RESET_CFLAG( context );
112 }