⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.asm

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 ASM
字号:
;Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either
;version 2 of the License, or (at your option) any later
;version.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

%include "macros.mac"

EXTSYM DosExit,curblank,previdmode,start65816,wramdata,C4Ram,cnetplaybuf
EXTSYM UpdateDPage,SA1Enable,splitflags,joinflags,delay
EXTSYM Open_File,Read_File,Create_File,Write_File,Close_File,romdata
EXTSYM Check_Key,Get_Key
EXTSYM SDD1Array, SDD1Entry
EXTSYM LastLog
EXTSYM fulladdtab
EXTSYM DecompArray,DecompAPtr
EXTSYM endprog
EXTSYM printhex
EXTSYM vesa2_rpos,vesa2_rfull,vesa2_rtrcl,vesa2_rtrcla
EXTSYM vesa2_gpos,vesa2_gfull,vesa2_gtrcl,vesa2_gtrcla
EXTSYM vesa2_bpos,vesa2_bfull,vesa2_btrcl,vesa2_btrcla
EXTSYM BRRBuffer,DSPMem,ResetState,PHdspsave,printnum,PHspcsave
EXTSYM ssdatst,timeron,timincr0,timincr1,timincr2,timinl0
EXTSYM timinl1,timinl2,vram
EXTSYM spcnumread
EXTSYM Curtableaddr,fnamest,procexecloop,stateloader,tableA
EXTSYM versn,vidmemch2
EXTSYM statesaver
EXTSYM memtablew8,printhex8,writeon,SetAddressingModesSA1
EXTSYM curcyc,dmadata,execsingle,initaddrl,memtabler8,pdh
EXTSYM regaccessbankr8,selcB800,snesmap2,snesmmap
EXTSYM ram7f
EXTSYM StringLength
EXTSYM exiter
EXTSYM SA1Status,CurrentCPU,SA1RegP
EXTSYM curypos,xa,xd,xdb,xe,xp,xpb,xpc,xs,xx,xy
EXTSYM SA1xpb,SA1xpc,SA1xa,SA1xx,SA1xy,SA1xd,SA1xdb,SA1xs
EXTSYM cycpbl,debugbuf,soundon,spcA,spcNZ,spcP,spcPCRam
EXTSYM spcRam,spcRamDP,spcS,spcX,spcY
EXTSYM CurPtrVal,SPC7110Enable

NEWSYM DebugAsmStart





; debstop at regsw.asm 2118/2119

NEWSYM SDD1Sort
    mov ecx,[SDD1Entry]
    cmp ecx,8
    jbe near .noSDD1
    sub ecx,8
.next2
    xor esi,esi
    xor ebx,ebx
.next
    xor eax,eax
    xor edx,edx
    mov al,[SDD1Array+ebx]
    shl eax,16
    mov ah,[SDD1Array+ebx+1]
    mov al,[SDD1Array+ebx+2]
    mov dl,[SDD1Array+ebx+8]
    shl edx,16
    mov dh,[SDD1Array+ebx+9]
    mov dl,[SDD1Array+ebx+10]
    cmp edx,eax
    ja .noswap
    mov eax,dword[SDD1Array+ebx]
    mov edx,dword[SDD1Array+ebx+8]
    mov dword[SDD1Array+ebx+8],eax
    mov dword[SDD1Array+ebx],edx
    mov eax,dword[SDD1Array+ebx+4]
    mov edx,dword[SDD1Array+ebx+12]
    mov dword[SDD1Array+ebx+12],eax
    mov dword[SDD1Array+ebx+4],edx
    mov esi,1
.noswap
    add ebx,8
    cmp ebx,ecx
    jne near .next
    or esi,esi
    jnz near .next2

    xor ebx,ebx
.next3
    mov al,[SDD1Array+ebx]
    mov ah,[SDD1Array+ebx+8]
    cmp al,ah
    jne .notequal
    mov ah,[SDD1Array+ebx+9]
    mov al,[SDD1Array+ebx+10]
    mov dh,[SDD1Array+ebx+1]
    mov dl,[SDD1Array+ebx+2]
    sub ax,dx
    mov [SDD1Array+ebx+5],ah
    mov [SDD1Array+ebx+6],al
.notequal
    add ebx,8
    cmp ebx,ecx
    jne near .next3
