;/*static char *SCCSID = "@(#)dosiokvm.asm      6.2 92/03/01";*/
        page    ,132
        .386

        TITLE   dosiokvm - 32-bit KBD/VIO/MOU thunks for DOSCALL1
;       These thunks are HEAVILY modified output from the thunk compiler.
;       They allow 32-bit code (IN DOSCALL1 ONLY) to call specific 16-bit
;       subsystem interfaces.  They are NOT general enough to handle NULL
;       pointers, structures that cross 64k boundaries, etc, because they
;       don't need to (all structures are carefully aligned beforehand,
;       usually by statically allocating them in the per-process data segment).
;
;       They are also not true 32-bit interfaces in the sense that, like
;       their 16-bit predecessors, they use the PASCAL calling convention.
;
;***  Change History:                                             ***
;***   noto  11/18/93  Define which segment for Page Tuning DLL   ***
;***                                                              ***

.xlist
include basemaca.inc
?cstype  = ?CS_32bit

include error.inc
include dc1segs.inc                                             ; DCR 704
include thkmacs.inc
.list


PUBLIC  KBD32CHARIN
PUBLIC  KBD32STRINGIN
PUBLIC  VIO32WRTTTY
PUBLIC  VIO32SETANSI

EXTRN   KBDCHARIN:FAR                                           ;MDLL
EXTRN   KBDSTRINGIN:FAR                                         ;MDLL
EXTRN   VIOWRTTTY:FAR                                           ;MDLL
EXTRN   VIOSETANSI:FAR                                          ;MDLL

DATA    SEGMENT                                                 ; DCR 704
        pfnKbdCharIn    dd KBDCHARIN                            ;MDLL
        pfnKbdStringIn  dd KBDSTRINGIN                          ;MDLL
        pfnVioWrtTTY    dd VIOWRTTTY                            ;MDLL
        pfnVioSetANSI   dd VIOSETANSI                           ;MDLL
DATA    ENDS                                                    ; DCR 704


; External Public Variables for converting pointers in packed region.
EXTRN   FenceLAddr:dword


CODE32_TUNE1  SEGMENT DWORD USE32 PUBLIC 'CODE'
EXTRN   DOS32FLATTOSEL:NEAR
CODE32_TUNE1  ENDS

CODE32  SEGMENT DWORD USE32 PUBLIC 'CODE'
CODE32  ENDS




CODE32  SEGMENT
        ASSUME  CS:FLAT,DS:FLAT,ES:FLAT


;***    KBD32CHARIN
;
;       Thunk to KbdCharIn
;
;       Uses    EAX, ECX, EDX
;               PASCAL calling convention
;

Procedure KBD32CHARIN,near

        ArgVar  hkbd,DWORD              ; pascal args in inverted order
        ArgVar  fIOWait,DWORD
        ArgVar  pChar,DWORD

        EnterProc
        push    offset FLAT:kci1

Begin32To16:
        pop     ecx                     ; save address to jump to
        T32Beg  CODE16C,CODE32
        T32Bump edx                     ; insure enough space on stack

        push    ss
        push    edx                     ; save old stack level
        getRPL  dx,ss
        jmp     ecx

; Create new call frame, using 16-bit semantics

kci1:   segPtr  eax,pChar,dx,input      ; start pushing arguments
        push    eax
        push    word ptr [fIOWait]
        push    word ptr [hKbd]
        mov     ecx,offset DATA:pfnKbdCharIn

End32To16:
        T32Stack eax,esp,dx             ; switch stacks
        T32Call  ecx,indirect           ; call the 16-bit API
        movzx    eax,ax
        T32End                          ; restore stack

        ExitProc

EndProc KBD32CHARIN


;***    KBD32STRINGIN
;
;       Thunk to KbdStringIn
;
;       Uses    EAX, ECX, EDX
;               PASCAL calling convention
;

Procedure KBD32STRINGIN,near

        ArgVar  hKbd,DWORD              ; pascal args in inverted order
        ArgVar  fIOWait,DWORD
        ArgVar  pLength,DWORD
        ArgVar  pBuffer,DWORD

        EnterProc
        call    Begin32To16

        segPtr  eax,pBuffer,dx,input    ; start pushing arguments
        push    eax
        segPtr  eax,pLength,dx
        push    eax
        push    word ptr [fIOWait]
        push    word ptr [hKbd]

        T32Stack eax,esp,dx             ; switch stacks
        T32Call  pfnKbdStringIn,indirect; call the 16-bit API
        T32End                          ; extend return code, and restore stack

        ExitProc

EndProc KBD32STRINGIN,NoCheck


;***    VIO32WRTTTY
;
;       Thunk to VioWrtTTY
;
;       Uses    EAX, ECX, EDX
;               PASCAL calling convention
;

Procedure VIO32WRTTTY,near

        ArgVar  hVio,DWORD              ; pascal args in inverted order
        ArgVar  cBytes,DWORD
        ArgVar  pBytes,DWORD

        EnterProc
        call    Begin32To16

        segPtr  eax,pBytes,dx,input     ; start pushing arguments
        push    eax
        push    word ptr [cBytes]
        push    word ptr [hVio]
        mov     ecx,offset DATA:pfnVioWrtTTY

        jmp     End32To16               ; Kbd32CharIn has 3 dword parms, too...

EndProc VIO32WRTTTY,NoCheck


;***    VIO32SETANSI
;
;       Thunk to VioSetANSI
;
;       Uses    EAX, ECX, EDX
;               PASCAL calling convention
;

Procedure VIO32SETANSI,near

        ArgVar  hVio,DWORD              ; pascal args in inverted order
        ArgVar  fEnable,DWORD

        EnterProc
        call    Begin32To16

        push    word ptr [fEnable]
        push    word ptr [hVio]
        T32Stack eax,esp,dx             ; switch stacks
        T32Call  pfnVioSetANSI,indirect ; call the 16-bit API
        T32End                          ; extend return code, and restore stack

        ExitProc

EndProc VIO32SETANSI,NoCheck


CODE32  ENDS


        END
