        page,132

;***EM  demmisc2.asm
;
;       SCCSID = @(#)demmisc2.asm       6.5 92/03/17
;
;       SUMMARY
;           DOS Emulation Misc. Supoort
;
;       NOTES
;
;       REVISIONS
;
;Local  DCR/
;Tag    PTR     Who     When
;             sudeepb   19-Sept-1989  Created for MVDM
;
; 001   12/15/91  CP20 B730404  Mark Rogalski
;       In Extend Handle Count function, add check if user is asking for
;       less than 20 handles. Make minimum request 20.
;---------------------------------------------------------------------- ;55855;
;  16Oct92 - G.L.Fulk                                                   ;55855;
; The check for minimum handle size should be unsigned arithmatic.      ;55855;
; Also don't reduce the size of the JFT by reducing the JFN_length.     ;55855;
; DOS_FILES sets it to a size and a program could accidently reduce     ;55855;
; it by issueing an int 21h, ah=67h with fewer files.                   ;55855;
;---------------------------------------------------------------------- ;55855;
; 003   12/15/92  58295  Mark Rogalski
;       For INT 25 and INT 26, calculate the segment size based on
;       the number of sectors being read or written, so we don't get
;       any seglock errors.
;----------------------------------------------------------------------
;  19Sep94 - bjn
; Change segment names for page tuning.
;----------------------------------------------------------------------

INCL_DEF        equ     1                       ; include typedef macros

.xlist
include dosseg.inc
.xcref
include basemaca.inc
include osmaca.inc
include dossymc.inc
include pdb.inc
include vpb.inc                        ; BN003
include mi.inc
include kmode.inc
include error.inc
include struc30.inc
.cref
.list

        CpuMode 386

        ReferTask       JFN_Length,WORD
        EXTRN16         w_GetDPB
        EXTRN16         ABSDRDWRT
        EXTRN16         w_SetMaxFH
        EXTRN16         Find_VPB       ;BN003

DefCode IMPORT, SWAP
DefFn   demMapESDI
DefFn   demMapDS
DefFn   demMapSegLenCX                 ;BN003
DefFn   demIOCTL
EndCode

        FARCODE HIGH32
DefCode PRIVATE, SWAP, PASCAL

;***LP  demGetDPB - Get DPB ($GET_DEAFULT_DPB,$GET_DPB)
;
;       ENTRY
;           EBX = Address of VSF
;           VSF(ES:DI)
;               Address of fake DPB
;           VSF(DL) = drive number
;
;       EXIT
;           SUCCESS
;               Fake DPB is filled in with values
;           FAILURE
;               returns AL = -1
;       CONTEXT
;           Called from Virtual Mode
;           Executes in Kernel
;
;       STEPS
;           call w_GetDPB
;
;       NOTES
;
;       WARNINGS
;           None
;
;       CALLS
;           w_GetDPB
;
;       USES
;

        ASSUME  DS:FLAT,ES:FLAT,SS:NOTHING,FS:NOTHING,GS:NOTHING
        align 4

Procedure demGetDPB,near
        mov     dl,[ebx].vsf_dl                 ; DL = drive number
        call    demMapESDI                      ; ES:DI = fake DPB
        CALL16  w_GetDPB
        ret
EndProc   demGetDPB

;***LP  demAbsDrd - Absolute Disk read (INT 25)
;
;       ENTRY
;           EBX = Address of VSF
;           VSF(AL)     - 0-based drive number
;           VSF(DS:BX)  - point to destination buffer
;           VSF(CX)     - number of logical sectors to read
;           VSF(DX)     - starting  logical sector number (0-based)
;
;       EXIT
;           SUCCESS
;               Carry Clear
;           FAILURE
;               Carry Set
;                   AH error code
;
;       CONTEXT
;           Called from Virtual Mode
;           Executes in Kernel
;
;       STEPS
;           Call ABSDRDWRT
;
;       NOTES
;
;       WARNINGS
;           None
;
;       CALLS
;           ABSDRDWRT
;
;       USES
;
        ASSUME  DS:FLAT,ES:FLAT,SS:NOTHING,FS:NOTHING,GS:NOTHING

Procedure demAbsDrd,near
        xor     ax,ax                  ; BN003 set r/w flag to 0
        jmp     short absrw_common     ; BN003

;BD003        movzx   ecx,[ebx].vsf_cx                ; cx = sectors to read/write
;BD003        movzx   edx,[ebx].vsf_dx                ; dx = starting sector number
;BD003        call    demMapDS
;BD003    ASSUME  DS:NOTHING
;BD003        movzx   ebx,es:[ebx].vsf_bx             ; (DS:BX) = transfer address
;BD003        xor     ah,ah
;BD003        CALL16  ABSDRDWRT
;BD003        ret
EndProc   demAbsDrd

;***LP  demAbsDwrt - Absolute Disk write (INT 26)
;
;       ENTRY
;           EBX = Address of VSF
;           VSF(AL)     - 0-based drive number
;           VSF(DS:BX)  - point to destination buffer
;           VSF(CX)     - number of logical sectors to read
;           VSF(DX)     - starting  logical sector number (0-based)
;
;       EXIT
;           SUCCESS
;               CArry Clear
;           FAILURE
;               CArry Set
;                   AH error code
;
;       CONTEXT
;           Called from Virtual Mode
;           Executes in Kernel
;
;       STEPS
;           Call ABSDRDWRT
;
;       NOTES
;
;       WARNINGS
;           None
;
;       CALLS
;           ABSDRDWRT
;
;       USES
;
        ASSUME  DS:FLAT,ES:FLAT,SS:NOTHING,FS:NOTHING,GS:NOTHING

Procedure demAbsDwrt,near

;START BN003
        mov     ax,0100h               ; set r/w flag to 1
absrw_common:
        or      ax,[ebx].vsf_ax        ; al = drive number
        push    ax                     ; save drive number and r/w flag
        xor     ah,ah                  ; clear r/w flag
        CALL16  Find_VPB               ; es:di -> vpb
        mov     eax,400h               ; default to 1k sector size
        jc      usedefault             ; if error just use default
        movzx   eax,es:[di].vpb_fsi.vpi_cbSector   ; get sector size

usedefault:
        cmp     [ebx].vsf_cx,0ffffh    ; check if address is of data packet
        jne     nopacket

;we have a data packet
        push    ds                     ; save pmode DS
        call    demMapDS               ; map DS segment to selector
        mov     ax,ds                  ; save Rmode DS in AX
        pop     ds                     ; done with data packet, res. pmode DS
        jmp     short commonend

nopacket:
        mul     [ebx].vsf_cx           ; sector size * num sectors
        add     ax,[ebx].vsf_bx        ; add in offset of data
        movzx   ecx,ax                 ; length of segment
        movzx   eax,[ebx].vsf_ds       ;
        call    demMapSegLenCX         ; map segment to selector (res in AX)

commonend:
        movzx   ecx,[ebx].vsf_cx       ; cx = sectors to read/write
        movzx   edx,[ebx].vsf_dx       ; dx = starting sector number
        movzx   ebx,[ebx].vsf_bx       ; (DS:BX) = transfer address
        mov     ds,ax                  ; setup DS with Rmode selector
    ASSUME  DS:NOTHING

        pop     ax                     ; restore drive num and r/w flag
;END BN003
        CALL16  ABSDRDWRT
        ret
EndProc   demAbsDwrt

SWAP32_23  segment
;***LP  demExtHandle - Extend handle count
;
;       ENTRY
;           EBX = Address of VSF
;           VSF(BX) = New handle count
;
;       EXIT
;           SUCCESS
;               Carry Clear
;           FAILURE
;               Carry Set
;                   AH error code
;
;       CONTEXT
;           Called from Virtual Mode
;           Executes in Kernel
;
;       STEPS
;           Call w_SetMaxFH
;
;       NOTES
;
;       WARNINGS
;           None
;
;       CALLS
;           w_SetMaxFH
;
;       USES
;
        ASSUME  DS:FLAT,ES:FLAT,SS:NOTHING,FS:NOTHING,GS:NOTHING

Procedure demExtHandle,near
        mov     bx,[ebx].vsf_bx
        .if     <BX b 20>                                               ;55855;
          mov     bx,20
        .endif
        .if     <BX be ss:[JFN_Length]>
;55855;   mov     ss:[JFN_Length],bx
          clc
        .else
          CALL16  w_SetMaxFH
        .endif
        ret
EndProc demExtHandle
SWAP32_23  ends

EndCode

        END
