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

📄 guicheat.inc

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 INC
📖 第 1 页 / 共 2 页
字号:
;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.







; GUI Cheat Code Routines

AddCSCheatCode:
    cmp byte[CSInputDisplay],'_'
    je .nodisplay
    jmp .okay
.nodisplay
    ret
.okay
    mov eax,[curentryval]
    mov [curaddrvalcs],eax
    mov eax,[CSCurValue]
    mov [curvaluecs],eax
    xor ecx,ecx
    mov cl,[CheatSrcByteSize]
    inc cl
    cmp byte[CheatUpperByteOnly],0
    je .cspardisploop
    mov cl,1
.cspardispagain
    cmp dword[curvaluecs],0FFh
    jbe .cspardisploop
    shr dword[curvaluecs],8
    inc dword[curaddrvalcs]
    jmp .cspardispagain
.cspardisploop
    push ecx
    mov esi,GUICSrcTextQ
    mov ecx,3
    mov eax,[curaddrvalcs]
    add eax,7E0000h
    mov bl,[curvaluecs]
    ; write bl at address eax
    call AddCheatCode

    shr dword[curvaluecs],8
    mov byte[GUItextcolor],223

    add dword[CheatSearchYPos],10
    inc dword[curaddrvalcs]
    pop ecx
    dec ecx
    jnz near .cspardisploop
    mov byte[CheatWinMode],2
    ret

%macro SearchCMPByte 0
    mov bl,[edi]
    cmp bl,[esi]
%endmacro

%macro SearchCMP2Bytes 0
    mov bx,[edi]
    cmp bx,[esi]
%endmacro

%macro SearchCMP3Bytes 0
    push ecx
    mov ebx,[edi]
    mov ecx,[esi]
    and ebx,0FFFFFFh
    and ecx,0FFFFFFh
    cmp ebx,ecx
    pop ecx
%endmacro

%macro SearchCMP4Bytes 0
    mov ebx,[edi]
    cmp ebx,[esi]
%endmacro

%macro SearchMacro 2
    mov dl,0FEh
%%searchloop
    %2
    %1 %%nofail
    and [eax],dl
%%nofail
    inc edi
    inc esi
    cmp dl,7Fh
    jne %%noinceax
    inc eax
%%noinceax
    rol dl,1
    loop %%searchloop
%endmacro

%macro SearchMacroB 1
    cmp byte[CheatCompareValue],0
    je near %%greater
    cmp byte[CheatCompareValue],1
    je near %%lessthan
    cmp byte[CheatCompareValue],3
    je near %%notequalthan
    SearchMacro je, %1
    jmp .end
%%greater
    SearchMacro ja, %1
    jmp .end
%%lessthan
    SearchMacro jb, %1
    jmp .end
%%notequalthan
    SearchMacro jne, %1
    jmp .end
%endmacro

CheatCodeSearchProcess:
    cmp byte[CheatSrcSearchType],1
    je near .comparative
    cmp byte[CSInputDisplay],0
    je near .nodisplay
    cmp byte[CSInputDisplay],'_'
    je near .nodisplay
    cmp byte[CSOverValue],1
    je near .nodisplay
    mov byte[CSInputDisplay],'_'
    mov byte[CSInputDisplay+1],0
    ; Process Cheat Search
    mov ecx,65536*2
    xor ebx,ebx
    mov bl,byte[CheatSrcByteSize]
    sub ecx,ebx
    mov edx,[SrcMask+ebx*4]
    mov edi,dword[vidbuffer]
    add edi,129600+65536*2
    mov esi,[wramdata]
    mov bl,0FEh
    mov bh,01h
.exactloop
    mov eax,[esi]
    and eax,edx
    cmp eax,[CSCurValue]
    je .found
    inc eax
    and eax,edx
    cmp eax,[CSCurValue]
    je .foundb
.failedfind
    and [edi],bl
    jmp .foundc
.found
    test byte[edi+16384],bh
    jz .failedfind
    jmp .foundc
.foundb
    cmp byte[FirstSearch],1
    je .clear
    test byte[edi+16384],bh
    jnz .failedfind
    jmp .foundc
.clear
    and byte[edi+16384],bl
.foundc
    cmp bl,7Fh
    jne .noincedi
    inc edi
.noincedi
    rol bl,1
    rol bh,1
    inc esi
    loop .exactloop
; CSCurValue  dd 0
    mov byte[CopyRamToggle],1
    mov byte[CheatSearchStatus],1
.nodisplay
    ret
.comparative
    mov byte[CSInputDisplay],'_'
    mov byte[CSInputDisplay+1],0
    mov byte[CheatSearchStatus],1
    mov eax,dword[vidbuffer]
    add eax,129600+65536*2
    mov esi,dword[vidbuffer]
    add esi,129600
    mov edi,[wramdata]
    mov ecx,65536*2
    cmp byte[CheatSrcByteSize],1
    je near .bytesize2
    cmp byte[CheatSrcByteSize],2
    je near .bytesize3
    cmp byte[CheatSrcByteSize],3
    je near .bytesize4
    SearchMacroB SearchCMPByte
.bytesize2
    dec ecx
    SearchMacroB SearchCMP2Bytes
.bytesize3
    sub ecx,2
    SearchMacroB SearchCMP3Bytes
.bytesize4
    sub ecx,3
    SearchMacroB SearchCMP4Bytes
.end
    mov byte[CopyRamToggle],1
    ret

CopyRamToggle db 0
FirstSearch   db 0

CheatCodeSearchInit:
    mov byte[CSInputDisplay],'_'
    mov byte[CSInputDisplay+1],0
    mov byte[CheatWinMode],1
    mov byte[CheatSearchStatus],0
    cmp byte[CopyRamToggle],0
    mov byte[FirstSearch],1
    mov eax,dword[vidbuffer]
    add eax,129600
    ; copy 128k ram
    mov ebx,[wramdata]
    mov ecx,32768
.loop
    mov edx,[ebx]
    mov [eax],edx
    add ebx,4
    add eax,4
    loop .loop
    ; fill searched buffer with 0xFF
    mov eax,dword[vidbuffer]
    add eax,129600+65536*2
    mov ecx,8192
.loop2
    mov dword[eax],0FFFFFFFFh
    add eax,4
    loop .loop2
    cmp byte[CheatSrcSearchType],1
    jne .nottype1
    mov byte[CheatSearchStatus],1
.nottype1
    mov dword[CheatCompareValue],0
    mov eax,dword[vidbuffer]
    add eax,129600+65536*2
    cmp byte[CheatSrcByteSize],1
    je near .bytesize2
    cmp byte[CheatSrcByteSize],2
    je near .bytesize3
    cmp byte[CheatSrcByteSize],3
    je near .bytesize4
    ret
.bytesize2
    and byte[eax+16383],07Fh
    ret
.bytesize3
    and byte[eax+16383],03Fh
    ret
.bytesize4
    and byte[eax+16383],01Fh
    ret

CheatCodeSave:
    cmp byte[NumCheats],0
    jne .okay
    mov byte[GUICBHold],0
    ret
.okay
    mov byte[cheatdata+6],254
    mov byte[cheatdata+7],252

    call SRAMDirc
    mov byte[GUICBHold],0
    mov ebx,[statefileloc]
    sub ebx,2
    mov eax,[fnamest+ebx]
    mov dword[fnamest+ebx],'CHT'
    push eax
    push ebx
    mov edx,fnamest+1
    call Create_File
    jc .cheatsavefail
    mov bx,ax
    mov ecx,[NumCheats]
    mov edx,ecx
    shl ecx,4
    shl edx,2
    add ecx,edx
    add ecx,edx
    add ecx,edx
    mov edx,cheatdata
    call Write_File
    call Close_File
.cheatsavefail
    pop ebx
    pop eax
    mov [fnamest+ebx],eax
    call LOADDir
    ret

CheatCodeLoad:
    call SRAMDirc
    mov byte[GUICBHold],0
    mov ebx,[statefileloc]
    sub ebx,2
    mov eax,[fnamest+ebx]
    mov dword[fnamest+ebx],'CHT'
    push eax
    push ebx
    mov edx,fnamest+1
    call Open_File
    jc near .fail
    mov bx,ax
    ; Disable all codes
    push ebx
    mov esi,cheatdata
    mov ecx,[NumCheats]
    cmp ecx,0
    je .skip
