📄 int21h.asm
字号:
;
; Copyright (C) 1996-2002 Supernar Systems, Ltd. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are
; met:
;
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; 3. The end-user documentation included with the redistribution, if any,
; must include the following acknowledgment:
;
; "This product uses DOS/32 Advanced DOS Extender technology."
;
; Alternately, this acknowledgment may appear in the software itself, if
; and wherever such third-party acknowledgments normally appear.
;
; 4. Products derived from this software may not be called "DOS/32A" or
; "DOS/32 Advanced".
;
; THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS" AND ANY EXPRESSED
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;
PushState
.386p
;=============================================================================
_int21: cld
test cs:_sys_misc,0100h ; check for CTRL-C flag
jnz _ctrl_c
push ds es
pushad
cmp ah,09h ; Print string: DS:EDX
jz @__09h
cmp ah,1Ah ; Set DTA buffer: DS:EDX
jz @__1Ah
cmp ah,1Bh ; Get DefDrive Info: -> AL, DS:EBX, ECX EDX
jz @__1Bh
cmp ah,1Ch ; Get Drive Info: AL, (-> ---//---)
jz @__1Ch
cmp ah,1Fh ; Get DefDrive PB: -> AL, DS:EBX
jz @__1Fh
cmp ah,25h ; Set INT vector: AL, DS:EDX
jz @__25h
cmp ah,2Fh ; Get DTA buffer: -> ES:EBX
jz @__2Fh
cmp ah,31h ; Go TSR AL
jz @__31h
cmp ah,32h ; Get Drive PB: AL, (-> DS:EBX)
jz @__32h
cmp ah,34h ; Get InDOS flag: -> ES:EBX
jz @__34h
cmp ah,35h ; Get INT vector: AL, ES:EBX
jz @__35h
cmp ah,39h ; Create DIR: DS:EDX
jz @__39h
cmp ah,3Ah ; Remove DIR: DS:EDX
jz @__3Ah
cmp ah,3Bh ; Change DIR: DS:EDX
jz @__3Bh
cmp ah,3Ch ; Create file: CX, DS:EDX
jz @__3Ch
cmp ah,3Dh ; Open file: AL, DS:EDX
jz @__3Dh
cmp ah,3Fh ; Read file: BX, ECX, DS:EDX
jz @__3Fh
cmp ah,40h ; Write file: BX, ECX, DS:EDX
jz @__40h
cmp ah,41h ; Delete file: DS:EDX
jz @__41h
cmp ah,42h ; Move file ptr: AL, BX, EDX, (->EAX)
jz @__42h
cmp ah,43h ; Change file attr: CX, DS:EDX
jz @__43h
cmp ah,47h ; Get DIR: DL, DS:ESI
jz @__47h
cmp ah,48h ; Alloc mem: BX (->AX)
jz @__48h
cmp ah,49h ; Dealloc mem: ES
jz @__49h
cmp ah,4Ah ; Realloc mem: BX
jz @__4Ah
cmp ah,4Bh ; Execute Prog: AL, DS:EDX, ES:EBX
jz @__4Bh
cmp ah,4Ch ; Terminate Prog: AL
jz @__4Ch
cmp ah,4Eh ; Find file: CX, DS:EDX
jz @__4Eh
cmp ah,4Fh ; Find next file: -
jz @__4Fh
cmp ah,51h ; Get PSP segment: (->BX)
jz @__51h
cmp ah,56h ; Rename file: DS:EDX, ES:EDI
jz @__56h
cmp ah,5Ah ; Create temp file: CX, DS:EDX
jz @__5Ah
cmp ah,5Bh ; Create new file: CX, DS:EDX
jz @__5Bh
cmp ah,62h ; Get PSP selector: (->BX)
jz @__62h
cmp ah,0FFh ; Rational DOS/4G call
jz @__FFh
cmp ah,71h ; Windows 95 long filename extensions
jnz @__go21
cmp al,39h ; Win95 Create DIR: DS:EDX
jz @__39h
cmp al,3Ah ; Win95 Remove DIR: DS:EDX
jz @__3Ah
cmp al,3Bh ; Win95 Change DIR: DS:EDX
jz @__3Bh
cmp al,41h ; Win95 Delete file: DS:EDX, CX, SI
jz @__41h
cmp al,43h ; Win95 Change attr: DS:EDX, BL, CX
jz @__43h
cmp al,47h ; Win95 Get curr DIR: DS:ESI, DL
jz @__47h
cmp al,56h ; Win95 Rename file: DS:EDX, ES:EDI
jz @__56h
cmp al,60h ; Win95 True name:
jz @_7160
cmp al,6Ch ; Win95 C/Open file:
jz @_716C
@__go21:popad
pop es ds
db 66h
jmp cs:_int21_ip
_ctrl_c:mov ax,4CFFh ; exit on CTRL-C with code 255
jmp @__4Ch
;=============================================================================
; Print String
; In: DS:EDX = offset of string
; Out: -
;
@__09h: push ds
pop es
sub esp,32h
mov ebp,esp
mov [ebp+1Ch],ax
mov esi,edx
mov edi,edx
mov al,'$'
or ecx,-1
repne scas byte ptr es:[edi]
not ecx
mov es,cs:_sel_ds
mov edi,cs:_lobufbase
rep movs byte ptr es:[edi],[esi]
stos byte ptr es:[edi]
mov ax,cs:_seg_buf
mov word ptr [ebp+24h],ax
mov word ptr [ebp+14h],00h
call int21h
add esp,32h
jmp @__ok
;=============================================================================
; Set DTA buffer
; In: DS:EDX = sel:offs
; Out: -
;
@__1Ah: mov es,cs:_sel_ds
mov es:_app_dta_sel,ds
mov es:_app_dta_off,edx
sub esp,32h
mov ebp,esp
mov [ebp+1Ch],ax
mov ax,cs:_seg_dta
mov word ptr [ebp+24h],ax
mov word ptr [ebp+14h],0
call int21h
add esp,32h
jmp @__ok
;=============================================================================
; Get Default Drive Info
; In: -
; Out: AL = sectors per cluster
; DS:EBX = addr of FAT
; ECX = bytes per sector
; EDX = number of clusters on drive
;
@__1Bh:
@__1Ch: call @__all
mov [esp+1Ch],al
cmp al,0FFh
jz @@done
mov [esp+14h],edx
mov [esp+18h],ecx
shl esi,4
add ebx,esi
mov [esp+10h],ebx
mov ax,cs:_sel_zero
mov [esp+22h],ax
@@done: jmp @__ok
;=============================================================================
; Get Drive Info
; In: DL = Drive number
; Out: AL = sectors per cluster
; DS:EBX = addr of FAT
; ECX = bytes per sector
; EDX = number of clusters on drive
;
;@__1Ch: jmp @__1Bh
;=============================================================================
; Get DefDrive Parameter Block
; In: -
; Out: AL = status
; DS:EBX = addr of DPB
;
@__1Fh:
@__32h: call @__all
mov [esp+1Ch],al
cmp al,0FFh
jz @@done
shl esi,4
add ebx,esi
mov [esp+10h],ebx
mov ax,cs:_sel_zero
mov [esp+22h],ax
@@done: jmp @__ok
;=============================================================================
; Set INT vector
; In: AL = INT vector, DS:EDX = sel:offs
; Out: -
;
@__25h: mov bl,al
mov cx,ds
mov ax,0205h
int 31h
jc @__err
jmp @__ok
;=============================================================================
; Get DTA buffer
; In: -
; Out: ES:EBX = addr of DTA
;
@__2Fh: mov ax,cs:_app_dta_sel
mov [esp+20h],ax
mov eax,cs:_app_dta_off
mov [esp+10h],eax
jmp @__ok
;=============================================================================
; Go TSR
; In: AL = exit code
; Out: -
;
@__31h: sub esp,32h
mov ebp,esp
mov bx,cs:_membase
add bx,cs:_buf_size
sub bx,cs:_seg_es
mov [ebp+1Ch],ax
mov [ebp+14h],bx
call int21h
add esp,32h
jmp @__ok
;=============================================================================
; Get Drive Parameter Block
; In: DL = drive number
; Out: AL = status
; DS:EBX = addr of DPB
;
;@__32h: jmp @__1Fh
;=============================================================================
; Get InDOS flag address
; In: -
; Out: ES:EBX = addr of InDOS flag
;
@__34h: call @__all
shl edi,4
add ebx,edi
mov [esp+10h],ebx
mov ax,cs:_sel_zero
mov [esp+20h],ax
jmp @__ok
;=============================================================================
; Get INT vector
; In: AL = INT vector
; Out: ES:EBX = sel:offs
;
@__35h: mov bl,al
mov ax,0204h
int 31h
mov [esp+20h],cx
mov [esp+10h],edx
jmp @__ok
;=============================================================================
; Create Directory
; In: DS:EDX = directory name
; Out: -
;
@__39h:
@__3Ah:
@__3Bh:
@__41h:
@__5Ah:
@__5Bh:
call @__std
jz @__ok
mov [esp+1Ch],eax
jmp @__err
;=============================================================================
; Remove Directory
; In: DS:EDX = directory name
; Out: -
;
;@__3Ah: jmp @__39h
;=============================================================================
; Change Directory
; In: DS:EDX = directory name
; Out: -
;
;@__3Bh: jmp @__39h
;=============================================================================
; Create File
; In: DS:EDX = file name, ECX = attributes
; Out: EAX = file handle
;
@__3Ch:
@__3Dh: call @__std
mov [esp+1Ch],eax
jz @__ok
jmp @__err
;=============================================================================
; Open File
; In: DS:EDX = file name, AL = access mode
; Out: EAX = file handle
;
;@__3Dh: jmp @__3Ch
;=============================================================================
; Read from File
; In: DS:EDX = addr, ECX = size, EBX = handle
; Out: EAX = bytes read
;
@__3Fh: push ds
pop es
mov ds,cs:_sel_ds ; DS=_TEXT16
sub esp,32h
mov ebp,esp
mov [ebp+10h],bx ; store handle in structure
mov edi,edx ; ES:EDI=destination
mov ebx,ecx ; EBX=bytes to read
xor edx,edx ; EDX=counter bytes read
cmp ecx,_lobufsize
jbe @@low
@@0: mov ax,_seg_buf
mov word ptr [ebp+24h],ax ; store DS in structure
mov word ptr [ebp+14h],0 ; store DX in structure
mov byte ptr [ebp+1Dh],3Fh ; store AH in structure
mov eax,ebx
cmp eax,_lobufsize
jbe @@1
mov eax,_lobufsize
@@1: mov [ebp+18h],ax ; store CX in structure
call int21h ; DOS read from file
movzx eax,word ptr [ebp+1Ch] ; EAX=bytes read
test byte ptr [ebp+20h],1 ; check for error
jnz @@err
mov ecx,eax ; ECX=EAX for string copy
mov esi,_lobufbase
jcxz @@done ; if ECX=0, 0 bytes read, done
shr cx,2
rep movs dword ptr es:[edi],[esi] ; copy buffer
mov cl,al
and cl,03h
rep movs byte ptr es:[edi],[esi]
add edx,eax ; adjust bytes read
sub ebx,eax ; adjust bytes to read
ja @@0
@@done: add esp,32h
mov [esp+1Ch],edx ; store bytes count
jmp @__ok
@@err: add esp,32h
mov [esp+1Ch],eax ; error reading, store errcode
jmp @__err
@@low: mov ax,_seg_buf
mov word ptr [ebp+24h],ax ; store DS in structure
mov word ptr [ebp+18h],cx ; store CX in structure
mov word ptr [ebp+14h],0 ; store DX in structure
mov byte ptr [ebp+1Dh],3Fh ; store AH in structure
call int21h ; DOS read from file
movzx eax,word ptr [ebp+1Ch] ; EAX=bytes read
test byte ptr [ebp+20h],1 ; check for error
jnz @@err
mov ecx,eax ; ECX=EAX for string copy
mov esi,_lobufbase
jcxz @@done ; if ECX=0, 0 bytes read, done
shr cx,2
rep movs dword ptr es:[edi],[esi] ; copy buffer
mov cl,al
and cl,03h
rep movs byte ptr es:[edi],[esi]
add edx,eax ; adjust bytes read
jmp @@done
;=============================================================================
; Write to File
; In: DS:EDX = addr, ECX = size, EBX = handle
; Out: EAX = bytes written
;
@__40h: mov es,cs:_sel_ds
sub esp,32h
mov ebp,esp
mov [ebp+10h],bx ; store handle in structure
mov esi,edx ; DS:ESI=source
mov ebx,ecx ; EBX=bytes to write
xor edx,edx ; EDX=counter bytes written
cmp ecx,cs:_lobufsize
jbe @@low
@@0: mov ax,cs:_seg_buf
mov word ptr [ebp+24h],ax ; store DS in structure
mov word ptr [ebp+14h],0 ; store DX in structure
mov byte ptr [ebp+1Dh],40h ; store AH in structure
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -