o add avrusb

o add zsnes
This commit is contained in:
optixx
2009-04-06 21:19:15 +02:00
parent c9a23df103
commit bcb4a055e9
449 changed files with 280735 additions and 0 deletions

33
zsnes/src/Makefile.check Normal file
View File

@@ -0,0 +1,33 @@
##############################################################################
# Makes sure that a system is capable of running ZSNES, errors out with
# an informative message if it is not.
##############################################################################
##############################################################################
# VARIABLES
##############################################################################
NASMMINVER=0.98.36
##############################################################################
# CHECKS
##############################################################################
# NASM version check
NASMVER=$(word 3, $(shell nasm -v))
ifeq ($(strip $(NASMVER)),)
$(error Could not find NASM executable. Please install NASM)
endif
ifneq ($(word 1, $(sort $(NASMMINVER) $(NASMVER))),$(NASMMINVER))
$(error ZSNES needs at least NASM version $(NASMMINVER) to compile. You have version $(NASMVER) installed)
endif
# OpenGL check
USE_OPENGL=true
ifeq ($(strip $(wildcard /usr/lib/libGL.so* /usr/local/lib/libGL.so*)),)
$(warning Could not find OpenGL libraries. Continuing without OpenGL support)
USE_OPENGL=false
endif
ifeq ($(strip $(wildcard /usr/include/GL/gl.h /usr/local/include/GL/gl.h)),)
$(warning Could not find OpenGL headers. Continuing without OpenGL support)
USE_OPENGL=false
endif

158
zsnes/src/Makefile.in Normal file
View File

@@ -0,0 +1,158 @@
#Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
#
#http://www.zsnes.com
#http://sourceforge.net/projects/zsnes
#https://zsnes.bountysource.com
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#version 2 as published by the Free Software Foundation.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
CHIP_D=chips
CPU_D=cpu
DOS_D=dos
EFF_D=effects
GUI_D=gui
JMA_D=jma
MMLIB_D=mmlib
NET_D=net
PORT_D=linux
TOOL_D=tools
VID_D=video
ZIP_D=zip
PSR=parsegen
PSR_H=cfg.h md.h input.h
CHIP_O=$(CHIP_D)/c4emu.o $(CHIP_D)/c4proc.o $(CHIP_D)/dsp1emu.o\
$(CHIP_D)/dsp1proc.o $(CHIP_D)/dsp2proc.o $(CHIP_D)/dsp3emu.o\
$(CHIP_D)/dsp3proc.o $(CHIP_D)/dsp4emu.o $(CHIP_D)/dsp4proc.o\
$(CHIP_D)/fxemu2.o $(CHIP_D)/fxemu2b.o $(CHIP_D)/fxemu2c.o\
$(CHIP_D)/fxtable.o $(CHIP_D)/obc1emu.o $(CHIP_D)/obc1proc.o\
$(CHIP_D)/sa1proc.o $(CHIP_D)/sa1regs.o $(CHIP_D)/sdd1emu.o\
$(CHIP_D)/seta10.o $(CHIP_D)/sfxproc.o $(CHIP_D)/st10proc.o\
$(CHIP_D)/7110proc.o $(CHIP_D)/seta11.o $(CHIP_D)/st11proc.o
CPU_O=$(CPU_D)/dma.o $(CPU_D)/dsp.o $(CPU_D)/dspproc.o $(CPU_D)/execute.o\
$(CPU_D)/executec.o $(CPU_D)/irq.o $(CPU_D)/memory.o $(CPU_D)/memtable.o\
$(CPU_D)/spc700.o $(CPU_D)/stable.o $(CPU_D)/table.o $(CPU_D)/tablec.o
DEBUG_O=@DEBUGGER_FILES@
EFF_O=$(EFF_D)/burn.o $(EFF_D)/smoke.o $(EFF_D)/water.o
GUI_O=$(GUI_D)/gui.o $(GUI_D)/guifuncs.o $(GUI_D)/menu.o
JMA_O=@JMA_FILES@
MAIN_O=cfg.o endmem.o init.o initc.o input.o md.o patch.o ui.o vcache.o\
version.o zloader.o zmovie.o zpath.o zstate.o ztime.o ztimec.o
MMLIB_O=@MMLIB_FILES@
NET_O=
#$(NET_D)/ztcp.o
PORT_O=$(PORT_D)/audio.o $(PORT_D)/battery.o\
$(PORT_D)/sdlintrf.o $(PORT_D)/sdllink.o @GL_DRAW@ $(PORT_D)/sw_draw.o\
$(PORT_D)/safelib.o
TOOL_O=$(TOOL_D)/fileutil.o $(TOOL_D)/strutil.o
VID_O=$(VID_D)/makev16b.o $(VID_D)/makev16t.o $(VID_D)/makevid.o\
$(VID_D)/mode716.o $(VID_D)/mode716b.o $(VID_D)/mode716d.o\
$(VID_D)/mode716e.o $(VID_D)/mode716t.o $(VID_D)/mode7.o\
$(VID_D)/mode7ext.o $(VID_D)/mv16tms.o $(VID_D)/m716text.o\
$(VID_D)/newg162.o $(VID_D)/newgfx.o $(VID_D)/newgfx16.o\
$(VID_D)/newgfx2.o $(VID_D)/procvid.o $(VID_D)/procvidc.o\
$(VID_D)/sw_draw.o $(VID_D)/2xsaiw.o $(VID_D)/hq2x16.o $(VID_D)/hq2x32.o\
$(VID_D)/hq3x16.o $(VID_D)/hq3x32.o $(VID_D)/hq4x16.o $(VID_D)/hq4x32.o\
$(VID_D)/ntsc.o $(VID_D)/copyvwin.o
ZIP_O=$(ZIP_D)/unzip.o $(ZIP_D)/zpng.o
Z_OBJS=$(MAIN_O) $(CHIP_O) $(CPU_O) $(DEBUG_O) $(GUI_O) $(EFF_O) $(JMA_O)\
$(MMLIB_O) $(NET_O) $(VID_O) $(PORT_O) $(ZIP_O)
.PHONY: default main tools all install clean tclean distclean
.SUFFIXES: .asm .c .cpp .psr
%: %.cpp
@CXX@ @CXXFLAGS@ -o $@ $<
%.o: %.asm
@NASMPATH@ @NFLAGS@ -o $@ $<
%.o: %.c
@CC@ @CFLAGS@ -o $@ -c $<
%.o: %.cpp
@CXX@ @CXXFLAGS@ -o $@ -c $<
%.o %.h: %.psr $(PSR)
./$(PSR) @PSRFLAGS@ -gcc @CC@ -compile -flags "@CFLAGS@ -O1" -cheader $*.h -fname $* $*.o $<
default: main
all: main tools
main: makefile.dep $(Z_OBJS)
@ZC@ -o @ZSNESEXE@ $(Z_OBJS) @ZCFLAGS@ @LDFLAGS@
rm -f version.o
$(PSR): parsegen.cpp
@CXX@ @CXXFLAGS@ -o $@ $< -lz
TOOLSEXE=$(TOOL_D)/archopt $(TOOL_D)/cutrtype $(TOOL_D)/extraext\
$(TOOL_D)/macroll $(TOOL_D)/minwhite $(TOOL_D)/nreplace\
$(TOOL_D)/sec-test $(TOOL_D)/srccount $(TOOL_D)/varrep
tools: $(TOOLSEXE) $(TOOL_D)/depbuild
$(TOOL_D)/archopt: $(TOOL_D)/archopt.c
@CC@ @CFLAGS@ -m32 -o $@ $@.c
$(TOOL_D)/cutrtype: $(TOOL_D)/cutrtype.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
$(TOOL_D)/depbuild: $(TOOL_D)/depbuild.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
$(TOOL_D)/extraext: $(TOOL_D)/extraext.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
$(TOOL_D)/macroll: $(TOOL_D)/macroll.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
$(TOOL_D)/minwhite: $(TOOL_D)/minwhite.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_D)/fileutil.o
$(TOOL_D)/nreplace: $(TOOL_D)/nreplace.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_D)/fileutil.o
$(TOOL_D)/sec-test: $(TOOL_D)/sec-test.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
$(TOOL_D)/srccount: $(TOOL_D)/srccount.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_D)/fileutil.o
$(TOOL_D)/varrep: $(TOOL_D)/varrep.cpp $(TOOL_O)
@CXX@ @CXXFLAGS@ -o $@ $@.cpp $(TOOL_O)
include makefile.dep
makefile.dep: $(TOOL_D)/depbuild Makefile
$(TOOL_D)/depbuild @CC@ "@CFLAGS@" @NASMPATH@ "@NFLAGS@" $(Z_OBJS) > makefile.dep
Makefile: Makefile.in config.status
./config.status
config.status: configure.in
./autogen.sh --recheck
install:
@INSTALL@ -d -m 0755 $(DESTDIR)/@prefix@/bin
@INSTALL@ -m 0755 @ZSNESEXE@ $(DESTDIR)/@prefix@/bin
@INSTALL@ -d -m 0755 $(DESTDIR)/@prefix@/man/man1
@INSTALL@ -m 0644 linux/zsnes.1 $(DESTDIR)/@prefix@/man/man1
uninstall:
rm -f @prefix@/bin/$(notdir @ZSNESEXE@) @prefix@/man/man1/zsnes.1
clean:
rm -f $(Z_OBJS) $(PSR) $(PSR_H) @ZSNESEXE@
tclean:
rm -f $(TOOL_O) $(TOOLSEXE)
distclean: clean tclean
rm -f Makefile makefile.dep aclocal.m4 configure config.log \
config.status config.h $(TOOL_D)/depbuild

310
zsnes/src/SConstruct Normal file
View File

@@ -0,0 +1,310 @@
# SConstruct file for ZSNES
# Run 'scons' in this directory to build.
# Run 'scons -c' in this directory to cleanup.
import os
env = Environment ()
platform = env['PLATFORM']
parsegen_tool = env.Program(target= 'parsegen', source = 'parsegen.cpp')
def parsegen_emitter(target,source,env):
env.Depends(target,parsegen_tool)
return (target,source)
if platform == 'posix':
os.system('rm cfgparse.c version.o')
print 'cfgparse.c and version.o removed'
psrbld = Builder(action ='./parsegen -D__UNIXSDL__ $TARGET $SOURCE',
emitter = parsegen_emitter,
suffix = '.c', src_suffix = '.psr')
env['BUILDERS']['PARSEGEN'] = psrbld
env.PARSEGEN('cfgparse.c', 'cfgparse.psr')
objfix_tool = env.Program(target= 'objfix.exe', source= 'objfix.c')
def objfix_emitter(target,source,env):
env.Depends(target,objfix_tool)
return (target,source)
objbld = Builder(action = 'objfix $TARGET',
emitter = objfix_emitter,
suffix = '.obj', src_suffix = '.obj')
env['BUILDERS']['OBJFIX'] = objbld
chipssrc = Split('''
chips/c4emu.c
chips/dsp1emu.c
chips/dsp1proc.asm
chips/dsp2proc.asm
chips/dsp4emu.c
chips/dsp4proc.asm
chips/fxemu2.asm
chips/fxemu2b.asm
chips/fxemu2c.asm
chips/fxtable.asm
chips/sa1proc.asm
chips/sa1regs.asm
chips/sdd1emu.c
chips/seta10.c
chips/sfxproc.asm
chips/st10proc.asm
''')
#ztcp is no longer used
netsrc = Split('''
net/ztcp.c
''')
cpusrc = Split('''
cpu/dma.asm
cpu/dsp.asm
cpu/dspproc.asm
cpu/execute.asm
cpu/executec.c
cpu/irq.asm
cpu/memory.asm
cpu/memtable.c
cpu/spc700.asm
cpu/stable.asm
cpu/table.asm
cpu/tableb.asm
cpu/tablec.asm
''')
dossrc = Split('''
dos/debug.asm
dos/joy.asm
dos/vesa2.asm
''')
effectssrc = Split('''
effects/burn.c
effects/water.c
effects/smoke.c
''')
guisrc = Split('''
gui/gui.asm
gui/guifuncs.c
gui/menu.asm
''')
videosrc = Split('''
video/makev16b.asm
video/makev16t.asm
video/makevid.asm
video/mode716.asm
video/mode716b.asm
video/mode716d.asm
video/mode716e.asm
video/mode716t.asm
video/mode7.asm
video/mode7ext.asm
video/mv16tms.asm
video/newg162.asm
video/newgfx16.asm
video/newgfx2.asm
video/newgfx.asm
video/m716text.asm
video/2xsaiw.asm
video/procvid.asm
video/procvidc.c
video/sw_draw.asm
video/hq2x16.asm
video/hq2x32.asm
video/hq3x16.asm
video/hq3x32.asm
video/hq4x16.asm
video/hq4x32.asm
''')
zipsrc = Split('''
zip/unzip.c
zip/zpng.c
''')
jmasrc = Split('''
jma/7zlzma.cpp
jma/crc32.cpp
jma/iiostrm.cpp
jma/inbyte.cpp
jma/zsnesjma.cpp
jma/jma.cpp
jma/lzma.cpp
jma/lzmadec.cpp
jma/winout.cpp
''')
basesrc = Split('''
cfgparse.c
cfgload.c
endmem.asm
init.asm
initc.c
uic.c
patch.c
ui.asm
vcache.asm
version.c
zmovie.c
zstate.c
zloader.c
''')
linuxsrc = Split('''
linux/copyvwin.asm
linux/sdlintrf.asm
linux/sdllink.c
linux/sw_draw.c
linux/zfilew.c
''')
winsrc = Split('''
win/copyvwin.asm
win/winintrf.asm
win/winlink.cpp
win/zfilew.c
win/zipxw.c
''')
platform = env['PLATFORM']
# Setup environment for nasm
env.Replace (AS = 'nasm')
env.Replace (ASFLAGS = '-f elf ')
#sdl_config = Builder (action = 'sdl-config --include')
# Run config tests.
conf = Configure (env)
# Must have SDL to compile
if not conf.CheckLib ('SDL', 'SDL_Init'):
print 'SDL not found! Please install SDL and try again.'
Exit (1)
if not conf.CheckLib ('png'):
print 'libpng not found! Please install libpng and try again.'
Exit (1)
if not conf.CheckLib ('z'):
print 'zlib not found! Please install zlib and try again.'
Exit (1)
# Check for nasm's existence
if not conf.TryCompile ('db __NASM_VER__', '.asm'):
print 'NASM not found! Please install NASM and try again.'
Exit (1)
env = conf.Finish ()
# Perform any platform-specific initialization
if platform == 'posix':
src = chipssrc + cpusrc + dossrc + effectssrc + guisrc + videosrc + zipsrc + jmasrc + linuxsrc + basesrc
env.Append (CCFLAGS = '-D__UNIXSDL__')
env.Append (ASFLAGS = '-DELF -D__UNIXSDL__')
env.Append (CCFLAGS = '-I.')
env.Append (CCFLAGS = '-I/usr/include/SDL')
#Build ZSNES
env.Program('zsnes',src)
if platform == 'win32':
if env['CC'] == 'cl':
def freeMSVCHack(env, vclibs):
# SCons automatically finds full versions of msvc via the registry, so
# if it can't find 'cl', it may be because we're trying to use the
# free version
def isMicrosoftSDKDir(dir):
return os.path.exists(dir+os.sep+'Include'+os.sep+'Windows.h') and os.path.exists(dir+os.sep+'Lib'+os.sep+'WinMM.lib')
def findMicrosoftSDK():
import SCons.Platform.win32
import SCons.Util
import re
if not SCons.Util.can_read_reg:
return None
HLM = SCons.Util.HKEY_LOCAL_MACHINE
K = r'Software\Microsoft\.NETFramework\AssemblyFolders\PSDK Assemblies'
try:
k = SCons.Util.RegOpenKeyEx(HLM, K)
p = SCons.Util.RegQueryValueEx(k,'')[0]
# this should have \include at the end, so chop that off
p = re.sub(r'(?i)\\+Include\\*$','',p)
if isMicrosoftSDKDir(p): return p
except SCons.Util.RegError:
pass
K = r'SOFTWARE\Microsoft\MicrosoftSDK\InstalledSDKs'
try:
k = SCons.Util.RegOpenKeyEx(HLM, K)
i=0
while 1:
p = SCons.Util.RegEnumKey(k,i)
i+=1
subk = SCons.Util.RegOpenKeyEx(k, p)
try:
p = SCons.Util.RegQueryValueEx(subk,'Install Dir')[0]
# trim trailing backslashes
p = re.sub(r'\\*$','',p)
if isMicrosoftSDKDir(p): return p
except SCons.Util.RegError:
pass
except SCons.Util.RegError:
pass
return None
# End of local defs. Actual freeMSVCHack begins here
if not env['MSVS'].get('VCINSTALLDIR'):
if os.environ.get('VCToolkitInstallDir'):
vcdir=os.environ['VCToolkitInstallDir']
env.PrependENVPath('INCLUDE', vcdir+os.sep+'Include')
env.PrependENVPath('LIB', vcdir+os.sep+'Lib')
env.PrependENVPath('PATH', vcdir+os.sep+'Bin')
env['MSVS']['VERSION'] = '7.1'
env['MSVS']['VERSIONS'] = ['7.1']
if not env['MSVS'].get('PLATFORMSDKDIR'):
sdkdir = findMicrosoftSDK()
if sdkdir:
env.PrependENVPath('INCLUDE', sdkdir+os.sep+'Include')
env.PrependENVPath('LIB', sdkdir+os.sep+'Lib')
env.PrependENVPath('PATH', sdkdir+os.sep+'Bin')
env['MSVS']['PLATFORMSDKDIR']=sdkdir
# FREE MSVC7 only allows
# /ML(libc) /MT(libcmt) or /MLd(libcd)
# Full IDE versions also have
# /MD(msvcrtd) /MTd(libcmtd) and /MDd(msvcrtd)
# So if you want to debug with the freever, the only option is
# the single-threaded lib, /MLd
vclibs['Debug']='/MLd'
vclibs['Release']='/MT'
# MSVC SETUP
# MDd is for multithreaded debug dll CRT (msvcrtd)
# MD is for multithreaded dll CRT (msvcrt)
# These are just my preferences
vclibs = {'Debug':'/MDd','Release':'/MD'}
freeMSVCHack(env, vclibs)
env.Append(CCFLAGS=[vclibs[variant]])
if debug:
env.Append(CCFLAGS=Split('/Zi /Fd${TARGET}.pdb'))
env.Append(LINKFLAGS = ['/DEBUG'])
# env.Clean('.', '${TARGET}.pdb')
# Need to clean .pdbs somehow! The above line doesn't work!
else:
env.Append(CCFLAGS=Split('/Og /Ot /Ob1 /Op /G6'))
env.Append(CCFLAGS=Split('/EHsc /J /W3 /Gd'))
env.Append(CPPDEFINES=Split('WIN32 _WINDOWS'))
src = chipssrc + cpusrc + dossrc + effectssrc + guisrc + videosrc + zipsrc + jmasrc + winsrc
env.Append (CCFLAGS = '-D__WIN32__')
env.Append (ASFLAGS = '-f win32')
#Build ZSNESW
env.Program('zsnesw.exe',src)
else:
if debug:
env.Append (CCFLAGS = '-g -D__WIN32__')
env.Append (CCFLAGS = '-D__WIN32__')
env.Append (ASFLAGS = '-f win32 -O0')
else:
env.Append (CCFLAGS = '-D__WIN32__')
env.Append (CCFLAGS = '-f win32')
#Build ZSNESW
env.Program('zsnesw.exe',src)

314
zsnes/src/acinclude.m4 Normal file
View File

@@ -0,0 +1,314 @@
#Copyright (C) 1997-2007 ZSNES Team ( theoddone33, grinvader, Nach )
#
#http://www.zsnes.com
#http://sourceforge.net/projects/zsnes
#https://zsnes.bountysource.com
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#version 2 as published by the Free Software Foundation.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
dnl -- Begin zlib autoconf macro
dnl When copying, include from Begin to End zlib autoconf macro, including
dnl those tags, so others can easily copy it too. (Maybe someday this will
dnl become zlib.m4?)
dnl
dnl AM_PATH_ZLIB([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl Tests for zlib, outputs ZLIB_VERSION, ZLIB_LIBS, and ZLIB_CFLAGS
AC_DEFUN([AM_PATH_ZLIB],
[dnl
dnl
dnl
AC_ARG_WITH(zlib-prefix,
[ --with-zlib-prefix=PFX Prefix where zlib is installed (optional)],
zlib_prefix="$withval",
zlib_prefix="")
min_zlib_version=ifelse([$1],,1.1.0,$1)
AC_MSG_CHECKING(for zlib - version >= $min_zlib_version)
tempLIBS="$LIBS"
tempCFLAGS="$CFLAGS"
if test x$zlib_prefix != x ; then
ZLIB_LIBS="-L$zlib_prefix"
ZLIB_CFLAGS="-I$zlib_prefix"
fi
ZLIB_LIBS="$ZLIB_LIBS -lz"
LIBS="$LIBS $ZLIB_LIBS"
CFLAGS="$CFLAGS $ZLIB_CFLAGS"
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <zlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* my_strdup (char *str)
{
char *new_str;
if (str)
{
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
strcpy (new_str, str);
}
else new_str = NULL;
return new_str;
}
int main (int argc, char *argv[])
{
int major, minor, micro, zlib_major_version, zlib_minor_version, zlib_micro_version;
char *zlibver, *tmp_version;
zlibver = ZLIB_VERSION;
FILE *fp = fopen("conf.zlibtest", "a");
if ( fp ) {
fprintf(fp, "%s", zlibver);
fclose(fp);
}
/* HP/UX 9 (%@#!) writes to sscanf strings */
tmp_version = my_strdup("$min_zlib_version");
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
printf("%s, bad version string for\n\tmin_zlib_version... ", "$min_zlib_version");
exit(1);
}
if (sscanf(zlibver, "%d.%d.%d", &zlib_major_version, &zlib_minor_version, &zlib_micro_version) != 3) {
printf("%s, bad version string given\n", zlibver);
puts("\tby zlib, sometimes due to very old zlibs that didnt correctly");
printf("\tdefine their version. Please upgrade if you are running an\n\told zlib... ");
exit(1);
}
if ((zlib_major_version > major) ||
((zlib_major_version == major) && (zlib_minor_version > minor)) ||
((zlib_major_version == major) && (zlib_minor_version == minor) && (zlib_micro_version >= micro)))
{
return 0;
}
else
{
return 1;
}
}
]])],
with_zlib=yes,
with_zlib=no,
[AC_MSG_RESULT(cross-compiling)
with_zlib=""
AC_MSG_WARN(Assuming zlib is available)])
if test x$with_zlib != x; then
AC_MSG_RESULT($with_zlib)
fi
if test x$with_zlib = xyes; then
ZLIB_VERSION=$(<conf.zlibtest)
ifelse([$2], , :, [$2])
else
ZLIB_CFLAGS=""
ZLIB_LIBS=""
ZLIB_VERSION=""
ifelse([$3], , :, [$3])
fi
LIBS="$tempLIBS"
CFLAGS="$tempCFLAGS"
rm conf.zlibtest
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_VERSION)
AC_SUBST(ZLIB_LIBS)
])
dnl -- End zlib autoconf macro
dnl ----
dnl -- Begin libpng autoconf macro
dnl When copying, include from Begin to End libpng autoconf macro, including
dnl those tags, so others can easily copy it too. (Maybe someday this will
dnl become libpng.m4?)
dnl
dnl AM_PATH_LIBPNG([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl Tests for libpng, outputs LIBPNG_VERSION, LIBPNG_LIBS, and LIBPNG_CFLAGS
AC_DEFUN([AM_PATH_LIBPNG],
[dnl
dnl
dnl
dnl Comment out this section, and the other labled parts to disable the user
dnl having a choice about being able to disable libpng or not. Recommended
dnl you use AC_MSG_ERROR(LIBPNG >= 1.0.0 is required) for the
dnl ACTION-IF-NOT-FOUND if you plan on disabling user choice.
dnl <--- disable for no user choice part #1
AC_ARG_ENABLE(libpng,
[ --disable-libpng Build without libpng support ],
,
enable_libpng=yes)
dnl --->
AC_ARG_WITH(libpng-prefix,
[ --with-libpng-prefix=PFX Prefix where libpng is installed (optional)],
libpng_prefix="$withval",
libpng_prefix="")
min_libpng_version=ifelse([$1], ,1.2.0,$1)
tempLIBS="$LIBS"
tempCFLAGS="$CFLAGS"
if test x$libpng_prefix != x ; then
LIBPNG_LIBS="-L$libpng_prefix"
LIBPNG_CFLAGS="-I$libpng_prefix"
fi
LIBPNG_LIBS="$LIBPNG_LIBS -lpng -lm"
LIBS="$LIBS $LIBPNG_LIBS"
CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
AC_MSG_CHECKING(for libpng - version >= $min_libpng_version)
dnl <--- disable for no user choice part #2
if test x$enable_libpng != xno; then
dnl --->
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* my_strdup (char *str)
{
char *new_str;
if (str)
{
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
strcpy (new_str, str);
}
else new_str = NULL;
return new_str;
}
int main (int argc, char *argv[])
{
int major, minor, micro, libpng_major_version, libpng_minor_version, libpng_micro_version;
char *libpngver, *tmp_version;
libpngver = PNG_LIBPNG_VER_STRING;
FILE *fp = fopen("conf.libpngtest", "a");
if ( fp ) {
fprintf(fp, "%s", libpngver);
fclose(fp);
}
/* HP/UX 9 (%@#!) writes to sscanf strings */
tmp_version = my_strdup("$min_libpng_version");
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
printf("%s, bad version string for\n\tmin_libpng_version... ", "$min_libpng_version");
exit(1);
}
if (sscanf(libpngver, "%d.%d.%d", &libpng_major_version, &libpng_minor_version, &libpng_micro_version) != 3) {
printf("%s, bad version string given\n", libpngver);
puts("\tby libpng, sometimes due to very old libpngs that didnt correctly");
printf("\tdefine their version. Please upgrade if you are running an\n\told libpng... ");
exit(1);
}
if ((libpng_major_version > major) ||
((libpng_major_version == major) && (libpng_minor_version > minor)) ||
((libpng_major_version == major) && (libpng_minor_version == minor) && (libpng_micro_version >= micro)))
{
return 0;
}
else
{
return 1;
}
}
]])],
with_libpng=yes,
with_libpng=no,
[AC_MSG_RESULT(cross-compiling)
with_libpng=""
AC_MSG_WARN(Assuming libpng is available)])
if test x$with_libpng != x; then
AC_MSG_RESULT($with_libpng)
fi
if test x$with_libpng = xyes; then
LIBPNG_VERSION=$(<conf.libpngtest)
ifelse([$2], , :, [$2])
else
LIBPNG_CFLAGS=""
LIBPNG_LIBS=""
LIBPNG_VERSION=""
ifelse([$3], , :, [$3])
fi
LIBS="$tempLIBS"
CFLAGS="$tempCFLAGS"
rm conf.libpngtest
AC_SUBST(LIBPNG_CFLAGS)
AC_SUBST(LIBPNG_VERSION)
AC_SUBST(LIBPNG_LIBS)
dnl <--- disable for no user choice part #3
else
AC_MSG_RESULT(disabled by user)
fi
dnl --->
])
dnl -- End libpng autoconf macro
dnl ----
dnl -- Begin custom tools use
dnl
AC_DEFUN([AM_ARCH_DETECT],
[
AC_MSG_CHECKING(for cpu info)
AC_ARG_ENABLE(cpucheck,
[ --disable-cpucheck Do not try to autodetect cpu architecture ],
,
enable_cpucheck=yes)
if test x$enable_cpucheck != xno; then
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdlib.h>
int main()
{
int check;
system("$CC -O3 -o tools/archopt tools/archopt.c");
check = system("tools/archopt > conf.archchk");
return((check) ? 1:0);
}
]])],
cpu_test=found,
cpu_test=failed,
[AC_MSG_RESULT(cross-compiling)
cpu_test=""
AC_MSG_WARN(You should use --target)])
if test x$cpu_test != x; then
AC_MSG_RESULT($cpu_test)
fi
if test x$cpu_test = xfound; then
ARCH_INFO=$(<conf.archchk)
fi
rm -f conf.archchk tools/archopt
AC_SUBST(ARCH_INFO)
else
AC_MSG_RESULT(disabled by user)
fi
])
dnl -- End custom tools use

154
zsnes/src/argv.h Normal file
View File

@@ -0,0 +1,154 @@
#ifndef ARGV_H
#define ARGV_H
static char *decode_string(char *str)
{
size_t str_len = strlen(str), i = 0;
char *dest = str;
if ((str_len > 1) && ((*str == '\"') || (*str == '\'')) && (str[str_len-1] == *str))
{
memmove(str, str+1, str_len-2);
str[str_len-2] = 0;
}
while (*str)
{
if (*str == '\\')
{
str++;
}
dest[i++] = *str++;
}
dest[i] = 0;
return(dest);
}
static char *find_next_match(char *str, char match_char)
{
char *pos = 0;
while (*str)
{
if (*str == match_char)
{
pos = str;
break;
}
if (*str == '\\')
{
if (str[1])
{
str++;
}
else
{
break;
}
}
str++;
}
return(pos);
}
static char *get_param(char *str)
{
static char *pos = 0;
char *token = 0;
if (str) //Start a new string?
{
pos = str;
}
if (pos)
{
//Skip delimiters
while (*pos == ' ') { pos++; }
if (*pos)
{
token = pos;
//Skip non-delimiters
while (*pos && (*pos != ' '))
{
//Skip quoted characters
if ((*pos == '\"') || (*pos == '\''))
{
char *match_pos = 0;
if ((match_pos = find_next_match(pos+1, *pos)))
{
pos = match_pos;
}
}
//Skip escaped spaces
if (*pos == '\\') { pos++; }
pos++;
}
if (*pos) { *pos++ = '\0'; }
}
}
return(token);
}
static size_t count_param(char *str)
{
size_t i = 0;
while (*str)
{
//Skip delimiters
while (*str == ' ') { str++; }
//Skip non-delimiters
while (*str && (*str != ' '))
{
//Skip quoted characters
if ((*str == '\"') || (*str == '\''))
{
char *match_str = 0;
if ((match_str = find_next_match(str+1, *str)))
{
str = match_str;
}
}
//Skip escaped spaces
if (*str == '\\') { str++; }
str++;
}
i++;
}
return(i);
}
static char **build_argv(char *str)
{
size_t argc = count_param(str);
char **argv = (char **)malloc(sizeof(char *)*(argc+1));
if (argv)
{
char *p, **argp = argv;
for (p = get_param(str); p; p = get_param(0), argp++)
{
*argp = decode_string(p);
}
*argp = 0;
return(argv);
}
return(0);
}
/*
static void argv_print(char **argv)
{
char **argp = argv;
while (*argp)
{
printf("argv[%u]: %s\n", argp-argv, *argp);
argp++;
}
printf("argv[%u]: NULL\n", argp-argv);
}
*/
#endif

95
zsnes/src/asm_call.h Normal file
View File

@@ -0,0 +1,95 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
Introducing 'the "DJGPP/MinGW/MSVC/GCC on *nix compatible" call asm function
safely from C/C++' macro function!
Usage:
asm_call( func_name );
That's all there is to it!!!
Note: Make sure this is used on a line by itself if the file will ever be
compiled with MSVC, since it's preproccessor won't parse the inline
assembly correctly if other stuff are on the line
Note: This will not work with GCC when using the parameter -MASM=intel
I'd fix that if anyone knows if that parameter defines something I can check
-Nach
*/
#ifndef ASM_CALL_H
#define ASM_CALL_H
////////////////////////////////////////////////////////
#ifdef __GNUC__
#define ASM_COMMAND(line) #line"\n\t"
#ifdef __x86_64__
#define PUSHAD ASM_COMMAND(pushq %rax) \
ASM_COMMAND(pushq %rcx) \
ASM_COMMAND(pushq %rdx) \
ASM_COMMAND(pushq %rbx) \
ASM_COMMAND(pushq %rsp) \
ASM_COMMAND(pushq %rbp) \
ASM_COMMAND(pushq %rsi) \
ASM_COMMAND(pushq %rdi)
#define POPAD ASM_COMMAND(popq %rdi) \
ASM_COMMAND(popq %rsi) \
ASM_COMMAND(popq %rbp) \
ASM_COMMAND(popq %rsp) \
ASM_COMMAND(popq %rbx) \
ASM_COMMAND(popq %rdx) \
ASM_COMMAND(popq %rcx) \
ASM_COMMAND(popq %rax)
#else
#define PUSHAD ASM_COMMAND(pushal)
#define POPAD ASM_COMMAND(popal)
#endif
#ifdef __ELF__
#define ASM_CALL(func) ASM_COMMAND(call func)
#else
#define ASM_CALL(func) ASM_COMMAND(call _ ## func)
#endif
#define asm_call(func) __asm__ __volatile__ ( \
PUSHAD \
ASM_CALL(func) \
POPAD \
);
#else //MSVC
#define asm_call(func) { _asm pushad \
_asm call func \
_asm popad };
#endif
////////////////////////////////////////////////////////
#endif

17
zsnes/src/autogen.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
echo "Generating build information using aclocal and autoconf..."
# Regenerate configuration files
aclocal --acdir=`sdl-config --prefix`/share/aclocal # thanks asfand
autoconf
# Run configure for this platform, or simply update Makefile
case $1 in
--noconf )
break ;;
--recheck )
./config.status --recheck; break ;;
* )
./configure $*; break ;;
esac

1011
zsnes/src/cfg.psr Normal file

File diff suppressed because it is too large Load Diff

1375
zsnes/src/chips/7110proc.asm Normal file

File diff suppressed because it is too large Load Diff

345
zsnes/src/chips/c4emu.c Normal file
View File

@@ -0,0 +1,345 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef __UNIXSDL__
#include "../gblhdr.h"
#else
#include <math.h>
#include <stdlib.h>
#endif
#ifdef PI
#undef PI
#endif
#define PI 3.1415926535897932384626433832795
#define Cos(a) ((double) CosTable[a])
#define Sin(a) ((double) SinTable[a])
#define Tan(a) (CosTable[a]?((((int)SinTable[a])<<16)/CosTable[a]):(int)0x80000000)
short SinTable[512] = {
0, 402, 804, 1206, 1607, 2009, 2410, 2811,
3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997,
6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126,
9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167,
12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090,
15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869,
18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475,
20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884,
23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073,
25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020,
27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707,
28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117,
30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237,
31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057,
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765,
32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647,
32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214,
32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471,
31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425,
30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086,
28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466,
27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583,
25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453,
23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097,
20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537,
18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800,
15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910,
12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896,
9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786,
6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611,
3211, 2811, 2410, 2009, 1607, 1206, 804, 402,
0, -402, -804, -1206, -1607, -2009, -2410, -2811,
-3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997,
-6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126,
-9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167,
-12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090,
-15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869,
-18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475,
-20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884,
-23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073,
-25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020,
-27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707,
-28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117,
-30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237,
-31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057,
-32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568,
-32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765,
-32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647,
-32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214,
-32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471,
-31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425,
-30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086,
-28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466,
-27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583,
-25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453,
-23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097,
-20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537,
-18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800,
-15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910,
-12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896,
-9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786,
-6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611,
-3211, -2811, -2410, -2009, -1607, -1206, -804, -402
};
short CosTable[512] = {
32767, 32765, 32758, 32745, 32728, 32706, 32679, 32647,
32610, 32568, 32521, 32469, 32413, 32351, 32285, 32214,
32138, 32057, 31971, 31881, 31785, 31685, 31581, 31471,
31357, 31237, 31114, 30985, 30852, 30714, 30572, 30425,
30273, 30117, 29956, 29791, 29621, 29447, 29269, 29086,
28898, 28707, 28511, 28310, 28106, 27897, 27684, 27466,
27245, 27020, 26790, 26557, 26319, 26077, 25832, 25583,
25330, 25073, 24812, 24547, 24279, 24007, 23732, 23453,
23170, 22884, 22594, 22301, 22005, 21706, 21403, 21097,
20787, 20475, 20159, 19841, 19519, 19195, 18868, 18537,
18204, 17869, 17530, 17189, 16846, 16499, 16151, 15800,
15446, 15090, 14732, 14372, 14010, 13645, 13278, 12910,
12539, 12167, 11793, 11416, 11039, 10659, 10278, 9896,
9512, 9126, 8739, 8351, 7961, 7571, 7179, 6786,
6392, 5997, 5602, 5205, 4808, 4409, 4011, 3611,
3211, 2811, 2410, 2009, 1607, 1206, 804, 402,
0, -402, -804, -1206, -1607, -2009, -2410, -2811,
-3211, -3611, -4011, -4409, -4808, -5205, -5602, -5997,
-6392, -6786, -7179, -7571, -7961, -8351, -8739, -9126,
-9512, -9896, -10278, -10659, -11039, -11416, -11793, -12167,
-12539, -12910, -13278, -13645, -14010, -14372, -14732, -15090,
-15446, -15800, -16151, -16499, -16846, -17189, -17530, -17869,
-18204, -18537, -18868, -19195, -19519, -19841, -20159, -20475,
-20787, -21097, -21403, -21706, -22005, -22301, -22594, -22884,
-23170, -23453, -23732, -24007, -24279, -24547, -24812, -25073,
-25330, -25583, -25832, -26077, -26319, -26557, -26790, -27020,
-27245, -27466, -27684, -27897, -28106, -28310, -28511, -28707,
-28898, -29086, -29269, -29447, -29621, -29791, -29956, -30117,
-30273, -30425, -30572, -30714, -30852, -30985, -31114, -31237,
-31357, -31471, -31581, -31685, -31785, -31881, -31971, -32057,
-32138, -32214, -32285, -32351, -32413, -32469, -32521, -32568,
-32610, -32647, -32679, -32706, -32728, -32745, -32758, -32765,
-32767, -32765, -32758, -32745, -32728, -32706, -32679, -32647,
-32610, -32568, -32521, -32469, -32413, -32351, -32285, -32214,
-32138, -32057, -31971, -31881, -31785, -31685, -31581, -31471,
-31357, -31237, -31114, -30985, -30852, -30714, -30572, -30425,
-30273, -30117, -29956, -29791, -29621, -29447, -29269, -29086,
-28898, -28707, -28511, -28310, -28106, -27897, -27684, -27466,
-27245, -27020, -26790, -26557, -26319, -26077, -25832, -25583,
-25330, -25073, -24812, -24547, -24279, -24007, -23732, -23453,
-23170, -22884, -22594, -22301, -22005, -21706, -21403, -21097,
-20787, -20475, -20159, -19841, -19519, -19195, -18868, -18537,
-18204, -17869, -17530, -17189, -16846, -16499, -16151, -15800,
-15446, -15090, -14732, -14372, -14010, -13645, -13278, -12910,
-12539, -12167, -11793, -11416, -11039, -10659, -10278, -9896,
-9512, -9126, -8739, -8351, -7961, -7571, -7179, -6786,
-6392, -5997, -5602, -5205, -4808, -4409, -4011, -3611,
-3211, -2811, -2410, -2009, -1607, -1206, -804, -402,
0, 402, 804, 1206, 1607, 2009, 2410, 2811,
3211, 3611, 4011, 4409, 4808, 5205, 5602, 5997,
6392, 6786, 7179, 7571, 7961, 8351, 8739, 9126,
9512, 9896, 10278, 10659, 11039, 11416, 11793, 12167,
12539, 12910, 13278, 13645, 14010, 14372, 14732, 15090,
15446, 15800, 16151, 16499, 16846, 17189, 17530, 17869,
18204, 18537, 18868, 19195, 19519, 19841, 20159, 20475,
20787, 21097, 21403, 21706, 22005, 22301, 22594, 22884,
23170, 23453, 23732, 24007, 24279, 24547, 24812, 25073,
25330, 25583, 25832, 26077, 26319, 26557, 26790, 27020,
27245, 27466, 27684, 27897, 28106, 28310, 28511, 28707,
28898, 29086, 29269, 29447, 29621, 29791, 29956, 30117,
30273, 30425, 30572, 30714, 30852, 30985, 31114, 31237,
31357, 31471, 31581, 31685, 31785, 31881, 31971, 32057,
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765
};
short C4WFXVal;
short C4WFYVal;
short C4WFZVal;
short C4WFX2Val;
short C4WFY2Val;
short C4WFDist;
short C4WFScale;
double tanval;
double c4x,c4y,c4z;
double c4x2,c4y2,c4z2;
void C4TransfWireFrame()
{
c4x=(double)C4WFXVal;
c4y=(double)C4WFYVal;
c4z=(double)C4WFZVal-0x95;
// Rotate X
tanval=-(double)C4WFX2Val*PI*2/128;
c4y2=c4y*cos(tanval)-c4z*sin(tanval);
c4z2=c4y*sin(tanval)+c4z*cos(tanval);
// Rotate Y
tanval=-(double)C4WFY2Val*PI*2/128;
c4x2=c4x*cos(tanval)+c4z2*sin(tanval);
c4z=c4x*-sin(tanval)+c4z2*cos(tanval);
// Rotate Z
tanval=-(double)C4WFDist*PI*2/128;
c4x=c4x2*cos(tanval)-c4y2*sin(tanval);
c4y=c4x2*sin(tanval)+c4y2*cos(tanval);
// Scale
C4WFXVal=(short)(c4x*C4WFScale/(0x90*(c4z+0x95))*0x95);
C4WFYVal=(short)(c4y*C4WFScale/(0x90*(c4z+0x95))*0x95);
}
void C4TransfWireFrame2()
{
c4x=(double)C4WFXVal;
c4y=(double)C4WFYVal;
c4z=(double)C4WFZVal;
// Rotate X
tanval=-(double)C4WFX2Val*PI*2/128;
c4y2=c4y*cos(tanval)-c4z*sin(tanval);
c4z2=c4y*sin(tanval)+c4z*cos(tanval);
// Rotate Y
tanval=-(double)C4WFY2Val*PI*2/128;
c4x2=c4x*cos(tanval)+c4z2*sin(tanval);
c4z=c4x*-sin(tanval)+c4z2*cos(tanval);
// Rotate Z
tanval=-(double)C4WFDist*PI*2/128;
c4x=c4x2*cos(tanval)-c4y2*sin(tanval);
c4y=c4x2*sin(tanval)+c4y2*cos(tanval);
// Scale
C4WFXVal=(short)(c4x*C4WFScale/0x100);
C4WFYVal=(short)(c4y*C4WFScale/0x100);
}
void C4CalcWireFrame()
{
C4WFXVal=C4WFX2Val-C4WFXVal;
C4WFYVal=C4WFY2Val-C4WFYVal;
if (abs(C4WFXVal)>abs(C4WFYVal)){
C4WFDist=abs(C4WFXVal)+1;
C4WFYVal=(short)((256*(long)C4WFYVal)/abs(C4WFXVal));
if (C4WFXVal<0) C4WFXVal=-256;
else C4WFXVal=256;
}
else
if (C4WFYVal!=0) {
C4WFDist=abs(C4WFYVal)+1;
C4WFXVal=(short)((256*(long)C4WFXVal)/abs(C4WFYVal));
if (C4WFYVal<0) C4WFYVal=-256;
else C4WFYVal=256;
}
else C4WFDist=0;
}
short C41FXVal;
short C41FYVal;
short C41FAngleRes;
short C41FDist;
short C41FDistVal;
void C4Op1F()
{
if (C41FXVal == 0) {
if (C41FYVal>0) C41FAngleRes=0x80;
else C41FAngleRes=0x180;
}
else {
tanval = ((double)C41FYVal)/((double)C41FXVal);
C41FAngleRes=(short)(atan(tanval)/(PI*2)*512);
C41FAngleRes=C41FAngleRes;
if (C41FXVal<0) C41FAngleRes+=0x100;
C41FAngleRes&=0x1FF;
}
}
void C4Op15()
{
tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)*
((double)C41FXVal));
C41FDist=(short)tanval;
}
void C4Op0D()
{
tanval=sqrt(((double)C41FYVal)*((double)C41FYVal)+((double)C41FXVal)*
((double)C41FXVal));
tanval=(double)C41FDistVal/tanval;
C41FYVal=(short)(((double)C41FYVal*tanval)*0.99);
C41FXVal=(short)(((double)C41FXVal*tanval)*0.98);
}
#define READ_WORD(s) (*(unsigned short *) (s))
void C4Op22()
{
extern unsigned char *C4Ram;
short angle1 = READ_WORD(C4Ram+0x1f8c) & 0x1ff;
short angle2 = READ_WORD(C4Ram+0x1f8f) & 0x1ff;
int tan1 = Tan(angle1);
int tan2 = Tan(angle2);
short y = READ_WORD(C4Ram+0x1f83) - READ_WORD(C4Ram+0x1f89);
short left, right;
int j;
for (j = 0; j < 225; j++, y++)
{
if (y >= 0)
{
left = (((int)tan1*y) >> 16) - READ_WORD(C4Ram+0x1f80) + READ_WORD(C4Ram+0x1f86);
right = (((int)tan2*y) >> 16) - READ_WORD(C4Ram+0x1f80) + READ_WORD(C4Ram+0x1f86) + READ_WORD(C4Ram+0x1f93);
if(left<0 && right<0)
{
left = 1;
right = 0;
}
else if (left < 0)
{
left = 0;
}
else if (right < 0)
{
right = 0;
}
if (left > 255 && right > 255)
{
left = 255;
right = 254;
}
else if (left > 255)
{
left = 255;
}
else if (right > 255)
{
right = 255;
}
}
else
{
left = 1;
right = 0;
}
C4Ram[j+0x800] = (unsigned char)left;
C4Ram[j+0x900] = (unsigned char)right;
}
}

2205
zsnes/src/chips/c4proc.asm Normal file

File diff suppressed because it is too large Load Diff

1216
zsnes/src/chips/dsp1emu.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,879 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM regaccessbankr8,regaccessbankr16,regaccessbankw8,regaccessbankw16
EXTSYM DSPOp0A,Op0AA,Op0AB,Op0AC,Op0AD,Op0AVS,DSPOp10,DSPOp00,Op00Multiplicand
EXTSYM Op00Multiplier,Op00Result,DSPOp0F,Op0FPass
EXTSYM DSPOp04,Op04Angle,Op04Cos,Op04Radius,Op04Sin
EXTSYM DSPOp28,Op28R,Op28X,Op28Y,Op28Z
EXTSYM DSPOp0C,Op0CA,Op0CX1,Op0CX2,Op0CY1,Op0CY2
EXTSYM DSPOp02,Op02AAS,Op02AZS,Op02CX,Op02CY,Op02FX,Op02FY
EXTSYM Op02FZ,Op02LES,Op02LFE,Op02VOF,Op02VVA
EXTSYM DSPOp06,Op06X,Op06Y,Op06Z,Op06H,Op06V,Op06M
EXTSYM DSPOp0E,Op0EH,Op0EV,Op0EX,Op0EY
EXTSYM Op01m,Op01Zr,Op01Xr,Op01Yr,DSPOp01
EXTSYM Op11m,Op11Zr,Op11Xr,Op11Yr,DSPOp11
EXTSYM Op21m,Op21Zr,Op21Xr,Op21Yr,DSPOp21
EXTSYM Op0DX,Op0DY,Op0DZ,Op0DF,Op0DL,Op0DU,DSPOp0D
EXTSYM Op1DX,Op1DY,Op1DZ,Op1DF,Op1DL,Op1DU,DSPOp1D
EXTSYM Op2DX,Op2DY,Op2DZ,Op2DF,Op2DL,Op2DU,DSPOp2D
EXTSYM Op03X,Op03Y,Op03Z,Op03F,Op03L,Op03U,DSPOp03
EXTSYM Op13X,Op13Y,Op13Z,Op13F,Op13L,Op13U,DSPOp13
EXTSYM Op23X,Op23Y,Op23Z,Op23F,Op23L,Op23U,DSPOp23
EXTSYM Op14Zr,Op14Xr,Op14Yr,Op14U,Op14F,Op14L
EXTSYM Op14Zrr,Op14Xrr,Op14Yrr,DSPOp14
EXTSYM Op0BX,Op0BY,Op0BZ,Op0BS,DSPOp0B
EXTSYM Op1BX,Op1BY,Op1BZ,Op1BS,DSPOp1B
EXTSYM Op2BX,Op2BY,Op2BZ,Op2BS,DSPOp2B
EXTSYM Op08X,Op08Y,Op08Z,Op08Ll,Op08Lh,DSPOp08
EXTSYM Op18X,Op18Y,Op18Z,Op18R,Op18D,DSPOp18
EXTSYM Op1CX,Op1CY,Op1CZ,Op1CXBR,Op1CYBR,Op1CZBR,Op1CXAR,Op1CYAR,Op1CZAR,DSPOp1C
EXTSYM Op10Exponent,Op10ExponentR,Op10Coefficient,Op10CoefficientR
SECTION .bss
NEWSYM dsp1ptr, resd 1
NEWSYM dsp1array, resb 4096
SECTION .text
;*******************************************************
; DSP1 Read Functions
;*******************************************************
NEWSYM DSP1Read8b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankr8
.dsp1area
mov al,80h
ret
NEWSYM DSP1Read16b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankr16
.dsp1area
or ecx,08000h
cmp ecx,0C000h
jae .doC000
cmp byte[DSP1RLeft],0
jne .movestuff
xor ax,ax
ret
.doC000
mov ax,08000h
cmp byte[DSP1WLeft],0
je .notwleft
mov ax,0C000h
.notwleft
ret
.movestuff
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrR]
mov ax,[DSP1RET+ebx*2]
pop ebx
inc byte[DSP1CPtrR]
dec byte[DSP1RLeft]
jz .nomore
.goback
ret
.nomore
cmp byte[DSP1COp],0Ah
jne .goback
push eax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
mov byte[DSP1CPtrR],0
pop eax
ret
NEWSYM DSP1Read8b
; mov byte[debstop],1
cmp ecx,7000h
jae .do7000
xor al,al
ret
.do7000
mov al,80h
test ecx,1
jz .no1
mov al,80h
.no1
ret
NEWSYM DSP1Read16b
; mov byte[debstop],1
cmp ecx,7000h
jae .do7000
cmp byte[DSP1RLeft],0
jne .movestuff
xor ax,ax
ret
.do7000
mov ax,8000h
cmp byte[DSP1WLeft],0
je .notwleft
mov ax,0C000h
.notwleft
; test ecx,01h
; jz .norev
; mov ax,0080h
;.norev
ret
.movestuff
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrR]
mov ax,[DSP1RET+ebx*2]
pop ebx
inc byte[DSP1CPtrR]
dec byte[DSP1RLeft]
jz .nomore
.goback
ret
.nomore
cmp byte[DSP1COp],0Ah
jne .goback
push eax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
mov byte[DSP1CPtrR],0
pop eax
ret
%macro DSP1WriteInit 2
cmp al,%1
jne %%no
mov byte[DSP1WLeft],%2
%%no
%endmacro
NEWSYM DSP1Write8b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankw8
.dsp1area
call DSP1Write8b
ret
NEWSYM DSP1Write16b3F
test ecx,8000h
jnz .dsp1area
cmp bl,0E0h
je .dsp1area
jmp regaccessbankw16
.dsp1area
call DSP1Write16b
ret
NEWSYM DSP1Write8b
push ebx
xor ebx,ebx
mov bl,al
mov byte[DSPFuncUsed+ebx],1
pop ebx
mov [DSP1COp],al
mov byte[DSP1CPtrW],0
DSP1WriteInit 00h, 2 ; 16-bit multiply
DSP1WriteInit 10h, 2 ; Inverse
DSP1WriteInit 04h, 2 ; Trigonometric
DSP1WriteInit 08h, 3 ; Vector Size
DSP1WriteInit 18h, 4 ; Vector Size Comparison
DSP1WriteInit 28h, 3 ; Vector Absolute Value
DSP1WriteInit 0Ch, 3 ; Coordinate Rotation
DSP1WriteInit 1Ch, 6 ; 3D Coordinate Rotation
DSP1WriteInit 02h, 7 ; Vector Size
DSP1WriteInit 0Ah, 1 ; Raster Data Calculation via DMA
DSP1WriteInit 1Ah, 1 ; Raster Data Calculation w/o DMA
DSP1WriteInit 06h, 3 ; Object Projection Calculation
DSP1WriteInit 0Eh, 2 ; Coordinate Calculation of a point onscreen
DSP1WriteInit 01h, 4 ; Set Attitude Matrix A
DSP1WriteInit 11h, 4 ; Set Attitude Matrix B
DSP1WriteInit 21h, 4 ; Set Attitude Matrix C
DSP1WriteInit 0Dh, 3 ; Convert from global to object coords Matrix A
DSP1WriteInit 1Dh, 3 ; Convert from global to object coords Matrix B
DSP1WriteInit 2Dh, 3 ; Convert from global to object coords Matrix C
DSP1WriteInit 03h, 3 ; Convert from object to global coords Matrix A
DSP1WriteInit 13h, 3 ; Convert from object to global coords Matrix B
DSP1WriteInit 23h, 3 ; Convert from object to global coords Matrix C
DSP1WriteInit 0Bh, 3 ; Calculation of inner product Matrix A
DSP1WriteInit 1Bh, 3 ; Calculation of inner product Matrix B
DSP1WriteInit 2Bh, 3 ; Calculation of inner product Matrix C
DSP1WriteInit 14h, 6 ; 3D angle rotation
DSP1WriteInit 0Fh, 1 ; DSP RAM Check
ret
%macro DSP1WriteProc 2
cmp byte[DSP1COp],%1
jne %%no
pushad
call %2
popad
%%no
%endmacro
NEWSYM DSP1Write16b
; mov byte[debstop],1
cmp byte[DSP1WLeft],0
jne .yesleft
ret
.yesleft
push ebx
xor ebx,ebx
mov bl,[DSP1CPtrW]
mov [DSP1VARS+ebx*2],ax
pop ebx
inc byte[DSP1CPtrW]
dec byte[DSP1WLeft]
jz .ProcessDSP1
ret
.ProcessDSP1
mov byte[DSP1CPtrR],0
mov byte[DSP1RLeft],0
DSP1WriteProc 00h, DSP1_00 ; 16-bit multiply
DSP1WriteProc 10h, DSP1_10 ; Inverse
DSP1WriteProc 04h, DSP1_04 ; Trigonometric
DSP1WriteProc 08h, DSP1_08 ; Vector Size
DSP1WriteProc 18h, DSP1_18 ; Vector Size Comparison
DSP1WriteProc 28h, DSP1_28 ; Vector Absolute Value
DSP1WriteProc 0Ch, DSP1_0C ; Coordinate Rotation
DSP1WriteProc 1Ch, DSP1_1C ; 3D Coordinate Rotation
DSP1WriteProc 02h, DSP1_02 ; Vector Size
DSP1WriteProc 0Ah, DSP1_0A ; Raster Data Calculation via DMA
DSP1WriteProc 1Ah, DSP1_0A ; Raster Data Calculation w/o DMA
DSP1WriteProc 06h, DSP1_06 ; Object Projection Calculation
DSP1WriteProc 0Eh, DSP1_0E ; Coordinate Calculation of a point onscreen
DSP1WriteProc 01h, DSP1_01 ; Set Attitude Matrix A
DSP1WriteProc 11h, DSP1_11 ; Set Attitude Matrix B
DSP1WriteProc 21h, DSP1_21 ; Set Attitude Matrix C
DSP1WriteProc 0Dh, DSP1_0D ; Convert from global to object coords Matrix A
DSP1WriteProc 1Dh, DSP1_1D ; Convert from global to object coords Matrix B
DSP1WriteProc 2Dh, DSP1_2D ; Convert from global to object coords Matrix C
DSP1WriteProc 03h, DSP1_03 ; Convert from object to global coords Matrix A
DSP1WriteProc 13h, DSP1_13 ; Convert from object to global coords Matrix B
DSP1WriteProc 23h, DSP1_23 ; Convert from object to global coords Matrix C
DSP1WriteProc 0Bh, DSP1_0B ; Calculation of inner product Matrix A
DSP1WriteProc 1Bh, DSP1_1B ; Calculation of inner product Matrix B
DSP1WriteProc 2Bh, DSP1_2B ; Calculation of inner product Matrix C
DSP1WriteProc 14h, DSP1_14 ; 3D angle rotation
DSP1WriteProc 0Fh, DSP1_0F ; DSP RAM Check
ret
SECTION .bss
NEWSYM DSP1COp, resb 1
NEWSYM DSP1RLeft, resb 1
NEWSYM DSP1WLeft, resb 1
NEWSYM DSP1CPtrW, resb 1
NEWSYM DSP1CPtrR, resb 1
NEWSYM DSP1VARS, resw 16
NEWSYM DSP1RET, resw 16
NEWSYM DSPDet, resb 1
NEWSYM DSPFuncUsed, resb 256
SECTION .text
;*******************************************************
; DSP1 Conversion Functions
;*******************************************************
DSP1_00: ; 16-bit multiply
or byte[DSPDet],01h
push eax
mov ax,[DSP1VARS]
mov [Op00Multiplicand],ax
mov ax,[DSP1VARS+2]
mov [Op00Multiplier],ax
pushad
call DSPOp00
popad
mov ax,[Op00Result]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_10: ; Inverse
push eax
mov ax,[DSP1VARS]
mov [Op10Coefficient],ax
mov ax,[DSP1VARS+2]
mov [Op10Exponent],ax
pushad
call DSPOp10
popad
mov ax,[Op10CoefficientR]
mov [DSP1RET],ax
mov ax,[Op10ExponentR]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_04: ; Trigonometric
or byte[DSPDet],02h
push eax
mov ax,[DSP1VARS]
mov [Op04Angle],ax
mov ax,[DSP1VARS+2]
mov [Op04Radius],ax
pushad
call DSPOp04
popad
mov ax,[Op04Sin]
mov [DSP1RET],ax
mov ax,[Op04Cos]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_08: ; Vector Size
push eax
mov ax,[DSP1VARS]
mov [Op08X],ax
mov ax,[DSP1VARS+2]
mov [Op08Y],ax
mov ax,[DSP1VARS+4]
mov [Op08Z],ax
pushad
call DSPOp08
popad
mov ax,[Op08Ll]
mov [DSP1RET],ax
mov ax,[Op08Lh]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_18: ; Vector Size Comparison
push eax
mov ax,[DSP1VARS]
mov [Op18X],ax
mov ax,[DSP1VARS+2]
mov [Op18Y],ax
mov ax,[DSP1VARS+4]
mov [Op18Z],ax
mov ax,[DSP1VARS+6]
mov [Op18R],ax
pushad
call DSPOp18
popad
mov ax,[Op18D]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_28: ; Vector Absolute Value
or byte[DSPDet],04h
push eax
mov ax,[DSP1VARS]
mov [Op28X],ax
mov ax,[DSP1VARS+2]
mov [Op28Y],ax
mov ax,[DSP1VARS+4]
mov [Op28Z],ax
pushad
call DSPOp28
popad
mov ax,[Op28R]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_0C: ; Coordinate Rotation
or byte[DSPDet],08h
push eax
mov ax,[DSP1VARS]
mov [Op0CA],ax
mov ax,[DSP1VARS+2]
mov [Op0CX1],ax
mov ax,[DSP1VARS+4]
mov [Op0CY1],ax
pushad
call DSPOp0C
popad
mov ax,[Op0CX2]
mov [DSP1RET],ax
mov ax,[Op0CY2]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_1C: ; 3D Coordinate Rotation
push eax
mov ax,[DSP1VARS]
mov [Op1CZ],ax
mov ax,[DSP1VARS+2]
mov [Op1CY],ax
mov ax,[DSP1VARS+4]
mov [Op1CX],ax
mov ax,[DSP1VARS+6]
mov [Op1CXBR],ax
mov ax,[DSP1VARS+8]
mov [Op1CYBR],ax
mov ax,[DSP1VARS+10]
mov [Op1CZBR],ax
pushad
call DSPOp1C
popad
mov ax,[Op1CXAR]
mov [DSP1RET],ax
mov ax,[Op1CYAR]
mov [DSP1RET+2],ax
mov ax,[Op1CZAR]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_02: ; Vector Size
or byte[DSPDet],10h
push eax
mov ax,[DSP1VARS]
mov [Op02FX],ax
mov ax,[DSP1VARS+2]
mov [Op02FY],ax
mov ax,[DSP1VARS+4]
mov [Op02FZ],ax
mov ax,[DSP1VARS+6]
mov [Op02LFE],ax
mov ax,[DSP1VARS+8]
mov [Op02LES],ax
mov ax,[DSP1VARS+10]
mov [Op02AAS],ax
mov ax,[DSP1VARS+12]
mov [Op02AZS],ax
pushad
call DSPOp02
popad
mov ax,[Op02VOF]
mov [DSP1RET],ax
mov ax,[Op02VVA]
mov [DSP1RET+2],ax
mov ax,[Op02CX]
mov [DSP1RET+4],ax
mov ax,[Op02CY]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
pop eax
ret
mov eax,dsp1array
add eax,[dsp1ptr]
push ebx
mov byte[eax],02h
mov bx,[Op02FX]
mov [eax+1],bx
mov bx,[Op02FY]
mov [eax+3],bx
mov bx,[Op02FZ]
mov [eax+5],bx
mov bx,[Op02LFE]
mov [eax+7],bx
mov bx,[Op02LES]
mov [eax+9],bx
mov bx,[Op02AAS]
mov [eax+11],bx
mov bx,[Op02AZS]
mov [eax+13],bx
mov bx,[Op02VOF]
mov [eax+15],bx
mov bx,[Op02VVA]
mov [eax+17],bx
mov bx,[Op02CX]
mov [eax+19],bx
mov bx,[Op02CY]
mov [eax+21],bx
pop ebx
add dword[dsp1ptr],23
DSP1_0A: ; Raster Data Calculation via DMA
mov byte[DSP1COp],0Ah
or byte[DSPDet],20h
push eax
mov ax,[DSP1VARS]
mov [Op0AVS],ax
pushad
call DSPOp0A
popad
mov ax,[Op0AA]
mov [DSP1RET],ax
mov ax,[Op0AB]
mov [DSP1RET+2],ax
mov ax,[Op0AC]
mov [DSP1RET+4],ax
mov ax,[Op0AD]
mov [DSP1RET+6],ax
mov byte[DSP1RLeft],4
pop eax
ret
DSP1_06: ; Object Projection Calculation
or byte[DSPDet],40h
push eax
mov ax,[DSP1VARS]
mov [Op06X],ax
mov ax,[DSP1VARS+2]
mov [Op06Y],ax
mov ax,[DSP1VARS+4]
mov [Op06Z],ax
pushad
call DSPOp06
popad
mov ax,[Op06H]
mov [DSP1RET],ax
mov ax,[Op06V]
mov [DSP1RET+2],ax
mov ax,[Op06M]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
mov eax,dsp1array
add eax,[dsp1ptr]
push ebx
mov byte[eax],06h
mov bx,[Op06X]
mov [eax+1],bx
mov bx,[Op06Y]
mov [eax+3],bx
mov bx,[Op06Z]
mov [eax+5],bx
mov bx,[Op06H]
mov [eax+7],bx
mov bx,[Op06V]
mov [eax+9],bx
mov bx,[Op06M]
mov [eax+11],bx
pop ebx
add dword[dsp1ptr],13
DSP1_0E: ; Coordinate Calculation of a point onscreen
push eax
mov ax,[DSP1VARS]
mov [Op0EH],ax
mov ax,[DSP1VARS+2]
mov [Op0EV],ax
pushad
call DSPOp0E
popad
mov ax,[Op0EX]
mov [DSP1RET],ax
mov ax,[Op0EY]
mov [DSP1RET+2],ax
mov byte[DSP1RLeft],2
pop eax
ret
DSP1_01: ; Set Attitude Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op01m],ax
mov ax,[DSP1VARS+2]
mov [Op01Zr],ax
mov ax,[DSP1VARS+4]
mov [Op01Yr],ax
mov ax,[DSP1VARS+6]
mov [Op01Xr],ax
pushad
call DSPOp01
popad
pop eax
ret
DSP1_11: ; Set Attitude Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op11m],ax
mov ax,[DSP1VARS+2]
mov [Op11Zr],ax
mov ax,[DSP1VARS+4]
mov [Op11Yr],ax
mov ax,[DSP1VARS+6]
mov [Op11Xr],ax
pushad
call DSPOp11
popad
pop eax
ret
DSP1_21: ; Set Attitude Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op21m],ax
mov ax,[DSP1VARS+2]
mov [Op21Zr],ax
mov ax,[DSP1VARS+4]
mov [Op21Yr],ax
mov ax,[DSP1VARS+6]
mov [Op21Xr],ax
pushad
call DSPOp21
popad
pop eax
ret
DSP1_0D: ; Convert from global to object coords Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op0DX],ax
mov ax,[DSP1VARS+2]
mov [Op0DY],ax
mov ax,[DSP1VARS+4]
mov [Op0DZ],ax
pushad
call DSPOp0D
popad
mov ax,[Op0DF]
mov [DSP1RET],ax
mov ax,[Op0DL]
mov [DSP1RET+2],ax
mov ax,[Op0DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_0F: ; DSP RAM Test
push eax
mov ax,[DSP1VARS]
pushad
call DSPOp0F
popad
mov ax,[Op0FPass]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_1D: ; Convert from global to object coords Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op1DX],ax
mov ax,[DSP1VARS+2]
mov [Op1DY],ax
mov ax,[DSP1VARS+4]
mov [Op1DZ],ax
pushad
call DSPOp1D
popad
mov ax,[Op1DF]
mov [DSP1RET],ax
mov ax,[Op1DL]
mov [DSP1RET+2],ax
mov ax,[Op1DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_2D: ; Convert from global to object coords Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op2DX],ax
mov ax,[DSP1VARS+2]
mov [Op2DY],ax
mov ax,[DSP1VARS+4]
mov [Op2DZ],ax
pushad
call DSPOp2D
popad
mov ax,[Op2DF]
mov [DSP1RET],ax
mov ax,[Op2DL]
mov [DSP1RET+2],ax
mov ax,[Op2DU]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_03: ; Convert from object to global coords Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op03F],ax
mov ax,[DSP1VARS+2]
mov [Op03L],ax
mov ax,[DSP1VARS+4]
mov [Op03U],ax
pushad
call DSPOp03
popad
mov ax,[Op03X]
mov [DSP1RET],ax
mov ax,[Op03Y]
mov [DSP1RET+2],ax
mov ax,[Op03Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_13: ; Convert from object to global coords Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op13F],ax
mov ax,[DSP1VARS+2]
mov [Op13L],ax
mov ax,[DSP1VARS+4]
mov [Op13U],ax
pushad
call DSPOp13
popad
mov ax,[Op13X]
mov [DSP1RET],ax
mov ax,[Op13Y]
mov [DSP1RET+2],ax
mov ax,[Op13Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_23: ; Convert from object to global coords Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op23F],ax
mov ax,[DSP1VARS+2]
mov [Op23L],ax
mov ax,[DSP1VARS+4]
mov [Op23U],ax
pushad
call DSPOp23
popad
mov ax,[Op23X]
mov [DSP1RET],ax
mov ax,[Op23Y]
mov [DSP1RET+2],ax
mov ax,[Op23Z]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret
DSP1_0B: ; Calculation of inner product Matrix A
push eax
mov ax,[DSP1VARS]
mov [Op0BX],ax
mov ax,[DSP1VARS+2]
mov [Op0BY],ax
mov ax,[DSP1VARS+4]
mov [Op0BZ],ax
pushad
call DSPOp0B
popad
mov ax,[Op0BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_1B: ; Calculation of inner product Matrix B
push eax
mov ax,[DSP1VARS]
mov [Op1BX],ax
mov ax,[DSP1VARS+2]
mov [Op1BY],ax
mov ax,[DSP1VARS+4]
mov [Op1BZ],ax
pushad
call DSPOp1B
popad
mov ax,[Op1BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_2B: ; Calculation of inner product Matrix C
push eax
mov ax,[DSP1VARS]
mov [Op2BX],ax
mov ax,[DSP1VARS+2]
mov [Op2BY],ax
mov ax,[DSP1VARS+4]
mov [Op2BZ],ax
pushad
call DSPOp2B
popad
mov ax,[Op2BS]
mov [DSP1RET],ax
mov byte[DSP1RLeft],1
pop eax
ret
DSP1_14: ; 3D angle rotation
push eax
mov ax,[DSP1VARS]
mov [Op14Zr],ax
mov ax,[DSP1VARS+2]
mov [Op14Xr],ax
mov ax,[DSP1VARS+4]
mov [Op14Yr],ax
mov ax,[DSP1VARS+6]
mov [Op14U],ax
mov ax,[DSP1VARS+8]
mov [Op14F],ax
mov ax,[DSP1VARS+10]
mov [Op14L],ax
pushad
call DSPOp14
popad
mov ax,[Op14Zrr]
mov [DSP1RET],ax
mov ax,[Op14Xrr]
mov [DSP1RET+2],ax
mov ax,[Op14Yrr]
mov [DSP1RET+4],ax
mov byte[DSP1RLeft],3
pop eax
ret

View File

@@ -0,0 +1,608 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; Apr 29, 2004
; DSP2 support code written by kentaro-k.21 <danmasu-lj@infoseek.jp>
; coding hints are based on DSP2 function overview at http://users.tpg.com.au/trauma/dsp/dsp2.html maintained by Overload.
; i have stolen the useful technical info there to implement DSP2 codes without any permission from its author.
; i do NOT know and peep the s9x source codes for either DSP2 or any purpose.
; May 02, 2004
; bug fix for Dungeon Master.
; Command 05h fixed.
; when you got the magic missile damage such as fireball, DSP2 support in prior version entered halt state.
%include "macros.mac"
DSP2F_HALT equ 1
DSP2F_AUTO_BUFFER_SHIFT equ 2
DSP2F_NO_ADDR_CHK equ 4
;*******************************************************
; .bss section
;*******************************************************
SECTION .bss
NEWSYM dsp2buffer, resb 256
NEWSYM dsp2enforcerQueue, resb 8*512
NEWSYM dsp2enforcer, resb 8
;*******************************************************
; .data section
;*******************************************************
SECTION .data
NEWSYM dsp2f03KeyLo, db 0 ; Current transparent-color in lower-byte
NEWSYM dsp2f03KeyHi, db 0 ; Current transparent-color in higher-byte
NEWSYM dsp2enforcerReaderCursor, dd 0 ; T/O
NEWSYM dsp2enforcerWriterCursor, dd 1 ; T/O
NEWSYM dsp2state, dd 1 ; Flags: 1=HALT, 2=AUTO_BUFFER_SHIFT, 4=NO_ADDR_CHK
NEWSYM dsp2input, dd 0 ; Saving input 8-bit data
NEWSYM dsp2inputTemp, dd 0 ; Temporary variable
NEWSYM dsp2f0dSizeOrg, dd 0 ; Command 0D, Original BMP width
NEWSYM dsp2f0dSizeNew, dd 0 ; Command 0D, New BMP width
NEWSYM dsp2f01TblByte ; Conversion table for Command 01
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 0, 1,16,17, 0, 1,16,17
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 2, 3,18,19, 2, 3,18,19
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 4, 5,20,21, 4, 5,20,21
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 6, 7,22,23, 6, 7,22,23
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 8, 9,24,25, 8, 9,24,25
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 10,11,26,27,10,11,26,27
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 12,13,28,29,12,13,28,29
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
db 14,15,30,31,14,15,30,31
NEWSYM dsp2f01TblBitMask ; Conversion table for Command 01
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
db 64, 64, 64, 64,128,128,128,128
db 16, 16, 16, 16, 32, 32, 32, 32
db 4, 4, 4, 4, 8, 8, 8, 8
db 1, 1, 1, 1, 2, 2, 2, 2
;*******************************************************
; .text section
;*******************************************************
SECTION .text
;*******************************************************
;
;*******************************************************
%macro CommandJmp 2
cmp al,%1
je near %2
%endmacro
%macro DevWriteX 1
%ifdef _USE_DEV
pushad
mov dword[_DSP2Dev_arg],%1
call _DevWriteX
popad
%endif
%endmacro
%macro EnterInsideCommand 1
DevWriteX %1
%endmacro
%macro QueueInsideCommand 1
DevWriteX %1+0ffff0000h
%endmacro
%macro LeaveInsideCommand 0
%ifdef _USE_DEV
pushad
call _Leave
popad
%endif
%endmacro
;*******************************************************
;
;*******************************************************
NEWSYM InitDSP2
.enter
mov dword[dsp2state],0
mov dword[dsp2enforcerQueue+8*0+0],0
mov dword[dsp2enforcerQueue+8*0+4],8000h
mov dword[dsp2enforcerReaderCursor],0
mov dword[dsp2enforcerWriterCursor],1
.leave
ret
;*******************************************************
;
;*******************************************************
NEWSYM DSP2Read8b
.enter
test byte[dsp2state],DSP2F_HALT
jnz .halt
test cx,8000h
jz .undef
test cx,7000h
jnz .undef
and ecx,255
mov al,[dsp2buffer+ecx]
xor ecx,ecx
test byte[dsp2state],DSP2F_AUTO_BUFFER_SHIFT
jnz .shiftbuffer
jmp .leave
.shiftbuffer
sar dword[dsp2buffer],8
jmp .leave
.halt
.undef
xor eax,eax
.leave
ret
NEWSYM DSP2Read16b
.enter
xor eax,eax
.leave
ret
;*******************************************************
;
;*******************************************************
NEWSYM _DSP2Add2Queue
.enter
push eax
push ebx
; *** Locates the write cursor
mov eax,[dsp2enforcerWriterCursor]
lea ebx,[dsp2enforcerQueue+eax*8]
inc eax
and eax,511
mov [dsp2enforcerWriterCursor],eax
; *** Copies the local inside command into his queue
mov eax,[dsp2enforcer]
mov [ebx],eax
mov eax,[dsp2enforcer+4]
mov [ebx+4],eax
pop ebx
pop eax
.leave
ret
NEWSYM DSP2Write8b
.enter
; Tests halt flag
test byte[dsp2state],DSP2F_HALT
jnz near .halt
; *** Locates current predicator store
mov [dsp2input],al
mov eax,[dsp2enforcerReaderCursor]
lea ebx,[dsp2enforcerQueue+8*eax]
; *** Copies inside command box into box in order to spare indirection cost
mov eax,[ebx]
mov [dsp2enforcer],eax
mov eax,[ebx+4]
mov [dsp2enforcer+4],eax
xor ebx,ebx
; *** About some commands need to be relaxed the write address check
test byte[dsp2state],DSP2F_NO_ADDR_CHK
jnz .noaddrchk
; *** Tests whether cx points expected address
cmp [dsp2enforcer+4],cx
jne near .gohalt
.noaddrchk
; *** Reads next inside command should be proceeded
mov al,[dsp2enforcer]
; *** Branches to inside commands respectively
CommandJmp 00h,.w00
CommandJmp 01h,.w01
CommandJmp 02h,.w02
CommandJmp 03h,.w03
CommandJmp 04h,.w04
CommandJmp 05h,.w05
CommandJmp 06h,.w06
CommandJmp 07h,.w07
CommandJmp 08h,.w08
CommandJmp 09h,.w09
CommandJmp 0Ah,.w0A
CommandJmp 0Bh,.w0B
jmp .gohalt
.w0B ; ---
EnterInsideCommand 0Bh
mov al,[dsp2input]
xor ecx,ecx
mov cl,[dsp2enforcer+1]
mov [dsp2buffer+ecx],al
jmp .done
.w0A ; ---
EnterInsideCommand 0Ah
mov al,[dsp2input]
sar al,1
mov [dsp2f0dSizeNew],al
test al,al
jz near .gohalt
xor ecx,ecx
xor eax,eax
mov bl,[dsp2f0dSizeNew]
mov bh,[dsp2f0dSizeOrg]
.w0Aploop
mov al,cl
mul bl
div bh
mov dword[dsp2enforcer+0],0Bh
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],al
mov [dsp2enforcer+4],cl
call _DSP2Add2Queue
inc cl
cmp cl,[dsp2f0dSizeOrg]
jne .w0Aploop
xor ebx,ebx
jmp .queueincoming
.w09 ; ---
EnterInsideCommand 9
mov al,[dsp2input]
sar al,1
mov [dsp2f0dSizeOrg],al
test al,al
jz near .gohalt
mov dword[dsp2enforcer+0],0Ah
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w08 ; ---
EnterInsideCommand 8
xor eax,eax
mov al,[dsp2enforcer+1]
mov cl,[dsp2input]
mov [dsp2buffer+eax],cl
cmp al,3
jne .w08done
mov al,[dsp2buffer]
mul byte[dsp2buffer+2]
mov [dsp2buffer],eax
or byte[dsp2state],DSP2F_AUTO_BUFFER_SHIFT
.w08done
jmp .done
.w07 ; ---
EnterInsideCommand 7
mov cl,[dsp2input]
rol cl,4
xor eax,eax
mov al,[dsp2enforcer+1]
mov [dsp2buffer+eax],cl
jmp .done
.w06 ; ---
EnterInsideCommand 6
cmp byte[dsp2input],0
je near .gohalt
xor eax,eax
xor ecx,ecx
mov cl,[dsp2input]
.w06ploop
dec cl
mov dword[dsp2enforcer+0],7
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],cl
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
test cl,cl
jnz .w06ploop
jmp .queueincoming
.w05 ; ---
EnterInsideCommand 5
xor eax,eax
mov al,[dsp2enforcer+4]
mov cl,[dsp2buffer+eax]
mov ch,[dsp2input]
and ch,0f0h
cmp ch,[dsp2f03KeyHi]
je .w05pnohi
and cl,0fh
or cl,ch
.w05pnohi
mov ch,[dsp2input]
and ch,0fh
cmp ch,[dsp2f03KeyLo]
je .w05pnolo
and cl,0f0h
or cl,ch
.w05pnolo
mov [dsp2buffer+eax],cl
jmp .done
.w04 ; ---
EnterInsideCommand 4
xor eax,eax
mov al,[dsp2enforcer+4]
mov cl,[dsp2input]
mov [dsp2buffer+eax],cl
xor ecx,ecx
jmp .done
.w03 ; ---
EnterInsideCommand 3
cmp byte[dsp2input],0
je near .gohalt
xor eax,eax
.w03aloop
mov dword[dsp2enforcer+0],4
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,[dsp2input]
jne .w03aloop
xor eax,eax
.w03bloop
mov dword[dsp2enforcer+0],5
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,[dsp2input]
jne .w03bloop
xor ecx,ecx
jmp .queueincoming
.w02 ; ---
EnterInsideCommand 2
mov al,[dsp2input]
and al,0fh
mov [dsp2f03KeyLo],al
sal al,4
mov [dsp2f03KeyHi],al
jmp .done
.w01 ; ---
EnterInsideCommand 1
xor ecx,ecx
mov cl,[dsp2enforcer+4]
sal ecx,3
mov al,[dsp2input]
mov [dsp2inputTemp],al
xor ebx,ebx
.w01ploop
mov bl,[dsp2f01TblByte+ecx]
mov al,[dsp2f01TblBitMask+ecx]
test byte[dsp2inputTemp],1h
jz .w01pclear
or [dsp2buffer+ebx],al
jmp .w01pok
.w01pclear
not al
and [dsp2buffer+ebx],al
.w01pok
sar byte[dsp2inputTemp],1
inc ecx
test cl,7
jnz .w01ploop
xor ebx,ebx
xor ecx,ecx
jmp .done
.w00 ; ---
EnterInsideCommand 0
and byte[dsp2state],~(DSP2F_AUTO_BUFFER_SHIFT|DSP2F_NO_ADDR_CHK)
mov al,[dsp2input]
CommandJmp 01h,.w00p01
CommandJmp 03h,.w00p03
CommandJmp 05h,.w00p05
CommandJmp 06h,.w00p06
CommandJmp 09h,.w00p09
CommandJmp 0Dh,.w00p0D
CommandJmp 0Fh,.w00p0F
jmp .gohalt
.w00p0D ; ----
QueueInsideCommand 0Dh
mov dword[dsp2enforcer+0],9
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p09 ; ----
QueueInsideCommand 09h
xor eax,eax
mov al,4
.w00p09loop
mov dword[dsp2enforcer+0],8
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+1],ah
call _DSP2Add2Queue
inc ah
dec al
jnz .w00p09loop
jmp .queueincoming
.w00p06 ; ----
QueueInsideCommand 06h
mov dword[dsp2enforcer+0],6
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p05 ; ----
or byte[dsp2state],DSP2F_NO_ADDR_CHK
QueueInsideCommand 05h
mov dword[dsp2enforcer+0],3
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.w00p03 ; ----
QueueInsideCommand 03h
mov dword[dsp2enforcer+0],2
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .queueincoming
.w00p01 ; ----
QueueInsideCommand 01h
xor eax,eax
.w00p01loop
mov dword[dsp2enforcer+0],1
mov dword[dsp2enforcer+4],8000h
mov [dsp2enforcer+4],al
call _DSP2Add2Queue
inc al
cmp al,32
jne .w00p01loop
xor ecx,ecx
jmp .queueincoming
.w00p0F ; ----
QueueInsideCommand 0Fh
.queueincoming
mov dword[dsp2enforcer+0],0
mov dword[dsp2enforcer+4],8000h
call _DSP2Add2Queue
jmp .done
.done
LeaveInsideCommand
mov eax,[dsp2enforcerReaderCursor]
inc eax
and eax,511
mov [dsp2enforcerReaderCursor],eax
xor eax,eax
jmp .leave
.gohalt
QueueInsideCommand 0ffh
or byte[dsp2state],DSP2F_HALT
.halt
xor eax,eax
.leave
ret
NEWSYM DSP2Write16b
.enter
xor eax,eax
.leave
ret

1174
zsnes/src/chips/dsp3emu.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM dsp3_address,dsp3_byte,DSP3GetByte,DSP3SetByte
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jz %1
%endmacro
NEWSYM DSP3Read8b
RouteAccess regaccessbankr8
mov [dsp3_address],cx
pushad
call DSP3GetByte
popad
mov al,[dsp3_byte]
ret
NEWSYM DSP3Write8b
RouteAccess regaccessbankw8
mov [dsp3_address],cx
mov [dsp3_byte],al
pushad
call DSP3SetByte
popad
ret
NEWSYM DSP3Read16b
RouteAccess regaccessbankr16
mov [dsp3_address],cx
pushad
call DSP3GetByte
mov al,[dsp3_byte]
mov [dsp3temp],al
inc word[dsp3_address]
call DSP3GetByte
popad
mov al,[dsp3temp]
mov ah,[dsp3_byte]
ret
NEWSYM DSP3Write16b
RouteAccess regaccessbankw16
mov [dsp3_address],cx
mov [dsp3_byte],al
mov [dsp3temp],ah
pushad
call DSP3SetByte
mov ah,[dsp3temp]
mov [dsp3_byte],ah
inc word[dsp3_address]
call DSP3SetByte
popad
ret
SECTION .bss
NEWSYM dsp3temp, resb 1

2172
zsnes/src/chips/dsp4emu.c Normal file

File diff suppressed because it is too large Load Diff

111
zsnes/src/chips/dsp4emu.h Normal file
View File

@@ -0,0 +1,111 @@
#ifndef DSP4EMU_H
#define DSP4EMU_H
typedef unsigned char bool8;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int16;
typedef long int32;
#define FALSE 0
#define TRUE 1
struct DSP4_t
{
bool8 waiting4command;
bool8 half_command;
uint16 command;
uint32 in_count;
uint32 in_index;
uint32 out_count;
uint32 out_index;
uint8 parameters[512];
uint8 output[512];
};
extern struct DSP4_t DSP4;
struct DSP4_vars_t
{
// op control
int8 DSP4_Logic; // controls op flow
// projection format
int16 lcv; // loop-control variable
int16 distance; // z-position into virtual world
int16 raster; // current raster line
int16 segments; // number of raster lines drawn
// 1.15.16 or 1.15.0 [sign, integer, fraction]
int32 world_x; // line of x-projection in world
int32 world_y; // line of y-projection in world
int32 world_dx; // projection line x-delta
int32 world_dy; // projection line y-delta
int16 world_ddx; // x-delta increment
int16 world_ddy; // y-delta increment
int32 world_xenv; // world x-shaping factor
int16 world_yofs; // world y-vertical scroll
int16 view_x1; // current viewer-x
int16 view_y1; // current viewer-y
int16 view_x2; // future viewer-x
int16 view_y2; // future viewer-y
int16 view_dx; // view x-delta factor
int16 view_dy; // view y-delta factor
int16 view_xofs1; // current viewer x-vertical scroll
int16 view_yofs1; // current viewer y-vertical scroll
int16 view_xofs2; // future viewer x-vertical scroll
int16 view_yofs2; // future viewer y-vertical scroll
int16 view_yofsenv; // y-scroll shaping factor
int16 view_turnoff_x; // road turnoff data
int16 view_turnoff_dx; // road turnoff delta factor
// drawing area
int16 viewport_cx; // x-center of viewport window
int16 viewport_cy; // y-center of render window
int16 viewport_left; // x-left of viewport
int16 viewport_right; // x-right of viewport
int16 viewport_top; // y-top of viewport
int16 viewport_bottom; // y-bottom of viewport
// sprite structure
int16 sprite_x; // projected x-pos of sprite
int16 sprite_y; // projected y-pos of sprite
int16 sprite_attr; // obj attributes
bool8 sprite_size; // sprite size: 8x8 or 16x16
int16 sprite_clipy; // visible line to clip pixels off
int16 sprite_count;
// generic projection variables designed for
// two solid polygons + two polygon sides
int16 poly_clipLf[2][2]; // left clip boundary
int16 poly_clipRt[2][2]; // right clip boundary
int16 poly_ptr[2][2]; // HDMA structure pointers
int16 poly_raster[2][2]; // current raster line below horizon
int16 poly_top[2][2]; // top clip boundary
int16 poly_bottom[2][2]; // bottom clip boundary
int16 poly_cx[2][2]; // center for left/right points
int16 poly_start[2]; // current projection points
int16 poly_plane[2]; // previous z-plane distance
// OAM
int16 OAM_attr[16]; // OAM (size,MSB) data
int16 OAM_index; // index into OAM table
int16 OAM_bits; // offset into OAM table
int16 OAM_RowMax; // maximum number of tiles per 8 aligned pixels (row)
int16 OAM_Row[32]; // current number of tiles per row
};
extern struct DSP4_vars_t DSP4_vars;
#endif

View File

@@ -0,0 +1,83 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM dsp4_address,dsp4_byte,DSP4GetByte,DSP4SetByte
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jz %1
test ecx,4000h
jz .dsp4continue
ret
.dsp4continue
%endmacro
NEWSYM DSP4Read8b
RouteAccess regaccessbankr8
mov [dsp4_address],cx
pushad
call DSP4GetByte
popad
mov al,[dsp4_byte]
ret
NEWSYM DSP4Write8b
RouteAccess regaccessbankw8
mov [dsp4_address],cx
mov [dsp4_byte],al
pushad
call DSP4SetByte
popad
ret
NEWSYM DSP4Read16b
RouteAccess regaccessbankr16
mov [dsp4_address],cx
pushad
call DSP4GetByte
mov al,[dsp4_byte]
mov [dsp4temp],al
inc word[dsp4_address]
call DSP4GetByte
popad
mov al,[dsp4temp]
mov ah,[dsp4_byte]
ret
NEWSYM DSP4Write16b
RouteAccess regaccessbankw16
mov [dsp4_address],cx
mov [dsp4_byte],al
mov [dsp4temp],ah
pushad
call DSP4SetByte
mov ah,[dsp4temp]
mov [dsp4_byte],ah
inc word[dsp4_address]
call DSP4SetByte
popad
ret
SECTION .bss
NEWSYM dsp4temp, resb 1

2686
zsnes/src/chips/fxemu2.asm Normal file

File diff suppressed because it is too large Load Diff

827
zsnes/src/chips/fxemu2.mac Normal file
View File

@@ -0,0 +1,827 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro FETCHPIPE 0
; mov edx,[SfxPBR]
; mov edx,[SfxMemTable+edx*4]
; mov edx,[SfxCPB]
; mov edx,[SfxR15]
mov cl,[ebp]
%endmacro
%macro UpdateR14 0
; mov edx,[SfxROMBR]
; mov edx,[SfxMemTable+edx*4]
mov eax,[SfxCROM]
; and dword[SfxR14],0FFFFh
add eax,[SfxR14]
mov [SfxRomBuffer],eax
%endmacro
%macro CLRFLAGS 0
;and dword[SfxSFR],0FFFFh-0100h-0200h-1000h ; Clear ALT1,ALT2 and B Flags
; xor ch,ch
; mov dword[SfxB],0 ; Clear B Flag
; mov esi,SfxR0
; mov edi,SfxR0
%endmacro
%macro TORN 1 ; V
FETCHPIPE
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov edi,SfxR0
ret
%endmacro
%macro WITH 1 ; Verified.
FETCHPIPE
mov esi,SfxR0+%1*4
mov edi,SfxR0+%1*4
mov dword[SfxB],1
inc ebp ; Increase program counter
call [FxTablec+ecx*4]
mov esi,SfxR0
mov edi,SfxR0
mov dword[SfxB],0 ; Clear B Flag
ret
%endmacro
%macro STWRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
add dword[SfxLastRamAdr],ebx ; Save last ram address
mov edx,[esi] ; Read Source
FETCHPIPE
mov [ebx+eax],dl ; Store Word
xor eax,1
inc ebp ; Increase program counter
mov [ebx+eax],dh ; Store Word
CLRFLAGS
ret
%endmacro
%macro STBRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
mov ebx,[esi] ; Read Source
mov [eax],bl ; Store Byte
CLRFLAGS
inc ebp ; Increase program counter
ret
%endmacro
%macro LDWRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
FETCHPIPE
mov dl,[ebx+eax] ; Store Word
add dword[SfxLastRamAdr],ebx ; Save last ram address
xor eax,1
and edx,0FFFFh
inc ebp ; Increase program counter
mov dh,[ebx+eax] ; Store Word
mov [edi],edx ; Read Source
CLRFLAGS
ret
%endmacro
%macro LDBRN 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
xor ebx,ebx
mov [SfxLastRamAdr],eax ; Save last ram address
mov bl,[eax] ; Read Byte
inc ebp ; Increase program counter
mov [edi],ebx ; Store Result
CLRFLAGS
ret
%endmacro
; test byte[SfxPOR],01h
; jnz .nozerocheck
; test byte[SfxPOR],02h
; jz .nodither
; **** Can pre-calculate [SfxSCBR] << 10 + [sfxramdata]
; Pre-calculate fxbit values from color register
%macro drawpix4b 0
and [eax],edx
and [eax+16],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax], ebx
and edx,[fxbit23pcal]
or [eax+16], edx
%endmacro
%macro drawpix4bd 0
and [eax],edx
and [eax+16],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax], ebx
and edx,[fxbit67pcal]
or [eax+16], edx
%endmacro
%macro drawpix2b 0
and [eax],edx
xor edx,0FFFFFFFFh
and edx,[fxbit01pcal]
or [eax], edx
%endmacro
%macro drawpix2bd 0
and [eax],edx
xor edx,0FFFFFFFFh
and edx,[fxbit45pcal]
or [eax], edx
%endmacro
%macro drawpix8b 0
and [eax],edx
and [eax+16],edx
and [eax+32],edx
and [eax+48],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax], ebx
mov ebx,[fxbit23pcal]
and ebx,edx
or [eax+16], ebx
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax+32], ebx
and edx,[fxbit67pcal]
or [eax+48], edx
%endmacro
%macro drawpix8bd 0
and [eax],edx
and [eax+16],edx
and [eax+32],edx
and [eax+48],edx
xor edx,0FFFFFFFFh
mov ebx,[fxbit45pcal]
and ebx,edx
or [eax], ebx
mov ebx,[fxbit67pcal]
and ebx,edx
or [eax+16], ebx
mov ebx,[fxbit01pcal]
and ebx,edx
or [eax+32], ebx
and edx,[fxbit23pcal]
or [eax+48], edx
%endmacro
%macro plotb 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
%2
%endmacro
%macro plotbz 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
test byte[SfxCOLR],%5
jz .nodraw
%2
%endmacro
%macro plotbd 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
mov bl,[SfxR1]
xor bl,[SfxR2]
test bl,01h
jz .nodither4b
%4
inc word[SfxR1]
%1
.nodither4b
%2
%endmacro
%macro plotbzd 5
shl eax,%3
and ebx,07h
add ebx,ebx
add eax,ebx
add eax,[SCBRrel]
mov bl,[SfxR1]
mov edx,[fxxand+ebx*4]
test byte[SfxCOLR],%5
jz near .nodraw
mov bl,[SfxR1]
xor bl,[SfxR2]
test bl,01h
jz .nodither4b
%4
inc word[SfxR1]
%1
.nodither4b
%2
%endmacro
%macro plotlines4b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix4b, 5, drawpix4bd, 0Fh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines4bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 FXReturn, drawpix4b, 5, drawpix4bd, 0Fh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines2b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 ret, drawpix2b, 4, drawpix2bd, 03h
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines2bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 FXReturn, drawpix2b, 4, drawpix2bd, 03h
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines8b 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix8b, 6, drawpix8bd, 0FFh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines8bb 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 FXReturn, drawpix8b, 6, drawpix8bd, 0FFh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro plotlines8bl 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je near .nodraw
%1 ret, drawpix8b, 6, drawpix8bd, 0Fh
.nodraw
inc word[SfxR1]
ret
%endmacro
%macro plotlines8bbl 1
mov ebx,[SfxR2]
FETCHPIPE
mov bh,[SfxR1]
mov eax,[sfxclineloc]
inc ebp
mov eax,[eax+ebx*4]
cmp eax,0FFFFFFFFh
je .nodraw
%1 FXReturn, drawpix8b, 6, drawpix8bd, 0Fh
.nodraw
inc word[SfxR1]
FXReturn
%endmacro
%macro ADDRN 1 ; V
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
FETCHPIPE
add ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADCRN 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
shr byte[SfxCarry],1
adc ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADIRN 1 ; V
mov eax, [esi] ; Read Source
FETCHPIPE
add ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ADCIRN 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
shr byte[SfxCarry],1
adc ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro SUBRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro SBCRN 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
cmp byte[SfxCarry],1
sbb ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro SUBIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
sub ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro CMPRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
mov [SfxSignZero],eax
CLRFLAGS
inc ebp ; Increase program counter
ret
%endmacro
%macro ANDRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read RN
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro BICRN 1 ; V
mov ebx,[SfxR0+%1*4] ; Read RN
mov eax,[esi] ; Read Source
xor ebx,0FFFFh
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro ANDIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro BICIRN 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro MULTRN 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro UMULTRN 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro MULTIRN 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro UMULTIRN 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
ret
%endmacro
%macro LINK 1 ; Verified.
mov eax,ebp
sub eax,[SfxCPB]
add eax,%1
FETCHPIPE
mov [SfxR11],ax
CLRFLAGS
inc ebp
ret
%endmacro
%macro JMPRN 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read RN
mov ebp,[SfxCPB]
add ebp,eax
CLRFLAGS
ret
%endmacro
%macro LJMPRN 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4]
and eax,07Fh
mov [SfxPBR],al
; mov byte[fxtrace+eax],1
mov eax,[SfxMemTable+eax*4]
mov [SfxCPB],eax
mov ebp,eax
add ebp,[esi] ; Read RN
mov dword[SfxCacheActive],0
push ecx
call FxOp02
pop ecx
dec ebp
ret
%endmacro
%macro IBTRN 1 ; V
movsx eax,byte[ebp]
mov cl,[ebp+1]
add ebp,2
mov [SfxR0+%1*4],ax
CLRFLAGS
ret
%endmacro
%macro LMSRN 1 ; Verified.
xor eax,eax
mov al,[ebp]
add eax,eax
inc ebp
add eax,[SfxRAMMem]
mov cl,[ebp]
mov [SfxLastRamAdr],eax
mov ebx,[eax] ; Read word from ram
inc ebp
mov [SfxR0+%1*4],bx ; Write data
CLRFLAGS
ret
%endmacro
%macro SMSRN 1 ; Verified.
xor eax,eax
mov al,[ebp]
inc ebp
add eax,eax
mov cl,[ebp]
add eax,[SfxRAMMem]
mov ebx,[SfxR0+%1*4] ; Read data
mov [SfxLastRamAdr],eax
inc ebp
mov [eax],bx ; Write word to ram
CLRFLAGS
ret
%endmacro
%macro FROMRN 1 ; V
FETCHPIPE
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
ret
%endmacro
%macro ORRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
or eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro XORRN 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
xor eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro ORI 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
or eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro XORI 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
xor eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
ret
%endmacro
%macro INCRN 1 ; Verified
inc word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
ret
%endmacro
%macro DECRN 1 ; Verified
dec word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxR0+%1*4],eax
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
ret
%endmacro
%macro IWTRN 1 ; aka LEA ; Verified.
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
add ebp,3
mov [SfxR0+%1*4],eax
CLRFLAGS
ret
%endmacro
%macro LMRN 1 ; Verified!
xor eax,eax
mov cl,[ebp+2]
mov ax,[ebp]
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov dl,[eax+ebx]
xor eax,1
add ebp,3
mov dh,[eax+ebx]
mov [SfxR0+%1*4],dx ; Store Word
CLRFLAGS
ret
%endmacro
%macro SMRN 1 ; Verified
mov ebx,[SfxR0+%1*4]
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
mov dx,bx
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov [eax+ebx],dl
xor eax,1
add ebp,3
mov [eax+ebx],dh
CLRFLAGS
ret
%endmacro
%macro PackEsiEdi 0
mov eax,[SfxSREG]
shl eax,2
add eax,SfxR0
mov esi,eax
mov eax,[SfxDREG]
shl eax,2
add eax,SfxR0
mov edi,eax
mov eax,[SfxRAMBR]
shl eax,16
add eax,[sfxramdata]
mov [SfxRAMMem],eax
%endmacro
%macro UnPackEsiEdi 0
mov eax,esi
sub eax,SfxR0
shr eax,2
mov [SfxSREG],eax
mov eax,edi
sub eax,SfxR0
shr eax,2
mov [SfxDREG],eax
%endmacro

615
zsnes/src/chips/fxemu2b.asm Normal file
View File

@@ -0,0 +1,615 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM FxTable,FxTableb,FxTablec,SfxB,SfxCPB,SfxCROM,SfxCarry,SfxOverflow
EXTSYM SfxR0,SfxR14,SfxR15,SfxRomBuffer,SfxSignZero,withr15sk
%include "chips/fxemu2.mac"
%include "chips/fxemu2b.mac"
SECTION .text
NEWSYM FxOpb05 ; BRA branch always ; Verified.
movsx eax,byte[ebp]
mov cl,[ebp+1]
inc ebp
add ebp,eax
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb06 ; BGE branch on greater or equals ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb07 ; BLT branch on lesss than ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb08 ; BNE branch on not equal ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb09 ; BEQ branch on equal (z=1) ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0A ; BPL branch on plus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0B ; BMI branch on minus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0C ; BCC branch on carry clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0D ; BCS branch on carry set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0E ; BVC branch on overflow clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb0F ; BVS branch on overflow set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTableb+ecx*4]
ret
.nojump
inc ebp
call [FxTableb+ecx*4]
ret
NEWSYM FxOpb10 ; TO RN set register n as destination register
TORNb 0
NEWSYM FxOpb11 ; TO RN set register n as destination register
TORNb 1
NEWSYM FxOpb12 ; TO RN set register n as destination register
TORNb 2
NEWSYM FxOpb13 ; TO RN set register n as destination register
TORNb 3
NEWSYM FxOpb14 ; TO RN set register n as destination register
TORNb 4
NEWSYM FxOpb15 ; TO RN set register n as destination register
TORNb 5
NEWSYM FxOpb16 ; TO RN set register n as destination register
TORNb 6
NEWSYM FxOpb17 ; TO RN set register n as destination register
TORNb 7
NEWSYM FxOpb18 ; TO RN set register n as destination register
TORNb 8
NEWSYM FxOpb19 ; TO RN set register n as destination register
TORNb 9
NEWSYM FxOpb1A ; TO RN set register n as destination register
TORNb 10
NEWSYM FxOpb1B ; TO RN set register n as destination register
TORNb 11
NEWSYM FxOpb1C ; TO RN set register n as destination register
TORNb 12
NEWSYM FxOpb1D ; TO RN set register n as destination register
TORNb 13
NEWSYM FxOpb1E ; TO RN set register n as destination register
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi,SfxR0+14*4
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov dword[withr15sk],1
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov edi,SfxR0
UpdateR14
ret
.VersionB
mov eax,[esi] ; Read Source
mov dword[withr15sk],1
mov [SfxR0+14*4],eax ; Write
CLRFLAGS
UpdateR14
inc ebp ; Increase program counter
ret
NEWSYM FxOpb1F ; TO RN set register n as destination register
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi,SfxR0+15*4
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov ebp,[SfxCPB]
mov dword[withr15sk],1
add ebp,[SfxR15]
mov edi,SfxR0
ret
.VersionB
mov eax,[esi] ; Read Source
mov ebp,[SfxCPB]
mov dword[withr15sk],1
add ebp,eax
CLRFLAGS
ret
NEWSYM FxOpb3D ; ALT1 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,01h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
xor ch,ch
ret
NEWSYM FxOpb3E ; ALT2 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,02h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTable+ecx*4]
xor ch,ch
ret
NEWSYM FxOpb3F ; ALT3 set alt3 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,03h
inc ebp
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTable+ecx*4]
xor ch,ch
ret
NEWSYM FxOpbB0 ; FROM rn set source register
FROMRNb 0
NEWSYM FxOpbB1 ; FROM rn set source register
FROMRNb 1
NEWSYM FxOpbB2 ; FROM rn set source register
FROMRNb 2
NEWSYM FxOpbB3 ; FROM rn set source register
FROMRNb 3
NEWSYM FxOpbB4 ; FROM rn set source register
FROMRNb 4
NEWSYM FxOpbB5 ; FROM rn set source register
FROMRNb 5
NEWSYM FxOpbB6 ; FROM rn set source register
FROMRNb 6
NEWSYM FxOpbB7 ; FROM rn set source register
FROMRNb 7
NEWSYM FxOpbB8 ; FROM rn set source register
FROMRNb 8
NEWSYM FxOpbB9 ; FROM rn set source register
FROMRNb 9
NEWSYM FxOpbBA ; FROM rn set source register
FROMRNb 10
NEWSYM FxOpbBB ; FROM rn set source register
FROMRNb 11
NEWSYM FxOpbBC ; FROM rn set source register
FROMRNb 12
NEWSYM FxOpbBD ; FROM rn set source register
FROMRNb 13
NEWSYM FxOpbBE ; FROM rn set source register
FROMRNb 14
NEWSYM FxOpbBF ; FROM rn set source register
test dword[SfxB],1
jnz .VersionB
mov esi,SfxR0+15*4
inc ebp ; Increase program counter
mov eax,ebp
sub eax,[SfxCPB]
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov esi,SfxR0
ret
.VersionB
FETCHPIPE
mov eax,ebp
sub eax,[SfxCPB]
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
NEWSYM FxOpc05 ; BRA branch always ; Verified.
movsx eax,byte[ebp]
mov cl,[ebp+1]
inc ebp
add ebp,eax
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc06 ; BGE branch on greater or equals ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc07 ; BLT branch on lesss than ; Verified.
movsx eax,byte[ebp]
mov ebx,[SfxSignZero]
shr ebx,15
inc ebp
xor bl,[SfxOverflow]
mov cl,[ebp]
test bl,01h
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc08 ; BNE branch on not equal ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc09 ; BEQ branch on equal (z=1) ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],0FFFFh
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0A ; BPL branch on plus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0B ; BMI branch on minus ; Verified.
movsx eax,byte[ebp]
inc ebp
test dword[SfxSignZero],088000h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0C ; BCC branch on carry clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0D ; BCS branch on carry set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxCarry],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0E ; BVC branch on overflow clear ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jnz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc0F ; BVS branch on overflow set ; Verified.
movsx eax,byte[ebp]
inc ebp
test byte[SfxOverflow],01h
mov cl,[ebp]
jz .nojump
add ebp,eax
call [FxTablec+ecx*4]
ret
.nojump
inc ebp
call [FxTablec+ecx*4]
ret
NEWSYM FxOpc10 ; TO RN set register n as destination register
TORNc 0
NEWSYM FxOpc11 ; TO RN set register n as destination register
TORNc 1
NEWSYM FxOpc12 ; TO RN set register n as destination register
TORNc 2
NEWSYM FxOpc13 ; TO RN set register n as destination register
TORNc 3
NEWSYM FxOpc14 ; TO RN set register n as destination register
TORNc 4
NEWSYM FxOpc15 ; TO RN set register n as destination register
TORNc 5
NEWSYM FxOpc16 ; TO RN set register n as destination register
TORNc 6
NEWSYM FxOpc17 ; TO RN set register n as destination register
TORNc 7
NEWSYM FxOpc18 ; TO RN set register n as destination register
TORNc 8
NEWSYM FxOpc19 ; TO RN set register n as destination register
TORNc 9
NEWSYM FxOpc1A ; TO RN set register n as destination register
TORNc 10
NEWSYM FxOpc1B ; TO RN set register n as destination register
TORNc 11
NEWSYM FxOpc1C ; TO RN set register n as destination register
TORNc 12
NEWSYM FxOpc1D ; TO RN set register n as destination register
TORNc 13
NEWSYM FxOpc1E ; TO RN set register n as destination register
FETCHPIPE
mov eax,[esi] ; Read Source
mov [SfxR0+14*4],eax ; Write
CLRFLAGS
UpdateR14
inc ebp ; Increase program counter
ret
NEWSYM FxOpc1F ; TO RN set register n as destination register
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebp,[SfxCPB]
mov [SfxR15],eax
add ebp,eax
CLRFLAGS
ret
NEWSYM FxOpc3D ; ALT1 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,01h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpc3E ; ALT2 set alt1 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,02h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpc3F ; ALT3 set alt3 mode ; Verified.
FETCHPIPE
mov dword[SfxB],0
or ch,03h
inc ebp
call [FxTablec+ecx*4]
xor ch,ch
ret
NEWSYM FxOpcB0 ; FROM rn set source register
FROMRNc 0
NEWSYM FxOpcB1 ; FROM rn set source register
FROMRNc 1
NEWSYM FxOpcB2 ; FROM rn set source register
FROMRNc 2
NEWSYM FxOpcB3 ; FROM rn set source register
FROMRNc 3
NEWSYM FxOpcB4 ; FROM rn set source register
FROMRNc 4
NEWSYM FxOpcB5 ; FROM rn set source register
FROMRNc 5
NEWSYM FxOpcB6 ; FROM rn set source register
FROMRNc 6
NEWSYM FxOpcB7 ; FROM rn set source register
FROMRNc 7
NEWSYM FxOpcB8 ; FROM rn set source register
FROMRNc 8
NEWSYM FxOpcB9 ; FROM rn set source register
FROMRNc 9
NEWSYM FxOpcBA ; FROM rn set source register
FROMRNc 10
NEWSYM FxOpcBB ; FROM rn set source register
FROMRNc 11
NEWSYM FxOpcBC ; FROM rn set source register
FROMRNc 12
NEWSYM FxOpcBD ; FROM rn set source register
FROMRNc 13
NEWSYM FxOpcBE ; FROM rn set source register
FROMRNc 14
NEWSYM FxOpcBF ; FROM rn set source register
FETCHPIPE
mov eax,ebp
sub eax,[SfxCPB]
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret

View File

@@ -0,0 +1,92 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro TORNb 1 ; V
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
mov eax,ebp
sub eax,[SfxCPB]
mov dword[withr15sk],1
mov [SfxR15],eax
call [FxTableb+ecx*4]
mov edi,SfxR0
ret
.VersionB
mov eax,[esi] ; Read Source
mov dword[withr15sk],1
inc ebp ; Increase program counter
mov [SfxR0+%1*4],eax ; Write
CLRFLAGS
ret
%endmacro
%macro FROMRNb 1 ; V
FETCHPIPE
test dword[SfxB],1
jnz .VersionB
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
ret
.VersionB
mov eax,[SfxR0+%1*4] ; Read
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
%endmacro
%macro TORNc 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
inc ebp ; Increase program counter
mov [SfxR0+%1*4],eax ; Write
CLRFLAGS
ret
%endmacro
%macro FROMRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read
inc ebp
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
shr al,7
mov [SfxOverflow],al
CLRFLAGS
ret
%endmacro

2553
zsnes/src/chips/fxemu2c.asm Normal file

File diff suppressed because it is too large Load Diff

532
zsnes/src/chips/fxemu2c.mac Normal file
View File

@@ -0,0 +1,532 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%macro FXReturn 0
dec dword[NumberOfOpcodes]
;pushad
js %%endloop
;call WriteLine
;popad
%%blah
jmp [FxTabled+ecx*4]
%%endloop
jmp FXEndLoop
ALIGN32
%endmacro
%macro FXReturn2 0
dec dword[NumberOfOpcodes]
js %%endloop
jmp [FxTabled+ecx*4]
%%endloop
jmp FXEndLoop
ALIGN32
%endmacro
%macro TORNd 1 ; V
FETCHPIPE
mov edi, SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov edi,SfxR0
FXReturn
%endmacro
%macro WITHc 1 ; Verified.
FETCHPIPE
mov esi,SfxR0+%1*4
mov edi,SfxR0+%1*4
mov dword[SfxB],1
inc ebp ; Increase program counter
call [FxTablec+ecx*4]
mov esi,SfxR0
mov edi,SfxR0
mov dword[SfxB],0 ; Clear B Flag
FXReturn
%endmacro
%macro STWRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
add dword[SfxLastRamAdr],ebx ; Save last ram address
mov edx,[esi] ; Read Source
FETCHPIPE
mov [ebx+eax],dl ; Store Word
xor eax,1
inc ebp ; Increase program counter
mov [ebx+eax],dh ; Store Word
CLRFLAGS
FXReturn
%endmacro
%macro STBRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
mov ebx,[esi] ; Read Source
mov [eax],bl ; Store Byte
CLRFLAGS
inc ebp ; Increase program counter
FXReturn
%endmacro
%macro LDWRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax ; Save last ram address
FETCHPIPE
mov dl,[ebx+eax] ; Store Word
add dword[SfxLastRamAdr],ebx ; Save last ram address
xor eax,1
and edx,0FFFFh
inc ebp ; Increase program counter
mov dh,[ebx+eax] ; Store Word
mov [edi],edx ; Read Source
CLRFLAGS
FXReturn
%endmacro
%macro LDBRNc 1 ; V
mov eax,[SfxR0+%1*4] ; Read register
FETCHPIPE
add eax,[SfxRAMMem]
xor ebx,ebx
mov [SfxLastRamAdr],eax ; Save last ram address
mov bl,[eax] ; Read Byte
inc ebp ; Increase program counter
mov [edi],ebx ; Store Result
CLRFLAGS
FXReturn
%endmacro
%macro ADDRNc 1 ; V
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
FETCHPIPE
add ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADCRNc 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
mov ebx, [SfxR0+%1*4]
shr byte[SfxCarry],1
adc ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADIRNc 1 ; V
mov eax, [esi] ; Read Source
FETCHPIPE
add ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ADCIRNc 1 ; V
FETCHPIPE
mov eax, [esi] ; Read Source
shr byte[SfxCarry],1
adc ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
mov [SfxSignZero],eax
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro SUBRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro SBCRNc 1 ; V
FETCHPIPE
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
cmp byte[SfxCarry],1
sbb ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro SUBIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
sub ax,%1
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
inc ebp ; Increase program counter
mov [edi],eax ; Write Destination
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro CMPRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4]
FETCHPIPE
sub ax,bx
seto byte[SfxOverflow]
setc byte[SfxCarry]
xor byte[SfxCarry],1
mov [SfxSignZero],eax
CLRFLAGS
inc ebp ; Increase program counter
FXReturn
%endmacro
%macro ANDRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read RN
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro BICRNc 1 ; V
mov ebx,[SfxR0+%1*4] ; Read RN
mov eax,[esi] ; Read Source
xor ebx,0FFFFh
FETCHPIPE
and eax,ebx
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro ANDIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro BICIRNc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
and eax,%1
inc ebp
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro MULTRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro UMULTRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,[SfxR0+%1*4] ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro MULTIRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
imul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro UMULTIRNc 1 ; V
mov al,[esi] ; Read Source
mov bl,%1 ; Read RN
FETCHPIPE
mul bl
inc ebp
and eax,0FFFFh
mov [SfxSignZero],eax
mov [edi],eax ; Write Destination
CLRFLAGS
FXReturn
%endmacro
%macro LINKc 1 ; Verified.
mov eax,ebp
sub eax,[SfxCPB]
add eax,%1
FETCHPIPE
mov [SfxR11],ax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro JMPRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read RN
mov ebp,[SfxCPB]
add ebp,eax
CLRFLAGS
FXReturn
%endmacro
%macro LJMPRNc 1 ; V
FETCHPIPE
mov eax,[SfxR0+%1*4]
and eax,07Fh
mov [SfxPBR],al
; mov byte[fxtrace+eax],1
mov eax,[SfxMemTable+eax*4]
mov [SfxCPB],eax
mov ebp,eax
add ebp,[esi] ; Read RN
mov dword[SfxCacheActive],0
push ecx
call FxOp02
pop ecx
dec ebp
FXReturn
%endmacro
%macro IBTRNc 1 ; V
movsx eax,byte[ebp]
mov cl,[ebp+1]
add ebp,2
mov [SfxR0+%1*4],ax
CLRFLAGS
FXReturn
%endmacro
%macro LMSRNc 1 ; Verified.
xor eax,eax
mov al,[ebp]
add eax,eax
inc ebp
add eax,[SfxRAMMem]
mov cl,[ebp]
mov [SfxLastRamAdr],eax
mov ebx,[eax] ; Read word from ram
inc ebp
mov [SfxR0+%1*4],bx ; Write data
CLRFLAGS
FXReturn
%endmacro
%macro SMSRNc 1 ; Verified.
xor eax,eax
mov al,[ebp]
inc ebp
add eax,eax
mov cl,[ebp]
add eax,[SfxRAMMem]
mov ebx,[SfxR0+%1*4] ; Read data
mov [SfxLastRamAdr],eax
inc ebp
mov [eax],bx ; Write word to ram
CLRFLAGS
FXReturn
%endmacro
%macro FROMRNd 1 ; V
FETCHPIPE
mov esi,SfxR0+%1*4
inc ebp ; Increase program counter
call [FxTable+ecx*4]
mov esi,SfxR0
FXReturn
%endmacro
%macro ORRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
or eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro XORRNc 1 ; V
mov eax,[esi] ; Read Source
mov ebx,[SfxR0+%1*4] ; Read
FETCHPIPE
xor eax,ebx
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro ORIc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
or eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro XORIc 1 ; V
mov eax,[esi] ; Read Source
FETCHPIPE
xor eax,%1
inc ebp
mov [edi],eax ; Write DREG
mov [SfxSignZero],eax
CLRFLAGS
FXReturn
%endmacro
%macro INCRNc 1 ; Verified
inc word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro DECRNc 1 ; Verified
dec word[SfxR0+%1*4]
FETCHPIPE
mov eax,[SfxR0+%1*4] ; Read Source
mov [SfxR0+%1*4],eax
mov [SfxSignZero],eax
CLRFLAGS
inc ebp
FXReturn
%endmacro
%macro IWTRNc 1 ; aka LEA ; Verified.
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
add ebp,3
mov [SfxR0+%1*4],eax
CLRFLAGS
FXReturn
%endmacro
%macro LMRNc 1 ; Verified!
xor eax,eax
mov cl,[ebp+2]
mov ax,[ebp]
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov dl,[eax+ebx]
xor eax,1
add ebp,3
mov dh,[eax+ebx]
mov [SfxR0+%1*4],dx ; Store Word
CLRFLAGS
FXReturn
%endmacro
%macro SMRNc 1 ; Verified
mov ebx,[SfxR0+%1*4]
mov eax,[ebp]
mov cl,[ebp+2]
and eax,0FFFFh
mov dx,bx
mov ebx,[SfxRAMMem]
mov [SfxLastRamAdr],eax
add [SfxLastRamAdr],ebx
mov [eax+ebx],dl
xor eax,1
add ebp,3
mov [eax+ebx],dh
CLRFLAGS
FXReturn
%endmacro

3535
zsnes/src/chips/fxtable.asm Normal file

File diff suppressed because it is too large Load Diff

142
zsnes/src/chips/obc1emu.c Normal file
View File

@@ -0,0 +1,142 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
typedef unsigned char bool8;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int16;
typedef long int32;
//C++ in C
typedef unsigned char bool;
#define true 1
#define false 0
static uint8 *OBC1_RAM = 0;
int OBC1_Address;
int OBC1_BasePtr;
int OBC1_Shift;
uint16 obc1_address;
uint8 obc1_byte;
void GetOBC1 ()
{
switch(obc1_address) {
case 0x7ff0:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)];
break;
case 0x7ff1:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1];
break;
case 0x7ff2:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2];
break;
case 0x7ff3:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3];
break;
case 0x7ff4:
obc1_byte = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
break;
default:
obc1_byte = OBC1_RAM[obc1_address & 0x1fff];
}
}
void SetOBC1 ()
{
switch(obc1_address) {
case 0x7ff0:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)] = obc1_byte;
break;
}
case 0x7ff1:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1] = obc1_byte;
break;
}
case 0x7ff2:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2] = obc1_byte;
break;
}
case 0x7ff3:
{
OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3] = obc1_byte;
break;
}
case 0x7ff4:
{
unsigned char Temp;
Temp = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200];
Temp = (Temp & ~(3 << OBC1_Shift)) | ((obc1_byte & 3) << OBC1_Shift);
OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200] = Temp;
break;
}
case 0x7ff5:
{
if (obc1_byte & 1)
OBC1_BasePtr = 0x1800;
else
OBC1_BasePtr = 0x1c00;
break;
}
case 0x7ff6:
{
OBC1_Address = obc1_byte & 0x7f;
OBC1_Shift = (obc1_byte & 3) << 1;
break;
}
}
OBC1_RAM[obc1_address & 0x1fff] = obc1_byte;
}
extern unsigned char *romdata;
void InitOBC1()
{
OBC1_RAM = romdata+0x400000;
if (OBC1_RAM[0x1ff5] & 1)
OBC1_BasePtr = 0x1800;
else
OBC1_BasePtr = 0x1c00;
OBC1_Address = OBC1_RAM[0x1ff6] & 0x7f;
OBC1_Shift = (OBC1_RAM[0x1ff6] & 3) << 1;
}

View File

@@ -0,0 +1,82 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM obc1_address,obc1_byte,SetOBC1,GetOBC1
EXTSYM regaccessbankr16,regaccessbankr8,regaccessbankw16,regaccessbankw8
EXTSYM memaccessbankr16,memaccessbankr8,memaccessbankw16,memaccessbankw8
SECTION .text
%macro RouteAccess 1
test ecx,8000h
jnz memaccessbank%1
cmp ecx,6000h
jb regaccessbank%1
%endmacro
NEWSYM OBC1Read8b
RouteAccess r8
mov [obc1_address],cx
pushad
call GetOBC1
popad
mov al,[obc1_byte]
ret
NEWSYM OBC1Write8b
RouteAccess w8
mov [obc1_address],cx
mov [obc1_byte],al
pushad
call SetOBC1
popad
ret
NEWSYM OBC1Read16b
RouteAccess r16
mov [obc1_address],cx
pushad
call GetOBC1
mov al,[obc1_byte]
mov [obc1temp],al
inc word[obc1_address]
call GetOBC1
popad
mov al,[obc1temp]
mov ah,[obc1_byte]
ret
NEWSYM OBC1Write16b
RouteAccess w16
mov [obc1_address],cx
mov [obc1_byte],al
mov [obc1temp],ah
pushad
call SetOBC1
mov ah,[obc1temp]
mov [obc1_byte],ah
inc word[obc1_address]
call SetOBC1
popad
ret
SECTION .bss
NEWSYM obc1temp, resb 1

363
zsnes/src/chips/sa1proc.asm Normal file
View File

@@ -0,0 +1,363 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM initaddrl,wramdata,IRAM,SA1DoIRQ,SNSRegP,SNSRegPCS
EXTSYM SA1Ptr,SNSPtr,snesmap2,SA1tablead,SA1xpb,SA1RegP,wramdataa,SA1TimerVal
EXTSYM SA1RegPCS,SA1BWPtr,SNSBWPtr,CurBWPtr,SA1NMIV,SA1IRQV
EXTSYM membank0w8,SA1LBound,SA1UBound,SA1SH,SA1SHb,stackor,stackand,snesmmap
EXTSYM SA1xs,SA1IRQExec,SA1Message,Sflagnz,Sflagc,Sflago
; In exec loop, jump to execloop if SA1Status != 0
; *** Disable spc700 if possible ***
SECTION .bss
NEWSYM SA1Status, resb 1 ; 0 = 65816, 1 = SA1A, 2 = SA1B
NEWSYM CurrentExecSA1, resb 1
NEWSYM CurrentCPU, resb 1
;ALIGN32
NEWSYM prevedi, resd 1
SECTION .text
%macro SA1Debugb 0
pushad
sub esi,[initaddrl]
mov [SA1xpc],esi
call nextopcodesa1
popad
mov bl,[esi]
xor dh,dh
inc esi
call dword near [edi+ebx*4]
dec esi
%endmacro
%macro SA1Debug 0
; debug version
test byte[debugds],01h
jz near .nodebug
cmp byte[debuggeron],0
je near .nodebug
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
SA1Debugb
jmp .debug
.nodebug
%endmacro
NEWSYM SA1Swap
mov ecx,[SA1BWPtr]
mov eax,[SA1Ptr] ; small speed hack
test byte[SA1DoIRQ],1
jnz near .sa1exec3
cmp byte[IRAM],0
jne .sa1exec2
cmp dword[eax],0FCF000A5h
je near .nosa1exec
cmp dword[eax-2],0FCF000A5h
je near .nosa1exec
.sa1exec2
cmp byte[SA1SHb],1
je near .nosa1execb
cmp word[ecx+72A4h],0
jnz .sa1exec
cmp dword[eax],0F072A4ADh
je near .nosa1execb
.sa1exec
cmp byte[IRAM+72h],0
jne .sa1exec3
cmp dword[eax],0F03072ADh
je near .nosa1execb
.sa1exec3
.yesdebugr
xor ecx,ecx
; store all snes 65816 stuff
mov [SNSRegP],dl
mov eax,[initaddrl]
mov [prevedi],edi
mov [SNSRegPCS],eax
mov [SNSPtr],esi
; restore all sa1 65816 stuff
mov dl,[SA1RegP]
mov eax,[SA1RegPCS]
mov [initaddrl],eax
mov eax,[SA1BWPtr]
mov [CurBWPtr],eax
mov esi,[SA1Ptr]
mov dword[snesmap2],IRAM
mov dword[wramdata],IRAM
; Check if IRQ is executed on SA-1
xor eax,eax
mov al,dl
add dh,20
mov edi,[SA1tablead+eax*4]
mov byte[SA1Status],1
test dword[SA1DoIRQ],0FF000003h
jnz near .switchirq
.returnirq
; SA1Debug
; cmp byte[SA1SH],1
; je near .speedhack
; non debug version
mov bl,[esi]
inc esi
call dword near [edi+ebx*4]
dec esi
.debug
; store all sa1 65816 stuff
mov [SA1RegP],dl
mov eax,[initaddrl]
mov [SA1RegPCS],eax
mov [SA1Ptr],esi
; restore all snes 65816 stuff
mov dl,[SNSRegP]
mov eax,[SNSRegPCS]
mov [initaddrl],eax
mov eax,[SNSBWPtr]
mov [CurBWPtr],eax
mov dword[wramdata],wramdataa
mov esi,[SNSPtr]
mov eax,[wramdata]
mov [snesmap2],eax
mov edi,[prevedi]
xor eax,eax
add dh,11
inc byte[CurrentExecSA1]
mov byte[SA1Status],0
add dword[SA1TimerVal],23
ret
.speedhack
add dh,90
mov bl,[esi]
inc esi
call dword near [edi+ebx*4]
dec esi
; store all sa1 65816 stuff
mov [SA1RegP],dl
mov eax,[initaddrl]
mov [SA1RegPCS],eax
mov [SA1Ptr],esi
; restore all snes 65816 stuff
mov dl,[SNSRegP]
mov eax,[SNSRegPCS]
mov [initaddrl],eax
mov eax,[SNSBWPtr]
mov [CurBWPtr],eax
mov dword[wramdata],wramdataa
mov esi,[SNSPtr]
mov eax,[wramdata]
mov [snesmap2],eax
mov edi,[prevedi]
xor eax,eax
add byte[CurrentExecSA1],4
mov byte[SA1Status],0
add dword[SA1TimerVal],23
xor dh,dh
mov dh,18
cmp esi,dword[SA1LBound]
jb .stoph
cmp esi,dword[SA1UBound]
ja .stoph
ret
.stoph
mov byte[SA1SH],0
ret
.nosa1execb
xor ecx,ecx
add dh,15
add byte[CurrentExecSA1],2
mov byte[SA1Status],0
ret
.nosa1exec
xor ecx,ecx
add dh,18
add byte[CurrentExecSA1],2
mov byte[SA1Status],0
ret
.switchirq
test dword[SA1DoIRQ],3
jz .notirq
test dword[SA1DoIRQ],1
jz .nmi
and byte[SA1DoIRQ],0FEh
call SA1switchtovirq
jmp .returnirq
.nmi
and byte[SA1DoIRQ],0FDh
call SA1switchtonmi
jmp .returnirq
.notirq
dec byte[SA1DoIRQ+3]
jz .hack
jmp .returnirq
.hack
or byte[SA1DoIRQ],8
jmp .returnirq
SECTION .bss
NEWSYM SA1xpc, resd 1
SECTION .text
%macro makedl 0
and dl,00111100b
test dword[Sflagnz],18000h
jz %%noneg
or dl,80h
%%noneg
test dword[Sflagnz],0FFFFh
jnz %%nozero
or dl,02h
%%nozero
test dword[Sflagc],0FFh
jz %%nocarry
or dl,01h
%%nocarry
test dword[Sflago],0FFh
jz %%nov
or dl,40h
%%nov
%endmacro
NEWSYM SA1switchtonmi
mov al,[SA1Message]
mov [SA1Message+2],al
mov byte[SA1IRQExec+2],1
mov ebx,esi
sub ebx,[initaddrl]
mov [SA1xpc],bx
xor ecx,ecx
mov cx,[SA1xs]
mov al,[SA1xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [SA1xs],cx
xor ebx,ebx
mov [SA1xpb],bl
xor eax,eax
mov ax,[SA1NMIV]
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
NEWSYM SA1switchtovirq
mov al,[SA1Message]
mov [SA1Message+2],al
mov byte[SA1IRQExec+1],1
mov ebx,esi
sub ebx,[initaddrl]
mov [SA1xpc],bx
xor ecx,ecx
mov cx,[SA1xs]
mov al,[SA1xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[SA1xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [SA1xs],cx
xor ebx,ebx
mov [SA1xpb],bl
xor eax,eax
mov ax,[SA1IRQV]
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
ret

1370
zsnes/src/chips/sa1regs.asm Normal file

File diff suppressed because it is too large Load Diff

271
zsnes/src/chips/sdd1emu.c Normal file
View File

@@ -0,0 +1,271 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*******************************************************************************
S-DD1 C emulator code
(c) Copyright 2003 Brad Jorsch with research by
Andreas Naive and John Weidman
*******************************************************************************/
/* S-DD1 decompressor
*
* Based on code and documentation by Andreas Naive, who deserves a great deal
* of thanks and credit for figuring this out.
*
* Andreas says:
* The author is greatly indebted with The Dumper, without whose help and
* patience providing him with real S-DD1 data the research had never been
* possible. He also wish to note that in the very beggining of his research,
* Neviksti had done some steps in the right direction. By last, the author is
* indirectly indebted to all the people that worked and contributed in the
* S-DD1 issue in the past.
*/
#include <string.h>
#ifndef __GNUC__
#define INLINE
#else
#define INLINE static inline
#endif
static int valid_bits;
static unsigned short in_stream;
static unsigned char *in_buf;
static unsigned char bit_ctr[8];
static unsigned char context_states[32];
static int context_MPS[32];
static int bitplane_type;
static int high_context_bits;
static int low_context_bits;
static int prev_bits[8];
static struct {
unsigned char code_size;
unsigned char MPS_next;
unsigned char LPS_next;
} evolution_table[] = {
/* 0 */ { 0,25,25},
/* 1 */ { 0, 2, 1},
/* 2 */ { 0, 3, 1},
/* 3 */ { 0, 4, 2},
/* 4 */ { 0, 5, 3},
/* 5 */ { 1, 6, 4},
/* 6 */ { 1, 7, 5},
/* 7 */ { 1, 8, 6},
/* 8 */ { 1, 9, 7},
/* 9 */ { 2,10, 8},
/* 10 */ { 2,11, 9},
/* 11 */ { 2,12,10},
/* 12 */ { 2,13,11},
/* 13 */ { 3,14,12},
/* 14 */ { 3,15,13},
/* 15 */ { 3,16,14},
/* 16 */ { 3,17,15},
/* 17 */ { 4,18,16},
/* 18 */ { 4,19,17},
/* 19 */ { 5,20,18},
/* 20 */ { 5,21,19},
/* 21 */ { 6,22,20},
/* 22 */ { 6,23,21},
/* 23 */ { 7,24,22},
/* 24 */ { 7,24,23},
/* 25 */ { 0,26, 1},
/* 26 */ { 1,27, 2},
/* 27 */ { 2,28, 4},
/* 28 */ { 3,29, 8},
/* 29 */ { 4,30,12},
/* 30 */ { 5,31,16},
/* 31 */ { 6,32,18},
/* 32 */ { 7,24,22}
};
static unsigned char run_table[128] = {
128, 64, 96, 32, 112, 48, 80, 16, 120, 56, 88, 24, 104, 40, 72,
8, 124, 60, 92, 28, 108, 44, 76, 12, 116, 52, 84, 20, 100, 36,
68, 4, 126, 62, 94, 30, 110, 46, 78, 14, 118, 54, 86, 22, 102,
38, 70, 6, 122, 58, 90, 26, 106, 42, 74, 10, 114, 50, 82, 18,
98, 34, 66, 2, 127, 63, 95, 31, 111, 47, 79, 15, 119, 55, 87,
23, 103, 39, 71, 7, 123, 59, 91, 27, 107, 43, 75, 11, 115, 51,
83, 19, 99, 35, 67, 3, 125, 61, 93, 29, 109, 45, 77, 13, 117,
53, 85, 21, 101, 37, 69, 5, 121, 57, 89, 25, 105, 41, 73, 9,
113, 49, 81, 17, 97, 33, 65, 1
};
INLINE unsigned char GetCodeword(int bits){
unsigned char tmp;
if(!valid_bits){
in_stream|=*(in_buf++);
valid_bits=8;
}
in_stream<<=1;
valid_bits--;
in_stream^=0x8000;
if(in_stream&0x8000) return 0x80+(1<<bits);
tmp=(in_stream>>8) | (0x7f>>bits);
in_stream<<=bits;
valid_bits-=bits;
if(valid_bits<0){
in_stream |= (*(in_buf++))<<(-valid_bits);
valid_bits+=8;
}
return run_table[tmp];
}
INLINE unsigned char GolombGetBit(int code_size){
if(!bit_ctr[code_size]) bit_ctr[code_size]=GetCodeword(code_size);
bit_ctr[code_size]--;
if(bit_ctr[code_size]==0x80){
bit_ctr[code_size]=0;
return 2; /* secret code for 'last zero'. ones are always last. */
}
return (bit_ctr[code_size]==0)?1:0;
}
INLINE unsigned char ProbGetBit(unsigned char context){
unsigned char state=context_states[context];
unsigned char bit=GolombGetBit(evolution_table[state].code_size);
if(bit&1){
context_states[context]=evolution_table[state].LPS_next;
if(state<2){
context_MPS[context]^=1;
return context_MPS[context]; /* just inverted, so just return it */
} else{
return context_MPS[context]^1; /* we know bit is 1, so use a constant */
}
} else if(bit){
context_states[context]=evolution_table[state].MPS_next;
/* zero here, zero there, no difference so drop through. */
}
return context_MPS[context]; /* we know bit is 0, so don't bother xoring */
}
INLINE unsigned char GetBit(unsigned char cur_bitplane){
unsigned char bit;
bit=ProbGetBit(((cur_bitplane&1)<<4)
| ((prev_bits[cur_bitplane]&high_context_bits)>>5)
| (prev_bits[cur_bitplane]&low_context_bits));
prev_bits[cur_bitplane] <<= 1;
prev_bits[cur_bitplane] |= bit;
return bit;
}
static unsigned char cur_plane;
static unsigned char num_bits;
static unsigned char next_byte;
void SDD1_init(unsigned char *in){
bitplane_type=in[0]>>6;
switch(in[0]&0x30){
case 0x00:
high_context_bits=0x01c0;
low_context_bits =0x0001;
break;
case 0x10:
high_context_bits=0x0180;
low_context_bits =0x0001;
break;
case 0x20:
high_context_bits=0x00c0;
low_context_bits =0x0001;
break;
case 0x30:
high_context_bits=0x0180;
low_context_bits =0x0003;
break;
}
in_stream=(in[0]<<11) | (in[1]<<3);
valid_bits=5;
in_buf=in+2;
memset(bit_ctr, 0, sizeof(bit_ctr));
memset(context_states, 0, sizeof(context_states));
memset(context_MPS, 0, sizeof(context_MPS));
memset(prev_bits, 0, sizeof(prev_bits));
cur_plane=0;
num_bits=0;
}
unsigned char SDD1_get_byte(void){
unsigned char bit;
unsigned char byte=0;
switch(bitplane_type){
case 0:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(0)) byte |= bit;
if(GetBit(1)) next_byte |= bit;
}
return byte;
} else {
return next_byte;
}
case 1:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(cur_plane)) byte |= bit;
if(GetBit(cur_plane+1)) next_byte |= bit;
}
return byte;
} else {
if(!num_bits) cur_plane = (cur_plane+2)&7;
return next_byte;
}
case 2:
num_bits+=16;
if(num_bits&16){
next_byte=0;
for(bit=0x80; bit; bit>>=1){
if(GetBit(cur_plane)) byte |= bit;
if(GetBit(cur_plane+1)) next_byte |= bit;
}
return byte;
} else {
if(!num_bits) cur_plane ^= 2;
return next_byte;
}
case 3:
for(cur_plane=0, bit=1; bit; bit<<=1, cur_plane++){
if(GetBit(cur_plane)) byte |= bit;
}
return byte;
default:
/* should never happen */
return 0;
}
}

566
zsnes/src/chips/seta10.c Normal file
View File

@@ -0,0 +1,566 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//http://users.tpg.com.au/trauma/dsp/st010.html
#ifdef __UNIXSDL__
#include "gblhdr.h"
#else
#include <math.h> //sqrt()
#include <stdlib.h> //abs()
#endif
#define SRAM setaramdata
extern unsigned char *setaramdata;
void ST010DoCommand(void);
//C++ style code in C
#define bool unsigned char
#define true 1
#define false 0
typedef signed char int8;
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
// Mode 7 scaling constants for all raster lines
const int16 ST010_M7Scale[176] = {
0x0380, 0x0325, 0x02da, 0x029c, 0x0268, 0x023b, 0x0215, 0x01f3,
0x01d5, 0x01bb, 0x01a3, 0x018e, 0x017b, 0x016a, 0x015a, 0x014b,
0x013e, 0x0132, 0x0126, 0x011c, 0x0112, 0x0109, 0x0100, 0x00f8,
0x00f0, 0x00e9, 0x00e3, 0x00dc, 0x00d6, 0x00d1, 0x00cb, 0x00c6,
0x00c1, 0x00bd, 0x00b8, 0x00b4, 0x00b0, 0x00ac, 0x00a8, 0x00a5,
0x00a2, 0x009e, 0x009b, 0x0098, 0x0095, 0x0093, 0x0090, 0x008d,
0x008b, 0x0088, 0x0086, 0x0084, 0x0082, 0x0080, 0x007e, 0x007c,
0x007a, 0x0078, 0x0076, 0x0074, 0x0073, 0x0071, 0x006f, 0x006e,
0x006c, 0x006b, 0x0069, 0x0068, 0x0067, 0x0065, 0x0064, 0x0063,
0x0062, 0x0060, 0x005f, 0x005e, 0x005d, 0x005c, 0x005b, 0x005a,
0x0059, 0x0058, 0x0057, 0x0056, 0x0055, 0x0054, 0x0053, 0x0052,
0x0051, 0x0051, 0x0050, 0x004f, 0x004e, 0x004d, 0x004d, 0x004c,
0x004b, 0x004b, 0x004a, 0x0049, 0x0048, 0x0048, 0x0047, 0x0047,
0x0046, 0x0045, 0x0045, 0x0044, 0x0044, 0x0043, 0x0042, 0x0042,
0x0041, 0x0041, 0x0040, 0x0040, 0x003f, 0x003f, 0x003e, 0x003e,
0x003d, 0x003d, 0x003c, 0x003c, 0x003b, 0x003b, 0x003a, 0x003a,
0x003a, 0x0039, 0x0039, 0x0038, 0x0038, 0x0038, 0x0037, 0x0037,
0x0036, 0x0036, 0x0036, 0x0035, 0x0035, 0x0035, 0x0034, 0x0034,
0x0034, 0x0033, 0x0033, 0x0033, 0x0032, 0x0032, 0x0032, 0x0031,
0x0031, 0x0031, 0x0030, 0x0030, 0x0030, 0x0030, 0x002f, 0x002f,
0x002f, 0x002e, 0x002e, 0x002e, 0x002e, 0x002d, 0x002d, 0x002d,
0x002d, 0x002c, 0x002c, 0x002c, 0x002c, 0x002b, 0x002b, 0x002b
};
const int16 ST010_SinTable[256] = {
0x0000, 0x0324, 0x0648, 0x096a, 0x0c8c, 0x0fab, 0x12c8, 0x15e2,
0x18f9, 0x1c0b, 0x1f1a, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11,
0x30fb, 0x33df, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a,
0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842,
0x5a82, 0x5cb3, 0x5ed7, 0x60eb, 0x62f1, 0x64e8, 0x66cf, 0x68a6,
0x6a6d, 0x6c23, 0x6dc9, 0x6f5e, 0x70e2, 0x7254, 0x73b5, 0x7504,
0x7641, 0x776b, 0x7884, 0x7989, 0x7a7c, 0x7b5c, 0x7c29, 0x7ce3,
0x7d89, 0x7e1d, 0x7e9c, 0x7f09, 0x7f61, 0x7fa6, 0x7fd8, 0x7ff5,
0x7fff, 0x7ff5, 0x7fd8, 0x7fa6, 0x7f61, 0x7f09, 0x7e9c, 0x7e1d,
0x7d89, 0x7ce3, 0x7c29, 0x7b5c, 0x7a7c, 0x7989, 0x7884, 0x776b,
0x7641, 0x7504, 0x73b5, 0x7254, 0x70e2, 0x6f5e, 0x6dc9, 0x6c23,
0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f1, 0x60eb, 0x5ed7, 0x5cb3,
0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4,
0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33df,
0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f1a, 0x1c0b,
0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8c, 0x096a, 0x0648, 0x0324,
0x0000, -0x0324, -0x0648, -0x096b, -0x0c8c, -0x0fab, -0x12c8, -0x15e2,
-0x18f9, -0x1c0b, -0x1f1a, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11,
-0x30fb, -0x33df, -0x36ba, -0x398d, -0x3c56, -0x3f17, -0x41ce, -0x447a,
-0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842,
-0x5a82, -0x5cb3, -0x5ed7, -0x60ec, -0x62f1, -0x64e8, -0x66cf, -0x68a6,
-0x6a6d, -0x6c23, -0x6dc9, -0x6f5e, -0x70e2, -0x7254, -0x73b5, -0x7504,
-0x7641, -0x776b, -0x7884, -0x7989, -0x7a7c, -0x7b5c, -0x7c29, -0x7ce3,
-0x7d89, -0x7e1d, -0x7e9c, -0x7f09, -0x7f61, -0x7fa6, -0x7fd8, -0x7ff5,
-0x7fff, -0x7ff5, -0x7fd8, -0x7fa6, -0x7f61, -0x7f09, -0x7e9c, -0x7e1d,
-0x7d89, -0x7ce3, -0x7c29, -0x7b5c, -0x7a7c, -0x7989, -0x7883, -0x776b,
-0x7641, -0x7504, -0x73b5, -0x7254, -0x70e2, -0x6f5e, -0x6dc9, -0x6c23,
-0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f1, -0x60eb, -0x5ed7, -0x5cb3,
-0x5a82, -0x5842, -0x55f5, -0x539a, -0x5133, -0x4ebf, -0x4c3f, -0x49b3,
-0x471c, -0x447a, -0x41cd, -0x3f17, -0x3c56, -0x398c, -0x36b9, -0x33de,
-0x30fb, -0x2e10, -0x2b1f, -0x2826, -0x2527, -0x2223, -0x1f19, -0x1c0b,
-0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324};
const unsigned char ST010_ArcTan[32][32] = {
{ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
{ 0x80, 0xa0, 0xad, 0xb3, 0xb6, 0xb8, 0xb9, 0xba, 0xbb, 0xbb, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd,
0xbd, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbe, 0xbf, 0xbf, 0xbf, 0xbf},
{ 0x80, 0x93, 0xa0, 0xa8, 0xad, 0xb0, 0xb3, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xbb,
0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc, 0xbc, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd, 0xbd},
{ 0x80, 0x8d, 0x98, 0xa0, 0xa6, 0xaa, 0xad, 0xb0, 0xb1, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb7, 0xb8,
0xb8, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbc, 0xbc, 0xbc, 0xbc},
{ 0x80, 0x8a, 0x93, 0x9a, 0xa0, 0xa5, 0xa8, 0xab, 0xad, 0xaf, 0xb0, 0xb2, 0xb3, 0xb4, 0xb5, 0xb5,
0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xba, 0xba, 0xba, 0xba, 0xba, 0xbb, 0xbb},
{ 0x80, 0x88, 0x90, 0x96, 0x9b, 0xa0, 0xa4, 0xa7, 0xa9, 0xab, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
0xb4, 0xb4, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8, 0xb9, 0xb9, 0xb9, 0xb9, 0xb9},
{ 0x80, 0x87, 0x8d, 0x93, 0x98, 0x9c, 0xa0, 0xa3, 0xa6, 0xa8, 0xaa, 0xac, 0xad, 0xae, 0xb0, 0xb0,
0xb1, 0xb2, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb8, 0xb8, 0xb8},
{ 0x80, 0x86, 0x8b, 0x90, 0x95, 0x99, 0x9d, 0xa0, 0xa3, 0xa5, 0xa7, 0xa9, 0xaa, 0xac, 0xad, 0xae,
0xaf, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7},
{ 0x80, 0x85, 0x8a, 0x8f, 0x93, 0x97, 0x9a, 0x9d, 0xa0, 0xa2, 0xa5, 0xa6, 0xa8, 0xaa, 0xab, 0xac,
0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb5, 0xb5, 0xb5, 0xb5},
{ 0x80, 0x85, 0x89, 0x8d, 0x91, 0x95, 0x98, 0x9b, 0x9e, 0xa0, 0xa0, 0xa4, 0xa6, 0xa7, 0xa9, 0xaa,
0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb4, 0xb4},
{ 0x80, 0x84, 0x88, 0x8c, 0x90, 0x93, 0x96, 0x99, 0x9b, 0x9e, 0xa0, 0xa2, 0xa4, 0xa5, 0xa7, 0xa8,
0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb2, 0xb3, 0xb3},
{ 0x80, 0x84, 0x87, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5, 0xa6,
0xa7, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb1, 0xb2, 0xb2},
{ 0x80, 0x83, 0x87, 0x8a, 0x8d, 0x90, 0x93, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0xa0, 0xa2, 0xa3, 0xa5,
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb0, 0xb0, 0xb1},
{ 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x94, 0x96, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa2, 0xa3,
0xa4, 0xa5, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab, 0xac, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xaf, 0xb0},
{ 0x80, 0x83, 0x86, 0x89, 0x8b, 0x8e, 0x90, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9d, 0x9e, 0xa0, 0xa1,
0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xad, 0xad, 0xae, 0xae, 0xaf},
{ 0x80, 0x83, 0x85, 0x88, 0x8b, 0x8d, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9b, 0x9d, 0x9f, 0xa0,
0xa1, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xab, 0xab, 0xac, 0xad, 0xad, 0xae},
{ 0x80, 0x83, 0x85, 0x88, 0x8a, 0x8c, 0x8f, 0x91, 0x93, 0x95, 0x97, 0x99, 0x9a, 0x9c, 0x9d, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa5, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xab, 0xac, 0xad},
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x97, 0x99, 0x9b, 0x9c, 0x9d,
0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac},
{ 0x80, 0x82, 0x85, 0x87, 0x89, 0x8b, 0x8d, 0x8f, 0x91, 0x93, 0x95, 0x96, 0x98, 0x99, 0x9b, 0x9c,
0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9, 0xa9, 0xaa, 0xab},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x9a, 0x9b,
0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8, 0xa8, 0xa9, 0xaa},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x99, 0x9a,
0x9b, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6, 0xa7, 0xa7, 0xa8, 0xa9},
{ 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8f, 0x90, 0x92, 0x94, 0x95, 0x97, 0x98, 0x99,
0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa8},
{ 0x80, 0x82, 0x84, 0x86, 0x87, 0x89, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x93, 0x94, 0x96, 0x97, 0x98,
0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa3, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7},
{ 0x80, 0x82, 0x84, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x8f, 0x91, 0x92, 0x94, 0x95, 0x96, 0x98,
0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5, 0xa6},
{ 0x80, 0x82, 0x83, 0x85, 0x87, 0x88, 0x8a, 0x8c, 0x8d, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x8a, 0x8b, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa4},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x88, 0x89, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x95,
0x96, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4},
{ 0x80, 0x82, 0x83, 0x85, 0x86, 0x87, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93, 0x95,
0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3},
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x89, 0x8a, 0x8b, 0x8d, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9e, 0x9f, 0xa0, 0xa1, 0xa1, 0xa2},
{ 0x80, 0x81, 0x83, 0x84, 0x86, 0x87, 0x88, 0x8a, 0x8b, 0x8c, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93,
0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1, 0xa1},
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8b, 0x8c, 0x8d, 0x8e, 0x90, 0x91, 0x92, 0x93,
0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0, 0xa1},
{ 0x80, 0x81, 0x83, 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92,
0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e, 0x9f, 0x9f, 0xa0}};
short ST010_Sin(short Theta)
{
return ST010_SinTable[(Theta >> 8) & 0xff];
}
short ST010_Cos(short Theta)
{
return ST010_SinTable[((Theta + 0x4000) >> 8) & 0xff];
}
void ST010_OP01(short x0, short y0, short *x1, short *y1, short *Quadrant, short *Theta)
{
if ((x0 < 0) && (y0 < 0))
{
*x1 = -x0;
*y1 = -y0;
*Quadrant = -0x8000;
}
else if (x0 < 0)
{
*x1 = y0;
*y1 = -x0;
*Quadrant = -0x4000;
}
else if (y0 < 0)
{
*x1 = -y0;
*y1 = x0;
*Quadrant = 0x4000;
}
else
{
*x1 = x0;
*y1 = y0;
*Quadrant = 0x0000;
}
while ((*x1 > 0x1f) || (*y1 > 0x1f))
{
if (*x1 > 1) *x1 >>= 1;
if (*y1 > 1) *y1 >>= 1;
}
if (*y1 == 0) *Quadrant += 0x4000;
*Theta = (ST010_ArcTan[*y1][*x1] << 8) ^ *Quadrant;
}
void ST010_Scale(short Multiplier, short X0, short Y0, int *X1, int *Y1)
{
*X1 = X0 * Multiplier << 1;
*Y1 = Y0 * Multiplier << 1;
}
void ST010_Multiply(short Multiplicand, short Multiplier, int *Product)
{
*Product = Multiplicand * Multiplier << 1;
}
void ST010_Rotate(short Theta, short X0, short Y0, short *X1, short *Y1)
{
*X1 = (Y0 * ST010_Sin(Theta) >> 15) + (X0 * ST010_Cos(Theta) >> 15);
*Y1 = (Y0 * ST010_Cos(Theta) >> 15) - (X0 * ST010_Sin(Theta) >> 15);
}
void ST010_SortDrivers(uint16 Positions, uint16 Places[32], uint16 Drivers[32])
{
bool Sorted;
uint16 Temp;
if (Positions > 1)
{
do
{
int i;
Sorted = true;
for (i = 0; i < Positions - 1; i++)
{
if (Places[i] < Places[i + 1])
{
Temp = Places[i + 1];
Places[i + 1] = Places[i];
Places[i] = Temp;
Temp = Drivers[i + 1];
Drivers[i + 1] = Drivers[i];
Drivers[i] = Temp;
Sorted = false;
}
}
Positions--;
} while (!Sorted);
}
}
#define ST010_WORD(offset) (*((short *)(SRAM+offset)))
//#define ST010_WORD(offset) (SRAM[offset + 1] << 8) | SRAM[offset]
void ST010DoCommand(void)
{
switch(SRAM[0x20])
{
/*
Calculate track data based on direction coords
Input
0x0000-0x0001 : DX (signed)
0x0002-0x0003 : DY (signed)
Output
0x0010-0x0011 : Angle (signed)
*/
case 0x01:
{
SRAM[0x0006] = SRAM[0x0002];
SRAM[0x0007] = SRAM[0x0003];
ST010_OP01(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)SRAM, (short *)&SRAM[2], (short *)&SRAM[4], (short *)&SRAM[0x10]);
}
break;
//Sorts a bunch of values by weight
case 0x02:
{
ST010_SortDrivers(*(short*)&SRAM[0x0024], (uint16*)&SRAM[0x0040], (uint16*)&SRAM[0x0080]);
}
break;
/*
Two Dimensional Coordinate Scale
Input
0x0000-0x0001 : X0 (signed)
0x0002-0x0003 : Y0 (signed)
0x0004-0x0005 : Multiplier (signed)
Output
0x0010-0x0013 : X1 (signed)
0x0014-0x0017 : Y1 (signed)
*/
case 0x03:
{
ST010_Scale(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10], (int *)&SRAM[0x14]);
}
break;
//Calculate the vector length of (x,y)
case 0x04:
{
int16 square, x,y;
x=*((int16*)SRAM);
y=*((int16*)&SRAM[2]);
square=(int16)sqrt((double)(y*y+x*x));
*((int16*)&SRAM[0x10])=square;
break;
}
//Calculate AI orientation based on specific guidelines
case 0x05:
{
int dx,dy;
int16 a1,b1,c1;
uint16 o1;
bool wrap=false;
//Target (x,y) coordinates
int16 ypos_max = ST010_WORD(0x00C0);
int16 xpos_max = ST010_WORD(0x00C2);
//Current coordinates and direction
int32 ypos = SRAM[0xC4]|(SRAM[0xC5]<<8)|(SRAM[0xC6]<<16)|(SRAM[0xC7]<<24);
int32 xpos = SRAM[0xC8]|(SRAM[0xC9]<<8)|(SRAM[0xCA]<<16)|(SRAM[0xCB]<<24);
uint16 rot = SRAM[0xCC]|(SRAM[0xCD]<<8);
//Physics
uint16 speed = ST010_WORD(0x00D4);
uint16 accel = ST010_WORD(0x00D6);
uint16 speed_max = ST010_WORD(0x00D8);
//Special condition acknowledgment
int16 system = ST010_WORD(0x00DA);
int16 flags = ST010_WORD(0x00DC);
//New target coordinates
int16 ypos_new = ST010_WORD(0x00DE);
int16 xpos_new = ST010_WORD(0x00E0);
//Backup speed
uint16 old_speed = speed;
//Mask upper bit
xpos_new &= 0x7FFF;
//Get the current distance
dx = xpos_max-(xpos>>16);
dy = ypos_max-(ypos>>16);
//Quirk: clear and move in9
SRAM[0xD2]=0xFF;
SRAM[0xD3]=0xFF;
SRAM[0xDA]=0;
SRAM[0xDB]=0;
//Grab the target angle
ST010_OP01(dy,dx,&a1,&b1,&c1,(int16 *)&o1);
//Check for wrapping
if (abs(o1-rot)>0x8000)
{
o1+=0x8000;
rot+=0x8000;
wrap=true;
}
//Special case
if (abs(o1-rot)==0x8000)
{
speed = 0x100;
}
//Slow down for sharp curves
else if (abs(o1-rot)>=0x1000)
{
uint32 slow = abs(o1-rot);
slow >>= 4; //Scaling
speed -= slow;
}
//Otherwise accelerate
else
{
speed += accel;
if (speed > speed_max)
{
//Clip speed
speed = speed_max;
}
}
//Prevent negative/positive overflow
if( abs(old_speed-speed)>0x8000)
{
if (old_speed<speed) { speed=0; }
else { speed=0xff00; }
}
//Adjust direction by so many degrees
//Be careful of negative adjustments
if ((o1>rot && (o1-rot)>0x80) || (o1<rot && (rot-o1)>=0x80))
{
if (o1<rot) { rot-=0x280; }
else if (o1>rot) { rot+=0x280; }
}
//Turn off wrapping
if (wrap) { rot-=0x8000; }
//Now check the distances (store for later)
dx = (xpos_max<<16)-xpos;
dy = (ypos_max<<16)-ypos;
dx>>=16;
dy>>=16;
//If we're in so many units of the target, signal it
if ((system && (dy<=6 && dy>=-8) && (dx<=126 && dx>=-128)) ||
(!system && (dx<=6 && dx>=-8) && (dy<=126 && dy>=-128)))
{
//Announce our new destination and flag it
xpos_max = xpos_new&0x7FFF;
ypos_max = ypos_new;
flags |= 0x08;
}
//Update position
xpos -= (ST010_Cos(rot) * 0x400 >> 15) * (speed >> 8) << 1;
ypos -= (ST010_Sin(rot) * 0x400 >> 15) * (speed >> 8) << 1;
//Quirk: mask upper byte
xpos &= 0x1FFFFFFF;
ypos &= 0x1FFFFFFF;
SRAM[0x00C0]=(uint8)(ypos_max);
SRAM[0x00C1]=(uint8)(ypos_max >> 8);
SRAM[0x00C2]=(uint8)(xpos_max);
SRAM[0x00C3]=(uint8)(xpos_max >> 8);
SRAM[0x00C4]=(uint8)(ypos);
SRAM[0x00C5]=(uint8)(ypos >> 8);
SRAM[0x00C6]=(uint8)(ypos >> 16);
SRAM[0x00C7]=(uint8)(ypos >> 24);
SRAM[0x00C8]=(uint8)(xpos);
SRAM[0x00C9]=(uint8)(xpos >> 8);
SRAM[0x00CA]=(uint8)(xpos >> 16);
SRAM[0x00CB]=(uint8)(xpos >> 24);
SRAM[0x00CC]=(uint8)(rot);
SRAM[0x00CD]=(uint8)(rot >> 8);
SRAM[0x00D4]=(uint8)(speed);
SRAM[0x00D5]=(uint8)(speed >> 8);
SRAM[0x00DC]=(uint8)(flags);
SRAM[0x00DD]=(uint8)(flags >> 8);
}
break;
/*
16-bit Multiplication
Input
0x0000-0x0001 : Multiplcand (signed)
0x0002-0x0003 : Multiplier (signed)
Output
0x0010-0x0013 : Product (signed)
*/
case 0x06:
{
ST010_Multiply(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10]);
}
break;
/*
Mode 7 Raster Data Calculation
Input
0x0000-0x0001 : Angle (signed)
Output
0x00f0-0x024f : Mode 7 Matrix A
0x0250-0x03af : Mode 7 Matrix B
0x03b0-0x050f : Mode 7 Matrix C
0x0510-0x066f : Mode 7 Matrix D
*/
case 0x07:
{
int16 data;
int32 offset = 0;
int16 Theta = ST010_WORD(0x0000);
int32 line;
for (line = 0; line < 176; line++)
{
//Calculate Mode 7 Matrix A/D data
data = ST010_M7Scale[line] * ST010_Cos(Theta) >> 15;
SRAM[0x00f0 + offset]=(uint8)(data);
SRAM[0x00f1 + offset]=(uint8)(data >> 8);
SRAM[0x0510 + offset]=(uint8)(data);
SRAM[0x0511 + offset]=(uint8)(data >> 8);
//Calculate Mode 7 Matrix B/C data
data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15;
SRAM[0x0250 + offset]=(uint8)(data);
SRAM[0x0251 + offset]=(uint8)(data >> 8);
if (data) { data = ~data; }
SRAM[0x03b0 + offset]=(uint8)(data);
SRAM[0x03b1 + offset]=(uint8)(data >> 8);
offset += 2;
}
//Shift Angle for use with Lookup table
SRAM[0x00] = SRAM[0x01];
SRAM[0x01] = 0x00;
}
break;
/*
Two dimensional Coordinate Rotation
Input
0x0000-0x0001 : X0 (signed)
0x0002-0x0003 : Y0 (signed)
0x0004-0x0005 : Angle (signed)
Output
0x0010-0x0011 : X1 (signed)
0x0012-0x0013 : Y1 (signed)
*/
case 0x08:
{
ST010_Rotate(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)&SRAM[0x10], (short *)&SRAM[0x12]);
}
break;
default: break;
}
//Lower signal: op processed
SRAM[0x20]=0;
SRAM[0x21]=0;
}

585
zsnes/src/chips/seta11.c Normal file
View File

@@ -0,0 +1,585 @@
// ST-011 SNES DSP adapted from Morita Shogi 64
//
// notes:
// - the SNES uses DMA to/from 60:0000 and maybe 68:0xxx
// - some code redundancy (helper subroutines for movement projection)
//
// - OPS04/05 have unknown output values (!)
// - OPS06/07 have unknown purposes
//
// - plenty of missing opcodes that don't show up in the only known binary log (st011-demo)
// (play the game until captured/promoted pieces, king checked, endgame)
// - minus emulation cycles (busy signals), bit-perfect to 'st011-demo'
//#define DEBUG_DSP
#ifdef DEBUG_DSP
#include <stdio.h>
int debug1, debug2;
int line_count;
#endif
void (*RunST011)();
void ST011_Command();
unsigned char ST011_DR;
unsigned char ST011_SR;
int ST011_input_length;
#define ST011_ram setaramdata
extern unsigned char *setaramdata;
#define ST011_board ( ST011_ram+0x130 )
int ST011_dma_count;
int ST011_dma_index;
int ST011_king1;
int ST011_king2;
// (x,y)
#define MOVE_UUL -1,-20
#define MOVE_UL -1,-10
#define MOVE_ULAll -9,- 9
#define MOVE_U 0,-10
#define MOVE_UAll 0,- 9
#define MOVE_UR 1,-10
#define MOVE_URAll 9,- 9
#define MOVE_UUR 1,-20
#define MOVE_L -1, 0
#define MOVE_LAll -9, 0
#define MOVE_R 1, 0
#define MOVE_RAll 9, 0
#define MOVE_DDL -1, 20
#define MOVE_DL -1, 10
#define MOVE_DLAll -9, 9
#define MOVE_D 0, 10
#define MOVE_DAll 0, 9
#define MOVE_DR 1, 10
#define MOVE_DRAll 9, 9
#define MOVE_DDR 1, 20
#define MOVE_STOP 127,127
#define MOVE_NOP 0, 0
const int ST011_move_table[8*2][9*2] =
{
// Pawn: one step forward
// - Promoted: same as Gold
{ MOVE_D, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Lance: all steps forward
// - Promoted: same as Gold
{ MOVE_DAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Knight: one step side, two forward
// - Promoted: same as Gold
{ MOVE_DDR, MOVE_DDL, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Silver general: one any diagonal, one step forward
// - Promoted: same as Gold
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_UR, MOVE_UL, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
// Gold general: one any forward, one sideways or one backward
// - Promoted: N/A
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_U, MOVE_STOP, MOVE_NOP, MOVE_NOP },
{ MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
// Bishop: any diagonal
// - Promoted: Bishop + King
{ MOVE_DRAll, MOVE_DLAll, MOVE_URAll, MOVE_ULAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DRAll, MOVE_D, MOVE_DLAll, MOVE_R, MOVE_L, MOVE_URAll, MOVE_U, MOVE_ULAll, MOVE_STOP },
// Rook: any vertical, horizontal
// - Promoted: Rook + King
{ MOVE_DAll, MOVE_RAll, MOVE_LAll, MOVE_UAll, MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
{ MOVE_DR, MOVE_DAll, MOVE_DL, MOVE_RAll, MOVE_LAll, MOVE_UR, MOVE_UAll, MOVE_UL, MOVE_STOP },
// King: one any direction
// - Promoted: N/A
{ MOVE_DR, MOVE_D, MOVE_DL, MOVE_R, MOVE_L, MOVE_UR, MOVE_U, MOVE_UL, MOVE_STOP },
{ MOVE_STOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP, MOVE_NOP },
};
void ST011_Reset()
{
RunST011 = &ST011_Command;
ST011_SR=0xff;
}
void ST011_OP01_A()
{
if( ST011_dma_count-- )
{
ST011_board[ ST011_dma_index++ ] = ST011_DR;
}
if( ST011_dma_count == 0 )
{
#ifdef DEBUG_DSP
int lcv1, lcv2;
#endif
int lcv;
for( lcv = 0; lcv < 11; lcv++ )
{
ST011_board[ lcv ] = 0;
}
for( lcv = 11; lcv < 21; lcv++ )
{
ST011_board[ lcv ] = 0x80;
}
ST011_king1 = ST011_board[ 126+21 ];
ST011_king2 = ST011_board[ 127+21 ];
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
#ifdef DEBUG_DSP
// Debug
printf( "OP01\n" );
for( lcv1 = 0; lcv1 < 9; lcv1++ )
{
for( lcv2 = 0; lcv2 < 10; lcv2++ )
{
printf( "%02x ", ST011_board[ lcv1*10 + lcv2 + 21 ] );
}
printf( "\n" );
}
printf( "OP01 END\n\n" );
#endif
}
}
void ST011_OP01()
{
ST011_dma_count = 128;
ST011_dma_index = 0+21;
RunST011 = &ST011_OP01_A;
ST011_SR = 0xa4;
}
void ST011_OP02_A()
{
if( ST011_dma_count-- )
{
ST011_DR = ST011_ram[ ST011_dma_index-- ];
}
if( ST011_dma_count == 0 )
{
#ifdef DEBUG_DSP
int lcv1, lcv2;
#endif
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
#ifdef DEBUG_DSP
// Debug
#define OP02_ROW 10
printf( "OP02\n" );
for( lcv1 = 0; lcv1 < 0x83 / OP02_ROW; lcv1++ )
{
for( lcv2 = 0; lcv2 < OP02_ROW; lcv2++ )
{
printf( "%02x ", ST011_ram[ debug1 - lcv1 * OP02_ROW - lcv2 ] );
}
printf( "\n" );
}
printf( "OP02 END\n\n" );
#endif
}
}
void ST011_OP02()
{
switch( ST011_input_length-- )
{
case 4: ST011_dma_index = ST011_DR; break;
case 3: ST011_dma_index |= ST011_DR << 8; break;
case 2: ST011_dma_count = ST011_DR; break;
case 1:
ST011_dma_count |= ST011_DR << 8;
#ifdef DEBUG_DSP
debug1 = ST011_dma_index;
debug2 = 0;
#endif
RunST011 = &ST011_OP02_A;
ST011_SR = 0xa4;
break;
}
}
void ST011_Project_Moves( int color )
{
int row, col, lcv, index;
int dir;
index = 0x121;
for( lcv = 0; lcv < 0x83; lcv++ )
{
ST011_ram[ index-- ] = 0;
}
index = 0x121 - 21;
if( color == 0x20 )
{
dir = 1;
}
else
{
dir = -1;
}
for( row = 0; row < 9; row++ )
{
for( col = 0; col < 10; col++ )
{
int shogi_piece;
int piece_id;
int lcv_steps, lcv_move;
int move_list[ 9*2 ];
shogi_piece = ST011_board[ row*10+col+21 ];
piece_id = shogi_piece & 0x1f;
if( col == 9 ) continue;
if( shogi_piece == 0x00 ) continue;
if( ( shogi_piece & ~0x1f ) != color ) continue;
for( lcv = 0; lcv < 9*2; lcv++ )
{
move_list[ lcv ] = ST011_move_table[ piece_id >> 1 ][ lcv ];
}
lcv_move = 0;
while( move_list[ lcv_move ] != 0x7f )
{
int pos_x, pos_y;
lcv_steps = 1;
if( move_list[ lcv_move ] == 9 || move_list[ lcv_move ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move ] == 9 )
{
move_list[ lcv_move ] = 1;
}
else
{
move_list[ lcv_move ] = -1;
}
}
if( move_list[ lcv_move+1 ] == 9 || move_list[ lcv_move+1 ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move+1 ] == 9 )
{
move_list[ lcv_move+1 ] = 1;
}
else
{
move_list[ lcv_move+1 ] = -1;
}
}
else
{
move_list[ lcv_move+1 ] /= 10;
}
pos_x = col;
pos_y = row;
while( lcv_steps-- )
{
pos_x += move_list[ lcv_move+0 ];
pos_y += ( move_list[ lcv_move+1 ] * dir );
ST011_ram[ index - pos_y*10 - pos_x ] = 0x80;
if( ST011_board[ pos_y*10 + pos_x + 21 ] ) break;
}
lcv_move += 2;
}
} // end col
} // end row
}
int ST011_Project_Valid_Moves( int color )
{
int row, col, lcv, index;
int dir;
index = 0x556;
if( color == 0x20 )
{
dir = 1;
}
else
{
dir = -1;
}
for( row = 0; row < 9; row++ )
{
for( col = 0; col < 10; col++ )
{
int shogi_piece;
int piece_id;
int lcv_steps, lcv_move;
int move_list[ 9*2 ];
shogi_piece = ST011_board[ row*10+col+21 ];
piece_id = shogi_piece & 0x1f;
if( col == 9 ) continue;
if( shogi_piece == 0x00 ) continue;
if( ( shogi_piece & ~0x1f ) != color ) continue;
for( lcv = 0; lcv < 9*2; lcv++ )
{
move_list[ lcv ] = ST011_move_table[ piece_id >> 1 ][ lcv ];
}
lcv_move = 0;
while( move_list[ lcv_move ] != 0x7f )
{
int pos_x, pos_y;
lcv_steps = 1;
if( move_list[ lcv_move ] == 9 || move_list[ lcv_move ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move ] == 9 )
{
move_list[ lcv_move ] = 1;
}
else
{
move_list[ lcv_move ] = -1;
}
}
if( move_list[ lcv_move+1 ] == 9 || move_list[ lcv_move+1 ] == -9 )
{
lcv_steps = 9;
if( move_list[ lcv_move+1 ] == 9 )
{
move_list[ lcv_move+1 ] = 1;
}
else
{
move_list[ lcv_move+1 ] = -1;
}
}
else
{
move_list[ lcv_move+1 ] /= 10;
}
pos_x = col;
pos_y = row;
while( lcv_steps-- )
{
pos_x += move_list[ lcv_move+0 ];
pos_y += ( move_list[ lcv_move+1 ] * dir );
if( pos_x < 0 ) break;
if( pos_x > 8 ) break;
if( pos_y < 0 ) break;
if( pos_y > 8 ) break;
if( ( ST011_board[ pos_y*10 + pos_x + 21 ] & ~0x1f ) == color ) break;
ST011_ram[ index + 0x000 ] = 21 + row*10 + col;
ST011_ram[ index + 0x001 ] = 0;
ST011_ram[ index + 0x418 ] = 21 + pos_y*10 + pos_x;
ST011_ram[ index + 0x419 ] = 0;
if( pos_y >= 6 )
{
ST011_ram[ index + 0x418 ] |= 0x80;
}
index += 2;
if( ST011_board[ pos_y*10+pos_x+21 ] ) break;
}
lcv_move += 2;
}
} // end col
} // end row
return ( index-0x556 ) >> 1;
}
void ST011_OP04()
{
ST011_Project_Moves( 0x40 );
// unknown outputs
ST011_ram[ 0x12c ] = 0;
ST011_ram[ 0x12d ] = 0;
ST011_ram[ 0x12e ] = 0;
ST011_ram[ 0x12f ] = 0;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_OP05()
{
ST011_Project_Moves( 0x20 );
// unknown outputs
ST011_ram[ 0x12c ] = 0;
ST011_ram[ 0x12d ] = 0;
ST011_ram[ 0x12e ] = 0;
ST011_ram[ 0x12f ] = 0;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_OP0E()
{
int valid_moves;
valid_moves = ST011_Project_Valid_Moves( 0x20 );
ST011_ram[ 0x12c ] = valid_moves & 0xff;
ST011_ram[ 0x12d ] = ( valid_moves >> 8 ) & 0xff;
RunST011 = &ST011_Command;
ST011_SR = 0xc4;
}
void ST011_Command()
{
#ifdef DEBUG_DSP
printf( "OP%02X @ line %d\n", ST011_DR, line_count );
#endif
// busy
ST011_SR = 0x84;
switch( ST011_DR )
{
// Download shogi playboard to on-board memory
case 0x01:
ST011_OP01();
break;
// Upload shogi analysis data to outside memory
case 0x02:
ST011_input_length = 4;
RunST011 = ST011_OP02;
break;
// Project all moves of player color $40
case 0x04:
ST011_OP04();
break;
// Project all moves of player color $20
case 0x05:
ST011_OP05();
break;
// Unknown - seems to set flags $00,$20,$40,..$e0 for restricted movement lists
case 0x06:
//ST011_OP06();
ST011_SR = 0xc4;
break;
// Unknown - seems to set flags $00,$20,$40,..$e0 for restricted movement lists
case 0x07:
//ST011_OP07();
ST011_SR = 0xc4;
break;
// List valid moves of player color $20
case 0x0E:
ST011_OP0E();
break;
default:
#ifdef DEBUG_DSP
printf( "Unknown OP @ line %d\n", line_count );
#endif
break;
}
}
unsigned short seta11_address;
unsigned char seta11_byte;
void ST011_MapR_68()
{
if (seta11_address < 0x1000)
{
ST011_DR = ST011_ram[seta11_address & 0xfff];
}
seta11_byte = ST011_DR;
}
void ST011_MapW_68()
{
ST011_DR = seta11_byte;
if (seta11_address < 0x1000)
{
ST011_ram[seta11_address & 0xfff] = ST011_DR;
}
}
void ST011_MapR_60()
{
if (seta11_address == 0)
{
RunST011();
}
if (seta11_address == 1)
{
seta11_byte = ST011_SR;
return;
}
seta11_byte = ST011_DR;
}
void ST011_MapW_60()
{
ST011_DR = seta11_byte;
if (seta11_address == 0)
{
RunST011();
}
}

667
zsnes/src/chips/sfxproc.asm Normal file
View File

@@ -0,0 +1,667 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM SfxB,SfxBRAMR,SfxCBR,SfxCFGR,SfxCLSR,SfxCPB,SfxCROM
EXTSYM SfxCarry,SfxMemTable,SfxOverflow,SfxPBR,SfxPIPE,SfxR0,SfxR1,SfxR10
EXTSYM SfxR11,SfxR12,SfxR13,SfxR14,SfxR15,SfxR2,SfxR3,SfxR4,SfxR5,SfxR6
EXTSYM SfxR7,SfxR8,SfxR9,SfxRAMBR,SfxRAMMem,SfxROMBR,SfxSCBR,SfxSCMR,SfxSFR
EXTSYM SfxSignZero,SfxnRamBanks,regptr,regptw,sfxramdata,ChangeOps
EXTSYM SfxPOR,sfxclineloc,UpdatePORSCMR,UpdateCLSR,UpdateSCBRCOLR,SfxAC
EXTSYM sfx128lineloc,sfx160lineloc,sfx192lineloc,sfxobjlineloc,SFXProc
%include "cpu/regs.mac"
%include "cpu/regsw.mac"
%macro AssembleSFXFlags 0
and word[SfxSFR],8F60h
test byte[SfxCarry],1
jz .nosfxcarry
or word[SfxSFR],04h
.nosfxcarry
cmp word[SfxSignZero],0
jne .nozero
or word[SfxSFR],02h
.nozero
test word[SfxSignZero],8000h
jz .noneg
or word[SfxSFR],08h
.noneg
cmp byte[SfxOverflow],0
je .noof
or word[SfxSFR],10h
.noof
cmp byte[SfxB],0
je .bzero
or word[SfxSFR],1000h
.bzero
%endmacro
SECTION .text
NEWSYM initsfxregsr
setreg 3000h*4,reg3000r
setreg 3001h*4,reg3001r
setreg 3002h*4,reg3002r
setreg 3003h*4,reg3003r
setreg 3004h*4,reg3004r
setreg 3005h*4,reg3005r
setreg 3006h*4,reg3006r
setreg 3007h*4,reg3007r
setreg 3008h*4,reg3008r
setreg 3009h*4,reg3009r
setreg 300Ah*4,reg300Ar
setreg 300Bh*4,reg300Br
setreg 300Ch*4,reg300Cr
setreg 300Dh*4,reg300Dr
setreg 300Eh*4,reg300Er
setreg 300Fh*4,reg300Fr
setreg 3010h*4,reg3010r
setreg 3011h*4,reg3011r
setreg 3012h*4,reg3012r
setreg 3013h*4,reg3013r
setreg 3014h*4,reg3014r
setreg 3015h*4,reg3015r
setreg 3016h*4,reg3016r
setreg 3017h*4,reg3017r
setreg 3018h*4,reg3018r
setreg 3019h*4,reg3019r
setreg 301Ah*4,reg301Ar
setreg 301Bh*4,reg301Br
setreg 301Ch*4,reg301Cr
setreg 301Dh*4,reg301Dr
setreg 301Eh*4,reg301Er
setreg 301Fh*4,reg301Fr
setreg 3030h*4,reg3030r
setreg 3031h*4,reg3031r
setreg 3032h*4,reg3032r
setreg 3033h*4,reg3033r
setreg 3034h*4,reg3034r
setreg 3035h*4,reg3035r
setreg 3036h*4,reg3036r
setreg 3037h*4,reg3037r
setreg 3038h*4,reg3038r
setreg 3039h*4,reg3039r
setreg 303Ah*4,reg303Ar
setreg 303Bh*4,reg303Br
setreg 303Ch*4,reg303Cr
setreg 303Dh*4,reg303Dr
setreg 303Eh*4,reg303Er
setreg 303Fh*4,reg303Fr
; set 3100-31FF to cacheregr
mov edi,3100h*4
add edi,[regptr]
mov eax,cacheregr
mov ecx,200h
.loop
mov [edi],eax
add edi,4
dec ecx
jnz .loop
ret
NEWSYM initsfxregsw
setregw 3000h*4,reg3000w
setregw 3001h*4,reg3001w
setregw 3002h*4,reg3002w
setregw 3003h*4,reg3003w
setregw 3004h*4,reg3004w
setregw 3005h*4,reg3005w
setregw 3006h*4,reg3006w
setregw 3007h*4,reg3007w
setregw 3008h*4,reg3008w
setregw 3009h*4,reg3009w
setregw 300Ah*4,reg300Aw
setregw 300Bh*4,reg300Bw
setregw 300Ch*4,reg300Cw
setregw 300Dh*4,reg300Dw
setregw 300Eh*4,reg300Ew
setregw 300Fh*4,reg300Fw
setregw 3010h*4,reg3010w
setregw 3011h*4,reg3011w
setregw 3012h*4,reg3012w
setregw 3013h*4,reg3013w
setregw 3014h*4,reg3014w
setregw 3015h*4,reg3015w
setregw 3016h*4,reg3016w
setregw 3017h*4,reg3017w
setregw 3018h*4,reg3018w
setregw 3019h*4,reg3019w
setregw 301Ah*4,reg301Aw
setregw 301Bh*4,reg301Bw
setregw 301Ch*4,reg301Cw
setregw 301Dh*4,reg301Dw
setregw 301Eh*4,reg301Ew
setregw 301Fh*4,reg301Fw
setregw 3030h*4,reg3030w
setregw 3031h*4,reg3031w
setregw 3032h*4,reg3032w
setregw 3033h*4,reg3033w
setregw 3034h*4,reg3034w
setregw 3035h*4,reg3035w
setregw 3036h*4,reg3036w
setregw 3037h*4,reg3037w
setregw 3038h*4,reg3038w
setregw 3039h*4,reg3039w
setregw 303Ah*4,reg303Aw
setregw 303Bh*4,reg303Bw
setregw 303Ch*4,reg303Cw
setregw 303Dh*4,reg303Dw
setregw 303Eh*4,reg303Ew
setregw 303Fh*4,reg303Fw
; set 3100-31FF to cacheregw
mov edi,3100h*4
add edi,[regptw]
mov eax,cacheregw
mov ecx,200h
.loop
mov [edi],eax
add edi,4
dec ecx
jnz .loop
ret
NEWSYM cacheregr
or byte[cachewarning],1
ret
NEWSYM cacheregw
or byte[cachewarning],2
ret
SECTION .bss
NEWSYM cachewarning, resb 1
SECTION .text
; SFX Registers
NEWSYM reg3000r
mov al,[SfxR0]
ret
NEWSYM reg3001r
mov al,[SfxR0+1]
ret
NEWSYM reg3002r
mov al,[SfxR1]
ret
NEWSYM reg3003r
mov al,[SfxR1+1]
ret
NEWSYM reg3004r
mov al,[SfxR2]
ret
NEWSYM reg3005r
mov al,[SfxR2+1]
ret
NEWSYM reg3006r
mov al,[SfxR3]
ret
NEWSYM reg3007r
mov al,[SfxR3+1]
ret
NEWSYM reg3008r
mov al,[SfxR4]
ret
NEWSYM reg3009r
mov al,[SfxR4+1]
ret
NEWSYM reg300Ar
mov al,[SfxR5]
ret
NEWSYM reg300Br
mov al,[SfxR5+1]
ret
NEWSYM reg300Cr
mov al,[SfxR6]
ret
NEWSYM reg300Dr
mov al,[SfxR6+1]
ret
NEWSYM reg300Er
mov al,[SfxR7]
ret
NEWSYM reg300Fr
mov al,[SfxR7+1]
ret
NEWSYM reg3010r
mov al,[SfxR8]
ret
NEWSYM reg3011r
mov al,[SfxR8+1]
ret
NEWSYM reg3012r
mov al,[SfxR9]
ret
NEWSYM reg3013r
mov al,[SfxR9+1]
ret
NEWSYM reg3014r
mov al,[SfxR10]
ret
NEWSYM reg3015r
mov al,[SfxR10+1]
ret
NEWSYM reg3016r
mov al,[SfxR11]
ret
NEWSYM reg3017r
mov al,[SfxR11+1]
ret
NEWSYM reg3018r
mov al,[SfxR12]
ret
NEWSYM reg3019r
mov al,[SfxR12+1]
ret
NEWSYM reg301Ar
mov al,[SfxR13]
ret
NEWSYM reg301Br
mov al,[SfxR13+1]
ret
NEWSYM reg301Cr
mov al,[SfxR14]
ret
NEWSYM reg301Dr
mov al,[SfxR14+1]
ret
NEWSYM reg301Er
mov al,[SfxR15]
ret
NEWSYM reg301Fr
mov al,[SfxR15+1]
ret
; Other SFX stuff
NEWSYM reg3030r
AssembleSFXFlags
mov al,[SfxSFR]
ret
NEWSYM reg3031r
cmp byte[SfxAC],1
je .alwaysclear
cmp dword[ChangeOps],-350*240
jl .noclear
.alwaysclear
and byte[SfxSFR+1],07fh ; clear IRQ flag
jmp .cleared
.noclear
cmp dword[ChangeOps],-350*240*4
jge .clear
mov dword[ChangeOps],-350*240*4
jmp .cleared
.clear
add dword[ChangeOps],350*240
.cleared
mov al,[SfxSFR+1]
ret
SECTION .bss
.test resb 1
SECTION .text
NEWSYM reg3032r ; Unused
xor al,al
ret
NEWSYM reg3033r ; BRAMR Backup Ram Read only on/off (bits 1-15 unused)
mov al,[SfxBRAMR]
ret
NEWSYM reg3034r ; PBR (Program Bank)
mov al,[SfxPBR]
ret
NEWSYM reg3035r ; Unused
xor al,al
ret
NEWSYM reg3036r ; ROMBR (Gamepak Rom Bank Register)
mov al,[SfxROMBR]
ret
NEWSYM reg3037r ; CFGR (Control Flags Register)
mov al,[SfxCFGR]
ret
NEWSYM reg3038r ; SCBR (Screen Bank Register)
mov al,[SfxSCBR]
ret
NEWSYM reg3039r ; CLSR (Clock Speed Register)
mov al,[SfxCLSR]
ret
NEWSYM reg303Ar ; SCMR (Screen Mode Register)
mov al,[SfxSCMR]
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
ret
NEWSYM reg303Br ; VCR (Version Code Register)
mov al,20h
ret
NEWSYM reg303Cr ; RAMBR (Ram bank register)
mov al,[SfxRAMBR]
ret
NEWSYM reg303Dr ; Unused
xor al,al
ret
NEWSYM reg303Er ; CBR (Cache Base Register), lower byte
mov al,[SfxCBR]
ret
NEWSYM reg303Fr ; CBR (Cache Base Register), upper byte
mov al,[SfxCBR+1]
ret
; SFX Write Registers
NEWSYM reg3000w
mov [SfxR0],al
ret
NEWSYM reg3001w
mov [SfxR0+1],al
ret
NEWSYM reg3002w
mov [SfxR1],al
ret
NEWSYM reg3003w
mov [SfxR1+1],al
ret
NEWSYM reg3004w
mov [SfxR2],al
ret
NEWSYM reg3005w
mov [SfxR2+1],al
ret
NEWSYM reg3006w
mov [SfxR3],al
ret
NEWSYM reg3007w
mov [SfxR3+1],al
ret
NEWSYM reg3008w
mov [SfxR4],al
ret
NEWSYM reg3009w
mov [SfxR4+1],al
ret
NEWSYM reg300Aw
mov [SfxR5],al
ret
NEWSYM reg300Bw
mov [SfxR5+1],al
ret
NEWSYM reg300Cw
mov [SfxR6],al
ret
NEWSYM reg300Dw
mov [SfxR6+1],al
ret
NEWSYM reg300Ew
mov [SfxR7],al
ret
NEWSYM reg300Fw
mov [SfxR7+1],al
ret
NEWSYM reg3010w
mov [SfxR8],al
ret
NEWSYM reg3011w
mov [SfxR8+1],al
ret
NEWSYM reg3012w
mov [SfxR9],al
ret
NEWSYM reg3013w
mov [SfxR9+1],al
ret
NEWSYM reg3014w
mov [SfxR10],al
ret
NEWSYM reg3015w
mov [SfxR10+1],al
ret
NEWSYM reg3016w
mov [SfxR11],al
ret
NEWSYM reg3017w
mov [SfxR11+1],al
ret
NEWSYM reg3018w
mov [SfxR12],al
ret
NEWSYM reg3019w
mov [SfxR12+1],al
ret
NEWSYM reg301Aw
mov [SfxR13],al
ret
NEWSYM reg301Bw
mov [SfxR13+1],al
ret
NEWSYM reg301Cw
mov [SfxR14],al
ret
NEWSYM reg301Dw
mov [SfxR14+1],al
ret
NEWSYM reg301Ew
mov [SfxR15],al
ret
NEWSYM reg301Fw
mov [SfxR15+1],al
; start execution
push edx
mov edx,[SfxPBR]
mov edx,[SfxMemTable+edx*4]
add edx,[SfxR15]
mov dl,[edx]
mov [SfxPIPE],dl
pop edx
inc word[SfxR15]
or byte[SfxSFR],20h
or dword[SfxSFR],08000h ; Set IRQ Flag
mov dword[SFXProc],1
; call StartSFXret
ret
; Other SFX stuff
NEWSYM reg3030w
mov [SfxSFR],al
mov byte[SfxAC],1
mov dh,10
ret
NEWSYM reg3031w
mov [SfxSFR+1],al
ret
NEWSYM reg3032w ; Unused
ret
NEWSYM reg3033w ; BRAMR Backup Ram Read only on/off (bits 1-15 unused)
and al,0FEh
mov [SfxBRAMR],al
ret
NEWSYM reg3034w ; PBR (Program Bank)
mov [SfxPBR],al
xor ebx,ebx
mov bl,al
mov ebx,[SfxMemTable+ebx*4]
mov [SfxCPB],ebx
ret
NEWSYM reg3035w ; Unused
ret
NEWSYM reg3036w ; ROMBR (Gamepak Rom Bank Register)
mov [SfxROMBR],al
xor ebx,ebx
mov bl,al
mov ebx,[SfxMemTable+ebx*4]
mov [SfxCROM],ebx
ret
NEWSYM reg3037w ; CFGR (Control Flags Register)
mov [SfxCFGR],al
ret
NEWSYM reg3038w ; SCBR (Screen Bank Register)
mov [SfxSCBR],al
call UpdateSCBRCOLR
ret
NEWSYM reg3039w ; CLSR (Clock Speed Register)
and al,0FEh
mov [SfxCLSR],al
call UpdateCLSR
ret
NEWSYM reg303Aw ; SCMR (Screen Mode Register)
mov [SfxSCMR],al
call UpdatePORSCMR
ret
NEWSYM reg303Bw ; VCR (Version Code Register)
ret
NEWSYM reg303Cw ; RAMBR (Ram bank register)
mov bl,[SfxnRamBanks]
dec bl
and al,bl
mov ebx,[SfxnRamBanks]
dec ebx
and eax,ebx
mov [SfxRAMBR],eax
xor ebx,ebx
mov bl,al
shl ebx,16
add ebx,[sfxramdata]
mov [SfxRAMMem],ebx
ret
NEWSYM reg303Dw ; Unused
ret
NEWSYM reg303Ew ; CBR (Cache Base Register), lower byte
mov [SfxCBR],al
ret
NEWSYM reg303Fw ; CBR (Cache Base Register), upper byte
mov [SfxCBR+1],al
ret
NEWSYM sfxaccessbankr8
mov ebx,[sfxramdata]
mov al,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8
mov ebx,[sfxramdata]
mov [ebx+ecx],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16
mov ebx,[sfxramdata]
mov ax,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16
mov ebx,[sfxramdata]
mov [ebx+ecx],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8b
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8b
mov ebx,[sfxramdata]
mov [ebx+ecx+65536],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16b
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16b
mov ebx,[sfxramdata]
mov [ebx+ecx+65536],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8c
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536*2]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8c
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*2],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16c
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536*2]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16c
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*2],ax
xor ebx,ebx
ret
NEWSYM sfxaccessbankr8d
mov ebx,[sfxramdata]
mov al,[ebx+ecx+65536*3]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw8d
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*3],al
xor ebx,ebx
ret
NEWSYM sfxaccessbankr16d
mov ebx,[sfxramdata]
mov ax,[ebx+ecx+65536*3]
xor ebx,ebx
ret
NEWSYM sfxaccessbankw16d
mov ebx,[sfxramdata]
mov [ebx+ecx+65536*3],ax
xor ebx,ebx
ret

View File

@@ -0,0 +1,133 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM setaramdata,ST010DoCommand
SECTION .data
NEWSYM SetaCmdEnable, dd 0 ; Seta ST010/ST011 command enable register. Maybe also status.
SECTION .text
;; TODO - should return ROM for > 8000h
NEWSYM setaaccessbankr8
mov ebx,[setaramdata]
and ecx,0fffh
mov al,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM setaaccessbankw8
test ecx,8000h
jnz .nosetenablew8 ; ignore ROM writes
and ecx,0fffh
mov ebx,[setaramdata]
mov [ebx+ecx],al
cmp byte[ebx+021h], 80h
jnz .nosetenablew8
pushad
call ST010DoCommand
popad
.nosetenablew8
xor ebx,ebx
ret
;; We ignore the case where it wraps into ROM reads - should never happen
NEWSYM setaaccessbankr16
mov ebx,[setaramdata]
and ecx,0fffh
mov ax,[ebx+ecx]
xor ebx,ebx
ret
NEWSYM setaaccessbankw16
test ecx,8000h
jnz .nosetenablew16 ; ignore ROM writes
cmp ecx,7fffh
jne .noromw16
mov [setaramdata+0fffh],al ; only write ram part in, not rom part
jmp short .nosetenablew16
.noromw16
and ecx,0fffh
mov ebx,[setaramdata]
cmp ecx,0fffh
jne .nowrapw16
mov [ebx+ecx],al
xchg ah,al
mov [ebx],al
jmp short .nosetenablew16
.nowrapw16
mov [ebx+ecx],ax
cmp byte[ebx+021h], 80h
jnz .nosetenablew16
pushad
call ST010DoCommand
popad
.nosetenablew16
xor ebx,ebx
ret
NEWSYM setaaccessbankr8a
xor al,al
cmp ecx,4000h
jae .nosetenabler8a
and ecx, 3
mov al,[SetaCmdEnable+ecx]
.nosetenabler8a
xor ebx,ebx
ret
NEWSYM setaaccessbankw8a
cmp ecx,4000h
jae .nosetenablew8a
and ecx, 03h
mov [SetaCmdEnable+ecx],al
.nosetenablew8a
xor ebx,ebx
ret
NEWSYM setaaccessbankr16a
xor ax,ax
cmp ecx,4000h
jae .nosetenabler16a
and ecx,3
mov al,[SetaCmdEnable+ecx]
xchg ah,al
inc ecx
and ecx,3
mov al,[SetaCmdEnable+ecx]
.nosetenabler16a
xor ebx,ebx
ret
NEWSYM setaaccessbankw16a
cmp ecx,4000h
jae .nosetenablew16a
mov ebx,[setaramdata]
and ecx,3
mov [ebx+ecx],al
xchg ah,al
inc ecx
and ecx,3
mov [ebx+ecx],al
.nosetenablew16a
xor ebx,ebx
ret

View File

@@ -0,0 +1,136 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM seta11_address,seta11_byte,setaramdata,ST011_DR
EXTSYM ST011_MapR_60,ST011_MapW_60,ST011_MapW_68;ST011_MapR_68
SECTION .text
NEWSYM Seta11Read8_68
mov ebx,[setaramdata]
and ecx,0fffh
mov al,[ebx+ecx]
mov [ST011_DR],al
xor ebx,ebx
ret
NEWSYM Seta11Write8_68
test ecx,8000h
jnz .nosetenablew8 ; ignore ROM writes
mov [seta11_address],cx
mov [seta11_byte],al
pushad
call ST011_MapW_68
popad
.nosetenablew8
ret
NEWSYM Seta11Read16_68
mov ebx,[setaramdata]
and ecx,0fffh
mov ax,[ebx+ecx]
mov [ST011_DR],ah
xor ebx,ebx
ret
NEWSYM Seta11Write16_68
test ecx,8000h
jnz .nosetenablew16 ; ignore ROM writes
mov [seta11_address],cx
mov [seta11_byte],al
mov [seta11temp],ah
pushad
call ST011_MapW_68
mov ah,[seta11temp]
mov [seta11_byte],ah
inc word[seta11_address]
call ST011_MapW_68
popad
.nosetenablew16
ret
NEWSYM Seta11Read8_60
xor al,al
cmp ecx,4000h
jae .nosetenabler8
and ecx,3
mov [seta11_address],cx
pushad
call ST011_MapR_60
popad
mov al,[seta11_byte]
.nosetenabler8
ret
NEWSYM Seta11Write8_60
cmp ecx,4000h
jae .nosetenablew8
and ecx,3
mov [seta11_address],cx
mov [seta11_byte],al
pushad
call ST011_MapW_60
popad
.nosetenablew8
ret
NEWSYM Seta11Read16_60
xor ax,ax
cmp ecx,4000h
jae .nosetenabler16
and ecx,3
mov [seta11_address],cx
pushad
call ST011_MapR_60
mov al,[seta11_byte]
mov [seta11temp],al
inc word[seta11_address]
and word[seta11_address],3
call ST011_MapR_60
popad
mov al,[seta11temp]
mov ah,[seta11_byte]
.nosetenabler16
ret
NEWSYM Seta11Write16_60
cmp ecx,4000h
jae .nosetenablew16
and ecx,3
mov [seta11_address],cx
mov [seta11_byte],al
mov [seta11temp],ah
pushad
call ST011_MapW_60
mov ah,[seta11temp]
mov [seta11_byte],ah
inc word[seta11_address]
and word[seta11_address],3
call ST011_MapW_60
popad
.nosetenablew16
ret
SECTION .bss
NEWSYM seta11temp, resb 1

1497
zsnes/src/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

8
zsnes/src/config.h.in Normal file
View File

@@ -0,0 +1,8 @@
#undef TIME_WITH_SYS_TIME
#undef HAVE_SYS_TIME_H
#undef HAVE_DIRENT_H
#undef HAVE_SYS_NDIR_H
#undef HAVE_SYS_DIR_H
#undef HAVE_NDIR_H
#undef HAVE_MEMCPY
#undef HAVE_UNISTD_H

1608
zsnes/src/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

7190
zsnes/src/configure vendored Executable file

File diff suppressed because it is too large Load Diff

387
zsnes/src/configure.in Normal file
View File

@@ -0,0 +1,387 @@
dnl - Process this file with autoconf to produce a configure script.
dnl
dnl Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
dnl
dnl http://www.zsnes.com
dnl http://sourceforge.net/projects/zsnes
dnl https://zsnes.bountysource.com
dnl
dnl This program is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU General Public License
dnl version 2 as published by the Free Software Foundation.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
AC_INIT([zsnes], [], [http://www.zsnes.com])
AC_PREREQ(2.50)
AC_CONFIG_SRCDIR(init.asm)
AC_CONFIG_HEADER(config.h)
VERSION=1.51
CFLAGS="$CFLAGS -pipe -I. -I/usr/local/include -I/usr/include"
dnl - You might wanna change -I/usr/include if you're trying to do this with
dnl Mingw, because it doesnt have a standard file tree. Maybe if ming do this
dnl else do -I/usr/include. Or some shit. You figure it out.
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/usr/lib"
dnl - Same thing here.
dnl - Where are our compilers, and who are we compiling for?
AC_CANONICAL_TARGET
AC_PROG_INSTALL
AC_PROG_CC
AC_PROG_CXX
AC_ARG_WITH(nasm-prefix,
[ --with-nasm-prefix=PFX Prefix where nasm is installed (optional)],
nasm_prefix="$withval",
nasm_prefix="")
AC_CHECK_TOOL(NASMPATH,nasm,"no",$nasm_prefix:$PATH)
if test x$NASMPATH = xno; then
AC_MSG_ERROR(You need NASM installed to compile ZSNES)
fi
AC_ARG_WITH(zconf-path,
[ --with-zconf-path=PATH Path where ZSNES looks for zsnesl.cfg (default is .zsnes)],
ZCONF="$withval",
ZCONF="")
CFLAGS="$CFLAGS -D__UNIXSDL__"
NFLAGS="$NFLAGS -w-orphan-labels -D__UNIXSDL__"
PSRFLAGS="$PSRFLAGS -D__UNIXSDL__"
MMLIB_FILES="\$(MMLIB_D)/mm.o"
STRIP="-s"
case x$target in
*-*-linux*)
NFLAGS="$NFLAGS -f elf -DELF"
MMLIB_FILES="$MMLIB_FILES \$(MMLIB_D)/linux.o"
;;
*-*-beos*)
CFLAGS="$CFLAGS -D__BEOS__"
NFLAGS="$NFLAGS -D__BEOS__ -f elf -DELF"
;;
*-*-*bsd*)
CFLAGS="$CFLAGS -D__BSDSDL__"
NFLAGS="$NFLAGS -D__BSDSDL__ -f elf -DELF"
;;
*-*-darwin* )
CFLAGS="$CFLAGS -D__MACOSX__ -D__OPENGL__ -arch i386 -mdynamic-no-pic -mstackrealign -fno-unit-at-a-time"
NFLAGS="$NFLAGS -D__MACOSX__ -D__OPENGL__ -f macho -DMACHO"
PSRFLAGS="$PSRFLAGS -D__OPENGL__"
MMLIB_FILES="$MMLIB_FILES \$(MMLIB_D)/osx.o"
STRIP=""
LDFLAGS="$LDFLAGS -framework Carbon -framework IOKit -framework Foundation -framework OpenGL -mdynamic-no-pic -read_only_relocs suppress -undefined dynamic_lookup"
GL_DRAW="\$(PORT_D)/gl_draw.o"
found_opengl=yes
;;
*-*-cygwin* | *-*-*ming*)
NFLAGS="$NFLAGS -f win32"
;;
*)
AC_MSG_ERROR(This target is not supported)
;;
esac
if test x$ZCONF != x; then
CFLAGS="$CFLAGS -DZCONF=\"\\\"$ZCONF\\\"\""
fi
dnl - Library checks (requisites marked *, others optionnal):
dnl - libSDL*, zlib*, libpng, curses, libao, OpenGL, JMAlib
dnl - libsdl stuff
AM_PATH_SDL(1.2.0,,[AC_MSG_ERROR(SDL >= 1.2.0 is required)])
dnl - zlib stuff
AM_PATH_ZLIB(1.2.3,,[AC_MSG_ERROR(zlib >= 1.2.3 is required)])
CFLAGS="$CFLAGS $ZLIB_CFLAGS"
LDFLAGS="$LDFLAGS $ZLIB_LIBS"
dnl - libpng stuff
AM_PATH_LIBPNG(1.2.0,,)
CFLAGS="$CFLAGS $SDL_CFLAGS"
LDFLAGS="$LDFLAGS $SDL_LIBS"
if test x$with_libpng != xyes; then
CFLAGS="$CFLAGS -DNO_PNG"
NFLAGS="$NFLAGS -DNO_PNG"
PSRFLAGS="$PSRFLAGS -DNO_PNG"
else
CFLAGS="$CFLAGS $LIBPNG_CFLAGS"
LDFLAGS="$LDFLAGS $LIBPNG_LIBS"
fi
dnl - debugger stuff
AC_ARG_ENABLE(debugger,
[ --disable-debugger Build without the zsnes debugger],
,
enable_debugger=yes)
AC_MSG_CHECKING(if you want the zsnes debugger)
AC_MSG_RESULT($enable_debugger)
if test x$enable_debugger != xyes; then
CFLAGS="$CFLAGS -DNO_DEBUGGER"
NFLAGS="$NFLAGS -DNO_DEBUGGER"
PSRFLAGS="$PSRFLAGS -DNO_DEBUGGER"
DEBUGGER_FILES=""
else
DEBUGGER_FILES="debugasm.o debugger.o"
AC_CHECK_LIB(curses, initscr, found_curses=yes,found_curses=no)
AC_CHECK_LIB(ncurses, initscr, found_ncurses=yes,found_ncurses=no)
AC_CHECK_LIB(pdcurses, initscr, found_pdcurses=yes,found_pdcurses=no)
if test x$found_curses = xyes; then
LDFLAGS="$LDFLAGS -lcurses"
else
if test x$found_ncurses = xyes; then
CFLAGS="$CFLAGS -DNCURSES"
LDFLAGS="$LDFLAGS -lncurses"
else
if test x$found_pdcurses = xyes; then
LDFLAGS="$LDFLAGS -lpdcurses"
else
AC_MSG_ERROR(A curses library is required to use the debugger)
DEBUGGER_FILES=""
fi
fi
fi
fi
dnl - libao stuff
AC_ARG_ENABLE(libao,
[ --enable-libao Build with libao support],
want_ao=$enableval,
want_ao=no)
AC_MSG_CHECKING(if you want libao support)
AC_MSG_RESULT($want_ao)
if test x$want_ao = xyes; then
AC_CHECK_LIB(ao, ao_initialize, got_ao=yes, got_ao=no)
if test x$got_ao = xyes; then
CFLAGS="$CFLAGS -D__LIBAO__"
LDFLAGS="$LDFLAGS -lao"
else
AC_MSG_ERROR(Couldn't find libao)
fi
fi
dnl - opengl stuff
if test x$found_opengl != xyes; then
AC_ARG_ENABLE(opengl,
[ --disable-opengl Build without OpenGL support],
,
enable_opengl=yes)
AC_ARG_WITH(
opengl-prefix,
[ --with-opengl-prefix=PFX Prefix where OpenGL is installed (optional)],
opengl_prefix="$withval",
opengl_prefix="")
if test x$enable_opengl != xno; then
AC_PATH_X
if test x$opengl_prefix != x; then
CFLAGS="$CFLAGS -I$opengl_prefix/include"
LDFLAGS-"$LDFLAGS -L$opengl_prefix/lib"
fi
if test x$x_libraries != x; then
LDFLAGS="$LDFLAGS -L$x_libraries"
fi
AC_CHECK_LIB(GL, glGetError, found_opengl=yes,found_opengl=no)
fi
AC_MSG_CHECKING(for OpenGL)
if test x$enable_opengl != xno; then
if test x$found_opengl = xyes; then
LDFLAGS="$LDFLAGS -lGL"
CFLAGS="$CFLAGS -D__OPENGL__"
NFLAGS="$NFLAGS -D__OPENGL__"
PSRFLAGS="$PSRFLAGS -D__OPENGL__"
GL_DRAW="\$(PORT_D)/gl_draw.o"
fi
AC_MSG_RESULT($found_opengl)
else
AC_MSG_RESULT(disabled by user)
fi
fi
dnl - jma stuff
AC_ARG_ENABLE(jma,
[ --disable-jma Build without JMA support],
,
enable_jma=yes)
AC_MSG_CHECKING(for JMA support)
AC_MSG_RESULT($enable_jma)
if test x$enable_jma != xyes; then
CFLAGS="$CFLAGS -DNO_JMA"
NFLAGS="$NFLAGS -DNO_JMA"
PSRFLAGS="$PSRFLAGS -DNO_JMA"
fi
dnl - Various debug and optimization option checks
AM_ARCH_DETECT()
AC_ARG_ENABLE(debug,
[ --enable-debug Build GDB friendly binary (zsnesd)],
debug=$enableval,
debug=no)
AC_MSG_CHECKING(if you want gdb friendly executable)
AC_MSG_RESULT($debug)
if test x$debug = xyes; then
dnl - It is easier to debug zsnes with no optimization enabled.
ZSNESEXE="zsnesd"
PSR_TEMP=""
CFLAGS="$CFLAGS -Wall -W -DDEBUG -O0 -fno-omit-frame-pointer -gstabs3"
NFLAGS="$NFLAGS -DDEBUG -g -F stabs -s -O0"
else
ZSNESEXE="zsnes"
PSR_TEMP=" rm -f t_\$*.c"
CFLAGSBAK="$CFLAGS"
AC_ARG_VAR(force_arch, [Force architecture to optimize GCC/G++ for])
AC_MSG_CHECKING(which cpu architecture to optimize for)
if test x$force_arch != x; then
CFLAGS="$CFLAGS -march=$force_arch"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]])],
[AC_MSG_RESULT(forcing $force_arch)],
[AC_MSG_RESULT($force_arch ??)
AC_MSG_WARN(incorrect force_arch parameter)
force_arch=""
CFLAGS="$CFLAGSBAK"
AC_MSG_CHECKING(for autodetected architecture)])
else
if test x$ARCH_INFO = x; then
case x$target in
i686-*-*)
AC_MSG_RESULT(guessing i686)
CFLAGS="$CFLAGS -march=i686"
;;
i586-*-*)
AC_MSG_RESULT(guessing i586)
CFLAGS="$CFLAGS -march=i586"
;;
i486-*-*)
AC_MSG_RESULT(guessing i486)
CFLAGS="$CFLAGS -march=i486"
;;
*)
AC_MSG_RESULT(guessing i386)
CFLAGS="$CFLAGS -march=i386"
AC_MSG_WARN([This is not what you want, use --target or force-arch])
;;
esac
else
AC_MSG_RESULT($ARCH_INFO)
CFLAGS="$CFLAGS -march=$ARCH_INFO"
fi
fi
AC_ARG_ENABLE(release,
[ --enable-release Build ultra-optimized release binary (zsnes)],
release=$enableval,
release=no)
AC_MSG_CHECKING(if you want crazy optimizations)
AC_MSG_RESULT($release)
if test x$release = xyes; then
if test x$force_arch = x; then
AC_MSG_WARN([If you intend to distribute this binary, make sure you use force_arch and set to i586 (or whichever CPU Arch you intend for)])
fi
CFLAGS="$CFLAGS -O3 -fomit-frame-pointer -fprefetch-loop-arrays -fforce-addr $STRIP -D__RELEASE__"
NFLAGS="$NFLAGS -O99999999 -D__RELEASE__"
else
CFLAGS="$CFLAGS -O3 -fomit-frame-pointer $STRIP"
NFLAGS="$NFLAGS -O1"
fi
fi
CXXFLAGS="$CFLAGS -fno-rtti"
if test x$enable_jma != xno; then
JMA_FILES="\$(JMA_D)/7zlzma.o \$(JMA_D)/crc32.o \$(JMA_D)/iiostrm.o\
\$(JMA_D)/inbyte.o \$(JMA_D)/jma.o \$(JMA_D)/lzma.o\
\$(JMA_D)/lzmadec.o \$(JMA_D)/winout.o \$(JMA_D)/zsnesjma.o"
ZC="$CXX"
ZCFLAGS="$CXXFLAGS"
else
JMA_FILES=""
ZC="$CC"
ZCFLAGS="$CFLAGS"
fi
dnl - Check for header files
AC_HEADER_STDC
AC_HEADER_MAJOR
dnl - Create Makefile
AC_SUBST(VERSION)
AC_SUBST(NASMPATH)
AC_SUBST(ZC)
AC_SUBST(ZCFLAGS)
AC_SUBST(PSRFLAGS)
AC_SUBST(NFLAGS)
AC_SUBST(ZSNESEXE)
AC_SUBST(GL_DRAW)
AC_SUBST(JMA_FILES)
AC_SUBST(MMLIB_FILES)
AC_SUBST(DEBUGGER_FILES)
AC_SUBST(PSR_TEMP)
AC_CONFIG_FILES(Makefile)
touch -t 198001010000 makefile.dep
AC_OUTPUT
dnl - Info output
echo
echo
echo ZSNES v$VERSION
echo
echo "SDL support Version `$SDL_CONFIG --version`"
echo "NASM support `nasm -v`"
echo "zlib support Version $ZLIB_VERSION"
echo $ECHO_N "PNG support $ECHO_C"
if test x$with_libpng = xyes; then
echo "${ECHO_T}Yes, version $LIBPNG_VERSION"
elif test x$enable_libpng = xno; then
echo "${ECHO_T}Disabled by user"
else
echo "${ECHO_T}Disabled, library not found"
fi
echo $ECHO_N "OpenGL support $ECHO_C"
if test x$found_opengl = xyes; then
echo "${ECHO_T}Yes"
elif test x$enable_opengl = xno; then
echo "${ECHO_T}Disabled by user"
else
echo "${ECHO_T}Disabled, library not found"
fi
echo $ECHO_N "JMA support $ECHO_C"
if test x$enable_jma = xno; then
echo "${ECHO_T}Disabled by user"
else
echo "${ECHO_T}Yes"
fi
echo $ECHO_N "ZSNES debugger $ECHO_C"
if test x$enable_debugger = xno; then
echo "${ECHO_T}Disabled"
else
echo "${ECHO_T}Enabled"
fi
echo
echo The binary will be installed in $prefix/bin
echo
echo $ECHO_N "Configure complete, now type '$ECHO_C"
case x$target in
*-*-*bsd*)
echo $ECHO_N "${ECHO_T}g$ECHO_C"
;;
*)
;;
esac
echo "${ECHO_T}make' and pray."
echo

1693
zsnes/src/cpu/65816d.inc Normal file

File diff suppressed because it is too large Load Diff

1707
zsnes/src/cpu/65816dc.inc Normal file

File diff suppressed because it is too large Load Diff

810
zsnes/src/cpu/address.inc Normal file
View File

@@ -0,0 +1,810 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;*******************************************************
; Address Modes
;*******************************************************
; 1. Immediate Addressing -- # - DONE IN PROGRAM
%macro addr_I_8br 0
mov al,[esi]
inc esi
%endmacro
%macro addr_I_16br 0
mov eax,[esi]
add esi,2
%endmacro
; 2. Absolute -- a (TESTED)
%macro addr_a_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_a_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_a_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_a_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtablew16+ebx*4]
%endmacro
; 3. Absolute Long -- al
%macro addr_al_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_al_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_al_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_al_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew16+ebx*4]
%endmacro
; 4. Direct -- d (TESTED)
%macro addr_d_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR8]
%endmacro
%macro addr_d_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
%endmacro
%macro addr_d_8bw 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageW8]
%endmacro
%macro addr_d_16bw 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageW16]
%endmacro
; 5. Accumulator -- A
%macro addr_A_8br 0
mov al,[xa]
%endmacro
%macro addr_A_16br 0
mov eax,[xa]
%endmacro
%macro addr_A_8bw 0
mov [xa],al
%endmacro
%macro addr_A_16bw 0
mov [xa],ax
%endmacro
; 7. Direct Indirect Indexed -- (d),y
%macro addr_BdBCy_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdBCy_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdBCy_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdBCy_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 8. Direct Indirect Indexed Long -- [d],y
%macro addr_LdLCy_8br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdLCy_16br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdLCy_8bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdLCy_16bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
xor bl,bl
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 9. Direct Indexed Indirect -- (d,x)
%macro addr_BdCxB_8br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCxB_16br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCxB_8bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCxB_16bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 10. Direct Indexed With X -- d,x
%macro addr_dCx_8br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r8
%endmacro
%macro addr_dCx_16br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0r16
%endmacro
%macro addr_dCx_8bw 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0w8
%endmacro
%macro addr_dCx_16bw 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xx]
call membank0w16
%endmacro
; 11. Direct Indexed With Y -- d,y
%macro addr_dCy_8br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xy]
call membank0r8
%endmacro
%macro addr_dCy_16br 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xy]
call membank0r16
%endmacro
%macro addr_dCy_8bw 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xy]
call membank0w8
%endmacro
%macro addr_dCy_16bw 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[xy]
call membank0w16
%endmacro
; 12. Absolute Indexed With X -- a,x
%macro addr_aCx_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCx_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCx_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCx_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 13. Absolute Indexed With Y -- a,y
%macro addr_aCy_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCy_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCy_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCy_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 14. Absolute Long Indexed With X -- al,x
%macro addr_alCx_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_alCx_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_alCx_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_alCx_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 18. Direct Indirect -- (d)
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; | 00 | (direct address) |
; + | DB |
; -------------------------------
; Address: | effective address |
%macro addr_BdB_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdB_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdB_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdB_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 19. Direct Indirect Long -- [d]
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; -------------------------------
; Address: | (direct address) |
%macro addr_LdL_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdL_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdL_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdL_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 22. Stack Relative -- d,s
%macro addr_dCs_8br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r8
%endmacro
%macro addr_dCs_16br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
%endmacro
%macro addr_dCs_8bw 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0w8
%endmacro
%macro addr_dCs_16bw 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0w16
%endmacro
; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED)
%macro addr_BdCsBCy_8br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCsBCy_8bw 0
push ax
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16bw 0
push ax
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro

795
zsnes/src/cpu/address2.inc Normal file
View File

@@ -0,0 +1,795 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
EXTSYM DPageR8,DPageR16,DPageW8,DPageW16
;*******************************************************
; Address Modes
;*******************************************************
; 1. Immediate Addressing -- # - DONE IN PROGRAM
%macro addr_I_8br 0
mov al,[esi]
inc esi
%endmacro
%macro addr_I_16br 0
mov eax,[esi]
add esi,2
%endmacro
; 2. Absolute -- a (TESTED)
%macro addr_a_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_a_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_a_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_a_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
call dword near [memtablew16+ebx*4]
%endmacro
; 3. Absolute Long -- al
%macro addr_al_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_al_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_al_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_al_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew16+ebx*4]
%endmacro
; 4. Direct -- d (TESTED)
%macro addr_d_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR8]
%endmacro
%macro addr_d_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
%endmacro
%macro addr_d_8bw 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageW8]
%endmacro
%macro addr_d_16bw 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageW16]
%endmacro
; 5. Accumulator -- A
%macro addr_A_8br 0
mov al,[xa]
%endmacro
%macro addr_A_16br 0
mov eax,[xa]
%endmacro
%macro addr_A_8bw 0
mov [xa],al
%endmacro
%macro addr_A_16bw 0
mov [xa],ax
%endmacro
; 7. Direct Indirect Indexed -- (d),y
%macro addr_BdBCy_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdBCy_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdBCy_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdBCy_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 8. Direct Indirect Indexed Long -- [d],y
%macro addr_LdLCy_8br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdLCy_16br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdLCy_8bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdLCy_16bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
xor bl,bl
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 9. Direct Indexed Indirect -- (d,x)
%macro addr_BdCxB_8br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCxB_16br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCxB_8bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCxB_16bw 0
push ax
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 10. Direct Indexed With X -- d,x
%macro addr_dCx_8br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR8]
%endmacro
%macro addr_dCx_16br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageR16]
%endmacro
%macro addr_dCx_8bw 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageW8]
%endmacro
%macro addr_dCx_16bw 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xx]
call dword near [DPageW16]
%endmacro
; 11. Direct Indexed With Y -- d,y
%macro addr_dCy_8br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xy]
call dword near [DPageR8]
%endmacro
%macro addr_dCy_16br 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xy]
call dword near [DPageR16]
%endmacro
%macro addr_dCy_8bw 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xy]
call dword near [DPageW8]
%endmacro
%macro addr_dCy_16bw 0
mov ecx,[xd]
mov bl,[esi]
inc esi
add cx,[xy]
call dword near [DPageW16]
%endmacro
; 12. Absolute Indexed With X -- a,x
%macro addr_aCx_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCx_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCx_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCx_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 13. Absolute Indexed With Y -- a,y
%macro addr_aCy_8br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCy_16br 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCy_8bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCy_16bw 0
mov cx,[esi]
mov bl,[xdb]
add esi,2
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 14. Absolute Long Indexed With X -- al,x
%macro addr_alCx_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_alCx_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_alCx_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_alCx_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 18. Direct Indirect -- (d)
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; | 00 | (direct address) |
; + | DB |
; -------------------------------
; Address: | effective address |
%macro addr_BdB_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdB_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdB_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdB_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 19. Direct Indirect Long -- [d]
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; -------------------------------
; Address: | (direct address) |
%macro addr_LdL_8br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdL_16br 0
mov bl,[esi]
mov ecx,[xd]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdL_8bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdL_16bw 0
push ax
mov bl,[esi]
mov ecx,[xd]
inc esi
push cx
call dword near [DPageR16]
pop cx
add cx,2
push ax
call dword near [DPageR8]
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 22. Stack Relative -- d,s
%macro addr_dCs_8br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r8
%endmacro
%macro addr_dCs_16br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
%endmacro
%macro addr_dCs_8bw 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0w8
%endmacro
%macro addr_dCs_16bw 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0w16
%endmacro
; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED)
%macro addr_BdCsBCy_8br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16br 0
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCsBCy_8bw 0
push ax
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16bw 0
push ax
mov bl,[esi]
mov cx,[xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
pop ax
add cx,[xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro

408
zsnes/src/cpu/addrni.inc Normal file
View File

@@ -0,0 +1,408 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;*******************************************************
; Address Modes
;*******************************************************
; 1. Immediate Addressing -- # - DONE IN PROGRAM
%macro addr_I_8brni 0
mov al,[esi]
%endmacro
%macro addr_I_16brni 0
mov ax,[esi]
%endmacro
; 2. Absolute -- a (TESTED)
%macro addr_a_8brni 0
mov cx,[esi]
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_a_16brni 0
mov cx,[esi]
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 3. Absolute Long -- al
%macro addr_al_8brni 0
mov cx,[esi]
mov bl,[esi+2]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_al_16brni 0
mov cx,[esi]
mov bl,[esi+2]
call dword near [memtabler16+ebx*4]
%endmacro
; 4. Direct -- d (TESTED)
%macro addr_d_8brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR8]
%endmacro
%macro addr_d_16brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR16]
%endmacro
; 5. Accumulator -- A
%macro addr_A_8brni 0
mov al,[xa]
%endmacro
%macro addr_A_16brni 0
mov ax,[xa]
%endmacro
; 7. Direct Indirect Indexed -- (d),y
%macro addr_BdBCy_8brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdBCy_16brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 8. Direct Indirect Indexed Long -- [d],y
%macro addr_LdLCy_8brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdLCy_16brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 9. Direct Indexed Indirect -- (d,x)
%macro addr_BdCxB_8brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCxB_16brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xx]
call membank0r16
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 10. Direct Indexed With X -- d,x
%macro addr_dCx_8brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xx]
call membank0r8
%endmacro
%macro addr_dCx_16brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xx]
call membank0r16
%endmacro
; 11. Direct Indexed With Y -- d,y
%macro addr_dCy_8brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xy]
call membank0r8
%endmacro
%macro addr_dCy_16brni 0
mov ecx,[xd]
mov bl,[esi]
add cx,bx
add cx,[xy]
call membank0r16
%endmacro
; 12. Absolute Indexed With X -- a,x
%macro addr_aCx_8brni 0
mov cx,[esi]
mov bl,[xdb]
add cx,[xx]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCx_16brni 0
mov cx,[esi]
mov bl,[xdb]
add cx,[xx]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 13. Absolute Indexed With Y -- a,y
%macro addr_aCy_8brni 0
mov cx,[esi]
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCy_16brni 0
mov cx,[esi]
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 14. Absolute Long Indexed With X -- al,x
%macro addr_alCx_8brni 0
mov cx,[esi]
mov bl,[esi+2]
add cx,[xx]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_alCx_16brni 0
mov cx,[esi]
mov bl,[esi+2]
add cx,[xx]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 18. Direct Indirect -- (d)
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; | 00 | (direct address) |
; + | DB |
; -------------------------------
; Address: | effective address |
%macro addr_BdB_8brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdB_16brni 0
mov bl,[esi]
mov ecx,[xd]
call dword near [DPageR16]
mov cx,ax
mov bl,[xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 19. Direct Indirect Long -- [d]
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; -------------------------------
; Address: | (direct address) |
%macro addr_LdL_8brni 0
mov bl,[esi]
mov ecx,[xd]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdL_16brni 0
mov bl,[esi]
mov ecx,[xd]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler16+ebx*4]
%endmacro
; 22. Stack Relative -- d,s
%macro addr_dCs_8brni 0
mov bl,[esi]
mov cx,[xs]
add cx,bx
call membank0r8
%endmacro
%macro addr_dCs_16brni 0
mov bl,[esi]
mov cx,[xs]
add cx,bx
call membank0r16
%endmacro
; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED)
%macro addr_BdCsBCy_8brni 0
mov bl,[esi]
mov cx,[xs]
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16brni 0
mov bl,[esi]
mov cx,[xs]
add cx,bx
call membank0r16
mov cx,ax
mov bl,[xdb]
add cx,[xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro

1310
zsnes/src/cpu/dma.asm Normal file

File diff suppressed because it is too large Load Diff

2836
zsnes/src/cpu/dsp.asm Normal file

File diff suppressed because it is too large Load Diff

5203
zsnes/src/cpu/dspproc.asm Normal file

File diff suppressed because it is too large Load Diff

2001
zsnes/src/cpu/e65816.inc Normal file

File diff suppressed because it is too large Load Diff

1992
zsnes/src/cpu/e65816c.inc Normal file

File diff suppressed because it is too large Load Diff

2206
zsnes/src/cpu/execute.asm Normal file

File diff suppressed because it is too large Load Diff

46
zsnes/src/cpu/executec.c Normal file
View File

@@ -0,0 +1,46 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef __UNIXSDL__
#include "../gblhdr.h"
#define DIR_SLASH "/"
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#define DIR_SLASH "\\"
#endif
#include "../gblvars.h"
//Start of execute.asm goodness
extern unsigned char t1cc; // not sure about this one
extern unsigned short int nextframe; // framecounter for frameskipping
void Game60hzcall()
{
t1cc++;
nextframe++;
}

6171
zsnes/src/cpu/firtable.inc Normal file

File diff suppressed because it is too large Load Diff

553
zsnes/src/cpu/irq.asm Normal file
View File

@@ -0,0 +1,553 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM flagnz,flago,flagc,SfxSCMR,curnmi,execloop,initaddrl,nmiv,snesmap2
EXTSYM snesmmap,stackand,stackor,xe,xirqb,xpb,xpc,xs,irqon,irqv,irqv8
EXTSYM execloopdeb,nmiv8,membank0w8
; NMI Hardware 00FFFA,B 00FFEA,B 3 -> 000108
; RES Hardware 00FFFC.D 00FFFC,D 1
; BRK Software 00FFFE,F 00FFE6,7 N/A
; IRQ Hardware 00FFFE,F 00FFEE,F 4 -> 00010C
%macro makedl 0
and dl,00111100b
test dword[flagnz],18000h
jz %%noneg
or dl,80h
%%noneg
test dword[flagnz],0FFFFh
jnz %%nozero
or dl,02h
%%nozero
test dword[flagc],0FFh
jz %%nocarry
or dl,01h
%%nocarry
test dword[flago],0FFh
jz %%nov
or dl,40h
%%nov
%endmacro
SECTION .text
;*******************************************************
; SwitchToNMI/VIRQ Calls NMI/VIRQ
;*******************************************************
NEWSYM switchtonmi
mov byte[curnmi],1
sub dh,100
test byte[xe],1
jne near NMIemulmode
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
xor ebx,ebx
mov cx,[xs]
mov al,[xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov bl,[xirqb]
mov [xpb],bl
xor eax,eax
mov ax,[nmiv]
test byte[SfxSCMR],10h
jz .nosfxnmi
; mov ax,0108h
.nosfxnmi
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
NEWSYM NMIemulmode
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov [xpb],bh
mov bl,[xpb]
xor eax,eax
mov ax,[nmiv8]
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
NEWSYM switchtovirq
mov byte[irqon],80h
sub dh,3
test byte[xe],1
jne near IRQemulmode
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov bl,[xirqb]
mov [xpb],bl
xor eax,eax
mov ax,[irqv]
test byte[SfxSCMR],10h
jz .nosfxnmi
mov ax,010Ch
.nosfxnmi
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
NEWSYM switchtovirqret
mov byte[irqon],80h
test byte[xe],1
jne near IRQemulmode
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov bl,[xirqb]
mov [xpb],bl
xor eax,eax
mov ax,[irqv]
test byte[SfxSCMR],10h
jz .nosfxnmi
mov ax,010Ch
.nosfxnmi
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
ret
NEWSYM IRQemulmode
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov [xpb],bh
mov bl,[xpb]
xor eax,eax
mov ax,[irqv8]
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloop
NEWSYM switchtovirqdeb
mov byte[irqon],80h
test byte[xe],1
jne near IRQemulmodedeb
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov bl,[xirqb]
mov [xpb],bl
xor eax,eax
mov ax,[irqv]
test byte[SfxSCMR],10h
jz .nosfxnmi
mov ax,010Ch
.nosfxnmi
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
NEWSYM IRQemulmodedeb
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov [xpb],bh
mov bl,[xpb]
xor eax,eax
mov ax,[irqv8]
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
NEWSYM switchtonmideb
mov byte[curnmi],1
test byte[xe],1
jne near NMIemulmodedeb
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpb]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov bl,[xirqb]
mov [xpb],bl
xor eax,eax
mov ax,[nmiv]
test byte[SfxSCMR],10h
jz .nosfxnmi
mov ax,0108h
.nosfxnmi
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
NEWSYM NMIemulmodedeb
mov ebx,esi
sub ebx,[initaddrl]
mov [xpc],bx
mov cx,[xs]
mov al,[xpc+1]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov al,[xpc]
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
makedl
mov al,dl
call membank0w8
dec cx
and cx,word[stackand]
or cx,word[stackor]
mov [xs],cx
xor bh,bh
mov [xpb],bh
mov bl,[xpb]
xor eax,eax
mov ax,[nmiv8]
mov [xpc],ax
and dl,11110011b
or dl,00000100b
test ax,8000h
jz .loweraddr
mov esi,[snesmmap+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb
.loweraddr
mov esi,[snesmap2+ebx*4]
mov [initaddrl],esi
add esi,eax
jmp execloopdeb

2271
zsnes/src/cpu/memory.asm Normal file

File diff suppressed because it is too large Load Diff

365
zsnes/src/cpu/memtable.c Normal file
View File

@@ -0,0 +1,365 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef __UNIXSDL__
#include "../gblhdr.h"
#define DIR_SLASH "/"
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#define DIR_SLASH "\\"
#endif
#include "memtable.h"
#include "../gblvars.h"
extern unsigned int Curtableaddr, tableA[256];
void PrepareOffset()
{
Curtableaddr -= (unsigned int)tableA;
}
void ResetOffset()
{
Curtableaddr += (unsigned int)tableA;
}
extern unsigned int snesmmap[256], snesmap2[256];
void BankSwitchSDD1C (unsigned char bankval, unsigned int offset)
{
unsigned int curbankval = bankval, i;
curbankval &= 7;
curbankval <<= 20;
curbankval += (unsigned int)romdata;
for (i=0; i<16 ; i++)
{
snesmap2[offset+i] = curbankval;
snesmmap[offset+i] = curbankval;
curbankval += 0x10000;
}
}
extern unsigned char SDD1BankA, SDD1BankB, SDD1BankC, SDD1BankD;
void UpdateBanksSDD1()
{
if (SDD1BankA)
{
BankSwitchSDD1C(SDD1BankA, 0x0C0);
BankSwitchSDD1C(SDD1BankB, 0x0D0);
BankSwitchSDD1C(SDD1BankC, 0x0E0);
BankSwitchSDD1C(SDD1BankD, 0x0F0);
}
}
extern void (*Bank0datr8[256])(), (*Bank0datr16[256])(), (*Bank0datw8[256])(), (*Bank0datw16[256])();
extern void *DPageR8, *DPageR16, *DPageW8, *DPageW16;
extern unsigned int xdb, xpb, xs, xx, xy, xd;
extern unsigned short oamaddrt, xat, xst, xdt, xxt, xyt;
extern unsigned char xdbt, xpbt;
void UpdateDPageC()
{
DPageR8 = Bank0datr8[(xd >> 8) & 0xFF];
DPageR16 = Bank0datr16[(xd >> 8) & 0xFF];
DPageW8 = Bank0datw8[(xd >> 8) & 0xFF];
DPageW16 = Bank0datw16[(xd >> 8) & 0xFF];
}
extern unsigned int SA1xd;
extern void *SA1DPageR8, *SA1DPageR16, *SA1DPageW8, *SA1DPageW16;
void SA1UpdateDPageC()
{
SA1DPageR8 = Bank0datr8[(SA1xd >> 8) & 0xFF];
SA1DPageR16 = Bank0datr16[(SA1xd >> 8) & 0xFF];
SA1DPageW8 = Bank0datw8[(SA1xd >> 8) & 0xFF];
SA1DPageW16 = Bank0datw16[(SA1xd >> 8) & 0xFF];
}
void unpackfunct()
{
oamaddrt = (oamaddr & 0xFFFF);
xat = (xa & 0xFFFF);
xdbt = (xdb & 0xFF);
xpbt = (xpb & 0xFF);
xst = (xs & 0xFFFF);
xdt = (xd & 0xFFFF);
xxt = (xx & 0xFFFF);
xyt = (xy & 0xFFFF);
}
#define bit_test(byte, checkbit) (byte & (1 << checkbit)) ? 1 : 0
extern unsigned int GlobalVL, GlobalVR, EchoVL, EchoVR, EchoRate[16], MaxEcho;
extern unsigned int EchoFB, NoiseSpeeds[32], dspPAdj, NoiseInc, bg1ptrx;
extern unsigned int bg1ptry, bg2ptrx, bg2ptry, bg3ptrx, bg3ptry, bg4ptrx;
extern unsigned int bg4ptry;
extern int FIRTAPVal0, FIRTAPVal1, FIRTAPVal2, FIRTAPVal3, FIRTAPVal4;
extern int FIRTAPVal5, FIRTAPVal6, FIRTAPVal7;
extern unsigned short VolumeConvTable[32768], bg1ptr, bg1ptrb, bg1ptrc;
extern unsigned short bg2ptr, bg2ptrb, bg2ptrc, bg3ptr, bg3ptrb, bg3ptrc;
extern unsigned short bg4ptr, bg4ptrb, bg4ptrc;
extern unsigned char VolumeTableb[256], MusicVol, Voice0Status;
extern unsigned char Voice1Status, Voice2Status, Voice3Status, Voice4Status;
extern unsigned char Voice5Status, Voice6Status, Voice7Status, Voice0Noise;
extern unsigned char Voice1Noise, Voice2Noise, Voice3Noise, Voice4Noise;
extern unsigned char Voice5Noise, Voice6Noise, Voice7Noise, bgtilesz;
extern unsigned char BG116x16t, BG216x16t, BG316x16t, BG416x16t, vramincby8on;
extern unsigned char vramincr;
extern void (**regptw)();
void reg2118();
void reg2118inc();
void reg2118inc8();
void reg2118inc8inc();
void reg2119();
void reg2119inc();
void reg2119inc8();
void reg2119inc8inc();
void repackfunct()
{
unsigned char block;
// Global/Echo Volumes
GlobalVL = (VolumeConvTable[(MusicVol << 8) + VolumeTableb[DSPMem[0x0C]]] & 0xFF);
GlobalVR = (VolumeConvTable[(MusicVol << 8) + VolumeTableb[DSPMem[0x1C]]] & 0xFF);
EchoVL = (VolumeConvTable[(MusicVol << 8) + VolumeTableb[DSPMem[0x2C]]] & 0xFF);
EchoVR = (VolumeConvTable[(MusicVol << 8) + VolumeTableb[DSPMem[0x3C]]] & 0xFF);
// Echo Values
MaxEcho = EchoRate[(DSPMem[0x7D] & 0xF)];
EchoFB = VolumeTableb[DSPMem[0x0D]];
// FIR Filter Values
FIRTAPVal0 = (char)DSPMem[0x0F];
FIRTAPVal1 = (char)DSPMem[0x1F];
FIRTAPVal2 = (char)DSPMem[0x2F];
FIRTAPVal3 = (char)DSPMem[0x3F];
FIRTAPVal4 = (char)DSPMem[0x4F];
FIRTAPVal5 = (char)DSPMem[0x5F];
FIRTAPVal6 = (char)DSPMem[0x6F];
FIRTAPVal7 = (char)DSPMem[0x7F];
// Noise
block = DSPMem[0x6C];
DSPMem[0x6C] &= 0x7F;
if (block & 0xC0)
{
Voice0Status = Voice1Status = Voice2Status = Voice3Status = 0;
Voice4Status = Voice5Status = Voice6Status = Voice7Status = 0;
}
NoiseInc = (((NoiseSpeeds[(block & 0x1F)] * dspPAdj) >> 17) & 0xFFFFFFFF);
Voice0Noise = bit_test(DSPMem[0x3D], 0);
Voice1Noise = bit_test(DSPMem[0x3D], 1);
Voice2Noise = bit_test(DSPMem[0x3D], 2);
Voice3Noise = bit_test(DSPMem[0x3D], 3);
Voice4Noise = bit_test(DSPMem[0x3D], 4);
Voice5Noise = bit_test(DSPMem[0x3D], 5);
Voice6Noise = bit_test(DSPMem[0x3D], 6);
Voice7Noise = bit_test(DSPMem[0x3D], 7);
bg1ptrx = bg1ptrb - bg1ptr;
bg1ptry = bg1ptrc - bg1ptr;
bg2ptrx = bg2ptrb - bg2ptr;
bg2ptry = bg2ptrc - bg2ptr;
bg3ptrx = bg3ptrb - bg3ptr;
bg3ptry = bg3ptrc - bg3ptr;
bg4ptrx = bg4ptrb - bg4ptr;
bg4ptry = bg4ptrc - bg4ptr;
// 16x16 tiles
BG116x16t = bit_test(bgtilesz, 0);
BG216x16t = bit_test(bgtilesz, 1);
BG316x16t = bit_test(bgtilesz, 2);
BG416x16t = bit_test(bgtilesz, 3);
oamaddr = oamaddrt;
xa = xat;
xdb = xdbt;
xpb = xpbt;
xs = xst;
xd = xdt;
xx = xxt;
xy = xyt;
if (vramincby8on == 1)
{
if (vramincr == 1)
{
regptw[0x2118] = reg2118inc8inc;
regptw[0x2119] = reg2119inc8;
}
else
{
regptw[0x2118] = reg2118inc8;
regptw[0x2119] = reg2119inc8inc;
}
}
else
{
if (vramincr == 1)
{
regptw[0x2118] = reg2118inc;
regptw[0x2119] = reg2119;
}
else
{
regptw[0x2118] = reg2118;
regptw[0x2119] = reg2119inc;
}
}
}
void regaccessbankr8(), regaccessbankw8(), regaccessbankr16(), regaccessbankw16();
void memaccessbankr8(), memaccessbankw8(), memaccessbankr16(), memaccessbankw16();
void wramaccessbankr8(), wramaccessbankw8(), wramaccessbankr16(), wramaccessbankw16();
void sramaccessbankr8(), sramaccessbankw8(), sramaccessbankr16(), sramaccessbankw16();
void eramaccessbankr8(), eramaccessbankw8(), eramaccessbankr16(), eramaccessbankw16();
void regaccessbankr8SA1(), regaccessbankw8SA1(), regaccessbankr16SA1(), regaccessbankw16SA1();
void SA1RAMaccessbankr8(), SA1RAMaccessbankw8(), SA1RAMaccessbankr16(), SA1RAMaccessbankw16();
void SA1RAMaccessbankr8b(), SA1RAMaccessbankw8b(), SA1RAMaccessbankr16b(), SA1RAMaccessbankw16b();
void sramaccessbankr8s(), sramaccessbankw8s(), sramaccessbankr16s(), sramaccessbankw16s();
void DSP1Read8b3F(), DSP1Write8b3F(), DSP1Read16b3F(), DSP1Write16b3F();
void DSP2Read8b(), DSP2Write8b(), DSP2Read16b(), DSP2Write16b();
void DSP3Read8b(), DSP3Write8b(), DSP3Read16b(), DSP3Write16b();
void DSP4Read8b(), DSP4Write8b(), DSP4Read16b(), DSP4Write16b();
void setaaccessbankr8(), setaaccessbankw8(), setaaccessbankr16(), setaaccessbankw16();
void setaaccessbankr8a(), setaaccessbankw8a(), setaaccessbankr16a(), setaaccessbankw16a();
void Seta11Read8_60(), Seta11Write8_60(), Seta11Read16_60(), Seta11Write16_60();
void Seta11Read8_68(), Seta11Write8_68(), Seta11Read16_68(), Seta11Write16_68();
void sfxaccessbankr8(), sfxaccessbankw8(), sfxaccessbankr16(), sfxaccessbankw16();
void sfxaccessbankr8b(), sfxaccessbankw8b(), sfxaccessbankr16b(), sfxaccessbankw16b();
void sfxaccessbankr8c(), sfxaccessbankw8c(), sfxaccessbankr16c(), sfxaccessbankw16c();
void sfxaccessbankr8d(), sfxaccessbankw8d(), sfxaccessbankr16d(), sfxaccessbankw16d();
void OBC1Read8b(), OBC1Write8b(), OBC1Read16b(), OBC1Write16b();
void C4Read8b(), C4Write8b(), C4Read16b(), C4Write16b();
void memaccessspc7110r8(), memaccessspc7110r16(), memaccessspc7110w8(), memaccessspc7110w16();
void SPC7110ReadSRAM8b(), SPC7110ReadSRAM16b(), SPC7110WriteSRAM8b(), SPC7110WriteSRAM16b();
void stsramr8(), stsramr16(), stsramw8(), stsramw16();
void stsramr8b(), stsramr16b(), stsramw8b(), stsramw16b();
mrwp regbank = { regaccessbankr8, regaccessbankw8, regaccessbankr16, regaccessbankw16 };
mrwp membank = { memaccessbankr8, memaccessbankw8, memaccessbankr16, memaccessbankw16 };
mrwp wrambank = { wramaccessbankr8, wramaccessbankw8, wramaccessbankr16, wramaccessbankw16 };
mrwp srambank = { sramaccessbankr8, sramaccessbankw8, sramaccessbankr16, sramaccessbankw16 };
mrwp erambank = { eramaccessbankr8, eramaccessbankw8, eramaccessbankr16, eramaccessbankw16 };
mrwp sa1regbank = { regaccessbankr8SA1, regaccessbankw8SA1, regaccessbankr16SA1, regaccessbankw16SA1 };
mrwp sa1rambank = { SA1RAMaccessbankr8, SA1RAMaccessbankw8, SA1RAMaccessbankr16, SA1RAMaccessbankw16 };
mrwp sa1rambankb = { SA1RAMaccessbankr8b, SA1RAMaccessbankw8b, SA1RAMaccessbankr16b, SA1RAMaccessbankw16b };
mrwp sramsbank = { sramaccessbankr8s, sramaccessbankw8s, sramaccessbankr16s, sramaccessbankw16s };
mrwp dsp1bank = { DSP1Read8b3F, DSP1Write8b3F, DSP1Read16b3F, DSP1Write16b3F };
mrwp dsp2bank = { DSP2Read8b, DSP2Write8b, DSP2Read16b, DSP2Write16b };
mrwp dsp3bank = { DSP3Read8b, DSP3Write8b, DSP3Read16b, DSP3Write16b };
mrwp dsp4bank = { DSP4Read8b, DSP4Write8b, DSP4Read16b, DSP4Write16b };
mrwp setabank = { setaaccessbankr8, setaaccessbankw8, setaaccessbankr16, setaaccessbankw16 };
mrwp setabanka = { setaaccessbankr8a, setaaccessbankw8a, setaaccessbankr16a, setaaccessbankw16a };
mrwp seta11bank = { Seta11Read8_68, Seta11Write8_68, Seta11Read16_68, Seta11Write16_68 };
mrwp seta11banka = { Seta11Read8_60, Seta11Write8_60, Seta11Read16_60, Seta11Write16_60 };
mrwp sfxbank = { sfxaccessbankr8, sfxaccessbankw8, sfxaccessbankr16, sfxaccessbankw16 };
mrwp sfxbankb = { sfxaccessbankr8b, sfxaccessbankw8b, sfxaccessbankr16b, sfxaccessbankw16b };
mrwp sfxbankc = { sfxaccessbankr8c, sfxaccessbankw8c, sfxaccessbankr16c, sfxaccessbankw16c };
mrwp sfxbankd = { sfxaccessbankr8d, sfxaccessbankw8d, sfxaccessbankr16d, sfxaccessbankw16d };
mrwp obc1bank = { OBC1Read8b, OBC1Write8b, OBC1Read16b, OBC1Write16b };
mrwp c4bank = { C4Read8b, C4Write8b, C4Read16b, C4Write16b };
mrwp SPC7110bank = { memaccessspc7110r8, memaccessspc7110w8, memaccessspc7110r16, memaccessspc7110w16 };
mrwp SPC7110SRAMBank = { SPC7110ReadSRAM8b, SPC7110WriteSRAM8b, SPC7110ReadSRAM16b, SPC7110WriteSRAM16b };
mrwp stbanka = { stsramr8, stsramw8, stsramr16, stsramw16 };
mrwp stbankb = { stsramr8b, stsramw8b, stsramr16b, stsramw16b };
void SetAddressingModes()
{ // Banks
map_mem(0x00, &regbank, 0x40); // 00 - 3F
map_mem(0x40, &membank, 0x3E); // 40 - 7D
map_mem(0x7E, &wrambank, 0x01); // 7E
map_mem(0x7F, &erambank, 0x01); // 7F
map_mem(0x80, &regbank, 0x40); // 80 - BF
map_mem(0xC0, &membank, 0x40); // C0 - FF
}
void SetAddressingModesSA1()
{
map_mem(0x00, &sa1regbank, 0x40); // 00 - 3F
map_mem(0x40, &sa1rambank, 0x20); // 40 - 5F
map_mem(0x60, &sa1rambankb, 0x10); // 60 - 6F
map_mem(0x70, &srambank, 0x08); // 70 - 77
map_mem(0x78, &membank, 0x06); // 78 - 7D
map_mem(0x7E, &wrambank, 0x01); // 7E
map_mem(0x7F, &erambank, 0x01); // 7F
map_mem(0x80, &sa1regbank, 0x40); // 80 - BF
map_mem(0xC0, &membank, 0x40); // C0 - FF
}
void membank0r8reg(), membank0w8reg(), membank0r16reg(), membank0w16reg();
void membank0r8ram(), membank0w8ram(), membank0r16ram(), membank0w16ram();
void membank0r8rom(), membank0w8rom(), membank0r16rom(), membank0w16rom();
void membank0r8romram(), membank0w8romram(), membank0r16romram(), membank0w16romram();
void membank0r8inv(), membank0w8inv(), membank0r16inv(), membank0w16inv();
void membank0r8chip(), membank0w8chip(), membank0r16chip(), membank0w16chip();
void membank0r8ramSA1(), membank0w8ramSA1(), membank0r16ramSA1(), membank0w16ramSA1();
mrwp regbank0 = { membank0r8reg, membank0w8reg, membank0r16reg, membank0w16reg };
mrwp rambank0 = { membank0r8ram, membank0w8ram, membank0r16ram, membank0w16ram };
mrwp rombank0 = { membank0r8rom, membank0w8rom, membank0r16rom, membank0w16rom };
mrwp romrambank0 = { membank0r8romram, membank0w8romram, membank0r16romram, membank0w16romram };
mrwp invbank0 = { membank0r8inv, membank0w8inv, membank0r16inv, membank0w16inv };
mrwp chipbank0 = { membank0r8chip, membank0w8chip, membank0r16chip, membank0w16chip };
mrwp sa1rambank0 = { membank0r8ramSA1, membank0w8ramSA1, membank0r16ramSA1, membank0w16ramSA1 };
static void map_bank0(size_t dest, mrwp *src, size_t num)
{
rep_stosd(Bank0datr8+dest, src->memr8, num);
rep_stosd(Bank0datw8+dest, src->memw8, num);
rep_stosd(Bank0datr16+dest, src->memr16, num);
rep_stosd(Bank0datw16+dest, src->memw16, num);
}
void GenerateBank0Table()
{
map_bank0(0x00, &rambank0, 0x20); // 00 - 1F
map_bank0(0x20, &regbank0, 0x28); // 20 - 47
map_bank0(0x48, &invbank0, 0x17); // 48 - 5E
map_bank0(0x5F, &chipbank0, 0x1F); // 5F - 7D
map_bank0(0x7E, &rombank0, 0x81); // 7E - FE
map_bank0(0xFF, &romrambank0, 0x01); // FF
}
void GenerateBank0TableSA1()
{
map_bank0(0x00, &sa1rambank0, 0x20); // 00 - 1F
}

66
zsnes/src/cpu/memtable.h Normal file
View File

@@ -0,0 +1,66 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef MEMTABLE_H
#define MEMTABLE_H
extern void (*memtabler8[256])();
extern void (*memtablew8[256])();
extern void (*memtabler16[256])();
extern void (*memtablew16[256])();
typedef struct
{
void (*memr8)();
void (*memw8)();
void (*memr16)();
void (*memw16)();
} mrwp;
extern mrwp regbank, membank, wrambank, srambank, erambank, sramsbank;
extern mrwp sa1regbank, sa1rambank, sa1rambankb;
extern mrwp dsp1bank, dsp2bank, dsp3bank, dsp4bank;
extern mrwp setabank, setabanka, seta11bank, seta11banka;
extern mrwp sfxbank, sfxbankb, sfxbankc, sfxbankd;
extern mrwp obc1bank, c4bank, SPC7110bank, SPC7110SRAMBank;
extern mrwp stbanka, stbankb;
/*
rep_stosd is my name for a 'copy <num> times a function pointer <func_ptr> into
a function pointer array <dest>' function, in honour of the almighty asm
instruction rep stosd, which is able to do that (and much more).
Since ZSNES is just full of func pointer arrays, it'll probably come in handy.
*/
static void rep_stosd(void (**dest)(), void (*func_ptr), size_t num)
{
while (num--) { dest[num] = func_ptr; }
}
static void map_mem(size_t dest, mrwp *src, size_t num)
{
rep_stosd(memtabler8+dest, src->memr8, num);
rep_stosd(memtablew8+dest, src->memw8, num);
rep_stosd(memtabler16+dest, src->memr16, num);
rep_stosd(memtablew16+dest, src->memw16, num);
}
#endif

1260
zsnes/src/cpu/regs.inc Normal file

File diff suppressed because it is too large Load Diff

57
zsnes/src/cpu/regs.mac Normal file
View File

@@ -0,0 +1,57 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;*******************************************************
; InitReg Initializes Registers
;*******************************************************
%macro setreg 2
mov edi,%1
add edi,[regptr]
mov eax,%2
mov [edi],eax
%endmacro
;*******************************************************
; Registers Note : Remember to restore AH, ECX, & DX
;*******************************************************
%macro checkmultchange 0
; execute multiplication
cmp byte[multchange],0
je .nomult
push edx
push eax
xor bh,bh
mov bl,[mode7B+1]
mov ax,[mode7A]
test bl,80h
jz .noneg
mov bh,0FFh
.noneg
imul bx
mov [compmult],ax
mov [compmult+2],dl
pop eax
pop edx
mov byte[multchange],0
.nomult
%endmacro

1682
zsnes/src/cpu/regsw.inc Normal file

File diff suppressed because it is too large Load Diff

46
zsnes/src/cpu/regsw.mac Normal file
View File

@@ -0,0 +1,46 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;*******************************************************
; InitRegW Initializes Write Registers
;*******************************************************
%macro reenablespc 0
cmp dword[cycpbl],1000000h
jb %%enspc
mov dword[cycpbl],0
test byte[curexecstate],02h
jnz %%enspc
or byte[curexecstate],02h
push ebx
xor ebx,ebx
mov bl,dl
mov edi,[tableadc+ebx*4]
pop ebx
%%enspc
%endmacro
%macro setregw 2
mov edi,%1
add edi,[regptw]
mov eax,%2
mov [edi],eax
%endmacro

1574
zsnes/src/cpu/s65816d.inc Normal file

File diff suppressed because it is too large Load Diff

811
zsnes/src/cpu/saddress.inc Normal file
View File

@@ -0,0 +1,811 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
EXTSYM SA1DPageR8,SA1DPageR16,SA1DPageW8,SA1DPageW16
;*******************************************************
; Address Modes
;*******************************************************
; 1. Immediate Addressing -- # - DONE IN PROGRAM
%macro addr_I_8br 0
mov al,[esi]
inc esi
%endmacro
%macro addr_I_16br 0
mov eax,[esi]
add esi,2
%endmacro
; 2. Absolute -- a (TESTED)
%macro addr_a_8br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_a_16br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_a_8bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_a_16bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
call dword near [memtablew16+ebx*4]
%endmacro
; 3. Absolute Long -- al
%macro addr_al_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_al_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_al_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_al_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
call dword near [memtablew16+ebx*4]
%endmacro
; 4. Direct -- d (TESTED)
%macro addr_d_8br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR8]
%endmacro
%macro addr_d_16br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
%endmacro
%macro addr_d_8bw 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageW8]
%endmacro
%macro addr_d_16bw 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageW16]
%endmacro
; 5. Accumulator -- A
%macro addr_A_8br 0
mov al,[SA1xa]
%endmacro
%macro addr_A_16br 0
mov eax,[SA1xa]
%endmacro
%macro addr_A_8bw 0
mov [SA1xa],al
%endmacro
%macro addr_A_16bw 0
mov [SA1xa],ax
%endmacro
; 7. Direct Indirect Indexed -- (d),y
%macro addr_BdBCy_8br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdBCy_16br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdBCy_8bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdBCy_16bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 8. Direct Indirect Indexed Long -- [d],y
%macro addr_LdLCy_8br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdLCy_16br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdLCy_8bw 0
push ax
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdLCy_16bw 0
push ax
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
push cx
call membank0r16
pop cx
add cx,2
xor bl,bl
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
pop ax
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 9. Direct Indexed Indirect -- (d,x)
%macro addr_BdCxB_8br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCxB_16br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCxB_8bw 0
push ax
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCxB_16bw 0
push ax
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 10. Direct Indexed With X -- d,x
%macro addr_dCx_8br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r8
%endmacro
%macro addr_dCx_16br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0r16
%endmacro
%macro addr_dCx_8bw 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0w8
%endmacro
%macro addr_dCx_16bw 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xx]
call membank0w16
%endmacro
; 11. Direct Indexed With Y -- d,y
%macro addr_dCy_8br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xy]
call membank0r8
%endmacro
%macro addr_dCy_16br 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xy]
call membank0r16
%endmacro
%macro addr_dCy_8bw 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xy]
call membank0w8
%endmacro
%macro addr_dCy_16bw 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
inc esi
add cx,[SA1xy]
call membank0w16
%endmacro
; 12. Absolute Indexed With X -- a,x
%macro addr_aCx_8br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCx_16br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCx_8bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCx_16bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 13. Absolute Indexed With Y -- a,y
%macro addr_aCy_8br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCy_16br 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_aCy_8bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_aCy_16bw 0
mov cx,[esi]
mov bl,[SA1xdb]
add esi,2
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 14. Absolute Long Indexed With X -- al,x
%macro addr_alCx_8br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_alCx_16br 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_alCx_8bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_alCx_16bw 0
mov cx,[esi]
mov bl,[esi+2]
add esi,3
add cx,[SA1xx]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro
; 18. Direct Indirect -- (d)
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; | 00 | (direct address) |
; + | DB |
; -------------------------------
; Address: | effective address |
%macro addr_BdB_8br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdB_16br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdB_8bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdB_16bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 19. Direct Indirect Long -- [d]
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; -------------------------------
; Address: | (direct address) |
%macro addr_LdL_8br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdL_16br 0
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_LdL_8bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_LdL_16bw 0
push ax
mov bl,[esi]
mov ecx,[SA1xd]
inc esi
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
pop ax
call dword near [memtablew16+ebx*4]
%endmacro
; 22. Stack Relative -- d,s
%macro addr_dCs_8br 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r8
%endmacro
%macro addr_dCs_16br 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r16
%endmacro
%macro addr_dCs_8bw 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0w8
%endmacro
%macro addr_dCs_16bw 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0w16
%endmacro
; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED)
%macro addr_BdCsBCy_8br 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16br 0
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtabler16+ebx*4]
%endmacro
%macro addr_BdCsBCy_8bw 0
push ax
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
pop ax
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtablew8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16bw 0
push ax
mov bl,[esi]
mov cx,[SA1xs]
inc esi
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
pop ax
add cx,[SA1xy]
jnc .np
inc bl
.np
call dword near [memtablew16+ebx*4]
%endmacro

407
zsnes/src/cpu/saddrni.inc Normal file
View File

@@ -0,0 +1,407 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;*******************************************************
; Address Modes
;*******************************************************
; 1. Immediate Addressing -- # - DONE IN PROGRAM
%macro addr_I_8brni 0
mov al,[esi]
%endmacro
%macro addr_I_16brni 0
mov ax,[esi]
%endmacro
; 2. Absolute -- a (TESTED)
%macro addr_a_8brni 0
mov cx,[esi]
mov bl,[SA1xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_a_16brni 0
mov cx,[esi]
mov bl,[SA1xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 3. Absolute Long -- al
%macro addr_al_8brni 0
mov cx,[esi]
mov bl,[esi+2]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_al_16brni 0
mov cx,[esi]
mov bl,[esi+2]
call dword near [memtabler16+ebx*4]
%endmacro
; 4. Direct -- d (TESTED)
%macro addr_d_8brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR8]
%endmacro
%macro addr_d_16brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR16]
%endmacro
; 5. Accumulator -- A
%macro addr_A_8brni 0
mov al,[SA1xa]
%endmacro
%macro addr_A_16brni 0
mov ax,[SA1xa]
%endmacro
; 7. Direct Indirect Indexed -- (d),y
%macro addr_BdBCy_8brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdBCy_16brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 8. Direct Indirect Indexed Long -- [d],y
%macro addr_LdLCy_8brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdLCy_16brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 9. Direct Indexed Indirect -- (d,x)
%macro addr_BdCxB_8brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCxB_16brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xx]
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 10. Direct Indexed With X -- d,x
%macro addr_dCx_8brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xx]
call membank0r8
%endmacro
%macro addr_dCx_16brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xx]
call membank0r16
%endmacro
; 11. Direct Indexed With Y -- d,y
%macro addr_dCy_8brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xy]
call membank0r8
%endmacro
%macro addr_dCy_16brni 0
mov ecx,[SA1xd]
mov bl,[esi]
add cx,bx
add cx,[SA1xy]
call membank0r16
%endmacro
; 12. Absolute Indexed With X -- a,x
%macro addr_aCx_8brni 0
mov cx,[esi]
mov bl,[SA1xdb]
add cx,[SA1xx]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCx_16brni 0
mov cx,[esi]
mov bl,[SA1xdb]
add cx,[SA1xx]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 13. Absolute Indexed With Y -- a,y
%macro addr_aCy_8brni 0
mov cx,[esi]
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_aCy_16brni 0
mov cx,[esi]
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 14. Absolute Long Indexed With X -- al,x
%macro addr_alCx_8brni 0
mov cx,[esi]
mov bl,[esi+2]
add cx,[SA1xx]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_alCx_16brni 0
mov cx,[esi]
mov bl,[esi+2]
add cx,[SA1xx]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro
; 18. Direct Indirect -- (d)
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; | 00 | (direct address) |
; + | DB |
; -------------------------------
; Address: | effective address |
%macro addr_BdB_8brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdB_16brni 0
mov bl,[esi]
mov ecx,[SA1xd]
call dword near [SA1DPageR16]
mov cx,ax
mov bl,[SA1xdb]
call dword near [memtabler16+ebx*4]
%endmacro
; 19. Direct Indirect Long -- [d]
; ___________________
; Instruction: | opcode | offset |
; ~~~~~~~~~~~~~~~~~~~
; | Direct Register |
; + | offset |
; ---------------------
; | 00 | direct address |
; then:
; -------------------------------
; Address: | (direct address) |
%macro addr_LdL_8brni 0
mov bl,[esi]
mov ecx,[SA1xd]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_LdL_16brni 0
mov bl,[esi]
mov ecx,[SA1xd]
add cx,bx
push cx
call membank0r16
pop cx
add cx,2
push ax
call membank0r8
mov bl,al
pop ax
mov cx,ax
call dword near [memtabler16+ebx*4]
%endmacro
; 22. Stack Relative -- d,s
%macro addr_dCs_8brni 0
mov bl,[esi]
mov cx,[SA1xs]
add cx,bx
call membank0r8
%endmacro
%macro addr_dCs_16brni 0
mov bl,[esi]
mov cx,[SA1xs]
add cx,bx
call membank0r16
%endmacro
; 23. Stack Relative Indirect Indexed -- (d,s),y (TESTED)
%macro addr_BdCsBCy_8brni 0
mov bl,[esi]
mov cx,[SA1xs]
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler8+ebx*4]
%endmacro
%macro addr_BdCsBCy_16brni 0
mov bl,[esi]
mov cx,[SA1xs]
add cx,bx
call membank0r16
mov cx,ax
mov bl,[SA1xdb]
add cx,[SA1xy]
jnc .npb
inc bl
.npb
call dword near [memtabler16+ebx*4]
%endmacro

2027
zsnes/src/cpu/se65816.inc Normal file

File diff suppressed because it is too large Load Diff

2649
zsnes/src/cpu/spc700.asm Normal file

File diff suppressed because it is too large Load Diff

92
zsnes/src/cpu/spcaddr.inc Normal file
View File

@@ -0,0 +1,92 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; A,DP addressing mode
%macro SPCaddr_DP 0
mov bl,[ebp]
add ebx,[spcRamDP]
inc ebp
ReadByte
%endmacro
%macro SPCaddr_DP_X 0
mov bl,[ebp]
add bl,[spcX]
add ebx,[spcRamDP]
inc ebp
ReadByte
%endmacro
%macro SPCaddr_LABS 0
mov bx,[ebp]
add ebx,SPCRAM
ReadByte
add ebp,2
%endmacro
%macro SPCaddr_LABS_X 0
mov bl,[spcX]
add bx,[ebp]
add ebp,2
add ebx,SPCRAM
ReadByte
%endmacro
; A,(X)
%macro SPCaddr__X_ 0
mov bl,[spcX]
add ebx,[spcRamDP]
ReadByte
%endmacro
; A,labs+Y
%macro SPCaddr_LABS_Y 0
mov bl,[spcY]
add bx,[ebp]
add ebp,2
add ebx,SPCRAM
ReadByte
%endmacro
; A,(DP,X)
%macro SPCaddr_bDP_Xb 0
mov bl,[ebp]
add bl,[spcX]
xor eax,eax
add ebx,[spcRamDP]
inc ebp
mov ax, [ebx]
mov ebx,eax
add ebx,SPCRAM
ReadByte
%endmacro
%macro SPCaddr_bDPb_Y 0
mov bl,[ebp]
xor eax,eax
add ebx,[spcRamDP]
inc ebp
mov ax,[ebx]
add ax,[spcY]
mov ebx,eax
add ebx,SPCRAM
ReadByte
%endmacro

164
zsnes/src/cpu/spcdef.inc Normal file
View File

@@ -0,0 +1,164 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; move al at address ebx
; branch instructions
%macro spcbrancher 0
inc ebp
ret
.branch
movsx ebx,byte[ebp]
inc ebp
add ebp,ebx
ret
%endmacro
; tcall instruction
%macro spctcall 1
mov ebx,ebp
sub ebx,SPCRAM
mov eax,[spcS]
mov [SPCRAM+eax],bh
dec byte[spcS]
mov eax,[spcS]
mov [SPCRAM+eax],bl
dec byte[spcS]
mov bx,[spcextraram+%1]
test byte[SPCRAM+0F1h],80h
jnz %%finished
mov bx,[SPCRAM+0FFC0h+%1]
%%finished
add ebx,SPCRAM
mov ebp,ebx
ret
%endmacro
; SET1 instruction
%macro set1 1
mov bl,[ebp]
add ebx,[spcRamDP]
inc ebp
push ebx
ReadByte
pop ebx
or al,%1
WriteByte
ret
%endmacro
; CLR1 instruction
%macro clr1 1
mov bl,[ebp]
add ebx,[spcRamDP]
inc ebp
push ebx
ReadByte
pop ebx
and al,%1
WriteByte
ret
%endmacro
; BBS instruction
%macro bbs 1
mov bl,[ebp]
add ebx,[spcRamDP]
ReadByte
test al,%1
jnz .dp0jump
add ebp,2
ret
.dp0jump
movsx ebx,byte[ebp+1]
add ebp,ebx
add ebp,2
ret
%endmacro
; BBC instruction
%macro bbc 1
mov bl,[ebp]
add ebx,[spcRamDP]
ReadByte
test al,%1
jz .dp0jump
add ebp,2
ret
.dp0jump
movsx ebx,byte[ebp+1]
add ebp,ebx
add ebp,2
ret
%endmacro
; OR A, instruction
%macro SPC_OR_A 0
or byte[spcA], al
mov al,[spcA]
mov [spcNZ],al
ret
%endmacro
; AND A, instruction
%macro SPC_AND_A 0
and byte[spcA], al
mov al,[spcA]
mov [spcNZ],al
ret
%endmacro
; EOR A, instruction
%macro SPC_EOR_A 0
xor byte[spcA], al
mov al,[spcA]
mov [spcNZ],al
ret
%endmacro
; CMP A, instruction
%macro SPC_CMP_A 0
cmp byte[spcA], al
cmc
SPCSetFlagnzc
%endmacro
%macro SPC_ADC_A 0
mov cl,[spcP]
shr cl,1
adc byte[spcA], al
SPCSetFlagnvhzc
%endmacro
%macro SPC_SBC_A 0
mov cl,[spcP]
xor cl,1
shr cl,1
sbb byte[spcA], al
cmc
SPCSetFlagnvhzc
%endmacro
%macro SPC_MOV_A 0
mov [spcA], al
mov [spcNZ],al
ret
%endmacro

698
zsnes/src/cpu/stable.asm Normal file
View File

@@ -0,0 +1,698 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM SA1tableA,SA1tableB,SA1tableC,SA1tableD,SA1tableE
EXTSYM SA1tableF,SA1tableG,SA1tableH,SA1tablead
EXTSYM cpucycle,SA1UpdateDPage,intrset
%include "cpu/s65816d.inc"
%include "cpu/saddress.inc"
%include "cpu/saddrni.inc"
%include "cpu/se65816.inc"
; global variables
;tableA times 256 ; Table addresses (M:0,X:0,D:0)
;tableB times 256 ; Table addresses (M:1,X:0,D:0)
;tableC times 256 ; Table addresses (M:0,X:1,D:0)
;tableD times 256 ; Table addresses (M:1,X:1,D:0)
;tableE times 256 ; Table addresses (M:0,X:0,D:1)
;tableF times 256 ; Table addresses (M:1,X:0,D:1)
;tableG times 256 ; Table addresses (M:0,X:1,D:1)
;tableH times 256 ; Table addresses (M:1,X:1,D:1)
;tablead times 256 ; Table address location according to P
;memtabler8 times 256 ; Memory Bank Locations for reading 8-bit
;memtablew8 times 256 ; Memory Bank Locations for writing 8-bit
;memtabler16 times 256 ; Memory Bank Locations for reading 16-bit
;memtablew16 times 256 ; Memory Bank Locations for reading 16-bit
;*******************************************************
; Generate OpCode Table
;*******************************************************
SECTION .text
NEWSYM SA1inittable
; set tablead (NVMXDIZC) ( MXD )
push es
xor ecx,ecx
xor al,al
mov cx,256
mov edi,SA1tablead
.loopa
test al,08h ; D flag
jnz .decon
test al,10h ; X flag
jnz .xon
test al,20h ; M flag
jnz .mon
mov esi,SA1tableA
jmp .done
.mon
mov esi,SA1tableB
jmp .done
.xon
test al,20h ; M flag
jnz .mon2
mov esi,SA1tableC
jmp .done
.mon2
mov esi,SA1tableD
jmp .done
.decon
test al,10h ; X flag
jnz .xon3
test al,20h ; M flag
jnz .mon3
mov esi,SA1tableE
jmp .done
.mon3
mov esi,SA1tableF
jmp .done
.xon3
test al,20h
jnz .mon4
mov esi,SA1tableG
jmp .done
.mon4
mov esi,SA1tableH
.done
inc al
push eax
mov eax,esi
stosd
pop eax
dec ecx
jnz .loopa
; Set CPU addresses
mov edi,SA1tableA
call SA1settables
mov edi,SA1tableB
call SA1settables
mov edi,SA1tableC
call SA1settables
mov edi,SA1tableD
call SA1settables
mov edi,SA1tableE
call SA1settables
mov edi,SA1tableF
call SA1settables
mov edi,SA1tableG
call SA1settables
mov edi,SA1tableH
call SA1settables
; set proper functions
mov edi,SA1tableA ; Table addresses (M:0,X:0,D:0)
call SA1settablem16
mov edi,SA1tableA
call SA1settablex16
mov edi,SA1tableB ; Table addresses (M:1,X:0,D:0)
call SA1settablex16
mov edi,SA1tableC ; Table addresses (M:0,X:1,D:0)
call SA1settablem16
mov edi,SA1tableE ; Table addresses (M:0,X:0,D:1)
call SA1settablem16
mov edi,SA1tableE
call SA1settableDm16
mov edi,SA1tableE
call SA1settablex16
mov edi,SA1tableF ; Table addresses (M:1,X:0,D:1)
call SA1settablex16
mov edi,SA1tableF
call SA1settableDm8
mov edi,SA1tableG ; Table addresses (M:0,X:1,D:1)
call SA1settablem16
mov edi,SA1tableG
call SA1settableDm16
mov edi,SA1tableH ; Table addresses (M:1,X:1,D:1)
call SA1settableDm8
pop es
ret
;*******************************************************
; Set Tables Sets the opcode tables according to EDI
;*******************************************************
; This function sets all the non-multiple entries
NEWSYM SA1settables
;row 0
mov dword[edi+00h*4],SA1COp00
mov dword[edi+01h*4],SA1COp01m8
mov dword[edi+02h*4],SA1COp02
mov dword[edi+03h*4],SA1COp03m8
mov dword[edi+04h*4],SA1COp04m8
mov dword[edi+05h*4],SA1COp05m8
mov dword[edi+06h*4],SA1COp06m8
mov dword[edi+07h*4],SA1COp07m8
mov dword[edi+08h*4],SA1COp08
mov dword[edi+09h*4],SA1COp09m8
mov dword[edi+0Ah*4],SA1COp0Am8
mov dword[edi+0Bh*4],SA1COp0B
mov dword[edi+0Ch*4],SA1COp0Cm8
mov dword[edi+0Dh*4],SA1COp0Dm8
mov dword[edi+0Eh*4],SA1COp0Em8
mov dword[edi+0Fh*4],SA1COp0Fm8
mov dword[edi+10h*4],SA1COp10
mov dword[edi+11h*4],SA1COp11m8
mov dword[edi+12h*4],SA1COp12m8
mov dword[edi+13h*4],SA1COp13m8
mov dword[edi+14h*4],SA1COp14m8
mov dword[edi+15h*4],SA1COp15m8
mov dword[edi+16h*4],SA1COp16m8
mov dword[edi+17h*4],SA1COp17m8
mov dword[edi+18h*4],SA1COp18
mov dword[edi+19h*4],SA1COp19m8
mov dword[edi+1Ah*4],SA1COp1Am8
mov dword[edi+1Bh*4],SA1COp1B
mov dword[edi+1Ch*4],SA1COp1Cm8
mov dword[edi+1Dh*4],SA1COp1Dm8
mov dword[edi+1Eh*4],SA1COp1Em8
mov dword[edi+1Fh*4],SA1COp1Fm8
mov dword[edi+20h*4],SA1COp20
mov dword[edi+21h*4],SA1COp21m8
mov dword[edi+22h*4],SA1COp22
mov dword[edi+23h*4],SA1COp23m8
mov dword[edi+24h*4],SA1COp24m8
mov dword[edi+25h*4],SA1COp25m8
mov dword[edi+26h*4],SA1COp26m8
mov dword[edi+27h*4],SA1COp27m8
mov dword[edi+28h*4],SA1COp28
mov dword[edi+29h*4],SA1COp29m8
mov dword[edi+2Ah*4],SA1COp2Am8
mov dword[edi+2Bh*4],SA1COp2B
mov dword[edi+2Ch*4],SA1COp2Cm8
mov dword[edi+2Dh*4],SA1COp2Dm8
mov dword[edi+2Eh*4],SA1COp2Em8
mov dword[edi+2Fh*4],SA1COp2Fm8
mov dword[edi+30h*4],SA1COp30
mov dword[edi+31h*4],SA1COp31m8
mov dword[edi+32h*4],SA1COp32m8
mov dword[edi+33h*4],SA1COp33m8
mov dword[edi+34h*4],SA1COp34m8
mov dword[edi+35h*4],SA1COp35m8
mov dword[edi+36h*4],SA1COp36m8
mov dword[edi+37h*4],SA1COp37m8
mov dword[edi+38h*4],SA1COp38
mov dword[edi+39h*4],SA1COp39m8
mov dword[edi+3Ah*4],SA1COp3Am8
mov dword[edi+3Bh*4],SA1COp3B
mov dword[edi+3Ch*4],SA1COp3Cm8
mov dword[edi+3Dh*4],SA1COp3Dm8
mov dword[edi+3Eh*4],SA1COp3Em8
mov dword[edi+3Fh*4],SA1COp3Fm8
mov dword[edi+40h*4],SA1COp40
mov dword[edi+41h*4],SA1COp41m8
mov dword[edi+42h*4],SA1COp42
mov dword[edi+43h*4],SA1COp43m8
mov dword[edi+44h*4],SA1COp44
mov dword[edi+45h*4],SA1COp45m8
mov dword[edi+46h*4],SA1COp46m8
mov dword[edi+47h*4],SA1COp47m8
mov dword[edi+48h*4],SA1COp48m8
mov dword[edi+49h*4],SA1COp49m8
mov dword[edi+4Ah*4],SA1COp4Am8
mov dword[edi+4Bh*4],SA1COp4B
mov dword[edi+4Ch*4],SA1COp4C
mov dword[edi+4Dh*4],SA1COp4Dm8
mov dword[edi+4Eh*4],SA1COp4Em8
mov dword[edi+4Fh*4],SA1COp4Fm8
mov dword[edi+50h*4],SA1COp50
mov dword[edi+51h*4],SA1COp51m8
mov dword[edi+52h*4],SA1COp52m8
mov dword[edi+53h*4],SA1COp53m8
mov dword[edi+54h*4],SA1COp54
mov dword[edi+55h*4],SA1COp55m8
mov dword[edi+56h*4],SA1COp56m8
mov dword[edi+57h*4],SA1COp57m8
mov dword[edi+58h*4],SA1COp58
mov dword[edi+59h*4],SA1COp59m8
mov dword[edi+5Ah*4],SA1COp5Ax8
mov dword[edi+5Bh*4],SA1COp5B
mov dword[edi+5Ch*4],SA1COp5C
mov dword[edi+5Dh*4],SA1COp5Dm8
mov dword[edi+5Eh*4],SA1COp5Em8
mov dword[edi+5Fh*4],SA1COp5Fm8
mov dword[edi+60h*4],SA1COp60
mov dword[edi+61h*4],SA1COp61m8nd
mov dword[edi+62h*4],SA1COp62
mov dword[edi+63h*4],SA1COp63m8nd
mov dword[edi+64h*4],SA1COp64m8
mov dword[edi+65h*4],SA1COp65m8nd
mov dword[edi+66h*4],SA1COp66m8
mov dword[edi+67h*4],SA1COp67m8nd
mov dword[edi+68h*4],SA1COp68m8
mov dword[edi+69h*4],SA1COp69m8nd
mov dword[edi+6Ah*4],SA1COp6Am8
mov dword[edi+6Bh*4],SA1COp6B
mov dword[edi+6Ch*4],SA1COp6C
mov dword[edi+6Dh*4],SA1COp6Dm8nd
mov dword[edi+6Eh*4],SA1COp6Em8
mov dword[edi+6Fh*4],SA1COp6Fm8nd
mov dword[edi+70h*4],SA1COp70
mov dword[edi+71h*4],SA1COp71m8nd
mov dword[edi+72h*4],SA1COp72m8nd
mov dword[edi+73h*4],SA1COp73m8nd
mov dword[edi+74h*4],SA1COp74m8
mov dword[edi+75h*4],SA1COp75m8nd
mov dword[edi+76h*4],SA1COp76m8
mov dword[edi+77h*4],SA1COp77m8nd
mov dword[edi+78h*4],SA1COp78
mov dword[edi+79h*4],SA1COp79m8nd
mov dword[edi+7Ah*4],SA1COp7Ax8
mov dword[edi+7Bh*4],SA1COp7B
mov dword[edi+7Ch*4],SA1COp7C
mov dword[edi+7Dh*4],SA1COp7Dm8nd
mov dword[edi+7Eh*4],SA1COp7Em8
mov dword[edi+7Fh*4],SA1COp7Fm8nd
mov dword[edi+80h*4],SA1COp80
mov dword[edi+81h*4],SA1COp81m8
mov dword[edi+82h*4],SA1COp82
mov dword[edi+83h*4],SA1COp83m8
mov dword[edi+84h*4],SA1COp84x8
mov dword[edi+85h*4],SA1COp85m8
mov dword[edi+86h*4],SA1COp86x8
mov dword[edi+87h*4],SA1COp87m8
mov dword[edi+88h*4],SA1COp88x8
mov dword[edi+89h*4],SA1COp89m8
mov dword[edi+8Ah*4],SA1COp8Am8
mov dword[edi+8Bh*4],SA1COp8B
mov dword[edi+8Ch*4],SA1COp8Cx8
mov dword[edi+8Dh*4],SA1COp8Dm8
mov dword[edi+8Eh*4],SA1COp8Ex8
mov dword[edi+8Fh*4],SA1COp8Fm8
mov dword[edi+90h*4],SA1COp90
mov dword[edi+91h*4],SA1COp91m8
mov dword[edi+92h*4],SA1COp92m8
mov dword[edi+93h*4],SA1COp93m8
mov dword[edi+94h*4],SA1COp94x8
mov dword[edi+95h*4],SA1COp95m8
mov dword[edi+96h*4],SA1COp96x8
mov dword[edi+97h*4],SA1COp97m8
mov dword[edi+98h*4],SA1COp98m8
mov dword[edi+99h*4],SA1COp99m8
mov dword[edi+9Ah*4],SA1COp9A
mov dword[edi+9Bh*4],SA1COp9Bx8
mov dword[edi+9Ch*4],SA1COp9Cm8
mov dword[edi+9Dh*4],SA1COp9Dm8
mov dword[edi+9Eh*4],SA1COp9Em8
mov dword[edi+9Fh*4],SA1COp9Fm8
mov dword[edi+0A0h*4],SA1COpA0x8
mov dword[edi+0A1h*4],SA1COpA1m8
mov dword[edi+0A2h*4],SA1COpA2x8
mov dword[edi+0A3h*4],SA1COpA3m8
mov dword[edi+0A4h*4],SA1COpA4x8
mov dword[edi+0A5h*4],SA1COpA5m8
mov dword[edi+0A6h*4],SA1COpA6x8
mov dword[edi+0A7h*4],SA1COpA7m8
mov dword[edi+0A8h*4],SA1COpA8x8
mov dword[edi+0A9h*4],SA1COpA9m8
mov dword[edi+0AAh*4],SA1COpAAx8
mov dword[edi+0ABh*4],SA1COpAB
mov dword[edi+0ACh*4],SA1COpACx8
mov dword[edi+0ADh*4],SA1COpADm8
mov dword[edi+0AEh*4],SA1COpAEx8
mov dword[edi+0AFh*4],SA1COpAFm8
mov dword[edi+0B0h*4],SA1COpB0
mov dword[edi+0B1h*4],SA1COpB1m8
mov dword[edi+0B2h*4],SA1COpB2m8
mov dword[edi+0B3h*4],SA1COpB3m8
mov dword[edi+0B4h*4],SA1COpB4x8
mov dword[edi+0B5h*4],SA1COpB5m8
mov dword[edi+0B6h*4],SA1COpB6x8
mov dword[edi+0B7h*4],SA1COpB7m8
mov dword[edi+0B8h*4],SA1COpB8
mov dword[edi+0B9h*4],SA1COpB9m8
mov dword[edi+0BAh*4],SA1COpBAx8
mov dword[edi+0BBh*4],SA1COpBBx8
mov dword[edi+0BCh*4],SA1COpBCx8
mov dword[edi+0BDh*4],SA1COpBDm8
mov dword[edi+0BEh*4],SA1COpBEx8
mov dword[edi+0BFh*4],SA1COpBFm8
mov dword[edi+0C0h*4],SA1COpC0x8
mov dword[edi+0C1h*4],SA1COpC1m8
mov dword[edi+0C2h*4],SA1COpC2
mov dword[edi+0C3h*4],SA1COpC3m8
mov dword[edi+0C4h*4],SA1COpC4x8
mov dword[edi+0C5h*4],SA1COpC5m8
mov dword[edi+0C6h*4],SA1COpC6m8
mov dword[edi+0C7h*4],SA1COpC7m8
mov dword[edi+0C8h*4],SA1COpC8x8
mov dword[edi+0C9h*4],SA1COpC9m8
mov dword[edi+0CAh*4],SA1COpCAx8
mov dword[edi+0CBh*4],SA1COpCB
mov dword[edi+0CCh*4],SA1COpCCx8
mov dword[edi+0CDh*4],SA1COpCDm8
mov dword[edi+0CEh*4],SA1COpCEm8
mov dword[edi+0CFh*4],SA1COpCFm8
mov dword[edi+0D0h*4],SA1COpD0
mov dword[edi+0D1h*4],SA1COpD1m8
mov dword[edi+0D2h*4],SA1COpD2m8
mov dword[edi+0D3h*4],SA1COpD3m8
mov dword[edi+0D4h*4],SA1COpD4
mov dword[edi+0D5h*4],SA1COpD5m8
mov dword[edi+0D6h*4],SA1COpD6m8
mov dword[edi+0D7h*4],SA1COpD7m8
mov dword[edi+0D8h*4],SA1COpD8
mov dword[edi+0D9h*4],SA1COpD9m8
mov dword[edi+0DAh*4],SA1COpDAx8
mov dword[edi+0DBh*4],SA1COpDB
mov dword[edi+0DCh*4],SA1COpDC
mov dword[edi+0DDh*4],SA1COpDDm8
mov dword[edi+0DEh*4],SA1COpDEm8
mov dword[edi+0DFh*4],SA1COpDFm8
mov dword[edi+0E0h*4],SA1COpE0x8
mov dword[edi+0E1h*4],SA1COpE1m8nd
mov dword[edi+0E2h*4],SA1COpE2
mov dword[edi+0E3h*4],SA1COpE3m8nd
mov dword[edi+0E4h*4],SA1COpE4x8
mov dword[edi+0E5h*4],SA1COpE5m8nd
mov dword[edi+0E6h*4],SA1COpE6m8
mov dword[edi+0E7h*4],SA1COpE7m8nd
mov dword[edi+0E8h*4],SA1COpE8x8
mov dword[edi+0E9h*4],SA1COpE9m8nd
mov dword[edi+0EAh*4],SA1COpEA
mov dword[edi+0EBh*4],SA1COpEB
mov dword[edi+0ECh*4],SA1COpECx8
mov dword[edi+0EDh*4],SA1COpEDm8nd
mov dword[edi+0EEh*4],SA1COpEEm8
mov dword[edi+0EFh*4],SA1COpEFm8nd
mov dword[edi+0F0h*4],SA1COpF0
mov dword[edi+0F1h*4],SA1COpF1m8nd
mov dword[edi+0F2h*4],SA1COpF2m8nd
mov dword[edi+0F3h*4],SA1COpF3m8nd
mov dword[edi+0F4h*4],SA1COpF4
mov dword[edi+0F5h*4],SA1COpF5m8nd
mov dword[edi+0F6h*4],SA1COpF6m8
mov dword[edi+0F7h*4],SA1COpF7m8nd
mov dword[edi+0F8h*4],SA1COpF8
mov dword[edi+0F9h*4],SA1COpF9m8nd
mov dword[edi+0FAh*4],SA1COpFAx8
mov dword[edi+0FBh*4],SA1COpFB
mov dword[edi+0FCh*4],SA1COpFC
mov dword[edi+0FDh*4],SA1COpFDm8nd
mov dword[edi+0FEh*4],SA1COpFEm8
mov dword[edi+0FFh*4],SA1COpFFm8nd
ret
NEWSYM SA1settablem16
mov dword[edi+01h*4],SA1COp01m16
mov dword[edi+03h*4],SA1COp03m16
mov dword[edi+04h*4],SA1COp04m16
mov dword[edi+05h*4],SA1COp05m16
mov dword[edi+06h*4],SA1COp06m16
mov dword[edi+07h*4],SA1COp07m16
mov dword[edi+09h*4],SA1COp09m16
mov dword[edi+0Ah*4],SA1COp0Am16
mov dword[edi+0Ch*4],SA1COp0Cm16
mov dword[edi+0Dh*4],SA1COp0Dm16
mov dword[edi+0Eh*4],SA1COp0Em16
mov dword[edi+0Fh*4],SA1COp0Fm16
mov dword[edi+11h*4],SA1COp11m16
mov dword[edi+12h*4],SA1COp12m16
mov dword[edi+13h*4],SA1COp13m16
mov dword[edi+14h*4],SA1COp14m16
mov dword[edi+15h*4],SA1COp15m16
mov dword[edi+16h*4],SA1COp16m16
mov dword[edi+17h*4],SA1COp17m16
mov dword[edi+19h*4],SA1COp19m16
mov dword[edi+1Ah*4],SA1COp1Am16
mov dword[edi+1Ch*4],SA1COp1Cm16
mov dword[edi+1Dh*4],SA1COp1Dm16
mov dword[edi+1Eh*4],SA1COp1Em16
mov dword[edi+1Fh*4],SA1COp1Fm16
mov dword[edi+21h*4],SA1COp21m16
mov dword[edi+23h*4],SA1COp23m16
mov dword[edi+24h*4],SA1COp24m16
mov dword[edi+25h*4],SA1COp25m16
mov dword[edi+26h*4],SA1COp26m16
mov dword[edi+27h*4],SA1COp27m16
mov dword[edi+29h*4],SA1COp29m16
mov dword[edi+2Ah*4],SA1COp2Am16
mov dword[edi+2Ch*4],SA1COp2Cm16
mov dword[edi+2Dh*4],SA1COp2Dm16
mov dword[edi+2Eh*4],SA1COp2Em16
mov dword[edi+2Fh*4],SA1COp2Fm16
mov dword[edi+31h*4],SA1COp31m16
mov dword[edi+32h*4],SA1COp32m16
mov dword[edi+33h*4],SA1COp33m16
mov dword[edi+34h*4],SA1COp34m16
mov dword[edi+35h*4],SA1COp35m16
mov dword[edi+36h*4],SA1COp36m16
mov dword[edi+37h*4],SA1COp37m16
mov dword[edi+39h*4],SA1COp39m16
mov dword[edi+3Ah*4],SA1COp3Am16
mov dword[edi+3Ch*4],SA1COp3Cm16
mov dword[edi+3Dh*4],SA1COp3Dm16
mov dword[edi+3Eh*4],SA1COp3Em16
mov dword[edi+3Fh*4],SA1COp3Fm16
mov dword[edi+41h*4],SA1COp41m16
mov dword[edi+43h*4],SA1COp43m16
mov dword[edi+45h*4],SA1COp45m16
mov dword[edi+46h*4],SA1COp46m16
mov dword[edi+47h*4],SA1COp47m16
mov dword[edi+48h*4],SA1COp48m16
mov dword[edi+49h*4],SA1COp49m16
mov dword[edi+4Ah*4],SA1COp4Am16
mov dword[edi+4Dh*4],SA1COp4Dm16
mov dword[edi+4Eh*4],SA1COp4Em16
mov dword[edi+4Fh*4],SA1COp4Fm16
mov dword[edi+51h*4],SA1COp51m16
mov dword[edi+52h*4],SA1COp52m16
mov dword[edi+53h*4],SA1COp53m16
mov dword[edi+55h*4],SA1COp55m16
mov dword[edi+56h*4],SA1COp56m16
mov dword[edi+57h*4],SA1COp57m16
mov dword[edi+59h*4],SA1COp59m16
mov dword[edi+5Dh*4],SA1COp5Dm16
mov dword[edi+5Eh*4],SA1COp5Em16
mov dword[edi+5Fh*4],SA1COp5Fm16
mov dword[edi+61h*4],SA1COp61m16nd
mov dword[edi+63h*4],SA1COp63m16nd
mov dword[edi+64h*4],SA1COp64m16
mov dword[edi+65h*4],SA1COp65m16nd
mov dword[edi+66h*4],SA1COp66m16
mov dword[edi+67h*4],SA1COp67m16nd
mov dword[edi+68h*4],SA1COp68m16
mov dword[edi+69h*4],SA1COp69m16nd
mov dword[edi+6Ah*4],SA1COp6Am16
mov dword[edi+6Dh*4],SA1COp6Dm16nd
mov dword[edi+6Eh*4],SA1COp6Em16
mov dword[edi+6Fh*4],SA1COp6Fm16nd
mov dword[edi+71h*4],SA1COp71m16nd
mov dword[edi+72h*4],SA1COp72m16nd
mov dword[edi+73h*4],SA1COp73m16nd
mov dword[edi+74h*4],SA1COp74m16
mov dword[edi+75h*4],SA1COp75m16nd
mov dword[edi+76h*4],SA1COp76m16
mov dword[edi+77h*4],SA1COp77m16nd
mov dword[edi+79h*4],SA1COp79m16nd
mov dword[edi+7Dh*4],SA1COp7Dm16nd
mov dword[edi+7Eh*4],SA1COp7Em16
mov dword[edi+7Fh*4],SA1COp7Fm16nd
mov dword[edi+81h*4],SA1COp81m16
mov dword[edi+83h*4],SA1COp83m16
mov dword[edi+85h*4],SA1COp85m16
mov dword[edi+87h*4],SA1COp87m16
mov dword[edi+89h*4],SA1COp89m16
mov dword[edi+8Ah*4],SA1COp8Am16
mov dword[edi+8Dh*4],SA1COp8Dm16
mov dword[edi+8Fh*4],SA1COp8Fm16
mov dword[edi+91h*4],SA1COp91m16
mov dword[edi+92h*4],SA1COp92m16
mov dword[edi+93h*4],SA1COp93m16
mov dword[edi+95h*4],SA1COp95m16
mov dword[edi+97h*4],SA1COp97m16
mov dword[edi+98h*4],SA1COp98m16
mov dword[edi+99h*4],SA1COp99m16
mov dword[edi+9Ch*4],SA1COp9Cm16
mov dword[edi+9Dh*4],SA1COp9Dm16
mov dword[edi+9Eh*4],SA1COp9Em16
mov dword[edi+9Fh*4],SA1COp9Fm16
mov dword[edi+0A1h*4],SA1COpA1m16
mov dword[edi+0A3h*4],SA1COpA3m16
mov dword[edi+0A5h*4],SA1COpA5m16
mov dword[edi+0A7h*4],SA1COpA7m16
mov dword[edi+0A9h*4],SA1COpA9m16
mov dword[edi+0ADh*4],SA1COpADm16
mov dword[edi+0AFh*4],SA1COpAFm16
mov dword[edi+0B1h*4],SA1COpB1m16
mov dword[edi+0B2h*4],SA1COpB2m16
mov dword[edi+0B3h*4],SA1COpB3m16
mov dword[edi+0B5h*4],SA1COpB5m16
mov dword[edi+0B7h*4],SA1COpB7m16
mov dword[edi+0B9h*4],SA1COpB9m16
mov dword[edi+0BDh*4],SA1COpBDm16
mov dword[edi+0BFh*4],SA1COpBFm16
mov dword[edi+0C1h*4],SA1COpC1m16
mov dword[edi+0C3h*4],SA1COpC3m16
mov dword[edi+0C5h*4],SA1COpC5m16
mov dword[edi+0C6h*4],SA1COpC6m16
mov dword[edi+0C7h*4],SA1COpC7m16
mov dword[edi+0C9h*4],SA1COpC9m16
mov dword[edi+0CDh*4],SA1COpCDm16
mov dword[edi+0CEh*4],SA1COpCEm16
mov dword[edi+0CFh*4],SA1COpCFm16
mov dword[edi+0D1h*4],SA1COpD1m16
mov dword[edi+0D2h*4],SA1COpD2m16
mov dword[edi+0D3h*4],SA1COpD3m16
mov dword[edi+0D5h*4],SA1COpD5m16
mov dword[edi+0D6h*4],SA1COpD6m16
mov dword[edi+0D7h*4],SA1COpD7m16
mov dword[edi+0D9h*4],SA1COpD9m16
mov dword[edi+0DDh*4],SA1COpDDm16
mov dword[edi+0DEh*4],SA1COpDEm16
mov dword[edi+0DFh*4],SA1COpDFm16
mov dword[edi+0E1h*4],SA1COpE1m16nd
mov dword[edi+0E3h*4],SA1COpE3m16nd
mov dword[edi+0E5h*4],SA1COpE5m16nd
mov dword[edi+0E6h*4],SA1COpE6m16
mov dword[edi+0E7h*4],SA1COpE7m16nd
mov dword[edi+0E9h*4],SA1COpE9m16nd
mov dword[edi+0EDh*4],SA1COpEDm16nd
mov dword[edi+0EEh*4],SA1COpEEm16
mov dword[edi+0EFh*4],SA1COpEFm16nd
mov dword[edi+0F1h*4],SA1COpF1m16nd
mov dword[edi+0F2h*4],SA1COpF2m16nd
mov dword[edi+0F3h*4],SA1COpF3m16nd
mov dword[edi+0F5h*4],SA1COpF5m16nd
mov dword[edi+0F6h*4],SA1COpF6m16
mov dword[edi+0F7h*4],SA1COpF7m16nd
mov dword[edi+0F9h*4],SA1COpF9m16nd
mov dword[edi+0FDh*4],SA1COpFDm16nd
mov dword[edi+0FEh*4],SA1COpFEm16
mov dword[edi+0FFh*4],SA1COpFFm16nd
ret
NEWSYM SA1settablex16
mov dword[edi+5Ah*4],SA1COp5Ax16
mov dword[edi+7Ah*4],SA1COp7Ax16
mov dword[edi+84h*4],SA1COp84x16
mov dword[edi+86h*4],SA1COp86x16
mov dword[edi+88h*4],SA1COp88x16
mov dword[edi+8Ch*4],SA1COp8Cx16
mov dword[edi+8Eh*4],SA1COp8Ex16
mov dword[edi+94h*4],SA1COp94x16
mov dword[edi+96h*4],SA1COp96x16
mov dword[edi+9Bh*4],SA1COp9Bx16
mov dword[edi+0A0h*4],SA1COpA0x16
mov dword[edi+0A2h*4],SA1COpA2x16
mov dword[edi+0A4h*4],SA1COpA4x16
mov dword[edi+0A6h*4],SA1COpA6x16
mov dword[edi+0A8h*4],SA1COpA8x16
mov dword[edi+0AAh*4],SA1COpAAx16
mov dword[edi+0ACh*4],SA1COpACx16
mov dword[edi+0AEh*4],SA1COpAEx16
mov dword[edi+0B4h*4],SA1COpB4x16
mov dword[edi+0B6h*4],SA1COpB6x16
mov dword[edi+0BAh*4],SA1COpBAx16
mov dword[edi+0BBh*4],SA1COpBBx16
mov dword[edi+0BCh*4],SA1COpBCx16
mov dword[edi+0BEh*4],SA1COpBEx16
mov dword[edi+0C0h*4],SA1COpC0x16
mov dword[edi+0C4h*4],SA1COpC4x16
mov dword[edi+0C8h*4],SA1COpC8x16
mov dword[edi+0CAh*4],SA1COpCAx16
mov dword[edi+0CCh*4],SA1COpCCx16
mov dword[edi+0DAh*4],SA1COpDAx16
mov dword[edi+0E0h*4],SA1COpE0x16
mov dword[edi+0E4h*4],SA1COpE4x16
mov dword[edi+0E8h*4],SA1COpE8x16
mov dword[edi+0ECh*4],SA1COpECx16
mov dword[edi+0FAh*4],SA1COpFAx16
ret
NEWSYM SA1settableDm8
mov dword[edi+61h*4],SA1COp61m8d
mov dword[edi+63h*4],SA1COp63m8d
mov dword[edi+65h*4],SA1COp65m8d
mov dword[edi+67h*4],SA1COp67m8d
mov dword[edi+69h*4],SA1COp69m8d
mov dword[edi+6Dh*4],SA1COp6Dm8d
mov dword[edi+6Fh*4],SA1COp6Fm8d
mov dword[edi+71h*4],SA1COp71m8d
mov dword[edi+72h*4],SA1COp72m8d
mov dword[edi+73h*4],SA1COp73m8d
mov dword[edi+75h*4],SA1COp75m8d
mov dword[edi+77h*4],SA1COp77m8d
mov dword[edi+79h*4],SA1COp79m8d
mov dword[edi+7Dh*4],SA1COp7Dm8d
mov dword[edi+7Fh*4],SA1COp7Fm8d
mov dword[edi+0E1h*4],SA1COpE1m8d
mov dword[edi+0E3h*4],SA1COpE3m8d
mov dword[edi+0E5h*4],SA1COpE5m8d
mov dword[edi+0E7h*4],SA1COpE7m8d
mov dword[edi+0E9h*4],SA1COpE9m8d
mov dword[edi+0EDh*4],SA1COpEDm8d
mov dword[edi+0EFh*4],SA1COpEFm8d
mov dword[edi+0F1h*4],SA1COpF1m8d
mov dword[edi+0F2h*4],SA1COpF2m8d
mov dword[edi+0F3h*4],SA1COpF3m8d
mov dword[edi+0F5h*4],SA1COpF5m8d
mov dword[edi+0F7h*4],SA1COpF7m8d
mov dword[edi+0F9h*4],SA1COpF9m8d
mov dword[edi+0FDh*4],SA1COpFDm8d
mov dword[edi+0FFh*4],SA1COpFFm8d
ret
NEWSYM SA1settableDm16
mov dword[edi+61h*4],SA1COp61m16d
mov dword[edi+63h*4],SA1COp63m16d
mov dword[edi+65h*4],SA1COp65m16d
mov dword[edi+67h*4],SA1COp67m16d
mov dword[edi+69h*4],SA1COp69m16d
mov dword[edi+6Dh*4],SA1COp6Dm16d
mov dword[edi+6Fh*4],SA1COp6Fm16d
mov dword[edi+71h*4],SA1COp71m16d
mov dword[edi+72h*4],SA1COp72m16d
mov dword[edi+73h*4],SA1COp73m16d
mov dword[edi+75h*4],SA1COp75m16d
mov dword[edi+77h*4],SA1COp77m16d
mov dword[edi+79h*4],SA1COp79m16d
mov dword[edi+7Dh*4],SA1COp7Dm16d
mov dword[edi+7Fh*4],SA1COp7Fm16d
mov dword[edi+0E1h*4],SA1COpE1m16d
mov dword[edi+0E3h*4],SA1COpE3m16d
mov dword[edi+0E5h*4],SA1COpE5m16d
mov dword[edi+0E7h*4],SA1COpE7m16d
mov dword[edi+0E9h*4],SA1COpE9m16d
mov dword[edi+0EDh*4],SA1COpEDm16d
mov dword[edi+0EFh*4],SA1COpEFm16d
mov dword[edi+0F1h*4],SA1COpF1m16d
mov dword[edi+0F2h*4],SA1COpF2m16d
mov dword[edi+0F3h*4],SA1COpF3m16d
mov dword[edi+0F5h*4],SA1COpF5m16d
mov dword[edi+0F7h*4],SA1COpF7m16d
mov dword[edi+0F9h*4],SA1COpF9m16d
mov dword[edi+0FDh*4],SA1COpFDm16d
mov dword[edi+0FFh*4],SA1COpFFm16d
ret

902
zsnes/src/cpu/table.asm Normal file
View File

@@ -0,0 +1,902 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM mosjmptab,mosdraw10,mosdraw11,mosdraw12,mosdraw13
EXTSYM mosdraw14,mosdraw15,mosdraw16,mosdraw2,mosdraw3
EXTSYM mosdraw4,mosdraw5,mosdraw6,mosdraw7,mosdraw8
EXTSYM mosdraw9,ngpalcon2b,ngpalcon4b
EXTSYM mosjmptab16b,mosdraw1016b,mosdraw1116b,mosdraw1216b,mosdraw1316b
EXTSYM mosdraw1416b,mosdraw1516b,mosdraw1616b,mosdraw216b,mosdraw316b
EXTSYM mosdraw416b,mosdraw516b,mosdraw616b,mosdraw716b,mosdraw816b
EXTSYM mosdraw916b
EXTSYM mosjmptab16bt,mosdraw1016bt,mosdraw1116bt,mosdraw1216bt,mosdraw1316bt
EXTSYM mosdraw1416bt,mosdraw1516bt,mosdraw1616bt,mosdraw216bt,mosdraw316bt
EXTSYM mosdraw416bt,mosdraw516bt,mosdraw616bt,mosdraw716bt,mosdraw816bt
EXTSYM mosdraw916bt
EXTSYM mosjmptab16btms,mosdraw1016btms,mosdraw1116btms,mosdraw1216btms,mosdraw1316btms
EXTSYM mosdraw1416btms,mosdraw1516btms,mosdraw1616btms,mosdraw216btms,mosdraw316btms
EXTSYM mosdraw416btms,mosdraw516btms,mosdraw616btms,mosdraw716btms,mosdraw816btms
EXTSYM mosdraw916btms
EXTSYM mosjmptab16bntms,mosdraw1016bntms,mosdraw1116bntms,mosdraw1216bntms,mosdraw1316bntms
EXTSYM mosdraw1416bntms,mosdraw1516bntms,mosdraw1616bntms,mosdraw216bntms,mosdraw316bntms
EXTSYM mosdraw416bntms,mosdraw516bntms,mosdraw616bntms,mosdraw716bntms,mosdraw816bntms
EXTSYM mosdraw916bntms
EXTSYM tableA,tableB,tableC,tableD,tableE,tableF,tableG,tableH
EXTSYM DPageR8,DPageW8,DPageR16,DPageW16
EXTSYM SDD1Enable
EXTSYM JoyAOrig,JoyANow,JoyBOrig,JoyBNow,JoyCOrig,JoyCNow,JoyDOrig,JoyDNow
%include "cpu/65816d.inc"
%include "cpu/address.inc"
%include "cpu/addrni.inc"
%include "cpu/e65816.inc"
%include "cpu/regs.mac"
%include "cpu/regsw.mac"
%include "cpu/regs.inc" ; start problem here
%include "cpu/regsw.inc"
section .data
; global variables
;tableA times 256 dd 0 ; Table addresses (M:0,X:0,D:0)
;tableB times 256 dd 0 ; Table addresses (M:1,X:0,D:0)
;tableC times 256 dd 0 ; Table addresses (M:0,X:1,D:0)
;tableD times 256 dd 0 ; Table addresses (M:1,X:1,D:0)
;tableE times 256 dd 0 ; Table addresses (M:0,X:0,D:1)
;tableF times 256 dd 0 ; Table addresses (M:1,X:0,D:1)
;tableG times 256 dd 0 ; Table addresses (M:0,X:1,D:1)
;tableH times 256 dd 0 ; Table addresses (M:1,X:1,D:1)
NEWSYM addrmdef, times 27 dd 0 ; Address modes
;tablead times 256 dd 0 ; Table address location according to P
;memtabler8 times 256 dd 0 ; Memory Bank Locations for reading 8-bit
;memtablew8 times 256 dd 0 ; Memory Bank Locations for writing 8-bit
;memtabler16 times 256 dd 0 ; Memory Bank Locations for reading 16-bit
;memtablew16 times 256 dd 0 ; Memory Bank Locations for reading 16-bit
section .text
;*******************************************************
; Generate OpCode Table
;*******************************************************
NEWSYM inittable
; set up mosaic
mov dword[mosjmptab],mosdraw2
mov dword[mosjmptab+4],mosdraw3
mov dword[mosjmptab+8],mosdraw4
mov dword[mosjmptab+12],mosdraw5
mov dword[mosjmptab+16],mosdraw6
mov dword[mosjmptab+20],mosdraw7
mov dword[mosjmptab+24],mosdraw8
mov dword[mosjmptab+28],mosdraw9
mov dword[mosjmptab+32],mosdraw10
mov dword[mosjmptab+36],mosdraw11
mov dword[mosjmptab+40],mosdraw12
mov dword[mosjmptab+44],mosdraw13
mov dword[mosjmptab+48],mosdraw14
mov dword[mosjmptab+52],mosdraw15
mov dword[mosjmptab+56],mosdraw16
mov dword[mosjmptab16b],mosdraw216b
mov dword[mosjmptab16b+4],mosdraw316b
mov dword[mosjmptab16b+8],mosdraw416b
mov dword[mosjmptab16b+12],mosdraw516b
mov dword[mosjmptab16b+16],mosdraw616b
mov dword[mosjmptab16b+20],mosdraw716b
mov dword[mosjmptab16b+24],mosdraw816b
mov dword[mosjmptab16b+28],mosdraw916b
mov dword[mosjmptab16b+32],mosdraw1016b
mov dword[mosjmptab16b+36],mosdraw1116b
mov dword[mosjmptab16b+40],mosdraw1216b
mov dword[mosjmptab16b+44],mosdraw1316b
mov dword[mosjmptab16b+48],mosdraw1416b
mov dword[mosjmptab16b+52],mosdraw1516b
mov dword[mosjmptab16b+56],mosdraw1616b
mov dword[mosjmptab16bt],mosdraw216bt
mov dword[mosjmptab16bt+4],mosdraw316bt
mov dword[mosjmptab16bt+8],mosdraw416bt
mov dword[mosjmptab16bt+12],mosdraw516bt
mov dword[mosjmptab16bt+16],mosdraw616bt
mov dword[mosjmptab16bt+20],mosdraw716bt
mov dword[mosjmptab16bt+24],mosdraw816bt
mov dword[mosjmptab16bt+28],mosdraw916bt
mov dword[mosjmptab16bt+32],mosdraw1016bt
mov dword[mosjmptab16bt+36],mosdraw1116bt
mov dword[mosjmptab16bt+40],mosdraw1216bt
mov dword[mosjmptab16bt+44],mosdraw1316bt
mov dword[mosjmptab16bt+48],mosdraw1416bt
mov dword[mosjmptab16bt+52],mosdraw1516bt
mov dword[mosjmptab16bt+56],mosdraw1616bt
mov dword[mosjmptab16btms],mosdraw216btms
mov dword[mosjmptab16btms+4],mosdraw316btms
mov dword[mosjmptab16btms+8],mosdraw416btms
mov dword[mosjmptab16btms+12],mosdraw516btms
mov dword[mosjmptab16btms+16],mosdraw616btms
mov dword[mosjmptab16btms+20],mosdraw716btms
mov dword[mosjmptab16btms+24],mosdraw816btms
mov dword[mosjmptab16btms+28],mosdraw916btms
mov dword[mosjmptab16btms+32],mosdraw1016btms
mov dword[mosjmptab16btms+36],mosdraw1116btms
mov dword[mosjmptab16btms+40],mosdraw1216btms
mov dword[mosjmptab16btms+44],mosdraw1316btms
mov dword[mosjmptab16btms+48],mosdraw1416btms
mov dword[mosjmptab16btms+52],mosdraw1516btms
mov dword[mosjmptab16btms+56],mosdraw1616btms
mov dword[mosjmptab16bntms],mosdraw216bntms
mov dword[mosjmptab16bntms+4],mosdraw316bntms
mov dword[mosjmptab16bntms+8],mosdraw416bntms
mov dword[mosjmptab16bntms+12],mosdraw516bntms
mov dword[mosjmptab16bntms+16],mosdraw616bntms
mov dword[mosjmptab16bntms+20],mosdraw716bntms
mov dword[mosjmptab16bntms+24],mosdraw816bntms
mov dword[mosjmptab16bntms+28],mosdraw916bntms
mov dword[mosjmptab16bntms+32],mosdraw1016bntms
mov dword[mosjmptab16bntms+36],mosdraw1116bntms
mov dword[mosjmptab16bntms+40],mosdraw1216bntms
mov dword[mosjmptab16bntms+44],mosdraw1316bntms
mov dword[mosjmptab16bntms+48],mosdraw1416bntms
mov dword[mosjmptab16bntms+52],mosdraw1516bntms
mov dword[mosjmptab16bntms+56],mosdraw1616bntms
; set ngpalcon4b
mov ecx,20h
xor eax,eax
.loopng
mov bl,al
shr bl,2
shl bl,4
mov dl,bl
mov dh,bl
shl edx,16
mov dl,bl
mov dh,bl
mov [ngpalcon4b+eax*4],edx
inc eax
dec ecx
jnz .loopng
; set ngpalcon2b
mov ecx,20h
xor eax,eax
.loopngb
mov bl,al
shr bl,2
shl bl,2
mov dl,bl
mov dh,bl
shl edx,16
mov dl,bl
mov dh,bl
mov [ngpalcon2b+eax*4],edx
inc eax
dec ecx
jnz .loopngb
; set tablead (NVMXDIZC) ( MXD )
push es
xor ecx,ecx
xor al,al
mov cx,256
mov edi,tablead
.loopa
test al,08h ; D flag
jnz .decon
test al,10h ; X flag
jnz .xon
test al,20h ; M flag
jnz .mon
mov esi,tableA
jmp .done
.mon
mov esi,tableB
jmp .done
.xon
test al,20h ; M flag
jnz .mon2
mov esi,tableC
jmp .done
.mon2
mov esi,tableD
jmp .done
.decon
test al,10h ; X flag
jnz .xon3
test al,20h ; M flag
jnz .mon3
mov esi,tableE
jmp .done
.mon3
mov esi,tableF
jmp .done
.xon3
test al,20h
jnz .mon4
mov esi,tableG
jmp .done
.mon4
mov esi,tableH
.done
inc al
push eax
mov eax,esi
stosd
pop eax
dec ecx
jnz .loopa
; Set CPU addresses
; First, set all addresses to invalid
mov eax,eopINVALID
mov edi,tableA
mov ecx,256
rep stosd
mov edi,tableB
mov ecx,256
rep stosd
mov edi,tableC
mov ecx,256
rep stosd
mov edi,tableD
mov ecx,256
rep stosd
mov edi,tableE
mov ecx,256
rep stosd
mov edi,tableF
mov ecx,256
rep stosd
mov edi,tableG
mov ecx,256
rep stosd
mov edi,tableH
mov ecx,256
rep stosd
mov edi,tableA
call settables
mov edi,tableB
call settables
mov edi,tableC
call settables
mov edi,tableD
call settables
mov edi,tableE
call settables
mov edi,tableF
call settables
mov edi,tableG
call settables
mov edi,tableH
call settables
; set proper functions
mov edi,tableA ; Table addresses (M:0,X:0,D:0)
call settablem16
mov edi,tableA
call settablex16
mov edi,tableB ; Table addresses (M:1,X:0,D:0)
call settablex16
mov edi,tableC ; Table addresses (M:0,X:1,D:0)
call settablem16
mov edi,tableE ; Table addresses (M:0,X:0,D:1)
call settablem16
mov edi,tableE
call settableDm16
mov edi,tableE
call settablex16
mov edi,tableF ; Table addresses (M:1,X:0,D:1)
call settablex16
mov edi,tableF
call settableDm8
mov edi,tableG ; Table addresses (M:0,X:1,D:1)
call settablem16
mov edi,tableG
call settableDm16
mov edi,tableH ; Table addresses (M:1,X:1,D:1)
call settableDm8
pop es
ret
eopINVALID
ret
section .data
;*******************************************************
; Cpu Cycles Sets the CPU cycle table
;*******************************************************
NEWSYM cpucycle
db 8, 6, 8, 4, 5, 3, 5, 6, 3, 2, 2, 4, 6, 4, 6, 5
db 2, 5, 5, 7, 5, 4, 6, 6, 2, 4, 2, 2, 6, 4, 7, 5
db 6, 6, 8, 4, 3, 3, 5, 6, 4, 2, 2, 5, 4, 4, 6, 5
db 2, 5, 5, 7, 4, 4, 6, 6, 2, 4, 2, 2, 4, 4, 7, 5
db 7, 6, 2, 4, 7, 3, 5, 6, 3, 2, 2, 3, 3, 4, 6, 5
db 2, 5, 5, 7, 7, 4, 6, 6, 2, 4, 3, 2, 4, 4, 7, 5
db 6, 6, 6, 4, 3, 3, 5, 6, 4, 2, 2, 6, 5, 4, 6, 5
db 2, 5, 5, 7, 4, 4, 6, 6, 2, 4, 4, 2, 6, 4, 7, 5
db 2, 6, 3, 4, 3, 3, 3, 6, 2, 2, 2, 3, 4, 4, 4, 5
db 2, 6, 5, 7, 4, 4, 4, 6, 2, 5, 2, 2, 4, 5, 5, 5
db 2, 6, 2, 4, 3, 3, 3, 6, 2, 2, 2, 4, 4, 4, 4, 5
db 2, 5, 5, 7, 4, 4, 4, 6, 2, 4, 2, 2, 4, 4, 4, 5
db 2, 6, 3, 4, 3, 3, 5, 6, 2, 2, 2, 3, 4, 4, 4, 5
db 2, 5, 5, 7, 6, 4, 6, 6, 2, 4, 3, 3, 6, 4, 7, 5
db 2, 6, 3, 4, 3, 3, 5, 6, 2, 2, 2, 3, 4, 4, 6, 5
db 2, 5, 5, 7, 5, 4, 6, 6, 2, 4, 4, 2, 6, 4, 7, 5
; 28 | 26 | 28 | 24 | 25 | 23 | 25 | 26 | 13 | 22 | 12 | 14 | 36 | 34 | 36 | 45
; 22 | 25 | 25 | 27 | 25 | 24 | 26 | 26 | 12 | 34 | 12 | 12 | 36 | 34 | 37 | 45
; 36 | 26 | 48 | 24 | 23 | 23 | 25 | 26 | 14 | 22 | 12 | 15 | 34 | 34 | 36 | 45
; 22 | 25 | 25 | 27 | 24 | 24 | 26 | 26 | 12 | 34 | 12 | 12 | 34 | 34 | 37 | 45
; 17 | 26 | 22 | 24 | 37 | 23 | 25 | 26 | 13 | 22 | 12 | 13 | 33 | 34 | 36 | 45
; 22 | 25 | 25 | 27 | 37 | 24 | 26 | 26 | 12 | 34 | 13 | 12 | 44 | 34 | 37 | 45
; 16 | 26 | 36 | 24 | 23 | 23 | 25 | 26 | 14 | 22 | 12 | 16 | 35 | 34 | 36 | 45
; 22 | 25 | 25 | 27 | 24 | 24 | 26 | 26 | 12 | 34 | 14 | 12 | 36 | 34 | 37 | 45
; 22 | 26 | 33 | 24 | 23 | 23 | 23 | 26 | 12 | 22 | 12 | 13 | 34 | 34 | 34 | 45
; 22 | 26 | 25 | 27 | 24 | 24 | 24 | 26 | 12 | 35 | 12 | 12 | 34 | 35 | 35 | 45
; 22 | 26 | 22 | 24 | 23 | 23 | 23 | 26 | 12 | 22 | 12 | 14 | 34 | 34 | 34 | 45
; 22 | 25 | 25 | 27 | 24 | 24 | 24 | 26 | 12 | 34 | 12 | 12 | 34 | 34 | 34 | 45
; 22 | 26 | 23 | 24 | 23 | 23 | 25 | 26 | 12 | 22 | 12 | 13 | 34 | 34 | 34 | 45
; 22 | 25 | 25 | 27 | 26 | 24 | 26 | 26 | 12 | 34 | 13 | 13 | 36 | 34 | 37 | 45
; 22 | 26 | 23 | 24 | 23 | 23 | 25 | 26 | 12 | 22 | 12 | 13 | 34 | 34 | 36 | 45
; 22 | 25 | 25 | 27 | 35 | 24 | 26 | 26 | 12 | 34 | 14 | 12 | 36 | 34 | 37 | 45
section .text
;*******************************************************
; Set Tables Sets the opcode tables according to EDI
;*******************************************************
; This function sets all the non-multiple entries
NEWSYM settables
;row 0
mov dword[edi+00h*4],COp00
mov dword[edi+01h*4],COp01m8
mov dword[edi+02h*4],COp02
mov dword[edi+03h*4],COp03m8
mov dword[edi+04h*4],COp04m8
mov dword[edi+05h*4],COp05m8
mov dword[edi+06h*4],COp06m8
mov dword[edi+07h*4],COp07m8
mov dword[edi+08h*4],COp08
mov dword[edi+09h*4],COp09m8
mov dword[edi+0Ah*4],COp0Am8
mov dword[edi+0Bh*4],COp0B
mov dword[edi+0Ch*4],COp0Cm8
mov dword[edi+0Dh*4],COp0Dm8
mov dword[edi+0Eh*4],COp0Em8
mov dword[edi+0Fh*4],COp0Fm8
mov dword[edi+10h*4],COp10
mov dword[edi+11h*4],COp11m8
mov dword[edi+12h*4],COp12m8
mov dword[edi+13h*4],COp13m8
mov dword[edi+14h*4],COp14m8
mov dword[edi+15h*4],COp15m8
mov dword[edi+16h*4],COp16m8
mov dword[edi+17h*4],COp17m8
mov dword[edi+18h*4],COp18
mov dword[edi+19h*4],COp19m8
mov dword[edi+1Ah*4],COp1Am8
mov dword[edi+1Bh*4],COp1B
mov dword[edi+1Ch*4],COp1Cm8
mov dword[edi+1Dh*4],COp1Dm8
mov dword[edi+1Eh*4],COp1Em8
mov dword[edi+1Fh*4],COp1Fm8
mov dword[edi+20h*4],COp20
mov dword[edi+21h*4],COp21m8
mov dword[edi+22h*4],COp22
mov dword[edi+23h*4],COp23m8
mov dword[edi+24h*4],COp24m8
mov dword[edi+25h*4],COp25m8
mov dword[edi+26h*4],COp26m8
mov dword[edi+27h*4],COp27m8
mov dword[edi+28h*4],COp28
mov dword[edi+29h*4],COp29m8
mov dword[edi+2Ah*4],COp2Am8
mov dword[edi+2Bh*4],COp2B
mov dword[edi+2Ch*4],COp2Cm8
mov dword[edi+2Dh*4],COp2Dm8
mov dword[edi+2Eh*4],COp2Em8
mov dword[edi+2Fh*4],COp2Fm8
mov dword[edi+30h*4],COp30
mov dword[edi+31h*4],COp31m8
mov dword[edi+32h*4],COp32m8
mov dword[edi+33h*4],COp33m8
mov dword[edi+34h*4],COp34m8
mov dword[edi+35h*4],COp35m8
mov dword[edi+36h*4],COp36m8
mov dword[edi+37h*4],COp37m8
mov dword[edi+38h*4],COp38
mov dword[edi+39h*4],COp39m8
mov dword[edi+3Ah*4],COp3Am8
mov dword[edi+3Bh*4],COp3B
mov dword[edi+3Ch*4],COp3Cm8
mov dword[edi+3Dh*4],COp3Dm8
mov dword[edi+3Eh*4],COp3Em8
mov dword[edi+3Fh*4],COp3Fm8
mov dword[edi+40h*4],COp40
mov dword[edi+41h*4],COp41m8
mov dword[edi+42h*4],COp42
mov dword[edi+43h*4],COp43m8
mov dword[edi+44h*4],COp44
mov dword[edi+45h*4],COp45m8
mov dword[edi+46h*4],COp46m8
mov dword[edi+47h*4],COp47m8
mov dword[edi+48h*4],COp48m8
mov dword[edi+49h*4],COp49m8
mov dword[edi+4Ah*4],COp4Am8
mov dword[edi+4Bh*4],COp4B
mov dword[edi+4Ch*4],COp4C
mov dword[edi+4Dh*4],COp4Dm8
mov dword[edi+4Eh*4],COp4Em8
mov dword[edi+4Fh*4],COp4Fm8
mov dword[edi+50h*4],COp50
mov dword[edi+51h*4],COp51m8
mov dword[edi+52h*4],COp52m8
mov dword[edi+53h*4],COp53m8
mov dword[edi+54h*4],COp54
mov dword[edi+55h*4],COp55m8
mov dword[edi+56h*4],COp56m8
mov dword[edi+57h*4],COp57m8
mov dword[edi+58h*4],COp58
mov dword[edi+59h*4],COp59m8
mov dword[edi+5Ah*4],COp5Ax8
mov dword[edi+5Bh*4],COp5B
mov dword[edi+5Ch*4],COp5C
mov dword[edi+5Dh*4],COp5Dm8
mov dword[edi+5Eh*4],COp5Em8
mov dword[edi+5Fh*4],COp5Fm8
mov dword[edi+60h*4],COp60
mov dword[edi+61h*4],COp61m8nd
mov dword[edi+62h*4],COp62
mov dword[edi+63h*4],COp63m8nd
mov dword[edi+64h*4],COp64m8
mov dword[edi+65h*4],COp65m8nd
mov dword[edi+66h*4],COp66m8
mov dword[edi+67h*4],COp67m8nd
mov dword[edi+68h*4],COp68m8
mov dword[edi+69h*4],COp69m8nd
mov dword[edi+6Ah*4],COp6Am8
mov dword[edi+6Bh*4],COp6B
mov dword[edi+6Ch*4],COp6C
mov dword[edi+6Dh*4],COp6Dm8nd
mov dword[edi+6Eh*4],COp6Em8
mov dword[edi+6Fh*4],COp6Fm8nd
mov dword[edi+70h*4],COp70
mov dword[edi+71h*4],COp71m8nd
mov dword[edi+72h*4],COp72m8nd
mov dword[edi+73h*4],COp73m8nd
mov dword[edi+74h*4],COp74m8
mov dword[edi+75h*4],COp75m8nd
mov dword[edi+76h*4],COp76m8
mov dword[edi+77h*4],COp77m8nd
mov dword[edi+78h*4],COp78
mov dword[edi+79h*4],COp79m8nd
mov dword[edi+7Ah*4],COp7Ax8
mov dword[edi+7Bh*4],COp7B
mov dword[edi+7Ch*4],COp7C
mov dword[edi+7Dh*4],COp7Dm8nd
mov dword[edi+7Eh*4],COp7Em8
mov dword[edi+7Fh*4],COp7Fm8nd
mov dword[edi+80h*4],COp80
mov dword[edi+81h*4],COp81m8
mov dword[edi+82h*4],COp82
mov dword[edi+83h*4],COp83m8
mov dword[edi+84h*4],COp84x8
mov dword[edi+85h*4],COp85m8
mov dword[edi+86h*4],COp86x8
mov dword[edi+87h*4],COp87m8
mov dword[edi+88h*4],COp88x8
mov dword[edi+89h*4],COp89m8
mov dword[edi+8Ah*4],COp8Am8
mov dword[edi+8Bh*4],COp8B
mov dword[edi+8Ch*4],COp8Cx8
mov dword[edi+8Dh*4],COp8Dm8
mov dword[edi+8Eh*4],COp8Ex8
mov dword[edi+8Fh*4],COp8Fm8
mov dword[edi+90h*4],COp90
mov dword[edi+91h*4],COp91m8
mov dword[edi+92h*4],COp92m8
mov dword[edi+93h*4],COp93m8
mov dword[edi+94h*4],COp94x8
mov dword[edi+95h*4],COp95m8
mov dword[edi+96h*4],COp96x8
mov dword[edi+97h*4],COp97m8
mov dword[edi+98h*4],COp98m8
mov dword[edi+99h*4],COp99m8
mov dword[edi+9Ah*4],COp9A
mov dword[edi+9Bh*4],COp9Bx8
mov dword[edi+9Ch*4],COp9Cm8
mov dword[edi+9Dh*4],COp9Dm8
mov dword[edi+9Eh*4],COp9Em8
mov dword[edi+9Fh*4],COp9Fm8
mov dword[edi+0A0h*4],COpA0x8
mov dword[edi+0A1h*4],COpA1m8
mov dword[edi+0A2h*4],COpA2x8
mov dword[edi+0A3h*4],COpA3m8
mov dword[edi+0A4h*4],COpA4x8
mov dword[edi+0A5h*4],COpA5m8
mov dword[edi+0A6h*4],COpA6x8
mov dword[edi+0A7h*4],COpA7m8
mov dword[edi+0A8h*4],COpA8x8
mov dword[edi+0A9h*4],COpA9m8
mov dword[edi+0AAh*4],COpAAx8
mov dword[edi+0ABh*4],COpAB
mov dword[edi+0ACh*4],COpACx8
mov dword[edi+0ADh*4],COpADm8
mov dword[edi+0AEh*4],COpAEx8
mov dword[edi+0AFh*4],COpAFm8
mov dword[edi+0B0h*4],COpB0
mov dword[edi+0B1h*4],COpB1m8
mov dword[edi+0B2h*4],COpB2m8
mov dword[edi+0B3h*4],COpB3m8
mov dword[edi+0B4h*4],COpB4x8
mov dword[edi+0B5h*4],COpB5m8
mov dword[edi+0B6h*4],COpB6x8
mov dword[edi+0B7h*4],COpB7m8
mov dword[edi+0B8h*4],COpB8
mov dword[edi+0B9h*4],COpB9m8
mov dword[edi+0BAh*4],COpBAx8
mov dword[edi+0BBh*4],COpBBx8
mov dword[edi+0BCh*4],COpBCx8
mov dword[edi+0BDh*4],COpBDm8
mov dword[edi+0BEh*4],COpBEx8
mov dword[edi+0BFh*4],COpBFm8
mov dword[edi+0C0h*4],COpC0x8
mov dword[edi+0C1h*4],COpC1m8
mov dword[edi+0C2h*4],COpC2
mov dword[edi+0C3h*4],COpC3m8
mov dword[edi+0C4h*4],COpC4x8
mov dword[edi+0C5h*4],COpC5m8
mov dword[edi+0C6h*4],COpC6m8
mov dword[edi+0C7h*4],COpC7m8
mov dword[edi+0C8h*4],COpC8x8
mov dword[edi+0C9h*4],COpC9m8
mov dword[edi+0CAh*4],COpCAx8
mov dword[edi+0CBh*4],COpCB
mov dword[edi+0CCh*4],COpCCx8
mov dword[edi+0CDh*4],COpCDm8
mov dword[edi+0CEh*4],COpCEm8
mov dword[edi+0CFh*4],COpCFm8
mov dword[edi+0D0h*4],COpD0
mov dword[edi+0D1h*4],COpD1m8
mov dword[edi+0D2h*4],COpD2m8
mov dword[edi+0D3h*4],COpD3m8
mov dword[edi+0D4h*4],COpD4
mov dword[edi+0D5h*4],COpD5m8
mov dword[edi+0D6h*4],COpD6m8
mov dword[edi+0D7h*4],COpD7m8
mov dword[edi+0D8h*4],COpD8
mov dword[edi+0D9h*4],COpD9m8
mov dword[edi+0DAh*4],COpDAx8
mov dword[edi+0DBh*4],COpDB
mov dword[edi+0DCh*4],COpDC
mov dword[edi+0DDh*4],COpDDm8
mov dword[edi+0DEh*4],COpDEm8
mov dword[edi+0DFh*4],COpDFm8
mov dword[edi+0E0h*4],COpE0x8
mov dword[edi+0E1h*4],COpE1m8nd
mov dword[edi+0E2h*4],COpE2
mov dword[edi+0E3h*4],COpE3m8nd
mov dword[edi+0E4h*4],COpE4x8
mov dword[edi+0E5h*4],COpE5m8nd
mov dword[edi+0E6h*4],COpE6m8
mov dword[edi+0E7h*4],COpE7m8nd
mov dword[edi+0E8h*4],COpE8x8
mov dword[edi+0E9h*4],COpE9m8nd
mov dword[edi+0EAh*4],COpEA
mov dword[edi+0EBh*4],COpEB
mov dword[edi+0ECh*4],COpECx8
mov dword[edi+0EDh*4],COpEDm8nd
mov dword[edi+0EEh*4],COpEEm8
mov dword[edi+0EFh*4],COpEFm8nd
mov dword[edi+0F0h*4],COpF0
mov dword[edi+0F1h*4],COpF1m8nd
mov dword[edi+0F2h*4],COpF2m8nd
mov dword[edi+0F3h*4],COpF3m8nd
mov dword[edi+0F4h*4],COpF4
mov dword[edi+0F5h*4],COpF5m8nd
mov dword[edi+0F6h*4],COpF6m8
mov dword[edi+0F7h*4],COpF7m8nd
mov dword[edi+0F8h*4],COpF8
mov dword[edi+0F9h*4],COpF9m8nd
mov dword[edi+0FAh*4],COpFAx8
mov dword[edi+0FBh*4],COpFB
mov dword[edi+0FCh*4],COpFC
mov dword[edi+0FDh*4],COpFDm8nd
mov dword[edi+0FEh*4],COpFEm8
mov dword[edi+0FFh*4],COpFFm8nd
ret
NEWSYM settablem16
mov dword[edi+01h*4],COp01m16
mov dword[edi+03h*4],COp03m16
mov dword[edi+04h*4],COp04m16
mov dword[edi+05h*4],COp05m16
mov dword[edi+06h*4],COp06m16
mov dword[edi+07h*4],COp07m16
mov dword[edi+09h*4],COp09m16
mov dword[edi+0Ah*4],COp0Am16
mov dword[edi+0Ch*4],COp0Cm16
mov dword[edi+0Dh*4],COp0Dm16
mov dword[edi+0Eh*4],COp0Em16
mov dword[edi+0Fh*4],COp0Fm16
mov dword[edi+11h*4],COp11m16
mov dword[edi+12h*4],COp12m16
mov dword[edi+13h*4],COp13m16
mov dword[edi+14h*4],COp14m16
mov dword[edi+15h*4],COp15m16
mov dword[edi+16h*4],COp16m16
mov dword[edi+17h*4],COp17m16
mov dword[edi+19h*4],COp19m16
mov dword[edi+1Ah*4],COp1Am16
mov dword[edi+1Ch*4],COp1Cm16
mov dword[edi+1Dh*4],COp1Dm16
mov dword[edi+1Eh*4],COp1Em16
mov dword[edi+1Fh*4],COp1Fm16
mov dword[edi+21h*4],COp21m16
mov dword[edi+23h*4],COp23m16
mov dword[edi+24h*4],COp24m16
mov dword[edi+25h*4],COp25m16
mov dword[edi+26h*4],COp26m16
mov dword[edi+27h*4],COp27m16
mov dword[edi+29h*4],COp29m16
mov dword[edi+2Ah*4],COp2Am16
mov dword[edi+2Ch*4],COp2Cm16
mov dword[edi+2Dh*4],COp2Dm16
mov dword[edi+2Eh*4],COp2Em16
mov dword[edi+2Fh*4],COp2Fm16
mov dword[edi+31h*4],COp31m16
mov dword[edi+32h*4],COp32m16
mov dword[edi+33h*4],COp33m16
mov dword[edi+34h*4],COp34m16
mov dword[edi+35h*4],COp35m16
mov dword[edi+36h*4],COp36m16
mov dword[edi+37h*4],COp37m16
mov dword[edi+39h*4],COp39m16
mov dword[edi+3Ah*4],COp3Am16
mov dword[edi+3Ch*4],COp3Cm16
mov dword[edi+3Dh*4],COp3Dm16
mov dword[edi+3Eh*4],COp3Em16
mov dword[edi+3Fh*4],COp3Fm16
mov dword[edi+41h*4],COp41m16
mov dword[edi+43h*4],COp43m16
mov dword[edi+45h*4],COp45m16
mov dword[edi+46h*4],COp46m16
mov dword[edi+47h*4],COp47m16
mov dword[edi+48h*4],COp48m16
mov dword[edi+49h*4],COp49m16
mov dword[edi+4Ah*4],COp4Am16
mov dword[edi+4Dh*4],COp4Dm16
mov dword[edi+4Eh*4],COp4Em16
mov dword[edi+4Fh*4],COp4Fm16
mov dword[edi+51h*4],COp51m16
mov dword[edi+52h*4],COp52m16
mov dword[edi+53h*4],COp53m16
mov dword[edi+55h*4],COp55m16
mov dword[edi+56h*4],COp56m16
mov dword[edi+57h*4],COp57m16
mov dword[edi+59h*4],COp59m16
mov dword[edi+5Dh*4],COp5Dm16
mov dword[edi+5Eh*4],COp5Em16
mov dword[edi+5Fh*4],COp5Fm16
mov dword[edi+61h*4],COp61m16nd
mov dword[edi+63h*4],COp63m16nd
mov dword[edi+64h*4],COp64m16
mov dword[edi+65h*4],COp65m16nd
mov dword[edi+66h*4],COp66m16
mov dword[edi+67h*4],COp67m16nd
mov dword[edi+68h*4],COp68m16
mov dword[edi+69h*4],COp69m16nd
mov dword[edi+6Ah*4],COp6Am16
mov dword[edi+6Dh*4],COp6Dm16nd
mov dword[edi+6Eh*4],COp6Em16
mov dword[edi+6Fh*4],COp6Fm16nd
mov dword[edi+71h*4],COp71m16nd
mov dword[edi+72h*4],COp72m16nd
mov dword[edi+73h*4],COp73m16nd
mov dword[edi+74h*4],COp74m16
mov dword[edi+75h*4],COp75m16nd
mov dword[edi+76h*4],COp76m16
mov dword[edi+77h*4],COp77m16nd
mov dword[edi+79h*4],COp79m16nd
mov dword[edi+7Dh*4],COp7Dm16nd
mov dword[edi+7Eh*4],COp7Em16
mov dword[edi+7Fh*4],COp7Fm16nd
mov dword[edi+81h*4],COp81m16
mov dword[edi+83h*4],COp83m16
mov dword[edi+85h*4],COp85m16
mov dword[edi+87h*4],COp87m16
mov dword[edi+89h*4],COp89m16
mov dword[edi+8Ah*4],COp8Am16
mov dword[edi+8Dh*4],COp8Dm16
mov dword[edi+8Fh*4],COp8Fm16
mov dword[edi+91h*4],COp91m16
mov dword[edi+92h*4],COp92m16
mov dword[edi+93h*4],COp93m16
mov dword[edi+95h*4],COp95m16
mov dword[edi+97h*4],COp97m16
mov dword[edi+98h*4],COp98m16
mov dword[edi+99h*4],COp99m16
mov dword[edi+9Ch*4],COp9Cm16
mov dword[edi+9Dh*4],COp9Dm16
mov dword[edi+9Eh*4],COp9Em16
mov dword[edi+9Fh*4],COp9Fm16
mov dword[edi+0A1h*4],COpA1m16
mov dword[edi+0A3h*4],COpA3m16
mov dword[edi+0A5h*4],COpA5m16
mov dword[edi+0A7h*4],COpA7m16
mov dword[edi+0A9h*4],COpA9m16
mov dword[edi+0ADh*4],COpADm16
mov dword[edi+0AFh*4],COpAFm16
mov dword[edi+0B1h*4],COpB1m16
mov dword[edi+0B2h*4],COpB2m16
mov dword[edi+0B3h*4],COpB3m16
mov dword[edi+0B5h*4],COpB5m16
mov dword[edi+0B7h*4],COpB7m16
mov dword[edi+0B9h*4],COpB9m16
mov dword[edi+0BDh*4],COpBDm16
mov dword[edi+0BFh*4],COpBFm16
mov dword[edi+0C1h*4],COpC1m16
mov dword[edi+0C3h*4],COpC3m16
mov dword[edi+0C5h*4],COpC5m16
mov dword[edi+0C6h*4],COpC6m16
mov dword[edi+0C7h*4],COpC7m16
mov dword[edi+0C9h*4],COpC9m16
mov dword[edi+0CDh*4],COpCDm16
mov dword[edi+0CEh*4],COpCEm16
mov dword[edi+0CFh*4],COpCFm16
mov dword[edi+0D1h*4],COpD1m16
mov dword[edi+0D2h*4],COpD2m16
mov dword[edi+0D3h*4],COpD3m16
mov dword[edi+0D5h*4],COpD5m16
mov dword[edi+0D6h*4],COpD6m16
mov dword[edi+0D7h*4],COpD7m16
mov dword[edi+0D9h*4],COpD9m16
mov dword[edi+0DDh*4],COpDDm16
mov dword[edi+0DEh*4],COpDEm16
mov dword[edi+0DFh*4],COpDFm16
mov dword[edi+0E1h*4],COpE1m16nd
mov dword[edi+0E3h*4],COpE3m16nd
mov dword[edi+0E5h*4],COpE5m16nd
mov dword[edi+0E6h*4],COpE6m16
mov dword[edi+0E7h*4],COpE7m16nd
mov dword[edi+0E9h*4],COpE9m16nd
mov dword[edi+0EDh*4],COpEDm16nd
mov dword[edi+0EEh*4],COpEEm16
mov dword[edi+0EFh*4],COpEFm16nd
mov dword[edi+0F1h*4],COpF1m16nd
mov dword[edi+0F2h*4],COpF2m16nd
mov dword[edi+0F3h*4],COpF3m16nd
mov dword[edi+0F5h*4],COpF5m16nd
mov dword[edi+0F6h*4],COpF6m16
mov dword[edi+0F7h*4],COpF7m16nd
mov dword[edi+0F9h*4],COpF9m16nd
mov dword[edi+0FDh*4],COpFDm16nd
mov dword[edi+0FEh*4],COpFEm16
mov dword[edi+0FFh*4],COpFFm16nd
ret
NEWSYM settablex16
mov dword[edi+5Ah*4],COp5Ax16
mov dword[edi+7Ah*4],COp7Ax16
mov dword[edi+84h*4],COp84x16
mov dword[edi+86h*4],COp86x16
mov dword[edi+88h*4],COp88x16
mov dword[edi+8Ch*4],COp8Cx16
mov dword[edi+8Eh*4],COp8Ex16
mov dword[edi+94h*4],COp94x16
mov dword[edi+96h*4],COp96x16
mov dword[edi+9Bh*4],COp9Bx16
mov dword[edi+0A0h*4],COpA0x16
mov dword[edi+0A2h*4],COpA2x16
mov dword[edi+0A4h*4],COpA4x16
mov dword[edi+0A6h*4],COpA6x16
mov dword[edi+0A8h*4],COpA8x16
mov dword[edi+0AAh*4],COpAAx16
mov dword[edi+0ACh*4],COpACx16
mov dword[edi+0AEh*4],COpAEx16
mov dword[edi+0B4h*4],COpB4x16
mov dword[edi+0B6h*4],COpB6x16
mov dword[edi+0BAh*4],COpBAx16
mov dword[edi+0BBh*4],COpBBx16
mov dword[edi+0BCh*4],COpBCx16
mov dword[edi+0BEh*4],COpBEx16
mov dword[edi+0C0h*4],COpC0x16
mov dword[edi+0C4h*4],COpC4x16
mov dword[edi+0C8h*4],COpC8x16
mov dword[edi+0CAh*4],COpCAx16
mov dword[edi+0CCh*4],COpCCx16
mov dword[edi+0DAh*4],COpDAx16
mov dword[edi+0E0h*4],COpE0x16
mov dword[edi+0E4h*4],COpE4x16
mov dword[edi+0E8h*4],COpE8x16
mov dword[edi+0ECh*4],COpECx16
mov dword[edi+0FAh*4],COpFAx16
ret
NEWSYM settableDm8
mov dword[edi+61h*4],COp61m8d
mov dword[edi+63h*4],COp63m8d
mov dword[edi+65h*4],COp65m8d
mov dword[edi+67h*4],COp67m8d
mov dword[edi+69h*4],COp69m8d
mov dword[edi+6Dh*4],COp6Dm8d
mov dword[edi+6Fh*4],COp6Fm8d
mov dword[edi+71h*4],COp71m8d
mov dword[edi+72h*4],COp72m8d
mov dword[edi+73h*4],COp73m8d
mov dword[edi+75h*4],COp75m8d
mov dword[edi+77h*4],COp77m8d
mov dword[edi+79h*4],COp79m8d
mov dword[edi+7Dh*4],COp7Dm8d
mov dword[edi+7Fh*4],COp7Fm8d
mov dword[edi+0E1h*4],COpE1m8d
mov dword[edi+0E3h*4],COpE3m8d
mov dword[edi+0E5h*4],COpE5m8d
mov dword[edi+0E7h*4],COpE7m8d
mov dword[edi+0E9h*4],COpE9m8d
mov dword[edi+0EDh*4],COpEDm8d
mov dword[edi+0EFh*4],COpEFm8d
mov dword[edi+0F1h*4],COpF1m8d
mov dword[edi+0F2h*4],COpF2m8d
mov dword[edi+0F3h*4],COpF3m8d
mov dword[edi+0F5h*4],COpF5m8d
mov dword[edi+0F7h*4],COpF7m8d
mov dword[edi+0F9h*4],COpF9m8d
mov dword[edi+0FDh*4],COpFDm8d
mov dword[edi+0FFh*4],COpFFm8d
ret
NEWSYM settableDm16
mov dword[edi+61h*4],COp61m16d
mov dword[edi+63h*4],COp63m16d
mov dword[edi+65h*4],COp65m16d
mov dword[edi+67h*4],COp67m16d
mov dword[edi+69h*4],COp69m16d
mov dword[edi+6Dh*4],COp6Dm16d
mov dword[edi+6Fh*4],COp6Fm16d
mov dword[edi+71h*4],COp71m16d
mov dword[edi+72h*4],COp72m16d
mov dword[edi+73h*4],COp73m16d
mov dword[edi+75h*4],COp75m16d
mov dword[edi+77h*4],COp77m16d
mov dword[edi+79h*4],COp79m16d
mov dword[edi+7Dh*4],COp7Dm16d
mov dword[edi+7Fh*4],COp7Fm16d
mov dword[edi+0E1h*4],COpE1m16d
mov dword[edi+0E3h*4],COpE3m16d
mov dword[edi+0E5h*4],COpE5m16d
mov dword[edi+0E7h*4],COpE7m16d
mov dword[edi+0E9h*4],COpE9m16d
mov dword[edi+0EDh*4],COpEDm16d
mov dword[edi+0EFh*4],COpEFm16d
mov dword[edi+0F1h*4],COpF1m16d
mov dword[edi+0F2h*4],COpF2m16d
mov dword[edi+0F3h*4],COpF3m16d
mov dword[edi+0F5h*4],COpF5m16d
mov dword[edi+0F7h*4],COpF7m16d
mov dword[edi+0F9h*4],COpF9m16d
mov dword[edi+0FDh*4],COpFDm16d
mov dword[edi+0FFh*4],COpFFm16d
ret

714
zsnes/src/cpu/tablec.asm Normal file
View File

@@ -0,0 +1,714 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM tableAc,tableBc,tableCc,tableDc,tableEc
EXTSYM tableFc,tableGc,tableHc,tableadc
%include "cpu/65816dc.inc"
%include "cpu/address.inc"
%include "cpu/addrni.inc"
%include "cpu/e65816c.inc"
; global variables
;*******************************************************
; Generate OpCode Table
;*******************************************************
SECTION .text
NEWSYM inittablec
; set tablead (NVMXDIZC) ( MXD )
push es
xor ecx,ecx
xor al,al
mov cx,256
mov edi,tableadc
.loopa
test al,08h ; D flag
jnz .decon
test al,10h ; X flag
jnz .xon
test al,20h ; M flag
jnz .mon
mov esi,tableAc
jmp .done
.mon
mov esi,tableBc
jmp .done
.xon
test al,20h ; M flag
jnz .mon2
mov esi,tableCc
jmp .done
.mon2
mov esi,tableDc
jmp .done
.decon
test al,10h ; X flag
jnz .xon3
test al,20h ; M flag
jnz .mon3
mov esi,tableEc
jmp .done
.mon3
mov esi,tableFc
jmp .done
.xon3
test al,20h
jnz .mon4
mov esi,tableGc
jmp .done
.mon4
mov esi,tableHc
.done
inc al
push eax
mov eax,esi
stosd
pop eax
dec ecx
jnz .loopa
; Set CPU addresses
; First, set all addresses to invalid
mov eax,eopINVALID
mov edi,tableAc
mov ecx,256
rep stosd
mov edi,tableBc
mov ecx,256
rep stosd
mov edi,tableCc
mov ecx,256
rep stosd
mov edi,tableDc
mov ecx,256
rep stosd
mov edi,tableEc
mov ecx,256
rep stosd
mov edi,tableFc
mov ecx,256
rep stosd
mov edi,tableGc
mov ecx,256
rep stosd
mov edi,tableHc
mov ecx,256
rep stosd
mov edi,tableAc
call settables
mov edi,tableBc
call settables
mov edi,tableCc
call settables
mov edi,tableDc
call settables
mov edi,tableEc
call settables
mov edi,tableFc
call settables
mov edi,tableGc
call settables
mov edi,tableHc
call settables
; set proper functions
mov edi,tableAc ; Table addresses (M:0,X:0,D:0)
call settablem16
mov edi,tableAc
call settablex16
mov edi,tableBc ; Table addresses (M:1,X:0,D:0)
call settablex16
mov edi,tableCc ; Table addresses (M:0,X:1,D:0)
call settablem16
mov edi,tableEc ; Table addresses (M:0,X:0,D:1)
call settablem16
mov edi,tableEc
call settableDm16
mov edi,tableEc
call settablex16
mov edi,tableFc ; Table addresses (M:1,X:0,D:1)
call settablex16
mov edi,tableFc
call settableDm8
mov edi,tableGc ; Table addresses (M:0,X:1,D:1)
call settablem16
mov edi,tableGc
call settableDm16
mov edi,tableHc ; Table addresses (M:1,X:1,D:1)
call settableDm8
pop es
ret
eopINVALID
ret
;*******************************************************
; Set Tables Sets the opcode tables according to EDI
;*******************************************************
; This function sets all the non-multiple entries
settables:
;row 0
mov dword[edi+00h*4],COp00
mov dword[edi+01h*4],COp01m8
mov dword[edi+02h*4],COp02
mov dword[edi+03h*4],COp03m8
mov dword[edi+04h*4],COp04m8
mov dword[edi+05h*4],COp05m8
mov dword[edi+06h*4],COp06m8
mov dword[edi+07h*4],COp07m8
mov dword[edi+08h*4],COp08
mov dword[edi+09h*4],COp09m8
mov dword[edi+0Ah*4],COp0Am8
mov dword[edi+0Bh*4],COp0B
mov dword[edi+0Ch*4],COp0Cm8
mov dword[edi+0Dh*4],COp0Dm8
mov dword[edi+0Eh*4],COp0Em8
mov dword[edi+0Fh*4],COp0Fm8
mov dword[edi+10h*4],COp10
mov dword[edi+11h*4],COp11m8
mov dword[edi+12h*4],COp12m8
mov dword[edi+13h*4],COp13m8
mov dword[edi+14h*4],COp14m8
mov dword[edi+15h*4],COp15m8
mov dword[edi+16h*4],COp16m8
mov dword[edi+17h*4],COp17m8
mov dword[edi+18h*4],COp18
mov dword[edi+19h*4],COp19m8
mov dword[edi+1Ah*4],COp1Am8
mov dword[edi+1Bh*4],COp1B
mov dword[edi+1Ch*4],COp1Cm8
mov dword[edi+1Dh*4],COp1Dm8
mov dword[edi+1Eh*4],COp1Em8
mov dword[edi+1Fh*4],COp1Fm8
mov dword[edi+20h*4],COp20
mov dword[edi+21h*4],COp21m8
mov dword[edi+22h*4],COp22
mov dword[edi+23h*4],COp23m8
mov dword[edi+24h*4],COp24m8
mov dword[edi+25h*4],COp25m8
mov dword[edi+26h*4],COp26m8
mov dword[edi+27h*4],COp27m8
mov dword[edi+28h*4],COp28
mov dword[edi+29h*4],COp29m8
mov dword[edi+2Ah*4],COp2Am8
mov dword[edi+2Bh*4],COp2B
mov dword[edi+2Ch*4],COp2Cm8
mov dword[edi+2Dh*4],COp2Dm8
mov dword[edi+2Eh*4],COp2Em8
mov dword[edi+2Fh*4],COp2Fm8
mov dword[edi+30h*4],COp30
mov dword[edi+31h*4],COp31m8
mov dword[edi+32h*4],COp32m8
mov dword[edi+33h*4],COp33m8
mov dword[edi+34h*4],COp34m8
mov dword[edi+35h*4],COp35m8
mov dword[edi+36h*4],COp36m8
mov dword[edi+37h*4],COp37m8
mov dword[edi+38h*4],COp38
mov dword[edi+39h*4],COp39m8
mov dword[edi+3Ah*4],COp3Am8
mov dword[edi+3Bh*4],COp3B
mov dword[edi+3Ch*4],COp3Cm8
mov dword[edi+3Dh*4],COp3Dm8
mov dword[edi+3Eh*4],COp3Em8
mov dword[edi+3Fh*4],COp3Fm8
mov dword[edi+40h*4],COp40
mov dword[edi+41h*4],COp41m8
mov dword[edi+42h*4],COp42
mov dword[edi+43h*4],COp43m8
mov dword[edi+44h*4],COp44
mov dword[edi+45h*4],COp45m8
mov dword[edi+46h*4],COp46m8
mov dword[edi+47h*4],COp47m8
mov dword[edi+48h*4],COp48m8
mov dword[edi+49h*4],COp49m8
mov dword[edi+4Ah*4],COp4Am8
mov dword[edi+4Bh*4],COp4B
mov dword[edi+4Ch*4],COp4C
mov dword[edi+4Dh*4],COp4Dm8
mov dword[edi+4Eh*4],COp4Em8
mov dword[edi+4Fh*4],COp4Fm8
mov dword[edi+50h*4],COp50
mov dword[edi+51h*4],COp51m8
mov dword[edi+52h*4],COp52m8
mov dword[edi+53h*4],COp53m8
mov dword[edi+54h*4],COp54
mov dword[edi+55h*4],COp55m8
mov dword[edi+56h*4],COp56m8
mov dword[edi+57h*4],COp57m8
mov dword[edi+58h*4],COp58
mov dword[edi+59h*4],COp59m8
mov dword[edi+5Ah*4],COp5Ax8
mov dword[edi+5Bh*4],COp5B
mov dword[edi+5Ch*4],COp5C
mov dword[edi+5Dh*4],COp5Dm8
mov dword[edi+5Eh*4],COp5Em8
mov dword[edi+5Fh*4],COp5Fm8
mov dword[edi+60h*4],COp60
mov dword[edi+61h*4],COp61m8nd
mov dword[edi+62h*4],COp62
mov dword[edi+63h*4],COp63m8nd
mov dword[edi+64h*4],COp64m8
mov dword[edi+65h*4],COp65m8nd
mov dword[edi+66h*4],COp66m8
mov dword[edi+67h*4],COp67m8nd
mov dword[edi+68h*4],COp68m8
mov dword[edi+69h*4],COp69m8nd
mov dword[edi+6Ah*4],COp6Am8
mov dword[edi+6Bh*4],COp6B
mov dword[edi+6Ch*4],COp6C
mov dword[edi+6Dh*4],COp6Dm8nd
mov dword[edi+6Eh*4],COp6Em8
mov dword[edi+6Fh*4],COp6Fm8nd
mov dword[edi+70h*4],COp70
mov dword[edi+71h*4],COp71m8nd
mov dword[edi+72h*4],COp72m8nd
mov dword[edi+73h*4],COp73m8nd
mov dword[edi+74h*4],COp74m8
mov dword[edi+75h*4],COp75m8nd
mov dword[edi+76h*4],COp76m8
mov dword[edi+77h*4],COp77m8nd
mov dword[edi+78h*4],COp78
mov dword[edi+79h*4],COp79m8nd
mov dword[edi+7Ah*4],COp7Ax8
mov dword[edi+7Bh*4],COp7B
mov dword[edi+7Ch*4],COp7C
mov dword[edi+7Dh*4],COp7Dm8nd
mov dword[edi+7Eh*4],COp7Em8
mov dword[edi+7Fh*4],COp7Fm8nd
mov dword[edi+80h*4],COp80
mov dword[edi+81h*4],COp81m8
mov dword[edi+82h*4],COp82
mov dword[edi+83h*4],COp83m8
mov dword[edi+84h*4],COp84x8
mov dword[edi+85h*4],COp85m8
mov dword[edi+86h*4],COp86x8
mov dword[edi+87h*4],COp87m8
mov dword[edi+88h*4],COp88x8
mov dword[edi+89h*4],COp89m8
mov dword[edi+8Ah*4],COp8Am8
mov dword[edi+8Bh*4],COp8B
mov dword[edi+8Ch*4],COp8Cx8
mov dword[edi+8Dh*4],COp8Dm8
mov dword[edi+8Eh*4],COp8Ex8
mov dword[edi+8Fh*4],COp8Fm8
mov dword[edi+90h*4],COp90
mov dword[edi+91h*4],COp91m8
mov dword[edi+92h*4],COp92m8
mov dword[edi+93h*4],COp93m8
mov dword[edi+94h*4],COp94x8
mov dword[edi+95h*4],COp95m8
mov dword[edi+96h*4],COp96x8
mov dword[edi+97h*4],COp97m8
mov dword[edi+98h*4],COp98m8
mov dword[edi+99h*4],COp99m8
mov dword[edi+9Ah*4],COp9A
mov dword[edi+9Bh*4],COp9Bx8
mov dword[edi+9Ch*4],COp9Cm8
mov dword[edi+9Dh*4],COp9Dm8
mov dword[edi+9Eh*4],COp9Em8
mov dword[edi+9Fh*4],COp9Fm8
mov dword[edi+0A0h*4],COpA0x8
mov dword[edi+0A1h*4],COpA1m8
mov dword[edi+0A2h*4],COpA2x8
mov dword[edi+0A3h*4],COpA3m8
mov dword[edi+0A4h*4],COpA4x8
mov dword[edi+0A5h*4],COpA5m8
mov dword[edi+0A6h*4],COpA6x8
mov dword[edi+0A7h*4],COpA7m8
mov dword[edi+0A8h*4],COpA8x8
mov dword[edi+0A9h*4],COpA9m8
mov dword[edi+0AAh*4],COpAAx8
mov dword[edi+0ABh*4],COpAB
mov dword[edi+0ACh*4],COpACx8
mov dword[edi+0ADh*4],COpADm8
mov dword[edi+0AEh*4],COpAEx8
mov dword[edi+0AFh*4],COpAFm8
mov dword[edi+0B0h*4],COpB0
mov dword[edi+0B1h*4],COpB1m8
mov dword[edi+0B2h*4],COpB2m8
mov dword[edi+0B3h*4],COpB3m8
mov dword[edi+0B4h*4],COpB4x8
mov dword[edi+0B5h*4],COpB5m8
mov dword[edi+0B6h*4],COpB6x8
mov dword[edi+0B7h*4],COpB7m8
mov dword[edi+0B8h*4],COpB8
mov dword[edi+0B9h*4],COpB9m8
mov dword[edi+0BAh*4],COpBAx8
mov dword[edi+0BBh*4],COpBBx8
mov dword[edi+0BCh*4],COpBCx8
mov dword[edi+0BDh*4],COpBDm8
mov dword[edi+0BEh*4],COpBEx8
mov dword[edi+0BFh*4],COpBFm8
mov dword[edi+0C0h*4],COpC0x8
mov dword[edi+0C1h*4],COpC1m8
mov dword[edi+0C2h*4],COpC2
mov dword[edi+0C3h*4],COpC3m8
mov dword[edi+0C4h*4],COpC4x8
mov dword[edi+0C5h*4],COpC5m8
mov dword[edi+0C6h*4],COpC6m8
mov dword[edi+0C7h*4],COpC7m8
mov dword[edi+0C8h*4],COpC8x8
mov dword[edi+0C9h*4],COpC9m8
mov dword[edi+0CAh*4],COpCAx8
mov dword[edi+0CBh*4],COpCB
mov dword[edi+0CCh*4],COpCCx8
mov dword[edi+0CDh*4],COpCDm8
mov dword[edi+0CEh*4],COpCEm8
mov dword[edi+0CFh*4],COpCFm8
mov dword[edi+0D0h*4],COpD0
mov dword[edi+0D1h*4],COpD1m8
mov dword[edi+0D2h*4],COpD2m8
mov dword[edi+0D3h*4],COpD3m8
mov dword[edi+0D4h*4],COpD4
mov dword[edi+0D5h*4],COpD5m8
mov dword[edi+0D6h*4],COpD6m8
mov dword[edi+0D7h*4],COpD7m8
mov dword[edi+0D8h*4],COpD8
mov dword[edi+0D9h*4],COpD9m8
mov dword[edi+0DAh*4],COpDAx8
mov dword[edi+0DBh*4],COpDB
mov dword[edi+0DCh*4],COpDC
mov dword[edi+0DDh*4],COpDDm8
mov dword[edi+0DEh*4],COpDEm8
mov dword[edi+0DFh*4],COpDFm8
mov dword[edi+0E0h*4],COpE0x8
mov dword[edi+0E1h*4],COpE1m8nd
mov dword[edi+0E2h*4],COpE2
mov dword[edi+0E3h*4],COpE3m8nd
mov dword[edi+0E4h*4],COpE4x8
mov dword[edi+0E5h*4],COpE5m8nd
mov dword[edi+0E6h*4],COpE6m8
mov dword[edi+0E7h*4],COpE7m8nd
mov dword[edi+0E8h*4],COpE8x8
mov dword[edi+0E9h*4],COpE9m8nd
mov dword[edi+0EAh*4],COpEA
mov dword[edi+0EBh*4],COpEB
mov dword[edi+0ECh*4],COpECx8
mov dword[edi+0EDh*4],COpEDm8nd
mov dword[edi+0EEh*4],COpEEm8
mov dword[edi+0EFh*4],COpEFm8nd
mov dword[edi+0F0h*4],COpF0
mov dword[edi+0F1h*4],COpF1m8nd
mov dword[edi+0F2h*4],COpF2m8nd
mov dword[edi+0F3h*4],COpF3m8nd
mov dword[edi+0F4h*4],COpF4
mov dword[edi+0F5h*4],COpF5m8nd
mov dword[edi+0F6h*4],COpF6m8
mov dword[edi+0F7h*4],COpF7m8nd
mov dword[edi+0F8h*4],COpF8
mov dword[edi+0F9h*4],COpF9m8nd
mov dword[edi+0FAh*4],COpFAx8
mov dword[edi+0FBh*4],COpFB
mov dword[edi+0FCh*4],COpFC
mov dword[edi+0FDh*4],COpFDm8nd
mov dword[edi+0FEh*4],COpFEm8
mov dword[edi+0FFh*4],COpFFm8nd
ret
settablem16:
mov dword[edi+01h*4],COp01m16
mov dword[edi+03h*4],COp03m16
mov dword[edi+04h*4],COp04m16
mov dword[edi+05h*4],COp05m16
mov dword[edi+06h*4],COp06m16
mov dword[edi+07h*4],COp07m16
mov dword[edi+09h*4],COp09m16
mov dword[edi+0Ah*4],COp0Am16
mov dword[edi+0Ch*4],COp0Cm16
mov dword[edi+0Dh*4],COp0Dm16
mov dword[edi+0Eh*4],COp0Em16
mov dword[edi+0Fh*4],COp0Fm16
mov dword[edi+11h*4],COp11m16
mov dword[edi+12h*4],COp12m16
mov dword[edi+13h*4],COp13m16
mov dword[edi+14h*4],COp14m16
mov dword[edi+15h*4],COp15m16
mov dword[edi+16h*4],COp16m16
mov dword[edi+17h*4],COp17m16
mov dword[edi+19h*4],COp19m16
mov dword[edi+1Ah*4],COp1Am16
mov dword[edi+1Ch*4],COp1Cm16
mov dword[edi+1Dh*4],COp1Dm16
mov dword[edi+1Eh*4],COp1Em16
mov dword[edi+1Fh*4],COp1Fm16
mov dword[edi+21h*4],COp21m16
mov dword[edi+23h*4],COp23m16
mov dword[edi+24h*4],COp24m16
mov dword[edi+25h*4],COp25m16
mov dword[edi+26h*4],COp26m16
mov dword[edi+27h*4],COp27m16
mov dword[edi+29h*4],COp29m16
mov dword[edi+2Ah*4],COp2Am16
mov dword[edi+2Ch*4],COp2Cm16
mov dword[edi+2Dh*4],COp2Dm16
mov dword[edi+2Eh*4],COp2Em16
mov dword[edi+2Fh*4],COp2Fm16
mov dword[edi+31h*4],COp31m16
mov dword[edi+32h*4],COp32m16
mov dword[edi+33h*4],COp33m16
mov dword[edi+34h*4],COp34m16
mov dword[edi+35h*4],COp35m16
mov dword[edi+36h*4],COp36m16
mov dword[edi+37h*4],COp37m16
mov dword[edi+39h*4],COp39m16
mov dword[edi+3Ah*4],COp3Am16
mov dword[edi+3Ch*4],COp3Cm16
mov dword[edi+3Dh*4],COp3Dm16
mov dword[edi+3Eh*4],COp3Em16
mov dword[edi+3Fh*4],COp3Fm16
mov dword[edi+41h*4],COp41m16
mov dword[edi+43h*4],COp43m16
mov dword[edi+45h*4],COp45m16
mov dword[edi+46h*4],COp46m16
mov dword[edi+47h*4],COp47m16
mov dword[edi+48h*4],COp48m16
mov dword[edi+49h*4],COp49m16
mov dword[edi+4Ah*4],COp4Am16
mov dword[edi+4Dh*4],COp4Dm16
mov dword[edi+4Eh*4],COp4Em16
mov dword[edi+4Fh*4],COp4Fm16
mov dword[edi+51h*4],COp51m16
mov dword[edi+52h*4],COp52m16
mov dword[edi+53h*4],COp53m16
mov dword[edi+55h*4],COp55m16
mov dword[edi+56h*4],COp56m16
mov dword[edi+57h*4],COp57m16
mov dword[edi+59h*4],COp59m16
mov dword[edi+5Dh*4],COp5Dm16
mov dword[edi+5Eh*4],COp5Em16
mov dword[edi+5Fh*4],COp5Fm16
mov dword[edi+61h*4],COp61m16nd
mov dword[edi+63h*4],COp63m16nd
mov dword[edi+64h*4],COp64m16
mov dword[edi+65h*4],COp65m16nd
mov dword[edi+66h*4],COp66m16
mov dword[edi+67h*4],COp67m16nd
mov dword[edi+68h*4],COp68m16
mov dword[edi+69h*4],COp69m16nd
mov dword[edi+6Ah*4],COp6Am16
mov dword[edi+6Dh*4],COp6Dm16nd
mov dword[edi+6Eh*4],COp6Em16
mov dword[edi+6Fh*4],COp6Fm16nd
mov dword[edi+71h*4],COp71m16nd
mov dword[edi+72h*4],COp72m16nd
mov dword[edi+73h*4],COp73m16nd
mov dword[edi+74h*4],COp74m16
mov dword[edi+75h*4],COp75m16nd
mov dword[edi+76h*4],COp76m16
mov dword[edi+77h*4],COp77m16nd
mov dword[edi+79h*4],COp79m16nd
mov dword[edi+7Dh*4],COp7Dm16nd
mov dword[edi+7Eh*4],COp7Em16
mov dword[edi+7Fh*4],COp7Fm16nd
mov dword[edi+81h*4],COp81m16
mov dword[edi+83h*4],COp83m16
mov dword[edi+85h*4],COp85m16
mov dword[edi+87h*4],COp87m16
mov dword[edi+89h*4],COp89m16
mov dword[edi+8Ah*4],COp8Am16
mov dword[edi+8Dh*4],COp8Dm16
mov dword[edi+8Fh*4],COp8Fm16
mov dword[edi+91h*4],COp91m16
mov dword[edi+92h*4],COp92m16
mov dword[edi+93h*4],COp93m16
mov dword[edi+95h*4],COp95m16
mov dword[edi+97h*4],COp97m16
mov dword[edi+98h*4],COp98m16
mov dword[edi+99h*4],COp99m16
mov dword[edi+9Ch*4],COp9Cm16
mov dword[edi+9Dh*4],COp9Dm16
mov dword[edi+9Eh*4],COp9Em16
mov dword[edi+9Fh*4],COp9Fm16
mov dword[edi+0A1h*4],COpA1m16
mov dword[edi+0A3h*4],COpA3m16
mov dword[edi+0A5h*4],COpA5m16
mov dword[edi+0A7h*4],COpA7m16
mov dword[edi+0A9h*4],COpA9m16
mov dword[edi+0ADh*4],COpADm16
mov dword[edi+0AFh*4],COpAFm16
mov dword[edi+0B1h*4],COpB1m16
mov dword[edi+0B2h*4],COpB2m16
mov dword[edi+0B3h*4],COpB3m16
mov dword[edi+0B5h*4],COpB5m16
mov dword[edi+0B7h*4],COpB7m16
mov dword[edi+0B9h*4],COpB9m16
mov dword[edi+0BDh*4],COpBDm16
mov dword[edi+0BFh*4],COpBFm16
mov dword[edi+0C1h*4],COpC1m16
mov dword[edi+0C3h*4],COpC3m16
mov dword[edi+0C5h*4],COpC5m16
mov dword[edi+0C6h*4],COpC6m16
mov dword[edi+0C7h*4],COpC7m16
mov dword[edi+0C9h*4],COpC9m16
mov dword[edi+0CDh*4],COpCDm16
mov dword[edi+0CEh*4],COpCEm16
mov dword[edi+0CFh*4],COpCFm16
mov dword[edi+0D1h*4],COpD1m16
mov dword[edi+0D2h*4],COpD2m16
mov dword[edi+0D3h*4],COpD3m16
mov dword[edi+0D5h*4],COpD5m16
mov dword[edi+0D6h*4],COpD6m16
mov dword[edi+0D7h*4],COpD7m16
mov dword[edi+0D9h*4],COpD9m16
mov dword[edi+0DDh*4],COpDDm16
mov dword[edi+0DEh*4],COpDEm16
mov dword[edi+0DFh*4],COpDFm16
mov dword[edi+0E1h*4],COpE1m16nd
mov dword[edi+0E3h*4],COpE3m16nd
mov dword[edi+0E5h*4],COpE5m16nd
mov dword[edi+0E6h*4],COpE6m16
mov dword[edi+0E7h*4],COpE7m16nd
mov dword[edi+0E9h*4],COpE9m16nd
mov dword[edi+0EDh*4],COpEDm16nd
mov dword[edi+0EEh*4],COpEEm16
mov dword[edi+0EFh*4],COpEFm16nd
mov dword[edi+0F1h*4],COpF1m16nd
mov dword[edi+0F2h*4],COpF2m16nd
mov dword[edi+0F3h*4],COpF3m16nd
mov dword[edi+0F5h*4],COpF5m16nd
mov dword[edi+0F6h*4],COpF6m16
mov dword[edi+0F7h*4],COpF7m16nd
mov dword[edi+0F9h*4],COpF9m16nd
mov dword[edi+0FDh*4],COpFDm16nd
mov dword[edi+0FEh*4],COpFEm16
mov dword[edi+0FFh*4],COpFFm16nd
ret
settablex16:
mov dword[edi+5Ah*4],COp5Ax16
mov dword[edi+7Ah*4],COp7Ax16
mov dword[edi+84h*4],COp84x16
mov dword[edi+86h*4],COp86x16
mov dword[edi+88h*4],COp88x16
mov dword[edi+8Ch*4],COp8Cx16
mov dword[edi+8Eh*4],COp8Ex16
mov dword[edi+94h*4],COp94x16
mov dword[edi+96h*4],COp96x16
mov dword[edi+9Bh*4],COp9Bx16
mov dword[edi+0A0h*4],COpA0x16
mov dword[edi+0A2h*4],COpA2x16
mov dword[edi+0A4h*4],COpA4x16
mov dword[edi+0A6h*4],COpA6x16
mov dword[edi+0A8h*4],COpA8x16
mov dword[edi+0AAh*4],COpAAx16
mov dword[edi+0ACh*4],COpACx16
mov dword[edi+0AEh*4],COpAEx16
mov dword[edi+0B4h*4],COpB4x16
mov dword[edi+0B6h*4],COpB6x16
mov dword[edi+0BAh*4],COpBAx16
mov dword[edi+0BBh*4],COpBBx16
mov dword[edi+0BCh*4],COpBCx16
mov dword[edi+0BEh*4],COpBEx16
mov dword[edi+0C0h*4],COpC0x16
mov dword[edi+0C4h*4],COpC4x16
mov dword[edi+0C8h*4],COpC8x16
mov dword[edi+0CAh*4],COpCAx16
mov dword[edi+0CCh*4],COpCCx16
mov dword[edi+0DAh*4],COpDAx16
mov dword[edi+0E0h*4],COpE0x16
mov dword[edi+0E4h*4],COpE4x16
mov dword[edi+0E8h*4],COpE8x16
mov dword[edi+0ECh*4],COpECx16
mov dword[edi+0FAh*4],COpFAx16
ret
settableDm8:
mov dword[edi+61h*4],COp61m8d
mov dword[edi+63h*4],COp63m8d
mov dword[edi+65h*4],COp65m8d
mov dword[edi+67h*4],COp67m8d
mov dword[edi+69h*4],COp69m8d
mov dword[edi+6Dh*4],COp6Dm8d
mov dword[edi+6Fh*4],COp6Fm8d
mov dword[edi+71h*4],COp71m8d
mov dword[edi+72h*4],COp72m8d
mov dword[edi+73h*4],COp73m8d
mov dword[edi+75h*4],COp75m8d
mov dword[edi+77h*4],COp77m8d
mov dword[edi+79h*4],COp79m8d
mov dword[edi+7Dh*4],COp7Dm8d
mov dword[edi+7Fh*4],COp7Fm8d
mov dword[edi+0E1h*4],COpE1m8d
mov dword[edi+0E3h*4],COpE3m8d
mov dword[edi+0E5h*4],COpE5m8d
mov dword[edi+0E7h*4],COpE7m8d
mov dword[edi+0E9h*4],COpE9m8d
mov dword[edi+0EDh*4],COpEDm8d
mov dword[edi+0EFh*4],COpEFm8d
mov dword[edi+0F1h*4],COpF1m8d
mov dword[edi+0F2h*4],COpF2m8d
mov dword[edi+0F3h*4],COpF3m8d
mov dword[edi+0F5h*4],COpF5m8d
mov dword[edi+0F7h*4],COpF7m8d
mov dword[edi+0F9h*4],COpF9m8d
mov dword[edi+0FDh*4],COpFDm8d
mov dword[edi+0FFh*4],COpFFm8d
ret
settableDm16:
mov dword[edi+61h*4],COp61m16d
mov dword[edi+63h*4],COp63m16d
mov dword[edi+65h*4],COp65m16d
mov dword[edi+67h*4],COp67m16d
mov dword[edi+69h*4],COp69m16d
mov dword[edi+6Dh*4],COp6Dm16d
mov dword[edi+6Fh*4],COp6Fm16d
mov dword[edi+71h*4],COp71m16d
mov dword[edi+72h*4],COp72m16d
mov dword[edi+73h*4],COp73m16d
mov dword[edi+75h*4],COp75m16d
mov dword[edi+77h*4],COp77m16d
mov dword[edi+79h*4],COp79m16d
mov dword[edi+7Dh*4],COp7Dm16d
mov dword[edi+7Fh*4],COp7Fm16d
mov dword[edi+0E1h*4],COpE1m16d
mov dword[edi+0E3h*4],COpE3m16d
mov dword[edi+0E5h*4],COpE5m16d
mov dword[edi+0E7h*4],COpE7m16d
mov dword[edi+0E9h*4],COpE9m16d
mov dword[edi+0EDh*4],COpEDm16d
mov dword[edi+0EFh*4],COpEFm16d
mov dword[edi+0F1h*4],COpF1m16d
mov dword[edi+0F2h*4],COpF2m16d
mov dword[edi+0F3h*4],COpF3m16d
mov dword[edi+0F5h*4],COpF5m16d
mov dword[edi+0F7h*4],COpF7m16d
mov dword[edi+0F9h*4],COpF9m16d
mov dword[edi+0FDh*4],COpFDm16d
mov dword[edi+0FFh*4],COpFFm16d
ret

262
zsnes/src/debugasm.asm Normal file
View File

@@ -0,0 +1,262 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; Stuff that looked like too much trouble to port
%include "macros.mac"
EXTSYM snesmmap, snesmap2, memtabler8, memtablew8, regaccessbankr8, dmadata
EXTSYM initaddrl, spcPCRam, UpdateDPage, pdh, numinst, writeon
EXTSYM xp, xpb, xpc, curcyc, Curtableaddr, splitflags, execsingle, joinflags
;;; from debugger.c
EXTSYM PrevBreakPt_page, PrevBreakPt_offset, my_getch_ret, my_getch
SECTION .text
;; Wrapper for calls to routines in memtabler8
NEWSYM memtabler8_wrapper
push ebp
mov ebp, esp
push ebx
push edi
push esi
movzx ebx, BYTE [ebp+8]
movzx ecx, WORD [ebp+12]
xor eax, eax
mov al, bl
call DWORD [memtabler8+eax*4]
and eax, 255
pop esi
pop edi
pop ebx
pop ebp
ret
NEWSYM memtablew8_wrapper
push ebp
mov ebp, esp
push ebx
push edi
push esi
movzx ebx, BYTE [ebp+8]
movzx ecx, WORD [ebp+12]
movzx eax, BYTE [ebp+16]
mov byte[writeon],1
call DWORD [memtablew8+ebx*4]
mov byte[writeon],0
and eax, 255
pop esi
pop edi
pop ebx
pop ebp
ret
NEWSYM breakops_wrapper
push ebp
mov ebp, esp
pushad
movzx ebx, BYTE [PrevBreakPt_page]
movzx ecx, WORD [PrevBreakPt_offset]
call breakops
popad
pop ebp
ret
;*******************************************************
; BreakOps Breaks at Breakpoint
;*******************************************************
NEWSYM breakops
; set cursor to (12,60)
mov [PrevBreakPt_offset],cx
mov [PrevBreakPt_page],bl
; push ebx
; mov ah,02h
; mov bl,0
; mov dh,12
; mov dl,60
; int 10h
; pop ebx
test cx,8000h
jz .loweraddr2
mov esi,[snesmmap+ebx*4]
jmp .skiplower2
.loweraddr2
mov esi,[snesmap2+ebx*4]
.skiplower2
add esi,ecx ; add program counter to address
mov [breakarea],esi
;; factored out
; mov byte[wx],14
; mov byte[wx2],65
; mov byte[wy],11
; mov byte[wy2],13
; call drawwindow
; mov ax,[selcB800]
; mov es,ax
; mov edi,12*160+18*2
; mov esi,.message1
; mov ecx,42
; mov ah,31
; .loopb
; lodsb
; stosw
; dec ecx
; jnz .loopb
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 ebp,[spcPCRam]
mov dl,[xp] ; set flags
mov dh,[curcyc] ; set cycles
mov edi,[Curtableaddr]
call UpdateDPage
; execute
.loopa
call splitflags
call execsingle
call joinflags
mov dh,[pdh]
inc dword[numinst]
cmp byte[numinst],0
jne .skipa
;; not DOS anymore
; mov ah,0bh
; int 21h
; test al,0FFh
; jz .skipa
; mov ah,07h
; int 21h
pushad
call my_getch
popad
mov eax, [my_getch_ret]
cmp eax,27
je .skipc
.skipa
cmp esi,[breakarea]
jne .loopa
.skipc
; copy back data
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
ret
SECTION .data
NEWSYM breakarea, dd 0
SECTION .text
;*******************************************************
; Execute Next Opcode
;*******************************************************
NEWSYM execnextop
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 ebp,[spcPCRam]
mov dl,[xp] ; set flags
mov dh,[curcyc] ; set cycles
mov edi,[Curtableaddr]
call splitflags
call execsingle
call joinflags
call UpdateDPage
; execute
; copy back data
mov [spcPCRam],ebp
mov [Curtableaddr],edi
mov [xp],dl
mov dh,[pdh]
mov [curcyc],dh
mov eax,[initaddrl]
sub esi,eax ; subtract program counter by address
mov [xpc],si
inc dword[numinst]
ret

1436
zsnes/src/debugger.c Normal file

File diff suppressed because it is too large Load Diff

935
zsnes/src/dos/dosintrf.asm Normal file
View File

@@ -0,0 +1,935 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM selcA000,selcB800,selc0040,previdmode,DosExit,
EXTSYM V8Mode,getblaster,Force8b,SBHDMA
EXTSYM oldhand9s,oldhand9o,interror,oldhand8s,oldhand8o,oldhandSBs,oldhandSBo
EXTSYM NoSoundReinit,soundon,DSPDisable,SBInt,PICMaskP,SBIrq,SBHandler,InitSB
EXTSYM handler8h,handler9h,init60hz,Interror,init18_2hz,DeInitSPC,GUIinit36_4hz
EXTSYM GUIoldhand9s,GUIoldhand9o,GUIoldhand8s,GUIoldhand8o,GUIhandler9h
EXTSYM GUIhandler8h,GUIinit18_2hz,dosinitvideo
EXTSYM DosDrawScreen,cvidmode,vidbuffer,GUICPC,DosDrawScreenB
EXTSYM DosUpdateDevices,DOSJoyRead,pl1contrl,pl2contrl,pl3contrl,pl4contrl
EXTSYM pl5contrl,GrayscaleMode
EXTSYM pl1upk,pl1downk,pl1leftk,pl1rightk,pl1startk,pl1selk
EXTSYM pl1Ak,pl1Bk,pl1Xk,pl1Yk,pl1Lk,pl1Rk
EXTSYM pl2upk,pl2downk,pl2leftk,pl2rightk,pl2startk,pl2selk
EXTSYM pl2Ak,pl2Bk,pl2Xk,pl2Yk,pl2Lk,pl2Rk
EXTSYM pl3upk,pl3downk,pl3leftk,pl3rightk,pl3startk,pl3selk
EXTSYM pl3Ak,pl3Bk,pl3Xk,pl3Yk,pl3Lk,pl3Rk
EXTSYM pl4upk,pl4downk,pl4leftk,pl4rightk,pl4startk,pl4selk
EXTSYM pl4Ak,pl4Bk,pl4Xk,pl4Yk,pl4Lk,pl4Rk
EXTSYM pl5upk,pl5downk,pl5leftk,pl5rightk,pl5startk,pl5selk
EXTSYM pl5Ak,pl5Bk,pl5Xk,pl5Yk,pl5Lk,pl5Rk
; NOTE: For timing, Game60hzcall should be called at 50hz or 60hz (depending
; on romispal) after a call to InitPreGame and before DeInitPostGame are
; made. GUI36hzcall should be called at 36hz after a call GUIInit and
; before GUIDeInit.
SECTION .data
NEWSYM dssel, dw 0
SECTION .text
NEWSYM StartUp
mov ax,901h ;enable interrupts
int 31h
mov ax,ds
mov [dssel],ax
mov bx,0A000h
call findselec
mov [selcA000],ax
mov bx,0B800h
call findselec
mov [selcB800],ax
mov bx,0040h
call findselec
mov [selc0040],ax
; get previous video mode
xor ecx,ecx
push es
mov ax,[selc0040]
mov es,ax
mov al,[es:49h]
mov [previdmode],al
pop es
; Get base address
mov ax,ds
mov bx,ax
mov eax,0006h
int 31h
jc .FatalError
mov [ZSNESBase+2],cx ; These variables are used for
mov [ZSNESBase],dx ; memory allocation so they can be
.FatalError ; ignored for non-DOS ports
ret
; SystemInit - Initialize all Joystick stuff, load in all configuration data,
; parse commandline data, obtain current directory (One time initialization)
NEWSYM SystemInit
; Be sure to set SBHDMA to a value other than 0 if 16bit sound exists
push es
call getblaster ; get set blaster environment
cmp byte[Force8b],1
jne .noforce8b
mov byte[SBHDMA],0
.noforce8b
pop es
ret
; Find Selector - DOS only
findselec:
mov ax, 2
int 31h
jnc .proceed
mov edx, .noselector
call PrintStr
jmp DosExit
.proceed
ret
SECTION .data
.noselector db 'Cannot find selector!',10,13,0
SECTION .text
NEWSYM PrintChar
; print character at dl, push all modified registers
push eax
mov ah,02h
int 21h
pop eax
ret
NEWSYM PrintStr ; Print ASCIIZ string
.next
mov al,[edx]
or al,al
jz .finish
push edx
mov dl,al
mov ah,02h
int 21h
pop edx
inc edx
jmp .next
.finish
ret
NEWSYM WaitForKey ; Wait for a key to be pressed
mov ah,7
int 21h
; return key in al
ret
%macro PressConv 3
cmp byte[pressed+%1],0
je %%nopr
test byte[prval],%2
jnz %%prskip
or byte[prval],%2
mov byte[prres],%3
; mov al,0FFh
jmp .done
jmp %%prskip
%%nopr
and byte[prval],%2^0FFh
%%prskip
%endmacro
NEWSYM Check_Key
; xor al,al
; PressConv 75,01h,75
; PressConv 77,02h,77
; PressConv 80,04h,80
; PressConv 72,08h,72
; PressConv 1,80h,27
;.done
; ret
; returns 0 if there are no keys in the keyboard buffer, 0xFF otherwise
mov ah,0Bh
int 21h
ret
NEWSYM Get_Key
; mov al,[prres]
; ret
; wait if there are no keys in buffer, then return key in al
; for extended keys, return a 0, then the extended key afterwards
mov ah,07h
int 21h
ret
NEWSYM Get_Memfree
mov ax,0500h
mov edi,edx
int 31h
ret
NEWSYM Output_Text ; Output character (ah=02h) or string (ah=09h)
; This function usually displays an error message on-screen
cmp ah,02h
je .char
cmp ah,09h
je .string
ret
.char
int 21h ; print dl
ret
.string
pushad
call PrintStr ; print edx
popad
ret
; Delay for CX/65536 of a second
NEWSYM delay
in al,61h
and al,10h
mov ah,al
.loopa
in al,61h
and al,10h
cmp al,ah
jz .loopa
mov ah,al
dec cx
jnz .loopa
ret
NEWSYM InitPreGame ; Executes before starting/continuing a game
; set up interrupt handler
; get old handler pmode mode address
; Process stuff such as sound init, interrupt initialization
cli
mov ax,204h
mov bl,09h
int 31h
jc near interror
mov [oldhand9s],cx
mov [oldhand9o],edx
mov ax,204h
mov bl,08h
int 31h
jc near interror
mov [oldhand8s],cx
mov [oldhand8o],edx
mov al,[GrayscaleMode]
cmp al,[V8Mode]
je .nochangemode
xor byte[V8Mode],1
xor al,al
.nochangemode
.nofs
cmp byte[NoSoundReinit],1
je .nosound
cmp byte[soundon],0
je .nosound
cmp byte[DSPDisable],1
je .nosound
mov ax,204h
mov bl,[SBInt]
int 31h
jc near Interror
mov [oldhandSBs],cx
mov [oldhandSBo],edx
.nosound
sti
ret
NEWSYM SetupPreGame ; Executes after pre-game init, can execute multiple
; times after a single InitPreGame
; set new handler
cmp byte[soundon],0
je near .nosound2
cmp byte[DSPDisable],1
je near .nosound2
; Turn off IRQ through controller
cli
xor dh,dh
mov dl,[PICMaskP]
mov cl,[SBIrq]
and cl,07h
mov al,01h
shl al,cl
mov bl,al
in al,dx
or al,bl
out dx,al
mov ax,205h
mov bl,[SBInt]
mov cx,cs
mov edx,SBHandler
int 31h
jc near interror
; Turn on IRQ through controller
xor dh,dh
mov dl,[PICMaskP]
mov cl,[SBIrq]
and cl,07h
mov al,01h
shl al,cl
not al
mov bl,al
in al,dx
and al,bl
out dx,al
call InitSB
sti
.nosound2
cli
mov ax,205h
mov bl,09h
mov cx,cs ; Requires CS rather than DS
mov edx,handler9h
int 31h
jc near interror
mov ax,205h
mov bl,08h
mov cx,cs ; Requires CS rather than DS
mov edx,handler8h
int 31h
jc near interror
call init60hz ; Set timer to 60/50Hz
.nofs2
sti
ret
NEWSYM DeInitPostGame ; Called after game is ended
; de-init interrupt handler
cli
mov cx,[oldhand9s]
mov edx,[oldhand9o]
mov ax,205h
mov bl,09h
int 31h
jc near interror
mov cx,[oldhand8s]
mov edx,[oldhand8o]
mov ax,205h
mov bl,08h
int 31h
jc near interror
call init18_2hz ; Set timer to 18.2Hz
.nofs3
sti
; DeINITSPC
cmp byte[soundon],0
je .nosoundb
cmp byte[DSPDisable],1
je .nosoundb
call DeInitSPC
mov cx,[oldhandSBs]
mov edx,[oldhandSBo]
mov ax,205h
mov bl,[SBInt]
int 31h
jc near interror
.nosoundb
ret
NEWSYM GUIInit
mov ax,204h
mov bl,09h
int 31h
mov [GUIoldhand9s],cx
mov [GUIoldhand9o],edx
mov ax,204h
mov bl,08h
int 31h
mov [GUIoldhand8s],cx
mov [GUIoldhand8o],edx
mov ax,205h
mov bl,09h
mov cx,cs
mov edx,GUIhandler9h
int 31h
mov ax,205h
mov bl,08h
mov cx,cs
mov edx,GUIhandler8h
int 31h
call GUIinit36_4hz
ret
NEWSYM GUIDeInit
mov cx,[GUIoldhand9s]
mov edx,[GUIoldhand9o]
mov ax,205h
mov bl,09h
int 31h
mov cx,[GUIoldhand8s]
mov edx,[GUIoldhand8o]
mov ax,205h
mov bl,08h
int 31h
call GUIinit18_2hz
ret
; ****************************
; Video Stuff
; ****************************
; ** Palette Functions **
NEWSYM displayfpspal
mov al,128
mov dx,03C8h
out dx,al
inc dx
mov al,63
out dx,al
out dx,al
out dx,al
mov al,128+64
mov dx,03C8h
out dx,al
inc dx
mov al,0
out dx,al
out dx,al
out dx,al
ret
NEWSYM superscopepal
mov al,128+16
mov dx,03C8h
out dx,al
inc dx
mov al,63
out dx,al
xor al,al
out dx,al
out dx,al
ret
NEWSYM saveselectpal
; set palette of colors 128,144, and 160 to white, blue, and red
mov al,128
mov dx,03C8h
out dx,al
inc dx
mov al,63
out dx,al
out dx,al
out dx,al
mov al,144
mov dx,03C8h
out dx,al
inc dx
xor al,al
out dx,al
out dx,al
mov al,50
out dx,al
mov al,160
mov dx,03C8h
out dx,al
inc dx
mov al,45
out dx,al
xor al,al
out dx,al
out dx,al
mov al,176
mov dx,03C8h
out dx,al
inc dx
mov al,47
out dx,al
xor al,al
out dx,al
out dx,al
mov al,208
mov dx,03C8h
out dx,al
inc dx
mov al,50
out dx,al
mov al,25
out dx,al
xor al,al
out dx,al
ret
; ** init video mode functions **
NEWSYM initvideo ; Returns 1 in videotroub if trouble occurs
jmp dosinitvideo
NEWSYM deinitvideo
mov al,[previdmode]
mov ah,0
int 10h
ret
; ** copy video mode functions **
NEWSYM DrawScreen ; In-game screen render w/ triple buffer check
jmp DosDrawScreen
NEWSYM vidpastecopyscr ; GUI screen render
; jmp dosvidpastecopyscr
pushad
movzx eax,byte[cvidmode]
cmp byte[GUI16VID+eax],1
jne .no16bconv
mov eax,[vidbuffer]
mov ecx,224*288
mov edx,ecx
sub ecx,288
dec edx
.loop
movzx ebx,byte[eax+edx]
mov bx,[GUICPC+ebx*2]
mov [eax+edx*2],bx
dec edx
dec ecx
jnz .loop
.no16bconv
popad
jmp DosDrawScreenB
; ** Video Mode Variables **
SECTION .data
; Total Number of Video Modes
NEWSYM NumVideoModes, dd 19
; GUI Video Mode Names - Make sure that all names are of the same length
; and end with a NULL terminator
NEWSYM GUIVideoModeNames
db '256x224x8B MODEQ',0 ; 0
db '256x240x8B MODEQ',0 ; 1
db '256x256x8B MODEQ',0 ; 2
db '320x224x8B MODEX',0 ; 3
db '320x240x8B MODEX',0 ; 4
db '320x256x8B MODEX',0 ; 5
db '640x480x16B VESA1',0 ; 6
db '320x240x8B VESA2',0 ; 7
db '320x240x16B VESA2',0 ; 8
db '320x480x8B VESA2',0 ; 9
db '320x480x16B VESA2',0 ; 10
db '512x384x8B VESA2',0 ; 11
db '512x384x16B VESA2',0 ; 12
db '640x400x8B VESA2',0 ; 13
db '640x400x16B VESA2',0 ; 14
db '640x480x8B VESA2',0 ; 15
db '640x480x16B VESA2',0 ; 16
db '800x600x8B VESA2',0 ; 17
db '800x600x16B VESA2',0 ; 18
; Video Mode Feature Availability (1 = Available, 0 = Not Available)
; Left side starts with Video Mode 0
; 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
NEWSYM GUI16VID, db 0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1 ; 16-bit mode
NEWSYM GUISLVID, db 0,0,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,1,1 ; Scanlines
NEWSYM GUIHSVID, db 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0 ; Half/Quarter Scanlines
NEWSYM GUII2VID, db 0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1 ; DOS Interpolation
NEWSYM GUIEAVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0 ; DOS Eagle
NEWSYM GUITBVID, db 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1 ; DOS Triple Buffering
NEWSYM GUIFSVID, db 0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0 ; DOS Fullscreen
NEWSYM GUIWSVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0 ; DOS Widescreen
NEWSYM GUISSVID, db 0,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1 ; DOS Smallscreen
NEWSYM GUI2xVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 ; 2xSaI/Super Engines
NEWSYM GUIM7VID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 ; Hires Mode 7
NEWSYM GUIHQ2X, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; (Hq2x Filter)
NEWSYM GUINTVID, db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; (NTSC Filter)
SECTION .text
; ****************************
; Input Device Stuff
; ****************************
; Variables related to Input Device Routines:
; pl1selk,pl1startk,pl1upk,pl1downk,pl1leftk,pl1rightk,pl1Xk,
; pl1Ak,pl1Lk,pl1Yk,pl1Bk,pl1Rk
; (Change 1 to 2,3,4 for other players)
; Each of these variables contains the corresponding key pressed value
; for the key data
; pressed[]
; - This is an array of pressed/released data (bytes) where the
; corresponding key pressed value is used as the index. The value
; for each entry is 0 for released and 1 for pressed. Also, when
; writing keyboard data to this array, be sure to first check if
; the value of the array entry is 2 or not. If it is 2, do not write 1
; to that array entry. (however, you can write 0 to it)
; As an example, to access Player 1 L button press data, it is
; done like : pressed[pl1Lk]
; The 3 character key description of that array entry is accessed by the
; GUI through ScanCodeListing[pl1Lk*3]
; Note: When storing the input device configuration of a dynamic input
; device system (ie. Win9x) rather than a static system (ie. Dos), it
; is best to store in the name of the device and relative button
; assignments in the configuration file, then convert it to ZSNES'
; numerical corresponding key format after reading from it. And then
; convert it back when writing to it back.
NEWSYM UpdateDevices ; One-time input device init
call DosUpdateDevices
ret
NEWSYM JoyRead
call DOSJoyRead
ret
%macro SetDefaultKey2 13
mov dword[%1upk],%4 ; Up
mov dword[%1downk],%5 ; Down
mov dword[%1leftk],%6 ; Left
mov dword[%1rightk],%7 ; Right
mov dword[%1startk],%3 ; Start
mov dword[%1selk],%2 ; Select
mov dword[%1Ak],%9 ; A
mov dword[%1Bk],%12 ; B
mov dword[%1Xk],%8 ; X
mov dword[%1Yk],%11 ; Y
mov dword[%1Lk],%10 ; L
mov dword[%1Rk],%13 ; R
%endmacro
%macro SetDefaultKey 12
cmp bh,0
jne %%nopl1
SetDefaultKey2 pl1,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12
%%nopl1
cmp bh,1
jne %%nopl2
SetDefaultKey2 pl2,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12
%%nopl2
cmp bh,2
jne %%nopl3
SetDefaultKey2 pl3,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12
%%nopl3
cmp bh,3
jne %%nopl4
SetDefaultKey2 pl4,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12
%%nopl4
cmp bh,4
jne %%nopl5
SetDefaultKey2 pl5,%1,%2,%3,%4,%5,%6,%7,%8,%9,%10,%11,%12
%%nopl5
%endmacro
NEWSYM SetInputDevice
; bl = device #, bh = player # (0-4)
; Sets keys according to input device selected
cmp bl,0
jne near .nozero
SetDefaultKey 0,0,0,0,0,0,0,0,0,0,0,0
ret
.nozero
cmp bl,1
jne near .nokeyb
cmp bh,1
ja near .exit
cmp bh,1
je near .input2
SetDefaultKey 54,28,72,80,75,77,31,45,32,30,44,46
ret
.input2
SetDefaultKey 56,29,36,50,49,51,82,71,73,83,79,81
ret
.nokeyb
cmp bl,2
jne near .no2buttons
xor bl,bl
cmp byte[pl1contrl],2
jne .nopl2a
inc bl
.nopl2a
cmp byte[pl2contrl],2
jne .nopl2b
inc bl
.nopl2b
cmp byte[pl3contrl],2
jne .nopl2c
inc bl
.nopl2c
cmp byte[pl4contrl],2
jne .nopl2d
inc bl
.nopl2d
cmp byte[pl5contrl],2
jne .nopl2e
inc bl
.nopl2e
cmp bl,2
jae .2ndjoyst
SetDefaultKey 0,0,0CCh,0CDh,0CEh,0CFh,0,0,0,82h,83h,0
ret
.2ndjoyst
SetDefaultKey 0,0,0E8h,0E9h,0EAh,0EBh,0,0,0,84h,85h,0
ret
.no2buttons
cmp bl,3
jne near .no4buttons
SetDefaultKey 0,0,0CCh,0CDh,0CEh,0CFh,84h,85h,0,82h,83h,0
ret
.no4buttons
cmp bl,4
jne near .no6buttons
SetDefaultKey 0,0,0CCh,0CDh,0CEh,0CFh,84h,85h,86h,82h,83h,87h
ret
.no6buttons
cmp bl,5
jne near .skip8b
SetDefaultKey 081h,080h,0CCh,0CDh,0CEh,0CFh,84h,85h,87h,82h,83h,86h
ret
.skip8b
cmp bl,6
jne near .nosw1
SetDefaultKey 0C9h,0C8h,0D4h,0D5h,0D6h,0D7h,08Ch,089h,08Eh,08Bh,088h,08Fh
ret
.nosw1
cmp bl,7
jne near .nosw2
SetDefaultKey 0C9h+8,0C8h+8,0D4h+8,0D5h+8,0D6h+8,0D7h+8,08Ch+8,089h+8,08Eh+8,08Bh+8,088h+8,08Fh+8
ret
.nosw2
cmp bl,8
jne near .nosw3
SetDefaultKey 0C9h+8*2,0C8h+8*2,0D4h+8*2,0D5h+8*2,0D6h+8*2,0D7h+8*2,08Ch+8*2,089h+8*2,08Eh+8*2,08Bh+8*2,088h+8*2,08Fh+8*2
ret
.nosw3
cmp bl,9
jne near .nosw4
SetDefaultKey 0C9h+8*3,0C8h+8*3,0D4h+8*3,0D5h+8*3,0D6h+8*3,0D7h+8*3,08Ch+8*3,089h+8*3,08Eh+8*3,08Bh+8*3,088h+8*3,08Fh+8*3
ret
.nosw4
cmp bl,10
jne near .nogrip0
SetDefaultKey 0CAh,0CBh,0F0h,0F1h,0F2h,0F3h,0A9h,0ABh,0ACh,0A8h,0AAh,0AEh
ret
.nogrip0
cmp bl,11
jne near .nogrip1
SetDefaultKey 0CAh+8,0CBh+8,0F0h+4,0F1h+4,0F2h+4,0F3h+4,0A9h+8,0ABh+8,0ACh+8,0A8h+8,0AAh+8,0AEh+8
ret
.nogrip1
cmp bl,12
jne near .nopp1
SetDefaultKey 182h,183h,184h,185h,186h,187h,189h,188h,18Ah,181h,180h,18Bh
ret
.nopp1
cmp bl,13
jne near .nopp2
SetDefaultKey 192h,193h,194h,195h,196h,197h,199h,198h,19Ah,191h,190h,19Bh
ret
.nopp2
cmp bl,14
jne near .nopp3
SetDefaultKey 1A2h,1A3h,1A4h,1A5h,1A6h,1A7h,1A9h,1A8h,1AAh,1A1h,1A0h,1ABh
ret
.nopp3
cmp bl,15
jne near .nopp4
SetDefaultKey 1B2h,1B3h,1B4h,1B5h,1B6h,1B7h,1B9h,1B8h,1BAh,1B1h,1B0h,1BBh
ret
.nopp4
cmp bl,16
jne near .nopp5
SetDefaultKey 1C2h,1C3h,1C4h,1C5h,1C6h,1C7h,1C9h,1C8h,1CAh,1C1h,1C0h,1CBh
ret
.nopp5
.exit
ret
SECTION .data
; Total Number of Input Devices
NEWSYM NumInputDevices, dd 17
; Input Device Names
NEWSYM GUIInputNames
db 'NONE ',0
db 'KEYBOARD ',0
db '2BUTTONJOYSTICK ',0
db '4BUTTONJOYSTICK ',0
db '6BUTTONJOYSTICK ',0
db '8BUTTONJOYSTICK ',0
db 'SIDEWINDERPAD1 ',0
db 'SIDEWINDERPAD2 ',0
db 'SIDEWINDERPAD3 ',0
db 'SIDEWINDERPAD4 ',0
db 'GAMEPAD PRO P0 ',0
db 'GAMEPAD PRO P1 ',0
db 'PARALLEL LPT1 P1',0
db 'PARALLEL LPT1 P2',0
db 'PARALLEL LPT1 P3',0
db 'PARALLEL LPT1 P4',0
db 'PARALLEL LPT1 P5',0
; GUI Description codes for each corresponding key pressed value
NEWSYM ScanCodeListing
db '---','ESC',' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 '
db ' 7 ',' 8 ',' 9 ',' 0 ',' - ',' = ','BKS','TAB'
db ' Q ',' W ',' E ',' R ',' T ',' Y ',' U ',' I '
db ' O ',' P ',' [ ',' ] ','RET','CTL',' A ',' S '
db ' D ',' F ',' G ',' H ',' J ',' K ',' L ',' : '
db ' " ',' ~ ','LSH',' \ ',' Z ',' X ',' C ',' V '
db ' B ',' N ',' M ',' , ',' . ',' / ','RSH',' * '
db 'ALT','SPC','CAP','F1 ','F2 ','F3 ','F4 ','F5 '
db 'F6 ','F7 ','F8 ','F9 ','F10','NUM','SCR','HOM'
db 'UP ','PGU',' - ','LFT',' 5 ','RGT',' + ','END'
db 'DWN','PGD','INS','DEL',' ',' ',' ','F11'
db 'F12',' ',' ',' ',' ',' ',' ',' '
db ' ',' ',' ',' ',' ',' ',' ',' '
db ' ',' ',' ',' ',' ',' ',' ',' '
db ' ',' ',' ',' ',' ',' ',' ',' '
db ' ',' ',' ',' ',' ',' ',' ',' '
; Joystick Stuff, Port 201h (80h)
db 'JB7','JB8','JB1','JB2','JB3','JB4','JB5','JB6'
db 'SWA','SWB','SWC','SWX','SWY','SWZ','SWL','SWR'
db 'S2A','S2B','S2C','S2X','S2Y','S2Z','S2L','S2R'
db 'S3A','S3B','S3C','S3X','S3Y','S3Z','S3L','S3R'
db 'S4A','S4B','S4C','S4X','S4Y','S4Z','S4L','S4R'
db 'GRR','GRB','GRY','GRG','GL1','GL2','GR1','GR2'
db 'G2R','G2B','G2Y','G2G','2L1','2L2','2R1','2R2'
db 'G3R','G3B','G3Y','G3G','3L1','3L2','3R1','3R2'
db 'G4R','G4B','G4Y','G4G','4L1','4L2','4R1','4R2'
db 'SWS','SWM','GSL','GST','JUP','JDN','JLF','JRG'
db 'S2S','S2M','2SL','2ST','SWU','SWD','SWL','SWR'
db 'S3S','S3M','3SL','3ST','S2U','S2D','S2L','S2R'
db 'S4S','S4M','4SL','4ST','S3U','S3D','S3L','S3R'
db 'J2U','J2D','J2L','J2R','S4U','S4D','S4L','S4R'
db 'GRU','GRD','GRL','GRR','G2U','G2D','G2L','G2R'
db 'G3U','G3D','G3L','G3R','G4U','G4D','G4L','G4R'
; Joystick Stuff, Port 209h (100h)
db 'JB7','JB8','JB1','JB2','JB3','JB4','JB5','JB6'
db 'SWA','SWB','SWC','SWX','SWY','SWZ','SWL','SWR'
db 'S2A','S2B','S2C','S2X','S2Y','S2Z','S2L','S2R'
db 'S3A','S3B','S3C','S3X','S3Y','S3Z','S3L','S3R'
db 'S4A','S4B','S4C','S4X','S4Y','S4Z','S4L','S4R'
db 'GRR','GRB','GRY','GRG','GL1','GL2','GR1','GR2'
db 'G2R','G2B','G2Y','G2G','2L1','2L2','2R1','2R2'
db 'G3R','G3B','G3Y','G3G','3L1','3L2','3R1','3R2'
db 'G4R','G4B','G4Y','G4G','4L1','4L2','4R1','4R2'
db 'SWS','SWM','GSL','GST','JUP','JDN','JLF','JRG'
db 'S2S','S2M','2SL','2ST','SWU','SWD','SWL','SWR'
db 'S3S','S3M','3SL','3ST','S2U','S2D','S2L','S2R'
db 'S4S','S4M','4SL','4ST','S3U','S3D','S3L','S3R'
db 'J2U','J2D','J2L','J2R','S4U','S4D','S4L','S4R'
db 'GRU','GRD','GRL','GRR','G2U','G2D','G2L','G2R'
db 'G3U','G3D','G3L','G3R','G4U','G4D','G4L','G4R'
; Extra Stuff (180h) (Parallel Port)
db 'PPB','PPY','PSL','PST','PUP','PDN','PLT','PRT'
db 'PPA','PPX','PPL','PPR',' ',' ',' ',' '
db 'P2B','P2Y','P2S','P2T','P2U','P2D','P2L','P2R'
db 'P2A','P2X','P2L','P2R',' ',' ',' ',' '
db 'P3B','P3Y','P3S','P3T','P3U','P3D','P3L','P3R'
db 'P3A','P3X','P3L','P3R',' ',' ',' ',' '
db 'P4B','P4Y','P4S','P4T','P4U','P4D','P4L','P4R'
db 'P4A','P4X','P4L','P4R',' ',' ',' ',' '
db 'P5B','P5Y','P5S','P5T','P5U','P5D','P5L','P5R'
db 'P5A','P5X','P5L','P5R',' ',' ',' ',' '
SECTION .bss
NEWSYM ZSNESBase, resd 1
TempVarSeek resd 1
SECTION .text
; ****************************
; Mouse Stuff
; ****************************
NEWSYM Init_Mouse
; return non-zero if successful
mov eax,00h
int 33h
cmp ax,0
je .nomouse
mov eax,07h
mov ecx,0
mov edx,255
int 33h
mov eax,08h
mov ecx,0
mov edx,223
int 33h
mov eax,0Fh
mov ecx,8
mov edx,8
int 33h
mov eax,04h
mov ecx,0
mov edx,0
int 33h
mov ax,1
.nomouse
ret
NEWSYM Get_MouseData ; Returns both pressed and coordinates
mov eax,03h
int 33h
; bx : bit 0 = left button, bit 1 = right button
; cx = Mouse X Position, dx = Mouse Y Position
ret
NEWSYM Set_MouseXMax ; Sets the X boundaries (ecx = left, edx = right)
mov eax,07h
int 33h
ret
NEWSYM Set_MouseYMax ; Sets the Y boundaries (ecx = left, edx = right)
mov eax,08h
int 33h
ret
NEWSYM Set_MousePosition ; Sets Mouse Position (x:cx,y:dx)
mov eax,04h
int 33h
ret
NEWSYM Get_MousePositionDisplacement
; returns x,y displacement in pixel in cx,dx
mov eax,0Bh
int 33h
ret
NEWSYM MouseWindow
ret
; ****************************
; Sound Stuff
; ****************************
NEWSYM StopSound
ret
NEWSYM StartSound
ret
NEWSYM Check60hz
; Call the timer update function here
ret

159
zsnes/src/dos/gppro.asm Normal file
View File

@@ -0,0 +1,159 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
section .data
sample times 60 db 0
clock_mask db 0
data_mask db 0
section .text
NEWSYM read_gpp
push ebx
push ecx
push edx
push edi
push esi
cmp al,0
jne GPP_L14
mov byte[clock_mask],0x10
mov byte[data_mask],0x20
jmp GPP_L15
GPP_L14:
mov byte[clock_mask],0x40
mov byte[data_mask],0x80
GPP_L15:
xor ebx,ebx
xor edi,edi
cli
in al,dx
mov ah,al
GPP_L4:
xor ecx,ecx
GPP_L0:
nop
nop
nop
nop
nop
nop
in al,dx
cmp al,ah
jne GPP_L1
inc ecx
cmp ecx,255
jl GPP_L0
GPP_L1:
cmp ecx,255
je near GPP_ERR
test [clock_mask],ah
jz GPP_L2
test [clock_mask],al
jnz GPP_L2
test [data_mask],al
jz GPP_L3
mov byte[sample+edi],1
jmp GPP_L12
GPP_L3:
mov byte[sample+edi],0
GPP_L12:
inc edi
GPP_L2:
mov ah,al
cmp ebx,200
je GPP_L13
inc ebx
cmp edi,50
jl GPP_L4
GPP_L13:
sti
xor ecx,ecx
mov esi,1
GPP_L7:
cmp byte[sample+esi],1
jg GPP_ERR
jne GPP_L6
inc ecx
jmp GPP_L5
GPP_L6:
xor ecx,ecx
GPP_L5:
cmp ecx,5
je GPP_L8
cmp esi,edi
je GPP_L8
inc esi
jmp GPP_L7
GPP_L8:
cmp ecx,5
jne GPP_ERR
add esi,2
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
GPP_L10:
inc ecx
cmp ecx,5
jne GPP_L11
mov ecx,1
inc esi
GPP_L11:
mov dl,[sample+esi]
or eax,edx
shl eax,1
cmp ebx,13
je GPP_L9
inc ebx
inc esi
jmp GPP_L10
GPP_L9:
pop esi
pop edi
pop edx
pop ecx
pop ebx
ret
GPP_ERR:
sti
pop esi
pop edi
pop edx
pop ecx
pop ebx
mov eax,1
ret

551
zsnes/src/dos/initvid.asm Normal file
View File

@@ -0,0 +1,551 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM InitVesa2,cbitmode,cvidmode,dosmakepal,scanlines,selcA000,vesa2_bits
EXTSYM vesa2_x,vesa2_y,vesa2selec,InitVesa12,videotroub,cscopymodeq,cscopymodex
EXTSYM res640,res480
SECTION .text
NEWSYM initvideo2
cmp byte[cvidmode],2
jne .nomodeq
jmp dosinitvideo.initmodeq256
.nomodeq
cmp byte[cvidmode],5
jne .nomodex
jmp dosinitvideo.initmodex256
.nomodex
;*******************************************************
; InitVideo
;*******************************************************
NEWSYM dosinitvideo
mov byte[cbitmode],0
mov byte[res640],0
mov byte[res480],0
cmp byte[cvidmode],0
je near .initmodeq224
cmp byte[cvidmode],1
je near .initmodeq240
cmp byte[cvidmode],2
je near .initmodeq256
cmp byte[cvidmode],3
je near .initmodex224
cmp byte[cvidmode],4
je near .initmodex240
cmp byte[cvidmode],5
je near .initmodex256
cmp byte[cvidmode],6
je near .initvesa12640x480x16
cmp byte[cvidmode],7
je near .initvesa2320x240x8
cmp byte[cvidmode],8
je near .initvesa2320x240x16
cmp byte[cvidmode],9
je near .initvesa2320x480x8
cmp byte[cvidmode],10
je near .initvesa2320x480x16
cmp byte[cvidmode],11
je near .initvesa2512x384x8
cmp byte[cvidmode],12
je near .initvesa2512x384x16
cmp byte[cvidmode],13
je near .initvesa2640x400x8
cmp byte[cvidmode],14
je near .initvesa2640x400x16
cmp byte[cvidmode],15
je near .initvesa2640x480x8
cmp byte[cvidmode],16
je near .initvesa2640x480x16
cmp byte[cvidmode],17
je near .initvesa2800x600x8
cmp byte[cvidmode],18
je near .initvesa2800x600x16
ret
%include "dos/vga.inc"
;*******************************************************
; InitModeQ 224 Sets up 256x224 chained mode
;*******************************************************
.initmodeq224
SetVGAMode .Mode256x224c
call cscopymodeq
call dosmakepal
ret
;*******************************************************
; InitModeQ 240 Sets up 256x240 chained mode
;*******************************************************
.initmodeq240
SetVGAMode .Mode256x240c
call cscopymodeq
call dosmakepal
ret
;*******************************************************
; InitModeQ 256 Sets up 256x256 chained mode
;*******************************************************
.initmodeq256
cmp byte[scanlines],1
je near .scanlines
SetVGAMode .Mode256x256c
jmp .done
.scanlines
SetVGAMode .Mode256x256cs
jmp .done
.done
call cscopymodeq
call dosmakepal
ret
;*******************************************************
; InitModeX 224 Sets up 320x224 unchained mode
;*******************************************************
.initmodex224
SetVGAMode .Mode320x224
call cscopymodex
call dosmakepal
ret
;*******************************************************
; InitModeX 240 Sets up 320x240 unchained mode
;*******************************************************
.initmodex240
SetVGAMode .Mode320x240
call cscopymodex
call dosmakepal
ret
;*******************************************************
; InitModeX 256 Sets up 320x256 unchained mode
;*******************************************************
.initmodex256
cmp byte[scanlines],1
je near .scanlines2
SetVGAMode .Mode320x256
jmp .done2
.scanlines2
SetVGAMode .Mode320x256s
jmp .done2
.done2
call cscopymodex
call dosmakepal
ret
;*******************************************************
; InitVESA2 320x240x8 Set up Linear 320x240x8b
;*******************************************************
.initvesa2320x240x8
mov byte[cbitmode],0
mov word[vesa2_x],320
mov word[vesa2_y],240
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble
ret
.notrouble
call dosmakepal
; clear screen (320*240 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,320*240
.loop
mov byte[es:edi],0
inc edi
dec ecx
jnz .loop
pop es
ret
;*******************************************************
; InitVESA2 320x240x16 Set up Linear 320x240x16b
;*******************************************************
.initvesa2320x240x16
mov byte[cbitmode],1
mov word[vesa2_x],320
mov word[vesa2_y],240
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble2
ret
.notrouble2
; clear screen (320*240*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,320*240*2
.loopb
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopb
pop es
ret
;*******************************************************
; InitVESA2 640x480x8 Set up Linear 640x480x8b
;*******************************************************
.initvesa2640x480x8
mov byte[res640],1
mov byte[res480],1
mov word[vesa2_x],640
mov word[vesa2_y],480
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble3
ret
.notrouble3
call dosmakepal
; clear screen (640*480 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,640*480
.loopc3
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopc3
pop es
ret
;*******************************************************
; InitVESA2 640x480x16 Set up Linear 640x480x16b
;*******************************************************
.initvesa2640x480x16
mov byte[res640],1
mov byte[res480],1
mov byte[cbitmode],1
mov word[vesa2_x],640
mov word[vesa2_y],480
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble4
ret
.notrouble4
; clear screen (640*480*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,640*480*2
.loopd3
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopd3
pop es
ret
;*******************************************************
; InitVESA2 800x600x8 Set up Linear 800x600x8b
;*******************************************************
.initvesa2800x600x8
mov byte[res640],1
mov byte[res480],1
mov word[vesa2_x],800
mov word[vesa2_y],600
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble11
ret
.notrouble11
call dosmakepal
; clear screen (800*600 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,800*600
.looph2
mov byte[es:edi],0
inc edi
dec ecx
jnz .looph2
pop es
ret
;*******************************************************
; InitVESA2 800x600x16 Set up Linear 800x600x16b
;*******************************************************
.initvesa2800x600x16
mov byte[res640],1
mov byte[res480],1
mov byte[cbitmode],1
mov word[vesa2_x],800
mov word[vesa2_y],600
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble12
ret
.notrouble12
; clear screen (800*600*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,800*600*2
.looph3
mov byte[es:edi],0
inc edi
dec ecx
jnz .looph3
pop es
ret
;*******************************************************
; InitVESA2 320x480x8 Set up Linear 320x480x8b
;*******************************************************
.initvesa2320x480x8
mov byte[res480],1
mov word[vesa2_x],320
mov word[vesa2_y],480
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble5
ret
.notrouble5
call dosmakepal
; clear screen (320*480 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,320*480
.loopc
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopc
pop es
ret
;*******************************************************
; InitVESA2 320x480x16 Set up Linear 320x480x16b
;*******************************************************
.initvesa2320x480x16
mov byte[res480],1
mov byte[cbitmode],1
mov word[vesa2_x],320
mov word[vesa2_y],480
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble6
ret
.notrouble6
; clear screen (320*480*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,320*480*2
.loopd
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopd
pop es
ret
;*******************************************************
; InitVESA2 512x384x8 Set up Linear 512x384x8b
;*******************************************************
.initvesa2512x384x8
mov byte[res640],2
mov byte[cbitmode],0
mov word[vesa2_x],512
mov word[vesa2_y],384
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble7
ret
.notrouble7
call dosmakepal
; clear screen (512*384 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,512*384
.loope
mov byte[es:edi],0
inc edi
dec ecx
jnz .loope
pop es
ret
;*******************************************************
; InitVESA2 512x384x16 Set up Linear 512x384x16b
;*******************************************************
.initvesa2512x384x16
mov byte[res640],2
mov byte[cbitmode],1
mov word[vesa2_x],512
mov word[vesa2_y],384
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble8
ret
.notrouble8
; clear screen (512*384*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,512*384*2
.loopf
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopf
pop es
ret
;*******************************************************
; InitVESA2 640x400x8 Set up Linear 640x400x8b
;*******************************************************
.initvesa2640x400x8
mov byte[res640],2
mov word[vesa2_x],640
mov word[vesa2_y],400
mov byte[vesa2_bits],8
call InitVesa2
cmp byte[videotroub],1
jne .notrouble9
ret
.notrouble9
call dosmakepal
; clear screen (640*400 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,640*400
.loopg
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopg
pop es
ret
;*******************************************************
; InitVESA2 640x400x16 Set up Linear 640x400x16b
;*******************************************************
.initvesa2640x400x16
mov byte[res640],2
mov byte[cbitmode],1
mov word[vesa2_x],640
mov word[vesa2_y],400
mov byte[vesa2_bits],16
call InitVesa2
cmp byte[videotroub],1
jne .notrouble10
ret
.notrouble10
; clear screen (640*400*2 bytes)
push es
mov ax,[vesa2selec]
mov es,ax
mov edi,0
mov ecx,640*400*2
.looph
mov byte[es:edi],0
inc edi
dec ecx
jnz .looph
pop es
ret
;*******************************************************
; InitVESA1.2 640x480x16 Set up 640x480x16b
;*******************************************************
.initvesa12640x480x16
mov byte[res640],1
mov byte[cbitmode],1
mov word[vesa2_x],640
mov word[vesa2_y],480
mov byte[vesa2_bits],16
call InitVesa12
ret
; clear screen (640*480*2 bytes)
push es
mov ax,[selcA000]
mov es,ax
mov ebx,9
xor edx,edx
.loopbanks
xor edi,edi
mov ecx,16384
.loopi
mov byte[es:edi],0
inc edi
dec ecx
jnz .loopi
dec ebx
jnz .loopbanks
mov ecx,6144
pop es
ret

1417
zsnes/src/dos/joy.asm Normal file

File diff suppressed because it is too large Load Diff

185
zsnes/src/dos/lib.c Normal file
View File

@@ -0,0 +1,185 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <go32.h>
#include <dpmi.h>
#include <dos.h>
#include <sys/stat.h>
#include <dir.h>
//C++ style code in C
#define bool unsigned char
#define true 1
#define false 0
#define BIT(X) (1 << (X))
//This file contains library functions that can be found on other OSs
//Return realpath in 8.3 or LFN format for any given filename
//Based on code from DJGPP website, here was the notice for that code:
/* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file TRUENAME.C
*
* Copyright (c) 1994, 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
static char *realpath_internal(const char *file, char *buf, bool LFN)
{
__dpmi_regs regs;
unsigned short dos_mem_selector = _dos_ds;
unsigned short our_mem_selector = _my_ds();
char true_name[FILENAME_MAX];
char file_name[FILENAME_MAX], *name_end;
if (!file || !*file)
{
errno = EINVAL;
buf = 0;
}
else
{
strncpy(file_name, file, FILENAME_MAX);
file_name[FILENAME_MAX - 1] = 0;
for (name_end = file_name + strlen(file_name) - 1; name_end >= file_name && isspace((unsigned char)*name_end); )
{
*name_end-- = 0;
}
if ((strlen(file_name) == 2) && (file_name[1] == ':'))
{
strcat(name_end, "\\.");
}
else if ((*name_end == '\\') && (name_end-file_name < FILENAME_MAX-2))
{
strcat(name_end, ".");
}
_put_path(file_name);
regs.x.ax = _USE_LFN ? 0x7160 : 0x6000;
regs.x.cx = LFN+1;
regs.x.ds = regs.x.es = __tb_segment;
regs.x.si = __tb_offset;
regs.x.di = __tb_offset + FILENAME_MAX;
__dpmi_int(0x21, &regs);
movedata(dos_mem_selector, __tb + FILENAME_MAX, our_mem_selector, (unsigned int)true_name, FILENAME_MAX);
if (regs.x.flags & 1)
{
errno = __doserr_to_errno(regs.x.ax);
buf = 0;
}
else
{
if (!buf)
{
buf = (char *)malloc(strlen(true_name)+1);
}
if (buf)
{
strcpy(buf, true_name);
}
else
{
errno = ENOMEM;
}
}
}
return(buf);
}
char *realpath_sfn(const char *file, char *buf)
{
return(realpath_internal(file, buf, false));
}
char *realpath_lfn(const char *file, char *buf)
{
return(realpath_internal(file, buf, true));
}
//We tested this with Hard Disks, Floppies, CD/DVD-ROM, Network drives, no issues.
//It should also be tested with RAM drives and on more versions of DOS (DR-DOS, MS-DOS 5.0, etc...)
static bool _is_drive(unsigned char drive) //A == 1, B == 2, etc...
{
__dpmi_regs regs;
regs.x.ax = 0x4409;
regs.x.bx = drive;
__dpmi_int(0x21, &regs);
if (regs.x.flags & 1)
{
errno = __doserr_to_errno(regs.x.ax);
}
else if (((regs.x.dx & (BIT(9)|BIT(12))) == BIT(12)) || (regs.x.dx == 0x800))
{
return(true);
}
regs.x.ax = 0x4408;
regs.x.bx = drive;
__dpmi_int(0x21, &regs);
if (regs.x.flags & 1)
{
errno = __doserr_to_errno(regs.x.ax);
return(false);
}
return(true);
}
//Return bitmask of available drives, A = BIT(0), B = BIT(1), etc...
unsigned int GetLogicalDrives()
{
unsigned int drives = 0;
int i;
for (i = 0; i < 26; i++)
{
if (_is_drive(i+1))
{
drives |= BIT(i);
}
}
return(drives);
}

35
zsnes/src/dos/lib.h Normal file
View File

@@ -0,0 +1,35 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef LIB_H
#define LIB_H
char *realpath_sfn(const char *file, char *buf);
char *realpath_lfn(const char *file, char *buf);
//Only beta versions of DJGPP currently have this function
#if (__DJGPP__ < 3) && (__DJGPP_MINOR__ < 4)
#define realpath(path, resolved_path) realpath_sfn(path, resolved_path)
#endif
unsigned int GetLogicalDrives();
#endif

1421
zsnes/src/dos/sound.asm Normal file

File diff suppressed because it is too large Load Diff

224
zsnes/src/dos/sw.asm Normal file
View File

@@ -0,0 +1,224 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM SidewinderFix
%macro ParityCheckSW 1
mov ecx,ebx
xor cl,ch
jpe %%ParChkSW
mov [%1],ebx
%%ParChkSW:
%endmacro
section .data
gDump times 256 db 0
bDump times 128 db 0
NEWSYM _SW1, dd 0
NEWSYM _SW2, dd 0
NEWSYM _SW3, dd 0
NEWSYM _SW4, dd 0
NEWSYM _SWCount, dd 0
section .text
NEWSYM _readSideWinder
pushad
mov ecx,200
mov ebx,gDump
cli
cmp byte[SidewinderFix],0
je .write
out dx,al
.write
GetSWDataLoop:
cmp byte[SidewinderFix],0
jne .nowrite
out dx,al
.nowrite
nop
nop
nop
nop
nop
nop
in al,dx
mov [ebx],al
inc ebx
dec ecx
jnz GetSWDataLoop
sti
xor ebx,ebx
xor ecx,ecx
xor edi,edi
mov esi,1
FindCycle:
mov al,[gDump+edi]
inc edi
cmp edi,200
je SMWError
test al,00010000b
jnz WMFCS1
xor ecx,ecx
jmp FindCycle
WMFCS1:
inc ecx
cmp ecx,15
jne FindCycle
xor ebp,ebp
FindStrobeLow:
mov al,[gDump+edi]
inc edi
cmp edi,200
je SMWError
test al,00010000b
jnz FindStrobeLow
xor ecx,ecx
FindStrobeHigh:
inc ecx
cmp ecx,15
je SWModeCheck
mov al,[gDump+edi]
inc edi
cmp edi,200
je SMWError
test al,00010000b
jz FindStrobeHigh
mov [bDump+ebp],al
inc ebp
jmp FindStrobeLow
SMWDone:
popad
mov eax,0
ret
SMWError:
popad
mov eax,1
ret
SWModeCheck:
cmp ebp,5
je near ModeB1
cmp ebp,15
je near ModeA1
cmp ebp,10
je near ModeB2
cmp ebp,30
je near ModeA2
cmp ebp,45
je near ModeA3
cmp ebp,20
je near ModeB4
cmp ebp,60
je near ModeA4
jmp short SMWError
ModeA1:
cmp dword[_SWCount],3
je near ModeB3
xor ebp,ebp
call DoModeA
ParityCheckSW _SW1
jmp SMWDone
ModeA4:
mov ebp,45
call DoModeA
ParityCheckSW _SW4
ModeA3:
mov ebp,30
call DoModeA
ParityCheckSW _SW3
ModeA2:
mov ebp,15
call DoModeA
ParityCheckSW _SW2
xor ebp,ebp
call DoModeA
ParityCheckSW _SW1
jmp SMWDone
ModeB4:
mov ebp,15
call DoModeB
ParityCheckSW _SW4
ModeB3:
mov ebp,10
call DoModeB
ParityCheckSW _SW3
ModeB2:
mov ebp,5
call DoModeB
ParityCheckSW _SW2
ModeB1:
xor ebp,ebp
call DoModeB
ParityCheckSW _SW1
jmp SMWDone
DoModeB:
xor ebx,ebx
mov eax,2
mov ecx,5
add ebp,bDump
ModeBLoop:
test byte[ebp],00100000b
jnz $+4
or ebx,eax
shl eax,1
test byte[ebp],01000000b
jnz $+4
or ebx,eax
shl eax,1
test byte[ebp],10000000b
jnz $+4
or ebx,eax
shl eax,1
inc ebp
dec ecx
jnz ModeBLoop
ret
DoModeA:
xor ebx,ebx
mov eax,2
mov ecx,15
add ebp,bDump
ModeALoop:
test byte[ebp],00100000b
jnz $+4
or ebx,eax
shl eax,1
inc ebp
dec ecx
jnz ModeALoop
ret

334
zsnes/src/dos/sw32.asm Normal file
View File

@@ -0,0 +1,334 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;32-bit DOS-Mode driver for the Microsoft Sidewinder Gamepad
;Multi-SW Version 1.5
;(C) 1997, 1998 Robert William Grubbs, All Rights Reserved
;Latest revision 1/20/98
; Driver Source code Include file
;C-linkable, rewrote decoder -sardu
;Flat memory mode (Protected mode extender required! Tested with DOS32)
;Tested with TASM 4.0+
SECTION .data
SW1 dd 0 ;SW #1's button status
SW2 dd 0 ;SW #2's button status
SW3 dd 0 ;SW #3's button status
SW4 dd 0 ;SW #4's button status
SWCount dd 1 ;Tell the driver how many sidewinders are present
SWSetup dd 0 ;Tell the driver what polling mode to use
; 0=Interrupts disabled, Multiple OUT statements
; 1=Interrupts disabled, Single OUT statement
; 2=Interrupts enabled, Multiple OUT statements
; 3=Interrupts enabled, Single OUT statement
gDump times 100h db 0 ;SW Status dump buffer (space for 256 bytes, uses 200)
bDump times 80h db 0 ;buffer to hold button data (Modes A and B, all SW)
SECTION .text
;This macro calculates parity for the buttons and compares it to the SW's
; parity bit. If they don't match, the button data is discarded.
%macro ParityCheckSW 1
mov ecx,ebx ;duplicate button status
xor cl,ch ;
jpe %%ParChkSW
mov [%1],ebx ;update button status for SW #n
%%ParChkSW ;done
%endmacro
;The main subroutine; this is the important one; bow down before it
;IN: None
;Out: SWx=buttons (bit 0=null 1=up 2=dn 3=rt 4=lt 5=A 6=B 7=C 8=X)
; (9=Y 10=Z 11=L 12=R 13=St 14=M 15=Parity)
;No registers destroyed
readSideWinder:
pushad
mov ecx,200 ;dump buffer fill size
mov ebx,gDump ;initial dump pointer
mov edx,0201h ;joystick port
cmp dword[SWSetup],0
jne NotSW0
cli ;Disable interrupts (required to avoid jitter)
GetSWDataLoop: ;
out dx,al ;trigger joystick port
in al,dx ;read SW status byte
mov [ebx],al ;dump status byte
inc ebx ;increment dump pointer
dec ecx
jnz GetSWDataLoop
sti ;Re-enable interrupts
jmp SWPollDone
NotSW0:
cmp dword[SWSetup],1
jne NotSW1
cli ;Disable interrupts (required to avoid jitter)
out dx,al ;trigger joystick port
GetSWDataLoop1: ;
in al,dx ;read SW status byte
mov [ebx],al ;dump status byte
inc ebx ;increment dump pointer
dec ecx
jnz GetSWDataLoop1
sti ;Re-enable interrupts
jmp SWPollDone
NotSW1:
cmp dword[SWSetup],2
jne NotSW2
GetSWDataLoop2: ;
out dx,al ;trigger joystick port
in al,dx ;read SW status byte
mov [ebx],al ;dump status byte
inc ebx ;increment dump pointer
dec ecx
jnz GetSWDataLoop2
jmp SWPollDone
NotSW2:
;default all others to SWStatus=3
out dx,al ;trigger joystick port
GetSWDataLoop3: ;
in al,dx ;read SW status byte
mov [ebx],al ;dump status byte
inc ebx ;increment dump pointer
dec ecx
jnz GetSWDataLoop3
SWPollDone:
mov ecx,0 ;tick count
mov esi,1 ;initialize output mask
mov ebx,0 ;initialize output
mov edi,0 ;initialize input pointer
;My current method of cycle detection is to look for 15 highs in a row on
; the strobe line. Cycle ends is detected by 15 lows in a row.
;Mode A has 15 strobes in a cycle, Mode B has 5.
; Note that the 15 highs/lows for cycle detection may be too high for slow
; machines. I havn't seen a problem yet, but it may exist...
;Multiple Sidewinder data complicates things. Each additional SW tags
; another set of strobes to the cycle, 5 more in mode B, 15 more in mode A.
; Detecting extra SW gamepad data is fairly simple: count the number of
; strobes. If it is a multiple of 5, you're in mode B and can divide by 5
; to get the total number of gamepads. If it's divisible by 15, use mode A.
; However, this method cannot distinguish between mode A for one SW and mode
; B for three SW. In that case, the SWCount variable must be set correctly.
FindCycle:
mov al,[gDump+edi] ;get next status byte
inc edi ;increment input pointer
cmp edi,200 ;test for end of status block
je SWNoFind ;if it's the end, quit sub with error
test al,00010000b ;Check for nonzero bits
jnz WMFCS1 ;
xor ecx,ecx ;if zero, reset tick count
jmp FindCycle ;can't be pre-cycle
WMFCS1: ;Possibly pre-cycle
inc ecx ;increment tick count
cmp ecx,15 ;test for sufficient ticks for cycle start
jne FindCycle ;if insufficient, get next status byte
;Yippie! it found a (probable) cycle!
mov ebp,0 ;initialize bDump index (strobe count)
FindStrobeLow: ;Search for leading edge of data strobe
mov al,[gDump+edi] ;get next status byte
inc edi ;increment input pointer
cmp edi,200 ;test for end of status block
je SWNoFind ;if it's the end, quit sub with error
test al,00010000b ;get "strobe" bit
jnz SHORT FindStrobeLow ;if it isn't zero, we're not there yet
xor ecx,ecx ;initialize cycle end test count
FindStrobeHigh:
inc ecx ;increment zero count
cmp ecx,0fh ;is it 15?
je SWModeCheck ;if so, goto mode check
mov al,[gDump+edi] ;get next status byte
inc edi ;increment input pointer
cmp edi,200 ;test for end of status block
je SWNoFind ;if it's the end, quit sub with error
test al,00010000b ;get "strobe" bit
jz FindStrobeHigh ;if it is zero, we're not there yet
;if not, we're there! data bit is valid (probably)
mov [bDump+ebp],al ;preserve data for button decoding
inc ebp ;increment strobe count/bDump index
jmp FindStrobeLow ;wait for the next button
SMWDone:
SWNoFind:
popad
ret ;return to calling procedure
SWModeCheck: ;Check strobe count to identify mode and # of SW
cmp ebp,15 ;Is it Mode A with 1 Sidewinder or B with 3?
je ModeA1
cmp ebp,5 ;Is it Mode B with 1 Sidewinders?
je ModeB1
cmp ebp,30 ;Is it Mode A with 2 Sidewinders?
je ModeA2
cmp ebp,10 ;Is it Mode B with 2 Sidewinders?
je near ModeB2
cmp ebp,45 ;Is it Mode A with 3 Sidewinders?
je near ModeA3
cmp ebp,60 ;Is it Mode A with 4 Sidewinders?
je near ModeA4
cmp ebp,20 ;Is it Mode B with 4 Sidewinders?
je near ModeB4
jmp SHORT SWNoFind ;Any other # of strobes is invalid data
ModeB1:
xor ebp,ebp
call DoModeB
ParityCheckSW SW1
jmp SMWDone
ModeA1:
cmp dword[SWCount],3
je near ModeB3
xor ebp,ebp
call DoModeA
ParityCheckSW SW1
jmp SMWDone
ModeA2:
xor ebp,ebp
call DoModeA
ParityCheckSW SW1
mov ebp,15
call DoModeA
ParityCheckSW SW2
jmp SMWDone
ModeA3:
xor ebp,ebp
call DoModeA
ParityCheckSW SW1
mov ebp,15
call DoModeA
ParityCheckSW SW2
mov ebp,30
call DoModeA
ParityCheckSW SW3
jmp SMWDone
ModeA4:
xor ebp,ebp
call DoModeA
ParityCheckSW SW1
mov ebp,15
call DoModeA
ParityCheckSW SW2
mov ebp,30
call DoModeA
ParityCheckSW SW3
mov ebp,45
call DoModeA
ParityCheckSW SW4
jmp SMWDone
ModeB2:
xor ebp,ebp
call DoModeB
ParityCheckSW SW1
mov ebp,5
call DoModeB
ParityCheckSW SW2
jmp SMWDone
ModeB3:
xor ebp,ebp
call DoModeB
ParityCheckSW SW1
mov ebp,5
call DoModeB
ParityCheckSW SW2
mov ebp,10
call DoModeB
ParityCheckSW SW3
jmp SMWDone
ModeB4:
xor ebp,ebp
call DoModeB
ParityCheckSW SW1
mov ebp,5
call DoModeB
ParityCheckSW SW2
mov ebp,10
call DoModeB
ParityCheckSW SW3
mov ebp,15
call DoModeB
ParityCheckSW SW4
jmp SMWDone
ENDP
%macro SWRepeat 1
mov al,[bDump+ebp+%1]
shr al,5 ;get upper 3 bits
shl eax,1+3*%1 ;shift into place
or ebx,eax ;or into output
%endmacro
DoModeB:
xor ebx,ebx ;Initialize output
xor eax,eax
SWRepeat 0
SWRepeat 1
SWRepeat 2
SWRepeat 3
SWRepeat 4
xor ebx,0FFFEh
ret
DoModeA:
xor ebx,ebx ;Clear output
mov ecx,15 ;bit count
ALP:
mov al,[bDump+ebp]
inc ebp
shl al,3
rcr ebx,1
dec ecx
jg ALP
shr ebx,16
xor ebx,0FFFEh
ret

532
zsnes/src/dos/vesa12.asm Normal file
View File

@@ -0,0 +1,532 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM vesa2_usbit,vesa2_clbit,vesa2_clbitng,vesa2_clbitng2,vesa2_clbitng3
EXTSYM vesa2_x,vesa2_y,vesa2_bits,vesa2_rpos,vesa2_gpos,vesa2_bpos,vesa2_rposng
EXTSYM vesa2_gposng,vesa2_bposng,vesa2_rtrcl,vesa2_rtrcla,vesa2_rfull
EXTSYM vesa2_gtrcl,vesa2_gtrcla,vesa2_gfull,vesa2_btrcl,vesa2_btrcla,vesa2_bfull
EXTSYM vesa2red10,videotroub,genfulladdtab,DosExit,noblocks
EXTSYM bytesperscanline,vesamode,VESAmodelist
; add 0214h video mode
SECTION .bss
NEWSYM granularity, resw 1
NEWSYM granadd, resd 1
SECTION .text
NEWSYM VESA12EXITTODOS
mov ax,0003h
int 10h
push edx
mov edx,.exitfromvesa12
mov ah,9
int 21h
pop edx
mov ah,9
int 21h
mov edx,.return
mov ah,9
int 21h
mov byte[videotroub],1
jmp DosExit
SECTION .data
.exitfromvesa12 db 'Unable to Initialize VESA1.2 $'
.return db 10,13,'$'
SECTION .text
;*******************************************************
; Set up Vesa 2
;*******************************************************
NEWSYM InitVesa12
;-------------------------------------------------;
; First - allocate some bytes in DOS memory for ;
; communication with VBE ;
;-------------------------------------------------;
mov eax,0100h
mov ebx,512/16 ; 512 bytes
int 31h ; Function 31h,100h - Allocate DOS memory (512 bytes)
jnc .gotmem
mov edx,.nomemmessage
jmp VESA12EXITTODOS
.gotmem
mov fs,dx ; FS now points to the DOS buffer
;--------------------------------------------------;
; Now, get information about the video card into ;
; a data structure ;
;--------------------------------------------------;
mov edi,RMREGS
mov dword[fs:0],'VBE1' ; Request VBE 2.0 info
mov dword[RMREGS.eax],4f00h
mov [RMREGS.es],ax ; Real mode segment of DOS buffer
mov dword[RMREGS.edi],0
push es
push ds
pop es
mov eax,300h
mov ebx,10h
xor ecx,ecx
int 31h ; Simulate real mode interrupt
pop es
jnc .int1ok
mov edx,.noint1message
jmp VESA12EXITTODOS
.int1ok ; Real mode int successful!!!
mov eax,[RMREGS.eax]
cmp al,4fh ; Check vbe interrupt went OK
jz .vbedetected
mov edx,.novbemessage
jmp VESA12EXITTODOS
.vbedetected
cmp dword[fs:0000],'VESA'
jz .vesadetected ; Check for presence of vesa
mov edx,.novesamessage
jmp VESA12EXITTODOS
.vesadetected
cmp word[fs:0004],102h
jae .vesa12detected ; Check we've got VESA 1.2 or greater
mov edx,.novesa2message
jmp VESA12EXITTODOS
;-----------------------------------------------------;
; OK - vesa 2.0 or greater has been detected. Copy ;
; mode information into VESAmodelist ;
;-----------------------------------------------------;
.vesa12detected
mov ax,[fs:12h] ; Get no. of 64k blocks
mov [noblocks],ax
mov ax, 2
mov bx,[fs:10h]
int 31h
jnc .wegottheselector
mov edx, .oopsnoselector
jmp VESA12EXITTODOS
.wegottheselector
mov gs,ax
xor eax,eax
mov ebp,VESAmodelist
mov ecx,512
mov ax,[fs:0eh]
.loopcopymodes
mov bx,[gs:eax]
mov [ebp],bx
cmp bx,0ffffh
jz .copiedmodes
add ebp,2
add eax,2
dec ecx
jz .outofmodelistspace
jmp .loopcopymodes
.outofmodelistspace
mov edx,.outofmodelistspacemessage
jmp VESA12EXITTODOS
;----------------------------------------------;
; OK - Scan the mode list to find a matching ;
; mode for vesa2_x, vesa2_y and vesa2_depth ;
;----------------------------------------------;
.copiedmodes
mov ebp,VESAmodelist
xor ecx,ecx
.loopcheckmodes
mov cx, [ebp]
cmp cx, 0ffffh
jnz .notendoflist
mov edx,.endoflist
jmp VESA12EXITTODOS
.notendoflist
mov edi, RMREGS
mov dword[RMREGS.eax],4f01h
mov dword[RMREGS.ebx],0
mov [RMREGS.ecx],ecx
mov dword[RMREGS.edi],0
push es
push ds
pop es
mov eax,300h
mov ebx,10h
xor ecx,ecx
int 31h ; Simulate real mode interrupt
pop es
jnc .modecheckok
mov edx,.modecheckfail
jmp VESA12EXITTODOS
.modecheckok
add ebp,2
test word[fs:0000h],1b
jz near .loopcheckmodes ; If mode is not available
;
; xor eax,eax
; mov ax,[fs:12h]
; call printnum
; mov ah,02h
; mov dl,'x'
; int 21h
; mov ax,[fs:14h]
; call printnum
; mov ah,02h
; mov dl,'x'
; int 21h
; xor ah,ah
; mov al,[fs:19h]
; call printnum
; mov ah,02h
; mov dl,13
; int 21h
; mov dl,10
; int 21h
mov eax,[vesa2_x]
cmp [fs:12h],ax ; Check that the height matches
jnz near .loopcheckmodes
mov eax,[vesa2_y]
cmp [fs:14h],ax ; Check that the width matches
jnz near .loopcheckmodes
mov al,[vesa2_bits]
cmp [fs:19h],al ; Check bits/pixel for match
jnz near .loopcheckmodes
; mov ah,07h
; int 21h
; D0 = Window supported
; 0 = Window is not supported
; 1 = Window is supported
; D1 = Window readable
; 0 = Window is not readable
; 1 = Window is readable
; D2 = Window writeable
; 0 = Window is not writeable
; 1 = Window is writeable
; D3-D7 = Reserved
mov byte[.whichwin],0
mov al,[fs:2] ; Get window A attributes
and al,0100b
cmp al,0100b
je .foundwin ; Mode supported
mov al,[fs:3] ; Get window B attributes
and al,0100b
cmp al,0100b
jne .foundwin ; Mode not supported
mov byte[.whichwin],1
.foundwin
; Success - a match has been found!!
sub ebp,2
mov ax,[ebp]
mov [vesamode],ax ; Store vesa 1.2 mode number
; and eax,0FFFFh
; push eax
; mov ax,0003h
; int 10h
; pop eax
; call printnum
; jmp DosExit
mov ax,[fs:10h]
mov byte[vesa2red10],0
mov byte[vesa2_rposng],11
mov byte[vesa2_gposng],6
mov byte[vesa2_bposng],0
mov dword[vesa2_clbitng],1111011111011110b
mov dword[vesa2_clbitng2],11110111110111101111011111011110b
mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b
mov dword[vesa2_clbitng3],0111101111101111b
mov [bytesperscanline],ax ; Store bytes per scan line
cmp byte[fs:20h],10
jne .nored10
mov byte[fs:20h],11
mov byte[vesa2red10],1
mov byte[vesa2_rposng],10
mov byte[vesa2_gposng],5
mov dword[vesa2_clbitng],0111101111011110b
mov dword[vesa2_clbitng2],01111011110111100111101111011110b
mov dword[vesa2_clbitng2+4],01111011110111100111101111011110b
mov dword[vesa2_clbitng3],0011110111101111b
.nored10
; fix up bit lengths
mov al,16
sub al,[fs:20h]
mov ah,[fs:22h]
sub ah,[fs:20h]
mov bl,[fs:24h]
sub bl,[fs:20h]
mov bh,al
cmp bh,ah
jb .scheck1
mov bh,ah
.scheck1
cmp bh,bl
jb .scheck2
mov bh,bl
.scheck2
mov byte[fs:19h],5
mov al,16
sub al,[fs:22h]
mov ah,[fs:20h]
sub ah,[fs:22h]
mov bl,[fs:24h]
sub bl,[fs:22h]
mov bh,al
cmp bh,ah
jb .scheck1b
mov bh,ah
.scheck1b
cmp bh,bl
jb .scheck2b
mov bh,bl
.scheck2b
mov [fs:21h],bh
mov al,16
sub al,[fs:24h]
mov ah,[fs:20h]
sub ah,[fs:24h]
mov bl,[fs:22h]
sub bl,[fs:24h]
mov bh,al
cmp bh,ah
jb .scheck1c
mov bh,ah
.scheck1c
cmp bh,bl
jb .scheck2c
mov bh,bl
.scheck2c
mov [fs:23h],bh
mov word[vesa2_clbit],0
cmp byte[fs:20h],10
jne .nottopbit
mov word[vesa2_usbit],8000h
.nottopbit
; Process Red Stuff
mov al,[fs:20h] ; bit sizes = [fs:19h,21h,23h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:19h],6
jne .no6bit
mov [vesa2_usbit],bx
inc al
.no6bit
or [vesa2_clbit],bx
mov [vesa2_rpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrr
shl bx,cl
jmp .shlr
.shrr
shr bx,1
.shlr
mov [vesa2_rfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_rtrcl],bx
xor bx,0FFFFh
mov [vesa2_rtrcla],bx
; Process Green Stuff
mov al,[fs:22h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:21h],6
jne .no6bitb
mov [vesa2_usbit],bx
inc al
.no6bitb
or [vesa2_clbit],bx
mov [vesa2_gpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrg
shl bx,cl
jmp .shlg
.shrg
shr bx,1
.shlg
mov [vesa2_gfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_gtrcl],bx
xor bx,0FFFFh
mov [vesa2_gtrcla],bx
; Process Blue Stuff
mov al,[fs:24h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:23h],6
jne .no6bitc
mov [vesa2_usbit],bx
inc al
.no6bitc
or [vesa2_clbit],bx
mov [vesa2_bpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrb
shl bx,cl
jmp .shlb
.shrb
shr bx,1
.shlb
mov [vesa2_bfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_btrcl],bx
xor bx,0FFFFh
mov [vesa2_btrcla],bx
xor word[vesa2_clbit],0FFFFh
mov ax,[fs:4]
mov [granularity],ax
xor edx,edx
mov ax,64
mov bx,[granularity]
div bx
mov [granadd],ax
call genfulladdtab
xor ecx,ecx
xor edx,edx
mov eax,4f02h
movzx ebx,word[vesamode]
int 10h ; Set the vesa mode
cmp ax,004fh
jz .modesetok
mov edx,.unableset
jmp VESA12EXITTODOS ; Failure!!!
.modesetok
;******************************* EXTRA BIT ****************************
ret
; Check logical scanline length
mov eax,4f06h
mov ebx,1
int 10h
cmp cx,[vesa2_x]
je .correctwidth
mov eax,4f06h ; VBE Set/Get logical scan line length
mov ebx,0 ; Set scan line length in pixels
mov ecx, [vesa2_x] ; Desired screen width
int 10h
cmp ax,04fh
jz .correctwidth
mov edx, .unablescan
jmp VESA12EXITTODOS ; Failure!!!
.correctwidth
ret
SECTION .data
.nomemmessage db ': Unable to locate DOS memory.$'
.noint1message db ': Simulated real mode interrupt failed.$'
.oopsnoselector db ': Failed to allocate vesa display selector!$'
.novesa2message db ': VESA 1.2 or greater required!$'
.novbemessage db ': VBE not detected!!$'
.novesamessage db ': VESA not detected!$'
.outofmodelistspacemessage db ': Out of VESA mode list space!$'
.endoflist db ': VESA 1.2 mode does not work on your video card/driver.$'
.whichwin db 0
.modecheckfail db ': Real mode interrupt failure while checking vesa mode$'
.unableset db 'Unable to initialize video mode.$'
.unablescan db 'Unable to set scan line length.$'
SECTION .bss
RMREGS
.edi resd 1
.esi resd 1
.ebp resd 1
.esp resd 1
.ebx resd 1
.edx resd 1
.ecx resd 1
.eax resd 1
.flags resw 1
.es resw 1
.ds resw 1
.fs resw 1
.gs resw 1
.ip resw 1
.cs resw 1
.sp resw 1
.ss resw 1
.spare times 20 resd 1

654
zsnes/src/dos/vesa2.asm Normal file
View File

@@ -0,0 +1,654 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
EXTSYM DosExit,PrintStr,HalfTransB,HalfTransC,Init_2xSaIMMX,ZSNESBase
EXTSYM UnusedBit,HalfTrans,UnusedBitXor,ngrposng,nggposng,ngbposng
EXTSYM videotroub,ExitFromGUI,ErrorPointer,vesa2_x,vesa2_y,vesa2_bits,TripBufAvail,vesa2red10
EXTSYM vesa2_rposng,vesa2_gposng,vesa2_bposng,vesa2_clbitng,vesa2_clbitng2,vesa2_clbitng3
EXTSYM vesa2_clbit,vesa2_usbit,vesa2_rpos,vesa2_rfull,vesa2_rtrcl,vesa2_rtrcla,genfulladdtab
EXTSYM vesa2_gpos,vesa2_gfull,vesa2_gtrcl,vesa2_gtrcla,vesa2_bpos,vesa2_bfull,vesa2_btrcl,vesa2_btrcla
SECTION .data
; add 0214h video mode
anticrash times 10 db 0
ALIGN32
NEWSYM vesa2selec, dd 0 ; VESA2 Selector Location
NEWSYM vesa3en, dd 0
NEWSYM VESAAddr, dd 0
SECTION .bss
SECTION .text
NEWSYM VESA2EXITTODOS
mov byte[videotroub],1
cmp byte[ExitFromGUI],0
je .nogui
mov [ErrorPointer],edx
ret
.nogui
mov ax,0003h
int 10h
push edx
mov edx,.exitfromvesa2
call PrintStr
pop edx
call PrintStr
mov edx,.return
call PrintStr
jmp DosExit
SECTION .data
.exitfromvesa2 db 'Unable to Initialize VESA2 : ',0
.return db 10,13,0
SECTION .text
;*******************************************************
; Set up Vesa 2
;*******************************************************
NEWSYM InitVesa2
;-------------------------------------------------;
; First - allocate some bytes in DOS memory for ;
; communication with VBE ;
;-------------------------------------------------;
mov eax,0100h
mov ebx,512/16 ; 512 bytes
int 31h ; Function 31h,100h - Allocate
; DOS memory (512 bytes)
jnc .gotmem
mov edx,.nomemmessage
jmp VESA2EXITTODOS
.gotmem
mov fs,dx ; FS now points to the DOS buffer
;--------------------------------------------------;
; Now, get information about the video card into ;
; a data structure ;
;--------------------------------------------------;
mov edi,RMREGS
mov dword[fs:0],'VBE2' ; Request VBE 2.0 info
mov dword[RMREGS.eax],4f00h
mov [RMREGS.es],ax ; Real mode segment of DOS buffer
mov dword[RMREGS.edi],0
push es
push ds
pop es
mov eax,300h
mov ebx,10h
xor ecx,ecx
int 31h ; Simulate real mode interrupt
pop es
jnc .int1ok
mov edx,.noint1message
jmp VESA2EXITTODOS
.int1ok ; Real mode int successful!!!
mov eax,[RMREGS.eax]
cmp al,4fh ; Check vbe interrupt went OK
jz .vbedetected
mov edx,.novbemessage
jmp VESA2EXITTODOS
.vbedetected
cmp dword[fs:0000],'VESA'
jz .vesadetected ; Check for presence of vesa
mov edx,.novesamessage
jmp VESA2EXITTODOS
.vesadetected
cmp word[fs:0004],200h
jae .vesa2detected ; Check we've got VESA 2.0 or greater
mov edx,.novesa2message
jmp VESA2EXITTODOS
;-----------------------------------------------------;
; OK - vesa 2.0 or greater has been detected. Copy ;
; mode information into VESAmodelist ;
;-----------------------------------------------------;
.vesa2detected
mov dword[vesa3en],0
cmp word[fs:004],300h
jb .notvbe3
mov dword[vesa3en],1
.notvbe3
mov ax,[fs:12h] ; Get no. of 64k blocks
mov [noblocks],ax
mov ax, 2
mov bx,[fs:10h]
int 31h
jnc .wegottheselector
mov edx, .oopsnoselector
jmp VESA2EXITTODOS
.wegottheselector
mov gs,ax
xor eax,eax
mov ebp,VESAmodelist
mov ecx,512
mov ax,[fs:0eh]
.loopcopymodes
mov bx,[gs:eax]
mov [ebp],bx
cmp bx,0ffffh
jz .copiedmodes
add ebp,2
add eax,2
dec ecx
jz .outofmodelistspace
jmp .loopcopymodes
.outofmodelistspace
mov edx,.outofmodelistspacemessage
jmp VESA2EXITTODOS
;----------------------------------------------;
; OK - Scan the mode list to find a matching ;
; mode for vesa2_x, vesa2_y and vesa2_depth ;
;----------------------------------------------;
.copiedmodes
mov ebp,VESAmodelist
xor ecx,ecx
.loopcheckmodes
mov cx, [ebp]
cmp cx, 0ffffh
jnz .notendoflist
mov edx,.endoflist
jmp VESA2EXITTODOS
.notendoflist
mov edi, RMREGS
mov dword[RMREGS.eax],4f01h
mov dword[RMREGS.ebx],0
mov [RMREGS.ecx],ecx
mov dword[RMREGS.edi],0
push es
push ds
pop es
mov eax,300h
mov ebx,10h
xor ecx,ecx
int 31h ; Simulate real mode interrupt
pop es
jnc .modecheckok
mov edx,.modecheckfail
jmp VESA2EXITTODOS
.modecheckok
add ebp,2
test word[fs:0000h],1b
jz near .loopcheckmodes ; If mode is not available
mov eax,[vesa2_x]
cmp [fs:12h],ax ; Check that the height matches
jnz near .loopcheckmodes
mov eax,[vesa2_y]
cmp [fs:14h],ax ; Check that the width matches
jnz near .loopcheckmodes
mov al,[vesa2_bits]
cmp [fs:19h],al ; Check bits/pixel for match
jnz near .loopcheckmodes
mov byte[TripBufAvail],1
test word[fs:0000h],400h
jz .notbuf
mov byte[TripBufAvail],1
.notbuf
.notvesa3
; D0 = Window supported
; 0 = Window is not supported
; 1 = Window is supported
; D1 = Window readable
; 0 = Window is not readable
; 1 = Window is readable
; D2 = Window writeable
; 0 = Window is not writeable
; 1 = Window is writeable
; D3-D7 = Reserved
mov byte[.whichwin],0
mov al,[fs:2] ; Get window A attributes
and al,0100b
cmp al,0100b
je .foundwin ; Mode supported
mov al,[fs:3] ; Get window B attributes
and al,0100b
cmp al,0100b
jne .foundwin ; Mode not supported
mov byte[.whichwin],1
.foundwin
; Success - a match has been found!!
sub ebp,2
mov ax,[ebp]
mov [vesamode],ax ; Store vesa 2 mode number
mov ax,[fs:10h]
mov byte[vesa2red10],0
mov byte[vesa2_rposng],11
mov byte[vesa2_gposng],6
mov byte[vesa2_bposng],0
mov dword[vesa2_clbitng],1111011111011110b
mov dword[vesa2_clbitng2],11110111110111101111011111011110b
mov dword[vesa2_clbitng2+4],11110111110111101111011111011110b
mov dword[vesa2_clbitng3],0111101111101111b
mov [bytesperscanline],ax ; Store bytes per scan line
cmp byte[fs:20h],10
jne near .nored10
mov byte[fs:20h],11
mov byte[vesa2red10],1
mov byte[vesa2_rposng],10
mov byte[vesa2_gposng],5
mov dword[vesa2_clbitng],0111101111011110b
mov dword[vesa2_clbitng2],01111011110111100111101111011110b
mov dword[vesa2_clbitng2+4],01111011110111100111101111011110b
mov dword[vesa2_clbitng3],0011110111101111b
mov dword[UnusedBit], 10000000000000001000000000000000b
mov dword[HalfTrans], 01111011110111100111101111011110b
mov dword[UnusedBitXor], 01111111111111110111111111111111b
mov dword[UnusedBit+4], 10000000000000001000000000000000b
mov dword[HalfTrans+4], 01111011110111100111101111011110b
mov dword[UnusedBitXor+4],01111111111111110111111111111111b
mov dword[HalfTransB], 00000100001000010000010000100001b
mov dword[HalfTransB+4], 00000100001000010000010000100001b
mov dword[HalfTransC], 01111011110111100111101111011110b
mov dword[HalfTransC+4], 01111011110111100111101111011110b
mov dword[ngrposng],10
mov dword[nggposng],5
mov dword[ngbposng],0
.nored10
; fix up bit lengths
mov al,16
sub al,[fs:20h]
mov ah,[fs:22h]
sub ah,[fs:20h]
mov bl,[fs:24h]
sub bl,[fs:20h]
mov bh,al
cmp bh,ah
jb .scheck1
mov bh,ah
.scheck1
cmp bh,bl
jb .scheck2
mov bh,bl
.scheck2
mov byte[fs:19h],5
mov al,16
sub al,[fs:22h]
mov ah,[fs:20h]
sub ah,[fs:22h]
mov bl,[fs:24h]
sub bl,[fs:22h]
mov bh,al
cmp bh,ah
jb .scheck1b
mov bh,ah
.scheck1b
cmp bh,bl
jb .scheck2b
mov bh,bl
.scheck2b
mov [fs:21h],bh
mov al,16
sub al,[fs:24h]
mov ah,[fs:20h]
sub ah,[fs:24h]
mov bl,[fs:22h]
sub bl,[fs:24h]
mov bh,al
cmp bh,ah
jb .scheck1c
mov bh,ah
.scheck1c
cmp bh,bl
jb .scheck2c
mov bh,bl
.scheck2c
mov [fs:23h],bh
mov word[vesa2_clbit],0
cmp byte[fs:20h],10
jne .nottopbit
mov word[vesa2_usbit],8000h
.nottopbit
; Process Red Stuff
mov al,[fs:20h] ; bit sizes = [fs:19h,21h,23h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:19h],6
jne .no6bit
mov [vesa2_usbit],bx
inc al
.no6bit
or [vesa2_clbit],bx
mov [vesa2_rpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrr
shl bx,cl
jmp .shlr
.shrr
shr bx,1
.shlr
mov [vesa2_rfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_rtrcl],bx
xor bx,0FFFFh
mov [vesa2_rtrcla],bx
; mov ax,03h
; int 10h
; mov ax,[vesa2_rfull]
; call printhex
; jmp DosExit
; Process Green Stuff
mov al,[fs:22h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:21h],6
jne .no6bitb
mov [vesa2_usbit],bx
inc al
.no6bitb
or [vesa2_clbit],bx
mov [vesa2_gpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrg
shl bx,cl
jmp .shlg
.shrg
shr bx,1
.shlg
mov [vesa2_gfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_gtrcl],bx
xor bx,0FFFFh
mov [vesa2_gtrcla],bx
; Process Blue Stuff
mov al,[fs:24h]
mov cl,al
mov bx,1
shl bx,cl
cmp byte[fs:23h],6
jne .no6bitc
mov [vesa2_usbit],bx
inc al
.no6bitc
or [vesa2_clbit],bx
mov [vesa2_bpos],al
dec al
mov cl,al
mov bx,001Fh
cmp cl,0FFh
je .shrb
shl bx,cl
jmp .shlb
.shrb
shr bx,1
.shlb
mov [vesa2_bfull],bx
add al,5
mov bx,1
mov cl,al
shl bx,cl
mov [vesa2_btrcl],bx
xor bx,0FFFFh
mov [vesa2_btrcla],bx
xor word[vesa2_clbit],0FFFFh
call genfulladdtab
test word[fs:0h],10000000b ; Check if linear available
jnz .linearavailable
mov edx,.nolframebuffer
jmp VESA2EXITTODOS ; None available
;---------------------------------------------;
; OK - now set the vesa 2 mode based on the ;
; information gleaned... ;
;---------------------------------------------;
.linearavailable
or word[vesamode],4000h ; Convert mode to its LFB equivalent
mov ebx,[fs:28h] ; Read in physical base ptr
mov cx,bx
shr ebx,16
mov si,[noblocks]
xor edi,edi ; Since noblocks = number of 64k blocks,
; these lines leave si:di holding byte size
mov eax,800h
int 31h
jnc .mappedphysicalarea
mov edx,.unablemap
jmp VESA2EXITTODOS ; Failure!!!
.mappedphysicalarea
shl ebx,16
mov bx,cx
mov [LFBpointer],ebx
mov eax,ebx
sub eax,[ZSNESBase]
mov [VESAAddr],eax
xor ecx,ecx
xor edx,edx
mov eax,4f02h
movzx ebx,word[vesamode]
int 10h ; Set the vesa mode
cmp ax,004fh
jz .modesetok
mov edx,.unableset
jmp VESA2EXITTODOS ; Failure!!!
.modesetok
;******************************* EXTRA BIT ****************************
; cmp byte[.whichwin],1 ; Check if Write is at Window B
; jne .nowinB
;
; mov ax,4F05h
; mov bx,1
; mov dx,0
; int 10h
;
;.nowinB
; Check logical scanline length
mov eax,4f06h
mov ebx,1
int 10h
cmp cx,[vesa2_x]
je .correctwidth
mov eax,4f06h ; VBE Set/Get logical scan line length
mov ebx,0 ; Set scan line length in pixels
mov ecx, [vesa2_x] ; Desired screen width
int 10h
cmp ax,04fh
jz .correctwidth
mov edx, .unablescan
jmp VESA2EXITTODOS ; Failure!!!
.correctwidth
;*************************** END OF EXTRA BIT *************************
xor eax,eax
mov ecx,1
int 31h ; Allocate a descriptor
mov bx,ax ; Move our selector into bx
mov ecx,[LFBpointer]
mov dx,cx
shr ecx,16
mov eax,7
int 31h ; Set our selector to LFB
jnc .selectornowset
mov edx,.unablelfb
jmp VESA2EXITTODOS ; Failure!!!
.selectornowset
movzx ecx,word[noblocks]
shl ecx,16 ; Multiply by 65536
dec ecx ; Necessary!!!
mov dx,cx
shr ecx,16 ; CX:DX size of screen
mov eax,8
int 31h ; Set size of selector
jnc .ok
mov edx,.unablesets
jmp VESA2EXITTODOS ; Failure!!!
.ok
lar ecx,ebx
shr ecx,8
and cl,60h
or cl,93h
and ch,0c0h ; Keep granularity bit
mov ax,9
int 31h ; Set selector access rights
jnc .accessrightsset
mov edx,.unablesetar
jmp VESA2EXITTODOS
.accessrightsset
mov [vesa2selec],bx
cmp byte[vesa2red10],1
je .red10
mov eax,565
jmp .red11
.red10
mov eax,555
.red11
push eax
call Init_2xSaIMMX
pop eax
ret
SECTION .data
.nomemmessage db 'Unable to locate DOS memory.',0
.noint1message db 'Simulated real mode interrupt failed.',0
.novbemessage db 'VBE not detected!!',0
.novesamessage db 'VESA not detected!',0
.novesa2message db 'VESA 2.0 or greater required!',0
.oopsnoselector db 'Failed to allocate vesa display selector!',0
.outofmodelistspacemessage db 'Out of VESA2 mode list space!',0
.endoflist db 'This VESA2 mode does not work on your video card / driver.',0
.whichwin db 0
.modecheckfail db 'Real mode interrupt failure while checking vesa mode',0
.nolframebuffer db 'Linear Frame Buffer not Detected.',0
.unablemap db 'Unable to map physical area.',0
.unableset db 'Unable to initialize video mode.',0
.unablescan db 'Unable to set scan line length.',0
.unablelfb db 'Unable to set selector to LFB.',0
.unablesets db 'Unable to set size of selector.',0
.unablesetar db 'Unable to set selector access rights.',0
NEWSYM LFBpointer
dd 0
NEWSYM noblocks
dw 0
NEWSYM bytesperscanline
dw 0
NEWSYM vesamode
dw 0
;----------------------------------------------------------------------
;NEWSYM VESAmodelist
; times 512 dw 0
;----------------------------------------------------------------------
SECTION .bss
NEWSYM VESAmodelist, times 512 resw 1
NEWSYM RMREGS
.edi resd 1
.esi resd 1
.ebp resd 1
.esp resd 1
.ebx resd 1
.edx resd 1
.ecx resd 1
.eax resd 1
.flags resw 1
.es resw 1
.ds resw 1
.fs resw 1
.gs resw 1
.ip resw 1
.cs resw 1
.sp resw 1
.ss resw 1
.spare times 20 resd 1
;----------------------------------------------------------------------

152
zsnes/src/dos/vga.inc Normal file
View File

@@ -0,0 +1,152 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; by kode54, stainless
%macro SetVGAMode 1
mov byte[cbitmode],0
mov ax,0013h
int 10h
mov dx,03d4h
mov ax,0011h
out dx,ax
inc edx
in al,dx
and al,07fh
mov ah,al
mov al,11h
dec edx
out dx,ax
xor ecx,ecx
jmp %%start
%%loop
add ecx,4
%%start
mov eax,[%1+ecx]
or eax,eax
jz %%end
cmp ax,03c0h
je %%3c0
cmp ax,03c2h
je %%3c2
cmp ax,03c3h
je %%3c2
jmp %%default
%%3c0
mov dx,03dah
in al,dx
mov dl,0c0h
shr eax,16
or al,20h
out dx,al
shr eax,8
out dx,al
jmp %%loop
%%3c2
mov dx,ax
rol eax,8
out dx,al
jmp %%loop
%%default
mov dx,ax
shr eax,16
out dx,ax
jmp %%loop
%%end
%endmacro
SECTION .data
.Mode256x224c:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,03f01h,03d4h,04002h,03d4h,08203h
dw 03d4h,04a04h,03d4h,09a05h,03d4h,00b06h,03d4h,03e07h,03d4h,00008h
dw 03d4h,06109h,03d4h,0da10h,03d4h,0ac11h,03d4h,0bf12h,03d4h,02013h
dw 03d4h,04014h,03d4h,00715h,03d4h,01a16h,03d4h,0a317h,03c4h,00101h
dw 03c4h,00e04h,03cEh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode256x240c:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,03f01h,03d4h,04002h,03d4h,08203h
dw 03d4h,04a04h,03d4h,09a05h,03d4h,00d06h,03d4h,03e07h,03d4h,00008h
dw 03d4h,04109h,03d4h,0ea10h,03d4h,0ac11h,03d4h,0df12h,03d4h,02013h
dw 03d4h,04014h,03d4h,0e715h,03d4h,00616h,03d4h,0a317h,03c4h,00101h
dw 03c4h,00e04h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode256x256c:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,03f01h,03d4h,04002h,03d4h,08203h
dw 03d4h,04a04h,03d4h,09a05h,03d4h,02306h,03d4h,0b207h,03d4h,00008h
dw 03d4h,06109h,03d4h,00a10h,03d4h,0ac11h,03d4h,0FF12h,03d4h,02013h
dw 03d4h,04014h,03d4h,00715h,03d4h,01a16h,03d4h,0a317h,03c4h,00101h
dw 03c4h,00e04h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode256x256cs:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,03f01h,03d4h,04002h,03d4h,08203h
dw 03d4h,04a04h,03d4h,09a05h,03d4h,02306h,03d4h,01d07h,03d4h,00008h
dw 03d4h,06009h,03d4h,00a10h,03d4h,0ac11h,03d4h,0ff12h,03d4h,02013h
dw 03d4h,04014h,03d4h,00715h,03d4h,01a16h,03d4h,0a317h,03c4h,00101h
dw 03c4h,00e04h,03ceh,04005h,03cEh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode320x224:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,04f01h,03d4h,05002h,03d4h,08203h
dw 03d4h,05404h,03d4h,08005h,03d4h,00b06h,03d4h,03e07h,03d4h,00008h
dw 03d4h,04109h,03d4h,0da10h,03d4h,09c11h,03d4h,0c012h,03d4h,02813h
dw 03d4h,00014h,03d4h,0c715h,03d4h,00416h,03d4h,0e317h,03c4h,00101h
dw 03c4h,00604h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode320x240:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,04f01h,03d4h,05002h,03d4h,08203h
dw 03d4h,05404h,03d4h,08005h,03d4h,00d06h,03d4h,03e07h,03d4h,00008h
dw 03d4h,04109h,03d4h,0ea10h,03d4h,0ac11h,03d4h,0df12h,03d4h,02813h
dw 03d4h,00014h,03d4h,0e715h,03d4h,00616h,03d4h,0e317h,03c4h,00101h
dw 03c4h,00604h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode320x256:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,04f01h,03d4h,05002h,03d4h,08203h
dw 03d4h,05404h,03d4h,08005h,03d4h,02306h,03d4h,0b207h,03d4h,00008h
dw 03d4h,06109h,03d4h,00a10h,03d4h,0ac11h,03d4h,0ff12h,03d4h,02813h
dw 03d4h,00014h,03d4h,00715h,03d4h,01a16h,03d4h,0e317h,03c4h,00101h
dw 03c4h,00604h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
.Mode320x256s:
dw 03c2h,0e300h,03d4h,05f00h,03d4h,04f01h,03d4h,05002h,03d4h,08203h
dw 03d4h,05404h,03d4h,08005h,03d4h,02306h,03d4h,01d07h,03d4h,00008h
dw 03d4h,06009h,03d4h,00a10h,03d4h,0ac11h,03d4h,0ff12h,03d4h,02813h
dw 03d4h,00014h,03d4h,00715h,03d4h,01a16h,03d4h,0e317h,03c4h,00101h
dw 03c4h,00604h,03ceh,04005h,03ceh,00506h,03c0h,04110h,03c0h,00013h
dd 0
SECTION .text

197
zsnes/src/effects/burn.c Normal file
View File

@@ -0,0 +1,197 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
Fire effects implementation by Frank Jan Sorensen, Joachim Fenkes,
Stefan Goehler, Jonas Quinn, et al.
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#ifndef M_PI
#ifndef PI
#define M_PI 3.1415926535897932384626433832795
#else
#define M_PI PI
#endif
#endif
#define BUF_WIDTH 288
#define BUF_HEIGHT 224
const int rootrand = 20; /* Max/Min decrease of the root of the flames */
const int decay = 5; /* How far should the flames go up on the screen? This MUST be positive - JF */
const int miny = 1; /* Starting line of the flame routine. (should be adjusted along with MinY above) */
const int smooth = 1; /* How discrete can the flames be? */
const int minfire = 50; /* limit between the "starting to burn" and the "is burning" routines */
const int xstart = 0; /* Starting position on the screen, should be divisible by 4 without remainder! */
const int xend = 287; /* Guess! */
const int width = 1 + 287;
const int maxcolor = 110; /* Constant for the MakePal procedure */
const int fireincrease = 3; /* 3 = Wood, 90 = Gasoline */
typedef struct colorvalue
{
unsigned char r, g, b;
} colorvalue;
typedef colorvalue vgapalettetype[256];
/* Converts (Hue, Saturation, Intensity) -> (RGB) */
void hsi2rgb(double h, double s, double i, struct colorvalue *c)
{
double t;
double rv, gv, bv;
t = h;
rv = 1 + s * sin(t - 2 * M_PI / 3);
gv = 1 + s * sin(t);
bv = 1 + s * sin(t + 2 * M_PI / 3);
t = 255.999 * i / 2;
c->r = (unsigned char) floor(rv * t);
c->g = (unsigned char) floor(gv * t);
c->b = (unsigned char) floor(bv * t);
}
void genpal()
{
int i;
vgapalettetype pal;
memset(pal, 0, 3);
for( i=1; i <= maxcolor; i ++)
{
hsi2rgb(4.6-1.5*i/maxcolor,(double)(i)/maxcolor,(double)(i)/maxcolor,&pal[i]);
}
for( i=maxcolor; i <= 255; i ++)
{
pal[i]=pal[i-1];
{
struct colorvalue *with = &pal[i];
if (with->r<255) with->r += 1;
if (with->r<255) with->r += 1;
if ((~i & 1) && (with->g<215)) with->g += 1;
if ((~i & 1) && (with->b<255)) with->b += 1;
}
}
}
int started = 0;
#define Randomize()
#define randint(a) (rand() % (a))
#define randreal() (((double)rand()) / ((double)RAND_MAX))
#define rand1(a) ((randint(a*2+1))-a)
unsigned char flamearray[BUF_WIDTH];
int morefire;
extern unsigned char *vidbuffer;
/* damn, this seems like such a waste */
static unsigned char pt[BUF_WIDTH * BUF_HEIGHT];
void DrawBurn()
{
int i,j;
int x,p;
int v;
if (!started)
{
started = 1;
for( i=xstart; i <= xend; i++)
{
flamearray[i]=0;
}
Randomize();
morefire=1;
memset(pt, 0, BUF_HEIGHT * BUF_WIDTH);
}
/* Put the values from FlameArray on the bottom line of the screen */
memcpy(pt+((BUF_HEIGHT-1)*BUF_WIDTH)+xstart,flamearray, width);
/* This loop makes the actual flames */
for( i=xstart; i <= xend; i++)
{
for( j=miny; j <= (BUF_HEIGHT-1); j ++)
{
v = pt[j*BUF_WIDTH + i];
if ((v==0) ||
(v<decay) ||
(i<=xstart) ||
(i>=xend))
pt[(j-1)*BUF_WIDTH + i] = 0;
else
pt[((j-1)*BUF_WIDTH) + (i-(randint(3)-1))] = v - randint(decay);
}
}
/* Match? */
if (randint(150)==0)
{
memset(flamearray + xstart + randint(xend-xstart-5),255,5);
}
/* This loop controls the "root" of the
flames, i.e. the values in FlameArray. */
for( i=xstart; i <= xend; i++)
{
x=flamearray[i];
if (x<minfire) /* Increase by the "burnability" */
{
/* Starting to burn: */
if (x>10) x += randint(fireincrease);
}
else
/* Otherwise randomize and increase by intensity (is burning) */
x += rand1(rootrand)+morefire;
if (x>255) x=255; /* X Too large? */
flamearray[i]=x;
}
/* Smoothen the values of FrameArray to avoid "discrete" flames */
p=0;
for( i=xstart+smooth; i <= xend-smooth; i++)
{
x=0;
for( j=-smooth; j <= smooth; j++) x += flamearray[i+j];
flamearray[i] = x / ((smooth << 1) + 1);
}
for (x=0; x < BUF_WIDTH*BUF_HEIGHT; x++)
{
i = vidbuffer[x];
j = pt[x] >> 3;
if (j > i) { vidbuffer[x] = j; }
else { vidbuffer[x] = ((i + j) >> 1) + 1; }
}
}

418
zsnes/src/effects/fixsin.h Normal file
View File

@@ -0,0 +1,418 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define FSINMAX 2047
#define FSin(x) FSinTab[(x)&FSINMAX]
#define FCos(x) FCosTab[(x)&FSINMAX]
int FSinTab[2048] =
{
0, 201, 402, 603, 804, 1005, 1206, 1407, 1608, 1809, 2010, 2211, 2412, 2613,
2814, 3014, 3215, 3416, 3617, 3818, 4018, 4219, 4420, 4620, 4821, 5021, 5222,
5422, 5622, 5823, 6023, 6223, 6423, 6623, 6823, 7023, 7223, 7423, 7623, 7822,
8022, 8221, 8421, 8620, 8819, 9019, 9218, 9417, 9616, 9814, 10013, 10212, 10410,
10609, 10807, 11006, 11204, 11402, 11600, 11797, 11995, 12193, 12390, 12588,
12785, 12982, 13179, 13376, 13573, 13769, 13966, 14162, 14359, 14555, 14751,
14946, 15142, 15338, 15533, 15728, 15923, 16118, 16313, 16508, 16702, 16897,
17091, 17285, 17479, 17672, 17866, 18059, 18253, 18446, 18638, 18831, 19024,
19216, 19408, 19600, 19792, 19983, 20175, 20366, 20557, 20748, 20938, 21129,
21319, 21509, 21699, 21889, 22078, 22267, 22456, 22645, 22833, 23022, 23210,
23398, 23586, 23773, 23960, 24147, 24334, 24521, 24707, 24893, 25079, 25265,
25450, 25635, 25820, 26005, 26189, 26373, 26557, 26741, 26925, 27108, 27291,
27473, 27656, 27838, 28020, 28201, 28383, 28564, 28745, 28925, 29105, 29285,
29465, 29645, 29824, 30003, 30181, 30360, 30538, 30715, 30893, 31070, 31247,
31424, 31600, 31776, 31952, 32127, 32302, 32477, 32651, 32826, 32999, 33173,
33346, 33519, 33692, 33864, 34036, 34208, 34379, 34550, 34721, 34891, 35061,
35231, 35400, 35569, 35738, 35906, 36074, 36242, 36409, 36576, 36743, 36909,
37075, 37241, 37406, 37571, 37736, 37900, 38064, 38227, 38390, 38553, 38716,
38878, 39039, 39201, 39362, 39522, 39682, 39842, 40002, 40161, 40319, 40478,
40636, 40793, 40950, 41107, 41263, 41419, 41575, 41730, 41885, 42040, 42194,
42347, 42501, 42653, 42806, 42958, 43110, 43261, 43412, 43562, 43712, 43862,
44011, 44160, 44308, 44456, 44603, 44750, 44897, 45043, 45189, 45335, 45480,
45624, 45768, 45912, 46055, 46198, 46340, 46482, 46624, 46765, 46906, 47046,
47186, 47325, 47464, 47602, 47740, 47878, 48015, 48151, 48288, 48423, 48558,
48693, 48828, 48961, 49095, 49228, 49360, 49492, 49624, 49755, 49886, 50016,
50146, 50275, 50403, 50532, 50660, 50787, 50914, 51040, 51166, 51291, 51416,
51541, 51665, 51788, 51911, 52033, 52155, 52277, 52398, 52518, 52639, 52758,
52877, 52996, 53114, 53231, 53348, 53465, 53581, 53696, 53811, 53926, 54040,
54153, 54266, 54379, 54491, 54602, 54713, 54823, 54933, 55043, 55152, 55260,
55368, 55475, 55582, 55688, 55794, 55899, 56004, 56108, 56212, 56315, 56417,
56519, 56621, 56722, 56822, 56922, 57022, 57120, 57219, 57316, 57414, 57510,
57606, 57702, 57797, 57892, 57986, 58079, 58172, 58264, 58356, 58447, 58538,
58628, 58718, 58807, 58895, 58983, 59070, 59157, 59243, 59329, 59414, 59499,
59583, 59666, 59749, 59831, 59913, 59994, 60075, 60155, 60235, 60313, 60392,
60470, 60547, 60624, 60700, 60775, 60850, 60924, 60998, 61071, 61144, 61216,
61288, 61359, 61429, 61499, 61568, 61637, 61705, 61772, 61839, 61905, 61971,
62036, 62100, 62164, 62228, 62291, 62353, 62414, 62475, 62536, 62596, 62655,
62714, 62772, 62829, 62886, 62942, 62998, 63053, 63108, 63162, 63215, 63268,
63320, 63371, 63422, 63473, 63522, 63571, 63620, 63668, 63715, 63762, 63808,
63854, 63899, 63943, 63987, 64030, 64073, 64115, 64156, 64197, 64237, 64276,
64315, 64353, 64391, 64428, 64465, 64501, 64536, 64571, 64605, 64638, 64671,
64703, 64735, 64766, 64796, 64826, 64855, 64884, 64912, 64939, 64966, 64992,
65018, 65043, 65067, 65091, 65114, 65136, 65158, 65179, 65200, 65220, 65239,
65258, 65276, 65294, 65311, 65327, 65343, 65358, 65372, 65386, 65400, 65412,
65424, 65436, 65446, 65457, 65466, 65475, 65483, 65491, 65498, 65505, 65511,
65516, 65520, 65524, 65528, 65531, 65533, 65534, 65535, 65536, 65535, 65534,
65533, 65531, 65528, 65524, 65520, 65516, 65511, 65505, 65498, 65491, 65483,
65475, 65466, 65457, 65446, 65436, 65424, 65412, 65400, 65386, 65372, 65358,
65343, 65327, 65311, 65294, 65276, 65258, 65239, 65220, 65200, 65179, 65158,
65136, 65114, 65091, 65067, 65043, 65018, 64992, 64966, 64939, 64912, 64884,
64855, 64826, 64796, 64766, 64735, 64703, 64671, 64638, 64605, 64571, 64536,
64501, 64465, 64428, 64391, 64353, 64315, 64276, 64237, 64197, 64156, 64115,
64073, 64030, 63987, 63943, 63899, 63854, 63808, 63762, 63715, 63668, 63620,
63571, 63522, 63473, 63422, 63371, 63320, 63268, 63215, 63162, 63108, 63053,
62998, 62942, 62886, 62829, 62772, 62714, 62655, 62596, 62536, 62475, 62414,
62353, 62291, 62228, 62164, 62100, 62036, 61971, 61905, 61839, 61772, 61705,
61637, 61568, 61499, 61429, 61359, 61288, 61216, 61144, 61071, 60998, 60924,
60850, 60775, 60700, 60624, 60547, 60470, 60392, 60313, 60235, 60155, 60075,
59994, 59913, 59831, 59749, 59666, 59583, 59499, 59414, 59329, 59243, 59157,
59070, 58983, 58895, 58807, 58718, 58628, 58538, 58447, 58356, 58264, 58172,
58079, 57986, 57892, 57797, 57702, 57606, 57510, 57414, 57316, 57219, 57120,
57022, 56922, 56822, 56722, 56621, 56519, 56417, 56315, 56212, 56108, 56004,
55899, 55794, 55688, 55582, 55475, 55368, 55260, 55152, 55043, 54933, 54823,
54713, 54602, 54491, 54379, 54266, 54153, 54040, 53926, 53811, 53696, 53581,
53465, 53348, 53231, 53114, 52996, 52877, 52758, 52639, 52518, 52398, 52277,
52155, 52033, 51911, 51788, 51665, 51541, 51416, 51291, 51166, 51040, 50914,
50787, 50660, 50532, 50403, 50275, 50146, 50016, 49886, 49755, 49624, 49492,
49360, 49228, 49095, 48961, 48828, 48693, 48558, 48423, 48288, 48151, 48015,
47878, 47740, 47602, 47464, 47325, 47186, 47046, 46906, 46765, 46624, 46482,
46340, 46198, 46055, 45912, 45768, 45624, 45480, 45335, 45189, 45043, 44897,
44750, 44603, 44456, 44308, 44160, 44011, 43862, 43712, 43562, 43412, 43261,
43110, 42958, 42806, 42653, 42501, 42347, 42194, 42040, 41885, 41730, 41575,
41419, 41263, 41107, 40950, 40793, 40636, 40478, 40319, 40161, 40002, 39842,
39682, 39522, 39362, 39201, 39039, 38878, 38716, 38553, 38390, 38227, 38064,
37900, 37736, 37571, 37406, 37241, 37075, 36909, 36743, 36576, 36409, 36242,
36074, 35906, 35738, 35569, 35400, 35231, 35061, 34891, 34721, 34550, 34379,
34208, 34036, 33864, 33692, 33519, 33346, 33173, 32999, 32826, 32651, 32477,
32302, 32127, 31952, 31776, 31600, 31424, 31247, 31070, 30893, 30715, 30538,
30360, 30181, 30003, 29824, 29645, 29465, 29285, 29105, 28925, 28745, 28564,
28383, 28201, 28020, 27838, 27656, 27473, 27291, 27108, 26925, 26741, 26557,
26373, 26189, 26005, 25820, 25635, 25450, 25265, 25079, 24893, 24707, 24521,
24334, 24147, 23960, 23773, 23586, 23398, 23210, 23022, 22833, 22645, 22456,
22267, 22078, 21889, 21699, 21509, 21319, 21129, 20938, 20748, 20557, 20366,
20175, 19983, 19792, 19600, 19408, 19216, 19024, 18831, 18638, 18446, 18253,
18059, 17866, 17672, 17479, 17285, 17091, 16897, 16702, 16508, 16313, 16118,
15923, 15728, 15533, 15338, 15142, 14946, 14751, 14555, 14359, 14162, 13966,
13769, 13573, 13376, 13179, 12982, 12785, 12588, 12390, 12193, 11995, 11797,
11600, 11402, 11204, 11006, 10807, 10609, 10410, 10212, 10013, 9814, 9616, 9417,
9218, 9019, 8819, 8620, 8421, 8221, 8022, 7822, 7623, 7423, 7223, 7023, 6823,
6623, 6423, 6223, 6023, 5823, 5622, 5422, 5222, 5021, 4821, 4620, 4420, 4219,
4018, 3818, 3617, 3416, 3215, 3014, 2814, 2613, 2412, 2211, 2010, 1809, 1608,
1407, 1206, 1005, 804, 603, 402, 201, 0, -201, -402, -603, -804, -1005, -1206,
-1407, -1608, -1809, -2010, -2211, -2412, -2613, -2814, -3014, -3215, -3416,
-3617, -3818, -4018, -4219, -4420, -4620, -4821, -5021, -5222, -5422, -5622,
-5823, -6023, -6223, -6423, -6623, -6823, -7023, -7223, -7423, -7623, -7822,
-8022, -8221, -8421, -8620, -8819, -9019, -9218, -9417, -9616, -9814, -10013,
-10212, -10410, -10609, -10807, -11006, -11204, -11402, -11600, -11797, -11995,
-12193, -12390, -12588, -12785, -12982, -13179, -13376, -13573, -13769, -13966,
-14162, -14359, -14555, -14751, -14946, -15142, -15338, -15533, -15728, -15923,
-16118, -16313, -16508, -16702, -16897, -17091, -17285, -17479, -17672, -17866,
-18059, -18253, -18446, -18638, -18831, -19024, -19216, -19408, -19600, -19792,
-19983, -20175, -20366, -20557, -20748, -20938, -21129, -21319, -21509, -21699,
-21889, -22078, -22267, -22456, -22645, -22833, -23022, -23210, -23398, -23586,
-23773, -23960, -24147, -24334, -24521, -24707, -24893, -25079, -25265, -25450,
-25635, -25820, -26005, -26189, -26373, -26557, -26741, -26925, -27108, -27291,
-27473, -27656, -27838, -28020, -28201, -28383, -28564, -28745, -28925, -29105,
-29285, -29465, -29645, -29824, -30003, -30181, -30360, -30538, -30715, -30893,
-31070, -31247, -31424, -31600, -31776, -31952, -32127, -32302, -32477, -32651,
-32826, -32999, -33173, -33346, -33519, -33692, -33864, -34036, -34208, -34379,
-34550, -34721, -34891, -35061, -35231, -35400, -35569, -35738, -35906, -36074,
-36242, -36409, -36576, -36743, -36909, -37075, -37241, -37406, -37571, -37736,
-37900, -38064, -38227, -38390, -38553, -38716, -38878, -39039, -39201, -39362,
-39522, -39682, -39842, -40002, -40161, -40319, -40478, -40636, -40793, -40950,
-41107, -41263, -41419, -41575, -41730, -41885, -42040, -42194, -42347, -42501,
-42653, -42806, -42958, -43110, -43261, -43412, -43562, -43712, -43862, -44011,
-44160, -44308, -44456, -44603, -44750, -44897, -45043, -45189, -45335, -45480,
-45624, -45768, -45912, -46055, -46198, -46340, -46482, -46624, -46765, -46906,
-47046, -47186, -47325, -47464, -47602, -47740, -47878, -48015, -48151, -48288,
-48423, -48558, -48693, -48828, -48961, -49095, -49228, -49360, -49492, -49624,
-49755, -49886, -50016, -50146, -50275, -50403, -50532, -50660, -50787, -50914,
-51040, -51166, -51291, -51416, -51541, -51665, -51788, -51911, -52033, -52155,
-52277, -52398, -52518, -52639, -52758, -52877, -52996, -53114, -53231, -53348,
-53465, -53581, -53696, -53811, -53926, -54040, -54153, -54266, -54379, -54491,
-54602, -54713, -54823, -54933, -55043, -55152, -55260, -55368, -55475, -55582,
-55688, -55794, -55899, -56004, -56108, -56212, -56315, -56417, -56519, -56621,
-56722, -56822, -56922, -57022, -57120, -57219, -57316, -57414, -57510, -57606,
-57702, -57797, -57892, -57986, -58079, -58172, -58264, -58356, -58447, -58538,
-58628, -58718, -58807, -58895, -58983, -59070, -59157, -59243, -59329, -59414,
-59499, -59583, -59666, -59749, -59831, -59913, -59994, -60075, -60155, -60235,
-60313, -60392, -60470, -60547, -60624, -60700, -60775, -60850, -60924, -60998,
-61071, -61144, -61216, -61288, -61359, -61429, -61499, -61568, -61637, -61705,
-61772, -61839, -61905, -61971, -62036, -62100, -62164, -62228, -62291, -62353,
-62414, -62475, -62536, -62596, -62655, -62714, -62772, -62829, -62886, -62942,
-62998, -63053, -63108, -63162, -63215, -63268, -63320, -63371, -63422, -63473,
-63522, -63571, -63620, -63668, -63715, -63762, -63808, -63854, -63899, -63943,
-63987, -64030, -64073, -64115, -64156, -64197, -64237, -64276, -64315, -64353,
-64391, -64428, -64465, -64501, -64536, -64571, -64605, -64638, -64671, -64703,
-64735, -64766, -64796, -64826, -64855, -64884, -64912, -64939, -64966, -64992,
-65018, -65043, -65067, -65091, -65114, -65136, -65158, -65179, -65200, -65220,
-65239, -65258, -65276, -65294, -65311, -65327, -65343, -65358, -65372, -65386,
-65400, -65412, -65424, -65436, -65446, -65457, -65466, -65475, -65483, -65491,
-65498, -65505, -65511, -65516, -65520, -65524, -65528, -65531, -65533, -65534,
-65535, -65536, -65535, -65534, -65533, -65531, -65528, -65524, -65520, -65516,
-65511, -65505, -65498, -65491, -65483, -65475, -65466, -65457, -65446, -65436,
-65424, -65412, -65400, -65386, -65372, -65358, -65343, -65327, -65311, -65294,
-65276, -65258, -65239, -65220, -65200, -65179, -65158, -65136, -65114, -65091,
-65067, -65043, -65018, -64992, -64966, -64939, -64912, -64884, -64855, -64826,
-64796, -64766, -64735, -64703, -64671, -64638, -64605, -64571, -64536, -64501,
-64465, -64428, -64391, -64353, -64315, -64276, -64237, -64197, -64156, -64115,
-64073, -64030, -63987, -63943, -63899, -63854, -63808, -63762, -63715, -63668,
-63620, -63571, -63522, -63473, -63422, -63371, -63320, -63268, -63215, -63162,
-63108, -63053, -62998, -62942, -62886, -62829, -62772, -62714, -62655, -62596,
-62536, -62475, -62414, -62353, -62291, -62228, -62164, -62100, -62036, -61971,
-61905, -61839, -61772, -61705, -61637, -61568, -61499, -61429, -61359, -61288,
-61216, -61144, -61071, -60998, -60924, -60850, -60775, -60700, -60624, -60547,
-60470, -60392, -60313, -60235, -60155, -60075, -59994, -59913, -59831, -59749,
-59666, -59583, -59499, -59414, -59329, -59243, -59157, -59070, -58983, -58895,
-58807, -58718, -58628, -58538, -58447, -58356, -58264, -58172, -58079, -57986,
-57892, -57797, -57702, -57606, -57510, -57414, -57316, -57219, -57120, -57022,
-56922, -56822, -56722, -56621, -56519, -56417, -56315, -56212, -56108, -56004,
-55899, -55794, -55688, -55582, -55475, -55368, -55260, -55152, -55043, -54933,
-54823, -54713, -54602, -54491, -54379, -54266, -54153, -54040, -53926, -53811,
-53696, -53581, -53465, -53348, -53231, -53114, -52996, -52877, -52758, -52639,
-52518, -52398, -52277, -52155, -52033, -51911, -51788, -51665, -51541, -51416,
-51291, -51166, -51040, -50914, -50787, -50660, -50532, -50403, -50275, -50146,
-50016, -49886, -49755, -49624, -49492, -49360, -49228, -49095, -48961, -48828,
-48693, -48558, -48423, -48288, -48151, -48015, -47878, -47740, -47602, -47464,
-47325, -47186, -47046, -46906, -46765, -46624, -46482, -46340, -46198, -46055,
-45912, -45768, -45624, -45480, -45335, -45189, -45043, -44897, -44750, -44603,
-44456, -44308, -44160, -44011, -43862, -43712, -43562, -43412, -43261, -43110,
-42958, -42806, -42653, -42501, -42347, -42194, -42040, -41885, -41730, -41575,
-41419, -41263, -41107, -40950, -40793, -40636, -40478, -40319, -40161, -40002,
-39842, -39682, -39522, -39362, -39201, -39039, -38878, -38716, -38553, -38390,
-38227, -38064, -37900, -37736, -37571, -37406, -37241, -37075, -36909, -36743,
-36576, -36409, -36242, -36074, -35906, -35738, -35569, -35400, -35231, -35061,
-34891, -34721, -34550, -34379, -34208, -34036, -33864, -33692, -33519, -33346,
-33173, -32999, -32826, -32651, -32477, -32302, -32127, -31952, -31776, -31600,
-31424, -31247, -31070, -30893, -30715, -30538, -30360, -30181, -30003, -29824,
-29645, -29465, -29285, -29105, -28925, -28745, -28564, -28383, -28201, -28020,
-27838, -27656, -27473, -27291, -27108, -26925, -26741, -26557, -26373, -26189,
-26005, -25820, -25635, -25450, -25265, -25079, -24893, -24707, -24521, -24334,
-24147, -23960, -23773, -23586, -23398, -23210, -23022, -22833, -22645, -22456,
-22267, -22078, -21889, -21699, -21509, -21319, -21129, -20938, -20748, -20557,
-20366, -20175, -19983, -19792, -19600, -19408, -19216, -19024, -18831, -18638,
-18446, -18253, -18059, -17866, -17672, -17479, -17285, -17091, -16897, -16702,
-16508, -16313, -16118, -15923, -15728, -15533, -15338, -15142, -14946, -14751,
-14555, -14359, -14162, -13966, -13769, -13573, -13376, -13179, -12982, -12785,
-12588, -12390, -12193, -11995, -11797, -11600, -11402, -11204, -11006, -10807,
-10609, -10410, -10212, -10013, -9814, -9616, -9417, -9218, -9019, -8819, -8620,
-8421, -8221, -8022, -7822, -7623, -7423, -7223, -7023, -6823, -6623, -6423,
-6223, -6023, -5823, -5622, -5422, -5222, -5021, -4821, -4620, -4420, -4219,
-4018, -3818, -3617, -3416, -3215, -3014, -2814, -2613, -2412, -2211, -2010,
-1809, -1608, -1407, -1206, -1005, -804, -603, -402, -201
};
int FCosTab[2048] =
{
65536, 65535, 65534, 65533, 65531, 65528, 65524, 65520, 65516, 65511, 65505,
65498, 65491, 65483, 65475, 65466, 65457, 65446, 65436, 65424, 65412, 65400,
65386, 65372, 65358, 65343, 65327, 65311, 65294, 65276, 65258, 65239, 65220,
65200, 65179, 65158, 65136, 65114, 65091, 65067, 65043, 65018, 64992, 64966,
64939, 64912, 64884, 64855, 64826, 64796, 64766, 64735, 64703, 64671, 64638,
64605, 64571, 64536, 64501, 64465, 64428, 64391, 64353, 64315, 64276, 64237,
64197, 64156, 64115, 64073, 64030, 63987, 63943, 63899, 63854, 63808, 63762,
63715, 63668, 63620, 63571, 63522, 63473, 63422, 63371, 63320, 63268, 63215,
63162, 63108, 63053, 62998, 62942, 62886, 62829, 62772, 62714, 62655, 62596,
62536, 62475, 62414, 62353, 62291, 62228, 62164, 62100, 62036, 61971, 61905,
61839, 61772, 61705, 61637, 61568, 61499, 61429, 61359, 61288, 61216, 61144,
61071, 60998, 60924, 60850, 60775, 60700, 60624, 60547, 60470, 60392, 60313,
60235, 60155, 60075, 59994, 59913, 59831, 59749, 59666, 59583, 59499, 59414,
59329, 59243, 59157, 59070, 58983, 58895, 58807, 58718, 58628, 58538, 58447,
58356, 58264, 58172, 58079, 57986, 57892, 57797, 57702, 57606, 57510, 57414,
57316, 57219, 57120, 57022, 56922, 56822, 56722, 56621, 56519, 56417, 56315,
56212, 56108, 56004, 55899, 55794, 55688, 55582, 55475, 55368, 55260, 55152,
55043, 54933, 54823, 54713, 54602, 54491, 54379, 54266, 54153, 54040, 53926,
53811, 53696, 53581, 53465, 53348, 53231, 53114, 52996, 52877, 52758, 52639,
52518, 52398, 52277, 52155, 52033, 51911, 51788, 51665, 51541, 51416, 51291,
51166, 51040, 50914, 50787, 50660, 50532, 50403, 50275, 50146, 50016, 49886,
49755, 49624, 49492, 49360, 49228, 49095, 48961, 48828, 48693, 48558, 48423,
48288, 48151, 48015, 47878, 47740, 47602, 47464, 47325, 47186, 47046, 46906,
46765, 46624, 46482, 46340, 46198, 46055, 45912, 45768, 45624, 45480, 45335,
45189, 45043, 44897, 44750, 44603, 44456, 44308, 44160, 44011, 43862, 43712,
43562, 43412, 43261, 43110, 42958, 42806, 42653, 42501, 42347, 42194, 42040,
41885, 41730, 41575, 41419, 41263, 41107, 40950, 40793, 40636, 40478, 40319,
40161, 40002, 39842, 39682, 39522, 39362, 39201, 39039, 38878, 38716, 38553,
38390, 38227, 38064, 37900, 37736, 37571, 37406, 37241, 37075, 36909, 36743,
36576, 36409, 36242, 36074, 35906, 35738, 35569, 35400, 35231, 35061, 34891,
34721, 34550, 34379, 34208, 34036, 33864, 33692, 33519, 33346, 33173, 32999,
32826, 32651, 32477, 32302, 32127, 31952, 31776, 31600, 31424, 31247, 31070,
30893, 30715, 30538, 30360, 30181, 30003, 29824, 29645, 29465, 29285, 29105,
28925, 28745, 28564, 28383, 28201, 28020, 27838, 27656, 27473, 27291, 27108,
26925, 26741, 26557, 26373, 26189, 26005, 25820, 25635, 25450, 25265, 25079,
24893, 24707, 24521, 24334, 24147, 23960, 23773, 23586, 23398, 23210, 23022,
22833, 22645, 22456, 22267, 22078, 21889, 21699, 21509, 21319, 21129, 20938,
20748, 20557, 20366, 20175, 19983, 19792, 19600, 19408, 19216, 19024, 18831,
18638, 18446, 18253, 18059, 17866, 17672, 17479, 17285, 17091, 16897, 16702,
16508, 16313, 16118, 15923, 15728, 15533, 15338, 15142, 14946, 14751, 14555,
14359, 14162, 13966, 13769, 13573, 13376, 13179, 12982, 12785, 12588, 12390,
12193, 11995, 11797, 11600, 11402, 11204, 11006, 10807, 10609, 10410, 10212,
10013, 9814, 9616, 9417, 9218, 9019, 8819, 8620, 8421, 8221, 8022, 7822, 7623,
7423, 7223, 7023, 6823, 6623, 6423, 6223, 6023, 5823, 5622, 5422, 5222, 5021,
4821, 4620, 4420, 4219, 4018, 3818, 3617, 3416, 3215, 3014, 2814, 2613, 2412,
2211, 2010, 1809, 1608, 1407, 1206, 1005, 804, 603, 402, 201, 0, -201, -402,
-603, -804, -1005, -1206, -1407, -1608, -1809, -2010, -2211, -2412, -2613, -2814,
-3014, -3215, -3416, -3617, -3818, -4018, -4219, -4420, -4620, -4821, -5021,
-5222, -5422, -5622, -5823, -6023, -6223, -6423, -6623, -6823, -7023, -7223,
-7423, -7623, -7822, -8022, -8221, -8421, -8620, -8819, -9019, -9218, -9417,
-9616, -9814, -10013, -10212, -10410, -10609, -10807, -11006, -11204, -11402,
-11600, -11797, -11995, -12193, -12390, -12588, -12785, -12982, -13179, -13376,
-13573, -13769, -13966, -14162, -14359, -14555, -14751, -14946, -15142, -15338,
-15533, -15728, -15923, -16118, -16313, -16508, -16702, -16897, -17091, -17285,
-17479, -17672, -17866, -18059, -18253, -18446, -18638, -18831, -19024, -19216,
-19408, -19600, -19792, -19983, -20175, -20366, -20557, -20748, -20938, -21129,
-21319, -21509, -21699, -21889, -22078, -22267, -22456, -22645, -22833, -23022,
-23210, -23398, -23586, -23773, -23960, -24147, -24334, -24521, -24707, -24893,
-25079, -25265, -25450, -25635, -25820, -26005, -26189, -26373, -26557, -26741,
-26925, -27108, -27291, -27473, -27656, -27838, -28020, -28201, -28383, -28564,
-28745, -28925, -29105, -29285, -29465, -29645, -29824, -30003, -30181, -30360,
-30538, -30715, -30893, -31070, -31247, -31424, -31600, -31776, -31952, -32127,
-32302, -32477, -32651, -32826, -32999, -33173, -33346, -33519, -33692, -33864,
-34036, -34208, -34379, -34550, -34721, -34891, -35061, -35231, -35400, -35569,
-35738, -35906, -36074, -36242, -36409, -36576, -36743, -36909, -37075, -37241,
-37406, -37571, -37736, -37900, -38064, -38227, -38390, -38553, -38716, -38878,
-39039, -39201, -39362, -39522, -39682, -39842, -40002, -40161, -40319, -40478,
-40636, -40793, -40950, -41107, -41263, -41419, -41575, -41730, -41885, -42040,
-42194, -42347, -42501, -42653, -42806, -42958, -43110, -43261, -43412, -43562,
-43712, -43862, -44011, -44160, -44308, -44456, -44603, -44750, -44897, -45043,
-45189, -45335, -45480, -45624, -45768, -45912, -46055, -46198, -46340, -46482,
-46624, -46765, -46906, -47046, -47186, -47325, -47464, -47602, -47740, -47878,
-48015, -48151, -48288, -48423, -48558, -48693, -48828, -48961, -49095, -49228,
-49360, -49492, -49624, -49755, -49886, -50016, -50146, -50275, -50403, -50532,
-50660, -50787, -50914, -51040, -51166, -51291, -51416, -51541, -51665, -51788,
-51911, -52033, -52155, -52277, -52398, -52518, -52639, -52758, -52877, -52996,
-53114, -53231, -53348, -53465, -53581, -53696, -53811, -53926, -54040, -54153,
-54266, -54379, -54491, -54602, -54713, -54823, -54933, -55043, -55152, -55260,
-55368, -55475, -55582, -55688, -55794, -55899, -56004, -56108, -56212, -56315,
-56417, -56519, -56621, -56722, -56822, -56922, -57022, -57120, -57219, -57316,
-57414, -57510, -57606, -57702, -57797, -57892, -57986, -58079, -58172, -58264,
-58356, -58447, -58538, -58628, -58718, -58807, -58895, -58983, -59070, -59157,
-59243, -59329, -59414, -59499, -59583, -59666, -59749, -59831, -59913, -59994,
-60075, -60155, -60235, -60313, -60392, -60470, -60547, -60624, -60700, -60775,
-60850, -60924, -60998, -61071, -61144, -61216, -61288, -61359, -61429, -61499,
-61568, -61637, -61705, -61772, -61839, -61905, -61971, -62036, -62100, -62164,
-62228, -62291, -62353, -62414, -62475, -62536, -62596, -62655, -62714, -62772,
-62829, -62886, -62942, -62998, -63053, -63108, -63162, -63215, -63268, -63320,
-63371, -63422, -63473, -63522, -63571, -63620, -63668, -63715, -63762, -63808,
-63854, -63899, -63943, -63987, -64030, -64073, -64115, -64156, -64197, -64237,
-64276, -64315, -64353, -64391, -64428, -64465, -64501, -64536, -64571, -64605,
-64638, -64671, -64703, -64735, -64766, -64796, -64826, -64855, -64884, -64912,
-64939, -64966, -64992, -65018, -65043, -65067, -65091, -65114, -65136, -65158,
-65179, -65200, -65220, -65239, -65258, -65276, -65294, -65311, -65327, -65343,
-65358, -65372, -65386, -65400, -65412, -65424, -65436, -65446, -65457, -65466,
-65475, -65483, -65491, -65498, -65505, -65511, -65516, -65520, -65524, -65528,
-65531, -65533, -65534, -65535, -65536, -65535, -65534, -65533, -65531, -65528,
-65524, -65520, -65516, -65511, -65505, -65498, -65491, -65483, -65475, -65466,
-65457, -65446, -65436, -65424, -65412, -65400, -65386, -65372, -65358, -65343,
-65327, -65311, -65294, -65276, -65258, -65239, -65220, -65200, -65179, -65158,
-65136, -65114, -65091, -65067, -65043, -65018, -64992, -64966, -64939, -64912,
-64884, -64855, -64826, -64796, -64766, -64735, -64703, -64671, -64638, -64605,
-64571, -64536, -64501, -64465, -64428, -64391, -64353, -64315, -64276, -64237,
-64197, -64156, -64115, -64073, -64030, -63987, -63943, -63899, -63854, -63808,
-63762, -63715, -63668, -63620, -63571, -63522, -63473, -63422, -63371, -63320,
-63268, -63215, -63162, -63108, -63053, -62998, -62942, -62886, -62829, -62772,
-62714, -62655, -62596, -62536, -62475, -62414, -62353, -62291, -62228, -62164,
-62100, -62036, -61971, -61905, -61839, -61772, -61705, -61637, -61568, -61499,
-61429, -61359, -61288, -61216, -61144, -61071, -60998, -60924, -60850, -60775,
-60700, -60624, -60547, -60470, -60392, -60313, -60235, -60155, -60075, -59994,
-59913, -59831, -59749, -59666, -59583, -59499, -59414, -59329, -59243, -59157,
-59070, -58983, -58895, -58807, -58718, -58628, -58538, -58447, -58356, -58264,
-58172, -58079, -57986, -57892, -57797, -57702, -57606, -57510, -57414, -57316,
-57219, -57120, -57022, -56922, -56822, -56722, -56621, -56519, -56417, -56315,
-56212, -56108, -56004, -55899, -55794, -55688, -55582, -55475, -55368, -55260,
-55152, -55043, -54933, -54823, -54713, -54602, -54491, -54379, -54266, -54153,
-54040, -53926, -53811, -53696, -53581, -53465, -53348, -53231, -53114, -52996,
-52877, -52758, -52639, -52518, -52398, -52277, -52155, -52033, -51911, -51788,
-51665, -51541, -51416, -51291, -51166, -51040, -50914, -50787, -50660, -50532,
-50403, -50275, -50146, -50016, -49886, -49755, -49624, -49492, -49360, -49228,
-49095, -48961, -48828, -48693, -48558, -48423, -48288, -48151, -48015, -47878,
-47740, -47602, -47464, -47325, -47186, -47046, -46906, -46765, -46624, -46482,
-46340, -46198, -46055, -45912, -45768, -45624, -45480, -45335, -45189, -45043,
-44897, -44750, -44603, -44456, -44308, -44160, -44011, -43862, -43712, -43562,
-43412, -43261, -43110, -42958, -42806, -42653, -42501, -42347, -42194, -42040,
-41885, -41730, -41575, -41419, -41263, -41107, -40950, -40793, -40636, -40478,
-40319, -40161, -40002, -39842, -39682, -39522, -39362, -39201, -39039, -38878,
-38716, -38553, -38390, -38227, -38064, -37900, -37736, -37571, -37406, -37241,
-37075, -36909, -36743, -36576, -36409, -36242, -36074, -35906, -35738, -35569,
-35400, -35231, -35061, -34891, -34721, -34550, -34379, -34208, -34036, -33864,
-33692, -33519, -33346, -33173, -32999, -32826, -32651, -32477, -32302, -32127,
-31952, -31776, -31600, -31424, -31247, -31070, -30893, -30715, -30538, -30360,
-30181, -30003, -29824, -29645, -29465, -29285, -29105, -28925, -28745, -28564,
-28383, -28201, -28020, -27838, -27656, -27473, -27291, -27108, -26925, -26741,
-26557, -26373, -26189, -26005, -25820, -25635, -25450, -25265, -25079, -24893,
-24707, -24521, -24334, -24147, -23960, -23773, -23586, -23398, -23210, -23022,
-22833, -22645, -22456, -22267, -22078, -21889, -21699, -21509, -21319, -21129,
-20938, -20748, -20557, -20366, -20175, -19983, -19792, -19600, -19408, -19216,
-19024, -18831, -18638, -18446, -18253, -18059, -17866, -17672, -17479, -17285,
-17091, -16897, -16702, -16508, -16313, -16118, -15923, -15728, -15533, -15338,
-15142, -14946, -14751, -14555, -14359, -14162, -13966, -13769, -13573, -13376,
-13179, -12982, -12785, -12588, -12390, -12193, -11995, -11797, -11600, -11402,
-11204, -11006, -10807, -10609, -10410, -10212, -10013, -9814, -9616, -9417,
-9218, -9019, -8819, -8620, -8421, -8221, -8022, -7822, -7623, -7423, -7223,
-7023, -6823, -6623, -6423, -6223, -6023, -5823, -5622, -5422, -5222, -5021,
-4821, -4620, -4420, -4219, -4018, -3818, -3617, -3416, -3215, -3014, -2814,
-2613, -2412, -2211, -2010, -1809, -1608, -1407, -1206, -1005, -804, -603, -402,
-201, 0, 201, 402, 603, 804, 1005, 1206, 1407, 1608, 1809, 2010, 2211, 2412,
2613, 2814, 3014, 3215, 3416, 3617, 3818, 4018, 4219, 4420, 4620, 4821, 5021,
5222, 5422, 5622, 5823, 6023, 6223, 6423, 6623, 6823, 7023, 7223, 7423, 7623,
7822, 8022, 8221, 8421, 8620, 8819, 9019, 9218, 9417, 9616, 9814, 10013, 10212,
10410, 10609, 10807, 11006, 11204, 11402, 11600, 11797, 11995, 12193, 12390,
12588, 12785, 12982, 13179, 13376, 13573, 13769, 13966, 14162, 14359, 14555,
14751, 14946, 15142, 15338, 15533, 15728, 15923, 16118, 16313, 16508, 16702,
16897, 17091, 17285, 17479, 17672, 17866, 18059, 18253, 18446, 18638, 18831,
19024, 19216, 19408, 19600, 19792, 19983, 20175, 20366, 20557, 20748, 20938,
21129, 21319, 21509, 21699, 21889, 22078, 22267, 22456, 22645, 22833, 23022,
23210, 23398, 23586, 23773, 23960, 24147, 24334, 24521, 24707, 24893, 25079,
25265, 25450, 25635, 25820, 26005, 26189, 26373, 26557, 26741, 26925, 27108,
27291, 27473, 27656, 27838, 28020, 28201, 28383, 28564, 28745, 28925, 29105,
29285, 29465, 29645, 29824, 30003, 30181, 30360, 30538, 30715, 30893, 31070,
31247, 31424, 31600, 31776, 31952, 32127, 32302, 32477, 32651, 32826, 32999,
33173, 33346, 33519, 33692, 33864, 34036, 34208, 34379, 34550, 34721, 34891,
35061, 35231, 35400, 35569, 35738, 35906, 36074, 36242, 36409, 36576, 36743,
36909, 37075, 37241, 37406, 37571, 37736, 37900, 38064, 38227, 38390, 38553,
38716, 38878, 39039, 39201, 39362, 39522, 39682, 39842, 40002, 40161, 40319,
40478, 40636, 40793, 40950, 41107, 41263, 41419, 41575, 41730, 41885, 42040,
42194, 42347, 42501, 42653, 42806, 42958, 43110, 43261, 43412, 43562, 43712,
43862, 44011, 44160, 44308, 44456, 44603, 44750, 44897, 45043, 45189, 45335,
45480, 45624, 45768, 45912, 46055, 46198, 46340, 46482, 46624, 46765, 46906,
47046, 47186, 47325, 47464, 47602, 47740, 47878, 48015, 48151, 48288, 48423,
48558, 48693, 48828, 48961, 49095, 49228, 49360, 49492, 49624, 49755, 49886,
50016, 50146, 50275, 50403, 50532, 50660, 50787, 50914, 51040, 51166, 51291,
51416, 51541, 51665, 51788, 51911, 52033, 52155, 52277, 52398, 52518, 52639,
52758, 52877, 52996, 53114, 53231, 53348, 53465, 53581, 53696, 53811, 53926,
54040, 54153, 54266, 54379, 54491, 54602, 54713, 54823, 54933, 55043, 55152,
55260, 55368, 55475, 55582, 55688, 55794, 55899, 56004, 56108, 56212, 56315,
56417, 56519, 56621, 56722, 56822, 56922, 57022, 57120, 57219, 57316, 57414,
57510, 57606, 57702, 57797, 57892, 57986, 58079, 58172, 58264, 58356, 58447,
58538, 58628, 58718, 58807, 58895, 58983, 59070, 59157, 59243, 59329, 59414,
59499, 59583, 59666, 59749, 59831, 59913, 59994, 60075, 60155, 60235, 60313,
60392, 60470, 60547, 60624, 60700, 60775, 60850, 60924, 60998, 61071, 61144,
61216, 61288, 61359, 61429, 61499, 61568, 61637, 61705, 61772, 61839, 61905,
61971, 62036, 62100, 62164, 62228, 62291, 62353, 62414, 62475, 62536, 62596,
62655, 62714, 62772, 62829, 62886, 62942, 62998, 63053, 63108, 63162, 63215,
63268, 63320, 63371, 63422, 63473, 63522, 63571, 63620, 63668, 63715, 63762,
63808, 63854, 63899, 63943, 63987, 64030, 64073, 64115, 64156, 64197, 64237,
64276, 64315, 64353, 64391, 64428, 64465, 64501, 64536, 64571, 64605, 64638,
64671, 64703, 64735, 64766, 64796, 64826, 64855, 64884, 64912, 64939, 64966,
64992, 65018, 65043, 65067, 65091, 65114, 65136, 65158, 65179, 65200, 65220,
65239, 65258, 65276, 65294, 65311, 65327, 65343, 65358, 65372, 65386, 65400,
65412, 65424, 65436, 65446, 65457, 65466, 65475, 65483, 65491, 65498, 65505,
65511, 65516, 65520, 65524, 65528, 65531, 65533, 65534, 65535
};

162
zsnes/src/effects/smoke.c Normal file
View File

@@ -0,0 +1,162 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Smoke effects implementation by Stainless et al. */
#include <stdlib.h>
#include <string.h>
#define MIN(x, y) \
(((x) < (y)) ? (x) : (y))
#define ABS(x) \
(((x) >= 0) ? (x) : ( - (x)))
#define FIRE_HOTSPOTS 80
static int fire_hotspot [FIRE_HOTSPOTS];
extern char * vidbuffer;
#define SCRW 288
#define SCRH 224
static unsigned char fire_line [SCRW];
static unsigned char fire_buffer [SCRW * SCRH];
static int fire_init_flag;
static void draw_bottom_line_of_fire (void)
{
int count, count2;
memset ((& fire_line), 0, SCRW);
for (count = 0; count < FIRE_HOTSPOTS; count ++)
{
for (count2 = (fire_hotspot [count] - 20);
count2 < (fire_hotspot [count] + 20); count2 ++)
{
if ((count2 >= 0) && (count2 < SCRW))
{
fire_line [count2] =
MIN ((fire_line [count2] + 20) -
ABS (fire_hotspot [count] - count2), 256);
}
}
fire_hotspot [count] += ((rand () & 7) - 3);
if (fire_hotspot [count] < 0)
{
fire_hotspot [count] += SCRW;
}
else if (fire_hotspot [count] >= SCRW)
{
fire_hotspot [count] -= SCRW;
}
}
for (count = 0; count < SCRW; count ++)
{
fire_buffer [((SCRH - 1) *
(SCRW)) + count] = fire_line [count];
}
}
static void init_fire (void)
{
int x, y, pixel, count;
for (count = 0; count < FIRE_HOTSPOTS; count ++)
{
fire_hotspot [count] = (rand () % SCRW);
}
for (count = 0; count < SCRH; count ++)
{
draw_bottom_line_of_fire ();
for (y = 0; y < (SCRH - 1); y ++)
{
for (x = 0; x < SCRW; x ++)
{
pixel = fire_buffer [((y + 1) * SCRW) + x];
if (pixel > 0)
{
pixel --;
}
fire_buffer [(y * SCRW) + x] = pixel;
}
}
}
fire_init_flag = 1;
}
void DrawSmoke (void)
{
int x, y, pixel, pixel2;
if (! fire_init_flag)
{
init_fire ();
}
draw_bottom_line_of_fire ();
for (y = 0; y < (SCRH - 1); y ++)
{
for (x = 0; x < SCRW; x ++)
{
pixel = fire_buffer [((y + 1) * SCRW) + x];
if (pixel > 0)
{
pixel --;
}
fire_buffer [(y * SCRW) + x] = pixel;
}
}
for (y = 0; y < SCRH; y ++)
{
for (x = 0; x < SCRW; x ++)
{
pixel = vidbuffer [(y * SCRW) + x];
pixel2 = (fire_buffer [(y * SCRW) + x] / 8);
if (pixel2 > pixel)
{
vidbuffer [(y * SCRW) + x] = pixel2;
}
else
{
vidbuffer [(y * SCRW) + x] =
(((pixel + pixel2) / 2) + 1);
}
}
}
}

248
zsnes/src/effects/water.c Normal file
View File

@@ -0,0 +1,248 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Water effects implementation by Pharos, Nach, et al. */
#ifdef __UNIXSDL__
#include "../gblhdr.h"
#else
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <memory.h>
#include <string.h>
#endif
#include "fixsin.h"
extern char *vidbuffer;
#define SCRW 288
#define SCRH 224
static unsigned char vscr[SCRW*SCRH];
static int Height[2][SCRW*SCRH];
extern char NetPlayNoMore;
static void DrawWaterWithLight(int *ptr,int light);
static void SineBlob(int x, int y, int radius, int height, int page);
static void CalcWater(int *nptr,int *optr,int density);
static int ox=80,oy=60;
static int xang,yang;
static int density=5;
static int Hpage=0;
static int mode=0x0001;
static int offset;
static int pheight=400;
static int radius=30;
extern char GUIEffect;
void DrawWater(void)
{
DrawWaterWithLight(Height[Hpage],1);
if (GUIEffect==2) { mode=0x0001; }
else { mode = 0x0004; }
if(mode&2)
{
int x,y;
x=rand()%(SCRW-2)+1;
y=rand()%(SCRH-2)+1;
Height[Hpage][y*SCRW+x]=rand()%(pheight<<2);
}
/* the surfer */
if(mode&1)
{
int x,y;
x = (SCRW/2)
+ ((((FSin( (xang* 65) >>8) >>8)
* (FSin( (xang*349) >>8) >>8))
* ((SCRW-8)/2)) >> 16);
y = (SCRH/2)
+ ((((FSin( (yang*377) >>8) >>8)
*(FSin( (yang* 84) >>8) >>8))
* ((SCRH-8)/2)) >> 16);
xang += 13;
yang += 12;
if(mode & 0x4000)
{
offset = (oy+y)/2*SCRW + (ox+x)/2;
Height[Hpage][offset] = pheight;
Height[Hpage][offset + 1] =
Height[Hpage][offset - 1] =
Height[Hpage][offset + SCRW] =
Height[Hpage][offset - SCRW] = pheight >> 1;
offset = y*SCRW + x;
Height[Hpage][offset] = pheight<<1;
Height[Hpage][offset + 1] =
Height[Hpage][offset - 1] =
Height[Hpage][offset + SCRW] =
Height[Hpage][offset - SCRW] = pheight;
}
else
{
SineBlob((ox+x)/2, (oy+y)/2, 3, -1200, Hpage);
SineBlob(x, y, 4, -2000, Hpage);
}
ox = x;
oy = y;
}
if(mode&4)
{
int x,y;
if(rand()%14 == 7)
{
x=rand()%(SCRW-2)+1;
y=rand()%(SCRH-2)+1;
SineBlob(x, y, radius, -pheight*6, Hpage);
}
}
CalcWater(Height[Hpage^1], Height[Hpage], density);
Hpage ^= 1; /* flip flop */
}
void DrawWaterWithLight(int *ptr,int light)
{
int dx,dy;
int x,y;
int c;
int p;
int offset = SCRW+1;
if(ptr == NULL)
{
return;
}
for(y=((SCRH-1)*SCRW); offset < y; offset+=2)
{
for(x = offset+SCRW-2;offset<x;offset++)
{
dx=ptr[offset]-ptr[offset+1];
dy=ptr[offset]-ptr[offset+SCRW];
p=offset+SCRW*(dy>>3)+(dx>>3);
if (p>(SCRH*SCRW)) p = (p % SCRW) + ((SCRH-((p - (SCRH*SCRW)) / SCRW)) * SCRW);
if (p<0) p = (SCRW + (p % SCRW)) + abs(p / SCRW) * SCRW;
c=vidbuffer[p];
c-=(dx>>light);
(c<1) ? c=1 : (c > 31) ? c=31 : 0;
vscr[offset]=c;
offset++;
dx=ptr[offset]-ptr[offset+1];
dy=ptr[offset]-ptr[offset+SCRW];
p=offset+SCRW*(dy>>3)+(dx>>3);
if (p>(SCRH*SCRW)) p = (p % SCRW) + ((SCRH-((p - (SCRH*SCRW)) / SCRW)) * SCRW);
if (p<0) p = (SCRW + (p % SCRW)) + abs(p / SCRW) * SCRW;
c=vidbuffer[p];
c-=(dx>>light);
(c<1) ? c=1 : (c > 31) ? c=31 : 0;
vscr[offset]=c;
}
}
memcpy( vidbuffer,vscr,SCRW*SCRH);
}
void CalcWater(int *nptr,int *optr,int density)
{
int newh;
int count = SCRW+1;
int x,y;
for(y = (SCRH-1) * SCRW;count<y;count+=2)
{
for(x = count+SCRW-2;count<x;count++)
{
newh = ((optr[count+SCRW]
+optr[count-SCRW]
+optr[count+1]
+optr[count-1]
+optr[count-SCRW-1]
+optr[count-SCRW+1]
+optr[count+SCRW-1]
+optr[count+SCRW+1]
) >> 2)
- nptr[count];
nptr[count] = newh - (newh >> density);
}
}
}
void SineBlob(int x, int y, int radius, int height, int page)
{
int cx, cy;
int left,top,right,bottom;
int square, dist;
int radsquare = radius * radius;
float length = (1024.0f/(float)radius)*(1024.0f/(float)radius);
if(x<0) x = 1+radius+ rand()%(SCRW-2*radius-1);
if(y<0) y = 1+radius+ rand()%(SCRH-2*radius-1);
radsquare = (radius*radius);
height /= 8;
left=-radius; right = radius;
top=-radius; bottom = radius;
// Perform edge clipping...
if(x - radius < 1) left -= (x-radius-1);
if(y - radius < 1) top -= (y-radius-1);
if(x + radius > SCRW-1) right -= (x+radius-SCRW+1);
if(y + radius > SCRH-1) bottom-= (y+radius-SCRH+1);
for(cy = top; cy < bottom; cy++)
{
for(cx = left; cx < right; cx++)
{
square = cy*cy + cx*cx;
if(square < radsquare)
{
dist = (int) sqrt(square*length);
Height[page][SCRW*(cy+y) + cx+x]
+= (int)((FCos(dist)+0xffff)*(height)) >> 19;
}
}
}
}

250
zsnes/src/endmem.asm Normal file
View File

@@ -0,0 +1,250 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%include "macros.mac"
SECTION .bss
NEWSYM wramdataa, resb 65536
NEWSYM ram7fa, resb 65536
NEWSYM Inbetweendat, resd 4
NEWSYM opcjmptab, resd 256
NEWSYM Bank0datr8 , resd 256
NEWSYM Bank0datr16, resd 256
NEWSYM Bank0datw8 , resd 256
NEWSYM Bank0datw16, resd 256
NEWSYM tableA, resd 256
NEWSYM tableB, resd 256
NEWSYM tableC, resd 256
NEWSYM tableD, resd 256
NEWSYM tableE, resd 256
NEWSYM tableF, resd 256
NEWSYM tableG, resd 256
NEWSYM tableH, resd 256
NEWSYM tableAb, resd 256
NEWSYM tableBb, resd 256
NEWSYM tableCb, resd 256
NEWSYM tableDb, resd 256
NEWSYM tableEb, resd 256
NEWSYM tableFb, resd 256
NEWSYM tableGb, resd 256
NEWSYM tableHb, resd 256
NEWSYM tableAc, resd 256
NEWSYM tableBc, resd 256
NEWSYM tableCc, resd 256
NEWSYM tableDc, resd 256
NEWSYM tableEc, resd 256
NEWSYM tableFc, resd 256
NEWSYM tableGc, resd 256
NEWSYM tableHc, resd 256
NEWSYM SA1tableA, resd 256
NEWSYM SA1tableB, resd 256
NEWSYM SA1tableC, resd 256
NEWSYM SA1tableD, resd 256
NEWSYM SA1tableE, resd 256
NEWSYM SA1tableF, resd 256
NEWSYM SA1tableG, resd 256
NEWSYM SA1tableH, resd 256
NEWSYM tablead, resd 256
NEWSYM tableadb, resd 256
NEWSYM tableadc, resd 256
NEWSYM SA1tablead, resd 256
NEWSYM memtabler8, resd 256
NEWSYM memtablew8, resd 256
NEWSYM memtabler16, resd 256
NEWSYM memtablew16, resd 256
NEWSYM vidmemch2, resb 4096
NEWSYM vidmemch4, resb 4096
NEWSYM vidmemch8, resb 4096
NEWSYM snesmmap, resd 256
NEWSYM snesmap2, resd 256
NEWSYM cachebg1, resb 64
NEWSYM cachebg2, resb 64
NEWSYM cachebg3, resb 64
NEWSYM cachebg4, resb 64
NEWSYM sprlefttot, resb 256
NEWSYM sprleftpr, resb 256
NEWSYM sprleftpr1, resb 256
NEWSYM sprleftpr2, resb 256
NEWSYM sprleftpr3, resb 256
NEWSYM sprpriodata, resb 288
NEWSYM sprprtabc, resb 64
NEWSYM sprprtabu, resb 64
NEWSYM prevpal, resw 256 ; previous palette buffer
NEWSYM winbgdata, resb 288 ; window buffer for backgrounds
NEWSYM winspdata, resb 288 ; window buffer for sprites
NEWSYM FxTable, resd 256
NEWSYM FxTableA1, resd 256
NEWSYM FxTableA2, resd 256
NEWSYM FxTableA3, resd 256
NEWSYM FxTableb, resd 256
NEWSYM FxTablebA1, resd 256
NEWSYM FxTablebA2, resd 256
NEWSYM FxTablebA3, resd 256
NEWSYM FxTablec, resd 256
NEWSYM FxTablecA1, resd 256
NEWSYM FxTablecA2, resd 256
NEWSYM FxTablecA3, resd 256
NEWSYM FxTabled, resd 256
NEWSYM FxTabledA1, resd 256
NEWSYM FxTabledA2, resd 256
NEWSYM FxTabledA3, resd 256
NEWSYM SfxMemTable, resd 256
NEWSYM fxxand, resd 256
NEWSYM fxbit01, resd 256
NEWSYM fxbit23, resd 256
NEWSYM fxbit45, resd 256
NEWSYM fxbit67, resd 256
NEWSYM PLOTJmpa, resd 64
NEWSYM PLOTJmpb, resd 64
NEWSYM pal16b, resd 256
NEWSYM pal16bcl, resd 256
NEWSYM pal16bclha, resd 256
NEWSYM pal16bxcl, resd 256
NEWSYM xtravbuf, resb 576
NEWSYM BG1SXl, resw 256
NEWSYM BG2SXl, resw 256
NEWSYM BG3SXl, resw 256
NEWSYM BG4SXl, resw 256
NEWSYM BG1SYl, resw 256
NEWSYM BG2SYl, resw 256
NEWSYM BG3SYl, resw 256
NEWSYM BG4SYl, resw 256
NEWSYM BGMA, resb 256
NEWSYM BGFB, resb 256
NEWSYM BG3PRI, resb 256
NEWSYM BGOPT1, resw 256
NEWSYM BGOPT2, resw 256
NEWSYM BGOPT3, resw 256
NEWSYM BGOPT4, resw 256
NEWSYM BGPT1, resw 256
NEWSYM BGPT2, resw 256
NEWSYM BGPT3, resw 256
NEWSYM BGPT4, resw 256
NEWSYM BGPT1X, resw 256
NEWSYM BGPT2X, resw 256
NEWSYM BGPT3X, resw 256
NEWSYM BGPT4X, resw 256
NEWSYM BGPT1Y, resw 256
NEWSYM BGPT2Y, resw 256
NEWSYM BGPT3Y, resw 256
NEWSYM BGPT4Y, resw 256
NEWSYM BGMS1, resw 1024
NEWSYM prdata, resb 256
NEWSYM prdatb, resb 256
NEWSYM prdatc, resb 256
NEWSYM ngpalcon2b, resd 20h
NEWSYM ngpalcon4b, resd 20h
NEWSYM ngpalcon8b, resd 20h
NEWSYM tltype2b, resb 4096
NEWSYM tltype4b, resb 2048
NEWSYM tltype8b, resb 1024
NEWSYM ngptrdat, resd 1024
NEWSYM ngceax, resd 1024
NEWSYM ngcedi, resd 1024
NEWSYM bgtxad, resw 1024
NEWSYM sprtbng, resd 256
NEWSYM sprtlng, resb 256
NEWSYM mosszng, resb 256
NEWSYM mosenng, resb 256
SECTION .data
ALIGN32
NEWSYM vidmemch2s, times 4096 db 0FFh
NEWSYM vidmemch4s, times 2048 db 0FFh
NEWSYM vidmemch8s, times 1024 db 0FFh
SECTION .bss
NEWSYM mode7ab, resd 256
NEWSYM mode7cd, resd 256
NEWSYM mode7xy, resd 256
NEWSYM mode7st, resb 256
NEWSYM t16x161, resb 256
NEWSYM t16x162, resb 256
NEWSYM t16x163, resb 256
NEWSYM t16x164, resb 256
NEWSYM intrlng, resb 256
NEWSYM mode7hr, resb 256
NEWSYM scadsng, resb 256
NEWSYM scadtng, resb 256
NEWSYM scbcong, resw 256
NEWSYM cpalval, resd 256
NEWSYM cgfxmod, resb 256
NEWSYM winboundary, resd 256
NEWSYM winbg1enval, resb 256
NEWSYM winbg2enval, resb 256
NEWSYM winbg3enval, resb 256
NEWSYM winbg4enval, resb 256
NEWSYM winbgobjenval, resb 256
NEWSYM winbgbackenval, resb 256
NEWSYM winlogicaval, resw 256
NEWSYM winbg1envals, resb 256
NEWSYM winbg2envals, resb 256
NEWSYM winbg3envals, resb 256
NEWSYM winbg4envals, resb 256
NEWSYM winbgobjenvals, resb 256
NEWSYM winbgbackenvals, resb 256
NEWSYM winbg1envalm, resb 256
NEWSYM winbg2envalm, resb 256
NEWSYM winbg3envalm, resb 256
NEWSYM winbg4envalm, resb 256
NEWSYM winbgobjenvalm, resb 256
NEWSYM winbgbackenvalm, resb 256
NEWSYM FillSubScr, resb 256
NEWSYM objclineptr, resd 256 ; l1,r1,l2,r2,en,log,ptr
SECTION .data
ALIGN32
NEWSYM objwlrpos , times 256 dd 0FFFFFFFFh
NEWSYM objwen , times 256 dw 0FFFFh ; en,log
SECTION .bss
NEWSYM SpecialLine, resb 256
NEWSYM bgallchange, resb 256
NEWSYM bg1change, resb 256
NEWSYM bg2change, resb 256
NEWSYM bg3change, resb 256
NEWSYM bg4change, resb 256
NEWSYM bgwinchange, resb 256
NEWSYM PrevPicture, resb 64*56*2

130
zsnes/src/gblhdr.h Normal file
View File

@@ -0,0 +1,130 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GBLHDR_H
#define GBLHDR_H
/*************************************\
* Global Definitions and Headers File *
\*************************************/
// Standard stuff
#include <math.h>
#include <ctype.h>
#include "fcntl.h"
#include <string.h>
#include <errno.h>
#include "config.h"
// General time.h checking
#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
# if HAVE_SYS_TIME_H
#include <sys/time.h>
# else
#include <time.h>
# endif
#endif
// General dirent.h stuff
#if HAVE_DIRENT_H
#include <dirent.h>
#else
# if HAVE_SYS_NDIR_H
#include <sys/ndir.h>
# endif
# if HAVE_SYS_DIR_H
#include <sys/dir.h>
# endif
# if HAVE_NDIR_H
#include <ndir.h>
# endif
#endif
// more standard stuff
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
// unistd.h stuff
//#if HAVE_UNISTD_H
//Small hack for now
#if unix
#include <sys/types.h>
#include <unistd.h>
#endif
// opengl stuff
#ifdef __OPENGL__
#ifndef __MACOSX__
#include <GL/gl.h>
#else
#include <OpenGL/gl.h>
#endif
#endif
// os specific stuff
#ifdef __QNXNTO__
/* QNX6 has getpagesize() commented out in unistd.h,
however it's a static value that we can just define */
#define getpagesize() 4096
#endif
#ifdef __UNIXSDL__
#include "SDL.h"
#include <limits.h>
#ifndef __BEOS__
#include <sys/mman.h>
#include <glob.h>
#include <arpa/inet.h>
#endif
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <utime.h>
#include <zlib.h>
#ifndef NO_PNG
#include <png.h>
#endif
#endif
#ifdef __UNIXSDL__
#ifdef linux
#include <asm/ioctls.h>
#else
#include <sys/filio.h>
#endif
#endif
#endif

45
zsnes/src/gblvars.h Normal file
View File

@@ -0,0 +1,45 @@
/*
Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
https://zsnes.bountysource.com
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//C++ style code in C
#define bool unsigned char
#define true 1
#define false 0
extern unsigned int cycpbl;
extern unsigned int *wramdata, *vram, PHspcsave, PHdspsave, *C4Ram, *sfxramdata;
extern unsigned int PHnum2writesa1reg, SA1Mode, prevedi, SA1xpc, sa1dmaptr;
extern unsigned int soundcycleft, spc700read, timer2upd, xa, PHnum2writesfxreg;
extern unsigned int opcd, HIRQCycNext, oamaddr, curexecstate, nmiprevaddrl;
extern unsigned int nmirept, nmiprevline, nmistatus, joycontren;
extern unsigned int SfxR0, *setaramdata, ramsize, *sram, nmiprevaddrh;
extern unsigned int tempesi, tempedi, tempedx, tempebp;
extern unsigned int SPCMultA, PHnum2writespc7110reg, PHdspsave2;
extern unsigned char sndrot, SPCRAM[65472], DSPMem[256], SA1Status, *SA1RAMArea;
extern unsigned char DSP1Enable, DSP1COp, prevoamptr, BRRBuffer[32], *romdata;
extern unsigned char curcyc, echoon0, spcnumread, NextLineCache, HIRQNextExe;
extern unsigned char vidmemch4[4096], vidmemch8[4096], vidmemch2[4096];
extern bool C4Enable, SFXEnable, SA1Enable, SPC7110Enable, SETAEnable, DSP4Enable, spcon;
extern short C4WFXVal, C41FXVal, Op00Multiplicand, Op04Angle, Op08X, Op18X;
extern short Op28X, Op0CA, Op02FX, Op0AVS, Op06X, Op01m, Op0DX, Op03F, Op14Zr;
extern short Op0EH, Op10Coefficient;

3768
zsnes/src/gui/gui.asm Normal file

File diff suppressed because it is too large Load Diff

1165
zsnes/src/gui/guicheat.inc Normal file

File diff suppressed because it is too large Load Diff

193
zsnes/src/gui/guicombo.inc Normal file
View File

@@ -0,0 +1,193 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
SECTION .text
ComboClip:
movzx eax,byte[GUINumCombo]
.next
cmp al,42
jae .excess
mov byte[GUIComboData+eax],0
inc eax
jmp .next
.excess
ret
ComboAdder:
cmp byte[romloadskip],0
je .romloaded
cmp byte[GUIComboGameSpec],0
jne near .skipall
.romloaded
pushad
call ComboClip
mov eax,[NumCombo]
shl eax,6
add eax,[NumCombo]
add eax,[NumCombo]
add eax,CombinDataGlob
cmp byte[GUIComboGameSpec],0
je .nogamespec
sub eax,CombinDataGlob
add eax,CombinDataLocl
.nogamespec
; copy data to eax
mov ecx,20 ; copy name
mov ebx,GUIComboTextH
.loop
mov dl,[ebx]
mov [eax],dl
inc ebx
inc eax
dec ecx
jnz .loop
mov ecx,42 ; copy combination code
mov ebx,GUIComboData
.loop2
mov dl,[ebx]
mov [eax],dl
inc ebx
inc eax
dec ecx
jnz .loop2
mov dx,[GUIComboKey]
mov [eax],dx
mov dl,[GUIComboPNum]
mov [eax+2],dl
mov dl,[GUIComboLHorz]
mov [eax+3],dl
mov eax,[NumCombo]
mov [GUIccombcursloc],eax
sub eax,7
cmp [GUIccombviewloc],eax
jge .rangeokay
mov [GUIccombviewloc],eax
.rangeokay
inc dword[NumCombo]
mov eax,[NumCombo]
cmp byte[GUIComboGameSpec],0
jne .local
mov [NumComboGlob],eax
jmp .global
.local
mov [NumComboLocl],eax
.global
popad
mov byte[GUIComboTextH],0
mov byte[GUINumCombo],0
mov dword[GUIComboKey],0
.skipall
ret
ComboReplace:
pushad
call ComboClip
mov eax,[GUIccombcursloc]
shl eax,6
add eax,[GUIccombcursloc]
add eax,[GUIccombcursloc]
add eax,CombinDataGlob
cmp byte[GUIComboGameSpec],0
je .nogamespec
sub eax,CombinDataGlob
add eax,CombinDataLocl
.nogamespec
; copy data to eax
mov ecx,20 ; copy name
mov ebx,GUIComboTextH
.loop
mov dl,[ebx]
mov [eax],dl
inc ebx
inc eax
dec ecx
jnz .loop
mov ecx,42 ; copy combination code
mov ebx,GUIComboData
.loop2
mov dl,[ebx]
mov [eax],dl
inc ebx
inc eax
dec ecx
jnz .loop2
mov dx,[GUIComboKey]
mov [eax],dx
mov dl,[GUIComboPNum]
mov [eax+2],dl
mov dl,[GUIComboLHorz]
mov [eax+3],dl
popad
ret
ComboRemoval:
pushad
mov eax,[GUIccombcursloc]
shl eax,6
add eax,[GUIccombcursloc]
add eax,[GUIccombcursloc]
add eax,CombinDataGlob
cmp byte[GUIComboGameSpec],0
je .nogamespec
sub eax,CombinDataGlob
add eax,CombinDataLocl
.nogamespec
mov ecx,[NumCombo]
sub ecx,[GUIccombcursloc]
dec ecx
cmp ecx,0
jle .nomove
.loop2
mov ebx,66
.loop
mov dl,[eax+66]
mov [eax],dl
inc eax
dec ebx
jnz .loop
dec ecx
jnz .loop2
.nomove
dec dword[NumCombo]
mov eax,[NumCombo]
or eax,eax
jz .yeszero
dec eax
.yeszero
cmp [GUIccombviewloc],eax
jbe .notequal
mov [GUIccombviewloc],eax
.notequal
cmp [GUIccombcursloc],eax
jbe .notequal2
mov [GUIccombcursloc],eax
.notequal2
mov eax,[NumCombo]
cmp byte[GUIComboGameSpec],0
jne .local
mov [NumComboGlob],eax
jmp .global
.local
mov [NumComboLocl],eax
.global
popad
ret

1850
zsnes/src/gui/guifuncs.c Normal file

File diff suppressed because it is too large Load Diff

2959
zsnes/src/gui/guikeys.inc Normal file

File diff suppressed because it is too large Load Diff

620
zsnes/src/gui/guimisc.inc Normal file
View File

@@ -0,0 +1,620 @@
;Copyright (C) 1997-2007 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
;
;http://www.zsnes.com
;http://sourceforge.net/projects/zsnes
;https://zsnes.bountysource.com
;
;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;version 2 as published by the Free Software Foundation.
;
;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;GNU General Public License for more details.
;
;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; Movie, Joystick setting (display) routines, SNES Reset Function
SECTION .bss
NEWSYM MovieRecordWinVal, resb 1
NEWSYM MovieProcessing, resb 1
NEWSYM MovieFileHand, resw 1
NEWSYM RecData, resb 16
NEWSYM NoPictureSave, resb 1
SECTION .text
CalibrateDispA:
xor ebx,ebx
mov ecx,256
.a
mov byte[pressed+ebx],0
inc ebx
dec ecx
jnz .a
call GUIUnBuffer
call DisplayBoxes
call DisplayMenu
GUIBox 75,103,192,135,160
GUIBox 75,103,192,103,162
GUIBox 75,103,75,135,161
GUIBox 192,103,192,135,159
GUIBox 75,135,192,135,158
GUIOuttext 81,109,guicalberror1,220-15
GUIOuttext 80,108,guicalberror1,220
GUIOuttext 81,117,guicalberror2,220-15
GUIOuttext 80,116,guicalberror2,220
GUIOuttext 81,125,guicalberror3,220-15
GUIOuttext 80,124,guicalberror3,220
call vidpastecopyscr
call WaitForKey
ret
CalibrateDispB:
xor ebx,ebx
mov ecx,256
.a
mov byte[pressed+ebx],0
inc ebx
dec ecx
jnz .a
call GUIUnBuffer
call DisplayBoxes
call DisplayMenu
GUIBox 75,103,192,143,160
GUIBox 75,103,192,103,162
GUIBox 75,103,75,143,161
GUIBox 192,103,192,143,159
GUIBox 75,143,192,143,158
GUIOuttext 81,109,guicalberror4,220-15
GUIOuttext 80,108,guicalberror4,220
GUIOuttext 81,117,guicalberror5,220-15
GUIOuttext 80,116,guicalberror5,220
GUIOuttext 81,125,guicalberror6,220-15
GUIOuttext 80,124,guicalberror6,220
GUIOuttext 81,133,guicalberror7,220-15
GUIOuttext 80,132,guicalberror7,220
call vidpastecopyscr
call WaitForKey
ret
SECTION .data
guicalberror1 db 'PRESS THE TOP LEFT',0
guicalberror2 db 'CORNER AND PRESS A',0
guicalberror3 db 'BUTTON OR KEY',0
guicalberror4 db 'PRESS THE BOTTOM',0
guicalberror5 db 'RIGHT CORNER AND',0
guicalberror6 db 'PRESS A BUTTON OR',0
guicalberror7 db 'KEY',0
SECTION .text
%macro ConfigureKey2 2
cmp ebx,0
jne near %%no0
mov dword[%2],%1upk ; Up
%%no0
cmp ebx,1
jne near %%no1
mov dword[%2],%1downk ; Down
%%no1
cmp ebx,2
jne near %%no2
mov dword[%2],%1leftk ; Left
%%no2
cmp ebx,3
jne near %%no3
mov dword[%2],%1rightk ; Right
%%no3
cmp ebx,4
jne near %%no4
mov dword[%2],%1startk ; Start
%%no4
cmp ebx,5
jne near %%no5
mov dword[%2],%1selk ; Select
%%no5
cmp ebx,6
jne near %%no6
mov dword[%2],%1Ak ; A
%%no6
cmp ebx,7
jne near %%no7
mov dword[%2],%1Bk ; B
%%no7
cmp ebx,8
jne near %%no8
mov dword[%2],%1Xk ; X
%%no8
cmp ebx,9
jne near %%no9
mov dword[%2],%1Yk ; Y
%%no9
cmp ebx,10
jne near %%no10
mov dword[%2],%1Lk ; L
%%no10
cmp ebx,11
jne near %%no11
mov dword[%2],%1Rk ; R
%%no11
%endmacro
%macro ConfigureKey 2
cmp byte[%2],0
jne near %%nopl1
ConfigureKey2 pl1,%1
%%nopl1
cmp byte[%2],1
jne near %%nopl2
ConfigureKey2 pl2,%1
%%nopl2
cmp byte[%2],2
jne near %%nopl3
ConfigureKey2 pl3,%1
%%nopl3
cmp byte[%2],3
jne near %%nopl4
ConfigureKey2 pl4,%1
%%nopl4
cmp byte[%2],4
jne near %%nopl5
ConfigureKey2 pl5,%1
%%nopl5
%endmacro
SetAllKeys:
xor ebx,ebx
mov ecx,256+128+64
.a
mov byte[pressed+ebx],0
inc ebx
dec ecx
jnz .a
mov byte[GUICBHold],0
mov dword[keycontrolval],pl1contrl
cmp byte[cplayernum],1
jne .nopl2
mov dword[keycontrolval],pl2contrl
.nopl2
cmp byte[cplayernum],2
jne .nopl3
mov dword[keycontrolval],pl3contrl
.nopl3
cmp byte[cplayernum],3
jne .nopl4
mov dword[keycontrolval],pl4contrl
.nopl4
cmp byte[cplayernum],4
jne .nopl5
mov dword[keycontrolval],pl5contrl
.nopl5
;Check if controller is set
push eax
mov eax,[keycontrolval]
cmp dword[eax],0
pop eax
jne .noLockInputChange
ret
.noLockInputChange
xor ebx,ebx
mov ecx,12
mov dword[guipressptr],guipresstext4b
.loop
ConfigureKey guicpressptr,cplayernum
push ebx
push ecx
call guipresstestb
pop ecx
pop ebx
add dword[guipressptr],21
inc ebx
dec ecx
jnz .loop
ret
SECTION .data
SECTION .text
CalibrateDev1:
movzx eax,byte[cplayernum]
mov ebx,[GUIInputRefP+eax*4]
mov bl,[ebx]
mov byte[GUICBHold],0
%ifdef __MSDOS__
cmp al,0
jne .notpl1
cmp byte[pl1p209],0
jne near .port209
.notpl1
cmp al,1
jne .notpl2
cmp byte[pl2p209],0
jne near .port209
.notpl2
cmp al,2
jne .notpl3
cmp byte[pl3p209],0
jne near .port209
.notpl3
cmp al,3
jne .notpl4
cmp byte[pl4p209],0
jne near .port209
.notpl4
cmp al,4
jne .notpl5
cmp byte[pl5p209],0
jne near .port209
.notpl5
%endif
cmp bl,1
jbe .nojoy
cmp bl,18
je near .6button
cmp bl,5
je near .6button
cmp bl,6
jae .nojoy
mov dx,201h
call GetCoords
mov eax,[JoyX]
mov [.joybcx],eax
mov eax,[JoyY]
mov [.joybcy],eax
call CalibrateDispA
mov dx,201h
call GetCoords
mov eax,[JoyX]
mov [.joyblx],eax
mov eax,[JoyY]
mov [.joybly],eax
call CalibrateDispB
mov dx,201h
call GetCoords
jmp .procdir
.nojoy
ret
.6button
mov dx,201h
call GetCoords3
mov eax,[JoyX]
mov [.joybcx],eax
mov eax,[JoyY]
mov [.joybcy],eax
call CalibrateDispA
mov dx,201h
call GetCoords3
mov eax,[JoyX]
mov [.joyblx],eax
mov eax,[JoyY]
mov [.joybly],eax
call CalibrateDispB
mov dx,201h
call GetCoords3
.procdir
mov eax,[.joybcx]
add eax,[.joyblx]
shr eax,1
mov [JoyMinX],eax
mov [CalibXmin],eax
mov eax,[.joybcy]
add eax,[.joybly]
shr eax,1
mov [JoyMinY],eax
mov [CalibYmin],eax
mov eax,[.joybcx]
add eax,[JoyX]
shr eax,1
mov [JoyMaxX],eax
mov [CalibXmax],eax
mov eax,[.joybcy]
add eax,[JoyY]
shr eax,1
mov [JoyMaxY],eax
mov [CalibYmax],eax
ret
%ifdef __MSDOS__
.port209
cmp bl,1
jbe .nojoy209
cmp bl,18
je near .6button209
cmp bl,5
je near .6button209
cmp bl,6
jae .nojoy209
mov dx,209h
call GetCoords
mov eax,[JoyX]
mov [.joybcx],eax
mov eax,[JoyY]
mov [.joybcy],eax
call CalibrateDispA
mov dx,209h
call GetCoords
mov eax,[JoyX]
mov [.joyblx],eax
mov eax,[JoyY]
mov [.joybly],eax
call CalibrateDispB
mov dx,209h
call GetCoords
jmp .procdir209
.nojoy209
ret
.6button209
mov dx,209h
call GetCoords3
mov eax,[JoyX]
mov [.joybcx],eax
mov eax,[JoyY]
mov [.joybcy],eax
call CalibrateDispA
mov dx,209h
call GetCoords3
mov eax,[JoyX]
mov [.joyblx],eax
mov eax,[JoyY]
mov [.joybly],eax
call CalibrateDispB
mov dx,209h
call GetCoords3
.procdir209
mov eax,[.joybcx]
add eax,[.joyblx]
shr eax,1
mov [JoyMinX209],eax
mov [CalibXmin209],eax
mov eax,[.joybcy]
add eax,[.joybly]
shr eax,1
mov [JoyMinY209],eax
mov [CalibYmin209],eax
mov eax,[.joybcx]
add eax,[JoyX]
shr eax,1
mov [JoyMaxX209],eax
mov [CalibXmax209],eax
mov eax,[.joybcy]
add eax,[JoyY]
shr eax,1
mov [JoyMaxY209],eax
mov [CalibYmax209],eax
ret
%endif
SECTION .bss
.joyblx resd 1
.joybly resd 1
.joybcx resd 1
.joybcy resd 1
SECTION .text
SetDevice:
mov byte[GUICBHold],0
movzx eax,byte[cplayernum]
%ifdef __MSDOS__
cmp al,0
jne .notpl1
cmp byte[pl1p209],0
jne .port209
.notpl1
cmp al,1
jne .notpl2
cmp byte[pl2p209],0
jne .port209
.notpl2
cmp al,2
jne .notpl3
cmp byte[pl3p209],0
jne .port209
.notpl3
cmp al,3
jne .notpl4
cmp byte[pl4p209],0
jne .port209
.notpl4
cmp al,4
jne .notpl5
cmp byte[pl5p209],0
jne .port209
.notpl5
%endif
;.notdos
mov dword[CalibXmin],0
mov eax,[GUIInputRefP+eax*4]
mov bl,[GUIcurrentinputcursloc]
mov [eax],bl
mov bh,[cplayernum]
call SetInputDevice
call UpdateDevices
jmp .procmtap
%ifdef __MSDOS__
.port209
mov dword[CalibXmin209],0
mov eax,[GUIInputRefP+eax*4]
mov bl,[GUIcurrentinputcursloc]
mov [eax],bl
mov bh,[cplayernum]
call SetInputDevice209
call UpdateDevices
%endif
.procmtap
mov byte[MultiTap],1
cmp byte[SFXEnable],1
je .dismtap
cmp byte[pl3contrl],0
jne .mtap
cmp byte[pl4contrl],0
jne .mtap
cmp byte[pl5contrl],0
jne .mtap
.dismtap
mov byte[MultiTap],0
.mtap
ret
NEWSYM GUIDoReset
%ifdef __MSDOS__
call DOSClearScreen
%endif
pushad
call Clear2xSaIBuffer
popad
; mov byte[NetPlayNoMore],1
mov byte[RestoreValues],0
pushad
call MovieStop
call RestoreSystemVars
popad
; reset the snes
call init65816
pushad
call procexecloop
popad
xor eax,eax
mov edx,SPCRAM
mov ax,0FFC9h
add edx,eax
mov [spcPCRam],edx
mov dword[spcS],1EFh
mov dword[spcRamDP],SPCRAM
mov byte[spcA],0
mov byte[spcX],0
mov byte[spcY],0
mov byte[spcP],0
mov byte[spcNZ],0
mov byte[Voice0Status],0
mov byte[Voice1Status],0
mov byte[Voice2Status],0
mov byte[Voice3Status],0
mov byte[Voice4Status],0
mov byte[Voice5Status],0
mov byte[Voice6Status],0
mov byte[Voice7Status],0
mov byte[GUIQuit],2
ret
SECTION .bss
NEWSYM JoyX, resd 1
NEWSYM JoyY, resd 1
NEWSYM JoyX2, resd 1
NEWSYM JoyY2, resd 1
NEWSYM JoyMaxX, resd 1
NEWSYM JoyMaxY, resd 1
NEWSYM JoyMinX, resd 1
NEWSYM JoyMinY, resd 1
NEWSYM JoyExists, resb 1
NEWSYM JoyExists2, resb 1
SECTION .text
NEWSYM GetCoords
mov dword[JoyX],0
mov dword[JoyY],0
cli
mov al,0
out dx,al
mov ecx,00FFFFh
.loopa
in al,dx
test al,01h
jz .YAxis
test al,02h
jz .XAxis
inc dword[JoyX]
inc dword[JoyY]
dec ecx
jnz .loopa
mov byte[JoyExists], 0
mov dword[JoyX],0
mov dword[JoyY],0
jmp .End
.YAxis
in al,dx
test al,02h
jz .YAxisOk
nop
nop
inc dword[JoyY]
nop
dec ecx
jnz .YAxis
mov byte[JoyExists], 0
mov dword[JoyX],0
mov dword[JoyY],0
.YAxisOk
jmp .End
.XAxis
in al,dx
test al,01h
jz .XAxisOk
nop
nop
inc dword[JoyX]
nop
dec ecx
jnz .XAxis
mov byte[JoyExists], 0
mov dword[JoyX],0
mov dword[JoyY],0
.XAxisOk
.End
sti
ret
; Dual Joysticks
NEWSYM GetCoords3
mov dword[JoyX],0
mov dword[JoyY],0
mov dword[JoyX2],0
mov dword[JoyY2],0
cli
mov al,0
out dx,al
mov ecx,01FFFFh
.loopa
in al,dx
test al,01h
jz .YAxis
inc dword[JoyX]
nop
.YAxis
test al,02h
jz .XAxis
inc dword[JoyY]
nop
.XAxis
test al,04h
jz .YAxis2
inc dword[JoyX2]
nop
.YAxis2
test al,08h
jz .XAxis2
inc dword[JoyY2]
nop
.XAxis2
test al,0Fh
jz .nomore
dec ecx
jnz .loopa
mov byte[JoyExists], 0
mov dword[JoyX],0
mov dword[JoyY],0
mov byte[JoyExists2], 0
mov dword[JoyX2],0
mov dword[JoyY2],0
.nomore
sti
ret

3593
zsnes/src/gui/guimouse.inc Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More