From 0e5094b120d0a75ff47341639dd4ba586d870f0e Mon Sep 17 00:00:00 2001 From: grinvader <> Date: Sat, 5 Nov 2005 18:49:07 +0000 Subject: [PATCH] Cleanup (whitespace & useless EXTSYM). --- zsnes/src/cpu/dma.asm | 2831 ++++++++++++------------ zsnes/src/cpu/execute.asm | 4410 ++++++++++++++++++------------------- zsnes/src/cpu/regs.inc | 2496 ++++++++++----------- zsnes/src/cpu/regsw.inc | 3494 ++++++++++++++--------------- 4 files changed, 6615 insertions(+), 6616 deletions(-) diff --git a/zsnes/src/cpu/dma.asm b/zsnes/src/cpu/dma.asm index c3650f18..c5a8ab9d 100644 --- a/zsnes/src/cpu/dma.asm +++ b/zsnes/src/cpu/dma.asm @@ -1,1416 +1,1415 @@ -;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) -; -;http://www.zsnes.com -;http://sourceforge.net/projects/zsnes -; -;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 memtabler8,regptw,snesmap2,snesmmap,memtablew8,regptr,memtabler16 -EXTSYM dmadata,hdmatype,nexthdma,resolutn -EXTSYM curhdma,curypos,disablehdma,hdmadata,hdmadelay,hdmastartsc,hdmarestart -EXTSYM nohdmaframe - -;******************************************************* -; Transfer DMA Inits & Transfers DMA -;******************************************************* -; DMA transfer register - -section .bss -NEWSYM AddrNoIncr, resb 1 -section .text - -%macro ExecSPCCycles 0 - xor ebx,ebx - mov bx,[esi+5] - inc bx - inc ebx - shr ebx,2 - mov [soundcycleft],ebx - or ebx,ebx - jz .nocycles - xor ebx,ebx - xor ecx,ecx - call pexecs2 -.nocycles -%endmacro - -NEWSYM transdma - push eax - cmp word[esi+5],480h - jne .no -; mov byte[debstop3],1 -.no -; ExecSPCCycles - - mov al,[esi] - test al,80h - jnz near transdmappu2cpu - - ; set address increment value - mov dword[.addrincr],0 - test al,00001000b - jnz .skipaddrincr - test al,00010000b - jnz .autodec - mov dword[.addrincr],1 - jmp .skipaddrincr -.autodec - mov dword[.addrincr],0FFFFFFFFh -.skipaddrincr - - mov byte[AddrNoIncr],0 - cmp dword[.addrincr],0 - jne .notzero - mov byte[AddrNoIncr],1 -.notzero - ; get address order to be written - xor ebx,ebx - and al,00000111b - cmp al,5 - jne .notmode5dma - sub al,4 -.notmode5dma - mov bl,al - shl bl,3 - add ebx,.addrwrite - mov edi,ebx - - ; get pointer #1 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi] - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [.regptra],eax - - ; get pointer #2 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+2] - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [.regptrb],eax - - ; get pointer #3 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+4] - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [.regptrc],eax - - ; get pointer #4 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+6] - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [.regptrd],eax - - mov dx,[esi+5] ; Number of bytes to transfer - xor ebx,ebx - mov bl,[esi+4] ; Bank # - mov ecx,[esi+2] ; address offset # - and ecx,0FFFFh - mov [.curbank],bl - mov word[esi+5],0 - - mov ebx,[.curbank] - mov eax,snesmap2 - test ecx,8000h - jz .nomap1 - mov eax,snesmmap -.nomap1 - and edx,0FFFFh - mov ebx,[eax+ebx*4] - - push esi - mov esi,ebx - xor ebx,ebx - mov bl,[.curbank] - ; do loop - cmp edx,0 - jne .no0 - mov edx,65536 -.no0 - mov ebx,[memtabler8+ebx*4] - mov [.readaddr],ebx - xor ebx,ebx - mov bl,[.curbank] - mov [.cebx],ebx -.againloop - cmp edx,4 - jbe .deccheckloop - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptra] - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrb] - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrc] - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrd] - sub edx,4 - jmp .againloop -.deccheckloop - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptra] - dec edx - jz .findma - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrb] - dec edx - jz .findma - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrc] - dec edx - jz .findma - mov ebx,[.cebx] - call dword near [.readaddr] - add cx,[.addrincr] - call dword near [.regptrd] -.findma - pop esi - mov [esi+2],cx - pop eax - mov byte[AddrNoIncr],0 - ret - -section .data -ALIGN32 - -.curbank dd 0 -.addrincr dd 0 -.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 - dw 0,1,2,3 -; pointer address of registers -.regptra dd 0 -.regptrb dd 0 -.regptrc dd 0 -.regptrd dd 0 -.readaddr dd 0 -.cebx dd 0 -section .text - -NEWSYM transdmappu2cpu - ; set address increment value - mov dword[.addrincr],0 - test al,00001000b - jnz .skipaddrincr - test al,00010000b - jnz .autodec - mov dword[.addrincr],1 - jmp .skipaddrincr -.autodec - mov dword[.addrincr],0FFFFFFFFh -.skipaddrincr - - ; get address order to be written - xor ebx,ebx - and al,00000111b - mov bl,al - shl bl,3 - add ebx,.addrwrite - mov edi,ebx - - ; get pointer #1 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi] - shl ebx,2 - add ebx,[regptr] - mov eax,[ebx] - mov [.regptra],eax - - ; get pointer #2 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+2] - shl ebx,2 - add ebx,[regptr] - mov eax,[ebx] - mov [.regptrb],eax - - ; get pointer #3 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+4] - shl ebx,2 - add ebx,[regptr] - mov eax,[ebx] - mov [.regptrc],eax - - ; get pointer #4 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+6] - shl ebx,2 - add ebx,[regptr] - mov eax,[ebx] - mov [.regptrd],eax - - mov dx,[esi+5] ; Number of bytes to transfer - xor ebx,ebx - mov bl,[esi+4] ; Bank # - mov ecx,[esi+2] ; address offset # - and ecx,0FFFFh - mov [.curbank],bl - mov word[esi+5],0 - - mov ebx,[.curbank] - mov eax,snesmap2 - test ecx,8000h - jz .nomap1 - mov eax,snesmmap -.nomap1 - and edx,0FFFFh - mov ebx,[eax+ebx*4] - - push esi - mov esi,ebx - xor ebx,ebx - mov bl,[.curbank] - ; do loop - cmp edx,0 - jne .no0 - mov edx,65536 -.no0 - mov ebx,[memtablew8+ebx*4] - mov [.writeaddr],ebx - xor ebx,ebx - mov bl,[.curbank] - mov [.cebx],ebx -.againloop - cmp edx,4 - jbe .deccheckloop - call dword near [.regptra] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - call dword near [.regptrb] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - call dword near [.regptrc] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - call dword near [.regptrd] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - sub edx,4 - jmp .againloop -.deccheckloop - call dword near [.regptra] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - dec edx - jz .findma - call dword near [.regptrb] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - dec edx - jz .findma - call dword near [.regptrc] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] - dec edx - jz .findma - call dword near [.regptrd] - mov ebx,[.cebx] - call dword near [.writeaddr] - add cx,[.addrincr] -.findma - pop esi - mov [esi+2],cx - pop eax - ret - -section .data -ALIGN32 - -.curbank dd 0 -.addrincr dd 0 -.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 - dw 0,1,2,3 -; pointer address of registers -.regptra dd 0 -.regptrb dd 0 -.regptrc dd 0 -.regptrd dd 0 -.writeaddr dd 0 -.cebx dd 0 -section .text - -%macro TestDMA 0 -%endmacro - -; DMA enable register -; use dmadata for input on dma -NEWSYM reg420Bw - push eax - push esi - push edi - push ecx - push edx - mov esi,dmadata - test al,01h - jz .notransa - TestDMA - call transdma -.notransa - add esi,16 - test al,02h - jz .notransb - TestDMA - call transdma -.notransb - add esi,16 - test al,04h - jz .notransc - TestDMA - call transdma -.notransc - add esi,16 - test al,08h - jz .notransd - TestDMA - call transdma -.notransd - add esi,16 - test al,10h - jz .notranse - TestDMA - call transdma -.notranse - add esi,16 - test al,20h - jz .notransf - TestDMA - call transdma -.notransf - add esi,16 - test al,40h - jz .notransg - TestDMA - call transdma -.notransg - add esi,16 - test al,80h - jz .notransh - TestDMA - call transdma -.notransh - pop edx - pop ecx - pop edi - pop esi - pop eax - ret - -;******************************************************* -; HDMA Settings -;******************************************************* -NEWSYM setuphdma - push eax - - ; transfer old address to new address - mov ax,[esi+2] - mov [esi+8],ax - mov [edx+17],ax - ; get address order to be written - xor ebx,ebx - xor eax,eax - xor ecx,ecx - mov al,[esi] - and al,00000111b - cmp al,5 - jb .notmode567dma - sub al,4 -.notmode567dma - mov ah,[.addrnumt+eax] - mov [edx+16],ah - mov bl,al - shl bl,3 - add ebx,.addrwrite - mov edi,ebx - - ; get pointer #1 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi] - cmp bx,2118h - je .notnormalhdma1 - cmp bx,2119h - je .notnormalhdma1 - jmp .normalhdma1 -.notnormalhdma1 - mov bx,2200h ; bad hack _Demo_ -.normalhdma1 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx],eax - - ; get pointer #2 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+2] - cmp bx,2118h - je .notnormalhdma2 - cmp bx,2119h - je .notnormalhdma2 - jmp .normalhdma2 -.notnormalhdma2 - mov bx,2200h ; bad hack _Demo_ -.normalhdma2 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+4],eax - - ; get pointer #3 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+4] - cmp bx,2118h - je .notnormalhdma3 - cmp bx,2119h - je .notnormalhdma3 - jmp .normalhdma3 -.notnormalhdma3 - mov bx,2200h ; bad hack _Demo_ -.normalhdma3 - - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+8],eax - - ; get pointer #4 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+6] - cmp bx,2118h - je .notnormalhdma4 - cmp bx,2119h - je .notnormalhdma4 - jmp .normalhdma4 -.notnormalhdma4 - mov bx,2200h ; bad hack _Demo_ -.normalhdma4 - - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+12],eax - - xor ebx,ebx - mov byte[esi+10],0 - pop eax - or [hdmatype],ah - ret - -section .data -.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 - dw 0,1,2,3 -.addrnumt db 1,2,2,4,4,4,4,4 -section .text - -NEWSYM setuphdmars - push eax - - ; get address order to be written - xor ebx,ebx - xor eax,eax - xor ecx,ecx - mov al,[esi] - and al,00000111b - cmp al,5 - jb .notmode567dma - sub al,4 -.notmode567dma - mov ah,[.addrnumt+eax] - mov [edx+16],ah - mov bl,al - shl bl,3 - add ebx,.addrwrite - mov edi,ebx - - ; get pointer #1 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi] - cmp bx,2118h - je .notnormalhdma1 - cmp bx,2119h - je .notnormalhdma1 - jmp .normalhdma1 -.notnormalhdma1 - mov bx,2200h ; bad hack _Demo_ -.normalhdma1 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx],eax - - ; get pointer #2 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+2] - cmp bx,2118h - je .notnormalhdma2 - cmp bx,2119h - je .notnormalhdma2 - jmp .normalhdma2 -.notnormalhdma2 - mov bx,2200h ; bad hack _Demo_ -.normalhdma2 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+4],eax - - ; get pointer #3 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+4] - cmp bx,2118h - je .notnormalhdma3 - cmp bx,2119h - je .notnormalhdma3 - jmp .normalhdma3 -.notnormalhdma3 - mov bx,2200h ; bad hack _Demo_ -.normalhdma3 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+8],eax - - ; get pointer #4 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+6] - cmp bx,2118h - je .notnormalhdma4 - cmp bx,2119h - je .notnormalhdma4 - jmp .normalhdma4 -.notnormalhdma4 - mov bx,2200h ; bad hack _Demo_ -.normalhdma4 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+12],eax - - xor ebx,ebx - pop eax - ret - -section .data -.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 - dw 0,1,2,3 -.addrnumt db 1,2,2,4,4,4,4,4 -section .text - -NEWSYM setuphdma2 - push eax - - cmp byte[esi+10],0 - je near .nohdma - - ; transfer old address to new address - mov ax,[esi+8] - mov [edx+17],ax - ; get address order to be written - xor ebx,ebx - xor eax,eax - xor ecx,ecx - mov al,[esi] - and al,00000111b - cmp al,5 - jb .notmode567dma - sub al,4 -.notmode567dma - mov ah,[.addrnumt+eax] - mov [edx+16],ah - mov bl,al - shl bl,3 - add ebx,.addrwrite - mov edi,ebx - - ; get pointer #1 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi] - cmp bx,2118h - je .notnormalhdma1 - cmp bx,2119h - je .notnormalhdma1 - jmp .normalhdma1 -.notnormalhdma1 - mov bx,2200h ; bad hack _Demo_ -.normalhdma1 - - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx],eax - - ; get pointer #2 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+2] - cmp bx,2118h - je .notnormalhdma2 - cmp bx,2119h - je .notnormalhdma2 - jmp .normalhdma2 -.notnormalhdma2 - mov bx,2200h ; bad hack _Demo_ -.normalhdma2 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+4],eax - ; get pointer #3 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+4] - cmp bx,2118h - je .notnormalhdma3 - cmp bx,2119h - je .notnormalhdma3 - jmp .normalhdma3 -.notnormalhdma3 - mov bx,2200h ; bad hack _Demo_ -.normalhdma3 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+8],eax - - ; get pointer #4 - xor ebx,ebx - mov bl,[esi+1] ; PPU memory - 21xx - mov bh,21h - add bx,[edi+6] - cmp bx,2118h - je .notnormalhdma4 - cmp bx,2119h - je .notnormalhdma4 - jmp .normalhdma4 -.notnormalhdma4 - mov bx,2200h ; bad hack _Demo_ -.normalhdma4 - shl ebx,2 - add ebx,[regptw] - mov eax,[ebx] - mov [edx+12],eax - - xor ebx,ebx - pop eax - and [hdmatype],ah - ret -.nohdma - pop eax - and [nexthdma],ah - ret - -section .data -.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 - dw 0,1,2,3 -.addrnumt db 1,2,2,4,4,4,4,4 - -section .text - -NEWSYM reg420Cw - mov [curhdma],al - mov bx,[resolutn] - cmp word[curypos],bx - jae near .nohdma - mov al,[curhdma] - cmp byte[disablehdma],0 - jne near .nohdma - mov [nexthdma],al - cmp al,0 - je near .nohdma - push ebx - push esi - push edi - push ecx - push edx - mov esi,dmadata - mov edx,hdmadata - mov ah,01h - test al,01h - jz .notransa - call setuphdma -.notransa - add esi,16 - add edx,19 - mov ah,02h - test al,02h - jz .notransb - call setuphdma -.notransb - add esi,16 - add edx,19 - mov ah,04h - test al,04h - jz .notransc - call setuphdma -.notransc - add esi,16 - add edx,19 - mov ah,08h - test al,08h - jz .notransd - call setuphdma -.notransd - add esi,16 - add edx,19 - mov ah,10h - test al,10h - jz .notranse - call setuphdma -.notranse - add esi,16 - add edx,19 - mov ah,20h - test al,20h - jz .notransf - call setuphdma -.notransf - add esi,16 - add edx,19 - mov ah,40h - test al,40h - jz .notransg - call setuphdma -.notransg - add esi,16 - add edx,19 - mov ah,80h - test al,80h - jz .notransh - call setuphdma -.notransh - pop edx - pop ecx - pop edi - pop esi - pop ebx -; call exechdma -; call exechdma -.nohdma - cmp byte[nohdmaframe],1 - jne .notframe - inc byte[hdmadelay] -.notframe - - mov byte[hdmarestart],0 - ret - -; HDMA enable register -NEWSYM starthdma - mov al,[curhdma] -NEWSYM startnexthdma - mov [nexthdma],al - cmp al,0 - je near .nohdma - push ebx - push esi - push edi - push ecx - push edx - mov esi,dmadata - mov edx,hdmadata - mov ah,01h - test al,01h - jz .notransa - call setuphdma -.notransa - add esi,16 - add edx,19 - mov ah,02h - test al,02h - jz .notransb - call setuphdma -.notransb - add esi,16 - add edx,19 - mov ah,04h - test al,04h - jz .notransc - call setuphdma -.notransc - add esi,16 - add edx,19 - mov ah,08h - test al,08h - jz .notransd - call setuphdma -.notransd - add esi,16 - add edx,19 - mov ah,10h - test al,10h - jz .notranse - call setuphdma -.notranse - add esi,16 - add edx,19 - mov ah,20h - test al,20h - jz .notransf - call setuphdma -.notransf - add esi,16 - add edx,19 - mov ah,40h - test al,40h - jz .notransg - call setuphdma -.notransg - add esi,16 - add edx,19 - mov ah,80h - test al,80h - jz .notransh - call setuphdma -.notransh - pop edx - pop ecx - pop edi - pop esi - pop ebx -.nohdma - ret - -NEWSYM dohdma - xor ebx,ebx - test byte[esi],40h - jnz near indirectaddr - push eax - test byte[esi+10],07Fh - jnz near .nozero - test byte[esi+10],80h - jnz near .noincr - test [hdmatype],ah - jnz .noincr - mov bl,[edx+16] - add word[edx+17],bx -.noincr - mov bl,ah - not bl - and [hdmatype],bl - mov bl,[esi+4] - mov cx,[edx+17] - call dword near [memtabler8+ebx*4] - inc word[edx+17] - mov [esi+10],al - test al,0FFh - jnz .yeszero - xor [nexthdma],ah - jmp .finhdma2 -.yeszero - cmp byte[esi+10],80h - ja near hdmatype2 - mov al,[edx+16] - mov [.tempdecr],al - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - call dword near [memtabler8+ebx*4] - call dword near [edx] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - inc cx - call dword near [memtabler8+ebx*4] - call dword near [edx+4] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - add cx,2 - call dword near [memtabler8+ebx*4] - call dword near [edx+8] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - add cx,3 - call dword near [memtabler8+ebx*4] - call dword near [edx+12] - jmp .finhdma -.nozero - test byte[esi+10],80h - jnz near hdmatype2 -.finhdma - mov ax,[edx+17] - mov [esi+8],ax - pop eax - dec byte[esi+10] - ret -.finhdma2 - mov ax,[edx+17] - mov [esi+8],ax - pop eax - ret - -section .bss -.tempdecr resd 1 -section .text - -NEWSYM hdmatype2 - mov al,[edx+16] - mov [.tempdecr],al - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - inc word[edx+17] - call dword near [memtabler8+ebx*4] - call dword near [edx] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - inc word[edx+17] - call dword near [memtabler8+ebx*4] - call dword near [edx+4] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - inc word[edx+17] - call dword near [memtabler8+ebx*4] - call dword near [edx+8] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+4] - mov cx,[edx+17] ; increment/decrement/keep pointer location - inc word[edx+17] - call dword near [memtabler8+ebx*4] - call dword near [edx+12] -.finhdma - mov ax,[edx+17] - mov [esi+8],ax - pop eax - dec byte[esi+10] - ret - -section .bss -.tempdecr resd 1 -section .text - -NEWSYM indirectaddr - push eax - test byte[esi+10],07Fh - jnz near .nozero - test [hdmatype],ah - jnz .noincr - add word[edx+17],2 -.noincr - mov bl,ah - not bl - and [hdmatype],bl - mov bl,[esi+4] - mov cx,[edx+17] - call dword near [memtabler8+ebx*4] - inc word[edx+17] - mov [esi+10],al - push eax - mov bl,[esi+4] - mov cx,[edx+17] - call dword near [memtabler16+ebx*4] - mov [esi+5],ax - pop eax - test al,0FFh - jnz .yeszero - xor [nexthdma],ah - jmp .finhdma2 -.yeszero - cmp byte[esi+10],80h - ja near hdmatype2indirect - mov al,[edx+16] - mov [.tempdecr],al - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - call dword near [memtabler8+ebx*4] - call dword near [edx] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - inc cx - call dword near [memtabler8+ebx*4] - call dword near [edx+4] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - add cx,2 - call dword near [memtabler8+ebx*4] - call dword near [edx+8] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - add cx,3 - call dword near [memtabler8+ebx*4] - call dword near [edx+12] - jmp .finhdma -.nozero - test byte[esi+10],80h - jnz near hdmatype2indirect -.finhdma - mov ax,[edx+17] - mov [esi+8],ax - pop eax - dec byte[esi+10] - ret -.finhdma2 - mov ax,[edx+17] - mov [esi+8],ax - pop eax - ret - -section .bss -.tempdecr resd 1 - -section .data -.fname2 db 9,'vram2.dat',0 -section .text - -EXTSYM SPCRAM -section .data -NEWSYM ewj2hack, dd 0 -section .text - -NEWSYM hdmatype2indirect - cmp dword[ewj2hack],1 - jne near .notend - cmp byte[esi+1],40h ; Writing to spc - jne near .notend - cmp byte[esi+10],0DAh ; first transfer - jne near .notend - ; EWJ2 HACK -; int 3h - push eax - push ebx - push ecx - push edx - xor eax,eax - xor ebx,ebx - xor ecx,ecx - xor edx,edx - mov ax,[SPCRAM+021h] ; load dest offset - mov dword[.dest],SPCRAM - add [.dest],eax - mov dl,[esi+10] ; number of bytes to transfer - sub dl,80h -.inloop - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+7] - mov cx,[esi+5] - inc word[esi+5] - call dword near [memtabler8+ebx*4] - mov ebx,[.dest] - mov [ebx],al - inc ebx - mov [.dest],ebx - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+7] - mov cx,[esi+5] - inc word[esi+5] - call dword near [memtabler8+ebx*4] - mov ebx,[.dest] - mov [ebx],al - inc ebx - mov [.dest],ebx - dec edx - jnz .inloop - sub word[esi+5],5Ah - sub word[esi+5],5Ah - pop edx - pop ecx - pop ebx - pop eax -.notend - - mov al,[edx+16] - mov [.tempdecr],al - xor ebx,ebx - xor ecx,ecx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - inc word[esi+5] - call dword near [memtabler8+ebx*4] - call dword near [edx] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - inc word[esi+5] - call dword near [memtabler8+ebx*4] - call dword near [edx+4] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - inc word[esi+5] - call dword near [memtabler8+ebx*4] - call dword near [edx+8] - dec byte[.tempdecr] - jz .finhdma - xor ebx,ebx - mov bl,[esi+7] - mov cx,[esi+5] ; increment/decrement/keep pointer location - inc word[esi+5] - call dword near [memtabler8+ebx*4] - call dword near [edx+12] -.finhdma - pop eax - dec byte[esi+10] - ret - -section .bss -.tempdecr resd 1 -.dest resd 1 -section .text - -NEWSYM exechdma - cmp byte[hdmarestart],1 - je near exechdmars - mov al,[nexthdma] - cmp al,0 - je near .nohdma - push ebx - push esi - push edi - push ecx - push edx - mov esi,dmadata - mov edx,hdmadata - mov ah,01h - test al,01h - jz .notransa - call dohdma -.notransa - add esi,16 - add edx,19 - mov ah,02h - test al,02h - jz .notransb - call dohdma -.notransb - add esi,16 - add edx,19 - mov ah,04h - test al,04h - jz .notransc - call dohdma -.notransc - add esi,16 - add edx,19 - mov ah,08h - test al,08h - jz .notransd - call dohdma -.notransd - add esi,16 - add edx,19 - mov ah,10h - test al,10h - jz .notranse - call dohdma -.notranse - add esi,16 - add edx,19 - mov ah,20h - test al,20h - jz .notransf - call dohdma -.notransf - add esi,16 - add edx,19 - mov ah,40h - test al,40h - jz .notransg - call dohdma -.notransg - add esi,16 - add edx,19 - mov ah,80h - test al,80h - jz .notransh - call dohdma -.notransh - pop edx - pop ecx - pop edi - pop esi - pop ebx -.nohdma - ret - -NEWSYM exechdmars - mov al,[nexthdma] - cmp al,0 - je near .nohdma - push ebx - push esi - push edi - push ecx - push edx - mov esi,dmadata - mov edx,hdmadata - mov ah,01h - test al,01h - jz .notransa - call setuphdmars - call dohdma -.notransa - add esi,16 - add edx,19 - mov ah,02h - test al,02h - jz .notransb - call setuphdmars - call dohdma -.notransb - add esi,16 - add edx,19 - mov ah,04h - test al,04h - jz .notransc - call setuphdmars - call dohdma -.notransc - add esi,16 - add edx,19 - mov ah,08h - test al,08h - jz .notransd - call setuphdmars - call dohdma -.notransd - add esi,16 - add edx,19 - mov ah,10h - test al,10h - jz .notranse - call setuphdmars - call dohdma -.notranse - add esi,16 - add edx,19 - mov ah,20h - test al,20h - jz .notransf - call setuphdmars - call dohdma -.notransf - add esi,16 - add edx,19 - mov ah,40h - test al,40h - jz .notransg - call setuphdmars - call dohdma -.notransg - add esi,16 - add edx,19 - mov ah,80h - test al,80h - jz .notransh - call setuphdmars - call dohdma -.notransh - pop edx - pop ecx - pop edi - pop esi - pop ebx -.nohdma - mov byte[hdmarestart],0 - ret - - +;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) +; +;http://www.zsnes.com +;http://sourceforge.net/projects/zsnes +; +;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 memtabler8,regptw,snesmap2,snesmmap,memtablew8,regptr,memtabler16 +EXTSYM dmadata,hdmatype,nexthdma,resolutn,curhdma,curypos,disablehdma,hdmadata +EXTSYM hdmadelay,hdmarestart,nohdmaframe + +;******************************************************* +; Transfer DMA Inits & Transfers DMA +;******************************************************* +; DMA transfer register + +section .bss +NEWSYM AddrNoIncr, resb 1 +section .text + +%macro ExecSPCCycles 0 + xor ebx,ebx + mov bx,[esi+5] + inc bx + inc ebx + shr ebx,2 + mov [soundcycleft],ebx + or ebx,ebx + jz .nocycles + xor ebx,ebx + xor ecx,ecx + call pexecs2 +.nocycles +%endmacro + +NEWSYM transdma + push eax + cmp word[esi+5],480h + jne .no +; mov byte[debstop3],1 +.no +; ExecSPCCycles + + mov al,[esi] + test al,80h + jnz near transdmappu2cpu + + ; set address increment value + mov dword[.addrincr],0 + test al,00001000b + jnz .skipaddrincr + test al,00010000b + jnz .autodec + mov dword[.addrincr],1 + jmp .skipaddrincr +.autodec + mov dword[.addrincr],0FFFFFFFFh +.skipaddrincr + + mov byte[AddrNoIncr],0 + cmp dword[.addrincr],0 + jne .notzero + mov byte[AddrNoIncr],1 +.notzero + ; get address order to be written + xor ebx,ebx + and al,00000111b + cmp al,5 + jne .notmode5dma + sub al,4 +.notmode5dma + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptra],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrb],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrc],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [.regptrd],eax + + mov dx,[esi+5] ; Number of bytes to transfer + xor ebx,ebx + mov bl,[esi+4] ; Bank # + mov ecx,[esi+2] ; address offset # + and ecx,0FFFFh + mov [.curbank],bl + mov word[esi+5],0 + + mov ebx,[.curbank] + mov eax,snesmap2 + test ecx,8000h + jz .nomap1 + mov eax,snesmmap +.nomap1 + and edx,0FFFFh + mov ebx,[eax+ebx*4] + + push esi + mov esi,ebx + xor ebx,ebx + mov bl,[.curbank] + ; do loop + cmp edx,0 + jne .no0 + mov edx,65536 +.no0 + mov ebx,[memtabler8+ebx*4] + mov [.readaddr],ebx + xor ebx,ebx + mov bl,[.curbank] + mov [.cebx],ebx +.againloop + cmp edx,4 + jbe .deccheckloop + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrd] + sub edx,4 + jmp .againloop +.deccheckloop + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptra] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrb] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrc] + dec edx + jz .findma + mov ebx,[.cebx] + call dword near [.readaddr] + add cx,[.addrincr] + call dword near [.regptrd] +.findma + pop esi + mov [esi+2],cx + pop eax + mov byte[AddrNoIncr],0 + ret + +section .data +ALIGN32 + +.curbank dd 0 +.addrincr dd 0 +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +; pointer address of registers +.regptra dd 0 +.regptrb dd 0 +.regptrc dd 0 +.regptrd dd 0 +.readaddr dd 0 +.cebx dd 0 +section .text + +NEWSYM transdmappu2cpu + ; set address increment value + mov dword[.addrincr],0 + test al,00001000b + jnz .skipaddrincr + test al,00010000b + jnz .autodec + mov dword[.addrincr],1 + jmp .skipaddrincr +.autodec + mov dword[.addrincr],0FFFFFFFFh +.skipaddrincr + + ; get address order to be written + xor ebx,ebx + and al,00000111b + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptra],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrb],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrc],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + shl ebx,2 + add ebx,[regptr] + mov eax,[ebx] + mov [.regptrd],eax + + mov dx,[esi+5] ; Number of bytes to transfer + xor ebx,ebx + mov bl,[esi+4] ; Bank # + mov ecx,[esi+2] ; address offset # + and ecx,0FFFFh + mov [.curbank],bl + mov word[esi+5],0 + + mov ebx,[.curbank] + mov eax,snesmap2 + test ecx,8000h + jz .nomap1 + mov eax,snesmmap +.nomap1 + and edx,0FFFFh + mov ebx,[eax+ebx*4] + + push esi + mov esi,ebx + xor ebx,ebx + mov bl,[.curbank] + ; do loop + cmp edx,0 + jne .no0 + mov edx,65536 +.no0 + mov ebx,[memtablew8+ebx*4] + mov [.writeaddr],ebx + xor ebx,ebx + mov bl,[.curbank] + mov [.cebx],ebx +.againloop + cmp edx,4 + jbe .deccheckloop + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + call dword near [.regptrd] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + sub edx,4 + jmp .againloop +.deccheckloop + call dword near [.regptra] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrb] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrc] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] + dec edx + jz .findma + call dword near [.regptrd] + mov ebx,[.cebx] + call dword near [.writeaddr] + add cx,[.addrincr] +.findma + pop esi + mov [esi+2],cx + pop eax + ret + +section .data +ALIGN32 + +.curbank dd 0 +.addrincr dd 0 +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +; pointer address of registers +.regptra dd 0 +.regptrb dd 0 +.regptrc dd 0 +.regptrd dd 0 +.writeaddr dd 0 +.cebx dd 0 +section .text + +%macro TestDMA 0 +%endmacro + +; DMA enable register +; use dmadata for input on dma +NEWSYM reg420Bw + push eax + push esi + push edi + push ecx + push edx + mov esi,dmadata + test al,01h + jz .notransa + TestDMA + call transdma +.notransa + add esi,16 + test al,02h + jz .notransb + TestDMA + call transdma +.notransb + add esi,16 + test al,04h + jz .notransc + TestDMA + call transdma +.notransc + add esi,16 + test al,08h + jz .notransd + TestDMA + call transdma +.notransd + add esi,16 + test al,10h + jz .notranse + TestDMA + call transdma +.notranse + add esi,16 + test al,20h + jz .notransf + TestDMA + call transdma +.notransf + add esi,16 + test al,40h + jz .notransg + TestDMA + call transdma +.notransg + add esi,16 + test al,80h + jz .notransh + TestDMA + call transdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop eax + ret + +;******************************************************* +; HDMA Settings +;******************************************************* +NEWSYM setuphdma + push eax + + ; transfer old address to new address + mov ax,[esi+2] + mov [esi+8],ax + mov [edx+17],ax + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + cmp al,5 + jb .notmode567dma + sub al,4 +.notmode567dma + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + cmp bx,2118h + je .notnormalhdma1 + cmp bx,2119h + je .notnormalhdma1 + jmp .normalhdma1 +.notnormalhdma1 + mov bx,2200h ; bad hack _Demo_ +.normalhdma1 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + cmp bx,2118h + je .notnormalhdma2 + cmp bx,2119h + je .notnormalhdma2 + jmp .normalhdma2 +.notnormalhdma2 + mov bx,2200h ; bad hack _Demo_ +.normalhdma2 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + cmp bx,2118h + je .notnormalhdma3 + cmp bx,2119h + je .notnormalhdma3 + jmp .normalhdma3 +.notnormalhdma3 + mov bx,2200h ; bad hack _Demo_ +.normalhdma3 + + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + cmp bx,2118h + je .notnormalhdma4 + cmp bx,2119h + je .notnormalhdma4 + jmp .normalhdma4 +.notnormalhdma4 + mov bx,2200h ; bad hack _Demo_ +.normalhdma4 + + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + mov byte[esi+10],0 + pop eax + or [hdmatype],ah + ret + +section .data +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 +section .text + +NEWSYM setuphdmars + push eax + + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + cmp al,5 + jb .notmode567dma + sub al,4 +.notmode567dma + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + cmp bx,2118h + je .notnormalhdma1 + cmp bx,2119h + je .notnormalhdma1 + jmp .normalhdma1 +.notnormalhdma1 + mov bx,2200h ; bad hack _Demo_ +.normalhdma1 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + cmp bx,2118h + je .notnormalhdma2 + cmp bx,2119h + je .notnormalhdma2 + jmp .normalhdma2 +.notnormalhdma2 + mov bx,2200h ; bad hack _Demo_ +.normalhdma2 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + cmp bx,2118h + je .notnormalhdma3 + cmp bx,2119h + je .notnormalhdma3 + jmp .normalhdma3 +.notnormalhdma3 + mov bx,2200h ; bad hack _Demo_ +.normalhdma3 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + cmp bx,2118h + je .notnormalhdma4 + cmp bx,2119h + je .notnormalhdma4 + jmp .normalhdma4 +.notnormalhdma4 + mov bx,2200h ; bad hack _Demo_ +.normalhdma4 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + pop eax + ret + +section .data +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 +section .text + +NEWSYM setuphdma2 + push eax + + cmp byte[esi+10],0 + je near .nohdma + + ; transfer old address to new address + mov ax,[esi+8] + mov [edx+17],ax + ; get address order to be written + xor ebx,ebx + xor eax,eax + xor ecx,ecx + mov al,[esi] + and al,00000111b + cmp al,5 + jb .notmode567dma + sub al,4 +.notmode567dma + mov ah,[.addrnumt+eax] + mov [edx+16],ah + mov bl,al + shl bl,3 + add ebx,.addrwrite + mov edi,ebx + + ; get pointer #1 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi] + cmp bx,2118h + je .notnormalhdma1 + cmp bx,2119h + je .notnormalhdma1 + jmp .normalhdma1 +.notnormalhdma1 + mov bx,2200h ; bad hack _Demo_ +.normalhdma1 + + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx],eax + + ; get pointer #2 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+2] + cmp bx,2118h + je .notnormalhdma2 + cmp bx,2119h + je .notnormalhdma2 + jmp .normalhdma2 +.notnormalhdma2 + mov bx,2200h ; bad hack _Demo_ +.normalhdma2 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+4],eax + ; get pointer #3 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+4] + cmp bx,2118h + je .notnormalhdma3 + cmp bx,2119h + je .notnormalhdma3 + jmp .normalhdma3 +.notnormalhdma3 + mov bx,2200h ; bad hack _Demo_ +.normalhdma3 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+8],eax + + ; get pointer #4 + xor ebx,ebx + mov bl,[esi+1] ; PPU memory - 21xx + mov bh,21h + add bx,[edi+6] + cmp bx,2118h + je .notnormalhdma4 + cmp bx,2119h + je .notnormalhdma4 + jmp .normalhdma4 +.notnormalhdma4 + mov bx,2200h ; bad hack _Demo_ +.normalhdma4 + shl ebx,2 + add ebx,[regptw] + mov eax,[ebx] + mov [edx+12],eax + + xor ebx,ebx + pop eax + and [hdmatype],ah + ret +.nohdma + pop eax + and [nexthdma],ah + ret + +section .data +.addrwrite dw 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,0,1,1, 0,1,2,3, 0,1,2,3, 0,1,2,3 + dw 0,1,2,3 +.addrnumt db 1,2,2,4,4,4,4,4 + +section .text + +NEWSYM reg420Cw + mov [curhdma],al + mov bx,[resolutn] + cmp word[curypos],bx + jae near .nohdma + mov al,[curhdma] + cmp byte[disablehdma],0 + jne near .nohdma + mov [nexthdma],al + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +; call exechdma +; call exechdma +.nohdma + cmp byte[nohdmaframe],1 + jne .notframe + inc byte[hdmadelay] +.notframe + + mov byte[hdmarestart],0 + ret + +; HDMA enable register +NEWSYM starthdma + mov al,[curhdma] +NEWSYM startnexthdma + mov [nexthdma],al + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + ret + +NEWSYM dohdma + xor ebx,ebx + test byte[esi],40h + jnz near indirectaddr + push eax + test byte[esi+10],07Fh + jnz near .nozero + test byte[esi+10],80h + jnz near .noincr + test [hdmatype],ah + jnz .noincr + mov bl,[edx+16] + add word[edx+17],bx +.noincr + mov bl,ah + not bl + and [hdmatype],bl + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler8+ebx*4] + inc word[edx+17] + mov [esi+10],al + test al,0FFh + jnz .yeszero + xor [nexthdma],ah + jmp .finhdma2 +.yeszero + cmp byte[esi+10],80h + ja near hdmatype2 + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc cx + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + add cx,2 + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + add cx,3 + call dword near [memtabler8+ebx*4] + call dword near [edx+12] + jmp .finhdma +.nozero + test byte[esi+10],80h + jnz near hdmatype2 +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret +.finhdma2 + mov ax,[edx+17] + mov [esi+8],ax + pop eax + ret + +section .bss +.tempdecr resd 1 +section .text + +NEWSYM hdmatype2 + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+4] + mov cx,[edx+17] ; increment/decrement/keep pointer location + inc word[edx+17] + call dword near [memtabler8+ebx*4] + call dword near [edx+12] +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret + +section .bss +.tempdecr resd 1 +section .text + +NEWSYM indirectaddr + push eax + test byte[esi+10],07Fh + jnz near .nozero + test [hdmatype],ah + jnz .noincr + add word[edx+17],2 +.noincr + mov bl,ah + not bl + and [hdmatype],bl + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler8+ebx*4] + inc word[edx+17] + mov [esi+10],al + push eax + mov bl,[esi+4] + mov cx,[edx+17] + call dword near [memtabler16+ebx*4] + mov [esi+5],ax + pop eax + test al,0FFh + jnz .yeszero + xor [nexthdma],ah + jmp .finhdma2 +.yeszero + cmp byte[esi+10],80h + ja near hdmatype2indirect + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc cx + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + add cx,2 + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + add cx,3 + call dword near [memtabler8+ebx*4] + call dword near [edx+12] + jmp .finhdma +.nozero + test byte[esi+10],80h + jnz near hdmatype2indirect +.finhdma + mov ax,[edx+17] + mov [esi+8],ax + pop eax + dec byte[esi+10] + ret +.finhdma2 + mov ax,[edx+17] + mov [esi+8],ax + pop eax + ret + +section .bss +.tempdecr resd 1 + +section .data +.fname2 db 9,'vram2.dat',0 +section .text + +EXTSYM SPCRAM +section .data +NEWSYM ewj2hack, dd 0 +section .text + +NEWSYM hdmatype2indirect + cmp dword[ewj2hack],1 + jne near .notend + cmp byte[esi+1],40h ; Writing to spc + jne near .notend + cmp byte[esi+10],0DAh ; first transfer + jne near .notend + ; EWJ2 HACK +; int 3h + push eax + push ebx + push ecx + push edx + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov ax,[SPCRAM+021h] ; load dest offset + mov dword[.dest],SPCRAM + add [.dest],eax + mov dl,[esi+10] ; number of bytes to transfer + sub dl,80h +.inloop + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] + inc word[esi+5] + call dword near [memtabler8+ebx*4] + mov ebx,[.dest] + mov [ebx],al + inc ebx + mov [.dest],ebx + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] + inc word[esi+5] + call dword near [memtabler8+ebx*4] + mov ebx,[.dest] + mov [ebx],al + inc ebx + mov [.dest],ebx + dec edx + jnz .inloop + sub word[esi+5],5Ah + sub word[esi+5],5Ah + pop edx + pop ecx + pop ebx + pop eax +.notend + + mov al,[edx+16] + mov [.tempdecr],al + xor ebx,ebx + xor ecx,ecx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+4] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+8] + dec byte[.tempdecr] + jz .finhdma + xor ebx,ebx + mov bl,[esi+7] + mov cx,[esi+5] ; increment/decrement/keep pointer location + inc word[esi+5] + call dword near [memtabler8+ebx*4] + call dword near [edx+12] +.finhdma + pop eax + dec byte[esi+10] + ret + +section .bss +.tempdecr resd 1 +.dest resd 1 +section .text + +NEWSYM exechdma + cmp byte[hdmarestart],1 + je near exechdmars + mov al,[nexthdma] + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call dohdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call dohdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call dohdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call dohdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call dohdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call dohdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call dohdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call dohdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + ret + +NEWSYM exechdmars + mov al,[nexthdma] + cmp al,0 + je near .nohdma + push ebx + push esi + push edi + push ecx + push edx + mov esi,dmadata + mov edx,hdmadata + mov ah,01h + test al,01h + jz .notransa + call setuphdmars + call dohdma +.notransa + add esi,16 + add edx,19 + mov ah,02h + test al,02h + jz .notransb + call setuphdmars + call dohdma +.notransb + add esi,16 + add edx,19 + mov ah,04h + test al,04h + jz .notransc + call setuphdmars + call dohdma +.notransc + add esi,16 + add edx,19 + mov ah,08h + test al,08h + jz .notransd + call setuphdmars + call dohdma +.notransd + add esi,16 + add edx,19 + mov ah,10h + test al,10h + jz .notranse + call setuphdmars + call dohdma +.notranse + add esi,16 + add edx,19 + mov ah,20h + test al,20h + jz .notransf + call setuphdmars + call dohdma +.notransf + add esi,16 + add edx,19 + mov ah,40h + test al,40h + jz .notransg + call setuphdmars + call dohdma +.notransg + add esi,16 + add edx,19 + mov ah,80h + test al,80h + jz .notransh + call setuphdmars + call dohdma +.notransh + pop edx + pop ecx + pop edi + pop esi + pop ebx +.nohdma + mov byte[hdmarestart],0 + ret + + diff --git a/zsnes/src/cpu/execute.asm b/zsnes/src/cpu/execute.asm index 52344dd2..c48bab0b 100644 --- a/zsnes/src/cpu/execute.asm +++ b/zsnes/src/cpu/execute.asm @@ -1,2205 +1,2205 @@ -;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) -; -;http://www.zsnes.com -;http://sourceforge.net/projects/zsnes -; -;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 KeyRewind,statesaver,Voice0Status,UpdateDPage -EXTSYM StartGUI,debuggeron,romdata,initvideo -EXTSYM vidbufferofsa,disable65816sh,GUISaveVars,virqnodisable -EXTSYM KeySaveState,KeyLoadState,KeyQuickExit,KeyQuickLoad,KeyQuickRst -EXTSYM GUIDoReset,GUIReset,KeyOnStA,KeyOnStB,ProcessKeyOn,C4Enable,KeyQuickClock -EXTSYM KeyQuickSaveSPC,TimerEnable,IRQHack,splitflags,joinflags -EXTSYM KeyQuickSnapShot,csounddisable,videotroub,ResetTripleBuf -EXTSYM Output_Text,Check_Key,Get_Key,Change_Dir -EXTSYM InitPreGame,Curtableaddr,curcyc,debugdisble,dmadata,guioff,memtabler8 -EXTSYM SetupPreGame,memtablew8,regaccessbankr8,showmenu,snesmap2,snesmmap -EXTSYM DeInitPostGame,spcPCRam,startdebugger,xp,xpb,xpc,tablead,tableadb -EXTSYM tableadc,SA1UpdateDPage,Makemode7Table,nextmenupopup,MovieProcessing -EXTSYM DosExit,InitDir,InitDrive,createnewcfg,sfxramdata,deinitvideo -EXTSYM SFXEnable,wramdata,cycpbl,cycpblt,irqon,spcon -EXTSYM multchange,romispal,scrndis,sprlefttot,sprleftpr,processsprites -EXTSYM cachesprites,NextLineStart,FlipWait,LastLineStart,opcjmptab,CheatOn -EXTSYM INTEnab,JoyCRead,NMIEnab,NumCheats,CurrentExecSA1,ReadInputDevice -EXTSYM StartDrawNewGfx,VIRQLoc,cachevideo,cfield,cheatdata,curblank,curnmi -EXTSYM curypos,cycpl,doirqnext,drawline,exechdma,hdmadelay,intrset,newengen -EXTSYM oamaddr,oamaddrs,resolutn,showvideo,snesmouse,starthdma,switchtonmi -EXTSYM switchtovirq,totlines,updatetimer,SA1Swap,SA1DoIRQ,JoyAOrig,JoyANow -EXTSYM JoyBOrig,JoyBNow,JoyCOrig,JoyCNow,JoyDOrig,JoyDNow,JoyEOrig,JoyENow -EXTSYM SA1Message,MultiTapStat,idledetectspc,SA1Control,SA1Enable,SA1IRQEnable -EXTSYM SPC700read,SPC700write,numspcvblleft,spc700idle,SA1IRQExec,ForceNewGfxOff -EXTSYM LethEnData,GUIQuit,IRAM,SA1Ptr,SA1BWPtr,scrnon,scaddset,outofmemfix -EXTSYM yesoutofmemory,ProcessMovies,MovieStop,ppustatus,C4VBlank -EXTSYM ReturnFromSPCStall,scanlines,smallscreenon,ScreenScale,MainLoop -EXTSYM NumberOfOpcodes,SfxCLSR,SfxSCMR,SfxPOR,sfx128lineloc,sfx160lineloc -EXTSYM sfx192lineloc,sfxobjlineloc,sfxclineloc,PLOTJmpa,PLOTJmpb,FxTable -EXTSYM FxTableb,FxTablec,FxTabled,SfxPBR,SCBRrel,SfxSCBR,SfxCOLR,SFXCounter -EXTSYM fxbit01,fxbit01pcal,fxbit23,fxbit23pcal,fxbit45,fxbit45pcal,fxbit67 -EXTSYM fxbit67pcal,SfxSFR,nosprincr,cpucycle,switchtovirqdeb,switchtonmideb -EXTSYM MovieSeekBehind,SaveSramData,BackupCVFrame,RestoreCVFrame,loadstate -EXTSYM KeyInsrtChap,KeyNextChap,KeyPrevChap,MovieInsertChapter,MovieSeekAhead -EXTSYM ResetDuringMovie,EMUPauseKey,INCRFrameKey,MovieWaiting,NoInputRead -EXTSYM AllocatedRewindStates,PauseFrameMode,RestorePauseFrame,BackupPauseFrame - -%ifdef __MSDOS__ -EXTSYM dssel,Game60hzcall -%endif - -SECTION .data -NEWSYM tempedx, dd 0 -NEWSYM tempesi, dd 0 -NEWSYM tempedi, dd 0 -NEWSYM tempebp, dd 0 -NEWSYM RewindTimer, dd 0 -NEWSYM BackState, db 1 -NEWSYM BackStateSize, dd 6 -SECTION .text - -NEWSYM ProcessRewind - mov eax,[KeyRewind] - cmp byte[pressed+eax],1 - jne near .notokay - mov byte[pressed+eax],2 - - pushad - call RestoreCVFrame - popad - - cmp byte[PauseFrameMode],1 - jne .notpauserewind - pushad - call BackupPauseFrame - popad -.notpauserewind - - mov esi,[tempesi] - mov edi,[tempedi] - mov ebp,[tempebp] - mov edx,[tempedx] - -.notokay - ret - -NEWSYM UpdateRewind - cmp byte[AllocatedRewindStates],0 - je .norewinds - cmp dword[KeyRewind],0 - je .norewinds - - dec dword[RewindTimer] - jnz .checkrewind - - mov [tempedx],edx - mov [tempesi],esi - mov [tempedi],edi - mov [tempebp],ebp - - pushad - call BackupCVFrame - popad - -.checkrewind - call ProcessRewind -.norewinds - ret - -SECTION .data -NEWSYM MuteVoiceF, dd 0 -SECTION .text - -VoiceEndMute: - mov byte[MuteVoiceF],0 - ret - -%macro StartMute 1 - mov al,[Voice0Status+%1] - or al,al - jz %%notmuted - or byte[MuteVoiceF],1 << %1 -%%notmuted -%endmacro - -VoiceStartMute: - mov byte[MuteVoiceF],0 - push eax - StartMute 0 - StartMute 1 - StartMute 2 - StartMute 3 - StartMute 4 - StartMute 5 - StartMute 6 - StartMute 7 - pop eax - ret - - -%macro stim 0 -%ifdef __MSDOS__ - sti -%endif -%endmacro - -%macro ProcessIRQStuff 0 - ; check for VIRQ/HIRQ - cmp byte[virqnodisable],1 - je %%virqdo - test dl,04h - jnz %%virqdo - cmp byte[doirqnext],1 - je near .virq -%%virqdo - test byte[INTEnab],20h - jz near %%novirq - mov ax,[VIRQLoc] - add ax,[IRQHack] - cmp ax,[resolutn] - jne %%notres - dec ax -; inc ax -%%notres - cmp ax,0FFFFh - jne %%notzero - xor ax,ax -%%notzero - cmp word[curypos],ax - jne near %%noirq - test byte[INTEnab],10h - jnz %%tryhirq -%%startirq - cmp byte[intrset],1 - jne %%nointrseta - mov byte[intrset],2 -%%nointrseta - mov byte[irqon],80h - test dl,04h - jnz %%irqd - jmp .virq -%%novirq - test byte[INTEnab],10h - jz %%noirq -%%setagain - cmp byte[intrset],2 - jbe %%nointrseta3 - dec byte[intrset] - cmp byte[intrset],2 - ja %%noirq -%%nointrseta3 - cmp byte[intrset],1 - jne %%nointrseta2 - test byte[INTEnab],80h - jz %%tryhirq - mov byte[intrset],8 - jmp %%noirq -%%nointrseta2 - test dl,04h - jnz %%noirq -%%tryhirq - jmp %%startirq -%%irqd - mov byte[doirqnext],1 -%%noirq -%endmacro - - -; .returnfromsfx - -; pexecs -; *** Copy to PC whenever a non-relative jump is executed - -SECTION .data -NEWSYM romloadskip, db 0 -NEWSYM SSKeyPressed, dd 0 -NEWSYM SPCKeyPressed, dd 0 -NEWSYM NoSoundReinit, dd 0 -NEWSYM NextNGDisplay, db 0 -NEWSYM TempVidInfo, dd 0 -NEWSYM tempdh, db 0 - -SECTION .text - - -; this wonderful mess starts up the CPU and initialized the emulation state -NEWSYM start65816 - - call initvideo - - cmp byte[videotroub],1 - jne .notrouble - ret -.notrouble - - mov edi,[vidbufferofsa] - mov ecx,37518 - xor eax,eax - rep stosd - cmp byte[romloadskip],1 - je near StartGUI - -NEWSYM continueprog - ; clear keyboard presses - mov esi,pressed - mov ecx,256+128+64 - mov al,0 -.loopa - mov [esi],al - inc esi - dec ecx - jnz .loopa - - mov byte[romloadskip],0 - mov byte[debuggeron],0 - mov byte[exiter],0 - - call InitPreGame - jmp reexecute - -NEWSYM continueprognokeys - mov byte[romloadskip],0 - mov byte[debuggeron],0 - mov byte[exiter],0 - - call InitPreGame - jmp reexecuteb2 - -; Incorrect - -NEWSYM reexecuteb -%ifndef __MSDOS__ - jmp reexecuteb2 -%endif -NEWSYM reexecute - - ; clear keyboard presses - mov esi,pressed - mov ecx,256+128+64 - mov al,0 -.loopa - cmp byte[esi],2 - jne .notclear - mov [esi],al -.notclear - inc esi - dec ecx - jnz .loopa -reexecuteb2: - cmp byte[NoSoundReinit],1 - je .skippregame - call SetupPreGame -.skippregame - - ; initialize variables (Copy from variables) - call UpdateDPage - call SA1UpdateDPage - call Makemode7Table - cmp byte[SFXEnable],0 - je .nosfxud - call UpdateSFX -.nosfxud - xor eax,eax - xor ebx,ebx - xor ecx,ecx - xor edx,edx - mov bl,[xpb] - mov ax,[xpc] - test ax,8000h - jz .loweraddr - mov esi,[snesmmap+ebx*4] - jmp .skiplower -.loweraddr - cmp ax,4300h - jb .lower - cmp dword[memtabler8+ebx*4],regaccessbankr8 - je .dma -.lower - mov esi,[snesmap2+ebx*4] - jmp .skiplower -.dma - mov esi,dmadata-4300h -.skiplower - mov [initaddrl],esi - add esi,eax ; add program counter to address - mov dl,[xp] ; set flags - mov dh,[curcyc] ; set cycles - - mov bl,dl - cmp byte[spcon],0 - je .nosoundta - mov edi,[tableadc+ebx*4] - or byte[curexecstate],2 - jmp .soundta -.nosoundta - mov edi,[tableadb+ebx*4] - and byte[curexecstate],0FDh -.soundta - - mov ebp,[spcPCRam] - - mov byte[NoSoundReinit],0 - mov byte[csounddisable],0 - mov byte[NextNGDisplay],0 - - call splitflags - - call execute - - call joinflags - - ; de-init variables (copy to variables) - - mov [spcPCRam],ebp - mov [Curtableaddr],edi - mov [xp],dl - mov [curcyc],dh - - mov eax,[initaddrl] - sub esi,eax ; subtract program counter by address - mov [xpc],si - call ResetTripleBuf - - mov eax,[KeySaveState] - test byte[pressed+eax],1 - jnz .soundreinit - mov eax,[KeyLoadState] - test byte[pressed+eax],1 - jz .skipsoundreinit -.soundreinit - mov byte[NoSoundReinit],1 - mov byte[csounddisable],1 -.skipsoundreinit - - cmp byte[NoSoundReinit],1 - je .skippostgame - call DeInitPostGame -.skippostgame - - ; clear all keys - call Check_Key - cmp al,0 - je .nokeys -.yeskeys - call Get_Key - call Check_Key - cmp al,0 - jne .yeskeys -.nokeys - - cmp byte[nextmenupopup],1 - je near showmenu - cmp byte[ReturnFromSPCStall],1 - je near .activatereset - mov eax,[KeySaveState] - test byte[pressed+eax],1 - jz .nosavestt - mov byte[pressed+1],0 - mov byte[pressed+eax],2 - pushad - call statesaver - popad - jmp reexecuteb -.nosavestt - mov eax,[KeyLoadState] - test byte[pressed+eax],1 - jz .noloadstt0 - pushad - call loadstate - popad - jmp reexecuteb -.noloadstt0 - mov eax,[KeyInsrtChap] - test byte[pressed+eax],1 - jz .noinsertchapter - mov byte[pressed+eax],0 - pushad - call MovieInsertChapter - popad - jmp continueprognokeys -.noinsertchapter - mov eax,[KeyNextChap] - test byte[pressed+eax],1 - jz .nonextchapter - mov byte[pressed+eax],0 - mov byte[multchange],1 - pushad - call MovieSeekAhead - popad - jmp continueprognokeys -.nonextchapter - mov eax,[KeyPrevChap] - test byte[pressed+eax],1 - jz .noprevchapter - mov byte[pressed+eax],0 - mov byte[multchange],1 - pushad - call MovieSeekBehind - popad - jmp continueprognokeys -.noprevchapter - cmp byte[SSKeyPressed],1 - je near showmenu - cmp byte[SPCKeyPressed],1 - je near showmenu - cmp byte[debugdisble],0 - jne .nodebugger - test byte[pressed+59],1 - jne near startdebugger -.nodebugger - test byte[pressed+59],1 - jne near showmenu - mov eax,[KeyQuickRst] - test byte[pressed+eax],1 - jz .noreset -.activatereset - pushad - mov byte[GUIReset],1 - cmp byte[MovieProcessing],2 ;Recording - jne .nomovierecording - call ResetDuringMovie - jmp .movieendif -.nomovierecording - call GUIDoReset -.movieendif - popad - mov byte[ReturnFromSPCStall],0 - jmp continueprog -.noreset - cmp byte[guioff],1 - je near endprog - mov eax,[KeyQuickExit] - test byte[pressed+eax],1 - jnz near endprog - jmp StartGUI - -NEWSYM endprog - call deinitvideo - - call SaveSramData - call createnewcfg - call GUISaveVars - - pushad - call MovieStop - popad - - ; change dir to InitDrive/InitDir - mov dl,[InitDrive] - mov ebx,InitDir - call Change_Dir - - jmp DosExit - -NEWSYM interror - stim - call deinitvideo - mov edx,.nohand ;use extended - mov ah,9 ;DOS- API - call Output_Text ;to print a string - jmp DosExit - -SECTION .data -.nohand db 'Cannot process interrupt handler!',13,10,0 - -; global variables -NEWSYM invalid, db 0 -NEWSYM invopcd, db 0 -NEWSYM pressed, times 256+128+64 db 0 ; keyboard pressed keys in scancode -NEWSYM exiter, db 0 -NEWSYM oldhand9o, dd 0 -NEWSYM oldhand9s, dw 0 -NEWSYM oldhand8o, dd 0 -NEWSYM oldhand8s, dw 0 -NEWSYM opcd, dd 0 -NEWSYM pdh, dd 0 -NEWSYM pcury, dd 0 -NEWSYM timercount, dd 0 -NEWSYM initaddrl, dd 0 ; initial address location -NEWSYM NetSent, dd 0 -NEWSYM nextframe, dd 0 ; tick count for timer -NEWSYM curfps, db 0 ; frame/sec for current screen -;NEWSYM newgfxerror, db 'NEED MEMORY FOR GFX ENGINE',0 -;NEWSYM newgfxerror2, db 'NEED 320x240 FOR NEW GFX 16B',0 -;newgfxerror db 'NEW GFX IN 16BIT IS N/A',0 -NEWSYM HIRQCycNext, dd 0 -NEWSYM HIRQNextExe, db 0 - - -SECTION .text - -;******************************************************* -; Int 08h vector -;******************************************************* - -; sets to either 60Hz or 50Hz depending on PAL/NTSC -NEWSYM init60hz - cmp byte[romispal],0 - jne .dopal - mov al,00110110b - out 43h,al - mov ax,19900 ; 65536/(60/((65536*24+175)/(60*60*24))) - mov dword[timercount],19900 - out 40h,al - mov al,ah - out 40h,al - ret -.dopal - mov al,00110110b - out 43h,al - mov ax,23863 ; 65536/(50/((65536*24+175)/(60*60*24))) - mov dword[timercount],23863 - out 40h,al - mov al,ah - out 40h,al - ret - -NEWSYM init18_2hz - mov al,00110110b - out 43h,al - mov ax,0 - mov dword[timercount],65536 - out 40h,al - mov al,ah - out 40h,al - ret - -%ifdef __MSDOS__ -NEWSYM handler8h - cli - push ds - push eax -; mov ax,0 - mov ax,[cs:dssel] -NEWSYM handler8hseg - mov ds,ax - call Game60hzcall - mov eax,[timercount] - sub dword[timeradj],eax - jnc .noupd - add dword[timeradj],65536 - pushf - call far [oldhand8o] -.noupd - mov al,20h - out 20h,al - pop eax - pop ds - sti - iretd -%endif - -SECTION .data -NEWSYM timeradj, dd 65536 -NEWSYM t1cc, dw 0 -SECTION .text - -;******************************************************* -; Int 09h vector -;******************************************************* - -%ifdef __MSDOS__ -SECTION .bss -NEWSYM skipnextkey42, resb 1 -SECTION .text - -NEWSYM handler9h - cli - push ds - push eax - push ebx - mov ax,[cs:dssel] - mov ds,ax - xor ebx,ebx - in al,60h ; get keyboard scan code - cmp al,42 - jne .no42 - cmp byte[skipnextkey42],0 - je .no42 - mov byte[skipnextkey42],0 - jmp .skipkeyrel -.no42 - cmp al,0E0h - jne .noE0 - mov byte[skipnextkey42],1 - jmp .skipkeyrel -.noE0 - mov byte[skipnextkey42],0 - mov bl,al - xor bh,bh - test bl,80h ; check if bit 7 is on (key released) - jnz .keyrel - cmp byte[pressed+ebx],0 - jne .skipa - mov byte[pressed+ebx],1 ; if not, set key to pressed -.skipa - jmp .skipkeyrel -.keyrel - and ebx,7Fh - cmp ebx,59 - je .skipkeyrel - cmp ebx,[KeySaveState] - je .skipkeyrel - cmp ebx,[KeyLoadState] - je .skipkeyrel - cmp ebx,[KeyQuickExit] - je .skipkeyrel - cmp ebx,[KeyQuickLoad] - je .skipkeyrel - cmp ebx,[KeyQuickRst] - je .skipkeyrel - cmp bl,1 - je .skipkeyrel - mov byte[pressed+ebx],0 ; if not, set key to pressed -.skipkeyrel - mov byte[pressed],0 - in al,61h - mov ah,al - or al,80h - out 61h,al - mov al,20h ; turn off interrupt mode - out 20h,al - pop ebx ; Pop registers off - pop eax ; stack in correct - pop ds - sti - iretd -%endif - -SECTION .data -ALIGN32 -NEWSYM soundcycleft, dd 0 -NEWSYM curexecstate, dd 0 - -NEWSYM nmiprevaddrl, dd 0 ; observed address -5 -NEWSYM nmiprevaddrh, dd 0 ; observed address +5 -NEWSYM nmirept, dd 0 ; NMI repeat check, if 6 then okay -NEWSYM nmiprevline, dd 224 ; previous line -NEWSYM nmistatus, dd 0 ; 0 = none, 1 = waiting for nmi location, - ; 2 = found, disable at next line -NEWSYM joycontren, dd 0 ; joystick read control check -NEWSYM NextLineCache, db 0 -NEWSYM ZMVZClose, db 0 - -SECTION .text - -Donextlinecache: - cmp word[curypos],0 - je .nocache - mov ax,[resolutn] - dec ax - cmp word[curypos],ax - jae .nocache - test byte[scrndis],10h - jnz .nocache - cmp byte[curblank],0h - jne .nocache - push ecx - push ebx - push esi - push edi - xor ecx,ecx - mov cl,[curypos] - push edx -.next - mov byte[sprlefttot+ecx],0 - mov dword[sprleftpr+ecx*4],0 - inc cl - jnz .next - call processsprites - call cachesprites - pop edx - pop edi - pop esi - pop ebx - pop ecx -.nocache - mov byte[NextLineCache],0 - ret - -;******************************************************* -; 65816 execution -;******************************************************* - -SECTION .data - -SpeedHackSafeTable: - db 1,0,1,0,0,0,1,0,1,0,1,1,0,0,0,0 - db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 - db 0,0,0,0,0,0,1,0,1,0,1,1,0,0,1,0 - db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 - db 0,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1 - db 0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0 - db 0,1,0,1,0,1,1,1,0,1,1,0,0,1,1,1 - db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 - db 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 - db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - db 0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0 - db 0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0 - db 0,1,0,1,0,1,1,1,1,1,0,0,0,1,1,1 - db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 -SECTION .text - -NEWSYM exitloop2 - mov byte[ExecExitOkay],0 -NEWSYM exitloop - ret - -ALIGN16 - -%macro FlipCheck 0 - cmp byte[FlipWait],0 - je %%noflip - push edx - push eax - mov dx,3DAh ;VGA status port - in al,dx - test al,8 - jz %%skipflip - push ebx - push ecx - mov ax,4F07h - mov bh,00h - mov bl,00h - xor cx,cx - mov dx,[NextLineStart] - mov [LastLineStart],dx - int 10h - mov byte[FlipWait],0 - pop ecx - pop ebx -%%skipflip - pop eax - pop edx -%%noflip -%endmacro - -NEWSYM execute -NEWSYM execloop - mov bl,dl - test byte[curexecstate],2 - jnz .sound - mov edi,[tableadb+ebx*4] - mov bl,[esi] - inc esi - sub dh,[cpucycle+ebx] - jc .cpuover -.startagain - call dword near [edi+ebx*4] -.cpuover - jmp cpuover -.sound - mov edi,[tableadc+ebx*4] -%ifdef OPENSPC - pushad - mov bl,[esi] - movzx eax,byte[cpucycle+ebx] - mov ebx,0xC3A13DE6 - mul ebx - add [ospc_cycle_frac],eax - adc [SPC_Cycles],edx - call OSPC_Run - popad -%else - sub dword[cycpbl],55 - jnc .skipallspc - mov eax,[cycpblt] - mov bl,[ebp] - add dword[cycpbl],eax - ; 1260, 10000/12625 - inc ebp - call dword near [opcjmptab+ebx*4] - xor ebx,ebx -.skipallspc -%endif - mov bl,[esi] - inc esi - sub dh,[cpucycle+ebx] - jc .cpuovers - call dword near [edi+ebx*4] -.cpuovers - jmp cpuover - - - -SECTION .data -ALIGN32 -NEWSYM ExecExitOkay, db 1 -NEWSYM JoyABack, dd 0 -NEWSYM JoyBBack, dd 0 -NEWSYM JoyCBack, dd 0 -NEWSYM JoyDBack, dd 0 -NEWSYM JoyEBack, dd 0 -NEWSYM NetCommand, dd 0 -NEWSYM spc700read, dd 0 -NEWSYM lowestspc, dd 0 -NEWSYM highestspc, dd 0 -NEWSYM SA1UBound, dd 0 -NEWSYM SA1LBound, dd 0 -NEWSYM SA1SH, dd 0 -NEWSYM SA1SHb, dd 0 -NEWSYM NumberOfOpcodes2, dd 0 -NEWSYM ChangeOps, dd 0 -NEWSYM SFXProc, dd 0 -NEWSYM EMUPause, db 0 -NEWSYM INCRFrame, db 0 -SECTION .text - -NEWSYM cpuover - dec esi - cmp byte[HIRQNextExe],0 - je .nohirq - add dh,[HIRQCycNext] - mov byte[HIRQCycNext],0 - jmp .hirq -.nohirq - cmp byte[SA1Enable],0 - je near .nosa1b - test byte[exiter],01h - jnz near .nosa1 - mov byte[cycpl],150 - test byte[SA1Control],60h - jnz near .nosa1 - call SA1Swap - cmp byte[CurrentExecSA1],15 - ja .nocontinueexec - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain -.nocontinueexec - - ; check for sa-1 speed hacks - mov byte[SA1SHb],0 - cmp word[IRAM+0A0h],80BFh - jne .noshb2 - cmp word[IRAM+020h],0 - jne .noshb2 - mov ecx,[SA1Ptr] ; small speed hack - sub ecx,[romdata] - cmp ecx,83h - jb .skipsh - cmp ecx,97h - ja .skipsh - mov byte[SA1SHb],1 -.skipsh -.noshb2 - - mov ecx,[SA1Ptr] ; small speed hack - cmp dword[ecx],0FCF04BA5h - je .shm - cmp dword[ecx-2],0FCF04BA5h - jne .skipshm -.shm - cmp byte[IRAM+4Bh],0 - jne .skipshm - mov byte[SA1SHb],1 -.skipshm - - cmp dword[ecx],80602EEEh - jne .skipshc - sub ecx,[romdata] - cmp ecx,4E5h - jb .skipshc - cmp ecx,4E8h - ja .skipshc - mov byte[SA1SHb],1 - mov ecx,[SA1BWPtr] - add word[ecx+602Eh],4 -.skipshc - - test word[IRAM+0Ah],8000h - jnz .noshb2b - test word[IRAM+0Eh],8000h - jz .noshb2b - mov ecx,[SA1Ptr] ; small speed hack - sub ecx,[romdata] - cmp ecx,0C93h - jb .skipshb - cmp ecx,0C9Bh - ja .skipshb - mov byte[SA1SHb],1 -.skipshb - cmp ecx,0CB8h - jb .skipshb3 - cmp ecx,0CC0h - ja .skipshb3 - mov byte[SA1SHb],1 -.skipshb3 -.noshb2b - - sub esi,[wramdata] - cmp esi,224h - jb .nosh - cmp esi,22Eh - ja .nosh - mov ecx,[wramdata] - mov dword[SA1LBound],224h - mov dword[SA1UBound],22Eh - add dword[SA1LBound],ecx - add dword[SA1UBound],ecx - mov byte[SA1SH],1 -.nosh - cmp esi,1F7C6h - jb .noshb - cmp esi,1F7CCh - ja .noshb - mov ecx,[wramdata] - mov dword[SA1LBound],1F7C6h - mov dword[SA1UBound],1F7CCh - add dword[SA1LBound],ecx - add dword[SA1UBound],ecx - mov byte[SA1SH],1 -.noshb - cmp esi,14h - jb .noshc - cmp esi,1Ch - ja .noshc - mov ecx,[wramdata] - cmp dword[ecx+14h],0F023002Ch - jne .noshc - mov dword[SA1LBound],14h - mov dword[SA1UBound],1Ch - add dword[SA1LBound],ecx - add dword[SA1UBound],ecx - mov byte[SA1SH],1 -.noshc - add esi,[wramdata] - sub esi,[romdata] - cmp esi,0A56h - jb .noshbc - cmp esi,0A59h - ja .noshbc - mov ecx,[romdata] - mov dword[SA1LBound],0A56h - mov dword[SA1UBound],0A59h - add dword[SA1LBound],ecx - add dword[SA1UBound],ecx - mov byte[SA1SH],1 -.noshbc - xor ecx,ecx - add esi,[romdata] - xor dh,dh - mov byte[cycpl],10 - cmp byte[CurrentExecSA1],255 - jne .notsa1255 - mov byte[cycpl],160 -.notsa1255 - mov byte[CurrentExecSA1],0 - test dl,04h - jnz .nosa1 - test byte[SA1IRQEnable],80h - jz .nosa1 - test byte[SA1DoIRQ],4 - jz .nosa1 - and byte[SA1DoIRQ],0FBh - mov al,[SA1Message+1] - mov [SA1Message+3],al - or byte[SA1IRQExec],1 - ; Start IRQ - add dh,10 - jmp .virq -.nosa1 - test byte[SA1IRQEnable],20h - jz .nosa1chirq - test byte[SA1DoIRQ],8 - jz .nosa1chirq -; jmp .nosa1chirq - and byte[SA1DoIRQ],0F7h - mov al,[SA1Message+1] - mov [SA1Message+3],al - or byte[SA1IRQExec],2 - ; Start IRQ - add dh,10 - jmp .virq -.nosa1chirq -.nosa1b - FlipCheck - cmp byte[NextLineCache],0 - je .nosprcache - call Donextlinecache -.nosprcache - cmp byte[KeyOnStB],0 - je .nokeyon - mov al,[KeyOnStB] - call ProcessKeyOn -.nokeyon - mov al,[KeyOnStA] - mov [KeyOnStB],al - mov byte[KeyOnStA],0 - test byte[exiter],01h - jnz near exitloop2 - - test byte[SfxSFR],20h - jnz near StartSFX -.returnfromsfx -; inc dword[numinst] ;Temporary - inc word[curypos] - add dh,[cycpl] - mov ax,[totlines] - cmp word[curypos],ax - jae near .overy - cmp byte[spcon],0 - je .nosound - call updatetimer -.nosound - mov ax,[resolutn] - inc ax - cmp [curypos],ax - je near .nmi - - mov ax,[resolutn] - cmp [curypos],ax - je near .hdma -; add ax,2 -; cmp [curypos],ax -; je near .hdma -.hdmacont - - cmp byte[curypos],100 - jne .noline100 - mov ax,[scrnon] - mov [TempVidInfo],ax - mov ax,[scaddset] - mov [TempVidInfo+2],ax -.noline100 - - ; check for VIRQ/HIRQ/NMI - ProcessIRQStuff - mov ax,[resolutn] - dec ax - cmp [curypos],ax - jb .drawline - - -; mov ax,[resolutn] -; cmp [curypos],ax -; jb .drawline - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain - -.hdma - call exechdma - jmp .hdmacont - -.drawline - mov al,[nmiprevline] - cmp [curypos],al - jb near .noskip - cmp byte[nmirept],10 - jb near .noskip - ; if between correct address, decrease by 2, set nmistatus as 2 - ; if not, set nmistatus as 1, increase by 2 - cmp byte[curexecstate],0 - jne .nn - xor dh,dh -.nn - cmp byte[nmistatus],2 - jae near .noskip - cmp esi,[nmiprevaddrl] - jb .failcheck2 - cmp esi,[nmiprevaddrh] - ja .failcheck2 - cmp byte[nmiprevline],20 - jb .nodec - sub byte[nmiprevline],10 -.nodec - xor eax,eax - mov al,[esi] - cmp byte[disable65816sh],1 - je .ohno - cmp byte[SpeedHackSafeTable+eax],1 - jne .okay -.ohno - mov byte[nmirept],0 - mov dword[nmiprevaddrl],0FFFFFFFFh - mov dword[nmiprevaddrh],0 - jmp .noskip -.okay - mov byte[nmistatus],2 - and byte[curexecstate],0FEh -.nodis65816 - jmp .noskip -.failcheck2 - add byte[nmiprevline],1 - mov byte[nmistatus],1 -.noskip - cmp byte[hdmadelay],0 - je .dohdma - dec byte[hdmadelay] - jmp .nodohdma -.dohdma - cmp word[curypos],1 - jne .nooffby1line - test byte[INTEnab],20h - jz .nooffby1line - cmp word[VIRQLoc],0 - je .nodohdma -.nooffby1line - call exechdma -.nodohdma - cmp word[curypos],1 - jne .nocache - call cachevideo -.nocache - cmp byte[curblank],0 - jne .nodrawlineb2 - call drawline -.nodrawlineb2 - cmp byte[curexecstate],2 - je near pexecs - cmp byte[curexecstate],0 - jne .yesexec - xor dh,dh -.yesexec - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain - -.nmi - mov byte[irqon],80h - mov byte[doirqnext],0 - cmp byte[yesoutofmemory],1 - jne .noout - call outofmemfix -.noout - - dec word[curypos] - mov [tempdh],dh - xor dh,dh - -; mov al,[SFXIRQFlag] - mov byte[doirqnext],0 - - call exechdma - call exechdma - - mov byte[NextNGDisplay],1 - cmp byte[newengen],0 - je .nonewgfx - cmp byte[curblank],0 - jne .nonewgfx - cmp byte[ForceNewGfxOff],0 - jne .nonewgfx -; cmp byte[NextNGDisplay],0 -; je .nonewgfx - call StartDrawNewGfx -.nonewgfx - cmp byte[GUIQuit],1 - je near endprog - mov eax,[KeyQuickSnapShot] - or eax,eax - jz .nosskey - test byte[pressed+eax],1 - jz .nosskey - mov byte[SSKeyPressed],1 - mov byte[pressed+eax],2 - jmp exitloop -.nosskey - mov eax,[KeyQuickClock] - or eax,eax - jz .noclockkey - test byte[pressed+eax],1 - jz .noclockkey - xor byte[TimerEnable],1 - mov byte[pressed+eax],2 -.noclockkey - mov eax,[KeyQuickSaveSPC] - or eax,eax - jz .nosavespckey - test byte[pressed+eax],1 - jz .nosavespckey - mov byte[SPCKeyPressed],1 - mov byte[pressed+eax],2 - jmp exitloop -.nosavespckey - mov eax,[EMUPauseKey] - or eax,eax - jz .nopausekey - test byte[pressed+eax],1 - jz .nopausekey - xor byte[EMUPause],1 - mov byte[pressed+eax],2 -.nopausekey - mov eax,[INCRFrameKey] - or eax,eax - jz .noincrframekey - test byte[pressed+eax],1 - jz .noincrframekey - xor byte[INCRFrame],1 - mov byte[pressed+eax],2 -.noincrframekey - test byte[pressed+1],01h - jnz near exitloop - test byte[pressed+59],01h - jnz near exitloop - cmp byte[nextmenupopup],1 - je near exitloop - cmp byte[nextmenupopup],2 - jb .skipmenupop - dec byte[nextmenupopup] -.skipmenupop - mov eax,[KeySaveState] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyLoadState] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyInsrtChap] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyPrevChap] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyNextChap] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyQuickRst] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyQuickExit] - test byte[pressed+eax],01h - jnz near exitloop - mov eax,[KeyQuickLoad] - test byte[pressed+eax],01h - jnz near exitloop - cmp byte[ExecExitOkay],0 - je .returntoloop - dec byte[ExecExitOkay] -.returntoloop - mov dh,[tempdh] - inc word[curypos] - cmp byte[NoInputRead],1 - je .noinputread - call ReadInputDevice -.noinputread - - ;Pause and Frame increment - cmp byte[PauseFrameMode],3 - jne .nopauseframemode3 - pushad - call RestorePauseFrame - popad - mov esi,[tempesi] - mov edi,[tempedi] - mov ebp,[tempebp] - mov edx,[tempedx] -.nopauseframemode3 - - cmp byte[EMUPause],1 - jne .noemupause - - cmp byte[PauseFrameMode],1 - jne .nopauseframemode1 - mov [tempedx],edx - mov [tempesi],esi - mov [tempedi],edi - mov [tempebp],ebp - pushad - call BackupPauseFrame - popad -.nopauseframemode1 - - call ProcessRewind - - cmp byte[PauseFrameMode],2 - jne .nopauseframemode2 - mov byte[PauseFrameMode],3 - jmp .noprocmovie -.nopauseframemode2 - - cmp byte[INCRFrame],1 - jne .noframeincr - xor byte[INCRFrame],1 - jmp .noemupause -.noframeincr - - ;Update screen - DISABLED FOR NOW - pushad - ;call StartDrawNewGfx - ;call showvideo - ;call cachevideo - popad - - jmp .nonewgfx -.noemupause - - ;Rewind update must be done before process this frame of movie, so rewind doesn't - ;back up incremented values (some vars being for the next frame) - call UpdateRewind - - cmp byte[MovieProcessing],0 - je .noprocmovie - pushad - call ProcessMovies - popad - cmp byte[GUIReset],1 - jne .notreset - mov byte[MovieWaiting],1 - mov eax,[KeyQuickRst] - mov byte[pressed+eax],01h - jmp near exitloop -.notreset - cmp byte[MovieProcessing],0 - jne .noprocmovie - cmp byte[ZMVZClose],1 - jne .noprocmovie - jmp DosExit -.noprocmovie - - cmp byte[snesmouse],4 - jne .nolethalen - mov eax,[LethEnData] - mov [JoyBNow],eax -.nolethalen - - test byte[INTEnab],1 - jz .noresetjoy - mov eax,[JoyAOrig] - rol eax,16 - mov [JoyANow],eax - mov eax,[JoyBOrig] - rol eax,16 - mov [JoyBNow],eax - mov eax,[JoyCOrig] - rol eax,16 - mov [JoyCNow],eax - mov eax,[JoyDOrig] - mov [JoyDNow],eax - mov eax,[JoyEOrig] - mov [JoyENow],eax - mov byte[JoyCRead],0 -.noresetjoy - mov byte[MultiTapStat],80h - - cmp byte[C4Enable],0 - je .noC4 - call C4VBlank -.noC4 -; mov byte[hdmastartsc],0 - mov byte[joycontren],0 - test byte[curexecstate],01h - jnz .dis65816 - or byte[curexecstate],01h -.dis65816 - cmp byte[CheatOn],1 - je near .cheater -.returncheat - mov ax,[VIRQLoc] - cmp word[curypos],ax - jne .novirqz - mov byte[doirqnext],1 -.novirqz - mov ax,[oamaddrs] - mov [oamaddr],ax - mov byte[nosprincr],0 - call showvideo - xor ebx,ebx - mov byte[NMIEnab],81h - test byte[INTEnab],80h - jz near .nonmi -; cmp byte[intrset],1 -; je near .nonmi - -.nmiokay - mov byte[curnmi],1 - cmp byte[intrset],1 - jne .nointrset - mov byte[intrset],2 -.nointrset - cmp byte[nmistatus],1 - jne .notnonmifound - mov byte[nmirept],0 -.notnonmifound - mov byte[nmistatus],0 - cmp byte[nmirept],0 - jne .nocheck - mov al,[resolutn] - sub al,2 - mov [nmiprevline],al - mov dword[nmiprevaddrl],0FFFFFFFFh - mov dword[nmiprevaddrh],0 - mov byte[nmirept],1 - mov byte[doirqnext],0 - jmp switchtonmi -.nocheck - cmp byte[nmirept],10 - je .nextcheck - cmp esi,[nmiprevaddrl] - jae .notlower - mov [nmiprevaddrl],esi -.notlower - cmp esi,[nmiprevaddrh] - jbe .notgreater - mov [nmiprevaddrh],esi -.notgreater - inc byte[nmirept] - jmp switchtonmi -.nextcheck - mov eax,[nmiprevaddrh] - sub eax,[nmiprevaddrl] - cmp eax,10 - ja .failcheck - cmp esi,[nmiprevaddrl] - jb .failcheck - cmp esi,[nmiprevaddrh] - ja .failcheck - mov byte[doirqnext],0 - jmp switchtonmi -.failcheck - mov byte[nmirept],0 - mov dword[nmiprevaddrl],0FFFFFFFFh - mov dword[nmiprevaddrh],0 - mov byte[doirqnext],0 - jmp switchtonmi -.nonmi - cmp byte[intrset],1 - jne .nointrset2w - mov byte[intrset],2 -.nointrset2w - xor ebx,ebx - xor ecx,ecx - mov bl,[esi] - inc esi - jmp execloop.startagain - - -.overy - sub dh,110 - cmp byte[smallscreenon],1 - je .nocfield - cmp byte[ScreenScale],1 - je .nocfield - cmp byte[scanlines],0 - jne .nocfield - xor byte[cfield],1 -.nocfield - mov word[curypos],0 - xor byte[ppustatus],80h - cmp dword[numspcvblleft],0 - je near .novblch - cmp [lowestspc],ebp - ja .failspc - cmp [highestspc],ebp - jb .failspc - jmp .okayspc -.failspc - mov eax,ebp - sub eax,10 - mov [lowestspc],eax - add eax,20 - mov [highestspc],eax - mov dword[spc700idle],0 -.okayspc - cmp dword[SPC700write],0 - jne .notwritespc - cmp dword[spc700read],0 - je .notwritespc - cmp dword[SPC700read],1500 - jb .notwritespc - inc dword[spc700idle] - cmp dword[spc700idle],30 - jne .noidleend - call idledetectspc - cmp byte[ReturnFromSPCStall],1 - jne .noidleend - mov byte[ExecExitOkay],0 - jmp exitloop -.noidleend - jmp .notidle -.notwritespc - mov dword[spc700idle],0 -.notidle - dec dword[numspcvblleft] - mov dword[SPC700write],0 - mov dword[SPC700read],0 - mov dword[spc700read],0 -.novblch - mov byte[NMIEnab],01h - call starthdma -.noirqhack - ; check for VIRQ/HIRQ/NMI - ProcessIRQStuff - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain - -.virq - test byte[curexecstate],01h - jnz .dis658162 - or byte[curexecstate],01h -.dis658162 - mov byte[doirqnext],0 - xor ebx,ebx - mov ax,[resolutn] - cmp word[curypos],ax - jnb .nodrawline - cmp byte[hdmadelay],1 - jne .virqstuff -.virqstuff - cmp byte[hdmadelay],0 - je .dohdma2 - dec byte[hdmadelay] - jmp .nodohdma2 -.dohdma2 - call exechdma -.nodohdma2 - cmp word[curypos],1 - jne .nocache2 - call cachevideo -.nocache2 - cmp byte[curblank],0 - jne .nodrawline - call drawline -.nodrawline - cmp byte[intrset],1 - jne .nointrset2 - mov byte[intrset],2 -.nointrset2 -; sub dh,8 - jmp switchtovirq - -.hirq - mov byte[HIRQNextExe],0 - test byte[INTEnab],10h - jz .hirqnotokay - test byte[curexecstate],01h - jnz .dis658162h - or byte[curexecstate],01h -.dis658162h - mov byte[doirqnext],0 - cmp byte[intrset],1 - jne .nointrset2h - mov byte[intrset],2 -.nointrset2h - test dl,04h - jnz .irqd - jmp switchtovirq -.irqd - mov byte[doirqnext],1 -.hirqnotokay - jmp .nodrawlineh - -.returnfromhirq - mov ax,[resolutn] - cmp word[curypos],ax - jnb .nodrawlineh - cmp byte[hdmadelay],0 - je .dohdma2h - dec byte[hdmadelay] - jmp .nodohdma2h -.dohdma2h - call exechdma -.nodohdma2h - cmp word[curypos],1 - jne .nocache2h - call cachevideo -.nocache2h - cmp byte[curblank],0 - jne .nodrawlineh - call drawline -.nodrawlineh - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain - -.cheater - push eax - push ebx - push ecx - push edx - mov al,[NumCheats] - mov [.numcheat],al - xor edx,edx -.anothercheat - xor ebx,ebx - xor ecx,ecx - test byte[cheatdata+edx],5 - jnz .nonormcheat - test byte[cheatdata+edx-28],80h - jnz .nonormcheat - test byte[cheatdata+edx],80h - jnz .cheatcodereflect - mov al,[cheatdata+edx+1] - mov cx,[cheatdata+edx+2] - mov bl,[cheatdata+edx+4] - push edx - call dword near [memtablew8+ebx*4] - pop edx - jmp .nonormcheat -.cheatcodereflect - cmp byte[.numcheat],1 - je .nonormcheat - mov cx,[cheatdata+edx+2+28] - mov bl,[cheatdata+edx+4+28] - push edx - call dword near [memtabler8+ebx*4] - pop edx - mov cx,[cheatdata+edx+2] - mov bl,[cheatdata+edx+4] - push edx - call dword near [memtablew8+ebx*4] - pop edx - add edx,28 - dec byte[.numcheat] -.nonormcheat - add edx,28 - dec byte[.numcheat] - jnz near .anothercheat - pop edx - pop ecx - pop ebx - pop eax - jmp .returncheat - -SECTION .bss -.numcheat resb 1 -SECTION .text - -ALIGN16 - -NEWSYM pexecs - mov byte[soundcycleft],30 -.sloop - mov bl,[ebp] - ; 1260, 10000/12625 - inc ebp - call dword near [opcjmptab+ebx*4] - xor ebx,ebx - dec byte[soundcycleft] - jnz .sloop - xor dh,dh - xor ebx,ebx - mov bl,[esi] - inc esi - jmp execloop.startagain - -NEWSYM pexecs2 -.sloop - mov bl,[ebp] - ; 1260, 10000/12625 - inc ebp - call dword near [opcjmptab+ebx*4] - xor ebx,ebx - dec dword[soundcycleft] - jnz .sloop - ret - -NEWSYM UpdatePORSCMR - push ebx - push eax - test byte[SfxPOR],10h - jnz .objmode - mov al,[SfxSCMR] - and al,00100100b ; 4 + 32 - cmp al,4 - je .lines160 - cmp al,32 - je .lines192 - cmp al,36 - je .objmode - mov eax,[sfx128lineloc] - jmp .donelines -.lines160 - mov eax,[sfx160lineloc] - jmp .donelines -.lines192 - mov eax,[sfx192lineloc] - jmp .donelines -.objmode - mov eax,[sfxobjlineloc] -.donelines - mov [sfxclineloc],eax - - mov al,[SfxSCMR] - and eax,00000011b - mov bl,[SfxPOR] - and bl,0Fh - shl bl,2 - or al,bl - mov ebx,[PLOTJmpb+eax*4] - mov eax,[PLOTJmpa+eax*4] - mov [FxTable+4Ch*4],eax - mov [FxTableb+4Ch*4],eax - mov [FxTablec+4Ch*4],eax - mov [FxTabled+4Ch*4],ebx - pop eax - pop ebx - ret - -NEWSYM UpdateSCBRCOLR - push eax - push ebx - mov ebx,[SfxSCBR] - shl ebx,10 - add ebx,[sfxramdata] - mov [SCBRrel],ebx - mov eax,[SfxCOLR] - mov ebx,[fxbit01+eax*4] - mov [fxbit01pcal],ebx - mov ebx,[fxbit23+eax*4] - mov [fxbit23pcal],ebx - mov ebx,[fxbit45+eax*4] - mov [fxbit45pcal],ebx - mov ebx,[fxbit67+eax*4] - mov [fxbit67pcal],ebx - pop ebx - pop eax - ret - -NEWSYM UpdateCLSR - mov dword[NumberOfOpcodes2],350 ; 0FFFFFFFh;350 - test byte[SfxCLSR],01h - jz .nohighsfx - mov dword[NumberOfOpcodes2],700 ;700 -.nohighsfx - cmp byte[SFXCounter],1 - je .noyi - mov dword[NumberOfOpcodes2],0FFFFFFFh -.noyi - ret - -NEWSYM UpdateSFX - call UpdatePORSCMR - call UpdatePORSCMR - call UpdateCLSR - ret - -NEWSYM StartSFX - push edx - push esi - push edi - push ebp - xor ebx,ebx - mov bl,[SfxPBR] - mov al,[SfxSCMR] - and bl,7Fh - cmp bl,70h - jae .ram - test al,10h - jz .noaccess - jmp .noram -.ram - test al,08h - jz .noaccess -.noram - mov eax,[NumberOfOpcodes2] - mov [NumberOfOpcodes],eax - call MainLoop -.noaccess - pop ebp - pop edi - pop esi - pop edx - xor ebx,ebx - xor ecx,ecx - jmp cpuover.returnfromsfx - -NEWSYM StartSFXdebug - push edx - push esi - push edi - push ebx - mov bl,[SfxPBR] - mov al,[SfxSCMR] - and bl,7Fh - cmp bl,70h - jae .ram - test al,10h - jz .noaccess - jmp .noram -.ram - test al,08h - jz .noaccess -.noram - mov dword[NumberOfOpcodes],350 ; 0FFFFFFFh;350 - test byte[SfxCLSR],01h - jz .nohighsfx - mov dword[NumberOfOpcodes],700 ;700 -.nohighsfx - cmp byte[SFXCounter],1 - jne .noyi - mov dword[NumberOfOpcodes],0FFFFFFFFh -.noyi -; call SFXDebugLoop -.noaccess - pop ebx - pop edi - pop esi - pop edx - xor ecx,ecx - jmp execsingle.returnfromsfx - -NEWSYM StartSFXdebugb - push edx - push esi - push edi - push ebp - push ebx - - test byte[SfxPOR],10h - jnz .objmode - mov al,[SfxSCMR] - and al,00100100b ; 4 + 32 - cmp al,4 - je .lines160 - cmp al,32 - je .lines192 - cmp al,36 - je .objmode - mov eax,[sfx128lineloc] - jmp .donelines -.lines160 - mov eax,[sfx160lineloc] - jmp .donelines -.lines192 - mov eax,[sfx192lineloc] - jmp .donelines -.objmode - mov eax,[sfxobjlineloc] -.donelines - mov [sfxclineloc],eax - - mov al,[SfxSCMR] - and eax,00000011b - mov bl,[SfxPOR] - and bl,0Fh - shl bl,2 - or al,bl - mov ebx,[PLOTJmpb+eax*4] - mov eax,[PLOTJmpa+eax*4] - mov [FxTable+4Ch*4],eax - mov [FxTableb+4Ch*4],eax - mov [FxTablec+4Ch*4],eax - mov [FxTabled+4Ch*4],ebx - - mov ebx,[SfxSCBR] - shl ebx,10 - add ebx,[sfxramdata] - mov [SCBRrel],ebx - - mov eax,[SfxCOLR] - mov ebx,[fxbit01+eax*4] - mov [fxbit01pcal],ebx - mov ebx,[fxbit23+eax*4] - mov [fxbit23pcal],ebx - mov ebx,[fxbit45+eax*4] - mov [fxbit45pcal],ebx - mov ebx,[fxbit67+eax*4] - mov [fxbit67pcal],ebx - xor ebx,ebx - - mov bl,[SfxPBR] - mov al,[SfxSCMR] - and bl,7Fh - cmp bl,70h - jae .ram - test al,10h - jz .noaccess - jmp .noram -.ram - test al,08h - jz .noaccess -.noram - mov dword[NumberOfOpcodes],400 ;678 - test byte[SfxCLSR],01h - jz .nohighsfx - mov dword[NumberOfOpcodes],800 ;678*2 -.nohighsfx - cmp byte[SFXCounter],1 - jne .noyi - mov dword[NumberOfOpcodes],0FFFFFFFh -.noyi - call MainLoop -.noaccess - pop ebx - pop ebp - pop edi - pop esi - pop edx - xor ecx,ecx - jmp execsingle.returnfromsfx - -NEWSYM StartSFXret - test byte[SfxSFR],20h - jz .endfx - pushad - mov bl,[SfxPBR] - mov al,[SfxSCMR] - and bl,7Fh - cmp bl,70h - jae .ram - test al,10h - jz .noaccess - jmp .noram -.ram - test al,08h - jz .noaccess -.noram - mov dword[NumberOfOpcodes],400 ;678 - test byte[SfxCLSR],01h - jz .nohighsfx - mov dword[NumberOfOpcodes],800 ;678*2 -.nohighsfx - mov dword[NumberOfOpcodes],0FFFFFFFFh - call MainLoop -.noaccess - popad -.endfx - ret - -;******************************************************* -; Execute a Single 65816 instruction (debugging purpose) -;******************************************************* -NEWSYM execloopdeb - jmp exitloop2 - -NEWSYM execsingle - - xor ebx,ebx - test byte[curexecstate],2 - jz .nosoundb - sub dword[cycpbl],55 - jnc .skipallspc - mov eax,[cycpblt] - mov bl,[ebp] - add dword[cycpbl],eax - ; 1260, 10000/12625 - inc ebp - call dword near [opcjmptab+ebx*4] - xor ebx,ebx -.skipallspc -.nosoundb - - mov bl,dl - mov byte[exiter],01h - mov edi,[tablead+ebx*4] - mov bl,[esi] - inc esi - sub dh,[cpucycle+ebx] - jc .cpuover - mov [pdh],dh - xor dh,dh - jmp dword near [edi+ebx*4] -.cpuover - - cmp byte[SA1Enable],0 - je near .nosa1 - mov byte[cycpl],150 - test byte[SA1Control],60h - jnz near .nosa1 - dec esi - call SA1Swap - - mov bl,[esi] - inc esi - mov [pdh],dh - xor dh,dh - cmp byte[CurrentExecSA1],17 - jb near cpuover - mov byte[CurrentExecSA1],0 - mov byte[cycpl],5 - jmp .nosa1 -.nosa1 - - cmp byte[KeyOnStB],0 - je .nokeyon - mov al,[KeyOnStB] - call ProcessKeyOn -.nokeyon - mov al,[KeyOnStA] - mov [KeyOnStB],al - mov byte[KeyOnStA],0 - test byte[SfxSFR],20h - jnz near StartSFXdebugb -.returnfromsfx - add dh,[cycpl] - mov [pdh],dh - - cmp byte[spcon],0 - je .nosound - call updatetimer - push ebx - xor ebx,ebx - mov bl,dl - mov edi,[tablead+ebx*4] - pop ebx -.nosound - xor dh,dh - inc word[curypos] - mov ax,[resolutn] - inc ax - cmp word[curypos],ax - je near .nmi - mov ax,[totlines] - cmp word[curypos],ax - jae near .overy - ; check for VIRQ/HIRQ/NMI - ProcessIRQStuff - -; test dl,04h -; jnz .noirq -; test byte[INTEnab],20h -; jz .novirq -; mov ax,[VIRQLoc] -; cmp word[curypos],ax -; je near .virq -; jmp .noirq -;.novirq -; test byte[INTEnab],10h -; jnz near .virq -;.noirq -; test byte[INTEnab],20h -; jz .novirq2b -; mov ax,[VIRQLoc] -; cmp word[curypos],ax -; jne .novirq2b -; cmp byte[intrset],1 -; jne .nointrset2b -; mov byte[intrset],2 -;.nointrset2b -;.novirq2b - mov ax,[resolutn] - cmp word[curypos],ax - jb .drawline - jmp dword near [edi+ebx*4] - -.drawline - cmp byte[hdmadelay],0 - je .dohdma - dec byte[hdmadelay] - jmp .nodohdma -.dohdma - call exechdma -.nodohdma - cmp byte[curblank],0 - jne .nodrawlineb - call drawline -.nodrawlineb - jmp dword near [edi+ebx*4] - -.nmi - mov byte[irqon],80h - cmp byte[C4Enable],0 - je .noC4 - call C4VBlank -.noC4 -; mov byte[hdmastartsc],0 - mov byte[joycontren],0 - mov ax,[VIRQLoc] - cmp word[curypos],ax - jne .novirqz - inc word[VIRQLoc] -.novirqz - - call ReadInputDevice - - test byte[INTEnab],1 - jz .noresetjoy - mov eax,[JoyAOrig] - rol eax,16 - mov [JoyANow],eax - mov eax,[JoyBOrig] - rol eax,16 - mov [JoyBNow],eax - mov eax,[JoyCOrig] - rol eax,16 - mov [JoyCNow],eax - mov eax,[JoyDOrig] - mov [JoyDNow],eax - mov byte[JoyCRead],0 -.noresetjoy - - cmp byte[snesmouse],4 - jne .nolethalen - mov eax,[LethEnData] - mov [JoyBNow],eax -.nolethalen - - mov byte[MultiTapStat],80h - mov byte[NMIEnab],81h - test byte[INTEnab],80h - jz .nonmi - mov byte[curnmi],1 - dec esi - cmp byte[intrset],1 - jne .nointrset - mov byte[intrset],2 -.nointrset - jmp switchtonmideb -.nonmi - cmp byte[intrset],1 - jne .nointrset2w - mov byte[intrset],2 -.nointrset2w - cmp byte[esi],0CBh - jne .nowai - and dl,0FBh -.nowai - jmp dword near [edi+ebx*4] - -.overy - sub dh,110 - mov word[curypos],0 - xor byte[ppustatus],80h - mov byte[NMIEnab],01h - add dword[opcd],170*262 - call cachevideo - call starthdma - - ProcessIRQStuff - -; test dl,04h -; jnz .novirq2 -; test byte[INTEnab],20h -; jz .novirq2 -; mov ax,[VIRQLoc] -; cmp word[curypos],ax -; je near .virq -; mov ax,[VIRQLoc] -; cmp ax,[totlines] -; jae .virq -;.novirq2 - jmp dword near [edi+ebx*4] - -.virq - mov ax,[resolutn] - cmp word[curypos],ax - jnb .nodrawline - cmp byte[hdmadelay],0 - je .dohdma2 - dec byte[hdmadelay] - jmp .nodohdma2 -.dohdma2 - call exechdma -.nodohdma2 - cmp byte[curblank],0 - jne .nodrawline - call drawline -.nodrawline - dec esi - cmp byte[intrset],1 - jne .nointrset2 - mov byte[intrset],2 -.nointrset2 - jmp switchtovirqdeb +;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) +; +;http://www.zsnes.com +;http://sourceforge.net/projects/zsnes +; +;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 KeyRewind,statesaver,Voice0Status,UpdateDPage +EXTSYM StartGUI,debuggeron,romdata,initvideo +EXTSYM vidbufferofsa,disable65816sh,GUISaveVars,virqnodisable +EXTSYM KeySaveState,KeyLoadState,KeyQuickExit,KeyQuickLoad,KeyQuickRst +EXTSYM GUIDoReset,GUIReset,KeyOnStA,KeyOnStB,ProcessKeyOn,C4Enable,KeyQuickClock +EXTSYM KeyQuickSaveSPC,TimerEnable,IRQHack,splitflags,joinflags +EXTSYM KeyQuickSnapShot,csounddisable,videotroub,ResetTripleBuf +EXTSYM Output_Text,Check_Key,Get_Key,Change_Dir +EXTSYM InitPreGame,Curtableaddr,curcyc,debugdisble,dmadata,guioff,memtabler8 +EXTSYM SetupPreGame,memtablew8,regaccessbankr8,showmenu,snesmap2,snesmmap +EXTSYM DeInitPostGame,spcPCRam,startdebugger,xp,xpb,xpc,tablead,tableadb +EXTSYM tableadc,SA1UpdateDPage,Makemode7Table,nextmenupopup,MovieProcessing +EXTSYM DosExit,InitDir,InitDrive,createnewcfg,sfxramdata,deinitvideo +EXTSYM SFXEnable,wramdata,cycpbl,cycpblt,irqon,spcon +EXTSYM multchange,romispal,scrndis,sprlefttot,sprleftpr,processsprites +EXTSYM cachesprites,NextLineStart,FlipWait,LastLineStart,opcjmptab,CheatOn +EXTSYM INTEnab,JoyCRead,NMIEnab,NumCheats,CurrentExecSA1,ReadInputDevice +EXTSYM StartDrawNewGfx,VIRQLoc,cachevideo,cfield,cheatdata,curblank,curnmi +EXTSYM curypos,cycpl,doirqnext,drawline,exechdma,hdmadelay,intrset,newengen +EXTSYM oamaddr,oamaddrs,resolutn,showvideo,snesmouse,starthdma,switchtonmi +EXTSYM switchtovirq,totlines,updatetimer,SA1Swap,SA1DoIRQ,JoyAOrig,JoyANow +EXTSYM JoyBOrig,JoyBNow,JoyCOrig,JoyCNow,JoyDOrig,JoyDNow,JoyEOrig,JoyENow +EXTSYM SA1Message,MultiTapStat,idledetectspc,SA1Control,SA1Enable,SA1IRQEnable +EXTSYM SPC700read,SPC700write,numspcvblleft,spc700idle,SA1IRQExec,ForceNewGfxOff +EXTSYM LethEnData,GUIQuit,IRAM,SA1Ptr,SA1BWPtr,scrnon,scaddset,outofmemfix +EXTSYM yesoutofmemory,ProcessMovies,MovieStop,ppustatus,C4VBlank +EXTSYM ReturnFromSPCStall,scanlines,smallscreenon,ScreenScale,MainLoop +EXTSYM NumberOfOpcodes,SfxCLSR,SfxSCMR,SfxPOR,sfx128lineloc,sfx160lineloc +EXTSYM sfx192lineloc,sfxobjlineloc,sfxclineloc,PLOTJmpa,PLOTJmpb,FxTable +EXTSYM FxTableb,FxTablec,FxTabled,SfxPBR,SCBRrel,SfxSCBR,SfxCOLR,SFXCounter +EXTSYM fxbit01,fxbit01pcal,fxbit23,fxbit23pcal,fxbit45,fxbit45pcal,fxbit67 +EXTSYM fxbit67pcal,SfxSFR,nosprincr,cpucycle,switchtovirqdeb,switchtonmideb +EXTSYM MovieSeekBehind,SaveSramData,BackupCVFrame,RestoreCVFrame,loadstate +EXTSYM KeyInsrtChap,KeyNextChap,KeyPrevChap,MovieInsertChapter,MovieSeekAhead +EXTSYM ResetDuringMovie,EMUPauseKey,INCRFrameKey,MovieWaiting,NoInputRead +EXTSYM AllocatedRewindStates,PauseFrameMode,RestorePauseFrame,BackupPauseFrame + +%ifdef __MSDOS__ +EXTSYM dssel,Game60hzcall +%endif + +SECTION .data +NEWSYM tempedx, dd 0 +NEWSYM tempesi, dd 0 +NEWSYM tempedi, dd 0 +NEWSYM tempebp, dd 0 +NEWSYM RewindTimer, dd 0 +NEWSYM BackState, db 1 +NEWSYM BackStateSize, dd 6 +SECTION .text + +NEWSYM ProcessRewind + mov eax,[KeyRewind] + cmp byte[pressed+eax],1 + jne near .notokay + mov byte[pressed+eax],2 + + pushad + call RestoreCVFrame + popad + + cmp byte[PauseFrameMode],1 + jne .notpauserewind + pushad + call BackupPauseFrame + popad +.notpauserewind + + mov esi,[tempesi] + mov edi,[tempedi] + mov ebp,[tempebp] + mov edx,[tempedx] + +.notokay + ret + +NEWSYM UpdateRewind + cmp byte[AllocatedRewindStates],0 + je .norewinds + cmp dword[KeyRewind],0 + je .norewinds + + dec dword[RewindTimer] + jnz .checkrewind + + mov [tempedx],edx + mov [tempesi],esi + mov [tempedi],edi + mov [tempebp],ebp + + pushad + call BackupCVFrame + popad + +.checkrewind + call ProcessRewind +.norewinds + ret + +SECTION .data +NEWSYM MuteVoiceF, dd 0 +SECTION .text + +VoiceEndMute: + mov byte[MuteVoiceF],0 + ret + +%macro StartMute 1 + mov al,[Voice0Status+%1] + or al,al + jz %%notmuted + or byte[MuteVoiceF],1 << %1 +%%notmuted +%endmacro + +VoiceStartMute: + mov byte[MuteVoiceF],0 + push eax + StartMute 0 + StartMute 1 + StartMute 2 + StartMute 3 + StartMute 4 + StartMute 5 + StartMute 6 + StartMute 7 + pop eax + ret + + +%macro stim 0 +%ifdef __MSDOS__ + sti +%endif +%endmacro + +%macro ProcessIRQStuff 0 + ; check for VIRQ/HIRQ + cmp byte[virqnodisable],1 + je %%virqdo + test dl,04h + jnz %%virqdo + cmp byte[doirqnext],1 + je near .virq +%%virqdo + test byte[INTEnab],20h + jz near %%novirq + mov ax,[VIRQLoc] + add ax,[IRQHack] + cmp ax,[resolutn] + jne %%notres + dec ax +; inc ax +%%notres + cmp ax,0FFFFh + jne %%notzero + xor ax,ax +%%notzero + cmp word[curypos],ax + jne near %%noirq + test byte[INTEnab],10h + jnz %%tryhirq +%%startirq + cmp byte[intrset],1 + jne %%nointrseta + mov byte[intrset],2 +%%nointrseta + mov byte[irqon],80h + test dl,04h + jnz %%irqd + jmp .virq +%%novirq + test byte[INTEnab],10h + jz %%noirq +%%setagain + cmp byte[intrset],2 + jbe %%nointrseta3 + dec byte[intrset] + cmp byte[intrset],2 + ja %%noirq +%%nointrseta3 + cmp byte[intrset],1 + jne %%nointrseta2 + test byte[INTEnab],80h + jz %%tryhirq + mov byte[intrset],8 + jmp %%noirq +%%nointrseta2 + test dl,04h + jnz %%noirq +%%tryhirq + jmp %%startirq +%%irqd + mov byte[doirqnext],1 +%%noirq +%endmacro + + +; .returnfromsfx + +; pexecs +; *** Copy to PC whenever a non-relative jump is executed + +SECTION .data +NEWSYM romloadskip, db 0 +NEWSYM SSKeyPressed, dd 0 +NEWSYM SPCKeyPressed, dd 0 +NEWSYM NoSoundReinit, dd 0 +NEWSYM NextNGDisplay, db 0 +NEWSYM TempVidInfo, dd 0 +NEWSYM tempdh, db 0 + +SECTION .text + + +; this wonderful mess starts up the CPU and initialized the emulation state +NEWSYM start65816 + + call initvideo + + cmp byte[videotroub],1 + jne .notrouble + ret +.notrouble + + mov edi,[vidbufferofsa] + mov ecx,37518 + xor eax,eax + rep stosd + cmp byte[romloadskip],1 + je near StartGUI + +NEWSYM continueprog + ; clear keyboard presses + mov esi,pressed + mov ecx,256+128+64 + mov al,0 +.loopa + mov [esi],al + inc esi + dec ecx + jnz .loopa + + mov byte[romloadskip],0 + mov byte[debuggeron],0 + mov byte[exiter],0 + + call InitPreGame + jmp reexecute + +NEWSYM continueprognokeys + mov byte[romloadskip],0 + mov byte[debuggeron],0 + mov byte[exiter],0 + + call InitPreGame + jmp reexecuteb2 + +; Incorrect + +NEWSYM reexecuteb +%ifndef __MSDOS__ + jmp reexecuteb2 +%endif +NEWSYM reexecute + + ; clear keyboard presses + mov esi,pressed + mov ecx,256+128+64 + mov al,0 +.loopa + cmp byte[esi],2 + jne .notclear + mov [esi],al +.notclear + inc esi + dec ecx + jnz .loopa +reexecuteb2: + cmp byte[NoSoundReinit],1 + je .skippregame + call SetupPreGame +.skippregame + + ; initialize variables (Copy from variables) + call UpdateDPage + call SA1UpdateDPage + call Makemode7Table + cmp byte[SFXEnable],0 + je .nosfxud + call UpdateSFX +.nosfxud + xor eax,eax + xor ebx,ebx + xor ecx,ecx + xor edx,edx + mov bl,[xpb] + mov ax,[xpc] + test ax,8000h + jz .loweraddr + mov esi,[snesmmap+ebx*4] + jmp .skiplower +.loweraddr + cmp ax,4300h + jb .lower + cmp dword[memtabler8+ebx*4],regaccessbankr8 + je .dma +.lower + mov esi,[snesmap2+ebx*4] + jmp .skiplower +.dma + mov esi,dmadata-4300h +.skiplower + mov [initaddrl],esi + add esi,eax ; add program counter to address + mov dl,[xp] ; set flags + mov dh,[curcyc] ; set cycles + + mov bl,dl + cmp byte[spcon],0 + je .nosoundta + mov edi,[tableadc+ebx*4] + or byte[curexecstate],2 + jmp .soundta +.nosoundta + mov edi,[tableadb+ebx*4] + and byte[curexecstate],0FDh +.soundta + + mov ebp,[spcPCRam] + + mov byte[NoSoundReinit],0 + mov byte[csounddisable],0 + mov byte[NextNGDisplay],0 + + call splitflags + + call execute + + call joinflags + + ; de-init variables (copy to variables) + + mov [spcPCRam],ebp + mov [Curtableaddr],edi + mov [xp],dl + mov [curcyc],dh + + mov eax,[initaddrl] + sub esi,eax ; subtract program counter by address + mov [xpc],si + call ResetTripleBuf + + mov eax,[KeySaveState] + test byte[pressed+eax],1 + jnz .soundreinit + mov eax,[KeyLoadState] + test byte[pressed+eax],1 + jz .skipsoundreinit +.soundreinit + mov byte[NoSoundReinit],1 + mov byte[csounddisable],1 +.skipsoundreinit + + cmp byte[NoSoundReinit],1 + je .skippostgame + call DeInitPostGame +.skippostgame + + ; clear all keys + call Check_Key + cmp al,0 + je .nokeys +.yeskeys + call Get_Key + call Check_Key + cmp al,0 + jne .yeskeys +.nokeys + + cmp byte[nextmenupopup],1 + je near showmenu + cmp byte[ReturnFromSPCStall],1 + je near .activatereset + mov eax,[KeySaveState] + test byte[pressed+eax],1 + jz .nosavestt + mov byte[pressed+1],0 + mov byte[pressed+eax],2 + pushad + call statesaver + popad + jmp reexecuteb +.nosavestt + mov eax,[KeyLoadState] + test byte[pressed+eax],1 + jz .noloadstt0 + pushad + call loadstate + popad + jmp reexecuteb +.noloadstt0 + mov eax,[KeyInsrtChap] + test byte[pressed+eax],1 + jz .noinsertchapter + mov byte[pressed+eax],0 + pushad + call MovieInsertChapter + popad + jmp continueprognokeys +.noinsertchapter + mov eax,[KeyNextChap] + test byte[pressed+eax],1 + jz .nonextchapter + mov byte[pressed+eax],0 + mov byte[multchange],1 + pushad + call MovieSeekAhead + popad + jmp continueprognokeys +.nonextchapter + mov eax,[KeyPrevChap] + test byte[pressed+eax],1 + jz .noprevchapter + mov byte[pressed+eax],0 + mov byte[multchange],1 + pushad + call MovieSeekBehind + popad + jmp continueprognokeys +.noprevchapter + cmp byte[SSKeyPressed],1 + je near showmenu + cmp byte[SPCKeyPressed],1 + je near showmenu + cmp byte[debugdisble],0 + jne .nodebugger + test byte[pressed+59],1 + jne near startdebugger +.nodebugger + test byte[pressed+59],1 + jne near showmenu + mov eax,[KeyQuickRst] + test byte[pressed+eax],1 + jz .noreset +.activatereset + pushad + mov byte[GUIReset],1 + cmp byte[MovieProcessing],2 ;Recording + jne .nomovierecording + call ResetDuringMovie + jmp .movieendif +.nomovierecording + call GUIDoReset +.movieendif + popad + mov byte[ReturnFromSPCStall],0 + jmp continueprog +.noreset + cmp byte[guioff],1 + je near endprog + mov eax,[KeyQuickExit] + test byte[pressed+eax],1 + jnz near endprog + jmp StartGUI + +NEWSYM endprog + call deinitvideo + + call SaveSramData + call createnewcfg + call GUISaveVars + + pushad + call MovieStop + popad + + ; change dir to InitDrive/InitDir + mov dl,[InitDrive] + mov ebx,InitDir + call Change_Dir + + jmp DosExit + +NEWSYM interror + stim + call deinitvideo + mov edx,.nohand ;use extended + mov ah,9 ;DOS- API + call Output_Text ;to print a string + jmp DosExit + +SECTION .data +.nohand db 'Cannot process interrupt handler!',13,10,0 + +; global variables +NEWSYM invalid, db 0 +NEWSYM invopcd, db 0 +NEWSYM pressed, times 256+128+64 db 0 ; keyboard pressed keys in scancode +NEWSYM exiter, db 0 +NEWSYM oldhand9o, dd 0 +NEWSYM oldhand9s, dw 0 +NEWSYM oldhand8o, dd 0 +NEWSYM oldhand8s, dw 0 +NEWSYM opcd, dd 0 +NEWSYM pdh, dd 0 +NEWSYM pcury, dd 0 +NEWSYM timercount, dd 0 +NEWSYM initaddrl, dd 0 ; initial address location +NEWSYM NetSent, dd 0 +NEWSYM nextframe, dd 0 ; tick count for timer +NEWSYM curfps, db 0 ; frame/sec for current screen +;NEWSYM newgfxerror, db 'NEED MEMORY FOR GFX ENGINE',0 +;NEWSYM newgfxerror2, db 'NEED 320x240 FOR NEW GFX 16B',0 +;newgfxerror db 'NEW GFX IN 16BIT IS N/A',0 +NEWSYM HIRQCycNext, dd 0 +NEWSYM HIRQNextExe, db 0 + + +SECTION .text + +;******************************************************* +; Int 08h vector +;******************************************************* + +; sets to either 60Hz or 50Hz depending on PAL/NTSC +NEWSYM init60hz + cmp byte[romispal],0 + jne .dopal + mov al,00110110b + out 43h,al + mov ax,19900 ; 65536/(60/((65536*24+175)/(60*60*24))) + mov dword[timercount],19900 + out 40h,al + mov al,ah + out 40h,al + ret +.dopal + mov al,00110110b + out 43h,al + mov ax,23863 ; 65536/(50/((65536*24+175)/(60*60*24))) + mov dword[timercount],23863 + out 40h,al + mov al,ah + out 40h,al + ret + +NEWSYM init18_2hz + mov al,00110110b + out 43h,al + mov ax,0 + mov dword[timercount],65536 + out 40h,al + mov al,ah + out 40h,al + ret + +%ifdef __MSDOS__ +NEWSYM handler8h + cli + push ds + push eax +; mov ax,0 + mov ax,[cs:dssel] +NEWSYM handler8hseg + mov ds,ax + call Game60hzcall + mov eax,[timercount] + sub dword[timeradj],eax + jnc .noupd + add dword[timeradj],65536 + pushf + call far [oldhand8o] +.noupd + mov al,20h + out 20h,al + pop eax + pop ds + sti + iretd +%endif + +SECTION .data +NEWSYM timeradj, dd 65536 +NEWSYM t1cc, dw 0 +SECTION .text + +;******************************************************* +; Int 09h vector +;******************************************************* + +%ifdef __MSDOS__ +SECTION .bss +NEWSYM skipnextkey42, resb 1 +SECTION .text + +NEWSYM handler9h + cli + push ds + push eax + push ebx + mov ax,[cs:dssel] + mov ds,ax + xor ebx,ebx + in al,60h ; get keyboard scan code + cmp al,42 + jne .no42 + cmp byte[skipnextkey42],0 + je .no42 + mov byte[skipnextkey42],0 + jmp .skipkeyrel +.no42 + cmp al,0E0h + jne .noE0 + mov byte[skipnextkey42],1 + jmp .skipkeyrel +.noE0 + mov byte[skipnextkey42],0 + mov bl,al + xor bh,bh + test bl,80h ; check if bit 7 is on (key released) + jnz .keyrel + cmp byte[pressed+ebx],0 + jne .skipa + mov byte[pressed+ebx],1 ; if not, set key to pressed +.skipa + jmp .skipkeyrel +.keyrel + and ebx,7Fh + cmp ebx,59 + je .skipkeyrel + cmp ebx,[KeySaveState] + je .skipkeyrel + cmp ebx,[KeyLoadState] + je .skipkeyrel + cmp ebx,[KeyQuickExit] + je .skipkeyrel + cmp ebx,[KeyQuickLoad] + je .skipkeyrel + cmp ebx,[KeyQuickRst] + je .skipkeyrel + cmp bl,1 + je .skipkeyrel + mov byte[pressed+ebx],0 ; if not, set key to pressed +.skipkeyrel + mov byte[pressed],0 + in al,61h + mov ah,al + or al,80h + out 61h,al + mov al,20h ; turn off interrupt mode + out 20h,al + pop ebx ; Pop registers off + pop eax ; stack in correct + pop ds + sti + iretd +%endif + +SECTION .data +ALIGN32 +NEWSYM soundcycleft, dd 0 +NEWSYM curexecstate, dd 0 + +NEWSYM nmiprevaddrl, dd 0 ; observed address -5 +NEWSYM nmiprevaddrh, dd 0 ; observed address +5 +NEWSYM nmirept, dd 0 ; NMI repeat check, if 6 then okay +NEWSYM nmiprevline, dd 224 ; previous line +NEWSYM nmistatus, dd 0 ; 0 = none, 1 = waiting for nmi location, + ; 2 = found, disable at next line +NEWSYM joycontren, dd 0 ; joystick read control check +NEWSYM NextLineCache, db 0 +NEWSYM ZMVZClose, db 0 + +SECTION .text + +Donextlinecache: + cmp word[curypos],0 + je .nocache + mov ax,[resolutn] + dec ax + cmp word[curypos],ax + jae .nocache + test byte[scrndis],10h + jnz .nocache + cmp byte[curblank],0h + jne .nocache + push ecx + push ebx + push esi + push edi + xor ecx,ecx + mov cl,[curypos] + push edx +.next + mov byte[sprlefttot+ecx],0 + mov dword[sprleftpr+ecx*4],0 + inc cl + jnz .next + call processsprites + call cachesprites + pop edx + pop edi + pop esi + pop ebx + pop ecx +.nocache + mov byte[NextLineCache],0 + ret + +;******************************************************* +; 65816 execution +;******************************************************* + +SECTION .data + +SpeedHackSafeTable: + db 1,0,1,0,0,0,1,0,1,0,1,1,0,0,0,0 + db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 + db 0,0,0,0,0,0,1,0,1,0,1,1,0,0,1,0 + db 0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0 + db 0,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,1,0,0,0,1,0 + db 0,1,0,1,0,1,1,1,0,1,1,0,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 + db 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + db 0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0 + db 0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0 + db 0,1,0,1,0,1,1,1,1,1,0,0,0,1,1,1 + db 0,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1 +SECTION .text + +NEWSYM exitloop2 + mov byte[ExecExitOkay],0 +NEWSYM exitloop + ret + +ALIGN16 + +%macro FlipCheck 0 + cmp byte[FlipWait],0 + je %%noflip + push edx + push eax + mov dx,3DAh ;VGA status port + in al,dx + test al,8 + jz %%skipflip + push ebx + push ecx + mov ax,4F07h + mov bh,00h + mov bl,00h + xor cx,cx + mov dx,[NextLineStart] + mov [LastLineStart],dx + int 10h + mov byte[FlipWait],0 + pop ecx + pop ebx +%%skipflip + pop eax + pop edx +%%noflip +%endmacro + +NEWSYM execute +NEWSYM execloop + mov bl,dl + test byte[curexecstate],2 + jnz .sound + mov edi,[tableadb+ebx*4] + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuover +.startagain + call dword near [edi+ebx*4] +.cpuover + jmp cpuover +.sound + mov edi,[tableadc+ebx*4] +%ifdef OPENSPC + pushad + mov bl,[esi] + movzx eax,byte[cpucycle+ebx] + mov ebx,0xC3A13DE6 + mul ebx + add [ospc_cycle_frac],eax + adc [SPC_Cycles],edx + call OSPC_Run + popad +%else + sub dword[cycpbl],55 + jnc .skipallspc + mov eax,[cycpblt] + mov bl,[ebp] + add dword[cycpbl],eax + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx +.skipallspc +%endif + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuovers + call dword near [edi+ebx*4] +.cpuovers + jmp cpuover + + + +SECTION .data +ALIGN32 +NEWSYM ExecExitOkay, db 1 +NEWSYM JoyABack, dd 0 +NEWSYM JoyBBack, dd 0 +NEWSYM JoyCBack, dd 0 +NEWSYM JoyDBack, dd 0 +NEWSYM JoyEBack, dd 0 +NEWSYM NetCommand, dd 0 +NEWSYM spc700read, dd 0 +NEWSYM lowestspc, dd 0 +NEWSYM highestspc, dd 0 +NEWSYM SA1UBound, dd 0 +NEWSYM SA1LBound, dd 0 +NEWSYM SA1SH, dd 0 +NEWSYM SA1SHb, dd 0 +NEWSYM NumberOfOpcodes2, dd 0 +NEWSYM ChangeOps, dd 0 +NEWSYM SFXProc, dd 0 +NEWSYM EMUPause, db 0 +NEWSYM INCRFrame, db 0 +SECTION .text + +NEWSYM cpuover + dec esi + cmp byte[HIRQNextExe],0 + je .nohirq + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + jmp .hirq +.nohirq + cmp byte[SA1Enable],0 + je near .nosa1b + test byte[exiter],01h + jnz near .nosa1 + mov byte[cycpl],150 + test byte[SA1Control],60h + jnz near .nosa1 + call SA1Swap + cmp byte[CurrentExecSA1],15 + ja .nocontinueexec + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain +.nocontinueexec + + ; check for sa-1 speed hacks + mov byte[SA1SHb],0 + cmp word[IRAM+0A0h],80BFh + jne .noshb2 + cmp word[IRAM+020h],0 + jne .noshb2 + mov ecx,[SA1Ptr] ; small speed hack + sub ecx,[romdata] + cmp ecx,83h + jb .skipsh + cmp ecx,97h + ja .skipsh + mov byte[SA1SHb],1 +.skipsh +.noshb2 + + mov ecx,[SA1Ptr] ; small speed hack + cmp dword[ecx],0FCF04BA5h + je .shm + cmp dword[ecx-2],0FCF04BA5h + jne .skipshm +.shm + cmp byte[IRAM+4Bh],0 + jne .skipshm + mov byte[SA1SHb],1 +.skipshm + + cmp dword[ecx],80602EEEh + jne .skipshc + sub ecx,[romdata] + cmp ecx,4E5h + jb .skipshc + cmp ecx,4E8h + ja .skipshc + mov byte[SA1SHb],1 + mov ecx,[SA1BWPtr] + add word[ecx+602Eh],4 +.skipshc + + test word[IRAM+0Ah],8000h + jnz .noshb2b + test word[IRAM+0Eh],8000h + jz .noshb2b + mov ecx,[SA1Ptr] ; small speed hack + sub ecx,[romdata] + cmp ecx,0C93h + jb .skipshb + cmp ecx,0C9Bh + ja .skipshb + mov byte[SA1SHb],1 +.skipshb + cmp ecx,0CB8h + jb .skipshb3 + cmp ecx,0CC0h + ja .skipshb3 + mov byte[SA1SHb],1 +.skipshb3 +.noshb2b + + sub esi,[wramdata] + cmp esi,224h + jb .nosh + cmp esi,22Eh + ja .nosh + mov ecx,[wramdata] + mov dword[SA1LBound],224h + mov dword[SA1UBound],22Eh + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.nosh + cmp esi,1F7C6h + jb .noshb + cmp esi,1F7CCh + ja .noshb + mov ecx,[wramdata] + mov dword[SA1LBound],1F7C6h + mov dword[SA1UBound],1F7CCh + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshb + cmp esi,14h + jb .noshc + cmp esi,1Ch + ja .noshc + mov ecx,[wramdata] + cmp dword[ecx+14h],0F023002Ch + jne .noshc + mov dword[SA1LBound],14h + mov dword[SA1UBound],1Ch + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshc + add esi,[wramdata] + sub esi,[romdata] + cmp esi,0A56h + jb .noshbc + cmp esi,0A59h + ja .noshbc + mov ecx,[romdata] + mov dword[SA1LBound],0A56h + mov dword[SA1UBound],0A59h + add dword[SA1LBound],ecx + add dword[SA1UBound],ecx + mov byte[SA1SH],1 +.noshbc + xor ecx,ecx + add esi,[romdata] + xor dh,dh + mov byte[cycpl],10 + cmp byte[CurrentExecSA1],255 + jne .notsa1255 + mov byte[cycpl],160 +.notsa1255 + mov byte[CurrentExecSA1],0 + test dl,04h + jnz .nosa1 + test byte[SA1IRQEnable],80h + jz .nosa1 + test byte[SA1DoIRQ],4 + jz .nosa1 + and byte[SA1DoIRQ],0FBh + mov al,[SA1Message+1] + mov [SA1Message+3],al + or byte[SA1IRQExec],1 + ; Start IRQ + add dh,10 + jmp .virq +.nosa1 + test byte[SA1IRQEnable],20h + jz .nosa1chirq + test byte[SA1DoIRQ],8 + jz .nosa1chirq +; jmp .nosa1chirq + and byte[SA1DoIRQ],0F7h + mov al,[SA1Message+1] + mov [SA1Message+3],al + or byte[SA1IRQExec],2 + ; Start IRQ + add dh,10 + jmp .virq +.nosa1chirq +.nosa1b + FlipCheck + cmp byte[NextLineCache],0 + je .nosprcache + call Donextlinecache +.nosprcache + cmp byte[KeyOnStB],0 + je .nokeyon + mov al,[KeyOnStB] + call ProcessKeyOn +.nokeyon + mov al,[KeyOnStA] + mov [KeyOnStB],al + mov byte[KeyOnStA],0 + test byte[exiter],01h + jnz near exitloop2 + + test byte[SfxSFR],20h + jnz near StartSFX +.returnfromsfx +; inc dword[numinst] ;Temporary + inc word[curypos] + add dh,[cycpl] + mov ax,[totlines] + cmp word[curypos],ax + jae near .overy + cmp byte[spcon],0 + je .nosound + call updatetimer +.nosound + mov ax,[resolutn] + inc ax + cmp [curypos],ax + je near .nmi + + mov ax,[resolutn] + cmp [curypos],ax + je near .hdma +; add ax,2 +; cmp [curypos],ax +; je near .hdma +.hdmacont + + cmp byte[curypos],100 + jne .noline100 + mov ax,[scrnon] + mov [TempVidInfo],ax + mov ax,[scaddset] + mov [TempVidInfo+2],ax +.noline100 + + ; check for VIRQ/HIRQ/NMI + ProcessIRQStuff + mov ax,[resolutn] + dec ax + cmp [curypos],ax + jb .drawline + + +; mov ax,[resolutn] +; cmp [curypos],ax +; jb .drawline + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.hdma + call exechdma + jmp .hdmacont + +.drawline + mov al,[nmiprevline] + cmp [curypos],al + jb near .noskip + cmp byte[nmirept],10 + jb near .noskip + ; if between correct address, decrease by 2, set nmistatus as 2 + ; if not, set nmistatus as 1, increase by 2 + cmp byte[curexecstate],0 + jne .nn + xor dh,dh +.nn + cmp byte[nmistatus],2 + jae near .noskip + cmp esi,[nmiprevaddrl] + jb .failcheck2 + cmp esi,[nmiprevaddrh] + ja .failcheck2 + cmp byte[nmiprevline],20 + jb .nodec + sub byte[nmiprevline],10 +.nodec + xor eax,eax + mov al,[esi] + cmp byte[disable65816sh],1 + je .ohno + cmp byte[SpeedHackSafeTable+eax],1 + jne .okay +.ohno + mov byte[nmirept],0 + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + jmp .noskip +.okay + mov byte[nmistatus],2 + and byte[curexecstate],0FEh +.nodis65816 + jmp .noskip +.failcheck2 + add byte[nmiprevline],1 + mov byte[nmistatus],1 +.noskip + cmp byte[hdmadelay],0 + je .dohdma + dec byte[hdmadelay] + jmp .nodohdma +.dohdma + cmp word[curypos],1 + jne .nooffby1line + test byte[INTEnab],20h + jz .nooffby1line + cmp word[VIRQLoc],0 + je .nodohdma +.nooffby1line + call exechdma +.nodohdma + cmp word[curypos],1 + jne .nocache + call cachevideo +.nocache + cmp byte[curblank],0 + jne .nodrawlineb2 + call drawline +.nodrawlineb2 + cmp byte[curexecstate],2 + je near pexecs + cmp byte[curexecstate],0 + jne .yesexec + xor dh,dh +.yesexec + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.nmi + mov byte[irqon],80h + mov byte[doirqnext],0 + cmp byte[yesoutofmemory],1 + jne .noout + call outofmemfix +.noout + + dec word[curypos] + mov [tempdh],dh + xor dh,dh + +; mov al,[SFXIRQFlag] + mov byte[doirqnext],0 + + call exechdma + call exechdma + + mov byte[NextNGDisplay],1 + cmp byte[newengen],0 + je .nonewgfx + cmp byte[curblank],0 + jne .nonewgfx + cmp byte[ForceNewGfxOff],0 + jne .nonewgfx +; cmp byte[NextNGDisplay],0 +; je .nonewgfx + call StartDrawNewGfx +.nonewgfx + cmp byte[GUIQuit],1 + je near endprog + mov eax,[KeyQuickSnapShot] + or eax,eax + jz .nosskey + test byte[pressed+eax],1 + jz .nosskey + mov byte[SSKeyPressed],1 + mov byte[pressed+eax],2 + jmp exitloop +.nosskey + mov eax,[KeyQuickClock] + or eax,eax + jz .noclockkey + test byte[pressed+eax],1 + jz .noclockkey + xor byte[TimerEnable],1 + mov byte[pressed+eax],2 +.noclockkey + mov eax,[KeyQuickSaveSPC] + or eax,eax + jz .nosavespckey + test byte[pressed+eax],1 + jz .nosavespckey + mov byte[SPCKeyPressed],1 + mov byte[pressed+eax],2 + jmp exitloop +.nosavespckey + mov eax,[EMUPauseKey] + or eax,eax + jz .nopausekey + test byte[pressed+eax],1 + jz .nopausekey + xor byte[EMUPause],1 + mov byte[pressed+eax],2 +.nopausekey + mov eax,[INCRFrameKey] + or eax,eax + jz .noincrframekey + test byte[pressed+eax],1 + jz .noincrframekey + xor byte[INCRFrame],1 + mov byte[pressed+eax],2 +.noincrframekey + test byte[pressed+1],01h + jnz near exitloop + test byte[pressed+59],01h + jnz near exitloop + cmp byte[nextmenupopup],1 + je near exitloop + cmp byte[nextmenupopup],2 + jb .skipmenupop + dec byte[nextmenupopup] +.skipmenupop + mov eax,[KeySaveState] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyLoadState] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyInsrtChap] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyPrevChap] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyNextChap] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickRst] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickExit] + test byte[pressed+eax],01h + jnz near exitloop + mov eax,[KeyQuickLoad] + test byte[pressed+eax],01h + jnz near exitloop + cmp byte[ExecExitOkay],0 + je .returntoloop + dec byte[ExecExitOkay] +.returntoloop + mov dh,[tempdh] + inc word[curypos] + cmp byte[NoInputRead],1 + je .noinputread + call ReadInputDevice +.noinputread + + ;Pause and Frame increment + cmp byte[PauseFrameMode],3 + jne .nopauseframemode3 + pushad + call RestorePauseFrame + popad + mov esi,[tempesi] + mov edi,[tempedi] + mov ebp,[tempebp] + mov edx,[tempedx] +.nopauseframemode3 + + cmp byte[EMUPause],1 + jne .noemupause + + cmp byte[PauseFrameMode],1 + jne .nopauseframemode1 + mov [tempedx],edx + mov [tempesi],esi + mov [tempedi],edi + mov [tempebp],ebp + pushad + call BackupPauseFrame + popad +.nopauseframemode1 + + call ProcessRewind + + cmp byte[PauseFrameMode],2 + jne .nopauseframemode2 + mov byte[PauseFrameMode],3 + jmp .noprocmovie +.nopauseframemode2 + + cmp byte[INCRFrame],1 + jne .noframeincr + xor byte[INCRFrame],1 + jmp .noemupause +.noframeincr + + ;Update screen - DISABLED FOR NOW + pushad + ;call StartDrawNewGfx + ;call showvideo + ;call cachevideo + popad + + jmp .nonewgfx +.noemupause + + ;Rewind update must be done before process this frame of movie, so rewind doesn't + ;back up incremented values (some vars being for the next frame) + call UpdateRewind + + cmp byte[MovieProcessing],0 + je .noprocmovie + pushad + call ProcessMovies + popad + cmp byte[GUIReset],1 + jne .notreset + mov byte[MovieWaiting],1 + mov eax,[KeyQuickRst] + mov byte[pressed+eax],01h + jmp near exitloop +.notreset + cmp byte[MovieProcessing],0 + jne .noprocmovie + cmp byte[ZMVZClose],1 + jne .noprocmovie + jmp DosExit +.noprocmovie + + cmp byte[snesmouse],4 + jne .nolethalen + mov eax,[LethEnData] + mov [JoyBNow],eax +.nolethalen + + test byte[INTEnab],1 + jz .noresetjoy + mov eax,[JoyAOrig] + rol eax,16 + mov [JoyANow],eax + mov eax,[JoyBOrig] + rol eax,16 + mov [JoyBNow],eax + mov eax,[JoyCOrig] + rol eax,16 + mov [JoyCNow],eax + mov eax,[JoyDOrig] + mov [JoyDNow],eax + mov eax,[JoyEOrig] + mov [JoyENow],eax + mov byte[JoyCRead],0 +.noresetjoy + mov byte[MultiTapStat],80h + + cmp byte[C4Enable],0 + je .noC4 + call C4VBlank +.noC4 +; mov byte[hdmastartsc],0 + mov byte[joycontren],0 + test byte[curexecstate],01h + jnz .dis65816 + or byte[curexecstate],01h +.dis65816 + cmp byte[CheatOn],1 + je near .cheater +.returncheat + mov ax,[VIRQLoc] + cmp word[curypos],ax + jne .novirqz + mov byte[doirqnext],1 +.novirqz + mov ax,[oamaddrs] + mov [oamaddr],ax + mov byte[nosprincr],0 + call showvideo + xor ebx,ebx + mov byte[NMIEnab],81h + test byte[INTEnab],80h + jz near .nonmi +; cmp byte[intrset],1 +; je near .nonmi + +.nmiokay + mov byte[curnmi],1 + cmp byte[intrset],1 + jne .nointrset + mov byte[intrset],2 +.nointrset + cmp byte[nmistatus],1 + jne .notnonmifound + mov byte[nmirept],0 +.notnonmifound + mov byte[nmistatus],0 + cmp byte[nmirept],0 + jne .nocheck + mov al,[resolutn] + sub al,2 + mov [nmiprevline],al + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + mov byte[nmirept],1 + mov byte[doirqnext],0 + jmp switchtonmi +.nocheck + cmp byte[nmirept],10 + je .nextcheck + cmp esi,[nmiprevaddrl] + jae .notlower + mov [nmiprevaddrl],esi +.notlower + cmp esi,[nmiprevaddrh] + jbe .notgreater + mov [nmiprevaddrh],esi +.notgreater + inc byte[nmirept] + jmp switchtonmi +.nextcheck + mov eax,[nmiprevaddrh] + sub eax,[nmiprevaddrl] + cmp eax,10 + ja .failcheck + cmp esi,[nmiprevaddrl] + jb .failcheck + cmp esi,[nmiprevaddrh] + ja .failcheck + mov byte[doirqnext],0 + jmp switchtonmi +.failcheck + mov byte[nmirept],0 + mov dword[nmiprevaddrl],0FFFFFFFFh + mov dword[nmiprevaddrh],0 + mov byte[doirqnext],0 + jmp switchtonmi +.nonmi + cmp byte[intrset],1 + jne .nointrset2w + mov byte[intrset],2 +.nointrset2w + xor ebx,ebx + xor ecx,ecx + mov bl,[esi] + inc esi + jmp execloop.startagain + + +.overy + sub dh,110 + cmp byte[smallscreenon],1 + je .nocfield + cmp byte[ScreenScale],1 + je .nocfield + cmp byte[scanlines],0 + jne .nocfield + xor byte[cfield],1 +.nocfield + mov word[curypos],0 + xor byte[ppustatus],80h + cmp dword[numspcvblleft],0 + je near .novblch + cmp [lowestspc],ebp + ja .failspc + cmp [highestspc],ebp + jb .failspc + jmp .okayspc +.failspc + mov eax,ebp + sub eax,10 + mov [lowestspc],eax + add eax,20 + mov [highestspc],eax + mov dword[spc700idle],0 +.okayspc + cmp dword[SPC700write],0 + jne .notwritespc + cmp dword[spc700read],0 + je .notwritespc + cmp dword[SPC700read],1500 + jb .notwritespc + inc dword[spc700idle] + cmp dword[spc700idle],30 + jne .noidleend + call idledetectspc + cmp byte[ReturnFromSPCStall],1 + jne .noidleend + mov byte[ExecExitOkay],0 + jmp exitloop +.noidleend + jmp .notidle +.notwritespc + mov dword[spc700idle],0 +.notidle + dec dword[numspcvblleft] + mov dword[SPC700write],0 + mov dword[SPC700read],0 + mov dword[spc700read],0 +.novblch + mov byte[NMIEnab],01h + call starthdma +.noirqhack + ; check for VIRQ/HIRQ/NMI + ProcessIRQStuff + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.virq + test byte[curexecstate],01h + jnz .dis658162 + or byte[curexecstate],01h +.dis658162 + mov byte[doirqnext],0 + xor ebx,ebx + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawline + cmp byte[hdmadelay],1 + jne .virqstuff +.virqstuff + cmp byte[hdmadelay],0 + je .dohdma2 + dec byte[hdmadelay] + jmp .nodohdma2 +.dohdma2 + call exechdma +.nodohdma2 + cmp word[curypos],1 + jne .nocache2 + call cachevideo +.nocache2 + cmp byte[curblank],0 + jne .nodrawline + call drawline +.nodrawline + cmp byte[intrset],1 + jne .nointrset2 + mov byte[intrset],2 +.nointrset2 +; sub dh,8 + jmp switchtovirq + +.hirq + mov byte[HIRQNextExe],0 + test byte[INTEnab],10h + jz .hirqnotokay + test byte[curexecstate],01h + jnz .dis658162h + or byte[curexecstate],01h +.dis658162h + mov byte[doirqnext],0 + cmp byte[intrset],1 + jne .nointrset2h + mov byte[intrset],2 +.nointrset2h + test dl,04h + jnz .irqd + jmp switchtovirq +.irqd + mov byte[doirqnext],1 +.hirqnotokay + jmp .nodrawlineh + +.returnfromhirq + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawlineh + cmp byte[hdmadelay],0 + je .dohdma2h + dec byte[hdmadelay] + jmp .nodohdma2h +.dohdma2h + call exechdma +.nodohdma2h + cmp word[curypos],1 + jne .nocache2h + call cachevideo +.nocache2h + cmp byte[curblank],0 + jne .nodrawlineh + call drawline +.nodrawlineh + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +.cheater + push eax + push ebx + push ecx + push edx + mov al,[NumCheats] + mov [.numcheat],al + xor edx,edx +.anothercheat + xor ebx,ebx + xor ecx,ecx + test byte[cheatdata+edx],5 + jnz .nonormcheat + test byte[cheatdata+edx-28],80h + jnz .nonormcheat + test byte[cheatdata+edx],80h + jnz .cheatcodereflect + mov al,[cheatdata+edx+1] + mov cx,[cheatdata+edx+2] + mov bl,[cheatdata+edx+4] + push edx + call dword near [memtablew8+ebx*4] + pop edx + jmp .nonormcheat +.cheatcodereflect + cmp byte[.numcheat],1 + je .nonormcheat + mov cx,[cheatdata+edx+2+28] + mov bl,[cheatdata+edx+4+28] + push edx + call dword near [memtabler8+ebx*4] + pop edx + mov cx,[cheatdata+edx+2] + mov bl,[cheatdata+edx+4] + push edx + call dword near [memtablew8+ebx*4] + pop edx + add edx,28 + dec byte[.numcheat] +.nonormcheat + add edx,28 + dec byte[.numcheat] + jnz near .anothercheat + pop edx + pop ecx + pop ebx + pop eax + jmp .returncheat + +SECTION .bss +.numcheat resb 1 +SECTION .text + +ALIGN16 + +NEWSYM pexecs + mov byte[soundcycleft],30 +.sloop + mov bl,[ebp] + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx + dec byte[soundcycleft] + jnz .sloop + xor dh,dh + xor ebx,ebx + mov bl,[esi] + inc esi + jmp execloop.startagain + +NEWSYM pexecs2 +.sloop + mov bl,[ebp] + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx + dec dword[soundcycleft] + jnz .sloop + ret + +NEWSYM UpdatePORSCMR + push ebx + push eax + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + mov [FxTable+4Ch*4],eax + mov [FxTableb+4Ch*4],eax + mov [FxTablec+4Ch*4],eax + mov [FxTabled+4Ch*4],ebx + pop eax + pop ebx + ret + +NEWSYM UpdateSCBRCOLR + push eax + push ebx + mov ebx,[SfxSCBR] + shl ebx,10 + add ebx,[sfxramdata] + mov [SCBRrel],ebx + mov eax,[SfxCOLR] + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + pop ebx + pop eax + ret + +NEWSYM UpdateCLSR + mov dword[NumberOfOpcodes2],350 ; 0FFFFFFFh;350 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword[NumberOfOpcodes2],700 ;700 +.nohighsfx + cmp byte[SFXCounter],1 + je .noyi + mov dword[NumberOfOpcodes2],0FFFFFFFh +.noyi + ret + +NEWSYM UpdateSFX + call UpdatePORSCMR + call UpdatePORSCMR + call UpdateCLSR + ret + +NEWSYM StartSFX + push edx + push esi + push edi + push ebp + xor ebx,ebx + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov eax,[NumberOfOpcodes2] + mov [NumberOfOpcodes],eax + call MainLoop +.noaccess + pop ebp + pop edi + pop esi + pop edx + xor ebx,ebx + xor ecx,ecx + jmp cpuover.returnfromsfx + +NEWSYM StartSFXdebug + push edx + push esi + push edi + push ebx + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword[NumberOfOpcodes],350 ; 0FFFFFFFh;350 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword[NumberOfOpcodes],700 ;700 +.nohighsfx + cmp byte[SFXCounter],1 + jne .noyi + mov dword[NumberOfOpcodes],0FFFFFFFFh +.noyi +; call SFXDebugLoop +.noaccess + pop ebx + pop edi + pop esi + pop edx + xor ecx,ecx + jmp execsingle.returnfromsfx + +NEWSYM StartSFXdebugb + push edx + push esi + push edi + push ebp + push ebx + + test byte[SfxPOR],10h + jnz .objmode + mov al,[SfxSCMR] + and al,00100100b ; 4 + 32 + cmp al,4 + je .lines160 + cmp al,32 + je .lines192 + cmp al,36 + je .objmode + mov eax,[sfx128lineloc] + jmp .donelines +.lines160 + mov eax,[sfx160lineloc] + jmp .donelines +.lines192 + mov eax,[sfx192lineloc] + jmp .donelines +.objmode + mov eax,[sfxobjlineloc] +.donelines + mov [sfxclineloc],eax + + mov al,[SfxSCMR] + and eax,00000011b + mov bl,[SfxPOR] + and bl,0Fh + shl bl,2 + or al,bl + mov ebx,[PLOTJmpb+eax*4] + mov eax,[PLOTJmpa+eax*4] + mov [FxTable+4Ch*4],eax + mov [FxTableb+4Ch*4],eax + mov [FxTablec+4Ch*4],eax + mov [FxTabled+4Ch*4],ebx + + mov ebx,[SfxSCBR] + shl ebx,10 + add ebx,[sfxramdata] + mov [SCBRrel],ebx + + mov eax,[SfxCOLR] + mov ebx,[fxbit01+eax*4] + mov [fxbit01pcal],ebx + mov ebx,[fxbit23+eax*4] + mov [fxbit23pcal],ebx + mov ebx,[fxbit45+eax*4] + mov [fxbit45pcal],ebx + mov ebx,[fxbit67+eax*4] + mov [fxbit67pcal],ebx + xor ebx,ebx + + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword[NumberOfOpcodes],400 ;678 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword[NumberOfOpcodes],800 ;678*2 +.nohighsfx + cmp byte[SFXCounter],1 + jne .noyi + mov dword[NumberOfOpcodes],0FFFFFFFh +.noyi + call MainLoop +.noaccess + pop ebx + pop ebp + pop edi + pop esi + pop edx + xor ecx,ecx + jmp execsingle.returnfromsfx + +NEWSYM StartSFXret + test byte[SfxSFR],20h + jz .endfx + pushad + mov bl,[SfxPBR] + mov al,[SfxSCMR] + and bl,7Fh + cmp bl,70h + jae .ram + test al,10h + jz .noaccess + jmp .noram +.ram + test al,08h + jz .noaccess +.noram + mov dword[NumberOfOpcodes],400 ;678 + test byte[SfxCLSR],01h + jz .nohighsfx + mov dword[NumberOfOpcodes],800 ;678*2 +.nohighsfx + mov dword[NumberOfOpcodes],0FFFFFFFFh + call MainLoop +.noaccess + popad +.endfx + ret + +;******************************************************* +; Execute a Single 65816 instruction (debugging purpose) +;******************************************************* +NEWSYM execloopdeb + jmp exitloop2 + +NEWSYM execsingle + + xor ebx,ebx + test byte[curexecstate],2 + jz .nosoundb + sub dword[cycpbl],55 + jnc .skipallspc + mov eax,[cycpblt] + mov bl,[ebp] + add dword[cycpbl],eax + ; 1260, 10000/12625 + inc ebp + call dword near [opcjmptab+ebx*4] + xor ebx,ebx +.skipallspc +.nosoundb + + mov bl,dl + mov byte[exiter],01h + mov edi,[tablead+ebx*4] + mov bl,[esi] + inc esi + sub dh,[cpucycle+ebx] + jc .cpuover + mov [pdh],dh + xor dh,dh + jmp dword near [edi+ebx*4] +.cpuover + + cmp byte[SA1Enable],0 + je near .nosa1 + mov byte[cycpl],150 + test byte[SA1Control],60h + jnz near .nosa1 + dec esi + call SA1Swap + + mov bl,[esi] + inc esi + mov [pdh],dh + xor dh,dh + cmp byte[CurrentExecSA1],17 + jb near cpuover + mov byte[CurrentExecSA1],0 + mov byte[cycpl],5 + jmp .nosa1 +.nosa1 + + cmp byte[KeyOnStB],0 + je .nokeyon + mov al,[KeyOnStB] + call ProcessKeyOn +.nokeyon + mov al,[KeyOnStA] + mov [KeyOnStB],al + mov byte[KeyOnStA],0 + test byte[SfxSFR],20h + jnz near StartSFXdebugb +.returnfromsfx + add dh,[cycpl] + mov [pdh],dh + + cmp byte[spcon],0 + je .nosound + call updatetimer + push ebx + xor ebx,ebx + mov bl,dl + mov edi,[tablead+ebx*4] + pop ebx +.nosound + xor dh,dh + inc word[curypos] + mov ax,[resolutn] + inc ax + cmp word[curypos],ax + je near .nmi + mov ax,[totlines] + cmp word[curypos],ax + jae near .overy + ; check for VIRQ/HIRQ/NMI + ProcessIRQStuff + +; test dl,04h +; jnz .noirq +; test byte[INTEnab],20h +; jz .novirq +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; je near .virq +; jmp .noirq +;.novirq +; test byte[INTEnab],10h +; jnz near .virq +;.noirq +; test byte[INTEnab],20h +; jz .novirq2b +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; jne .novirq2b +; cmp byte[intrset],1 +; jne .nointrset2b +; mov byte[intrset],2 +;.nointrset2b +;.novirq2b + mov ax,[resolutn] + cmp word[curypos],ax + jb .drawline + jmp dword near [edi+ebx*4] + +.drawline + cmp byte[hdmadelay],0 + je .dohdma + dec byte[hdmadelay] + jmp .nodohdma +.dohdma + call exechdma +.nodohdma + cmp byte[curblank],0 + jne .nodrawlineb + call drawline +.nodrawlineb + jmp dword near [edi+ebx*4] + +.nmi + mov byte[irqon],80h + cmp byte[C4Enable],0 + je .noC4 + call C4VBlank +.noC4 +; mov byte[hdmastartsc],0 + mov byte[joycontren],0 + mov ax,[VIRQLoc] + cmp word[curypos],ax + jne .novirqz + inc word[VIRQLoc] +.novirqz + + call ReadInputDevice + + test byte[INTEnab],1 + jz .noresetjoy + mov eax,[JoyAOrig] + rol eax,16 + mov [JoyANow],eax + mov eax,[JoyBOrig] + rol eax,16 + mov [JoyBNow],eax + mov eax,[JoyCOrig] + rol eax,16 + mov [JoyCNow],eax + mov eax,[JoyDOrig] + mov [JoyDNow],eax + mov byte[JoyCRead],0 +.noresetjoy + + cmp byte[snesmouse],4 + jne .nolethalen + mov eax,[LethEnData] + mov [JoyBNow],eax +.nolethalen + + mov byte[MultiTapStat],80h + mov byte[NMIEnab],81h + test byte[INTEnab],80h + jz .nonmi + mov byte[curnmi],1 + dec esi + cmp byte[intrset],1 + jne .nointrset + mov byte[intrset],2 +.nointrset + jmp switchtonmideb +.nonmi + cmp byte[intrset],1 + jne .nointrset2w + mov byte[intrset],2 +.nointrset2w + cmp byte[esi],0CBh + jne .nowai + and dl,0FBh +.nowai + jmp dword near [edi+ebx*4] + +.overy + sub dh,110 + mov word[curypos],0 + xor byte[ppustatus],80h + mov byte[NMIEnab],01h + add dword[opcd],170*262 + call cachevideo + call starthdma + + ProcessIRQStuff + +; test dl,04h +; jnz .novirq2 +; test byte[INTEnab],20h +; jz .novirq2 +; mov ax,[VIRQLoc] +; cmp word[curypos],ax +; je near .virq +; mov ax,[VIRQLoc] +; cmp ax,[totlines] +; jae .virq +;.novirq2 + jmp dword near [edi+ebx*4] + +.virq + mov ax,[resolutn] + cmp word[curypos],ax + jnb .nodrawline + cmp byte[hdmadelay],0 + je .dohdma2 + dec byte[hdmadelay] + jmp .nodohdma2 +.dohdma2 + call exechdma +.nodohdma2 + cmp byte[curblank],0 + jne .nodrawline + call drawline +.nodrawline + dec esi + cmp byte[intrset],1 + jne .nointrset2 + mov byte[intrset],2 +.nointrset2 + jmp switchtovirqdeb diff --git a/zsnes/src/cpu/regs.inc b/zsnes/src/cpu/regs.inc index 7f52bde8..99054e0b 100644 --- a/zsnes/src/cpu/regs.inc +++ b/zsnes/src/cpu/regs.inc @@ -1,1248 +1,1248 @@ -;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) -; -;http://www.zsnes.com -;http://sourceforge.net/projects/zsnes -; -;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. - - - -EXTSYM SFXEnable,regptr,initsfxregsr,initSA1regs,SA1Enable,initSDD1regs -EXTSYM SPC7110Enable,initSPC7110regs,RTCEnable,RTCReset,curypos,cycpl -EXTSYM debuggeron,pdh,vram,romispal,reg1read,spcnumread,spcon,reg2read,reg3read -EXTSYM reg4read,JoyEOrig,JoyENow,snesmouse,cycphb,joycontren,totlines,DosExit -EXTSYM invalid,numinst,previdmode,printhex,printnum - -SECTION .text - -NEWSYM initregr - ; Fill register pointer with invalid register accesses - mov edi,[regptr] - add edi,8000h - mov ecx,3000h - mov eax,regINVALID -.loopa - mov [edi],eax - add edi,4 - dec ecx - jnz .loopa - ; Set all valid register accesses - setreg 2100h*4,reg2100r - setreg 2134h*4,reg2134r - setreg 2135h*4,reg2135r - setreg 2136h*4,reg2136r - setreg 2137h*4,reg2137r - setreg 2138h*4,reg2138r - setreg 2139h*4,reg2139r - setreg 213Ah*4,reg213Ar - setreg 213Bh*4,reg213Br - setreg 213Ch*4,reg213Cr - setreg 213Dh*4,reg213Dr - setreg 213Eh*4,reg213Er - setreg 213Fh*4,reg213Fr - setreg 2140h*4,reg2140r - setreg 2141h*4,reg2141r - setreg 2142h*4,reg2142r - setreg 2143h*4,reg2143r - setreg 2144h*4,reg2140r - setreg 2180h*4,reg2180r - setreg 21C2h*4,reg21C2r - setreg 21C3h*4,reg21C3r - - setreg 4016h*4,reg4016r - setreg 4017h*4,reg4017r - - setreg 4100h*4,reg4100r - - setreg 420Ah*4,reg420Ar - setreg 420Bh*4,reg420Br - setreg 420Ch*4,reg420Cr - setreg 420Dh*4,reg420Dr - setreg 420Eh*4,reg420Er - setreg 420Fh*4,reg420Fr - - setreg 4210h*4,reg4210r - setreg 4211h*4,reg4211r - setreg 4212h*4,reg4212r - setreg 4213h*4,reg4213r - setreg 4214h*4,reg4214r - setreg 4215h*4,reg4215r - setreg 4216h*4,reg4216r - setreg 4217h*4,reg4217r - setreg 4218h*4,reg4218r - setreg 4219h*4,reg4219r - setreg 421Ah*4,reg421Ar - setreg 421Bh*4,reg421Br - setreg 421Ch*4,reg421Cr - setreg 421Dh*4,reg421Dr - setreg 421Eh*4,reg421Er - setreg 421Fh*4,reg421Fr - - setreg 4300h*4,reg43XXr - setreg 4301h*4,reg43XXr - setreg 4302h*4,reg43XXr - setreg 4303h*4,reg43XXr - setreg 4304h*4,reg43XXr - setreg 4305h*4,reg43XXr - setreg 4306h*4,reg43XXr - setreg 4307h*4,reg43XXr - setreg 4308h*4,reg43XXr - setreg 4309h*4,reg43XXr - setreg 430Ah*4,reg43XXr - setreg 430Bh*4,reg43XXr - setreg 430Ch*4,reg43XXr - setreg 430Dh*4,reg43XXr - setreg 430Eh*4,reg43XXr - setreg 430Fh*4,reg43XXr - setreg 4310h*4,reg43XXr - setreg 4311h*4,reg43XXr - setreg 4312h*4,reg43XXr - setreg 4313h*4,reg43XXr - setreg 4314h*4,reg43XXr - setreg 4315h*4,reg43XXr - setreg 4316h*4,reg43XXr - setreg 4317h*4,reg43XXr - setreg 4318h*4,reg43XXr - setreg 4319h*4,reg43XXr - setreg 431Ah*4,reg43XXr - setreg 431Bh*4,reg43XXr - setreg 431Ch*4,reg43XXr - setreg 431Dh*4,reg43XXr - setreg 431Eh*4,reg43XXr - setreg 431Fh*4,reg43XXr - setreg 4320h*4,reg43XXr - setreg 4321h*4,reg43XXr - setreg 4322h*4,reg43XXr - setreg 4323h*4,reg43XXr - setreg 4324h*4,reg43XXr - setreg 4325h*4,reg43XXr - setreg 4326h*4,reg43XXr - setreg 4327h*4,reg43XXr - setreg 4328h*4,reg43XXr - setreg 4329h*4,reg43XXr - setreg 432Ah*4,reg43XXr - setreg 432Bh*4,reg43XXr - setreg 432Ch*4,reg43XXr - setreg 432Dh*4,reg43XXr - setreg 432Eh*4,reg43XXr - setreg 432Fh*4,reg43XXr - setreg 4330h*4,reg43XXr - setreg 4331h*4,reg43XXr - setreg 4332h*4,reg43XXr - setreg 4333h*4,reg43XXr - setreg 4334h*4,reg43XXr - setreg 4335h*4,reg43XXr - setreg 4336h*4,reg43XXr - setreg 4337h*4,reg43XXr - setreg 4338h*4,reg43XXr - setreg 4339h*4,reg43XXr - setreg 433Ah*4,reg43XXr - setreg 433Bh*4,reg43XXr - setreg 433Ch*4,reg43XXr - setreg 433Dh*4,reg43XXr - setreg 433Eh*4,reg43XXr - setreg 433Fh*4,reg43XXr - setreg 4340h*4,reg43XXr - setreg 4341h*4,reg43XXr - setreg 4342h*4,reg43XXr - setreg 4343h*4,reg43XXr - setreg 4344h*4,reg43XXr - setreg 4345h*4,reg43XXr - setreg 4346h*4,reg43XXr - setreg 4347h*4,reg43XXr - setreg 4348h*4,reg43XXr - setreg 4349h*4,reg43XXr - setreg 434Ah*4,reg43XXr - setreg 434Bh*4,reg43XXr - setreg 434Ch*4,reg43XXr - setreg 434Dh*4,reg43XXr - setreg 434Eh*4,reg43XXr - setreg 434Fh*4,reg43XXr - setreg 4350h*4,reg43XXr - setreg 4351h*4,reg43XXr - setreg 4352h*4,reg43XXr - setreg 4353h*4,reg43XXr - setreg 4354h*4,reg43XXr - setreg 4355h*4,reg43XXr - setreg 4356h*4,reg43XXr - setreg 4357h*4,reg43XXr - setreg 4358h*4,reg43XXr - setreg 4359h*4,reg43XXr - setreg 435Ah*4,reg43XXr - setreg 435Bh*4,reg43XXr - setreg 435Ch*4,reg43XXr - setreg 435Dh*4,reg43XXr - setreg 435Eh*4,reg43XXr - setreg 435Fh*4,reg43XXr - setreg 4360h*4,reg43XXr - setreg 4361h*4,reg43XXr - setreg 4362h*4,reg43XXr - setreg 4363h*4,reg43XXr - setreg 4364h*4,reg43XXr - setreg 4365h*4,reg43XXr - setreg 4366h*4,reg43XXr - setreg 4367h*4,reg43XXr - setreg 4368h*4,reg43XXr - setreg 4369h*4,reg43XXr - setreg 436Ah*4,reg43XXr - setreg 436Bh*4,reg43XXr - setreg 436Ch*4,reg43XXr - setreg 436Dh*4,reg43XXr - setreg 436Eh*4,reg43XXr - setreg 436Fh*4,reg43XXr - setreg 4370h*4,reg43XXr - setreg 4371h*4,reg43XXr - setreg 4372h*4,reg43XXr - setreg 4373h*4,reg43XXr - setreg 4374h*4,reg43XXr - setreg 4375h*4,reg43XXr - setreg 4376h*4,reg43XXr - setreg 4377h*4,reg43XXr - setreg 4378h*4,reg43XXr - setreg 4379h*4,reg43XXr - setreg 437Ah*4,reg43XXr - setreg 437Bh*4,reg43XXr - setreg 437Ch*4,reg43XXr - setreg 437Dh*4,reg43XXr - setreg 437Eh*4,reg43XXr - setreg 437Fh*4,reg43XXr - - cmp byte[SFXEnable],0 - je .nosfx - call initsfxregsr -.nosfx - cmp byte[SA1Enable],0 - je .nosa1 - call initSA1regs -.nosa1 - cmp byte[SDD1Enable],0 - je .nosdd1 - call initSDD1regs -.nosdd1 - cmp byte[SPC7110Enable],0 - je .nospc7110 - call initSPC7110regs -.nospc7110 - cmp byte[RTCEnable],0 - je .noRTC - call RTCReset -.noRTC - ret - -; global variables -SECTION .data -NEWSYM invreg, dw 0 -NEWSYM sndrot, db 0 ; rotates to use A,X or Y for sound skip -NEWSYM sndrot2, db 0 ; rotates a random value for sound skip -NEWSYM INTEnab, db 0 ; enables NMI(7)/VIRQ(5)/HIRQ(4)/JOY(0) -NEWSYM NMIEnab, db 1 ; controlled in e65816 loop. Sets to 81h -NEWSYM VIRQLoc, dw 0 ; VIRQ Y location -NEWSYM vidbright, db 0 ; screen brightness (0 .. 15) -NEWSYM previdbr, db 0 ; previous screen brightness -NEWSYM forceblnk, db 80h ; force blanking on/off ($80=on) -NEWSYM objptr, dd 0 ; pointer to object data in VRAM -NEWSYM objptrn, dd 0 ; pointer2 to object data in VRAM -NEWSYM objsize1, db 1 ; 1 = 8dot, 4=16 dot, 16=32 dot, 64=64dot -NEWSYM objsize2, db 4 ; large object size -NEWSYM objmovs1, db 2 ; number of bytes to move/paragraph -NEWSYM objadds1, dw 14 ; number of bytes to add/paragraph -NEWSYM objmovs2, db 2 ; number of bytes to move/paragraph -NEWSYM objadds2, dw 14 ; number of bytes to add/paragraph -NEWSYM oamaddrt, dw 0 ; oam address -NEWSYM oamaddrs, dw 0 ; oam address at beginning of vblank -NEWSYM objhipr, db 0 ; highest priority object # -NEWSYM bgmode, db 0 ; graphics mode ( 0 .. 7 ) -NEWSYM bg3highst, db 0 ; is 1 if background 3 has the highest priority -NEWSYM bgtilesz, db 0 ; 0 = 8x8, 1 = 16x16, bit 0=bg1,bit1=bg2,etc -NEWSYM mosaicon, db 0 ; mosaic on, bit 0=bg1,bit1=bg2, etc -NEWSYM mosaicsz, db 0 ; mosaic size in pixels -NEWSYM bg1ptr, dw 0 ; pointer to background1 -NEWSYM bg2ptr, dw 0 ; pointer to background2 -NEWSYM bg3ptr, dw 0 ; pointer to background3 -NEWSYM bg4ptr, dw 0 ; pointer to background4 -NEWSYM bg1ptrb, dw 0 ; pointer to background1 -NEWSYM bg2ptrb, dw 0 ; pointer to background2 -NEWSYM bg3ptrb, dw 0 ; pointer to background3 -NEWSYM bg4ptrb, dw 0 ; pointer to background4 -NEWSYM bg1ptrc, dw 0 ; pointer to background1 -NEWSYM bg2ptrc, dw 0 ; pointer to background2 -NEWSYM bg3ptrc, dw 0 ; pointer to background3 -NEWSYM bg4ptrc, dw 0 ; pointer to background4 -NEWSYM bg1ptrd, dw 0 ; pointer to background1 -NEWSYM bg2ptrd, dw 0 ; pointer to background2 -NEWSYM bg3ptrd, dw 0 ; pointer to background3 -NEWSYM bg4ptrd, dw 0 ; pointer to background4 -NEWSYM bg1scsize, db 0 ; bg #1 screen size (0=1x1,1=1x2,2=2x1,3=2x2) -NEWSYM bg2scsize, db 0 ; bg #2 screen size (0=1x1,1=1x2,2=2x1,3=2x2) -NEWSYM bg3scsize, db 0 ; bg #3 screen size (0=1x1,1=1x2,2=2x1,3=2x2) -NEWSYM bg4scsize, db 0 ; bg #4 screen size (0=1x1,1=1x2,2=2x1,3=2x2) -NEWSYM bg1objptr, dw 0 ; pointer to tiles in background1 -NEWSYM bg2objptr, dw 0 ; pointer to tiles in background2 -NEWSYM bg3objptr, dw 0 ; pointer to tiles in background3 -NEWSYM bg4objptr, dw 0 ; pointer to tiles in background4 -NEWSYM bg1scrolx, dw 0 ; background 1 x position -NEWSYM bg2scrolx, dw 0 ; background 2 x position -NEWSYM bg3scrolx, dw 0 ; background 3 x position -NEWSYM bg4scrolx, dw 0 ; background 4 x position -NEWSYM bg1sx, dw 0 ; Temporary Variable for Debugging purposes -NEWSYM bg1scroly, dw 0 ; background 1 y position -NEWSYM bg2scroly, dw 0 ; background 2 y position -NEWSYM bg3scroly, dw 0 ; background 3 y position -NEWSYM bg4scroly, dw 0 ; background 4 y position -NEWSYM addrincr, dw 2 ; vram increment (2,64,128,256) -NEWSYM vramincr, db 0 ; 0 = inrement at 2118/2139, 1 = 2119,213A -NEWSYM vramread, db 0 ; previous character for vram read -NEWSYM vramaddr, dd 0 ; vram address -NEWSYM cgaddr, dw 0 ; cg (palette) address -NEWSYM cgmod, db 0 ; if cgram is modified or not -NEWSYM scrnon, dw 0 ; main & sub screen on -NEWSYM scrndist, db 0 ; which background is disabled -NEWSYM resolutn, dw 224 ; screen resolution -NEWSYM multa, db 0 ; multiplier A -NEWSYM diva, dw 0 ; divisor C -NEWSYM divres, dw 0 ; quotent of divc/divb -NEWSYM multres, dw 0 ; result of multa * multb/remainder of divc/divb -NEWSYM latchx, dw 0 ; latched x value -NEWSYM latchy, dw 0 ; latched y value -NEWSYM latchxr, db 0 ; low or high byte read for x value -NEWSYM latchyr, db 0 ; low or high byte read for y value -NEWSYM frskipper, db 0 ; used to control frame skipping -NEWSYM winl1, db 0 ; window 1 left position -NEWSYM winr1, db 0 ; window 1 right position -NEWSYM winl2, db 0 ; window 2 left position -NEWSYM winr2, db 0 ; window 2 right position -NEWSYM winbg1en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG1 -NEWSYM winbg2en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG2 -NEWSYM winbg3en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG3 -NEWSYM winbg4en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG4 -NEWSYM winobjen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on sprites -NEWSYM wincolen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on backarea -NEWSYM winlogica, db 0 ; Window logic type for BG1 to 4 -NEWSYM winlogicb, db 0 ; Window logic type for Sprites and Backarea -NEWSYM winenabm, db 0 ; Window logic enable for main screen -NEWSYM winenabs, db 0 ; Window logic enable for sub screen -NEWSYM mode7set, db 0 ; mode 7 settings -NEWSYM mode7A, dw 0 ; A value for Mode 7 -NEWSYM mode7B, dw 0 ; B value for Mode 7 -NEWSYM mode7C, dw 0 ; C value for Mode 7 -NEWSYM mode7D, dw 0 ; D value for Mode 7 -NEWSYM mode7X0, dw 0 ; Center X for Mode 7 -NEWSYM mode7Y0, dw 0 ; Center Y for Mode 7 -NEWSYM JoyAPos, db 0 ; Old-Style Joystick Read Position for Joy 1 & 3 -NEWSYM JoyBPos, db 0 ; Old-Style Joystick Read Position for Joy 2 & 4 -NEWSYM compmult, dd 0 ; Complement Multiplication for Mode 7 -NEWSYM joyalt, db 0 ; temporary joystick alternation - -NEWSYM wramrwadr, dd 0 ; continuous read/write to wram address -NEWSYM dmadata, times 129 db 0FFh ; dma data (written from ports 43xx) -NEWSYM irqon, db 0 ; if IRQ has been called (80h) or not (0) -NEWSYM nexthdma, db 0 ; HDMA data to execute once vblank ends -NEWSYM curhdma, db 0 ; Currently executed hdma -NEWSYM hdmadata, times 8*19 db 0 ; 4 dword register addresses, # of bytes to - ; transfer/line, address increment (word) -NEWSYM hdmatype, db 0 ; if first time executing hdma or not -NEWSYM coladdr, db 0 ; red value of color to add -NEWSYM coladdg, db 0 ; green value of color to add -NEWSYM coladdb, db 0 ; blue value of color to add -NEWSYM colnull, db 0 ; keep this 0 (when accessing colors by dword) -NEWSYM scaddset, db 0 ; screen/fixed color addition settings -NEWSYM scaddtype, db 0 ; which screen to add/sub -NEWSYM Voice0Disabl2, db 1 ; Disable Voice 0 -NEWSYM Voice1Disabl2, db 1 ; Disable Voice 1 -NEWSYM Voice2Disabl2, db 1 ; Disable Voice 2 -NEWSYM Voice3Disabl2, db 1 ; Disable Voice 3 -NEWSYM Voice4Disabl2, db 1 ; Disable Voice 4 -NEWSYM Voice5Disabl2, db 1 ; Disable Voice 5 -NEWSYM Voice6Disabl2, db 1 ; Disable Voice 6 -NEWSYM Voice7Disabl2, db 1 ; Disable Voice 7 - -NEWSYM oamram, times 1024 db 0 ; OAMRAM (544 bytes) -NEWSYM cgram, times 512 db 0 ; CGRAM -NEWSYM pcgram, times 512 db 0 ; Previous CGRAM - -NEWSYM vraminctype, db 0 - -; New variables -NEWSYM vramincby8on, db 0 ; if increment by 8 is on -NEWSYM vramincby8left, db 0 ; how many left -NEWSYM vramincby8totl, db 0 ; how many in total (32,64,128) -NEWSYM vramincby8rowl, db 0 ; how many left in that row (start at 8) -NEWSYM vramincby8ptri, dw 0 ; increment by how many when rowl = 0 - -NEWSYM nexthprior, db 0 -NEWSYM doirqnext, db 0 - -NEWSYM vramincby8var, dw 0 -NEWSYM screstype, db 0 -NEWSYM extlatch, db 0 -NEWSYM cfield, db 0 -NEWSYM interlval, db 0 - -NEWSYM HIRQLoc, dw 0 ; HIRQ X location - -NEWSYM KeyOnStA, db 0 -NEWSYM KeyOnStB, db 0 - -NEWSYM SDD1BankA, db 0 -NEWSYM SDD1BankB, db 1 -NEWSYM SDD1BankC, db 2 -NEWSYM SDD1BankD, db 3 -NEWSYM vramread2, db 0 ; previous character for vram read -NEWSYM nosprincr, db 0 -NEWSYM poamaddrs, dw 0 -NEWSYM ioportval, db 255 -NEWSYM iohvlatch, db 0 -NEWSYM ppustatus, db 0 -NEWSYM hdmastartsc, db 0 -NEWSYM hdmarestart, db 0 -NEWSYM hdmadelay, db 0 -NEWSYM nohdmaframe, db 0 ; no hdma for current frame - -NEWSYM tempdat, times 474 db 0 ; expandable area - -num2writeppureg equ $-sndrot -; pharos equ hack *sigh* -NEWSYM PHnum2writeppureg, dd num2writeppureg - -NEWSYM scrndis, db 0 ; which background is disabled - -ALIGN32 -NEWSYM oamaddr, dd 0 ; oam address - -NEWSYM bg1ptrx, dd 0 ; pointer to background1 -NEWSYM bg2ptrx, dd 0 ; pointer to background2 -NEWSYM bg3ptrx, dd 0 ; pointer to background3 -NEWSYM bg4ptrx, dd 0 ; pointer to background4 - -NEWSYM bg1ptry, dd 0 ; pointer to background1 -NEWSYM bg2ptry, dd 0 ; pointer to background2 -NEWSYM bg3ptry, dd 0 ; pointer to background3 -NEWSYM bg4ptry, dd 0 ; pointer to background4 - -NEWSYM Voice0Disable, db 1 ; Disable Voice 0 -NEWSYM Voice1Disable, db 1 ; Disable Voice 1 -NEWSYM Voice2Disable, db 1 ; Disable Voice 2 -NEWSYM Voice3Disable, db 1 ; Disable Voice 3 -NEWSYM Voice4Disable, db 1 ; Disable Voice 4 -NEWSYM Voice5Disable, db 1 ; Disable Voice 5 -NEWSYM Voice6Disable, db 1 ; Disable Voice 6 -NEWSYM Voice7Disable, db 1 ; Disable Voice 7 - -NEWSYM BG116x16t, db 0 -NEWSYM BG216x16t, db 0 -NEWSYM BG316x16t, db 0 -NEWSYM BG416x16t, db 0 -NEWSYM SPC700read, dd 0 -NEWSYM SPC700write, dd 0 - -NEWSYM JoyCRead, db 0 - -NEWSYM nssdip1, db 0 -NEWSYM nssdip2, db 0 -NEWSYM nssdip3, db 0 -NEWSYM nssdip4, db 0 -NEWSYM nssdip5, db 0 -NEWSYM nssdip6, db 0 - -SECTION .text - -NEWSYM ClearRegs - mov word[VIRQLoc],0 - mov word[bg1ptr],0 - mov word[bg2ptr],0 - mov word[bg3ptr],0 - mov word[bg4ptr],0 - mov word[bg1ptrb],0 - mov word[bg2ptrb],0 - mov word[bg3ptrb],0 - mov word[bg4ptrb],0 - mov word[bg1ptrc],0 - mov word[bg2ptrc],0 - mov word[bg3ptrc],0 - mov word[bg4ptrc],0 - mov word[bg1ptrd],0 - mov word[bg2ptrd],0 - mov word[bg3ptrd],0 - mov word[bg4ptrd],0 - mov word[bg1objptr],0 - mov word[bg2objptr],0 - mov word[bg3objptr],0 - mov word[bg4objptr],0 - mov byte[ioportval],0FFh - mov byte[hdmastartsc],0 - mov byte[hdmarestart],0 - mov byte[nohdmaframe],0 - mov byte[hdmadelay],0 - ret - -reg2100r: - mov al,[vidbright] - or al,[forceblnk] - ret - -; Multiply Result Low -reg2134r: - checkmultchange - mov al,[compmult] - ret - -; Multiply Result Middle -reg2135r: - checkmultchange - mov al,[compmult+1] - ret - -; Multiply Result High -reg2136r: - checkmultchange - mov al,[compmult+2] - ret - -; Software latch for horizontal/vertical counter -reg2137r: -; mov byte[debstop3],1 - cmp byte[debuggeron],1 - je .debugger - cmp byte[iohvlatch],1 - je .dolatch - test byte[ioportval],80h - jz .nolatch -.dolatch - xor ebx,ebx - mov bl,[cycpl] - sub bl,dh - add bx,bx - mov [latchx],bx - mov bx,[curypos] - mov [latchy],bx - mov bl,[INTEnab] - and bl,30h - cmp bl,30h - jne .novhirq - cmp word[HIRQLoc],0F0h - ja .incry - cmp dh,20 - jae .noincly -.incry - inc word[latchy] -.novhirq -.noincly -.nolatch - xor al,al - mov byte[extlatch],0 - ret -.debugger -debblah: - cmp byte[iohvlatch],1 - je .dolatch2 - test byte[ioportval],80h - jz near .nolatch2 -.dolatch2 - xor ebx,ebx - mov bl,[cycpl] - sub bl,[pdh] - add bx,bx - mov [latchx],bx - mov bx,[curypos] - mov [latchy],bx - mov bl,[INTEnab] - and bl,30h - cmp bl,30h - jne .novhirq - cmp word[HIRQLoc],0F0h -; ja .incry - cmp word[latchx],80 -; jb .noincly -.incry - inc word[latchy] -.novhirq -.noincly - xor al,al - mov byte[extlatch],0 - ret - - push eax - push edx - xor eax,eax - xor ebx,ebx - mov al,[cycpl] - sub al,[pdh] - mov bx,339 - mul bx - xor ebx,ebx - mov bl,[cycpl] - div bx - mov [latchx],ax - pop edx - pop eax - mov bx,[curypos] - mov [latchy],bx - mov bl,[INTEnab] - and bl,30h - cmp bl,30h - jne .novhirq2 - cmp word[HIRQLoc],0F0h - ja .incry2 - cmp word[latchx],80 - jb .noincly2 -.incry2 - inc word[latchy] -.novhirq2 -.noincly2 -.nolatch2 - xor al,al - mov byte[extlatch],0 - ret - -; Read OAM Data (Low, High) -reg2138r: - xor ebx,ebx - mov bx,[oamaddr] - add ebx,oamram - mov al,[ebx] - inc word[oamaddr] - cmp word[oamaddr],543 - ja .wrapoam - ret -.wrapoam - mov word[oamaddr],0 - ret - -; Read VRAM Data (Low) -reg2139r: - mov al,[vramread] - - xor ebx,ebx - mov bx,[vramaddr] - add ebx,[vram] - mov bl,[ebx] - mov [vramread],bl - - cmp byte[vramincr],0 - je near .noincr - mov bx,[addrincr] - add [vramaddr],bx - cmp byte[vramincby8on],1 - jne .noincr - dec byte[vramincby8left] - jnz .noincr - - add word[vramaddr],2 - mov bl,[vramincby8totl] - mov [vramincby8left],bl - dec byte[vramincby8rowl] - jz .nextrow - mov bx,[vramincby8ptri] - sub [vramaddr],bx - jmp .noincr -.nextrow - mov byte[vramincby8rowl],8 - sub word[vramaddr],16 -.noincr - ret - -; Read VRAM Data (High) -reg213Ar: - mov al,[vramread2] - - xor ebx,ebx - mov bx,[vramaddr] - add ebx,[vram] - mov bl,[ebx+1] - mov [vramread2],bl - - cmp byte[vramincr],1 - je near .noincr - mov bx,[addrincr] - add [vramaddr],bx - cmp byte[vramincby8on],1 - jne .noincr - dec byte[vramincby8left] - jnz .noincr - - add word[vramaddr],2 - mov bl,[vramincby8totl] - mov [vramincby8left],bl - dec byte[vramincby8rowl] - jz .nextrow - mov bx,[vramincby8ptri] - sub [vramaddr],bx - jmp .noincr -.nextrow - mov byte[vramincby8rowl],8 - sub word[vramaddr],16 -.noincr - ret - -; Read CGRAM Data -reg213Br: - xor ebx,ebx - mov bx,[cgaddr] - mov al,[cgram+ebx] - inc word[cgaddr] - and word[cgaddr],01FFh - ret - -; H counter data by external or software latch -reg213Cr: - cmp byte[latchxr],1 - je .highv - mov al,[latchx] - mov byte[latchxr],1 - ret -.highv - mov al,[latchx] - and al,0FEh - or al,byte[latchx+1] - mov byte[latchxr],0 - ret - -; V counter data by external or software latch -reg213Dr: - cmp byte[latchyr],2 ; hack for games that don't read 213F - je .noreset - cmp byte[latchyr],1 - je .highv - mov al,[latchy] - mov byte[latchyr],1 - ret -.highv - mov al,[latchy] - and al,0FEh - or al,byte[latchy+1] - mov byte[latchyr],0 - ret -.noreset - mov al,[latchy] - and al,0FEh - or al,byte[latchy+1] - ret -; PPU Status Flag & Version number (OBJ over flags) -reg213Er: - mov al,01h - ret - -; PPU Status Flag & Version number (NTSC/PAL/EXTRN Latch flag) -reg213Fr: -; mov byte[debstop3],1 - mov al,[romispal] - shl al,4 - or al,[ppustatus] - or al,[cfield] - mov byte[latchxr],0 - mov byte[latchyr],0 - or al,[extlatch] - ret - -; Sound Reg #1 -reg2140r: - cmp byte[spcon],0 - je .nosound - inc dword[SPC700read] - mov al,[reg1read] - mov byte[spcnumread],0 - ret -.nosound - ; Find for D0 - mov ebx,esi - cmp word[ebx],0FB10h - jne .noret - mov word[ebx],0EAEAh -.noret - mov al,5 -.tryagain - cmp byte[ebx],0D0h - je .foundit - inc ebx - dec al - jnz .tryagain - jmp .notfound -.foundit - mov byte[ebx],0EAh - mov byte[ebx+1],0EAh -.notfound - inc byte[sndrot2] - cmp byte[sndrot2],3 - jne .a - mov byte[sndrot2],0 -.a - xor al,al - test byte[sndrot2],01h - jz .n - mov al,[xa] -.n - ret - -; Sound Reg #2 -reg2141r: - cmp byte[spcon],0 - je .nosound - inc dword[SPC700read] - mov al,[reg2read] - mov byte[spcnumread],0 - ret -.nosound - ; Find for D0 - mov ebx,esi - mov al,3 -.tryagain - cmp byte[ebx],0D0h - je .foundit - inc ebx - dec al - jnz .tryagain - jmp .notfound -.foundit - mov byte[ebx],0EAh - mov byte[ebx+1],0EAh -.notfound - xor byte[sndrot],01h - mov al,[xa+1] - test byte[sndrot],01h - jz .n - mov al,[xa] -.n - ret - -; Sound Reg #3 -reg2142r: - cmp byte[spcon],0 - je .nosound - inc dword[SPC700read] - mov al,[reg3read] - mov byte[spcnumread],0 - ret -.nosound - ; Find for D0 - mov ebx,esi - mov al,3 -.tryagain - cmp byte[ebx],0D0h - je .foundit - inc ebx - dec al - jnz .tryagain - jmp .notfound -.foundit - mov byte[ebx],0EAh - mov byte[ebx+1],0EAh -.notfound - mov al,[xa] - test byte[sndrot],01h - jz .n - mov al,[xa+1] -.n - ret - -; Sound Reg #4 -reg2143r: - cmp byte[spcon],0 - je .nosound - inc dword[SPC700read] - mov al,[reg4read] - mov byte[spcnumread],0 - ret -.nosound - ; Find for D0 - mov ebx,esi - mov al,3 -.tryagain - cmp byte[ebx],0D0h - je .foundit - inc ebx - dec al - jnz .tryagain - jmp .notfound -.foundit - mov byte[ebx],0EAh - mov byte[ebx+1],0EAh -.notfound - mov al,[xa+1] - ret - -reg2144r: - xor al,al - ret - -; WRAM Read -reg2180r: - mov ebx,[wramrwadr] - add ebx,[wramdata] - mov al,[ebx] - inc dword[wramrwadr] - and dword[wramrwadr],01FFFFh - ret - -; Unknown register, used by test cart - -reg21C2r: -reg21C3r: - mov al,21h - ret - -; Joystick Data for controller 1 and 2 - -reg4016r: - xor al,al - test dword[JoyANow],80000000h - jz .noal - mov al,1 -.noal - rol dword[JoyANow],1 - ret - -SECTION .bss -NEWSYM MultiTap, resb 1 -SECTION .text - -; Joystick Data for controller 2 and 4 -reg4017r: - cmp byte[snesmouse],0 - jne .nomultitap - cmp byte[MultiTap],1 - je .multitap -.nomultitap - xor al,al - test dword[JoyBNow],80000000h - jz .noal - mov al,1 -.noal - rol dword[JoyBNow],1 - ret -.multitap - test byte[MultiTapStat],1 - jz .no1 - mov al,0FFh - ret -.no1 - test byte[MultiTapStat],80h - jz .contr45 - xor al,al - test dword[JoyBNow],80000000h - jz .nojb - or al,01h -.nojb - test dword[JoyCNow],80000000h - jz .nojc - or al,02h -.nojc - rol dword[JoyBNow],1 - rol dword[JoyCNow],1 - ret -.contr45 - xor al,al - test dword[JoyDNow],80000000h - jz .nojd - or al,1 -.nojd - test dword[JoyENow],80000000h - jz .noje - or al,02h -.noje - rol dword[JoyDNow],1 - rol dword[JoyENow],1 - ret - -reg4100r: - xor al,al - cmp byte[nssdip1],1 - jne .nodip1 - mov al,1 -.nodip1 - cmp byte[nssdip2],1 - jne .nodip2 - or al,02h -.nodip2 - cmp byte[nssdip3],1 - jne .nodip3 - or al,04h -.nodip3 - cmp byte[nssdip4],1 - jne .nodip4 - or al,08h -.nodip4 - cmp byte[nssdip5],1 - jne .nodip5 - or al,10h -.nodip5 - cmp byte[nssdip6],1 - jne .nodip6 - or al,20h -.nodip6 - ret - -reg420Ar: -reg420Br: -reg420Cr: -reg420Dr: -reg420Er: -reg420Fr: - xor al,al - ret - -; NMI Check Register -reg4210r: - mov al,[NMIEnab] - cmp byte[curnmi],0 - jne .nmi - mov byte[NMIEnab],01h -.nmi - mov byte[curnmi],0 - ret - -; Video IRQ Register -reg4211r: - mov al,[irqon] - mov byte[irqon],0 - cmp dh,[cycphb] - jae .nohblank - or al,40h -.nohblank - ret - -SECTION .bss -NEWSYM hblank, resb 1 -SECTION .text - -; H/V Blank Flag & Joystick Controller Enable Flag -; bit 7 = vblank, 0=out,1=in, bit 6 = hblank, 0=out,1=in, bit 0 = joystick on -reg4212r: - xor al,al - cmp byte[joycontren],25 - jb .nojoyc -.yesjoy - mov al,1 -.nojoyc - inc byte[joycontren] - cmp byte[joycontren],50 - jne .n - mov byte[joycontren],0 -.n - cmp byte[debuggeron],1 - je .debugger - mov bx,[resolutn] - cmp word[curypos],bx - jne .notres - cmp byte[nmistatus],2 - je .vblank -.notres - inc bx - cmp word[curypos],bx - jb .novbl - mov bx,[totlines] - dec bx - cmp word[curypos],bx - jae .novbl -.vblank - or al,80h -; jmp .nohblank -.novbl - mov byte[hblank],0 - cmp dh,[cycphb] - jae .nohblank - mov byte[hblank],1 - or al,40h -.nohblank - test byte[INTEnab],01h - jz .nojoy - mov bx,[resolutn] - add bx,2 - cmp word[curypos],bx - jne .nojoy - cmp dh,5 - ja .nojoy - ret -.nojoy - ret -.debugger -debblah2: - push edx - mov dh,[pdh] - mov bx,[resolutn] - cmp word[curypos],bx - jne .notres - cmp byte[nmistatus],2 - je .vblank -.notres - inc bx - cmp word[curypos],bx - jb .novbl - mov bx,[totlines] - dec bx - cmp word[curypos],bx - jae .novbl -.vblank - or al,80h -; jmp .nohblank -.novbl - cmp dh,[cycphb] - jae .nohblank - or al,40h -.nohblank - test byte[INTEnab],01h - jz .nojoy - mov bx,[resolutn] - add bx,2 - cmp word[curypos],bx - jne .nojoy - cmp dh,5 - ja .nojoy - pop edx - ret -.nojoy - pop edx - ret - - mov bx,[resolutn] - inc bx - cmp word[curypos],bx - jb .novbl2 - or al,80h - jmp .nohblank2 -.novbl2 - mov bl,[pdh] - cmp bl,[cycphb] - jae .nohblank2 - or al,40h -.nohblank2 - test byte[INTEnab],01h - jz .nojoy2 - mov bx,[resolutn] - add bx,2 - cmp word[curypos],bx - jne .nojoy2 - cmp byte[pdh],5 - ja .nojoy -; or al,01h - ret -.nojoy2 - ret - -; Programmable I/O port -reg4213r: - mov al,[ioportval] - ret - -; Quotent of Divide Result (Low) -reg4214r: - mov al,[divres] - ret - -; Quotent of Divide Result (High) -reg4215r: - mov al,[divres+1] - ret - -; Product of Multiplication Result or Remainder of Divide Result (Low) -reg4216r: - mov al,[multres] - ret - -; Product of Multiplication Result or Remainder of Divide Result (High) -reg4217r: - mov al,[multres+1] - ret - -; Joystick 1 Low -; bit7=X,bit6=Y,bit5=L,bit4=R -reg4218r: - mov al,[JoyAOrig+2] - ret - -; Joystick 1 High -; bit7=A,bit6=B,bit5=Sel,bit4=Start,bit3=up,bit2=down,bit1=left,bit0=right -reg4219r: - mov al,[JoyAOrig+3] - ret - -; Joystick 2 Low -reg421Ar: - mov al,[JoyBOrig+2] - ret - -; Joystick 2 High -reg421Br: - mov al,[JoyBOrig+3] - ret - -; Joystick 3 Low -reg421Cr: - mov al,[JoyDOrig+2] - ret - -; Joystick 3 High -reg421Dr: - mov al,[JoyDOrig+3] - ret - -; Joystick 4 Low -reg421Er: - mov al,[JoyCOrig+2] - ret - -; Joystick 4 High -reg421Fr: - mov al,[JoyCOrig+3] - ret - -; DMA Reader -reg43XXr: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov al,[dmadata+ebx] - ret - -regINVALID: ; Invalid Register - cmp cx,2100h - jb .cleared - mov al,ch - cmp byte[SPC7110Enable],0 - je .nospc7110 -.cleared - xor al,al -.nospc7110 -; mov byte[debstop3],1 - ret - - mov al,[previdmode] - mov ah,0 - int 10h - mov byte[invalid],1 - mov [invreg],cx - mov ah,9 - mov edx,.invalidreg - int 21h - xor eax,eax - mov ax,[invreg] - call printhex - mov ah,2 - mov dl,13 - int 21h - mov ah,2 - mov dl,10 - int 21h - mov eax,[numinst] ;Temporary - call printnum - jmp DosExit - -SECTION .data -.invalidreg db 'Invalid Read Register : $' -SECTION .text - - - - +;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) +; +;http://www.zsnes.com +;http://sourceforge.net/projects/zsnes +; +;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. + + + +EXTSYM SFXEnable,regptr,initsfxregsr,initSA1regs,SA1Enable,initSDD1regs +EXTSYM SPC7110Enable,initSPC7110regs,RTCEnable,RTCReset,curypos,cycpl +EXTSYM debuggeron,pdh,vram,romispal,reg1read,spcnumread,spcon,reg2read,reg3read +EXTSYM reg4read,JoyEOrig,JoyENow,snesmouse,cycphb,joycontren,totlines,DosExit +EXTSYM invalid,numinst,previdmode,printhex,printnum + +SECTION .text + +NEWSYM initregr + ; Fill register pointer with invalid register accesses + mov edi,[regptr] + add edi,8000h + mov ecx,3000h + mov eax,regINVALID +.loopa + mov [edi],eax + add edi,4 + dec ecx + jnz .loopa + ; Set all valid register accesses + setreg 2100h*4,reg2100r + setreg 2134h*4,reg2134r + setreg 2135h*4,reg2135r + setreg 2136h*4,reg2136r + setreg 2137h*4,reg2137r + setreg 2138h*4,reg2138r + setreg 2139h*4,reg2139r + setreg 213Ah*4,reg213Ar + setreg 213Bh*4,reg213Br + setreg 213Ch*4,reg213Cr + setreg 213Dh*4,reg213Dr + setreg 213Eh*4,reg213Er + setreg 213Fh*4,reg213Fr + setreg 2140h*4,reg2140r + setreg 2141h*4,reg2141r + setreg 2142h*4,reg2142r + setreg 2143h*4,reg2143r + setreg 2144h*4,reg2140r + setreg 2180h*4,reg2180r + setreg 21C2h*4,reg21C2r + setreg 21C3h*4,reg21C3r + + setreg 4016h*4,reg4016r + setreg 4017h*4,reg4017r + + setreg 4100h*4,reg4100r + + setreg 420Ah*4,reg420Ar + setreg 420Bh*4,reg420Br + setreg 420Ch*4,reg420Cr + setreg 420Dh*4,reg420Dr + setreg 420Eh*4,reg420Er + setreg 420Fh*4,reg420Fr + + setreg 4210h*4,reg4210r + setreg 4211h*4,reg4211r + setreg 4212h*4,reg4212r + setreg 4213h*4,reg4213r + setreg 4214h*4,reg4214r + setreg 4215h*4,reg4215r + setreg 4216h*4,reg4216r + setreg 4217h*4,reg4217r + setreg 4218h*4,reg4218r + setreg 4219h*4,reg4219r + setreg 421Ah*4,reg421Ar + setreg 421Bh*4,reg421Br + setreg 421Ch*4,reg421Cr + setreg 421Dh*4,reg421Dr + setreg 421Eh*4,reg421Er + setreg 421Fh*4,reg421Fr + + setreg 4300h*4,reg43XXr + setreg 4301h*4,reg43XXr + setreg 4302h*4,reg43XXr + setreg 4303h*4,reg43XXr + setreg 4304h*4,reg43XXr + setreg 4305h*4,reg43XXr + setreg 4306h*4,reg43XXr + setreg 4307h*4,reg43XXr + setreg 4308h*4,reg43XXr + setreg 4309h*4,reg43XXr + setreg 430Ah*4,reg43XXr + setreg 430Bh*4,reg43XXr + setreg 430Ch*4,reg43XXr + setreg 430Dh*4,reg43XXr + setreg 430Eh*4,reg43XXr + setreg 430Fh*4,reg43XXr + setreg 4310h*4,reg43XXr + setreg 4311h*4,reg43XXr + setreg 4312h*4,reg43XXr + setreg 4313h*4,reg43XXr + setreg 4314h*4,reg43XXr + setreg 4315h*4,reg43XXr + setreg 4316h*4,reg43XXr + setreg 4317h*4,reg43XXr + setreg 4318h*4,reg43XXr + setreg 4319h*4,reg43XXr + setreg 431Ah*4,reg43XXr + setreg 431Bh*4,reg43XXr + setreg 431Ch*4,reg43XXr + setreg 431Dh*4,reg43XXr + setreg 431Eh*4,reg43XXr + setreg 431Fh*4,reg43XXr + setreg 4320h*4,reg43XXr + setreg 4321h*4,reg43XXr + setreg 4322h*4,reg43XXr + setreg 4323h*4,reg43XXr + setreg 4324h*4,reg43XXr + setreg 4325h*4,reg43XXr + setreg 4326h*4,reg43XXr + setreg 4327h*4,reg43XXr + setreg 4328h*4,reg43XXr + setreg 4329h*4,reg43XXr + setreg 432Ah*4,reg43XXr + setreg 432Bh*4,reg43XXr + setreg 432Ch*4,reg43XXr + setreg 432Dh*4,reg43XXr + setreg 432Eh*4,reg43XXr + setreg 432Fh*4,reg43XXr + setreg 4330h*4,reg43XXr + setreg 4331h*4,reg43XXr + setreg 4332h*4,reg43XXr + setreg 4333h*4,reg43XXr + setreg 4334h*4,reg43XXr + setreg 4335h*4,reg43XXr + setreg 4336h*4,reg43XXr + setreg 4337h*4,reg43XXr + setreg 4338h*4,reg43XXr + setreg 4339h*4,reg43XXr + setreg 433Ah*4,reg43XXr + setreg 433Bh*4,reg43XXr + setreg 433Ch*4,reg43XXr + setreg 433Dh*4,reg43XXr + setreg 433Eh*4,reg43XXr + setreg 433Fh*4,reg43XXr + setreg 4340h*4,reg43XXr + setreg 4341h*4,reg43XXr + setreg 4342h*4,reg43XXr + setreg 4343h*4,reg43XXr + setreg 4344h*4,reg43XXr + setreg 4345h*4,reg43XXr + setreg 4346h*4,reg43XXr + setreg 4347h*4,reg43XXr + setreg 4348h*4,reg43XXr + setreg 4349h*4,reg43XXr + setreg 434Ah*4,reg43XXr + setreg 434Bh*4,reg43XXr + setreg 434Ch*4,reg43XXr + setreg 434Dh*4,reg43XXr + setreg 434Eh*4,reg43XXr + setreg 434Fh*4,reg43XXr + setreg 4350h*4,reg43XXr + setreg 4351h*4,reg43XXr + setreg 4352h*4,reg43XXr + setreg 4353h*4,reg43XXr + setreg 4354h*4,reg43XXr + setreg 4355h*4,reg43XXr + setreg 4356h*4,reg43XXr + setreg 4357h*4,reg43XXr + setreg 4358h*4,reg43XXr + setreg 4359h*4,reg43XXr + setreg 435Ah*4,reg43XXr + setreg 435Bh*4,reg43XXr + setreg 435Ch*4,reg43XXr + setreg 435Dh*4,reg43XXr + setreg 435Eh*4,reg43XXr + setreg 435Fh*4,reg43XXr + setreg 4360h*4,reg43XXr + setreg 4361h*4,reg43XXr + setreg 4362h*4,reg43XXr + setreg 4363h*4,reg43XXr + setreg 4364h*4,reg43XXr + setreg 4365h*4,reg43XXr + setreg 4366h*4,reg43XXr + setreg 4367h*4,reg43XXr + setreg 4368h*4,reg43XXr + setreg 4369h*4,reg43XXr + setreg 436Ah*4,reg43XXr + setreg 436Bh*4,reg43XXr + setreg 436Ch*4,reg43XXr + setreg 436Dh*4,reg43XXr + setreg 436Eh*4,reg43XXr + setreg 436Fh*4,reg43XXr + setreg 4370h*4,reg43XXr + setreg 4371h*4,reg43XXr + setreg 4372h*4,reg43XXr + setreg 4373h*4,reg43XXr + setreg 4374h*4,reg43XXr + setreg 4375h*4,reg43XXr + setreg 4376h*4,reg43XXr + setreg 4377h*4,reg43XXr + setreg 4378h*4,reg43XXr + setreg 4379h*4,reg43XXr + setreg 437Ah*4,reg43XXr + setreg 437Bh*4,reg43XXr + setreg 437Ch*4,reg43XXr + setreg 437Dh*4,reg43XXr + setreg 437Eh*4,reg43XXr + setreg 437Fh*4,reg43XXr + + cmp byte[SFXEnable],0 + je .nosfx + call initsfxregsr +.nosfx + cmp byte[SA1Enable],0 + je .nosa1 + call initSA1regs +.nosa1 + cmp byte[SDD1Enable],0 + je .nosdd1 + call initSDD1regs +.nosdd1 + cmp byte[SPC7110Enable],0 + je .nospc7110 + call initSPC7110regs +.nospc7110 + cmp byte[RTCEnable],0 + je .noRTC + call RTCReset +.noRTC + ret + +; global variables +SECTION .data +NEWSYM invreg, dw 0 +NEWSYM sndrot, db 0 ; rotates to use A,X or Y for sound skip +NEWSYM sndrot2, db 0 ; rotates a random value for sound skip +NEWSYM INTEnab, db 0 ; enables NMI(7)/VIRQ(5)/HIRQ(4)/JOY(0) +NEWSYM NMIEnab, db 1 ; controlled in e65816 loop. Sets to 81h +NEWSYM VIRQLoc, dw 0 ; VIRQ Y location +NEWSYM vidbright, db 0 ; screen brightness (0 .. 15) +NEWSYM previdbr, db 0 ; previous screen brightness +NEWSYM forceblnk, db 80h ; force blanking on/off ($80=on) +NEWSYM objptr, dd 0 ; pointer to object data in VRAM +NEWSYM objptrn, dd 0 ; pointer2 to object data in VRAM +NEWSYM objsize1, db 1 ; 1 = 8dot, 4=16 dot, 16=32 dot, 64=64dot +NEWSYM objsize2, db 4 ; large object size +NEWSYM objmovs1, db 2 ; number of bytes to move/paragraph +NEWSYM objadds1, dw 14 ; number of bytes to add/paragraph +NEWSYM objmovs2, db 2 ; number of bytes to move/paragraph +NEWSYM objadds2, dw 14 ; number of bytes to add/paragraph +NEWSYM oamaddrt, dw 0 ; oam address +NEWSYM oamaddrs, dw 0 ; oam address at beginning of vblank +NEWSYM objhipr, db 0 ; highest priority object # +NEWSYM bgmode, db 0 ; graphics mode ( 0 .. 7 ) +NEWSYM bg3highst, db 0 ; is 1 if background 3 has the highest priority +NEWSYM bgtilesz, db 0 ; 0 = 8x8, 1 = 16x16, bit 0=bg1,bit1=bg2,etc +NEWSYM mosaicon, db 0 ; mosaic on, bit 0=bg1,bit1=bg2, etc +NEWSYM mosaicsz, db 0 ; mosaic size in pixels +NEWSYM bg1ptr, dw 0 ; pointer to background1 +NEWSYM bg2ptr, dw 0 ; pointer to background2 +NEWSYM bg3ptr, dw 0 ; pointer to background3 +NEWSYM bg4ptr, dw 0 ; pointer to background4 +NEWSYM bg1ptrb, dw 0 ; pointer to background1 +NEWSYM bg2ptrb, dw 0 ; pointer to background2 +NEWSYM bg3ptrb, dw 0 ; pointer to background3 +NEWSYM bg4ptrb, dw 0 ; pointer to background4 +NEWSYM bg1ptrc, dw 0 ; pointer to background1 +NEWSYM bg2ptrc, dw 0 ; pointer to background2 +NEWSYM bg3ptrc, dw 0 ; pointer to background3 +NEWSYM bg4ptrc, dw 0 ; pointer to background4 +NEWSYM bg1ptrd, dw 0 ; pointer to background1 +NEWSYM bg2ptrd, dw 0 ; pointer to background2 +NEWSYM bg3ptrd, dw 0 ; pointer to background3 +NEWSYM bg4ptrd, dw 0 ; pointer to background4 +NEWSYM bg1scsize, db 0 ; bg #1 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg2scsize, db 0 ; bg #2 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg3scsize, db 0 ; bg #3 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg4scsize, db 0 ; bg #4 screen size (0=1x1,1=1x2,2=2x1,3=2x2) +NEWSYM bg1objptr, dw 0 ; pointer to tiles in background1 +NEWSYM bg2objptr, dw 0 ; pointer to tiles in background2 +NEWSYM bg3objptr, dw 0 ; pointer to tiles in background3 +NEWSYM bg4objptr, dw 0 ; pointer to tiles in background4 +NEWSYM bg1scrolx, dw 0 ; background 1 x position +NEWSYM bg2scrolx, dw 0 ; background 2 x position +NEWSYM bg3scrolx, dw 0 ; background 3 x position +NEWSYM bg4scrolx, dw 0 ; background 4 x position +NEWSYM bg1sx, dw 0 ; Temporary Variable for Debugging purposes +NEWSYM bg1scroly, dw 0 ; background 1 y position +NEWSYM bg2scroly, dw 0 ; background 2 y position +NEWSYM bg3scroly, dw 0 ; background 3 y position +NEWSYM bg4scroly, dw 0 ; background 4 y position +NEWSYM addrincr, dw 2 ; vram increment (2,64,128,256) +NEWSYM vramincr, db 0 ; 0 = inrement at 2118/2139, 1 = 2119,213A +NEWSYM vramread, db 0 ; previous character for vram read +NEWSYM vramaddr, dd 0 ; vram address +NEWSYM cgaddr, dw 0 ; cg (palette) address +NEWSYM cgmod, db 0 ; if cgram is modified or not +NEWSYM scrnon, dw 0 ; main & sub screen on +NEWSYM scrndist, db 0 ; which background is disabled +NEWSYM resolutn, dw 224 ; screen resolution +NEWSYM multa, db 0 ; multiplier A +NEWSYM diva, dw 0 ; divisor C +NEWSYM divres, dw 0 ; quotent of divc/divb +NEWSYM multres, dw 0 ; result of multa * multb/remainder of divc/divb +NEWSYM latchx, dw 0 ; latched x value +NEWSYM latchy, dw 0 ; latched y value +NEWSYM latchxr, db 0 ; low or high byte read for x value +NEWSYM latchyr, db 0 ; low or high byte read for y value +NEWSYM frskipper, db 0 ; used to control frame skipping +NEWSYM winl1, db 0 ; window 1 left position +NEWSYM winr1, db 0 ; window 1 right position +NEWSYM winl2, db 0 ; window 2 left position +NEWSYM winr2, db 0 ; window 2 right position +NEWSYM winbg1en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG1 +NEWSYM winbg2en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG2 +NEWSYM winbg3en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG3 +NEWSYM winbg4en, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on BG4 +NEWSYM winobjen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on sprites +NEWSYM wincolen, db 0 ; Win1 on (IN/OUT) or Win2 on (IN/OUT) on backarea +NEWSYM winlogica, db 0 ; Window logic type for BG1 to 4 +NEWSYM winlogicb, db 0 ; Window logic type for Sprites and Backarea +NEWSYM winenabm, db 0 ; Window logic enable for main screen +NEWSYM winenabs, db 0 ; Window logic enable for sub screen +NEWSYM mode7set, db 0 ; mode 7 settings +NEWSYM mode7A, dw 0 ; A value for Mode 7 +NEWSYM mode7B, dw 0 ; B value for Mode 7 +NEWSYM mode7C, dw 0 ; C value for Mode 7 +NEWSYM mode7D, dw 0 ; D value for Mode 7 +NEWSYM mode7X0, dw 0 ; Center X for Mode 7 +NEWSYM mode7Y0, dw 0 ; Center Y for Mode 7 +NEWSYM JoyAPos, db 0 ; Old-Style Joystick Read Position for Joy 1 & 3 +NEWSYM JoyBPos, db 0 ; Old-Style Joystick Read Position for Joy 2 & 4 +NEWSYM compmult, dd 0 ; Complement Multiplication for Mode 7 +NEWSYM joyalt, db 0 ; temporary joystick alternation + +NEWSYM wramrwadr, dd 0 ; continuous read/write to wram address +NEWSYM dmadata, times 129 db 0FFh ; dma data (written from ports 43xx) +NEWSYM irqon, db 0 ; if IRQ has been called (80h) or not (0) +NEWSYM nexthdma, db 0 ; HDMA data to execute once vblank ends +NEWSYM curhdma, db 0 ; Currently executed hdma +NEWSYM hdmadata, times 8*19 db 0 ; 4 dword register addresses, # of bytes to + ; transfer/line, address increment (word) +NEWSYM hdmatype, db 0 ; if first time executing hdma or not +NEWSYM coladdr, db 0 ; red value of color to add +NEWSYM coladdg, db 0 ; green value of color to add +NEWSYM coladdb, db 0 ; blue value of color to add +NEWSYM colnull, db 0 ; keep this 0 (when accessing colors by dword) +NEWSYM scaddset, db 0 ; screen/fixed color addition settings +NEWSYM scaddtype, db 0 ; which screen to add/sub +NEWSYM Voice0Disabl2, db 1 ; Disable Voice 0 +NEWSYM Voice1Disabl2, db 1 ; Disable Voice 1 +NEWSYM Voice2Disabl2, db 1 ; Disable Voice 2 +NEWSYM Voice3Disabl2, db 1 ; Disable Voice 3 +NEWSYM Voice4Disabl2, db 1 ; Disable Voice 4 +NEWSYM Voice5Disabl2, db 1 ; Disable Voice 5 +NEWSYM Voice6Disabl2, db 1 ; Disable Voice 6 +NEWSYM Voice7Disabl2, db 1 ; Disable Voice 7 + +NEWSYM oamram, times 1024 db 0 ; OAMRAM (544 bytes) +NEWSYM cgram, times 512 db 0 ; CGRAM +NEWSYM pcgram, times 512 db 0 ; Previous CGRAM + +NEWSYM vraminctype, db 0 + +; New variables +NEWSYM vramincby8on, db 0 ; if increment by 8 is on +NEWSYM vramincby8left, db 0 ; how many left +NEWSYM vramincby8totl, db 0 ; how many in total (32,64,128) +NEWSYM vramincby8rowl, db 0 ; how many left in that row (start at 8) +NEWSYM vramincby8ptri, dw 0 ; increment by how many when rowl = 0 + +NEWSYM nexthprior, db 0 +NEWSYM doirqnext, db 0 + +NEWSYM vramincby8var, dw 0 +NEWSYM screstype, db 0 +NEWSYM extlatch, db 0 +NEWSYM cfield, db 0 +NEWSYM interlval, db 0 + +NEWSYM HIRQLoc, dw 0 ; HIRQ X location + +NEWSYM KeyOnStA, db 0 +NEWSYM KeyOnStB, db 0 + +NEWSYM SDD1BankA, db 0 +NEWSYM SDD1BankB, db 1 +NEWSYM SDD1BankC, db 2 +NEWSYM SDD1BankD, db 3 +NEWSYM vramread2, db 0 ; previous character for vram read +NEWSYM nosprincr, db 0 +NEWSYM poamaddrs, dw 0 +NEWSYM ioportval, db 255 +NEWSYM iohvlatch, db 0 +NEWSYM ppustatus, db 0 +NEWSYM hdmastartsc, db 0 +NEWSYM hdmarestart, db 0 +NEWSYM hdmadelay, db 0 +NEWSYM nohdmaframe, db 0 ; no hdma for current frame + +NEWSYM tempdat, times 474 db 0 ; expandable area + +num2writeppureg equ $-sndrot +; pharos equ hack *sigh* +NEWSYM PHnum2writeppureg, dd num2writeppureg + +NEWSYM scrndis, db 0 ; which background is disabled + +ALIGN32 +NEWSYM oamaddr, dd 0 ; oam address + +NEWSYM bg1ptrx, dd 0 ; pointer to background1 +NEWSYM bg2ptrx, dd 0 ; pointer to background2 +NEWSYM bg3ptrx, dd 0 ; pointer to background3 +NEWSYM bg4ptrx, dd 0 ; pointer to background4 + +NEWSYM bg1ptry, dd 0 ; pointer to background1 +NEWSYM bg2ptry, dd 0 ; pointer to background2 +NEWSYM bg3ptry, dd 0 ; pointer to background3 +NEWSYM bg4ptry, dd 0 ; pointer to background4 + +NEWSYM Voice0Disable, db 1 ; Disable Voice 0 +NEWSYM Voice1Disable, db 1 ; Disable Voice 1 +NEWSYM Voice2Disable, db 1 ; Disable Voice 2 +NEWSYM Voice3Disable, db 1 ; Disable Voice 3 +NEWSYM Voice4Disable, db 1 ; Disable Voice 4 +NEWSYM Voice5Disable, db 1 ; Disable Voice 5 +NEWSYM Voice6Disable, db 1 ; Disable Voice 6 +NEWSYM Voice7Disable, db 1 ; Disable Voice 7 + +NEWSYM BG116x16t, db 0 +NEWSYM BG216x16t, db 0 +NEWSYM BG316x16t, db 0 +NEWSYM BG416x16t, db 0 +NEWSYM SPC700read, dd 0 +NEWSYM SPC700write, dd 0 + +NEWSYM JoyCRead, db 0 + +NEWSYM nssdip1, db 0 +NEWSYM nssdip2, db 0 +NEWSYM nssdip3, db 0 +NEWSYM nssdip4, db 0 +NEWSYM nssdip5, db 0 +NEWSYM nssdip6, db 0 + +SECTION .text + +NEWSYM ClearRegs + mov word[VIRQLoc],0 + mov word[bg1ptr],0 + mov word[bg2ptr],0 + mov word[bg3ptr],0 + mov word[bg4ptr],0 + mov word[bg1ptrb],0 + mov word[bg2ptrb],0 + mov word[bg3ptrb],0 + mov word[bg4ptrb],0 + mov word[bg1ptrc],0 + mov word[bg2ptrc],0 + mov word[bg3ptrc],0 + mov word[bg4ptrc],0 + mov word[bg1ptrd],0 + mov word[bg2ptrd],0 + mov word[bg3ptrd],0 + mov word[bg4ptrd],0 + mov word[bg1objptr],0 + mov word[bg2objptr],0 + mov word[bg3objptr],0 + mov word[bg4objptr],0 + mov byte[ioportval],0FFh + mov byte[hdmastartsc],0 + mov byte[hdmarestart],0 + mov byte[nohdmaframe],0 + mov byte[hdmadelay],0 + ret + +reg2100r: + mov al,[vidbright] + or al,[forceblnk] + ret + +; Multiply Result Low +reg2134r: + checkmultchange + mov al,[compmult] + ret + +; Multiply Result Middle +reg2135r: + checkmultchange + mov al,[compmult+1] + ret + +; Multiply Result High +reg2136r: + checkmultchange + mov al,[compmult+2] + ret + +; Software latch for horizontal/vertical counter +reg2137r: +; mov byte[debstop3],1 + cmp byte[debuggeron],1 + je .debugger + cmp byte[iohvlatch],1 + je .dolatch + test byte[ioportval],80h + jz .nolatch +.dolatch + xor ebx,ebx + mov bl,[cycpl] + sub bl,dh + add bx,bx + mov [latchx],bx + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq + cmp word[HIRQLoc],0F0h + ja .incry + cmp dh,20 + jae .noincly +.incry + inc word[latchy] +.novhirq +.noincly +.nolatch + xor al,al + mov byte[extlatch],0 + ret +.debugger +debblah: + cmp byte[iohvlatch],1 + je .dolatch2 + test byte[ioportval],80h + jz near .nolatch2 +.dolatch2 + xor ebx,ebx + mov bl,[cycpl] + sub bl,[pdh] + add bx,bx + mov [latchx],bx + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq + cmp word[HIRQLoc],0F0h +; ja .incry + cmp word[latchx],80 +; jb .noincly +.incry + inc word[latchy] +.novhirq +.noincly + xor al,al + mov byte[extlatch],0 + ret + + push eax + push edx + xor eax,eax + xor ebx,ebx + mov al,[cycpl] + sub al,[pdh] + mov bx,339 + mul bx + xor ebx,ebx + mov bl,[cycpl] + div bx + mov [latchx],ax + pop edx + pop eax + mov bx,[curypos] + mov [latchy],bx + mov bl,[INTEnab] + and bl,30h + cmp bl,30h + jne .novhirq2 + cmp word[HIRQLoc],0F0h + ja .incry2 + cmp word[latchx],80 + jb .noincly2 +.incry2 + inc word[latchy] +.novhirq2 +.noincly2 +.nolatch2 + xor al,al + mov byte[extlatch],0 + ret + +; Read OAM Data (Low, High) +reg2138r: + xor ebx,ebx + mov bx,[oamaddr] + add ebx,oamram + mov al,[ebx] + inc word[oamaddr] + cmp word[oamaddr],543 + ja .wrapoam + ret +.wrapoam + mov word[oamaddr],0 + ret + +; Read VRAM Data (Low) +reg2139r: + mov al,[vramread] + + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov bl,[ebx] + mov [vramread],bl + + cmp byte[vramincr],0 + je near .noincr + mov bx,[addrincr] + add [vramaddr],bx + cmp byte[vramincby8on],1 + jne .noincr + dec byte[vramincby8left] + jnz .noincr + + add word[vramaddr],2 + mov bl,[vramincby8totl] + mov [vramincby8left],bl + dec byte[vramincby8rowl] + jz .nextrow + mov bx,[vramincby8ptri] + sub [vramaddr],bx + jmp .noincr +.nextrow + mov byte[vramincby8rowl],8 + sub word[vramaddr],16 +.noincr + ret + +; Read VRAM Data (High) +reg213Ar: + mov al,[vramread2] + + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov bl,[ebx+1] + mov [vramread2],bl + + cmp byte[vramincr],1 + je near .noincr + mov bx,[addrincr] + add [vramaddr],bx + cmp byte[vramincby8on],1 + jne .noincr + dec byte[vramincby8left] + jnz .noincr + + add word[vramaddr],2 + mov bl,[vramincby8totl] + mov [vramincby8left],bl + dec byte[vramincby8rowl] + jz .nextrow + mov bx,[vramincby8ptri] + sub [vramaddr],bx + jmp .noincr +.nextrow + mov byte[vramincby8rowl],8 + sub word[vramaddr],16 +.noincr + ret + +; Read CGRAM Data +reg213Br: + xor ebx,ebx + mov bx,[cgaddr] + mov al,[cgram+ebx] + inc word[cgaddr] + and word[cgaddr],01FFh + ret + +; H counter data by external or software latch +reg213Cr: + cmp byte[latchxr],1 + je .highv + mov al,[latchx] + mov byte[latchxr],1 + ret +.highv + mov al,[latchx] + and al,0FEh + or al,byte[latchx+1] + mov byte[latchxr],0 + ret + +; V counter data by external or software latch +reg213Dr: + cmp byte[latchyr],2 ; hack for games that don't read 213F + je .noreset + cmp byte[latchyr],1 + je .highv + mov al,[latchy] + mov byte[latchyr],1 + ret +.highv + mov al,[latchy] + and al,0FEh + or al,byte[latchy+1] + mov byte[latchyr],0 + ret +.noreset + mov al,[latchy] + and al,0FEh + or al,byte[latchy+1] + ret +; PPU Status Flag & Version number (OBJ over flags) +reg213Er: + mov al,01h + ret + +; PPU Status Flag & Version number (NTSC/PAL/EXTRN Latch flag) +reg213Fr: +; mov byte[debstop3],1 + mov al,[romispal] + shl al,4 + or al,[ppustatus] + or al,[cfield] + mov byte[latchxr],0 + mov byte[latchyr],0 + or al,[extlatch] + ret + +; Sound Reg #1 +reg2140r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg1read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + cmp word[ebx],0FB10h + jne .noret + mov word[ebx],0EAEAh +.noret + mov al,5 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + inc byte[sndrot2] + cmp byte[sndrot2],3 + jne .a + mov byte[sndrot2],0 +.a + xor al,al + test byte[sndrot2],01h + jz .n + mov al,[xa] +.n + ret + +; Sound Reg #2 +reg2141r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg2read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + xor byte[sndrot],01h + mov al,[xa+1] + test byte[sndrot],01h + jz .n + mov al,[xa] +.n + ret + +; Sound Reg #3 +reg2142r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg3read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + mov al,[xa] + test byte[sndrot],01h + jz .n + mov al,[xa+1] +.n + ret + +; Sound Reg #4 +reg2143r: + cmp byte[spcon],0 + je .nosound + inc dword[SPC700read] + mov al,[reg4read] + mov byte[spcnumread],0 + ret +.nosound + ; Find for D0 + mov ebx,esi + mov al,3 +.tryagain + cmp byte[ebx],0D0h + je .foundit + inc ebx + dec al + jnz .tryagain + jmp .notfound +.foundit + mov byte[ebx],0EAh + mov byte[ebx+1],0EAh +.notfound + mov al,[xa+1] + ret + +reg2144r: + xor al,al + ret + +; WRAM Read +reg2180r: + mov ebx,[wramrwadr] + add ebx,[wramdata] + mov al,[ebx] + inc dword[wramrwadr] + and dword[wramrwadr],01FFFFh + ret + +; Unknown register, used by test cart + +reg21C2r: +reg21C3r: + mov al,21h + ret + +; Joystick Data for controller 1 and 2 + +reg4016r: + xor al,al + test dword[JoyANow],80000000h + jz .noal + mov al,1 +.noal + rol dword[JoyANow],1 + ret + +SECTION .bss +NEWSYM MultiTap, resb 1 +SECTION .text + +; Joystick Data for controller 2 and 4 +reg4017r: + cmp byte[snesmouse],0 + jne .nomultitap + cmp byte[MultiTap],1 + je .multitap +.nomultitap + xor al,al + test dword[JoyBNow],80000000h + jz .noal + mov al,1 +.noal + rol dword[JoyBNow],1 + ret +.multitap + test byte[MultiTapStat],1 + jz .no1 + mov al,0FFh + ret +.no1 + test byte[MultiTapStat],80h + jz .contr45 + xor al,al + test dword[JoyBNow],80000000h + jz .nojb + or al,01h +.nojb + test dword[JoyCNow],80000000h + jz .nojc + or al,02h +.nojc + rol dword[JoyBNow],1 + rol dword[JoyCNow],1 + ret +.contr45 + xor al,al + test dword[JoyDNow],80000000h + jz .nojd + or al,1 +.nojd + test dword[JoyENow],80000000h + jz .noje + or al,02h +.noje + rol dword[JoyDNow],1 + rol dword[JoyENow],1 + ret + +reg4100r: + xor al,al + cmp byte[nssdip1],1 + jne .nodip1 + mov al,1 +.nodip1 + cmp byte[nssdip2],1 + jne .nodip2 + or al,02h +.nodip2 + cmp byte[nssdip3],1 + jne .nodip3 + or al,04h +.nodip3 + cmp byte[nssdip4],1 + jne .nodip4 + or al,08h +.nodip4 + cmp byte[nssdip5],1 + jne .nodip5 + or al,10h +.nodip5 + cmp byte[nssdip6],1 + jne .nodip6 + or al,20h +.nodip6 + ret + +reg420Ar: +reg420Br: +reg420Cr: +reg420Dr: +reg420Er: +reg420Fr: + xor al,al + ret + +; NMI Check Register +reg4210r: + mov al,[NMIEnab] + cmp byte[curnmi],0 + jne .nmi + mov byte[NMIEnab],01h +.nmi + mov byte[curnmi],0 + ret + +; Video IRQ Register +reg4211r: + mov al,[irqon] + mov byte[irqon],0 + cmp dh,[cycphb] + jae .nohblank + or al,40h +.nohblank + ret + +SECTION .bss +NEWSYM hblank, resb 1 +SECTION .text + +; H/V Blank Flag & Joystick Controller Enable Flag +; bit 7 = vblank, 0=out,1=in, bit 6 = hblank, 0=out,1=in, bit 0 = joystick on +reg4212r: + xor al,al + cmp byte[joycontren],25 + jb .nojoyc +.yesjoy + mov al,1 +.nojoyc + inc byte[joycontren] + cmp byte[joycontren],50 + jne .n + mov byte[joycontren],0 +.n + cmp byte[debuggeron],1 + je .debugger + mov bx,[resolutn] + cmp word[curypos],bx + jne .notres + cmp byte[nmistatus],2 + je .vblank +.notres + inc bx + cmp word[curypos],bx + jb .novbl + mov bx,[totlines] + dec bx + cmp word[curypos],bx + jae .novbl +.vblank + or al,80h +; jmp .nohblank +.novbl + mov byte[hblank],0 + cmp dh,[cycphb] + jae .nohblank + mov byte[hblank],1 + or al,40h +.nohblank + test byte[INTEnab],01h + jz .nojoy + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy + cmp dh,5 + ja .nojoy + ret +.nojoy + ret +.debugger +debblah2: + push edx + mov dh,[pdh] + mov bx,[resolutn] + cmp word[curypos],bx + jne .notres + cmp byte[nmistatus],2 + je .vblank +.notres + inc bx + cmp word[curypos],bx + jb .novbl + mov bx,[totlines] + dec bx + cmp word[curypos],bx + jae .novbl +.vblank + or al,80h +; jmp .nohblank +.novbl + cmp dh,[cycphb] + jae .nohblank + or al,40h +.nohblank + test byte[INTEnab],01h + jz .nojoy + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy + cmp dh,5 + ja .nojoy + pop edx + ret +.nojoy + pop edx + ret + + mov bx,[resolutn] + inc bx + cmp word[curypos],bx + jb .novbl2 + or al,80h + jmp .nohblank2 +.novbl2 + mov bl,[pdh] + cmp bl,[cycphb] + jae .nohblank2 + or al,40h +.nohblank2 + test byte[INTEnab],01h + jz .nojoy2 + mov bx,[resolutn] + add bx,2 + cmp word[curypos],bx + jne .nojoy2 + cmp byte[pdh],5 + ja .nojoy +; or al,01h + ret +.nojoy2 + ret + +; Programmable I/O port +reg4213r: + mov al,[ioportval] + ret + +; Quotent of Divide Result (Low) +reg4214r: + mov al,[divres] + ret + +; Quotent of Divide Result (High) +reg4215r: + mov al,[divres+1] + ret + +; Product of Multiplication Result or Remainder of Divide Result (Low) +reg4216r: + mov al,[multres] + ret + +; Product of Multiplication Result or Remainder of Divide Result (High) +reg4217r: + mov al,[multres+1] + ret + +; Joystick 1 Low +; bit7=X,bit6=Y,bit5=L,bit4=R +reg4218r: + mov al,[JoyAOrig+2] + ret + +; Joystick 1 High +; bit7=A,bit6=B,bit5=Sel,bit4=Start,bit3=up,bit2=down,bit1=left,bit0=right +reg4219r: + mov al,[JoyAOrig+3] + ret + +; Joystick 2 Low +reg421Ar: + mov al,[JoyBOrig+2] + ret + +; Joystick 2 High +reg421Br: + mov al,[JoyBOrig+3] + ret + +; Joystick 3 Low +reg421Cr: + mov al,[JoyDOrig+2] + ret + +; Joystick 3 High +reg421Dr: + mov al,[JoyDOrig+3] + ret + +; Joystick 4 Low +reg421Er: + mov al,[JoyCOrig+2] + ret + +; Joystick 4 High +reg421Fr: + mov al,[JoyCOrig+3] + ret + +; DMA Reader +reg43XXr: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov al,[dmadata+ebx] + ret + +regINVALID: ; Invalid Register + cmp cx,2100h + jb .cleared + mov al,ch + cmp byte[SPC7110Enable],0 + je .nospc7110 +.cleared + xor al,al +.nospc7110 +; mov byte[debstop3],1 + ret + + mov al,[previdmode] + mov ah,0 + int 10h + mov byte[invalid],1 + mov [invreg],cx + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov ax,[invreg] + call printhex + mov ah,2 + mov dl,13 + int 21h + mov ah,2 + mov dl,10 + int 21h + mov eax,[numinst] ;Temporary + call printnum + jmp DosExit + +SECTION .data +.invalidreg db 'Invalid Read Register : $' +SECTION .text + + + + diff --git a/zsnes/src/cpu/regsw.inc b/zsnes/src/cpu/regsw.inc index 70d5c611..afcb613f 100644 --- a/zsnes/src/cpu/regsw.inc +++ b/zsnes/src/cpu/regsw.inc @@ -1,1747 +1,1747 @@ -;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) -; -;http://www.zsnes.com -;http://sourceforge.net/projects/zsnes -; -;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. - - - -EXTSYM initsfxregsw,reg420Bw,reg420Cw,regptw,initSA1regsw,SDD1Reset -EXTSYM SPC7110Reset,RTCReset2,debstop,NextLineCache,vidmemch2,vidmemch4 -EXTSYM vidmemch8,vrama,nmirept,sndwrit,SPCRAM,HIRQCycNext,HIRQNextExe,HIRQSkip -EXTSYM cycpb268,cycpb358,cycpbl,cycpblt,opexec268,opexec268cph,opexec358 -EXTSYM opexec358cph,printhex8 - -SECTION .bss -NEWSYM testgfxv1, resb 1 -NEWSYM testgfxv2, resb 1 -SECTION .text - -NEWSYM initregw - ; Fill register pointer with invalid register accesses - mov edi,[regptw] - add edi,8000h - mov ecx,3000h - mov eax,regINVALIDw -.loopa - mov [edi],eax - add edi,4 - dec ecx - jnz .loopa - ; Set all valid register accesses - setregw 2100h*4,reg2100w - setregw 2101h*4,reg2101w - setregw 2102h*4,reg2102w - setregw 2103h*4,reg2103w - setregw 2104h*4,reg2104w - setregw 2105h*4,reg2105w - setregw 2106h*4,reg2106w - setregw 2107h*4,reg2107w - setregw 2108h*4,reg2108w - setregw 2109h*4,reg2109w - setregw 210Ah*4,reg210Aw - setregw 210Bh*4,reg210Bw - setregw 210Ch*4,reg210Cw - setregw 210Dh*4,reg210Dw - setregw 210Eh*4,reg210Ew - setregw 210Fh*4,reg210Fw - setregw 2110h*4,reg2110w - setregw 2111h*4,reg2111w - setregw 2112h*4,reg2112w - setregw 2113h*4,reg2113w - setregw 2114h*4,reg2114w - setregw 2115h*4,reg2115w - setregw 2116h*4,reg2116w - setregw 2117h*4,reg2117w - setregw 2118h*4,reg2118 - setregw 2119h*4,reg2119inc - setregw 211Ah*4,reg211Aw - setregw 211Bh*4,reg211Bw - setregw 211Ch*4,reg211Cw - setregw 211Dh*4,reg211Dw - setregw 211Eh*4,reg211Ew - setregw 211Fh*4,reg211Fw - setregw 2120h*4,reg2120w - setregw 2121h*4,reg2121w - setregw 2122h*4,reg2122w - setregw 2123h*4,reg2123w - setregw 2124h*4,reg2124w - setregw 2125h*4,reg2125w - setregw 2126h*4,reg2126w - setregw 2127h*4,reg2127w - setregw 2128h*4,reg2128w - setregw 2129h*4,reg2129w - setregw 212Ah*4,reg212Aw - setregw 212Bh*4,reg212Bw - setregw 212Ch*4,reg212Cw - setregw 212Dh*4,reg212Dw - setregw 212Eh*4,reg212Ew - setregw 212Fh*4,reg212Fw - setregw 2130h*4,reg2130w - setregw 2131h*4,reg2131w - setregw 2132h*4,reg2132w - setregw 2133h*4,reg2133w - setregw 2140h*4,reg2140w - setregw 2141h*4,reg2141w - setregw 2142h*4,reg2142w - setregw 2143h*4,reg2143w - setregw 2144h*4,reg2140w - setregw 2180h*4,reg2180w - setregw 2181h*4,reg2181w - setregw 2182h*4,reg2182w - setregw 2183h*4,reg2183w - setregw 4016h*4,reg4016w - setregw 4017h*4,reg4017w - setregw 4200h*4,reg4200w - setregw 4201h*4,reg4201w - setregw 4202h*4,reg4202w - setregw 4203h*4,reg4203w - setregw 4204h*4,reg4204w - setregw 4205h*4,reg4205w - setregw 4206h*4,reg4206w - setregw 4207h*4,reg4207w - setregw 4208h*4,reg4208w - setregw 4209h*4,reg4209w - setregw 420Ah*4,reg420Aw - setregw 420Bh*4,reg420Bw - setregw 420Ch*4,reg420Cw - setregw 420Dh*4,reg420Dw - setregw 420Eh*4,reg420Ew - setregw 4210h*4,reg4210w - setregw 4211h*4,reg4211w - setregw 4212h*4,reg4212w - setregw 4216h*4,reg4216w - setregw 4300h*4,reg43X0w - setregw 4301h*4,reg43X1w - setregw 4302h*4,reg43x2w - setregw 4303h*4,reg43x3w - setregw 4304h*4,reg43x4w - setregw 4305h*4,reg43x5w - setregw 4306h*4,reg43x6w - setregw 4307h*4,reg43x7w - setregw 4308h*4,reg43x8w - setregw 4309h*4,reg43x9w - setregw 430Ah*4,reg43XAw - setregw 430Bh*4,reg43XAw - setregw 430Ch*4,reg43XAw - setregw 430Dh*4,reg43XAw - setregw 430Eh*4,reg43XAw - setregw 430Fh*4,reg43XAw - setregw 4310h*4,reg43X0w - setregw 4311h*4,reg43X1w - setregw 4312h*4,reg43x2w - setregw 4313h*4,reg43x3w - setregw 4314h*4,reg43x4w - setregw 4315h*4,reg43x5w - setregw 4316h*4,reg43x6w - setregw 4317h*4,reg43x7w - setregw 4318h*4,reg43x8w - setregw 4319h*4,reg43x9w - setregw 431Ah*4,reg43XAw - setregw 431Bh*4,reg43XAw - setregw 431Ch*4,reg43XAw - setregw 431Dh*4,reg43XAw - setregw 431Eh*4,reg43XAw - setregw 431Fh*4,reg43XAw - setregw 4320h*4,reg43X0w - setregw 4321h*4,reg43X1w - setregw 4322h*4,reg43x2w - setregw 4323h*4,reg43x3w - setregw 4324h*4,reg43x4w - setregw 4325h*4,reg43x5w - setregw 4326h*4,reg43x6w - setregw 4327h*4,reg43x7w - setregw 4328h*4,reg43x8w - setregw 4329h*4,reg43x9w - setregw 432Ah*4,reg43XAw - setregw 432Bh*4,reg43XAw - setregw 432Ch*4,reg43XAw - setregw 432Dh*4,reg43XAw - setregw 432Eh*4,reg43XAw - setregw 432Fh*4,reg43XAw - setregw 4330h*4,reg43X0w - setregw 4331h*4,reg43X1w - setregw 4332h*4,reg43x2w - setregw 4333h*4,reg43x3w - setregw 4334h*4,reg43x4w - setregw 4335h*4,reg43x5w - setregw 4336h*4,reg43x6w - setregw 4337h*4,reg43x7w - setregw 4338h*4,reg43x8w - setregw 4339h*4,reg43x9w - setregw 433Ah*4,reg43XAw - setregw 433Bh*4,reg43XAw - setregw 433Ch*4,reg43XAw - setregw 433Dh*4,reg43XAw - setregw 433Eh*4,reg43XAw - setregw 433Fh*4,reg43XAw - setregw 4340h*4,reg43X0w - setregw 4341h*4,reg43X1w - setregw 4342h*4,reg43x2w - setregw 4343h*4,reg43x3w - setregw 4344h*4,reg43x4w - setregw 4345h*4,reg43x5w - setregw 4346h*4,reg43x6w - setregw 4347h*4,reg43x7w - setregw 4348h*4,reg43x8w - setregw 4349h*4,reg43x9w - setregw 434Ah*4,reg43XAw - setregw 434Bh*4,reg43XAw - setregw 434Ch*4,reg43XAw - setregw 434Dh*4,reg43XAw - setregw 434Eh*4,reg43XAw - setregw 434Fh*4,reg43XAw - setregw 4350h*4,reg43X0w - setregw 4351h*4,reg43X1w - setregw 4352h*4,reg43x2w - setregw 4353h*4,reg43x3w - setregw 4354h*4,reg43x4w - setregw 4355h*4,reg43x5w - setregw 4356h*4,reg43x6w - setregw 4357h*4,reg43x7w - setregw 4358h*4,reg43x8w - setregw 4359h*4,reg43x9w - setregw 435Ah*4,reg43XAw - setregw 435Bh*4,reg43XAw - setregw 435Ch*4,reg43XAw - setregw 435Dh*4,reg43XAw - setregw 435Eh*4,reg43XAw - setregw 435Fh*4,reg43XAw - setregw 4360h*4,reg43X0w - setregw 4361h*4,reg43X1w - setregw 4362h*4,reg43x2w - setregw 4363h*4,reg43x3w - setregw 4364h*4,reg43x4w - setregw 4365h*4,reg43x5w - setregw 4366h*4,reg43x6w - setregw 4367h*4,reg43x7w - setregw 4368h*4,reg43x8w - setregw 4369h*4,reg43x9w - setregw 436Ah*4,reg43XAw - setregw 436Bh*4,reg43XAw - setregw 436Ch*4,reg43XAw - setregw 436Dh*4,reg43XAw - setregw 436Eh*4,reg43XAw - setregw 436Fh*4,reg43XAw - setregw 4370h*4,reg43X0w - setregw 4371h*4,reg43X1w - setregw 4372h*4,reg43x2w - setregw 4373h*4,reg43x3w - setregw 4374h*4,reg43x4w - setregw 4375h*4,reg43x5w - setregw 4376h*4,reg43x6w - setregw 4377h*4,reg43x7w - setregw 4378h*4,reg43x8w - setregw 4379h*4,reg43x9w - setregw 437Ah*4,reg43XAw - setregw 437Bh*4,reg43XAw - setregw 437Ch*4,reg43XAw - setregw 437Dh*4,reg43XAw - setregw 437Eh*4,reg43XAw - setregw 437Fh*4,reg43XAw - cmp byte[SFXEnable],0 - je .nosfx - call initsfxregsw -.nosfx - cmp byte[SA1Enable],0 - je .nosa1 - call initSA1regsw -.nosa1 - cmp byte[SDD1Enable],0 - je .nosdd1 - call SDD1Reset -.nosdd1 - cmp byte[SPC7110Enable],0 - je .nospc7110 - call SPC7110Reset -.nospc7110 - cmp byte[RTCEnable],0 - je .nortc - call RTCReset2 -.nortc - ret - -; video memory change buffer for caching (65536/16=4096) -;vidmemch2, vidmemch4, vidmemch8. 4096 bytes each - -;******************************************************* -; Registers Note : restore AH, ECX, ESI, EDI, *S & DX -;******************************************************* - - -; Screen display register -reg2100w: - mov [vidbright],al - and byte[vidbright],0Fh - mov [forceblnk],al - and byte[forceblnk],80h - ret - -SECTION .bss -NEWSYM prevoamptr, resb 1 -SECTION .text - -; OAM size register -reg2101w: - cmp byte[prevoamptr],0FFh - je .noskip - cmp byte[prevoamptr],al - je near .noproc -.noskip - mov [prevoamptr],al - xor ebx,ebx - mov bl,al - and bl,03h - shl bx,14 - mov [objptr],bx - mov [objptrn],bx - xor ebx,ebx - mov bl,al - and bl,18h - shr bl,3 - shl bx,13 - add [objptrn],bx - xor ebx,ebx - mov bl,al - shr bl,5 - push eax - mov byte[NextLineCache],1 - mov al,[.objsize1+ebx] - mov [objsize1],al - mov al,[.objsize2+ebx] - mov [objsize2],al - mov al,[.objmovs1+ebx] - mov [objmovs1],al - mov al,[.objmovs2+ebx] - mov [objmovs2],al - mov ax,[.objadds1+ebx*2] - mov [objadds1],ax - mov ax,[.objadds2+ebx*2] - mov [objadds2],ax - pop eax -.noproc - ret - -SECTION .data -.objsize1 db 1,1,1,4,4,16,1,1 -.objsize2 db 4,16,64,16,64,64,4,4 -.objmovs1 db 2,2,2,2,2,4,2,2 -.objmovs2 db 2,4,8,4,8,8,2,2 -.objadds1 dw 14,14,14,14,14,12,14,14 -.objadds2 dw 14,12,8,12,8,8,14,14 - -SECTION .bss -NEWSYM oamlow, resb 1 -SECTION .text - -; OAM address register -reg2102w: - mov byte[oamlow],1 - mov word[oamaddr],0 - shr word[oamaddr],1 - mov [oamaddr],al - shl word[oamaddr],1 -; or al,al -; jz .skipstore - mov bx,[oamaddrs] - mov [poamaddrs],bx - mov bx,[oamaddr] - mov [oamaddrs],bx -.skipstore - cmp byte[nexthprior],1 - je .priorset - mov byte[objhipr],0 - jmp .cachespr -.priorset - mov bx,[oamaddr] - shr bx,2 - and bl,0x7F -; cmp bl,80h -; jae .noreset -; xor bl,bl -.noreset - mov [objhipr],bl -.cachespr - ret - -; OAM address register -reg2103w: - cmp byte[oamlow],1 - jne .afteroamlow - mov byte[oamlow],0 - mov bl,al - and bl,01h - shr word[oamaddr],1 - mov [oamaddr+1],bl - shl word[oamaddr],1 -.afteroamlow - cmp word[poamaddrs],200h - jbe .notinvptr - cmp word[oamaddr],200h - jne .notinvptr - mov bx,[poamaddrs] - mov [oamaddr],bx - mov byte[nosprincr],1 -.notinvptr - mov bx,[oamaddr] - mov [oamaddrs],bx - test al,80h - jnz .hipri - mov byte[nexthprior],0 - mov byte[NextLineCache],1 - ret -.hipri - mov byte[nexthprior],1 - mov byte[NextLineCache],1 - ret - -; OAM data register -reg2104w: - mov byte[NextLineCache],1 - mov ebx,[oamaddr] - cmp byte[nosprincr],1 - je .noinc - inc dword[oamaddr] - cmp ebx,544 - jae .overflow -.noinc - mov [oamram+ebx],al - ret -.overflow - xor ebx,ebx - mov dword[oamaddr],1 - mov [oamram+ebx],al - ret - -; Screen mode register -reg2105w: - mov bl,al - and bl,00000111b - mov [bgmode],bl - mov bl,al - shr bl,3 - and bl,01h - mov [bg3highst],bl - mov bl,al - shr bl,4 - mov [bgtilesz],bl - mov bl,al - mov dword[BG116x16t],0 - add bl,bl - adc byte[BG416x16t],0 - add bl,bl - adc byte[BG316x16t],0 - add bl,bl - adc byte[BG216x16t],0 - add bl,bl - adc byte[BG116x16t],0 - ret - -; Screen pixelation register -reg2106w: - mov bl,al - and bl,0Fh - mov [mosaicon],bl - mov bl,al - shr bl,4 - mov [mosaicsz],bl - ret - -; BG1 VRAM location register -reg2107w: - xor ebx,ebx - mov bl,al - shr bl,2 - shl bx,11 - mov [bg1ptr],bx - mov [bg1ptrb],bx - mov [bg1ptrc],bx - mov [bg1ptrd],bx - mov dword[bg1ptrx],0 - mov dword[bg1ptry],0 - mov bl,al - and bl,00000011b - mov [bg1scsize],bl - cmp bl,1 - jne .skipa - add word[bg1ptrb],800h - add word[bg1ptrd],800h - mov dword[bg1ptrx],800h -.skipa - cmp bl,2 - jne .skipb - add word[bg1ptrc],800h - add word[bg1ptrd],800h - mov dword[bg1ptry],800h -.skipb - cmp bl,3 - jne .skipc - add word[bg1ptrb],800h - add word[bg1ptrc],1000h - add word[bg1ptrd],1800h - mov dword[bg1ptrx],800h - mov dword[bg1ptry],1000h -.skipc - ret - -; BG2 VRAM location register -reg2108w: - xor ebx,ebx - mov bl,al - shr bl,2 - shl bx,11 - mov [bg2ptr],bx - mov [bg2ptrb],bx - mov [bg2ptrc],bx - mov [bg2ptrd],bx - mov dword[bg2ptrx],0 - mov dword[bg2ptry],0 - mov bl,al - and bl,00000011b - mov [bg2scsize],bl - cmp bl,1 - jne .skipa - add word[bg2ptrb],800h - add word[bg2ptrd],800h - mov dword[bg2ptrx],800h -.skipa - cmp bl,2 - jne .skipb - add word[bg2ptrc],800h - add word[bg2ptrd],800h - mov dword[bg2ptry],800h -.skipb - cmp bl,3 - jne .skipc - add word[bg2ptrb],800h - add word[bg2ptrc],1000h - add word[bg2ptrd],1800h - mov dword[bg2ptrx],800h - mov dword[bg2ptry],1000h -.skipc - ret - -; BG3 VRAM location register -reg2109w: - xor ebx,ebx - mov bl,al - shr bl,2 - shl bx,11 - mov [bg3ptr],bx - mov [bg3ptrb],bx - mov [bg3ptrc],bx - mov [bg3ptrd],bx - mov dword[bg3ptrx],0 - mov dword[bg3ptry],0 - mov bl,al - and bl,00000011b - mov [bg3scsize],bl - cmp bl,1 - jne .skipa - add word[bg3ptrb],800h - add word[bg3ptrd],800h - mov dword[bg3ptrx],800h -.skipa - cmp bl,2 - jne .skipb - add word[bg3ptrc],800h - add word[bg3ptrd],800h - mov dword[bg3ptry],800h -.skipb - cmp bl,3 - jne .skipc - add word[bg3ptrb],800h - add word[bg3ptrc],1000h - add word[bg3ptrd],1800h - mov dword[bg3ptrx],800h - mov dword[bg3ptry],1000h -.skipc - ret - -; BG4 VRAM location register -reg210Aw: - xor ebx,ebx - mov bl,al - shr bl,2 - shl bx,11 - mov [bg4ptr],bx - mov [bg4ptrb],bx - mov [bg4ptrc],bx - mov [bg4ptrd],bx - mov dword[bg4ptrx],0 - mov dword[bg4ptry],0 - mov bl,al - and bl,00000011b - mov [bg4scsize],bl - cmp bl,1 - jne .skipa - add word[bg4ptrb],800h - add word[bg4ptrd],800h - mov dword[bg4ptrx],800h -.skipa - cmp bl,2 - jne .skipb - add word[bg4ptrc],800h - add word[bg4ptrd],800h - mov dword[bg4ptry],800h -.skipb - cmp bl,3 - jne .skipc - add word[bg4ptrb],800h - add word[bg4ptrc],1000h - add word[bg4ptrd],1800h - mov dword[bg4ptrx],800h - mov dword[bg4ptry],1000h -.skipc - ret - -; BG1 & BG2 VRAM location register -reg210Bw: - xor ebx,ebx - mov bl,al - and bl,0Fh - shl bx,13 - mov [bg1objptr],bx - mov bl,al - shr bl,4 - shl bx,13 - mov [bg2objptr],bx - ret - -; BG3 & BG4 VRAM location register -reg210Cw: - xor ebx,ebx - mov bl,al - and bl,0Fh - shl bx,13 - mov [bg3objptr],bx - mov bl,al - shr bl,4 - shl bx,13 - mov [bg4objptr],bx - ret - -; BG1 horizontal scroll register -reg210Dw: - xor ebx,ebx - mov [bg1scrolx],al - shl word[bg1scrolx],8 - mov bl,[bgscroltemp] - add word[bg1scrolx],bx - mov [bgscroltemp],al - ret - -; BG1 vertical scroll register -reg210Ew: - xor ebx,ebx - mov [bg1scroly],al - shl word[bg1scroly],8 - mov bl,[bgscroltemp] - add word[bg1scroly],bx - mov [bgscroltemp],al - ret - -SECTION .bss -bgscroltemp resb 1 -SECTION .text - -; BG2 horizontal scroll register -reg210Fw: - xor ebx,ebx - mov [bg2scrolx],al - shl word[bg2scrolx],8 - mov bl,[bgscroltemp] - add word[bg2scrolx],bx - mov [bgscroltemp],al - ret - -; BG2 vertical scroll register -reg2110w: - xor ebx,ebx - mov [bg2scroly],al - shl word[bg2scroly],8 - mov bl,[bgscroltemp] - add word[bg2scroly],bx - mov [bgscroltemp],al - ret - -; BG3 horizontal scroll register -reg2111w: - xor ebx,ebx - mov [bg3scrolx],al - shl word[bg3scrolx],8 - mov bl,[bgscroltemp] - add word[bg3scrolx],bx - mov [bgscroltemp],al - ret - -section .data -NEWSYM latchbg3, db 0 - -section .text - -; BG3 vertical scroll register -reg2112w: - xor ebx,ebx - mov [bg3scroly],al - shl word[bg3scroly],8 - mov bl,[bgscroltemp] - add word[bg3scroly],bx - mov [bgscroltemp],al - ret - -; BG4 horizontal scroll register -reg2113w: - xor ebx,ebx - mov [bg4scrolx],al - shl word[bg4scrolx],8 - mov bl,[bgscroltemp] - add word[bg4scrolx],bx - mov [bgscroltemp],al - ret - -; BG4 vertical scroll register -reg2114w: - xor ebx,ebx - mov [bg4scroly],al - shl word[bg4scroly],8 - mov bl,[bgscroltemp] - add word[bg4scroly],bx - mov [bgscroltemp],al - ret - -; Video port control -reg2115w: - and al,11111111b - mov [vraminctype],al - mov bl,al - and bl,00000011b - cmp bl,0 - jne .skip1 - mov word[addrincr],2 -.skip1 - cmp bl,1 - jne .skip2 - mov word[addrincr],64 -.skip2 - cmp bl,2 - jne .skip3 - mov word[addrincr],256 -.skip3 - cmp bl,3 - jne .skip4 - mov word[addrincr],256 -.skip4 - mov bl,al - mov byte[vramincby8on],0 - and bl,00001100b - jz near .noincby8 - mov byte[vramincby8on],1 - cmp bl,4 - jne .nextinc8 - mov byte[vramincby8left],64-1 - mov byte[vramincby8totl],5 - mov word[vramincby8ptri],65535-511 - mov word[vramincby8var],256+128+64 -.nextinc8 - cmp bl,8 - jne .nextinc8b - mov byte[vramincby8left],128-1 - mov byte[vramincby8totl],6 - mov word[vramincby8ptri],65535-1023 - mov word[vramincby8var],512+256+128 -.nextinc8b - cmp bl,12 - jne .nextinc8c - mov byte[vramincby8left],256-1 - mov byte[vramincby8totl],7 - mov word[vramincby8ptri],65535-2047 - mov word[vramincby8var],1024+512+256 -.nextinc8c - mov ebx,[regptw] - test al,80h - jz .from2118 - mov dword[ebx+2118h*4],reg2118inc8 - mov dword[ebx+2119h*4],reg2119inc8inc - mov byte[vramincr],0 - jmp .from2119 -.from2118 - mov dword[ebx+2118h*4],reg2118inc8inc - mov dword[ebx+2119h*4],reg2119inc8 - mov byte[vramincr],1 -.from2119 - ret -.noincby8 - mov ebx,[regptw] - test al,80h - jz .from2118b - mov dword[ebx+2118h*4],reg2118 - mov dword[ebx+2119h*4],reg2119inc - mov byte[vramincr],0 - jmp .from2119b -.from2118b - mov dword[ebx+2118h*4],reg2118inc - mov dword[ebx+2119h*4],reg2119 - mov byte[vramincr],1 -.from2119b - ret - -; Video port address (Low) -reg2116w: - shr word[vramaddr],1 - mov [vramaddr],al - shl word[vramaddr],1 - mov byte[vramread],0 - ret - -; Video port address (High) -reg2117w: - shr word[vramaddr],1 - mov [vramaddr+1],al - shl word[vramaddr],1 - mov byte[vramread],0 - - xor ebx,ebx - mov bx,[vramaddr] - add ebx,[vram] - mov bl,[ebx] - mov [vramread],bl - xor ebx,ebx - mov bx,[vramaddr] - add ebx,[vram] - mov bl,[ebx+1] - mov [vramread2],bl - ret - -; Video port data (Low) -NEWSYM reg2118 - mov ebx,[vramaddr] - mov [vrama+ebx],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 - ret - -NEWSYM reg2118inc - mov ebx,[vramaddr] - mov [vrama+ebx],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 - mov ebx,[addrincr] - add [vramaddr],bx - ret - -NEWSYM reg2118inc8 - push ecx - xor ecx,ecx - mov ebx,[vramaddr] - mov cl,[vramincby8left] - and ebx,ecx - shl ebx,3 - push eax - mov eax,[vramaddr] - and ax,[vramincby8var] - mov cl,[vramincby8totl] - shr eax,cl - add ebx,eax - mov eax,[vramaddr] - and ax,[vramincby8ptri] - add ebx,eax - pop eax - pop ecx - add ebx,[vram] -; cmp [ebx],al -; je .nochange2 - mov [ebx],al - sub ebx,[vram] - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange2 - ret - -NEWSYM reg2118inc8inc - push ecx - xor ecx,ecx - mov ebx,[vramaddr] - mov cl,[vramincby8left] - and ebx,ecx - shl ebx,3 - push eax - mov eax,[vramaddr] - and ax,[vramincby8var] - mov cl,[vramincby8totl] - shr eax,cl - add ebx,eax - mov eax,[vramaddr] - and ax,[vramincby8ptri] - add ebx,eax - pop eax - pop ecx - add ebx,[vram] -; cmp [ebx],al -; je .nochange2 - mov [ebx],al - sub ebx,[vram] - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange2 - mov ebx,[addrincr] - add [vramaddr],bx - ret - -NEWSYM reg2119 - cmp dword[vramaddr],0E000h - jb .skip - mov byte[debstop],1 -.skip - mov ebx,[vramaddr] -; cmp [vrama+ebx+1],al -; je .nochange - mov [vrama+ebx+1],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange - ret - -NEWSYM reg2119inc - mov ebx,[vramaddr] -; cmp [vrama+ebx+1],al -; je .nochange - mov [vrama+ebx+1],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange - mov ebx,[addrincr] - add [vramaddr],bx - ret - -NEWSYM reg2119inc8 - push ecx - xor ecx,ecx - mov ebx,[vramaddr] - mov cl,[vramincby8left] - and ebx,ecx - shl ebx,3 - push eax - mov eax,[vramaddr] - and ax,[vramincby8var] - mov cl,[vramincby8totl] - shr eax,cl - add ebx,eax - mov eax,[vramaddr] - and ax,[vramincby8ptri] - add ebx,eax - pop eax - pop ecx -; cmp [vrama+ebx+1],al -; je .nochange2 - mov [vrama+ebx+1],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange2 - ret - -NEWSYM reg2119inc8inc - push ecx - xor ecx,ecx - mov ebx,[vramaddr] - mov cl,[vramincby8left] - and ebx,ecx - shl ebx,3 - push eax - mov eax,[vramaddr] - and ax,[vramincby8var] - mov cl,[vramincby8totl] - shr eax,cl - add ebx,eax - mov eax,[vramaddr] - and ax,[vramincby8ptri] - add ebx,eax - pop eax - pop ecx -; cmp [vrama+ebx+1],al -; je .nochange2 - mov [vrama+ebx+1],al - shr ebx,4 - mov byte[vidmemch2+ebx],1 - mov byte[vidmemch4+ebx],1 - mov byte[vidmemch8+ebx],1 -.nochange2 - mov ebx,[addrincr] - add [vramaddr],bx - ret - -; MODE7 settings register -reg211Aw: - mov [mode7set],al - ret - -SECTION .data -NEWSYM multchange, db 1 -SECTION .text - -; COS (COSINE) rotate angle / X Expansion -reg211Bw: - mov bl,[mode7A+1] - mov [mode7A],bl - mov [mode7A+1],al - mov byte[multchange],1 - ret - -; SIN (SIN) rotate angle / X Expansion & Complement Multiplication Start -reg211Cw: - mov bl,[mode7B+1] - mov [mode7B],bl - mov [mode7B+1],al - mov byte[multchange],1 - ret - -; SIN (SIN) rotate angle / Y Expansion -reg211Dw: - mov bl,[mode7C+1] - mov [mode7C],bl - mov [mode7C+1],al - ret - -; COS (COSINE) rotate angle / Y Expansion -reg211Ew: - mov bl,[mode7D+1] - mov [mode7D],bl - mov [mode7D+1],al - ret - -; Center position X (13-bit data only) -reg211Fw: - mov bl,[mode7X0+1] - mov [mode7X0],bl - mov [mode7X0+1],al - ret - -; Center position Y (13-bit data only) -reg2120w: - mov bl,[mode7Y0+1] - mov [mode7Y0],bl - mov [mode7Y0+1],al - ret - -; Colour # (or palette) selection register -reg2121w: - xor bh,bh - mov bl,al - shl bx,1 - mov [cgaddr],bx - and word[cgaddr],01FFh - ret - -; Colour data register -reg2122w: - xor ebx,ebx - mov bx,[cgaddr] - cmp [cgram+ebx],al - je .nomod - mov [cgram+ebx],al - mov byte[cgmod],1 -.nomod - inc word[cgaddr] - and word[cgaddr],01FFh - ret - -; Window mask settings register [W12SEL] -reg2123w: - mov bl,al - and bl,0Fh - test bl,0Ah - jnz .nen1 -; or bl,02h -.nen1 - mov [winbg1en],bl - mov bl,al - shr bl,4 - test bl,0Ah - jnz .nen2 -; or bl,02h -.nen2 - mov [winbg2en],bl - ret - -; Window mask settings register [W34SEL] -reg2124w: - mov bl,al - and bl,0Fh - test bl,0Ah - jnz .nen1 -; or bl,02h -.nen1 - mov [winbg3en],bl - mov bl,al - shr bl,4 - test bl,0Ah - jnz .nen2 -; or bl,02h -.nen2 - mov [winbg4en],bl - ret - -; Window mask settings register [WOBJSEL] -reg2125w: - mov bl,al - and bl,0Fh - mov [winobjen],bl - mov bl,al - shr bl,4 - mov [wincolen],bl - ret - -; Window 1 left position register -reg2126w: - mov [winl1],al - ret - -; Window 1 right position register -reg2127w: - mov [winr1],al - ret - -; Window 2 left position register -reg2128w: - mov [winl2],al - ret - -; Window 2 right position register -reg2129w: - mov [winr2],al - ret - -; Mask logic settings for Window 1 & 2 per screen -reg212Aw: - mov [winlogica],al - ret - -; Mask logic settings for Colour Windows & OBJ Windows -reg212Bw: - mov [winlogicb],al - ret - -; Main screen designation -reg212Cw: - mov [scrnon],al - ret - -; Sub-screen designation -reg212Dw: - mov [scrnon+1],al - ret - -; Window mask main screen designation register -reg212Ew: - mov [winenabm],al - ret - -; Window mask sub screen designation register -reg212Fw: - mov [winenabs],al - ret - -; Fixed color addition or screen addition register -reg2130w: - mov [scaddset],al - ret - -; Addition/subtraction for screens, BGs, & OBJs -reg2131w: - mov [scaddtype],al - ret - -; Fixed colour data for fixed colour +/- -reg2132w: - mov bl,al - and bl,1Fh - test al,20h - jz .nored - mov [coladdr],bl -.nored - test al,40h - jz .nogreen - mov [coladdg],bl -.nogreen - test al,80h - jz .noblue - mov [coladdb],bl -.noblue - ret - -; Screen mode/video select register -reg2133w: - mov [interlval],al - and byte[interlval],41h - test al,04h - jnz .line239 - mov word[resolutn],224 - ret -.line239 - mov word[resolutn],239 - ret - -SECTION .bss -NEWSYM CleartheScreen, resb 1 -SECTION .text - -; Sound Register #1 -reg2140w: - mov byte[sndwrit],1 - cmp byte[nmistatus],2 - jne .n - mov byte[nmirept],0 -.n - mov [SPCRAM+0F4h],al - inc dword[SPC700write] - reenablespc - ret -; cmp dword[cycpbl],0FFFFh -; ja .spcreset -; ret -;.spcreset -; mov dword[cycpbl],100 -; ret - -; Sound Register #2 -reg2141w: - mov byte[sndwrit],1 - mov [SPCRAM+0F5h],al - inc dword[SPC700write] - reenablespc - ret -; cmp dword[cycpbl],0FFFFh -; ja .spcreset -; ret -;.spcreset -; mov dword[cycpbl],100 -; ret - -; Sound Register #3 -reg2142w: - mov byte[sndwrit],1 - mov [SPCRAM+0F6h],al - inc dword[SPC700write] - reenablespc - ret -; cmp dword[cycpbl],0FFFFh -; ja .spcreset -; ret -;.spcreset -; mov dword[cycpbl],100 -; ret - -; Sound Register #4 -reg2143w: - mov byte[sndwrit],1 - mov [SPCRAM+0F7h],al - inc dword[SPC700write] - reenablespc - ret -; cmp dword[cycpbl],0FFFFh -; ja .spcreset -; ret -;.spcreset -; mov dword[cycpbl],100 -; ret - -; Read/write WRAM register -reg2180w: - mov ebx,[wramrwadr] - add ebx,[wramdata] - mov [ebx],al - inc dword[wramrwadr] - and dword[wramrwadr],01FFFFh - ret - -; WRAM data register (low byte) -reg2181w: - mov [wramrwadr],al - ret - -; WRAM data register (middle byte) -reg2182w: - mov [wramrwadr+1],al - ret - -; WRAM data register (high byte) -reg2183w: - mov bl,al - and bl,01h - mov [wramrwadr+2],bl - ret - -; Joystick 1 & 2 status bytes -SECTION .bss -NEWSYM MultiTapStat, resb 1 -SECTION .text - -reg4016w: - test byte[INTEnab],1 - jnz .nointenab - mov ebx,[JoyAOrig] - or ebx,0FFFFh - mov [JoyANow],ebx - mov ebx,[JoyBOrig] - or ebx,0FFFFh - mov [JoyBNow],ebx - mov ebx,[JoyCOrig] - or ebx,0FFFFh - mov [JoyCNow],ebx - mov ebx,[JoyDOrig] - or ebx,0FFFFh - mov [JoyDNow],ebx - mov ebx,[JoyEOrig] - or ebx,0FFFFh - mov [JoyENow],ebx - cmp al,01h - jne .noreset - or byte[MultiTapStat],1 - ret -.noreset - and byte[MultiTapStat],0FEh - ret -.nointenab - cmp al,01h - jne .noone - or byte[MultiTapStat],1 - or byte[JoyCRead],2 - ret -.noone - and byte[MultiTapStat],0FEh - cmp al,0 - jne near .nozero - or byte[JoyCRead],1 - cmp byte[JoyCRead],3 - jne near .nozero -.resetports - mov ebx,[JoyAOrig] - or ebx,0FFFFh - mov [JoyANow],ebx - or ebx,0FFFFh - mov ebx,[JoyBOrig] - or ebx,0FFFFh - mov [JoyBNow],ebx - or ebx,0FFFFh - mov ebx,[JoyCOrig] - or ebx,0FFFFh - mov [JoyCNow],ebx - or ebx,0FFFFh - mov ebx,[JoyDOrig] - or ebx,0FFFFh - mov [JoyDNow],ebx - or ebx,0FFFFh - mov ebx,[JoyEOrig] - or ebx,0FFFFh - mov [JoyENow],ebx -.nozero - ret - -; Joystick 1 & 2 status bytes -reg4017w: - ret - -; Counter enable -reg4200w: - mov [INTEnab],al - ret - -; Programmable I/O port (out-port) -reg4201w: - cmp byte[iohvlatch],1 - jne .noiohvlatch - test al,80h - jnz .noiohvlatch - mov byte[iohvlatch],0 -.noiohvlatch - test byte[ioportval],80h - jnz .nolatch - test al,80h - jz .nolatch - mov byte[iohvlatch],1 -.nolatch - mov [ioportval],al - mov bl,al - and bl,80h - and byte[MultiTapStat],07Fh - or byte[MultiTapStat],bl - ret - -; Multiplicand 'A' -reg4202w: - mov [multa],al - ret - -; Multiplier 'B' -reg4203w: - push edx - push eax - xor ah,ah - xor bh,bh - mov bl,[multa] - mul bx - mov [multres],ax - pop eax - pop edx - ret - -; Dividend C (Low) -reg4204w: - mov [diva],al - ret - -; Dividend C (High) -reg4205w: - mov [diva+1],al - ret - -; Divisor B -reg4206w: - cmp al,0 - je .divby0 - push eax - push edx - xor ebx,ebx - xor edx,edx - mov bl,al - mov ax,[diva] - div bx - mov [divres],ax - mov [multres],dx - pop edx - pop eax - ret -.divby0 - push eax - mov word[divres],0FFFFh - mov ax,[diva] - mov [multres],ax - pop eax - ret - - -DetermineHIRQExec - cmp byte[HIRQSkip],1 - je near .ret - add dh,[HIRQCycNext] - mov byte[HIRQCycNext],0 - mov byte[HIRQNextExe],0 - push eax - push ecx - push edx - mov ax,[HIRQLoc] - xor ecx,ecx - mov cl,[cycpl] - mul cx - mov cx,340 - div cx - mov cl,[cycpl] - sub cl,al - pop edx - cmp dh,cl - ja .hirqokay -.notokay - pop ecx - pop eax -.ret - ret -.hirqokay - sub dh,cl - add dh,30 - add cl,16 - mov [HIRQCycNext],cl - mov byte[HIRQNextExe],1 - pop ecx - pop eax - ret - -; Video horizontal IRQ beam position/pointer (Low) -reg4207w: - cmp [HIRQLoc],al - je .nohirqc - mov [HIRQLoc],al - mov bx,[curypos] - cmp bx,[VIRQLoc] - je near DetermineHIRQExec -.nohirqc - ret - -; Video horizontal IRQ beam position/pointer (High) -reg4208w: - cmp [HIRQLoc+1],al - je .nohirqc - mov [HIRQLoc+1],al - mov bx,[curypos] - cmp bx,[VIRQLoc] - je near DetermineHIRQExec -.nohirqc - ret - -; Video vertical IRQ beam position/pointer (Low) -reg4209w: - mov [VIRQLoc],al -; mov bx,[curypos] - cmp byte[HIRQNextExe],1 - je .nohirq - ret -.nohirq - mov bx,[curypos] - cmp bx,[VIRQLoc] - je .nocancelhirq - add dh,[HIRQCycNext] - mov byte[HIRQCycNext],0 - mov byte[HIRQNextExe],0 -.nocancelhirq - ret - -; Video vertical IRQ beam position/pointer (High) -reg420Aw: - and al,01h - mov [VIRQLoc+1],al - mov bx,[totlines] - sub bx,1 - cmp word[VIRQLoc],bx - jb .okvirqpos - mov word[VIRQLoc],07FFFh -.okvirqpos - cmp byte[HIRQNextExe],1 - je .nohirq - ret -.nohirq - mov bx,[curypos] - cmp bx,[VIRQLoc] - je .nocancelhirq - add dh,[HIRQCycNext] - mov byte[HIRQCycNext],0 - mov byte[HIRQNextExe],0 -.nocancelhirq - ret - -; Cycle speed register -reg420Dw: - test al,01h - jnz .speed358 - ; 2.68 Mhz - mov al,[opexec268] - mov [cycpl],al ; 2.68 Mhz - mov al,[opexec268cph] - mov [cycphb],al ; 2.68 Mhz - and byte[xirqb],00h - mov bl,[cycpb268] - mov [cycpblt],bl ; percentage of CPU/SPC to run - ret -.speed358 - ; 3.58 Mhz - mov al,[opexec358] - mov [cycpl],al ; 3.58 Mhz - mov al,[opexec358cph] - mov [cycphb],al ; 3.58 Mhz - or byte[xirqb],80h - mov bl,[cycpb358] - mov [cycpblt],bl ; percentage of CPU/SPC to run - ret - -; ??? -reg420Ew: - ret - -; NMI Check register -reg4210w: - ret - -; Video IRQ register -reg4211w: - ret - -; Status register -reg4212w: - ret - -; Product of Multiplication Result or Remainder of Divide Result (Low) -reg4216w: - ret - -; DMA Control register -reg43X0w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - mov byte[hdmarestart],1 - ret - -; DMA Destination register -reg43X1w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - mov byte[hdmarestart],1 - ret - -; Source address (Low) -reg43x2w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al -; mov [dmadata+ebx+6],al - ret - -; Source address (High) -reg43x3w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al -; mov [dmadata+ebx+6],al - ret - -; Source bank address -reg43x4w - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; DMA transfer size & HDMA address register (Low) -reg43x5w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; DMA transfer size & HDMA address register (High) -reg43x6w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; DMA transfer size & HDMA address register (Bank) -reg43x7w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; Table Address of A-BUS by DMA < A2 Table Address (Low) -reg43x8w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; Table Address of A-BUS by DMA < A2 Table Address (High) -reg43x9w: - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - ret - -; Number of lines for HDMA transfer -reg43XAw: - mov byte[nohdmaframe],0 - xor ebx,ebx - mov bx,cx - sub bx,4300h - mov [dmadata+ebx],al - mov bx,[resolutn] - cmp word[curypos],bx - jb .nodma - mov byte[nohdmaframe],1 - inc byte[hdmadelay] -.nodma - ret - -regINVALIDw: ; Invalid Register - ret - - -regexiter: - mov bl,[xpb] - mov ax,[xpc] - test ax,8000h - jz .loweraddr2 - mov eax,[snesmmap+ebx*4] - jmp .nextaddr -.loweraddr2 - mov eax,[snesmap2+ebx*4] -.nextaddr - mov ebx,esi - sub ebx,eax ; subtract program counter by address - mov [.invaddr],bx - mov bl,[xpb] - mov [.invbank],bl - - mov al,[previdmode] - mov ah,0 - int 10h - mov byte[invalid],1 - mov [invreg],cx - mov ah,9 - mov edx,.invalidreg - int 21h - xor eax,eax - mov ax,[invreg] - call printhex - mov ah,9 - mov edx,.invalidreg - int 21h - xor eax,eax - mov al,[.invbank] - call printhex8 - mov ax,[.invaddr] - call printhex - mov ah,2 - mov dl,13 - int 21h - mov ah,2 - mov dl,10 - int 21h - mov eax,[numinst] - call printnum - jmp DosExit - -SECTION .data -.invalidreg db 'Invalid Write Register : $' -.invalidaddr db ' at address $' - -SECTION .bss -.invbank resb 1 -.invaddr resb 1 -SECTION .text +;Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach ) +; +;http://www.zsnes.com +;http://sourceforge.net/projects/zsnes +; +;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. + + + +EXTSYM initsfxregsw,reg420Bw,reg420Cw,regptw,initSA1regsw,SDD1Reset +EXTSYM SPC7110Reset,RTCReset2,debstop,NextLineCache,vidmemch2,vidmemch4 +EXTSYM vidmemch8,vrama,nmirept,sndwrit,SPCRAM,HIRQCycNext,HIRQNextExe,HIRQSkip +EXTSYM cycpb268,cycpb358,cycpbl,cycpblt,opexec268,opexec268cph,opexec358 +EXTSYM opexec358cph,printhex8 + +SECTION .bss +NEWSYM testgfxv1, resb 1 +NEWSYM testgfxv2, resb 1 +SECTION .text + +NEWSYM initregw + ; Fill register pointer with invalid register accesses + mov edi,[regptw] + add edi,8000h + mov ecx,3000h + mov eax,regINVALIDw +.loopa + mov [edi],eax + add edi,4 + dec ecx + jnz .loopa + ; Set all valid register accesses + setregw 2100h*4,reg2100w + setregw 2101h*4,reg2101w + setregw 2102h*4,reg2102w + setregw 2103h*4,reg2103w + setregw 2104h*4,reg2104w + setregw 2105h*4,reg2105w + setregw 2106h*4,reg2106w + setregw 2107h*4,reg2107w + setregw 2108h*4,reg2108w + setregw 2109h*4,reg2109w + setregw 210Ah*4,reg210Aw + setregw 210Bh*4,reg210Bw + setregw 210Ch*4,reg210Cw + setregw 210Dh*4,reg210Dw + setregw 210Eh*4,reg210Ew + setregw 210Fh*4,reg210Fw + setregw 2110h*4,reg2110w + setregw 2111h*4,reg2111w + setregw 2112h*4,reg2112w + setregw 2113h*4,reg2113w + setregw 2114h*4,reg2114w + setregw 2115h*4,reg2115w + setregw 2116h*4,reg2116w + setregw 2117h*4,reg2117w + setregw 2118h*4,reg2118 + setregw 2119h*4,reg2119inc + setregw 211Ah*4,reg211Aw + setregw 211Bh*4,reg211Bw + setregw 211Ch*4,reg211Cw + setregw 211Dh*4,reg211Dw + setregw 211Eh*4,reg211Ew + setregw 211Fh*4,reg211Fw + setregw 2120h*4,reg2120w + setregw 2121h*4,reg2121w + setregw 2122h*4,reg2122w + setregw 2123h*4,reg2123w + setregw 2124h*4,reg2124w + setregw 2125h*4,reg2125w + setregw 2126h*4,reg2126w + setregw 2127h*4,reg2127w + setregw 2128h*4,reg2128w + setregw 2129h*4,reg2129w + setregw 212Ah*4,reg212Aw + setregw 212Bh*4,reg212Bw + setregw 212Ch*4,reg212Cw + setregw 212Dh*4,reg212Dw + setregw 212Eh*4,reg212Ew + setregw 212Fh*4,reg212Fw + setregw 2130h*4,reg2130w + setregw 2131h*4,reg2131w + setregw 2132h*4,reg2132w + setregw 2133h*4,reg2133w + setregw 2140h*4,reg2140w + setregw 2141h*4,reg2141w + setregw 2142h*4,reg2142w + setregw 2143h*4,reg2143w + setregw 2144h*4,reg2140w + setregw 2180h*4,reg2180w + setregw 2181h*4,reg2181w + setregw 2182h*4,reg2182w + setregw 2183h*4,reg2183w + setregw 4016h*4,reg4016w + setregw 4017h*4,reg4017w + setregw 4200h*4,reg4200w + setregw 4201h*4,reg4201w + setregw 4202h*4,reg4202w + setregw 4203h*4,reg4203w + setregw 4204h*4,reg4204w + setregw 4205h*4,reg4205w + setregw 4206h*4,reg4206w + setregw 4207h*4,reg4207w + setregw 4208h*4,reg4208w + setregw 4209h*4,reg4209w + setregw 420Ah*4,reg420Aw + setregw 420Bh*4,reg420Bw + setregw 420Ch*4,reg420Cw + setregw 420Dh*4,reg420Dw + setregw 420Eh*4,reg420Ew + setregw 4210h*4,reg4210w + setregw 4211h*4,reg4211w + setregw 4212h*4,reg4212w + setregw 4216h*4,reg4216w + setregw 4300h*4,reg43X0w + setregw 4301h*4,reg43X1w + setregw 4302h*4,reg43x2w + setregw 4303h*4,reg43x3w + setregw 4304h*4,reg43x4w + setregw 4305h*4,reg43x5w + setregw 4306h*4,reg43x6w + setregw 4307h*4,reg43x7w + setregw 4308h*4,reg43x8w + setregw 4309h*4,reg43x9w + setregw 430Ah*4,reg43XAw + setregw 430Bh*4,reg43XAw + setregw 430Ch*4,reg43XAw + setregw 430Dh*4,reg43XAw + setregw 430Eh*4,reg43XAw + setregw 430Fh*4,reg43XAw + setregw 4310h*4,reg43X0w + setregw 4311h*4,reg43X1w + setregw 4312h*4,reg43x2w + setregw 4313h*4,reg43x3w + setregw 4314h*4,reg43x4w + setregw 4315h*4,reg43x5w + setregw 4316h*4,reg43x6w + setregw 4317h*4,reg43x7w + setregw 4318h*4,reg43x8w + setregw 4319h*4,reg43x9w + setregw 431Ah*4,reg43XAw + setregw 431Bh*4,reg43XAw + setregw 431Ch*4,reg43XAw + setregw 431Dh*4,reg43XAw + setregw 431Eh*4,reg43XAw + setregw 431Fh*4,reg43XAw + setregw 4320h*4,reg43X0w + setregw 4321h*4,reg43X1w + setregw 4322h*4,reg43x2w + setregw 4323h*4,reg43x3w + setregw 4324h*4,reg43x4w + setregw 4325h*4,reg43x5w + setregw 4326h*4,reg43x6w + setregw 4327h*4,reg43x7w + setregw 4328h*4,reg43x8w + setregw 4329h*4,reg43x9w + setregw 432Ah*4,reg43XAw + setregw 432Bh*4,reg43XAw + setregw 432Ch*4,reg43XAw + setregw 432Dh*4,reg43XAw + setregw 432Eh*4,reg43XAw + setregw 432Fh*4,reg43XAw + setregw 4330h*4,reg43X0w + setregw 4331h*4,reg43X1w + setregw 4332h*4,reg43x2w + setregw 4333h*4,reg43x3w + setregw 4334h*4,reg43x4w + setregw 4335h*4,reg43x5w + setregw 4336h*4,reg43x6w + setregw 4337h*4,reg43x7w + setregw 4338h*4,reg43x8w + setregw 4339h*4,reg43x9w + setregw 433Ah*4,reg43XAw + setregw 433Bh*4,reg43XAw + setregw 433Ch*4,reg43XAw + setregw 433Dh*4,reg43XAw + setregw 433Eh*4,reg43XAw + setregw 433Fh*4,reg43XAw + setregw 4340h*4,reg43X0w + setregw 4341h*4,reg43X1w + setregw 4342h*4,reg43x2w + setregw 4343h*4,reg43x3w + setregw 4344h*4,reg43x4w + setregw 4345h*4,reg43x5w + setregw 4346h*4,reg43x6w + setregw 4347h*4,reg43x7w + setregw 4348h*4,reg43x8w + setregw 4349h*4,reg43x9w + setregw 434Ah*4,reg43XAw + setregw 434Bh*4,reg43XAw + setregw 434Ch*4,reg43XAw + setregw 434Dh*4,reg43XAw + setregw 434Eh*4,reg43XAw + setregw 434Fh*4,reg43XAw + setregw 4350h*4,reg43X0w + setregw 4351h*4,reg43X1w + setregw 4352h*4,reg43x2w + setregw 4353h*4,reg43x3w + setregw 4354h*4,reg43x4w + setregw 4355h*4,reg43x5w + setregw 4356h*4,reg43x6w + setregw 4357h*4,reg43x7w + setregw 4358h*4,reg43x8w + setregw 4359h*4,reg43x9w + setregw 435Ah*4,reg43XAw + setregw 435Bh*4,reg43XAw + setregw 435Ch*4,reg43XAw + setregw 435Dh*4,reg43XAw + setregw 435Eh*4,reg43XAw + setregw 435Fh*4,reg43XAw + setregw 4360h*4,reg43X0w + setregw 4361h*4,reg43X1w + setregw 4362h*4,reg43x2w + setregw 4363h*4,reg43x3w + setregw 4364h*4,reg43x4w + setregw 4365h*4,reg43x5w + setregw 4366h*4,reg43x6w + setregw 4367h*4,reg43x7w + setregw 4368h*4,reg43x8w + setregw 4369h*4,reg43x9w + setregw 436Ah*4,reg43XAw + setregw 436Bh*4,reg43XAw + setregw 436Ch*4,reg43XAw + setregw 436Dh*4,reg43XAw + setregw 436Eh*4,reg43XAw + setregw 436Fh*4,reg43XAw + setregw 4370h*4,reg43X0w + setregw 4371h*4,reg43X1w + setregw 4372h*4,reg43x2w + setregw 4373h*4,reg43x3w + setregw 4374h*4,reg43x4w + setregw 4375h*4,reg43x5w + setregw 4376h*4,reg43x6w + setregw 4377h*4,reg43x7w + setregw 4378h*4,reg43x8w + setregw 4379h*4,reg43x9w + setregw 437Ah*4,reg43XAw + setregw 437Bh*4,reg43XAw + setregw 437Ch*4,reg43XAw + setregw 437Dh*4,reg43XAw + setregw 437Eh*4,reg43XAw + setregw 437Fh*4,reg43XAw + cmp byte[SFXEnable],0 + je .nosfx + call initsfxregsw +.nosfx + cmp byte[SA1Enable],0 + je .nosa1 + call initSA1regsw +.nosa1 + cmp byte[SDD1Enable],0 + je .nosdd1 + call SDD1Reset +.nosdd1 + cmp byte[SPC7110Enable],0 + je .nospc7110 + call SPC7110Reset +.nospc7110 + cmp byte[RTCEnable],0 + je .nortc + call RTCReset2 +.nortc + ret + +; video memory change buffer for caching (65536/16=4096) +;vidmemch2, vidmemch4, vidmemch8. 4096 bytes each + +;******************************************************* +; Registers Note : restore AH, ECX, ESI, EDI, *S & DX +;******************************************************* + + +; Screen display register +reg2100w: + mov [vidbright],al + and byte[vidbright],0Fh + mov [forceblnk],al + and byte[forceblnk],80h + ret + +SECTION .bss +NEWSYM prevoamptr, resb 1 +SECTION .text + +; OAM size register +reg2101w: + cmp byte[prevoamptr],0FFh + je .noskip + cmp byte[prevoamptr],al + je near .noproc +.noskip + mov [prevoamptr],al + xor ebx,ebx + mov bl,al + and bl,03h + shl bx,14 + mov [objptr],bx + mov [objptrn],bx + xor ebx,ebx + mov bl,al + and bl,18h + shr bl,3 + shl bx,13 + add [objptrn],bx + xor ebx,ebx + mov bl,al + shr bl,5 + push eax + mov byte[NextLineCache],1 + mov al,[.objsize1+ebx] + mov [objsize1],al + mov al,[.objsize2+ebx] + mov [objsize2],al + mov al,[.objmovs1+ebx] + mov [objmovs1],al + mov al,[.objmovs2+ebx] + mov [objmovs2],al + mov ax,[.objadds1+ebx*2] + mov [objadds1],ax + mov ax,[.objadds2+ebx*2] + mov [objadds2],ax + pop eax +.noproc + ret + +SECTION .data +.objsize1 db 1,1,1,4,4,16,1,1 +.objsize2 db 4,16,64,16,64,64,4,4 +.objmovs1 db 2,2,2,2,2,4,2,2 +.objmovs2 db 2,4,8,4,8,8,2,2 +.objadds1 dw 14,14,14,14,14,12,14,14 +.objadds2 dw 14,12,8,12,8,8,14,14 + +SECTION .bss +NEWSYM oamlow, resb 1 +SECTION .text + +; OAM address register +reg2102w: + mov byte[oamlow],1 + mov word[oamaddr],0 + shr word[oamaddr],1 + mov [oamaddr],al + shl word[oamaddr],1 +; or al,al +; jz .skipstore + mov bx,[oamaddrs] + mov [poamaddrs],bx + mov bx,[oamaddr] + mov [oamaddrs],bx +.skipstore + cmp byte[nexthprior],1 + je .priorset + mov byte[objhipr],0 + jmp .cachespr +.priorset + mov bx,[oamaddr] + shr bx,2 + and bl,0x7F +; cmp bl,80h +; jae .noreset +; xor bl,bl +.noreset + mov [objhipr],bl +.cachespr + ret + +; OAM address register +reg2103w: + cmp byte[oamlow],1 + jne .afteroamlow + mov byte[oamlow],0 + mov bl,al + and bl,01h + shr word[oamaddr],1 + mov [oamaddr+1],bl + shl word[oamaddr],1 +.afteroamlow + cmp word[poamaddrs],200h + jbe .notinvptr + cmp word[oamaddr],200h + jne .notinvptr + mov bx,[poamaddrs] + mov [oamaddr],bx + mov byte[nosprincr],1 +.notinvptr + mov bx,[oamaddr] + mov [oamaddrs],bx + test al,80h + jnz .hipri + mov byte[nexthprior],0 + mov byte[NextLineCache],1 + ret +.hipri + mov byte[nexthprior],1 + mov byte[NextLineCache],1 + ret + +; OAM data register +reg2104w: + mov byte[NextLineCache],1 + mov ebx,[oamaddr] + cmp byte[nosprincr],1 + je .noinc + inc dword[oamaddr] + cmp ebx,544 + jae .overflow +.noinc + mov [oamram+ebx],al + ret +.overflow + xor ebx,ebx + mov dword[oamaddr],1 + mov [oamram+ebx],al + ret + +; Screen mode register +reg2105w: + mov bl,al + and bl,00000111b + mov [bgmode],bl + mov bl,al + shr bl,3 + and bl,01h + mov [bg3highst],bl + mov bl,al + shr bl,4 + mov [bgtilesz],bl + mov bl,al + mov dword[BG116x16t],0 + add bl,bl + adc byte[BG416x16t],0 + add bl,bl + adc byte[BG316x16t],0 + add bl,bl + adc byte[BG216x16t],0 + add bl,bl + adc byte[BG116x16t],0 + ret + +; Screen pixelation register +reg2106w: + mov bl,al + and bl,0Fh + mov [mosaicon],bl + mov bl,al + shr bl,4 + mov [mosaicsz],bl + ret + +; BG1 VRAM location register +reg2107w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg1ptr],bx + mov [bg1ptrb],bx + mov [bg1ptrc],bx + mov [bg1ptrd],bx + mov dword[bg1ptrx],0 + mov dword[bg1ptry],0 + mov bl,al + and bl,00000011b + mov [bg1scsize],bl + cmp bl,1 + jne .skipa + add word[bg1ptrb],800h + add word[bg1ptrd],800h + mov dword[bg1ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg1ptrc],800h + add word[bg1ptrd],800h + mov dword[bg1ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg1ptrb],800h + add word[bg1ptrc],1000h + add word[bg1ptrd],1800h + mov dword[bg1ptrx],800h + mov dword[bg1ptry],1000h +.skipc + ret + +; BG2 VRAM location register +reg2108w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg2ptr],bx + mov [bg2ptrb],bx + mov [bg2ptrc],bx + mov [bg2ptrd],bx + mov dword[bg2ptrx],0 + mov dword[bg2ptry],0 + mov bl,al + and bl,00000011b + mov [bg2scsize],bl + cmp bl,1 + jne .skipa + add word[bg2ptrb],800h + add word[bg2ptrd],800h + mov dword[bg2ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg2ptrc],800h + add word[bg2ptrd],800h + mov dword[bg2ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg2ptrb],800h + add word[bg2ptrc],1000h + add word[bg2ptrd],1800h + mov dword[bg2ptrx],800h + mov dword[bg2ptry],1000h +.skipc + ret + +; BG3 VRAM location register +reg2109w: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg3ptr],bx + mov [bg3ptrb],bx + mov [bg3ptrc],bx + mov [bg3ptrd],bx + mov dword[bg3ptrx],0 + mov dword[bg3ptry],0 + mov bl,al + and bl,00000011b + mov [bg3scsize],bl + cmp bl,1 + jne .skipa + add word[bg3ptrb],800h + add word[bg3ptrd],800h + mov dword[bg3ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg3ptrc],800h + add word[bg3ptrd],800h + mov dword[bg3ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg3ptrb],800h + add word[bg3ptrc],1000h + add word[bg3ptrd],1800h + mov dword[bg3ptrx],800h + mov dword[bg3ptry],1000h +.skipc + ret + +; BG4 VRAM location register +reg210Aw: + xor ebx,ebx + mov bl,al + shr bl,2 + shl bx,11 + mov [bg4ptr],bx + mov [bg4ptrb],bx + mov [bg4ptrc],bx + mov [bg4ptrd],bx + mov dword[bg4ptrx],0 + mov dword[bg4ptry],0 + mov bl,al + and bl,00000011b + mov [bg4scsize],bl + cmp bl,1 + jne .skipa + add word[bg4ptrb],800h + add word[bg4ptrd],800h + mov dword[bg4ptrx],800h +.skipa + cmp bl,2 + jne .skipb + add word[bg4ptrc],800h + add word[bg4ptrd],800h + mov dword[bg4ptry],800h +.skipb + cmp bl,3 + jne .skipc + add word[bg4ptrb],800h + add word[bg4ptrc],1000h + add word[bg4ptrd],1800h + mov dword[bg4ptrx],800h + mov dword[bg4ptry],1000h +.skipc + ret + +; BG1 & BG2 VRAM location register +reg210Bw: + xor ebx,ebx + mov bl,al + and bl,0Fh + shl bx,13 + mov [bg1objptr],bx + mov bl,al + shr bl,4 + shl bx,13 + mov [bg2objptr],bx + ret + +; BG3 & BG4 VRAM location register +reg210Cw: + xor ebx,ebx + mov bl,al + and bl,0Fh + shl bx,13 + mov [bg3objptr],bx + mov bl,al + shr bl,4 + shl bx,13 + mov [bg4objptr],bx + ret + +; BG1 horizontal scroll register +reg210Dw: + xor ebx,ebx + mov [bg1scrolx],al + shl word[bg1scrolx],8 + mov bl,[bgscroltemp] + add word[bg1scrolx],bx + mov [bgscroltemp],al + ret + +; BG1 vertical scroll register +reg210Ew: + xor ebx,ebx + mov [bg1scroly],al + shl word[bg1scroly],8 + mov bl,[bgscroltemp] + add word[bg1scroly],bx + mov [bgscroltemp],al + ret + +SECTION .bss +bgscroltemp resb 1 +SECTION .text + +; BG2 horizontal scroll register +reg210Fw: + xor ebx,ebx + mov [bg2scrolx],al + shl word[bg2scrolx],8 + mov bl,[bgscroltemp] + add word[bg2scrolx],bx + mov [bgscroltemp],al + ret + +; BG2 vertical scroll register +reg2110w: + xor ebx,ebx + mov [bg2scroly],al + shl word[bg2scroly],8 + mov bl,[bgscroltemp] + add word[bg2scroly],bx + mov [bgscroltemp],al + ret + +; BG3 horizontal scroll register +reg2111w: + xor ebx,ebx + mov [bg3scrolx],al + shl word[bg3scrolx],8 + mov bl,[bgscroltemp] + add word[bg3scrolx],bx + mov [bgscroltemp],al + ret + +section .data +NEWSYM latchbg3, db 0 + +section .text + +; BG3 vertical scroll register +reg2112w: + xor ebx,ebx + mov [bg3scroly],al + shl word[bg3scroly],8 + mov bl,[bgscroltemp] + add word[bg3scroly],bx + mov [bgscroltemp],al + ret + +; BG4 horizontal scroll register +reg2113w: + xor ebx,ebx + mov [bg4scrolx],al + shl word[bg4scrolx],8 + mov bl,[bgscroltemp] + add word[bg4scrolx],bx + mov [bgscroltemp],al + ret + +; BG4 vertical scroll register +reg2114w: + xor ebx,ebx + mov [bg4scroly],al + shl word[bg4scroly],8 + mov bl,[bgscroltemp] + add word[bg4scroly],bx + mov [bgscroltemp],al + ret + +; Video port control +reg2115w: + and al,11111111b + mov [vraminctype],al + mov bl,al + and bl,00000011b + cmp bl,0 + jne .skip1 + mov word[addrincr],2 +.skip1 + cmp bl,1 + jne .skip2 + mov word[addrincr],64 +.skip2 + cmp bl,2 + jne .skip3 + mov word[addrincr],256 +.skip3 + cmp bl,3 + jne .skip4 + mov word[addrincr],256 +.skip4 + mov bl,al + mov byte[vramincby8on],0 + and bl,00001100b + jz near .noincby8 + mov byte[vramincby8on],1 + cmp bl,4 + jne .nextinc8 + mov byte[vramincby8left],64-1 + mov byte[vramincby8totl],5 + mov word[vramincby8ptri],65535-511 + mov word[vramincby8var],256+128+64 +.nextinc8 + cmp bl,8 + jne .nextinc8b + mov byte[vramincby8left],128-1 + mov byte[vramincby8totl],6 + mov word[vramincby8ptri],65535-1023 + mov word[vramincby8var],512+256+128 +.nextinc8b + cmp bl,12 + jne .nextinc8c + mov byte[vramincby8left],256-1 + mov byte[vramincby8totl],7 + mov word[vramincby8ptri],65535-2047 + mov word[vramincby8var],1024+512+256 +.nextinc8c + mov ebx,[regptw] + test al,80h + jz .from2118 + mov dword[ebx+2118h*4],reg2118inc8 + mov dword[ebx+2119h*4],reg2119inc8inc + mov byte[vramincr],0 + jmp .from2119 +.from2118 + mov dword[ebx+2118h*4],reg2118inc8inc + mov dword[ebx+2119h*4],reg2119inc8 + mov byte[vramincr],1 +.from2119 + ret +.noincby8 + mov ebx,[regptw] + test al,80h + jz .from2118b + mov dword[ebx+2118h*4],reg2118 + mov dword[ebx+2119h*4],reg2119inc + mov byte[vramincr],0 + jmp .from2119b +.from2118b + mov dword[ebx+2118h*4],reg2118inc + mov dword[ebx+2119h*4],reg2119 + mov byte[vramincr],1 +.from2119b + ret + +; Video port address (Low) +reg2116w: + shr word[vramaddr],1 + mov [vramaddr],al + shl word[vramaddr],1 + mov byte[vramread],0 + ret + +; Video port address (High) +reg2117w: + shr word[vramaddr],1 + mov [vramaddr+1],al + shl word[vramaddr],1 + mov byte[vramread],0 + + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov bl,[ebx] + mov [vramread],bl + xor ebx,ebx + mov bx,[vramaddr] + add ebx,[vram] + mov bl,[ebx+1] + mov [vramread2],bl + ret + +; Video port data (Low) +NEWSYM reg2118 + mov ebx,[vramaddr] + mov [vrama+ebx],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 + ret + +NEWSYM reg2118inc + mov ebx,[vramaddr] + mov [vrama+ebx],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 + mov ebx,[addrincr] + add [vramaddr],bx + ret + +NEWSYM reg2118inc8 + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx + add ebx,[vram] +; cmp [ebx],al +; je .nochange2 + mov [ebx],al + sub ebx,[vram] + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + ret + +NEWSYM reg2118inc8inc + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx + add ebx,[vram] +; cmp [ebx],al +; je .nochange2 + mov [ebx],al + sub ebx,[vram] + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + mov ebx,[addrincr] + add [vramaddr],bx + ret + +NEWSYM reg2119 + cmp dword[vramaddr],0E000h + jb .skip + mov byte[debstop],1 +.skip + mov ebx,[vramaddr] +; cmp [vrama+ebx+1],al +; je .nochange + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + ret + +NEWSYM reg2119inc + mov ebx,[vramaddr] +; cmp [vrama+ebx+1],al +; je .nochange + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange + mov ebx,[addrincr] + add [vramaddr],bx + ret + +NEWSYM reg2119inc8 + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx +; cmp [vrama+ebx+1],al +; je .nochange2 + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + ret + +NEWSYM reg2119inc8inc + push ecx + xor ecx,ecx + mov ebx,[vramaddr] + mov cl,[vramincby8left] + and ebx,ecx + shl ebx,3 + push eax + mov eax,[vramaddr] + and ax,[vramincby8var] + mov cl,[vramincby8totl] + shr eax,cl + add ebx,eax + mov eax,[vramaddr] + and ax,[vramincby8ptri] + add ebx,eax + pop eax + pop ecx +; cmp [vrama+ebx+1],al +; je .nochange2 + mov [vrama+ebx+1],al + shr ebx,4 + mov byte[vidmemch2+ebx],1 + mov byte[vidmemch4+ebx],1 + mov byte[vidmemch8+ebx],1 +.nochange2 + mov ebx,[addrincr] + add [vramaddr],bx + ret + +; MODE7 settings register +reg211Aw: + mov [mode7set],al + ret + +SECTION .data +NEWSYM multchange, db 1 +SECTION .text + +; COS (COSINE) rotate angle / X Expansion +reg211Bw: + mov bl,[mode7A+1] + mov [mode7A],bl + mov [mode7A+1],al + mov byte[multchange],1 + ret + +; SIN (SIN) rotate angle / X Expansion & Complement Multiplication Start +reg211Cw: + mov bl,[mode7B+1] + mov [mode7B],bl + mov [mode7B+1],al + mov byte[multchange],1 + ret + +; SIN (SIN) rotate angle / Y Expansion +reg211Dw: + mov bl,[mode7C+1] + mov [mode7C],bl + mov [mode7C+1],al + ret + +; COS (COSINE) rotate angle / Y Expansion +reg211Ew: + mov bl,[mode7D+1] + mov [mode7D],bl + mov [mode7D+1],al + ret + +; Center position X (13-bit data only) +reg211Fw: + mov bl,[mode7X0+1] + mov [mode7X0],bl + mov [mode7X0+1],al + ret + +; Center position Y (13-bit data only) +reg2120w: + mov bl,[mode7Y0+1] + mov [mode7Y0],bl + mov [mode7Y0+1],al + ret + +; Colour # (or palette) selection register +reg2121w: + xor bh,bh + mov bl,al + shl bx,1 + mov [cgaddr],bx + and word[cgaddr],01FFh + ret + +; Colour data register +reg2122w: + xor ebx,ebx + mov bx,[cgaddr] + cmp [cgram+ebx],al + je .nomod + mov [cgram+ebx],al + mov byte[cgmod],1 +.nomod + inc word[cgaddr] + and word[cgaddr],01FFh + ret + +; Window mask settings register [W12SEL] +reg2123w: + mov bl,al + and bl,0Fh + test bl,0Ah + jnz .nen1 +; or bl,02h +.nen1 + mov [winbg1en],bl + mov bl,al + shr bl,4 + test bl,0Ah + jnz .nen2 +; or bl,02h +.nen2 + mov [winbg2en],bl + ret + +; Window mask settings register [W34SEL] +reg2124w: + mov bl,al + and bl,0Fh + test bl,0Ah + jnz .nen1 +; or bl,02h +.nen1 + mov [winbg3en],bl + mov bl,al + shr bl,4 + test bl,0Ah + jnz .nen2 +; or bl,02h +.nen2 + mov [winbg4en],bl + ret + +; Window mask settings register [WOBJSEL] +reg2125w: + mov bl,al + and bl,0Fh + mov [winobjen],bl + mov bl,al + shr bl,4 + mov [wincolen],bl + ret + +; Window 1 left position register +reg2126w: + mov [winl1],al + ret + +; Window 1 right position register +reg2127w: + mov [winr1],al + ret + +; Window 2 left position register +reg2128w: + mov [winl2],al + ret + +; Window 2 right position register +reg2129w: + mov [winr2],al + ret + +; Mask logic settings for Window 1 & 2 per screen +reg212Aw: + mov [winlogica],al + ret + +; Mask logic settings for Colour Windows & OBJ Windows +reg212Bw: + mov [winlogicb],al + ret + +; Main screen designation +reg212Cw: + mov [scrnon],al + ret + +; Sub-screen designation +reg212Dw: + mov [scrnon+1],al + ret + +; Window mask main screen designation register +reg212Ew: + mov [winenabm],al + ret + +; Window mask sub screen designation register +reg212Fw: + mov [winenabs],al + ret + +; Fixed color addition or screen addition register +reg2130w: + mov [scaddset],al + ret + +; Addition/subtraction for screens, BGs, & OBJs +reg2131w: + mov [scaddtype],al + ret + +; Fixed colour data for fixed colour +/- +reg2132w: + mov bl,al + and bl,1Fh + test al,20h + jz .nored + mov [coladdr],bl +.nored + test al,40h + jz .nogreen + mov [coladdg],bl +.nogreen + test al,80h + jz .noblue + mov [coladdb],bl +.noblue + ret + +; Screen mode/video select register +reg2133w: + mov [interlval],al + and byte[interlval],41h + test al,04h + jnz .line239 + mov word[resolutn],224 + ret +.line239 + mov word[resolutn],239 + ret + +SECTION .bss +NEWSYM CleartheScreen, resb 1 +SECTION .text + +; Sound Register #1 +reg2140w: + mov byte[sndwrit],1 + cmp byte[nmistatus],2 + jne .n + mov byte[nmirept],0 +.n + mov [SPCRAM+0F4h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #2 +reg2141w: + mov byte[sndwrit],1 + mov [SPCRAM+0F5h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #3 +reg2142w: + mov byte[sndwrit],1 + mov [SPCRAM+0F6h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Sound Register #4 +reg2143w: + mov byte[sndwrit],1 + mov [SPCRAM+0F7h],al + inc dword[SPC700write] + reenablespc + ret +; cmp dword[cycpbl],0FFFFh +; ja .spcreset +; ret +;.spcreset +; mov dword[cycpbl],100 +; ret + +; Read/write WRAM register +reg2180w: + mov ebx,[wramrwadr] + add ebx,[wramdata] + mov [ebx],al + inc dword[wramrwadr] + and dword[wramrwadr],01FFFFh + ret + +; WRAM data register (low byte) +reg2181w: + mov [wramrwadr],al + ret + +; WRAM data register (middle byte) +reg2182w: + mov [wramrwadr+1],al + ret + +; WRAM data register (high byte) +reg2183w: + mov bl,al + and bl,01h + mov [wramrwadr+2],bl + ret + +; Joystick 1 & 2 status bytes +SECTION .bss +NEWSYM MultiTapStat, resb 1 +SECTION .text + +reg4016w: + test byte[INTEnab],1 + jnz .nointenab + mov ebx,[JoyAOrig] + or ebx,0FFFFh + mov [JoyANow],ebx + mov ebx,[JoyBOrig] + or ebx,0FFFFh + mov [JoyBNow],ebx + mov ebx,[JoyCOrig] + or ebx,0FFFFh + mov [JoyCNow],ebx + mov ebx,[JoyDOrig] + or ebx,0FFFFh + mov [JoyDNow],ebx + mov ebx,[JoyEOrig] + or ebx,0FFFFh + mov [JoyENow],ebx + cmp al,01h + jne .noreset + or byte[MultiTapStat],1 + ret +.noreset + and byte[MultiTapStat],0FEh + ret +.nointenab + cmp al,01h + jne .noone + or byte[MultiTapStat],1 + or byte[JoyCRead],2 + ret +.noone + and byte[MultiTapStat],0FEh + cmp al,0 + jne near .nozero + or byte[JoyCRead],1 + cmp byte[JoyCRead],3 + jne near .nozero +.resetports + mov ebx,[JoyAOrig] + or ebx,0FFFFh + mov [JoyANow],ebx + or ebx,0FFFFh + mov ebx,[JoyBOrig] + or ebx,0FFFFh + mov [JoyBNow],ebx + or ebx,0FFFFh + mov ebx,[JoyCOrig] + or ebx,0FFFFh + mov [JoyCNow],ebx + or ebx,0FFFFh + mov ebx,[JoyDOrig] + or ebx,0FFFFh + mov [JoyDNow],ebx + or ebx,0FFFFh + mov ebx,[JoyEOrig] + or ebx,0FFFFh + mov [JoyENow],ebx +.nozero + ret + +; Joystick 1 & 2 status bytes +reg4017w: + ret + +; Counter enable +reg4200w: + mov [INTEnab],al + ret + +; Programmable I/O port (out-port) +reg4201w: + cmp byte[iohvlatch],1 + jne .noiohvlatch + test al,80h + jnz .noiohvlatch + mov byte[iohvlatch],0 +.noiohvlatch + test byte[ioportval],80h + jnz .nolatch + test al,80h + jz .nolatch + mov byte[iohvlatch],1 +.nolatch + mov [ioportval],al + mov bl,al + and bl,80h + and byte[MultiTapStat],07Fh + or byte[MultiTapStat],bl + ret + +; Multiplicand 'A' +reg4202w: + mov [multa],al + ret + +; Multiplier 'B' +reg4203w: + push edx + push eax + xor ah,ah + xor bh,bh + mov bl,[multa] + mul bx + mov [multres],ax + pop eax + pop edx + ret + +; Dividend C (Low) +reg4204w: + mov [diva],al + ret + +; Dividend C (High) +reg4205w: + mov [diva+1],al + ret + +; Divisor B +reg4206w: + cmp al,0 + je .divby0 + push eax + push edx + xor ebx,ebx + xor edx,edx + mov bl,al + mov ax,[diva] + div bx + mov [divres],ax + mov [multres],dx + pop edx + pop eax + ret +.divby0 + push eax + mov word[divres],0FFFFh + mov ax,[diva] + mov [multres],ax + pop eax + ret + + +DetermineHIRQExec + cmp byte[HIRQSkip],1 + je near .ret + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 + push eax + push ecx + push edx + mov ax,[HIRQLoc] + xor ecx,ecx + mov cl,[cycpl] + mul cx + mov cx,340 + div cx + mov cl,[cycpl] + sub cl,al + pop edx + cmp dh,cl + ja .hirqokay +.notokay + pop ecx + pop eax +.ret + ret +.hirqokay + sub dh,cl + add dh,30 + add cl,16 + mov [HIRQCycNext],cl + mov byte[HIRQNextExe],1 + pop ecx + pop eax + ret + +; Video horizontal IRQ beam position/pointer (Low) +reg4207w: + cmp [HIRQLoc],al + je .nohirqc + mov [HIRQLoc],al + mov bx,[curypos] + cmp bx,[VIRQLoc] + je near DetermineHIRQExec +.nohirqc + ret + +; Video horizontal IRQ beam position/pointer (High) +reg4208w: + cmp [HIRQLoc+1],al + je .nohirqc + mov [HIRQLoc+1],al + mov bx,[curypos] + cmp bx,[VIRQLoc] + je near DetermineHIRQExec +.nohirqc + ret + +; Video vertical IRQ beam position/pointer (Low) +reg4209w: + mov [VIRQLoc],al +; mov bx,[curypos] + cmp byte[HIRQNextExe],1 + je .nohirq + ret +.nohirq + mov bx,[curypos] + cmp bx,[VIRQLoc] + je .nocancelhirq + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 +.nocancelhirq + ret + +; Video vertical IRQ beam position/pointer (High) +reg420Aw: + and al,01h + mov [VIRQLoc+1],al + mov bx,[totlines] + sub bx,1 + cmp word[VIRQLoc],bx + jb .okvirqpos + mov word[VIRQLoc],07FFFh +.okvirqpos + cmp byte[HIRQNextExe],1 + je .nohirq + ret +.nohirq + mov bx,[curypos] + cmp bx,[VIRQLoc] + je .nocancelhirq + add dh,[HIRQCycNext] + mov byte[HIRQCycNext],0 + mov byte[HIRQNextExe],0 +.nocancelhirq + ret + +; Cycle speed register +reg420Dw: + test al,01h + jnz .speed358 + ; 2.68 Mhz + mov al,[opexec268] + mov [cycpl],al ; 2.68 Mhz + mov al,[opexec268cph] + mov [cycphb],al ; 2.68 Mhz + and byte[xirqb],00h + mov bl,[cycpb268] + mov [cycpblt],bl ; percentage of CPU/SPC to run + ret +.speed358 + ; 3.58 Mhz + mov al,[opexec358] + mov [cycpl],al ; 3.58 Mhz + mov al,[opexec358cph] + mov [cycphb],al ; 3.58 Mhz + or byte[xirqb],80h + mov bl,[cycpb358] + mov [cycpblt],bl ; percentage of CPU/SPC to run + ret + +; ??? +reg420Ew: + ret + +; NMI Check register +reg4210w: + ret + +; Video IRQ register +reg4211w: + ret + +; Status register +reg4212w: + ret + +; Product of Multiplication Result or Remainder of Divide Result (Low) +reg4216w: + ret + +; DMA Control register +reg43X0w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + mov byte[hdmarestart],1 + ret + +; DMA Destination register +reg43X1w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + mov byte[hdmarestart],1 + ret + +; Source address (Low) +reg43x2w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al +; mov [dmadata+ebx+6],al + ret + +; Source address (High) +reg43x3w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al +; mov [dmadata+ebx+6],al + ret + +; Source bank address +reg43x4w + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (Low) +reg43x5w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (High) +reg43x6w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; DMA transfer size & HDMA address register (Bank) +reg43x7w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Table Address of A-BUS by DMA < A2 Table Address (Low) +reg43x8w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Table Address of A-BUS by DMA < A2 Table Address (High) +reg43x9w: + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + ret + +; Number of lines for HDMA transfer +reg43XAw: + mov byte[nohdmaframe],0 + xor ebx,ebx + mov bx,cx + sub bx,4300h + mov [dmadata+ebx],al + mov bx,[resolutn] + cmp word[curypos],bx + jb .nodma + mov byte[nohdmaframe],1 + inc byte[hdmadelay] +.nodma + ret + +regINVALIDw: ; Invalid Register + ret + + +regexiter: + mov bl,[xpb] + mov ax,[xpc] + test ax,8000h + jz .loweraddr2 + mov eax,[snesmmap+ebx*4] + jmp .nextaddr +.loweraddr2 + mov eax,[snesmap2+ebx*4] +.nextaddr + mov ebx,esi + sub ebx,eax ; subtract program counter by address + mov [.invaddr],bx + mov bl,[xpb] + mov [.invbank],bl + + mov al,[previdmode] + mov ah,0 + int 10h + mov byte[invalid],1 + mov [invreg],cx + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov ax,[invreg] + call printhex + mov ah,9 + mov edx,.invalidreg + int 21h + xor eax,eax + mov al,[.invbank] + call printhex8 + mov ax,[.invaddr] + call printhex + mov ah,2 + mov dl,13 + int 21h + mov ah,2 + mov dl,10 + int 21h + mov eax,[numinst] + call printnum + jmp DosExit + +SECTION .data +.invalidreg db 'Invalid Write Register : $' +.invalidaddr db ' at address $' + +SECTION .bss +.invbank resb 1 +.invaddr resb 1 +SECTION .text