📄 api.asm
字号:
;Returns:
;
; Carry set on ASCII dump invalid buffer address
;
cwAPI_UserDump PROC NEAR
mov ds,cs:apiDSeg
assume ds:_cwMain
mov ax,[ebp+Int_ES]
verr ax
jnz udfail ; can't read to user selector
mov DebugUserSel,ax
mov es,ax
mov edi,[ebp+Int_EDI]
xor eax,eax
mov ax,es
lsl eax,eax
cmp eax,10000h
jnc @@0
movzx edi,di
@@0:
mov DebugUserOff,edi
mov cx,[ebp+Int_CX]
mov DebugUserCount,cx
; check for out of bounds
movzx edx,cx
add edx,edi
jc udfail
dec edx ; make relative 0
xor eax,eax
mov ax,es
lsl eax,eax
cmp eax,edx
jb udfail
mov al,[ebp+Int_BL]
cmp al,'A'
je aflag
xor al,al
aflag:
mov DebugAsciiFlag,al
test al,al
je udret ; if not ASCII then no fill
mov al,[ebp+Int_BH] ; check fill flag
test al,al ; no fill, carry flag reset by default
je udret
; fill the allocation with value in dx to count specified in cx
mov ax,es
verw ax
jnz udfail ; can't write to user selector
mov ax,[ebp+Int_DX]
push ax
push ax
pop eax
push ecx
shr ecx,1
rep stosd
pop ecx
and cx,3
je udsuccess
mov es:[edi],al ; finish off remainder bytes
dec cx
je udsuccess
inc edi
mov es:[edi],ah
dec cx
je udsuccess
inc edi
mov es:[edi],al
udsuccess:
clc ; flag success
jmp udret
udfail:
mov DebugUserCount,0
stc ; flag failure
udret:
cwAPI_C2C
ret
cwAPI_UserDump ENDP
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get CauseWay identifier, return PageDIRLinear and Page1stLinear info
;
;Returns:
;
;EDX - Linear address of patch table.
;
cwAPI_ID proc near
push ds
assume ds:nothing
mov ax,KernalDS
mov ds,ax
assume ds:_cwRaw
mov esi,PageDIRLinear
mov edi,Page1stLinear
pop ds
mov ecx,"CAUS"
mov edx,"EWAY"
mov [ebp+Int_ESI],esi
mov [ebp+Int_EDI],edi
mov [ebp+Int_EDX],edx
mov [ebp+Int_ECX],ecx
xor al,al
cwAPI_AL2C
ret
cwAPI_ID endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get patch table address.
;
;Returns:
;
;EDX - Linear address of patch table.
;
cwAPI_GetPatch proc near
assume ds:nothing
mov bx,cs:apiDDSeg
sys GetSelDet32
add edx,offset PatchTable
assume ds:_apiCode
mov [ebp+Int_EDX],edx
xor al,al
cwAPI_AL2C
ret
cwAPI_GetPatch endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get address of transfer buffer.
;
;Returns:
;
;BX - Real mode segment
;DX - Protected mode selector.
;ECX - Buffer size.
;
cwAPI_GetDOSTrans proc near
assume ds:nothing
mov es,cs:apiDSeg
assume es:_cwMain
mov es,es:PSPSegment
assume es:nothing
assume ds:_apiCode
mov ax,es:w[EPSP_TransReal]
mov [ebp+Int_BX],ax
mov ax,es:w[EPSP_TransProt]
mov [ebp+Int_DX],ax
mov eax,es:d[EPSP_TransSize]
mov [ebp+Int_ECX],eax
ret
cwAPI_GetDOSTrans endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Set real mode transfer buffer address.
;
;On Entry:
;
;BX - Real mode segment.
;DX - Protected mode selector.
;ECX - Buffer size.
;
cwAPI_SetDOSTrans proc near
mov bx,[ebp+Int_BX]
mov dx,[ebp+Int_DX]
mov ecx,[ebp+Int_ECX]
assume ds:nothing
mov es,cs:apiDSeg
assume es:_cwMain
mov es,es:PSPSegment
assume es:nothing
assume ds:_apiCode
mov es:w[EPSP_TransReal],bx
mov es:w[EPSP_TransProt],dx
cmp ecx,10000h
jc @@0
mov ecx,65535
@@0: mov es:d[EPSP_TransSize],ecx
ret
cwAPI_SetDOSTrans endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Get various useful variable contents.
;
;Returns:
;
;AX - 0-4G selector.
;BX - Current PSP selector.
;ECX - Transfer buffer size.
;DX - Transfer buffer real mode segment.
;ESI - Transfer buffer offset.
;DI - System flags.
;ES - Transfer buffer protected mode selector.
;
cwAPI_Info proc near
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
mov di,w[SystemFlags]
mov ax,RealSegment
mov bx,PspSegment
mov es,bx
mov dx,es:w[EPSP_TransReal]
mov ecx,es:d[EPSP_TransSize]
mov es,es:w[EPSP_TransProt]
xor esi,esi
assume ds:_apiCode
mov [ebp+Int_AX],ax
mov [ebp+Int_BX],bx
mov [ebp+Int_ECX],ecx
mov [ebp+Int_DX],dx
mov [ebp+Int_ESI],esi
mov [ebp+Int_DI],di
mov [ebp+Int_ES],es
ret
cwAPI_Info endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Pass control to a real mode interrupt handler.
;
;On Entry:
;
;BL - INT number.
;ES:[E]DI - Real mode register structure.
;
cwAPI_IntXX proc near
mov edi,[ebp+Int_EDI]
mov es,[ebp+Int_ES]
; mov bl,[ebp+Int_BL]
xor eax,eax
mov ax,es
lsl eax,eax
cmp eax,10000h
jnc @@0
movzx edi,di
@@0: assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp ProtectedType,2
assume ds:_apiCode
jnz @@NoStack0
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
sub DPMIStackOff,RawStackDif
mov ax,DPMIStackOff
add ax,RawStackDif
mov es:Real_SP[edi],ax
mov ax,DPMIStackSeg
mov es:Real_SS[edi],ax
; MED 05/23/96
test cs:apiSystemFlags,1
jz medUse32Bit8
mov ebx,Int_Flags16
jmp medUse16Bit8
medUse32Bit8:
mov ebx,Int_Flags32
medUse16Bit8:
mov ax,ss:[ebp+ebx]
and ax,1111110011111111b ;clear Trap and INT flag.
mov es:Real_Flags[edi],ax ; explicitly set flags on DPMI 300h call
assume ds:_apiCode
jmp @@DoneStack0
@@NoStack0:
mov es:Real_SP[edi],0 ;use DPMI provided stack.
mov es:Real_SS[edi],0
@@DoneStack0:
xor cx,cx ;No stack parameters.
mov bh,ch ;no flags.
mov bl,ss:[ebp+Int_BL] ; MED 05/23/96
mov ax,0300h
cwAPI_CallOld
cwAPI_C2C
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp ProtectedType,2
assume ds:_apiCode
jnz @@DoneStack1
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
add DPMIStackOff,RawStackDif
assume ds:_apiCode
@@DoneStack1: assume ds:nothing
test cs:apiSystemFlags,1
assume ds:_apiCode
jz @@Use32Bit8
mov ebx,Int_Flags16
jmp @@Use16Bit8
@@Use32Bit8: mov ebx,Int_Flags32
@@Use16Bit8: mov ax,ss:[ebp+ebx]
and ax,0000011000000000b ;retain IF.
and es:Real_Flags[edi],1111100111111111b ;lose IF.
or es:Real_Flags[edi],ax
ret
cwAPI_IntXX endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Pass control to a real mode far routine.
;
;On Entry:
;
;ES:[E]DI - Real mode register structure.
;
cwAPI_FarCallReal proc near
mov edi,[ebp+Int_EDI]
mov es,[ebp+Int_ES]
xor eax,eax
mov ax,es
lsl eax,eax
cmp eax,10000h
jnc @@0
movzx edi,di
@@0: pushf
pop es:Real_Flags[edi]
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp ProtectedType,2
assume ds:_apiCode
jnz @@NoStack1
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
sub DPMIStackOff,RawStackDif
mov ax,DPMIStackOff
add ax,RawStackDif
mov es:Real_SP[edi],ax
mov ax,DPMIStackSeg
mov es:Real_SS[edi],ax
assume ds:_apiCode
jmp @@DoneStack2
@@NoStack1: mov es:Real_SP[edi],0 ;use DPMI provided stack.
mov es:Real_SS[edi],0
@@DoneStack2: xor cx,cx ;No stack parameters.
xor bx,bx ;no flags.
mov ax,0301h
cwAPI_CallOld
cwAPI_C2C
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
cmp ProtectedType,2
assume ds:_apiCode
jnz @@DoneStack3
assume ds:nothing
mov ds,cs:apiDSeg
assume ds:_cwMain
add DPMIStackOff,RawStackDif
assume ds:_apiCode
@@DoneStack3: ;
assume ds:nothing
test cs:apiSystemFlags,1
assume ds:_apiCode
jz @@Use32Bit8
mov ebx,Int_Flags16
jmp @@Use16Bit8
@@Use32Bit8: mov ebx,Int_Flags32
@@Use16Bit8: mov ax,ss:[ebp+ebx]
and ax,0000011000000000b ;retain IF.
and es:Real_Flags[edi],1111100111111111b ;lose IF.
or es:Real_Flags[edi],ax
ret
cwAPI_FarCallReal endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a selector.
;
;Returns:
;
;Carry set on error (no more selectors) else,
;
;BX - new selector.
;
cwAPI_GetSel proc near
xor eax,eax
xor ebx,ebx
call _SetSelector
cwAPI_C2C
jc @@9
mov [ebp+Int_BX],bx
@@9: ret
cwAPI_GetSel endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate multiple selectors.
;
;On Entry:
;
;CX - Number of selectors.
;
;Returns:
;
;Carry set on error (not enough selectors) else,
;
;BX - Base selector.
;
cwAPI_GetSels proc near
;
;Get selectors from DPMI.
;
mov cx,[ebp+Int_CX]
mov ax,0000h
cwAPI_CallOld
cwAPI_C2C
jc @@9
;
mov [ebp+Int_BX],ax
movzx edx,ax
movzx ecx,cx
mov ax,Res_SEL
@@0: call RegisterResource
add edx,8
dec ecx
jnz @@0
;
@@9: ret
cwAPI_GetSels endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Release a selector.
;
;On Entry:
;
;BX - Selector to release.
;
cwAPI_RelSel proc near
mov bx,[ebp+Int_BX]
mov ds,[ebp+Int_DS]
mov es,[ebp+Int_ES]
mov fs,[ebp+Int_FS]
mov gs,[ebp+Int_GS]
call _RelSelector
cwAPI_C2C
jc @@9
mov [ebp+Int_DS],ds
mov [ebp+Int_ES],es
mov [ebp+Int_FS],fs
mov [ebp+Int_GS],gs
@@9: ret
cwAPI_RelSel endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Force a selector to be type CODE.
;
;On Entry:
;
;BX - Selector.
;
cwAPI_CodeSel proc near
mov bx,[ebp+Int_BX]
call _CodeSelector
cwAPI_C2C
ret
cwAPI_CodeSel endp
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Allocate a selector with type DATA that maps same memory as another selector.
;
;On Entry:
;
;BX - selector.
;
;Returns:
;
;AX - New selector.
;
cwAPI_AliasSel proc near
mov ax,000ah
mov bx,[ebp+Int_BX]
cwAPI_CallOld
cwAPI_C2C
jc @@9
;
mov [ebp+Int_AX],ax
pushm eax,edx
movzx edx,ax
mov ax,Res_SEL
call RegisterResource
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -