;@GOTO TRANSLATE

; This ExD example installs Callback procedure which monitors
; IN EAX,DX (DX=1234H) and returns "DNGL" in EAX
; You can check it in Win or DOS program

; Only one handler per port can be installed!

.586P
.MODEL FLAT

 INCLUDE ExD.INC

.CODE


COMMENT $  ---MSDN
mov     ebx, VM             ; current VM handle
mov     ecx, IOType         ; type of I/O
mov     edx, Port           ; port number
mov     ebp, OFFSET32 crs   ; points to a Client_Reg_Struc
mov     eax, Data           ; output data (if I/O type is output)
call    [IOCallback]

mov     [Data], eax         ; input data (if I/O type is input)
        $


         DongleRet EQU "DNGL"


  MyIOCallback:   ;for all VMs (don't check EBX)

         CMP      ECX, Dword_Input
         JNE      Ignore
         MOV      EAX, DongleRet
         RET
        Ignore:
         VMMJmp   Simulate_IO


Start:

         MyPort   EQU  1234H

         MOV      EDX, MyPort
         VMMCall  Remove_IO_Handler        ;remove current handler (if any)

         LEA      ESI, MyIOCallback
         VMMCall  Install_IO_Handler

         ;VCALL returned CF set if failed, clear if succeeded
         ;so here is no need to do CLC/STC 

         RET


.DATA

.STACK	4   ; to satisfy DLINK

END Start

:TRANSLATE
@ECHO OFF
REM   CALL .BAT   PathToExDLoad PathToExDLoad ThisFolder PathToInclude
CALL  ..\..\ExDLoad\ExDLdr.bat ..\..\ExDLoad\ .\ ..\..\Include\
TASM  /M /T /Q /I..\..\Include SWDongle.BAT
DLINK -SExDLdr SWDongle >NUL
DEL            SWDongle.obj
DEL            ExDLdr.exe