📄 cw32.asm
字号:
;
;CauseWay v2 main file.
;
;
;Things to note:
;
;The IDT has a page to itself even though it only needs 2k. For RAW/VCPI systems
;the top 2k could be used for something else.
;
;Things to do:
;
;Put in some sort of system stack overflow checking and terminate the program
;if it happens.
;
option oldstructs
include general.inc
include strucs.inc
include cw.inc
; include cw-undoc.inc
ifndef ENGLISH
ENGLISH equ 0
endif
ifndef SPANISH
SPANISH equ 0
endif
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;
;Main code segment. This takes care of calling the right initialisation routines
;and generaly getting everything rolling.
;
_cwMain segment para public 'Main thread' use16
assume cs:_cwMain, ds:_cwMain, ss:_cwStack
;
;Want a copyright message embedded first.
;
Copyright label byte
db 'CauseWay DOS Extender v'
VersionMajor db '3.'
VersionMinor db '60'
db " No copyright. Public domain. MED.",13,10,"No rights retained. ",13,10,0
.386
;-------------------------------------------------------------------------------
;
;Final init stuff.
;
cwOpen proc near
assume ds:nothing ;make our data addresable.
mov ds,cs:DataSegment
assume ds:_cwMain
;
mov d[TerminationHandler],offset cwClose
mov w[TerminationHandler+4],cs
;
;Now we know the machines details, re-size the program
;block again to release as much memory as possible.
;
mov edi,offset Int21Buffer
push ds
pop es
mov ax,RealPSPSegment
mov es:Real_ES[edi],ax
mov bx,_cwDPMIEMU
cmp ProtectedType,2
jnz @@KeepRaw
mov bx,_cwRaw
@@KeepRaw: sub bx,ax ;Size program.
inc bx
mov TSRSize,bx
mov es:Real_EBX[edi],ebx
mov es:Real_EAX[edi],4a00h
mov bl,21h
mov ErrorNumber,1
sys IntXX
test es:w[edi+Real_Flags],1
jnz @@9
mov ErrorNumber,0 ;clear error number.
;
;Force accurate memory values.
;
or ecx,-1
sys GetMemLinear32
;
;Enable resource tracking and MCB allocations.
;
or ResourceTracking,-1 ;Enable resource tracking.
;
;Run the main program.
;
mov edx,offset MainExec ;name to exec.
mov esi,80h
mov es,PSPSegment
xor cx,cx
sys cwExec ;run the bugger.
jnc @@8
add ax,10-1 ;convert error number.
mov ErrorNumber,ax
jmp @@9
@@8: cmp DebugDump,0
jnz @@9
mov ErrorLevel,ax ;store programs error level.
mov ErrorNumber,0 ;clear error number.
@@9: jmp cwClose
cwOpen endp
;-------------------------------------------------------------------------------
;
;Shut everything down.
;
cwClose proc near
IFDEF DEBUG4
push eax
push ebx
push ecx
push edx
push ds
push cs
pop ds
mov edx,OFFSET debugatext1
debugaloop2:
cmp BYTE PTR ds:[edx],0
je debugab
mov ecx,1
mov bx,1
mov ah,40h
int 21h
inc edx
jmp debugaloop2
debugab:
mov edx,OFFSET debugatext2
push cs
pop ds
mov ecx,2
mov bx,1
mov ah,40h
int 21h
pop ds
pop edx
pop ecx
pop ebx
pop eax
jmp debugaout
debugatext1 DB 'Entering cwClose...',0
debugatext2 DB 13,10
debugaout:
push ecx
mov ecx,100000h
debugaloop:
; dec ecx
; jne debugaloop
pop ecx
ENDIF
assume ds:nothing
mov ds,cs:DataSegment
assume ds:_cwMain
;
mov ResourceTracking,0
mov mcbAllocations,0
sti
mov w[TerminationHandler+4],0
;
IFDEF DEBUG4
push eax
push ebx
push ecx
push edx
push ds
mov dx,w[ExceptionExtension+12]
; lar ax,dx
cmp dx,127h
jnz debughout
; and ah,3
; cmp ah,3
; jne debughout
push cs
pop ds
mov edx,OFFSET debughtext1
debughloop2:
cmp BYTE PTR ds:[edx],0
je debughb
mov ecx,1
mov bx,1
mov ah,40h
int 21h
inc edx
jmp debughloop2
debughb:
mov edx,OFFSET debughtext2
push cs
pop ds
mov ecx,2
mov bx,1
mov ah,40h
int 21h
pop ds
pop edx
pop ecx
pop ebx
pop eax
jmp debughout
debughtext1 DB 'Calling DebugDisplay...',0
debughtext2 DB 13,10
debughout:
push ecx
mov ecx,100000h
debughloop:
; dec ecx
; jne debughloop
pop ecx
ENDIF
push cs
push offset @@dd0
push w[ExceptionExtension+12]
mov eax,offset DebugDisplay
push ax
retf
@@dd0: ;
cmp ErrorNumber,0
jz @@NoError
mov ax,ErrorNumber ;Get the error number.
xor dx,dx
mov cx,10
div cx
add al,'0'
mov b[ErrorM00n],al
add dl,'0'
mov b[ErrorM00n+1],dl
cmp EnableDebugDump,0 ; if debug dump turned off, no screen i/o
je @@NoError
xor edx,edx
mov dx,w[ErrorList]
mov ah,9
int 21h
;
;Get a pointer to the appropriate error message and print it.
;
mov bx,ErrorNumber
add bx,bx
xor edx,edx
mov dx,[ErrorList+bx]
mov ah,9
int 21h
;
;Now exit with the error number as the DOS "errorlevel".
;
@@NoError:
;
;Remove extension patches.
;
mov di,offset ExtensionList ;list of interupt patches.
@@p1: cmp w[di+2],-1 ;search for the end of the table so we can restore
jz @@p0 ;vectors in reverse order.
add di,2
jmp @@p1
;
@@p0: mov bp,w[di]
cmp ds:w[bp+32],-1 ;installed?
jnz @@p2
pushm di,bp
push cs
push offset @@p3
push ds:w[bp+20]
push ds:w[bp+16]
retf
@@p3: popm di,bp
@@p2: sub di,2
cmp di,offset ExtensionList-2
jnz @@p0
;
;Remove api exception patches.
;
cmp apiExcepPatched,0
jz @@pe0
mov ax,cs
push ax
mov ax,offset @@pe0
push ax
mov ax,apiCodeSeg
push ax
mov eax,offset UnPatchExc
push ax
retf
@@pe0: ;
;
;Remove the API patch.
;
mov es,apiDataSeg
assume es:_apiCode
test SystemFlags,1
jz @@Use32
mov dx,es:w[OldIntSys]
mov cx,es:w[OldIntSys+2]
jmp @@Use0
@@Use32: mov edx,es:d[OldIntSys]
mov cx,es:w[OldIntSys+4]
@@Use0: mov bl,31h
mov ax,205h
int 31h
mov es:d[cwIdentity],0
mov es:d[cwIdentity+4],0
assume es:nothing
;
@@noAPI:
cmp ProtectedType,2 ;DPMI?
jz @@DPMI
;
;Make RAW stuff addressable.
;
cli ;Don't want interrupts interfering.
mov ax,KernalDS ;Get supervisor data descriptor,
mov ds,ax ;DS,ES,FS,GS,SS must be data with 64k limit
assume ds:_cwRaw
mov ax,KernalZero
mov es,ax
;
;Switch to RAW exit code.
;
push _cwMain
push offset @@6
mov ax,KernalCS
push ax
mov ax,offset RawVCPIRealMode
push ax
retf
@@6: jmp @@RealMode
;
;Remove DPMI stuff.
;
@@DPMI:
assume ds:nothing
mov ds,cs:DataSegment
assume ds:_cwMain
if 0
cmp d[OldInt21hExec],0
jz @@d0
mov bl,21h
mov dx,w[OldInt21hExec]
mov cx,w[OldInt21hExec+2]
mov ax,201h
int 31h
@@d0: movzx edx,dx
endif
jmp @@InRealMode
;
;Make sure our data is addressable.
;
@@RealMode: mov ax,_cwMain
mov ds,ax
assume ds:_cwMain
;
;Display the "CauseWay error: ??" bit.
;
@@InRealMode:
if 0
cmp ErrorNumber,0
jz @@NoError
push ax
mov al,3
call bordm
pop ax
mov ax,ErrorNumber ;Get the error number.
xor dx,dx
mov cx,10
div cx
add al,'0'
mov b[ErrorM00n],al
add dl,'0'
mov b[ErrorM00n+1],dl
cmp EnableDebugDump,0 ; if debug dump turned off, no screen i/o
je @@NoError
xor edx,edx
mov dx,w[ErrorList]
mov ah,9
int 21h
;
;Get a pointer to the appropriate error message and print it.
;
mov bx,ErrorNumber
add bx,bx
mov dx,[ErrorList+bx]
mov ah,9
int 21h
;
;Now exit with the error number as the DOS "errorlevel".
;
@@NoError:
endif
; MED, 12/24/99, coalesce free memory by attempting to allocate largest possible
; with upper memory in the chain
mov ax,5800h
int 21h
push ax
mov ax,5802h
int 21h
push ax
mov bx,1
mov ax,5803h
int 21h
mov bx,81h
mov ax,5801h
int 21h
mov ah,48h
mov bx,-1
int 21h
pop bx
mov ax,5803h
int 21h
pop bx
mov ax,5801h
int 21h
mov ax,ErrorNumber
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -