int21h.asm

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

ASM
2,067
字号
        ;
        ;Pass control to real mode handler.
        ;
        mov     es,cs:Int21hDseg
        mov     edi,offset Int21Buffer
        mov     eax,[ebp+Int_EAX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     es:RealRegsStruc.Real_EDX[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     bl,21h
        sys     IntXX
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        mov     eax,es:RealRegsStruc.Real_EAX[edi]      ;Get return code.
        mov     [ebp+Int_AX],ax
        DOS4GExtend w[ebp+Int_EAX+2]
        ret
Int21hCreateDIR endp


;------------------------------------------------------------------------------
;
;Function 3C emulation.
;
Int21hCreateFile proc near
        ;
        ;Copy string into transfer buffer.
        ;
        mov     ds,[ebp+Int_DS]
        mov     esi,[ebp+Int_EDX]
        call    Int21hExtend_DS_ESI     ;Extend [E]SI.
        xor     al,al           ;Character to look for.
        call    Int21hStringLen ;Get length of this string.
        mov     es,fs:[EPSP_Struc.EPSP_TransProt]
        xor     edi,edi
        inc     ecx             ;Include terminator.
        rep     movsb
        ;
        ;Pass control to real mode handler.
        ;
        mov     es,cs:Int21hDseg
        mov     edi,offset Int21Buffer
        mov     eax,[ebp+Int_EAX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     eax,[ebp+Int_ECX]
        mov     es:RealRegsStruc.Real_ECX[edi],eax
        mov     es:RealRegsStruc.Real_EDX[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     bl,21h
        sys     IntXX
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        mov     eax,es:RealRegsStruc.Real_EAX[edi]      ;Get return code.
        mov     [ebp+Int_AX],ax
        DOS4GExtend w[ebp+Int_EAX+2]
        mov     eax,es:RealRegsStruc.Real_ECX[edi]
        mov     [ebp+Int_CX],ax
        DOS4GExtend w[ebp+Int_ECX+2]
        ret
Int21hCreateFile endp


;------------------------------------------------------------------------------
;
;Function 3D emulation.
;
Int21hOpenFile  proc    near
        ;
        ;Copy string into transfer buffer.
        ;
        mov     ds,[ebp+Int_DS]
        mov     esi,[ebp+Int_EDX]
        call    Int21hExtend_DS_ESI     ;Extend [E]SI.
        xor     al,al           ;Character to look for.
        call    Int21hStringLen ;Get length of this string.
        mov     es,fs:[EPSP_Struc.EPSP_TransProt]
        xor     edi,edi
        inc     ecx             ;Include terminator.
        rep     movsb
        ;
        ;Pass control to real mode handler.
        ;
        mov     es,cs:Int21hDseg
        mov     edi,offset Int21Buffer
        mov     eax,[ebp+Int_EAX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     es:RealRegsStruc.Real_EDX[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     bl,21h
        sys     IntXX
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        mov     eax,es:RealRegsStruc.Real_EAX[edi]      ;Get return code.
        mov     [ebp+Int_AX],ax
        DOS4GExtend w[ebp+Int_EAX+2]
        ret
Int21hOpenFile  endp


;------------------------------------------------------------------------------
;
;Function 3F emulation.
;
Int21hReadFile  proc    near
        mov     ds,[ebp+Int_DS] ;Point to source.
        mov     esi,[ebp+Int_EDX]
        call    Int21hExtend_DS_ESI     ;Extend [E]SI.
        mov     es,cs:Int21hDSeg
        mov     edi,offset Int21Buffer
        movzx   edx,w[ebp+Int_CX]       ;Get length.
        cmp     cs:Int21hDOS4GFlag,0
        jz      int2114_4
        mov     edx,[ebp+Int_ECX]       ;Get length.
int2114_4:      xor     ebx,ebx         ;Reset length read.
int2114_0:      mov     ecx,edx
        cmp     ecx,fs:[EPSP_Struc.EPSP_TransSize]
        jc      int2114_1
        mov     ecx,fs:[EPSP_Struc.EPSP_TransSize]
int2114_1:      mov     es:RealRegsStruc.Real_ECX[edi],ecx      ;Store length.
        mov     es:RealRegsStruc.Real_EDX[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     ax,[ebp+Int_AX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     ax,[ebp+Int_BX] ;Set handle.
        mov     es:RealRegsStruc.Real_EBX[edi],eax
        push    ebx
        mov     bl,21h
        sys     IntXX
        pop     ebx
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        or      al,al           ;Carry set?
        jz      int2114_2
        mov     ebx,es:RealRegsStruc.Real_EAX[edi]      ;get return code.
        jmp     int2114_3
int2114_2:      mov     eax,es:RealRegsStruc.Real_EAX[edi]      ;get bytes read.
        movzx   eax,ax
        sub     edx,eax         ;Update count remaining.
        add     ebx,eax         ;Update count so far.
        push    ecx
        mov     ecx,eax
        push    edi
        push    es
        push    esi
        push    ds
        pop     es
        pop     edi
        mov     ds,fs:[EPSP_Struc.EPSP_TransProt]
        xor     esi,esi
        Int21h_repmovs          ;Copy this data.
        push    edi
        push    es
        pop     ds
        pop     esi
        pop     es
        pop     edi
        pop     ecx
        cmp     eax,ecx
        jnz     int2114_3
        or      edx,edx
        jnz     int2114_0
int2114_3:      mov     [ebp+Int_AX],bx ;store length or return code.
        cmp     cs:Int21hDOS4GFlag,0
        jz      int2114_5
        mov     [ebp+Int_EAX],ebx
int2114_5:      ret
Int21hReadFile  endp


;------------------------------------------------------------------------------
;
;Function 40 emulation.
;
Int21hWriteFile proc near
        mov     ds,[ebp+Int_DS] ;Point to source.
        mov     esi,[ebp+Int_EDX]
        call    Int21hExtend_DS_ESI     ;Extend [E]SI.
        mov     es,cs:Int21hDSeg
        mov     edi,offset Int21Buffer
        movzx   edx,w[ebp+Int_CX]       ;Get length.
        cmp     cs:Int21hDOS4GFlag,0
        jz      int2115_4
        mov     edx,[ebp+Int_ECX]       ;Get length.
int2115_4:      xor     ebx,ebx         ;Reset length read.
int2115_0:      mov     ecx,edx
        cmp     ecx,fs:[EPSP_Struc.EPSP_TransSize]
        jc      int2115_1
        mov     ecx,fs:[EPSP_Struc.EPSP_TransSize]
int2115_1:      mov     es:RealRegsStruc.Real_ECX[edi],ecx      ;Store length.
        mov     es:RealRegsStruc.Real_EDX[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     ax,[ebp+Int_AX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     ax,[ebp+Int_BX] ;Set handle.
        mov     es:RealRegsStruc.Real_EBX[edi],eax
        push    ecx
        push    edi
        push    es
        mov     es,fs:[EPSP_Struc.EPSP_TransProt]
        xor     edi,edi
        Int21h_repmovs          ;Copy this data.
        pop     es
        pop     edi
        pop     ecx
        push    ebx
        mov     bl,21h
        sys     IntXX           ;Do the write.
        pop     ebx
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        or      al,al           ;Carry set?
        jz      int2115_2
        mov     ebx,es:RealRegsStruc.Real_EAX[edi]      ;get return code.
        jmp     int2115_3
int2115_2:      mov     eax,es:RealRegsStruc.Real_EAX[edi]      ;get bytes read.
        movzx   eax,ax
        sub     edx,eax         ;Update count remaining.
        add     ebx,eax         ;Update count so far.
        cmp     eax,ecx         ;Get anything?
        jnz     int2115_3
        or      edx,edx
        jnz     int2115_0
int2115_3:      mov     [ebp+Int_AX],bx ;store length or return code.
        cmp     cs:Int21hDOS4GFlag,0
        jz      int2115_5
        mov     [ebp+Int_EAX],ebx
int2115_5:      ret
Int21hWriteFile endp


;------------------------------------------------------------------------------
;
;Function 44 emulation.
;
Int21hIOCTLDispatch proc near
        mov     al,[ebp+Int_AL]
        cmp     al,02h          ;IOCTL?
        jz      Int21hReadFile
        cmp     al,03h
        jz      Int21hWriteFile
        cmp     al,04h
        jz      Int21hReadFile
        cmp     al,05h
        jz      Int21hWriteFile
        jmp     Int21hNotOurs
Int21hIOCTLDispatch endp


;------------------------------------------------------------------------------
;
;Function 47 emulation.
;
Int21hGetCurDir proc near
        ;
        ;Call the real mode handler to take care of things.
        ;
        mov     es,cs:Int21hDseg
        mov     edi,offset Int21Buffer
        mov     eax,[ebp+Int_EAX]
        mov     es:RealRegsStruc.Real_EAX[edi],eax
        mov     eax,[ebp+Int_EDX]
        mov     es:RealRegsStruc.Real_EDX[edi],eax
        mov     es:RealRegsStruc.Real_ESI[edi],0
        mov     ax,fs:[EPSP_Struc.EPSP_TransReal]
        mov     es:RealRegsStruc.Real_DS[edi],ax
        mov     bl,21h
        sys     IntXX
        mov     eax,es:RealRegsStruc.Real_EAX[edi]
        mov     [ebp+Int_AX],ax
        DOS4GExtend w[ebp+Int_EAX+2]
        mov     ax,es:RealRegsStruc.Real_Flags[edi]
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        or      al,al
        jnz     int2117_9
        ;
        ;Copy returned info to callers buffer.
        ;
        mov     ds,fs:[EPSP_Struc.EPSP_TransProt]       ;Point to source data.
        xor     esi,esi
        xor     al,al           ;Character to look for.
        call    Int21hStringLen ;Get length of this string.
        inc     ecx
        mov     es,[ebp+Int_DS]
        mov     edi,[ebp+Int_ESI]
        call    Int21hExtend_ES_EDI     ;Extend [E]SI.
        rep     movsb
int2117_9:      ret
Int21hGetCurDir endp


;------------------------------------------------------------------------------
;
;Function 48 emulation.
;
Int21hAllocMem  proc    near
        cmp     bx,-1           ;maximum free check?
        jz      int2118_AllocMuch
        movzx   ebx,bx
        shl     ebx,4           ;convert paragraphs to bytes.
        mov     dx,bx
        shr     ebx,16
        mov     cx,bx
        sys     GetMem          ;try to allocate memory.
        jc      int2118_AllocMuch               ;report how much free then.
        mov     [ebp+Int_AX],bx ;get the selector allocated.
        DOS4GExtend w[ebp+Int_EAX+2]
        ret
        ;
int2118_AllocMuch:      mov     cx,-1
        mov     dx,-1
        sys     GetMem          ;get free memory size.
        mov     bx,cx
        shl     ebx,16
        mov     bx,dx
        cmp     ebx,0fffeh*16   ;can't report too much.
        jc      int2118_AllocOK
        mov     ebx,0fffeh*16
int2118_AllocOK:        shr     ebx,4           ;convert to paragraphs free.
        mov     [ebp+Int_BX],ax
        DOS4GExtend w[ebp+Int_EBX+2]
        mov     w[ebp+Int_AX],1
        DOS4GExtend w[ebp+Int_EAX+2]
        call    Int21hAL2Carry  ;Set carry.
        ret
Int21hAllocMem  endp


;------------------------------------------------------------------------------
;
;Function 49 emulation.
;
Int21hRelMem    proc    near
        mov     bx,[ebp+Int_ES]
        mov     ds,[ebp+Int_DS]
        mov     es,[ebp+Int_ES]
        mov     fs,[ebp+Int_FS]
        mov     gs,[ebp+Int_GS]
        sys     RelMem
        mov     [ebp+Int_DS],ds
        mov     [ebp+Int_ES],es
        mov     [ebp+Int_FS],fs
        mov     [ebp+Int_GS],gs
        ret
Int21hRelMem    endp


;------------------------------------------------------------------------------
;
;Function 4A emulation.
;
Int21hResMem    proc    near
        movzx   ebx,w[ebp+Int_BX]
        shl     ebx,4           ;convert paragraphs to bytes.
        mov     dx,bx
        shr     ebx,16
        mov     cx,bx
        mov     bx,[ebp+Int_ES]
        sys     ResMem
        pushf
        pop     ax
        and     al,1
        call    Int21hAL2Carry  ;Set carry.
        ret
Int21hResMem    endp


;------------------------------------------------------------------------------
;
;Function 4B emulation.
;
Int21hExecFile  proc    near
        cmp     b[ebp+Int_AL],0 ;We only support sub-function 0.
        jz      int2121_OK
int2121_Done:   call    Int21hAL2Carry  ;Set carry.
        ret
        ;
int2121_OK:     ;Copy the file name into transfer buffer.
        ;
        mov     ds,[ebp+Int_DS]
        mov     esi,[ebp+Int_EDX]
        call    Int21hExtend_DS_ESI     ;Extend [E]SI.
        xor     al,al
        call    Int21hStringLen ;Get length of this string.
        inc     ecx
        mov     es,fs:[EPSP_Struc.EPSP_TransProt]
        xor     edi,edi
        rep     movsb           ;Copy the file name.
        ;
        ;Copy the command line into transfer buffer.
        ;
        mov     ebx,[ebp+Int_EBX]
        mov     ds,[ebp+Int_ES]
        cmp     cs:Int21hDOS4GFlag,0
        jz      int2121_0
        lds     esi,f[ebx+4+2]
        jmp     int2121_Ef4
int2121_0:      test    BYTE PTR cs:Int21hSystemFlags,1
        jz      int2121_Ef3
        movzx   ebx,bx
        movzx   esi,w[ebx+2]            ;Get command line offset.
        mov     ds,[ebx+2+2]            ;& segment.
        jmp     int2121_Ef4
int2121_Ef3:    mov     esi,[ebx+2]

⌨️ 快捷键说明

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