int21h.asm

来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 2,067 行 · 第 1/5 页

ASM
2,067
字号
        mov     ecx,DUMMYSEGMENTSIZE

        sys     GetMem32                ; allocate the memory
        jnc     zerodummy               ; no error allocating memory
        pop     ebx
        push    ebx                     ; use application DS value if can't create dummy value
        jmp     savedummy

; MED 07/15/97, zero out dummy segment
zerodummy:
        push    edx
        push    ds
        mov     ds,bx
        mov     ecx,DUMMYSEGMENTSIZE-4

dumloop:
        mov     DWORD PTR ds:[ecx],0
        sub     ecx,4
        jns     dumloop
        pop     ds
        pop     edx

savedummy:
        add     esp,4                   ; throw away application DS value
        mov     DOS16DummySegment,bx
        mov     eax,ebx                 ; allocated memory or application DS selector to put in GS

setgs:
        mov     WORD PTR [ebp+Int_GS],ax

        mov     ds,cs:Int21hDSeg
        assume ds:_cwMain
        or      DOS4GFlag,-1
        assume ds:nothing
        mov     ds,cs:Int21hDDSeg
        assume ds:_Int21h
        or      Int21hDOS4GFlag,-1
        assume ds:nothing
        pop     ecx
        pop     ebx
        pop     eax
        pop     ds
;
        ret
Int21hDOS4GTest endp


