📄 cwd-ovl.asm
字号:
; 2) Add CFG vars for CSEIP,REGS & Data0 window position & size.
; 4) make register display inteligent so if the window is made wider it will
; put registers side by side.
; 6) add source search & goto functions.
; 7) Add place marker dropping/restore
;99) fix window highlight problems when removing windowpopup stuff etc.
;
.386
.model small
.stack 4096
option oldstructs
;
;Setup language equates.
;
ifndef ENGLISH
ENGLISH equ 0
endif
ifndef SPANISH
SPANISH equ 0
endif
include macros.inc
include ..\cw.inc
MaxBreaks equ 256
MaxEIPs equ 4096
MaxWatches equ 64
MaxWindows equ 256
MaxLineLength equ 1024 ;Maximum source line length.
RetStackSize equ 64
include ..\strucs.inc
include disas.inc
;
;Hardware break point table entry structure.
;
HBRK struc
HBRK_Win dw 0 ;display window handle.
HBRK_Handle dw 0 ;DPMI break point handle.
HBRK_Address dd 0 ;Linear break point address.
HBRK_Size db 0 ;DPMI size code to use.
HBRK_Type db 0 ;DPMI type code to use.
HBRK_Flags dw 0 ;padding.
HBRK ends
.code
;-------------------------------------------------------------------------
;
;Trap any calls to a null pointer. Mostly for instruction table mistakes
;but it might catch other problems as well.
;
CallZero proc near
mov ax,DGROUP
mov ds,ax
mov fs,ax
mov gs,ax
mov SystemError,4
pop eax ;Get return address.
mov edi,offset SErrorM04Num
mov ecx,8
call Bin2Hex
jmp system
CallZero endp
;-------------------------------------------------------------------------
;
;Main entry point.
;
main proc near
mov ax,DGROUP
mov ds,ax
mov fs,ax
mov gs,ax
mov PSPSegment,es
mov ax,es:w[2ch]
mov ENVSegment,ax
push ds
pop es
call CheckFPU ; check for FPU presence
;
;Get 0-4G selector and current system flags.
;
push es
sys Info
mov si,di
and si,1
and di,65535-(16384)
shl si,14
or di,si
mov SystemFlags,di
mov RealSegment,ax
pop es
;
;Check for VGA.
;
mov SystemError,5
mov ax,1a00h
int 10h
cmp al,1ah
mov ax,5
jne System
;
;Lock program memory.
;
mov SystemError,1
push fs
mov fs,PSPSegment
mov esi,fs:[EPSP_MemBase]
mov ecx,fs:[EPSP_MemSize]
pop fs
sys LockMem32
jc System
;
;Get a code segment alias.
;
mov SystemError,2
mov bx,cs
sys AliasSel
jc system
mov CodeSegAlias,ax
mov bx,_EXCEP
sys AliasSel
jc system
mov ECodeSegAlias,ax
;
;Get a selector for video memory access.
;
sys GetSel
jc system
mov VideoSwapSel,bx
;
;Extend programs DS limit.
;
mov bx,ds
sys GetSelDet32
mov ecx,-1
sys SetSelDet32
sys GetSelDet32
cmp ecx,-1
jz @@longlimit
or OS2TypeMalloc,-1
;
;Move stack into data segment so we can use EBP without overides.
;
@@longLimit: mov ax,ds
mov ss,ax
mov esp,offset DataStack
;
;Set data segments D bit according to program type.
;
test SystemFlags,1
jz @@no16stack
mov bx,ds
mov ax,000bh
push ds
pop es
mov edi,offset DescriptorBuffer
int 31h
and DescriptorBuffer+6,255-(1 shl 6) ;clear code size bit.
mov ax,000ch
int 31h
;
;Read configuration file if any.
;
@@no16stack: call ReadConfig
;
;Get memory for source file list.
;
mov ecx,4
call Malloc
mov SystemError,1
jc System
mov d[esi],0
mov SourceFileTable,esi
;
;Now setup the mouse.
;
mov ax,0
int 33h
cmp ax,0
jz @@NoMouse
mov MousePresent,1 ;flag mouse.
;
;Allocate mouse state save buffers.
;
mov ax,15h
int 33h
mov SystemError,3
mov ecx,ebx
call Malloc
jc System
mov MouseUserState,esi
call Malloc
jc System
mov MouseOldUserState,esi
call Malloc
jc System
mov MouseDebugState,esi
;
;Set initial Debug mouse state to current.
;
mov edx,esi
mov ax,16h
int 33h
;
;Set user old state to current.
;
mov edx,MouseOldUserState
mov ax,16h
int 33h
;
;Set debug old state to current.
;
mov edx,MouseDebugState
mov ax,16h
int 33h
;
;Allocate video state save buffers.
;
@@NoMouse: mov ah,0fh
int 10h ;get current page.
mov UserOldPage,bh
mov UserOldMode,al
;
;Get 50-line state.
;
mov UserOld50,0
mov ax,1130h
xor bx,bx
xor dx,dx
push es
int 10h
pop es
cmp dl,49
jnz @@U_Not50
or UserOld50,-1
@@U_Not50: ;
mov ax,1c00h
mov cx,1+2+4
int 10h ;get save buffer size.
mov SystemError,3
movzx ebx,bx
shl ebx,6 ;want size in bytes.
mov ecx,ebx
call Malloc
jc System
mov VideoUserState,esi
call Malloc
jc System
mov VideoOldUserState,esi
call Malloc
jc System
mov VideoDebugState,esi
;
;Set initial Debug video state to current.
;
mov ebx,esi
mov ax,1c01h
mov cx,1+2+4
push ebx
int 10h ;save state in buffer.
pop ebx
mov ax,1c02h
mov cx,1+2+4
int 10h ;restore it again.
;
;Set old user video state to current.
;
mov ebx,VideoOldUserState
mov ax,1c01h
mov cx,1+2+4
push ebx
int 10h ;save state in buffer.
pop ebx
mov ax,1c02h
mov cx,1+2+4
int 10h ;restore it again.
;
;Allocate video memory save buffers.
;
mov ecx,65536+4+4
call Malloc
mov VideoUserBuffer,esi
mov d[esi+4],0
call Malloc
mov VideoOldUserBuffer,esi
mov d[esi+4],0
call Malloc
mov VideoDebugBuffer,esi
mov d[esi+4],0
;
;Store current video memory.
;
;
;Get current video memory contents.
;
mov ah,0fh
int 10h ;get current mode.
mov UserMode,al
mov edx,0b8000h
mov ecx,16384
cmp al,3
jz @@vg1
cmp al,4
jz @@vg1
mov edx,0b0000h
cmp al,7 ;80*25*16 T
jc @@vg1
jz @@vg1
mov edx,0a0000h
mov ecx,65535
cmp al,13h ;320*200*256 G
jz @@vg1
mov edx,0b8000h
mov ecx,16384
@@vg1: mov esi,VideoOldUserBuffer
mov [esi],edx
mov [esi+4],ecx
mov bx,VideoSwapSel
sys SetSelDet32
cld
mov edi,VideoOldUserBuffer
mov ecx,[edi+4]
add edi,4+4
xor esi,esi
push ds
mov ds,VideoSwapSel
rep_movsb
pop ds
@@vg2: ;
;Patch INT 9 & INT 31h so we always see keyboard activity
;and can interrupt the program.
;
mov bl,9
sys GetVect
test SystemFlags,1
jz @@i932
movzx edx,dx
@@i932: push ds
mov ds,CodeSegAlias
assume ds:_TEXT
mov d[OldInt09],edx
mov w[OldInt09+4],cx
assume ds:DGROUP
pop ds
mov edx,offset BreakChecker
mov cx,cs
mov bl,9
sys SetVect
mov bl,31h
sys GetVect
test SystemFlags,1
jz @@i3132
movzx edx,dx
@@i3132: push ds
mov ds,CodeSegAlias
assume ds:_TEXT
mov d[OldInt31],edx
mov w[OldInt31+4],cx
push es
mov es,cx
mov ax,es:[edx-2]
pop es
mov w[cwMajorVersion],ax
assume ds:DGROUP
pop ds
mov edx,offset Int31Intercept
mov cx,cs
mov bl,31h
sys SetVect
;
;Check command line for CWD options and retrieve name of program to load.
;
mov DebugName,0
push es
mov es,PSPSegment
mov esi,80h
movzx ecx,es:b[esi]
inc esi
mov edi,offset DebugName ;default to storeing program name.
@@c0: or ecx,ecx
jz @@c1
cmp es:b[esi],' '
jz @@c2
cmp es:b[esi],13
jz @@c2
cmp es:b[esi],10
jz @@c2
cmp es:b[esi],'/' ;option switch?
jnz @@c3
cmp es:w[esi+1],'MD' ;mono display?
jz @@og0
cmp es:w[esi+1],'mD'
jz @@og0
cmp es:w[esi+1],'Md'
jz @@og0
cmp es:w[esi+1],'md'
jnz @@o0
@@og0: mov MonoSwap,1 ;flag want mono display.
mov es:b[esi],' '
mov es:w[esi+1],' '
jmp @@c0
;
@@o0: cmp es:b[esi+1],'e' ;execute to label?
jz @@og1
cmp es:b[esi+1],'E'
jnz @@o1
@@og1: mov es:b[esi],' '
mov es:b[esi+1],' '
add esi,2
pushm edi
mov edi,offset EntryGotoText ;store goto expresion.
@@og1_0: mov al,es:[esi]
or al,al
jz @@og1_1
cmp al,13
jz @@og1_1
cmp al,10
jz @@og1_1
cmp al,' '
jz @@og1_1
mov [edi],al
mov es:b[esi]," "
inc edi
inc esi
jmp @@og1_0
@@og1_1: mov b[edi],0
pop edi
jmp @@c0
@@o1: ;
cmp es:b[esi+1],'a'
jz @@og2
cmp es:b[esi+1],'A'
jnz @@o2
@@og2: mov es:b[esi],' '
mov es:b[esi+1],' '
add esi,2
mov AssemblerMode,-1
jmp @@c0
;
@@o2: cmp es:b[esi+1],"c"
jz @@og3
cmp es:b[esi+1],"C"
jnz @@o3
@@og3: mov es:b[esi]," "
mov es:b[esi+1]," "
add esi,2
mov CMode,-1
jmp @@c0
@@o3: ;
@@c3: cmp ecx,0
jz @@c1
cmp es:b[esi],' '
jz @@c1
cmp es:b[esi],13
jz @@c1
cmp es:b[esi],10
jz @@c1
mov al,es:[esi]
mov es:b[esi],' '
mov [edi],al
inc esi
inc edi
dec ecx
jmp @@c3
;
@@c2: inc esi
dec ecx
jmp @@c0
@@c1: pop es
;
;Clean up the command line, ie, remove any spaces created by removeing options.
;
push es
mov es,PSPSegment
mov esi,80h
movzx ecx,es:b[esi]
or ecx,ecx
jz @@cl3
inc esi
mov edi,esi
@@cl0: cmp es:b[esi],' '
jnz @@cl1
inc esi
dec ecx
jnz @@cl0
@@cl1: jecxz @@cl2
push ecx
push ds
push es
pop ds
rep movsb ;Copy it down.
pop ds
pop ecx
@@cl2: mov es:b[80h],cl ;Store new length.
@@cl3: movzx ecx,cl
add ecx,81h
mov es:b[ecx],13 ;Terminate it correctly.
pop es
;
;Switch to debug screen/page.
;
call DisasScreen
;
;Get memory for window buffers.
;
mov SystemError,3
mov ecx,32768
call Malloc
jc System
mov SystemError,0
;
;Initialise window stuff.
;
mov eax,esi
mov bx,MaxWindows
call InitWindows
mov WindowsOpened,-1
mov ScreenWidth,cl
mov ScreenDepth,ch
;
;open the title bar window.
;
call CursorOFF
mov MenuText,offset Copyright
mov cl,0
mov bl,0
mov ch,ScreenWidth
mov bh,1
mov ax,WindowClear
mov dl,70h
mov esi,0
mov ebp,offset MenuHandler
call OpenWindow
mov MenuHandle,bp
;
;open the help bar window.
;
mov HelpText,offset HelpText1
mov cl,0
mov bl,ScreenDepth
dec bl
mov ch,ScreenWidth
mov bh,1
mov ax,WindowClear
mov dl,70h
mov esi,0
mov ebp,offset HelpHandler
call OpenWindow
mov HelpHandle,bp
call PointWindow
mov WindowFill[esi],' '
;
;Create EXE, MAP and SYM file names.
;
mov ErrorNumber,4
cmp DebugName,0
jz @@4
mov ErrorNumber,0
;
@@4: ;Make .EXE file name.
;
mov esi,offset DebugName ;get file name mask.
mov edi,offset EXEFileName
cld
xor al,al
@@e0: movsb
cmp b[esi-1],'.'
jnz @@e1
mov al,1
@@e1: cmp b[esi-1],0
jnz @@e0
or al,al
jnz @@e2
mov b[edi-1],'.'
mov esi,offset EXEextension
@@e4: movsb
cmp b[esi-1],0
jnz @@e4
;
@@e2: ;Generate .MAP file name.
;
mov esi,offset EXEFileName
mov edi,offset MapFileName
@@e3: movsb
cmp b[esi-1],'.'
jnz @@e3
mov esi,offset MAPextension
@@e5: movsb
cmp b[esi-1],0
jnz @@e5
;
;Generate .SYM file name.
;
mov esi,offset EXEFileName
mov edi,offset SymFileName
@@sn0: movsb
cmp b[esi-1],'.'
jnz @@sn0
mov esi,offset SYMExtension
@@sn1: movsb
cmp b[esi-1],0
jnz @@sn1
;
;Check if we need to display an error message yet.
;
movzx ebx,ErrorNumber
or ebx,ebx
jz @@NoE0
shl ebx,2
mov ebx,[ErrorList+ebx]
call WindowPopup
jmp System
@@NoE0: mov ErrorNumber,0
;
;Patch int 10h for mode checks.
;
mov bl,10h
sys GetVect
test SystemFlags,1
jz @@v32_0
movzx edx,dx
@@v32_0: push ds
mov ds,CodeSegAlias
assume ds:_Text
mov w[OldInt10+4],cx
mov d[OldInt10],edx
assume ds:DGROUP
pop ds
mov cx,cs
mov edx,offset Int10Handler
sys SetVect
;
;Patch exception 0 interupt.
;
mov bl,0
sys GetVect
test SystemFlags,1
jz @@v32_1
movzx edx,dx
@@v32_1: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldInt00+4],cx
mov d[OldInt00],edx
assume ds:DGROUP
pop ds
mov bl,0
mov cx,_EXCEP
mov edx,offset Int00Handler
sys SetVect
;
;Patch debug interupt.
;
mov bl,1
sys GetVect
test SystemFlags,1
jz @@v32_20
movzx edx,dx
@@v32_20: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldInt01+4],cx
mov d[OldInt01],edx
assume ds:DGROUP
pop ds
mov bl,1
mov cx,_EXCEP
mov edx,offset Int01Handler
sys SetVect
;
;Patch trap interupt.
;
mov bl,3
sys GetVect
test SystemFlags,1
jz @@v32_2
movzx edx,dx
@@v32_2: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldInt03+4],cx
mov d[OldInt03],edx
assume ds:DGROUP
pop ds
mov bl,3
mov cx,_EXCEP
mov edx,offset Int03Handler
sys SetVect
;
;Patch debug interupt.
;
mov bl,1
sys GetEVect
test SystemFlags,1
jz @@v32_30
movzx edx,dx
@@v32_30: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldEInt01+4],cx
mov d[OldEInt01],edx
assume ds:DGROUP
pop ds
mov bl,1
mov cx,_EXCEP
mov edx,offset EInt01Handler
sys SetEVect
;
;Patch trap interupt.
;
mov bl,3
sys GetEVect
test SystemFlags,1
jz @@v32_3
movzx edx,dx
@@v32_3: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldEInt03+4],cx
mov d[OldEInt03],edx
assume ds:DGROUP
pop ds
mov bl,3
mov cx,_EXCEP
mov edx,offset EInt03Handler
sys SetEVect
;
;Patch exception 12 interupt.
;
mov bl,12
sys GetEVect
test SystemFlags,1
jz @@v32_4
movzx edx,dx
@@v32_4: push ds
mov ds,ECodeSegAlias
assume ds:_EXCEP
mov w[OldExc12+4],cx
mov d[OldExc12],edx
assume ds:DGROUP
pop ds
mov bl,12
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -