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

📄 memory.asm

📁 linux下的任天堂模拟器代码。供大家参考。
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach );;http://www.zsnes.com;http://sourceforge.net/projects/zsnes;https://zsnes.bountysource.com;;This program is free software; you can redistribute it and/or;modify it under the terms of the GNU General Public License;version 2 as published by the Free Software Foundation.;;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 romdata,sramb4save,curromspace,SA1OverflowEXTSYM SFXEnable,regptra,sfxramdata,snesmmap,wramdataaEXTSYM DSP1Write8b,regptwa,writeon,DSP1Read16bEXTSYM Bank0datr8,Bank0datw8,Bank0datr16,Bank0datw16,xd,SA1xdEXTSYM DSP1Read8b,DSP1Type,SA1Enable,DSP1Write16bEXTSYM ramsize,ramsizeand,sram,sram2,ram7faEXTSYM SA1Status,IRAM,CurBWPtr,SA1RAMAreaEXTSYM Sdd1Mode,Sdd1Bank,Sdd1Addr,Sdd1NewAddr,memtabler8,AddrNoIncr,SDD1BankAEXTSYM SDD1_init,SDD1_get_byte,BWShift,SA1BWPtr;*******************************************************; Register & Memory Access Banks (0 - 3F) / (80 - BF);*******************************************************; enter : BL = bank number, CX = address location; leave : AL = value readSECTION .textNEWSYM regaccessbankr8    test ecx,8000h    jz .regacc    mov ebx,[snesmmap+ebx*4]    mov al,[ebx+ecx]    xor ebx,ebx    ret.regacc    cmp ecx,2000h    jae .regs    mov al,[wramdataa+ecx]    ret.regs    cmp ecx,48FFh    ja .invaccess    call dword near [regptra+ecx*4-8000h]    xor ebx,ebx    ret.invaccess    cmp ecx,6000h    jae .hiromsram    mov al,ch    ret.hiromsram    cmp byte[SFXEnable],1    je .sfxram    and ebx,7Fh    cmp bl,10h    jb .dsp1    cmp bl,30h    jae .hiromsramok    xor al,al    xor ebx,ebx    ret.dsp1    xor al,al    cmp byte[DSP1Type],2    jne .nodsp1    call DSP1Read8b.nodsp1    xor ebx,ebx    ret.hiromsramok    push ecx    sub ecx,6000h    and ecx,1fffh    sub bl,30h    shl ebx,13    add ecx,ebx    and ecx,0FFFFh    call sramaccessbankr8b    pop ecx    ret.sfxram    push ecx    sub ecx,6000h    and ecx,1fffh    mov ebx,[sfxramdata]    mov al,[ebx+ecx]    xor ebx,ebx    pop ecx    retNEWSYM regaccessbankr16    test ecx,8000h    jz .regacc    mov ebx,[snesmmap+ebx*4]    mov ax,[ebx+ecx]    xor ebx,ebx    ret.regacc    cmp ecx,2000h    jae .regs    mov ax,[wramdataa+ecx]    cmp ecx,1FFFh    jne .notopenbus    mov ah,al.notopenbus    ret.regs    cmp ecx,48FFh    ja .invaccess;    mov ebx,ecx;    shl ebx,2;    add ebx,[regptr];    call dword near [ebx]    call dword near [regptra+ecx*4-8000h]    inc ecx    mov ah,al;    mov ebx,ecx;    shl ebx,2;    add ebx,[regptr];    call dword near [ebx]    call dword near [regptra+ecx*4-8000h]    mov bl,al    dec ecx    mov al,ah    mov ah,bl    xor ebx,ebx    ret.invaccess;    jmp regexiter    cmp ecx,6000h    jae .hiromsram    mov al,ch    mov ah,ch    ret.hiromsram    cmp byte[SFXEnable],1    je .sfxram    and ebx,7Fh    cmp bl,10h    jb .dsp1    cmp bl,30h    jae .hiromsramok    xor ax,ax    xor ebx,ebx    ret.dsp1    xor ax,ax    cmp byte[DSP1Type],2    jne .nodsp1    call DSP1Read16b.nodsp1    xor ebx,ebx    ret.hiromsramok    push ecx    sub ecx,6000h    and ecx,1fffh    sub bl,30h    shl ebx,13    add ecx,ebx    and ecx,0FFFFh    call sramaccessbankr16b    pop ecx    ret.sfxram    push ecx    sub ecx,6000h    and ecx,1fffh    mov ebx,[sfxramdata]    mov ax,[ebx+ecx]    xor ebx,ebx    pop ecx    retNEWSYM regaccessbankw8    test ecx,8000h    jnz .romacc    cmp ecx,2000h    jae .regs    mov [wramdataa+ecx],al    ret.romacc    cmp byte[writeon],0    jne .modrom    ret.modrom    mov ebx,[snesmmap+ebx*4]    mov [ebx+ecx],al    xor ebx,ebx    ret.regs    cmp ecx,48FFh    ja .invaccess;    mov ebx,ecx;    shl ebx,2;    add ebx,[regptw];    call dword near [ebx]    call dword near [regptwa+ecx*4-8000h]    xor ebx,ebx    ret.invaccess;    jmp regexiter    cmp ecx,6000h    jae .hiromsram    ret.hiromsram    cmp byte[SFXEnable],1    je .sfxram    and ebx,7Fh    cmp bl,10h    jb .dsp1    cmp bl,30h    jae .hiromsramok    xor ebx,ebx    ret.dsp1    cmp byte[DSP1Type],2    jne .nodsp1    call DSP1Write8b.nodsp1    xor ebx,ebx    ret.hiromsramok    push ecx    sub ecx,6000h    and ecx,1fffh    sub bl,30h    shl ebx,13    add ecx,ebx    and ecx,0FFFFh    call sramaccessbankw8b    pop ecx    ret.sfxram    push ecx    sub ecx,6000h    and ecx,1fffh    mov ebx,[sfxramdata]    mov [ebx+ecx],al    xor ebx,ebx    pop ecx    retNEWSYM regaccessbankw16    test ecx,8000h    jnz .romacc    cmp ecx,2000h    jae .regs    cmp ecx,1FFFh    je .endwram    mov [wramdataa+ecx],ax    ret.endwram    mov [wramdataa+ecx],al    ret.romacc    cmp byte[writeon],0    jne .modrom    ret.modrom    mov ebx,[snesmmap+ebx*4]    mov [ebx+ecx],ax    xor ebx,ebx    ret.regs    cmp cx,48FFh    ja .invaccess;    mov ebx,ecx;    shl ebx,2;    add ebx,[regptw];    call dword near [ebx]    call dword near [regptwa+ecx*4-8000h]    inc ecx    mov al,ah;    mov ebx,ecx;    shl ebx,2;    add ebx,[regptw];    call dword near [ebx]    call dword near [regptwa+ecx*4-8000h]    dec ecx    xor ebx,ebx    ret.invaccess;    jmp regexiter    cmp ecx,6000h    jae .hiromsram    ret.hiromsram    cmp byte[SFXEnable],1    je .sfxram    and ebx,7Fh    cmp bl,10h    jb .dsp1    cmp bl,30h    jae .hiromsramok    xor al,al    xor ebx,ebx    ret.dsp1    cmp byte[DSP1Type],2    jne .nodsp1    call DSP1Write16b.nodsp1    ret.hiromsramok    push ecx    sub ecx,6000h    and ecx,1fffh    sub bl,30h    shl ebx,13    add ecx,ebx    and ecx,0FFFFh    call sramaccessbankw16b    pop ecx    ret.sfxram    push ecx    sub ecx,6000h    and ecx,1fffh    mov ebx,[sfxramdata]    mov [ebx+ecx],ax    xor ebx,ebx    pop ecx    retNEWSYM regaccessbankr8mp    ret;*******************************************************; Register & Memory Bank (Bank 0);*******************************************************; enter : BL = bank number, CX = address location; leave : AL = value read%macro BWCheck 0    cmp byte[BWShift],0    jne near .shift.nosa1%endmacrosection .bssNEWSYM BWUsed2, resb 1NEWSYM BWUsed, resb 1section .text%macro BWCheck2r8 0.shift    cmp byte[SA1Status],0    je .nosa1    ; value of 8Fh    test byte[SA1Overflow+1],80h    jnz .2bit    push ecx    push ebx    sub ecx,6000h    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov al,0Fh    shl al,cl    add ebx,[SA1BWPtr]    and al,[ebx]    shr al,cl    pop ebx    pop ecx    ret.2bit    push ecx    push ebx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov al,03h    shl al,cl    add ebx,[SA1BWPtr]    and al,[ebx]    shr al,cl    pop ebx    pop ecx    ret%endmacro%macro BWCheck2r16 0.shift    cmp byte[SA1Status],0    je .nosa1    ; value of 8Fh    test byte[SA1Overflow+1],80h    jnz .2bit    push ecx    push ebx    sub ecx,6000h    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov al,0Fh    shl al,cl    add ebx,[SA1BWPtr]    and al,[ebx]    shr al,cl    pop ebx    pop ecx    push ecx    push ebx    sub ecx,6000h    inc ecx    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov ah,0Fh    shl ah,cl    add ebx,[SA1BWPtr]    and ah,[ebx]    shr ah,cl    pop ebx    pop ecx    ret.2bit    push ecx    push ebx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov al,03h    shl al,cl    add ebx,[SA1BWPtr]    and al,[ebx]    shr al,cl    pop ebx    pop ecx    push ecx    push ebx    inc ecx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov ah,03h    shl ah,cl    add ebx,[SA1BWPtr]    and ah,[ebx]    shr ah,cl    pop ebx    pop ecx    ret%endmacro%macro BWCheck2w8 0.shift    cmp byte[SA1Status],0    je .nosa1    test byte[SA1Overflow+1],80h    jnz .2bit    push ecx    push ebx    push edx    sub ecx,6000h    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov dh,0Fh    shl dh,cl    xor dh,0FFh    and al,0Fh    shl al,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],al    pop edx    pop ebx    pop ecx    ret.2bit    push ecx    push ebx    push edx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov dh,03h    shl dh,cl    xor dh,0FFh    and al,03h    shl al,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],al    pop edx    pop ebx    pop ecx    ret%endmacro%macro BWCheck2w16 0.shift    cmp byte[SA1Status],0    je .nosa1    test byte[SA1Overflow+1],80h    jnz .2bit    push eax    push ecx    push ebx    push edx    sub ecx,6000h    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov dh,0Fh    shl dh,cl    xor dh,0FFh    and al,0Fh    shl al,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],al    pop edx    pop ebx    pop ecx    pop eax    push ecx    push ebx    push edx    inc ecx    sub ecx,6000h    push eax    mov eax,ecx    and eax,01h    shl eax,2    shr ecx,1    mov ebx,ecx    mov cl,al    pop eax    mov dh,0Fh    shl dh,cl    xor dh,0FFh    and ah,0Fh    shl ah,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],ah    pop edx    pop ebx    pop ecx    ret.2bit    push eax    push ecx    push ebx    push edx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov dh,03h    shl dh,cl    xor dh,0FFh    and al,03h    shl al,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],al    pop edx    pop ebx    pop ecx    pop eax    push ecx    push ebx    push edx    inc ecx    sub ecx,6000h    push eax    mov eax,ecx    and eax,03h    shl eax,1    shr ecx,2    mov ebx,ecx    mov cl,al    pop eax    mov dh,03h    shl dh,cl    xor dh,0FFh    and ah,03h    shl ah,cl    add ebx,[SA1BWPtr]    and byte[ebx],dh    or byte[ebx],ah    pop edx    pop ebx    pop ecx    ret%endmacro%macro writetobank0table 2    mov ebx,%1    mov ecx,%2%%loop    mov [eax],ebx    add eax,4    dec ecx    jnz %%loop%endmacrosection .bssNEWSYM DPageR8, resd 1NEWSYM DPageR16, resd 1NEWSYM DPageW8, resd 1NEWSYM DPageW16, resd 1NEWSYM SA1DPageR8, resd 1NEWSYM SA1DPageR16, resd 1NEWSYM SA1DPageW8, resd 1NEWSYM SA1DPageW16, resd 1section .textNEWSYM UpdateDPage    push eax    movzx eax,byte[xd+1]    push ecx    mov ecx,[Bank0datr8+eax*4]    mov [DPageR8],ecx    mov ecx,[Bank0datr16+eax*4]    mov [DPageR16],ecx    mov ecx,[Bank0datw8+eax*4]    mov [DPageW8],ecx    mov ecx,[Bank0datw16+eax*4]    mov [DPageW16],ecx    pop ecx    pop eax    retNEWSYM SA1UpdateDPage    push eax    movzx eax,byte[SA1xd+1]    push ecx    mov ecx,[Bank0datr8+eax*4]    mov [SA1DPageR8],ecx    mov ecx,[Bank0datr16+eax*4]    mov [SA1DPageR16],ecx    mov ecx,[Bank0datw8+eax*4]    mov [SA1DPageW8],ecx    mov ecx,[Bank0datw16+eax*4]    mov [SA1DPageW16],ecx    pop ecx    pop eax    ret; SA1 StuffNEWSYM membank0r8ramSA1             ; 0000-1FFF    cmp byte[SA1Status],0    jne .nowram    mov al,[wramdataa+ecx+ebx]    ret.nowram    cmp ecx,800h    jae .invaccess    mov al,[IRAM+ecx+ebx]    ret.invaccess    xor al,al    retNEWSYM membank0r16ramSA1             ; 0000-1FFF    cmp byte[SA1Status],0    jne .nowram    mov ax,[wramdataa+ecx+ebx]    ret.nowram    cmp ecx,800h    jae .invaccess    mov ax,[IRAM+ecx+ebx]    ret.invaccess    xor ax,ax    retNEWSYM membank0w8ramSA1             ; 0000-1FFF    cmp byte[SA1Status],0    jne .nowram    mov [wramdataa+ecx+ebx],al    ret.nowram    cmp ecx,800h    jae .invaccess    mov [IRAM+ecx+ebx],al.invaccess    retNEWSYM membank0w16ramSA1             ; 0000-1FFF    cmp byte[SA1Status],0    jne .nowram    mov [wramdataa+ecx+ebx],ax    ret.nowram    cmp ecx,800h    jae .invaccess    mov [IRAM+ecx+ebx],ax.invaccess

⌨️ 快捷键说明

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