From 850b3019782dd340bb7aec62019c5282437d3259 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 16 Oct 2008 01:50:21 +0000 Subject: [PATCH] [What Was New 003 - July 25, 2008] - added: alphabetical file sorting - added: background logo/backdrop + nicer menus - added: scrolling in ROM selector - fixed: switching between pal/ntsc ROMS doesn't mess up timings - fixed: GC controller config works now - fixed: freeze autoloading on ROM load - fixed: zipped ROMS should now load in a reasonable time - fixed: precompiled dols for autosaving to various locations (see readme) - changed: GC default quickload slot (to sd) (thanks kerframil) - changed: default load/save dirs are now "/snes9x/roms" and "/snes9x/saves/" (thanks kerframil) - changed: Classic X and Y defaults aren't switched - changed: if autosave is enabled, it doesn't ask to save SRAM anymore. It is saved in the background. - updated README --- COMPILING.txt | 6 + Makefile | 43 +- Makefile.gc | 45 +- Makefile.wii | 47 +- README.txt | 308 +- gu_psasm.S | 694 ++ inject/Makefile | 4 + inject/inject.c | 154 + inject/make-inject | 10 + inject/makefiles/Makefile-inject-linux | 4 + inject/makefiles/Makefile-inject-macosx | 4 + inject/makefiles/Makefile-inject-win32 | 4 + makeall | 25 + makefiles/Makefile-mcslota | 179 + makefiles/Makefile-mcslotb | 179 + makefiles/Makefile-noload | 179 + makefiles/Makefile-sdslota | 179 + makefiles/Makefile-sdslotb | 179 + makefiles/Makefile-smb | 188 + source/ngc/aram.cpp | 24 +- source/ngc/aram.h | 11 +- source/ngc/audio.cpp | 79 +- source/ngc/audio.h | 11 +- source/ngc/button_mapping.c | 327 +- source/ngc/button_mapping.h | 10 - source/ngc/cheatmgr.cpp | 104 - source/ngc/dkpro.h | 877 +++ source/ngc/dvd.cpp | 816 +-- source/ngc/dvd.h | 50 +- source/ngc/fileop.cpp | 305 - source/ngc/fileop.h | 37 - source/ngc/filesel.cpp | 942 +-- source/ngc/filesel.h | 50 +- source/ngc/freeze.cpp | 348 - source/ngc/freeze.h | 34 - source/ngc/ftfont.cpp | 875 +++ source/ngc/{menudraw.h => ftfont.h} | 44 +- .../ngc/{images/saveicon.h => gcglobals.cpp} | 420 +- source/ngc/gctime.cpp | 51 + source/ngc/{cheatmgr.h => gctime.h} | 17 +- source/ngc/{images => }/gfx_bg.h | 7 +- source/ngc/gui.cpp | 568 -- source/ngc/gui.h | 43 - source/ngc/input.cpp | 622 -- source/ngc/input.h | 42 - source/ngc/{memcardop.cpp => mcsave.cpp} | 388 +- source/ngc/{memcardop.h => mcsave.h} | 24 +- source/ngc/memfile.cpp | 489 ++ source/ngc/memfile.h | 34 + source/ngc/menu.cpp | 1254 ++-- source/ngc/menu.h | 15 +- source/ngc/menudraw.cpp | 1066 --- .../unused/logger.h => ngc/ngc-missing.cpp} | 95 +- source/ngc/ngcunzip.cpp | 170 + source/ngc/ngcunzip.h | 35 + source/ngc/preferences.cpp | 501 +- source/ngc/preferences.h | 20 +- source/ngc/s9xconfig.cpp | 329 +- source/ngc/s9xconfig.h | 152 +- source/ngc/s9xsupport.cpp | 205 +- source/ngc/sdload.cpp | 419 ++ source/ngc/sdload.h | 35 + source/ngc/smbload.cpp | 484 ++ source/ngc/smbload.h | 40 + source/ngc/smbop.cpp | 380 -- source/ngc/smbop.h | 34 - source/ngc/snes9xGX.cpp | 832 ++- source/ngc/snes9xGX.h | 255 +- source/ngc/sram.cpp | 425 +- source/ngc/sram.h | 17 +- source/ngc/tempgfx.h | 556 ++ source/ngc/unzip.cpp | 599 +- source/ngc/unzip.h | 19 +- source/ngc/video.cpp | 926 +-- source/ngc/video.h | 30 +- source/smb/DES.c | 726 ++ source/smb/DES.h | 179 + source/smb/LMhash.c | 169 + source/smb/LMhash.h | 115 + source/smb/readme1st.txt | 112 + source/smb/smb.c | 932 +++ source/smb/smb.h | 219 + source/snes9x/3d.h | 36 +- source/snes9x/65c816.h | 35 +- source/snes9x/apu.cpp | 203 +- source/snes9x/apu.h | 44 +- source/snes9x/apudebug.cpp | 175 +- source/snes9x/apumem.h | 261 +- source/snes9x/bsx.cpp | 329 +- source/snes9x/bsx.h | 39 +- source/snes9x/c4.cpp | 71 +- source/snes9x/c4.h | 35 +- source/snes9x/c4emu.cpp | 158 +- source/snes9x/clip.cpp | 35 +- source/snes9x/controls.cpp | 608 +- source/snes9x/controls.h | 57 +- source/snes9x/copyright.h | 37 +- source/snes9x/cpu.cpp | 56 +- source/snes9x/cpuaddr.h | 37 +- source/snes9x/cpuexec.cpp | 222 +- source/snes9x/cpuexec.h | 42 +- source/snes9x/cpumacro.h | 41 +- source/snes9x/cpuops.cpp | 201 +- source/snes9x/cpuops.h | 35 +- source/snes9x/crosshairs.cpp | 37 +- source/snes9x/crosshairs.h | 35 +- source/snes9x/data.cpp | 35 +- source/snes9x/debug.cpp | 72 +- source/snes9x/debug.h | 35 +- source/snes9x/display.h | 41 +- source/snes9x/dma.cpp | 2345 +++---- source/snes9x/dma.h | 37 +- source/snes9x/dsp1.cpp | 242 +- source/snes9x/dsp1.h | 55 +- source/snes9x/dsp1emu.c.inc | 179 - source/snes9x/dsp2emu.c.inc | 39 +- source/snes9x/dsp3emu.c.inc | 49 +- source/snes9x/dsp4emu.c.inc | 35 +- source/snes9x/font.h | 50 +- source/snes9x/fxdbg.cpp | 51 +- source/snes9x/fxemu.cpp | 75 +- source/snes9x/fxemu.h | 35 +- source/snes9x/fxinst.cpp | 59 +- source/snes9x/fxinst.h | 81 +- source/snes9x/getset.h | 130 +- source/snes9x/gfx.cpp | 525 +- source/snes9x/gfx.h | 55 +- source/snes9x/globals.cpp | 61 +- source/snes9x/language.h | 57 +- source/snes9x/memmap.cpp | 6012 ++++++++++------- source/snes9x/memmap.h | 410 +- source/snes9x/messages.h | 36 +- source/snes9x/missing.h | 35 +- source/snes9x/{unused => }/movie.h | 64 +- source/snes9x/obc1.cpp | 71 +- source/snes9x/obc1.h | 37 +- source/snes9x/pixform.h | 37 +- source/snes9x/port.h | 55 +- source/snes9x/ppu.cpp | 301 +- source/snes9x/ppu.h | 82 +- source/snes9x/sa1.cpp | 75 +- source/snes9x/sa1.h | 35 +- source/snes9x/sa1cpu.cpp | 39 +- source/snes9x/sar.h | 35 +- source/snes9x/screenshot.h | 35 +- source/snes9x/sdd1.cpp | 37 +- source/snes9x/sdd1.h | 35 +- source/snes9x/sdd1emu.cpp | 45 +- source/snes9x/sdd1emu.h | 35 +- source/snes9x/seta.cpp | 35 +- source/snes9x/seta.h | 35 +- source/snes9x/seta010.cpp | 119 +- source/snes9x/seta011.cpp | 39 +- source/snes9x/seta018.cpp | 37 +- source/snes9x/snapshot.cpp | 2064 ++---- source/snes9x/snapshot.h | 38 +- source/snes9x/snes9x.cpp | 184 +- source/snes9x/snes9x.h | 99 +- source/snes9x/soundux.cpp | 435 +- source/snes9x/soundux.h | 37 +- source/snes9x/spc700.cpp | 68 +- source/snes9x/spc700.h | 88 +- source/snes9x/spc7110.cpp | 256 +- source/snes9x/spc7110.h | 35 +- source/snes9x/srtc.cpp | 99 +- source/snes9x/srtc.h | 35 +- source/snes9x/tile.cpp | 35 +- source/snes9x/tile.h | 35 +- source/snes9x/unused/2xsai.cpp | 1305 ---- source/snes9x/unused/2xsaiwin.cpp | 821 --- source/snes9x/unused/Makefile.in | 403 -- source/snes9x/unused/Makefile.mingw | 193 - source/snes9x/{ => unused}/cheats.cpp | 133 +- source/snes9x/{ => unused}/cheats.h | 58 +- source/snes9x/{ => unused}/cheats2.cpp | 71 +- source/snes9x/unused/loadzip.cpp | 66 +- source/snes9x/unused/logger.cpp | 338 - source/snes9x/unused/makeasm.bat | 14 - source/snes9x/unused/movie.cpp | 910 +-- source/snes9x/unused/netplay.cpp | 249 +- source/snes9x/unused/netplay.h | 42 +- source/snes9x/unused/offsets.cpp | 481 -- source/snes9x/unused/reader.cpp | 41 +- source/snes9x/unused/reader.h | 37 +- source/snes9x/unused/screenshot.cpp | 60 +- source/snes9x/unused/server.cpp | 246 +- source/snes9x/unused/snaporig.cpp | 45 +- source/snes9x/unused/snaporig.h | 41 +- .../snes9x/unused/snes9x_default_config.cfg | 81 - source/snes9x/unused/sound.cpp | 356 - source/snes9x/unused/xenofarm.sh | 113 - source/snes9x/unused/xenofarm_gdb_cmd | 14 - source/sz/7zAlloc.c | 70 - source/sz/7zAlloc.h | 20 - source/sz/7zBuffer.c | 29 - source/sz/7zBuffer.h | 19 - source/sz/7zCrc.c | 76 - source/sz/7zCrc.h | 24 - source/sz/7zDecode.c | 361 - source/sz/7zDecode.h | 37 - source/sz/7zExtract.c | 254 - source/sz/7zExtract.h | 60 - source/sz/7zHeader.c | 5 - source/sz/7zHeader.h | 55 - source/sz/7zIn.c | 1281 ---- source/sz/7zIn.h | 55 - source/sz/7zItem.c | 133 - source/sz/7zItem.h | 90 - source/sz/7zMethodID.c | 14 - source/sz/7zMethodID.h | 18 - source/sz/7zTypes.h | 71 - source/sz/LzmaDecode.c | 584 -- source/sz/LzmaDecode.h | 113 - source/sz/LzmaTypes.h | 45 - 214 files changed, 21473 insertions(+), 27940 deletions(-) create mode 100644 COMPILING.txt create mode 100644 gu_psasm.S create mode 100644 inject/Makefile create mode 100644 inject/inject.c create mode 100644 inject/make-inject create mode 100644 inject/makefiles/Makefile-inject-linux create mode 100644 inject/makefiles/Makefile-inject-macosx create mode 100644 inject/makefiles/Makefile-inject-win32 create mode 100644 makeall create mode 100644 makefiles/Makefile-mcslota create mode 100644 makefiles/Makefile-mcslotb create mode 100644 makefiles/Makefile-noload create mode 100644 makefiles/Makefile-sdslota create mode 100644 makefiles/Makefile-sdslotb create mode 100644 makefiles/Makefile-smb delete mode 100644 source/ngc/cheatmgr.cpp create mode 100644 source/ngc/dkpro.h delete mode 100644 source/ngc/fileop.cpp delete mode 100644 source/ngc/fileop.h delete mode 100644 source/ngc/freeze.cpp delete mode 100644 source/ngc/freeze.h create mode 100644 source/ngc/ftfont.cpp rename source/ngc/{menudraw.h => ftfont.h} (51%) rename source/ngc/{images/saveicon.h => gcglobals.cpp} (60%) create mode 100644 source/ngc/gctime.cpp rename source/ngc/{cheatmgr.h => gctime.h} (50%) rename source/ngc/{images => }/gfx_bg.h (99%) delete mode 100644 source/ngc/gui.cpp delete mode 100644 source/ngc/gui.h delete mode 100644 source/ngc/input.cpp delete mode 100644 source/ngc/input.h rename source/ngc/{memcardop.cpp => mcsave.cpp} (62%) rename source/ngc/{memcardop.h => mcsave.h} (55%) create mode 100644 source/ngc/memfile.cpp create mode 100644 source/ngc/memfile.h delete mode 100644 source/ngc/menudraw.cpp rename source/{snes9x/unused/logger.h => ngc/ngc-missing.cpp} (80%) create mode 100644 source/ngc/ngcunzip.cpp create mode 100644 source/ngc/ngcunzip.h create mode 100644 source/ngc/sdload.cpp create mode 100644 source/ngc/sdload.h create mode 100644 source/ngc/smbload.cpp create mode 100644 source/ngc/smbload.h delete mode 100644 source/ngc/smbop.cpp delete mode 100644 source/ngc/smbop.h create mode 100644 source/ngc/tempgfx.h create mode 100644 source/smb/DES.c create mode 100644 source/smb/DES.h create mode 100644 source/smb/LMhash.c create mode 100644 source/smb/LMhash.h create mode 100644 source/smb/readme1st.txt create mode 100644 source/smb/smb.c create mode 100644 source/smb/smb.h rename source/snes9x/{unused => }/movie.h (83%) delete mode 100644 source/snes9x/unused/2xsai.cpp delete mode 100644 source/snes9x/unused/2xsaiwin.cpp delete mode 100644 source/snes9x/unused/Makefile.in delete mode 100644 source/snes9x/unused/Makefile.mingw rename source/snes9x/{ => unused}/cheats.cpp (85%) rename source/snes9x/{ => unused}/cheats.h (87%) rename source/snes9x/{ => unused}/cheats2.cpp (87%) delete mode 100644 source/snes9x/unused/logger.cpp delete mode 100644 source/snes9x/unused/makeasm.bat delete mode 100644 source/snes9x/unused/offsets.cpp delete mode 100644 source/snes9x/unused/snes9x_default_config.cfg delete mode 100644 source/snes9x/unused/sound.cpp delete mode 100644 source/snes9x/unused/xenofarm.sh delete mode 100644 source/snes9x/unused/xenofarm_gdb_cmd delete mode 100644 source/sz/7zAlloc.c delete mode 100644 source/sz/7zAlloc.h delete mode 100644 source/sz/7zBuffer.c delete mode 100644 source/sz/7zBuffer.h delete mode 100644 source/sz/7zCrc.c delete mode 100644 source/sz/7zCrc.h delete mode 100644 source/sz/7zDecode.c delete mode 100644 source/sz/7zDecode.h delete mode 100644 source/sz/7zExtract.c delete mode 100644 source/sz/7zExtract.h delete mode 100644 source/sz/7zHeader.c delete mode 100644 source/sz/7zHeader.h delete mode 100644 source/sz/7zIn.c delete mode 100644 source/sz/7zIn.h delete mode 100644 source/sz/7zItem.c delete mode 100644 source/sz/7zItem.h delete mode 100644 source/sz/7zMethodID.c delete mode 100644 source/sz/7zMethodID.h delete mode 100644 source/sz/7zTypes.h delete mode 100644 source/sz/LzmaDecode.c delete mode 100644 source/sz/LzmaDecode.h delete mode 100644 source/sz/LzmaTypes.h diff --git a/COMPILING.txt b/COMPILING.txt new file mode 100644 index 00000000..01149eb4 --- /dev/null +++ b/COMPILING.txt @@ -0,0 +1,6 @@ +In order to compile Snes9xGx 2.0 with actual libogc, you need to: + +1/ download last libogc source (04-02-2007) +2/ replace gu_psasm.S in /LIBBOGC directory located in root libogc source directory by the one included with this release +3/ recompile and reinstall libogc in your devkitPP environment (type 'make' then 'make install') +4/ compile snes9xgx source (type 'make' in snes9xgx folder) \ No newline at end of file diff --git a/Makefile b/Makefile index 65a1cb6a..37da27d9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY = all wii gc wii-clean gc-clean wii-run gc-run +.PHONY = all wii gc wii-clean gc-clean wii-run gc-run mca mcb sd smb mca-clean mcb-clean sd-clean smb-clean specials specials-clean + +VERSION := 003 all: wii gc @@ -21,3 +23,42 @@ gc-clean: gc-run: $(MAKE) -f Makefile.gc run + +# Custom Quicksave Versions + +specials: sd mcb mca smb + +specials-clean: mca-clean mcb-clean smb-clean sd-clean + +mca: + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=0" "LOADTYPE:='"MCSLOTA"'" "VERSION:=$(VERSION)" -f Makefile.wii + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=0" "LOADTYPE:='"MCSLOTA"'" "VERSION:=$(VERSION)" -f Makefile.gc +mca-clean: + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=0" "LOADTYPE:='"MCSLOTA"'" "VERSION:=$(VERSION)" -f Makefile.wii clean + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=0" "LOADTYPE:='"MCSLOTA"'" "VERSION:=$(VERSION)" -f Makefile.gc clean + +mcb: + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=1" "LOADTYPE:='"MCSLOTB"'" "VERSION:=$(VERSION)" -f Makefile.wii + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=1" "LOADTYPE:='"MCSLOTB"'" "VERSION:=$(VERSION)" -f Makefile.gc +mcb-clean: + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=1" "LOADTYPE:='"MCSLOTB"'" "VERSION:=$(VERSION)" -f Makefile.wii clean + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=1" "LOADTYPE:='"MCSLOTB"'" "VERSION:=$(VERSION)" -f Makefile.gc clean + +sd: + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=3" "LOADTYPE:='"SD"'" "VERSION:=$(VERSION)" -f Makefile.wii + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=3" "LOADTYPE:='"SD"'" "VERSION:=$(VERSION)" -f Makefile.gc +sd-clean: + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=3" "LOADTYPE:='"SD"'" "VERSION:=$(VERSION)" -f Makefile.wii clean + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=3" "LOADTYPE:='"SD"'" "VERSION:=$(VERSION)" -f Makefile.gc clean + +smb: + touch source/ngc/snes9xGX.h + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=4" "LOADTYPE:='"SMB"'" "VERSION:=$(VERSION)" -f Makefile.gc +smb-clean: + $(MAKE) "CUSTOMFLAGS:=-DQUICK_SAVE_SLOT=4" "LOADTYPE:='"SMB"'" "VERSION:=$(VERSION)" -f Makefile.gc clean \ No newline at end of file diff --git a/Makefile.gc b/Makefile.gc index acd8e38d..8c83d0dc 100644 --- a/Makefile.gc +++ b/Makefile.gc @@ -1,5 +1,3 @@ -VERSION := 006 - #--------------------------------------------------------------------------------- # Clear the implicit built in rules #--------------------------------------------------------------------------------- @@ -11,32 +9,35 @@ endif include $(DEVKITPPC)/gamecube_rules +LOADTYPE = '"sd"' +VERSION = '"version"' + #--------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed # SOURCES is a list of directories containing source code # INCLUDES is a list of directories containing extra header files #--------------------------------------------------------------------------------- -TARGET := snes9xgx-$(VERSION)-gc -TARGETDIR := executables +TARGET := executables/snes9xgx-$(VERSION)-$(LOADTYPE)-gc BUILD := build_gc -SOURCES := source/snes9x source/ngc source/sz +SOURCES := source/snes9x source/unzip source/ngc source/smb DATA := data -INCLUDES := source/snes9x source/ngc +INCLUDES := source/snes9x source/unzip source/ngc source/smb #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \ - -DNGC \ - -DNO_ASM -DRIGHTSHIFT_IS_SAR \ - -DCPU_SHUTDOWN -DSPC700_SHUTDOWN \ - -DSPC700_C -DSDD1_DECOMP \ - -DCORRECT_VRAM_READS -DNEW_COLOUR_BLENDING \ - -D_SZ_ONE_DIRECTORY -D_LZMA_IN_CB -D_LZMA_OUT_READ \ - -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ - #-D_DEBUG_VIDEO -pipe +CUSTOMFLAGS = -DQUICK_SAVE_SLOT=1 -DSMB_SVID='"Crunchewy"' \ + -DSMB_IP='"192.168.1.111"' -DGW_IP='"192.168.1.1"' + +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DFORCE_WII=0 $(CUSTOMFLAGS) \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter -pipe CXXFLAGS = $(CFLAGS) LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref @@ -44,13 +45,13 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lpngu -lpng -lmxml -lbba -ltinysmb -lfat -lz -logc -lm -lfreetype +LIBS := -lfat -lz -logc -lm -lfreetype -lbba #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := $(CURDIR) +LIBDIRS := #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional @@ -59,7 +60,7 @@ LIBDIRS := $(CURDIR) ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) +export OUTPUT := $(CURDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) @@ -102,15 +103,13 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ -L$(LIBOGC_LIB) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) +export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ - @[ -d $(TARGETDIR) ] || mkdir -p $(TARGETDIR) @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.gc - @rm -fr $(OUTPUT).elf #--------------------------------------------------------------------------------- clean: @@ -119,11 +118,11 @@ clean: #--------------------------------------------------------------------------------- run: - psoload $(OUTPUT).dol + wiiload $(OUTPUT).dol #--------------------------------------------------------------------------------- reload: - psoload -r $(OUTPUT).dol + wiiload -r $(OUTPUT).dol #--------------------------------------------------------------------------------- diff --git a/Makefile.wii b/Makefile.wii index e58a7b85..dd924ee5 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -1,5 +1,3 @@ -VERSION := 006 - #--------------------------------------------------------------------------------- # Clear the implicit built in rules #--------------------------------------------------------------------------------- @@ -11,46 +9,51 @@ endif include $(DEVKITPPC)/wii_rules + +LOADTYPE = '"sd"' +VERSION = '"version"' + #--------------------------------------------------------------------------------- # TARGET is the name of the output # BUILD is the directory where object files & intermediate files will be placed # SOURCES is a list of directories containing source code # INCLUDES is a list of directories containing extra header files #--------------------------------------------------------------------------------- -TARGET := snes9xgx-$(VERSION)-wii -TARGETDIR := executables +TARGET := executables/snes9xgx-$(VERSION)-$(LOADTYPE)-wii BUILD := build_wii -SOURCES := source/snes9x source/ngc source/sz +SOURCES := source/snes9x source/unzip source/ngc source/smb DATA := data -INCLUDES := source/snes9x source/ngc +INCLUDES := source/snes9x source/unzip source/ngc source/smb #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \ - -DNGC -DWII_DVD \ - -DNO_ASM -DRIGHTSHIFT_IS_SAR \ - -DCPU_SHUTDOWN -DSPC700_SHUTDOWN \ - -DSPC700_C -DSDD1_DECOMP \ - -DCORRECT_VRAM_READS -DNEW_COLOUR_BLENDING \ - -D_SZ_ONE_DIRECTORY -D_LZMA_IN_CB -D_LZMA_OUT_READ \ - -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ - #-D_DEBUG_VIDEO -pipe -CXXFLAGS = -save-temps -Xassembler -aln=$@.lst $(CFLAGS) +CUSTOMFLAGS = -DQUICK_SAVE_SLOT=3 -DSMB_SVID='"Crunchewy"' \ + -DSMB_IP='"192.168.1.111"' -DGW_IP='"192.168.1.1"' + +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DHW_RVL -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DFORCE_WII=1 $(CUSTOMFLAGS)\ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter -pipe +CXXFLAGS = $(CFLAGS) -LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -ldi -lpngu -lpng -lmxml -lfat -lwiiuse -lz -lbte -logc -lm -lfreetype -ltinysmb +LIBS := -lfat -lwiiuse -lz -lbte -logc -lm -lfreetype +# -logcsys #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib #--------------------------------------------------------------------------------- -LIBDIRS := $(CURDIR) +LIBDIRS := #--------------------------------------------------------------------------------- # no real need to edit anything past this point unless you need to add additional @@ -59,7 +62,7 @@ LIBDIRS := $(CURDIR) ifneq ($(BUILD),$(notdir $(CURDIR))) #--------------------------------------------------------------------------------- -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) +export OUTPUT := $(CURDIR)/$(TARGET) export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ $(foreach dir,$(DATA),$(CURDIR)/$(dir)) @@ -102,15 +105,13 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ -L$(LIBOGC_LIB) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) +export OUTPUT := $(CURDIR)/$(TARGET) .PHONY: $(BUILD) clean #--------------------------------------------------------------------------------- $(BUILD): @[ -d $@ ] || mkdir -p $@ - @[ -d $(TARGETDIR) ] || mkdir -p $(TARGETDIR) @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.wii - @rm -fr $(OUTPUT).elf #--------------------------------------------------------------------------------- clean: diff --git a/README.txt b/README.txt index c4428596..5016609a 100644 --- a/README.txt +++ b/README.txt @@ -10,100 +10,13 @@ ­———————————————————————————————————————————————————————————————————————•ßrK• ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ -|0O×øo· SNES9X GX 006 ·oø×O0| -| http://code.google.com/p/snes9x-gx | -| (Under GPL License) | +|0O×øo· SNES9XGX v003 ·oø×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' -SNES9x GX is a Super Nintendo emulator for the Wii based on the PC emulator -SNES9x 1.51 (http://snes9x.ipherswipsite.com/). SoftDev is responsible for -the original SNES9x 1.50 GameCube port, whose work was continued by crunchy2. -It was updated for the Wii by michniewski and SNES9x 1.51 was ported by -Tantric. The project is currently being maintained by michniewski and Tantric. +PLEASE NOTE: THIS DOCUMENT IS A WORK IN PROGRESS -×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ -|0O×øo· FEATURES ·oø×O0| -`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' -- Based on Snes9x 1.51 - superior ROM compatibility -- Wiimote, Nunchuk, Classic, and Gamecube controller support -- SNES Superscope, Mouse, Justifier support -- Cheat support -- Auto Load/Save Game Snapshots and SRAM -- Custom controller configurations -- SD, USB, DVD, SMB, GC Memory Card, Zip, and 7z support -- Autodetect PAL/NTSC, 16:9 widescreen support -- Open Source! - -×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ -|0O×øo· UPDATE HISTORY ·oø×O0| -`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' +[What's New 003] -[What's New 006 - October 15, 2008] - -Tantric -- added: 480p for GameCube -- added: Sound sync -- added: 7z support -- changed: Faster SD/USB access (readahead cache enabled) -- fixed: Video offset issues -- fixed: BS-X games work now -- fixed: Wii DVD works now -- fixed: DVD re-enabled for GameCube -- fixed: Nunchuk analog stick issues -- fixed: Many crashes, memory leaks, etc - -michniewski -- added: Video shift options -- changed: Turn DVD motor off option re-enabled for GameCube - -[What Was New 005 - September 23, 2008] - -michniewski -- added: Superscope/mouse/justifier support, with Wii remote -- added: 3 render modes - Original, Filtered, Unfiltered -- added: widescreen compensation option -- added: DVD support on the Wii -- changed: zoom - limited range, added reset zoom option - -Tantric -- added: now uses SNES 1.51 core (thanks to eke-eke for help with this) -- added: cheats menu! Loads .CHT file from /snes9x/cheats folder, - .CHT file name must match file name of ROM -- added: load/save preference selector. ROM, SRAM, Freeze, and preferences - are saved/loaded according to these -- added: preliminary Windows file share loading/saving (SMB) support on Wii: - You can input your network settings into snes9xGX.xml, or edit - s9xconfig.cpp from the source code and compile. -- added: 'Auto' settings for save/load - attempts to automatically determine - your load/save device(s) - SD, USB, Memory Card, DVD, SMB -- added: ROM Information page -- added: Game Menu - all game-specific options are here now: - SRAM save/load, Snapshot save/load, game reload, etc -- added: Credits page -- fixed: sd gecko works now -- fixed: full USB support -- changed: menu structure -- changed: preferences are now loaded and saved in XML format. You can open - snes9xGX.xml edit all settings, including some not available within - the program -- changed: if Home button is pressed when a game is running, Game Menu pops up -- changed: if preferences can't be loaded at the start and/or are reset, - preferences menu pops up - remove to save your preferences! -- changed: SRAM load - game reloaded automatically after loading SRAM - -[What Was New 004 - August 5, 2008] - -- added: option to disable AA filtering - (snes graphics 'crisper', AA now default OFF) -- added: mapped zooming and turbo mode to classic controller -- added: preliminary usb support (loading) -- changed: sram and freezes now saved by filename, not internal romname. - If you have multiple versions of the same game, you can now have - srams and freezes for each version. A prompt to convert to the - new naming is provided for sram only. -- changed: by default, autoload/save sram and freeze enabled - -[What Was New 003 - July 25, 2008] - added: alphabetical file sorting - added: background logo/backdrop + nicer menus - added: scrolling in ROM selector @@ -114,13 +27,13 @@ Tantric - fixed: precompiled dols for autosaving to various locations (see readme) - changed: GC default quickload slot (to sd) (thanks kerframil) - changed: default load/save dirs are now "/snes9x/roms" and - "/snes9x/saves/" (thanks kerframil) + "/snes/save/" (thanks kerframil) - changed: Classic X and Y defaults aren't switched - changed: if autosave is enabled, it doesn't ask to save SRAM anymore. It is saved in the background. - updated README -[Whats Was New 002 - July 21, 2008] +[Whats Was New 002] - added: classic and nunchuk support - added: all controllers can now be configured - added: GC version (untested) @@ -130,7 +43,7 @@ Tantric - one makefile to make all versions. (thanks to snes9x143 SVN) -[What Was New 001 - July 12, 2008] +[What Was New 001] - compiles with latest devkitppc (r15) - now uses libfat (can use front sd slot on wii) - updated menu items a bit @@ -140,89 +53,102 @@ Tantric [older update history at the bottom] + ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ -|0O×øo· SETUP & INSTALLATION ·oø×O0| +|0O×øo· FEATURES ·oø×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' +- Based on Snes9x 1.5 - superior ROM compatibility +- Auto Load/Save Freeze States and SRAM +- Custom controller configurations +- Wiimote, Nunchuk, Classic, and Gamecube controller support +- Autodetect PAL/NTSC +- Zip Support +- Open Source! -Unzip the archive. You will find the following folders inside: +×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ +|0O×øo· SETUP & INSTALLATION ·oø×O0| +`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' -apps Contains Homebrew Channel ready files - (see Homebrew Channel instructions below) - -executables Contains Gamecube / Wii DOL files - (for loading from other methods) - -snes9x Contains the directory structure required for storing - roms, saves, and cheats (see below) +Unzip the archive into a folder. You'll find 4 variations of the dol for both +wii and gamecube versions. The variants auto save and load preferences and sram +to/from different locations as follows (you can also manually save and load +SRAM to any location). +[A default version is provided for quick install. See loading from HBC below.] ----------------------------- -Directory Structure Setup ----------------------------- + filename preferences/sram autoloading location + ------------------------- ------------------------------------- + snes9xGX-003-sd-xxxx.dol SD card + snes9xGX-003-mcslota-xxxx.dol Memory card in slot A + snes9xGX-003-mcslotb-xxxx.dol Memory card in slot B + snes9xGX-003-smb-xxxx.dol SMB share (see SMB section below) + snes9xGX-003-noload-xxxx.dol none - doesn't load prefs nor autosave SRAM -By default, roms are loaded from "snes9x/roms/", saves and preferences are -stored in "snes9x/saves/", and cheats are loaded from "/snes9x/cheats/". -Therefore you should have the following folder structure at the root -of your load device (SD/USB/SMB): +The last part of the filename (shown above as xxxx), denotes the wii and gamecube +versions. - snes9x/ - roms/ - saves/ - cheats/ - ---------------------------- -ROMS, Preferences, Saves, and Cheats: +ROMS, Preferences, and Saves: ---------------------------- Your SNES rom images must be in the Super Magicom (SMC) or FIG format. Generally, all images you find will be in this format, but if you run across one that isn't please download RTOOL which will allow you to convert the image into SMC format. -Cheats must be placed in the cheats folder and named identically to the ROM name, -except with a CHT extension. + Wii ---------- -On the Wii, you can load roms from SD card (Front SD or SD Gecko), USB, DVD, -or SMB share. Note that if you are using the Homebrew Channel, to load from -USB, DVD, or SMB you will first have to load Snes9xGx from SD, and then set -your load method preference. To load roms from a Windows network share (SMB) -you will have to edit snes9xGX.xml on your SD card with your network settings, -or edit s9xconfig.cpp from the source code and compile. If you edit and compile -the source, you can use wiiload and the Homebrew Channel to load and play -Snes9xGx completely over the network, without needing an SD card. +On the Wii, you can load roms from any SD card (Front SD, SD Gecko, etc). +By default, ROMs are loaded from "snes9x/roms/" and saves and preferences are +stored in "snes9x/saves/". Therefore, on your SD card, you should have the following +folders: + + snes9x/ + roms/ + saves/ Gamecube ------------ -You can load roms from DVD or SD card. If you create a bootable -DVD of Snes9xGx you can put roms on the same DVD. You may save preferences and -game data to SD or Memory Card. +You can load roms from DVD, SD card or SMB share. If you wish to use an SD card +or SMB share, you must create the same folder tree as above. Put your roms in the +"snes9x/roms" folder. On DVD you can either place your roms at the top level, or +optionally you may have an SNESROMS folder at the top level of the DVD, in which +case the game selectorwill default to showing that folder when first entered. +If you create a bootable DVD of Snes9xGx you can put roms on the same DVD. ------------------------------ Loading / Running the Emulator: ------------------------------ -Wii - Via Homebrew Channel: +Via Homebrew Channel: -------------------- -The most popular method of running homebrew on the Wii is through the Homebrew +The most popular method of running homebrew on the wii is through the Homebrew Channel. If you already have the channel installed, just copy over the apps folder -included in the archive into the root of your SD card. +included in the archive into the root of your SD card (the SD autosaving version +for wii is included in the apps/Snes9xGX/ folder renamed to boot.dol). + +Remember to also create the snes9x/roms and snes9x/saves directories. See above. + +If you wish to use a version that autosaves to other available saving locations, +just choose the appropriate dol, copy it into the apps/Snes9XGX/ folder, and +RENAME it to boot.dol (remove the other version). Then proceed to copy +the entire apps folder to your sd card and run it with the HBC. -Remember to also create the snes9x directory structure required. See above. +If you haven't installed the homebrew channel yet, read about how to here: + http://hbc.hackmii.com/ -If you haven't installed the Homebrew Channel yet, read about how to here: -http://hbc.hackmii.com/ Gamecube: --------- -You can load Snes9xGX via sdload and an SD card in slot A, or by streaming -it to your Gamecube, or by booting a bootable DVD with Snes9xGX on it. -This document doesn't cover how to do any of that. A good source for information -on these topics is the tehskeen forums: http://www.tehskeen.com/forums/ +You can load it via sdload and an SD card in slot A, or by streaming it to your +cube, or by booting a bootable DVD (gamecube only) with it on it. This document doesn't cover +how to do any of that. A good source for information on these topics is the +tehskeen forums: + http://www.tehskeen.com/forums/ ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· ABOUT SNES9X ·oø×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' - -Welcome to the revolution in Wii/GameCube emulators! SNES9X is by far the most +Welcome to the revolution in GameCube emulators! SNES9X is by far the most complete and accurate Super Nintendo Entertainment System emulator to date. Taking full power of the ATi-GX chipset and packed full of features that are to die for after playing your games you'll never want to come back to @@ -230,9 +156,10 @@ reality. SNES9X is a very popular open source emulator mainly for the PC platform, but has seen many ports to other consoles such as the Nintendo DS, Microsoft XBOX -, -and, thanks to SoftDev, the Nintendo GameCube. SoftDev's 1.50 port is not based -on any previous SNES emulators that have existed for the GameCube. +and now thanks to SoftDev the Nintendo GameCube! This is a straight port and +is not based on any previous SNES emulators that have existed for the +GameCube. You can get more information on SNES9X here from the below URL. +http://snes9x.ipherswipsite.com/ ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· DEFAULT CONTROLLER MAPPING ·oø×O0| @@ -244,51 +171,34 @@ under the Config Controllers option. Below are the default button mappings for supported controllers. The wiimote configuration allows you to play with the wiimote held sideways. -Wiimote SNES Nunchuk SNES +Wiimote SNES Nunchuk SNES --------------------- --------------------- - 1 Y Z Y - 2 B B B - A A A A - B X C X - - SELECT 2 SELECT - + START 1 START -HOME Emulator menu HOME Emulator menu - LT - LT - RT + RT + 1 Y Z Y + 2 B B B + A A A A + B X C X + - SELECT 2 SELECT + + START 1 START +HOME Emulator menu HOME Emulator menu + LT - LT + RT + RT -Classic SNES GC PAD SNES +Classic SNES GC PAD SNES --------------------- --------------------- - X X Y Y - B B B B - A A A A - Y Y X X - - SELECT Z SELECT - + START START START + X X Y Y + B B B B + A A A A + Y Y X X + - SELECT Z SELECT + + START START START HOME Emulator menu - LT LT LT LT - RT RT RT RT - -×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ -|0O×øo· SUPERSCOPE / MOUSE / JUSTIFIER SUPPORT ·oø×O0| -`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' - -Make sure you enable the superscope, mouse, or justifier in the controller -options menu BEFORE loading the rom. If you have already loaded the rom -and changed the setting, reset the game for the settings to take effect. - -These controllers can be controlled by either the Gamecube controller analog -sticks,the Classic controller analog sticks, or by aiming at the screen -with the wiimote. + LT LT LT LT + RT RT RT RT -Aim Offscreen - Wiimote Minus, GameCube Z button -Fire - B button -Cursor - A button -Turbo Toggle - Wiimote D-Pad Down, GameCube Y button -These configurations cannot be changed. ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· ZIP SUPPORT ·oø×O0| @@ -316,15 +226,16 @@ To use 7-Zip compression on either linux or windows, use the following command: `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' Once the DOL file is loaded you will be presented with main menu where you can -load a ROM, set options for the emulator, set the joypad configuration, etc. +load a ROM, set options for the emulator, set the joypad configuration, save or +load freezes, manage SRAM, etc. After loading a game the game will start running immediately. If you have the auto-load SRAM option enabled it will automatically load SRAM (if it exists) before starting play. -You can return to the menu at any time by pressing the Home button -(Wiimote and Classic Controller) or on the c-stick (the yellow control stick) -to the left, or by pressing L+R+X+Y (GameCube Controller). -Return to the game by selecting "Resume Game". +You can return to the main menu at any time by pressing +the c-stick (the yellow control stick) to the left, or by pressing L+R+X+Y. +Return to the game by selecting "Resume Game" or by pressing the B button until +play resumes. ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· TURBO MODE ·oø×O0| @@ -339,16 +250,23 @@ want normal playback speed to resume. |0O×øo· IMPORTING AND EXPORTING SRAM ·oø×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' -Snes9xGx now includes the ability to load SRAM from Snes9x on other -platforms (Mac/PC/Linux/Etc) and to save back to those platforms. +Snes9xGx 2.0.1 now includes the ability to load SRAM from Snes9x on other +platforms (Mac/PC/Linux/Etc) and to save back to those platforms. To use this +feature simply save or load SRAM to/from SD card or an SMB share. -To load a SRAM file on the Wii or Gamecube from another platform, ensure the -name of the SRM file matches the filename of the ROM (except with an SRM -extension). +The only thing to be aware of is that Snes9xGx requires that the SRM file have a +name that is the rom name (not necessarily the same as the file name!) with .SRM +at the end. For example, the game "Super Mario All-Stars + World" has a rom name +of "ALL_STARS + WORLD", so the SRAM file should have the name "ALL_STARS + +WORLD.srm". You can see the rom name for a game by loading the game - the rom +name is shown in the information that is briefly shown at the bottom of the +screen. A perhaps easier way to find the correct name is simply to load the game +and then save SRAM to SD or SMB and look at the filename that Snes9xGx uses. +That's the name you should use when importing an SRAM from another platform. -To use a Wii/GameCube SRAM file on another platform just do the opposite: -copy the saved SRAM file to the other platform. You may have to rename the -file to be what that version of snes9x expects it to be. +To use an Snes9xGx SRAM on another platform just do the opposite: save SRAM to +SD or SMB, and then copy that saved SRAM file to the other platform. You may +have to rename the file to be what that version of snes9x expects it to be. ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· UPDATE HISTORY (old) ·oø×O0| @@ -482,7 +400,7 @@ changes to the emulator settings again and save them. GameCube Port 2.0 WIP6 and earlier - SoftDev Additional improvements to 2.0 WIP6 - eke-eke GameCube 2.0.1bx enhancements - crunchy2 - v00x updates - michniewski & Tantric + v00x updates - michniewski GX - http://www.gc-linux.org libogc - Shagkur & wintermute @@ -492,7 +410,7 @@ changes to the emulator settings again and save them. Documentation - brakken, crunchy2, michniewski, Tantric + brakken, crunchy2, michniewski ×—–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•¬ |0O×øo· ·oø×O0| diff --git a/gu_psasm.S b/gu_psasm.S new file mode 100644 index 00000000..b030e74b --- /dev/null +++ b/gu_psasm.S @@ -0,0 +1,694 @@ +#include + +#define A00_A01 fr0 +#define A02_A03 fr1 +#define A10_A11 fr2 +#define A12_A13 fr3 +#define A20_A21 fr4 +#define A22_A23 fr5 + +#define B00_B01 fr6 +#define B02_B03 fr7 +#define B10_B11 fr8 +#define B12_B13 fr9 +#define B20_B21 fr10 +#define B22_B23 fr11 + +#define D00_D01 fr12 +#define D02_D03 fr13 +#define D10_D11 fr14 +#define D12_D13 fr15 +#define D20_D21 fr2 +#define D22_D23 fr0 + +#define UNIT01 fr31 + +#define RET_REG fr1 +#define V1_XY fr2 +#define V1_Z fr3 +#define V2_XY fr4 +#define V2_Z fr5 +#define D1_XY fr6 +#define D1_Z fr7 +#define D2_XY fr8 +#define D2_Z fr9 +#define W1_XY fr10 +#define W1_Z fr11 +#define W2_XY fr12 +#define W2_Z fr13 + + .globl ps_guMtxConcat + //r3 = mtxA, r4 = mtxB, r5 = mtxAB +ps_guMtxConcat: + stwu r1,-64(r1) + psq_l A00_A01,0(r3),0,0 + stfd fr14,8(r1) + psq_l B00_B01,0(r4),0,0 + lis r6,Unit01@ha + psq_l B02_B03,8(r4),0,0 + stfd fr15,16(r1) + addi 6,6,Unit01@l + stfd fr31,40(r1) + psq_l B10_B11,16(r4),0,0 + ps_muls0 D00_D01,B00_B01,A00_A01 + psq_l A10_A11,16(r3),0,0 + ps_muls0 D02_D03,B02_B03,A00_A01 + psq_l UNIT01,0(r6),0,0 + ps_muls0 D10_D11,B00_B01,A10_A11 + psq_l B12_B13,24(r4),0,0 + ps_muls0 D12_D13,B02_B03,A10_A11 + psq_l A02_A03,8(r3),0,0 + ps_madds1 D00_D01,B10_B11,A00_A01,D00_D01 + psq_l A12_A13,24(r3),0,0 + ps_madds1 D10_D11,B10_B11,A10_A11,D10_D11 + psq_l B20_B21,32(r4),0,0 + ps_madds1 D02_D03,B12_B13,A00_A01,D02_D03 + psq_l B22_B23,40(r4),0,0 + ps_madds1 D12_D13,B12_B13,A10_A11,D12_D13 + psq_l A20_A21,32(r3),0,0 + psq_l A22_A23,40(r3),0,0 + ps_madds0 D00_D01,B20_B21,A02_A03,D00_D01 + ps_madds0 D02_D03,B22_B23,A02_A03,D02_D03 + ps_madds0 D10_D11,B20_B21,A12_A13,D10_D11 + ps_madds0 D12_D13,B22_B23,A12_A13,D12_D13 + psq_st D00_D01,0(r5),0,0 + ps_muls0 D20_D21,B00_B01,A20_A21 + ps_madds1 D02_D03,UNIT01,A02_A03,D02_D03 + ps_muls0 D22_D23,B02_B03,A20_A21 + psq_st D10_D11,16(r5),0,0 + ps_madds1 D12_D13,UNIT01,A12_A13,D12_D13 + psq_st D02_D03,8(r5),0,0 + ps_madds1 D20_D21,B10_B11,A20_A21,D20_D21 + ps_madds1 D22_D23,B12_B13,A20_A21,D22_D23 + ps_madds0 D20_D21,B20_B21,A22_A23,D20_D21 + lfd fr14,8(r1) + psq_st D12_D13,24(r5),0,0 + ps_madds0 D22_D23,B22_B23,A22_A23,D22_D23 + psq_st D20_D21,32(r5),0,0 + ps_madds1 D22_D23,UNIT01,A22_A23,D22_D23 + lfd fr15,16(r1) + psq_st D22_D23,40(r5),0,0 + lfd fr31,40(r1) + addi r1,r1,64 + blr + + .globl ps_guMtxIdentity + //r3 == mtx +ps_guMtxIdentity: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr0,0(r9) + lfs fr1,4(r9) + psq_st fr0,8(r3),0,0 + ps_merge01 fr2,fr0,fr1 + psq_st fr0,24(r3),0,0 + ps_merge10 fr3,fr1,fr0 + psq_st fr0,32(r3),0,0 + psq_st fr2,16(r3),0,0 + psq_st fr3,0(r3),0,0 + psq_st fr3,40(r3),0,0 + blr + + .globl ps_guMtxCopy + //r3 = src, r4 = dst +ps_guMtxCopy: + psq_l fr0,0(r3),0,0 + psq_st fr0,0(r4),0,0 + psq_l fr1,8(r3),0,0 + psq_st fr1,8(r4),0,0 + psq_l fr2,16(r3),0,0 + psq_st fr2,16(r4),0,0 + psq_l fr3,24(r3),0,0 + psq_st fr3,24(r4),0,0 + psq_l fr4,32(r3),0,0 + psq_st fr4,32(r4),0,0 + psq_l fr5,40(r3),0,0 + psq_st fr5,40(r4),0,0 + blr + + .globl ps_guMtxTranspose + //r3 = src, r4 = xpose +ps_guMtxTranspose: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr0,0(r9) + psq_l fr1,0(r3),0,0 + stfs fr0,44(r4) + psq_l fr2,16(r3),0,0 + ps_merge00 fr5,fr1,fr2 + psq_l fr3,8(r3),1,0 + ps_merge11 fr6,fr1,fr2 + psq_l fr4,24(r3),1,0 + psq_st fr5,0(r4),0,0 + psq_l fr1,32(r3),0,0 + ps_merge00 fr7,fr3,fr4 + psq_st fr6,16(r4),0,0 + ps_merge00 fr5,fr1,fr0 + psq_st fr7,32(r4),0,0 + ps_merge10 fr6,fr1,fr0 + psq_st fr5,8(r4),0,0 + lfs fr3,40(r3) + psq_st fr6,24(r4),0,0 + stfs fr3,40(r4) + blr + + .globl ps_guMtxInverse + //r3 = src, r4 = inv +ps_guMtxInverse: + psq_l fr0,0(r3),1,0 + psq_l fr1,4(r3),0,0 + psq_l fr2,16(r3),1,0 + ps_merge10 fr6,fr1,fr0 + psq_l fr3,20(r3),0,0 + psq_l fr4,32(r3),1,0 + ps_merge10 fr7,fr3,fr2 + psq_l fr5,36(r3),0,0 + ps_mul fr11,fr3,fr6 + ps_mul fr13,fr5,fr7 + ps_merge10 fr8,fr5,fr4 + ps_msub fr11,fr1,fr7,fr11 + ps_mul fr12,fr1,fr8 + ps_msub fr13,fr3,fr8,fr13 + ps_mul fr10,fr3,fr4 + ps_msub fr12,fr5,fr6,fr12 + ps_mul fr9,fr0,fr5 + ps_mul fr8,fr1,fr2 + ps_sub fr6,fr6,fr6 + ps_msub fr10,fr2,fr5,fr10 + ps_mul fr7,fr0,fr13 + ps_msub fr9,fr1,fr4,fr9 + ps_madd fr7,fr2,fr12,fr7 + ps_msub fr8,fr0,fr3,fr8 + ps_madd fr7,fr4,fr11,fr7 + ps_cmpo0 cr0,fr7,fr6 + bne 0f + li r3,0 + blr + +0: fres fr0,fr7 + ps_add fr6,fr0,fr0 + ps_mul fr5,fr0,fr0 + ps_nmsub fr0,fr7,fr5,fr6 + lfs fr1,12(r3) + ps_muls0 fr13,fr13,fr0 + lfs fr2,28(r3) + ps_muls0 fr12,fr12,fr0 + lfs fr3,44(r3) + ps_muls0 fr11,fr11,fr0 + ps_merge00 fr5,fr13,fr12 + ps_muls0 fr10,fr10,fr0 + ps_merge11 fr4,fr13,fr12 + ps_muls0 fr9,fr9,fr0 + psq_st fr5,0(r4),0,0 + ps_mul fr6,fr13,fr1 + psq_st fr4,16(r4),0,0 + ps_muls0 fr8,fr8,fr0 + ps_madd fr6,fr12,fr2,fr6 + psq_st fr10,32(r4),1,0 + ps_nmadd fr6,fr11,fr3,fr6 + psq_st fr9,36(r4),1,0 + ps_mul fr7,fr10,fr1 + ps_merge00 fr5,fr11,fr6 + psq_st fr8,40(r4),1,0 + ps_merge11 fr4,fr11,fr6 + psq_st fr5,8(r4),0,0 + ps_madd fr7,fr9,fr2,fr7 + psq_st fr4,24(r4),0,0 + ps_nmadd fr7,fr8,fr3,fr7 + li r3,1 + psq_st fr7,44(r4),1,0 + blr + + .globl ps_guMtxInvXpos + //r3 = src, r4 = invx +ps_guMtxInvXpos: + psq_l fr0, 0(r3), 1, 0 + psq_l fr1, 4(r3), 0, 0 + psq_l fr2, 16(r3), 1, 0 + ps_merge10 fr6, fr1, fr0 + psq_l fr3, 20(r3), 0, 0 + psq_l fr4, 32(r3), 1, 0 + ps_merge10 fr7, fr3, fr2 + psq_l fr5, 36(r3), 0, 0 + ps_mul fr11, fr3, fr6 + ps_merge10 fr8, fr5, fr4 + ps_mul fr13, fr5, fr7 + ps_msub fr11, fr1, fr7, fr11 + ps_mul fr12, fr1, fr8 + ps_msub fr13, fr3, fr8, fr13 + ps_msub fr12, fr5, fr6, fr12 + ps_mul fr10, fr3, fr4 + ps_mul fr9, fr0, fr5 + ps_mul fr8, fr1, fr2 + ps_msub fr10, fr2, fr5, fr10 + ps_msub fr9, fr1, fr4, fr9 + ps_msub fr8, fr0, fr3, fr8 + ps_mul fr7, fr0, fr13 + ps_sub fr1, fr1, fr1 + ps_madd fr7, fr2, fr12, fr7 + ps_madd fr7, fr4, fr11, fr7 + ps_cmpo0 cr0, fr7, fr1 + bne 0f + addi r3, 0, 0 + blr + +0: fres fr0, fr7 + psq_st fr1, 12(r4), 1, 0 + ps_add fr6, fr0, fr0 + ps_mul fr5, fr0, fr0 + psq_st fr1, 28(r4), 1, 0 + ps_nmsub fr0, fr7, fr5, fr6 + psq_st fr1, 44(r4), 1, 0 + ps_muls0 fr13, fr13, fr0 + ps_muls0 fr12, fr12, fr0 + ps_muls0 fr11, fr11, fr0 + psq_st fr13, 0(r4), 0, 0 + psq_st fr12, 16(r4), 0, 0 + ps_muls0 fr10, fr10, fr0 + ps_muls0 fr9, fr9, fr0 + psq_st fr11, 32(r4), 0, 0 + psq_st fr10, 8(r4), 1, 0 + ps_muls0 fr8, fr8, fr0 + addi r3, 0, 1 + psq_st fr9, 24(r4), 1, 0 + psq_st fr8, 40(r4), 1, 0 + blr + + .globl ps_guMtxScale + //r3 = mtx,fr1 = xS,fr2 = yS,fr3 = zS +ps_guMtxScale: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr0,0(r9) + stfs fr1,0(r3) + psq_st fr0,4(r3),0,0 + psq_st fr0,12(r3),0,0 + stfs fr2,20(r3) + psq_st fr0,24(r3),0,0 + psq_st fr0,32(r3),0,0 + stfs fr3,40(r3) + stfs fr0,44(r3) + blr + + .globl ps_guMtxScaleApply + //r3 = src,r4 = dst,fr1 = xS,fr2 = yS,fr3 = zS +ps_guMtxScaleApply: + psq_l fr4,0(r3),0,0 + psq_l fr5,8(r3),0,0 + ps_muls0 fr4,fr4,fr1 + psq_l fr6,16(r3),0,0 + ps_muls0 fr5,fr5,fr1 + psq_l fr7,24(r3),0,0 + ps_muls0 fr6,fr6,fr2 + psq_l fr8,32(r3),0,0 + psq_st fr4,0(r4),0,0 + ps_muls0 fr7,fr7,fr2 + psq_l fr2,40(r3),0,0 + psq_st fr5,8(r4),0,0 + ps_muls0 fr8,fr8,fr3 + psq_st fr6,16(r4),0,0 + ps_muls0 fr2,fr2,fr3 + psq_st fr7,24(r4),0,0 + psq_st fr8,32(r4),0,0 + psq_st fr2,40(r4),0,0 + blr + + .globl ps_guMtxTrans + //r3 = mtx,fr1 = xT,fr2 = yT,fr3 = zT +ps_guMtxTrans: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr4,0(r9) + lfs fr5,4(r9) + stfs fr1,12(r3) + stfs fr2,28(r3) + psq_st fr4,4(r3),0,0 + psq_st fr4,32(r3),0,0 + stfs fr5,20(r3) + stfs fr4,24(r3) + stfs fr5,40(r3) + stfs fr3,44(r3) + stfs fr5,0(r3) + blr + + .globl ps_guMtxTransApply + //r3 = src,r4 = dst,fr1 = xT,fr2 = yT,fr3 = zT +ps_guMtxTransApply: + psq_l fr4,0(r3),0,0 + psq_l fr5,8(r3),0,0 + psq_l fr7,24(r3),0,0 + psq_l fr8,40(r3),0,0 + ps_sum1 fr5,fr1,fr5,fr5 + psq_l fr6,16(r3),0,0 + ps_sum1 fr7,fr2,fr7,fr7 + psq_l fr9,32(r3),0,0 + ps_sum1 fr8,fr3,fr8,fr8 + psq_st fr4,0(r4),0,0 + psq_st fr5,8(r4),0,0 + psq_st fr6,16(r4),0,0 + psq_st fr7,24(r4),0,0 + psq_st fr9,32(r4),0,0 + psq_st fr8,40(r4),0,0 + blr + + .globl ps_guMtxRotTrig + //r3 = mt,r4 = axis,fr1 = sinA,fr2 = cosA +ps_guMtxRotTrig: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr3,0(r9) + lfs fr4,4(r9) + ori r4,r4,0x20 + ps_neg fr5,fr1 + cmplwi r4,'x' + beq 0f + cmplwi r4,'y' + beq 1f + cmplwi r4,'z' + beq 2f + b 3f +0: + psq_st fr4,0(r3),1,0 + psq_st fr3,4(r3),0,0 + ps_merge00 fr6,fr1,fr2 + psq_st fr3,12(r3),0,0 + ps_merge00 fr7,fr2,fr5 + psq_st fr3,28(r3),0,0 + psq_st fr3,44(r3),1,0 + psq_st fr6,36(r3),0,0 + psq_st fr7,20(r3),0,0 + b 3f +1: + ps_merge00 fr6,fr2,fr3 + ps_merge00 fr7,fr3,fr4 + psq_st fr3,24(r3),0,0 + psq_st fr6,0(r3),0,0 + ps_merge00 fr8,fr5,fr3 + ps_merge00 fr9,fr1,fr3 + psq_st fr6,40(r3),0,0 + psq_st fr7,16(r3),0,0 + psq_st fr9,8(r3),0,0 + psq_st fr8,32(r3),0,0 + b 3f +2: + psq_st fr3,8(r3),0,0 + ps_merge00 fr6,fr1,fr2 + ps_merge00 fr8,fr2,fr5 + psq_st fr3,24(r3),0,0 + psq_st fr3,32(r3),0,0 + ps_merge00 fr7,fr4,fr3 + psq_st fr6,16(r3),0,0 + psq_st fr8,0(r3),0,0 + psq_st fr7,40(r3),0,0 +3: + blr + + .globl ps_guMtxReflect + //r3 = mtx,r4 = vec1,r5 = vec2 +ps_guMtxReflect: + lis r9,Unit01@ha + addi r9,r9,Unit01@l + lfs fr0,4(r9) + psq_l fr1,8(r5),1,0 + psq_l fr2,0(r5),0,0 + psq_l fr3,0(r4),0,0 + ps_nmadd fr5,fr1,fr0,fr1 + psq_l fr4,8(r4),1,0 + ps_nmadd fr6,fr2,fr0,fr2 + ps_muls0 fr7,fr2,fr5 + ps_mul fr8,fr6,fr3 + ps_muls0 fr9,fr2,fr6 + ps_sum0 fr8,fr8,fr8,fr8 + ps_muls1 fr10,fr2,fr6 + psq_st fr7,32(r3),0,0 + ps_sum0 fr2,fr2,fr2,fr0 + ps_nmadd fr8,fr5,fr4,fr8 + ps_sum1 fr10,fr0,fr10,fr10 + psq_st fr9,0(r3),0,0 + ps_muls0 fr11,fr2,fr8 + ps_merge00 fr12,fr5,fr8 + psq_st fr10,16(r3),0,0 + ps_merge00 fr13,fr7,fr11 + ps_muls0 fr12,fr12,fr1 + ps_merge11 fr11,fr7,fr11 + psq_st fr13,8(r3),0,0 + ps_sum0 fr12,fr12,fr12,fr0 + psq_st fr11,24(r3),0,0 + psq_st fr12,40(r3),0,0 + blr + + .globl ps_guVecAdd + //r3 = v1,r4 = v2,r5 = dst +ps_guVecAdd: + psq_l V1_XY,0(r3),0,0 + psq_l V2_XY,0(r4),0,0 + ps_add D1_XY,V1_XY,V2_XY + psq_st D1_XY,0(r5),0,0 + psq_l V1_Z,8(r3),1,0 + psq_l V2_Z,8(r4),1,0 + ps_add D1_Z,V1_Z,V2_Z + psq_st D1_Z,8(r5),1,0 + blr + + .globl ps_guVecSub + //r3 = v1,r4 = v2,r5 = dst +ps_guVecSub: + psq_l V1_XY,0(r3),0,0 + psq_l V2_XY,0(r4),0,0 + ps_sub D1_XY,V1_XY,V2_XY + psq_st D1_XY,0(r5),0,0 + psq_l V1_Z,8(r3),1,0 + psq_l V2_Z,8(r4),1,0 + ps_sub D1_Z,V1_Z,V2_Z + psq_st D1_Z,8(r5),1,0 + blr + + .globl ps_guVecScale + //r3 = src,r4 = dst,fr1 = S +ps_guVecScale: + psq_l fr2,0(r3),0,0 + psq_l fr3,8(r3),1,0 + ps_muls0 fr4,fr2,fr1 + psq_st fr4,0(r4),0,0 + ps_muls0 fr4,fr3,fr1 + psq_st fr4,8(r4),1,0 + blr + + .globl ps_guVecNormalize + //r3 = v +ps_guVecNormalize: + lis r9,NrmData@ha + addi r9,r9,NrmData@l + lfs fr0,0(r9) + lfs fr1,4(r9) + psq_l fr2,0(r3),0,0 + ps_mul fr4,fr2,fr2 + psq_l fr3,8(r3),1,0 + ps_madd fr5,fr3,fr3,fr4 + ps_sum0 fr6,fr5,fr3,fr4 + frsqrte fr7,fr6 + fmuls fr8,fr7,fr7 + fmuls fr9,fr7,fr0 + fnmsubs fr8,fr8,fr6,fr1 + fmuls fr7,fr8,fr9 + ps_muls0 fr2,fr2,fr7 + psq_st fr2,0(r3),0,0 + ps_muls0 fr3,fr3,fr7 + psq_st fr3,8(r3),1,0 + blr + + .globl ps_guVecCross + //r3 = v1,r4 = v2,r5 = v12 +ps_guVecCross: + psq_l fr1,0(r4),0,0 + lfs fr2,8(r3) + psq_l fr0,0(r3),0,0 + ps_merge10 fr6,fr1,fr1 + lfs fr3,8(r4) + ps_mul fr4,fr1,fr2 + ps_muls0 fr7,fr1,fr0 + ps_msub fr5,fr0,fr3,fr4 + ps_msub fr8,fr0,fr6,fr7 + ps_merge11 fr9,fr5,fr5 + ps_merge01 fr10,fr5,fr8 + psq_st fr9,0(r5),1,0 + ps_neg fr10,fr10 + psq_st fr10,4(r5),0,0 + blr + + .globl ps_guVecDotProduct + //r3 = vec1,r4 = vec2 +ps_guVecDotProduct: + psq_l fr2,4(r3),0,0 + psq_l fr3,4(r4),0,0 + ps_mul fr2,fr2,fr3 + psq_l fr5,0(r3),0,0 + psq_l fr4,0(r4),0,0 + ps_madd fr3,fr5,fr4,fr2 + ps_sum0 fr1,fr3,fr2,fr2 + blr + + .globl ps_guVecMultiply +ps_guVecMultiply: + psq_l fr0,0(r4),0,0 + psq_l fr2,0(r3),0,0 + psq_l fr1,8(r4),1,0 + ps_mul fr4,fr2,fr0 + psq_l fr3,8(r3),0,0 + ps_madd fr5,fr3,fr1,fr4 + psq_l fr8,16(r3),0,0 + ps_sum0 fr6,fr5,fr6,fr5 + psq_l fr9,24(r3),0,0 + ps_mul fr10,fr8,fr0 + psq_st fr6,0(r5),1,0 + ps_madd fr11,fr9,fr1,fr10 + psq_l fr2,32(r3),0,0 + ps_sum0 fr12,fr11,fr12,fr11 + psq_l fr3,40(r3),0,0 + ps_mul fr4,fr2,fr0 + psq_st fr12,4(r5),1,0 + ps_madd fr5,fr3,fr1,fr4 + ps_sum0 fr6,fr5,fr6,fr5 + psq_st fr6,8(r5),1,0 + blr + + .globl ps_guVecMultiplySR + // r3 = mt, r4 = src, r5 = dst +ps_guVecMultiplySR: + psq_l fr0,0(r3),0,0 // m[0][0], m[0][1] GQR0 = 0 + // fp6 - x y + psq_l fr6,0(r4),0,0 + psq_l fr2,16(r3),0,0 // m[1][0], m[1][1] + // fp8 = m00x m01y // next X + ps_mul fr8,fr0,fr6 + psq_l fr4,32(r3),0,0 // m[2][0], m[2][1] + // fp10 = m10x m11y // next Y + ps_mul fr10,fr2,fr6 + psq_l fr7,8(r4),1,0 // fp7 - z,1.0 + // fp12 = m20x m21y // next Z + ps_mul fr12,fr4,fr6 // YYY last FP6 usage + psq_l fr3,24(r3),0,0 // m[1][2], m[1][3] + ps_sum0 fr8,fr8,fr8,fr8 + psq_l fr5,40(r3),0,0 // m[2][2], m[2][3] + ps_sum0 fr10,fr10,fr10,fr10 + psq_l fr1,8(r3),0,0 // m[0][2], m[0][3] + ps_sum0 fr12,fr12,fr12,fr12 + ps_madd fr9,fr1,fr7,fr8 + psq_st fr9,0(r5),1,0 // store X + ps_madd fr11,fr3,fr7,fr10 + psq_st fr11,4(r5),1,0 // store Y + ps_madd fr13,fr5,fr7,fr12 + psq_st fr13,8(r5),1,0 // sore Z + blr + + .globl ps_guQuatAdd + //r3 = a, r4 = b, r5 = ab +ps_guQuatAdd: + psq_l fr0,0(r3),0,0 + psq_l fr1,0(r4),0,0 + ps_add fr1,fr0,fr1 + psq_st fr1,0(r5),0,0 + psq_l fr0,8(r3),0,0 + psq_l fr1,8(r4),0,0 + ps_add fr1,fr0,fr1 + psq_st fr1,8(r5),0,0 + blr + + .globl ps_guQuatSub + //r3 = a, r4 = b, r5 = ab +ps_guQuatSub: + psq_l fr0,0(r3),0,0 + psq_l fr1,0(r4),0,0 + ps_sub fr1,fr0,fr1 + psq_st fr1,0(r5),0,0 + psq_l fr0,8(r3),0,0 + psq_l fr1,8(r4),0,0 + ps_sub fr1,fr0,fr1 + psq_st fr1,8(r5),0,0 + blr + + .globl ps_guQuatMultiply + //r3 = a, r4 = b, r5 = ab +ps_guQuatMultiply: + psq_l fr0,0(r3),0,0 + psq_l fr1,8(r3),0,0 + psq_l fr2,0(r4),0,0 + ps_neg fr4,fr0 + psq_l fr3,8(r4),0,0 + ps_neg fr5,fr1 + ps_merge01 fr6,fr4,fr0 + ps_muls0 fr8,fr1,fr2 + ps_muls0 fr9,fr4,fr2 + ps_merge01 fr7,fr5,fr1 + ps_muls1 fr11,fr6,fr2 + ps_madds0 fr8,fr6,fr3,fr8 + ps_muls1 fr10,fr7,fr2 + ps_madds0 fr9,fr7,fr3,fr9 + ps_madds1 fr11,fr5,fr3,fr11 + ps_merge10 fr8,fr8,fr8 + ps_madds1 fr10,fr0,fr3,fr10 + ps_merge10 fr9,fr9,fr9 + ps_add fr8,fr8,fr8 + psq_st fr8,0(r5),0,0 + ps_sub fr9,fr9,fr9 + psq_st fr9,8(r5),0,0 + blr + + .globl ps_quQuatScale + //r3 = q,r4 = r, fr1 = scale +ps_guQuatScale: + psq_l fr4,0(r3),0,0 + psq_l fr5,8(r3),0,0 + ps_muls0 fr4,fr4,fr1 + psq_st fr4,0(r4),0,0 + ps_muls0 fr5,fr5,fr1 + psq_st fr5,8(r4),0,0 + blr + + .globl ps_guQuatDotProduct + //r3 = p, r4 = q ; fr1 = res +ps_guQuatDotProduct: + psq_l fr2,0(r3),0,0 + psq_l fr4,0(r4),0,0 + ps_mul fr1,fr2,fr4 + psq_l fr3,8(r3),0,0 + psq_l fr5,8(r4),0,0 + ps_madd fr1,fr3,fr5,fr1 + ps_sum0 fr1,fr1,fr1,fr1 + blr + + .globl ps_guQuatNormalize + //r3 = src, r4 = unit +ps_guQuatNormalize: + lis r9,NrmData@ha + addi r9,r9,NrmData@l + lfs fr9,0(r9) + lfs fr10,4(r9) + lis r9,QuatEpsilon@ha + lfs fr8,QuatEpsilon@l(r9) + psq_l fr0,0(r3),0,0 + ps_mul fr2,fr0,fr0 + psq_l fr1,8(r3),0,0 + ps_sub fr5,fr8,fr8 + ps_madd fr2,fr2,fr2,fr2 + frsqrte fr3,fr2 + ps_sub fr4,fr2,fr8 + fmul fr6,fr3,fr3 + fmul fr7,fr3,fr9 + fnmsub fr6,fr6,fr2,fr10 + fmul fr3,fr6,fr7 + ps_sel fr3,fr4,fr3,fr5 + ps_muls0 fr0,fr0,fr3 + ps_muls0 fr1,fr1,fr3 + psq_st fr0,0(r4),0,0 + psq_st fr1,8(r4),0,0 + blr + + .section .data + .balign 4 +QuatEpsilon: + .float 0.00001 +Unit01: + .float 0.0, 1.0 +NrmData: + .float 0.5, 3.0 diff --git a/inject/Makefile b/inject/Makefile new file mode 100644 index 00000000..141d2bd8 --- /dev/null +++ b/inject/Makefile @@ -0,0 +1,4 @@ +inject.exe : inject.c + @gcc -O2 -Wall inject.c -o inject.exe + @strip inject.exe + diff --git a/inject/inject.c b/inject/inject.c new file mode 100644 index 00000000..a2c89fc5 --- /dev/null +++ b/inject/inject.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * Snes9x-GX 2.0 + * + * Developer ROM injector. + * + * You should set ROMOFFSET to match aram.cpp, as this will change as the + * binary expands and/or contracts. + ****************************************************************************/ +#include +#include +#include + +#define DOLHEADERLENGTH 256 // GC DOL Header Length +#define MAXTEXT 7 // Maximum 7 Text Sections +#define MAXDATA 11 // Maximum 11 Data Sections + +struct DOLHEADER{ + unsigned int textOffsets[MAXTEXT]; + unsigned int dataOffsets[MAXDATA]; + + unsigned int textAddress[MAXTEXT]; + unsigned int dataAddress[MAXDATA]; + + unsigned int textLength[MAXTEXT]; + unsigned int dataLength[MAXDATA]; + + unsigned int bssAddress; + unsigned int bssLength; + + unsigned int entryPoint; + unsigned int unused[MAXTEXT]; +} dolheader; + +unsigned int FLIP32(unsigned int b) +{ + unsigned int c; + + c = ( b & 0xff000000 ) >> 24; + c |= ( b & 0xff0000 ) >> 8; + c |= ( b & 0xff00 ) << 8; + c |= ( b & 0xff ) << 24; + + return c; +} + +#define ROMOFFSET 0x81000000 + +int main( int argc, char *argv[] ) +{ + FILE *infile, *outfile; + char *dol; + char *rom; + int dollen, romlen, outlen; + char *sig = "SNESROM0"; + + if ( argc != 4 ) + { + printf("Usage : %s snes9xGx201.dol snesrom.smc output.dol\n", argv[0]); + return 1; + } + + /*** Try to open all three handles ***/ + infile = fopen(argv[1], "rb"); + if ( infile == NULL ) + { + printf("Unable to open %s for reading\n", argv[1]); + return 1; + } + + /*** Allocate and load ***/ + fseek(infile, 0, SEEK_END); + dollen=ftell(infile); + fseek(infile, 0, SEEK_SET); + + dol = calloc(sizeof(char), dollen + 32); + + if ( fread(dol, 1, dollen, infile ) != dollen ) + { + free(dol); + printf("Error reading %s\n", argv[1]); + fclose(infile); + return 1; + } + + fclose(infile); + + infile = fopen(argv[2], "rb"); + if ( infile == NULL ) + { + printf("Unable to open %s for reading\n", argv[2]); + free(dol); + return 1; + } + + /*** Allocate and load ***/ + fseek( infile, 0, SEEK_END); + romlen = ftell(infile); + fseek( infile, 0, SEEK_SET); + rom = calloc( sizeof(char), romlen + 48 ); + + if ( fread(rom, 1, romlen, infile) != romlen ) + { + printf("Error reading %s\n", argv[2]); + fclose(infile); + free(rom); + free(dol); + return 1; + } + + fclose(infile); + + /*** Ok, now have both in memory - so update the dol header and get this file done -;) ***/ + memcpy(&dolheader, dol, DOLHEADERLENGTH); + + /*** Align to 32 bytes - no real reason, I just like it -;) ***/ + if ( dollen & 0x1f ) + dollen = ( dollen & ~0x1f ) + 0x20; + + dolheader.dataOffsets[1] = FLIP32(dollen); + dolheader.dataAddress[1] = FLIP32(ROMOFFSET); + dolheader.dataLength[1] = FLIP32(romlen + 32); + + /*** Move the updated header back ***/ + memcpy(dol, &dolheader, DOLHEADERLENGTH); + + outfile = fopen(argv[3], "wb"); + if ( outfile == NULL ) + { + printf("Unable to open %s for writing!\n", argv[3]); + free(rom); + free(dol); + } + + /*** Now simply update the files ***/ + fwrite(dol, 1, dollen, outfile); + fwrite(sig, 1, 8, outfile); + + outlen = FLIP32(romlen); + fwrite(&outlen, 1, 4, outfile); + + char align[32]; + memset(align, 0, 32); + fwrite(align, 1, 20, outfile); + fwrite(rom, 1, romlen, outfile); + fclose(outfile); + + free(dol); + free(rom); + + printf("Output file %s created successfully\n", argv[3]); + + return 0; +} + diff --git a/inject/make-inject b/inject/make-inject new file mode 100644 index 00000000..4c82ecd4 --- /dev/null +++ b/inject/make-inject @@ -0,0 +1,10 @@ +#!/bin/bash + +#OS="macosx" +OS="win32" +#OS="linux" + +echo Compiling inject.c for ${OS}... +cp makefiles/Makefile-inject-${OS} Makefile +make +echo \ No newline at end of file diff --git a/inject/makefiles/Makefile-inject-linux b/inject/makefiles/Makefile-inject-linux new file mode 100644 index 00000000..d55da103 --- /dev/null +++ b/inject/makefiles/Makefile-inject-linux @@ -0,0 +1,4 @@ +inject.exe : inject.c + @gcc -O2 -Wall inject.c -o inject + @strip inject + diff --git a/inject/makefiles/Makefile-inject-macosx b/inject/makefiles/Makefile-inject-macosx new file mode 100644 index 00000000..f1a75a83 --- /dev/null +++ b/inject/makefiles/Makefile-inject-macosx @@ -0,0 +1,4 @@ +inject.exe : inject.c + @gcc -O2 -arch i386 -arch ppc -Wall inject.c -o inject + @strip inject + diff --git a/inject/makefiles/Makefile-inject-win32 b/inject/makefiles/Makefile-inject-win32 new file mode 100644 index 00000000..141d2bd8 --- /dev/null +++ b/inject/makefiles/Makefile-inject-win32 @@ -0,0 +1,4 @@ +inject.exe : inject.c + @gcc -O2 -Wall inject.c -o inject.exe + @strip inject.exe + diff --git a/makeall b/makeall new file mode 100644 index 00000000..a3928212 --- /dev/null +++ b/makeall @@ -0,0 +1,25 @@ +#!/bin/bash + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-mcslota Makefile +make + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-sdslota Makefile +make + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-sdslotb Makefile +make + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-smb Makefile +make + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-noload Makefile +make + +touch source/ngc/snes9xGX.h +cp makefiles/Makefile-mcslotb Makefile +make \ No newline at end of file diff --git a/makefiles/Makefile-mcslota b/makefiles/Makefile-mcslota new file mode 100644 index 00000000..acf8e02c --- /dev/null +++ b/makefiles/Makefile-mcslota @@ -0,0 +1,179 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-mcslota +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=0 \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/makefiles/Makefile-mcslotb b/makefiles/Makefile-mcslotb new file mode 100644 index 00000000..509a98d7 --- /dev/null +++ b/makefiles/Makefile-mcslotb @@ -0,0 +1,179 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-mcslotb +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=1 \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/makefiles/Makefile-noload b/makefiles/Makefile-noload new file mode 100644 index 00000000..db328cad --- /dev/null +++ b/makefiles/Makefile-noload @@ -0,0 +1,179 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-noload +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=-1 \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/makefiles/Makefile-sdslota b/makefiles/Makefile-sdslota new file mode 100644 index 00000000..f2556ed5 --- /dev/null +++ b/makefiles/Makefile-sdslota @@ -0,0 +1,179 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-sdslota +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=2 \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/makefiles/Makefile-sdslotb b/makefiles/Makefile-sdslotb new file mode 100644 index 00000000..1cc28c86 --- /dev/null +++ b/makefiles/Makefile-sdslotb @@ -0,0 +1,179 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-sdslotb +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=3 \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/makefiles/Makefile-smb b/makefiles/Makefile-smb new file mode 100644 index 00000000..aefe15e7 --- /dev/null +++ b/makefiles/Makefile-smb @@ -0,0 +1,188 @@ +#--------------------------------------------------------------------------------- +# Generic makefile for Gamecube projects +# +# Tab stops set to 4 +# | | | | +# 0 1 2 3 +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := bin/snes9xGx201b8-smb +BUILD := build +SOURCES := source/snes9x source/unzip source/ngc source/smb +INCLUDES := source/snes9x source/unzip source/ngc source/smb + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) \ + -DNGC -DNO_ASM -DCPU_SHUTDOWN -DSPC700C \ + -DSPC700_SHUTDOWN -DNEW_COLOUR_BLENDING \ + -DNO_INLINE_GET_SET -DSDD1_DECOMP -DCORRECT_VRAM_READS \ + -DDETECT_NASTY_FX_INTERLEAVE -DNGC_ZOOM -DSDUSE_LFN \ + -DQUICK_SAVE_SLOT=4 \ + -DGC_IP='"192.168.1.32"' \ + -DGW_IP='"192.168.1.100"' \ + -DMASK='"255.255.255.0"' \ + -DSMB_USER='"Guest"' \ + -DSMB_PWD='"password"' \ + -DSMB_GCID='"gamecube"' \ + -DSMB_SVID='"mypc"' \ + -DSMB_SHARE='"gcshare"' \ + -DSMB_IP='"192.168.1.100"' \ + -fomit-frame-pointer -fno-exceptions -Wno-unused-parameter \ + -pipe + + +LDFLAGS = $(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map -Wl,--cref + +PREFIX := powerpc-gekko- + +#export PATH:=/c/devkitPPC_r11/bin:/bin + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with +#--------------------------------------------------------------------------------- +LIBS := -logc -lm -lz -logcsys -lfreetype -lbba -lsdcard + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- +export OUTPUT := $(CURDIR)/$(TARGET) +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +export CC := $(PREFIX)gcc +export CXX := $(PREFIX)g++ +export AR := $(PREFIX)ar +export OBJCOPY := $(PREFIX)objcopy +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) *.elf + +#--------------------------------------------------------------------------------- +run: + psoload $(TARGET).dol + +#--------------------------------------------------------------------------------- +reload: + psoload -r $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf + @echo output ... $(notdir $@) + @$(OBJCOPY) -O binary $< $@ + +#--------------------------------------------------------------------------------- +$(OUTPUT).elf: $(OFILES) + @echo linking ... $(notdir $@) + @$(LD) $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +#--------------------------------------------------------------------------------- +# Compile Targets for C/C++ +#--------------------------------------------------------------------------------- + +#--------------------------------------------------------------------------------- +%.o : %.cpp + @echo Compiling ... $(notdir $<) + @$(CXX) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.c + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -o $@ -c $< + +#--------------------------------------------------------------------------------- +%.o : %.S + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +%.o : %.s + @echo Compiling ... $(notdir $<) + @$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@ + +#--------------------------------------------------------------------------------- +# canned command sequence for binary data +#--------------------------------------------------------------------------------- +define bin2o + cp $(<) $(*).tmp + $(OBJCOPY) -I binary -O elf32-powerpc -B powerpc \ + --rename-section .data=.rodata,readonly,data,contents,alloc \ + --redefine-sym _binary_$*_tmp_start=$*\ + --redefine-sym _binary_$*_tmp_end=$*_end\ + --redefine-sym _binary_$*_tmp_size=$*_size\ + $(*).tmp $(@) + echo "extern const u8" $(*)"[];" > $(*).h + echo "extern const u32" $(*)_size[]";" >> $(*).h + rm $(*).tmp +endef + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/source/ngc/aram.cpp b/source/ngc/aram.cpp index e64a3120..b79b6ac9 100644 --- a/source/ngc/aram.cpp +++ b/source/ngc/aram.cpp @@ -1,16 +1,12 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * - * aram.cpp + * Nintendo Gamecube Audio RAM * - * Gamecube Audio RAM storage - ***************************************************************************/ - + * softdev July 2006 + ****************************************************************************/ #include #include - #include "aram.h" #define ARAM_READ 1 @@ -19,11 +15,11 @@ #define TEMPSIZE 32768 static char tempbuffer[TEMPSIZE] ATTRIBUTE_ALIGN (32); -/**************************************************************************** +/** * ARAMPut * * Move data from MAIN memory to ARAM - ***************************************************************************/ + */ void ARAMPut (char *src, char *dst, int len) { @@ -32,11 +28,11 @@ ARAMPut (char *src, char *dst, int len) while (AR_GetDMAStatus()); } -/**************************************************************************** +/** * ARAMFetch * * This function will move data from ARAM to MAIN memory - ***************************************************************************/ + */ void ARAMFetch (char *dst, char *src, int len) { @@ -45,11 +41,11 @@ ARAMFetch (char *dst, char *src, int len) while (AR_GetDMAStatus ()); } -/**************************************************************************** +/** * ARAMFetchSlow * * Required as SNES memory may NOT be 32-byte aligned - ***************************************************************************/ + */ void ARAMFetchSlow (char *dst, char *src, int len) { diff --git a/source/ngc/aram.h b/source/ngc/aram.h index cb18facc..e3a71241 100644 --- a/source/ngc/aram.h +++ b/source/ngc/aram.h @@ -1,13 +1,10 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * - * aram.h + * Nintendo Gamecube Audio RAM * - * Gamecube Audio RAM storage - ***************************************************************************/ - + * softdev July 2006 + ****************************************************************************/ #ifndef _GCARAMI_ #define _GCARAMI_ diff --git a/source/ngc/audio.cpp b/source/ngc/audio.cpp index 4ef225f6..3b7e34b6 100644 --- a/source/ngc/audio.cpp +++ b/source/ngc/audio.cpp @@ -1,20 +1,17 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * - * audio.cpp + * Nintendo Gamecube Audio * - * Audio driver * Audio is fixed to 32Khz/16bit/Stereo - ***************************************************************************/ - + * + * softdev July 2006 + ****************************************************************************/ #include #include #include #include #include - #include "snes9x.h" #include "memmap.h" #include "debug.h" @@ -29,7 +26,7 @@ #include "controls.h" #include "video.h" -#include "menudraw.h" +#include "ftfont.h" /*** Double buffered audio ***/ #define AUDIOBUFFER 2048 @@ -43,65 +40,65 @@ lwpq_t audioqueue; lwp_t athread; static uint8 astack[AUDIOSTACK]; -/**************************************************************************** +/** * Audio Threading - ***************************************************************************/ + */ static void * AudioThread (void *arg) { - LWP_InitQueue (&audioqueue); + LWP_InitQueue (&audioqueue); - while (1) + while (1) + { + whichab ^= 1; + if (ConfigRequested) + memset (soundbuffer[whichab], 0, AUDIOBUFFER); + else { - whichab ^= 1; - if (ConfigRequested) - memset (soundbuffer[whichab], 0, AUDIOBUFFER); - else - { - so.samples_mixed_so_far = so.play_position = 0; - S9xMixSamples (soundbuffer[whichab], AUDIOBUFFER >> 1); - } - LWP_ThreadSleep (audioqueue); + so.samples_mixed_so_far = so.play_position = 0; + S9xMixSamples (soundbuffer[whichab], AUDIOBUFFER >> 1); } + LWP_ThreadSleep (audioqueue); + } - return NULL; + return NULL; } -/**************************************************************************** - * MixSamples - * This continually calls S9xMixSamples On each DMA Completion - ***************************************************************************/ +/** + * MixSamples + * This continually calls S9xMixSamples On each DMA Completion + */ static void GCMixSamples () { - AUDIO_StopDMA (); + AUDIO_StopDMA (); - DCFlushRange (soundbuffer[whichab], AUDIOBUFFER); - AUDIO_InitDMA ((u32) soundbuffer[whichab], AUDIOBUFFER); - AUDIO_StartDMA (); + DCFlushRange (soundbuffer[whichab], AUDIOBUFFER); + AUDIO_InitDMA ((u32) soundbuffer[whichab], AUDIOBUFFER); + AUDIO_StartDMA (); - LWP_ThreadSignal (audioqueue); + LWP_ThreadSignal (audioqueue); } -/**************************************************************************** - * InitGCAudio - ***************************************************************************/ +/** + * InitGCAudio + */ void InitGCAudio () { - AUDIO_SetDSPSampleRate (AI_SAMPLERATE_32KHZ); - AUDIO_RegisterDMACallback (GCMixSamples); + AUDIO_SetDSPSampleRate (AI_SAMPLERATE_32KHZ); + AUDIO_RegisterDMACallback (GCMixSamples); - LWP_CreateThread (&athread, AudioThread, NULL, astack, AUDIOSTACK, 80); + LWP_CreateThread (&athread, AudioThread, NULL, astack, AUDIOSTACK, 80); } -/**************************************************************************** +/** * AudioStart * * Called to kick off the Audio Queue - ***************************************************************************/ + */ void AudioStart () { - GCMixSamples (); + GCMixSamples (); } diff --git a/source/ngc/audio.h b/source/ngc/audio.h index 19433f79..90540466 100644 --- a/source/ngc/audio.h +++ b/source/ngc/audio.h @@ -1,13 +1,12 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * - * audio.h + * Nintendo Gamecube Audio * - * Audio driver * Audio is fixed to 32Khz/16bit/Stereo - ***************************************************************************/ + * + * softdev July 2006 + ****************************************************************************/ void InitGCAudio (); void AudioStart (); diff --git a/source/ngc/button_mapping.c b/source/ngc/button_mapping.c index 83d097a8..90a0fb79 100644 --- a/source/ngc/button_mapping.c +++ b/source/ngc/button_mapping.c @@ -1,117 +1,240 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * michniewski August 2008 - * - * button_mapping.c - * - * Controller button mapping - ***************************************************************************/ - #include #include #include #include + #include #include #include - #include "button_mapping.h" -/**************************************************************************** - * Controller Button Descriptions: - * used for identifying which buttons have been pressed when configuring - * and for displaying the name of said button - ***************************************************************************/ +/*** +* Controller Button Descriptions: +* used for identifying which buttons have been pressed when configuring +* and for displaying the name of said button +***/ +//CtrlrMap ctrlr_def[4]; -CtrlrMap ctrlr_def[4] = { +CtrlrMap ctrlr_def[4] = { // Nunchuk btn def -{ - CTRLR_NUNCHUK, - 13, - { - {WPAD_BUTTON_DOWN, "DOWN"}, - {WPAD_BUTTON_UP, "UP"}, - {WPAD_BUTTON_LEFT, "LEFT"}, - {WPAD_BUTTON_RIGHT, "RIGHT"}, - {WPAD_BUTTON_A, "A"}, - {WPAD_BUTTON_B, "B"}, - {WPAD_BUTTON_1, "1"}, - {WPAD_BUTTON_2, "2"}, - {WPAD_BUTTON_PLUS, "PLUS"}, - {WPAD_BUTTON_MINUS, "MINUS"}, - {WPAD_BUTTON_HOME, "HOME"}, - {WPAD_NUNCHUK_BUTTON_Z, "Z"}, - {WPAD_NUNCHUK_BUTTON_C, "C"}, - {0, ""}, - {0, ""} - } -}, +CTRLR_NUNCHUK, +13, +WPAD_BUTTON_DOWN, "DOWN", +WPAD_BUTTON_UP, "UP", +WPAD_BUTTON_LEFT, "LEFT", +WPAD_BUTTON_RIGHT, "RIGHT", +WPAD_BUTTON_A, "A", +WPAD_BUTTON_B, "B", +WPAD_BUTTON_1, "1", +WPAD_BUTTON_2, "2", +WPAD_BUTTON_PLUS, "PLUS", +WPAD_BUTTON_MINUS, "MINUS", +WPAD_BUTTON_HOME, "HOME", +WPAD_NUNCHUK_BUTTON_Z, "Z", +WPAD_NUNCHUK_BUTTON_C, "C", +0, "", +0, "", // Classic btn def -{ - CTRLR_CLASSIC, - 15, - { - {WPAD_CLASSIC_BUTTON_DOWN, "DOWN"}, - {WPAD_CLASSIC_BUTTON_UP, "UP"}, - {WPAD_CLASSIC_BUTTON_LEFT, "LEFT"}, - {WPAD_CLASSIC_BUTTON_RIGHT, "RIGHT"}, - {WPAD_CLASSIC_BUTTON_A, "A"}, - {WPAD_CLASSIC_BUTTON_B, "B"}, - {WPAD_CLASSIC_BUTTON_X, "X"}, - {WPAD_CLASSIC_BUTTON_Y, "Y"}, - {WPAD_CLASSIC_BUTTON_PLUS, "PLUS"}, - {WPAD_CLASSIC_BUTTON_MINUS, "MINUS"}, - {WPAD_CLASSIC_BUTTON_HOME, "HOME"}, - {WPAD_CLASSIC_BUTTON_FULL_L, "L TRIG"}, - {WPAD_CLASSIC_BUTTON_FULL_R, "R TRIG"}, - {WPAD_CLASSIC_BUTTON_ZL, "ZL"}, - {WPAD_CLASSIC_BUTTON_ZR, "ZR"} - } -}, -// Gamecube controller btn def -{ - CTRLR_GCPAD, - 13, - { - {PAD_BUTTON_DOWN, "DOWN"}, - {PAD_BUTTON_UP, "UP"}, - {PAD_BUTTON_LEFT, "LEFT"}, - {PAD_BUTTON_RIGHT, "RIGHT"}, - {PAD_BUTTON_A, "A"}, - {PAD_BUTTON_B, "B"}, - {PAD_BUTTON_X, "X"}, - {PAD_BUTTON_Y, "Y"}, - {PAD_BUTTON_MENU, "MENU"}, - {PAD_BUTTON_START, "START"}, - {PAD_TRIGGER_L, "L TRIG"}, - {PAD_TRIGGER_R, "R TRIG"}, - {PAD_TRIGGER_Z, "Z"}, - {0, ""}, - {0, ""} - } -}, +CTRLR_CLASSIC, +15, +WPAD_CLASSIC_BUTTON_DOWN, "DOWN", +WPAD_CLASSIC_BUTTON_UP, "UP", +WPAD_CLASSIC_BUTTON_LEFT, "LEFT", +WPAD_CLASSIC_BUTTON_RIGHT, "RIGHT", +WPAD_CLASSIC_BUTTON_A, "A", +WPAD_CLASSIC_BUTTON_B, "B", +WPAD_CLASSIC_BUTTON_X, "X", +WPAD_CLASSIC_BUTTON_Y, "Y", +WPAD_CLASSIC_BUTTON_PLUS, "PLUS", +WPAD_CLASSIC_BUTTON_MINUS, "MINUS", +WPAD_CLASSIC_BUTTON_HOME, "HOME", +WPAD_CLASSIC_BUTTON_FULL_L, "L TRIG", +WPAD_CLASSIC_BUTTON_FULL_R, "R TRIG", +WPAD_CLASSIC_BUTTON_ZL, "ZL", +WPAD_CLASSIC_BUTTON_ZR, "ZR", +// Gamecube controller btn def +CTRLR_GCPAD, +13, +PAD_BUTTON_DOWN, "DOWN", +PAD_BUTTON_UP, "UP", +PAD_BUTTON_LEFT, "LEFT", +PAD_BUTTON_RIGHT, "RIGHT", +PAD_BUTTON_A, "A", +PAD_BUTTON_B, "B", +PAD_BUTTON_X, "X", +PAD_BUTTON_Y, "Y", +PAD_BUTTON_MENU, "MENU", +PAD_BUTTON_START, "START", +PAD_TRIGGER_L, "L TRIG", +PAD_TRIGGER_R, "R TRIG", +PAD_TRIGGER_Z, "Z", +0, "", +0, "", // Wiimote btn def -{ - CTRLR_WIIMOTE, - 11, - { - {WPAD_BUTTON_DOWN, "DOWN"}, - {WPAD_BUTTON_UP, "UP"}, - {WPAD_BUTTON_LEFT, "LEFT"}, - {WPAD_BUTTON_RIGHT, "RIGHT"}, - {WPAD_BUTTON_A, "A"}, - {WPAD_BUTTON_B, "B"}, - {WPAD_BUTTON_1, "1"}, - {WPAD_BUTTON_2, "2"}, - {WPAD_BUTTON_PLUS, "PLUS"}, - {WPAD_BUTTON_MINUS, "MINUS"}, - {WPAD_BUTTON_HOME, "HOME"}, - {0, ""}, - {0, ""}, - {0, ""}, - {0, ""} - } - } +CTRLR_WIIMOTE, +11, +WPAD_BUTTON_DOWN, "DOWN", +WPAD_BUTTON_UP, "UP", +WPAD_BUTTON_LEFT, "LEFT", +WPAD_BUTTON_RIGHT, "RIGHT", +WPAD_BUTTON_A, "A", +WPAD_BUTTON_B, "B", +WPAD_BUTTON_1, "1", +WPAD_BUTTON_2, "2", +WPAD_BUTTON_PLUS, "PLUS", +WPAD_BUTTON_MINUS, "MINUS", +WPAD_BUTTON_HOME, "HOME", +0, "", +0, "", +0, "", +0, "" +}; + +/* +// Nunchuk btn def +ctrlr_def[0].type = CTRLR_NUNCHUK; +ctrlr_def[0].num_btns = 13; +ctrlr_def[0].map[] = { WPAD_BUTTON_DOWN, "DOWN", +WPAD_BUTTON_UP, "UP", +WPAD_BUTTON_LEFT, "LEFT", +WPAD_BUTTON_RIGHT, "RIGHT", +WPAD_BUTTON_A, "A", +WPAD_BUTTON_B, "B", +WPAD_BUTTON_1, "1", +WPAD_BUTTON_2, "2", +WPAD_BUTTON_PLUS, "PLUS", +WPAD_BUTTON_MINUS, "MINUS", +WPAD_BUTTON_HOME, "HOME", +WPAD_NUNCHUK_BUTTON_Z, "Z", +WPAD_NUNCHUK_BUTTON_C, "C" +}; +// Classic btn def +ctrlr_def[1].type = CTRLR_CLASSIC; +ctrlr_def[1].num_btns = 15; +ctrlr_def[1].map[] = { WPAD_CLASSIC_BUTTON_DOWN, "DOWN", +WPAD_CLASSIC_BUTTON_UP, "UP", +WPAD_CLASSIC_BUTTON_LEFT, "LEFT", +WPAD_CLASSIC_BUTTON_RIGHT, "RIGHT", +WPAD_CLASSIC_BUTTON_A, "A", +WPAD_CLASSIC_BUTTON_B, "B", +WPAD_CLASSIC_BUTTON_X, "X", +WPAD_CLASSIC_BUTTON_Y, "Y", +WPAD_CLASSIC_BUTTON_PLUS, "PLUS", +WPAD_CLASSIC_BUTTON_MINUS, "MINUS", +WPAD_CLASSIC_BUTTON_HOME, "HOME", +WPAD_CLASSIC_BUTTON_FULL_L, "L TRIG", +WPAD_CLASSIC_BUTTON_FULL_R, "R TRIG", +WPAD_CLASSIC_BUTTON_ZL, "ZL", +WPAD_CLASSIC_BUTTON_ZR, "ZR", }; +// Gamecube controller btn def +ctrlr_def[2].type = CTRLR_GCPAD; +ctrlr_def[2].num_btns = 13; +ctrlr_def[2].map[] = { PAD_BUTTON_DOWN, "DOWN", +PAD_BUTTON_UP, "UP", +PAD_BUTTON_LEFT, "LEFT", +PAD_BUTTON_RIGHT, "RIGHT", +PAD_BUTTON_A, "A", +PAD_BUTTON_B, "B", +PAD_BUTTON_X, "X", +PAD_BUTTON_Y, "Y", +PAD_BUTTON_MENU, "MENU", +PAD_BUTTON_START, "START", +PAD_BUTTON_L, "L TRIG", +PAD_BUTTON_R, "R TRIG", +PAD_BUTTON_Z, "Z", +}; +// Wiimote btn def +ctrlr_def[3].type = CTRLR_WIIMOTE; +ctrlr_def[3].num_btns = 11; +ctrlr_def[3].map[] = { WPAD_BUTTON_DOWN, "DOWN", +WPAD_BUTTON_UP, "UP", +WPAD_BUTTON_LEFT, "LEFT", +WPAD_BUTTON_RIGHT, "RIGHT", +WPAD_BUTTON_A, "A", +WPAD_BUTTON_B, "B", +WPAD_BUTTON_1, "1", +WPAD_BUTTON_2, "2", +WPAD_BUTTON_PLUS, "PLUS", +WPAD_BUTTON_MINUS, "MINUS", +WPAD_BUTTON_HOME, "HOME" +}; +// end buttonmaps +*/ + +/*** +* Default controller maps +* button press on left, and corresponding snes button on right +* arguably some data is unnecessary here but lets stick to one struct type ok? + +CtrlrMap defaultmap[4]; +// Nunchuk Default +defaultmap[0].type = CTRLR_NUNCHUK; +defaultmap[0].num_btns = 12; +defaultmap[0].map[] = { WPAD_BUTTON_A, "A", + WPAD_BUTTON_B, "B", + WPAD_NUNCHUK_BUTTON_C, "X", + WPAD_NUNCHUK_BUTTON_Z, "Y", + WPAD_BUTTON_MINUS, "L", + WPAD_BUTTON_PLUS, "R", + WPAD_BUTTON_2, "SELECT", + WPAD_BUTTON_1, "START", + WPAD_BUTTON_UP, "UP", + WPAD_BUTTON_DOWN, "DOWN", + WPAD_BUTTON_LEFT, "LEFT", + WPAD_BUTTON_RIGHT, "RIGHT" +}; +// Classic Default +defaultmap[1].type = CTRLR_CLASSIC; +defaultmap[1].num_btns = 12; +defaultmap[1].map[] = { WPAD_CLASSIC_BUTTON_A, "A", + WPAD_CLASSIC_BUTTON_B, "B", + WPAD_CLASSIC_BUTTON_Y, "X", + WPAD_CLASSIC_BUTTON_X, "Y", + WPAD_CLASSIC_BUTTON_FULL_L, "L", + WPAD_CLASSIC_BUTTON_FULL_R, "R", + WPAD_CLASSIC_BUTTON_MINUS, "SELECT", + WPAD_CLASSIC_BUTTON_PLUS, "START", + WPAD_CLASSIC_BUTTON_UP, "UP", + WPAD_CLASSIC_BUTTON_DOWN, "DOWN", + WPAD_CLASSIC_BUTTON_LEFT, "LEFT", + WPAD_CLASSIC_BUTTON_RIGHT, "RIGHT" +}; +// Gamecube Controller Default +defaultmap[2].type = CTRLR_GCPAD; +defaultmap[2].num_btns = 12; +defaultmap[2].map[] = {PAD_BUTTON_A, "A", + PAD_BUTTON_B, "B", + PAD_BUTTON_X, "X", + PAD_BUTTON_Y, "Y", + PAD_TRIGGER_L, "L", + PAD_TRIGGER_R, "R", + PAD_TRIGGER_Z, "SELECT", + PAD_BUTTON_START, "START", + PAD_BUTTON_UP, "UP", + PAD_BUTTON_DOWN, "DOWN", + PAD_BUTTON_LEFT, "LEFT", + PAD_BUTTON_RIGHT, "RIGHT" +}; +// Wiimote Default +defaultmap[3].type = CTRLR_WIIMOTE; +defaultmap[3].num_btns = 12; +defaultmap[3].map[] = { WPAD_BUTTON_B, "A", + WPAD_BUTTON_2, "B", + WPAD_BUTTON_1, "X", + WPAD_BUTTON_A, "Y", + 0x0000, "L", + 0x0000, "R", + WPAD_BUTTON_MINUS, "SELECT", + WPAD_BUTTON_PLUS, "START", + WPAD_BUTTON_RIGHT, "UP", + WPAD_BUTTON_LEFT, "DOWN", + WPAD_BUTTON_UP, "LEFT", + WPAD_BUTTON_DOWN, "RIGHT" +}; +// end default padmaps +***/ + + +// eof diff --git a/source/ngc/button_mapping.h b/source/ngc/button_mapping.h index 178dfc2c..1df99951 100644 --- a/source/ngc/button_mapping.h +++ b/source/ngc/button_mapping.h @@ -1,13 +1,3 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * michniewski August 2008 - * - * button_mapping.h - * - * Controller button mapping - ***************************************************************************/ - #ifndef BTN_MAP_H #define BTN_MAP_H diff --git a/source/ngc/cheatmgr.cpp b/source/ngc/cheatmgr.cpp deleted file mode 100644 index 6bb1b1c8..00000000 --- a/source/ngc/cheatmgr.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * Tantric August 2008 - * - * cheatmgr.cpp - * - * Cheat handling - ***************************************************************************/ - -#include "memmap.h" -#include "cheats.h" - -#include "snes9xGX.h" -#include "fileop.h" -#include "filesel.h" -#include "smbop.h" -#include "menudraw.h" - -extern SCheatData Cheat; - -/**************************************************************************** - * NGCLoadCheatFile - * - * Loads cheat file from save buffer - * Custom version of S9xLoadCheatFile() - ***************************************************************************/ - -bool NGCLoadCheatFile (int length) -{ - Cheat.num_cheats = 0; - - uint8 data [28]; - int offset = 0; - - while (offset < length) - { - if(Cheat.num_cheats < MAX_CHEATS) - { - memcpy (data, savebuffer+offset, 28); - offset += 28; - - Cheat.c [Cheat.num_cheats].enabled = (data [0] & 4) == 0; - Cheat.c [Cheat.num_cheats].byte = data [1]; - Cheat.c [Cheat.num_cheats].address = data [2] | (data [3] << 8) | (data [4] << 16); - Cheat.c [Cheat.num_cheats].saved_byte = data [5]; - Cheat.c [Cheat.num_cheats].saved = (data [0] & 8) != 0; - memmove (Cheat.c [Cheat.num_cheats].name, &data [8], 20); - Cheat.c [Cheat.num_cheats++].name [20] = 0; - } - } - - return true; -} - -/**************************************************************************** - * SetupCheats - * - * Erases any prexisting cheats, loads cheats from a cheat file - * Called when a ROM is first loaded - ***************************************************************************/ -void -SetupCheats() -{ - char filepath[1024]; - int offset = 0; - - S9xInitCheatData (); - S9xDeleteCheats (); - - int method = GCSettings.SaveMethod; - - if(method == METHOD_AUTO) - method = autoSaveMethod(); - - AllocSaveBuffer(); - - if(method == METHOD_SD || method == METHOD_USB) - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filepath, "%s/%s/%s.cht", ROOTFATDIR, GCSettings.CheatFolder, Memory.ROMFilename); - offset = LoadBufferFromFAT (filepath, SILENT); - } - } - else if(method == METHOD_SMB) - { - sprintf (filepath, "%s/%s.cht", GCSettings.CheatFolder, Memory.ROMFilename); - offset = LoadBufferFromSMB (filepath, SILENT); - } - - // load cheat file if present - if(offset > 0) - { - if(NGCLoadCheatFile (offset)) - { - // disable all cheats loaded from the file - for (uint16 i = 0; i < Cheat.num_cheats; i++) - S9xDisableCheat(i); - } - } - - FreeSaveBuffer (); -} diff --git a/source/ngc/dkpro.h b/source/ngc/dkpro.h new file mode 100644 index 00000000..718d401a --- /dev/null +++ b/source/ngc/dkpro.h @@ -0,0 +1,877 @@ +/******************************************************************* + * Image File : /public/dkpro.bmp + * Width : 218 + * Height : 65 + * + * This header contains a compressed Zip image. + * Use zlib1.2.3 uncompress function to restore. + *******************************************************************/ + +#define dkpro_RAW 28340 +#define dkpro_COMPRESSED 6887 +#define dkpro_WIDTH 218 +#define dkpro_HEIGHT 65 + +unsigned char dkpro[6887] = { + 0x78, 0xda, 0xed, 0x9c, 0x67, 0x70, 0x54, 0x57, 0x96, 0xc7, 0xf9, 0xb8, + 0xb5, 0x55, 0xbb, 0x55, + 0x53, 0xb5, 0xb5, 0xb3, 0x9e, 0x31, 0xc6, 0x98, 0x20, 0x31, 0xf6, 0x38, + 0x7b, 0xc6, 0x33, 0x0e, + 0xe3, 0x34, 0x60, 0x03, 0x36, 0xc9, 0x80, 0x49, 0xb6, 0x41, 0x42, 0x59, + 0x42, 0x39, 0x20, 0x75, + 0xbf, 0xd3, 0x92, 0x90, 0x84, 0x32, 0x41, 0x02, 0x11, 0xd4, 0x48, 0xe4, + 0x60, 0x72, 0x0e, 0x22, + 0x98, 0x8c, 0x8d, 0x04, 0x26, 0x83, 0x31, 0xe0, 0xec, 0x71, 0x06, 0xe7, + 0xa0, 0xfd, 0xdd, 0xdb, + 0xdd, 0xaf, 0x5f, 0xb7, 0xba, 0x07, 0x30, 0xc6, 0xf6, 0x87, 0xd6, 0xbf, + 0x1e, 0xb4, 0x6e, 0x38, + 0xf7, 0xe4, 0x7b, 0xee, 0x7b, 0x4f, 0xdd, 0x4e, 0xda, 0x5d, 0x1d, 0xaa, + 0xc3, 0x52, 0xba, 0x38, + 0x3b, 0x46, 0x75, 0x70, 0xb6, 0x8f, 0xbd, 0xb1, 0xfe, 0xc6, 0xf8, 0x3f, + 0x3a, 0x6f, 0x8c, 0x6f, + 0xef, 0xbc, 0x29, 0xb6, 0xa3, 0xb3, 0x53, 0x74, 0x57, 0x67, 0xb7, 0x88, + 0x76, 0x12, 0xc2, 0x6f, + 0x06, 0x55, 0xe1, 0xd8, 0xea, 0xe6, 0xa8, 0x3f, 0x38, 0xc3, 0x62, 0xfa, + 0xd5, 0x94, 0xc4, 0x2f, + 0x28, 0xdd, 0x91, 0x71, 0x74, 0xdc, 0xf9, 0xdc, 0x0b, 0x85, 0xa7, 0x72, + 0x0f, 0x8c, 0x5f, 0x95, + 0x59, 0x37, 0x29, 0x32, 0xf1, 0xfe, 0xfa, 0x3f, 0xc4, 0xb4, 0x77, 0x76, + 0x8a, 0x09, 0x9b, 0x15, + 0xb2, 0xdd, 0xaf, 0x6f, 0xaf, 0xb0, 0x94, 0x9b, 0x89, 0xa3, 0xbe, 0x93, + 0x9d, 0x09, 0xef, 0x39, + 0x5a, 0xed, 0xad, 0x12, 0x0c, 0x3f, 0xca, 0x8e, 0xca, 0x84, 0x94, 0xdb, + 0x9d, 0xed, 0xa3, 0xba, + 0x84, 0xec, 0xf6, 0x6b, 0xda, 0x2b, 0xf5, 0x26, 0x67, 0x58, 0x74, 0xe5, + 0xf8, 0x7f, 0x65, 0x6a, + 0xab, 0x18, 0xdf, 0x49, 0x50, 0x18, 0x3f, 0xb8, 0x6c, 0x37, 0x6e, 0x5d, + 0xee, 0xd3, 0x33, 0x6e, + 0x88, 0xeb, 0xec, 0xec, 0x16, 0x19, 0xd2, 0xe0, 0x2f, 0x9f, 0x0f, 0x3b, + 0xd4, 0xdf, 0x1b, 0x35, + 0xaf, 0xa8, 0x75, 0x6c, 0x2b, 0xf6, 0xf8, 0xc6, 0xf8, 0x46, 0x3c, 0xf8, + 0x9e, 0x98, 0xf2, 0x46, + 0xd7, 0x0f, 0xf2, 0xad, 0x78, 0xfb, 0xbe, 0x33, 0x68, 0xcd, 0x3f, 0x69, + 0x1b, 0x36, 0xfd, 0xa6, + 0xd8, 0x2e, 0xd5, 0xed, 0x52, 0x43, 0x9a, 0xfc, 0x85, 0x50, 0xdd, 0x2d, + 0xa5, 0xb3, 0xb3, 0x43, + 0x74, 0x69, 0x49, 0x6b, 0x76, 0xab, 0xf1, 0xb5, 0x7c, 0xa5, 0xa1, 0x6c, + 0xe5, 0xb2, 0xd3, 0x27, + 0x72, 0x52, 0xf6, 0xcb, 0x36, 0x69, 0x92, 0x5d, 0x72, 0x48, 0xde, 0x96, + 0x1f, 0xdc, 0xd6, 0xfb, + 0x56, 0xdc, 0x63, 0x0d, 0x6c, 0x5a, 0xb0, 0x3b, 0xef, 0xfe, 0xfa, 0x9b, + 0xa2, 0xc3, 0xab, 0xda, + 0xa5, 0x84, 0x34, 0x7a, 0xfd, 0xd1, 0xcd, 0xd9, 0x61, 0x74, 0x8f, 0xca, + 0x8f, 0x53, 0x5b, 0x8d, + 0xaf, 0xe4, 0x4b, 0x8d, 0x6f, 0xb0, 0xc9, 0xb7, 0x72, 0x5c, 0xe6, 0x48, + 0x86, 0x3c, 0x2b, 0x4f, + 0x4b, 0x5f, 0xe9, 0x2f, 0x03, 0x40, 0x7f, 0xe9, 0x27, 0x7d, 0xf8, 0x3d, + 0x5a, 0x2a, 0x65, 0x27, + 0xb6, 0x6c, 0xc5, 0xae, 0xae, 0x19, 0x5f, 0x2a, 0xbb, 0x95, 0x8c, 0xcf, + 0xea, 0xe8, 0x0c, 0x8b, + 0x0a, 0x69, 0xf4, 0x7a, 0xc7, 0x58, 0x58, 0xca, 0x1f, 0xa7, 0x94, 0x24, + 0xfd, 0x68, 0xff, 0x46, + 0x2e, 0x6a, 0x7c, 0x85, 0x25, 0x3e, 0x90, 0x06, 0x19, 0x8d, 0xb5, 0x06, + 0xcb, 0x70, 0x79, 0x41, + 0x5e, 0x6c, 0x83, 0x11, 0x32, 0x84, 0xde, 0x61, 0x32, 0x4e, 0x5e, 0xd5, + 0xd6, 0xbd, 0xa4, 0x67, + 0x5e, 0x22, 0x4f, 0x1e, 0x9a, 0x78, 0x4b, 0xca, 0xef, 0x9d, 0x37, 0x24, + 0xdd, 0xe0, 0xbc, 0x21, + 0x31, 0x74, 0x5d, 0xdb, 0xd5, 0xa1, 0xaa, 0x5d, 0x7a, 0x20, 0x9b, 0x85, + 0xcd, 0xea, 0x34, 0x7a, + 0x4d, 0x61, 0x6b, 0xee, 0xe7, 0xc6, 0x67, 0xf2, 0x99, 0x7c, 0x4e, 0xdc, + 0x9c, 0x93, 0x72, 0xe2, + 0x69, 0x08, 0x96, 0x19, 0x75, 0x19, 0x8c, 0xc4, 0x76, 0x03, 0x24, 0x81, + 0xac, 0xf9, 0x9d, 0x7c, + 0x21, 0x9f, 0x69, 0x7c, 0x65, 0x04, 0xaf, 0x34, 0x43, 0xb8, 0x3a, 0xac, + 0x99, 0xdc, 0x21, 0xb9, + 0x6d, 0xdd, 0xd1, 0x35, 0xb5, 0xc3, 0xc4, 0xe6, 0x94, 0xef, 0xed, 0x9f, + 0x88, 0xc2, 0x25, 0x62, + 0xac, 0x51, 0x86, 0x62, 0x89, 0xc8, 0xab, 0xc0, 0x48, 0x79, 0x4e, 0xc6, + 0xca, 0x19, 0xec, 0xf6, + 0xa9, 0x7c, 0x12, 0xc2, 0xcf, 0x05, 0xea, 0x8a, 0x39, 0x35, 0x1d, 0x92, + 0xda, 0xc6, 0x58, 0x97, + 0xc8, 0x23, 0xf2, 0x95, 0xfd, 0x43, 0x51, 0xf8, 0x42, 0x8e, 0x92, 0x0f, + 0x87, 0x73, 0x45, 0x5d, + 0x35, 0x46, 0x92, 0x45, 0x17, 0x90, 0x1d, 0x3f, 0x96, 0x0f, 0x43, 0xf8, + 0x79, 0x60, 0x7c, 0x21, + 0x8d, 0x35, 0x37, 0x27, 0xf9, 0xd7, 0xf6, 0xed, 0x27, 0xee, 0x4e, 0xbd, + 0x64, 0x7f, 0x5f, 0xde, + 0x67, 0xff, 0xfa, 0x5a, 0x56, 0x90, 0x0d, 0x47, 0x4b, 0xec, 0x4f, 0x44, + 0x8c, 0x3c, 0x2f, 0x42, + 0xa4, 0xaa, 0x5a, 0x32, 0x84, 0x6b, 0xc3, 0x87, 0x58, 0xe4, 0x7d, 0xe3, + 0x73, 0x69, 0xf0, 0xb3, + 0x99, 0xaa, 0x15, 0xe7, 0x17, 0x7c, 0x99, 0xf7, 0xae, 0xbc, 0x2b, 0xef, + 0x11, 0x8b, 0x33, 0x89, + 0xb0, 0x38, 0x89, 0xbf, 0x26, 0x44, 0x63, 0x37, 0xb5, 0xcb, 0x85, 0x70, + 0x2d, 0x18, 0x28, 0x47, + 0x88, 0xa1, 0x77, 0x8d, 0x4f, 0xc5, 0xe9, 0x67, 0xb3, 0x9b, 0xa7, 0x66, + 0xc4, 0x7d, 0x61, 0x7f, + 0xdb, 0xf1, 0x16, 0xe7, 0xad, 0xcf, 0x64, 0xaa, 0x44, 0x48, 0xa2, 0x24, + 0x5d, 0x33, 0x12, 0x43, + 0xb8, 0x66, 0x8c, 0x94, 0x63, 0xc4, 0xd1, 0x5b, 0xc6, 0x47, 0x52, 0x6f, + 0xb5, 0x59, 0x75, 0x97, + 0xd4, 0xbf, 0x95, 0x5f, 0x4c, 0xbf, 0x60, 0x9c, 0x97, 0xf3, 0xd8, 0x74, + 0x16, 0x95, 0x44, 0x4a, + 0x08, 0xbf, 0x11, 0x44, 0xc9, 0x6b, 0xf2, 0x96, 0x9c, 0x37, 0x3e, 0x90, + 0xe9, 0x35, 0x1d, 0x4d, + 0x9b, 0x85, 0x3b, 0x3b, 0x8e, 0xde, 0xe6, 0x78, 0xdb, 0x7e, 0x56, 0xce, + 0x62, 0xd1, 0xd5, 0xec, + 0x46, 0x69, 0x57, 0x81, 0x74, 0x13, 0x69, 0xd7, 0x1d, 0xe9, 0x57, 0xb9, + 0x5a, 0xaa, 0xbe, 0x52, + 0xaf, 0x61, 0x95, 0xf4, 0x5f, 0x54, 0xbe, 0x40, 0x88, 0x91, 0x43, 0x44, + 0xd2, 0x59, 0xe3, 0x5d, + 0x99, 0x66, 0xb1, 0xd9, 0x2d, 0x75, 0xa9, 0x71, 0x1f, 0xd8, 0x4f, 0x3b, + 0x4e, 0xcb, 0x1b, 0xd2, + 0xcc, 0xf9, 0x2a, 0x53, 0xb2, 0xae, 0x10, 0x99, 0x3e, 0x92, 0xa4, 0x4b, + 0xc6, 0x15, 0xcf, 0xbc, + 0x7a, 0x64, 0xfa, 0x69, 0x2d, 0xfd, 0xdf, 0xf2, 0x99, 0x89, 0xa5, 0xd4, + 0x8e, 0xea, 0xaa, 0x63, + 0xa3, 0xf1, 0xc3, 0x64, 0x66, 0x5c, 0xfd, 0x2a, 0x69, 0x7e, 0xf2, 0x65, + 0x5e, 0x47, 0x09, 0x03, + 0x23, 0x41, 0x0e, 0x12, 0x4b, 0xa7, 0x8d, 0x37, 0x65, 0xaa, 0xc7, 0x66, + 0xd4, 0x8b, 0xb7, 0x54, + 0x9d, 0x4d, 0x3f, 0x65, 0x9c, 0x90, 0x93, 0xf4, 0x8d, 0x83, 0xab, 0xb1, + 0x57, 0x88, 0x2c, 0x19, + 0x23, 0x2f, 0xc8, 0x30, 0xce, 0xdb, 0x0a, 0xc3, 0xa9, 0x33, 0xd3, 0x25, + 0xfb, 0x8a, 0x67, 0x5f, + 0x1d, 0x72, 0xd0, 0x57, 0x2c, 0x27, 0xc5, 0xa1, 0xe6, 0x6a, 0xa3, 0x69, + 0xc9, 0x09, 0x3a, 0x3e, + 0x93, 0x9d, 0x40, 0x5d, 0xb1, 0x54, 0x52, 0xb1, 0x58, 0x2f, 0x8d, 0x2c, + 0x93, 0xa6, 0xc7, 0xe7, + 0xc0, 0xa3, 0xb2, 0x4d, 0x86, 0x86, 0xb2, 0x81, 0x97, 0xe7, 0x6c, 0x2c, + 0xfd, 0xa2, 0x29, 0x91, + 0x15, 0x43, 0x59, 0xf1, 0x79, 0xf6, 0x0c, 0x65, 0xfb, 0x8c, 0xeb, 0x26, + 0x65, 0x20, 0x24, 0xcb, + 0x2b, 0x72, 0x5a, 0x4e, 0xb0, 0x6f, 0xd5, 0xd6, 0xba, 0x6c, 0xd6, 0x6d, + 0x56, 0xc7, 0x48, 0x5b, + 0xd1, 0xf9, 0x9c, 0x23, 0x54, 0x27, 0xa7, 0x39, 0x53, 0x65, 0x88, 0xed, + 0x8a, 0xa1, 0xfc, 0x6e, + 0xbf, 0x6c, 0x91, 0xcd, 0x1a, 0x4d, 0xf2, 0x2a, 0x3a, 0xcd, 0x11, 0xfb, + 0x55, 0x50, 0xb8, 0x72, + 0xe4, 0xa2, 0x77, 0xa7, 0xec, 0x34, 0x57, 0xdb, 0x2e, 0x6b, 0xa9, 0x93, + 0xc6, 0x06, 0x1d, 0x9f, + 0x49, 0x74, 0xf9, 0xde, 0x45, 0xa8, 0x46, 0xe3, 0x36, 0xb8, 0xcb, 0xc1, + 0xd3, 0x46, 0x70, 0xee, + 0x1f, 0xa4, 0x31, 0x84, 0x3d, 0x3e, 0x03, 0xea, 0x36, 0xdd, 0x97, 0xc9, + 0x2a, 0x07, 0x90, 0x64, + 0x73, 0x1b, 0x34, 0xc9, 0x4a, 0x99, 0x27, 0xe5, 0xd8, 0x7d, 0x04, 0x67, + 0xcf, 0x04, 0x2c, 0x9d, + 0x7b, 0x5d, 0xe4, 0x0c, 0xa4, 0xe5, 0xfd, 0x72, 0x5c, 0x8e, 0x18, 0x67, + 0x64, 0xb2, 0x3b, 0xce, + 0xc2, 0x9d, 0x5d, 0x22, 0x0f, 0x18, 0x47, 0x8c, 0x43, 0x72, 0x98, 0xbd, + 0x6e, 0xac, 0x18, 0x72, + 0xa5, 0x3f, 0x06, 0x3e, 0x99, 0xe2, 0xa7, 0x97, 0xdb, 0xd0, 0xc8, 0xf5, + 0xf9, 0xb1, 0xa1, 0xdb, + 0x26, 0x9f, 0xb5, 0xde, 0x94, 0x87, 0xd0, 0x72, 0xb0, 0x9f, 0x4c, 0xa2, + 0xe2, 0x0b, 0xf9, 0xc1, + 0x7c, 0xbe, 0xd7, 0x0a, 0xb7, 0x23, 0x34, 0xd7, 0x69, 0x52, 0x88, 0x77, + 0x36, 0xbb, 0x71, 0x48, + 0x5a, 0x88, 0x44, 0x97, 0xdc, 0x06, 0xd6, 0x7b, 0xfe, 0xb2, 0x77, 0x90, + 0xbe, 0xc6, 0xaa, 0xd1, + 0xc4, 0x62, 0x16, 0x3c, 0xfd, 0x12, 0x3f, 0x59, 0xb2, 0x07, 0xcb, 0x1c, + 0x32, 0x4e, 0xca, 0xc4, + 0x9a, 0x8e, 0x89, 0xca, 0x66, 0x9d, 0xa7, 0x45, 0xc4, 0xbe, 0x6e, 0x6f, + 0x76, 0x34, 0x13, 0x67, + 0x0d, 0x70, 0x5d, 0x70, 0x85, 0x28, 0xe4, 0x4a, 0xc3, 0x2b, 0x5b, 0x3d, + 0xf7, 0xf1, 0x41, 0xab, + 0xfc, 0x51, 0xf2, 0xe8, 0x29, 0xbc, 0x62, 0x2a, 0x57, 0xbe, 0x9a, 0x90, + 0xb3, 0x56, 0xc9, 0x8f, + 0xe6, 0x5a, 0xdf, 0xc9, 0x51, 0xb9, 0x5b, 0xf2, 0x03, 0xae, 0xa5, 0xda, + 0x72, 0xb0, 0xd0, 0xa7, + 0xe8, 0xd7, 0xcb, 0x9b, 0xca, 0xe3, 0xaa, 0x27, 0x85, 0x59, 0xea, 0xf9, + 0x83, 0x0b, 0xad, 0x9c, + 0xfb, 0x9f, 0xc0, 0x66, 0x8a, 0xeb, 0x7c, 0xf4, 0x33, 0xd8, 0x47, 0xa2, + 0x40, 0xf8, 0x5a, 0x3f, + 0x7b, 0x9a, 0x43, 0x8c, 0x8e, 0x15, 0xc7, 0xcf, 0x2e, 0x69, 0x5b, 0xe4, + 0xc9, 0x6e, 0xfc, 0xaa, + 0xd9, 0x38, 0x26, 0xd5, 0x6e, 0x9b, 0xdd, 0x34, 0x71, 0x69, 0x6a, 0x8b, + 0x71, 0x80, 0x9c, 0xb9, + 0x5f, 0x8a, 0xd8, 0xcd, 0x8a, 0x2e, 0x8b, 0x62, 0xa0, 0xfe, 0x1d, 0xa7, + 0x33, 0x49, 0xab, 0x7c, + 0x6e, 0xa2, 0x55, 0xda, 0xe3, 0xf9, 0x81, 0x66, 0x78, 0xe7, 0xfd, 0x34, + 0x14, 0xc3, 0xfb, 0x48, + 0x59, 0x21, 0xdf, 0x9a, 0x6b, 0x7d, 0x45, 0x5e, 0xb8, 0x87, 0xd6, 0x60, + 0x34, 0xf3, 0xc8, 0x9c, + 0x1f, 0x11, 0x69, 0x17, 0xdd, 0x50, 0x36, 0x8b, 0xd0, 0x12, 0xa6, 0xd0, + 0xe7, 0xe5, 0xfa, 0x12, + 0x67, 0x9b, 0xfb, 0x89, 0x98, 0x22, 0xdd, 0x97, 0x43, 0xae, 0xb4, 0x4a, + 0x14, 0x1c, 0xad, 0x64, + 0xea, 0x61, 0x78, 0xd2, 0xb8, 0x9f, 0x20, 0x4b, 0xb1, 0x45, 0x2b, 0x97, + 0x87, 0x21, 0x3b, 0xd8, + 0x75, 0x0e, 0x18, 0x87, 0xa5, 0xb2, 0x16, 0x9b, 0x55, 0x87, 0xa5, 0xdc, + 0x56, 0x71, 0x32, 0x75, + 0xaf, 0xec, 0x25, 0xde, 0x97, 0xb2, 0x7e, 0x69, 0x50, 0x94, 0x81, 0x52, + 0x19, 0x2f, 0x25, 0x7a, + 0xad, 0x12, 0x3e, 0x95, 0x92, 0xd1, 0x93, 0xd0, 0xa2, 0xf7, 0x9e, 0x58, + 0xab, 0x74, 0x44, 0x8b, + 0xae, 0x91, 0xbe, 0x33, 0xc6, 0xb9, 0x65, 0x73, 0xcd, 0xf3, 0x8c, 0x08, + 0xbe, 0x8e, 0xff, 0x88, + 0x32, 0x68, 0x44, 0xc1, 0xe1, 0x25, 0x73, 0xad, 0xcf, 0x90, 0xe3, 0x7e, + 0xe8, 0x05, 0xa3, 0x95, + 0x0f, 0x6f, 0xff, 0x72, 0x3f, 0x13, 0x72, 0xd9, 0x4c, 0xd5, 0x91, 0x6a, + 0x6c, 0x06, 0x36, 0xfb, + 0xc6, 0xa4, 0xf3, 0x09, 0x67, 0x9f, 0x07, 0xd0, 0xbd, 0x8b, 0x8a, 0x8d, + 0x4a, 0xe3, 0xfb, 0x2b, + 0xbc, 0x03, 0xf8, 0x23, 0xd6, 0xcf, 0x80, 0x83, 0xc0, 0x72, 0x28, 0xb9, + 0x95, 0xb4, 0xe3, 0x03, + 0x68, 0xa3, 0xc8, 0xad, 0x8f, 0x62, 0xb7, 0x36, 0x4a, 0xff, 0x8d, 0x3e, + 0x4a, 0x89, 0xff, 0x6d, + 0xb2, 0x4f, 0xf6, 0x1a, 0xcd, 0x52, 0xae, 0x6a, 0x90, 0xea, 0xce, 0xa9, + 0x11, 0x25, 0xcd, 0x59, + 0x3b, 0xd9, 0xdb, 0xf7, 0x4b, 0x0d, 0x3b, 0x6c, 0x45, 0x10, 0x54, 0x72, + 0x95, 0xb3, 0x82, 0x50, + 0x31, 0x25, 0xe3, 0xb1, 0x69, 0xd8, 0xab, 0x10, 0xaf, 0x4c, 0x42, 0x2b, + 0xef, 0x9a, 0xf8, 0x5e, + 0x6e, 0x81, 0x97, 0x4a, 0x0d, 0x35, 0xab, 0x4c, 0x7b, 0x49, 0x26, 0xe3, + 0xe3, 0x75, 0xed, 0x36, + 0x86, 0xdc, 0x63, 0xc0, 0x69, 0x99, 0x9b, 0x66, 0x39, 0x1c, 0x15, 0x61, + 0xe5, 0x7c, 0x33, 0xa7, + 0x95, 0x68, 0x1e, 0x5c, 0xab, 0x95, 0x40, 0xcb, 0xd3, 0x33, 0x8e, 0xbe, + 0x18, 0x59, 0x2c, 0x1f, + 0x9b, 0x6b, 0x7d, 0x88, 0x9f, 0xfd, 0x4d, 0x53, 0x2a, 0x63, 0x64, 0xa1, + 0x39, 0x32, 0x9f, 0xb1, + 0xc5, 0x9a, 0xd7, 0x6c, 0xe9, 0x21, 0x37, 0x49, 0x07, 0x8d, 0x9b, 0xc1, + 0x7d, 0xd8, 0x4a, 0x71, + 0xa4, 0xb8, 0xb8, 0x68, 0xd2, 0x79, 0x5f, 0xce, 0xc9, 0x5f, 0x90, 0x64, + 0x9c, 0x5e, 0x5b, 0xd8, + 0xcf, 0xbe, 0xb4, 0x48, 0xa4, 0x70, 0xc9, 0x8d, 0x4f, 0xf1, 0x01, 0x6b, + 0xfb, 0x47, 0xb2, 0x4b, + 0x06, 0x6a, 0x69, 0x8a, 0xcd, 0xf5, 0x0b, 0xa1, 0x5f, 0xaa, 0xa5, 0xb2, + 0xe9, 0x3a, 0x3d, 0x9f, + 0xcf, 0x15, 0xa6, 0x36, 0x4a, 0xdc, 0xfa, 0x8b, 0xd7, 0x77, 0x64, 0x93, + 0xa8, 0x2e, 0x6c, 0x3a, + 0x4e, 0xca, 0x4d, 0x8d, 0x05, 0x42, 0x09, 0x75, 0xd7, 0x2e, 0xd9, 0x49, + 0x2e, 0x2c, 0xad, 0xb9, + 0x25, 0x91, 0x9a, 0x71, 0x74, 0x4d, 0xc1, 0xee, 0xbc, 0xed, 0x54, 0x61, + 0x5b, 0x99, 0x39, 0x31, + 0x28, 0x26, 0x40, 0x73, 0x1c, 0xd2, 0xa6, 0xf0, 0x79, 0x31, 0x15, 0x54, + 0x23, 0xdc, 0xc4, 0xea, + 0x3a, 0xfa, 0x23, 0x64, 0xf6, 0xe0, 0x92, 0x74, 0x41, 0x57, 0xae, 0xf1, + 0x55, 0x7c, 0xca, 0x65, + 0x44, 0x3a, 0xf5, 0xda, 0x22, 0xd9, 0x48, 0xfd, 0xb0, 0x89, 0x99, 0x55, + 0x50, 0x88, 0x25, 0x7f, + 0x96, 0xd2, 0xaa, 0xc6, 0x14, 0xf3, 0x39, 0x85, 0x2a, 0x4c, 0x21, 0x09, + 0xaf, 0x55, 0x3d, 0x13, + 0x98, 0x5f, 0x05, 0xa7, 0x79, 0xcc, 0x4d, 0xd4, 0x3d, 0x63, 0xb0, 0xbb, + 0xb0, 0xef, 0x2f, 0x40, + 0x53, 0x9e, 0xb5, 0xde, 0x26, 0x63, 0x3c, 0xc4, 0xb8, 0x4a, 0xf4, 0x94, + 0x61, 0xd2, 0x48, 0xe4, + 0xd3, 0x58, 0xb4, 0x53, 0xae, 0xf5, 0x1f, 0x47, 0x75, 0x38, 0x50, 0x9e, + 0x05, 0x83, 0xb0, 0x45, + 0xaa, 0xf6, 0xef, 0x5c, 0x72, 0x6c, 0x16, 0xda, 0xf7, 0xd0, 0xb9, 0xc0, + 0x09, 0xe7, 0x2f, 0xd0, + 0xce, 0x40, 0xa2, 0x32, 0x68, 0x8d, 0xc4, 0x2f, 0xce, 0x59, 0xf0, 0x31, + 0x19, 0x55, 0xdd, 0x8d, + 0x48, 0x86, 0xaf, 0x3d, 0x96, 0x79, 0x0a, 0x5f, 0xca, 0x3f, 0xb1, 0x93, + 0xb2, 0x4f, 0xaa, 0x7b, + 0xfd, 0x64, 0x5d, 0x83, 0xd9, 0xb0, 0x4a, 0xae, 0x4c, 0x41, 0xee, 0x32, + 0x56, 0x74, 0xc9, 0x53, + 0x8a, 0xb7, 0xc6, 0xe1, 0xeb, 0x65, 0x48, 0xb1, 0x01, 0x2b, 0x6c, 0x95, + 0x97, 0x64, 0x2a, 0x72, + 0xc5, 0x60, 0xc5, 0x12, 0xfa, 0x27, 0x04, 0xd5, 0x7d, 0x05, 0x9a, 0xdb, + 0x21, 0xdb, 0x8d, 0xbd, + 0x52, 0x8c, 0xcd, 0xc2, 0x67, 0x75, 0x89, 0x58, 0x23, 0x5b, 0xed, 0x8a, + 0xc2, 0x32, 0x66, 0xd5, + 0x04, 0xc5, 0x04, 0x38, 0x8b, 0xa6, 0xd6, 0x3d, 0x8f, 0xae, 0x2e, 0xf0, + 0xef, 0x9b, 0x68, 0xaf, + 0x45, 0xd7, 0xcc, 0xef, 0x51, 0x83, 0x79, 0xf0, 0xb1, 0x84, 0xa1, 0x2b, + 0xd7, 0xf8, 0xf1, 0xe8, + 0xcf, 0x4e, 0x2c, 0xbc, 0xa9, 0x67, 0x78, 0xf4, 0xa3, 0x3e, 0x6f, 0xd5, + 0xf7, 0x26, 0xca, 0xe0, + 0xa6, 0x1a, 0xc9, 0x8e, 0xa0, 0xb3, 0xe3, 0x6e, 0xbc, 0x41, 0x6b, 0x1e, + 0xed, 0x35, 0xf4, 0xe4, + 0xc9, 0x5c, 0x79, 0xdd, 0xec, 0x39, 0x2f, 0x93, 0xc8, 0x5a, 0xf3, 0x98, + 0xed, 0x59, 0xeb, 0x1c, + 0x72, 0x3f, 0xcc, 0xb8, 0x12, 0x7c, 0x60, 0xbb, 0x9c, 0x32, 0x47, 0x9e, + 0x24, 0x72, 0xd4, 0xee, + 0x57, 0x01, 0x85, 0x63, 0x8c, 0x3b, 0xe5, 0xc6, 0x05, 0xc6, 0xaa, 0x13, + 0x65, 0x33, 0x23, 0x4e, + 0xca, 0x19, 0x0b, 0xd7, 0x67, 0x98, 0x75, 0x02, 0x7a, 0x55, 0x68, 0xb5, + 0x08, 0x0b, 0x59, 0x25, + 0x3a, 0xcd, 0xce, 0xd5, 0x0e, 0xdf, 0x78, 0x4c, 0x1e, 0x91, 0xbb, 0xe4, + 0x77, 0xe8, 0xf9, 0xbc, + 0xa5, 0xef, 0x7d, 0xe4, 0xcf, 0x46, 0xef, 0xfb, 0x2d, 0xeb, 0xbf, 0x23, + 0x3d, 0xb1, 0xcd, 0x7e, + 0xfe, 0x7f, 0x0b, 0x7f, 0xce, 0xa3, 0x77, 0x32, 0x12, 0x95, 0xe9, 0xfb, + 0x28, 0x4d, 0x70, 0xf1, + 0x8e, 0xa9, 0x8d, 0xf3, 0xa2, 0xee, 0xed, 0x1e, 0x84, 0xdb, 0x18, 0xae, + 0x6a, 0xc6, 0x05, 0xd3, + 0xfd, 0x7a, 0x66, 0x6e, 0x31, 0x76, 0xca, 0x38, 0x6c, 0x16, 0xe6, 0xbc, + 0x3b, 0x62, 0x9b, 0x7d, + 0x23, 0x51, 0xb0, 0x59, 0x66, 0xe3, 0x17, 0x53, 0x03, 0xa0, 0x8e, 0xab, + 0x16, 0x2f, 0x89, 0x23, + 0x7f, 0xbe, 0x4e, 0xad, 0x76, 0xc4, 0xc4, 0x71, 0xd6, 0x2c, 0x83, 0x73, + 0x6f, 0xcb, 0x3b, 0xf2, + 0x27, 0x24, 0xaf, 0x63, 0x1d, 0x65, 0xb1, 0x25, 0x70, 0x75, 0xdc, 0xd2, + 0xeb, 0xc1, 0x09, 0xe6, + 0x4d, 0xc2, 0x27, 0x2b, 0x91, 0x25, 0x4b, 0x66, 0xa0, 0xb3, 0xa3, 0x6e, + 0xa8, 0xf3, 0xe1, 0x08, + 0x78, 0x9f, 0x8a, 0x04, 0xf1, 0xd8, 0xfb, 0x84, 0xbb, 0xfd, 0x18, 0x2b, + 0xdf, 0x43, 0x04, 0xcc, + 0x46, 0x37, 0x5e, 0x2a, 0xeb, 0xd0, 0x63, 0x29, 0xe3, 0x96, 0x6b, 0xbe, + 0x5c, 0x38, 0x8e, 0x1e, + 0x9f, 0x64, 0x9f, 0xab, 0x86, 0x7a, 0x32, 0xf6, 0x39, 0x6e, 0xf6, 0x9c, + 0x47, 0x02, 0x75, 0xd7, + 0x7b, 0xbf, 0xa6, 0xea, 0xcb, 0xd1, 0x31, 0xdd, 0x1f, 0x8f, 0x56, 0xcb, + 0xd8, 0x35, 0xcf, 0xf9, + 0xf4, 0x29, 0x99, 0xaa, 0x65, 0x1a, 0x98, 0x04, 0xb7, 0xd1, 0xf8, 0x95, + 0xb7, 0xef, 0x0d, 0xe8, + 0x25, 0x43, 0x75, 0xa7, 0xc9, 0xe9, 0x51, 0xc6, 0x77, 0x14, 0x75, 0x77, + 0x42, 0xf5, 0x9f, 0xe3, + 0xdc, 0x9f, 0x8a, 0xf6, 0x14, 0x2f, 0x53, 0x91, 0xfa, 0x44, 0x00, 0x6d, + 0x28, 0x7f, 0x5c, 0xcf, + 0xb8, 0x12, 0xb4, 0xe6, 0xd2, 0xb6, 0x3f, 0x6a, 0x64, 0x0d, 0x16, 0xda, + 0x68, 0x6c, 0x93, 0x82, + 0xda, 0x5b, 0x92, 0xba, 0xce, 0x78, 0x2a, 0xea, 0x65, 0xfb, 0x5a, 0xc7, + 0x5a, 0x66, 0xcd, 0x42, + 0x7b, 0x33, 0x03, 0x62, 0x06, 0x5a, 0xcc, 0x90, 0x85, 0xf0, 0xf3, 0x6a, + 0x1b, 0xbc, 0xe6, 0xf3, + 0xdb, 0x59, 0xf9, 0x33, 0x63, 0xa7, 0x63, 0x8b, 0x64, 0xe2, 0xf6, 0xb8, + 0xd9, 0x7e, 0x90, 0x1a, + 0xef, 0x08, 0xd7, 0x41, 0xb3, 0xe5, 0x04, 0xde, 0x93, 0x8e, 0x16, 0x4a, + 0xd0, 0xd1, 0x29, 0xb3, + 0xb5, 0x19, 0xe9, 0xfb, 0x41, 0x61, 0x06, 0x51, 0x92, 0x80, 0xdc, 0x9e, + 0xf6, 0xc3, 0x64, 0xd5, + 0x3f, 0x21, 0xbd, 0xd3, 0xb2, 0xde, 0x21, 0x32, 0xf4, 0xc3, 0x5a, 0x23, + 0x27, 0x2c, 0xf3, 0xcf, + 0xb1, 0x87, 0x75, 0x25, 0x5a, 0x66, 0x42, 0x7f, 0x0c, 0xb9, 0xac, 0xd9, + 0xec, 0x3b, 0xc9, 0x89, + 0x5a, 0x69, 0x78, 0xbb, 0xa5, 0xcd, 0x8a, 0x13, 0xf4, 0x67, 0xe1, 0x71, + 0xb1, 0x16, 0x7a, 0x2e, + 0x99, 0x6e, 0x83, 0x4f, 0xa5, 0x85, 0x5a, 0xb2, 0x5e, 0x86, 0x45, 0x2a, + 0x45, 0x33, 0x8a, 0xac, + 0x99, 0x44, 0xc4, 0xb7, 0x98, 0x6d, 0xc7, 0x90, 0xeb, 0x84, 0x65, 0xcd, + 0x74, 0xe4, 0xc9, 0xc1, + 0xe2, 0xc7, 0x03, 0xae, 0xea, 0xc2, 0x51, 0x59, 0x8b, 0x37, 0x4c, 0x64, + 0x54, 0x20, 0xfd, 0x4f, + 0xe3, 0x8c, 0xb3, 0x4e, 0xd6, 0x1a, 0x9b, 0xc5, 0x51, 0xd3, 0x29, 0xb1, + 0xcb, 0xb4, 0x11, 0xb1, + 0x9b, 0xed, 0x2b, 0x45, 0x61, 0x56, 0x10, 0x34, 0x60, 0x03, 0x55, 0x85, + 0x1d, 0x64, 0x1f, 0xbc, + 0x1c, 0x8e, 0xca, 0xed, 0x44, 0xeb, 0x34, 0x4e, 0x2d, 0xb5, 0x68, 0xc6, + 0xd3, 0xba, 0x1b, 0xfd, + 0x2e, 0x20, 0x67, 0xce, 0x87, 0xc6, 0x6e, 0xcb, 0xd8, 0x24, 0x72, 0xfd, + 0x64, 0x4e, 0x5d, 0x9b, + 0xd0, 0xad, 0xa7, 0xf5, 0x90, 0x0c, 0x65, 0xb5, 0xe9, 0x7a, 0x27, 0x7f, + 0xc5, 0x6c, 0x6d, 0x61, + 0x37, 0x7a, 0x8e, 0x5d, 0x62, 0x1a, 0x51, 0xe2, 0x69, 0xdb, 0x47, 0x1c, + 0xdf, 0x81, 0xcd, 0x5b, + 0x2c, 0xeb, 0x9c, 0x90, 0x07, 0xa5, 0x1b, 0x51, 0xd1, 0x08, 0xdf, 0x93, + 0xb1, 0xcf, 0x56, 0xcb, + 0x7a, 0x2d, 0xc4, 0x69, 0x2a, 0xb9, 0x78, 0x17, 0xda, 0x3b, 0xe4, 0xc3, + 0xf5, 0x1e, 0x1d, 0x1f, + 0xe7, 0xf4, 0x3e, 0x3b, 0x91, 0x68, 0x6b, 0xf6, 0xe9, 0x3d, 0x46, 0x5d, + 0x95, 0xaf, 0x2b, 0x3e, + 0x21, 0x6f, 0xd6, 0x5b, 0x38, 0x50, 0xdc, 0x0e, 0xc0, 0xce, 0xa9, 0xc4, + 0xc1, 0x1e, 0x0b, 0x17, + 0xbb, 0xcc, 0x55, 0x5b, 0x64, 0x14, 0x56, 0x2e, 0x46, 0x1f, 0x87, 0x2d, + 0xb3, 0x76, 0x6b, 0x1f, + 0x6e, 0xb1, 0xcc, 0xd9, 0x45, 0x4b, 0x0d, 0x23, 0xeb, 0xf0, 0xca, 0xb6, + 0x16, 0xa8, 0x27, 0x93, + 0x60, 0x21, 0x63, 0xbd, 0xd8, 0xb1, 0x59, 0xe7, 0xa9, 0x71, 0x71, 0xeb, + 0xec, 0xcb, 0x88, 0x89, + 0xa5, 0xe4, 0x9d, 0x40, 0x98, 0xc3, 0x35, 0x03, 0x49, 0x5f, 0x62, 0x17, + 0xdc, 0x6a, 0x62, 0x3b, + 0xfa, 0x6c, 0x61, 0x9d, 0x3d, 0x96, 0x36, 0x85, 0x83, 0x9c, 0x72, 0xeb, + 0xf4, 0xea, 0xbb, 0xcc, + 0xb6, 0x6d, 0x9c, 0x22, 0xba, 0xcb, 0x7f, 0xa2, 0xcb, 0x8e, 0x68, 0xf4, + 0x80, 0xd9, 0xbe, 0x03, + 0x4e, 0xa2, 0xb4, 0xef, 0x16, 0x22, 0x85, 0xa7, 0x75, 0x37, 0x96, 0xc9, + 0x81, 0x46, 0x1e, 0xeb, + 0x7a, 0x57, 0x3c, 0x2c, 0xe1, 0xec, 0x35, 0x0e, 0xfc, 0x61, 0xa7, 0xd9, + 0xf6, 0x32, 0x96, 0x79, + 0x1c, 0x7a, 0xdb, 0xcc, 0x75, 0x0e, 0xb1, 0xeb, 0xdc, 0x4a, 0x84, 0xce, + 0x85, 0xeb, 0x39, 0xe4, + 0x94, 0x34, 0xf6, 0xfa, 0x6d, 0xe6, 0xf8, 0x7d, 0x78, 0x47, 0x0e, 0x36, + 0x19, 0x2a, 0x37, 0xca, + 0x53, 0x16, 0x3e, 0xb6, 0xe3, 0x33, 0x37, 0x63, 0x97, 0x4e, 0xf2, 0x77, + 0xbd, 0xa3, 0x27, 0x92, + 0x93, 0xad, 0x32, 0xed, 0x97, 0xde, 0xfa, 0xe4, 0x9c, 0x8f, 0xd7, 0xcd, + 0xb1, 0xc8, 0xa5, 0xd0, + 0x42, 0x16, 0x2e, 0x64, 0xc7, 0x5a, 0xae, 0x6b, 0x38, 0xaf, 0xc4, 0xd6, + 0x35, 0xd5, 0x3d, 0xce, + 0x55, 0x96, 0xfe, 0x6d, 0x50, 0x4c, 0x93, 0x47, 0x39, 0x07, 0x6e, 0x41, + 0x06, 0xeb, 0x3a, 0xc3, + 0x89, 0xe7, 0x46, 0xad, 0x71, 0x5f, 0x34, 0x62, 0x1d, 0x6c, 0x64, 0xac, + 0x91, 0xbc, 0xda, 0x4e, + 0x89, 0x9d, 0x6a, 0xd3, 0x12, 0x56, 0xda, 0x17, 0x8b, 0xc2, 0x82, 0x20, + 0x98, 0x8f, 0x06, 0x33, + 0x58, 0x73, 0x9d, 0x89, 0x0d, 0xec, 0x7e, 0x0f, 0xc8, 0x7f, 0x53, 0x41, + 0xa7, 0xa2, 0xd7, 0x75, + 0x16, 0xec, 0x92, 0x7b, 0x89, 0x11, 0x55, 0x5d, 0x6c, 0x36, 0xdb, 0xb6, + 0x22, 0x53, 0x7b, 0x64, + 0x9e, 0x82, 0xff, 0x0f, 0x67, 0xc7, 0x6e, 0x32, 0x7b, 0xb6, 0x93, 0xc5, + 0xab, 0xd0, 0x52, 0x2c, + 0xa3, 0xd7, 0xbb, 0xdb, 0x36, 0x52, 0x67, 0x0c, 0xa3, 0x2d, 0x07, 0xcf, + 0xf2, 0xb4, 0x6d, 0xc2, + 0xfb, 0xee, 0x84, 0x8b, 0x22, 0x64, 0xda, 0x64, 0xe1, 0x62, 0x01, 0xb2, + 0x6c, 0x74, 0xff, 0xb6, + 0x1e, 0x4d, 0xdf, 0x4f, 0x66, 0x9e, 0x4a, 0x0e, 0x77, 0xf1, 0x3d, 0x83, + 0x75, 0xbd, 0x34, 0xd4, + 0x6a, 0x23, 0xb0, 0xfb, 0x1c, 0xec, 0x92, 0xc8, 0xce, 0xb6, 0xcd, 0x42, + 0x67, 0x39, 0x5c, 0x67, + 0x62, 0x97, 0x6a, 0xac, 0x3d, 0x4d, 0x47, 0xe7, 0x3a, 0x1f, 0xbc, 0x0c, + 0xcf, 0x0a, 0x5b, 0x2c, + 0xab, 0xbb, 0x78, 0x5d, 0x8a, 0x8f, 0xd4, 0x52, 0xd9, 0x2c, 0x82, 0xca, + 0x3a, 0x3f, 0xac, 0x67, + 0xf4, 0x2e, 0x6c, 0x96, 0x82, 0x57, 0x36, 0x59, 0xda, 0xf7, 0xb0, 0x5a, + 0x07, 0x2c, 0xd6, 0x97, + 0x9c, 0xbb, 0xce, 0x32, 0xaf, 0x09, 0x0e, 0x6c, 0x70, 0xb0, 0x30, 0x80, + 0x0d, 0xb4, 0x85, 0x8c, + 0x15, 0x32, 0x56, 0xd9, 0xac, 0x26, 0x2b, 0x71, 0xa9, 0xa1, 0x5a, 0x17, + 0x92, 0x69, 0x16, 0x07, + 0xc0, 0x12, 0x7a, 0x6a, 0xc8, 0x61, 0x6b, 0x90, 0xcc, 0x83, 0x2d, 0x9c, + 0x8b, 0xee, 0x85, 0xd3, + 0x5c, 0xf9, 0x07, 0xbe, 0xb7, 0xda, 0xd2, 0xb3, 0x59, 0xfe, 0x8a, 0xcd, + 0x0a, 0xf0, 0x8c, 0x95, + 0x66, 0xdb, 0x26, 0xec, 0xdb, 0x47, 0xdf, 0xcd, 0x53, 0x77, 0x79, 0x5f, + 0x44, 0x16, 0x4f, 0xcf, + 0x5a, 0x5a, 0x6d, 0xd8, 0x23, 0x85, 0x6b, 0xa5, 0x85, 0x46, 0x1f, 0x5d, + 0xe7, 0x7b, 0x57, 0xdc, + 0x28, 0x83, 0xd9, 0x17, 0xe6, 0x90, 0x9d, 0xaa, 0x7c, 0x56, 0x5b, 0x69, + 0x99, 0xb5, 0x16, 0x9e, + 0xd4, 0xbe, 0xf3, 0x12, 0x1c, 0xbb, 0xe0, 0xc4, 0xee, 0x8b, 0x64, 0x85, + 0x39, 0x62, 0x03, 0xbe, + 0x50, 0xa0, 0xa5, 0x9c, 0x42, 0x0e, 0x5c, 0x6b, 0xa1, 0xb2, 0x80, 0xaa, + 0x65, 0xb6, 0xce, 0x35, + 0x4b, 0xd8, 0x3d, 0x52, 0x2d, 0x7d, 0xff, 0x1e, 0x4d, 0x9c, 0x20, 0x5e, + 0x60, 0xef, 0xb0, 0xc3, + 0xdb, 0x4a, 0x9f, 0x9e, 0x55, 0xd8, 0x7d, 0x0d, 0x3e, 0x30, 0x15, 0x3f, + 0x49, 0xc1, 0x4b, 0x56, + 0x5b, 0x56, 0x5b, 0x2c, 0xff, 0xa7, 0x4f, 0x3f, 0x73, 0xe8, 0xb1, 0xea, + 0x75, 0x15, 0x5e, 0x16, + 0x41, 0x84, 0x2c, 0x69, 0x63, 0x89, 0x25, 0x2e, 0x3b, 0x1a, 0x4b, 0x25, + 0x5b, 0xc7, 0x59, 0x46, + 0xe2, 0x22, 0x43, 0x65, 0x92, 0xb9, 0x48, 0xb7, 0x2c, 0x00, 0x96, 0x33, + 0x63, 0x22, 0xd9, 0xdc, + 0x1b, 0x87, 0x8b, 0xe0, 0x32, 0x1c, 0xaf, 0x5f, 0x89, 0x7e, 0x6a, 0xd9, + 0x39, 0x97, 0x5a, 0xfc, + 0x61, 0x15, 0xf9, 0x45, 0xed, 0x66, 0x8d, 0x16, 0x6f, 0x59, 0x08, 0x1f, + 0x0b, 0x88, 0x9e, 0xb9, + 0x5c, 0xf3, 0xc1, 0x42, 0x0b, 0xa5, 0xa9, 0xd8, 0x70, 0x2e, 0x12, 0x64, + 0x41, 0xcb, 0xd3, 0xba, + 0x8c, 0x8c, 0x99, 0x48, 0xac, 0x2e, 0x31, 0x5b, 0x56, 0x10, 0x3f, 0xd5, + 0x70, 0x50, 0xee, 0xc3, + 0x87, 0x2f, 0x96, 0xe3, 0xb9, 0x39, 0x7a, 0xf6, 0x72, 0xf7, 0x35, 0x07, + 0xaf, 0xb2, 0xf2, 0xb1, + 0x9c, 0x1d, 0xb1, 0x98, 0x7f, 0x97, 0xc2, 0xa1, 0xcd, 0x42, 0x7d, 0x11, + 0x3b, 0xc6, 0x93, 0x8c, + 0x5e, 0xae, 0x67, 0x39, 0xa9, 0x19, 0x5e, 0x0a, 0x9a, 0x73, 0xac, 0x50, + 0x67, 0xa3, 0x1b, 0x91, + 0x60, 0x01, 0x59, 0x73, 0xa6, 0x4f, 0x74, 0x2c, 0xc1, 0x6f, 0x6f, 0x92, + 0xff, 0xa0, 0x16, 0xba, + 0x15, 0xff, 0x13, 0x7c, 0x7e, 0x91, 0xd9, 0xf7, 0x12, 0x5c, 0x0e, 0x40, + 0x8a, 0x15, 0x7c, 0x9a, + 0xc4, 0xe7, 0x97, 0x2c, 0x7c, 0x38, 0xf1, 0x81, 0xf9, 0x6e, 0x3e, 0xac, + 0x58, 0xe1, 0xca, 0xf6, + 0xc6, 0x42, 0xc9, 0xc0, 0x66, 0x9d, 0x6b, 0x13, 0xe3, 0xe7, 0x19, 0x6a, + 0x9f, 0x6b, 0xc4, 0x17, + 0x56, 0x06, 0xc0, 0x2a, 0x64, 0x9c, 0x80, 0xae, 0xe6, 0x30, 0xc2, 0x85, + 0xb9, 0xe8, 0xee, 0x51, + 0xf8, 0x5a, 0x0d, 0xad, 0x06, 0x32, 0xf3, 0x3c, 0xb3, 0xa7, 0x91, 0xd6, + 0x07, 0xe0, 0xd7, 0xa1, + 0xe9, 0x79, 0xe1, 0x9f, 0x9d, 0xbd, 0x58, 0x84, 0xb6, 0x16, 0xf0, 0x7f, + 0x14, 0x9f, 0x3c, 0x6d, + 0xf3, 0xd8, 0x21, 0xfa, 0xa1, 0xd7, 0xd9, 0xe6, 0x7a, 0x95, 0x44, 0xf5, + 0x42, 0xf8, 0xa8, 0x44, + 0xe7, 0x73, 0x7d, 0xe6, 0x5b, 0xb1, 0x10, 0x2a, 0xf5, 0x48, 0xe8, 0xe2, + 0x5a, 0x3d, 0x37, 0xb1, + 0xe1, 0xb9, 0xb3, 0x2d, 0x6b, 0x0d, 0x46, 0x8e, 0x55, 0x70, 0x3d, 0x83, + 0x28, 0xf6, 0x72, 0x3d, + 0x07, 0xff, 0x7b, 0x0a, 0x5d, 0xb9, 0x66, 0xcd, 0xc6, 0x7f, 0xe6, 0x05, + 0x5d, 0xc3, 0x3b, 0x47, + 0x9d, 0x87, 0xff, 0x8b, 0x3c, 0xba, 0x02, 0x99, 0x0b, 0xf9, 0x3c, 0xdb, + 0x22, 0xed, 0x3c, 0xf9, + 0x3d, 0xa7, 0xf8, 0x49, 0x7c, 0x9a, 0xcf, 0x55, 0xc2, 0x27, 0xaf, 0xf6, + 0x16, 0xe0, 0xe5, 0xf1, + 0x70, 0xa9, 0x22, 0x6f, 0x3a, 0x3b, 0xc5, 0x3c, 0xcb, 0xbc, 0x06, 0x2c, + 0x3c, 0xd7, 0xcd, 0x87, + 0x15, 0xab, 0xe9, 0xc3, 0x46, 0xc6, 0x3c, 0x49, 0xc3, 0x66, 0x5d, 0xa6, + 0x8e, 0x8c, 0x9b, 0x6d, + 0x9f, 0x81, 0x14, 0xf5, 0x96, 0xcc, 0xef, 0x9b, 0x95, 0x57, 0xe2, 0x27, + 0x85, 0x8c, 0x98, 0xe6, + 0xc6, 0x4c, 0x7e, 0x1b, 0x08, 0xdd, 0xf5, 0xe4, 0x90, 0xf9, 0xf8, 0xf2, + 0x54, 0xd6, 0xf6, 0xf4, + 0xcd, 0x26, 0x5b, 0x3a, 0xb1, 0x59, 0x9d, 0xd9, 0xe2, 0x9a, 0x51, 0x1f, + 0x10, 0x33, 0xe1, 0xf0, + 0x19, 0x7c, 0x6e, 0x99, 0xbe, 0xa7, 0xee, 0x59, 0x61, 0x3a, 0xd1, 0xfb, + 0x0c, 0x94, 0x3c, 0xb3, + 0x1b, 0x91, 0x3f, 0x12, 0x4e, 0x56, 0x52, 0x09, 0x5a, 0xf9, 0xf0, 0xc7, + 0x4c, 0x2c, 0x92, 0x0d, + 0xb5, 0x35, 0x5a, 0x92, 0xb5, 0x7c, 0x52, 0x1e, 0xee, 0xe5, 0xad, 0x01, + 0x3a, 0x15, 0xf4, 0xad, + 0xe1, 0x93, 0x4d, 0x57, 0xd0, 0x2e, 0xcc, 0x20, 0x8f, 0xf4, 0xc2, 0x06, + 0xeb, 0xf4, 0x3c, 0x25, + 0xd1, 0x4c, 0x3f, 0xca, 0x56, 0x9e, 0x9d, 0xcc, 0x9e, 0x47, 0x5b, 0x7f, + 0x2c, 0x96, 0x86, 0xc5, + 0xd6, 0xc3, 0xfd, 0x78, 0xbc, 0x7a, 0xba, 0x65, 0xf4, 0x58, 0xf2, 0xb4, + 0xca, 0xe8, 0x1b, 0xb8, + 0x96, 0xeb, 0xbb, 0x70, 0x5e, 0xae, 0xd5, 0x9b, 0x36, 0x39, 0x58, 0x61, + 0x03, 0x7c, 0xcc, 0x62, + 0xb7, 0xf0, 0xae, 0xa5, 0x28, 0x28, 0x0f, 0x6e, 0x6b, 0x83, 0x8d, 0xfa, + 0x1c, 0x36, 0xc3, 0x68, + 0x94, 0x94, 0xda, 0xce, 0xd4, 0xfa, 0x03, 0x62, 0x1a, 0xec, 0x75, 0x8e, + 0x3a, 0xb4, 0xbc, 0x81, + 0x9d, 0x67, 0x63, 0x1b, 0xa8, 0x5d, 0xb7, 0x8e, 0x8c, 0x5d, 0x83, 0xb7, + 0xb8, 0x50, 0x83, 0x4d, + 0x86, 0xb2, 0xea, 0x66, 0x66, 0xcc, 0xc7, 0x63, 0xbd, 0x3d, 0x93, 0x58, + 0xf7, 0x31, 0x74, 0x5c, + 0xc0, 0xbe, 0x33, 0xc9, 0x32, 0x3e, 0x5f, 0x3f, 0x1b, 0xf6, 0xc0, 0xfa, + 0x04, 0xd6, 0x86, 0xb6, + 0x96, 0xb1, 0x82, 0x93, 0xba, 0x7f, 0x8a, 0x39, 0x63, 0x0a, 0x55, 0x89, + 0xf7, 0x37, 0x27, 0x27, + 0xb3, 0x09, 0xec, 0xa1, 0x6b, 0x68, 0x33, 0x7c, 0x56, 0xf3, 0xc7, 0x14, + 0x72, 0xea, 0x14, 0xbc, + 0x69, 0xa3, 0x96, 0x64, 0xa9, 0xbe, 0x17, 0x32, 0xd9, 0xec, 0xad, 0x23, + 0x27, 0x4d, 0xa0, 0x67, + 0x03, 0x5e, 0x6f, 0xe5, 0x7a, 0x32, 0x79, 0xb8, 0x37, 0x5c, 0x6c, 0x42, + 0x22, 0x75, 0x77, 0x2d, + 0xcf, 0x6f, 0x8d, 0x5a, 0xf7, 0xb3, 0x6d, 0x17, 0xef, 0x31, 0x50, 0xf9, + 0xb3, 0xfc, 0x0f, 0x7b, + 0x40, 0xb1, 0xae, 0x8e, 0x36, 0xe1, 0x4b, 0xe5, 0x50, 0xf0, 0xae, 0xa3, + 0xf2, 0x7d, 0x8c, 0xae, + 0xd3, 0x14, 0xc5, 0x55, 0xb4, 0xe4, 0xfb, 0xf4, 0x46, 0x41, 0x65, 0xad, + 0xae, 0xba, 0x94, 0xef, + 0x58, 0xf9, 0xa8, 0xa4, 0xbe, 0x5e, 0xaa, 0x69, 0xfa, 0xda, 0xa0, 0x09, + 0x3f, 0xc0, 0x42, 0x46, + 0xbd, 0x8c, 0xc1, 0x66, 0x61, 0x33, 0x1e, 0x8d, 0x72, 0xda, 0x6b, 0x1c, + 0x6a, 0xe6, 0x06, 0xf6, + 0xcd, 0xa6, 0x36, 0xd8, 0x0a, 0x85, 0xd9, 0xac, 0x52, 0xa1, 0xef, 0xe0, + 0x95, 0xeb, 0x3b, 0xb8, + 0x25, 0xc4, 0xd9, 0x62, 0xc6, 0xaf, 0xc5, 0x4b, 0xf2, 0x2c, 0x3d, 0xe5, + 0x50, 0x79, 0x82, 0x1c, + 0xa4, 0xee, 0xe2, 0x7b, 0x5b, 0x6b, 0x38, 0x45, 0xdd, 0xc2, 0x19, 0xe0, + 0x5e, 0xae, 0xbb, 0xf9, + 0x7c, 0x3b, 0xf8, 0xb3, 0xc6, 0x9d, 0x72, 0x0f, 0x5c, 0x2b, 0x9e, 0x56, + 0xe0, 0xb3, 0x25, 0x96, + 0x39, 0x95, 0x96, 0x4f, 0xf9, 0xd4, 0x35, 0x2b, 0xa8, 0xf3, 0x36, 0xe0, + 0x11, 0xbe, 0xab, 0x95, + 0x63, 0x03, 0xdf, 0xdf, 0xab, 0xa8, 0x08, 0x17, 0xc0, 0xf1, 0x56, 0x4d, + 0x53, 0xdd, 0x39, 0xf7, + 0xf6, 0x4f, 0xa4, 0x52, 0x9b, 0x4c, 0xcf, 0x16, 0x46, 0xd8, 0x7c, 0xe4, + 0x29, 0xe4, 0x1c, 0xbe, + 0x50, 0xfb, 0xf3, 0x16, 0x74, 0x66, 0xf8, 0xd1, 0xac, 0x93, 0x76, 0x70, + 0x7d, 0x0f, 0xb8, 0x9b, + 0xeb, 0x21, 0xa8, 0x24, 0x63, 0xc7, 0x75, 0xee, 0x8a, 0xbe, 0x09, 0x2d, + 0x4c, 0xf0, 0x91, 0x77, + 0x02, 0x36, 0xcb, 0xd6, 0xf7, 0x13, 0x95, 0xf6, 0xd6, 0xeb, 0xb8, 0xab, + 0xb4, 0x70, 0x98, 0x06, + 0x8f, 0xab, 0xe9, 0x5b, 0x8f, 0x3c, 0x36, 0x1f, 0x99, 0x0d, 0x72, 0xf4, + 0xba, 0x00, 0x56, 0xd8, + 0xc1, 0xc8, 0xc9, 0x52, 0x63, 0x4c, 0x93, 0xc4, 0x9a, 0xce, 0x89, 0xe1, + 0xce, 0x3b, 0x22, 0x6a, + 0xed, 0xea, 0x3e, 0x64, 0x25, 0xfe, 0xb2, 0x93, 0xde, 0xb6, 0xd8, 0x86, + 0x1c, 0xd9, 0x3e, 0xcf, + 0x7a, 0xca, 0x38, 0x29, 0x96, 0x22, 0x79, 0x83, 0xbe, 0xef, 0x6e, 0xed, + 0x29, 0x47, 0xfa, 0xe5, + 0xda, 0x33, 0xbd, 0xad, 0xa5, 0x8c, 0xce, 0x42, 0x27, 0xcb, 0xb0, 0xf3, + 0x6c, 0xd6, 0x2e, 0xd5, + 0x99, 0xb0, 0x50, 0xdf, 0xab, 0x99, 0xaf, 0x6b, 0xf0, 0x1d, 0x68, 0xab, + 0x82, 0x6a, 0xbb, 0x24, + 0xc0, 0xb3, 0xa3, 0x72, 0x62, 0x20, 0x1e, 0xbe, 0x5f, 0x46, 0x0b, 0x33, + 0x7d, 0xe8, 0x16, 0xc1, + 0xf3, 0x5f, 0xc9, 0xa2, 0x15, 0x96, 0x96, 0x12, 0x38, 0x2d, 0xd0, 0xfa, + 0xdc, 0x41, 0x5c, 0xaa, + 0xb3, 0x6c, 0xb1, 0x85, 0xd2, 0x33, 0x78, 0xf9, 0xcb, 0xf4, 0x2d, 0xc1, + 0xf6, 0xc5, 0x96, 0xa7, + 0x59, 0x25, 0xf4, 0x94, 0x93, 0xa7, 0x57, 0x61, 0xed, 0x15, 0xcc, 0xf1, + 0xe5, 0xa0, 0x42, 0x1e, + 0x81, 0xfb, 0xd5, 0xf4, 0xae, 0x06, 0xeb, 0xe1, 0x63, 0x07, 0x54, 0x5e, + 0x36, 0xf5, 0xb3, 0x11, + 0x99, 0xc4, 0x47, 0xde, 0xe1, 0xd0, 0xdf, 0xa6, 0x47, 0xa8, 0x53, 0xc2, + 0x62, 0x2a, 0x51, 0xab, + 0x64, 0xa5, 0xe4, 0x55, 0xb5, 0x6b, 0x2d, 0xa2, 0xd5, 0xe1, 0x33, 0x2f, + 0x92, 0xca, 0x76, 0xab, + 0x85, 0xb2, 0x07, 0x7b, 0xe0, 0x7b, 0x82, 0x4c, 0x34, 0xa6, 0x48, 0x5c, + 0x4d, 0xe7, 0x84, 0x6e, + 0xb3, 0xc2, 0x22, 0xc6, 0x4b, 0xb5, 0xbd, 0x0a, 0x9e, 0x1b, 0x39, 0xd5, + 0xed, 0x0e, 0x88, 0x8d, + 0x58, 0x26, 0xcf, 0xe7, 0x69, 0x77, 0x01, 0xb9, 0xcc, 0x0e, 0xf2, 0xfc, + 0x9e, 0x82, 0x8f, 0xc3, + 0x53, 0xd6, 0x63, 0xe3, 0x31, 0x70, 0x63, 0xfd, 0x89, 0xc6, 0x53, 0x54, + 0xad, 0x51, 0xa5, 0xdf, + 0x05, 0x70, 0x68, 0xb8, 0x7e, 0xd6, 0x41, 0x7f, 0x0f, 0x7c, 0x2e, 0xc1, + 0x32, 0x8e, 0x00, 0xcf, + 0xd5, 0xc7, 0x51, 0x7b, 0xcd, 0x64, 0xcc, 0x5e, 0x6c, 0xdb, 0xa8, 0xef, + 0xee, 0x7b, 0x7e, 0xf2, + 0x99, 0xd1, 0x81, 0x88, 0x1f, 0xeb, 0x33, 0xaf, 0x80, 0xb5, 0x1a, 0xf4, + 0xdf, 0x32, 0x6e, 0x44, + 0x0b, 0x63, 0x2d, 0x3d, 0x85, 0xf2, 0x34, 0x5c, 0xa8, 0x3b, 0x14, 0x2b, + 0xe0, 0xc2, 0xf7, 0x0d, + 0x0a, 0xf5, 0x54, 0xc9, 0x86, 0x2f, 0x2a, 0xbb, 0x14, 0xfa, 0xf5, 0x8d, + 0x93, 0x9e, 0xd8, 0x69, + 0x9f, 0xec, 0x35, 0xb1, 0xc7, 0x47, 0x3b, 0x4d, 0xe4, 0xe3, 0x5c, 0x1f, + 0x0e, 0x9e, 0x83, 0xfe, + 0x2e, 0xf7, 0xa8, 0x9d, 0xf0, 0x91, 0xeb, 0xd3, 0xef, 0x20, 0xd2, 0x32, + 0xf5, 0x53, 0x92, 0x5c, + 0x9f, 0x75, 0xc6, 0xcb, 0x7d, 0x5c, 0x7b, 0xfc, 0xa8, 0x2b, 0xbc, 0x42, + 0x14, 0x54, 0x48, 0x95, + 0x31, 0x49, 0x62, 0x6a, 0xbb, 0x24, 0x76, 0x9b, 0xd5, 0x39, 0x22, 0xa9, + 0xa0, 0x2a, 0xaf, 0x4c, + 0x3f, 0xe5, 0x69, 0x81, 0xb3, 0xb6, 0xd8, 0x8f, 0xb6, 0x1a, 0xd0, 0x44, + 0x9e, 0xcf, 0x4e, 0x94, + 0x1b, 0xf0, 0x0d, 0x21, 0x3b, 0xfb, 0xd3, 0x16, 0x7d, 0x3a, 0x1c, 0x63, + 0x19, 0x91, 0xab, 0xdf, + 0x99, 0xb2, 0x41, 0xc1, 0xfa, 0xb6, 0x52, 0x1e, 0xbc, 0x3f, 0x48, 0xc6, + 0x53, 0x2b, 0xec, 0xd5, + 0x92, 0xb5, 0x7d, 0xdf, 0x2b, 0x0f, 0xdf, 0xf8, 0x3b, 0xde, 0xbf, 0x1f, + 0xec, 0xc4, 0x3b, 0xd3, + 0x7c, 0xfa, 0x62, 0xe5, 0x79, 0xfd, 0xac, 0xd8, 0xee, 0xf7, 0x7e, 0x56, + 0x0a, 0x9a, 0xdf, 0xc5, + 0x8e, 0x51, 0x4e, 0xdd, 0xee, 0xcb, 0x5b, 0xbd, 0x96, 0x68, 0x9d, 0x7e, + 0x8f, 0x67, 0xac, 0x9f, + 0x3c, 0x79, 0xc4, 0xc7, 0x34, 0x3c, 0xae, 0xc8, 0xef, 0x9d, 0x2a, 0x97, + 0x4c, 0x07, 0x02, 0xea, + 0x46, 0x61, 0x3b, 0x9e, 0x90, 0xe9, 0x33, 0x7e, 0x20, 0xf2, 0xef, 0x85, + 0x63, 0x57, 0xff, 0xcb, + 0xd4, 0x0f, 0xa3, 0x7d, 0xb4, 0x97, 0xa7, 0xdf, 0xfc, 0xf2, 0xdf, 0xd9, + 0x53, 0x38, 0x5f, 0xae, + 0x34, 0x67, 0x59, 0xd1, 0xcc, 0x9e, 0x33, 0x5e, 0xca, 0x8c, 0x2a, 0x89, + 0xc2, 0x66, 0xed, 0xaa, + 0xbb, 0xa6, 0xf6, 0x2e, 0xa9, 0xcc, 0x2a, 0xd1, 0x4f, 0xe3, 0x76, 0x06, + 0xbc, 0x7b, 0x7a, 0x10, + 0x3a, 0x4d, 0xfa, 0xee, 0x6a, 0x46, 0x80, 0xb7, 0x34, 0xd5, 0xfb, 0x8c, + 0xde, 0xdf, 0xb2, 0xf0, + 0xe5, 0xed, 0xac, 0xb2, 0x06, 0x4d, 0xa6, 0x59, 0xc6, 0x67, 0x04, 0x98, + 0x6b, 0xc0, 0x63, 0x12, + 0xba, 0x70, 0xad, 0xb2, 0x8b, 0xbc, 0x19, 0xd9, 0x66, 0x54, 0x0e, 0xb9, + 0x36, 0x01, 0x3f, 0x3b, + 0x08, 0xf6, 0x92, 0xa1, 0x92, 0x2d, 0x7d, 0x99, 0x9c, 0x40, 0x63, 0xc9, + 0x41, 0xe3, 0x65, 0xa4, + 0x7e, 0x27, 0xd1, 0xbb, 0x56, 0x2c, 0x1e, 0xb8, 0x0d, 0x3d, 0x57, 0xe1, + 0x39, 0x5e, 0x8a, 0xd9, + 0xe4, 0x80, 0x06, 0xbd, 0x56, 0x13, 0x76, 0x49, 0x69, 0xc3, 0x4f, 0x36, + 0xb6, 0x99, 0x88, 0x7f, + 0x8c, 0x27, 0x97, 0xa5, 0xb7, 0x91, 0xe9, 0x60, 0xd0, 0xfb, 0xbb, 0x3b, + 0xf5, 0x5d, 0x01, 0x2b, + 0x9d, 0x7e, 0xc4, 0xea, 0x2b, 0xee, 0x19, 0x07, 0xf5, 0x5b, 0x5c, 0xe9, + 0x54, 0x25, 0x99, 0x41, + 0xdf, 0x74, 0x4d, 0xd7, 0xef, 0x7d, 0xa9, 0x7b, 0x45, 0x07, 0x02, 0xae, + 0x73, 0x84, 0xd3, 0x29, + 0x79, 0xdf, 0x28, 0x97, 0xc8, 0xda, 0x2e, 0x09, 0xed, 0xaa, 0xc3, 0x53, + 0xfe, 0x54, 0x51, 0x99, + 0x5a, 0xa8, 0xdf, 0x91, 0x99, 0xab, 0xef, 0x9e, 0xb6, 0x45, 0x0b, 0x56, + 0x9b, 0x43, 0xa5, 0x9c, + 0xae, 0x9f, 0xfc, 0x59, 0x91, 0xca, 0x6a, 0x03, 0xb0, 0x8e, 0xf7, 0xf7, + 0x7e, 0xfa, 0xce, 0xe8, + 0x7e, 0x3c, 0xb6, 0xa7, 0x7e, 0x4a, 0x96, 0x1c, 0x10, 0xea, 0x5e, 0xed, + 0xdf, 0xe5, 0x7e, 0xf6, + 0xef, 0xc3, 0xee, 0x35, 0x5e, 0x25, 0xd2, 0xd4, 0x73, 0x6c, 0xdf, 0x71, + 0x59, 0xd4, 0x2b, 0x33, + 0xf4, 0x98, 0xc3, 0xfa, 0xdd, 0x87, 0x31, 0x96, 0x11, 0xea, 0x3d, 0xc4, + 0x44, 0xfc, 0x63, 0x33, + 0x36, 0x4b, 0xf4, 0xe3, 0x6c, 0x34, 0xf9, 0x6f, 0x33, 0xde, 0x19, 0x6f, + 0x69, 0x4b, 0xc3, 0x66, + 0xf3, 0xe0, 0xed, 0x10, 0xd9, 0xa7, 0x11, 0x7b, 0xfb, 0xf3, 0x96, 0x06, + 0xc7, 0xb5, 0xe8, 0xb7, + 0x42, 0x3f, 0xb9, 0x4c, 0xf6, 0x93, 0xe9, 0x70, 0x40, 0xcd, 0x28, 0xec, + 0x45, 0x37, 0x49, 0x3e, + 0x74, 0xfa, 0x60, 0xf7, 0x66, 0xcb, 0x8c, 0x03, 0x44, 0xf6, 0x20, 0xea, + 0xc5, 0xb6, 0xfa, 0xf3, + 0xcc, 0xc8, 0xa5, 0x4a, 0x7b, 0x9a, 0x88, 0x0c, 0xbc, 0xc2, 0x09, 0x5d, + 0x89, 0x15, 0x1a, 0x25, + 0x32, 0x4a, 0xc5, 0x99, 0x7a, 0xef, 0x6a, 0x52, 0x4a, 0x72, 0x81, 0xe1, + 0xd0, 0xf7, 0x60, 0x8f, + 0xb6, 0x79, 0xb2, 0xe4, 0xc2, 0x6b, 0xac, 0x5b, 0x23, 0xff, 0xa4, 0xe2, + 0x49, 0x32, 0xff, 0xe6, + 0x25, 0x41, 0x3f, 0x85, 0xf8, 0x03, 0x3b, 0x74, 0x9a, 0x65, 0xfd, 0xe7, + 0x18, 0x79, 0x54, 0x8f, + 0x9f, 0xce, 0x59, 0x6d, 0x28, 0x2d, 0x49, 0x8c, 0x8c, 0xb7, 0xcc, 0x4a, + 0x42, 0x0b, 0x51, 0xd2, + 0x89, 0x2a, 0x6c, 0x05, 0x94, 0x8f, 0x9a, 0x2b, 0xec, 0x23, 0x2e, 0x22, + 0x7d, 0x64, 0x51, 0x6f, + 0xaa, 0x3f, 0x84, 0x24, 0x47, 0xf5, 0xb8, 0x16, 0xf2, 0xa8, 0x7a, 0x56, + 0xe5, 0xed, 0x7d, 0x1e, + 0x8f, 0x79, 0x0d, 0xcf, 0x9c, 0x23, 0x43, 0x7c, 0xb4, 0x96, 0x0c, 0x9f, + 0x45, 0x44, 0x5a, 0x3d, + 0x19, 0xdd, 0xaa, 0xfb, 0xde, 0x9c, 0xc2, 0x8e, 0x6a, 0x4a, 0x3b, 0xe1, + 0x64, 0x84, 0x7e, 0x47, + 0xc2, 0xf3, 0x57, 0x20, 0x49, 0xd0, 0xeb, 0xcd, 0xce, 0xa9, 0xf6, 0xfb, + 0x68, 0x3f, 0x9d, 0xba, + 0x64, 0x3a, 0x12, 0x10, 0xea, 0xf9, 0xd4, 0x0a, 0x1f, 0x6f, 0x4b, 0xa5, + 0xb2, 0xac, 0xb6, 0x48, + 0xa6, 0x64, 0x6b, 0xa1, 0x32, 0x53, 0x7f, 0x77, 0x9e, 0xc8, 0xb8, 0x44, + 0x1f, 0x6d, 0xa8, 0xb7, + 0x34, 0x86, 0x72, 0x76, 0x18, 0x80, 0x8f, 0x05, 0x5b, 0xe3, 0x0c, 0x3b, + 0xad, 0x5d, 0x1c, 0x46, + 0xa1, 0xbc, 0xa8, 0xe2, 0x4c, 0xfd, 0x9d, 0xe0, 0xb4, 0xee, 0x31, 0x85, + 0x76, 0x9b, 0x43, 0xbd, + 0xc5, 0xb9, 0x5a, 0xce, 0x62, 0xd5, 0x40, 0x50, 0xbc, 0x55, 0xa3, 0xc1, + 0x1e, 0x44, 0xb9, 0x4b, + 0xc6, 0x68, 0xe2, 0xe4, 0x77, 0xc8, 0x93, 0xcd, 0x09, 0xf2, 0x2e, 0x5d, + 0xc7, 0xdf, 0xcd, 0xff, + 0xf1, 0x70, 0x78, 0x52, 0x8f, 0x57, 0xcf, 0x5f, 0x9e, 0xa5, 0x9e, 0xef, + 0x81, 0xd7, 0x7b, 0xfe, + 0xc2, 0x63, 0x0c, 0x9f, 0x9f, 0x92, 0xce, 0xf2, 0xbf, 0xe8, 0x7b, 0x8d, + 0x0f, 0xfd, 0xe3, 0xf8, + 0xe5, 0x26, 0x22, 0xe7, 0x2e, 0x93, 0x96, 0xaa, 0xac, 0xbb, 0xe0, 0x47, + 0x47, 0x4c, 0x0e, 0xf6, + 0xe1, 0x8f, 0xf7, 0x59, 0xfa, 0xef, 0xc2, 0x32, 0xa7, 0xe4, 0x18, 0x51, + 0x5d, 0x8a, 0x7f, 0x78, + 0xdb, 0x55, 0xcf, 0x20, 0xe2, 0x76, 0x35, 0xff, 0xde, 0x69, 0xb6, 0xdd, + 0x29, 0x8f, 0xd2, 0xa6, + 0x78, 0x3b, 0xc6, 0x5a, 0x6b, 0xb1, 0xf3, 0xed, 0xcc, 0xea, 0xa5, 0xff, + 0x8e, 0x7f, 0x00, 0xa7, + 0xd9, 0xee, 0xf2, 0x00, 0xb5, 0xdc, 0x21, 0xb4, 0xdb, 0xd3, 0x32, 0xcb, + 0x2a, 0x53, 0x60, 0xbc, + 0x86, 0x57, 0x45, 0x5b, 0xf8, 0xbe, 0x4b, 0xfe, 0xc2, 0x19, 0xd8, 0x77, + 0xfc, 0x31, 0x46, 0x6d, + 0xc1, 0x93, 0xd4, 0x59, 0x61, 0xa8, 0xe9, 0x27, 0x63, 0xf0, 0xc9, 0x27, + 0xf4, 0x1b, 0x2b, 0xc9, + 0xfa, 0x39, 0x52, 0x30, 0x9c, 0xd7, 0x6f, 0x69, 0xd8, 0x88, 0xab, 0x11, + 0xb5, 0x5d, 0x13, 0x5c, + 0xef, 0x11, 0x87, 0x8d, 0xca, 0x34, 0x72, 0x0d, 0xf5, 0xde, 0x73, 0x36, + 0xfd, 0x67, 0x7c, 0x9e, + 0xac, 0x7b, 0x71, 0x12, 0xad, 0x6d, 0x60, 0xbd, 0x7b, 0x24, 0x0c, 0xad, + 0xb7, 0x97, 0x9b, 0xf1, + 0x9c, 0x3a, 0x72, 0x80, 0xaa, 0x38, 0x5c, 0x3b, 0x96, 0x7a, 0xb3, 0x76, + 0xb5, 0xf9, 0xdc, 0xfe, + 0x14, 0x9f, 0x0e, 0xea, 0xea, 0xe5, 0x3e, 0xc6, 0x87, 0x11, 0x59, 0x1d, + 0xe5, 0x46, 0xfe, 0x7d, + 0x8c, 0x91, 0x4b, 0xb1, 0xd1, 0xeb, 0x7e, 0x2b, 0x9d, 0x82, 0xfe, 0x72, + 0x76, 0xb0, 0x74, 0xf7, + 0x3b, 0xd9, 0x8a, 0x5e, 0x11, 0x7e, 0xef, 0xed, 0x3f, 0x46, 0x85, 0x60, + 0x33, 0xfb, 0xb3, 0xc8, + 0xff, 0x4d, 0x50, 0x39, 0x0d, 0xad, 0x83, 0xec, 0x44, 0x19, 0x26, 0x32, + 0xf5, 0xb3, 0x4b, 0xf5, + 0xd4, 0xae, 0xde, 0xa7, 0x6d, 0x2a, 0xb6, 0xf2, 0xd0, 0x3a, 0xce, 0x8e, + 0x53, 0x8f, 0xae, 0xfa, + 0xcb, 0xe3, 0xd8, 0xf2, 0x51, 0xec, 0x34, 0x80, 0xda, 0x60, 0x1f, 0x3d, + 0x2d, 0xfa, 0x59, 0x92, + 0x97, 0x07, 0xab, 0x4c, 0x81, 0xa0, 0x9e, 0x9c, 0x2f, 0xd6, 0xbb, 0xba, + 0x67, 0x46, 0x25, 0xf9, + 0xf2, 0x4c, 0xc0, 0x71, 0x6b, 0xd0, 0xf0, 0x13, 0xd2, 0x15, 0x74, 0x46, + 0x13, 0x37, 0x92, 0x11, + 0x7b, 0xb0, 0xea, 0x26, 0xe8, 0xbf, 0x1e, 0x94, 0xfe, 0x69, 0x79, 0x1b, + 0x3d, 0x64, 0xc9, 0x58, + 0xc3, 0x26, 0xc3, 0xdc, 0x36, 0x53, 0x75, 0x48, 0x9f, 0xa2, 0xbc, 0x9c, + 0x2c, 0xfd, 0xf6, 0xfd, + 0x62, 0x79, 0x57, 0xce, 0x06, 0xc1, 0xeb, 0xfa, 0xfd, 0x8c, 0xdd, 0x68, + 0x76, 0x0e, 0x1e, 0xd9, + 0x84, 0xef, 0xb8, 0x5a, 0xcf, 0xb8, 0x39, 0x54, 0xfd, 0x67, 0xf5, 0xe5, + 0x9d, 0x71, 0x06, 0x4d, + 0xef, 0x45, 0xd7, 0xf3, 0xf5, 0x9d, 0xc3, 0xe5, 0xfa, 0x29, 0xb1, 0x7a, + 0x97, 0xe3, 0x8d, 0x00, + 0xf4, 0xcf, 0x58, 0x68, 0x9d, 0xd6, 0xbf, 0x9d, 0xf5, 0xa1, 0x77, 0xc6, + 0x0d, 0x57, 0xef, 0x19, + 0x68, 0x78, 0x56, 0xb4, 0xce, 0x73, 0xf5, 0xf9, 0x8e, 0xf6, 0x50, 0x7b, + 0xdd, 0x4f, 0x1a, 0xa5, + 0xc7, 0x66, 0xbd, 0xef, 0x1f, 0xc2, 0x63, 0x4e, 0xb9, 0xe9, 0x58, 0x69, + 0xb5, 0x95, 0xa9, 0xad, + 0x56, 0xac, 0x7c, 0xab, 0xcf, 0x6f, 0x04, 0x19, 0xaf, 0x68, 0x29, 0x3f, + 0xde, 0xe2, 0x7e, 0x5a, + 0xb9, 0x4c, 0x3f, 0xf3, 0x3b, 0x13, 0x50, 0x17, 0x56, 0xbc, 0x47, 0xb5, + 0x41, 0x2d, 0x44, 0x54, + 0x0d, 0x31, 0x6d, 0xd6, 0x2d, 0xa5, 0x6b, 0x55, 0x46, 0x6a, 0xba, 0x91, + 0xa6, 0xdf, 0x1e, 0x3a, + 0x8a, 0x5d, 0xcf, 0x07, 0xc4, 0x05, 0x0d, 0xf5, 0xde, 0xc9, 0x3b, 0xfa, + 0x0d, 0x95, 0xb7, 0xdc, + 0x2d, 0x6f, 0x5a, 0x70, 0x41, 0xbf, 0xe1, 0x63, 0x1d, 0xff, 0xa6, 0x7e, + 0x8b, 0xc7, 0x35, 0x47, + 0xfd, 0xff, 0x96, 0xdf, 0x28, 0x5f, 0xfa, 0x6f, 0x06, 0xa5, 0x76, 0x3e, + 0xe0, 0x5a, 0x17, 0x7c, + 0xd6, 0xf1, 0xef, 0xbb, 0x12, 0xde, 0xde, 0x72, 0x23, 0xd8, 0xac, 0x60, + 0xdc, 0xb6, 0xa5, 0x74, + 0xb9, 0xf1, 0xde, 0x15, 0x5d, 0xda, 0x78, 0x47, 0x6b, 0xe3, 0xc2, 0x65, + 0xe8, 0x9f, 0x97, 0x0f, + 0xc9, 0x64, 0x54, 0x2a, 0x46, 0xa6, 0x0c, 0xf6, 0xd8, 0xcc, 0xbd, 0xa7, + 0x65, 0xda, 0x93, 0x1d, + 0xc9, 0xd8, 0xcc, 0x2e, 0x9f, 0x6a, 0x5a, 0x21, 0xfc, 0x56, 0xf0, 0x29, + 0xf5, 0x21, 0xb5, 0x17, + 0x31, 0x35, 0xb0, 0xc6, 0x6b, 0xb3, 0x6e, 0xb3, 0xba, 0x46, 0x8c, 0x74, + 0x8c, 0xb1, 0xab, 0x9d, + 0x31, 0x82, 0xea, 0xe9, 0x22, 0xf1, 0xf8, 0xf3, 0xe1, 0x03, 0xf9, 0x38, + 0xf4, 0x4d, 0x11, 0xd7, + 0x80, 0xef, 0xd8, 0xc5, 0xe3, 0x24, 0xd1, 0x18, 0x23, 0x03, 0x2c, 0x71, + 0xa6, 0xce, 0x69, 0xb7, + 0x97, 0x8f, 0x49, 0x8b, 0x33, 0xe2, 0xe8, 0x7d, 0x41, 0x56, 0xc9, 0xd7, + 0xf2, 0x2f, 0x74, 0xfd, + 0x73, 0xe0, 0x13, 0x72, 0xc0, 0x0a, 0x7d, 0xaf, 0x2e, 0x84, 0x9f, 0x86, + 0x4d, 0xfa, 0x6f, 0x3d, + 0xe3, 0x8c, 0x44, 0xe9, 0x67, 0xb5, 0x19, 0xe8, 0x3a, 0xed, 0xb1, 0x98, + 0x04, 0x7b, 0xb4, 0x43, + 0xfd, 0x65, 0xe4, 0x10, 0x2a, 0x8c, 0x6f, 0x88, 0x8e, 0x8f, 0xae, 0x19, + 0x17, 0xc9, 0xc6, 0x71, + 0x32, 0x8c, 0xda, 0x3e, 0x84, 0x9f, 0x8e, 0xd1, 0x54, 0xdf, 0xd1, 0xc4, + 0x53, 0x9f, 0xda, 0xb0, + 0x78, 0x9f, 0xef, 0x9a, 0x20, 0x3f, 0xf6, 0x2d, 0x88, 0xc9, 0x55, 0xdf, + 0xa4, 0x13, 0x81, 0x96, + 0xd7, 0x49, 0xab, 0x7c, 0x46, 0x2e, 0xbd, 0x16, 0xa8, 0x68, 0x4d, 0x22, + 0x6e, 0x23, 0x43, 0xb8, + 0x76, 0x18, 0xd1, 0xf2, 0x4c, 0x6d, 0x58, 0x82, 0xff, 0xf7, 0xff, 0x75, + 0x9d, 0x34, 0x78, 0x4c, + 0xa4, 0xe1, 0xfa, 0xe6, 0xaa, 0x7e, 0x9c, 0xad, 0xd4, 0x77, 0xc4, 0x7d, + 0xfe, 0x13, 0x71, 0x51, + 0x7e, 0xe4, 0x3c, 0x38, 0x44, 0x46, 0xb8, 0xbf, 0x0b, 0x2b, 0xd2, 0x1e, + 0xe9, 0x08, 0x5d, 0xd7, + 0x70, 0xd9, 0xa2, 0x1c, 0x6d, 0x6c, 0xa6, 0x63, 0x2d, 0x7c, 0xd4, 0x73, + 0x32, 0xca, 0xfe, 0x82, + 0x28, 0x0c, 0xe4, 0x04, 0xf8, 0xa5, 0xfe, 0x0b, 0xba, 0x2f, 0xae, 0x1a, + 0xdf, 0x32, 0x6f, 0x89, + 0x0c, 0xc6, 0x62, 0x8a, 0xd2, 0x8b, 0xf6, 0x91, 0xd2, 0xab, 0xac, 0x57, + 0x7a, 0xaf, 0xf2, 0x5f, + 0xfb, 0x7a, 0x2a, 0xbd, 0x7b, 0x45, 0xf7, 0xb4, 0xee, 0xe5, 0xbd, 0xd2, + 0x2e, 0x37, 0xb6, 0x67, + 0x39, 0xe3, 0x18, 0xdb, 0xd3, 0x6c, 0x7b, 0x32, 0xfd, 0x91, 0xca, 0x47, + 0x52, 0x1f, 0xa9, 0xe8, + 0xc1, 0xdc, 0x9e, 0xf4, 0xf7, 0xcc, 0xe8, 0xf9, 0x4b, 0xca, 0x54, 0xd6, + 0x3b, 0xfd, 0xe1, 0xba, + 0xf0, 0x98, 0x40, 0xdf, 0xb5, 0x19, 0x36, 0xe9, 0xd9, 0xa4, 0x17, 0xec, + 0xc3, 0x1d, 0xc3, 0x65, + 0xb8, 0x0c, 0x92, 0x01, 0xd4, 0x23, 0xea, 0xef, 0x51, 0xbf, 0xba, 0x0a, + 0xa8, 0xbf, 0x83, 0x3d, + 0x2b, 0x29, 0xd2, 0x87, 0x0c, 0x0b, 0x15, 0x03, 0xbb, 0x95, 0xdd, 0x93, + 0xde, 0xb5, 0x21, 0x2c, + 0x22, 0x2c, 0x74, 0x5d, 0xf3, 0x15, 0xf0, 0xfb, 0x36, 0x89, 0xb5, 0x5e, + 0x05, 0x2f, 0xd8, 0x86, + 0x1a, 0x43, 0xf5, 0x77, 0x04, 0x3c, 0xad, 0x9f, 0x98, 0xb4, 0xea, 0xbf, + 0x66, 0xfd, 0xe6, 0x32, + 0xf8, 0xd6, 0xfd, 0x2d, 0xaa, 0xd5, 0xd8, 0x6b, 0xa0, 0x0c, 0xd5, 0x18, + 0x0e, 0x9d, 0xbb, 0x66, + 0x86, 0x8f, 0x0e, 0x7d, 0x33, 0xe6, 0xf5, 0xfd, 0x5e, 0xdb, 0xae, 0x75, + 0xff, 0x88, 0x1b, 0x6a, + 0x1b, 0x22, 0xcf, 0x81, 0xc1, 0xc4, 0x5a, 0x0f, 0xf6, 0xb7, 0x55, 0x3a, + 0x4f, 0xba, 0x6c, 0xd7, + 0xf6, 0x1b, 0xa4, 0x3d, 0xdf, 0x4f, 0x7c, 0x58, 0xf2, 0x19, 0xdd, 0x97, + 0x59, 0x6a, 0xee, 0x73, + 0xf6, 0x61, 0x8e, 0xbe, 0x13, 0xc3, 0x93, 0xc2, 0xab, 0x43, 0xdf, 0x6f, + 0x7b, 0xdd, 0xbf, 0xdb, + 0x96, 0x58, 0xbb, 0xb3, 0xe2, 0xd9, 0xd4, 0x21, 0xf6, 0x41, 0x0e, 0xd7, + 0x37, 0x32, 0xf4, 0x97, + 0xa7, 0xa8, 0x4a, 0xb2, 0x65, 0x99, 0xbc, 0x1d, 0xf0, 0x6f, 0xf9, 0x2f, + 0xca, 0x3e, 0xa9, 0x60, + 0xf7, 0x7a, 0x52, 0x47, 0x98, 0x9e, 0x63, 0x0c, 0x96, 0xa1, 0xc5, 0x0f, + 0x67, 0x87, 0xcf, 0xea, + 0x36, 0x2a, 0xa4, 0xd1, 0x5f, 0x26, 0xd6, 0xc2, 0x67, 0x85, 0x47, 0x3c, + 0x58, 0x3c, 0x30, 0x7b, + 0xa0, 0x7d, 0x80, 0x0c, 0x70, 0x7f, 0xf7, 0xf0, 0x33, 0xd8, 0xe4, 0x31, + 0x79, 0x1c, 0xdb, 0x64, + 0x4a, 0x91, 0x4c, 0x90, 0x49, 0x52, 0xc6, 0x19, 0x3d, 0x9a, 0xfc, 0xf9, + 0x88, 0x74, 0x97, 0xde, + 0xc4, 0x97, 0x7b, 0xac, 0xf1, 0xac, 0x0c, 0xca, 0x7f, 0xca, 0x76, 0x9b, + 0x33, 0x3c, 0xa2, 0x5b, + 0x28, 0xc6, 0x7e, 0x59, 0xbb, 0x39, 0x6f, 0x8d, 0x78, 0xb4, 0x70, 0x60, + 0xee, 0xb3, 0xf6, 0xfe, + 0xe2, 0x85, 0x7a, 0x7a, 0xd7, 0x5b, 0x7a, 0x49, 0x4f, 0x62, 0xaf, 0x27, + 0x9f, 0x9e, 0xd1, 0xdf, + 0x28, 0x6d, 0x02, 0x1b, 0x0f, 0x32, 0x7a, 0x19, 0xf7, 0xcc, 0x08, 0x8f, + 0x0a, 0xd9, 0xeb, 0xd7, + 0x8a, 0xb7, 0x6e, 0xa3, 0x1e, 0x1c, 0xff, 0x74, 0x66, 0x7f, 0x5b, 0xbf, + 0xfc, 0xbe, 0x46, 0x5f, + 0x09, 0x0a, 0xfa, 0xfa, 0xd9, 0xfa, 0x3b, 0xfa, 0x16, 0x3e, 0x9e, 0x7b, + 0x47, 0x7d, 0xd8, 0xe8, + 0x50, 0x4e, 0xfc, 0xd5, 0xf3, 0xe4, 0xa8, 0x3b, 0x26, 0x3f, 0x9c, 0xd0, + 0xd3, 0x20, 0xca, 0xf2, + 0xfa, 0xe6, 0xf7, 0xb5, 0xf7, 0x71, 0xf4, 0x31, 0xfa, 0x88, 0xbe, 0xec, + 0x7d, 0x1d, 0x7d, 0x6d, + 0xfd, 0x1c, 0xfd, 0xed, 0xcf, 0x38, 0x9e, 0xa8, 0xbc, 0x2f, 0x45, 0xed, + 0x85, 0xa1, 0xf8, 0xfa, + 0x6d, 0xd8, 0x4d, 0xd9, 0x22, 0xac, 0xa1, 0xdb, 0xa8, 0x3b, 0x6a, 0xef, + 0x8f, 0x7f, 0xa8, 0xf4, + 0xb1, 0x8c, 0x7f, 0x16, 0xf6, 0x18, 0xdb, 0xa3, 0xb0, 0x7b, 0xee, 0xe3, + 0xe3, 0xff, 0x91, 0xf5, + 0xc0, 0xa4, 0xbb, 0x93, 0x6e, 0x65, 0xff, 0x53, 0x7b, 0x60, 0xb7, 0x50, + 0x7c, 0xfd, 0x26, 0x6d, + 0x17, 0xde, 0xc0, 0xd5, 0x88, 0x8d, 0xd4, 0xa5, 0x3e, 0x63, 0xa7, 0x90, + 0xad, 0x42, 0x08, 0x21, + 0x30, 0xfe, 0x1f, 0x7e, 0x26, 0xe7, 0x5b +}; diff --git a/source/ngc/dvd.cpp b/source/ngc/dvd.cpp index 66de3c06..e44c56cd 100644 --- a/source/ngc/dvd.cpp +++ b/source/ngc/dvd.cpp @@ -1,228 +1,89 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 + * + * Nintendo Gamecube DVD * * softdev July 2006 * svpe & crunchy2 June 2007 - * Tantric September 2008 - * - * dvd.cpp - * - * DVD I/O functions - ***************************************************************************/ - + ****************************************************************************/ #include #include #include #include #include -#include - -#ifdef WII_DVD -extern "C" { -#include -} -#endif - -#include "memmap.h" - -#include "menudraw.h" -#include "snes9xGX.h" -#include "unzip.h" +#include +#include "snes9xGx.h" -u64 dvddir = 0; // offset of currently selected file or folder -int dvddirlength = 0; // length of currently selected file or folder -u64 dvdrootdir = 0; // offset of DVD root -bool isWii = false; - -#ifdef HW_DOL /** DVD I/O Address base **/ volatile unsigned long *dvd = (volatile unsigned long *) 0xCC006000; -#endif -/**************************************************************************** - * dvd_read - * - * Main DVD function, everything else uses this! - * returns: 1 - ok ; 0 - error - ***************************************************************************/ -#define ALIGN_FORWARD(x,align) ((typeof(x))((((uint32_t)(x)) + (align) - 1) & (~(align-1)))) -#define ALIGN_BACKWARD(x,align) ((typeof(x))(((uint32_t)(x)) & (~(align-1)))) + /** Due to lack of memory, we'll use this little 2k keyhole for all DVD operations **/ +unsigned char DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); +unsigned char dvdbuffer[2048]; + +/** + * dvd_driveid + * + * Gets and returns the dvd driveid +**/ +static unsigned char *inquiry=(unsigned char *)0x80000004; + +int dvd_driveid() +{ + dvd[0] = 0x2e; + dvd[1] = 0; + dvd[2] = 0x12000000; + dvd[3] = 0; + dvd[4] = 0x20; + dvd[5] = 0x80000000; + dvd[6] = 0x20; + dvd[7] = 3; + + while( dvd[7] & 1 ) + ; + DCFlushRange((void *)0x80000000, 32); + + return (int)inquiry[2]; +} + /** + * dvd_read + * + * The only DVD function we need - you gotta luv gc-linux self-boots! + */ int dvd_read (void *dst, unsigned int len, u64 offset) { - if (len > 2048) - return 0; /*** We only allow 2k reads **/ - // don't read past the end of the DVD (1.5 GB for GC DVD, 4.7 GB for DVD) - if((offset < 0x57057C00) || (isWii && (offset < 0x118244F00LL))) - { - u8 * buffer = (u8 *)memalign(32, 0x8000); - u32 off_size = 0; - - DCInvalidateRange ((void *) buffer, len); - - #ifdef HW_DOL - dvd[0] = 0x2E; - dvd[1] = 0; - dvd[2] = 0xA8000000; - dvd[3] = (u32)(offset >> 2); - dvd[4] = len; - dvd[5] = (u32) buffer; - dvd[6] = len; - dvd[7] = 3; - - // Enable reading with DMA - while (dvd[7] & 1); - - // Ensure it has completed - if (dvd[0] & 0x4) - return 0; - #else - off_size = offset - ALIGN_BACKWARD(offset,0x800); - if (DI_ReadDVD( - buffer, - (ALIGN_FORWARD(offset + len,0x800) - ALIGN_BACKWARD(offset,0x800)) >> 11, - (u32)(ALIGN_BACKWARD(offset, 0x800) >> 11) - )) - return 0; - #endif - - memcpy (dst, buffer+off_size, len); - free(buffer); - return 1; - } + unsigned char *buffer = (unsigned char *) (unsigned int) DVDreadbuffer; - return 0; -} + if (len > 2048) + return 1; /*** We only allow 2k reads **/ -/**************************************************************************** - * dvd_buffered_read - * - * the GC's dvd drive only supports offsets and length which are a multiple - * of 32 bytes additionally the max length of a read is 2048 bytes - * this function removes these limitations - * additionally the 7zip SDK does often read data in 1 byte parts from the - * DVD even when it could read 32 bytes. the dvdsf_buffer has been added to - * avoid having to read the same sector over and over again - ***************************************************************************/ - -#define DVD_LENGTH_MULTIPLY 32 -#define DVD_OFFSET_MULTIPLY 32 -#define DVD_MAX_READ_LENGTH 2048 -#define DVD_SECTOR_SIZE 2048 - -unsigned char dvdsf_buffer[DVD_SECTOR_SIZE]; -u64 dvdsf_last_offset = 0; -u64 dvdsf_last_length = 0; - -int dvd_buffered_read(void *dst, u32 len, u64 offset) -{ - int ret = 0; + DCInvalidateRange ((void *) buffer, len); - // only read data if the data inside dvdsf_buffer cannot be used - if(offset != dvdsf_last_offset || len > dvdsf_last_length) + if(offset < 0x57057C00 || (isWii == true && offset < 0x118244F00LL)) // don't read past the end of the DVD { - memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE); - ret = dvd_read(&dvdsf_buffer, len, offset); - dvdsf_last_offset = offset; - dvdsf_last_length = len; + offset >>= 2; + dvd[0] = 0x2E; + dvd[1] = 0; + dvd[2] = 0xA8000000; + dvd[3] = (u32)offset; + dvd[4] = len; + dvd[5] = (unsigned long) buffer; + dvd[6] = len; + dvd[7] = 3; /*** Enable reading with DMA ***/ + while (dvd[7] & 1); + memcpy (dst, buffer, len); } + else // Let's not read past end of DVD + return 0; - memcpy(dst, &dvdsf_buffer, len); - return ret; -} + if (dvd[0] & 0x4) /* Ensure it has completed */ + return 0; -int dvd_safe_read(void *dst_v, u32 len, u64 offset) -{ - unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector + return 1; - // if read size and length are a multiply of DVD_(OFFSET,LENGTH)_MULTIPLY and length < DVD_MAX_READ_LENGTH - // we don't need to fix anything - if(len % DVD_LENGTH_MULTIPLY == 0 && offset % DVD_OFFSET_MULTIPLY == 0 && len <= DVD_MAX_READ_LENGTH) - { - int ret = dvd_buffered_read(buffer, len, offset); - memcpy(dst_v, &buffer, len); - return ret; - } - else - { - // no errors yet -> ret = 0 - // the return value of dvd_read will be OR'd with ret - // because dvd_read does return 1 on error and 0 on success and - // because 0 | 1 = 1 ret will also contain 1 if at least one error - // occured and 0 otherwise ;) - int ret = 0; // return value of dvd_read - - // we might need to fix all 3 issues - unsigned char *dst = (unsigned char *)dst_v; // gcc will not allow to use var[num] on void* types - u64 bytesToRead; // the number of bytes we still need to read & copy to the output buffer - u64 currentOffset; // the current dvd offset - u64 bufferOffset; // the current buffer offset - u64 i, j, k; // temporary variables which might be used for different stuff - // unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector - - currentOffset = offset; - bytesToRead = len; - bufferOffset = 0; - - // fix first issue (offset is not a multiply of 32) - if(offset % DVD_OFFSET_MULTIPLY) - { - // calculate offset of the prior 32 byte position - i = currentOffset - (currentOffset % DVD_OFFSET_MULTIPLY); - - // calculate the offset from which the data of the dvd buffer will be copied - j = currentOffset % DVD_OFFSET_MULTIPLY; - - // calculate the number of bytes needed to reach the next DVD_OFFSET_MULTIPLY byte mark - k = DVD_OFFSET_MULTIPLY - j; - - // maybe we'll only need to copy a few bytes and we therefore don't even reach the next sector - if(k > len) - { - k = len; - } - - // read 32 bytes from the last 32 byte position - ret |= dvd_buffered_read(buffer, DVD_OFFSET_MULTIPLY, i); - - // copy the bytes to the output buffer and update currentOffset, bufferOffset and bytesToRead - memcpy(&dst[bufferOffset], &buffer[j], k); - currentOffset += k; - bufferOffset += k; - bytesToRead -= k; - } - - // fix second issue (more than 2048 bytes are needed) - if(bytesToRead > DVD_MAX_READ_LENGTH) - { - // calculate the number of 2048 bytes sector needed to get all data - i = (bytesToRead - (bytesToRead % DVD_MAX_READ_LENGTH)) / DVD_MAX_READ_LENGTH; - - // read data in 2048 byte sector - for(j = 0; j < i; j++) - { - ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector - memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer - - // update currentOffset, bufferOffset and bytesToRead - currentOffset += DVD_MAX_READ_LENGTH; - bufferOffset += DVD_MAX_READ_LENGTH; - bytesToRead -= DVD_MAX_READ_LENGTH; - } - } - - // fix third issue (length is not a multiply of 32) - if(bytesToRead) - { - ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd - memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer - } - - //free(tmp); - return ret; - } } /** Minimal ISO Directory Definition **/ @@ -236,391 +97,235 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) /** Minimal Primary Volume Descriptor **/ #define PVDROOT 0x9c static int IsJoliet = 0; +u64 rootdir = 0; +int rootdirlength = 0; -/**************************************************************************** +/** Global file entry table **/ +FILEENTRIES filelist[MAXFILES]; + +/** * Primary Volume Descriptor * * The PVD should reside between sector 16 and 31. * This is for single session DVD only. - ***************************************************************************/ + */ int getpvd () { - int sector = 16; - u32 rootdir32; - unsigned char dvdbuffer[2048]; + int sector = 16; + u32 rootdir32; - dvddir = dvddirlength = 0; - IsJoliet = -1; + rootdir = rootdirlength = 0; + IsJoliet = -1; /** Look for Joliet PVD first **/ - while (sector < 32) + while (sector < 32) + { + if (dvd_read (dvdbuffer, 2048, (u64)(sector << 11))) { - if (dvd_read (&dvdbuffer, 2048, (u64)(sector << 11))) - { - if (memcmp (&dvdbuffer, "\2CD001\1", 8) == 0) - { - memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); - dvddir = (u64)rootdir32; - dvddir <<= 11; - dvdrootdir = dvddir; - memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); - IsJoliet = 1; - break; - } - } - else - return 0; /*** Can't read sector! ***/ - sector++; + if (memcmp (&dvdbuffer, "\2CD001\1", 8) == 0) + { + memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); + rootdir = (u64)rootdir32; + rootdir <<= 11; + memcpy (&rootdirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); + IsJoliet = 1; + break; + } } + else + return 0; /*** Can't read sector! ***/ + + sector++; + } - if (IsJoliet > 0) /*** Joliet PVD Found ? ***/ - return 1; + if (IsJoliet > 0) /*** Joliet PVD Found ? ***/ + return 1; - sector = 16; + sector = 16; /*** Look for standard ISO9660 PVD ***/ - while (sector < 32) + while (sector < 32) + { + if (dvd_read (&dvdbuffer, 2048, sector << 11)) { - if (dvd_read (&dvdbuffer, 2048, sector << 11)) - { - if (memcmp (&dvdbuffer, "\1CD001\1", 8) == 0) - { - memcpy (&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); - dvddir = (u64)rootdir32; - dvddir <<= 11; - dvdrootdir = dvddir; - memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); - IsJoliet = 0; - break; - } - } - else - return 0; /*** Can't read sector! ***/ - sector++; + if (memcmp (&dvdbuffer, "\1CD001\1", 8) == 0) + { + memcpy (&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); + rootdir = (u64)rootdir32; + rootdir <<= 11; + memcpy (&rootdirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); + IsJoliet = 0; + break; + } } - return (IsJoliet == 0); -} + else + return 0; /*** Can't read sector! ***/ -/**************************************************************************** - * TestDVD() - * - * Tests if a ISO9660 DVD is inserted and available - ***************************************************************************/ -bool TestDVD() -{ + sector++; - if (!getpvd()) - { - #ifdef HW_DOL - DVD_Mount(); - #elif WII_DVD - DI_Mount(); - while(DI_GetStatus() & DVD_INIT); - #endif - if (!getpvd()) - return false; - } + } + + return (IsJoliet == 0); - return true; } -/**************************************************************************** +/** * getentry * * Support function to return the next file entry, if any * Declared static to avoid accidental external entry. - ***************************************************************************/ + */ static int diroffset = 0; static int -getentry (int entrycount, unsigned char dvdbuffer[]) +getentry (int entrycount) { - char fname[512]; /* Huge, but experience has determined this */ - char *ptr; - char *filename; - char *filenamelength; - char *rr; - int j; - u32 offset32; + char fname[512]; /* Huge, but experience has determined this */ + char *ptr; + char *filename; + char *filenamelength; + char *rr; + int j; + u32 offset32; - /* Basic checks */ - if (entrycount >= MAXFILES) - return 0; + /* Basic checks */ + if (entrycount >= MAXFILES) + return 0; - if (diroffset >= 2048) - return 0; + if (diroffset >= 2048) + return 0; /** Decode this entry **/ - if (dvdbuffer[diroffset]) /* Record length available */ - { - /* Update offsets into sector buffer */ - ptr = (char *) &dvdbuffer[0]; - ptr += diroffset; - filename = ptr + FILENAME; - filenamelength = ptr + FILENAME_LENGTH; - - /* Check for wrap round - illegal in ISO spec, - * but certain crap writers do it! */ - if ((diroffset + dvdbuffer[diroffset]) > 2048) - return 0; - - if (*filenamelength) - { - memset (&fname, 0, 512); - - if (!IsJoliet) /*** Do ISO 9660 first ***/ - strcpy (fname, filename); - else - { /*** The more tortuous unicode joliet entries ***/ - for (j = 0; j < (*filenamelength >> 1); j++) - { - fname[j] = filename[j * 2 + 1]; - } - - fname[j] = 0; - - if (strlen (fname) >= MAXJOLIET) - fname[MAXJOLIET - 1] = 0; - - if (strlen (fname) == 0) - fname[0] = filename[0]; - } - - if (strlen (fname) == 0) // root entry - { - fname[0] = 0; // we'll skip it by setting the filename to 0 length - } - else - { - if (fname[0] == 1) - { - if(dvddir == dvdrootdir) // at root already, don't show .. - fname[0] = 0; - else - strcpy (fname, ".."); - } - else - { - /* - * Move *filenamelength to t, - * Only to stop gcc warning for noobs :) - */ - int t = *filenamelength; - fname[t] = 0; - } - } - /** Rockridge Check **/ - rr = strstr (fname, ";"); - if (rr != NULL) - *rr = 0; - - strcpy (filelist[entrycount].filename, fname); - fname[MAXDISPLAY - 1] = 0; - strcpy (filelist[entrycount].displayname, fname); - - memcpy (&offset32, &dvdbuffer[diroffset + EXTENT], 4); - - filelist[entrycount].offset = (u64)offset32; - memcpy (&filelist[entrycount].length, &dvdbuffer[diroffset + FILE_LENGTH], 4); - memcpy (&filelist[entrycount].flags, &dvdbuffer[diroffset + FILE_FLAGS], 1); + if (dvdbuffer[diroffset]) /* Record length available */ + { + /* Update offsets into sector buffer */ + ptr = (char *) &dvdbuffer[0]; + ptr += diroffset; + filename = ptr + FILENAME; + filenamelength = ptr + FILENAME_LENGTH; + + /* Check for wrap round - illegal in ISO spec, + * but certain crap writers do it! */ + if ((diroffset + dvdbuffer[diroffset]) > 2048) + return 0; - filelist[entrycount].offset <<= 11; - filelist[entrycount].flags = filelist[entrycount].flags & 2; + if (*filenamelength) + { + memset (&fname, 0, 512); - /*** Prepare for next entry ***/ + if (!IsJoliet) /*** Do ISO 9660 first ***/ + strcpy (fname, filename); + else + { /*** The more tortuous unicode joliet entries ***/ - diroffset += dvdbuffer[diroffset]; - return 1; + for (j = 0; j < (*filenamelength >> 1); j++) + { + fname[j] = filename[j * 2 + 1]; } - } - return 0; -} -/**************************************************************************** - * parseDVDdirectory - * - * This function will parse the directory tree. - * It relies on dvddir and dvddirlength being pre-populated by a call to - * getpvd, a previous parse or a menu selection. - * - * The return value is number of files collected, or 0 on failure. - ***************************************************************************/ -int -ParseDVDdirectory () -{ - int pdlength; - u64 pdoffset; - u64 rdoffset; - int len = 0; - int filecount = 0; - unsigned char dvdbuffer[2048]; + fname[j] = 0; + + if (strlen (fname) >= MAXJOLIET) + fname[MAXJOLIET] = 0; + + if (strlen (fname) == 0) + fname[0] = filename[0]; + } + + if (strlen (fname) == 0) + strcpy (fname, "ROOT"); + else + { + if (fname[0] == 1) + strcpy (fname, ".."); + else + { /* + * Move *filenamelength to t, + * Only to stop gcc warning for noobs :) + */ + int t = *filenamelength; + fname[t] = 0; + } + } - // initialize selection - selection = offset = 0; + /** Rockridge Check **/ + rr = strstr (fname, ";"); + if (rr != NULL) + *rr = 0; - pdoffset = rdoffset = dvddir; - pdlength = dvddirlength; - filecount = 0; + strcpy (filelist[entrycount].filename, fname); + fname[MAXDISPLAY] = 0; + strcpy (filelist[entrycount].displayname, fname); - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); + memcpy (&offset32, + &dvdbuffer[diroffset + EXTENT], 4); + filelist[entrycount].offset = (u64)offset32; + memcpy (&filelist[entrycount].length, + &dvdbuffer[diroffset + FILE_LENGTH], 4); + memcpy (&filelist[entrycount].flags, + &dvdbuffer[diroffset + FILE_FLAGS], 1); - /*** Get as many files as possible ***/ - while (len < pdlength) - { - if (dvd_read (&dvdbuffer, 2048, pdoffset) == 0) - return 0; + filelist[entrycount].offset <<= 11; + filelist[entrycount].flags = filelist[entrycount].flags & 2; - diroffset = 0; + /*** Prepare for next entry ***/ + diroffset += dvdbuffer[diroffset]; - while (getentry (filecount, dvdbuffer)) - { - if(strlen(filelist[filecount].filename) > 0 && filecount < MAXFILES) - filecount++; - } + return 1; - len += 2048; - pdoffset = rdoffset + len; } - // Sort the file list - qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); + } - return filecount; -} + return 0; -/**************************************************************************** - * DirectorySearch - * - * Searches for the directory name specified within the current directory - * Returns the index of the directory, or -1 if not found - ***************************************************************************/ -int DirectorySearch(char dir[512]) -{ - for (int i = 0; i < maxfiles; i++ ) - if (strcmp(filelist[i].filename, dir) == 0) - return i; - return -1; } -/**************************************************************************** - * SwitchDVDFolder +/** + * parsedirectory * - * Recursively searches for any directory path 'dir' specified - * Also loads the directory contents via ParseDVDdirectory() - * It relies on dvddir, dvddirlength, and filelist being pre-populated - ***************************************************************************/ -bool SwitchDVDFolder(char * dir, int maxDepth) + * This function will parse the directory tree. + * It relies on rootdir and rootdirlength being pre-populated by a call to + * getpvd, a previous parse or a menu selection. + * + * The return value is number of files collected, or 0 on failure. + */ +int +parsedirectory () { - if(maxDepth > 8) // only search to a max depth of 8 levels - return false; + int pdlength; + u64 pdoffset; + u64 rdoffset; + int len = 0; + int filecount = 0; - bool lastdir = false; - char * nextdir = NULL; - unsigned int t = strcspn(dir, "/"); + pdoffset = rdoffset = rootdir; + pdlength = rootdirlength; + filecount = 0; - if(t != strlen(dir)) - nextdir = dir + t + 1; // next directory path to find - else - lastdir = true; + /*** Clear any existing values ***/ + memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); - dir[t] = 0; + /*** Get as many files as possible ***/ + while (len < pdlength) + { + if (dvd_read (&dvdbuffer, 2048, pdoffset) == 0) + return 0; - int dirindex = DirectorySearch(dir); + diroffset = 0; - if(dirindex >= 0) + while (getentry (filecount)) { - dvddir = filelist[dirindex].offset; - dvddirlength = filelist[dirindex].length; - maxfiles = ParseDVDdirectory(); - - if(lastdir) - return true; - else - return SwitchDVDFolder(nextdir, maxDepth++); + if (filecount < MAXFILES) + filecount++; } - return false; -} -bool SwitchDVDFolder(char origdir[]) -{ - // make a copy of origdir so we don't mess with original - char dir[200]; - strcpy(dir, origdir); - - char * dirptr = dir; - - // strip off leading/trailing slashes on the directory path - // we don't want to screw up our recursion! - if(dir[0] == '/') - dirptr = dirptr + 1; - if(dir[strlen(dir)-1] == '/') - dir[strlen(dir)-1] = 0; - - return SwitchDVDFolder(dirptr, 0); -} - -/**************************************************************************** - * LoadDVDFile - * This function will load a file from DVD - * The values for offset and length are inherited from dvddir and - * dvddirlength. - * - * The buffer parameter should re-use the initial ROM buffer - ***************************************************************************/ - -int -LoadDVDFile (unsigned char *buffer, int length) -{ - int offset; - int blocks; - int i; - u64 discoffset; - char readbuffer[2048]; - - dvddir = filelist[selection].offset; - dvddirlength = filelist[selection].length; - - // How many 2k blocks to read - blocks = dvddirlength / 2048; - offset = 0; - discoffset = dvddir; - ShowAction ((char*) "Loading..."); - - if(length > 0 && length <= 2048) - { - dvd_read (buffer, length, discoffset); - } - else // load whole file - { - dvd_read (readbuffer, 2048, discoffset); + len += 2048; + pdoffset = rdoffset + len; + } - if (!IsZipFile (readbuffer)) - { - for (i = 0; i < blocks; i++) - { - dvd_read (readbuffer, 2048, discoffset); - memcpy (buffer + offset, readbuffer, 2048); - offset += 2048; - discoffset += 2048; - } - - /*** And final cleanup ***/ - if (dvddirlength % 2048) - { - i = dvddirlength % 2048; - dvd_read (readbuffer, 2048, discoffset); - memcpy (buffer + offset, readbuffer, i); - } - } - else - { - return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd - } - } - return dvddirlength; + return filecount; } - /**************************************************************************** * uselessinquiry * @@ -629,27 +334,23 @@ LoadDVDFile (unsigned char *buffer, int length) * memcard interface. * * libOGC tends to foul up if you don't, and sometimes does if you do! - ***************************************************************************/ -#ifdef HW_DOL + ****************************************************************************/ void uselessinquiry () { - dvd[0] = 0; - dvd[1] = 0; - dvd[2] = 0x12000000; - dvd[3] = 0; - dvd[4] = 0x20; - dvd[5] = 0x80000000; - dvd[6] = 0x20; - dvd[7] = 1; - while (dvd[7] & 1); + dvd[0] = 0; + dvd[1] = 0; + dvd[2] = 0x12000000; + dvd[3] = 0; + dvd[4] = 0x20; + dvd[5] = 0x80000000; + dvd[6] = 0x20; + dvd[7] = 1; + + while (dvd[7] & 1); } -/**************************************************************************** - * dvd_motor_off( ) - * Turns off DVD drive motor so it doesn't make noise (Gamecube only) - ***************************************************************************/ -void dvd_motor_off () +void dvd_motor_off( ) { dvd[0] = 0x2e; dvd[1] = 0; @@ -666,48 +367,3 @@ void dvd_motor_off () dvd[1] = 0; } -/**************************************************************************** - * dvd_driveid - * - * Gets and returns the dvd driveid - ***************************************************************************/ - -int dvd_driveid() -{ - static unsigned char *inquiry=(unsigned char *)0x80000004; - - dvd[0] = 0x2e; - dvd[1] = 0; - dvd[2] = 0x12000000; - dvd[3] = 0; - dvd[4] = 0x20; - dvd[5] = 0x80000000; - dvd[6] = 0x20; - dvd[7] = 3; - - while( dvd[7] & 1 ) - ; - DCFlushRange((void *)0x80000000, 32); - - return (int)inquiry[2]; -} - -#endif - -/**************************************************************************** - * SetDVDDriveType() - * - * Sets the DVD drive ID for use to determine disc size (1.5 GB or 4.7 GB) - ***************************************************************************/ -void SetDVDDriveType() -{ - #ifdef HW_RVL - isWii = true; - #else - int drvid = dvd_driveid (); - if ( drvid == 4 || drvid == 6 || drvid == 8 ) - isWii = false; - else - isWii = true; - #endif -} diff --git a/source/ngc/dvd.h b/source/ngc/dvd.h index 04991b5e..f8033b2a 100644 --- a/source/ngc/dvd.h +++ b/source/ngc/dvd.h @@ -1,31 +1,37 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 + * + * Nintendo Gamecube DVD * * softdev July 2006 * svpe & crunchy2 June 2007 - * Tantric September 2008 - * - * dvd.h - * - * DVD I/O functions - ***************************************************************************/ + ****************************************************************************/ -#ifndef _NGCDVD_H_ -#define _NGCDVD_H_ +#ifndef _NGCDVD_ +#define _NGCDVD_ -int getpvd (); -int ParseDVDdirectory (); -int LoadDVDFile (unsigned char *buffer, int length); -bool TestDVD(); -int dvd_read (void *dst, unsigned int len, u64 offset); -int dvd_safe_read (void *dst, unsigned int len, u64 offset); -bool SwitchDVDFolder(char dir[]); -void SetDVDDriveType(); -#ifdef HW_DOL -void dvd_motor_off (); -#endif +#define MAXJOLIET 255 +#define MAXDISPLAY 54 +typedef struct +{ + u64 offset; + unsigned int length; + char flags; + char filename[MAXJOLIET + 1]; + char displayname[MAXDISPLAY + 1]; +} FILEENTRIES; -extern u64 dvddir; -extern int dvddirlength; +extern u64 rootdir; +extern int rootdirlength; +#define MAXFILES 2000 /** Restrict to 2000 files per dir **/ + +extern int getpvd (); +extern int parsedirectory (); +extern FILEENTRIES filelist[MAXFILES]; + +int dvd_driveid(); + +int dvd_read (void *dst, unsigned int len, u64 offset); +extern void dvd_motor_off (); #endif diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp deleted file mode 100644 index 0d4e96c2..00000000 --- a/source/ngc/fileop.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * fileop.cpp - * - * FAT File operations - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include "memmap.h" - -#include "fileop.h" -#include "unzip.h" -#include "video.h" -#include "menudraw.h" -#include "filesel.h" -#include "sram.h" -#include "preferences.h" -#include "snes9xGX.h" - -// FAT file pointer - the only one we should ever use! -FILE * fatfile; - -/**************************************************************************** - * fat_is_mounted - * to check whether FAT media are detected. - ***************************************************************************/ - -bool FatIsMounted(PARTITION_INTERFACE partition) { - char prefix[] = "fatX:/"; - prefix[3] = partition + '0'; - DIR_ITER *dir = diropen(prefix); - if (dir) { - dirclose(dir); - return true; - } - return false; -} - -/**************************************************************************** - * changeFATInterface - * Checks if the device (method) specified is available, and - * sets libfat to use the device - ***************************************************************************/ -bool ChangeFATInterface(int method, bool silent) -{ - bool devFound = false; - - if(method == METHOD_SD) - { - // check which SD device is loaded - - #ifdef HW_RVL - if (FatIsMounted(PI_INTERNAL_SD)) - { - devFound = true; - fatSetDefaultInterface(PI_INTERNAL_SD); - fatEnableReadAhead (PI_INTERNAL_SD, 6, 64); - } - #endif - - if (!devFound && FatIsMounted(PI_SDGECKO_A)) - { - devFound = true; - fatSetDefaultInterface(PI_SDGECKO_A); - } - if(!devFound && FatIsMounted(PI_SDGECKO_B)) - { - devFound = true; - fatSetDefaultInterface(PI_SDGECKO_B); - } - if(!devFound) - { - if(!silent) - WaitPrompt ((char *)"SD card not found!"); - } - } - else if(method == METHOD_USB) - { - #ifdef HW_RVL - if(FatIsMounted(PI_USBSTORAGE)) - { - devFound = true; - fatSetDefaultInterface(PI_USBSTORAGE); - fatEnableReadAhead (PI_USBSTORAGE, 6, 64); - } - else - { - if(!silent) - WaitPrompt ((char *)"USB flash drive not found!"); - } - #endif - } - - return devFound; -} - -/*************************************************************************** - * Browse FAT subdirectories - **************************************************************************/ -int -ParseFATdirectory(int method) -{ - int nbfiles = 0; - DIR_ITER *fatdir; - char filename[MAXPATHLEN]; - struct stat filestat; - char msg[128]; - - // initialize selection - selection = offset = 0; - - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); - - // open the directory - fatdir = diropen(currentdir); - if (fatdir == NULL) - { - sprintf(msg, "Couldn't open %s", currentdir); - WaitPrompt(msg); - - // if we can't open the dir, open root dir - sprintf(currentdir,"%s",ROOTFATDIR); - - fatdir = diropen(currentdir); - - if (fatdir == NULL) - { - sprintf(msg, "Error opening %s", currentdir); - WaitPrompt(msg); - return 0; - } - } - - // index files/folders - while(dirnext(fatdir,filename,&filestat) == 0) - { - if(strcmp(filename,".") != 0) - { - memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES)); - strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN); - strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1); // crop name for display - filelist[nbfiles].length = filestat.st_size; - filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir - nbfiles++; - } - } - - // close directory - dirclose(fatdir); - - // Sort the file list - qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); - - return nbfiles; -} - -/**************************************************************************** - * LoadFATFile - ***************************************************************************/ -int -LoadFATFile (char * rbuffer, int length) -{ - char zipbuffer[2048]; - char filepath[MAXPATHLEN]; - u32 size; - - /* Check filename length */ - if (!MakeROMPath(filepath, METHOD_SD)) - { - WaitPrompt((char*) "Maximum filepath length reached!"); - return -1; - } - - fatfile = fopen (filepath, "rb"); - if (fatfile > 0) - { - if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) - { - fread (rbuffer, 1, length, fatfile); - size = length; - } - else // load whole file - { - fread (zipbuffer, 1, 2048, fatfile); - - if (IsZipFile (zipbuffer)) - { - size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT - } - else - { - // Just load the file up - fseek(fatfile, 0, SEEK_END); - size = ftell(fatfile); // get filesize - fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off - memcpy (rbuffer, zipbuffer, 2048); // copy what we already read - - ShowProgress ((char *)"Loading...", 2048, size); - - u32 offset = 2048; - while(offset < size) - { - offset += fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks - ShowProgress ((char *)"Loading...", offset, size); - } - } - } - fclose (fatfile); - return size; - } - else - { - WaitPrompt((char*) "Error opening file"); - return 0; - } -} - -/**************************************************************************** - * LoadFATSzFile - * Loads the selected file # from the specified 7z into rbuffer - * Returns file size - ***************************************************************************/ -int -LoadFATSzFile(char * filepath, unsigned char * rbuffer) -{ - u32 size; - fatfile = fopen (filepath, "rb"); - if (fatfile > 0) - { - size = SzExtractFile(filelist[selection].offset, rbuffer); - fclose (fatfile); - return size; - } - else - { - WaitPrompt((char*) "Error opening file"); - return 0; - } -} - -/**************************************************************************** - * Load savebuffer from FAT file - ***************************************************************************/ -int -LoadBufferFromFAT (char *filepath, bool silent) -{ - int size = 0; - - fatfile = fopen (filepath, "rb"); - - if (fatfile <= 0) - { - if ( !silent ) - { - char msg[100]; - sprintf(msg, "Couldn't open %s", filepath); - WaitPrompt (msg); - } - return 0; - } - - // Just load the file up - fseek(fatfile, 0, SEEK_END); // go to end of file - size = ftell(fatfile); // get filesize - fseek(fatfile, 0, SEEK_SET); // go to start of file - fread (savebuffer, 1, size, fatfile); - fclose (fatfile); - - return size; -} - -/**************************************************************************** - * Write savebuffer to FAT card file - ***************************************************************************/ -int -SaveBufferToFAT (char *filepath, int datasize, bool silent) -{ - if (datasize) - { - fatfile = fopen (filepath, "wb"); - - if (fatfile <= 0) - { - char msg[100]; - sprintf(msg, "Couldn't save %s", filepath); - WaitPrompt (msg); - return 0; - } - - fwrite (savebuffer, 1, datasize, fatfile); - fclose (fatfile); - } - return datasize; -} diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h deleted file mode 100644 index 92be4752..00000000 --- a/source/ngc/fileop.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * fileop.h - * - * FAT File operations - ****************************************************************************/ - -#ifndef _FATFILESC_ -#define _FATFILESC_ -#include -#include -#include -#include -#include -#include -#include -#include - -#define ROOTFATDIR "fat:/" - -bool ChangeFATInterface(int method, bool silent); -int ParseFATdirectory(int method); -int LoadFATFile (char * fbuffer, int length); -int LoadFATSzFile(char * filepath, unsigned char * rbuffer); -int SaveBufferToFAT (char *filepath, int datasize, bool silent); -int LoadBufferFromFAT (char *filepath, bool silent); - -extern char currFATdir[MAXPATHLEN]; -extern FILE * fatfile; - -#endif diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 383727a3..7062e90a 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -1,549 +1,304 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 + * + * Nintendo Gamecube Filesel - borrowed from GPP * * softdev July 2006 * svpe June 2007 * crunchy2 May-July 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * filesel.cpp - * - * Generic file routines - reading, writing, browsing - ***************************************************************************/ - + ****************************************************************************/ #include #include #include #include #include -#include -#include - -#ifdef WII_DVD -extern "C" { -#include -} -#endif #include "snes9x.h" #include "memmap.h" - -#include "snes9xGX.h" +#include "debug.h" +#include "cpuexec.h" +#include "ppu.h" +#include "apu.h" +#include "display.h" +#include "gfx.h" +#include "soundux.h" +#include "spc700.h" +#include "spc7110.h" +#include "controls.h" + +#include "snes9xGx.h" #include "dvd.h" -#include "menudraw.h" +#include "ftfont.h" #include "video.h" #include "aram.h" -#include "smbop.h" -#include "fileop.h" -#include "memcardop.h" -#include "input.h" #include "unzip.h" +#include "filesel.h" +#include "smbload.h" +#include "sdload.h" +#include "mcsave.h" -int offset; -int selection; -char currentdir[MAXPATHLEN]; -char szpath[MAXPATHLEN]; +#define PAGESIZE 17 int maxfiles; +int havedir = 0; +int hasloaded = 0; +int loadtype = 0; +int LoadDVDFile (unsigned char *buffer); +int haveSDdir = 0; +extern unsigned long ARAM_ROMSIZE; extern int screenheight; -unsigned long SNESROMSize = 0; -int havedir = -1; -extern u64 dvddir; -extern int dvddirlength; +extern FILEENTRIES filelist[MAXFILES]; -// Global file entry table -FILEENTRIES filelist[MAXFILES]; -bool inSz = false; - -unsigned char *savebuffer = NULL; - -/**************************************************************************** - * AllocSaveBuffer () - * Allocate and clear the savebuffer - ***************************************************************************/ -void -AllocSaveBuffer () +/** + * Showfile screen + * + * Display the file selection to the user + */ +static void +ShowFiles (int offset, int selection) { - if (savebuffer != NULL) - free(savebuffer); + int i, j; + char text[MAXPATHLEN]; + int ypos; + int w; + + setfontsize(18); + clearscreen (); - savebuffer = (unsigned char *) malloc(SAVEBUFFERSIZE); - memset (savebuffer, 0, SAVEBUFFERSIZE); -} + ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1; -/**************************************************************************** - * FreeSaveBuffer () - * Free the savebuffer memory - ***************************************************************************/ -void -FreeSaveBuffer () -{ - if (savebuffer != NULL) - free(savebuffer); + if (screenheight == 480) + ypos += 24; + else + ypos += 10; - savebuffer = NULL; -} -/**************************************************************************** -* autoLoadMethod() -* Auto-determines and sets the load method -* Returns method set -****************************************************************************/ -int autoLoadMethod() -{ - ShowAction ((char*) "Attempting to determine load method..."); - - if(ChangeFATInterface(METHOD_SD, SILENT)) - return METHOD_SD; - else if(ChangeFATInterface(METHOD_USB, SILENT)) - return METHOD_USB; - else if(TestDVD()) - return METHOD_DVD; - else if(ConnectShare (SILENT)) - return METHOD_SMB; - else - { - WaitPrompt((char*) "Unable to auto-determine load method!"); - return 0; // no method found - } -} + j = 0; + for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++) -/**************************************************************************** -* autoSaveMethod() -* Auto-determines and sets the save method -* Returns method set -****************************************************************************/ -int autoSaveMethod() -{ - ShowAction ((char*) "Attempting to determine save method..."); - - if(ChangeFATInterface(METHOD_SD, SILENT)) - return METHOD_SD; - else if(ChangeFATInterface(METHOD_USB, SILENT)) - return METHOD_USB; - else if(TestCard(CARD_SLOTA, SILENT)) - return METHOD_MC_SLOTA; - else if(TestCard(CARD_SLOTB, SILENT)) - return METHOD_MC_SLOTB; - else if(ConnectShare (SILENT)) - return METHOD_SMB; - else - { - WaitPrompt((char*) "Unable to auto-determine save method!"); - return 0; // no method found - } -} + { + if (filelist[i].flags) // if a dir -/**************************************************************************** - * UpdateDirName() - * Update curent directory name for file browser - ***************************************************************************/ -int UpdateDirName(int method) -{ - int size=0; - char * test; - char temp[1024]; - - // update DVD directory (does not utilize 'currentdir') - if(method == METHOD_DVD) - { - dvddir = filelist[selection].offset; - dvddirlength = filelist[selection].length; - return 1; - } - - /* current directory doesn't change */ - if (strcmp(filelist[selection].filename,".") == 0) - { - return 0; - } - /* go up to parent directory */ - else if (strcmp(filelist[selection].filename,"..") == 0) - { - /* determine last subdirectory namelength */ - sprintf(temp,"%s",currentdir); - test = strtok(temp,"/"); - while (test != NULL) - { - size = strlen(test); - test = strtok(NULL,"/"); - } - - /* remove last subdirectory name */ - size = strlen(currentdir) - size - 1; - currentdir[size] = 0; - - return 1; - } - /* Open a directory */ - else - { - /* test new directory namelength */ - if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) - { - /* update current directory name */ - sprintf(currentdir, "%s/%s",currentdir, filelist[selection].filename); - return 1; - } - else - { - WaitPrompt((char*)"Directory name is too long !"); - return -1; - } - } -} + { + strcpy (text, "["); + strcat (text, filelist[i].displayname); + strcat (text, "]"); + } -bool MakeROMPath(char filepath[], int method) -{ - char temppath[MAXPATHLEN]; - - // Check filename length - if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) - { - sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename); - - if(method == METHOD_SMB) - strcpy(filepath, SMBPath(temppath)); - else - strcpy(filepath, temppath); - return true; - } - else - { - filepath[0] = 0; - return false; - } -} + else + strcpy (text, filelist[i].displayname); + if (j == (selection - offset)) -/**************************************************************************** - * FileSortCallback - * - * Quick sort callback to sort file entries with the following order: - * . - * .. - * - * - ***************************************************************************/ -int FileSortCallback(const void *f1, const void *f2) -{ - /* Special case for implicit directories */ - if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') - { - if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } - if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } - } - - /* If one is a file and one is a directory the directory is first. */ - if(((FILEENTRIES *)f1)->flags && !(((FILEENTRIES *)f2)->flags)) return -1; - if(!(((FILEENTRIES *)f1)->flags) && ((FILEENTRIES *)f2)->flags) return 1; - - return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); -} + { -/**************************************************************************** - * IsValidROM - * - * Checks if the specified file is a valid ROM - * For now we will just check the file extension and file size - * If the file is a zip, we will check the file extension / file size of the - * first file inside - ***************************************************************************/ + /*** Highlighted text entry ***/ + for ( w = 0; w < 20; w++ ) + DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 ); -bool IsValidROM(int method) -{ - // file size should be between 128K and 8MB - if(filelist[selection].length < (1024*128) || - filelist[selection].length > (1024*1024*8)) - { - WaitPrompt((char *)"Invalid file size!"); - return false; - } - - if (strlen(filelist[selection].filename) > 4) - { - char * p = strrchr(filelist[selection].filename, '.'); - - if (p != NULL) - { - if(stricmp(p, ".zip") == 0 && !inSz) - { - // we need to check the file extension of the first file in the archive - char * zippedFilename = GetFirstZipFilename (method); - - if(zippedFilename == NULL) // we don't want to run strlen on NULL - p = NULL; - else if(strlen(zippedFilename) > 4) - p = strrchr(zippedFilename, '.'); - else - p = NULL; - } + setfontcolour (0x00, 0x00, 0xe0); + DrawText (-1, (j * 20) + ypos, text); + setfontcolour (0x00, 0x00, 0x00); + } - if(p != NULL) - { - if (stricmp(p, ".smc") == 0 || stricmp(p, ".fig") == 0) - { - return true; - } - } - } - } - WaitPrompt((char *)"Unknown file type!"); - return false; -} + else -/**************************************************************************** - * IsSz - * - * Checks if the specified file is a 7z - ***************************************************************************/ + { + /*** Normal entry ***/ + DrawText (-1, (j * 20) + ypos, text); + } + j++; + } + showscreen (); -bool IsSz() -{ - if (strlen(filelist[selection].filename) > 4) - { - char * p = strrchr(filelist[selection].filename, '.'); - - if (p != NULL) - if(stricmp(p, ".7z") == 0) - return true; - } - return false; } -/**************************************************************************** - * StripExt - * - * Strips an extension from a filename - ***************************************************************************/ - -void StripExt(char* returnstring, char * inputstring) +/** +* SNESROMSOffset +* +* Function to check for and return offset to a directory called SNESROMS, if +* any +*/ +int SNESROMSOffset() { - char* loc_dot; - - strcpy (returnstring, inputstring); - loc_dot = strrchr(returnstring,'.'); - if (loc_dot != NULL) - *loc_dot = 0; // strip file extension + int i; + + for ( i = 0; i < maxfiles; i++ ) + if (strcmp(filelist[i].filename, "SNESROMS") == 0) + return i; + return 0; } -/**************************************************************************** +/** * FileSelector * - * Let user select a file from the listing - ***************************************************************************/ -int FileSelector (int method) -{ - u32 p = 0; - u32 wp = 0; - u32 ph = 0; - u32 wh = 0; - signed char gc_ay = 0; - signed char gc_sx = 0; - signed char wm_ay = 0; - signed char wm_sx = 0; + * Let user select a file from the DVD listing + */ +int offset = 0; +int selection = 0; +#define PADCAL 40 +int +FileSelector () +{ + u32 p, wp, ph, wh; + signed char a, c; int haverom = 0; int redraw = 1; int selectit = 0; - + float mag = 0; + u16 ang = 0; int scroll_delay = 0; bool move_selection = 0; #define SCROLL_INITIAL_DELAY 15 - #define SCROLL_LOOP_DELAY 2 - - while (haverom == 0) + #define SCROLL_LOOP_DELAY 4 + + while (haverom == 0) { if (redraw) - ShowFiles (filelist, maxfiles, offset, selection); + ShowFiles (offset, selection); redraw = 0; VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads - - gc_ay = PAD_StickY (0); - gc_sx = PAD_SubStickX (0); - + p = PAD_ButtonsDown (0); ph = PAD_ButtonsHeld (0); #ifdef HW_RVL - wm_ay = WPAD_Stick (0, 0, 1); - wm_sx = WPAD_Stick (0, 1, 0); - wp = WPAD_ButtonsDown (0); wh = WPAD_ButtonsHeld (0); + wpad_get_analogues(0, &mag, &ang); // get joystick info from wii expansions +#else + wp = 0; + wh = 0; #endif - + a = PAD_StickY (0); + c = PAD_SubStickX (0); + /*** Check for exit combo ***/ - if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) - return 0; - + if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) return 0; + /*** Check buttons, perform actions ***/ - if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) - { - if ( selectit ) - selectit = 0; - if (filelist[selection].flags) // This is directory - { - /* update current directory and set new entry list if directory has changed */ - int status; - - if(inSz && selection == 0) // inside a 7z, requesting to leave - { - if(method == METHOD_DVD) - { - // go to directory the 7z was in - dvddir = filelist[0].offset; - dvddirlength = filelist[0].length; - } - inSz = false; - status = 1; - SzClose(); - } - else - { - status = UpdateDirName(method); - } - - if (status == 1) // ok, open directory - { - switch (method) - { - case METHOD_SD: - case METHOD_USB: - maxfiles = ParseFATdirectory(method); - break; - - case METHOD_DVD: - maxfiles = ParseDVDdirectory(); - break; - - case METHOD_SMB: - maxfiles = ParseSMBdirectory(); - break; - } - - if (!maxfiles) - { - WaitPrompt ((char*) "Error reading directory !"); - haverom = 1; // quit menu - } - } - else if (status == -1) // directory name too long - { - return 0; // quit menu - } - } - else // this is a file - { - // 7z file - let's open it up to select a file inside - if(IsSz()) - { - // we'll store the 7z filepath for extraction later - if(!MakeROMPath(szpath, method)) - { - WaitPrompt((char*) "Maximum filepath length reached!"); - return -1; - } - int szfiles = SzParse(szpath, method); - if(szfiles) - { - maxfiles = szfiles; - inSz = true; - } - else - WaitPrompt((char*) "Error opening archive!"); - } - else - { - // check that this is a valid ROM - if(!IsValidROM(method)) - return 0; - - // store the filename (w/o ext) - used for sram/freeze naming - StripExt(Memory.ROMFilename, filelist[selection].filename); - - ShowAction ((char *)"Loading..."); - - SNESROMSize = 0; - - switch (method) - { - case METHOD_SD: - case METHOD_USB: - if(inSz) - SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM); - else - SNESROMSize = LoadFATFile ((char *)Memory.ROM, filelist[selection].length); - break; - - case METHOD_DVD: - if(inSz) - SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM); - else - SNESROMSize = LoadDVDFile (Memory.ROM, filelist[selection].length); - break; - - case METHOD_SMB: - if(inSz) - SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM); - else - SNESROMSize = LoadSMBFile ((char *)Memory.ROM, filelist[selection].length); - break; - } - inSz = false; - - if (SNESROMSize > 0) - { - Memory.LoadROM ("BLANK.SMC"); - Memory.LoadSRAM ("BLANK"); - haverom = 1; - return 1; - } - else - { - WaitPrompt((char*) "Error loading ROM!"); - } - } - } - redraw = 1; - } // End of A + if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) + { + if ( selectit ) + selectit = 0; + if (filelist[selection].flags) /*** This is directory ***/ + { + if (loadtype == LOAD_SDC) + { + /* memorize last entries list, actual root directory and selection for next access */ + haveSDdir = 1; + + /* update current directory and set new entry list if directory has changed */ + int status = updateSDdirname(); + if (status == 1) // ok, open directory + { + maxfiles = parseSDdirectory(); + if (!maxfiles) + { + WaitPrompt ((char*) "Error reading directory !"); + haverom = 1; // quit SD menu + haveSDdir = 0; // reset everything at next access + } + } + else if (status == -1) // directory name too long + { + haverom = 1; // quit SD menu + haveSDdir = 0; // reset everything at next access + } + } + else + { + if ( (strcmp (filelist[selection].filename, "..") == 0) + && ((unsigned int)rootdir == filelist[selection].offset) ) + return 0; + else + { + rootdir = filelist[selection].offset; + rootdirlength = filelist[selection].length; + offset = selection = 0; + maxfiles = parsedirectory (); + } + } + } + else // this is a file + { + rootdir = filelist[selection].offset; + rootdirlength = filelist[selection].length; + + switch (loadtype) + { + case LOAD_DVD: + /*** Now load the DVD file to it's offset ***/ + ARAM_ROMSIZE = LoadDVDFile (Memory.ROM); + break; + + case LOAD_SMB: + /*** Load from SMB ***/ + ARAM_ROMSIZE = + LoadSMBFile (filelist[selection].filename, + filelist[selection].length); + break; + + case LOAD_SDC: + /*** Load from SD Card ***/ + /* memorize last entries list, actual root directory and selection for next access */ + haveSDdir = 1; + ARAM_ROMSIZE = LoadSDFile (filelist[selection].filename, + filelist[selection].length); + break; + } + + if (ARAM_ROMSIZE > 0) + { + hasloaded = 1; + Memory.LoadROM ("BLANK.SMC"); + + Memory.LoadSRAM ("BLANK"); + haverom = 1; + + return 1; + } + else + { + WaitPrompt((char*) "Error loading ROM!"); + } + } + redraw = 1; + } // End of A if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) { - while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) + while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) #ifdef HW_RVL - || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) + || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) #endif ) VIDEO_WaitVSync(); - if ( strcmp(filelist[0].filename,"..") == 0 ) + //if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0)) + if ( strcmp(filelist[0].filename,"..") == 0 ) { selection = 0; selectit = 1; } - else if ( strcmp(filelist[1].filename,"..") == 0 ) + else if ( strcmp(filelist[1].filename,"..") == 0 ) { selection = selectit = 1; - } - else - { + } else { return 0; } } // End of B - if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) ) + if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -PADCAL) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) ) { if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) - } + } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } - + if (move_selection) { selection++; @@ -555,19 +310,19 @@ int FileSelector (int method) move_selection = 0; } } // End of down - if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) ) - { + if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) ) + { if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) - } + } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } - + if (move_selection) { selection--; @@ -612,142 +367,173 @@ int FileSelector (int method) return 0; } -/**************************************************************************** +/** * OpenDVD * * Function to load a DVD directory and display to user. - ***************************************************************************/ + */ int -OpenDVD (int method) +OpenDVD () { - if (!getpvd()) - { - ShowAction((char*) "Loading DVD..."); - #ifdef HW_DOL - DVD_Mount(); // mount the DVD unit again - #elif WII_DVD - u32 val; - DI_GetCoverRegister(&val); - if(val & 0x1) // True if no disc inside, use (val & 0x2) for true if disc inside. - { - WaitPrompt((char *)"No disc inserted!"); - return 0; - } - DI_Mount(); - while(DI_GetStatus() & DVD_INIT); - #endif - - if (!getpvd()) - { - WaitPrompt ((char *)"Invalid DVD."); - return 0; // not a ISO9660 DVD - } - } - - maxfiles = ParseDVDdirectory(); // load root folder - - // switch to rom folder - SwitchDVDFolder(GCSettings.LoadFolder); - - if (maxfiles > 0) - { - return FileSelector (method); - } - else - { - // no entries found - WaitPrompt ((char *)"No Files Found!"); - return 0; - } + int romsdiroffset = 0; + + loadtype = LOAD_DVD; + + if (!getpvd()) + { + ShowAction((char*) "Mounting DVD ... Wait"); + DVD_Mount(); /* mount the DVD unit again */ + havedir = 0; /* this may be a new DVD: content need to be parsed again */ + if (!getpvd()) + return 0; /* no correct ISO9660 DVD */ + } + + if (havedir == 0) + { + offset = selection = 0; /* reset file selector */ + haveSDdir = 0; /* prevent conflicts with SDCARD file selector */ + + if ((maxfiles = parsedirectory ())) + { + if ( romsdiroffset = SNESROMSOffset() ) + { + rootdir = filelist[romsdiroffset].offset; + rootdirlength = filelist[romsdiroffset].length; + offset = selection = 0; + maxfiles = parsedirectory (); + } + + int ret = FileSelector (); + havedir = 1; + return ret; + } + } + + else + return FileSelector (); + + return 0; } -/**************************************************************************** +/** * OpenSMB * * Function to load from an SMB share - ***************************************************************************/ + */ int -OpenSMB (int method) +OpenSMB () { - // Connect to network share - if(ConnectShare (NOTSILENT)) - { - // change current dir to root dir - sprintf(currentdir, "/%s", GCSettings.LoadFolder); - - maxfiles = ParseSMBdirectory (); - if (maxfiles > 0) - { - return FileSelector (method); - } - else - { - // no entries found - WaitPrompt ((char *)"No Files Found!"); - return 0; - } - } - return 0; + loadtype = LOAD_SMB; + + if ((maxfiles = parseSMBDirectory ())) + { + char txt[80]; + sprintf(txt,"maxfiles = %d", maxfiles); + + return FileSelector (); + } + return 0; } -/**************************************************************************** - * OpenFAT +/** + * OpenSD * - * Function to load from FAT - ***************************************************************************/ + * Function to load from an SD Card + */ int -OpenFAT (int method) +OpenSD () { - if(ChangeFATInterface(method, NOTSILENT)) - { - // change current dir to snes roms directory - sprintf ( currentdir, "%s/%s", ROOTFATDIR, GCSettings.LoadFolder ); - - // Parse initial root directory and get entries list - maxfiles = ParseFATdirectory (method); - if (maxfiles > 0) - { - // Select an entry - return FileSelector (method); - } - else - { - // no entries found - WaitPrompt ((char *)"No Files Found!"); - return 0; - } - } - return 0; + char msg[80]; + char buf[50] = ""; + + loadtype = LOAD_SDC; + + if (haveSDdir == 0) + { + /* don't mess with DVD entries */ + havedir = 0; // gamecube only + + /* change current dir to snes roms directory */ + sprintf ( currSDdir, "%s/%s", ROOTSDDIR, SNESROMDIR ); + + + /* Parse initial root directory and get entries list */ + if ((maxfiles = parseSDdirectory ())) + { + /* Select an entry */ + return FileSelector (); + } + else + { + /* no entries found */ + sprintf (msg, "No Files Found!"); + WaitPrompt (msg); + return 0; + } + } + /* Retrieve previous entries list and made a new selection */ + else + return FileSelector (); + + return 0; } -/**************************************************************************** - * OpenROM - * Opens device specified by method, displays a list of ROMS - ***************************************************************************/ +/** + * LoadDVDFile + * + * This function will load a file from DVD, in BIN, SMD or ZIP format. + * The values for offset and length are inherited from rootdir and + * rootdirlength. + * + * The buffer parameter should re-use the initial ROM buffer. + */ int -OpenROM (int method) +LoadDVDFile (unsigned char *buffer) { - int loadROM = 0; - - if(method == METHOD_AUTO) - method = autoLoadMethod(); - - switch (method) - { - case METHOD_SD: - case METHOD_USB: - loadROM = OpenFAT (method); - break; - case METHOD_DVD: - // Load from DVD - loadROM = OpenDVD (method); - break; - case METHOD_SMB: - // Load from Network (SMB) - loadROM = OpenSMB (method); - break; - } - - return loadROM; + int offset; + int blocks; + int i; + u64 discoffset; + char readbuffer[2048]; + + /*** SDCard Addition ***/ + if (rootdirlength == 0) + return 0; + + /*** How many 2k blocks to read ***/ + blocks = rootdirlength / 2048; + offset = 0; + discoffset = rootdir; + ShowAction ((char*) "Loading ... Wait"); + dvd_read (readbuffer, 2048, discoffset); + + if (!IsZipFile (readbuffer)) + + { + for (i = 0; i < blocks; i++) + + { + dvd_read (readbuffer, 2048, discoffset); + memcpy (buffer + offset, readbuffer, 2048); + offset += 2048; + discoffset += 2048; + } + + /*** And final cleanup ***/ + if (rootdirlength % 2048) + + { + i = rootdirlength % 2048; + dvd_read (readbuffer, 2048, discoffset); + memcpy (buffer + offset, readbuffer, i); + } + } + + else + + { + return UnZipBuffer (buffer, discoffset, 1, NULL); // unzip from dvd + } + return rootdirlength; } diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index 29edf028..0e72761e 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -1,50 +1,24 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 + * + * Nintendo Gamecube Filesel - borrowed from GPP * * softdev July 2006 * crunchy2 May 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * filesel.h - * - * Generic file routines - reading, writing, browsing ****************************************************************************/ #ifndef _NGCFILESEL_ #define _NGCFILESEL_ -#include - -#define SAVEBUFFERSIZE (512 * 1024) -#define MAXJOLIET 255 -#define MAXDISPLAY 54 - -typedef struct -{ - u64 offset; - unsigned int length; - char flags; - char filename[MAXJOLIET + 1]; - char displayname[MAXDISPLAY + 1]; -} FILEENTRIES; - -#define MAXFILES 2000 // Restrict to 2000 files per dir -extern FILEENTRIES filelist[MAXFILES]; -extern unsigned char *savebuffer; -extern int offset; -extern int selection; -extern char currentdir[MAXPATHLEN]; -extern int maxfiles; -extern unsigned long SNESROMSize; +int OpenDVD (); +int OpenSMB (); +int OpenSD (); -void AllocSaveBuffer(); -void FreeSaveBuffer(); -bool MakeROMPath(char filepath[], int method); -int OpenROM (int method); -int autoLoadMethod(); -int autoSaveMethod(); -int FileSortCallback(const void *f1, const void *f2); -void StripExt(char* returnstring, char * inputstring); +#define LOAD_DVD 1 +#define LOAD_SMB 2 +#define LOAD_SDC 4 +#define ROOTSDDIR "fat:/" +#define SNESROMDIR "snes9x/roms" +#define SNESSAVEDIR "snes9x/saves" #endif diff --git a/source/ngc/freeze.cpp b/source/ngc/freeze.cpp deleted file mode 100644 index 48e9a79a..00000000 --- a/source/ngc/freeze.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007-July 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * freeze.cpp - * - * Snapshots Memory File System - * - * This is a single global memory file controller. - * Don't even think of opening two at the same time! - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include "snes9x.h" -#include "memmap.h" -#include "soundux.h" -#include "snapshot.h" -#include "srtc.h" - -#include "snes9xGX.h" -#include "images/saveicon.h" -#include "freeze.h" -#include "filesel.h" -#include "menudraw.h" -#include "smbop.h" -#include "fileop.h" -#include "memcardop.h" - -extern void S9xSRTCPreSaveState (); -extern void NGCFreezeStruct (); -extern bool8 S9xUnfreezeGame (const char *filename); - -static int bufoffset; - -char freezecomment[2][32]; - - -/**************************************************************************** - * GetMem - * - * Return x bytes from memory buffer - ***************************************************************************/ -int -GetMem (char *buffer, int len) -{ - memcpy (buffer, savebuffer + bufoffset, len); - bufoffset += len; - - return len; -} - -/**************************************************************************** - * PutMem - * - * Put some values in memory buffer - ***************************************************************************/ -static void -PutMem (char *buffer, int len) -{ - memcpy (savebuffer + bufoffset, buffer, len); - bufoffset += len; -} - -void -NGCFreezeBlock (char *name, uint8 * block, int size) -{ - char buffer[512]; - sprintf (buffer, "%s:%06d:", name, size); - PutMem (buffer, strlen (buffer)); - PutMem ((char *) block, size); -} - -/**************************************************************************** - * NGCFreezeMembuffer - * - * Copies a snapshot of Snes9x state into memory - ***************************************************************************/ -static int -NGCFreezeMemBuffer () -{ - int i; - char buffer[1024]; - - bufoffset = 0; - - S9xUpdateRTC (); - S9xSRTCPreSaveState (); - - for (i = 0; i < 8; i++) - { - SoundData.channels[i].previous16[0] = - (int16) SoundData.channels[i].previous[0]; - SoundData.channels[i].previous16[1] = - (int16) SoundData.channels[i].previous[1]; - } - - sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION); - PutMem (buffer, strlen (buffer)); - sprintf (buffer, "NAM:%06d:%s%c", (int) strlen (Memory.ROMFilename) + 1, - Memory.ROMFilename, 0); - - PutMem (buffer, strlen (buffer) + 1); - - NGCFreezeStruct (); - - return 0; -} - - -/**************************************************************************** - * NGCFreezeGame - * - * Do freeze game for Nintendo Gamecube - ***************************************************************************/ -int -NGCFreezeGame (int method, bool8 silent) -{ - ShowAction ((char*) "Saving..."); - - if(method == METHOD_AUTO) - method = autoSaveMethod(); - - char filename[1024]; - int offset = 0; - char msg[100]; - - S9xSetSoundMute (TRUE); - S9xPrepareSoundForSnapshotSave (FALSE); - - AllocSaveBuffer (); - NGCFreezeMemBuffer (); // copy freeze mem into savebuffer - - S9xPrepareSoundForSnapshotSave (TRUE); - S9xSetSoundMute (FALSE); - - if (method == METHOD_SD || method == METHOD_USB) // FAT devices - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); - offset = SaveBufferToFAT (filename, bufoffset, silent); - } - } - else if (method == METHOD_SMB) // SMB - { - sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename); - offset = SaveBufferToSMB (filename, bufoffset, silent); - } - else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B - { - sprintf (filename, "%s.snz", Memory.ROMName); - - // Copy in save icon - int woffset = sizeof (saveicon); - memcpy (savebuffer, saveicon, woffset); - - // And the freezecomment - sprintf (freezecomment[0], "%s Freeze", VERSIONSTR); - sprintf (freezecomment[1], Memory.ROMName); - memcpy (savebuffer + woffset, freezecomment, 64); - woffset += 64; - - // Zip and copy in the freeze - uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE; - int err= compress2((Bytef*)(savebuffer+woffset+8), (uLongf*)&DestBuffSize, (const Bytef*)savebuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); - - if(err!=Z_OK) - { - sprintf (msg, "zip error %s ",zError(err)); - WaitPrompt (msg); - return 0; - } - - int zippedsize = (int)DestBuffSize; - memcpy (savebuffer + woffset, &zippedsize, 4); - woffset += 4; - - int decompressedsize = (int)bufoffset; - memcpy (savebuffer + woffset, &decompressedsize, 4); - woffset += 4; - - woffset += zippedsize; - - if(method == METHOD_MC_SLOTA) - offset = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, woffset, SILENT ); - else - offset = SaveBufferToMC ( savebuffer, CARD_SLOTB, filename, woffset, SILENT ); - } - - FreeSaveBuffer (); - - if(offset > 0) // save successful! - { - if(!silent) - WaitPrompt((char*) "Save successful"); - return 1; - } - return 0; -} - -/**************************************************************************** - * NGCUnFreezeBlock - ***************************************************************************/ -int -NGCUnFreezeBlock (char *name, uint8 * block, int size) -{ - char buffer[20], *e; - int len = 0; - int rem = 0; - - GetMem (buffer, 11); - - if (strncmp (buffer, name, 3) != 0 || buffer[3] != ':' || - buffer[10] != ':' || (len = strtol (&buffer[4], &e, 10)) == 0 || - e != buffer + 10) - { - return WRONG_FORMAT; - } - - if (len > size) - { - rem = len - size; - len = size; - } - - ZeroMemory (block, size); - - GetMem ((char *) block, len); - - if (rem) - { - bufoffset += rem; - } - - return SUCCESS; -} - -/**************************************************************************** - * NGCUnfreezeGame - ***************************************************************************/ -int -NGCUnfreezeGame (int method, bool8 silent) -{ - ShowAction ((char*) "Loading..."); - char filename[1024]; - int offset = 0; - char msg[80]; - - bufoffset = 0; - - if(method == METHOD_AUTO) - method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W - - AllocSaveBuffer (); - - if (method == METHOD_SD || method == METHOD_USB) // SD & USB - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); - offset = LoadBufferFromFAT (filename, silent); - } - } - else if (method == METHOD_SMB) // Network (SMB) - { - sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename); - offset = LoadBufferFromSMB (filename, silent); - } - else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B - { - sprintf (filename, "%s.snz", Memory.ROMName); - - int ret = 0; - - if(method == METHOD_MC_SLOTA) - ret = LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent ); - else - ret = LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent ); - - if (ret) - { - char * zipbuffer = (char *)malloc(SAVEBUFFERSIZE); - memset (zipbuffer, 0, SAVEBUFFERSIZE); - - // skip the saveicon and comment - offset = (sizeof(saveicon) + 64); - uLongf zipsize = 0; - uLongf decompressedsize = 0; - - memcpy (&zipsize, savebuffer+offset, 4); - offset += 4; - - memcpy (&decompressedsize, savebuffer+offset, 4); - offset += 4; - - uLongf DestBuffSize = SAVEBUFFERSIZE; - int err= uncompress((Bytef*)zipbuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); - - if ( err!=Z_OK ) - { - sprintf (msg, "Unzip error %s ",zError(err)); - WaitPrompt (msg); - } - else if ( DestBuffSize != decompressedsize ) - { - WaitPrompt((char*) "Unzipped size doesn't match expected size!"); - } - else - { - offset = SAVEBUFFERSIZE; - memcpy (savebuffer, zipbuffer, SAVEBUFFERSIZE); - } - free(zipbuffer); - zipbuffer = NULL; - - if(offset == 0) - return 0; - } - } - - int result = 0; - - if(offset > 0) - { - if (S9xUnfreezeGame ("AGAME") == SUCCESS) - result = 1; - else - WaitPrompt((char*) "Error thawing"); - } - else - { - if(!silent) - WaitPrompt((char*) "Freeze file not found"); - } - FreeSaveBuffer (); - return result; -} diff --git a/source/ngc/freeze.h b/source/ngc/freeze.h deleted file mode 100644 index 4470c15e..00000000 --- a/source/ngc/freeze.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007-July 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * freeze.h - * - * Snapshots Memory File System - * - * This is a single global memory file controller. - * Don't even think of opening two at the same time! - ***************************************************************************/ - -#ifndef _NGCMEMFILE_ -#define _NGCMEMFILE_ - -typedef struct -{ - char filename[512]; /*** Way over size - but who cares -;) ***/ - int filehandle; - int currpos; - int length; - int mode; - char *buffer; /*** Memspace for read / write ***/ -} -MEMFILE; - -int NGCFreezeGame (int method, bool8 silent); -int NGCUnfreezeGame (int method, bool8 silent); - -#endif diff --git a/source/ngc/ftfont.cpp b/source/ngc/ftfont.cpp new file mode 100644 index 00000000..1c7c9f9f --- /dev/null +++ b/source/ngc/ftfont.cpp @@ -0,0 +1,875 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Screen Font Driver + * + * Uses libfreetype 2.2.1 compiled for GC with TTF support only. + * TTF only reduces the library by some 900k bytes! + * + * Visit - http://www.freetype.org ! + * + * **WARNING*** + * + * ONLY USE GUARANTEED PATENT FREE FONTS. + * THOSE IN YOUR WINDOWS\FONTS DIRECTORY ARE COPYRIGHT + * AND MAY NOT BE DISTRIBUTED! + * + * softdev July 2006 + * crunchy2 June 2007 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include FT_FREETYPE_H +#include "video.h" +#include "ftfont.h" +#include "dkpro.h" +#include "snes9xGX.h" + +#include "aram.h" +#include + +#include "gfx_bg.h" + +/*** Globals ***/ +FT_Library ftlibrary; +FT_Face face; +FT_GlyphSlot slot; +FT_UInt glyph_index; +static unsigned int fonthi, fontlo; + +extern char fontface[]; /*** From fontface.s ***/ +extern int fontsize; /*** From fontface.s ***/ +extern int screenheight; +extern unsigned int *xfb[2]; +extern int whichfb; + +/** + * Unpack the devkit pro logo + */ +static u32 *dkproraw; +/*** Permanent backdrop ***/ +#ifdef HW_RVL +u32 *backdrop; +#else +static u32 *backdrop; +#endif +static void unpackbackdrop (); +unsigned int getcolour (u8 r1, u8 g1, u8 b1); +void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ); +u32 getrgb( u32 ycbr, u32 low ); + +/** + * Initialisation of libfreetype + */ +int +FT_Init () +{ + + int err; + + err = FT_Init_FreeType (&ftlibrary); + if (err) + return 1; + + err = + FT_New_Memory_Face (ftlibrary, (FT_Byte *) fontface, fontsize, 0, &face); + if (err) + return 1; + + setfontsize (16); + setfontcolour (0xff, 0xff, 0xff); + + slot = face->glyph; + + return 0; + +} + +/** + * setfontsize + * + * Set the screen font size in pixels + */ +void +setfontsize (int pixelsize) +{ + int err; + + err = FT_Set_Pixel_Sizes (face, 0, pixelsize); + + if (err) + printf ("Error setting pixel sizes!"); +} + +static void +DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y) +{ + FT_Int i, j, p, q; + FT_Int x_max = x + bmp->width; + FT_Int y_max = y + bmp->rows; + int spos; + unsigned int pixel; + int c; + + for (i = x, p = 0; i < x_max; i++, p++) + { + for (j = y, q = 0; j < y_max; j++, q++) + { + if (i < 0 || j < 0 || i >= 640 || j >= screenheight) + continue; + + /*** Convert pixel position to GC int sizes ***/ + spos = (j * 320) + (i >> 1); + + pixel = xfb[whichfb][spos]; + c = bmp->buffer[q * bmp->width + p]; + + /*** Cool Anti-Aliasing doesn't work too well at hires on GC ***/ + if (c > 128) + { + if (i & 1) + pixel = (pixel & 0xffff0000) | fontlo; + else + pixel = ((pixel & 0xffff) | fonthi); + + xfb[whichfb][spos] = pixel; + } + } + } +} + +/** + * DrawText + * + * Place the font bitmap on the screen + */ +void +DrawText (int x, int y, char *text) +{ + int px, n; + int i; + int err; + int value, count; + + n = strlen (text); + if (n == 0) + return; + + /*** x == -1, auto centre ***/ + if (x == -1) + { + value = 0; + px = 0; + } + else + { + value = 1; + px = x; + } + + for (count = value; count < 2; count++) + { + /*** Draw the string ***/ + for (i = 0; i < n; i++) + { + err = FT_Load_Char (face, text[i], FT_LOAD_RENDER); + + if (err) + { + printf ("Error %c %d\n", text[i], err); + continue; /*** Skip unprintable characters ***/ + } + + if (count) + DrawCharacter (&slot->bitmap, px + slot->bitmap_left, + y - slot->bitmap_top); + + px += slot->advance.x >> 6; + } + + px = (640 - px) >> 1; + + } +} + +/** + * setfontcolour + * + * Uses RGB triple values. + */ +void +setfontcolour (u8 r, u8 g, u8 b) +{ + u32 fontcolour; + + fontcolour = getcolour (r, g, b); + fonthi = fontcolour & 0xffff0000; + fontlo = fontcolour & 0xffff; +} + +/** + * Licence Information + * + * THIS MUST NOT BE REMOVED IN ANY DERIVATIVE WORK. + */ +void +licence () +{ + + int ypos = ((screenheight - (282 + dkpro_HEIGHT)) >> 1); + + if (screenheight == 480) + ypos += 42; + else + ypos += 24; + + setfontsize (16); + setfontcolour (0x00, 0x00, 0x00); + + DrawText (-1, ypos += 40, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006"); + + DrawText (-1, ypos += 40, (char*)"This is free software, and you are welcome to"); + DrawText (-1, ypos += 20, (char*)"redistribute it under the conditions of the"); + DrawText (-1, ypos += 20, (char*)"GNU GENERAL PUBLIC LICENSE Version 2"); + DrawText (-1, ypos += + 20, (char*)"Additionally, the developers of this port disclaim"); + DrawText (-1, ypos += + 20, (char*)"all copyright interests in the Nintendo GameCube"); + DrawText (-1, ypos += + 20, (char*)"porting code. You are free to use it as you wish"); + + DrawText (-1, ypos += 40, (char*)"Developed with DevkitPPC and libOGC"); + DrawText (-1, ypos += 20, (char*)"http://www.devkitpro.org"); + +} + +/** + * dkunpack + * + * Support function to expand the DevkitPro logo + */ +int +dkunpack () +{ + unsigned long res, inbytes, outbytes; + + inbytes = dkpro_COMPRESSED; + outbytes = dkpro_RAW; + dkproraw = (u32 *) malloc (dkpro_RAW + 16); + + res = uncompress ((Bytef *) dkproraw, &outbytes, (Bytef *) dkpro, inbytes); + + if (res == Z_OK) + return 1; + + return 0; +} + +/** + * showdklogo + * + * Display the DevkitPro logo + */ +void +showdklogo () +{ + int w, h, p, dispoffset; + p = 0; + dispoffset = + ((screenheight != 480 ? 365 : 355) * 320) + ((640 - dkpro_WIDTH) >> 2); + + dkunpack (); + + for (h = 0; h < dkpro_HEIGHT; h++) + { + for (w = 0; w < dkpro_WIDTH >> 1; w++) + { + if (dkproraw[p] != 0x00800080) + xfb[whichfb][dispoffset + w] = dkproraw[p++]; + else + p++; + } + + dispoffset += 320; + } + + free (dkproraw); +} + +/** + * getcolour + * + * Simply converts RGB to Y1CbY2Cr format + * + * I got this from a pastebin, so thanks to whoever originally wrote it! + */ + +unsigned int +getcolour (u8 r1, u8 g1, u8 b1) +{ + int y1, cb1, cr1, y2, cb2, cr2, cb, cr; + u8 r2, g2, b2; + + r2 = r1; + g2 = g1; + b2 = b1; + + y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000; + cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000; + cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000; + + y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000; + cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000; + cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000; + + cb = (cb1 + cb2) >> 1; + cr = (cr1 + cr2) >> 1; + + return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr); +} + +/** + * Unpackbackdrop + */ +void +unpackbackdrop () +{ + unsigned long res, inbytes, outbytes; + unsigned int colour; + int offset; + int i; + +// backdrop = (unsigned int *) malloc (screenheight * 1280); + backdrop = (u32 *) malloc (screenheight * 1280); + colour = getcolour (0x00, 0x00, 0x00); + + /*** Fill with black for now ***/ + for (i = 0; i < (320 * screenheight); i++) + backdrop[i] = colour; + + /*** If it's PAL50, need to move down a few lines ***/ + offset = ((screenheight - 480) >> 1) * 320; + inbytes = BG_COMPRESSED; + outbytes = BG_RAW; + + res = + uncompress ((Bytef *) backdrop + offset, &outbytes, (Bytef *) bg, + inbytes); + +#ifndef HW_RVL + /*** Now store the backdrop in ARAM ***/ + ARAMPut ((char *) backdrop, (char *) AR_BACKDROP, 640 * screenheight * 2); + free (backdrop); +#endif + // otherwise (on wii) backdrop is stored in memory + +} + +/** + * Display legal copyright and licence + */ +void +legal () +{ + unpackbackdrop (); + clearscreen (); + licence (); + showdklogo (); + showscreen (); +} + +/** + * Wait for user to press A + */ +void +WaitButtonA () +{ +#ifdef HW_RVL + while ( (PAD_ButtonsDown (0) & PAD_BUTTON_A) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) VIDEO_WaitVSync(); + while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) && !(WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) VIDEO_WaitVSync(); +#else + while ( PAD_ButtonsDown (0) & PAD_BUTTON_A ) VIDEO_WaitVSync(); + while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) ) VIDEO_WaitVSync(); +#endif +} + +/** + * Wait for user to press A or B. Returns 0 = B; 1 = A + */ + +int +WaitButtonAB () +{ +#ifdef HW_RVL + u32 gc_btns, wm_btns; + + while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) + || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B)) + ) VIDEO_WaitVSync(); + + while ( TRUE ) + { + gc_btns = PAD_ButtonsDown (0); + wm_btns = WPAD_ButtonsDown (0); + if ( (gc_btns & PAD_BUTTON_A) || (wm_btns & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) + return 1; + else if ( (gc_btns & PAD_BUTTON_B) || (wm_btns & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) + return 0; + } +#else + u32 gc_btns; + + while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) VIDEO_WaitVSync(); + + while ( TRUE ) + { + gc_btns = PAD_ButtonsDown (0); + if ( gc_btns & PAD_BUTTON_A ) + return 1; + else if ( gc_btns & PAD_BUTTON_B ) + return 0; + } +#endif +} + +/** + * Show a prompt + */ +void +WaitPrompt (char *msg) +{ + int ypos = (screenheight - 64) >> 1; + + if (screenheight == 480) + ypos += 52; + else + ypos += 32; + + clearscreen (); + DrawText (-1, ypos, msg); + ypos += 30; + DrawText (-1, ypos, (char*)"Press A to continue"); + showscreen (); + WaitButtonA (); +} + +/** + * Show a prompt with choice of two options. Returns 1 if A button was pressed + and 0 if B button was pressed. + */ +int +WaitPromptChoice (char *msg, char *bmsg, char *amsg) +{ + int ypos = (screenheight - 64) >> 1; + + if (screenheight == 480) + ypos += 37; + else + ypos += 17; + + clearscreen (); + DrawText (-1, ypos, msg); + ypos += 60; + char txt[80]; + sprintf (txt, "B = %s : A = %s", bmsg, amsg); + DrawText (-1, ypos, txt); + showscreen (); + return WaitButtonAB (); +} + +/** + * Show an action in progress + */ +void +ShowAction (char *msg) +{ + int ypos = (screenheight - 30) >> 1; + + if (screenheight == 480) + ypos += 52; + else + ypos += 32; + + clearscreen (); + DrawText (-1, ypos, msg); + showscreen (); +} + +/**************************************************************************** + * Generic Menu Routines + ****************************************************************************/ +void +DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsize) +{ + int i, w; + int ypos; + +#if 0 + int bounding[] = { 80, 40, 600, 40, 560, 94, 40, 94 }; + int base[] = { 80, screenheight - 90, 600, screenheight - 90, + 560, screenheight - 40, 40, screenheight - 40 + }; +#endif + + //ypos = (screenheight - (maxitems * 32)) >> 1; previous + ypos = (screenheight - (maxitems * (fontsize + 8))) >> 1; + + if (screenheight == 480) + ypos += 52; + else + ypos += 32; + + clearscreen (); + +//#if 0 +// DrawPolygon (4, bounding, 0x00, 0x00, 0xc0); +// DrawPolygon (4, base, 0x00, 0x00, 0xc0); + setfontsize (30); + if (title != NULL) + DrawText (-1, 60, title); + setfontsize (12); + DrawText (510, screenheight - 20, "Snes9x GX 003"); +//#endif + + setfontsize (fontsize); // set font size + setfontcolour (0, 0, 0); + + for (i = 0; i < maxitems; i++) + { + if (i == selected) + { + //for( w = 0; w < 32; w++ ) + for( w = 0; w < (fontsize + 8); w++ ) + //DrawLineFast( 30, 610, (i << 5) + (ypos-26) + w, 0x80, 0x80, 0x80 ); previous + DrawLineFast( 30, 610, i * (fontsize + 8) + (ypos-(fontsize + 2)) + w, 0x80, 0x80, 0x80 ); + + setfontcolour (0xff, 0xff, 0xff); + //DrawText (-1, (i << 5) + ypos, items[i]); previous + DrawText (-1, i * (fontsize + 8) + ypos, items[i]); + setfontcolour (0x00, 0x00, 0x00); + } + else + DrawText (-1, i * (fontsize + 8) + ypos, items[i]); + //DrawText (-1, i * 32 + ypos, items[i]); previous + } + + showscreen (); + +} + +/**************************************************************************** + * RunMenu + * + * Call this with the menu array defined in menu.cpp + * It's here to keep all the font / interface stuff together. + ****************************************************************************/ +int menu = 0; +int +RunMenu (char items[][20], int maxitems, char *title, int fontsize) +{ + int redraw = 1; + int quit = 0; + u32 p, wp; + int ret = 0; + signed char a; + float mag = 0; + u16 ang = 0; + + //while (!(PAD_ButtonsDown (0) & PAD_BUTTON_B) && (quit == 0)) + while (quit == 0) + { + if (redraw) + { + DrawMenu (&items[0], title, maxitems, menu, fontsize); + redraw = 0; + } + + p = PAD_ButtonsDown (0); +#ifdef HW_RVL + wp = WPAD_ButtonsDown (0); + wpad_get_analogues(0, &mag, &ang); // get joystick info from wii expansions +#else + wp = 0; +#endif + a = PAD_StickY (0); + + VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads + + /*** Look for up ***/ + if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > 70) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) ) + { + redraw = 1; + menu--; + } + + /*** Look for down ***/ + if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -70) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) ) + { + redraw = 1; + menu++; + } + + if ((p & PAD_BUTTON_A) || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A))) + { + quit = 1; + ret = menu; + } + + if ((p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))) + { + quit = -1; + ret = -1; + } + + if (menu == maxitems) + menu = 0; + + if (menu < 0) + menu = maxitems - 1; + } + + /*** Wait for B button to be released before proceeding ***/ + while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) +#ifdef HW_RVL + || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) +#endif + ) + { + ret = -1; + VIDEO_WaitVSync(); + } + + return ret; + +} + +/**************************************************************************** + * DrawLine + * + * Quick'n'Dirty Bresenham line drawing routine. + ****************************************************************************/ +#define SIGN(x) ((x<0)?-1:((x>0)?1:0)) + +void +DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b) +{ + u32 colour, pixel; + u32 colourhi, colourlo; + int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py; + int sp; + + colour = getcolour (r, g, b); + colourhi = colour & 0xffff0000; + colourlo = colour & 0xffff; + + dx = x2 - x1; /*** Horizontal distance ***/ + dy = y2 - y1; /*** Vertical distance ***/ + + dxabs = abs (dx); + dyabs = abs (dy); + sdx = SIGN (dx); + sdy = SIGN (dy); + x = dyabs >> 1; + y = dxabs >> 1; + px = x1; + py = y1; + + sp = (py * 320) + (px >> 1); + pixel = xfb[whichfb][sp]; + /*** Plot this pixel ***/ + if (px & 1) + xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; + else + xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; + + if (dxabs >= dyabs) /*** Mostly horizontal ***/ + { + for (i = 0; i < dxabs; i++) + { + y += dyabs; + if (y >= dxabs) + { + y -= dxabs; + py += sdy; + } + + px += sdx; + + sp = (py * 320) + (px >> 1); + pixel = xfb[whichfb][sp]; + + if (px & 1) + xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; + else + xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; + } + } + else + { + for (i = 0; i < dyabs; i++) + { + x += dxabs; + if (x >= dyabs) + { + x -= dyabs; + px += sdx; + } + + py += sdy; + + sp = (py * 320) + (px >> 1); + pixel = xfb[whichfb][sp]; + + if (px & 1) + xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; + else + xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; + } + } +} + +/**************************************************************************** + * Progress Bar + * + * Show the user what's happening + ****************************************************************************/ +void +ShowProgress (char *msg, int done, int total) +{ + int ypos = (screenheight - 30) >> 1; + + if (screenheight == 480) + ypos += 52; + else + ypos += 32; + + int xpos; + int i; + + clearscreen (); + DrawText (-1, ypos, msg); + + /*** Draw a white outline box ***/ + for (i = 380; i < 401; i++) + DrawLine (100, i, 540, i, 0xff, 0xff, 0xff); + + /*** Show progess ***/ + xpos = (int) (((float) done / (float) total) * 438); + + for (i = 381; i < 400; i++) + DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80); + + showscreen (); +} + +/**************************************************************************** + * DrawPolygon + ****************************************************************************/ +void +DrawPolygon (int vertices, int varray[], u8 r, u8 g, u8 b) +{ + int i; + + for (i = 0; i < vertices - 1; i++) + { + DrawLine (varray[(i << 1)], varray[(i << 1) + 1], varray[(i << 1) + 2], + varray[(i << 1) + 3], r, g, b); + } + + DrawLine (varray[0], varray[1], varray[(vertices << 1) - 2], + varray[(vertices << 1) - 1], r, g, b); +} + +/***************************************************************************** + * Draw Line Fast + * + * This routine requires that start and endx are 32bit aligned. + * It tries to perform a semi-transparency over the existing image. + *****************************************************************************/ + +#define SRCWEIGHT 0.7f +#define DSTWEIGHT (1.0f - SRCWEIGHT) + +static inline u8 c_adjust( u8 c , float weight ) +{ + return (u8)((float)c * weight); +} + +void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ) +{ + int width; + u32 offset; + int i; + u32 colour, clo, chi; + u32 lo,hi; + u8 *s, *d; + + //colour = getcolour(r, g, b); + colour = ( r << 16 | g << 8 | b ); + d = (u8 *)&colour; + d[1] = c_adjust(d[1], DSTWEIGHT); + d[2] = c_adjust(d[2], DSTWEIGHT); + d[3] = c_adjust(d[3], DSTWEIGHT); + + width = ( endx - startx ) >> 1; + offset = ( y << 8 ) + ( y << 6 ) + ( startx >> 1 ); + + for ( i = 0; i < width; i++ ) + { + lo = getrgb(xfb[whichfb][offset], 0); + hi = getrgb(xfb[whichfb][offset], 1); + + s = (u8 *)&hi; + s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); + s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); + s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] ); + + s = (u8 *)&lo; + s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); + s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); + s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] ); + + clo = getcolour( s[1], s[2], s[3] ); + s = (u8 *)&hi; + chi = getcolour( s[1], s[2], s[3] ); + + xfb[whichfb][offset++] = (chi & 0xffff0000 ) | ( clo & 0xffff) ; + } +} + +/** + * Ok, I'm useless with Y1CBY2CR colour. + * So convert back to RGB so I can work with it -;) + */ +u32 getrgb( u32 ycbr, u32 low ) +{ + u8 r,g,b; + u32 y; + s8 cb,cr; + + if ( low ) + y = ( ycbr & 0xff00 ) >> 8; + else + y = ( ycbr & 0xff000000 ) >> 24; + + cr = ycbr & 0xff; + cb = ( ycbr & 0xff0000 ) >> 16; + + cr -= 128; + cb -= 128; + + r = (u8)((float)y + 1.371 * (float)cr); + g = (u8)((float)y - 0.698 * (float)cr - 0.336 * (float)cb); + b = (u8)((float)y + 1.732 * (float)cb); + + return (u32)( r << 16 | g << 8 | b ); + +} + + diff --git a/source/ngc/menudraw.h b/source/ngc/ftfont.h similarity index 51% rename from source/ngc/menudraw.h rename to source/ngc/ftfont.h index 83ecfabb..c6ac86d3 100644 --- a/source/ngc/menudraw.h +++ b/source/ngc/ftfont.h @@ -1,42 +1,34 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * crunchy2 June 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * menudraw.h - * - * Menu drawing routines + * Nintendo Gamecube Screen Font Driver * * Uses libfreetype 2.2.1 compiled for GC with TTF support only. - * TTF only reduces the library by some 900k bytes! + * TTF only reduces the library by some 900kbytes! + * + * Visit - http://www.freetype.org ! * * **WARNING*** * * ONLY USE GUARANTEED PATENT FREE FONTS. - ***************************************************************************/ -#ifndef _NGCMENUDRAW_ -#define _NGCMENUDRAW_ - -#include "filesel.h" - -#define PAGESIZE 17 // max item listing on a screen + * THOSE IN YOUR WINDOWS\FONTS DIRECTORY ARE COPYRIGHT + * AND MAY NOT BE DISTRIBUTED! + * + * softdev July 2006 + * crunchy2 June 2007 + ****************************************************************************/ +#ifndef _TTFFONTS_ +#define _TTFFONTS_ int FT_Init (); void setfontsize (int pixelsize); -void setfontcolour (u8 r, u8 g, u8 b); void DrawText (int x, int y, char *text); -void unpackbackdrop (); -void Credits (); -void RomInfo (); +void legal (); +void highlight (int on); void WaitButtonA (); -int RunMenu (char items[][50], int maxitems, char *title, int fontsize = 20, int x = -1); -void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize = 20, int x = -1); -void ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection); -void ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection); - +void setfontcolour (u8 r, u8 g, u8 b); +int RunMenu (char items[][20], int maxitems, char *title, int fontsize = 24); +void DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsize = 24); void WaitPrompt (char *msg); int WaitPromptChoice (char *msg, char* bmsg, char* amsg); void ShowAction (char *msg); diff --git a/source/ngc/images/saveicon.h b/source/ngc/gcglobals.cpp similarity index 60% rename from source/ngc/images/saveicon.h rename to source/ngc/gcglobals.cpp index 51e211f8..b4cb1df8 100644 --- a/source/ngc/images/saveicon.h +++ b/source/ngc/gcglobals.cpp @@ -1,139 +1,281 @@ -/* - * File : saveicon.bmp -*/ - -#ifndef _IMGSAVEICON_ -#define _IMGSAVEICON_ - -const unsigned short saveicon[1024] = { - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xE73F, - 0xFFFF, 0xFFFF, 0xB5BF, 0x801F, 0xFFFF, 0xD29F, 0x801F, 0x801F, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xA11E, 0x843C, 0x8439, 0x9CF7, - 0x801F, 0x801F, 0x801C, 0x8018, 0x801F, 0x801F, 0x801C, 0x8018, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xEB5C, 0xFFFF, 0xFFFF, 0xFFFF, - 0x800F, 0xB9D3, 0xFFFF, 0xFFFF, 0x8013, 0x8008, 0xDAD7, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0x801F, 0x801F, 0x885F, 0xFFFF, 0x98D6, 0x801F, 0x801F, - 0xFFFF, 0xFFFF, 0xFFFF, 0x843C, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFBDF, 0x801E, 0x801B, 0x8017, 0x801E, 0x801B, 0x8018, 0x8015, - 0x801A, 0x8018, 0x8015, 0x8011, 0x8016, 0x8014, 0x8011, 0x800D, - 0x8012, 0x800B, 0x8848, 0xFFFF, 0x8010, 0x8009, 0x8003, 0xFFFF, - 0x800C, 0x8007, 0x8006, 0xFFFF, 0x8008, 0x8005, 0xA52E, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFBBD, 0xF1EF, 0xFFFF, 0xF508, 0xF000, 0xEC00, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xE56B, 0xE16B, 0xE673, 0xFFFF, 0xE800, 0xDC00, 0xCC00, 0xB400, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xDE94, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xEBBA, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xEFBA, 0xE378, 0xB2EB, 0x9AA4, 0x9AA5, 0x9AA5, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xE778, 0xF3BC, 0xFFFF, 0xFFFF, 0x9A84, 0x9623, 0x91E3, 0xB66C, - 0xD6BB, 0x800E, 0x800C, 0x8008, 0xFFFF, 0x8C6A, 0x8004, 0x8004, - 0xFFFF, 0xFFFF, 0xB191, 0xDAD8, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0x8006, 0x8004, 0xFFFF, 0xFFFF, 0x8006, 0xF39D, 0xFFFF, 0xFA94, - 0xFFFF, 0xFFFF, 0xFFFF, 0xEC21, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xF484, 0xF800, 0xF800, 0xF000, 0xF800, 0xF800, 0xFD6B, 0xF8C6, - 0xF400, 0xF400, 0xFDEF, 0xF4A5, 0xFF18, 0xEC63, 0xE400, 0xE000, - 0xE800, 0xE000, 0xD400, 0xC400, 0xE400, 0xE000, 0xD000, 0xC400, - 0xE000, 0xD800, 0xCC00, 0xC000, 0xD800, 0xD000, 0xC400, 0xB800, - 0xA400, 0xD673, 0xFFFF, 0xFFFF, 0xB400, 0x9000, 0xFFFF, 0xFFFF, - 0xB000, 0x9000, 0xFFFF, 0xFFFF, 0xA800, 0x9000, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xDB75, 0x9AE4, 0xFFFF, 0xFFFF, 0x9A84, 0xA6E7, - 0xFFFF, 0xFFFF, 0xA1E7, 0x9604, 0xFFFF, 0xFFFF, 0xFFFF, 0x8D03, - 0xA707, 0xA708, 0xAF2A, 0xAF2A, 0xA6E7, 0xA2C7, 0xBF4E, 0xCB71, - 0x9E46, 0x9E26, 0x9A25, 0x9604, 0x80E0, 0x8922, 0x8D22, 0x8D22, - 0xA2C7, 0xA2A7, 0x9E66, 0x95E4, 0xA2A6, 0x9E46, 0x9E25, 0x95C4, - 0x99E5, 0x95C4, 0x9163, 0x8D02, 0x88E2, 0x84A1, 0x8060, 0x8020, - 0x8500, 0xF7BD, 0xFFFF, 0xFFFF, 0x8901, 0xA148, 0xFFFF, 0xFFFF, - 0x8040, 0xB9ED, 0xFFFF, 0xFFFF, 0x9926, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xE529, 0xD400, 0xFFFF, 0xFFFF, 0xFFFF, 0xD4C6, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xD000, 0xC400, 0xBC00, 0xB000, 0xC000, 0xB800, 0xAC00, 0xA000, - 0xA800, 0xA800, 0x9C00, 0x9400, 0xC18C, 0x8C00, 0x8C00, 0x8C00, - 0x9C00, 0x8C00, 0xFFFF, 0xFFFF, 0x9400, 0x8C00, 0xFFFF, 0xFFFF, - 0x8800, 0xDEB5, 0xFFFF, 0xFFFF, 0xE2D6, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xD6D5, 0xAD8A, 0x8CC3, 0x8060, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0x8060, 0x90E4, 0xB1CC, 0xE759, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, 0xF7AF, - 0xFFFF, 0xFFFF, 0xFBDC, 0xF7B1, 0xFFFB, 0xFFE2, 0xFFE0, 0xFFE0, - 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE5, - 0xF38C, 0xEF6A, 0xEB4B, 0xEB4F, 0xFFE0, 0xFBC0, 0xF7A0, 0xEB40, - 0xFFE0, 0xFFE0, 0xFBC0, 0xF7A0, 0xFFF5, 0xFFE4, 0xF380, 0xEF60, - 0xEF76, 0xFFFF, 0xFFFF, 0xFFFF, 0xE300, 0xCE60, 0xD6AB, 0xFFFF, - 0xEB40, 0xE300, 0xCE60, 0xB180, 0xE720, 0xDEE0, 0xCE60, 0xB180, - 0xF7BD, 0xB96B, 0xDAB4, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xB9CA, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xF399, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xD280, 0xEB40, 0xEB40, 0xEB40, 0xDAD1, 0xAD60, 0xC200, 0xCA40, - 0xFFFF, 0xF7BE, 0xBDEB, 0x98C0, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xEB40, 0xE720, 0xE300, 0xDAC0, 0xCA40, 0xC620, 0xC200, 0xBDE0, - 0x9080, 0x94A0, 0x94A0, 0x9080, 0xFBDD, 0xE738, 0xE337, 0xE738, - 0xD280, 0xCA40, 0xB5A0, 0x98C0, 0xB180, 0xA100, 0x94A0, 0x9080, - 0x8C60, 0x9080, 0xC20C, 0xFFFF, 0xF7BD, 0xFFFF, 0xFFFF, 0xFFFF, - 0xB9C9, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, - 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, -}; - -#endif +/********************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +**********************************************************************************/ + +#include "snes9xGx.h" +START_EXTERN_C +struct SGCSettings GCSettings; +bool8 isWii; + +unsigned short saveicon[1024] = { + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xE73F, + 0xFFFF, 0xFFFF, 0xB5BF, 0x801F, 0xFFFF, 0xD29F, 0x801F, 0x801F, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xA11E, 0x843C, 0x8439, 0x9CF7, + 0x801F, 0x801F, 0x801C, 0x8018, 0x801F, 0x801F, 0x801C, 0x8018, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xEB5C, 0xFFFF, 0xFFFF, 0xFFFF, + 0x800F, 0xB9D3, 0xFFFF, 0xFFFF, 0x8013, 0x8008, 0xDAD7, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0x801F, 0x801F, 0x885F, 0xFFFF, 0x98D6, 0x801F, 0x801F, + 0xFFFF, 0xFFFF, 0xFFFF, 0x843C, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFBDF, 0x801E, 0x801B, 0x8017, 0x801E, 0x801B, 0x8018, 0x8015, + 0x801A, 0x8018, 0x8015, 0x8011, 0x8016, 0x8014, 0x8011, 0x800D, + 0x8012, 0x800B, 0x8848, 0xFFFF, 0x8010, 0x8009, 0x8003, 0xFFFF, + 0x800C, 0x8007, 0x8006, 0xFFFF, 0x8008, 0x8005, 0xA52E, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFBBD, 0xF1EF, 0xFFFF, 0xF508, 0xF000, 0xEC00, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xE56B, 0xE16B, 0xE673, 0xFFFF, 0xE800, 0xDC00, 0xCC00, 0xB400, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xDE94, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xEBBA, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xEFBA, 0xE378, 0xB2EB, 0x9AA4, 0x9AA5, 0x9AA5, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xE778, 0xF3BC, 0xFFFF, 0xFFFF, 0x9A84, 0x9623, 0x91E3, 0xB66C, + 0xD6BB, 0x800E, 0x800C, 0x8008, 0xFFFF, 0x8C6A, 0x8004, 0x8004, + 0xFFFF, 0xFFFF, 0xB191, 0xDAD8, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0x8006, 0x8004, 0xFFFF, 0xFFFF, 0x8006, 0xF39D, 0xFFFF, 0xFA94, + 0xFFFF, 0xFFFF, 0xFFFF, 0xEC21, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xF484, 0xF800, 0xF800, 0xF000, 0xF800, 0xF800, 0xFD6B, 0xF8C6, + 0xF400, 0xF400, 0xFDEF, 0xF4A5, 0xFF18, 0xEC63, 0xE400, 0xE000, + 0xE800, 0xE000, 0xD400, 0xC400, 0xE400, 0xE000, 0xD000, 0xC400, + 0xE000, 0xD800, 0xCC00, 0xC000, 0xD800, 0xD000, 0xC400, 0xB800, + 0xA400, 0xD673, 0xFFFF, 0xFFFF, 0xB400, 0x9000, 0xFFFF, 0xFFFF, + 0xB000, 0x9000, 0xFFFF, 0xFFFF, 0xA800, 0x9000, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xDB75, 0x9AE4, 0xFFFF, 0xFFFF, 0x9A84, 0xA6E7, + 0xFFFF, 0xFFFF, 0xA1E7, 0x9604, 0xFFFF, 0xFFFF, 0xFFFF, 0x8D03, + 0xA707, 0xA708, 0xAF2A, 0xAF2A, 0xA6E7, 0xA2C7, 0xBF4E, 0xCB71, + 0x9E46, 0x9E26, 0x9A25, 0x9604, 0x80E0, 0x8922, 0x8D22, 0x8D22, + 0xA2C7, 0xA2A7, 0x9E66, 0x95E4, 0xA2A6, 0x9E46, 0x9E25, 0x95C4, + 0x99E5, 0x95C4, 0x9163, 0x8D02, 0x88E2, 0x84A1, 0x8060, 0x8020, + 0x8500, 0xF7BD, 0xFFFF, 0xFFFF, 0x8901, 0xA148, 0xFFFF, 0xFFFF, + 0x8040, 0xB9ED, 0xFFFF, 0xFFFF, 0x9926, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xE529, 0xD400, 0xFFFF, 0xFFFF, 0xFFFF, 0xD4C6, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xD000, 0xC400, 0xBC00, 0xB000, 0xC000, 0xB800, 0xAC00, 0xA000, + 0xA800, 0xA800, 0x9C00, 0x9400, 0xC18C, 0x8C00, 0x8C00, 0x8C00, + 0x9C00, 0x8C00, 0xFFFF, 0xFFFF, 0x9400, 0x8C00, 0xFFFF, 0xFFFF, + 0x8800, 0xDEB5, 0xFFFF, 0xFFFF, 0xE2D6, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xD6D5, 0xAD8A, 0x8CC3, 0x8060, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0x8060, 0x90E4, 0xB1CC, 0xE759, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, 0xF7AF, + 0xFFFF, 0xFFFF, 0xFBDC, 0xF7B1, 0xFFFB, 0xFFE2, 0xFFE0, 0xFFE0, + 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE0, 0xFFE5, + 0xF38C, 0xEF6A, 0xEB4B, 0xEB4F, 0xFFE0, 0xFBC0, 0xF7A0, 0xEB40, + 0xFFE0, 0xFFE0, 0xFBC0, 0xF7A0, 0xFFF5, 0xFFE4, 0xF380, 0xEF60, + 0xEF76, 0xFFFF, 0xFFFF, 0xFFFF, 0xE300, 0xCE60, 0xD6AB, 0xFFFF, + 0xEB40, 0xE300, 0xCE60, 0xB180, 0xE720, 0xDEE0, 0xCE60, 0xB180, + 0xF7BD, 0xB96B, 0xDAB4, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xB9CA, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xF399, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xD280, 0xEB40, 0xEB40, 0xEB40, 0xDAD1, 0xAD60, 0xC200, 0xCA40, + 0xFFFF, 0xF7BE, 0xBDEB, 0x98C0, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xEB40, 0xE720, 0xE300, 0xDAC0, 0xCA40, 0xC620, 0xC200, 0xBDE0, + 0x9080, 0x94A0, 0x94A0, 0x9080, 0xFBDD, 0xE738, 0xE337, 0xE738, + 0xD280, 0xCA40, 0xB5A0, 0x98C0, 0xB180, 0xA100, 0x94A0, 0x9080, + 0x8C60, 0x9080, 0xC20C, 0xFFFF, 0xF7BD, 0xFFFF, 0xFFFF, 0xFFFF, + 0xB9C9, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, +}; + +END_EXTERN_C + diff --git a/source/ngc/gctime.cpp b/source/ngc/gctime.cpp new file mode 100644 index 00000000..0f45cf6f --- /dev/null +++ b/source/ngc/gctime.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** + * gctime.cpp + ****************************************************************************/ +#include "gctime.h" + +#define TB_CLOCK 40500000 + + +unsigned long tb_diff_msec(tb_t *end, tb_t *start) +{ + unsigned long upper, lower; + upper = end->u - start->u; + if (start->l > end->l) + upper--; + lower = end->l - start->l; + return ((upper*((unsigned long)0x80000000/(TB_CLOCK/2000))) + (lower/(TB_CLOCK/1000))); +} + +unsigned long tb_diff_usec(tb_t *end, tb_t *start) +{ + unsigned long upper, lower; + upper = end->u - start->u; + if (start->l > end->l) + upper--; + lower = end->l - start->l; + return ((upper*((unsigned long)0x80000000/(TB_CLOCK/2000000))) + (lower/(TB_CLOCK/1000000))); +} + +void udelay(unsigned int us) +{ + tb_t start, end; + mftb(&start); + while (1) + { + mftb(&end); + if (tb_diff_usec(&end, &start) >= us) + break; + } +} + +void mdelay(unsigned int ms) +{ + tb_t start, end; + mftb(&start); + while (1) + { + mftb(&end); + if (tb_diff_msec(&end, &start) >= ms) + break; + } +} diff --git a/source/ngc/cheatmgr.h b/source/ngc/gctime.h similarity index 50% rename from source/ngc/cheatmgr.h rename to source/ngc/gctime.h index 6ff8130f..247d156e 100644 --- a/source/ngc/cheatmgr.h +++ b/source/ngc/gctime.h @@ -1,11 +1,10 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * Tantric August 2008 - * - * cheatmgr.h - * - * Cheat handling - ***************************************************************************/ + * gctime.h + ****************************************************************************/ -void SetupCheats(); +extern "C" { + +long long gettime(); +u32 diff_usec(long long start,long long end); + +} diff --git a/source/ngc/images/gfx_bg.h b/source/ngc/gfx_bg.h similarity index 99% rename from source/ngc/images/gfx_bg.h rename to source/ngc/gfx_bg.h index 16a16bb2..8105be26 100644 --- a/source/ngc/images/gfx_bg.h +++ b/source/ngc/gfx_bg.h @@ -3,16 +3,12 @@ * Width : 640 * Height: 480 */ - -#ifndef _IMGBG_ -#define _IMGBG_ - #define BG_WIDTH (640) #define BG_HEIGHT (480) #define BG_RAW (614400) #define BG_COMPRESSED (8789) -const unsigned char bg[]= + static unsigned char bg[]= { 0x78,0x9c,0xed,0xdd,0x77,0xb0,0x94,0xf5,0xbd,0xf8,0x71,0x9d,0x4c, 0x26,0xe3,0x24,0x93,0xdc,0xeb,0xe4,0xc6,0x4b,0x20,0x89,0xf1,0xc6, @@ -693,4 +689,3 @@ const unsigned char bg[]= 0x14,0x14 }; -#endif diff --git a/source/ngc/gui.cpp b/source/ngc/gui.cpp deleted file mode 100644 index 36a60c6e..00000000 --- a/source/ngc/gui.cpp +++ /dev/null @@ -1,568 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * Michniewski 2008 - * - * gui.cpp - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include FT_FREETYPE_H - -#include "video.h" -#include "snes9xGX.h" -#include "gui.h" - -struct sGui Gui; - -GXTexObj texobj_BG, texobj_MENU; -void * texdata_bg; // stores the blended menu backdrop -void * texdata_menu; // stores the menu overlay - -bool mem_alloced = 0; - -extern GXTexObj texobj; -extern int vwidth, vheight; -extern s16 square[]; -extern Mtx view; -extern int whichfb; -extern unsigned int copynow; -extern int screenheight; -extern unsigned int *xfb[2]; -extern GXRModeObj *vmode; - -extern FT_Library ftlibrary; -extern FT_Face face; -extern FT_GlyphSlot slot; -extern FT_UInt glyph_index; - -extern int WaitButtonAB (); - - -// MAIN - -static void -draw_vert (u8 pos, u8 c, f32 s, f32 t) -{ - GX_Position1x8 (pos); - GX_Color1x8 (c); - GX_TexCoord2f32 (s, t); -} - -static void -draw_square (Mtx v) -{ - Mtx m; // model matrix. - Mtx mv; // modelview matrix. - - guMtxIdentity (m); - guMtxTransApply (m, m, 0, 0, -100); - guMtxConcat (v, m, mv); - - GX_LoadPosMtxImm (mv, GX_PNMTX0); - GX_Begin (GX_QUADS, GX_VTXFMT0, 4); - draw_vert (0, 0, 0.0, 0.0); - draw_vert (1, 0, 1.0, 0.0); - draw_vert (2, 0, 1.0, 1.0); - draw_vert (3, 0, 0.0, 1.0); - GX_End (); -} - -void -gui_alphasetup () -{ - GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); - GX_SetAlphaUpdate(GX_ENABLE); -} - -void -gui_alloc () -{ - if (!mem_alloced) - { - texdata_bg = memalign (32, 640 * 480 * 4); - texdata_menu = memalign (32, 640 * 480 * 4); - Gui.texmem = memalign (32, 640 * 480 * 4); - - mem_alloced = 1; - } -} - -void -gui_free () -{ - if (mem_alloced) - { - free (texdata_bg); - free (texdata_menu); - free (Gui.texmem); - - mem_alloced = 0; - } -} - -/**************************************************************************** -* make BG -* -* Blend the last rendered emulator screen and the menu backdrop. -* Save this as a texture to be loaded later - ****************************************************************************/ -void -gui_makebg () -{ - IMGCTX ctx; - PNGUPROP imgProp; - - /** Load menu backdrop (either from file or buffer) **/ - - ctx = PNGU_SelectImageFromDevice ("bg.png"); - PNGU_GetImageProperties (ctx, &imgProp); - // can check image dimensions here - //texdata_bg = memalign (32, imgProp.imgWidth * imgProp.imgHeight * 4); - GX_InitTexObj (&texobj_BG, &texdata_bg, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - //PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, &texdata_bg, 255); - PNGU_DecodeToRGBA8 (ctx, 640, 480, Gui.texmem, 0, 7); - Make_Texture_RGBA8 (&texdata_bg, Gui.texmem, 640, 480); - PNGU_ReleaseImageContext (ctx); - DCFlushRange (&texdata_bg, imgProp.imgWidth * imgProp.imgHeight * 4); - - /* - texdata_bg = memalign (32, 640 * 480 * 4); - #ifdef HW_RVL - // on wii copy from memory - memcpy (texdata_bg, (char *) backdrop, 640 * 480 * 2); - #else - // on gc copy from aram - ARAMFetch (texdata_bg, (char *) AR_BACKDROP, 640 * 480 * 2); - #endif - */ - - /** blend last rendered snes frame and menu backdrop **/ - - // draw 640x480 quads - int xscale, yscale, xshift, yshift; - xshift = yshift = 0; - xscale = 320; - yscale = 240; - square[6] = square[3] = xscale + xshift; - square[0] = square[9] = -xscale + xshift; - square[4] = square[1] = yscale + yshift; - square[7] = square[10] = -yscale + yshift; - - // draw 2 quads - - GX_InvalidateTexAll (); - - // behind (last snes frame) - square[2] = square[5] = square[8] = square[11] = 0; // z value - GX_InvVtxCache (); - GX_LoadTexObj (&texobj, GX_TEXMAP0); // load last rendered snes frame - draw_square (view); - - // in front (menu backdrop) - square[2] = square[5] = square[8] = square[11] = 1; // z value - GX_InvVtxCache (); - GX_LoadTexObj (&texobj_BG, GX_TEXMAP0); - draw_square (view); - - GX_DrawDone (); - - /* DEBUG ----------- - // show the output - VIDEO_SetNextFramebuffer (xfb[whichfb]); - VIDEO_Flush (); - copynow = GX_TRUE; - #ifdef VIDEO_THREADING - // Return to caller, don't waste time waiting for vb - LWP_ResumeThread (vbthread); - #endif - WaitButtonAB(); - */ - - // load blended image from efb to a texture - GX_InitTexObj (&texobj_BG, &texdata_bg, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GX_SetTexCopySrc ( 0,0,640,480 ); - GX_SetTexCopyDst ( 640, 480, GX_TF_RGBA8, 0 ); - GX_CopyTex (&texdata_bg, 0); // assuming that the efb is 640x480, which it should be - GX_PixModeSync (); // wait until copy has completed - DCFlushRange (&texdata_bg, 640 * 480 * 4); - - - square[2] = square[5] = square[8] = square[11] = 0; // reset z value - GX_InvVtxCache (); -} - -void -gui_clearscreen () -{ - whichfb ^= 1; - VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK); - memset ( Gui.texmem, 0, sizeof(Gui.texmem) ); - Gui.fontcolour = 0; -} - -void -gui_draw () -{ - gui_drawbox (0, 0, 640, 80, 255, 255, 255, 128); // topbar - gui_drawbox (0, 370, 640, 480, 255, 255, 255, 128); // bottombar - gui_setfontcolour (0,255,0,255); - // top bar text - setfontsize (32); // 32/24 depending on whether selected or not - gui_DrawText (-1, 35, (char *)"Menu"); - // main text - setfontsize (24); - gui_DrawText (75, 113, (char *)"Hello World"); - // bottom bar text - setfontsize (24); - gui_DrawText (75, 400, (char *)"Description"); -} - -void -gui_savescreen () -{ - FILE* handle; - handle = fopen ("out.txt", "wb"); - fwrite (Gui.texmem, 1, sizeof(Gui.texmem), handle); - fclose (handle); - - printf("\nsaved screen."); -} - -void -gui_showscreen () -{ - - /** Screen to Texture **/ - - GX_InitTexObj (&texobj_MENU, texdata_menu, 640, 480, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - Make_Texture_RGBA8 (texdata_menu, Gui.texmem, 640, 480); - DCFlushRange (&texdata_menu, 640 * 480 * 4); - - GX_InvalidateTexAll (); - - /** thats nice, but will it blend? **/ - - // draw 640x480 quads - int xscale, yscale, xshift, yshift; - xshift = yshift = 0; - xscale = 320; - yscale = 240; - square[6] = square[3] = xscale + xshift; - square[0] = square[9] = -xscale + xshift; - square[4] = square[1] = yscale + yshift; - square[7] = square[10] = -yscale + yshift; - - // draw 2 quads - - // backdrop - square[2] = square[5] = square[8] = square[11] = 0; // z value - GX_InvVtxCache (); - GX_LoadTexObj (&texobj_BG, GX_TEXMAP0); - draw_square (view); - - // menu overlay - square[2] = square[5] = square[8] = square[11] = 1; // z value - GX_InvVtxCache (); - GX_LoadTexObj (&texobj_MENU, GX_TEXMAP0); - draw_square (view); - - GX_DrawDone (); - - /** Display **/ - - // show the output - VIDEO_SetNextFramebuffer (xfb[whichfb]); - VIDEO_Flush (); - copynow = GX_TRUE; - #ifdef VIDEO_THREADING - /* Return to caller, don't waste time waiting for vb */ - LWP_ResumeThread (vbthread); - #endif - WaitButtonAB(); - - square[2] = square[5] = square[8] = square[11] = 0; // z value - GX_InvVtxCache (); -} - -/**************************************************************************** -* Make Texture RGBA8 -* -* input: pointer to RGBA data -* output: formatted texture data (GX_TF_RGBA8) -* code modified from quake wii (thanks :) -* todo: fix last few lines (?) - ****************************************************************************/ -void -Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height) -{ - if ( (width % 4) || (height % 4) ) { - printf ("Error: make_texture_rgba8 width/height not multiple of 4"); - return; - } - - int i, x, y; - u8 *pos; - - pos = (u8 *)dst_tex; - for (y = 0; y < height; y += 4) // process 4 lines at a time to make rows of tiles - { - u8* row1 = (u8 *) src_data; - u8* row2 = (u8 *) src_data; - u8* row3 = (u8 *) src_data; - u8* row4 = (u8 *) src_data; - row1 += width * 4 * (y + 0); // move 640 pixels x 4 bytes * line # - row2 += width * 4 * (y + 1); - row3 += width * 4 * (y + 2); - row4 += width * 4 * (y + 3); - - for (x = 0; x < width; x += 4) // move across 4 pixels per tile - { - u8 AR[32]; - u8 GB[32]; - - for (i = 0; i < 4; i++) // save those 4 pixels of data in texture format - { - u8* ptr1 = &(row1[(x + i) * 4]); // start at beginning of a row - u8* ptr2 = &(row2[(x + i) * 4]); // move across (4 pixels per tile + pixel offset within tile) * 4 bytes per pixel - u8* ptr3 = &(row3[(x + i) * 4]); - u8* ptr4 = &(row4[(x + i) * 4]); - - AR[(i * 2) + 0] = ptr1[3]; // fill columns of tile with rgba data - AR[(i * 2) + 1] = ptr1[0]; - AR[(i * 2) + 8] = ptr2[3]; - AR[(i * 2) + 9] = ptr2[0]; - AR[(i * 2) + 16] = ptr3[3]; - AR[(i * 2) + 17] = ptr3[0]; - AR[(i * 2) + 24] = ptr4[3]; - AR[(i * 2) + 25] = ptr4[0]; - - GB[(i * 2) + 0] = ptr1[1]; - GB[(i * 2) + 1] = ptr1[2]; - GB[(i * 2) + 8] = ptr2[1]; - GB[(i * 2) + 9] = ptr2[2]; - GB[(i * 2) + 16] = ptr3[1]; - GB[(i * 2) + 17] = ptr3[2]; - GB[(i * 2) + 24] = ptr4[1]; - GB[(i * 2) + 25] = ptr4[2]; - } - - memcpy(pos, AR, sizeof(AR)); // copy over to resulting texture - pos += sizeof(AR); - memcpy(pos, GB, sizeof(GB)); - pos += sizeof(GB); - } - } - -} - -void -gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a) -{ - u32 colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a; - - int i, j; - - u32* memory = (u32*) Gui.texmem; - for (j = y1; jwidth; - FT_Int y_max = y + bmp->rows; - int c; - - u32* memory = (u32*)Gui.texmem; - for (i = x, p = 0; i < x_max; i++, p++) - { - for (j = y, q = 0; j < y_max; j++, q++) - { - if (i < 0 || j < 0 || i >= 640 || j >= 480) - continue; - - c = bmp->buffer[q * bmp->width + p]; - - /*** Cool Anti-Aliasing doesn't work too well at hires on GC ***/ - if (c > 128) - memory[(j * 640) + i] = Gui.fontcolour; - } - } -} - -/**************************************************************************** - * DrawText - * - * Place the font bitmap on the screen - ****************************************************************************/ -void -gui_DrawText (int x, int y, char *text) -{ - int px, n; - int i; - int err; - int value, count; - - n = strlen (text); - if (n == 0) - return; - - /*** x == -1, auto centre ***/ - if (x == -1) - { - value = 0; - px = 0; - } - else - { - value = 1; - px = x; - } - - for (count = value; count < 2; count++) - { - /*** Draw the string ***/ - for (i = 0; i < n; i++) - { - err = FT_Load_Char (face, text[i], FT_LOAD_RENDER); - - if (err) - { - printf ("Error %c %d\n", text[i], err); - continue; /*** Skip unprintable characters ***/ - } - - if (count) - gui_DrawCharacter (&slot->bitmap, px + slot->bitmap_left, y - slot->bitmap_top); - - px += slot->advance.x >> 6; - } - - px = (640 - px) >> 1; - - } -} - -/**************************************************************************** - * setfontcolour - * - * Uses RGB triple values. - ****************************************************************************/ -void -gui_setfontcolour (int r, int g, int b, int a) -{ - Gui.fontcolour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a; -} - -/**************************************************************************** - * DrawLine - * - * Quick'n'Dirty Bresenham line drawing routine. - ****************************************************************************/ -#define SIGN(x) ((x<0)?-1:((x>0)?1:0)) - -void -gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a) -{ - u32 colour; - int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py; - int sp; - - u32* memory = (u32*)Gui.texmem; - - colour = ((u8)r << 24) | ((u8)g << 16) | ((u8)b << 8) | (u8)a; - - dx = x2 - x1; /*** Horizontal distance ***/ - dy = y2 - y1; /*** Vertical distance ***/ - - dxabs = abs (dx); - dyabs = abs (dy); - sdx = SIGN (dx); - sdy = SIGN (dy); - x = dyabs >> 1; - y = dxabs >> 1; - px = x1; - py = y1; - - sp = (py * 640) + px; - - /*** Plot this pixel ***/ - memory[sp] = colour; - - if (dxabs >= dyabs) /*** Mostly horizontal ***/ - { - for (i = 0; i < dxabs; i++) - { - y += dyabs; - if (y >= dxabs) - { - y -= dxabs; - py += sdy; - } - - px += sdx; - sp = (py * 640) + px; - memory[sp] = colour; - } - } - else - { - for (i = 0; i < dyabs; i++) - { - x += dxabs; - if (x >= dyabs) - { - x -= dyabs; - px += sdx; - } - - py += sdy; - sp = (py * 640) + px; - memory[sp] = colour; - } - } -} - -/* */ - - /** draw menu, etc **/ - // - draw topbar, bottombar - // - draw icons - // - draw bar text - - // draw main text - - /** make textures **/ - // - load background texture - // - draw onto quad - // - make foreground texture - // - draw onto quad - - /** render image **/ - - /** update framebuffer **/ - -/* */ - -// EOF diff --git a/source/ngc/gui.h b/source/ngc/gui.h deleted file mode 100644 index d463dbea..00000000 --- a/source/ngc/gui.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * Michniewski 2008 - * - * gui.h - ***************************************************************************/ -#ifndef __GUI_H__ -#define __GUI_H__ - -#include - - -struct sGui { - void * texmem; // rgba8 - working draw area - int currmenu; - int prevmenu; - u32 fontcolour; - int screenheight; -}; - -extern struct sGui Gui; - -// Prototypes -void gui_alphasetup (); -void gui_makebg (); -void Make_Texture_RGBA8 (void * dst_tex, void * src_data, int width, int height); -void gui_drawbox (int x1, int y1, int width, int height, int r, int g, int b, int a); -void gui_DrawText (int x, int y, char *text); -void gui_setfontcolour (int r, int g, int b, int a); -void gui_DrawLine (int x1, int y1, int x2, int y2, int r, int g, int b, int a); -void gui_clearscreen (); -void gui_draw (); -void gui_showscreen (); - -void gui_savescreen (); - -// external functions -extern void setfontsize (int pixelsize); - - -#endif - diff --git a/source/ngc/input.cpp b/source/ngc/input.cpp deleted file mode 100644 index 55ef5cf6..00000000 --- a/source/ngc/input.cpp +++ /dev/null @@ -1,622 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May-June 2007 - * Michniewski 2008 - * Tantric September 2008 - * - * input.cpp - * - * Wii/Gamecube controller management - ***************************************************************************/ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "snes9x.h" -#include "memmap.h" -#include "controls.h" - -#include "snes9xGX.h" -#include "button_mapping.h" -#include "s9xconfig.h" -#include "menu.h" -#include "video.h" -#include "input.h" - -extern int ConfigRequested; - -/**************************************************************************** - * Controller Functions - * - * The following map the NGC Pads to the *NEW* controller system. - ***************************************************************************/ -#define ASSIGN_BUTTON_TRUE( keycode, snescmd ) \ - S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), true) - -#define ASSIGN_BUTTON_FALSE( keycode, snescmd ) \ - S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), false) - -/*** Gamecube controller Padmap ***/ -unsigned int gcpadmap[] = { - PAD_BUTTON_A, PAD_BUTTON_B, - PAD_BUTTON_X, PAD_BUTTON_Y, - PAD_TRIGGER_L, PAD_TRIGGER_R, - PAD_TRIGGER_Z, PAD_BUTTON_START, - PAD_BUTTON_UP, PAD_BUTTON_DOWN, - PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT -}; -/*** Wiimote Padmap ***/ -unsigned int wmpadmap[] = { - WPAD_BUTTON_B, WPAD_BUTTON_2, - WPAD_BUTTON_1, WPAD_BUTTON_A, - 0x0000, 0x0000, - WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS, - WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, - WPAD_BUTTON_UP, WPAD_BUTTON_DOWN -}; -/*** Classic Controller Padmap ***/ -unsigned int ccpadmap[] = { - WPAD_CLASSIC_BUTTON_A, WPAD_CLASSIC_BUTTON_B, - WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_Y, - WPAD_CLASSIC_BUTTON_FULL_L, WPAD_CLASSIC_BUTTON_FULL_R, - WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS, - WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, - WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT -}; -/*** Nunchuk + wiimote Padmap ***/ -unsigned int ncpadmap[] = { - WPAD_BUTTON_A, WPAD_BUTTON_B, - WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z, - WPAD_BUTTON_2, WPAD_BUTTON_1, - WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS, - WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, - WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT -}; -/*** Superscope : GC controller button mapping ***/ -unsigned int gcscopemap[] = { PAD_TRIGGER_Z, PAD_BUTTON_B, - PAD_BUTTON_A, PAD_BUTTON_Y, PAD_BUTTON_START -}; -/*** Superscope : wiimote button mapping ***/ -unsigned int wmscopemap[] = { WPAD_BUTTON_MINUS, WPAD_BUTTON_B, - WPAD_BUTTON_A, WPAD_BUTTON_DOWN, WPAD_BUTTON_PLUS -}; -/*** Mouse : GC controller button mapping ***/ -unsigned int gcmousemap[] = { PAD_BUTTON_A, PAD_BUTTON_B }; -/*** Mouse : wiimote button mapping ***/ -unsigned int wmmousemap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B }; -/*** Justifier : GC controller button mapping ***/ -unsigned int gcjustmap[] = { PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_START }; -/*** Justifier : wiimote button mapping ***/ -unsigned int wmjustmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B, WPAD_BUTTON_PLUS }; - -/**************************************************************************** - * WPAD_Stick - * - * Get X/Y value from Wii Joystick (classic, nunchuk) input - ***************************************************************************/ - -s8 WPAD_Stick(u8 chan, u8 right, int axis) -{ - float mag = 0.0; - float ang = 0.0; - WPADData *data = WPAD_Data(chan); - - switch (data->exp.type) - { - case WPAD_EXP_NUNCHUK: - case WPAD_EXP_GUITARHERO3: - if (right == 0) - { - mag = data->exp.nunchuk.js.mag; - ang = data->exp.nunchuk.js.ang; - } - break; - - case WPAD_EXP_CLASSIC: - if (right == 0) - { - mag = data->exp.classic.ljs.mag; - ang = data->exp.classic.ljs.ang; - } - else - { - mag = data->exp.classic.rjs.mag; - ang = data->exp.classic.rjs.ang; - } - break; - - default: - break; - } - - /* calculate x/y value (angle need to be converted into radian) */ - if (mag > 1.0) mag = 1.0; - else if (mag < -1.0) mag = -1.0; - double val; - - if(axis == 0) // x-axis - val = mag * sin((PI * ang)/180.0f); - else // y-axis - val = mag * cos((PI * ang)/180.0f); - - return (s8)(val * 128.0f); -} - -// hold superscope/mouse/justifier cursor positions -static int cursor_x[5] = {0,0,0,0,0}; -static int cursor_y[5] = {0,0,0,0,0}; - -/**************************************************************************** - * UpdateCursorPosition - * - * Updates X/Y coordinates for Superscope/mouse/justifier position - ***************************************************************************/ - -void UpdateCursorPosition (int pad, int &pos_x, int &pos_y) -{ - #define SCOPEPADCAL 20 - - // gc left joystick - signed char pad_x = PAD_StickX (pad); - signed char pad_y = PAD_StickY (pad); - - if (pad_x > SCOPEPADCAL){ - pos_x += (pad_x*1.0)/SCOPEPADCAL; - if (pos_x > 256) pos_x = 256; - } - if (pad_x < -SCOPEPADCAL){ - pos_x -= (pad_x*-1.0)/SCOPEPADCAL; - if (pos_x < 0) pos_x = 0; - } - - if (pad_y < -SCOPEPADCAL){ - pos_y += (pad_y*-1.0)/SCOPEPADCAL; - if (pos_y > 224) pos_y = 224; - } - if (pad_y > SCOPEPADCAL){ - pos_y -= (pad_y*1.0)/SCOPEPADCAL; - if (pos_y < 0) pos_y = 0; - } - -#ifdef HW_RVL - struct ir_t ir; // wiimote ir - WPAD_IR(pad, &ir); - if (ir.valid) - { - pos_x = (ir.x * 256) / 640; - pos_y = (ir.y * 224) / 480; - } - else - { - signed char wm_ax = WPAD_Stick (pad, 0, 0); - signed char wm_ay = WPAD_Stick (pad, 0, 1); - - if (wm_ax > SCOPEPADCAL){ - pos_x += (wm_ax*1.0)/SCOPEPADCAL; - if (pos_x > 256) pos_x = 256; - } - if (wm_ax < -SCOPEPADCAL){ - pos_x -= (wm_ax*-1.0)/SCOPEPADCAL; - if (pos_x < 0) pos_x = 0; - } - - if (wm_ay < -SCOPEPADCAL){ - pos_y += (wm_ay*-1.0)/SCOPEPADCAL; - if (pos_y > 224) pos_y = 224; - } - if (wm_ay > SCOPEPADCAL){ - pos_y -= (wm_ay*1.0)/SCOPEPADCAL; - if (pos_y < 0) pos_y = 0; - } - } -#endif - -} - -/**************************************************************************** - * decodepad - * - * Reads the changes (buttons pressed, etc) from a controller and reports - * these changes to Snes9x - ***************************************************************************/ - -void decodepad (int pad) -{ - int i, offset; - float t; - - signed char pad_x = PAD_StickX (pad); - signed char pad_y = PAD_StickY (pad); - u32 jp = PAD_ButtonsHeld (pad); - -#ifdef HW_RVL - signed char wm_ax = 0; - signed char wm_ay = 0; - u32 wp = 0; - wm_ax = WPAD_Stick ((u8)pad, 0, 0); - wm_ay = WPAD_Stick ((u8)pad, 0, 1); - wp = WPAD_ButtonsHeld (pad); - - u32 exp_type; - if ( WPAD_Probe(pad, &exp_type) != 0 ) - exp_type = WPAD_EXP_NONE; -#endif - - /*** - Gamecube Joystick input - ***/ - // Is XY inside the "zone"? - if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL) - { - /*** we don't want division by zero ***/ - if (pad_x > 0 && pad_y == 0) - jp |= PAD_BUTTON_RIGHT; - if (pad_x < 0 && pad_y == 0) - jp |= PAD_BUTTON_LEFT; - if (pad_x == 0 && pad_y > 0) - jp |= PAD_BUTTON_UP; - if (pad_x == 0 && pad_y < 0) - jp |= PAD_BUTTON_DOWN; - - if (pad_x != 0 && pad_y != 0) - { - /*** Recalc left / right ***/ - t = (float) pad_y / pad_x; - if (t >= -2.41421356237 && t < 2.41421356237) - { - if (pad_x >= 0) - jp |= PAD_BUTTON_RIGHT; - else - jp |= PAD_BUTTON_LEFT; - } - - /*** Recalc up / down ***/ - t = (float) pad_x / pad_y; - if (t >= -2.41421356237 && t < 2.41421356237) - { - if (pad_y >= 0) - jp |= PAD_BUTTON_UP; - else - jp |= PAD_BUTTON_DOWN; - } - } - } -#ifdef HW_RVL - /*** - Wii Joystick (classic, nunchuk) input - ***/ - // Is XY inside the "zone"? - if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL) - { - /*** we don't want division by zero ***/ - if (wm_ax > 0 && wm_ay == 0) - wp |= WPAD_BUTTON_RIGHT; - if (wm_ax < 0 && wm_ay == 0) - wp |= WPAD_BUTTON_LEFT; - if (wm_ax == 0 && wm_ay > 0) - wp |= WPAD_BUTTON_UP; - if (wm_ax == 0 && wm_ay < 0) - wp |= WPAD_BUTTON_DOWN; - - if (wm_ax != 0 && wm_ay != 0) - { - /*** Recalc left / right ***/ - t = (float) wm_ay / wm_ax; - if (t >= -2.41421356237 && t < 2.41421356237) - { - if (wm_ax >= 0) - wp |= WPAD_BUTTON_RIGHT; - else - wp |= WPAD_BUTTON_LEFT; - } - - /*** Recalc up / down ***/ - t = (float) wm_ax / wm_ay; - if (t >= -2.41421356237 && t < 2.41421356237) - { - if (wm_ay >= 0) - wp |= WPAD_BUTTON_UP; - else - wp |= WPAD_BUTTON_DOWN; - } - } - } -#endif - - /*** Fix offset to pad ***/ - offset = ((pad + 1) << 4); - - /*** Report pressed buttons (gamepads) ***/ - for (i = 0; i < MAXJP; i++) - { - if ( (jp & gcpadmap[i]) // gamecube controller -#ifdef HW_RVL - || ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) ) // wiimote - || ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) ) // classic controller - || ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) ) // nunchuk + wiimote -#endif - ) - S9xReportButton (offset + i, true); - else - S9xReportButton (offset + i, false); - } - - /*** Superscope ***/ - if (Settings.SuperScopeMaster && pad == GCSettings.Superscope - 1) // report only once - { - // buttons - offset = 0x50; - for (i = 0; i < 6; i++) - { - if (jp & gcscopemap[i] -#ifdef HW_RVL - || wp & wmscopemap[i] -#endif - ) - S9xReportButton(offset + i, true); - else - S9xReportButton(offset + i, false); - } - // pointer - offset = 0x80; - UpdateCursorPosition(pad, cursor_x[0], cursor_y[0]); - S9xReportPointer(offset, (u16) cursor_x[0], (u16) cursor_y[0]); - } - /*** Mouse ***/ - else if (Settings.MouseMaster && pad < GCSettings.Mouse) - { - // buttons - offset = 0x60 + (2 * pad); - for (i = 0; i < 2; i++) - { - if (jp & gcmousemap[i] -#ifdef HW_RVL - || wp & wmmousemap[i] -#endif - ) - S9xReportButton(offset + i, true); - else - S9xReportButton(offset + i, false); - } - // pointer - offset = 0x81; - UpdateCursorPosition(pad, cursor_x[1 + pad], cursor_y[1 + pad]); - S9xReportPointer(offset + pad, (u16) cursor_x[1 + pad], - (u16) cursor_y[1 + pad]); - } - /*** Justifier ***/ - else if (Settings.JustifierMaster && pad < GCSettings.Justifier) - { - // buttons - offset = 0x70 + (3 * pad); - for (i = 0; i < 3; i++) - { - if (jp & gcjustmap[i] -#ifdef HW_RVL - || wp & wmjustmap[i] -#endif - ) - S9xReportButton(offset + i, true); - else - S9xReportButton(offset + i, false); - } - // pointer - offset = 0x83; - UpdateCursorPosition(pad, cursor_x[3 + pad], cursor_y[3 + pad]); - S9xReportPointer(offset + pad, (u16) cursor_x[3 + pad], - (u16) cursor_y[3 + pad]); - } -} - -/**************************************************************************** - * NGCReportButtons - * - * Called on each rendered frame - * Our way of putting controller input into Snes9x - ***************************************************************************/ -void NGCReportButtons () -{ - s8 gc_px = PAD_SubStickX (0); - s8 gc_py = PAD_SubStickY (0); - - u16 gc_pb = PAD_ButtonsHeld (0); - -#ifdef HW_RVL - s8 wm_sx = WPAD_Stick (0,1,0); - s8 wm_sy = WPAD_Stick (0,1,1); - u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info -#endif - - - /*** Check for video zoom ***/ - if (GCSettings.NGCZoom) - { - if (gc_py < -36 || gc_py > 36) - zoom ((float) gc_py / -36); -#ifdef HW_RVL - if (wm_sy < -36 || wm_sy > 36) - zoom ((float) wm_sy / -36); -#endif - } - - Settings.TurboMode = ( (gc_px > 70) -#ifdef HW_RVL - || (wm_sx > 70) -#endif - ); // RIGHT on c-stick and on classic ctrlr right joystick - - /*** Check for menu: - CStick left - OR "L+R+X+Y" (eg. Hombrew/Adapted SNES controllers) - OR "Home" on the wiimote or classic controller - OR LEFT on classic right analog stick***/ - - if ((gc_px < -70) || - ((gc_pb & PAD_TRIGGER_L) && - (gc_pb & PAD_TRIGGER_R ) && - (gc_pb & PAD_BUTTON_X) && - (gc_pb & PAD_BUTTON_Y )) -#ifdef HW_RVL - || (wm_pb & WPAD_BUTTON_HOME) - || (wm_pb & WPAD_CLASSIC_BUTTON_HOME) - || (wm_sx < -70) -#endif - ) - { - ConfigRequested = 1; // go to the menu - } - else - { - int j = (Settings.MultiPlayer5Master == true ? 4 : 2); - for (int i = 0; i < j; i++) - decodepad (i); - } -} - -void SetControllers () -{ - if (Settings.MultiPlayer5Master == true) - { - S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); - S9xSetController (1, CTL_MP5, 1, 2, 3, -1); - } - else if (Settings.SuperScopeMaster == true) - { - S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); - S9xSetController (1, CTL_SUPERSCOPE, 1, 0, 0, 0); - } - else if (Settings.MouseMaster == true) - { - S9xSetController (0, CTL_MOUSE, 0, 0, 0, 0); - if (GCSettings.Mouse == 2) - S9xSetController (1, CTL_MOUSE, 1, 0, 0, 0); - else - S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); - } - else if (Settings.JustifierMaster == true) - { - S9xSetController(0, CTL_JUSTIFIER, 0, 0, 0, 0); - if(GCSettings.Justifier == 2) - S9xSetController(1, CTL_JUSTIFIER, 1, 0, 0, 0); - else - S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); - } - else - { - // Plugin 2 Joypads by default - S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); - S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); - } -} - -/**************************************************************************** - * Set the default mapping for NGC - ***************************************************************************/ -void SetDefaultButtonMap () -{ - int maxcode = 0x10; - s9xcommand_t cmd; - - /*** Joypad 1 ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 A"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 B"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 X"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Y"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 R"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Select"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Start"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Up"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Down"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Left"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Right"); - - maxcode = 0x20; - /*** Joypad 2 ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 A"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 B"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 X"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Y"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 R"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Select"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Start"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Up"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Down"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Left"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Right"); - - maxcode = 0x30; - /*** Joypad 3 ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 A"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 B"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 X"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Y"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 R"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Select"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Start"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Up"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Down"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Left"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Right"); - - maxcode = 0x40; - /*** Joypad 4 ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 A"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 B"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 X"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Y"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 R"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Select"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Start"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Up"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Down"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Left"); - ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Right"); - - maxcode = 0x50; - /*** Superscope ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Superscope AimOffscreen"); - ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Fire"); - ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Cursor"); - ASSIGN_BUTTON_FALSE (maxcode++, "Superscope ToggleTurbo"); - ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Pause"); - - maxcode = 0x60; - /*** Mouse ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 R"); - ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 L"); - ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 R"); - - maxcode = 0x70; - /*** Justifier ***/ - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 AimOffscreen"); - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Trigger"); - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Start"); - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 AimOffscreen"); - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Trigger"); - ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Start"); - - maxcode = 0x80; - S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Superscope"), false); - S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse1"), false); - S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse2"), false); - S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier1"), false); - S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier2"), false); - - SetControllers (); - -} - diff --git a/source/ngc/input.h b/source/ngc/input.h deleted file mode 100644 index 60d2c51b..00000000 --- a/source/ngc/input.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May-June 2007 - * Michniewski 2008 - * Tantric September 2008 - * - * input.h - * - * Wii/Gamecube controller management - ***************************************************************************/ - -#ifndef _INPUT_H_ -#define _INPUT_H_ - -#include - -#define PI 3.14159265f -#define PADCAL 50 -#define MAXJP 12 // # of mappable controller buttons - -extern unsigned int gcpadmap[]; -extern unsigned int wmpadmap[]; -extern unsigned int ccpadmap[]; -extern unsigned int ncpadmap[]; -extern unsigned int gcscopemap[]; -extern unsigned int wmscopemap[]; -extern unsigned int gcmousemap[]; -extern unsigned int wmmousemap[]; -extern unsigned int gcjustmap[]; -extern unsigned int wmjustmap[]; - -s8 WPAD_Stick(u8 chan,u8 right, int axis); - -void UpdateCursorPosition (int pad, int &pos_x, int &pos_y); -void decodepad (int pad); -void NGCReportButtons (); -void SetControllers (); -void SetDefaultButtonMap (); - -#endif diff --git a/source/ngc/memcardop.cpp b/source/ngc/mcsave.cpp similarity index 62% rename from source/ngc/memcardop.cpp rename to source/ngc/mcsave.cpp index db5c622e..f10843cb 100644 --- a/source/ngc/memcardop.cpp +++ b/source/ngc/mcsave.cpp @@ -1,15 +1,14 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 * crunchy2 May-June 2007 - * Tantric September 2008 * - * memcardop.cpp + * mcsave.cpp * - * Memory Card routines - ***************************************************************************/ - + * Memory Card Save Routines. + ****************************************************************************/ #include #include #include @@ -17,118 +16,130 @@ #include #include +#include "snes9x.h" +#include "memmap.h" +#include "debug.h" +#include "cpuexec.h" +#include "ppu.h" +#include "apu.h" +#include "display.h" +#include "gfx.h" +#include "soundux.h" +#include "spc700.h" +#include "spc7110.h" + #include "snes9xGX.h" #include "video.h" -#include "menudraw.h" +#include "ftfont.h" #include "s9xconfig.h" #include "audio.h" #include "menu.h" #include "sram.h" #include "preferences.h" -#include "memcardop.h" -#include "fileop.h" -#include "filesel.h" +#include "mcsave.h" #define VERIFBUFFERSIZE 65536 static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); +unsigned char savebuffer[SAVEBUFFERSIZE] ATTRIBUTE_ALIGN (32); unsigned char verifbuffer[VERIFBUFFERSIZE] ATTRIBUTE_ALIGN (32); card_dir CardDir; card_file CardFile; card_stat CardStatus; + +/**************************************************************************** + * Clear the savebuffer + ****************************************************************************/ +void +ClearSaveBuffer () +{ + memset (savebuffer, 0, SAVEBUFFERSIZE); +} + + /**************************************************************************** * CardFileExists * * Wrapper to search through the files on the card. * Returns TRUE if found. - ***************************************************************************/ + ****************************************************************************/ int CardFileExists (char *filename, int slot) { - int CardError; + int CardError; - CardError = CARD_FindFirst (slot, &CardDir, TRUE); - while (CardError != CARD_ERROR_NOFILE) - { - CardError = CARD_FindNext (&CardDir); + CardError = CARD_FindFirst (slot, &CardDir, TRUE); + while (CardError != CARD_ERROR_NOFILE) + { + CardError = CARD_FindNext (&CardDir); - if (strcmp ((char *) CardDir.filename, filename) == 0) - return 1; - } + if (strcmp ((char *) CardDir.filename, filename) == 0) + return 1; + } - return 0; + return 0; } /**************************************************************************** - * TestCard + * MountCard * - * Checks to see if a card is in the card slot specified - ***************************************************************************/ -bool TestCard(int slot, bool silent) -{ - // Memory Cards do not work in Wii mode - disable - #ifdef HW_RVL - return false; - #endif - - /*** Initialize Card System ***/ - memset (SysArea, 0, CARD_WORKAREA); - CARD_Init ("SNES", "00"); - - /*** Try to mount the card ***/ - if (MountCard(slot, silent) == 0) + * Mounts the memory card in the given slot. Error checking is done and + * workarounds implemented for when the mount fails. + * Returns the result of the last attempted CARD_Mount command. + ****************************************************************************/ +int MountCard(int cslot) +{ + int ret; + int tries; + + EXI_ProbeReset(); + + /*** Mount the card ***/ + ret = CARD_Mount (cslot, SysArea, NULL); + + tries = 0; + while ( tries < 3 && ret == CARD_ERROR_IOERROR ) { - // Mount successful! - if(!silent) - { - if (slot == CARD_SLOTA) - WaitPrompt((char*) "Mounted Slot A Memory Card!"); - else - WaitPrompt((char*) "Mounted Slot B Memory Card!"); - } - CARD_Unmount (slot); - return true; + if (cslot == CARD_SLOTA) + WaitPrompt((char*) "Replug card in slot A!"); + else + WaitPrompt((char*) "Replug card in slot B!"); + + ShowAction ((char*) ""); + ret = CARD_Mount (cslot, SysArea, NULL); + tries++; } - else + + tries = 0; + while ( tries < 5 && ret == CARD_ERROR_NOCARD ) { - if(!silent) - { - if (slot == CARD_SLOTA) - WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); - else - WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); - } - - return false; + ShowAction ((char*) "Mounting card..."); + CARD_Unmount (cslot); + usleep(500000); // wait half second + ShowAction ((char*) ""); + usleep(500000); // wait half second + ret = CARD_Mount (cslot, SysArea, NULL); + tries++; } -} - -/**************************************************************************** - * MountCard - * - * Mounts the memory card in the given slot. - * Returns the result of the last attempted CARD_Mount command. - ***************************************************************************/ -int MountCard(int cslot, bool silent) -{ - int ret = -1; - int tries = 0; - // Mount the card - while ( tries < 10 && ret != 0) + tries = 0; + while ( tries < 5 && ret == CARD_ERROR_UNLOCKED ) { - EXI_ProbeReset (); - ret = CARD_Mount (cslot, SysArea, NULL); - VIDEO_WaitVSync (); + ShowAction ((char*) "Waiting for unlock..."); + usleep(500000); // wait half second + ShowAction ((char*) ""); + usleep(500000); // wait half second + ret = CARD_Probe(cslot); tries++; } + return ret; } /**************************************************************************** * Verify Memory Card file against buffer - ***************************************************************************/ + ****************************************************************************/ int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize) { @@ -142,36 +153,36 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize) /*** Initialize Card System ***/ memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("SNES", "00"); - + /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); - + CardError = MountCard(slot); + if (CardError == 0) { /*** Get Sector Size ***/ CARD_GetSectorSize (slot, &SectorSize); - + if (!CardFileExists (filename, slot)) { CARD_Unmount (slot); WaitPrompt((char*) "Unable to open file for verify!"); return 0; } - + memset (&CardFile, 0, sizeof (CardFile)); CardError = CARD_Open (slot, filename, &CardFile); - + blocks = CardFile.len; - + if (blocks < SectorSize) blocks = SectorSize; - + if (blocks % SectorSize) blocks += SectorSize; - + if (blocks > (unsigned int)datasize) blocks = datasize; - + memset (verifbuffer, 0, VERIFBUFFERSIZE); bytesleft = blocks; bytesread = 0; @@ -185,16 +196,16 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize) WaitPrompt((char*) "File did not verify!"); return 0; } - + bytesleft -= SectorSize; bytesread += SectorSize; - + sprintf (msg, "Verified %d of %d bytes", bytesread, blocks); ShowProgress (msg, bytesread, blocks); } CARD_Close (&CardFile); CARD_Unmount (slot); - + return 1; } else @@ -202,54 +213,56 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize) WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); else WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); - + return 0; } + /**************************************************************************** * Load savebuffer from Memory Card file - ***************************************************************************/ + ****************************************************************************/ int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent) { int CardError; unsigned int blocks; unsigned int SectorSize; + char msg[80]; int bytesleft = 0; int bytesread = 0; /*** Initialize Card System ***/ memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("SNES", "00"); - + /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); - + CardError = MountCard(slot); + if (CardError == 0) { /*** Get Sector Size ***/ CARD_GetSectorSize (slot, &SectorSize); - + if (!CardFileExists (filename, slot)) { - if (!silent) + if ( !silent ) WaitPrompt((char*) "Unable to open file"); return 0; } - + memset (&CardFile, 0, sizeof (CardFile)); CardError = CARD_Open (slot, filename, &CardFile); - + blocks = CardFile.len; - + if (blocks < SectorSize) blocks = SectorSize; - + if (blocks % SectorSize) blocks += SectorSize; - + memset (buf, 0, 0x22000); - + bytesleft = blocks; bytesread = 0; while (bytesleft > 0) @@ -257,6 +270,9 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent) CARD_Read (&CardFile, buf + bytesread, SectorSize, bytesread); bytesleft -= SectorSize; bytesread += SectorSize; + + sprintf (msg, "Read %d of %d bytes", bytesread, blocks); + ShowProgress (msg, bytesread, blocks); } CARD_Close (&CardFile); CARD_Unmount (slot); @@ -266,14 +282,14 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent) WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); else WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); - + return bytesread; } /**************************************************************************** * Write savebuffer to Memory Card file - ***************************************************************************/ + ****************************************************************************/ int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent) { @@ -281,26 +297,26 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool unsigned int blocks; unsigned int SectorSize; char msg[80]; - + /*** Initialize Card System ***/ memset (SysArea, 0, CARD_WORKAREA); CARD_Init ("SNES", "00"); - + /*** Try to mount the card ***/ - CardError = MountCard(slot, NOTSILENT); - + CardError = MountCard(slot); + if (CardError == 0) { /*** Get Sector Size ***/ CARD_GetSectorSize (slot, &SectorSize); - + if (datasize) - { + { /*** Calculate number of blocks required ***/ blocks = (datasize / SectorSize) * SectorSize; if (datasize % SectorSize) blocks += SectorSize; - + /*** Does this file exist ? ***/ if (CardFileExists (filename, slot)) { @@ -312,11 +328,36 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool WaitPrompt((char*) "Unable to open card file!"); return 0; } - + +// if ( (s32)blocks < CardFile.len ) /*** new data is shorter ***/ +// { +// CARD_Close (&CardFile); +// +// /*** Delete the existing longer file ***/ +// CardError = CARD_Delete(slot, filename); +// if (CardError) +// { +// CARD_Unmount (slot); +// WaitPrompt((char*) "Unable to delete existing file!"); +// return 0; +// } +// +// /*** Create new, shorter file ***/ +// CardError = CARD_Create (slot, filename, blocks, &CardFile); +// if (CardError) +// { +// CARD_Unmount (slot); +// WaitPrompt((char*) "Unable to create updated card file!"); +// return 0; +// } +// +// } +// else + if ( (s32)blocks > CardFile.len ) /*** new data is longer ***/ { CARD_Close (&CardFile); - + /*** Try to create temp file to check available space ***/ CardError = CARD_Create (slot, "TEMPFILESNES9XGX201", blocks, &CardFile); if (CardError) @@ -325,7 +366,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool WaitPrompt((char*) "Not enough space to update file!"); return 0; } - + /*** Delete the temporary file ***/ CARD_Close (&CardFile); CardError = CARD_Delete(slot, "TEMPFILESNES9XGX201"); @@ -335,7 +376,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool WaitPrompt((char*) "Unable to delete temporary file!"); return 0; } - + /*** Delete the existing shorter file ***/ CardError = CARD_Delete(slot, filename); if (CardError) @@ -344,7 +385,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool WaitPrompt((char*) "Unable to delete existing file!"); return 0; } - + /*** Create new, longer file ***/ CardError = CARD_Create (slot, filename, blocks, &CardFile); if (CardError) @@ -362,14 +403,14 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool if (CardError) { CARD_Unmount (slot); - if ( CardError == CARD_ERROR_INSSPACE ) + if ( CardError = CARD_ERROR_INSSPACE ) WaitPrompt((char*) "Not enough space to create file!"); else WaitPrompt((char*) "Unable to create card file!"); return 0; } } - + /*** Now, have an open file handle, ready to send out the data ***/ CARD_GetStatus (slot, CardFile.filenum, &CardStatus); CardStatus.icon_addr = 0x0; @@ -377,7 +418,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool CardStatus.icon_speed = 1; CardStatus.comment_addr = 2048; CARD_SetStatus (slot, CardFile.filenum, &CardStatus); - + int byteswritten = 0; int bytesleft = blocks; while (bytesleft > 0) @@ -387,14 +428,14 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool SectorSize, byteswritten); bytesleft -= SectorSize; byteswritten += SectorSize; - + sprintf (msg, "Wrote %d of %d bytes", byteswritten, blocks); ShowProgress (msg, byteswritten, blocks); } - + CARD_Close (&CardFile); CARD_Unmount (slot); - + if ( GCSettings.VerifySaves ) { /*** Verify the written file, but only up to the length we wrote @@ -416,7 +457,112 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool WaitPrompt((char*) "Unable to Mount Slot A Memory Card!"); else WaitPrompt((char*) "Unable to Mount Slot B Memory Card!"); - + return 0; } + +/**************************************************************************** + * Memory Card SRAM Load + ****************************************************************************/ +void +LoadSRAMFromMC (int slot, int silent) +{ + char filename[128]; + + ShowAction ((char*) "Loading SRAM from MC..."); + + /*** Build SRAM filename ***/ + sprintf (filename, "%s.srm", Memory.ROMName); + + int offset = LoadBufferFromMC (savebuffer, slot, filename, silent); + + if ( offset > 0 ) + { + decodesavedata (offset); + if ( !silent ) + { + sprintf (filename, "Loaded %d bytes", offset); + WaitPrompt (filename); + } + S9xSoftReset(); + } +} + + +/**************************************************************************** + * Memory Card SRAM Save + ****************************************************************************/ +void +SaveSRAMToMC (int slot, int silent) +{ + char filename[128]; + int datasize; + int offset; + + if (!silent) + ShowAction ((char*) "Saving SRAM to MC..."); + + /*** Build SRAM filename ***/ + sprintf (filename, "%s.srm", Memory.ROMName); + + datasize = prepareMCsavedata (); + offset = SaveBufferToMC (savebuffer, slot, filename, datasize, silent); + + if ( (offset > 0) && (!silent)) + { + sprintf (filename, "Wrote %d bytes", offset); + WaitPrompt (filename); + } +} + + +/**************************************************************************** + * Memory Card Preferences Load + ****************************************************************************/ +void +LoadPrefsFromMC (int slot, int silent) +{ + int offset; + char msg[80]; + + ShowAction ((char*) "Loading Prefs from MC..."); + + offset = LoadBufferFromMC (savebuffer, slot, PREFS_FILE_NAME, silent); + + if ( offset > 0 ) + { + decodePrefsData (); + if ( !silent ) + { + sprintf (msg, "Loaded %d bytes", offset); + WaitPrompt (msg); + } + } +} + + +/**************************************************************************** + * Memory Card Preferences Save + ****************************************************************************/ +void +SavePrefsToMC (int slot, int silent) +{ + int datasize; + int offset; + char msg[80]; + + if (!silent) + ShowAction ((char*) "Saving Prefs to MC..."); + + datasize = preparePrefsData (); + offset = SaveBufferToMC (savebuffer, slot, PREFS_FILE_NAME, datasize, silent); + + if ( offset > 0 && !silent) + { + sprintf (msg, "Wrote %d bytes", offset); + WaitPrompt (msg); + } +} + + diff --git a/source/ngc/memcardop.h b/source/ngc/mcsave.h similarity index 55% rename from source/ngc/memcardop.h rename to source/ngc/mcsave.h index 9ff1112d..811383de 100644 --- a/source/ngc/memcardop.h +++ b/source/ngc/mcsave.h @@ -1,23 +1,31 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 - * crunchy2 May-June 2007 - * Tantric September 2008 + * crunchy2 May 2007 * - * memcardop.cpp + * mcsave.cpp * - * Memory Card routines - ***************************************************************************/ + * Memory Card Save Routines. + ****************************************************************************/ #ifndef _NGCMCSAVE_ #define _NGCMCSAVE_ +#define SAVEBUFFERSIZE ((512 * 1024) + 2048 + 64 + 4 + 4) + +void ClearSaveBuffer (); + int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize); int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent); int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent); -int MountCard(int cslot, bool silent); -bool TestCard(int slot, bool silent); + +void LoadSRAMFromMC (int slot, int silent); +void SaveSRAMToMC (int slot, int silent); + +void LoadPrefsFromMC (int slot, int silent); +void SavePrefsToMC (int slot, int silent); #endif diff --git a/source/ngc/memfile.cpp b/source/ngc/memfile.cpp new file mode 100644 index 00000000..1c2041f2 --- /dev/null +++ b/source/ngc/memfile.cpp @@ -0,0 +1,489 @@ +/**************************************************************************** + * Snes9x 1.50 - GX 2.0 + * + * NGC Snapshots Memory File System + * + * This is a single global memory file controller. Don't even think of opening two + * at the same time ! + * + * There's just enough here to do SnapShots - you should add anything else you + * need. + * + * softdev July 2006 + * crunchy2 May 2007-July 2007 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include + +#include "memfile.h" +#include "snes9x.h" +#include "memmap.h" +#include "soundux.h" +#include "snapshot.h" +#include "srtc.h" + +#include "Snes9xGx.h" +#include "filesel.h" +#include "ftfont.h" +#include "smbload.h" +#include "mcsave.h" + +extern "C" +{ +#include "smb.h" +} + +#define MEMBUFFER (512 * 1024) + +extern void S9xSRTCPreSaveState (); +extern void NGCFreezeStruct (); +extern bool8 S9xUnfreezeGame (const char *filename); +extern unsigned char savebuffer[]; + +static int bufoffset; +static char membuffer[MEMBUFFER]; + +char freezecomment[2][32] = { {"Snes9x GX 003 Freeze"}, {"Freeze"} }; + + +/** + * GetMem + * + * Return x bytes from memory buffer + */ +int +GetMem (char *buffer, int len) +{ + memcpy (buffer, membuffer + bufoffset, len); + bufoffset += len; + + return len; +} + +/** + * PutMem + * + * Put some values in memory buffer + */ +static void +PutMem (char *buffer, int len) +{ + memcpy (membuffer + bufoffset, buffer, len); + bufoffset += len; +} + +void +NGCFreezeBlock (char *name, uint8 * block, int size) +{ + char buffer[512]; + +// char msg[90]; +// sprintf (msg, "name=%s", name); +// WaitPrompt(msg); + + sprintf (buffer, "%s:%06d:", name, size); + PutMem (buffer, strlen (buffer)); + PutMem ((char *) block, size); +} + +/** + * NGCFreezeMembuffer + */ +static int +NGCFreezeMemBuffer () +{ + int i; + char buffer[1024]; + + bufoffset = 0; + + S9xUpdateRTC (); + S9xSRTCPreSaveState (); + + for (i = 0; i < 8; i++) + { + SoundData.channels[i].previous16[0] = + (int16) SoundData.channels[i].previous[0]; + SoundData.channels[i].previous16[1] = + (int16) SoundData.channels[i].previous[1]; + } + + sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION); + PutMem (buffer, strlen (buffer)); + sprintf (buffer, "NAM:%06d:%s%c", (int) strlen (Memory.ROMFilename) + 1, + Memory.ROMFilename, 0); + + PutMem (buffer, strlen (buffer) + 1); + + NGCFreezeStruct (); + + return 0; +} + + +/** + * NGCFreezeGame + * + * Do freeze game for Nintendo Gamecube + */ +int +NGCFreezeGame (int where, bool8 silent) +{ + char filename[1024]; + SMBFILE smbfile; + FILE *handle; + int len = 0; + int wrote = 0; + int offset = 0; + char msg[100]; + + if (where == 4) + { + /*** Freeze to SMB ***/ + sprintf (filename, "/%s/%s.frz", SNESSAVEDIR, Memory.ROMName); + } + else if (where == 2 || where == 3) + { + /*** Freeze to SDCard in slot A or slot B ***/ + +#ifdef SDUSE_LFN + sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMName); +#else + /*** Until we have LFN on SD ... ***/ + sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); +#endif + } + else + { + /*** Freeze to MC in slot A or slot B ***/ + sprintf (filename, "%s.snz", Memory.ROMName); + } + + S9xSetSoundMute (TRUE); + S9xPrepareSoundForSnapshotSave (FALSE); + + NGCFreezeMemBuffer (); + + S9xPrepareSoundForSnapshotSave (TRUE); + S9xSetSoundMute (FALSE); + + if (where == 4) /*** SMB ***/ + { + ConnectSMB (); + + smbfile = SMB_Open (filename, SMB_OPEN_WRITING | SMB_DENY_NONE, + SMB_OF_CREATE | SMB_OF_TRUNCATE); + + if (smbfile) + { + if (!silent) + ShowAction ((char*) "Saving freeze game..."); + + len = bufoffset; + offset = 0; + while (len > 0) + { + if (len > 1024) + wrote = + SMB_Write ((char *) membuffer + offset, 1024, offset, + smbfile); + else + wrote = + SMB_Write ((char *) membuffer + offset, len, offset, + smbfile); + + offset += wrote; + len -= wrote; + } + + SMB_Close (smbfile); + + if ( !silent ) + { + sprintf (filename, "Written %d bytes", bufoffset); + WaitPrompt (filename); + } + } + else + { + char msg[100]; + sprintf(msg, "Couldn't save to SMB:\\%s\\", SNESSAVEDIR); + WaitPrompt (msg); + } + } + else if (where == 2 || where == 3) /*** SDCard slot A or slot B ***/ + { + handle = fopen (filename, "wb"); + + if (handle > 0) + { + if (!silent) + ShowAction ((char*) "Saving freeze game..."); + + len = fwrite (membuffer, 1, bufoffset, handle); + fclose (handle); + + if (len != bufoffset) + WaitPrompt((char*) "Error writing freeze file"); + else if ( !silent ) + { + sprintf (filename, "Written %d bytes", bufoffset); + WaitPrompt (filename); + } + + } + else + { + sprintf(msg, "Couldn't save to %s/%s/", ROOTSDDIR, SNESSAVEDIR); + WaitPrompt (msg); + } + } + else /*** MC in slot A or slot B ***/ + { + if (!silent) + ShowAction ((char*) "Saving freeze game..."); + + ClearSaveBuffer (); + + /*** Copy in save icon ***/ + int offset = sizeof (saveicon); + memcpy (savebuffer, saveicon, offset); + + /*** And the freezecomment ***/ + sprintf (freezecomment[1], "%s", Memory.ROMName); + memcpy (savebuffer + offset, freezecomment, 64); + offset += 64; + + /*** Zip and copy in the freeze ***/ + uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE; + int err= compress2((Bytef*)(savebuffer+offset+8), (uLongf*)&DestBuffSize, (const Bytef*)membuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); + + if(err!=Z_OK) + { + sprintf (msg, "zip error %s ",zError(err)); + WaitPrompt (msg); + return 0; + } + + int zippedsize = (int)DestBuffSize; + memcpy (savebuffer + offset, &zippedsize, 4); + offset += 4; + + int decompressedsize = (int)bufoffset; + memcpy (savebuffer + offset, &decompressedsize, 4); + offset += 4; + + offset += zippedsize; + + int ret = SaveBufferToMC ( savebuffer, where, filename, offset, SILENT ); + if ( ret && !silent ) + { + sprintf (filename, "Written %d bytes", ret); + WaitPrompt (filename); + } + } + + return 0; +} + +/** + * NGCUnFreezeBlock + */ +int +NGCUnFreezeBlock (char *name, uint8 * block, int size) +{ + char buffer[20], *e; + int len = 0; + int rem = 0; + + GetMem (buffer, 11); + + if (strncmp (buffer, name, 3) != 0 || buffer[3] != ':' || + buffer[10] != ':' || (len = strtol (&buffer[4], &e, 10)) == 0 || + e != buffer + 10) + { + return WRONG_FORMAT; + } + + if (len > size) + { + rem = len - size; + len = size; + } + + ZeroMemory (block, size); + + GetMem ((char *) block, len); + + if (rem) + { + bufoffset += rem; + } + + return SUCCESS; +} + +/** + * NGCUnfreezeGame + */ +int +NGCUnfreezeGame (int from, bool8 silent) +{ + char filename[1024]; + SMBFILE smbfile; + FILE *handle; + int read = 0; + int offset = 0; + char msg[80]; + + bufoffset = 0; + + if (from == 4) + { + /*** From SMB ***/ + sprintf (filename, "\\%s\\%s.frz", SNESSAVEDIR, Memory.ROMName); + ConnectSMB (); + + /*** Read the file into memory ***/ + smbfile = + SMB_Open (filename, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); + + if (smbfile) + { + ShowAction ((char*) "Loading freeze file..."); + while ((read = + SMB_Read ((char *) membuffer + offset, 1024, offset, + smbfile)) > 0) + offset += read; + + SMB_Close (smbfile); + + ShowAction ((char*) "Unpacking freeze file"); + if (S9xUnfreezeGame ("AGAME") != SUCCESS) + { + WaitPrompt((char*) "Error thawing"); + return 0; + } + } + else if ( !silent ) + { + WaitPrompt((char*) "No freeze file found"); + return 0; + } + } + else if (from == 2 || from == 3) /*** From SD slot A or slot B ***/ + { + +#ifdef SDUSE_LFN + sprintf (filename, "%s/%s/%s.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMName); +#else + /*** From SDCard ***/ + sprintf (filename, "%s/%s/%08x.frz", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); +#endif + + handle = fopen (filename, "rb"); + + if (handle > 0) + { + ShowAction ((char*) "Loading freeze file..."); + + offset = 0; + /*** Usual chunks into memory ***/ + while ((read = fread (membuffer + offset, 1, 2048, handle)) > + 0) + offset += read; + + fclose (handle); + + ShowAction ((char*) "Unpacking freeze file"); + + if (S9xUnfreezeGame ("AGAME") != SUCCESS) + { + WaitPrompt((char*) "Error thawing"); + return 0; + } + } + else if ( !silent ) + { + WaitPrompt((char*) "No freeze file found"); + return 0; + } + } + else /*** From MC in slot A or slot B ***/ + { + ShowAction ((char*) "Loading freeze file..."); + + sprintf (filename, "%s.snz", Memory.ROMName); + + int ret = LoadBufferFromMC ( savebuffer, from, filename, silent ); + if ( ret ) + { + ShowAction ((char*) "Unpacking freeze file"); + + // skip the saveicon and comment + offset = (sizeof(saveicon) + 64); + uLongf zipsize = 0; + uLongf decompressedsize = 0; + + memcpy (&zipsize, savebuffer+offset, 4); + offset += 4; + + memcpy (&decompressedsize, savebuffer+offset, 4); + offset += 4; + + memset(membuffer, 0, MEMBUFFER); + + uLongf DestBuffSize = MEMBUFFER; + int err= uncompress((Bytef*)membuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); + + if ( err!=Z_OK ) + { + sprintf (msg, "unzip error %s ",zError(err)); + WaitPrompt (msg); + return 0; + } + + if ( DestBuffSize != decompressedsize ) + { + WaitPrompt((char*) "Unzipped size doesn't match expected size!"); + return 0; + } + + if (S9xUnfreezeGame ("AGAME") != SUCCESS) + { + WaitPrompt((char*) "Error thawing"); + return 0; + } + } + else if ( !silent ) + { + sprintf(msg, "Couldn't load from MC slot %s", (from ? "B" : "A")); + WaitPrompt (msg); + return 0; + } + + } + + return 1; + +} + + +void quickLoadFreeze (bool8 silent) +{ + if ( QUICK_SAVE_SLOT >= 0 ) + NGCUnfreezeGame ( QUICK_SAVE_SLOT, silent ); +} + + +void quickSaveFreeze (bool8 silent) +{ + if ( QUICK_SAVE_SLOT >= 0 ) + NGCFreezeGame ( QUICK_SAVE_SLOT, silent ); +} + + diff --git a/source/ngc/memfile.h b/source/ngc/memfile.h new file mode 100644 index 00000000..8da54bfa --- /dev/null +++ b/source/ngc/memfile.h @@ -0,0 +1,34 @@ +/**************************************************************************** + * Snes9x 1.50 - GX 2.0 + * + * NGC Snapshots Memory File System + * + * This is a single global memory file controller. Don't even think of opening two + * at the same time ! + * + * There's just enough here to do SnapShots - you should add anything else you + * need. + ****************************************************************************/ +#include "snes9x.h" + +#ifndef _NGCMEMFILE_ +#define _NGCMEMFILE_ + +typedef struct +{ + char filename[512]; /*** Way over size - but who cares -;) ***/ + int filehandle; + int currpos; + int length; + int mode; + char *buffer; /*** Memspace for read / write ***/ +} +MEMFILE; + +int NGCFreezeGame (int where, bool8 silent); +int NGCUnfreezeGame (int from, bool8 silent); + +void quickLoadFreeze (bool8 silent); +void quickSaveFreeze (bool8 silent); + +#endif diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 1b1649ae..1dd5bf89 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -1,30 +1,19 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 + * + * Nintendo Gamecube Menu * * softdev July 2006 * crunchy2 May-June 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * menu.cpp - * - * Menu flow routines - handles all menu logic - ***************************************************************************/ - + ****************************************************************************/ #include #include #include #include #include #include - -#ifdef WII_DVD -extern "C" { -#include -} -#endif - #include "snes9x.h" +#include "snes9xGx.h" #include "memmap.h" #include "debug.h" #include "cpuexec.h" @@ -36,46 +25,35 @@ extern "C" { #include "spc700.h" #include "spc7110.h" #include "controls.h" -#include "cheats.h" - -#include "snes9xGX.h" +#include "aram.h" +#include "ftfont.h" #include "video.h" +#include "mcsave.h" #include "filesel.h" #include "unzip.h" -#include "smbop.h" -#include "memcardop.h" -#include "fileop.h" -#include "freeze.h" +#include "smbload.h" +#include "mcsave.h" +#include "sdload.h" +#include "memfile.h" #include "dvd.h" #include "s9xconfig.h" #include "sram.h" #include "preferences.h" -#include "button_mapping.h" -#include "menudraw.h" -#include "cheatmgr.h" -#include "input.h" -extern void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize); +#include "button_mapping.h" +#include "ftfont.h" -extern SCheatData Cheat; +extern void DrawMenu (char items[][20], char *title, int maxitems, int selected, int fontsize); +#define PSOSDLOADID 0x7c6000a6 extern int menu; +extern unsigned long ARAM_ROMSIZE; #define SOFTRESET_ADR ((volatile u32*)0xCC003024) -/**************************************************************************** - * Reboot / Exit - ***************************************************************************/ - -#ifndef HW_RVL -#define PSOSDLOADID 0x7c6000a6 -int *psoid = (int *) 0x80001800; -void (*PSOReload) () = (void (*)()) 0x80001800; -#endif -void Reboot() -{ -#ifdef HW_RVL +void Reboot() { +#ifdef __wii__ SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); #else #define SOFTRESET_ADR ((volatile u32*)0xCC003024) @@ -84,615 +62,416 @@ void Reboot() } /**************************************************************************** - * Load Manager - ***************************************************************************/ - + * Freeze Manager + ****************************************************************************/ +int freezecountwii = 7; +char freezemenuwii[][20] = { "Freeze to SD", "Thaw from SD", + "Freeze to MC Slot A", "Thaw from MC Slot A", + "Freeze to MC Slot B", "Thaw from MC Slot B", + "Return to previous" +}; +int freezecount = 9; +char freezemenu[][20] = { "Freeze to SD", "Thaw from SD", + "Freeze to MC Slot A", "Thaw from MC Slot A", + "Freeze to MC Slot B", "Thaw from MC Slot B", + "Freeze to SMB", "Thaw from SMB", + "Return to previous" +}; int -LoadManager () +FreezeManager () { - int loadROM = OpenROM(GCSettings.LoadMethod); - - /*** - * check for autoloadsram / freeze - ***/ - if ( loadROM == 1 ) // if ROM was loaded, load the SRAM & settings - { - if ( GCSettings.AutoLoad == 1 ) - LoadSRAM(GCSettings.SaveMethod, SILENT); - else if ( GCSettings.AutoLoad == 2 ) - NGCUnfreezeGame (GCSettings.SaveMethod, SILENT); - - // setup cheats - SetupCheats(); - - // reset zoom - zoom_reset (); - } + int ret; + int loaded = 0; + int quit = 0; + int oldmenu = menu; + menu = 0; + + + while (quit == 0) + { + if ( isWii ) /* Wii menu */ + { + ret = RunMenu (freezemenuwii, freezecountwii, (char*)"Freeze Manager"); + if (ret >= freezecountwii-1) + ret = freezecount-1; + } + else /* Gamecube menu */ + ret = RunMenu (freezemenu, freezecount, (char*)"Freeze Manager"); + + switch (ret) + { + case 0:/*** Freeze to SDCard ***/ + NGCFreezeGame (2, NOTSILENT); + break; + + case 1:/*** Thaw from SDCard***/ + quit = loaded = NGCUnfreezeGame (2, NOTSILENT); + break; + + case 2:/*** Freeze to MC in slot A ***/ + NGCFreezeGame (0, NOTSILENT); + break; + + case 3:/*** Thaw from MC in slot A ***/ + quit = loaded = NGCUnfreezeGame (0, NOTSILENT); + break; + + case 4:/*** Freeze to MC in slot B ***/ + NGCFreezeGame (1, NOTSILENT); + break; - return loadROM; + case 5:/*** Thaw from MC in slot B ***/ + quit = loaded = NGCUnfreezeGame (1, NOTSILENT); + break; + + case 6:/*** Freeze to SMB ***/ + if ( !isWii ) + NGCFreezeGame (4, NOTSILENT); + break; + + case 7:/*** Thaw from SMB ***/ + if ( !isWii ) + quit = loaded = NGCUnfreezeGame (4, NOTSILENT); + break; + + case -1: /*** Button B ***/ + case 8: + quit = 1; + break; + } + + } + + menu = oldmenu; + return loaded; } /**************************************************************************** - * Cheat Menu - ***************************************************************************/ -static int cheatmenuCount = 0; -static char cheatmenu[MAX_CHEATS][50]; -static char cheatmenuvalue[MAX_CHEATS][50]; - -void CheatMenu() + * Load Manager + ****************************************************************************/ +int loadmancountwii = 2; +char loadmanwii[][20] = { "Load from SD", + "Return to previous" +}; +int loadmancount = 4; +char loadman[][20] = { "Load from SD", + "Load from DVD", "Load from SMB", "Return to previous" +}; +int +LoadManager () { - int ret = -1; - int oldmenu = menu; - menu = 0; - - int selection = 0; - int offset = 0; - int redraw = 1; - int selectit = 0; - - u32 p = 0; - u32 wp = 0; - u32 ph = 0; - u32 wh = 0; - signed char gc_ay = 0; - signed char gc_sx = 0; - signed char wm_ay = 0; - signed char wm_sx = 0; - - int scroll_delay = 0; - bool move_selection = 0; - #define SCROLL_INITIAL_DELAY 15 - #define SCROLL_LOOP_DELAY 2 - - if(Cheat.num_cheats > 0) - { - cheatmenuCount = Cheat.num_cheats + 1; - - for(uint16 i=0; i < Cheat.num_cheats; i++) - sprintf (cheatmenu[i], "%s", Cheat.c[i].name); - - sprintf (cheatmenu[cheatmenuCount-1], "Back to Game Menu"); - - while(ret != cheatmenuCount-1) + int ret; + int quit = 0; + int oldmenu = menu; + int retval = 1; + menu = 0; + + while (quit == 0) + { + if ( isWii ) /* Wii menu */ { - if(ret >= 0) - { - if(Cheat.c[ret].enabled) - S9xDisableCheat(ret); - else - S9xEnableCheat(ret); - - ret = -1; - } - - for(uint16 i=0; i < Cheat.num_cheats; i++) - sprintf (cheatmenuvalue[i], "%s", Cheat.c[i].enabled == true ? "ON" : "OFF"); - - if (redraw) - ShowCheats (cheatmenu, cheatmenuvalue, cheatmenuCount, offset, selection); - - redraw = 0; - - VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads - - gc_ay = PAD_StickY (0); - gc_sx = PAD_SubStickX (0); - p = PAD_ButtonsDown (0); - ph = PAD_ButtonsHeld (0); - - #ifdef HW_RVL - wm_ay = WPAD_Stick (0, 0, 1); - wm_sx = WPAD_Stick (0, 1, 0); - wp = WPAD_ButtonsDown (0); - wh = WPAD_ButtonsHeld (0); - #endif - - /*** Check for exit combo ***/ - if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) - break; - - if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) - break; - - /*** Check buttons, perform actions ***/ - if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) - { - if ( selectit ) - selectit = 0; - - redraw = 1; - ret = selection; - } // End of A - - if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) ) - { - if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ - scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. - move_selection = 1; //continue (move selection) - } - else if (scroll_delay == 0) { /*** Button is held ***/ - scroll_delay = SCROLL_LOOP_DELAY; - move_selection = 1; //continue (move selection) - } else { - scroll_delay--; // wait - } - - if (move_selection) - { - selection++; - if (selection == cheatmenuCount) - selection = offset = 0; - if ((selection - offset) >= PAGESIZE) - offset += PAGESIZE; - redraw = 1; - move_selection = 0; - } - } // End of down - if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) ) - { - if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ - scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. - move_selection = 1; //continue (move selection) - } - else if (scroll_delay == 0) { /*** Button is held ***/ - scroll_delay = SCROLL_LOOP_DELAY; - move_selection = 1; //continue (move selection) - } else { - scroll_delay--; // wait - } - - if (move_selection) - { - selection--; - if (selection < 0) { - selection = cheatmenuCount - 1; - offset = selection - PAGESIZE + 1; - } - if (selection < offset) - offset -= PAGESIZE; - if (offset < 0) - offset = 0; - redraw = 1; - move_selection = 0; - } - } // End of Up - if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) ) - { - /*** Go back a page ***/ - selection -= PAGESIZE; - if (selection < 0) - { - selection = cheatmenuCount - 1; - offset = selection - PAGESIZE + 1; - } - if (selection < offset) - offset -= PAGESIZE; - if (offset < 0) - offset = 0; - redraw = 1; - } - if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) ) - { - /*** Go forward a page ***/ - selection += PAGESIZE; - if (selection > cheatmenuCount - 1) - selection = offset = 0; - if ((selection - offset) >= PAGESIZE) - offset += PAGESIZE; - redraw = 1; - } + ret = RunMenu (loadmanwii, loadmancountwii, (char*)"Load Manager"); + if (ret >= loadmancountwii-1) + ret = loadmancount-1; } - } - else - { - WaitPrompt((char*)"No cheats found!"); - } - menu = oldmenu; -} - -/**************************************************************************** - * Game Options Menu - ***************************************************************************/ - -int -GameMenu () -{ - int gamemenuCount = 10; - char gamemenu[][50] = { - "Return to Game", - "Reset Game", - "ROM Information", - "Cheats", - "Load SRAM", "Save SRAM", - "Load Game Snapshot", "Save Game Snapshot", - "Reset Zoom", - "Back to Main Menu" - }; - - int ret, retval = 0; - int quit = 0; - int oldmenu = menu; - menu = 0; - - while (quit == 0) + else /* Gamecube menu */ + ret = RunMenu (loadman, loadmancount, (char*)"Load Manager"); + + switch (ret) + { + case 0: + /*** Load from SD ***/ + quit = OpenSD (); + break; + + case 1: + /*** Load from DVD ***/ + quit = OpenDVD (); + break; + + case 2: + /*** Load from SMB ***/ //(gamecube option) + quit = OpenSMB (); + break; + + case -1: /*** Button B ***/ + case 3: + retval = 0; + quit = 1; + break; + } + } + + /*** + * check for autoloadsram / freeze + ***/ + if ( retval == 1 ) // if ROM was loaded, load the SRAM & settings { - // disable SRAM/SNAPSHOT saving/loading if AUTO is on - - if (GCSettings.AutoLoad == 1) // Auto Load SRAM - gamemenu[4][0] = '\0'; - else if (GCSettings.AutoLoad == 2) // Auto Load SNAPSHOT - gamemenu[6][0] = '\0'; - - if (GCSettings.AutoSave == 1) // Auto Save SRAM - gamemenu[5][0] = '\0'; - else if (GCSettings.AutoSave == 2) // Auto Save SNAPSHOT - gamemenu[7][0] = '\0'; - else if (GCSettings.AutoSave == 3) // Auto Save BOTH + if ( GCSettings.AutoLoad == 1 ) { - gamemenu[5][0] = '\0'; - gamemenu[7][0] = '\0'; + quickLoadSRAM ( SILENT ); + S9xSoftReset(); // reset after loading sram } - - // hide cheats menu if cheats file not present - if(Cheat.num_cheats == 0) - gamemenu[3][0] = '\0'; - - ret = RunMenu (gamemenu, gamemenuCount, (char*)"Game Menu"); - - switch (ret) + else if ( GCSettings.AutoLoad == 2 ) { - case 0: // Return to Game - quit = retval = 1; - break; - - case 1: // Reset Game - zoom_reset (); - S9xSoftReset (); - quit = retval = 1; - break; - - case 2: // ROM Information - RomInfo(); - WaitButtonA (); - break; - - case 3: // load cheats - CheatMenu(); - break; - - case 4: // Load SRAM - zoom_reset (); - quit = retval = LoadSRAM(GCSettings.SaveMethod, NOTSILENT); - break; - - case 5: // Save SRAM - SaveSRAM(GCSettings.SaveMethod, NOTSILENT); - break; - - case 6: // Load Freeze - zoom_reset (); - quit = retval = NGCUnfreezeGame (GCSettings.SaveMethod, NOTSILENT); - break; - - case 7: // Save Freeze - NGCFreezeGame (GCSettings.SaveMethod, NOTSILENT); - break; - - case 8: // Reset Zoom - zoom_reset (); - quit = retval = 1; - break; - - case -1: // Button B - case 9: // Return to previous menu - retval = 0; - quit = 1; - break; + quickLoadFreeze ( SILENT ); } } - - menu = oldmenu; - - return retval; + + menu = oldmenu; + return retval; } /**************************************************************************** - * File Options Menu - ***************************************************************************/ -static int filemenuCount = 8; -static char filemenu[][50] = { - "Load Method", - "Load Folder", - "Save Method", - "Save Folder", - - "Auto Load", - "Auto Save", - "Verify MC Saves", - - "Back to Preferences Menu" + * Save Manager + ****************************************************************************/ +int savecountwii = 7; +char savemenuwii[][20] = { "Save to SD", "Load from SD", + "Save to MC SLOT A", "Load from MC SLOT A", + "Save to MC SLOT B", "Load from MC SLOT B", + "Return to previous" +}; +int savecount = 9; +char savemenu[][20] = { "Save to SD", "Load from SD", + "Save to MC SLOT A", "Load from MC SLOT A", + "Save to MC SLOT B", "Load from MC SLOT B", + "Save to SMB", "Load from SMB", + "Return to previous" }; - void -FileOptions () +SaveManager () { - int ret = 0; - int quit = 0; - int oldmenu = menu; - menu = 0; - while (quit == 0) - { - // some load/save methods are not implemented - here's where we skip them - // they need to be skipped in the order they were enumerated in snes9xGX.h - - // no USB ports on GameCube - #ifndef HW_RVL - if(GCSettings.LoadMethod == METHOD_USB) - GCSettings.LoadMethod++; - if(GCSettings.SaveMethod == METHOD_USB) - GCSettings.SaveMethod++; - #endif - - // saving to DVD is impossible - if(GCSettings.SaveMethod == METHOD_DVD) - GCSettings.SaveMethod++; - - // disable SMB in GC mode (stalls out) - #ifndef HW_RVL - if(GCSettings.LoadMethod == METHOD_SMB) - GCSettings.LoadMethod++; - if(GCSettings.SaveMethod == METHOD_SMB) - GCSettings.SaveMethod++; - #endif - - // disable MC saving in Wii mode - does not work for some reason! - #ifdef HW_RVL - if(GCSettings.SaveMethod == METHOD_MC_SLOTA) - GCSettings.SaveMethod++; - if(GCSettings.SaveMethod == METHOD_MC_SLOTB) - GCSettings.SaveMethod++; - #endif - - // correct load/save methods out of bounds - if(GCSettings.LoadMethod > 4) - GCSettings.LoadMethod = 0; - if(GCSettings.SaveMethod > 6) - GCSettings.SaveMethod = 0; - - if (GCSettings.LoadMethod == METHOD_AUTO) sprintf (filemenu[0],"Load Method AUTO"); - else if (GCSettings.LoadMethod == METHOD_SD) sprintf (filemenu[0],"Load Method SD"); - else if (GCSettings.LoadMethod == METHOD_USB) sprintf (filemenu[0],"Load Method USB"); - else if (GCSettings.LoadMethod == METHOD_DVD) sprintf (filemenu[0],"Load Method DVD"); - else if (GCSettings.LoadMethod == METHOD_SMB) sprintf (filemenu[0],"Load Method Network"); - - sprintf (filemenu[1], "Load Folder %s", GCSettings.LoadFolder); - - if (GCSettings.SaveMethod == METHOD_AUTO) sprintf (filemenu[2],"Save Method AUTO"); - else if (GCSettings.SaveMethod == METHOD_SD) sprintf (filemenu[2],"Save Method SD"); - else if (GCSettings.SaveMethod == METHOD_USB) sprintf (filemenu[2],"Save Method USB"); - else if (GCSettings.SaveMethod == METHOD_SMB) sprintf (filemenu[2],"Save Method Network"); - else if (GCSettings.SaveMethod == METHOD_MC_SLOTA) sprintf (filemenu[2],"Save Method MC Slot A"); - else if (GCSettings.SaveMethod == METHOD_MC_SLOTB) sprintf (filemenu[2],"Save Method MC Slot B"); - - sprintf (filemenu[3], "Save Folder %s", GCSettings.SaveFolder); - - // disable changing load/save directories for now - filemenu[1][0] = '\0'; - filemenu[3][0] = '\0'; - - if (GCSettings.AutoLoad == 0) sprintf (filemenu[4],"Auto Load OFF"); - else if (GCSettings.AutoLoad == 1) sprintf (filemenu[4],"Auto Load SRAM"); - else if (GCSettings.AutoLoad == 2) sprintf (filemenu[4],"Auto Load SNAPSHOT"); - - if (GCSettings.AutoSave == 0) sprintf (filemenu[5],"Auto Save OFF"); - else if (GCSettings.AutoSave == 1) sprintf (filemenu[5],"Auto Save SRAM"); - else if (GCSettings.AutoSave == 2) sprintf (filemenu[5],"Auto Save SNAPSHOT"); - else if (GCSettings.AutoSave == 3) sprintf (filemenu[5],"Auto Save BOTH"); - - sprintf (filemenu[6], "Verify MC Saves %s", - GCSettings.VerifySaves == true ? " ON" : "OFF"); - - ret = RunMenu (filemenu, filemenuCount, (char*)"Save/Load Options", 16); - - switch (ret) - { - case 0: - GCSettings.LoadMethod ++; - break; - - case 1: - break; - - case 2: - GCSettings.SaveMethod ++; - break; - - case 3: - break; - - case 4: - GCSettings.AutoLoad ++; - if (GCSettings.AutoLoad > 2) - GCSettings.AutoLoad = 0; - break; - - case 5: - GCSettings.AutoSave ++; - if (GCSettings.AutoSave > 3) - GCSettings.AutoSave = 0; - break; + int ret; + int quit = 0; + int oldmenu = menu; + menu = 0; + + while (quit == 0) + { + if ( isWii ) /* Wii menu */ + { + ret = RunMenu (savemenuwii, savecountwii, (char*)"SRAM Manager"); + if (ret >= savecountwii-1) + ret = savecount-1; + } + else /* Gamecube menu */ + ret = RunMenu (savemenu, savecount, (char*)"SRAM Manager"); + + switch (ret) + { + case 0: + /*** Save to SD***/ + SaveSRAMToSD (NOTSILENT); + break; + + case 1: + /*** Load from SD***/ + LoadSRAMFromSD (NOTSILENT); + break; + + case 2: + /*** Save to MC slot A ***/ + SaveSRAMToMC (CARD_SLOTA, NOTSILENT); + break; + + case 3: + /*** Load from MC slot A ***/ + LoadSRAMFromMC (CARD_SLOTA, NOTSILENT); + break; + + case 4: + /*** Save to MC slot B ***/ + SaveSRAMToMC (CARD_SLOTB, NOTSILENT); + break; + + case 5: + /*** Load from MC slot B ***/ + LoadSRAMFromMC (CARD_SLOTB, NOTSILENT); + break; - case 6: - GCSettings.VerifySaves ^= 1; - break; + case 6: + /*** Save to SMB **/ + SaveSRAMToSMB (NOTSILENT); + break; + + case 7: + /*** Load from SMB ***/ + LoadSRAMFromSMB (NOTSILENT); + break; + case -1: /*** Button B ***/ - case 7: - quit = 1; - break; - - } - } - menu = oldmenu; + case 8: + /*** Return ***/ + quit = 1; + break; + } + } + + menu = oldmenu; } /**************************************************************************** - * Video Options - ***************************************************************************/ -static int videomenuCount = 12; -static char videomenu[][50] = { - - "Transparency", - "Display Frame Rate", - "Enable Zooming", - "Video Filtering", - "Widescreen", - - "Shift Video Up", - "Shift Video Down", - "Shift Video Left", - "Shift Video Right", - - "Shift: ", - "Reset Video Shift", - - "Back to Preferences Menu" + * Emulator Options + ****************************************************************************/ +static int emuCount = 11; +static char emulatorOptions[][20] = { "Reverse Stereo OFF", + "Interp. Sound ON", "Transparency ON", "FPS Display OFF", + "MultiTap 5 OFF", "C-Stick Zoom OFF", + "Auto Load OFF", "Auto Save OFF", "Verify MC Saves OFF", + "Save Prefs Now", "Return to previous" }; void -VideoOptions () +EmulatorOptions () { int ret = 0; int quit = 0; int oldmenu = menu; menu = 0; + while (quit == 0) { - sprintf (videomenu[0], "Transparency %s", + sprintf (emulatorOptions[0], "Reverse Stereo %s", + Settings.ReverseStereo == true ? " ON" : "OFF"); + + sprintf (emulatorOptions[1], "Interp. Sound %s", + Settings.InterpolatedSound == true ? " ON" : "OFF"); + + sprintf (emulatorOptions[2], "Transparency %s", Settings.Transparency == true ? " ON" : "OFF"); - - sprintf (videomenu[1], "Display Frame Rate %s", + + sprintf (emulatorOptions[3], "FPS Display %s", Settings.DisplayFrameRate == true ? " ON" : "OFF"); - - sprintf (videomenu[2], "Enable Zooming %s", + + sprintf (emulatorOptions[4], "MultiTap 5 %s", + Settings.MultiPlayer5Master == true ? " ON" : "OFF"); + + sprintf (emulatorOptions[5], "C-Stick Zoom %s", GCSettings.NGCZoom == true ? " ON" : "OFF"); - - // don't allow original render mode if progressive video mode detected - if (GCSettings.render==0 && progressive) - GCSettings.render++; - - if ( GCSettings.render == 0 ) - sprintf (videomenu[3], "Video Rendering Original"); - if ( GCSettings.render == 1 ) - sprintf (videomenu[3], "Video Rendering Filtered"); - if ( GCSettings.render == 2 ) - sprintf (videomenu[3], "Video Rendering Unfiltered"); - - sprintf (videomenu[4], "Video Scaling %s", - GCSettings.widescreen == true ? "16:9 Correction" : "Default"); - - sprintf (videomenu[9], "Video Shift: %d, %d", GCSettings.xshift, GCSettings.yshift); - - ret = RunMenu (videomenu, videomenuCount, (char*)"Video Options", 16); - + + if (GCSettings.AutoLoad == 0) sprintf (emulatorOptions[6],"Auto Load OFF"); + else if (GCSettings.AutoLoad == 1) sprintf (emulatorOptions[6],"Auto Load SRAM"); + else if (GCSettings.AutoLoad == 2) sprintf (emulatorOptions[6],"Auto Load FREEZE"); + + if (GCSettings.AutoSave == 0) sprintf (emulatorOptions[7],"Auto Save OFF"); + else if (GCSettings.AutoSave == 1) sprintf (emulatorOptions[7],"Auto Save SRAM"); + else if (GCSettings.AutoSave == 2) sprintf (emulatorOptions[7],"Auto Save FREEZE"); + else if (GCSettings.AutoSave == 3) sprintf (emulatorOptions[7],"Auto Save BOTH"); + + sprintf (emulatorOptions[8], "Verify MC Saves %s", + GCSettings.VerifySaves == true ? " ON" : "OFF"); + + ret = RunMenu (emulatorOptions, emuCount, (char*)"Emulator Options"); + switch (ret) { case 0: - Settings.Transparency ^= 1; + Settings.ReverseStereo = + (Settings.ReverseStereo == false ? true : false); break; - + case 1: - Settings.DisplayFrameRate ^= 1; + Settings.InterpolatedSound = + (Settings.InterpolatedSound == false ? true : false); break; - + case 2: - GCSettings.NGCZoom ^= 1; + Settings.Transparency = + (Settings.Transparency == false ? true : false); break; - + case 3: - GCSettings.render++; - if (GCSettings.render > 2 ) - GCSettings.render = 0; - // reset zoom - zoom_reset (); + Settings.DisplayFrameRate = + (Settings.DisplayFrameRate == false ? true : false); break; - + case 4: - GCSettings.widescreen ^= 1; + Settings.MultiPlayer5Master = + (Settings.MultiPlayer5Master == false ? true : false); + + if (Settings.MultiPlayer5Master) + { + S9xSetController (1, CTL_MP5, 1, 2, 3, -1); + } + else + { + S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); + } break; - + case 5: - // Move up - GCSettings.yshift--; + GCSettings.NGCZoom = + (GCSettings.NGCZoom == false ? true : false); break; + case 6: - // Move down - GCSettings.yshift++; + GCSettings.AutoLoad ++; + if (GCSettings.AutoLoad > 2) + GCSettings.AutoLoad = 0; break; + case 7: - // Move left - GCSettings.xshift--; + GCSettings.AutoSave ++; + if (GCSettings.AutoSave > 3) + GCSettings.AutoSave = 0; break; + case 8: - // Move right - GCSettings.xshift++; + GCSettings.VerifySaves = + (GCSettings.VerifySaves == false ? true : false); break; - + case 9: + quickSavePrefs(NOTSILENT); break; - + + case -1: /*** Button B ***/ case 10: - // reset video shifts - GCSettings.xshift = GCSettings.yshift = 0; - WaitPrompt((char *)"Video Shift Reset"); - break; - - case -1: // Button B - case 11: quit = 1; break; - + } } + menu = oldmenu; } /**************************************************************************** * Controller Configuration * - * Snes9x 1.51 uses a cmd system to work out which button has been pressed. - * Here, I simply move the designated value to the gcpadmaps array, which - * saves on updating the cmd sequences. - ***************************************************************************/ + * Snes9x 1.50 uses a cmd system to work out which button has been pressed. + * Here, I simply move the designated value to the gcpadmaps array, which saves + * on updating the cmd sequences. + ****************************************************************************/ u32 GetInput (u16 ctrlr_type) { - //u32 exp_type; - u32 pressed; + u32 exp_type, pressed; pressed=0; s8 gc_px = 0; - + while( PAD_ButtonsHeld(0) #ifdef HW_RVL | WPAD_ButtonsHeld(0) #endif ) VIDEO_WaitVSync(); // button 'debounce' - + while (pressed == 0) { VIDEO_WaitVSync(); // get input based on controller type - if (ctrlr_type == CTRLR_GCPAD) + if (ctrlr_type == CTRLR_GCPAD) { pressed = PAD_ButtonsHeld (0); gc_px = PAD_SubStickX (0); - } + } #ifdef HW_RVL - else - { + else + { // if ( WPAD_Probe( 0, &exp_type) == 0) // check wiimote and expansion status (first if wiimote is connected & no errors) // { pressed = WPAD_ButtonsHeld (0); - + // if (ctrlr_type != CTRLR_WIIMOTE && exp_type != ctrlr_type+1) // if we need input from an expansion, and its not connected... // pressed = 0; // } @@ -702,17 +481,17 @@ GetInput (u16 ctrlr_type) if ( (gc_px < -70) || (pressed & WPAD_BUTTON_HOME) || (pressed & WPAD_CLASSIC_BUTTON_HOME) ) return 0; } // end while - while( pressed == (PAD_ButtonsHeld(0) + while( pressed == (PAD_ButtonsHeld(0) #ifdef HW_RVL | WPAD_ButtonsHeld(0) #endif ) ) VIDEO_WaitVSync(); - + return pressed; } // end GetInput() int cfg_text_count = 7; -char cfg_text[][50] = { +char cfg_text[][20] = { "Remapping ", "Press Any Button", "on the", @@ -726,10 +505,10 @@ u32 GetButtonMap(u16 ctrlr_type, char* btn_name) { u32 pressed, previous; - char temp[50] = ""; - uint k; + char temp[20] = ""; + int k; pressed = 0; previous = 1; - + switch (ctrlr_type) { case CTRLR_NUNCHUK: strncpy (cfg_text[3], (char*)"NUNCHUK", 7); @@ -743,16 +522,16 @@ GetButtonMap(u16 ctrlr_type, char* btn_name) case CTRLR_WIIMOTE: strncpy (cfg_text[3], (char*)"WIIMOTE", 7); break; - }; - + }; + /*** note which button we are remapping ***/ sprintf (temp, (char*)"Remapping "); - for (k=0; k<9-strlen(btn_name); k++) strcat(temp, " "); // add whitespace padding to align text + for (k=0; k<9-strlen(btn_name) ;k++) strcat(temp, " "); // add whitespace padding to align text strncat (temp, btn_name, 9); // snes button we are remapping strncpy (cfg_text[0], temp, 19); // copy this all back to the text we wish to display - + DrawMenu(&cfg_text[0], NULL, cfg_text_count, 1); // display text - + // while (previous != pressed && pressed == 0); // get two consecutive button presses (which are the same) // { // previous = pressed; @@ -761,9 +540,9 @@ GetButtonMap(u16 ctrlr_type, char* btn_name) // } return pressed; } // end getButtonMap() - + int cfg_btns_count = 13; -char cfg_btns_menu[][50] = { +char cfg_btns_menu[][20] = { "A - ", "B - ", "X - ", @@ -791,14 +570,13 @@ ConfigureButtons (u16 ctrlr_type) int ret = 0; int oldmenu = menu; menu = 0; - char* menu_title = NULL; + char* menu_title; u32 pressed; - - unsigned int* currentpadmap = 0; - char temp[50] = ""; - int i, j; - uint k; - + + unsigned int* currentpadmap; + char temp[20] = ""; + int i, j, k; + /*** Update Menu Title (based on controller we're configuring) ***/ switch (ctrlr_type) { case CTRLR_NUNCHUK: @@ -818,18 +596,18 @@ ConfigureButtons (u16 ctrlr_type) currentpadmap = wmpadmap; break; }; - + while (quit == 0) - { + { /*** Update Menu with Current ButtonMap ***/ for (i=0; i<12; i++) // snes pad has 12 buttons to config (go thru them) { // get current padmap button name to display - for ( j=0; + for ( j=0; j < ctrlr_def[ctrlr_type].num_btns && currentpadmap[i] != ctrlr_def[ctrlr_type].map[j].btn // match padmap button press with button names ; j++ ); - + memset (temp, 0, sizeof(temp)); strncpy (temp, cfg_btns_menu[i], 12); // copy snes button information if (currentpadmap[i] == ctrlr_def[ctrlr_type].map[j].btn) // check if a match was made @@ -842,9 +620,9 @@ ConfigureButtons (u16 ctrlr_type) strncpy (cfg_btns_menu[i], temp, 19); // move back updated information } - - ret = RunMenu (cfg_btns_menu, cfg_btns_count, menu_title, 16); - + + ret = RunMenu (cfg_btns_menu, cfg_btns_count, menu_title, 18); + switch (ret) { case 0: @@ -876,22 +654,23 @@ ConfigureButtons (u16 ctrlr_type) break; } } + menu = oldmenu; } // end configurebuttons() -int ctlrmenucount = 9; -char ctlrmenu[][50] = { - // toggle: - "MultiTap", - "SuperScope", - "Snes Mice", - "Justifiers", - // config: - "Nunchuk", +int cfg_ctrlr_count_wii = 6; +char cfg_ctrlr_menu_wii[][20] = { "Nunchuk", "Classic Controller", - "Wiimote", "Gamecube Pad", - "Back to Preferences Menu" + "Wiimote", + "Save Prefs Now", + "Return to previous" +}; + +int cfg_ctrlr_count_gc = 3; +char cfg_ctrlr_menu_gc[][20] = { "Gamecube Pad", + "Save Prefs Now", + "Return to previous" }; void @@ -901,245 +680,180 @@ ConfigureControllers () int ret = 0; int oldmenu = menu; menu = 0; - - // disable unavailable controller options if in GC mode - #ifndef HW_RVL - ctlrmenu[4][0] = '\0'; - ctlrmenu[5][0] = '\0'; - ctlrmenu[6][0] = '\0'; - #endif - + while (quit == 0) - { - sprintf (ctlrmenu[0], "MultiTap %s", Settings.MultiPlayer5Master == true ? " ON" : "OFF"); - - if (GCSettings.Superscope > 0) sprintf (ctlrmenu[1], "Superscope: Pad %d", GCSettings.Superscope); - else sprintf (ctlrmenu[1], "Superscope OFF"); - - if (GCSettings.Mouse > 0) sprintf (ctlrmenu[2], "Mice: %d", GCSettings.Mouse); - else sprintf (ctlrmenu[2], "Mice: OFF"); - - if (GCSettings.Justifier > 0) sprintf (ctlrmenu[3], "Justifiers: %d", GCSettings.Justifier); - else sprintf (ctlrmenu[3], "Justifiers: OFF"); - - /*** Controller Config Menu ***/ - ret = RunMenu (ctlrmenu, ctlrmenucount, (char*)"Configure Controllers"); - + { +#ifdef HW_RVL + /*** Wii Controller Config Menu ***/ + ret = RunMenu (cfg_ctrlr_menu_wii, cfg_ctrlr_count_wii, (char*)"Configure Controllers"); + switch (ret) { case 0: - Settings.MultiPlayer5Master ^= 1; - break; - case 1: - GCSettings.Superscope ++; - if (GCSettings.Superscope > 4) - GCSettings.Superscope = 0; - break; - case 2: - GCSettings.Mouse ++; - if (GCSettings.Mouse > 2) - GCSettings.Mouse = 0; - break; - case 3: - GCSettings.Justifier ++; - if (GCSettings.Justifier > 2) - GCSettings.Justifier = 0; - break; - - case 4: /*** Configure Nunchuk ***/ ConfigureButtons (CTRLR_NUNCHUK); break; - - case 5: + + case 1: /*** Configure Classic ***/ ConfigureButtons (CTRLR_CLASSIC); break; - - case 6: + + case 2: + /*** Configure GC Pad ***/ + ConfigureButtons (CTRLR_GCPAD); + break; + + case 3: /*** Configure Wiimote ***/ ConfigureButtons (CTRLR_WIIMOTE); break; - - case 7: - /*** Configure GC Pad ***/ - ConfigureButtons (CTRLR_GCPAD); + + case 4: + /*** Save Preferences Now ***/ + quickSavePrefs(NOTSILENT); break; case -1: /*** Button B ***/ - case 8: + case 5: /*** Return ***/ quit = 1; break; } - } - - menu = oldmenu; -} - -/**************************************************************************** - * Preferences Menu - ***************************************************************************/ -static int prefmenuCount = 5; -static char prefmenu[][50] = { - "Controllers", - "Video", - "Saving / Loading", - "Reset Preferences", - "Back to Main Menu" -}; - -void -PreferencesMenu () -{ - int ret = 0; - int quit = 0; - int oldmenu = menu; - menu = 0; - while (quit == 0) - { - ret = RunMenu (prefmenu, prefmenuCount, (char*)"Preferences"); - +#else + /*** Gamecube Controller Config Menu ***/ + ret = RunMenu (cfg_ctrlr_menu_gc, cfg_ctrlr_count_gc, (char*)"Configure Controllers"); + switch (ret) { case 0: - ConfigureControllers (); + /*** Configure Nunchuk ***/ + ConfigureButtons (CTRLR_GCPAD); break; - + case 1: - VideoOptions (); - break; - - case 2: - FileOptions (); - break; - - case 3: - DefaultSettings (); - WaitPrompt((char *)"Preferences Reset"); + /*** Save Preferences Now ***/ + quickSavePrefs(NOTSILENT); break; case -1: /*** Button B ***/ - case 4: - SavePrefs(GCSettings.SaveMethod, SILENT); + case 2: + /*** Return ***/ quit = 1; break; - } +#endif } + menu = oldmenu; } /**************************************************************************** * Main Menu - ***************************************************************************/ -int menucount = 7; -char menuitems[][50] = { - "Choose Game", - "Preferences", - "Game Menu", - "Credits", - "DVD Motor Off", - "Reset System", - "Return to Loader" + ****************************************************************************/ +int menucount = 10; +char menuitems[][20] = { "Choose Game", + "SRAM Manager", "Freeze Manager", + "Config Controllers", "Emulator Options", + "Reset Game", "Stop DVD Drive", "Exit to Loader", + "Reboot System", "Return to Game" }; void -MainMenu (int selectedMenu) +mainmenu () { int quit = 0; int ret; - - // disable game-specific menu items if a ROM isn't loaded - if (SNESROMSize == 0) - menuitems[2][0] = '\0'; + int *psoid = (int *) 0x80001800; + void (*PSOReload) () = (void (*)()) 0x80001800; + + if ( isWii ) + sprintf (menuitems[8],"Reset Wii"); else - sprintf (menuitems[2], "Game Menu"); - - #ifndef HW_DOL - // don't show dvd motor off on the wii - menuitems[4][0] = '\0'; - #endif - + sprintf (menuitems[8],"Reset Gamecube"); + VIDEO_WaitVSync (); - + while (quit == 0) { - if(selectedMenu >= 0) - { - ret = selectedMenu; - selectedMenu = -1; // default back to main menu - } - else - { - ret = RunMenu (menuitems, menucount, (char*)"Main Menu"); - } - + ret = RunMenu (menuitems, menucount, (char*)"Main Menu"); + switch (ret) { case 0: - // Load ROM Menu + /*** Load ROM Menu ***/ quit = LoadManager (); break; - + case 1: - // Preferences - PreferencesMenu (); - break; - + /*** SRAM Manager Menu ***/ + if ( ARAM_ROMSIZE > 0 ) + SaveManager (); + else + WaitPrompt((char*) "No ROM is loaded!"); + break; + case 2: - // Game Options - quit = GameMenu (); - break; - - case 3: - // Credits - Credits (); - WaitButtonA (); + /*** Do Freeze / Thaw Menu ***/ + if ( ARAM_ROMSIZE > 0 ) + quit = FreezeManager (); + else + WaitPrompt((char*) "No ROM is loaded!"); break; - + + case 3: + /*** Configure Controllers ***/ + ConfigureControllers (); + break; + case 4: - // turn the dvd motor off (GC only) - #ifdef HW_DOL - dvd_motor_off (); - #endif + /*** Emulator Options ***/ + EmulatorOptions (); break; - + case 5: - // Reset the Gamecube/Wii - Reboot(); - break; - + /*** Soft reset ***/ + S9xSoftReset (); + quit = 1; + break; + case 6: - // Exit to Loader - #ifdef HW_RVL - #ifdef WII_DVD - DI_Close(); - #endif - exit(0); + /*** Turn off DVD motor ***/ + dvd_motor_off(); + break; + + case 7: + /*** Exit to Loader ***/ + #ifdef __wii__ + exit(0); #else // gamecube - if (psoid[0] == PSOSDLOADID) - PSOReload (); + if (psoid[0] == PSOSDLOADID) + PSOReload (); #endif break; - - case -1: // Button B - // Return to Game + + case 8: + /*** Reset the Gamecube/Wii ***/ + Reboot(); + break; + + case -1: /*** Button B ***/ + case 9: + /*** Return to Game ***/ quit = 1; break; + } + } - - // Wait for buttons to be released - int count = 0; // how long we've been waiting for the user to release the button - while(count < 50 && ( - PAD_ButtonsHeld(0) - #ifdef HW_RVL - || WPAD_ButtonsHeld(0) - #endif - )) - { - VIDEO_WaitVSync(); - count++; - } + + /*** Remove any still held buttons ***/ +#ifdef HW_RVL + while( PAD_ButtonsHeld(0) || WPAD_ButtonsHeld(0) ) + VIDEO_WaitVSync(); +#else + while( PAD_ButtonsHeld(0) ) + VIDEO_WaitVSync(); +#endif + } diff --git a/source/ngc/menu.h b/source/ngc/menu.h index 3b57fdac..62c825fc 100644 --- a/source/ngc/menu.h +++ b/source/ngc/menu.h @@ -1,20 +1,15 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * crunchy2 May-June 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * menu.h + * Nintendo Gamecube Menu * - * Menu flow routines - handles all menu logic - ***************************************************************************/ + * softdev July 2006 + ****************************************************************************/ #ifndef _NGCMENU_ #define _NGCMENU_ -void MainMenu (int selectedMenu); +void mainmenu (); #endif diff --git a/source/ngc/menudraw.cpp b/source/ngc/menudraw.cpp deleted file mode 100644 index 3cfa11fd..00000000 --- a/source/ngc/menudraw.cpp +++ /dev/null @@ -1,1066 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 June 2007 - * Michniewski 2008 - * Tantric August 2008 - * - * menudraw.cpp - * - * Menu drawing routines - * - * Uses libfreetype 2.2.1 compiled for GC with TTF support only. - * TTF only reduces the library by some 900k bytes! - * - * **WARNING*** - * - * ONLY USE GUARANTEED PATENT FREE FONTS. - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include FT_FREETYPE_H - -#include "memmap.h" - -#include "video.h" -#include "menudraw.h" -#include "snes9xGX.h" -#include "filesel.h" -#include "dvd.h" -#include "aram.h" -#include "images/gfx_bg.h" -#include "input.h" - -/*** Globals ***/ -FT_Library ftlibrary; -FT_Face face; -FT_GlyphSlot slot; -FT_UInt glyph_index; -static unsigned int fonthi, fontlo; - -extern char fontface[]; /*** From fontface.s ***/ -extern int fontsize; /*** From fontface.s ***/ -extern int screenheight; -extern unsigned int *xfb[2]; -extern int whichfb; - -/*** Permanent backdrop ***/ -#ifdef HW_RVL -u32 *backdrop = NULL; -#endif -unsigned int getcolour (u8 r1, u8 g1, u8 b1); -void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ); -u32 getrgb( u32 ycbr, u32 low ); - -/**************************************************************************** - * Initialisation of libfreetype - ***************************************************************************/ -int -FT_Init () -{ - - int err; - - err = FT_Init_FreeType (&ftlibrary); - if (err) - return 1; - - err = - FT_New_Memory_Face (ftlibrary, (FT_Byte *) fontface, fontsize, 0, &face); - if (err) - return 1; - - setfontsize (16); - setfontcolour (0xff, 0xff, 0xff); - - slot = face->glyph; - - return 0; - -} - -/**************************************************************************** - * setfontsize - * - * Set the screen font size in pixels - ***************************************************************************/ -void -setfontsize (int pixelsize) -{ - int err; - - err = FT_Set_Pixel_Sizes (face, 0, pixelsize); - - if (err) - printf ("Error setting pixel sizes!"); -} - -/**************************************************************************** - * DrawCharacter - * Draws a single character on the screen - ***************************************************************************/ -static void -DrawCharacter (FT_Bitmap * bmp, FT_Int x, FT_Int y) -{ - FT_Int i, j, p, q; - FT_Int x_max = x + bmp->width; - FT_Int y_max = y + bmp->rows; - int spos; - unsigned int pixel; - int c; - - for (i = x, p = 0; i < x_max; i++, p++) - { - for (j = y, q = 0; j < y_max; j++, q++) - { - if (i < 0 || j < 0 || i >= 640 || j >= screenheight) - continue; - - /*** Convert pixel position to GC int sizes ***/ - spos = (j * 320) + (i >> 1); - - pixel = xfb[whichfb][spos]; - c = bmp->buffer[q * bmp->width + p]; - - /*** Cool Anti-Aliasing doesn't work too well at hires on GC ***/ - if (c > 128) - { - if (i & 1) - pixel = (pixel & 0xffff0000) | fontlo; - else - pixel = ((pixel & 0xffff) | fonthi); - - xfb[whichfb][spos] = pixel; - } - } - } -} - -/**************************************************************************** - * DrawText - * - * Place the font bitmap on the screen - ***************************************************************************/ -void -DrawText (int x, int y, char *text) -{ - int px, n; - int i; - int err; - int value, count; - - n = strlen (text); - if (n == 0) - return; - - setfontcolour (0x00, 0x00, 0x00); - - /*** x == -1, auto centre ***/ - if (x == -1) - { - value = 0; - px = 0; - } - else - { - value = 1; - px = x; - } - - for (count = value; count < 2; count++) - { - /*** Draw the string ***/ - for (i = 0; i < n; i++) - { - err = FT_Load_Char (face, text[i], FT_LOAD_RENDER); - - if (err) - { - printf ("Error %c %d\n", text[i], err); - continue; /*** Skip unprintable characters ***/ - } - - if (count) - DrawCharacter (&slot->bitmap, px + slot->bitmap_left, - y - slot->bitmap_top); - - px += slot->advance.x >> 6; - } - - px = (640 - px) >> 1; - - } -} - -/**************************************************************************** - * setfontcolour - * - * Uses RGB triple values. - ***************************************************************************/ -void -setfontcolour (u8 r, u8 g, u8 b) -{ - u32 fontcolour; - - fontcolour = getcolour (r, g, b); - fonthi = fontcolour & 0xffff0000; - fontlo = fontcolour & 0xffff; -} - -/**************************************************************************** - * Display credits, legal copyright and licence - * - * THIS MUST NOT BE REMOVED IN ANY DERIVATIVE WORK. - ***************************************************************************/ -void -Credits () -{ - clearscreen (); - - setfontcolour (0x00, 0x00, 0x00); - - setfontsize (28); - DrawText (-1, 60, (char*)"Credits"); - - int ypos = 25; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - setfontsize (20); - DrawText (-1, ypos += 30, (char*)"Technical"); - - setfontsize (16); - - DrawText (75, ypos += 30, (char*)"Snes9x GX 00x"); - DrawText (350, ypos, (char*)"michniewski & Tantric"); - DrawText (75, ypos += 20, (char*)"Snes9X GX 2.0.1 GameCube"); - DrawText (350, ypos, (char*)"crunchy2, eke-eke, others"); - DrawText (75, ypos += 20, (char*)"Snes9x GX GameCube Port"); - DrawText (350, ypos, (char*)"SoftDev"); - DrawText (75, ypos += 20, (char*)"Snes9x 1.5.1"); - DrawText (350, ypos, (char*)"Snes9x Team"); - DrawText (75, ypos += 20, (char*)"GX"); - DrawText (350, ypos, (char*)"http://www.gc-linux.org"); - DrawText (75, ypos += 20, (char*)"libogc"); - DrawText (350, ypos, (char*)"Shagkur & wintermute"); - - setfontsize (20); - DrawText (-1, ypos += 40, (char*)"Testing"); - - setfontsize (16); - DrawText (-1, ypos += 30, (char*)"TehSkeen users"); - - setfontsize (12); - DrawText (-1, ypos += 75, (char*)"Snes9x - Copyright (c) Snes9x Team 1996 - 2006"); - DrawText (-1, ypos += 15, (char*)"This software is open source and may be copied, distributed, or modified"); - DrawText (-1, ypos += 15, (char*)"under the terms of the GNU General Public License (GPL) Version 2."); - - showscreen (); -} - - - -/**************************************************************************** - * getcolour - * - * Simply converts RGB to Y1CbY2Cr format - * - * I got this from a pastebin, so thanks to whoever originally wrote it! - ***************************************************************************/ - -unsigned int -getcolour (u8 r1, u8 g1, u8 b1) -{ - int y1, cb1, cr1, y2, cb2, cr2, cb, cr; - u8 r2, g2, b2; - - r2 = r1; - g2 = g1; - b2 = b1; - - y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000; - cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000; - cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000; - - y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000; - cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000; - cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000; - - cb = (cb1 + cb2) >> 1; - cr = (cr1 + cr2) >> 1; - - return ((y1 << 24) | (cb << 16) | (y2 << 8) | cr); -} - -/**************************************************************************** - * Unpackbackdrop - * - * Decompress menu background and store it in ARAM or memory - ***************************************************************************/ -void -unpackbackdrop () -{ - unsigned long res, inbytes, outbytes; - unsigned int colour; - int offset; - int i; - int bgSize = (screenheight * 640 * 2); - - u32 * bgtemp = (u32 *) malloc (bgSize); - colour = getcolour (0x00, 0x00, 0x00); - - /*** Fill with black for now ***/ - for (i = 0; i < (320 * screenheight); i++) - bgtemp[i] = colour; - - /*** If it's PAL50, need to move down a few lines ***/ - offset = ((screenheight - 480) >> 1) * 320; - inbytes = BG_COMPRESSED; - outbytes = BG_RAW; - - res = - uncompress ((Bytef *) bgtemp + offset, &outbytes, (Bytef *) bg, - inbytes); - - #ifdef HW_RVL - // On Wii - store backdrop in MEM2 - unsigned int MEM2Storage = 0x91000000; - backdrop = (u32 *)MEM2Storage; - memcpy(backdrop, bgtemp, bgSize); - #else - // On GameCube - store the backdrop in ARAM - ARAMPut ((char *) bgtemp, (char *) AR_BACKDROP, bgSize); - #endif - - free (bgtemp); - bgtemp = NULL; - - clearscreen (); - showscreen (); -} - -/**************************************************************************** - * Wait for user to press A - ***************************************************************************/ -void -WaitButtonA () -{ -#ifdef HW_RVL - while ( (PAD_ButtonsDown (0) & PAD_BUTTON_A) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) VIDEO_WaitVSync(); - while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) && !(WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) VIDEO_WaitVSync(); -#else - while ( PAD_ButtonsDown (0) & PAD_BUTTON_A ) VIDEO_WaitVSync(); - while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) ) VIDEO_WaitVSync(); -#endif -} - -/**************************************************************************** - * Wait for user to press A or B. Returns 0 = B; 1 = A - ***************************************************************************/ - -int -WaitButtonAB () -{ -#ifdef HW_RVL - u32 gc_btns, wm_btns; - - while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) - || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B)) - ) VIDEO_WaitVSync(); - - while ( TRUE ) - { - gc_btns = PAD_ButtonsDown (0); - wm_btns = WPAD_ButtonsDown (0); - if ( (gc_btns & PAD_BUTTON_A) || (wm_btns & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) - return 1; - else if ( (gc_btns & PAD_BUTTON_B) || (wm_btns & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) - return 0; - } -#else - u32 gc_btns; - - while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) VIDEO_WaitVSync(); - - while ( TRUE ) - { - gc_btns = PAD_ButtonsDown (0); - if ( gc_btns & PAD_BUTTON_A ) - return 1; - else if ( gc_btns & PAD_BUTTON_B ) - return 0; - } -#endif -} - -/**************************************************************************** - * Show a prompt - ***************************************************************************/ -void -WaitPrompt (char *msg) -{ - int ypos = (screenheight - 64) >> 1; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - clearscreen (); - DrawText (-1, ypos, msg); - ypos += 30; - DrawText (-1, ypos, (char*)"Press A to continue"); - showscreen (); - WaitButtonA (); -} - -/**************************************************************************** - * Show a prompt with choice of two options. Returns 1 if A button was pressed - and 0 if B button was pressed. - ***************************************************************************/ -int -WaitPromptChoice (char *msg, char *bmsg, char *amsg) -{ - int ypos = (screenheight - 64) >> 1; - - if (screenheight == 480) - ypos += 37; - else - ypos += 17; - - clearscreen (); - DrawText (-1, ypos, msg); - ypos += 60; - char txt[80]; - sprintf (txt, "B = %s : A = %s", bmsg, amsg); - DrawText (-1, ypos, txt); - showscreen (); - return WaitButtonAB (); -} - -/**************************************************************************** - * Show an action in progress - ***************************************************************************/ -void -ShowAction (char *msg) -{ - int ypos = (screenheight - 30) >> 1; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - clearscreen (); - DrawText (-1, ypos, msg); - showscreen (); -} - -/**************************************************************************** - * Generic Menu Routines - ***************************************************************************/ -void -DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize, int x) -{ - int i, w = 0; - int ypos = 0; - int n = 1; - int line_height; - - ypos = 45; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - clearscreen (); - - setfontcolour (0, 0, 0); - - if (title != NULL) - { - setfontsize (28); - DrawText (-1, 60, title); - } - - setfontsize (12); - DrawText (510, screenheight - 20, (char *)VERSIONSTR); - - // Draw menu items - - setfontsize (fontsize); // set font size - - line_height = (fontsize + 8); - - for (i = 0; i < maxitems; i++) - { - if(strlen(items[i]) > 0) - { - if ( items[i] == NULL ) - ypos -= line_height; - else if (i == selected) - { - for( w = 0; w < line_height; w++ ) - DrawLineFast( 30, 610, n * line_height + (ypos-line_height+6) + w, 0x80, 0x80, 0x80 ); - - setfontcolour (0xff, 0xff, 0xff); - DrawText (x, n * line_height + ypos, items[i]); - setfontcolour (0x00, 0x00, 0x00); - } - else - { - DrawText (x, n * line_height + ypos, items[i]); - } - n++; - } - } - - showscreen (); - -} - -/**************************************************************************** - * FindMenuItem - * - * Help function to find the next visible menu item on the list - * Supports menu wrap-around - ***************************************************************************/ - -int FindMenuItem(char items[][50], int maxitems, int currentItem, int direction) -{ - int nextItem = currentItem + direction; - - if(nextItem < 0) - nextItem = maxitems-1; - else if(nextItem >= maxitems) - nextItem = 0; - - if(strlen(items[nextItem]) > 0) - return nextItem; - else - return FindMenuItem(&items[0], maxitems, nextItem, direction); -} - -/**************************************************************************** - * RunMenu - * - * Call this with the menu array defined in menu.cpp - * It's here to keep all the font / interface stuff together. - ***************************************************************************/ -int menu = 0; - -int -RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x) -{ - int redraw = 1; - int quit = 0; - int ret = 0; - - u32 p = 0; - u32 wp = 0; - signed char gc_ay = 0; - signed char wm_ay = 0; - - while (quit == 0) - { - if (redraw) - { - DrawMenu (&items[0], title, maxitems, menu, fontsize); - redraw = 0; - } - - gc_ay = PAD_StickY (0); - p = PAD_ButtonsDown (0); -#ifdef HW_RVL - wm_ay = WPAD_Stick (0,0, 1); - wp = WPAD_ButtonsDown (0); -#endif - - - VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads - - /*** Look for up ***/ - if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) ) - { - redraw = 1; - menu = FindMenuItem(&items[0], maxitems, menu, -1); - } - - /*** Look for down ***/ - if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) ) - { - redraw = 1; - menu = FindMenuItem(&items[0], maxitems, menu, +1); - } - - if ((p & PAD_BUTTON_A) || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A))) - { - quit = 1; - ret = menu; - } - - if ((p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))) - { - quit = -1; - ret = -1; - } - } - - /*** Wait for B button to be released before proceeding ***/ - while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) -#ifdef HW_RVL - || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) -#endif - ) - { - ret = -1; - VIDEO_WaitVSync(); - } - - return ret; - -} - -/**************************************************************************** - * Showfile screen - * - * Display the file selection to the user - ***************************************************************************/ - -void -ShowFiles (FILEENTRIES filelist[], int maxfiles, int offset, int selection) -{ - int i, j; - char text[MAXPATHLEN]; - int ypos; - int w; - - clearscreen (); - - setfontsize (28); - DrawText (-1, 60, (char*)"Choose Game"); - - setfontsize(18); - - ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1; - - if (screenheight == 480) - ypos += 24; - else - ypos += 10; - - j = 0; - for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++) - { - if (filelist[i].flags) // if a dir - { - strcpy (text, "["); - strcat (text, filelist[i].displayname); - strcat (text, "]"); - } - else - { - // hide file extension on listing (.7z, .fig, .smc) - StripExt(text, filelist[i].displayname); - } - if (j == (selection - offset)) - { - /*** Highlighted text entry ***/ - for ( w = 0; w < 20; w++ ) - DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 ); - - setfontcolour (0x00, 0x00, 0xe0); - DrawText (50, (j * 20) + ypos, text); - setfontcolour (0x00, 0x00, 0x00); - } - else - { - /*** Normal entry ***/ - DrawText (50, (j * 20) + ypos, text); - } - j++; - } - showscreen (); -} - -/**************************************************************************** - * Cheats screen - * - * Displays a scrollable list of cheats to the user - ***************************************************************************/ - -void -ShowCheats (char items[][50], char itemvalues[][50], int maxitems, int offset, int selection) -{ - int i, j = 0; - int ypos; - int w; - - clearscreen (); - - setfontsize (28); - DrawText (-1, 60, (char*)"Cheats"); - - setfontsize(18); - - ypos = (screenheight - ((PAGESIZE - 1) * 20)) >> 1; - - if (screenheight == 480) - ypos += 24; - else - ypos += 10; - - for (i = offset; i < (offset + PAGESIZE) && (i < maxitems); i++) - { - if (i == selection) - { - /*** Highlighted text entry ***/ - for ( w = 0; w < 20; w++ ) - DrawLineFast( 30, 610, ( j * 20 ) + (ypos-16) + w, 0x80, 0x80, 0x80 ); - - DrawText (150, (j * 20) + ypos, items[i]); - DrawText (400, (j * 20) + ypos, itemvalues[i]); - } - else - { - /*** Normal entry ***/ - DrawText (150, (j * 20) + ypos, items[i]); - DrawText (400, (j * 20) + ypos, itemvalues[i]); - } - j++; - } - showscreen (); -} - -/**************************************************************************** - * ROM Information Screen - ***************************************************************************/ - -void RomInfo() -{ - clearscreen (); - - int ypos = 65; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - setfontsize (28); - DrawText (-1, 60, (char*)"Rom Information"); - - setfontsize (16); - setfontcolour (0x00, 0x00, 0x00); - - #define MENU_INFO_ROM "ROM" - #define MENU_INFO_ROMID "ROMID" - #define MENU_INFO_COMPANY "Company" - #define MENU_INFO_SIZE "Size" - #define MENU_INFO_SRAM "SRAM" - #define MENU_INFO_TYPE "Type" - #define MENU_INFO_CHECKSUM "Checksum" - #define MENU_INFO_TVTYPE "TV Type" - #define MENU_INFO_FRAMES "Frames" - #define MENU_INFO_CRC32 "CRC32" - - char fmtString[1024]; - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_ROM); - DrawText (300, ypos, Memory.ROMName); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_ROMID); - DrawText (300, ypos, Memory.ROMId); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_COMPANY); - DrawText (300, ypos, Memory.CompanyId); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_SIZE); - sprintf(fmtString, "%d", Memory.ROMSize); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_SRAM); - sprintf(fmtString, "%d", Memory.SRAMSize); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_TYPE); - sprintf(fmtString, "%d", Memory.ROMType); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_CHECKSUM); - sprintf(fmtString, "%04x / %04x", Memory.ROMChecksum, Memory.ROMComplementChecksum); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_TVTYPE); - sprintf(fmtString, "%s", Settings.PAL ? "PAL" : "NTSC"); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_FRAMES); - sprintf(fmtString, "%d", Memory.ROMFramesPerSecond); - DrawText (300, ypos, fmtString); - - ypos += 20; - DrawText (150, ypos, (char *)MENU_INFO_CRC32); - sprintf(fmtString, "%08X", Memory.ROMCRC32); - DrawText (300, ypos, fmtString); - - showscreen (); -} - - -/**************************************************************************** - * DrawLine - * - * Quick'n'Dirty Bresenham line drawing routine. - ***************************************************************************/ -#define SIGN(x) ((x<0)?-1:((x>0)?1:0)) - -void -DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b) -{ - u32 colour, pixel; - u32 colourhi, colourlo; - int i, dx, dy, sdx, sdy, dxabs, dyabs, x, y, px, py; - int sp; - - colour = getcolour (r, g, b); - colourhi = colour & 0xffff0000; - colourlo = colour & 0xffff; - - dx = x2 - x1; /*** Horizontal distance ***/ - dy = y2 - y1; /*** Vertical distance ***/ - - dxabs = abs (dx); - dyabs = abs (dy); - sdx = SIGN (dx); - sdy = SIGN (dy); - x = dyabs >> 1; - y = dxabs >> 1; - px = x1; - py = y1; - - sp = (py * 320) + (px >> 1); - pixel = xfb[whichfb][sp]; - /*** Plot this pixel ***/ - if (px & 1) - xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; - else - xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; - - if (dxabs >= dyabs) /*** Mostly horizontal ***/ - { - for (i = 0; i < dxabs; i++) - { - y += dyabs; - if (y >= dxabs) - { - y -= dxabs; - py += sdy; - } - - px += sdx; - - sp = (py * 320) + (px >> 1); - pixel = xfb[whichfb][sp]; - - if (px & 1) - xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; - else - xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; - } - } - else - { - for (i = 0; i < dyabs; i++) - { - x += dxabs; - if (x >= dyabs) - { - x -= dyabs; - px += sdx; - } - - py += sdy; - - sp = (py * 320) + (px >> 1); - pixel = xfb[whichfb][sp]; - - if (px & 1) - xfb[whichfb][sp] = (pixel & 0xffff0000) | colourlo; - else - xfb[whichfb][sp] = (pixel & 0xffff) | colourhi; - } - } -} - -/**************************************************************************** - * Progress Bar - * - * Show the user what's happening - ***************************************************************************/ -void -ShowProgress (char *msg, int done, int total) -{ - if(total <= 0) // division by 0 is bad! - return; - else if(done > total) // this shouldn't happen - done = total; - - int xpos, ypos; - int i; - - if(done < 5000) // we just started! - { - ypos = (screenheight - 30) >> 1; - - if (screenheight == 480) - ypos += 52; - else - ypos += 32; - - clearscreen (); - setfontsize(20); - DrawText (-1, ypos, msg); - - /*** Draw a white outline box ***/ - for (i = 380; i < 401; i++) - DrawLine (100, i, 540, i, 0xff, 0xff, 0xff); - } - - /*** Show progess ***/ - xpos = (int) (((float) done / (float) total) * 438); - - for (i = 381; i < 400; i++) - DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80); - - if(done < 5000) // we just started! - { - showscreen (); - } -} - -/**************************************************************************** - * DrawPolygon - ***************************************************************************/ -void -DrawPolygon (int vertices, int varray[], u8 r, u8 g, u8 b) -{ - int i; - - for (i = 0; i < vertices - 1; i++) - { - DrawLine (varray[(i << 1)], varray[(i << 1) + 1], varray[(i << 1) + 2], - varray[(i << 1) + 3], r, g, b); - } - - DrawLine (varray[0], varray[1], varray[(vertices << 1) - 2], - varray[(vertices << 1) - 1], r, g, b); -} - -/**************************************************************************** - * Draw Line Fast - * - * This routine requires that start and endx are 32bit aligned. - * It tries to perform a semi-transparency over the existing image. - ***************************************************************************/ - -#define SRCWEIGHT 0.7f -#define DSTWEIGHT (1.0f - SRCWEIGHT) - -static inline u8 c_adjust( u8 c , float weight ) -{ - return (u8)((float)c * weight); -} - -void DrawLineFast( int startx, int endx, int y, u8 r, u8 g, u8 b ) -{ - int width; - u32 offset; - int i; - u32 colour, clo, chi; - u32 lo,hi; - u8 *s, *d; - - //colour = getcolour(r, g, b); - colour = ( r << 16 | g << 8 | b ); - d = (u8 *)&colour; - d[1] = c_adjust(d[1], DSTWEIGHT); - d[2] = c_adjust(d[2], DSTWEIGHT); - d[3] = c_adjust(d[3], DSTWEIGHT); - - width = ( endx - startx ) >> 1; - offset = ( y << 8 ) + ( y << 6 ) + ( startx >> 1 ); - - for ( i = 0; i < width; i++ ) - { - lo = getrgb(xfb[whichfb][offset], 0); - hi = getrgb(xfb[whichfb][offset], 1); - - s = (u8 *)&hi; - s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); - s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); - s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] ); - - s = (u8 *)&lo; - s[1] = ( ( c_adjust(s[1],SRCWEIGHT) ) + d[1] ); - s[2] = ( ( c_adjust(s[2],SRCWEIGHT) ) + d[2] ); - s[3] = ( ( c_adjust(s[3],SRCWEIGHT) ) + d[3] ); - - clo = getcolour( s[1], s[2], s[3] ); - s = (u8 *)&hi; - chi = getcolour( s[1], s[2], s[3] ); - - xfb[whichfb][offset++] = (chi & 0xffff0000 ) | ( clo & 0xffff) ; - } -} - -/**************************************************************************** - * Ok, I'm useless with Y1CBY2CR colour. - * So convert back to RGB so I can work with it -;) - ***************************************************************************/ -u32 getrgb( u32 ycbr, u32 low ) -{ - u8 r,g,b; - u32 y; - s8 cb,cr; - - if ( low ) - y = ( ycbr & 0xff00 ) >> 8; - else - y = ( ycbr & 0xff000000 ) >> 24; - - cr = ycbr & 0xff; - cb = ( ycbr & 0xff0000 ) >> 16; - - cr -= 128; - cb -= 128; - - r = (u8)((float)y + 1.371 * (float)cr); - g = (u8)((float)y - 0.698 * (float)cr - 0.336 * (float)cb); - b = (u8)((float)y + 1.732 * (float)cb); - - return (u32)( r << 16 | g << 8 | b ); - -} diff --git a/source/snes9x/unused/logger.h b/source/ngc/ngc-missing.cpp similarity index 80% rename from source/snes9x/unused/logger.h rename to source/ngc/ngc-missing.cpp index 330f251f..d387d34b 100644 --- a/source/snes9x/unused/logger.h +++ b/source/ngc/ngc-missing.cpp @@ -1,7 +1,20 @@ -/********************************************************************************** +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Port + * softdev July 2006 + * + * ngc_missing.cpp + * + * This file contains the missing low-level file I/O function definitions. + * Note that these are DUMMY functions, and only allow Snes9x to + * compile. Where possible, they will return an error signal. + ****************************************************************************/ + +/**************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +25,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +123,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -156,23 +152,30 @@ Super NES and Super Nintendo Entertainment System are trademarks of Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - -#ifndef LOGGER_H -#define LOGGER_H - -extern int dumpstreams; -extern char autodemo[128]; -extern int maxframes; -extern int logger_pivot; - -int Logger_FrameCounter(); -void Logger_NextFrame(); - -void ResetLogger(); -void VideoLogger(void *pixels, int width, int height, int depth, int bytes_per_row); -void AudioLogger(void *samples, int length); - -#endif +*****************************************************************************/ + +#include +#include +#include +#include + +/*** splitpath function ***/ +void +_splitpath (char const *buffer, char *drive, char *dir, char *fname, + char *ext) +{ + return; /*** Do nothing - NGC code should NEVER call a function which relies on it ***/ +} + +void +_makepath (char *filename, const char *drive, const char *dir, + const char *fname, const char *ext) +{ + return; /*** Do nothing - NGC code should NEVER call a function which relies on it ***/ +} + +char * +S9xBasename (char *name) +{ + return name; +} diff --git a/source/ngc/ngcunzip.cpp b/source/ngc/ngcunzip.cpp new file mode 100644 index 00000000..23089ea4 --- /dev/null +++ b/source/ngc/ngcunzip.cpp @@ -0,0 +1,170 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Unzip - borrowed from the GPP + * + * softdev July 2006 + ****************************************************************************/ +#include +#include +#include +#include +#include +#include "dvd.h" +#include "video.h" +#include "ftfont.h" +#include "ngcunzip.h" + +/* + * PKWare Zip Header - adopted into zip standard + */ +#define PKZIPID 0x504b0304 +#define MAXROM 0x500000 +#define ZIPCHUNK 2048 + +/* + * Zip files are stored little endian + * Support functions for short and int types + */ +u32 +FLIP32 (u32 b) +{ + unsigned int c; + + c = (b & 0xff000000) >> 24; + c |= (b & 0xff0000) >> 8; + c |= (b & 0xff00) << 8; + c |= (b & 0xff) << 24; + + return c; +} + +u16 +FLIP16 (u16 b) +{ + u16 c; + + c = (b & 0xff00) >> 8; + c |= (b & 0xff) << 8; + + return c; +} + +/**************************************************************************** + * IsZipFile + * + * Returns TRUE when PKZIPID is first four characters of buffer + ****************************************************************************/ +int +IsZipFile (char *buffer) +{ + unsigned int *check; + + check = (unsigned int *) buffer; + + if (check[0] == PKZIPID) + return 1; + + return 0; +} + + /***************************************************************************** + * unzip + * + * It should be noted that there is a limit of 5MB total size for any ROM + ******************************************************************************/ +int +UnZipBuffer (unsigned char *outbuffer, u64 discoffset, int length) +{ + PKZIPHEADER pkzip; + int zipoffset = 0; + int zipchunk = 0; + char out[ZIPCHUNK]; + z_stream zs; + int res; + int bufferoffset = 0; + int have = 0; + char readbuffer[2048]; + char msg[128]; + + /*** Read Zip Header ***/ + dvd_read (readbuffer, 2048, discoffset); + + /*** Copy PKZip header to local, used as info ***/ + memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); + + sprintf (msg, "Unzipping %d bytes ... Wait", + FLIP32 (pkzip.uncompressedSize)); + ShowAction (msg); + + /*** Prepare the zip stream ***/ + memset (&zs, 0, sizeof (z_stream)); + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + zs.avail_in = 0; + zs.next_in = Z_NULL; + res = inflateInit2 (&zs, -MAX_WBITS); + + if (res != Z_OK) + return 0; + + /*** Set ZipChunk for first pass ***/ + zipoffset = + (sizeof (PKZIPHEADER) + FLIP16 (pkzip.filenameLength) + + FLIP16 (pkzip.extraDataLength)); + zipchunk = ZIPCHUNK - zipoffset; + + /*** Now do it! ***/ + do + { + zs.avail_in = zipchunk; + zs.next_in = (Bytef *) & readbuffer[zipoffset]; + + /*** Now inflate until input buffer is exhausted ***/ + do + { + zs.avail_out = ZIPCHUNK; + zs.next_out = (Bytef *) & out; + + res = inflate (&zs, Z_NO_FLUSH); + + if (res == Z_MEM_ERROR) + { + inflateEnd (&zs); + return 0; + } + + have = ZIPCHUNK - zs.avail_out; + if (have) + { + /*** Copy to normal block buffer ***/ + memcpy (&outbuffer[bufferoffset], &out, have); + bufferoffset += have; + } + + } + while (zs.avail_out == 0); + + /*** Readup the next 2k block ***/ + zipoffset = 0; + zipchunk = ZIPCHUNK; + discoffset += 2048; + + dvd_read (readbuffer, 2048, discoffset); + } + while (res != Z_STREAM_END); + + inflateEnd (&zs); + + if (res == Z_STREAM_END) + { + if (FLIP32 (pkzip.uncompressedSize) == (u32) bufferoffset) + return bufferoffset; + else + return FLIP32 (pkzip.uncompressedSize); + } + + return 0; + +} diff --git a/source/ngc/ngcunzip.h b/source/ngc/ngcunzip.h new file mode 100644 index 00000000..946c1363 --- /dev/null +++ b/source/ngc/ngcunzip.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Unzip - borrowed from the GPP + * + * softdev July 2006 + ****************************************************************************/ +#ifndef _NGCUNZIP_ +#define _NGCUNZIP_ + +extern int IsZipFile (char *buffer); +int UnZipBuffer (unsigned char *outbuffer, u64 discoffset, int length); +/* + * Zip file header definition + */ +typedef struct +{ + unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50 + unsigned short zipversion __attribute__ ((__packed__)); + unsigned short zipflags __attribute__ ((__packed__)); + unsigned short compressionMethod __attribute__ ((__packed__)); + unsigned short lastmodtime __attribute__ ((__packed__)); + unsigned short lastmoddate __attribute__ ((__packed__)); + unsigned int crc32 __attribute__ ((__packed__)); + unsigned int compressedSize __attribute__ ((__packed__)); + unsigned int uncompressedSize __attribute__ ((__packed__)); + unsigned short filenameLength __attribute__ ((__packed__)); + unsigned short extraDataLength __attribute__ ((__packed__)); +} +PKZIPHEADER; + +u32 FLIP32 (u32 b); +u16 FLIP16 (u16 b); + +#endif diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index b244dbb5..f0fb9f4c 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -1,424 +1,153 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * Tantric September 2008 + * Nintendo Gamecube Port + * crunchy2 April 2007-July 2007 * * preferences.cpp * - * Preferences save/load to XML file - ***************************************************************************/ - + * Preferences save/load preferences utilities + ****************************************************************************/ #include #include #include #include -#include -#include "snes9xGX.h" -#include "images/saveicon.h" -#include "menudraw.h" -#include "memcardop.h" -#include "fileop.h" -#include "smbop.h" -#include "filesel.h" -#include "input.h" +#include "snes9x.h" +#include "snes9xGx.h" +#include "memmap.h" +#include "srtc.h" +#include "ftfont.h" +#include "mcsave.h" +#include "sdload.h" +#include "smbload.h" +extern unsigned char savebuffer[]; extern int currconfig[4]; -#define PREFS_FILE_NAME "SNES9xGX.xml" +// button map configurations +extern unsigned int gcpadmap[]; +extern unsigned int wmpadmap[]; +extern unsigned int ccpadmap[]; +extern unsigned int ncpadmap[]; + +#define PREFSVERSTRING "Snes9x GX 003 Prefs" -char prefscomment[2][32]; +char prefscomment[2][32] = { {PREFSVERSTRING}, {"Preferences"} }; /**************************************************************************** * Prepare Preferences Data * - * This sets up the save buffer for saving. - ***************************************************************************/ -mxml_node_t *xml; -mxml_node_t *data; -mxml_node_t *section; -mxml_node_t *item; -mxml_node_t *elem; - -char temp[20]; - -const char * toStr(int i) -{ - sprintf(temp, "%d", i); - return temp; -} - -void createXMLSection(const char * name, const char * description) -{ - section = mxmlNewElement(data, "section"); - mxmlElementSetAttr(section, "name", name); - mxmlElementSetAttr(section, "description", description); -} - -void createXMLSetting(const char * name, const char * description, const char * value) -{ - item = mxmlNewElement(section, "setting"); - mxmlElementSetAttr(item, "name", name); - mxmlElementSetAttr(item, "value", value); - mxmlElementSetAttr(item, "description", description); -} - -void createXMLController(unsigned int controller[], const char * name, const char * description) -{ - item = mxmlNewElement(section, "controller"); - mxmlElementSetAttr(item, "name", name); - mxmlElementSetAttr(item, "description", description); - - // create buttons - for(int i=0; i < MAXJP; i++) - { - elem = mxmlNewElement(item, "button"); - mxmlElementSetAttr(elem, "number", toStr(i)); - mxmlElementSetAttr(elem, "assignment", toStr(controller[i])); - } -} - -const char * XMLSaveCallback(mxml_node_t *node, int where) -{ - const char *name; - - name = node->value.element.name; - - if(where == MXML_WS_BEFORE_CLOSE) - { - if(!strcmp(name, "file") || !strcmp(name, "section")) - return ("\n"); - else if(!strcmp(name, "controller")) - return ("\n\t"); - } - if (where == MXML_WS_BEFORE_OPEN) - { - if(!strcmp(name, "file")) - return ("\n"); - else if(!strcmp(name, "section")) - return ("\n\n"); - else if(!strcmp(name, "setting") || !strcmp(name, "controller")) - return ("\n\t"); - else if(!strcmp(name, "button")) - return ("\n\t\t"); - } - return (NULL); -} - - + * This sets up the save buffer for saving to a memory card. + ****************************************************************************/ int -preparePrefsData (int method) +preparePrefsData () { - int offset = 0; - - // add save icon and comments for Memory Card saves - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - { - offset = sizeof (saveicon); - - // Copy in save icon - memcpy (savebuffer, saveicon, offset); - - // And the comments - sprintf (prefscomment[0], "%s Prefs", VERSIONSTR); - sprintf (prefscomment[1], "Preferences"); - memcpy (savebuffer + offset, prefscomment, 64); - offset += 64; - } - - xml = mxmlNewXML("1.0"); - mxmlSetWrapMargin(0); // disable line wrapping - - data = mxmlNewElement(xml, "file"); - mxmlElementSetAttr(data, "version",VERSIONSTR); - - createXMLSection("File", "File Settings"); - - createXMLSetting("AutoLoad", "Auto Load", toStr(GCSettings.AutoLoad)); - createXMLSetting("AutoSave", "Auto Save", toStr(GCSettings.AutoSave)); - createXMLSetting("LoadMethod", "Load Method", toStr(GCSettings.LoadMethod)); - createXMLSetting("SaveMethod", "Save Method", toStr(GCSettings.SaveMethod)); - createXMLSetting("LoadFolder", "Load Folder", GCSettings.LoadFolder); - createXMLSetting("SaveFolder", "Save Folder", GCSettings.SaveFolder); - createXMLSetting("CheatFolder", "Cheats Folder", GCSettings.CheatFolder); - createXMLSetting("VerifySaves", "Verify Memory Card Saves", toStr(GCSettings.VerifySaves)); - - createXMLSection("Network", "Network Settings"); - - createXMLSetting("smbip", "Share Computer IP", GCSettings.smbip); - createXMLSetting("smbshare", "Share Name", GCSettings.smbshare); - createXMLSetting("smbuser", "Share Username", GCSettings.smbuser); - createXMLSetting("smbpwd", "Share Password", GCSettings.smbpwd); - - createXMLSection("Emulation", "Emulation Settings"); - - createXMLSetting("ReverseStereo", "Reverse Stereo", toStr(Settings.ReverseStereo)); - createXMLSetting("InterpolatedSound", "Interpolated Sound", toStr(Settings.InterpolatedSound)); - createXMLSetting("Transparency", "Transparency", toStr(Settings.Transparency)); - createXMLSetting("DisplayFrameRate", "Display Frame Rate", toStr(Settings.DisplayFrameRate)); - createXMLSetting("NGCZoom", "C-Stick Zoom", toStr(GCSettings.NGCZoom)); - createXMLSetting("render", "Video Filtering", toStr(GCSettings.render)); - createXMLSetting("widescreen", "Aspect Ratio Correction", toStr(GCSettings.widescreen)); - createXMLSetting("xshift", "Horizontal Video Shift", toStr(GCSettings.xshift)); - createXMLSetting("yshift", "Vertical Video Shift", toStr(GCSettings.yshift)); - - createXMLSection("Controller", "Controller Settings"); - - createXMLSetting("MultiTap", "MultiTap", toStr(Settings.MultiPlayer5Master)); - createXMLSetting("Superscope", "Superscope", toStr(GCSettings.Superscope)); - createXMLSetting("Mice", "Mice", toStr(GCSettings.Mouse)); - createXMLSetting("Justifiers", "Justifiers", toStr(GCSettings.Justifier)); - - createXMLController(gcpadmap, "gcpadmap", "GameCube Pad"); - createXMLController(wmpadmap, "wmpadmap", "Wiimote"); - createXMLController(ccpadmap, "ccpadmap", "Classic Controller"); - createXMLController(ncpadmap, "ncpadmap", "Nunchuk"); - - int datasize = mxmlSaveString(xml, (char *)savebuffer+offset, (SAVEBUFFERSIZE-offset), XMLSaveCallback); - - mxmlDelete(xml); - - return datasize; + int offset = sizeof (saveicon); + int size; + + memset (savebuffer, 0, SAVEBUFFERSIZE); + + /*** Copy in save icon ***/ + memcpy (savebuffer, saveicon, offset); + + /*** And the prefscomments ***/ + memcpy (savebuffer + offset, prefscomment, 64); + offset += 64; + + /*** Save all settings ***/ + size = sizeof (Settings); + memcpy (savebuffer + offset, &Settings, size); + offset += size; + + /*** Save GC specific settings ***/ + size = sizeof (GCSettings); + memcpy (savebuffer + offset, &GCSettings, size); + offset += size; + + /*** Save buttonmaps ***/ + size = sizeof (unsigned int) *12; // this size applies to all padmaps + memcpy (savebuffer + offset, &gcpadmap, size); + offset += size; + memcpy (savebuffer + offset, &wmpadmap, size); + offset += size; + memcpy (savebuffer + offset, &ccpadmap, size); + offset += size; + memcpy (savebuffer + offset, &ncpadmap, size); + offset += size; + + return offset; } /**************************************************************************** - * loadXMLSetting - * - * Load XML elements into variables for an individual variable - ***************************************************************************/ - -void loadXMLSetting(char * var, const char * name) -{ - item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); - if(item) - sprintf(var, "%s", mxmlElementGetAttr(item, "value")); -} -void loadXMLSetting(int * var, const char * name) -{ - item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); - if(item) - *var = atoi(mxmlElementGetAttr(item, "value")); -} -void loadXMLSetting(bool8 * var, const char * name) + * Decode Preferences Data + ****************************************************************************/ +void +decodePrefsData () { - item = mxmlFindElement(xml, xml, "setting", "name", name, MXML_DESCEND); - if(item) - *var = atoi(mxmlElementGetAttr(item, "value")); -} - -/**************************************************************************** - * loadXMLController - * - * Load XML elements into variables for a controller mapping - ***************************************************************************/ - -void loadXMLController(unsigned int controller[], const char * name) -{ - item = mxmlFindElement(xml, xml, "controller", "name", name, MXML_DESCEND); - - if(item) + int offset; + char prefscomment[32]; + int size; + + offset = sizeof (saveicon); + memcpy (prefscomment, savebuffer + offset, 32); + + if ( strcmp (prefscomment, PREFSVERSTRING) == 0 ) { - // populate buttons - for(int i=0; i < MAXJP; i++) - { - elem = mxmlFindElement(item, xml, "button", "number", toStr(i), MXML_DESCEND); - if(elem) - controller[i] = atoi(mxmlElementGetAttr(elem, "assignment")); - } + offset += 64; + memcpy (&Settings, savebuffer + offset, sizeof (Settings)); + offset += sizeof (Settings); + memcpy (&GCSettings, savebuffer + offset, sizeof (GCSettings)); + offset += sizeof (GCSettings); + // load padmaps (order important) + size = sizeof (unsigned int) *12; + memcpy (&gcpadmap, savebuffer + offset, size); + offset += size; + memcpy (&wmpadmap, savebuffer + offset, size); + offset += size; + memcpy (&ccpadmap, savebuffer + offset, size); + offset += size; + memcpy (&ncpadmap, savebuffer + offset, size); } + else + WaitPrompt((char*) "Preferences reset - check settings!"); } -/**************************************************************************** - * decodePrefsData - * - * Decodes preferences - parses XML and loads preferences into the variables - ***************************************************************************/ - -bool -decodePrefsData (int method) +void quickLoadPrefs (bool8 silent) { - int offset = 0; - - // skip save icon and comments for Memory Card saves - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + switch ( QUICK_SAVE_SLOT ) { - offset = sizeof (saveicon); - offset += 64; // sizeof prefscomment + case CARD_SLOTA: + case CARD_SLOTB: + LoadPrefsFromMC(QUICK_SAVE_SLOT, silent); + break; + + case CARD_SLOTA+2: + case CARD_SLOTB+2: + LoadPrefsFromSD(silent); + break; + + case CARD_SLOTA+4: + LoadPrefsFromSMB(silent); + break; } - - xml = mxmlLoadString(NULL, (char *)savebuffer+offset, MXML_TEXT_CALLBACK); - - // check settings version - // we don't do anything with the version #, but we'll store it anyway - char * version; - item = mxmlFindElement(xml, xml, "file", "version", NULL, MXML_DESCEND); - if(item) // a version entry exists - version = (char *)mxmlElementGetAttr(item, "version"); - else // version # not found, must be invalid - return false; - - // File Settings - - loadXMLSetting(&GCSettings.AutoLoad, "AutoLoad"); - loadXMLSetting(&GCSettings.AutoSave, "AutoSave"); - loadXMLSetting(&GCSettings.LoadMethod, "LoadMethod"); - loadXMLSetting(&GCSettings.SaveMethod, "SaveMethod"); - loadXMLSetting(GCSettings.LoadFolder, "LoadFolder"); - loadXMLSetting(GCSettings.SaveFolder, "SaveFolder"); - loadXMLSetting(GCSettings.CheatFolder, "CheatFolder"); - loadXMLSetting(&GCSettings.VerifySaves, "VerifySaves"); - - // Network Settings - - loadXMLSetting(GCSettings.smbip, "smbip"); - loadXMLSetting(GCSettings.smbshare, "smbshare"); - loadXMLSetting(GCSettings.smbuser, "smbuser"); - loadXMLSetting(GCSettings.smbpwd, "smbpwd"); - - // Emulation Settings - - loadXMLSetting(&Settings.ReverseStereo, "ReverseStereo"); - loadXMLSetting(&Settings.InterpolatedSound, "InterpolatedSound"); - loadXMLSetting(&Settings.Transparency, "Transparency"); - loadXMLSetting(&Settings.DisplayFrameRate, "DisplayFrameRate"); - loadXMLSetting(&GCSettings.NGCZoom, "NGCZoom"); - loadXMLSetting(&GCSettings.render, "render"); - loadXMLSetting(&GCSettings.widescreen, "widescreen"); - loadXMLSetting(&GCSettings.xshift, "xshift"); - loadXMLSetting(&GCSettings.yshift, "yshift"); - - // Controller Settings - - loadXMLSetting(&Settings.MultiPlayer5Master, "MultiTap"); - loadXMLSetting(&GCSettings.Superscope, "Superscope"); - loadXMLSetting(&GCSettings.Mouse, "Mice"); - loadXMLSetting(&GCSettings.Justifier, "Justifiers"); - - loadXMLController(gcpadmap, "gcpadmap"); - loadXMLController(wmpadmap, "wmpadmap"); - loadXMLController(ccpadmap, "ccpadmap"); - loadXMLController(ncpadmap, "ncpadmap"); - - mxmlDelete(xml); - - return true; } -/**************************************************************************** - * Save Preferences - ***************************************************************************/ -bool -SavePrefs (int method, bool silent) +void quickSavePrefs (bool8 silent) { - // there's no point in saving SMB settings TO SMB, because then we'll have no way to load them the next time! - // so instead we'll save using whatever other method is available (eg: SD) - if(method == METHOD_AUTO || method == METHOD_SMB) - method = autoSaveMethod(); - - char filepath[1024]; - int datasize; - int offset = 0; - - AllocSaveBuffer (); - datasize = preparePrefsData (method); - - if (!silent) - ShowAction ((char*) "Saving preferences..."); - - if(method == METHOD_SD || method == METHOD_USB) - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); - offset = SaveBufferToFAT (filepath, datasize, silent); - } - } - else if(method == METHOD_SMB) - { - sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME); - offset = SaveBufferToSMB (filepath, datasize, silent); - } - else if(method == METHOD_MC_SLOTA) + switch ( QUICK_SAVE_SLOT ) { - offset = SaveBufferToMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, datasize, silent); + case CARD_SLOTA: + case CARD_SLOTB: + SavePrefsToMC(QUICK_SAVE_SLOT, silent); + break; + case CARD_SLOTA+2: + case CARD_SLOTB+2: + SavePrefsToSD(silent); + break; + case CARD_SLOTA+4: + SavePrefsToSMB(silent); + break; } - else if(method == METHOD_MC_SLOTB) - { - offset = SaveBufferToMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, datasize, silent); - } - - FreeSaveBuffer (); - - if (offset > 0) - { - if (!silent) - WaitPrompt ((char *)"Preferences saved"); - return true; - } - return false; -} - -/**************************************************************************** - * Load Preferences from specified method - ***************************************************************************/ -bool -LoadPrefsFromMethod (int method) -{ - bool retval = false; - char filepath[1024]; - int offset = 0; - - AllocSaveBuffer (); - - if(method == METHOD_SD || method == METHOD_USB) - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME); - offset = LoadBufferFromFAT (filepath, SILENT); - } - } - else if(method == METHOD_SMB) - { - sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME); - offset = LoadBufferFromSMB (filepath, SILENT); - } - else if(method == METHOD_MC_SLOTA) - { - offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, SILENT); - } - else if(method == METHOD_MC_SLOTB) - { - offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, SILENT); - } - - if (offset > 0) - retval = decodePrefsData (method); - - FreeSaveBuffer (); - - return retval; -} - -/**************************************************************************** - * Load Preferences - * Checks sources consecutively until we find a preference file - ***************************************************************************/ -bool LoadPrefs() -{ - ShowAction ((char*) "Loading preferences..."); - bool prefFound = false; - if(ChangeFATInterface(METHOD_SD, SILENT)) - prefFound = LoadPrefsFromMethod(METHOD_SD); - if(!prefFound && ChangeFATInterface(METHOD_USB, SILENT)) - prefFound = LoadPrefsFromMethod(METHOD_USB); - if(!prefFound && TestCard(CARD_SLOTA, SILENT)) - prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTA); - if(!prefFound && TestCard(CARD_SLOTB, SILENT)) - prefFound = LoadPrefsFromMethod(METHOD_MC_SLOTB); - if(!prefFound && ConnectShare (SILENT)) - prefFound = LoadPrefsFromMethod(METHOD_SMB); - - return prefFound; } diff --git a/source/ngc/preferences.h b/source/ngc/preferences.h index ff83c325..75eb511f 100644 --- a/source/ngc/preferences.h +++ b/source/ngc/preferences.h @@ -1,12 +1,18 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * Tantric September 2008 + * Nintendo Gamecube Port + * crunchy2 April 2007 * - * preferences.h + * preferences.cpp * - * Preferences save/load to XML file - ***************************************************************************/ + * Preferences save/load preferences utilities + ****************************************************************************/ -bool SavePrefs (int method, bool silent); -bool LoadPrefs (); +#define PREFS_FILE_NAME "snes9xGx.prf" + +int preparePrefsData (); +void decodePrefsData (); + +void quickLoadPrefs (bool8 silent); +void quickSavePrefs (bool8 silent); diff --git a/source/ngc/s9xconfig.cpp b/source/ngc/s9xconfig.cpp index 6469b2fc..206cb7dd 100644 --- a/source/ngc/s9xconfig.cpp +++ b/source/ngc/s9xconfig.cpp @@ -1,128 +1,239 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 * crunchy2 May 2007 - * Michniewski 2008 - * Tantric September 2008 * * s9xconfig.cpp * - * Configuration parameters are here for easy maintenance. + * Configuration parameters have been moved here for easier maintenance. * Refer to Snes9x.h for all combinations. * The defaults used here are taken directly from porting.html - ***************************************************************************/ + ****************************************************************************/ +/**************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +*****************************************************************************/ #include #include "snes9x.h" #include "snes9xGX.h" -#include "smbop.h" - -struct SGCSettings GCSettings; +#include "smbload.h" void DefaultSettings () { - /************** GameCube/Wii Settings *********************/ - GCSettings.LoadMethod = METHOD_AUTO; // Auto, SD, DVD, USB, Network (SMB) - GCSettings.SaveMethod = METHOD_AUTO; // Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, Network (SMB) - sprintf (GCSettings.LoadFolder,"snes9x/roms"); // Path to game files - sprintf (GCSettings.SaveFolder,"snes9x/saves"); // Path to save files - sprintf (GCSettings.CheatFolder,"snes9x/cheats"); // Path to cheat files - GCSettings.AutoLoad = 1; - GCSettings.AutoSave = 1; - - GCSettings.VerifySaves = 0; - - // custom SMB settings - strncpy (GCSettings.smbip, "", 15); // IP Address of share server - strncpy (GCSettings.smbuser, "", 19); // Your share user - strncpy (GCSettings.smbpwd, "", 19); // Your share user password - strncpy (GCSettings.smbshare, "", 19); // Share name on server - - GCSettings.smbip[15] = 0; - GCSettings.smbuser[19] = 0; - GCSettings.smbpwd[19] = 0; - GCSettings.smbshare[19] = 0; - - GCSettings.gcip[0] = 0; - GCSettings.gwip[0] = 0; - GCSettings.mask[0] = 0; - GCSettings.smbsvid[0] = 0; - GCSettings.smbgcid[0] = 0; - - GCSettings.Superscope = 0; - GCSettings.Mouse = 0; - GCSettings.Justifier = 0; - - GCSettings.NGCZoom = 0; // zooming default off - - GCSettings.render = 2; // Unfiltered - GCSettings.widescreen = 0; // no aspect ratio correction - - GCSettings.xshift = 0; // video shift - GCSettings.yshift = 0; - - /****************** SNES9x Settings ***********************/ - - // Default ALL to false - memset (&Settings, 0, sizeof (Settings)); - - // General - - Settings.MouseMaster = false; - Settings.SuperScopeMaster = false; - Settings.MultiPlayer5Master = false; - Settings.JustifierMaster = false; - Settings.ShutdownMaster = false; - Settings.ApplyCheats = true; - - Settings.BlockInvalidVRAMAccess = true; - Settings.HDMATimingHack = 100; - - // Sound defaults. On GC this is 32Khz/16bit/Stereo/InterpolatedSound - Settings.APUEnabled = true; - Settings.NextAPUEnabled = true; - Settings.SoundPlaybackRate = 32000; - Settings.Stereo = true; - Settings.SixteenBitSound = true; - Settings.SoundEnvelopeHeightReading = true; - Settings.SoundSync = true; - Settings.FixFrequency = false; - Settings.DisableSampleCaching = true; - Settings.InterpolatedSound = true; - Settings.ReverseStereo = false; - - // Graphics - Settings.Transparency = true; - Settings.SupportHiRes = true; - Settings.SkipFrames = AUTO_FRAMERATE; - Settings.TurboSkipFrames = 19; - Settings.DisplayFrameRate = false; - Settings.AutoDisplayMessages = 0; - Settings.InitialInfoStringTimeout = 200; // # frames to display messages for - - // Frame timings in 50hz and 60hz cpu mode - Settings.FrameTimePAL = 20000; - Settings.FrameTimeNTSC = 16667; - - // SDD1 - Star Ocean Returns - Settings.SDD1Pack = true; - - Settings.ForceNTSC = 0; - Settings.ForcePAL = 0; - Settings.ForceHiROM = 0; - Settings.ForceLoROM = 0; - Settings.ForceHeader = 0; - Settings.ForceNoHeader = 0; - Settings.ForceTransparency = 0; - Settings.ForceInterleaved = 0; - Settings.ForceInterleaved2 = 0; - Settings.ForceInterleaveGD24 = 0; - Settings.ForceNotInterleaved = 0; - Settings.ForceNoSuperFX = 0; - Settings.ForceSuperFX = 0; - Settings.ForceDSP1 = 0; - Settings.ForceNoDSP1 = 0; + /*** Default ALL to false ***/ + memset (&Settings, 0, sizeof (Settings)); + + /*** General ***/ + Settings.MouseMaster = true; + Settings.SuperScopeMaster = true; + Settings.MultiPlayer5Master = false; + Settings.JustifierMaster = true; + Settings.ShutdownMaster = false; + Settings.CyclesPercentage = 100; // snes9x 1.50 and earlier + + /* Eke-Eke: specific to snes9x 1.51 */ +// Settings.BlockInvalidVRAMAccess = true; +// Settings.HDMATimingHack = 100; + + /*** Sound defaults. On GC this is 32Khz/16bit/Stereo/InterpolatedSound ***/ + Settings.APUEnabled = true; + Settings.NextAPUEnabled = true; + Settings.SoundPlaybackRate = 32000; + Settings.Stereo = true; + Settings.SixteenBitSound = true; + Settings.SoundEnvelopeHeightReading = true; + Settings.DisableSampleCaching = true; + Settings.InterpolatedSound = true; + Settings.ReverseStereo = false; + + /*** Graphics ***/ + Settings.Transparency = true; + Settings.SupportHiRes = true; + Settings.SkipFrames = 10; + Settings.TurboSkipFrames = 19; + Settings.DisplayFrameRate = false; +// Settings.AutoDisplayMessages = 1; /*** eke-eke snes9x 1.51 ***/ + + /* Eke-Eke: frame timings in 50hz and 60hz cpu mode */ + Settings.FrameTimePAL = 20000; + Settings.FrameTimeNTSC = 16667; + + /*** SDD1 - Star Ocean Returns -;) ***/ + Settings.SDD1Pack = true; + + GCSettings.AutoLoad = 0; + GCSettings.AutoSave = 0; + + strncpy (GCSettings.gcip, GC_IP, 15); + strncpy (GCSettings.gwip, GW_IP, 15); + strncpy (GCSettings.mask, MASK, 15); + strncpy (GCSettings.smbip, SMB_IP, 15); + strncpy (GCSettings.smbuser, SMB_USER, 19); + strncpy (GCSettings.smbpwd, SMB_PWD, 19); + strncpy (GCSettings.smbgcid, SMB_GCID, 19); + strncpy (GCSettings.smbsvid, SMB_SVID, 19); + strncpy (GCSettings.smbshare, SMB_SHARE, 19); + + GCSettings.NGCZoom = 0; + GCSettings.VerifySaves = 0; + + Settings.ForceNTSC = 0; + Settings.ForcePAL = 0; + Settings.ForceHiROM = 0; + Settings.ForceLoROM = 0; + Settings.ForceHeader = 0; + Settings.ForceNoHeader = 0; + Settings.ForceTransparency = 0; + Settings.ForceInterleaved = 0; + Settings.ForceInterleaved2 = 0; + Settings.ForceInterleaveGD24 = 0; + Settings.ForceNotInterleaved = 0; + Settings.ForceNoSuperFX = 0; + Settings.ForceSuperFX = 0; + Settings.ForceDSP1 = 0; + Settings.ForceNoDSP1 = 0; + } diff --git a/source/ngc/s9xconfig.h b/source/ngc/s9xconfig.h index 4502012b..946b7f53 100644 --- a/source/ngc/s9xconfig.h +++ b/source/ngc/s9xconfig.h @@ -1,18 +1,158 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 - * crunchy2 May 2007 - * Michniewski 2008 - * Tantric September 2008 * * s9xconfig.h * - * Configuration parameters are here for easy maintenance. + * Configuration parameters have been moved here for easier maintenance. * Refer to Snes9x.h for all combinations. * The defaults used here are taken directly from porting.html - ***************************************************************************/ + ****************************************************************************/ +/**************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +*****************************************************************************/ #ifndef _S9XCONFIG_ #define _S9XCONFIG_ diff --git a/source/ngc/s9xsupport.cpp b/source/ngc/s9xsupport.cpp index c7cbf5a7..b93a438e 100644 --- a/source/ngc/s9xsupport.cpp +++ b/source/ngc/s9xsupport.cpp @@ -1,17 +1,158 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 * crunchy2 May 2007 - * Michniewski 2008 - * Tantric September 2008 * * s9xsupport.cpp * * This file contains the supporting functions defined in porting.html, with * others taken from unix/x11.cpp and unix/unix.cpp - ***************************************************************************/ + ****************************************************************************/ +/**************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +*****************************************************************************/ #include #include #include @@ -31,8 +172,10 @@ #include "spc700.h" #include "spc7110.h" #include "controls.h" +#include "gctime.h" +#include "snes9xGx.h" + -#include "snes9xGX.h" #include "video.h" #include "audio.h" @@ -41,12 +184,6 @@ extern u32 FrameTimer; long long prev; long long now; -extern "C" { - -long long gettime(); -u32 diff_usec(long long start,long long end); - -} /*** Miscellaneous Functions ***/ void @@ -65,7 +202,7 @@ S9xExit () { /*** Nintendo Gamecube will NEVER get here ... unless something major went wrong !! - + In which case, I'll settle for a reboot first -;) ***/ } @@ -105,7 +242,7 @@ S9xGetFilenameInc (const char *e, enum s9x_getdirtype dirtype) void S9xAutoSaveSRAM () { - + //Memory.SaveSRAM (S9xGetFilename (".srm", SRAM_DIR)); } /*** Sound based functions ***/ @@ -123,7 +260,7 @@ S9xToggleSoundChannel (int c) * OpenSoundDevice * * Main initialisation for NGC sound system - ***************************************************************************/ + ****************************************************************************/ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) { @@ -147,7 +284,7 @@ S9xGenerateSound () /* eke-eke */ void S9xInitSync() -{ +{ FrameTimer = 0; prev = gettime(); } @@ -158,7 +295,7 @@ extern int timerstyle; void S9xSyncSpeed () { uint32 skipFrms = Settings.SkipFrames; - + if ( Settings.TurboMode ) skipFrms = Settings.TurboSkipFrames; @@ -168,10 +305,10 @@ void S9xSyncSpeed () { usleep (50); } - + if (FrameTimer > skipFrms) FrameTimer = skipFrms; - + if ((FrameTimer > 1) && (IPPU.SkippedFrames < skipFrms)) { IPPU.SkippedFrames++; @@ -183,11 +320,11 @@ void S9xSyncSpeed () IPPU.RenderThisFrame = TRUE; } } - else /* use internal timer for PAL roms */ + else /* use internal timer for PAL roms */ { unsigned int timediffallowed = Settings.TurboMode ? 0 : Settings.FrameTime; now = gettime(); - + if (diff_usec(prev, now) > timediffallowed) { /*while ( diff_usec((prev, now) < timediffallowed * 2) { @@ -216,7 +353,7 @@ void S9xSyncSpeed () prev = now; } - + if ( !Settings.TurboMode ) FrameTimer--; return; @@ -295,29 +432,3 @@ S9xLoadSDD1Data () return; } - -/**************************************************************************** - * Note that these are DUMMY functions, and only allow Snes9x to - * compile. Where possible, they will return an error signal. - ***************************************************************************/ - -/*** splitpath function ***/ -void -_splitpath (char const *buffer, char *drive, char *dir, char *fname, - char *ext) -{ - return; /*** Do nothing - NGC code should NEVER call a function which relies on it ***/ -} - -void -_makepath (char *filename, const char *drive, const char *dir, - const char *fname, const char *ext) -{ - return; /*** Do nothing - NGC code should NEVER call a function which relies on it ***/ -} - -char * -S9xBasename (char *name) -{ - return name; -} diff --git a/source/ngc/sdload.cpp b/source/ngc/sdload.cpp new file mode 100644 index 00000000..243af1ff --- /dev/null +++ b/source/ngc/sdload.cpp @@ -0,0 +1,419 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Port + * softdev July 2006 + * crunchy2 May 2007 + * + * sdload.cpp + * + * Load ROMS from SD Card + ****************************************************************************/ +#include +#include +#include +#include +#include "sdload.h" +#include "unzip.h" +#include "memmap.h" +#include "video.h" +#include "ftfont.h" +#include "dvd.h" +#include "filesel.h" +#include "sram.h" +#include "preferences.h" + +#include +extern unsigned char savebuffer[]; +extern char output[16384]; +FILE * filehandle; + +char currSDdir[MAXPATHLEN]; +extern int offset; +extern int selection; + +extern FILEENTRIES filelist[MAXFILES]; + +/*************************************************************************** + * FileSortCallback + * + * Quick sort callback to sort file entries with the following order: + * . + * .. + * + * + ***************************************************************************/ +static int FileSortCallback(const void *f1, const void *f2) +{ + /* Special case for implicit directories */ + if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') + { + if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } + if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } + if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } + if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } + } + + /* If one is a file and one is a directory the directory is first. */ + if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; + if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; + + return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); +} + +/*************************************************************************** + * Update SDCARD curent directory name + ***************************************************************************/ +int updateSDdirname() +{ + int size=0; + char *test; + char temp[1024]; + + /* current directory doesn't change */ + if (strcmp(filelist[selection].filename,".") == 0) return 0; + + /* go up to parent directory */ + else if (strcmp(filelist[selection].filename,"..") == 0) + { + /* determine last subdirectory namelength */ + sprintf(temp,"%s",currSDdir); + test = strtok(temp,"/"); + while (test != NULL) { + size = strlen(test); + test = strtok(NULL,"/"); + } + + /* remove last subdirectory name */ + size = strlen(currSDdir) - size - 1; + currSDdir[size] = 0; + + /* handles root name */ + if (strcmp(currSDdir, "/") == 0) + + + return 1; + } + else /* Open a directory */ + { + /* test new directory namelength */ + if ((strlen(currSDdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) + { + /* handles root name */ + sprintf(temp, "/%s/..", SNESROMDIR); + if (strcmp(currSDdir, temp) == 0) + sprintf(currSDdir,"%s",ROOTSDDIR); + + /* update current directory name */ + sprintf(currSDdir, "%s/%s",currSDdir, filelist[selection].filename); + return 1; + } else { + WaitPrompt((char*)"Dirname is too long !"); + return -1; + } + } +} + +/*************************************************************************** + * Browse SDCARD subdirectories + ***************************************************************************/ +int parseSDdirectory() { + int nbfiles = 0; + DIR_ITER *sddir; + char filename[MAXPATHLEN]; + struct stat filestat; + char msg[128]; + + /* initialize selection */ + selection = offset = 0; + + /* open the directory */ + sddir = diropen(currSDdir); + if (sddir == NULL) { + sprintf(currSDdir,"%s",ROOTSDDIR); // if we can't open the previous dir, open root dir + sddir = diropen(currSDdir); + WaitPrompt(msg); + if (sddir == NULL) { + sprintf(msg, "Error opening %s", currSDdir); + WaitPrompt(msg); + return 0; + } + } + + /* Move to DVD structure - this is required for the file selector */ + while(dirnext(sddir,filename,&filestat) == 0) { + if(strcmp(filename,".") != 0) { + memset(&filelist[nbfiles], 0, sizeof(FILEENTRIES)); + strncpy(filelist[nbfiles].filename, filename, MAXPATHLEN); + strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1); // crop name for display + filelist[nbfiles].length = filestat.st_size; + filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; + nbfiles++; + } + } + + /*** close directory ***/ + dirclose(sddir); + + /* Sort the file list */ + qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); + + return nbfiles; +} + +/**************************************************************************** + * LoadSDFile + ****************************************************************************/ +extern int haveSDdir; +int +LoadSDFile (char *filename, int length) +{ + char zipbuffer[2048]; + char filepath[MAXPATHLEN]; + FILE *handle; + unsigned char *rbuffer; + u32 size; + + rbuffer = (unsigned char *) Memory.ROM; + + /* Check filename length */ + if ((strlen(currSDdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN) + sprintf(filepath, "%s/%s",currSDdir,filelist[selection].filename); + else + { + WaitPrompt((char*) "Maximum Filename Length reached !"); + haveSDdir = 0; // reset everything before next access + return -1; + } + + handle = fopen (filepath, "rb"); + if (handle > 0) + { + fread (zipbuffer, 1, 2048, handle); + + if (IsZipFile (zipbuffer)) + { + /*** Unzip the ROM ***/ + size = UnZipBuffer (rbuffer, 0, 0, handle); // unzip from SD + + fclose (handle); + return size; + + } + else + { + /*** Just load the file up ***/ + + fseek(handle, 0, SEEK_END); + length = ftell(handle); // get filesize + fseek(handle, 2048, SEEK_SET); // seek back to point where we left off + + sprintf (filepath, "Loading %d bytes", length); + ShowAction (filepath); + memcpy (rbuffer, zipbuffer, 2048); // copy what we already read + fread (rbuffer + 2048, 1, length - 2048, handle); + fclose (handle); + + return length; + } + } + else + { + WaitPrompt((char*) "Error opening file"); + return 0; + } + + return 0; +} + + + +/**************************************************************************** + * Load savebuffer from SD card file + ****************************************************************************/ +int +LoadBufferFromSD (char *filepath, bool silent) +{ + FILE *handle; + int offset = 0; + int read = 0; + + handle = fopen (filepath, "rb"); + + if (handle <= 0) + { + if ( !silent ) + { + char msg[100]; + sprintf(msg, "Couldn't open %s", filepath); + WaitPrompt (msg); + } + return 0; + } + + memset (savebuffer, 0, 0x22000); + + /*** This is really nice, just load the file and decode it ***/ + while ((read = fread (savebuffer + offset, 1, 1024, handle)) > 0) + { + offset += read; + } + + fclose (handle); + + return offset; +} + + +/**************************************************************************** + * Write savebuffer to SD card file + ****************************************************************************/ +int +SaveBufferToSD (char *filepath, int datasize, bool silent) +{ + FILE *handle; + + if (datasize) + { + handle = fopen (filepath, "wb"); + + if (handle <= 0) + { + char msg[100]; + sprintf(msg, "Couldn't save %s", filepath); + WaitPrompt (msg); + return 0; + } + + fwrite (savebuffer, 1, datasize, handle); + fclose (handle); + } + + return datasize; +} + + +/**************************************************************************** + * Save SRAM to SD Card + ****************************************************************************/ +void SaveSRAMToSD (bool silent) +{ + char filepath[1024]; + int datasize; + int offset; + + if (!silent) + ShowAction ((char*) "Saving SRAM to SD..."); + +#ifdef SDUSE_LFN + sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMName); +#else + sprintf (filepath, "%s/%s/%08x.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); +#endif + + datasize = prepareEXPORTsavedata (); + + if ( datasize ) + { + offset = SaveBufferToSD (filepath, datasize, silent); + + if ( (offset > 0) && (!silent) ) + { + sprintf (filepath, "Wrote %d bytes", offset); + WaitPrompt (filepath); + } + } +} + + +/**************************************************************************** + * Load SRAM From SD Card + ****************************************************************************/ +void +LoadSRAMFromSD (bool silent) +{ + char filepath[1024]; + int offset = 0; + + ShowAction ((char*) "Loading SRAM from SD..."); + +#ifdef SDUSE_LFN + sprintf (filepath, "%s/%s/%s.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMName); +#else + sprintf (filepath, "%s/%s/%08x.srm", ROOTSDDIR, SNESSAVEDIR, Memory.ROMCRC32); +#endif + + offset = LoadBufferFromSD (filepath, silent); + + if (offset > 0) + { + decodesavedata (offset); + if ( !silent ) + { + sprintf (filepath, "Loaded %d bytes", offset); + WaitPrompt(filepath); + } + S9xSoftReset(); + } +} + + +/**************************************************************************** + * Save Preferences to SD Card + ****************************************************************************/ +void +SavePrefsToSD (bool silent) +{ + char filepath[1024]; + int datasize; + int offset; + + if (!silent) + ShowAction ((char*) "Saving prefs to SD..."); + +#ifdef SDUSE_LFN + sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME); +#else + sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME); +#endif + + datasize = preparePrefsData (); + offset = SaveBufferToSD (filepath, datasize, silent); + + if ( (offset > 0) && (!silent) ) + { + sprintf (filepath, "Wrote %d bytes", offset); + WaitPrompt (filepath); + } +} + + +/**************************************************************************** + * Load Preferences from SD Card + ****************************************************************************/ +void +LoadPrefsFromSD (bool silent) +{ + char filepath[1024]; + int offset = 0; + + ShowAction ((char*) "Loading prefs from SD..."); + +#ifdef SDUSE_LFN + sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME); +#else + sprintf (filepath, "%s/%s/%s", ROOTSDDIR, SNESSAVEDIR, PREFS_FILE_NAME); +#endif + + offset = LoadBufferFromSD (filepath, silent); + + if (offset > 0) + { + decodePrefsData (); + if ( !silent ) + { + sprintf (filepath, "Loaded %d bytes", offset); + WaitPrompt(filepath); + } + } +} diff --git a/source/ngc/sdload.h b/source/ngc/sdload.h new file mode 100644 index 00000000..28b236de --- /dev/null +++ b/source/ngc/sdload.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Port + * softdev July 2006 + * crunchy2 May 2007 + * + * sdload.cpp + * + * Load ROMS from SD Card + ****************************************************************************/ + +#ifndef _LOADFROMSDC_ +#define _LOADFROMSDC_ +#include +#include +#include +#include +#include +#include +#include +#include + +static int FileSortCallback(const void *f1, const void *f2); +int updateSDdirname(); +int parseSDdirectory(); +int LoadSDFile (char *filename, int length); +void SaveSRAMToSD (bool silent); +void LoadSRAMFromSD (bool silent); +void SavePrefsToSD (bool silent); +void LoadPrefsFromSD (bool silent); + +extern char currSDdir[MAXPATHLEN]; + +#endif diff --git a/source/ngc/smbload.cpp b/source/ngc/smbload.cpp new file mode 100644 index 00000000..1fd55d8b --- /dev/null +++ b/source/ngc/smbload.cpp @@ -0,0 +1,484 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Port + * softdev July 2006 + * crunchy2 May 2007 + * + * smbload.cpp + * + * Load ROMS from a Network share. + ****************************************************************************/ +#include +#include +#include +#include +#include +extern "C" +{ +#include "smb.h" +} +#include "unzip.h" +#include "memmap.h" +#include "video.h" +#include "ftfont.h" +#include "dvd.h" +#include "filesel.h" +#include "sram.h" +#include "preferences.h" +#include "smbload.h" +#include "Snes9xGx.h" +#include + +static int connected = 0; +static int netinited = 0; + +char output[16384]; +unsigned int SMBTimer = 0; +extern unsigned char savebuffer[]; + +#define ZIPCHUNK 16384 +#define SMBTIMEOUT ( 3600 ) /*** Some implementations timeout in 10 minutes ***/ +SMBINFO smbinfo = + { GC_IP, GW_IP, MASK, SMB_IP, + SMB_USER, SMB_PWD, SMB_GCID, SMB_SVID, SMB_SHARE +}; + +extern FILEENTRIES filelist[MAXFILES]; + +/**************************************************************************** + * Mount SMB Share + ****************************************************************************/ +void +ConnectSMB () +{ + int ret; + + if (SMBTimer > SMBTIMEOUT) + { + connected = 0; + SMBTimer = 0; + } + + if (connected == 0) + { + + if (netinited == 0) + { + ShowAction ((char*) "Setting up network interface ..."); + ret = if_config (smbinfo.gcip, smbinfo.gwip, smbinfo.mask, 0); + netinited = 1; + } + + ShowAction ((char*) "Connecting to share ..."); + SMB_Destroy (); + + if (SMB_Init (smbinfo.smbuser, smbinfo.smbpwd, + smbinfo.smbgcid, smbinfo.smbsvid, smbinfo.smbshare, + smbinfo.smbip) != SMB_SUCCESS) + { + WaitPrompt((char*) "Failed to connect to SMB share"); + connected = 0; + return; + } + } + + connected = 1; + +} + +/**************************************************************************** + * parseSMBDirectory + * + * Load the share directory and put in the filelist array + *****************************************************************************/ +int +parseSMBDirectory () +{ + char searchpath[1024]; + int filecount = 0; + SMBDIRENTRY smbdir; + + ConnectSMB (); + + strcpy (searchpath, SNESROMDIR); + strcat (searchpath, "\\*.*"); + + if (SMB_FindFirst + (searchpath, SMB_SRCH_READONLY | SMB_SRCH_SYSTEM | SMB_SRCH_HIDDEN, + &smbdir) != SMB_SUCCESS) + { + return 0; + } + + do + { + memset (&filelist[filecount], 0, sizeof (FILEENTRIES)); + filelist[filecount].length = smbdir.size_low; + smbdir.name[MAXJOLIET] = 0; + + /*** Update display name ***/ + memcpy (&filelist[filecount].displayname, smbdir.name, MAXDISPLAY); + filelist[filecount].displayname[MAXDISPLAY] = 0; + + strcpy (filelist[filecount].filename, smbdir.name); + filecount++; + + } + while (SMB_FindNext (&smbdir) == SMB_SUCCESS); + + SMB_FindClose (); + + return filecount; +} + +/**************************************************************************** + * Load SMB file + ****************************************************************************/ +int +LoadSMBFile (char *filename, int length) +{ + char buffer[128]; + int offset = 0; + int bytesread = 0; + int total = 0; + char filepath[1024]; + SMBFILE smbfile; + char *rbuffer; + char zipbuffer[16384]; + int pass = 0; + int zip = 0; + PKZIPHEADER pkzip; + z_stream zs; + int res, outbytes; + + strcpy (filepath, SNESROMDIR); + strcat (filepath, "\\"); + strcat (filepath, filename); + rbuffer = (char *) Memory.ROM; + outbytes = 0; + int have = 0; + + ConnectSMB (); + + if ( connected ) + { + + /*** Open the file for reading ***/ + smbfile = + SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); + if (smbfile) + { + while (total < length) + { + bytesread = SMB_Read (zipbuffer, 16384, offset, smbfile); + + if (pass == 0) + { + /*** Is this a Zip file ? ***/ + zip = IsZipFile (zipbuffer); + if (zip) + { + memcpy (&pkzip, zipbuffer, sizeof (PKZIPHEADER)); + pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); + memset (&zs, 0, sizeof (zs)); + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + zs.avail_in = 0; + zs.next_in = Z_NULL; + res = inflateInit2 (&zs, -MAX_WBITS); + + if (res != Z_OK) + { + SMB_Close (smbfile); + return 0; + } + + zs.avail_in = + 16384 - (sizeof (PKZIPHEADER) + + FLIP16 (pkzip.filenameLength) + + FLIP16 (pkzip.extraDataLength)); + zs.next_in = + (Bytef *) zipbuffer + (sizeof (PKZIPHEADER) + + FLIP16 (pkzip.filenameLength) + + FLIP16 (pkzip.extraDataLength)); + } + } + + if (zip) + { + if (pass) + { + zs.avail_in = bytesread; + zs.next_in = (Bytef *) zipbuffer; + } + + do + { + zs.avail_out = ZIPCHUNK; + zs.next_out = (Bytef *) output; + + res = inflate (&zs, Z_NO_FLUSH); + + have = ZIPCHUNK - zs.avail_out; + + if (have) + { + memcpy (rbuffer + outbytes, output, have); + outbytes += have; + } + } + while (zs.avail_out == 0); + } + else + memcpy (rbuffer + offset, zipbuffer, bytesread); + + total += bytesread; + offset += bytesread; + + if (!zip) + { + sprintf (buffer, "Read %d of %d bytes", total, length); + ShowProgress (buffer, total, length); + } + else + { + sprintf (buffer, "Unzipped %d of %d", outbytes, + pkzip.uncompressedSize); + ShowProgress (buffer, outbytes, pkzip.uncompressedSize); + } + //ShowAction (buffer); + + pass++; + + } + + if (zip) + { + inflateEnd (&zs); + total = outbytes; + } + + SMB_Close (smbfile); + + return total; + } + else + { + WaitPrompt((char*) "SMB Reading Failed!"); + //while (1); + return 0; + } + } + + return 0; +} + + +/**************************************************************************** + * Write savebuffer to SMB file + ****************************************************************************/ +int +SaveBufferToSMB (char *filepath, int datasize, bool8 silent) +{ + SMBFILE smbfile; + int dsize = datasize; + int wrote = 0; + int offset = 0; + + ConnectSMB (); + + if ( connected ) + { + smbfile = + SMB_Open (filepath, SMB_OPEN_WRITING | SMB_DENY_NONE, + SMB_OF_CREATE | SMB_OF_TRUNCATE); + + if (smbfile) + { + while (dsize > 0) + { + if (dsize > 1024) + wrote = + SMB_Write ((char *) savebuffer + offset, 1024, offset, smbfile); + else + wrote = + SMB_Write ((char *) savebuffer + offset, dsize, offset, smbfile); + + offset += wrote; + dsize -= wrote; + } + + SMB_Close (smbfile); + SMBTimer = 0; + + return offset; + } + else + { + char msg[100]; + sprintf(msg, "Couldn't save SMB:%s", filepath); + WaitPrompt (msg); + } + } + + return 0; +} + + +/**************************************************************************** + * Load savebuffer from SMB file + ****************************************************************************/ +int +LoadBufferFromSMB (char *filepath, bool8 silent) +{ + SMBFILE smbfile; + int ret; + int offset = 0; + + ConnectSMB (); + + if ( connected ) + { + smbfile = + SMB_Open (filepath, SMB_OPEN_READING | SMB_DENY_NONE, SMB_OF_OPEN); + + if (!smbfile) + { + if (!silent) + { + char msg[100]; + sprintf(msg, "Couldn't open SMB:%s", filepath); + WaitPrompt (msg); + } + return 0; + } + + memset (savebuffer, 0, 0x22000); + + while ((ret = + SMB_Read ((char *) savebuffer + offset, 1024, offset, + smbfile)) > 0) + offset += ret; + + SMB_Close (smbfile); + + return offset; + } + + return 0; +} + + +/**************************************************************************** + * Save SRAM to SMB + ****************************************************************************/ +void +SaveSRAMToSMB (bool8 silent) +{ + char filepath[1024]; + int datasize; + int offset; + + sprintf (filepath, "%s\\%s.srm", SNESSAVEDIR, Memory.ROMName); + + if (!silent) + ShowAction ((char*) "Saving SRAM to SMB..."); + + datasize = prepareEXPORTsavedata (); + + if ( datasize ) + { + offset = SaveBufferToSMB (filepath, datasize, silent); + + if ( (offset > 0) && (!silent) ) + { + sprintf (filepath, "Wrote %d bytes", offset); + WaitPrompt (filepath); + } + } +} + +/**************************************************************************** + * Load SRAM from SMB + ****************************************************************************/ +void +LoadSRAMFromSMB (bool8 silent) +{ + char filepath[1024]; + int offset; + + sprintf (filepath, "%s\\%s.srm", SNESSAVEDIR, Memory.ROMName); + ShowAction ((char*) "Loading SRAM from SMB..."); + + offset = LoadBufferFromSMB (filepath, silent); + + if (offset > 0) + { + decodesavedata (offset); + if ( !silent ) + { + sprintf (filepath, "Loaded %d bytes", offset); + WaitPrompt(filepath); + } + S9xSoftReset(); + } +} + + +/**************************************************************************** + * Save Preferences to SMB + ****************************************************************************/ +void +SavePrefsToSMB (bool8 silent) +{ + char filepath[1024]; + int datasize; + int offset; + + sprintf (filepath, "%s\\%s", SNESSAVEDIR, PREFS_FILE_NAME); + + if (!silent) + ShowAction ((char*) "Saving preferences to SMB..."); + + datasize = preparePrefsData (); + + if ( datasize ) + { + offset = SaveBufferToSMB (filepath, datasize, silent); + + if ( (offset > 0) && (!silent) ) + { + sprintf (filepath, "Wrote %d bytes", offset); + WaitPrompt (filepath); + } + } +} + + +/**************************************************************************** + * Load Preferences from SMB + ****************************************************************************/ +void +LoadPrefsFromSMB (bool8 silent) +{ + char filepath[1024]; + int offset; + + ShowAction ((char*) "Loading preferences from SMB..."); + + sprintf (filepath, "%s\\%s", SNESSAVEDIR, PREFS_FILE_NAME); + + offset = LoadBufferFromSMB (filepath, silent); + + if (offset > 0) + { + decodePrefsData (); + if ( !silent ) + { + sprintf (filepath, "Loaded %d bytes", offset); + WaitPrompt(filepath); + } + } +} diff --git a/source/ngc/smbload.h b/source/ngc/smbload.h new file mode 100644 index 00000000..c4f1ebaa --- /dev/null +++ b/source/ngc/smbload.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * Snes9x 1.50 + * + * Nintendo Gamecube Port + * softdev July 2006 + * crunchy2 May 2007 + * + * smbload.cpp + * + * Load ROMS from a Network share. + ****************************************************************************/ + +#ifndef _NGCSMB_ + +#define _NGCSMB_ + +void ConnectSMB (); +int parseSMBDirectory (); +int LoadSMBFile (char *filename, int length); +void SaveSRAMToSMB (bool8 silent); +void LoadSRAMFromSMB (bool8 silent); +void SavePrefsToSMB (bool8 silent); +void LoadPrefsFromSMB (bool8 silent); + +typedef struct +{ + char gcip[16]; + char gwip[16]; + char mask[16]; + char smbip[16]; + char smbuser[20]; + char smbpwd[20]; + char smbgcid[20]; + char smbsvid[20]; + char smbshare[20]; +} +SMBINFO; + + +#endif diff --git a/source/ngc/smbop.cpp b/source/ngc/smbop.cpp deleted file mode 100644 index cb3b47a6..00000000 --- a/source/ngc/smbop.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007 - * Tantric August 2008 - * - * smbload.cpp - * - * SMB support routines - ****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "memmap.h" - -#include "smbop.h" -#include "unzip.h" -#include "video.h" -#include "menudraw.h" -#include "filesel.h" -#include "snes9xGX.h" - -bool networkInit = false; -bool networkShareInit = false; -unsigned int SMBTimer = 0; -#define SMBTIMEOUT ( 3600 ) // Some implementations timeout in 10 minutes - -// SMB connection/file handles - the only ones we should ever use! -SMBCONN smbconn; -SMBFILE smbfile; - -#define ZIPCHUNK 16384 - -/**************************************************************************** - * InitializeNetwork - * Initializes the Wii/GameCube network interface - ****************************************************************************/ - -bool InitializeNetwork(bool silent) -{ - ShowAction ((char*) "Initializing network..."); - s32 result; - - while ((result = net_init()) == -EAGAIN); - - if (result >= 0) - { - char myIP[16]; - - if (if_config(myIP, NULL, NULL, true) < 0) - { - if(!silent) - WaitPrompt((char*) "Error reading IP address."); - return false; - } - else - { - return true; - } - } - - if(!silent) - WaitPrompt((char*) "Unable to initialize network."); - return false; -} - -/**************************************************************************** - * Mount SMB Share - ****************************************************************************/ - -bool -ConnectShare (bool silent) -{ - // Crashes or stalls system in GameCube mode - so disable - #ifndef HW_RVL - return false; - #endif - - // check that all parameter have been set - if(strlen(GCSettings.smbuser) == 0 || - strlen(GCSettings.smbpwd) == 0 || - strlen(GCSettings.smbshare) == 0 || - strlen(GCSettings.smbip) == 0) - { - if(!silent) - WaitPrompt((char*) "Invalid network settings. Check SNES9xGX.xml."); - return false; - } - - if(!networkInit) - networkInit = InitializeNetwork(silent); - - if(networkInit) - { - // connection may have expired - if (networkShareInit && SMBTimer > SMBTIMEOUT) - { - networkShareInit = false; - SMBTimer = 0; - SMB_Close(smbconn); - } - - if(!networkShareInit) - { - if(!silent) - ShowAction ((char*) "Connecting to network share..."); - - if(SMB_Connect(&smbconn, GCSettings.smbuser, GCSettings.smbpwd, - GCSettings.smbgcid, GCSettings.smbsvid, GCSettings.smbshare, GCSettings.smbip) == SMB_SUCCESS) - networkShareInit = true; - } - - if(!networkShareInit && !silent) - WaitPrompt ((char*) "Failed to connect to network share."); - } - - return networkShareInit; -} - -/**************************************************************************** - * SMBPath - * - * Returns a SMB-style path - *****************************************************************************/ - -char * SMBPath(char * path) -{ - // fix path - replace all '/' with '\' - for(uint i=0; i < strlen(path); i++) - if(path[i] == '/') - path[i] = '\\'; - - return path; -} - -/**************************************************************************** - * parseSMBDirectory - * - * Load the directory and put in the filelist array - *****************************************************************************/ -int -ParseSMBdirectory () -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int filecount = 0; - char searchpath[1024]; - SMBDIRENTRY smbdir; - - // initialize selection - selection = offset = 0; - - // Clear any existing values - memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); - - if(strlen(currentdir) <= 1) // root - sprintf(searchpath, "*"); - else - sprintf(searchpath, "%s/*", currentdir); - - if (SMB_FindFirst - (SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS) - { - char msg[200]; - sprintf(msg, "Could not open %s", currentdir); - WaitPrompt (msg); - - // if we can't open the dir, open root dir - sprintf(searchpath, "/"); - sprintf(searchpath,"*"); - - if (SMB_FindFirst - (SMBPath(searchpath), SMB_SRCH_READONLY | SMB_SRCH_DIRECTORY, &smbdir, smbconn) != SMB_SUCCESS) - return 0; - } - - // index files/folders - do - { - if(strcmp(smbdir.name,".") != 0 && - !(strlen(currentdir) <= 1 && strcmp(smbdir.name,"..") == 0)) - { - memset (&filelist[filecount], 0, sizeof (FILEENTRIES)); - filelist[filecount].length = smbdir.size_low; - smbdir.name[MAXJOLIET] = 0; - - if(smbdir.attributes == SMB_SRCH_DIRECTORY) - filelist[filecount].flags = 1; // flag this as a dir - else - filelist[filecount].flags = 0; - - // Update display name - memcpy (&filelist[filecount].displayname, smbdir.name, MAXDISPLAY); - filelist[filecount].displayname[MAXDISPLAY] = 0; - - strcpy (filelist[filecount].filename, smbdir.name); - filecount++; - } - } while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS); - - // close directory - SMB_FindClose (smbconn); - - // Sort the file list - qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); - - return filecount; -} - -/**************************************************************************** - * Open SMB file - ***************************************************************************/ - -SMBFILE OpenSMBFile(char * filepath) -{ - return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn); -} - -/**************************************************************************** - * Load SMB file - * rom - pointer to memory where ROM will be stored - * length - # bytes to read (0 for all) - ****************************************************************************/ -int -LoadSMBFile (char * rom, int length) -{ - char filepath[MAXPATHLEN]; - - /* Check filename length */ - if (!MakeROMPath(filepath, METHOD_SMB)) - { - WaitPrompt((char*) "Maximum filepath length reached!"); - return -1; - } - return LoadBufferFromSMB(rom, filepath, length, NOTSILENT); -} - -/**************************************************************************** - * LoadSMBSzFile - * Loads the selected file # from the specified 7z into rbuffer - * Returns file size - ***************************************************************************/ -int -LoadSMBSzFile(char * filepath, unsigned char * rbuffer) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - smbfile = OpenSMBFile(filepath); - - if (smbfile) - { - u32 size = SzExtractFile(filelist[selection].offset, rbuffer); - SMB_CloseFile (smbfile); - return size; - } - else - { - WaitPrompt((char*) "Error opening file"); - return 0; - } -} - -/**************************************************************************** - * Write savebuffer to SMB file - ****************************************************************************/ -// no buffer specified, use savebuffer -int -SaveBufferToSMB (char *filepath, int datasize, bool silent) -{ - return SaveBufferToSMB((char *)savebuffer, filepath, datasize, silent); -} - -int -SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int dsize = datasize; - int wrote = 0; - int boffset = 0; - - smbfile = - SMB_OpenFile (SMBPath(filepath), SMB_OPEN_WRITING | SMB_DENY_NONE, - SMB_OF_CREATE | SMB_OF_TRUNCATE, smbconn); - - if (smbfile) - { - while (dsize > 0) - { - if (dsize > 1024) - wrote = - SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile); - else - wrote = - SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile); - - boffset += wrote; - dsize -= wrote; - } - SMB_CloseFile (smbfile); - } - else - { - char msg[100]; - sprintf(msg, "Couldn't save SMB: %s", SMBPath(filepath)); - WaitPrompt (msg); - } - - return boffset; -} - -/**************************************************************************** - * Load up a buffer from SMB file - ****************************************************************************/ - -// no buffer is specified - so use savebuffer -int -LoadBufferFromSMB (char *filepath, bool silent) -{ - return LoadBufferFromSMB((char *)savebuffer, filepath, 0, silent); -} - -int -LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent) -{ - if(!ConnectShare (NOTSILENT)) - return 0; - - int ret; - int boffset = 0; - - smbfile = OpenSMBFile(filepath); - - if (!smbfile) - { - if(!silent) - { - char msg[100]; - sprintf(msg, "Couldn't open SMB: %s", SMBPath(filepath)); - WaitPrompt (msg); - } - return 0; - } - - if(length > 0 && length <= 2048) // do a partial read (eg: to check file header) - { - boffset = SMB_ReadFile (sbuffer, length, 0, smbfile); - } - else // load whole file - { - ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile); - - if (IsZipFile (sbuffer)) - { - boffset = UnZipBuffer ((unsigned char *)sbuffer, METHOD_SMB); // unzip from SMB - } - else - { - // Just load the file up - while ((ret = SMB_ReadFile (sbuffer + boffset, 2048, boffset, smbfile)) > 0) - { - boffset += ret; - ShowProgress ((char *)"Loading...", boffset, length); - } - } - } - SMB_CloseFile (smbfile); - - return boffset; -} diff --git a/source/ngc/smbop.h b/source/ngc/smbop.h deleted file mode 100644 index d876a65e..00000000 --- a/source/ngc/smbop.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port - * - * softdev July 2006 - * crunchy2 May 2007 - * Tantric August 2008 - * - * smbload.h - * - * SMB support routines - ****************************************************************************/ - -#ifndef _NGCSMB_ - -#define _NGCSMB_ - -#include - -bool InitializeNetwork(bool silent); -bool ConnectShare (bool silent); -char * SMBPath(char * path); -int UpdateSMBdirname(); -int ParseSMBdirectory (); -SMBFILE OpenSMBFile(char * filepath); -int LoadSMBFile (char * fbuffer, int length); -int LoadSMBSzFile(char * filepath, unsigned char * rbuffer); -int LoadBufferFromSMB (char *filepath, bool silent); -int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent); -int SaveBufferToSMB (char *filepath, int datasize, bool silent); -int SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent); - -extern SMBFILE smbfile; - -#endif diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index fcadc393..d3ee5ad2 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -1,16 +1,157 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 * crunchy2 May 2007-July 2007 - * Michniewski 2008 - * Tantric September 2008 * * snes9xGX.cpp * * This file controls overall program flow. Most things start and end here! - ***************************************************************************/ + ****************************************************************************/ +/**************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +*****************************************************************************/ #include #include #include @@ -18,17 +159,11 @@ #include #include +#include #include #include #include #include -#include - -#ifdef WII_DVD -extern "C" { -#include -} -#endif #include "snes9x.h" #include "memmap.h" @@ -44,46 +179,238 @@ extern "C" { #include "controls.h" #include "snes9xGX.h" -#include "aram.h" #include "dvd.h" -#include "smbop.h" #include "video.h" -#include "menudraw.h" +#include "ftfont.h" #include "s9xconfig.h" #include "audio.h" #include "menu.h" #include "sram.h" -#include "freeze.h" +#include "memfile.h" #include "preferences.h" +#include "gctime.h" #include "button_mapping.h" -#include "fileop.h" -#include "input.h" - -#include "gui.h" +unsigned long ARAM_ROMSIZE = 0; int ConfigRequested = 0; -FILE* debughandle; - extern int FrameTimer; extern long long prev; extern unsigned int timediffallowed; -extern void fat_enable_readahead_all(); +/**************************************************************************** + * Controller Functions + * + * The following map the NGC Pads to the *NEW* controller system. + ****************************************************************************/ +#define ASSIGN_BUTTON_TRUE( keycode, snescmd ) \ + S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), true) + +#define ASSIGN_BUTTON_FALSE( keycode, snescmd ) \ + S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), false) + +#define MAXJP 12 +int padcal = 50; +/*** Gamecube controller Padmap ***/ +unsigned int gcpadmap[] = { PAD_BUTTON_A, PAD_BUTTON_B, + PAD_BUTTON_X, PAD_BUTTON_Y, + PAD_TRIGGER_L, PAD_TRIGGER_R, + PAD_TRIGGER_Z, PAD_BUTTON_START, + PAD_BUTTON_UP, PAD_BUTTON_DOWN, + PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT +}; +/*** Wiimote Padmap ***/ +unsigned int wmpadmap[] = { WPAD_BUTTON_B, WPAD_BUTTON_2, + WPAD_BUTTON_1, WPAD_BUTTON_A, + 0x0000, 0x0000, + WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS, + WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, + WPAD_BUTTON_UP, WPAD_BUTTON_DOWN +}; +/*** Classic Controller Padmap ***/ +unsigned int ccpadmap[] = { WPAD_CLASSIC_BUTTON_A, WPAD_CLASSIC_BUTTON_B, + WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_Y, + WPAD_CLASSIC_BUTTON_FULL_L, WPAD_CLASSIC_BUTTON_FULL_R, + WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS, + WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, + WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT +}; +/*** Nunchuk + wiimote Padmap ***/ +unsigned int ncpadmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B, + WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z, + WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS, + WPAD_BUTTON_2, WPAD_BUTTON_1, + WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, + WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT +}; + +#if 0 +/**************************************************************************** + * decodepad + * Called per pad with offset + ****************************************************************************/ +void +decodepadold (int pad) +{ + int i, offset; + signed char x, y; + unsigned short jp; + + /*** Do analogue updates ***/ + x = PAD_StickX (pad); + y = PAD_StickY (pad); + jp = PAD_ButtonsHeld (pad); + + /*** Recalc left / right ***/ + if (x < -padcal) + jp |= PAD_BUTTON_LEFT; + if (x > padcal) + jp |= PAD_BUTTON_RIGHT; + + /*** Recalc up / down ***/ + if (y > padcal) + jp |= PAD_BUTTON_UP; + if (y < -padcal) + jp |= PAD_BUTTON_DOWN; + + /*** Fix offset to pad ***/ + offset = ((pad + 1) << 4); + + for (i = 0; i < MAXJP; i++) + { + if (jp & gcpadmap[i]) + S9xReportButton (offset + i, true); + else + S9xReportButton (offset + i, false); + } +} +#endif +/**************************************************************************** + * This is the joypad algorithm submitted by Krullo. + ****************************************************************************/ +void +decodepad (int pad) +{ + int i, offset; + signed char x, y; + //unsigned short jp, wp; // + u32 jp, wp; + float t; + float mag = 0; + u16 ang = 0; + u32 exp_type; + + /*** Do analogue updates ***/ + x = PAD_StickX (pad); + y = PAD_StickY (pad); + jp = PAD_ButtonsHeld (pad); +#ifdef HW_RVL + exp_type = wpad_get_analogues(pad, &mag, &ang); // get joystick info from wii expansions + wp = WPAD_ButtonsHeld (pad); // wiimote +#else + wp = 0; +#endif + + /*** + Gamecube Joystick input + ***/ + // Is XY inside the "zone"? + if (x * x + y * y > padcal * padcal) + { + /*** we don't want division by ZERO ***/ + if (x > 0 && y == 0) + jp |= PAD_BUTTON_RIGHT; + if (x < 0 && y == 0) + jp |= PAD_BUTTON_LEFT; + if (x == 0 && y > 0) + jp |= PAD_BUTTON_UP; + if (x == 0 && y < 0) + jp |= PAD_BUTTON_DOWN; + + if (x != 0 && y != 0) + { + + /*** Recalc left / right ***/ + t = (float) y / x; + if (t >= -2.41421356237 && t < 2.41421356237) + { + if (x >= 0) + jp |= PAD_BUTTON_RIGHT; + else + jp |= PAD_BUTTON_LEFT; + } + + /*** Recalc up / down ***/ + t = (float) x / y; + if (t >= -2.41421356237 && t < 2.41421356237) + { + if (y >= 0) + jp |= PAD_BUTTON_UP; + else + jp |= PAD_BUTTON_DOWN; + } + } + } +#ifdef HW_RVL + /*** + Wii Joystick (classic, nunchuk) input + ***/ + if (exp_type == WPAD_EXP_NUNCHUK) + { + if ( mag>JOY_THRESHOLD && (ang>300 || ang<50) ) + wp |= WPAD_BUTTON_UP; + if ( mag>JOY_THRESHOLD && (ang>130 && ang<230) ) + wp |= WPAD_BUTTON_DOWN; + if ( mag>JOY_THRESHOLD && (ang>220 && ang<320) ) + wp |= WPAD_BUTTON_LEFT; + if ( mag>JOY_THRESHOLD && (ang>40 && ang<140) ) + wp |= WPAD_BUTTON_RIGHT; + } else if (exp_type == WPAD_EXP_CLASSIC) + { + if ( mag>JOY_THRESHOLD && (ang>300 || ang<50) ) + wp |= WPAD_CLASSIC_BUTTON_UP; + if ( mag>JOY_THRESHOLD && (ang>130 && ang<230) ) + wp |= WPAD_CLASSIC_BUTTON_DOWN; + if ( mag>JOY_THRESHOLD && (ang>220 && ang<320) ) + wp |= WPAD_CLASSIC_BUTTON_LEFT; + if ( mag>JOY_THRESHOLD && (ang>40 && ang<140) ) + wp |= WPAD_CLASSIC_BUTTON_RIGHT; + } +#endif + + /*** Fix offset to pad ***/ + offset = ((pad + 1) << 4); + + for (i = 0; i < MAXJP; i++) + { + /*** Report pressed buttons ***/ + if ( (jp & gcpadmap[i]) // gamecube controller +#ifdef HW_RVL + || ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) ) // wiimote + || ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) ) // classic controller + || ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) ) // nunchuk + wiimote +#endif + ) + S9xReportButton (offset + i, true); + else + S9xReportButton (offset + i, false); + } + +} /**************************************************************************** * setFrameTimerMethod() - * change frametimer method depending on whether ROM is NTSC or PAL - ***************************************************************************/ + * change frametimer method depending on whether ROM is NTSC or PAL + ****************************************************************************/ extern u8 vmode_60hz; int timerstyle; void setFrameTimerMethod() { /* - Set frametimer method - (timerstyle: 0=NTSC vblank, 1=PAL int timer) + Set frametimer method + (timerstyle: 0=NTSC vblank, 1=PAL int timer) */ if ( Settings.PAL ) { if(vmode_60hz == 1) @@ -100,87 +427,224 @@ void setFrameTimerMethod() } return; } +/**************************************************************************** + * NGCReportButtons + * Called on each rendered frame + ****************************************************************************/ +void +NGCReportButtons () +{ + s8 gc_px = PAD_SubStickX (0); + s8 gc_py = PAD_SubStickY (0); + u16 gc_pb = PAD_ButtonsHeld (0); +#ifdef HW_RVL + u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote +#endif + + /*** Check for video zoom ***/ + if (GCSettings.NGCZoom) + { + if (gc_py < -18 || gc_py > 18) + zoom ((float) gc_py / -18); + } + + Settings.TurboMode = (gc_px > 70); + + /*** Check for menu: + CStick left + OR "L+R+X+Y" (eg. Hombrew/Adapted SNES controllers) + OR "Home" on the wiimote or classic controller ***/ + + if ((gc_px < -70) || + ((gc_pb & PAD_TRIGGER_L) && + (gc_pb & PAD_TRIGGER_R ) && + (gc_pb & PAD_BUTTON_X) && + (gc_pb & PAD_BUTTON_Y )) +#ifdef HW_RVL + || (wm_pb & WPAD_BUTTON_HOME) + || (wm_pb & WPAD_CLASSIC_BUTTON_HOME) +#endif + ) + { + ConfigRequested = 1; + + VIDEO_WaitVSync (); + + if ( GCSettings.AutoSave == 1 ) + { + //if ( WaitPromptChoice ((char*)"Save SRAM?", (char*)"Don't Save", (char*)"Save") ) + quickSaveSRAM ( SILENT ); + } + else if ( GCSettings.AutoSave == 2 ) + { + if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") ) + quickSaveFreeze ( SILENT ); + } + else if ( GCSettings.AutoSave == 3 ) + { + if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") ) + { + quickSaveSRAM ( SILENT ); + quickSaveFreeze ( SILENT ); + } + } + + mainmenu (); + FrameTimer = 0; + ConfigRequested = 0; + + setFrameTimerMethod(); // set frametimer method every time a ROM is loaded + + // auto load freeze/sram? + + } + else + { + int j = (Settings.MultiPlayer5Master == true ? 4 : 2); + for (int i = 0; i < j; i++) + decodepad (i); + } +} + +/**************************************************************************** + * wpad_get_analogues() + * + * gets the analogue stick magnitude and angle values ( + * from classic or nunchuk expansions) + ****************************************************************************/ +u32 wpad_get_analogues(int pad, float* mag, u16* ang) +{ + *mag = *ang = 0; + u32 exp_type = 0; +#ifdef HW_RVL + struct expansion_t exp; + memset( &exp, 0, sizeof(exp) ); + + if ( WPAD_Probe( pad, &exp_type) == 0) // check wiimote and expansion status (first if wiimote is connected & no errors) + { + WPAD_Expansion(pad, &exp); // expansion connected. get info + if (exp_type == WPAD_EXP_CLASSIC) + { + *ang = exp.classic.ljs.ang; // left cc joystick + *mag = exp.classic.ljs.mag; + } + else if (exp_type == WPAD_EXP_NUNCHUK) + { + *ang = exp.nunchuk.js.ang; // nunchuk joystick + *mag = exp.nunchuk.js.mag; + } + } +#endif + return exp_type; // return expansion type +} + + +/**************************************************************************** + * Set the default mapping for NGC + ****************************************************************************/ +void +SetDefaultButtonMap () +{ + int maxcode = 0x10; + s9xcommand_t cmd; + + /*** Joypad 1 ***/ + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 A"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 B"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 X"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Y"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 L"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 R"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Select"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Start"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Up"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Down"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Left"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Right"); + + maxcode = 0x20; + /*** Joypad 2 ***/ + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 A"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 B"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 X"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Y"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 L"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 R"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Select"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Start"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Up"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Down"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Left"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Right"); + + maxcode = 0x30; + /*** Joypad 3 ***/ + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 A"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 B"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 X"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Y"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 L"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 R"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Select"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Start"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Up"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Down"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Left"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Right"); + + maxcode = 0x40; + /*** Joypad 4 ***/ + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 A"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 B"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 X"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Y"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 L"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 R"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Select"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Start"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Up"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Down"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Left"); + ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Right"); + + if (Settings.MultiPlayer5Master == false) + { + /*** Plugin 2 Joypads by default ***/ + S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); + S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0); + } + else + { + S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0); + S9xSetController (1, CTL_MP5, 1, 2, 3, -1); + } + +} /**************************************************************************** * Emulation loop - ***************************************************************************/ + * + * The 'clock' timer is long gone. + * System now only uses vbl as hardware clock, so force PAL50 if you need 50hz + ****************************************************************************/ +/* Eke-Eke: initialize frame Sync */ extern void S9xInitSync(); -bool CheckVideo = 0; // for forcing video reset in video.cpp -extern uint32 prevRenderedFrameCount; void emulate () { + S9xSetSoundMute (TRUE); AudioStart (); - S9xInitSync(); // Eke-Eke: initialize frame Sync + S9xInitSync(); - setFrameTimerMethod(); // set frametimer method every time a ROM is loaded + setFrameTimerMethod(); // also called in NGCReportButtons() while (1) { - S9xMainLoop (); - NGCReportButtons (); - - if (ConfigRequested) - { - // change to menu video mode - ResetVideo_Menu (); - - if ( GCSettings.AutoSave == 1 ) - { - SaveSRAM ( GCSettings.SaveMethod, SILENT ); - } - else if ( GCSettings.AutoSave == 2 ) - { - if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") ) - NGCFreezeGame ( GCSettings.SaveMethod, SILENT ); - } - else if ( GCSettings.AutoSave == 3 ) - { - if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") ) - { - SaveSRAM(GCSettings.SaveMethod, SILENT ); - NGCFreezeGame ( GCSettings.SaveMethod, SILENT ); - } - } - - // GUI Stuff - /* - gui_alloc(); - gui_makebg (); - gui_clearscreen(); - gui_draw (); - gui_showscreen (); - //gui_savescreen (); - */ - - MainMenu (2); // go to game menu - - FrameTimer = 0; - setFrameTimerMethod (); // set frametimer method every time a ROM is loaded - - Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false); - Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false); - Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false); - SetControllers (); - //S9xReportControllers (); - - ConfigRequested = 0; - - #ifdef _DEBUG_VIDEO - // log stuff - fprintf(debughandle, "\n\nPlaying ROM: %s", Memory.ROMFilename); - fprintf(debughandle, "\nrender: %u", GCSettings.render); - #endif - - CheckVideo = 1; // force video update - prevRenderedFrameCount = IPPU.RenderedFramesCount; - - - }//if ConfigRequested - - }//while + S9xMainLoop (); + NGCReportButtons (); + } } /**************************************************************************** @@ -196,138 +660,118 @@ emulate () * 7. Initialise Snes9x/GC Sound System * 8. Initialise Snes9x Graphics subsystem * 9. Let's Party! - ***************************************************************************/ + * + * NB: The SNES ROM is now delivered from ARAM. (AR_SNESROM) + * Any method of loading a ROM, RAM, DVD, SMB, SDCard, + * MUST place the unpacked ROM at this location. + * This provides a single consistent interface in memmap.cpp. + * Refer to that file if you need to change it. + ****************************************************************************/ int main () { -#ifdef WII_DVD - DI_Init(); // first + unsigned int save_flags; + + /*** Initialise GC ***/ + InitGCVideo (); /*** Get the ball rolling ***/ + + /*** Initialize libFAT and SD cards ***/ + fatInitDefault(); + //sdio_Startup(); // wii front sd + //sdgecko_initIODefault(); // sd gecko + + + /*** Initialize DVD subsystem ***/ + DVD_Init (); + +#ifdef FORCE_WII + isWii = TRUE; +#else + int drvid = dvd_driveid (); + if ( drvid == 4 || drvid == 6 || drvid == 8 ) + isWii = FALSE; + else + isWii = TRUE; #endif - int selectedMenu = -1; - - // Initialise video - InitGCVideo (); - - // Controllers #ifdef HW_RVL WPAD_Init(); - // read wiimote accelerometer and IR data - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL,640,480); #endif - PAD_Init (); - - // Audio - AUDIO_Init (NULL); - - // GC Audio RAM (for ROM and backdrop storage) - AR_Init (NULL, 0); - - // GameCube only - Injected ROM - // Before going any further, let's copy any injected ROM image - // We'll put it in ARAM for safe storage - - #ifdef HW_DOL - int *romptr = (int *) 0x81000000; // location of injected rom - - if (memcmp ((char *) romptr, "SNESROM0", 8) == 0) - { - SNESROMSize = romptr[2]; - - if(SNESROMSize > (1024*128) && SNESROMSize < (1024*1024*8)) - { - romptr = (int *) 0x81000020; - ARAMPut ((char *) romptr, (char *) AR_SNESROM, SNESROMSize); - } - else // not a valid ROM size - { - SNESROMSize = 0; - } - } - #endif - - // Initialise freetype font system + + /*** Initialise freetype ***/ if (FT_Init ()) { printf ("Cannot initialise font subsystem!\n"); while (1); } - - unpackbackdrop (); - - // Set defaults + setfontsize (16);/***sets the font size.***/ + + /*** Set defaults ***/ DefaultSettings (); - + S9xUnmapAllControls (); SetDefaultButtonMap (); - - // Allocate SNES Memory + + printf ("Initialise Memory\n"); + /*** Allocate SNES Memory ***/ if (!Memory.Init ()) while (1); - - // Allocate APU + + printf ("Initialise APU\n"); + /*** Allocate APU ***/ if (!S9xInitAPU ()) while (1); - - // Set Pixel Renderer to match 565 + + /*** Set Pixel Renderer to match 565 ***/ S9xSetRenderPixelFormat (RGB565); - - // Initialise Snes Sound System + + /*** Initialise Snes Sound System ***/ S9xInitSound (5, TRUE, 1024); - - // Initialise Graphics + + printf ("Initialise GFX\n"); + /*** Initialise Graphics ***/ setGFX (); if (!S9xGraphicsInit ()) while (1); - - // Initialize libFAT for SD and USB - fatInit (8, false); - - #ifdef _DEBUG_VIDEO - // log stuff - debughandle = fopen ("log.txt", "wb"); - #endif - - // Initialize DVD subsystem (GameCube only) - #ifndef HW_RVL - DVD_Init (); - #endif - - // Check if DVD drive belongs to a Wii - SetDVDDriveType(); - + + legal (); + WaitButtonA (); + // Load preferences - if(!LoadPrefs()) - { - WaitPrompt((char*) "Preferences reset - check settings!"); - selectedMenu = 1; // change to preferences menu - } - - // GameCube only - Injected ROM - // Everything's been initialized, we can copy our ROM back - // from ARAM into main memory - - #ifdef HW_DOL - if(SNESROMSize > 0) + quickLoadPrefs(SILENT); + + // Correct any relevant saved settings that are invalid + Settings.FrameTimeNTSC = 16667; + Settings.FrameTimePAL = 20000; + if ( Settings.TurboSkipFrames <= Settings.SkipFrames ) + Settings.TurboSkipFrames = 20; + + /*** No appended ROM, so get the user to load one ***/ + if (ARAM_ROMSIZE == 0) { - ARAMFetchSlow( (char *)Memory.ROM, (char *)AR_SNESROM, SNESROMSize); - Memory.LoadROM ("BLANK.SMC"); - Memory.LoadSRAM ("BLANK"); + while (ARAM_ROMSIZE == 0) + { + mainmenu (); + } } - #endif - - // Get the user to load a ROM - while (SNESROMSize <= 0) + else { - MainMenu (selectedMenu); + /*** Load ROM ***/ + save_flags = CPU.Flags; + if (!Memory.LoadROM ("VIRTUAL.ROM")) + while (1); + CPU.Flags = save_flags; + + /*** Load SRAM ***/ + Memory.LoadSRAM ("DVD"); } - - // Emulate + + /*** Emulate ***/ emulate (); - - // NO! - We're never leaving here! + + /*** NO! - We're never leaving here ! ***/ while (1); - return 0; + return 0; + } diff --git a/source/ngc/snes9xGX.h b/source/ngc/snes9xGX.h index 799386cf..828c6dd4 100644 --- a/source/ngc/snes9xGX.h +++ b/source/ngc/snes9xGX.h @@ -1,15 +1,157 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * softdev July 2006 * crunchy2 May 2007-July 2007 - * Michniewski 2008 - * Tantric September 2008 * - * snes9xGX.h + * snes9xGX.cpp * * This file controls overall program flow. Most things start and end here! - ***************************************************************************/ + ****************************************************************************/ + +/**************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and + zones (kasumitokoduck@yahoo.com) + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x filter + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Specific ports contains the works of other authors. See headers in + individual files. + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +*****************************************************************************/ #ifndef _SNES9XGX_H_ #define _SNES9XGX_H_ @@ -17,50 +159,79 @@ #include #include "snes9x.h" -#define VERSIONNUM "006" -#define VERSIONSTR "Snes9x GX 006" +// FIX: these are unused, but could be... must also change "freezecomment", PREFSVERSTRING, and "sramcomment" +//#define GCVERSION "002" +//#define GCVERSIONSTRING "Snes9x 1.5 v002" #define NOTSILENT 0 #define SILENT 1 -enum { - METHOD_AUTO, - METHOD_SD, - METHOD_USB, - METHOD_DVD, - METHOD_SMB, - METHOD_MC_SLOTA, - METHOD_MC_SLOTB -}; - struct SGCSettings{ - int AutoLoad; - int AutoSave; - int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB) - int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, SMB - char LoadFolder[200]; // Path to game files - char SaveFolder[200]; // Path to save files - char CheatFolder[200]; // Path to cheat files - char gcip[16]; - char gwip[16]; - char mask[16]; - char smbip[16]; - char smbuser[20]; - char smbpwd[20]; - char smbgcid[20]; - char smbsvid[20]; - char smbshare[20]; - int NGCZoom; // 0 - off, 1 - on - int VerifySaves; - int render; // 0 - original, 1 - filtered, 2 - unfiltered - int Superscope; - int Mouse; - int Justifier; - int widescreen; // 0 - 4:3 aspect, 1 - 16:9 aspect - int xshift; // video output shift - int yshift; + uint8 AutoLoad; + uint8 AutoSave; + char gcip[16]; + char gwip[16]; + char mask[16]; + char smbip[16]; + char smbuser[20]; + char smbpwd[20]; + char smbgcid[20]; + char smbsvid[20]; + char smbshare[20]; + bool8 NGCZoom; + uint8 VerifySaves; }; +START_EXTERN_C extern struct SGCSettings GCSettings; +extern unsigned short saveicon[1024]; +extern bool8 isWii; + +extern u32 wpad_get_analogues(int pad, float* mag, u16* ang); +END_EXTERN_C + +#define JOY_THRESHOLD 0.70 // for wii (expansion) analogues #endif + +/*** QUICK_SAVE_SLOT defines where preferences are loaded and saved, and also + where SRAM and Freezes are auto loaded or saved if enabled: + + -1 Disabled - no prefs are loaded + 0 Memory card in slot A + 1 Memory card in slot B + 2 SD card in slot A + 3 SD card in slot B + 4 SMB share ***/ +#ifndef QUICK_SAVE_SLOT +#define QUICK_SAVE_SLOT 2 // save to SD +#endif + +/*** default SMB settings ***/ +#ifndef GC_IP +#define GC_IP "192.168.1.32" /*** IP to assign the GameCube ***/ +#endif +#ifndef GW_IP +#define GW_IP "192.168.1.100" /*** Your gateway IP ***/ +#endif +#ifndef MASK +#define MASK "255.255.255.0" /*** Your subnet mask ***/ +#endif +#ifndef SMB_USER +#define SMB_USER "Guest" /*** Your share user ***/ +#endif +#ifndef SMB_PWD +#define SMB_PWD "password" /*** Your share user password ***/ +#endif +#ifndef SMB_GCID +#define SMB_GCID "gamecube" /*** Machine Name of GameCube ***/ +#endif +#ifndef SMB_SVID +#define SMB_SVID "mypc" /*** Machine Name of Server(Share) ***/ +#endif +#ifndef SMB_SHARE +#define SMB_SHARE "gcshare" /*** Share name on server ***/ +#endif +#ifndef SMB_IP +#define SMB_IP "192.168.1.100" /*** IP Address of share server ***/ +#endif diff --git a/source/ngc/sram.cpp b/source/ngc/sram.cpp index a8925be7..38137030 100644 --- a/source/ngc/sram.cpp +++ b/source/ngc/sram.cpp @@ -1,262 +1,271 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * + * Nintendo Gamecube Port * crunchy2 April 2007-July 2007 - * Michniewski 2008 - * Tantric September 2008 * * sram.cpp * * SRAM save/load/import/export handling - ***************************************************************************/ - + ****************************************************************************/ #include #include #include #include #include "snes9x.h" +#include "snes9xGx.h" #include "memmap.h" #include "srtc.h" +#include "ftfont.h" +#include "mcsave.h" +#include "sdload.h" +#include "smbload.h" -#include "snes9xGX.h" -#include "images/saveicon.h" -#include "menudraw.h" -#include "memcardop.h" -#include "fileop.h" -#include "smbop.h" -#include "filesel.h" - +extern unsigned char savebuffer[]; +//extern int currconfig[4]; extern int padcal; extern unsigned short gcpadmap[]; +//extern unsigned short padmap[4]; -char sramcomment[2][32]; +char sramcomment[2][32] = { {"Snes9x GX 003 SRAM"}, {"Savegame"} }; /**************************************************************************** - * Prepare SRAM Save Data + * Prepare Memory Card SRAM Save Data * - * This sets up the savebuffer for saving in a format compatible with - * snes9x on other platforms. - ***************************************************************************/ + * This sets up the save buffer for saving to a memory card. + ****************************************************************************/ int -preparesavedata (int method) +prepareMCsavedata () { - int offset = 0; - int size; - - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - { - // Copy in save icon - memcpy (savebuffer, saveicon, sizeof(saveicon)); - offset += sizeof (saveicon); - } - - // Copy in the sramcomments - sprintf (sramcomment[0], "%s SRAM", VERSIONSTR); - sprintf (sramcomment[1], Memory.ROMName); - memcpy (savebuffer + offset, sramcomment, 64); - offset += 64; - - if(method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB) - { - // make it a 512 byte header so it is compatible with other platforms - if (offset <= 512) - offset = 512; - // header was longer than 512 bytes - hopefully this never happens! - else - return 0; - } + int offset = sizeof (saveicon); + int size; + + ClearSaveBuffer (); + + /*** Copy in save icon ***/ + memcpy (savebuffer, saveicon, offset); + + /*** And the sramcomments ***/ + sprintf (sramcomment[1], "%s", Memory.ROMName); + memcpy (savebuffer + offset, sramcomment, 64); + offset += 64; + + /*** Copy SRAM size ***/ + size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; + + if (size > 0x20000) + size = 0x20000; + + memcpy (savebuffer + offset, &size, 4); + offset += 4; + + /*** Copy SRAM ***/ + if (size != 0) + { + memcpy (savebuffer + offset, Memory.SRAM, size); + offset += size; + } + +// /*** Save Joypad Configuration ***/ +// memcpy (savebuffer + offset, &currconfig, 16); + offset += 16; +// memcpy (savebuffer + offset, &padcal, 4); + offset += 4; + + return offset; +} - // Copy in the SRAM +/**************************************************************************** + * Prepare Exportable SRAM Save Data + * + * This sets up the save buffer for saving in a format compatible with + * snes9x on other platforms. This is used when saving to SD or SMB. + ****************************************************************************/ +int +prepareEXPORTsavedata () +{ + int offset = 0; + int size; + + ClearSaveBuffer (); + + /*** Copy in the sramcomments ***/ + sprintf (sramcomment[1], "%s", Memory.ROMName); + memcpy (savebuffer + offset, sramcomment, 64); + offset += 64; + +// /*** Save Joypad Configuration ***/ +// memcpy (savebuffer + offset, &currconfig, 16); + offset += 16; +// memcpy (savebuffer + offset, &padcal, 4); + offset += 4; + + if ( offset <= 512 ) + { + // make it a 512 byte header so it is compatible with other platforms + offset = 512; + + /*** Copy in the SRAM ***/ size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; - + if (size > 0x20000) - size = 0x20000; - + size = 0x20000; + if (size != 0) { - memcpy (savebuffer + offset, Memory.SRAM, size); - offset += size; - } - else - { - offset = 0; + memcpy (savebuffer + offset, Memory.SRAM, size); + offset += size; } - + return offset; + } + else + { + // header was longer than 512 bytes - hopefully this never happens! + return 0; + } } /**************************************************************************** * Decode Save Data - ***************************************************************************/ + ****************************************************************************/ void -decodesavedata (int method, int readsize) +decodesavedata (int readsize) { - int offset = 0; - char sramsavecomment[32]; - - int size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; - + int offset; + int size; + char sramcomment[32]; + + // Check for exportable format sram - it has the sram comment at the start + memcpy (sramcomment, savebuffer, 32); + + if ( (strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0) || (strncmp (sramcomment, "Snes9x GX 00", 12) == 0) ) // version 2.0.XX or 00x + { + offset = 64; + + // Get the control pad configuration +// memcpy (&currconfig, savebuffer + offset, 16); + offset += 16; +// memcpy (&padcal, savebuffer + offset, 4); + offset += 4; + +// for (size = 0; size < 4; size++) +// gcpadmap[size] = padmap[currconfig[size]]; + + // move to start of SRAM which is after the 512 byte header + offset = 512; + + // import the SRAM + size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; + if (size > 0x20000) - size = 0x20000; - - // memory card save - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - offset = sizeof (saveicon); // skip save icon - - // Check for sram comment - memcpy (sramsavecomment, savebuffer+offset, 32); - - // version 0xx found! - if ( (strncmp (sramsavecomment, "Snes9x GX 0", 11) == 0) ) + size = 0x20000; + + memcpy (Memory.SRAM, savebuffer + offset, size); + offset += size; + } + else + { + // else, check for a v2.0 memory card format save + offset = sizeof (saveicon); + memcpy (sramcomment, savebuffer + offset, 32); + + if ( strncmp (sramcomment, "Snes9x GX 2.0", 13) == 0 ) { - // adjust offset - if(method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB) - offset = 512; // skip entire 512 byte header - else - offset += 64; // skip savecomments - - // import the SRAM - memcpy (Memory.SRAM, savebuffer + offset, size); + //WaitPrompt((char*) "Memory Card format save"); + offset += 64; + memcpy (&size, savebuffer + offset, 4); + offset += 4; + memcpy (Memory.SRAM, savebuffer + offset, size); + offset += size; + + // If it is an old 2.0 format save, skip over the Settings as we + // don't save them in SRAM now + if ( strcmp (sramcomment, "Snes9x GX 2.0") == 0 ) + offset += sizeof (Settings); + + // Get the control pad configuration +// memcpy (&currconfig, savebuffer + offset, 16); + offset += 16; +// memcpy (&padcal, savebuffer + offset, 4); + offset += 4; + +// for (size = 0; size < 4; size++) +// gcpadmap[size] = padmap[currconfig[size]]; + } + else if ( strncmp (sramcomment, "Snes9x 1.43 SRAM (GX", 20) == 0) + { + // it's an older SnesGx memory card format save + size = Memory.SRAMSize ? ( 1 << (Memory.SRAMSize + 3)) * 128 : 0; + + // import the SRAM + if ( size ) + memcpy(&Memory.SRAM[0], &savebuffer[sizeof(saveicon)+68], size); + + // Ignore the settings saved in the file + + // NOTE: need to add import of joypad config?? Nah. } - // check for SRAM from other version/platform of snes9x - else if ( readsize == size || readsize == size + SRTC_SRAM_PAD) + else { + // else, check for SRAM from other version/platform of snes9x + size = Memory.SRAMSize ? (1 << (Memory.SRAMSize + 3)) * 128 : 0; + + if ( readsize == size || readsize == size + SRTC_SRAM_PAD) + { + //WaitPrompt("readsize=size or + SRTC_SRAM_PAD"); // SRAM data should be at the start of the file, just import it and // ignore anything after the SRAM memcpy (Memory.SRAM, savebuffer, size); - } - else if ( readsize == size + 512 ) - { + } + else if ( readsize == size + 512 ) + { + //WaitPrompt("readsize=size+512"); // SRAM has a 512 byte header - remove it, then import the SRAM, // ignoring anything after the SRAM - memcpy(Memory.SRAM, savebuffer+512, size); - } - else - { - WaitPrompt((char*)"Incompatible SRAM save!"); + memmove (savebuffer, savebuffer + 512, size); + memcpy (Memory.SRAM, savebuffer, size); + } + else + WaitPrompt((char*)"Incompatible SRAM save!"); } + } } -/**************************************************************************** - * Load SRAM - ***************************************************************************/ -int -LoadSRAM (int method, bool silent) +void quickLoadSRAM (bool8 silent) { - ShowAction ((char*) "Loading..."); - - if(method == METHOD_AUTO) - method = autoSaveMethod(); // we use 'Save' because SRAM needs R/W - - char filepath[1024]; - int offset = 0; - - AllocSaveBuffer(); - - if(method == METHOD_SD || method == METHOD_USB) - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); - offset = LoadBufferFromFAT (filepath, silent); - } - } - else if(method == METHOD_SMB) - { - sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename); - offset = LoadBufferFromSMB (filepath, silent); - } - else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - { - sprintf (filepath, "%s.srm", Memory.ROMName); - - if(method == METHOD_MC_SLOTA) - offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent); - else - offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent); - } - - if (offset > 0) - { - decodesavedata (method, offset); - S9xSoftReset(); - } - - FreeSaveBuffer (); - - if(offset > 0) - { - return 1; - } - else - { - // if we reached here, nothing was done! - if(!silent) - WaitPrompt ((char*) "SRAM file not found"); - - return 0; - } + switch ( QUICK_SAVE_SLOT ) + { + case CARD_SLOTA: + case CARD_SLOTB: + LoadSRAMFromMC(QUICK_SAVE_SLOT, silent); + break; + case CARD_SLOTA+2: + case CARD_SLOTB+2: + LoadSRAMFromSD(silent); + break; + case CARD_SLOTA+4: + LoadSRAMFromSMB(SILENT); + break; + } } -/**************************************************************************** - * Save SRAM - ***************************************************************************/ -bool -SaveSRAM (int method, bool silent) +void quickSaveSRAM (bool8 silent) { - ShowAction ((char*) "Saving..."); - - if(method == METHOD_AUTO) - method = autoSaveMethod(); - - bool retval = false; - char filepath[1024]; - int datasize; - int offset = 0; - - AllocSaveBuffer (); - - datasize = preparesavedata (method); - - if ( datasize ) - { - if(method == METHOD_SD || method == METHOD_USB) - { - if(ChangeFATInterface(method, NOTSILENT)) - { - sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename); - offset = SaveBufferToFAT (filepath, datasize, silent); - } - } - else if(method == METHOD_SMB) - { - sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename); - offset = SaveBufferToSMB (filepath, datasize, silent); - } - else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - { - sprintf (filepath, "%s.srm", Memory.ROMName); - - if(method == METHOD_MC_SLOTA) - offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent); - else - offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent); - } - - if (offset > 0) - { - if ( !silent ) - WaitPrompt((char *)"Save successful"); - retval = true; - } - } - else - { - if(!silent) - WaitPrompt((char *)"No SRAM data to save!"); - } - - FreeSaveBuffer (); - return retval; + switch ( QUICK_SAVE_SLOT ) + { + case CARD_SLOTA: + case CARD_SLOTB: + SaveSRAMToMC(QUICK_SAVE_SLOT, silent); + break; + case CARD_SLOTA+2: + case CARD_SLOTB+2: + SaveSRAMToSD(silent); + break; + case CARD_SLOTA+4: + SaveSRAMToSMB(SILENT); + break; + } } + diff --git a/source/ngc/sram.h b/source/ngc/sram.h index e50a9648..cca22f92 100644 --- a/source/ngc/sram.h +++ b/source/ngc/sram.h @@ -1,14 +1,17 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * crunchy2 April 2007-July 2007 - * Michniewski 2008 - * Tantric September 2008 + * Nintendo Gamecube Port + * crunchy2 April 2007 * * sram.cpp * * SRAM save/load/import/export handling - ***************************************************************************/ + ****************************************************************************/ -bool SaveSRAM (int method, bool silent); -int LoadSRAM (int method, bool silent); +int prepareMCsavedata (); +int prepareEXPORTsavedata (); +void decodesavedata (int readsize); + +void quickLoadSRAM (bool8 silent); +void quickSaveSRAM (bool8 silent); diff --git a/source/ngc/tempgfx.h b/source/ngc/tempgfx.h new file mode 100644 index 00000000..f9d3b3d2 --- /dev/null +++ b/source/ngc/tempgfx.h @@ -0,0 +1,556 @@ +/******************************************************************* + * Image File : ..\snesGX2.bmp + * Width : 640 + * Height : 480 + * + * This header contains a compressed Zip image. + * Use zlib1.2.3 uncompress function to restore. + *******************************************************************/ + +#define tempgfx_RAW 614400 +#define tempgfx_COMPRESSED 8647 +#define tempgfx_WIDTH 640 +#define tempgfx_HEIGHT 480 + +unsigned char tempgfx[8647] = { +0x78,0xda,0xed,0x9d,0xd9,0x77,0x14,0x47,0x9e,0xef,0xf9,0xdb,0xee,0xcb,0x9d,0x99, +0x3b,0x67,0x66,0x7a,0xe6,0x9c,0xdb,0xe3,0xf6,0x9d,0xde,0x6c,0xb7,0xdb,0xdd,0xee, +0xf6,0xc2,0x8e,0xa9,0x88,0x5f,0xa6,0x58,0x8d,0x31,0x60,0xcc,0x2a,0x30,0x8b,0x58, +0x2c,0x10,0x48,0x2c,0x02,0x81,0x16,0xb4,0x21,0xb4,0x21,0xc4,0x22,0x21,0xc0,0x02, +0x03,0x9e,0x87,0xee,0x73,0x6e,0x9f,0xe3,0x7e,0xe8,0x97,0x7e,0xb8,0xf7,0x17,0x51, +0x59,0xa5,0xcc,0x92,0x4a,0xca,0x12,0x2a,0x55,0x09,0x3e,0xfd,0x3d,0x9f,0x36,0x52, +0xe5,0x12,0x99,0x59,0xf9,0x51,0x44,0x46,0x64,0xe6,0x32,0x59,0x46,0x08,0x21,0x84, +0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10, +0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0xbc,0xa6, +0xe9,0x91,0x2b,0x72,0x46,0x8e,0xcb,0x7e,0xd9,0x47,0x08,0x21,0x65,0xc9,0x7e,0x75, +0xcc,0x19,0x75,0x4d,0x4f,0xd5,0x98,0xaf,0x5d,0xce,0xcb,0x37,0x52,0x4b,0x08,0x21, +0x8b,0x96,0x6f,0xd4,0x3b,0xed,0x15,0xb7,0x5f,0xb3,0xfa,0x98,0x10,0x42,0x2a,0x91, +0xe6,0x0a,0xba,0xef,0x96,0x5c,0x94,0x7a,0x42,0x08,0xa9,0x58,0x2e,0xaa,0x87,0x2a, +0x61,0xbf,0x6e,0xb9,0xa4,0xeb,0x26,0x84,0x90,0x4a,0xe6,0x92,0xba,0x68,0xf1,0xfb, +0x3b,0xae,0x11,0x42,0x48,0x55,0xa4,0x67,0x91,0x5b,0xbe,0xad,0x84,0x10,0x52,0x35, +0x59,0xbc,0x56,0xf0,0x90,0x74,0x48,0xdb,0xb4,0x74,0x49,0xbf,0x19,0x92,0x3b,0xe6, +0x4e,0x00,0x00,0x50,0x1e,0x86,0xd4,0x33,0x5d,0xd2,0x66,0x0b,0xfd,0xd3,0xa1,0x5e, +0x5a,0xac,0xb6,0x6f,0x47,0x41,0x3a,0x65,0x88,0x63,0x03,0x00,0x8b,0x83,0xfa,0xa6, +0x53,0x3a,0x6c,0xd2,0x42,0x8b,0xd3,0x06,0xee,0x97,0x1b,0x05,0xe9,0xb3,0x23,0xd4, +0xfb,0x00,0x60,0x11,0x19,0x91,0x3e,0x53,0x68,0xa2,0xfe,0x45,0xf0,0x5f,0xaf,0xd6, +0xf6,0xe2,0xe9,0xc7,0x7d,0x00,0x50,0x01,0xfa,0xa5,0xd3,0xc6,0x5d,0xd4,0xbb,0x28, +0xad,0xdf,0xee,0x58,0xfa,0x2c,0xc7,0x01,0x00,0x2a,0xd3,0x0e,0xee,0x33,0x71,0x1b, +0x95,0xbf,0x05,0x3c,0xa8,0xeb,0x88,0x67,0x04,0xff,0x01,0x40,0x85,0xfc,0x77,0xdb, +0x24,0x7d,0x34,0x58,0x66,0xff,0x0d,0xc8,0xcd,0x58,0x68,0xfb,0x02,0x40,0x65,0xdb, +0xc0,0x37,0x6d,0xdc,0x48,0xe5,0xee,0xfd,0xe8,0x8b,0x85,0xf1,0x2e,0x00,0x50,0xd9, +0xf1,0x30,0x7d,0x76,0xca,0x48,0xb7,0xca,0x5e,0xff,0xeb,0x8f,0x65,0x84,0xfd,0x0f, +0x00,0x15,0xed,0x07,0xee,0xb7,0x71,0x27,0x95,0xdb,0x7f,0xf1,0xb0,0xff,0x01,0xa0, +0xb2,0xd7,0x00,0x07,0x6c,0xdc,0x49,0xe5,0xee,0xff,0x88,0x87,0xfd,0x0f,0x00,0x95, +0xf5,0xdf,0xa0,0x8d,0x3b,0xa9,0xbc,0xfe,0x1b,0x49,0x84,0xfd,0x0f,0x00,0x95,0xf5, +0xdf,0xb0,0x1d,0x96,0xa9,0x94,0xd7,0x7f,0xb7,0x13,0x61,0xff,0x03,0x40,0x85,0xc7, +0xc0,0xd8,0xb8,0x93,0xa8,0xff,0x01,0xc0,0x9b,0xe3,0xbf,0x11,0x1b,0x77,0x52,0x79, +0xfd,0x77,0x27,0x19,0xf6,0x3f,0x00,0x54,0xd4,0x7f,0x77,0x6c,0xdc,0x49,0xe5,0xf5, +0xdf,0xdd,0x44,0xd8,0xff,0x73,0x1d,0x9b,0xcb,0x66,0x9b,0xac,0xb6,0xab,0x65,0xee, +0x6c,0x93,0xba,0x45,0xbb,0x97,0xe6,0xb2,0x6c,0x33,0x69,0xca,0xa4,0xa5,0xb2,0x75, +0x6e,0x8c,0xa7,0x34,0xa6,0xda,0x8e,0x6d,0xd2,0xc8,0xfd,0x40,0xb0,0xc8,0xe7,0xd8, +0x5d,0x1b,0x77,0x52,0x79,0xfd,0x77,0x2f,0x11,0xf6,0xff,0xac,0xd7,0x65,0xcd,0x9e, +0x94,0xee,0xcb,0xe5,0xa8,0x7c,0x6e,0xd3,0x7a,0xa9,0x31,0x37,0xf6,0x3c,0xa5,0x9b, +0x72,0x8e,0x1d,0x96,0x3d,0xa6,0x94,0x32,0x69,0xa9,0xec,0xee,0x12,0xb6,0xe3,0xac, +0x0c,0x99,0x63,0x5a,0xbe,0xe4,0x7a,0xaf,0xc7,0xf6,0xcb,0xf5,0x82,0xf2,0x46,0x8e, +0x9d,0x63,0x7f,0xf6,0xc9,0x61,0xb3,0x25,0xf5,0x76,0x76,0x9a,0xba,0x05,0x2a,0xc3, +0xb0,0xec,0x33,0x61,0xaa,0xf5,0xae,0xb7,0xbb,0xe2,0xeb,0x28,0xa0,0xb1,0xa0,0x3c, +0x73,0x1e,0x57,0x48,0x79,0x9e,0xdd,0xb3,0x71,0x27,0x95,0xd7,0x7f,0xf7,0x13,0x61, +0xff,0xcf,0x76,0x5c,0x9c,0x67,0x32,0xf6,0xe4,0x86,0x3b,0x99,0x3b,0x9b,0xee,0xac, +0x9f,0x8b,0xab,0xe1,0xea,0x12,0xbd,0xb4,0xdb,0xf6,0x07,0x03,0xe6,0xeb,0x12,0x1d, +0xeb,0x5c,0x96,0x09,0x4e,0x9a,0x34,0x65,0xba,0xb3,0xf1,0xea,0xfa,0xd5,0xf2,0xb9, +0xb8,0xed,0x38,0x9b,0x62,0x3b,0xce,0x06,0xae,0x2c,0x33,0x9f,0xe7,0x57,0xd5,0x8b, +0xc3,0xc1,0x6d,0x73,0x7d,0xc6,0xf2,0x6e,0xb7,0x43,0xc1,0xb0,0xb9,0x1d,0x8c,0x98, +0x19,0xc7,0xd4,0xab,0xcf,0x4c,0x49,0xfb,0xa6,0x46,0x16,0xaa,0x0c,0xfb,0x4a,0xdc, +0xbf,0x67,0xa3,0x75,0x8c,0xe8,0x72,0xa6,0x1c,0x5a,0xca,0xdf,0x1c,0x77,0x5c,0x67, +0xd9,0x17,0x15,0x19,0x63,0x7c,0xd3,0xdc,0xf4,0x74,0xeb,0xbe,0xbb,0xee,0xb9,0x22, +0x4d,0xb6,0xc9,0x73,0xce,0x9e,0x92,0x53,0x33,0x72,0x42,0x0e,0xd9,0x43,0x52,0x98, +0x13,0x05,0xd3,0x9d,0xf5,0xcb,0xb9,0xe2,0x97,0xdb,0xed,0xd7,0x73,0xbb,0xa4,0xf3, +0xec,0xbe,0x8d,0x3b,0xa9,0xbc,0xfe,0x7b,0x90,0x08,0x9e,0xbb,0x33,0xcb,0xdf,0x7b, +0xf5,0x4c,0x38,0x90,0x19,0xdf,0x38,0xbe,0x3e,0x0d,0x6d,0x81,0xfa,0x2f,0x68,0x33, +0xa9,0xa6,0xaf,0x69,0x5a,0x9f,0xd1,0xe5,0xef,0x94,0x5d,0xd6,0xb9,0xa9,0xa9,0xa6, +0x84,0x75,0xe8,0xf4,0x03,0x1b,0xd2,0x4d,0x3f,0xbe,0xa1,0x6d,0xbd,0x3b,0x23,0x53, +0x6f,0x87,0x96,0xcb,0xdb,0xa7,0x60,0x3b,0xea,0xbc,0x17,0x9b,0x6c,0xaf,0x34,0x7b, +0x0f,0xd4,0xd5,0x8c,0x67,0xe2,0xeb,0x50,0x5b,0xd9,0x16,0xe9,0x33,0x03,0xd1,0x79, +0x5f,0xb8,0x2f,0x3b,0x65,0x8d,0xce,0xbf,0xd7,0xf6,0xa4,0x2c,0xf7,0x4e,0x5d,0xde, +0x42,0x95,0xc1,0xd5,0xfd,0x52,0xed,0xaf,0x0d,0xa3,0xd1,0x3a,0x4e,0xe9,0x3a,0xfa, +0xcd,0x90,0x77,0x60,0x76,0x19,0x7b,0xfc,0xdf,0x9c,0x26,0x93,0xfe,0xb8,0xf6,0x9a, +0x5b,0xc1,0xe0,0x8c,0xfb,0xa2,0x0c,0xf7,0xcf,0xaa,0x73,0xba,0x22,0xaf,0x65,0x9d, +0xf6,0x6d,0xe4,0xa6,0xc3,0x72,0xa8,0x82,0x39,0xa5,0xe5,0x68,0xb2,0x97,0xb4,0x5c, +0x9d,0xb3,0x39,0x51,0x1e,0xd8,0xb8,0x93,0xca,0xeb,0xbf,0xb1,0x44,0xf0,0x5c,0x71, +0x76,0xe9,0xf7,0xf8,0x72,0x38,0x99,0x99,0xac,0x49,0x47,0xb7,0xf7,0x5f,0xb7,0x49, +0x3b,0xfd,0x9d,0xc0,0xf8,0xf3,0xd8,0xe8,0xba,0x4a,0x5b,0xc7,0x65,0x9b,0x76,0xfa, +0xc9,0xb0,0x3b,0xe3,0xd6,0x51,0xca,0x76,0xe4,0xda,0x95,0x89,0x79,0xc2,0x53,0x7e, +0x39,0xf5,0x92,0xf5,0x43,0x7c,0xfa,0xcb,0xde,0x19,0x9b,0xed,0x35,0xad,0xe3,0xf5, +0xca,0xc0,0x8c,0xe7,0xbc,0xdb,0x97,0x47,0x4a,0x28,0xc3,0xae,0x05,0x2c,0x83,0xf3, +0xdf,0x9d,0xd4,0xfb,0xeb,0xb2,0xae,0x43,0xe4,0x4a,0x70,0x63,0x6a,0x39,0x7a,0xfe, +0xea,0x51,0x92,0x3b,0x25,0x1d,0xd7,0x6f,0x6d,0x7b,0xd0,0xab,0x6e,0x1a,0x7e,0xf5, +0x3a,0xa0,0x3a,0xfd,0xa6,0xf4,0x78,0xbf,0x35,0x27,0xea,0x6b,0x87,0xed,0x21,0x59, +0x5a,0x39,0xa5,0xfb,0xa5,0x49,0xae,0xa9,0x0f,0x6f,0xc5,0xb6,0x6f,0xcc,0xc6,0x9d, +0x54,0x5e,0xff,0x8d,0x27,0x82,0xe7,0x8a,0xb3,0x5e,0xcf,0x9b,0xc9,0xf0,0x87,0xcc, +0x0f,0x35,0xe9,0xb8,0xe5,0xce,0xc1,0xe0,0x96,0x4d,0x3b,0xfd,0x0f,0x61,0x7d,0xf6, +0x7c,0x2e,0x79,0x1d,0x93,0x26,0xfd,0x3a,0x6e,0xf9,0x75,0x94,0xb2,0x1d,0x17,0x74, +0xbb,0xb3,0xd7,0xcb,0x2e,0x24,0xb6,0xa5,0x3e,0x72,0x52,0xa2,0xbc,0x61,0x8b,0x5f, +0xfe,0xe7,0x72,0xd2,0x9c,0x97,0x16,0xff,0xbd,0x1e,0x9e,0xe6,0xbf,0x01,0xe7,0x8f, +0x92,0xf6,0xa5,0x6b,0xe3,0x7f,0xbe,0x40,0x65,0x70,0xdb,0x32,0x56,0x53,0xda,0xba, +0xf7,0xcb,0x05,0xd3,0xaa,0x75,0xb8,0x41,0xad,0x03,0xde,0x91,0x3a,0x2d,0x7f,0x7d, +0x89,0xc7,0xf5,0x4b,0x7b,0x5e,0xcf,0xf3,0xee,0x60,0x20,0x75,0x1d,0xd0,0xb5,0x1b, +0x3b,0x7d,0x1d,0xee,0xa2,0x69,0x92,0x46,0xef,0xb8,0x63,0x33,0xb6,0x3f,0x5f,0x97, +0x9c,0xb4,0x0d,0x72,0xc9,0xb6,0xca,0xb8,0x8d,0x3b,0xa9,0xbc,0xfe,0x7b,0x98,0x08, +0x9e,0x2b,0x8e,0x3b,0xa7,0xfe,0x1c,0xfe,0xd9,0xe4,0x48,0xd7,0x17,0x32,0x64,0xe3, +0xf3,0xcc,0x4a,0x30,0xe4,0xd7,0x31,0x14,0xa4,0x9c,0x5e,0x19,0x72,0x65,0x08,0xfe, +0x3c,0xb5,0x8e,0x20,0xdd,0x75,0xa9,0xb9,0xb6,0xa3,0x2d,0x56,0x86,0x36,0xfd,0x7c, +0x8d,0x6c,0xf0,0xd3,0x34,0xc4,0xcb,0x16,0x34,0xe8,0xba,0x1a,0x12,0xdb,0xd7,0xe0, +0x97,0x65,0xec,0x16,0xf9,0xda,0x1c,0x57,0x67,0xb4,0x07,0x37,0xb5,0xdd,0x58,0x70, +0xbe,0xcb,0x55,0x9d,0x6f,0x4f,0xfa,0xfd,0x12,0x95,0x71,0x63,0xd4,0x97,0xf4,0xaa, +0x65,0x70,0xfe,0x7b,0x52,0xc2,0xba,0x2f,0xbb,0xb6,0xb7,0x1c,0x35,0x8d,0xd2,0x6e, +0xfa,0xb4,0x2d,0x3d,0x22,0x5f,0x9a,0xd2,0x8f,0x6b,0x46,0xcf,0xef,0x06,0x75,0x59, +0xef,0xb4,0xfd,0x71,0x4b,0x3d,0x77,0x43,0x3d,0x77,0x55,0xeb,0x72,0x8d,0xbe,0x1e, +0x77,0xe4,0x35,0x76,0x5c,0x9a,0x24,0x9d,0x54,0x5e,0xff,0x4d,0x24,0x82,0xe7,0x66, +0xf7,0xdf,0x8f,0xc1,0x8f,0x26,0xc7,0x5c,0xd7,0xd1,0x57,0xc8,0x4a,0xfd,0x7c,0xd4, +0xe6,0xe7,0x29,0x32,0xfd,0xd4,0xe7,0xcf,0xfd,0x3a,0x46,0x63,0xeb,0x48,0x77,0x7d, +0xfd,0xc7,0xd8,0x3a,0xf6,0xcd,0x31,0xcf,0x0a,0x9b,0x66,0x3b,0x3a,0x65,0xea,0xf3, +0x4e,0xfd,0xfc,0x13,0x59,0x1f,0xd5,0xbf,0x1a,0x6d,0x7c,0xde,0x78,0x59,0x7f,0x94, +0x46,0xbf,0xee,0x4f,0x64,0xb9,0x35,0xb2,0xc3,0x6c,0x8b,0x9c,0x39,0x53,0x9f,0xe8, +0x6a,0xd9,0x17,0x2b,0x73,0x67,0xaa,0xed,0x14,0xad,0x43,0x7d,0x55,0x62,0x19,0x8e, +0x4a,0x93,0xfa,0xaf,0x2f,0x51,0xff,0x4b,0xd3,0xff,0x11,0x5f,0x66,0xa7,0xf7,0xff, +0x97,0xf6,0xb8,0x5c,0x36,0x5d,0x5a,0x7f,0xcb,0xfa,0x6f,0xa6,0xe3,0xfa,0x3c,0x71, +0x1c,0xa6,0xca,0x38,0xea,0xcb,0xb4,0x55,0xf6,0x9a,0xd3,0x5a,0xbe,0xcb,0xd2,0xac, +0xf5,0xb9,0xf3,0x55,0x70,0x3d,0xae,0x5a,0x93,0x74,0x12,0xfe,0xab,0x9e,0xf6,0xef, +0x5f,0x82,0xbf,0xd9,0xbf,0x45,0x1c,0x98,0xe3,0x3c,0x5a,0xe5,0x3f,0x7f,0x90,0x9f, +0xfe,0x6f,0x45,0xa6,0xcf,0x7f,0x1e,0xfc,0xb7,0xff,0xfc,0x81,0x4c,0xad,0x63,0x6e, +0x2b,0xe8,0x5a,0xe4,0x2f,0xb1,0x75,0x1c,0xb0,0x73,0x4f,0xaf,0x73,0xc4,0xb6,0x63, +0x2e,0x7a,0xb4,0xdc,0x1f,0xca,0xc7,0xbe,0x3e,0xe5,0xe6,0x3d,0x23,0x33,0x4f,0x77, +0xc6,0x6f,0xdf,0x6f,0xec,0xbb,0xf2,0x91,0xb5,0xb2,0x61,0x0e,0xa7,0x1d,0x88,0x95, +0xb9,0x67,0xce,0xed,0x5c,0xa9,0x7f,0x4b,0xc4,0xfb,0xec,0x68,0x09,0x65,0xd8,0x65, +0x4e,0xc8,0x25,0xf5,0x57,0x7f,0xa2,0xcd,0x39,0xac,0xcb,0x59,0x2d,0x5b,0xa4,0x47, +0xd2,0x6d,0x7f,0xab,0xf7,0x7f,0xc6,0xee,0xd5,0xfa,0x5b,0x9b,0x5b,0x96,0xf7,0xdf, +0xf4,0xe3,0x7a,0x51,0x92,0xfb,0x6c,0xea,0xf3,0x07,0xfa,0xf9,0x87,0xf2,0xb6,0xfc, +0x41,0x8c,0x6c,0x93,0x3d,0x72,0x10,0xc7,0x55,0x8d,0xff,0x1e,0x25,0x82,0xe7,0x66, +0xef,0xff,0x68,0x96,0xbf,0xdb,0xbf,0xcf,0xc9,0x73,0x9d,0xce,0x9d,0x11,0x9f,0xe9, +0xf7,0x7e,0x22,0xf6,0x7b,0x77,0x9e,0xfc,0x93,0xfd,0x77,0xf9,0xb9,0xfd,0x40,0x7d, +0xb2,0xd2,0xf7,0x81,0xae,0x96,0xa9,0xcf,0xff,0xe4,0x7f,0x9e,0x48,0xb5,0x0e,0x47, +0x9f,0xcd,0xd6,0xe7,0x9a,0x25,0xcd,0xf4,0xcf,0x25,0x5b,0x2a,0xf5,0xb8,0xf4,0xa5, +0x5e,0xc7,0xdf,0x6d,0x9f,0x96,0xfb,0x03,0x79,0xdf,0x86,0x52,0x6b,0x0e,0xfb,0x32, +0x1f,0x9c,0x61,0x7d,0x07,0x7d,0xd9,0x7f,0x25,0x6f,0xdb,0xf7,0xb4,0x4c,0x9b,0x45, +0x4c,0x72,0xdb,0xe3,0x34,0x17,0x2c,0xa3,0xcf,0x3b,0xeb,0x5f,0xe4,0x3f,0xed,0x3b, +0xf2,0xa1,0xfd,0x54,0x56,0x39,0xc7,0x15,0x3a,0x51,0xdb,0xbf,0xbb,0x6d,0x9d,0xd6, +0xe7,0x4e,0xa7,0x2e,0x43,0xad,0x69,0x08,0x5a,0x4d,0xaf,0x24,0xfb,0x5d,0xeb,0x74, +0x59,0x5b,0xe5,0xaf,0xa9,0xb7,0xff,0xa0,0x2e,0xf3,0x5d,0xad,0x4f,0x7e,0x29,0xa7, +0xcc,0x35,0xad,0x4b,0x66,0xfd,0x57,0x78,0x5c,0xb7,0xc6,0xca,0xf3,0x57,0x75,0x75, +0xfc,0xb8,0x4e,0xe8,0xe7,0x1f,0xc8,0xbf,0xcb,0x7b,0xb2,0x56,0xbd,0xbb,0xbb,0x6a, +0xfc,0x77,0x58,0x72,0x63,0x56,0xea,0xf3,0x63,0x5f,0x2e,0xdb,0xdc,0x78,0x98,0xf6, +0xfc,0x18,0x99,0x42,0xfa,0x8a,0x5e,0xaf,0x8c,0xd3,0x96,0xed,0x7f,0xce,0xd7,0x75, +0x8f,0xa7,0xbe,0x76,0x99,0x74,0x52,0x79,0xfd,0xf7,0x38,0x11,0x3c,0x57,0x9c,0xec, +0x18,0xb3,0x27,0xf2,0xff,0x52,0xe5,0xff,0x8a,0xf8,0xf3,0x36,0x3e,0xbd,0xfb,0xf9, +0x7f,0xd9,0xb7,0xe4,0xf7,0x76,0x9d,0x6c,0x32,0xdb,0xb5,0x7e,0xe2,0x7e,0x13,0x9f, +0xa7,0x70,0x8e,0xd9,0x33,0xe0,0xea,0x73,0xb6,0x94,0x79,0x72,0xa5,0x12,0xfd,0x57, +0x29,0x6b,0xf9,0xad,0xbc,0xa7,0xe7,0xf4,0x41,0x73,0x4a,0x44,0xd7,0x57,0x3b,0xc3, +0x54,0xb5,0x3a,0xd5,0xa7,0x5a,0xc7,0xf9,0xb9,0xd6,0x15,0xc5,0xee,0x91,0x1a,0x53, +0xbc,0x54,0x57,0x24,0xb9,0x0c,0xb7,0x86,0xf7,0xec,0x4f,0xe4,0x97,0x5a,0xcf,0xb2, +0x66,0xab,0xd6,0xcf,0x02,0x37,0x46,0xa5,0x60,0xe9,0x5b,0xd4,0x67,0xf5,0x72,0xc5, +0x34,0x4b,0x90,0xb2,0x0c,0xa7,0xcd,0x55,0xe9,0x9a,0xd6,0xe7,0xea,0xfa,0xb3,0x4b, +0xdb,0xc7,0x1f,0xcb,0x7f,0x6a,0x7d,0x72,0x93,0x1c,0xd6,0xf5,0x5f,0x30,0x97,0x64, +0x93,0x9d,0x7e,0x5c,0xe3,0x3f,0x9f,0x93,0xe4,0x71,0x7d,0xe2,0xf7,0xe0,0x3f,0xcb, +0x2f,0xb5,0x1e,0xbb,0x49,0xbe,0x5a,0x14,0xff,0xd5,0x79,0xe7,0x9c,0xf1,0x4e,0xbb, +0x10,0x39,0xad,0x27,0x72,0x53,0x25,0xcf,0xa3,0x01,0x5d,0x7f,0x9b,0x1f,0x97,0xd3, +0xa0,0xe5,0x3b,0x3a,0x63,0xd9,0x93,0x4e,0x2a,0xaf,0xff,0x9e,0x24,0x82,0xe7,0x66, +0x1b,0x77,0x50,0xe7,0x7d,0xd5,0x20,0xcf,0x53,0xd5,0xb7,0xda,0xbd,0x2f,0x0b,0xeb, +0x09,0x3f,0xd1,0x3a,0xce,0x3a,0x75,0xdf,0x21,0x73,0x52,0xea,0xcd,0xab,0xd7,0xff, +0xd6,0x6a,0x3b,0xcf,0x2d,0xd7,0x97,0x2a,0xc5,0x3c,0xed,0x3a,0xad,0xf3,0x87,0xa4, +0xae,0x03,0xba,0xfa,0xdf,0xfb,0xf2,0x8e,0x35,0xd1,0x7d,0x13,0x07,0x67,0xa9,0x27, +0x7d,0xaa,0xf5,0xc4,0xb5,0xea,0xaf,0x93,0xb2,0xb9,0xe4,0xfa,0xdf,0x4f,0xb5,0xee, +0x17,0xca,0x6e,0x6d,0xe3,0x9e,0x36,0xee,0x5a,0x63,0x5f,0xc1,0xb2,0xbf,0x90,0x23, +0xe6,0x5c,0x70,0xd1,0x6c,0x4a,0x5d,0x86,0x2b,0xa6,0xbb,0xa0,0xed,0x9b,0xbb,0x8e, +0x9b,0x6e,0xff,0xfe,0x35,0xaa,0xc7,0xff,0x87,0xfc,0x83,0xfc,0x54,0x7e,0x2f,0x19, +0xdf,0x7a,0xad,0x95,0x40,0x0a,0x8f,0x6b,0x43,0x6c,0xbe,0x89,0xa8,0xee,0x9a,0xac, +0xff,0xfd,0x56,0xfe,0x51,0xfe,0x4b,0x96,0xcb,0x46,0xd9,0x25,0x07,0x16,0x68,0xec, +0x48,0xae,0xde,0x76,0xd5,0xfb,0xad,0x23,0xaa,0x77,0x2d,0xb5,0xf3,0xaa,0x4f,0x7a, +0x7d,0x1f,0xf7,0x19,0x75,0x76,0x76,0xcb,0x92,0x4e,0xc2,0x7f,0xd5,0x41,0x67,0x8a, +0x7b,0x6c,0xe3,0xd7,0x94,0x1e,0xcc,0x78,0xfd,0xef,0x7f,0xdb,0xdf,0x69,0xfd,0xc1, +0xf5,0x05,0x5e,0xd5,0xbf,0x83,0xaf,0x7e,0xfd,0xef,0x33,0xfb,0xd9,0x9c,0xd7,0xf3, +0x7b,0x0a,0xae,0x45,0x7d,0x66,0x4b,0xd9,0x8e,0x9e,0xc8,0x7f,0x19,0x71,0xe3,0xd8, +0x76,0xda,0xa2,0xd7,0x0e,0xfd,0xb5,0xc7,0x15,0x6a,0x87,0x03,0xe6,0xbc,0xd6,0x15, +0x5f,0xf5,0xfa,0x5f,0xbc,0x0c,0x07,0x7c,0x9b,0xb5,0xd6,0x9c,0xf0,0x7d,0x2a,0x69, +0xcb,0xd0,0x6e,0x6e,0x05,0xd3,0xc7,0xdb,0x25,0xf7,0xf9,0xdc,0xd7,0x71,0x3f,0x50, +0xf7,0xbd,0x23,0x9f,0x24,0x7a,0x62,0x92,0xc7,0xd5,0xda,0xff,0x8e,0x2d,0x6f,0x4b, +0xe1,0x75,0x5d,0xbf,0xcf,0x9d,0xff,0xfe,0x8f,0xba,0x79,0x83,0xec,0x2c,0xc1,0x7f, +0x47,0x7c,0xfb,0xb4,0xc1,0xb7,0x4d,0xa7,0xda,0xa4,0x43,0x0b,0xf0,0x7d,0xbe,0x6f, +0xee,0x7b,0x1e,0x98,0x87,0xe1,0x43,0xcf,0xa3,0xf0,0xbb,0xcc,0x77,0x9e,0xc9,0xcc, +0xf7,0xe1,0xf7,0x33,0xf2,0x7c,0xa6,0x31,0x4b,0xe1,0xf3,0x82,0xe9,0x9e,0xfa,0xe5, +0x3c,0x72,0xcb,0xd5,0xe5,0xbb,0xf5,0x8c,0xa6,0xae,0x63,0xdc,0xd4,0x6d,0x7c,0x62, +0xf1,0x5f,0xf5,0x91,0xe6,0x9e,0xdc,0x78,0xbf,0xe9,0xa8,0x9f,0xbe,0xb0,0x9f,0xf0, +0x2d,0xfb,0x91,0x6c,0xd7,0xba,0xc9,0x55,0xd3,0xe3,0xc7,0xc1,0x2d,0x44,0xff,0xef, +0x9c,0xa5,0xb2,0x85,0x7d,0x91,0xa5,0x6c,0x47,0xa7,0xf7,0xdf,0x7b,0x76,0x8d,0xfe, +0x77,0x87,0xfc,0x29,0xd6,0xaf,0xf9,0x27,0x73,0x3a,0xf1,0xf3,0x8f,0x66,0x87,0x4e, +0xb3,0x56,0xeb,0x89,0x8d,0x72,0xc3,0x1c,0x29,0x7a,0xef,0xf3,0x5a,0x49,0xd3,0xff, +0x1b,0x2f,0x83,0xeb,0xb3,0xb5,0xf2,0x85,0xbb,0xae,0x56,0x52,0x19,0xfa,0x63,0xf7, +0x6c,0xe4,0xee,0x8d,0x28,0xb5,0x1f,0xbf,0x48,0x0f,0x71,0xac,0xfc,0x2d,0xd3,0xfa, +0x9f,0x93,0xeb,0x70,0xfb,0xfc,0xb7,0x5a,0x87,0x2c,0xee,0xbf,0xc3,0xde,0x73,0xe7, +0xa3,0xba,0x5c,0x87,0xaf,0xc7,0xcd,0x77,0x9c,0xf4,0x3d,0xef,0xb5,0xb1,0x8c,0x73, +0xda,0x44,0x90,0x75,0xda,0xb3,0xc8,0x4d,0x3f,0x94,0x30,0xee,0x71,0xc1,0xd1,0xf5, +0x3f,0xd3,0xb2,0x3c,0xd6,0x72,0x8d,0xcd,0xe6,0x44,0xfc,0xb7,0x24,0xc6,0xff,0xcd, +0x45,0x8f,0x3f,0xaf,0x62,0xe3,0xc4,0xfc,0x3d,0x09,0x3f,0xb3,0x9f,0xc8,0x2e,0x53, +0xaf,0x75,0xbf,0x81,0x69,0xcb,0x7c,0xf2,0xea,0xe3,0xff,0xe6,0x1c,0x8b,0xd6,0x53, +0xf2,0x76,0xb4,0x79,0xff,0x2d,0xb7,0x6e,0x0c,0xef,0x8b,0xc4,0xb2,0x5c,0x3f,0xc0, +0x97,0x89,0x75,0xbf,0xf0,0xbf,0xcb,0x48,0x5d,0xd0,0x62,0xdc,0x3d,0x63,0x7d,0xea, +0xb6,0xcb,0x72,0xca,0x1c,0xd0,0xf6,0xe8,0x56,0xd9,0x68,0x36,0xca,0x46,0xbb,0x51, +0x42,0x5b,0xea,0xf8,0xbf,0x2f,0xb5,0x0c,0x2b,0xb4,0xad,0x5f,0x4a,0x19,0x0e,0x4b, +0xa3,0xbd,0xa4,0x6d,0xe0,0x0b,0xfa,0x5f,0x77,0xff,0xd7,0x37,0x91,0x6b,0xe6,0xb3, +0xfd,0xc9,0xe3,0xb8,0x69,0x1e,0xe3,0xff,0x72,0xf5,0xbf,0x8d,0xda,0xf2,0xaf,0xb3, +0x8d,0x5a,0x9f,0x6b,0x89,0xee,0x03,0xeb,0x2f,0xf9,0xbb,0x78,0x2f,0x5f,0x6f,0x7b, +0x9c,0xa8,0xaf,0xfd,0x50,0x59,0xbf,0xcd,0x83,0xef,0xc3,0x67,0x5a,0xfe,0x89,0xcc, +0x98,0x6e,0x13,0xfe,0xab,0x7e,0xff,0x95,0x72,0x6c,0xfd,0xbd,0x09,0xf1,0xfb,0x3f, +0xfc,0xbd,0xba,0xd3,0xfd,0x37,0x35,0xcf,0xd8,0x3c,0xef,0xff,0xf8,0xc1,0x94,0x7a, +0x8f,0x49,0xa9,0xdb,0xf1,0x91,0xbb,0xfe,0x56,0x70,0x9f,0xc9,0xee,0xe8,0xf7,0xbb, +0xc3,0xd8,0xfa,0xf5,0x5c,0xfc,0x42,0x7f,0x6f,0xe4,0xb4,0x69,0x55,0xd7,0xf6,0x4a, +0xb7,0xfe,0xf7,0x82,0xd6,0xd1,0x8e,0x9a,0x5a,0xd9,0xaf,0x75,0xad,0x7d,0x76,0x9f, +0xec,0x2d,0xf1,0xfe,0x0f,0xb7,0x5f,0x56,0xc8,0x72,0x5d,0x6e,0x29,0x65,0x58,0xa5, +0xad,0xe0,0xed,0xf2,0xb5,0xd6,0xb6,0x6a,0x35,0x53,0x75,0xad,0x52,0xb7,0xbf,0x65, +0xda,0x71,0xdc,0x38,0x8f,0xfb,0x3f,0x7e,0x25,0x6f,0xfb,0xfb,0x48,0x9a,0xd4,0x79, +0xe9,0xda,0xaf,0xae,0xdd,0x38,0x16,0xb8,0xb6,0xe9,0x13,0x5f,0x87,0x73,0x8e,0x7b, +0xb1,0x04,0x1d,0x57,0x4a,0xfd,0x70,0x32,0x7c,0x9c,0x79,0x18,0xe0,0xbf,0x6a,0xf5, +0x5f,0xea,0xfb,0x6c,0x6b,0xfa,0xbd,0x67,0x12,0xf7,0xff,0x16,0xf1,0xdf,0xd4,0x3c, +0x77,0x32,0xf3,0xbb,0xff,0x77,0x32,0xf5,0xf4,0xfd,0xc1,0xea,0x12,0xb7,0x63,0x32, +0xb3,0x41,0xb2,0xcf,0x80,0x19,0x4f,0xdc,0x17,0xbb,0xdf,0xb8,0x9e,0x86,0x9f,0xca, +0xa7,0xfa,0xd9,0xfe,0xc4,0xbd,0xb7,0xe3,0x81,0xbb,0x4e,0xba,0x4e,0xea,0xa5,0xd5, +0x74,0xa9,0x03,0x3b,0xf5,0xbf,0x97,0xb5,0x5d,0xd8,0x20,0xf5,0xba,0xdd,0x8e,0x33, +0x66,0x73,0x29,0xf7,0xff,0x86,0xae,0x9f,0x7c,0x85,0xcc,0x5c,0x86,0x8f,0xe5,0x7f, +0x8a,0x33,0xe0,0x4c,0x65,0x58,0x2d,0xa1,0x37,0xe0,0xfe,0x84,0x01,0x4b,0xdd,0x7e, +0x7f,0x2f,0x71,0xe2,0x38,0x6e,0x98,0xc7,0xfd,0xbf,0x6f,0xdb,0x77,0xc5,0xea,0xdf, +0x80,0x8b,0xa6,0x3b,0x18,0x9e,0xd6,0x5e,0x1d,0xcb,0x5f,0x7f,0x73,0xf5,0xb8,0x97, +0xaf,0xaf,0xe3,0xd2,0x10,0x3c,0x31,0xf8,0xaf,0x3a,0xfd,0x97,0xf6,0xd9,0x2f,0xd9, +0xe7,0x86,0x7c,0x28,0x89,0xe7,0xbf,0xf8,0xe7,0x61,0xfd,0xc2,0xae,0x94,0xdd,0xe6, +0xac,0xb4,0xe7,0xfd,0x37,0xf5,0xbc,0x91,0x81,0xf5,0xab,0xbd,0x4f,0x4a,0x7c,0xfe, +0x4b,0x38,0x9e,0xf2,0x19,0x33,0x75,0x99,0xdc,0xb5,0xa9,0xb4,0xdb,0x31,0x10,0xee, +0xf5,0xf3,0xec,0x0d,0x47,0x13,0xcf,0x8b,0x39,0xa4,0xdb,0xb7,0x52,0xcf,0xe9,0x9f, +0xca,0xbb,0xd6,0x8d,0xa8,0x3e,0x94,0x78,0xf6,0xca,0xe8,0xfa,0xbd,0xea,0xb7,0xdd, +0x7a,0xae,0xbb,0x7b,0xfe,0x6f,0x4a,0xaf,0xe9,0xd6,0x76,0x70,0x7b,0xd0,0xae,0x6d, +0xc9,0x36,0xa5,0xdd,0x5c,0x4c,0xfb,0xfc,0x97,0x0d,0x6d,0xfe,0xd9,0x2f,0x1f,0x15, +0x29,0xc3,0x72,0x6d,0x55,0xfe,0x0f,0xf9,0x89,0xb7,0xe3,0x4c,0x65,0x58,0x2b,0x9b, +0x65,0xa7,0xec,0xd5,0x36,0x67,0xd2,0x7f,0x69,0xb7,0xdf,0xd1,0x54,0xf8,0x1c,0x9f, +0xb0,0xc6,0xef,0x93,0x52,0x9e,0xff,0xf2,0x81,0xbc,0x65,0x3f,0x94,0x2d,0xa6,0x2e, +0x68,0x35,0x83,0x7a,0xbc,0x72,0xf5,0xb9,0x37,0xda,0x73,0xf8,0xef,0xb5,0xeb,0xff, +0x88,0xe7,0x37,0xf2,0xfe,0xb4,0xe9,0x3f,0x91,0xdf,0xda,0x8c,0xb6,0x03,0xcf,0xcb, +0x0d,0xef,0xbf,0xe9,0xcb,0xfc,0x83,0xd6,0x0f,0xe7,0x73,0x3d,0x3e,0x75,0xa9,0xec, +0xc7,0x25,0xce,0xb1,0x22,0xba,0x67,0xae,0x30,0xbf,0x96,0x9f,0xdb,0xf7,0x64,0xb9, +0xef,0x93,0x98,0xfe,0xe9,0x1a,0x71,0xf7,0x4b,0x5c,0xd7,0xfa,0x5f,0xbf,0x0c,0x9a, +0xc1,0x60,0x40,0xb7,0x37,0x4e,0xab,0xc9,0xa4,0x2e,0xc1,0x47,0xf2,0x4f,0xae,0xf5, +0x3b,0xc3,0xbd,0x2c,0xff,0xaa,0xb5,0xbf,0x7f,0xd6,0x5a,0xe8,0x6f,0x8a,0xdc,0xeb, +0xb2,0x22,0xaa,0x01,0x1e,0x88,0xf9,0x4f,0x16,0x60,0x2f,0xae,0x91,0x75,0x25,0x1c, +0xa3,0x3f,0xd8,0x5f,0x07,0x1f,0x9b,0x8d,0xe1,0x11,0xd3,0x12,0x0e,0x67,0x1e,0xd5, +0x3c,0xc7,0x71,0x55,0xea,0xbf,0x46,0xb9,0x68,0xaf,0xeb,0xb9,0x79,0x53,0x86,0x71, +0xde,0x3c,0xc6,0xbf,0xe4,0xf2,0xa9,0xbc,0x67,0xdf,0x91,0xdf,0xdb,0x35,0x89,0xb1, +0x26,0x2b,0xf5,0x4c,0x5e,0x65,0xb6,0xc8,0x51,0xad,0xff,0x74,0xa9,0x13,0xa6,0x2f, +0x73,0xb9,0x9e,0x2b,0xab,0x44,0x9c,0x1b,0x6c,0x5a,0x37,0xad,0x49,0x7d,0x1e,0x7e, +0xaa,0xbe,0x7a,0xc7,0xfe,0xa1,0x04,0xbf,0xae,0x90,0x3f,0xda,0x5f,0xcb,0x07,0x5a, +0xa6,0xc2,0xb5,0xfc,0xd1,0xfe,0x4e,0x59,0xab,0x75,0x1a,0x6d,0x5d,0x16,0x3c,0x4f, +0x79,0x95,0xa6,0xc6,0xee,0x95,0x6f,0xcd,0x55,0xe9,0x56,0xd7,0x25,0xfb,0x60,0x6f, +0xcb,0x4d,0xd3,0x23,0xd7,0xcc,0x05,0x6d,0xcf,0xda,0xb9,0xdd,0x21,0xbf,0x52,0xc3, +0xfd,0x8b,0xbc,0xa5,0x2d,0xdd,0x55,0x89,0x4f,0xdc,0xa8,0xe4,0x7f,0x93,0xff,0x90, +0xb7,0xe5,0x7d,0xdd,0xdf,0xeb,0x7c,0xaf,0x72,0x7c,0x5f,0xff,0x51,0xad,0xf8,0x89, +0x58,0xf9,0x5c,0xbe,0x4a,0xb4,0x80,0xf7,0x96,0x68,0x40,0xb7,0x8f,0xd7,0x26,0x8e, +0xe3,0x1a,0xbb,0x5e,0x02,0x5b,0xa3,0xf5,0xf4,0xb9,0xe7,0x5e,0xa9,0x7f,0x6f,0xfe, +0x68,0x56,0x05,0x35,0x66,0x5f,0x78,0xce,0x74,0x87,0xf7,0xb4,0x4d,0xfc,0xa2,0x4a, +0xae,0xb7,0xfd,0x90,0x1f,0xb3,0xf2,0x2c,0x3f,0xf6,0xe5,0x71,0x26,0x37,0x1e,0x66, +0x3c,0x3f,0x46,0xa6,0x90,0x7b,0x45,0xaf,0x57,0xc6,0x79,0x18,0x3c,0xd4,0x65,0x7d, +0x97,0xbf,0x76,0xf9,0x7c,0x09,0xf8,0x6f,0xa6,0xe7,0x15,0x36,0xcb,0x75,0x6d,0xbf, +0xdc,0xc4,0x81,0xfe,0xde,0xd1,0x5e,0xd3,0x1a,0x34,0x98,0x5a,0xf9,0x42,0xcf,0xf9, +0xcf,0xcc,0x1a,0x3d,0x17,0x92,0xb8,0xeb,0xee,0xab,0xcc,0x4a,0x65,0x9d,0x84,0x66, +0x87,0x1f,0xb3,0x76,0x5a,0xd9,0xaf,0x75,0xbd,0x1a,0x9d,0x67,0xab,0xd9,0x27,0xf5, +0xa6,0x45,0x97,0x33,0x1c,0x5b,0x66,0x8b,0xfe,0x6e,0x9f,0x7e,0x16,0xea,0x3c,0x5b, +0x65,0x8f,0x39,0x26,0x27,0x95,0xfd,0x66,0xbb,0xfe,0xbc,0x4e,0x97,0xb5,0xca,0xdf, +0x13,0x56,0xb8,0xae,0x35,0x7a,0x5e,0x66,0xec,0x46,0xd9,0x6e,0xf6,0xe8,0x7a,0x0e, +0xca,0x57,0xe6,0x73,0x9d,0xfe,0x33,0x59,0x33,0xad,0x5c,0xab,0xfd,0x32,0x56,0x2a, +0xeb,0x74,0x1d,0x3b,0x74,0xda,0xe3,0xe6,0x94,0xb2,0x6f,0x8e,0xed,0xc8,0xfa,0xd5, +0x18,0x77,0xef,0xfe,0x71,0x39,0xa3,0xed,0xf6,0x93,0x3a,0xef,0x76,0x9d,0x27,0xa3, +0x8e,0xde,0x68,0x77,0xca,0x37,0xa6,0x21,0xb8,0x62,0xae,0x29,0x0d,0xfa,0xef,0x9d, +0xb2,0x51,0x7f,0x9f,0xb1,0x5a,0xeb,0xd2,0x7d,0x54,0x6f,0xdc,0x33,0x9f,0x5a,0xa4, +0xc5,0x3f,0xa7,0xee,0x9c,0x7e,0x9f,0xea,0x62,0xf7,0x40,0x1d,0x54,0x13,0xed,0xd4, +0xf6,0xe9,0x7a,0xfd,0xab,0xf0,0x1b,0xf9,0x85,0x7a,0xec,0x2d,0x9f,0x9f,0xe9,0xbf, +0xb2,0xf9,0x59,0xf4,0x9b,0xb7,0xf5,0xd3,0xf7,0xd5,0x65,0x9f,0xc9,0x06,0x9d,0x7e, +0xa3,0x18,0xb5,0xdb,0xef,0xb4,0xfe,0xf9,0x0b,0xcd,0xbb,0x6a,0x48,0x77,0x9d,0x6f, +0xab,0x6c,0x53,0x42,0x6f,0xcc,0x77,0xfd,0x27,0xbf,0xd6,0x69,0x56,0xaa,0xeb,0xb2, +0xfe,0x9b,0x6a,0x01,0x1f,0xf7,0xe3,0x86,0x4f,0x5b,0xdd,0xbf,0xf6,0x0b,0xf5,0x98, +0xdb,0xbf,0xcb,0x75,0x3b,0x57,0xce,0xb2,0x8f,0x37,0xe9,0x3e,0xab,0x0d,0xea,0xcc, +0xc9,0xe0,0xb0,0xd9,0x1b,0xec,0x32,0x3b,0x83,0x7d,0xe6,0x68,0xd8,0x68,0x2e,0x87, +0x4d,0x99,0xd3,0xe1,0x41,0xf3,0x65,0xb8,0xd1,0xe8,0xa2,0x8c,0x09,0x8c,0x62,0x8d, +0x0d,0xc4,0x84,0x41,0x18,0xb1,0xd9,0xec,0x08,0x6b,0xcd,0xd9,0xb0,0xdd,0xdc,0x0e, +0x27,0x16,0xe7,0xfa,0x5e,0x34,0x26,0xef,0xa9,0xf7,0xcf,0x93,0xac,0xd3,0xa2,0xb1, +0x78,0xf7,0x2b,0x7a,0x0e,0xdd,0xd5,0xf5,0x3f,0xcc,0xb8,0x71,0x39,0x93,0xae,0x3f, +0xa7,0xaa,0xfd,0x37,0xc3,0x68,0x4c,0x3f,0x16,0xb3,0xc5,0xb6,0xaa,0x0f,0x07,0xde, +0x40,0xff,0xdd,0x0e,0xfa,0xb5,0xce,0x76,0xc5,0xd4,0x6b,0x1d,0x6e,0xbf,0xec,0x36, +0xbb,0x64,0x57,0x11,0x76,0xab,0x5b,0x0e,0x9b,0x93,0x72,0xde,0x5c,0x56,0x37,0x5c, +0x92,0xb3,0xea,0x8f,0xc3,0xe6,0x90,0x1c,0xf3,0xf7,0x70,0x65,0xef,0xc9,0x9f,0xbe, +0x4c,0x3d,0x47,0xd5,0x7b,0xf5,0xe6,0x42,0x70,0x59,0xeb,0x88,0x0d,0x3a,0xff,0x21, +0xb3,0x77,0xd6,0xf5,0x7c,0xad,0xf3,0x1c,0xf5,0xf7,0x92,0xd4,0xcb,0x09,0x73,0x58, +0x9d,0xb9,0xbb,0xe8,0xb4,0xbb,0xf4,0xb3,0x7d,0x3a,0x8d,0x7b,0x2e,0xde,0x25,0x2d, +0x57,0xb6,0x5f,0x76,0xf6,0xed,0xf8,0xca,0x7c,0x2d,0x07,0x7d,0x99,0x2e,0x6a,0x19, +0xaf,0x04,0x4d,0xbe,0x9c,0x07,0x74,0x39,0xfb,0xe5,0x88,0xce,0x7f,0xd1,0xb4,0xba, +0x3e,0x5e,0xf5,0x5c,0x83,0xfe,0xfe,0x6b,0xd9,0xac,0xee,0x5b,0x67,0x3f,0x93,0xf5, +0x5a,0xb7,0xdb,0x2c,0x3b,0xa6,0xf5,0x3e,0x4c,0xa5,0x56,0x5b,0xa5,0x7b,0x74,0x8a, +0x2d,0xea,0xa8,0xb5,0x5a,0xf3,0xd5,0x7a,0x52,0x91,0x7c,0xac,0x75,0xb0,0x75,0x3a, +0xd5,0x66,0x6d,0xcb,0x7e,0xa9,0x9e,0xdb,0xa4,0xb5,0xba,0xb5,0xfa,0xbb,0x4f,0x75, +0x2e,0xb5,0xb3,0xfe,0xbc,0x5d,0x1d,0xf7,0xb5,0xb2,0x5d,0xff,0x6d,0xf4,0x77,0xcb, +0xf5,0xb3,0x15,0x3a,0xcd,0x46,0xd9,0x69,0xbf,0x51,0xd7,0x5d,0xf2,0xcf,0xd8,0xbc, +0x69,0x86,0x24,0xdd,0x71,0xdc,0xad,0xfb,0x75,0xaf,0x3a,0xee,0x40,0x70,0xd0,0x1c, +0x0a,0xf4,0x98,0x85,0x97,0x32,0xd7,0xc3,0x1b,0xa6,0x23,0x6c,0x31,0x17,0xc2,0x06, +0x75,0x59,0xa3,0xb9,0x1a,0x76,0x9a,0xde,0xb0,0x27,0xd3,0x1e,0x36,0xeb,0xcf,0x27, +0xcd,0xf1,0xf0,0xa8,0x3a,0x71,0x3a,0xc7,0xf5,0xb3,0xb3,0x3a,0x4d,0xa7,0xb6,0x7d, +0xc7,0xc3,0xa7,0x5a,0x0f,0x7a,0xb9,0x40,0x63,0x47,0x22,0xbf,0x05,0x8f,0x32,0x51, +0x7d,0x2d,0xe3,0xfc,0xb6,0xd4,0xce,0x29,0xd7,0xff,0xe3,0xfa,0xb8,0x9f,0x86,0xcf, +0xab,0xdc,0x7f,0xd3,0xe3,0xfe,0x96,0x66,0xdb,0xcc,0x1d,0x45,0xef,0x8b,0x7e,0x9d, +0x18,0x09,0x86,0xfc,0x98,0xb6,0x16,0x3d,0xef,0xcf,0xab,0xd3,0xea,0xf3,0x7d,0x9a, +0x85,0x9c,0xd5,0xcf,0x2f,0x9a,0x96,0xa0,0x5d,0xcf,0xb3,0x2e,0xff,0x1c,0x4b,0xe7, +0x9b,0x0b,0xea,0x9d,0x16,0x9d,0xbf,0x4f,0x97,0x33,0x32,0x6d,0x99,0x97,0x4c,0x53, +0xe0,0xee,0x2f,0x6d,0x31,0x1d,0xfa,0xb3,0xeb,0x37,0xbd,0x2a,0x17,0xe6,0x58,0x4f, +0x83,0x69,0xd4,0xf9,0xae,0x04,0x2d,0xba,0xae,0x66,0x75,0xd4,0x79,0xad,0xa3,0xd5, +0x17,0x9d,0xfe,0xac,0x7e,0x7e,0x51,0x97,0xdf,0xee,0x97,0xdf,0x9e,0x62,0x3b,0xce, +0x68,0xfd,0xae,0x49,0xcb,0x7e,0xdd,0x97,0xe9,0x8a,0x4e,0x5f,0xaf,0xde,0x3b,0x24, +0xbb,0xad,0xfa,0x46,0xd9,0x6b,0xf7,0xa8,0xe1,0x0e,0x28,0x7b,0xb4,0x36,0xb7,0x4d, +0x1d,0xb5,0x41,0x6b,0x61,0x35,0x6a,0x9e,0xad,0xea,0xaa,0xaf,0x0a,0xfa,0x1e,0x92, +0xfe,0xab,0xf5,0x73,0xed,0x92,0x2f,0xd4,0x81,0x6e,0xae,0x62,0xff,0x0b,0x75,0x69, +0x5b,0xd4,0x6d,0x3b,0x65,0xb7,0xc6,0x59,0x6e,0xab,0xfe,0xa6,0x46,0x7f,0xef,0xea, +0x83,0xdb,0xf4,0xf7,0xae,0x0c,0x75,0x72,0xcc,0x9e,0x96,0x3a,0x7b,0x52,0xff,0xc6, +0xd4,0xc9,0x09,0xdb,0xa0,0xfb,0xf2,0x8a,0xb4,0x99,0x6e,0x75,0x5d,0xe1,0x33,0x58, +0xe3,0xc7,0xf1,0x42,0x70,0xde,0x34,0xea,0x36,0x5e,0xd4,0xbf,0x39,0x57,0xc2,0xab, +0xe6,0x7a,0xd8,0x9a,0x69,0x8d,0xd1,0x16,0xb6,0x67,0xba,0xc3,0xbe,0xcc,0x50,0x38, +0x92,0x19,0x09,0x07,0x33,0x37,0xd5,0x79,0xdd,0xe1,0xcd,0xcc,0x40,0xa8,0xe7,0x6e, +0xcd,0x5d,0xfd,0xdd,0x40,0xa6,0x27,0xbc,0xa1,0xd3,0x25,0xe7,0x9b,0x9a,0xff,0x86, +0xe9,0xd1,0x69,0x46,0x6b,0x1e,0x9a,0xc9,0x9a,0xef,0x33,0x2f,0x4b,0x70,0xdc,0x4b, +0xdf,0x3e,0x9d,0xf4,0x6d,0xc8,0x09,0xad,0x37,0x65,0xdb,0xa4,0xa3,0xaf,0xf1,0x39, +0x76,0x5f,0x3d,0x5e,0xb9,0xf1,0x2f,0x0b,0x71,0x5f,0xe2,0x09,0x75,0xe2,0x59,0x6d, +0xef,0x5c,0xf4,0xf7,0x5c,0xf7,0x2e,0xd0,0xfd,0x3a,0xd5,0xe2,0xbf,0xdb,0x66,0x48, +0xcf,0xa7,0x5e,0x75,0xda,0x8d,0x7c,0x7f,0xe6,0x74,0xda,0xbd,0xf7,0xba,0x75,0xba, +0x5b,0xfe,0x7a,0x7f,0x7f,0xd4,0x07,0xea,0x5c,0x58,0xf8,0x2e,0x89,0xf8,0x32,0x3b, +0x75,0x9a,0x2e,0xf7,0xae,0x08,0x9d,0xa6,0x5f,0xe7,0xcd,0xad,0xa7,0x7d,0xd6,0xf5, +0x74,0x99,0x1e,0x9d,0xa7,0x37,0xe8,0xd6,0x7f,0xdf,0x28,0x3a,0xad,0xeb,0x77,0x75, +0xde,0xeb,0x8e,0x2f,0x3f,0x98,0x79,0x3b,0xae,0x38,0x17,0xab,0xff,0xce,0x68,0x1b, +0xf9,0x78,0xf6,0xb9,0xea,0x76,0xaf,0xba,0x6c,0x8f,0xaf,0x65,0xed,0xd4,0x5a,0xdb, +0x0e,0xfd,0xff,0xaf,0xf4,0xe7,0x7d,0xde,0x6f,0x2e,0x07,0xf5,0xdf,0x7b,0x12,0x9f, +0xaa,0x1d,0xd5,0x8c,0xc5,0xfc,0x77,0x28,0x9a,0x6b,0x7f,0x6c,0xae,0x1d,0xea,0xcc, +0x64,0xb2,0xbf,0xd5,0xfa,0xb4,0x5f,0xd7,0x7e,0xcd,0x5e,0xd9,0xe7,0xcb,0x73,0x5c, +0x5d,0xd7,0x20,0x8d,0x5a,0xde,0x1b,0xd1,0xfb,0x89,0x6e,0x9b,0x61,0xdd,0xae,0x9b, +0x7e,0x3f,0x74,0x78,0x5f,0xbb,0x6d,0xed,0x57,0xd7,0xe5,0xee,0x01,0x76,0x75,0x8d, +0x71,0x3f,0xd6,0xe4,0x51,0xe6,0x89,0xb6,0x45,0x1f,0x86,0x63,0x99,0x7b,0x35,0xa3, +0x99,0x3b,0x35,0x7a,0x2c,0x8a,0x30,0xaa,0x8e,0xbb,0x1f,0x8e,0x67,0x1e,0xd6,0x4c, +0x98,0x09,0x75,0xd8,0x58,0xa8,0xf5,0x2c,0x9d,0xef,0x61,0xcd,0xe3,0xcc,0x77,0x35, +0xdf,0x65,0x1e,0xd7,0x3c,0xcc,0x8c,0x85,0xf7,0xd4,0x6f,0xa3,0x33,0xcc,0x3f,0xaa, +0xf3,0xdf,0xd3,0xcf,0x27,0x74,0x7d,0xcf,0x8a,0xd7,0xfd,0xbc,0xe7,0x5c,0x5b,0x55, +0xeb,0x72,0xc1,0xf8,0x92,0xac,0xc7,0x2d,0xdc,0x7d,0xf6,0x4b,0xdb,0x7f,0x45,0xda, +0xce,0xfe,0x79,0x14,0x4d,0xd1,0xb8,0xf7,0x1b,0xda,0x16,0xe9,0x5b,0x92,0xef,0x05, +0x1c,0xc9,0x9e,0x67,0xc1,0x60,0x41,0x7f,0xe6,0x74,0x06,0x83,0xec,0x7b,0xc3,0x6e, +0x7b,0x86,0xd5,0x71,0xae,0x1f,0x74,0x70,0xda,0xbb,0xc4,0xe2,0xcb,0x1c,0xf4,0x0c, +0x47,0xf3,0xb8,0xdf,0x0d,0xcd,0xb9,0x9e,0x01,0x9d,0xc7,0xbd,0xe7,0xcc,0x4d,0x3b, +0x98,0x72,0xda,0xdc,0xf2,0x7b,0xd4,0x11,0x1d,0xd2,0x6c,0x9a,0xe5,0x9c,0xd6,0x0d, +0xdd,0x35,0xb1,0x63,0x76,0xbf,0x4c,0x8f,0xb3,0x58,0x36,0x07,0x0a,0x7e,0x5b,0x1b, +0xb5,0x6e,0x73,0x0e,0x2c,0xf6,0x79,0x71,0x03,0xd6,0xfa,0xe5,0xee,0x2f,0x92,0x23, +0x72,0x4c,0xbe,0x55,0xcf,0x5d,0xd6,0xef,0x4d,0x87,0x96,0xf7,0x56,0x62,0x3b,0x73, +0xfb,0x38,0xbb,0x3f,0x73,0xfb,0x31,0xfb,0xb9,0xfb,0xfd,0xdd,0xf0,0xbe,0x99,0x08, +0x1f,0x6b,0xdb,0xea,0x59,0x41,0xbd,0xeb,0xa5,0xfe,0xfc,0xdc,0xdf,0x7f,0xf0,0xb4, +0xe6,0xe9,0x9c,0xf8,0xfb,0xc7,0x6a,0xb2,0x3c,0xd3,0x79,0x1c,0xee,0xdf,0xcf,0x6b, +0x5e,0x28,0xd9,0x7b,0x5e,0x67,0x9b,0x3f,0x7b,0xfd,0xdf,0xad,0xf3,0xa5,0xff,0xb7, +0xaf,0xcf,0x45,0xf7,0x81,0xdd,0xe3,0xba,0xfa,0x1b,0xe0,0xbf,0xa2,0xcf,0xfc,0x97, +0xec,0xfb,0xf2,0x2e,0xfa,0xfb,0xbb,0x7b,0xdd,0x35,0x1a,0xbe,0x03,0x0b,0xf8,0x5d, +0x1a,0xf0,0xf7,0x92,0x76,0xf8,0xba,0xb8,0xab,0xd3,0x35,0xd9,0x7a,0x7f,0xaf,0xe9, +0x37,0x55,0xf7,0x8c,0xf5,0x6f,0xb4,0x5c,0xa7,0xfd,0xf3,0x4c,0x72,0xed,0x86,0xf4, +0xef,0x4a,0x8b,0xfa,0x1b,0xcd,0x93,0xe8,0x5e,0xd7,0x97,0x55,0xd0,0xbf,0xfa,0x32, +0x5f,0xa7,0xd3,0x7a,0x66,0x30,0xa6,0x75,0xba,0xbb,0x7c,0x1f,0xab,0xdc,0x7f,0xad, +0xd2,0xa2,0xdf,0xbf,0xb3,0x55,0xf0,0x0e,0x82,0x63,0xb1,0xe7,0xfb,0x64,0xdd,0xd8, +0x1a,0x3d,0xdf,0x67,0x84,0xef,0x48,0xec,0xbb,0x72,0xcb,0xef,0x93,0xde,0xe8,0x99, +0x95,0x57,0xfd,0xfe,0x6a,0xa8,0xfa,0x77,0xe5,0x1c,0x8f,0xae,0x91,0x5c,0x8e,0x9e, +0xdb,0x94,0xfe,0x1e,0xd8,0xd1,0xe8,0xde,0xd7,0x89,0x4c,0xf5,0x8c,0x21,0x7e,0x11, +0xdd,0xc7,0xfa,0x9d,0xef,0x87,0x78,0xa0,0x2e,0xbe,0xcb,0x77,0x73,0x49,0xfa,0xaf, +0xf0,0x59,0x34,0xdd,0xd1,0x3b,0xf6,0xbe,0x95,0x93,0x55,0x76,0x2e,0xe5,0xde,0xb9, +0xdc,0x18,0x3d,0xb7,0xf6,0x6a,0xf4,0x8c,0xc7,0x1b,0xd1,0x33,0x1e,0x6f,0x2d,0xf1, +0xef,0xc1,0x48,0xfe,0x39,0xba,0xed,0x91,0xdb,0x92,0xef,0xa6,0x3e,0xb6,0x44,0xde, +0x91,0x53,0xa7,0x7f,0xc7,0xea,0xfd,0x31,0xba,0x16,0x8d,0xa3,0x1a,0x92,0x52,0xc6, +0x4a,0x8c,0xa9,0xeb,0x1e,0x99,0xec,0x3d,0xfe,0xcf,0xab,0xa2,0x4e,0xe7,0xc6,0xca, +0x3d,0xc9,0x8e,0x27,0xc9,0xbc,0xde,0x7d,0x11,0x6f,0xb8,0xff,0xa6,0x31,0xac,0xe7, +0x63,0x87,0x7f,0x56,0x61,0x63,0xf6,0x79,0xd6,0x4b,0xe4,0x1d,0xa3,0xb9,0xf7,0xd2, +0x9f,0x89,0x5c,0xe9,0x68,0xce,0x3f,0xe7,0x3b,0x4b,0x57,0x91,0x67,0x7d,0x67,0x19, +0x2a,0xa1,0xad,0x59,0x9c,0xb6,0xfc,0xfa,0xae,0xf9,0xe7,0x82,0x67,0xcb,0xd2,0x90, +0x2f,0xdf,0x29,0x7b,0x64,0xc9,0xbe,0xb3,0xe1,0xb8,0xcd,0xbe,0xcb,0x75,0xea,0xfa, +0x6e,0x69,0xcf,0x19,0x76,0xcf,0x34,0x19,0x57,0xd7,0x3d,0x56,0xd7,0xb9,0xeb,0x65, +0x2f,0xaa,0xc6,0x75,0x8f,0xa3,0xb1,0xc0,0x5c,0xa7,0x7b,0xfd,0xfd,0x97,0x1d,0x2b, +0x39,0x96,0xba,0x8f,0xdd,0x3d,0x4f,0x2d,0xdb,0x66,0x76,0x6d,0xae,0x93,0x6f,0xf8, +0x7b,0xfb,0xde,0x84,0x1c,0x97,0xb8,0xe7,0x3a,0xe6,0xf1,0x3c,0xf5,0x51,0x75,0xc9, +0x83,0x68,0x0c,0xec,0x77,0x55,0xf2,0xdc,0xa6,0x17,0xd1,0x58,0x3a,0x75,0x9d,0x1b, +0x63,0x92,0xc1,0x75,0x6f,0xa6,0xff,0x66,0x7a,0x5e,0xe1,0xa3,0xe8,0x9a,0x46,0xfa, +0xe7,0x59,0x67,0xdf,0x67,0xda,0xe2,0xeb,0x37,0xbc,0xcf,0x74,0x69,0xe6,0x98,0x1e, +0xb7,0xd3,0xaf,0xe4,0xb9,0x5c,0xbf,0xc4,0x78,0xf4,0x6c,0x93,0xc9,0x62,0xcf,0x0f, +0xae,0x80,0xeb,0x26,0xa3,0xef,0xf5,0x18,0xd7,0xea,0xf0,0x5f,0x31,0xff,0x4d,0xe3, +0x65,0x34,0x16,0xd3,0xf5,0x67,0x95,0xf8,0xbd,0x91,0x21,0xff,0x1c,0x10,0xd7,0xf6, +0xbb,0xa8,0xe7,0xd4,0x59,0xf5,0xe2,0x89,0xd7,0xfa,0x5d,0xf6,0x4b,0x25,0x27,0xf2, +0x9e,0xbb,0x9a,0x7f,0xbe,0xfa,0xc8,0xfc,0x3c,0xe7,0xea,0x74,0xbe,0xbf,0xf3,0x59, +0x55,0xb4,0x5f,0x1d,0xcf,0x73,0xae,0xd3,0xb2,0xa9,0xeb,0x32,0xa3,0xf8,0x05,0xff, +0xcd,0xdb,0x7f,0x33,0x7f,0xbf,0x7c,0x9b,0x79,0xde,0x63,0x36,0xfb,0xf4,0x7c,0xbb, +0xa1,0x5e,0x6c,0xf1,0xd7,0xc3,0x4e,0x15,0x7d,0x27,0x14,0x79,0x95,0xbe,0xd6,0x53, +0x72,0x2e,0xef,0xb8,0xeb,0xd2,0xed,0xaf,0x47,0xde,0x9e,0xe7,0xbd,0x4a,0xee,0x99, +0x9c,0xd9,0xb6,0xeb,0xb3,0xaa,0xe8,0x93,0x88,0xdf,0x0f,0x96,0x1b,0x57,0xf7,0xa0, +0x94,0x77,0x4e,0x00,0xfe,0x9b,0xa7,0xff,0x8a,0x39,0xf1,0x69,0xb6,0x8f,0xcc,0xd7, +0x13,0xe7,0xd7,0x47,0x36,0xe8,0xcf,0xd1,0x2e,0x7f,0xbe,0x66,0xdd,0xd8,0x18,0xf5, +0x11,0x1c,0xc6,0x69,0x33,0xbc,0xc3,0xb5,0x3e,0xea,0xd7,0xb9,0xe2,0xfb,0x75,0x3a, +0x5f,0xf1,0x3d,0x39,0xf7,0xb2,0xd7,0xe8,0xdc,0x7d,0x99,0x51,0x7f,0x44,0x15,0x3d, +0xb3,0x29,0x7c,0x19,0x8d,0x37,0x71,0x7f,0x77,0x1f,0x9a,0x37,0xfa,0x5e,0x09,0xfc, +0x57,0x75,0xfe,0x2b,0xfe,0x9d,0x5d,0xc0,0x71,0xef,0xd2,0x17,0xf5,0xa9,0xb6,0x46, +0x7d,0xaa,0x97,0xa2,0xfe,0xd4,0xb3,0x51,0x5f,0x6a,0xdd,0x92,0x6f,0x5b,0x1f,0x8b, +0x7c,0xff,0x6d,0xd4,0x4f,0xdc,0x1c,0xf5,0x1d,0x77,0x2d,0xe0,0x38,0xc8,0xc8,0x73, +0x99,0xec,0x33,0xd6,0x27,0xab,0xef,0x99,0x9c,0xfe,0x39,0x26,0x93,0xd1,0x7d,0x61, +0xae,0x5f,0x8e,0x31,0xc4,0xf8,0x6f,0x09,0xfa,0xaf,0x28,0xb9,0xf7,0xe5,0x65,0x9f, +0xd1,0x73,0xbf,0x0c,0xd7,0xa3,0xa7,0xc6,0x9f,0x74,0xc6,0xc6,0xbb,0x34,0x9b,0xa9, +0xb1,0x30,0x8e,0x7a,0x7b,0x2a,0x36,0x0e,0xa5,0x90,0x74,0x6d,0xf2,0xa3,0x32,0xdb, +0x32,0x72,0xef,0x31,0xcc,0xd2,0x92,0x1f,0x7f,0xd3,0x1a,0x1b,0x23,0xd3,0xbf,0xe0, +0xdf,0xa7,0xbb,0xf9,0x6b,0x73,0xd9,0xb1,0x25,0xb9,0x77,0x81,0x55,0xdf,0x33,0xd6, +0x5f,0xe6,0x9f,0x43,0x97,0x6b,0x37,0xe0,0x02,0xfc,0xb7,0xb8,0xfe,0x7b,0x18,0x4e, +0x44,0xed,0x9d,0x97,0x55,0x30,0xa6,0xbe,0xf0,0xf9,0x65,0xf7,0x69,0xeb,0xcc,0x38, +0x6e,0xce,0xed,0x97,0xf8,0x3b,0x5c,0x27,0xab,0xfe,0x5d,0x39,0x05,0xe3,0x4d,0x18, +0x5b,0x07,0x55,0x38,0xfe,0x39,0x7b,0x0d,0xe8,0x71,0x54,0x67,0xa8,0xbe,0x76,0x51, +0xee,0xfe,0xca,0xa9,0x67,0xa0,0x65,0xc7,0x2e,0x16,0x7f,0x46,0xed,0x52,0x22,0xf7, +0x1c,0xdd,0xf1,0xe8,0x79,0xbc,0xc9,0x77,0x53,0xbf,0x58,0x22,0xef,0xf4,0x7a,0x9e, +0xbf,0x37,0x6c,0x42,0x5d,0x47,0xbf,0x04,0x2c,0xdd,0xfb,0x3f,0xdc,0xbd,0x97,0xe3, +0xd1,0xb5,0xa2,0xa5,0xf3,0x2e,0xbe,0xc2,0xf7,0xd2,0x7f,0x97,0x7b,0xce,0x50,0xe4, +0x95,0x6c,0xdd,0x72,0x2c,0x73,0xbf,0xe8,0xf3,0xbe,0xd3,0xb6,0xc9,0xef,0x9a,0xd9, +0x96,0x71,0xdf,0xb7,0x41,0xb3,0xeb,0x9b,0xc8,0x97,0x23,0x3b,0x2e,0x2e,0x57,0xc6, +0x97,0x4b,0xf6,0xbd,0x0d,0x09,0xcf,0xf9,0xeb,0xbb,0xb4,0x5f,0xe1,0xf5,0xf2,0x5f, +0xb1,0x67,0xb7,0x4e,0x98,0xaa,0xbc,0x76,0x0e,0x65,0xa8,0xcf,0xbd,0x48,0x78,0x2e, +0xfb,0xcc,0x61,0xce,0x59,0x78,0x33,0xfd,0x57,0x74,0x8c,0x58,0xbe,0x8e,0xc3,0xfb, +0x4c,0x5f,0x13,0xcf,0x51,0x9f,0x03,0xfc,0x37,0x6f,0x46,0xb3,0xcf,0x68,0x0b,0xb3, +0xcf,0x68,0x7b,0x5a,0x25,0xf7,0x42,0xe1,0xb9,0xa9,0x76,0xeb,0xa3,0xfc,0xf3,0xd5, +0x39,0x07,0x01,0xff,0x2d,0xd6,0xf3,0xfe,0xb3,0xcf,0x38,0x9a,0xc8,0xbf,0x13,0xfa, +0x05,0x5e,0x5a,0xf0,0x7b,0xc0,0x72,0xef,0x90,0x70,0x8e,0xcb,0xbd,0x07,0x8c,0x7e, +0x08,0xc0,0x7f,0xd5,0xfa,0xfe,0xf3,0x6c,0x5f,0xc2,0x98,0xef,0x33,0x98,0x88,0xfa, +0x3e,0xbf,0xe7,0x1a,0x63,0xd1,0x77,0xb8,0x3e,0x4d,0xf4,0xeb,0x8c,0xbd,0xf6,0xef, +0xc9,0x01,0xfc,0xf7,0x3a,0xfb,0xaf,0xb4,0x71,0x6f,0xb9,0xb1,0xbd,0xd9,0xb1,0x8b, +0xdf,0x57,0xd7,0xfd,0x5a,0xaf,0x30,0x46,0x2e,0xfe,0x6e,0x6a,0x37,0x56,0x2e,0x72, +0x5b,0x86,0x71,0x90,0x80,0xff,0xde,0x64,0xff,0x95,0x3e,0x8e,0x2e,0xdb,0xce,0xce, +0xfb,0x32,0x36,0x16,0x26,0xee,0xcd,0x99,0x79,0x51,0xc2,0x98,0xed,0xe2,0x4c,0xc6, +0xd6,0x37,0x31,0x35,0xfe,0x26,0x36,0x46,0x86,0x71,0xc0,0x80,0xff,0xf0,0x1f,0x00, +0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff, +0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f, +0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00, +0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00, +0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8, +0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00, +0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f, +0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00, +0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87, +0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03, +0x00,0xfc,0xc7,0xfe,0x07,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00, +0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0, +0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03, +0x00,0xc0,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f, +0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07, +0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0, +0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xd8, +0xff,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00, +0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80, +0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f, +0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0, +0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1, +0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00, +0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03, +0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00, +0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f, +0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0xc0,0x7f,0xf8,0x0f, +0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0, +0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1, +0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00, +0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00, +0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0x96,0xb6,0xff,0x86,0xf1, +0x1f,0x00,0x50,0xff,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01, +0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00, +0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f, +0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00, +0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87, +0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03, +0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xec,0x7f,0x00,0xc0, +0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07, +0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00, +0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0xf8,0x0f, +0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07, +0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0, +0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0, +0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x8f,0xfd,0x0f,0x00,0xf8,0x0f,0x00,0x00, +0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f, +0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00, +0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0, +0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1, +0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00, +0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc, +0x87,0xff,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff, +0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00, +0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0, +0x1f,0x00,0x00,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0, +0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1, +0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00, +0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc, +0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00, +0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80, +0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x80,0xff,0xf0, +0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00, +0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe, +0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff, +0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0x00,0x00,0xfc, +0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00, +0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80, +0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff, +0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff, +0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00, +0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f, +0xfe,0x03,0x00,0xfc,0xc7,0xfe,0x07,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0, +0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01, +0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00, +0xfe,0x03,0x00,0xc0,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f,0xfc,0x07,0x00, +0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f,0x00,0xe0,0x3f, +0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80,0xff,0xf0,0x1f, +0x00,0xe0,0x3f,0xfc,0x07,0x00,0xf8,0x0f,0xff,0x01,0x00,0xfe,0xc3,0x7f,0x00,0x80, +0xff,0xd8,0xff,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0, +0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0x00,0xfc,0x07, +0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00, +0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f, +0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00, +0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87, +0xff,0x00,0x00,0xff,0xe1,0x3f,0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0x00,0x00, +0xfe,0x03,0x00,0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f, +0x00,0x00,0xfc,0x07,0x00,0x80,0xff,0x00,0x00,0xf0,0x1f,0x00,0x00,0xfe,0x03,0x00, +0xc0,0x7f,0x00,0x00,0xf8,0x0f,0x00,0x00,0xff,0x01,0x00,0xe0,0x3f,0x00,0xc0,0x7f, +0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00,0xff,0xe1,0x3f, +0x00,0xc0,0x7f,0xf8,0x0f,0x00,0xf0,0x1f,0xfe,0x03,0x00,0xfc,0x87,0xff,0x00,0x00, +0xff,0x95,0xe0,0xbf,0x11,0x19,0x31,0x00,0x00,0x95,0xa3,0x82,0xfe,0x0b,0x74,0xfd, +0x00,0x00,0x95,0x62,0x51,0xfd,0xf7,0x38,0x11,0xf6,0x3f,0x00,0x54,0xd6,0x7f,0x8f, +0x6d,0xdc,0x49,0xe5,0xf5,0xdf,0xa3,0x44,0xa8,0x7b,0x03,0x40,0x65,0x79,0x64,0xe3, +0x4e,0x2a,0xaf,0xff,0x26,0x12,0xb9,0x1d,0xdc,0x36,0x00,0x00,0x15,0x43,0x26,0x6c, +0xdc,0x49,0xf8,0x0f,0x00,0xf0,0x5f,0x39,0xf2,0x30,0x91,0xdb,0xe2,0xd6,0x0f,0x00, +0x50,0x29,0x1e,0xda,0xb8,0x93,0xca,0xeb,0xbf,0xf1,0x44,0x86,0x83,0x61,0x03,0x00, +0x50,0x31,0x64,0xdc,0xc6,0x9d,0x54,0x5e,0xff,0x8d,0x25,0x32,0x2c,0x6e,0xfd,0x00, +0x00,0x95,0x62,0xcc,0xc6,0x9d,0x54,0x5e,0xff,0x3d,0x48,0x64,0x48,0x86,0x0c,0x00, +0x40,0xe5,0x78,0x60,0xe3,0x4e,0x2a,0xaf,0xff,0xee,0x27,0xc2,0xbe,0x07,0x80,0xca, +0x72,0xdf,0xc6,0x9d,0x54,0x5e,0xff,0xdd,0x4b,0x64,0x50,0x06,0x0d,0x00,0x40,0xe5, +0xb8,0x67,0xe3,0x4e,0x2a,0xaf,0xff,0xee,0x26,0xa2,0xeb,0xb7,0x00,0x00,0x95,0xe3, +0xae,0x8d,0x3b,0xa9,0xbc,0xfe,0xbb,0x93,0xc8,0x80,0x0c,0x18,0x00,0x80,0xca,0x71, +0xc7,0xc6,0x9d,0x54,0x5e,0xff,0x8d,0x24,0xa2,0xeb,0xb7,0x00,0x00,0x95,0x63,0xc4, +0xc6,0x9d,0x54,0x5e,0xff,0xdd,0x4e,0xa4,0x5f,0xfa,0x0d,0x00,0x40,0xe5,0xb8,0x6d, +0xe3,0x4e,0x5a,0x64,0xff,0x59,0x00,0x80,0xca,0x31,0x6c,0x87,0x65,0x2a,0xe5,0xf5, +0xdf,0x60,0x22,0xb7,0xe4,0x96,0x05,0x00,0xa8,0x1c,0xbe,0x1f,0x24,0x9f,0xf2,0xfa, +0x6f,0x20,0x11,0xf6,0x3d,0x00,0x54,0x16,0x7f,0x1d,0x30,0x6f,0xa4,0x72,0xfb,0xaf, +0x3f,0x96,0x3e,0xe9,0xb3,0x00,0x00,0x95,0xc3,0xb7,0x83,0xa3,0x74,0x95,0xd9,0x7f, +0xde,0x79,0xf1,0xb0,0xff,0x01,0xa0,0xd2,0x44,0xb9,0x5a,0xf6,0xfa,0xdf,0xcd,0x64, +0x2c,0x00,0x40,0x85,0x89,0x72,0xae,0xec,0xfd,0x1f,0x3d,0x89,0xb0,0xef,0x01,0xa0, +0x72,0x24,0x7d,0x54,0x57,0x66,0xff,0x2d,0xd3,0x75,0x74,0xc7,0xd2,0x23,0xbd,0xd2, +0x6b,0x01,0x00,0x16,0x9f,0x1e,0x1b,0xb7,0x51,0x67,0xd9,0xed,0xb7,0x4c,0x7d,0xd7, +0x99,0x48,0x37,0xc7,0x01,0x00,0x2a,0x80,0x1a,0xcf,0xc6,0x5d,0x74,0x69,0x11,0xfc, +0xd7,0x2f,0x37,0x0a,0xd2,0xe5,0xea,0xa0,0x00,0x00,0x8b,0x48,0x97,0x2d,0x34,0xd1, +0xa9,0x45,0xf0,0x9f,0x6b,0x01,0x77,0x14,0xe4,0x86,0x74,0x73,0x3c,0x00,0x60,0x91, +0xe8,0x56,0xf7,0x15,0x5a,0xe8,0xc2,0xa2,0xd8,0x6f,0x99,0x0c,0xe9,0xba,0xda,0xa6, +0xa5,0x43,0x7d,0xdc,0xcd,0xb1,0x01,0x80,0x32,0xd2,0x2d,0x5d,0xce,0x3f,0xb6,0xd0, +0x3f,0x2d,0x8b,0x64,0x3f,0x97,0x5b,0xd2,0x4a,0x08,0x21,0x55,0x93,0x93,0x8b,0xe8, +0xbf,0x65,0xd2,0x2d,0xd7,0x08,0x21,0xa4,0x2a,0x72,0x76,0x51,0xed,0xe7,0xd2,0x21, +0x17,0x09,0x21,0xa4,0xe2,0x39,0xbd,0xe8,0xf6,0x73,0xe9,0x92,0x0b,0x52,0x4f,0x08, +0x21,0x15,0xcb,0x29,0x39,0x22,0xb5,0x15,0xf1,0x9f,0x4b,0xb3,0x1c,0x27,0x84,0x90, +0x8a,0xe4,0x88,0x1c,0xd2,0x2c,0xab,0x60,0xda,0xe5,0x9c,0x1c,0x56,0x03,0x13,0x42, +0xc8,0xe2,0xc5,0x99,0xef,0xb0,0xcf,0xb2,0x8a,0xa7,0x5b,0xae,0x68,0x5d,0xf4,0x98, +0xec,0x23,0x84,0x90,0xb2,0xe5,0x80,0x1c,0xf4,0xde,0x3b,0x92,0xcf,0x32,0x42,0x08, +0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21, +0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84, +0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x10,0x42,0x08,0x21,0x84,0x54, +0x79,0xfe,0x3f,0x57,0x9d,0xaa,0x31}; diff --git a/source/ngc/unzip.cpp b/source/ngc/unzip.cpp index cd4db848..7ebcf2d7 100644 --- a/source/ngc/unzip.cpp +++ b/source/ngc/unzip.cpp @@ -1,33 +1,18 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * Michniewski 2008 - * Tantric September 2008 - * - * unzip.cpp + * Nintendo Gamecube Unzip - borrowed from the GPP * - * File unzip routines - ***************************************************************************/ - + * softdev July 2006 + ****************************************************************************/ #include #include #include #include #include - -extern "C" { -#include "../sz/7zCrc.h" -#include "../sz/7zIn.h" -#include "../sz/7zExtract.h" -} - -#include "snes9xGX.h" #include "dvd.h" -#include "smbop.h" -#include "fileop.h" #include "video.h" -#include "menudraw.h" +#include "ftfont.h" #include "unzip.h" /* @@ -44,25 +29,25 @@ extern "C" { u32 FLIP32 (u32 b) { - unsigned int c; + unsigned int c; - c = (b & 0xff000000) >> 24; - c |= (b & 0xff0000) >> 8; - c |= (b & 0xff00) << 8; - c |= (b & 0xff) << 24; + c = (b & 0xff000000) >> 24; + c |= (b & 0xff0000) >> 8; + c |= (b & 0xff00) << 8; + c |= (b & 0xff) << 24; - return c; + return c; } u16 FLIP16 (u16 b) { - u16 c; + u16 c; - c = (b & 0xff00) >> 8; - c |= (b & 0xff) << 8; + c = (b & 0xff00) >> 8; + c |= (b & 0xff) << 8; - return c; + return c; } /**************************************************************************** @@ -73,487 +58,127 @@ FLIP16 (u16 b) int IsZipFile (char *buffer) { - unsigned int *check; + unsigned int *check; - check = (unsigned int *) buffer; + check = (unsigned int *) buffer; - if (check[0] == PKZIPID) - return 1; + if (check[0] == PKZIPID) + return 1; - return 0; + return 0; } -/***************************************************************************** -* UnZipBuffer -* -* It should be noted that there is a limit of 5MB total size for any ROM -******************************************************************************/ - + /***************************************************************************** + * unzip + * + * It should be noted that there is a limit of 5MB total size for any ROM + ******************************************************************************/ int -UnZipBuffer (unsigned char *outbuffer, int method) +UnZipBuffer (unsigned char *outbuffer, u64 discoffset, short where, FILE* filehandle) { - PKZIPHEADER pkzip; - int zipoffset = 0; - int zipchunk = 0; - char out[ZIPCHUNK]; - z_stream zs; - int res; - int bufferoffset = 0; - int readoffset = 0; - int have = 0; - char readbuffer[ZIPCHUNK]; - u64 discoffset = 0; - - // Read Zip Header - switch (method) - { - case METHOD_SD: - case METHOD_USB: - fseek(fatfile, 0, SEEK_SET); - fread (readbuffer, 1, ZIPCHUNK, fatfile); - break; - - case METHOD_DVD: - discoffset = dvddir; - dvd_read (readbuffer, ZIPCHUNK, discoffset); - break; - - case METHOD_SMB: - SMB_ReadFile(readbuffer, ZIPCHUNK, 0, smbfile); - break; - } + PKZIPHEADER pkzip; + int zipoffset = 0; + int zipchunk = 0; + char out[ZIPCHUNK]; + z_stream zs; + int res; + int bufferoffset = 0; + int have = 0; + char readbuffer[2048]; + char msg[128]; + + /*** Read Zip Header ***/ + switch (where) { + case 0: // SD Card + fseek(filehandle, 0, SEEK_SET); + fread (readbuffer, 1, 2048, filehandle); break; + case 1: // DVD + dvd_read (readbuffer, 2048, discoffset); break; + } /*** Copy PKZip header to local, used as info ***/ - memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); - - pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); + memcpy (&pkzip, readbuffer, sizeof (PKZIPHEADER)); - ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize); + pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); + + sprintf (msg, "Unzipping %d bytes ... Wait", + pkzip.uncompressedSize); + ShowAction (msg); /*** Prepare the zip stream ***/ - memset (&zs, 0, sizeof (z_stream)); - zs.zalloc = Z_NULL; - zs.zfree = Z_NULL; - zs.opaque = Z_NULL; - zs.avail_in = 0; - zs.next_in = Z_NULL; - res = inflateInit2 (&zs, -MAX_WBITS); + memset (&zs, 0, sizeof (z_stream)); + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + zs.avail_in = 0; + zs.next_in = Z_NULL; + res = inflateInit2 (&zs, -MAX_WBITS); - if (res != Z_OK) - return 0; + if (res != Z_OK) + return 0; /*** Set ZipChunk for first pass ***/ - zipoffset = - (sizeof (PKZIPHEADER) + FLIP16 (pkzip.filenameLength) + - FLIP16 (pkzip.extraDataLength)); - zipchunk = ZIPCHUNK - zipoffset; + zipoffset = + (sizeof (PKZIPHEADER) + FLIP16 (pkzip.filenameLength) + + FLIP16 (pkzip.extraDataLength)); + zipchunk = ZIPCHUNK - zipoffset; /*** Now do it! ***/ - do - { - zs.avail_in = zipchunk; - zs.next_in = (Bytef *) & readbuffer[zipoffset]; + do + { + zs.avail_in = zipchunk; + zs.next_in = (Bytef *) & readbuffer[zipoffset]; /*** Now inflate until input buffer is exhausted ***/ - do - { - zs.avail_out = ZIPCHUNK; - zs.next_out = (Bytef *) & out; - - res = inflate (&zs, Z_NO_FLUSH); - - if (res == Z_MEM_ERROR) - { - inflateEnd (&zs); - return 0; - } - - have = ZIPCHUNK - zs.avail_out; - if (have) - { - /*** Copy to normal block buffer ***/ - memcpy (&outbuffer[bufferoffset], &out, have); - bufferoffset += have; - } - } - while (zs.avail_out == 0); - - // Readup the next 2k block - zipoffset = 0; - zipchunk = ZIPCHUNK; - - switch (method) - { - case METHOD_SD: - case METHOD_USB: - fread (readbuffer, 1, ZIPCHUNK, fatfile); - break; - - case METHOD_DVD: - readoffset += ZIPCHUNK; - dvd_read (readbuffer, ZIPCHUNK, discoffset+readoffset); - break; - - case METHOD_SMB: - readoffset += ZIPCHUNK; - SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile); - break; - } - ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize); - } - while (res != Z_STREAM_END); - - inflateEnd (&zs); - - if (res == Z_STREAM_END) - { - if (pkzip.uncompressedSize == (u32) bufferoffset) - return bufferoffset; - else - return pkzip.uncompressedSize; - } - - return 0; -} - -/**************************************************************************** -* GetFirstZipFilename -* -* Returns the filename of the first file in the zipped archive -* The idea here is to do the least amount of work required -***************************************************************************/ - -char * -GetFirstZipFilename (int method) -{ - char * firstFilename = NULL; - char tempbuffer[ZIPCHUNK]; - - // read start of ZIP - switch (method) + do { - case METHOD_SD: // SD Card - case METHOD_USB: // USB - LoadFATFile (tempbuffer, ZIPCHUNK); - break; - - case METHOD_DVD: // DVD - LoadDVDFile ((unsigned char *)tempbuffer, ZIPCHUNK); - break; - - case METHOD_SMB: // From SMB - LoadSMBFile (tempbuffer, ZIPCHUNK); - break; - } - - tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) - int namelength = tempbuffer[26]; // filename length starts 26 bytes in - - firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in - firstFilename[namelength] = 0; // truncate at filename length - - return firstFilename; -} - -/**************************************************************************** -* 7z functions -***************************************************************************/ + zs.avail_out = ZIPCHUNK; + zs.next_out = (Bytef *) & out; -typedef struct _SzFileInStream -{ - ISzInStream InStream; - u64 offset; // offset of the file - unsigned int len; // length of the file - u64 pos; // current position of the file pointer -} SzFileInStream; - -// 7zip error list -char szerrormsg[][30] = { - "7z: Data error", - "7z: Out of memory", - "7z: CRC Error", - "7z: Not implemented", - "7z: Fail", - "7z: Archive error", - "7z: Dictionary too large", -}; - -SZ_RESULT SzRes; - -SzFileInStream SzArchiveStream; -CArchiveDatabaseEx SzDb; -ISzAlloc SzAllocImp; -ISzAlloc SzAllocTempImp; -UInt32 SzBlockIndex = 0xFFFFFFFF; -size_t SzBufferSize; -size_t SzOffset; -size_t SzOutSizeProcessed; -CFileItem *SzF; - -char sz_buffer[2048]; -int szMethod = 0; - -/**************************************************************************** -* Is7ZipFile -* -* Returns 1 when 7z signature is found -****************************************************************************/ -int -Is7ZipFile (char *buffer) -{ - unsigned int *check; - check = (unsigned int *) buffer; - - // 7z signature - static Byte Signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; - - int i; - for(i = 0; i < 6; i++) - if(buffer[i] != Signature[i]) - return 0; - - return 1; // 7z archive found -} - -// display an error message -void SzDisplayError(SZ_RESULT res) -{ - WaitPrompt(szerrormsg[(res - 1)]); -} + res = inflate (&zs, Z_NO_FLUSH); -// function used by the 7zip SDK to read data from SD/USB/DVD/SMB + if (res == Z_MEM_ERROR) + { + inflateEnd (&zs); + return 0; + } -SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize) -{ - // the void* object is a SzFileInStream - SzFileInStream *s = (SzFileInStream *) object; - - // calculate offset - u64 offset = (u64) (s->offset + s->pos); - - if (maxRequiredSize > 2048) - maxRequiredSize = 2048; - - // read data - switch (szMethod) - { - case METHOD_SD: - case METHOD_USB: - fseek(fatfile, offset, SEEK_SET); - fread(sz_buffer, 1, maxRequiredSize, fatfile); - break; - case METHOD_DVD: - dvd_safe_read(sz_buffer, maxRequiredSize, offset); - break; - case METHOD_SMB: - SMB_ReadFile(sz_buffer, maxRequiredSize, offset, smbfile); - break; - } - - *buffer = sz_buffer; - *processedSize = maxRequiredSize; - s->pos += *processedSize; - - if(maxRequiredSize > 1024) // only show progress for large reads - // this isn't quite right, but oh well - ShowProgress ((char *)"Loading...", s->pos, filelist[selection].length); - - return SZ_OK; -} - -// function used by the 7zip SDK to change the filepointer -SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) -{ - // the void* object is a SzFileInStream - SzFileInStream *s = (SzFileInStream *) object; - - // check if the 7z SDK wants to move the pointer to somewhere after the EOF - if (pos >= s->len) - { - WaitPrompt((char *) "7z: Error - attempt to read after EOF!"); - return SZE_FAIL; - } - - // save new position and return - s->pos = pos; - return SZ_OK; -} - -/**************************************************************************** -* SzParse -* -* Opens a 7z file, and parses it -* Right now doesn't parse 7z, since we'll always use the first file -* But it could parse the entire 7z for full browsing capability -***************************************************************************/ - -int SzParse(char * filepath, int method) -{ - int nbfiles = 0; - - // save the offset and the length of this file inside the archive stream structure - SzArchiveStream.offset = filelist[selection].offset; - SzArchiveStream.len = filelist[selection].length; - SzArchiveStream.pos = 0; - - // open file - switch (method) - { - case METHOD_SD: - case METHOD_USB: - fatfile = fopen (filepath, "rb"); - if(!fatfile) - return 0; - break; - case METHOD_SMB: - smbfile = OpenSMBFile(filepath); - if(!smbfile) - return 0; - break; - } - - // set szMethod to current chosen load method - szMethod = method; - - // set handler functions for reading data from FAT/SMB/DVD - SzArchiveStream.InStream.Read = SzFileReadImp; - SzArchiveStream.InStream.Seek = SzFileSeekImp; - - // set default 7Zip SDK handlers for allocation and freeing memory - SzAllocImp.Alloc = SzAlloc; - SzAllocImp.Free = SzFree; - SzAllocTempImp.Alloc = SzAllocTemp; - SzAllocTempImp.Free = SzFreeTemp; - - // prepare CRC and 7Zip database structures - InitCrcTable(); - SzArDbExInit(&SzDb); - - // open the archive - SzRes = SzArchiveOpen(&SzArchiveStream.InStream, &SzDb, &SzAllocImp, - &SzAllocTempImp); - - if (SzRes != SZ_OK) - { - SzDisplayError(SzRes); - // free memory used by the 7z SDK - SzClose(); - } - else // archive opened successfully - { - if(SzDb.Database.NumFiles > 0) - { - // Parses the 7z into a full file listing - - // erase all previous entries - memset(&filelist, 0, sizeof(FILEENTRIES) * MAXFILES); - - // add '..' folder in case the user wants exit the 7z - strncpy(filelist[0].displayname, "..", 2); - filelist[0].flags = 1; - filelist[0].offset = dvddir; - filelist[0].length = dvddirlength; - - // get contents and parse them into file list structure - unsigned int SzI, SzJ; - SzJ = 1; - for (SzI = 0; SzI < SzDb.Database.NumFiles; SzI++) - { - SzF = SzDb.Database.Files + SzI; - - // skip directories - if (SzF->IsDirectory) - continue; - - // do not exceed MAXFILES to avoid possible buffer overflows - if (SzJ == (MAXFILES - 1)) - break; - - // parse information about this file to the dvd file list structure - strncpy(filelist[SzJ].filename, SzF->Name, MAXJOLIET); // copy joliet name (useless...) - filelist[SzJ].filename[MAXJOLIET] = 0; // terminate string - strncpy(filelist[SzJ].displayname, SzF->Name, MAXDISPLAY+1); // crop name for display - filelist[SzJ].length = SzF->Size; // filesize - filelist[SzJ].offset = SzI; // the extraction function identifies the file with this number - filelist[SzJ].flags = 0; // only files will be displayed (-> no flags) - SzJ++; - } + have = ZIPCHUNK - zs.avail_out; + if (have) + { + /*** Copy to normal block buffer ***/ + memcpy (&outbuffer[bufferoffset], &out, have); + bufferoffset += have; + } - // update maxfiles and select the first entry - offset = selection = 0; - nbfiles = SzJ; - } - else - { - SzArDbExFree(&SzDb, SzAllocImp.Free); - } } + while (zs.avail_out == 0); + + /*** Readup the next 2k block ***/ + zipoffset = 0; + zipchunk = ZIPCHUNK; + + switch (where) { + case 0: // SD Card + fread (readbuffer, 1, 2048, filehandle); break; + case 1: // DVD + discoffset += 2048; + dvd_read (readbuffer, 2048, discoffset); break; + } + + } + while (res != Z_STREAM_END); + + inflateEnd (&zs); + + if (res == Z_STREAM_END) + { + if (pkzip.uncompressedSize == (u32) bufferoffset) + return bufferoffset; + else + return pkzip.uncompressedSize; + } + + return 0; - // close file - switch (method) - { - case METHOD_SD: - case METHOD_USB: - fclose(fatfile); - break; - case METHOD_SMB: - SMB_CloseFile (smbfile); - break; - } - return nbfiles; -} - -/**************************************************************************** -* SzClose -* -* Closes a 7z file -***************************************************************************/ - -void SzClose() -{ - if(SzDb.Database.NumFiles > 0) - SzArDbExFree(&SzDb, SzAllocImp.Free); -} - -/**************************************************************************** -* SzExtractFile -* -* Extracts the given file # into the buffer specified -* Must parse the 7z BEFORE running this function -***************************************************************************/ - -int SzExtractFile(int i, unsigned char *buffer) -{ - // prepare some variables - SzBlockIndex = 0xFFFFFFFF; - SzOffset = 0; - - // Unzip the file - - SzRes = SzExtract2( - &SzArchiveStream.InStream, - &SzDb, - i, // index of file - &SzBlockIndex, // index of solid block - &buffer, - &SzBufferSize, - &SzOffset, // offset of stream for required file in *outBuffer - &SzOutSizeProcessed, // size of file in *outBuffer - &SzAllocImp, - &SzAllocTempImp); - - // close 7Zip archive and free memory - SzClose(); - - // check for errors - if(SzRes != SZ_OK) - { - // display error message - SzDisplayError(SzRes); - return 0; - } - else - { - return SzOutSizeProcessed; - } } diff --git a/source/ngc/unzip.h b/source/ngc/unzip.h index 8d2783de..7a862a7b 100644 --- a/source/ngc/unzip.h +++ b/source/ngc/unzip.h @@ -1,26 +1,15 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * Michniewski 2008 - * Tantric September 2008 - * - * unzip.h + * Nintendo Gamecube Unzip - borrowed from the GPP * - * File unzip routines + * softdev July 2006 ****************************************************************************/ #ifndef _UNZIP_ #define _UNZIP_ -#include - extern int IsZipFile (char *buffer); -char * GetFirstZipFilename(int method); -int UnZipBuffer (unsigned char *outbuffer, int method); -int SzParse(char * filepath, int method); -int SzExtractFile(int i, unsigned char *buffer); -void SzClose(); - +int UnZipBuffer (unsigned char *outbuffer, u64 discoffset, short where, FILE* filehandle); /* * Zip file header definition */ diff --git a/source/ngc/video.cpp b/source/ngc/video.cpp index 7c7339d2..c6e4c10b 100644 --- a/source/ngc/video.cpp +++ b/source/ngc/video.cpp @@ -1,15 +1,14 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * crunchy2 May 2007 - * Michniewski 2008 + * Nintendo Gamecube Video * - * video.cpp + * This is a modified renderer from the Genesis Plus Project. + * Well - you didn't expect me to write another one did ya ? -;) * - * Video routines - ***************************************************************************/ - + * softdev July 2006 + * crunchy2 May 2007 + ****************************************************************************/ #include #include #include @@ -19,20 +18,30 @@ #include #include "snes9x.h" #include "memmap.h" +//#include "debug.h" +//#include "cpuexec.h" +//#include "ppu.h" +//#include "apu.h" +//#include "display.h" +//#include "gfx.h" +//#include "soundux.h" +//#include "spc700.h" +//#include "spc7110.h" +//#include "controls.h" #include "aram.h" -#include "snes9xGX.h" - -#include "gui.h" +//#include "video.h" /*** Snes9x GFX Buffer ***/ static unsigned char snes9xgfx[1024 * 512 * 2]; +/*** Memory ROM Loading ***/ +extern unsigned long ARAM_ROMSIZE; extern unsigned int SMBTimer; /*** 2D Video ***/ unsigned int *xfb[2] = { NULL, NULL }; /*** Double buffered ***/ int whichfb = 0; /*** Switch ***/ -GXRModeObj *vmode; /*** Menu video mode ***/ +GXRModeObj *vmode; /*** General video mode ***/ int screenheight; extern u32* backdrop; @@ -44,20 +53,15 @@ unsigned int copynow = GX_FALSE; static unsigned char gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32); static unsigned char texturemem[TEX_WIDTH * (TEX_HEIGHT + 8)] ATTRIBUTE_ALIGN (32); GXTexObj texobj; -Mtx view; +static Mtx view; int vwidth, vheight, oldvwidth, oldvheight; -float zoom_level = 1; -int zoom_xshift = 0; -int zoom_yshift = 0; - u32 FrameTimer = 0; u8 vmode_60hz = 0; -bool progressive = 0; -#define HASPECT 320 -#define VASPECT 240 +#define HASPECT 76 +#define VASPECT 54 /* New texture based scaler */ typedef struct tagcamera @@ -84,173 +88,15 @@ s16 square[] ATTRIBUTE_ALIGN (32) = -HASPECT, -VASPECT, 0, // 3 }; - static camera cam = { {0.0F, 0.0F, 0.0F}, {0.0F, 0.5F, 0.0F}, {0.0F, 0.0F, -0.5F} }; - -/*** -*** Custom Video modes (used to emulate original console video modes) -***/ - -/** Original SNES PAL Resolutions: **/ - -/* 239 lines progressive (PAL 50Hz) */ -GXRModeObj TV_239p = -{ - VI_TVMODE_PAL_DS, // viDisplayMode - 256, // fbWidth - 239, // efbHeight - 239, // xfbHeight - (VI_MAX_WIDTH_PAL - 640)/2, // viXOrigin - (VI_MAX_HEIGHT_PAL/2 - 478/2)/2, // viYOrigin - 640, // viWidth - 478, // viHeight - VI_XFBMODE_SF, // xFBmode - GX_FALSE, // field_rendering - GX_FALSE, // aa - - // sample points arranged in increasing Y order - { - {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each - {6,6},{6,6},{6,6}, // pix 1 - {6,6},{6,6},{6,6}, // pix 2 - {6,6},{6,6},{6,6} // pix 3 - }, - - // vertical filter[7], 1/64 units, 6 bits each - { - 0, // line n-1 - 0, // line n-1 - 21, // line n - 22, // line n - 21, // line n - 0, // line n+1 - 0 // line n+1 - } -}; - -/* 478 lines interlaced (PAL 50Hz, Deflicker) */ -GXRModeObj TV_478i = -{ - VI_TVMODE_PAL_INT, // viDisplayMode - 512, // fbWidth - 478, // efbHeight - 478, // xfbHeight - (VI_MAX_WIDTH_PAL - 640)/2, // viXOrigin - (VI_MAX_HEIGHT_PAL/2 - 478/2)/2, // viYOrigin - 640, // viWidth - 478, // viHeight - VI_XFBMODE_DF, // xFBmode - GX_FALSE, // field_rendering - GX_FALSE, // aa - - // sample points arranged in increasing Y order - { - {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each - {6,6},{6,6},{6,6}, // pix 1 - {6,6},{6,6},{6,6}, // pix 2 - {6,6},{6,6},{6,6} // pix 3 - }, - - // vertical filter[7], 1/64 units, 6 bits each - { - 8, // line n-1 - 8, // line n-1 - 10, // line n - 12, // line n - 10, // line n - 8, // line n+1 - 8 // line n+1 - } -}; - -/** Original SNES NTSC Resolutions: **/ - -/* 224 lines progressive (NTSC or PAL 60Hz) */ -GXRModeObj TV_224p = -{ - VI_TVMODE_EURGB60_DS, // viDisplayMode - 256, // fbWidth - 224, // efbHeight - 224, // xfbHeight - (VI_MAX_WIDTH_NTSC - 640)/2, // viXOrigin - (VI_MAX_HEIGHT_NTSC/2 - 448/2)/2, // viYOrigin - 640, // viWidth - 448, // viHeight - VI_XFBMODE_SF, // xFBmode - GX_FALSE, // field_rendering - GX_FALSE, // aa - - // sample points arranged in increasing Y order - { - {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each - {6,6},{6,6},{6,6}, // pix 1 - {6,6},{6,6},{6,6}, // pix 2 - {6,6},{6,6},{6,6} // pix 3 - }, - - // vertical filter[7], 1/64 units, 6 bits each - { - 0, // line n-1 - 0, // line n-1 - 21, // line n - 22, // line n - 21, // line n - 0, // line n+1 - 0 // line n+1 - } -}; - -/* 448 lines interlaced (NTSC or PAL 60Hz, Deflicker) */ -GXRModeObj TV_448i = -{ - VI_TVMODE_EURGB60_INT, // viDisplayMode - 512, // fbWidth - 448, // efbHeight - 448, // xfbHeight - (VI_MAX_WIDTH_NTSC - 640)/2, // viXOrigin - (VI_MAX_HEIGHT_NTSC/2 - 448/2)/2, // viYOrigin - 640, // viWidth - 448, // viHeight - VI_XFBMODE_DF, // xFBmode - GX_FALSE, // field_rendering - GX_FALSE, // aa - - - // sample points arranged in increasing Y order - { - {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each - {6,6},{6,6},{6,6}, // pix 1 - {6,6},{6,6},{6,6}, // pix 2 - {6,6},{6,6},{6,6} // pix 3 - }, - - // vertical filter[7], 1/64 units, 6 bits each - { - 8, // line n-1 - 8, // line n-1 - 10, // line n - 12, // line n - 10, // line n - 8, // line n+1 - 8 // line n+1 - } -}; - -/* TV Modes table */ -GXRModeObj *tvmodes[4] = { - &TV_239p, &TV_478i, /* Snes PAL video modes */ - &TV_224p, &TV_448i, /* Snes NTSC video modes */ -}; - - #ifdef VIDEO_THREADING /**************************************************************************** * VideoThreading - ***************************************************************************/ + ****************************************************************************/ #define TSTACK 16384 lwpq_t videoblankqueue; lwp_t vbthread; @@ -260,20 +106,20 @@ static unsigned char vbstack[TSTACK]; * vbgetback * * This callback enables the emulator to keep running while waiting for a - * vertical blank. + * vertical blank. * * Putting LWP to good use :) - ***************************************************************************/ + ****************************************************************************/ static void * vbgetback (void *arg) { - while (1) - { - VIDEO_WaitVSync (); /**< Wait for video vertical blank */ - LWP_SuspendThread (vbthread); - } + while (1) + { + VIDEO_WaitVSync (); /**< Wait for video vertical blank */ + LWP_SuspendThread (vbthread); + } - return NULL; + return NULL; } @@ -282,15 +128,15 @@ vbgetback (void *arg) * * libOGC provides a nice wrapper for LWP access. * This function sets up a new local queue and attaches the thread to it. - ***************************************************************************/ + ****************************************************************************/ void InitVideoThread () { /*** Initialise a new queue ***/ - LWP_InitQueue (&videoblankqueue); + LWP_InitQueue (&videoblankqueue); /*** Create the thread on this queue ***/ - LWP_CreateThread (&vbthread, vbgetback, NULL, vbstack, TSTACK, 80); + LWP_CreateThread (&vbthread, vbgetback, NULL, vbstack, TSTACK, 80); } #endif @@ -300,376 +146,364 @@ InitVideoThread () * * Stock code to copy the GX buffer to the current display mode. * Also increments the frameticker, as it's called for each vb. - ***************************************************************************/ + ****************************************************************************/ static void copy_to_xfb (u32 arg) { - if (copynow == GX_TRUE) - { - GX_CopyDisp (xfb[whichfb], GX_TRUE); - GX_Flush (); - copynow = GX_FALSE; - } + if (copynow == GX_TRUE) + { + GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); + GX_SetColorUpdate (GX_TRUE); + GX_CopyDisp (xfb[whichfb], GX_TRUE); + GX_Flush (); + copynow = GX_FALSE; + } + + FrameTimer++; + SMBTimer++; - FrameTimer++; - SMBTimer++; } /**************************************************************************** - * Scaler Support Functions - ***************************************************************************/ + * WIP3 - Scaler Support Functions + ****************************************************************************/ static void draw_init () { - GX_ClearVtxDesc (); - GX_SetVtxDesc (GX_VA_POS, GX_INDEX8); - GX_SetVtxDesc (GX_VA_CLR0, GX_INDEX8); - GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); - - GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); - GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); - GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); + GX_ClearVtxDesc (); + GX_SetVtxDesc (GX_VA_POS, GX_INDEX8); + GX_SetVtxDesc (GX_VA_CLR0, GX_INDEX8); + GX_SetVtxDesc (GX_VA_TEX0, GX_DIRECT); - GX_SetArray (GX_VA_POS, square, 3 * sizeof (s16)); + GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); + GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + GX_SetVtxAttrFmt (GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); - GX_SetNumTexGens (1); - GX_SetNumChans (0); + GX_SetArray (GX_VA_POS, square, 3 * sizeof (s16)); - GX_SetTexCoordGen (GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); + GX_SetNumTexGens (1); + GX_SetTexCoordGen (GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); - GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE); - GX_SetTevOrder (GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL); - - memset (&view, 0, sizeof (Mtx)); - guLookAt(view, &cam.pos, &cam.up, &cam.view); - GX_LoadPosMtxImm (view, GX_PNMTX0); + GX_InvalidateTexAll (); + GX_InitTexObj (&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, + GX_CLAMP, GX_CLAMP, GX_FALSE); } static void draw_vert (u8 pos, u8 c, f32 s, f32 t) { - GX_Position1x8 (pos); - GX_Color1x8 (c); - GX_TexCoord2f32 (s, t); + GX_Position1x8 (pos); + GX_Color1x8 (c); + GX_TexCoord2f32 (s, t); } static void draw_square (Mtx v) { - Mtx m; // model matrix. - Mtx mv; // modelview matrix. - - guMtxIdentity (m); - guMtxTransApply (m, m, 0, 0, -100); - guMtxConcat (v, m, mv); - - GX_LoadPosMtxImm (mv, GX_PNMTX0); - GX_Begin (GX_QUADS, GX_VTXFMT0, 4); - draw_vert (0, 0, 0.0, 0.0); - draw_vert (1, 0, 1.0, 0.0); - draw_vert (2, 0, 1.0, 1.0); - draw_vert (3, 0, 0.0, 1.0); - GX_End (); + Mtx m; // model matrix. + Mtx mv; // modelview matrix. + + /* + * Use C functions! + * Calling the faster asm ones cause reboot! + */ + guMtxIdentity (m); + guMtxTransApply (m, m, 0, 0, -100); + guMtxConcat (v, m, mv); + + GX_LoadPosMtxImm (mv, GX_PNMTX0); + GX_Begin (GX_QUADS, GX_VTXFMT0, 4); + draw_vert (0, 0, 0.0, 0.0); + draw_vert (1, 0, 1.0, 0.0); + draw_vert (2, 0, 1.0, 1.0); + draw_vert (3, 0, 0.0, 1.0); + GX_End (); } /**************************************************************************** * StartGX * * This function initialises the GX. - ***************************************************************************/ + * WIP3 - Based on texturetest from libOGC examples. + ****************************************************************************/ static void StartGX () { - Mtx p; + Mtx p; - GXColor background = { 0, 0, 0, 0xff }; + GXColor background = { 0, 0, 0, 0xff }; /*** Clear out FIFO area ***/ - memset (&gp_fifo, 0, DEFAULT_FIFO_SIZE); + memset (&gp_fifo, 0, DEFAULT_FIFO_SIZE); /*** Initialise GX ***/ - GX_Init (&gp_fifo, DEFAULT_FIFO_SIZE); - GX_SetCopyClear (background, 0x00ffffff); - - - GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); - GX_SetDispCopyYScale ((f32) vmode->xfbHeight / (f32) vmode->efbHeight); - GX_SetScissor (0, 0, vmode->fbWidth, vmode->efbHeight); - - GX_SetDispCopySrc (0, 0, vmode->fbWidth, vmode->efbHeight); - GX_SetDispCopyDst (vmode->fbWidth, vmode->xfbHeight); - GX_SetCopyFilter (vmode->aa, vmode->sample_pattern, GX_TRUE, vmode->vfilter); - - GX_SetFieldMode (vmode->field_rendering, ((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); - - GX_SetPixelFmt (GX_PF_RGB8_Z24, GX_ZC_LINEAR); - GX_SetCullMode (GX_CULL_NONE); - GX_SetDispCopyGamma (GX_GM_1_0); - GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); - GX_SetColorUpdate (GX_TRUE); - - gui_alphasetup (); - - guOrtho(p, vmode->efbHeight/2, -(vmode->efbHeight/2), -(vmode->fbWidth/2), vmode->fbWidth/2, 10, 1000); // matrix, t, b, l, r, n, f - GX_LoadProjectionMtx (p, GX_ORTHOGRAPHIC); - - - GX_CopyDisp (xfb[whichfb], GX_TRUE); // reset xfb - - vwidth = 100; - vheight = 100; + GX_Init (&gp_fifo, DEFAULT_FIFO_SIZE); + GX_SetCopyClear (background, 0x00ffffff); + + GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); + GX_SetDispCopyYScale ((f32) vmode->xfbHeight / (f32) vmode->efbHeight); + GX_SetScissor (0, 0, vmode->fbWidth, vmode->efbHeight); + GX_SetDispCopySrc (0, 0, vmode->fbWidth, vmode->efbHeight); + GX_SetDispCopyDst (vmode->fbWidth, vmode->xfbHeight); + GX_SetCopyFilter (vmode->aa, vmode->sample_pattern, GX_TRUE, + vmode->vfilter); + GX_SetFieldMode (vmode->field_rendering, + ((vmode->viHeight == + 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); + GX_SetPixelFmt (GX_PF_RGB8_Z24, GX_ZC_LINEAR); + GX_SetCullMode (GX_CULL_NONE); + GX_CopyDisp (xfb[whichfb], GX_TRUE); + GX_SetDispCopyGamma (GX_GM_1_0); + + guPerspective (p, 60, 1.33F, 10.0F, 1000.0F); + GX_LoadProjectionMtx (p, GX_PERSPECTIVE); + + vwidth = 100; + vheight = 100; } /**************************************************************************** - * UpdatePadsCB + * UpdatePads * * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad - ***************************************************************************/ -void -UpdatePadsCB () + ****************************************************************************/ +void UpdatePadsCB() { #ifdef HW_RVL WPAD_ScanPads(); #endif PAD_ScanPads(); } - + /**************************************************************************** * InitGCVideo * * This function MUST be called at startup. - * - also sets up menu video mode - ***************************************************************************/ + ****************************************************************************/ + void InitGCVideo () { - // init video + /* + * Before doing anything else under libogc, + * Call VIDEO_Init + */ + + int *romptr = (int *) 0x81000000; + VIDEO_Init (); - - // get default video mode + PAD_Init (); + //DVD_Init (); + + /*** Check to see if this is a GC or a Wii ***/ +// int driveid = dvd_driveid(); +// bool8 isWii = !((driveid == 4) || (driveid == 6) || (driveid == 8)); + + AUDIO_Init (NULL); + AR_Init (NULL, 0); + + /* Before going any further, let's copy any attached ROM image ** */ + if (memcmp ((char *) romptr, "SNESROM0", 8) == 0) + { + ARAM_ROMSIZE = romptr[2]; + romptr = (int *) 0x81000020; + ARAMPut ((char *) romptr, (char *) AR_SNESROM, ARAM_ROMSIZE); + } + + /* + * Always use NTSC mode - this works on NTSC and PAL, GC and Wii + vmode = &TVNtsc480IntDf; + */ + vmode = VIDEO_GetPreferredMode(NULL); - switch (vmode->viTVMode >> 2) + switch(vmode->viTVMode) { - case VI_PAL: - // 576 lines (PAL 50Hz) - // display should be centered vertically (borders) - vmode = &TVPal574IntDfScale; - vmode->xfbHeight = 480; - vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2; - vmode->viHeight = 480; - + case VI_TVMODE_PAL_DS: + case VI_TVMODE_PAL_INT: vmode_60hz = 0; break; - case VI_NTSC: - // 480 lines (NTSC 60hz) - vmode_60hz = 1; - break; - + case VI_TVMODE_EURGB60_PROG: + case VI_TVMODE_EURGB60_DS: + case VI_TVMODE_NTSC_DS: + case VI_TVMODE_NTSC_INT: + case VI_TVMODE_NTSC_PROG: + case VI_TVMODE_MPAL_INT: default: - // 480 lines (PAL 60Hz) vmode_60hz = 1; break; } - -#ifdef HW_DOL -/* we have component cables, but the preferred mode is interlaced - * why don't we switch into progressive? - * on the Wii, the user can do this themselves on their Wii Settings */ - if(VIDEO_HaveComponentCable() && vmode == &TVNtsc480IntDf) - vmode = &TVNtsc480Prog; -#endif - - // check for progressive scan - if (vmode->viTVMode == VI_TVMODE_NTSC_PROG) - progressive = true; - + VIDEO_Configure (vmode); - + screenheight = vmode->xfbHeight; - - - // Allocate the video buffers + + /* + * Allocate the video buffers + */ xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); - - // A console is always useful while debugging. + + /* + * A console is always useful while debugging. + */ console_init (xfb[0], 20, 64, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth * 2); - - // Clear framebuffers etc. + + /* + * Clear framebuffers etc. + */ VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer (xfb[0]); - - // video callbacks + + /* + * Let libogc populate manage the PADs for us + */ + //VIDEO_SetPostRetraceCallback ((VIRetraceCallback)PAD_ScanPads); VIDEO_SetPostRetraceCallback ((VIRetraceCallback)UpdatePadsCB); VIDEO_SetPreRetraceCallback ((VIRetraceCallback)copy_to_xfb); - VIDEO_SetBlack (FALSE); VIDEO_Flush (); VIDEO_WaitVSync (); if (vmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync (); - + VIDEO_WaitVSync (); + copynow = GX_FALSE; StartGX (); - - draw_init (); - + #ifdef VIDEO_THREADING InitVideoThread (); #endif - - // Finally, the video is up and ready for use :) + + /* + * Finally, the video is up and ready for use :) + */ } /**************************************************************************** - * ResetVideo_Emu - * - * Reset the video/rendering mode for the emulator rendering -****************************************************************************/ + * Drawing screen + ****************************************************************************/ void -ResetVideo_Emu () +clearscreen (int colour) { - GXRModeObj *rmode; - Mtx p; - - switch (vmode->viTVMode >> 2) - { - case VI_PAL: /* 576 lines (PAL 50Hz) */ - - // set video signal mode - TV_239p.viTVMode = VI_TVMODE_PAL_DS; - TV_478i.viTVMode = VI_TVMODE_PAL_INT; - TV_224p.viTVMode = VI_TVMODE_PAL_DS; - TV_448i.viTVMode = VI_TVMODE_PAL_INT; - // set VI position - TV_239p.viXOrigin = TV_478i.viXOrigin = TV_224p.viXOrigin = TV_448i.viXOrigin = (VI_MAX_WIDTH_PAL - 640)/2; - TV_239p.viYOrigin = TV_478i.viYOrigin = (VI_MAX_HEIGHT_PAL/2 - 478/2)/2; - TV_224p.viYOrigin = TV_448i.viYOrigin = (VI_MAX_HEIGHT_PAL/2 - 448/2)/2; - - break; - - case VI_NTSC: /* 480 lines (NTSC 60hz) */ - - // set video signal mode - TV_239p.viTVMode = VI_TVMODE_NTSC_DS; - TV_478i.viTVMode = VI_TVMODE_NTSC_INT; - TV_224p.viTVMode = VI_TVMODE_NTSC_DS; - TV_448i.viTVMode = VI_TVMODE_NTSC_INT; - // set VI position - TV_239p.viXOrigin = TV_224p.viXOrigin = TV_478i.viXOrigin = TV_448i.viXOrigin = (VI_MAX_WIDTH_NTSC - 640)/2; - TV_239p.viYOrigin = TV_478i.viYOrigin = (VI_MAX_HEIGHT_NTSC/2 - 478/2)/2; - TV_224p.viYOrigin = TV_448i.viYOrigin = (VI_MAX_HEIGHT_NTSC/2 - 448/2)/2; - - break; - - default: /* 480 lines (PAL 60Hz) */ - - // set video signal mode - TV_239p.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_NON_INTERLACE); - TV_478i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE); - TV_224p.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_NON_INTERLACE); - TV_448i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE); - // set VI position - TV_239p.viXOrigin = TV_224p.viXOrigin = TV_478i.viXOrigin = TV_448i.viXOrigin = (VI_MAX_WIDTH_NTSC - 640)/2; - TV_239p.viYOrigin = TV_478i.viYOrigin = (VI_MAX_HEIGHT_NTSC/2 - 478/2)/2; - TV_224p.viYOrigin = TV_448i.viYOrigin = (VI_MAX_HEIGHT_NTSC/2 - 448/2)/2; - - break; - } + whichfb ^= 1; + VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], colour); +#ifdef HW_RVL + // on wii copy from memory + memcpy ((char *) xfb[whichfb], (char *) backdrop, 640 * screenheight * 2); +#else + // on gc copy from aram + ARAMFetch ((char *) xfb[whichfb], (char *) AR_BACKDROP, 640 * screenheight * 2); // FIX +#endif +} - int i = -1; - if (GCSettings.render == 0) // original render mode - { - for (i=0; i<4; i++) { - if (tvmodes[i]->efbHeight == vheight) { - // FIX: ok? - tvmodes[i]->fbWidth = vwidth; // update width - some games are 512x224 (super pang) - break; - } - } - rmode = tvmodes[i]; - } - else if (GCSettings.render == 2) // unfiltered - { - rmode = vmode; - } - else // filtered - { - rmode = vmode; // same mode as menu - } +void +showscreen () +{ + copynow = GX_FALSE; + VIDEO_SetNextFramebuffer (xfb[whichfb]); + VIDEO_Flush (); + VIDEO_WaitVSync (); +} +/**************************************************************************** + * setGFX + * + * Setup the global GFX information for Snes9x + ****************************************************************************/ +void +setGFX () +{ + GFX.Screen = (unsigned short *) snes9xgfx; + GFX.Pitch = 1024; +} - VIDEO_Configure (rmode); - VIDEO_ClearFrameBuffer (rmode, xfb[whichfb], COLOR_BLACK); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); +#ifndef NGCC +#if 0 +/**************************************************************************** + * MakeTexture + * + * GC requires RGB565 colour tiles of 4 x 4 pixels. + * Ok, apparently the pipeline stalls waiting for the indexed register to update. + * Solution : Use R9 to mirror R4 + * + * THIS IS NOW UNUSED, BUT LEFT HERE SO I CAN TINKER -;) + ****************************************************************************/ +void +MakeTexture (char *src, /*** R3 Pointer to source ***/ + char *dst, /*** R4 Pointer to output ***/ + int width, /*** R5 Width ***/ + int height, /*** R6 Height ***/ + int w1, /*** R7 Worker ***/ + int w2, /*** R8 Worker ***/ + int w3, /*** R9 Worker ***/ + int w4) /*** R10 Worker ***/ +{ + /*** How many tiles per row ***/ + asm ("srwi 5,5,2"); /*** Width / 4 == Tiles ***/ + asm ("srwi 6,6,2"); /*** Height / 4 == Tiles ***/ + asm ("mr 9,4"); /*** Mirror R4 ***/ + asm ("subi 4,4,8"); /*** Adjust R4 for index update ***/ + asm ("subi 9,9,4"); /*** Adjust R9 for index update ***/ - GX_SetViewport (0, 0, rmode->fbWidth, rmode->efbHeight, 0, 1); - GX_SetDispCopyYScale ((f32) rmode->xfbHeight / (f32) rmode->efbHeight); - GX_SetScissor (0, 0, rmode->fbWidth, rmode->efbHeight); + /*** Outer loop ***/ + asm ("DoAllTiles:"); - GX_SetDispCopySrc (0, 0, rmode->fbWidth, rmode->efbHeight); - GX_SetDispCopyDst (rmode->fbWidth, rmode->xfbHeight); - GX_SetCopyFilter (rmode->aa, rmode->sample_pattern, (GCSettings.render == 1) ? GX_TRUE : GX_FALSE, rmode->vfilter); // AA on only for filtered mode + asm ("mtctr 5"); /*** Will loop for this number of tiles across ***/ + asm ("mr 8,3"); /*** Preserve current source position ***/ - GX_SetFieldMode (rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); - GX_SetPixelFmt (GX_PF_RGB8_Z24, GX_ZC_LINEAR); + asm ("DoOneTile:"); - guOrtho(p, rmode->efbHeight/2, -(rmode->efbHeight/2), -(rmode->fbWidth/2), rmode->fbWidth/2, 10, 1000); // matrix, t, b, l, r, n, f - GX_LoadProjectionMtx (p, GX_ORTHOGRAPHIC); + /*** Store 4 Horizontal Pixels - ROW 1 ***/ + asm ("lwz 7,0(3)"); + asm ("stwu 7,8(4)"); + asm ("lwz 10,4(3)"); + asm ("stwu 10,8(9)"); - #ifdef _DEBUG_VIDEO - // log stuff - fprintf(debughandle, "\n\nrmode = tvmodes[%d], field_rendering: %d", i, (rmode->viHeight == 2 * rmode->xfbHeight)); - fprintf(debughandle, "\nInterlaced: %i,\t vwidth: %d, vheight: %d,\t fb_W: %u, efb_H: %u", IPPU.Interlace, vwidth, vheight, rmode->fbWidth, rmode->efbHeight); - #endif + /*** Store 4 Horizontal Pixels - ROW 2 ***/ + asm ("lwz 7,1024(3)"); + asm ("stwu 7,8(4)"); + asm ("lwz 10,1028(3)"); + asm ("stwu 10,8(9)"); -} + /*** Store 4 Horizontal Pixels - ROW 3 ***/ + asm ("lwz 7,2048(3)"); + asm ("stwu 7,8(4)"); + asm ("lwz 10,2052(3)"); + asm ("stwu 10,8(9)"); -/**************************************************************************** - * ResetVideo_Menu - * - * Reset the video/rendering mode for the menu -****************************************************************************/ -void -ResetVideo_Menu () -{ - Mtx p; + /*** Store 4 Horizontal Pixels - ROW 4 ***/ + asm ("lwz 7,3072(3)"); + asm ("stwu 7,8(4)"); + asm ("lwz 10,3076(3)"); + asm ("stwu 10,8(9)"); - VIDEO_Configure (vmode); - VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], COLOR_BLACK); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); + /*** Move along 4 pixels ***/ + asm ("addi 3,3,8"); - GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); - GX_SetDispCopyYScale ((f32) vmode->xfbHeight / (f32) vmode->efbHeight); - GX_SetScissor (0, 0, vmode->fbWidth, vmode->efbHeight); + /*** Repeat for next tile ***/ + asm ("bdnz DoOneTile"); - GX_SetDispCopySrc (0, 0, vmode->fbWidth, vmode->efbHeight); - GX_SetDispCopyDst (vmode->fbWidth, vmode->xfbHeight); - GX_SetCopyFilter (vmode->aa, vmode->sample_pattern, GX_TRUE, vmode->vfilter); + /*** Update R3 to be 4 rows down ***/ + asm ("mr 3,8"); + asm ("addi 3,3,4096"); - GX_SetFieldMode (vmode->field_rendering, ((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); - GX_SetPixelFmt (GX_PF_RGB8_Z24, GX_ZC_LINEAR); + /*** Decrement Outer Tile loop ***/ + asm ("subi 6,6,1"); + asm ("cmpwi 6,0"); + asm ("bne DoAllTiles"); - guOrtho(p, vmode->efbHeight/2, -(vmode->efbHeight/2), -(vmode->fbWidth/2), vmode->fbWidth/2, 10, 1000); // matrix, t, b, l, r, n, f - GX_LoadProjectionMtx (p, GX_ORTHOGRAPHIC); } +#endif /**************************************************************************** - * MakeTexture + * MakeTexture * * Proper GNU Asm rendition of the above, converted by shagkur. - Thanks! - ***************************************************************************/ + ****************************************************************************/ void MakeTexture (const void *src, void *dst, s32 width, s32 height) { @@ -682,7 +516,7 @@ MakeTexture (const void *src, void *dst, s32 width, s32 height) " subi %4,%4,4\n" "2: mtctr %6\n" " mr %0,%5\n" - // + // "1: lwz %1,0(%5)\n" " stwu %1,8(%4)\n" " lwz %2,4(%5)\n" @@ -704,166 +538,126 @@ MakeTexture (const void *src, void *dst, s32 width, s32 height) " addi %5,%0,4096\n" " subic. %7,%7,1\n" " bne 2b" - // 0 1 2 3 4 5 6 7 + // 0 1 2 3 4 5 6 7 :"=&r" (tmp0), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "+r" (dst):"r" (src), "r" (width), "r" (height)); } +#endif + /**************************************************************************** * Update Video - ***************************************************************************/ -uint32 prevRenderedFrameCount = 0; -extern bool CheckVideo; - + ****************************************************************************/ void update_video (int width, int height) { - - vwidth = width; - vheight = height; + vwidth = width; + vheight = height; #ifdef VIDEO_THREADING - // Ensure previous vb has complete - while ((LWP_ThreadIsSuspended (vbthread) == 0) || (copynow == GX_TRUE)) + /* Ensure previous vb has complete */ + while ((LWP_ThreadIsSuspended (vbthread) == 0) || (copynow == GX_TRUE)) #else - while (copynow == GX_TRUE) + while (copynow == GX_TRUE) #endif - { - usleep (50); - } + { + usleep (50); + } - whichfb ^= 1; + whichfb ^= 1; - if ( oldvheight != vheight || oldvwidth != vwidth ) // if rendered width/height changes, update scaling - CheckVideo = 1; - - if ( CheckVideo && (IPPU.RenderedFramesCount != prevRenderedFrameCount) ) // if we get back from the menu, and have rendered at least 1 frame + if ((oldvheight != vheight) || (oldvwidth != vwidth)) + { + /** Update scaling **/ + oldvwidth = vwidth; + oldvheight = vheight; + draw_init (); + + memset (&view, 0, sizeof (Mtx)); + guLookAt(view, &cam.pos, &cam.up, &cam.view); + GX_SetViewport (0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); + } + + GX_InvVtxCache (); + GX_InvalidateTexAll (); + GX_SetTevOp (GX_TEVSTAGE0, GX_DECAL); + GX_SetTevOrder (GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); + +#ifdef NGCC + int h, w; + int *dst = (int *) texturemem; + int *src = (int *) GFX.Screen; + int hpos; + + /*** Pitch for screen, regardless of size is always the same ***/ + for (h = 0; h < vheight; h += 4) + { + + for (w = 0; w < (vwidth >> 1); w += 2) { - int xscale, yscale; - ResetVideo_Emu (); // reset video to emulator rendering settings + hpos = w; + *dst++ = src[hpos++]; + *dst++ = src[hpos]; - /** Update scaling **/ - if (GCSettings.render == 0) // original render mode - { - xscale = vwidth / 2; - yscale = vheight / 2; - } else { // unfiltered and filtered mode - xscale = vmode->fbWidth / 2; - yscale = vmode->efbHeight / 2; - } + hpos = w + 256; + *dst++ = src[hpos++]; + *dst++ = src[hpos]; - // aspect ratio scaling (change width scale) - // yes its pretty cheap and ugly, but its easy! - if (GCSettings.widescreen) - xscale -= (4.0*yscale)/9; + hpos = w + 512; + *dst++ = src[hpos++]; + *dst++ = src[hpos]; - xscale *= zoom_level; - yscale *= zoom_level; + hpos = w + 768; + *dst++ = src[hpos++]; + *dst++ = src[hpos]; - square[6] = square[3] = xscale + GCSettings.xshift; - square[0] = square[9] = -xscale + GCSettings.xshift; - square[4] = square[1] = yscale - GCSettings.yshift; - square[7] = square[10] = -yscale - GCSettings.yshift; + } - GX_InvVtxCache (); // update vertex cache + src += GFX.Pitch; - GX_InitTexObj (&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); // initialize the texture obj we are going to use + } - if (GCSettings.render == 0 || GCSettings.render == 2) - GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,2.5,9.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1); // original/unfiltered video mode: force texture filtering OFF +#else - GX_LoadTexObj (&texobj, GX_TEXMAP0); // load texture object so its ready to use + MakeTexture ((char *) GFX.Screen, (char *) texturemem, vwidth, vheight); - #ifdef _DEBUG_VIDEO - // log stuff - fprintf(debughandle, "\nxscale: %d, yscale: %d", xscale, yscale); - #endif +#endif - oldvwidth = vwidth; - oldvheight = vheight; - CheckVideo = 0; - } + DCFlushRange (texturemem, TEX_WIDTH * TEX_HEIGHT * 2); - MakeTexture ((char *) GFX.Screen, (char *) texturemem, vwidth, vheight); // convert image to texture + GX_SetNumChans (1); - DCFlushRange (texturemem, TEX_WIDTH * TEX_HEIGHT * 2); // update the texture memory - GX_InvalidateTexAll (); + GX_LoadTexObj (&texobj, GX_TEXMAP0); - draw_square (view); // draw the quad + draw_square (view); - GX_DrawDone (); - VIDEO_SetNextFramebuffer (xfb[whichfb]); - VIDEO_Flush (); - copynow = GX_TRUE; + GX_DrawDone (); + VIDEO_SetNextFramebuffer (xfb[whichfb]); + VIDEO_Flush (); + copynow = GX_TRUE; #ifdef VIDEO_THREADING - // Return to caller, don't waste time waiting for vb - LWP_ResumeThread (vbthread); + /* Return to caller, don't waste time waiting for vb */ + LWP_ResumeThread (vbthread); #endif } -/**************************************************************************** - * Zoom Functions - ***************************************************************************/ void zoom (float speed) { - if (zoom_level > 1) - zoom_level += (speed / -100.0); - else - zoom_level += (speed / -200.0); - - if (zoom_level < 0.5) zoom_level = 0.5; - else if (zoom_level > 10.0) zoom_level = 10.0; - - oldvheight = 0; // update video -} - -void -zoom_reset () -{ - zoom_level = 1.0; - - oldvheight = 0; // update video -} + Vector v; -/**************************************************************************** - * Drawing screen - ***************************************************************************/ -void -clearscreen (int colour) -{ - whichfb ^= 1; - VIDEO_ClearFrameBuffer (vmode, xfb[whichfb], colour); -#ifdef HW_RVL - // on wii copy from memory - memcpy ((char *) xfb[whichfb], (char *) backdrop, 640 * screenheight * 2); -#else - // on gc copy from aram - ARAMFetch ((char *) xfb[whichfb], (char *) AR_BACKDROP, 640 * screenheight * 2); -#endif -} + v.x = cam.view.x - cam.pos.x; + v.y = cam.view.y - cam.pos.y; + v.z = cam.view.z - cam.pos.z; -void -showscreen () -{ - copynow = GX_FALSE; - VIDEO_SetNextFramebuffer (xfb[whichfb]); - VIDEO_Flush (); - VIDEO_WaitVSync (); -} + cam.pos.x += v.x * speed; + cam.pos.z += v.z * speed; + cam.view.x += v.x * speed; + cam.view.z += v.z * speed; -/**************************************************************************** - * setGFX - * - * Setup the global GFX information for Snes9x - ***************************************************************************/ -void -setGFX () -{ - GFX.Screen = (unsigned short *) snes9xgfx; - GFX.Pitch = 1024; + oldvheight = 0; } diff --git a/source/ngc/video.h b/source/ngc/video.h index 78222c8a..8224be8c 100644 --- a/source/ngc/video.h +++ b/source/ngc/video.h @@ -1,37 +1,27 @@ /**************************************************************************** - * Snes9x 1.51 Nintendo Wii/Gamecube Port + * Snes9x 1.50 * - * softdev July 2006 - * Michniewski 2008 + * Nintendo Gamecube Video * - * video.h + * This is a modified renderer from the Genesis Plus Project. + * Well - you didn't expect me to write another one did ya ? -;) * - * Video routines - ***************************************************************************/ - + * softdev July 2006 + ****************************************************************************/ #ifndef _GCVIDEOH_ #define _GCVIDEOH_ - +//#include #include #include "snes9x.h" void InitGCVideo (); -void ResetVideo_Emu (); -void ResetVideo_Menu (); +void clearscreen (int colour = COLOR_WHITE); +void showscreen (); void setGFX (); void update_video (int width, int height); -void clearscreen (int colour = COLOR_BLACK); -void showscreen (); void zoom (float speed); -void zoom_reset (); - -extern bool progressive; - -#ifdef _DEBUG_VIDEO - // log stuff -extern FILE * debughandle; -#endif +void UpdatePadsCB(); #endif diff --git a/source/smb/DES.c b/source/smb/DES.c new file mode 100644 index 00000000..80955660 --- /dev/null +++ b/source/smb/DES.c @@ -0,0 +1,726 @@ +/* ========================================================================== ** + * + * DES.c + * + * Copyright: + * Copyright (C) 2003, 2004 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * $Id: DES.c,v 0.6 2004/05/30 05:41:20 crh Exp $ + * + * -------------------------------------------------------------------------- ** + * + * Description: + * + * Implements DES encryption, but not decryption. + * DES is used to create LM password hashes and both LM and NTLM Responses. + * + * -------------------------------------------------------------------------- ** + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- ** + * + * Notes: + * + * This implementation was created by studying many existing examples + * found in Open Source, in the public domain, and in various documentation. + * The SMB protocol makes minimal use of the DES function, so this is a + * minimal implementation. That which is not required has been removed. + * + * The SMB protocol uses the DES algorithm as a hash function, not an + * encryption function. The auth_DEShash() implemented here is a one-way + * function. The reverse is not implemented in this module. Also, there + * is no attempt at making this either fast or efficient. There is no + * need, as the auth_DEShash() function is used for generating the LM + * Response from a 7-byte key and an 8-byte challenge. It is not intended + * for use in encrypting large blocks of data or data streams. + * + * As stated above, this implementation is based on studying existing work + * in the public domain or under Open Source (specifically LGPL) license. + * The code, however, is written from scratch. Obviously, I make no claim + * with regard to those earlier works (except to claim that I am grateful + * to the previous implementors whose work I studied). See the list of + * references below for resources I used. + * + * References: + * I read through the libmcrypt code to see how they put the pieces + * together. See: http://mcrypt.hellug.gr/ + * Libmcrypt is available under the terms of the LGPL. + * + * The libmcrypt implementation includes the following credits: + * written 12 Dec 1986 by Phil Karn, KA9Q; large sections adapted + * from the 1977 public-domain program by Jim Gillogly + * Modified for additional speed - 6 December 1988 Phil Karn + * Modified for parameterized key schedules - Jan 1991 Phil Karn + * modified in order to use the libmcrypt API by Nikos Mavroyanopoulos + * All modifications are placed under the license of libmcrypt. + * + * See also Phil Karn's privacy and security page: + * http://www.ka9q.net/privacy.html + * + * I relied heavily upon: + * Applied Cryptography, Second Edition: + * Protocols, Algorithms, and Source Code in C + * by Bruce Schneier. ISBN 0-471-11709-9, John Wiley & Sons, Inc., 1996 + * Particularly Chapter 12. + * + * Here's one more DES resource, which I found quite helpful (aside from + * the Clinton jokes): + * http://www.aci.net/kalliste/des.htm + * + * Finally, the use of DES in SMB is covered in: + * Implementing CIFS - the Common Internet File System + * by your truly. ISBN 0-13-047116-X, Prentice Hall PTR., August 2003 + * Section 15.3, in particular. + * (Online at: http://ubiqx.org/cifs/SMB.html#SMB.8.3) + * + * ========================================================================== ** + */ + +#include "DES.h" + + +/* -------------------------------------------------------------------------- ** + * Static Constants: + */ + +/* Initial permutation map. + * In the first step of DES, the bits of the initial plaintext are rearranged + * according to the map given below. This map and those like it are read by + * the Permute() function (below) which uses the maps as a guide when moving + * bits from one place to another. + * + * Note that the values here are all one less than those shown in Schneier. + * That's because C likes to start counting from 0, not 1. + * + * According to Schneier (Ch12, pg 271), the purpose of the initial + * permutation was to make it easier to load plaintext and ciphertext into + * a DES ecryption chip. I have no idea why that would be the case. + */ +static const uint8_t InitialPermuteMap[64] = + { + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7, + 56, 48, 40, 32, 24, 16, 8, 0, + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6 + }; + + +/* Key permutation map. + * Like the input data and encryption result, the key is permuted before + * the algorithm really gets going. The original algorithm called for an + * eight-byte key in which each byte contained a parity bit. During the + * key permutiation, the parity bits were discarded. The DES algorithm, + * as used with SMB, does not make use of the parity bits. Instead, SMB + * passes 7-byte keys to DES. For DES implementations that expect parity, + * the parity bits must be added. In this case, however, we're just going + * to start with a 7-byte (56 bit) key. KeyPermuteMap, below, is adjusted + * accordingly and, of course, each entry in the map is reduced by 1 with + * respect to the documented values because C likes to start counting from + * 0, not 1. + */ +static const uint8_t KeyPermuteMap[56] = + { + 49, 42, 35, 28, 21, 14, 7, 0, + 50, 43, 36, 29, 22, 15, 8, 1, + 51, 44, 37, 30, 23, 16, 9, 2, + 52, 45, 38, 31, 55, 48, 41, 34, + 27, 20, 13, 6, 54, 47, 40, 33, + 26, 19, 12, 5, 53, 46, 39, 32, + 25, 18, 11, 4, 24, 17, 10, 3, + }; + + +/* Key rotation table. + * At the start of each round of encryption, the key is split and each + * 28-bit half is rotated left. The number of bits of rotation per round + * is given in the table below. + */ +static const uint8_t KeyRotation[16] = + { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }; + + +/* Key compression table. + * This table is used to select 48 of the 56 bits of the key. + * The left and right halves of the source text are each 32 bits, + * but they are expanded to 48 bits and the results are XOR'd + * against the compressed (48-bit) key. + */ +static const uint8_t KeyCompression[48] = + { + 13, 16, 10, 23, 0, 4, 2, 27, + 14, 5, 20, 9, 22, 18, 11, 3, + 25, 7, 15, 6, 26, 19, 12, 1, + 40, 51, 30, 36, 46, 54, 29, 39, + 50, 44, 32, 47, 43, 48, 38, 55, + 33, 52, 45, 41, 49, 35, 28, 31 + }; + + +/* Data expansion table. + * This table is used after the data block (64-bits) has been split + * into two 32-bit (4-byte) halves (generally denoted L and R). + * Each 32-bit half is "expanded", using this table, to a 48 bit + * data block, which is then XOR'd with the 48 bit subkey for the + * round. + */ +static const uint8_t DataExpansion[48] = + { + 31, 0, 1, 2, 3, 4, 3, 4, + 5, 6, 7, 8, 7, 8, 9, 10, + 11, 12, 11, 12, 13, 14, 15, 16, + 15, 16, 17, 18, 19, 20, 19, 20, + 21, 22, 23, 24, 23, 24, 25, 26, + 27, 28, 27, 28, 29, 30, 31, 0 + }; + + +/* The (in)famous S-boxes. + * These are used to perform substitutions. + * Six bits worth of input will return four bits of output. + * The four bit values are stored in these tables. Each table has + * 64 entries...and 6 bits provides a number between 0 and 63. + * There are eight S-boxes, one per 6 bits of a 48-bit value. + * Thus, 48 bits are reduced to 32 bits. Obviously, this step + * follows the DataExpansion step. + * + * Note that the literature generally shows this as 8 arrays each + * with four rows and 16 colums. There is a complex formula for + * mapping the 6 bit input values to the correct row and column. + * I've pre-computed that mapping, and the tables below provide + * direct 6-bit input to 4-bit output. See pp 274-274 in Schneier. + */ +static const uint8_t SBox[8][64] = + { + { /* S0 */ + 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, + 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, + 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, + 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13 + }, + { /* S1 */ + 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, + 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, + 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, + 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9 + }, + { /* S2 */ + 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, + 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, + 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, + 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12 + }, + { /* S3 */ + 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, + 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, + 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, + 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14 + }, + { /* S4 */ + 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, + 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, + 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, + 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3 + }, + { /* S5 */ + 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, + 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, + 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, + 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13 + }, + { /* S6 */ + 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, + 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, + 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, + 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12 + }, + { /* S7 */ + 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, + 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, + 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, + 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11 + } + }; + + +/* P-Box permutation. + * This permutation is applied to the result of the S-Box Substitutions. + * It's a straight-forward re-arrangement of the bits. + */ +static const uint8_t PBox[32] = + { + 15, 6, 19, 20, 28, 11, 27, 16, + 0, 14, 22, 25, 4, 17, 30, 9, + 1, 7, 23, 13, 31, 26, 2, 8, + 18, 12, 29, 5, 21, 10, 3, 24 + }; + + +/* Final permutation map. + * This is supposed to be the inverse of the Initial Permutation, + * but there's been a bit of fiddling done. + * As always, the values given are one less than those in the literature + * (because C starts counting from 0, not 1). In addition, the penultimate + * step in DES is to swap the left and right hand sides of the ciphertext. + * The inverse of the Initial Permutation is then applied to produce the + * final result. + * To save a step, the map below does the left/right swap as well as the + * inverse permutation. + */ +static const uint8_t FinalPermuteMap[64] = + { + 7, 39, 15, 47, 23, 55, 31, 63, + 6, 38, 14, 46, 22, 54, 30, 62, + 5, 37, 13, 45, 21, 53, 29, 61, + 4, 36, 12, 44, 20, 52, 28, 60, + 3, 35, 11, 43, 19, 51, 27, 59, + 2, 34, 10, 42, 18, 50, 26, 58, + 1, 33, 9, 41, 17, 49, 25, 57, + 0, 32, 8, 40, 16, 48, 24, 56 + }; + + +/* -------------------------------------------------------------------------- ** + * Macros: + * + * CLRBIT( STR, IDX ) + * Input: STR - (uchar *) pointer to an array of 8-bit bytes. + * IDX - (int) bitwise index of a bit within the STR array + * that is to be cleared (that is, given a value of 0). + * Notes: This macro clears a bit within an array of bits (which is + * built within an array of bytes). + * - The macro converts to an assignment of the form A &= B. + * - The string of bytes is viewed as an array of bits, read from + * highest order bit first. The highest order bit of a byte + * would, therefore, be bit 0 (within that byte). + * + * SETBIT( STR, IDX ) + * Input: STR - (uchar *) pointer to an array of 8-bit bytes. + * IDX - (int) bitwise index of a bit within the STR array + * that is to be set (that is, given a value of 1). + * Notes: This macro sets a bit within an array of bits (which is + * built within an array of bytes). + * - The macro converts to an assignment of the form A |= B. + * - The string of bytes is viewed as an array of bits, read from + * highest order bit first. The highest order bit of a byte + * would, therefore, be bit 0 (within that byte). + * + * GETBIT( STR, IDX ) + * Input: STR - (uchar *) pointer to an array of 8-bit bytes. + * IDX - (int) bit-wise index of a bit within the STR array + * that is to be read. + * Output: True (1) if the indexed bit was set, else false (0). + * + * -------------------------------------------------------------------------- ** + */ + +#define CLRBIT( STR, IDX ) ( (STR)[(IDX)/8] &= ~(0x01 << (7 - ((IDX)%8))) ) + +#define SETBIT( STR, IDX ) ( (STR)[(IDX)/8] |= (0x01 << (7 - ((IDX)%8))) ) + +#define GETBIT( STR, IDX ) (( ((STR)[(IDX)/8]) >> (7 - ((IDX)%8)) ) & 0x01) + + +/* -------------------------------------------------------------------------- ** + * Static Functions: + */ + +static void Permute( uchar *dst, + const uchar *src, + const uint8_t *map, + const int mapsize ) + /* ------------------------------------------------------------------------ ** + * Performs a DES permutation, which re-arranges the bits in an array of + * bytes. + * + * Input: dst - Destination into which to put the re-arranged bits. + * src - Source from which to read the bits. + * map - Permutation map. + * mapsize - Number of bytes represented by the . This also + * represents the number of bytes to be copied to . + * + * Output: none. + * + * Notes: and must not point to the same location. + * + * - No checks are done to ensure that there is enough room + * in , or that the bit numbers in do not exceed + * the bits available in . A good reason to make this + * function static (private). + * + * - The value is in bytes. All permutations in DES + * use tables that are a multiple of 8 bits, so there is no + * need to handle partial bytes. (Yes, I know that there + * are some machines out there that still use bytes of a size + * other than 8 bits. For our purposes we'll stick with 8-bit + * bytes.) + * + * ------------------------------------------------------------------------ ** + */ + { + int bitcount; + int i; + + /* Clear all bits in the destination. + */ + for( i = 0; i < mapsize; i++ ) + dst[i] = 0; + + /* Set destination bit if the mapped source bit it set. */ + bitcount = mapsize * 8; + for( i = 0; i < bitcount; i++ ) + { + if( GETBIT( src, map[i] ) ) + SETBIT( dst, i ); + } + } /* Permute */ + + +static void KeyShift( uchar *key, const int numbits ) + /* ------------------------------------------------------------------------ ** + * Split the 56-bit key in half & left rotate each half by bits. + * + * Input: key - The 56-bit key to be split-rotated. + * numbits - The number of bits by which to rotate the key. + * + * Output: none. + * + * Notes: There are probably several better ways to implement this. + * + * ------------------------------------------------------------------------ ** + */ + { + int i; + uchar keep = key[0]; /* Copy the highest order bits of the key. */ + + /* Repeat the shift process times. + */ + for( i = 0; i < numbits; i++ ) + { + int j; + + /* Shift the entire thing, byte by byte. + */ + for( j = 0; j < 7; j++ ) + { + if( j && (key[j] & 0x80) ) /* If the top bit of this byte is set. */ + key[j-1] |= 0x01; /* ...shift it to last byte's low bit. */ + key[j] <<= 1; /* Then left-shift the whole byte. */ + } + + /* Now move the high-order bits of each 28-bit half-key to their + * correct locations. + * Bit 27 is the lowest order bit of the first half-key. + * Before the shift, it was the highest order bit of the 2nd half-key. + */ + if( GETBIT( key, 27 ) ) /* If bit 27 is set... */ + { + CLRBIT( key, 27 ); /* ...clear bit 27. */ + SETBIT( key, 55 ); /* ...set lowest order bit of 2nd half-key. */ + } + + /* We kept the highest order bit of the first half-key in . + * If it's set, copy it to bit 27. + */ + if( keep & 0x80 ) + SETBIT( key, 27 ); + + /* Rotate the byte too, in case is 2 and there's + * a second round coming. + */ + keep <<= 1; + } + } /* KeyShift */ + + +static void sbox( uchar *dst, const uchar *src ) + /* ------------------------------------------------------------------------ ** + * Perform S-Box substitutions. + * + * Input: dst - Destination byte array into which the S-Box substituted + * bitmap will be written. + * src - Source byte array. + * + * Output: none. + * + * Notes: It's really not possible (for me, anyway) to understand how + * this works without reading one or more detailed explanations. + * Quick overview, though: + * + * After the DataExpansion step (in which a 32-bit bit array is + * expanded to a 48-bit bit array) the expanded data block is + * XOR'd with 48-bits worth of key. That 48 bits then needs to + * be condensed back into 32 bits. + * + * The S-Box substitution handles the data reduction by breaking + * the 48-bit value into eight 6-bit values. For each of these + * 6-bit values there is a table (an S-Box table). The table + * contains 64 possible values. Conveniently, a 6-bit integer + * can represent a value between 0 and 63. + * + * So, if you think of the 48-bit bit array as an array of 6-bit + * integers, you use S-Box table 0 with the 0th 6-bit value. + * Table 1 is used with the 6-bit value #1, and so on until #7. + * Within each table, the correct substitution is found based + * simply on the value of the 6-bit integer. + * + * Well, the original algorithm (and most documentation) don't + * make it so simple. There's a complex formula for mapping + * the 6-bit values to the correct substitution. Fortunately, + * those lookups can be precomputed (and have been for this + * implementation). See pp 274-274 in Schneier. + * + * Oh, and the substitute values are all 4-bit values, so each + * 6-bits gets reduced to 4-bits resulting in a 32-bit bit array. + * + * ------------------------------------------------------------------------ ** + */ + { + int i; + + /* Clear the destination array. + */ + for( i = 0; i < 4; i++ ) + dst[i] = 0; + + /* For each set of six input bits... + */ + for( i = 0; i < 8; i++ ) + { + int j; + int Snum; + int bitnum; + + /* Extract the 6-bit integer from the source. + * This will be the lookup key within the SBox[i] array. + */ + for( Snum = j = 0, bitnum = (i * 6); j < 6; j++, bitnum++ ) + { + Snum <<= 1; + Snum |= GETBIT( src, bitnum ); + } + + /* Find the correct value in the correct SBox[] + * and copy it into the destination. + * Left shift the nibble four bytes for even values of . + */ + if( 0 == (i%2) ) + dst[i/2] |= ((SBox[i][Snum]) << 4); + else + dst[i/2] |= SBox[i][Snum]; + } + } /* sbox */ + + +static void xor( uchar *dst, const uchar *a, const uchar *b, const int count ) + /* ------------------------------------------------------------------------ ** + * Perform an XOR operation on two byte arrays. + * + * Input: dst - Destination array to which the result will be written. + * a - The first string of bytes. + * b - The second string of bytes. + * count - Number of bytes to XOR against one another. + * + * Output: none. + * + * Notes: This function operates on whole byte chunks. There's no need + * to XOR partial bytes so no need to write code to handle it. + * + * - This function essentially implements dst = a ^ b; for byte + * arrays. + * + * - may safely point to the same location as or . + * + * ------------------------------------------------------------------------ ** + */ + { + int i; + + for( i = 0; i < count; i++ ) + dst[i] = a[i] ^ b[i]; + } /* xor */ + + +/* -------------------------------------------------------------------------- ** + * Functions: + */ + +uchar *auth_DESkey8to7( uchar *dst, const uchar *key ) + /* ------------------------------------------------------------------------ ** + * Compress an 8-byte DES key to its 7-byte form. + * + * Input: dst - Pointer to a memory location (minimum 7 bytes) to accept + * the compressed key. + * key - Pointer to an 8-byte DES key. See the notes below. + * + * Output: A pointer to the compressed key (same as ) or NULL if + * either or were NULL. + * + * Notes: There are no checks done to ensure that and point + * to sufficient space. Please be carefull. + * + * The two pointers, and may point to the same + * memory location. Internally, a temporary buffer is used and + * the results are copied back to . + * + * The DES algorithm uses 8 byte keys by definition. The first + * step in the algorithm, however, involves removing every eigth + * bit to produce a 56-bit key (seven bytes). SMB authentication + * skips this step and uses 7-byte keys. The + * algorithm in this module expects 7-byte keys. This function + * is used to convert an 8-byte DES key into a 7-byte SMB DES key. + * + * ------------------------------------------------------------------------ ** + */ + { + int i; + uchar tmp[7]; + static const uint8_t map8to7[56] = + { + 0, 1, 2, 3, 4, 5, 6, + 8, 9, 10, 11, 12, 13, 14, + 16, 17, 18, 19, 20, 21, 22, + 24, 25, 26, 27, 28, 29, 30, + 32, 33, 34, 35, 36, 37, 38, + 40, 41, 42, 43, 44, 45, 46, + 48, 49, 50, 51, 52, 53, 54, + 56, 57, 58, 59, 60, 61, 62 + }; + + if( (NULL == dst) || (NULL == key) ) + return( NULL ); + + Permute( tmp, key, map8to7, 7 ); + for( i = 0; i < 7; i++ ) + dst[i] = tmp[i]; + + return( dst ); + } /* auth_DESkey8to7 */ + + +uchar *auth_DEShash( uchar *dst, const uchar *key, const uchar *src ) + /* ------------------------------------------------------------------------ ** + * DES encryption of the input data using the input key. + * + * Input: dst - Destination buffer. It *must* be at least eight bytes + * in length, to receive the encrypted result. + * key - Encryption key. Exactly seven bytes will be used. + * If your key is shorter, ensure that you pad it to seven + * bytes. + * src - Source data to be encrypted. Exactly eight bytes will + * be used. If your source data is shorter, ensure that + * you pad it to eight bytes. + * + * Output: A pointer to the encrpyted data (same as ). + * + * Notes: In SMB, the DES function is used as a hashing function rather + * than an encryption/decryption tool. When used for generating + * the LM hash the input is the known value "KGS!@#$%" and + * the key is derived from the password entered by the user. + * When used to generate the LM or NTLM response, the is + * derived from the LM or NTLM hash, and the challenge is used + * as the input. + * See: http://ubiqx.org/cifs/SMB.html#SMB.8.3 + * + * - This function is called "DEShash" rather than just "DES" + * because it is only used for creating LM hashes and the + * LM/NTLM responses. For all practical purposes, however, it + * is a full DES encryption implementation. + * + * - This DES implementation does not need to be fast, nor is a + * DES decryption function needed. The goal is to keep the + * code small, simple, and well documented. + * + * - The input values are copied and refiddled within the module + * and the result is not written to until the very last + * step, so it's okay if points to the same memory as + * or . + * + * ------------------------------------------------------------------------ ** + */ + { + int i; /* Loop counter. */ + uchar K[7]; /* Holds the key, as we manipulate it. */ + uchar D[8]; /* The data block, as we manipulate it. */ + + /* Create the permutations of the key and the source. + */ + Permute( K, key, KeyPermuteMap, 7 ); + Permute( D, src, InitialPermuteMap, 8 ); + + /* DES encryption proceeds in 16 rounds. + * The stuff inside the loop is known in the literature as "function f". + */ + for( i = 0; i < 16; i++ ) + { + int j; + uchar *L = D; /* The left 4 bytes (half) of the data block. */ + uchar *R = &(D[4]); /* The right half of the ciphertext block. */ + uchar Rexp[6]; /* Expanded right half. */ + uchar Rn[4]; /* New value of R, as we manipulate it. */ + uchar SubK[6]; /* The 48-bit subkey. */ + + /* Generate the subkey for this round. + */ + KeyShift( K, KeyRotation[i] ); + Permute( SubK, K, KeyCompression, 6 ); + + /* Expand the right half (R) of the data block to 48 bytes, + * then XOR the result with the Subkey for this round. + */ + Permute( Rexp, R, DataExpansion, 6 ); + xor( Rexp, Rexp, SubK, 6 ); + + /* S-Box substitutions, P-Box permutation, and final XOR. + * The S-Box substitutions return a 32-bit value, which is then + * run through the 32-bit to 32-bit P-Box permutation. The P-Box + * result is then XOR'd with the left-hand half of the key. + * (Rexp is used as a temporary variable between the P-Box & XOR). + */ + sbox( Rn, Rexp ); + Permute( Rexp, Rn, PBox, 4 ); + xor( Rn, L, Rexp, 4 ); + + /* The previous R becomes the new L, + * and Rn is moved into R ready for the next round. + */ + for( j = 0; j < 4; j++ ) + { + L[j] = R[j]; + R[j] = Rn[j]; + } + } + + /* The encryption is complete. + * Now reverse-permute the ciphertext to produce the final result. + * We actually combine two steps here. The penultimate step is to + * swap the positions of L and R in the result of the 16 rounds, + * after which the reverse of the Initial Permutation is applied. + * To save a step, the FinalPermuteMap applies both the L/R swap + * and the inverse of the Initial Permutation. + */ + Permute( dst, D, FinalPermuteMap, 8 ); + return( dst ); + } /* auth_DEShash */ + +/* ========================================================================== */ diff --git a/source/smb/DES.h b/source/smb/DES.h new file mode 100644 index 00000000..d1b7f2e4 --- /dev/null +++ b/source/smb/DES.h @@ -0,0 +1,179 @@ +#ifndef AUTH_DES_H +#define AUTH_DES_H +/* ========================================================================== ** + * + * DES.h + * + * Copyright: + * Copyright (C) 2003, 2004 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * $Id: DES.h,v 0.5 2004/05/30 02:31:47 crh Exp $ + * + * -------------------------------------------------------------------------- ** + * + * Description: + * + * Implements DES encryption, but not decryption. + * DES is used to create LM password hashes and both LM and NTLM Responses. + * + * -------------------------------------------------------------------------- ** + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- ** + * + * Notes: + * + * This implementation was created by studying many existing examples + * found in Open Source, in the public domain, and in various documentation. + * The SMB protocol makes minimal use of the DES function, so this is a + * minimal implementation. That which is not required has been removed. + * + * The SMB protocol uses the DES algorithm as a hash function, not an + * encryption function. The auth_DEShash() implemented here is a one-way + * function. The reverse is not implemented in this module. Also, there + * is no attempt at making this either fast or efficient. There is no + * need, as the auth)DEShash() function is used for generating the LM + * Response from a 7-byte key and an 8-byte challenge. It is not intended + * for use in encrypting large blocks of data or data streams. + * + * As stated above, this implementation is based on studying existing work + * in the public domain or under Open Source (specifically LGPL) license. + * The code, however, is written from scratch. Obviously, I make no claim + * with regard to those earlier works (except to claim that I am grateful + * to the previous implementors whose work I studied). See the list of + * references below for resources I used. + * + * References: + * I read through the libmcrypt code to see how they put the pieces + * together. See: http://mcrypt.hellug.gr/ + * Libmcrypt is available under the terms of the LGPL. + * + * The libmcrypt implementation includes the following credits: + * written 12 Dec 1986 by Phil Karn, KA9Q; large sections adapted + * from the 1977 public-domain program by Jim Gillogly + * Modified for additional speed - 6 December 1988 Phil Karn + * Modified for parameterized key schedules - Jan 1991 Phil Karn + * modified in order to use the libmcrypt API by Nikos Mavroyanopoulos + * All modifications are placed under the license of libmcrypt. + * + * See also Phil Karn's privacy and security page: + * http://www.ka9q.net/privacy.html + * + * I relied heavily upon: + * Applied Cryptography, Second Edition: + * Protocols, Algorithms, and Source Code in C + * by Bruce Schneier. ISBN 0-471-11709-9, John Wiley & Sons, Inc., 1996 + * Particularly Chapter 12. + * + * Here's one more DES resource, which I found quite helpful (aside from + * the Clinton jokes): + * http://www.aci.net/kalliste/des.htm + * + * Finally, the use of DES in SMB is covered in: + * Implementing CIFS - the Common Internet File System + * by your truly. ISBN 0-13-047116-X, Prentice Hall PTR., August 2003 + * Section 15.3, in particular. + * (Online at: http://ubiqx.org/cifs/SMB.html#SMB.8.3) + * + * ========================================================================== ** + */ + +//#include "auth_common.h" +#include +typedef unsigned char uchar; +typedef unsigned char uint8_t; + +/* -------------------------------------------------------------------------- ** + * Functions: + */ + +uchar *auth_DESkey8to7( uchar *dst, const uchar *key ); + /* ------------------------------------------------------------------------ ** + * Compress an 8-byte DES key to its 7-byte form. + * + * Input: dst - Pointer to a memory location (minimum 7 bytes) to accept + * the compressed key. + * key - Pointer to an 8-byte DES key. See the notes below. + * + * Output: A pointer to the compressed key (same as ) or NULL if + * either or were NULL. + * + * Notes: There are no checks done to ensure that and point + * to sufficient space. Please be carefull. + * + * The two pointers, and may point to the same + * memory location. Internally, a temporary buffer is used and + * the results are copied back to . + * + * The DES algorithm uses 8 byte keys by definition. The first + * step in the algorithm, however, involves removing every eigth + * bit to produce a 56-bit key (seven bytes). SMB authentication + * skips this step and uses 7-byte keys. The + * algorithm in this module expects 7-byte keys. This function + * is used to convert an 8-byte DES key into a 7-byte SMB DES key. + * + * ------------------------------------------------------------------------ ** + */ + + +uchar *auth_DEShash( uchar *dst, const uchar *key, const uchar *src ); + /* ------------------------------------------------------------------------ ** + * DES encryption of the input data using the input key. + * + * Input: dst - Destination buffer. It *must* be at least eight bytes + * in length, to receive the encrypted result. + * key - Encryption key. Exactly seven bytes will be used. + * If your key is shorter, ensure that you pad it to seven + * bytes. + * src - Source data to be encrypted. Exactly eight bytes will + * be used. If your source data is shorter, ensure that + * you pad it to eight bytes. + * + * Output: A pointer to the encrpyted data (same as ). + * + * Notes: In SMB, the DES function is used as a hashing function rather + * than an encryption/decryption tool. When used for generating + * the LM hash the input is the known value "KGS!@#$%" and + * the key is derived from the password entered by the user. + * When used to generate the LM or NTLM response, the is + * derived from the LM or NTLM hash, and the challenge is used + * as the input. + * See: http://ubiqx.org/cifs/SMB.html#SMB.8.3 + * + * - This function is called "DEShash" rather than just "DES" + * because it is only used for creating LM hashes and the + * LM/NTLM responses. For all practical purposes, however, it + * is a full DES encryption implementation. + * + * - This DES implementation does not need to be fast, nor is a + * DES decryption function needed. The goal is to keep the + * code small, simple, and well documented. + * + * - The input values are copied and refiddled within the module + * and the result is not written to until the very last + * step, so it's okay if points to the same memory as + * or . + * + * ------------------------------------------------------------------------ ** + */ + + +/* ========================================================================== */ +#endif /* AUTH_DES_H */ diff --git a/source/smb/LMhash.c b/source/smb/LMhash.c new file mode 100644 index 00000000..20cc6b64 --- /dev/null +++ b/source/smb/LMhash.c @@ -0,0 +1,169 @@ +/* ========================================================================== ** + * + * LMhash.c + * + * Copyright: + * Copyright (C) 2004 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * $Id: LMhash.c,v 0.1 2004/05/30 02:26:31 crh Exp $ + * + * -------------------------------------------------------------------------- ** + * + * Description: + * + * Implemention of the LAN Manager hash (LM hash) and LM response + * algorithms. + * + * -------------------------------------------------------------------------- ** + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- ** + * + * Notes: + * + * This module implements the LM hash. The NT hash is simply the MD4() of + * the password, so we don't need a separate implementation of that. This + * module also implements the LM response, which can be combined with the + * NT hash to produce the NTLM response. + * + * This implementation was created based on the description in my own book. + * The book description was, in turn, written after studying many existing + * examples in various documentation. Jeremy Allison and Andrew Tridgell + * deserve lots of credit for having figured out the secrets of Lan Manager + * authentication many years ago. + * + * See: + * Implementing CIFS - the Common Internet File System + * by your truly. ISBN 0-13-047116-X, Prentice Hall PTR., August 2003 + * Section 15.3, in particular. + * (Online at: http://ubiqx.org/cifs/SMB.html#SMB.8.3) + * + * ========================================================================== ** + */ + +#include "DES.h" +#include "LMhash.h" + + +/* -------------------------------------------------------------------------- ** + * Static Constants: + * + * SMB_LMhash_Magic - This is the plaintext "magic string" that is used to + * generate the LM Hash from the user's password. This + * value was a Microsoft "secret" for many years. + */ + +static const uchar SMB_LMhash_Magic[8] = + { 'K', 'G', 'S', '!', '@', '#', '$', '%' }; + + +/* -------------------------------------------------------------------------- ** + * Functions: + */ + +uchar *auth_LMhash( uchar *dst, const uchar *pwd, const int pwdlen ) + /* ------------------------------------------------------------------------ ** + * Generate an LM Hash from the input password. + * + * Input: dst - Pointer to a location to which to write the LM Hash. + * Requires 16 bytes minimum. + * pwd - Source password. Should be in OEM charset (extended + * ASCII) format in all upper-case, but this + * implementation doesn't really care. See the notes + * below. + * pwdlen - Length, in bytes, of the password. Normally, this + * will be strlen( pwd ). + * + * Output: Pointer to the resulting LM hash (same as ). + * + * Notes: This function does not convert the input password to upper + * case. The upper-case conversion should be done before the + * password gets this far. DOS codepage handling and such + * should be taken into consideration. Rather than attempt to + * work out all those details here, the function assumes that + * the password is in the correct form before it reaches this + * point. + * + * ------------------------------------------------------------------------ ** + */ + { + int i, + max14; + uint8_t tmp_pwd[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; + + /* Copy at most 14 bytes of into . + * If the password is less than 14 bytes long + * the rest will be nul padded. + */ + max14 = pwdlen > 14 ? 14 : pwdlen; + for( i = 0; i < max14; i++ ) + tmp_pwd[i] = pwd[i]; + + /* The password is split into two 7-byte keys, each of which + * are used to DES-encrypt the magic string. The results are + * concatonated to produce the 16-byte LM Hash. + */ + (void)auth_DEShash( dst, tmp_pwd, SMB_LMhash_Magic ); + (void)auth_DEShash( &dst[8], &tmp_pwd[7], SMB_LMhash_Magic ); + + /* Return a pointer to the result. + */ + return( dst ); + } /* auth_LMhash */ + + +uchar *auth_LMresponse( uchar *dst, const uchar *hash, const uchar *challenge ) + /* ------------------------------------------------------------------------ ** + * Generate the LM (or NTLM) response from the password hash and challenge. + * + * Input: dst - Pointer to memory into which to write the response. + * Must have 24 bytes available. + * hash - Pointer to the 16-byte password hash. + * challenge - Pointer to the 8-byte challenge. + * + * Output: A pointer to the 24-byte response (same as ). + * + * Notes: The function does not check the lengths of the input or output + * parameters. The byte sizes given above must be respected by + * calling function. + * + * ------------------------------------------------------------------------ ** + */ + { + uchar tmp[7] = + { hash[14], hash[15], 0,0,0,0,0 }; /* 3rd key is nul-padded. */ + + /* It's painfully simple... + * The challenge is DES encrypted three times. + * The first time, the first 7 bytes of the hash are used. + * The second time, the second 7 bytes of the hash are used. + * The third time, the two remaining hash bytes plus five nuls are used. + * The three 8-byte results are concatonated to form the 24-byte response. + */ + (void)auth_DEShash( dst, hash, challenge ); + (void)auth_DEShash( &dst[8], &hash[7], challenge ); + (void)auth_DEShash( &dst[16], tmp, challenge ); + + /* Return the result. + */ + return( dst ); + } /* auth_LMresponse */ + +/* ========================================================================== */ diff --git a/source/smb/LMhash.h b/source/smb/LMhash.h new file mode 100644 index 00000000..ad94f6ad --- /dev/null +++ b/source/smb/LMhash.h @@ -0,0 +1,115 @@ +#ifndef AUTH_LMHASH_H +#define AUTH_LMHASH_H +/* ========================================================================== ** + * + * LMhash.h + * + * Copyright: + * Copyright (C) 2004 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * $Id: LMhash.h,v 0.1 2004/05/30 02:26:31 crh Exp $ + * + * -------------------------------------------------------------------------- ** + * + * Description: + * + * Implemention of the LAN Manager hash (LM hash) and LM response + * algorithms. + * + * -------------------------------------------------------------------------- ** + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * -------------------------------------------------------------------------- ** + * + * Notes: + * + * This module implements the LM hash. The NT hash is simply the MD4() of + * the password, so we don't need a separate implementation of that. This + * module also implements the LM response, which can be combined with the + * NT hash to produce the NTLM response. + * + * This implementation was created based on the description in my own book. + * The book description was, in turn, written after studying many existing + * examples in various documentation. Jeremy Allison and Andrew Tridgell + * deserve lots of credit for having figured out the secrets of Lan Manager + * authentication many years ago. + * + * See: + * Implementing CIFS - the Common Internet File System + * by your truly. ISBN 0-13-047116-X, Prentice Hall PTR., August 2003 + * Section 15.3, in particular. + * (Online at: http://ubiqx.org/cifs/SMB.html#SMB.8.3) + * + * ========================================================================== ** + */ + + +/* -------------------------------------------------------------------------- ** + * Functions: + */ + +uchar *auth_LMhash( uchar *dst, const uchar *pwd, const int pwdlen ); + /* ------------------------------------------------------------------------ ** + * Generate an LM Hash from the input password. + * + * Input: dst - Pointer to a location to which to write the LM Hash. + * Requires 16 bytes minimum. + * pwd - Source password. Should be in OEM charset (extended + * ASCII) format in all upper-case, but this + * implementation doesn't really care. See the notes + * below. + * pwdlen - Length, in bytes, of the password. Normally, this + * will be strlen( pwd ). + * + * Output: Pointer to the resulting LM hash (same as ). + * + * Notes: This function does not convert the input password to upper + * case. The upper-case conversion should be done before the + * password gets this far. DOS codepage handling and such + * should be taken into consideration. Rather than attempt to + * work out all those details here, the function assumes that + * the password is in the correct form before it reaches this + * point. + * + * ------------------------------------------------------------------------ ** + */ + + +uchar *auth_LMresponse( uchar *dst, const uchar *hash, const uchar *challenge ); + /* ------------------------------------------------------------------------ ** + * Generate the LM (or NTLM) response from the password hash and challenge. + * + * Input: dst - Pointer to memory into which to write the response. + * Must have 24 bytes available. + * hash - Pointer to the 16-byte password hash. + * challenge - Pointer to the 8-byte challenge. + * + * Output: A pointer to the 24-byte response (same as ). + * + * Notes: The function does not check the lengths of the input or output + * parameters. The byte sizes given above must be respected by + * calling function. + * + * ------------------------------------------------------------------------ ** + */ + + +/* ========================================================================== */ +#endif /* AUTH_LMHASH_H */ diff --git a/source/smb/readme1st.txt b/source/smb/readme1st.txt new file mode 100644 index 00000000..8e6e1bc3 --- /dev/null +++ b/source/smb/readme1st.txt @@ -0,0 +1,112 @@ +TinySMB-GC 0.1 +May 2006 + +Developer Documentation + +What is TinySMB-GC? + +TinySMB-GC is a minimal implementation of the SMB protocol for the Nintendo Gamecube. + +What does it do? + +Essentially, TinySMB-GC enables network share support. This means that it will allow the +GameCube to connect to a shared folder on a Windows XP or linux samba box, and perform +basic file functions. + +Known Restrictions + +TinySMB-GC only supports the LM1.2X002 protocol. THIS IS NOT THE MOST SECURE! +However, it does NOT transmit your password over the wire, so it's reasonably safe. + +How do I use it? + +TinySMB-GC is developed with devkitPPC and libOGC, therefore you should be using this +development environment. Put simply, it won't work with anything else! + +TinySMB-GC uses the TCP-raw form of SMB on port 445. + +The Functions. + +int SMB_Init (char *user, /*** The logon user - MUST have share access rights ***/ + char *password, /*** PLEASE USE PASSWORD SECURITY! ***/ + char *client, /*** Machine ID, whatever you want to call the GC ***/ + char *server, /*** Machine ID of share server ***/ + char *share, /*** Share ID ***/ + char *IP); /*** IP of share server ***/ + +SMB_Init is used to establish the connection, authenticate and attach to the share. +Obviously, this must be called successfully before any other function. + +void SMB_Destroy (); + +SMB_Destroy takes care of releasing the internal socket of TinySMB-GC and should be +called when the SMB functions are no longer required. + +int SMB_FindFirst (char *filename, /*** The file mask to search for ***/ + unsigned short flags, /*** Search criteria flags ***/ + SMBDIRENTRY * sdir); /*** An SMBDIRENTRY to hold directory information ***/ + +Similar to MS-Windows, to search for a file or directory, use this function to determine if the +file already exists. The SMBDIRENTRY simply holds basic information on each entry retrieved. + +int SMB_FindNext (SMBDIRENTRY * sdir); + +Called to continue a search started with SMB_FindFirst. + +int SMB_FindClose (); + +When all searches have completed, call SMB_FindClose to dispense with the search handle. + +SMBFILE SMB_Open (char *filename, /*** The filename to open ***/ + unsigned short access, /*** Access method ***/ + unsigned short creation); /*** Creation flags ***/ + +This call will open a file on the share. Both reading and writing are supported. +Look at smb.h for information on the access and creation flags. + +void SMB_Close (SMBFILE sfid); + +Close a file previously opened with SMB_Open + +int SMB_Read (char *buffer, int size, int offset, SMBFILE sfile); + +Read from the file opened with SMB_Open. + +int SMB_Write (char *buffer, int size, int offset, SMBFILE sfile); + +Write to the file opened with SMB_Open. + +NOTE: The offset value provides the missing seek function. However, the onus +is on the developer to maintain the offset value when reading / writing +sequentially. + +You should also be aware that these functions should only be used to read/write +blocks up to 62Kbytes. Although it allows reading and writing of 4Gb files, it +does not support blocks larger then 16-bit - go figure! + +Credits + +TinySMB-GC Copyright softdev@tehskeen.com + Please respect this copyright! + NOTE WELL: This software is released under GPL 2.1 + YOU MAY NOT STEAL IT AND HIDE IT IN YOUR + CLOSED SOURCE PRODUCT. + +libOGC shagkur + +devkitPPC wntrmute + +CIFS Info Christopher R Hertel + http://www.ubiqx.com + Storage Networking Industry Association + http://www.snia.com + Ethereal - Packet Capture + http://www.ethereal.com + +Thanks + +Cedy_NL, for testing and helping get this off the ground. +brakken, web hosting and promotion. + +Everyone who has participated in the Genesis Plus Project - keep up the good work ! + \ No newline at end of file diff --git a/source/smb/smb.c b/source/smb/smb.c new file mode 100644 index 00000000..4d9a5b89 --- /dev/null +++ b/source/smb/smb.c @@ -0,0 +1,932 @@ +/**************************************************************************** + * TinySMB-GC + * + * Nintendo Gamecube SaMBa implementation. + * + * Copyright softdev@tehskeen.com + * + * Authentication modules, LMhash and DES are + * + * Copyright Christopher R Hertel. + * http://www.ubiqx.org + * + * You WILL find Ethereal, available from http://www.ethereal.com + * invaluable for debugging each new SAMBA implementation. + * + * Recommended Reading + * Implementing CIFS - Christopher R Hertel + * SNIA CIFS Documentation - http://www.snia.org + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ****************************************************************************/ + +#include +#include +#include "smb.h" +#include "DES.h" +#include "LMhash.h" +#include + +/** + * A few little bits for libOGC + */ +typedef int SOCKET; +#define recv net_recv +#define send net_send +#define closesocket net_close +#define connect net_connect +#define setsockopt net_setsockopt +#define socket net_socket + +/** + * Client and server SMB + */ +NBTSMB c; +NBTSMB s; +SMBSESSION session; +SOCKET smbsock; +static struct sockaddr_in smbs; +static int smbcheckbytes = 0; + +/** + * SMB Endian aware supporting functions + * + * SMB always uses Intel Little-Endian values, so htons etc are + * of little or no use :) ... Thanks M$ + */ +/*** get unsigned char ***/ +static unsigned char +getUChar (unsigned char *buffer, int offset) +{ + return buffer[offset]; +} + +/*** set unsigned char ***/ +static void +setUChar (unsigned char *buffer, int offset, unsigned char value) +{ + buffer[offset] = value; +} + +/*** get unsigned short ***/ +static unsigned short +getUShort (unsigned char *buffer, int offset) +{ + unsigned short t; + t = buffer[offset]; + t |= (buffer[offset + 1] << 8); + + return t; +} + +/*** set unsigned short ***/ +static void +setUShort (unsigned char *buffer, int offset, unsigned short value) +{ + buffer[offset] = value & 0xff; + buffer[offset + 1] = (value & 0xff00) >> 8; +} + +/*** get unsigned int ***/ +static unsigned int +getUInt (unsigned char *buffer, int offset) +{ + unsigned int t; + + t = buffer[offset]; + t |= (buffer[offset + 1] << 8); + t |= (buffer[offset + 2] << 16); + t |= (buffer[offset + 3] << 24); + + return t; +} + +/*** set unsigned int ***/ +static void +setUInt (unsigned char *buffer, int offset, int value) +{ + buffer[offset] = value & 0xff; + buffer[offset + 1] = (value & 0xff00) >> 8; + buffer[offset + 2] = (value & 0xff0000) >> 16; + buffer[offset + 3] = (value & 0xff000000) >> 24; +} + +/** + * MakeSMBHdr + * + * Generate the SMB header for each request. + * Uses 'c' NBTSMB + */ +static void +MakeSMBHdr (unsigned char command) +{ + int pos = 0; + + /*** Clear client packet ***/ + memset (&c, 0, sizeof (c)); + + /*** Add protocol SMB ***/ + setUInt (c.smb, pos, SMB_PROTO); + pos += 4; + setUChar (c.smb, pos, command); + pos++; + pos++; /*** Error class ***/ + pos++; /*** Reserved ***/ + pos += 2; /*** Error Code ***/ + setUChar (c.smb, pos, 0x8); + pos++; /*** Flags == 8 == Case Insensitive ***/ + setUShort (c.smb, pos, 0x1); + pos += 2; /*** Flags2 == 1 == LFN ***/ + pos += 2; /*** Process ID High ***/ + pos += 8; /*** Signature ***/ + pos += 2; /*** Reserved ***/ + setUShort (c.smb, pos, session.TID); + pos += 2; + setUShort (c.smb, pos, session.PID); + pos += 2; + setUShort (c.smb, pos, session.UID); + pos += 2; + setUShort (c.smb, pos, session.MID); +} + +/** + * MakeTRANS2Hdr + */ +static void +MakeTRANS2Hdr (unsigned char subcommand) +{ + setUChar (c.smb, T2_WORD_CNT, 15); + setUShort (c.smb, T2_MAXPRM_CNT, 10); + setUShort (c.smb, T2_MAXBUFFER, session.MaxBuffer); + setUChar (c.smb, T2_SSETUP_CNT, 1); + setUShort (c.smb, T2_SUB_CMD, subcommand); +} + +/** + * SMBCheck + * + * Do very basic checking on the return SMB + */ +static int +SMBCheck (unsigned char command, int readlen) +{ + int ret; + + memset (&s, 0, sizeof (s)); + + smbcheckbytes = ret = recv (smbsock, (char *) &s, readlen, 0); + + if (ret < 12) + return 0; + + /*** Do basic SMB Header checks ***/ + ret = getUInt (s.smb, 0); + if (ret != SMB_PROTO) + return BAD_PROTOCOL; + + if (getUChar (s.smb, 4) != command) + return SMB_BAD_COMMAND; + + ret = getUInt (s.smb, SMB_OFFSET_NTSTATUS); + + if (ret) + return SMB_ERROR; + + return SMB_SUCCESS; + +} + +/** + * SMB_NegotiateProtocol + * + * The only protocol we admit to is 'DOS LANMAN 2.1' + */ +static int +SMB_NegotiateProtocol () +{ + int pos; + int bcpos; + int ret; + char proto[] = "\2LM1.2X002"; /*** Seems to work with Samba and XP Home ***/ + unsigned short bytecount; + + /*** Clear session variables ***/ + memset (&session, 0, sizeof (session)); + session.PID = 0xdead; + session.MID = 1; + + MakeSMBHdr (SMB_NEG_PROTOCOL); + pos = SMB_HEADER; + + pos++; /*** Add word count ***/ + bcpos = pos; + pos += 2; /*** Byte count - when known ***/ + + strcpy (&c.smb[pos], proto); + + pos += strlen (proto) + 1; + + /*** Update byte count ***/ + setUShort (c.smb, bcpos, (pos - bcpos) - 2); + + /*** Set NBT information ***/ + c.msg = SESS_MSG; + c.length = htons (pos); + + pos += 4; + ret = send (smbsock, (char *) &c, pos, 0); + + /*** Check response ***/ + if (SMBCheck (SMB_NEG_PROTOCOL, sizeof (s)) == SMB_SUCCESS) + { + pos = SMB_HEADER; + /*** Collect information ***/ + if (getUChar (s.smb, pos) != 13) + return SMB_PROTO_FAIL; + + pos++; + if (getUShort (s.smb, pos)) + return SMB_PROTO_FAIL; + + pos += 2; + if (getUShort (s.smb, pos) != 3) + return SMB_NOT_USER; + + pos += 2; + session.MaxBuffer = getUShort (s.smb, pos); + pos += 2; + if (session.MaxBuffer > 2916) + session.MaxBuffer = 2916; + session.MaxMpx = getUShort (s.smb, pos); + pos += 2; + session.MaxVCS = getUShort (s.smb, pos); + pos += 2; + pos += 2; /*** Raw Mode ***/ + pos += 4; /*** Session Key ***/ + pos += 6; /*** Time information ***/ + if (getUShort (s.smb, pos) != 8) + return SMB_BAD_KEYLEN; + + pos += 2; + pos += 2; /*** Reserved ***/ + + bytecount = getUShort (s.smb, pos); + pos += 2; + + /*** Copy challenge key ***/ + memcpy (&session.challenge, &s.smb[pos], 8); + pos += 8; + /*** Primary domain ***/ + strcpy (session.p_domain, &s.smb[pos]); + + return SMB_SUCCESS; + } + + return 0; + +} + +/** + * SMB_SetupAndX + * + * Setup the SMB session, including authentication with the + * magic 'LM Response' + */ +static int +SMB_SetupAndX (char *user, char *password) +{ + int pos; + int bcpos; + char pwd[24], LMh[24], LMr[24]; + int i, ret; + + MakeSMBHdr (SMB_SETUP_ANDX); + pos = SMB_HEADER; + + setUChar (c.smb, pos, 10); + pos++; /*** Word Count ***/ + setUChar (c.smb, pos, 0xff); + pos++; /*** Next AndX ***/ + pos++; /*** Reserved ***/ + pos += 2; /*** Next AndX Offset ***/ + setUShort (c.smb, pos, session.MaxBuffer); + pos += 2; + setUShort (c.smb, pos, session.MaxMpx); + pos += 2; + setUShort (c.smb, pos, session.MaxVCS); + pos += 2; + pos += 4; /*** Session key, unknown at this point ***/ + setUShort (c.smb, pos, 24); + pos += 2; /*** Password length ***/ + pos += 4; /*** Reserved ***/ + bcpos = pos; + pos += 2; /*** Byte count ***/ + + /*** The magic 'LM Response' ***/ + strcpy (pwd, password); + for (i = 0; i < strlen (pwd); i++) + pwd[i] = toupper (pwd[i]); + + auth_LMhash (LMh, pwd, strlen (pwd)); + auth_LMresponse (LMr, LMh, session.challenge); + + /*** Build information ***/ + memcpy (&c.smb[pos], LMr, 24); + pos += 24; + + /*** Account ***/ + strcpy (pwd, user); + for (i = 0; i < strlen (user); i++) + pwd[i] = toupper (pwd[i]); + memcpy (&c.smb[pos], pwd, strlen (pwd)); + pos += strlen (pwd) + 1; + + /*** Primary Domain ***/ + memcpy (&c.smb[pos], &session.p_domain, strlen (session.p_domain)); + pos += strlen (session.p_domain) + 1; + + /*** Native OS ***/ + strcpy (pwd, "Unix (libOGC)"); + memcpy (&c.smb[pos], pwd, strlen (pwd)); + pos += strlen (pwd) + 1; + + /*** Native LAN Manager ***/ + strcpy (pwd, "Nintendo GameCube 0.1"); + memcpy (&c.smb[pos], pwd, strlen (pwd)); + pos += strlen (pwd) + 1; + + /*** Update byte count ***/ + setUShort (c.smb, bcpos, (pos - bcpos) - 2); + + c.msg = SESS_MSG; + c.length = htons (pos); + pos += 4; + + ret = send (smbsock, (char *) &c, pos, 0); + + if (SMBCheck (SMB_SETUP_ANDX, sizeof (s)) == SMB_SUCCESS) + { + /*** Collect UID ***/ + session.UID = getUShort (s.smb, SMB_OFFSET_UID); + + return SMB_SUCCESS; + } + + return 0; +} + +/** + * SMB_TreeAndX + * + * Finally, connect to the remote share + */ +static int +SMB_TreeAndX (char *server, char *share) +{ + int pos, bcpos, ret; + char path[256]; + + MakeSMBHdr (SMB_TREEC_ANDX); + pos = SMB_HEADER; + + setUChar (c.smb, pos, 4); + pos++; /*** Word Count ***/ + setUChar (c.smb, pos, 0xff); + pos++; /*** Next AndX ***/ + pos++; /*** Reserved ***/ + pos += 2; /*** Next AndX Offset ***/ + pos += 2; /*** Flags ***/ + setUShort (c.smb, pos, 1); + pos += 2; /*** Password Length ***/ + bcpos = pos; + pos += 2; + pos++; /*** NULL Password ***/ + + /*** Build server share path ***/ + strcpy (path, "\\\\"); + strcat (path, server); + strcat (path, "\\"); + strcat (path, share); + for (ret = 0; ret < strlen (path); ret++) + path[ret] = toupper (path[ret]); + + memcpy (&c.smb[pos], path, strlen (path)); + pos += strlen (path) + 1; + + /*** Service ***/ + strcpy (path, "?????"); + memcpy (&c.smb[pos], path, strlen (path)); + pos += strlen (path) + 1; + + /*** Update byte count ***/ + setUShort (c.smb, bcpos, (pos - bcpos) - 2); + + c.msg = SESS_MSG; + c.length = htons (pos); + pos += 4; + + ret = send (smbsock, (char *) &c, pos, 0); + + if (SMBCheck (SMB_TREEC_ANDX, sizeof (s)) == SMB_SUCCESS) + { + /*** Collect Tree ID ***/ + session.TID = getUShort (s.smb, SMB_OFFSET_TID); + return SMB_SUCCESS; + } + + return 0; +} + +/** + * SMB_FindFirst + * + * Uses TRANS2 to support long filenames + */ +int +SMB_FindFirst (char *filename, unsigned short flags, SMBDIRENTRY * sdir) +{ + int pos; + int ret; + int bpos; + + MakeSMBHdr (SMB_TRANS2); + MakeTRANS2Hdr (SMB_FIND_FIRST2); + pos = T2_BYTE_CNT + 2; + bpos = pos; + pos += 3; /*** Padding ***/ + + setUShort (c.smb, pos, flags); + pos += 2; /*** Flags ***/ + setUShort (c.smb, pos, 1); + pos += 2; /*** Count ***/ + setUShort (c.smb, pos, 6); + pos += 2; /*** Internal Flags ***/ + setUShort (c.smb, pos, 260); + pos += 2; /*** Level of Interest ***/ + pos += 4; /*** Storage Type == 0 ***/ + memcpy (&c.smb[pos], filename, strlen (filename)); + pos += strlen (filename) + 1; /*** Include padding ***/ + + /*** Update counts ***/ + setUShort (c.smb, T2_PRM_CNT, 13 + strlen (filename)); + setUShort (c.smb, T2_SPRM_CNT, 13 + strlen (filename)); + setUShort (c.smb, T2_SPRM_OFS, 68); + setUShort (c.smb, T2_SDATA_OFS, 81 + strlen (filename)); + setUShort (c.smb, T2_BYTE_CNT, pos - bpos); + + c.msg = SESS_MSG; + c.length = htons (pos); + + pos += 4; + + ret = send (smbsock, (char *) &c, pos, 0); + session.sid = 0; + session.count = 0; + session.eos = 1; + + if (SMBCheck (SMB_TRANS2, sizeof (s)) == SMB_SUCCESS) + { + /*** Get parameter offset ***/ + pos = getUShort (s.smb, SMB_HEADER + 9); + session.sid = getUShort (s.smb, pos); + pos += 2; + session.count = getUShort (s.smb, pos); + pos += 2; + session.eos = getUShort (s.smb, pos); + pos += 2; + pos += 46; + + if (session.count) + { + sdir->size_low = getUInt (s.smb, pos); + pos += 4; + sdir->size_high = getUInt (s.smb, pos); + pos += 4; + pos += 8; + sdir->attributes = getUInt (s.smb, pos); + pos += 38; + strcpy (sdir->name, &s.smb[pos]); + + return SMB_SUCCESS; + } + } + + return 0; + +} + +/** + * SMB_FindNext + */ +int +SMB_FindNext (SMBDIRENTRY * sdir) +{ + int pos; + int ret; + int bpos; + + if (session.eos) + return 0; + + if (session.sid == 0) + return 0; + + MakeSMBHdr (SMB_TRANS2); + MakeTRANS2Hdr (SMB_FIND_NEXT2); + pos = T2_BYTE_CNT + 2; + bpos = pos; + pos += 3; /*** Padding ***/ + + setUShort (c.smb, pos, session.sid); + pos += 2; /*** Search ID ***/ + setUShort (c.smb, pos, 1); + pos += 2; /*** Count ***/ + setUShort (c.smb, pos, 260); + pos += 2; /*** Level of Interest ***/ + pos += 4; /*** Storage Type == 0 ***/ + setUShort (c.smb, pos, 12); + pos += 2; /*** Search flags ***/ + pos++; + + /*** Update counts ***/ + setUShort (c.smb, T2_PRM_CNT, 13); + setUShort (c.smb, T2_SPRM_CNT, 13); + setUShort (c.smb, T2_SPRM_OFS, 68); + setUShort (c.smb, T2_SDATA_OFS, 81); + setUShort (c.smb, T2_BYTE_CNT, pos - bpos); + + c.msg = SESS_MSG; + c.length = htons (pos); + + pos += 4; + + ret = send (smbsock, (char *) &c, pos, 0); + + if (SMBCheck (SMB_TRANS2, sizeof (s)) == SMB_SUCCESS) + { + /*** Get parameter offset ***/ + pos = getUShort (s.smb, SMB_HEADER + 9); + session.count = getUShort (s.smb, pos); + pos += 2; + session.eos = getUShort (s.smb, pos); + pos += 2; + pos += 44; + + if (session.count) + { + sdir->size_low = getUInt (s.smb, pos); + pos += 4; + sdir->size_high = getUInt (s.smb, pos); + pos += 4; + pos += 8; + sdir->attributes = getUInt (s.smb, pos); + pos += 38; + strcpy (sdir->name, &s.smb[pos]); + + return SMB_SUCCESS; + } + } + + return 0; + +} + +/** + * SMB_FindClose + */ +int +SMB_FindClose () +{ + int pos = SMB_HEADER; + int ret; + + if (session.sid == 0) + return 0; + + MakeSMBHdr (SMB_FIND_CLOSE2); + + setUChar (c.smb, pos, 1); + pos++; /*** Word Count ***/ + setUShort (c.smb, pos, session.sid); + pos += 2; + pos += 2; /*** Byte Count ***/ + + c.msg = SESS_MSG; + c.length = htons (pos); + pos += 4; + ret = send (smbsock, (char *) &c, pos, 0); + + return SMBCheck (SMB_FIND_CLOSE2, sizeof (s)); + +} + +/** + * SMB_Open + */ +SMBFILE +SMB_Open (char *filename, unsigned short access, unsigned short creation) +{ + int pos = SMB_HEADER; + int bpos, ret; + char realfile[256]; + unsigned short fid; + + MakeSMBHdr (SMB_OPEN_ANDX); + + setUChar (c.smb, pos, 15); + pos++; /*** Word Count ***/ + setUChar (c.smb, pos, 0xff); + pos++; /*** Next AndX ***/ + pos += 3; /*** Next AndX Offset ***/ + + pos += 2; /*** Flags ***/ + setUShort (c.smb, pos, access); + pos += 2; /*** Access mode ***/ + setUShort (c.smb, pos, 0x6); + pos += 2; /*** Type of file ***/ + pos += 2; /*** Attributes ***/ + pos += 4; /*** File time - don't care - let server decide ***/ + setUShort (c.smb, pos, creation); + pos += 2; /*** Creation flags ***/ + pos += 4; /*** Allocation size ***/ + pos += 8; /*** Reserved ***/ + pos += 2; /*** Byte Count ***/ + bpos = pos; + + if (filename[0] != '\\') + { + strcpy (realfile, "\\"); + strcat (realfile, filename); + } + else + strcpy (realfile, filename); + + memcpy (&c.smb[pos], realfile, strlen (realfile)); + pos += strlen (realfile) + 1; + + setUShort (c.smb, bpos - 2, (pos - bpos)); + + c.msg = SESS_MSG; + c.length = htons (pos); + + pos += 4; + ret = send (smbsock, (char *) &c, pos, 0); + + if (SMBCheck (SMB_OPEN_ANDX, sizeof (s)) == SMB_SUCCESS) + { + /*** Check file handle ***/ + fid = getUShort (s.smb, SMB_HEADER + 5); + + if (fid) + return fid; + } + + return 0; +} + +/** + * SMB_Close + */ +void +SMB_Close (SMBFILE sfid) +{ + int pos, ret; + + MakeSMBHdr (SMB_CLOSE); + pos = SMB_HEADER; + + setUChar (c.smb, pos, 3); + pos++; /** Word Count **/ + setUShort (c.smb, pos, sfid); + pos += 2; + setUInt (c.smb, pos, 0xffffffff); + pos += 4; /*** Last Write ***/ + pos += 2; /*** Byte Count ***/ + + c.msg = SESS_MSG; + c.length = htons (pos); + pos += 4; + ret = send (smbsock, (char *) &c, pos, 0); + + SMBCheck (SMB_CLOSE, sizeof (s)); +} + +/** + * SMB_Read + */ +int +SMB_Read (char *buffer, int size, int offset, SMBFILE sfile) +{ + int pos, ret, ofs; + unsigned short length = 0; + + MakeSMBHdr (SMB_READ_ANDX); + pos = SMB_HEADER; + + /*** Don't let the size exceed! ***/ + if (size > 62 * 1024) + return 0; + + setUChar (c.smb, pos, 10); + pos++; /*** Word count ***/ + setUChar (c.smb, pos, 0xff); + pos++; + pos += 3; /*** Reserved, Next AndX Offset ***/ + setUShort (c.smb, pos, sfile); + pos += 2; /*** FID ***/ + setUInt (c.smb, pos, offset); + pos += 4; /*** Offset ***/ + + setUShort (c.smb, pos, size & 0xffff); + pos += 2; + setUShort (c.smb, pos, size & 0xffff); + pos += 2; + setUInt (c.smb, pos, 0); + pos += 4; + pos += 2; /*** Remaining ***/ + pos += 2; /*** Byte count ***/ + + c.msg = SESS_MSG; + c.length = htons (pos); + + pos += 4; + ret = send (smbsock, (char *) &c, pos, 0); + + /*** SMBCheck should now only read up to the end of a standard header ***/ + if (SMBCheck (SMB_READ_ANDX, SMB_HEADER + 27 + 4) == SMB_SUCCESS) + { + /*** Retrieve data length for this packet ***/ + length = getUShort (s.smb, SMB_HEADER + 11); + /*** Retrieve offset to data ***/ + ofs = getUShort (s.smb, SMB_HEADER + 13); + + /*** Default offset, with no padding is 59, so grab any outstanding padding ***/ + if (ofs > 59) + { + char pad[1024]; + ret = recv (smbsock, pad, ofs - 59, 0); + } + + /*** Finally, go grab the data ***/ + ofs = 0; + + if (length) + { + while (((ret = recv (smbsock, buffer + ofs, length, 0)) > 0)) + { + ofs += ret; + if (ofs == length) + break; + } + } + + return ofs; + + } + + return 0; + +} + +/** + * SMB_Write + */ +int +SMB_Write (char *buffer, int size, int offset, SMBFILE sfile) +{ + int pos, ret; + int blocks64; + + MakeSMBHdr (SMB_WRITE_ANDX); + pos = SMB_HEADER; + + setUChar (c.smb, pos, 12); + pos++; /*** Word Count ***/ + setUChar (c.smb, pos, 0xff); + pos += 2; /*** Next AndX ***/ + pos += 2; /*** Next AndX Offset ***/ + + setUShort (c.smb, pos, sfile); + pos += 2; + setUInt (c.smb, pos, offset); + pos += 4; + pos += 4; /*** Reserved ***/ + pos += 2; /*** Write Mode ***/ + pos += 2; /*** Remaining ***/ + + blocks64 = size >> 16; + + setUShort (c.smb, pos, blocks64); + pos += 2; /*** Length High ***/ + setUShort (c.smb, pos, size & 0xffff); + pos += 2; /*** Length Low ***/ + setUShort (c.smb, pos, 59); + pos += 2; /*** Data Offset ***/ + setUShort (c.smb, pos, size & 0xffff); + pos += 2; /*** Data Byte Count ***/ + + c.msg = SESS_MSG; + c.length = htons (pos + size); + + /*** Will this fit in a single send? ***/ + if (size <= 2916) + { + memcpy (&c.smb[pos], buffer, size); + pos += size; + } + else + { + memcpy (&c.smb[pos], buffer, 2916); + pos += 2916; + } + + pos += 4; + + /*** Send Header Information ***/ + ret = send (smbsock, (char *) &c, pos, 0); + + if (size > 2916) + { + /*** Send the data ***/ + ret = send (smbsock, buffer + 2916, size - 2916, 0); + } + + if (SMBCheck (SMB_WRITE_ANDX, sizeof (s)) == SMB_SUCCESS) + { + return (int) getUShort (s.smb, SMB_HEADER + 5); + } + + return 0; + +} + +/**************************************************************************** + * Primary setup, logon and connection all in one :) + ****************************************************************************/ +int +SMB_Init (char *user, char *password, char *client, + char *server, char *share, char *IP) +{ + int ret; + int nodelay; + + /*** Create the global socket ***/ + smbsock = socket (AF_INET, SOCK_STREAM, IPPROTO_IP); + + /*** Switch off Nagle, ON TCP_NODELAY ***/ + nodelay = 1; + ret = setsockopt (smbsock, IPPROTO_TCP, TCP_NODELAY, + (char *) &nodelay, sizeof (char)); + + /*** Attempt to connect to the server IP ***/ + memset (&smbs, 0, sizeof (client)); + smbs.sin_family = AF_INET; + smbs.sin_port = htons (445); + smbs.sin_addr.s_addr = inet_addr (IP); + + ret = connect (smbsock, (struct sockaddr *) &smbs, sizeof (smbs)); + + if (ret) + { + closesocket (smbsock); + return 0; + } + + if (SMB_NegotiateProtocol () == SMB_SUCCESS) + { + if (SMB_SetupAndX (user, password) == SMB_SUCCESS) + { + if (SMB_TreeAndX (server, share) == SMB_SUCCESS) + return SMB_SUCCESS; + } + } + + return 0; + +} + +/**************************************************************************** + * SMB_Destroy + * + * Probably NEVER called on GameCube, but here for completeness + ****************************************************************************/ +void +SMB_Destroy () +{ + if (smbsock) + closesocket (smbsock); +} diff --git a/source/smb/smb.h b/source/smb/smb.h new file mode 100644 index 00000000..a755cd9b --- /dev/null +++ b/source/smb/smb.h @@ -0,0 +1,219 @@ +/**************************************************************************** + * TinySMB-GC + * + * Nintendo Gamecube SaMBa implementation. + * + * Copyright softdev@tehskeen.com + * + * Authentication modules, LMhash and DES are + * + * Copyright Christopher R Hertel. + * http://www.ubiqx.org + * + * You WILL find Ethereal, available from http://www.ethereal.com + * invaluable for debugging each new SAMBA implementation. + * + * Recommended Reading + * Implementing CIFS - Christopher R Hertel + * SNIA CIFS Documentation - http://www.snia.org + * + * License: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ****************************************************************************/ +#ifndef NBTSMB_INC +#define NBTSMB_INC +#include +#include +#include + +/** + * NBT/SMB Wrapper + */ +typedef struct +{ + unsigned char msg; /*** NBT Message ***/ + unsigned char flags; /*** Not much here really ***/ + unsigned short length; /*** Length, excluding NBT ***/ + char smb[2916]; /*** GC Actual is 2920 bytes ***/ +} +NBTSMB; + +/** + * Session Information + */ +typedef struct +{ + unsigned short TID; + unsigned short PID; + unsigned short UID; + unsigned short MID; + unsigned short sKey; + unsigned short MaxBuffer; + unsigned short MaxMpx; + unsigned short MaxVCS; + unsigned char challenge[10]; + char p_domain[64]; + unsigned short sid; + unsigned short count; + unsigned short eos; +} +SMBSESSION; + +/*** SMB_FILEENTRY + SMB Long Filename Directory Entry + ***/ +typedef struct +{ + unsigned int size_low; + unsigned int size_high; + unsigned int attributes; + char name[256]; +} +SMBDIRENTRY; + +/*** + * SMB File Handle + */ +typedef unsigned short SMBFILE; + +#define SMB_HEADER 32 /*** SMB Headers are always 32 bytes long ***/ +#define SMB_PROTO 0x424d53ff + +/** + * Field offsets. + */ +#define SMB_OFFSET_CMD 4 +#define SMB_OFFSET_NTSTATUS 5 +#define SMB_OFFSET_ECLASS 5 +#define SMB_OFFSET_ECODE 7 +#define SMB_OFFSET_FLAGS 9 +#define SMB_OFFSET_FLAGS2 10 +#define SMB_OFFSET_EXTRA 12 +#define SMB_OFFSET_TID 24 +#define SMB_OFFSET_PID 26 +#define SMB_OFFSET_UID 28 +#define SMB_OFFSET_MID 30 + +/** + * Message / Commands + */ +#define SESS_MSG 0x00 +#define SMB_NEG_PROTOCOL 0x72 +#define SMB_SETUP_ANDX 0x73 +#define SMB_TREEC_ANDX 0x75 + +/** + * SMBTrans2 + */ +#define SMB_TRANS2 0x32 + +#define SMB_OPEN2 0 +#define SMB_FIND_FIRST2 1 +#define SMB_FIND_NEXT2 2 +#define SMB_QUERY_FS_INFO 3 +#define SMB_QUERY_PATH_INFO 5 +#define SMB_SET_PATH_INFO 6 +#define SMB_QUERY_FILE_INFO 7 +#define SMB_SET_FILE_INFO 8 +#define SMB_CREATE_DIR 13 +#define SMB_FIND_CLOSE2 0x34 + +/** + * File I/O + */ +#define SMB_OPEN_ANDX 0x2d +#define SMB_WRITE_ANDX 0x2f +#define SMB_READ_ANDX 0x2e +#define SMB_CLOSE 4 + +/** + * SMB File Access Modes + */ +#define SMB_OPEN_READING 0 +#define SMB_OPEN_WRITING 1 +#define SMB_OPEN_READWRITE 2 +#define SMB_OPEN_COMPATIBLE 0 +#define SMB_DENY_READWRITE 0x10 +#define SMB_DENY_WRITE 0x20 +#define SMB_DENY_READ 0x30 +#define SMB_DENY_NONE 0x40 + +/** + * SMB File Open Function + */ +#define SMB_OF_OPEN 1 +#define SMB_OF_TRUNCATE 2 +#define SMB_OF_CREATE 16 + +/** + * FileSearch + */ +#define SMB_SRCH_DIRECTORY 16 +#define SMB_SRCH_READONLY 1 +#define SMB_SRCH_HIDDEN 2 +#define SMB_SRCH_SYSTEM 4 +#define SMB_SRCH_VOLUME 8 + +/** + * SMB Error codes + */ +#define SMB_SUCCESS 1 +#define BAD_PROTOCOL -1 +#define SMB_ERROR -2 +#define SMB_BAD_COMMAND -3 +#define SMB_PROTO_FAIL -4 +#define SMB_NOT_USER -5 +#define SMB_BAD_KEYLEN -6 + +/** + * TRANS2 Offsets + */ +#define T2_WORD_CNT SMB_HEADER +#define T2_PRM_CNT T2_WORD_CNT + 1 +#define T2_DATA_CNT T2_PRM_CNT + 2 +#define T2_MAXPRM_CNT T2_DATA_CNT + 2 +#define T2_MAXBUFFER T2_MAXPRM_CNT + 2 +#define T2_SETUP_CNT T2_MAXBUFFER + 2 +#define T2_SPRM_CNT T2_SETUP_CNT + 10 +#define T2_SPRM_OFS T2_SPRM_CNT + 2 +#define T2_SDATA_CNT T2_SPRM_OFS + 2 +#define T2_SDATA_OFS T2_SDATA_CNT + 2 +#define T2_SSETUP_CNT T2_SDATA_OFS + 2 +#define T2_SUB_CMD T2_SSETUP_CNT + 2 +#define T2_BYTE_CNT T2_SUB_CMD + 2 + +/** + * Prototypes + */ + +/*** Session ***/ +int SMB_Init (char *user, char *password, char *client, + char *server, char *share, char *IP); +void SMB_Destroy (); + +/*** File Find ***/ +int SMB_FindFirst (char *filename, unsigned short flags, SMBDIRENTRY * sdir); +int SMB_FindNext (SMBDIRENTRY * sdir); +int SMB_FindClose (); + +/*** File I/O ***/ +SMBFILE SMB_Open (char *filename, unsigned short access, + unsigned short creation); +void SMB_Close (SMBFILE sfid); +int SMB_Read (char *buffer, int size, int offset, SMBFILE sfile); +int SMB_Write (char *buffer, int size, int offset, SMBFILE sfile); + +#endif diff --git a/source/snes9x/3d.h b/source/snes9x/3d.h index 0122ce23..cec93441 100644 --- a/source/snes9x/3d.h +++ b/source/snes9x/3d.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _3D_H_ #define _3D_H_ @@ -186,7 +167,6 @@ typedef struct GLint texture_size; uint32 num_textures; // 1 if max_texture_size == 256, 2 otherwise GLuint textures [2]; - bool8 initialized; } OpenGLData; extern OpenGLData OpenGL; diff --git a/source/snes9x/65c816.h b/source/snes9x/65c816.h index bee73da6..9c45fc17 100644 --- a/source/snes9x/65c816.h +++ b/source/snes9x/65c816.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _65c816_h_ #define _65c816_h_ diff --git a/source/snes9x/apu.cpp b/source/snes9x/apu.cpp index 553530f3..ad4620ef 100644 --- a/source/snes9x/apu.cpp +++ b/source/snes9x/apu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifdef __DJGPP #include #undef TRUE @@ -182,7 +163,7 @@ extern int32 env_counter_table[32]; int spc_is_dumping=0; int spc_is_dumping_temp; -uint8 spc_dump_dsp[0x100]; +uint8 spc_dump_dsp[0x100]; #ifdef DEBUGGER void S9xTraceSoundDSP (const char *s, int i1 = 0, int i2 = 0, int i3 = 0, @@ -192,15 +173,19 @@ void S9xTraceSoundDSP (const char *s, int i1 = 0, int i2 = 0, int i3 = 0, bool8 S9xInitAPU () { IAPU.RAM = (uint8 *) malloc (0x10000); - - if (!IAPU.RAM) + IAPU.ShadowRAM = (uint8 *) malloc (0x10000); + IAPU.CachedSamples = (uint8 *) malloc (0x40000); + + if (!IAPU.RAM || !IAPU.ShadowRAM || !IAPU.CachedSamples) { S9xDeinitAPU (); return (FALSE); } memset(IAPU.RAM, 0, 0x10000); - + memset(IAPU.ShadowRAM, 0, 0x10000); + memset(IAPU.CachedSamples, 0, 0x40000); + return (TRUE); } @@ -211,19 +196,27 @@ void S9xDeinitAPU () free ((char *) IAPU.RAM); IAPU.RAM = NULL; } + if (IAPU.ShadowRAM) + { + free ((char *) IAPU.ShadowRAM); + IAPU.ShadowRAM = NULL; + } + if (IAPU.CachedSamples) + { + free ((char *) IAPU.CachedSamples); + IAPU.CachedSamples = NULL; + } } EXTERN_C uint8 APUROM [64]; void S9xResetAPU () { + int i; Settings.APUEnabled = Settings.NextAPUEnabled; - if(Settings.APUEnabled) - APU.Flags &= ~HALTED_FLAG; - ZeroMemory(spc_dump_dsp, 0x100); ZeroMemory(IAPU.RAM, 0x100); memset(IAPU.RAM+0x20, 0xFF, 0x20); @@ -236,17 +229,19 @@ void S9xResetAPU () memcpy(IAPU.RAM+(i<<8), IAPU.RAM, 0x100); } + memcpy (IAPU.ShadowRAM, IAPU.RAM, 0x10000); + + ZeroMemory (IAPU.CachedSamples, 0x40000); ZeroMemory (APU.OutPorts, 4); IAPU.DirectPage = IAPU.RAM; - memmove (APU.ExtraRAM, &IAPU.RAM [0xffc0], sizeof (APUROM)); memmove (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM)); + memmove (APU.ExtraRAM, APUROM, sizeof (APUROM)); IAPU.PC = IAPU.RAM + IAPU.RAM [0xfffe] + (IAPU.RAM [0xffff] << 8); APU.Cycles = 0; - APU.OldCycles = -99999999; // For shapshot compatibility APURegisters.YA.W = 0; APURegisters.X = 0; - APURegisters.S = 0xef; - APURegisters.P = 0x02; + APURegisters.S = 0xff; + APURegisters.P = 0; S9xAPUUnpackStatus (); APURegisters.PC = 0; IAPU.APUExecuting = Settings.APUEnabled; @@ -259,7 +254,7 @@ void S9xResetAPU () IAPU.APUTimerCounter = 0; APU.ShowROM = TRUE; IAPU.RAM [0xf1] = 0x80; - + for (i = 0; i < 3; i++) { APU.TimerEnabled [i] = FALSE; @@ -269,18 +264,18 @@ void S9xResetAPU () } for (int j = 0; j < 0x80; j++) APU.DSP [j] = 0; - + IAPU.TwoCycles = IAPU.OneCycle * 2; - + for (i = 0; i < 256; i++) S9xAPUCycles [i] = S9xAPUCycleLengths [i] * IAPU.OneCycle; - + APU.DSP [APU_ENDX] = 0; APU.DSP [APU_KOFF] = 0; APU.DSP [APU_KON] = 0; APU.DSP [APU_FLG] = APU_MUTE | APU_ECHO_DISABLED; APU.KeyedChannels = 0; - + S9xResetSound (TRUE); S9xSetEchoEnable (0); } @@ -323,7 +318,7 @@ void S9xSetAPUDSP (uint8 byte) } else S9xSetSoundMute (FALSE); - + SoundData.noise_rate = env_counter_table[byte & 0x1f]; } break; @@ -375,7 +370,7 @@ void S9xSetAPUDSP (uint8 byte) { #ifdef DEBUGGER if (Settings.TraceSoundDSP) - S9xTraceSoundDSP ("[%d] Master volume left:%d\n", + S9xTraceSoundDSP ("[%d] Master volume left:%d\n", ICPU.Scanline, (signed char) byte); #endif S9xSetMasterVolume ((signed char) byte, @@ -425,7 +420,7 @@ void S9xSetAPUDSP (uint8 byte) #endif byte = 0; break; - + case APU_KOFF: // if (byte) { @@ -439,10 +434,10 @@ void S9xSetAPUDSP (uint8 byte) if ((byte & mask) != 0) { #ifdef DEBUGGER - + if (Settings.TraceSoundDSP) S9xTraceSoundDSP ("%d,", c); -#endif +#endif if (APU.KeyedChannels & mask) { { @@ -489,7 +484,7 @@ void S9xSetAPUDSP (uint8 byte) { uint8 mask = 1; #ifdef DEBUGGER - + if (Settings.TraceSoundDSP) S9xTraceSoundDSP ("[%d] Key on:", ICPU.Scanline); #endif @@ -500,7 +495,7 @@ void S9xSetAPUDSP (uint8 byte) #ifdef DEBUGGER if (Settings.TraceSoundDSP) S9xTraceSoundDSP ("%d,", c); -#endif +#endif // Pac-In-Time requires that channels can be key-on // regardeless of their current state. if((APU.DSP [APU_KOFF] & mask) ==0) @@ -522,7 +517,7 @@ void S9xSetAPUDSP (uint8 byte) } spc_is_dumping_temp = byte; return; - + case APU_VOL_LEFT + 0x00: case APU_VOL_LEFT + 0x10: case APU_VOL_LEFT + 0x20: @@ -536,7 +531,7 @@ void S9xSetAPUDSP (uint8 byte) { #ifdef DEBUGGER if (Settings.TraceSoundDSP) - S9xTraceSoundDSP ("[%d] %d volume left: %d\n", + S9xTraceSoundDSP ("[%d] %d volume left: %d\n", ICPU.Scanline, reg>>4, (signed char) byte); #endif S9xSetSoundVolume (reg >> 4, (signed char) byte, @@ -556,14 +551,14 @@ void S9xSetAPUDSP (uint8 byte) { #ifdef DEBUGGER if (Settings.TraceSoundDSP) - S9xTraceSoundDSP ("[%d] %d volume right: %d\n", + S9xTraceSoundDSP ("[%d] %d volume right: %d\n", ICPU.Scanline, reg >>4, (signed char) byte); #endif S9xSetSoundVolume (reg >> 4, (signed char) APU.DSP [reg - 1], (signed char) byte); } break; - + case APU_P_LOW + 0x00: case APU_P_LOW + 0x10: case APU_P_LOW + 0x20: @@ -579,7 +574,7 @@ void S9xSetAPUDSP (uint8 byte) #endif S9xSetSoundHertz (reg >> 4, ((byte + (APU.DSP [reg + 1] << 8)) & FREQUENCY_MASK) * 8); break; - + case APU_P_HIGH + 0x00: case APU_P_HIGH + 0x10: case APU_P_HIGH + 0x20: @@ -593,10 +588,10 @@ void S9xSetAPUDSP (uint8 byte) S9xTraceSoundDSP ("[%d] %d freq high: %d\n", ICPU.Scanline, reg>>4, byte); #endif - S9xSetSoundHertz (reg >> 4, + S9xSetSoundHertz (reg >> 4, (((byte << 8) + APU.DSP [reg - 1]) & FREQUENCY_MASK) * 8); break; - + case APU_SRCN + 0x00: case APU_SRCN + 0x10: case APU_SRCN + 0x20: @@ -611,7 +606,7 @@ void S9xSetAPUDSP (uint8 byte) ICPU.Scanline, reg>>4, byte); #endif break; - + case APU_ADSR1 + 0x00: case APU_ADSR1 + 0x10: case APU_ADSR1 + 0x20: @@ -628,12 +623,12 @@ void S9xSetAPUDSP (uint8 byte) ICPU.Scanline, reg>>4, byte); #endif { - S9xFixEnvelope (reg >> 4, APU.DSP [reg + 2], byte, + S9xFixEnvelope (reg >> 4, APU.DSP [reg + 2], byte, APU.DSP [reg + 1]); } } break; - + case APU_ADSR2 + 0x00: case APU_ADSR2 + 0x10: case APU_ADSR2 + 0x20: @@ -646,7 +641,7 @@ void S9xSetAPUDSP (uint8 byte) { #ifdef DEBUGGER if (Settings.TraceSoundDSP) - S9xTraceSoundDSP ("[%d] %d adsr2: %02x\n", + S9xTraceSoundDSP ("[%d] %d adsr2: %02x\n", ICPU.Scanline, reg>>4, byte); #endif { @@ -655,7 +650,7 @@ void S9xSetAPUDSP (uint8 byte) } } break; - + case APU_GAIN + 0x00: case APU_GAIN + 0x10: case APU_GAIN + 0x20: @@ -677,7 +672,7 @@ void S9xSetAPUDSP (uint8 byte) } } break; - + case APU_ENVX + 0x00: case APU_ENVX + 0x10: case APU_ENVX + 0x20: @@ -687,7 +682,7 @@ void S9xSetAPUDSP (uint8 byte) case APU_ENVX + 0x60: case APU_ENVX + 0x70: break; - + case APU_OUTX + 0x00: case APU_OUTX + 0x10: case APU_OUTX + 0x20: @@ -697,7 +692,7 @@ void S9xSetAPUDSP (uint8 byte) case APU_OUTX + 0x60: case APU_OUTX + 0x70: break; - + case APU_DIR: #ifdef DEBUGGER if (Settings.TraceSoundDSP) @@ -705,7 +700,7 @@ void S9xSetAPUDSP (uint8 byte) ICPU.Scanline, byte); #endif break; - + case APU_PMON: if (byte != APU.DSP [APU_PMON]) { @@ -735,7 +730,7 @@ void S9xSetAPUDSP (uint8 byte) S9xSetFrequencyModulationEnable (byte); } break; - + case APU_EON: if (byte != APU.DSP [APU_EON]) { @@ -765,18 +760,18 @@ void S9xSetAPUDSP (uint8 byte) S9xSetEchoEnable (byte); } break; - + case APU_EFB: S9xSetEchoFeedback ((signed char) byte); break; - + case APU_ESA: break; - + case APU_EDL: S9xSetEchoDelay (byte & 0xf); break; - + case APU_C0: case APU_C1: case APU_C2: @@ -792,10 +787,10 @@ void S9xSetAPUDSP (uint8 byte) //printf ("Write %02x to unknown APU register %02x\n", byte, reg); break; } - + KeyOnPrev|=KeyOn; KeyOn=0; - + if (reg < 0x80) APU.DSP [reg] = byte; } @@ -861,13 +856,13 @@ void S9xSetAPUControl (uint8 byte) APU.TimerEnabled [0] = byte & 1; APU.TimerEnabled [1] = (byte & 2) >> 1; APU.TimerEnabled [2] = (byte & 4) >> 2; - + if (byte & 0x10) IAPU.RAM [0xF4] = IAPU.RAM [0xF5] = 0; - + if (byte & 0x20) IAPU.RAM [0xF6] = IAPU.RAM [0xF7] = 0; - + if (byte & 0x80) { if (!APU.ShowROM) @@ -890,7 +885,7 @@ void S9xSetAPUControl (uint8 byte) void S9xSetAPUTimer (uint16 Address, uint8 byte) { IAPU.RAM [Address] = byte; - + switch (Address) { case 0xfa: @@ -911,21 +906,12 @@ void S9xSetAPUTimer (uint16 Address, uint8 byte) } } -void S9xAPUExecute (void) +void S9xUpdateAPUTimer (void) { - while ((CPU.Cycles << SNES_APU_ACCURACY) >= IAPU.NextAPUTimerPos) + while ((CPU.Cycles << SNES_APUTIMER_ACCURACY) >= IAPU.NextAPUTimerPos) { - // catch up the APU timers - if (IAPU.APUExecuting) - { - while (APU.Cycles < IAPU.NextAPUTimerPos) - APU_EXECUTE1(); - } - else - APU.Cycles = IAPU.NextAPUTimerPos; - - IAPU.NextAPUTimerPos += SNES_APUTIMER2_CYCLE_SCALED; - + IAPU.NextAPUTimerPos += SNES_APUTIMER2_CYCLE_SHIFT; + if (APU.TimerEnabled [2]) { APU.Timer [2] ++; @@ -933,17 +919,17 @@ void S9xAPUExecute (void) { IAPU.RAM [0xff] = (IAPU.RAM [0xff] + 1) & 0xf; APU.Timer [2] = 0; - #ifdef SPC700_SHUTDOWN + #ifdef SPC700_SHUTDOWN IAPU.WaitCounter++; IAPU.APUExecuting = TRUE; - #endif + #endif } } if (++IAPU.APUTimerCounter == 8) { IAPU.APUTimerCounter = 0; - + if (APU.TimerEnabled [0]) { APU.Timer [0]++; @@ -951,10 +937,10 @@ void S9xAPUExecute (void) { IAPU.RAM [0xfd] = (IAPU.RAM [0xfd] + 1) & 0xf; APU.Timer [0] = 0; - #ifdef SPC700_SHUTDOWN + #ifdef SPC700_SHUTDOWN IAPU.WaitCounter++; IAPU.APUExecuting = TRUE; - #endif + #endif } } @@ -965,23 +951,14 @@ void S9xAPUExecute (void) { IAPU.RAM [0xfe] = (IAPU.RAM [0xfe] + 1) & 0xf; APU.Timer [1] = 0; - #ifdef SPC700_SHUTDOWN + #ifdef SPC700_SHUTDOWN IAPU.WaitCounter++; IAPU.APUExecuting = TRUE; - #endif + #endif } } } } - - // catch up the current cycles - if (IAPU.APUExecuting) - { - while (APU.Cycles < (CPU.Cycles << SNES_APU_ACCURACY)) - APU_EXECUTE1(); - } - else - APU.Cycles = (CPU.Cycles << SNES_APU_ACCURACY); } uint8 S9xGetAPUDSP () @@ -1004,18 +981,10 @@ uint8 S9xGetAPUDSP () case APU_OUTX + 0x50: case APU_OUTX + 0x60: case APU_OUTX + 0x70: - if(Settings.FakeMuteFix) - { - // hack that is off by default: fixes Terranigma desync - return (0); - } - else - { if (SoundData.channels [reg >> 4].state == SOUND_SILENT) return (0); return (int8) (SoundData.channels [reg >> 4].out_sample >> 8); - } - + case APU_ENVX + 0x00: case APU_ENVX + 0x10: case APU_ENVX + 0x20: @@ -1025,7 +994,7 @@ uint8 S9xGetAPUDSP () case APU_ENVX + 0x60: case APU_ENVX + 0x70: return (S9xGetEnvelopeHeight (reg >> 4)); - + case APU_ENDX: // To fix speech in Magical Drop 2 6/11/00 // APU.DSP [APU_ENDX] = 0; @@ -1034,6 +1003,6 @@ uint8 S9xGetAPUDSP () default: break; } - + return (byte); } diff --git a/source/snes9x/apu.h b/source/snes9x/apu.h index 9c3d949c..90b562b2 100644 --- a/source/snes9x/apu.h +++ b/source/snes9x/apu.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _apu_h_ #define _apu_h_ @@ -177,8 +158,8 @@ struct SIAPU uint8 *WaitAddress1; uint8 *WaitAddress2; uint32 WaitCounter; - uint8 *ShadowRAM; // unused - uint8 *CachedSamples; // unused + uint8 *ShadowRAM; + uint8 *CachedSamples; uint8 _Carry; uint8 _Zero; uint8 _Overflow; @@ -192,7 +173,7 @@ struct SIAPU struct SAPU { - int32 OldCycles; // unused + int32 Cycles; bool8 ShowROM; uint32 Flags; uint8 KeyedChannels; @@ -203,7 +184,6 @@ struct SAPU uint16 TimerTarget [3]; bool8 TimerEnabled [3]; bool8 TimerValueWritten [3]; - int32 Cycles; }; EXTERN_C struct SAPU APU; @@ -236,7 +216,7 @@ void S9xSetAPUControl (uint8 byte); void S9xSetAPUDSP (uint8 byte); uint8 S9xGetAPUDSP (); void S9xSetAPUTimer (uint16 Address, uint8 byte); -void S9xAPUExecute (void); +void S9xUpdateAPUTimer (void); bool8 S9xInitSound (int quality, bool8 stereo, int buffer_size); void S9xOpenCloseSoundTracingFile (bool8); void S9xPrintAPUState (); diff --git a/source/snes9x/apudebug.cpp b/source/snes9x/apudebug.cpp index 495979a5..58a268a3 100644 --- a/source/snes9x/apudebug.cpp +++ b/source/snes9x/apudebug.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,83 +142,85 @@ **********************************************************************************/ - - #include "snes9x.h" #include "spc700.h" #include "apu.h" #include "soundux.h" #include "cpuexec.h" +#ifdef SPCTOOL +#include "spctool/spc700.h" +#endif + #ifdef DEBUGGER extern int32 env_counter_table[32]; FILE *apu_trace = NULL; static char *S9xMnemonics [256] = { - "NOP", "TCALL 0", "SET1 $%02X.0", "BBS $%02X.0,$%04X", - "OR A,$%02X", "OR A,!$%04X", "OR A,(X)", "OR A,[$%02X+X]", - "OR A,#$%02X", "OR $%02X,$%02X", "OR1 C,$%04X.%d", "ASL $%02X", - "MOV !$%04X,Y", "PUSH PSW", "TSET1 !$%04X", "BRK", - "BPL $%04X", "TCALL 1", "CLR1 $%02X.0", "BBC $%02X.0,$%04X", - "OR A,$%02X+X", "OR A,!$%04X+X", "OR A,!$%04X+Y", "OR A,[$%02X]+Y", - "OR $%02X,#$%02X", "OR (X),(Y)", "DECW $%02X", "ASL $%02X+X", - "ASL A", "DEC X", "CMP X,!$%04X", "JMP [!$%04X+X]", - "CLRP", "TCALL 2", "SET1 $%02X.1", "BBS $%02X.1,$%04X", - "AND A,$%02X", "AND A,!$%04X", "AND A,(X)", "AND A,[$%02X+X]", - "AND A,#$%02X", "AND $%02X,$%02X", "OR1 C,/$%04X.%d", "ROL $%02X", - "ROL !$%04X", "PUSH A", "CBNE $%02X,$%04X", "BRA $%04X", - "BMI $%04X", "TCALL 3", "CLR1 $%02X.1", "BBC $%02X.1,$%04X", - "AND A,$%02X+X", "AND A,!$%04X+X", "AND A,!$%04X+Y", "AND A,[$%02X]+Y", - "AND $%02X,#$%02X", "AND (X),(Y)", "INCW $%02X", "ROL $%02X+X", - "ROL A", "INC X", "CMP X,$%02X", "CALL !$%04X", - "SETP", "TCALL 4", "SET1 $%02X.2", "BBS $%02X.2,$%04X", - "EOR A,$%02X", "EOR A,!$%04X", "EOR A,(X)", "EOR A,[$%02X+X]", - "EOR A,#$%02X", "EOR $%02X,$%02X", "AND1 C,$%04X.%d", "LSR $%02X", - "LSR !$%04X", "PUSH X", "TCLR1 !$%04X", "PCALL $%02X", - "BVC $%04X", "TCALL 5", "CLR1 $%02X.2", "BBC $%02X.2,$%04X", - "EOR A,$%02X+X", "EOR A,!$%04X+X", "EOR A,!$%04X+Y", "EOR A,[$%02X]+Y", - "EOR $%02X,#$%02X", "EOR (X),(Y)", "CMPW YA,$%02X", "LSR $%02X+X", - "LSR A", "MOV X,A", "CMP Y,!$%04X", "JMP !$%04X", - "CLRC", "TCALL 6", "SET1 $%02X.3", "BBS $%02X.3,$%04X", - "CMP A,$%02X", "CMP A,!$%04X", "CMP A,(X)", "CMP A,[$%02X+X]", - "CMP A,#$%02X", "CMP $%02X,$%02X", "AND1 C,/$%04X.%d", "ROR $%02X", - "ROR !$%04X", "PUSH Y", "DBNZ $%02X,$%04X", "RET", - "BVS $%04X", "TCALL 7", "CLR1 $%02X.3", "BBC $%02X.3,$%04X", - "CMP A,$%02X+X", "CMP A,!$%04X+X", "CMP A,!$%04X+Y", "CMP A,[$%02X]+Y", - "CMP $%02X,#$%02X", "CMP (X),(Y)", "ADDW YA,$%02X", "ROR $%02X+X", - "ROR A", "MOV A,X", "CMP Y,$%02X", "RET1", - "SETC", "TCALL 8", "SET1 $%02X.4", "BBS $%02X.4,$%04X", - "ADC A,$%02X", "ADC A,!$%04X", "ADC A,(X)", "ADC A,[$%02X+X]", - "ADC A,#$%02X", "ADC $%02X,$%02X", "EOR1 C,$%04X.%d", "DEC $%02X", - "DEC !$%04X", "MOV Y,#$%02X", "POP PSW", "MOV $%02X,#$%02X", - "BCC $%04X", "TCALL 9", "CLR1 $%02X.4", "BBC $%02X.4,$%04X", - "ADC A,$%02X+X", "ADC A,!$%04X+X", "ADC A,!$%04X+Y", "ADC A,[$%02X]+Y", - "ADC $%02X,#$%02X", "ADC (X),(Y)", "SUBW YA,$%02X", "DEC $%02X+X", - "DEC A", "MOV X,SP", "DIV YA,X", "XCN A", - "EI", "TCALL 10", "SET1 $%02X.5", "BBS $%02X.5,$%04X", - "SBC A,$%02X", "SBC A,!$%04X", "SBC A,(X)", "SBC A,[$%02X+X]", - "SBC A,#$%02X", "SBC $%02X,$%02X", "MOV1 C,$%04X.%d", "INC $%02X", - "INC !$%04X", "CMP Y,#$%02X", "POP A", "MOV (X)+,A", - "BCS $%04X", "TCALL 11", "CLR1 $%02X.5", "BBC $%02X.5,$%04X", - "SBC A,$%02X+X", "SBC A,!$%04X+X", "SBC A,!$%04X+Y", "SBC A,[$%02X]+Y", - "SBC $%02X,#$%02X", "SBC (X),(Y)", "MOVW YA,$%02X", "INC $%02X+X", - "INC A", "MOV SP,X", "DAS A", "MOV A,(X)+", - "DI", "TCALL 12", "SET1 $%02X.6", "BBS $%02X.6,$%04X", - "MOV $%02X,A", "MOV !$%04X,A", "MOV (X),A", "MOV [$%02X+X],A", - "CMP X,#$%02X", "MOV !$%04X,X", "MOV1 $%04X.%d,C", "MOV $%02X,Y", - "ASL !$%04X", "MOV X,#$%02X", "POP X", "MUL YA", - "BNE $%04X", "TCALL 13", "CLR1 $%02X.6", "BBC $%02X.6,$%04X", - "MOV $%02X+X,A", "MOV !$%04X+X,A", "MOV !$%04X+Y,A", "MOV [$%02X]+Y,A", - "MOV $%02X,X", "MOV $%02X+Y,X", "MOVW $%02X,YA", "MOV $%02X+X,Y", - "DEC Y", "MOV A,Y", "CBNE $%02X+X,$%04X", "DAA A", - "CLRV", "TCALL 14", "SET1 $%02X.7", "BBS $%02X.7,$%04X", - "MOV A,$%02X", "MOV A,!$%04X", "MOV A,(X)", "MOV A,[$%02X+X]", - "MOV A,#$%02X", "MOV X,!$%04X", "NOT1 $%04X.%d", "MOV Y,$%02X", - "MOV Y,!$%04X", "NOTC", "POP Y", "SLEEP", - "BEQ $%04X", "TCALL 15", "CLR1 $%02X.7", "BBC $%02X.7,$%04X", - "MOV A,$%02X+X", "MOV A,!$%04X+X", "MOV A,!$%04X+Y", "MOV A,[$%02X]+Y", - "MOV X,$%02X", "MOV X,$%02X+Y", "MOV $%02X,$%02X", "MOV Y,$%02X+X", + "NOP", "TCALL 0", "SET1 $%02X.0", "BBS $%02X.0,$%04X", + "OR A,$%02X", "OR A,!$%04X", "OR A,(X)", "OR A,[$%02X+X]", + "OR A,#$%02X", "OR $%02X,$%02X", "OR1 C,$%04X.%d", "ASL $%02X", + "MOV !$%04X,Y", "PUSH PSW", "TSET1 !$%04X", "BRK", + "BPL $%04X", "TCALL 1", "CLR1 $%02X.0", "BBC $%02X.0,$%04X", + "OR A,$%02X+X", "OR A,!$%04X+X", "OR A,!$%04X+Y", "OR A,[$%02X]+Y", + "OR $%02X,#$%02X", "OR (X),(Y)", "DECW $%02X", "ASL $%02X+X", + "ASL A", "DEC X", "CMP X,!$%04X", "JMP [!$%04X+X]", + "CLRP", "TCALL 2", "SET1 $%02X.1", "BBS $%02X.1,$%04X", + "AND A,$%02X", "AND A,!$%04X", "AND A,(X)", "AND A,[$%02X+X]", + "AND A,#$%02X", "AND $%02X,$%02X", "OR1 C,/$%04X.%d", "ROL $%02X", + "ROL !$%04X", "PUSH A", "CBNE $%02X,$%04X", "BRA $%04X", + "BMI $%04X", "TCALL 3", "CLR1 $%02X.1", "BBC $%02X.1,$%04X", + "AND A,$%02X+X", "AND A,!$%04X+X", "AND A,!$%04X+Y", "AND A,[$%02X]+Y", + "AND $%02X,#$%02X", "AND (X),(Y)", "INCW $%02X", "ROL $%02X+X", + "ROL A", "INC X", "CMP X,$%02X", "CALL !$%04X", + "SETP", "TCALL 4", "SET1 $%02X.2", "BBS $%02X.2,$%04X", + "EOR A,$%02X", "EOR A,!$%04X", "EOR A,(X)", "EOR A,[$%02X+X]", + "EOR A,#$%02X", "EOR $%02X,$%02X", "AND1 C,$%04X.%d", "LSR $%02X", + "LSR !$%04X", "PUSH X", "TCLR1 !$%04X", "PCALL $%02X", + "BVC $%04X", "TCALL 5", "CLR1 $%02X.2", "BBC $%02X.2,$%04X", + "EOR A,$%02X+X", "EOR A,!$%04X+X", "EOR A,!$%04X+Y", "EOR A,[$%02X]+Y", + "EOR $%02X,#$%02X", "EOR (X),(Y)", "CMPW YA,$%02X", "LSR $%02X+X", + "LSR A", "MOV X,A", "CMP Y,!$%04X", "JMP !$%04X", + "CLRC", "TCALL 6", "SET1 $%02X.3", "BBS $%02X.3,$%04X", + "CMP A,$%02X", "CMP A,!$%04X", "CMP A,(X)", "CMP A,[$%02X+X]", + "CMP A,#$%02X", "CMP $%02X,$%02X", "AND1 C,/$%04X.%d", "ROR $%02X", + "ROR !$%04X", "PUSH Y", "DBNZ $%02X,$%04X", "RET", + "BVS $%04X", "TCALL 7", "CLR1 $%02X.3", "BBC $%02X.3,$%04X", + "CMP A,$%02X+X", "CMP A,!$%04X+X", "CMP A,!$%04X+Y", "CMP A,[$%02X]+Y", + "CMP $%02X,#$%02X", "CMP (X),(Y)", "ADDW YA,$%02X", "ROR $%02X+X", + "ROR A", "MOV A,X", "CMP Y,$%02X", "RET1", + "SETC", "TCALL 8", "SET1 $%02X.4", "BBS $%02X.4,$%04X", + "ADC A,$%02X", "ADC A,!$%04X", "ADC A,(X)", "ADC A,[$%02X+X]", + "ADC A,#$%02X", "ADC $%02X,$%02X", "EOR1 C,$%04X.%d", "DEC $%02X", + "DEC !$%04X", "MOV Y,#$%02X", "POP PSW", "MOV $%02X,#$%02X", + "BCC $%04X", "TCALL 9", "CLR1 $%02X.4", "BBC $%02X.4,$%04X", + "ADC A,$%02X+X", "ADC A,!$%04X+X", "ADC A,!$%04X+Y", "ADC A,[$%02X]+Y", + "ADC $%02X,#$%02X", "ADC (X),(Y)", "SUBW YA,$%02X", "DEC $%02X+X", + "DEC A", "MOV X,SP", "DIV YA,X", "XCN A", + "EI", "TCALL 10", "SET1 $%02X.5", "BBS $%02X.5,$%04X", + "SBC A,$%02X", "SBC A,!$%04X", "SBC A,(X)", "SBC A,[$%02X+X]", + "SBC A,#$%02X", "SBC $%02X,$%02X", "MOV1 C,$%04X.%d", "INC $%02X", + "INC !$%04X", "CMP Y,#$%02X", "POP A", "MOV (X)+,A", + "BCS $%04X", "TCALL 11", "CLR1 $%02X.5", "BBC $%02X.5,$%04X", + "SBC A,$%02X+X", "SBC A,!$%04X+X", "SBC A,!$%04X+Y", "SBC A,[$%02X]+Y", + "SBC $%02X,#$%02X", "SBC (X),(Y)", "MOVW YA,$%02X", "INC $%02X+X", + "INC A", "MOV SP,X", "DAS A", "MOV A,(X)+", + "DI", "TCALL 12", "SET1 $%02X.6", "BBS $%02X.6,$%04X", + "MOV $%02X,A", "MOV !$%04X,A", "MOV (X),A", "MOV [$%02X+X],A", + "CMP X,#$%02X", "MOV !$%04X,X", "MOV1 $%04X.%d,C", "MOV $%02X,Y", + "ASL !$%04X", "MOV X,#$%02X", "POP X", "MUL YA", + "BNE $%04X", "TCALL 13", "CLR1 $%02X.6", "BBC $%02X.6,$%04X", + "MOV $%02X+X,A", "MOV !$%04X+X,A", "MOV !$%04X+Y,A", "MOV [$%02X]+Y,A", + "MOV $%02X,X", "MOV $%02X+Y,X", "MOVW $%02X,YA", "MOV $%02X+X,Y", + "DEC Y", "MOV A,Y", "CBNE $%02X+X,$%04X", "DAA A", + "CLRV", "TCALL 14", "SET1 $%02X.7", "BBS $%02X.7,$%04X", + "MOV A,$%02X", "MOV A,!$%04X", "MOV A,(X)", "MOV A,[$%02X+X]", + "MOV A,#$%02X", "MOV X,!$%04X", "NOT1 $%04X.%d", "MOV Y,$%02X", + "MOV Y,!$%04X", "NOTC", "POP Y", "SLEEP", + "BEQ $%04X", "TCALL 15", "CLR1 $%02X.7", "BBC $%02X.7,$%04X", + "MOV A,$%02X+X", "MOV A,!$%04X+X", "MOV A,!$%04X+Y", "MOV A,[$%02X]+Y", + "MOV X,$%02X", "MOV X,$%02X+Y", "MOV $%02X,$%02X", "MOV Y,$%02X+X", "INC Y", "MOV Y,A", "DBNZ Y,$%04X", "STOP" }; @@ -346,7 +331,7 @@ void S9xTraceSoundDSP (const char *s, int i1 = 0, int i2 = 0, int i3 = 0, int S9xTraceAPU () { char buffer [200]; - + uint8 b = S9xAPUOPrint (buffer, IAPU.PC - IAPU.RAM); if (apu_trace == NULL) apu_trace = fopen ("apu_trace.log", "wb"); @@ -361,7 +346,7 @@ int S9xAPUOPrint (char *buffer, uint16 Address) uint8 *p = IAPU.RAM + Address; int mode = Modes [*p]; int bytes = ModesToBytes [mode]; - + switch (bytes) { case 1: @@ -422,8 +407,8 @@ int S9xAPUOPrint (char *buffer, uint16 Address) APUCheckCarry () ? 'C' : 'c', CPU.V_Counter, CPU.Cycles, - APU.Cycles >> SNES_APU_ACCURACY); - + APU.Cycles); + return (bytes); } @@ -493,7 +478,7 @@ void S9xPrintAPUState () printf ("left: %d, right: %d, ", ch->volume_left, ch->volume_right); - static char* envelope [] = + static char* envelope [] = { "silent", "attack", "decay", "sustain", "release", "gain", "inc_lin", "inc_bent", "dec_lin", "dec_exp" diff --git a/source/snes9x/apumem.h b/source/snes9x/apumem.h index df9a3f1c..158fd577 100644 --- a/source/snes9x/apumem.h +++ b/source/snes9x/apumem.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,152 +142,162 @@ **********************************************************************************/ - #ifndef _apumemory_h_ #define _apumemory_h_ START_EXTERN_C +extern uint8 W4; extern uint8 APUROM[64]; END_EXTERN_C -static INLINE uint8 apu_get_reg (uint8 Address) +INLINE uint8 S9xAPUGetByteZ (uint8 Address) { - switch (Address) + if (Address >= 0xf0 && IAPU.DirectPage == IAPU.RAM) + { + if (Address >= 0xf4 && Address <= 0xf7) { - case 0xf0: // -w TEST - return 0; - - case 0xf1: // -w CONTROL - return 0; - - case 0xf2: // rw DSPADDR - return (IAPU.RAM[Address]); - - case 0xf3: // rw DSPDATA - return (S9xGetAPUDSP()); - - case 0xf4: // r- CPUI0 - case 0xf5: // r- CPUI1 - case 0xf6: // r- CPUI2 - case 0xf7: // r- CPUI3 - #ifdef SPC700_SHUTDOWN - IAPU.WaitAddress2 = IAPU.WaitAddress1; - IAPU.WaitAddress1 = IAPU.PC; - #endif - return (IAPU.RAM[Address]); - - case 0xf8: // rw - Normal RAM - case 0xf9: // rw - Normal RAM - return (IAPU.RAM[Address]); - - case 0xfa: // -w T0TARGET - case 0xfb: // -w T1TARGET - case 0xfc: // -w T2TARGET - return 0; - - case 0xfd: // r- T0OUT - case 0xfe: // r- T1OUT - case 0xff: // r- T2OUT - #ifdef SPC700_SHUTDOWN - IAPU.WaitAddress2 = IAPU.WaitAddress1; - IAPU.WaitAddress1 = IAPU.PC; - #endif - uint8 t = IAPU.RAM[Address] & 0xF; - IAPU.RAM[Address] = 0; - return (t); +#ifdef SPC700_SHUTDOWN + IAPU.WaitAddress2 = IAPU.WaitAddress1; + IAPU.WaitAddress1 = IAPU.PC; +#endif + return (IAPU.RAM [Address]); } - - return 0; -} - -static INLINE void apu_set_reg (uint8 byte, uint8 Address) -{ - switch (Address) + if (Address >= 0xfd) { - case 0xf0: // -w TEST - //printf("Write %02X to APU 0xF0!\n", byte); - return; - - case 0xf1: // -w CONTROL - S9xSetAPUControl(byte); - return; - - case 0xf2: // rw DSPADDR - IAPU.RAM[Address] = byte; - return; - - case 0xf3: // rw DSPDATA - S9xSetAPUDSP(byte); - return; - - case 0xf4: // -w CPUO0 - case 0xf5: // -w CPUO1 - case 0xf6: // -w CPUO2 - case 0xf7: // -w CPUO3 - APU.OutPorts[Address - 0xf4] = byte; - return; - - case 0xf8: // rw - Normal RAM - case 0xf9: // rw - Normal RAM - IAPU.RAM[Address] = byte; - return; - - case 0xfa: // -w T0TARGET - case 0xfb: // -w T1TARGET - case 0xfc: // -w T2TARGET - IAPU.RAM[Address] = byte; - if (byte == 0) - APU.TimerTarget[Address - 0xfa] = 0x100; - else - APU.TimerTarget[Address - 0xfa] = byte; - return; - - case 0xfd: // r- T0OUT - case 0xfe: // r- T1OUT - case 0xff: // r- T2OUT - return; +#ifdef SPC700_SHUTDOWN + IAPU.WaitAddress2 = IAPU.WaitAddress1; + IAPU.WaitAddress1 = IAPU.PC; +#endif + uint8 t = IAPU.RAM [Address]; + IAPU.RAM [Address] = 0; + return (t); } -} - -INLINE uint8 S9xAPUGetByteZ (uint8 Address) -{ - if (Address >= 0xf0 && IAPU.DirectPage == IAPU.RAM) - return (apu_get_reg(Address)); else - return (IAPU.DirectPage[Address]); + if (Address == 0xf3) + return (S9xGetAPUDSP ()); + + return (IAPU.RAM [Address]); + } + else + return (IAPU.DirectPage [Address]); } INLINE void S9xAPUSetByteZ (uint8 byte, uint8 Address) { if (Address >= 0xf0 && IAPU.DirectPage == IAPU.RAM) - apu_set_reg(byte, Address); + { + if (Address == 0xf3) + S9xSetAPUDSP (byte); + else + if (Address >= 0xf4 && Address <= 0xf7) + APU.OutPorts [Address - 0xf4] = byte; + else + if (Address == 0xf1) + S9xSetAPUControl (byte); + else + if (Address < 0xfd) + { + IAPU.RAM [Address] = byte; + if (Address >= 0xfa) + { + if (byte == 0) + APU.TimerTarget [Address - 0xfa] = 0x100; + else + APU.TimerTarget [Address - 0xfa] = byte; + } + } + } else - IAPU.DirectPage[Address] = byte; + IAPU.DirectPage [Address] = byte; } INLINE uint8 S9xAPUGetByte (uint32 Address) { Address &= 0xffff; + if (Address <= 0xff && Address >= 0xf0) - return (apu_get_reg(Address & 0xff)); + { + if (Address >= 0xf4 && Address <= 0xf7) + { +#ifdef SPC700_SHUTDOWN + IAPU.WaitAddress2 = IAPU.WaitAddress1; + IAPU.WaitAddress1 = IAPU.PC; +#endif + return (IAPU.RAM [Address]); + } + else + if (Address == 0xf3) + return (S9xGetAPUDSP ()); + if (Address >= 0xfd) + { +#ifdef SPC700_SHUTDOWN + IAPU.WaitAddress2 = IAPU.WaitAddress1; + IAPU.WaitAddress1 = IAPU.PC; +#endif + uint8 t = IAPU.RAM [Address]; + IAPU.RAM [Address] = 0; + return (t); + } + return (IAPU.RAM [Address]); + } else - return (IAPU.RAM[Address]); + return (IAPU.RAM [Address]); } INLINE void S9xAPUSetByte (uint8 byte, uint32 Address) { Address &= 0xffff; + if (Address <= 0xff && Address >= 0xf0) - apu_set_reg(byte, Address & 0xff); + { + if (Address == 0xf3) + S9xSetAPUDSP (byte); + else + if (Address >= 0xf4 && Address <= 0xf7) + APU.OutPorts [Address - 0xf4] = byte; else + if (Address == 0xf1) + S9xSetAPUControl (byte); + else + if (Address < 0xfd) + { + IAPU.RAM [Address] = byte; + if (Address >= 0xfa) + { + if (byte == 0) + APU.TimerTarget [Address - 0xfa] = 0x100; + else + APU.TimerTarget [Address - 0xfa] = byte; + } + } + } + else + { +#if 0 +if (Address >= 0x2500 && Address <= 0x2504) +printf ("%06d %04x <- %02x\n", ICPU.Scanline, Address, byte); +if (Address == 0x26c6) +{ + extern FILE *apu_trace; + extern FILE *trace; + APU.Flags |= TRACE_FLAG; + CPU.Flags |= TRACE_FLAG; + if (apu_trace == NULL) + apu_trace = fopen ("aputrace.log", "wb"); + if (trace == NULL) + trace = fopen ("trace.log", "wb"); + printf ("TRACING SWITCHED ON\n"); +} +#endif if (Address < 0xffc0) - IAPU.RAM[Address] = byte; + IAPU.RAM [Address] = byte; else { - APU.ExtraRAM[Address - 0xffc0] = byte; + APU.ExtraRAM [Address - 0xffc0] = byte; if (!APU.ShowROM) - IAPU.RAM[Address] = byte; + IAPU.RAM [Address] = byte; } + } } +#endif -#endif // _apumemory_h_ diff --git a/source/snes9x/bsx.cpp b/source/snes9x/bsx.cpp index e594ae31..d2c00eb9 100644 --- a/source/snes9x/bsx.cpp +++ b/source/snes9x/bsx.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - // Anonymous wrote: // Large thanks to John Weidman for all his initial research // Thanks to Seph3 for his modem notes @@ -246,9 +227,9 @@ static int is_bsx(unsigned char *); static void BSX_Map_SNES(void) { // These maps will be partially overwritten - + int c; - + // Banks 00->3F and 80->BF for (c = 0; c < 0x400; c += 16) { @@ -256,7 +237,7 @@ static void BSX_Map_SNES(void) Map[c + 1] = Map[c + 0x801] = RAM; BlockIsRAM[c + 0] = BlockIsRAM[c + 0x800] = TRUE; BlockIsRAM[c + 1] = BlockIsRAM[c + 0x801] = TRUE; - + Map[c + 2] = Map[c + 0x802] = (uint8 *) MAP_PPU; Map[c + 3] = Map[c + 0x803] = (uint8 *) MAP_PPU; Map[c + 4] = Map[c + 0x804] = (uint8 *) MAP_CPU; @@ -269,9 +250,9 @@ static void BSX_Map_SNES(void) static void BSX_Map_LoROM(void) { // These maps will be partially overwritten - + int i, c; - + // Banks 00->3F and 80->BF for (c = 0; c < 0x400; c += 16) { @@ -282,16 +263,16 @@ static void BSX_Map_LoROM(void) BlockIsROM[i] = BlockIsROM[i + 0x800] = !BSX.write_enable; } } - + // Banks 40->7F and C0->FF for (c = 0; c < 0x400; c += 16) { for (i = c; i < c + 8; i++) Map[i + 0x400] = Map[i + 0xC00] = &MapROM[(c << 11) % FlashSize]; - + for (i = c + 8; i < c + 16; i++) Map[i + 0x400] = Map[i + 0xC00] = &MapROM[(c << 11) % FlashSize] - 0x8000; - + for (i = c; i < c + 16; i++) { BlockIsRAM[i + 0x400] = BlockIsRAM[i + 0xC00] = BSX.write_enable; @@ -303,9 +284,9 @@ static void BSX_Map_LoROM(void) static void BSX_Map_HiROM(void) { // These maps will be partially overwritten - + int i, c; - + // Banks 00->3F and 80->BF for (c = 0; c < 0x400; c += 16) { @@ -316,7 +297,7 @@ static void BSX_Map_HiROM(void) BlockIsROM[i] = BlockIsROM[i + 0x800] = !BSX.write_enable; } } - + // Banks 40->7F and C0->FF for (c = 0; c < 0x400; c += 16) { @@ -332,7 +313,7 @@ static void BSX_Map_HiROM(void) static void BSX_Map_MMC(void) { int c; - + // Banks 01->0E:5000-5FFF for (c = 0x010; c < 0x0F0; c += 16) { @@ -344,7 +325,7 @@ static void BSX_Map_MMC(void) static void BSX_Map_FlashIO(void) { int c; - + if (BSX.MMC[0x0C] || BSX.MMC[0x0D]) { // Bank C0:0000, 2AAA, 5555, FF00-FF1F @@ -360,7 +341,7 @@ static void BSX_Map_FlashIO(void) static void BSX_Map_SRAM(void) { int c; - + // Banks 10->17:5000-5FFF for (c = 0x100; c < 0x180; c += 16) { @@ -373,9 +354,9 @@ static void BSX_Map_SRAM(void) static void map_psram_mirror_sub(uint32 bank) { int i, c; - + bank <<= 4; - + if (BSX.MMC[0x02]) { for (c = 0; c < 0x100; c += 16) @@ -394,10 +375,10 @@ static void map_psram_mirror_sub(uint32 bank) { for (i = c; i < c + 8; i++) Map[i + bank] = &PSRAM[(c << 11) % PSRAM_SIZE]; - + for (i = c + 8; i < c + 16; i++) Map[i + bank] = &PSRAM[(c << 11) % PSRAM_SIZE] - 0x8000; - + for (i = c; i < c + 16; i++) { BlockIsRAM[i + bank] = TRUE; @@ -410,7 +391,7 @@ static void map_psram_mirror_sub(uint32 bank) static void BSX_Map_PSRAM(void) { int c; - + // Banks 70->77:0000-FFFF // FIXME: could be toggled by $03 for (c = 0; c < 0x80; c++) @@ -419,7 +400,7 @@ static void BSX_Map_PSRAM(void) BlockIsRAM[c + 0x700] = TRUE; BlockIsROM[c + 0x700] = FALSE; } - + // Banks 20->3F:6000-7FFF mirrors 70->77:6000-7FFF for (c = 0x200; c < 0x400; c += 16) { @@ -430,15 +411,15 @@ static void BSX_Map_PSRAM(void) BlockIsROM[c + 6] = FALSE; BlockIsROM[c + 7] = FALSE; } - + if (!BSX.MMC[0x05]) // Banks 40->4F:0000-FFFF mirrors 70->77:0000-7FFF map_psram_mirror_sub(0x40); - + if (!BSX.MMC[0x06]) // Banks 50->5F:0000-FFFF mirrors 70->77:0000-7FFF map_psram_mirror_sub(0x50); - + // FIXME if (!BSX.MMC[0x03]) // Banks 60->6F:0000-FFFF mirrors 70->77:0000-7FFF (?) @@ -448,7 +429,7 @@ static void BSX_Map_PSRAM(void) static void BSX_Map_BIOS(void) { int i,c; - + // Banks 00->1F:8000-FFFF if (BSX.MMC[0x07]) { @@ -462,7 +443,7 @@ static void BSX_Map_BIOS(void) } } } - + // Banks 80->9F:8000-FFFF if (BSX.MMC[0x08]) { @@ -481,7 +462,7 @@ static void BSX_Map_BIOS(void) static void BSX_Map_RAM(void) { int c; - + // Banks 7E->7F for (c = 0; c < 16; c++) { @@ -497,9 +478,9 @@ static void BSX_Map_RAM(void) static void BSX_Map_Dirty(void) { // for the quick bank change - + int i, c; - + // Banks 00->1F and 80->9F:8000-FFFF if (BSX.MMC[0x02]) { @@ -534,21 +515,21 @@ static void BSX_Map(void) for (int i = 0; i < 32; i++) printf("BS: MMC %02X: %d\n", i, BSX.MMC[i]); #endif - + memcpy(BSX.prevMMC, BSX.MMC, sizeof(BSX.MMC)); - + // Do a quick bank change if (BSX.dirty2 && !BSX.dirty) { BSX_Map_Dirty(); BSX_Map_BIOS(); - + BSX.dirty2 = FALSE; - - Memory.map_WriteProtectROM(); + + Memory.WriteProtectROM(); return; } - + if (BSX.MMC[0x01]) { MapROM = PSRAM; @@ -559,27 +540,27 @@ static void BSX_Map(void) MapROM = FlashROM; FlashSize = FLASH_SIZE; } - + BSX_Map_SNES(); - + if (BSX.MMC[0x02]) BSX_Map_HiROM(); else BSX_Map_LoROM(); - + BSX_Map_PSRAM(); BSX_Map_SRAM(); BSX_Map_RAM(); - + BSX_Map_BIOS(); BSX_Map_FlashIO(); BSX_Map_MMC(); - + // Monitor new register changes BSX.dirty = FALSE; BSX.dirty2 = FALSE; - - Memory.map_WriteProtectROM(); + + Memory.WriteProtectROM(); } static uint8 BSX_Get_Bypass_FlashIO(uint16 offset) @@ -613,17 +594,17 @@ uint8 S9xGetBSX(uint32 address) uint8 bank = (address >> 16) & 0xFF; uint16 offset = address & 0xFFFF; uint8 t = 0; - + // MMC if ((bank >= 0x01 && bank <= 0x0E) && (offset == 0x5000)) return BSX.MMC[bank]; - + // Flash IO if (bank == 0xC0) { // default: read-through mode t = BSX_Get_Bypass_FlashIO(offset); - + // note: may be more registers, purposes unknown switch (offset) { @@ -631,12 +612,12 @@ uint8 S9xGetBSX(uint32 address) if (BSX.flash_enable) t = 0x80; // status register? break; - + case 0x5555: if (BSX.flash_enable) t = 0x80; // ??? break; - + case 0xFF00: case 0xFF02: case 0xFF04: @@ -653,7 +634,7 @@ uint8 S9xGetBSX(uint32 address) break; } } - + return t; } @@ -661,7 +642,7 @@ void S9xSetBSX(uint8 byte, uint32 address) { uint8 bank = (address >> 16) & 0xFF; uint16 offset = address & 0xFFFF; - + // MMC if ((bank >= 0x01 && bank <= 0x0E) && (offset == 0x5000)) { @@ -684,7 +665,7 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX.dirty = TRUE; } break; - + case 0x07: case 0x08: if (BSX.MMC[bank] != byte) @@ -693,7 +674,7 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX.dirty2 = TRUE; } break; - + case 0x0E: BSX.MMC[bank] = byte; if (byte && (BSX.dirty || BSX.dirty2)) @@ -701,13 +682,13 @@ void S9xSetBSX(uint8 byte, uint32 address) break; } } - + // Flash IO if (bank == 0xC0) { BSX.old_write = BSX.new_write; BSX.new_write = address; - + // ???: double writes to the desired address will bypass // flash registers if (BSX.old_write == BSX.new_write && BSX.write_enable) @@ -715,7 +696,7 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX_Set_Bypass_FlashIO(offset, byte); return; } - + // flash command handling // note: incomplete switch (offset) @@ -730,16 +711,16 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX.read_enable = TRUE; } break; - + case 0x2AAA: BSX.flash_command <<= 8; BSX.flash_command |= byte; break; - + case 0x5555: BSX.flash_command <<= 8; BSX.flash_command |= byte; - + switch (BSX.flash_command & 0xFFFFFF) { case 0xAA55F0: @@ -748,7 +729,7 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX.write_enable = FALSE; BSX.read_enable = FALSE; break; - + case 0xAA55A0: // enable writing to flash BSX.old_write = 0; @@ -757,20 +738,20 @@ void S9xSetBSX(uint8 byte, uint32 address) BSX.write_enable = TRUE; BSX_Map(); break; - + case 0xAA5570: // turn on write-protection BSX.write_enable = FALSE; BSX_Map(); break; - + case 0xAA5580: case 0xAA5510: // ??? break; - + } - + break; } } @@ -779,7 +760,7 @@ void S9xSetBSX(uint8 byte, uint32 address) uint8 S9xGetBSXPPU(uint16 address) { uint8 t = 0; - + if (address >= 0x2188 && address <= 0x219F) { // known read registers @@ -789,44 +770,44 @@ uint8 S9xGetBSXPPU(uint16 address) case 0x2188: t = BSX.PPU[0x2188]; break; - + // Test register high? (r/w) case 0x2189: t = BSX.PPU[0x2189]; break; - + case 0x218A: t = BSX.PPU[0x218A]; break; - + case 0x218C: t = BSX.PPU[0x218C]; break; - + // Transmission number low? (r/w) case 0x218E: t = BSX.PPU[0x218E]; break; - + // Transmission number high? (r/w) case 0x218F: t = BSX.PPU[0x218F]; break; - + // Status register? (r) case 0x2190: t = BSX.PPU[0x2190]; break; - + // Data register? (r/w) case 0x2192: t = BSX.PPU[0x2192]; - + // test t = BSX.test2192[BSX.out_index++]; if (BSX.out_index == 32) BSX.out_index = 0; - + BSX_RTC.ticks++; if (BSX_RTC.ticks >= 1000) { @@ -845,45 +826,45 @@ uint8 S9xGetBSXPPU(uint16 address) } if (BSX_RTC.hours >= 24) BSX_RTC.hours = 0; - + BSX.test2192[10] = BSX_RTC.seconds; BSX.test2192[11] = BSX_RTC.minutes; BSX.test2192[12] = BSX_RTC.hours; - + break; - + // Transmission status? (r/w) case 0x2193: // Data ready when bits 2/3 clear? t = BSX.PPU[0x2193] & ~0x0C; break; - + // Reset? (r/w) case 0x2194: t = BSX.PPU[0x2194]; break; - + // Unknown (r) case 0x2196: t = BSX.PPU[0x2196]; break; - + // Unknown (r/w) case 0x2197: t = BSX.PPU[0x2197]; break; - + // Modem protocol? (r/w) case 0x2199: t = BSX.PPU[0x2199]; break; - + default: t = OpenBus; break; } } - + return t; } @@ -898,68 +879,68 @@ void S9xSetBSXPPU(uint8 byte, uint16 address) case 0x2188: BSX.PPU[0x2188] = byte; break; - + // Test register high? (r/w) case 0x2189: BSX.PPU[0x2189] = byte; break; - + case 0x218A: BSX.PPU[0x218A] = byte; break; - + case 0x218B: BSX.PPU[0x218B] = byte; break; - + case 0x218C: BSX.PPU[0x218C] = byte; break; - + // Transmission number low? (r/w) case 0x218E: BSX.PPU[0x218E] = byte; break; - + // Transmission number high? (r/w) case 0x218F: BSX.PPU[0x218F] = byte; - + // ? BSX.PPU[0x218E] >>= 1; BSX.PPU[0x218E] = BSX.PPU[0x218F] - BSX.PPU[0x218E]; BSX.PPU[0x218F] >>= 1; - + BSX.PPU[0x2190] = 0x80; // ? break; - + // Strobe assert? (w) case 0x2191: BSX.PPU[0x2191] = byte; BSX.out_index = 0; break; - + // Data register? (r/w) case 0x2192: BSX.PPU[0x2192] = 0x01; // ? BSX.PPU[0x2190] = 0x80; // ? break; - + // Transmission status? (r/w) case 0x2193: BSX.PPU[0x2193] = byte; break; - + // Reset? (r/w) case 0x2194: BSX.PPU[0x2194] = byte; break; - + // Unknown (r/w) case 0x2197: BSX.PPU[0x2197] = byte; break; - + // Modem protocol? (r/w) case 0x2199: // Lots of modem strings written here when @@ -970,35 +951,27 @@ void S9xSetBSXPPU(uint8 byte, uint16 address) } } -uint8 * S9xGetBasePointerBSX(uint32 address) +uint8 * S9xGetPasePointerBSX(uint32 address) { return MapROM; } static bool8 BSX_LoadBIOS(void) { - return FALSE; // We're not loading the BIOS! +#ifndef NGC FILE *fp; - char path[_MAX_PATH + 1], name[_MAX_PATH + 1]; + char path[_MAX_PATH + 1]; bool8 r = FALSE; - + strcpy(path, S9xGetDirectory(BIOS_DIR)); strcat(path, SLASH_STR); - strcpy(name, path); - strcat(name, "BS-X.bin"); - - fp = fopen(name, "rb"); - if (!fp) - { - strcpy(name, path); - strcat(name, "BS-X.bios"); - fp = fopen(name, "rb"); - } - + strcat(path, "BS-X.bios"); + + fp = fopen(path, "rb"); if (fp) { size_t size; - + size = fread((void *) BIOSROM, 1, BIOS_SIZE, fp); fclose(fp); if (size == BIOS_SIZE) @@ -1011,61 +984,65 @@ static bool8 BSX_LoadBIOS(void) else printf("BS: BIOS not found!\n"); #endif - + return r; +#else + return false; +#endif + } void S9xInitBSX(void) { Settings.BS = FALSE; - - if (!memcmp(&Memory.ROM[0x7FC0], "Satellaview BS-X ", 21)) + + if (!memcmp(&ROM[0x7FC0], "Satellaview BS-X ", 21)) { // BS-X itself - + Settings.BS = TRUE; Settings.BSXItself = TRUE; - + Memory.LoROM = TRUE; Memory.HiROM = FALSE; - - memmove(BIOSROM, Memory.ROM, BIOS_SIZE); - + + memmove(BIOSROM, ROM, BIOS_SIZE); + FlashMode = FALSE; FlashSize = FLASH_SIZE; - + BSX.bootup = TRUE; } else { Settings.BSXItself = FALSE; - + int r1, r2; - - r1 = (is_bsx(Memory.ROM + 0x7FC0) == 1); - r2 = (is_bsx(Memory.ROM + 0xFFC0) == 1); + + r1 = (is_bsx(ROM + 0x7FC0) == 1); + r2 = (is_bsx(ROM + 0xFFC0) == 1); Settings.BS = (r1 | r2) ? TRUE : FALSE; - + if (Settings.BS) { // BS games - + Memory.LoROM = r1 ? TRUE : FALSE; Memory.HiROM = r2 ? TRUE : FALSE; - - uint8 *header = r1 ? Memory.ROM + 0x7FC0 : Memory.ROM + 0xFFC0; - + + uint8 *header = r1 ? ROM + 0x7FC0 : ROM + 0xFFC0; + FlashMode = (header[0x18] & 0xEF) == 0x20 ? FALSE : TRUE; FlashSize = (header[0x19] & 0x20) ? PSRAM_SIZE : FLASH_SIZE; - + #ifdef BSX_DEBUG for (int i = 0; i <= 0x1F; i++) printf("BS: ROM Header %02X: %02X\n", i, header[i]); printf("BS: FlashMode: %d, FlashSize: %x\n", FlashMode, FlashSize); #endif - + BSX.bootup = Settings.BSXBootup; - + if (!BSX_LoadBIOS()) { BSX.bootup = FALSE; @@ -1073,18 +1050,18 @@ void S9xInitBSX(void) } } } - + if (Settings.BS) { MapROM = NULL; - FlashROM = Memory.ROM; - + FlashROM = ROM; + time_t t; struct tm *tmr; - + time(&t); tmr = localtime(&t); - + BSX_RTC.ticks = 0; memcpy(BSX.test2192, init2192, sizeof(init2192)); BSX.test2192[10] = BSX_RTC.seconds = tmr->tm_sec; @@ -1100,12 +1077,12 @@ void S9xInitBSX(void) void S9xResetBSX(void) { if (Settings.BSXItself) - memset(Memory.ROM, 0, FLASH_SIZE); - + memset(ROM, 0, FLASH_SIZE); + memset(BSX.PPU, 0, sizeof(BSX.PPU)); memset(BSX.MMC, 0, sizeof(BSX.MMC)); memset(BSX.prevMMC, 0, sizeof(BSX.prevMMC)); - + BSX.dirty = FALSE; BSX.dirty2 = FALSE; BSX.flash_enable = FALSE; @@ -1114,22 +1091,22 @@ void S9xResetBSX(void) BSX.flash_command = 0; BSX.old_write = 0; BSX.new_write = 0; - + BSX.out_index = 0; memset(BSX.output, 0, sizeof(BSX.output)); - + // starting from the bios if (BSX.bootup) BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80; else { BSX.MMC[0x02] = FlashMode ? 0x80: 0; - + // per bios: run from psram or flash card if (FlashSize == PSRAM_SIZE) { memcpy(PSRAM, FlashROM, PSRAM_SIZE); - + BSX.MMC[0x01] = 0x80; BSX.MMC[0x03] = 0x80; BSX.MMC[0x04] = 0x80; @@ -1142,10 +1119,10 @@ void S9xResetBSX(void) BSX.MMC[0x05] = 0x80; BSX.MMC[0x06] = 0x80; } - + BSX.MMC[0x0E] = 0x80; } - + BSX_Map(); } @@ -1153,17 +1130,17 @@ void S9xFixBSXAfterSnapshotLoad(void) { uint8 temp[16]; bool8 pd1, pd2; - + pd1 = BSX.dirty; pd2 = BSX.dirty2; memcpy(temp, BSX.MMC, sizeof(BSX.MMC)); - + memcpy(BSX.MMC, BSX.prevMMC, sizeof(BSX.MMC)); BSX_Map(); - + memcpy(BSX.MMC, temp, sizeof(BSX.MMC)); BSX.dirty = pd1; - BSX.dirty2 = pd2; + BSX.dirty2 = pd2; } static bool valid_normal_bank(unsigned char bankbyte) diff --git a/source/snes9x/bsx.h b/source/snes9x/bsx.h index abf74ab6..34ad7087 100644 --- a/source/snes9x/bsx.h +++ b/source/snes9x/bsx.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _BSX_H_ #define _BSX_H_ @@ -183,17 +164,15 @@ struct SBSX uint8 test2192[32]; }; -START_EXTERN_C extern struct SBSX BSX; uint8 S9xGetBSX(uint32); void S9xSetBSX(uint8, uint32); uint8 S9xGetBSXPPU(uint16); void S9xSetBSXPPU(uint8, uint16); -uint8 * S9xGetBasePointerBSX(uint32); +uint8 * S9xGetPasePointerBSX(uint32); void S9xInitBSX(void); void S9xResetBSX(void); void S9xFixBSXAfterSnapshotLoad(void); -END_EXTERN_C #endif diff --git a/source/snes9x/c4.cpp b/source/snes9x/c4.cpp index 6c82d26f..312f94ca 100644 --- a/source/snes9x/c4.cpp +++ b/source/snes9x/c4.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include #include "c4.h" @@ -183,22 +164,22 @@ void C4TransfWireFrame () c4x = (double) C4WFXVal; c4y = (double) C4WFYVal; c4z = (double) C4WFZVal - 0x95; - + // Rotate X tanval = -(double) C4WFX2Val * 3.14159265 * 2 / 128; c4y2 = c4y * cos (tanval) - c4z * sin (tanval); c4z2 = c4y * sin (tanval) + c4z * cos (tanval); - + // Rotate Y tanval = -(double)C4WFY2Val*3.14159265*2/128; c4x2 = c4x * cos (tanval) + c4z2 * sin (tanval); c4z = c4x * - sin (tanval) + c4z2 * cos (tanval); - + // Rotate Z tanval = -(double) C4WFDist * 3.14159265*2 / 128; c4x = c4x2 * cos (tanval) - c4y2 * sin (tanval); c4y = c4x2 * sin (tanval) + c4y2 * cos (tanval); - + // Scale C4WFXVal = (short) (c4x*(double)C4WFScale/(0x90*(c4z+0x95))*0x95); C4WFYVal = (short) (c4y*(double)C4WFScale/(0x90*(c4z+0x95))*0x95); @@ -209,22 +190,22 @@ void C4TransfWireFrame2 () c4x = (double)C4WFXVal; c4y = (double)C4WFYVal; c4z = (double)C4WFZVal; - + // Rotate X tanval = -(double) C4WFX2Val * 3.14159265 * 2 / 128; c4y2 = c4y * cos (tanval) - c4z * sin (tanval); c4z2 = c4y * sin (tanval) + c4z * cos (tanval); - + // Rotate Y tanval = -(double) C4WFY2Val * 3.14159265 * 2 / 128; c4x2 = c4x * cos (tanval) + c4z2 * sin (tanval); c4z = c4x * -sin (tanval) + c4z2 * cos (tanval); - + // Rotate Z tanval = -(double)C4WFDist * 3.14159265 * 2 / 128; c4x = c4x2 * cos (tanval) - c4y2 * sin (tanval); c4y = c4x2 * sin (tanval) + c4y2 * cos (tanval); - + // Scale C4WFXVal =(short)(c4x * (double)C4WFScale / 0x100); C4WFYVal =(short)(c4y * (double)C4WFScale / 0x100); @@ -240,21 +221,21 @@ void C4CalcWireFrame () C4WFYVal = (short) (256 * (double) C4WFYVal / abs (C4WFXVal)); if (C4WFXVal < 0) C4WFXVal = -256; - else + else C4WFXVal = 256; } else { - if (C4WFYVal != 0) + if (C4WFYVal != 0) { C4WFDist = abs(C4WFYVal)+1; C4WFXVal = (short) (256 * (double)C4WFXVal / abs (C4WFYVal)); if (C4WFYVal < 0) C4WFYVal = -256; - else + else C4WFYVal = 256; } - else + else C4WFDist = 0; } } @@ -267,19 +248,19 @@ short C41FDistVal; void C4Op1F () { - if (C41FXVal == 0) + if (C41FXVal == 0) { - if (C41FYVal > 0) + if (C41FYVal > 0) C41FAngleRes = 0x80; - else + else C41FAngleRes = 0x180; } - else + else { tanval = (double) C41FYVal / C41FXVal; C41FAngleRes = (short) (atan (tanval) / (3.141592675 * 2) * 512); C41FAngleRes = C41FAngleRes; - if (C41FXVal< 0) + if (C41FXVal< 0) C41FAngleRes += 0x100; C41FAngleRes &= 0x1FF; } @@ -302,7 +283,7 @@ void C4Op0D() #ifdef ZSNES_C4 EXTERN_C void C4LoaDMem(char *C4RAM) { - memmove(C4RAM+(READ_WORD(C4RAM+0x1f45)&0x1fff), + memmove(C4RAM+(READ_WORD(C4RAM+0x1f45)&0x1fff), C4GetMemPointer(READ_3WORD(C4RAM+0x1f40)), READ_WORD(C4RAM+0x1f43)); } diff --git a/source/snes9x/c4.h b/source/snes9x/c4.h index 9bc9d83a..f8349e14 100644 --- a/source/snes9x/c4.h +++ b/source/snes9x/c4.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _C4_H_ #define _C4_H_ diff --git a/source/snes9x/c4emu.cpp b/source/snes9x/c4emu.cpp index ea809899..8af64ae3 100644 --- a/source/snes9x/c4emu.cpp +++ b/source/snes9x/c4emu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,9 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - -#ifndef ZSNES_C4 #ifdef HAVE_CONFIG_H #include #endif @@ -214,7 +194,7 @@ static void C4ConvOAM(void){ int16 SprX, SprY; uint8 SprName, SprAttr; uint8 SprCount; - + globalX=READ_WORD(Memory.C4RAM+0x0621); globalY=READ_WORD(Memory.C4RAM+0x0623); OAMptr2=Memory.C4RAM+0x200+(Memory.C4RAM[0x626]>>2); @@ -228,59 +208,62 @@ static void C4ConvOAM(void){ if(Memory.C4RAM[0x0620]!=0){ SprCount=128-Memory.C4RAM[0x626]; uint8 offset=(Memory.C4RAM[0x626]&3)*2; - uint8 *srcptr=Memory.C4RAM+0x220; - for(int i=Memory.C4RAM[0x0620]; i>0 && SprCount>0; i--, srcptr+=16){ - SprX=READ_WORD(srcptr)-globalX; - SprY=READ_WORD(srcptr+2)-globalY; - SprName=srcptr[5]; - SprAttr=srcptr[4] | srcptr[0x06]; // XXX: mask bits? - - uint8 *sprptr=C4GetMemPointer(READ_3WORD(srcptr+7)); - if(*sprptr!=0){ - int16 X, Y; - for(int SprCnt=*sprptr++; SprCnt>0 && SprCount>0; SprCnt--, sprptr+=4){ - X=(int8)sprptr[1]; - if(SprAttr&0x40){ // flip X - X=-X-((sprptr[0]&0x20)?16:8); - } - X+=SprX; - if(X>=-16 && X<=272){ - Y=(int8)sprptr[2]; - if(SprAttr&0x80){ - Y=-Y-((sprptr[0]&0x20)?16:8); + for(int prio=0x30; prio>=0; prio-=0x10){ + uint8 *srcptr=Memory.C4RAM+0x220; + for(int i=Memory.C4RAM[0x0620]; i>0 && SprCount>0; i--, srcptr+=16){ + if((srcptr[4]&0x30)!=prio) continue; + SprX=READ_WORD(srcptr)-globalX; + SprY=READ_WORD(srcptr+2)-globalY; + SprName=srcptr[5]; + SprAttr=srcptr[4] | srcptr[0x06]; // XXX: mask bits? + + uint8 *sprptr=C4GetMemPointer(READ_3WORD(srcptr+7)); + if(*sprptr!=0){ + int16 X, Y; + for(int SprCnt=*sprptr++; SprCnt>0 && SprCount>0; SprCnt--, sprptr+=4){ + X=(int8)sprptr[1]; + if(SprAttr&0x40){ // flip X + X=-X-((sprptr[0]&0x20)?16:8); } - Y+=SprY; - if(Y>=-16 && Y<=224){ - OAMptr[0]=X&0xff; - OAMptr[1]=(uint8)Y; - OAMptr[2]=SprName+sprptr[3]; - OAMptr[3]=SprAttr^(sprptr[0]&0xc0); // XXX: Carry from SprName addition? - *OAMptr2 &= ~(3<=-16 && X<=272){ + Y=(int8)sprptr[2]; + if(SprAttr&0x80){ + Y=-Y-((sprptr[0]&0x20)?16:8); + } + Y+=SprY; + if(Y>=-16 && Y<=224){ + OAMptr[0]=X&0xff; + OAMptr[1]=(uint8)Y; + OAMptr[2]=SprName+sprptr[3]; + OAMptr[3]=SprAttr^(sprptr[0]&0xc0); // XXX: Carry from SprName addition? + *OAMptr2 &= ~(3<0){ + OAMptr[0]=(uint8)SprX; + OAMptr[1]=(uint8)SprY; + OAMptr[2]=SprName; + OAMptr[3]=SprAttr; + *OAMptr2 &= ~(3<0){ - // XXX: Should we be testing -16<=SprX<=272 and -16<=SprY<=224? - OAMptr[0]=(uint8)SprX; - OAMptr[1]=(uint8)SprY; - OAMptr[2]=SprName; - OAMptr[3]=SprAttr; - *OAMptr2 &= ~(3< add an A and a C Y+=C; } @@ -533,7 +516,7 @@ static void C4BitPlaneWave(){ 0x0600, 0x0602, 0x0604, 0x0606, 0x0608, 0x060A, 0x060C, 0x060E, 0x0800, 0x0802, 0x0804, 0x0806, 0x0808, 0x080A, 0x080C, 0x080E }; - + uint8 *dst=Memory.C4RAM; uint32 waveptr=Memory.C4RAM[0x1f83]; uint16 mask1=0xc0c0; @@ -602,7 +585,7 @@ static void C4SprDisintegrate() #ifdef DEBUGGER if((Cx&~1)!=width/2 || (Cy&~1)!=height/2) printf("Center is not middle of image for disintegrate! (%d, %d) != (%d, %d)\n", Cx, Cy, width/2, height/2); #endif - + scaleX=(int16)READ_WORD(Memory.C4RAM+0x1f86); scaleY=(int16)READ_WORD(Memory.C4RAM+0x1f8f); StartX=-Cx*scaleX+(Cx<<8); @@ -610,7 +593,7 @@ static void C4SprDisintegrate() src=Memory.C4RAM+0x600; memset(Memory.C4RAM, 0, width*height/2); - + for(uint32 y=StartY, i=0; i=0) { left = SAR((int32)tan1*y, 16) - - READ_WORD(Memory.C4RAM+0x1f80) + + READ_WORD(Memory.C4RAM+0x1f80) + READ_WORD(Memory.C4RAM+0x1f86); right = SAR((int32)tan2*y, 16) - - READ_WORD(Memory.C4RAM+0x1f80) + + READ_WORD(Memory.C4RAM+0x1f80) + READ_WORD(Memory.C4RAM+0x1f86) + READ_WORD(Memory.C4RAM+0x1f93); @@ -860,7 +842,7 @@ void S9xSetC4 (uint8 byte, uint16 Address) printf("25 Multiply!\n"); if(Memory.C4RAM[0x1f4d]!=2) printf("$7f4d=%02x, expected 02 for command 25 %02x\n", Memory.C4RAM[0x1f4d], Memory.C4RAM[0x1f4d]); #endif - { + { int32 foo=READ_3WORD(Memory.C4RAM+0x1f80); int32 bar=READ_3WORD(Memory.C4RAM+0x1f83); foo*=bar; @@ -946,7 +928,7 @@ void S9xSetC4 (uint8 byte, uint16 Address) if(byte != 0) printf("C4 load: non-0 written to $7f47! Wrote %02x\n", byte); if(READ_WORD(Memory.C4RAM+0x1f45) < 0x6000 || (READ_WORD(Memory.C4RAM+0x1f45) + READ_WORD(Memory.C4RAM+0x1f43)) > 0x6c00) printf("C4 load: Dest unusual! It's %04x\n", READ_WORD(Memory.C4RAM+0x1f45)); #endif - memmove(Memory.C4RAM+(READ_WORD(Memory.C4RAM+0x1f45)&0x1fff), + memmove(Memory.C4RAM+(READ_WORD(Memory.C4RAM+0x1f45)&0x1fff), C4GetMemPointer(READ_3WORD(Memory.C4RAM+0x1f40)), READ_WORD(Memory.C4RAM+0x1f43)); } @@ -1085,4 +1067,4 @@ int16 C4CosTable[512] = { 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765 }; -#endif + diff --git a/source/snes9x/clip.cpp b/source/snes9x/clip.cpp index 13947d37..0196da42 100644 --- a/source/snes9x/clip.cpp +++ b/source/snes9x/clip.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "ppu.h" diff --git a/source/snes9x/controls.cpp b/source/snes9x/controls.cpp index 96efb9f1..adcf4897 100644 --- a/source/snes9x/controls.cpp +++ b/source/snes9x/controls.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include #include @@ -181,14 +162,7 @@ #include "cpuexec.h" #include "snapshot.h" #include "spc7110.h" -//#include "movie.h" -#ifdef NETPLAY_SUPPORT -#include "netplay.h" -#endif - -#ifdef __WIN32__ -#define snprintf _snprintf // needs ANSI compliant name -#endif +#include "movie.h" using namespace std; @@ -216,16 +190,16 @@ static set pollmap[NUMCTLS+1]; static vector multis; struct exemulti { int32 pos; - bool8 data1; + bool data1; s9xcommand_t *script; }; static set exemultis; static struct { int16 x, y; - int16 V_adj; bool8 V_var; - int16 H_adj; bool8 H_var; - bool8 mapped; + int V_adj; bool V_var; + int H_adj; bool H_var; + bool mapped; } pseudopointer[8]; static uint8 pseudobuttons[256]; @@ -273,7 +247,7 @@ static struct { static struct { int16 x[2], y[2]; uint8 buttons; - bool8 offscreen[2]; + bool offscreen[2]; uint32 ID[2]; struct crosshair crosshair[2]; } justifier; @@ -283,78 +257,101 @@ static struct { uint8 read_idx[2 /* ports */][2 /* per port */]; -bool8 pad_read = 0, pad_read_last = 0; - #define FLAG_IOBIT0 (Memory.FillRAM[0x4213]&0x40) #define FLAG_IOBIT1 (Memory.FillRAM[0x4213]&0x80) #define FLAG_IOBIT(n) ((n)?(FLAG_IOBIT1):(FLAG_IOBIT0)) -static bool8 FLAG_LATCH=false; -static int32 curcontrollers[2]={ NONE, NONE }; -static int32 newcontrollers[2]={ JOYPAD0, NONE }; +static bool FLAG_LATCH=false; +static int curcontrollers[2]={ NONE, NONE }; +static int newcontrollers[2]={ JOYPAD0, NONE }; /*******************/ // Note: these should be in asciibetical order! -#define THE_COMMANDS \ - S(BGLayeringHack), \ - S(BeginRecordingMovie), \ - S(ClipWindows), \ - S(Debugger), \ - S(DecEmuTurbo), \ - S(DecFrameRate), \ - S(DecFrameTime), \ - S(DecTurboSpeed), \ - S(DumpSPC7110Log), \ - S(EmuTurbo), \ - S(EndRecordingMovie), \ - S(ExitEmu), \ - S(IncEmuTurbo), \ - S(IncFrameRate), \ - S(IncFrameTime), \ - S(IncTurboSpeed), \ - S(InterpolateSound), \ - S(LoadFreezeFile), \ - S(LoadMovie), \ - S(LoadOopsFile), \ -/* S(Mode7Interpolate),*/ \ - S(Pause), \ - S(QuickLoad000), S(QuickLoad001), S(QuickLoad002), S(QuickLoad003), S(QuickLoad004), S(QuickLoad005), S(QuickLoad006), S(QuickLoad007), S(QuickLoad008), S(QuickLoad009), S(QuickLoad010), \ - S(QuickSave000), S(QuickSave001), S(QuickSave002), S(QuickSave003), S(QuickSave004), S(QuickSave005), S(QuickSave006), S(QuickSave007), S(QuickSave008), S(QuickSave009), S(QuickSave010), \ - S(Reset), \ - S(SaveFreezeFile), \ - S(SaveSPC), \ - S(Screenshot), \ - S(SeekToFrame), \ - S(SoftReset), \ - S(SoundChannel0), S(SoundChannel1), S(SoundChannel2), S(SoundChannel3), S(SoundChannel4), S(SoundChannel5), S(SoundChannel6), S(SoundChannel7), \ - S(SoundChannelsOn), \ - S(SwapJoypads), \ - S(SynchronizeSound), \ - S(ToggleBG0), S(ToggleBG1), S(ToggleBG2), S(ToggleBG3), \ - S(ToggleEmuTurbo), \ - S(ToggleHDMA), \ - S(ToggleSprites), \ - S(ToggleTransparency), \ - // end - -#define S(x) x - -enum command_numbers { - THE_COMMANDS - LAST_COMMAND // must be last! +static const char *command_names[]={ + "BGLayeringHack", + "BeginRecordingMovie", + "ClipWindows", + "Debugger", + "DecEmuTurbo", + "DecFrameRate", + "DecFrameTime", + "DecTurboSpeed", + "DumpSPC7110Log", + "EmuTurbo", + "EndRecordingMovie", + "ExitEmu", + "IncEmuTurbo", + "IncFrameRate", + "IncFrameTime", + "IncTurboSpeed", + "InterpolateSound", + "LoadFreezeFile", + "LoadMovie", + "LoadOopsFile", + "Mode7Interpolate", + "Pause", + "QuickLoad000", "QuickLoad001", "QuickLoad002", "QuickLoad003", "QuickLoad004", "QuickLoad005", "QuickLoad006", "QuickLoad007", "QuickLoad008", "QuickLoad009", "QuickLoad010", + "QuickSave000", "QuickSave001", "QuickSave002", "QuickSave003", "QuickSave004", "QuickSave005", "QuickSave006", "QuickSave007", "QuickSave008", "QuickSave009", "QuickSave010", + "Reset", + "SaveFreezeFile", + "SaveSPC", + "Screenshot", + "SoftReset", + "SoundChannel0", "SoundChannel1", "SoundChannel2", "SoundChannel3", "SoundChannel4", "SoundChannel5", "SoundChannel6", "SoundChannel7", + "SoundChannelsOn", + "SwapJoypads", + "SynchronizeSound", + "ToggleBG0", "ToggleBG1", "ToggleBG2", "ToggleBG3", + "ToggleEmuTurbo", + "ToggleHDMA", + "ToggleSprites", + "ToggleTransparency", + NULL // This MUST be last! }; -#undef S -#define S(x) #x +enum command_numbers { + BGLayeringHack, + BeginRecordingMovie, + ClipWindows, + Debugger, + DecEmuTurbo, + DecFrameRate, + DecFrameTime, + DecTurboSpeed, + DumpSPC7110Log, + EmuTurbo, + EndRecordingMovie, + ExitEmu, + IncEmuTurbo, + IncFrameRate, + IncFrameTime, + IncTurboSpeed, + InterpolateSound, + LoadFreezeFile, + LoadMovie, + LoadOopsFile, + Mode7Interpolate, + Pause, + QuickLoad000, QuickLoad001, QuickLoad002, QuickLoad003, QuickLoad004, QuickLoad005, QuickLoad006, QuickLoad007, QuickLoad008, QuickLoad009, QuickLoad010, + QuickSave000, QuickSave001, QuickSave002, QuickSave003, QuickSave004, QuickSave005, QuickSave006, QuickSave007, QuickSave008, QuickSave009, QuickSave010, + Reset, + SaveFreezeFile, + SaveSPC, + Screenshot, + SoftReset, + SoundChannel0, SoundChannel1, SoundChannel2, SoundChannel3, SoundChannel4, SoundChannel5, SoundChannel6, SoundChannel7, + SoundChannelsOn, + SwapJoypads, + SynchronizeSound, + ToggleBG0, ToggleBG1, ToggleBG2, ToggleBG3, + ToggleEmuTurbo, + ToggleHDMA, + ToggleSprites, + ToggleTransparency, -static const char *command_names[LAST_COMMAND+1]={ - THE_COMMANDS - NULL // This MUST be last! + LAST_COMMAND // must be last! }; -#undef S -#undef THE_COMMANDS - static const char *color_names[32]={ "Trans", "Black", "25Grey", "50Grey", "75Grey", "White", "Red", "Orange", "Yellow", "Green", "Cyan", "Sky", "Blue", "Violet", "MagicPink", "Purple", NULL, "tBlack", "t25Grey", "t50Grey", "t75Grey", "tWhite", "tRed", "tOrange", "tYellow", "tGreen", "tCyan", "tSky", "tBlue", "tViolet", "tMagicPink", "tPurple" @@ -454,7 +451,7 @@ void S9xControlsSoftReset(void){ void S9xUnmapAllControls(void){ int i; - + S9xControlsReset(); keymap.clear(); for(i=0; i<(int)multis.size(); i++){ @@ -481,7 +478,7 @@ void S9xUnmapAllControls(void){ mouse[i].cur_x=mouse[i].cur_y=0; mouse[i].buttons=1; mouse[i].ID=InvalidControlID; - if(!(mouse[i].crosshair.set&1)) mouse[i].crosshair.img=1; // no image for mouse because its only logical position is game-specific, not known by the emulator + if(!(mouse[i].crosshair.set&1)) mouse[i].crosshair.img=1; if(!(mouse[i].crosshair.set&2)) mouse[i].crosshair.fg=5; if(!(mouse[i].crosshair.set&4)) mouse[i].crosshair.bg=1; justifier.x[i]=justifier.y[i]=0; @@ -653,9 +650,9 @@ bool S9xVerifyControllers(void){ void S9xGetController(int port, enum controllers *controller, int8 *id1, int8 *id2, int8 *id3, int8 *id4){ int i; - + *controller=CTL_NONE; - *id1=*id2=*id3=*id4=-1; + *id1=*id2=*id3=*id4=0; if(port<0 || port>1) return; switch(i=newcontrollers[port]){ case MP5: @@ -679,7 +676,6 @@ void S9xGetController(int port, enum controllers *controller, int8 *id1, int8 *i case SUPERSCOPE: *controller=CTL_SUPERSCOPE; - *id1=1; return; case ONE_JUSTIFIER: case TWO_JUSTIFIERS: @@ -691,61 +687,64 @@ void S9xGetController(int port, enum controllers *controller, int8 *id1, int8 *i void S9xReportControllers(void){ int port, i; - static char buf[128]; // static because S9xMessage keeps our pointer instead of copying - char *c=buf; - + char buf[79], *c; + S9xVerifyControllers(); for(port=0; port<2; port++){ - c+=sprintf(c, "Port %d: ", port+1); + sprintf(buf, "Controller Port %d: ", port+1); + c=buf+19; switch(newcontrollers[port]){ case NONE: - c+=sprintf(c, ". "); + strcat(c, ""); break; case MP5: - c+=sprintf(c, "MP5 with pads"); + strcat(c, "MP5 with pads"); + c+=13; for(i=0; i<4; i++){ if(mp5[port].pads[i]==NONE){ - c+=sprintf(c, " . "); + strcat(c, " "); + c+=7; } else { - c+=sprintf(c, " #%d. ", mp5[port].pads[i]+1-JOYPAD0); + sprintf(c, " #%d", mp5[port].pads[i]+1-JOYPAD0); + c+=3; } } break; case JOYPAD0: case JOYPAD1: case JOYPAD2: case JOYPAD3: case JOYPAD4: case JOYPAD5: case JOYPAD6: case JOYPAD7: - c+=sprintf(c, "Pad #%d. ", (int)(newcontrollers[port]-JOYPAD0+1)); + sprintf(c, "Pad %d", newcontrollers[port]-JOYPAD0+1); break; case MOUSE0: case MOUSE1: - c+=sprintf(c, "Mouse #%d. ", (int)(newcontrollers[port]-MOUSE0+1)); + sprintf(c, "Mouse %d", newcontrollers[port]-MOUSE0+1); break; case SUPERSCOPE: - if(port==0) c+=sprintf(c, "Superscope (cannot fire). "); - else c+=sprintf(c, "Superscope. "); + if(port==0) strcat(c, "Superscope (cannot fire)"); + else strcat(c, "Superscope"); break; case ONE_JUSTIFIER: - if(port==0) c+=sprintf(c, "Blue Justifier (cannot fire). "); - else c+=sprintf(c, "Blue Justifier. "); + if(port==0) strcat(c, "Blue Justifier (cannot fire)"); + else strcat(c, "Blue Justifier"); break; case TWO_JUSTIFIERS: - if(port==0) c+=sprintf(c, "Blue and Pink Justifiers (cannot fire). "); - else c+=sprintf(c, "Blue and Pink Justifiers. "); + if(port==0) strcat(c, "Blue and Pink Justifiers (cannot fire)"); + else strcat(c, "Blue and Pink Justifiers"); break; } + S9xMessage(S9X_INFO, S9X_CONFIG_INFO, buf); } - S9xMessage(S9X_INFO, S9X_CONFIG_INFO, buf); } char *S9xGetCommandName(s9xcommand_t command){ string s; char c; - + switch(command.type){ case S9xButtonJoypad: if(command.button.joypad.buttons==0) return strdup("None"); @@ -879,7 +878,7 @@ char *S9xGetCommandName(s9xcommand_t command){ case S9xAxisPort: case S9xPointerPort: return strdup("BUG: Port should have handled this instead of calling S9xGetCommandName()"); - + case S9xNoMapping: return strdup("None"); @@ -1183,7 +1182,7 @@ s9xcommand_t S9xGetCommandT(const char *name){ i=j+1; n++; } while(name[i]!='\0'); c[n].type=S9xNoMapping; c[n].multi_press=3; - + multis.push_back(c); cmd.button.multi_idx=multis.size()-1; cmd.type=S9xButtonMulti; @@ -1292,8 +1291,7 @@ void S9xReportButton(uint32 id, bool pressed){ return; } - if(keymap[id].type==S9xButtonCommand) // skips the "already-pressed check" unless it's a command, as a hack to work around the following problem: - if(keymap[id].button_norpt==pressed) return; // FIXME: this makes the controls "stick" after loading a savestate while recording a movie and holding any button + if(keymap[id].button_norpt==pressed) return; keymap[id].button_norpt=pressed; S9xApplyCommand(keymap[id], pressed, 0); } @@ -1465,13 +1463,11 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ x=t; t=st; st=x; } if(data1){ - if(!Settings.UpAndDown) // if up+down isn't allowed AND we are NOT playing a movie, - { if(cmd.button.joypad.buttons&(SNES_LEFT_MASK|SNES_RIGHT_MASK)){ // if we're pressing left or right, then unpress and unturbo // them both first so we don't end up hittnig left AND right // accidentally. Note though that the user can still do it on - // purpose, if Settings.UpAndDown = true. + // purpose, bu specifying a single button that presses both. // This is a feature, look up glitches in tLoZ:aLttP to find // out why. joypad[cmd.button.joypad.idx].buttons &= ~(SNES_LEFT_MASK|SNES_RIGHT_MASK); @@ -1482,7 +1478,6 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ joypad[cmd.button.joypad.idx].buttons &= ~(SNES_UP_MASK|SNES_DOWN_MASK); joypad[cmd.button.joypad.idx].turbos &= ~(SNES_UP_MASK|SNES_DOWN_MASK); } - }//end up+down protection joypad[cmd.button.joypad.idx].buttons |= r; joypad[cmd.button.joypad.idx].turbos |= t; joypad[cmd.button.joypad.idx].buttons ^= s; @@ -1495,7 +1490,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ } } return; - + case S9xButtonMouse: i=0; if(cmd.button.mouse.left) i|=0x40; @@ -1506,7 +1501,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ mouse[cmd.button.mouse.idx].buttons &= ~i; } return; - + case S9xButtonSuperscope: i=0; if(cmd.button.scope.fire) i|=SUPERSCOPE_FIRE; @@ -1524,10 +1519,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ } } superscope.next_buttons |= i&(SUPERSCOPE_FIRE|SUPERSCOPE_CURSOR|SUPERSCOPE_PAUSE); -#ifndef NGC - if(!S9xMovieActive()) // PPU modification during non-recordable command screws up movie synchronization -#endif - if((superscope.next_buttons&(SUPERSCOPE_FIRE|SUPERSCOPE_CURSOR)) && + if((superscope.next_buttons&(SUPERSCOPE_FIRE|SUPERSCOPE_CURSOR)) && curcontrollers[1]==SUPERSCOPE && !(superscope.phys_buttons&SUPERSCOPE_OFFSCREEN)){ DoGunLatch(superscope.x, superscope.y); @@ -1550,7 +1542,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ justifier.buttons &= ~i; } return; - + case S9xButtonCommand: if(((enum command_numbers)cmd.button.command)>=LAST_COMMAND){ fprintf(stderr, "Unknown command %04x\n", cmd.button.command); @@ -1571,12 +1563,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xReset(); break; case SoftReset: -#ifndef NGC - S9xMovieUpdateOnReset (); - if(S9xMoviePlaying()) - S9xMovieStop (TRUE); -#endif - S9xSoftReset(); + S9xSoftReset(); break; case EmuTurbo: Settings.TurboMode = TRUE; @@ -1677,14 +1664,14 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xDisplayStateChange("Interpolated sound", Settings.InterpolatedSound); break; case LoadFreezeFile: -#ifndef NGC +#ifndef NGC S9xUnfreezeGame(S9xChooseFilename(TRUE)); -#endif +#endif break; case SaveFreezeFile: -#ifndef NGC +#ifndef NGC S9xFreezeGame(S9xChooseFilename(FALSE)); -#endif +#endif break; case LoadOopsFile: { @@ -1699,7 +1686,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xGetDirectory(SNAPSHOT_DIR), SLASH_STR, def, _MAX_EXT-1, "oops"); -#ifndef NGC +#ifndef NGC if (S9xLoadSnapshot (filename)) { sprintf (buf, "%s.%.*s loaded", def, _MAX_EXT-1, "oops"); @@ -1710,20 +1697,17 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xMessage (S9X_ERROR, S9X_FREEZE_FILE_NOT_FOUND, "Oops file not found"); } -#endif +#endif } break; -/* case Mode7Interpolate: + case Mode7Interpolate: Settings.Mode7Interpolate ^= TRUE; S9xDisplayStateChange ("Mode 7 Interpolation", Settings.Mode7Interpolate); - break;*/ + break; case Pause: Settings.Paused ^= 1; S9xDisplayStateChange ("Pause", Settings.Paused); -#if defined(NETPLAY_SUPPORT) && !defined(__WIN32__) - S9xNPSendPause(Settings.Paused); -#endif break; case QuickLoad000: case QuickLoad001: case QuickLoad002: case QuickLoad003: case QuickLoad004: case QuickLoad005: case QuickLoad006: case QuickLoad007: case QuickLoad008: case QuickLoad009: case QuickLoad010: { @@ -1732,13 +1716,13 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; - _splitpath (Memory.ROMFilename, drive, dir, def, ext); + sprintf (filename, "%s%s%s.%03d", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, i - QuickLoad000); -#ifndef NGC +#ifndef NGC if (S9xLoadSnapshot (filename)) { sprintf (buf, "%s.%03d loaded", def, i - QuickLoad000); @@ -1748,6 +1732,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ { static char *digits = "t123456789"; _splitpath (Memory.ROMFilename, drive, dir, def, ext); + sprintf (filename, "%s%s%s.zs%c", S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def, digits [i - QuickLoad000]); @@ -1762,7 +1747,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xMessage (S9X_ERROR, S9X_FREEZE_FILE_NOT_FOUND, "Freeze file not found"); } -#endif +#endif } break; case QuickSave000: case QuickSave001: case QuickSave002: case QuickSave003: case QuickSave004: case QuickSave005: case QuickSave006: case QuickSave007: case QuickSave008: case QuickSave009: case QuickSave010: @@ -1779,7 +1764,7 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ i - QuickSave000); sprintf (buf, "%s.%03d saved", def, i - QuickSave000); S9xSetInfoString (buf); -#ifndef NGC +#ifndef NGC Snapshot(filename); #endif @@ -1792,13 +1777,12 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; - _splitpath (Memory.ROMFilename, drive, dir, def, ext); strcpy (ext, "spc"); _makepath (filename, drive, S9xGetDirectory (SPC_DIR), def, ext); -#ifndef NGC +#ifndef NGC if (S9xSPCDump (filename)) sprintf (buf, "%s.%s saved", def, ext); else @@ -1826,24 +1810,24 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ Settings.SoundSync); break; case ToggleBG0: - Settings.BG_Forced ^= 1; - S9xDisplayStateChange ("BG#0", !(Settings.BG_Forced & 1)); + PPU.BG_Forced ^= 1; + S9xDisplayStateChange ("BG#0", !(PPU.BG_Forced & 1)); break; case ToggleBG1: - Settings.BG_Forced ^= 2; - S9xDisplayStateChange ("BG#1", !(Settings.BG_Forced & 2)); + PPU.BG_Forced ^= 2; + S9xDisplayStateChange ("BG#1", !(PPU.BG_Forced & 2)); break; case ToggleBG2: - Settings.BG_Forced ^= 4; - S9xDisplayStateChange ("BG#2", !(Settings.BG_Forced & 4)); + PPU.BG_Forced ^= 4; + S9xDisplayStateChange ("BG#2", !(PPU.BG_Forced & 4)); break; case ToggleBG3: - Settings.BG_Forced ^= 8; - S9xDisplayStateChange ("BG#3", !(Settings.BG_Forced & 8)); + PPU.BG_Forced ^= 8; + S9xDisplayStateChange ("BG#3", !(PPU.BG_Forced & 8)); break; case ToggleSprites: - Settings.BG_Forced ^= 16; - S9xDisplayStateChange ("Sprites", !(Settings.BG_Forced & 16)); + PPU.BG_Forced ^= 16; + S9xDisplayStateChange ("Sprites", !(PPU.BG_Forced & 16)); break; case ToggleHDMA: Settings.DisableHDMA = !Settings.DisableHDMA; @@ -1858,30 +1842,29 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ case DumpSPC7110Log: if(Settings.SPC7110) Do7110Logging(); break; - + case BeginRecordingMovie: -#ifndef NGC +#ifndef NGC if(S9xMovieActive()) S9xMovieStop(FALSE); - S9xMovieCreate(S9xChooseMovieFilename(FALSE), 0xFF, //MOVIE_OPT_FROM_SNAPSHOT MOVIE_OPT_FROM_RESET, NULL, 0); -#endif +#endif break; - + case LoadMovie: -#ifndef NGC +#ifndef NGC if(S9xMovieActive()) S9xMovieStop(FALSE); S9xMovieOpen(S9xChooseMovieFilename(TRUE), FALSE); -#endif +#endif break; case EndRecordingMovie: -#ifndef NGC +#ifndef NGC if(S9xMovieActive()) S9xMovieStop(FALSE); -#endif +#endif break; case SwapJoypads: @@ -1916,37 +1899,12 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ S9xSetInfoString(buf); break; - case SeekToFrame: { -#ifndef NGC - if (!S9xMovieActive()) - - { - S9xSetInfoString("No movie in progress."); - return; - } - - char msg[128]; - sprintf(msg, "Select frame number (current: %d)", S9xMovieGetFrameCounter()); - - const char *frameno = S9xStringInput(msg); - if (!frameno) - return; - int frameDest = atoi(frameno); - if (frameDest > 0 && frameDest > (int)S9xMovieGetFrameCounter()) - { - int distance = frameDest - S9xMovieGetFrameCounter(); - Settings.HighSpeedSeek = distance; - } -#endif - } // braces for vlocalitylocality - break; - case LAST_COMMAND: break; /* no default, so we get compiler warnings */ } } return; - + case S9xPointer: if(cmd.pointer.aim_mouse0){ mouse[0].cur_x=data1; @@ -2034,10 +1992,10 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ } else { if(cmd.axis.pointer.invert) data1=-data1; if(cmd.axis.pointer.HV){ - if(!pseudopointer[cmd.axis.pointer.idx].V_adj) pseudopointer[cmd.axis.pointer.idx].V_adj=(int16)((int32)data1*ptrspeeds[cmd.axis.pointer.speed_type]/32767); + if(!pseudopointer[cmd.axis.pointer.idx].V_adj) pseudopointer[cmd.axis.pointer.idx].V_adj=(int32)data1*ptrspeeds[cmd.axis.pointer.speed_type]/32767; pseudopointer[cmd.axis.pointer.idx].V_var=(cmd.axis.pointer.speed_type==0); } else { - if(!pseudopointer[cmd.axis.pointer.idx].H_adj) pseudopointer[cmd.axis.pointer.idx].H_adj=(int16)((int32)data1*ptrspeeds[cmd.axis.pointer.speed_type]/32767); + if(!pseudopointer[cmd.axis.pointer.idx].H_adj) pseudopointer[cmd.axis.pointer.idx].H_adj=(int32)data1*ptrspeeds[cmd.axis.pointer.speed_type]/32767; pseudopointer[cmd.axis.pointer.idx].H_var=(cmd.axis.pointer.speed_type==0); } } @@ -2081,14 +2039,12 @@ void S9xApplyCommand(s9xcommand_t cmd, int16 data1, int16 data2){ if(i>=0){ struct exemulti *e=new struct exemulti; e->pos=i; - e->data1=data1!=0; + e->data1=data1; e->script=multis[cmd.button.multi_idx]; exemultis.insert(e); } return; - - default: fprintf(stderr, "WARNING: Unknown command type %d\n", cmd.type); return; @@ -2100,10 +2056,7 @@ static void do_polling(int mp){ set::iterator itr; if(pollmap[mp].empty()) return; -#ifndef NGC - if(S9xMoviePlaying()) return; -#endif - for(itr=pollmap[mp].begin(); itr!=pollmap[mp].end(); itr++){ + for(itr=pollmap[mp].begin(); itr!=pollmap[mp].end(); itr++){ switch(maptype(keymap[*itr].type)){ case MAP_BUTTON: bool pressed; @@ -2119,45 +2072,13 @@ static void do_polling(int mp){ int16 x, y; if(S9xPollPointer(*itr, &x, &y)) S9xReportPointer(*itr, x, y); break; - + default: break; } } } -static void UpdatePolledMouse(int i) { - int16 j; - j=mouse[i-MOUSE0].cur_x-mouse[i-MOUSE0].old_x; - if(j<-127){ - mouse[i-MOUSE0].delta_x=0xff; - mouse[i-MOUSE0].old_x-=127; - } else if(j<0){ - mouse[i-MOUSE0].delta_x=0x80 | -j; - mouse[i-MOUSE0].old_x=mouse[i-MOUSE0].cur_x; - } else if(j>127){ - mouse[i-MOUSE0].delta_x=0x7f; - mouse[i-MOUSE0].old_x+=127; - } else { - mouse[i-MOUSE0].delta_x=(uint8)j; - mouse[i-MOUSE0].old_x=mouse[i-MOUSE0].cur_x; - } - j=mouse[i-MOUSE0].cur_y-mouse[i-MOUSE0].old_y; - if(j<-127){ - mouse[i-MOUSE0].delta_y=0xff; - mouse[i-MOUSE0].old_y-=127; - } else if(j<0){ - mouse[i-MOUSE0].delta_y=0x80 | -j; - mouse[i-MOUSE0].old_y=mouse[i-MOUSE0].cur_y; - } else if(j>127){ - mouse[i-MOUSE0].delta_y=0x7f; - mouse[i-MOUSE0].old_y+=127; - } else { - mouse[i-MOUSE0].delta_y=(uint8)j; - mouse[i-MOUSE0].old_y=mouse[i-MOUSE0].cur_y; - } -} - void S9xSetJoypadLatch(bool latch){ if(!latch && FLAG_LATCH){ // 1 written, 'plug in' new controllers now @@ -2182,13 +2103,37 @@ void S9xSetJoypadLatch(bool latch){ case JOYPAD4: case JOYPAD5: case JOYPAD6: case JOYPAD7: do_polling(i); break; - + case MOUSE0: case MOUSE1: do_polling(i); -#ifndef NGC - if(!S9xMoviePlaying()) -#endif - UpdatePolledMouse(i); + j=mouse[i-MOUSE0].cur_x-mouse[i-MOUSE0].old_x; + if(j<-127){ + mouse[i-MOUSE0].delta_x=0xff; + mouse[i-MOUSE0].old_x-=127; + } else if(j<0){ + mouse[i-MOUSE0].delta_x=0x80 | -j; + mouse[i-MOUSE0].old_x=mouse[i-MOUSE0].cur_x; + } else if(j>127){ + mouse[i-MOUSE0].delta_x=0x7f; + mouse[i-MOUSE0].old_x+=127; + } else { + mouse[i-MOUSE0].delta_x=j; + mouse[i-MOUSE0].old_x=mouse[i-MOUSE0].cur_x; + } + j=mouse[i-MOUSE0].cur_y-mouse[i-MOUSE0].old_y; + if(j<-127){ + mouse[i-MOUSE0].delta_y=0xff; + mouse[i-MOUSE0].old_y-=127; + } else if(j<0){ + mouse[i-MOUSE0].delta_y=0x80 | -j; + mouse[i-MOUSE0].old_y=mouse[i-MOUSE0].cur_y; + } else if(j>127){ + mouse[i-MOUSE0].delta_y=0x7f; + mouse[i-MOUSE0].old_y+=127; + } else { + mouse[i-MOUSE0].delta_y=j; + mouse[i-MOUSE0].old_y=mouse[i-MOUSE0].cur_y; + } break; case SUPERSCOPE: if(superscope.next_buttons&SUPERSCOPE_FIRE){ @@ -2220,7 +2165,7 @@ void S9xSetJoypadLatch(bool latch){ } uint8 S9xReadJOYSERn(int n){ - int i, j, r; + int i, j, r; if(n>1) n-=0x4016; assert(n==0 || n==1); @@ -2281,7 +2226,7 @@ uint8 S9xReadJOYSERn(int n){ } else { read_idx[n][0]++; return bits|1; - } + } case SUPERSCOPE: if(read_idx[n][0]<8){ return bits|((superscope.read_buttons&(0x80>>read_idx[n][0]++))?1:0); @@ -2319,12 +2264,10 @@ uint8 S9xReadJOYSERn(int n){ void S9xDoAutoJoypad(void){ int n, i, j; - + S9xSetJoypadLatch(1); S9xSetJoypadLatch(0); -#ifndef NGC - S9xMovieUpdate(false); -#endif + for(n=0; n<2; n++){ switch(i=curcontrollers[n]){ case MP5: @@ -2485,8 +2428,7 @@ void S9xControlEOF(void){ #ifndef NGC S9xMovieUpdate(); #endif - pad_read_last = pad_read; - pad_read = false; + } void S9xSetControllerCrosshair(enum crosscontrols ctl, int8 idx, const char *fg, const char *bg){ @@ -2574,83 +2516,11 @@ void MovieSetJoypad(int i, uint16 buttons){ joypad[i].buttons=buttons; } -// from movie.cpp, used for MovieGetX functions to avoid platform-dependent byte order in the file -#ifndef NGC -extern void Write16(uint16 v, uint8*& ptr); -extern uint16 Read16(const uint8*& ptr); -#endif -#ifndef NGC -bool MovieGetMouse(int i, uint8 out [5]){ - if(i<0 || i>1 || (curcontrollers[i] != MOUSE0 && curcontrollers[i] != MOUSE1)) return false; - const int n = curcontrollers[i]-MOUSE0; - uint8* ptr = out; - Write16(mouse[n].cur_x, ptr); - Write16(mouse[n].cur_y, ptr); - *ptr++ = mouse[n].buttons; - return true; -} - -void MovieSetMouse(int i, const uint8 in [5], bool inPolling){ - if(i<0 || i>1 || (curcontrollers[i] != MOUSE0 && curcontrollers[i] != MOUSE1)) return; - const int n = curcontrollers[i]-MOUSE0; - const uint8* ptr = in; - mouse[n].cur_x = Read16(ptr); - mouse[n].cur_y = Read16(ptr); - mouse[n].buttons = *ptr++; - if(inPolling) - UpdatePolledMouse(curcontrollers[i]); -} - -bool MovieGetScope(int i, uint8 out [6]){ - if(i<0 || i>1 || (curcontrollers[i] != SUPERSCOPE)) return false; - uint8* ptr = out; - Write16(superscope.x, ptr); - Write16(superscope.y, ptr); - *ptr++ = superscope.phys_buttons; - *ptr++ = superscope.next_buttons; - return true; -} - -void MovieSetScope(int i, const uint8 in [6]){ - if(i<0 || i>1 || (curcontrollers[i] != SUPERSCOPE)) return; - const uint8* ptr = in; - superscope.x = Read16(ptr); - superscope.y = Read16(ptr); - superscope.phys_buttons = *ptr++; - superscope.next_buttons = *ptr++; -} - -bool MovieGetJustifier(int i, uint8 out [11]){ - if(i<0 || i>1 || (curcontrollers[i] != ONE_JUSTIFIER && curcontrollers[i] != TWO_JUSTIFIERS)) return false; - uint8* ptr = out; - Write16(justifier.x[0], ptr); - Write16(justifier.x[1], ptr); - Write16(justifier.y[0], ptr); - Write16(justifier.y[1], ptr); - *ptr++ = justifier.buttons; - *ptr++ = justifier.offscreen[0]; - *ptr++ = justifier.offscreen[1]; - return true; -} - -void MovieSetJustifier(int i, const uint8 in [11]){ - if(i<0 || i>1 || (curcontrollers[i] != ONE_JUSTIFIER && curcontrollers[i] != TWO_JUSTIFIERS)) return; - const uint8* ptr = in; - justifier.x[0] = Read16(ptr); - justifier.x[1] = Read16(ptr); - justifier.y[0] = Read16(ptr); - justifier.y[1] = Read16(ptr); - justifier.buttons = *ptr++; - justifier.offscreen[0] = *ptr++; - justifier.offscreen[1] = *ptr++; -} -#endif - void S9xControlPreSave(struct SControlSnapshot *s){ - int i, j; + int i; ZeroMemory(s, sizeof(*s)); - s->ver=3; + s->ver=1; for(i=0; i<2; i++){ s->port1_read_idx[i]=read_idx[0][i]; s->port2_read_idx[i]=read_idx[1][i]; @@ -2659,40 +2529,10 @@ void S9xControlPreSave(struct SControlSnapshot *s){ s->mouse_speed[i]=(mouse[i].buttons&0x30)>>4; } s->justifier_select=((justifier.buttons&JUSTIFIER_SELECT)?1:0); - -#define COPY(x) {memcpy((char*)s->internal+i, &(x), sizeof(x)); i+=sizeof(x);} - i=0; - for(j=0; j<8; j++) - COPY(joypad[j].buttons); - for(j=0; j<2; j++) { - COPY(mouse[j].delta_x); - COPY(mouse[j].delta_y); - COPY(mouse[j].old_x); - COPY(mouse[j].old_y); - COPY(mouse[j].cur_x); - COPY(mouse[j].cur_y); - COPY(mouse[j].buttons); - } - COPY(superscope.x); - COPY(superscope.y); - COPY(superscope.phys_buttons); - COPY(superscope.next_buttons); - COPY(superscope.read_buttons); - for(j=0; j<2; j++) COPY(justifier.x[j]); - for(j=0; j<2; j++) COPY(justifier.y[j]); - COPY(justifier.buttons); - for(j=0; j<2; j++) COPY(justifier.offscreen[j]); - for(j=0; j<2; j++) - for(int k=0; k<2; k++) - COPY(mp5[j].pads[k]); - assert(i==sizeof(s->internal)); -#undef COPY - s->pad_read=pad_read; - s->pad_read_last=pad_read_last; } void S9xControlPostLoad(struct SControlSnapshot *s){ - int i, j; + int i; if(curcontrollers[0]==MP5 && s->ver<1){ // Crap. Old snes9x didn't support this. @@ -2713,40 +2553,4 @@ void S9xControlPostLoad(struct SControlSnapshot *s){ justifier.buttons&=~JUSTIFIER_SELECT; } FLAG_LATCH=(Memory.FillRAM[0x4016]&1)==1; - - if(s->ver>1) - { -#define COPY(x) {memcpy(&(x), (char*)s->internal+i, sizeof(x)); i+=sizeof(x);} - i=0; - for(j=0; j<8; j++) - COPY(joypad[j].buttons); - for(j=0; j<2; j++) { - COPY(mouse[j].delta_x); - COPY(mouse[j].delta_y); - COPY(mouse[j].old_x); - COPY(mouse[j].old_y); - COPY(mouse[j].cur_x); - COPY(mouse[j].cur_y); - COPY(mouse[j].buttons); - } - COPY(superscope.x); - COPY(superscope.y); - COPY(superscope.phys_buttons); - COPY(superscope.next_buttons); - COPY(superscope.read_buttons); - for(j=0; j<2; j++) COPY(justifier.x[j]); - for(j=0; j<2; j++) COPY(justifier.y[j]); - COPY(justifier.buttons); - for(j=0; j<2; j++) COPY(justifier.offscreen[j]); - for(j=0; j<2; j++) - for(int k=0; k<2; k++) - COPY(mp5[j].pads[k]); - assert(i==sizeof(s->internal)); -#undef COPY - } - if(s->ver>2) - { - pad_read=s->pad_read; - pad_read_last=s->pad_read_last; - } } diff --git a/source/snes9x/controls.h b/source/snes9x/controls.h index a81d6958..e281c74c 100644 --- a/source/snes9x/controls.h +++ b/source/snes9x/controls.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef FOO_H #define FOO_H @@ -202,7 +183,7 @@ typedef struct { uint8 type; uint8 multi_press:2; uint8 button_norpt:1; - + union { union { struct { @@ -258,7 +239,7 @@ typedef struct { uint8 threshold; // (threshold+1)/256% deflection is a // button press } joypad; - + struct { uint8 idx:3; // Pseudo-pointer number 0-7 uint8 speed_type:2; // 0=variable, 1=slow, 2=med, 3=fast @@ -329,7 +310,7 @@ const char **S9xGetAllSnes9xCommands(void); s9xcommand_t S9xGetMapping(uint32 id); void S9xUnmapID(uint32 id); -/* +/* * Button mapping functions. If a button is mapped with poll=TRUE, then * S9xPollButton will be called whenever snes9x feels a need for that mapping. * Otherwise, snes9x will assume you will call S9xReportButton() whenever the @@ -339,7 +320,7 @@ void S9xUnmapID(uint32 id); bool S9xMapButton(uint32 id, s9xcommand_t mapping, bool poll); void S9xReportButton(uint32 id, bool pressed); -/* +/* * Pointer mapping functions. If a button is mapped with poll=TRUE, then * S9xPollPointer will be called whenever snes9x feels a need for that mapping. * Otherwise, snes9x will assume you will call S9xReportPointer() whenever the @@ -354,7 +335,7 @@ void S9xReportButton(uint32 id, bool pressed); bool S9xMapPointer(uint32 id, s9xcommand_t mapping, bool poll); void S9xReportPointer(uint32 id, int16 x, int16 y); -/* +/* * Axis mapping functions. If a button is mapped with poll=TRUE, then * S9xPollAxis will be called whenever snes9x feels a need for that mapping. * Otherwise, snes9x will assume you will call S9xReportAxis() whenever the @@ -397,14 +378,6 @@ bool S9xPollAxis(uint32 id, int16 *value); */ void S9xHandlePortCommand(s9xcommand_t cmd, int16 data1, int16 data2); -/* - * Called before already-read SNES joypad data is being used by the game - * if your port defines SNES_JOY_READ_CALLBACKS - */ -#ifdef SNES_JOY_READ_CALLBACKS -void S9xOnSNESPadRead(); -#endif - /* These are for your use */ s9xcommand_t S9xGetPortCommandT(const char *name); char *S9xGetPortCommandName(s9xcommand_t command); @@ -439,9 +412,7 @@ struct SControlSnapshot { uint8 dummy2[4]; uint8 mouse_speed[2]; uint8 justifier_select; - uint8 dummy3[8]; - bool8 pad_read, pad_read_last; - uint8 internal[60]; // yes, we need to save this! + uint8 dummy3[10]; }; void S9xControlPreSave(struct SControlSnapshot *s); diff --git a/source/snes9x/copyright.h b/source/snes9x/copyright.h index e90dd1ae..1079a259 100644 --- a/source/snes9x/copyright.h +++ b/source/snes9x/copyright.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,15 +141,13 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - /* * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. * * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and * Jerremy Koot (jkoot@snes9x.com) * - * Super FX C emulator code + * Super FX C emulator code * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and * Gary Henderson. * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. diff --git a/source/snes9x/cpu.cpp b/source/snes9x/cpu.cpp index d6fb170c..8f67a21e 100644 --- a/source/snes9x/cpu.cpp +++ b/source/snes9x/cpu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "ppu.h" @@ -181,9 +162,6 @@ #include "obc1.h" #include "bsx.h" #include "snapshot.h" -#ifndef NGC -#include "logger.h" -#endif #ifndef ZSNES_FX @@ -225,17 +203,12 @@ void S9xSoftResetCPU () CPU.NMIActive = FALSE; CPU.IRQActive = FALSE; CPU.WaitingForInterrupt = FALSE; - CPU.InDMA = FALSE; - CPU.InHDMA = FALSE; - CPU.InDMAorHDMA = FALSE; - CPU.InWRAMDMAorHDMA = FALSE; - CPU.HDMARanInDMA = 0; + CPU.InDMA = CPU.InWRAM_DMA = FALSE; CPU.PCBase = NULL; CPU.PBPCAtOpcodeStart = 0xffffffff; CPU.WaitAddress = 0xffffffff; CPU.WaitCounter = 0; CPU.Cycles = 182; // Or 188. This is the cycle count just after the jump to the Reset Vector. - CPU.PrevCycles = -1; CPU.V_Counter = 0; CPU.MemSpeed = SLOW_ONE_CYCLE; CPU.MemSpeedx2 = SLOW_ONE_CYCLE * 2; @@ -243,7 +216,7 @@ void S9xSoftResetCPU () CPU.AutoSaveTimer = 0; CPU.SRAMModified = FALSE; CPU.BRKTriggered = FALSE; - CPU.IRQPending = 0; + //CPU.TriedInterleavedMode2 = FALSE; // Reset when ROM image loaded Timings.InterlaceField = FALSE; Timings.H_Max = Timings.H_Max_Master; @@ -262,7 +235,7 @@ void S9xSoftResetCPU () ICPU.S9xOpcodes = S9xOpcodesE1; ICPU.S9xOpLengths = S9xOpLengthsM1X1; ICPU.CPUExecuting = TRUE; - + S9xUnpackStatus(); } @@ -271,10 +244,7 @@ void S9xResetCPU () S9xSoftResetCPU (); Registers.SL = 0xFF; Registers.P.W = 0; - Registers.A.W = 0; - Registers.X.W = 0; - Registers.Y.W = 0; - SetFlags (MemoryFlag | IndexFlag | IRQ | Emulation); + SetFlags (MemoryFlag | IndexFlag | IRQ | Emulation); ClearFlags (Decimal); } @@ -289,7 +259,6 @@ END_EXTERN_C void S9xReset (void) { #ifndef NGC - ResetLogger(); S9xResetSaveTimer (FALSE); #endif @@ -313,6 +282,7 @@ void S9xReset (void) S9xSA1Init (); if (Settings.C4) S9xInitC4 (); + #ifndef NGC S9xInitCheatData (); #endif diff --git a/source/snes9x/cpuaddr.h b/source/snes9x/cpuaddr.h index bc66a739..06a8c1e4 100644 --- a/source/snes9x/cpuaddr.h +++ b/source/snes9x/cpuaddr.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _CPUADDR_H_ #define _CPUADDR_H_ @@ -302,7 +283,7 @@ STATIC inline uint32 AbsoluteLongSlow (AccessMode a) { // l // JSR l pushes the old bank in the middle of loading the new. // OpenBus needs to be set to account for this. if(a==JSR) OpenBus = Registers.PB; - + addr |= Immediate8Slow(a)<<16; return addr; } diff --git a/source/snes9x/cpuexec.cpp b/source/snes9x/cpuexec.cpp index 17d301ea..6b7887cd 100644 --- a/source/snes9x/cpuexec.cpp +++ b/source/snes9x/cpuexec.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "cpuops.h" @@ -182,17 +163,10 @@ extern struct FxInit_s SuperFX; void S9xMainLoop (void) { - if(ICPU.SavedAtOp) - { - ICPU.SavedAtOp = FALSE; - Registers.PCw = CPU.PBPCAtOpcodeStart; - if(CPU.PCBase) - CPU.Cycles -= CPU.MemSpeed; - goto doOp; - } - for (;;) { + APU_EXECUTE(); + if (CPU.Flags) { if (CPU.Flags & NMI_FLAG) @@ -206,11 +180,11 @@ void S9xMainLoop (void) CPU.WaitingForInterrupt = FALSE; Registers.PCw++; } - + S9xOpcode_NMI(); } } - + #ifdef DEBUGGER if ((CPU.Flags & BREAK_FLAG) && !(CPU.Flags & SINGLE_STEP_FLAG)) { @@ -228,33 +202,26 @@ void S9xMainLoop (void) } } #endif - + CHECK_SOUND(); - if (CPU.Flags & IRQ_FLAG) + if (CPU.Flags & IRQ_PENDING_FLAG) { - if (CPU.IRQPending) - // FIXME: In case of IRQ during WRAM refresh - CPU.IRQPending = 0; - else + if (CPU.WaitingForInterrupt) { - if (CPU.WaitingForInterrupt) - { - CPU.WaitingForInterrupt = FALSE; - Registers.PCw++; - } + CPU.WaitingForInterrupt = FALSE; + Registers.PCw++; + } - if (CPU.IRQActive && !Settings.DisableIRQ) - { - if (!CheckFlag(IRQ)) - // in IRQ handler $4211 is supposed to be read, so IRQ_FLAG should be cleared. - S9xOpcode_IRQ(); - } - else - CPU.Flags &= ~IRQ_FLAG; + if (CPU.IRQActive && !Settings.DisableIRQ) + { + if (!CheckFlag(IRQ)) + S9xOpcode_IRQ(); } + else + CPU.Flags &= ~IRQ_PENDING_FLAG; } - + if (CPU.Flags & SCAN_KEYS_FLAG) break; @@ -272,16 +239,14 @@ void S9xMainLoop (void) } #endif } - + #ifdef CPU_SHUTDOWN CPU.PBPCAtOpcodeStart = Registers.PBPC; #endif - doOp: + register uint8 Op; register struct SOpcodes *Opcodes; - - CPU.PrevCycles = CPU.Cycles; - + if (CPU.PCBase) { Op = CPU.PCBase[Registers.PCw]; @@ -294,7 +259,7 @@ void S9xMainLoop (void) OpenBus = Op; Opcodes = S9xOpcodesSlow; } - + if ((Registers.PCw&MEMMAP_MASK) + ICPU.S9xOpLengths[Op] >= MEMMAP_BLOCK_SIZE) { uint8 *oldPCBase = CPU.PCBase; @@ -303,29 +268,23 @@ void S9xMainLoop (void) if (oldPCBase!=CPU.PCBase || (Registers.PCw&~MEMMAP_MASK) == (0xffff & ~MEMMAP_MASK)) Opcodes = S9xOpcodesSlow; } - + Registers.PCw++; (*Opcodes[Op].S9xOpcode)(); - - if(ICPU.SavedAtOp) - { - ICPU.SavedAtOp = false; - continue; - } - - S9xAPUExecute(); - + + S9xUpdateAPUTimer(); + if (SA1.Executing) S9xSA1MainLoop(); - - while (CPU.Cycles >= CPU.NextEvent) + + if (CPU.Cycles >= CPU.NextEvent) S9xDoHEventProcessing(); } - + S9xPackStatus(); APURegisters.PC = IAPU.PC - IAPU.RAM; S9xAPUPackStatus(); - + if (CPU.Flags & SCAN_KEYS_FLAG) { #ifdef DEBUGGER @@ -339,11 +298,11 @@ void S9xMainLoop (void) void S9xSetIRQ (uint32 source) { CPU.IRQActive |= source; - CPU.Flags |= IRQ_FLAG; - + CPU.Flags |= IRQ_PENDING_FLAG; + if (CPU.WaitingForInterrupt) { - // Force IRQ to trigger immediately after WAI - + // Force IRQ to trigger immediately after WAI - // Final Fantasy Mystic Quest crashes without this. CPU.WaitingForInterrupt = FALSE; Registers.PCw++; @@ -357,10 +316,6 @@ void S9xClearIRQ (uint32 source) void S9xDoHEventProcessing (void) { -#ifdef DEBUGGER - char mes[256]; -#endif - #ifdef CPU_SHUTDOWN CPU.WaitCounter++; #endif @@ -368,23 +323,17 @@ void S9xDoHEventProcessing (void) { case HC_HBLANK_START_EVENT: S9xCheckMissingHTimerPosition(Timings.HBlankStart); - + break; - + case HC_HDMA_START_EVENT: if (IPPU.HDMA && CPU.V_Counter <= PPU.ScreenHeight) - { - #ifdef DEBUGGER - sprintf(mes, "*** HDMA HC:%04d, Channel:%02x", CPU.Cycles, IPPU.HDMA); - S9xTraceMessage(mes); - #endif IPPU.HDMA = S9xDoHDMA(IPPU.HDMA); - } - + S9xCheckMissingHTimerPosition(Timings.HDMAStart); - + break; - + case HC_HCOUNTER_MAX_EVENT: #ifndef ZSNES_FX if (Settings.SuperFX) @@ -403,12 +352,14 @@ void S9xDoHEventProcessing (void) #endif CPU.Cycles -= Timings.H_Max; - IAPU.NextAPUTimerPos -= (Timings.H_Max << SNES_APU_ACCURACY); - APU.Cycles -= (Timings.H_Max << SNES_APU_ACCURACY); - + IAPU.NextAPUTimerPos -= (Timings.H_Max << SNES_APUTIMER_ACCURACY); + if (IAPU.APUExecuting) + APU.Cycles -= Timings.H_Max; + else + APU.Cycles = 0; if ((Timings.NMITriggerPos != 0xffff) && (Timings.NMITriggerPos >= Timings.H_Max)) Timings.NMITriggerPos -= Timings.H_Max; - + ICPU.Scanline++; CPU.V_Counter++; @@ -416,9 +367,9 @@ void S9xDoHEventProcessing (void) { CPU.V_Counter = 0; Timings.InterlaceField ^= 1; - + // From byuu: - // [NTSC] + // [NTSC] // interlace mode has 525 scanlines: 263 on the even frame, and 262 on the odd. // non-interlace mode has 524 scanlines: 262 scanlines on both even and odd frames. // [PAL] @@ -428,15 +379,15 @@ void S9xDoHEventProcessing (void) Timings.V_Max = Timings.V_Max_Master + 1; // 263 (NTSC), 313?(PAL) else Timings.V_Max = Timings.V_Max_Master; // 262 (NTSC), 312?(PAL) - + Memory.FillRAM[0x213F] ^= 0x80; PPU.RangeTimeOver = 0; - + // FIXME: reading $4210 will wait 2 cycles, then perform reading, then wait 4 more cycles. Memory.FillRAM[0x4210] = Model->_5A22; CPU.Flags &= ~NMI_FLAG; Timings.NMITriggerPos = 0xffff; - + ICPU.Frame++; PPU.HVBeamCounterLatched = 0; CPU.Flags |= SCAN_KEYS_FLAG; @@ -452,7 +403,7 @@ void S9xDoHEventProcessing (void) Timings.H_Max = Timings.H_Max_Master - ONE_DOT_CYCLE; // HC=1360 else Timings.H_Max = Timings.H_Max_Master; // HC=1364 - + if (Model->_5A22 == 2) { if (CPU.V_Counter != 240 || IPPU.Interlace || !Timings.InterlaceField) // V=240 @@ -465,7 +416,7 @@ void S9xDoHEventProcessing (void) } else Timings.WRAMRefreshPos = SNES_WRAM_REFRESH_HC_v1; - + S9xCheckMissingHTimerPosition(0); if (CPU.V_Counter == PPU.ScreenHeight + FIRST_VISIBLE_LINE) // VBlank starts from V=225(240). @@ -484,7 +435,7 @@ void S9xDoHEventProcessing (void) PPU.OAMAddr = PPU.SavedOAMAddr; uint8 tmp = 0; - + if (PPU.OAMPriorityRotation) tmp = (PPU.OAMAddr & 0xFE) >> 1; if ((PPU.OAMFlip & 1) || PPU.FirstSprite!=tmp) @@ -492,7 +443,7 @@ void S9xDoHEventProcessing (void) PPU.FirstSprite = tmp; IPPU.OBJChanged = TRUE; } - + PPU.OAMFlip = 0; } @@ -507,47 +458,44 @@ void S9xDoHEventProcessing (void) } } - + if (CPU.V_Counter == PPU.ScreenHeight + 3) // FIXME: not true - { - if (Memory.FillRAM[0x4200] & 1) - S9xDoAutoJoypad(); - } - + S9xDoAutoJoypad(); + if (CPU.V_Counter == FIRST_VISIBLE_LINE) // V=1 S9xStartScreenRefresh(); - + CPU.NextEvent = -1; - + break; - + case HC_HDMA_INIT_EVENT: if (CPU.V_Counter == 0) S9xStartHDMA(); - + S9xCheckMissingHTimerPosition(Timings.HDMAInit); - + break; - + case HC_RENDER_EVENT: if (CPU.V_Counter >= FIRST_VISIBLE_LINE && CPU.V_Counter <= PPU.ScreenHeight) - RenderLine((uint8)(CPU.V_Counter - FIRST_VISIBLE_LINE)); - + RenderLine(CPU.V_Counter - FIRST_VISIBLE_LINE); + S9xCheckMissingHTimerPosition(Timings.RenderPos); - + break; - + case HC_WRAM_REFRESH_EVENT: - #ifdef DEBUGGER - sprintf(mes, "*** WRAM Refresh HC:%04d", CPU.Cycles); - S9xTraceMessage(mes); - #endif - S9xCheckMissingHTimerHalt(Timings.WRAMRefreshPos, SNES_WRAM_REFRESH_CYCLES); - CPU.Cycles += SNES_WRAM_REFRESH_CYCLES; - S9xAPUExecute(); - - S9xCheckMissingHTimerPosition(Timings.WRAMRefreshPos); - + if (!CPU.InDMA) + { + S9xCheckMissingHTimerPositionRange(Timings.WRAMRefreshPos, SNES_WRAM_REFRESH_CYCLES); + CPU.Cycles += SNES_WRAM_REFRESH_CYCLES; + S9xUpdateAPUTimer(); + APU_EXECUTE(); + } + else + S9xCheckMissingHTimerPosition(Timings.WRAMRefreshPos); + break; case HC_IRQ_1_3_EVENT: @@ -561,9 +509,9 @@ void S9xDoHEventProcessing (void) else if (PPU.VTimerEnabled && (CPU.V_Counter == PPU.VTimerPosition)) S9xSetIRQ(PPU_V_BEAM_IRQ_SOURCE); - + break; } - + S9xReschedule(); } diff --git a/source/snes9x/cpuexec.h b/source/snes9x/cpuexec.h index 101c354f..11d47a89 100644 --- a/source/snes9x/cpuexec.h +++ b/source/snes9x/cpuexec.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _CPUEXEC_H_ #define _CPUEXEC_H_ @@ -176,7 +157,7 @@ struct SOpcodes { struct SICPU { - uint8 *Speed; // unused + uint8 *Speed; struct SOpcodes *S9xOpcodes; uint8 *S9xOpLengths; uint8 _Carry; @@ -189,7 +170,6 @@ struct SICPU uint32 Frame; uint32 Scanline; uint32 FrameAdvanceCount; - bool8 SavedAtOp; }; START_EXTERN_C @@ -239,9 +219,9 @@ STATIC inline void CLEAR_IRQ_SOURCE (uint32 M) { CPU.IRQActive &= ~M; if (!CPU.IRQActive) - CPU.Flags &= ~IRQ_FLAG; + CPU.Flags &= ~IRQ_PENDING_FLAG; } - + STATIC inline void S9xFixCycles () { if (CheckEmulation ()) diff --git a/source/snes9x/cpumacro.h b/source/snes9x/cpumacro.h index f0cd8700..ebd8b906 100644 --- a/source/snes9x/cpumacro.h +++ b/source/snes9x/cpumacro.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _CPUMACRO_H_ #define _CPUMACRO_H_ @@ -245,10 +226,10 @@ mOPC(OP, Memory, ADDR, WRAP, FUNC) -#define bOP(OP, REL, COND, CHK, E) \ +#define bOP(OP, COND, CHK, E) \ static void Op##OP (void) { \ pair newPC; \ - newPC.W = REL(JUMP); \ + newPC.W = Relative(JUMP); \ BranchCheck##CHK (); \ if(COND){ \ AddCycles(ONE_CYCLE); \ @@ -309,7 +290,7 @@ STATIC inline void ADC (uint8 Work8) { ICPU._Carry = Ans16 >= 0x100; - if (~(Registers.AL ^ Work8) & + if (~(Registers.AL ^ Work8) & (Work8 ^ (uint8) Ans16) & 0x80) SetOverflow(); else diff --git a/source/snes9x/cpuops.cpp b/source/snes9x/cpuops.cpp index 83e5a9be..706a9b83 100644 --- a/source/snes9x/cpuops.cpp +++ b/source/snes9x/cpuops.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - /*****************************************************************************/ /* CPU-S9xOpcodes.CPP */ /* This file contains all the opcodes */ @@ -181,7 +162,7 @@ #include "dsp1.h" #ifdef SA1_OPCODES -#define AddCycles(n) {} +#define AddCycles(n) #else #define AddCycles(n) CPU.Cycles+=n #endif @@ -830,10 +811,10 @@ static void OpA9M0 (void) { static void OpA9Slow (void) { if(CheckMemory()) { - Registers.AL = Immediate8Slow(READ); + Registers.AL = Immediate8(READ); SetZN(Registers.AL); } else { - Registers.A.W = Immediate16Slow(READ); + Registers.A.W = Immediate16(READ); SetZN(Registers.A.W); } } @@ -1523,39 +1504,51 @@ mOPM (0CSlow, AbsoluteSlow, WRAP_BANK, TSB) #ifndef SA1_OPCODES inline void CPUShutdown() { - if (Settings.Shutdown && Registers.PBPC == CPU.WaitAddress) + if (Settings.Shutdown && Registers.PBPC == CPU.WaitAddress) + { + // Don't skip cycles with a pending NMI or IRQ - could cause delayed + // interrupt. Interrupts are delayed for a few cycles already, but + // the delay could allow the shutdown code to cycle skip again. + // Was causing screen flashing on Top Gear 3000. + + if (CPU.WaitCounter == 0 && + !(CPU.Flags & (IRQ_PENDING_FLAG | NMI_FLAG))) { - // Don't skip cycles with a pending NMI or IRQ - could cause delayed interrupt. - if (CPU.WaitCounter == 0 && !(CPU.Flags & (IRQ_FLAG | NMI_FLAG))) + CPU.WaitAddress = 0xffffffff; + if (Settings.SA1) + S9xSA1ExecuteDuringSleep (); + CPU.Cycles = CPU.NextEvent; + S9xUpdateAPUTimer(); + if (IAPU.APUExecuting) + { + ICPU.CPUExecuting = FALSE; + do { - CPU.WaitAddress = 0xffffffff; - if (Settings.SA1) - S9xSA1ExecuteDuringSleep(); - CPU.Cycles = CPU.NextEvent; - ICPU.CPUExecuting = FALSE; - S9xAPUExecute(); - ICPU.CPUExecuting = TRUE; - } - else - if (CPU.WaitCounter >= 2) - CPU.WaitCounter = 1; - else - CPU.WaitCounter--; + APU_EXECUTE1(); + } while (APU.Cycles < CPU.NextEvent); + ICPU.CPUExecuting = TRUE; + } } + else + if (CPU.WaitCounter >= 2) + CPU.WaitCounter = 1; + else + CPU.WaitCounter--; + } } #else inline void CPUShutdown() { - if (Settings.Shutdown && Registers.PBPC == CPU.WaitAddress) + if (Settings.Shutdown && Registers.PBPC == CPU.WaitAddress) + { + if (CPU.WaitCounter >= 1) { - if (CPU.WaitCounter >= 1) - { - SA1.Executing = FALSE; - SA1.CPUExecuting = FALSE; - } - else - CPU.WaitCounter++; + SA1.Executing = FALSE; + SA1.CPUExecuting = FALSE; } + else + CPU.WaitCounter++; + } } #endif #else @@ -1563,59 +1556,55 @@ inline void CPUShutdown() #endif /* BCC */ -bOP(90E0, Relative, !CheckCarry(), 0, 0) -bOP(90E1, Relative, !CheckCarry(), 0, 1) -bOP(90Slow, RelativeSlow, !CheckCarry(), 0, CheckEmulation()) +bOP(90E0, !CheckCarry(), 0, 0) +bOP(90E1, !CheckCarry(), 0, 1) +bOP(90Slow, !CheckCarry(), 0, CheckEmulation()) /* BCS */ -bOP(B0E0, Relative, CheckCarry(), 0, 0) -bOP(B0E1, Relative, CheckCarry(), 0, 1) -bOP(B0Slow, RelativeSlow, CheckCarry(), 0, CheckEmulation()) +bOP(B0E0, CheckCarry(), 0, 0) +bOP(B0E1, CheckCarry(), 0, 1) +bOP(B0Slow, CheckCarry(), 0, CheckEmulation()) /* BEQ */ -bOP(F0E0, Relative, CheckZero(), 2, 0) -bOP(F0E1, Relative, CheckZero(), 2, 1) -bOP(F0Slow, RelativeSlow, CheckZero(), 2, CheckEmulation()) +bOP(F0E0, CheckZero(), 2, 0) +bOP(F0E1, CheckZero(), 2, 1) +bOP(F0Slow, CheckZero(), 2, CheckEmulation()) /* BMI */ -bOP(30E0, Relative, CheckNegative(), 1, 0) -bOP(30E1, Relative, CheckNegative(), 1, 1) -bOP(30Slow, RelativeSlow, CheckNegative(), 1, CheckEmulation()) +bOP(30E0, CheckNegative(), 1, 0) +bOP(30E1, CheckNegative(), 1, 1) +bOP(30Slow, CheckNegative(), 1, CheckEmulation()) /* BNE */ -bOP(D0E0, Relative, !CheckZero(), 1, 0) -bOP(D0E1, Relative, !CheckZero(), 1, 1) -bOP(D0Slow, RelativeSlow, !CheckZero(), 1, CheckEmulation()) +bOP(D0E0, !CheckZero(), 1, 0) +bOP(D0E1, !CheckZero(), 1, 1) +bOP(D0Slow, !CheckZero(), 1, CheckEmulation()) /* BPL */ -bOP(10E0, Relative, !CheckNegative(), 1, 0) -bOP(10E1, Relative, !CheckNegative(), 1, 1) -bOP(10Slow, RelativeSlow, !CheckNegative(), 1, CheckEmulation()) +bOP(10E0, !CheckNegative(), 1, 0) +bOP(10E1, !CheckNegative(), 1, 1) +bOP(10Slow, !CheckNegative(), 1, CheckEmulation()) /* BRA */ -bOP(80E0, Relative, 1, X, 0) -bOP(80E1, Relative, 1, X, 1) -bOP(80Slow, RelativeSlow, 1, X, CheckEmulation()) +bOP(80E0, 1, X, 0) +bOP(80E1, 1, X, 1) +bOP(80Slow, 1, X, CheckEmulation()) /* BVC */ -bOP(50E0, Relative, !CheckOverflow(), 0, 0) -bOP(50E1, Relative, !CheckOverflow(), 0, 1) -bOP(50Slow, RelativeSlow, !CheckOverflow(), 0, CheckEmulation()) +bOP(50E0, !CheckOverflow(), 0, 0) +bOP(50E1, !CheckOverflow(), 0, 1) +bOP(50Slow, !CheckOverflow(), 0, CheckEmulation()) /* BVS */ -bOP(70E0, Relative, CheckOverflow(), 0, 0) -bOP(70E1, Relative, CheckOverflow(), 0, 1) -bOP(70Slow, RelativeSlow, CheckOverflow(), 0, CheckEmulation()) +bOP(70E0, CheckOverflow(), 0, 0) +bOP(70E1, CheckOverflow(), 0, 1) +bOP(70Slow, CheckOverflow(), 0, CheckEmulation()) /* BRL */ static void Op82 (void) { S9xSetPCBase(ICPU.ShiftedPB + RelativeLong(JUMP)); } -static void Op82Slow (void) { - S9xSetPCBase(ICPU.ShiftedPB + RelativeLongSlow(JUMP)); -} - /*****************************************************************************/ /* Flag Instructions ******************************************************* */ @@ -3045,9 +3034,9 @@ static void Op44X0 (void) { static void Op44Slow (void) { uint32 SrcBank; - OpenBus = Registers.DB = Immediate8Slow(NONE); + OpenBus = Registers.DB = Immediate8(NONE); ICPU.ShiftedDB = Registers.DB << 16; - OpenBus = SrcBank = Immediate8Slow(NONE); + OpenBus = SrcBank = Immediate8(NONE); S9xSetByte(OpenBus=S9xGetByte ((SrcBank << 16) + Registers.X.W), ICPU.ShiftedDB + Registers.Y.W); @@ -3205,9 +3194,15 @@ static void OpCB (void) { // XXX: FIXME if(Settings.Shutdown){ SA1.Cycles = SA1.NextEvent; - SA1.Executing = FALSE; - //S9xAPUExecute(); // FIXME - SA1.Executing = TRUE; + if (IAPU.APUExecuting) + { + SA1.Executing = FALSE; + do + { + APU_EXECUTE1 (); + } while (APU.Cycles < SA1.NextEvent); + SA1.Executing = TRUE; + } } #endif #else // SA1_OPCODES @@ -3223,15 +3218,20 @@ static void OpCB (void) { if (Settings.Shutdown) { CPU.Cycles = CPU.NextEvent; - ICPU.CPUExecuting = FALSE; - S9xAPUExecute(); - ICPU.CPUExecuting = TRUE; - } - else + S9xUpdateAPUTimer(); + if (IAPU.APUExecuting) + { + ICPU.CPUExecuting = FALSE; + do + { + APU_EXECUTE1 (); + } while (APU.Cycles < CPU.NextEvent); + ICPU.CPUExecuting = TRUE; + } + } else { AddCycles(TWO_CYCLES); -#else - AddCycles(TWO_CYCLES); #endif + } } #endif // SA1_OPCODES } @@ -3248,10 +3248,9 @@ extern FILE *trace; extern FILE *trace2; #endif static void Op42 (void) { -#ifdef DEBUGGER - uint8 byte = (uint8) +#ifndef NGC + uint8 byte = S9xGetWord(Registers.PBPC); #endif - S9xGetWord(Registers.PBPC); Registers.PCw++; #ifdef DEBUGGER // Hey, let's use this to trigger debug modes @@ -3611,7 +3610,7 @@ struct SOpcodes S9xOpcodesSlow[256] = { {Op73Slow}, {Op74Slow}, {Op75Slow}, {Op76Slow}, {Op77Slow}, {Op78}, {Op79Slow}, {Op7ASlow}, {Op7B}, {Op7CSlow}, {Op7DSlow}, {Op7ESlow}, {Op7FSlow}, {Op80Slow}, {Op81Slow}, - {Op82Slow}, {Op83Slow}, {Op84Slow}, {Op85Slow}, {Op86Slow}, + {Op82}, {Op83Slow}, {Op84Slow}, {Op85Slow}, {Op86Slow}, {Op87Slow}, {Op88Slow}, {Op89Slow}, {Op8ASlow}, {Op8BSlow}, {Op8CSlow}, {Op8DSlow}, {Op8ESlow}, {Op8FSlow}, {Op90Slow}, {Op91Slow}, {Op92Slow}, {Op93Slow}, {Op94Slow}, {Op95Slow}, diff --git a/source/snes9x/cpuops.h b/source/snes9x/cpuops.h index 06d8c165..c6abd0b6 100644 --- a/source/snes9x/cpuops.h +++ b/source/snes9x/cpuops.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _CPUOPS_H_ #define _CPUOPS_H_ void S9xOpcode_NMI (); diff --git a/source/snes9x/crosshairs.cpp b/source/snes9x/crosshairs.cpp index c0ee542e..3f32d136 100644 --- a/source/snes9x/crosshairs.cpp +++ b/source/snes9x/crosshairs.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifdef HAVE_CONFIG_H #include #endif @@ -454,7 +435,7 @@ bool S9xLoadCrosshairFile(int idx, const char *filename){ int i, r; char *s; FILE *fp; - + if(idx<1 || idx>31) return false; if((s=(char *)calloc(15*15+1, sizeof(char)))==NULL){ fprintf(stderr, "S9xLoadCrosshairFile: malloc error while reading "); diff --git a/source/snes9x/crosshairs.h b/source/snes9x/crosshairs.h index b9c7ac5e..02df50f1 100644 --- a/source/snes9x/crosshairs.h +++ b/source/snes9x/crosshairs.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef CROSSHAIRS_H #define CROSSHAIRS_H diff --git a/source/snes9x/data.cpp b/source/snes9x/data.cpp index 6c7b563e..738b45ae 100644 --- a/source/snes9x/data.cpp +++ b/source/snes9x/data.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" uint8 add32_32 [32][32] = { diff --git a/source/snes9x/debug.cpp b/source/snes9x/debug.cpp index 073ec6dd..0a531aa6 100644 --- a/source/snes9x/debug.cpp +++ b/source/snes9x/debug.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include #ifdef HAVE_STRINGS_H #include @@ -189,6 +170,12 @@ static void WhatsUsed (); EXTERN_C SDMA DMA[8]; extern struct SCheatData Cheat; +#ifdef SPCTOOL +#include "spctool/spc700.h" +extern "C" void TraceSPC (unsigned char *PC, unsigned short YA, unsigned char X, + SPCFlags PS, unsigned char *SP); +#endif + FILE *trace = NULL; FILE *trace2 = NULL; struct SBreakPoint S9xBreakpoint[6]; @@ -236,7 +223,7 @@ char *HelpMessage[] = { "bs [Number] [Address] - Enable/Disable Breakpoint", " [Enable example: BS #2 $02:8002]", " [Disable example: BS #2]", - "c - Dump SNES colour palette", + "c - Dump SNES colour palette", "W - Show what SNES hardware features a ROM is using", " which might not be implemented yet.", "w - Show some SNES hardware features used so far in this frame", @@ -731,7 +718,7 @@ uint8 S9xOPrint (char *Line, uint8 Bank, uint16 Address) break; } // XXX: - sprintf (Line, "%-44s A:%04X X:%04X Y:%04X D:%04X DB:%02X S:%04X P:%c%c%c%c%c%c%c%c%c HC:%04d VC:%03d FC:%02d %02x", + sprintf (Line, "%-44s A:%04X X:%04X Y:%04X D:%04X DB:%02X S:%04X P:%c%c%c%c%c%c%c%c%c HC:%03d VC:%03ld %02x", Line, Registers.A.W, Registers.X.W, Registers.Y.W, Registers.D.W, Registers.DB, Registers.S.W, CheckEmulation () ? 'E' : 'e', @@ -745,7 +732,6 @@ uint8 S9xOPrint (char *Line, uint8 Bank, uint16 Address) CheckCarry () ? 'C' : 'c', Cycles, CPU.V_Counter, - IPPU.FrameCount, CPU.IRQActive); CPU.Cycles = Cycles; @@ -1243,7 +1229,7 @@ static void ProcessDebugCommand (char *Line) S9xAddCheat (TRUE, TRUE, Address, Byte); return; } - + if (strncasecmp (Line, "dump", 4) == 0) { int Count; @@ -1435,11 +1421,18 @@ static void ProcessDebugCommand (char *Line) extern FILE *apu_trace; if (APU.Flags & TRACE_FLAG) { +#ifdef SPCTOOL + printf ("ENABLED\n"); + _SetSPCDbg (TraceSPC); //Install debug handler +#endif if (apu_trace == NULL) apu_trace = fopen ("aputrace.log", "wb"); } else { +#ifdef SPCTOOL + _SetSPCDbg (NULL); +#endif if (apu_trace) { fclose (apu_trace); @@ -1467,7 +1460,7 @@ static void ProcessDebugCommand (char *Line) printf ("SPC700 sample addresses at 0x%04x:\n", APU.DSP [APU_DIR] << 8); for (int i = 0; i < 256; i++) { - uint8 *dir = IAPU.RAM + + uint8 *dir = IAPU.RAM + (((APU.DSP [APU_DIR] << 8) + i * 4) & 0xffff); int addr = *dir + (*(dir + 1) << 8); @@ -1506,8 +1499,13 @@ static void ProcessDebugCommand (char *Line) { printf ("APU in-ports: %02X %02X %02X %02X\n", IAPU.RAM [0xF4], IAPU.RAM [0xF5], IAPU.RAM [0xF6], IAPU.RAM [0xF7]); +#ifdef SPCTOOL + printf ("APU out-ports: %02X %02X %02X %02X\n", + _SPCOutP [0], _SPCOutP [1], _SPCOutP [2], _SPCOutP [3]); +#else printf ("APU out-ports: %02X %02X %02X %02X\n", APU.OutPorts [0], APU.OutPorts [1], APU.OutPorts [2], APU.OutPorts [3]); +#endif printf ("ROM/RAM switch: %s\n", (IAPU.RAM [0xf1] & 0x80) ? "ROM" : "RAM"); for (int i = 0; i < 3; i++) if (APU.TimerEnabled [i]) @@ -1749,7 +1747,7 @@ static void ProcessDebugCommand (char *Line) (Registers.P.W & 1) != 0 ? "C" : "c", (Registers.P.W & 256) != 0 ? "E" : "e"); DPrint (String); -#endif +#endif S9xOPrint (String, Bank, Address); DPrint (String); } @@ -1821,7 +1819,7 @@ static void WhatsUsed () printf ("Screen mode: %d, ", PPU.BGMode); if (PPU.BGMode <= 1 && (Memory.FillRAM [0x2105] & 8)) printf ("(BG#2 Priority)"); - + printf ("Brightness: %d", PPU.Brightness); if (Memory.FillRAM[0x2100] & 0x80) printf (" (screen blanked)"); @@ -1904,7 +1902,7 @@ static void WhatsUsed () { printf ("BG%d: VOffset:%d, HOffset:%d, W:%d, H:%d, TS:%d, BA:0x%04x, TA:0x%04X\n", i, PPU.BG[i].VOffset, PPU.BG[i].HOffset, - (PPU.BG[i].SCSize & 1) * 32 + 32, + (PPU.BG[i].SCSize & 1) * 32 + 32, (PPU.BG[i].SCSize & 2) * 16 + 32, PPU.BG[i].BGSize * 8 + 8, PPU.BG[i].SCBase, @@ -1939,7 +1937,7 @@ static void WhatsUsed () printf ("OBJ,"); break; } - + switch ((Memory.FillRAM [0x2130] & 0x30) >> 4) { case 0: s = "always on"; break; @@ -1947,7 +1945,7 @@ static void WhatsUsed () case 2: s = "outside"; break; case 3: s = "always off"; break; } - + printf ("\nSub-screen (%s): ", s); for (i = 0; i < 5; i++) if (Memory.FillRAM[0x212d] & (1 << i)) diff --git a/source/snes9x/debug.h b/source/snes9x/debug.h index 289fd9dd..3d193c34 100644 --- a/source/snes9x/debug.h +++ b/source/snes9x/debug.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _DEBUG_H_ #define _DEBUG_H_ diff --git a/source/snes9x/display.h b/source/snes9x/display.h index c571d71d..9565ab9a 100644 --- a/source/snes9x/display.h +++ b/source/snes9x/display.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _DISPLAY_H_ #define _DISPLAY_H_ @@ -169,11 +150,11 @@ START_EXTERN_C void S9xSetPalette (); void S9xTextMode (); void S9xGraphicsMode (); +void S9xLoadConfigFiles(char **argv, int argc); +char *S9xParseArgs (char **argv, int argc); void S9xParseArg (char **argv, int &index, int argc); void S9xExtraUsage (); -void S9xLoadConfigFiles(char **argv, int argc); -char *S9xParseArgs (char **argv, int argc); void S9xUsage (); void S9xInitDisplay (int argc, char **argv); void S9xDeinitDisplay (); @@ -190,7 +171,7 @@ void S9xNextController (); bool8 S9xLoadROMImage (const char *string); const char *S9xSelectFilename (const char *def, const char *dir, const char *ext, const char *title); -const char *S9xStringInput(const char *message); + const char *S9xChooseFilename (bool8 read_only); bool8 S9xOpenSnapshotFile (const char *base, bool8 read_only, STREAM *file); void S9xCloseSnapshotFile (STREAM file); diff --git a/source/snes9x/dma.cpp b/source/snes9x/dma.cpp index 92f502c2..c5df50f1 100644 --- a/source/snes9x/dma.cpp +++ b/source/snes9x/dma.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,13 +141,12 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifdef HAVE_CONFIG_H #include #endif #include "snes9x.h" + #include "memmap.h" #include "ppu.h" #include "cpuexec.h" @@ -174,1224 +156,1119 @@ #include "gfx.h" #include "sa1.h" #include "spc7110.h" + +#ifdef SDD1_DECOMP #include "sdd1emu.h" +#endif -extern uint8 *HDMAMemPointers[8]; -extern int HDMA_ModeByteCounts[8]; -static uint8 sdd1_decode_buffer[0x10000]; +#ifdef SDD1_DECOMP +uint8 buffer[0x10000]; +#endif +extern int HDMA_ModeByteCounts [8]; +extern uint8 *HDMAMemPointers [8]; +#if defined(__linux__) || defined(__WIN32__) || defined(__MACOSX__) static int S9xCompareSDD1IndexEntries (const void *p1, const void *p2) { return (*(uint32 *) p1 - *(uint32 *) p2); } +#endif -// Add 8 cycles per byte, sync APU, and do HC related events. -// If HDMA was done in S9xDoHEventProcessing(), check if it used the same channel as DMA. -static inline bool8 addCyclesInDMA (uint8 dma_channel) +static inline void S9xTrySyncAPUInDMA (void) { - CPU.Cycles += SLOW_ONE_CYCLE; - S9xAPUExecute(); - while (CPU.Cycles >= CPU.NextEvent) - S9xDoHEventProcessing(); - - if (CPU.HDMARanInDMA & (1 << dma_channel)) - { - CPU.HDMARanInDMA = 0; - #if 1 - printf("HDMA and DMA use the same channel %d!\n", dma_channel); - #endif - // If HDMA triggers in the middle of DMA transfer and it uses the same channel, - // it kills the DMA transfer immediately. $43x2 and $43x5 stop updating. - return FALSE; - } - - CPU.HDMARanInDMA = 0; - return TRUE; +#ifdef SPC700_C + S9xUpdateAPUTimer(); + APU_EXECUTE(); +#endif } -bool8 S9xDoDMA (uint8 Channel) +/**********************************************************************************************/ +/* S9xDoDMA() */ +/* This function preforms the general dma transfer */ +/**********************************************************************************************/ + +void S9xDoDMA (uint8 Channel) { - CPU.InDMA = TRUE; - CPU.InDMAorHDMA = TRUE; + uint8 Work; - SDMA *d = &DMA[Channel]; + if (Channel > 7 || CPU.InDMA) + return; - // Check invalid DMA first - if ((d->ABank == 0x7E || d->ABank == 0x7F) && d->BAddress == 0x80 && !d->ReverseTransfer) - { - // Attempting a DMA from WRAM to $2180 will not work, WRAM will not be written. - // Attempting a DMA from $2180 to WRAM will similarly not work, - // the value written is (initially) the OpenBus value. - // In either case, the address in $2181-3 is not incremented. - - // Does an invalid DMA actually take time? - // I'd say yes, since 'invalid' is probably just the WRAM chip - // not being able to read and write itself at the same time - // And no, PPU.WRAM should not be updated. - - int32 c = d->TransferBytes; - // Writing $0000 to $43x5 actually results in a transfer of $10000 bytes, not 0. - if (c == 0) - c = 0x10000; - - // 8 cycles per channel - CPU.Cycles += SLOW_ONE_CYCLE; - // 8 cycles per byte - while (c) - { - d->TransferBytes--; - d->AAddress++; - c--; - if (!addCyclesInDMA(Channel)) - { - CPU.InDMA = FALSE; - CPU.InDMAorHDMA = FALSE; - return FALSE; - } - } - - #ifdef DEBUGGER - if (Settings.TraceDMA) - { - sprintf(String, "DMA[%d]: WRAM Bank:%02X->$2180", Channel, d->ABank); - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - } - #endif - - CPU.InDMA = FALSE; - CPU.InDMAorHDMA = FALSE; - return TRUE; - } + CPU.InDMA = TRUE; + bool8 in_sa1_dma = FALSE; + uint8 *in_sdd1_dma = NULL; + uint8 *spc7110_dma=NULL; + bool s7_wrap=false; + SDMA *d = &DMA[Channel]; - // Prepare for accessing $2118-2119 - switch (d->BAddress) - { - case 0x18: - case 0x19: - if (IPPU.RenderThisFrame) - FLUSH_REDRAW(); - break; - } - int32 inc = d->AAddressFixed ? 0 : (!d->AAddressDecrement ? 1 : -1); - int32 count = d->TransferBytes; - // Writing $0000 to $43x5 actually results in a transfer of $10000 bytes, not 0. - if (count == 0) - count = 0x10000; + int32 count = d->TransferBytes; - // Prepare for custom chip DMA + if (count == 0) + count = 0x10000; - // S-DD1 + int inc = d->AAddressFixed ? 0 : (!d->AAddressDecrement ? 1 : -1); - uint8 *in_sdd1_dma = NULL; + if((d->ABank==0x7E || d->ABank==0x7F) && d->BAddress==0x80 && !d->TransferDirection) + { + d->AAddress+= d->TransferBytes; + //does an invalid DMA actually take time? + // I'd say yes, since 'invalid' is probably just the WRAM chip + // not being able to read and write itself at the same time + // And no, PPU.WRAM should not be updated. + CPU.Cycles+=(d->TransferBytes+1)*SLOW_ONE_CYCLE; + S9xTrySyncAPUInDMA(); - if (Settings.SDD1) - { - if (d->AAddressFixed && Memory.FillRAM[0x4801] > 0) - { - // XXX: Should probably verify that we're DMAing from ROM? - // And somewhere we should make sure we're not running across a mapping boundary too. - // Hacky support for pre-decompressed S-DD1 data - inc = !d->AAddressDecrement ? 1 : -1; - - if (Settings.SDD1Pack) // XXX: Settings.SDD1Pack == true -> on-the-fly decoding. Weird. - { - // on-the-fly S-DD1 decoding - uint8 *in_ptr = GetBasePointer(((d->ABank << 16) | d->AAddress)); - if (in_ptr) - { - in_ptr += d->AAddress; - SDD1_decompress(sdd1_decode_buffer, in_ptr, d->TransferBytes); - } - #ifdef DEBUGGER - else - { - sprintf(String, "S-DD1: DMA from non-block address $%02X:%04X", d->ABank, d->AAddress); - S9xMessage(S9X_WARNING, S9X_DMA_TRACE, String); - } - #endif - - in_sdd1_dma = sdd1_decode_buffer; - } - else - { - // S-DD1 graphics pack support - // XXX: Who still uses the graphics pack? - uint32 address = (((d->ABank << 16) | d->AAddress) & 0xfffff) << 4; - address |= Memory.FillRAM[0x4804 + ((d->ABank - 0xc0) >> 4)]; - - void *ptr = bsearch(&address, Memory.SDD1Index, Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); - if (ptr) - in_sdd1_dma = *(uint32 *) ((uint8 *) ptr + 4) + Memory.SDD1Data; - - if (!in_sdd1_dma) - { - // No matching decompressed data found. Must be some new graphics not encountered before. - // Log it if it hasn't been already. - uint8 *p = Memory.SDD1LoggedData; - bool8 found = FALSE; - uint8 SDD1Bank = Memory.FillRAM[0x4804 + ((d->ABank - 0xc0) >> 4)] | 0xf0; - - for (uint32 i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) - { - if (*(p + 0) == d->ABank || - *(p + 1) == (d->AAddress >> 8) && - *(p + 2) == (d->AAddress & 0xff) && - *(p + 3) == (count >> 8) && - *(p + 4) == (count & 0xff) && - *(p + 7) == SDD1Bank) - { - found = TRUE; - break; - } - } - - if (!found && Memory.SDD1LoggedDataCount < MEMMAP_MAX_SDD1_LOGGED_ENTRIES) - { - *(p + 0) = d->ABank; - *(p + 1) = d->AAddress >> 8; - *(p + 2) = d->AAddress & 0xff; - *(p + 3) = count >> 8; - *(p + 4) = count & 0xff; - *(p + 7) = SDD1Bank; - Memory.SDD1LoggedDataCount += 1; - } - } - } - } - - Memory.FillRAM[0x4801] = 0; - } +#ifdef DEBUGGER + if (Settings.TraceDMA) + { + sprintf (String, "DMA[%d]: %s Mode: %d 0x%02X%04X->0x21%02X Bytes: %d (%s) V-Line:%ld -- ABORT WRAM Bank%02X->$2180", + Channel, d->TransferDirection ? "read" : "write", + d->TransferMode, d->ABank, d->AAddress, + d->BAddress, d->TransferBytes, + d->AAddressFixed ? "fixed" : + (d->AAddressDecrement ? "dec" : "inc"), + CPU.V_Counter, d->ABank); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } +#endif + goto update_address; + } + switch (d->BAddress) + { + case 0x18: + case 0x19: + if (IPPU.RenderThisFrame) + FLUSH_REDRAW (); + break; + } + if (Settings.SDD1) + { + if (d->AAddressFixed && Memory.FillRAM [0x4801] > 0) + { + // XXX: Should probably verify that we're DMAing from ROM? And + // somewhere we should make sure we're not running across a mapping + // boundary too. + // Hacky support for pre-decompressed S-DD1 data + inc = !d->AAddressDecrement ? 1 : -1; + uint32 address = (((d->ABank << 16) | d->AAddress) & 0xfffff) << 4; + + address |= Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)]; + +#ifdef SDD1_DECOMP + if(Settings.SDD1Pack) + { + uint8* in_ptr=GetBasePointer(((d->ABank << 16) | d->AAddress)); + if(in_ptr){ + in_ptr+=d->AAddress; + SDD1_decompress(buffer,in_ptr,d->TransferBytes); + } else { + sprintf(String, "S-DD1 DMA from non-block address $%02X:%04X", d->ABank, d->AAddress); + S9xMessage(S9X_WARNING, S9X_DMA_TRACE, String); + } + in_sdd1_dma=buffer; +#ifdef SDD1_VERIFY + void *ptr = bsearch (&address, Memory.SDD1Index, + Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); + if(memcmp(buffer, ptr, d->TransferBytes)) + { + uint8 *p = Memory.SDD1LoggedData; + bool8 found = FALSE; + uint8 SDD1Bank = Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)] | 0xf0; + + for (uint32 i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) + { + if (*p == d->ABank || + *(p + 1) == (d->AAddress >> 8) && + *(p + 2) == (d->AAddress & 0xff) && + *(p + 3) == (count >> 8) && + *(p + 4) == (count & 0xff) && + *(p + 7) == SDD1Bank) + { + found = TRUE; + } + } + if (!found && Memory.SDD1LoggedDataCount < MEMMAP_MAX_SDD1_LOGGED_ENTRIES) + { + int j=0; + while(ptr[j]==buffer[j]) + j++; + + *p = d->ABank; + *(p + 1) = d->AAddress >> 8; + *(p + 2) = d->AAddress & 0xff; + *(p + 3) = j&0xFF; + *(p + 4) = (j>>8)&0xFF; + *(p + 7) = SDD1Bank; + Memory.SDD1LoggedDataCount += 1; + } + } +#endif + } - // SPC7110 + else + { +#endif +#if defined(__linux__) || defined(__WIN32__) || defined(__MACOSX__) + void *ptr = bsearch (&address, Memory.SDD1Index, + Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); + if (ptr) + in_sdd1_dma = *(uint32 *) ((uint8 *) ptr + 4) + Memory.SDD1Data; +#else + uint8 *ptr = Memory.SDD1Index; + + for (uint32 e = 0; e < Memory.SDD1Entries; e++, ptr += 12) + { + if (address == *(uint32 *) ptr) + { + in_sdd1_dma = *(uint32 *) (ptr + 4) + Memory.SDD1Data; + break; + } + } +#endif - uint8 *spc7110_dma = NULL; - bool8 s7_wrap = FALSE; + if (!in_sdd1_dma) + { + // No matching decompressed data found. Must be some new + // graphics not encountered before. Log it if it hasn't been + // already. + uint8 *p = Memory.SDD1LoggedData; + bool8 found = FALSE; + uint8 SDD1Bank = Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)] | 0xf0; + + for (uint32 i = 0; i < Memory.SDD1LoggedDataCount; i++, p += 8) + { + if (*p == d->ABank || + *(p + 1) == (d->AAddress >> 8) && + *(p + 2) == (d->AAddress & 0xff) && + *(p + 3) == (count >> 8) && + *(p + 4) == (count & 0xff) && + *(p + 7) == SDD1Bank) + { + found = TRUE; + break; + } + } + if (!found && Memory.SDD1LoggedDataCount < MEMMAP_MAX_SDD1_LOGGED_ENTRIES) + { + *p = d->ABank; + *(p + 1) = d->AAddress >> 8; + *(p + 2) = d->AAddress & 0xff; + *(p + 3) = count >> 8; + *(p + 4) = count & 0xff; + *(p + 7) = SDD1Bank; + Memory.SDD1LoggedDataCount += 1; + } + } + } +#ifdef SDD1_DECOMP + } +#endif - if (Settings.SPC7110) - { - if (d->AAddress == 0x4800 || d->ABank == 0x50) - { - uint32 i, j; - - i = (s7r.reg4805 | (s7r.reg4806 << 8)); - - #ifdef SPC7110_DEBUG - printf("SPC7110: DMA Transfer of %04X bytes from %02X%02X%02X:%02X, offset of %04X, internal bank of %04X, multiplier %02X\n", - d->TransferBytes, s7r.reg4803, s7r.reg4802, s7r.reg4801, s7r.reg4804, i, s7r.bank50Internal, s7r.AlignBy); - #endif - - i *= s7r.AlignBy; - i += s7r.bank50Internal; - i %= DECOMP_BUFFER_SIZE; - j = 0; - - if ((i + d->TransferBytes) < DECOMP_BUFFER_SIZE) - spc7110_dma = &s7r.bank50[i]; - else - { - spc7110_dma = new uint8[d->TransferBytes]; - j = DECOMP_BUFFER_SIZE - i; - memcpy(spc7110_dma, &s7r.bank50[i], j); - memcpy(&spc7110_dma[j], s7r.bank50, d->TransferBytes - j); - s7_wrap = TRUE; - } - - int32 icount = s7r.reg4809 | (s7r.reg480A << 8); - icount -= d->TransferBytes; - s7r.reg4809 = 0x00ff & icount; - s7r.reg480A = (0xff00 & icount) >> 8; - - s7r.bank50Internal += d->TransferBytes; - s7r.bank50Internal %= DECOMP_BUFFER_SIZE; - - inc = 1; - d->AAddress -= count; - } - } + Memory.FillRAM [0x4801] = 0; + } + if(Settings.SPC7110&&(d->AAddress==0x4800||d->ABank==0x50)) + { + uint32 i,j; + i=(s7r.reg4805|(s7r.reg4806<<8)); +#ifdef SPC7110_DEBUG + printf("DMA Transfer of %04X bytes from %02X%02X%02X:%02X, offset of %04X, internal bank of %04X, multiplier %02X\n",d->TransferBytes,s7r.reg4803,s7r.reg4802,s7r.reg4801, s7r.reg4804,i, s7r.bank50Internal, s7r.AlignBy); +#endif + i*=s7r.AlignBy; + i+=s7r.bank50Internal; + i%=DECOMP_BUFFER_SIZE; + j=0; + if((i+d->TransferBytes)TransferBytes]; + j=DECOMP_BUFFER_SIZE-i; + memcpy(spc7110_dma, &s7r.bank50[i], j); + memcpy(&spc7110_dma[j],s7r.bank50,d->TransferBytes-j); + s7_wrap=true; + } + int icount=s7r.reg4809|(s7r.reg480A<<8); + icount-=d->TransferBytes; + s7r.reg4809=0x00ff&icount; + s7r.reg480A=(0xff00&icount)>>8; + + s7r.bank50Internal+=d->TransferBytes; + s7r.bank50Internal%=DECOMP_BUFFER_SIZE; + inc=1; + d->AAddress-=count; + } + if (d->BAddress == 0x18 && SA1.in_char_dma && (d->ABank & 0xf0) == 0x40) + { + // Perform packed bitmap to PPU character format conversion on the + // data before transmitting it to V-RAM via-DMA. + int num_chars = 1 << ((Memory.FillRAM [0x2231] >> 2) & 7); + int depth = (Memory.FillRAM [0x2231] & 3) == 0 ? 8 : + (Memory.FillRAM [0x2231] & 3) == 1 ? 4 : 2; + + int bytes_per_char = 8 * depth; + int bytes_per_line = depth * num_chars; + int char_line_bytes = bytes_per_char * num_chars; + uint32 addr = (d->AAddress / char_line_bytes) * char_line_bytes; + uint8 *base = GetBasePointer ((d->ABank << 16) + addr); + if(!base){ + sprintf(String, "SA-1 DMA from non-block address $%02X:%04X", d->ABank, addr); + S9xMessage(S9X_WARNING, S9X_DMA_TRACE, String); + base=Memory.ROM; + } + base+=addr; + uint8 *buffer = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000]; + uint8 *p = buffer; + uint32 inc = char_line_bytes - (d->AAddress % char_line_bytes); + uint32 char_count = inc / bytes_per_char; - // SA-1 + in_sa1_dma = TRUE; - bool8 in_sa1_dma = FALSE; + //printf ("%08x,", base); fflush (stdout); + //printf ("depth = %d, count = %d, bytes_per_char = %d, bytes_per_line = %d, num_chars = %d, char_line_bytes = %d\n", + //depth, count, bytes_per_char, bytes_per_line, num_chars, char_line_bytes); + int i; - if (Settings.SA1) - { - if (SA1.in_char_dma && d->BAddress == 0x18 && (d->ABank & 0xf0) == 0x40) - { - // Perform packed bitmap to PPU character format conversion on the data - // before transmitting it to V-RAM via-DMA. - int32 num_chars = 1 << ((Memory.FillRAM[0x2231] >> 2) & 7); - int32 depth = (Memory.FillRAM[0x2231] & 3) == 0 ? 8 : (Memory.FillRAM[0x2231] & 3) == 1 ? 4 : 2; - int32 bytes_per_char = 8 * depth; - int32 bytes_per_line = depth * num_chars; - int32 char_line_bytes = bytes_per_char * num_chars; - uint32 addr = (d->AAddress / char_line_bytes) * char_line_bytes; - - uint8 *base = GetBasePointer((d->ABank << 16) + addr); - if (!base) - { - sprintf(String, "SA-1: DMA from non-block address $%02X:%04X", d->ABank, addr); - S9xMessage(S9X_WARNING, S9X_DMA_TRACE, String); - base = Memory.ROM; - } - - base += addr; - - uint8 *buffer = &Memory.ROM[CMemory::MAX_ROM_SIZE - 0x10000]; - uint8 *p = buffer; - uint32 inc_sa1 = char_line_bytes - (d->AAddress % char_line_bytes); - uint32 char_count = inc_sa1 / bytes_per_char; - - in_sa1_dma = TRUE; - - #if 0 - printf("SA-1 DMA: %08x,", base); - printf("depth = %d, count = %d, bytes_per_char = %d, bytes_per_line = %d, num_chars = %d, char_line_bytes = %d\n", - depth, count, bytes_per_char, bytes_per_line, num_chars, char_line_bytes); - #endif - - switch (depth) - { - case 2: - for (int32 i = 0; i < count; i += inc_sa1, base += char_line_bytes, inc_sa1 = char_line_bytes, char_count = num_chars) - { - uint8 *line = base + (num_chars - char_count) * 2; - for (uint32 j = 0; j < char_count && p - buffer < count; j++, line += 2) - { - uint8 *q = line; - for (int32 l = 0; l < 8; l++, q += bytes_per_line) - { - for (int32 b = 0; b < 2; b++) - { - uint8 r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 2) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 3) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 6) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 7) & 1); - } - - p += 2; - } - } - } - - break; - - case 4: - for (int32 i = 0; i < count; i += inc_sa1, base += char_line_bytes, inc_sa1 = char_line_bytes, char_count = num_chars) - { - uint8 *line = base + (num_chars - char_count) * 4; - for (uint32 j = 0; j < char_count && p - buffer < count; j++, line += 4) - { - uint8 *q = line; - for (int32 l = 0; l < 8; l++, q += bytes_per_line) - { - for (int32 b = 0; b < 4; b++) - { - uint8 r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); - *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 6) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 7) & 1); - } - - p += 2; - } - - p += 32 - 16; - } - } - - break; - - case 8: - for (int32 i = 0; i < count; i += inc_sa1, base += char_line_bytes, inc_sa1 = char_line_bytes, char_count = num_chars) - { - uint8 *line = base + (num_chars - char_count) * 8; - for (uint32 j = 0; j < char_count && p - buffer < count; j++, line += 8) - { - uint8 *q = line; - for (int32 l = 0; l < 8; l++, q += bytes_per_line) - { - for (int32 b = 0; b < 8; b++) - { - uint8 r = *(q + b); - *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); - *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); - *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); - *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); - *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1); - *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1); - *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1); - *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1); - } - - p += 2; - } - - p += 64 - 16; - } - - break; - } - } - } - } + switch (depth) + { + case 2: + for (i = 0; i < count; i += inc, base += char_line_bytes, + inc = char_line_bytes, char_count = num_chars) + { + uint8 *line = base + (num_chars - char_count) * 2; + for (uint32 j = 0; j < char_count && p - buffer < count; + j++, line += 2) + { + uint8 *q = line; + for (int l = 0; l < 8; l++, q += bytes_per_line) + { + for (int b = 0; b < 2; b++) + { + uint8 r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 2) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 3) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 6) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 7) & 1); + } + p += 2; + } + } + } + break; + case 4: + for (i = 0; i < count; i += inc, base += char_line_bytes, + inc = char_line_bytes, char_count = num_chars) + { + uint8 *line = base + (num_chars - char_count) * 4; + for (uint32 j = 0; j < char_count && p - buffer < count; + j++, line += 4) + { + uint8 *q = line; + for (int l = 0; l < 8; l++, q += bytes_per_line) + { + for (int b = 0; b < 4; b++) + { + uint8 r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); + *(p + 0) = (*(p + 0) << 1) | ((r >> 4) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 5) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 6) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 7) & 1); + } + p += 2; + } + p += 32 - 16; + } + } + break; + case 8: + for (i = 0; i < count; i += inc, base += char_line_bytes, + inc = char_line_bytes, char_count = num_chars) + { + uint8 *line = base + (num_chars - char_count) * 8; + for (uint32 j = 0; j < char_count && p - buffer < count; + j++, line += 8) + { + uint8 *q = line; + for (int l = 0; l < 8; l++, q += bytes_per_line) + { + for (int b = 0; b < 8; b++) + { + uint8 r = *(q + b); + *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1); + *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1); + *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1); + *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1); + *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1); + *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1); + *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1); + *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1); + } + p += 2; + } + p += 64 - 16; + } + } + break; + } + } #ifdef DEBUGGER - if (Settings.TraceDMA) - { - sprintf(String, "DMA[%d]: %s Mode:%d 0x%02X%04X->0x21%02X Bytes:%d (%s) V:%03d", - Channel, d->ReverseTransfer ? "PPU->CPU" : "CPU->PPU", d->TransferMode, d->ABank, d->AAddress, d->BAddress, - d->TransferBytes, d->AAddressFixed ? "fixed" : (d->AAddressDecrement ? "dec" : "inc"), CPU.V_Counter); - - if (d->BAddress == 0x18 || d->BAddress == 0x19 || d->BAddress == 0x39 || d->BAddress == 0x3a) - sprintf(String, "%s VRAM: %04X (%d,%d) %s", String, - PPU.VMA.Address, PPU.VMA.Increment, PPU.VMA.FullGraphicCount, PPU.VMA.High ? "word" : "byte"); - else - if (d->BAddress == 0x22 || d->BAddress == 0x3b) - sprintf(String, "%s CGRAM: %02X (%x)", String, PPU.CGADD, PPU.CGFLIP); - else - if (d->BAddress == 0x04 || d->BAddress == 0x38) - sprintf(String, "%s OBJADDR: %04X", String, PPU.OAMAddr); - - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - } + if (Settings.TraceDMA) + { + sprintf (String, "DMA[%d]: %s Mode: %d 0x%02X%04X->0x21%02X Bytes: %d (%s) V-Line:%ld", + Channel, d->TransferDirection ? "read" : "write", + d->TransferMode, d->ABank, d->AAddress, + d->BAddress, d->TransferBytes, + d->AAddressFixed ? "fixed" : + (d->AAddressDecrement ? "dec" : "inc"), + CPU.V_Counter); + if (d->BAddress == 0x18 || d->BAddress == 0x19 || d->BAddress == 0x39 || d->BAddress == 0x3a) + sprintf (String, "%s VRAM: %04X (%d,%d) %s", String, + PPU.VMA.Address, + PPU.VMA.Increment, PPU.VMA.FullGraphicCount, + PPU.VMA.High ? "word" : "byte"); + + else + if (d->BAddress == 0x22 || d->BAddress == 0x3b) + + sprintf (String, "%s CGRAM: %02X (%x)", String, PPU.CGADD, + PPU.CGFLIP); + else + if (d->BAddress == 0x04 || d->BAddress == 0x38) + sprintf (String, "%s OBJADDR: %04X", String, PPU.OAMAddr); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } #endif - // Do Transfer + if (!d->TransferDirection) + { + //reflects extra cycle used by DMA + CPU.Cycles += SLOW_ONE_CYCLE * (count+1); + S9xTrySyncAPUInDMA(); + + uint8 *base = GetBasePointer((d->ABank << 16) + d->AAddress); + uint16 p = d->AAddress; + int rem = count; + int b = 0; + count = d->AAddressFixed ? rem : (d->AAddressDecrement ? ((p&MEMMAP_MASK)+1) : (MEMMAP_BLOCK_SIZE-(p&MEMMAP_MASK))); + bool8 inWRAM_DMA = FALSE; + + if (in_sa1_dma) + { + base = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000]; + p = 0; + count = rem; + } - uint8 Work; + if (in_sdd1_dma) + { + base = in_sdd1_dma; + p = 0; + count = rem; + } - // 8 cycles per channel - CPU.Cycles += SLOW_ONE_CYCLE; + if (spc7110_dma) + { + base = spc7110_dma; + p = 0; + count = rem; + } + + inWRAM_DMA = ((!in_sa1_dma && !in_sdd1_dma && !spc7110_dma) && + (d->ABank == 0x7e || d->ABank == 0x7f || (!(d->ABank & 0x40) && d->AAddress < 0x2000))); + + while(1){ + if(count>rem) count=rem; + rem -= count; + if (inc > 0) + d->AAddress += count; + else if (inc < 0) + d->AAddress -= count; + //CPU.InWRAM_DMA = (base>=Memory.RAM && baseTransferMode == 0 || d->TransferMode == 2 || d->TransferMode == 6) + { + do + { + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } + else if (d->TransferMode == 1 || d->TransferMode == 5) + { + // This is a variation on Duff's Device. It is legal C/C++, + // see http://www.lysator.liu.se/c/duffs-device.html + switch(b){ + default: + while (count > 1) + { + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + count--; - if (!d->ReverseTransfer) - { - // CPU -> PPU - int32 b = 0; - uint16 p = d->AAddress; - uint8 *base = GetBasePointer((d->ABank << 16) + d->AAddress); - bool8 inWRAM_DMA; - - int32 rem = count; - // Transfer per block if d->AAdressFixed is FALSE - count = d->AAddressFixed ? rem : (d->AAddressDecrement ? ((p & MEMMAP_MASK) + 1) : (MEMMAP_BLOCK_SIZE - (p & MEMMAP_MASK))); - - // Settings for custom chip DMA - if (in_sa1_dma) - { - base = &Memory.ROM[CMemory::MAX_ROM_SIZE - 0x10000]; - p = 0; - count = rem; - } - else - if (in_sdd1_dma) - { - base = in_sdd1_dma; - p = 0; - count = rem; - } - else - if (spc7110_dma) - { - base = spc7110_dma; - p = 0; - count = rem; - } + case 1: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + CHECK_SOUND(); + count --; + } + } + if (count == 1) + { + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + b = 1; + } else { + b = 0; + } + } + else if (d->TransferMode == 3 || d->TransferMode == 7) + { + switch(b){ + default: + do + { + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 1; + break; + } - inWRAM_DMA = ((!in_sa1_dma && !in_sdd1_dma && !spc7110_dma) && - (d->ABank == 0x7e || d->ABank == 0x7f || (!(d->ABank & 0x40) && d->AAddress < 0x2000))); - - // 8 cycles per byte - #define UPDATE_COUNTERS \ - d->TransferBytes--; \ - d->AAddress += inc; \ - p += inc; \ - if (!addCyclesInDMA(Channel)) \ - { \ - CPU.InDMA = FALSE; \ - CPU.InDMAorHDMA = FALSE; \ - CPU.InWRAMDMAorHDMA = FALSE; \ - return FALSE; \ - } - - while (1) - { - if (count > rem) - count = rem; - rem -= count; - - CPU.InWRAMDMAorHDMA = inWRAM_DMA; - - if (!base) - { - // DMA SLOW PATH - if (d->TransferMode == 0 || d->TransferMode == 2 || d->TransferMode == 6) - { - do - { - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - else - if (d->TransferMode == 1 || d->TransferMode == 5) - { - // This is a variation on Duff's Device. It is legal C/C++. - switch (b) - { - default: - while (count > 1) - { - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - count--; - - case 1: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - count--; - } - } - - if (count == 1) - { - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - b = 1; - } - else - b = 0; - } - else - if (d->TransferMode == 3 || d->TransferMode == 7) - { - switch (b) - { - default: - do - { - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 1; - break; - } - - case 1: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 2; - break; - } - - case 2: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 3; - break; - } - - case 3: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - if (--count <= 0) - { - b = 0; - break; - } - } while (1); - } - } - else - if (d->TransferMode == 4) - { - switch (b) - { - default: - do - { - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 1; - break; - } - - case 1: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 2; - break; - } - - case 2: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2102 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 3; - break; - } - - case 3: - Work = S9xGetByte((d->ABank << 16) + p); - S9xSetPPU(Work, 0x2103 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - if (--count <= 0) - { - b = 0; - break; - } - } while (1); - } - } - #ifdef DEBUGGER - else - { - sprintf(String, "Unknown DMA transfer mode: %d on channel %d\n", d->TransferMode, Channel); - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - } - #endif - } - else - { - // DMA FAST PATH - if (d->TransferMode == 0 || d->TransferMode == 2 || d->TransferMode == 6) - { - switch (d->BAddress) - { - case 0x04: // OAMDATA - do - { - Work = *(base + p); - REGISTER_2104(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - - break; - - case 0x18: // VMDATAL - #ifndef CORRECT_VRAM_READS - IPPU.FirstVRAMRead = TRUE; - #endif - if (!PPU.VMA.FullGraphicCount) - { - do - { - Work = *(base + p); - REGISTER_2118_linear(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - else - { - do - { - Work = *(base + p); - REGISTER_2118_tile(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - - break; - - case 0x19: // VMDATAH - #ifndef CORRECT_VRAM_READS - IPPU.FirstVRAMRead = TRUE; - #endif - if (!PPU.VMA.FullGraphicCount) - { - do - { - Work = *(base + p); - REGISTER_2119_linear(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - else - { - do - { - Work = *(base + p); - REGISTER_2119_tile(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - - break; - - case 0x22: // CGDATA - do - { - Work = *(base + p); - REGISTER_2122(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - - break; - - case 0x80: // WMDATA - if (!CPU.InWRAMDMAorHDMA) - { - do - { - Work = *(base + p); - REGISTER_2180(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - else - { - do - { - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - } - - break; - - default: - do - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - } while (--count > 0); - - break; - } - } - else - if (d->TransferMode == 1 || d->TransferMode == 5) - { - if (d->BAddress == 0x18) - { - // VMDATAL - #ifndef CORRECT_VRAM_READS - IPPU.FirstVRAMRead = TRUE; - #endif - if (!PPU.VMA.FullGraphicCount) - { - switch (b) - { - default: - while (count > 1) - { - Work = *(base + p); - REGISTER_2118_linear(Work); - UPDATE_COUNTERS; - count--; - - case 1: - Work = *(base + p); - REGISTER_2119_linear(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - count--; - } - } - - if (count == 1) - { - Work = *(base + p); - REGISTER_2118_linear(Work); - UPDATE_COUNTERS; - b = 1; - } - else - b = 0; - } - else - { - switch (b) - { - default: - while (count > 1) - { - Work = *(base + p); - REGISTER_2118_tile(Work); - UPDATE_COUNTERS; - count--; - - case 1: - Work = *(base + p); - REGISTER_2119_tile(Work); - UPDATE_COUNTERS; - CHECK_SOUND(); - count--; - } - } - - if (count == 1) - { - Work = *(base + p); - REGISTER_2118_tile(Work); - UPDATE_COUNTERS; - b = 1; - } - else - b = 0; - } - } - else - { - // DMA mode 1 general case - switch (b) - { - default: - while (count > 1) - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - count--; - - case 1: - Work = *(base + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - count--; - } - } - - if (count == 1) - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - b = 1; - } - else - b = 0; - } - } - else - if (d->TransferMode == 3 || d->TransferMode == 7) - { - switch (b) - { - default: - do - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 1; - break; - } - - case 1: - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 2; - break; - } - - case 2: - Work = *(base + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 3; - break; - } - - case 3: - Work = *(base + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - if (--count <= 0) - { - b = 0; - break; - } - } while (1); - } - } - else - if (d->TransferMode == 4) - { - switch (b) - { - default: - do - { - Work = *(base + p); - S9xSetPPU(Work, 0x2100 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 1; - break; - } - - case 1: - Work = *(base + p); - S9xSetPPU(Work, 0x2101 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 2; - break; - } - - case 2: - Work = *(base + p); - S9xSetPPU(Work, 0x2102 + d->BAddress); - UPDATE_COUNTERS; - if (--count <= 0) - { - b = 3; - break; - } - - case 3: - Work = *(base + p); - S9xSetPPU(Work, 0x2103 + d->BAddress); - UPDATE_COUNTERS; - CHECK_SOUND(); - if (--count <= 0) - { - b = 0; - break; - } - } while (1); - } - } - #ifdef DEBUGGER - else - { - sprintf(String, "Unknown DMA transfer mode: %d on channel %d\n", d->TransferMode, Channel); - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - } - #endif - } - - if (rem <= 0) - break; - - base = GetBasePointer((d->ABank << 16) + d->AAddress); - count = MEMMAP_BLOCK_SIZE; - inWRAM_DMA = ((!in_sa1_dma && !in_sdd1_dma && !spc7110_dma) && - (d->ABank == 0x7e || d->ABank == 0x7f || (!(d->ABank & 0x40) && d->AAddress < 0x2000))); - } + case 1: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 2; + break; + } - #undef UPDATE_COUNTERS - } + case 2: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 3; + break; + } + + case 3: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + CHECK_SOUND(); + if(--count<=0){ + b = 0; + break; + } + } while (1); + } + } + else if (d->TransferMode == 4) + { + switch(b){ + default: + do + { + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 1; + break; + } + + case 1: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 2; + break; + } + + case 2: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2102 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 3; + break; + } + + case 3: + Work = S9xGetByte((d->ABank << 16) + p); + S9xSetPPU (Work, 0x2103 + d->BAddress); + p += inc; + CHECK_SOUND(); + if (--count <= 0){ + b = 0; + break; + } + } while (1); + } + } + else + { +#ifdef DEBUGGER + // if (Settings.TraceDMA) + { + sprintf (String, "Unknown DMA transfer mode: %d on channel %d\n", + d->TransferMode, Channel); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } +#endif + } + } else { + // DMA FAST PATH + if (d->TransferMode == 0 || d->TransferMode == 2 || d->TransferMode == 6) + { + switch (d->BAddress) + { + case 0x04: + do + { + Work = *(base + p); + REGISTER_2104(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + break; + case 0x18: +#ifndef CORRECT_VRAM_READS + IPPU.FirstVRAMRead = TRUE; +#endif + if (!PPU.VMA.FullGraphicCount) + { + do + { + Work = *(base + p); + REGISTER_2118_linear(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } + else + { + do + { + Work = *(base + p); + REGISTER_2118_tile(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } + break; + case 0x19: +#ifndef CORRECT_VRAM_READS + IPPU.FirstVRAMRead = TRUE; +#endif + if (!PPU.VMA.FullGraphicCount) + { + do + { + Work = *(base + p); + REGISTER_2119_linear(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } + else + { + do + { + Work = *(base + p); + REGISTER_2119_tile(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } + break; + case 0x22: + do + { + Work = *(base + p); + REGISTER_2122(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + break; + case 0x80: + if(!CPU.InWRAM_DMA){ + do + { + Work = *(base + p); + REGISTER_2180(Work); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + } else { + count=0; + } + break; + default: + do + { + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + CHECK_SOUND(); + } while (--count > 0); + break; + } + } + else if (d->TransferMode == 1 || d->TransferMode == 5) + { + if (d->BAddress == 0x18) + { + // Write to V-RAM +#ifndef CORRECT_VRAM_READS + IPPU.FirstVRAMRead = TRUE; +#endif + if (!PPU.VMA.FullGraphicCount) + { + switch(b){ + default: + while (count > 1) + { + Work = *(base + p); + REGISTER_2118_linear(Work); + p += inc; + count--; + + case 1: + Work = *(base + p); + REGISTER_2119_linear(Work); + p += inc; + CHECK_SOUND(); + count--; + } + } + if (count == 1) + { + Work = *(base + p); + REGISTER_2118_linear(Work); + p += inc; + b = 1; + } else { + b = 0; + } + } + else + { + switch(b){ + default: + while (count > 1) + { + Work = *(base + p); + REGISTER_2118_tile(Work); + p += inc; + count--; + + case 1: + Work = *(base + p); + REGISTER_2119_tile(Work); + p += inc; + CHECK_SOUND(); + count--; + } + } + if (count == 1) + { + Work = *(base + p); + REGISTER_2118_tile(Work); + p += inc; + b = 1; + } else { + b = 0; + } + } + } + else + { + // DMA mode 1 general case + switch(b){ + default: + while (count > 1) + { + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + count--; + + case 1: + Work = *(base + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + CHECK_SOUND(); + count --; + } + } + if (count == 1) + { + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + b = 1; + } else { + b = 0; + } + } + } + else if (d->TransferMode == 3 || d->TransferMode == 7) + { + switch(b){ + default: + do + { + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 1; + break; + } + + case 1: + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 2; + break; + } + + case 2: + Work = *(base + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 3; + break; + } + + case 3: + Work = *(base + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + CHECK_SOUND(); + if(--count<=0){ + b = 0; + break; + } + } while (1); + } + } + else if (d->TransferMode == 4) + { + switch(b){ + default: + do + { + Work = *(base + p); + S9xSetPPU (Work, 0x2100 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 1; + break; + } + + case 1: + Work = *(base + p); + S9xSetPPU (Work, 0x2101 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 2; + break; + } + + case 2: + Work = *(base + p); + S9xSetPPU (Work, 0x2102 + d->BAddress); + p += inc; + if (--count <= 0){ + b = 3; + break; + } + + case 3: + Work = *(base + p); + S9xSetPPU (Work, 0x2103 + d->BAddress); + p += inc; + CHECK_SOUND(); + if (--count <= 0){ + b = 0; + break; + } + } while (1); + } + } + else + { +#ifdef DEBUGGER + // if (Settings.TraceDMA) + { + sprintf (String, "Unknown DMA transfer mode: %d on channel %d\n", + d->TransferMode, Channel); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } +#endif + } + } + if(rem<=0) break; + base = GetBasePointer((d->ABank << 16) + d->AAddress); + count=MEMMAP_BLOCK_SIZE; + inWRAM_DMA = ((!in_sa1_dma && !in_sdd1_dma && !spc7110_dma) && + (d->ABank == 0x7e || d->ABank == 0x7f || (!(d->ABank & 0x40) && d->AAddress < 0x2000))); + } + } else { - // PPU -> CPU - - // 8 cycles per byte - #define UPDATE_COUNTERS \ - d->TransferBytes--; \ - d->AAddress += inc; \ - if (!addCyclesInDMA(Channel)) \ - { \ - CPU.InDMA = FALSE; \ - CPU.InDMAorHDMA = FALSE; \ - CPU.InWRAMDMAorHDMA = FALSE; \ - return FALSE; \ - } - - if (d->BAddress > 0x80 - 4 && d->BAddress <= 0x83 && !(d->ABank & 0x40)) - { - // REVERSE-DMA REALLY-SLOW PATH - do - { - switch (d->TransferMode) - { - case 0: - case 2: - case 6: - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 1: - case 5: - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 3: - case 7: - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 4: - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2102 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - CPU.InWRAMDMAorHDMA = (d->AAddress < 0x2000); - Work = S9xGetPPU(0x2103 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - default: - #ifdef DEBUGGER - sprintf(String, "Unknown DMA transfer mode: %d on channel %d\n", d->TransferMode, Channel); - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - #endif - while (count) - { - UPDATE_COUNTERS; - count--; - } - - break; - } - - CHECK_SOUND(); - } while (count); - } - else - { - // REVERSE-DMA FASTER PATH - CPU.InWRAMDMAorHDMA = (d->ABank == 0x7e || d->ABank == 0x7f); - do - { - switch (d->TransferMode) - { - case 0: - case 2: - case 6: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 1: - case 5: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 3: - case 7: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - case 4: - Work = S9xGetPPU(0x2100 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2101 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2102 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - if (!--count) - break; - - Work = S9xGetPPU(0x2103 + d->BAddress); - S9xSetByte(Work, (d->ABank << 16) + d->AAddress); - UPDATE_COUNTERS; - count--; - - break; - - default: - #ifdef DEBUGGER - sprintf(String, "Unknown DMA transfer mode: %d on channel %d\n", d->TransferMode, Channel); - S9xMessage(S9X_TRACE, S9X_DMA_TRACE, String); - #endif - while (count) - { - UPDATE_COUNTERS; - count--; - } - - break; - } - - CHECK_SOUND(); - } while (count); - } - } + if(d->BAddress>0x80-4 && d->BAddress<=0x83 && !(d->ABank&0x40)){ + // REVERSE-DMA REALLY-SLOW PATH + do + { + switch (d->TransferMode) + { + case 0: + case 2: + case 6: + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + --count; + break; + + case 1: + case 5: + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + case 3: + case 7: + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; - // If the CPU is halted (i.e. for DMA) while /NMI goes low, the NMI will trigger - // after the DMA completes (even if /NMI goes high again before the DMA - // completes). In this case, there is a 24-30 cycle delay between the end of DMA - // and the NMI handler, time enough for an instruction or two. - if ((CPU.Flags & NMI_FLAG) && (Timings.NMITriggerPos != 0xffff)) + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + case 4: + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2102 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + CPU.InWRAM_DMA = (d->AAddress<0x2000); + Work = S9xGetPPU (0x2103 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + default: +#ifdef DEBUGGER + if (1) //Settings.TraceDMA) + { + sprintf (String, "Unknown DMA transfer mode: %d on channel %d\n", + d->TransferMode, Channel); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } +#endif + count = 0; + break; + } + CHECK_SOUND(); + } while (count); + } else { + // REVERSE-DMA FASTER PATH + CPU.InWRAM_DMA = (d->ABank==0x7e || d->ABank==0x7f); + do + { + switch (d->TransferMode) + { + case 0: + case 2: + case 6: + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + --count; + break; + + case 1: + case 5: + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + case 3: + case 7: + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + case 4: + Work = S9xGetPPU (0x2100 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2101 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2102 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + if (!--count) + break; + + Work = S9xGetPPU (0x2103 + d->BAddress); + S9xSetByte (Work, (d->ABank << 16) + d->AAddress); + d->AAddress += inc; + count--; + break; + + default: +#ifdef DEBUGGER + if (1) //Settings.TraceDMA) + { + sprintf (String, "Unknown DMA transfer mode: %d on channel %d\n", + d->TransferMode, Channel); + S9xMessage (S9X_TRACE, S9X_DMA_TRACE, String); + } +#endif + count = 0; + break; + } + CHECK_SOUND(); + } while(count); + } + } + + while (CPU.Cycles >= CPU.NextEvent) + S9xDoHEventProcessing (); + if ((CPU.Cycles >= Timings.WRAMRefreshPos) && (CPU.Cycles < (Timings.WRAMRefreshPos + SNES_WRAM_REFRESH_CYCLES))) { - Timings.NMITriggerPos = CPU.Cycles + 30; - if (Timings.NMITriggerPos >= Timings.H_Max) - Timings.NMITriggerPos -= Timings.H_Max; + int32 mc = Timings.WRAMRefreshPos + SNES_WRAM_REFRESH_CYCLES - CPU.Cycles; + S9xCheckMissingHTimerPositionRange(CPU.Cycles, mc); + CPU.Cycles += mc; } - - // Release the memory used in SPC7110 DMA - if (Settings.SPC7110) + + S9xTrySyncAPUInDMA(); + + if(Settings.SPC7110&&spc7110_dma) { - if (spc7110_dma && s7_wrap) + if(spc7110_dma&&s7_wrap) delete [] spc7110_dma; } -#if 1 - // sanity check - if (d->TransferBytes != 0) - fprintf(stderr,"DMA[%d] TransferBytes not 0! $21%02x Reverse:%d %04x\n", Channel, d->BAddress, d->ReverseTransfer, d->TransferBytes); -#endif - - CPU.InDMA = FALSE; - CPU.InDMAorHDMA = FALSE; - CPU.InWRAMDMAorHDMA = FALSE; +update_address: + d->TransferBytes = 0; - return TRUE; + CPU.InDMA = CPU.InWRAM_DMA = FALSE; } static inline bool8 HDMAReadLineCount(int d){ @@ -1403,12 +1280,7 @@ static inline bool8 HDMAReadLineCount(int d){ DMA[d].Repeat = FALSE; DMA[d].LineCount = 128; if(DMA[d].HDMAIndirectAddressing){ - if(IPPU.HDMA&(0xfe<HDMAIndirectAddressing) { ShiftedIBank = (p->IndirectBank << 16); IAddr = p->IndirectAddress; @@ -1521,13 +1390,13 @@ uint8 S9xDoHDMA (uint8 byte) } #ifdef DEBUGGER - if (Settings.TraceSoundDSP && p->DoTransfer && + if (Settings.TraceSoundDSP && p->DoTransfer && p->BAddress >= 0x40 && p->BAddress <= 0x43) S9xTraceSoundDSP ("Spooling data!!!\n"); if (Settings.TraceHDMA && p->DoTransfer) { sprintf (String, "H-DMA[%d] %s (%d) 0x%06X->0x21%02X %s, Count: %3d, Rep: %s, V-LINE: %3ld %02X%04X", - p-DMA, p->ReverseTransfer? "read" : "write", + p-DMA, p->TransferDirection? "read" : "write", p->TransferMode, ShiftedIBank+IAddr, p->BAddress, p->HDMAIndirectAddressing ? "ind" : "abs", p->LineCount, @@ -1537,12 +1406,12 @@ uint8 S9xDoHDMA (uint8 byte) } #endif - if (!p->ReverseTransfer) { + if (!p->TransferDirection) { if((IAddr&MEMMAP_MASK)+HDMA_ModeByteCounts[p->TransferMode]>=MEMMAP_BLOCK_SIZE){ // HDMA REALLY-SLOW PATH HDMAMemPointers[d]=NULL; #define DOBYTE(Addr, RegOff) \ - CPU.InWRAMDMAorHDMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && ((uint16)(Addr))<0x2000)); \ + CPU.InWRAM_DMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && ((uint16)(Addr))<0x2000)); \ S9xSetPPU (S9xGetByte(ShiftedIBank + ((uint16)(Addr))), 0x2100 + p->BAddress + RegOff); switch (p->TransferMode) { case 0: @@ -1585,7 +1454,7 @@ uint8 S9xDoHDMA (uint8 byte) } #undef DOBYTE } else { - CPU.InWRAMDMAorHDMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && IAddr<0x2000)); + CPU.InWRAM_DMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && IAddr<0x2000)); if(!HDMAMemPointers[d]){ // HDMA SLOW PATH uint32 Addr = ShiftedIBank + IAddr; @@ -1680,7 +1549,7 @@ uint8 S9xDoHDMA (uint8 byte) // bother with faster paths. HDMAMemPointers[d]=NULL; #define DOBYTE(Addr, RegOff) \ - CPU.InWRAMDMAorHDMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && ((uint16)(Addr))<0x2000)); \ + CPU.InWRAM_DMA = (ShiftedIBank==0x7e0000 || ShiftedIBank==0x7f0000 || (!(ShiftedIBank&0x400000) && ((uint16)(Addr))<0x2000)); \ S9xSetByte (S9xGetPPU(0x2100 + p->BAddress + RegOff), ShiftedIBank + ((uint16)(Addr))); switch (p->TransferMode) { case 0: @@ -1741,25 +1610,22 @@ uint8 S9xDoHDMA (uint8 byte) } else { CPU.Cycles += SLOW_ONE_CYCLE; } + + S9xTrySyncAPUInDMA(); } } - - S9xAPUExecute(); - - CPU.InHDMA = FALSE; - CPU.InDMAorHDMA = CPU.InDMA; - CPU.InWRAMDMAorHDMA = temp; - + CPU.InDMA=CPU.InWRAM_DMA=FALSE; + return (byte); } void S9xResetDMA () { int d; for (d = 0; d < 8; d++) { - DMA[d].ReverseTransfer = TRUE; - DMA[d].HDMAIndirectAddressing = TRUE; + DMA[d].TransferDirection = FALSE; + DMA[d].HDMAIndirectAddressing = FALSE; DMA[d].AAddressFixed = TRUE; - DMA[d].AAddressDecrement = TRUE; + DMA[d].AAddressDecrement = FALSE; DMA[d].TransferMode = 7; DMA[d].BAddress = 0xff; DMA[d].AAddress = 0xffff; @@ -1771,6 +1637,5 @@ void S9xResetDMA () { DMA[d].LineCount = 0x7f; DMA[d].UnknownByte = 0xff; DMA[d].DoTransfer = FALSE; - DMA[d].UnusedBit43x0 = 1; } } diff --git a/source/snes9x/dma.h b/source/snes9x/dma.h index 38c56661..147a5ad5 100644 --- a/source/snes9x/dma.h +++ b/source/snes9x/dma.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _DMA_H_ #define _DMA_H_ @@ -168,7 +149,7 @@ START_EXTERN_C void S9xResetDMA (); uint8 S9xDoHDMA (uint8); void S9xStartHDMA (); -bool8 S9xDoDMA (uint8); +void S9xDoDMA (uint8); END_EXTERN_C #endif diff --git a/source/snes9x/dsp1.cpp b/source/snes9x/dsp1.cpp index 2ce54c93..8a840f04 100644 --- a/source/snes9x/dsp1.cpp +++ b/source/snes9x/dsp1.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,14 +141,11 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "snes9x.h" #include "dsp1.h" #include "missing.h" #include "memmap.h" #include -#include #include "dsp1emu.c.inc" #include "dsp2emu.c.inc" @@ -178,7 +158,7 @@ uint8 (*GetDSP)(uint16)=&DSP1GetByte; void S9xInitDSP1 () { static bool8 init = FALSE; - + if (!init) { InitDSP (); @@ -189,14 +169,14 @@ void S9xInitDSP1 () void S9xResetDSP1 () { S9xInitDSP1 (); - + DSP1.waiting4command = TRUE; DSP1.in_count = 0; DSP1.out_count = 0; DSP1.in_index = 0; DSP1.out_index = 0; DSP1.first_parameter = TRUE; - + DSP4.waiting4command = TRUE; //printf("DSP-4 Reset\n"); } @@ -204,7 +184,7 @@ void S9xResetDSP1 () uint8 S9xGetDSP (uint16 address) { uint8 t; - + #ifdef DEBUGGER if (Settings.TraceDSP) { @@ -212,7 +192,7 @@ uint8 S9xGetDSP (uint16 address) S9xMessage (S9X_TRACE, S9X_TRACE_DSP1, String); } #endif - + t=(*GetDSP)(address); //DSP1GetByte(address); return (t); @@ -234,14 +214,14 @@ void S9xSetDSP (uint8 byte, uint16 address) void DSP1SetByte(uint8 byte, uint16 address) { - if (address < DSP1.boundary) + if( (address & 0xf000) == 0x6000 || (address & 0x7fff) < 0x4000 ) { // if ((address & 1) == 0) // { if((DSP1.command==0x0A||DSP1.command==0x1A)&&DSP1.out_count!=0) { DSP1.out_count--; - DSP1.out_index++; + DSP1.out_index++; return; } else if (DSP1.waiting4command) @@ -275,7 +255,7 @@ void DSP1SetByte(uint8 byte, uint16 address) case 0x0a: DSP1.in_count = 1; break; case 0x3a: case 0x2a: - case 0x1a: + case 0x1a: DSP1. command =0x1a; DSP1.in_count = 1; break; case 0x16: @@ -338,7 +318,7 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.first_parameter = FALSE; DSP1.in_index++; } - + if (DSP1.waiting4command || (DSP1.first_parameter && byte == 0x80)) { @@ -369,9 +349,9 @@ void DSP1SetByte(uint8 byte, uint16 address) case 0x00: // Multiple Op00Multiplicand = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op00Multiplier = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); - + DSPOp00 (); - + DSP1.out_count = 2; DSP1.output [0] = Op00Result&0xFF; DSP1.output [1] = (Op00Result>>8)&0xFF; @@ -380,111 +360,111 @@ void DSP1SetByte(uint8 byte, uint16 address) case 0x20: // Multiple Op20Multiplicand = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op20Multiplier = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); - + DSPOp20 (); - + DSP1.out_count = 2; DSP1.output [0] = Op20Result&0xFF; DSP1.output [1] = (Op20Result>>8)&0xFF; break; - + case 0x30: case 0x10: // Inverse Op10Coefficient = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op10Exponent = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); - + DSPOp10 (); - + DSP1.out_count = 4; DSP1.output [0] = (uint8) (((int16) Op10CoefficientR)&0xFF); DSP1.output [1] = (uint8) ((((int16) Op10CoefficientR)>>8)&0xFF); DSP1.output [2] = (uint8) (((int16) Op10ExponentR)&0xff); DSP1.output [3] = (uint8) ((((int16) Op10ExponentR)>>8)&0xff); break; - + case 0x24: case 0x04: // Sin and Cos of angle Op04Angle = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op04Radius = (uint16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); - + DSPOp04 (); - + DSP1.out_count = 4; DSP1.output [0] = (uint8) (Op04Sin&0xFF); DSP1.output [1] = (uint8) ((Op04Sin>>8)&0xFF); DSP1.output [2] = (uint8) (Op04Cos&0xFF); DSP1.output [3] = (uint8) ((Op04Cos>>8)&0xFF); break; - + case 0x08: // Radius Op08X = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op08Y = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op08Z = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp08 (); - + DSP1.out_count = 4; - DSP1.output [0] = (uint8) (((int16) Op08Ll)&0xFF); - DSP1.output [1] = (uint8) ((((int16) Op08Ll)>>8)&0xFF); + DSP1.output [0] = (uint8) (((int16) Op08Ll)&0xFF); + DSP1.output [1] = (uint8) ((((int16) Op08Ll)>>8)&0xFF); DSP1.output [2] = (uint8) (((int16) Op08Lh)&0xFF); DSP1.output [3] = (uint8) ((((int16) Op08Lh)>>8)&0xFF); break; - + case 0x18: // Range - + Op18X = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op18Y = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op18Z = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op18R = (int16) (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); - + DSPOp18 (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op18D&0xFF); DSP1.output [1] = (uint8) ((Op18D>>8)&0xFF); break; case 0x38: // Range - + Op38X = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op38Y = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op38Z = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op38R = (int16) (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); - + DSPOp38 (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op38D&0xFF); DSP1.output [1] = (uint8) ((Op38D>>8)&0xFF); break; - + case 0x28: // Distance (vector length) Op28X = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op28Y = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op28Z = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp28 (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op28R&0xFF); DSP1.output [1] = (uint8) ((Op28R>>8)&0xFF); break; - + case 0x2c: case 0x0c: // Rotate (2D rotate) Op0CA = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op0CX1 = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op0CY1 = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp0C (); - + DSP1.out_count = 4; DSP1.output [0] = (uint8) (Op0CX2&0xFF); DSP1.output [1] = (uint8) ((Op0CX2>>8)&0xFF); DSP1.output [2] = (uint8) (Op0CY2&0xFF); DSP1.output [3] = (uint8) ((Op0CY2>>8)&0xFF); break; - + case 0x3c: case 0x1c: // Polar (3D rotate) Op1CZ = (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); @@ -494,9 +474,9 @@ void DSP1SetByte(uint8 byte, uint16 address) Op1CXBR = (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); Op1CYBR = (DSP1.parameters [8]|(DSP1.parameters[9]<<8)); Op1CZBR = (DSP1.parameters [10]|(DSP1.parameters[11]<<8)); - + DSPOp1C (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op1CXAR&0xFF); DSP1.output [1] = (uint8) ((Op1CXAR>>8)&0xFF); @@ -505,7 +485,7 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op1CZAR&0xFF); DSP1.output [5] = (uint8) ((Op1CZAR>>8)&0xFF); break; - + case 0x32: case 0x22: case 0x12: @@ -517,9 +497,9 @@ void DSP1SetByte(uint8 byte, uint16 address) Op02LES = (short)(DSP1.parameters [8]|(DSP1.parameters[9]<<8)); Op02AAS = (unsigned short)(DSP1.parameters [10]|(DSP1.parameters[11]<<8)); Op02AZS = (unsigned short)(DSP1.parameters [12]|(DSP1.parameters[13]<<8)); - + DSPOp02 (); - + DSP1.out_count = 8; DSP1.output [0] = (uint8) (Op02VOF&0xFF); DSP1.output [1] = (uint8) ((Op02VOF>>8)&0xFF); @@ -530,15 +510,15 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [6] = (uint8) (Op02CY&0xFF); DSP1.output [7] = (uint8) ((Op02CY>>8)&0xFF); break; - + case 0x3a: //1a Mirror case 0x2a: //1a Mirror case 0x1a: // Raster mode 7 matrix data case 0x0a: Op0AVS = (short)(DSP1.parameters [0]|(DSP1.parameters[1]<<8)); - + DSPOp0A (); - + DSP1.out_count = 8; DSP1.output [0] = (uint8) (Op0AA&0xFF); DSP1.output [2] = (uint8) (Op0AB&0xFF); @@ -550,7 +530,7 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [7] = (uint8) ((Op0AD>>8)&0xFF); DSP1.in_index=0; break; - + case 0x16: case 0x26: case 0x36: @@ -558,9 +538,9 @@ void DSP1SetByte(uint8 byte, uint16 address) Op06X = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op06Y = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op06Z = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp06 (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op06H&0xff); DSP1.output [1] = (uint8) ((Op06H>>8)&0xFF); @@ -569,23 +549,23 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op06M&0xFF); DSP1.output [5] = (uint8) ((Op06M>>8)&0xFF); break; - + case 0x1e: case 0x2e: case 0x3e: case 0x0e: // Target Op0EH = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op0EV = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); - + DSPOp0E (); - + DSP1.out_count = 4; DSP1.output [0] = (uint8) (Op0EX&0xFF); DSP1.output [1] = (uint8) ((Op0EX>>8)&0xFF); DSP1.output [2] = (uint8) (Op0EY&0xFF); DSP1.output [3] = (uint8) ((Op0EY>>8)&0xFF); break; - + // Extra commands used by Pilot Wings case 0x05: case 0x35: @@ -595,30 +575,30 @@ void DSP1SetByte(uint8 byte, uint16 address) Op01Zr = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op01Yr = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op01Xr = (int16) (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); - + DSPOp01 (); break; - - case 0x15: + + case 0x15: case 0x11: // Set attitude matrix B Op11m = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op11Zr = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op11Yr = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op11Xr = (int16) (DSP1.parameters [7]|(DSP1.parameters[7]<<8)); - + DSPOp11 (); break; - + case 0x25: case 0x21: // Set attitude matrix C Op21m = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op21Zr = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op21Yr = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op21Xr = (int16) (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); - + DSPOp21 (); break; - + case 0x09: case 0x39: case 0x3d: @@ -626,9 +606,9 @@ void DSP1SetByte(uint8 byte, uint16 address) Op0DX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op0DY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op0DZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp0D (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op0DF&0xFF); DSP1.output [1] = (uint8) ((Op0DF>>8)&0xFF); @@ -637,15 +617,15 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op0DU&0xFF); DSP1.output [5] = (uint8) ((Op0DU>>8)&0xFF); break; - + case 0x19: case 0x1d: // Objective matrix B Op1DX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op1DY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op1DZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp1D (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op1DF&0xFF); DSP1.output [1] = (uint8) ((Op1DF>>8)&0xFF); @@ -654,15 +634,15 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op1DU&0xFF); DSP1.output [5] = (uint8) ((Op1DU>>8)&0xFF); break; - + case 0x29: case 0x2d: // Objective matrix C Op2DX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op2DY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op2DZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp2D (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op2DF&0xFF); DSP1.output [1] = (uint8) ((Op2DF>>8)&0xFF); @@ -671,15 +651,15 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op2DU&0xFF); DSP1.output [5] = (uint8) ((Op2DU>>8)&0xFF); break; - + case 0x33: case 0x03: // Subjective matrix A Op03F = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op03L = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op03U = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp03 (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op03X&0xFF); DSP1.output [1] = (uint8) ((Op03X>>8)&0xFF); @@ -688,14 +668,14 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op03Z&0xFF); DSP1.output [5] = (uint8) ((Op03Z>>8)&0xFF); break; - + case 0x13: // Subjective matrix B Op13F = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op13L = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op13U = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp13 (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op13X&0xFF); DSP1.output [1] = (uint8) ((Op13X>>8)&0xFF); @@ -704,14 +684,14 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op13Z&0xFF); DSP1.output [5] = (uint8) ((Op13Z>>8)&0xFF); break; - + case 0x23: // Subjective matrix C Op23F = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op23L = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op23U = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp23 (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op23X&0xFF); DSP1.output [1] = (uint8) ((Op23X>>8)&0xFF); @@ -720,55 +700,55 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op23Z&0xFF); DSP1.output [5] = (uint8) ((Op23Z>>8)&0xFF); break; - + case 0x3b: case 0x0b: Op0BX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op0BY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op0BZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp0B (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op0BS&0xFF); DSP1.output [1] = (uint8) ((Op0BS>>8)&0xFF); break; - + case 0x1b: Op1BX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op1BY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op1BZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp1B (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op1BS&0xFF); DSP1.output [1] = (uint8) ((Op1BS>>8)&0xFF); break; - + case 0x2b: Op2BX = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op2BY = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op2BZ = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); - + DSPOp2B (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8) (Op2BS&0xFF); DSP1.output [1] = (uint8) ((Op2BS>>8)&0xFF); break; - + case 0x34: - case 0x14: + case 0x14: Op14Zr = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); Op14Xr = (int16) (DSP1.parameters [2]|(DSP1.parameters[3]<<8)); Op14Yr = (int16) (DSP1.parameters [4]|(DSP1.parameters[5]<<8)); Op14U = (int16) (DSP1.parameters [6]|(DSP1.parameters[7]<<8)); Op14F = (int16) (DSP1.parameters [8]|(DSP1.parameters[9]<<8)); Op14L = (int16) (DSP1.parameters [10]|(DSP1.parameters[11]<<8)); - + DSPOp14 (); - + DSP1.out_count = 6; DSP1.output [0] = (uint8) (Op14Zrr&0xFF); DSP1.output [1] = (uint8) ((Op14Zrr>>8)&0xFF); @@ -777,30 +757,30 @@ void DSP1SetByte(uint8 byte, uint16 address) DSP1.output [4] = (uint8) (Op14Yrr&0xFF); DSP1.output [5] = (uint8) ((Op14Yrr>>8)&0xFF); break; - + case 0x27: case 0x2F: Op2FUnknown = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); - + DSPOp2F (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8)(Op2FSize&0xFF); DSP1.output [1] = (uint8)((Op2FSize>>8)&0xFF); break; - - + + case 0x07: case 0x0F: Op0FRamsize = (int16) (DSP1.parameters [0]|(DSP1.parameters[1]<<8)); - + DSPOp0F (); - + DSP1.out_count = 2; DSP1.output [0] = (uint8)(Op0FPass&0xFF); DSP1.output [1] = (uint8)((Op0FPass>>8)&0xFF); break; - + default: break; } @@ -813,7 +793,9 @@ void DSP1SetByte(uint8 byte, uint16 address) uint8 DSP1GetByte(uint16 address) { uint8 t; - if (address < DSP1.boundary) + if ((address & 0xf000) == 0x6000 || +// (address >= 0x8000 && address < 0xc000)) + (address&0x7fff) < 0x4000) { if (DSP1.out_count) { @@ -898,7 +880,7 @@ void DSP2SetByte(uint8 byte, uint16 address) // DSP1.first_parameter = FALSE; DSP1.in_index++; } - + if (DSP1.in_count==DSP1.in_index) { //DSP1.parameters [DSP1.in_index] |= (byte << 8); @@ -1034,7 +1016,7 @@ void DSP4SetByte(uint8 byte, uint16 address) InitDSP4(); DSP4_init=TRUE; } - if (address < DSP1.boundary) + if ((address & 0xf000) == 0x6000 || (address >= 0x8000 && address < 0xc000)) { dsp4_byte=byte; dsp4_address=address; @@ -1044,7 +1026,7 @@ void DSP4SetByte(uint8 byte, uint16 address) uint8 DSP4GetByte(uint16 address) { - if (address < DSP1.boundary) + if ((address & 0xf000) == 0x6000 || (address >= 0x8000 && address < 0xc000)) { dsp4_address=address; DSP4_GetByte(); diff --git a/source/snes9x/dsp1.h b/source/snes9x/dsp1.h index 8a1074bb..9d04f0f9 100644 --- a/source/snes9x/dsp1.h +++ b/source/snes9x/dsp1.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _DSP1_H_ #define _DSP1_H_ @@ -180,16 +161,6 @@ void DSP3_Reset(); void DSP4SetByte(uint8 byte, uint16 address); uint8 DSP4GetByte(uint16 address); -enum -{ - M_DSP1_LOROM_S, - M_DSP1_LOROM_L, - M_DSP1_HIROM, - M_DSP2_LOROM, - M_DSP3_LOROM, - M_DSP4_LOROM -}; - struct SDSP1 { uint8 version; bool8 waiting4command; @@ -201,22 +172,14 @@ struct SDSP1 { uint32 out_index; uint8 parameters [512]; uint8 output [512]; - - uint8 temp_save_data [406]; - uint32 maptype; - uint32 boundary; }; START_EXTERN_C void S9xResetDSP1 (); uint8 S9xGetDSP (uint16 Address); void S9xSetDSP (uint8 Byte, uint16 Address); -void S9xPreSaveDSP1(); -void S9xPostLoadDSP1(); - -extern struct SDSP1 DSP1; - END_EXTERN_C +extern struct SDSP1 DSP1; #endif diff --git a/source/snes9x/dsp1emu.c.inc b/source/snes9x/dsp1emu.c.inc index cf442409..d8377aa9 100644 --- a/source/snes9x/dsp1emu.c.inc +++ b/source/snes9x/dsp1emu.c.inc @@ -1213,182 +1213,3 @@ void DSPOp2F() { Op2FSize=0x100; } - - - -// FIXME: many of these are unnecessary to save. But some of them are necessary, like Matrix* and maybe VPlane_* -// TODO: move the necessary ones into a global structure so it's not as ugly to save -#define SAVE_OR_LOAD_THE_VARIABLES() \ -S(Op00Multiplicand); \ -S(Op00Multiplier); \ -S(Op00Result); \ -S(Op20Multiplicand); \ -S(Op20Multiplier); \ -S(Op20Result); \ -S(Op10Coefficient); \ -S(Op10Exponent); \ -S(Op10CoefficientR); \ -S(Op10ExponentR); \ -S(Op04Angle); \ -S(Op04Radius); \ -S(Op04Sin); \ -S(Op04Cos); \ -S(Op0CA); \ -S(Op0CX1); \ -S(Op0CY1); \ -S(Op0CX2); \ -S(Op0CY2); \ -S(CentreX); \ -S(CentreY); \ -S(VOffset); \ -S(VPlane_C); \ -S(VPlane_E); \ -S(SinAas); \ -S(CosAas); \ -S(SinAzs); \ -S(CosAzs); \ -S(SinAZS); \ -S(CosAZS); \ -S(SecAZS_C1); \ -S(SecAZS_E1); \ -S(SecAZS_C2); \ -S(SecAZS_E2); \ -S(Nx); S(Ny); S(Nz); \ -S(Gx); S(Gy); S(Gz); \ -S(C_Les); S(E_Les); S(G_Les); \ -S(Op02FX); \ -S(Op02FY); \ -S(Op02FZ); \ -S(Op02LFE); \ -S(Op02LES); \ -S(Op02AAS); \ -S(Op02AZS); \ -S(Op02VOF); \ -S(Op02VVA); \ -S(Op02CX); \ -S(Op02CY); \ -S(Op0AVS); \ -S(Op0AA); \ -S(Op0AB); \ -S(Op0AC); \ -S(Op0AD); \ -S(Op06X); \ -S(Op06Y); \ -S(Op06Z); \ -S(Op06H); \ -S(Op06V); \ -S(Op06M); \ -S(matrixC); \ -S(matrixB); \ -S(matrixA); \ -S(Op01m); \ -S(Op01Zr); \ -S(Op01Xr); \ -S(Op01Yr); \ -S(Op11m); \ -S(Op11Zr); \ -S(Op11Xr); \ -S(Op11Yr); \ -S(Op21m); \ -S(Op21Zr); \ -S(Op21Xr); \ -S(Op21Yr); \ -S(Op0DX); \ -S(Op0DY); \ -S(Op0DZ); \ -S(Op0DF); \ -S(Op0DL); \ -S(Op0DU); \ -S(Op1DX); \ -S(Op1DY); \ -S(Op1DZ); \ -S(Op1DF); \ -S(Op1DL); \ -S(Op1DU); \ -S(Op2DX); \ -S(Op2DY); \ -S(Op2DZ); \ -S(Op2DF); \ -S(Op2DL); \ -S(Op2DU); \ -S(Op03F); \ -S(Op03L); \ -S(Op03U); \ -S(Op03X); \ -S(Op03Y); \ -S(Op03Z); \ -S(Op13F); \ -S(Op13L); \ -S(Op13U); \ -S(Op13X); \ -S(Op13Y); \ -S(Op13Z); \ -S(Op23F); \ -S(Op23L); \ -S(Op23U); \ -S(Op23X); \ -S(Op23Y); \ -S(Op23Z); \ -S(Op14Zr); \ -S(Op14Xr); \ -S(Op14Yr); \ -S(Op14U); \ -S(Op14F); \ -S(Op14L); \ -S(Op14Zrr); \ -S(Op14Xrr); \ -S(Op14Yrr); \ -S(Op0EH); \ -S(Op0EV); \ -S(Op0EX); \ -S(Op0EY); \ -S(Op0BX); \ -S(Op0BY); \ -S(Op0BZ); \ -S(Op0BS); \ -S(Op1BX); \ -S(Op1BY); \ -S(Op1BZ); \ -S(Op1BS); \ -S(Op2BX); \ -S(Op2BY); \ -S(Op2BZ); \ -S(Op2BS); \ -S(Op08X); S(Op08Y); S(Op08Z); S(Op08Ll); S(Op08Lh); \ -S(Op18X); S(Op18Y); S(Op18Z); S(Op18R); S(Op18D); \ -S(Op38X); S(Op38Y); S(Op38Z); S(Op38R); S(Op38D); \ -S(Op28X); \ -S(Op28Y); \ -S(Op28Z); \ -S(Op28R); \ -S(Op1CX); S(Op1CY); S(Op1CZ); \ -S(Op1CXBR); S(Op1CYBR); S(Op1CZBR); S(Op1CXAR); S(Op1CYAR); S(Op1CZAR); \ -S(Op1CX1); \ -S(Op1CY1); \ -S(Op1CZ1); \ -S(Op1CX2); \ -S(Op1CY2); \ -S(Op1CZ2); \ -S(Op0FRamsize); \ -S(Op0FPass); \ -S(Op2FUnknown); \ -S(Op2FSize); \ -// end - -void S9xPreSaveDSP1() -{ - int i = 0; -#define S(x) {memcpy(DSP1.temp_save_data + i, &(x), sizeof(x)); i += sizeof(x);} - SAVE_OR_LOAD_THE_VARIABLES(); -#undef S - assert(i == sizeof(DSP1.temp_save_data)); -} - -void S9xPostLoadDSP1() -{ - int i = 0; -#define S(x) {memcpy(&(x), DSP1.temp_save_data + i, sizeof(x)); i += sizeof(x);} - SAVE_OR_LOAD_THE_VARIABLES(); -#undef S - assert(i == sizeof(DSP1.temp_save_data)); -} diff --git a/source/snes9x/dsp2emu.c.inc b/source/snes9x/dsp2emu.c.inc index 7512b2d5..869ed816 100644 --- a/source/snes9x/dsp2emu.c.inc +++ b/source/snes9x/dsp2emu.c.inc @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -160,8 +143,6 @@ - - uint16 DSP2Op09Word1=0; uint16 DSP2Op09Word2=0; bool DSP2Op05HasLen=false; @@ -220,7 +201,7 @@ void DSP2_Op01 () { // Op01 size is always 32 bytes input and output. // The hardware does strange things if you vary the size. - + int j; unsigned char c0, c1, c2, c3; unsigned char *p1 = DSP1.parameters; @@ -318,7 +299,7 @@ void DSP2_Op0D() if ( (pixel_offset&1) == 0 ) pixelarray[i] = DSP1.parameters[pixel_offset>>1] >> 4; else - pixelarray[i] = DSP1.parameters[pixel_offset>>1] & 0x0f; + pixelarray[i] = DSP1.parameters[pixel_offset>>1] & 0x0f; } for ( i=0; i < DSP2Op0DOutLen; i++ ) diff --git a/source/snes9x/dsp3emu.c.inc b/source/snes9x/dsp3emu.c.inc index 06b91c8c..7b120b9c 100644 --- a/source/snes9x/dsp3emu.c.inc +++ b/source/snes9x/dsp3emu.c.inc @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef __cplusplus //C++ in C typedef unsigned char bool; @@ -1125,7 +1106,9 @@ void DSP3_OP1E_D( int16 move, int16 *lo, int16 *hi ) void DSP3_OP1E_D1( int16 move, int16 *lo, int16 *hi ) { - //uint32 dataOfs = ((move << 1) + 0x03b2) & 0x03ff; +#ifndef NGC + uint32 dataOfs = ((move << 1) + 0x03b2) & 0x03ff; +#endif int16 Lo; int16 Hi; @@ -1249,7 +1232,7 @@ void DSP3_Command() void DSP3SetByte(uint8 byte, uint16 address) { - if (address < DSP1.boundary) + if ((address & 0xC000) == 0x8000) { if (DSP3_SR & 0x04) { @@ -1260,20 +1243,20 @@ void DSP3SetByte(uint8 byte, uint16 address) { DSP3_SR ^= 0x10; - if (DSP3_SR & 0x10) + if (DSP3_SR & 0x10) DSP3_DR = (DSP3_DR & 0xff00) + byte; else { DSP3_DR = (DSP3_DR & 0x00ff) + (byte << 8); (*SetDSP3)(); - } + } } } } uint8 DSP3GetByte(uint16 address) { - if (address < DSP1.boundary) + if ((address & 0xC000) == 0x8000) { uint8 byte; @@ -1286,7 +1269,7 @@ uint8 DSP3GetByte(uint16 address) { DSP3_SR ^= 0x10; - if (DSP3_SR & 0x10) + if (DSP3_SR & 0x10) byte = (uint8) (DSP3_DR); else { diff --git a/source/snes9x/dsp4emu.c.inc b/source/snes9x/dsp4emu.c.inc index 2a658425..29a1696c 100644 --- a/source/snes9x/dsp4emu.c.inc +++ b/source/snes9x/dsp4emu.c.inc @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include diff --git a/source/snes9x/font.h b/source/snes9x/font.h index 1b126cc2..ad54c3fb 100644 --- a/source/snes9x/font.h +++ b/source/snes9x/font.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - static char *font[] = { " . . . . .. . . ", " .#. .#.#. . . ... .#. . . .##. .#. .#. . . . . ", @@ -246,7 +227,7 @@ static char *font[] = { " .#.#. .##. .#. .###. .#. .#. .#. .###. .#. .#. .####. .##. .##. ", " .#. .. .#. ... . . . ... . . .... .. .. ", " . . ", -//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 +//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 " .... . . ... . . . .... . . . .. . ..... . . . ", " .####. .#. ..#.. .###. ...#. ..#.. ..#.. .####. .#... .... .#.#. .##..#. .#####. .#... .#. .#. ", " .... ...#. .#. .#####. .#. .#####. .#####. .#####. .#..#. .####. .####. .#####. .. .#. ....#. .#####. .#. .#. ", @@ -256,24 +237,24 @@ static char *font[] = { " .#. .#. .##. .#####. .#..#. .#..#. .#. .#. .#. .####. .#. .###. .#. .#. .###. .###. ", " . . .. ..... . . . . . . . .... . ... . . ... ... ", " ", -//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 +//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 " .... .. . . . ... . . ... .... . . . ..... . . ", " .####. ..##. .#.#.#. .###. .#. ..#.. .###. .####. ..#.. .#. . . .#. .. .#####. .#. ..#.. ..... ", " .#..#. .###. .#.#.#. ..... .#. .#####. ... ...#. .#####. .#. .#.#. .#..##. ....#. .#.#. .#####. .#####. ", -" .####. ..#. .#.#.#. .#####. .##. ..#.. .#.#. ....#. .#. .#.#. .###.. .#. .#..#. ..#.. .#. ", +" .####. ..#. .#.#.#. .#####. .##. ..#.. .#.#. ....#. .#. .#.#. .###.. .#. .#..#. ..#.. .#. ", ".#...#. .####. . ..#. ..#.. .#.#. .#. .#. .###. .#. .#. .#. .#.. .#. . .#. .#.#.#. .#.#. ", " . .#. ..#. ...#. .#. .#.. ..#. ..... .#.#. .#.#.#. .#. .#. .#. .#.... ..#. .#. .#.#.#. .#. ", " .#. .##. .###. .#. .#. .##. .#####. .#. .#. ..#.. .#. .#. .#. .####. .##. .#. ..#.. .#. ", " . .. ... . . .. ..... . . . . . . .... .. . . . ", " ", -//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 +//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 " .. . . ... . .... .... . . . . . ..... . . . . ", " .##. .#. .#. .###. .#... ... .####. .####. .#..#. .#.#. .#. ..... .#####. ....#. .#.#. .#. ", " ..#. .#. . .#. .#. .#.##. .###. ...#. ..... .#..#. .#.#. .#. .#####. .#...#. .###.#. .#.#. .#.#. ", -" .##. .#. . .#.#. .#####. .##.#. .#. .###. .#####. .#..#. .#.#. .#. . .#...#. . .#. ....#. . . .#. ", +" .##. .#. . .#.#. .#####. .##.#. .#. .###. .#####. .#..#. .#.#. .#. . .#...#. . .#. ....#. . . .#. ", " ..#. .#..#. .##. ..#.. .#.#. ..#. ..#. ....#. . .#. .#.#. .#..#. .#...#. .#. .#. . ", " .##. .####. ..#.#. .#.. .#. ...#. ...#. ..#. ..#. .#.#. .#.#. .#####. ..#. ...#. ", -" ..#. ...#. .##. . .###. .#. .#####. .####. .##. .##. .#..##. .##. .#...#. .##. .###. ", +" ..#. ...#. .##. . .###. .#. .#####. .####. .##. .##. .#..##. .##. .#...#. .##. .###. ", " . . .. ... . ..... .... .. ... . .. .. . . .. ... ", " ", @@ -298,3 +279,6 @@ static char *font[] = { " " }; +static int font_width = 8; +static int font_height = 9; + diff --git a/source/snes9x/fxdbg.cpp b/source/snes9x/fxdbg.cpp index f51c94de..d7b0d4c0 100644 --- a/source/snes9x/fxdbg.cpp +++ b/source/snes9x/fxdbg.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "fxemu.h" #include "fxinst.h" #include @@ -192,7 +173,7 @@ extern struct FxRegs_s GSU; in this debug function. (See the diffrence of how the values vPipe1 and vPipe2 are read, compared to the values vByte1 and vByte2) - + */ void FxPipeString(char * pvString) { @@ -201,11 +182,11 @@ void FxPipeString(char * pvString) const char *m = fx_apvMnemonicTable[vOpcode]; uint8 vPipe1,vPipe2,vByte1,vByte2; uint8 vPipeBank = GSU.vPipeAdr >> 16; - + /* The next two bytes after the pipe's address */ vPipe1 = GSU.apvRomBank[vPipeBank][USEX16(GSU.vPipeAdr+1)]; vPipe2 = GSU.apvRomBank[vPipeBank][USEX16(GSU.vPipeAdr+2)]; - + /* The actual next two bytes to be read */ vByte1 = PRGBANK(USEX16(R15)); vByte2 = PRGBANK(USEX16(R15+1)); @@ -214,7 +195,7 @@ void FxPipeString(char * pvString) sprintf(pvString, "%02x:%04x %02x ", USEX8(vPipeBank), USEX16(GSU.vPipeAdr), USEX8(PIPE)); p = &pvString[strlen(pvString)]; - + /* Check if it's a branch instruction */ if( PIPE >= 0x05 && PIPE <= 0x0f ) { @@ -263,7 +244,7 @@ const char *fx_apvMnemonicTable[] = "to r0", "to r1", "to r2", "to r3", "to r4", "to r5", "to r6", "to r7", "to r8", "to r9", "to r10", "to r11", "to r12", "to r13", "to r14", "to r15", /* 20 - 2f */ - "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", + "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", "with r8", "with r9", "with r10", "with r11", "with r12", "with r13", "with r14", "with r15", /* 30 - 3f */ "stw (r0)","stw (r1)","stw (r2)", "stw (r3)", "stw (r4)", "stw (r5)", "stw (r6)", "stw (r7)", @@ -320,7 +301,7 @@ const char *fx_apvMnemonicTable[] = "to r0", "to r1", "to r2", "to r3", "to r4", "to r5", "to r6", "to r7", "to r8", "to r9", "to r10", "to r11", "to r12", "to r13", "to r14", "to r15", /* 20 - 2f */ - "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", + "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", "with r8", "with r9", "with r10", "with r11", "with r12", "with r13", "with r14", "with r15", /* 30 - 3f */ "stb (r0)","stb (r1)","stb (r2)", "stb (r3)", "stb (r4)", "stb (r5)", "stb (r6)", "stb (r7)", @@ -377,7 +358,7 @@ const char *fx_apvMnemonicTable[] = "to r0", "to r1", "to r2", "to r3", "to r4", "to r5", "to r6", "to r7", "to r8", "to r9", "to r10", "to r11", "to r12", "to r13", "to r14", "to r15", /* 20 - 2f */ - "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", + "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", "with r8", "with r9", "with r10", "with r11", "with r12", "with r13", "with r14", "with r15", /* 30 - 3f */ "stw (r0)","stw (r1)","stw (r2)", "stw (r3)", "stw (r4)", "stw (r5)", "stw (r6)", "stw (r7)", @@ -434,7 +415,7 @@ const char *fx_apvMnemonicTable[] = "to r0", "to r1", "to r2", "to r3", "to r4", "to r5", "to r6", "to r7", "to r8", "to r9", "to r10", "to r11", "to r12", "to r13", "to r14", "to r15", /* 20 - 2f */ - "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", + "with r0", "with r1", "with r2", "with r3", "with r4", "with r5", "with r6", "with r7", "with r8", "with r9", "with r10", "with r11", "with r12", "with r13", "with r14", "with r15", /* 30 - 3f */ "stb (r0)","stb (r1)","stb (r2)", "stb (r3)", "stb (r4)", "stb (r5)", "stb (r6)", "stb (r7)", diff --git a/source/snes9x/fxemu.cpp b/source/snes9x/fxemu.cpp index 2b7e6606..d2b15d13 100644 --- a/source/snes9x/fxemu.cpp +++ b/source/snes9x/fxemu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "fxemu.h" #include "fxinst.h" #include @@ -253,7 +234,7 @@ static void fx_backupCache() memcpy(t1,&GSU.pvCache[i<<4],a); memcpy(&GSU.avCacheBackup[(i<<4)+a],t2,16-a); memcpy(t2,&GSU.pvCache[(i<<4)+a],16-a); - } + } } c = USEX16(c+16); v >>= 1; @@ -289,7 +270,7 @@ static void fx_restoreCache() memcpy(&GSU.pvCache[i<<4],t1,a); memcpy(t2,&GSU.avCacheBackup[(i<<4)+a],16-a); memcpy(&GSU.pvCache[(i<<4)+a],t2,16-a); - } + } } c = USEX16(c+16); v >>= 1; @@ -345,7 +326,7 @@ static void fx_readRegisterSpace() GSU.vSign = (GSU.vStatusReg & FLG_S) << 12; GSU.vOverflow = (GSU.vStatusReg & FLG_OV) << 16; GSU.vCarry = (GSU.vStatusReg & FLG_CY) >> 2; - + /* Set bank pointers */ GSU.pvRamBank = GSU.apvRamBank[GSU.vRamBankReg & 0x3]; GSU.pvRomBank = GSU.apvRomBank[GSU.vRomBankReg]; @@ -397,7 +378,7 @@ void fx_dirtySCBR() void fx_computeScreenPointers () { - if (GSU.vMode != GSU.vPrevMode || + if (GSU.vMode != GSU.vPrevMode || GSU.vPrevScreenHeight != GSU.vScreenHeight || GSU.vSCBRDirty) { @@ -495,7 +476,7 @@ void fx_computeScreenPointers () case 0: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 9) + ((i & 0xf) << 8); GSU.x[i] = ((i & 0x10) << 8) + ((i & 0xf) << 4); } @@ -503,7 +484,7 @@ void fx_computeScreenPointers () case 1: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 10) + ((i & 0xf) << 9); GSU.x[i] = ((i & 0x10) << 9) + ((i & 0xf) << 5); } @@ -512,7 +493,7 @@ void fx_computeScreenPointers () case 3: for (i = 0; i < 32; i++) { - GSU.apvScreen[i] = GSU.pvScreenBase + + GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 11) + ((i & 0xf) << 10); GSU.x[i] = ((i & 0x10) << 10) + ((i & 0xf) << 6); } @@ -529,7 +510,7 @@ static void fx_writeRegisterSpace() { int i; uint8 *p; - + p = GSU.pvRegisters; for(i=0; i<16; i++) { @@ -546,7 +527,7 @@ static void fx_writeRegisterSpace() else CF(OV); if(GSU.vCarry) SF(CY); else CF(CY); - + p = GSU.pvRegisters; p[GSU_SFR] = (uint8)GSU.vStatusReg; p[GSU_SFR+1] = (uint8)(GSU.vStatusReg>>8); @@ -555,7 +536,7 @@ static void fx_writeRegisterSpace() p[GSU_RAMBR] = (uint8)GSU.vRamBankReg; p[GSU_CBR] = (uint8)GSU.vCacheBaseReg; p[GSU_CBR+1] = (uint8)(GSU.vCacheBaseReg>>8); - + fx_restoreCache(); } @@ -569,7 +550,7 @@ void FxReset(struct FxInit_s *psFxInfo) &fx_a_apfFunctionTable[0], &fx_r_apfFunctionTable[0], &fx_ar_apfFunctionTable[0], -#endif +#endif }; static void (**appfPlot[])() = { &fx_apfPlotTable[0], @@ -577,22 +558,22 @@ void FxReset(struct FxInit_s *psFxInfo) &fx_a_apfPlotTable[0], &fx_r_apfPlotTable[0], &fx_ar_apfPlotTable[0], -#endif +#endif }; static void (**appfOpcode[])() = { &fx_apfOpcodeTable[0], -#if 0 +#if 0 &fx_a_apfOpcodeTable[0], &fx_r_apfOpcodeTable[0], &fx_ar_apfOpcodeTable[0], -#endif +#endif }; /* Get function pointers for the current emulation mode */ fx_ppfFunctionTable = appfFunction[psFxInfo->vFlags & 0x3]; fx_ppfPlotTable = appfPlot[psFxInfo->vFlags & 0x3]; fx_ppfOpcodeTable = appfOpcode[psFxInfo->vFlags & 0x3]; - + /* Clear all internal variables */ memset((uint8*)&GSU,0,sizeof(struct FxRegs_s)); @@ -611,7 +592,7 @@ void FxReset(struct FxInit_s *psFxInfo) /* The GSU can't access more than 2mb (16mbits) */ if(GSU.nRomBanks > 0x20) GSU.nRomBanks = 0x20; - + /* Clear FxChip register space */ memset(GSU.pvRegisters,0,0x300); @@ -644,7 +625,7 @@ void FxReset(struct FxInit_s *psFxInfo) GSU.apvRamBank[i] = &GSU.pvRam[(i % GSU.nRamBanks) << 16]; GSU.apvRomBank[0x70 + i] = GSU.apvRamBank[i]; } - + /* Start with a nop in the pipe */ GSU.vPipe = 0x01; @@ -659,7 +640,7 @@ static uint8 fx_checkStartAddress() /* Check if we start inside the cache */ if(GSU.bCacheActive && R15 >= GSU.vCacheBaseReg && R15 < (GSU.vCacheBaseReg+512)) return TRUE; - + /* Check if we're in an unused area */ #if 0 if(GSU.vPrgBankReg < 0x40 && R15 < 0x8000) @@ -677,7 +658,7 @@ static uint8 fx_checkStartAddress() /* If not, we're in ROM, so check if the RON flag is set */ if(!(SCMR&(1<<4))) return FALSE; - + return TRUE; } @@ -748,7 +729,7 @@ int FxStepOver(uint32 nInstructions) return 0; #endif } - + if( PIPE >= 0xf0 ) GSU.vStepPoint = USEX16(R15+3); else if( (PIPE >= 0x05 && PIPE <= 0x0f) || (PIPE >= 0xa0 && PIPE <= 0xaf) ) diff --git a/source/snes9x/fxemu.h b/source/snes9x/fxemu.h index a9e1ee4c..22f8d5a9 100644 --- a/source/snes9x/fxemu.h +++ b/source/snes9x/fxemu.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _FXEMU_H_ #define _FXEMU_H_ 1 diff --git a/source/snes9x/fxinst.cpp b/source/snes9x/fxinst.cpp index 9f45bcc9..76ee3e84 100644 --- a/source/snes9x/fxinst.cpp +++ b/source/snes9x/fxinst.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #define FX_DO_ROMBUFFER #include "fxemu.h" @@ -232,7 +213,7 @@ static void fx_cache() memcpy(GSU.pvCache,t1,i); memcpy(&GSU.pvCache[i],t2,512-i); } -#endif +#endif } R15++; CLRFLAGS; @@ -408,7 +389,7 @@ static void fx_alt2() { SF(ALT2); CF(B); R15++; } /* 3f - alt3 - set alt3 mode */ static void fx_alt3() { SF(ALT1); SF(ALT2); CF(B); R15++; } - + /* 40-4b - ldw (rn) - load word from RAM */ #define FX_LDW(reg) uint32 v; \ GSU.vLastRamAdr = GSU.avReg[reg]; \ @@ -469,7 +450,7 @@ static void fx_plot_2bit() c = (x^y)&1 ? (uint8)(GSU.vColorReg>>4) : (uint8)GSU.vColorReg; else c = (uint8)GSU.vColorReg; - + if( !(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) return; a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1); v = 128 >> (x&7); @@ -514,7 +495,7 @@ static void fx_plot_4bit() R15++; CLRFLAGS; R1++; - + #ifdef CHECK_LIMITS if(y >= GSU.vScreenHeight) return; #endif @@ -575,7 +556,7 @@ static void fx_plot_8bit() R15++; CLRFLAGS; R1++; - + #ifdef CHECK_LIMITS if(y >= GSU.vScreenHeight) return; #endif @@ -1082,7 +1063,7 @@ static void fx_umult_r12() { FX_UMULT(12); } static void fx_umult_r13() { FX_UMULT(13); } static void fx_umult_r14() { FX_UMULT(14); } static void fx_umult_r15() { FX_UMULT(15); } - + /* 80-8f(ALT2) - mult #n - 8 bit to 16 bit signed multiply, register * immediate */ #define FX_MULT_I(imm) \ uint32 v = (uint32) (SEX8(SREG) * ((int32)imm)); \ @@ -1107,7 +1088,7 @@ static void fx_mult_i12() { FX_MULT_I(12); } static void fx_mult_i13() { FX_MULT_I(13); } static void fx_mult_i14() { FX_MULT_I(14); } static void fx_mult_i15() { FX_MULT_I(15); } - + /* 80-8f(ALT3) - umult #n - 8 bit to 16 bit unsigned multiply, register * immediate */ #define FX_UMULT_I(imm) \ uint32 v = USEX8(SREG) * ((uint32)imm); \ @@ -1132,7 +1113,7 @@ static void fx_umult_i12() { FX_UMULT_I(12); } static void fx_umult_i13() { FX_UMULT_I(13); } static void fx_umult_i14() { FX_UMULT_I(14); } static void fx_umult_i15() { FX_UMULT_I(15); } - + /* 90 - sbk - store word to last accessed RAM address */ static void fx_sbk() { @@ -1786,7 +1767,7 @@ void (*fx_apfOpcodeTable[])() = &fx_to_r0, &fx_to_r1, &fx_to_r2, &fx_to_r3, &fx_to_r4, &fx_to_r5, &fx_to_r6, &fx_to_r7, &fx_to_r8, &fx_to_r9, &fx_to_r10, &fx_to_r11, &fx_to_r12, &fx_to_r13, &fx_to_r14, &fx_to_r15, /* 20 - 2f */ - &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, + &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15, /* 30 - 3f */ &fx_stw_r0, &fx_stw_r1, &fx_stw_r2, &fx_stw_r3, &fx_stw_r4, &fx_stw_r5, &fx_stw_r6, &fx_stw_r7, @@ -1839,7 +1820,7 @@ void (*fx_apfOpcodeTable[])() = &fx_to_r0, &fx_to_r1, &fx_to_r2, &fx_to_r3, &fx_to_r4, &fx_to_r5, &fx_to_r6, &fx_to_r7, &fx_to_r8, &fx_to_r9, &fx_to_r10, &fx_to_r11, &fx_to_r12, &fx_to_r13, &fx_to_r14, &fx_to_r15, /* 20 - 2f */ - &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, + &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15, /* 30 - 3f */ &fx_stb_r0, &fx_stb_r1, &fx_stb_r2, &fx_stb_r3, &fx_stb_r4, &fx_stb_r5, &fx_stb_r6, &fx_stb_r7, @@ -1892,7 +1873,7 @@ void (*fx_apfOpcodeTable[])() = &fx_to_r0, &fx_to_r1, &fx_to_r2, &fx_to_r3, &fx_to_r4, &fx_to_r5, &fx_to_r6, &fx_to_r7, &fx_to_r8, &fx_to_r9, &fx_to_r10, &fx_to_r11, &fx_to_r12, &fx_to_r13, &fx_to_r14, &fx_to_r15, /* 20 - 2f */ - &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, + &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15, /* 30 - 3f */ &fx_stw_r0, &fx_stw_r1, &fx_stw_r2, &fx_stw_r3, &fx_stw_r4, &fx_stw_r5, &fx_stw_r6, &fx_stw_r7, @@ -1945,7 +1926,7 @@ void (*fx_apfOpcodeTable[])() = &fx_to_r0, &fx_to_r1, &fx_to_r2, &fx_to_r3, &fx_to_r4, &fx_to_r5, &fx_to_r6, &fx_to_r7, &fx_to_r8, &fx_to_r9, &fx_to_r10, &fx_to_r11, &fx_to_r12, &fx_to_r13, &fx_to_r14, &fx_to_r15, /* 20 - 2f */ - &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, + &fx_with_r0, &fx_with_r1, &fx_with_r2, &fx_with_r3, &fx_with_r4, &fx_with_r5, &fx_with_r6, &fx_with_r7, &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15, /* 30 - 3f */ &fx_stb_r0, &fx_stb_r1, &fx_stb_r2, &fx_stb_r3, &fx_stb_r4, &fx_stb_r5, &fx_stb_r6, &fx_stb_r7, diff --git a/source/snes9x/fxinst.h b/source/snes9x/fxinst.h index e78e682a..a95c5529 100644 --- a/source/snes9x/fxinst.h +++ b/source/snes9x/fxinst.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _FXINST_H_ #define _FXINST_H_ 1 @@ -174,20 +155,20 @@ * 3004 - R2 pixel plot Y position register * 3006 - R3 * 3008 - R4 lower 16 bit result of lmult - * 300a - R5 + * 300a - R5 * 300c - R6 multiplier for fmult and lmult * 300e - R7 fixed point texel X position for merge * 3010 - R8 fixed point texel Y position for merge - * 3012 - R9 - * 3014 - R10 + * 3012 - R9 + * 3014 - R10 * 3016 - R11 return address set by link * 3018 - R12 loop counter * 301a - R13 loop point address * 301c - R14 rom address for getb, getbh, getbl, getbs - * 301e - R15 program counter + * 301e - R15 program counter * * 3020-302f - unused - * + * * Other internal registers * 3030 - SFR status flag register (16bit) * 3032 - unused @@ -209,21 +190,21 @@ * 3100-32ff - CACHERAM 512 bytes of GSU cache memory * * SFR status flag register bits: - * 0 - + * 0 - * 1 Z Zero flag * 2 CY Carry flag * 3 S Sign flag * 4 OV Overflow flag * 5 G Go flag (set to 1 when the GSU is running) * 6 R Set to 1 when reading ROM using R14 address - * 7 - + * 7 - * 8 ALT1 Mode set-up flag for the next instruction * 9 ALT2 Mode set-up flag for the next instruction * 10 IL Immediate lower 8-bit flag * 11 IH Immediate higher 8-bit flag * 12 B Set to 1 when the WITH instruction is executed - * 13 - - * 14 - + * 13 - + * 14 - * 15 IRQ Set to 1 when GSU caused an interrupt * Set to 0 when read by 658c16 * @@ -231,13 +212,13 @@ * BRAMR = 1, BackupRAM is enabled * * CFGR control flags register bits: - * 0 - - * 1 - - * 2 - - * 3 - - * 4 - + * 0 - + * 1 - + * 2 - + * 3 - + * 4 - * 5 MS0 Multiplier speed, 0=standard, 1=high speed - * 6 - + * 6 - * 7 IRQ Set to 1 when GSU interrupt request is masked * * CLSR clock speed register bits: @@ -250,8 +231,8 @@ * 3 RAN RAM access control * 4 RON ROM access control * 5 HT1 screen height bit 2 - * 6 - - * 7 - + * 6 - + * 7 - * * RON = 0 SNES CPU has ROM access * RON = 1 GSU has ROM access @@ -314,16 +295,16 @@ struct FxRegs_s uint32 vZero; /* v == 0 */ uint32 vCarry; /* a value of 1 or 0 */ int32 vOverflow; /* (v >= 0x8000 || v < -0x8000) */ - + /* Other emulator variables */ - + int32 vErrorCode; uint32 vIllegalAddress; - + uint8 bBreakPoint; uint32 vBreakPoint; uint32 vStepPoint; - + uint8 * pvRegisters; /* 768 bytes located in the memory at address 0x3000 */ uint32 nRamBanks; /* Number of 64kb-banks in FxRam (Don't confuse it with SNES-Ram!!!) */ uint8 * pvRam; /* Pointer to FxRam */ @@ -334,14 +315,14 @@ struct FxRegs_s uint32 vPrevMode; /* Previous depth */ uint8 * pvScreenBase; uint8 * apvScreen[32]; /* Pointer to each of the 32 screen colums */ - int32 x[32]; + int x[32]; uint32 vScreenHeight; /* 128, 160, 192 or 256 (could be overriden by cmode) */ uint32 vScreenRealHeight; /* 128, 160, 192 or 256 */ uint32 vPrevScreenHeight; uint32 vScreenSize; void (*pfPlot)(); void (*pfRpix)(); - + uint8 * pvRamBank; /* Pointer to current RAM-bank */ uint8 * pvRomBank; /* Pointer to current ROM-bank */ uint8 * pvPrgBank; /* Pointer to current program ROM-bank */ diff --git a/source/snes9x/getset.h b/source/snes9x/getset.h index aa61a786..219ff6f6 100644 --- a/source/snes9x/getset.h +++ b/source/snes9x/getset.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _GETSET_H_ #define _GETSET_H_ @@ -183,7 +164,7 @@ INLINE uint8 S9xGetByte (uint32 Address) int block; uint8 *GetAddress = Memory.Map [block = ((Address&0xffffff) >> MEMMAP_SHIFT)]; - if(!CPU.InDMAorHDMA) + if(!CPU.InDMA) CPU.Cycles += Memory.MemorySpeed [block]; if (GetAddress >= (uint8 *) CMemory::MAP_LAST) @@ -194,11 +175,11 @@ INLINE uint8 S9xGetByte (uint32 Address) #endif return (*(GetAddress + (Address & 0xffff))); } - + switch ((pint) GetAddress) { case CMemory::MAP_PPU: - if(CPU.InDMAorHDMA && (Address&0xff00)==0x2100) return OpenBus; + if(CPU.InDMA && (Address&0xff00)==0x2100) return OpenBus; return (S9xGetPPU (Address & 0xffff)); case CMemory::MAP_CPU: return (S9xGetCPU (Address & 0xffff)); @@ -212,9 +193,6 @@ INLINE uint8 S9xGetByte (uint32 Address) //unbound & SRAMMask = Sram offset return (*(Memory.SRAM + ((((Address&0xFF0000)>>1) |(Address&0x7FFF)) &Memory.SRAMMask))); - case CMemory::MAP_LOROM_SRAM_B: - return (*(Multi.sramB + ((((Address&0xFF0000)>>1) |(Address&0x7FFF)) &Multi.sramMaskB))); - case CMemory::MAP_RONLY_SRAM: case CMemory::MAP_HIROM_SRAM: return (*(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + @@ -293,10 +271,10 @@ INLINE uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w=WRAP_NONE) int block; uint8 *GetAddress = Memory.Map [block = ((Address&0xffffff) >> MEMMAP_SHIFT)]; - if(!CPU.InDMAorHDMA) + if(!CPU.InDMA) CPU.Cycles += (Memory.MemorySpeed [block]<<1); - + if (GetAddress >= (uint8 *) CMemory::MAP_LAST) { #ifdef CPU_SHUTDOWN @@ -309,7 +287,7 @@ INLINE uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w=WRAP_NONE) switch ((pint) GetAddress) { case CMemory::MAP_PPU: - if(CPU.InDMAorHDMA){ + if(CPU.InDMA){ OpenBus=S9xGetByte (Address); return (OpenBus | (S9xGetByte (Address + 1) << 8)); } @@ -335,20 +313,11 @@ INLINE uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w=WRAP_NONE) } else { /* no READ_WORD here, since if Memory.SRAMMask=0x7ff * then the high byte doesn't follow the low byte. */ - return + return (*(Memory.SRAM + ((((Address&0xFF0000)>>1) |(Address&0x7FFF)) &Memory.SRAMMask)))| ((*(Memory.SRAM + (((((Address+1)&0xFF0000)>>1) |((Address+1)&0x7FFF)) &Memory.SRAMMask)))<<8); } - case CMemory::MAP_LOROM_SRAM_B: - if(Multi.sramMaskB>=MEMMAP_MASK){ - return READ_WORD(Multi.sramB + ((((Address&0xFF0000)>>1) |(Address&0x7FFF)) &Multi.sramMaskB)); - } else { - return - (*(Multi.sramB + ((((Address&0xFF0000)>>1) |(Address&0x7FFF)) &Multi.sramMaskB)))| - ((*(Multi.sramB + (((((Address+1)&0xFF0000)>>1) |((Address+1)&0x7FFF)) &Multi.sramMaskB)))<<8); - } - case CMemory::MAP_RONLY_SRAM: case CMemory::MAP_HIROM_SRAM: if(Memory.SRAMMask>=MEMMAP_MASK){ @@ -378,7 +347,7 @@ INLINE uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w=WRAP_NONE) printf("reading spc7110 ROM (word) at %06X\n", Address); #endif return (S9xGetSPC7110Byte(Address)| - (S9xGetSPC7110Byte (Address+1))<<8); + (S9xGetSPC7110Byte (Address+1))<<8); case CMemory::MAP_SPC7110_DRAM: #ifdef SPC7110_DEBUG printf("reading Bank 50 (word)\n"); @@ -415,10 +384,10 @@ INLINE void S9xSetByte (uint8 Byte, uint32 Address) int block; uint8 *SetAddress = Memory.WriteMap [block = ((Address&0xffffff) >> MEMMAP_SHIFT)]; - if (!CPU.InDMAorHDMA) + if (!CPU.InDMA) CPU.Cycles += Memory.MemorySpeed [block]; - + if (SetAddress >= (uint8 *) CMemory::MAP_LAST) { #ifdef CPU_SHUTDOWN @@ -435,11 +404,11 @@ INLINE void S9xSetByte (uint8 Byte, uint32 Address) #endif return; } - + switch ((pint) SetAddress) { case CMemory::MAP_PPU: - if(CPU.InDMAorHDMA && (Address&0xff00)==0x2100) return; + if(CPU.InDMA && (Address&0xff00)==0x2100) return; S9xSetPPU (Byte, Address & 0xffff); return; @@ -462,15 +431,7 @@ INLINE void S9xSetByte (uint8 Byte, uint32 Address) } return; - case CMemory::MAP_LOROM_SRAM_B: - if (Multi.sramMaskB) - { - *(Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF))& Multi.sramMaskB))=Byte; - CPU.SRAMModified = TRUE; - } - return; - - case CMemory::MAP_HIROM_SRAM: + case CMemory::MAP_HIROM_SRAM: if (Memory.SRAMMask) { *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + @@ -565,7 +526,7 @@ INLINE void S9xSetWord (uint16 Word, uint32 Address, enum s9xwrap_t w=WRAP_NONE, int block; uint8 *SetAddress = Memory.WriteMap [block = ((Address&0xffffff) >> MEMMAP_SHIFT)]; - if (!CPU.InDMAorHDMA) + if (!CPU.InDMA) CPU.Cycles += Memory.MemorySpeed [block] << 1; @@ -589,7 +550,7 @@ INLINE void S9xSetWord (uint16 Word, uint32 Address, enum s9xwrap_t w=WRAP_NONE, switch ((pint) SetAddress) { case CMemory::MAP_PPU: - if(CPU.InDMAorHDMA){ + if(CPU.InDMA){ if((Address&0xff00)!=0x2100) S9xSetPPU((uint8)Word, Address&0xffff); if(((Address+1)&0xff00)!=0x2100) S9xSetPPU(Word>>8, (Address+1)&0xffff); return; @@ -641,32 +602,19 @@ INLINE void S9xSetWord (uint16 Word, uint32 Address, enum s9xwrap_t w=WRAP_NONE, } return; - case CMemory::MAP_LOROM_SRAM_B: - if (Multi.sramMaskB) { - if(Multi.sramMaskB>=MEMMAP_MASK){ - WRITE_WORD(Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF))&Multi.sramMaskB), Word); - } else { - *(Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF))& Multi.sramMaskB)) = (uint8) Word; - *(Multi.sramB + (((((Address+1)&0xFF0000)>>1)|((Address+1)&0x7FFF))& Multi.sramMaskB)) = Word >> 8; - } - - CPU.SRAMModified = TRUE; - } - return; - case CMemory::MAP_HIROM_SRAM: if (Memory.SRAMMask) { if(Memory.SRAMMask>=MEMMAP_MASK){ - WRITE_WORD(Memory.SRAM + + WRITE_WORD(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3) & Memory.SRAMMask)), Word); } else { /* no WRITE_WORD here, since if Memory.SRAMMask=0x7ff * then the high byte doesn't follow the low byte. */ - *(Memory.SRAM + + *(Memory.SRAM + (((Address & 0x7fff) - 0x6000 + ((Address & 0xf0000) >> 3) & Memory.SRAMMask))) = (uint8) Word; - *(Memory.SRAM + + *(Memory.SRAM + ((((Address + 1) & 0x7fff) - 0x6000 + (((Address + 1) & 0xf0000) >> 3) & Memory.SRAMMask))) = (uint8) (Word >> 8); } @@ -766,7 +714,7 @@ INLINE uint8 *GetBasePointer (uint32 Address) // { // return s7r.bank50; // } - + case CMemory::MAP_SPC7110_ROM: #ifdef SPC7110_DEBUG printf("Getting Base pointer to SPC7110ROM\n"); @@ -780,10 +728,6 @@ INLINE uint8 *GetBasePointer (uint32 Address) if((Memory.SRAMMask&MEMMAP_MASK)!=MEMMAP_MASK) return NULL; return (Memory.SRAM + ((((Address&0xFF0000)>>1)|(Address&0x7FFF)) & Memory.SRAMMask) - (Address&0xffff)); - case CMemory::MAP_LOROM_SRAM_B: - if((Multi.sramMaskB&MEMMAP_MASK)!=MEMMAP_MASK) return NULL; - return (Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF)) & Multi.sramMaskB) - (Address&0xffff)); - case CMemory::MAP_BWRAM: return (Memory.BWRAM - 0x6000 - (Address&0x8000)); @@ -822,7 +766,7 @@ INLINE uint8 *S9xGetMemPointer (uint32 Address) // { // return s7r.bank50 + (Address&0xffff); // } - + case CMemory::MAP_SPC7110_ROM: #ifdef SPC7110_DEBUG printf("Getting Mem pointer to SPC7110ROM\n"); @@ -836,10 +780,6 @@ INLINE uint8 *S9xGetMemPointer (uint32 Address) if((Memory.SRAMMask&MEMMAP_MASK)!=MEMMAP_MASK) return NULL; return (Memory.SRAM + ((((Address&0xFF0000)>>1)|(Address&0x7FFF)) & Memory.SRAMMask)); - case CMemory::MAP_LOROM_SRAM_B: - if((Multi.sramMaskB&MEMMAP_MASK)!=MEMMAP_MASK) return NULL; - return (Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF)) & Multi.sramMaskB)); - case CMemory::MAP_BWRAM: return (Memory.BWRAM - 0x6000 + (Address&0x7fff)); @@ -889,7 +829,7 @@ INLINE void S9xSetPCBase (uint32 Address) // CPU.PCBase = s7r.bank50; // return; // } - + case CMemory::MAP_SPC7110_ROM: #ifdef SPC7110_DEBUG printf("Getting Base pointer to SPC7110ROM\n"); @@ -909,14 +849,6 @@ INLINE void S9xSetPCBase (uint32 Address) } return; - case CMemory::MAP_LOROM_SRAM_B: - if((Multi.sramMaskB&MEMMAP_MASK)!=MEMMAP_MASK){ - CPU.PCBase = NULL; - } else { - CPU.PCBase = (Multi.sramB + ((((Address&0xFF0000)>>1)|(Address&0x7FFF)) & Multi.sramMaskB)) - (Address&0xffff); - } - return; - case CMemory::MAP_BWRAM: CPU.PCBase = (Memory.BWRAM - 0x6000 - (Address&0x8000)); return; @@ -936,9 +868,9 @@ INLINE void S9xSetPCBase (uint32 Address) case CMemory::MAP_OBC_RAM: CPU.PCBase = GetBasePointerOBC1(Address); return; - + case CMemory::MAP_BSX: - CPU.PCBase = S9xGetBasePointerBSX(Address); + CPU.PCBase = S9xGetPasePointerBSX(Address); return; case CMemory::MAP_DEBUG: diff --git a/source/snes9x/gfx.cpp b/source/snes9x/gfx.cpp index 027d1933..702c0b82 100644 --- a/source/snes9x/gfx.cpp +++ b/source/snes9x/gfx.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "cpuexec.h" #include "gfx.h" @@ -170,32 +151,14 @@ #include "controls.h" #include "screenshot.h" -#include "cheats.h" - -#ifndef NGC -#include "movie.h" -#endif - -#include "font.h" -static int font_width = 8; -static int font_height = 9; - -// private text-displaying functions -static void S9xDisplayPressedKeys (); -static void S9xDisplayFrameRate (); -static void S9xDisplayString (const char *string, int linesFromBottom=5, int pixelsFromLeft=1, bool allowWrap=true); #ifndef NGC -static void S9xDisplayWatchedAddresses (); +#include "cheats.h" #endif -// shared params for the above functions and DisplayChar -uint16* display_screen = NULL; -int display_ppl, display_width, display_height; -int display_fontwidth = font_width, display_fontheight = font_height, display_hfontaccessscale = 1, display_vfontaccessscale = 1; -bool8 display_paramsinited = FALSE; -#define DisplayString (S9xCustomDisplayString ? S9xCustomDisplayString : S9xDisplayString) - -void ComputeClipWindows (); +static void S9xDisplayString(const char *string); +static void S9xDisplayFrameRate(); +void ComputeClipWindows(); + extern struct SLineData LineData[240]; extern struct SLineMatrixData LineMatrixData [240]; @@ -209,7 +172,7 @@ bool8 S9xGraphicsInit(){ GFX.DoInterlace=0; GFX.InterlaceFrame=0; - Settings.BG_Forced=0; + PPU.BG_Forced=0; IPPU.OBJChanged=TRUE; IPPU.DirectColourMapsNeedRebuild=TRUE; GFX.RealPPL=GFX.Pitch>>1; @@ -280,8 +243,6 @@ bool8 S9xGraphicsInit(){ } } - GFX.Repainting = FALSE; - return TRUE; FAIL: @@ -382,7 +343,6 @@ void S9xStartScreenRefresh(){ IPPU.RenderedFramesCount = 0; IPPU.FrameCount = 0; } - ++IPPU.TotalEmulatedFrames; } void RenderLine(uint8 C) { @@ -417,71 +377,12 @@ void RenderLine(uint8 C) { } } -bool watchesCleared=false; -#ifndef NGC -void S9xDisplayWatchedAddresses () -{ - if(!watchesCleared) - { - for(unsigned int i = 0 ; i < sizeof(watches)/sizeof(*watches) ; i++) - watches[i].on = false; - watchesCleared = true; - } - - for(unsigned int i = 0 ; i < sizeof(watches)/sizeof(*watches) ; i++) - { - if(!watches[i].on) - break; - - int32 displayNumber = 0; - - extern struct SCheatData Cheat; - for(int r=0;r= 8388608) - displayNumber -= 16777216; - - sprintf(buf, "%s,%ds = %d", watches[i].desc, watches[i].size, (int)displayNumber); - } - - - DisplayString(buf, 6+i, 1, false); - } -} -#endif - -void S9xReRefresh () -{ - if(Settings.StopEmulation) - return; - - GFX.Repainting = TRUE; - S9xDeinitUpdate (IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight/*, Settings.SixteenBit*/); - GFX.Repainting = FALSE; -} - - void S9xEndScreenRefresh() { if(IPPU.RenderThisFrame) { FLUSH_REDRAW(); if(GFX.DoInterlace && GFX.InterlaceFrame==0){ S9xControlEOF(); - S9xContinueUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight); + // XXX: Invent S9xContinueUpdate()? } else { if(IPPU.ColorsChanged) { uint32 saved = PPU.CGDATA[0]; @@ -495,17 +396,19 @@ void S9xEndScreenRefresh() { S9xDoScreenshot(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight); #endif S9xControlEOF(); - - if(Settings.AutoDisplayMessages || Settings.OpenGLEnable || Settings.GlideEnable) - S9xDisplayMessages(GFX.Screen, GFX.RealPPL, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 1); - + if (Settings.DisplayFrameRate) + S9xDisplayFrameRate(); + if (GFX.InfoString) + S9xDisplayString(GFX.InfoString); S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight); } } else { S9xControlEOF(); } +#ifndef NGC S9xApplyCheats(); +#endif #ifdef DEBUGGER if(CPU.Flags & FRAME_ADVANCE_FLAG) { @@ -598,13 +501,13 @@ void S9xSetupOBJ() { } else { GFX.OBJWidths[S]=SmallWidth; Height=SmallHeight; } - int HPos=PPU.OBJ[S].HPos; if(HPos==-256) HPos=0; + int HPos=PPU.OBJ[S].HPos; if(HPos==-256) HPos=256; if(HPos>-GFX.OBJWidths[S] && HPos<=256) { if(HPos<0){ GFX.OBJVisibleTiles[S]=(GFX.OBJWidths[S]+HPos+7)>>3; - } else if(HPos+GFX.OBJWidths[S]>255){ - GFX.OBJVisibleTiles[S]=(256-HPos+7)>>3; + } else if(HPos+GFX.OBJWidths[S]>=257){ + GFX.OBJVisibleTiles[S]=(257-HPos+7)>>3; } else { GFX.OBJVisibleTiles[S]=GFX.OBJWidths[S]>>3; } @@ -1006,7 +909,7 @@ static void DrawBackgroundMosaic(int bg, uint8 Zh, uint8 Zl){ } uint32 Width = Right-Left; - HPos&=7; + uint32 f = 0; while(LeftWidth) w=Width; @@ -1024,8 +927,9 @@ static void DrawBackgroundMosaic(int bg, uint8 Zh, uint8 Zl){ } } HPos+=PPU.Mosaic; - while(HPos>=8){ - HPos-=8; + f+=PPU.Mosaic; + while(f>=8){ + f-=8; if(BG.TileSizeH==8){ t++; if(HTile==31) t=b2; @@ -1428,14 +1332,14 @@ static inline void RenderScreen(bool8 sub){ GFX.S = GFX.Screen; GFX.DB = GFX.ZBuffer; GFX.Clip = IPPU.Clip[0]; - BGActive=Memory.FillRAM[0x212c] & ~Settings.BG_Forced; + BGActive=Memory.FillRAM[0x212c] & ~PPU.BG_Forced; if(GFX.DoInterlace && GFX.InterlaceFrame) GFX.S+=GFX.RealPPL; D=32; } else { GFX.S = GFX.SubScreen; GFX.DB = GFX.SubZBuffer; GFX.Clip = IPPU.Clip[1]; - BGActive=Memory.FillRAM[0x212d] & ~Settings.BG_Forced; + BGActive=Memory.FillRAM[0x212d] & ~PPU.BG_Forced; D=(Memory.FillRAM[0x2130]&2)<<4; // 'do math' depth flag } @@ -1619,291 +1523,76 @@ void S9xUpdateScreen() { IPPU.PreviousLine = IPPU.CurrentLine; } -extern bool unfreezing_from_stream; void S9xSetInfoString (const char *string) { - if(Settings.InitialInfoStringTimeout > 0) - { - GFX.InfoString = string; - GFX.InfoStringTimeout = Settings.InitialInfoStringTimeout; - - if (Settings.Paused && !unfreezing_from_stream) - { - //refresh screen to show new message immediately - S9xReRefresh(); - } - } + GFX.InfoString = string; + GFX.InfoStringTimeout = 120; } -static inline void FontPixToScreen(char p, uint16 *s) -{ - if(p == '#') - { - *s = Settings.DisplayColor; - } - else if(p == '.') - { - static const uint16 black = BUILD_PIXEL(0,0,0); - *s = black; - } -} +#include "font.h" void DisplayChar(uint16 *s, uint8 c) { - int line = ((c - 32) >> 4) * display_fontheight; - int offset = ((c - 32) & 15) * display_fontwidth; - int h, w; - if(!display_paramsinited) display_ppl = Settings.OpenGLEnable ? IPPU.RenderedScreenWidth : GFX.RealPPL; - if(display_hfontaccessscale == 1 && display_vfontaccessscale == 1) { - for(h=0; h> 4) * font_height; + int offset = ((c - 32) & 15) * font_width; + int h, w, rws; + rws = Settings.OpenGLEnable ? IPPU.RenderedScreenWidth : GFX.RealPPL; + for(h=0; h max_chars && !allowWrap && display_hfontaccessscale > 1) - { - display_fontwidth /= display_hfontaccessscale; - display_hfontaccessscale--; - display_fontwidth *= display_hfontaccessscale; - - max_chars = display_width / (display_fontwidth-display_hfontaccessscale); - } - - // loop through and draw the characters - for(int i = 0 ; i < len ; i++, char_count++) - { - if(char_count >= max_chars || (unsigned char)string[i] < 32) - { - if(!allowWrap) - break; - - Screen -= /*Settings.SixteenBit ? (display_fontwidth-display_hfontaccessscale)*sizeof(uint16)*max_chars :*/ (display_fontwidth-display_hfontaccessscale)*max_chars; - Screen += display_fontheight * display_ppl; - if(Screen >= display_screen + display_ppl * display_height) - break; - - char_count -= max_chars; - } - if((unsigned char) string[i]<32) continue; - - DisplayChar(Screen, string[i]); - Screen += /*Settings.SixteenBit ? (display_fontwidth-display_hfontaccessscale)*sizeof(uint16) :*/ (display_fontwidth-display_hfontaccessscale); - } - - // revert temporary change to font scale, if any - if(display_hfontaccessscale != prev_hfont_access_scale) - { - display_hfontaccessscale = prev_hfont_access_scale; - display_fontwidth *= display_hfontaccessscale; - } + int i; + for(i=0; i','<','v','^','S','s','Y','B'}; - const static int KeyOrder[]={8,10,7,9, 0, 6,14,13,5, 1, 4,3, 2, 11,12}; // < ^ > v A B Y X L R S s -#endif - char string[255]; - int len; - - S9xGetController(1, &controller, &ids[0],&ids[1],&ids[2],&ids[3]); -#ifndef NGC - bool singlePlayer = (controller == CTL_NONE || (controller == CTL_JOYPAD && !(MovieGetJoypad(1) & 0xffff))); -#else - bool singlePlayer = (controller == CTL_NONE || (controller == CTL_JOYPAD)); -#endif - for(int port = 0; port < 2; port++) - { - S9xGetController(port, &controller, &ids[0],&ids[1],&ids[2],&ids[3]); - for(int idid = 0; idid < 4; idid++) - { - const int id = ids[idid]; - if(id == -1) - continue; - - bool skip = false; - switch(controller) - { - default: { - skip = true; - } break; - - case CTL_MP5: - singlePlayer = false; - // no break: - case CTL_JOYPAD: { - if(line < id+1) - line = id+1; -#ifndef NGC - uint16 tempJoypad = MovieGetJoypad(id); - if(!(tempJoypad & 0xffff) && id > 0) - skip = true; - else - { - sprintf(string, !singlePlayer?"P%d: ":" ",id+1); - - for (int i=0; i < 15; i++) - { - int j = KeyOrder[i]; - int mask = (1 << (j+1)); - string[strlen("P?: ")+i]= ((tempJoypad & mask)!=0) ? KeyMap[j] : ' '; - } - } -#endif - } break; - - case CTL_MOUSE: { -#ifndef NGC - uint8 buf [5] = {0}; - MovieGetMouse(id, buf); - int16 x = ((uint16*)buf)[0]; - int16 y = ((uint16*)buf)[1]; - uint8 buttons = buf[4]; - //if(delta_x < 0) delta_x = 128|-delta_x; - //if(delta_y < 0) delta_y = 128|-delta_y; - sprintf(string, "(%4d,%4d) %c%c", x, y, (buttons&0x40)?'L':' ', (buttons&0x80)?'R':' '); -#endif - } break; - - case CTL_SUPERSCOPE: { -#ifndef NGC - uint8 buf [6] = {0}; - MovieGetScope(id, buf); - int16 x = ((uint16*)buf)[0]; - int16 y = ((uint16*)buf)[1]; - uint8 buttons = buf[4]; - sprintf(string, "(%3d,%3d) %c%c%c%c", x, y, (buttons&0x80)?'F':' ', (buttons&0x40)?'C':' ', (buttons&0x20)?'T':' ', (buttons&0x10)?'P':' '); -#endif - } break; - - case CTL_JUSTIFIER: { -#ifndef NGC - uint8 buf [11] = {0}; - MovieGetJustifier(port, buf); - int16 x1 = ((uint16*)buf)[0]; - int16 x2 = ((uint16*)buf)[1]; - int16 y1 = ((uint16*)buf)[2]; - int16 y2 = ((uint16*)buf)[3]; - uint8 buttons = buf[8]; - bool8 offscreen1 = buf[9]; - bool8 offscreen2 = buf[10]; - if(id == 1) - sprintf(string, "(%3d,%3d) %c%c%c / (%3d,%3d) %c%c%c", x1, y1, (buttons&0x80)?'T':' ', (buttons&0x20)?'S':' ', offscreen1?'O':' ', x2, y2, (buttons&0x40)?'T':' ', (buttons&0x10)?'S':' ', offscreen2?'O':' '); - else - sprintf(string, "(%3d,%3d) %c%c%c", x1, y1, (buttons&0x80)?'T':' ', (buttons&0x20)?'S':' ', offscreen1?'O':' '); -#endif - } break; - } - - if(skip) - continue; - - len=strlen(string); - - DisplayString(string, line, 1, false); - - line++; - } +static void S9xDisplayString(const char *string) { + uint16 *Screen = GFX.Screen + 1 + + (IPPU.RenderedScreenHeight - font_height * 5) * GFX.RealPPL; + int len = strlen (string); + int max_chars = IPPU.RenderedScreenWidth / (font_width - 1); + int char_count = 0; + int i; + + for(i=0; i= max_chars || (unsigned char) string [i] < 32) { + Screen -= (font_width - 1) * max_chars; + Screen += font_height * GFX.RealPPL; + if(Screen >= GFX.Screen+GFX.RealPPL*IPPU.RenderedScreenHeight) + break; + char_count -= max_chars; } -} - -void S9xDisplayMessages(uint16 *screen, int ppl, int width, int height, int scale) -{ - display_screen = screen; - display_ppl = ppl; - display_width = width; - display_height = height; - display_fontwidth = font_width * scale; - display_fontheight = font_height * scale; - display_hfontaccessscale = scale; - display_vfontaccessscale = scale; - display_paramsinited = TRUE; - - if (Settings.DisplayFrameRate) - S9xDisplayFrameRate(); - - if (Settings.DisplayPressedKeys==2) - S9xDisplayPressedKeys(); - - if (GFX.FrameDisplay -#ifndef NGC - && S9xMovieActive() -#endif -#ifdef NETPLAY_SUPPORT - || Settings.NetPlay -#endif - ) - DisplayString(GFX.FrameDisplayString, 4, 1, false); - - if (GFX.InfoString && *GFX.InfoString) - DisplayString(GFX.InfoString, 5, 1, !GFX.FrameDisplay -#ifndef NGC -|| (!S9xMovieActive() -#ifdef NETPLAY_SUPPORT - && !Settings.NetPlay -#endif - ) -#endif - ); - -#ifndef NGC - if (Settings.DisplayWatchedAddresses) - S9xDisplayWatchedAddresses(); -#endif - display_paramsinited = FALSE; - display_fontwidth = font_width; - display_fontheight = font_height; - display_hfontaccessscale = 1; - display_vfontaccessscale = 1; + if((unsigned char) string[i]<32) continue; + DisplayChar(Screen, string [i]); + Screen += font_width-1; + } } #include "crosshairs.h" @@ -1924,7 +1613,7 @@ static uint16 get_crosshair_color(uint8 color){ case 11: return BUILD_PIXEL(0,23,31); // Sky case 12: return BUILD_PIXEL(0,0,31); // Blue case 13: return BUILD_PIXEL(23,0,31); // Violet - case 14: return BUILD_PIXEL(31,0,31); // Magenta + case 14: return BUILD_PIXEL(31,0,31); // MagicPink case 15: return BUILD_PIXEL(31,0,16); // Purple } return 0; // stupid compiler warning @@ -1938,33 +1627,26 @@ void S9xDrawCrosshair(const char *crosshair, uint8 fgcolor, uint8 bgcolor, int16 if(IPPU.DoubleWidthPixels){ cx=2; x*=2; W*=2; } if(IPPU.DoubleHeightPixels){ rx=2; y*=2; H*=2; } if(crosshair==NULL) return; - if(GFX.Screen==NULL) return; - if(Settings.StopEmulation) return; uint16 fg, bg; fg=get_crosshair_color(fgcolor); bg=get_crosshair_color(bgcolor); -#if (defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP)) // XXX: FIXME: why does it crash without this on Linux port? There are no out-of-bound writes without it... - if(x >= 0 && y >= 0) -#endif - { - uint16 *s = GFX.Screen + y * GFX.RealPPL + x; - rws = Settings.OpenGLEnable ? IPPU.RenderedScreenWidth : GFX.RealPPL; - for(r=0; r<15*rx; r++, s+=rws-15*cx) { - if(y+r<0){ s+=15*cx; continue; } // if y is negative, skip line - if(y+r>=H) break; // if y is past bottom, stop - for(c=0; c<15*cx; c++, s++) { - if(x+c<0 || s=W){ s+=15*cx-c; break; } // if x is past right, go to next line - uint8 p = crosshair[(r/rx)*15+(c/cx)]; - - if(p == '#' && fgcolor) { - *s=(fgcolor&0x10)?COLOR_ADD1_2(fg,*s):fg; - } else if(p == '.' && bgcolor) { - *s=(bgcolor&0x10)?COLOR_ADD1_2(*s,bg):bg; - } - } - } - } + uint16 *s = GFX.Screen + y * GFX.RealPPL + x; + rws = Settings.OpenGLEnable ? IPPU.RenderedScreenWidth : GFX.RealPPL; + for(r=0; r<15*rx; r++, s+=rws-15*cx) { + if(y+r<0){ s+=15*cx; continue; } + if(y+r>=H) break; + for(c=0; c<15*cx; c++, s++) { + if(x+c<0) continue; + if(x+c>=W){ s+=15*cx-c; break; } + uint8 p = crosshair[(r/rx)*15+(c/cx)]; + + if(p == '#' && fgcolor) { + *s=(fgcolor&0x10)?COLOR_ADD1_2(fg,*s):fg; + } else if(p == '.' && bgcolor) { + *s=(bgcolor&0x10)?COLOR_ADD1_2(*s,bg):bg; + } + } + } } @@ -2062,4 +1744,3 @@ bool8 S9xSetRenderPixelFormat (int format) } #endif -void (*S9xCustomDisplayString) (const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap) = NULL; diff --git a/source/snes9x/gfx.h b/source/snes9x/gfx.h index 248885e5..980ecd66 100644 --- a/source/snes9x/gfx.h +++ b/source/snes9x/gfx.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _GFX_H_ #define _GFX_H_ @@ -194,9 +175,6 @@ struct SGFX{ uint32 FixedColour; const char *InfoString; uint32 InfoStringTimeout; - char FrameDisplayString[256]; - bool8 FrameDisplay; - bool8 Repainting; // True if the frame is being re-drawn uint8 DoInterlace; uint8 InterlaceFrame; uint32 StartY; @@ -264,7 +242,7 @@ struct SBG { uint32 PaletteMask; uint8 EnableMath; uint8 InterlaceLine; - + uint8 *Buffer, *BufferFlip; uint8 *Buffered, *BufferedFlip; bool8 DirectColourMode; @@ -309,7 +287,7 @@ GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \ (GFX.X2 [((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \ ((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \ ((C1) & (C2) & RGB_LOW_BITS_MASK)] | \ - (((C1) ^ (C2)) & RGB_LOW_BITS_MASK)) + (((C1) ^ (C2)) & RGB_LOW_BITS_MASK)) #endif #define COLOR_ADD1_2(C1, C2) \ @@ -336,7 +314,7 @@ inline uint16 COLOR_SUB(uint16 C1, uint16 C2) mC1 = C1 & FIRST_COLOR_MASK; mC2 = C2 & FIRST_COLOR_MASK; if (mC1 > mC2) v += (mC1 - mC2); - + mC1 = C1 & SECOND_COLOR_MASK; mC2 = C2 & SECOND_COLOR_MASK; if (mC1 > mC2) v += (mC1 - mC2); @@ -344,7 +322,7 @@ inline uint16 COLOR_SUB(uint16 C1, uint16 C2) mC1 = C1 & THIRD_COLOR_MASK; mC2 = C2 & THIRD_COLOR_MASK; if (mC1 > mC2) v += (mC1 - mC2); - + return v; } #endif @@ -362,22 +340,17 @@ void S9xUpdateScreen (); void RenderLine (uint8 line); void S9xBuildDirectColourMaps (); -void S9xDisplayMessages (uint16 *screen, int ppl, int width, int height, int scale); // called automatically unless Settings.AutoDisplayMessages is false - -extern struct SGFX GFX; - // External port interface which must be implemented or initialised for each // port. +extern struct SGFX GFX; + bool8 S9xGraphicsInit (); void S9xGraphicsDeinit(); bool8 S9xInitUpdate (void); bool8 S9xDeinitUpdate (int Width, int Height); -bool8 S9xContinueUpdate (int Width, int Height); void S9xSetPalette (); void S9xSyncSpeed (); -extern void (*S9xCustomDisplayString) (const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap); // called instead of S9xDisplayString if set to non-NULL - #ifdef GFX_MULTI_FORMAT bool8 S9xSetRenderPixelFormat (int format); #endif diff --git a/source/snes9x/globals.cpp b/source/snes9x/globals.cpp index e031e810..07fe15f4 100644 --- a/source/snes9x/globals.cpp +++ b/source/snes9x/globals.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,7 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - +#define _GLOBALS_CPP #include "snes9x.h" #include "memmap.h" @@ -174,16 +156,20 @@ #include "gfx.h" #include "soundux.h" +#ifndef NGC #include "cheats.h" +#endif #include "sa1.h" #include "bsx.h" -#include "spc7110.h" + #ifdef NETPLAY_SUPPORT #include "netplay.h" #endif -START_EXTERN_C +#include "spc7110.h" + +//START_EXTERN_C char String[513]; struct Missing missing; @@ -212,28 +198,25 @@ struct SSA1 SA1; struct SBSX BSX; -struct SMulti Multi; - SSoundData SoundData; SnesModel M1SNES={1,3,2}; SnesModel M2SNES={2,4,3}; SnesModel* Model=&M1SNES; -#if defined(ZSNES_FX) || defined(ZSNES_C4) -uint8 *ROM = NULL; + uint8 *SRAM = NULL; +uint8 *ROM = NULL; uint8 *RegRAM = NULL; -#endif CMemory Memory; -struct SSNESGameFixes SNESGameFixes; +SSNESGameFixes SNESGameFixes; unsigned char OpenBus = 0; -END_EXTERN_C +//END_EXTERN_C #ifndef ZSNES_FX struct FxInit_s SuperFX; @@ -270,7 +253,7 @@ uint32 MAX_GREEN = MAX_GREEN_RGB565; uint32 MAX_BLUE = MAX_BLUE_RGB565; uint32 SPARE_RGB_BIT_MASK = SPARE_RGB_BIT_MASK_RGB565; uint32 GREEN_HI_BIT = (MAX_GREEN_RGB565 + 1) >> 1; -uint32 RGB_LOW_BITS_MASK = (RED_LOW_BIT_MASK_RGB565 | +uint32 RGB_LOW_BITS_MASK = (RED_LOW_BIT_MASK_RGB565 | GREEN_LOW_BIT_MASK_RGB565 | BLUE_LOW_BIT_MASK_RGB565); uint32 RGB_HI_BITS_MASK = (RED_HI_BIT_MASK_RGB565 | @@ -293,7 +276,9 @@ uint32 current_graphic_format = RGB565; uint8 GetBank = 0; +#ifndef NGC struct SCheatData Cheat; +#endif volatile SoundStatus so; @@ -348,7 +333,7 @@ struct SNetPlay NetPlay; #endif // Raw SPC700 instruction cycle lengths -int32 S9xAPUCycleLengths [256] = +int32 S9xAPUCycleLengths [256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* 00 */ 2, 8, 4, 5, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, diff --git a/source/snes9x/language.h b/source/snes9x/language.h index 3bf22f95..91aa32fd 100644 --- a/source/snes9x/language.h +++ b/source/snes9x/language.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,30 +142,22 @@ **********************************************************************************/ - - /* This file is for core emulator messages. Use a port-specific file for * * GUI strings and the like. Thank you. */ /* Movie Messages */ -#define MOVIE_ERR_SNAPSHOT_WRONG_MOVIE "Snapshot not from this movie" -#define MOVIE_ERR_SNAPSHOT_NOT_MOVIE "Not a movie snapshot" #define MOVIE_INFO_REPLAY "Movie replay" #define MOVIE_INFO_RECORD "Movie record" #define MOVIE_INFO_RERECORD "Movie re-record" #define MOVIE_INFO_REWIND "Movie rewind" #define MOVIE_INFO_STOP "Movie stop" #define MOVIE_INFO_END "Movie end" -#define MOVIE_INFO_SNAPSHOT "Movie snapshot" -#define MOVIE_ERR_SNAPSHOT_INCONSISTENT "Snapshot inconsistent with movie" - -/* Snapshot Messages */ - -#define SAVE_INFO_SNAPSHOT "Saved" -#define SAVE_INFO_LOAD "Loaded" -#define SAVE_ERR_WRONG_FORMAT "File not in Snes9x freeze format" -#define SAVE_ERR_WRONG_VERSION "Incompatable Snes9x freeze file format version" -#define SAVE_ERR_ROM_NOT_FOUND "ROM image \"%s\" for freeze file not found" -#define SAVE_ERR_SAVE_NOT_FOUND "Save file %s does not exist." - +#define MOVIE_INFO_RECORDING_ENABLED "Recording enabled" +#define MOVIE_INFO_RECORDING_DISABLED "Recording disabled" +#define MOVIE_ERR_SNAPSHOT_WRONG_MOVIE "Snapshot not from this movie" +#define MOVIE_ERR_SNAPSHOT_NOT_MOVIE "Not a movie snapshot" +#define MOVIE_ERR_COULD_NOT_OPEN "Could not open movie file." +#define MOVIE_ERR_NOT_FOUND "File not found." +#define MOVIE_ERR_WRONG_FORMAT "File is wrong format." +#define MOVIE_ERR_WRONG_VERSION "File is wrong version." diff --git a/source/snes9x/memmap.cpp b/source/snes9x/memmap.cpp index 5f317da2..b389e9d9 100644 --- a/source/snes9x/memmap.cpp +++ b/source/snes9x/memmap.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,9 +142,6 @@ **********************************************************************************/ - -#include - #include #ifdef HAVE_STRINGS_H #include @@ -173,795 +153,785 @@ #include #endif -#ifdef __W32_HEAP -#include +#ifdef JMA_SUPPORT +#include "jma/s9x-jma.h" #endif +#include "snes9x.h" #include "memmap.h" -#include "display.h" #include "cpuexec.h" #include "ppu.h" +#include "display.h" + +#ifndef NGC +#include "cheats.h" +#endif + #include "apu.h" -#include "dsp1.h" #include "sa1.h" +#include "dsp1.h" +#include "srtc.h" #include "sdd1.h" #include "spc7110.h" #include "seta.h" -#include "srtc.h" #include "bsx.h" - #ifndef NGC #include "reader.h" -#include "cheats.h" #else #include - -extern unsigned long SNESROMSize; +#include "aram.h" /*** Nintendo GameCube ARAM loader. + FileLoader requires that the ROM is preloaded in ARAM first + ***/ +extern unsigned long ARAM_ROMSIZE; +extern int hasloaded; #endif #include "controls.h" -//#include "movie.h" - -#ifndef ZSNES_FX -#include "fxemu.h" -#endif #ifdef UNZIP_SUPPORT #include "unzip.h" #endif -#ifdef JMA_SUPPORT -#include "jma/s9x-jma.h" -#endif - -#ifdef __WIN32__ -#ifndef _XBOX -#include "win32/wsnes9x.h" // FIXME: shouldn't be necessary -#endif +#ifdef __W32_HEAP +#include #endif -#ifdef __WIN32__ -#define snprintf _snprintf // needs ANSI compliant name +#ifndef ZSNES_FX +#include "fxemu.h" +extern struct FxInit_s SuperFX; +#else +START_EXTERN_C +extern uint8 *SFXPlotTable; +END_EXTERN_C #endif #ifndef SET_UI_COLOR #define SET_UI_COLOR(r,g,b) ; #endif +//you would think everyone would have these +//since they're so useful. #ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef ZSNES_FX -extern struct FxInit_s SuperFX; -#else -EXTERN_C uint8 *SFXPlotTable; +#define min(a,b) (((a) < (b)) ? (a) : (b)) #endif -static bool8 stopMovie = TRUE; -static char LastRomFilename[_MAX_PATH + 1] = ""; - -static const uint32 crc32Table[256] = -{ - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +static int retry_count=0; +void S9xDeinterleaveType2 (bool8 reset=TRUE); +inline uint32 caCRC32(uint8 *array, uint32 size, register uint32 crc32 = 0xFFFFFFFF); + +extern char *rom_filename; + +const uint32 crc32Table[256] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -static void S9xDeinterleaveType1 (int, uint8 *); -static void S9xDeinterleaveType2 (int, uint8 *); -static void S9xDeinterleaveGD24 (int, uint8 *); -static bool8 allASCII (uint8 *, int); -static bool8 is_SufamiTurbo_BIOS (uint8 *, uint32); -static bool8 is_SufamiTurbo_Cart (uint8 *, uint32); -static bool8 is_SameGame_BIOS (uint8 *, uint32); -static bool8 is_SameGame_Add_On (uint8 *, uint32); -static uint32 caCRC32 (uint8 *, uint32, uint32 crc32 = 0xffffffff); -#ifndef NGC -static long ReadInt (Reader *, unsigned); -static bool8 ReadIPSPatch (Reader *, long, int32 &); -static int unzFindExtension (unzFile &, const char *, bool restart = TRUE, bool print = TRUE); -#endif -// deinterleave -static void S9xDeinterleaveType1 (int size, uint8 *base) + +void S9xDeinterleaveType1(int TotalFileSize, uint8 * base) { - if (Settings.DisplayColor == 0xffff) + if(Settings.DisplayColor==0xffff) { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); + Settings.DisplayColor=BUILD_PIXEL(0,31,0); + SET_UI_COLOR(0,255,0); } - uint8 blocks[256]; - int nblocks = size >> 16; - - for (int i = 0; i < nblocks; i++) + int i; + int nblocks = TotalFileSize >> 16; + uint8 blocks [256]; + for (i = 0; i < nblocks; i++) { - blocks[i * 2] = i + nblocks; - blocks[i * 2 + 1] = i; + blocks [i * 2] = i + nblocks; + blocks [i * 2 + 1] = i; } - - uint8 *tmp = (uint8 *) malloc(0x8000); + uint8 *tmp = (uint8 *) malloc (0x8000); if (tmp) { - for (int i = 0; i < nblocks * 2; i++) + for (i = 0; i < nblocks * 2; i++) { for (int j = i; j < nblocks * 2; j++) { - if (blocks[j] == i) + if (blocks [j] == i) { - memmove(tmp, &base[blocks[j] * 0x8000], 0x8000); - memmove(&base[blocks[j] * 0x8000], &base[blocks[i] * 0x8000], 0x8000); - memmove(&base[blocks[i] * 0x8000], tmp, 0x8000); - uint8 b = blocks[j]; - blocks[j] = blocks[i]; - blocks[i] = b; + memmove (tmp, &base [blocks [j] * 0x8000], 0x8000); + memmove (&base [blocks [j] * 0x8000], + &base [blocks [i] * 0x8000], 0x8000); + memmove (&base [blocks [i] * 0x8000], tmp, 0x8000); + uint8 b = blocks [j]; + blocks [j] = blocks [i]; + blocks [i] = b; break; } } } - - free(tmp); + free ((char *) tmp); } } -static void S9xDeinterleaveType2 (int size, uint8 *base) +void S9xDeinterleaveGD24(int TotalFileSize, uint8 * base) { - // for odd Super FX images - if (Settings.DisplayColor == 0xffff || Settings.DisplayColor == BUILD_PIXEL(0, 31, 0)) - { - Settings.DisplayColor = BUILD_PIXEL(31, 14, 6); - SET_UI_COLOR(255, 119, 25); - } - - uint8 blocks[256]; - int nblocks = size >> 16; - int step = 64; - - while (nblocks <= step) - step >>= 1; - nblocks = step; - for (int i = 0; i < nblocks * 2; i++) - blocks[i] = (i & ~0xf) | ((i & 3) << 2) | ((i & 12) >> 2); - - uint8 *tmp = (uint8 *) malloc(0x10000); - if (tmp) - { - for (int i = 0; i < nblocks * 2; i++) - { - for (int j = i; j < nblocks * 2; j++) - { - if (blocks[j] == i) - { - memmove(tmp, &base[blocks[j] * 0x10000], 0x10000); - memmove(&base[blocks[j] * 0x10000], &base[blocks[i] * 0x10000], 0x10000); - memmove(&base[blocks[i] * 0x10000], tmp, 0x10000); - uint8 b = blocks[j]; - blocks[j] = blocks[i]; - blocks[i] = b; - break; - } - } - } - - free(tmp); - } -} - -static void S9xDeinterleaveGD24 (int size, uint8 *base) -{ - // for 24Mb images dumped with Game Doctor - if (size != 0x300000) + if(TotalFileSize!=0x300000) return; - if (Settings.DisplayColor == 0xffff) + if(Settings.DisplayColor==0xffff) { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 31); - SET_UI_COLOR(0, 255, 255); + Settings.DisplayColor=BUILD_PIXEL(0,31,31); + SET_UI_COLOR(0,255,255); } - uint8 *tmp = (uint8 *) malloc(0x80000); + uint8 *tmp = (uint8 *) malloc (0x80000); if (tmp) { memmove(tmp, &base[0x180000], 0x80000); memmove(&base[0x180000], &base[0x200000], 0x80000); memmove(&base[0x200000], &base[0x280000], 0x80000); memmove(&base[0x280000], tmp, 0x80000); + free ((char *) tmp); - free(tmp); - - S9xDeinterleaveType1(size, base); + S9xDeinterleaveType1(TotalFileSize, base); } } -// allocation and deallocation - -bool8 CMemory::Init (void) +bool8 CMemory::AllASCII (uint8 *b, int size) { - RAM = (uint8 *) malloc(0x20000); - SRAM = (uint8 *) malloc(0x20000); - VRAM = (uint8 *) malloc(0x10000); - ROM = (uint8 *) malloc(MAX_ROM_SIZE + 0x200 + 0x8000); - - IPPU.TileCache[TILE_2BIT] = (uint8 *) malloc(MAX_2BIT_TILES * 64); - IPPU.TileCache[TILE_4BIT] = (uint8 *) malloc(MAX_4BIT_TILES * 64); - IPPU.TileCache[TILE_8BIT] = (uint8 *) malloc(MAX_8BIT_TILES * 64); - IPPU.TileCache[TILE_2BIT_EVEN] = (uint8 *) malloc(MAX_2BIT_TILES * 64); - IPPU.TileCache[TILE_2BIT_ODD] = (uint8 *) malloc(MAX_2BIT_TILES * 64); - IPPU.TileCache[TILE_4BIT_EVEN] = (uint8 *) malloc(MAX_4BIT_TILES * 64); - IPPU.TileCache[TILE_4BIT_ODD] = (uint8 *) malloc(MAX_4BIT_TILES * 64); - - IPPU.TileCached[TILE_2BIT] = (uint8 *) malloc(MAX_2BIT_TILES); - IPPU.TileCached[TILE_4BIT] = (uint8 *) malloc(MAX_4BIT_TILES); - IPPU.TileCached[TILE_8BIT] = (uint8 *) malloc(MAX_8BIT_TILES); - IPPU.TileCached[TILE_2BIT_EVEN] = (uint8 *) malloc(MAX_2BIT_TILES); - IPPU.TileCached[TILE_2BIT_ODD] = (uint8 *) malloc(MAX_2BIT_TILES); - IPPU.TileCached[TILE_4BIT_EVEN] = (uint8 *) malloc(MAX_4BIT_TILES); - IPPU.TileCached[TILE_4BIT_ODD] = (uint8 *) malloc(MAX_4BIT_TILES); - - if (!RAM || !SRAM || !VRAM || !ROM || - !IPPU.TileCache[TILE_2BIT] || - !IPPU.TileCache[TILE_4BIT] || - !IPPU.TileCache[TILE_8BIT] || - !IPPU.TileCache[TILE_2BIT_EVEN] || - !IPPU.TileCache[TILE_2BIT_ODD] || - !IPPU.TileCache[TILE_4BIT_EVEN] || - !IPPU.TileCache[TILE_4BIT_ODD] || - !IPPU.TileCached[TILE_2BIT] || - !IPPU.TileCached[TILE_4BIT] || - !IPPU.TileCached[TILE_8BIT] || - !IPPU.TileCached[TILE_2BIT_EVEN] || - !IPPU.TileCached[TILE_2BIT_ODD] || - !IPPU.TileCached[TILE_4BIT_EVEN] || - !IPPU.TileCached[TILE_4BIT_ODD]) - { - Deinit(); - return (FALSE); + for (int i = 0; i < size; i++) + { + if (b[i] < 32 || b[i] > 126) + return (FALSE); } + return (TRUE); +} + +int CMemory::ScoreHiROM (bool8 skip_header, int32 romoff) +{ + int score = 0; + int o = skip_header ? 0xff00 + 0x200 : 0xff00; + + o+=romoff; + + if(Memory.ROM [o + 0xd5] & 0x1) + score+=2; + + //Mode23 is SA-1 + if(Memory.ROM [o + 0xd5] == 0x23) + score-=2; + + if(Memory.ROM [o+0xd4] == 0x20) + score +=2; + + if ((Memory.ROM [o + 0xdc] + (Memory.ROM [o + 0xdd] << 8) + + Memory.ROM [o + 0xde] + (Memory.ROM [o + 0xdf] << 8)) == 0xffff) + { + score += 2; + if(0!=(Memory.ROM [o + 0xde] + (Memory.ROM [o + 0xdf] << 8))) + score++; + } + + if (Memory.ROM [o + 0xda] == 0x33) + score += 2; + if ((Memory.ROM [o + 0xd5] & 0xf) < 4) + score += 2; + if (!(Memory.ROM [o + 0xfd] & 0x80)) + score -= 6; + if ((Memory.ROM [o + 0xfc]|(Memory.ROM [o + 0xfd]<<8))>0xFFB0) + score -= 2; //reduced after looking at a scan by Cowering + if (CalculatedSize > 1024 * 1024 * 3) + score += 4; + if ((1 << (Memory.ROM [o + 0xd7] - 7)) > 48) + score -= 1; + if (!AllASCII (&Memory.ROM [o + 0xb0], 6)) + score -= 1; + if (!AllASCII (&Memory.ROM [o + 0xc0], ROM_NAME_LEN - 1)) + score -= 1; + + return (score); +} - ZeroMemory(RAM, 0x20000); - ZeroMemory(SRAM, 0x20000); - ZeroMemory(VRAM, 0x10000); - ZeroMemory(ROM, MAX_ROM_SIZE + 0x200 + 0x8000); +int CMemory::ScoreLoROM (bool8 skip_header, int32 romoff) +{ + int score = 0; + int o = skip_header ? 0x7f00 + 0x200 : 0x7f00; + + o+=romoff; - ZeroMemory(IPPU.TileCache[TILE_2BIT], MAX_2BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_4BIT], MAX_4BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_8BIT], MAX_8BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_2BIT_EVEN], MAX_2BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_2BIT_ODD], MAX_2BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_4BIT_EVEN], MAX_4BIT_TILES * 64); - ZeroMemory(IPPU.TileCache[TILE_4BIT_ODD], MAX_4BIT_TILES * 64); + if(!(Memory.ROM [o + 0xd5] & 0x1)) + score+=3; - ZeroMemory(IPPU.TileCached[TILE_2BIT], MAX_2BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_4BIT], MAX_4BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_8BIT], MAX_8BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_2BIT_EVEN], MAX_2BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_2BIT_ODD], MAX_2BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_4BIT_EVEN], MAX_4BIT_TILES); - ZeroMemory(IPPU.TileCached[TILE_4BIT_ODD], MAX_4BIT_TILES); + //Mode23 is SA-1 + if(Memory.ROM [o + 0xd5] == 0x23) + score+=2; - // FillRAM uses first 32K of ROM image area, otherwise space just - // wasted. Might be read by the SuperFX code. + if ((Memory.ROM [o + 0xdc] + (Memory.ROM [o + 0xdd] << 8) + + Memory.ROM [o + 0xde] + (Memory.ROM [o + 0xdf] << 8)) == 0xffff) + { + score += 2; + if(0!=(Memory.ROM [o + 0xde] + (Memory.ROM [o + 0xdf] << 8))) + score++; + } + + if (Memory.ROM [o + 0xda] == 0x33) + score += 2; + if ((Memory.ROM [o + 0xd5] & 0xf) < 4) + score += 2; + if (CalculatedSize <= 1024 * 1024 * 16) + score += 2; + if (!(Memory.ROM [o + 0xfd] & 0x80)) + score -= 6; + if ((Memory.ROM [o + 0xfc]|(Memory.ROM [o + 0xfd]<<8))>0xFFB0) + score -= 2;//reduced per Cowering suggestion + if ((1 << (Memory.ROM [o + 0xd7] - 7)) > 48) + score -= 1; + if (!AllASCII (&Memory.ROM [o + 0xb0], 6)) + score -= 1; + if (!AllASCII (&Memory.ROM [o + 0xc0], ROM_NAME_LEN - 1)) + score -= 1; + + return (score); +} - FillRAM = ROM; +char *CMemory::Safe (const char *s) +{ + static char *safe; + static int safe_len = 0; - // Add 0x8000 to ROM image pointer to stop SuperFX code accessing - // unallocated memory (can cause crash on some ports). + if(s==NULL) + { + if(safe!=NULL) + { + free((char*)safe); + safe = NULL; + } + return NULL; + } + int len = strlen (s); + if (!safe || len + 1 > safe_len) + { + if (safe) + free ((char *) safe); + safe = (char *) malloc (safe_len = len + 1); + } + + for (int i = 0; i < len; i++) + { + if (s [i] >= 32 && s [i] < 127) + safe [i] = s[i]; + else + safe [i] = '?'; + } + safe [len] = 0; + return (safe); +} - ROM += 0x8000; +char *CMemory::SafeANK (const char *s) +{ + static char *safe; + static int safe_len = 0; - C4RAM = ROM + 0x400000 + 8192 * 8; // C4 - BIOSROM = ROM + 0x300000; // BS - BSRAM = ROM + 0x400000; // BS + if(s==NULL) + { + if(safe!=NULL) + { + free((char*)safe); + safe = NULL; + } + return NULL; + } + int len = strlen (s); + if (!safe || len + 1 > safe_len) + { + if (safe) + free ((char *) safe); + safe = (char *) malloc (safe_len = len + 1); + } + + for (int i = 0; i < len; i++) + { + if (s [i] >= 32 && s [i] < 127) // ASCII + safe [i] = s[i]; + else + if (Memory.ROMRegion == 0 && ((unsigned char) s[i] >= 0xa0 && (unsigned char) s[i] < 0xe0)) // JIS X 201 + safe [i] = s[i]; + else + safe [i] = '?'; + + } + safe [len] = 0; + return (safe); +} -#if defined(ZSNES_FX) || defined(ZSNES_C4) +/**********************************************************************************************/ +/* Init() */ +/* This function allocates all the memory needed by the emulator */ +/**********************************************************************************************/ +bool8 CMemory::Init () +{ + RAM = (uint8 *) malloc (0x20000); + SRAM = (uint8 *) malloc (0x20000); + VRAM = (uint8 *) malloc (0x10000); + ROM = (uint8 *) malloc (MAX_ROM_SIZE + 0x200 + 0x8000); + + memset (RAM, 0, 0x20000); + memset (SRAM, 0, 0x20000); + memset (VRAM, 0, 0x10000); + memset (ROM, 0, MAX_ROM_SIZE + 0x200 + 0x8000); + + FillRAM = NULL; + + IPPU.TileCache [TILE_2BIT] = (uint8 *) malloc (MAX_2BIT_TILES * 64); + IPPU.TileCache [TILE_4BIT] = (uint8 *) malloc (MAX_4BIT_TILES * 64); + IPPU.TileCache [TILE_8BIT] = (uint8 *) malloc (MAX_8BIT_TILES * 64); + IPPU.TileCache [TILE_2BIT_EVEN] = (uint8 *) malloc (MAX_2BIT_TILES * 64); + IPPU.TileCache [TILE_2BIT_ODD] = (uint8 *) malloc (MAX_2BIT_TILES * 64); + IPPU.TileCache [TILE_4BIT_EVEN] = (uint8 *) malloc (MAX_4BIT_TILES * 64); + IPPU.TileCache [TILE_4BIT_ODD] = (uint8 *) malloc (MAX_4BIT_TILES * 64); + + IPPU.TileCached [TILE_2BIT] = (uint8 *) malloc (MAX_2BIT_TILES); + IPPU.TileCached [TILE_4BIT] = (uint8 *) malloc (MAX_4BIT_TILES); + IPPU.TileCached [TILE_8BIT] = (uint8 *) malloc (MAX_8BIT_TILES); + IPPU.TileCached [TILE_2BIT_EVEN] = (uint8 *) malloc (MAX_2BIT_TILES); + IPPU.TileCached [TILE_2BIT_ODD] = (uint8 *) malloc (MAX_2BIT_TILES); + IPPU.TileCached [TILE_4BIT_EVEN] = (uint8 *) malloc (MAX_4BIT_TILES); + IPPU.TileCached [TILE_4BIT_ODD] = (uint8 *) malloc (MAX_4BIT_TILES); + + if (!RAM || !SRAM || !VRAM || !ROM || + !IPPU.TileCache [TILE_2BIT] || !IPPU.TileCache [TILE_4BIT] || + !IPPU.TileCache [TILE_8BIT] || !IPPU.TileCached [TILE_2BIT] || + !IPPU.TileCached [TILE_4BIT] || !IPPU.TileCached [TILE_8BIT] || + !IPPU.TileCache [TILE_2BIT_EVEN] || !IPPU.TileCache [TILE_2BIT_ODD] || + !IPPU.TileCache [TILE_4BIT_EVEN] || !IPPU.TileCache [TILE_4BIT_ODD] || + !IPPU.TileCached [TILE_2BIT_EVEN] || !IPPU.TileCached [TILE_2BIT_ODD] || + !IPPU.TileCached [TILE_4BIT_EVEN] || !IPPU.TileCached [TILE_4BIT_ODD]) + { + Deinit (); + return (FALSE); + } + + // FillRAM uses first 32K of ROM image area, otherwise space just + // wasted. Might be read by the SuperFX code. + + FillRAM = ROM; + + // Add 0x8000 to ROM image pointer to stop SuperFX code accessing + // unallocated memory (can cause crash on some ports). + ROM += 0x8000; + + C4RAM = ROM + 0x400000 + 8192 * 8; ::ROM = ROM; ::SRAM = SRAM; ::RegRAM = FillRAM; -#endif - + + // BS + BIOSROM = ROM + 0x300000; + BSRAM = ROM + 0x400000; + #ifdef ZSNES_FX - SFXPlotTable = ROM + 0x400000; + SFXPlotTable = ROM + 0x400000; #else - SuperFX.pvRegisters = FillRAM + 0x3000; - SuperFX.nRamBanks = 2; // Most only use 1. 1=64KB=512Mb, 2=128KB=1024Mb - SuperFX.pvRam = SRAM; - SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024); - SuperFX.pvRom = (uint8 *) ROM; + SuperFX.pvRegisters = &Memory.FillRAM [0x3000]; + SuperFX.nRamBanks = 2; // Most only use 1. 1=64KB, 2=128KB=1024Mb + SuperFX.pvRam = ::SRAM; + SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024); + SuperFX.pvRom = (uint8 *) ROM; #endif - - SDD1Data = NULL; - SDD1Index = NULL; - - PostRomInitFunc = NULL; - - return (TRUE); + + ZeroMemory (IPPU.TileCache [TILE_2BIT], MAX_2BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_4BIT], MAX_4BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_8BIT], MAX_8BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_2BIT_EVEN], MAX_2BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_2BIT_ODD], MAX_2BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_4BIT_EVEN], MAX_4BIT_TILES * 64); + ZeroMemory (IPPU.TileCache [TILE_4BIT_ODD], MAX_4BIT_TILES * 64); + + ZeroMemory (IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_2BIT_EVEN], MAX_2BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_2BIT_ODD], MAX_2BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_4BIT_EVEN], MAX_4BIT_TILES); + ZeroMemory (IPPU.TileCached [TILE_4BIT_ODD], MAX_4BIT_TILES); + + SDD1Data = NULL; + SDD1Index = NULL; + + return (TRUE); } -void CMemory::Deinit (void) +void CMemory::Deinit () { - // XXX: Please remove port specific codes #ifdef __W32_HEAP - if (_HEAPOK! = _heapchk()) + if(_HEAPOK!=_heapchk()) MessageBox(GUI.hWnd, "CMemory::Deinit", "Heap Corrupt", MB_OK); #endif - if (RAM) - { - free(RAM); + if (RAM) + { + free ((char *) RAM); RAM = NULL; - } - - if (SRAM) - { - free(SRAM); + } + if (SRAM) + { + free ((char *) SRAM); SRAM = NULL; - } - - if (VRAM) - { - free(VRAM); + } + if (VRAM) + { + free ((char *) VRAM); VRAM = NULL; - } - - if (ROM) - { + } + if (ROM) + { ROM -= 0x8000; - free(ROM); + free ((char *) ROM); ROM = NULL; - } + } - for (int t = 0; t < 7; t++) - { - if (IPPU.TileCache[t]) - { - free(IPPU.TileCache[t]); + for(int t=0; t<7; t++){ + if(IPPU.TileCache[t]) { + free ((char *) IPPU.TileCache[t]); IPPU.TileCache[t] = NULL; } - - if (IPPU.TileCached[t]) - { - free(IPPU.TileCached[t]); + if(IPPU.TileCached[t]) { + free ((char *) IPPU.TileCached[t]); IPPU.TileCached[t] = NULL; } } - - FreeSDD1Data(); - + + FreeSDD1Data (); Safe(NULL); SafeANK(NULL); } -void CMemory::FreeSDD1Data (void) +void CMemory::FreeSDD1Data () { - if (SDD1Index) - { - free(SDD1Index); + if (SDD1Index) + { + free ((char *) SDD1Index); SDD1Index = NULL; - } - - if (SDD1Data) - { - free(SDD1Data); + } + if (SDD1Data) + { + free ((char *) SDD1Data); SDD1Data = NULL; - } + } } -// file management and ROM detection +/**********************************************************************************************/ +/* LoadROM() */ +/* This function loads a Snes-Backup image */ +/**********************************************************************************************/ -static bool8 allASCII (uint8 *b, int size) +bool8 CMemory::LoadROM (const char *filename) { - for (int i = 0; i < size; i++) - { - if (b[i] < 32 || b[i] > 126) - return (FALSE); - } - - return (TRUE); -} + int32 TotalFileSize = 0; + bool8 Interleaved = FALSE; + bool8 Tales = FALSE; + + uint8* RomHeader=ROM; + + ExtendedFormat=NOPE; -static bool8 is_SufamiTurbo_BIOS (uint8 *data, uint32 size) -{ - if (size == 0x40000 && - strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) == 0) - return (TRUE); - else - return (FALSE); -} -static bool8 is_SufamiTurbo_Cart (uint8 *data, uint32 size) -{ - if (size >= 0x80000 && size <= 0x100000 && - strncmp((char *) data, "BANDAI SFC-ADX", 14) == 0 && strncmp((char * ) (data + 0x10), "SFC-ADX BACKUP", 14) != 0) - return (TRUE); - else - return (FALSE); -} + if(CleanUp7110!=NULL) + (*CleanUp7110)(); + + memset (&SNESGameFixes, 0, sizeof(SNESGameFixes)); + SNESGameFixes.SRAMInitialValue = 0x60; + + CPU.TriedInterleavedMode2 = FALSE; + + CalculatedSize = 0; + retry_count =0; -static bool8 is_SameGame_BIOS (uint8 *data, uint32 size) -{ - if (size == 0x100000 && strncmp((char *) (data + 0xffc0), "Same Game Tsume Game", 20) == 0) - return (TRUE); - else - return (FALSE); -} +again: + Settings.DisplayColor=0xffff; + SET_UI_COLOR(255,255,255); -static bool8 is_SameGame_Add_On (uint8 *data, uint32 size) -{ - if (size == 0x80000) - return (TRUE); - else - return (FALSE); -} + TotalFileSize = FileLoader(ROM, filename, MAX_ROM_SIZE); -int CMemory::ScoreHiROM (bool8 skip_header, int32 romoff) -{ - uint8 *buf = ROM + 0xff00 + romoff + (skip_header ? 0x200 : 0); - int score = 0; + if (!TotalFileSize) + return FALSE; // it ends here - if (buf[0xd5] & 0x1) - score += 2; +#ifndef NGC + else if(!Settings.NoPatch) + CheckForIPSPatch (filename, HeaderCount != 0, TotalFileSize); +#endif - // Mode23 is SA-1 - if (buf[0xd5] == 0x23) - score -= 2; + //fix hacked games here. + if((strncmp("HONKAKUHA IGO GOSEI", (char*)&ROM[0x7FC0],19)==0)&&(ROM[0x7FD5]!=0x31)) + { + ROM[0x7FD5]=0x31; + ROM[0x7FD6]=0x02; + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); + S9xMessage(S9X_ERROR,S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); + } - if (buf[0xd4] == 0x20) - score += 2; + if((strncmp("HONKAKUHA IGO GOSEI", (char*)&ROM[0xFFC0],19)==0)&&(ROM[0xFFD5]!=0x31)) + { + ROM[0xFFD5]=0x31; + ROM[0xFFD6]=0x02; + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); + S9xMessage(S9X_ERROR,S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); + } - if ((buf[0xdc] + (buf[0xdd] << 8)) + (buf[0xde] + (buf[0xdf] << 8)) == 0xffff) + if((ROM[0x7FD5]==0x42)&&(ROM[0x7FD6]==0x13)&&(strncmp("METAL COMBAT",(char*)&ROM[0x7FC0],12)==0)) { - score += 2; - if (0 != (buf[0xde] + (buf[0xdf] << 8))) - score++; + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); + S9xMessage(S9X_ERROR,S9X_ROM_CONFUSING_FORMAT_INFO, "Warning! Hacked Dump!"); } - if (buf[0xda] == 0x33) - score += 2; + int orig_hi_score, orig_lo_score; + int hi_score, lo_score; + + orig_hi_score = hi_score = ScoreHiROM (FALSE); + orig_lo_score = lo_score = ScoreLoROM (FALSE); + + if (HeaderCount == 0 && !Settings.ForceNoHeader && + ((hi_score > lo_score && ScoreHiROM (TRUE) > hi_score) || + (hi_score <= lo_score && ScoreLoROM (TRUE) > lo_score))) + { + memmove (Memory.ROM, Memory.ROM + 512, TotalFileSize - 512); + TotalFileSize -= 512; + S9xMessage (S9X_INFO, S9X_HEADER_WARNING, + "Try specifying the -nhd command line option if the game doesn't work\n"); + //modifying ROM, so we need to rescore + orig_hi_score = hi_score = ScoreHiROM (FALSE); + orig_lo_score = lo_score = ScoreLoROM (FALSE); + } + + CalculatedSize = (TotalFileSize / 0x2000) * 0x2000; + ZeroMemory (ROM + CalculatedSize, MAX_ROM_SIZE - CalculatedSize); + + if(CalculatedSize >0x400000&& + !(ROM[0x7FD5]==0x32&&((ROM[0x7FD6]&0xF0)==0x40)) && //exclude S-DD1 + !(ROM[0xFFD5]==0x3A&&((ROM[0xFFD6]&0xF0)==0xF0))) //exclude SPC7110 + { + //you might be a Jumbo! + ExtendedFormat=YEAH; + } - if ((buf[0xd5] & 0xf) < 4) - score += 2; + //If both vectors are invalid, it's type 1 LoROM - if (!(buf[0xfd] & 0x80)) - score -= 6; + if(ExtendedFormat==NOPE&&((ROM[0x7FFC]|(ROM[0x7FFD]<<8))<0x8000)&&((ROM[0xFFFC]|(ROM[0xFFFD]<<8)) <0x8000)) + { + if(Settings.DisplayColor==0xffff) + { + Settings.DisplayColor=BUILD_PIXEL(0,31,0); + SET_UI_COLOR(0,255,0); + } + if(!Settings.ForceInterleaved) + S9xDeinterleaveType1(TotalFileSize, ROM); + } - if ((buf[0xfc] + (buf[0xfd] << 8)) > 0xffb0) - score -= 2; // reduced after looking at a scan by Cowering + //CalculatedSize is now set, so rescore + orig_hi_score = hi_score = ScoreHiROM (FALSE); + orig_lo_score = lo_score = ScoreLoROM (FALSE); - if (CalculatedSize > 1024 * 1024 * 3) - score += 4; + if(NOPE!=ExtendedFormat) + { + int loromscore, hiromscore, swappedlorom, swappedhirom; + loromscore=ScoreLoROM(FALSE); + hiromscore=ScoreHiROM(FALSE); + swappedlorom=ScoreLoROM(FALSE, 0x400000); + swappedhirom=ScoreHiROM(FALSE, 0x400000); - if ((1 << (buf[0xd7] - 7)) > 48) - score -= 1; + //set swapped here. - if (!allASCII(&buf[0xb0], 6)) - score -= 1; + if(max(swappedlorom, swappedhirom) >= max(loromscore, hiromscore)) + { + ExtendedFormat = BIGFIRST; + hi_score=swappedhirom; + lo_score=swappedlorom; + RomHeader=ROM+0x400000; + } + else + { + ExtendedFormat = SMALLFIRST; + lo_score=loromscore; + hi_score=hiromscore; + RomHeader=ROM; + } - if (!allASCII(&buf[0xc0], ROM_NAME_LEN - 1)) - score -= 1; - return (score); -} + } -int CMemory::ScoreLoROM (bool8 skip_header, int32 romoff) -{ - uint8 *buf = ROM + 0x7f00 + romoff + (skip_header ? 0x200 : 0); - int score = 0; - - if (!(buf[0xd5] & 0x1)) - score += 3; - - // Mode23 is SA-1 - if (buf[0xd5] == 0x23) - score += 2; - - if ((buf[0xdc] + (buf[0xdd] << 8)) + (buf[0xde] + (buf[0xdf] << 8)) == 0xffff) - { - score += 2; - if (0 != (buf[0xde] + (buf[0xdf] << 8))) - score++; - } - - if (buf[0xda] == 0x33) - score += 2; - - if ((buf[0xd5] & 0xf) < 4) - score += 2; - - if (!(buf[0xfd] & 0x80)) - score -= 6; - - if ((buf[0xfc] + (buf[0xfd] << 8)) > 0xffb0) - score -= 2; // reduced per Cowering suggestion - - if (CalculatedSize <= 1024 * 1024 * 16) - score += 2; - - if ((1 << (buf[0xd7] - 7)) > 48) - score -= 1; - - if (!allASCII(&buf[0xb0], 6)) - score -= 1; - - if (!allASCII(&buf[0xc0], ROM_NAME_LEN - 1)) - score -= 1; - - return (score); -} - -uint32 CMemory::HeaderRemove (uint32 size, int32 &headerCount, uint8 *buf) -{ - uint32 calc_size = (size / 0x2000) * 0x2000; - - if ((size - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) - { - uint8 *NSRTHead = buf + 0x1D0; // NSRT Header Location - - // detect NSRT header - if (!strncmp("NSRT", (char *) &NSRTHead[24], 4)) + Interleaved = Settings.ForceInterleaved || Settings.ForceInterleaved2; + if (Settings.ForceLoROM || (!Settings.ForceHiROM && lo_score >= hi_score)) + { + LoROM = TRUE; + HiROM = FALSE; + + // Ignore map type byte if not 0x2x or 0x3x + if ((RomHeader [0x7fd5] & 0xf0) == 0x20 || (RomHeader [0x7fd5] & 0xf0) == 0x30) { - if (NSRTHead[28] == 22) + switch (RomHeader [0x7fd5] & 0xf) { - if (((std::accumulate(NSRTHead, NSRTHead + sizeof(NSRTHeader), 0) & 0xFF) == NSRTHead[30]) && - (NSRTHead[30] + NSRTHead[31] == 255) && ((NSRTHead[0] & 0x0F) <= 13) && - (((NSRTHead[0] & 0xF0) >> 4) <= 3) && ((NSRTHead[0] & 0xF0) >> 4)) - memcpy(NSRTHeader, NSRTHead, sizeof(NSRTHeader)); + case 1: + Interleaved = TRUE; + break; + case 5: + Interleaved = TRUE; + Tales = TRUE; + break; } } - - memmove(buf, buf + 512, calc_size); - headerCount++; - size -= 512; - } - - return (size); -} - - - -bool8 CMemory::LoadROM (const char *filename) -{ - int retry_count = 0; - - if (!filename || !*filename) - return (FALSE); - -#ifndef NGC - ZeroMemory(ROM, MAX_ROM_SIZE); - ZeroMemory(&Multi, sizeof(Multi)); -#endif /* you don't want to do that: ROM already loaded */ - -again: - Settings.DisplayColor = 0xffff; - SET_UI_COLOR(255, 255, 255); - - CalculatedSize = 0; - ExtendedFormat = NOPE; - - int32 totalFileSize; - - totalFileSize = FileLoader(ROM, filename, MAX_ROM_SIZE); - if (!totalFileSize) - return (FALSE); -#ifndef NGC - if (!Settings.NoPatch) - CheckForIPSPatch(filename, HeaderCount != 0, totalFileSize); -#endif - int hi_score, lo_score; - - hi_score = ScoreHiROM(FALSE); - lo_score = ScoreLoROM(FALSE); - - if (HeaderCount == 0 && !Settings.ForceNoHeader && - ((hi_score > lo_score && ScoreHiROM(TRUE) > hi_score) || - (hi_score <= lo_score && ScoreLoROM(TRUE) > lo_score))) - { - memmove(ROM, ROM + 512, totalFileSize - 512); - totalFileSize -= 512; - S9xMessage(S9X_INFO, S9X_HEADER_WARNING, "Try 'force no-header' option if the game doesn't work"); - // modifying ROM, so we need to rescore - hi_score = ScoreHiROM(FALSE); - lo_score = ScoreLoROM(FALSE); - } - - CalculatedSize = (totalFileSize / 0x2000) * 0x2000; - - if (CalculatedSize > 0x400000 && - (ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x4332 && // exclude S-DD1 - (ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x4532 && - (ROM[0xffd5] + (ROM[0xffd6] << 8)) != 0xF93a && // exclude SPC7110 - (ROM[0xffd5] + (ROM[0xffd6] << 8)) != 0xF53a) - ExtendedFormat = YEAH; - - // if both vectors are invalid, it's type 1 LoROM - if (ExtendedFormat == NOPE && - ((ROM[0x7ffc] + (ROM[0x7ffd] << 8)) < 0x8000) && - ((ROM[0xfffc] + (ROM[0xfffd] << 8)) < 0x8000)) - { - if (Settings.DisplayColor == 0xffff) - { - Settings.DisplayColor = BUILD_PIXEL(0, 31, 0); - SET_UI_COLOR(0, 255, 0); - } - - if (!Settings.ForceInterleaved) - S9xDeinterleaveType1(totalFileSize, ROM); - } - - // CalculatedSize is now set, so rescore - hi_score = ScoreHiROM(FALSE); - lo_score = ScoreLoROM(FALSE); - - uint8 *RomHeader = ROM; - - if (ExtendedFormat != NOPE) - { - int swappedhirom, swappedlorom; - - swappedhirom = ScoreHiROM(FALSE, 0x400000); - swappedlorom = ScoreLoROM(FALSE, 0x400000); - - // set swapped here - if (max(swappedlorom, swappedhirom) >= max(lo_score, hi_score)) - { - ExtendedFormat = BIGFIRST; - hi_score = swappedhirom; - lo_score = swappedlorom; - RomHeader += 0x400000; - } - else - ExtendedFormat = SMALLFIRST; - } - - bool8 interleaved, tales = FALSE; - - interleaved = Settings.ForceInterleaved || Settings.ForceInterleaved2; - - if (Settings.ForceLoROM || (!Settings.ForceHiROM && lo_score >= hi_score)) - { - LoROM = TRUE; - HiROM = FALSE; - - // ignore map type byte if not 0x2x or 0x3x - if ((RomHeader[0x7fd5] & 0xf0) == 0x20 || (RomHeader[0x7fd5] & 0xf0) == 0x30) + } + else + { + if ((RomHeader [0xffd5] & 0xf0) == 0x20 || (RomHeader [0xffd5] & 0xf0) == 0x30) { - switch (RomHeader[0x7fd5] & 0xf) + switch (RomHeader [0xffd5] & 0xf) { - case 1: - interleaved = TRUE; - break; - - case 5: - interleaved = TRUE; - tales = TRUE; - break; + case 0: + case 3: + Interleaved = TRUE; + break; } } - } - else - { LoROM = FALSE; HiROM = TRUE; + } + + // More + if (!Settings.ForceHiROM && !Settings.ForceLoROM && + !Settings.ForceInterleaved && !Settings.ForceInterleaved2 && + !Settings.ForceNotInterleaved && !Settings.ForcePAL && + !Settings.ForceSuperFX && !Settings.ForceDSP1 && + !Settings.ForceSA1 && !Settings.ForceC4 && + !Settings.ForceSDD1) + { - if ((RomHeader[0xffd5] & 0xf0) == 0x20 || (RomHeader[0xffd5] & 0xf0) == 0x30) + +#ifdef DETECT_NASTY_FX_INTERLEAVE +//MK: Damn. YI trips a BRK currently. Maybe even on a real cart. + + if(strncmp((char *)&ROM[0x7fc0], "YOSHI'S ISLAND", 14) == 0 && READ_WORD(ROM+0x7FDE)==57611 && ROM[0x10002]==0xA9) { - switch (RomHeader[0xffd5] & 0xf) - { - case 0: - case 3: - interleaved = TRUE; - break; - } + Interleaved=true; + Settings.ForceInterleaved2=true; } - } - - // this two games fail to be detected - if (!Settings.ForceHiROM && !Settings.ForceLoROM) - { - if (strncmp((char *) &ROM[0x7fc0], "YUYU NO QUIZ DE GO!GO!", 22) == 0 || - (strncmp((char *) &ROM[0xffc0], "BATMAN--REVENGE JOKER", 21) == 0)) +#endif + if (strncmp ((char *) &ROM [0x7fc0], "YUYU NO QUIZ DE GO!GO!", 22) == 0) { LoROM = TRUE; HiROM = FALSE; - interleaved = FALSE; - tales = FALSE; + Interleaved = FALSE; } - } - - if (!Settings.ForceNotInterleaved && interleaved) - { - S9xMessage(S9X_INFO, S9X_ROM_INTERLEAVED_INFO, "ROM image is in interleaved format - converting..."); - - if (tales) + } + + if (!Settings.ForceNotInterleaved && Interleaved) + { + CPU.TriedInterleavedMode2 = TRUE; + S9xMessage (S9X_INFO, S9X_ROM_INTERLEAVED_INFO, + "ROM image is in interleaved format - converting..."); + + if (Tales) { - if (ExtendedFormat == BIGFIRST) + if(Memory.ExtendedFormat==BIGFIRST) { S9xDeinterleaveType1(0x400000, ROM); - S9xDeinterleaveType1(CalculatedSize - 0x400000, ROM + 0x400000); + S9xDeinterleaveType1(CalculatedSize-0x400000, ROM+0x400000); } else { - S9xDeinterleaveType1(CalculatedSize - 0x400000, ROM); - S9xDeinterleaveType1(0x400000, ROM + CalculatedSize - 0x400000); + S9xDeinterleaveType1(CalculatedSize-0x400000, ROM); + S9xDeinterleaveType1(0x400000, ROM+CalculatedSize-0x400000); + } - + LoROM = FALSE; HiROM = TRUE; + + } - else - if (Settings.ForceInterleaveGD24 && CalculatedSize == 0x300000) + else if (Settings.ForceInterleaved2) + { + S9xDeinterleaveType2(FALSE); + } + else if (Settings.ForceInterleaveGD24 && CalculatedSize ==0x300000) { - bool8 t = LoROM; + bool8 t = LoROM; + LoROM = HiROM; HiROM = t; S9xDeinterleaveGD24(CalculatedSize, ROM); } else - if (Settings.ForceInterleaved2) - S9xDeinterleaveType2(CalculatedSize, ROM); - else { - bool8 t = LoROM; + if(Settings.DisplayColor==0xffff) + { + Settings.DisplayColor=BUILD_PIXEL(0,31,0); + SET_UI_COLOR(0,255,0); + } + bool8 t = LoROM; + LoROM = HiROM; HiROM = t; + S9xDeinterleaveType1(CalculatedSize, ROM); } - hi_score = ScoreHiROM(FALSE); - lo_score = ScoreLoROM(FALSE); - - if ((HiROM && (lo_score >= hi_score || hi_score < 0)) || - (LoROM && (hi_score > lo_score || lo_score < 0))) + hi_score = ScoreHiROM (FALSE); + lo_score = ScoreLoROM (FALSE); + + if ((HiROM && + (lo_score >= hi_score || hi_score < 0)) || + (LoROM && + (hi_score > lo_score || lo_score < 0))) { if (retry_count == 0) { - S9xMessage(S9X_INFO, S9X_ROM_CONFUSING_FORMAT_INFO, "ROM lied about its type! Trying again."); + S9xMessage (S9X_INFO, S9X_ROM_CONFUSING_FORMAT_INFO, + "ROM lied about its type! Trying again."); Settings.ForceNotInterleaved = TRUE; Settings.ForceInterleaved = FALSE; retry_count++; @@ -970,475 +940,871 @@ bool8 CMemory::LoadROM (const char *filename) } } - if (ExtendedFormat == SMALLFIRST) - tales = TRUE; - - if (tales) - { - uint8 *tmp = (uint8 *) malloc(CalculatedSize - 0x400000); - if (tmp) - { - S9xMessage(S9X_INFO, S9X_ROM_INTERLEAVED_INFO, "Fixing swapped ExHiROM..."); - memmove(tmp, ROM, CalculatedSize - 0x400000); - memmove(ROM, ROM + CalculatedSize - 0x400000, 0x400000); - memmove(ROM + 0x400000, tmp, CalculatedSize - 0x400000); - free(tmp); - } - } - - if (strncmp(LastRomFilename, filename, _MAX_PATH)) - { - strncpy(LastRomFilename, filename, _MAX_PATH); - LastRomFilename[_MAX_PATH] = 0; - } - - FreeSDD1Data(); - if (CleanUp7110) - (*CleanUp7110)(); - - ZeroMemory(&SNESGameFixes, sizeof(SNESGameFixes)); - SNESGameFixes.SRAMInitialValue = 0x60; - -#ifndef NGC - S9xLoadCheatFile(S9xGetFilename(".cht", PATCH_DIR)); -#endif + if(ExtendedFormat==SMALLFIRST) + Tales=true; - InitROM(); + FreeSDD1Data (); + InitROM (Tales); #ifndef NGC - S9xInitCheatData(); - S9xApplyCheats(); + S9xLoadCheatFile (S9xGetFilename(".cht", PATCH_DIR)); + S9xInitCheatData (); + S9xApplyCheats (); #endif - S9xReset(); - + S9xReset (); + return (TRUE); } -uint32 CMemory::FileLoader (uint8 *buffer, const char *filename, int32 maxsize) +uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize) { - // <- ROM size without header - // ** Memory.HeaderCount - // ** Memory.ROMFilename - int32 totalSize = 0; + #ifndef NGC - char fname[_MAX_PATH + 1]; - char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], name[_MAX_FNAME + 1], exts[_MAX_EXT + 1]; - char *ext; + STREAM ROMFile; + int len = 0; + int nFormat=FILE_DEFAULT; +#endif -#if defined(__WIN32__) || defined(__MACOSX__) - ext = &exts[1]; -#else - ext = &exts[0]; + int32 TotalFileSize = 0; + char dir [_MAX_DIR + 1]; + char drive [_MAX_DRIVE + 1]; + char name [_MAX_FNAME + 1]; + char ext [_MAX_EXT + 1]; + char fname [_MAX_PATH + 1]; + + unsigned long FileSize = 0; + +#ifdef UNZIP_SUPPORT + unzFile file=NULL; #endif + + _splitpath (filename, drive, dir, name, ext); + _makepath (fname, drive, dir, name, ext); + +#if defined(__WIN32__) || defined(__MACOSX__) + memmove (&ext [0], &ext[1], 4); #endif - memset(NSRTHeader, 0, sizeof(NSRTHeader)); - HeaderCount = 0; #ifndef NGC - _splitpath(filename, drive, dir, name, exts); - _makepath(fname, drive, dir, name, exts); - int nFormat = FILE_DEFAULT; - if (strcasecmp(ext, "zip") == 0) + if (strcasecmp (ext, "zip") == 0) nFormat = FILE_ZIP; + else if (strcasecmp (ext, "rar") == 0) + nFormat = FILE_RAR; + else if (strcasecmp (ext, "jma") == 0) + nFormat = FILE_JMA; else - if (strcasecmp(ext, "jma") == 0) - nFormat = FILE_JMA; + nFormat = FILE_DEFAULT; - switch (nFormat) + switch( nFormat ) { - case FILE_ZIP: - { + case FILE_ZIP: + #ifdef UNZIP_SUPPORT - if (!LoadZip(fname, &totalSize, &HeaderCount, buffer)) - { - S9xMessage(S9X_ERROR, S9X_ROM_INFO, "Invalid Zip archive."); - return (0); - } - strcpy(ROMFilename, fname); -#else - S9xMessage(S9X_ERROR, S9X_ROM_INFO, "This binary was not created with Zip support."); - return (0); -#endif - break; - } + file = unzOpen(fname); - case FILE_JMA: + if(file != NULL) { -#ifdef JMA_SUPPORT - size_t size = load_jma_file(fname, buffer); - if (!size) - { - S9xMessage(S9X_ERROR, S9X_ROM_INFO, "Invalid JMA archive."); + + // its a valid ZIP, close it and let LoadZIP handle it. + + unzClose(file); + + if (!LoadZip (fname, &TotalFileSize, &HeaderCount, ROM)) return (0); - } + + strcpy (ROMFilename, fname); - totalSize = HeaderRemove(size, HeaderCount, buffer); + } + else + { + // its a bad zip file. Walk away - strcpy(ROMFilename, fname); -#else - S9xMessage(S9X_ERROR, S9X_ROM_INFO, "This binary was not created with JMA support."); + S9xMessage (S9X_ERROR, S9X_ROM_INFO, "Invalid Zip Archive."); return (0); -#endif - break; } +#else + S9xMessage (S9X_ERROR, S9X_ROM_INFO, "This binary was not created with Zip support."); + return (0); +#endif + break; - case FILE_DEFAULT: - default: + case FILE_JMA: + { +#ifdef JMA_SUPPORT + size_t FileSize = load_jma_file(fname, ROM); + + if (!FileSize) { - STREAM fp = OPEN_STREAM(fname, "rb"); - if (!fp) - return (0); + S9xMessage (S9X_ERROR, S9X_ROM_INFO, "Invalid JMA."); + return (0); + } + + TotalFileSize = FileSize; + HeaderCount = 0; + + size_t calc_size = (FileSize / 0x2000) * 0x2000; + + + if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || + Settings.ForceHeader) + { + memmove (ROM, ROM + 512, calc_size); + HeaderCount = 1; + FileSize -= 512; + } - strcpy(ROMFilename, fname); + strcpy (ROMFilename, fname); +#else + S9xMessage (S9X_ERROR, S9X_ROM_INFO, "This binary was not created with JMA support."); + return (0); +#endif + break; + } + + case FILE_RAR: + // non existant rar loading + S9xMessage (S9X_ERROR, S9X_ROM_INFO, "Rar Archives are not currently supported."); + return (0); + break; - int len = 0; - uint32 size = 0; - bool8 more = FALSE; - uint8 *ptr = buffer; + case FILE_DEFAULT: + default: + // any other roms go here - do + if ((ROMFile = OPEN_STREAM (fname, "rb")) == NULL) + return (0); + + strcpy (ROMFilename, fname); + + HeaderCount = 0; + uint8 *ptr = buffer; + bool8 more = FALSE; + + do + { + FileSize = READ_STREAM (ptr, maxsize + 0x200 - (ptr - ROM), ROMFile); + CLOSE_STREAM (ROMFile); + + int calc_size = (FileSize / 0x2000) * 0x2000; + + if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || + Settings.ForceHeader) { - size = READ_STREAM(ptr, maxsize + 0x200 - (ptr - buffer), fp); - CLOSE_STREAM(fp); - - size = HeaderRemove(size, HeaderCount, ptr); - totalSize += size; - ptr += size; - - // check for multi file roms - if (ptr - buffer < maxsize + 0x200 && - (isdigit(ext[0]) && ext[1] == 0 && ext[0] < '9')) - { - more = TRUE; - ext[0]++; - _makepath(fname, drive, dir, name, exts); - } - else - if (ptr - buffer < maxsize + 0x200 && - (((len = strlen(name)) == 7 || len == 8) && - strncasecmp(name, "sf", 2) == 0 && - isdigit(name[2]) && isdigit(name[3]) && isdigit(name[4]) && isdigit(name[5]) && - isalpha(name[len - 1]))) - { - more = TRUE; - name[len - 1]++; - _makepath(fname, drive, dir, name, exts); - } - else - more = FALSE; + memmove (ptr, ptr + 512, calc_size); + HeaderCount++; + FileSize -= 512; + } + + ptr += FileSize; + TotalFileSize += FileSize; + - } while (more && (fp = OPEN_STREAM(fname, "rb")) != NULL); + // check for multi file roms - break; - } + if (ptr - ROM < maxsize + 0x200 && + (isdigit (ext [0]) && ext [1] == 0 && ext [0] < '9')) + { + more = TRUE; + ext [0]++; +#if defined(__WIN32__) || defined(__MACOSX__) + memmove (&ext [1], &ext [0], 4); + ext [0] = '.'; +#endif + _makepath (fname, drive, dir, name, ext); + } + else if (ptr - ROM < maxsize + 0x200 && + (((len = strlen (name)) == 7 || len == 8) && + strncasecmp (name, "sf", 2) == 0 && + isdigit (name [2]) && isdigit (name [3]) && isdigit (name [4]) && + isdigit (name [5]) && isalpha (name [len - 1]))) + { + more = TRUE; + name [len - 1]++; +#if defined(__WIN32__) || defined(__MACOSX__) + memmove (&ext [1], &ext [0], 4); + ext [0] = '.'; +#endif + _makepath (fname, drive, dir, name, ext); + } + else + more = FALSE; + } while (more && (ROMFile = OPEN_STREAM (fname, "rb")) != NULL); + + break; + } + #else - /*** Nintendo Wii/Gamecube ROM File Loader - By now we've already loaded the ROM into main memory - This is simply a modified version of FILE_DEFAULT + + /*** Nintendo Gamecube ARAM ROM File Loader + This is simply a modified version of FILE_DEFAULT, which uses + the ARAM as temporary ROM storage. + + NB: Make sure ARAM_ROMSIZE is correct! All hell ensues if you don't ***/ HeaderCount = 0; uint8 *ptr = buffer; - uint32 size = SNESROMSize; - - size = HeaderRemove(size, HeaderCount, ptr); - ptr += size; - totalSize += size; + + unsigned long ARAM_max = maxsize + 0x200 - (ptr - ROM); + FileSize = ARAM_ROMSIZE; + + if ( FileSize > ARAM_max ) + FileSize = ARAM_max; + + if ( hasloaded == 0 ) + ARAMFetchSlow( (char *)ptr, (char *)AR_SNESROM, FileSize ); + + int calc_size = (FileSize / 0x2000) * 0x2000; + + if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || + Settings.ForceHeader) + { + memmove (ptr, ptr + 512, calc_size); + HeaderCount++; + FileSize -= 512; + } + + ptr += FileSize; + TotalFileSize += FileSize; + #endif + if (HeaderCount == 0) - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found."); + S9xMessage (S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found."); else - if (HeaderCount == 1) - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "Found ROM file header (and ignored it)."); - else - S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "Found multiple ROM file headers (and ignored them)."); + { + if (HeaderCount == 1) + S9xMessage (S9X_INFO, S9X_HEADERS_INFO, + "Found ROM file header (and ignored it)."); + else + S9xMessage (S9X_INFO, S9X_HEADERS_INFO, + "Found multiple ROM file headers (and ignored them)."); + } + + + return TotalFileSize; - return ((uint32) totalSize); } -bool8 CMemory::LoadMultiCart (const char *cartA, const char *cartB) -{ - bool8 r = TRUE; - ZeroMemory(ROM, MAX_ROM_SIZE); - ZeroMemory(&Multi, sizeof(Multi)); +#if 0 +/**********************************************************************************************/ +/* LoadMulti() */ +/* This function loads a Slotted SNES-Backup image and fills the slot. */ +/**********************************************************************************************/ - Settings.DisplayColor = 0xffff; - SET_UI_COLOR(255, 255, 255); - - CalculatedSize = 0; - ExtendedFormat = NOPE; +bool8 CMemory::LoadMulti (const char *basename, const char *slot1name, const char *slot2name) +{ + unsigned long FileSize = 0; + + if(*basename=='\0') + return FALSE; + + SufamiTurbo=TRUE; + + int32 offset; + + memset (&SNESGameFixes, 0, sizeof(SNESGameFixes)); + SNESGameFixes.SRAMInitialValue = 0x60; + + CalculatedSize = 0; + + Settings.DisplayColor=0xffff; + SET_UI_COLOR(255,255,255); + + int32 TotalFileSize = FileLoader(ROM, basename, MAX_ROM_SIZE); + + if(0== TotalFileSize) return FALSE; - if (cartA && cartA[0]) - Multi.cartSizeA = FileLoader(ROM, cartA, MAX_ROM_SIZE); +#ifndef NGC + CheckForIPSPatch (basename, HeaderCount != 0, TotalFileSize); +#endif - if (Multi.cartSizeA == 0) - { - if (cartB && cartB[0]) - Multi.cartSizeB = FileLoader(ROM, cartB, MAX_ROM_SIZE); - } + CalculatedSize=TotalFileSize; - if (Multi.cartSizeA) - { - if (is_SufamiTurbo_Cart(ROM, Multi.cartSizeA)) - Multi.cartType = 4; - else - if (is_SameGame_BIOS(ROM, Multi.cartSizeA)) - Multi.cartType = 3; - } - else - if (Multi.cartSizeB) - { - if (is_SufamiTurbo_Cart(ROM, Multi.cartSizeB)) - Multi.cartType = 4; - } - else - Multi.cartType = 4; // assuming BIOS only + for(offset=0; offset0x100000||size <0x80000) + return FALSE; + //probably a minicart + return TRUE; } + return FALSE; +} - FILE *fp; - size_t size; - char path[_MAX_PATH + 1]; - - strcpy(path, S9xGetDirectory(BIOS_DIR)); - strcat(path, SLASH_STR); - strcat(path, "STBIOS.bin"); - - fp = fopen(path, "rb"); - if (fp) - { - size = fread((void *) ROM, 1, 0x40000, fp); - fclose(fp); - if (!is_SufamiTurbo_BIOS(ROM, size)) - return (FALSE); - } - else - return (FALSE); - - if (Multi.cartSizeA) - strcpy(ROMFilename, Multi.fileNameA); - else - if (Multi.cartSizeB) - strcpy(ROMFilename, Multi.fileNameB); - else - strcpy(ROMFilename, path); - - LoROM = TRUE; - HiROM = FALSE; - CalculatedSize = 0x40000; - - return (TRUE); +bool8 SameGameSig(uint8* file, int32 size) +{ + //preheader sig + if(strcmp((char*)(file+0xFFA0),"1995/12/16 10:2018ZS5J")) + return FALSE; + if(size!=0x100000) + return FALSE; + if(0x133E1C5B==caCRC32(file, size)) + return TRUE; + return FALSE; } - -bool8 CMemory::LoadSameGame (const char *cartA, const char *cartB) +bool8 GNextSig(uint8* file, int32 size) { - Multi.cartOffsetA = 0; - Multi.cartOffsetB = 0x200000; - Multi.sramA = SRAM; - Multi.sramB = NULL; - - Multi.sramSizeA = ROM[0xffd8]; - Multi.sramMaskA = Multi.sramSizeA ? ((1 << (Multi.sramSizeA + 3)) * 128 - 1) : 0; - Multi.sramSizeB = 0; - Multi.sramMaskB = 0; + //preheader sig + if(strcmp((char*)(file+0xFFAA),"GNEXT B2ZX3J")) + return FALSE; + if(size!=0x180000) + return FALSE; + if(0x845E420D==caCRC32(file, size)) + return TRUE; + return FALSE; +} +int MultiType(uint8* file, int32 size) +{ + //check for ST signiture + if(SufamiTurboBIOSSig(file, size)) + return 1; + //check for Same Game signiture + if(SameGameSig(file, size)) + return 2; + //check for G-Next signiture + if(GNextSig(file, size)) + return 3; + return 0; +} -#ifndef NGC - if (!Settings.NoPatch) - CheckForIPSPatch(cartA, HeaderCount != 0, Multi.cartSizeA); #endif - strcpy(Multi.fileNameA, cartA); - if (cartB && cartB[0]) - Multi.cartSizeB = FileLoader(ROM + Multi.cartOffsetB, cartB, MAX_ROM_SIZE - Multi.cartOffsetB); +//compatibility wrapper +void S9xDeinterleaveMode2 () +{ + S9xDeinterleaveType2(); +} - if (Multi.cartSizeB) +void S9xDeinterleaveType2 (bool8 reset) +{ + if(Settings.DisplayColor==0xffff||Settings.DisplayColor==BUILD_PIXEL(0,31,0)) { - if (!is_SameGame_Add_On(ROM + Multi.cartOffsetB, Multi.cartSizeB)) - Multi.cartSizeB = 0; - else - strcpy(Multi.fileNameB, cartB); + Settings.DisplayColor=BUILD_PIXEL(31,14,6); + SET_UI_COLOR(255,119,25); + } + S9xMessage (S9X_INFO, S9X_ROM_INTERLEAVED_INFO, + "ROM image is in interleaved format - converting..."); + + int nblocks = Memory.CalculatedSize >> 16; + int step = 64; + + while (nblocks <= step) + step >>= 1; + + nblocks = step; + uint8 blocks [256]; + int i; + + for (i = 0; i < nblocks * 2; i++) + { + blocks [i] = (i & ~0xF) | ((i & 3) << 2) | + ((i & 12) >> 2); + } + + uint8 *tmp = (uint8 *) malloc (0x10000); + + if (tmp) + { + for (i = 0; i < nblocks * 2; i++) + { + for (int j = i; j < nblocks * 2; j++) + { + if (blocks [j] == i) + { + memmove (tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000); + memmove (&Memory.ROM [blocks [j] * 0x10000], + &Memory.ROM [blocks [i] * 0x10000], 0x10000); + memmove (&Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000); + uint8 b = blocks [j]; + blocks [j] = blocks [i]; + blocks [i] = b; + break; + } + } + } + free ((char *) tmp); + tmp=NULL; + } + if(reset) + { + Memory.InitROM (FALSE); + S9xReset (); + } +} - strcpy(ROMFilename, Multi.fileNameA); - - LoROM = FALSE; - HiROM = TRUE; - CalculatedSize = Multi.cartSizeA; - - return (TRUE); +//CRC32 for char arrays +inline uint32 caCRC32(uint8 *array, uint32 size, register uint32 crc32) +{ + for (register uint32 i = 0; i < size; i++) + { + crc32 = ((crc32 >> 8) & 0x00FFFFFF) ^ crc32Table[(crc32 ^ array[i]) & 0xFF]; + } + return ~crc32; } -bool8 CMemory::LoadLastROM (void) +void CMemory::InitROM (bool8 Interleaved) { - if (Multi.cartType) - return (FALSE); +#ifndef ZSNES_FX + SuperFX.nRomBanks = CalculatedSize >> 15; +#endif + Settings.DSP1Master = Settings.ForceDSP1; + Settings.SuperFX = FALSE; + Settings.SA1 = FALSE; + Settings.C4 = FALSE; + Settings.SDD1 = FALSE; + Settings.SRTC = FALSE; + Settings.SPC7110=FALSE; + Settings.SPC7110RTC=FALSE; + Settings.BS=FALSE; + Settings.OBC1=FALSE; + Settings.SETA=FALSE; + s7r.DataRomSize = 0; + CalculatedChecksum=0; + + uint8* RomHeader; - bool8 r; + RomHeader=ROM+0x7FB0; - stopMovie = FALSE; - r = LoadROM(LastRomFilename); - stopMovie = TRUE; + if(ExtendedFormat==BIGFIRST) + RomHeader+=0x400000; - return (r); -} + if(HiROM) + RomHeader+=0x8000; -void CMemory::ClearSRAM (bool8 onlyNonSavedSRAM) -{ - if(onlyNonSavedSRAM) - if (!(Settings.SuperFX && ROMType < 0x15) && !(Settings.SA1 && ROMType == 0x34)) // can have SRAM - return; + for (int i = 0; i < MEMMAP_NUM_BLOCKS; i++) + { + Map [MEMMAP_NUM_BLOCKS] = (uint8 *) MAP_NONE; + BlockIsRAM [MEMMAP_NUM_BLOCKS] = FALSE; + BlockIsROM [MEMMAP_NUM_BLOCKS] = FALSE; + } + + S9xInitBSX(); - memset(SRAM, SNESGameFixes.SRAMInitialValue, 0x20000); -} + ::SRAM = SRAM; + memset (ROMId, 0, 5); + memset (CompanyId, 0, 3); -bool8 CMemory::LoadSRAM (const char *filename) -{ - ClearSRAM(); + ParseSNESHeader(RomHeader); + + // Try to auto-detect the DSP1 chip + if (!Settings.ForceNoDSP1 && + (ROMType & 0xf) >= 3 && (ROMType & 0xf0) == 0) + Settings.DSP1Master = TRUE; + + if (Memory.HiROM) + { + // Enable S-RTC (Real Time Clock) emulation for Dai Kaijyu Monogatari 2 + Settings.SRTC = ((ROMType & 0xf0) >> 4) == 5; -#ifndef NGC - FILE *file; - int size, len; - char sramName[_MAX_PATH + 1]; - strcpy(sramName, filename); + if(((ROMSpeed&0x0F)==0x0A)&&((ROMType&0xF0)==0xF0)) + { + Settings.SPC7110=true; + if((ROMType&0x0F)==0x09) + Settings.SPC7110RTC=true; + } + + if (Settings.BS) + /* Do nothing */; + else if(Settings.SPC7110) + { + SPC7110HiROMMap(); + } + else if ((ROMSpeed & ~0x10) == 0x25) + { + TalesROMMap (Interleaved); + } + else HiROMMap (); + } + else + { + Settings.SuperFX = Settings.ForceSuperFX; + + if(ROMType==0x25) + { + Settings.OBC1=TRUE; + } + + if ((ROMType & 0xf0) == 0x10) + Settings.SuperFX = !Settings.ForceNoSuperFX; + + Settings.SDD1 = Settings.ForceSDD1; + if ((ROMType & 0xf0) == 0x40) + Settings.SDD1 = !Settings.ForceNoSDD1; + + if (Settings.SDD1) + S9xLoadSDD1Data (); + + if(((ROMType &0xF0) == 0xF0)&((ROMSpeed&0x0F)!=5)) + { + SRAMSize=2; + SNESGameFixes.SRAMInitialValue = 0x00; + if((ROMType &0x0F)==6) + { + if(ROM[0x7FD7]==0x09) + { + Settings.SETA=ST_011; + SetSETA=&S9xSetST011; + GetSETA=&S9xGetST011; + } + else + { + Settings.SETA=ST_010; + SetSETA=&S9xSetST010; + GetSETA=&S9xGetST010; + } + } + else + { + Settings.SETA=ST_018; + SRAMSize=2; + } + } + + Settings.C4 = Settings.ForceC4; + if ((ROMType & 0xf0) == 0xf0 && + (strncmp (ROMName, "MEGAMAN X", 9) == 0 || + strncmp (ROMName, "ROCKMAN X", 9) == 0)) + { + Settings.C4 = !Settings.ForceNoC4; + } + + if(Settings.SETA&&Settings.SETA!=ST_018) + { + SetaDSPMap(); + } + else if (Settings.SuperFX) + { + //::SRAM = ROM + 1024 * 1024 * 4; + SuperFXROMMap (); + Settings.MultiPlayer5Master = FALSE; + //Settings.MouseMaster = FALSE; + //Settings.SuperScopeMaster = FALSE; + Settings.DSP1Master = FALSE; + Settings.SA1 = FALSE; + Settings.C4 = FALSE; + Settings.SDD1 = FALSE; + } + else if (Settings.ForceSA1 || + (!Settings.ForceNoSA1 && (ROMSpeed & ~0x10) == 0x23 && + (ROMType & 0xf) > 3 && (ROMType & 0xf0) == 0x30)) + { + Settings.SA1 = TRUE; +// Settings.MultiPlayer5Master = FALSE; + //Settings.MouseMaster = FALSE; + //Settings.SuperScopeMaster = FALSE; + Settings.DSP1Master = FALSE; + Settings.C4 = FALSE; + Settings.SDD1 = FALSE; + SA1ROMMap (); + } + else if ((ROMSpeed & ~0x10) == 0x25) + TalesROMMap (Interleaved); + else if(ExtendedFormat!=NOPE) + JumboLoROMMap(Interleaved); + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "SOUND NOVEL-TCOOL", 17) == 0 || + strncmp ((char *) &Memory.ROM [0x7fc0], "DERBY STALLION 96", 17) == 0) + { + LoROM24MBSMap (); + Settings.DSP1Master = FALSE; + } + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "THOROUGHBRED BREEDER3", 21) == 0 || + strncmp ((char *) &Memory.ROM [0x7fc0], "RPG-TCOOL 2", 11) == 0) + { + SRAM512KLoROMMap (); + Settings.DSP1Master = FALSE; + } + else if (strncmp ((char *) &Memory.ROM [0x7fc0], "ADD-ON BASE CASSETE", 19) == 0) + { + Settings.MultiPlayer5Master = FALSE; + Settings.MouseMaster = FALSE; + Settings.SuperScopeMaster = FALSE; + Settings.DSP1Master = FALSE; + SufamiTurboLoROMMap(); + Memory.SRAMSize = 3; + } + else if ((ROMSpeed & ~0x10) == 0x22 && + strncmp (ROMName, "Super Street Fighter", 20) != 0) + { + AlphaROMMap (); + } + else if (Settings.BS) + /* Do nothing */; + else LoROMMap (); + } - if (Multi.cartType && Multi.sramSizeB) + uint32 sum1 = 0; + uint32 sum2 = 0; + if(0==CalculatedChecksum) { - char temp[_MAX_PATH + 1]; + int power2 = 0; + int size = CalculatedSize; + + while (size >>= 1) + power2++; + + size = 1 << power2; + uint32 remainder = CalculatedSize - size; + + + int i; + + for (i = 0; i < size; i++) + sum1 += ROM [i]; + + for (i = 0; i < (int) remainder; i++) + sum2 += ROM [size + i]; + + int sub = 0; + if (Settings.BS && !Settings.BSXItself) + { + if (Memory.HiROM) + { + for (i = 0; i < 48; i++) + sub += ROM[0xffb0 + i]; + } + else if (Memory.LoROM) + { + for (i = 0; i < 48; i++) + sub += ROM[0x7fb0 + i]; + } + sum1 -= sub; + } - strcpy(temp, ROMFilename); - strcpy(ROMFilename, Multi.fileNameB); - size = (1 << (Multi.sramSizeB + 3)) * 128; + if (remainder) + { + sum1 += sum2 * (size / remainder); + } + + + sum1 &= 0xffff; + Memory.CalculatedChecksum=sum1; + } + //now take a CRC32 + ROMCRC32 = caCRC32(ROM, CalculatedSize); - file = fopen(S9xGetFilename(".srm", SRAM_DIR), "rb"); - if (file) + if (Settings.ForceNTSC) + Settings.PAL = FALSE; + else if (Settings.ForcePAL) + Settings.PAL = TRUE; + else + { + //Korea refers to South Korea, which uses NTSC + switch(ROMRegion) { - len = fread((char *) Multi.sramB, 1, 0x10000, file); - fclose(file); - if (len - size == 512) - memmove(Multi.sramB, Multi.sramB + 512, size); + case 13: + case 1: + case 0: + Settings.PAL=FALSE; + break; + default: Settings.PAL=TRUE; + break; } + } + + Timings.H_Max_Master = SNES_CYCLES_PER_SCANLINE; + Timings.H_Max = Timings.H_Max_Master; + Timings.HBlankStart = SNES_HBLANK_START_HC; + Timings.HBlankEnd = SNES_HBLANK_END_HC; + Timings.HDMAInit = SNES_HDMA_INIT_HC; + Timings.HDMAStart = SNES_HDMA_START_HC; + Timings.RenderPos = SNES_RENDER_START_HC; + Timings.V_Max_Master = Settings.PAL ? SNES_MAX_PAL_VCOUNTER : SNES_MAX_NTSC_VCOUNTER; + Timings.V_Max = Timings.V_Max_Master; + + if (Settings.PAL) + { + Settings.FrameTime = Settings.FrameTimePAL; + Memory.ROMFramesPerSecond = 50; + } + else + { + Settings.FrameTime = Settings.FrameTimeNTSC; + Memory.ROMFramesPerSecond = 60; + } + + ROMName[ROM_NAME_LEN - 1] = 0; + if (strlen (ROMName)) + { + char *p = ROMName + strlen (ROMName); + if(p>ROMName+21 && ROMName[20]==' ') p=ROMName+21; - strcpy(ROMFilename, temp); + while (p > ROMName && *(p - 1) == ' ') + p--; + *p = 0; + } + + { + SRAMMask = Memory.SRAMSize ? + ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0; } + if((ROMChecksum + ROMComplementChecksum != 0xffff) || ROMChecksum != CalculatedChecksum || ((uint32)CalculatedSize > (uint32)(((1<<(ROMSize-7))*128)*1024))) + { + if(Settings.DisplayColor==0xffff || Settings.DisplayColor!=BUILD_PIXEL(31,0,0)) + { + Settings.DisplayColor=BUILD_PIXEL(31,31,0); + SET_UI_COLOR(255,255,0); + } + } + + IAPU.OneCycle = ONE_APU_CYCLE; + Settings.Shutdown = Settings.ShutdownMaster; + + SetDSP=&DSP1SetByte; + GetDSP=&DSP1GetByte; - size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0; - if (size > 0x20000) - size = 0x20000; + CPU.FastROMSpeed = 0; + ResetSpeedMap(); + ApplyROMFixes (); + + char displayName[ROM_NAME_LEN]; + strcpy (RawROMName, ROMName); + sprintf (displayName, "%s", SafeANK (ROMName)); + sprintf (ROMName, "%s", Safe (ROMName)); + sprintf (ROMId, "%s", Safe (ROMId)); + sprintf (CompanyId, "%s", Safe (CompanyId)); + + sprintf (String, "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s CRC32: %08X", + displayName, + (ROMChecksum + ROMComplementChecksum != 0xffff || + ROMChecksum != CalculatedChecksum) ? "bad checksum" : "checksum ok", + MapType (), + Size (), + KartContents (), + MapMode (), + TVStandard (), + StaticRAMSize (), + ROMId, + CompanyId, + ROMCRC32); + + S9xMessage (S9X_INFO, S9X_ROM_INFO, String); +#ifdef __WIN32__ + #ifndef _XBOX + EnableMenuItem(GUI.hMenu, IDM_ROM_INFO, MF_ENABLED); + #endif + #ifdef RTC_DEBUGGER + if(Settings.SPC7110RTC) + EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_ENABLED); + else EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_GRAYED); + #endif +#endif + Settings.ForceHeader = Settings.ForceHiROM = Settings.ForceLoROM = + Settings.ForceInterleaved = Settings.ForceNoHeader = Settings.ForceNotInterleaved = + Settings.ForceInterleaved2=false; - if (size) - { - file = fopen(sramName, "rb"); - if (file) + S9xVerifyControllers(); +} + +bool8 CMemory::LoadSRAM (const char *filename) +{ + int size = Memory.SRAMSize ? + (1 << (Memory.SRAMSize + 3)) * 128 : 0; + + memset (SRAM, SNESGameFixes.SRAMInitialValue, 0x20000); + + if (size > 0x20000) + size = 0x20000; +#ifndef NGC + if (size) + { + FILE *file; + if ((file = fopen (filename, "rb"))) { - len = fread((char *) SRAM, 1, 0x20000, file); - fclose(file); + int len = fread ((char*) ::SRAM, 1, 0x20000, file); + fclose (file); if (len - size == 512) - memmove(SRAM, SRAM + 512, size); - + { + // S-RAM file has a header - remove it + memmove (::SRAM, ::SRAM + 512, size); + } if (len == size + SRTC_SRAM_PAD) { - S9xSRTCPostLoadState(); - S9xResetSRTC(); + S9xSRTCPostLoadState (); + S9xResetSRTC (); rtc.index = -1; rtc.mode = MODE_READ; } else - S9xHardResetSRTC(); - - if (Settings.SPC7110RTC) - S9xLoadSPC7110RTC(&rtc_f9); - + S9xHardResetSRTC (); + + if(Settings.SPC7110RTC) + { + S9xLoadSPC7110RTC (&rtc_f9); + } + return (TRUE); } else @@ -1446,20 +1812,17 @@ bool8 CMemory::LoadSRAM (const char *filename) { // The BS game's SRAM was not found // Try to read BS-X.srm instead + char path[_MAX_PATH + 1]; strcpy(path, S9xGetDirectory(SRAM_DIR)); strcat(path, SLASH_STR); strcat(path, "BS-X.srm"); - - file = fopen(path, "rb"); - if (file) + + if ((file = fopen(path, "rb"))) { - len = fread((char *) SRAM, 1, 0x20000, file); - fclose(file); - if (len - size == 512) - memmove(SRAM, SRAM + 512, size); - + fread((char *) ::SRAM, 1, 0x20000, file); + fclose (file); S9xMessage(S9X_INFO, S9X_ROM_INFO, "The SRAM file wasn't found: BS-X.srm was read instead."); S9xHardResetSRTC(); return (TRUE); @@ -1471,1846 +1834,2326 @@ bool8 CMemory::LoadSRAM (const char *filename) return (FALSE); } } - - S9xHardResetSRTC(); + + S9xHardResetSRTC (); return (FALSE); - } + } + if (Settings.SDD1) + S9xSDD1LoadLoggedData (); - if (Settings.SDD1) - S9xSDD1LoadLoggedData(); #endif - return (TRUE); + return (TRUE); } bool8 CMemory::SaveSRAM (const char *filename) { - if (Settings.SuperFX && ROMType < 0x15) // doesn't have SRAM - return (TRUE); - - if (Settings.SA1 && ROMType == 0x34) // doesn't have SRAM - return (TRUE); - - FILE *file; - int size; - char sramName[_MAX_PATH + 1]; - - strcpy(sramName, filename); - - if (Multi.cartType && Multi.sramSizeB) - { - char name[_MAX_PATH + 1], temp[_MAX_PATH + 1]; - - strcpy(temp, ROMFilename); - strcpy(ROMFilename, Multi.fileNameB); - strcpy(name, S9xGetFilename(".srm", SRAM_DIR)); - - size = (1 << (Multi.sramSizeB + 3)) * 128; - - file = fopen(name, "wb"); - if (file) + if(Settings.SuperFX && Memory.ROMType < 0x15) + return TRUE; + if(Settings.SA1 && Memory.ROMType == 0x34) + return TRUE; + + int size = Memory.SRAMSize ? + (1 << (Memory.SRAMSize + 3)) * 128 : 0; + if (Settings.SRTC) + { + size += SRTC_SRAM_PAD; + S9xSRTCPreSaveState (); + } + + if (Settings.SDD1) + S9xSDD1SaveLoggedData (); + + if (size > 0x20000) + size = 0x20000; + + if (size && *Memory.ROMFilename) + { + FILE *file; + if ((file = fopen (filename, "wb"))) { - fwrite((char *) Multi.sramB, size, 1, file); - fclose(file); -#ifdef __linux - chown(name, getuid(), getgid()); + fwrite ((char *) ::SRAM, size, 1, file); + fclose (file); +#if defined(__linux) + chown (filename, getuid (), getgid ()); #endif + if(Settings.SPC7110RTC) + { + S9xSaveSPC7110RTC (&rtc_f9); + } + return (TRUE); } - - strcpy(ROMFilename, temp); } + return (FALSE); +} - size = SRAMSize ? (1 << (SRAMSize + 3)) * 128 : 0; +void CMemory::FixROMSpeed () +{ + int c; - if (Settings.SRTC) - { - size += SRTC_SRAM_PAD; - S9xSRTCPreSaveState(); - } + if(CPU.FastROMSpeed==0) + CPU.FastROMSpeed=SLOW_ONE_CYCLE; + - if (Settings.SDD1) - S9xSDD1SaveLoggedData(); + for (c = 0x800; c < 0x1000; c++) + { + if (c&0x8 || c&0x400) + MemorySpeed [c] = (uint8) CPU.FastROMSpeed; + } +} - if (size > 0x20000) - size = 0x20000; - if (size) +void CMemory::ResetSpeedMap() +{ + int i; + memset(MemorySpeed, SLOW_ONE_CYCLE, 0x1000); + for(i=0;i<0x400;i+=0x10) { - file = fopen(sramName, "wb"); - if (file) - { - fwrite((char *) SRAM, size, 1, file); - fclose(file); -#ifdef __linux - chown(sramName, getuid(), getgid()); -#endif - if (Settings.SPC7110RTC) - S9xSaveSPC7110RTC(&rtc_f9); - - return (TRUE); - } + MemorySpeed[i+2]=MemorySpeed[0x800+i+2]= ONE_CYCLE; + MemorySpeed[i+3]=MemorySpeed[0x800+i+3]= ONE_CYCLE; + MemorySpeed[i+4]=MemorySpeed[0x800+i+4]= ONE_CYCLE; + MemorySpeed[i+5]=MemorySpeed[0x800+i+5]= ONE_CYCLE; } - - return (FALSE); + CMemory::FixROMSpeed (); } -// initialization - -static uint32 caCRC32 (uint8 *array, uint32 size, uint32 crc32) +void CMemory::WriteProtectROM () { - for (uint32 i = 0; i < size; i++) - crc32 = ((crc32 >> 8) & 0x00FFFFFF) ^ crc32Table[(crc32 ^ array[i]) & 0xFF]; - - return (~crc32); + memmove ((void *) WriteMap, (void *) Map, sizeof (Map)); + for (int c = 0; c < 0x1000; c++) + { + if (BlockIsROM [c]) + WriteMap [c] = (uint8 *) MAP_NONE; + } } -char * CMemory::Safe (const char *s) +void CMemory::MapRAM () { - static char *safe = NULL; - static int safe_len = 0; + int c; - if (s == NULL) + if(Memory.LoROM&&!Settings.SDD1) { - if (safe) + // Banks 70->77, S-RAM + for (c = 0; c < 0x0f; c++) { - free(safe); - safe = NULL; + for(int i=0;i<8;i++) + { + Map [(c<<4) + 0xF00+i]=Map [(c<<4) + 0x700+i] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [(c<<4) + 0xF00+i] =BlockIsRAM [(c<<4) + 0x700+i] = TRUE; + BlockIsROM [(c<<4) + 0xF00+i] =BlockIsROM [(c<<4) + 0x700+i] = FALSE; + } } - - return (NULL); - } - - int len = strlen(s); - if (!safe || len + 1 > safe_len) - { - if (safe) - free(safe); - - safe_len = len + 1; - safe = (char *) malloc(safe_len); } - - for (int i = 0; i < len; i++) + else if(Memory.LoROM&&Settings.SDD1) { - if (s[i] >= 32 && s[i] < 127) - safe[i] = s[i]; - else - safe[i] = '_'; + // Banks 70->77, S-RAM + for (c = 0; c < 0x0f; c++) + { + for(int i=0;i<8;i++) + { + Map [(c<<4) + 0x700+i] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [(c<<4) + 0x700+i] = TRUE; + BlockIsROM [(c<<4) + 0x700+i] = FALSE; + } + } } - - safe[len] = 0; - - return (safe); + // Banks 7e->7f, RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + WriteProtectROM (); } -char * CMemory::SafeANK (const char *s) +void CMemory::MapExtraRAM () { - static char *safe = NULL; - static int safe_len = 0; + int c; + + // Banks 7e->7f, RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + + // Banks 70->73, S-RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x700] = ::SRAM; + Map [c + 0x710] = ::SRAM + 0x8000; + Map [c + 0x720] = ::SRAM + 0x10000; + Map [c + 0x730] = ::SRAM + 0x18000; + + BlockIsRAM [c + 0x700] = TRUE; + BlockIsROM [c + 0x700] = FALSE; + BlockIsRAM [c + 0x710] = TRUE; + BlockIsROM [c + 0x710] = FALSE; + BlockIsRAM [c + 0x720] = TRUE; + BlockIsROM [c + 0x720] = FALSE; + BlockIsRAM [c + 0x730] = TRUE; + BlockIsROM [c + 0x730] = FALSE; + } +} - if (s == NULL) +void CMemory::LoROMMap () +{ + int c; + int i; + int j; + int mask[4]; + for (j=0; j<4; j++) + mask[j]=0x00ff; + + mask[0]=(CalculatedSize/0x8000)-1; + + int x; + bool foundZeros; + bool pastZeros; + + for(j=0;j<3;j++) { - if (safe) + x=1; + foundZeros=false; + pastZeros=false; + + mask[j+1]=mask[j]; + + while (x>0x100&&!pastZeros) { - free(safe); - safe = NULL; + if(mask[j]&x) + { + x<<=1; + if(foundZeros) + pastZeros=true; + } + else + { + foundZeros=true; + pastZeros=false; + mask[j+1]|=x; + x<<=1; + } } - - return (NULL); } - int len = strlen(s); - if (!safe || len + 1 > safe_len) - { - if (safe) - free(safe); - - safe_len = len + 1; - safe = (char *) malloc(safe_len); - } - for (int i = 0; i < len; i++) - { - if (s[i] >= 32 && s[i] < 127) // ASCII - safe [i] = s[i]; - else - if (ROMRegion == 0 && ((uint8) s[i] >= 0xa0 && (uint8) s[i] < 0xe0)) // JIS X 201 - Katakana - safe [i] = s[i]; - else - safe [i] = '_'; - } - - safe [len] = 0; - - return (safe); -} - -void CMemory::ParseSNESHeader (uint8 *RomHeader) -{ - bool8 bs = Settings.BS & !Settings.BSXItself; - - strncpy(ROMName, (char *) &RomHeader[0x10], ROM_NAME_LEN - 1); - if (bs) - memset(ROMName + 16, 0x20, ROM_NAME_LEN - 17); - - if (bs) - { - if (!(((RomHeader[0x29] & 0x20) && CalculatedSize < 0x100000) || - (!(RomHeader[0x29] & 0x20) && CalculatedSize == 0x100000))) - printf("BS: Size mismatch\n"); - - // FIXME - int p = 0; - while ((1 << p) < (int) CalculatedSize) - p++; - ROMSize = p - 10; - } - else - ROMSize = RomHeader[0x27]; - - SRAMSize = bs ? 5 /* BS-X */ : RomHeader[0x28]; - ROMSpeed = bs ? RomHeader[0x28] : RomHeader[0x25]; - ROMType = bs ? 0xE5 /* BS-X */ : RomHeader[0x26]; - ROMRegion = bs ? 0 : RomHeader[0x29]; - - ROMChecksum = RomHeader[0x2E] + (RomHeader[0x2F] << 8); - ROMComplementChecksum = RomHeader[0x2C] + (RomHeader[0x2D] << 8); - - memmove(ROMId, &RomHeader[0x02], 4); - - if (RomHeader[0x2A] == 0x33) - memmove(CompanyId, &RomHeader[0x00], 2); - else - sprintf(CompanyId, "%02X", RomHeader[0x2A]); -} - -void CMemory::InitROM (void) -{ - Settings.DSP1Master = FALSE; - Settings.SuperFX = FALSE; - Settings.SA1 = FALSE; - Settings.C4 = FALSE; - Settings.SDD1 = FALSE; - Settings.SRTC = FALSE; - Settings.SPC7110 = FALSE; - Settings.SPC7110RTC = FALSE; - Settings.BS = FALSE; - Settings.OBC1 = FALSE; - Settings.SETA = FALSE; -#ifndef ZSNES_FX - SuperFX.nRomBanks = CalculatedSize >> 15; -#endif - s7r.DataRomSize = 0; - - //// Parse ROM header and read ROM informatoin - - memset(ROMId, 0, 5); - memset(CompanyId, 0, 3); - - uint8 *RomHeader = ROM + 0x7FB0; - if (ExtendedFormat == BIGFIRST) - RomHeader += 0x400000; - if (HiROM) - RomHeader += 0x8000; - - S9xInitBSX(); // Set BS header before parsing - - ParseSNESHeader(RomHeader); - - //// Detect and initialize chips - //// detection codes are compatible with NSRT - - // DSP1/2/3/4 - Settings.DSP1Master = Settings.ForceDSP1; - DSP1.version = 0xff; - - if (ROMType == 0x03) - { - if (ROMSpeed == 0x30) - DSP1.version = 3; // DSP4 - else - DSP1.version = 0; // DSP1 - } - else - if (ROMType == 0x05) - { - if (ROMSpeed == 0x20) - DSP1.version = 1; // DSP2 - else - if (ROMSpeed == 0x30 && RomHeader[0x2a] == 0xb2) - DSP1.version = 2; // DSP3 + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + if(Settings.SETA==ST_018) + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_SETA_RISC; + else Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + if (Settings.DSP1Master) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_DSP; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_DSP; + } + else if (Settings.C4) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_C4; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_C4; + } + else if(Settings.OBC1) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_OBC_RAM; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_OBC_RAM; + } else - DSP1.version = 0; // DSP1 - } - - if (DSP1.version != 0xff) - Settings.DSP1Master = !Settings.ForceNoDSP1; - - switch (DSP1.version) - { - case 0: // DSP1 - if (HiROM) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + } + + for (i = c + 8; i < c + 16; i++) + { + int e=3; + int d=c>>4; + while(d>mask[0]) { - DSP1.boundary = 0x7000; - DSP1.maptype = M_DSP1_HIROM; + d&=mask[e]; + e--; } - else - if (CalculatedSize > 0x100000) + Map [i] = Map [i + 0x800] = ROM + (((d)-1)*0x8000); + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + if (Settings.DSP1Master) + { + // Banks 30->3f and b0->bf + for (c = 0x300; c < 0x400; c += 16) + { + for (i = c + 8; i < c + 16; i++) { - DSP1.boundary = 0x4000; - DSP1.maptype = M_DSP1_LOROM_L; + Map [i] = Map [i + 0x800] = (uint8 *) MAP_DSP; + BlockIsROM [i] = BlockIsROM [i + 0x800] = FALSE; } - else + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 8; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) % CalculatedSize]; + + for (i = c + 8; i < c + 16; i++) + { + int e=3; + int d=(c+0x400)>>4; + while(d>mask[0]) { - DSP1.boundary = 0xc000; - DSP1.maptype = M_DSP1_LOROM_S; + d&=mask[e]; + e--; } - SetDSP = &DSP1SetByte; - GetDSP = &DSP1GetByte; - break; - - case 1: // DSP2 - DSP1.boundary = 0x10000; - DSP1.maptype = M_DSP2_LOROM; - SetDSP = &DSP2SetByte; - GetDSP = &DSP2GetByte; - break; - - case 2: // DSP3 - DSP1.boundary = 0xc000; - DSP1.maptype = M_DSP3_LOROM; - SetDSP = &DSP3SetByte; - GetDSP = &DSP3GetByte; - DSP3_Reset(); - break; + Map [i + 0x400] = Map [i + 0xc00] = ROM + (((d)-1)*0x8000); + } + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + if (Settings.DSP1Master) + { + for (c = 0; c < 0x100; c++) + { + Map [c + 0xe00] = (uint8 *) MAP_DSP; + BlockIsROM [c + 0xe00] = FALSE; + } + } - case 3: // DSP4 - DSP1.boundary = 0xc000; - DSP1.maptype = M_DSP4_LOROM; - SetDSP = &DSP4SetByte; - GetDSP = &DSP4GetByte; - break; + int sum=0, k,l, bankcount; + bankcount=1<<(ROMSize-7);//Mbits - default: - SetDSP = NULL; - GetDSP = NULL; - break; + //safety for corrupt headers + if(bankcount > 128) + bankcount = (CalculatedSize/0x8000)/4; + bankcount*=4;//to banks + bankcount<<=4;//Map banks + bankcount+=0x800;//normalize + for(k=0x800;k<(bankcount);k+=16) + { + uint8* bank=0x8000+Map[k+8]; + for(l=0;l<0x8000;l++) + sum+=bank[l]; } + CalculatedChecksum=sum&0xFFFF; - Settings.SA1 = Settings.ForceSA1; - Settings.SuperFX = Settings.ForceSuperFX; - Settings.SDD1 = Settings.ForceSDD1; - Settings.C4 = Settings.ForceC4; - - uint32 identifier = ((ROMType & 0xff) << 8) + (ROMSpeed & 0xff); + MapRAM (); + WriteProtectROM (); +} - switch (identifier) +void CMemory::SetaDSPMap () +{ + int c; + int i; + int j; + int mask[4]; + for (j=0; j<4; j++) + mask[j]=0x00ff; + + mask[0]=(CalculatedSize/0x8000)-1; + + int x; + bool foundZeros; + bool pastZeros; + + for(j=0;j<3;j++) { - // SRTC - case 0x5535: - Settings.SRTC = TRUE; - break; - - // SPC7110 - case 0xF93A: - Settings.SPC7110RTC = TRUE; - case 0xF53A: - Settings.SPC7110 = TRUE; - S9xSpc7110Init(); - break; - - // OBC1 - case 0x2530: - Settings.OBC1 = TRUE; - break; - - // SA1 - case 0x3423: - case 0x3523: - Settings.SA1 = !Settings.ForceNoSA1; - break; + x=1; + foundZeros=false; + pastZeros=false; - // SuperFX - case 0x1320: - case 0x1420: - case 0x1520: - case 0x1A20: - Settings.SuperFX = !Settings.ForceNoSuperFX; - if (Settings.SuperFX) - { - if (ROM[0x7FDA] == 0x33) - SRAMSize = ROM[0x7FBD]; - else - SRAMSize = 5; - } - - break; - - // SDD1 - case 0x4332: - case 0x4532: - Settings.SDD1 = !Settings.ForceNoSDD1; - if (Settings.SDD1) - S9xLoadSDD1Data(); - break; - - // ST018 - case 0xF530: - Settings.SETA = ST_018; - SetSETA = NULL; - GetSETA = NULL; - SRAMSize = 2; - SNESGameFixes.SRAMInitialValue = 0x00; - break; + mask[j+1]=mask[j]; - // ST010/011 - case 0xF630: - if (ROM[0x7FD7] == 0x09) + while (x>0x100&&!pastZeros) + { + if(mask[j]&x) { - Settings.SETA = ST_011; - SetSETA = &S9xSetST011; - GetSETA = &S9xGetST011; + x<<=1; + if(foundZeros) + pastZeros=true; } else { - Settings.SETA = ST_010; - SetSETA = &S9xSetST010; - GetSETA = &S9xGetST010; + foundZeros=true; + pastZeros=false; + mask[j+1]|=x; + x<<=1; } - - SRAMSize = 2; - SNESGameFixes.SRAMInitialValue = 0x00; - break; - - // C4 - case 0xF320: - Settings.C4 = !Settings.ForceNoC4; - break; + } } - //// Map memory and calculate checksum - - Map_Initialize(); - CalculatedChecksum = 0; - if (HiROM) + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) { - if (Settings.BS) - /* Do nothing */; - else - if (Settings.SPC7110) - Map_SPC7110HiROMMap(); - else - if (ExtendedFormat != NOPE) - Map_ExtendedHiROMMap(); - else - if (Multi.cartType == 3) - Map_SameGameHiROMMap(); - else - Map_HiROMMap(); - } - else - { - if (Settings.BS) - /* Do nothing */; - else - if (Settings.SETA && Settings.SETA != ST_018) - Map_SetaDSPLoROMMap(); - else - if (Settings.SuperFX) - Map_SuperFXLoROMMap(); - else - if (Settings.SA1) - Map_SA1LoROMMap(); - else - if (Settings.SDD1) - Map_SDD1LoROMMap(); - else - if (ExtendedFormat != NOPE) - Map_JumboLoROMMap(); - else - if (strncmp(ROMName, "WANDERERS FROM YS", 17) == 0) - Map_NoMAD1LoROMMap(); - else - if (strncmp(ROMName, "SOUND NOVEL-TCOOL", 17) == 0 || - strncmp(ROMName, "DERBY STALLION 96", 17) == 0) - Map_ROM24MBSLoROMMap(); - else - if (strncmp(ROMName, "THOROUGHBRED BREEDER3", 21) == 0 || - strncmp(ROMName, "RPG-TCOOL 2", 11) == 0) - Map_SRAM512KLoROMMap(); - else - if (strncmp(ROMName, "ADD-ON BASE CASSETE", 19) == 0) + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) { - if (Multi.cartType == 4) + int e=3; + int d=c>>4; + while(d>mask[0]) { - SRAMSize = Multi.sramSizeA; - Map_SufamiTurboLoROMMap(); + d&=mask[e]; + e--; } - else + Map [i] = Map [i + 0x800] = ROM + (((d)-1)*0x8000); + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c + 8; i < c + 16; i++) + { + int e=3; + int d=(c+0x400)>>4; + while(d>mask[0]) { - SRAMSize = 5; - Map_SufamiTurboPseudoLoROMMap(); + d&=mask[e]; + e--; } + + Map [i + 0x400] = Map [i + 0xc00] = ROM + (((d)-1)*0x8000); + } + + //only upper half is ROM + for (i = c+8; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; } - else - Map_LoROMMap(); } - - Checksum_Calculate(); - - bool8 isChecksumOK = (ROMChecksum + ROMComplementChecksum == 0xffff) & - (ROMChecksum == CalculatedChecksum); - - //// Build more ROM information - - // CRC32 - if (!Settings.BS || Settings.BSXItself) // Not BS Dump - ROMCRC32 = caCRC32(ROM, CalculatedSize); - else // Convert to correct format before scan + + memset(SRAM, 0, 0x1000); + for (c=0x600;c<0x680;c+=0x10) { - int offset = HiROM ? 0xffc0 : 0x7fc0; - // Backup - uint8 BSMagic0 = ROM[offset + 22], - BSMagic1 = ROM[offset + 23]; - // uCONSRT standard - ROM[offset + 22] = 0x42; - ROM[offset + 23] = 0x00; - // Calc - ROMCRC32 = caCRC32(ROM, CalculatedSize); - // Convert back - ROM[offset + 22] = BSMagic0; - ROM[offset + 23] = BSMagic1; - } - - // NTSC/PAL - if (Settings.ForceNTSC) - Settings.PAL = FALSE; - else - if (Settings.ForcePAL) - Settings.PAL = TRUE; - else - if (!Settings.BS && (ROMRegion >= 2) && (ROMRegion <= 12)) - Settings.PAL = TRUE; - else - Settings.PAL = FALSE; - - - //// Initialize emulation - - Timings.H_Max_Master = SNES_CYCLES_PER_SCANLINE; - Timings.H_Max = Timings.H_Max_Master; - Timings.HBlankStart = SNES_HBLANK_START_HC; - Timings.HBlankEnd = SNES_HBLANK_END_HC; - Timings.HDMAInit = SNES_HDMA_INIT_HC; - Timings.HDMAStart = SNES_HDMA_START_HC; - Timings.RenderPos = SNES_RENDER_START_HC; - Timings.V_Max_Master = Settings.PAL ? SNES_MAX_PAL_VCOUNTER : SNES_MAX_NTSC_VCOUNTER; - Timings.V_Max = Timings.V_Max_Master; - /* From byuu: The total delay time for both the initial (H)DMA sync (to the DMA clock), - and the end (H)DMA sync (back to the last CPU cycle's mcycle rate (6, 8, or 12)) always takes between 12-24 mcycles. - Possible delays: { 12, 14, 16, 18, 20, 22, 24 } - XXX: Snes9x can't emulate this timing :( so let's use the average value... */ - Timings.DMACPUSync = 18; - - - if (Settings.PAL) - { - Settings.FrameTime = Settings.FrameTimePAL; - ROMFramesPerSecond = 50; - } - else - { - Settings.FrameTime = Settings.FrameTimeNTSC; - ROMFramesPerSecond = 60; - } - - // truncate cart name - ROMName[ROM_NAME_LEN - 1] = 0; - if (strlen(ROMName)) - { - char *p = ROMName + strlen(ROMName); - if (p > ROMName + 21 && ROMName[20] == ' ') - p = ROMName + 21; - while (p > ROMName && *(p - 1) == ' ') - p--; - *p = 0; - } - - // SRAM size - SRAMMask = SRAMSize ? ((1 << (SRAMSize + 3)) * 128) - 1 : 0; - - // checksum - if (!isChecksumOK || ((uint32) CalculatedSize > (uint32) (((1 << (ROMSize - 7)) * 128) * 1024))) - { - if (Settings.DisplayColor == 0xffff || Settings.DisplayColor != BUILD_PIXEL(31, 0, 0)) + for(i=0;i<0x08;i++) + { + //where does the SETA chip access, anyway? + //please confirm this? + Map[c+0x80+i]=(uint8*)MAP_SETA_DSP; + BlockIsROM [c+0x80+i] = FALSE; + BlockIsRAM [c+0x80+i] = TRUE; + } + + for(i=0;i<0x04;i++) { - Settings.DisplayColor = BUILD_PIXEL(31, 31, 0); - SET_UI_COLOR(255, 255, 0); + //and this! + Map[c+i]=(uint8*)MAP_SETA_DSP; + BlockIsROM [c+i] = FALSE; } } - if (Multi.cartType == 4) + int sum=0, k,l, bankcount; + bankcount=1<<(ROMSize-7);//Mbits + //safety for corrupt headers + if(bankcount > 128) + bankcount = (CalculatedSize/0x8000)/4; + bankcount*=4;//to banks + bankcount<<=4;//Map banks + bankcount+=0x800;//normalize + for(k=0x800;k<(bankcount);k+=16) { - Settings.DisplayColor = BUILD_PIXEL(0, 16, 31); - SET_UI_COLOR(0, 128, 255); + uint8* bank=0x8000+Map[k+8]; + for(l=0;l<0x8000;l++) + sum+=bank[l]; } + CalculatedChecksum=sum&0xFFFF; - IAPU.OneCycle = SNES_APU_ONE_CYCLE_SCALED; - - CPU.FastROMSpeed = 0; - ResetSpeedMap(); - - IPPU.TotalEmulatedFrames = 0; - - Settings.Shutdown = Settings.ShutdownMaster; - - //// Hack games - - ApplyROMFixes(); - - //// Show ROM information - char displayName[ROM_NAME_LEN]; - - strcpy(RawROMName, ROMName); - sprintf(displayName, "%s", SafeANK(ROMName)); - sprintf(ROMName, "%s", Safe(ROMName)); - sprintf(ROMId, "%s", Safe(ROMId)); - sprintf(CompanyId, "%s", Safe(CompanyId)); - - sprintf(String, "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s CRC32: %08X", - displayName, isChecksumOK ? "checksum ok" : ((Multi.cartType == 4) ? "no checksum" : "bad checksum"), - MapType(), Size(), KartContents(), MapMode(), TVStandard(), StaticRAMSize(), ROMId, CompanyId, ROMCRC32); - S9xMessage(S9X_INFO, S9X_ROM_INFO, String); - - // XXX: Please remove port specific codes -#ifdef __WIN32__ -#ifndef _XBOX - EnableMenuItem(GUI.hMenu, IDM_ROM_INFO, MF_ENABLED); -#endif -#ifdef RTC_DEBUGGER - if (Settings.SPC7110RTC) - EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_ENABLED); - else - EnableMenuItem(GUI.hMenu, IDM_7110_RTC, MF_GRAYED); -#endif -#endif - - Settings.ForceHiROM = Settings.ForceLoROM = FALSE; - Settings.ForceHeader = Settings.ForceNoHeader = FALSE; - Settings.ForceInterleaved = Settings.ForceNotInterleaved = Settings.ForceInterleaved2 = FALSE; - -#ifndef NGC - if (stopMovie) - S9xMovieStop(TRUE); -#endif - if (PostRomInitFunc) - PostRomInitFunc(); - - S9xVerifyControllers(); + MapRAM (); + WriteProtectROM (); } -void CMemory::FixROMSpeed (void) +void CMemory::HiROMMap () { - if (CPU.FastROMSpeed == 0) - CPU.FastROMSpeed = SLOW_ONE_CYCLE; + int i; + int c; + int j; - // [80-bf]:[8000-ffff], [c0-ff]:[0000-ffff] - for (int c = 0x800; c < 0x1000; c++) - { - if (c & 0x8 || c & 0x400) - MemorySpeed[c] = (uint8) CPU.FastROMSpeed; - } -} + int mask[4]; + for (j=0; j<4; j++) + mask[j]=0x00ff; -void CMemory::ResetSpeedMap (void) -{ - memset(MemorySpeed, SLOW_ONE_CYCLE, 0x1000); + mask[0]=(CalculatedSize/0x10000)-1; - // Fast - [00-3f|80-bf]:[2000-3fff|4200-5fff] - // XSlow - [00-3f|80-bf]:[4000-41ff] see also S9xGet/SetCPU() - for (int i = 0; i < 0x400; i += 0x10) + if (Settings.ForceSA1 || + (!Settings.ForceNoSA1 && (ROMSpeed & ~0x10) == 0x23 && + (ROMType & 0xf) > 3 && (ROMType & 0xf0) == 0x30)) { - MemorySpeed[i + 2] = MemorySpeed[0x800 + i + 2] = ONE_CYCLE; - MemorySpeed[i + 3] = MemorySpeed[0x800 + i + 3] = ONE_CYCLE; - MemorySpeed[i + 4] = MemorySpeed[0x800 + i + 4] = ONE_CYCLE; - MemorySpeed[i + 5] = MemorySpeed[0x800 + i + 5] = ONE_CYCLE; + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); } - FixROMSpeed(); -} - -// memory map - -uint32 CMemory::map_mirror (uint32 size, uint32 pos) -{ - // from bsnes - if (size == 0) - return (0); - if (pos < size) - return (pos); - - uint32 mask = 1 << 31; - while (!(pos & mask)) - mask >>= 1; - if (size <= (pos & mask)) - return (map_mirror(size, pos - mask)); - else - return (mask + map_mirror(size - mask, pos - mask)); -} + int x; + bool foundZeros; + bool pastZeros; + + for(j=0;j<3;j++) + { + x=1; + foundZeros=false; + pastZeros=false; -void CMemory::map_lorom (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, uint32 size) -{ - uint32 c, i, p, addr; + mask[j+1]=mask[j]; - for (c = bank_s; c <= bank_e; c++) - { - for (i = addr_s; i <= addr_e; i += 0x1000) + while (x>0x100&&!pastZeros) { - p = (c << 4) | (i >> 12); - addr = (c & 0x7f) * 0x8000; - Map[p] = ROM + map_mirror(size, addr) - (i & 0x8000); - BlockIsROM[p] = TRUE; - BlockIsRAM[p] = FALSE; + if(mask[j]&x) + { + x<<=1; + if(foundZeros) + pastZeros=true; + } + else + { + foundZeros=true; + pastZeros=false; + mask[j+1]|=x; + x<<=1; + } } } -} - -void CMemory::map_hirom (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, uint32 size) -{ - uint32 c, i, p, addr; - for (c = bank_s; c <= bank_e; c++) - { - for (i = addr_s; i <= addr_e; i += 0x1000) + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + + if (Settings.DSP1Master) { - p = (c << 4) | (i >> 12); - addr = c << 16; - Map[p] = ROM + map_mirror(size, addr); - BlockIsROM[p] = TRUE; - BlockIsRAM[p] = FALSE; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_DSP; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_DSP; } - } -} - -void CMemory::map_lorom_offset (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, uint32 size, uint32 offset) -{ - uint32 c, i, p, addr; - - for (c = bank_s; c <= bank_e; c++) - { - for (i = addr_s; i <= addr_e; i += 0x1000) + else { - p = (c << 4) | (i >> 12); - addr = ((c - bank_s) & 0x7f) * 0x8000; - Map[p] = ROM + offset + map_mirror(size, addr) - (i & 0x8000); - BlockIsROM[p] = TRUE; - BlockIsRAM[p] = FALSE; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; } - } -} - -void CMemory::map_hirom_offset (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, uint32 size, uint32 offset) -{ - uint32 c, i, p, addr; + + for (i = c + 8; i < c + 16; i++) + { + int e=3; + int d=c>>4; + while(d>mask[0]) + { + d&=mask[e]; + e--; + } + Map [i] = Map [i + 0x800] = ROM + (d*0x10000); + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 30->3f and b0->bf, address ranges 6000->7fff is S-RAM. + for (c = 0; c < 16; c++) + { + Map [0x306 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0x307 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0xb06 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0xb07 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + BlockIsRAM [0x306 + (c << 4)] = TRUE; + BlockIsRAM [0x307 + (c << 4)] = TRUE; + BlockIsRAM [0xb06 + (c << 4)] = TRUE; + BlockIsRAM [0xb07 + (c << 4)] = TRUE; + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + int e=3; + int d=(c)>>4; + while(d>mask[0]) + { + d&=mask[e]; + e--; + } + Map [i + 0x400] = Map [i + 0xc00] = ROM + (d*0x10000); + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } - for (c = bank_s; c <= bank_e; c++) + int bankmax=0x40+ (1<<(ROMSize-6)); + //safety for corrupt headers + if(bankmax > 128) + bankmax = 0x80; + int sum=0; + for(i=0x40;i> 12); - addr = (c - bank_s) << 16; - Map[p] = ROM + offset + map_mirror(size, addr); - BlockIsROM[p] = TRUE; - BlockIsRAM[p] = FALSE; + sum+=bank_low[c]; } } + CalculatedChecksum=sum&0xFFFF; + + MapRAM (); + WriteProtectROM (); } -void CMemory::map_space (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, uint8 *data) +void CMemory::TalesROMMap (bool8 Interleaved) { - uint32 c, i, p; - - for (c = bank_s; c <= bank_e; c++) + int c; + int i; + + if(Interleaved) { - for (i = addr_s; i <= addr_e; i += 0x1000) + if(Settings.DisplayColor==0xffff) { - p = (c << 4) | (i >> 12); - Map[p] = data; - BlockIsROM[p] = FALSE; - BlockIsRAM[p] = TRUE; + Settings.DisplayColor=BUILD_PIXEL(0,31,0); + SET_UI_COLOR(0,255,0); } } -} + uint32 OFFSET0 = 0x400000; + uint32 OFFSET1 = 0x400000; + uint32 OFFSET2 = 0x000000; + + if (Interleaved) + { + OFFSET0 = 0x000000; + OFFSET1 = 0x000000; + OFFSET2 = CalculatedSize-0x400000; //changed to work with interleaved DKJM2. + } + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + + //makes more sense to map the range here. + //ToP seems to use sram to skip intro??? + if(c>=0x300) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_HIROM_SRAM; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_HIROM_SRAM; + BlockIsRAM [6 + c] = BlockIsRAM [7 + c] = + BlockIsRAM [0x806 + c]= BlockIsRAM [0x807 + c] = TRUE; + } + else + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; -void CMemory::map_index (uint32 bank_s, uint32 bank_e, uint32 addr_s, uint32 addr_e, int index, int type) -{ - uint32 c, i, p; - bool8 isROM, isRAM; + } + for (i = c + 8; i < c + 16; i++) + { + Map [i] = &ROM [((c << 12) % (CalculatedSize-0x400000)) + OFFSET0]; + Map [i + 0x800] = &ROM [((c << 12) % 0x400000) + OFFSET2]; + BlockIsROM [i] = TRUE; + BlockIsROM [i + 0x800] = TRUE; + } + } - isROM = ((type == MAP_TYPE_I_O) || (type == MAP_TYPE_RAM)) ? FALSE : TRUE; - isRAM = ((type == MAP_TYPE_I_O) || (type == MAP_TYPE_ROM)) ? FALSE : TRUE; + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 8; i++) + { + Map [i + 0x400] = &ROM [((c << 12) % (CalculatedSize-0x400000)) + OFFSET1]; + Map [i + 0x408] = &ROM [((c << 12) % (CalculatedSize-0x400000)) + OFFSET1]; + Map [i + 0xc00] = &ROM [((c << 12) %0x400000)+ OFFSET2]; + Map [i + 0xc08] = &ROM [((c << 12) % 0x400000) + OFFSET2]; + BlockIsROM [i + 0x400] = TRUE; + BlockIsROM [i + 0x408] = TRUE; + BlockIsROM [i + 0xc00] = TRUE; + BlockIsROM [i + 0xc08] = TRUE; + } + } - for (c = bank_s; c <= bank_e; c++) + if((strncmp("TALES",(char*)Map[8]+0xFFC0, 5)==0)) { - for (i = addr_s; i <= addr_e; i += 0x1000) + if(((*(Map[8]+0xFFDE))==(*(Map[0x808]+0xFFDE)))) { - p = (c << 4) | (i >> 12); - Map[p] = (uint8 *) index; - BlockIsROM[p] = isROM; - BlockIsRAM[p] = isRAM; + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); } } -} -void CMemory::map_System (void) -{ - // will be overwritten - map_space(0x00, 0x3f, 0x0000, 0x1fff, RAM); - map_index(0x00, 0x3f, 0x2000, 0x3fff, MAP_PPU, MAP_TYPE_I_O); - map_index(0x00, 0x3f, 0x4000, 0x5fff, MAP_CPU, MAP_TYPE_I_O); - map_space(0x80, 0xbf, 0x0000, 0x1fff, RAM); - map_index(0x80, 0xbf, 0x2000, 0x3fff, MAP_PPU, MAP_TYPE_I_O); - map_index(0x80, 0xbf, 0x4000, 0x5fff, MAP_CPU, MAP_TYPE_I_O); -} - -void CMemory::map_WRAM (void) -{ - // will overwrite others - map_space(0x7e, 0x7e, 0x0000, 0xffff, RAM); - map_space(0x7f, 0x7f, 0x0000, 0xffff, RAM + 0x10000); -} - -void CMemory::map_LoROMSRAM (void) -{ - map_index(0x70, 0x7f, 0x0000, 0x7fff, MAP_LOROM_SRAM, MAP_TYPE_RAM); - map_index(0xf0, 0xff, 0x0000, 0x7fff, MAP_LOROM_SRAM, MAP_TYPE_RAM); -} - -void CMemory::map_HiROMSRAM (void) -{ - map_index(0x20, 0x3f, 0x6000, 0x7fff, MAP_HIROM_SRAM, MAP_TYPE_RAM); - map_index(0xa0, 0xbf, 0x6000, 0x7fff, MAP_HIROM_SRAM, MAP_TYPE_RAM); -} + ROMChecksum = *(Map[8]+0xFFDE) + (*(Map[8]+0xFFDF) << 8); + ROMComplementChecksum = *(Map[8]+0xFFDC) + (*(Map[8]+0xFFDD) << 8); -void CMemory::map_DSP (void) +int sum=0; +for(i=0x40;i<0x80; i++) { - switch (DSP1.maptype) + uint8 * bank_low=(uint8*)Map[i<<4]; + uint8 * bank_high=(uint8*)Map[(i<<4)+0x800]; + for (c=0;c<0x10000; c++) { - case M_DSP1_LOROM_S: - map_index(0x20, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xa0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - break; - - case M_DSP1_LOROM_L: - map_index(0x60, 0x6f, 0x0000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xe0, 0xef, 0x0000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); - break; - - case M_DSP1_HIROM: - map_index(0x00, 0x1f, 0x6000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); - map_index(0x80, 0x9f, 0x6000, 0x7fff, MAP_DSP, MAP_TYPE_I_O); - break; - - case M_DSP2_LOROM: - map_index(0x20, 0x3f, 0x6000, 0x6fff, MAP_DSP, MAP_TYPE_I_O); - map_index(0x20, 0x3f, 0x8000, 0xbfff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xa0, 0xbf, 0x6000, 0x6fff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xa0, 0xbf, 0x8000, 0xbfff, MAP_DSP, MAP_TYPE_I_O); - break; - - case M_DSP3_LOROM: - map_index(0x20, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xa0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - break; - - case M_DSP4_LOROM: - map_index(0x30, 0x3f, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - map_index(0xb0, 0xbf, 0x8000, 0xffff, MAP_DSP, MAP_TYPE_I_O); - break; + sum+=bank_low[c]; + sum+=bank_high[c]; } } -void CMemory::map_C4 (void) -{ - map_index(0x00, 0x3f, 0x6000, 0x7fff, MAP_C4, MAP_TYPE_I_O); - map_index(0x80, 0xbf, 0x6000, 0x7fff, MAP_C4, MAP_TYPE_I_O); -} +CalculatedChecksum=sum&0xFFFF; -void CMemory::map_OBC1 (void) -{ - map_index(0x00, 0x3f, 0x6000, 0x7fff, MAP_OBC_RAM, MAP_TYPE_I_O); - map_index(0x80, 0xbf, 0x6000, 0x7fff, MAP_OBC_RAM, MAP_TYPE_I_O); -} - -void CMemory::map_SetaRISC (void) -{ - map_index(0x00, 0x3f, 0x3000, 0x3fff, MAP_SETA_RISC, MAP_TYPE_I_O); - map_index(0x80, 0xbf, 0x3000, 0x3fff, MAP_SETA_RISC, MAP_TYPE_I_O); + MapRAM (); + WriteProtectROM (); } -void CMemory::map_SetaDSP (void) +void CMemory::AlphaROMMap () { - // where does the SETA chip access, anyway? - // please confirm this? - map_index(0x68, 0x6f, 0x0000, 0x7fff, MAP_SETA_DSP, MAP_TYPE_RAM); - // and this! - map_index(0x60, 0x67, 0x0000, 0x3fff, MAP_SETA_DSP, MAP_TYPE_I_O); - - // ST-0010: - // map_index(0x68, 0x6f, 0x0000, 0x0fff, MAP_SETA_DSP, ?); + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = TRUE; + } + } + + // Banks 40->7f and c0->ff + + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + Map [i + 0x400] = &ROM [(c << 12) % CalculatedSize]; + Map [i + 0xc00] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + MapRAM (); + WriteProtectROM (); } -void CMemory::map_WriteProtectROM (void) +void DetectSuperFxRamSize() { - memmove((void *) WriteMap, (void *) Map, sizeof(Map)); - - for (int c = 0; c < 0x1000; c++) + if(ROM[0x7FDA]==0x33) { - if (BlockIsROM[c]) - WriteMap[c] = (uint8 *) MAP_NONE; + Memory.SRAMSize=ROM[0x7FBD]; } -} - -void CMemory::Map_Initialize (void) -{ - for (int c = 0; c < 0x1000; c++) + else { - Map[c] = (uint8 *) MAP_NONE; - WriteMap[c] = (uint8 *) MAP_NONE; - BlockIsROM[c] = FALSE; - BlockIsRAM[c] = FALSE; + if(strncmp(Memory.ROMName, "STAR FOX 2", 10)==0) + { + Memory.SRAMSize=6; + } + else Memory.SRAMSize=5; } } -void CMemory::Map_LoROMMap (void) +void CMemory::SuperFXROMMap () { - printf("Map_LoROMMap\n"); - map_System(); - - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_lorom(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize); - - if (Settings.DSP1Master) - map_DSP(); - else - if (Settings.C4) - map_C4(); - else - if (Settings.OBC1) - map_OBC1(); - else - if (Settings.SETA == ST_018) - map_SetaRISC(); - - map_LoROMSRAM(); - map_WRAM(); + int c; + int i; + + DetectSuperFxRamSize(); - map_WriteProtectROM(); -} - -void CMemory::Map_NoMAD1LoROMMap (void) -{ - printf("Map_NoMAD1LoROMMap\n"); - map_System(); - - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_lorom(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize); - - map_index(0x70, 0x7f, 0x0000, 0xffff, MAP_LOROM_SRAM, MAP_TYPE_RAM); - map_index(0xf0, 0xff, 0x0000, 0xffff, MAP_LOROM_SRAM, MAP_TYPE_RAM); - - map_WRAM(); - - map_WriteProtectROM(); -} - -void CMemory::Map_JumboLoROMMap (void) -{ - // XXX: Which game uses this? - printf("Map_JumboLoROMMap\n"); - map_System(); - - map_lorom_offset(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize - 0x400000, 0x400000); - map_lorom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize - 0x400000, 0x400000); - map_lorom_offset(0x80, 0xbf, 0x8000, 0xffff, 0x400000, 0); - map_lorom_offset(0xc0, 0xff, 0x0000, 0xffff, 0x400000, 0x200000); - - map_LoROMSRAM(); - map_WRAM(); - - map_WriteProtectROM(); -} - -void CMemory::Map_ROM24MBSLoROMMap (void) -{ - // PCB: BSC-1A5M-01, BSC-1A7M-10 - printf("Map_ROM24MBSLoROMMap\n"); - map_System(); - - map_lorom_offset(0x00, 0x1f, 0x8000, 0xffff, 0x100000, 0); - map_lorom_offset(0x20, 0x3f, 0x8000, 0xffff, 0x100000, 0x100000); - map_lorom_offset(0x80, 0x9f, 0x8000, 0xffff, 0x100000, 0x200000); - map_lorom_offset(0xa0, 0xbf, 0x8000, 0xffff, 0x100000, 0x100000); - - map_LoROMSRAM(); - map_WRAM(); - - map_WriteProtectROM(); -} - -void CMemory::Map_SRAM512KLoROMMap (void) -{ - printf("Map_SRAM512KLoROMMap\n"); - map_System(); - - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_lorom(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize); - - map_space(0x70, 0x70, 0x0000, 0xffff, SRAM); - map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x8000); - map_space(0x72, 0x72, 0x0000, 0xffff, SRAM + 0x10000); - map_space(0x73, 0x73, 0x0000, 0xffff, SRAM + 0x18000); - - map_WRAM(); - - map_WriteProtectROM(); -} - -void CMemory::Map_SufamiTurboLoROMMap (void) -{ - printf("Map_SufamiTurboLoROMMap\n"); - map_System(); - - map_lorom_offset(0x00, 0x1f, 0x8000, 0xffff, 0x40000, 0); - map_lorom_offset(0x20, 0x3f, 0x8000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_lorom_offset(0x40, 0x5f, 0x8000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - map_lorom_offset(0x80, 0x9f, 0x8000, 0xffff, 0x40000, 0); - map_lorom_offset(0xa0, 0xbf, 0x8000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_lorom_offset(0xc0, 0xdf, 0x8000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - - if (Multi.sramSizeA) - { - map_index(0x60, 0x63, 0x8000, 0xffff, MAP_LOROM_SRAM, MAP_TYPE_RAM); - map_index(0xe0, 0xe3, 0x8000, 0xffff, MAP_LOROM_SRAM, MAP_TYPE_RAM); - } - - if (Multi.sramSizeB) - { - map_index(0x70, 0x73, 0x8000, 0xffff, MAP_LOROM_SRAM_B, MAP_TYPE_RAM); - map_index(0xf0, 0xf3, 0x8000, 0xffff, MAP_LOROM_SRAM_B, MAP_TYPE_RAM); - } - - map_WRAM(); - - map_WriteProtectROM(); + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [0x006 + c] = Map [0x806 + c] = (uint8 *) ::SRAM - 0x6000; + Map [0x007 + c] = Map [0x807 + c] = (uint8 *) ::SRAM - 0x6000; + BlockIsRAM [0x006 + c] = BlockIsRAM [0x007 + c] = BlockIsRAM [0x806 + c] = BlockIsRAM [0x807 + c] = TRUE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + // Banks 7e->7f, RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + + // Banks 70->71, S-RAM + for (c = 0; c < 32; c++) + { + Map [c + 0x700] = ::SRAM + (((c >> 4) & 1) << 16); + BlockIsRAM [c + 0x700] = TRUE; + BlockIsROM [c + 0x700] = FALSE; + } + + // Replicate the first 2Mb of the ROM at ROM + 2MB such that each 32K + // block is repeated twice in each 64K block. + for (c = 0; c < 64; c++) + { + memmove (&ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); + memmove (&ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000); + } + + WriteProtectROM (); } -void CMemory::Map_SufamiTurboPseudoLoROMMap (void) +void CMemory::SA1ROMMap () { - // for combined images - printf("Map_SufamiTurboPseudoLoROMMap\n"); - map_System(); - - map_lorom_offset(0x00, 0x1f, 0x8000, 0xffff, 0x40000, 0); - map_lorom_offset(0x20, 0x3f, 0x8000, 0xffff, 0x100000, 0x100000); - map_lorom_offset(0x40, 0x5f, 0x8000, 0xffff, 0x100000, 0x200000); - map_lorom_offset(0x80, 0x9f, 0x8000, 0xffff, 0x40000, 0); - map_lorom_offset(0xa0, 0xbf, 0x8000, 0xffff, 0x100000, 0x100000); - map_lorom_offset(0xc0, 0xdf, 0x8000, 0xffff, 0x100000, 0x200000); - - // I don't care :P - map_space(0x60, 0x63, 0x8000, 0xffff, SRAM - 0x8000); - map_space(0xe0, 0xe3, 0x8000, 0xffff, SRAM - 0x8000); - map_space(0x70, 0x73, 0x8000, 0xffff, SRAM + 0x4000 - 0x8000); - map_space(0xf0, 0xf3, 0x8000, 0xffff, SRAM + 0x4000 - 0x8000); - - map_WRAM(); - - map_WriteProtectROM(); + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) &Memory.FillRAM [0x3000] - 0x3000; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_BWRAM; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_BWRAM; + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + Map [i + 0x400] = (uint8 *) &SRAM [(c << 12) & 0x1ffff]; + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = FALSE; + } + } + + // c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + Map [i + 0xc00] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i + 0xc00] = TRUE; + } + } + + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + WriteProtectROM (); + + // Now copy the map and correct it for the SA1 CPU. + memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); + memmove ((void *) SA1.Map, (void *) Map, sizeof (Map)); + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + SA1.Map [c + 0] = SA1.Map [c + 0x800] = &Memory.FillRAM [0x3000]; + SA1.Map [c + 1] = SA1.Map [c + 0x801] = (uint8 *) MAP_NONE; + SA1.WriteMap [c + 0] = SA1.WriteMap [c + 0x800] = &Memory.FillRAM [0x3000]; + SA1.WriteMap [c + 1] = SA1.WriteMap [c + 0x801] = (uint8 *) MAP_NONE; + } + + // Banks 60->6f + for (c = 0; c < 0x100; c++) + SA1.Map [c + 0x600] = SA1.WriteMap [c + 0x600] = (uint8 *) MAP_BWRAM_BITMAP; + + BWRAM = SRAM; } -void CMemory::Map_SuperFXLoROMMap (void) +void CMemory::LoROM24MBSMap () { - printf("Map_SuperFXLoROMMap\n"); - map_System(); - - // Replicate the first 2Mb of the ROM at ROM + 2MB such that each 32K - // block is repeated twice in each 64K block. - for (int c = 0; c < 64; c++) - { - memmove(&ROM[0x200000 + c * 0x10000], &ROM[c * 0x8000], 0x8000); - memmove(&ROM[0x208000 + c * 0x10000], &ROM[c * 0x8000], 0x8000); - } - - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - - map_hirom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); - - map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000); - map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000); - map_space(0x70, 0x70, 0x0000, 0xffff, SRAM); - map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x10000); - - map_WRAM(); - - map_WriteProtectROM(); + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x200; c += 16) + { + Map [c + 0x800] = RAM; + Map [c + 0x801] = RAM; + BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 0x807] = (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i + 0x800] = &ROM [c << 11] - 0x8000 + 0x200000; + BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 8; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000]; + + for (i = c + 8; i < c + 16; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000 - 0x8000]; + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + MapExtraRAM (); + WriteProtectROM (); } -void CMemory::Map_SetaDSPLoROMMap (void) +void CMemory::SufamiTurboLoROMMap () { - printf("Map_SetaDSPLoROMMap\n"); - map_System(); - - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x40, 0x7f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_lorom(0xc0, 0xff, 0x8000, 0xffff, CalculatedSize); - - map_SetaDSP(); - - map_LoROMSRAM(); - map_WRAM(); - - map_WriteProtectROM(); + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 8; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000]; + + for (i = c + 8; i < c + 16; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000 - 0x8000]; + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + if (Settings.DSP1Master) + { + for (c = 0; c < 0x100; c++) + { + Map [c + 0xe00] = (uint8 *) MAP_DSP; + BlockIsROM [c + 0xe00] = FALSE; + } + } + + // Banks 7e->7f, RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + + // Banks 60->67, S-RAM + for (c = 0; c < 0x80; c++) + { + Map [c + 0x600] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [c + 0x600] = TRUE; + BlockIsROM [c + 0x600] = FALSE; + } + + WriteProtectROM (); } -void CMemory::Map_SDD1LoROMMap (void) +#if 0 + +//untested!! +void CMemory::SameGameMap () { - printf("Map_SDD1LoROMMap\n"); - map_System(); + int i; + int c; + int j; + + int mask[4]; + int mask2[4]; + for (j=0; j<4; j++) + mask[j]=mask2[j]=0x00ff; + + mask[0]=(CalculatedSize/0x10000)-1; + mask2[0]=(Slot1Size/0x10000)-1; + + int x; + bool foundZeros; + bool pastZeros; + + for(j=0;j<3;j++) + { + x=1; + foundZeros=false; + pastZeros=false; - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); + mask[j+1]=mask[j]; - map_hirom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); // will be overwritten dynamically + while (x>0x100&&!pastZeros) + { + if(mask[j]&x) + { + x<<=1; + if(foundZeros) + pastZeros=true; + } + else + { + foundZeros=true; + pastZeros=false; + mask[j+1]|=x; + x<<=1; + } + } + } - map_index(0x70, 0x7f, 0x0000, 0x7fff, MAP_LOROM_SRAM, MAP_TYPE_RAM); + for(j=0;j<3;j++) + { + x=1; + foundZeros=false; + pastZeros=false; - map_WRAM(); + mask2[j+1]=mask2[j]; - map_WriteProtectROM(); -} + while (x>0x100&&!pastZeros) + { + if(mask2[j]&x) + { + x<<=1; + if(foundZeros) + pastZeros=true; + } + else + { + foundZeros=true; + pastZeros=false; + mask2[j+1]|=x; + x<<=1; + } + } + } -void CMemory::Map_SA1LoROMMap (void) -{ - printf("Map_SA1LoROMMap\n"); - map_System(); - map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + } + + // Banks 30->3f and b0->bf, address ranges 6000->7fff is S-RAM. + for (c = 0; c < 16; c++) + { + Map [0x306 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0x307 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0xb06 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0xb07 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + BlockIsRAM [0x306 + (c << 4)] = TRUE; + BlockIsRAM [0x307 + (c << 4)] = TRUE; + BlockIsRAM [0xb06 + (c << 4)] = TRUE; + BlockIsRAM [0xb07 + (c << 4)] = TRUE; + } - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); + for c=0; c<0x200; c+=16) + { + for(i=0;i<8;i++) + { + int e=3; + int d=c>>4; + while(d>mask[0]) + { + d&=mask[e]; + e--; + } - map_space(0x00, 0x3f, 0x3000, 0x3fff, FillRAM); - map_space(0x80, 0xbf, 0x3000, 0x3fff, FillRAM); - map_index(0x00, 0x3f, 0x6000, 0x7fff, MAP_BWRAM, MAP_TYPE_I_O); - map_index(0x80, 0xbf, 0x6000, 0x7fff, MAP_BWRAM, MAP_TYPE_I_O); + int f=3; + int g=c>>4; + while(g>mask2[0]) + { + g&=mask2[f]; + f--; + } + + //stuff in HiROM areas + Map[c+0x400+i]=&ROM[d*0x10000]; + Map[c+0xC00+i]=&ROM[d*0x10000]; + //MINI + Map[c+0x600+i]=&ROMOffset1[g*0x10000]; + Map[c+0xE00+i]=&ROMOffset1[g*0x10000]; - for (int c = 0x40; c < 0x80; c++) - map_space(c, c, 0x0000, 0xffff, SRAM + (c & 1) * 0x10000); + } + for(i=8;i<16;i++) + { + int e=3; + int d=c>>4; + while(d>mask[0]) + { + d&=mask[e]; + e--; + } - map_WRAM(); + int f=3; + int g=c>>4; + while(g>mask2[0]) + { + g&=mask2[f]; + f--; + } - map_WriteProtectROM(); + + //all stuff + //BASE + Map[c+i]=&ROM[d*0x10000]; + Map[c+0x800+i]=&ROM[d*0x10000]; + Map[c+0x400+i]=&ROM[d*0x10000]; + Map[c+0xC00+i]=&ROM[d*0x10000]; + //MINI + Map[c+0x200+i]=&ROMOffset1[g*0x10000]; + Map[c+0xA00+i]=&ROMOffset1[g*0x10000]; + Map[c+0x600+i]=&ROMOffset1[g*0x10000]; + Map[c+0xE00+i]=&ROMOffset1[g*0x10000]; + } - // Now copy the map and correct it for the SA1 CPU. - memmove((void *) SA1.Map, (void *) Map, sizeof(Map)); - memmove((void *) SA1.WriteMap, (void *) WriteMap, sizeof(WriteMap)); + } - // SA-1 Banks 00->3f and 80->bf - for (int c = 0x000; c < 0x400; c += 0x10) + int bankmax=0x40+ (1<<(ROMSize-6)); + //safety for corrupt headers + if(bankmax > 128) + bankmax = 0x80; + int sum=0; + for(i=0x40;i6f - for (int c = 0x600; c < 0x700; c++) - SA1.Map[c] = SA1.WriteMap[c] = (uint8 *) MAP_BWRAM_BITMAP; - - BWRAM = SRAM; + MapRAM (); + WriteProtectROM (); } -void CMemory::Map_HiROMMap (void) -{ - printf("Map_HiROMMap\n"); - map_System(); - - map_hirom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_hirom(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize); - map_hirom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_hirom(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize); - if (Settings.DSP1Master) - map_DSP(); +//Untested!! +void CMemory::GNextROMMap () +{ + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) &Memory.FillRAM [0x3000] - 0x3000; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_BWRAM; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_BWRAM; + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + - map_HiROMSRAM(); - map_WRAM(); + // Banks 40->4f (was 7f, but SNES docs and GNext overdumping shows nothing here.) + for (c = 0; c < 0x100; c += 16) + { + for (i = c; i < c + 16; i++) + Map [i + 0x400] = (uint8 *) &SRAM [(c << 12) & 0x1ffff]; + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = FALSE; + } + } + + for (c = 0; c < 0x100; c += 16) + { + for (i = c; i < c + 16; i++) + Map [i + 0x700] = (uint8 *) &ROMOffset1 [(c << 12) & (Slot1Size-1)]; + } - map_WriteProtectROM(); + // c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + Map [i + 0xc00] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i + 0xc00] = TRUE; + } + } + + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + WriteProtectROM (); + + // Now copy the map and correct it for the SA1 CPU. + memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap)); + memmove ((void *) SA1.Map, (void *) Map, sizeof (Map)); + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + SA1.Map [c + 0] = SA1.Map [c + 0x800] = &Memory.FillRAM [0x3000]; + SA1.Map [c + 1] = SA1.Map [c + 0x801] = (uint8 *) MAP_NONE; + SA1.WriteMap [c + 0] = SA1.WriteMap [c + 0x800] = &Memory.FillRAM [0x3000]; + SA1.WriteMap [c + 1] = SA1.WriteMap [c + 0x801] = (uint8 *) MAP_NONE; + } + + // Banks 60->6f + for (c = 0; c < 0x100; c++) + SA1.Map [c + 0x600] = SA1.WriteMap [c + 0x600] = (uint8 *) MAP_BWRAM_BITMAP; + + BWRAM = SRAM; } -void CMemory::Map_ExtendedHiROMMap (void) +void CMemory::SufamiTurboAltROMMap () { - printf("Map_ExtendedHiROMMap\n"); - map_System(); + int c; + int i; + + if(Slot1Size!=0) + Slot1SRAMSize=(1<<((uint8)ROMOffset1[0x32]))*1024; + else Slot1Size=0x8000; + if(Slot2Size!=0) + Slot2SRAMSize=(1<<((uint8)ROMOffset2[0x32]))*1024; +else Slot2Size=0x8000; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + +// for (i = c + 8; i < c + 16; i++) +// { +// Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; +// BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; +// } + + } - map_hirom_offset(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize - 0x400000, 0x400000); - map_hirom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize - 0x400000, 0x400000); - map_hirom_offset(0x80, 0xbf, 0x8000, 0xffff, 0x400000, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, 0x400000, 0); + //Map Bios - map_HiROMSRAM(); - map_WRAM(); + for (c=0; c<0x200; c+=16) + { + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [((c>>4)*0x8000)%CalculatedSize] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } - map_WriteProtectROM(); -} + } + -void CMemory::Map_SameGameHiROMMap (void) -{ - printf("Map_SameGameHiROMMap\n"); - map_System(); - - map_hirom_offset(0x00, 0x1f, 0x8000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_hirom_offset(0x20, 0x3f, 0x8000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_hirom_offset(0x60, 0x7f, 0x0000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - map_hirom_offset(0x80, 0x9f, 0x8000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_hirom_offset(0xa0, 0xbf, 0x8000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - map_hirom_offset(0xc0, 0xdf, 0x0000, 0xffff, Multi.cartSizeA, Multi.cartOffsetA); - map_hirom_offset(0xe0, 0xff, 0x0000, 0xffff, Multi.cartSizeB, Multi.cartOffsetB); - - map_HiROMSRAM(); - map_WRAM(); - - map_WriteProtectROM(); -} + for (c=0x200; c<0x400; c+=16) + { + for (i = c + 8; i < c + 16; i++) + { + if(Slot1Size!=0) + { + Map [i] = Map [i + 0x800] = &ROMOffset1 [(((c>>4)*0x8000)%Slot1Size)] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + else Map [i] = Map [i + 0x800] = (uint8*)MAP_NONE; + } -void CMemory::Map_SPC7110HiROMMap (void) -{ - printf("Map_SPC7110HiROMMap\n"); - map_System(); + } - map_hirom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize); - map_hirom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize); - map_hirom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); + for (c=0x400; c<0x600; c+=16) + { + for (i = c; i < c + 8; i++) + { + if(Slot2Size!=0) + { + Map [i] = Map [i + 0x800] = &ROMOffset2[(((c>>4)*0x8000)%Slot2Size)]; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + else Map [i] = Map [i + 0x800] = (uint8*)MAP_NONE; - map_index(0x50, 0x50, 0x0000, 0xffff, MAP_SPC7110_DRAM, MAP_TYPE_ROM); - map_index(0xd0, 0xff, 0x0000, 0xffff, MAP_SPC7110_ROM, MAP_TYPE_ROM); + } + for (i = c + 8; i < c + 16; i++) + { + if(Slot2Size!=0) + { + Map [i] = Map [i + 0x800] = &ROMOffset2[(((c>>4)*0x8000)%Slot2Size)] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + else Map [i] = Map [i + 0x800] = (uint8*)MAP_NONE; - map_index(0x00, 0x3f, 0x6000, 0x7fff, MAP_HIROM_SRAM, MAP_TYPE_RAM); + } - map_WRAM(); + } - map_WriteProtectROM(); + // Banks 60->67 (7F?), S-RAM + if(Slot1SRAMSize!=0) + { + for (c = 0; c < 0x100; c++) + { + Map [c + 0xE00] = Map [c + 0x600] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [c + 0xE00] = BlockIsRAM [c + 0x600] = TRUE; + BlockIsROM [c + 0xE00] = BlockIsROM [c + 0x600] = FALSE; + } + } + if(Slot2SRAMSize!=0) + { + for (c = 0; c < 0x100; c++) + { + Map [c + 0xF00] = Map [c + 0x700] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [c + 0xF00] = BlockIsRAM [c + 0x700] = TRUE; + BlockIsROM [c + 0xF00] = BlockIsROM [c + 0x700] = FALSE; + } + } + + // Banks 7e->7f, RAM + for (c = 0; c < 16; c++) + { + Map [c + 0x7e0] = RAM; + Map [c + 0x7f0] = RAM + 0x10000; + BlockIsRAM [c + 0x7e0] = TRUE; + BlockIsRAM [c + 0x7f0] = TRUE; + BlockIsROM [c + 0x7e0] = FALSE; + BlockIsROM [c + 0x7f0] = FALSE; + } + + WriteProtectROM (); } +#endif -// checksum -uint16 CMemory::checksum_calc_sum (uint8 *data, uint32 length) +void CMemory::SRAM512KLoROMMap () { - uint16 sum = 0; - - for (uint32 i = 0; i < length; i++) - sum += data[i]; - - return (sum); + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [c << 11] - 0x8000; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 8; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000]; + + for (i = c + 8; i < c + 16; i++) + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 11) + 0x200000 - 0x8000]; + + for (i = c; i < c + 16; i++) + { + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + MapExtraRAM (); + WriteProtectROM (); } -uint16 CMemory::checksum_mirror_sum (uint8 *start, uint32 &length, uint32 mask) +void CMemory::JumboLoROMMap (bool8 Interleaved) { - // from NSRT - while (!(length & mask)) - mask >>= 1; - - uint16 part1 = checksum_calc_sum(start, mask); - uint16 part2 = 0; - - uint32 next_length = length - mask; - if (next_length) - { - part2 = checksum_mirror_sum(start + mask, next_length, mask >> 1); + int c; + int i; + + uint32 OFFSET0 = 0x400000; + uint32 OFFSET1 = 0x400000; + uint32 OFFSET2 = 0x000000; + + if (Interleaved) + { + OFFSET0 = 0x000000; + OFFSET1 = 0x000000; + OFFSET2 = CalculatedSize-0x400000; //changed to work with interleaved DKJM2. + } + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + if (Settings.DSP1Master) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_DSP; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_DSP; + } + else if (Settings.C4) + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_C4; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_C4; + } + else + { + Map [c + 6] = Map [c + 0x806] = (uint8 *) MAP_NONE; + Map [c + 7] = Map [c + 0x807] = (uint8 *) MAP_NONE; + } + + for (i = c + 8; i < c + 16; i++) + { + Map [i]= &ROM [((c << 11) % (CalculatedSize - 0x400000)) + OFFSET0] - 0x8000; + Map [i + 0x800] = &ROM [((c << 11) % (0x400000)) + OFFSET2] - 0x8000; + BlockIsROM [i + 0x800] = BlockIsROM [i] = TRUE; + } + } + + if (Settings.DSP1Master) + { + // Banks 30->3f and b0->bf + for (c = 0x300; c < 0x400; c += 16) + { + for (i = c + 8; i < c + 16; i++) + { + Map [i + 0x800] = (uint8 *) MAP_DSP; + BlockIsROM [i] = BlockIsROM [i + 0x800] = FALSE; + } + } + } + + // Banks 40->7f and c0->ff + for (c = 0x400; c < 0x800; c += 16) + { + //updated mappings to correct A15 mirroring + for (i = c; i < c + 8; i++) + { + Map [i]= &ROM [((c << 11) % (CalculatedSize - 0x400000)) + OFFSET0]; + Map [i + 0x800] = &ROM [((c << 11) % 0x400000) +OFFSET2]; + } - while (next_length < mask) + for (i = c + 8; i < c + 16; i++) + { + Map [i]= &ROM [((c << 11) % (CalculatedSize - 0x400000)) + OFFSET0] - 0x8000; + Map [i + 0x800] = &ROM [((c << 11) % 0x400000) + OFFSET2 ] - 0x8000; + } + + for (i = c; i < c + 16; i++) { - next_length += next_length; - part2 += part2; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; } + } - length = mask + mask; + //ROM type has to be 64 Mbit header! + int sum=0, k,l; + for(k=0;k<256;k++) + { + uint8* bank=0x8000+Map[8+(k<<4)];//use upper half of the banks, and adjust for LoROM. + for(l=0;l<0x8000;l++) + sum+=bank[l]; } + CalculatedChecksum=sum&0xFFFF; - return (part1 + part2); + MapRAM (); + WriteProtectROM (); } -void CMemory::Checksum_Calculate (void) +void CMemory::SPC7110HiROMMap () { - // from NSRT - uint16 sum = 0; - - if (Settings.BS && !Settings.BSXItself) - sum = checksum_calc_sum(ROM, CalculatedSize) - checksum_calc_sum(ROM + (HiROM ? 0xffb0 : 0x7fb0), 48); - else - if (Settings.SPC7110) + int c; + int i; + + // Banks 00->3f and 80->bf + for (c = 0; c < 0x400; c += 16) + { + Map [c + 0] = Map [c + 0x800] = RAM; + BlockIsRAM [c + 0] = BlockIsRAM [c + 0x800] = TRUE; + Map [c + 1] = Map [c + 0x801] = RAM; + BlockIsRAM [c + 1] = BlockIsRAM [c + 0x801] = TRUE; + + Map [c + 2] = Map [c + 0x802] = (uint8 *) MAP_PPU; + Map [c + 3] = Map [c + 0x803] = (uint8 *) MAP_PPU; + Map [c + 4] = Map [c + 0x804] = (uint8 *) MAP_CPU; + Map [c + 5] = Map [c + 0x805] = (uint8 *) MAP_CPU; + + Map [c + 6] /*= Map [c + 0x806]*/ = (uint8 *) MAP_HIROM_SRAM; + Map [c + 7] /*= Map [c + 0x807]*/ = (uint8 *) MAP_HIROM_SRAM; + Map [c + 0x806]=Map [c + 0x807]= (uint8 *) MAP_NONE; + + for (i = c + 8; i < c + 16; i++) + { + Map [i] = Map [i + 0x800] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i] = BlockIsROM [i + 0x800] = TRUE; + } + } + + // Banks 30->3f and b0->bf, address ranges 6000->7fff is S-RAM. + for (c = 0; c < 16; c++) + { + Map [0x306 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0x307 + (c << 4)] = (uint8 *) MAP_HIROM_SRAM; + Map [0xb06 + (c << 4)] = (uint8 *) MAP_NONE; + Map [0xb07 + (c << 4)] = (uint8 *) MAP_NONE; + BlockIsRAM [0x306 + (c << 4)] = TRUE; + BlockIsRAM [0x307 + (c << 4)] = TRUE; + // BlockIsRAM [0xb06 + (c << 4)] = TRUE; + // BlockIsRAM [0xb07 + (c << 4)] = TRUE; + } + + // Banks 40->7f and c0->ff + for (c = 0; c < 0x400; c += 16) + { + for (i = c; i < c + 16; i++) + { + Map [i + 0x400] = Map [i + 0xc00] = &ROM [(c << 12) % CalculatedSize]; + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = TRUE; + } + } + + for (c=0;c<0x10;c++) { - sum = checksum_calc_sum(ROM, CalculatedSize); - if (CalculatedSize == 0x300000) - sum += sum; + Map [0x500+c]=(uint8 *)MAP_SPC7110_DRAM; + BlockIsROM [0x500+c]=TRUE; } - else + + for (c=0;c<0x100;c++) { - if (CalculatedSize & 0x7fff) - sum = checksum_calc_sum(ROM, CalculatedSize); - else - { - uint32 length = CalculatedSize; - sum = checksum_mirror_sum(ROM, length); - } + Map [0xD00+c] = (uint8 *) MAP_SPC7110_ROM; + Map [0xE00+c] = (uint8 *) MAP_SPC7110_ROM; + Map [0xF00+c] = (uint8 *) MAP_SPC7110_ROM; + BlockIsROM [0xD00+c] = BlockIsROM [0xE00+c] = BlockIsROM [0xF00+c] = TRUE; + } + S9xSpc7110Init(); - CalculatedChecksum = sum; +int sum=0; +for(i=0;i<(int)CalculatedSize; i++) +{ + sum+=ROM[i]; } -// information +if(CalculatedSize==0x300000) + sum<<=1; +CalculatedChecksum=sum&0xFFFF; -const char * CMemory::TVStandard (void) -{ - return (Settings.PAL ? "PAL" : "NTSC"); + MapRAM (); + WriteProtectROM (); } - -const char * CMemory::MapType (void) +void CMemory::SPC7110Sram(uint8 newstate) { - return (HiROM ? ((ExtendedFormat != NOPE) ? "ExHiROM": "HiROM") : "LoROM"); + if(newstate&0x80) + { + Memory.Map[6]=(uint8 *)MAP_HIROM_SRAM; + Memory.Map[7]=(uint8 *)MAP_HIROM_SRAM; + Memory.Map[0x306]=(uint8 *)MAP_HIROM_SRAM; + Memory.Map[0x307]=(uint8 *)MAP_HIROM_SRAM; + + + } + else + { + Memory.Map[6]=(uint8 *)MAP_RONLY_SRAM; + Memory.Map[7]=(uint8 *)MAP_RONLY_SRAM; + Memory.Map[0x306]=(uint8 *)MAP_RONLY_SRAM; + Memory.Map[0x307]=(uint8 *)MAP_RONLY_SRAM; + } } - -const char * CMemory::MapMode (void) +const char *CMemory::TVStandard () { - static char str[4]; - - sprintf(str, "%02x", ROMSpeed & ~0x10); - - return (str); + return (Settings.PAL ? "PAL" : "NTSC"); } -const char * CMemory::StaticRAMSize (void) +const char *CMemory::Speed () { - static char str[20]; - - if (SRAMSize > 16) - strcpy(str, "Corrupt"); - else - sprintf(str, "%dKB", (SRAMMask + 1) / 1024); - - return (str); + return (ROMSpeed & 0x10 ? "120ns" : "200ns"); } -const char * CMemory::Size (void) +const char *CMemory::MapType () { - static char str[20]; - - if (Multi.cartType == 4) - strcpy(str, "N/A"); - else - if (ROMSize < 7 || ROMSize - 7 > 23) - strcpy(str, "Corrupt"); - else - sprintf(str, "%dMbits", 1 << (ROMSize - 7)); - - return (str); + return (HiROM ? "HiROM" : "LoROM"); } -const char * CMemory::Revision (void) +const char *CMemory::StaticRAMSize () { - static char str[20]; - - sprintf(str, "1.%d", HiROM ? ((ExtendedFormat != NOPE) ? ROM[0x40ffdb] : ROM[0xffdb]) : ROM[0x7fdb]); - - return (str); + static char tmp [20]; + + if (Memory.SRAMSize > 16) + return ("Corrupt"); + sprintf (tmp, "%dKB", (SRAMMask + 1) / 1024); + return (tmp); } -const char * CMemory::KartContents (void) +const char *CMemory::Size () { - static char str[30]; - static char *contents[3] = { "ROM", "ROM+RAM", "ROM+RAM+BAT" }; - - char chip[16]; - - if (ROMType == 0 && !Settings.BS) - return ("ROM"); - - if (Settings.BS) - strcpy(chip, "+BSX"); - else - if (Settings.SuperFX) - strcpy(chip, "+SuperFX"); - else - if (Settings.SDD1) - strcpy(chip, "+S-DD1"); - else - if (Settings.OBC1) - strcpy(chip, "+OBC1"); - else - if (Settings.SA1) - strcpy(chip, "+SA-1"); - else - if (Settings.SPC7110RTC) - strcpy(chip, "+SPC7110+RTC"); - else - if (Settings.SPC7110) - strcpy(chip, "+SPC7110"); - else - if (Settings.SRTC) - strcpy(chip, "+S-RTC"); - else - if (Settings.C4) - strcpy(chip, "+C4"); - else - if (Settings.SETA == ST_010) - strcpy(chip, "+ST-010"); - else - if (Settings.SETA == ST_011) - strcpy(chip, "+ST-011"); - else - if (Settings.SETA == ST_018) - strcpy(chip, "+ST-018"); - else - if (Settings.DSP1Master) - sprintf(chip, "+DSP%d", DSP1.version + 1); - else - strcpy(chip, ""); - - sprintf(str, "%s%s", contents[(ROMType & 0xf) % 3], chip); - - return (str); + static char tmp [20]; + + if (ROMSize < 7 || ROMSize - 7 > 23) + return ("Corrupt"); + sprintf (tmp, "%dMbits", 1 << (ROMSize - 7)); + return (tmp); } -// hack - -bool8 CMemory::match_na (const char *str) +const char *CMemory::KartContents () { - return (strcmp(ROMName, str) == 0); -} + static char tmp [30]; + static const char *CoPro [16] = { + "DSP", "SuperFX", "OBC1", "SA-1", "S-DD1", "S-RTC", "CoPro#6", + "CoPro#7", "CoPro#8", "CoPro#9", "CoPro#10", "CoPro#11", "CoPro#12", + "CoPro#13", "CoPro#14", "CoPro-Custom" + }; + static const char *Contents [3] = { + "ROM", "ROM+RAM", "ROM+RAM+BAT" + }; + static const char *DSPSel [4] = { + "DSP1", "DSP2", "DSP3", "DSP4" + }; + if (ROMType == 0&&!Settings.BS) + return ("ROM only"); + + sprintf (tmp, "%s", Contents [(ROMType & 0xf) % 3]); + + if(Settings.BS) + sprintf (tmp, "%s+%s", tmp, "BSX"); + else if(Settings.SPC7110&&Settings.SPC7110RTC) + sprintf (tmp, "%s+%s", tmp, "SPC7110+RTC"); + else if(Settings.SPC7110) + sprintf (tmp, "%s+%s", tmp, "SPC7110"); + else if(Settings.C4) + sprintf (tmp, "%s+%s", tmp, "C4"); + else if(Settings.SETA!=0) + { + switch(Settings.SETA) + { + case ST_010: + sprintf (tmp, "%s+%s", tmp, "ST-010"); + break; + case ST_011: + sprintf (tmp, "%s+%s", tmp, "ST-011"); + break; + + case ST_018: + sprintf (tmp, "%s+%s", tmp, "ST-018"); + break; -bool8 CMemory::match_nn (const char *str) -{ - return (strncmp(ROMName, str, strlen(str)) == 0); + } + } + else if ((ROMType & 0xf) >= 3) + { + if (ROMType & 0xf0) + sprintf (tmp, "%s+%s", tmp, CoPro [(ROMType & 0xf0) >> 4]); + else + sprintf (tmp, "%s+%s", tmp, DSPSel [DSP1.version]); + } + + return (tmp); } -bool8 CMemory::match_nc (const char *str) +const char *CMemory::MapMode () { - return (strncasecmp(ROMName, str, strlen(str)) == 0); + static char tmp [4]; + sprintf (tmp, "%02x", ROMSpeed & ~0x10); + return (tmp); } -bool8 CMemory::match_id (const char *str) +const char *CMemory::ROMID () { - return (strncmp(ROMId, str, strlen(str)) == 0); + return (ROMId); } -void CMemory::ApplyROMFixes (void) +void CMemory::ApplyROMFixes () { #ifdef __W32_HEAP - if (_HEAPOK != _heapchk()) + if(_HEAPOK!=_heapchk()) MessageBox(GUI.hWnd, "CMemory::ApplyROMFixes", "Heap Corrupt", MB_OK); #endif - //// Warnings - - // Don't steal my work! -MK - if ((ROMCRC32 == 0x1B4A5616) && match_nn("RUDORA NO HIHOU")) + //don't steal my work! -MK + if(ROMCRC32 == 0x1B4A5616 && strncmp(ROMName, "RUDORA NO HIHOU", 15)==0) { strncpy(ROMName, "THIS SCRIPT WAS STOLEN", 22); - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); } - // Reject strange hacked games - if ((ROMCRC32 == 0x6810aa95) || - (ROMCRC32 == 0x340f23e5) || - (ROMCRC32 == 0x77fd806a) || - (match_nn("HIGHWAY BATTLE 2")) || - (match_na("FX SKIING NINTENDO 96") && (ROM[0x7fda] == 0)) || - (match_nn("HONKAKUHA IGO GOSEI") && (ROM[0xffd5] != 0x31))) - { - Settings.DisplayColor = BUILD_PIXEL(31, 0, 0); - SET_UI_COLOR(255, 0, 0); - } - - //// APU timing hacks :( - - // This game cannot work well anyway - if (match_id("AVCJ")) // Rendering Ranger R2 - { - IAPU.OneCycle = (int32) (15.7 * (1 << SNES_APU_ACCURACY)); - printf("APU OneCycle hack: %d\n", IAPU.OneCycle); - } - - // XXX: All Quintet games? - if (match_na("GAIA GENSOUKI 1 JPN") || // Gaia Gensouki - match_id("JG ") || // Illusion of Gaia - match_id("CQ ")) // Stunt Race FX - { - IAPU.OneCycle = (int32) (13.0 * (1 << SNES_APU_ACCURACY)); - printf("APU OneCycle hack: %d\n", IAPU.OneCycle); - } + /* + HACKS NSRT can fix that we hadn't detected before. +[14:25:13] <@Nach> case 0x0c572ef0: //So called Hook (US)(2648) +[14:25:13] <@Nach> case 0x6810aa95: //Bazooka Blitzkreig swapped sizes hack -handled +[14:25:17] <@Nach> case 0x61E29C06: //The Tick region hack +[14:25:19] <@Nach> case 0x1EF90F74: //Jikkyou Keiba Simulation Stable Star PAL hack +[14:25:23] <@Nach> case 0x4ab225b5: //So called Krusty's Super Fun House (E) +[14:25:25] <@Nach> case 0x77fd806a: //Donkey Kong Country 2 (E) v1.1 bad dump -handled +[14:25:27] <@Nach> case 0x340f23e5: //Donkey Kong Country 3 (U) copier hack - handled + */ - if (match_na("SOULBLADER - 1") || // Soul Blader - match_na("SOULBLAZER - 1 USA") || // Soul Blazer - match_na("SLAP STICK 1 JPN") || // Slap Stick - match_id("E9 ") || // Robotrek - match_nn("ACTRAISER") || // Actraiser - match_nn("ActRaiser-2") || // Actraiser 2 - match_id("AQT") || // Tenchi Souzou, Terranigma - match_id("ATV") || // Tales of Phantasia - match_id("ARF") || // Star Ocean - match_id("APR") || // Zen-Nippon Pro Wrestling 2 - 3-4 Budoukan - match_id("A4B") || // Super Bomberman 4 - match_id("Y7 ") || // U.F.O. Kamen Yakisoban - Present Ban - match_id("Y9 ") || // U.F.O. Kamen Yakisoban - Shihan Ban - match_id("APB") || // Super Bomberman - Panic Bomber W - match_na("DARK KINGDOM") || // Dark Kingdom - match_na("ZAN3 SFC") || // Zan III Spirits - match_na("HIOUDEN") || // Hiouden - Mamono-tachi Tono Chikai - match_na("\xC3\xDD\xBC\xC9\xB3\xC0") || // Tenshi no Uta - match_na("FORTUNE QUEST") || // Fortune Quest - Dice wo Korogase - match_na("FISHING TO BASSING") || // Shimono Masaki no Fishing To Bassing - match_na("OHMONO BLACKBASS") || // Oomono Black Bass Fishing - Jinzouko Hen - match_na("MASTERS") || // Harukanaru Augusta 2 - Masters - match_na("SFC \xB6\xD2\xDD\xD7\xB2\xC0\xDE\xB0") || // Kamen Rider - match_na("ZENKI TENCHIMEIDOU") || // Kishin Douji Zenki - Tenchi Meidou - match_nn("TokyoDome '95Battle 7") || // Shin Nippon Pro Wrestling Kounin '95 - Tokyo Dome Battle 7 - match_nn("SWORD WORLD SFC") || // Sword World SFC/2 - match_nn("LETs PACHINKO(") || // BS Lets Pachinko Nante Gindama 1/2/3/4 - match_nn("THE FISHING MASTER") || // Mark Davis The Fishing Master - match_nn("Parlor") || // Parlor mini/2/3/4/5/6/7, Parlor Parlor!/2/3/4/5 - match_na("HEIWA Parlor!Mini8") || // Parlor mini 8 - match_nn("SANKYO Fever! \xCC\xA8\xB0\xCA\xDE\xB0!")) // SANKYO Fever! Fever! + if(ROMCRC32==0x6810aa95 || ROMCRC32==0x340f23e5 || ROMCRC32==0x77fd806a || + strncmp (ROMName, "HIGHWAY BATTLE 2", 16)==0 || + (strcmp (ROMName, "FX SKIING NINTENDO 96") == 0 && ROM[0x7FDA]==0)) { - IAPU.OneCycle = (int32) (15.0 * (1 << SNES_APU_ACCURACY)); - printf("APU OneCycle hack: %d\n", IAPU.OneCycle); + Settings.DisplayColor=BUILD_PIXEL(31,0,0); + SET_UI_COLOR(255,0,0); } - //// DMA/HDMA timing hacks :( - - Timings.HDMAStart = SNES_HDMA_START_HC + Settings.HDMATimingHack - 100; - Timings.HBlankStart = SNES_HBLANK_START_HC + Timings.HDMAStart - SNES_HDMA_START_HC; + //Ambiguous chip function pointer assignments + DSP1.version=0; - // The HC counter (CPU.Cycles for snes9x) passes over the WRAM refresh point (HC~536) - // while preparing to jump to the IRQ vector address. - // That is to say, the WRAM refresh point is passed over in S9xOpcode_IRQ(). - // Then, HDMA starts just after $210e is half updated, and it causes the flicker of the ground. - // IRQ timing is bad? HDMA timing is bad? else? - if (match_na("GUNDAMW ENDLESSDUEL")) // Shin Kidou Senki Gundam W - Endless Duel + //DSP switching: + if(strncmp(ROMName, "DUNGEON MASTER", 14)==0) { - Timings.HDMAStart -= 10; - Timings.HBlankStart -= 10; - printf("HDMA timing hack: %d\n", Timings.HDMAStart); + //Set DSP-2 + DSP1.version=1; + SetDSP=&DSP2SetByte; + GetDSP=&DSP2GetByte; } - // The delay to sync CPU and DMA which Snes9x cannot emulate. - // Some games need really severe delay timing... - if (match_na("BATTLE GRANDPRIX")) // Battle Grandprix + if(strncmp(ROMName, "SD\x0b6\x0de\x0dd\x0c0\x0de\x0d1GX", 10)==0) // SD Gundam GX { - Timings.DMACPUSync = 20; - printf("DMA sync: %d\n", Timings.DMACPUSync); - } - - //// CPU speed-ups (CPU_Shutdown()) - - // Force disabling a speed-up hack - // Games which spool sound samples between the SNES and sound CPU using - // H-DMA as the sample is playing. - if (match_na("EARTHWORM JIM 2") || // Earth Worm Jim 2 - match_na("PRIMAL RAGE") || // Primal Rage - match_na("CLAY FIGHTER") || // Clay Fighter - match_na("ClayFighter 2") || // Clay Fighter 2 - match_na("WeaponLord") || // Weapon Lord - match_nn("WAR 2410") || // War 2410 - match_id("ARF") || // Star Ocean - match_id("A4WJ") || // Mini Yonku Shining Scorpion - Let's & Go!! - match_nn("NHL") || - match_nc("MADDEN")) - { - if (Settings.Shutdown) - printf("Disabled CPU shutdown hack.\n"); - Settings.Shutdown = FALSE; + //Set DSP-3 + DSP1.version=2; + SetDSP = &DSP3SetByte; + GetDSP = &DSP3GetByte; + DSP3_Reset(); } - // SA-1 - SA1.WaitAddress = 0xffffffff; - SA1.WaitByteAddress1 = NULL; - SA1.WaitByteAddress2 = NULL; - - if (Settings.SA1) + if(strncmp(ROMName, "TOP GEAR 3000", 13)==0 + ||strncmp(ROMName, "PLANETS CHAMP TG3000", 20)==0) { - // Itoi Shigesato no Bass Tsuri No.1 (J) - if (match_id("ZBPJ")) - { - SA1.WaitAddress = 0x0093f1; - SA1.WaitByteAddress1 = FillRAM + 0x304a; - } - - // Daisenryaku Expert WWII (J) - if (match_id("AEVJ")) - { - SA1.WaitAddress = 0x0ed18d; - SA1.WaitByteAddress1 = FillRAM + 0x3000; - } - - // Derby Jockey 2 (J) - if (match_id("A2DJ")) - { - SA1.WaitAddress = 0x008b62; - } - - // Dragon Ball Z - Hyper Dimension (J) - if (match_id("AZIJ")) - { - SA1.WaitAddress = 0x008083; - SA1.WaitByteAddress1 = FillRAM + 0x3020; - } - - // SD Gundam G NEXT (J) - if (match_id("ZX3J")) - { - SA1.WaitAddress = 0x0087f2; - SA1.WaitByteAddress1 = FillRAM + 0x30c4; - } - - // Shougi no Hanamichi (J) - if (match_id("AARJ")) - { - SA1.WaitAddress = 0xc1f85a; - SA1.WaitByteAddress1 = SRAM + 0x0c64; - SA1.WaitByteAddress2 = SRAM + 0x0c66; - } - - // Asahi Shinbun Rensai Katou Hifumi Kudan Shougi Shingiryu (J) - if (match_id("A23J")) - { - SA1.WaitAddress = 0xc25037; - SA1.WaitByteAddress1 = SRAM + 0x0c06; - SA1.WaitByteAddress2 = SRAM + 0x0c08; - } - - // Taikyoku Igo - Idaten (J) - if (match_id("AIIJ")) - { - SA1.WaitAddress = 0xc100be; - SA1.WaitByteAddress1 = SRAM + 0x1002; - SA1.WaitByteAddress2 = SRAM + 0x1004; - } - - // Takemiya Masaki Kudan no Igo Taishou (J) - if (match_id("AITJ")) - { - SA1.WaitAddress = 0x0080b7; - } - - // J. League '96 Dream Stadium (J) - if (match_id("AJ6J")) - { - SA1.WaitAddress = 0xc0f74a; - } - - // Jumpin' Derby (J) - if (match_id("AJUJ")) - { - SA1.WaitAddress = 0x00d926; - } - - // Kakinoki Shougi (J) - if (match_id("AKAJ")) - { - SA1.WaitAddress = 0x00f070; - } - - // Hoshi no Kirby 3 (J), Kirby's Dream Land 3 (U) - if (match_id("AFJJ") || match_id("AFJE")) - { - SA1.WaitAddress = 0x0082d4; - SA1.WaitByteAddress1 = SRAM + 0x72a4; - } - - // Hoshi no Kirby - Super Deluxe (J) - if (match_id("AKFJ")) - { - SA1.WaitAddress = 0x008c93; - SA1.WaitByteAddress1 = FillRAM + 0x300a; - SA1.WaitByteAddress2 = FillRAM + 0x300e; - } - - // Kirby Super Star (U) - if (match_id("AKFE")) - { - SA1.WaitAddress = 0x008cb8; - SA1.WaitByteAddress1 = FillRAM + 0x300a; - SA1.WaitByteAddress2 = FillRAM + 0x300e; - } - - // Super Mario RPG (J), (U) - if (match_id("ARWJ") || match_id("ARWE")) - { - SA1.WaitAddress = 0xc0816f; - SA1.WaitByteAddress1 = FillRAM + 0x3000; - } - - // Marvelous (J) - if (match_id("AVRJ")) - { - SA1.WaitAddress = 0x0085f2; - SA1.WaitByteAddress1 = FillRAM + 0x3024; - } - - // Harukanaru Augusta 3 - Masters New (J) - if (match_id("AO3J")) - { - SA1.WaitAddress = 0x00dddb; - SA1.WaitByteAddress1 = FillRAM + 0x37b4; - } - - // Jikkyou Oshaberi Parodius (J) - if (match_id("AJOJ")) - { - SA1.WaitAddress = 0x8084e5; - } - - // Super Bomberman - Panic Bomber W (J) - if (match_id("APBJ")) - { - SA1.WaitAddress = 0x00857a; - } - - // Pebble Beach no Hatou New - Tournament Edition (J) - if (match_id("AONJ")) - { - SA1.WaitAddress = 0x00df33; - SA1.WaitByteAddress1 = FillRAM + 0x37b4; - } - - // PGA European Tour (U) - if (match_id("AEPE")) - { - SA1.WaitAddress = 0x003700; - SA1.WaitByteAddress1 = FillRAM + 0x3102; - } - - // PGA Tour 96 (U) - if (match_id("A3GE")) - { - SA1.WaitAddress = 0x003700; - SA1.WaitByteAddress1 = FillRAM + 0x3102; - } - - // Power Rangers Zeo - Battle Racers (U) - if (match_id("A4RE")) + //Set DSP-4 + DSP1.version=3; + SetDSP=&DSP4SetByte; + GetDSP=&DSP4GetByte; + // FIXME: memory map correction + for (int c = 0; c < 0x400; c += 16) { - SA1.WaitAddress = 0x009899; - SA1.WaitByteAddress1 = FillRAM + 0x3000; - } - - // SD F-1 Grand Prix (J) - if (match_id("AGFJ")) - { - SA1.WaitAddress = 0x0181bc; + Map[c + 6] = Map[c + 0x806] = (uint8 *) MAP_NONE; + Map[c + 7] = Map[c + 0x807] = (uint8 *) MAP_NONE; } + WriteProtectROM(); + } - // Saikousoku Shikou Shougi Mahjong (J) - if (match_id("ASYJ")) + //memory map corrections + if(strncmp(ROMName, "XBAND",5)==0) + { + for (int c=0xE00;c<0xE10;c++) { - SA1.WaitAddress = 0x00f2cc; - SA1.WaitByteAddress1 = SRAM + 0x7ffe; - SA1.WaitByteAddress2 = SRAM + 0x7ffc; + Map [c] = (uint8 *) MAP_LOROM_SRAM; + BlockIsRAM [c] = TRUE; + BlockIsROM [c] = FALSE; } + WriteProtectROM (); + } - // Shougi Saikyou II (J) - if (match_id("AX2J")) + //not MAD-1 compliant + if(strcmp (ROMName, "WANDERERS FROM YS") == 0) + { + for(int c=0;c<0xE0;c++) { - SA1.WaitAddress = 0x00d675; + Map[c+0x700]=(uint8*)MAP_LOROM_SRAM; + BlockIsROM[c+0x700]=FALSE; + BlockIsRAM[c+0x700]=TRUE; } + WriteProtectROM(); + } - // Mini Yonku Shining Scorpion - Let's & Go!! (J) - if (match_id("A4WJ")) +#if 0 +// These two games don't have SRAM. Sounds like OpenBus issue... + if (strcmp (ROMName, "GOGO ACKMAN3") == 0 || + strcmp (ROMName, "HOME ALONE") == 0) + { + // Banks 00->3f and 80->bf + for (int c = 0; c < 0x400; c += 16) { - SA1.WaitAddress = 0xc048be; + Map [c + 6] = Map [c + 0x806] = SRAM; + Map [c + 7] = Map [c + 0x807] = SRAM; + BlockIsROM [c + 6] = BlockIsROM [c + 0x806] = FALSE; + BlockIsROM [c + 7] = BlockIsROM [c + 0x807] = FALSE; + BlockIsRAM [c + 6] = BlockIsRAM [c + 0x806] = TRUE; + BlockIsRAM [c + 7] = BlockIsRAM [c + 0x807] = TRUE; } + WriteProtectROM (); + } +#endif - // Shin Shougi Club (J) - if (match_id("AHJJ")) - { - SA1.WaitAddress = 0xc1002a; - SA1.WaitByteAddress1 = SRAM + 0x0806; - SA1.WaitByteAddress2 = SRAM + 0x0808; - } + if (strncmp (ROMName, "BATMAN--REVENGE JOKER", 21) == 0) + { + Memory.HiROM = FALSE; + Memory.LoROM = TRUE; + LoROMMap (); + } + + // Force Disabling a speed-up hack (CPU_Shutdown()) + // Games which spool sound samples between the SNES and sound CPU using + // H-DMA as the sample is playing. + if (strcmp (ROMName, "EARTHWORM JIM 2") == 0 || + strcmp (ROMName, "PRIMAL RAGE") == 0 || + strcmp (ROMName, "CLAY FIGHTER") == 0 || + strcmp (ROMName, "ClayFighter 2") == 0 || + strncasecmp (ROMName, "MADDEN", 6) == 0 || + strncmp (ROMName, "NHL", 3) == 0 || + strcmp (ROMName, "WeaponLord") == 0 || + strncmp(ROMName, "WAR 2410", 8) == 0 || + strncmp (ROMId, "ARF", 3) == 0) // Star Ocean + { + Settings.Shutdown = FALSE; + } + + //APU timing hacks + + // Stunt Racer FX + if (strcmp (ROMId, "CQ ") == 0 || + // Illusion of Gaia + strncmp (ROMId, "JG", 2) == 0 || + strcmp (ROMName, "GAIA GENSOUKI 1 JPN") == 0) + { + IAPU.OneCycle = 13; + } + + // RENDERING RANGER R2 + if (strcmp (ROMId, "AVCJ") == 0 || + //Mark Davis + strncmp(ROMName, "THE FISHING MASTER", 18)==0 || //needs >= actual APU timing. (21 is .002 Mhz slower) + // Star Ocean + strncmp (ROMId, "ARF", 3) == 0 || + // Tales of Phantasia + strncmp (ROMId, "ATV", 3) == 0 || + // Act Raiser 1 & 2 + strncasecmp (ROMName, "ActRaiser", 9) == 0 || + // Soulblazer + strcmp (ROMName, "SOULBLAZER - 1 USA") == 0 || + strcmp (ROMName, "SOULBLADER - 1") == 0 || + + // Terranigma + strncmp (ROMId, "AQT", 3) == 0 || + // Robotrek + strncmp (ROMId, "E9 ", 3) == 0 || + strcmp (ROMName, "SLAP STICK 1 JPN") == 0 || + // ZENNIHON PURORESU2 + strncmp (ROMId, "APR", 3) == 0 || + // Bomberman 4 + strncmp (ROMId, "A4B", 3) == 0 || + // UFO KAMEN YAKISOBAN + strncmp (ROMId, "Y7 ", 3) == 0 || + strncmp (ROMId, "Y9 ", 3) == 0 || + // Panic Bomber World + strncmp (ROMId, "APB", 3) == 0 || + ((strncmp (ROMName, "Parlor", 6) == 0 || + strcmp (ROMName, "HEIWA Parlor!Mini8") == 0 || + strncmp (ROMName, "SANKYO Fever! \xCC\xA8\xB0\xCA\xDE\xB0!", 21) == 0) && //SANKYO Fever! Fever! + strcmp (CompanyId, "A0") == 0) || + strcmp (ROMName, "DARK KINGDOM") == 0 || + strcmp (ROMName, "ZAN3 SFC") == 0 || + strcmp (ROMName, "HIOUDEN") == 0 || + strcmp (ROMName, "\xC3\xDD\xBC\xC9\xB3\xC0") == 0 || //Tenshi no Uta + strcmp (ROMName, "FORTUNE QUEST") == 0 || + strcmp (ROMName, "FISHING TO BASSING") == 0 || + strncmp (ROMName, "TokyoDome '95Battle 7", 21) == 0 || + strcmp (ROMName, "OHMONO BLACKBASS") == 0 || + strncmp (ROMName, "SWORD WORLD SFC", 15) == 0 || + strcmp (ROMName, "MASTERS") ==0 || //Augusta 2 J + strcmp (ROMName, "SFC \xB6\xD2\xDD\xD7\xB2\xC0\xDE\xB0") == 0 || //Kamen Rider + strcmp (ROMName, "ZENKI TENCHIMEIDOU") == 0 || + strncmp (ROMName, "LETs PACHINKO(", 14) == 0) //A set of BS games + { + IAPU.OneCycle = 15; + } + + //Specific game fixes - // rest games: - // Habu Meijin no Omoshiro Shougi (J) - // Hayashi Kaihou Kudan no Igo Taidou (J) - // Shougi Saikyou (J) - // Super Robot Wars Gaiden (J) - // Super Shougi 3 - Kitaihei (J) - } + // for ZSNES SuperFX: is it still necessary? + Settings.WinterGold = strcmp (ROMName, "FX SKIING NINTENDO 96") == 0 || + strcmp (ROMName, "DIRT RACER") == 0; + + //OAM hacks because we don't fully understand the + //behavior of the SNES. + //Totally wacky display... + //seems to need a disproven behavior, so + //we're definitely overlooking some other bug? + if(strncmp(ROMName, "UNIRACERS", 9)==0) + SNESGameFixes.Uniracers=true; + +#if 0 + if (strcmp (ROMName, "\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0") == 0 || //Super Famista + strcmp (ROMName, "\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0 2") == 0 || //Super Famista 2 + strcmp (ROMName, "GANBA LEAGUE") == 0) + { + SNESGameFixes.APU_OutPorts_ReturnValueFix = TRUE; + } +#endif - //// SRAM fixes + //CPU timing hacks + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * Settings.CyclesPercentage) / 100; + Timings.HBlankStart = SNES_HBLANK_START_HC; + Timings.HDMAStart = SNES_HDMA_START_HC; + Timings.RenderPos = SNES_RENDER_START_HC; - if (match_na("HITOMI3")) + //The first new hack since timings were changed :( + if (strncmp(ROMName, "SeikenDensetsu 2", 16) == 0 || + strncmp(ROMName, "Secret of MANA", 14) == 0) { - SRAMSize = 1; - SRAMMask = ((1 << (SRAMSize + 3)) * 128) - 1; + Timings.HBlankStart -= 34; + Timings.HDMAStart -= 34; } - // SRAM value fixes - if (match_na("SUPER DRIFT OUT") || // Super Drift Out - match_na("SATAN IS OUR FATHER!") || - match_na("goemon 4")) // Ganbare Goemon Kirakira Douchuu - SNESGameFixes.SRAMInitialValue = 0x00; - - // Additional game fixes by sanmaiwashi ... - // XXX: unnecessary? - if (match_na("SFX \xC5\xB2\xC4\xB6\xDE\xDD\xC0\xDE\xD1\xD3\xC9\xB6\xDE\xC0\xD8 1")) // SD Gundam Gaiden - Knight Gundam Monogatari - SNESGameFixes.SRAMInitialValue = 0x6b; +/* if(strcmp(ROMName, "HOME IMPROVEMENT")==0) + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 200) / 100; + + if (strcmp (ROMId, "ASRJ") == 0 && Settings.CyclesPercentage == 100) + // Street Racer + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 95) / 100; + + // Power Rangers Fight + if (strncmp (ROMId, "A3R", 3) == 0 || + // Clock Tower + strncmp (ROMId, "AJE", 3) == 0) + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 103) / 100; + + if (strncmp (ROMId, "A3M", 3) == 0 && Settings.CyclesPercentage == 100) + // Mortal Kombat 3. Fixes cut off speech sample + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 110) / 100; + + //Darkness Beyond Twilight + //Crimson beyond blood that flows + //buried in the stream of time + //is where your power grows + //I pledge myself to conquer + //all the foes who stand + //before the might gift betsowed + //in my unworthy hand + if (strcmp (ROMName, "\x0bd\x0da\x0b2\x0d4\x0b0\x0bd\x0de") == 0 && + Settings.CyclesPercentage == 100) + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 101) / 100; + // Start Trek: Deep Sleep 9 + if (strncmp (ROMId, "A9D", 3) == 0 && Settings.CyclesPercentage == 100) + Timings.H_Max = (SNES_CYCLES_PER_SCANLINE * 110) / 100; +*/ + Timings.H_Max_Master = Timings.H_Max; + + //SA-1 Speedup settings + SA1.WaitAddress = 0xffffffff; + SA1.WaitByteAddress1 = NULL; + SA1.WaitByteAddress2 = NULL; + + /* Bass Fishing */ + if (strcmp (ROMId, "ZBPJ") == 0) + { + SA1.WaitAddress = 0x0093f1; + SA1.WaitByteAddress1 = FillRAM + 0x304a; + } + /* DAISENRYAKU EXPERTWW2 */ + if (strcmp (ROMId, "AEVJ") == 0) + { + SA1.WaitAddress = 0x0ed18d; + SA1.WaitByteAddress1 = FillRAM + 0x3000; + } + /* debjk2 */ + if (strcmp (ROMId, "A2DJ") == 0) + { + SA1.WaitAddress = 0x008b62; + } + /* Dragon Ballz HD */ + if (strcmp (ROMId, "AZIJ") == 0) + { + SA1.WaitAddress = 0x008083; + SA1.WaitByteAddress1 = FillRAM + 0x3020; + } + /* SFC SDGUNDAMGNEXT */ + if (strcmp (ROMId, "ZX3J") == 0) + { + SA1.WaitAddress = 0x0087f2; + SA1.WaitByteAddress1 = FillRAM + 0x30c4; + } + /* ShougiNoHanamichi */ + if (strcmp (ROMId, "AARJ") == 0) + { + SA1.WaitAddress = 0xc1f85a; + SA1.WaitByteAddress1 = SRAM + 0x0c64; + SA1.WaitByteAddress2 = SRAM + 0x0c66; + } + /* KATO HIFUMI9DAN SYOGI */ + if (strcmp (ROMId, "A23J") == 0) + { + SA1.WaitAddress = 0xc25037; + SA1.WaitByteAddress1 = SRAM + 0x0c06; + SA1.WaitByteAddress2 = SRAM + 0x0c08; + } + /* idaten */ + if (strcmp (ROMId, "AIIJ") == 0) + { + SA1.WaitAddress = 0xc100be; + SA1.WaitByteAddress1 = SRAM + 0x1002; + SA1.WaitByteAddress2 = SRAM + 0x1004; + } + /* igotais */ + if (strcmp (ROMId, "AITJ") == 0) + { + SA1.WaitAddress = 0x0080b7; + } + /* J96 DREAM STADIUM */ + if (strcmp (ROMId, "AJ6J") == 0) + { + SA1.WaitAddress = 0xc0f74a; + } + /* JumpinDerby */ + if (strcmp (ROMId, "AJUJ") == 0) + { + SA1.WaitAddress = 0x00d926; + } + /* JKAKINOKI SHOUGI */ + if (strcmp (ROMId, "AKAJ") == 0) + { + SA1.WaitAddress = 0x00f070; + } + /* HOSHI NO KIRBY 3 & KIRBY'S DREAM LAND 3 JAP & US */ + if (strcmp (ROMId, "AFJJ") == 0 || strcmp (ROMId, "AFJE") == 0) + { + SA1.WaitAddress = 0x0082d4; + SA1.WaitByteAddress1 = SRAM + 0x72a4; + } + /* KIRBY SUPER DELUXE JAP */ + if (strcmp (ROMId, "AKFJ") == 0) + { + SA1.WaitAddress = 0x008c93; + SA1.WaitByteAddress1 = FillRAM + 0x300a; + SA1.WaitByteAddress2 = FillRAM + 0x300e; + } + /* KIRBY SUPER DELUXE US */ + if (strcmp (ROMId, "AKFE") == 0) + { + SA1.WaitAddress = 0x008cb8; + SA1.WaitByteAddress1 = FillRAM + 0x300a; + SA1.WaitByteAddress2 = FillRAM + 0x300e; + } + /* SUPER MARIO RPG JAP & US */ + if (strcmp (ROMId, "ARWJ") == 0 || strcmp (ROMId, "ARWE") == 0) + { + SA1.WaitAddress = 0xc0816f; + SA1.WaitByteAddress1 = FillRAM + 0x3000; + } + /* marvelous.zip */ + if (strcmp (ROMId, "AVRJ") == 0) + { + SA1.WaitAddress = 0x0085f2; + SA1.WaitByteAddress1 = FillRAM + 0x3024; + } + /* AUGUSTA3 MASTERS NEW */ + if (strcmp (ROMId, "AO3J") == 0) + { + SA1.WaitAddress = 0x00dddb; + SA1.WaitByteAddress1 = FillRAM + 0x37b4; + } + /* OSHABERI PARODIUS */ + if (strcmp (ROMId, "AJOJ") == 0) + { + SA1.WaitAddress = 0x8084e5; + } + /* PANIC BOMBER WORLD */ + if (strcmp (ROMId, "APBJ") == 0) + { + SA1.WaitAddress = 0x00857a; + } + /* PEBBLE BEACH NEW */ + if (strcmp (ROMId, "AONJ") == 0) + { + SA1.WaitAddress = 0x00df33; + SA1.WaitByteAddress1 = FillRAM + 0x37b4; + } + /* PGA EUROPEAN TOUR */ + if (strcmp (ROMId, "AEPE") == 0) + { + SA1.WaitAddress = 0x003700; + SA1.WaitByteAddress1 = FillRAM + 0x3102; + } + /* PGA TOUR 96 */ + if (strcmp (ROMId, "A3GE") == 0) + { + SA1.WaitAddress = 0x003700; + SA1.WaitByteAddress1 = FillRAM + 0x3102; + } + /* POWER RANGERS 4 */ + if (strcmp (ROMId, "A4RE") == 0) + { + SA1.WaitAddress = 0x009899; + SA1.WaitByteAddress1 = FillRAM + 0x3000; + } + /* PACHISURO PALUSUPE */ + if (strcmp (ROMId, "AGFJ") == 0) + { + // Never seems to turn on the SA-1! + } + /* SD F1 GRAND PRIX */ + if (strcmp (ROMId, "AGFJ") == 0) + { + SA1.WaitAddress = 0x0181bc; + } + /* SHOUGI MARJONG */ + if (strcmp (ROMId, "ASYJ") == 0) + { + SA1.WaitAddress = 0x00f2cc; + SA1.WaitByteAddress1 = SRAM + 0x7ffe; + SA1.WaitByteAddress2 = SRAM + 0x7ffc; + } + /* shogisai2 */ + if (strcmp (ROMId, "AX2J") == 0) + { + SA1.WaitAddress = 0x00d675; + } + + /* SHINING SCORPION */ + if (strcmp (ROMId, "A4WJ") == 0) + { + SA1.WaitAddress = 0xc048be; + } + /* SHIN SHOUGI CLUB */ + if (strcmp (ROMId, "AHJJ") == 0) + { + SA1.WaitAddress = 0xc1002a; + SA1.WaitByteAddress1 = SRAM + 0x0806; + SA1.WaitByteAddress2 = SRAM + 0x0808; + } + - // others: BS and ST-01x games are 0x00. + //Other - //// Specific game fixes + // Additional game fixes by sanmaiwashi ... + if (strcmp (ROMName, "SFX \xC5\xB2\xC4\xB6\xDE\xDD\xC0\xDE\xD1\xD3\xC9\xB6\xDE\xC0\xD8 1") == 0) // Gundam Knight Story + { +// bytes0x2000 [0xb18] = 0x4c; +// bytes0x2000 [0xb19] = 0x4b; +// bytes0x2000 [0xb1a] = 0xea; + SNESGameFixes.SRAMInitialValue = 0x6b; + } + + + // HITOMI3 + if (strcmp (ROMName, "HITOMI3") == 0) + { + Memory.SRAMSize = 1; + SRAMMask = Memory.SRAMSize ? + ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0; + } - // for ZSNES SuperFX: is it still necessary? - Settings.WinterGold = match_na("FX SKIING NINTENDO 96") || match_na("DIRT RACER"); + //sram value fixes + if (strcmp (Memory.ROMName, "SUPER DRIFT OUT") == 0 || + strcmp(Memory.ROMName, "SATAN IS OUR FATHER!") == 0 || + strcmp (ROMName, "goemon 4") == 0) + SNESGameFixes.SRAMInitialValue = 0x00; - // OAM hacks because we don't fully understand the behavior of the SNES. - // Totally wacky display in 2P mode... - // seems to need a disproven behavior, so we're definitely overlooking some other bug? - if (match_nn("UNIRACERS")) // Uniracers - { - SNESGameFixes.Uniracers = TRUE; - printf("Applied Uniracers hack.\n"); - } +#if 0 + if(strcmp (ROMName, "XBAND JAPANESE MODEM") == 0) + { + for (c = 0x200; c < 0x400; c += 16) + { + for (int i = c; i < c + 16; i++) + { + Map [i + 0x400] = Map [i + 0xc00] = &ROM[c * 0x1000]; + BlockIsRAM [i + 0x400] = BlockIsRAM [i + 0xc00] = TRUE; + BlockIsROM [i + 0x400] = BlockIsROM [i + 0xc00] = FALSE; + } + } + WriteProtectROM (); + } +#endif - /* - // XXX: What's this? - if (match_na("\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0") || // Super Famista - match_na("\xBD\xB0\xCA\xDF\xB0\xCC\xA7\xD0\xBD\xC0 2") || // Super Famista 2 - match_na("GANBA LEAGUE")) // Hakunetsu Pro Yakyuu - Ganba League - SNESGameFixes.APU_OutPorts_ReturnValueFix = TRUE; - */ +#if 0 +// XXX: wait-and-see... +#define RomPatch(adr,ov,nv) \ + if (ROM [adr] == ov) \ + ROM [adr] = nv + + // Love Quest + if (strcmp (ROMName, "LOVE QUEST") == 0) + { + RomPatch (0x1385ec, 0xd0, 0xea); + RomPatch (0x1385ed, 0xb2, 0xea); + } + //BNE D0 into nops + + //this is a cmp on $00:2140 + // Super Batter Up + if (strcmp (ROMName, "Super Batter Up") == 0) + { + RomPatch (0x27ae0, 0xd0, 0xea); + RomPatch (0x27ae1, 0xfa, 0xea); + } + //BNE +#endif } -#ifndef NGC -// IPS +#ifndef NGC // Read variable size MSB int from a file static long ReadInt (Reader *r, unsigned nbytes) { @@ -3318,7 +4161,7 @@ static long ReadInt (Reader *r, unsigned nbytes) while (nbytes--) { int c = r->get_char(); - if (c == EOF) + if (c == EOF) return -1; v = (v << 8) | (c & 0xFF); } @@ -3329,7 +4172,7 @@ static long ReadInt (Reader *r, unsigned nbytes) #define IPS_EOF 0x00454F46l #ifndef NGC -static bool8 ReadIPSPatch (Reader *r, long offset, int32 &rom_size) +static bool8 ReadIPSPatch(Reader *r, long offset, int32 &rom_size) { char fname[6]; for(int i=0; i<5; i++){ @@ -3355,7 +4198,7 @@ static bool8 ReadIPSPatch (Reader *r, long offset, int32 &rom_size) if (ofs == -1) goto err_eof; - if (ofs == IPS_EOF) + if (ofs == IPS_EOF) break; ofs -= offset; @@ -3373,9 +4216,9 @@ static bool8 ReadIPSPatch (Reader *r, long offset, int32 &rom_size) while (len--) { rchar = r->get_char(); - if (rchar == EOF) + if (rchar == EOF) goto err_eof; - Memory.ROM [ofs++] = (uint8) rchar; + ROM [ofs++] = (uint8) rchar; } if (ofs > rom_size) rom_size = ofs; @@ -3383,24 +4226,24 @@ static bool8 ReadIPSPatch (Reader *r, long offset, int32 &rom_size) else { rlen = ReadInt (r, 2); - if (rlen == -1) + if (rlen == -1) goto err_eof; rchar = r->get_char(); - if (rchar == EOF) + if (rchar == EOF) goto err_eof; if (ofs + rlen > CMemory::MAX_ROM_SIZE) goto err_eof; - while (rlen--) - Memory.ROM [ofs++] = (uint8) rchar; + while (rlen--) + ROM [ofs++] = (uint8) rchar; if (ofs > rom_size) rom_size = ofs; } } - + // Check if ROM image needs to be truncated ofs = ReadInt (r, 3); if (ofs != -1 && ofs - offset < rom_size) @@ -3409,19 +4252,18 @@ static bool8 ReadIPSPatch (Reader *r, long offset, int32 &rom_size) rom_size = ofs - offset; } return 1; - + err_eof: return 0; } + #endif #ifndef NGC - -static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool print) -{ +static int unzFindExtension(unzFile &file, const char *ext, bool restart=true, bool print=true){ int port; int l=strlen(ext); - + if(restart){ port=unzGoToFirstFile(file); } else { @@ -3441,11 +4283,12 @@ static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool } return port; } + #endif #ifndef NGC - -void CMemory::CheckForIPSPatch (const char *rom_filename, bool8 header, int32 &rom_size) +void CMemory::CheckForIPSPatch (const char *rom_filename, bool8 header, + int32 &rom_size) { if(Settings.NoPatch) return; @@ -3666,7 +4509,50 @@ void CMemory::CheckForIPSPatch (const char *rom_filename, bool8 header, int32 &r if(flag) return; } } + #endif + +void CMemory::ParseSNESHeader(uint8 *RomHeader) +{ + bool8 bs = Settings.BS & !Settings.BSXItself; + + strncpy(ROMName, (char *) &RomHeader[0x10], ROM_NAME_LEN - 1); + if (bs) + memset(ROMName + 16, 0x20, ROM_NAME_LEN - 17); + + if (bs) + { + if (!(((RomHeader[0x29] & 0x20) && CalculatedSize < 0x100000) || + (!(RomHeader[0x29] & 0x20) && CalculatedSize == 0x100000))) + printf("BS: Size mismatch\n"); + + // FIXME + int p = 0; + while ((1 << p) < (int) CalculatedSize) + p++; + ROMSize = p - 10; + } + else + ROMSize = RomHeader[0x27]; + + Memory.SRAMSize = bs ? 5 /* BS-X */: RomHeader[0x28]; + + ROMSpeed = bs ? RomHeader[0x28] : RomHeader[0x25]; + ROMType = bs ? 0xE5 /* BS-X */ : RomHeader[0x26]; + ROMRegion = bs ? 0 : RomHeader[0x29]; + + ROMChecksum = RomHeader[0x2E] + (RomHeader[0x2F] << 8); + ROMComplementChecksum = RomHeader[0x2C] + (RomHeader[0x2D] << 8); + + memmove(ROMId, &RomHeader[0x02], 4); + + if (RomHeader[0x2A] == 0x33) + memmove(CompanyId, &RomHeader[0x00], 2); + else + sprintf(CompanyId, "%02X", RomHeader[0x2A]); +} + #undef INLINE #define INLINE #include "getset.h" + diff --git a/source/snes9x/memmap.h b/source/snes9x/memmap.h index 4eb8e676..f4d3ddf6 100644 --- a/source/snes9x/memmap.h +++ b/source/snes9x/memmap.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,242 +142,191 @@ **********************************************************************************/ - #ifndef _memmap_h_ #define _memmap_h_ #include "snes9x.h" -#define MEMMAP_BLOCK_SIZE (0x1000) -#define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE) -#define MEMMAP_SHIFT (12) -#define MEMMAP_MASK (MEMMAP_BLOCK_SIZE - 1) -#define MEMMAP_MAX_SDD1_LOGGED_ENTRIES (0x10000 / 8) - -struct CMemory -{ - enum - { MAX_ROM_SIZE = 0x800000 }; - - enum file_formats - { FILE_ZIP, FILE_JMA, FILE_DEFAULT }; - - enum - { NOPE, YEAH, BIGFIRST, SMALLFIRST }; - - enum - { MAP_TYPE_I_O, MAP_TYPE_ROM, MAP_TYPE_RAM }; - - enum - { - MAP_PPU, - MAP_CPU, - MAP_LOROM_SRAM, - MAP_LOROM_SRAM_B, - MAP_HIROM_SRAM, - MAP_DSP, - MAP_C4, - MAP_BWRAM, - MAP_BWRAM_BITMAP, - MAP_BWRAM_BITMAP2, - MAP_SA1RAM, - MAP_SPC7110_ROM, - MAP_SPC7110_DRAM, - MAP_RONLY_SRAM, - MAP_OBC_RAM, - MAP_SETA_DSP, - MAP_SETA_RISC, - MAP_BSX, - MAP_NONE, - MAP_DEBUG, - MAP_LAST - }; - - uint8 NSRTHeader[32]; - int32 HeaderCount; - - uint8 *RAM; - uint8 *ROM; - uint8 *SRAM; - uint8 *VRAM; - uint8 *FillRAM; - uint8 *BWRAM; - uint8 *C4RAM; - uint8 *BSRAM; - uint8 *BIOSROM; - - uint8 *Map[MEMMAP_NUM_BLOCKS]; - uint8 *WriteMap[MEMMAP_NUM_BLOCKS]; - uint8 BlockIsRAM[MEMMAP_NUM_BLOCKS]; - uint8 BlockIsROM[MEMMAP_NUM_BLOCKS]; - uint8 MemorySpeed[MEMMAP_NUM_BLOCKS]; - uint8 ExtendedFormat; - - char ROMFilename[_MAX_PATH + 1]; - char ROMName[ROM_NAME_LEN]; - char RawROMName[ROM_NAME_LEN]; - char ROMId[5]; - char CompanyId[3]; - uint8 ROMRegion; - uint8 ROMSpeed; - uint8 ROMType; - uint8 ROMSize; - uint32 ROMChecksum; - uint32 ROMComplementChecksum; - uint32 ROMCRC32; - int32 ROMFramesPerSecond; - - bool8 HiROM; - bool8 LoROM; - uint8 SRAMSize; - uint32 SRAMMask; - uint32 CalculatedSize; - uint32 CalculatedChecksum; - - uint8 *SDD1Index; - uint8 *SDD1Data; - uint32 SDD1Entries; - uint32 SDD1LoggedDataCountPrev; - uint32 SDD1LoggedDataCount; - uint8 SDD1LoggedData[MEMMAP_MAX_SDD1_LOGGED_ENTRIES]; - - // ports can assign this to perform some custom action upon loading a ROM (such as adjusting controls) - void (*PostRomInitFunc) (); - - bool8 Init (void); - void Deinit (void); - void FreeSDD1Data (void); - - int ScoreHiROM (bool8, int32 romoff = 0); - int ScoreLoROM (bool8, int32 romoff = 0); - uint32 HeaderRemove (uint32, int32 &, uint8 *); - uint32 FileLoader (uint8 *, const char *, int32); - bool8 LoadROM (const char *); - bool8 LoadMultiCart (const char *, const char *); - bool8 LoadSufamiTurbo (const char *, const char *); - bool8 LoadSameGame (const char *, const char *); - bool8 LoadLastROM (void); - bool8 LoadSRAM (const char *); - bool8 SaveSRAM (const char *); - void ClearSRAM (bool8 onlyNonSavedSRAM = 0); - - char * Safe (const char *); - char * SafeANK (const char *); - void ParseSNESHeader (uint8 *); - void InitROM (void); - void FixROMSpeed (void); - void ResetSpeedMap (void); - - uint32 map_mirror (uint32, uint32); - void map_lorom (uint32, uint32, uint32, uint32, uint32); - void map_hirom (uint32, uint32, uint32, uint32, uint32); - void map_lorom_offset (uint32, uint32, uint32, uint32, uint32, uint32); - void map_hirom_offset (uint32, uint32, uint32, uint32, uint32, uint32); - void map_space (uint32, uint32, uint32, uint32, uint8 *); - void map_index (uint32, uint32, uint32, uint32, int, int); - void map_System (void); - void map_WRAM (void); - void map_LoROMSRAM (void); - void map_HiROMSRAM (void); - void map_DSP (void); - void map_C4 (void); - void map_OBC1 (void); - void map_SetaRISC (void); - void map_SetaDSP (void); - void map_WriteProtectROM (void); - void Map_Initialize (void); - void Map_LoROMMap (void); - void Map_NoMAD1LoROMMap (void); - void Map_JumboLoROMMap (void); - void Map_ROM24MBSLoROMMap (void); - void Map_SRAM512KLoROMMap (void); - void Map_SufamiTurboLoROMMap (void); - void Map_SufamiTurboPseudoLoROMMap (void); - void Map_SuperFXLoROMMap (void); - void Map_SetaDSPLoROMMap (void); - void Map_SDD1LoROMMap (void); - void Map_SA1LoROMMap (void); - void Map_HiROMMap (void); - void Map_ExtendedHiROMMap (void); - void Map_SameGameHiROMMap (void); - void Map_SPC7110HiROMMap (void); - - uint16 checksum_calc_sum (uint8 *, uint32); - uint16 checksum_mirror_sum (uint8 *, uint32 &, uint32 mask = 0x800000); - void Checksum_Calculate (void); - - bool8 match_na (const char *); - bool8 match_nn (const char *); - bool8 match_nc (const char *); - bool8 match_id (const char *); - void ApplyROMFixes (void); - void CheckForIPSPatch (const char *, bool8, int32 &); - - const char * TVStandard (void); - const char * MapType (void); - const char * MapMode (void); - const char * StaticRAMSize (void); - const char * Size (void); - const char * Revision (void); - const char * KartContents (void); -}; - -struct SMulti -{ - int cartType; - int32 cartSizeA, cartSizeB; - int32 sramSizeA, sramSizeB; - uint32 sramMaskA, sramMaskB; - uint32 cartOffsetA, cartOffsetB; - uint8 *sramA, *sramB; - char fileNameA[_MAX_PATH + 1], fileNameB[_MAX_PATH + 1]; +#define MEMMAP_BLOCK_SIZE (0x1000) +#define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE) +#define MEMMAP_BLOCKS_PER_BANK (0x10000 / MEMMAP_BLOCK_SIZE) +#define MEMMAP_SHIFT 12 +#define MEMMAP_MASK (MEMMAP_BLOCK_SIZE - 1) +#define MEMMAP_MAX_SDD1_LOGGED_ENTRIES (0x10000 / 8) + +//Extended ROM Formats +#define NOPE 0 +#define YEAH 1 +#define BIGFIRST 2 +#define SMALLFIRST 3 + +//File Formats go here +enum file_formats { FILE_ZIP, FILE_RAR, FILE_JMA, FILE_DEFAULT }; + +class CMemory { +public: + bool8 LoadROM (const char *); + uint32 FileLoader (uint8* buffer, const char* filename, int32 maxsize); + void InitROM (bool8); + bool8 LoadSRAM (const char *); + bool8 SaveSRAM (const char *); + bool8 Init (); + void Deinit (); + void FreeSDD1Data (); + + void WriteProtectROM (); + void FixROMSpeed (); + void MapRAM (); + void MapExtraRAM (); + char *Safe (const char *); + char *SafeANK (const char *); + + void JumboLoROMMap (bool8); + void LoROMMap (); + void LoROM24MBSMap (); + void SRAM512KLoROMMap (); +// void SRAM1024KLoROMMap (); + void SufamiTurboLoROMMap (); + void HiROMMap (); + void SuperFXROMMap (); + void TalesROMMap (bool8); + void AlphaROMMap (); + void SA1ROMMap (); + void SPC7110HiROMMap(); + void SPC7110Sram(uint8); + void SetaDSPMap(); + bool8 AllASCII (uint8 *b, int size); + int ScoreHiROM (bool8 skip_header, int32 offset=0); + int ScoreLoROM (bool8 skip_header, int32 offset=0); +#if 0 + void SufamiTurboAltROMMap(); +#endif + void ApplyROMFixes (); + void CheckForIPSPatch (const char *rom_filename, bool8 header, + int32 &rom_size); + + const char *TVStandard (); + const char *Speed (); + const char *StaticRAMSize (); + const char *MapType (); + const char *MapMode (); + const char *KartContents (); + const char *Size (); + const char *Headers (); + const char *ROMID (); + const char *CompanyID (); + void ParseSNESHeader(uint8*); + enum { + MAP_PPU, MAP_CPU, MAP_DSP, MAP_LOROM_SRAM, MAP_HIROM_SRAM, + MAP_NONE, MAP_DEBUG, MAP_C4, MAP_BWRAM, MAP_BWRAM_BITMAP, + MAP_BWRAM_BITMAP2, MAP_SA1RAM, MAP_SPC7110_ROM, MAP_SPC7110_DRAM, + MAP_RONLY_SRAM, MAP_OBC_RAM, MAP_SETA_DSP, MAP_SETA_RISC, MAP_BSX, MAP_LAST + }; + enum { MAX_ROM_SIZE = 0x800000 }; + + uint8 *RAM; + uint8 *ROM; + uint8 *VRAM; + uint8 *SRAM; + uint8 *BWRAM; + uint8 *FillRAM; + uint8 *C4RAM; + bool8 HiROM; + bool8 LoROM; + uint32 SRAMMask; + uint8 SRAMSize; + uint8 *Map [MEMMAP_NUM_BLOCKS]; + uint8 *WriteMap [MEMMAP_NUM_BLOCKS]; + uint8 MemorySpeed [MEMMAP_NUM_BLOCKS]; + uint8 BlockIsRAM [MEMMAP_NUM_BLOCKS]; + uint8 BlockIsROM [MEMMAP_NUM_BLOCKS]; + char ROMName [ROM_NAME_LEN]; + char RawROMName [ROM_NAME_LEN]; + char ROMId [5]; + char CompanyId [3]; + uint8 ROMSpeed; + uint8 ROMType; + uint8 ROMSize; + int32 ROMFramesPerSecond; + int32 HeaderCount; + uint32 CalculatedSize; + uint32 CalculatedChecksum; + uint32 ROMChecksum; + uint32 ROMComplementChecksum; + uint8 *SDD1Index; + uint8 *SDD1Data; + uint32 SDD1Entries; + uint32 SDD1LoggedDataCountPrev; + uint32 SDD1LoggedDataCount; + uint8 SDD1LoggedData [MEMMAP_MAX_SDD1_LOGGED_ENTRIES]; + char ROMFilename [_MAX_PATH]; + uint8 ROMRegion; + uint32 ROMCRC32; + uint8 ExtendedFormat; +#if 0 + bool8 SufamiTurbo; + char Slot1Filename [_MAX_PATH]; + char Slot2Filename [_MAX_PATH]; + uint8* ROMOffset1; + uint8* ROMOffset2; + uint8* SRAMOffset1; + uint8* SRAMOffset2; + uint32 Slot1Size; + uint32 Slot2Size; + uint32 Slot1SRAMSize; + uint32 Slot2SRAMSize; + uint8 SlotContents; +#endif + uint8 *BSRAM; + uint8 *BIOSROM; + void ResetSpeedMap(); +#if 0 + bool8 LoadMulti (const char *,const char *,const char *); +#endif }; START_EXTERN_C -extern CMemory Memory; -extern SMulti Multi; -#if defined(ZSNES_FX) || defined(ZSNES_C4) -extern uint8 *ROM; -extern uint8 *SRAM; -extern uint8 *RegRAM; -#endif -bool8 LoadZip(const char *, int32 *, int32 *, uint8 *); +extern CMemory Memory; +extern uint8 *SRAM; +extern uint8 *ROM; +extern uint8 *RegRAM; +void S9xDeinterleaveMode2 (); +bool8 LoadZip(const char* zipname, + int32 *TotalFileSize, + int32 *headers, + uint8 *buffer); END_EXTERN_C -void S9xAutoSaveSRAM (void); +void S9xAutoSaveSRAM (); + -enum s9xwrap_t -{ - WRAP_NONE, - WRAP_BANK, - WRAP_PAGE +enum s9xwrap_t { + WRAP_NONE, + WRAP_BANK, + WRAP_PAGE }; -enum s9xwriteorder_t -{ - WRITE_01, - WRITE_10 +enum s9xwriteorder_t { + WRITE_01, + WRITE_10 }; #ifdef NO_INLINE_SET_GET - -uint8 S9xGetByte (uint32); -uint16 S9xGetWord (uint32, enum s9xwrap_t w = WRAP_NONE); -void S9xSetByte (uint8, uint32); -void S9xSetWord (uint16, uint32, enum s9xwrap_t w = WRAP_NONE, enum s9xwriteorder_t o = WRITE_01); -void S9xSetPCBase (uint32); -uint8 * S9xGetMemPointer (uint32); -uint8 * GetBasePointer (uint32); +uint8 S9xGetByte (uint32 Address); +uint16 S9xGetWord (uint32 Address, enum s9xwrap_t w=WRAP_NONE); +void S9xSetByte (uint8 Byte, uint32 Address); +void S9xSetWord (uint16 Word, uint32 Address, enum s9xwrap_t w=WRAP_NONE, enum s9xwriteorder_t o=WRITE_01); +void S9xSetPCBase (uint32 Address); +uint8 *S9xGetMemPointer (uint32 Address); +uint8 *GetBasePointer (uint32 Address); START_EXTERN_C -extern uint8 OpenBus; +extern uint8 OpenBus; END_EXTERN_C - #else - #define INLINE inline #include "getset.h" - #endif // NO_INLINE_SET_GET #endif // _memmap_h_ + diff --git a/source/snes9x/messages.h b/source/snes9x/messages.h index eb552616..b2230e19 100644 --- a/source/snes9x/messages.h +++ b/source/snes9x/messages.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _messages_h_ #define _messages_h_ @@ -205,7 +186,6 @@ enum { S9X_MOVIE_INFO, S9X_WRONG_MOVIE_SNAPSHOT, S9X_NOT_A_MOVIE_SNAPSHOT, - S9X_SNAPSHOT_INCONSISTENT, S9X_AVI_INFO }; diff --git a/source/snes9x/missing.h b/source/snes9x/missing.h index ef7c8d8c..98dc6a46 100644 --- a/source/snes9x/missing.h +++ b/source/snes9x/missing.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _MISSING_H_ #define _MISSING_H_ diff --git a/source/snes9x/unused/movie.h b/source/snes9x/movie.h similarity index 83% rename from source/snes9x/unused/movie.h rename to source/snes9x/movie.h index efc14ca3..4f4d47a5 100644 --- a/source/snes9x/unused/movie.h +++ b/source/snes9x/movie.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - // Input recording/playback code // (c) Copyright 2004 blip @@ -180,18 +161,8 @@ #define MOVIE_OPT_FROM_SNAPSHOT 0 #define MOVIE_OPT_FROM_RESET (1<<0) #define MOVIE_OPT_PAL (1<<1) -#define MOVIE_OPT_NOSAVEDATA (1<<2) #define MOVIE_MAX_METADATA 512 -#define MOVIE_SYNC_DATA_EXISTS 0x01 -#define MOVIE_SYNC_OBSOLETE 0x02 -#define MOVIE_SYNC_LEFTRIGHT 0x04 -#define MOVIE_SYNC_VOLUMEENVX 0x08 -#define MOVIE_SYNC_FAKEMUTE 0x10 -#define MOVIE_SYNC_SYNCSOUND 0x20 -#define MOVIE_SYNC_HASROMINFO 0x40 -#define MOVIE_SYNC_NOCPUSHUTDOWN 0x80 - START_EXTERN_C struct MovieInfo { @@ -202,14 +173,6 @@ struct MovieInfo uint8 Opts; uint8 ControllersMask; bool8 ReadOnly; - uint8 SyncFlags; - - uint32 ROMCRC32; - char ROMName [23]; - - uint32 LengthSamples; - uint8 PortType[2]; - uint32 Version; }; // methods used by the user-interface code @@ -217,30 +180,23 @@ int S9xMovieOpen (const char* filename, bool8 read_only); int S9xMovieCreate (const char* filename, uint8 controllers_mask, uint8 opts, const wchar_t* metadata, int metadata_length); int S9xMovieGetInfo (const char* filename, struct MovieInfo* info); void S9xMovieStop (bool8 suppress_message); -void S9xMovieToggleRecState (); void S9xMovieToggleFrameDisplay (); const char *S9xChooseMovieFilename(bool8 read_only); // methods used by the emulation void S9xMovieInit (); -void S9xMovieShutdown (); -void S9xMovieUpdate (bool addFrame=true); -void S9xMovieUpdateOnReset (); +void S9xMovieUpdate (); //bool8 S9xMovieRewind (uint32 at_frame); void S9xMovieFreeze (uint8** buf, uint32* size); -int S9xMovieUnfreeze (const uint8* buf, uint32 size); -void S9xUpdateFrameCounter (int offset=0); +bool8 S9xMovieUnfreeze (const uint8* buf, uint32 size); // accessor functions bool8 S9xMovieActive (); -bool8 S9xMoviePlaying (); -bool8 S9xMovieRecording (); // the following accessors return 0/false if !S9xMovieActive() bool8 S9xMovieReadOnly (); uint32 S9xMovieGetId (); uint32 S9xMovieGetLength (); uint32 S9xMovieGetFrameCounter (); -uint8 S9xMovieControllers (); END_EXTERN_C diff --git a/source/snes9x/obc1.cpp b/source/snes9x/obc1.cpp index 9f4cee81..06da2f5d 100644 --- a/source/snes9x/obc1.cpp +++ b/source/snes9x/obc1.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include "memmap.h" #include "obc1.h" @@ -177,18 +158,18 @@ uint8 GetOBC1 (uint16 Address) switch(Address) { case 0x7ff0: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)]; - + case 0x7ff1: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1]; - + case 0x7ff2: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2]; - + case 0x7ff3: return OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3]; - + case 0x7ff4: - return OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200]; + return OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200]; } return OBC1_RAM[Address & 0x1fff]; @@ -202,51 +183,51 @@ void SetOBC1 (uint8 Byte, uint16 Address) OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2)] = Byte; break; } - + case 0x7ff1: { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 1] = Byte; break; } - + case 0x7ff2: { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 2] = Byte; break; } - + case 0x7ff3: { OBC1_RAM[OBC1_BasePtr + (OBC1_Address << 2) + 3] = Byte; break; } - + case 0x7ff4: { unsigned char Temp; Temp = OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200]; - Temp = (Temp & ~(3 << OBC1_Shift)) | ((Byte & 3) << OBC1_Shift); + Temp = (Temp & ~(3 << OBC1_Shift)) | ((Byte & 3) << OBC1_Shift); OBC1_RAM[OBC1_BasePtr + (OBC1_Address >> 2) + 0x200] = Temp; break; } - + case 0x7ff5: { - if (Byte & 1) + if (Byte & 1) OBC1_BasePtr = 0x1800; else OBC1_BasePtr = 0x1c00; break; } - + case 0x7ff6: { - OBC1_Address = Byte & 0x7f; - OBC1_Shift = (Byte & 3) << 1; + OBC1_Address = Byte & 0x7f; + OBC1_Shift = (Byte & 3) << 1; break; - } + } } OBC1_RAM[Address & 0x1fff] = Byte; @@ -272,12 +253,12 @@ void ResetOBC1() { OBC1_RAM = &Memory.FillRAM[0x6000]; - if (OBC1_RAM[0x1ff5] & 1) + if (OBC1_RAM[0x1ff5] & 1) OBC1_BasePtr = 0x1800; else OBC1_BasePtr = 0x1c00; - OBC1_Address = OBC1_RAM[0x1ff6] & 0x7f; + OBC1_Address = OBC1_RAM[0x1ff6] & 0x7f; OBC1_Shift = (OBC1_RAM[0x1ff6] & 3) << 1; } diff --git a/source/snes9x/obc1.h b/source/snes9x/obc1.h index c9ddc668..2b4c5c42 100644 --- a/source/snes9x/obc1.h +++ b/source/snes9x/obc1.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _OBC1_H_ #define _OBC1_H_ @@ -170,7 +151,7 @@ void SetOBC1 (uint8 Byte, uint16 Address); uint8 *GetBasePointerOBC1(uint32 Address); uint8 *GetMemPointerOBC1(uint32 Address); void ResetOBC1();//bool8 full); -END_EXTERN_C +END_EXTERN_C #endif diff --git a/source/snes9x/pixform.h b/source/snes9x/pixform.h index bdda64cb..5f42ad25 100644 --- a/source/snes9x/pixform.h +++ b/source/snes9x/pixform.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _PIXFORM_H_ #define _PIXFORM_H_ @@ -215,7 +196,7 @@ extern uint32 HIGH_BITS_SHIFTED_TWO_MASK; #define FIRST_COLOR_MASK_RGB565 0xF800 #define SECOND_COLOR_MASK_RGB565 0x07E0 #define THIRD_COLOR_MASK_RGB565 0x001F -#define ALPHA_BITS_MASK_RGB565 0x0000 +#define ALPHA_BITS_MASK_RGB565 0x0000 /* RGB555 format */ #define BUILD_PIXEL_RGB555(R,G,B) (((int) (R) << 10) | ((int) (G) << 5) | (int) (B)) diff --git a/source/snes9x/port.h b/source/snes9x/port.h index a98409a3..c5b204c6 100644 --- a/source/snes9x/port.h +++ b/source/snes9x/port.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _PORT_H_ #define _PORT_H_ @@ -196,17 +177,17 @@ #ifdef _C #undef _C #endif - + #ifdef _D #undef _D #endif - + #define CHECK_SOUND() #define PIXEL_FORMAT RGB555 #undef GFX_MULTI_FORMAT #undef USE_X86_ASM #undef _MAX_PATH - + #define SET_UI_COLOR(r,g,b) SetInfoDlgColor(r,g,b) void SetInfoDlgColor(unsigned char, unsigned char, unsigned char); @@ -253,16 +234,10 @@ typedef long long int64; typedef unsigned long long uint64; #else /* __WIN32__ */ -#ifndef PATH_MAX -#define PATH_MAX _MAX_PATH -#endif - # ifdef __BORLANDC__ # include # else -#define SNES_JOY_READ_CALLBACKS - typedef unsigned char uint8; typedef unsigned short uint16; typedef signed char int8; @@ -370,12 +345,16 @@ EXTERN_C void MixSound(void); #if defined(__i386__) || defined(__i486__) || defined(__i586__) || \ defined(__x86_64__) || defined(__WIN32__) || defined(__alpha__) -#define LSB_FIRST -#define FAST_LSB_WORD_ACCESS +//#define LSB_FIRST +//#define FAST_LSB_WORD_ACCESS #else #define MSB_FIRST #endif +#ifndef MSB_FIRST +#define MSB_FIRST +#endif + #ifdef __sun #define TITLE "Snes9X: Solaris" #endif diff --git a/source/snes9x/ppu.cpp b/source/snes9x/ppu.cpp index 600732e5..20684e54 100644 --- a/source/snes9x/ppu.cpp +++ b/source/snes9x/ppu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "ppu.h" @@ -171,15 +152,17 @@ #include "gfx.h" #include "display.h" #include "sa1.h" + +#ifndef NGC +#include "netplay.h" +#endif + #include "sdd1.h" #include "srtc.h" #include "spc7110.h" #include "bsx.h" -//#include "movie.h" +#include "movie.h" #include "controls.h" -#ifdef NETPLAY_SUPPORT -#include "netplay.h" -#endif #ifndef ZSNES_FX #include "fxemu.h" @@ -210,23 +193,23 @@ static inline void S9xLatchCounters (bool force) #endif PPU.HVBeamCounterLatched = 1; PPU.VBeamPosLatched = (uint16) CPU.V_Counter; - + // From byuu: - // All dots are 4 cycles long, except dots 322 and 326. dots 322 and 326 are 6 cycles long. + // All dots are 4 cycles long, except dots 322 and 326. dots 322 and 326 are 6 cycles long. // This holds true for all scanlines except scanline 240 on non-interlace odd frames. // The reason for this is because this scanline is only 1360 cycles long, // instead of 1364 like all other scanlines. // This makes the effective range of hscan_pos 0-339 at all times. int32 hc = CPU.Cycles; - + if (Timings.H_Max == Timings.H_Max_Master) // 1364 - { + { if (hc >= 1292) hc -= (ONE_DOT_CYCLE / 2); if (hc >= 1308) hc -= (ONE_DOT_CYCLE / 2); } - + PPU.HBeamPosLatched = (uint16) (hc / ONE_DOT_CYCLE); // Causes screen flicker for Yoshi's Island if uncommented @@ -235,7 +218,7 @@ static inline void S9xLatchCounters (bool force) Memory.FillRAM [0x213F] |= 0x40; } - + if (CPU.V_Counter > PPU.GunVLatch || (CPU.V_Counter == PPU.GunVLatch && CPU.Cycles >= PPU.GunHLatch * ONE_DOT_CYCLE)) { @@ -267,7 +250,7 @@ static inline void S9xTryGunLatch (bool force) Memory.FillRAM [0x213F] |= 0x40; } - + PPU.GunVLatch = 1000; } } @@ -284,28 +267,22 @@ void S9xCheckMissingHTimerPosition (int32 hc) } } -void S9xCheckMissingHTimerHalt (int32 hc_from, int32 range) -{ +void S9xCheckMissingHTimerPositionRange (int32 hc_from, int32 range) +{ if ((PPU.HTimerPosition >= hc_from) && (PPU.HTimerPosition < (hc_from + range))) { if (PPU.HTimerEnabled && (!PPU.VTimerEnabled || (CPU.V_Counter == PPU.VTimerPosition))) - CPU.IRQPending = 1; + S9xSetIRQ(PPU_H_BEAM_IRQ_SOURCE); else if (PPU.VTimerEnabled && (CPU.V_Counter == PPU.VTimerPosition)) - CPU.IRQPending = 1; + S9xSetIRQ(PPU_V_BEAM_IRQ_SOURCE); } } -void S9xCheckMissingHTimerRange (int32 hc_from, int32 range) +void S9xCheckMissingVTimerPosition (void) { - if ((PPU.HTimerPosition >= hc_from) && (PPU.HTimerPosition < (hc_from + range))) - { - if (PPU.HTimerEnabled && (!PPU.VTimerEnabled || (CPU.V_Counter == PPU.VTimerPosition))) - S9xSetIRQ(PPU_H_BEAM_IRQ_SOURCE); - else - if (PPU.VTimerEnabled && (CPU.V_Counter == PPU.VTimerPosition)) - S9xSetIRQ(PPU_V_BEAM_IRQ_SOURCE); - } + if (PPU.VTimerEnabled && !PPU.HTimerEnabled && (CPU.V_Counter == PPU.VTimerPosition) && (CPU.Cycles >= PPU.HTimerPosition)) + S9xSetIRQ(PPU_V_BEAM_IRQ_SOURCE); } void S9xUpdateHVTimerPosition (void) @@ -320,7 +297,7 @@ void S9xUpdateHVTimerPosition (void) // IRQ_read PPU.HTimerPosition = PPU.IRQHBeamPos * ONE_DOT_CYCLE; if (Timings.H_Max == Timings.H_Max_Master) // 1364 - { + { if (PPU.IRQHBeamPos > 322) PPU.HTimerPosition += (ONE_DOT_CYCLE / 2); if (PPU.IRQHBeamPos > 326) @@ -342,7 +319,7 @@ void S9xUpdateHVTimerPosition (void) if ((PPU.HTimerPosition >= Timings.H_Max) && (PPU.IRQHBeamPos < 340)) { - PPU.HTimerPosition -= Timings.H_Max; + PPU.HTimerPosition -= Timings.H_Max; PPU.VTimerPosition++; // FIXME if (PPU.VTimerPosition >= Timings.V_Max) @@ -357,27 +334,27 @@ void S9xUpdateHVTimerPosition (void) CPU.WhichEvent = HC_HDMA_START_EVENT; CPU.NextEvent = Timings.HDMAStart; break; - + case HC_IRQ_3_5_EVENT: CPU.WhichEvent = HC_HCOUNTER_MAX_EVENT; CPU.NextEvent = Timings.H_Max; break; - + case HC_IRQ_5_7_EVENT: CPU.WhichEvent = HC_HDMA_INIT_EVENT; CPU.NextEvent = Timings.HDMAInit; break; - + case HC_IRQ_7_9_EVENT: CPU.WhichEvent = HC_RENDER_EVENT; CPU.NextEvent = Timings.RenderPos; break; - + case HC_IRQ_9_A_EVENT: CPU.WhichEvent = HC_WRAM_REFRESH_EVENT; CPU.NextEvent = Timings.WRAMRefreshPos; break; - + case HC_IRQ_A_1_EVENT: CPU.WhichEvent = HC_HBLANK_START_EVENT; CPU.NextEvent = Timings.HBlankStart; @@ -385,32 +362,32 @@ void S9xUpdateHVTimerPosition (void) } } else - if ((PPU.HTimerPosition < CPU.NextEvent) || (!(CPU.WhichEvent & 1) && (PPU.HTimerPosition == CPU.NextEvent))) + if (PPU.HTimerPosition < CPU.NextEvent) { CPU.NextEvent = PPU.HTimerPosition; - + switch (CPU.WhichEvent) { case HC_HDMA_START_EVENT: CPU.WhichEvent = HC_IRQ_1_3_EVENT; break; - + case HC_HCOUNTER_MAX_EVENT: CPU.WhichEvent = HC_IRQ_3_5_EVENT; break; - + case HC_HDMA_INIT_EVENT: CPU.WhichEvent = HC_IRQ_5_7_EVENT; break; - + case HC_RENDER_EVENT: CPU.WhichEvent = HC_IRQ_7_9_EVENT; break; - + case HC_WRAM_REFRESH_EVENT: CPU.WhichEvent = HC_IRQ_9_A_EVENT; break; - + case HC_HBLANK_START_EVENT: CPU.WhichEvent = HC_IRQ_A_1_EVENT; break; @@ -424,27 +401,27 @@ void S9xUpdateHVTimerPosition (void) CPU.WhichEvent = HC_HDMA_START_EVENT; CPU.NextEvent = Timings.HDMAStart; break; - + case HC_IRQ_3_5_EVENT: CPU.WhichEvent = HC_HCOUNTER_MAX_EVENT; CPU.NextEvent = Timings.H_Max; break; - + case HC_IRQ_5_7_EVENT: CPU.WhichEvent = HC_HDMA_INIT_EVENT; CPU.NextEvent = Timings.HDMAInit; break; - + case HC_IRQ_7_9_EVENT: CPU.WhichEvent = HC_RENDER_EVENT; CPU.NextEvent = Timings.RenderPos; break; - + case HC_IRQ_9_A_EVENT: CPU.WhichEvent = HC_WRAM_REFRESH_EVENT; CPU.NextEvent = Timings.WRAMRefreshPos; break; - + case HC_IRQ_A_1_EVENT: CPU.WhichEvent = HC_HBLANK_START_EVENT; CPU.NextEvent = Timings.HBlankStart; @@ -475,7 +452,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) // fprintf(stderr, "%03d: %02x to %04x\n", CPU.V_Counter, Byte, Address); // Take care of DMA wrapping - if(CPU.InDMAorHDMA && Address>0x21ff) Address=0x2100+(Address&0xff); + if(CPU.InDMA && Address>0x21ff) Address=0x2100+(Address&0xff); if (Address <= 0x219F) { @@ -501,17 +478,6 @@ void S9xSetPPU (uint8 Byte, uint16 Address) PPU.ForcedBlanking = (Byte >> 7) & 1; } } - if ((Memory.FillRAM[0x2100] & 0x80) && CPU.V_Counter==PPU.ScreenHeight+FIRST_VISIBLE_LINE){ - PPU.OAMAddr = PPU.SavedOAMAddr; - uint8 tmp = 0; - if(PPU.OAMPriorityRotation) - tmp = (PPU.OAMAddr & 0xFE) >> 1; - if((PPU.OAMFlip&1) || PPU.FirstSprite!=tmp){ - PPU.FirstSprite = tmp; - IPPU.OBJChanged = TRUE; - } - PPU.OAMFlip = 0; - } break; case 0x2101: @@ -684,7 +650,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) case 0x210E: // Yes, the two formulas are supposed to be different. - PPU.BG[0].VOffset = (Byte<<8) | PPU.BGnxOFSbyte; + PPU.BG[0].VOffset = (Byte<<8) | (PPU.BGnxOFSbyte&~7) | ((PPU.BG[0].VOffset>>8)&7); PPU.M7VOFS = (Byte<<8) | PPU.M7byte; PPU.BGnxOFSbyte = Byte; PPU.M7byte = Byte; @@ -696,7 +662,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) break; case 0x2110: - PPU.BG[1].VOffset = (Byte<<8) | PPU.BGnxOFSbyte; + PPU.BG[1].VOffset = (Byte<<8) | (PPU.BGnxOFSbyte&~7) | ((PPU.BG[1].VOffset>>8)&7); PPU.BGnxOFSbyte = Byte; break; @@ -706,7 +672,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) break; case 0x2112: - PPU.BG[2].VOffset = (Byte<<8) | PPU.BGnxOFSbyte; + PPU.BG[2].VOffset = (Byte<<8) | (PPU.BGnxOFSbyte&~7) | ((PPU.BG[2].VOffset>>8)&7); PPU.BGnxOFSbyte = Byte; break; @@ -716,7 +682,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) break; case 0x2114: - PPU.BG[3].VOffset = (Byte<<8) | PPU.BGnxOFSbyte; + PPU.BG[3].VOffset = (Byte<<8) | (PPU.BGnxOFSbyte&~7) | ((PPU.BG[3].VOffset>>8)&7); PPU.BGnxOFSbyte = Byte; break; @@ -1191,33 +1157,37 @@ void S9xSetPPU (uint8 Byte, uint16 Address) case 0x2174: case 0x2175: case 0x2176: case 0x2177: case 0x2178: case 0x2179: case 0x217a: case 0x217b: case 0x217c: case 0x217d: case 0x217e: case 0x217f: +#ifdef SPCTOOL + _SPCInPB (Address & 3, Byte); +#else + // CPU.Flags |= DEBUG_MODE_FLAG; + Memory.FillRAM [Address] = Byte; + IAPU.RAM [(Address & 3) + 0xf4] = Byte; #ifdef SPC700_SHUTDOWN IAPU.APUExecuting = Settings.APUEnabled; IAPU.WaitCounter++; #endif - S9xAPUExecute(); - Memory.FillRAM [Address] = Byte; - IAPU.RAM [(Address & 3) + 0xf4] = Byte; +#endif // SPCTOOL break; case 0x2180: - if(!CPU.InWRAMDMAorHDMA){ + if(!CPU.InWRAM_DMA){ REGISTER_2180(Byte); } break; case 0x2181: - if(!CPU.InWRAMDMAorHDMA){ + if(!CPU.InWRAM_DMA){ PPU.WRAM &= 0x1FF00; PPU.WRAM |= Byte; } break; case 0x2182: - if(!CPU.InWRAMDMAorHDMA){ + if(!CPU.InWRAM_DMA){ PPU.WRAM &= 0x100FF; PPU.WRAM |= Byte << 8; } break; case 0x2183: - if(!CPU.InWRAMDMAorHDMA){ + if(!CPU.InWRAM_DMA){ PPU.WRAM &= 0x0FFFF; PPU.WRAM |= Byte << 16; PPU.WRAM &= 0x1FFFF; @@ -1387,7 +1357,7 @@ uint8 S9xGetPPU (uint16 Address) return OpenBus; //treat as unmapped memory returning last byte on the bus // Take care of DMA wrapping - if(CPU.InDMAorHDMA && Address>0x21ff) Address=0x2100+(Address&0xff); + if(CPU.InDMA && Address>0x21ff) Address=0x2100+(Address&0xff); if (Address <= 0x219F) { @@ -1582,7 +1552,7 @@ uint8 S9xGetPPU (uint16 Address) } else byte = Memory.VRAM[((PPU.VMA.Address << 1) - 2) & 0xffff]; - + if (!PPU.VMA.High) { PPU.VMA.Address += PPU.VMA.Increment; @@ -1648,7 +1618,7 @@ uint8 S9xGetPPU (uint16 Address) PPU.CGFLIPRead ^= 1; return (PPU.OpenBus2 = byte); - + case 0x213C: // Horizontal counter value 0-339 #ifdef DEBUGGER @@ -1709,24 +1679,26 @@ uint8 S9xGetPPU (uint16 Address) case 0x2174: case 0x2175: case 0x2176: case 0x2177: case 0x2178: case 0x2179: case 0x217a: case 0x217b: case 0x217c: case 0x217d: case 0x217e: case 0x217f: -#ifdef SPC700_SHUTDOWN +#ifdef SPCTOOL + return ((uint8) _SPCOutP [Address & 3]); +#else + // CPU.Flags |= DEBUG_MODE_FLAG; +#ifdef SPC700_SHUTDOWN IAPU.APUExecuting = Settings.APUEnabled; IAPU.WaitCounter++; #endif - S9xAPUExecute(); - if (Settings.APUEnabled) + if (Settings.APUEnabled) { #ifdef CPU_SHUTDOWN // CPU.WaitAddress = CPU.PCAtOpcodeStart; -#endif -#if 0 +#endif if (SNESGameFixes.APU_OutPorts_ReturnValueFix && Address >= 0x2140 && Address <= 0x2143 && !CPU.V_Counter) { - return (uint8)((Address & 1) ? ((rand() & 0xff00) >> 8) : + return (uint8)((Address & 1) ? ((rand() & 0xff00) >> 8) : (rand() & 0xff)); } -#endif + return (APU.OutPorts [Address & 3]); } @@ -1760,13 +1732,14 @@ uint8 S9xGetPPU (uint16 Address) return ((r >> 3) & 0xff); } return (Memory.FillRAM[Address]); +#endif // SPCTOOL case 0x2180: // Read WRAM #ifdef DEBUGGER missing.wram_read = 1; #endif - if(!CPU.InWRAMDMAorHDMA){ + if(!CPU.InWRAM_DMA){ byte = Memory.RAM [PPU.WRAM++]; PPU.WRAM &= 0x1FFFF; } else { @@ -1781,7 +1754,7 @@ uint8 S9xGetPPU (uint16 Address) case 0x2186: case 0x2187: return OpenBus; - + case 0x2188: case 0x2189: case 0x218a: @@ -1840,7 +1813,7 @@ uint8 S9xGetPPU (uint16 Address) if (Settings.SRTC) return (S9xGetSRTC (Address)); /*FALL*/ - + default: #ifdef DEBUGGER missing.unknownppu_read = Address; @@ -1853,7 +1826,7 @@ uint8 S9xGetPPU (uint16 Address) return OpenBus; } } - + if (!Settings.SuperFX) return OpenBus; #ifdef ZSNES_FX @@ -1865,7 +1838,7 @@ uint8 S9xGetPPU (uint16 Address) #ifdef CPU_SHUTDOWN if (Address == 0x3030) CPU.WaitAddress = CPU.PBPCAtOpcodeStart; -#endif +#endif if (Address == 0x3031) CLEAR_IRQ_SOURCE (GSU_IRQ_SOURCE); #else @@ -1931,7 +1904,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4200: // NMI, V & H IRQ and joypad reading enable flags pV = PPU.VTimerEnabled; - + if (byte & 0x20) { PPU.VTimerEnabled = TRUE; @@ -1953,17 +1926,16 @@ void S9xSetCPU (uint8 byte, uint16 Address) } else PPU.HTimerEnabled = FALSE; - + S9xUpdateHVTimerPosition(); - - // The case that IRQ will trigger in an instruction such as STA $4200 - // FIXME: not true but good enough for Snes9x, I think. - S9xCheckMissingHTimerRange(CPU.PrevCycles, CPU.Cycles - CPU.PrevCycles); - + // FIXME + if (pV != PPU.VTimerEnabled) + S9xCheckMissingVTimerPosition(); + if (!(byte & 0x30)) CLEAR_IRQ_SOURCE (PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE); - if ((byte & 0x80) && + if ((byte & 0x80) && !(Memory.FillRAM [0x4200] & 0x80) && // NMI can trigger during VBlank as long as NMI_read ($4210) wasn't cleard. // Panic Bomberman clears the NMI pending flag @ scanline 230 before enabling @@ -2039,8 +2011,12 @@ void S9xSetCPU (uint8 byte, uint16 Address) missing.virq_pos = PPU.IRQVBeamPos; #endif if (PPU.IRQVBeamPos != d) + { S9xUpdateHVTimerPosition(); - + // FIXME + S9xCheckMissingVTimerPosition(); + } + break; case 0x420A: @@ -2050,18 +2026,22 @@ void S9xSetCPU (uint8 byte, uint16 Address) missing.virq_pos = PPU.IRQVBeamPos; #endif if (PPU.IRQVBeamPos != d) + { S9xUpdateHVTimerPosition(); - + // FIXME + S9xCheckMissingVTimerPosition(); + } + break; case 0x420B: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; #ifdef DEBUGGER missing.dma_this_frame = byte; missing.dma_channels = byte; #endif // XXX: Not quite right... - if (byte) CPU.Cycles += Timings.DMACPUSync; + if(byte) CPU.Cycles += 18; if ((byte & 0x01) != 0) S9xDoDMA (0); if ((byte & 0x02) != 0) @@ -2080,10 +2060,10 @@ void S9xSetCPU (uint8 byte, uint16 Address) S9xDoDMA (7); break; case 0x420C: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; #ifdef DEBUGGER missing.hdma_this_frame |= byte; - missing.hdma_channels |= byte; + missing.hdma_channels |= byte; #endif if (Settings.DisableHDMA) byte = 0; @@ -2153,9 +2133,9 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4350: case 0x4360: case 0x4370: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; - DMA[d].ReverseTransfer = (byte&0x80)?1:0; + DMA[d].TransferDirection = (byte&0x80)?1:0; DMA[d].HDMAIndirectAddressing = (byte&0x40)?1:0; DMA[d].UnusedBit43x0 = (byte&0x20)?1:0; DMA[d].AAddressDecrement = (byte&0x10)?1:0; @@ -2171,7 +2151,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4351: case 0x4361: case 0x4371: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; DMA[((Address >> 4) & 0x7)].BAddress = byte; return; @@ -2183,7 +2163,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4352: case 0x4362: case 0x4372: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; DMA[d].AAddress &= 0xFF00; DMA[d].AAddress |= byte; @@ -2197,7 +2177,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4353: case 0x4363: case 0x4373: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; DMA[d].AAddress &= 0xFF; DMA[d].AAddress |= byte << 8; @@ -2211,7 +2191,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4354: case 0x4364: case 0x4374: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; DMA[d=((Address >> 4) & 0x7)].ABank = byte; HDMAMemPointers[d]=NULL; return; @@ -2224,7 +2204,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4355: case 0x4365: case 0x4375: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; DMA[d].DMACount_Or_HDMAIndirectAddress &= 0xff00; DMA[d].DMACount_Or_HDMAIndirectAddress |= byte; @@ -2239,7 +2219,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4356: case 0x4366: case 0x4376: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; DMA[d].DMACount_Or_HDMAIndirectAddress &= 0xff; DMA[d].DMACount_Or_HDMAIndirectAddress |= byte << 8; @@ -2254,7 +2234,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4357: case 0x4367: case 0x4377: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; DMA[d = ((Address >> 4) & 0x7)].IndirectBank = byte; HDMAMemPointers[d]=NULL; return; @@ -2267,7 +2247,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4358: case 0x4368: case 0x4378: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 7; DMA[d].Address &= 0xff00; DMA[d].Address |= byte; @@ -2282,7 +2262,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4359: case 0x4369: case 0x4379: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; DMA[d].Address &= 0xff; DMA[d].Address |= byte << 8; @@ -2297,7 +2277,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x435A: case 0x436A: case 0x437A: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; d = (Address >> 4) & 0x7; if(byte&0x7f){ DMA[d].LineCount = byte & 0x7f; @@ -2325,7 +2305,7 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x435F: case 0x436F: case 0x437F: - if(CPU.InDMAorHDMA) return; + if(CPU.InDMA) return; DMA[((Address >> 4) & 0x7)].UnknownByte = byte; return; @@ -2422,12 +2402,6 @@ uint8 S9xGetCPU (uint16 Address) if (Address < 0x4200) { -#ifdef SNES_JOY_READ_CALLBACKS - extern bool8 pad_read; - if(Address==0x4016 || Address==0x4017) - S9xOnSNESPadRead(), pad_read = true; -#endif - CPU.Cycles += ONE_CYCLE; switch (Address) { @@ -2472,7 +2446,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4210: #ifdef CPU_SHUTDOWN CPU.WaitAddress = CPU.PBPCAtOpcodeStart; -#endif +#endif byte = Memory.FillRAM[0x4210]; Memory.FillRAM[0x4210] = Model->_5A22; //SNEeSe returns 2 for 5A22 version. @@ -2516,13 +2490,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x421d: case 0x421e: case 0x421f: -#ifdef SNES_JOY_READ_CALLBACKS - { - extern bool8 pad_read; - if(Memory.FillRAM[0x4200] & 1) - S9xOnSNESPadRead(), pad_read = true; - } -#endif // Joypads 1-4 button and direction state. return (Memory.FillRAM [Address]); @@ -2534,9 +2501,9 @@ uint8 S9xGetCPU (uint16 Address) case 0x4350: case 0x4360: case 0x4370: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; d = (Address >> 4) & 0x7; - return ((DMA[d].ReverseTransfer?0x80:0x00) | + return ((DMA[d].TransferDirection?0x80:0x00) | (DMA[d].HDMAIndirectAddressing?0x40:0x00) | (DMA[d].UnusedBit43x0?0x20:0x00) | (DMA[d].AAddressDecrement?0x10:0x00) | @@ -2551,7 +2518,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4351: case 0x4361: case 0x4371: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return DMA[((Address >> 4) & 0x7)].BAddress; case 0x4302: @@ -2562,7 +2529,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4352: case 0x4362: case 0x4372: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].AAddress & 0xFF); case 0x4303: @@ -2573,7 +2540,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4353: case 0x4363: case 0x4373: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].AAddress >> 8); case 0x4304: @@ -2584,7 +2551,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4354: case 0x4364: case 0x4374: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return DMA[((Address >> 4) & 0x7)].ABank; case 0x4305: @@ -2595,7 +2562,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4355: case 0x4365: case 0x4375: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].DMACount_Or_HDMAIndirectAddress & 0xff); case 0x4306: @@ -2606,7 +2573,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4356: case 0x4366: case 0x4376: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].DMACount_Or_HDMAIndirectAddress >> 8); case 0x4307: @@ -2617,7 +2584,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4357: case 0x4367: case 0x4377: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return DMA[((Address >> 4) & 0x7)].IndirectBank; case 0x4308: @@ -2628,7 +2595,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4358: case 0x4368: case 0x4378: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].Address & 0xFF); case 0x4309: @@ -2639,7 +2606,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x4359: case 0x4369: case 0x4379: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return (DMA[((Address >> 4) & 0x7)].Address >> 8); case 0x430A: @@ -2650,7 +2617,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x435A: case 0x436A: case 0x437A: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; d = (Address >> 4) & 0x7; return (DMA[d].LineCount ^ (DMA[d].Repeat?0x00:0x80)); @@ -2670,7 +2637,7 @@ uint8 S9xGetCPU (uint16 Address) case 0x435F: case 0x436F: case 0x437F: - if(CPU.InDMAorHDMA) return OpenBus; + if(CPU.InDMA) return OpenBus; return DMA[((Address >> 4) & 0x7)].UnknownByte; default: @@ -2681,7 +2648,7 @@ uint8 S9xGetCPU (uint16 Address) sprintf (String, "Unknown register read: $%04X\n", Address); S9xMessage (S9X_TRACE, S9X_PPU_TRACE, String); } - + #endif if(Address>= 0x4800&&Settings.SPC7110) @@ -2701,9 +2668,6 @@ void S9xResetPPU () S9xSoftResetPPU(); S9xControlsReset(); IPPU.PreviousLine = IPPU.CurrentLine = 0; - PPU.M7HOFS = 0; - PPU.M7VOFS = 0; - PPU.M7byte = 0; } void S9xSoftResetPPU () @@ -2776,8 +2740,8 @@ void S9xSoftResetPPU () PPU.OAMFlip = 0; PPU.OAMTileAddress = 0; PPU.OAMAddr = 0; - PPU.IRQVBeamPos = 0x1ff; - PPU.IRQHBeamPos = 0x1ff; + PPU.IRQVBeamPos = 0; + PPU.IRQHBeamPos = 0; PPU.VBeamPosLatched = 0; PPU.HBeamPosLatched = 0; @@ -2794,6 +2758,7 @@ void S9xSoftResetPPU () PPU.SavedOAMAddr = 0; PPU.ScreenHeight = SNES_HEIGHT; PPU.WRAM = 0; + PPU.BG_Forced = 0; PPU.ForcedBlanking = TRUE; PPU.OBJThroughMain = FALSE; PPU.OBJThroughSub = FALSE; diff --git a/source/snes9x/ppu.h b/source/snes9x/ppu.h index ced5d0bd..f7031d52 100644 --- a/source/snes9x/ppu.h +++ b/source/snes9x/ppu.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _PPU_H_ #define _PPU_H_ @@ -206,7 +187,6 @@ struct InternalPPU { uint32 FrameCount; uint32 RenderedFramesCount; uint32 DisplayedRenderedFrameCount; - uint32 TotalEmulatedFrames; uint32 SkippedFrames; uint32 FrameSkip; uint8 *TileCache [7]; @@ -235,7 +215,7 @@ struct InternalPPU { struct SOBJ { - int16 HPos; + short HPos; uint16 VPos; uint16 Name; uint8 VFlip; @@ -269,7 +249,7 @@ struct SPPU { } BG [4]; bool8 CGFLIP; - uint16 CGDATA [256]; + uint16 CGDATA [256]; uint8 FirstSprite; uint8 LastSprite; struct SOBJ OBJ [128]; @@ -304,6 +284,7 @@ struct SPPU { uint16 SavedOAMAddr; uint16 ScreenHeight; uint32 WRAM; + uint8 BG_Forced; bool8 ForcedBlanking; bool8 OBJThroughMain; bool8 OBJThroughSub; @@ -353,7 +334,7 @@ struct SPPU { struct SDMA { /* $43x0 */ - bool8 ReverseTransfer; + bool8 TransferDirection; bool8 HDMAIndirectAddressing; bool8 UnusedBit43x0; bool8 AAddressFixed; @@ -411,8 +392,8 @@ uint8 *S9xGetBasePointerC4 (uint16 Address); void S9xUpdateHVTimerPosition (void); void S9xCheckMissingHTimerPosition (int32); -void S9xCheckMissingHTimerRange (int32, int32); -void S9xCheckMissingHTimerHalt (int32, int32); +void S9xCheckMissingHTimerPositionRange (int32, int32); +void S9xCheckMissingVTimerPosition (void); extern struct SPPU PPU; extern struct SDMA DMA [8]; @@ -428,11 +409,11 @@ typedef struct{ uint8 _5A22; } SnesModel; -START_EXTERN_C +#ifndef _GLOBALS_CPP extern SnesModel* Model; extern SnesModel M1SNES; extern SnesModel M2SNES; -END_EXTERN_C +#endif #define MAX_5C77_VERSION 0x01 #define MAX_5C78_VERSION 0x03 @@ -445,7 +426,7 @@ STATIC inline uint8 REGISTER_4212() CPU.V_Counter < PPU.ScreenHeight + FIRST_VISIBLE_LINE + 3) GetBank = 1; - GetBank |= ((CPU.Cycles < Timings.HBlankEnd) || (CPU.Cycles >= Timings.HBlankStart)) ? 0x40 : 0; + GetBank |= CPU.Cycles >= Timings.HBlankStart ? 0x40 : 0; if (CPU.V_Counter >= PPU.ScreenHeight + FIRST_VISIBLE_LINE) GetBank |= 0x80; /* XXX: 0x80 or 0xc0 ? */ @@ -545,19 +526,8 @@ STATIC inline void REGISTER_2104 (uint8 byte) Memory.FillRAM [0x2104] = byte; } -// This code is correct, however due to Snes9x's inaccurate timings, some games might be broken by this chage. :( -#define CHECK_INBLANK \ -{ \ - if (Settings.BlockInvalidVRAMAccess && !PPU.ForcedBlanking && CPU.V_Counter < PPU.ScreenHeight + FIRST_VISIBLE_LINE) \ - { \ - return; \ - } \ -} \ - STATIC inline void REGISTER_2118 (uint8 Byte) { - CHECK_INBLANK; - uint32 address; if (PPU.VMA.FullGraphicCount) { @@ -585,13 +555,13 @@ STATIC inline void REGISTER_2118 (uint8 Byte) if (!PPU.VMA.High) { #ifdef DEBUGGER - if (Settings.TraceVRAM && !CPU.InDMAorHDMA) + if (Settings.TraceVRAM && !CPU.InDMA) { printf ("VRAM write byte: $%04X (%d,%d)\n", PPU.VMA.Address, Memory.FillRAM[0x2115] & 3, (Memory.FillRAM [0x2115] & 0x0c) >> 2); } -#endif +#endif PPU.VMA.Address += PPU.VMA.Increment; } // Memory.FillRAM [0x2118] = Byte; @@ -599,8 +569,6 @@ STATIC inline void REGISTER_2118 (uint8 Byte) STATIC inline void REGISTER_2118_tile (uint8 Byte) { - CHECK_INBLANK; - uint32 address; uint32 rem = PPU.VMA.Address & PPU.VMA.Mask1; address = (((PPU.VMA.Address & ~PPU.VMA.Mask1) + @@ -625,8 +593,6 @@ STATIC inline void REGISTER_2118_tile (uint8 Byte) STATIC inline void REGISTER_2118_linear (uint8 Byte) { - CHECK_INBLANK; - uint32 address; Memory.VRAM[address = (PPU.VMA.Address << 1) & 0xFFFF] = Byte; IPPU.TileCached [TILE_2BIT][address >> 4] = FALSE; @@ -647,8 +613,6 @@ STATIC inline void REGISTER_2118_linear (uint8 Byte) STATIC inline void REGISTER_2119 (uint8 Byte) { - CHECK_INBLANK; - uint32 address; if (PPU.VMA.FullGraphicCount) { @@ -676,13 +640,13 @@ STATIC inline void REGISTER_2119 (uint8 Byte) if (PPU.VMA.High) { #ifdef DEBUGGER - if (Settings.TraceVRAM && !CPU.InDMAorHDMA) + if (Settings.TraceVRAM && !CPU.InDMA) { printf ("VRAM write word: $%04X (%d,%d)\n", PPU.VMA.Address, Memory.FillRAM[0x2115] & 3, (Memory.FillRAM [0x2115] & 0x0c) >> 2); } -#endif +#endif PPU.VMA.Address += PPU.VMA.Increment; } // Memory.FillRAM [0x2119] = Byte; @@ -690,8 +654,6 @@ STATIC inline void REGISTER_2119 (uint8 Byte) STATIC inline void REGISTER_2119_tile (uint8 Byte) { - CHECK_INBLANK; - uint32 rem = PPU.VMA.Address & PPU.VMA.Mask1; uint32 address = ((((PPU.VMA.Address & ~PPU.VMA.Mask1) + (rem >> PPU.VMA.Shift) + @@ -715,8 +677,6 @@ STATIC inline void REGISTER_2119_tile (uint8 Byte) STATIC inline void REGISTER_2119_linear (uint8 Byte) { - CHECK_INBLANK; - uint32 address; Memory.VRAM[address = ((PPU.VMA.Address << 1) + 1) & 0xFFFF] = Byte; IPPU.TileCached [TILE_2BIT][address >> 4] = FALSE; diff --git a/source/snes9x/sa1.cpp b/source/snes9x/sa1.cpp index 81d41639..7389f9e6 100644 --- a/source/snes9x/sa1.cpp +++ b/source/snes9x/sa1.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "ppu.h" #include "cpuexec.h" @@ -456,7 +437,7 @@ void S9xSA1SetPCBase (uint32 address) #ifdef DEBUGGER printf ("SBP %06x\n", address); #endif - + default: case CMemory::MAP_NONE: SA1.PCBase = NULL; @@ -495,7 +476,7 @@ void S9xSetSA1MemMap (uint32 which1, uint8 map) for (i = c; i < c + 16; i++) Memory.Map [start + i] = SA1.Map [start + i] = block; } - + for (c = 0; c < 0x200; c += 16) { uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 11) - 0x8000]; @@ -512,7 +493,7 @@ uint8 S9xGetSA1 (uint32 address) switch (address) { case 0x2300: - return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) | + return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) | (CPU.IRQActive & (SA1_IRQ_SOURCE | SA1_DMA_IRQ_SOURCE)))); case 0x2301: return ((Memory.FillRAM [0x2200] & 0xf) | @@ -539,7 +520,7 @@ uint8 S9xGetSA1 (uint32 address) } return (byte); } - default: + default: printf ("R: %04x\n", address); break; } @@ -564,7 +545,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) Memory.FillRAM [0x2301] |= 0x80; if (Memory.FillRAM [0x220a] & 0x80) { - SA1.Flags |= IRQ_FLAG; + SA1.Flags |= IRQ_PENDING_FLAG; SA1.IRQActive |= SNES_IRQ_SOURCE; SA1.Executing = !SA1.Waiting && SA1.S9xOpcodes; } @@ -640,21 +621,21 @@ void S9xSetSA1 (uint8 byte, uint32 address) if (((byte ^ Memory.FillRAM [0x220a]) & 0x80) && (Memory.FillRAM [0x2301] & byte & 0x80)) { - SA1.Flags |= IRQ_FLAG; + SA1.Flags |= IRQ_PENDING_FLAG; SA1.IRQActive |= SNES_IRQ_SOURCE; // SA1.Executing = !SA1.Waiting; } if (((byte ^ Memory.FillRAM [0x220a]) & 0x40) && (Memory.FillRAM [0x2301] & byte & 0x40)) { - SA1.Flags |= IRQ_FLAG; + SA1.Flags |= IRQ_PENDING_FLAG; SA1.IRQActive |= TIMER_IRQ_SOURCE; // SA1.Executing = !SA1.Waiting; } if (((byte ^ Memory.FillRAM [0x220a]) & 0x20) && (Memory.FillRAM [0x2301] & byte & 0x20)) { - SA1.Flags |= IRQ_FLAG; + SA1.Flags |= IRQ_PENDING_FLAG; SA1.IRQActive |= DMA_IRQ_SOURCE; // SA1.Executing = !SA1.Waiting; } @@ -688,7 +669,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) Memory.FillRAM [0x2301] &= ~0x10; } if (!SA1.IRQActive) - SA1.Flags &= ~IRQ_FLAG; + SA1.Flags &= ~IRQ_PENDING_FLAG; break; case 0x220c: // printf ("SNES NMI vector: %04x\n", byte | (Memory.FillRAM [0x220d] << 8)); @@ -712,19 +693,19 @@ void S9xSetSA1 (uint8 byte, uint32 address) #endif break; case 0x2211: -// printf ("Timer reset\n"); + printf ("Timer reset\n"); break; case 0x2212: -// printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8)); + printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8)); break; case 0x2213: -// printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]); + printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]); break; case 0x2214: -// printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8)); + printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8)); break; case 0x2215: -// printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]); + printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]); break; case 0x2220: case 0x2221: @@ -782,7 +763,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) case 0x2234: Memory.FillRAM [address] = byte; #if 0 - printf ("DMA source start %06x\n", + printf ("DMA source start %06x\n", Memory.FillRAM [0x2232] | (Memory.FillRAM [0x2233] << 8) | (Memory.FillRAM [0x2234] << 16)); #endif @@ -814,7 +795,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) S9xSA1DMA (); } #if 0 - printf ("DMA dest address %06x\n", + printf ("DMA dest address %06x\n", Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8) | (Memory.FillRAM [0x2237] << 16)); #endif @@ -823,7 +804,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) case 0x2239: Memory.FillRAM [address] = byte; #if 0 - printf ("DMA length %04x\n", + printf ("DMA length %04x\n", Memory.FillRAM [0x2238] | (Memory.FillRAM [0x2239] << 8)); #endif break; @@ -865,7 +846,7 @@ void S9xSetSA1 (uint8 byte, uint32 address) SA1.sum = 0; SA1.arithmetic_op = byte & 3; break; - + case 0x2251: SA1.op1 = (SA1.op1 & 0xff00) | byte; break; @@ -1006,10 +987,10 @@ static void S9xSA1DMA () } memmove (d, s, len); Memory.FillRAM [0x2301] |= 0x20; - + if (Memory.FillRAM [0x220a] & 0x20) { - SA1.Flags |= IRQ_FLAG; + SA1.Flags |= IRQ_PENDING_FLAG; SA1.IRQActive |= DMA_IRQ_SOURCE; // SA1.Executing = !SA1.Waiting; } diff --git a/source/snes9x/sa1.h b/source/snes9x/sa1.h index 96e11947..ae19900e 100644 --- a/source/snes9x/sa1.h +++ b/source/snes9x/sa1.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _sa1_h_ #define _sa1_h_ diff --git a/source/snes9x/sa1cpu.cpp b/source/snes9x/sa1cpu.cpp index 0183c2e9..53414110 100644 --- a/source/snes9x/sa1cpu.cpp +++ b/source/snes9x/sa1cpu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "ppu.h" @@ -232,7 +213,7 @@ void S9xSA1MainLoop () S9xSA1Opcode_NMI (); } #endif - if (SA1.Flags & IRQ_FLAG) + if (SA1.Flags & IRQ_PENDING_FLAG) { if (SA1.IRQActive) { @@ -245,7 +226,7 @@ void S9xSA1MainLoop () S9xSA1Opcode_IRQ (); } else - SA1.Flags &= ~IRQ_FLAG; + SA1.Flags &= ~IRQ_PENDING_FLAG; } for (i = 0; i < 3 && SA1.Executing; i++) { diff --git a/source/snes9x/sar.h b/source/snes9x/sar.h index 140dfeb4..9562fda7 100644 --- a/source/snes9x/sar.h +++ b/source/snes9x/sar.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _SAR_H_ #define _SAR_H_ diff --git a/source/snes9x/screenshot.h b/source/snes9x/screenshot.h index 1665a3c9..4afdfe99 100644 --- a/source/snes9x/screenshot.h +++ b/source/snes9x/screenshot.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef SCREENSHOT_H #define SCREENSHOT_H diff --git a/source/snes9x/sdd1.cpp b/source/snes9x/sdd1.cpp index ae5206f0..fa5caf1c 100644 --- a/source/snes9x/sdd1.cpp +++ b/source/snes9x/sdd1.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #include "snes9x.h" #include "memmap.h" #include "ppu.h" @@ -244,7 +225,7 @@ void S9xSDD1LoadLoggedData () if (fs) { - int c = fread (Memory.SDD1LoggedData, 8, + int c = fread (Memory.SDD1LoggedData, 8, MEMMAP_MAX_SDD1_LOGGED_ENTRIES, fs); if (c != EOF) diff --git a/source/snes9x/sdd1.h b/source/snes9x/sdd1.h index c03c3432..0cc17a82 100644 --- a/source/snes9x/sdd1.h +++ b/source/snes9x/sdd1.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _SDD1_H_ #define _SDD1_H_ void S9xSetSDD1MemoryMap (uint32 bank, uint32 value); diff --git a/source/snes9x/sdd1emu.cpp b/source/snes9x/sdd1emu.cpp index 4104137a..9e6a5a1c 100644 --- a/source/snes9x/sdd1emu.cpp +++ b/source/snes9x/sdd1emu.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,16 +141,14 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - /* 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 + * 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 @@ -293,7 +274,7 @@ static inline uint8 ProbGetBit(uint8 context){ static inline uint8 GetBit(uint8 cur_bitplane){ uint8 bit; - + bit=ProbGetBit(((cur_bitplane&1)<<4) | ((prev_bits[cur_bitplane]&high_context_bits)>>5) | (prev_bits[cur_bitplane]&low_context_bits)); @@ -308,7 +289,7 @@ void SDD1_decompress(uint8 *out, uint8 *in, int len){ uint8 byte1, byte2; if(len==0) len=0x10000; - + bitplane_type=in[0]>>6; switch(in[0]&0x30){ @@ -431,7 +412,7 @@ void SDD1_init(uint8 *in){ uint8 SDD1_get_byte(void){ uint8 bit; uint8 byte=0; - + switch(bitplane_type){ case 0: num_bits+=16; diff --git a/source/snes9x/sdd1emu.h b/source/snes9x/sdd1emu.h index 86c03e9d..1a15296e 100644 --- a/source/snes9x/sdd1emu.h +++ b/source/snes9x/sdd1emu.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef SDD1EMU_H #define SDD1EMU_H diff --git a/source/snes9x/seta.cpp b/source/snes9x/seta.cpp index ca3bfba5..364e9b7e 100644 --- a/source/snes9x/seta.cpp +++ b/source/snes9x/seta.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "seta.h" void (*SetSETA)(uint32, uint8)=&S9xSetST010; diff --git a/source/snes9x/seta.h b/source/snes9x/seta.h index 0c49170d..89ba9831 100644 --- a/source/snes9x/seta.h +++ b/source/snes9x/seta.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef NO_SETA #ifndef _seta_h #define _seta_h diff --git a/source/snes9x/seta010.cpp b/source/snes9x/seta010.cpp index e0a84f15..89878518 100644 --- a/source/snes9x/seta010.cpp +++ b/source/snes9x/seta010.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "seta.h" #include "memmap.h" @@ -326,7 +307,7 @@ short ST010_Cos(short Theta) 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; @@ -346,7 +327,7 @@ void ST010_OP01(short x0, short y0, short &x1, short &y1, short &Quadrant, short else { x1 = x0; - y1 = y0; + y1 = y0; Quadrant = 0x0000; } @@ -385,7 +366,7 @@ void SETA_Distance(short Y0, short X0, short &Distance) Distance = ((X0 * 0x7af0) + 0x4000) >> 15; } -void ST010_SortDrivers(uint16 Positions, uint16 Places[32], uint16 Drivers[32]) +void ST010_SortDrivers(uint16 Positions, uint16 Places[32], uint16 Drivers[32]) { bool Sorted; uint16 Temp; @@ -394,7 +375,7 @@ void ST010_SortDrivers(uint16 Positions, uint16 Places[32], uint16 Drivers[32]) do { Sorted = true; for (int i = 0; i < Positions - 1; i++) - if (Places[i] < Places[i + 1]) + if (Places[i] < Places[i + 1]) { Temp = Places[i + 1]; Places[i + 1] = Places[i]; @@ -444,7 +425,7 @@ void S9xSetST010(uint32 Address, uint8 Byte) case 0x02: { #ifdef FAST_LSB_WORD_ACCESS - ST010_SortDrivers(*(uint16*)(Memory.SRAM + 0x0024), (uint16*) (Memory.SRAM + 0x0040), (uint16*) (Memory.SRAM + 0x0080)); + ST010_SortDrivers(*(short*)&SRAM[0x0024], (uint16*) (SRAM + 0x0040), (uint16*) (SRAM + 0x0080)); #else uint16 Places[32]; uint16 Positions = ST010_WORD(0x0024); @@ -452,25 +433,25 @@ void S9xSetST010(uint32 Address, uint8 Byte) Offset = 0; - for (Pos = 0; Pos < Positions; Pos++) + for (Pos = 0; Pos < Positions; Pos++) { Places[Pos] = ST010_WORD(0x0040 + Offset); Offset += 2; } - ST010_SortDrivers(Positions, Places, (uint16*) (Memory.SRAM + 0x0080)); + ST010_SortDrivers(Positions, Places, (uint16*) (SRAM + 0x0080)); Offset = 0; for (Pos = 0; Pos < Positions; Pos++) { - Memory.SRAM[0x0040 + Offset]=(uint8)(Places[Pos]); - Memory.SRAM[0x0041 + Offset]=(uint8)(Places[Pos] >> 8); + SRAM[0x0040 + Offset]=(uint8)(Places[Pos]); + SRAM[0x0041 + Offset]=(uint8)(Places[Pos] >> 8); Offset += 2; } -#endif +#endif break; - + } // Two Dimensional Coordinate Scale @@ -550,23 +531,23 @@ void S9xSetST010(uint32 Address, uint8 Byte) { // Calculate Mode 7 Matrix A/D data data = ST010_M7Scale[line] * ST010_Cos(Theta) >> 15; - + Memory.SRAM[0x00f0 + offset]=(uint8)(data); Memory.SRAM[0x00f1 + offset]=(uint8)(data >> 8); Memory.SRAM[0x0510 + offset]=(uint8)(data); - Memory.SRAM[0x0511 + offset]=(uint8)(data >> 8); + Memory.SRAM[0x0511 + offset]=(uint8)(data >> 8); // Calculate Mode 7 Matrix B/C data - data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15; + data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15; Memory.SRAM[0x0250 + offset]=(uint8)(data); Memory.SRAM[0x0251 + offset]=(uint8)(data >> 8); - + if (data) data = ~data; - + Memory.SRAM[0x03b0 + offset]=(uint8)(data); Memory.SRAM[0x03b1 + offset]=(uint8)(data >> 8); - + offset += 2; } @@ -674,9 +655,9 @@ void S9xSetST010(uint32 Address, uint8 Byte) int16 xpos_max = ST010_WORD(0x00C2); // current coordinates and direction - int32 ypos = Memory.SRAM[0xC4]|(Memory.SRAM[0xC5]<<8)|(Memory.SRAM[0xC6]<<16)|(Memory.SRAM[0xC7]<<24); - int32 xpos = Memory.SRAM[0xC8]|(Memory.SRAM[0xC9]<<8)|(Memory.SRAM[0xCA]<<16)|(Memory.SRAM[0xCB]<<24); - uint16 rot = Memory.SRAM[0xCC]|(Memory.SRAM[0xCD]<<8); + 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); @@ -699,10 +680,10 @@ void S9xSetST010(uint32 Address, uint8 Byte) dy = ypos_max-(ypos>>16); // quirk: clear and move in9 - Memory.SRAM[0xD2]=0xFF; - Memory.SRAM[0xD3]=0xFF; - Memory.SRAM[0xDA]=0; - Memory.SRAM[0xDB]=0; + 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); @@ -789,24 +770,24 @@ void S9xSetST010(uint32 Address, uint8 Byte) xpos &= 0x1FFFFFFF; ypos &= 0x1FFFFFFF; - Memory.SRAM[0x00C0]=(uint8)(ypos_max); - Memory.SRAM[0x00C1]=(uint8)(ypos_max >> 8); - Memory.SRAM[0x00C2]=(uint8)(xpos_max); - Memory.SRAM[0x00C3]=(uint8)(xpos_max >> 8); - Memory.SRAM[0x00C4]=(uint8)(ypos); - Memory.SRAM[0x00C5]=(uint8)(ypos >> 8); - Memory.SRAM[0x00C6]=(uint8)(ypos >> 16); - Memory.SRAM[0x00C7]=(uint8)(ypos >> 24); - Memory.SRAM[0x00C8]=(uint8)(xpos); - Memory.SRAM[0x00C9]=(uint8)(xpos >> 8); - Memory.SRAM[0x00CA]=(uint8)(xpos >> 16); - Memory.SRAM[0x00CB]=(uint8)(xpos >> 24); - Memory.SRAM[0x00CC]=(uint8)(rot); - Memory.SRAM[0x00CD]=(uint8)(rot >> 8); - Memory.SRAM[0x00D4]=(uint8)(speed); - Memory.SRAM[0x00D5]=(uint8)(speed >> 8); - Memory.SRAM[0x00DC]=(uint8)(flags); - Memory.SRAM[0x00DD]=(uint8)(flags >> 8); + 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; } diff --git a/source/snes9x/seta011.cpp b/source/snes9x/seta011.cpp index 99952830..aff54294 100644 --- a/source/snes9x/seta011.cpp +++ b/source/snes9x/seta011.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include "seta.h" #include "memmap.h" @@ -190,7 +171,7 @@ uint8 S9xGetST011(uint32 Address) { t = Memory.SRAM[address]; } - + // debug // if(address<0x150) // printf( "ST011 R: %06X %02X\n", Address, t); @@ -279,7 +260,7 @@ void S9xSetST011(uint32 Address, uint8 Byte) break; // unknown - case 0x05: + case 0x05: { // outputs Memory.SRAM[0x12C] = 0x00; diff --git a/source/snes9x/seta018.cpp b/source/snes9x/seta018.cpp index 6ce9e9e7..505c17e2 100644 --- a/source/snes9x/seta018.cpp +++ b/source/snes9x/seta018.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "seta.h" #include "memmap.h" @@ -192,7 +173,7 @@ uint8 S9xGetST018(uint32 Address) // status register else if (address == 0x3800) t = ST018.status; - + printf( "ST018 R: %06X %02X\n", Address, t); return t; diff --git a/source/snes9x/snapshot.cpp b/source/snes9x/snapshot.cpp index f60ab8a2..03667744 100644 --- a/source/snes9x/snapshot.cpp +++ b/source/snes9x/snapshot.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #ifdef HAVE_STRINGS_H #include @@ -167,7 +148,6 @@ #include #include #include -#include #if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP) #include @@ -176,9 +156,11 @@ #endif #include "snapshot.h" + #ifndef NGC #include "snaporig.h" #endif + #include "memmap.h" #include "snes9x.h" #include "65c816.h" @@ -192,30 +174,11 @@ #include "srtc.h" #include "sdd1.h" #include "spc7110.h" -//#include "movie.h" +#include "movie.h" #include "controls.h" -#include "dsp1.h" -#include "c4.h" -#ifndef ZSNES_FX - #include "fxinst.h" -#endif -#include "language.h" - -#ifdef NGC -#include "freeze.h" +#include "memfile.h" #include "gccore.h" -#include "menudraw.h" -#endif - -//you would think everyone would have these -//since they're so useful. -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif +#include "ftfont.h" extern uint8 *SRAM; @@ -231,8 +194,8 @@ void S9xResetSaveTimer(bool8 dontsave){ static time_t t=-1; if(!dontsave && t!=-1 && time(NULL)-t>300){{ -#ifndef NGC - char def [PATH_MAX]; +#ifndef NGC + char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; @@ -243,8 +206,8 @@ void S9xResetSaveTimer(bool8 dontsave){ SLASH_STR, def, _MAX_EXT-1, "oops"); S9xMessage(S9X_INFO, S9X_FREEZE_FILE_INFO, "Auto-saving 'oops' savestate"); Snapshot(filename); -#endif - }} +#endif + }} t=time(NULL); } @@ -252,15 +215,13 @@ bool8 S9xUnfreezeZSNES (const char *filename); typedef struct { int offset; - int offset2; int size; int type; uint16 debuted_in, deleted_in; - const char* name; } FreezeData; enum { - INT_V, uint8_ARRAY_V, uint16_ARRAY_V, uint32_ARRAY_V, uint8_INDIR_ARRAY_V, uint16_INDIR_ARRAY_V, uint32_INDIR_ARRAY_V, POINTER_V + INT_V, uint8_ARRAY_V, uint16_ARRAY_V, uint32_ARRAY_V }; static struct Obsolete { @@ -271,142 +232,114 @@ static struct Obsolete { uint8 SAPU_Flags; } Obsolete; -#define COUNT(ARRAY) (sizeof (ARRAY) / sizeof (ARRAY[0])) -#define SIZE_TO_ARRAY_TYPE(s) ((s)==1 ? uint8_ARRAY_V : ((s)==2 ? uint16_ARRAY_V : uint32_ARRAY_V)) - #define Offset(field,structure) \ ((int) (((char *) (&(((structure)NULL)->field))) - ((char *) NULL))) #define DUMMY(f) Offset(f,struct Obsolete *) #define DELETED(f) (-1) -#define OFFSET(f) Offset(f, STRUCT *) -//#define ARRAY_ENTRY(save_version_introduced, field) {OFFSET(field), COUNT(((STRUCT*)NULL)->field), SIZE_TO_ARRAY_TYPE(sizeof(((STRUCT*)NULL)->field)), save_version_introduced, 9999} -#define INT_ENTRY(save_version_introduced, field) {OFFSET(field),0, sizeof(((STRUCT*)NULL)->field), INT_V, save_version_introduced, 9999, #field} -#define ARRAY_ENTRY(save_version_introduced, field, count, elemType) {OFFSET(field),0, count, elemType, save_version_introduced, 9999, #field} -#define POINTER_ENTRY(save_version_introduced, field, relativeToField) {OFFSET(field),OFFSET(relativeToField), 4, POINTER_V, save_version_introduced, 9999, #field} // size=4 -> (field - relativeToField) must fit in 4 bytes -#define OBSOLETE_INT_ENTRY(save_version_introduced, save_version_removed, field) {DUMMY(field),0, sizeof(((struct Obsolete*)NULL)->field), INT_V, save_version_introduced, save_version_removed, #field} -#define OBSOLETE_ARRAY_ENTRY(save_version_introduced, save_version_removed, field, count, elemType) {DUMMY(field),0, count, elemType, save_version_introduced, save_version_removed, #field} -#define OBSOLETE_POINTER_ENTRY(save_version_introduced, save_version_removed, field, relativeToField) {DUMMY(field),DUMMY(relativeToField), 4, POINTER_V, save_version_introduced, save_version_removed, #field} // size=4 -> (field - relativeToField) must fit in 4 bytes -#define DELETED_INT_ENTRY(save_version_introduced, save_version_removed, field, size) {DELETED(field),0, size, INT_V, save_version_introduced, save_version_removed, #field} -#define DELETED_ARRAY_ENTRY(save_version_introduced, save_version_removed, field, count, elemType) {DELETED(field),0, count, elemType, save_version_introduced, save_version_removed, #field} -#define DELETED_POINTER_ENTRY(save_version_introduced, save_version_removed, field, relativeToField) {DELETED(field),DELETED(relativeToField), 4, POINTER_V, save_version_introduced, save_version_removed, #field} // size=4 -> (field - relativeToField) must fit in 4 bytes + +#define COUNT(ARRAY) (sizeof (ARRAY) / sizeof (ARRAY[0])) struct SnapshotMovieInfo { uint32 MovieInputDataSize; }; -#undef STRUCT -#define STRUCT struct SnapshotMovieInfo +#undef OFFSET +#define OFFSET(f) Offset(f,struct SnapshotMovieInfo *) -#ifndef NGC - static FreezeData SnapMovie [] = { - INT_ENTRY(1, MovieInputDataSize), +#ifndef NGC +static FreezeData SnapMovie [] = { + {OFFSET (MovieInputDataSize), 4, INT_V, 1, 9999}, }; #endif -#undef STRUCT -#define STRUCT struct SCPUState +#undef OFFSET +#define OFFSET(f) Offset(f,struct SCPUState *) static FreezeData SnapCPU [] = { - INT_ENTRY(1, Flags), - INT_ENTRY(1, BranchSkip), - DELETED_INT_ENTRY(1,4, NMIActive,1), - INT_ENTRY(1, IRQActive), - INT_ENTRY(1, WaitingForInterrupt), - INT_ENTRY(1, WhichEvent), - INT_ENTRY(1, Cycles), - INT_ENTRY(1, NextEvent), - INT_ENTRY(1, V_Counter), - INT_ENTRY(1, MemSpeed), - INT_ENTRY(1, MemSpeedx2), - INT_ENTRY(1, FastROMSpeed), - // not sure if the following are necessary - INT_ENTRY(3, InDMAorHDMA), - INT_ENTRY(3, InWRAMDMAorHDMA), - INT_ENTRY(3, PBPCAtOpcodeStart), - INT_ENTRY(3, WaitAddress), - INT_ENTRY(3, WaitCounter), - DELETED_INT_ENTRY(3,4, AutoSaveTimer,4), - DELETED_INT_ENTRY(3,4, SRAMModified,1), - DELETED_INT_ENTRY(3,4, BRKTriggered,1), - INT_ENTRY(3, TriedInterleavedMode2), // deprecated - INT_ENTRY(4, IRQPending), // essential - INT_ENTRY(4, InDMA), - INT_ENTRY(4, InHDMA), - INT_ENTRY(4, HDMARanInDMA), - INT_ENTRY(4, PrevCycles), + {OFFSET (Flags), 4, INT_V, 1, 9999}, + {OFFSET (BranchSkip), 1, INT_V, 1, 9999}, + {OFFSET (NMIActive), 1, INT_V, 1, 9999}, + {OFFSET (IRQActive), 1, INT_V, 1, 9999}, + {OFFSET (WaitingForInterrupt), 1, INT_V, 1, 9999}, + {OFFSET (WhichEvent), 1, INT_V, 1, 9999}, + {OFFSET (Cycles), 4, INT_V, 1, 9999}, + {OFFSET (NextEvent), 4, INT_V, 1, 9999}, + {OFFSET (V_Counter), 4, INT_V, 1, 9999}, + {OFFSET (MemSpeed), 4, INT_V, 1, 9999}, + {OFFSET (MemSpeedx2), 4, INT_V, 1, 9999}, + {OFFSET (FastROMSpeed), 4, INT_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SRegisters +#undef OFFSET +#define OFFSET(f) Offset(f,struct SRegisters *) static FreezeData SnapRegisters [] = { - INT_ENTRY(1, PB), - INT_ENTRY(1, DB), - INT_ENTRY(1, P.W), - INT_ENTRY(1, A.W), - INT_ENTRY(1, D.W), - INT_ENTRY(1, S.W), - INT_ENTRY(1, X.W), - INT_ENTRY(1, Y.W), - INT_ENTRY(1, PCw), + {OFFSET (PB), 1, INT_V, 1, 9999}, + {OFFSET (DB), 1, INT_V, 1, 9999}, + {OFFSET (P.W), 2, INT_V, 1, 9999}, + {OFFSET (A.W), 2, INT_V, 1, 9999}, + {OFFSET (D.W), 2, INT_V, 1, 9999}, + {OFFSET (S.W), 2, INT_V, 1, 9999}, + {OFFSET (X.W), 2, INT_V, 1, 9999}, + {OFFSET (Y.W), 2, INT_V, 1, 9999}, + {OFFSET (PCw), 2, INT_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SPPU +#undef OFFSET +#define OFFSET(f) Offset(f,struct SPPU *) static FreezeData SnapPPU [] = { - INT_ENTRY(1, BGMode), - INT_ENTRY(1, BG3Priority), - INT_ENTRY(1, Brightness), - INT_ENTRY(1, VMA.High), - INT_ENTRY(1, VMA.Increment), - INT_ENTRY(1, VMA.Address), - INT_ENTRY(1, VMA.Mask1), - INT_ENTRY(1, VMA.FullGraphicCount), - INT_ENTRY(1, VMA.Shift), - INT_ENTRY(1, BG[0].SCBase), - INT_ENTRY(1, BG[0].VOffset), - INT_ENTRY(1, BG[0].HOffset), - INT_ENTRY(1, BG[0].BGSize), - INT_ENTRY(1, BG[0].NameBase), - INT_ENTRY(1, BG[0].SCSize), - - INT_ENTRY(1, BG[1].SCBase), - INT_ENTRY(1, BG[1].VOffset), - INT_ENTRY(1, BG[1].HOffset), - INT_ENTRY(1, BG[1].BGSize), - INT_ENTRY(1, BG[1].NameBase), - INT_ENTRY(1, BG[1].SCSize), - - INT_ENTRY(1, BG[2].SCBase), - INT_ENTRY(1, BG[2].VOffset), - INT_ENTRY(1, BG[2].HOffset), - INT_ENTRY(1, BG[2].BGSize), - INT_ENTRY(1, BG[2].NameBase), - INT_ENTRY(1, BG[2].SCSize), - - INT_ENTRY(1, BG[3].SCBase), - INT_ENTRY(1, BG[3].VOffset), - INT_ENTRY(1, BG[3].HOffset), - INT_ENTRY(1, BG[3].BGSize), - INT_ENTRY(1, BG[3].NameBase), - INT_ENTRY(1, BG[3].SCSize), - - INT_ENTRY(1, CGFLIP), - ARRAY_ENTRY(1, CGDATA, 256, uint16_ARRAY_V), - INT_ENTRY(1, FirstSprite), - INT_ENTRY(3, LastSprite), + {OFFSET (BGMode), 1, INT_V, 1, 9999}, + {OFFSET (BG3Priority), 1, INT_V, 1, 9999}, + {OFFSET (Brightness), 1, INT_V, 1, 9999}, + {OFFSET (VMA.High), 1, INT_V, 1, 9999}, + {OFFSET (VMA.Increment), 1, INT_V, 1, 9999}, + {OFFSET (VMA.Address), 2, INT_V, 1, 9999}, + {OFFSET (VMA.Mask1), 2, INT_V, 1, 9999}, + {OFFSET (VMA.FullGraphicCount), 2, INT_V, 1, 9999}, + {OFFSET (VMA.Shift), 2, INT_V, 1, 9999}, + {OFFSET (BG[0].SCBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[0].VOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[0].HOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[0].BGSize), 1, INT_V, 1, 9999}, + {OFFSET (BG[0].NameBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[0].SCSize), 2, INT_V, 1, 9999}, + + {OFFSET (BG[1].SCBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[1].VOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[1].HOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[1].BGSize), 1, INT_V, 1, 9999}, + {OFFSET (BG[1].NameBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[1].SCSize), 2, INT_V, 1, 9999}, + + {OFFSET (BG[2].SCBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[2].VOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[2].HOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[2].BGSize), 1, INT_V, 1, 9999}, + {OFFSET (BG[2].NameBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[2].SCSize), 2, INT_V, 1, 9999}, + + {OFFSET (BG[3].SCBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[3].VOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[3].HOffset), 2, INT_V, 1, 9999}, + {OFFSET (BG[3].BGSize), 1, INT_V, 1, 9999}, + {OFFSET (BG[3].NameBase), 2, INT_V, 1, 9999}, + {OFFSET (BG[3].SCSize), 2, INT_V, 1, 9999}, + + {OFFSET (CGFLIP), 1, INT_V, 1, 9999}, + {OFFSET (CGDATA), 256, uint16_ARRAY_V, 1, 9999}, + {OFFSET (FirstSprite), 1, INT_V, 1, 9999}, #define O(N) \ - INT_ENTRY(1, OBJ[N].HPos), \ - INT_ENTRY(1, OBJ[N].VPos), \ - INT_ENTRY(1, OBJ[N].Name), \ - INT_ENTRY(1, OBJ[N].VFlip), \ - INT_ENTRY(1, OBJ[N].HFlip), \ - INT_ENTRY(1, OBJ[N].Priority), \ - INT_ENTRY(1, OBJ[N].Palette), \ - INT_ENTRY(1, OBJ[N].Size) - + {OFFSET (OBJ[N].HPos), 2, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].VPos), 2, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].Name), 2, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].VFlip), 1, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].HFlip), 1, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].Priority), 1, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].Palette), 1, INT_V, 1, 9999}, \ + {OFFSET (OBJ[N].Size), 1, INT_V, 1, 9999} + O( 0), O( 1), O( 2), O( 3), O( 4), O( 5), O( 6), O( 7), O( 8), O( 9), O( 10), O( 11), O( 12), O( 13), O( 14), O( 15), O( 16), O( 17), O( 18), O( 19), O( 20), O( 21), O( 22), O( 23), @@ -424,502 +357,355 @@ static FreezeData SnapPPU [] = { O(112), O(113), O(114), O(115), O(116), O(117), O(118), O(119), O(120), O(121), O(122), O(123), O(124), O(125), O(126), O(127), #undef O - INT_ENTRY(1, OAMPriorityRotation), - INT_ENTRY(1, OAMAddr), - INT_ENTRY(1, OAMFlip), - INT_ENTRY(1, OAMTileAddress), - INT_ENTRY(1, IRQVBeamPos), - INT_ENTRY(1, IRQHBeamPos), - INT_ENTRY(1, VBeamPosLatched), - INT_ENTRY(1, HBeamPosLatched), - INT_ENTRY(1, HBeamFlip), - INT_ENTRY(1, VBeamFlip), - INT_ENTRY(1, HVBeamCounterLatched), - INT_ENTRY(1, MatrixA), - INT_ENTRY(1, MatrixB), - INT_ENTRY(1, MatrixC), - INT_ENTRY(1, MatrixD), - INT_ENTRY(1, CentreX), - INT_ENTRY(1, CentreY), - INT_ENTRY(2, M7HOFS), - INT_ENTRY(2, M7VOFS), - OBSOLETE_INT_ENTRY(1,2, SPPU_Joypad1ButtonReadPos), - OBSOLETE_INT_ENTRY(1,2, SPPU_Joypad2ButtonReadPos), - OBSOLETE_INT_ENTRY(1,2, SPPU_Joypad3ButtonReadPos), - INT_ENTRY(1, CGADD), - INT_ENTRY(1, FixedColourRed), - INT_ENTRY(1, FixedColourGreen), - INT_ENTRY(1, FixedColourBlue), - INT_ENTRY(1, SavedOAMAddr), - INT_ENTRY(1, ScreenHeight), - INT_ENTRY(1, WRAM), - DELETED_INT_ENTRY(3,3, BG_Forced,1), - INT_ENTRY(1, ForcedBlanking), - INT_ENTRY(3, OBJThroughMain), - INT_ENTRY(3, OBJThroughSub), - INT_ENTRY(1, OBJNameSelect), - INT_ENTRY(1, OBJSizeSelect), - INT_ENTRY(1, OBJNameBase), - INT_ENTRY(3, OBJAddition), - INT_ENTRY(1, OAMReadFlip), - INT_ENTRY(1, VTimerEnabled), - INT_ENTRY(1, HTimerEnabled), - INT_ENTRY(1, HTimerPosition), - INT_ENTRY(1, Mosaic), - INT_ENTRY(3, MosaicStart), - INT_ENTRY(1, Mode7HFlip), - INT_ENTRY(1, Mode7VFlip), - INT_ENTRY(1, Mode7Repeat), - INT_ENTRY(1, Window1Left), - INT_ENTRY(1, Window1Right), - INT_ENTRY(1, Window2Left), - INT_ENTRY(1, Window2Right), + {OFFSET (OAMPriorityRotation), 1, INT_V, 1, 9999}, + {OFFSET (OAMAddr), 2, INT_V, 1, 9999}, + {OFFSET (OAMFlip), 1, INT_V, 1, 9999}, + {OFFSET (OAMTileAddress), 2, INT_V, 1, 9999}, + {OFFSET (IRQVBeamPos), 2, INT_V, 1, 9999}, + {OFFSET (IRQHBeamPos), 2, INT_V, 1, 9999}, + {OFFSET (VBeamPosLatched), 2, INT_V, 1, 9999}, + {OFFSET (HBeamPosLatched), 2, INT_V, 1, 9999}, + {OFFSET (HBeamFlip), 1, INT_V, 1, 9999}, + {OFFSET (VBeamFlip), 1, INT_V, 1, 9999}, + {OFFSET (HVBeamCounterLatched), 1, INT_V, 1, 9999}, + {OFFSET (MatrixA), 2, INT_V, 1, 9999}, + {OFFSET (MatrixB), 2, INT_V, 1, 9999}, + {OFFSET (MatrixC), 2, INT_V, 1, 9999}, + {OFFSET (MatrixD), 2, INT_V, 1, 9999}, + {OFFSET (CentreX), 2, INT_V, 1, 9999}, + {OFFSET (CentreY), 2, INT_V, 1, 9999}, + {OFFSET (M7HOFS), 2, INT_V, 2, 9999}, + {OFFSET (M7VOFS), 2, INT_V, 2, 9999}, + {DUMMY (SPPU_Joypad1ButtonReadPos), 1, INT_V, 1, 2}, + {DUMMY (SPPU_Joypad2ButtonReadPos), 1, INT_V, 1, 2}, + {DUMMY (SPPU_Joypad3ButtonReadPos), 1, INT_V, 1, 2}, + {OFFSET (CGADD), 1, INT_V, 1, 9999}, + {OFFSET (FixedColourRed), 1, INT_V, 1, 9999}, + {OFFSET (FixedColourGreen), 1, INT_V, 1, 9999}, + {OFFSET (FixedColourBlue), 1, INT_V, 1, 9999}, + {OFFSET (SavedOAMAddr), 2, INT_V, 1, 9999}, + {OFFSET (ScreenHeight), 2, INT_V, 1, 9999}, + {OFFSET (WRAM), 4, INT_V, 1, 9999}, + {OFFSET (ForcedBlanking), 1, INT_V, 1, 9999}, + {OFFSET (OBJNameSelect), 2, INT_V, 1, 9999}, + {OFFSET (OBJSizeSelect), 1, INT_V, 1, 9999}, + {OFFSET (OBJNameBase), 2, INT_V, 1, 9999}, + {OFFSET (OAMReadFlip), 1, INT_V, 1, 9999}, + {OFFSET (VTimerEnabled), 1, INT_V, 1, 9999}, + {OFFSET (HTimerEnabled), 1, INT_V, 1, 9999}, + {OFFSET (HTimerPosition), 2, INT_V, 1, 9999}, + {OFFSET (Mosaic), 1, INT_V, 1, 9999}, + {OFFSET (Mode7HFlip), 1, INT_V, 1, 9999}, + {OFFSET (Mode7VFlip), 1, INT_V, 1, 9999}, + {OFFSET (Mode7Repeat), 1, INT_V, 1, 9999}, + {OFFSET (Window1Left), 1, INT_V, 1, 9999}, + {OFFSET (Window1Right), 1, INT_V, 1, 9999}, + {OFFSET (Window2Left), 1, INT_V, 1, 9999}, + {OFFSET (Window2Right), 1, INT_V, 1, 9999}, #define O(N) \ - INT_ENTRY(3, ClipCounts[N]), \ - INT_ENTRY(1, ClipWindowOverlapLogic[N]), \ - INT_ENTRY(1, ClipWindow1Enable[N]), \ - INT_ENTRY(1, ClipWindow2Enable[N]), \ - INT_ENTRY(1, ClipWindow1Inside[N]), \ - INT_ENTRY(1, ClipWindow2Inside[N]) - + {OFFSET (ClipWindowOverlapLogic[N]), 1, INT_V, 1, 9999}, \ + {OFFSET (ClipWindow1Enable[N]), 1, INT_V, 1, 9999}, \ + {OFFSET (ClipWindow2Enable[N]), 1, INT_V, 1, 9999}, \ + {OFFSET (ClipWindow1Inside[N]), 1, INT_V, 1, 9999}, \ + {OFFSET (ClipWindow2Inside[N]), 1, INT_V, 1, 9999} + O(0), O(1), O(2), O(3), O(4), O(5), + #undef O - INT_ENTRY(3, RecomputeClipWindows), - INT_ENTRY(1, CGFLIPRead), - INT_ENTRY(1, Need16x8Mulitply), - ARRAY_ENTRY(1, BGMosaic, 4, uint8_ARRAY_V), - ARRAY_ENTRY(1, OAMData, 512 + 32, uint8_ARRAY_V), - INT_ENTRY(1, Need16x8Mulitply), - OBSOLETE_ARRAY_ENTRY(1,2, SPPU_MouseSpeed, 2, uint8_ARRAY_V), - INT_ENTRY(2, OAMWriteRegister), - INT_ENTRY(2, BGnxOFSbyte), - INT_ENTRY(2, M7byte), - INT_ENTRY(2, OpenBus1), - INT_ENTRY(2, OpenBus2), - INT_ENTRY(3, GunVLatch), - INT_ENTRY(3, GunHLatch), - INT_ENTRY(2, VTimerPosition), + + {OFFSET (CGFLIPRead), 1, INT_V, 1, 9999}, + {OFFSET (Need16x8Mulitply), 1, INT_V, 1, 9999}, + {OFFSET (BGMosaic), 4, uint8_ARRAY_V, 1, 9999}, + {OFFSET (OAMData), 512 + 32, uint8_ARRAY_V, 1, 9999}, + {OFFSET (Need16x8Mulitply), 1, INT_V, 1, 9999}, + {DUMMY (SPPU_MouseSpeed), 2, uint8_ARRAY_V, 1, 2}, + {OFFSET (OAMWriteRegister), 2, INT_V, 2, 9999}, + {OFFSET (BGnxOFSbyte), 1, INT_V, 2, 9999}, + {OFFSET (M7byte), 1, INT_V, 2, 9999}, + {OFFSET (OpenBus1), 1, INT_V, 2, 9999}, + {OFFSET (OpenBus2), 1, INT_V, 2, 9999}, + {OFFSET (VTimerPosition), 2, INT_V, 2, 9999}, }; -#undef STRUCT -#define STRUCT struct SDMA +#undef OFFSET +#define OFFSET(f) Offset(f,struct SDMA *) static FreezeData SnapDMA [] = { #define O(N) \ - {OFFSET (ReverseTransfer) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "ReverseTransfer"}, \ - {OFFSET (AAddressFixed) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "AAddressFixed"}, \ - {OFFSET (AAddressDecrement) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "AAddressDecrement"}, \ - {OFFSET (TransferMode) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "TransferMode"}, \ - {OFFSET (ABank) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "ABank"}, \ - {OFFSET (AAddress) + N * sizeof (struct SDMA),0, 2, INT_V, 1, 9999, "AAddress"}, \ - {OFFSET (Address) + N * sizeof (struct SDMA),0, 2, INT_V, 1, 9999, "Address"}, \ - {OFFSET (BAddress) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "BAddress"}, \ - {DELETED (TransferBytes),0, 2, INT_V, 1, 2, "TransferBytes"}, \ - {OFFSET (HDMAIndirectAddressing) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "HDMAIndirectAddressing"}, \ - {OFFSET (DMACount_Or_HDMAIndirectAddress) + N * sizeof (struct SDMA),0, 2, INT_V, 1, 9999, "DMACount_Or_HDMAIndirectAddress"}, \ - {OFFSET (IndirectBank) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "IndirectBank"}, \ - {OFFSET (Repeat) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "Repeat"}, \ - {OFFSET (LineCount) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "LineCount"}, \ - {OFFSET (DoTransfer) + N * sizeof (struct SDMA),0, 1, INT_V, 1, 9999, "DoTransfer"}, \ - {OFFSET (UnknownByte) + N * sizeof (struct SDMA),0, 1, INT_V, 2, 9999, "UnknownByte"}, \ - {OFFSET (UnusedBit43x0) + N * sizeof (struct SDMA),0, 1, INT_V, 2, 9999, "UnusedBit43x0"} - + {OFFSET (TransferDirection) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (AAddressFixed) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (AAddressDecrement) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (TransferMode) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (ABank) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (AAddress) + N * sizeof (struct SDMA), 2, INT_V, 1, 9999}, \ + {OFFSET (Address) + N * sizeof (struct SDMA), 2, INT_V, 1, 9999}, \ + {OFFSET (BAddress) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {DELETED (TransferBytes), 2, INT_V, 1, 2}, \ + {OFFSET (HDMAIndirectAddressing) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (DMACount_Or_HDMAIndirectAddress) + N * sizeof (struct SDMA), 2, INT_V, 1, 9999}, \ + {OFFSET (IndirectBank) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (Repeat) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (LineCount) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (DoTransfer) + N * sizeof (struct SDMA), 1, INT_V, 1, 9999}, \ + {OFFSET (UnknownByte) + N * sizeof (struct SDMA), 1, INT_V, 2, 9999}, \ + {OFFSET (UnusedBit43x0) + N * sizeof (struct SDMA), 1, INT_V, 2, 9999} + O(0), O(1), O(2), O(3), O(4), O(5), O(6), O(7) #undef O }; -#undef STRUCT -#define STRUCT struct SAPU +#undef OFFSET +#define OFFSET(f) Offset(f,struct SAPU *) static FreezeData SnapAPU [] = { - INT_ENTRY(1, OldCycles), - INT_ENTRY(1, ShowROM), - OBSOLETE_INT_ENTRY(1,2, SAPU_Flags), - INT_ENTRY(2, Flags), - INT_ENTRY(1, KeyedChannels), - ARRAY_ENTRY(1, OutPorts, 4, uint8_ARRAY_V), - ARRAY_ENTRY(1, DSP, 0x80, uint8_ARRAY_V), - ARRAY_ENTRY(1, ExtraRAM, 64, uint8_ARRAY_V), - ARRAY_ENTRY(1, Timer, 3, uint16_ARRAY_V), - ARRAY_ENTRY(1, TimerTarget, 3, uint16_ARRAY_V), - ARRAY_ENTRY(1, TimerEnabled, 3, uint8_ARRAY_V), - ARRAY_ENTRY(1, TimerValueWritten, 3, uint8_ARRAY_V), - INT_ENTRY(4, Cycles), + {OFFSET (Cycles), 4, INT_V, 1, 9999}, + {OFFSET (ShowROM), 1, INT_V, 1, 9999}, + {DUMMY (SAPU_Flags), 1, INT_V, 1, 2}, + {OFFSET (Flags), 4, INT_V, 2, 9999}, + {OFFSET (KeyedChannels), 1, INT_V, 1, 9999}, + {OFFSET (OutPorts), 4, uint8_ARRAY_V, 1, 9999}, + {OFFSET (DSP), 0x80, uint8_ARRAY_V, 1, 9999}, + {OFFSET (ExtraRAM), 64, uint8_ARRAY_V, 1, 9999}, + {OFFSET (Timer), 3, uint16_ARRAY_V, 1, 9999}, + {OFFSET (TimerTarget), 3, uint16_ARRAY_V, 1, 9999}, + {OFFSET (TimerEnabled), 3, uint8_ARRAY_V, 1, 9999}, + {OFFSET (TimerValueWritten), 3, uint8_ARRAY_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SAPURegisters +#undef OFFSET +#define OFFSET(f) Offset(f,struct SAPURegisters *) static FreezeData SnapAPURegisters [] = { - INT_ENTRY(1, P), - INT_ENTRY(1, YA.W), - INT_ENTRY(1, X), - INT_ENTRY(1, S), - INT_ENTRY(1, PC), + {OFFSET (P), 1, INT_V, 1, 9999}, + {OFFSET (YA.W), 2, INT_V, 1, 9999}, + {OFFSET (X), 1, INT_V, 1, 9999}, + {OFFSET (S), 1, INT_V, 1, 9999}, + {OFFSET (PC), 2, INT_V, 1, 9999}, }; -#undef STRUCT -#define STRUCT SSoundData +#undef OFFSET +#define OFFSET(f) Offset(f,SSoundData *) static FreezeData SnapSoundData [] = { - INT_ENTRY(1, master_volume_left), - INT_ENTRY(1, master_volume_right), - INT_ENTRY(1, echo_volume_left), - INT_ENTRY(1, echo_volume_right), - INT_ENTRY(1, echo_enable), - INT_ENTRY(1, echo_feedback), - INT_ENTRY(1, echo_ptr), - INT_ENTRY(1, echo_buffer_size), - INT_ENTRY(1, echo_write_enabled), - INT_ENTRY(1, echo_channel_enable), - INT_ENTRY(1, pitch_mod), - ARRAY_ENTRY(1, dummy, 3, uint32_ARRAY_V), + {OFFSET (master_volume_left), 2, INT_V, 1, 9999}, + {OFFSET (master_volume_right), 2, INT_V, 1, 9999}, + {OFFSET (echo_volume_left), 2, INT_V, 1, 9999}, + {OFFSET (echo_volume_right), 2, INT_V, 1, 9999}, + {OFFSET (echo_enable), 4, INT_V, 1, 9999}, + {OFFSET (echo_feedback), 4, INT_V, 1, 9999}, + {OFFSET (echo_ptr), 4, INT_V, 1, 9999}, + {OFFSET (echo_buffer_size), 4, INT_V, 1, 9999}, + {OFFSET (echo_write_enabled), 4, INT_V, 1, 9999}, + {OFFSET (echo_channel_enable), 4, INT_V, 1, 9999}, + {OFFSET (pitch_mod), 4, INT_V, 1, 9999}, + {OFFSET (dummy), 3, uint32_ARRAY_V, 1, 9999}, #define O(N) \ - INT_ENTRY(1, channels [N].state), \ - INT_ENTRY(1, channels [N].type), \ - INT_ENTRY(1, channels [N].volume_left), \ - INT_ENTRY(1, channels [N].volume_right), \ - INT_ENTRY(1, channels [N].hertz), \ - INT_ENTRY(1, channels [N].count), \ - INT_ENTRY(1, channels [N].loop), \ - INT_ENTRY(1, channels [N].envx), \ - INT_ENTRY(1, channels [N].left_vol_level), \ - INT_ENTRY(1, channels [N].right_vol_level), \ - INT_ENTRY(1, channels [N].envx_target), \ - INT_ENTRY(1, channels [N].env_error), \ - INT_ENTRY(1, channels [N].erate), \ - INT_ENTRY(1, channels [N].direction), \ - INT_ENTRY(1, channels [N].attack_rate), \ - INT_ENTRY(1, channels [N].decay_rate), \ - INT_ENTRY(1, channels [N].sustain_rate), \ - INT_ENTRY(1, channels [N].release_rate), \ - INT_ENTRY(1, channels [N].sustain_level), \ - INT_ENTRY(1, channels [N].sample), \ - ARRAY_ENTRY(1, channels [N].decoded, 16, uint16_ARRAY_V), \ - ARRAY_ENTRY(1, channels [N].previous16, 2, uint16_ARRAY_V), \ - INT_ENTRY(1, channels [N].sample_number), \ - INT_ENTRY(1, channels [N].last_block), \ - INT_ENTRY(1, channels [N].needs_decode), \ - INT_ENTRY(1, channels [N].block_pointer), \ - INT_ENTRY(1, channels [N].sample_pointer), \ - INT_ENTRY(1, channels [N].mode) - + {OFFSET (channels [N].state), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].type), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].volume_left), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].volume_right), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].hertz), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].count), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].loop), 1, INT_V, 1, 9999}, \ + {OFFSET (channels [N].envx), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].left_vol_level), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].right_vol_level), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].envx_target), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].env_error), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].erate), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].direction), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].attack_rate), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].decay_rate), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].sustain_rate), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].release_rate), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].sustain_level), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].sample), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].decoded), 16, uint16_ARRAY_V, 1, 9999}, \ + {OFFSET (channels [N].previous16), 2, uint16_ARRAY_V, 1, 9999}, \ + {OFFSET (channels [N].sample_number), 2, INT_V, 1, 9999}, \ + {OFFSET (channels [N].last_block), 1, INT_V, 1, 9999}, \ + {OFFSET (channels [N].needs_decode), 1, INT_V, 1, 9999}, \ + {OFFSET (channels [N].block_pointer), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].sample_pointer), 4, INT_V, 1, 9999}, \ + {OFFSET (channels [N].mode), 4, INT_V, 1, 9999} + O(0), O(1), O(2), O(3), O(4), O(5), O(6), O(7), #undef O - INT_ENTRY(2, noise_rate), + {OFFSET (noise_rate), 4, INT_V, 2, 9999}, #define O(N) \ - INT_ENTRY(2, channels [N].out_sample), \ - INT_ENTRY(2, channels [N].xenvx), \ - INT_ENTRY(2, channels [N].xenvx_target), \ - INT_ENTRY(2, channels [N].xenv_count), \ - INT_ENTRY(2, channels [N].xenv_rate), \ - INT_ENTRY(2, channels [N].xattack_rate), \ - INT_ENTRY(2, channels [N].xdecay_rate), \ - INT_ENTRY(2, channels [N].xsustain_rate), \ - INT_ENTRY(2, channels [N].xsustain_level) - - O(0), O(1), O(2), O(3), O(4), O(5), O(6), O(7), + {OFFSET (channels [N].out_sample), 2, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xenvx), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xenvx_target), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xenv_count), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xenv_rate), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xattack_rate), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xdecay_rate), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xsustain_rate), 4, INT_V, 2, 9999}, \ + {OFFSET (channels [N].xsustain_level), 4, INT_V, 2, 9999} + + O(0), O(1), O(2), O(3), O(4), O(5), O(6), O(7) #undef O - INT_ENTRY(4, noise_count), - INT_ENTRY(4, no_filter), - INT_ENTRY(4, echo_volume[0]), - INT_ENTRY(4, echo_volume[1]), - INT_ENTRY(4, master_volume[0]), - INT_ENTRY(4, master_volume[1]), }; -#undef STRUCT -#define STRUCT struct SSA1Registers +#undef OFFSET +#define OFFSET(f) Offset(f,struct SSA1Registers *) static FreezeData SnapSA1Registers [] = { - INT_ENTRY(1, PB), - INT_ENTRY(1, DB), - INT_ENTRY(1, P.W), - INT_ENTRY(1, A.W), - INT_ENTRY(1, D.W), - INT_ENTRY(1, S.W), - INT_ENTRY(1, X.W), - INT_ENTRY(1, Y.W), - INT_ENTRY(1, PCw), + {OFFSET (PB), 1, INT_V, 1, 9999}, + {OFFSET (DB), 1, INT_V, 1, 9999}, + {OFFSET (P.W), 2, INT_V, 1, 9999}, + {OFFSET (A.W), 2, INT_V, 1, 9999}, + {OFFSET (D.W), 2, INT_V, 1, 9999}, + {OFFSET (S.W), 2, INT_V, 1, 9999}, + {OFFSET (X.W), 2, INT_V, 1, 9999}, + {OFFSET (Y.W), 2, INT_V, 1, 9999}, + {OFFSET (PCw), 2, INT_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SSA1 +#undef OFFSET +#define OFFSET(f) Offset(f,struct SSA1 *) static FreezeData SnapSA1 [] = { - INT_ENTRY(1, Flags), - INT_ENTRY(1, NMIActive), - INT_ENTRY(1, IRQActive), - INT_ENTRY(1, WaitingForInterrupt), - INT_ENTRY(1, op1), - INT_ENTRY(1, op2), - INT_ENTRY(1, arithmetic_op), - INT_ENTRY(1, sum), - INT_ENTRY(1, overflow), - // not sure if the following are necessary, but better safe than sorry - INT_ENTRY(3, CPUExecuting), - INT_ENTRY(3, ShiftedPB), - INT_ENTRY(3, ShiftedDB), - INT_ENTRY(3, Executing), - INT_ENTRY(3, Waiting), - INT_ENTRY(3, PBPCAtOpcodeStart), - INT_ENTRY(3, WaitAddress), - INT_ENTRY(3, WaitCounter), - INT_ENTRY(3, VirtualBitmapFormat), - INT_ENTRY(3, in_char_dma), - INT_ENTRY(3, variable_bit_pos), -}; - -#undef STRUCT -#define STRUCT struct SDSP1 - -static FreezeData SnapDSP1 [] = { - INT_ENTRY(3, version), - INT_ENTRY(3, waiting4command), - INT_ENTRY(3, first_parameter), - INT_ENTRY(3, command), - INT_ENTRY(3, in_count), - INT_ENTRY(3, in_index), - INT_ENTRY(3, out_count), - INT_ENTRY(3, out_index), - ARRAY_ENTRY(3, parameters, 512, uint8_ARRAY_V), - ARRAY_ENTRY(3, output, 512, uint8_ARRAY_V), - ARRAY_ENTRY(4, temp_save_data, sizeof(DSP1.temp_save_data), uint8_ARRAY_V), + {OFFSET (Flags), 4, INT_V, 1, 9999}, + {OFFSET (NMIActive), 1, INT_V, 1, 9999}, + {OFFSET (IRQActive), 1, INT_V, 1, 9999}, + {OFFSET (WaitingForInterrupt), 1, INT_V, 1, 9999}, + {OFFSET (op1), 2, INT_V, 1, 9999}, + {OFFSET (op2), 2, INT_V, 1, 9999}, + {OFFSET (arithmetic_op), 4, INT_V, 1, 9999}, + {OFFSET (sum), 8, INT_V, 1, 9999}, + {OFFSET (overflow), 1, INT_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SPC7110EmuVars +#undef OFFSET +#define OFFSET(f) Offset(f,struct SPC7110EmuVars *) static FreezeData SnapSPC7110 [] = { - INT_ENTRY(1, reg4800), - INT_ENTRY(1, reg4801), - INT_ENTRY(1, reg4802), - INT_ENTRY(1, reg4803), - INT_ENTRY(1, reg4804), - INT_ENTRY(1, reg4805), - INT_ENTRY(1, reg4806), - INT_ENTRY(1, reg4807), - INT_ENTRY(1, reg4808), - INT_ENTRY(1, reg4809), - INT_ENTRY(1, reg480A), - INT_ENTRY(1, reg480B), - INT_ENTRY(1, reg480C), - INT_ENTRY(1, reg4811), - INT_ENTRY(1, reg4812), - INT_ENTRY(1, reg4813), - INT_ENTRY(1, reg4814), - INT_ENTRY(1, reg4815), - INT_ENTRY(1, reg4816), - INT_ENTRY(1, reg4817), - INT_ENTRY(1, reg4818), - INT_ENTRY(1, reg4820), - INT_ENTRY(1, reg4821), - INT_ENTRY(1, reg4822), - INT_ENTRY(1, reg4823), - INT_ENTRY(1, reg4824), - INT_ENTRY(1, reg4825), - INT_ENTRY(1, reg4826), - INT_ENTRY(1, reg4827), - INT_ENTRY(1, reg4828), - INT_ENTRY(1, reg4829), - INT_ENTRY(1, reg482A), - INT_ENTRY(1, reg482B), - INT_ENTRY(1, reg482C), - INT_ENTRY(1, reg482D), - INT_ENTRY(1, reg482E), - INT_ENTRY(1, reg482F), - INT_ENTRY(1, reg4830), - INT_ENTRY(1, reg4831), - INT_ENTRY(1, reg4832), - INT_ENTRY(1, reg4833), - INT_ENTRY(1, reg4834), - INT_ENTRY(1, reg4840), - INT_ENTRY(1, reg4841), - INT_ENTRY(1, reg4842), - INT_ENTRY(1, AlignBy), - INT_ENTRY(1, written), - INT_ENTRY(1, offset_add), - INT_ENTRY(1, DataRomOffset), - INT_ENTRY(1, DataRomSize), - INT_ENTRY(1, bank50Internal), - ARRAY_ENTRY(1, bank50, 0x10000, uint8_ARRAY_V), + {OFFSET (reg4800), 1, INT_V, 1, 9999}, + {OFFSET (reg4801), 1, INT_V, 1, 9999}, + {OFFSET (reg4802), 1, INT_V, 1, 9999}, + {OFFSET (reg4803), 1, INT_V, 1, 9999}, + {OFFSET (reg4804), 1, INT_V, 1, 9999}, + {OFFSET (reg4805), 1, INT_V, 1, 9999}, + {OFFSET (reg4806), 1, INT_V, 1, 9999}, + {OFFSET (reg4807), 1, INT_V, 1, 9999}, + {OFFSET (reg4808), 1, INT_V, 1, 9999}, + {OFFSET (reg4809), 1, INT_V, 1, 9999}, + {OFFSET (reg480A), 1, INT_V, 1, 9999}, + {OFFSET (reg480B), 1, INT_V, 1, 9999}, + {OFFSET (reg480C), 1, INT_V, 1, 9999}, + {OFFSET (reg4811), 1, INT_V, 1, 9999}, + {OFFSET (reg4812), 1, INT_V, 1, 9999}, + {OFFSET (reg4813), 1, INT_V, 1, 9999}, + {OFFSET (reg4814), 1, INT_V, 1, 9999}, + {OFFSET (reg4815), 1, INT_V, 1, 9999}, + {OFFSET (reg4816), 1, INT_V, 1, 9999}, + {OFFSET (reg4817), 1, INT_V, 1, 9999}, + {OFFSET (reg4818), 1, INT_V, 1, 9999}, + {OFFSET (reg4820), 1, INT_V, 1, 9999}, + {OFFSET (reg4821), 1, INT_V, 1, 9999}, + {OFFSET (reg4822), 1, INT_V, 1, 9999}, + {OFFSET (reg4823), 1, INT_V, 1, 9999}, + {OFFSET (reg4824), 1, INT_V, 1, 9999}, + {OFFSET (reg4825), 1, INT_V, 1, 9999}, + {OFFSET (reg4826), 1, INT_V, 1, 9999}, + {OFFSET (reg4827), 1, INT_V, 1, 9999}, + {OFFSET (reg4828), 1, INT_V, 1, 9999}, + {OFFSET (reg4829), 1, INT_V, 1, 9999}, + {OFFSET (reg482A), 1, INT_V, 1, 9999}, + {OFFSET (reg482B), 1, INT_V, 1, 9999}, + {OFFSET (reg482C), 1, INT_V, 1, 9999}, + {OFFSET (reg482D), 1, INT_V, 1, 9999}, + {OFFSET (reg482E), 1, INT_V, 1, 9999}, + {OFFSET (reg482F), 1, INT_V, 1, 9999}, + {OFFSET (reg4830), 1, INT_V, 1, 9999}, + {OFFSET (reg4831), 1, INT_V, 1, 9999}, + {OFFSET (reg4832), 1, INT_V, 1, 9999}, + {OFFSET (reg4833), 1, INT_V, 1, 9999}, + {OFFSET (reg4834), 1, INT_V, 1, 9999}, + {OFFSET (reg4840), 1, INT_V, 1, 9999}, + {OFFSET (reg4841), 1, INT_V, 1, 9999}, + {OFFSET (reg4842), 1, INT_V, 1, 9999}, + {OFFSET (AlignBy), 1, INT_V, 1, 9999}, + {OFFSET (written), 1, INT_V, 1, 9999}, + {OFFSET (offset_add), 1, INT_V, 1, 9999}, + {OFFSET (DataRomOffset), 4, INT_V, 1, 9999}, + {OFFSET (DataRomSize), 4, INT_V, 1, 9999}, + {OFFSET (bank50Internal), 4, INT_V, 1, 9999}, + {OFFSET (bank50), 0x10000, uint8_ARRAY_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SPC7110RTC +#undef OFFSET +#define OFFSET(f) Offset(f,struct SPC7110RTC *) static FreezeData SnapS7RTC [] = { - ARRAY_ENTRY(1, reg, 16, uint8_ARRAY_V), - INT_ENTRY(1, index), - INT_ENTRY(1, control), - INT_ENTRY(1, init), - INT_ENTRY(1, last_used), + {OFFSET (reg), 16, uint8_ARRAY_V, 1, 9999}, + {OFFSET (index), 2, INT_V, 1, 9999}, + {OFFSET (control), 1, INT_V, 1, 9999}, + {OFFSET (init), 1, INT_V, 1, 9999}, + {OFFSET (last_used), 4, INT_V, 1, 9999} }; -#undef STRUCT -#define STRUCT struct SControlSnapshot +#undef OFFSET +#define OFFSET(f) Offset(f,struct SControlSnapshot *) static FreezeData SnapControls [] = { - INT_ENTRY(2, ver), - ARRAY_ENTRY(2, port1_read_idx, 2, uint8_ARRAY_V), - ARRAY_ENTRY(2, dummy1, 4, uint8_ARRAY_V), - ARRAY_ENTRY(2, port2_read_idx, 2, uint8_ARRAY_V), - ARRAY_ENTRY(2, dummy2, 4, uint8_ARRAY_V), - ARRAY_ENTRY(2, mouse_speed, 2, uint8_ARRAY_V), - INT_ENTRY(2, justifier_select), - ARRAY_ENTRY(2, dummy3, 8, uint8_ARRAY_V), - INT_ENTRY(4, pad_read), - INT_ENTRY(4, pad_read_last), - ARRAY_ENTRY(3, internal, 60, uint8_ARRAY_V), // yes, we need to save this! + {OFFSET (ver), 1, INT_V, 2, 9999}, + {OFFSET (port1_read_idx), 2, uint8_ARRAY_V, 2, 9999}, + {OFFSET (dummy1), 4, uint8_ARRAY_V, 2, 9999}, + {OFFSET (port2_read_idx), 2, uint8_ARRAY_V, 2, 9999}, + {OFFSET (dummy2), 4, uint8_ARRAY_V, 2, 9999}, + {OFFSET (mouse_speed), 2, uint8_ARRAY_V, 2, 9999}, + {OFFSET (justifier_select), 1, INT_V, 2, 9999}, + {OFFSET (dummy3), 10, uint8_ARRAY_V, 2, 9999} }; -#undef STRUCT -#define STRUCT struct STimings +#undef OFFSET +#define OFFSET(f) Offset(f,struct STimings *) static FreezeData SnapTimings [] = { - INT_ENTRY(2, H_Max_Master), - INT_ENTRY(2, H_Max), - INT_ENTRY(2, V_Max_Master), - INT_ENTRY(2, V_Max), - INT_ENTRY(2, HBlankStart), - INT_ENTRY(2, HBlankEnd), - INT_ENTRY(2, HDMAInit), - INT_ENTRY(2, HDMAStart), - INT_ENTRY(2, NMITriggerPos), - INT_ENTRY(2, WRAMRefreshPos), - INT_ENTRY(2, RenderPos), - INT_ENTRY(2, InterlaceField), - INT_ENTRY(4, DMACPUSync), + {OFFSET (H_Max_Master), 4, INT_V, 2, 9999}, + {OFFSET (H_Max), 4, INT_V, 2, 9999}, + {OFFSET (V_Max_Master), 4, INT_V, 2, 9999}, + {OFFSET (V_Max), 4, INT_V, 2, 9999}, + {OFFSET (HBlankStart), 4, INT_V, 2, 9999}, + {OFFSET (HBlankEnd), 4, INT_V, 2, 9999}, + {OFFSET (HDMAInit), 4, INT_V, 2, 9999}, + {OFFSET (HDMAStart), 4, INT_V, 2, 9999}, + {OFFSET (NMITriggerPos), 4, INT_V, 2, 9999}, + {OFFSET (WRAMRefreshPos), 4, INT_V, 2, 9999}, + {OFFSET (RenderPos), 4, INT_V, 2, 9999}, + {OFFSET (InterlaceField), 1, INT_V, 2, 9999} }; -#undef STRUCT -#define STRUCT struct SBSX +#undef OFFSET +#define OFFSET(f) Offset(f,struct SBSX *) static FreezeData SnapBSX [] = { - INT_ENTRY(2, dirty), - INT_ENTRY(2, dirty2), - INT_ENTRY(2, bootup), - INT_ENTRY(2, flash_enable), - INT_ENTRY(2, write_enable), - INT_ENTRY(2, read_enable), - INT_ENTRY(2, flash_command), - INT_ENTRY(2, old_write), - INT_ENTRY(2, new_write), - INT_ENTRY(2, out_index), - ARRAY_ENTRY(2, output, 32, uint8_ARRAY_V), - ARRAY_ENTRY(2, PPU, 32, uint8_ARRAY_V), - ARRAY_ENTRY(2, MMC, 16, uint8_ARRAY_V), - ARRAY_ENTRY(2, prevMMC, 16, uint8_ARRAY_V), - ARRAY_ENTRY(2, test2192, 32, uint8_ARRAY_V), + {OFFSET (dirty), 1, INT_V, 2, 9999}, + {OFFSET (dirty2), 1, INT_V, 2, 9999}, + {OFFSET (bootup), 1, INT_V, 2, 9999}, + {OFFSET (flash_enable), 1, INT_V, 2, 9999}, + {OFFSET (write_enable), 1, INT_V, 2, 9999}, + {OFFSET (read_enable), 1, INT_V, 2, 9999}, + {OFFSET (flash_command), 4, INT_V, 2, 9999}, + {OFFSET (old_write), 4, INT_V, 2, 9999}, + {OFFSET (new_write), 4, INT_V, 2, 9999}, + {OFFSET (out_index), 1, INT_V, 2, 9999}, + {OFFSET (output), 32, uint8_ARRAY_V, 2, 9999}, + {OFFSET (PPU), 32, uint8_ARRAY_V, 2, 9999}, + {OFFSET (MMC), 16, uint8_ARRAY_V, 2, 9999}, + {OFFSET (prevMMC), 16, uint8_ARRAY_V, 2, 9999}, + {OFFSET (test2192), 32, uint8_ARRAY_V, 2, 9999} }; -// deleted blocks -static FreezeData SnapIPPU [] = { - DELETED_ARRAY_ENTRY(3,4, Junk, 2, uint32_ARRAY_V), -}; -static FreezeData SnapGFX [] = { - DELETED_ARRAY_ENTRY(3,4, Junk, 22+256+MAX_SNES_WIDTH*MAX_SNES_HEIGHT*2, uint8_ARRAY_V), -}; - - -#ifndef NGC -struct SnapshotScreenshotInfo -{ - uint16 Width; - uint16 Height; - uint8 Data [MAX_SNES_WIDTH * MAX_SNES_HEIGHT * 3]; - uint8 Interlaced; -}; - -#undef STRUCT -#define STRUCT struct SnapshotScreenshotInfo - -static FreezeData SnapScreenshot [] = { - INT_ENTRY(4, Width), - INT_ENTRY(4, Height), - ARRAY_ENTRY(4, Data, MAX_SNES_WIDTH * MAX_SNES_HEIGHT * 3, uint8_ARRAY_V), - INT_ENTRY(4, Interlaced), // needed in case interlacing was on before loading a state where it is off -}; -#endif - -#ifndef ZSNES_FX - extern struct FxRegs_s GSU; - - #undef STRUCT - #define STRUCT struct FxRegs_s - - // TODO: figure out which of these are completely unnecessary. Many of them are necessary. - static FreezeData SnapFX [] = { - INT_ENTRY(4, vColorReg), - INT_ENTRY(4, vPlotOptionReg), - INT_ENTRY(4, vStatusReg), - INT_ENTRY(4, vPrgBankReg), - INT_ENTRY(4, vRomBankReg), - INT_ENTRY(4, vRamBankReg), - INT_ENTRY(4, vCacheBaseReg), - INT_ENTRY(4, vCacheFlags), - INT_ENTRY(4, vLastRamAdr), - INT_ENTRY(4, vPipeAdr), - INT_ENTRY(4, vSign), - INT_ENTRY(4, vZero), - INT_ENTRY(4, vCarry), - INT_ENTRY(4, vOverflow), - INT_ENTRY(4, vErrorCode), - INT_ENTRY(4, vIllegalAddress), - INT_ENTRY(4, vBreakPoint), - INT_ENTRY(4, vStepPoint), - INT_ENTRY(4, nRamBanks), - INT_ENTRY(4, nRomBanks), - INT_ENTRY(4, vMode), - INT_ENTRY(4, vPrevMode), - INT_ENTRY(4, vScreenHeight), - INT_ENTRY(4, vScreenRealHeight), - INT_ENTRY(4, vPrevScreenHeight), - INT_ENTRY(4, vScreenSize), - INT_ENTRY(4, vCounter), - INT_ENTRY(4, vInstCount), - INT_ENTRY(4, vSCBRDirty), - INT_ENTRY(4, vRomBuffer), - INT_ENTRY(4, vPipe), - INT_ENTRY(4, bCacheActive), - INT_ENTRY(4, bBreakPoint), - ARRAY_ENTRY(4, avCacheBackup, 512, uint8_ARRAY_V), - ARRAY_ENTRY(4, avReg, 16, uint32_ARRAY_V), - ARRAY_ENTRY(4, x, 32, uint32_ARRAY_V), - POINTER_ENTRY(4, pvScreenBase, pvRam), - POINTER_ENTRY(4, pvPrgBank, apvRomBank), - POINTER_ENTRY(4, pvDreg, avReg), - POINTER_ENTRY(4, pvSreg, avReg), -#define O(N) POINTER_ENTRY(4, apvScreen[N], pvRam) - O( 0), O( 1), O( 2), O( 3), O( 4), O( 5), O( 6), O( 7), - O( 8), O( 9), O( 10), O( 11), O( 12), O( 13), O( 14), O( 15), - O( 16), O( 17), O( 18), O( 19), O( 20), O( 21), O( 22), O( 23), - O( 24), O( 25), O( 26), O( 27), O( 28), O( 29), O( 30), O( 31), -#undef O - POINTER_ENTRY(4, pvRamBank, apvRamBank), - POINTER_ENTRY(4, pvRomBank, apvRomBank), - POINTER_ENTRY(4, pvCache, pvRegisters), - POINTER_ENTRY(4, apvRamBank[0], pvRam), - POINTER_ENTRY(4, apvRamBank[1], pvRam), - POINTER_ENTRY(4, apvRamBank[2], pvRam), - POINTER_ENTRY(4, apvRamBank[3], pvRam), -// uint8 * apvRomBank[256]; // probably OK to not save it, because it only changes in FxReset -// uint8 * pvRegisters; // can't save, but no need -// uint8 * pvRam; // can't save, but no need -// uint8 * pvRom; // can't save, but no need -// void (*pfPlot)(); // can't save, so we set it after loading -// void (*pfRpix)(); // can't save, so we set it after loading - }; -#endif - - static char ROMFilename [_MAX_PATH]; //static char SnapshotFilename [_MAX_PATH]; void FreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields, int num_fields); -void FreezeBlock (STREAM stream, char *name, uint8 *block, int size); +void FreezeBlock (STREAM stream, char *name, uint8 *block, int size); #ifdef NGC extern void NGCFreezeBlock (char *name, uint8 *block, int size); extern int NGCUnFreezeBlock( char *name, uint8 *block, int size ); @@ -940,6 +726,7 @@ void S9xCloseSnapshotFile (FILE *stream) { fclose(stream); } + bool8 Snapshot (const char *filename) { return (S9xFreezeGame (filename)); @@ -949,34 +736,28 @@ bool8 S9xFreezeGame (const char *filename) { STREAM stream = NULL; -#ifndef NGC +#ifndef NGC if (S9xOpenSnapshotFile (filename, FALSE, &stream)) #endif - { + { S9xPrepareSoundForSnapshotSave (FALSE); - + S9xFreezeToStream (stream); S9xCloseSnapshotFile (stream); S9xPrepareSoundForSnapshotSave (TRUE); - + S9xResetSaveTimer (TRUE); -#ifndef NGC +#ifndef NGC if(S9xMovieActive()) { - const char * name = S9xBasename (filename); - if(name && strlen(name) > 3) - name += strlen(name) - 3; - else - name = filename; - sprintf(String, MOVIE_INFO_SNAPSHOT " %s", name); + sprintf(String, "Movie snapshot %s", S9xBasename (filename)); S9xMessage (S9X_INFO, S9X_FREEZE_FILE_INFO, String); - GFX.InfoStringTimeout /= 4; } - else + else { - sprintf(String, SAVE_INFO_SNAPSHOT " %s", S9xBasename (filename)); + sprintf(String, "Saved %s", S9xBasename (filename)); S9xMessage (S9X_INFO, S9X_FREEZE_FILE_INFO, String); } #endif @@ -992,14 +773,14 @@ bool8 S9xLoadSnapshot (const char *filename) bool8 S9xUnfreezeGame (const char *filename) { - char def [PATH_MAX + 1 ]; - char drive [_MAX_DRIVE + 1]; - char dir [_MAX_DIR + 1 ]; - char ext [_MAX_EXT + 1 ] ; + char def [PATH_MAX]; + char drive [_MAX_DRIVE]; + char dir [_MAX_DIR]; + char ext [_MAX_EXT]; _splitpath (filename, drive, dir, def, ext); S9xResetSaveTimer (!strcmp(ext, "oops") || !strcmp(ext, "oop")); - + ZeroMemory (&Obsolete, sizeof(Obsolete)); #ifndef NGC @@ -1008,25 +789,32 @@ bool8 S9xUnfreezeGame (const char *filename) if (S9xLoadOrigSnapshot (filename)) return (TRUE); + if (S9xUnfreezeZSNES (filename)) return (TRUE); -#endif +#endif + STREAM snapshot = NULL; + #ifndef NGC - if (S9xOpenSnapshotFile (filename, TRUE, &snapshot)) + if (S9xOpenSnapshotFile (filename, TRUE, &snapshot)) #endif - { + { int result; if ((result = S9xUnfreezeFromStream (snapshot)) != SUCCESS) { switch (result) { case WRONG_FORMAT: - S9xMessage (S9X_ERROR, S9X_WRONG_FORMAT, SAVE_ERR_WRONG_FORMAT); + S9xMessage (S9X_ERROR, S9X_WRONG_FORMAT, + "File not in Snes9x freeze format"); + WaitPrompt("File not in Snes9x freeze format"); break; case WRONG_VERSION: - S9xMessage (S9X_ERROR, S9X_WRONG_VERSION, SAVE_ERR_WRONG_VERSION); + S9xMessage (S9X_ERROR, S9X_WRONG_VERSION, + "Incompatable Snes9x freeze file format version"); + WaitPrompt("Incompatable Snes9x freeze file format version"); break; case WRONG_MOVIE_SNAPSHOT: S9xMessage (S9X_ERROR, S9X_WRONG_MOVIE_SNAPSHOT, MOVIE_ERR_SNAPSHOT_WRONG_MOVIE); @@ -1034,13 +822,12 @@ bool8 S9xUnfreezeGame (const char *filename) case NOT_A_MOVIE_SNAPSHOT: S9xMessage (S9X_ERROR, S9X_NOT_A_MOVIE_SNAPSHOT, MOVIE_ERR_SNAPSHOT_NOT_MOVIE); break; - case SNAPSHOT_INCONSISTENT: - S9xMessage (S9X_ERROR, S9X_SNAPSHOT_INCONSISTENT, MOVIE_ERR_SNAPSHOT_INCONSISTENT); - break; default: case FILE_NOT_FOUND: - sprintf (String, SAVE_ERR_ROM_NOT_FOUND, ROMFilename); + sprintf (String, "ROM image \"%s\" for freeze file not found", + ROMFilename); S9xMessage (S9X_ERROR, S9X_ROM_NOT_FOUND, String); + WaitPrompt(String); break; } S9xCloseSnapshotFile (snapshot); @@ -1048,50 +835,20 @@ bool8 S9xUnfreezeGame (const char *filename) } #ifndef NGC - if(S9xMovieActive()) + if(!S9xMovieActive()) { - const char * name = S9xBasename (filename); - if(name && strlen(name) > 3) - name += strlen(name) - 3; - else - name = filename; - if(S9xMovieReadOnly()) - sprintf(String, MOVIE_INFO_REWIND " %s", name); - else - sprintf(String, MOVIE_INFO_RERECORD " %s", name); - S9xMessage (S9X_INFO, S9X_FREEZE_FILE_INFO, String); - GFX.InfoStringTimeout /= 4; - } - else - { - sprintf(String, SAVE_INFO_LOAD " %s", S9xBasename (filename)); + sprintf(String, "Loaded %s", S9xBasename (filename)); S9xMessage (S9X_INFO, S9X_FREEZE_FILE_INFO, String); } S9xCloseSnapshotFile (snapshot); + #endif return (TRUE); } - -#ifndef NGC - // failed; error message: - { - char name [PATH_MAX]; - strcpy(name, S9xBasename (filename)); - int len = strlen(name); - if(len > 3 && name[len-3] == 'z' && name[len-2] == 's') - name[len-3] = name[len-2] = '0'; - sprintf(String, SAVE_ERR_SAVE_NOT_FOUND, name); - S9xMessage (S9X_INFO, S9X_FREEZE_FILE_INFO, String); - } - return (FALSE); -#endif } -bool diagnostic_freezing = false; -//#define DIAGNOSTIC_FREEZING_SUPPORT - void S9xFreezeToStream (STREAM stream) { char buffer [1024]; @@ -1111,7 +868,7 @@ void S9xFreezeToStream (STREAM stream) SoundData.channels [i].previous16 [0] = (int16) SoundData.channels [i].previous [0]; SoundData.channels [i].previous16 [1] = (int16) SoundData.channels [i].previous [1]; } - sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, diagnostic_freezing ? 9999 : SNAPSHOT_VERSION); + sprintf (buffer, "%s:%04d\n", SNAPSHOT_MAGIC, SNAPSHOT_VERSION); WRITE_STREAM (buffer, strlen (buffer), stream); sprintf (buffer, "NAM:%06d:%s%c", (int)strlen (Memory.ROMFilename) + 1, Memory.ROMFilename, 0); @@ -1124,7 +881,7 @@ void S9xFreezeToStream (STREAM stream) // RAM and VRAM FreezeBlock (stream, "VRA", Memory.VRAM, 0x10000); FreezeBlock (stream, "RAM", Memory.RAM, 0x20000); - FreezeBlock (stream, "SRA", Memory.SRAM, 0x20000); + FreezeBlock (stream, "SRA", ::SRAM, 0x20000); FreezeBlock (stream, "FIL", Memory.FillRAM, 0x8000); if (Settings.APUEnabled) { @@ -1141,7 +898,7 @@ void S9xFreezeToStream (STREAM stream) struct SControlSnapshot ctl_snap; S9xControlPreSave(&ctl_snap); FreezeStruct (stream, "CTL", &ctl_snap, SnapControls, COUNT (SnapControls)); - + // Timings FreezeStruct (stream, "TIM", &Timings, SnapTimings, COUNT (SnapTimings)); @@ -1150,7 +907,7 @@ void S9xFreezeToStream (STREAM stream) { S9xSA1PackStatus (); FreezeStruct (stream, "SA1", &SA1, SnapSA1, COUNT (SnapSA1)); - FreezeStruct (stream, "SAR", &SA1Registers, SnapSA1Registers, + FreezeStruct (stream, "SAR", &SA1Registers, SnapSA1Registers, COUNT (SnapSA1Registers)); } @@ -1171,7 +928,7 @@ void S9xFreezeToStream (STREAM stream) } #ifndef NGC - if (S9xMovieActive ()) + if (S9xMovieActive ()) { uint8* movie_freeze_buf; uint32 movie_freeze_size; @@ -1187,56 +944,7 @@ void S9xFreezeToStream (STREAM stream) } } #endif - - // DSP1 chip - if(Settings.DSP1Master) - { - S9xPreSaveDSP1(); - FreezeStruct (stream, "DSP", &DSP1, SnapDSP1, COUNT (SnapDSP1)); - } - - if (Settings.C4) - { -#ifdef ZSNES_C4 - extern uint8 *C4Ram; - if (C4Ram) - FreezeBlock (stream, "CX4", C4Ram, 8192); -#else - FreezeBlock (stream, "CX4", Memory.C4RAM, 8192); -#endif - } - -#ifndef ZSNES_FX - if (Settings.SuperFX) - FreezeStruct (stream, "SFX", &GSU, SnapFX, COUNT (SnapFX)); -#endif - -#ifndef NGC - if(Settings.SnapshotScreenshots) - { - SnapshotScreenshotInfo *ssi = new SnapshotScreenshotInfo; - ssi->Width = min(IPPU.RenderedScreenWidth, MAX_SNES_WIDTH); - ssi->Height = min(IPPU.RenderedScreenHeight, MAX_SNES_HEIGHT); - ssi->Interlaced = GFX.DoInterlace; - - uint8 *rowpix=ssi->Data; - uint16 *screen=GFX.Screen; - for(int y=0; yHeight; y++, screen+=GFX.RealPPL){ - for(int x=0; xWidth; x++){ - uint32 r, g, b; - DECOMPOSE_PIXEL(screen[x], r, g, b); - *(rowpix++) = r; // save pixel as 15-bits-in-3-bytes, for simplicity - *(rowpix++) = g; - *(rowpix++) = b; - } - } - memset(rowpix, 0, sizeof(ssi->Data) + ssi->Data - rowpix); - - FreezeStruct (stream, "SHO", ssi, SnapScreenshot, COUNT (SnapScreenshot)); - delete ssi; - } -#endif - + S9xSetSoundMute (FALSE); #ifdef ZSNES_FX if (Settings.SuperFX) @@ -1244,41 +952,38 @@ void S9xFreezeToStream (STREAM stream) #endif } -bool unfreezing_from_stream = false; - int S9xUnfreezeFromStream (STREAM stream) { char buffer [_MAX_PATH + 1]; char rom_filename [_MAX_PATH + 1]; int result; - + int version; int len = strlen (SNAPSHOT_MAGIC) + 1 + 4 + 1; + #ifdef NGC GetMem(buffer, len); #else if (READ_STREAM (buffer, len, stream) != len) return (WRONG_FORMAT); -#endif - if (strncmp (buffer, SNAPSHOT_MAGIC, strlen (SNAPSHOT_MAGIC)) != 0) +#endif + if (strncmp (buffer, SNAPSHOT_MAGIC, strlen (SNAPSHOT_MAGIC)) != 0) return (WRONG_FORMAT); if ((version = atoi (&buffer [strlen (SNAPSHOT_MAGIC) + 1])) > SNAPSHOT_VERSION) return (WRONG_VERSION); - + if ((result = UnfreezeBlock (stream, "NAM", (uint8 *) rom_filename, _MAX_PATH)) != SUCCESS) return (result); - - unfreezing_from_stream = true; - -#ifndef NGC - if (strcasecmp (rom_filename, Memory.ROMFilename) != 0 && + +#ifndef NGC + if (strcasecmp (rom_filename, Memory.ROMFilename) != 0 && strcasecmp (S9xBasename (rom_filename), S9xBasename (Memory.ROMFilename)) != 0) { S9xMessage (S9X_WARNING, S9X_FREEZE_ROM_NAME, "Current loaded ROM image doesn't match that required by freeze-game file."); } #endif - + // ## begin load ## uint8* local_cpu = NULL; uint8* local_registers = NULL; @@ -1300,12 +1005,7 @@ int S9xUnfreezeFromStream (STREAM stream) uint8* local_control_data = NULL; uint8* local_timing_data = NULL; uint8* local_bsx_data = NULL; - uint8* local_dsp1 = NULL; - uint8* local_cx4_data = NULL; - uint8* local_superfx = NULL; - uint8* local_screenshot = NULL; - uint8* local_dummy[2] = {NULL,NULL}; - + do { if ((result = UnfreezeStructCopy (stream, "CPU", &local_cpu, SnapCPU, COUNT (SnapCPU), version)) != SUCCESS) @@ -1344,78 +1044,52 @@ int S9xUnfreezeFromStream (STREAM stream) if ((result = UnfreezeStructCopy (stream, "SAR", &local_sa1_registers, SnapSA1Registers, COUNT (SnapSA1Registers), version)) != SUCCESS) break; } - else if (Settings.SA1) - break; - + if ((result = UnfreezeStructCopy (stream, "SP7", &local_spc, SnapSPC7110, COUNT(SnapSPC7110), version)) != SUCCESS) - if (Settings.SPC7110) + { + if(Settings.SPC7110) break; - + } if ((result = UnfreezeStructCopy (stream, "RTC", &local_spc_rtc, SnapS7RTC, COUNT (SnapS7RTC), version)) != SUCCESS) - if (Settings.SPC7110RTC) + { + if(Settings.SPC7110RTC) break; + } - if ((result = UnfreezeStructCopy (stream, "BSX", &local_bsx_data, SnapBSX, COUNT (SnapBSX), version)) != SUCCESS) + if ((result = UnfreezeStructCopy (stream, "BSX", &local_bsx_data, SnapBSX, COUNT (SnapBSX), version)) != SUCCESS && version > 1) + { if (Settings.BS) break; + } -#ifndef NGC - // movie +#ifndef NGC + if (S9xMovieActive ()) { SnapshotMovieInfo mi; if ((result = UnfreezeStruct (stream, "MOV", &mi, SnapMovie, COUNT(SnapMovie), version)) != SUCCESS) { - if (S9xMovieActive ()) - { - result = NOT_A_MOVIE_SNAPSHOT; - break; - } - } else { - - if ((result = UnfreezeBlockCopy (stream, "MID", &local_movie_data, mi.MovieInputDataSize)) != SUCCESS) - { - if (S9xMovieActive ()) - { - result = NOT_A_MOVIE_SNAPSHOT; - break; - } - } - - if (S9xMovieActive ()) - { - result = S9xMovieUnfreeze(local_movie_data, mi.MovieInputDataSize); - if(result != SUCCESS) - break; - } - } - } -#endif - if ((result = UnfreezeStructCopy (stream, "DSP", &local_dsp1, SnapDSP1, COUNT(SnapDSP1), version)) != SUCCESS) - if(Settings.DSP1Master) + result = NOT_A_MOVIE_SNAPSHOT; break; + } - if ((result = UnfreezeBlockCopy (stream, "CX4", &local_cx4_data, 8192)) != SUCCESS) - if(Settings.C4) + if ((result = UnfreezeBlockCopy (stream, "MID", &local_movie_data, mi.MovieInputDataSize)) != SUCCESS) + { + result = NOT_A_MOVIE_SNAPSHOT; break; + } -#ifndef ZSNES_FX - if ((result = UnfreezeStructCopy (stream, "SFX", &local_superfx, SnapFX, COUNT(SnapFX), version)) != SUCCESS) -// if (Settings.SuperFX) -// break; // what if the savestate was made with ZSNES_FX on? - {} -#endif - - UnfreezeStructCopy (stream, "IPU", &local_dummy[0], SnapIPPU, COUNT(SnapIPPU), version); // obsolete - UnfreezeStructCopy (stream, "GFX", &local_dummy[1], SnapGFX, COUNT(SnapGFX), version); // obsolete - -#ifndef NGC - UnfreezeStructCopy (stream, "SHO", &local_screenshot, SnapScreenshot, COUNT(SnapScreenshot), version); + if (!S9xMovieUnfreeze(local_movie_data, mi.MovieInputDataSize)) + { + result = WRONG_MOVIE_SNAPSHOT; + break; + } + } #endif result=SUCCESS; } while(false); // ## end load ## - + if (result == SUCCESS) { uint32 old_flags = CPU.Flags; @@ -1429,7 +1103,7 @@ int S9xUnfreezeFromStream (STREAM stream) UnfreezeStructFromCopy (DMA, SnapDMA, COUNT (SnapDMA), local_dma, version); memcpy (Memory.VRAM, local_vram, 0x10000); memcpy (Memory.RAM, local_ram, 0x20000); - memcpy (Memory.SRAM, local_sram, 0x20000); + memcpy (::SRAM, local_sram, 0x20000); memcpy (Memory.FillRAM, local_fillram, 0x8000); if(local_apu) { @@ -1451,7 +1125,7 @@ int S9xUnfreezeFromStream (STREAM stream) { UnfreezeStructFromCopy (&rtc_f9, SnapS7RTC, COUNT (SnapS7RTC), local_spc_rtc, version); } - + struct SControlSnapshot ctl_snap; if(local_control_data) { UnfreezeStructFromCopy (&ctl_snap, SnapControls, COUNT (SnapControls), local_control_data, version); @@ -1467,16 +1141,7 @@ int S9xUnfreezeFromStream (STREAM stream) ctl_snap.justifier_select=0; } S9xControlPostLoad(&ctl_snap); - - if(local_movie_data) // restore last displayed pad_read status - { - extern bool8 pad_read, pad_read_last; - bool8 pad_read_temp = pad_read; - pad_read = pad_read_last; - //S9xUpdateFrameCounter (-1); - pad_read = pad_read_temp; - } - + if (local_timing_data) UnfreezeStructFromCopy (&Timings, SnapTimings, COUNT (SnapTimings), local_timing_data, version); else // Must be an old snes9x savestate @@ -1487,112 +1152,27 @@ int S9xUnfreezeFromStream (STREAM stream) if (local_bsx_data) UnfreezeStructFromCopy (&BSX, SnapBSX, COUNT (SnapBSX), local_bsx_data, version); - if(local_dsp1) - { - UnfreezeStructFromCopy (&DSP1, SnapDSP1, COUNT (SnapDSP1), local_dsp1, version); - S9xPostLoadDSP1(); - } - - if (local_cx4_data) - { -#ifdef ZSNES_C4 - extern uint8 *C4Ram; - if (C4Ram) - memcpy(C4Ram, local_cx4_data, 8192); -#else - memcpy(Memory.C4RAM, local_cx4_data, 8192); -#endif - } - -#ifndef ZSNES_FX - if(local_superfx) - { - UnfreezeStructFromCopy (&GSU, SnapFX, COUNT (SnapFX), local_superfx, version); - GSU.pfPlot = fx_apfPlotTable[GSU.vMode]; - GSU.pfRpix = fx_apfPlotTable[GSU.vMode + 5]; - } -#endif -#ifndef NGC - if(GFX.Screen) - if(local_screenshot) - { - SnapshotScreenshotInfo *ssi = new SnapshotScreenshotInfo; - UnfreezeStructFromCopy (ssi, SnapScreenshot, COUNT (SnapScreenshot), local_screenshot, version); - IPPU.RenderedScreenWidth = min(ssi->Width, IMAGE_WIDTH); - IPPU.RenderedScreenHeight = min(ssi->Height, IMAGE_HEIGHT); - const bool scaleDownX = IPPU.RenderedScreenWidth < ssi->Width; - const bool scaleDownY = IPPU.RenderedScreenHeight < ssi->Height && ssi->Height > SNES_HEIGHT_EXTENDED; - GFX.DoInterlace = Settings.SupportHiRes ? ssi->Interlaced : 0; - - uint8 *rowpix=ssi->Data; - uint16 *screen=GFX.Screen; - for(int y=0; y>1; - g = (g + *(rowpix++))>>1; - b = (b + *(rowpix++))>>1; - if(x+x+1 >= ssi->Width) - break; - } - screen[x] = BUILD_PIXEL(r, g, b); - } - if(scaleDownY) - { - rowpix += 3*ssi->Width; - if(y+y+1 >= ssi->Height) - break; - } - } - - // black out what we might have missed - for (uint32 y = IPPU.RenderedScreenHeight; y < (uint32)(IMAGE_HEIGHT); y++) - memset(GFX.Screen + y * GFX.RealPPL, 0, GFX.RealPPL*2); - delete ssi; - } - else - { - // couldn't load graphics, so black out the screen instead - for (uint32 y = 0; y < (uint32)(IMAGE_HEIGHT); y++) - memset(GFX.Screen + y * GFX.RealPPL, 0, GFX.RealPPL*2); - } -#endif Memory.FixROMSpeed (); CPU.Flags |= old_flags & (DEBUG_MODE_FLAG | TRACE_FLAG | SINGLE_STEP_FLAG | FRAME_ADVANCE_FLAG); IPPU.ColorsChanged = TRUE; IPPU.OBJChanged = TRUE; - CPU.InDMA = CPU.InHDMA = FALSE; - CPU.InDMAorHDMA = CPU.InWRAMDMAorHDMA = FALSE; - CPU.HDMARanInDMA = 0; + CPU.InDMA = CPU.InWRAM_DMA = FALSE; S9xFixColourBrightness (); - IPPU.RenderThisFrame = TRUE; // was FALSE, but for most games it's more useful to see that frame + IPPU.RenderThisFrame = FALSE; if (local_apu) { - if (APU.OldCycles != -99999999) - { - // Must be <= v1.5 savestate - printf("Older APU Cycles found.\n"); - APU.Cycles = (APU.OldCycles << SNES_APU_ACCURACY); - APU.OldCycles = -99999999; - } - S9xSetSoundMute (FALSE); IAPU.PC = IAPU.RAM + APURegisters.PC; S9xAPUUnpackStatus (); - IAPU.APUExecuting = TRUE; if (APUCheckDirectPage ()) IAPU.DirectPage = IAPU.RAM + 0x100; else IAPU.DirectPage = IAPU.RAM; Settings.APUEnabled = TRUE; + IAPU.APUExecuting = TRUE; } else { @@ -1611,7 +1191,7 @@ int S9xUnfreezeFromStream (STREAM stream) { S9xUpdateRTC(); } - + if (local_bsx_data) S9xFixBSXAfterSnapshotLoad(); @@ -1634,7 +1214,7 @@ int S9xUnfreezeFromStream (STREAM stream) Memory.FillRAM[0x4213]=Memory.FillRAM[0x4201]=0xFF; } if(local_apu) APU.Flags = Obsolete.SAPU_Flags; - + // FIXME: assuming the old savesate was made outside S9xMainLoop(). // In this case, V=0 and HDMA was already initialized. CPU.WhichEvent = HC_HDMA_INIT_EVENT; @@ -1653,13 +1233,13 @@ int S9xUnfreezeFromStream (STREAM stream) if (Settings.SuperFX) S9xSuperFXPostLoadState (); #endif - + S9xSRTCPostLoadState (); if (Settings.SDD1) S9xSDD1PostLoadState (); - - IAPU.NextAPUTimerPos = (CPU.Cycles << SNES_APU_ACCURACY); - IAPU.APUTimerCounter = 0; + + IAPU.NextAPUTimerPos = CPU.Cycles << SNES_APUTIMER_ACCURACY; + IAPU.APUTimerCounter = 0; } if (local_cpu) delete [] local_cpu; @@ -1682,14 +1262,6 @@ int S9xUnfreezeFromStream (STREAM stream) if (local_control_data) delete [] local_control_data; if (local_timing_data) delete [] local_timing_data; if (local_bsx_data) delete [] local_bsx_data; - if (local_dsp1) delete [] local_dsp1; - if (local_cx4_data) delete [] local_cx4_data; - if (local_superfx) delete [] local_superfx; - if (local_screenshot) delete [] local_screenshot; - for(int i=0; i<2; i++) - if (local_dummy[i]) delete [] local_dummy[i]; - - unfreezing_from_stream = false; return (result); } @@ -1702,10 +1274,8 @@ int FreezeSize (int size, int type) switch (type) { case uint16_ARRAY_V: - case uint16_INDIR_ARRAY_V: return (size * 2); case uint32_ARRAY_V: - case uint32_INDIR_ARRAY_V: return (size * 4); default: return (size); @@ -1722,26 +1292,8 @@ void FreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields, for (i = 0; i < num_fields; i++) { - if(fields[i].debuted_in > SNAPSHOT_VERSION) - { - fprintf(stderr, "%s[%p]: field has bad debuted_in value %d, > %d.", name, (void *)fields, fields[i].debuted_in, SNAPSHOT_VERSION); - continue; - } - if (SNAPSHOT_VERSION=fields[i].deleted_in) continue; - if (SNAPSHOT_VERSION> 8); - *ptr++ = (uint8) word; - break; - case 4: - dword = *((uint32 *) (addr)); - *ptr++ = (uint8) (dword >> 24); - *ptr++ = (uint8) (dword >> 16); - *ptr++ = (uint8) (dword >> 8); - *ptr++ = (uint8) dword; - break; - case 8: - qword = *((int64 *) (addr)); + switch (fields [i].type) + { + case INT_V: + switch (fields [i].size) + { + case 1: + *ptr++ = *((uint8 *) base + fields [i].offset); + break; + case 2: + word = *((uint16 *) ((uint8 *) base + fields [i].offset)); + *ptr++ = (uint8) (word >> 8); + *ptr++ = (uint8) word; + break; + case 4: + dword = *((uint32 *) ((uint8 *) base + fields [i].offset)); + *ptr++ = (uint8) (dword >> 24); + *ptr++ = (uint8) (dword >> 16); + *ptr++ = (uint8) (dword >> 8); + *ptr++ = (uint8) dword; + break; + case 8: + qword = *((int64 *) ((uint8 *) base + fields [i].offset)); *ptr++ = (uint8) (qword >> 56); *ptr++ = (uint8) (qword >> 48); *ptr++ = (uint8) (qword >> 40); @@ -1829,25 +1340,22 @@ void FreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields, break; } break; - case uint8_ARRAY_V: - case uint8_INDIR_ARRAY_V: - memmove (ptr, addr, fields[i].size); - ptr += fields[i].size; - break; - case uint16_ARRAY_V: - case uint16_INDIR_ARRAY_V: - for (j = 0; j < fields[i].size; j++) - { - word = *((uint16 *) (addr + j * 2)); - *ptr++ = (uint8) (word >> 8); - *ptr++ = (uint8) word; - } - break; - case uint32_ARRAY_V: - case uint32_INDIR_ARRAY_V: - for (j = 0; j < fields[i].size; j++) - { - dword = *((uint32 *) (addr + j * 4)); + case uint8_ARRAY_V: + memmove (ptr, (uint8 *) base + fields [i].offset, fields [i].size); + ptr += fields [i].size; + break; + case uint16_ARRAY_V: + for (j = 0; j < fields [i].size; j++) + { + word = *((uint16 *) ((uint8 *) base + fields [i].offset + j * 2)); + *ptr++ = (uint8) (word >> 8); + *ptr++ = (uint8) word; + } + break; + case uint32_ARRAY_V: + for (j = 0; j < fields [i].size; j++) + { + dword = *((uint32 *) ((uint8 *) base + fields [i].offset + j * 4)); *ptr++ = (uint8) (dword >> 24); *ptr++ = (uint8) (dword >> 16); *ptr++ = (uint8) (dword >> 8); @@ -1857,34 +1365,23 @@ void FreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields, } } //fprintf(stderr, "%s: Wrote %d bytes\n", name, ptr-block); -#ifndef NGC + +#ifndef NGC FreezeBlock (stream, name, block, len); #else NGCFreezeBlock(name, block, len); #endif - delete[] block; + + delete[] block; } void FreezeBlock (STREAM stream, char *name, uint8 *block, int size) { - char buffer [512]; - - if(size <= 999999) // check if it fits in 6 digits. (letting it go over and using strlen isn't safe) - sprintf (buffer, "%s:%06d:", name, size); - else - { - // to make it fit, pack it in the bytes instead of as digits - sprintf (buffer, "%s:------:", name); - buffer[6] = (unsigned char)((unsigned)size >> 24); - buffer[7] = (unsigned char)((unsigned)size >> 16); - buffer[8] = (unsigned char)((unsigned)size >> 8); - buffer[9] = (unsigned char)((unsigned)size >> 0); - } - buffer[11] = 0; - - WRITE_STREAM (buffer, 11, stream); + char buffer [512]; + sprintf (buffer, "%s:%06d:", name, size); + WRITE_STREAM (buffer, strlen (buffer), stream); WRITE_STREAM (block, size, stream); - + } #ifdef NGC @@ -1900,7 +1397,7 @@ void NGCFreezeStruct() // RAM and VRAM NGCFreezeBlock ("VRA", Memory.VRAM, 0x10000); NGCFreezeBlock ("RAM", Memory.RAM, 0x20000); - NGCFreezeBlock ("SRA", Memory.SRAM, 0x20000); + NGCFreezeBlock ("SRA", ::SRAM, 0x20000); NGCFreezeBlock ("FIL", Memory.FillRAM, 0x8000); if (Settings.APUEnabled) @@ -1945,30 +1442,7 @@ void NGCFreezeStruct() if (Settings.BS) { FreezeStruct (s,"BSX", &BSX, SnapBSX, COUNT (SnapBSX)); - } - - // DSP1 chip - if(Settings.DSP1Master) - { - S9xPreSaveDSP1(); - FreezeStruct (s, "DSP", &DSP1, SnapDSP1, COUNT (SnapDSP1)); - } - - if (Settings.C4) - { -#ifdef ZSNES_C4 - extern uint8 *C4Ram; - if (C4Ram) - NGCFreezeBlock ("CX4", C4Ram, 8192); -#else - NGCFreezeBlock ("CX4", Memory.C4RAM, 8192); -#endif - } - -#ifndef ZSNES_FX - if (Settings.SuperFX) - FreezeStruct (s, "SFX", &GSU, SnapFX, COUNT (SnapFX)); -#endif + } } #endif @@ -1978,35 +1452,19 @@ void NGCFreezeStruct() int UnfreezeBlock (STREAM stream, char *name, uint8 *block, int size) { #ifndef NGC - char buffer [20]; + char buffer [20], *e; int len = 0; int rem = 0; long rewind = FIND_STREAM(stream); - size_t l = READ_STREAM (buffer, 11, stream); - buffer[l] = 0; - if (l != 11 - || strncmp (buffer, name, 3) != 0 - || buffer[3] != ':') - { - err: - fprintf(stdout, "absent: %s(%d); next: '%.11s'\n", name, size, buffer); - REVERT_STREAM(stream, FIND_STREAM(stream)-l, 0); - return (WRONG_FORMAT); - } - - if(buffer[4] == '-') - { - len = (((unsigned char)buffer[6]) << 24) - | (((unsigned char)buffer[7]) << 16) - | (((unsigned char)buffer[8]) << 8) - | (((unsigned char)buffer[9]) << 0); - } - else + if (READ_STREAM (buffer, 11, stream) != 11 || + strncmp (buffer, name, 3) != 0 || buffer [3] != ':' || + buffer[10] != ':' || + (len = strtol (&buffer [4], &e, 10)) == 0 || e != buffer+10) { - len = atoi(buffer+4); + REVERT_STREAM(stream, rewind, 0); + return (WRONG_FORMAT); } - if(len <= 0) goto err; if (len > size) { @@ -2035,6 +1493,7 @@ int UnfreezeBlock (STREAM stream, char *name, uint8 *block, int size) #else return NGCUnFreezeBlock(name, block, size); #endif + } int UnfreezeBlockCopy (STREAM stream, char *name, uint8** block, int size) @@ -2077,8 +1536,8 @@ int UnfreezeStructCopy (STREAM stream, char *name, uint8** block, FreezeData *fi for (i = 0; i < num_fields; i++) { - if (version>=fields[i].debuted_in && version=fields [i].debuted_in && version=fields[i].deleted_in) continue; + if (version=fields[i].deleted_in) continue; base = (SNAPSHOT_VERSION>=fields[i].deleted_in)?((void *)&Obsolete):sbase; - - uint8 *addr = (uint8 *) base + fields[i].offset; - - // determine real address of indirect-type fields - // (where the structure contains a pointer to an array rather than the array itself) - if (fields[i].type == uint8_INDIR_ARRAY_V || fields[i].type == uint16_INDIR_ARRAY_V || fields[i].type == uint32_INDIR_ARRAY_V) - addr = (uint8 *)(*((pint*)addr)); - - switch (fields[i].type) + switch (fields [i].type) { case INT_V: - case POINTER_V: - switch (fields[i].size) + switch (fields [i].size) { case 1: if(fields[i].offset<0){ ptr++; break; } - *(addr) = *ptr++; + *((uint8 *) base + fields [i].offset) = *ptr++; break; case 2: if(fields[i].offset<0){ ptr+=2; break; } word = *ptr++ << 8; word |= *ptr++; - *((uint16 *) (addr)) = word; + *((uint16 *) ((uint8 *) base + fields [i].offset)) = word; break; case 4: if(fields[i].offset<0){ ptr+=4; break; } @@ -2130,7 +1580,7 @@ void UnfreezeStructFromCopy (void *sbase, FreezeData *fields, int num_fields, ui dword |= *ptr++ << 16; dword |= *ptr++ << 8; dword |= *ptr++; - *((uint32 *) (addr)) = dword; + *((uint32 *) ((uint8 *) base + fields [i].offset)) = dword; break; case 8: if(fields[i].offset<0){ ptr+=8; break; } @@ -2142,51 +1592,37 @@ void UnfreezeStructFromCopy (void *sbase, FreezeData *fields, int num_fields, ui qword |= (int64) *ptr++ << 16; qword |= (int64) *ptr++ << 8; qword |= (int64) *ptr++; - *((int64 *) (addr)) = qword; + *((int64 *) ((uint8 *) base + fields [i].offset)) = qword; break; - default: - assert(0); - break; } break; case uint8_ARRAY_V: - case uint8_INDIR_ARRAY_V: if(fields[i].offset>=0) - memmove (addr, ptr, fields[i].size); - ptr += fields[i].size; + memmove ((uint8 *) base + fields [i].offset, ptr, fields [i].size); + ptr += fields [i].size; break; case uint16_ARRAY_V: - case uint16_INDIR_ARRAY_V: if(fields[i].offset<0){ ptr+=fields[i].size*2; break; } - for (j = 0; j < fields[i].size; j++) + for (j = 0; j < fields [i].size; j++) { word = *ptr++ << 8; word |= *ptr++; - *((uint16 *) (addr + j * 2)) = word; + *((uint16 *) ((uint8 *) base + fields [i].offset + j * 2)) = word; } break; case uint32_ARRAY_V: - case uint32_INDIR_ARRAY_V: if(fields[i].offset<0){ ptr+=fields[i].size*4; break; } - for (j = 0; j < fields[i].size; j++) + for (j = 0; j < fields [i].size; j++) { dword = *ptr++ << 24; dword |= *ptr++ << 16; dword |= *ptr++ << 8; dword |= *ptr++; - *((uint32 *) (addr + j * 4)) = dword; + *((uint32 *) ((uint8 *) base + fields [i].offset + j * 4)) = dword; } break; } - - // convert pointer-type saves from relative to absolute pointers - if(fields[i].type == POINTER_V) - { - int relativeAddr = (int)*((pint*)((uint8 *) base + fields[i].offset)); - uint8* relativeTo = (uint8*)*((pint*)((uint8 *) base + fields[i].offset2)); - *((pint *) (addr)) = (pint)(relativeTo + relativeAddr); - } - } + } //fprintf(stderr, "%p: Unfroze %d bytes\n", fields, ptr-block); } @@ -2205,14 +1641,14 @@ bool8 S9xSPCDump (const char *filename) static uint8 version = { 0x1e }; - + FILE *fs; - + + S9xSetSoundMute (TRUE); + if (!(fs = fopen (filename, "wb"))) return (FALSE); - - S9xSetSoundMute (TRUE); - + // The SPC file format: // 0000: header: 'SNES-SPC700 Sound File Data v0.30',26,26,26 // 0036: version: $1e @@ -2235,7 +1671,7 @@ bool8 S9xSPCDump (const char *filename) // 0000: Reserved: 36 bytes // 0256: SPC700 RAM: 64K // ----: DSP Registers: 256 bytes - + if (fwrite (header, sizeof (header), 1, fs) != 1 || fputc (version, fs) == EOF || fseek (fs, 37, SEEK_SET) == EOF || @@ -2263,222 +1699,222 @@ bool8 S9xUnfreezeZSNES (const char *filename) { FILE *fs; uint8 t [4000]; - + if (!(fs = fopen (filename, "rb"))) return (FALSE); - + if (fread (t, 64, 1, fs) == 1 && strncmp ((char *) t, "ZSNES Save State File V0.6", 26) == 0) { S9xReset (); S9xSetSoundMute (TRUE); - + // 28 Curr cycle - CPU.V_Counter = READ_WORD (&t[29]); + CPU.V_Counter = READ_WORD (&t [29]); // 33 instrset - Settings.APUEnabled = t[36]; - + Settings.APUEnabled = t [36]; + // 34 bcycpl cycles per scanline // 35 cycphb cyclers per hblank - - Registers.A.W = READ_WORD (&t[41]); - Registers.DB = t[43]; - Registers.PB = t[44]; - Registers.S.W = READ_WORD (&t[45]); - Registers.D.W = READ_WORD (&t[47]); - Registers.X.W = READ_WORD (&t[49]); - Registers.Y.W = READ_WORD (&t[51]); - Registers.P.W = READ_WORD (&t[53]); - Registers.PCw = READ_WORD (&t[55]); - + + Registers.A.W = READ_WORD (&t [41]); + Registers.DB = t [43]; + Registers.PB = t [44]; + Registers.S.W = READ_WORD (&t [45]); + Registers.D.W = READ_WORD (&t [47]); + Registers.X.W = READ_WORD (&t [49]); + Registers.Y.W = READ_WORD (&t [51]); + Registers.P.W = READ_WORD (&t [53]); + Registers.PCw = READ_WORD (&t [55]); + fread (t, 1, 8, fs); fread (t, 1, 3019, fs); - S9xSetCPU (t[2], 0x4200); - Memory.FillRAM [0x4210] = t[3]; - PPU.IRQVBeamPos = READ_WORD (&t[4]); - PPU.IRQHBeamPos = READ_WORD (&t[2527]); - PPU.Brightness = t[6]; - PPU.ForcedBlanking = t[8] >> 7; - + S9xSetCPU (t [2], 0x4200); + Memory.FillRAM [0x4210] = t [3]; + PPU.IRQVBeamPos = READ_WORD (&t [4]); + PPU.IRQHBeamPos = READ_WORD (&t [2527]); + PPU.Brightness = t [6]; + PPU.ForcedBlanking = t [8] >> 7; + int i; for (i = 0; i < 544; i++) - S9xSetPPU (t[0464 + i], 0x2104); - - PPU.OBJNameBase = READ_WORD (&t[9]); - PPU.OBJNameSelect = READ_WORD (&t[13]) - PPU.OBJNameBase; - switch (t[18]) + S9xSetPPU (t [0464 + i], 0x2104); + + PPU.OBJNameBase = READ_WORD (&t [9]); + PPU.OBJNameSelect = READ_WORD (&t [13]) - PPU.OBJNameBase; + switch (t [18]) { case 4: - if (t[17] == 1) + if (t [17] == 1) PPU.OBJSizeSelect = 0; else PPU.OBJSizeSelect = 6; break; case 16: - if (t[17] == 1) + if (t [17] == 1) PPU.OBJSizeSelect = 1; else PPU.OBJSizeSelect = 3; break; default: case 64: - if (t[17] == 1) + if (t [17] == 1) PPU.OBJSizeSelect = 2; else - if (t[17] == 4) + if (t [17] == 4) PPU.OBJSizeSelect = 4; else PPU.OBJSizeSelect = 5; break; } - PPU.OAMAddr = READ_WORD (&t[25]); - PPU.SavedOAMAddr = READ_WORD (&t[27]); - PPU.FirstSprite = t[29]; - PPU.BGMode = t[30]; - PPU.BG3Priority = t[31]; - PPU.BG[0].BGSize = (t[32] >> 0) & 1; - PPU.BG[1].BGSize = (t[32] >> 1) & 1; - PPU.BG[2].BGSize = (t[32] >> 2) & 1; - PPU.BG[3].BGSize = (t[32] >> 3) & 1; - PPU.Mosaic = t[33] + 1; - PPU.BGMosaic [0] = (t[34] & 1) != 0; - PPU.BGMosaic [1] = (t[34] & 2) != 0; - PPU.BGMosaic [2] = (t[34] & 4) != 0; - PPU.BGMosaic [3] = (t[34] & 8) != 0; - PPU.BG [0].SCBase = READ_WORD (&t[35]) >> 1; - PPU.BG [1].SCBase = READ_WORD (&t[37]) >> 1; - PPU.BG [2].SCBase = READ_WORD (&t[39]) >> 1; - PPU.BG [3].SCBase = READ_WORD (&t[41]) >> 1; - PPU.BG [0].SCSize = t[67]; - PPU.BG [1].SCSize = t[68]; - PPU.BG [2].SCSize = t[69]; - PPU.BG [3].SCSize = t[70]; - PPU.BG[0].NameBase = READ_WORD (&t[71]) >> 1; - PPU.BG[1].NameBase = READ_WORD (&t[73]) >> 1; - PPU.BG[2].NameBase = READ_WORD (&t[75]) >> 1; - PPU.BG[3].NameBase = READ_WORD (&t[77]) >> 1; - PPU.BG[0].HOffset = READ_WORD (&t[79]); - PPU.BG[1].HOffset = READ_WORD (&t[81]); - PPU.BG[2].HOffset = READ_WORD (&t[83]); - PPU.BG[3].HOffset = READ_WORD (&t[85]); - PPU.BG[0].VOffset = READ_WORD (&t[89]); - PPU.BG[1].VOffset = READ_WORD (&t[91]); - PPU.BG[2].VOffset = READ_WORD (&t[93]); - PPU.BG[3].VOffset = READ_WORD (&t[95]); - PPU.VMA.Increment = READ_WORD (&t[97]) >> 1; - PPU.VMA.High = t[99]; + PPU.OAMAddr = READ_WORD (&t [25]); + PPU.SavedOAMAddr = READ_WORD (&t [27]); + PPU.FirstSprite = t [29]; + PPU.BGMode = t [30]; + PPU.BG3Priority = t [31]; + PPU.BG[0].BGSize = (t [32] >> 0) & 1; + PPU.BG[1].BGSize = (t [32] >> 1) & 1; + PPU.BG[2].BGSize = (t [32] >> 2) & 1; + PPU.BG[3].BGSize = (t [32] >> 3) & 1; + PPU.Mosaic = t [33] + 1; + PPU.BGMosaic [0] = (t [34] & 1) != 0; + PPU.BGMosaic [1] = (t [34] & 2) != 0; + PPU.BGMosaic [2] = (t [34] & 4) != 0; + PPU.BGMosaic [3] = (t [34] & 8) != 0; + PPU.BG [0].SCBase = READ_WORD (&t [35]) >> 1; + PPU.BG [1].SCBase = READ_WORD (&t [37]) >> 1; + PPU.BG [2].SCBase = READ_WORD (&t [39]) >> 1; + PPU.BG [3].SCBase = READ_WORD (&t [41]) >> 1; + PPU.BG [0].SCSize = t [67]; + PPU.BG [1].SCSize = t [68]; + PPU.BG [2].SCSize = t [69]; + PPU.BG [3].SCSize = t [70]; + PPU.BG[0].NameBase = READ_WORD (&t [71]) >> 1; + PPU.BG[1].NameBase = READ_WORD (&t [73]) >> 1; + PPU.BG[2].NameBase = READ_WORD (&t [75]) >> 1; + PPU.BG[3].NameBase = READ_WORD (&t [77]) >> 1; + PPU.BG[0].HOffset = READ_WORD (&t [79]); + PPU.BG[1].HOffset = READ_WORD (&t [81]); + PPU.BG[2].HOffset = READ_WORD (&t [83]); + PPU.BG[3].HOffset = READ_WORD (&t [85]); + PPU.BG[0].VOffset = READ_WORD (&t [89]); + PPU.BG[1].VOffset = READ_WORD (&t [91]); + PPU.BG[2].VOffset = READ_WORD (&t [93]); + PPU.BG[3].VOffset = READ_WORD (&t [95]); + PPU.VMA.Increment = READ_WORD (&t [97]) >> 1; + PPU.VMA.High = t [99]; #ifndef CORRECT_VRAM_READS - IPPU.FirstVRAMRead = t[100]; + IPPU.FirstVRAMRead = t [100]; #endif - S9xSetPPU (t[2512], 0x2115); - PPU.VMA.Address = READ_DWORD (&t[101]); + S9xSetPPU (t [2512], 0x2115); + PPU.VMA.Address = READ_DWORD (&t [101]); for (i = 0; i < 512; i++) - S9xSetPPU (t[1488 + i], 0x2122); - - PPU.CGADD = (uint8) READ_WORD (&t[105]); - Memory.FillRAM [0x212c] = t[108]; - Memory.FillRAM [0x212d] = t[109]; - PPU.ScreenHeight = READ_WORD (&t[111]); - Memory.FillRAM [0x2133] = t[2526]; - Memory.FillRAM [0x4202] = t[113]; - Memory.FillRAM [0x4204] = t[114]; - Memory.FillRAM [0x4205] = t[115]; - Memory.FillRAM [0x4214] = t[116]; - Memory.FillRAM [0x4215] = t[117]; - Memory.FillRAM [0x4216] = t[118]; - Memory.FillRAM [0x4217] = t[119]; - PPU.VBeamPosLatched = READ_WORD (&t[122]); - PPU.HBeamPosLatched = READ_WORD (&t[120]); - PPU.Window1Left = t[127]; - PPU.Window1Right = t[128]; - PPU.Window2Left = t[129]; - PPU.Window2Right = t[130]; - S9xSetPPU (t[131] | (t[132] << 4), 0x2123); - S9xSetPPU (t[133] | (t[134] << 4), 0x2124); - S9xSetPPU (t[135] | (t[136] << 4), 0x2125); - S9xSetPPU (t[137], 0x212a); - S9xSetPPU (t[138], 0x212b); - S9xSetPPU (t[139], 0x212e); - S9xSetPPU (t[140], 0x212f); - S9xSetPPU (t[141], 0x211a); - PPU.MatrixA = READ_WORD (&t[142]); - PPU.MatrixB = READ_WORD (&t[144]); - PPU.MatrixC = READ_WORD (&t[146]); - PPU.MatrixD = READ_WORD (&t[148]); - PPU.CentreX = READ_WORD (&t[150]); - PPU.CentreY = READ_WORD (&t[152]); + S9xSetPPU (t [1488 + i], 0x2122); + + PPU.CGADD = (uint8) READ_WORD (&t [105]); + Memory.FillRAM [0x212c] = t [108]; + Memory.FillRAM [0x212d] = t [109]; + PPU.ScreenHeight = READ_WORD (&t [111]); + Memory.FillRAM [0x2133] = t [2526]; + Memory.FillRAM [0x4202] = t [113]; + Memory.FillRAM [0x4204] = t [114]; + Memory.FillRAM [0x4205] = t [115]; + Memory.FillRAM [0x4214] = t [116]; + Memory.FillRAM [0x4215] = t [117]; + Memory.FillRAM [0x4216] = t [118]; + Memory.FillRAM [0x4217] = t [119]; + PPU.VBeamPosLatched = READ_WORD (&t [122]); + PPU.HBeamPosLatched = READ_WORD (&t [120]); + PPU.Window1Left = t [127]; + PPU.Window1Right = t [128]; + PPU.Window2Left = t [129]; + PPU.Window2Right = t [130]; + S9xSetPPU (t [131] | (t [132] << 4), 0x2123); + S9xSetPPU (t [133] | (t [134] << 4), 0x2124); + S9xSetPPU (t [135] | (t [136] << 4), 0x2125); + S9xSetPPU (t [137], 0x212a); + S9xSetPPU (t [138], 0x212b); + S9xSetPPU (t [139], 0x212e); + S9xSetPPU (t [140], 0x212f); + S9xSetPPU (t [141], 0x211a); + PPU.MatrixA = READ_WORD (&t [142]); + PPU.MatrixB = READ_WORD (&t [144]); + PPU.MatrixC = READ_WORD (&t [146]); + PPU.MatrixD = READ_WORD (&t [148]); + PPU.CentreX = READ_WORD (&t [150]); + PPU.CentreY = READ_WORD (&t [152]); PPU.M7HOFS = PPU.BG[0].HOffset; PPU.M7VOFS = PPU.BG[0].VOffset; // JoyAPos t[154] // JoyBPos t[155] - Memory.FillRAM [0x2134] = t[156]; // Matrix mult - Memory.FillRAM [0x2135] = t[157]; // Matrix mult - Memory.FillRAM [0x2136] = t[158]; // Matrix mult - PPU.WRAM = READ_DWORD (&t[161]); - + Memory.FillRAM [0x2134] = t [156]; // Matrix mult + Memory.FillRAM [0x2135] = t [157]; // Matrix mult + Memory.FillRAM [0x2136] = t [158]; // Matrix mult + PPU.WRAM = READ_DWORD (&t [161]); + for (i = 0; i < 128; i++) - S9xSetCPU (t[165 + i], 0x4300 + i); - - if (t[294]) + S9xSetCPU (t [165 + i], 0x4300 + i); + + if (t [294]) CPU.IRQActive |= PPU_V_BEAM_IRQ_SOURCE | PPU_H_BEAM_IRQ_SOURCE; - - S9xSetCPU (t[296], 0x420c); + + S9xSetCPU (t [296], 0x420c); // hdmadata t[297] + 8 * 19 - PPU.FixedColourRed = t[450]; - PPU.FixedColourGreen = t[451]; - PPU.FixedColourBlue = t[452]; - S9xSetPPU (t[454], 0x2130); - S9xSetPPU (t[455], 0x2131); + PPU.FixedColourRed = t [450]; + PPU.FixedColourGreen = t [451]; + PPU.FixedColourBlue = t [452]; + S9xSetPPU (t [454], 0x2130); + S9xSetPPU (t [455], 0x2131); // vraminctype ... - + fread (Memory.RAM, 1, 128 * 1024, fs); fread (Memory.VRAM, 1, 64 * 1024, fs); - + if (Settings.APUEnabled) { // SNES SPC700 RAM (64K) fread (IAPU.RAM, 1, 64 * 1024, fs); - + // Junk 16 bytes fread (t, 1, 16, fs); - + // SNES SPC700 state and internal ZSNES SPC700 emulation state fread (t, 1, 304, fs); - - APURegisters.PC = READ_DWORD (&t[0]); - APURegisters.YA.B.A = t[4]; - APURegisters.X = t[8]; - APURegisters.YA.B.Y = t[12]; - APURegisters.P = t[16]; - APURegisters.S = t[24]; - - APU.Cycles = READ_DWORD (&t[32]) << SNES_APU_ACCURACY; + + APURegisters.PC = READ_DWORD (&t [0]); + APURegisters.YA.B.A = t [4]; + APURegisters.X = t [8]; + APURegisters.YA.B.Y = t [12]; + APURegisters.P = t [16]; + APURegisters.S = t [24]; + + APU.Cycles = READ_DWORD (&t [32]); APU.ShowROM = (IAPU.RAM [0xf1] & 0x80) != 0; - APU.OutPorts [0] = t[36]; - APU.OutPorts [1] = t[37]; - APU.OutPorts [2] = t[38]; - APU.OutPorts [3] = t[39]; - - APU.TimerEnabled [0] = (t[40] & 1) != 0; - APU.TimerEnabled [1] = (t[40] & 2) != 0; - APU.TimerEnabled [2] = (t[40] & 4) != 0; - S9xSetAPUTimer (0xfa, t[41]); - S9xSetAPUTimer (0xfb, t[42]); - S9xSetAPUTimer (0xfc, t[43]); - APU.Timer [0] = t[44]; - APU.Timer [1] = t[45]; - APU.Timer [2] = t[46]; - - memmove (APU.ExtraRAM, &t[48], 64); - + APU.OutPorts [0] = t [36]; + APU.OutPorts [1] = t [37]; + APU.OutPorts [2] = t [38]; + APU.OutPorts [3] = t [39]; + + APU.TimerEnabled [0] = (t [40] & 1) != 0; + APU.TimerEnabled [1] = (t [40] & 2) != 0; + APU.TimerEnabled [2] = (t [40] & 4) != 0; + S9xSetAPUTimer (0xfa, t [41]); + S9xSetAPUTimer (0xfb, t [42]); + S9xSetAPUTimer (0xfc, t [43]); + APU.Timer [0] = t [44]; + APU.Timer [1] = t [45]; + APU.Timer [2] = t [46]; + + memmove (APU.ExtraRAM, &t [48], 64); + // Internal ZSNES sound DSP state fread (t, 1, 1068, fs); - + // SNES sound DSP register values fread (t, 1, 256, fs); - + uint8 saved = IAPU.RAM [0xf2]; - + for (i = 0; i < 128; i++) { switch (i) @@ -2487,17 +1923,17 @@ bool8 S9xUnfreezeZSNES (const char *filename) case APU_KOFF: break; case APU_FLG: - t[i] &= ~APU_SOFT_RESET; + t [i] &= ~APU_SOFT_RESET; default: IAPU.RAM [0xf2] = i; - S9xSetAPUDSP (t[i]); + S9xSetAPUDSP (t [i]); break; } } IAPU.RAM [0xf2] = APU_KON; - S9xSetAPUDSP (t[APU_KON]); + S9xSetAPUDSP (t [APU_KON]); IAPU.RAM [0xf2] = saved; - + S9xSetSoundMute (FALSE); IAPU.PC = IAPU.RAM + APURegisters.PC; S9xAPUUnpackStatus (); @@ -2514,40 +1950,40 @@ bool8 S9xUnfreezeZSNES (const char *filename) IAPU.APUExecuting = FALSE; S9xSetSoundMute (TRUE); } - + if (Settings.SuperFX) { - fread (Memory.SRAM, 1, 64 * 1024, fs); + fread (::SRAM, 1, 64 * 1024, fs); fseek (fs, 64 * 1024, SEEK_CUR); fread (Memory.FillRAM + 0x7000, 1, 692, fs); } if (Settings.SA1) { fread (t, 1, 2741, fs); - S9xSetSA1 (t[4], 0x2200); // Control - S9xSetSA1 (t[12], 0x2203); // ResetV low - S9xSetSA1 (t[13], 0x2204); // ResetV hi - S9xSetSA1 (t[14], 0x2205); // NMI low - S9xSetSA1 (t[15], 0x2206); // NMI hi - S9xSetSA1 (t[16], 0x2207); // IRQ low - S9xSetSA1 (t[17], 0x2208); // IRQ hi - S9xSetSA1 (((READ_DWORD (&t[28]) - (4096*1024-0x6000))) >> 13, 0x2224); - S9xSetSA1 (t[36], 0x2201); - S9xSetSA1 (t[41], 0x2209); - - SA1Registers.A.W = READ_DWORD (&t[592]); - SA1Registers.X.W = READ_DWORD (&t[596]); - SA1Registers.Y.W = READ_DWORD (&t[600]); - SA1Registers.D.W = READ_DWORD (&t[604]); - SA1Registers.DB = t[608]; - SA1Registers.PB = t[612]; - SA1Registers.S.W = READ_DWORD (&t[616]); - SA1Registers.PCw = READ_DWORD (&t[636]); - SA1Registers.P.W = t[620] | (t[624] << 8); - + S9xSetSA1 (t [4], 0x2200); // Control + S9xSetSA1 (t [12], 0x2203); // ResetV low + S9xSetSA1 (t [13], 0x2204); // ResetV hi + S9xSetSA1 (t [14], 0x2205); // NMI low + S9xSetSA1 (t [15], 0x2206); // NMI hi + S9xSetSA1 (t [16], 0x2207); // IRQ low + S9xSetSA1 (t [17], 0x2208); // IRQ hi + S9xSetSA1 (((READ_DWORD (&t [28]) - (4096*1024-0x6000))) >> 13, 0x2224); + S9xSetSA1 (t [36], 0x2201); + S9xSetSA1 (t [41], 0x2209); + + SA1Registers.A.W = READ_DWORD (&t [592]); + SA1Registers.X.W = READ_DWORD (&t [596]); + SA1Registers.Y.W = READ_DWORD (&t [600]); + SA1Registers.D.W = READ_DWORD (&t [604]); + SA1Registers.DB = t [608]; + SA1Registers.PB = t [612]; + SA1Registers.S.W = READ_DWORD (&t [616]); + SA1Registers.PCw = READ_DWORD (&t [636]); + SA1Registers.P.W = t [620] | (t [624] << 8); + memmove (&Memory.FillRAM [0x3000], t + 692, 2 * 1024); - - fread (Memory.SRAM, 1, 64 * 1024, fs); + + fread (::SRAM, 1, 64 * 1024, fs); fseek (fs, 64 * 1024, SEEK_CUR); S9xFixSA1AfterSnapshotLoad (); } @@ -2555,10 +1991,10 @@ bool8 S9xUnfreezeZSNES (const char *filename) { uint32 temp; fread(&s7r.bank50, 1,0x10000, fs); - + //NEWSYM SPCMultA, dd 0 4820-23 fread(&temp, 1, 4, fs); - + s7r.reg4820=temp&(0x0FF); s7r.reg4821=(temp>>8)&(0x0FF); s7r.reg4822=(temp>>16)&(0x0FF); @@ -2577,12 +2013,12 @@ bool8 S9xUnfreezeZSNES (const char *filename) //NEWSYM SPCMulRes, dd 0 4828-B fread(&temp, 1, 4, fs); - + s7r.reg4828=temp&(0x0FF); s7r.reg4829=(temp>>8)&(0x0FF); s7r.reg482A=(temp>>16)&(0x0FF); s7r.reg482B=(temp>>24)&(0x0FF); - + //NEWSYM SPCDivRes, dd 0 482C-D fread(&temp, 1,4,fs); s7r.reg482C=temp&(0x0FF); @@ -2590,14 +2026,14 @@ bool8 S9xUnfreezeZSNES (const char *filename) //NEWSYM SPC7110BankA, dd 020100h 4831-3 fread(&temp, 1, 4, fs); - + s7r.reg4831=temp&(0x0FF); s7r.reg4832=(temp>>8)&(0x0FF); s7r.reg4833=(temp>>16)&(0x0FF); - + //NEWSYM SPC7110RTCStat, dd 0 4840,init,command, index fread(&temp, 1, 4, fs); - + s7r.reg4840=temp&(0x0FF); //NEWSYM SPC7110RTC, db 00,00,00,00,00,00,01,00,01,00,00,00,00,00,0Fh,00 @@ -2641,7 +2077,7 @@ fread(&temp, 1, 4, fs); //NEWSYM SPCROMPtr, dd 0 4811-4813 fread(&temp, 1, 4, fs); - + s7r.reg4811=temp&(0x0FF); s7r.reg4812=(temp>>8)&(0x0FF); s7r.reg4813=(temp>>16)&(0x0FF); @@ -2657,13 +2093,13 @@ fread(&temp, 1, 4, fs); s7r.reg4817=(temp>>8)&(0x0FF); //NEWSYM SPCROMCom, dd 0 4818 fread(&temp, 1, 4, fs); - + s7r.reg4818=temp&(0x0FF); //NEWSYM SPCCompPtr, dd 0 4801-4804 (+b50i) if"manual" fread(&temp, 1, 4, fs); //do table check - + s7r.reg4801=temp&(0x0FF); s7r.reg4802=(temp>>8)&(0x0FF); s7r.reg4803=(temp>>16)&(0x0FF); @@ -2678,26 +2114,26 @@ fread(&temp, 1, 4, fs); s7r.reg480A=(temp>>8)&(0x0FF); //NEWSYM SPCCompCommand, dd 0 480B fread(&temp, 1, 4, fs); - + s7r.reg480B=temp&(0x0FF); //NEWSYM SPCCheckFix, dd 0 written(if 1, then set writtne to max value!) fread(&temp, 1, 4, fs); (temp&(0x0FF))?s7r.written=0x1F:s7r.written=0x00; //NEWSYM SPCSignedVal, dd 0 482E fread(&temp, 1, 4, fs); - + s7r.reg482E=temp&(0x0FF); - + } fclose (fs); - + Memory.FixROMSpeed (); IPPU.ColorsChanged = TRUE; IPPU.OBJChanged = TRUE; - CPU.InDMAorHDMA = CPU.InWRAMDMAorHDMA = FALSE; + CPU.InDMA = CPU.InWRAM_DMA = FALSE; S9xFixColourBrightness (); IPPU.RenderThisFrame = FALSE; - + S9xFixSoundAfterSnapshotLoad (1); ICPU.ShiftedPB = Registers.PB << 16; ICPU.ShiftedDB = Registers.DB << 16; diff --git a/source/snes9x/snapshot.h b/source/snes9x/snapshot.h index 9bea7a06..b6eb433e 100644 --- a/source/snes9x/snapshot.h +++ b/source/snes9x/snapshot.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _SNAPSHOT_H_ #define _SNAPSHOT_H_ @@ -167,7 +148,7 @@ #include "snes9x.h" #define SNAPSHOT_MAGIC "#!snes9x" -#define SNAPSHOT_VERSION 4 +#define SNAPSHOT_VERSION 2 #define SUCCESS 1 #define WRONG_FORMAT (-1) @@ -175,7 +156,6 @@ #define FILE_NOT_FOUND (-3) #define WRONG_MOVIE_SNAPSHOT (-4) #define NOT_A_MOVIE_SNAPSHOT (-5) -#define SNAPSHOT_INCONSISTENT (-6) START_EXTERN_C void S9xResetSaveTimer(bool8 dontsave); diff --git a/source/snes9x/snes9x.cpp b/source/snes9x/snes9x.cpp index 440d75d4..f8f01557 100644 --- a/source/snes9x/snes9x.cpp +++ b/source/snes9x/snes9x.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include #include @@ -179,9 +160,7 @@ #ifndef NGC #include "netplay.h" -#include "logger.h" #endif -#include "gfx.h" #ifdef DEBUGGER extern FILE *trace; @@ -203,10 +182,11 @@ void S9xUsage () S9xMessage(S9X_INFO, S9X_USAGE, "-ratio or -ra Ratio of 65c816 to SPC700 instructions (ignored)"); #endif S9xMessage(S9X_INFO, S9X_USAGE, "-soundquality, -sq, or -r Set sound playback quality"); -#ifndef __MSDOS__ +#ifdef __sgi +/* BS: changed the sample rate values to match the IRIX options */ S9xMessage (S9X_INFO, S9X_USAGE, "\ 0 - off, 1 - 8192, 2 - 11025, 3 - 16000,\n\ - 4 - 22050, 5 - 32000 (default), 6 - 44100,\n\ + 4 - 22050 (default), 5 - 32000, 6 - 44100,\n\ 7 - 48000"); #else S9xMessage (S9X_INFO, S9X_USAGE, "\ @@ -222,7 +202,8 @@ void S9xUsage () #ifdef USE_THREADS S9xMessage(S9X_INFO, S9X_USAGE, "-threadsound or -ts Use a separate thread to output sound"); #endif - S9xMessage(S9X_INFO, S9X_USAGE, "-nois Turn off interpolated sound"); + S9xMessage(S9X_INFO, S9X_USAGE, "-interpolatedsound or -is <0-3> Select sound interpolation method\n\ + 0=none, 1=linear, 2=cubic, 3=gaussian"); S9xMessage(S9X_INFO, S9X_USAGE, "-echo or -e Enable DSP echo effects at startup"); S9xMessage(S9X_INFO, S9X_USAGE, "-noecho or -ne Disable DSP echo effects at startup"); S9xMessage(S9X_INFO, S9X_USAGE, "-envx or -ex Enable volume envelope height reading"); @@ -230,7 +211,7 @@ void S9xUsage () S9xMessage(S9X_INFO, S9X_USAGE, "-nomastervolume or -nmv Disable master volume setting"); S9xMessage(S9X_INFO, S9X_USAGE, "-fix 'Fix' sound frequencies"); S9xMessage(S9X_INFO, S9X_USAGE, ""); - + /* FEATURE OPTIONS */ S9xMessage(S9X_INFO, S9X_USAGE, "-conf Use specified conf file (after standard files)"); S9xMessage(S9X_INFO, S9X_USAGE, "-nostdconf Do not load the standard config files"); @@ -277,17 +258,11 @@ void S9xUsage () S9xMessage(S9X_INFO, S9X_USAGE, "-nodsp1 Force detection of no DSP-1 chip"); S9xMessage(S9X_INFO, S9X_USAGE, ""); - /* Multi ROMs OPTIONS */ - S9xMessage(S9X_INFO, S9X_USAGE, "-multi Enable multi cartridge system"); - S9xMessage(S9X_INFO, S9X_USAGE, "-carta ROM in slot A. Use with -multi"); - S9xMessage(S9X_INFO, S9X_USAGE, "-cartb ROM in slot B. Use with -multi"); - +#ifdef DEBUGGER /* OPTIONS FOR DEBUGGING USE */ - S9xMessage(S9X_INFO, S9X_USAGE, "-hdmahacks or -h <1-199> Changes HDMA transfer timing"); + S9xMessage(S9X_INFO, S9X_USAGE, "-cycles or -h <1-199> Percentage of CPU cycles to execute per scanline"); S9xMessage(S9X_INFO, S9X_USAGE, "-speedhacks or -sh Enable speed hacks"); S9xMessage(S9X_INFO, S9X_USAGE, "-nospeedhacks or -nsh Disable speed hacks"); - S9xMessage(S9X_INFO, S9X_USAGE, "-invalidvramaccess Allow invalid VRAM access"); -#ifdef DEBUGGER S9xMessage(S9X_INFO, S9X_USAGE, "-debug or -d Set the Debugger flag at startup"); S9xMessage(S9X_INFO, S9X_USAGE, "-trace or -t Begin CPU instruction tracing at startup"); S9xMessage(S9X_INFO, S9X_USAGE, "-noirq Disable processor IRQ (for debugging)"); @@ -321,7 +296,7 @@ void S9xUsage () S9xMessage(S9X_INFO, S9X_USAGE, " one-justifier ditto"); S9xMessage(S9X_INFO, S9X_USAGE, " two-justifiers Blue & Pink Justifiers"); S9xMessage(S9X_INFO, S9X_USAGE, " mp5:#### MP5 with the 4 named pads (1-8 or n)"); - + S9xMessage(S9X_INFO, S9X_USAGE, ""); #ifdef NETPLAY_SUPPORT @@ -341,24 +316,15 @@ void S9xUsage () S9xMessage(S9X_INFO, S9X_USAGE, "-ahiunit Set AHI Unit to "); S9xMessage(S9X_INFO, S9X_USAGE, ""); #endif - S9xMessage(S9X_INFO, S9X_USAGE, " DeHackEd's commands:"); - S9xMessage(S9X_INFO, S9X_USAGE, "-dumpstreams Save audio/video data to disk"); - S9xMessage(S9X_INFO, S9X_USAGE, "-mute Don't output audio to sound card, use with above."); - S9xMessage(S9X_INFO, S9X_USAGE, "-upanddown Override protection from pressing"); - S9xMessage(S9X_INFO, S9X_USAGE, " left+right or up+down together"); - S9xMessage(S9X_INFO, S9X_USAGE, "-autodemo Start emulator playing a movie"); - S9xMessage(S9X_INFO, S9X_USAGE, "-maxframes Stop emulator after playing specified"); - S9xMessage(S9X_INFO, S9X_USAGE, " number of frames. Requires -dumpstreams"); - S9xMessage(S9X_INFO, S9X_USAGE, "-oldturbo Turbo button renders all frames, but slower"); - S9xMessage(S9X_INFO, S9X_USAGE, ""); + #ifndef NGC - S9xExtraUsage(); + S9xExtraUsage(); #endif S9xMessage (S9X_INFO, S9X_USAGE, "\ \nROM image needs to be in Super MagiCom (*.smc), Super FamiCom (*.sfc),\n\ *.fig, or split (*.1, *.2, or sf32527a, sf32527b, etc) format and can be\n\ -compressed with zip, gzip, JMA, or compress.\n"); +compressed with zip, gzip, or compress.\n"); exit (1); } @@ -456,13 +422,13 @@ char *S9xParseArgs (char **argv, int argc) S9xUsage (); } else if (strcasecmp (argv [i], "-h") == 0 || - strcasecmp (argv [i], "-hdmahacks") == 0) + strcasecmp (argv [i], "-cycles") == 0) { if (i + 1 < argc) { int p = atoi (argv [++i]); if (p > 0 && p < 200) - Settings.HDMATimingHack = p; + Settings.CyclesPercentage = p; } else S9xUsage (); @@ -487,10 +453,6 @@ char *S9xParseArgs (char **argv, int argc) { Settings.ShutdownMaster = TRUE; } - else if (strcasecmp (argv [i], "-invalidvramaccess") == 0) - { - Settings.BlockInvalidVRAMAccess = FALSE; - } else if (strcasecmp (argv [i], "-p") == 0 || strcasecmp (argv [i], "-pal") == 0) { @@ -567,7 +529,7 @@ char *S9xParseArgs (char **argv, int argc) Settings.ForceNoTransparency = TRUE; Settings.ForceTransparency = FALSE; } - else if (strcasecmp (argv [i], "-hi") == 0 || + else if (strcasecmp (argv [i], "-hi") == 0 || strcasecmp (argv [i], "-hires") == 0) { Settings.SupportHiRes = TRUE; @@ -581,8 +543,6 @@ char *S9xParseArgs (char **argv, int argc) { Settings.DisplayFrameRate = TRUE; } - else if (strcasecmp (argv [i], "-nomessagesinimage") == 0) - Settings.AutoDisplayMessages = FALSE; else if (strcasecmp (argv [i], "-i") == 0 || strcasecmp (argv [i], "-interleaved") == 0) Settings.ForceInterleaved = TRUE; @@ -709,8 +669,14 @@ char *S9xParseArgs (char **argv, int argc) double ft; if (sscanf (argv [++i], "%lf", &ft) == 1) { - Settings.FrameTimePAL = (int32) ft; - Settings.FrameTimeNTSC = (int32) ft; +#ifdef __WIN32__ + Settings.FrameTimePAL = (int32) (ft * 1000); + Settings.FrameTimeNTSC = (int32) (ft * 1000); +#else + Settings.FrameTimePAL = (int32) ft; + Settings.FrameTimeNTSC = (int32) ft; +#endif + } } else @@ -773,9 +739,10 @@ char *S9xParseArgs (char **argv, int argc) Settings.SoundEnvelopeHeightReading = TRUE; Settings.InterpolatedSound = TRUE; } - else if (strcasecmp (argv [i], "-nois") == 0) + else if (strcasecmp (argv [i], "-interpolatedsound") == 0 || + strcasecmp (argv [i], "-is") == 0) { - Settings.InterpolatedSound = FALSE; + Settings.InterpolatedSound = TRUE; } #ifdef USE_THREADS else if (strcasecmp (argv [i], "-threadsound") == 0 || @@ -866,26 +833,6 @@ char *S9xParseArgs (char **argv, int argc) } } #endif - else if (strcasecmp (argv[i], "-dumpstreams") == 0) - dumpstreams = 1; - else if (strcasecmp (argv[i], "-maxframes") == 0) - maxframes = atoi(argv[++i]); - else if (strcasecmp (argv[i], "-mute") == 0) - Settings.Mute = 1; - else if (strcasecmp (argv[i], "-upanddown") == 0) - Settings.UpAndDown = 1; - else if (strcasecmp (argv[i], "-oldturbo") == 0) - Settings.OldTurbo = 1; - else if (strcasecmp(argv[i], "-autodemo") == 0) { - i++; - if (!argv[i]) - abort(); - strcpy(autodemo, argv[i]); - } - else if (strcasecmp(argv[i], "-keypress") == 0) // videologger output of controller 1 - Settings.DisplayPressedKeys = 1; - else if (strcasecmp(argv[i], "-keypress2") == 0) // S9xDisplayMessages output of all controllers and peripherals - Settings.DisplayPressedKeys = 2; else if (strcasecmp (argv [i], "-conf") == 0) { if (++i>=argc) S9xUsage(); @@ -895,33 +842,6 @@ char *S9xParseArgs (char **argv, int argc) { // Do nothing, S9xLoadConfigFiles() handled it } - else if (strcasecmp (argv [i], "-version") == 0) - { - printf("Snes9X " VERSION "\n"); - exit(0); - } - else if (strcasecmp (argv [i], "-help") == 0) - { - S9xUsage(); - } - else if (strcasecmp (argv [i], "-multi") == 0) - { - Settings.Multi = TRUE; - } - else if (strcasecmp (argv [i], "-carta") == 0) - { - if (i + 1 < argc) - { - strncpy (Settings.CartAName, argv [++i], _MAX_PATH); - } - } - else if (strcasecmp (argv [i], "-cartb") == 0) - { - if (i + 1 < argc) - { - strncpy (Settings.CartBName, argv [++i], _MAX_PATH); - } - } else S9xParseArg (argv, i, argc); @@ -935,6 +855,7 @@ char *S9xParseArgs (char **argv, int argc) #endif return (rom_filename); + } #ifndef NGC @@ -962,7 +883,7 @@ void S9xParseCheatsFile (const char *rom_filename) { while(fgets(buf, 80, f) != NULL) { - if ((p = strrchr (buf, '\n')) != NULL) + if ((p = strrchr (buf, '\n')) != NULL) *p = '\0'; if (((error = S9xGameGenieToRaw (buf, address, byte)) == NULL) || ((error = S9xProActionReplayToRaw (buf, address, byte)) == NULL)) @@ -1033,7 +954,7 @@ static void parse_crosshair_spec(enum crosscontrols ctl, const char *spec){ static bool try_load(const char *fname, ConfigFile &conf){ STREAM fp; if((fp=OPEN_STREAM(fname, "r"))!=NULL){ - fprintf(stdout, "Reading config file %s\n", fname); + fprintf(stderr, "Reading config file %s\n", fname); conf.LoadFile(new fReader(fp)); CLOSE_STREAM(fp); return true; @@ -1052,7 +973,7 @@ void S9xLoadConfigFiles(char **argv, int argc){ } } - static ConfigFile conf; // static because some of its functions return pointers that would otherwise become invalid after this function + ConfigFile conf; conf.Clear(); if(!skip){ @@ -1088,11 +1009,10 @@ void S9xLoadConfigFiles(char **argv, int argc){ /* Parse config file here */ Settings.NextAPUEnabled=conf.GetBool("Sound::APUEnabled", Settings.APUEnabled); Settings.SoundSkipMethod=conf.GetInt("Sound::SoundSkip", 0); - i=conf.GetInt("CPU::HDMATimingHack", 100); - if(i>0 && i<200) Settings.HDMATimingHack = i; + i=conf.GetInt("CPU::Cycles", 100); + if(i>0 && i<200) Settings.CyclesPercentage = i; Settings.DisableHDMA=conf.GetBool("Settings::DisableHDMA", false); - Settings.ShutdownMaster=conf.GetBool("Settings::SpeedHacks", false); - Settings.BlockInvalidVRAMAccess=conf.GetBool("Settings::BlockInvalidVRAMAccess", true); + Settings.ShutdownMaster=conf.GetBool("Settings::SpeedHacks", true); Settings.ForcePAL=conf.GetBool("ROM::PAL", false); Settings.ForceNTSC=conf.GetBool("ROM::NTSC", false); if(!strcasecmp(conf.GetString("Settings::FrameSkip", "Auto"),"Auto")){ @@ -1103,7 +1023,6 @@ void S9xLoadConfigFiles(char **argv, int argc){ Settings.TurboSkipFrames=conf.GetUInt("Settings::TurboFrameSkip", 15); Settings.TurboMode=conf.GetBool("Settings::TurboMode",false); Settings.StretchScreenshots=conf.GetInt("Settings::StretchScreenshots",1); - Settings.InitialInfoStringTimeout=conf.GetInt("Settings::MessageDisplayTime",120); Settings.AutoSaveDelay=conf.GetUInt("Settings::AutoSaveDelay", 30); Settings.ForceHiROM=conf.GetBool("ROM::HiROM", false); Settings.ForceLoROM=conf.GetBool("ROM::LoROM", false); @@ -1126,11 +1045,6 @@ void S9xLoadConfigFiles(char **argv, int argc){ } Settings.SupportHiRes=conf.GetBool("Display::HiRes", true); Settings.DisplayFrameRate=conf.GetBool("Display::FrameRate", false); - if(conf.Exists("Display::DisplayInput")) - Settings.DisplayPressedKeys=conf.GetBool("Display::DisplayInput", false)?1:0; -// GFX.FrameDisplay=conf.GetBool("Display::DisplayFrameCount", false); - GFX.FrameDisplay=TRUE; - Settings.AutoDisplayMessages=conf.GetBool("Display::MessagesInImage", true); if(conf.Exists("ROM::Interleaved")){ Settings.ForceInterleaved=conf.GetBool("ROM::Interleaved", false); Settings.ForceNotInterleaved=!Settings.ForceInterleaved; @@ -1154,8 +1068,14 @@ void S9xLoadConfigFiles(char **argv, int argc){ double ft; if (sscanf(conf.GetString("Settings::FrameTime"), "%lf", &ft) == 1) { +#ifdef __WIN32__ + Settings.FrameTimePAL = (int32) (ft * 1000); + Settings.FrameTimeNTSC = (int32) (ft * 1000); +#else Settings.FrameTimePAL = (int32) ft; Settings.FrameTimeNTSC = (int32) ft; +#endif + } } Settings.FrameTime = Settings.FrameTimeNTSC; @@ -1174,7 +1094,7 @@ void S9xLoadConfigFiles(char **argv, int argc){ Settings.SoundEnvelopeHeightReading=conf.GetBool("Sound::EnvelopeHeightReading"); Settings.DisableSampleCaching=!conf.GetBool("Sound::SampleCaching"); Settings.DisableMasterVolume=!conf.GetBool("Sound::MasterVolume"); - Settings.InterpolatedSound=conf.GetBool("Sound::Interpolate", true); + Settings.InterpolatedSound=conf.GetBool("Sound::Interpolate", false); if(conf.Exists("Sound::Sync")){ Settings.SoundSync=conf.GetInt("Sound::Sync", 1); if(Settings.SoundSync>2) Settings.SoundSync=1; @@ -1227,7 +1147,7 @@ void S9xLoadConfigFiles(char **argv, int argc){ Settings.Port = NP_DEFAULT_PORT; if(conf.Exists("Netplay::Port")){ Settings.NetPlay = TRUE; - Settings.Port = -(int)conf.GetUInt("Netplay::Port"); + Settings.Port = -conf.GetUInt("Netplay::Port"); } Settings.ServerName[0]='\0'; if(conf.Exists("Netplay::Server")){ @@ -1249,12 +1169,6 @@ void S9xLoadConfigFiles(char **argv, int argc){ } #endif Settings.JoystickEnabled=conf.GetBool("Controls::Joystick", Settings.JoystickEnabled); - Settings.UpAndDown=conf.GetBool("Controls::AllowLeftRight", false); - Settings.SnapshotScreenshots=conf.GetBool("Settings::SnapshotScreenshots", true); - Settings.MovieTruncate=conf.GetBool("Settings::MovieTruncateAtEnd", false); - Settings.MovieNotifyIgnored=conf.GetBool("Settings::MovieNotifyIgnored", false); - Settings.DisplayWatchedAddresses=conf.GetBool("Settings::DisplayWatchedAddresses", false); - Settings.WrongMovieStateProtection=conf.GetBool("Settings::WrongMovieStateProtection", true); rom_filename=conf.GetStringDup("ROM::Filename", NULL); S9xParsePortConfig(conf, 1); diff --git a/source/snes9x/snes9x.h b/source/snes9x/snes9x.h index 18d3e0e6..83e8e412 100644 --- a/source/snes9x/snes9x.h +++ b/source/snes9x/snes9x.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,24 +141,22 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _SNES9X_H_ #define _SNES9X_H_ -#define VERSION "1.51" +#define VERSION "1.5" #include #include #ifdef __WIN32__ -#include +#include "..\wsnes9x.h" #ifdef ZLIB -#include +#include "..\zlib\zlib.h" #endif #endif -//#include "language.h" // files should include this as needed, no need to recompile practically everything when it changes +#include "language.h" #include "port.h" #include "65c816.h" @@ -189,8 +170,9 @@ #ifdef ZLIB #ifndef __WIN32__ -#include +#include "zlib.h" #endif + #define STREAM gzFile #define READ_STREAM(p,l,s) gzread (s,p,l) #define WRITE_STREAM(p,l,s) gzwrite (s,p,l) @@ -218,10 +200,8 @@ #define SNES_WIDTH 256 #define SNES_HEIGHT 224 #define SNES_HEIGHT_EXTENDED 239 -#define MAX_SNES_WIDTH (SNES_WIDTH * 2) -#define MAX_SNES_HEIGHT (SNES_HEIGHT_EXTENDED * 2) -#define IMAGE_WIDTH (Settings.SupportHiRes ? MAX_SNES_WIDTH : SNES_WIDTH) -#define IMAGE_HEIGHT (Settings.SupportHiRes ? MAX_SNES_HEIGHT : SNES_HEIGHT_EXTENDED) +#define IMAGE_WIDTH (Settings.SupportHiRes ? SNES_WIDTH * 2 : SNES_WIDTH) +#define IMAGE_HEIGHT (Settings.SupportHiRes ? SNES_HEIGHT_EXTENDED * 2 : SNES_HEIGHT_EXTENDED) #define NTSC_MASTER_CLOCK 21477272.0 #define PAL_MASTER_CLOCK 21281370.0 @@ -248,10 +228,8 @@ #define SNES_HDMA_INIT_HC 20 // FIXME: not true #define SNES_RENDER_START_HC (48 * ONE_DOT_CYCLE) // FIXME: Snes9x renders a line at a time. -#define SNES_APU_CLOCK 1024000.0 // 1026900.0? -#define SNES_APU_ACCURACY 10 -#define SNES_APU_ONE_CYCLE_SCALED ((int32) (NTSC_MASTER_CLOCK / SNES_APU_CLOCK * (1 << SNES_APU_ACCURACY))) -#define SNES_APUTIMER2_CYCLE_SCALED ((int32) (NTSC_MASTER_CLOCK / 64000.0 * (1 << SNES_APU_ACCURACY))) +#define SNES_APUTIMER_ACCURACY 10 +#define SNES_APUTIMER2_CYCLE_SHIFT ((int32) ((SNES_CYCLES_PER_SCANLINE << SNES_APUTIMER_ACCURACY) * (1.0 / 64000.0) / SNES_SCANLINE_TIME + 0.5)) #define AUTO_FRAMERATE 200 @@ -280,7 +258,7 @@ #define PROCESS_SOUND_FLAG (1 << 8) #define FRAME_ADVANCE_FLAG (1 << 9) #define DELAYED_NMI_FLAG2 (1 << 10) -#define IRQ_FLAG (1 << 11) +#define IRQ_PENDING_FLAG (1 << 11) #define HALTED_FLAG (1 << 12) struct SCPUState{ @@ -289,8 +267,8 @@ struct SCPUState{ bool8 NMIActive; bool8 IRQActive; bool8 WaitingForInterrupt; - bool8 InDMAorHDMA; - bool8 InWRAMDMAorHDMA; + bool8 InDMA; + bool8 InWRAM_DMA; uint8 WhichEvent; uint8 *PCBase; uint32 PBPCAtOpcodeStart; @@ -306,11 +284,6 @@ struct SCPUState{ bool8 SRAMModified; bool8 BRKTriggered; bool8 TriedInterleavedMode2; - int32 IRQPending; - bool8 InDMA; - bool8 InHDMA; - uint8 HDMARanInDMA; - int32 PrevCycles; }; struct STimings { @@ -326,7 +299,6 @@ struct STimings { int32 WRAMRefreshPos; int32 RenderPos; bool8 InterlaceField; - int32 DMACPUSync; }; enum { @@ -349,7 +321,7 @@ struct SSettings{ bool8 APUEnabled; bool8 Shutdown; uint8 SoundSkipMethod; - int32 HDMATimingHack; + int32 CyclesPercentage; bool8 DisableIRQ; bool8 Paused; bool8 ForcedPause; @@ -396,7 +368,7 @@ struct SSettings{ bool8 ForceSDD1; bool8 ForceNoSDD1; bool8 SRTC; - + bool8 ShutdownMaster; bool8 MultiPlayer5Master; bool8 SuperScopeMaster; @@ -423,22 +395,17 @@ struct SSettings{ bool8 DisableSampleCaching; bool8 DisableMasterVolume; bool8 SoundSync; - bool8 FakeMuteFix; bool8 InterpolatedSound; bool8 ThreadSound; bool8 Mute; bool8 NextAPUEnabled; uint8 AltSampleDecode; bool8 FixFrequency; - + /* Graphics options */ bool8 Transparency; bool8 SupportHiRes; - bool8 Mode7Interpolate; // no longer used? - bool8 AutoDisplayMessages; - uint8 BG_Forced; - bool8 SnapshotScreenshots; - uint32 InitialInfoStringTimeout; // Messages normally display for this many frames + bool8 Mode7Interpolate; /* SNES graphics options */ bool8 BGLayering; @@ -448,12 +415,6 @@ struct SSettings{ bool8 DisableHDMA; bool8 DisplayFrameRate; bool8 DisableRangeTimeOver; /* XXX: unused */ - bool8 DisplayWatchedAddresses; - - /* Multi ROMs */ - bool8 Multi; - char CartAName[_MAX_PATH + 1]; - char CartBName[_MAX_PATH + 1]; /* Others */ bool8 NetPlay; @@ -465,16 +426,9 @@ struct SSettings{ int32 AutoSaveDelay; /* Time in seconds before S-RAM auto-saved if modified. */ bool8 ApplyCheats; bool8 TurboMode; - bool8 OldTurbo; - bool8 UpAndDown; - uint8 DisplayPressedKeys; // The value indicates how to do it. - uint32 HighSpeedSeek; uint32 TurboSkipFrames; uint32 AutoMaxSkipFrames; - bool8 MovieTruncate; - bool8 MovieNotifyIgnored; - bool8 WrongMovieStateProtection; - + /* Fixes for individual games */ bool8 WinterGold; bool8 BS; /* Japanese Satellite System games. */ @@ -483,7 +437,6 @@ struct SSettings{ uint8 APURAMInitialValue; bool8 SampleCatchup; int8 SETA; - bool8 BlockInvalidVRAMAccess; bool8 TakeScreenshot; int8 StretchScreenshots; uint16 DisplayColor; diff --git a/source/snes9x/soundux.cpp b/source/snes9x/soundux.cpp index 3247e912..d551eb88 100644 --- a/source/snes9x/soundux.cpp +++ b/source/snes9x/soundux.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifdef __DJGPP__ #include #undef TRUE @@ -325,7 +306,7 @@ void S9xAPUSetEndX (int); void S9xSetEnvRate (Channel *, int32, int32); void MixStereo (int); void MixMono (int); - + static void S9xSetSoundFrequency (int, int); static void S9xConvertSoundOldValues (); static void DecodeBlock (Channel *); @@ -336,7 +317,6 @@ STATIC inline uint8 *S9xGetSampleAddress (int); EXTERN_C void DecodeBlockAsm (int8 *, int16 *, int32 *, int32 *); EXTERN_C void DecodeBlockAsm2 (int8 *, int16 *, int32 *, int32 *); -static bool8 DoFakeMute = FALSE; STATIC inline uint8 *S9xGetSampleAddress (int sample_number) { @@ -350,12 +330,10 @@ void S9xAPUSetEndOfSample (int i, Channel *ch) ch->mode = MODE_NONE; ch->out_sample = 0; ch->xenvx = 0; - if(!DoFakeMute) { APU.DSP[APU_ENDX] |= 1 << i; APU.DSP[APU_KON] &= ~(1 << i); APU.DSP[APU_KOFF] &= ~(1 << i); APU.KeyedChannels &= ~(1 << i); - } } #ifdef __DJGPP @@ -364,9 +342,7 @@ END_OF_FUNCTION (S9xAPUSetEndOfSample) void S9xAPUSetEndX (int i) { - if(!DoFakeMute) { APU.DSP[APU_ENDX] |= 1 << i; - } } #ifdef __DJGPP @@ -511,8 +487,8 @@ void S9xPrepareSoundForSnapshotSave (bool8 restore) { for (i = 0; i < NUM_CHANNELS; i++) { - Channel *ch = &SoundData.channels[i]; - + Channel *ch = &SoundData.channels[i]; + ch->count = 0; ch->envx = ch->xenvx >> 4; ch->envx_target = ch->xenvx_target >> 4; @@ -524,32 +500,32 @@ void S9xPrepareSoundForSnapshotSave (bool8 restore) if (env_counter_max < ch->xenv_count) ch->env_error = 0; - else + else ch->env_error = (uint32) ((double) FIXED_POINT / env_counter_max * (env_counter_max - ch->xenv_count)); if (ch->xenv_rate < 0) ch->erate = 0; - else + else ch->erate = (uint32) ((double) FIXED_POINT / env_counter_max * ch->xenv_rate); - + for (j = 0; j < 32; j++) if (env_counter_table[j] == ch->xattack_rate) break; ch->attack_rate = OldAttackRate[(unsigned) (((j - 1) >> 1) & 0xF)]; - + for (j = 0; j < 32; j++) if (env_counter_table[j] == ch->xdecay_rate) break; ch->decay_rate = OldDecayRate[(unsigned) (((j - 0x10) >> 1) & 0x7)]; - + for (j = 0; j < 32; j++) if (env_counter_table[j] == ch->xsustain_rate) break; - ch->sustain_rate = OldSustainRate[(unsigned) (j & 0x1F)]; + ch->sustain_rate = OldSustainRate[(unsigned) (j & 0x1F)]; } - + for (j = 0; j < 32; j++) if (env_counter_table[j] == SoundData.noise_rate) break; @@ -557,7 +533,7 @@ void S9xPrepareSoundForSnapshotSave (bool8 restore) for (i = 0; i < NUM_CHANNELS; i++) { Channel *ch = &SoundData.channels[i]; - + temp_hertz[i] = ch->hertz; if (ch->type == SOUND_NOISE) ch->hertz = OldNoiseFreq[(unsigned) (j & 0x1F)]; @@ -568,7 +544,7 @@ void S9xPrepareSoundForSnapshotSave (bool8 restore) for (i = 0; i < NUM_CHANNELS; i++) { Channel *ch = &SoundData.channels[i]; - + ch->hertz = temp_hertz[i]; } } @@ -582,38 +558,38 @@ static void S9xConvertSoundOldValues () for (i = 0; i < NUM_CHANNELS; i++) { Channel *ch = &SoundData.channels[i]; - + ch->xenvx = ch->envx << 4; ch->xenvx_target = ch->envx_target << 4; ch->out_sample = ((ch->sample * ch->xenvx) >> 11) & ~1; ch->xsustain_level = ch->sustain_level << 8; ch->xenv_rate = (int32) ((double) ch->erate * env_counter_max / FIXED_POINT); - ch->xenv_count = env_counter_max - + ch->xenv_count = env_counter_max - (int32) ((double) ch->env_error * env_counter_max / FIXED_POINT); - + for (j = 0; j < 16; j++) if (OldAttackRate[j] == ch->attack_rate) break; ch->xattack_rate = env_counter_table[(unsigned) (((j << 1) + 1) & 0x1F)]; - + for (j = 0; j < 8; j++) if (OldDecayRate[j] == ch->decay_rate) break; ch->xdecay_rate = env_counter_table[(unsigned) (((j << 1) + 0x10) & 0x1F)]; - + for (j = 0; j < 32; j++) if (OldSustainRate[j] == ch->sustain_rate) break; ch->xsustain_rate = env_counter_table[(unsigned) (j & 0x1F)]; - + if (ch->type == SOUND_NOISE) { old_noise_freq = ch->hertz; ch->hertz = 32000; } } - + if (old_noise_freq) { for (j = 0; j < 32; j++) @@ -640,7 +616,7 @@ void S9xFixSoundAfterSnapshotLoad (int version) S9xSetFilterCoefficient (5, (signed char) APU.DSP[APU_C5]); S9xSetFilterCoefficient (6, (signed char) APU.DSP[APU_C6]); S9xSetFilterCoefficient (7, (signed char) APU.DSP[APU_C7]); - + if (version < 2) S9xConvertSoundOldValues (); @@ -657,7 +633,7 @@ void S9xFixSoundAfterSnapshotLoad (int version) SoundData.channels[i].previous[0] = (int32) SoundData.channels[i].previous16[0]; SoundData.channels[i].previous[1] = (int32) SoundData.channels[i].previous16[1]; } - + SoundData.noise_count = 0; SoundData.master_volume[Settings.ReverseStereo] = SoundData.master_volume_left; @@ -669,7 +645,7 @@ void S9xFixSoundAfterSnapshotLoad (int version) void S9xSetFilterCoefficient (int tap, int value) { FilterTaps[tap & 7] = value; - SoundData.no_filter = + SoundData.no_filter = FilterTaps[0] == 127 && FilterTaps[1] == 0 && FilterTaps[2] == 0 && @@ -683,7 +659,7 @@ void S9xSetFilterCoefficient (int tap, int value) void S9xSetSoundADSR (int channel, int ar, int dr, int sr, int sl) { Channel *ch = &SoundData.channels[channel]; - + ch->xattack_rate = env_counter_table[(ar << 1) + 1]; ch->xdecay_rate = env_counter_table[(dr << 1) + 0x10]; ch->xsustain_rate = env_counter_table[sr]; @@ -694,7 +670,7 @@ void S9xSetSoundADSR (int channel, int ar, int dr, int sr, int sl) case SOUND_ATTACK: S9xSetEnvRate (ch, ch->xattack_rate, ENV_MAX); break; - + case SOUND_DECAY: S9xSetEnvRate (ch, ch->xdecay_rate, ch->xsustain_level); break; @@ -825,13 +801,13 @@ static void AltDecodeBlock (Channel *ch) sample2 = sample1 << 4; sample2 >>= 4; sample1 >>= 4; - + out = (sample1 << shift) - prev1 + (prev1 >> 4); prev1 = (int16) prev0; prev0 &= ~3; - *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) - + *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) - (prev0 >> 4); - + out = (sample2 << shift) - prev1 + (prev1 >> 4); prev1 = (int16) prev0; prev0 &= ~3; @@ -848,18 +824,18 @@ static void AltDecodeBlock (Channel *ch) sample2 >>= 4; sample1 >>= 4; out = (sample1 << shift); - + out = out - prev1 + (prev1 >> 3) + (prev1 >> 4); prev1 = (int16) prev0; prev0 &= ~3; - *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - + *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - (prev0 >> 4) - (prev1 >> 6); - + out = (sample2 << shift); out = out - prev1 + (prev1 >> 3) + (prev1 >> 4); prev1 = (int16) prev0; prev0 &= ~3; - *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - + *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - (prev0 >> 4) - (prev1 >> 6); } break; @@ -913,16 +889,16 @@ static void AltDecodeBlock2 (Channel *ch) sample2 = sample1 << 4; sample2 >>= 4; sample1 >>= 4; - + out = (int32) (sample1 << shift); - + prev1 = prev0; prev0 = out; CLIP16(out); *raw++ = (int16) out; - + out = (int32) (sample2 << shift); - + prev1 = prev0; prev0 = out; CLIP16(out); @@ -939,15 +915,15 @@ static void AltDecodeBlock2 (Channel *ch) sample1 >>= 4; out = (int32) (sample1 << shift); out += (int32) ((double) prev0 * 15/16); - + prev1 = prev0; prev0 = out; CLIP16(out); *raw++ = (int16) out; - + out = (int32) (sample2 << shift); out += (int32) ((double) prev0 * 15/16); - + prev1 = prev0; prev0 = out; CLIP16(out); @@ -962,21 +938,21 @@ static void AltDecodeBlock2 (Channel *ch) sample2 = sample1 << 4; sample2 >>= 4; sample1 >>= 4; - + out = ((sample1 << shift) * 256 + (prev0 & ~0x2) * 488 - prev1 * 240) >> 8; - + prev1 = prev0; prev0 = (int16) out; *raw++ = (int16) out; - + out = ((sample2 << shift) * 256 + (prev0 & ~0x2) * 488 - prev1 * 240) >> 8; - + prev1 = prev0; prev0 = (int16) out; *raw++ = (int16) out; } break; - + case 3: for (i = 8; i != 0; i--) { @@ -986,19 +962,19 @@ static void AltDecodeBlock2 (Channel *ch) sample1 >>= 4; out = (int32) (sample1 << shift); out += (int32) ((double) prev0 * 115/64 - (double) prev1 * 13/16); - + prev1 = prev0; prev0 = out; - + CLIP16(out); *raw++ = (int16) out; - + out = (int32) (sample2 << shift); out += (int32) ((double) prev0 * 115/64 - (double) prev1 * 13/16); - + prev1 = prev0; prev0 = out; - + CLIP16(out); *raw++ = (int16) out; } @@ -1066,7 +1042,7 @@ static void DecodeBlock (Channel *ch) sample2 >>= 4; //Sample 1 = Top Nibble, shifted down and Sign Extended. sample1 >>= 4; - + for (int nybblesmp = 0; nybblesmp < 2; nybblesmp++) { out = (nybblesmp ? sample2 : sample1); @@ -1074,19 +1050,19 @@ static void DecodeBlock (Channel *ch) out = (out << shift) >> 1; else out &= ~0x7FF; - + switch (filter) { case 0x00: // Method0 -[Smp] break; - + case 0x04: // Method1 -[Delta]+[Smp-1](15/16) out += prev0 >> 1; out += (-prev0) >> 5; break; - + case 0x08: // Method2 -[Delta]+[Smp-1](61/32)-[Smp-2](15/16) out += prev0; @@ -1094,7 +1070,7 @@ static void DecodeBlock (Channel *ch) out -= prev1 >> 1; out += prev1 >> 5; break; - + case 0x0C: // Method3 -[Delta]+[Smp-1](115/64)-[Smp-2](13/16) out += prev0; @@ -1105,7 +1081,7 @@ static void DecodeBlock (Channel *ch) } CLIP16(out); - + prev1 = (signed short) prev0; prev0 = *raw++ = (signed short) (out << 1); } @@ -1119,20 +1095,18 @@ static void DecodeBlock (Channel *ch) void MixStereo (int sample_count) { - DoFakeMute=Settings.FakeMuteFix; - static int32 noise_cache[256]; static int32 wave[SOUND_BUFFER_SIZE]; int pitch_mod = SoundData.pitch_mod & ~APU.DSP[APU_NON]; - + int32 noise_index = 0; int32 noise_count = 0; - + if (APU.DSP[APU_NON]) { noise_count = SoundData.noise_count; - + for (uint32 I = 0; I < (uint32) sample_count; I += 2) { noise_count -= SoundData.noise_rate; @@ -1150,9 +1124,9 @@ void MixStereo (int sample_count) { Channel *ch = &SoundData.channels[J]; uint32 freq = ch->frequency; - + bool8 last_block = FALSE; - + if (ch->type == SOUND_NOISE) { noise_index = 0; @@ -1161,10 +1135,10 @@ void MixStereo (int sample_count) if (ch->state == SOUND_SILENT || last_block || !(so.sound_switch & (1 << J))) continue; - + bool8 mod1 = pitch_mod & (1 << J); bool8 mod2 = pitch_mod & (1 << (J + 1)); - + if (ch->needs_decode) { DecodeBlock(ch); @@ -1172,9 +1146,9 @@ void MixStereo (int sample_count) ch->sample = ch->block[0]; ch->sample_pointer = 0; } - + for (uint32 I = 0; I < (uint32) sample_count; I += 2) - { + { switch (ch->state) { case SOUND_ATTACK: @@ -1189,12 +1163,12 @@ void MixStereo (int sample_count) ch->xenv_count += env_counter_max; } } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; - if (ch->xsustain_level != ENV_RANGE) + if (ch->xsustain_level != ENV_RANGE) { ch->state = SOUND_DECAY; S9xSetEnvRate (ch, ch->xdecay_rate, ch->xsustain_level); @@ -1205,9 +1179,9 @@ void MixStereo (int sample_count) S9xSetEnvRate (ch, ch->xsustain_rate, 0); } } - + break; - + case SOUND_DECAY: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1229,9 +1203,9 @@ void MixStereo (int sample_count) S9xSetEnvRate (ch, ch->xsustain_rate, 0); } } - + break; - + case SOUND_SUSTAIN: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1247,7 +1221,7 @@ void MixStereo (int sample_count) } break; - + case SOUND_RELEASE: ch->xenv_count -= env_counter_max; while (ch->xenv_count <= 0) @@ -1263,7 +1237,7 @@ void MixStereo (int sample_count) } break; - + case SOUND_INCREASE_LINEAR: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1271,7 +1245,7 @@ void MixStereo (int sample_count) ch->xenvx += (ENV_RANGE >> 6); // 1/64 ch->xenv_count += env_counter_max; } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; @@ -1279,9 +1253,9 @@ void MixStereo (int sample_count) ch->mode = MODE_GAIN; S9xSetEnvRate (ch, 0, 0); } - + break; - + case SOUND_INCREASE_BENT_LINE: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1290,10 +1264,10 @@ void MixStereo (int sample_count) ch->xenvx += (ENV_RANGE >> 8); // 1/256 else ch->xenvx += (ENV_RANGE >> 6); // 1/64 - + ch->xenv_count += env_counter_max; } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; @@ -1301,9 +1275,9 @@ void MixStereo (int sample_count) ch->mode = MODE_GAIN; S9xSetEnvRate (ch, 0, 0); } - + break; - + case SOUND_DECREASE_LINEAR: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1311,7 +1285,7 @@ void MixStereo (int sample_count) ch->xenvx -= (ENV_RANGE >> 6); // 1/64 ch->xenv_count += env_counter_max; } - + if (ch->xenvx <= 0) { S9xAPUSetEndOfSample (J, ch); @@ -1319,7 +1293,7 @@ void MixStereo (int sample_count) } break; - + case SOUND_DECREASE_EXPONENTIAL: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1327,7 +1301,7 @@ void MixStereo (int sample_count) ch->xenvx -= ((ch->xenvx - 1) >> 8) + 1; // 1 - 1/256 ch->xenv_count += env_counter_max; } - + if (ch->xenvx <= 0) { S9xAPUSetEndOfSample (J, ch); @@ -1335,7 +1309,7 @@ void MixStereo (int sample_count) } break; - + case SOUND_GAIN: S9xSetEnvRate (ch, 0, 0); @@ -1350,11 +1324,11 @@ void MixStereo (int sample_count) ch->nb_sample[ch->nb_index] = ch->sample; ch->nb_index = (ch->nb_index + 1) & 3; - ch->sample_pointer++; + ch->sample_pointer++; if (ch->sample_pointer == SOUND_DECODE_LENGTH) { ch->sample_pointer = 0; - + if (ch->last_block) { S9xAPUSetEndX (J); @@ -1369,7 +1343,7 @@ void MixStereo (int sample_count) ch->nb_sample[ch->nb_index] = 0; ch->nb_index = (ch->nb_index + 1) & 3; } - + break; } else @@ -1379,13 +1353,13 @@ void MixStereo (int sample_count) ch->block_pointer = READ_WORD(dir + 2); // loop pointer } } - + DecodeBlock (ch); } ch->sample = ch->block[ch->sample_pointer]; } - + int32 outx, d; if (ch->type == SOUND_SAMPLE) @@ -1412,21 +1386,21 @@ void MixStereo (int sample_count) noise_count += env_counter_max; noise_index = (noise_index + 1) & 0xFF; } - + outx = noise_cache[noise_index] >> 16; } - + outx = ((outx * ch->xenvx) >> 11) & ~1; ch->out_sample = outx; - + if (mod2) wave[I >> 1] = outx; int32 VL, VR; - + VL = (outx * ch->volume_left ) >> 7; VR = (outx * ch->volume_right) >> 7; - + MixBuffer[I ^ Settings.ReverseStereo ] += VL; MixBuffer[I + (1 ^ Settings.ReverseStereo)] += VR; ch->echo_buf_ptr[I ^ Settings.ReverseStereo ] += VL; @@ -1435,8 +1409,7 @@ void MixStereo (int sample_count) stereo_exit: ; } - DoFakeMute=FALSE; - + if (APU.DSP[APU_NON]) SoundData.noise_count = noise_count; } @@ -1447,20 +1420,18 @@ END_OF_FUNCTION(MixStereo); void MixMono (int sample_count) { - DoFakeMute=Settings.FakeMuteFix; - static int32 noise_cache[256]; static int32 wave[SOUND_BUFFER_SIZE]; int pitch_mod = SoundData.pitch_mod & ~APU.DSP[APU_NON]; - + int32 noise_index = 0; int32 noise_count = 0; - + if (APU.DSP[APU_NON]) { noise_count = SoundData.noise_count; - + for (uint32 I = 0; I < (uint32) sample_count; I++) { noise_count -= SoundData.noise_rate; @@ -1478,9 +1449,9 @@ void MixMono (int sample_count) { Channel *ch = &SoundData.channels[J]; uint32 freq = ch->frequency; - + bool8 last_block = FALSE; - + if (ch->type == SOUND_NOISE) { noise_index = 0; @@ -1489,10 +1460,10 @@ void MixMono (int sample_count) if (ch->state == SOUND_SILENT || last_block || !(so.sound_switch & (1 << J))) continue; - + bool8 mod1 = pitch_mod & (1 << J); bool8 mod2 = pitch_mod & (1 << (J + 1)); - + if (ch->needs_decode) { DecodeBlock(ch); @@ -1500,9 +1471,9 @@ void MixMono (int sample_count) ch->sample = ch->block[0]; ch->sample_pointer = 0; } - + for (uint32 I = 0; I < (uint32) sample_count; I++) - { + { switch (ch->state) { case SOUND_ATTACK: @@ -1517,12 +1488,12 @@ void MixMono (int sample_count) ch->xenv_count += env_counter_max; } } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; - if (ch->xsustain_level != ENV_RANGE) + if (ch->xsustain_level != ENV_RANGE) { ch->state = SOUND_DECAY; S9xSetEnvRate (ch, ch->xdecay_rate, ch->xsustain_level); @@ -1533,9 +1504,9 @@ void MixMono (int sample_count) S9xSetEnvRate (ch, ch->xsustain_rate, 0); } } - + break; - + case SOUND_DECAY: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1557,9 +1528,9 @@ void MixMono (int sample_count) S9xSetEnvRate (ch, ch->xsustain_rate, 0); } } - + break; - + case SOUND_SUSTAIN: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1575,7 +1546,7 @@ void MixMono (int sample_count) } break; - + case SOUND_RELEASE: ch->xenv_count -= env_counter_max; while (ch->xenv_count <= 0) @@ -1591,7 +1562,7 @@ void MixMono (int sample_count) } break; - + case SOUND_INCREASE_LINEAR: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1599,7 +1570,7 @@ void MixMono (int sample_count) ch->xenvx += (ENV_RANGE >> 6); // 1/64 ch->xenv_count += env_counter_max; } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; @@ -1607,9 +1578,9 @@ void MixMono (int sample_count) ch->mode = MODE_GAIN; S9xSetEnvRate (ch, 0, 0); } - + break; - + case SOUND_INCREASE_BENT_LINE: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1618,10 +1589,10 @@ void MixMono (int sample_count) ch->xenvx += (ENV_RANGE >> 8); // 1/256 else ch->xenvx += (ENV_RANGE >> 6); // 1/64 - + ch->xenv_count += env_counter_max; } - + if (ch->xenvx > ENV_MAX) { ch->xenvx = ENV_MAX; @@ -1629,9 +1600,9 @@ void MixMono (int sample_count) ch->mode = MODE_GAIN; S9xSetEnvRate (ch, 0, 0); } - + break; - + case SOUND_DECREASE_LINEAR: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1639,7 +1610,7 @@ void MixMono (int sample_count) ch->xenvx -= (ENV_RANGE >> 6); // 1/64 ch->xenv_count += env_counter_max; } - + if (ch->xenvx <= 0) { S9xAPUSetEndOfSample (J, ch); @@ -1647,7 +1618,7 @@ void MixMono (int sample_count) } break; - + case SOUND_DECREASE_EXPONENTIAL: ch->xenv_count -= ch->xenv_rate; while (ch->xenv_count <= 0) @@ -1655,7 +1626,7 @@ void MixMono (int sample_count) ch->xenvx -= ((ch->xenvx - 1) >> 8) + 1; // 1 - 1/256 ch->xenv_count += env_counter_max; } - + if (ch->xenvx <= 0) { S9xAPUSetEndOfSample (J, ch); @@ -1663,7 +1634,7 @@ void MixMono (int sample_count) } break; - + case SOUND_GAIN: S9xSetEnvRate (ch, 0, 0); @@ -1678,11 +1649,11 @@ void MixMono (int sample_count) ch->nb_sample[ch->nb_index] = ch->sample; ch->nb_index = (ch->nb_index + 1) & 3; - ch->sample_pointer++; + ch->sample_pointer++; if (ch->sample_pointer == SOUND_DECODE_LENGTH) { ch->sample_pointer = 0; - + if (ch->last_block) { S9xAPUSetEndX (J); @@ -1697,7 +1668,7 @@ void MixMono (int sample_count) ch->nb_sample[ch->nb_index] = 0; ch->nb_index = (ch->nb_index + 1) & 3; } - + break; } else @@ -1707,13 +1678,13 @@ void MixMono (int sample_count) ch->block_pointer = READ_WORD(dir + 2); // loop pointer } } - + DecodeBlock (ch); } ch->sample = ch->block[ch->sample_pointer]; } - + int32 outx, d; if (ch->type == SOUND_SAMPLE) @@ -1740,28 +1711,27 @@ void MixMono (int sample_count) noise_count += env_counter_max; noise_index = (noise_index + 1) & 0xFF; } - + outx = noise_cache[noise_index] >> 16; } - + outx = ((outx * ch->xenvx) >> 11) & ~1; ch->out_sample = outx; - + if (mod2) wave[I] = outx; int32 V; - + V = (outx * ch->volume_left ) >> 7; - + MixBuffer[I] += V; ch->echo_buf_ptr[I] += V; } mono_exit: ; } - DoFakeMute=FALSE; - + if (APU.DSP[APU_NON]) SoundData.noise_count = noise_count; } @@ -1793,7 +1763,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) memset (MixBuffer, 0, sample_count * sizeof (MixBuffer[0])); if (!Settings.DisableSoundEcho) memset (EchoBuffer, 0, sample_count * sizeof (EchoBuffer[0])); - + if (so.stereo) MixStereo (sample_count); else @@ -1819,11 +1789,11 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 15] = E; E = (E * 127) >> 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -1832,10 +1802,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[J & 1] + E * SoundData.echo_volume[J & 1]) >> 7; CLIP16(I); @@ -1848,7 +1818,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 15] = E; E = E * FilterTaps[0]; E += Loop[(FIRIndex - 2) & 15] * FilterTaps[1]; @@ -1860,7 +1830,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) E += Loop[(FIRIndex - 14) & 15] * FilterTaps[7]; E >>= 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -1869,10 +1839,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[J & 1] + E * SoundData.echo_volume[J & 1]) >> 7; CLIP16(I); @@ -1889,7 +1859,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 7] = E; E = (E * 127) >> 7; FIRIndex++; @@ -1902,12 +1872,12 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[0] + - E * SoundData.echo_volume[0]) >> 7; + E * SoundData.echo_volume[0]) >> 7; CLIP16(I); ((int16 *) buffer) [J] = I; } @@ -1918,7 +1888,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 7] = E; E = E * FilterTaps[0]; E += Loop[(FIRIndex - 1) & 7] * FilterTaps[1]; @@ -1930,7 +1900,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) E += Loop[(FIRIndex - 7) & 7] * FilterTaps[7]; E >>= 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -1939,12 +1909,12 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[0] + - E * SoundData.echo_volume[0]) >> 7; + E * SoundData.echo_volume[0]) >> 7; CLIP16(I); ((int16 *) buffer) [J] = I; } @@ -1956,7 +1926,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) // 16-bit mono or stereo sound, no echo for (J = 0; J < sample_count; J++) { - I = (MixBuffer[J] * SoundData.master_volume[J & 1]) >> 7; + I = (MixBuffer[J] * SoundData.master_volume[J & 1]) >> 7; CLIP16(I); ((int16 *) buffer) [J] = I; } @@ -1993,11 +1963,11 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 15] = E; E = (E * 127) >> 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -2006,10 +1976,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[J & 1] + E * SoundData.echo_volume[J & 1]) >> 15; CLIP8(I); @@ -2022,7 +1992,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 15] = E; E = E * FilterTaps[0]; E += Loop[(FIRIndex - 2) & 15] * FilterTaps[1]; @@ -2034,7 +2004,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) E += Loop[(FIRIndex - 14) & 15] * FilterTaps[7]; E >>= 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -2043,10 +2013,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[J & 1] + E * SoundData.echo_volume[J & 1]) >> 15; CLIP8(I); @@ -2063,7 +2033,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 7] = E; E = (E * 127) >> 7; FIRIndex++; @@ -2076,10 +2046,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[0] + E * SoundData.echo_volume[0]) >> 15; CLIP8(I); @@ -2092,7 +2062,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) for (J = 0; J < sample_count; J++) { int E = Echo[SoundData.echo_ptr]; - + Loop[FIRIndex & 7] = E; E = E * FilterTaps[0]; E += Loop[(FIRIndex - 1) & 7] * FilterTaps[1]; @@ -2104,7 +2074,7 @@ void S9xMixSamples (uint8 *buffer, int sample_count) E += Loop[(FIRIndex - 7) & 7] * FilterTaps[7]; E >>= 7; FIRIndex++; - + if (SoundData.echo_write_enabled) { I = EchoBuffer[J] + ((E * SoundData.echo_feedback) >> 7); @@ -2113,10 +2083,10 @@ void S9xMixSamples (uint8 *buffer, int sample_count) } else // FIXME: Snes9x's echo buffer is not in APU_RAM Echo[SoundData.echo_ptr] = 0; - + if (++SoundData.echo_ptr >= SoundData.echo_buffer_size) SoundData.echo_ptr = 0; - + I = (MixBuffer[J] * SoundData.master_volume[0] + E * SoundData.echo_volume[0]) >> 15; CLIP8(I); @@ -2130,13 +2100,14 @@ void S9xMixSamples (uint8 *buffer, int sample_count) // 8-bit mono or stereo sound, no echo for (J = 0; J < sample_count; J++) { - I = (MixBuffer[J] * SoundData.master_volume[J & 1]) >> 15; + I = (MixBuffer[J] * SoundData.master_volume[J & 1]) >> 15; CLIP8(I); buffer[J] = I + 128; } } } } + } #ifdef __DJGPP @@ -2163,20 +2134,8 @@ void S9xResetSound (bool8 full) SoundData.channels[i].xdecay_rate = 0; SoundData.channels[i].xsustain_rate = 0; SoundData.channels[i].xsustain_level = 0; - if(full) - { - SoundData.channels[i].out_sample = 0; - SoundData.channels[i].block_pointer = 0; - SoundData.channels[i].sample_pointer = 0; - SoundData.channels[i].sample = 0; - SoundData.channels[i].sample_number = 0; - SoundData.channels[i].last_block = 0; - for(int j = 0 ; j < 2 ; j++) SoundData.channels[i].previous[j] = 0; - for(int j = 0 ; j < 2 ; j++) SoundData.channels[i].previous16[j] = 0; - for(int j = 0 ; j < 16 ; j++) SoundData.channels[i].decoded[j] = 0; - } } - + FilterTaps [0] = 127; FilterTaps [1] = 0; FilterTaps [2] = 0; @@ -2185,7 +2144,7 @@ void S9xResetSound (bool8 full) FilterTaps [5] = 0; FilterTaps [6] = 0; FilterTaps [7] = 0; - + rand_seed = 1; so.mute_sound = TRUE; @@ -2195,7 +2154,7 @@ void S9xResetSound (bool8 full) so.samples_mixed_so_far = 0; so.play_position = 0; so.err_counter = 0; - + if (full) { SoundData.echo_volume_left = 0; @@ -2213,9 +2172,9 @@ void S9xResetSound (bool8 full) memset (Loop, 0, sizeof (Loop)); memset (Echo, 0, sizeof (Echo)); } - + // At least Super Bomberman 2 requires the defaule master volume is not zero. -#if 1 +#if 1 SoundData.master_volume_left = 127; SoundData.master_volume_right = 127; SoundData.master_volume [0] = SoundData.master_volume [1] = 127; @@ -2228,7 +2187,7 @@ void S9xResetSound (bool8 full) SoundData.echo_ptr = 0; SoundData.echo_feedback = 0; SoundData.echo_buffer_size = 1; - + if (so.playback_rate) so.err_rate = (uint32) (FIXED_POINT * SNES_SCANLINE_TIME * so.playback_rate); else @@ -2239,7 +2198,7 @@ void S9xSetPlaybackRate (uint32 playback_rate) { if (playback_rate > 48000) playback_rate = 48000; - + so.playback_rate = playback_rate; so.err_rate = (uint32) (FIXED_POINT * SNES_SCANLINE_TIME * so.playback_rate); @@ -2301,7 +2260,7 @@ bool8 S9xSetSoundMode (int channel, int mode) return (TRUE); } break; - + case MODE_DECREASE_LINEAR: case MODE_DECREASE_EXPONENTIAL: case MODE_GAIN: @@ -2310,11 +2269,11 @@ bool8 S9xSetSoundMode (int channel, int mode) ch->mode = mode; if (ch->state != SOUND_SILENT) ch->state = mode; - + return (TRUE); } break; - + case MODE_INCREASE_LINEAR: case MODE_INCREASE_BENT_LINE: if (ch->mode != MODE_RELEASE) @@ -2322,11 +2281,11 @@ bool8 S9xSetSoundMode (int channel, int mode) ch->mode = mode; if (ch->state != SOUND_SILENT) ch->state = mode; - + return (TRUE); } break; - + case MODE_ADSR: if (ch->mode == MODE_NONE || ch->mode == MODE_ADSR) { @@ -2352,7 +2311,7 @@ void S9xPlaySample (int channel) ch->xenvx = 0; S9xFixEnvelope (channel, - APU.DSP[APU_GAIN + (channel << 4)], + APU.DSP[APU_GAIN + (channel << 4)], APU.DSP[APU_ADSR1 + (channel << 4)], APU.DSP[APU_ADSR2 + (channel << 4)]); @@ -2407,36 +2366,36 @@ void S9xPlaySample (int channel) ch->xenvx = 0; S9xSetEnvRate (ch, ch->xattack_rate, ENV_MAX); } - + break; #endif - + case MODE_GAIN: ch->state = SOUND_GAIN; break; - + case MODE_INCREASE_LINEAR: ch->state = SOUND_INCREASE_LINEAR; break; - + case MODE_INCREASE_BENT_LINE: ch->state = SOUND_INCREASE_BENT_LINE; break; - + case MODE_DECREASE_LINEAR: ch->state = SOUND_DECREASE_LINEAR; break; - + case MODE_DECREASE_EXPONENTIAL: ch->state = SOUND_DECREASE_EXPONENTIAL; break; - + default: break; } S9xFixEnvelope (channel, - APU.DSP[APU_GAIN + (channel << 4)], + APU.DSP[APU_GAIN + (channel << 4)], APU.DSP[APU_ADSR1 + (channel << 4)], APU.DSP[APU_ADSR2 + (channel << 4)]); } diff --git a/source/snes9x/soundux.h b/source/snes9x/soundux.h index 13570611..482429f4 100644 --- a/source/snes9x/soundux.h +++ b/source/snes9x/soundux.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _SOUND_H_ #define _SOUND_H_ @@ -249,7 +230,7 @@ typedef struct { int32 envx; // ** unused short left_vol_level; // ** unused short right_vol_level; // ** unused - short envx_target; // ** unused + short envx_target; // ** unused uint32 env_error; // ** unused uint32 erate; // ** unused int32 direction; // ** unused diff --git a/source/snes9x/spc700.cpp b/source/snes9x/spc700.cpp index abbf360b..95db72e6 100644 --- a/source/snes9x/spc700.cpp +++ b/source/snes9x/spc700.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include "snes9x.h" #include "spc700.h" #include "memmap.h" @@ -199,21 +180,24 @@ END_EXTERN_C #ifdef SPC700_SHUTDOWN #define APUShutdown() \ -if (Settings.Shutdown && (IAPU.PC == IAPU.WaitAddress1 || IAPU.PC == IAPU.WaitAddress2)) \ -{ \ + if (Settings.Shutdown && (IAPU.PC == IAPU.WaitAddress1 || IAPU.PC == IAPU.WaitAddress2)) \ + { \ if (IAPU.WaitCounter == 0) \ { \ - if (!ICPU.CPUExecuting) \ - S9xAPUExecute(); \ - else \ - IAPU.APUExecuting = FALSE; \ + if (!ICPU.CPUExecuting) \ + { \ + APU.Cycles = CPU.Cycles = CPU.NextEvent; \ + S9xUpdateAPUTimer(); \ + } \ + else \ + IAPU.APUExecuting = FALSE; \ } \ else \ if (IAPU.WaitCounter >= 2) \ - IAPU.WaitCounter = 1; \ + IAPU.WaitCounter = 1; \ else \ - IAPU.WaitCounter--; \ -} + IAPU.WaitCounter--; \ + } #else #define APUShutdown() #endif @@ -241,7 +225,6 @@ void STOP (char *s) WARN(s); APU.TimerEnabled[0] = APU.TimerEnabled[1] = APU.TimerEnabled[2] = FALSE; IAPU.APUExecuting = FALSE; - Settings.APUEnabled = FALSE; // re-enabled on next APU reset #ifdef DEBUGGER CPU.Flags |= DEBUG_MODE_FLAG; #else @@ -319,7 +302,7 @@ APUSetZN8 ((uint8) Int16); #define PushW(w)\ if(APURegisters.S==0){ \ *(IAPU.RAM + 0x1ff) = (w);\ - *(IAPU.RAM + 0x100) = ((w) >> 8);\ + *(IAPU.RAM + 0x100) = (w >> 8);\ } else { \ *(uint16 *) (IAPU.RAM + 0xff + APURegisters.S) = (w);\ } \ @@ -333,7 +316,7 @@ APUSetZN8 ((uint8) Int16); } #else #define PushW(w)\ - *(IAPU.RAM + 0x100 + APURegisters.S--) = ((w) >> 8);\ + *(IAPU.RAM + 0x100 + APURegisters.S--) = (w >> 8);\ *(IAPU.RAM + 0x100 + APURegisters.S--) = (w); #define PopW(w)\ APURegisters.S += 2;\ @@ -947,7 +930,7 @@ void Apu0E () Absolute (); Work8 = S9xAPUGetByte (IAPU.Address); S9xAPUSetByte (Work8 | APURegisters.YA.B.A, IAPU.Address); - Work8 = APURegisters.YA.B.A - Work8; + Work8 &= APURegisters.YA.B.A; APUSetZN8 (Work8); IAPU.PC += 3; } @@ -958,7 +941,7 @@ void Apu4E () Absolute (); Work8 = S9xAPUGetByte (IAPU.Address); S9xAPUSetByte (Work8 & ~APURegisters.YA.B.A, IAPU.Address); - Work8 = APURegisters.YA.B.A - Work8; + Work8 &= APURegisters.YA.B.A; APUSetZN8 (Work8); IAPU.PC += 3; } @@ -995,7 +978,6 @@ void ApuFF () APU.Flags |= HALTED_FLAG; APU.TimerEnabled[0] = APU.TimerEnabled[1] = APU.TimerEnabled[2] = FALSE; IAPU.APUExecuting = FALSE; - Settings.APUEnabled = FALSE; // re-enabled on next APU reset } void Apu10 () @@ -1561,7 +1543,7 @@ void Apu2E () // CBNE dp,rel Work8 = OP1; Relative2 (); - + if (S9xAPUGetByteZ (Work8) != APURegisters.YA.B.A) { IAPU.PC = IAPU.RAM + (uint16) Int16; diff --git a/source/snes9x/spc700.h b/source/snes9x/spc700.h index fb29bb73..2bdbe636 100644 --- a/source/snes9x/spc700.h +++ b/source/snes9x/spc700.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,11 +141,16 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _SPC700_H_ #define _SPC700_H_ +#ifdef SPCTOOL +#define NO_CHANNEL_STRUCT +#include "spctool/dsp.h" +#include "spctool/spc700.h" +#include "spctool/soundmod.h" +#endif + #define Carry 1 #define Zero 2 #define Interrupt 4 @@ -218,20 +206,54 @@ struct SAPURegisters{ EXTERN_C struct SAPURegisters APURegisters; +// Needed by ILLUSION OF GAIA +//#define ONE_APU_CYCLE 14 +#define ONE_APU_CYCLE 21 + +// Needed by all games written by the software company called Human +//#define ONE_APU_CYCLE_HUMAN 17 +#define ONE_APU_CYCLE_HUMAN 21 + +// 1.953us := 1.024065.54MHz + +#ifdef SPCTOOL +EXTERN_C int32 ESPC (int32); + +#define APU_EXECUTE() \ +{ \ + int32 l = (CPU.Cycles - APU.Cycles) / 14; \ + if (l > 0) \ + { \ + l -= _EmuSPC(l); \ + APU.Cycles += l * 14; \ + } \ +} + +#else + #ifdef DEBUGGER #define APU_EXECUTE1() \ { \ - if (APU.Flags & TRACE_FLAG) \ - S9xTraceAPU (); \ - APU.Cycles += S9xAPUCycles [*IAPU.PC]; \ - (*S9xApuOpcodes[*IAPU.PC]) (); \ + if (APU.Flags & TRACE_FLAG) \ + S9xTraceAPU ();\ + APU.Cycles += S9xAPUCycles [*IAPU.PC]; \ + (*S9xApuOpcodes[*IAPU.PC]) (); \ } #else #define APU_EXECUTE1() \ { \ - APU.Cycles += S9xAPUCycles [*IAPU.PC]; \ - (*S9xApuOpcodes[*IAPU.PC]) (); \ + APU.Cycles += S9xAPUCycles [*IAPU.PC]; \ + (*S9xApuOpcodes[*IAPU.PC]) (); \ +} +#endif + +#define APU_EXECUTE() \ +if (IAPU.APUExecuting) \ +{\ + while (APU.Cycles <= CPU.Cycles) \ + APU_EXECUTE1(); \ } #endif #endif + diff --git a/source/snes9x/spc7110.cpp b/source/snes9x/spc7110.cpp index 36b47479..45e72cf7 100644 --- a/source/snes9x/spc7110.cpp +++ b/source/snes9x/spc7110.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - //#define SPC7110_DEBUG #include "spc7110.h" @@ -171,12 +152,11 @@ //Windows includes #ifdef __WIN32__ #ifndef _XBOX // chdir and getcwd not supported on Xbox hardware -#include "win32/wsnes9x.h" // FIXME: shouldn't be necessary #include #define chdir _chdir #define getcwd _getcwd #endif -#undef PATH_MAX +#define FREEZEFOLDER GUI.FreezeFileDir //zinx suggested this, for *nix compatibility #define PATH_MAX MAX_PATH #else // Unix @@ -184,6 +164,8 @@ #include #ifdef __MACOSX__ const char * S9xGetSPC7110Directory(void); +#else +#define FREEZEFOLDER S9xGetDirectory (PATCH_DIR) #endif #endif #include "display.h" @@ -191,6 +173,7 @@ const char * S9xGetSPC7110Directory(void); #ifndef NGC extern "C" char *osd_GetPackDir(); #endif + //really not needed, but usually MS adds the _ to POSIX functions, //while *nix doesn't, so this was to "un-M$" the function. #define splitpath _splitpath @@ -206,8 +189,6 @@ void (*CleanUp7110)(void)=NULL; void (*LoadUp7110)(char*)=&SPC7110Load; void (*Copy7110)(void)=NULL; -static void SetSPC7110SRAMMap (uint8); - //size and offset of the pack data //offset and size of reads from pack typedef struct SPC7110DecompressionLocationStruct @@ -298,9 +279,9 @@ void S9xSpc7110Init() s7r.offset_add=0; s7r.AlignBy=1; - #ifndef NGC +#ifndef NGC (*LoadUp7110)(osd_GetPackDir()); - #endif +#endif if(Settings.SPC7110RTC) Settings.TurboMode=false; @@ -320,26 +301,26 @@ void MovePackData() log->used_len=s7r.bank50Internal; log->used_offset=decompack->last_offset; } - + //set up for next logging decompack->last_offset=(s7r.reg4805)|(s7r.reg4806<<8); - + decompack->last_idx=s7r.reg4804; //start decompression int table=(s7r.reg4803<<16)|(s7r.reg4802<<8)|s7r.reg4801; - + //the table is a offset multiplier byte and a big-endian pointer int j= 4*s7r.reg4804; j+=s7r.DataRomOffset; j+=table; - + //set proper offsetting. if(s7r.reg480B==0) s7r.AlignBy=0; else { - switch(Memory.ROM[j]) + switch(ROM[j]) { case 0x03: s7r.AlignBy=8; @@ -404,7 +385,7 @@ void ReadPackData() static int table_age_3; static int table_age_4; static int table_age_5; - + int table=(s7r.reg4803<<16)|(s7r.reg4802<<8)|s7r.reg4801; if(table==0) @@ -421,20 +402,20 @@ void ReadPackData() log->used_len=s7r.bank50Internal; log->used_offset=decompack->last_offset; } - + decompack->last_offset=(s7r.reg4805)|(s7r.reg4806<<8); - + decompack->last_idx=s7r.reg4804; - + int j= 4*s7r.reg4804; j+=s7r.DataRomOffset; j+=table; - + if(s7r.reg480B==0) s7r.AlignBy=0; else { - switch(Memory.ROM[j]) + switch(ROM[j]) { case 0x03: s7r.AlignBy=8; @@ -480,10 +461,10 @@ void ReadPackData() table_age_4=table_age_3; table_age_3=table_age_2; table_age_2=decompack->idx; - + #ifdef __MACOSX__ char name[PATH_MAX + 1], bfname[11]; - strcpy(name, S9xGetSPC7110Directory()); + strcpy(name, S9xGetSPC7110Directory()); sprintf(bfname, "%06X.bin", table); strcat(name, bfname); #else @@ -493,11 +474,10 @@ void ReadPackData() char dir [_MAX_DIR + 1]; char fname [_MAX_FNAME + 1]; char ext [_MAX_EXT + 1]; - const char* patchDir = S9xGetDirectory (PATCH_DIR); - if (patchDir && strlen (patchDir)) + if (strlen (FREEZEFOLDER)) { //splitpath (Memory.ROMFilename, drive, dir, fname, ext); - strcpy (name, patchDir); + strcpy (name, FREEZEFOLDER); strcat (name, "/"); } else @@ -563,21 +543,21 @@ void GetPackData() log->used_len=s7r.bank50Internal; log->used_offset=decompack->last_offset; } - + decompack->last_offset=(s7r.reg4805)|(s7r.reg4806<<8); - + decompack->last_idx=s7r.reg4804; int table=(s7r.reg4803<<16)|(s7r.reg4802<<8)|s7r.reg4801; - + int j= 4*s7r.reg4804; j+=s7r.DataRomOffset; j+=table; - + if(s7r.reg480B==0) s7r.AlignBy=0; else { - switch(Memory.ROM[j]) + switch(ROM[j]) { case 0x03: s7r.AlignBy=8; @@ -661,7 +641,7 @@ uint8 S9xGetSPC7110(uint16 Address) i+=s7r.bank50Internal; i%=DECOMP_BUFFER_SIZE; s7r.reg4800=s7r.bank50[i]; - + s7r.bank50Internal++; s7r.bank50Internal%=DECOMP_BUFFER_SIZE; #ifdef SPC7110_DEBUG @@ -698,10 +678,10 @@ uint8 S9xGetSPC7110(uint16 Address) case 0x480B: return s7r.reg480B; //decompression finished: just emulated by switching each read. - case 0x480C: + case 0x480C: s7r.reg480C^=0x80; return s7r.reg480C^0x80; - + //Data access port //reads from the data ROM (anywhere over the first 8 mbits //behavior is complex, will document later, @@ -734,13 +714,13 @@ uint8 S9xGetSPC7110(uint16 Address) else r4814=0; s7r.reg4815=(uint8)(r4814>>8); s7r.reg4814=(uint8)(r4814&0x00FF); - + } } i+=s7r.DataRomOffset; - uint8 tmp=Memory.ROM[i]; + uint8 tmp=ROM[i]; i=(s7r.reg4813<<16)|(s7r.reg4812<<8)|s7r.reg4811; - + if(s7r.reg4818&0x02) { } @@ -750,7 +730,7 @@ uint8 S9xGetSPC7110(uint16 Address) { signed short inc; inc=(s7r.reg4817<<8)|s7r.reg4816; - + if(!(s7r.reg4818&0x10)) i+=inc; else @@ -770,7 +750,7 @@ uint8 S9xGetSPC7110(uint16 Address) r4814+=inc; s7r.reg4815=(r4814&0xFF00)>>8; s7r.reg4814=r4814&0xFF; - + } } //is signed @@ -798,7 +778,7 @@ uint8 S9xGetSPC7110(uint16 Address) r4814+=inc; s7r.reg4815=(r4814&0xFF00)>>8; s7r.reg4814=r4814&0xFF; - + } } } @@ -824,15 +804,15 @@ uint8 S9xGetSPC7110(uint16 Address) r4814+=1; s7r.reg4815=(r4814&0xFF00)>>8; s7r.reg4814=r4814&0xFF; - + } } } - + #ifdef SPC7110_DEBUG printf("Returned %02X\n", tmp); #endif - + i%=s7r.DataRomSize; s7r.reg4811=i&0x00FF; s7r.reg4812=(i&0x00FF00)>>8; @@ -877,15 +857,15 @@ uint8 S9xGetSPC7110(uint16 Address) adj=(s7r.reg4815<<8)|s7r.reg4814; i+=adj; } - + i%=s7r.DataRomSize; i+=s7r.DataRomOffset; - uint8 tmp=Memory.ROM[i]; + uint8 tmp=ROM[i]; i=((s7r.reg4813<<16)|(s7r.reg4812<<8)|s7r.reg4811); if(0x60==(s7r.reg4818&0x60)) { i=((s7r.reg4813<<16)|(s7r.reg4812<<8)|s7r.reg4811); - + if(!(s7r.reg4818&0x10)) { if(s7r.reg4818&0x08) @@ -931,7 +911,7 @@ uint8 S9xGetSPC7110(uint16 Address) return tmp; } else return 0; - + //multiplicand low or dividend lowest case 0x4820: return s7r.reg4820; //multiplicand high or divdend lower @@ -948,7 +928,7 @@ uint8 S9xGetSPC7110(uint16 Address) case 0x4826: return s7r.reg4826; //divisor high case 0x4827: return s7r.reg4827; - + //result lowest case 0x4828: return s7r.reg4828; @@ -1090,16 +1070,16 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) { s7r.reg480B=data; int table=(s7r.reg4803<<16)|(s7r.reg4802<<8)|s7r.reg4801; - + int j= 4*s7r.reg4804; j+=s7r.DataRomOffset; j+=table; - + if(s7r.reg480B==0) s7r.AlignBy=0; else { - switch(Memory.ROM[j]) + switch(ROM[j]) { case 0x03: s7r.AlignBy=8; @@ -1199,13 +1179,13 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) s7r.reg4813=((i&0xFF0000)>>16); } } - + } } - + s7r.written|=0x08; break; - + //data port adjust high (has a funky immediate increment mode) case 0x4815: s7r.reg4815=data; @@ -1222,7 +1202,7 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) else { uint32 i=(s7r.reg4813<<16)|(s7r.reg4812<<8)|s7r.reg4811; - + if(s7r.reg4818&0x08) { i+=(signed char)s7r.reg4814; @@ -1317,7 +1297,7 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) int mul; short m1=(short)((s7r.reg4824)|(s7r.reg4825<<8)); short m2=(short)((s7r.reg4820)|(s7r.reg4821<<8)); - + mul=m1*m2; s7r.reg4828=(uint8)(mul&0x000000FF); s7r.reg4829=(uint8)((mul&0x0000FF00)>>8); @@ -1329,7 +1309,7 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) uint32 mul; uint16 m1=(uint16)((s7r.reg4824)|(s7r.reg4825<<8)); uint16 m2=(uint16)((s7r.reg4820)|(s7r.reg4821<<8)); - + mul=m1*m2; s7r.reg4828=(uint8)(mul&0x000000FF); s7r.reg4829=(uint8)((mul&0x0000FF00)>>8); @@ -1406,7 +1386,7 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) //SRAM toggle case 0x4830: - SetSPC7110SRAMMap(data); + Memory.SPC7110Sram(data); s7r.reg4830=data; break; //Bank DX mapping @@ -1459,7 +1439,7 @@ void S9xSetSPC7110 (uint8 data, uint16 Address) } else { - + if(0x0D==rtc_f9.index) { if(data&0x08) @@ -1550,7 +1530,7 @@ uint8 S9xGetSPC7110Byte(uint32 Address) } i+=Address&0x000FFFFF; i+=s7r.DataRomOffset; - return Memory.ROM[i]; + return ROM[i]; } } /**********************************************************************************************/ @@ -1561,7 +1541,7 @@ uint8 S9xGetSPC7110Byte(uint32 Address) int S9xRTCDaysInMonth( int month, int year ) { int mdays; - + switch ( month ) { case 2: @@ -1570,19 +1550,19 @@ int S9xRTCDaysInMonth( int month, int year ) else mdays = 28; break; - + case 4: case 6: case 9: case 11: mdays = 30; break; - + default: // months 1,3,5,7,8,10,12 mdays = 31; break; } - + return mdays; } @@ -1601,22 +1581,22 @@ void S9xUpdateRTC () { time_t cur_systime; long time_diff; - + // Keep track of game time by computing the number of seconds that pass on the system // clock and adding the same number of seconds to the RTC clock structure. - + if (rtc_f9.init && 0==(rtc_f9.reg[0x0D]&0x01) && 0==(rtc_f9.reg[0x0F]&0x03)) { cur_systime = time (NULL); - + // This method assumes one time_t clock tick is one second // which should work on PCs and GNU systems. // If your tick interval is different adjust the // DAYTICK, HOURTICK, and MINUTETICK defines - + time_diff = (long) (cur_systime - rtc_f9.last_used); rtc_f9.last_used = cur_systime; - + if ( time_diff > 0 ) { int seconds; @@ -1626,12 +1606,12 @@ void S9xUpdateRTC () int month; int year; int temp_days; - + int year_hundreds; int year_tens; int year_ones; - - + + if ( time_diff > DAYTICKS ) { days = time_diff / DAYTICKS; @@ -1641,7 +1621,7 @@ void S9xUpdateRTC () { days = 0; } - + if ( time_diff > HOURTICKS ) { hours = time_diff / HOURTICKS; @@ -1651,7 +1631,7 @@ void S9xUpdateRTC () { hours = 0; } - + if ( time_diff > MINUTETICKS ) { minutes = time_diff / MINUTETICKS; @@ -1661,7 +1641,7 @@ void S9xUpdateRTC () { minutes = 0; } - + if ( time_diff > 0 ) { seconds = time_diff; @@ -1670,29 +1650,29 @@ void S9xUpdateRTC () { seconds = 0; } - - + + seconds += (rtc_f9.reg[1]*10 + rtc_f9.reg[0]); if ( seconds >= 60 ) { seconds -= 60; minutes += 1; } - + minutes += (rtc_f9.reg[3]*10 + rtc_f9.reg[2]); if ( minutes >= 60 ) { minutes -= 60; hours += 1; } - + hours += (rtc_f9.reg[5]*10 + rtc_f9.reg[4]); if ( hours >= 24 ) { hours -= 24; days += 1; } - + year = rtc_f9.reg[11]*10 + rtc_f9.reg[10]; year += ( 1900 ); month = rtc_f9.reg[8]+10*rtc_f9.reg[9]; @@ -1716,7 +1696,7 @@ void S9xUpdateRTC () year_ones = year_tens % 10; year_tens /= 10; year_hundreds = (year - 1000) / 100; - + rtc_f9.reg[0] = seconds % 10; rtc_f9.reg[1] = seconds / 10; rtc_f9.reg[2] = minutes % 10; @@ -1754,7 +1734,7 @@ uint8* Get7110BasePtr(uint32 Address) default:i=0; } i+=Address&0x000F0000; - return &Memory.ROM[i]; + return &ROM[i]; } //end extern } @@ -1793,7 +1773,7 @@ bool Load7110Index(char* filename) decompack->tableEnts[i].location[index].size=size; decompack->tableEnts[i].location[index].used_len=0; decompack->tableEnts[i].location[index].used_offset=0; - + } while(!feof(fp)); fclose(fp); @@ -1804,6 +1784,7 @@ bool Load7110Index(char* filename) //Cache 1 load function void SPC7110Load(char* dirname) { +#ifndef NGC char temp_path[PATH_MAX]; int i=0; @@ -1814,13 +1795,15 @@ void SPC7110Load(char* dirname) #endif ZeroMemory(decompack, sizeof(Pack7110)); - -#ifndef _XBOX + +#ifndef _XBOX +#ifndef NGC if(-1==chdir(dirname)) { S9xMessage(0,0,"Graphics Pack not found!"); } #endif +#endif #ifndef _XBOX Load7110Index("index.bin"); @@ -1840,8 +1823,11 @@ void SPC7110Load(char* dirname) sprintf(binname,"%s%06X.bin",filename,decompack->tableEnts[i].table); #endif struct stat buf; + +#ifndef NGC if(-1!=stat(binname, &buf)) decompack->binfiles[i]=new uint8[buf.st_size]; +#endif FILE* fp=fopen(binname, "rb"); if(fp) { @@ -1851,8 +1837,10 @@ void SPC7110Load(char* dirname) } } -#ifndef _XBOX +#ifndef _XBOX +#ifndef NGC chdir(temp_path); +#endif #endif Copy7110=&MovePackData; @@ -1877,7 +1865,7 @@ void SPC7110Open(char* dirname) #endif ZeroMemory(decompack, sizeof(Pack7110)); - + #ifndef _XBOX if(-1==chdir(dirname)) { @@ -1927,7 +1915,7 @@ void SPC7110Grab(char* dirname) ZeroMemory(decompack, sizeof(Pack7110)); #ifndef _XBOX - + if(-1==chdir(dirname)) { S9xMessage(0,0,"Graphics Pack not found!"); @@ -1953,6 +1941,8 @@ void SPC7110Grab(char* dirname) #endif struct stat buf; //add load/no load calculations here + +#ifndef NGC if(-1!=stat(binname, &buf)) { if(buf.st_sizetableEnts[j].location[k].used_len&0xFF; - fwrite(&ent_temp,1,1,flog);//lsb of + fwrite(&ent_temp,1,1,flog);//lsb of ent_temp=(decompack->tableEnts[j].location[k].used_len>>8)&0xFF; fwrite(&ent_temp,1,1,flog);//msb of ent_temp=(decompack->tableEnts[j].location[k].used_offset)&0xFF; @@ -2354,25 +2349,6 @@ void Do7110Logging() } } } - -static void SetSPC7110SRAMMap (uint8 newstate) -{ - if (newstate & 0x80) - { - Memory.Map[0x006] = (uint8 *) Memory.MAP_HIROM_SRAM; - Memory.Map[0x007] = (uint8 *) Memory.MAP_HIROM_SRAM; - Memory.Map[0x306] = (uint8 *) Memory.MAP_HIROM_SRAM; - Memory.Map[0x307] = (uint8 *) Memory.MAP_HIROM_SRAM; - } - else - { - Memory.Map[0x006] = (uint8 *) Memory.MAP_RONLY_SRAM; - Memory.Map[0x007] = (uint8 *) Memory.MAP_RONLY_SRAM; - Memory.Map[0x306] = (uint8 *) Memory.MAP_RONLY_SRAM; - Memory.Map[0x307] = (uint8 *) Memory.MAP_RONLY_SRAM; - } -} - bool8 S9xSaveSPC7110RTC (S7RTC *rtc_f9) { FILE* fp; @@ -2420,7 +2396,7 @@ bool8 S9xLoadSPC7110RTC (S7RTC *rtc_f9) rtc_f9->index|=(temp<<8); fread(&rtc_f9->control,1,1,fp); fread(&rtc_f9->init,1,1,fp); - + fread(&temp,1,1,fp); rtc_f9->last_used=temp; fread(&temp,1,1,fp); diff --git a/source/snes9x/spc7110.h b/source/snes9x/spc7110.h index 7d12b78f..2db39d4a 100644 --- a/source/snes9x/spc7110.h +++ b/source/snes9x/spc7110.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _spc7110_h #define _spc7110_h #include "port.h" diff --git a/source/snes9x/srtc.cpp b/source/snes9x/srtc.cpp index 9dd76e47..319de1c8 100644 --- a/source/snes9x/srtc.cpp +++ b/source/snes9x/srtc.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include "snes9x.h" #include "srtc.h" @@ -210,7 +191,7 @@ static int month_keys[12] = { 1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6 }; * * restore the rtc data structure * rtc.system_timestamp = time (NULL); - * + * * *********************************************************************************************/ @@ -328,7 +309,7 @@ void S9xUpdateSrtcTime () time_diff = (long) (cur_systime - rtc.system_timestamp); rtc.system_timestamp = cur_systime; - + if ( time_diff > 0 ) { int seconds; @@ -597,23 +578,25 @@ void S9xSRTCPreSaveState () if (s > 0x20000) s = 0x20000; - Memory.SRAM [s + 0] = rtc.needs_init; - Memory.SRAM [s + 1] = rtc.count_enable; - memmove (&Memory.SRAM [s + 2], rtc.data, MAX_RTC_INDEX + 1); - Memory.SRAM [s + 3 + MAX_RTC_INDEX] = rtc.index; - Memory.SRAM [s + 4 + MAX_RTC_INDEX] = rtc.mode; + SRAM [s + 0] = rtc.needs_init; + SRAM [s + 1] = rtc.count_enable; + memmove (&SRAM [s + 2], rtc.data, MAX_RTC_INDEX + 1); + SRAM [s + 3 + MAX_RTC_INDEX] = rtc.index; + SRAM [s + 4 + MAX_RTC_INDEX] = rtc.mode; #ifdef LSB_FIRST - memmove (&Memory.SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8); + memmove (&SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8); #else - Memory.SRAM [s + 5 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 0); - Memory.SRAM [s + 6 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 8); - Memory.SRAM [s + 7 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 16); - Memory.SRAM [s + 8 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 24); - Memory.SRAM [s + 9 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 32); - Memory.SRAM [s + 10 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 40); - Memory.SRAM [s + 11 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 48); - Memory.SRAM [s + 12 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 56); +#ifndef NGC + SRAM [s + 5 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 0); + SRAM [s + 6 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 8); + SRAM [s + 7 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 16); + SRAM [s + 8 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 24); + SRAM [s + 9 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 32); + SRAM [s + 10 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 40); + SRAM [s + 11 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 48); + SRAM [s + 12 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 56); +#endif #endif } } @@ -627,23 +610,25 @@ void S9xSRTCPostLoadState () if (s > 0x20000) s = 0x20000; - rtc.needs_init = Memory.SRAM [s + 0]; - rtc.count_enable = Memory.SRAM [s + 1]; - memmove (rtc.data, &Memory.SRAM [s + 2], MAX_RTC_INDEX + 1); - rtc.index = Memory.SRAM [s + 3 + MAX_RTC_INDEX]; - rtc.mode = Memory.SRAM [s + 4 + MAX_RTC_INDEX]; + rtc.needs_init = SRAM [s + 0]; + rtc.count_enable = SRAM [s + 1]; + memmove (rtc.data, &SRAM [s + 2], MAX_RTC_INDEX + 1); + rtc.index = SRAM [s + 3 + MAX_RTC_INDEX]; + rtc.mode = SRAM [s + 4 + MAX_RTC_INDEX]; #ifdef LSB_FIRST - memmove (&rtc.system_timestamp, &Memory.SRAM [s + 5 + MAX_RTC_INDEX], 8); + memmove (&rtc.system_timestamp, &SRAM [s + 5 + MAX_RTC_INDEX], 8); #else - rtc.system_timestamp |= (Memory.SRAM [s + 5 + MAX_RTC_INDEX] << 0); - rtc.system_timestamp |= (Memory.SRAM [s + 6 + MAX_RTC_INDEX] << 8); - rtc.system_timestamp |= (Memory.SRAM [s + 7 + MAX_RTC_INDEX] << 16); - rtc.system_timestamp |= (Memory.SRAM [s + 8 + MAX_RTC_INDEX] << 24); - rtc.system_timestamp |= (Memory.SRAM [s + 9 + MAX_RTC_INDEX] << 32); - rtc.system_timestamp |= (Memory.SRAM [s + 10 + MAX_RTC_INDEX] << 40); - rtc.system_timestamp |= (Memory.SRAM [s + 11 + MAX_RTC_INDEX] << 48); - rtc.system_timestamp |= (Memory.SRAM [s + 12 + MAX_RTC_INDEX] << 56); +#ifndef NGC + rtc.system_timestamp |= (SRAM [s + 5 + MAX_RTC_INDEX] << 0); + rtc.system_timestamp |= (SRAM [s + 6 + MAX_RTC_INDEX] << 8); + rtc.system_timestamp |= (SRAM [s + 7 + MAX_RTC_INDEX] << 16); + rtc.system_timestamp |= (SRAM [s + 8 + MAX_RTC_INDEX] << 24); + rtc.system_timestamp |= (SRAM [s + 9 + MAX_RTC_INDEX] << 32); + rtc.system_timestamp |= (SRAM [s + 10 + MAX_RTC_INDEX] << 40); + rtc.system_timestamp |= (SRAM [s + 11 + MAX_RTC_INDEX] << 48); + rtc.system_timestamp |= (SRAM [s + 12 + MAX_RTC_INDEX] << 56); +#endif #endif S9xUpdateSrtcTime (); } diff --git a/source/snes9x/srtc.h b/source/snes9x/srtc.h index 895e233a..f626779b 100644 --- a/source/snes9x/srtc.h +++ b/source/snes9x/srtc.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _srtc_h_ #define _srtc_h_ diff --git a/source/snes9x/tile.cpp b/source/snes9x/tile.cpp index 71f3c21c..b91e1d68 100644 --- a/source/snes9x/tile.cpp +++ b/source/snes9x/tile.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - // This file includes itself multiple times. The other option would be to have // 4 files, where A includes B, and B includes C 3 times, and C includes D 5 // times. Look for the following marker to find where the divisions are. diff --git a/source/snes9x/tile.h b/source/snes9x/tile.h index 8b6d20cd..0f351413 100644 --- a/source/snes9x/tile.h +++ b/source/snes9x/tile.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _TILE_H_ #define _TILE_H_ diff --git a/source/snes9x/unused/2xsai.cpp b/source/snes9x/unused/2xsai.cpp deleted file mode 100644 index e966605e..00000000 --- a/source/snes9x/unused/2xsai.cpp +++ /dev/null @@ -1,1305 +0,0 @@ -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - - -#ifdef __DJGPP -#include -#endif - -#include "snes9x.h" -#include "port.h" -#include "gfx.h" - -#if (defined(USE_X86_ASM) && (defined (__i386__) || defined (__i486__) || \ - defined (__i586__) || defined (__WIN32__) || defined (__DJGPP))) -# ifndef MMX -# define MMX -# endif -#endif - -extern "C" -{ - -#ifdef MMX - void _2xSaILine (uint8 *srcPtr, uint8 *deltaPtr, uint32 srcPitch, - uint32 width, uint8 *dstPtr, uint32 dstPitch); - void _2xSaISuperEagleLine (uint8 *srcPtr, uint8 *deltaPtr, - uint32 srcPitch, uint32 width, - uint8 *dstPtr, uint32 dstPitch); - void _2xSaISuper2xSaILine (uint8 *srcPtr, uint8 *deltaPtr, - uint32 srcPitch, uint32 width, - uint8 *dstPtr, uint32 dstPitch); - void Init_2xSaIMMX (uint32 BitFormat); - void BilinearMMX (uint16 * A, uint16 * B, uint16 * C, uint16 * D, - uint16 * dx, uint16 * dy, uint8 *dP); - void BilinearMMXGrid0 (uint16 * A, uint16 * B, uint16 * C, uint16 * D, - uint16 * dx, uint16 * dy, uint8 *dP); - void BilinearMMXGrid1 (uint16 * A, uint16 * B, uint16 * C, uint16 * D, - uint16 * dx, uint16 * dy, uint8 *dP); - void EndMMX (); - -#endif -} - -bool8 cpu_mmx = 1; - -static uint32 colorMask = 0xF7DEF7DE; -static uint32 lowPixelMask = 0x08210821; -static uint32 qcolorMask = 0xE79CE79C; -static uint32 qlowpixelMask = 0x18631863; -static uint32 redblueMask = 0xF81F; -static uint32 greenMask = 0x7E0; - -int Init_2xSaI (uint32 BitFormat) -{ - if (BitFormat == 565) - { - colorMask = 0xF7DEF7DE; - lowPixelMask = 0x08210821; - qcolorMask = 0xE79CE79C; - qlowpixelMask = 0x18631863; - redblueMask = 0xF81F; - greenMask = 0x7E0; - } - else if (BitFormat == 555) - { - colorMask = 0x7BDE7BDE; - lowPixelMask = 0x04210421; - qcolorMask = 0x739C739C; - qlowpixelMask = 0x0C630C63; - redblueMask = 0x7C1F; - greenMask = 0x3E0; - } - else - { - return 0; - } - -#ifdef MMX - Init_2xSaIMMX (BitFormat); -#endif - - return 1; -} - -static inline int GetResult1 (uint32 A, uint32 B, uint32 C, uint32 D, - uint32 /* E */) -{ - int x = 0; - int y = 0; - int r = 0; - - if (A == C) - x += 1; - else if (B == C) - y += 1; - if (A == D) - x += 1; - else if (B == D) - y += 1; - if (x <= 1) - r += 1; - if (y <= 1) - r -= 1; - return r; -} - -static inline int GetResult2 (uint32 A, uint32 B, uint32 C, uint32 D, - uint32 /* E */) -{ - int x = 0; - int y = 0; - int r = 0; - - if (A == C) - x += 1; - else if (B == C) - y += 1; - if (A == D) - x += 1; - else if (B == D) - y += 1; - if (x <= 1) - r -= 1; - if (y <= 1) - r += 1; - return r; -} - -static inline int GetResult (uint32 A, uint32 B, uint32 C, uint32 D) -{ - int x = 0; - int y = 0; - int r = 0; - - if (A == C) - x += 1; - else if (B == C) - y += 1; - if (A == D) - x += 1; - else if (B == D) - y += 1; - if (x <= 1) - r += 1; - if (y <= 1) - r -= 1; - return r; -} - -static inline uint32 INTERPOLATE (uint32 A, uint32 B) -{ - if (A != B) - { - return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + - (A & B & lowPixelMask)); - } - else - return A; -} - -static inline uint32 Q_INTERPOLATE (uint32 A, uint32 B, uint32 C, uint32 D) -{ - register uint32 x = ((A & qcolorMask) >> 2) + - ((B & qcolorMask) >> 2) + - ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2); - register uint32 y = (A & qlowpixelMask) + - (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask); - - y = (y >> 2) & qlowpixelMask; - return x + y; -} - -#define BLUE_MASK565 0x001F001F -#define RED_MASK565 0xF800F800 -#define GREEN_MASK565 0x07E007E0 - -#define BLUE_MASK555 0x001F001F -#define RED_MASK555 0x7C007C00 -#define GREEN_MASK555 0x03E003E0 - -void Super2xSaI (uint8 *srcPtr, uint32 srcPitch, - uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, - int width, int height) -{ - uint16 *bP; - uint8 *dP; - uint32 inc_bP; - -#ifdef MMX - if (cpu_mmx) - { - while (height--) - { - _2xSaISuper2xSaILine (srcPtr, deltaPtr, srcPitch, width, - dstPtr, dstPitch); - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } - } - else -#endif - - { - uint32 Nextline = srcPitch >> 1; - inc_bP = 1; - - while (height--) - { - bP = (uint16 *) srcPtr; - dP = (uint8 *) dstPtr; - - for (uint32 finish = width; finish; finish -= inc_bP) - { - uint32 color4, color5, color6; - uint32 color1, color2, color3; - uint32 colorA0, colorA1, colorA2, colorA3, - colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; - uint32 product1a, product1b, product2a, product2b; - -//--------------------------------------- B1 B2 -// 4 5 6 S2 -// 1 2 3 S1 -// A1 A2 - - colorB0 = *(bP - Nextline - 1); - colorB1 = *(bP - Nextline); - colorB2 = *(bP - Nextline + 1); - colorB3 = *(bP - Nextline + 2); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA0 = *(bP + Nextline + Nextline - 1); - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - colorA3 = *(bP + Nextline + Nextline + 2); - -//-------------------------------------- - if (color2 == color6 && color5 != color3) - { - product2b = product1b = color2; - } - else if (color5 == color3 && color2 != color6) - { - product2b = product1b = color5; - } - else if (color5 == color3 && color2 == color6) - { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) - product2b = product1b = color6; - else if (r < 0) - product2b = product1b = color5; - else - { - product2b = product1b = INTERPOLATE (color5, color6); - } - } - else - { - if (color6 == color3 && color3 == colorA1 - && color2 != colorA2 && color3 != colorA0) - product2b = - Q_INTERPOLATE (color3, color3, color3, color2); - else if (color5 == color2 && color2 == colorA2 - && colorA1 != color3 && color2 != colorA3) - product2b = - Q_INTERPOLATE (color2, color2, color2, color3); - else - product2b = INTERPOLATE (color2, color3); - - if (color6 == color3 && color6 == colorB1 - && color5 != colorB2 && color6 != colorB0) - product1b = - Q_INTERPOLATE (color6, color6, color6, color5); - else if (color5 == color2 && color5 == colorB2 - && colorB1 != color6 && color5 != colorB3) - product1b = - Q_INTERPOLATE (color6, color5, color5, color5); - else - product1b = INTERPOLATE (color5, color6); - } - - if (color5 == color3 && color2 != color6 && color4 == color5 - && color5 != colorA2) - product2a = INTERPOLATE (color2, color5); - else - if (color5 == color1 && color6 == color5 - && color4 != color2 && color5 != colorA0) - product2a = INTERPOLATE (color2, color5); - else - product2a = color2; - - if (color2 == color6 && color5 != color3 && color1 == color2 - && color2 != colorB2) - product1a = INTERPOLATE (color2, color5); - else - if (color4 == color2 && color3 == color2 - && color1 != color5 && color2 != colorB0) - product1a = INTERPOLATE (color2, color5); - else - product1a = color5; - -#ifdef MSB_FIRST - product1a = product1b | (product1a << 16); - product2a = product2b | (product2a << 16); -#else - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); -#endif - - *((uint32 *) dP) = product1a; - *((uint32 *) (dP + dstPitch)) = product2a; - - bP += inc_bP; - dP += sizeof (uint32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } // while (height--) - } -} - -void SuperEagle (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height) -{ - uint8 *dP; - uint16 *bP; - uint16 *xP; - uint32 inc_bP; - -#ifdef MMX - if (cpu_mmx) - { - while (height--) - { - _2xSaISuperEagleLine (srcPtr, deltaPtr, srcPitch, width, - dstPtr, dstPitch); - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } - } - else -#endif - - { - inc_bP = 1; - - uint32 Nextline = srcPitch >> 1; - - while (height--) - { - bP = (uint16 *) srcPtr; - xP = (uint16 *) deltaPtr; - dP = dstPtr; - for (uint32 finish = width; finish; finish -= inc_bP) - { - uint32 color4, color5, color6; - uint32 color1, color2, color3; - uint32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; - uint32 product1a, product1b, product2a, product2b; - - colorB1 = *(bP - Nextline); - colorB2 = *(bP - Nextline + 1); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - - // -------------------------------------- - if (color2 == color6 && color5 != color3) - { - product1b = product2a = color2; - if ((color1 == color2) || (color6 == colorB2)) - { - product1a = INTERPOLATE (color2, color5); - product1a = INTERPOLATE (color2, product1a); -// product1a = color2; - } - else - { - product1a = INTERPOLATE (color5, color6); - } - - if ((color6 == colorS2) || (color2 == colorA1)) - { - product2b = INTERPOLATE (color2, color3); - product2b = INTERPOLATE (color2, product2b); -// product2b = color2; - } - else - { - product2b = INTERPOLATE (color2, color3); - } - } - else if (color5 == color3 && color2 != color6) - { - product2b = product1a = color5; - - if ((colorB1 == color5) || (color3 == colorS1)) - { - product1b = INTERPOLATE (color5, color6); - product1b = INTERPOLATE (color5, product1b); -// product1b = color5; - } - else - { - product1b = INTERPOLATE (color5, color6); - } - - if ((color3 == colorA2) || (color4 == color5)) - { - product2a = INTERPOLATE (color5, color2); - product2a = INTERPOLATE (color5, product2a); -// product2a = color5; - } - else - { - product2a = INTERPOLATE (color2, color3); - } - - } - else if (color5 == color3 && color2 == color6) - { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) - { - product1b = product2a = color2; - product1a = product2b = INTERPOLATE (color5, color6); - } - else if (r < 0) - { - product2b = product1a = color5; - product1b = product2a = INTERPOLATE (color5, color6); - } - else - { - product2b = product1a = color5; - product1b = product2a = color2; - } - } - else - { - product2b = product1a = INTERPOLATE (color2, color6); - product2b = - Q_INTERPOLATE (color3, color3, color3, product2b); - product1a = - Q_INTERPOLATE (color5, color5, color5, product1a); - - product2a = product1b = INTERPOLATE (color5, color3); - product2a = - Q_INTERPOLATE (color2, color2, color2, product2a); - product1b = - Q_INTERPOLATE (color6, color6, color6, product1b); - -// product1a = color5; -// product1b = color6; -// product2a = color2; -// product2b = color3; - } -#ifdef MSB_FIRST - product1a = product1b | (product1a << 16); - product2a = product2b | (product2a << 16); -#else - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); -#endif - - *((uint32 *) dP) = product1a; - *((uint32 *) (dP + dstPitch)) = product2a; - *xP = color5; - - bP += inc_bP; - xP += inc_bP; - dP += sizeof (uint32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } // endof: while (height--) - } -} - -void _2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height) -{ - uint8 *dP; - uint16 *bP; - uint32 inc_bP; - -#ifdef MMX - if (cpu_mmx) - { - while (height--) - { - _2xSaILine (srcPtr, deltaPtr, srcPitch, width, dstPtr, dstPitch); - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } - } - else -#endif - - { - inc_bP = 1; - - uint32 Nextline = srcPitch >> 1; - - while (height--) - { - bP = (uint16 *) srcPtr; - dP = dstPtr; - - for (uint32 finish = width; finish; finish -= inc_bP) - { - - register uint32 colorA, colorB; - uint32 colorC, colorD, - colorE, colorF, colorG, colorH, - colorI, colorJ, colorK, colorL, - - colorM, colorN, colorO, colorP; - uint32 product, product1, product2; - -//--------------------------------------- -// Map of the pixels: I|E F|J -// G|A B|K -// H|C D|L -// M|N O|P - colorI = *(bP - Nextline - 1); - colorE = *(bP - Nextline); - colorF = *(bP - Nextline + 1); - colorJ = *(bP - Nextline + 2); - - colorG = *(bP - 1); - colorA = *(bP); - colorB = *(bP + 1); - colorK = *(bP + 2); - - colorH = *(bP + Nextline - 1); - colorC = *(bP + Nextline); - colorD = *(bP + Nextline + 1); - colorL = *(bP + Nextline + 2); - - colorM = *(bP + Nextline + Nextline - 1); - colorN = *(bP + Nextline + Nextline); - colorO = *(bP + Nextline + Nextline + 1); - colorP = *(bP + Nextline + Nextline + 2); - - if ((colorA == colorD) && (colorB != colorC)) - { - if (((colorA == colorE) && (colorB == colorL)) || - ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ))) - { - product = colorA; - } - else - { - product = INTERPOLATE (colorA, colorB); - } - - if (((colorA == colorG) && (colorC == colorO)) || - ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM))) - { - product1 = colorA; - } - else - { - product1 = INTERPOLATE (colorA, colorC); - } - product2 = colorA; - } - else if ((colorB == colorC) && (colorA != colorD)) - { - if (((colorB == colorF) && (colorA == colorH)) || - ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI))) - { - product = colorB; - } - else - { - product = INTERPOLATE (colorA, colorB); - } - - if (((colorC == colorH) && (colorA == colorF)) || - ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI))) - { - product1 = colorC; - } - else - { - product1 = INTERPOLATE (colorA, colorC); - } - product2 = colorB; - } - else if ((colorA == colorD) && (colorB == colorC)) - { - if (colorA == colorB) - { - product = colorA; - product1 = colorA; - product2 = colorA; - } - else - { - register int r = 0; - - product1 = INTERPOLATE (colorA, colorC); - product = INTERPOLATE (colorA, colorB); - - r += - GetResult1 (colorA, colorB, colorG, colorE, - colorI); - r += - GetResult2 (colorB, colorA, colorK, colorF, - colorJ); - r += - GetResult2 (colorB, colorA, colorH, colorN, - colorM); - r += - GetResult1 (colorA, colorB, colorL, colorO, - colorP); - - if (r > 0) - product2 = colorA; - else if (r < 0) - product2 = colorB; - else - { - product2 = - Q_INTERPOLATE (colorA, colorB, colorC, - colorD); - } - } - } - else - { - product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD); - - if ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ)) - { - product = colorA; - } - else - if ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI)) - { - product = colorB; - } - else - { - product = INTERPOLATE (colorA, colorB); - } - - if ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM)) - { - product1 = colorA; - } - else - if ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI)) - { - product1 = colorC; - } - else - { - product1 = INTERPOLATE (colorA, colorC); - } - } - -#ifdef MSB_FIRST - product = product | (colorA << 16); - product1 = product2 | (product1 << 16); -#else - product = colorA | (product << 16); - product1 = product1 | (product2 << 16); -#endif - *((int32 *) dP) = product; - *((uint32 *) (dP + dstPitch)) = product1; - - bP += inc_bP; - dP += sizeof (uint32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; - deltaPtr += srcPitch; - } // endof: while (height--) - } -} - -#ifdef MMX -void Scale_2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */, - uint8 *dstPtr, uint32 dstPitch, - uint32 dstWidth, uint32 dstHeight, int width, int height) -{ - uint8 *dP; - uint16 *bP; - uint32 w; - uint32 h; - uint32 dw; - uint32 dh; - uint32 hfinish; - uint32 wfinish; - uint32 Nextline; - uint16 colorA[4]; - uint16 colorB[4]; - uint16 colorC[4]; - uint16 colorD[4]; - uint16 dx[4]; - uint16 dy[4]; - - Nextline = srcPitch >> 1; - - wfinish = (width - 1) << 16; // convert to fixed point - hfinish = (height - 1) << 16; // convert to fixed point - dw = wfinish / (dstWidth - 1); - dh = hfinish / (dstHeight - 1); - - for (h = 0; h < hfinish; h += dh) - { - uint32 y1, y2; - - y1 = h & 0xffff; // fraction part of fixed point - y2 = 0x10000 - y1; - bP = (uint16 *) (srcPtr + ((h >> 16) * srcPitch)); - dP = dstPtr; - - for (w = 0; w < wfinish;) - { - uint32 A, B, C, D; - uint32 E, F, G, H; - uint32 I, J, K, L; - uint32 x1, x2, a1, f1, f2; - uint32 position; - - for (int c = 0; c < 4; c++) - { - position = w >> 16; - A = bP[position]; // current pixel - B = bP[position + 1]; // next pixel - C = bP[position + Nextline]; - D = bP[position + Nextline + 1]; - E = bP[position - Nextline]; - F = bP[position - Nextline + 1]; - G = bP[position - 1]; - H = bP[position + Nextline - 1]; - I = bP[position + 2]; - J = bP[position + Nextline + 2]; - K = bP[position + Nextline + Nextline]; - L = bP[position + Nextline + Nextline + 1]; - - x1 = w & 0xffff; // fraction part of fixed point - x2 = 0x10000 - x1; - - /*1*/ - if (A == D && B != C) - { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y1 <= f1 && A == J && A != E) // close to B - { - a1 = f1 - y1; - colorA[c] = A; - colorB[c] = B; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y1 >= f1 && A == G && A != L) // close to C - { - a1 = y1 - f1; - colorA[c] = A; - colorB[c] = C; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (x1 >= f2 && A == E && A != J) // close to B - { - a1 = x1 - f2; - colorA[c] = A; - colorB[c] = B; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (x1 <= f2 && A == L && A != G) // close to C - { - a1 = f2 - x1; - colorA[c] = A; - colorB[c] = C; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y1 >= x1) // close to C - { - a1 = y1 - x1; - colorA[c] = A; - colorB[c] = C; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y1 <= x1) // close to B - { - a1 = x1 - y1; - colorA[c] = A; - colorB[c] = B; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - } - else - /*2*/ - if (B == C && A != D) - { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y2 >= f1 && B == H && B != F) // close to A - { - a1 = y2 - f1; - colorA[c] = B; - colorB[c] = A; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y2 <= f1 && B == I && B != K) // close to D - { - a1 = f1 - y2; - colorA[c] = B; - colorB[c] = D; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (x2 >= f2 && B == F && B != H) // close to A - { - a1 = x2 - f2; - colorA[c] = B; - colorB[c] = A; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (x2 <= f2 && B == K && B != I) // close to D - { - a1 = f2 - x2; - colorA[c] = B; - colorB[c] = D; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y2 >= x1) // close to A - { - a1 = y2 - x1; - colorA[c] = B; - colorB[c] = A; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - else if (y2 <= x1) // close to D - { - a1 = x1 - y2; - colorA[c] = B; - colorB[c] = D; - colorC[c] = 0; - colorD[c] = 0; - dx[c] = a1; - dy[c] = 0; - } - } - /*3*/ - else - { - colorA[c] = A; - colorB[c] = B; - colorC[c] = C; - colorD[c] = D; - dx[c] = x1; - dy[c] = y1; - } - w += dw; - } - BilinearMMX (colorA, colorB, colorC, colorD, dx, dy, dP); - dP += 8; - } - dstPtr += dstPitch; - }; - EndMMX (); - -} - -#else -static uint32 Bilinear (uint32 A, uint32 B, uint32 x) -{ - unsigned long areaA, areaB; - unsigned long result; - - if (A == B) - return A; - - areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits - areaA = 0x20 - areaB; - - A = (A & redblueMask) | ((A & greenMask) << 16); - B = (B & redblueMask) | ((B & greenMask) << 16); - - result = ((areaA * A) + (areaB * B)) >> 5; - - return (result & redblueMask) | ((result >> 16) & greenMask); - -} - -static uint32 Bilinear4 (uint32 A, uint32 B, uint32 C, uint32 D, uint32 x, - uint32 y) -{ - unsigned long areaA, areaB, areaC, areaD; - unsigned long result, xy; - - x = (x >> 11) & 0x1f; - y = (y >> 11) & 0x1f; - xy = (x * y) >> 5; - - A = (A & redblueMask) | ((A & greenMask) << 16); - B = (B & redblueMask) | ((B & greenMask) << 16); - C = (C & redblueMask) | ((C & greenMask) << 16); - D = (D & redblueMask) | ((D & greenMask) << 16); - - areaA = 0x20 + xy - x - y; - areaB = x - xy; - areaC = y - xy; - areaD = xy; - - result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5; - - return (result & redblueMask) | ((result >> 16) & greenMask); -} - -void Scale_2xSaI (uint8 *srcPtr, uint32 srcPitch, uint8 * /* deltaPtr */, - uint8 *dstPtr, uint32 dstPitch, - uint32 dstWidth, uint32 dstHeight, int width, int height) -{ - uint8 *dP; - uint16 *bP; - - uint32 w; - uint32 h; - uint32 dw; - uint32 dh; - uint32 hfinish; - uint32 wfinish; - - uint32 Nextline = srcPitch >> 1; - - wfinish = (width - 1) << 16; // convert to fixed point - dw = wfinish / (dstWidth - 1); - hfinish = (height - 1) << 16; // convert to fixed point - dh = hfinish / (dstHeight - 1); - - for (h = 0; h < hfinish; h += dh) - { - uint32 y1, y2; - - y1 = h & 0xffff; // fraction part of fixed point - bP = (uint16 *) (srcPtr + ((h >> 16) * srcPitch)); - dP = dstPtr; - y2 = 0x10000 - y1; - - w = 0; - - for (; w < wfinish;) - { - uint32 A, B, C, D; - uint32 E, F, G, H; - uint32 I, J, K, L; - uint32 x1, x2, a1, f1, f2; - uint32 position, product1; - - position = w >> 16; - A = bP[position]; // current pixel - B = bP[position + 1]; // next pixel - C = bP[position + Nextline]; - D = bP[position + Nextline + 1]; - E = bP[position - Nextline]; - F = bP[position - Nextline + 1]; - G = bP[position - 1]; - H = bP[position + Nextline - 1]; - I = bP[position + 2]; - J = bP[position + Nextline + 2]; - K = bP[position + Nextline + Nextline]; - L = bP[position + Nextline + Nextline + 1]; - - x1 = w & 0xffff; // fraction part of fixed point - x2 = 0x10000 - x1; - - /*0*/ - if (A == B && C == D && A == C) - product1 = A; - else - /*1*/ - if (A == D && B != C) - { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y1 <= f1 && A == J && A != E) // close to B - { - a1 = f1 - y1; - product1 = Bilinear (A, B, a1); - } - else if (y1 >= f1 && A == G && A != L) // close to C - { - a1 = y1 - f1; - product1 = Bilinear (A, C, a1); - } - else if (x1 >= f2 && A == E && A != J) // close to B - { - a1 = x1 - f2; - product1 = Bilinear (A, B, a1); - } - else if (x1 <= f2 && A == L && A != G) // close to C - { - a1 = f2 - x1; - product1 = Bilinear (A, C, a1); - } - else if (y1 >= x1) // close to C - { - a1 = y1 - x1; - product1 = Bilinear (A, C, a1); - } - else if (y1 <= x1) // close to B - { - a1 = x1 - y1; - product1 = Bilinear (A, B, a1); - } - } - else - /*2*/ - if (B == C && A != D) - { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y2 >= f1 && B == H && B != F) // close to A - { - a1 = y2 - f1; - product1 = Bilinear (B, A, a1); - } - else if (y2 <= f1 && B == I && B != K) // close to D - { - a1 = f1 - y2; - product1 = Bilinear (B, D, a1); - } - else if (x2 >= f2 && B == F && B != H) // close to A - { - a1 = x2 - f2; - product1 = Bilinear (B, A, a1); - } - else if (x2 <= f2 && B == K && B != I) // close to D - { - a1 = f2 - x2; - product1 = Bilinear (B, D, a1); - } - else if (y2 >= x1) // close to A - { - a1 = y2 - x1; - product1 = Bilinear (B, A, a1); - } - else if (y2 <= x1) // close to D - { - a1 = x1 - y2; - product1 = Bilinear (B, D, a1); - } - } - /*3*/ - else - { - product1 = Bilinear4 (A, B, C, D, x1, y1); - } - -//end First Pixel - *(uint32 *) dP = product1; - dP += 2; - w += dw; - } - dstPtr += dstPitch; - } -} - -#endif - diff --git a/source/snes9x/unused/2xsaiwin.cpp b/source/snes9x/unused/2xsaiwin.cpp deleted file mode 100644 index 8ccc9d61..00000000 --- a/source/snes9x/unused/2xsaiwin.cpp +++ /dev/null @@ -1,821 +0,0 @@ -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - - -//#define MMX - -#include "snes9x/snes9x.h" -#include "snes9x/port.h" -#include "snes9x/gfx.h" - -#ifdef MMX -EXTERN_C void _2xSaILine (uint8 *srcPtr, uint8 *deltaPtr, uint32 srcPitch, uint32 width, - uint8 *dstPtr, uint32 dstPitch); -EXTERN_C void _2xSaISuperEagleLine (uint8 *srcPtr, uint8 *deltaPtr, uint32 srcPitch, uint32 width, - uint8 *dstPtr, uint32 dstPitch); -EXTERN_C int Init_2xSaIMMX (uint32 BitFormat); -#endif - -bool mmx_cpu = false; - -static uint32 colorMask = 0xF7DEF7DE; -static uint32 lowPixelMask = 0x08210821; -static uint32 qcolorMask = 0xE79CE79C; -static uint32 qlowpixelMask = 0x18631863; - - -int Init_2xSaI(uint32 BitFormat) -{ - if (BitFormat == 565) - { - colorMask = 0xF7DEF7DE; - lowPixelMask = 0x08210821; - qcolorMask = 0xE79CE79C; - qlowpixelMask = 0x18631863; - } - else - if (BitFormat == 555) - { - colorMask = 0x7BDE7BDE; - lowPixelMask = 0x04210421; - qcolorMask = 0x739C739C; - qlowpixelMask = 0x0C630C63; - } - else - { - return 0; - } -#ifdef MMX - Init_2xSaIMMX(BitFormat); -#endif - return 1; -} - -STATIC inline int GetResult1(uint32 A, uint32 B, uint32 C, uint32 D, uint32 E) -{ - int x = 0; - int y = 0; - int r = 0; - if (A == C) x+=1; else if (B == C) y+=1; - if (A == D) x+=1; else if (B == D) y+=1; - if (x <= 1) r+=1; - if (y <= 1) r-=1; - return r; -} - -STATIC inline int GetResult2(uint32 A, uint32 B, uint32 C, uint32 D, uint32 E) -{ - int x = 0; - int y = 0; - int r = 0; - if (A == C) x+=1; else if (B == C) y+=1; - if (A == D) x+=1; else if (B == D) y+=1; - if (x <= 1) r-=1; - if (y <= 1) r+=1; - return r; -} - - -STATIC inline int GetResult(uint32 A, uint32 B, uint32 C, uint32 D) -{ - int x = 0; - int y = 0; - int r = 0; - if (A == C) x+=1; else if (B == C) y+=1; - if (A == D) x+=1; else if (B == D) y+=1; - if (x <= 1) r+=1; - if (y <= 1) r-=1; - return r; -} - - -STATIC inline uint32 INTERPOLATE(uint32 A, uint32 B) -{ - if (A !=B) - { - return ( ((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask) ); - } - else return A; -} - - -STATIC inline uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) -{ - register uint32 x = ((A & qcolorMask) >> 2) + - ((B & qcolorMask) >> 2) + - ((C & qcolorMask) >> 2) + - ((D & qcolorMask) >> 2); - register uint32 y = (A & qlowpixelMask) + - (B & qlowpixelMask) + - (C & qlowpixelMask) + - (D & qlowpixelMask); - y = (y>>2) & qlowpixelMask; - return x+y; -} - - - - -#define HOR -#define VER -void Super2xSaI(uint8 *srcPtr, uint32 srcPitch, - uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height) -{ - uint32 *dP; - uint16 *bP; - -#ifdef MMX_BLA //no MMX version yet - if (cpu_mmx && width != 512) - { - for (height; height; height-=1) - { - bP = (uint16 *) srcPtr; - xP = (uint16 *) deltaPtr; - dP = (uint32 *) dstPtr; - _2xSaISuperEagleLine ((uint8 *) bP, (uint8 *) xP, srcPitch, width, (uint8 *) dP, dstPitch); - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - } - } - else - { -#endif - uint32 Nextline = srcPitch >> 1; - - for (height; height; height-=1) - { - bP = (uint16 *) srcPtr; - dP = (uint32 *) dstPtr; - for (uint32 finish = width; finish; finish -= 1 ) - { - uint32 color4, color5, color6; - uint32 color1, color2, color3; - uint32 colorA0, colorA1, colorA2, colorA3, - colorB0, colorB1, colorB2, colorB3, - colorS1, colorS2; - uint32 product1a, product1b, - product2a, product2b; - -//--------------------------------------- B1 B2 -// 4 5 6 S2 -// 1 2 3 S1 -// A1 A2 - - colorB0 = *(bP- Nextline - 1); - colorB1 = *(bP- Nextline); - colorB2 = *(bP- Nextline + 1); - colorB3 = *(bP- Nextline + 2); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA0 = *(bP + Nextline + Nextline - 1); - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - colorA3 = *(bP + Nextline + Nextline + 2); - - -//-------------------------------------- - if (color2 == color6 && color5 != color3) - { - product2b = product1b = color2; - } - else - if (color5 == color3 && color2 != color6) - { - product2b = product1b = color5; - } - else - if (color5 == color3 && color2 == color6 && color5 != color6) - { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) - product2b = product1b = color6; - else - if (r < 0) - product2b = product1b = color5; - else - { - product2b = product1b = INTERPOLATE (color5, color6); - } - - } - else - { - -#ifdef VER - if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0) - product2b = Q_INTERPOLATE (color3, color3, color3, color2); - else - if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3) - product2b = Q_INTERPOLATE (color2, color2, color2, color3); - else -#endif - product2b = INTERPOLATE (color2, color3); - -#ifdef VER - if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0) - product1b = Q_INTERPOLATE (color6, color6, color6, color5); - else - if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3) - product1b = Q_INTERPOLATE (color6, color5, color5, color5); - else -#endif - product1b = INTERPOLATE (color5, color6); - } - -#ifdef HOR - if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2) - product2a = INTERPOLATE (color2, color5); - else - if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0) - product2a = INTERPOLATE(color2, color5); - else -#endif - product2a = color2; - -#ifdef HOR - if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2) - product1a = INTERPOLATE (color2, color5); - else - if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0) - product1a = INTERPOLATE(color2, color5); - else -#endif - product1a = color5; - - - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); - - *(dP) = product1a; - *(dP+(dstPitch>>2)) = product2a; - - bP += 1; - dP += 1; - }//end of for ( finish= width etc..) - - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - }; //endof: for (height; height; height--) -#ifdef MMX_BLA - } -#endif -} - - - - - - -/*ONLY use with 640x480x16 or higher resolutions*/ -/*Only use this if 2*width * 2*height fits on the current screen*/ -void SuperEagle(uint8 *srcPtr, uint32 srcPitch, - uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height) -{ - uint32 *dP; - uint16 *bP; - uint16 *xP; - -#ifdef MMX - if (mmx_cpu && width != 512) - { - for (height; height; height-=1) - { - bP = (uint16 *) srcPtr; - xP = (uint16 *) deltaPtr; - dP = (uint32 *) dstPtr; - _2xSaISuperEagleLine ((uint8 *) bP, (uint8 *) xP, srcPitch, width, (uint8 *)dP, dstPitch); - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - } - } - else - { -#endif - uint32 Nextline = srcPitch >> 1; - - for (height; height; height-=1) - { - bP = (uint16 *) srcPtr; - dP = (uint32 *) dstPtr; - for (uint32 finish = width; finish; finish -= 1 ) - { - - uint32 color4, color5, color6; - uint32 color1, color2, color3; - uint32 colorA0, colorA1, colorA2, colorA3, - colorB0, colorB1, colorB2, colorB3, - colorS1, colorS2; - uint32 product1a, product1b, - product2a, product2b; - - colorB0 = *(bP- Nextline - 1); - colorB1 = *(bP- Nextline); - colorB2 = *(bP- Nextline + 1); - colorB3 = *(bP- Nextline + 2); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA0 = *(bP + Nextline + Nextline - 1); - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - colorA3 = *(bP + Nextline + Nextline + 2); - - - //-------------------------------------- - if (color2 == color6 && color5 != color3) - { - product1b = product2a = color2; - if ((color1 == color2 && color6 == colorS2) || - (color2 == colorA1 && color6 == colorB2)) - { - product1a = INTERPOLATE (color2, color5); - product1a = INTERPOLATE (color2, product1a); - product2b = INTERPOLATE (color2, color3); - product2b = INTERPOLATE (color2, product2b); -// product1a = color2; -// product2b = color2; - } - else - { - product1a = INTERPOLATE (color5, color6); - product2b = INTERPOLATE (color2, color3); - } - } - else - if (color5 == color3 && color2 != color6) - { - product2b = product1a = color5; - if ((colorB1 == color5 && color3 == colorA2) || - (color4 == color5 && color3 == colorS1)) - { - product1b = INTERPOLATE (color5, color6); - product1b = INTERPOLATE (color5, product1b); - product2a = INTERPOLATE (color5, color2); - product2a = INTERPOLATE (color5, product2a); -// product1b = color5; -// product2a = color5; - } - else - { - product1b = INTERPOLATE (color5, color6); - product2a = INTERPOLATE (color2, color3); - } - } - else - if (color5 == color3 && color2 == color6 && color5 != color6) - { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) - { - product1b = product2a = color2; - product1a = product2b = INTERPOLATE (color5, color6); - } - else - if (r < 0) - { - product2b = product1a = color5; - product1b = product2a = INTERPOLATE (color5, color6); - } - else - { - product2b = product1a = color5; - product1b = product2a = color2; - } - } - else - { - - if ((color2 == color5) || (color3 == color6)) - { - product1a = color5; - product2a = color2; - product1b = color6; - product2b = color3; - - } - else - { - product1b = product1a = INTERPOLATE (color5, color6); - product1a = INTERPOLATE (color5, product1a); - product1b = INTERPOLATE (color6, product1b); - - product2a = product2b = INTERPOLATE (color2, color3); - product2a = INTERPOLATE (color2, product2a); - product2b = INTERPOLATE (color3, product2b); - } - } - - - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); - - *(dP) = product1a; - *(dP+(dstPitch>>2)) = product2a; - - bP += 1; - dP += 1; - }//end of for ( finish= width etc..) - - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - }; //endof: for (height; height; height--) -#ifdef MMX - } -#endif -} - - - -/*ONLY use with 640x480x16 or higher resolutions*/ -/*Only use this if 2*width * 2*height fits on the current screen*/ -void _2xSaI(uint8 *srcPtr, uint32 srcPitch, - uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height) -{ - uint32 *dP; - uint16 *bP; - uint16 *xP; - -#ifdef MMX - if (mmx_cpu && width != 512) - { - for (height; height; height-=1) - { - - bP = (uint16 *) srcPtr; - xP = (uint16 *) deltaPtr; - dP = (uint32 *) dstPtr; - _2xSaILine ((uint8 *) bP, (uint8 *) xP, srcPitch, width, (uint8 *)dP, dstPitch); - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - } - } - else - { -#endif - uint32 Nextline = srcPitch >> 1; - - for (height; height; height-=1) - { - bP = (uint16 *) srcPtr; - dP = (uint32 *) dstPtr; - for (uint32 finish = width; finish; finish -= 1 ) - { - - - register uint32 colorA, colorB; - uint32 colorC, colorD, - colorE, colorF, colorG, colorH, - colorI, colorJ, colorK, colorL, - colorM, colorN, colorO, colorP; - uint32 product, product1, product2; - - -//--------------------------------------- -// Map of the pixels: I|E F|J -// G|A B|K -// H|C D|L -// M|N O|P - colorI = *(bP- Nextline - 1); - colorE = *(bP- Nextline); - colorF = *(bP- Nextline + 1); - colorJ = *(bP- Nextline + 2); - - colorG = *(bP - 1); - colorA = *(bP); - colorB = *(bP + 1); - colorK = *(bP + 2); - - colorH = *(bP + Nextline - 1); - colorC = *(bP + Nextline); - colorD = *(bP + Nextline + 1); - colorL = *(bP + Nextline + 2); - - colorM = *(bP + Nextline + Nextline - 1); - colorN = *(bP + Nextline + Nextline); - colorO = *(bP + Nextline + Nextline + 1); - colorP = *(bP + Nextline + Nextline + 2); - - if ((colorA == colorD) && (colorB != colorC)) - { - if ( ((colorA == colorE) && (colorB == colorL)) || - ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) ) - { - product = colorA; - } - else - { - product = INTERPOLATE(colorA, colorB); - } - - if (((colorA == colorG) && (colorC == colorO)) || - ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) ) - { - product1 = colorA; - } - else - { - product1 = INTERPOLATE(colorA, colorC); - } - product2 = colorA; - } - else - if ((colorB == colorC) && (colorA != colorD)) - { - if (((colorB == colorF) && (colorA == colorH)) || - ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) ) - { - product = colorB; - } - else - { - product = INTERPOLATE(colorA, colorB); - } - - if (((colorC == colorH) && (colorA == colorF)) || - ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) ) - { - product1 = colorC; - } - else - { - product1 = INTERPOLATE(colorA, colorC); - } - product2 = colorB; - } - else - if ((colorA == colorD) && (colorB == colorC)) - { - if (colorA == colorB) - { - product = colorA; - product1 = colorA; - product2 = colorA; - } - else - { - register int r = 0; - product1 = INTERPOLATE(colorA, colorC); - product = INTERPOLATE(colorA, colorB); - - r += GetResult1 (colorA, colorB, colorG, colorE, colorI); - r += GetResult2 (colorB, colorA, colorK, colorF, colorJ); - r += GetResult2 (colorB, colorA, colorH, colorN, colorM); - r += GetResult1 (colorA, colorB, colorL, colorO, colorP); - - if (r > 0) - product2 = colorA; - else - if (r < 0) - product2 = colorB; - else - { - product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); - } - } - } - else - { - product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD); - - if ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) - { - product = colorA; - } - else - if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) - { - product = colorB; - } - else - { - product = INTERPOLATE(colorA, colorB); - } - - if ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) - { - product1 = colorA; - } - else - if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) - { - product1 = colorC; - } - else - { - product1 = INTERPOLATE(colorA, colorC); - } - } - product = colorA | (product << 16); - product1 = product1 | (product2 << 16); - *(dP) = product; - *(dP+(dstPitch>>2)) = product1; - - bP += 1; - dP += 1; - }//end of for ( finish= width etc..) - - dstPtr += dstPitch << 1; - srcPtr += srcPitch; - deltaPtr += srcPitch; - }; //endof: for (height; height; height--) -#ifdef MMX - } -#endif -} - diff --git a/source/snes9x/unused/Makefile.in b/source/snes9x/unused/Makefile.in deleted file mode 100644 index 3d1766e8..00000000 --- a/source/snes9x/unused/Makefile.in +++ /dev/null @@ -1,403 +0,0 @@ -@ZSNESFX@ -@ZSNESC4@ -@ASMCPU@ -@SPC700ASM@ -@NETPLAY@ -UNZIP=1 -@JMA@ -@GLIDE@ -@OPENGL@ -@AIDO@ -#GUI=0 -@THREAD_SOUND@ -@ASMKREED@ -@SDD1_DECOMP@ -@CORRECT_VRAM_READS@ -@DREAMCAST@ -CHEATS=1 -2XSAI=1 - -#Fairly good and special-char-safe descriptor of the os being built on. -OS=`uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"` -BUILDDIR=. -#BUILDDIR=build/$(OS) - -ifdef DREAMCAST -CPU=sh -ASMCPU=1 -CHEATS=0 -2XSAI=0 -else -CPU=i386 -endif - -ifdef ZSNESFX -FXOBJ=$(CPU)/fxemu2b.o $(CPU)/fxemu2.o $(CPU)/fxemu2c.o $(CPU)/fxtable.o $(CPU)/sfxproc.o $(CPU)/ZSNES.O -FXDEFINES=-DZSNES_FX -DEXECUTE_SUPERFX_PER_LINE -FXDEPENDS=zsnes_fx -FXNO_DEPENDS=c_fx -else -FXOBJ=fxinst.o fxemu.o fxdbg.o -FXDEFINES= -FXDEPENDS=c_fx -FXNO_DEPENDS=zsnes_fx -endif - -ifdef ZSNESC4 -C4OBJ=$(CPU)/C4.O $(CPU)/zsnesc4.o c4.o -C4DEFINES=-DZSNES_C4 -C4DEPENDS=zsnes_c4 -C4NO_DEPENDS=c_c4 -else -C4OBJ=c4.o c4emu.o -C4DEFINES= -C4DEPENDS=c_c4 -C4NO_DEPENDS=zsnes_c4 -endif - -SOUNDOBJ=spc700.o soundux.o apu.o @I386SPC@ -SOUNDDEFINES=-DSPC700_C - -ifdef ASMCPU -CPUOBJ=$(CPU)/cpuops.o $(CPU)/cpuexec.o $(CPU)/sa1ops.o -else -CPUOBJ=cpuops.o cpuexec.o sa1cpu.o -endif - -ifdef DREAMCAST -PLATFORMOBJ=dc/input.o dc/display.o dc/sound.o \ -dc/dc.o dc/menu.o dc/trace.o dc/lcd.o \ -dc/lain_blanker.o dc/td.o dc/md5.o -else -PLATFORMOBJ=unix/unix.o -endif - -ifdef CHEATS -CHEATOBJ=cheats.o cheats2.o -endif - -ifndef DREAMCAST -SNAPOBJ = snaporig.o snapshot.o -SCREENSHOTOBJ = screenshot.o -MOVIEOBJ = movie.o -endif - -ifdef 2XSAI -ifdef ASMKREED -KREEDOBJ=$(CPU)/2XSAIMMX.O $(CPU)/bilinear.o 2xsai.o -KREEDDEFINES=-DMMX -else -KREEDOBJ=2xsai.o -endif -endif - -ifdef SDD1_DECOMP -SDD1OBJ=sdd1emu.o -ifdef SDD1_VERIFY -SDD1DEFINES=-DSDD1_DECOMP -DSDD1_VERIFY -else -SDD1DEFINES=-DSDD1_DECOMP -endif -endif - -ifdef CORRECT_VRAM_READS -CORRVRAMDEFINES=-DCORRECT_VRAM_READS -endif - -SPC7110OBJ=spc7110.o -OBC1OBJ=obc1.o -SETAOBJ=seta.o seta010.o seta011.o seta018.o - -OBJECTS=$(CPUOBJ) $(SOUNDOBJ) apudebug.o $(FXOBJ) $(C4OBJ) \ - controls.o crosshairs.o cpu.o sa1.o debug.o sdd1.o tile.o srtc.o gfx.o \ - memmap.o clip.o dsp1.o ppu.o dma.o snes9x.o data.o globals.o reader.o \ - conffile.o bsx.o logger.o \ - $(SPC7110OBJ) $(OBC1OBJ) $(SETAOBJ) $(KREEDOBJ) $(SDD1OBJ) \ - $(CHEATOBJ) $(PLATFORMOBJ) $(SNAPOBJ) $(SCREENSHOTOBJ) $(MOVIEOBJ) - -ifdef NETPLAY -OBJECTS += netplay.o server.o -NETPLAYDEFINES=-DNETPLAY_SUPPORT -SERVER_OBJECTS=server.o unix/server_main.o globals.o netplay.o -endif - -ifdef UNZIP -OBJECTS += loadzip.o unzip/unzip.o unzip/explode.o unzip/unreduce.o unzip/unshrink.o -UNZIPDEFINES=-DUNZIP_SUPPORT -endif - -ifdef JMA -OBJECTS += jma/s9x-jma.o jma/7zlzma.o jma/crc32.o jma/iiostrm.o jma/inbyte.o jma/jma.o jma/lzma.o jma/lzmadec.o jma/winout.o -JMADEFINES = -DJMA_SUPPORT -endif - -ifdef THREAD_SOUND -CPUDEFINES += -DUSE_THREADS -EXTRALIBS += -lpthread -endif - -ifdef GLIDE -GLIDEOBJS = unix/glide.o -GLIDEDEFINES = -DUSE_GLIDE -I/usr/include/glide -GLIDELIBS = -lglide2x -endif - -ifdef OPENGL -OPENGLOBJS = unix/opengl.o -OPENGLDEFINES = -DUSE_OPENGL -OPENGLLIBS = -lGL -lGLU -ldl -endif - -ifdef AIDO -AIDOOBJS = unix/aido.o -AIDODEFINES = -DUSE_AIDO -endif - -JOYDEFINES = @JOYDEFINES@ - -ifdef DREAMCAST -CCC = sh-elf-c++ -fno-rtti -CC = sh-elf-gcc -NASM = fail -GASM = fail -else -CCC = @CXX@ @RTTIFLAG@ -CC = @CC@ -NASM = @NASM@ -GASM = @CXX@ -endif - -#INCLUDES = -I../zlib @X_INCLUDES@ -ifdef DREAMCAST -INCLUDES = -Idc -DEFS = -DDC -else -INCLUDES = @X_INCLUDES@ -DEFS = -DMITSHM -endif - -INCLUDES += -I. -Iunzip @CPUINC@ - -ifdef DREAMCAST -OPTIMISE=-O4 -ffreestanding -ffast-math -fschedule-insns2 -fomit-frame-pointer -fno-inline-functions -fno-defer-pop -fforce-addr -fstrict-aliasing -funroll-loops -fdelete-null-pointer-checks -fno-exceptions -CPUFLAGS=-ml -m4-single-only -else -OPTIMISE = @OPTIMIZE@ -endif - -DEFS += \ --DCPU_SHUTDOWN \ --DSPC700_SHUTDOWN \ -$(FXDEFINES) \ -$(C4DEFINES) \ -$(CPUDEFINES) \ -$(SOUNDDEFINES) \ -$(NETPLAYDEFINES) \ -$(UNZIPDEFINES) \ -$(JMADEFINES) \ -$(GLIDEDEFINES) \ -$(OPENGLDEFINES) \ -$(AIDODEFINES) \ -$(KREEDDEFINES) \ -$(SDD1DEFINES) \ -$(CORRVRAMDEFINES) \ -$(JOYDEFINES) \ --DNO_INLINE_SET_GET @SYSDEFINES@ - -CCFLAGS = $(OPTIMISE) $(CPUFLAGS) $(INCLUDES) $(DEFS) - -CFLAGS=$(CCFLAGS) - -.SUFFIXES: .o .cpp .c .cc .h .m .i .S .asm .obj .O .CPP .C .ASM -#FIXME: Why is this set statically? -#LDLIBS = -L/usr/X11R6/lib -# -L../zlib - -ifdef GLIDE -all: Makefile configure gsnes9x -else -ifdef OPENGL -all: Makefile configure osnes9x -else -all: Makefile configure snes9x -endif -endif - -Makefile: configure Makefile.in - @echo "Makefile is older than configure or in-file. Run configure or touch Makefile." - exit 1 - -configure: configure.in - @echo "configure is older than in-file. Run autoconf or touch configure." - exit 1 - -#ggisnes9x -#xf86snes9x - -ifdef ASMCPU -OFFSET=offsets -else -OFFSET= -endif - -offsets: offsets.o - $(CCC) $(INCLUDES) -o $@ offsets.o - ./offsets >$(CPU)/offsets.h - -#../zlib/libz.a: -# cd ../zlib && sh ./configure && make - -snes9x: $(OBJECTS) unix/x11.o $(AIDOOBJS) $(OFFSET) - $(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(AIDOOBJS) $(GLIDEOBJS) $(OPENGLOBJS) unix/x11.o $(LDLIBS) $(GLIDELIBS) $(OPENGLLIBS) @SYSLIBS@ -lXext -lX11 $(EXTRALIBS) -lm - -unix/svga_keynames.h: unix/svga_get_keynames.pl - unix/svga_get_keynames.pl /usr/include/vgakeyboard.h > unix/svga_keynames.h - -unix/svga.o: unix/svga_keynames.h - -ssnes9x: $(OBJECTS) unix/svga.o - $(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(GLIDEOBJS) unix/svga.o $(LDLIBS) $(GLIDELIBS) @SYSLIBS@ -lvga -lvgagl $(EXTRALIBS) -lm - -gsnes9x: $(OBJECTS) $(GLIDEOBJS) - $(CCC) $(INCLUDES) -o $@ $(OBJECTS) $(GLIDEOBJS) $(LDLIBS) @SYSLIBS@ -lglide $(EXTRALIBS) -lm - -ggisnes9x: $(OBJECTS) unix/ggi.o - $(CCC) $(INCLUDES) -o $@ $(OBJECTS) unix/ggi.o $(LDLIBS) @SYSLIBS@ -lggi $(EXTRALIBS) -lm - -osnes9x: $(OBJECTS) unix/x11.o $(OPENGLOBJS) - $(CCC) $(INCLUDES) -o $@ $(OBJECTS) unix/x11.o $(OPENGLOBJS) $(LDLIBS) $(OPENGLLIBS) @SYSLIBS@ -lXext -lX11 $(EXTRALIBS) -lm - -s9xserver: $(SERVER_OBJECTS) - $(CCC) $(INCLUDES) -o $@ $(SERVER_OBJECTS) - -jma/s9x-jma.o: jma/s9x-jma.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/7zlzma.o: jma/7zlzma.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/crc32.o: jma/crc32.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/iiostrm.o: jma/iiostrm.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/inbyte.o: jma/inbyte.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/jma.o: jma/jma.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/lzma.o: jma/lzma.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/lzmadec.o: jma/lzmadec.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ -jma/winout.o: jma/winout.cpp - $(CCC) $(INCLUDES) -c $(CCFLAGS) -fexceptions $*.cpp -o $@ - -.cpp.o: - $(CCC) $(INCLUDES) -c $(CCFLAGS) $*.cpp -o $@ - -.c.o: - $(CC) $(INCLUDES) -c $(CCFLAGS) $*.c -o $@ - -.cpp.S: - $(GASM) $(INCLUDES) -S $(CCFLAGS) $*.cpp -o $@ - -.cpp.i: - $(GASM) $(INCLUDES) -E $(CCFLAGS) $*.cpp -o $@ - -.S.o: - $(GASM) $(INCLUDES) -c $(CCFLAGS) $*.S -o $@ - -.S.i: - $(GASM) $(INCLUDES) -c -E $(CCFLAGS) $*.S -o $@ - -.s.o: - @echo Compiling $*.s - sh-elf-as -little $*.s -o $@ - -.asm.o: - $(NASM) -f elf -DELF $(FXDEFINES) -i. -ii386 -o $@ $*.asm - -.obj.o: - cp $*.obj $*.o - -.CPP.O: - $(CCC) $(INCLUDES) -c $(CCFLAGS) -x c++ $*.CPP -o $@ - -.C.O: - $(CC) $(INCLUDES) -c $(CCFLAGS) $*.C -o $@ - -.ASM.O: - $(NASM) -f elf -DELF $(FXDEFINES) -i . -i i386 $*.ASM -o $@ - -unix/moc_snes9x_gui.cpp: unix/snes9x_gui.h - $(MOC) unix/snes9x_gui.h -o $@ - -clean: - rm -f $(OBJECTS) offsets.o unix/svga.o unix/aido.o unix/x11.o unix/ggi.o unix/xf86.o unix/glide.o - -#release: CCFLAGS += -DNO_DEBUGGER - -_bin-package: - RELNR=`grep "#define VERSION" snes9x.h | sed -e 's/"//g' | awk '{ print $$3 }'` && \ - echo $$RELNR && \ - RELNAME=snes9x-$${RELNR} && export RELNAME && \ - test \! -f $${RELNAME}.tar.gz && \ - DISTDIR=disttmp/$${RELNAME}/ && \ - rm -rf disttmp && \ - mkdir disttmp && \ - mkdir $${DISTDIR} && \ - cp snes9x $${DISTDIR} && \ - cp config.info hardware.txt problems.txt changes.txt ../faqs.txt ../readme.txt ../readme.unix $${DISTDIR} && \ - (cd disttmp && tar cvf - $${RELNAME}) | gzip -c > $${RELNAME}.tar.gz &&\ - rm -rf disttmp - -#FIXME: Should possibly have clean, but not in xenofarm build -bin-release: snes9x _bin-package - -#FIXME: Intelligent messages when bailing out. -#FIXME: See those ls:s? Don't look to closely at the statements... -_src-package: - RELNR=`grep "#define VERSION" snes9x.h | sed -e 's/"//g' | awk '{ print $$3 }'` && \ - echo $$RELNR && \ - RELNAME=snes9x-$${RELNR}-src && \ - test \! -f $${RELNAME}.tar.gz && \ - test \! `ls *~` && \ - test \! `ls *.o` && \ - test \! -f snes9x && \ - export RELNR && export RELNAME && \ - (cd .. && PWD=`pwd` && SNESDIR=`basename $$PWD` && cd .. && \ - DISTDIR=disttmp/$${RELNAME} && \ - rm -rf disttmp && \ - mkdir disttmp && \ - cp -r $${SNESDIR} $${DISTDIR} && \ - rm -f $${DISTDIR}/snes9x/config.* 2>/dev/null && \ - rm -f $${DISTDIR}/snes9x/conftezt.out.* 2>/dev/null && \ - rm -rf $${DISTDIR}/snes9x/autom4te.cache 2>/dev/null && \ - rm $${DISTDIR}/snes9x/Makefile && \ - find disttmp -name CVS -type f -exec rm "{}" \; && \ - find disttmp -name CVS -type d -exec rm "{}" \; && \ - (cd disttmp && tar cvf - $${RELNAME}) | gzip -c > $${RELNAME}.tar.gz && \ - mv $${RELNAME}.tar.gz $${SNESDIR}/snes9x/ ) && \ - rm -rf disttmp - -#Requires: -# 1. Prestine checkout -# 2. `autoconf` -# 3. `./configure` -src-release: depend _src-package - -xenofarm: - ./xenofarm.sh - cd build/xenofarm && tar cf - . > ../../../xenofarm_result.tar - gzip -f9 ../xenofarm_result.tar - -# And now for the impressive testsuite: -verify: snes9x - ./snes9x --selftest - -#FIXME: Make a auto-self-reference. -depend: - $(CC) $(CFLAGS) -MM -MG \ - `find . '(' -name '*.c' -o -name '*.cpp' -o -name '*.S' ')' -print -o -name msdos -prune` \ - | sed -e 's@^[^ :]*: *\([^ ]*/\)[^ /]*@\1&@' \ - >dependencies - -include dependencies - diff --git a/source/snes9x/unused/Makefile.mingw b/source/snes9x/unused/Makefile.mingw deleted file mode 100644 index 53ecfa3a..00000000 --- a/source/snes9x/unused/Makefile.mingw +++ /dev/null @@ -1,193 +0,0 @@ -ASM=nasm -OBJFIX=win32/objfix.exe - -CFLAGSORIG=-Wall -I../zlib -I -I../FMOD/api/inc -DSPC700_SHUTDOWN -DNETPLAY_SUPPORT \ - -DCPU_SHUTDOWN -DZLIB -DVAR_CYCLES -DEXECUTE_SUPERFX_PER_LINE -D__WIN32__ -DUSE_OPENGL \ - -DUNZIP_SUPPORT -DHAVE_LIBPNG -DSDD1_DECOMP -DCORRECT_VRAM_READS -DNEW_COLOUR_BLENDING \ - -DWIN32 -D_WINDOWS -DSPC700_C -DJMA_SUPPORT -DZSNES_FX -DZSNES_C4 -DHAVE_STDINT_H -D_WIN32_IE=0x0501 -#-DFMOD_SUPPORT -DUSE_GLIDE - - -ifeq (${DEBUG},yes) -CFLAGS= ${CFLAGSORIG} -ggdb3 -else -CFLAGS= ${CFLAGSORIG} -O3 -DNDEBUG -endif - - -ifeq (${CROSS},yes) -CC=i586-mingw32-gcc -CPPC=i586-mingw32-g++ -WINDRES=i586-mingw32-windres -DEL=rm -f -SLASH=/ -else -CC=gcc -CPPC=g++ -WINDRES=windres -DEL=del -SLASH=\${blahblahblahblah} -endif - -LINK=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lz -lpng -lcomctl32 -lwinmm -lopengl32 -lglu32 -lwsock32 -lddraw -ldsound -ldxguid -lvfw32 -mwindows -#-L..\..\FMOD\api\lib -lfmodvc -lglide2x -ldelayimp - -OBJS= 2xsai.obj apu.obj apudebug.obj bsx.obj c4.obj c4emu.obj cheats.obj cheats2.obj \ - clip.obj conffile.obj controls.obj cpu.obj cpuexec.obj cpuops.obj crosshairs.obj data.obj \ - debug.obj dma.obj dsp1.obj fxdbg.obj fxemu.obj fxinst.obj gfx.obj globals.obj loadzip.obj \ - logger.obj memmap.obj movie.obj netplay.obj obc1.obj ppu.obj reader.obj sa1.obj sa1cpu.obj \ - screenshot.obj sdd1.obj sdd1emu.obj server.obj seta.obj seta010.obj seta011.obj seta018.obj \ - snaporig.obj snapshot.obj snes9x.obj sound.obj soundux.obj spc700.obj spc7110.obj srtc.obj \ - tile.obj unzip/unreduce.obj i386/ZSNES.obj i386/fxemu2b.obj i386/fxtable.obj i386/fxemu2.obj \ - i386/fxemu2c.obj i386/sfxproc.obj i386/SPC.obj i386/zsnesc4.obj i386/C4.obj i386/2XSAIMMX.obj \ - i386/bilinear.obj jma/7zlzma.obj jma/crc32.obj jma/iiostrm.obj jma/inbyte.obj jma/jma.obj \ - jma/lzma.obj jma/lzmadec.obj jma/s9x-jma.obj jma/winout.obj unzip/unshrink.obj unzip/unzip.obj \ - unzip/explode.obj win32/auxmath.obj win32/AVIOutput.obj win32/directx.obj win32/InputCustom.obj \ - win32/render.obj win32/win32.obj win32/wconfig.obj win32/wsnes9x.obj win32/snes9x.obj - -#adler32.obj compress.obj deflate.obj emucrc32.obj gzio.obj infback.obj \ -#inffast.obj inflate.obj inftrees.obj minigzip.obj trees.obj uncompr.obj zutil.obj -#png.obj pngerror.obj pnggccrd.obj pngget.obj pngmem.obj \ -#pngpread.obj pngread.obj pngrio.obj pngrtran.obj pngrutil.obj pngset.obj pngtrans.obj \ -#pngvcrd.obj pngwio.obj pngwrite.obj pngwtran.obj pngwutil.obj - -.SUFFIXES: .c .cpp .asm .ASM - -%.obj: %.c - ${CC} ${CFLAGS} -o $@ -c $< - -%.obj: %.cpp - ${CPPC} ${CFLAGS} -o $@ -c $< - -%.obj: %.asm - ${ASM} -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o $@ $< - ${OBJFIX} $@ - -%.obj: %.ASM - ${ASM} -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o $@ $< - ${OBJFIX} $@ - -all: ${OBJFIX} ${OBJS} -ifeq (${DEBUG},yes) - ${CPPC} -ggdb3 -osnes9x-debug.exe ${OBJS} ${LINK} -else - ${CPPC} -s -osnes9x.exe ${OBJS} ${LINK} -endif - -${OBJFIX}: win32/objfix.c - gcc -O3 -s -o $@ win32/objfix.c -2xsai.obj: 2xsai.cpp -apu.obj: apu.cpp -apudebug.obj: apudebug.cpp -bsx.obj: bsx.cpp -c4.obj: c4.cpp -c4emu.obj: c4emu.cpp -cheats.obj: cheats.cpp -cheats2.obj: cheats2.cpp -clip.obj: clip.cpp -conffile.obj: conffile.cpp -controls.obj: controls.cpp -cpu.obj: cpu.cpp -cpuexec.obj: cpuexec.cpp -cpuops.obj: cpuops.cpp -crosshairs.obj: crosshairs.cpp -data.obj: data.cpp -debug.obj: debug.cpp -dma.obj: dma.cpp -dsp1.obj: dsp1.cpp -fxdbg.obj: fxdbg.cpp -fxemu.obj: fxemu.cpp -fxinst.obj: fxinst.cpp -gfx.obj: gfx.cpp -globals.obj: globals.cpp -loadzip.obj: loadzip.cpp -logger.obj: logger.cpp -memmap.obj: memmap.cpp -movie.obj: movie.cpp -netplay.obj: netplay.cpp -obc1.obj: obc1.cpp -ppu.obj: ppu.cpp -reader.obj: reader.cpp -sa1.obj: sa1.cpp -sa1cpu.obj: sa1cpu.cpp -screenshot.obj: screenshot.cpp -sdd1.obj: sdd1.cpp -sdd1emu.obj: sdd1emu.cpp -server.obj: server.cpp -seta.obj: seta.cpp -seta010.obj: seta010.cpp -seta011.obj: seta011.cpp -seta018.obj: seta018.cpp -snaporig.obj: snaporig.cpp -snapshot.obj: snapshot.cpp -snes9x.obj: snes9x.cpp -sound.obj: sound.cpp -soundux.obj: soundux.cpp -spc700.obj: spc700.cpp -spc7110.obj: spc7110.cpp -srtc.obj: srtc.cpp -tile.obj: tile.cpp -unzip/unreduce.obj: unzip/unreduce.c -unzip/unshrink.obj: unzip/unshrink.c -unzip/unzip.obj: unzip/unzip.c -unzip/explode.obj: unzip/explode.c -jma/7zlzma.obj: jma/7zlzma.cpp -jma/crc32.obj: jma/crc32.cpp -jma/iiostrm.obj: jma/iiostrm.cpp -jma/inbyte.obj: jma/inbyte.cpp -jma/jma.obj: jma/jma.cpp -jma/lzma.obj: jma/lzma.cpp -jma/lzmadec.obj: jma/lzmadec.cpp -jma/s9x-jma.obj: jma/s9x-jma.cpp -jma/winout.obj: jma/winout.cpp -win32/auxmath.obj: win32/auxmath.cpp -win32/AVIOutput.obj: win32/AVIOutput.cpp -win32/directx.obj: win32/directx.cpp -win32/InputCustom.obj: win32/InputCustom.cpp -win32/render.obj: win32/render.cpp -win32/wconfig.obj: win32/wconfig.cpp -win32/win32.obj: win32/win32.cpp -win32/wsnes9x.obj: win32/wsnes9x.cpp -win32/snes9x.obj: win32/rsrc/snes9x.rc - ${WINDRES} --include-dir win32/rsrc --language=0x413 -D_WIN32_IE=0x0501 win32/rsrc/snes9x.rc -owin32/snes9x.obj -#--language=0x809 - -#adler32.obj: ../zlib/adler32.c -#compress.obj: ../zlib/compress.c -#deflate.obj: ../zlib/deflate.c -#emucrc32.obj: ../zlib/emucrc32.c -#gzio.obj: ../zlib/gzio.c -#infback.obj: ../zlib/infback.c -#inffast.obj: ../zlib/inffast.c -#inflate.obj: ../zlib/inflate.c -#inftrees.obj: ../zlib/inftrees.c -#minigzip.obj: ../zlib/minigzip.c -#trees.obj: ../zlib/trees.c -#uncompr.obj: ../zlib/uncompr.c -#zutil.obj: ../zlib/zutil.c - -#png.obj: ../libpng/src/png.c -#pngerror.obj: ../libpng/src/pngerror.c -#pnggccrd.obj: ../libpng/src/pnggccrd.c -#pngget.obj: ../libpng/src/pngget.c -#pngmem.obj: ../libpng/src/pngmem.c -#pngpread.obj: ../libpng/src/pngpread.c -#pngread.obj: ../libpng/src/pngread.c -#pngrio.obj: ../libpng/src/pngrio.c -#pngrtran.obj: ../libpng/src/pngrtran.c -#pngrutil.obj: ../libpng/src/pngrutil.c -#pngset.obj: ../libpng/src/pngset.c -#pngtrans.obj: ../libpng/src/pngtrans.c -#pngvcrd.obj: ../libpng/src/pngvcrd.c -#pngwio.obj: ../libpng/src/pngwio.c -#pngwrite.obj: ../libpng/src/pngwrite.c -#pngwtran.obj: ../libpng/src/pngwtran.c -#pngwutil.obj: ../libpng/src/pngwutil.c - -clean: - ${DEL} *.obj - ${DEL} snes9x.exe - ${DEL} i386${SLASH}*.obj - ${DEL} jma${SLASH}*.obj - ${DEL} unzip${SLASH}*.obj - ${DEL} win32${SLASH}*.obj diff --git a/source/snes9x/cheats.cpp b/source/snes9x/unused/cheats.cpp similarity index 85% rename from source/snes9x/cheats.cpp rename to source/snes9x/unused/cheats.cpp index 0a94e398..50907f30 100644 --- a/source/snes9x/cheats.cpp +++ b/source/snes9x/unused/cheats.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include #include @@ -220,7 +201,7 @@ const char *S9xGoldFingerToRaw (const char *code, uint32 &address, bool8 &sram, const char *S9xGameGenieToRaw (const char *code, uint32 &address, uint8 &byte) { char new_code [12]; - + if (strlen (code) != 9 || *(code + 4) != '-' || !S9xAllHex (code, 4) || !S9xAllHex (code + 5, 4)) return ("Invalid Game Genie(tm) code - should be 'xxxx-xxxx'."); @@ -231,7 +212,7 @@ const char *S9xGameGenieToRaw (const char *code, uint32 &address, uint8 &byte) static char *real_hex = "0123456789ABCDEF"; static char *genie_hex = "DF4709156BC8A23E"; - + for (int i = 2; i < 10; i++) { if (islower (new_code [i])) @@ -268,7 +249,9 @@ void S9xStartCheatSearch (SCheatData *d) memmove (d->CWRAM, d->RAM, 0x20000); memmove (d->CSRAM, d->SRAM, 0x10000); memmove (d->CIRAM, &d->FillRAM [0x3000], 0x2000); - memset ((char *) d->ALL_BITS, 0xff, 0x32000 >> 3); + memset ((char *) d->WRAM_BITS, 0xff, 0x20000 >> 3); + memset ((char *) d->SRAM_BITS, 0xff, 0x10000 >> 3); + memset ((char *) d->IRAM_BITS, 0xff, 0x2000 >> 3); } #define BIT_CLEAR(a,v) \ @@ -304,7 +287,7 @@ void S9xStartCheatSearch (SCheatData *d) (s) == S9X_24_BITS ? (((int32) ((*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16)) << 8)) >> 8): \ ((int32) (*((m) + (o)) + (*((m) + (o) + 1) << 8) + (*((m) + (o) + 2) << 16) + (*((m) + (o) + 3) << 24)))) -void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, +void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, S9xCheatDataSize size, bool8 is_signed, bool8 update) { int l; @@ -332,7 +315,7 @@ void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->WRAM_BITS, i); } - + for (i = 0; i < 0x10000 - l; i++) { if (TEST_BIT (d->SRAM_BITS, i) && @@ -344,7 +327,7 @@ void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->SRAM_BITS, i); } - + for (i = 0; i < 0x2000 - l; i++) { if (TEST_BIT (d->IRAM_BITS, i) && @@ -370,7 +353,7 @@ void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->WRAM_BITS, i); } - + for (i = 0; i < 0x10000 - l; i++) { if (TEST_BIT (d->SRAM_BITS, i) && @@ -382,7 +365,7 @@ void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->SRAM_BITS, i); } - + for (i = 0; i < 0x2000 - l; i++) { if (TEST_BIT (d->IRAM_BITS, i) && @@ -395,14 +378,10 @@ void S9xSearchForChange (SCheatData *d, S9xCheatComparisonType cmp, BIT_CLEAR (d->IRAM_BITS, i); } } - for (i = 0x20000 - l; i < 0x20000; i++) - BIT_CLEAR (d->WRAM_BITS, i); - for (i = 0x10000 - l; i < 0x10000; i++) - BIT_CLEAR (d->SRAM_BITS, i); } -void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, - S9xCheatDataSize size, uint32 value, +void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, + S9xCheatDataSize size, uint32 value, bool8 is_signed, bool8 update) { int l; @@ -431,7 +410,7 @@ void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->WRAM_BITS, i); } - + for (i = 0; i < 0x10000 - l; i++) { if (TEST_BIT (d->SRAM_BITS, i) && @@ -443,7 +422,7 @@ void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->SRAM_BITS, i); } - + for (i = 0; i < 0x2000 - l; i++) { if (TEST_BIT (d->IRAM_BITS, i) && @@ -469,7 +448,7 @@ void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->WRAM_BITS, i); } - + for (i = 0; i < 0x10000 - l; i++) { if (TEST_BIT (d->SRAM_BITS, i) && @@ -481,7 +460,7 @@ void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, else BIT_CLEAR (d->SRAM_BITS, i); } - + for (i = 0; i < 0x2000 - l; i++) { if (TEST_BIT (d->IRAM_BITS, i) && @@ -494,70 +473,6 @@ void S9xSearchForValue (SCheatData *d, S9xCheatComparisonType cmp, BIT_CLEAR (d->IRAM_BITS, i); } } - for (i = 0x20000 - l; i < 0x20000; i++) - BIT_CLEAR (d->WRAM_BITS, i); - for (i = 0x10000 - l; i < 0x10000; i++) - BIT_CLEAR (d->SRAM_BITS, i); -} - -void S9xSearchForAddress (SCheatData *d, S9xCheatComparisonType cmp, - S9xCheatDataSize size, uint32 value, bool8 update) -{ - int l; - - switch (size) - { - case S9X_8_BITS: l = 0; break; - case S9X_16_BITS: l = 1; break; - case S9X_24_BITS: l = 2; break; - default: - case S9X_32_BITS: l = 3; break; - } - - int i; - - { - - for (i = 0; i < 0x20000 - l; i++) - { - if (TEST_BIT (d->WRAM_BITS, i) && - _C(cmp, i, (int)value)) - { - if (update) - d->CWRAM [i] = d->RAM [i]; - } - else - BIT_CLEAR (d->WRAM_BITS, i); - } - - for (i = 0; i < 0x10000 - l; i++) - { - if (TEST_BIT (d->SRAM_BITS, i) && - _C(cmp, i+0x20000, (int)value)) - { - if (update) - d->CSRAM [i] = d->SRAM [i]; - } - else - BIT_CLEAR (d->SRAM_BITS, i); - } - - for (i = 0; i < 0x2000 - l; i++) - { - if (TEST_BIT (d->IRAM_BITS, i) && - _C(cmp, i+0x30000, (int)value)) - { - if (update) - d->CIRAM [i] = d->FillRAM [i + 0x3000]; - } - else - BIT_CLEAR (d->IRAM_BITS, i); - } - } - for (i = 0x20000 - l; i < 0x20000; i++) - BIT_CLEAR (d->WRAM_BITS, i); - for (i = 0x10000 - l; i < 0x10000; i++) - BIT_CLEAR (d->SRAM_BITS, i); } void S9xOutputCheatSearchResults (SCheatData *d) diff --git a/source/snes9x/cheats.h b/source/snes9x/unused/cheats.h similarity index 87% rename from source/snes9x/cheats.h rename to source/snes9x/unused/cheats.h index 199189ff..3786602a 100644 --- a/source/snes9x/cheats.h +++ b/source/snes9x/unused/cheats.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _CHEATS_H_ #define _CHEATS_H_ @@ -173,7 +154,7 @@ struct SCheat char name [22]; }; -#define MAX_CHEATS 150 +#define MAX_CHEATS 75 struct SCheatData { @@ -185,23 +166,10 @@ struct SCheatData uint8 *RAM; uint8 *FillRAM; uint8 *SRAM; - uint32 ALL_BITS [(0x32000 >> 5)]; -#define WRAM_BITS ALL_BITS -#define SRAM_BITS ALL_BITS + (0x20000 >> 5) -#define IRAM_BITS ALL_BITS + (0x30000 >> 5) - uint8 CWatchRAM [0x32000]; -}; - - -struct Watch { - bool on; - int size; - int format; - uint32 address; - char buf[12]; - char desc[32]; + uint32 WRAM_BITS [0x20000 >> 3]; + uint32 SRAM_BITS [0x10000 >> 3]; + uint32 IRAM_BITS [0x2000 >> 3]; }; -extern Watch watches [16]; typedef enum { @@ -239,8 +207,6 @@ void S9xSearchForChange (SCheatData *, S9xCheatComparisonType cmp, void S9xSearchForValue (SCheatData *, S9xCheatComparisonType cmp, S9xCheatDataSize size, uint32 value, bool8 is_signed, bool8 update); -void S9xSearchForAddress (SCheatData *, S9xCheatComparisonType cmp, - S9xCheatDataSize size, uint32 address, bool8 update); void S9xOutputCheatSearchResults (SCheatData *); #endif diff --git a/source/snes9x/cheats2.cpp b/source/snes9x/unused/cheats2.cpp similarity index 87% rename from source/snes9x/cheats2.cpp rename to source/snes9x/unused/cheats2.cpp index 55fb2ddc..372a1400 100644 --- a/source/snes9x/cheats2.cpp +++ b/source/snes9x/unused/cheats2.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #include #include @@ -167,40 +148,16 @@ #include "cheats.h" #include "memmap.h" -#ifndef INLINE -#define INLINE inline -#endif - extern SCheatData Cheat; -Watch watches [16]; - -// read a byte without altering CPU -INLINE uint8 S9xGetByteFree (uint32 Address) -{ - uint32 Cycles = CPU.Cycles; - uint32 WaitAddress = CPU.WaitAddress; - uint8 rv = S9xGetByte (Address); - CPU.WaitAddress = WaitAddress; - CPU.Cycles = Cycles; - return rv; -} -INLINE void S9xSetByteFree (uint8 Byte, uint32 Address) -{ - uint32 Cycles = CPU.Cycles; - uint32 WaitAddress = CPU.WaitAddress; - S9xSetByte (Byte, Address); - CPU.WaitAddress = WaitAddress; - CPU.Cycles = Cycles; -} void S9xInitCheatData () { Cheat.RAM = Memory.RAM; - Cheat.SRAM = Memory.SRAM; + Cheat.SRAM = ::SRAM; Cheat.FillRAM = Memory.FillRAM; } -void S9xAddCheat (bool8 enable, bool8 save_current_value, +void S9xAddCheat (bool8 enable, bool8 save_current_value, uint32 address, uint8 byte) { if (Cheat.num_cheats < sizeof (Cheat.c) / sizeof (Cheat. c [0])) @@ -214,7 +171,7 @@ void S9xAddCheat (bool8 enable, bool8 save_current_value, #endif if (save_current_value) { - Cheat.c [Cheat.num_cheats].saved_byte = S9xGetByteFree (address); + Cheat.c [Cheat.num_cheats].saved_byte = S9xGetByte (address); Cheat.c [Cheat.num_cheats].saved = TRUE; } Cheat.num_cheats++; @@ -266,7 +223,7 @@ void S9xRemoveCheat (uint32 which1) int block = ((address&0xffffff) >> MEMMAP_SHIFT); uint8 *ptr = Memory.Map [block]; - + if (ptr >= (uint8 *) CMemory::MAP_LAST) *(ptr + (address & 0xffff)) = Cheat.c [which1].saved_byte; else @@ -279,11 +236,11 @@ void S9xApplyCheat (uint32 which1) uint32 address = Cheat.c [which1].address; if (!Cheat.c [which1].saved) - Cheat.c [which1].saved_byte = S9xGetByteFree (address); + Cheat.c [which1].saved_byte = S9xGetByte (address); int block = ((address&0xffffff) >> MEMMAP_SHIFT); uint8 *ptr = Memory.Map [block]; - + if (ptr >= (uint8 *) CMemory::MAP_LAST) *(ptr + (address & 0xffff)) = Cheat.c [which1].byte; else diff --git a/source/snes9x/unused/loadzip.cpp b/source/snes9x/unused/loadzip.cpp index 2eadd097..1d0a7f1a 100644 --- a/source/snes9x/unused/loadzip.cpp +++ b/source/snes9x/unused/loadzip.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifdef UNZIP_SUPPORT /**********************************************************************************************/ /* Loadzip.CPP */ @@ -180,7 +161,7 @@ #include "snes9x.h" #include "memmap.h" -#include "unzip/unzip.h" +#include "unzip.h" #include #include #include @@ -191,7 +172,7 @@ bool8 LoadZip(const char* zipname, { *TotalFileSize = 0; *headers = 0; - + unzFile file = unzOpen(zipname); if(file == NULL) return (FALSE); @@ -222,7 +203,7 @@ bool8 LoadZip(const char* zipname, port = unzGoToNextFile(file); continue; } - + if ((int) info.uncompressed_size > filesize) { strcpy(filename,name); @@ -249,14 +230,14 @@ bool8 LoadZip(const char* zipname, char *ext = strrchr(filename,'.'); if(ext) ext++; else ext = tmp; - + uint8 *ptr = buffer; bool8 more = FALSE; printf("Using ROM %s in %s\n", filename, zipname); unzLocateFile(file,filename,1); unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0); - + if( unzOpenCurrentFile(file) != UNZ_OK ) { unzClose(file); @@ -267,14 +248,17 @@ bool8 LoadZip(const char* zipname, { assert(info.uncompressed_size <= CMemory::MAX_ROM_SIZE + 512); int FileSize = info.uncompressed_size; - + + int calc_size = FileSize / 0x2000; + calc_size *= 0x2000; + int l = unzReadCurrentFile(file,ptr,FileSize); if(unzCloseCurrentFile(file) == UNZ_CRCERROR) { unzClose(file); return (FALSE); } - + if(l <= 0 || l != FileSize) { unzClose(file); @@ -296,7 +280,13 @@ bool8 LoadZip(const char* zipname, return (FALSE); } - FileSize = (int)Memory.HeaderRemove((uint32)FileSize, *headers, ptr); + if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || + Settings.ForceHeader) + { + memmove (ptr, ptr + 512, calc_size); + (*headers)++; + FileSize -= 512; + } ptr += FileSize; (*TotalFileSize) += FileSize; @@ -322,7 +312,7 @@ bool8 LoadZip(const char* zipname, } else more = FALSE; - + if(more) { if( unzLocateFile(file,filename,1) != UNZ_OK || @@ -331,9 +321,9 @@ bool8 LoadZip(const char* zipname, break; printf(" ... and %s in %s\n", filename, zipname); } - + } while(more); - + unzClose(file); return (TRUE); } diff --git a/source/snes9x/unused/logger.cpp b/source/snes9x/unused/logger.cpp deleted file mode 100644 index 2ea1ad97..00000000 --- a/source/snes9x/unused/logger.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - -#include -#include -#include "snes9x.h" -#include "gfx.h" -#include "soundux.h" -#include "movie.h" -#include "display.h" -#include "logger.h" - -#if !(defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP)) -#define __builtin_expect(exp,c) ((exp)!=(c)) -#endif - -int dumpstreams = 0; -int maxframes = -1; - -static int resetno = 0; -static int framecounter = 0; - -int fastforwardpoint = -1; -int fastforwarddistance = 0; - -int keypressscreen = 0; - -static int drift = 0; - -FILE *video=NULL, *audio=NULL; -char autodemo[128] = ""; - -int Logger_FrameCounter() -{ - return framecounter; -} - -void Logger_NextFrame() -{ - framecounter++; -} - -void breakpoint() -{ - -} - -void ResetLogger() -{ - char buffer[256*224*4]; - - if (!dumpstreams) - return; - - framecounter = 0; - drift=0; - - if (video) - fclose(video); - if (audio) - fclose(audio); - - sprintf(buffer, "videostream%d.dat", resetno); - video = fopen(buffer, "wb"); - if (!video) - { - printf("Opening %s failed. Logging cancelled.\n", buffer); - return; - } - - sprintf(buffer, "audiostream%d.dat", resetno); - audio = fopen(buffer, "wb"); - if (!audio) - { - printf("Opening %s failed. Logging cancelled.\n", buffer); - fclose(video); - return; - } - - char *logo = getenv("LOGO"); - if (!logo) - logo = "logo.dat"; - FILE *l = fopen(logo, "rb"); - if (l) - { - const int soundsize = (so.sixteen_bit ? 2 : 1)*(so.stereo?2:1)*so.playback_rate * Settings.FrameTime / 1000000; - printf("Soundsize: %d\n", soundsize); - while (!feof(l)) - { - if (fread(buffer, 1024,224, l) != 224) - break; - VideoLogger(buffer, 256, 224, 4,1024); - memset(buffer, 0, soundsize); - AudioLogger(buffer, soundsize); - } - fclose(l); - } - resetno++; -} - -char message[128]; -int messageframe; - - -void VideoLogger(void *pixels, int width, int height, int depth, int bytes_per_line) -{ - int fc = S9xMovieGetFrameCounter(); - if (fc > 0) - framecounter = fc; - else - framecounter++; - - if (video) - { - int i; - char *data = (char*)pixels; - for (i=0; i < height; i++) - fwrite(data + i*bytes_per_line, depth, width, video); - fflush(video); - fflush(audio); - drift++; - - if (maxframes > 0 && __builtin_expect(framecounter >= maxframes, 0)) - { - printf("-maxframes hit\ndrift:%d\n",drift); - S9xExit(); - } - - } - - if (Settings.DisplayPressedKeys==1 || keypressscreen) - { - uint16 MovieGetJoypad(int i); - - int buttons = MovieGetJoypad(0); - static char buffer[128]; - - // This string spacing pattern is optimized for the 256 pixel wide screen. - sprintf(buffer, "%s %s %s %s %s %s %c%c%c%c%c%c", - buttons & SNES_START_MASK ? "Start" : "_____", - buttons & SNES_SELECT_MASK ? "Select" : "______", - buttons & SNES_UP_MASK ? "Up" : "__", - buttons & SNES_DOWN_MASK ? "Down" : "____", - buttons & SNES_LEFT_MASK ? "Left" : "____", - buttons & SNES_RIGHT_MASK ? "Right" : "_____", - buttons & SNES_A_MASK ? 'A':'_', - buttons & SNES_B_MASK ? 'B':'_', - buttons & SNES_X_MASK ? 'X':'_', - buttons & SNES_Y_MASK ? 'Y':'_', - buttons & SNES_TL_MASK ? 'L':'_', - buttons & SNES_TR_MASK ? 'R':'_' - /*framecounter*/); - if (Settings.DisplayPressedKeys==1) - fprintf(stderr, "%s %d \r", buffer, framecounter); - //if (keypressscreen) - S9xSetInfoString(buffer); - } - - if (__builtin_expect(messageframe >= 0 && framecounter == messageframe, 0)) - { - S9xMessage(S9X_INFO, S9X_MOVIE_INFO, message); - GFX.InfoStringTimeout = 300; - messageframe = -1; - } - -/* if (__builtin_expect(fastforwardpoint >= 0 && framecounter >= fastforwardpoint, 0)) - { - Settings.FramesToSkip = fastforwarddistance; - fastforwardpoint = -1; - }*/ -} - - -void AudioLogger(void *samples, int length) -{ - if (audio) - fwrite(samples, 1, length, audio); - drift--; -} diff --git a/source/snes9x/unused/makeasm.bat b/source/snes9x/unused/makeasm.bat deleted file mode 100644 index 856d4d1a..00000000 --- a/source/snes9x/unused/makeasm.bat +++ /dev/null @@ -1,14 +0,0 @@ -@REM gcc -c -DEXECUTE_SUPERFX_PER_LINE -DMICROSOFT_C -DSPC700_C -DCPU_SHUTDOWN -DSPC700_SHUTDOWN -Ii386 i386/cpuexec.S -o i386/cpuexec.obj -@REM gcc -c -DEXECUTE_SUPERFX_PER_LINE -DMICROSOFT_C -DSPC700_C -DCPU_SHUTDOWN -DSPC700_SHUTDOWN -Ii386 i386/cpuops.S -o i386/cpuops.obj -@REM gcc -c -DEXECUTE_SUPERFX_PER_LINE -DMICROSOFT_C -DSPC700_C -DCPU_SHUTDOWN -DSPC700_SHUTDOWN -Ii386 i386/sa1ops.S -o i386/sa1ops.obj -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/zsnes.obj i386/zsnes.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/fxemu2b.obj i386/fxemu2b.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/fxtable.obj i386/fxtable.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/fxemu2.obj i386/fxemu2.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/fxemu2c.obj i386/fxemu2c.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/sfxproc.obj i386/sfxproc.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/spc.obj i386/spc.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/zsnesc4.obj i386/zsnesc4.asm -@REM nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/c4.obj i386/c4.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/2xsaimmx.obj i386/2xsaimmx.asm -nasmw -d__DJGPP__=1 -dZSNES_FX -f win32 -i . -i i386 -o i386/bilinear.obj i386/bilinear.asm diff --git a/source/snes9x/unused/movie.cpp b/source/snes9x/unused/movie.cpp index 09ed1554..74d0ddce 100644 --- a/source/snes9x/unused/movie.cpp +++ b/source/snes9x/unused/movie.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - // Input recording/playback code // (c) Copyright 2004 blip @@ -169,7 +150,6 @@ #endif #include #include -#include #if defined(__unix) || defined(__linux) || defined(__sun) || defined(__DJGPP) || defined(__MACOSX__) #include @@ -183,7 +163,6 @@ #ifndef W_OK #define W_OK 2 #endif -#define ftruncate chsize #endif #include "movie.h" @@ -191,31 +170,12 @@ #include "memmap.h" #include "cpuexec.h" #include "snapshot.h" -#include "controls.h" -#include "language.h" -#ifdef NETPLAY_SUPPORT -#include "netplay.h" -#endif #define SMV_MAGIC 0x1a564d53 // SMV0x1a -#define SMV_VERSION 4 -#define SMV_HEADER_SIZE 64 -#define SMV_EXTRAROMINFO_SIZE (3 + sizeof(uint32) + 23) +#define SMV_VERSION 2 +#define SMV_HEADER_SIZE 32 #define CONTROLLER_DATA_SIZE 2 #define BUFFER_GROWTH_SIZE 4096 -#define PERIPHERAL_SUPPORT -#ifdef PERIPHERAL_SUPPORT - #define MOUSE_DATA_SIZE 5 - #define SCOPE_DATA_SIZE 6 - #define JUSTIFIER_DATA_SIZE 11 -#endif - -// HACK: reduce movie size by not storing changes that can only affect polled input in the movie for these types, because currently no port sets these types to polling -#define SKIPPED_POLLING_PORT_TYPE(x) ((x==CTL_NONE)||(x==CTL_JOYPAD)||(x==CTL_MP5)) - -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif enum MovieState { @@ -237,80 +197,33 @@ static struct SMovie uint32 RerecordCount; uint8 ControllersMask; uint8 Opts; - uint8 SyncFlags; bool8 ReadOnly; - uint32 BytesPerSample; + uint32 BytesPerFrame; uint8* InputBuffer; uint32 InputBufferSize; uint8* InputBufferPtr; - - uint32 ROMCRC32; - char ROMName [23]; - - uint32 CurrentSample; - uint32 MaxSample; - uint8 PortType[2]; - int8 PortIDs[2][4]; - - bool8 RecordedThisSession; - uint32 Version; + bool8 FrameDisplay; + char FrameDisplayString[256]; } Movie; /* -// For illustration: - struct MovieFileHeader - { - uint32 magic; // SMV0x1a - uint32 version; // for Snes9x 1.51 this must be 4. In Snes9x 1.43 it was 1. - uint32 uid; // used to match savestates to a particular movie... this is also the date/time of first recording - uint32 rerecord_count; - uint32 length_frames; - uint8 flags[4]; // (ControllersMask, Opts, Reserved, SyncFlags) - uint32 offset_to_savestate; // pointer to embedded savestate or SRAM - uint32 offset_to_controller_data; // pointer to controller data - - uint32 length_samples; // number of recorded input samples, may be more than length_frames for peripheral-using games - uint8 PortType[2]; // for each controller port, 0=NONE, 1=JOYPAD, 2=MOUSE, 3=SUPERSCOPE, 4=JUSTIFIER, 5=MULTITAP - int8 PortIDs[2][4]; // for each port, then for each possible controller in the port, the controller ID number counting up from 0, or -1 if unplugged - uint8 reserved[18]; - }; - // sizeof(MovieFileHeader) == 64 - -// after the header comes extra metadata, i.e. author info - // sizeof(metadata) = (offset_to_savestate - sizeof(MovieFileHeader)) - sizeof(ExtraRomInfo); - // that should be an even number of bytes because the author info consists of 2-byte characters - -// after the metadata comes extra info about the ROM used for recording - struct ExtraRomInfo - { - uint8 reserved[3]; - uint32 romCRC32; - uint8 romName[23]; - }; - // sizeof(ExtraRomInfo) == 30 - -// after that comes the savestate or SRAM data (depending on the Opts flag) - // sizeof(SaveData) <= offset_to_controller_data - offset_to_savestate - -// after that comes the controller data - // sizeof(ControllerData) == length_samples * sizeof(InputSample) - // sizeof(InputSample) == 2*(sum of bits in ControllersMask) + 5*num_mouse_ports + 6*num_superscope_ports + 11*num_justifier_ports - + For illustration: +struct MovieFileHeader +{ + uint32 magic; // SMV0x1a + uint32 version; + uint32 uid; // used to match savestates to a particular movie + uint32 rerecord_count; + uint32 length_frames; + uint8 flags[4]; + uint32 offset_to_savestate; // smvs have an embedded savestate + uint32 offset_to_controller_data; + // after the header comes extra metadata + // sizeof(metadata) = offset_to_savestate - sizeof(MovieFileHeader) +}; */ -// some state for peripherals etc. (playback) -#ifdef PERIPHERAL_SUPPORT -uint8 prevPortType[2]; -int8 prevPortIDs[2][4]; -bool8 prevMouseMaster; -bool8 prevSuperScopeMaster; -bool8 prevJustifierMaster; -bool8 prevMultiPlayer5Master; -#endif -bool8 prevForcePal, prevPal, prevForceNTSC, delayedPrevRestore=false; -bool8 prevUpAndDown, prevSoundEnvelopeHeightReading, prevFakeMuteFix, prevSoundSync, prevCPUShutdown; - -static int bytes_per_sample() +static int bytes_per_frame() { int i; int num_controllers; @@ -324,57 +237,31 @@ static int bytes_per_sample() } } - int bytes = CONTROLLER_DATA_SIZE*num_controllers; - -#ifdef PERIPHERAL_SUPPORT - for(int port=0; port<2; port++) - { - if(Movie.PortType[port] == CTL_MOUSE) bytes += MOUSE_DATA_SIZE; - if(Movie.PortType[port] == CTL_SUPERSCOPE) bytes += SCOPE_DATA_SIZE; - if(Movie.PortType[port] == CTL_JUSTIFIER) bytes += JUSTIFIER_DATA_SIZE; - // MP5 support is already handled by the regular controllers code - } -#endif - - return bytes; + return CONTROLLER_DATA_SIZE*num_controllers; } -uint32 Read32(const uint8*& ptr) +static inline uint32 Read32(const uint8*& ptr) { uint32 v=(ptr[0] | (ptr[1]<<8) | (ptr[2]<<16) | (ptr[3]<<24)); ptr += 4; return v; } -uint16 Read16(const uint8*& ptr) /* const version */ +static inline uint16 Read16(const uint8*& ptr) /* const version */ { uint16 v=(ptr[0] | (ptr[1]<<8)); ptr += 2; return v; } -uint16 Read16(uint8*& ptr) /* non-const version */ +static inline uint16 Read16(uint8*& ptr) /* non-const version */ { uint16 v=(ptr[0] | (ptr[1]<<8)); ptr += 2; return v; } -static inline uint8 Read8(const uint8*& ptr) /* const version */ -{ - uint8 v=(ptr[0]); - ptr++; - return v; -} - -static inline uint8 Read8(uint8*& ptr) /* non-const version */ -{ - uint8 v=(ptr[0]); - ptr++; - return v; -} - -void Write32(uint32 v, uint8*& ptr) +static void Write32(uint32 v, uint8*& ptr) { ptr[0]=(uint8)(v&0xff); ptr[1]=(uint8)((v>>8)&0xff); @@ -383,19 +270,13 @@ void Write32(uint32 v, uint8*& ptr) ptr += 4; } -void Write16(uint16 v, uint8*& ptr) +static void Write16(uint16 v, uint8*& ptr) { ptr[0]=(uint8)(v&0xff); ptr[1]=(uint8)((v>>8)&0xff); ptr += 2; } -static inline void Write8(uint8 v, uint8*& ptr) -{ - ptr[0]=(uint8)(v); - ptr++; -} - static int read_movie_header(FILE* fd, SMovie* movie) { uint8 header[SMV_HEADER_SIZE]; @@ -408,81 +289,19 @@ static int read_movie_header(FILE* fd, SMovie* movie) return WRONG_FORMAT; uint32 version=Read32(ptr); - if(version>SMV_VERSION) + if(version!=SMV_VERSION) return WRONG_VERSION; - // we can still get this basic info from v1 movies movie->MovieId=Read32(ptr); movie->RerecordCount=Read32(ptr); movie->MaxFrame=Read32(ptr); - movie->Version=version; - - int i, p, j; - for(j = 0; j < 2; j++) - { - if((j == 0 && version != 3) || (j == 1 && version == 3)) - { - movie->ControllersMask=Read8(ptr); - movie->Opts=Read8(ptr); - Read8(ptr); // reserved byte - movie->SyncFlags=Read8(ptr); - - movie->SaveStateOffset=Read32(ptr); - movie->ControllerDataOffset=Read32(ptr); - } - - // not part of original v1 SMV format: - - if((j == 1 && version > 3) || (j == 0 && version == 3)) - { - movie->MaxSample=Read32(ptr); - movie->PortType[0]=Read8(ptr); - movie->PortType[1]=Read8(ptr); - for(p=0;p<2;p++) - for(i=0;i<4;i++) - movie->PortIDs[p][i]=Read8(ptr); - } - } - - if(version<3) - return WRONG_VERSION; - - // needs to be at least 1 sample per frame. So, assume that to make hex editing easier, at least for non-peripheral-using movies. - if(movie->MaxSample < movie->MaxFrame) - movie->MaxSample = movie->MaxFrame; - - - ptr += 18; // reserved bytes + movie->ControllersMask=*ptr++; + movie->Opts=*ptr++; + ptr += 2; - assert(ptr-header==SMV_HEADER_SIZE); - - return SUCCESS; -} - -static int read_movie_extrarominfo(FILE* fd, SMovie* movie) -{ - if((movie->SyncFlags & MOVIE_SYNC_HASROMINFO) != 0) - { - fseek(fd, movie->SaveStateOffset - SMV_EXTRAROMINFO_SIZE, SEEK_SET); - - uint8 extraRomInfo[SMV_EXTRAROMINFO_SIZE]; - if(fread(extraRomInfo, 1, SMV_EXTRAROMINFO_SIZE, fd) != SMV_EXTRAROMINFO_SIZE) - return WRONG_FORMAT; - - const uint8* ptr=extraRomInfo; - - ptr ++; // zero byte - ptr ++; // zero byte - ptr ++; // zero byte - movie->ROMCRC32=Read32(ptr); - strncpy(movie->ROMName,(const char*)ptr,23); ptr += 23; - } - else - { - movie->ROMCRC32=Memory.ROMCRC32; - strncpy(movie->ROMName,(const char*)Memory.ROMName,23); - } + movie->SaveStateOffset=Read32(ptr); + movie->ControllerDataOffset=Read32(ptr); return SUCCESS; } @@ -498,177 +317,23 @@ static void write_movie_header(FILE* fd, const SMovie* movie) Write32(movie->RerecordCount, ptr); Write32(movie->MaxFrame, ptr); - Write8(movie->ControllersMask, ptr); - Write8(movie->Opts, ptr); - Write8(0, ptr); // reserved byte - Write8(movie->SyncFlags, ptr); + *ptr++=movie->ControllersMask; + *ptr++=movie->Opts; + *ptr++=0; + *ptr++=0; Write32(movie->SaveStateOffset, ptr); Write32(movie->ControllerDataOffset, ptr); - // not part of original v1 SMV format: - - Write32(movie->MaxSample, ptr); - Write8(movie->PortType[0], ptr); - Write8(movie->PortType[1], ptr); - - int i, p; - for(p=0;p<2;p++) - for(i=0;i<4;i++) - Write8(movie->PortIDs[p][i], ptr); - - // 18 reserved bytes, could be anything, ignored by this version when reading - for(i=0;i<18-4;i++) - Write8(0, ptr); - Write32(movie->RerecordCount/2, ptr); // why not... - - assert(ptr-header==SMV_HEADER_SIZE); - fwrite(header, 1, SMV_HEADER_SIZE, fd); - - assert(!ferror(fd)); -} - -static void write_movie_extrarominfo(FILE* fd, const SMovie* movie) -{ - if((movie->SyncFlags & MOVIE_SYNC_HASROMINFO) != 0) // should be true... - { - uint8 extraRomInfo [SMV_EXTRAROMINFO_SIZE]; - uint8* ptr = extraRomInfo; - - *ptr++=0; // zero byte - *ptr++=0; // zero byte - *ptr++=0; // zero byte - Write32(movie->ROMCRC32, ptr); - strncpy((char*)ptr,movie->ROMName,23); ptr += 23; - - fwrite(extraRomInfo, 1, SMV_EXTRAROMINFO_SIZE, fd); - assert(!ferror(fd)); - } } static void flush_movie() { - if(!Movie.File) - return; - fseek(Movie.File, 0, SEEK_SET); write_movie_header(Movie.File, &Movie); fseek(Movie.File, Movie.ControllerDataOffset, SEEK_SET); - fwrite(Movie.InputBuffer, 1, Movie.BytesPerSample*(Movie.MaxSample+1), Movie.File); - assert(!ferror(Movie.File)); -} - -static void store_previous_settings() -{ -#ifdef PERIPHERAL_SUPPORT - for(int i=0; i<2; i++){ - enum controllers pt; - S9xGetController(i, &pt, &prevPortIDs[i][0],&prevPortIDs[i][1],&prevPortIDs[i][2],&prevPortIDs[i][3]); - prevPortType[i] = (uint8) pt; - } - prevMouseMaster = Settings.MouseMaster; - prevSuperScopeMaster = Settings.SuperScopeMaster; - prevJustifierMaster = Settings.JustifierMaster; - prevMultiPlayer5Master = Settings.MultiPlayer5Master; -#endif - if(!delayedPrevRestore) - { - prevPal = Settings.PAL; - prevCPUShutdown = Settings.ShutdownMaster; - } - delayedPrevRestore = false; - prevForcePal = Settings.ForcePAL; - prevForceNTSC = Settings.ForceNTSC; - prevUpAndDown = Settings.UpAndDown; - prevSoundEnvelopeHeightReading = Settings.SoundEnvelopeHeightReading; - prevFakeMuteFix = Settings.FakeMuteFix; - prevSoundSync = Settings.SoundSync; -} - -static void restore_previous_settings() -{ -#ifdef PERIPHERAL_SUPPORT - Settings.MouseMaster = prevMouseMaster; - Settings.SuperScopeMaster = prevSuperScopeMaster; - Settings.JustifierMaster = prevJustifierMaster; - Settings.MultiPlayer5Master = prevMultiPlayer5Master; - S9xSetController(0, (enum controllers)prevPortType[0], prevPortIDs[0][0],prevPortIDs[0][1],prevPortIDs[0][2],prevPortIDs[0][3]); - S9xSetController(1, (enum controllers)prevPortType[1], prevPortIDs[1][0],prevPortIDs[1][1],prevPortIDs[1][2],prevPortIDs[1][3]); -#endif - Settings.ForcePAL = prevForcePal; - Settings.ForceNTSC = prevForceNTSC; - Settings.SoundEnvelopeHeightReading = prevSoundEnvelopeHeightReading; - Settings.FakeMuteFix = prevFakeMuteFix; -// Settings.PAL = prevPal; // changing this after the movie while it's still emulating would be bad -// Settings.ShutdownMaster = prevCPUShutdown; // changing this after the movie while it's still emulating would be bad - delayedPrevRestore = true; // wait to change the above 2 settings until later -// Settings.UpAndDown = prevUpAndDown; // doesn't actually affect synchronization, so leave the setting alone; the port can change it if it wants -// Settings.SoundSync = prevSoundSync; // doesn't seem to affect synchronization, so leave the setting alone; the port can change it if it wants -} - -static void store_movie_settings() -{ -#ifdef PERIPHERAL_SUPPORT - for(int i=0; i<2; i++){ - enum controllers pt; - S9xGetController(i, &pt, &Movie.PortIDs[i][0],&Movie.PortIDs[i][1],&Movie.PortIDs[i][2],&Movie.PortIDs[i][3]); - Movie.PortType[i] = (uint8) pt; - } - if(!Movie.PortType[0] && !Movie.PortType[1]) - fprintf(stderr, "WARNING: S9xMovieCreate: no controller ports set\n"); -#endif - if(Settings.PAL) - Movie.Opts |= MOVIE_OPT_PAL; - else - Movie.Opts &= ~MOVIE_OPT_PAL; - Movie.SyncFlags = MOVIE_SYNC_DATA_EXISTS | MOVIE_SYNC_HASROMINFO; - if(Settings.UpAndDown) Movie.SyncFlags |= MOVIE_SYNC_LEFTRIGHT; - if(Settings.SoundEnvelopeHeightReading) Movie.SyncFlags |= MOVIE_SYNC_VOLUMEENVX; - if(Settings.FakeMuteFix || !Settings.APUEnabled) Movie.SyncFlags |= MOVIE_SYNC_FAKEMUTE; - if(Settings.SoundSync) Movie.SyncFlags |= MOVIE_SYNC_SYNCSOUND; - if(!Settings.ShutdownMaster) Movie.SyncFlags |= MOVIE_SYNC_NOCPUSHUTDOWN; -} - -static void restore_movie_settings() -{ -#ifdef PERIPHERAL_SUPPORT - Settings.MouseMaster = (Movie.PortType[0] == CTL_MOUSE || Movie.PortType[1] == CTL_MOUSE); - Settings.SuperScopeMaster = (Movie.PortType[0] == CTL_SUPERSCOPE || Movie.PortType[1] == CTL_SUPERSCOPE); - Settings.JustifierMaster = (Movie.PortType[0] == CTL_JUSTIFIER || Movie.PortType[1] == CTL_JUSTIFIER); - Settings.MultiPlayer5Master = (Movie.PortType[0] == CTL_MP5 || Movie.PortType[1] == CTL_MP5); - S9xSetController(0, (enum controllers)Movie.PortType[0], Movie.PortIDs[0][0],Movie.PortIDs[0][1],Movie.PortIDs[0][2],Movie.PortIDs[0][3]); - S9xSetController(1, (enum controllers)Movie.PortType[1], Movie.PortIDs[1][0],Movie.PortIDs[1][1],Movie.PortIDs[1][2],Movie.PortIDs[1][3]); -#endif - if(Movie.Opts & MOVIE_OPT_PAL) - { - Settings.ForcePAL = Settings.PAL = TRUE; // OK to change while starting playing a movie because either we are re-loading the ROM or we are entering a state that already had this setting set - Settings.ForceNTSC = FALSE; - } - else - { - Settings.ForcePAL = Settings.PAL = FALSE; // OK to change while starting playing a movie because either we are re-loading the ROM or we are entering a state that already had this setting set - Settings.ForceNTSC = TRUE; - } - Settings.SoundEnvelopeHeightReading = (Movie.SyncFlags & MOVIE_SYNC_VOLUMEENVX) ? TRUE : FALSE; - Settings.FakeMuteFix = (Movie.SyncFlags & MOVIE_SYNC_FAKEMUTE) ? TRUE : FALSE; - Settings.ShutdownMaster = (Movie.SyncFlags & MOVIE_SYNC_NOCPUSHUTDOWN) ? FALSE : TRUE; // OK to change while starting playing a movie because either we are re-loading the ROM or we are entering a state that already had this setting set -// Settings.UpAndDown = (Movie.SyncFlags & MOVIE_SYNC_LEFTRIGHT) ? TRUE : FALSE; // doesn't actually affect synchronization, so leave the setting alone; the port can change it if it wants -// Settings.SoundSync = (Movie.SyncFlags & MOVIE_SYNC_SYNCSOUND) ? TRUE : FALSE; // doesn't seem to affect synchronization, so leave the setting alone; the port can change it if it wants -} - -// file must still be open for this to work -static void truncate_movie() -{ - if(!Settings.MovieTruncate || !Movie.File) - return; - - assert(Movie.SaveStateOffset <= Movie.ControllerDataOffset); - if(Movie.SaveStateOffset > Movie.ControllerDataOffset) - return; - - const unsigned long length = Movie.ControllerDataOffset + Movie.BytesPerSample * (Movie.MaxSample + 1); - ftruncate(fileno(Movie.File), length); + fwrite(Movie.InputBuffer, 1, Movie.BytesPerFrame*(Movie.MaxFrame+1), Movie.File); } static void change_state(MovieState new_state) @@ -681,21 +346,19 @@ static void change_state(MovieState new_state) flush_movie(); } + Movie.State=new_state; + if(new_state==MOVIE_STATE_NONE) { - // truncate movie to MaxSample length if Settings.MovieTruncate is true - truncate_movie(); - fclose(Movie.File); Movie.File=NULL; - - if(S9xMoviePlaying() || S9xMovieRecording()) // even if recording, it could have been switched to from playback - { - restore_previous_settings(); - } + // FIXME: truncate movie to MaxFrame length + /* truncate() could be used, if it's certain + * that the savestate block is never after + * the controller data block. It is not guaranteed + * by the format. + */ } - - Movie.State=new_state; } static void reserve_buffer_space(uint32 space_needed) @@ -714,41 +377,10 @@ static void reserve_buffer_space(uint32 space_needed) /* accessors into controls.cpp static variables */ uint16 MovieGetJoypad(int i); void MovieSetJoypad(int i, uint16 buttons); -#ifdef PERIPHERAL_SUPPORT -bool MovieGetMouse(int i, uint8 out [MOUSE_DATA_SIZE]); -void MovieSetMouse(int i, const uint8 in [MOUSE_DATA_SIZE], bool inPolling); -bool MovieGetScope(int i, uint8 out [SCOPE_DATA_SIZE]); -void MovieSetScope(int i, const uint8 in [SCOPE_DATA_SIZE]); -bool MovieGetJustifier(int i, uint8 out [JUSTIFIER_DATA_SIZE]); -void MovieSetJustifier(int i, const uint8 in [JUSTIFIER_DATA_SIZE]); -#endif -static void read_frame_controller_data(bool addFrame) +static void read_frame_controller_data() { int i; - - // one sample of all 1 bits = reset code - // (the SNES controller doesn't have enough buttons to possibly generate this sequence) - // (a single bit indicator was not used, to avoid having to special-case peripheral recording here) - if(Movie.InputBufferPtr[0] == 0xFF) - { - bool reset = true; - for(i=1; i<(int)Movie.BytesPerSample; i++) - { - if(Movie.InputBufferPtr[i] != 0xFF) - { - reset = false; - break; - } - } - if(reset) - { - Movie.InputBufferPtr += Movie.BytesPerSample; - S9xSoftReset(); - return; - } - } - for(i=0; i<8; ++i) { if(Movie.ControllersMask & (1<0) { uint8 meta_buf[MOVIE_MAX_METADATA * sizeof(uint16)]; - for(int i=0; i=Movie.MaxFrame) { - reserve_buffer_space((uint32)((Movie.InputBufferPtr+Movie.BytesPerSample)-Movie.InputBuffer)); - memset(Movie.InputBufferPtr, 0xFF, Movie.BytesPerSample); - Movie.InputBufferPtr += Movie.BytesPerSample; - Movie.MaxSample = ++Movie.CurrentSample; - Movie.MaxFrame = ++Movie.CurrentFrame; - fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File); - assert(!ferror(Movie.File)); + change_state(MOVIE_STATE_NONE); + S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_END); + return; } - break; - default: break; - } -} - -void S9xMovieUpdate (bool addFrame) -{ -movieUpdateStart: - switch(Movie.State) - { - case MOVIE_STATE_PLAY: + else { - if(Movie.CurrentFrame>=Movie.MaxFrame || Movie.CurrentSample>=Movie.MaxSample) - { - if(!Movie.RecordedThisSession) - { - // stop movie; it reached the end - change_state(MOVIE_STATE_NONE); - S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_END); - return; - } - else - { - // if user has been recording this movie since the last time it started playing, - // they probably don't want the movie to end now during playback, - // so switch back to recording when it reaches the end - change_state(MOVIE_STATE_RECORD); - S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_RECORD); - fseek(Movie.File, Movie.ControllerDataOffset+(Movie.BytesPerSample * (Movie.CurrentSample+1)), SEEK_SET); - Settings.Paused = true; // also pause so it doesn't keep going unless they want it to - goto movieUpdateStart; - } - } - else + if(Movie.FrameDisplay) { - if(addFrame) - S9xUpdateFrameCounter(); - else if(SKIPPED_POLLING_PORT_TYPE(Movie.PortType[0]) && SKIPPED_POLLING_PORT_TYPE(Movie.PortType[1])) - return; - - read_frame_controller_data(addFrame); - ++Movie.CurrentSample; - if(addFrame) - ++Movie.CurrentFrame; + sprintf(Movie.FrameDisplayString, "Playing frame: %d", Movie.CurrentFrame); + S9xMessage (S9X_INFO, S9X_MOVIE_INFO, Movie.FrameDisplayString); } + read_frame_controller_data(); + ++Movie.CurrentFrame; } break; - case MOVIE_STATE_RECORD: + case MOVIE_STATE_RECORD: { - if(addFrame) - S9xUpdateFrameCounter(); - else if(SKIPPED_POLLING_PORT_TYPE(Movie.PortType[0]) && SKIPPED_POLLING_PORT_TYPE(Movie.PortType[1])) - return; - + if(Movie.FrameDisplay) + { + sprintf(Movie.FrameDisplayString, "Recording frame: %d", Movie.CurrentFrame); + S9xMessage (S9X_INFO, S9X_MOVIE_INFO, Movie.FrameDisplayString); + } write_frame_controller_data(); - Movie.MaxSample = ++Movie.CurrentSample; - if(addFrame) - Movie.MaxFrame = ++Movie.CurrentFrame; - fwrite((Movie.InputBufferPtr - Movie.BytesPerSample), 1, Movie.BytesPerSample, Movie.File); - assert(!ferror(Movie.File)); - - Movie.RecordedThisSession = true; + ++Movie.CurrentFrame; + Movie.MaxFrame=Movie.CurrentFrame; + fwrite((Movie.InputBufferPtr - Movie.BytesPerFrame), 1, Movie.BytesPerFrame, Movie.File); } break; default: - if(addFrame) - S9xUpdateFrameCounter(); break; } } @@ -1223,8 +641,6 @@ void S9xMovieStop (bool8 suppress_message) int S9xMovieGetInfo (const char* filename, struct MovieInfo* info) { - flush_movie(); - FILE* fd; int result; SMovie local_movie; @@ -1234,22 +650,13 @@ int S9xMovieGetInfo (const char* filename, struct MovieInfo* info) if(!(fd=fopen(filename, "rb"))) return FILE_NOT_FOUND; - result = read_movie_header(fd, &local_movie); + if((result=(read_movie_header(fd, &local_movie)))!=SUCCESS) + return result; - // we can still get this basic info from older, unsupported movies (v1 movies) info->TimeCreated=(time_t)local_movie.MovieId; - info->RerecordCount=local_movie.RerecordCount; info->LengthFrames=local_movie.MaxFrame; - info->Version=local_movie.Version; - - if(result!=SUCCESS) - return result; - - info->LengthSamples=local_movie.MaxSample; - info->PortType[0]=local_movie.PortType[0]; - info->PortType[1]=local_movie.PortType[1]; + info->RerecordCount=local_movie.RerecordCount; info->Opts=local_movie.Opts; - info->SyncFlags=local_movie.SyncFlags; info->ControllersMask=local_movie.ControllersMask; if(local_movie.SaveStateOffset > SMV_HEADER_SIZE) @@ -1257,9 +664,7 @@ int S9xMovieGetInfo (const char* filename, struct MovieInfo* info) uint8 meta_buf[MOVIE_MAX_METADATA * sizeof(uint16)]; int i; - int curRomInfoSize = (local_movie.SyncFlags & MOVIE_SYNC_HASROMINFO) != 0 ? SMV_EXTRAROMINFO_SIZE : 0; - - metadata_length=((int)local_movie.SaveStateOffset-SMV_HEADER_SIZE-curRomInfoSize)/sizeof(uint16); + metadata_length=((int)local_movie.SaveStateOffset-SMV_HEADER_SIZE)/sizeof(uint16); metadata_length=(metadata_length>=MOVIE_MAX_METADATA) ? MOVIE_MAX_METADATA-1 : metadata_length; metadata_length=(int)fread(meta_buf, sizeof(uint16), metadata_length, fd); @@ -1275,11 +680,6 @@ int S9xMovieGetInfo (const char* filename, struct MovieInfo* info) info->Metadata[0]='\0'; } - read_movie_extrarominfo(fd, &local_movie); - - info->ROMCRC32=local_movie.ROMCRC32; - strncpy(info->ROMName,local_movie.ROMName,23); - fclose(fd); if(access(filename, W_OK)) @@ -1292,19 +692,6 @@ bool8 S9xMovieActive () { return (Movie.State!=MOVIE_STATE_NONE); } -bool8 S9xMoviePlaying () -{ - return (Movie.State==MOVIE_STATE_PLAY); -} -bool8 S9xMovieRecording () -{ - return (Movie.State==MOVIE_STATE_RECORD); -} - -uint8 S9xMovieControllers () -{ - return Movie.ControllersMask; -} bool8 S9xMovieReadOnly () { @@ -1338,22 +725,13 @@ uint32 S9xMovieGetFrameCounter () return Movie.CurrentFrame; } -void S9xMovieToggleRecState() -{ - Movie.ReadOnly=!Movie.ReadOnly; - - if (Movie.ReadOnly) - S9xMessage(S9X_INFO, S9X_MOVIE_INFO, "Movie is now read-only."); - else - S9xMessage(S9X_INFO, S9X_MOVIE_INFO, "Movie is now read+write."); -} - void S9xMovieToggleFrameDisplay () { - GFX.FrameDisplay = !GFX.FrameDisplay; - // updating the frame counter string here won't work, because it may or may not be 1 too high now - extern void S9xReRefresh(); - S9xReRefresh(); + Movie.FrameDisplay = !Movie.FrameDisplay; + if(!Movie.FrameDisplay) + { + GFX.InfoStringTimeout = 1; + } } void S9xMovieFreeze (uint8** buf, uint32* size) @@ -1368,8 +746,8 @@ void S9xMovieFreeze (uint8** buf, uint32* size) *size = 0; // compute size needed for the buffer - uint32 size_needed = sizeof(Movie.MovieId) + sizeof(Movie.CurrentFrame) + sizeof(Movie.MaxFrame) + sizeof(Movie.CurrentSample) + sizeof(Movie.MaxSample); - size_needed += (uint32)(Movie.BytesPerSample * (Movie.MaxSample+1)); + uint32 size_needed = 4*3; // room for MovieId, CurrentFrame, and MaxFrame + size_needed += (uint32)(Movie.BytesPerFrame * (Movie.MaxFrame+1)); *buf=new uint8[size_needed]; *size=size_needed; @@ -1382,92 +760,76 @@ void S9xMovieFreeze (uint8** buf, uint32* size) Write32(Movie.MovieId, ptr); Write32(Movie.CurrentFrame, ptr); Write32(Movie.MaxFrame, ptr); - Write32(Movie.CurrentSample, ptr); - Write32(Movie.MaxSample, ptr); - memcpy(ptr, Movie.InputBuffer, Movie.BytesPerSample * (Movie.MaxSample+1)); + memcpy(ptr, Movie.InputBuffer, Movie.BytesPerFrame * (Movie.MaxFrame+1)); } -int S9xMovieUnfreeze (const uint8* buf, uint32 size) +bool8 S9xMovieUnfreeze (const uint8* buf, uint32 size) { // sanity check if(!S9xMovieActive()) { - return FILE_NOT_FOUND; + return false; } const uint8* ptr = buf; - if(size < sizeof(Movie.MovieId) + sizeof(Movie.CurrentFrame) + sizeof(Movie.MaxFrame) + sizeof(Movie.CurrentSample) + sizeof(Movie.MaxSample) ) + if(size < 4*3) { - return WRONG_FORMAT; + return false; } uint32 movie_id = Read32(ptr); uint32 current_frame = Read32(ptr); uint32 max_frame = Read32(ptr); - uint32 current_sample = Read32(ptr); - uint32 max_sample = Read32(ptr); - uint32 space_needed = (Movie.BytesPerSample * (max_sample+1)); + uint32 space_needed = (Movie.BytesPerFrame * (max_frame+1)); - if(current_frame > max_frame || - current_sample > max_sample || - space_needed > size) + if(movie_id != Movie.MovieId || + current_frame > max_frame || + space_needed > size) { - return WRONG_MOVIE_SNAPSHOT; + return false; } - if(movie_id != Movie.MovieId) - if(Settings.WrongMovieStateProtection) - if(max_frame < Movie.MaxFrame || max_sample < Movie.MaxSample || - memcmp(Movie.InputBuffer, ptr, space_needed)) - return WRONG_MOVIE_SNAPSHOT; - if(!Movie.ReadOnly) { // here, we are going to take the input data from the savestate // and make it the input data for the current movie, then continue // writing new input data at the currentframe pointer change_state(MOVIE_STATE_RECORD); -// S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_RERECORD); + S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_RERECORD); Movie.CurrentFrame = current_frame; Movie.MaxFrame = max_frame; - Movie.CurrentSample = current_sample; - Movie.MaxSample = max_sample; ++Movie.RerecordCount; - // when re-recording, update the sync info in the movie to the new settings as of the last re-record. - store_movie_settings(); - reserve_buffer_space(space_needed); memcpy(Movie.InputBuffer, ptr, space_needed); flush_movie(); - fseek(Movie.File, Movie.ControllerDataOffset+(Movie.BytesPerSample * (Movie.CurrentSample+1)), SEEK_SET); + fseek(Movie.File, Movie.ControllerDataOffset+(Movie.BytesPerFrame * (Movie.CurrentFrame+1)), SEEK_SET); } else { // here, we are going to keep the input data from the movie file // and simply rewind to the currentframe pointer - // this will cause a desync if the savestate is not in sync // <-- NOT ANYMORE + // this will cause a desync if the savestate is not in sync // with the on-disk recording data, but it's easily solved // by loading another savestate or playing the movie from the beginning - // don't allow loading a state inconsistent with the current movie - if(current_frame > Movie.MaxFrame || current_sample > Movie.MaxSample || - memcmp(Movie.InputBuffer, ptr, space_needed)) + // and older savestate might have a currentframe pointer past + // the end of the input data, so check for that here + if(current_frame > Movie.MaxFrame) { - return SNAPSHOT_INCONSISTENT; + return false; } change_state(MOVIE_STATE_PLAY); -// S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_REWIND); + S9xMessage(S9X_INFO, S9X_MOVIE_INFO, MOVIE_INFO_REWIND); Movie.CurrentFrame = current_frame; - Movie.CurrentSample = current_sample; } - Movie.InputBufferPtr = Movie.InputBuffer + (Movie.BytesPerSample * (Movie.CurrentSample)); - read_frame_controller_data(true); + Movie.InputBufferPtr = Movie.InputBuffer + (Movie.BytesPerFrame * Movie.CurrentFrame); + read_frame_controller_data(); - return SUCCESS; + return true; } diff --git a/source/snes9x/unused/netplay.cpp b/source/snes9x/unused/netplay.cpp index 1283c40a..a015f5b9 100644 --- a/source/snes9x/unused/netplay.cpp +++ b/source/snes9x/unused/netplay.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,14 +142,7 @@ **********************************************************************************/ - - #ifdef NETPLAY_SUPPORT -#ifdef _DEBUG - #define NP_DEBUG 1 -#endif - -#define NP_DEBUG 3 // FF-FIXME #include #include @@ -174,31 +150,33 @@ #include #include -#ifdef __WIN32__ - #include - #include - #include "win32/wsnes9x.h" - - #define ioctl ioctlsocket - #define close closesocket - #define read(a,b,c) recv(a, b, c, 0) - #define write(a,b,c) send(a, b, c, 0) +#ifndef __WIN32__ +#include +#include +#include +#include +#endif + +#if defined (__WIN32__) +#include +#include + +#define ioctl ioctlsocket +#define close closesocket +#define read(a,b,c) recv(a, b, c, 0) +#define write(a,b,c) send(a, b, c, 0) #else - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - - #ifdef __SVR4 - #include - #endif + +#include +#include +#include +#include +#include +#include + +#ifdef __SVR4 +#include +#endif #endif #ifdef USE_THREADS @@ -223,8 +201,6 @@ void S9xNPGetFreezeFile (uint32 len); unsigned long START = 0; -bool8 S9xNPConnect (); - bool8 S9xNPConnectToServer (const char *hostname, int port, const char *rom_name) { @@ -258,11 +234,9 @@ bool8 S9xNPConnectToServer (const char *hostname, int port, NetPlay.ReplyEvent = CreateEvent (NULL, FALSE, FALSE, NULL); _beginthread (S9xNPClientLoop, 0, NULL); - - return (TRUE); #endif - return S9xNPConnect(); + return (TRUE); } bool8 S9xNPConnect () @@ -270,7 +244,7 @@ bool8 S9xNPConnect () struct sockaddr_in address; struct hostent *hostinfo; unsigned int addr; - + address.sin_family = AF_INET; address.sin_port = htons (NetPlay.Port); #ifdef NP_DEBUG @@ -357,7 +331,7 @@ on the remote machine on this port?"); WRITE_LONG (ptr, len); ptr += 4; #ifdef __WIN32__ - uint32 ft = Settings.FrameTime; + uint32 ft = Settings.FrameTime * 1000; WRITE_LONG (ptr, ft); #else @@ -382,8 +356,8 @@ on the remote machine on this port?"); uint8 header [7]; - if (!S9xNPGetData (NetPlay.Socket, header, 7) || - header [0] != NP_SERV_MAGIC || header [1] != 0 || + if (!S9xNPGetData (NetPlay.Socket, header, 7) || + header [0] != NP_SERV_MAGIC || header [1] != 0 || (header [2] & 0x1f) != NP_SERV_HELLO) { S9xNPSetError ("Error in 'HELLO' reply packet received from server."); @@ -438,14 +412,14 @@ version of the protocol. Disconnecting."); Settings.NetPlay = TRUE; S9xNPResetJoypadReadPos (); NetPlay.ServerSequenceNum = 1; - + #ifdef NP_DEBUG printf ("CLIENT: Sending 'READY' to server @%ld...\n", S9xGetMilliTime () - START); #endif S9xNPSetAction ("Sending 'READY' to the server..."); - return (S9xNPSendReady ((header [2] & 0x80) ? - NP_CLNT_WAITING_FOR_ROM_IMAGE : + return (S9xNPSendReady ((header [2] & 0x80) ? + NP_CLNT_WAITING_FOR_ROM_IMAGE : NP_CLNT_READY)); } @@ -514,7 +488,7 @@ void S9xNPClientLoop (void *) } else { - if (!NetPlay.Waiting4EmulationThread && + if (!NetPlay.Waiting4EmulationThread && prev == (int) NetPlay.MaxBehindFrameCount) { NetPlay.Waiting4EmulationThread = TRUE; @@ -536,45 +510,6 @@ void S9xNPClientLoop (void *) } #endif -bool8 S9xNPCheckForHeartBeat (uint32 time_msec) -{ - fd_set read_fds; - struct timeval timeout; - int res; - int i; - - int max_fd = NetPlay.Socket; - - FD_ZERO (&read_fds); - FD_SET (NetPlay.Socket, &read_fds); - - timeout.tv_sec = 0; - timeout.tv_usec = time_msec * 1000; - res = select (max_fd + 1, &read_fds, NULL, NULL, &timeout); - - i = (res > 0 && FD_ISSET(NetPlay.Socket, &read_fds)); - -#if defined(NP_DEBUG) && NP_DEBUG >= 4 - printf ("CLIENT: S9xCheckForHeartBeat %s @%ld\n", (i?"successful":"still waiting"), S9xGetMilliTime () - START); -#endif - - return i; -} - -bool8 S9xNPWaitForHeartBeatDelay (uint32 time_msec) -{ - if (!S9xNPCheckForHeartBeat(time_msec)) - return FALSE; - - if (!S9xNPWaitForHeartBeat()) - { - S9xNPDisconnect(); - return FALSE; - } - - return TRUE; -} - bool8 S9xNPWaitForHeartBeat () { uint8 header [3 + 4 + 4 * 5]; @@ -596,7 +531,7 @@ bool8 S9xNPWaitForHeartBeat () } else NetPlay.ServerSequenceNum++; - + if ((header [2] & 0x1f) == NP_SERV_JOYPAD) { // Top 2 bits + 1 of opcode is joypad data count. @@ -613,18 +548,15 @@ bool8 S9xNPWaitForHeartBeat () } NetPlay.Frame [NetPlay.JoypadWriteInd] = READ_LONG (&header [3]); - int i; - - for (i = 0; i < num; i++) - NetPlay.Joypads [NetPlay.JoypadWriteInd][i] = READ_LONG (&header [3 + 4 + i * sizeof (uint32)]); - - for (i = 0; i < NP_MAX_CLIENTS; i++) - NetPlay.JoypadsReady [NetPlay.JoypadWriteInd][i] = TRUE; - - NetPlay.Paused = (header [2] & 0x20) != 0; + for (int i = 0; i < num; i++) + { + NetPlay.Joypads [NetPlay.JoypadWriteInd][i] = + READ_LONG (&header [3 + 4 + i * sizeof (uint32)]); + } + NetPlay.Paused = (header [2] & 0x20) != 0; NetPlay.JoypadWriteInd = (NetPlay.JoypadWriteInd + 1) % NP_JOYPAD_HIST_SIZE; - + if (NetPlay.JoypadWriteInd != (NetPlay.JoypadReadInd + 1) % NP_JOYPAD_HIST_SIZE) { //printf ("(%d)", (NetPlay.JoypadWriteInd - NetPlay.JoypadReadInd) % NP_JOYPAD_HIST_SIZE); fflush (stdout); @@ -649,10 +581,6 @@ bool8 S9xNPWaitForHeartBeat () break; case NP_SERV_PAUSE: NetPlay.Paused = (header [2] & 0x20) != 0; - if (NetPlay.Paused) - S9xNPSetWarning("CLIENT: Server has paused."); - else - S9xNPSetWarning("CLIENT: Server has resumed."); break; case NP_SERV_LOAD_ROM: #ifdef NP_DEBUG @@ -705,7 +633,7 @@ bool8 S9xNPLoadROMDialog (const char *rom_name) NetPlay.Answer = FALSE; #ifdef __WIN32__ - ResetEvent (NetPlay.ReplyEvent); + ResetEvent (NetPlay.ReplyEvent); #ifdef NP_DEBUG printf ("CLIENT: Asking GUI thread to open ROM load dialog...\n"); @@ -730,7 +658,7 @@ bool8 S9xNPLoadROMDialog (const char *rom_name) bool8 S9xNPLoadROM (uint32 len) { uint8 *data = new uint8 [len]; - + S9xNPSetAction ("Receiving ROM name..."); if (!S9xNPGetData (NetPlay.Socket, data, len)) { @@ -739,7 +667,7 @@ bool8 S9xNPLoadROM (uint32 len) S9xNPDisconnect (); return (FALSE); } - + S9xNPSetAction ("Opening LoadROM dialog..."); if (!S9xNPLoadROMDialog ((char *) data)) { @@ -767,14 +695,14 @@ bool8 S9xNPGetROMImage (uint32 len) #ifdef NP_DEBUG printf ("CLIENT: Hi-ROM: %s, Size: %04x\n", rom_info [0] ? "Y" : "N", CalculatedSize); #endif - if (CalculatedSize + 5 >= len || + if (CalculatedSize + 5 >= len || CalculatedSize >= CMemory::MAX_ROM_SIZE) { S9xNPSetError ("Size error in ROM image data received from server."); S9xNPDisconnect (); return (FALSE); } - + Memory.HiROM = rom_info [0]; Memory.LoROM = !Memory.HiROM; Memory.HeaderCount = 0; @@ -788,7 +716,7 @@ bool8 S9xNPGetROMImage (uint32 len) if (!S9xNPGetData (NetPlay.Socket, Memory.ROM, Memory.CalculatedSize)) { S9xNPSetError ("Error while receiving ROM image from server."); - Settings.StopEmulation = TRUE; + Settings.StopEmulation = TRUE; S9xNPDisconnect (); return (FALSE); } @@ -805,7 +733,7 @@ bool8 S9xNPGetROMImage (uint32 len) Settings.StopEmulation = TRUE; return (FALSE); } - Memory.InitROM (); + Memory.InitROM (FALSE); S9xReset (); S9xNPResetJoypadReadPos (); Settings.StopEmulation = FALSE; @@ -813,7 +741,7 @@ bool8 S9xNPGetROMImage (uint32 len) #ifdef __WIN32__ PostMessage (GUI.hWnd, WM_NULL, 0, 0); #endif - + return (TRUE); } @@ -826,12 +754,11 @@ void S9xNPGetSRAMData (uint32 len) return; } S9xNPSetAction ("Receiving S-RAM data..."); - if (len > 0 && !S9xNPGetData (NetPlay.Socket, Memory.SRAM, len)) + if (len > 0 && !S9xNPGetData (NetPlay.Socket, ::SRAM, len)) { S9xNPSetError ("Error while receiving S-RAM data from server."); S9xNPDisconnect (); } - S9xNPSetAction ("", TRUE); } void S9xNPGetFreezeFile (uint32 len) @@ -862,14 +789,13 @@ void S9xNPGetFreezeFile (uint32 len) delete data; return; } - S9xNPSetAction ("", TRUE); //FIXME: Setting umask here wouldn't hurt. FILE *file; #ifdef HAVE_MKSTEMP int fd; char fname[] = "/tmp/snes9x_fztmpXXXXXX"; - if ((fd = mkstemp(fname)) >= 0) + if ((fd = mkstemp(fname)) < 0) { if ((file = fdopen (fd, "wb"))) #else @@ -882,23 +808,11 @@ void S9xNPGetFreezeFile (uint32 len) if (fwrite (data, 1, len, file) == len) { fclose(file); -#ifndef __WIN32__ - /* We need .s96 extension, else .s96 is addded by unix code */ - char buf[PATH_MAX +1 ]; - - strncpy(buf, fname, PATH_MAX); - strcat(buf, ".s96"); - - rename(fname, buf); - - if (!S9xUnfreezeGame (buf)) -#else if (!S9xUnfreezeGame (fname)) -#endif S9xNPSetError ("Unable to load freeze file just received."); } else { S9xNPSetError ("Failed to write to temporary freeze file."); - fclose(file); + fclose (file); } } else S9xNPSetError ("Failed to create temporary freeze file."); @@ -910,18 +824,8 @@ void S9xNPGetFreezeFile (uint32 len) uint32 S9xNPGetJoypad (int which1) { - if (Settings.NetPlay && which1 < 8) - { -#ifdef NP_DEBUG - if(!NetPlay.JoypadsReady [NetPlay.JoypadReadInd][which1]) - { - S9xNPSetWarning ("Missing input from server!"); - } -#endif - NetPlay.JoypadsReady [NetPlay.JoypadReadInd][which1] = FALSE; - - return (NetPlay.Joypads [NetPlay.JoypadReadInd][which1]); - } + if (Settings.NetPlay && which1 < 5) + return (NetPlay.Joypads [NetPlay.JoypadReadInd][which1]); return (0); } @@ -957,8 +861,6 @@ void S9xNPResetJoypadReadPos () NetPlay.JoypadReadInd = NP_JOYPAD_HIST_SIZE - 1; for (int h = 0; h < NP_JOYPAD_HIST_SIZE; h++) memset ((void *) &NetPlay.Joypads [h], 0, sizeof (NetPlay.Joypads [0])); - for (int h = 0; h < NP_JOYPAD_HIST_SIZE; h++) - memset ((void *) &NetPlay.JoypadsReady [h], 0, sizeof (NetPlay.JoypadsReady [0])); } bool8 S9xNPSendJoypadUpdate (uint32 joypad) @@ -1012,7 +914,7 @@ bool8 S9xNPSendData (int socket, const uint8 *data, int length) int sent = write (socket, (char *) ptr, num_bytes); if (sent < 0) { - if (errno == EINTR + if (errno == EINTR #ifdef EAGAIN || errno == EAGAIN #endif @@ -1107,12 +1009,12 @@ bool8 S9xNPGetData (int socket, uint8 *data, int length) { NetPlay.PercentageComplete = (uint8) (((length - len) * 100) / length); #ifdef __WIN32__ - PostMessage (GUI.hWnd, WM_USER, NetPlay.PercentageComplete, + PostMessage (GUI.hWnd, WM_USER, NetPlay.PercentageComplete, NetPlay.PercentageComplete); Sleep (0); #endif } - + } while (len > 0); return (TRUE); @@ -1137,11 +1039,11 @@ bool8 S9xNPInitialise () if (WSAStartup (MAKEWORD (1, 0), &data) != 0) { S9xNPSetError ("Call to init Windows sockets failed. Do you have WinSock2 installed?"); - return (FALSE); + return (FALSE); } } #endif - return (TRUE); + return (TRUE); } void S9xNPDiscardHeartbeats () @@ -1166,9 +1068,6 @@ void S9xNPDiscardHeartbeats () void S9xNPSetAction (const char *action, bool8 force) { -#ifdef NP_DEBUG - printf ("NPSetAction: %s, forced = %d %ld\n", action, force, S9xGetMilliTime () - START); -#endif if (force || !Settings.NetPlayServer) { strncpy (NetPlay.ActionMsg, action, NP_MAX_ACTION_LEN - 1); @@ -1182,13 +1081,9 @@ void S9xNPSetAction (const char *action, bool8 force) void S9xNPSetError (const char *error) { -#if defined(NP_DEBUG) && NP_DEBUG == 2 - printf("ERROR: %s\n", error); - fflush (stdout); -#endif strncpy (NetPlay.ErrorMsg, error, NP_MAX_ACTION_LEN - 1); NetPlay.ErrorMsg [NP_MAX_ACTION_LEN - 1] = 0; -#ifdef __WIN32__ +#ifdef __WIN32 PostMessage (GUI.hWnd, WM_USER + 1, 0, 0); Sleep (0); #endif @@ -1196,10 +1091,6 @@ void S9xNPSetError (const char *error) void S9xNPSetWarning (const char *warning) { -#if defined(NP_DEBUG) && NP_DEBUG == 3 - printf("Warning: %s\n", warning); - fflush (stdout); -#endif strncpy (NetPlay.WarningMsg, warning, NP_MAX_ACTION_LEN - 1); NetPlay.WarningMsg [NP_MAX_ACTION_LEN - 1] = 0; #ifdef __WIN32__ diff --git a/source/snes9x/unused/netplay.h b/source/snes9x/unused/netplay.h index 686e414f..bfede8be 100644 --- a/source/snes9x/unused/netplay.h +++ b/source/snes9x/unused/netplay.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,8 +142,6 @@ **********************************************************************************/ - - #ifndef _NETPLAY_H_ #define _NETPLAY_H_ @@ -185,7 +166,7 @@ #define NP_JOYPAD_HIST_SIZE 120 #define NP_DEFAULT_PORT 6096 -#define NP_MAX_CLIENTS 8 +#define NP_MAX_CLIENTS 5 #define NP_SERV_MAGIC 'S' #define NP_CLNT_MAGIC 'C' @@ -257,7 +238,7 @@ struct SNPServer uint32 FrameTime; uint32 FrameCount; char ROMName [30]; - uint32 Joypads [NP_MAX_CLIENTS]; + uint32 Joypads [5]; bool8 ClientPaused; uint32 Paused; bool8 SendROMImageOnConnect; @@ -294,7 +275,6 @@ struct SNetPlay uint32 FrameCount; uint32 MaxFrameSkip; uint32 MaxBehindFrameCount; - bool8 JoypadsReady [NP_JOYPAD_HIST_SIZE][NP_MAX_CLIENTS]; char ActionMsg [NP_MAX_ACTION_LEN]; char ErrorMsg [NP_MAX_ACTION_LEN]; char WarningMsg [NP_MAX_ACTION_LEN]; @@ -324,8 +304,6 @@ extern "C" struct SNetPlay NetPlay; bool8 S9xNPConnectToServer (const char *server_name, int port, const char *rom_name); bool8 S9xNPWaitForHeartBeat (); -bool8 S9xNPWaitForHeartBeatDelay (uint32 time_msec = 0); -bool8 S9xNPCheckForHeartBeat (uint32 time_msec = 0); uint32 S9xNPGetJoypad (int which1); bool8 S9xNPSendJoypadUpdate (uint32 joypad); void S9xNPDisconnect (); diff --git a/source/snes9x/unused/offsets.cpp b/source/snes9x/unused/offsets.cpp deleted file mode 100644 index 021c0fed..00000000 --- a/source/snes9x/unused/offsets.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - - -#include "snes9x.h" -#include "65c816.h" -#include "memmap.h" -#include "ppu.h" -#include "apu.h" -#include "cpuexec.h" -#include "sa1.h" - -#ifndef S9xSTREAM -#define S9xSTREAM stdout -#endif - -#define OFFSET(N,F) \ -fprintf (S9xSTREAM, "#define " #N " CPU + %d\n", (int) &((struct SCPUState *) 0)->F); -#define OFFSET2(N,F) \ -fprintf (S9xSTREAM, "#define " #N " Registers + %d\n", (int) &((struct SRegisters *) 0)->F); -#define OFFSET3(F) \ -fprintf (S9xSTREAM, "#define " #F " Memory + %d\n", (int) &((class CMemory *) 0)->F); -#define OFFSET4(N,F) \ -fprintf (S9xSTREAM, "#define " #N " APU + %d\n", (int) &((struct SAPU *) 0)->F); -#define OFFSET5(N,F) \ -fprintf (S9xSTREAM, "#define " #N " IAPU + %d\n", (int) &((struct SIAPU *) 0)->F); -#define OFFSET6(N,F) \ -fprintf (S9xSTREAM, "#define " #N " ICPU + %d\n", (int) &((struct SICPU *) 0)->F); -#define OFFSET7(N,F) \ -fprintf (S9xSTREAM, "#define " #N " Settings + %d\n", (int) &((struct SSettings *) 0)->F); -#define OFFSET8(N, F) \ -fprintf (S9xSTREAM, "#define " #N " APURegisters + %d\n", (int) &((struct SAPURegisters *) 0)->F); - -#define OFFSET9(N, F) \ -fprintf (S9xSTREAM, "#define " #N " PPU + %d\n", (int) &((struct SPPU *) 0)->F); -#define OFFSET10(N, F) \ -fprintf (S9xSTREAM, "#define " #N " IPPU + %d\n", (int) &((struct InternalPPU *) 0)->F); -#define OFFSET11(N, F) \ -fprintf (S9xSTREAM, "#define " #N " SA1 + %d\n", (int) &((struct SSA1 *) 0)->F); -#define OFFSET12(N, F) \ -fprintf (S9xSTREAM, "#define " #N " SA1Registers + %d\n", (int) &((struct SSA1Registers *) 0)->F); - -int main (int /*argc*/, char ** /*argv*/) -{ - OFFSET(Flags,Flags) - OFFSET(BranchSkip,BranchSkip) - OFFSET(NMIActive,NMIActive) - OFFSET(IRQActive,IRQActive) - OFFSET(WaitingForInterrupt,WaitingForInterrupt) - OFFSET(InDMA,InDMA) - OFFSET(InWRAM_DMA,InWRAM_DMA) - OFFSET(WhichEvent,WhichEvent) - OFFSET(PCBase,PCBase) - OFFSET(PBPCAtOpcodeStart,PBPCAtOpcodeStart) - OFFSET(WaitAddress,WaitAddress) - OFFSET(WaitCounter,WaitCounter) - OFFSET(Cycles,Cycles) - OFFSET(NextEvent,NextEvent) - OFFSET(V_Counter,V_Counter) - OFFSET(MemSpeed,MemSpeed) - OFFSET(MemSpeedx2,MemSpeedx2) - OFFSET(FastROMSpeed,FastROMSpeed) - OFFSET(AutoSaveTimer,AutoSaveTimer) - OFFSET(SRAMModified,SRAMModified) - OFFSET(BRKTriggered,BRKTriggered) - OFFSET(TriedInterleavedMode2,TriedInterleavedMode2) - - OFFSET2(DB,DB) - OFFSET2(PP,P.W) - OFFSET2(PL,P.W) - fprintf (S9xSTREAM, "#define PH PL + 1\n"); - OFFSET2(AA,A.W) - OFFSET2(AL,A.W) - fprintf (S9xSTREAM, "#define AH AL + 1\n"); - OFFSET2(DD,D.W) - OFFSET2(DL,D.W) - fprintf (S9xSTREAM, "#define DH DL + 1\n"); - OFFSET2(SS,S.W) - OFFSET2(SL,S.W) - fprintf (S9xSTREAM, "#define SH SL + 1\n"); - OFFSET2(XX,X.W) - OFFSET2(XL,X.W) - fprintf (S9xSTREAM, "#define XH XL + 1\n"); - OFFSET2(YY,Y.W) - OFFSET2(YL,Y.W) - fprintf (S9xSTREAM, "#define YH YL + 1\n"); - OFFSET2(PCR,PC.W.xPC) - OFFSET2(PB,PC.B.xPB) - - OFFSET3(RAM) - OFFSET3(ROM) - OFFSET3(VRAM) - OFFSET3(SRAM) - OFFSET3(BWRAM) - OFFSET3(FillRAM) - OFFSET3(C4RAM) - OFFSET3(HiROM) - OFFSET3(LoROM) - OFFSET3(SRAMMask) - OFFSET3(SRAMSize) - OFFSET3(Map) - OFFSET3(WriteMap) - OFFSET3(MemorySpeed) - OFFSET3(BlockIsRAM) - OFFSET3(BlockIsROM) - OFFSET3(ROMFilename) - - OFFSET5(APUPCS,PC) - OFFSET5(APURAM,RAM) - OFFSET5(APUExecuting,APUExecuting) - OFFSET5(APUDirectPage,DirectPage) - OFFSET5(APUBit,Bit) - OFFSET5(APUAddress,Address) - OFFSET5(APUWaitAddress1,WaitAddress1) - OFFSET5(APUWaitAddress2,WaitAddress2) - OFFSET5(APUWaitCounter,WaitCounter) - OFFSET5(APUShadowRAM,ShadowRAM) - OFFSET5(APUCachedSamples,CachedSamples) - OFFSET5(APU_Carry,_Carry) - OFFSET5(APU_Zero,_Zero) - OFFSET5(APU_Overflow,_Overflow) - OFFSET5(APUTimerErrorCounter,TimerErrorCounter) - OFFSET5(NextAPUTimerPos,NextAPUTimerPos) - - OFFSET4(APUCycles,Cycles) - OFFSET4(APUShowROM,ShowROM) - OFFSET4(APUFlags,Flags) - OFFSET4(APUKeyedChannels,KeyedChannels) - OFFSET4(APUOutPorts,OutPorts) - OFFSET4(APUDSP,DSP) - OFFSET4(APUExtraRAM,ExtraRAM) - OFFSET4(APUTimer,Timer) - OFFSET4(APUTimerTarget,TimerTarget) - OFFSET4(APUTimerEnabled,TimerEnabled) - OFFSET4(TimerValueWritten,TimerValueWritten) - - OFFSET6(CPUSpeed,Speed) - OFFSET6(CPUOpcodes,S9xOpcodes) - OFFSET6(_Carry,_Carry) - OFFSET6(_Zero,_Zero) - OFFSET6(_Negative,_Negative) - OFFSET6(_Overflow,_Overflow) - OFFSET6(ShiftedDB,ShiftedDB) - OFFSET6(ShiftedPB,ShiftedPB) - OFFSET6(CPUExecuting,CPUExecuting) - OFFSET6(Scanline,Scanline) - OFFSET6(Frame,Frame) - - OFFSET7(APUEnabled,APUEnabled) - OFFSET7(Shutdown,Shutdown) - OFFSET7(SoundSkipMethod,SoundSkipMethod) - OFFSET7(HDMATimingHack,HDMATimingHack) - OFFSET7(DisableIRQ,DisableIRQ) - OFFSET7(Paused,Paused) - OFFSET7(PAL,PAL) - OFFSET7(SoundSync,SoundSync) - OFFSET7(SA1Enabled,SA1) - OFFSET7(SuperFXEnabled,SuperFX) - - OFFSET8(ApuP,P) - OFFSET8(ApuYA,YA.W) - OFFSET8(ApuA,YA.B.A) - OFFSET8(ApuY,YA.B.Y) - OFFSET8(ApuX,X) - OFFSET8(ApuS,S) - OFFSET8(ApuPC,PC) - OFFSET8(APUPCR,PC) - - OFFSET9(BGMode,BGMode) - OFFSET9(BG3Priority,BG3Priority) - OFFSET9(Brightness,Brightness) - OFFSET9(GHight,VMA.High) - OFFSET9(GInc,VMA.Increment) - OFFSET9(GAddress,VMA.Address) - OFFSET9(GMask1,VMA.Mask1) - OFFSET9(GFullGraphicCount,VMA.FullGraphicCount) - OFFSET9(GShift,VMA.Shift) - OFFSET9(CGFLIP,CGFLIP) - OFFSET9(CGDATA,CGDATA) - OFFSET9(FirstSprite,FirstSprite) - OFFSET9(LastSprite,LastSprite) - OFFSET9(OBJ,OBJ) - OFFSET9(OAMPriorityRotation,OAMPriorityRotation) - OFFSET9(OAMAddr,OAMAddr) - OFFSET9(OAMFlip,OAMFlip) - OFFSET9(OAMTileAddress,OAMTileAddress) - OFFSET9(IRQVBeamPos,IRQVBeamPos) - OFFSET9(IRQHBeamPos,IRQHBeamPos) - OFFSET9(VBeamPosLatched,VBeamPosLatched) - OFFSET9(HBeamPosLatched,HBeamPosLatched) - OFFSET9(HBeamFlip,HBeamFlip) - OFFSET9(VBeamFlip,VBeamFlip) - OFFSET9(HVBeamCounterLatched,HVBeamCounterLatched) - OFFSET9(MatrixA,MatrixA) - OFFSET9(MatrixB,MatrixB) - OFFSET9(MatrixC,MatrixC) - OFFSET9(MatrixD,MatrixD) - OFFSET9(CentreX,CentreX) - OFFSET9(CentreY,CentreY) - OFFSET9(CGADD,CGADD) - OFFSET9(FixedColourGreen,FixedColourGreen) - OFFSET9(FixedColourRed,FixedColourRed) - OFFSET9(FixedColourBlue,FixedColourBlue) - OFFSET9(SavedOAMAddr,SavedOAMAddr) - OFFSET9(ScreenHeight,ScreenHeight) - OFFSET9(WRAM,WRAM) - OFFSET9(BG_Forced,BG_Forced) - OFFSET9(ForcedBlanking,ForcedBlanking) - OFFSET9(OBJThroughMain,OBJThroughMain) - OFFSET9(OBJThroughSub,OBJThroughSub) - OFFSET9(OBJSizeSelect,OBJSizeSelect) - OFFSET9(OBJNameBase,OBJNameBase) - OFFSET9(OAMReadFlip,OAMReadFlip) - OFFSET9(OAMData,OAMData) - OFFSET9(VTimerEnabled,VTimerEnabled) - OFFSET9(HTimerEnabled,HTimerEnabled) - OFFSET9(HTimerPosition,HTimerPosition) - OFFSET9(Mosaic,Mosaic) - OFFSET9(BGMosaic,BGMosaic) - OFFSET9(Mode7HFlip,Mode7HFlip) - OFFSET9(Mode7VFlip,Mode7VFlip) - OFFSET9(Mode7Repeat,Mode7Repeat) - OFFSET9(Window1Left,Window1Left) - OFFSET9(Window1Right,Window1Right) - OFFSET9(Window2Left,Window2Left) - OFFSET9(Window2Right,Window2Right) - OFFSET9(ClipWindowOverlapLogic,ClipWindowOverlapLogic) - OFFSET9(ClipWindow1Enable,ClipWindow1Enable) - OFFSET9(ClipWindow2Enable,ClipWindow2Enable) - OFFSET9(ClipWindow1Inside,ClipWindow1Inside) - OFFSET9(ClipWindow2Inside,ClipWindow2Inside) - OFFSET9(RecomputeClipWindows,RecomputeClipWindows) - OFFSET9(CGFLIPRead,CGFLIPRead) - OFFSET9(OBJNameSelect,OBJNameSelect) - OFFSET9(Need16x8Mulitply,Need16x8Mulitply) - OFFSET9(RangeTimeOver,RangeTimeOver) - - OFFSET10(ColorsChanged,ColorsChanged) - OFFSET10(HDMA,HDMA) - OFFSET10(HDMAStarted,HDMAStarted) - OFFSET10(MaxBrightness,MaxBrightness) - OFFSET10(LatchedBlanking,LatchedBlanking) - OFFSET10(OBJChanged,OBJChanged) - OFFSET10(RenderThisFrame,RenderThisFrame) - OFFSET10(SkippedFrames,SkippedFrames) - OFFSET10(FrameSkip,FrameSkip) - OFFSET10(TileCache,TileCache) - OFFSET10(TileCached,TileCached) -#ifdef CORRECT_VRAM_READS - OFFSET10(VRAMReadBuffer,VRAMReadBuffer) -#else - OFFSET10(FirstVRAMRead,FirstVRAMRead) -#endif - OFFSET10(Interlace,Interlace) - OFFSET10(DoubleWidthPixels,DoubleWidthPixels) - OFFSET10(RenderedScreenHeight,RenderedScreenHeight) - OFFSET10(RenderedScreenWidth,RenderedScreenWidth) - OFFSET10(Red,Red) - OFFSET10(Green,Green) - OFFSET10(Blue,Blue) - OFFSET10(XB,XB) - OFFSET10(ScreenColors,ScreenColors) - OFFSET10(PreviousLine,PreviousLine) - OFFSET10(CurrentLine,CurrentLine) - OFFSET10(Clip,Clip) - - OFFSET11(SA1Opcodes,S9xOpcodes) - OFFSET11(SA1_Carry,_Carry) - OFFSET11(SA1_Zero,_Zero) - OFFSET11(SA1_Negative,_Negative) - OFFSET11(SA1_Overflow,_Overflow) - OFFSET11(SA1CPUExecuting,CPUExecuting) - OFFSET11(SA1ShiftedPB,ShiftedPB) - OFFSET11(SA1ShiftedDB,ShiftedDB) - OFFSET11(SA1Flags,Flags) - OFFSET11(SA1Executing,Executing) - OFFSET11(SA1NMIActive,NMIActive) - OFFSET11(SA1IRQActive,IRQActive) - OFFSET11(SA1WaitingForInterrupt,WaitingForInterrupt) - OFFSET11(SA1PCBase,PCBase) - OFFSET11(SA1PBPCAtOpcodeStart,PBPCAtOpcodeStart) - OFFSET11(SA1WaitAddress,WaitAddress) - OFFSET11(SA1WaitCounter,WaitCounter) - OFFSET11(SA1WaitByteAddress1,WaitByteAddress1) - OFFSET11(SA1WaitByteAddress2,WaitByteAddress2) - OFFSET11(SA1BWRAM,BWRAM) - OFFSET11(SA1Map,Map) - OFFSET11(SA1WriteMap,WriteMap) - OFFSET11(SA1op1,op1) - OFFSET11(SA1op2,op2) - OFFSET11(SA1arithmetic_op,arithmetic_op) - OFFSET11(SA1sum,sum) - OFFSET11(SA1overflow,overflow) - OFFSET11(VirtualBitmapFormat,VirtualBitmapFormat) - OFFSET11(SA1_in_char_dma,in_char_dma) - OFFSET11(SA1variable_bit_pos,variable_bit_pos) - - OFFSET12(SA1DB,DB) - OFFSET12(SA1PP,P.W) - OFFSET12(SA1PL,P.W) - fprintf (S9xSTREAM, "#define SA1PH SA1PL + 1\n"); - OFFSET12(SA1AA,A.W) - OFFSET12(SA1AL,A.W) - fprintf (S9xSTREAM, "#define SA1AH SA1AL + 1\n"); - OFFSET12(SA1DD,D.W) - OFFSET12(SA1DL,D.W) - fprintf (S9xSTREAM, "#define SA1DH SA1DL + 1\n"); - OFFSET12(SA1SS,S.W) - OFFSET12(SA1SL,S.W) - fprintf (S9xSTREAM, "#define SA1SH SA1SL + 1\n"); - OFFSET12(SA1XX,X.W) - OFFSET12(SA1XL,X.W) - fprintf (S9xSTREAM, "#define SA1XH SA1XL + 1\n"); - OFFSET12(SA1YY,Y.W) - OFFSET12(SA1YL,Y.W) - fprintf (S9xSTREAM, "#define SA1YH SA1YL + 1\n"); - OFFSET12(SA1PB,PC.B.xPB) - OFFSET12(SA1PCR,PC.W.xPC) - - return (0); -} - diff --git a/source/snes9x/unused/reader.cpp b/source/snes9x/unused/reader.cpp index 540fa203..3712fa47 100644 --- a/source/snes9x/unused/reader.cpp +++ b/source/snes9x/unused/reader.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - // Abstract the details of reading from zip files versus FILE *'s. #include "reader.h" @@ -184,9 +165,9 @@ char *Reader::getline(void){ } std::string Reader::getline(bool &eof){ - char buf[1024]; + char buf[100]; std::string ret; - + eof=false; ret.clear(); do { @@ -240,7 +221,7 @@ int unzReader::get_char(){ if(numbytes<=0) return (EOF); head=buffer; } - + c=*head; head++; numbytes--; diff --git a/source/snes9x/unused/reader.h b/source/snes9x/unused/reader.h index 302139e0..4e260091 100644 --- a/source/snes9x/unused/reader.h +++ b/source/snes9x/unused/reader.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - // Abstract the details of reading from zip files versus FILE *'s. #ifndef _READER_H_ @@ -193,7 +174,7 @@ class fReader : public Reader { }; #ifdef UNZIP_SUPPORT -#include "unzip/unzip.h" +#include "unzip.h" #define unz_BUFFSIZ 1024 diff --git a/source/snes9x/unused/screenshot.cpp b/source/snes9x/unused/screenshot.cpp index 6999edb6..e285bf20 100644 --- a/source/snes9x/unused/screenshot.cpp +++ b/source/snes9x/unused/screenshot.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -160,8 +143,6 @@ - - #ifdef HAVE_CONFIG_H #include #endif @@ -186,10 +167,7 @@ #include "ppu.h" #include "screenshot.h" -#define ShowFailure() S9xSetInfoString("Failed to take screenshot.") - -bool8 S9xDoScreenshot(int width, int height) -{ +bool8 S9xDoScreenshot(int width, int height){ #ifdef HAVE_LIBPNG FILE *fp; png_structp png_ptr; @@ -198,11 +176,10 @@ bool8 S9xDoScreenshot(int width, int height) int imgwidth; int imgheight; const char *fname=S9xGetFilenameInc(".png", SCREENSHOT_DIR); - + Settings.TakeScreenshot=FALSE; if((fp=fopen(fname, "wb"))==NULL){ - ShowFailure(); perror("Screenshot failed"); return FALSE; } @@ -211,7 +188,6 @@ bool8 S9xDoScreenshot(int width, int height) if(!png_ptr){ fclose(fp); unlink(fname); - ShowFailure(); return FALSE; } info_ptr=png_create_info_struct(png_ptr); @@ -219,7 +195,6 @@ bool8 S9xDoScreenshot(int width, int height) png_destroy_write_struct(&png_ptr, (png_infopp)NULL); fclose(fp); unlink(fname); - ShowFailure(); return FALSE; } @@ -228,7 +203,6 @@ bool8 S9xDoScreenshot(int width, int height) png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); unlink(fname); - ShowFailure(); return FALSE; } @@ -241,7 +215,7 @@ bool8 S9xDoScreenshot(int width, int height) if(width<=256) imgwidth=width<<1; if(height<=SNES_HEIGHT_EXTENDED) imgheight=height<<1; } - + png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, imgwidth, imgheight, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, @@ -255,7 +229,7 @@ bool8 S9xDoScreenshot(int width, int height) png_set_shift(png_ptr, &sig_bit); png_write_info(png_ptr, info_ptr); - + png_set_packing(png_ptr); png_byte *row_pointer=new png_byte [png_get_rowbytes(png_ptr, info_ptr)]; @@ -280,20 +254,12 @@ bool8 S9xDoScreenshot(int width, int height) } delete [] row_pointer; - + png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); fprintf(stderr, "%s saved.\n", fname); - - { - static char str [64]; - sprintf(str, "Saved screenshot %s", fname + strlen(fname)-7); - str[strlen(str)-3] = '\0'; - S9xSetInfoString(str); - } - return TRUE; #else Settings.TakeScreenshot=FALSE; diff --git a/source/snes9x/unused/server.cpp b/source/snes9x/unused/server.cpp index 43a56393..275fe203 100644 --- a/source/snes9x/unused/server.cpp +++ b/source/snes9x/unused/server.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -159,48 +142,44 @@ **********************************************************************************/ - - #ifdef NETPLAY_SUPPORT -#ifdef _DEBUG - #define NP_DEBUG 1 -#endif - #include #include #include #include #include #ifdef HAVE_STRINGS_H - #include +#include +#endif + +#ifndef __WIN32__ +#include +#include #endif #ifdef __WIN32__ - #include - #include - #include "win32/wsnes9x.h" - #define ioctl ioctlsocket - #define close closesocket - #define read(a,b,c) recv(a, b, c, 0) - #define write(a,b,c) send(a, b, c, 0) - #define gettimeofday(a,b) S9xGetTimeOfDay (a) - #define exit(a) _endthread() - void S9xGetTimeOfDay (struct timeval *n); +#include +#include +#define ioctl ioctlsocket +#define close closesocket +#define read(a,b,c) recv(a, b, c, 0) +#define write(a,b,c) send(a, b, c, 0) +#define gettimeofday(a,b) S9xGetTimeOfDay (a) +#define exit(a) _endthread() +void S9xGetTimeOfDay (struct timeval *n); #else - #include - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include - #ifdef __SVR4 - #include - #endif +#ifdef __SVR4 +#include +#endif #endif // !__WIN32__ @@ -209,11 +188,7 @@ #include "memmap.h" #include "snapshot.h" -#ifdef __WIN32__ #define NP_ONE_CLIENT 1 -#else -#define NP_ONE_CLIENT 0 -#endif struct SNPServer NPServer; @@ -247,10 +222,10 @@ void S9xNPShutdownClient (int c, bool8 report_error = FALSE) #endif if (report_error) { - sprintf (NetPlay.ErrorMsg, + sprintf (NetPlay.ErrorMsg, "Player %d on '%s' has disconnected.", c + 1, NPServer.Clients [c].HostName); - S9xNPSetWarning (NetPlay.ErrorMsg); + S9xNPSetError (NetPlay.ErrorMsg); } if (NPServer.Clients [c].HostName) @@ -336,7 +311,7 @@ static bool8 S9xNPSSendData (int fd, const uint8 *data, int length) if (chunk < 1024) chunk = 1024; - + do { int num_bytes = len; @@ -351,7 +326,7 @@ static bool8 S9xNPSSendData (int fd, const uint8 *data, int length) if (sent < 0) { - if (errno == EINTR + if (errno == EINTR #ifdef EAGAIN || errno == EAGAIN #endif @@ -401,18 +376,18 @@ void S9xNPSendHeartBeat () if (n >= 0) { bool8 Paused = NPServer.Paused != 0; - + NPServer.FrameCount++; *ptr++ = NP_SERV_MAGIC; *ptr++ = 0; // Individual client sequence number will get placed here *ptr++ = NP_SERV_JOYPAD | (n << 6) | ((Paused != 0) << 5); - + WRITE_LONG (ptr, NPServer.FrameCount); len += 4; ptr += 4; int i; - + for (i = 0; i <= n; i++) { WRITE_LONG (ptr, NPServer.Joypads [i]); @@ -463,15 +438,15 @@ void S9xNPProcessClient (int c) { #ifdef NP_DEBUG printf ("SERVER: Messages lost from '%s', expected %d, got %d\n", - NPServer.Clients [c].HostName ? - NPServer.Clients [c].HostName : "Unknown", + NPServer.Clients [c].HostName ? + NPServer.Clients [c].HostName : "Unknown", NPServer.Clients [c].ReceiveSequenceNum, header [1]); #endif - sprintf (NetPlay.WarningMsg, + sprintf (NetPlay.WarningMsg, "SERVER: Messages lost from '%s', expected %d, got %d\n", - NPServer.Clients [c].HostName ? - NPServer.Clients [c].HostName : "Unknown", + NPServer.Clients [c].HostName ? + NPServer.Clients [c].HostName : "Unknown", NPServer.Clients [c].ReceiveSequenceNum, header [1]); NPServer.Clients [c].ReceiveSequenceNum = header [1] + 1; @@ -524,7 +499,7 @@ void S9xNPProcessClient (int c) *ptr++ = NP_SERV_MAGIC; *ptr++ = NPServer.Clients [c].SendSequenceNum++; - if (NPServer.SendROMImageOnConnect && + if (NPServer.SendROMImageOnConnect && NPServer.NumClients > NP_ONE_CLIENT) *ptr++ = NP_SERV_HELLO | 0x80; else @@ -570,7 +545,7 @@ void S9xNPProcessClient (int c) S9xNPServerAddTask (NP_SERVER_RESET_ALL, 0); } else - S9xNPServerAddTask (NP_SERVER_SYNC_CLIENT, (void *) c); + S9xNPServerAddTask (NP_SERVER_SYNC_CLIENT, (void *) c); break; case NP_CLNT_RECEIVED_ROM_IMAGE: @@ -589,7 +564,7 @@ void S9xNPProcessClient (int c) S9xNPServerAddTask (NP_SERVER_RESET_ALL, 0); } else - S9xNPServerAddTask (NP_SERVER_SYNC_CLIENT, (void *) c); + S9xNPServerAddTask (NP_SERVER_SYNC_CLIENT, (void *) c); break; @@ -612,7 +587,7 @@ void S9xNPProcessClient (int c) { NPServer.Clients [c].Paused = FALSE; NPServer.Clients [c].Ready = TRUE; - + S9xNPRecomputePause (); break; } @@ -627,19 +602,14 @@ void S9xNPProcessClient (int c) if (!NPServer.SendROMImageOnConnect) { S9xNPWaitForEmulationToComplete (); - + if (NPServer.SyncByReset) { S9xNPServerAddTask (NP_SERVER_SEND_SRAM, (void *) c); S9xNPServerAddTask (NP_SERVER_RESET_ALL, 0); } else -#ifdef __WIN32__ S9xNPServerAddTask (NP_SERVER_SYNC_CLIENT, (void *) c); -#else - /* We need to resync all clients on new player connect as we don't have a 'reference game' */ - S9xNPServerAddTask (NP_SERVER_SYNC_ALL, (void *) c); -#endif } } else @@ -673,14 +643,14 @@ void S9xNPAcceptClient (int Listen, bool8 block) struct hostent *host; int new_fd; int i; - + #ifdef NP_DEBUG printf ("SERVER: attempting to accept new client connection @%ld\n", S9xGetMilliTime () - START); #endif S9xNPSetAction ("SERVER: Attempting to accept client connection...", TRUE); memset (&remote_address, 0, sizeof (remote_address)); ACCEPT_SIZE_T len = sizeof (remote_address); - + new_fd = accept (Listen, (struct sockaddr *)&remote_address, &len); S9xNPSetAction ("Setting socket options...", TRUE); @@ -792,9 +762,9 @@ static bool8 S9xNPServerInit (int port) S9xNPSetError ("NetPlay Server: Can't create listening socket."); return (FALSE); } - + val = 1; - setsockopt (NPServer.Socket, SOL_SOCKET, SO_REUSEADDR, + setsockopt (NPServer.Socket, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof (val)); memset (&address, 0, sizeof (address)); @@ -826,32 +796,14 @@ static bool8 S9xNPServerInit (int port) return (TRUE); } -void S9xNPSendServerPause (bool8 paused) -{ -#ifdef NP_DEBUG - printf ("SERVER: Pause - %s @%ld\n", paused ? "YES" : "NO", S9xGetMilliTime () - START); -#endif - uint8 pause [7]; - uint8 *ptr = pause; - *ptr++ = NP_SERV_MAGIC; - *ptr++ = 0; - *ptr++ = NP_SERV_PAUSE | (paused ? 0x20 : 0); - WRITE_LONG (ptr, NPServer.FrameCount); - S9xNPSendToAllClients (pause, 7); -} - void S9xNPServerLoop (void *) { #ifdef __WIN32__ BOOL success = FALSE; #else bool8 success = FALSE; - static struct timeval next1 = {0, 0}; - struct timeval now; #endif - int pausedState = -1, newPausedState = -1; - while (server_continue) { fd_set read_fds; @@ -860,27 +812,16 @@ void S9xNPServerLoop (void *) int i; int max_fd = NPServer.Socket; - + #ifdef __WIN32__ Sleep (0); #endif - if (success && !(Settings.Paused && !Settings.FrameAdvance) && !Settings.StopEmulation && + if (success && !Settings.Paused && !Settings.StopEmulation && !Settings.ForcedPause && !NPServer.Paused) { S9xNPSendHeartBeat (); - newPausedState = 0; } - else - { - newPausedState = 1; - } - - if(pausedState != newPausedState) - { - pausedState = newPausedState; -// S9xNPSendServerPause(pausedState); // XXX: doesn't seem to work yet... - } do { @@ -895,11 +836,11 @@ void S9xNPServerLoop (void *) max_fd = NPServer.Clients [i].Socket; } } - + timeout.tv_sec = 0; timeout.tv_usec = 1000; res = select (max_fd + 1, &read_fds, NULL, NULL, &timeout); - + if (res > 0) { if (FD_ISSET (NPServer.Socket, &read_fds)) @@ -907,7 +848,7 @@ void S9xNPServerLoop (void *) for (i = 0; i < NP_MAX_CLIENTS; i++) { - if (NPServer.Clients [i].Connected && + if (NPServer.Clients [i].Connected && FD_ISSET (NPServer.Clients [i].Socket, &read_fds)) { S9xNPProcessClient (i); @@ -918,35 +859,6 @@ void S9xNPServerLoop (void *) #ifdef __WIN32__ success = WaitForSingleObject (GUI.ServerTimerSemaphore, 200) == WAIT_OBJECT_0; -#else - while (gettimeofday (&now, NULL) < 0) ; - - /* If there is no known "next" frame, initialize it now */ - if (next1.tv_sec == 0) { next1 = now; ++next1.tv_usec; } - - success=FALSE; - - if (timercmp(&next1, &now, >)) - { - /* If we're ahead of time, sleep a while */ - unsigned timeleft = - (next1.tv_sec - now.tv_sec) * 1000000 - + next1.tv_usec - now.tv_usec; - usleep(timeleft<(200*1000)?timeleft:(200*1000)); - } - - if (!timercmp(&next1, &now, >)) - { - - /* Calculate the timestamp of the next frame. */ - next1.tv_usec += Settings.FrameTime; - if (next1.tv_usec >= 1000000) - { - next1.tv_sec += next1.tv_usec / 1000000; - next1.tv_usec %= 1000000; - } - success=TRUE; - } #endif while (NPServer.TaskHead != NPServer.TaskTail) @@ -996,7 +908,6 @@ void S9xNPServerLoop (void *) WRITE_LONG (ptr, NPServer.FrameCount); S9xNPSendToAllClients (reset, 7); } - S9xNPSetAction ("", TRUE); break; case NP_SERVER_SEND_SRAM: NPServer.Clients [(pint) task_data].Ready = FALSE; @@ -1035,9 +946,8 @@ bool8 S9xNPStartServer (int port) server_continue = TRUE; if (S9xNPServerInit (port)) #ifdef __WIN32__ - return (_beginthread (S9xNPServerLoop, 0, &p) != (uintptr_t)(~0)); + return (_beginthread (S9xNPServerLoop, 0, &p) != ~0); #else - S9xNPServerLoop(NULL); return (TRUE); #endif @@ -1055,7 +965,11 @@ void S9xNPStopServer () for (int i = 0; i < NP_MAX_CLIENTS; i++) { if (NPServer.Clients [i].Connected) - S9xNPShutdownClient(i, FALSE); + { + close (NPServer.Clients [i].Socket); + NPServer.Clients [i].Connected = FALSE; + NPServer.Clients [i].SaidHello = FALSE; + } } } @@ -1063,7 +977,7 @@ void S9xNPStopServer () void S9xGetTimeOfDay (struct timeval *n) { unsigned long t = S9xGetMilliTime (); - + n->tv_sec = t / 1000; n->tv_usec = (t % 1000) * 1000; } @@ -1101,7 +1015,7 @@ bool8 S9xNPSendROMImageToClient (int c) uint8 header [7 + 1 + 4]; uint8 *ptr = header; - int len = sizeof (header) + Memory.CalculatedSize + + int len = sizeof (header) + Memory.CalculatedSize + strlen (Memory.ROMFilename) + 1; *ptr++ = NP_SERV_MAGIC; *ptr++ = NPServer.Clients [c].SendSequenceNum++; @@ -1133,7 +1047,6 @@ void S9xNPSyncClient (int client) { #ifdef HAVE_MKSTEMP char fname[] = "/tmp/snes9x_fztmpXXXXXX"; - int fd=-1; #else char fname [L_tmpnam]; #endif @@ -1142,7 +1055,7 @@ void S9xNPSyncClient (int client) S9xNPSetAction ("SERVER: Freezing game...", TRUE); #ifdef HAVE_MKSTEMP - if ( ((fd=mkstemp(fname)) >= 0) && S9xFreezeGame(fname) ) + if ( (mkstemp(fname) < 0) && S9xFreezeGame(fname) ) #else if ( tmpnam(fname) && S9xFreezeGame(fname) ) #endif @@ -1177,10 +1090,6 @@ void S9xNPSyncClient (int client) } remove (fname); } -#ifdef HAVE_MKSTEMP - if (fd != -1) - close(fd); -#endif } bool8 S9xNPLoadFreezeFile (const char *fname, uint8 *&data, uint32 &len) @@ -1225,7 +1134,6 @@ void S9xNPSendFreezeFile (int c, uint8 *data, uint32 len) { S9xNPShutdownClient (c, TRUE); } - S9xNPSetAction ("", TRUE); } void S9xNPRecomputePause () @@ -1314,7 +1222,7 @@ void S9xNPSendSRAMToClient (int c) if (SRAMSize > 0x10000) SRAMSize = 0x10000; int len = 7 + SRAMSize; - + sprintf (NetPlay.ActionMsg, "SERVER: Sending S-RAM to player %d...", c + 1); S9xNPSetAction (NetPlay.ActionMsg, TRUE); @@ -1323,11 +1231,11 @@ void S9xNPSendSRAMToClient (int c) *ptr++ = NPServer.Clients [c].SendSequenceNum++; *ptr++ = NP_SERV_SRAM_DATA; WRITE_LONG (ptr, len); - if (!S9xNPSSendData (NPServer.Clients [c].Socket, + if (!S9xNPSSendData (NPServer.Clients [c].Socket, sram, sizeof (sram)) || (len > 7 && !S9xNPSSendData (NPServer.Clients [c].Socket, - Memory.SRAM, len - 7))) + ::SRAM, len - 7))) { S9xNPShutdownClient (c, TRUE); } @@ -1372,8 +1280,8 @@ void S9xNPWaitForEmulationToComplete () #endif while (!NetPlay.PendingWait4Sync && NetPlay.Connected && - !Settings.ForcedPause && !Settings.StopEmulation && - !(Settings.Paused && !Settings.FrameAdvance)) + !Settings.ForcedPause && !Settings.StopEmulation && + !Settings.Paused) { #ifdef __WIN32__ Sleep (40); @@ -1386,7 +1294,7 @@ void S9xNPWaitForEmulationToComplete () void S9xNPServerQueueSyncAll () { - if (Settings.NetPlay && Settings.NetPlayServer && + if (Settings.NetPlay && Settings.NetPlayServer && NPServer.NumClients > NP_ONE_CLIENT) { S9xNPNoClientReady (); @@ -1397,7 +1305,7 @@ void S9xNPServerQueueSyncAll () void S9xNPServerQueueSendingROMImage () { - if (Settings.NetPlay && Settings.NetPlayServer && + if (Settings.NetPlay && Settings.NetPlayServer && NPServer.NumClients > NP_ONE_CLIENT) { S9xNPNoClientReady (); @@ -1408,19 +1316,19 @@ void S9xNPServerQueueSendingROMImage () void S9xNPServerQueueSendingFreezeFile (const char *filename) { - if (Settings.NetPlay && Settings.NetPlayServer && + if (Settings.NetPlay && Settings.NetPlayServer && NPServer.NumClients > NP_ONE_CLIENT) { S9xNPNoClientReady (); S9xNPDiscardHeartbeats (); - S9xNPServerAddTask (NP_SERVER_SEND_FREEZE_FILE_ALL, + S9xNPServerAddTask (NP_SERVER_SEND_FREEZE_FILE_ALL, (void *) strdup (filename)); } } void S9xNPServerQueueSendingLoadROMRequest (const char *filename) { - if (Settings.NetPlay && Settings.NetPlayServer && + if (Settings.NetPlay && Settings.NetPlayServer && NPServer.NumClients > NP_ONE_CLIENT) { S9xNPNoClientReady (); diff --git a/source/snes9x/unused/snaporig.cpp b/source/snes9x/unused/snaporig.cpp index bb07192f..fd6c1263 100644 --- a/source/snes9x/unused/snaporig.cpp +++ b/source/snes9x/unused/snaporig.cpp @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #include #ifdef HAVE_STRINGS_H #include @@ -220,7 +201,7 @@ static int ReadBlock (const char *key, void *block, int max_len, STREAM snap) char buffer [20]; int len = 0; int rem = 0; - + if (READ_STREAM (buffer, 11, snap) != 11 || strncmp (buffer, key, 4) != 0 || (len = atoi (&buffer [4])) == 0) @@ -240,7 +221,7 @@ static int ReadBlock (const char *key, void *block, int max_len, STREAM snap) READ_STREAM (junk, rem, snap); delete[] junk; } - + return (SUCCESS); } @@ -419,7 +400,7 @@ static int ReadOrigSnapshot (STREAM snap) for (i = 0; i < 8; i++) { - DMA[i].ReverseTransfer = OrigDMA[i].ReverseTransfer; + DMA[i].TransferDirection = OrigDMA[i].TransferDirection; DMA[i].AAddressFixed = OrigDMA[i].AAddressFixed; DMA[i].AAddressDecrement = OrigDMA[i].AAddressDecrement; DMA[i].TransferMode = OrigDMA[i].TransferMode; @@ -439,7 +420,7 @@ static int ReadOrigSnapshot (STREAM snap) return (result); if ((result = ReadBlock ("RAM:", Memory.RAM, 0x20000, snap)) != SUCCESS) return (result); - if ((result = ReadBlock ("SRA:", Memory.SRAM, 0x10000, snap)) != SUCCESS) + if ((result = ReadBlock ("SRA:", ::SRAM, 0x10000, snap)) != SUCCESS) return (result); if ((result = ReadBlock ("FIL:", Memory.FillRAM, 0x8000, snap)) != SUCCESS) return (result); @@ -460,7 +441,7 @@ static int ReadOrigSnapshot (STREAM snap) SoundData.master_volume_left = OrigSoundData.master_volume_left; SoundData.master_volume_right = OrigSoundData.master_volume_right; SoundData.echo_volume_left = OrigSoundData.echo_volume_left; - SoundData.echo_volume_right = OrigSoundData.echo_volume_right; + SoundData.echo_volume_right = OrigSoundData.echo_volume_right; SoundData.echo_enable = OrigSoundData.echo_enable; SoundData.echo_feedback = OrigSoundData.echo_feedback; SoundData.echo_ptr = OrigSoundData.echo_ptr; diff --git a/source/snes9x/unused/snaporig.h b/source/snes9x/unused/snaporig.h index 139f9795..c75147b7 100644 --- a/source/snes9x/unused/snaporig.h +++ b/source/snes9x/unused/snaporig.h @@ -1,7 +1,7 @@ /********************************************************************************** Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com) and Jerremy Koot (jkoot@snes9x.com) (c) Copyright 2002 - 2004 Matthew Kendora @@ -12,16 +12,12 @@ (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), + (c) Copyright 2002 - 2006 Brad Jorsch (anomie@users.sourceforge.net), + funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com), + Nach (n-a-c-h@users.sourceforge.net), and zones (kasumitokoduck@yahoo.com) - (c) Copyright 2006 - 2007 nitsuja - - BS-X C emulator code (c) Copyright 2005 - 2006 Dreamer Nom, zones @@ -114,30 +110,17 @@ 2xSaI filter (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - HQ2x, HQ3x, HQ4x filters + HQ2x filter (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - Specific ports contains the works of other authors. See headers in individual files. - Snes9x homepage: http://www.snes9x.com Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear with all copies and any derived work. This software is provided 'as-is', without any express or implied @@ -158,8 +141,6 @@ Nintendo Co., Limited and its subsidiary companies. **********************************************************************************/ - - #ifndef _SNAPORIG_H_ #define _SNAPORIG_H_ @@ -179,7 +160,7 @@ struct SOrigCPUState{ bool8 NMIActive; bool8 IRQActive; bool8 WaitingForInterrupt; - bool8 InDMAorHDMA; + bool8 InDMA; uint8 WhichEvent; uint8 *PC; uint8 *PCBase; @@ -331,7 +312,7 @@ struct SOrigPPU { } BG [4]; bool8 CGFLIP; - uint16 CGDATA [256]; + uint16 CGDATA [256]; uint8 FirstSprite; uint8 LastSprite; struct SOrigOBJ OBJ [129]; @@ -404,7 +385,7 @@ struct SOrigPPU { }; struct SOrigDMA { - bool8 ReverseTransfer; + bool8 TransferDirection; bool8 AAddressFixed; bool8 AAddressDecrement; uint8 TransferMode; diff --git a/source/snes9x/unused/snes9x_default_config.cfg b/source/snes9x/unused/snes9x_default_config.cfg deleted file mode 100644 index aaf168f0..00000000 --- a/source/snes9x/unused/snes9x_default_config.cfg +++ /dev/null @@ -1,81 +0,0 @@ -#--------------------------- -# Snes9x Configuration file -#--------------------------- - -[CPU] -Cycles = -DisableIRQ = - -[ROM] -PAL = -NTSC = -HiROM = -LoROM = -Header = -Interleaved = -Interleaved2 = -InterleaveGD24 = -SuperFX = -DSP1 = -Cheat = -Patch = -BS = -Filename = - -[Sound] -APUEnabled = -Sync = -Stereo = -SixteenBitSound = -AltDecode = -BufferSize = -Echo = -FixFrequency = -Interpolate = -MasterVolume = -Rate = -SoundSkip = -ReverseStereo = -EnvelopeHeightReading = -FakeMuteFix = -SampleCaching = -Mute = - -[Display] -GraphicWindows = -Mode7Interpolate = -HiRes = -Transparency = -MessagesInImage = -FrameRate = -DisplayInput = -DisplayFrameCount = - -[Settings] -DisableHDMA = -TurboMode = -StretchScreenshots = -BGLayeringHack = -PALFrameTime = -NTSCFrameTime = -FrameTime = -FrameSkip = -AutoMaxSkipFramesAtOnce = -TurboFrameSkip = -AutoSaveDelay = -SpeedHacks = - -[Controls] -MP5Master = -MouseMaster = -SuperscopeMaster = -JustifierMaster = -Port1 = -Port2 = -Mouse1Crosshair = -Mouse2Crosshair = -SuperscopeCrosshair = -Justifier1Crosshair = -Justifier2Crosshair = -Joystick = -AllowLeftRight = diff --git a/source/snes9x/unused/sound.cpp b/source/snes9x/unused/sound.cpp deleted file mode 100644 index de396555..00000000 --- a/source/snes9x/unused/sound.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - - - -#ifndef __WIN32__ - -#include -#include -#include -#include -#include -#include -#include - -#define EQ == -#define MINBUFFLEN 10000 - -#include -#include -#include -#include -#include - -#include "snes9x.h" -#include "soundux.h" - -extern SoundStatus so; - -extern int AudioOpen(unsigned long freq, unsigned long bufsize, unsigned long bitrate, unsigned long stereo); -extern void AudioClose(void); - -extern int OpenPrelude(ULONG Type, ULONG DefaultFreq, ULONG MinBuffSize); -extern void ClosePrelude(void); - -extern int SoundSignal; -unsigned long DoubleBuffer; -//extern struct AHISampleInfo Sample0; -//extern struct AHISampleInfo Sample1; -//extern unsigned long BufferSize; - -struct Library *AHIPPCBase; -struct Library *AHIBase; -struct MsgPort *AHImp=NULL; -struct AHIRequest *AHIio=NULL; -BYTE AHIDevice=-1; - -struct AHIData *AHIData; - -unsigned long Frequency = 0; -//unsigned long BufferSize = 0; -unsigned long BitRate = 0; -unsigned long Stereo = 0; -//unsigned long AHIError = 9; - -BYTE InternSignal=-1; - -int mixsamples; -extern int prelude; - -#define REALSIZE (BitRate*Stereo) - -struct AHIAudioModeRequester *req=NULL; -struct AHIAudioCtrl *actrl=NULL; - -ULONG BufferLen=NULL; - - -/* this really should be dynamically allocated... */ -#undef MAX_BUFFER_SIZE -#define MAX_BUFFER_SIZE 65536 -#define MIN_BUFFER_SIZE 65536 - -#define MODE_MONO 0 -#define MODE_STEREO 1 - -#define QUAL_8BIT 8 -#define QUAL_16BIT 16 - - -int test=0; -int test2=0; - -int AudioOpen(unsigned long freq, unsigned long minbufsize, unsigned long bitrate, unsigned long stereo) -{ - ULONG Type; - - Frequency = freq; - - so.playback_rate = Frequency; - - if(stereo) so.stereo = TRUE; - else so.stereo = FALSE; - - switch(bitrate) - { - case 8: - so.sixteen_bit = FALSE; - BitRate=1; - if(stereo) - { - Stereo=2; - Type = AHIST_S8S; - } - else - { - Stereo=1; - Type = AHIST_M8S; - } - - break; - - default: //defaulting to 16bit, because it means it won't crash atleast - case QUAL_16BIT: - so.sixteen_bit = TRUE; - BitRate=2; - if(stereo) - { - Stereo=2; - Type = AHIST_S16S; - } - else - { - Stereo=1; - Type = AHIST_M16S; - } - break; - } - - if(prelude) prelude = OpenPrelude(Type, freq, minbufsize); - - - if(prelude) return 1; else printf("Defaulting to AHI...\n"); - - /* only 1 channel right? */ - /* NOTE: The buffersize will not always be what you requested - * it finds the minimun AHI requires and then rounds it up to - * nearest 32 bytes. Check AHIData->BufferSize or Samples[n].something_Length - */ - if(AHIData = OpenAHI(1, Type, AHI_INVALID_ID, AHI_DEFAULT_FREQ, 0, minbufsize)) - { - printf("AHI opened\n"); - printf("BuffSize %d\n", AHIData->BufferSize); - } - else - { - printf("AHI failed to open: %d\n", AHIData); - return 0; - } - - so.buffer_size = AHIData->BufferSize; // in bytes - if (so.buffer_size > MAX_BUFFER_SIZE) so.buffer_size = MAX_BUFFER_SIZE; - - /* Lots of useful fields in the AHIData struct, have a look */ - AHIBase = AHIData->AHIBase; - actrl = AHIData->AudioCtrl; - Frequency = AHIData->MixingFreq; - - printf("signal %ld\n", AHIData->SoundFuncSignal); - - Wait(AHIData->SoundFuncSignal); - - /* I don't think it should start playing until there is something - * In the buffer, however to set off the SoundFunc it should - * probably go through the buffer at least once, just silently. - */ - AHI_SetFreq(0, Frequency, actrl, AHISF_IMM); - - Wait(AHIData->SoundFuncSignal); - - AHI_SetVol(0, 0x10000, 0x8000, actrl, AHISF_IMM); - - mixsamples=AHIData->BufferSamples; - - SoundSignal = AHIData->SoundFuncSignal; - - return 1; -} - -void AudioClose( void ) -{ - if(prelude) ClosePrelude(); - else ;//CloseAHI(AHIData); -} - - -#include - -extern int main(int argc, char **argv); - -void wbmain(struct WBStartup * argmsg) -{ - char argv[1][]={"WarpSNES"}; - int argc=1; - main(argc,(char **)argv); -} - - -#endif diff --git a/source/snes9x/unused/xenofarm.sh b/source/snes9x/unused/xenofarm.sh deleted file mode 100644 index 90f2254f..00000000 --- a/source/snes9x/unused/xenofarm.sh +++ /dev/null @@ -1,113 +0,0 @@ -#! /bin/sh - -# This script is part of the automated Xenofarm testing testing. For -# more information about Xenofarm see http://www.lysator.liu.se/xenofarm/ - -# $Id: xenofarm.sh,v 1.6 2003/11/09 14:02:39 pbortas Exp $ -# This file scripts the xenofarm actions and creates a result package -# to send back. - -#FIXME: snes9x doesn't really need MAKE_FLAGS. Clean out later. - -BUILDDIR=. -#OS=`uname -s -r -m|sed \"s/ /-/g\"|tr \"[A-Z]\" \"[a-z]\"|tr \"/()\" \"___\"` -#BUILDDIR=build/$(OS) -MAKE=${MAKE-make} -PATH=$PATH:/usr/ccs/bin -export PATH - -log() { - echo $1 | tee -a build/xenofarm/mainlog.txt -} - -log_start() { - log "BEGIN $1" - TZ=GMT date >> build/xenofarm/mainlog.txt -} - -log_end() { - LASTERR=$1 - if [ "$1" = "0" ] ; then - log "PASS" - else - log "FAIL" - fi - TZ=GMT date >> build/xenofarm/mainlog.txt -} - -xenofarm_build() { - log_start compile - "`pwd`/configure" >> build/xenofarm/compilelog.txt 2>&1 && - $MAKE $MAKE_FLAGS >> build/xenofarm/compilelog.txt 2>&1 - log_end $? - [ $LASTERR = 0 ] || return 1 -} - -xenofarm_post_build() { - log_start verify - $MAKE $MAKE_FLAGS verify > build/xenofarm/verifylog.txt 2>&1 - log_end $? - [ $LASTERR = 0 ] || return 1 - - log_start binrelease - $MAKE $MAKE_FLAGS bin-release > build/xenofarm/binreleaselog.txt 2>&1 - log_end $? - [ $LASTERR = 0 ] || return 1 -} - -fail_builddir() { - echo "FATAL: Failed to create build directory!" - exit 1 -} - -# main code - -test -d build || mkdir build 2>&1 && -rm -rf build/xenofarm 2>&1 && -mkdir build/xenofarm 2>&1 || fail_builddir - -LC_CTYPE=C -export LC_CTYPE -log "FORMAT 2" - -log_start build -xenofarm_build -log_end $? - -if [ $LASTERR = 0 ]; then - log_start post_build - xenofarm_post_build - log_end $? - else : -fi - -log_start response_assembly - # Basic stuff - cp ../buildid.txt build/xenofarm/ - # Configuration - cp "$BUILDDIR/config.info" build/xenofarm/configinfo.txt 2>/dev/null || /bin/true - ( - cd "$BUILDDIR" - test -f config.log && cat config.log - for f in `find . -name config.log -type f`; do - echo - echo '###################################################' - echo '##' `dirname "$f"` - echo - cat "$f" - done - ) > build/xenofarm/configlogs.txt - cp "$BUILDDIR/config.cache" build/xenofarm/configcache.txt 2>/dev/null || /bin/true; - # Core files - find . -name "core" -exec \ - gdb --batch --nx --command=bin/xenofarm_gdb_cmd "$BUILDDIR/pike" {} >> \ - build/xenofarm/_core.txt ";" - find . -name "*.core" -exec \ - gdb --batch --nx --command=bin/xenofarm_gdb_cmd "$BUILDDIR/pike" {} >> \ - build/xenofarm/_core.txt ";" - find . -name "core.*" -exec \ - gdb --batch --nx --command=bin/xenofarm_gdb_cmd "$BUILDDIR/pike" {} >> \ - build/xenofarm/_core.txt ";" -log_end $? - -log "END" diff --git a/source/snes9x/unused/xenofarm_gdb_cmd b/source/snes9x/unused/xenofarm_gdb_cmd deleted file mode 100644 index 43b471d2..00000000 --- a/source/snes9x/unused/xenofarm_gdb_cmd +++ /dev/null @@ -1,14 +0,0 @@ -echo \nActive threads\n -info threads -echo \nBacktrace\n -bt -echo \nSource code for frame 0\n -list -echo \nDisassembly of frame 0\n -disassemble -echo \nSource code for frame 1\n -up -list -echo \nDisassembly of frame 1\n -disassemble -echo \nEnd of core inspection\n\n\n\n diff --git a/source/sz/7zAlloc.c b/source/sz/7zAlloc.c deleted file mode 100644 index d5da81b1..00000000 --- a/source/sz/7zAlloc.c +++ /dev/null @@ -1,70 +0,0 @@ -/* 7zAlloc.c */ - -#include -#include "7zAlloc.h" - -/* #define _SZ_ALLOC_DEBUG */ -/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ - -#ifdef _SZ_ALLOC_DEBUG - -#ifdef _WIN32 -#include -#endif -#include -int g_allocCount = 0; -int g_allocCountTemp = 0; -#endif - -void *SzAlloc(size_t size) -{ - if (size == 0) - return 0; - #ifdef _SZ_ALLOC_DEBUG - fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); - g_allocCount++; - #endif - return malloc(size); -} - -void SzFree(void *address) -{ - #ifdef _SZ_ALLOC_DEBUG - if (address != 0) - { - g_allocCount--; - fprintf(stderr, "\nFree; count = %10d", g_allocCount); - } - #endif - free(address); -} - -void *SzAllocTemp(size_t size) -{ - if (size == 0) - return 0; - #ifdef _SZ_ALLOC_DEBUG - fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp); - g_allocCountTemp++; - #ifdef _WIN32 - return HeapAlloc(GetProcessHeap(), 0, size); - #endif - #endif - return malloc(size); -} - -void SzFreeTemp(void *address) -{ - #ifdef _SZ_ALLOC_DEBUG - if (address != 0) - { - g_allocCountTemp--; - fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); - } - #ifdef _WIN32 - HeapFree(GetProcessHeap(), 0, address); - return; - #endif - #endif - free(address); -} diff --git a/source/sz/7zAlloc.h b/source/sz/7zAlloc.h deleted file mode 100644 index b02c1dea..00000000 --- a/source/sz/7zAlloc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* 7zAlloc.h */ - -#ifndef __7Z_ALLOC_H -#define __7Z_ALLOC_H - -#include - -typedef struct _ISzAlloc -{ - void *(*Alloc)(size_t size); - void (*Free)(void *address); /* address can be 0 */ -} ISzAlloc; - -void *SzAlloc(size_t size); -void SzFree(void *address); - -void *SzAllocTemp(size_t size); -void SzFreeTemp(void *address); - -#endif diff --git a/source/sz/7zBuffer.c b/source/sz/7zBuffer.c deleted file mode 100644 index 8bc8e067..00000000 --- a/source/sz/7zBuffer.c +++ /dev/null @@ -1,29 +0,0 @@ -/* 7zBuffer.c */ - -#include "7zBuffer.h" -#include "7zAlloc.h" - -void SzByteBufferInit(CSzByteBuffer *buffer) -{ - buffer->Capacity = 0; - buffer->Items = 0; -} - -int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size)) -{ - buffer->Capacity = newCapacity; - if (newCapacity == 0) - { - buffer->Items = 0; - return 1; - } - buffer->Items = (Byte *)allocFunc(newCapacity); - return (buffer->Items != 0); -} - -void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *)) -{ - freeFunc(buffer->Items); - buffer->Items = 0; - buffer->Capacity = 0; -} diff --git a/source/sz/7zBuffer.h b/source/sz/7zBuffer.h deleted file mode 100644 index afea3ca8..00000000 --- a/source/sz/7zBuffer.h +++ /dev/null @@ -1,19 +0,0 @@ -/* 7zBuffer.h */ - -#ifndef __7Z_BUFFER_H -#define __7Z_BUFFER_H - -#include -#include "7zTypes.h" - -typedef struct _CSzByteBuffer -{ - size_t Capacity; - Byte *Items; -}CSzByteBuffer; - -void SzByteBufferInit(CSzByteBuffer *buffer); -int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size)); -void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *)); - -#endif diff --git a/source/sz/7zCrc.c b/source/sz/7zCrc.c deleted file mode 100644 index 6dc7dd32..00000000 --- a/source/sz/7zCrc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* 7zCrc.c */ - -#include "7zCrc.h" - -#define kCrcPoly 0xEDB88320 - -UInt32 g_CrcTable[256]; - -void InitCrcTable() -{ - UInt32 i; - for (i = 0; i < 256; i++) - { - UInt32 r = i; - int j; - for (j = 0; j < 8; j++) - if (r & 1) - r = (r >> 1) ^ kCrcPoly; - else - r >>= 1; - g_CrcTable[i] = r; - } -} - -void CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; } -UInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } - -void CrcUpdateByte(UInt32 *crc, Byte b) -{ - *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8); -} - -void CrcUpdateUInt16(UInt32 *crc, UInt16 v) -{ - CrcUpdateByte(crc, (Byte)v); - CrcUpdateByte(crc, (Byte)(v >> 8)); -} - -void CrcUpdateUInt32(UInt32 *crc, UInt32 v) -{ - int i; - for (i = 0; i < 4; i++) - CrcUpdateByte(crc, (Byte)(v >> (8 * i))); -} - -void CrcUpdateUInt64(UInt32 *crc, UInt64 v) -{ - int i; - for (i = 0; i < 8; i++) - { - CrcUpdateByte(crc, (Byte)(v)); - v >>= 8; - } -} - -void CrcUpdate(UInt32 *crc, const void *data, size_t size) -{ - UInt32 v = *crc; - const Byte *p = (const Byte *)data; - for (; size > 0 ; size--, p++) - v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8); - *crc = v; -} - -UInt32 CrcCalculateDigest(const void *data, size_t size) -{ - UInt32 crc; - CrcInit(&crc); - CrcUpdate(&crc, data, size); - return CrcGetDigest(&crc); -} - -int CrcVerifyDigest(UInt32 digest, const void *data, size_t size) -{ - return (CrcCalculateDigest(data, size) == digest); -} diff --git a/source/sz/7zCrc.h b/source/sz/7zCrc.h deleted file mode 100644 index bac26b14..00000000 --- a/source/sz/7zCrc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* 7zCrc.h */ - -#ifndef __7Z_CRC_H -#define __7Z_CRC_H - -#include - -#include "7zTypes.h" - -extern UInt32 g_CrcTable[256]; -void InitCrcTable(); - -void CrcInit(UInt32 *crc); -UInt32 CrcGetDigest(UInt32 *crc); -void CrcUpdateByte(UInt32 *crc, Byte v); -void CrcUpdateUInt16(UInt32 *crc, UInt16 v); -void CrcUpdateUInt32(UInt32 *crc, UInt32 v); -void CrcUpdateUInt64(UInt32 *crc, UInt64 v); -void CrcUpdate(UInt32 *crc, const void *data, size_t size); - -UInt32 CrcCalculateDigest(const void *data, size_t size); -int CrcVerifyDigest(UInt32 digest, const void *data, size_t size); - -#endif diff --git a/source/sz/7zDecode.c b/source/sz/7zDecode.c deleted file mode 100644 index 12198eea..00000000 --- a/source/sz/7zDecode.c +++ /dev/null @@ -1,361 +0,0 @@ -/* 7zDecode.c */ - -#include "7zDecode.h" -#ifdef _SZ_ONE_DIRECTORY -#include "LzmaDecode.h" -#else -#include "../../Compress/LZMA_C/LzmaDecode.h" -#endif - -#ifdef _LZMA_OUT_READ -#include // for memcpy -#endif - -CMethodID k_Copy = { { 0x0 }, 1 }; -CMethodID k_LZMA = { { 0x3, 0x1, 0x1 }, 3 }; - -#ifdef _LZMA_IN_CB - -typedef struct _CLzmaInCallbackImp -{ - ILzmaInCallback InCallback; - ISzInStream *InStream; - size_t Size; -} CLzmaInCallbackImp; - -int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size) -{ - CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object; - size_t processedSize; - SZ_RESULT res; - *size = 0; - res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, cb->Size, &processedSize); - *size = (SizeT)processedSize; - if (processedSize > cb->Size) - return (int)SZE_FAIL; - cb->Size -= processedSize; - if (res == SZ_OK) - return 0; - return (int)res; -} - -#endif - -SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, - #ifdef _LZMA_IN_CB - ISzInStream *inStream, - #else - const Byte *inBuffer, - #endif - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain) -{ - UInt32 si; - size_t inSize = 0; - CCoderInfo *coder; - if (folder->NumPackStreams != 1) - return SZE_NOTIMPL; - if (folder->NumCoders != 1) - return SZE_NOTIMPL; - coder = folder->Coders; - *outSizeProcessed = 0; - - for (si = 0; si < folder->NumPackStreams; si++) - inSize += (size_t)packSizes[si]; - - if (AreMethodsEqual(&coder->MethodID, &k_Copy)) - { - size_t i; - if (inSize != outSize) - return SZE_DATA_ERROR; - #ifdef _LZMA_IN_CB - for (i = 0; i < inSize;) - { - size_t j; - Byte *inBuffer; - size_t bufferSize; - RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, inSize - i, &bufferSize)); - if (bufferSize == 0) - return SZE_DATA_ERROR; - if (bufferSize > inSize - i) - return SZE_FAIL; - *outSizeProcessed += bufferSize; - for (j = 0; j < bufferSize && i < inSize; j++, i++) - outBuffer[i] = inBuffer[j]; - } - #else - for (i = 0; i < inSize; i++) - outBuffer[i] = inBuffer[i]; - *outSizeProcessed = inSize; - #endif - return SZ_OK; - } - - if (AreMethodsEqual(&coder->MethodID, &k_LZMA)) - { - #ifdef _LZMA_IN_CB - CLzmaInCallbackImp lzmaCallback; - #else - SizeT inProcessed; - #endif - - CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */ - int result; - SizeT outSizeProcessedLoc; - - #ifdef _LZMA_IN_CB - lzmaCallback.Size = inSize; - lzmaCallback.InStream = inStream; - lzmaCallback.InCallback.Read = LzmaReadImp; - #endif - - if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, - coder->Properties.Capacity) != LZMA_RESULT_OK) - return SZE_FAIL; - - state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); - if (state.Probs == 0) - return SZE_OUTOFMEMORY; - - #ifdef _LZMA_OUT_READ - if (state.Properties.DictionarySize == 0) - state.Dictionary = 0; - else - { - state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize); - if (state.Dictionary == 0) - { - allocMain->Free(state.Probs); - return SZE_OUTOFMEMORYDIC; - } - } - LzmaDecoderInit(&state); - #endif - - result = LzmaDecode(&state, - #ifdef _LZMA_IN_CB - &lzmaCallback.InCallback, - #else - inBuffer, (SizeT)inSize, &inProcessed, - #endif - outBuffer, (SizeT)outSize, &outSizeProcessedLoc); - *outSizeProcessed = (size_t)outSizeProcessedLoc; - allocMain->Free(state.Probs); - #ifdef _LZMA_OUT_READ - allocMain->Free(state.Dictionary); - #endif - if (result == LZMA_RESULT_DATA_ERROR) - return SZE_DATA_ERROR; - if (result != LZMA_RESULT_OK) - return SZE_FAIL; - return SZ_OK; - } - return SZE_NOTIMPL; -} - -#ifdef _LZMA_OUT_READ -// like SzDecode but uses less memory -SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder, - ISzInStream *inStream, - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain, - size_t *fileOffset, size_t *fileSize) -{ - UInt32 si; - size_t inSize = 0; - CCoderInfo *coder; - if (folder->NumPackStreams != 1) - return SZE_NOTIMPL; - if (folder->NumCoders != 1) - return SZE_NOTIMPL; - coder = folder->Coders; - *outSizeProcessed = 0; - - for (si = 0; si < folder->NumPackStreams; si++) - inSize += (size_t)packSizes[si]; - - if (AreMethodsEqual(&coder->MethodID, &k_Copy)) - { - size_t i; - if (inSize != outSize) - return SZE_DATA_ERROR; - #ifdef _LZMA_IN_CB - for (i = 0; i < inSize;) - { - size_t j; - Byte *inBuffer; - size_t bufferSize; - RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, inSize - i, &bufferSize)); - if (bufferSize == 0) - return SZE_DATA_ERROR; - if (bufferSize > inSize - i) - return SZE_FAIL; - *outSizeProcessed += bufferSize; - for (j = 0; j < bufferSize && i < inSize; j++, i++) - outBuffer[i] = inBuffer[j]; - } - #else - for (i = 0; i < inSize; i++) - outBuffer[i] = inBuffer[i]; - *outSizeProcessed = inSize; - #endif - return SZ_OK; - } - - if (AreMethodsEqual(&coder->MethodID, &k_LZMA)) - { - #ifdef _LZMA_IN_CB - CLzmaInCallbackImp lzmaCallback; - #else - SizeT inProcessed; - #endif - - CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */ - int result; - SizeT outSizeProcessedLoc; - - #ifdef _LZMA_IN_CB - lzmaCallback.Size = inSize; - lzmaCallback.InStream = inStream; - lzmaCallback.InCallback.Read = LzmaReadImp; - #endif - - if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items, - coder->Properties.Capacity) != LZMA_RESULT_OK) - return SZE_FAIL; - - state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); - if (state.Probs == 0) - return SZE_OUTOFMEMORY; - - if (state.Properties.DictionarySize == 0) - state.Dictionary = 0; - else - { - state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize); - if (state.Dictionary == 0) - { - allocMain->Free(state.Probs); - return SZE_OUTOFMEMORY; - } - } - LzmaDecoderInit(&state); - - // allocate memory for the temporary buffer - Byte *tmpBuffer = (Byte *)allocMain->Alloc(_LZMA_TEMP_BUFFER_SIZE); - - // variables containing the number of the first and the last bytes of the buffer - size_t bufferStart, bufferEnd; - bufferStart = bufferEnd = 0; - - // integers contains the offset, the size and the already copied data which will be - // copied from the tmpBuffer to outBuffer - size_t copyOffset, copySize, copyDone; - copyOffset = copySize = copyDone = 0; - - UInt32 i = 0; - int bytesToCopy = 0; - - // decompress data in _LZMA_TEMP_BUFFER_SIZE byte steps and copy the wanted file to outBuffer - do - { - if((*fileSize - copyDone) >= _LZMA_TEMP_BUFFER_SIZE) - bytesToCopy = _LZMA_TEMP_BUFFER_SIZE; - else - bytesToCopy = (*fileSize - copyDone); - - // decompress next bytes - result = LzmaDecode(&state, - #ifdef _LZMA_IN_CB - &lzmaCallback.InCallback, - #else - //inBuffer, (SizeT)inSize, &inProcessed, //TODO! - #endif - tmpBuffer, bytesToCopy, &outSizeProcessedLoc - ); - - // check result - if(result == LZMA_RESULT_DATA_ERROR) - { - return SZE_DATA_ERROR; - } - if(result != LZMA_RESULT_OK) - { - return SZE_FAIL; - } - - // normally this should never happen - if(outSizeProcessedLoc > _LZMA_TEMP_BUFFER_SIZE) - { - return SZE_FAIL; - } - - // update bufferStart and bufferEnd - bufferStart = _LZMA_TEMP_BUFFER_SIZE * i; - bufferEnd = bufferStart + outSizeProcessedLoc; - i++; - - // calculate copy offset and size - if(*fileOffset > bufferEnd) - { - // we haven't reached the start of the file yet - continue; - } - - // calculate offset - if(*fileOffset < bufferStart) - { - // the file has already started before this decompression step - copyOffset = 0; - } - else - { - // the file starts somewhere inside this buffer - copyDone = 0; - copyOffset = _LZMA_TEMP_BUFFER_SIZE - (bufferEnd - *fileOffset); - } - - // calculate size - if((*fileOffset + *fileSize) > bufferEnd) - { - // we'll need the whole buffer after copyOffset - copySize = _LZMA_TEMP_BUFFER_SIZE - copyOffset; - } - else - { - // we'll stop somewhere inside the buffer - copySize = (*fileOffset + *fileSize) - (bufferStart + copyOffset); - } - - // copy bytes to the real output buffer - if(copySize == 0) - { - continue; - } - // printf("memcpy(outBuffer + %d, tmpBuffer + %d, %d)\n", copyDone, copyOffset, copySize); - memcpy(outBuffer + copyDone, tmpBuffer + copyOffset, copySize); - copyDone += copySize; - } - while((*fileOffset + *fileSize) > bufferEnd); - - /* result = LzmaDecode(&state, - #ifdef _LZMA_IN_CB - &lzmaCallback.InCallback, - #else - inBuffer, (SizeT)inSize, &inProcessed, - #endif - outBuffer, (SizeT)outSize, &outSizeProcessedLoc);*/ - //*outSizeProcessed = (size_t)outSizeProcessedLoc; - *outSizeProcessed = copyDone; - allocMain->Free(tmpBuffer); // free the temporary buffer again - allocMain->Free(state.Probs); - allocMain->Free(state.Dictionary); - /* if (result == LZMA_RESULT_DATA_ERROR) - return SZE_DATA_ERROR; - if (result != LZMA_RESULT_OK) - return SZE_FAIL;*/ - return SZ_OK; - } - return SZE_NOTIMPL; - } - #endif diff --git a/source/sz/7zDecode.h b/source/sz/7zDecode.h deleted file mode 100644 index 9f15ba16..00000000 --- a/source/sz/7zDecode.h +++ /dev/null @@ -1,37 +0,0 @@ -/* 7zDecode.h */ - -#if defined(_LZMA_OUT_READ) && !defined(_LZMA_IN_CB) -#error "Fixme: _LZMA_OUT_READ && _LZMA_IN_CB isn't currently possible!" -#endif - -#ifndef __7Z_DECODE_H -#define __7Z_DECODE_H - -#include "7zItem.h" -#include "7zAlloc.h" -#ifdef _LZMA_IN_CB -#include "7zIn.h" -#endif - -SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder, - #ifdef _LZMA_IN_CB - ISzInStream *stream, - #else - const Byte *inBuffer, - #endif - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain); - -#ifdef _LZMA_OUT_READ -#ifndef _LZMA_TEMP_BUFFER_SIZE -#define _LZMA_TEMP_BUFFER_SIZE (2048) // size of the temporary buffer in bytes -#endif - -SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder, - ISzInStream *stream, - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain, - size_t *fileOffset, size_t *fileSize); -#endif // #ifdef _LZMA_OUT_READ - -#endif diff --git a/source/sz/7zExtract.c b/source/sz/7zExtract.c deleted file mode 100644 index 13ba62ce..00000000 --- a/source/sz/7zExtract.c +++ /dev/null @@ -1,254 +0,0 @@ -/* 7zExtract.c */ - -#include "7zExtract.h" -#include "7zDecode.h" -#include "7zCrc.h" - -SZ_RESULT SzExtract( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - UInt32 fileIndex, - UInt32 *blockIndex, - Byte **outBuffer, - size_t *outBufferSize, - size_t *offset, - size_t *outSizeProcessed, - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex]; - SZ_RESULT res = SZ_OK; - *offset = 0; - *outSizeProcessed = 0; - if (folderIndex == (UInt32)-1) - { - allocMain->Free(*outBuffer); - *blockIndex = folderIndex; - *outBuffer = 0; - *outBufferSize = 0; - return SZ_OK; - } - - if (*outBuffer == 0 || *blockIndex != folderIndex) - { - CFolder *folder = db->Database.Folders + folderIndex; - CFileSize unPackSize = SzFolderGetUnPackSize(folder); - #ifndef _LZMA_IN_CB - CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex); - Byte *inBuffer = 0; - size_t processedSize; - #endif - *blockIndex = folderIndex; - allocMain->Free(*outBuffer); - *outBuffer = 0; - - RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0))); - - #ifndef _LZMA_IN_CB - if (packSize != 0) - { - inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize); - if (inBuffer == 0) - return SZE_OUTOFMEMORY; - } - res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize); - if (res == SZ_OK && processedSize != (size_t)packSize) - res = SZE_FAIL; - #endif - if (res == SZ_OK) - { - *outBufferSize = (size_t)unPackSize; - if (unPackSize != 0) - { - *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize); - if (*outBuffer == 0) - res = SZE_OUTOFMEMORY; - } - if (res == SZ_OK) - { - size_t outRealSize; - res = SzDecode(db->Database.PackSizes + - db->FolderStartPackStreamIndex[folderIndex], folder, - #ifdef _LZMA_IN_CB - inStream, - #else - inBuffer, - #endif - *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp); - if (res == SZ_OK) - { - if (outRealSize == (size_t)unPackSize) - { - if (folder->UnPackCRCDefined) - { - if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize)) - res = SZE_FAIL; - } - } - else - res = SZE_FAIL; - } - } - } - #ifndef _LZMA_IN_CB - allocTemp->Free(inBuffer); - #endif - } - if (res == SZ_OK) - { - UInt32 i; - CFileItem *fileItem = db->Database.Files + fileIndex; - *offset = 0; - for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++) - *offset += (UInt32)db->Database.Files[i].Size; - *outSizeProcessed = (size_t)fileItem->Size; - if (*offset + *outSizeProcessed > *outBufferSize) - return SZE_FAIL; - { - if (fileItem->IsFileCRCDefined) - { - if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed)) - res = SZE_FAIL; - } - } - } - return res; -} - -#ifdef _LZMA_OUT_READ -// similar to SzExtract but needs less memory -SZ_RESULT SzExtract2( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - UInt32 fileIndex, - UInt32 *blockIndex, - Byte **outBuffer, - size_t *outBufferSize, - size_t *offset, - size_t *outSizeProcessed, - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex]; - SZ_RESULT res = SZ_OK; - *offset = 0; - *outSizeProcessed = 0; - if (folderIndex == (UInt32)-1) - { - *blockIndex = folderIndex; - #ifndef NGC - allocMain->Free(*outBuffer); - *outBuffer = 0; - #endif - *outBufferSize = 0; - return SZ_OK; - } - -// if (*outBuffer == 0 || *blockIndex != folderIndex) -// { - CFolder *folder = db->Database.Folders + folderIndex; - CFileSize unPackSize = SzFolderGetUnPackSize(folder); - #ifndef _LZMA_IN_CB - CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex); - Byte *inBuffer = 0; - size_t processedSize; - #endif - *blockIndex = folderIndex; - #ifndef NGC - allocMain->Free(*outBuffer); - *outBuffer = 0; - #endif - - RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0))); - - #ifndef _LZMA_IN_CB - if (packSize != 0) - { - inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize); - if (inBuffer == 0) - return SZE_OUTOFMEMORY; - } - res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize); - if (res == SZ_OK && processedSize != (size_t)packSize) - res = SZE_FAIL; - #endif - if (res == SZ_OK) - { - // calculate file offset and filesize - CFileItem *fileItem = db->Database.Files + fileIndex; - UInt32 i; - *offset = 0; - for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++) - *offset += (UInt32)db->Database.Files[i].Size; - *outSizeProcessed = (size_t)fileItem->Size; - *outBufferSize = (size_t)fileItem->Size; - if (unPackSize != 0) - { - #ifndef NGC - *outBuffer = (Byte *)allocMain->Alloc((size_t)fileItem->Size); - if (*outBuffer == 0) - res = SZE_OUTOFMEMORY; - #endif - } - if (res == SZ_OK) - { - - size_t outRealSize; - res = SzDecode2(db->Database.PackSizes + - db->FolderStartPackStreamIndex[folderIndex], folder, - #ifdef _LZMA_IN_CB - inStream, - #else - inBuffer, - #endif - *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp, - offset, outSizeProcessed - ); - *outSizeProcessed = outRealSize; -/* if (res == SZ_OK) // we can't validate the CRC of the whole data stream because we only extracted the wanted file - { - if (outRealSize == (size_t)unPackSize) - { - if (folder->UnPackCRCDefined) - { - if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize)) - res = SZE_FAIL; - } - } - else - res = SZE_FAIL; - }*/ - } -// } - #ifndef _LZMA_IN_CB - allocTemp->Free(inBuffer); - #endif - } - if (res == SZ_OK) - { -/* UInt32 i; - CFileItem *fileItem = db->Database.Files + fileIndex; - *offset = 0; - for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++) - *offset += (UInt32)db->Database.Files[i].Size; - *outSizeProcessed = (size_t)fileItem->Size;*/ - //CFileItem *fileItem = db->Database.Files + fileIndex; - if (/**offset +*/ *outSizeProcessed > *outBufferSize) - return SZE_FAIL; - { - //if (fileItem->IsFileCRCDefined) - //{ - // if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer/* + *offset*/, *outSizeProcessed)) - // res = SZE_CRC_ERROR; // why does SzExtract return SZE_FAIL when we can return SZE_CRC_ERROR? - //} - } - } - - // change *offset to 0 because SzExtract normally decompresses the whole solid block - // and sets *offset to the offset of the wanted file. - // SzDecode2 does only copy the needed file to the output buffer and has to set *offset - // to 0 to ensure compatibility with SzExtract - *offset = 0; - return res; -} -#endif diff --git a/source/sz/7zExtract.h b/source/sz/7zExtract.h deleted file mode 100644 index 7f7e07ee..00000000 --- a/source/sz/7zExtract.h +++ /dev/null @@ -1,60 +0,0 @@ -/* 7zExtract.h */ - -#if defined(_LZMA_OUT_READ) && !defined(_LZMA_IN_CB) -#error "Fixme: _LZMA_OUT_READ && _LZMA_IN_CB isn't currently possible!" -#endif - -#ifndef __7Z_EXTRACT_H -#define __7Z_EXTRACT_H - -#include "7zIn.h" - -/* - SzExtract extracts file from archive - - SzExtract2 does the same but needs less memory - - *outBuffer must be 0 before first call for each new archive. - - Extracting cache: - If you need to decompress more than one file, you can send - these values from previous call: - *blockIndex, - *outBuffer, - *outBufferSize - You can consider "*outBuffer" as cache of solid block. If your archive is solid, - it will increase decompression speed. - - If you use external function, you can declare these 3 cache variables - (blockIndex, outBuffer, outBufferSize) as static in that external function. - - Free *outBuffer and set *outBuffer to 0, if you want to flush cache. -*/ - -SZ_RESULT SzExtract( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - UInt32 fileIndex, /* index of file */ - UInt32 *blockIndex, /* index of solid block */ - Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ - size_t *outBufferSize, /* buffer size for output buffer */ - size_t *offset, /* offset of stream for required file in *outBuffer */ - size_t *outSizeProcessed, /* size of file in *outBuffer */ - ISzAlloc *allocMain, - ISzAlloc *allocTemp); - -#ifdef _LZMA_OUT_READ -SZ_RESULT SzExtract2( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - UInt32 fileIndex, /* index of file */ - UInt32 *blockIndex, /* index of solid block */ - Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ - size_t *outBufferSize, /* buffer size for output buffer */ - size_t *offset, /* offset of stream for required file in *outBuffer */ - size_t *outSizeProcessed, /* size of file in *outBuffer */ - ISzAlloc *allocMain, - ISzAlloc *allocTemp); -#endif - -#endif diff --git a/source/sz/7zHeader.c b/source/sz/7zHeader.c deleted file mode 100644 index e26c0143..00000000 --- a/source/sz/7zHeader.c +++ /dev/null @@ -1,5 +0,0 @@ -/* 7zHeader.c */ - -#include "7zHeader.h" - -Byte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; diff --git a/source/sz/7zHeader.h b/source/sz/7zHeader.h deleted file mode 100644 index 7edf640f..00000000 --- a/source/sz/7zHeader.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 7zHeader.h */ - -#ifndef __7Z_HEADER_H -#define __7Z_HEADER_H - -#include "7zTypes.h" - -#define k7zSignatureSize 6 -extern Byte k7zSignature[k7zSignatureSize]; - -#define k7zMajorVersion 0 - -#define k7zStartHeaderSize 0x20 - -enum EIdEnum -{ - k7zIdEnd, - - k7zIdHeader, - - k7zIdArchiveProperties, - - k7zIdAdditionalStreamsInfo, - k7zIdMainStreamsInfo, - k7zIdFilesInfo, - - k7zIdPackInfo, - k7zIdUnPackInfo, - k7zIdSubStreamsInfo, - - k7zIdSize, - k7zIdCRC, - - k7zIdFolder, - - k7zIdCodersUnPackSize, - k7zIdNumUnPackStream, - - k7zIdEmptyStream, - k7zIdEmptyFile, - k7zIdAnti, - - k7zIdName, - k7zIdCreationTime, - k7zIdLastAccessTime, - k7zIdLastWriteTime, - k7zIdWinAttributes, - k7zIdComment, - - k7zIdEncodedHeader, - - k7zIdStartPos -}; - -#endif diff --git a/source/sz/7zIn.c b/source/sz/7zIn.c deleted file mode 100644 index b3e9ea27..00000000 --- a/source/sz/7zIn.c +++ /dev/null @@ -1,1281 +0,0 @@ -/* 7zIn.c */ - -#include "7zIn.h" -#include "7zCrc.h" -#include "7zDecode.h" - -#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; } - -void SzArDbExInit(CArchiveDatabaseEx *db) -{ - SzArchiveDatabaseInit(&db->Database); - db->FolderStartPackStreamIndex = 0; - db->PackStreamStartPositions = 0; - db->FolderStartFileIndex = 0; - db->FileIndexToFolderIndexMap = 0; -} - -void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *)) -{ - freeFunc(db->FolderStartPackStreamIndex); - freeFunc(db->PackStreamStartPositions); - freeFunc(db->FolderStartFileIndex); - freeFunc(db->FileIndexToFolderIndexMap); - SzArchiveDatabaseFree(&db->Database, freeFunc); - SzArDbExInit(db); -} - -/* -CFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const -{ - return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex]; -} - -CFileSize GetFilePackSize(int fileIndex) const -{ - int folderIndex = FileIndexToFolderIndexMap[fileIndex]; - if (folderIndex >= 0) - { - const CFolder &folderInfo = Folders[folderIndex]; - if (FolderStartFileIndex[folderIndex] == fileIndex) - return GetFolderFullPackSize(folderIndex); - } - return 0; -} -*/ - -#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \ - if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; } - -SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size)) -{ - UInt32 startPos = 0; - CFileSize startPosSize = 0; - UInt32 i; - UInt32 folderIndex = 0; - UInt32 indexInFolder = 0; - MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc); - for(i = 0; i < db->Database.NumFolders; i++) - { - db->FolderStartPackStreamIndex[i] = startPos; - startPos += db->Database.Folders[i].NumPackStreams; - } - - MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc); - - for(i = 0; i < db->Database.NumPackStreams; i++) - { - db->PackStreamStartPositions[i] = startPosSize; - startPosSize += db->Database.PackSizes[i]; - } - - MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc); - MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc); - - for (i = 0; i < db->Database.NumFiles; i++) - { - CFileItem *file = db->Database.Files + i; - int emptyStream = !file->HasStream; - if (emptyStream && indexInFolder == 0) - { - db->FileIndexToFolderIndexMap[i] = (UInt32)-1; - continue; - } - if (indexInFolder == 0) - { - /* - v3.13 incorrectly worked with empty folders - v4.07: Loop for skipping empty folders - */ - while(1) - { - if (folderIndex >= db->Database.NumFolders) - return SZE_ARCHIVE_ERROR; - db->FolderStartFileIndex[folderIndex] = i; - if (db->Database.Folders[folderIndex].NumUnPackStreams != 0) - break; - folderIndex++; - } - } - db->FileIndexToFolderIndexMap[i] = folderIndex; - if (emptyStream) - continue; - indexInFolder++; - if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams) - { - folderIndex++; - indexInFolder = 0; - } - } - return SZ_OK; -} - - -CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder) -{ - return db->ArchiveInfo.DataStartPosition + - db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder]; -} - -CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex) -{ - UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex]; - CFolder *folder = db->Database.Folders + folderIndex; - CFileSize size = 0; - UInt32 i; - for (i = 0; i < folder->NumPackStreams; i++) - size += db->Database.PackSizes[packStreamIndex + i]; - return size; -} - - -/* -SZ_RESULT SzReadTime(const CObjectVector &dataVector, - CObjectVector &files, UInt64 type) -{ - CBoolVector boolVector; - RINOK(ReadBoolVector2(files.Size(), boolVector)) - - CStreamSwitch streamSwitch; - RINOK(streamSwitch.Set(this, &dataVector)); - - for(int i = 0; i < files.Size(); i++) - { - CFileItem &file = files[i]; - CArchiveFileTime fileTime; - bool defined = boolVector[i]; - if (defined) - { - UInt32 low, high; - RINOK(SzReadUInt32(low)); - RINOK(SzReadUInt32(high)); - fileTime.dwLowDateTime = low; - fileTime.dwHighDateTime = high; - } - switch(type) - { - case k7zIdCreationTime: - file.IsCreationTimeDefined = defined; - if (defined) - file.CreationTime = fileTime; - break; - case k7zIdLastWriteTime: - file.IsLastWriteTimeDefined = defined; - if (defined) - file.LastWriteTime = fileTime; - break; - case k7zIdLastAccessTime: - file.IsLastAccessTimeDefined = defined; - if (defined) - file.LastAccessTime = fileTime; - break; - } - } - return SZ_OK; -} -*/ - -SZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size) -{ - #ifdef _LZMA_IN_CB - while (size > 0) - { - Byte *inBuffer; - size_t processedSize; - RINOK(inStream->Read(inStream, (void **)&inBuffer, size, &processedSize)); - if (processedSize == 0 || processedSize > size) - return SZE_FAIL; - size -= processedSize; - do - { - *data++ = *inBuffer++; - } - while (--processedSize != 0); - } - #else - size_t processedSize; - RINOK(inStream->Read(inStream, data, size, &processedSize)); - if (processedSize != size) - return SZE_FAIL; - #endif - return SZ_OK; -} - -SZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data) -{ - return SafeReadDirect(inStream, data, 1); -} - -SZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value) -{ - int i; - *value = 0; - for (i = 0; i < 4; i++) - { - Byte b; - RINOK(SafeReadDirectByte(inStream, &b)); - *value |= ((UInt32)b << (8 * i)); - } - return SZ_OK; -} - -SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value) -{ - int i; - *value = 0; - for (i = 0; i < 8; i++) - { - Byte b; - RINOK(SafeReadDirectByte(inStream, &b)); - *value |= ((UInt32)b << (8 * i)); - } - return SZ_OK; -} - -int TestSignatureCandidate(Byte *testBytes) -{ - size_t i; - for (i = 0; i < k7zSignatureSize; i++) - if (testBytes[i] != k7zSignature[i]) - return 0; - return 1; -} - -typedef struct _CSzState -{ - Byte *Data; - size_t Size; -}CSzData; - -SZ_RESULT SzReadByte(CSzData *sd, Byte *b) -{ - if (sd->Size == 0) - return SZE_ARCHIVE_ERROR; - sd->Size--; - *b = *sd->Data++; - return SZ_OK; -} - -SZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size) -{ - size_t i; - for (i = 0; i < size; i++) - { - RINOK(SzReadByte(sd, data + i)); - } - return SZ_OK; -} - -SZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value) -{ - int i; - *value = 0; - for (i = 0; i < 4; i++) - { - Byte b; - RINOK(SzReadByte(sd, &b)); - *value |= ((UInt32)(b) << (8 * i)); - } - return SZ_OK; -} - -SZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value) -{ - Byte firstByte; - Byte mask = 0x80; - int i; - RINOK(SzReadByte(sd, &firstByte)); - *value = 0; - for (i = 0; i < 8; i++) - { - Byte b; - if ((firstByte & mask) == 0) - { - UInt64 highPart = firstByte & (mask - 1); - *value += (highPart << (8 * i)); - return SZ_OK; - } - RINOK(SzReadByte(sd, &b)); - *value |= ((UInt64)b << (8 * i)); - mask >>= 1; - } - return SZ_OK; -} - -SZ_RESULT SzReadSize(CSzData *sd, CFileSize *value) -{ - UInt64 value64; - RINOK(SzReadNumber(sd, &value64)); - *value = (CFileSize)value64; - return SZ_OK; -} - -SZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value) -{ - UInt64 value64; - RINOK(SzReadNumber(sd, &value64)); - if (value64 >= 0x80000000) - return SZE_NOTIMPL; - if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2))) - return SZE_NOTIMPL; - *value = (UInt32)value64; - return SZ_OK; -} - -SZ_RESULT SzReadID(CSzData *sd, UInt64 *value) -{ - return SzReadNumber(sd, value); -} - -SZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size) -{ - if (size > sd->Size) - return SZE_ARCHIVE_ERROR; - sd->Size -= (size_t)size; - sd->Data += (size_t)size; - return SZ_OK; -} - -SZ_RESULT SzSkeepData(CSzData *sd) -{ - UInt64 size; - RINOK(SzReadNumber(sd, &size)); - return SzSkeepDataSize(sd, size); -} - -SZ_RESULT SzReadArchiveProperties(CSzData *sd) -{ - while(1) - { - UInt64 type; - RINOK(SzReadID(sd, &type)); - if (type == k7zIdEnd) - break; - SzSkeepData(sd); - } - return SZ_OK; -} - -SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute) -{ - while(1) - { - UInt64 type; - RINOK(SzReadID(sd, &type)); - if (type == attribute) - return SZ_OK; - if (type == k7zIdEnd) - return SZE_ARCHIVE_ERROR; - RINOK(SzSkeepData(sd)); - } -} - -SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size)) -{ - Byte b = 0; - Byte mask = 0; - size_t i; - MY_ALLOC(Byte, *v, numItems, allocFunc); - for(i = 0; i < numItems; i++) - { - if (mask == 0) - { - RINOK(SzReadByte(sd, &b)); - mask = 0x80; - } - (*v)[i] = (Byte)(((b & mask) != 0) ? 1 : 0); - mask >>= 1; - } - return SZ_OK; -} - -SZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size)) -{ - Byte allAreDefined; - size_t i; - RINOK(SzReadByte(sd, &allAreDefined)); - if (allAreDefined == 0) - return SzReadBoolVector(sd, numItems, v, allocFunc); - MY_ALLOC(Byte, *v, numItems, allocFunc); - for(i = 0; i < numItems; i++) - (*v)[i] = 1; - return SZ_OK; -} - -SZ_RESULT SzReadHashDigests( - CSzData *sd, - size_t numItems, - Byte **digestsDefined, - UInt32 **digests, - void * (*allocFunc)(size_t size)) -{ - size_t i; - RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc)); - MY_ALLOC(UInt32, *digests, numItems, allocFunc); - for(i = 0; i < numItems; i++) - if ((*digestsDefined)[i]) - { - RINOK(SzReadUInt32(sd, (*digests) + i)); - } - return SZ_OK; -} - -SZ_RESULT SzReadPackInfo( - CSzData *sd, - CFileSize *dataOffset, - UInt32 *numPackStreams, - CFileSize **packSizes, - Byte **packCRCsDefined, - UInt32 **packCRCs, - void * (*allocFunc)(size_t size)) -{ - UInt32 i; - RINOK(SzReadSize(sd, dataOffset)); - RINOK(SzReadNumber32(sd, numPackStreams)); - - RINOK(SzWaitAttribute(sd, k7zIdSize)); - - MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc); - - for(i = 0; i < *numPackStreams; i++) - { - RINOK(SzReadSize(sd, (*packSizes) + i)); - } - - while(1) - { - UInt64 type; - RINOK(SzReadID(sd, &type)); - if (type == k7zIdEnd) - break; - if (type == k7zIdCRC) - { - RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc)); - continue; - } - RINOK(SzSkeepData(sd)); - } - if (*packCRCsDefined == 0) - { - MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc); - MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc); - for(i = 0; i < *numPackStreams; i++) - { - (*packCRCsDefined)[i] = 0; - (*packCRCs)[i] = 0; - } - } - return SZ_OK; -} - -SZ_RESULT SzReadSwitch(CSzData *sd) -{ - Byte external; - RINOK(SzReadByte(sd, &external)); - return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR; -} - -SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size)) -{ - UInt32 numCoders; - UInt32 numBindPairs; - UInt32 numPackedStreams; - UInt32 i; - UInt32 numInStreams = 0; - UInt32 numOutStreams = 0; - RINOK(SzReadNumber32(sd, &numCoders)); - folder->NumCoders = numCoders; - - MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc); - - for (i = 0; i < numCoders; i++) - SzCoderInfoInit(folder->Coders + i); - - for (i = 0; i < numCoders; i++) - { - Byte mainByte; - CCoderInfo *coder = folder->Coders + i; - { - RINOK(SzReadByte(sd, &mainByte)); - coder->MethodID.IDSize = (Byte)(mainByte & 0xF); - RINOK(SzReadBytes(sd, coder->MethodID.ID, coder->MethodID.IDSize)); - if ((mainByte & 0x10) != 0) - { - RINOK(SzReadNumber32(sd, &coder->NumInStreams)); - RINOK(SzReadNumber32(sd, &coder->NumOutStreams)); - } - else - { - coder->NumInStreams = 1; - coder->NumOutStreams = 1; - } - if ((mainByte & 0x20) != 0) - { - UInt64 propertiesSize = 0; - RINOK(SzReadNumber(sd, &propertiesSize)); - if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc)) - return SZE_OUTOFMEMORY; - RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize)); - } - } - while ((mainByte & 0x80) != 0) - { - RINOK(SzReadByte(sd, &mainByte)); - RINOK(SzSkeepDataSize(sd, (mainByte & 0xF))); - if ((mainByte & 0x10) != 0) - { - UInt32 n; - RINOK(SzReadNumber32(sd, &n)); - RINOK(SzReadNumber32(sd, &n)); - } - if ((mainByte & 0x20) != 0) - { - UInt64 propertiesSize = 0; - RINOK(SzReadNumber(sd, &propertiesSize)); - RINOK(SzSkeepDataSize(sd, propertiesSize)); - } - } - numInStreams += (UInt32)coder->NumInStreams; - numOutStreams += (UInt32)coder->NumOutStreams; - } - - numBindPairs = numOutStreams - 1; - folder->NumBindPairs = numBindPairs; - - - MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc); - - for (i = 0; i < numBindPairs; i++) - { - CBindPair *bindPair = folder->BindPairs + i;; - RINOK(SzReadNumber32(sd, &bindPair->InIndex)); - RINOK(SzReadNumber32(sd, &bindPair->OutIndex)); - } - - numPackedStreams = numInStreams - (UInt32)numBindPairs; - - folder->NumPackStreams = numPackedStreams; - MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc); - - if (numPackedStreams == 1) - { - UInt32 j; - UInt32 pi = 0; - for (j = 0; j < numInStreams; j++) - if (SzFolderFindBindPairForInStream(folder, j) < 0) - { - folder->PackStreams[pi++] = j; - break; - } - } - else - for(i = 0; i < numPackedStreams; i++) - { - RINOK(SzReadNumber32(sd, folder->PackStreams + i)); - } - return SZ_OK; -} - -SZ_RESULT SzReadUnPackInfo( - CSzData *sd, - UInt32 *numFolders, - CFolder **folders, /* for allocFunc */ - void * (*allocFunc)(size_t size), - ISzAlloc *allocTemp) -{ - UInt32 i; - RINOK(SzWaitAttribute(sd, k7zIdFolder)); - RINOK(SzReadNumber32(sd, numFolders)); - { - RINOK(SzReadSwitch(sd)); - - MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc); - - for(i = 0; i < *numFolders; i++) - SzFolderInit((*folders) + i); - - for(i = 0; i < *numFolders; i++) - { - RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc)); - } - } - - RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize)); - - for(i = 0; i < *numFolders; i++) - { - UInt32 j; - CFolder *folder = (*folders) + i; - UInt32 numOutStreams = SzFolderGetNumOutStreams(folder); - - MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc); - - for(j = 0; j < numOutStreams; j++) - { - RINOK(SzReadSize(sd, folder->UnPackSizes + j)); - } - } - - while(1) - { - UInt64 type; - RINOK(SzReadID(sd, &type)); - if (type == k7zIdEnd) - return SZ_OK; - if (type == k7zIdCRC) - { - SZ_RESULT res; - Byte *crcsDefined = 0; - UInt32 *crcs = 0; - res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc); - if (res == SZ_OK) - { - for(i = 0; i < *numFolders; i++) - { - CFolder *folder = (*folders) + i; - folder->UnPackCRCDefined = crcsDefined[i]; - folder->UnPackCRC = crcs[i]; - } - } - allocTemp->Free(crcs); - allocTemp->Free(crcsDefined); - RINOK(res); - continue; - } - RINOK(SzSkeepData(sd)); - } -} - -SZ_RESULT SzReadSubStreamsInfo( - CSzData *sd, - UInt32 numFolders, - CFolder *folders, - UInt32 *numUnPackStreams, - CFileSize **unPackSizes, - Byte **digestsDefined, - UInt32 **digests, - ISzAlloc *allocTemp) -{ - UInt64 type = 0; - UInt32 i; - UInt32 si = 0; - UInt32 numDigests = 0; - - for(i = 0; i < numFolders; i++) - folders[i].NumUnPackStreams = 1; - *numUnPackStreams = numFolders; - - while(1) - { - RINOK(SzReadID(sd, &type)); - if (type == k7zIdNumUnPackStream) - { - *numUnPackStreams = 0; - for(i = 0; i < numFolders; i++) - { - UInt32 numStreams; - RINOK(SzReadNumber32(sd, &numStreams)); - folders[i].NumUnPackStreams = numStreams; - *numUnPackStreams += numStreams; - } - continue; - } - if (type == k7zIdCRC || type == k7zIdSize) - break; - if (type == k7zIdEnd) - break; - RINOK(SzSkeepData(sd)); - } - - if (*numUnPackStreams == 0) - { - *unPackSizes = 0; - *digestsDefined = 0; - *digests = 0; - } - else - { - *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize)); - RINOM(*unPackSizes); - *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte)); - RINOM(*digestsDefined); - *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32)); - RINOM(*digests); - } - - for(i = 0; i < numFolders; i++) - { - /* - v3.13 incorrectly worked with empty folders - v4.07: we check that folder is empty - */ - CFileSize sum = 0; - UInt32 j; - UInt32 numSubstreams = folders[i].NumUnPackStreams; - if (numSubstreams == 0) - continue; - if (type == k7zIdSize) - for (j = 1; j < numSubstreams; j++) - { - CFileSize size; - RINOK(SzReadSize(sd, &size)); - (*unPackSizes)[si++] = size; - sum += size; - } - (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum; - } - if (type == k7zIdSize) - { - RINOK(SzReadID(sd, &type)); - } - - for(i = 0; i < *numUnPackStreams; i++) - { - (*digestsDefined)[i] = 0; - (*digests)[i] = 0; - } - - - for(i = 0; i < numFolders; i++) - { - UInt32 numSubstreams = folders[i].NumUnPackStreams; - if (numSubstreams != 1 || !folders[i].UnPackCRCDefined) - numDigests += numSubstreams; - } - - - si = 0; - while(1) - { - if (type == k7zIdCRC) - { - int digestIndex = 0; - Byte *digestsDefined2 = 0; - UInt32 *digests2 = 0; - SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc); - if (res == SZ_OK) - { - for (i = 0; i < numFolders; i++) - { - CFolder *folder = folders + i; - UInt32 numSubstreams = folder->NumUnPackStreams; - if (numSubstreams == 1 && folder->UnPackCRCDefined) - { - (*digestsDefined)[si] = 1; - (*digests)[si] = folder->UnPackCRC; - si++; - } - else - { - UInt32 j; - for (j = 0; j < numSubstreams; j++, digestIndex++) - { - (*digestsDefined)[si] = digestsDefined2[digestIndex]; - (*digests)[si] = digests2[digestIndex]; - si++; - } - } - } - } - allocTemp->Free(digestsDefined2); - allocTemp->Free(digests2); - RINOK(res); - } - else if (type == k7zIdEnd) - return SZ_OK; - else - { - RINOK(SzSkeepData(sd)); - } - RINOK(SzReadID(sd, &type)); - } -} - - -SZ_RESULT SzReadStreamsInfo( - CSzData *sd, - CFileSize *dataOffset, - CArchiveDatabase *db, - UInt32 *numUnPackStreams, - CFileSize **unPackSizes, /* allocTemp */ - Byte **digestsDefined, /* allocTemp */ - UInt32 **digests, /* allocTemp */ - void * (*allocFunc)(size_t size), - ISzAlloc *allocTemp) -{ - while(1) - { - UInt64 type; - RINOK(SzReadID(sd, &type)); - if ((UInt64)(int)type != type) - return SZE_FAIL; - switch((int)type) - { - case k7zIdEnd: - return SZ_OK; - case k7zIdPackInfo: - { - RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams, - &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc)); - break; - } - case k7zIdUnPackInfo: - { - RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp)); - break; - } - case k7zIdSubStreamsInfo: - { - RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders, - numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp)); - break; - } - default: - return SZE_FAIL; - } - } -} - -Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - -SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files, - void * (*allocFunc)(size_t size)) -{ - UInt32 i; - for(i = 0; i < numFiles; i++) - { - UInt32 len = 0; - UInt32 pos = 0; - CFileItem *file = files + i; - while(pos + 2 <= sd->Size) - { - int numAdds; - UInt32 value = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8)); - pos += 2; - len++; - if (value == 0) - break; - if (value < 0x80) - continue; - if (value >= 0xD800 && value < 0xE000) - { - UInt32 c2; - if (value >= 0xDC00) - return SZE_ARCHIVE_ERROR; - if (pos + 2 > sd->Size) - return SZE_ARCHIVE_ERROR; - c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8)); - pos += 2; - if (c2 < 0xDC00 || c2 >= 0xE000) - return SZE_ARCHIVE_ERROR; - value = ((value - 0xD800) << 10) | (c2 - 0xDC00); - } - for (numAdds = 1; numAdds < 5; numAdds++) - if (value < (((UInt32)1) << (numAdds * 5 + 6))) - break; - len += numAdds; - } - - MY_ALLOC(char, file->Name, (size_t)len, allocFunc); - - len = 0; - while(2 <= sd->Size) - { - int numAdds; - UInt32 value = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8)); - SzSkeepDataSize(sd, 2); - if (value < 0x80) - { - file->Name[len++] = (char)value; - if (value == 0) - break; - continue; - } - if (value >= 0xD800 && value < 0xE000) - { - UInt32 c2 = (UInt32)(sd->Data[0] | (((UInt32)sd->Data[1]) << 8)); - SzSkeepDataSize(sd, 2); - value = ((value - 0xD800) << 10) | (c2 - 0xDC00); - } - for (numAdds = 1; numAdds < 5; numAdds++) - if (value < (((UInt32)1) << (numAdds * 5 + 6))) - break; - file->Name[len++] = (char)(kUtf8Limits[numAdds - 1] + (value >> (6 * numAdds))); - do - { - numAdds--; - file->Name[len++] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F)); - } - while(numAdds > 0); - - len += numAdds; - } - } - return SZ_OK; -} - -SZ_RESULT SzReadHeader2( - CSzData *sd, - CArchiveDatabaseEx *db, /* allocMain */ - CFileSize **unPackSizes, /* allocTemp */ - Byte **digestsDefined, /* allocTemp */ - UInt32 **digests, /* allocTemp */ - Byte **emptyStreamVector, /* allocTemp */ - Byte **emptyFileVector, /* allocTemp */ - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - UInt64 type; - UInt32 numUnPackStreams = 0; - UInt32 numFiles = 0; - CFileItem *files = 0; - UInt32 numEmptyStreams = 0; - UInt32 i; - - RINOK(SzReadID(sd, &type)); - - if (type == k7zIdArchiveProperties) - { - RINOK(SzReadArchiveProperties(sd)); - RINOK(SzReadID(sd, &type)); - } - - - if (type == k7zIdMainStreamsInfo) - { - RINOK(SzReadStreamsInfo(sd, - &db->ArchiveInfo.DataStartPosition, - &db->Database, - &numUnPackStreams, - unPackSizes, - digestsDefined, - digests, allocMain->Alloc, allocTemp)); - db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader; - RINOK(SzReadID(sd, &type)); - } - - if (type == k7zIdEnd) - return SZ_OK; - if (type != k7zIdFilesInfo) - return SZE_ARCHIVE_ERROR; - - RINOK(SzReadNumber32(sd, &numFiles)); - db->Database.NumFiles = numFiles; - - MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc); - - db->Database.Files = files; - for(i = 0; i < numFiles; i++) - SzFileInit(files + i); - - while(1) - { - UInt64 type; - UInt64 size; - RINOK(SzReadID(sd, &type)); - if (type == k7zIdEnd) - break; - RINOK(SzReadNumber(sd, &size)); - - if ((UInt64)(int)type != type) - { - RINOK(SzSkeepDataSize(sd, size)); - } - else - switch((int)type) - { - case k7zIdName: - { - RINOK(SzReadSwitch(sd)); - RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc)) - break; - } - case k7zIdEmptyStream: - { - RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc)); - numEmptyStreams = 0; - for (i = 0; i < numFiles; i++) - if ((*emptyStreamVector)[i]) - numEmptyStreams++; - break; - } - case k7zIdEmptyFile: - { - RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc)); - break; - } - default: - { - RINOK(SzSkeepDataSize(sd, size)); - } - } - } - - { - UInt32 emptyFileIndex = 0; - UInt32 sizeIndex = 0; - for(i = 0; i < numFiles; i++) - { - CFileItem *file = files + i; - file->IsAnti = 0; - if (*emptyStreamVector == 0) - file->HasStream = 1; - else - file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1); - if(file->HasStream) - { - file->IsDirectory = 0; - file->Size = (*unPackSizes)[sizeIndex]; - file->FileCRC = (*digests)[sizeIndex]; - file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex]; - sizeIndex++; - } - else - { - if (*emptyFileVector == 0) - file->IsDirectory = 1; - else - file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1); - emptyFileIndex++; - file->Size = 0; - file->IsFileCRCDefined = 0; - } - } - } - return SzArDbExFill(db, allocMain->Alloc); -} - -SZ_RESULT SzReadHeader( - CSzData *sd, - CArchiveDatabaseEx *db, - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - CFileSize *unPackSizes = 0; - Byte *digestsDefined = 0; - UInt32 *digests = 0; - Byte *emptyStreamVector = 0; - Byte *emptyFileVector = 0; - SZ_RESULT res = SzReadHeader2(sd, db, - &unPackSizes, &digestsDefined, &digests, - &emptyStreamVector, &emptyFileVector, - allocMain, allocTemp); - allocTemp->Free(unPackSizes); - allocTemp->Free(digestsDefined); - allocTemp->Free(digests); - allocTemp->Free(emptyStreamVector); - allocTemp->Free(emptyFileVector); - return res; -} - -SZ_RESULT SzReadAndDecodePackedStreams2( - ISzInStream *inStream, - CSzData *sd, - CSzByteBuffer *outBuffer, - CFileSize baseOffset, - CArchiveDatabase *db, - CFileSize **unPackSizes, - Byte **digestsDefined, - UInt32 **digests, - #ifndef _LZMA_IN_CB - Byte **inBuffer, - #endif - ISzAlloc *allocTemp) -{ - - UInt32 numUnPackStreams = 0; - CFileSize dataStartPos; - CFolder *folder; - #ifndef _LZMA_IN_CB - CFileSize packSize = 0; - UInt32 i = 0; - #endif - CFileSize unPackSize; - size_t outRealSize; - SZ_RESULT res; - - RINOK(SzReadStreamsInfo(sd, &dataStartPos, db, - &numUnPackStreams, unPackSizes, digestsDefined, digests, - allocTemp->Alloc, allocTemp)); - - dataStartPos += baseOffset; - if (db->NumFolders != 1) - return SZE_ARCHIVE_ERROR; - - folder = db->Folders; - unPackSize = SzFolderGetUnPackSize(folder); - - RINOK(inStream->Seek(inStream, dataStartPos)); - - #ifndef _LZMA_IN_CB - for (i = 0; i < db->NumPackStreams; i++) - packSize += db->PackSizes[i]; - - MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc); - - RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize)); - #endif - - if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc)) - return SZE_OUTOFMEMORY; - - res = SzDecode(db->PackSizes, folder, - #ifdef _LZMA_IN_CB - inStream, - #else - *inBuffer, - #endif - outBuffer->Items, (size_t)unPackSize, - &outRealSize, allocTemp); - RINOK(res) - if (outRealSize != (UInt32)unPackSize) - return SZE_FAIL; - if (folder->UnPackCRCDefined) - if (!CrcVerifyDigest(folder->UnPackCRC, outBuffer->Items, (size_t)unPackSize)) - return SZE_FAIL; - return SZ_OK; -} - -SZ_RESULT SzReadAndDecodePackedStreams( - ISzInStream *inStream, - CSzData *sd, - CSzByteBuffer *outBuffer, - CFileSize baseOffset, - ISzAlloc *allocTemp) -{ - CArchiveDatabase db; - CFileSize *unPackSizes = 0; - Byte *digestsDefined = 0; - UInt32 *digests = 0; - #ifndef _LZMA_IN_CB - Byte *inBuffer = 0; - #endif - SZ_RESULT res; - SzArchiveDatabaseInit(&db); - res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset, - &db, &unPackSizes, &digestsDefined, &digests, - #ifndef _LZMA_IN_CB - &inBuffer, - #endif - allocTemp); - SzArchiveDatabaseFree(&db, allocTemp->Free); - allocTemp->Free(unPackSizes); - allocTemp->Free(digestsDefined); - allocTemp->Free(digests); - #ifndef _LZMA_IN_CB - allocTemp->Free(inBuffer); - #endif - return res; -} - -SZ_RESULT SzArchiveOpen2( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - Byte signature[k7zSignatureSize]; - Byte version; - UInt32 crcFromArchive; - UInt64 nextHeaderOffset; - UInt64 nextHeaderSize; - UInt32 nextHeaderCRC; - UInt32 crc; - CFileSize pos = 0; - CSzByteBuffer buffer; - CSzData sd; - SZ_RESULT res; - - RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize)); - - if (!TestSignatureCandidate(signature)) - return SZE_ARCHIVE_ERROR; - - /* - db.Clear(); - db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition; - */ - RINOK(SafeReadDirectByte(inStream, &version)); - if (version != k7zMajorVersion) - return SZE_ARCHIVE_ERROR; - RINOK(SafeReadDirectByte(inStream, &version)); - - RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive)); - - CrcInit(&crc); - RINOK(SafeReadDirectUInt64(inStream, &nextHeaderOffset)); - CrcUpdateUInt64(&crc, nextHeaderOffset); - RINOK(SafeReadDirectUInt64(inStream, &nextHeaderSize)); - CrcUpdateUInt64(&crc, nextHeaderSize); - RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC)); - CrcUpdateUInt32(&crc, nextHeaderCRC); - - pos = k7zStartHeaderSize; - db->ArchiveInfo.StartPositionAfterHeader = pos; - - if (CrcGetDigest(&crc) != crcFromArchive) - return SZE_ARCHIVE_ERROR; - - if (nextHeaderSize == 0) - return SZ_OK; - - RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset))); - - if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc)) - return SZE_OUTOFMEMORY; - - res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize); - if (res == SZ_OK) - { - if (CrcVerifyDigest(nextHeaderCRC, buffer.Items, (UInt32)nextHeaderSize)) - { - while (1) - { - UInt64 type; - sd.Data = buffer.Items; - sd.Size = buffer.Capacity; - res = SzReadID(&sd, &type); - if (res != SZ_OK) - break; - if (type == k7zIdHeader) - { - res = SzReadHeader(&sd, db, allocMain, allocTemp); - break; - } - if (type != k7zIdEncodedHeader) - { - res = SZE_ARCHIVE_ERROR; - break; - } - { - CSzByteBuffer outBuffer; - res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer, - db->ArchiveInfo.StartPositionAfterHeader, - allocTemp); - if (res != SZ_OK) - { - SzByteBufferFree(&outBuffer, allocTemp->Free); - break; - } - SzByteBufferFree(&buffer, allocTemp->Free); - buffer.Items = outBuffer.Items; - buffer.Capacity = outBuffer.Capacity; - } - } - } - } - SzByteBufferFree(&buffer, allocTemp->Free); - return res; -} - -SZ_RESULT SzArchiveOpen( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - ISzAlloc *allocMain, - ISzAlloc *allocTemp) -{ - SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp); - if (res != SZ_OK) - SzArDbExFree(db, allocMain->Free); - return res; -} diff --git a/source/sz/7zIn.h b/source/sz/7zIn.h deleted file mode 100644 index 8ded0ecc..00000000 --- a/source/sz/7zIn.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 7zIn.h */ - -#ifndef __7Z_IN_H -#define __7Z_IN_H - -#include "7zHeader.h" -#include "7zItem.h" -#include "7zAlloc.h" - -typedef struct _CInArchiveInfo -{ - CFileSize StartPositionAfterHeader; - CFileSize DataStartPosition; -}CInArchiveInfo; - -typedef struct _CArchiveDatabaseEx -{ - CArchiveDatabase Database; - CInArchiveInfo ArchiveInfo; - UInt32 *FolderStartPackStreamIndex; - CFileSize *PackStreamStartPositions; - UInt32 *FolderStartFileIndex; - UInt32 *FileIndexToFolderIndexMap; -}CArchiveDatabaseEx; - -void SzArDbExInit(CArchiveDatabaseEx *db); -void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *)); -CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder); -CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex); - -typedef struct _ISzInStream -{ - #ifdef _LZMA_IN_CB - SZ_RESULT (*Read)( - void *object, /* pointer to ISzInStream itself */ - void **buffer, /* out: pointer to buffer with data */ - size_t maxRequiredSize, /* max required size to read */ - size_t *processedSize); /* real processed size. - processedSize can be less than maxRequiredSize. - If processedSize == 0, then there are no more - bytes in stream. */ - #else - SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize); - #endif - SZ_RESULT (*Seek)(void *object, CFileSize pos); -} ISzInStream; - - -int SzArchiveOpen( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - ISzAlloc *allocMain, - ISzAlloc *allocTemp); - -#endif diff --git a/source/sz/7zItem.c b/source/sz/7zItem.c deleted file mode 100644 index 5f9a37f6..00000000 --- a/source/sz/7zItem.c +++ /dev/null @@ -1,133 +0,0 @@ -/* 7zItem.c */ - -#include "7zItem.h" -#include "7zAlloc.h" - -void SzCoderInfoInit(CCoderInfo *coder) -{ - SzByteBufferInit(&coder->Properties); -} - -void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p)) -{ - SzByteBufferFree(&coder->Properties, freeFunc); - SzCoderInfoInit(coder); -} - -void SzFolderInit(CFolder *folder) -{ - folder->NumCoders = 0; - folder->Coders = 0; - folder->NumBindPairs = 0; - folder->BindPairs = 0; - folder->NumPackStreams = 0; - folder->PackStreams = 0; - folder->UnPackSizes = 0; - folder->UnPackCRCDefined = 0; - folder->UnPackCRC = 0; - folder->NumUnPackStreams = 0; -} - -void SzFolderFree(CFolder *folder, void (*freeFunc)(void *p)) -{ - UInt32 i; - for (i = 0; i < folder->NumCoders; i++) - SzCoderInfoFree(&folder->Coders[i], freeFunc); - freeFunc(folder->Coders); - freeFunc(folder->BindPairs); - freeFunc(folder->PackStreams); - freeFunc(folder->UnPackSizes); - SzFolderInit(folder); -} - -UInt32 SzFolderGetNumOutStreams(CFolder *folder) -{ - UInt32 result = 0; - UInt32 i; - for (i = 0; i < folder->NumCoders; i++) - result += folder->Coders[i].NumOutStreams; - return result; -} - -int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex) -{ - UInt32 i; - for(i = 0; i < folder->NumBindPairs; i++) - if (folder->BindPairs[i].InIndex == inStreamIndex) - return i; - return -1; -} - - -int SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex) -{ - UInt32 i; - for(i = 0; i < folder->NumBindPairs; i++) - if (folder->BindPairs[i].OutIndex == outStreamIndex) - return i; - return -1; -} - -CFileSize SzFolderGetUnPackSize(CFolder *folder) -{ - int i = (int)SzFolderGetNumOutStreams(folder); - if (i == 0) - return 0; - for (i--; i >= 0; i--) - if (SzFolderFindBindPairForOutStream(folder, i) < 0) - return folder->UnPackSizes[i]; - /* throw 1; */ - return 0; -} - -/* -int FindPackStreamArrayIndex(int inStreamIndex) const -{ - for(int i = 0; i < PackStreams.Size(); i++) - if (PackStreams[i] == inStreamIndex) - return i; - return -1; -} -*/ - -void SzFileInit(CFileItem *fileItem) -{ - fileItem->IsFileCRCDefined = 0; - fileItem->HasStream = 1; - fileItem->IsDirectory = 0; - fileItem->IsAnti = 0; - fileItem->Name = 0; -} - -void SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p)) -{ - freeFunc(fileItem->Name); - SzFileInit(fileItem); -} - -void SzArchiveDatabaseInit(CArchiveDatabase *db) -{ - db->NumPackStreams = 0; - db->PackSizes = 0; - db->PackCRCsDefined = 0; - db->PackCRCs = 0; - db->NumFolders = 0; - db->Folders = 0; - db->NumFiles = 0; - db->Files = 0; -} - -void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *)) -{ - UInt32 i; - for (i = 0; i < db->NumFolders; i++) - SzFolderFree(&db->Folders[i], freeFunc); - for (i = 0; i < db->NumFiles; i++) - SzFileFree(&db->Files[i], freeFunc); - freeFunc(db->PackSizes); - freeFunc(db->PackCRCsDefined); - freeFunc(db->PackCRCs); - freeFunc(db->Folders); - freeFunc(db->Files); - SzArchiveDatabaseInit(db); -} diff --git a/source/sz/7zItem.h b/source/sz/7zItem.h deleted file mode 100644 index e59b73f0..00000000 --- a/source/sz/7zItem.h +++ /dev/null @@ -1,90 +0,0 @@ -/* 7zItem.h */ - -#ifndef __7Z_ITEM_H -#define __7Z_ITEM_H - -#include "7zMethodID.h" -#include "7zHeader.h" -#include "7zBuffer.h" - -typedef struct _CCoderInfo -{ - UInt32 NumInStreams; - UInt32 NumOutStreams; - CMethodID MethodID; - CSzByteBuffer Properties; -}CCoderInfo; - -void SzCoderInfoInit(CCoderInfo *coder); -void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p)); - -typedef struct _CBindPair -{ - UInt32 InIndex; - UInt32 OutIndex; -}CBindPair; - -typedef struct _CFolder -{ - UInt32 NumCoders; - CCoderInfo *Coders; - UInt32 NumBindPairs; - CBindPair *BindPairs; - UInt32 NumPackStreams; - UInt32 *PackStreams; - CFileSize *UnPackSizes; - int UnPackCRCDefined; - UInt32 UnPackCRC; - - UInt32 NumUnPackStreams; -}CFolder; - -void SzFolderInit(CFolder *folder); -CFileSize SzFolderGetUnPackSize(CFolder *folder); -int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex); -UInt32 SzFolderGetNumOutStreams(CFolder *folder); -CFileSize SzFolderGetUnPackSize(CFolder *folder); - -/* #define CArchiveFileTime UInt64 */ - -typedef struct _CFileItem -{ - /* - CArchiveFileTime LastWriteTime; - CFileSize StartPos; - UInt32 Attributes; - */ - CFileSize Size; - UInt32 FileCRC; - char *Name; - - Byte IsFileCRCDefined; - Byte HasStream; - Byte IsDirectory; - Byte IsAnti; - /* - int AreAttributesDefined; - int IsLastWriteTimeDefined; - int IsStartPosDefined; - */ -}CFileItem; - -void SzFileInit(CFileItem *fileItem); - -typedef struct _CArchiveDatabase -{ - UInt32 NumPackStreams; - CFileSize *PackSizes; - Byte *PackCRCsDefined; - UInt32 *PackCRCs; - UInt32 NumFolders; - CFolder *Folders; - UInt32 NumFiles; - CFileItem *Files; -}CArchiveDatabase; - -void SzArchiveDatabaseInit(CArchiveDatabase *db); -void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *)); - - -#endif diff --git a/source/sz/7zMethodID.c b/source/sz/7zMethodID.c deleted file mode 100644 index 9daf39c2..00000000 --- a/source/sz/7zMethodID.c +++ /dev/null @@ -1,14 +0,0 @@ -/* 7zMethodID.c */ - -#include "7zMethodID.h" - -int AreMethodsEqual(CMethodID *a1, CMethodID *a2) -{ - int i; - if (a1->IDSize != a2->IDSize) - return 0; - for (i = 0; i < a1->IDSize; i++) - if (a1->ID[i] != a2->ID[i]) - return 0; - return 1; -} diff --git a/source/sz/7zMethodID.h b/source/sz/7zMethodID.h deleted file mode 100644 index 4d886899..00000000 --- a/source/sz/7zMethodID.h +++ /dev/null @@ -1,18 +0,0 @@ -/* 7zMethodID.h */ - -#ifndef __7Z_METHOD_ID_H -#define __7Z_METHOD_ID_H - -#include "7zTypes.h" - -#define kMethodIDSize 15 - -typedef struct _CMethodID -{ - Byte ID[kMethodIDSize]; - Byte IDSize; -} CMethodID; - -int AreMethodsEqual(CMethodID *a1, CMethodID *a2); - -#endif diff --git a/source/sz/7zTypes.h b/source/sz/7zTypes.h deleted file mode 100644 index fa4c5c3c..00000000 --- a/source/sz/7zTypes.h +++ /dev/null @@ -1,71 +0,0 @@ -/* 7zTypes.h */ - -#ifndef __COMMON_TYPES_H -#define __COMMON_TYPES_H - -#ifndef _7ZIP_BYTE_DEFINED -#define _7ZIP_BYTE_DEFINED -#ifndef ZCONF_H -typedef unsigned char Byte; -#endif -#endif - -#ifndef _7ZIP_UINT16_DEFINED -#define _7ZIP_UINT16_DEFINED -typedef unsigned short UInt16; -#endif - -#ifndef _7ZIP_UINT32_DEFINED -#define _7ZIP_UINT32_DEFINED -#ifdef _LZMA_UINT32_IS_ULONG -typedef unsigned long UInt32; -#else -typedef unsigned int UInt32; -#endif -#endif - -/* #define _SZ_NO_INT_64 */ -/* define it your compiler doesn't support long long int */ - -#ifndef _7ZIP_UINT64_DEFINED -#define _7ZIP_UINT64_DEFINED -#ifdef _SZ_NO_INT_64 -typedef unsigned long UInt64; -#else -#ifdef _MSC_VER -typedef unsigned __int64 UInt64; -#else -typedef unsigned long long int UInt64; -#endif -#endif -#endif - - -/* #define _SZ_FILE_SIZE_64 */ -/* Use _SZ_FILE_SIZE_64 if you need support for files larger than 4 GB*/ - -#ifndef CFileSize -#ifdef _SZ_FILE_SIZE_64 -typedef UInt64 CFileSize; -#else -typedef UInt32 CFileSize; -#endif -#endif - -#define SZ_RESULT int - -#define SZ_OK (0) -#define SZE_DATA_ERROR (1) -#define SZE_OUTOFMEMORY (2) -#define SZE_CRC_ERROR (3) - -#define SZE_NOTIMPL (4) -#define SZE_FAIL (5) - -#define SZE_ARCHIVE_ERROR (6) - -#define SZE_OUTOFMEMORYDIC (7) - -#define RINOK(x) { int __result_ = (x); if(__result_ != 0) return __result_; } - -#endif diff --git a/source/sz/LzmaDecode.c b/source/sz/LzmaDecode.c deleted file mode 100644 index 71c62c47..00000000 --- a/source/sz/LzmaDecode.c +++ /dev/null @@ -1,584 +0,0 @@ -/* - LzmaDecode.c - LZMA Decoder (optimized for Speed version) - - LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this Code, expressly permits you to - statically or dynamically link your Code (or bind by name) to the - interfaces of this file without subjecting your linked Code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#include "LzmaDecode.h" - -#define kNumTopBits 24 -#define kTopValue ((UInt32)1 << kNumTopBits) - -#define kNumBitModelTotalBits 11 -#define kBitModelTotal (1 << kNumBitModelTotalBits) -#define kNumMoveBits 5 - -#define RC_READ_BYTE (*Buffer++) - -#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \ - { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }} - -#ifdef _LZMA_IN_CB - -#define RC_TEST { if (Buffer == BufferLim) \ - { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \ - BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }} - -#define RC_INIT Buffer = BufferLim = 0; RC_INIT2 - -#else - -#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; } - -#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2 - -#endif - -#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } - -#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) -#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; -#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; - -#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ - { UpdateBit0(p); mi <<= 1; A0; } else \ - { UpdateBit1(p); mi = (mi + mi) + 1; A1; } - -#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) - -#define RangeDecoderBitTreeDecode(probs, numLevels, res) \ - { int i = numLevels; res = 1; \ - do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ - res -= (1 << numLevels); } - - -#define kNumPosBitsMax 4 -#define kNumPosStatesMax (1 << kNumPosBitsMax) - -#define kLenNumLowBits 3 -#define kLenNumLowSymbols (1 << kLenNumLowBits) -#define kLenNumMidBits 3 -#define kLenNumMidSymbols (1 << kLenNumMidBits) -#define kLenNumHighBits 8 -#define kLenNumHighSymbols (1 << kLenNumHighBits) - -#define LenChoice 0 -#define LenChoice2 (LenChoice + 1) -#define LenLow (LenChoice2 + 1) -#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) -#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) -#define kNumLenProbs (LenHigh + kLenNumHighSymbols) - - -#define kNumStates 12 -#define kNumLitStates 7 - -#define kStartPosModelIndex 4 -#define kEndPosModelIndex 14 -#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) - -#define kNumPosSlotBits 6 -#define kNumLenToPosStates 4 - -#define kNumAlignBits 4 -#define kAlignTableSize (1 << kNumAlignBits) - -#define kMatchMinLen 2 - -#define IsMatch 0 -#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) -#define IsRepG0 (IsRep + kNumStates) -#define IsRepG1 (IsRepG0 + kNumStates) -#define IsRepG2 (IsRepG1 + kNumStates) -#define IsRep0Long (IsRepG2 + kNumStates) -#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) -#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) -#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) -#define LenCoder (Align + kAlignTableSize) -#define RepLenCoder (LenCoder + kNumLenProbs) -#define Literal (RepLenCoder + kNumLenProbs) - -#if Literal != LZMA_BASE_SIZE -StopCompilingDueBUG -#endif - -int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size) -{ - unsigned char prop0; - if (size < LZMA_PROPERTIES_SIZE) - return LZMA_RESULT_DATA_ERROR; - prop0 = propsData[0]; - if (prop0 >= (9 * 5 * 5)) - return LZMA_RESULT_DATA_ERROR; - { - for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5)); - for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9); - propsRes->lc = prop0; - /* - unsigned char remainder = (unsigned char)(prop0 / 9); - propsRes->lc = prop0 % 9; - propsRes->pb = remainder / 5; - propsRes->lp = remainder % 5; - */ - } - - #ifdef _LZMA_OUT_READ - { - int i; - propsRes->DictionarySize = 0; - for (i = 0; i < 4; i++) - propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8); - if (propsRes->DictionarySize == 0) - propsRes->DictionarySize = 1; - } - #endif - return LZMA_RESULT_OK; -} - -#define kLzmaStreamWasFinishedId (-1) - -int LzmaDecode(CLzmaDecoderState *vs, - #ifdef _LZMA_IN_CB - ILzmaInCallback *InCallback, - #else - const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, - #endif - unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed) -{ - CProb *p = vs->Probs; - SizeT nowPos = 0; - Byte previousByte = 0; - UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1; - UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1; - int lc = vs->Properties.lc; - - #ifdef _LZMA_OUT_READ - - UInt32 Range = vs->Range; - UInt32 Code = vs->Code; - #ifdef _LZMA_IN_CB - const Byte *Buffer = vs->Buffer; - const Byte *BufferLim = vs->BufferLim; - #else - const Byte *Buffer = inStream; - const Byte *BufferLim = inStream + inSize; - #endif - int state = vs->State; - UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; - int len = vs->RemainLen; - UInt32 globalPos = vs->GlobalPos; - UInt32 distanceLimit = vs->DistanceLimit; - - Byte *dictionary = vs->Dictionary; - UInt32 dictionarySize = vs->Properties.DictionarySize; - UInt32 dictionaryPos = vs->DictionaryPos; - - Byte tempDictionary[4]; - - #ifndef _LZMA_IN_CB - *inSizeProcessed = 0; - #endif - *outSizeProcessed = 0; - if (len == kLzmaStreamWasFinishedId) - return LZMA_RESULT_OK; - - if (dictionarySize == 0) - { - dictionary = tempDictionary; - dictionarySize = 1; - tempDictionary[0] = vs->TempDictionary[0]; - } - - if (len == kLzmaNeedInitId) - { - { - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); - UInt32 i; - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - rep0 = rep1 = rep2 = rep3 = 1; - state = 0; - globalPos = 0; - distanceLimit = 0; - dictionaryPos = 0; - dictionary[dictionarySize - 1] = 0; - #ifdef _LZMA_IN_CB - RC_INIT; - #else - RC_INIT(inStream, inSize); - #endif - } - len = 0; - } - while(len != 0 && nowPos < outSize) - { - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - len--; - } - if (dictionaryPos == 0) - previousByte = dictionary[dictionarySize - 1]; - else - previousByte = dictionary[dictionaryPos - 1]; - - #else /* if !_LZMA_OUT_READ */ - - int state = 0; - UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; - int len = 0; - const Byte *Buffer; - const Byte *BufferLim; - UInt32 Range; - UInt32 Code; - - #ifndef _LZMA_IN_CB - *inSizeProcessed = 0; - #endif - *outSizeProcessed = 0; - - { - UInt32 i; - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - } - - #ifdef _LZMA_IN_CB - RC_INIT; - #else - RC_INIT(inStream, inSize); - #endif - - #endif /* _LZMA_OUT_READ */ - - while(nowPos < outSize) - { - CProb *prob; - UInt32 bound; - int posState = (int)( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & posStateMask); - - prob = p + IsMatch + (state << kNumPosBitsMax) + posState; - IfBit0(prob) - { - int symbol = 1; - UpdateBit0(prob) - prob = p + Literal + (LZMA_LIT_SIZE * - ((( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & literalPosMask) << lc) + (previousByte >> (8 - lc)))); - - if (state >= kNumLitStates) - { - int matchByte; - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - matchByte = dictionary[pos]; - #else - matchByte = outStream[nowPos - rep0]; - #endif - do - { - int bit; - CProb *probLit; - matchByte <<= 1; - bit = (matchByte & 0x100); - probLit = prob + 0x100 + bit + symbol; - RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break) - } - while (symbol < 0x100); - } - while (symbol < 0x100) - { - CProb *probLit = prob + symbol; - RC_GET_BIT(probLit, symbol) - } - previousByte = (Byte)symbol; - - outStream[nowPos++] = previousByte; - #ifdef _LZMA_OUT_READ - if (distanceLimit < dictionarySize) - distanceLimit++; - - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #endif - if (state < 4) state = 0; - else if (state < 10) state -= 3; - else state -= 6; - } - else - { - UpdateBit1(prob); - prob = p + IsRep + state; - IfBit0(prob) - { - UpdateBit0(prob); - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - state = state < kNumLitStates ? 0 : 3; - prob = p + LenCoder; - } - else - { - UpdateBit1(prob); - prob = p + IsRepG0 + state; - IfBit0(prob) - { - UpdateBit0(prob); - prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState; - IfBit0(prob) - { - #ifdef _LZMA_OUT_READ - UInt32 pos; - #endif - UpdateBit0(prob); - - #ifdef _LZMA_OUT_READ - if (distanceLimit == 0) - #else - if (nowPos == 0) - #endif - return LZMA_RESULT_DATA_ERROR; - - state = state < kNumLitStates ? 9 : 11; - #ifdef _LZMA_OUT_READ - pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - outStream[nowPos++] = previousByte; - #ifdef _LZMA_OUT_READ - if (distanceLimit < dictionarySize) - distanceLimit++; - #endif - - continue; - } - else - { - UpdateBit1(prob); - } - } - else - { - UInt32 distance; - UpdateBit1(prob); - prob = p + IsRepG1 + state; - IfBit0(prob) - { - UpdateBit0(prob); - distance = rep1; - } - else - { - UpdateBit1(prob); - prob = p + IsRepG2 + state; - IfBit0(prob) - { - UpdateBit0(prob); - distance = rep2; - } - else - { - UpdateBit1(prob); - distance = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = distance; - } - state = state < kNumLitStates ? 8 : 11; - prob = p + RepLenCoder; - } - { - int numBits, offset; - CProb *probLen = prob + LenChoice; - IfBit0(probLen) - { - UpdateBit0(probLen); - probLen = prob + LenLow + (posState << kLenNumLowBits); - offset = 0; - numBits = kLenNumLowBits; - } - else - { - UpdateBit1(probLen); - probLen = prob + LenChoice2; - IfBit0(probLen) - { - UpdateBit0(probLen); - probLen = prob + LenMid + (posState << kLenNumMidBits); - offset = kLenNumLowSymbols; - numBits = kLenNumMidBits; - } - else - { - UpdateBit1(probLen); - probLen = prob + LenHigh; - offset = kLenNumLowSymbols + kLenNumMidSymbols; - numBits = kLenNumHighBits; - } - } - RangeDecoderBitTreeDecode(probLen, numBits, len); - len += offset; - } - - if (state < 4) - { - int posSlot; - state += kNumLitStates; - prob = p + PosSlot + - ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << - kNumPosSlotBits); - RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot); - if (posSlot >= kStartPosModelIndex) - { - int numDirectBits = ((posSlot >> 1) - 1); - rep0 = (2 | ((UInt32)posSlot & 1)); - if (posSlot < kEndPosModelIndex) - { - rep0 <<= numDirectBits; - prob = p + SpecPos + rep0 - posSlot - 1; - } - else - { - numDirectBits -= kNumAlignBits; - do - { - RC_NORMALIZE - Range >>= 1; - rep0 <<= 1; - if (Code >= Range) - { - Code -= Range; - rep0 |= 1; - } - } - while (--numDirectBits != 0); - prob = p + Align; - rep0 <<= kNumAlignBits; - numDirectBits = kNumAlignBits; - } - { - int i = 1; - int mi = 1; - do - { - CProb *prob3 = prob + mi; - RC_GET_BIT2(prob3, mi, ; , rep0 |= i); - i <<= 1; - } - while(--numDirectBits != 0); - } - } - else - rep0 = posSlot; - if (++rep0 == (UInt32)(0)) - { - /* it's for stream version */ - len = kLzmaStreamWasFinishedId; - break; - } - } - - len += kMatchMinLen; - #ifdef _LZMA_OUT_READ - if (rep0 > distanceLimit) - #else - if (rep0 > nowPos) - #endif - return LZMA_RESULT_DATA_ERROR; - - #ifdef _LZMA_OUT_READ - if (dictionarySize - distanceLimit > (UInt32)len) - distanceLimit += len; - else - distanceLimit = dictionarySize; - #endif - - do - { - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - len--; - outStream[nowPos++] = previousByte; - } - while(len != 0 && nowPos < outSize); - } - } - RC_NORMALIZE; - - #ifdef _LZMA_OUT_READ - vs->Range = Range; - vs->Code = Code; - vs->DictionaryPos = dictionaryPos; - vs->GlobalPos = globalPos + (UInt32)nowPos; - vs->DistanceLimit = distanceLimit; - vs->Reps[0] = rep0; - vs->Reps[1] = rep1; - vs->Reps[2] = rep2; - vs->Reps[3] = rep3; - vs->State = state; - vs->RemainLen = len; - vs->TempDictionary[0] = tempDictionary[0]; - #endif - - #ifdef _LZMA_IN_CB - vs->Buffer = Buffer; - vs->BufferLim = BufferLim; - #else - *inSizeProcessed = (SizeT)(Buffer - inStream); - #endif - *outSizeProcessed = nowPos; - return LZMA_RESULT_OK; -} diff --git a/source/sz/LzmaDecode.h b/source/sz/LzmaDecode.h deleted file mode 100644 index 8382fa85..00000000 --- a/source/sz/LzmaDecode.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - LzmaDecode.h - LZMA Decoder interface - - LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this code, expressly permits you to - statically or dynamically link your code (or bind by name) to the - interfaces of this file without subjecting your linked code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#ifndef __LZMADECODE_H -#define __LZMADECODE_H - -#include "LzmaTypes.h" - -/* #define _LZMA_IN_CB */ -/* Use callback for input data */ - -/* #define _LZMA_OUT_READ */ -/* Use read function for output data */ - -/* #define _LZMA_PROB32 */ -/* It can increase speed on some 32-bit CPUs, - but memory usage will be doubled in that case */ - -/* #define _LZMA_LOC_OPT */ -/* Enable local speed optimizations inside code */ - -#ifdef _LZMA_PROB32 -#define CProb UInt32 -#else -#define CProb UInt16 -#endif - -#define LZMA_RESULT_OK 0 -#define LZMA_RESULT_DATA_ERROR 1 - -#ifdef _LZMA_IN_CB -typedef struct _ILzmaInCallback -{ - int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize); -} ILzmaInCallback; -#endif - -#define LZMA_BASE_SIZE 1846 -#define LZMA_LIT_SIZE 768 - -#define LZMA_PROPERTIES_SIZE 5 - -typedef struct _CLzmaProperties -{ - int lc; - int lp; - int pb; - #ifdef _LZMA_OUT_READ - UInt32 DictionarySize; - #endif -}CLzmaProperties; - -int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size); - -#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp))) - -#define kLzmaNeedInitId (-2) - -typedef struct _CLzmaDecoderState -{ - CLzmaProperties Properties; - CProb *Probs; - - #ifdef _LZMA_IN_CB - const unsigned char *Buffer; - const unsigned char *BufferLim; - #endif - - #ifdef _LZMA_OUT_READ - unsigned char *Dictionary; - UInt32 Range; - UInt32 Code; - UInt32 DictionaryPos; - UInt32 GlobalPos; - UInt32 DistanceLimit; - UInt32 Reps[4]; - int State; - int RemainLen; - unsigned char TempDictionary[4]; - #endif -} CLzmaDecoderState; - -#ifdef _LZMA_OUT_READ -#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; } -#endif - -int LzmaDecode(CLzmaDecoderState *vs, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback, - #else - const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, - #endif - unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed); - -#endif diff --git a/source/sz/LzmaTypes.h b/source/sz/LzmaTypes.h deleted file mode 100644 index 4a1f7db4..00000000 --- a/source/sz/LzmaTypes.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -LzmaTypes.h - -Types for LZMA Decoder - -This file written and distributed to public domain by Igor Pavlov. -This file is part of LZMA SDK 4.40 (2006-05-01) -*/ - -#ifndef __LZMATYPES_H -#define __LZMATYPES_H - -#ifndef _7ZIP_BYTE_DEFINED -#define _7ZIP_BYTE_DEFINED -typedef unsigned char Byte; -#endif - -#ifndef _7ZIP_UINT16_DEFINED -#define _7ZIP_UINT16_DEFINED -typedef unsigned short UInt16; -#endif - -#ifndef _7ZIP_UINT32_DEFINED -#define _7ZIP_UINT32_DEFINED -#ifdef _LZMA_UINT32_IS_ULONG -typedef unsigned long UInt32; -#else -typedef unsigned int UInt32; -#endif -#endif - -/* #define _LZMA_SYSTEM_SIZE_T */ -/* Use system's size_t. You can use it to enable 64-bit sizes supporting */ - -#ifndef _7ZIP_SIZET_DEFINED -#define _7ZIP_SIZET_DEFINED -#ifdef _LZMA_SYSTEM_SIZE_T -#include -typedef size_t SizeT; -#else -typedef UInt32 SizeT; -#endif -#endif - -#endif