.noSDD1
    ret

NEWSYM startdebugger
    mov byte[curblank],40h
    mov byte[debuggeron],1
    mov ax,0003h
    int 10h

;    mov edx,.fname3+1
;    call Open_File
;    mov bx,ax
;    mov ecx,480h
;    mov edx,[romdata]
;    add edx,65536*13h
;    call Read_File
;    call Close_File

    mov byte[execut],0
    call startdisplay
    call debugloop
    call cleardisplay
    ; sort SDD1
;    jmp .noSDD1
    call SDD1Sort
.noSDD1

    pushad
    call LastLog
;    cmp dword[DecompAPtr],0
;    je near .nofile
    mov edx,.fname2+1
    call Create_File
    xor ecx,ecx
    mov bx,ax
    mov ecx,65536
    mov edx,[vram]
    EXTSYM oamram
    mov edx,oamram
    mov ecx,544
;    mov ecx,2048*4
;    mov edx,[C4Ram]
;    mov ecx,32768
;    mov edx,[romdata]
;    add edx,65536*13h
;    mov ecx,2EFh
;    mov edx,SDD1Array
;    mov ecx,[SDD1Entry]
;    mov edx,[romdata]
;    add edx,32768*40
;    mov edx,cnetplaybuf
;    mov ecx,512
;    mov edx,[sfxramdata]
;    add edx,65536
;    mov edx,fxtrace
;    mov ecx,65536
;    mov edx,[wramdata]
;    mov ecx,544
;    mov edx,oamram
;    mov ecx,256
;    mov edx,DSPFuncUsed

;    mov edx,fulladdtab
;    mov ecx,65536*2

;    mov ecx,17*4
;    mov edx,_ViewerZ
;    mov ecx,512
;    mov edx,cgram
;    mov ecx,256*4
;    mov edx,fxtrace
;NEWSYM DecompArray, times 65536 db 0
;NEWSYM DecompAPtr, dd 0
;    mov edx,DecompArray
;    mov ecx,[DecompAPtr]
;    shl ecx,3
;    mov edx,[romdata]
;    add edx,3E5CCEh
;    mov ecx,0022h
;    mov edx,[romdata]

;    add edx,1024*4096
;    mov ecx,65536

    or ecx,ecx
    jz .nofilecontents
    call Write_File
.nofilecontents
    call Close_File
.nofile
    popad

    cmp byte[execut],1
    je near start65816
;    mov al,[previdmode]
;    mov ah,0
;    int 10h
;    jmp DosExit

    jmp endprog
    jmp DosExit


    mov ax,3
    int 10h

    mov ax,[vesa2_rfull]
    call printhex
    mov ax,[vesa2_rtrcl]
    call printhex
    mov ax,[vesa2_gfull]
    call printhex
    mov ax,[vesa2_gtrcl]
    call printhex
    mov ax,[vesa2_bfull]
    call printhex
    mov ax,[vesa2_btrcl]
    call printhex

    jmp DosExit

.fname2 db 9,'vram.dat',0
.fname3 db 9,'vram2.dat',0

SECTION .data
; global variables
NEWSYM debugh,  dw 0            ; debug head
NEWSYM debugt,  dw 0            ; debug tail
NEWSYM debugv,  dw 0            ; debug view
NEWSYM debugds, db 0            ; debug disable (bit 0 = 65816, bit 1 = SPC)
NEWSYM numinst, dd 0            ; # of instructions
NEWSYM wx,      db 0
NEWSYM wy,      db 0
NEWSYM wx2,     db 0
NEWSYM wy2,     db 0
NEWSYM execut,  db 0
NEWSYM debuggeron, db 1
NEWSYM debstop, db 0
NEWSYM debstop2, db 0
NEWSYM debstop3, db 0
NEWSYM debstop4, db 0
SECTION .text

NEWSYM WriteSPC7110log
    cmp byte[SPC7110Enable],0
    je .nospc7110
    mov edx,SPC7110fn
    call Create_File
    mov bx,ax
    mov ecx,8
    mov edx,DecompAPtr
    call Write_File
    mov edx,CurPtrVal
    mov ecx,[DecompAPtr]
    shl ecx,3
    add ecx,27
    call Write_File
    call Close_File
