📄 api.asm
字号:
.386
_apiCode segment para 'API CODE' use32
assume cs:_apiCode, ds:_apiCode
_apiCodeStart label byte
;*******************************************************************************
;Put carry into return carry.
;*******************************************************************************
cwAPI_C2C macro
push eax
pushfd
pushfd
pop eax
and al,1
cwAPI_AL2C
popfd
pop eax
endm
;*******************************************************************************
;Put carry into return carry.
;*******************************************************************************
cwAPI_AL2C macro
local __0, __1
pushfd
assume ds:nothing
test cs:apiSystemFlags,1
jz __0
or b[ebp+Int_Flags16],al
jmp __1
__0: or b[ebp+Int_Flags32],al
__1: assume ds:_apiCode
popfd
endm
;*******************************************************************************
;Call old int 31h handler.
;*******************************************************************************
cwAPI_CallOld macro
local __0, __1
assume ds:nothing
test cs:apiSystemFlags,1
jz __0
pushf
db 66h
call cs:f[OldIntSys] ;pass it onto previous handler.
jmp __1
__0: pushfd
call cs:f[OldIntSys] ;pass it onto previous handler.
__1: assume ds:_apiCode
endm
;*******************************************************************************
;Convert character in AL to upper case.
;*******************************************************************************
UpperChar macro
local __0
cmp al,61h ; 'a'
jb __0
cmp al,7Ah ; 'z'
ja __0
and al,5Fh ;convert to upper case.
__0: ;
endm
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;This must be just before cwAPIpatch
;
cwIdentity db "CAUSEWAY"
cwMajorVersion db 0
cwMinorVersion db 0
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;CW API int 31h patch.
;
cwAPIpatch proc near
pushm ds,es,fs,gs ;Preserve all registers.
pushad ;/
mov ebp,esp ;Make registers addressable.
;
;Check if we're allowed to interfere.
;
push ds
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp Int21hExecCount,0
assume ds:_apiCode
pop ds
jnz @@Nope
;
;Check if this is a CauseWay function.
;
cmp ah,255
jz @@Ours
;
;Scan the table of other relavent functions.
;
mov edi,offset apiExtraCallTable+2
@@extra: cmp cs:w[edi-2],0
jz @@Nope
cmp ax,cs:w[edi-2]
jz @@GotCall
add edi,4+2
jmp @@extra
;
;An internal funtion? so point to table entry.
;
@@Ours: movzx edi,al
shl edi,2
add edi,offset apiCallTable
;
;Check if final call is still going to pass control to the old handler.
;
@@GotCall: cmp cs:d[edi],0
jz @@Nope
;
;See about turning interrupts back on.
;
mov esi,Int_Flags32
assume ds:nothing
test cs:apiSystemFlags,1 ;/
assume ds:_apiCode
jz @@32bit0 ;/
movzx ebp,bp ;/
mov esi,Int_Flags16
@@32Bit0: and ss:b[ebp+esi],not 1 ;clear carry.
cld ;Default direction.
test ss:w[ebp+esi],1 shl 9 ;Were interrupts enabled?
jz @@NoInts
sti ;Turn interrupts back on.
;
;Call the function handler.
;
@@NoInts: assume ds:nothing
call cs:d[edi] ;Pass control to handler.
assume ds:_apiCode
popad ;\
popm ds,es,fs,gs ;Restore all registers.
assume ds:nothing
test cs:apiSystemFlags,1
assume ds:_apiCode
jz @@32Bit1
iret
@@32Bit1: iretd ;Return to caller.
;
;Not an internal function or anything we want to interfere with so pass control
;to origional handler.
;
@@Nope: popad ;Restore registers.
popm ds,es,fs,gs
assume ds:nothing
test cs:apiSystemFlags,1
jz @@n32
db 66h
@@n32: jmp cs:f[OldIntSys] ;pass it onto previous handler.
assume ds:_apiCode
;
OldIntSys df 0
;
APICallTable dd cwAPI_Info ;00
dd cwAPI_IntXX ;01
dd cwAPI_FarCallReal ;02
dd cwAPI_GetSel ;03
dd cwAPI_RelSel ;04
dd cwAPI_CodeSel ;05
dd cwAPI_AliasSel ;06
dd cwAPI_GetSelDet ;07
;
dd cwAPI_GetSelDet32 ;08
dd cwAPI_SetSelDet ;09
dd cwAPI_SetSelDet32 ;0A
dd cwAPI_GetMem ;0B
dd cwAPI_GetMem32 ;0C
dd cwAPI_ResMem ;0D
dd cwAPI_ResMem32 ;0E
dd cwAPI_RelMem ;0F
;
dd cwAPI_GetMemLinear ;10
dd cwAPI_GetMemLinear32 ;11
dd cwAPI_ResMemLinear ;12
dd cwAPI_ResMemLinear32 ;13
dd cwAPI_RelMemLinear ;14
dd cwAPI_RelMemLinear32 ;15
dd cwAPI_GetMemNear ;16
dd cwAPI_ResMemNear ;17
;
dd cwAPI_RelMemNear ;18
dd cwAPI_Linear2Near ;19
dd cwAPI_Near2Linear ;1A
dd cwAPI_LockMem ;1B
dd cwAPI_LockMem32 ;1C
dd cwAPI_UnLockMem ;1D
dd cwAPI_UnLockMem32 ;1E
dd cwAPI_LockMemNear ;1F
;
dd cwAPI_UnLockMemNear ;20
dd cwAPI_GetMemDOS ;21
dd cwAPI_ResMemDOS ;22
dd cwAPI_RelMemDOS ;23
dd cwAPI_Exec ;24
dd cwAPI_GetDOSTrans ;25
dd cwAPI_SetDOSTrans ;26
dd cwAPI_GetMCBSize ;27
;
dd cwAPI_SetMCBSize ;28
dd cwAPI_GetSels ;29
dd cwAPI_cwLoad ;2A
dd cwAPI_cwcInfo ;2B
dd cwAPI_GetMemSO ;2C
dd cwAPI_ResMemSO ;2D
dd cwAPI_RelMemSO ;2E
dd cwAPI_UserDump ;2F
; dd 16 dup (0) ;30-3F
dd cwAPI_SetDump ; 30
dd cwAPI_UserErrTerm ; 31
dd cwAPI_CWErrName ; 32
dd 13 dup (0) ;33-3F
dd 16 dup (0) ;40-4F
dd 16 dup (0) ;50-5F
dd 16 dup (0) ;60-6F
dd 16 dup (0) ;70-7F
;
dd 16*7 dup (0) ;80-EF
;
dd 8 dup (0) ;F0-F7
;
dd 0 ;F8
dd cwAPI_ID ;F9
dd cwAPI_GetPatch ;FA
dd cwAPI_cwcLoad ;FB
dd cwAPI_LinearCheck ;FC
dd cwAPI_ExecDebug ;FD
dd cwAPI_Cleanup ;FE
dd 0 ;FF
;
apiExtraCallTable label byte
dw 0600h
dd dpmiAPI_Lock
dw 0601h
dd dpmiAPI_UnLock
dw 0303h
dd dpmiAPI_GetCallBack
dw 0304h
dd dpmiAPI_RelCallBack
dw 0
cwAPIpatch endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0600h
;BX:CX = Starting linear address of memory to lock
;SI:DI = Size of region to lock in bytes
;
dpmiAPI_Lock proc near
mov ax,[ebp+Int_AX]
mov bx,[ebp+Int_BX]
mov cx,[ebp+Int_CX]
mov si,[ebp+Int_SI]
mov di,[ebp+Int_DI]
pushad
shl ebx,16
mov bx,cx
shl esi,16
mov si,di
mov edx,ebx
mov ecx,esi
mov ax,Res_LOCK
call RegisterResource
popad
cwAPI_CallOld
cwAPI_C2C
jnc @@0
mov [ebp+Int_AX],ax
@@0: ret
dpmiAPI_Lock endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0601h
;BX:CX = Starting linear address of memory to unlock
;SI:DI = Size of region to unlock in bytes
;
dpmiAPI_UnLock proc near
mov ax,[ebp+Int_AX]
mov bx,[ebp+Int_BX]
mov cx,[ebp+Int_CX]
mov si,[ebp+Int_SI]
mov di,[ebp+Int_DI]
pushad
shl ebx,16
mov bx,cx
shl esi,16
mov si,di
mov edx,ebx
mov ecx,esi
mov ax,Res_LOCK
call ReleaseResource
popad
cwAPI_CallOld
cwAPI_C2C
jnc @@0
mov [ebp+Int_AX],ax
@@0: ret
dpmiAPI_UnLock endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0303h
;DS:(E)SI = Selector:Offset of procedure to call
;ES:(E)DI = Selector:Offset of real mode call structure
;
;Returns
;
;If function was successful:
;Carry flag is clear.
;CX:DX = Segment:Offset of real mode call address
;
dpmiAPI_GetCallBack proc near
mov ax,[ebp+Int_AX]
mov ds,[ebp+Int_DS]
mov esi,[ebp+Int_ESI]
mov es,[ebp+Int_ES]
mov edi,[ebp+Int_EDI]
cwAPI_CallOld
cwAPI_C2C
jc @@9
;
mov [ebp+Int_CX],cx
mov [ebp+Int_DX],dx
;
shl ecx,16
mov cx,dx
mov edx,ecx
mov ecx,esi
xor ebx,ebx
mov bx,ds
mov ax,Res_CALLBACK
call RegisterResource
;
@@9: ret
dpmiAPI_GetCallBack endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;AX = 0304h
;CX:DX = Real mode call-back address to free
;
dpmiAPI_RelCallBack proc near
mov ax,[ebp+Int_AX]
mov cx,[ebp+Int_CX]
mov dx,[ebp+Int_DX]
cwAPI_CallOld
cwAPI_C2C
jc @@9
;
shl ecx,16
mov cx,dx
mov edx,ecx
mov ax,Res_CALLBACK
call ReleaseResource
;
@@9: ret
dpmiAPI_RelCallBack endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Call user termination routine on exception
;
;On Entry:
;
; AX = 0ff31h
; CL = 0 if 16-bit termination routine
; CL = nonzero if 32-bit termination routine
; DS:[E]SI = user termination routine address, if ES is zero or an invalid
; selector value, then the user termination routine call is removed
; ES:[E]DI = user information dump area
;
;Returns:
;
; None
;
cwAPI_UserErrTerm PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov UserTermFlag,0 ; initialize flag
mov dx,[ebp+Int_DS]
lsl ax,dx
jnz uetret ; invalid selector
mov al,[ebp+Int_CL] ; get bitness flag
test al,al
setne al ; 0 if 0, 1 if nonzero
inc ax ; 1 if 16-bit, 2 if 32-bit
mov UserTermFlag,al
cmp al,1 ; see if 16-bit
jne uet32 ; no
mov ax,[ebp+Int_SI]
mov WORD PTR UserTermRoutine,ax
mov WORD PTR UserTermRoutine+2,dx
mov ax,[ebp+Int_DI]
mov WORD PTR UserTermDump,ax
mov ax,[ebp+Int_ES]
mov WORD PTR UserTermDump+2,ax
jmp uetret
uet32:
mov eax,[ebp+Int_ESI]
mov DWORD PTR UserTermRoutine,eax
mov WORD PTR UserTermRoutine+4,dx
mov eax,[ebp+Int_EDI]
mov DWORD PTR UserTermDump,eax
mov ax,[ebp+Int_ES]
mov WORD PTR UserTermDump+4,ax
uetret:
ret
cwAPI_UserErrTerm ENDP
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Disable/enable error display and CW.ERR creation
;
;On Entry:
;
; AX = 0ff30h
; CL = 0, disable error display and CW.ERR file creation
; CL = nonzero, enable error display and CW.ERR file creation
;
;Returns:
;
; None
;
cwAPI_SetDump PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov al,[ebp+Int_CL]
mov EnableDebugDump,al
ret
cwAPI_SetDump ENDP
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
; change CW.ERR file name, with optional path/drivespec
;
;On Entry:
;
; AX = 0ff32h
; CX:[E]DX = new CW.ERR ASCIIZ file name
;
;Returns:
;
; None
;
cwAPI_CWErrName PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov edx,[ebp+Int_EDX]
test cs:apiSystemFlags,1
jz cen2
movzx edx,dx ; 16-bit, zero high word of edx
cen2:
mov ax,[ebp+Int_CX]
mov es,ax
mov ebx,OFFSET NewCWErrName ; ds:ebx -> destination, es:edx -> source
mov cx,80 ; don't allow more than 80 chars in file name
cenloop:
mov al,es:[edx]
test al,al
je centerm ; at null terminator
mov ds:[ebx],al
inc edx
inc ebx
dec cx
jne cenloop
centerm:
mov BYTE PTR ds:[ebx],0
ret
cwAPI_CWErrName ENDP
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Setup user buffer display in CW.ERR file
;
;On Entry:
;
; AX = 0ff2fh
; ES:[E]DI -> user buffer to display in CW.ERR
; CX = count of bytes to display from buffer in CW.ERR
; BL = 'A' if ASCII dump (non-binary display of bytes, control characters
; display as periods)
; BH = nonzero if preset ASCII buffer to word value, ignored for non-ASCII
; DX = word value to fill ASCII dump buffer if BH is nonzero, ignored
; for non-ASCII
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -