int26.c 2.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * DOS interrupt 26h handler
 *
 * Copyright 1997 Andreas Mohr
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23
 */

#include "config.h"

#include <stdlib.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
24
#include <stdio.h>
25 26 27 28
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
29
#include "dosexe.h"
30 31 32 33 34 35 36 37 38 39 40 41
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(int);


/***********************************************************************
 *           DOSVM_RawWrite
 *
 * Write raw sectors to a device.
 */
BOOL DOSVM_RawWrite(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success)
{
42 43
    WCHAR root[] = {'\\','\\','.','\\','A',':',0};
    HANDLE h;
44
    DWORD w;
45

46 47
    TRACE( "abs diskwrite, drive %d, sector %d, "
           "count %d, buffer %p\n",
48 49
           drive, begin, nr_sect, dataptr );

50 51 52 53
    root[4] += drive;
    h = CreateFileW(root, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
                    0, NULL);
    if (h != INVALID_HANDLE_VALUE)
54
    {
55
        SetFilePointer(h, begin * 512, NULL, SEEK_SET );
56
        /* FIXME: check errors */
57
        WriteFile( h, dataptr, nr_sect * 512, &w, NULL );
58
        CloseHandle( h );
59 60 61 62 63 64 65 66 67
    }
    else if (!fake_success)
        return FALSE;

    return TRUE;
}


/**********************************************************************
68
 *	    DOSVM_Int26Handler
69
 *
70
 * Handler for int 26h (absolute disk write).
71
 */
72
void WINAPI DOSVM_Int26Handler( CONTEXT *context )
73
{
74
    WCHAR drivespec[] = {'A', ':', '\\', 0};
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    BYTE *dataptr = CTX_SEG_OFF_TO_LIN( context, context->SegDs, context->Ebx );
    DWORD begin;
    DWORD length;

    drivespec[0] += AL_reg( context );

    if (GetDriveTypeW( drivespec ) == DRIVE_NO_ROOT_DIR || 
        GetDriveTypeW( drivespec ) == DRIVE_UNKNOWN)
    {
        SET_CFLAG( context );
        SET_AX( context, 0x0201 ); /* unknown unit */
        return;
    }

    if (CX_reg( context ) == 0xffff)
    {
        begin   = *(DWORD *)dataptr;
        length  = *(WORD *)(dataptr + 4);
        dataptr = (BYTE *)CTX_SEG_OFF_TO_LIN( context,
                                              *(WORD *)(dataptr + 8), 
                                              *(DWORD *)(dataptr + 6) );
    }
    else
    {
        begin  = DX_reg( context );
        length = CX_reg( context );
    }

    DOSVM_RawWrite( AL_reg( context ), begin, length, dataptr, TRUE );
    RESET_CFLAG( context );
}