.nospc7110
    ret
NEWSYM ReadSPC7110log
    cmp byte[SPC7110Enable],0
    je .nospc7110
    mov edx,SPC7110fn
    call Open_File
    jc .nospc7110
    mov bx,ax
    mov ecx,8
    mov edx,DecompAPtr
    call Read_File
    mov edx,CurPtrVal
    mov ecx,[DecompAPtr]
    shl ecx,3
    add ecx,27
    call Read_File
    call Close_File
.nospc7110
    ret
SPC7110fn db 'SPC7110.dat',0

NEWSYM loadtempstuff
    ; Load stuff
    mov edx,.spcfname
    call Open_File
    mov bx,ax
;    mov ecx,64
;    mov edx,ssdatst
;    call Read_File
    ; Load SPC stuff
    mov ecx,[PHspcsave]
    mov edx,spcRam
    call Read_File
    ; Load DSP stuff
    mov ecx,[PHdspsave]
    mov edx,BRRBuffer
    call Read_File
    mov ecx,256
    mov edx,DSPMem
    call Read_File
    call Close_File
    add dword[spcPCRam],spcRam
    add dword[spcRamDP],spcRam
    call ResetState
    ret
    mov dword[spcPCRam],0
    xor eax,eax
    mov ax,[ssdatst+37]
    mov [spcPCRam],ax
    call printnum
    mov al,[ssdatst+39]
    mov [spcA],al
    mov al,[ssdatst+40]
    mov [spcX],al
    mov al,[ssdatst+41]
    mov [spcY],al
    mov al,[ssdatst+42]
    mov [spcP],al
    mov al,[ssdatst+43]
    mov [spcS],al
    add dword[spcPCRam],spcRam
    ; Assemble N/Z flags into P
    mov byte[spcNZ],0
    test byte[spcP],02h
    jnz .zero
    mov byte[spcNZ],1
.zero
    test byte[spcP],80h
    jz .noneg
    or byte[spcNZ],80h
.noneg
    ; Init separate variables
    xor eax,eax
    mov al,[spcRam+0F1h]
    mov byte[timeron],al
    mov al,[spcRam+0FAh]
    mov [timincr0],al
    mov [timinl0],al
    mov al,[spcRam+0FBh]
    mov [timincr1],al
    mov [timinl1],al
    mov al,[spcRam+0FCh]
    mov [timincr2],al
    mov [timinl2],al
    ret

.spcfname db 'temp.spc',0

;*******************************************************
; Debug Loop
;*******************************************************

NEWSYM debugloop
NEWSYM debugloopa
    test byte[debugds],02h
    jnz .no65816
    call nextopcode
.no65816
    test byte[debugds],01h
    jnz .nospc
    call nextspcopcode
.nospc

NEWSYM debugloopb
    call showdd
.loopb
    mov byte[spcnumread],0
    ; wait for key
    mov ah,07h
    int 21h
    ; capitalize
    cmp al,'a'
    jb .nocap
    cmp al,'z'
    ja .nocap
    sub al,'a'-'A'
.nocap
    cmp al,0
    jne .loopc
    mov ah,07h
    int 21h
    cmp al,59
    je near .execute65816
    cmp al,62
    je near debugloadstate
    cmp al,60
    je near debugsavestate
    jmp .loopd
.loopc
    cmp al,27
    je .exit
    cmp al,13
    je near .loope
    cmp al,'-'
    je near .skipopcode
    cmp al,'C'
    je near .clear
    cmp al,'M'
    je near modify
    cmp al,'B'
    je near breakpoint
    cmp al,'R'
    je near repeatbreakpoint
    cmp al,'S'
    je near SPCbreakpoint
    cmp al,'A'
    je near SPCmodify
    cmp al,'T'
    je near trace
    cmp al,'D'
    je near debugdump
    cmp al,'W'
    je near breakatsign
    cmp al,'L'
    je near breakatsignlog
    cmp al,'1'
    je .disableSPC
    cmp al,'2'
    je .disable65816
.loopd
    jmp .loopb
.execute65816
   mov byte[execut],1
.exit
    ret

.disableSPC
    xor byte[debugds],01h
    jmp debugloopa

.disable65816
    xor byte[debugds],02h
    jmp debugloopa