;------------------------------------------------------------------------------
;
;Get extended error information.
;
Int21hGetErrorInfo proc near
        mov     edi,offset Int21Buffer
        mov     es,cs:Int21hDSeg
        mov     eax,[ebp+Int_EAX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     eax,[ebp+Int_EBX]
        mov     es:RealRegsStruc.Real_EBX[edi],eax
        mov     bl,21h
        sys     IntXX
        mov     eax,es:RealRegsStruc.Real_EAX[edi]
        mov     [ebp+Int_AX],ax
        DOS4GExtend w[ebp+Int_EAX+2]
        mov     eax,es:RealRegsStruc.Real_EBX[edi]
        mov     [ebp+Int_BX],ax
        DOS4GExtend w[ebp+Int_EBX+2]
        mov     eax,es:RealRegsStruc.Real_ECX[edi]
        mov     [ebp+Int_CX],ax
        DOS4GExtend w[ebp+Int_ECX+2]
;
;LABEL string?
;
        cmp     w[ebp+Int_AX],22h
        jnz     int2132_done
        mov     ds,cs:Int21hDSeg
        assume ds:_cwMain
        mov     ds,RealSegment
        assume ds:nothing
        mov     eax,es:RealRegsStruc.Real_EDI[edi]
        movzx   eax,ax
        movzx   esi,es:RealRegsStruc.Real_ES[edi]
        shl     esi,4
        add     esi,eax
        mov     es,fs:[EPSP_Struc.EPSP_TransProt]
        mov     [ebp+Int_ES],es
        mov     w[ebp+Int_DI],0
        DOS4GExtend w[ebp+Int_EDI+2]
        xor     edi,edi
        mov     ecx,11
        rep     movsb
;
int2132_done:   ret
Int21hGetErrorInfo endp


;------------------------------------------------------------------------------
;
;Extend SI into ESI if DS's limit is < 64K
;
;On Entry:
;
;DS:[E]SI       - Pointer to convert.
;
;On Exit:
;
;DS:ESI - Valid [extended] pointer.
;
;All other registers preserved.
;
Int21hExtend_DS_ESI proc near
        push    eax
        xor     eax,eax
        mov     ax,ds
        lsl     eax,eax
        cmp     eax,10000h
        jnc     int2133_32Bit
        movzx   esi,si
int2133_32Bit:  pop     eax
        ret
Int21hExtend_DS_ESI endp


;------------------------------------------------------------------------------
;
;Extend DI into EDI if ES's limit is < 64K
;
;On Entry:
;
;ES:[E]DI       - Pointer to convert.
;
;On Exit:
;
;ES:EDI - Valid [extended] pointer.
;
;All other registers preserved.
;
Int21hExtend_ES_EDI proc near
        push    eax
        xor     eax,eax
        mov     ax,es
        lsl     eax,eax
        cmp     eax,10000h
        jnc     int2134_32Bit
        movzx   edi,di
int2134_32Bit:  pop     eax
        ret
Int21hExtend_ES_EDI endp


;------------------------------------------------------------------------------
;
;Fing length of a string.
;
;On Entry:
;
;AL     - Termination value.
;DS:ESI - String to find length of.
;
;On Exit:
;
;ECX    - Length of string EXCLUDEING terminator.
;
;All other registers preserved.
;
Int21hStringLen proc near
        push    edi
        push    es
        push    ds
        pop     es
        mov     edi,esi
        or      ecx,-1
        repne   scasb
        mov     ecx,edi
        sub     ecx,esi
        dec     ecx
        pop     es
        pop     edi
        ret
Int21hStringLen endp


;------------------------------------------------------------------------------
Int21hAL2Carry  proc    near
        test    BYTE PTR cs:Int21hSystemFlags,1
        jz      int2136_32Bit
        or      b[ebp+Int_Flags16],al
        ret
int2136_32Bit:  or      b[ebp+Int_Flags32],al
        ret
Int21hAL2Carry  endp


;------------------------------------------------------------------------------
;
;The jump table used to pass control to the right routine.
;
Int21hTable     label dword
;       dd 8 dup (Int21hNotOurs)        ;00-07
        IRP     arg,<1,2,3,4,5,6,7,8>
        DD      Int21hNotOurs
        ENDM

        dd Int21hNotOurs                ;08
        dd Int21hPrintString    ;09
        dd Int21hGetString              ;0A

;       dd 4 dup (Int21hNotOurs)        ;0B-0E
        IRP     arg,<1,2,3,4>
        DD      Int21hNotOurs
        ENDM

        dd Int21hInvalid                ;0F

;       dd 8 dup (Int21hInvalid)        ;10-17
        IRP     arg,<1,2,3,4,5,6,7,8>
        DD      Int21hInvalid
        ENDM

;       dd 2 dup (Int21hNotOurs)        ;18-19
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hSetDTA         ;1A
;       dd 5 dup (Int21hNotOurs)        ;1B-1F
        IRP     arg,<1,2,3,4,5>
        DD      Int21hNotOurs
        ENDM

        dd Int21hNotOurs                ;20

;       dd 4 dup (Int21hInvalid)        ;21-24
        IRP     arg,<1,2,3,4>
        DD      Int21hInvalid
        ENDM

        dd Int21hSetVect                ;25
;       dd 2 dup (Int21hInvalid)        ;26-27
        IRP     arg,<1,2>
        DD      Int21hInvalid
        ENDM

;       dd 2 dup (Int21hInvalid)        ;28-29
        IRP     arg,<1,2>
        DD      Int21hInvalid
        ENDM

;       dd 5 dup (Int21hNotOurs)        ;2A-2E
        IRP     arg,<1,2,3,4,5>
        DD      Int21hNotOurs
        ENDM

        dd Int21hGetDTA         ;2F

;       dd 5 dup (Int21hNotOurs)        ;30-34
        IRP     arg,<1,2,3,4,5>
        DD      Int21hNotOurs
        ENDM

        dd Int21hGetVect                ;35
;       dd 2 dup (Int21hNotOurs)        ;36-37
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hGetSetCountry  ;38
        dd Int21hCreateDIR              ;39
        dd Int21hCreateDIR              ;3A
        dd Int21hCreateDIR              ;3B
        dd Int21hCreateFile     ;3C
        dd Int21hOpenFile               ;3D
        dd Int21hNotOurs                ;3E
        dd Int21hReadFile               ;3F

        dd Int21hWriteFile              ;40
        dd Int21hOpenFile               ;41
        dd Int21hNotOurs                ;42
        dd Int21hCreateFile     ;43
        dd Int21hIOCTLDispatch  ;44
;       dd 2 dup (Int21hNotOurs)        ;45-46
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hGetCurDir              ;47

        dd Int21hAllocMem               ;48
        dd Int21hRelMem         ;49
        dd Int21hResMem         ;4A
        dd Int21hExecFile               ;4B

;       dd 2 dup (Int21hNotOurs)        ;4C-4D
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hFindFirstFile  ;4E
        dd Int21hFindNextFile   ;4F

        dd Int21hSetPSP         ;50
        dd Int21hGetPSP         ;51
;       dd 4 dup (Int21hNotOurs)        ;52-55
        IRP     arg,<1,2,3,4>
        DD      Int21hNotOurs
        ENDM

        dd Int21hRenameFile     ;56
        dd Int21hNotOurs                ;57

        dd Int21hNotOurs                ;58
        dd Int21hGetErrorInfo   ;59
        dd Int21hCreateTemp     ;5A
        dd Int21hCreateFile     ;5B
;       dd 2 dup (Int21hNotOurs)        ;5C-5D
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hMSNet          ;5E
        dd Int21hNotOurs                ;5F

;       dd 2 dup (Int21hNotOurs)        ;60-61
        IRP     arg,<1,2>
        DD      Int21hNotOurs
        ENDM

        dd Int21hGetPSP                 ;62
;       dd 4 dup (Int21hNotOurs)        ;63-66
        IRP     arg,<1,2,3,4>
        DD      Int21hNotOurs
        ENDM

        dd Int21hSetHandles             ;67

;       dd 4 dup (Int21hNotOurs)        ;68-6B
        IRP     arg,<1,2,3,4>
        DD      Int21hNotOurs
        ENDM

        dd Int21hExtendOpen             ;6C
;       dd 3 dup (Int21hNotOurs)        ;6D-6F
        IRP     arg,<1,2,3>
        DD      Int21hNotOurs
        ENDM

;       dd (16*9)-1 dup (Int21hNotOurs) ;70-FE
        IRP     arg,<1,2,3,4,5,6,7,8>
        IRP     arg2,<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16>
        DD      Int21hNotOurs
        ENDM
        ENDM
        IRP     arg,<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15>
        DD      Int21hNotOurs
        ENDM

        dd Int21hDOS4GTest              ;FF


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Setup int 21h patch.
;
Int21hOpen      proc    near
        assume ds:_Int21h
        assume es:_cwMain
        mov     Int21hDSeg,es   ;Store cwCode selector.
        mov     Int21hCSeg,cs   ;store this segment.
        mov     Int21hDDSeg,ds
        ;
        mov     bl,21h
        sys     GetVect
        test    BYTE PTR es:SystemFlags,1
        jz      int2137_Use32
        movzx   edx,dx
int2137_Use32:  mov     d[OldInt21h],edx
        mov     w[OldInt21h+4],cx
int2137_Use0:   mov     edx,offset Int21h
        mov     cx,cs
        mov     bl,21h
        sys     SetVect
        ;
        mov     eax,es:SystemFlags
        mov     Int21hSystemFlags,eax
        ;
        assume es:nothing
        assume ds:nothing
        clc
int2137_9:      ;
        db 66h
        retf
Int21hOpen      endp


;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Remove int 21h patch.
;
Int21hClose     proc    near
        push    ds
        mov     ds,cs:Int21hDDSeg
        assume ds:_Int21h
        cmp     d[OldInt21h+2],0
        jz      int2138_9
        mov     edx,d[OldInt21h]
        mov     cx,w[OldInt21h+4]
        mov     bl,21h
        sys     SetVect
        assume ds:nothing
int2138_9:      pop     ds
        ;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?