.loop2
    test byte[esi],4
    jnz .disabled2
    push esi
    push ecx
    call DisableCheatCode
    pop ecx
    pop esi
.disabled2
    add esi,28
    dec ecx
    jnz .loop2
.skip
    pop ebx
    mov ecx,255*28
    mov edx,cheatdata
    call Read_File
    push eax
    call Close_File
    pop eax
    cmp byte[cheatdata+6],254
    jne .notnewformat
    cmp byte[cheatdata+7],252
    jne .notnewformat
    jmp .newformat
.notnewformat
    ; Convert format
    mov esi,cheatdata
    mov ebx,18
    push eax
    xor edx,edx
    div ebx
    push edx
    mov [NumCheats],eax
    mov ebx,28
    mul ebx
    mov ecx,eax
    pop edx
    pop eax
    sub eax,edx
.convloop
    sub ecx,28
    sub eax,18
    mov ebx,6
.convloopb
    mov dl,[cheatdata+eax+ebx-1]
    mov [cheatdata+ecx+ebx-1],dl
    dec ebx
    jnz .convloopb
    mov ebx,12
.convloopd
    mov dl,[cheatdata+eax+ebx+5]
    mov [cheatdata+ecx+ebx+7],dl
    dec ebx
    jnz .convloopd
    mov ebx,8
.convloopc
    mov byte[cheatdata+ecx+ebx+19],0
    dec ebx
    jnz .convloopc
    or ecx,ecx
    jnz .convloop
    jmp .fin
.newformat
    mov ebx,28
    xor edx,edx
    div ebx
    mov [NumCheats],eax
.fin
    pop ebx
    pop eax
    mov [fnamest+ebx],eax
    ; Enable all ON toggled cheat codes
    mov esi,cheatdata
    mov ecx,[NumCheats]
    cmp ecx,0
    je .skip2
.loop
    test byte[esi],4
    jnz .disabled
    push esi
    push ecx
    call EnableCheatCode
    pop ecx
    pop esi
.disabled
    add esi,28
    dec ecx
    jnz .loop
.skip2
    mov eax,[NumCheats]
    cmp eax,[GUIcurrentcheatcursloc]
    ja .noconf
    dec eax
    mov dword[GUIcurrentcheatcursloc],eax
.noconf
    cmp dword[NumCheats],0
    jne .nozero
    mov dword[GUIcurrentcheatcursloc],0
    mov byte[CheatOn],0
    call LOADDir
    ret
.nozero
    mov byte[CheatOn],1
    call LOADDir
    ret
.fail
    pop ebx
    pop eax
    mov [fnamest+ebx],eax
    call LOADDir
    ret

CheatCodeRemove:
    cmp dword[NumCheats],0
    jne .nonone
    mov byte[GUICBHold],0
    ret
.nonone
    mov byte[GUICBHold],0
    mov esi,[GUIcurrentcheatcursloc]
    shl esi,5
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    add esi,cheatdata
    push esi
    call DisableCheatCode
    pop esi
    mov eax,255
    sub eax,[GUIcurrentcheatcursloc]
    mov ebx,eax
    shl eax,4
    add eax,ebx
    add eax,ebx
.loop
    mov bl,[esi+28]
    mov [esi],bl
    inc esi
    dec eax
    jnz .loop
    dec dword[NumCheats]
    mov eax,[GUIcurrentcheatcursloc]
    cmp dword[NumCheats],0
    je .okay
    cmp eax,[NumCheats]
    jne .okay
    dec dword[GUIcurrentcheatcursloc]
.okay
    cmp byte[NumCheats],0
    jne .cheatexists
    mov byte[CheatOn],0
.cheatexists
    ret

CheatCodeFix:
    cmp dword[NumCheats],0
    jne .nonone
    mov byte[GUICBHold],0
    ret
.nonone
    mov byte[GUICBHold],0
    call DisableCheatCode
    mov esi,[GUIcurrentcheatcursloc]
    shl esi,5
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    add esi,cheatdata
    xor byte[esi+3],80h
    call EnableCheatCodeNoPrevMod
    ret

CheatCodeToggle:
    cmp dword[NumCheats],0
    jne .nonone
    mov byte[GUICBHold],0
    ret
.nonone
    mov byte[GUICBHold],0
    mov esi,[GUIcurrentcheatcursloc]
    shl esi,5
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    sub esi,[GUIcurrentcheatcursloc]
    add esi,cheatdata
    test byte[esi],4
    jz DisableCheatCode
    jmp EnableCheatCodeNoPrevMod

DisableCheatCode:
    ; code is at esi
    xor ecx,ecx
    xor ebx,ebx
    or byte[esi],4
    test byte[esi],1
    jnz .gfrom
    mov al,[esi+5]
    mov cx,[esi+2]
    mov bl,[esi+4]
    mov byte[writeon],1
    test byte[esi],80h
    jnz .nowrite
    test byte[esi-28],80h
    jnz .nowrite
    call dword near [memtablew8+ebx*4]
.nowrite
    mov byte[writeon],0
    ret
.gfrom
    mov al,[esi+5]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[romdata]
    mov [esi+ecx],al
    ret
.gfram
    mov al,[esi+5]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[sram]
    mov [esi+ecx],al
    ret

EnableCheatCode:
    ; code is at esi
    xor ecx,ecx
    xor ebx,ebx
    and byte[esi],0FBh
    test byte[esi],1
    jnz .gfrom
    mov al,[esi+1]
    mov cx,[esi+2]
    mov bl,[esi+4]
    push ecx
    push eax
    push ebx
    push edx
    call dword near [memtabler8+ebx*4]
    pop edx
    mov byte[esi+5],al
    pop ebx
    pop eax
    pop ecx
    mov byte[writeon],1
    test byte[esi],80h
    jnz .nowrite
    test byte[esi-28],80h
    jnz .nowrite
    call dword near [memtablew8+ebx*4]
.nowrite
    mov byte[writeon],0
    ret
.gfrom
    mov al,[esi+1]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[romdata]
    mov bl,[esi+ecx]
    mov [esi+ecx],al
    mov [esi+5],bl
    ret
.gfram
    mov al,[esi+1]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[sram]
    mov bl,[esi+ecx]
    mov [esi+ecx],al
    mov [esi+5],bl
    ret

EnableCheatCodeNoPrevMod:
    ; code is at esi
    xor ecx,ecx
    xor ebx,ebx
    and byte[esi],0FBh
    test byte[esi],1
    jnz .gfrom
    mov al,[esi+1]
    mov cx,[esi+2]
    mov bl,[esi+4]
    mov byte[writeon],1
    test byte[esi],80h
    jnz .nowrite
    test byte[esi-28],80h
    jnz .nowrite
    call dword near [memtablew8+ebx*4]
.nowrite
    mov byte[writeon],0
    ret
.gfrom
    mov al,[esi+1]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[romdata]
    mov bl,[esi+ecx]
    mov [esi+ecx],al
    mov [esi+5],bl
    ret
.gfram
    mov al,[esi+1]
    mov ecx,[esi+2]
    and ecx,0FFFFFFh
    mov esi,[sram]
    mov bl,[esi+ecx]
    mov [esi+ecx],al
    mov [esi+5],bl
    ret

AddCheatCode:
    mov byte[GUICBHold],0
    cmp dword[NumCheats],255
    jne .okay
    ret
.okay
    push eax
    push ebx
    ; transfer description
    mov eax,[NumCheats]
    shl eax,5
    sub eax,[NumCheats]
    sub eax,[NumCheats]
    sub eax,[NumCheats]
    sub eax,[NumCheats]
    add eax,cheatdata
    mov edx,eax
    push edx
    add eax,6
    mov ebx,CSDescDisplay
    mov ecx,20
.dloop
    mov dl,[ebx]
    mov [eax+2],dl
    mov [eax+18+2],dl
    mov [eax+18*2+2],dl

⌨️ 快捷键说明

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