.clear
;    call loadtempstuff
    mov dword[numinst],0
;    mov byte[DSPDet],0
;    mov esi,fxtrace
;    mov ecx,16384
;.n
;    mov dword[esi],0
;    add esi,4
;    dec ecx
;    jnz .n
    jmp debugloopa

.skipopcode
    xor eax,eax
    xor ebx,ebx
    xor ecx,ecx
    xor edx,edx
    mov bl,[xpb]
    mov ax,[xpc]
    test ax,8000h
    jz .loweraddrso
    mov esi,[snesmmap+ebx*4]
    jmp .skiplowerso
.loweraddrso
    cmp ax,4300h
    jb .lowerso
    cmp dword[memtabler8+ebx*4],regaccessbankr8
    je .dmaso
.lowerso
    mov esi,[snesmap2+ebx*4]
    jmp .skiplowerso
.dmaso
    mov esi,dmadata-4300h
.skiplowerso
    mov [initaddrl],esi
    add esi,eax                 ; add program counter to address
    ; 10,30,50,70,80,90,B0,D0,F0
    cmp byte[esi],10h
    je .okay
    cmp byte[esi],30h
    je .okay
    cmp byte[esi],50h
    je .okay
    cmp byte[esi],70h
    je .okay
    cmp byte[esi],80h
    je .okay
    cmp byte[esi],90h
    je .okay
    cmp byte[esi],0B0h
    je .okay
    cmp byte[esi],0D0h
    je .okay
    cmp byte[esi],0F0h
    je .okay
    jmp .notokay
.okay
    mov word[esi],0EAEAh
.notokay
    jmp debugloopa

.loope
    mov byte[skipdebugsa1],0
    call execnextop
    mov byte[skipdebugsa1],1
    cmp byte[soundon],0
    je .nosnd
    test byte[debugds],02h
    jz .nosnd
    cmp dword[cycpbl],55
    jnb .loope
.nosnd
    jmp debugloopa

;*******************************************************
; Debug dump
;*******************************************************

NEWSYM debugdump
    ; Dump SPCRam
    mov edx,.fname
    call Create_File
    mov bx,ax
    mov ecx,65536
    mov edx,spcRam
    call Write_File
    call Close_File
    mov edx,.fname2
    call Create_File
    mov bx,ax
    mov ecx,256
    mov edx,DSPMem
    call Write_File
    call Close_File
    jmp debugloopb
.fname db 'SPCRAM.DMP',0
.fname2 db 'DSP.DMP',0

;*******************************************************
; Debug save/load states
;*******************************************************
NEWSYM debugloadstate
    ; Load State
    mov edx,fnamest+1
    call Open_File
    jc near .nofile
    call stateloader
    ; Clear Cache Check
    mov esi,vidmemch2
    mov ecx,4096+4096+4096
.next
    mov byte[esi],1
    inc esi
    dec ecx
    jnz .next
    cmp byte[versn],60
    jne near .convert
    jmp .noconvert
.convert
    mov byte[versn],60
    mov byte[versn-2],'6'
.noconvert
    add dword[Curtableaddr],tableA
    add dword[spcPCRam],spcRam
    add dword[spcRamDP],spcRam
    call ResetState
    call procexecloop
.nofile
    jmp debugloopa

NEWSYM debugsavestate
    call statesaver
    jmp debugloopb

;*******************************************************
; DrawWindow          Draws a Window using WX,WY,WX2,WY2
;*******************************************************

NEWSYM drawwindow
    push es
    mov ax,[selcB800]
    mov es,ax
    xor eax,eax
    xor ebx,ebx
    xor edi,edi
    mov al,[wy]
    mov bl,160
    mul bx
    mov edi,eax
    xor eax,eax
    mov al,[wx]
    shl al,1
    add edi,eax
    mov ah,[wx2]
    shl ah,1
    sub ah,al
    mov dl,ah
    mov al,160
    sub al,dl
    mov dh,al
    mov bl,[wy]
    shr dl,1
.loopa
    mov ah,31
    xor ecx,ecx
    mov cl,dl
    ; check if first, middle or last line
    cmp bl,[wy]
    je .first
    cmp bl,[wy2]
    je .last
    ; middle
    mov al,'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -