mirror of https://github.com/bsnes-emu/bsnes.git
Update to bsnes v046 release.
Unfortunately, I was not able to include any actual Super Game Boy support in this release. I was however able to back-port all other changes since v045, as well as add a lot of new stuff. Though there are few visible changes from the last release, internally much has changed. I'm releasing this mostly as a point release whilst everything should be stable. I've decided to support the Super Game Boy via external DLL (or SO for Linux users.) There are many reasons for this. Most notably is that the largest special chip in bsnes right now weighs in at ~30kb of code. Emulating an entire Game Boy, not including the SGB enhancements, would require an additional ~800kb of code, or nearly half the size of the entire SNES emulation core. Add to that potential issues with licensing, conflicts with the build process / namespace, a significant increase to build time, and a lack of flexibility over which Game Boy emulator to use, and it's pretty clear that this is something best left external. At least until we have a fully trimmed, fully working SGB emulator available. The way this will work is bsnes will look for SuperGameBoy.(dll,so), and if present, it will call out to pre-defined functions. Users will need the SGB BIOS loaded, at which point they can select a Game Boy cartridge, and bsnes will use the DLL for actual emulation. Sadly I don't have a working DLL ready for this release, and even if I did, there's no sound bridge yet for the Game Boy audio. Other than that, much of the core has been updated in an attempt to make the core more library-like. It still has a few major limitations: it requires libco (which is not portable) and nall (which is quite large), and only one instance can be instantiated as all of the base objects are pre-defined and inter-linked. Not that I can imagine any practical use for multiple simultaneous SNES emulators anyway ... Changelog: - Save RAM is now automatically saved once per minute - Added delay to Super Scope / Justifier latching to fix X-Zone - Fixed an edge case in CPU<>PPU counter history - S-CPU can now run up to one full scanline ahead of S-PPU before syncing - Added interface for Super Game Boy support (no emulation yet) - Fixed a bug with path selection not adding trailing slash - All S-SMP opcodes re-written to use new pre-processor - Entire core encapsulated into SNES namespace - Core accepts files via memory only; zlib and libjma moved outside of core - Major Makefile restructuring: it's now possible to build with just "make" alone - Linux: libxtst / inputproto is no longer required for compilation - Lots of additional code cleanup
This commit is contained in:
parent
3c42e6caa0
commit
2a6a66f478
253
src/Makefile
253
src/Makefile
|
@ -1,69 +1,40 @@
|
|||
include lib/nall/Makefile.string
|
||||
prefix = /usr/local
|
||||
include lib/nall/Makefile
|
||||
ui = ui_qt
|
||||
|
||||
################
|
||||
### compiler ###
|
||||
################
|
||||
|
||||
ifneq ($(findstring gcc,$(compiler)),) # GCC family
|
||||
flags = -O3 -fomit-frame-pointer -Ilib
|
||||
# note: libco *requires* -fomit-frame-pointer on i386 arch
|
||||
libcoflags := $(flags) -static
|
||||
c = $(compiler)
|
||||
cpp = $(subst cc,++,$(compiler))
|
||||
obj = o
|
||||
rule = -c $< -o $@
|
||||
link = -s
|
||||
mkbin = -o$1
|
||||
mkdef = -D$1
|
||||
mkincpath = -I$1
|
||||
mklib = -l$1
|
||||
mklibpath = -L$1
|
||||
c := $(compiler)
|
||||
cpp := $(subst cc,++,$(compiler))
|
||||
flags := -O3 -fomit-frame-pointer -Ilib
|
||||
link := -s
|
||||
|
||||
# profile-guided optimization:
|
||||
# flags += -fprofile-generate
|
||||
# link += -lgcov
|
||||
# flags += -fprofile-use
|
||||
else ifeq ($(compiler),cl) # Visual C++
|
||||
flags = /nologo /wd4355 /wd4805 /wd4996 /Ox /GL /EHsc /Ilib
|
||||
libcoflags = $(flags)
|
||||
c = cl
|
||||
cpp = cl
|
||||
obj = obj
|
||||
rule = /c $< /Fo$@
|
||||
link = /link
|
||||
mkbin = /Fe$1
|
||||
mkdef = /D$1
|
||||
mkincpath = /I$1
|
||||
mklib = $1.lib
|
||||
mklibpath = /L$1
|
||||
else
|
||||
unknown_compiler: help;
|
||||
endif
|
||||
# profile-guided instrumentation:
|
||||
# flags += -fprofile-generate
|
||||
# link += -lgcov
|
||||
|
||||
##########
|
||||
### os ###
|
||||
##########
|
||||
# profile-guided optimization:
|
||||
flags += -fprofile-use
|
||||
|
||||
ifeq ($(platform),x) # X11
|
||||
ruby = video.glx video.xv video.sdl audio.alsa audio.openal audio.oss audio.pulseaudio audio.ao input.sdl input.x
|
||||
delete = rm -f $1
|
||||
else ifeq ($(platform),win) # Windows
|
||||
mingw_link_flags = -mwindows
|
||||
# mingw_links_flags = -mconsole
|
||||
################
|
||||
### platform ###
|
||||
################
|
||||
|
||||
# enable static linking to Qt for Windows build
|
||||
mingw_link_flags += -enable-stdcall-fixup -Wl,-s -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
|
||||
ifeq ($(platform),x)
|
||||
ruby := video.glx video.xv video.sdl
|
||||
ruby += audio.alsa audio.openal audio.oss audio.pulseaudio audio.ao
|
||||
ruby += input.sdl input.x
|
||||
else ifeq ($(platform),win)
|
||||
ruby := video.direct3d video.wgl video.directdraw video.gdi
|
||||
ruby += audio.directsound
|
||||
ruby += input.rawinput input.directinput
|
||||
|
||||
ruby = video.direct3d video.wgl video.directdraw video.gdi audio.directsound input.rawinput input.directinput
|
||||
delete = $(if $(findstring i586-mingw-gcc,$(compiler)),rm -f $1,del $(subst /,\,$1))
|
||||
link += $(if $(findstring mingw,$(compiler)),$(mingw_link_flags))
|
||||
link += $(call mklib,uuid)
|
||||
link += $(call mklib,kernel32)
|
||||
link += $(call mklib,user32)
|
||||
link += $(call mklib,gdi32)
|
||||
link += $(call mklib,shell32)
|
||||
link += -mwindows
|
||||
# link += -mconsole
|
||||
link += -luuid -lkernel32 -luser32 -lgdi32 -lshell32
|
||||
# statically link Qt for Windows build
|
||||
link += -enable-stdcall-fixup -Wl,-s -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
|
||||
else
|
||||
unknown_platform: help;
|
||||
endif
|
||||
|
@ -72,46 +43,39 @@ endif
|
|||
### ruby ###
|
||||
############
|
||||
|
||||
rubyflags = $(if $(findstring .sdl,$(ruby)),`sdl-config --cflags`)
|
||||
link += $(if $(findstring .sdl,$(ruby)),`sdl-config --libs`)
|
||||
rubyflags = $(call ifhas,.sdl,$(ruby),`sdl-config --cflags`)
|
||||
|
||||
link += $(if $(findstring video.direct3d,$(ruby)),$(call mklib,d3d9))
|
||||
link += $(if $(findstring video.directdraw,$(ruby)),$(call mklib,ddraw))
|
||||
link += $(if $(findstring video.glx,$(ruby)),$(call mklib,GL))
|
||||
link += $(if $(findstring video.wgl,$(ruby)),$(call mklib,opengl32))
|
||||
link += $(if $(findstring video.xv,$(ruby)),$(call mklib,Xv))
|
||||
link += $(if $(findstring audio.alsa,$(ruby)),$(call mklib,asound))
|
||||
link += $(if $(findstring audio.ao,$(ruby)),$(call mklib,ao))
|
||||
link += $(if $(findstring audio.directsound,$(ruby)),$(call mklib,dsound))
|
||||
link += $(if $(findstring audio.openal,$(ruby)),$(if $(call streq,$(platform),x),$(call mklib,openal),$(call mklib,openal32)))
|
||||
link += $(if $(findstring audio.pulseaudio,$(ruby)),$(call mklib,pulse-simple))
|
||||
link += $(if $(findstring input.directinput,$(ruby)),$(call mklib,dinput8) $(call mklib,dxguid))
|
||||
link += $(if $(findstring input.rawinput,$(ruby)),$(call mklib,xinput) $(call mklib,dinput8) $(call mklib,dxguid))
|
||||
link += $(call ifhas,.sdl,$(ruby),`sdl-config --libs`)
|
||||
link += $(call ifhas,video.direct3d,$(ruby),-ld3d9)
|
||||
link += $(call ifhas,video.directdraw,$(ruby),-lddraw)
|
||||
link += $(call ifhas,video.glx,$(ruby),-lGL)
|
||||
link += $(call ifhas,video.wgl,$(ruby),-lopengl32)
|
||||
link += $(call ifhas,video.xv,$(ruby),-lXv)
|
||||
link += $(call ifhas,audio.alsa,$(ruby),-lasound)
|
||||
link += $(call ifhas,audio.ao,$(ruby),-lao)
|
||||
link += $(call ifhas,audio.directsound,$(ruby),-ldsound)
|
||||
link += $(call ifhas,audio.openal,$(ruby),$(if $(call streq,$(platform),x),-lopenal,-lopenal32))
|
||||
link += $(call ifhas,audio.pulseaudio,$(ruby),-lpulse-simple)
|
||||
link += $(call ifhas,input.directinput,$(ruby),-ldinput8 -ldxguid)
|
||||
link += $(call ifhas,input.rawinput,$(ruby),-lxinput -ldinput8 -ldxguid)
|
||||
|
||||
####################
|
||||
### core objects ###
|
||||
####################
|
||||
|
||||
objects = libco ruby libfilter string \
|
||||
reader cartridge cheat \
|
||||
memory smemory cpu cpucore scpu smp smpcore ssmp sdsp ppu bppu system \
|
||||
objects = libco ruby libreader libfilter string \
|
||||
system cartridge cheat \
|
||||
memory smemory cpu cpucore scpu smp smpcore ssmp sdsp ppu bppu \
|
||||
sgb sa1 bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010
|
||||
|
||||
ifeq ($(enable_gzip),true)
|
||||
objects += adler32 compress crc32 deflate gzio inffast inflate inftrees ioapi trees unzip zip zutil
|
||||
flags += $(call mkdef,GZIP_SUPPORT)
|
||||
flags += -DGZIP_SUPPORT
|
||||
endif
|
||||
|
||||
ifeq ($(enable_jma),true)
|
||||
objects += jma jcrc32 lzmadec 7zlzma iiostrm inbyte lzma winout
|
||||
flags += $(call mkdef,JMA_SUPPORT)
|
||||
endif
|
||||
|
||||
sgbflags =
|
||||
ifeq ($(sgb),gambatte)
|
||||
sgbflags += $(call mkdef,SGB_GAMBATTE)
|
||||
link += $(call mklibpath,lib/libgambatte)
|
||||
link += $(call mklib,gambatte)
|
||||
flags += -DJMA_SUPPORT
|
||||
endif
|
||||
|
||||
######################
|
||||
|
@ -121,139 +85,138 @@ endif
|
|||
compile = \
|
||||
$(strip \
|
||||
$(if $(filter %.c,$<), \
|
||||
$(c) $(flags) $1 $(rule), \
|
||||
$(c) $(flags) $1 -c $< -o $@, \
|
||||
$(if $(filter %.cpp,$<), \
|
||||
$(cpp) $(flags) $1 $(rule) \
|
||||
$(cpp) $(flags) $1 -c $< -o $@ \
|
||||
) \
|
||||
) \
|
||||
)
|
||||
|
||||
%.$(obj): $<; $(call compile)
|
||||
%.o: $<; $(call compile)
|
||||
|
||||
all: build;
|
||||
|
||||
include $(ui)/Makefile
|
||||
objects := $(patsubst %,obj/%.$(obj),$(objects))
|
||||
rubydef := $(foreach c,$(subst .,_,$(call strupper,$(ruby))),$(call mkdef,$c))
|
||||
objects := $(patsubst %,obj/%.o,$(objects))
|
||||
rubydef := $(foreach c,$(subst .,_,$(call strupper,$(ruby))),-D$c)
|
||||
|
||||
#################
|
||||
### libraries ###
|
||||
#################
|
||||
|
||||
obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/* lib/ruby/video/* lib/ruby/audio/* lib/ruby/input/*
|
||||
obj/ruby.o: lib/ruby/ruby.cpp $(call rwildcard,lib/ruby/*)
|
||||
$(call compile,$(rubydef) $(rubyflags))
|
||||
obj/libco.$(obj): lib/libco/libco.c lib/libco/*
|
||||
$(c) $(libcoflags) $(rule)
|
||||
obj/libfilter.$(obj): lib/libfilter/libfilter.cpp lib/libfilter/*
|
||||
obj/string.$(obj): lib/nall/string.cpp lib/nall/*
|
||||
obj/reader.$(obj): lib/reader/reader.cpp lib/reader/*
|
||||
obj/libco.o: lib/libco/libco.c lib/libco/*
|
||||
$(c) -O3 -fomit-frame-pointer -static -Ilib -c $< -o $@
|
||||
obj/libreader.o: lib/libreader/libreader.cpp lib/libreader/*
|
||||
obj/libfilter.o: lib/libfilter/libfilter.cpp lib/libfilter/*
|
||||
obj/string.o: lib/nall/string.cpp lib/nall/*
|
||||
|
||||
#################
|
||||
### utilities ###
|
||||
#################
|
||||
|
||||
obj/cartridge.$(obj): cartridge/cartridge.cpp cartridge/*
|
||||
obj/cheat.$(obj) : cheat/cheat.cpp cheat/*
|
||||
obj/cartridge.o: cartridge/cartridge.cpp cartridge/*
|
||||
obj/cheat.o : cheat/cheat.cpp cheat/*
|
||||
|
||||
##############
|
||||
### memory ###
|
||||
##############
|
||||
|
||||
obj/memory.$(obj) : memory/memory.cpp memory/*
|
||||
obj/smemory.$(obj): memory/smemory/smemory.cpp memory/smemory/* memory/smemory/mapper/*
|
||||
obj/memory.o : memory/memory.cpp memory/*
|
||||
obj/smemory.o: memory/smemory/smemory.cpp $(call rwildcard,memory/smemory/)
|
||||
|
||||
###########
|
||||
### cpu ###
|
||||
###########
|
||||
|
||||
obj/cpu.$(obj) : cpu/cpu.cpp cpu/*
|
||||
obj/cpucore.$(obj): cpu/core/core.cpp cpu/core/* cpu/core/disasm/*
|
||||
obj/scpu.$(obj) : cpu/scpu/scpu.cpp cpu/scpu/* cpu/scpu/dma/* cpu/scpu/memory/* cpu/scpu/mmio/* cpu/scpu/timing/*
|
||||
obj/cpu.o : cpu/cpu.cpp cpu/*
|
||||
obj/cpucore.o: cpu/core/core.cpp $(call rwildcard,cpu/core/)
|
||||
obj/scpu.o : cpu/scpu/scpu.cpp $(call rwildcard,cpu/scpu/)
|
||||
|
||||
###########
|
||||
### smp ###
|
||||
###########
|
||||
|
||||
obj/smp.$(obj) : smp/smp.cpp smp/*
|
||||
obj/smpcore.$(obj): smp/core/core.cpp smp/core/* smp/core/disasm/*
|
||||
obj/ssmp.$(obj) : smp/ssmp/ssmp.cpp smp/ssmp/* smp/ssmp/memory/* smp/ssmp/timing/*
|
||||
obj/smp.o : smp/smp.cpp smp/*
|
||||
obj/smpcore.o: smp/core/core.cpp $(call rwildcard,smp/core/)
|
||||
obj/ssmp.o : smp/ssmp/ssmp.cpp $(call rwildcard,smp/ssmp/)
|
||||
|
||||
###########
|
||||
### dsp ###
|
||||
###########
|
||||
|
||||
obj/adsp.$(obj): dsp/adsp/adsp.cpp dsp/adsp/*
|
||||
obj/sdsp.$(obj): dsp/sdsp/sdsp.cpp dsp/sdsp/*
|
||||
obj/adsp.o: dsp/adsp/adsp.cpp dsp/adsp/*
|
||||
obj/sdsp.o: dsp/sdsp/sdsp.cpp dsp/sdsp/*
|
||||
|
||||
###########
|
||||
### ppu ###
|
||||
###########
|
||||
|
||||
obj/ppu.$(obj) : ppu/ppu.cpp ppu/*
|
||||
obj/bppu.$(obj): ppu/bppu/bppu.cpp ppu/bppu/*
|
||||
obj/ppu.o : ppu/ppu.cpp ppu/*
|
||||
obj/bppu.o: ppu/bppu/bppu.cpp ppu/bppu/*
|
||||
|
||||
##############
|
||||
### system ###
|
||||
##############
|
||||
|
||||
obj/system.$(obj): system/system.cpp system/* system/scheduler/* system/video/* system/audio/* system/input/*
|
||||
obj/system.o: system/system.cpp $(call rwildcard,system/)
|
||||
|
||||
#####################
|
||||
### special chips ###
|
||||
#####################
|
||||
|
||||
obj/sgb.$(obj): chip/sgb/sgb.cpp chip/sgb/* chip/sgb/interface/*
|
||||
$(call compile,$(sgbflags))
|
||||
obj/sa1.$(obj) : chip/sa1/sa1.cpp chip/sa1/* chip/sa1/bus/* chip/sa1/dma/* chip/sa1/memory/* chip/sa1/mmio/*
|
||||
obj/bsx.$(obj) : chip/bsx/bsx.cpp chip/bsx/*
|
||||
obj/srtc.$(obj) : chip/srtc/srtc.cpp chip/srtc/*
|
||||
obj/sdd1.$(obj) : chip/sdd1/sdd1.cpp chip/sdd1/*
|
||||
obj/spc7110.$(obj): chip/spc7110/spc7110.cpp chip/spc7110/*
|
||||
obj/cx4.$(obj) : chip/cx4/cx4.cpp chip/cx4/*
|
||||
obj/dsp1.$(obj) : chip/dsp1/dsp1.cpp chip/dsp1/*
|
||||
obj/dsp2.$(obj) : chip/dsp2/dsp2.cpp chip/dsp2/*
|
||||
obj/dsp3.$(obj) : chip/dsp3/dsp3.cpp chip/dsp3/*
|
||||
obj/dsp4.$(obj) : chip/dsp4/dsp4.cpp chip/dsp4/*
|
||||
obj/obc1.$(obj) : chip/obc1/obc1.cpp chip/obc1/*
|
||||
obj/st010.$(obj) : chip/st010/st010.cpp chip/st010/*
|
||||
obj/sgb.o : chip/sgb/sgb.cpp $(call rwildcard,chip/sgb/)
|
||||
obj/sa1.o : chip/sa1/sa1.cpp $(call rwildcard,chip/sa1/)
|
||||
obj/bsx.o : chip/bsx/bsx.cpp chip/bsx/*
|
||||
obj/srtc.o : chip/srtc/srtc.cpp chip/srtc/*
|
||||
obj/sdd1.o : chip/sdd1/sdd1.cpp chip/sdd1/*
|
||||
obj/spc7110.o: chip/spc7110/spc7110.cpp chip/spc7110/*
|
||||
obj/cx4.o : chip/cx4/cx4.cpp chip/cx4/*
|
||||
obj/dsp1.o : chip/dsp1/dsp1.cpp chip/dsp1/*
|
||||
obj/dsp2.o : chip/dsp2/dsp2.cpp chip/dsp2/*
|
||||
obj/dsp3.o : chip/dsp3/dsp3.cpp chip/dsp3/*
|
||||
obj/dsp4.o : chip/dsp4/dsp4.cpp chip/dsp4/*
|
||||
obj/obc1.o : chip/obc1/obc1.cpp chip/obc1/*
|
||||
obj/st010.o : chip/st010/st010.cpp chip/st010/*
|
||||
|
||||
############
|
||||
### zlib ###
|
||||
############
|
||||
|
||||
obj/adler32.$(obj) : lib/zlib/adler32.c lib/zlib/*
|
||||
obj/compress.$(obj): lib/zlib/compress.c lib/zlib/*
|
||||
obj/crc32.$(obj) : lib/zlib/crc32.c lib/zlib/*
|
||||
obj/deflate.$(obj) : lib/zlib/deflate.c lib/zlib/*
|
||||
obj/gzio.$(obj) : lib/zlib/gzio.c lib/zlib/*
|
||||
obj/inffast.$(obj) : lib/zlib/inffast.c lib/zlib/*
|
||||
obj/inflate.$(obj) : lib/zlib/inflate.c lib/zlib/*
|
||||
obj/inftrees.$(obj): lib/zlib/inftrees.c lib/zlib/*
|
||||
obj/ioapi.$(obj) : lib/zlib/ioapi.c lib/zlib/*
|
||||
obj/trees.$(obj) : lib/zlib/trees.c lib/zlib/*
|
||||
obj/unzip.$(obj) : lib/zlib/unzip.c lib/zlib/*
|
||||
obj/zip.$(obj) : lib/zlib/zip.c lib/zlib/*
|
||||
obj/zutil.$(obj) : lib/zlib/zutil.c lib/zlib/*
|
||||
obj/adler32.o : lib/zlib/adler32.c lib/zlib/*
|
||||
obj/compress.o: lib/zlib/compress.c lib/zlib/*
|
||||
obj/crc32.o : lib/zlib/crc32.c lib/zlib/*
|
||||
obj/deflate.o : lib/zlib/deflate.c lib/zlib/*
|
||||
obj/gzio.o : lib/zlib/gzio.c lib/zlib/*
|
||||
obj/inffast.o : lib/zlib/inffast.c lib/zlib/*
|
||||
obj/inflate.o : lib/zlib/inflate.c lib/zlib/*
|
||||
obj/inftrees.o: lib/zlib/inftrees.c lib/zlib/*
|
||||
obj/ioapi.o : lib/zlib/ioapi.c lib/zlib/*
|
||||
obj/trees.o : lib/zlib/trees.c lib/zlib/*
|
||||
obj/unzip.o : lib/zlib/unzip.c lib/zlib/*
|
||||
obj/zip.o : lib/zlib/zip.c lib/zlib/*
|
||||
obj/zutil.o : lib/zlib/zutil.c lib/zlib/*
|
||||
|
||||
##############
|
||||
### libjma ###
|
||||
##############
|
||||
|
||||
obj/jma.$(obj) : lib/libjma/jma.cpp lib/libjma/*
|
||||
obj/jcrc32.$(obj) : lib/libjma/jcrc32.cpp lib/libjma/*
|
||||
obj/lzmadec.$(obj): lib/libjma/lzmadec.cpp lib/libjma/*
|
||||
obj/7zlzma.$(obj) : lib/libjma/7zlzma.cpp lib/libjma/*
|
||||
obj/iiostrm.$(obj): lib/libjma/iiostrm.cpp lib/libjma/*
|
||||
obj/inbyte.$(obj) : lib/libjma/inbyte.cpp lib/libjma/*
|
||||
obj/lzma.$(obj) : lib/libjma/lzma.cpp lib/libjma/*
|
||||
obj/winout.$(obj) : lib/libjma/winout.cpp lib/libjma/*
|
||||
obj/jma.o : lib/libjma/jma.cpp lib/libjma/*
|
||||
obj/jcrc32.o : lib/libjma/jcrc32.cpp lib/libjma/*
|
||||
obj/lzmadec.o: lib/libjma/lzmadec.cpp lib/libjma/*
|
||||
obj/7zlzma.o : lib/libjma/7zlzma.cpp lib/libjma/*
|
||||
obj/iiostrm.o: lib/libjma/iiostrm.cpp lib/libjma/*
|
||||
obj/inbyte.o : lib/libjma/inbyte.cpp lib/libjma/*
|
||||
obj/lzma.o : lib/libjma/lzma.cpp lib/libjma/*
|
||||
obj/winout.o : lib/libjma/winout.cpp lib/libjma/*
|
||||
|
||||
###############
|
||||
### targets ###
|
||||
###############
|
||||
|
||||
build: ui_build $(objects)
|
||||
$(strip $(cpp) $(call mkbin,../bsnes) $(objects) $(link))
|
||||
$(strip $(cpp) -o../bsnes $(objects) $(link))
|
||||
|
||||
install:
|
||||
install -D -m 755 ../bsnes $(DESTDIR)$(prefix)/bin/bsnes
|
||||
|
@ -261,7 +224,7 @@ install:
|
|||
install -D -m 644 data/bsnes.desktop $(DESTDIR)$(prefix)/share/applications/bsnes.desktop
|
||||
|
||||
clean: ui_clean
|
||||
-@$(call delete,obj/*.$(obj))
|
||||
-@$(call delete,obj/*.o)
|
||||
-@$(call delete,*.res)
|
||||
-@$(call delete,*.pgd)
|
||||
-@$(call delete,*.pgc)
|
||||
|
@ -280,7 +243,6 @@ help:
|
|||
@echo " gcc - GCC compiler"
|
||||
@echo " mingw32-gcc - MinGW compiler"
|
||||
@echo " i586-mingw32-gcc - MinGW cross compiler"
|
||||
@echo " cl - Visual C++"
|
||||
@echo ""
|
||||
@echo "Available options:"
|
||||
@echo " enable_gzip=[true|false] - Enable ZIP / GZ support (default=false)"
|
||||
|
@ -288,3 +250,4 @@ help:
|
|||
@echo ""
|
||||
@echo "Example: $(MAKE) platform=x compiler=gcc enable_gzip=true"
|
||||
@echo ""
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define BSNES_VERSION "0.045.09"
|
||||
#define BSNES_VERSION "0.046"
|
||||
#define BSNES_TITLE "bsnes v" BSNES_VERSION
|
||||
|
||||
#define BUSCORE sBus
|
||||
|
@ -20,8 +20,9 @@
|
|||
#include <nall/array.hpp>
|
||||
#include <nall/bit.hpp>
|
||||
#include <nall/detect.hpp>
|
||||
#include <nall/dl.hpp>
|
||||
#include <nall/endian.hpp>
|
||||
#include <nall/file.hpp>
|
||||
#include <nall/function.hpp>
|
||||
#include <nall/moduloarray.hpp>
|
||||
#include <nall/new.hpp>
|
||||
#include <nall/platform.hpp>
|
||||
|
@ -40,3 +41,4 @@ typedef uint16_t uint16;
|
|||
typedef uint32_t uint32;
|
||||
|
||||
#include "interface.hpp"
|
||||
|
||||
|
|
|
@ -1,82 +1,98 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define CART_CPP
|
||||
|
||||
#define CARTRIDGE_CPP
|
||||
namespace SNES {
|
||||
|
||||
#include "cartridge_header.cpp"
|
||||
#include "cartridge_loader.cpp"
|
||||
#include "header.cpp"
|
||||
|
||||
namespace memory {
|
||||
MappedRAM cartrom, cartram, cartrtc;
|
||||
MappedRAM bscram;
|
||||
MappedRAM bsxflash, bsxram, bsxpram;
|
||||
MappedRAM stArom, stAram;
|
||||
MappedRAM stBrom, stBram;
|
||||
MappedRAM dmgrom, dmgram, dmgrtc;
|
||||
MappedRAM stBrom, stBram;
|
||||
MappedRAM gbrom, gbram;
|
||||
};
|
||||
|
||||
Cartridge cartridge;
|
||||
|
||||
void Cartridge::load_begin(Mode cartridge_mode) {
|
||||
memory::cartrom.map(0, 0);
|
||||
memory::cartram.map(0, 0);
|
||||
memory::cartrtc.map(0, 0);
|
||||
memory::bscram.map (0, 0);
|
||||
memory::stArom.map (0, 0);
|
||||
memory::stAram.map (0, 0);
|
||||
memory::stBrom.map (0, 0);
|
||||
memory::stBram.map (0, 0);
|
||||
memory::dmgrom.map (0, 0);
|
||||
memory::dmgram.map (0, 0);
|
||||
memory::dmgrtc.map (0, 0);
|
||||
|
||||
set(loaded, false);
|
||||
set(bsx_flash_loaded, false);
|
||||
set(patched, false);
|
||||
set(mode, cartridge_mode);
|
||||
}
|
||||
|
||||
void Cartridge::load_end() {
|
||||
|
||||
void Cartridge::load(Mode cartridge_mode) {
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, memory::cartrom.data(), memory::cartrom.size());
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
set(mode, cartridge_mode);
|
||||
|
||||
if(cartinfo.ram_size > 0) {
|
||||
memory::cartram.map(new(zeromemory) uint8_t[cartinfo.ram_size], cartinfo.ram_size);
|
||||
}
|
||||
|
||||
if(cartinfo.srtc || cartinfo.spc7110rtc) {
|
||||
memory::cartrtc.map(new(zeromemory) uint8_t[20], 20);
|
||||
}
|
||||
|
||||
if(mode() == ModeBsx) {
|
||||
memory::bsxram.map (new(zeromemory) uint8_t[ 32 * 1024], 32 * 1024);
|
||||
memory::bsxpram.map(new(zeromemory) uint8_t[512 * 1024], 512 * 1024);
|
||||
}
|
||||
|
||||
if(mode() == ModeSufamiTurbo) {
|
||||
if(memory::stArom.data()) memory::stAram.map(new(zeromemory) uint8_t[128 * 1024], 128 * 1024);
|
||||
if(memory::stBrom.data()) memory::stBram.map(new(zeromemory) uint8_t[128 * 1024], 128 * 1024);
|
||||
}
|
||||
|
||||
if(mode() == ModeSuperGameBoy) {
|
||||
if(memory::gbrom.data()) memory::gbram.map(new(zeromemory) uint8_t[64 * 1024], 64 * 1024);
|
||||
}
|
||||
|
||||
memory::cartrom.write_protect(true);
|
||||
memory::cartram.write_protect(false);
|
||||
memory::cartram.write_protect(false);
|
||||
memory::cartrtc.write_protect(false);
|
||||
memory::bscram.write_protect (true);
|
||||
memory::stArom.write_protect (true);
|
||||
memory::stAram.write_protect (false);
|
||||
memory::stBrom.write_protect (true);
|
||||
memory::stBram.write_protect (false);
|
||||
memory::dmgrom.write_protect (true);
|
||||
memory::dmgram.write_protect (false);
|
||||
memory::dmgrtc.write_protect (false);
|
||||
|
||||
bus.load_cart();
|
||||
set(loaded, true);
|
||||
memory::bsxflash.write_protect(true);
|
||||
memory::bsxram.write_protect(false);
|
||||
memory::bsxpram.write_protect(false);
|
||||
memory::stArom.write_protect(true);
|
||||
memory::stAram.write_protect(false);
|
||||
memory::stBrom.write_protect(true);
|
||||
memory::stBram.write_protect(false);
|
||||
memory::gbrom.write_protect(true);
|
||||
memory::gbram.write_protect(false);
|
||||
|
||||
bus.load_cart();
|
||||
set(loaded, true);
|
||||
}
|
||||
|
||||
void Cartridge::unload() {
|
||||
void Cartridge::unload() {
|
||||
memory::cartrom.reset();
|
||||
memory::cartram.reset();
|
||||
memory::cartrtc.reset();
|
||||
memory::bsxflash.reset();
|
||||
memory::bsxram.reset();
|
||||
memory::bsxpram.reset();
|
||||
memory::stArom.reset();
|
||||
memory::stAram.reset();
|
||||
memory::stBrom.reset();
|
||||
memory::stBram.reset();
|
||||
memory::gbrom.reset();
|
||||
memory::gbram.reset();
|
||||
|
||||
if(loaded() == false) return;
|
||||
bus.unload_cart();
|
||||
|
||||
memory::cartrom.reset();
|
||||
memory::cartram.reset();
|
||||
memory::cartrtc.reset();
|
||||
memory::bscram.reset();
|
||||
memory::stArom.reset();
|
||||
memory::stAram.reset();
|
||||
memory::stBrom.reset();
|
||||
memory::stBram.reset();
|
||||
memory::dmgrom.reset();
|
||||
memory::dmgram.reset();
|
||||
memory::dmgrtc.reset();
|
||||
|
||||
set(loaded, false);
|
||||
}
|
||||
|
||||
Cartridge::Type Cartridge::detect_image_type(uint8_t *data, unsigned size) const {
|
||||
cartinfo_t info;
|
||||
read_header(info, data, size);
|
||||
return info.type;
|
||||
}
|
||||
|
||||
Cartridge::Cartridge() {
|
||||
set(loaded, false);
|
||||
set(loaded, false);
|
||||
unload();
|
||||
}
|
||||
|
||||
Cartridge::~Cartridge() {
|
||||
if(loaded() == true) unload();
|
||||
unload();
|
||||
}
|
||||
|
||||
void Cartridge::set_cartinfo(const Cartridge::cartinfo_t &source) {
|
||||
|
@ -137,4 +153,5 @@ Cartridge::cartinfo_t::cartinfo_t() {
|
|||
reset();
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ public:
|
|||
ModeNormal,
|
||||
ModeBsxSlotted,
|
||||
ModeBsx,
|
||||
ModeSufamiTurbo,
|
||||
ModeSuperGameboy,
|
||||
ModeSufamiTurbo,
|
||||
ModeSuperGameBoy,
|
||||
};
|
||||
|
||||
enum Type {
|
||||
|
@ -14,9 +14,9 @@ public:
|
|||
TypeBsxBios,
|
||||
TypeBsx,
|
||||
TypeSufamiTurboBios,
|
||||
TypeSufamiTurbo,
|
||||
TypeSuperGameboyBios,
|
||||
TypeGameboy,
|
||||
TypeSufamiTurbo,
|
||||
TypeSuperGameBoyBios,
|
||||
TypeGameBoy,
|
||||
TypeUnknown,
|
||||
};
|
||||
|
||||
|
@ -48,9 +48,7 @@ public:
|
|||
//properties can be read via operator(), eg "if(cartridge.loaded() == true)";
|
||||
//warning: if loaded() == false, no other property is considered valid!
|
||||
|
||||
property_t<bool> loaded; //is a base cartridge inserted?
|
||||
property_t<bool> bsx_flash_loaded; //is a BS-X flash cart connected?
|
||||
property_t<bool> patched; //has a UPS patch been applied?
|
||||
property_t<bool> loaded; //is a base cartridge inserted?
|
||||
|
||||
property_t<Mode> mode;
|
||||
property_t<Region> region;
|
||||
|
@ -68,22 +66,17 @@ public:
|
|||
property_t<bool> has_obc1;
|
||||
property_t<bool> has_st010, has_st011, has_st018;
|
||||
|
||||
//main interface
|
||||
Type detect_image_type (uint8_t*, unsigned) const;
|
||||
bool load_normal (uint8_t*, unsigned);
|
||||
bool load_bsx_slotted (uint8_t*, unsigned, uint8_t*, unsigned);
|
||||
bool load_bsx (uint8_t*, unsigned, uint8_t*, unsigned);
|
||||
bool load_sufami_turbo (uint8_t*, unsigned, uint8_t*, unsigned, uint8_t*, unsigned);
|
||||
bool load_super_gameboy(uint8_t*, unsigned, uint8_t*, unsigned);
|
||||
//main interface
|
||||
void load(Mode);
|
||||
//void read();
|
||||
//void load();
|
||||
void unload();
|
||||
Type detect_image_type(uint8_t *data, unsigned size) const;
|
||||
|
||||
Cartridge();
|
||||
~Cartridge();
|
||||
|
||||
private:
|
||||
void load_begin(Mode);
|
||||
void load_end();
|
||||
|
||||
struct cartinfo_t {
|
||||
Type type;
|
||||
Region region;
|
||||
|
@ -128,10 +121,10 @@ private:
|
|||
|
||||
namespace memory {
|
||||
extern MappedRAM cartrom, cartram, cartrtc;
|
||||
extern MappedRAM bscram;
|
||||
extern MappedRAM bsxflash, bsxram, bsxpram;
|
||||
extern MappedRAM stArom, stAram;
|
||||
extern MappedRAM stBrom, stBram;
|
||||
extern MappedRAM dmgrom, dmgram, dmgrtc;
|
||||
extern MappedRAM stBrom, stBram;
|
||||
extern MappedRAM gbrom, gbram;
|
||||
};
|
||||
|
||||
extern Cartridge cartridge;
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
#ifdef CART_CPP
|
||||
|
||||
Cartridge::Type Cartridge::detect_image_type(uint8_t *data, unsigned size) const {
|
||||
cartinfo_t info;
|
||||
read_header(info, data, size);
|
||||
return info.type;
|
||||
}
|
||||
|
||||
//================
|
||||
//Normal cartridge
|
||||
//================
|
||||
|
||||
bool Cartridge::load_normal(uint8_t *basedata, unsigned basesize) {
|
||||
load_begin(ModeNormal);
|
||||
|
||||
memory::cartrom.map(new uint8_t[basesize], basesize);
|
||||
memcpy(memory::cartrom.handle(), basedata, basesize);
|
||||
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, basedata, basesize);
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
if(cartinfo.ram_size) {
|
||||
memory::cartram.map(new(zeromemory) uint8_t[cartinfo.ram_size], cartinfo.ram_size);
|
||||
}
|
||||
|
||||
if(cartinfo.srtc || cartinfo.spc7110rtc) {
|
||||
memory::cartrtc.map(new(zeromemory) uint8_t[20], 20);
|
||||
}
|
||||
|
||||
load_end();
|
||||
return true;
|
||||
}
|
||||
|
||||
//======================
|
||||
//BS-X slotted cartridge
|
||||
//======================
|
||||
|
||||
bool Cartridge::load_bsx_slotted(uint8_t *basedata, unsigned basesize, uint8_t *slotdata, unsigned slotsize) {
|
||||
load_begin(ModeBsxSlotted);
|
||||
|
||||
memory::cartrom.map(new uint8_t[basesize], basesize);
|
||||
memcpy(memory::cartrom.handle(), basedata, basesize);
|
||||
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, basedata, basesize);
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
if(slotdata) {
|
||||
memory::bscram.map(new uint8_t[slotsize], slotsize);
|
||||
memcpy(memory::bscram.handle(), slotdata, slotsize);
|
||||
set(bsx_flash_loaded, true);
|
||||
}
|
||||
|
||||
if(cartinfo.ram_size) {
|
||||
memory::cartram.map(new(zeromemory) uint8_t[cartinfo.ram_size], cartinfo.ram_size);
|
||||
}
|
||||
|
||||
load_end();
|
||||
return true;
|
||||
}
|
||||
|
||||
//====================
|
||||
//BS-X flash cartridge
|
||||
//====================
|
||||
|
||||
bool Cartridge::load_bsx(uint8_t *basedata, unsigned basesize, uint8_t *slotdata, unsigned slotsize) {
|
||||
load_begin(ModeBsx);
|
||||
|
||||
memory::cartrom.map(new uint8_t[basesize], basesize);
|
||||
memcpy(memory::cartrom.handle(), basedata, basesize);
|
||||
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, basedata, basesize);
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
if(slotdata) {
|
||||
memory::bscram.map(new uint8_t[slotsize], slotsize);
|
||||
memcpy(memory::bscram.handle(), slotdata, slotsize);
|
||||
set(bsx_flash_loaded, true);
|
||||
}
|
||||
|
||||
memset(bsxcart.sram.handle (), 0x00, bsxcart.sram.size ());
|
||||
memset(bsxcart.psram.handle(), 0x00, bsxcart.psram.size());
|
||||
|
||||
load_end();
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================
|
||||
//Sufami Turbo flash cartridge
|
||||
//============================
|
||||
|
||||
bool Cartridge::load_sufami_turbo(uint8_t *basedata, unsigned basesize, uint8_t *slotAdata, unsigned slotAsize, uint8_t *slotBdata, unsigned slotBsize) {
|
||||
load_begin(ModeSufamiTurbo);
|
||||
|
||||
memory::cartrom.map(new uint8_t[basesize], basesize);
|
||||
memcpy(memory::cartrom.handle(), basedata, basesize);
|
||||
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, basedata, basesize);
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
if(slotAdata) {
|
||||
memory::stArom.map(new uint8_t[slotAsize], slotAsize);
|
||||
memory::stAram.map(new uint8_t[0x020000], 0x020000);
|
||||
memcpy(memory::stArom.handle(), slotAdata, slotAsize);
|
||||
}
|
||||
|
||||
if(slotBdata) {
|
||||
memory::stBrom.map(new uint8_t[slotBsize], slotBsize);
|
||||
memory::stBram.map(new uint8_t[0x020000], 0x020000);
|
||||
memcpy(memory::stBrom.handle(), slotBdata, slotBsize);
|
||||
}
|
||||
|
||||
load_end();
|
||||
return true;
|
||||
}
|
||||
|
||||
//=======================
|
||||
//Super Gameboy cartridge
|
||||
//=======================
|
||||
|
||||
bool Cartridge::load_super_gameboy(uint8_t *basedata, unsigned basesize, uint8_t *slotdata, unsigned slotsize) {
|
||||
load_begin(ModeSuperGameboy);
|
||||
|
||||
memory::cartrom.map(new uint8_t[basesize], basesize);
|
||||
memcpy(memory::cartrom.handle(), basedata, basesize);
|
||||
|
||||
cartinfo_t cartinfo;
|
||||
read_header(cartinfo, basedata, basesize);
|
||||
set_cartinfo(cartinfo);
|
||||
|
||||
if(slotdata) {
|
||||
uint8_t *data = new uint8_t[slotsize];
|
||||
memcpy(data, slotdata, slotsize);
|
||||
memory::dmgrom.map(data, slotsize);
|
||||
|
||||
//TODO: determine proper RAM size via GB ROM header
|
||||
memory::dmgram.map(new uint8_t[524288], 524288);
|
||||
memory::dmgrtc.map(new uint8_t[4], 4);
|
||||
}
|
||||
|
||||
load_end();
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,18 +1,17 @@
|
|||
#ifdef CART_CPP
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size) const {
|
||||
info.reset();
|
||||
|
||||
//====================
|
||||
//detect Gameboy carts
|
||||
//====================
|
||||
//=====================
|
||||
//detect Game Boy carts
|
||||
//=====================
|
||||
|
||||
if(size >= 0x0150) {
|
||||
if(data[0x0104] == 0xce && data[0x0105] == 0xed && data[0x0106] == 0x66 && data[0x0107] == 0x66) {
|
||||
if(data[0x0108] == 0xcc && data[0x0109] == 0x0d && data[0x010a] == 0x00 && data[0x010b] == 0x0b) {
|
||||
info.type = TypeGameboy;
|
||||
return;
|
||||
}
|
||||
if(size >= 0x0140) {
|
||||
if(data[0x0104] == 0xce && data[0x0105] == 0xed && data[0x0106] == 0x66 && data[0x0107] == 0x66
|
||||
&& data[0x0108] == 0xcc && data[0x0109] == 0x0d && data[0x010a] == 0x00 && data[0x010b] == 0x0b) {
|
||||
info.type = TypeGameBoy;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +22,12 @@ void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size
|
|||
const uint8 company = data[index + Company];
|
||||
const uint8 region = data[index + CartRegion] & 0x7f;
|
||||
|
||||
if(data[index + RamSize] & 7) {
|
||||
info.ram_size = 1024 << (data[index + RamSize] & 7);
|
||||
} else {
|
||||
info.ram_size = 0;
|
||||
}
|
||||
|
||||
//0, 1, 13 = NTSC; 2 - 12 = PAL
|
||||
info.region = (region <= 1 || region >= 13) ? NTSC : PAL;
|
||||
|
||||
|
@ -37,6 +42,7 @@ void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size
|
|||
if(data[index + 0x1a] == 0x33 || data[index + 0x1a] == 0xff) {
|
||||
info.type = TypeBsx;
|
||||
info.mapper = BSXROM;
|
||||
info.region = NTSC; //BS-X only released in Japan
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -54,16 +60,16 @@ void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size
|
|||
info.type = TypeSufamiTurbo;
|
||||
}
|
||||
info.mapper = STROM;
|
||||
return;
|
||||
info.region = NTSC; //Sufami Turbo only released in Japan
|
||||
return; //RAM size handled internally by load_cart_st();
|
||||
}
|
||||
|
||||
//=========================
|
||||
//detect Super Gameboy cart
|
||||
//=========================
|
||||
//==========================
|
||||
//detect Super Game Boy BIOS
|
||||
//==========================
|
||||
|
||||
if(!memcmp(data + index, "Super GAMEBOY", 13)) {
|
||||
info.type = TypeSuperGameboyBios;
|
||||
info.mapper = LoROM;
|
||||
info.type = TypeSuperGameBoyBios;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -187,12 +193,6 @@ void Cartridge::read_header(cartinfo_t &info, const uint8_t *data, unsigned size
|
|||
if(mapper == 0x30 && rom_type == 0xf5) {
|
||||
info.st018 = true;
|
||||
}
|
||||
|
||||
if(data[index + RamSize] & 7) {
|
||||
info.ram_size = 1024 << (data[index + RamSize] & 7);
|
||||
} else {
|
||||
info.ram_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Cartridge::find_header(const uint8_t *data, unsigned size) const {
|
|
@ -1,3 +1,3 @@
|
|||
@mingw32-make platform=win compiler=mingw32-gcc sgb=gambatte
|
||||
::@mingw32-make platform=win compiler=mingw32-gcc enable_gzip=true enable_jma=true
|
||||
@mingw32-make
|
||||
::@mingw32-make enable_gzip=true enable_jma=true
|
||||
@pause
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
make platform=x compiler=gcc sgb=gambatte
|
||||
#make platform=x compiler=gcc enable_gzip=true enable_jma=true
|
|
@ -1,6 +1,6 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define CHEAT_CPP
|
||||
#include <../base.hpp>
|
||||
|
||||
#define CHEAT_CPP
|
||||
namespace SNES {
|
||||
|
||||
Cheat cheat;
|
||||
|
@ -181,9 +181,7 @@ void Cheat::disable(unsigned i) {
|
|||
//...
|
||||
//===============================
|
||||
|
||||
bool Cheat::load(const char *fn) {
|
||||
string data;
|
||||
if(!data.readfile(fn)) return false;
|
||||
void Cheat::load(string data) {
|
||||
data.replace("\r\n", "\n");
|
||||
data.qreplace(" ", "");
|
||||
|
||||
|
@ -196,21 +194,16 @@ bool Cheat::load(const char *fn) {
|
|||
trim(part[0], "\"");
|
||||
add(part[1] == "enabled", /* code = */ part[2], /* desc = */ part[0]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Cheat::save(const char *fn) const {
|
||||
file fp;
|
||||
if(!fp.open(fn, file::mode_write)) return false;
|
||||
for(unsigned i = 0; i < code.size(); i++) {
|
||||
fp.print(string()
|
||||
<< "\"" << code[i].desc << "\", "
|
||||
<< (code[i].enabled ? "enabled, " : "disabled, ")
|
||||
<< code[i].code << "\r\n");
|
||||
}
|
||||
fp.close();
|
||||
return true;
|
||||
string Cheat::save() const {
|
||||
string data;
|
||||
for(unsigned i = 0; i < code.size(); i++) {
|
||||
data << "\"" << code[i].desc << "\", "
|
||||
<< (code[i].enabled ? "enabled, " : "disabled, ")
|
||||
<< code[i].code << "\r\n";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void Cheat::clear() {
|
||||
|
@ -393,5 +386,6 @@ string& Cheat::decode_description(string &desc) const {
|
|||
desc.replace("\\n", "\n");
|
||||
return desc;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ public:
|
|||
void enable(unsigned i);
|
||||
void disable(unsigned i);
|
||||
|
||||
bool load(const char *fn);
|
||||
bool save(const char *fn) const;
|
||||
void load(string data);
|
||||
string save() const;
|
||||
void clear();
|
||||
|
||||
Cheat();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define BSX_CPP
|
||||
|
||||
#define BSX_CPP
|
||||
namespace SNES {
|
||||
|
||||
#include "bsx_base.cpp"
|
||||
#include "bsx_cart.cpp"
|
||||
#include "bsx_flash.cpp"
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -32,16 +32,10 @@ public:
|
|||
uint8 mmio_read(unsigned addr);
|
||||
void mmio_write(unsigned addr, uint8 data);
|
||||
|
||||
MappedRAM sram;
|
||||
MappedRAM psram;
|
||||
|
||||
BSXCart();
|
||||
~BSXCart();
|
||||
|
||||
private:
|
||||
uint8 *sram_data; //256kbit SRAM
|
||||
uint8 *psram_data; // 4mbit PSRAM
|
||||
|
||||
struct {
|
||||
uint8 r[16];
|
||||
} regs;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifdef BSX_CPP
|
||||
|
||||
BSXBase bsxbase;
|
||||
|
||||
void BSXBase::init() {
|
||||
}
|
||||
|
||||
|
@ -135,3 +137,4 @@ void BSXBase::mmio_write(unsigned addr, uint8 data) {
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifdef BSX_CPP
|
||||
|
||||
BSXCart bsxcart;
|
||||
|
||||
void BSXCart::init() {
|
||||
}
|
||||
|
||||
|
@ -20,7 +22,7 @@ void BSXCart::reset() {
|
|||
}
|
||||
|
||||
void BSXCart::update_memory_map() {
|
||||
Memory &cart = (regs.r[0x01] & 0x80) == 0x00 ? (Memory&)bsxflash : (Memory&)psram;
|
||||
Memory &cart = (regs.r[0x01] & 0x80) == 0x00 ? (Memory&)bsxflash : (Memory&)memory::bsxpram;
|
||||
|
||||
if((regs.r[0x02] & 0x80) == 0x00) {
|
||||
//LoROM mapping
|
||||
|
@ -35,16 +37,16 @@ void BSXCart::update_memory_map() {
|
|||
}
|
||||
|
||||
if(regs.r[0x03] & 0x80) {
|
||||
bus.map(Bus::MapLinear, 0x60, 0x6f, 0x0000, 0xffff, psram);
|
||||
//bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, psram);
|
||||
bus.map(Bus::MapLinear, 0x60, 0x6f, 0x0000, 0xffff, memory::bsxpram);
|
||||
//bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, memory::bsxpram);
|
||||
}
|
||||
|
||||
if((regs.r[0x05] & 0x80) == 0x00) {
|
||||
bus.map(Bus::MapLinear, 0x40, 0x4f, 0x0000, 0xffff, psram);
|
||||
bus.map(Bus::MapLinear, 0x40, 0x4f, 0x0000, 0xffff, memory::bsxpram);
|
||||
}
|
||||
|
||||
if((regs.r[0x06] & 0x80) == 0x00) {
|
||||
bus.map(Bus::MapLinear, 0x50, 0x5f, 0x0000, 0xffff, psram);
|
||||
bus.map(Bus::MapLinear, 0x50, 0x5f, 0x0000, 0xffff, memory::bsxpram);
|
||||
}
|
||||
|
||||
if(regs.r[0x07] & 0x80) {
|
||||
|
@ -55,8 +57,8 @@ void BSXCart::update_memory_map() {
|
|||
bus.map(Bus::MapLinear, 0x80, 0x9f, 0x8000, 0xffff, memory::cartrom);
|
||||
}
|
||||
|
||||
bus.map(Bus::MapShadow, 0x20, 0x3f, 0x6000, 0x7fff, psram);
|
||||
bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, psram);
|
||||
bus.map(Bus::MapShadow, 0x20, 0x3f, 0x6000, 0x7fff, memory::bsxpram);
|
||||
bus.map(Bus::MapLinear, 0x70, 0x77, 0x0000, 0xffff, memory::bsxpram);
|
||||
}
|
||||
|
||||
uint8 BSXCart::mmio_read(unsigned addr) {
|
||||
|
@ -66,7 +68,7 @@ uint8 BSXCart::mmio_read(unsigned addr) {
|
|||
}
|
||||
|
||||
if((addr & 0xf8f000) == 0x105000) { //$[10-17]:[5000-5fff] SRAM
|
||||
return sram.read(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff));
|
||||
return memory::bsxram.read(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff));
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
|
@ -81,21 +83,15 @@ void BSXCart::mmio_write(unsigned addr, uint8 data) {
|
|||
}
|
||||
|
||||
if((addr & 0xf8f000) == 0x105000) { //$[10-17]:[5000-5fff] SRAM
|
||||
return sram.write(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff), data);
|
||||
return memory::bsxram.write(((addr >> 16) & 7) * 0x1000 + (addr & 0xfff), data);
|
||||
}
|
||||
}
|
||||
|
||||
BSXCart::BSXCart() {
|
||||
sram_data = new uint8_t[ 32 * 1024];
|
||||
psram_data = new uint8_t[512 * 1024];
|
||||
|
||||
sram.map (sram_data, 32 * 1024);
|
||||
psram.map(psram_data, 512 * 1024);
|
||||
}
|
||||
|
||||
BSXCart::~BSXCart() {
|
||||
delete[] sram_data;
|
||||
delete[] psram_data;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifdef BSX_CPP
|
||||
|
||||
BSXFlash bsxflash;
|
||||
|
||||
void BSXFlash::init() {}
|
||||
void BSXFlash::enable() {}
|
||||
|
||||
|
@ -15,10 +17,11 @@ void BSXFlash::reset() {
|
|||
regs.flash_enable = false;
|
||||
regs.read_enable = false;
|
||||
regs.write_enable = false;
|
||||
memory::bsxflash.write_protect(!regs.write_enable);
|
||||
}
|
||||
|
||||
unsigned BSXFlash::size() const {
|
||||
return memory::bscram.size();
|
||||
return memory::bsxflash.size();
|
||||
}
|
||||
|
||||
uint8 BSXFlash::read(unsigned addr) {
|
||||
|
@ -45,7 +48,7 @@ uint8 BSXFlash::read(unsigned addr) {
|
|||
}
|
||||
}
|
||||
|
||||
return memory::bscram.read(addr);
|
||||
return memory::bsxflash.read(addr);
|
||||
}
|
||||
|
||||
void BSXFlash::write(unsigned addr, uint8 data) {
|
||||
|
@ -64,11 +67,11 @@ void BSXFlash::write(unsigned addr, uint8 data) {
|
|||
regs.write_new = data;
|
||||
|
||||
if(regs.write_enable && regs.write_old == regs.write_new) {
|
||||
return memory::bscram.write(addr, data);
|
||||
return memory::bsxflash.write(addr, data);
|
||||
}
|
||||
} else {
|
||||
if(regs.write_enable) {
|
||||
return memory::bscram.write(addr, data);
|
||||
return memory::bsxflash.write(addr, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +110,10 @@ void BSXFlash::write(unsigned addr, uint8 data) {
|
|||
regs.read_enable = false;
|
||||
regs.write_enable = false;
|
||||
}
|
||||
|
||||
memory::bsxflash.write_protect(!regs.write_enable);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
struct Chip {
|
||||
virtual void load() {}
|
||||
virtual void unload() {}
|
||||
};
|
||||
|
||||
#include "sgb/sgb.hpp"
|
||||
#include "sgb/sgb.hpp"
|
||||
#include "sa1/sa1.hpp"
|
||||
#include "bsx/bsx.hpp"
|
||||
#include "srtc/srtc.hpp"
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
*/
|
||||
|
||||
#include <../base.hpp>
|
||||
|
||||
#define CX4_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define CX4_CPP
|
||||
namespace SNES {
|
||||
|
||||
Cx4 cx4;
|
||||
|
||||
#include "cx4data.cpp"
|
||||
#include "cx4fn.cpp"
|
||||
|
@ -196,5 +198,5 @@ void Cx4::reset() {
|
|||
memset(ram, 0, 0x0c00);
|
||||
memset(reg, 0, 0x0100);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define DSP1_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define DSP1_CPP
|
||||
namespace SNES {
|
||||
|
||||
DSP1 dsp1;
|
||||
|
||||
#include "dsp1emu.cpp"
|
||||
|
||||
|
@ -57,5 +59,5 @@ void DSP1::write(unsigned addr, uint8 data) {
|
|||
dsp1.setDr(data);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define DSP2_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define DSP2_CPP
|
||||
namespace SNES {
|
||||
|
||||
DSP2 dsp2;
|
||||
|
||||
#include "dsp2_op.cpp"
|
||||
|
||||
|
@ -135,5 +137,5 @@ void DSP2::write(unsigned addr, uint8 data) {
|
|||
|
||||
DSP2::DSP2() {}
|
||||
DSP2::~DSP2() {}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define DSP3_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define DSP3_CPP
|
||||
namespace SNES {
|
||||
|
||||
DSP3 dsp3;
|
||||
|
||||
namespace DSP3i {
|
||||
#define bool8 uint8
|
||||
|
@ -34,5 +36,5 @@ void DSP3::write(unsigned addr, uint8 data) {
|
|||
DSP3i::dsp3_byte = data;
|
||||
DSP3i::DSP3SetByte();
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define DSP4_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define DSP4_CPP
|
||||
namespace SNES {
|
||||
|
||||
DSP4 dsp4;
|
||||
|
||||
namespace DSP4i {
|
||||
inline uint16 READ_WORD(uint8 *addr) {
|
||||
|
@ -54,5 +56,5 @@ void DSP4::write(unsigned addr, uint8 data) {
|
|||
DSP4i::DSP4SetByte();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define OBC1_CPP
|
||||
namespace SNES {
|
||||
#define OBC1_CPP
|
||||
namespace SNES {
|
||||
|
||||
OBC1 obc1;
|
||||
|
||||
void OBC1::init() {}
|
||||
void OBC1::enable() {}
|
||||
|
@ -70,6 +72,7 @@ void OBC1::ram_write(unsigned addr, uint8 data) {
|
|||
}
|
||||
|
||||
OBC1::OBC1() {}
|
||||
OBC1::~OBC1() {}
|
||||
OBC1::~OBC1() {}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifdef SA1_CPP
|
||||
|
||||
SA1Bus sa1bus;
|
||||
|
||||
namespace memory {
|
||||
VectorSelectionPage vectorsp;
|
||||
StaticRAM iram(2048);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//BS-X flash carts, when present, are mapped to 0x400000+
|
||||
Memory& SA1::mmio_access(unsigned &addr) {
|
||||
if(cartridge.bsx_flash_loaded() == false) return memory::cartrom;
|
||||
if(!memory::bsxflash.data()) return memory::cartrom;
|
||||
if(addr < 0x400000) return memory::cartrom;
|
||||
addr &= 0x3fffff;
|
||||
return bsxflash;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#define SA1_CPP
|
||||
namespace SNES {
|
||||
|
||||
SA1 sa1;
|
||||
|
||||
#include "bus/bus.cpp"
|
||||
#include "dma/dma.cpp"
|
||||
#include "memory/memory.cpp"
|
||||
|
@ -313,3 +315,4 @@ SA1::SA1() {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define SDD1_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define SDD1_CPP
|
||||
namespace SNES {
|
||||
|
||||
SDD1 sdd1;
|
||||
|
||||
#include "sdd1emu.cpp"
|
||||
|
||||
|
@ -156,5 +158,5 @@ SDD1::SDD1() {
|
|||
SDD1::~SDD1() {
|
||||
delete[] buffer.data;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,174 +0,0 @@
|
|||
#include <libgambatte/include/gambatte.h>
|
||||
|
||||
namespace SNES {
|
||||
|
||||
class GambatteVideo : public Gambatte::VideoBlitter {
|
||||
public:
|
||||
unsigned bufferWidth, bufferHeight;
|
||||
uint32_t *buffer;
|
||||
|
||||
void setBufferDimensions(unsigned width, unsigned height) {
|
||||
if(buffer) delete[] buffer;
|
||||
buffer = new uint32_t[width * height];
|
||||
bufferWidth = width;
|
||||
bufferHeight = height;
|
||||
}
|
||||
|
||||
const Gambatte::PixelBuffer inBuffer() {
|
||||
Gambatte::PixelBuffer pb;
|
||||
pb.pixels = (void*)buffer;
|
||||
pb.format = Gambatte::PixelBuffer::RGB32;
|
||||
pb.pitch = bufferWidth;
|
||||
return pb;
|
||||
}
|
||||
|
||||
void blit() {
|
||||
}
|
||||
|
||||
void update(unsigned row) {
|
||||
uint32_t *source = buffer + row * 160 * 8;
|
||||
uint8_t *buffer = new(zeromemory) uint8_t[5760];
|
||||
|
||||
for(unsigned y = row * 8; y < row * 8 + 8; y++) {
|
||||
for(unsigned x = 0; x < 160; x++) {
|
||||
unsigned pixel = *source++ / 0x555555;
|
||||
pixel ^= 3;
|
||||
|
||||
unsigned tile = ((y / 8) * 20) + (x / 8);
|
||||
unsigned addr = (tile * 16) + ((y & 7) * 2);
|
||||
|
||||
buffer[addr + 0] |= ((pixel & 1) >> 0) << (7 - (x & 7));
|
||||
buffer[addr + 1] |= ((pixel & 2) >> 1) << (7 - (x & 7));
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(sgb.gameboy->vram, buffer, 5760);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
~GambatteVideo() {
|
||||
if(buffer) delete[] buffer;
|
||||
}
|
||||
};
|
||||
|
||||
class GambatteInput : public Gambatte::InputStateGetter {
|
||||
public:
|
||||
Gambatte::InputState is;
|
||||
const Gambatte::InputState& operator()() {
|
||||
unsigned joypad = sgb.gameboy->joypadid();
|
||||
unsigned data = sgb.mmio.joypad[joypad];
|
||||
|
||||
//TODO: fix SGB detection
|
||||
joypad = 1;
|
||||
data = sgb.mmio.joypad[0];
|
||||
|
||||
is.joypadId = 0x0f - joypad;
|
||||
is.startButton = !(data & 0x80);
|
||||
is.selectButton = !(data & 0x40);
|
||||
is.bButton = !(data & 0x20);
|
||||
is.aButton = !(data & 0x10);
|
||||
is.dpadDown = !(data & 0x08);
|
||||
is.dpadUp = !(data & 0x04);
|
||||
is.dpadLeft = !(data & 0x02);
|
||||
is.dpadRight = !(data & 0x01);
|
||||
return is;
|
||||
}
|
||||
};
|
||||
|
||||
class GambatteMemory : public Gambatte::MemoryInterface {
|
||||
public:
|
||||
Gambatte::MemoryBuffer loadRomData() {
|
||||
Gambatte::MemoryBuffer mb;
|
||||
mb.data = (void*)memory::dmgrom.handle();
|
||||
mb.size = memory::dmgrom.size();
|
||||
return mb;
|
||||
}
|
||||
|
||||
Gambatte::MemoryBuffer loadRamData() {
|
||||
Gambatte::MemoryBuffer mb;
|
||||
mb.data = (void*)memory::dmgram.handle();
|
||||
mb.size = memory::dmgram.size();
|
||||
return mb;
|
||||
}
|
||||
|
||||
Gambatte::MemoryBuffer loadRtcData() {
|
||||
Gambatte::MemoryBuffer mb;
|
||||
mb.data = (void*)memory::dmgrtc.handle();
|
||||
mb.size = memory::dmgram.size();
|
||||
return mb;
|
||||
}
|
||||
|
||||
Gambatte::MemoryBuffer saveRamData(unsigned size) {
|
||||
memory::dmgram.reset();
|
||||
memory::dmgram.map(new uint8_t[size], size);
|
||||
|
||||
Gambatte::MemoryBuffer mb;
|
||||
mb.data = (void*)memory::dmgram.handle();
|
||||
mb.size = memory::dmgram.size();
|
||||
return mb;
|
||||
}
|
||||
|
||||
Gambatte::MemoryBuffer saveRtcData() {
|
||||
memory::dmgrtc.reset();
|
||||
memory::dmgrtc.map(new uint8_t[4], 4);
|
||||
|
||||
Gambatte::MemoryBuffer mb;
|
||||
mb.data = (void*)memory::dmgrtc.handle();
|
||||
mb.size = memory::dmgrtc.size();
|
||||
return mb;
|
||||
}
|
||||
|
||||
void joypWrite(bool p15, bool p14) {
|
||||
sgb.gameboy->write(p15, p14);
|
||||
}
|
||||
};
|
||||
|
||||
class GameboyGambatte : public Gameboy {
|
||||
public:
|
||||
Gambatte::GB gambatte;
|
||||
GambatteInput gambatte_input;
|
||||
GambatteVideo gambatte_video;
|
||||
GambatteMemory gambatte_memory;
|
||||
uint32_t audio_buffer[65536];
|
||||
|
||||
unsigned run() {
|
||||
unsigned samples = gambatte.runFor(audio_buffer, 16);
|
||||
for(unsigned i = 0; i < samples; i++) {
|
||||
system.audio.cop_sample(audio_buffer[i] >> 0, audio_buffer[i] >> 16);
|
||||
}
|
||||
return (samples << 3) + (samples << 1); //1 sample = 10 S-CPU clock cycles
|
||||
}
|
||||
|
||||
unsigned lyCounter() {
|
||||
return gambatte.lyCounter();
|
||||
}
|
||||
|
||||
void updateVideo(unsigned row) {
|
||||
gambatte.updateVideo();
|
||||
gambatte_video.update(row);
|
||||
}
|
||||
|
||||
void unload() {
|
||||
gambatte.save();
|
||||
}
|
||||
|
||||
void power() {
|
||||
Gameboy::power();
|
||||
gambatte.load(true);
|
||||
system.audio.set_cop_frequency(60 * 35112);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
Gameboy::reset();
|
||||
gambatte.reset();
|
||||
system.audio.set_cop_frequency(60 * 35112);
|
||||
}
|
||||
|
||||
GameboyGambatte() {
|
||||
gambatte.setVideoBlitter(&gambatte_video);
|
||||
gambatte.setInputStateGetter(&gambatte_input);
|
||||
gambatte.setMemoryInterface(&gambatte_memory);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
|
@ -1,98 +0,0 @@
|
|||
namespace SNES {
|
||||
|
||||
static const char command_name[32][64] = {
|
||||
"PAL01", "PAL23", "PAL03", "PAL12",
|
||||
"ATTR_BLK", "ATTR_LIN", "ATTR_DIV", "ATTR_CHR",
|
||||
"SOUND", "SOU_TRN", "PAL_SET", "PAL_TRN",
|
||||
"ATRC_EN", "TEST_EN", "ICON_EN", "DATA_SND",
|
||||
"DATA_TRN", "MLT_REG", "JUMP", "CHR_TRN",
|
||||
"PCT_TRN", "ATTR_TRN", "ATTR_SET", "MASK_EN",
|
||||
"OBJ_TRN", "19_???", "1A_???", "1B_???",
|
||||
"1C_???", "1D_???", "1E_ROM", "1F_???",
|
||||
};
|
||||
|
||||
class Gameboy {
|
||||
public:
|
||||
uint8_t vram[(160 / 8) * (144 / 8) * (64 / 4)];
|
||||
|
||||
bool pulselock;
|
||||
bool strobelock;
|
||||
bool packetlock;
|
||||
|
||||
SuperGameboy::Packet packet;
|
||||
uint8_t packetoffset;
|
||||
uint8_t bitdata, bitoffset;
|
||||
|
||||
unsigned joypadid() {
|
||||
return sgb.mmio.joypadid;
|
||||
}
|
||||
|
||||
void write(bool p15, bool p14) {
|
||||
if(p15 == 1 && p14 == 1) {
|
||||
sgb.mmio.joypadid++;
|
||||
if(sgb.mmio.r6003 & 0x20) sgb.mmio.joypadid &= 3;
|
||||
else if(sgb.mmio.r6003 & 0x10) sgb.mmio.joypadid &= 1;
|
||||
else sgb.mmio.joypadid &= 0;
|
||||
}
|
||||
|
||||
if(p15 == 0 && p14 == 0) {
|
||||
//pulse
|
||||
pulselock = false;
|
||||
packetoffset = 0;
|
||||
bitoffset = 0;
|
||||
strobelock = true;
|
||||
packetlock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(pulselock) return;
|
||||
|
||||
if(p15 == 1 && p14 == 1) {
|
||||
strobelock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(strobelock) return;
|
||||
|
||||
//p15(1), p14(0) = 0
|
||||
//p15(0), p14(1) = 1
|
||||
bool bit = (p15 == 0);
|
||||
strobelock = true;
|
||||
|
||||
if(packetlock) {
|
||||
if(p15 == 1 && p14 == 0) {
|
||||
//packet stop bit
|
||||
printf("%s\n", command_name[packet[0] >> 3]);
|
||||
sgb.packet.add(packet);
|
||||
packetlock = false;
|
||||
pulselock = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bitdata = (bit << 7) | (bitdata >> 1);
|
||||
if(++bitoffset < 8) return;
|
||||
|
||||
bitoffset = 0;
|
||||
packet[packetoffset] = bitdata;
|
||||
if(++packetoffset < 16) return;
|
||||
packetlock = true;
|
||||
}
|
||||
|
||||
virtual unsigned run() { return 64; }
|
||||
virtual unsigned lyCounter() { return 0; }
|
||||
virtual void updateVideo(unsigned) {}
|
||||
virtual void unload() {}
|
||||
|
||||
virtual void power() {
|
||||
pulselock = true;
|
||||
memset(&vram, 0, sizeof vram);
|
||||
}
|
||||
|
||||
virtual void reset() {
|
||||
pulselock = true;
|
||||
memset(&vram, 0, sizeof vram);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
namespace SNES {
|
||||
|
||||
class Gameboy {
|
||||
public:
|
||||
unsigned run() {
|
||||
for(unsigned i = 0; i < memory::sgbvram.size(); i++) {
|
||||
memory::sgbvram.write(i, rand());
|
||||
}
|
||||
sgb.refresh();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unload() {
|
||||
}
|
||||
|
||||
void power() {
|
||||
}
|
||||
|
||||
void reset() {
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
|
@ -1,147 +1,66 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#include "interface/interface.hpp"
|
||||
#if defined(SGB_GAMBATTE)
|
||||
#include "interface/gambatte.cpp"
|
||||
#else
|
||||
#include "interface/reference.cpp"
|
||||
#endif
|
||||
|
||||
#define SGB_CPP
|
||||
namespace SNES {
|
||||
|
||||
void SuperGameboy::enter() {
|
||||
SuperGameBoy sgb;
|
||||
|
||||
void SuperGameBoy::enter() {
|
||||
while(true) {
|
||||
unsigned clocks;
|
||||
if((mmio.r6003 & 0x80) == 0) {
|
||||
clocks = 10;
|
||||
system.audio.cop_sample(0, 0);
|
||||
if(sgb_run) {
|
||||
unsigned samples = sgb_run(samplebuffer, 16);
|
||||
scheduler.addclocks_cop(samples * 10);
|
||||
scheduler.sync_copcpu();
|
||||
} else {
|
||||
clocks = gameboy->run();
|
||||
scheduler.addclocks_cop(64 * 1024 * 1024);
|
||||
scheduler.sync_copcpu();
|
||||
}
|
||||
scheduler.addclocks_cop(clocks);
|
||||
scheduler.sync_copcpu();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SuperGameboy::read(unsigned addr) {
|
||||
uint8_t SuperGameBoy::read(unsigned addr) {
|
||||
addr &= 0xffff;
|
||||
|
||||
//DMG lyCounter
|
||||
if(addr == 0x6000) {
|
||||
return gameboy->lyCounter();
|
||||
}
|
||||
|
||||
//command ready port
|
||||
if(addr == 0x6002) {
|
||||
bool data = packet.size() > 0;
|
||||
if(data) {
|
||||
mmio.r7000 = packet[0];
|
||||
unsigned size = packet.size() - 1;
|
||||
for(unsigned i = 0; i < size; i++) packet[i] = packet[i + 1];
|
||||
packet.resize(size);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//command port
|
||||
if((addr & 0xfff0) == 0x7000) {
|
||||
return mmio.r7000[addr & 15];
|
||||
}
|
||||
|
||||
//screen data port
|
||||
if(addr == 0x7800) {
|
||||
uint8_t data = gameboy->vram[mmio.r7800++];
|
||||
if(mmio.r7800 >= (160 / 8) * (144 / 8) * (64 / 4)) mmio.r7800 = 0;
|
||||
return data;
|
||||
}
|
||||
|
||||
if(sgb_read) return sgb_read(addr);
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
void SuperGameboy::write(unsigned addr, uint8_t data) {
|
||||
void SuperGameBoy::write(unsigned addr, uint8_t data) {
|
||||
addr &= 0xffff;
|
||||
if(sgb_write) return sgb_write(addr, data);
|
||||
}
|
||||
|
||||
if(addr == 0x6001) {
|
||||
gameboy->updateVideo(mmio.r7800 / 320);
|
||||
}
|
||||
|
||||
//control port
|
||||
//d7 = Gameboy enable
|
||||
//d5 = four-player enable (1=4-player, 0=see d4)
|
||||
//d4 = two-player enable (if: d5=0; 1=2-player, 0=1-player)
|
||||
//d0 = ??? (always 1)
|
||||
if(addr == 0x6003) {
|
||||
if(((mmio.r6003 & 0x80) == 0x00) && ((data & 0x80) == 0x80)) {
|
||||
gameboy->reset();
|
||||
command_1e();
|
||||
mmio.r7800 = 320 * 16;
|
||||
}
|
||||
mmio.r6003 = data;
|
||||
return;
|
||||
}
|
||||
|
||||
//joypad ports 1-4
|
||||
if((addr & 0x600c) == 0x6004) {
|
||||
mmio.joypad[addr & 3] = data;
|
||||
return;
|
||||
void SuperGameBoy::init() {
|
||||
if(libsgb.open("SuperGameBoy")) {
|
||||
sgb_init = libsgb.sym("sgb_init");
|
||||
sgb_term = libsgb.sym("sgb_term");
|
||||
sgb_power = libsgb.sym("sgb_power");
|
||||
sgb_reset = libsgb.sym("sgb_reset");
|
||||
sgb_read = libsgb.sym("sgb_read");
|
||||
sgb_write = libsgb.sym("sgb_write");
|
||||
sgb_run = libsgb.sym("sgb_run");
|
||||
}
|
||||
}
|
||||
|
||||
void SuperGameboy::init() {}
|
||||
void SuperGameboy::enable() {}
|
||||
|
||||
void SuperGameboy::power() {
|
||||
multiplier = (system.region() == System::NTSC ? config.cpu.ntsc_clock_rate : config.cpu.pal_clock_rate);
|
||||
gameboy->power();
|
||||
reset();
|
||||
void SuperGameBoy::enable() {
|
||||
}
|
||||
|
||||
void SuperGameboy::reset() {
|
||||
gameboy->reset();
|
||||
packet.reset();
|
||||
counter = 0;
|
||||
|
||||
void SuperGameBoy::power() {
|
||||
bus.map(Bus::MapDirect, 0x00, 0x3f, 0x6000, 0x7fff, *this);
|
||||
bus.map(Bus::MapDirect, 0x80, 0xbf, 0x6000, 0x7fff, *this);
|
||||
|
||||
mmio.r6000 = 0;
|
||||
mmio.r6003 = 0;
|
||||
|
||||
//$6004-$6007
|
||||
mmio.joypadid = 0;
|
||||
for(unsigned i = 0; i < 4; i++) mmio.joypad[i] = 0xff;
|
||||
|
||||
for(unsigned i = 0; i < 16; i++) mmio.r7000[i] = 0;
|
||||
mmio.r7800 = 0;
|
||||
}
|
||||
|
||||
void SuperGameboy::unload() {
|
||||
gameboy->unload();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void SuperGameboy::command_1e() {
|
||||
for(unsigned i = 0; i < 6; i++) {
|
||||
Packet p;
|
||||
p[0] = (0x1e << 3) + 1;
|
||||
p[1] = 0;
|
||||
for(unsigned n = 2; n < 16; n++) {
|
||||
p[n] = memory::dmgrom.read(0x0104 + (i * 14) + (n - 2));
|
||||
}
|
||||
packet.add(p);
|
||||
if(sgb_init) {
|
||||
sgb_init(SGB2,
|
||||
memory::gbrom.data(), memory::gbrom.size(),
|
||||
memory::gbram.data(), memory::gbram.size()
|
||||
);
|
||||
}
|
||||
|
||||
if(sgb_power) sgb_power();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
SuperGameboy::SuperGameboy() {
|
||||
gameboy = new GameboyGambatte;
|
||||
}
|
||||
|
||||
SuperGameboy::~SuperGameboy() {
|
||||
delete gameboy;
|
||||
void SuperGameBoy::reset() {
|
||||
if(sgb_reset) sgb_reset();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
class Gameboy;
|
||||
|
||||
class SuperGameboy : public Memory {
|
||||
class SuperGameBoy : public Memory {
|
||||
public:
|
||||
Gameboy *gameboy;
|
||||
void enter();
|
||||
|
||||
struct Packet {
|
||||
uint8_t data[16];
|
||||
uint8_t& operator[](unsigned addr) { return data[addr & 15]; }
|
||||
};
|
||||
vector<Packet> packet;
|
||||
|
||||
struct MMIO {
|
||||
unsigned r6000;
|
||||
uint8_t r6003;
|
||||
|
||||
//$6004-$6007
|
||||
uint8_t joypadid;
|
||||
uint8_t joypad[4];
|
||||
|
||||
Packet r7000;
|
||||
unsigned r7800;
|
||||
} mmio;
|
||||
|
||||
uint8_t read(unsigned addr);
|
||||
void write(unsigned addr, uint8_t data);
|
||||
|
||||
|
@ -30,15 +9,20 @@ public:
|
|||
void enable();
|
||||
void power();
|
||||
void reset();
|
||||
void unload();
|
||||
|
||||
SuperGameboy();
|
||||
~SuperGameboy();
|
||||
private:
|
||||
library libsgb;
|
||||
uint32_t samplebuffer[4096];
|
||||
|
||||
protected:
|
||||
uint64_t multiplier;
|
||||
uint64_t counter;
|
||||
void command_1e();
|
||||
enum { SGB1 = 0, SGB2 = 1 };
|
||||
function<bool (bool, uint8_t*, unsigned, uint8_t*, unsigned)> sgb_init;
|
||||
function<void ()> sgb_term;
|
||||
function<void ()> sgb_power;
|
||||
function<void ()> sgb_reset;
|
||||
function<uint8_t (unsigned)> sgb_read;
|
||||
function<void (unsigned, uint8_t)> sgb_write;
|
||||
function<unsigned (uint32_t*, unsigned)> sgb_run;
|
||||
};
|
||||
|
||||
extern SuperGameboy sgb;
|
||||
extern SuperGameBoy sgb;
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#define SPC7110_CPP
|
||||
namespace SNES {
|
||||
|
||||
SPC7110 spc7110;
|
||||
|
||||
#include "decomp.cpp"
|
||||
|
||||
const unsigned SPC7110::months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
@ -672,3 +674,4 @@ SPC7110::SPC7110() {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#define SRTC_CPP
|
||||
namespace SNES {
|
||||
|
||||
SRTC srtc;
|
||||
|
||||
const unsigned SRTC::months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
void SRTC::init() {
|
||||
|
@ -227,3 +229,4 @@ SRTC::SRTC() {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define ST010_CPP
|
||||
|
||||
#define ST010_CPP
|
||||
namespace SNES {
|
||||
|
||||
ST010 st010;
|
||||
|
||||
#include "st010_data.hpp"
|
||||
#include "st010_op.cpp"
|
||||
|
@ -86,5 +88,5 @@ void ST010::write(unsigned addr, uint8 data) {
|
|||
ram[0x0021] &= ~0x80;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
@mingw32-make platform=win compiler=mingw32-gcc clean
|
||||
@mingw32-make clean
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
make platform=x compiler=gcc clean
|
|
@ -48,3 +48,4 @@ CPUcore::CPUcore() {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#ifdef CPUCORE_CPP
|
||||
|
||||
inline void CPUcore::op_adc_b() {
|
||||
int r;
|
||||
if(regs.p.d) {
|
||||
|
@ -363,3 +365,5 @@ inline void CPUcore::op_tsb_w() {
|
|||
regs.p.z = (rd.w & regs.a.w) == 0;
|
||||
rd.w |= regs.a.w;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -383,6 +383,4 @@ void op_per_e();
|
|||
void op_per_n();
|
||||
@endmacro
|
||||
|
||||
//
|
||||
|
||||
@include "opcode_list.bpp"
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
void CPUcore::initialize_opcode_table() {
|
||||
for(unsigned i = 0; i < 256 * 5; i++) op_table[i] = 0;
|
||||
#ifdef CPUCORE_CPP
|
||||
|
||||
void CPUcore::initialize_opcode_table() {
|
||||
//same implementation for all processor states
|
||||
#define opA(id, name) \
|
||||
op_table[table_EM + id] = &sCPU::op_ ## name; \
|
||||
op_table[table_MX + id] = &sCPU::op_ ## name; \
|
||||
op_table[table_Mx + id] = &sCPU::op_ ## name; \
|
||||
op_table[table_mX + id] = &sCPU::op_ ## name; \
|
||||
op_table[table_mx + id] = &sCPU::op_ ## name;
|
||||
op_table[table_EM + id] = &CPUcore::op_ ## name; \
|
||||
op_table[table_MX + id] = &CPUcore::op_ ## name; \
|
||||
op_table[table_Mx + id] = &CPUcore::op_ ## name; \
|
||||
op_table[table_mX + id] = &CPUcore::op_ ## name; \
|
||||
op_table[table_mx + id] = &CPUcore::op_ ## name;
|
||||
|
||||
//implementation changes based on E processor state
|
||||
#define opE(id, name) \
|
||||
op_table[table_EM + id] = &sCPU::op_ ## name ## _e; \
|
||||
op_table[table_MX + id] = &sCPU::op_ ## name ## _n; \
|
||||
op_table[table_Mx + id] = &sCPU::op_ ## name ## _n; \
|
||||
op_table[table_mX + id] = &sCPU::op_ ## name ## _n; \
|
||||
op_table[table_mx + id] = &sCPU::op_ ## name ## _n; \
|
||||
op_table[table_EM + id] = &CPUcore::op_ ## name ## _e; \
|
||||
op_table[table_MX + id] = &CPUcore::op_ ## name ## _n; \
|
||||
op_table[table_Mx + id] = &CPUcore::op_ ## name ## _n; \
|
||||
op_table[table_mX + id] = &CPUcore::op_ ## name ## _n; \
|
||||
op_table[table_mx + id] = &CPUcore::op_ ## name ## _n; \
|
||||
|
||||
//implementation changes based on M processor state
|
||||
#define opM(id, name) \
|
||||
op_table[table_EM + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_MX + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_Mx + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_mX + id] = &sCPU::op_ ## name ## _w; \
|
||||
op_table[table_mx + id] = &sCPU::op_ ## name ## _w;
|
||||
op_table[table_EM + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_MX + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_Mx + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_mX + id] = &CPUcore::op_ ## name ## _w; \
|
||||
op_table[table_mx + id] = &CPUcore::op_ ## name ## _w;
|
||||
|
||||
//implementation changes based on X processor state
|
||||
#define opX(id, name) \
|
||||
op_table[table_EM + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_MX + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_Mx + id] = &sCPU::op_ ## name ## _w; \
|
||||
op_table[table_mX + id] = &sCPU::op_ ## name ## _b; \
|
||||
op_table[table_mx + id] = &sCPU::op_ ## name ## _w;
|
||||
op_table[table_EM + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_MX + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_Mx + id] = &CPUcore::op_ ## name ## _w; \
|
||||
op_table[table_mX + id] = &CPUcore::op_ ## name ## _b; \
|
||||
op_table[table_mx + id] = &CPUcore::op_ ## name ## _w;
|
||||
|
||||
opE(0x00, brk) opM(0x01, ora_idpx) opE(0x02, cop) opM(0x03, ora_sr)
|
||||
opM(0x04, tsb_dp) opM(0x05, ora_dp) opM(0x06, asl_dp) opM(0x07, ora_ildp)
|
||||
|
@ -136,3 +136,6 @@ void CPUcore::update_table() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define CPU_CPP
|
||||
|
||||
#define CPU_CPP
|
||||
namespace SNES {
|
||||
|
||||
void CPU::power() {
|
||||
|
@ -15,5 +15,5 @@ CPU::CPU() {
|
|||
|
||||
CPU::~CPU() {
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -4,11 +4,6 @@ void sCPU::op_io() {
|
|||
status.clock_count = 6;
|
||||
precycle_edge();
|
||||
add_clocks(6);
|
||||
|
||||
if(regs.wai) {
|
||||
scheduler.sync_cpucop();
|
||||
scheduler.sync_cpuppu();
|
||||
}
|
||||
cycle_edge();
|
||||
}
|
||||
|
||||
|
@ -16,9 +11,7 @@ uint8 sCPU::op_read(uint32 addr) {
|
|||
status.clock_count = speed(addr);
|
||||
precycle_edge();
|
||||
add_clocks(status.clock_count - 4);
|
||||
|
||||
scheduler.sync_cpucop();
|
||||
scheduler.sync_cpuppu();
|
||||
regs.mdr = bus.read(addr);
|
||||
add_clocks(4);
|
||||
cycle_edge();
|
||||
|
@ -29,9 +22,7 @@ void sCPU::op_write(uint32 addr, uint8 data) {
|
|||
status.clock_count = speed(addr);
|
||||
precycle_edge();
|
||||
add_clocks(status.clock_count);
|
||||
|
||||
scheduler.sync_cpucop();
|
||||
scheduler.sync_cpuppu();
|
||||
bus.write(addr, regs.mdr = data);
|
||||
cycle_edge();
|
||||
}
|
||||
|
@ -47,3 +38,4 @@ unsigned sCPU::speed(unsigned addr) const {
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ void sCPU::mmio_w4016(uint8 data) {
|
|||
status.joypad_strobe_latch = !!(data & 1);
|
||||
|
||||
if(status.joypad_strobe_latch == 1) {
|
||||
system.input.poll();
|
||||
input.poll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ void sCPU::mmio_w4016(uint8 data) {
|
|||
//realtime or buffered status of joypadN.b
|
||||
uint8 sCPU::mmio_r4016() {
|
||||
uint8 r = regs.mdr & 0xfc;
|
||||
r |= system.input.port_read(0) & 3;
|
||||
r |= input.port_read(0) & 3;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ uint8 sCPU::mmio_r4016() {
|
|||
//1-0 = Joypad serial data
|
||||
uint8 sCPU::mmio_r4017() {
|
||||
uint8 r = (regs.mdr & 0xe0) | 0x1c;
|
||||
r |= system.input.port_read(1) & 3;
|
||||
r |= input.port_read(1) & 3;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <../base.hpp>
|
||||
#include <nall/priorityqueue.hpp>
|
||||
#include <../base.hpp>
|
||||
#include <nall/priorityqueue.hpp>
|
||||
|
||||
#define SCPU_CPP
|
||||
#define SCPU_CPP
|
||||
namespace SNES {
|
||||
|
||||
priority_queue<unsigned> event(512, bind(&sCPU::queue_event, &cpu));
|
||||
|
@ -30,7 +30,7 @@ void sCPU::enter() {
|
|||
}
|
||||
|
||||
tracer.trace_cpuop(); //traces CPU opcode (only if tracer is enabled)
|
||||
(this->*opcode_table[op_readpc()])();
|
||||
(this->*opcode_table[op_readpc()])();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,5 +96,5 @@ sCPU::sCPU() {
|
|||
|
||||
sCPU::~sCPU() {
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
void sCPU::run_auto_joypad_poll() {
|
||||
uint16 joy1 = 0, joy2 = 0, joy3 = 0, joy4 = 0;
|
||||
for(unsigned i = 0; i < 16; i++) {
|
||||
uint8 port0 = system.input.port_read(0);
|
||||
uint8 port1 = system.input.port_read(1);
|
||||
uint8 port0 = input.port_read(0);
|
||||
uint8 port1 = input.port_read(1);
|
||||
|
||||
joy1 |= (port0 & 1) ? (0x8000 >> i) : 0;
|
||||
joy2 |= (port1 & 1) ? (0x8000 >> i) : 0;
|
||||
|
|
|
@ -13,21 +13,24 @@ void sCPU::add_clocks(unsigned clocks) {
|
|||
unsigned ticks = clocks >> 1;
|
||||
while(ticks--) {
|
||||
ppu.tick();
|
||||
if((ppu.hcounter() & 2) == 0) {
|
||||
system.input.tick();
|
||||
} else {
|
||||
if(ppu.hcounter() & 2) {
|
||||
input.tick();
|
||||
poll_interrupts();
|
||||
}
|
||||
}
|
||||
scheduler.addclocks_cpu(clocks);
|
||||
}
|
||||
|
||||
//called by ppu.tick() when Hcounter=0
|
||||
void sCPU::scanline() {
|
||||
status.dma_counter = (status.dma_counter + status.line_clocks) & 7;
|
||||
status.line_clocks = ppu.lineclocks();
|
||||
|
||||
//forcefully sync S-CPU and S-SMP, in case chips are not communicating
|
||||
if((ppu.vcounter() & 7) == 0) scheduler.sync_cpusmp();
|
||||
//forcefully sync S-CPU to other processors, in case chips are not communicating
|
||||
scheduler.sync_cpuppu();
|
||||
scheduler.sync_cpucop();
|
||||
scheduler.sync_cpusmp();
|
||||
system.scanline();
|
||||
|
||||
if(ppu.vcounter() == 0) {
|
||||
//hdma init triggers once every frame
|
||||
|
@ -44,7 +47,7 @@ void sCPU::scanline() {
|
|||
}
|
||||
|
||||
if(status.auto_joypad_poll == true && ppu.vcounter() == (ppu.overscan() == false ? 227 : 242)) {
|
||||
system.input.poll();
|
||||
input.poll();
|
||||
run_auto_joypad_poll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,6 @@ software which is ordinarily not compatible with this license, such as the GPL.
|
|||
<table border="1" cellpadding="3">
|
||||
<tr><td><b>Name</b></td><td><b>License</b></td><td><b>Author(s)</b></td></tr>
|
||||
|
||||
<tr><td>gambatte Gameboy emulator</td><td>GPL 2</td><td>Sindre Aamas</td></tr>
|
||||
|
||||
<tr><td>Cx4 emulator</td><td></td><td>anomie, Kris Bleakley, Nach, zsKnight</td></tr>
|
||||
<tr><td>DSP-1 emulator</td><td></td><td>Andreas Naive, John Weidman, Kris Bleakley, neviksti</td></tr>
|
||||
<tr><td>DSP-2 emulator</td><td></td><td>Kris Bleakley</td></tr>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <../base.hpp>
|
||||
|
||||
#define ADSP_CPP
|
||||
namespace SNES {
|
||||
|
||||
#define ADSP_CPP
|
||||
namespaec SNES {
|
||||
|
||||
#include "adsp_tables.cpp"
|
||||
|
||||
|
@ -582,12 +582,13 @@ int32 fir_samplel, fir_sampler;
|
|||
msampler = sclamp<16>(msampler);
|
||||
}
|
||||
|
||||
system.audio.dsp_sample(msamplel, msampler);
|
||||
audio.sample(msamplel, msampler);
|
||||
scheduler.addclocks_dsp(32 * 3 * 8);
|
||||
scheduler.sync_dspsmp();
|
||||
}
|
||||
|
||||
aDSP::aDSP() {}
|
||||
aDSP::~aDSP() {}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ void sDSP::echo_27() {
|
|||
}
|
||||
|
||||
//output sample to DAC
|
||||
system.audio.dsp_sample(outl, outr);
|
||||
audio.sample(outl, outr);
|
||||
}
|
||||
|
||||
void sDSP::echo_28() {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
/*
|
||||
S-DSP emulator
|
||||
license: LGPLv2
|
||||
|
||||
Note: this is basically a C++ cothreaded implementation of Shay Green's (blargg's) S-DSP emulator.
|
||||
The actual algorithms, timing information, tables, variable names, etc were all from him.
|
||||
*/
|
||||
|
||||
#include <../base.hpp>
|
||||
|
||||
#define SDSP_CPP
|
||||
namespace SNES {
|
||||
|
||||
|
@ -327,3 +326,4 @@ sDSP::~sDSP() {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ namespace SNES {
|
|||
|
||||
#include "system/system.hpp"
|
||||
#include "chip/chip.hpp"
|
||||
|
||||
#include "cartridge/cartridge.hpp"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
|
@ -1,69 +0,0 @@
|
|||
cc = g++
|
||||
|
||||
cflags = -O2 -fomit-frame-pointer -Wall -Wextra
|
||||
cflags += -fno-exceptions -fno-rtti
|
||||
cflags += -DHAVE_STDINT_H -DCHAR_WIDTH_8
|
||||
cflags += -Isrc -Iinclude -Icommon
|
||||
|
||||
headers = src/*.h src/file/*.h src/sound/*.h src/video/*.h src/video/filters/*.h
|
||||
headers += include/*.h
|
||||
headers += common/*.h common/resample/*.h
|
||||
|
||||
source = \
|
||||
src/bitmap_font.cpp \
|
||||
src/colorconversion.cpp \
|
||||
src/cpu.cpp \
|
||||
src/gambatte.cpp \
|
||||
src/initstate.cpp \
|
||||
src/interrupter.cpp \
|
||||
src/memory.cpp \
|
||||
src/rtc.cpp \
|
||||
src/sound.cpp \
|
||||
src/state_osd_elements.cpp \
|
||||
src/statesaver.cpp \
|
||||
src/video.cpp \
|
||||
src/sound/channel1.cpp \
|
||||
src/sound/channel2.cpp \
|
||||
src/sound/channel3.cpp \
|
||||
src/sound/channel4.cpp \
|
||||
src/sound/duty_unit.cpp \
|
||||
src/sound/envelope_unit.cpp \
|
||||
src/sound/length_counter.cpp \
|
||||
src/video/basic_add_event.cpp \
|
||||
src/video/break_event.cpp \
|
||||
src/video/irq_event.cpp \
|
||||
src/video/ly_counter.cpp \
|
||||
src/video/lyc_irq.cpp \
|
||||
src/video/m3_extra_cycles.cpp \
|
||||
src/video/mode3_event.cpp \
|
||||
src/video/mode0_irq.cpp \
|
||||
src/video/mode1_irq.cpp \
|
||||
src/video/mode2_irq.cpp \
|
||||
src/video/sc_reader.cpp \
|
||||
src/video/scx_reader.cpp \
|
||||
src/video/sprite_mapper.cpp \
|
||||
src/video/we_master_checker.cpp \
|
||||
src/video/we.cpp \
|
||||
src/video/wx_reader.cpp \
|
||||
src/video/wy.cpp \
|
||||
src/video/filters/catrom2x.cpp \
|
||||
src/video/filters/catrom3x.cpp \
|
||||
src/video/filters/kreed2xsai.cpp \
|
||||
src/video/filters/maxsthq2x.cpp \
|
||||
src/video/filters/maxsthq3x.cpp \
|
||||
src/file/file.cpp \
|
||||
|
||||
all: build;
|
||||
|
||||
clean:
|
||||
-@rm obj/*.o
|
||||
-@rm libgambatte.a
|
||||
|
||||
$(foreach item,$(source),$(eval obj/$(notdir $(basename $(item))).o: $(item) $(headers)))
|
||||
objects := $(foreach item,$(source),obj/$(notdir $(basename $(item))).o)
|
||||
|
||||
%.o: $<
|
||||
$(cc) -o $@ -c $< $(cflags)
|
||||
|
||||
build: $(objects)
|
||||
ar rcs libgambatte.a $(objects)
|
|
@ -1,130 +0,0 @@
|
|||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
Copyright (C) 2007 by Sindre Aamås
|
||||
aamas@stud.ntnu.no
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License version 2 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 2 along with this program; if not, write to the
|
||||
Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
About
|
||||
--------------------------------------------------------------------------------
|
||||
Gambatte is an accuracy-focused, open-source, cross-platform
|
||||
Game Boy Color emulator written in C++. It is based on hundreds of
|
||||
corner case hardware tests, as well as previous documentation and reverse
|
||||
engineering efforts.
|
||||
|
||||
The core emulation code is contained in a separate library back-end
|
||||
(libgambatte) written in platform-independent C++. There is currently a GUI
|
||||
front-end (gambatte_qt) using Trolltech's Qt4 toolkit, and a simple command-line
|
||||
SDL front-end (gambatte_sdl).
|
||||
|
||||
The GUI front-end contains platform-specific extensions for video, sound and
|
||||
timers. It should work on MS Windows, Linux/BSD/UNIX-like OSes, and Mac OS X.
|
||||
|
||||
The SDL front-end should be usable on all platforms with a working SDL port. It
|
||||
should also be quite trivial to create new (simple) front-ends (note that the
|
||||
library API should in no way be considered stable).
|
||||
|
||||
Usage
|
||||
--------------------------------------------------------------------------------
|
||||
You will have to supply Gambatte with a ROM image file of the GB/GBC
|
||||
program/game you'd like to run/play, either as a command-line argument to
|
||||
gambatte_sdl, or through the File->Open... menu in gambatte_qt.
|
||||
|
||||
gambatte_sdl keyboard commands:
|
||||
TAB - fast-forward
|
||||
Ctrl-f - toggle full screen
|
||||
Ctrl-r - reset
|
||||
F5 - save state
|
||||
F6 - previous state slot
|
||||
F7 - next state slot
|
||||
F8 - load state
|
||||
0 to 9 - select state slot 0 to 9
|
||||
|
||||
Default key mapping:
|
||||
Up: Up
|
||||
Down: Down
|
||||
Left: Left
|
||||
Right: Right
|
||||
A: D
|
||||
B: C
|
||||
Start: Return
|
||||
Select: Shift
|
||||
|
||||
Compiling
|
||||
--------------------------------------------------------------------------------
|
||||
Building Gambatte from source code can be done by executing the
|
||||
build_<qt/sdl>.sh scripts for the qt/sdl front-ends respectively, or by issueing
|
||||
the correct build command (either 'scons' or 'qmake && make') in the top-level
|
||||
subdirectories (libgambatte will have to be built first). The clean.sh script
|
||||
can be executed to remove all generated files after a compile (including
|
||||
binaries).
|
||||
|
||||
Requirements for building libgambatte:
|
||||
- A decent C++ compiler (like g++ in the GNU Compiler Collection).
|
||||
- SCons.
|
||||
- optionally zlib
|
||||
|
||||
Requirements for building gambatte_sdl:
|
||||
- A decent C++ compiler (like g++ in the GNU Compiler Collection).
|
||||
- SDL headers and library.
|
||||
- SCons.
|
||||
(- libgambatte.)
|
||||
|
||||
Requirements for building gambatte_qt:
|
||||
- A decent C++ compiler (like g++ in the GNU Compiler Collection).
|
||||
- Qt4 (Core, GUI, OpenGL) headers and library.
|
||||
- Qmake and make (GNU Make should work).
|
||||
- Platform-specific requirements:
|
||||
* MS Windows:
|
||||
- Win32 API headers and libraries.
|
||||
- DirectSound and DirectDraw7 headers and libraries.
|
||||
- Direct3D9 headers
|
||||
* Linux/BSD/UNIX-like OSes:
|
||||
- POSIX/UNIX headers (unistd.h, fcntl.h, sys/ioctl.h, sys/time.h, sys/shm.h).
|
||||
- Open Sound System header (sys/soundcard.h).
|
||||
- X11 Xlib, XVideo, XRandR and XShm headers and libraries.
|
||||
- Alsa headers and library (Linux only).
|
||||
* Max OS X:
|
||||
- Recent Mac OS X SDK (Panther Xcode/SDK should work)
|
||||
(- libgambatte.)
|
||||
|
||||
Installing after a compile simply amounts to copying the generated binary
|
||||
(either gambatte_qt/bin/gambatte_qt<.exe> or gambatte_sdl/gambatte_sdl<.exe>)
|
||||
to wherever you'd like to keep it.
|
||||
|
||||
Thanks
|
||||
--------------------------------------------------------------------------------
|
||||
Derek Liauw Kie Fa (Kreed)
|
||||
Gilles Vollant
|
||||
Jeff Frohwein
|
||||
Jonathan Gevaryahu (Lord Nightmare)
|
||||
kOOPa
|
||||
Marat Fayzullin
|
||||
Martin Korth (nocash)
|
||||
Maxim Stepin (MaxSt)
|
||||
Nach
|
||||
Pan of Anthrox
|
||||
Pascal Felber
|
||||
Paul Robson
|
||||
SDL
|
||||
Shay Green (blargg)
|
||||
The OpenGL Extension Wrangler Library
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
Game Boy and Game Boy Color are registered trademarks of
|
||||
Nintendo of America Inc.
|
||||
Gambatte is not affiliated with or endorsed by any of the companies mentioned.
|
|
@ -1,56 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "adaptivesleep.h"
|
||||
|
||||
usec_t AdaptiveSleep::sleepUntil(usec_t base, usec_t inc) {
|
||||
usec_t now = getusecs();
|
||||
usec_t diff = now - base;
|
||||
|
||||
if (diff >= inc)
|
||||
return diff - inc;
|
||||
|
||||
diff = inc - diff;
|
||||
|
||||
if (diff > oversleep + oversleepVar) {
|
||||
diff -= oversleep + oversleepVar;
|
||||
usecsleep(diff);
|
||||
const usec_t ideal = now + diff;
|
||||
now = getusecs();
|
||||
|
||||
{
|
||||
usec_t curOversleep = now - ideal;
|
||||
|
||||
if (negate(curOversleep) < curOversleep)
|
||||
curOversleep = 0;
|
||||
|
||||
oversleepVar = (oversleepVar * 15 + (curOversleep < oversleep ? oversleep - curOversleep : curOversleep - oversleep)) >> 4;
|
||||
oversleep = (oversleep * 15 + curOversleep) >> 4;
|
||||
}
|
||||
|
||||
noSleep = 60;
|
||||
} else if (--noSleep == 0) {
|
||||
noSleep = 60;
|
||||
oversleep = oversleepVar = 0;
|
||||
}
|
||||
|
||||
while (now - base < inc)
|
||||
now = getusecs();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef ADAPTIVE_SLEEP_H
|
||||
#define ADAPTIVE_SLEEP_H
|
||||
|
||||
#include "usec.h"
|
||||
|
||||
class AdaptiveSleep {
|
||||
usec_t oversleep;
|
||||
usec_t oversleepVar;
|
||||
unsigned noSleep;
|
||||
|
||||
public:
|
||||
AdaptiveSleep() : oversleep(0), oversleepVar(0), noSleep(60) {}
|
||||
usec_t sleepUntil(usec_t base, usec_t inc);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,40 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
template<typename T>
|
||||
class Array {
|
||||
T *a;
|
||||
std::size_t sz;
|
||||
|
||||
Array(const Array &ar);
|
||||
|
||||
public:
|
||||
Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {}
|
||||
~Array() { delete []a; }
|
||||
void reset(const std::size_t size) { delete []a; a = size ? new T[size] : 0; sz = size; }
|
||||
std::size_t size() const { return sz; }
|
||||
operator T*() { return a; }
|
||||
operator const T*() const { return a; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,96 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "rateest.h"
|
||||
#include <cstdlib>
|
||||
|
||||
void RateEst::SumQueue::reset() {
|
||||
q.clear();
|
||||
samples_ = usecs_ = 0;
|
||||
}
|
||||
|
||||
void RateEst::SumQueue::push(const long samples, const usec_t usecs) {
|
||||
q.push_back(pair_t(samples, usecs));
|
||||
samples_ += samples;
|
||||
usecs_ += usecs;
|
||||
}
|
||||
|
||||
void RateEst::SumQueue::pop() {
|
||||
const pair_t &f = q.front();
|
||||
samples_ -= f.first;
|
||||
usecs_ -= f.second;
|
||||
q.pop_front();
|
||||
}
|
||||
|
||||
static usec_t sampleUsecs(long samples, long rate) {
|
||||
return static_cast<usec_t>((samples * 1000000.0f) / (rate ? rate : 1) + 0.5f);
|
||||
}
|
||||
|
||||
static long limit(long est, const long reference) {
|
||||
if (est > reference + (reference >> 6))
|
||||
est = reference + (reference >> 6);
|
||||
else if (est < reference - (reference >> 6))
|
||||
est = reference - (reference >> 6);
|
||||
|
||||
return est;
|
||||
}
|
||||
|
||||
void RateEst::init(long srate, long reference, const long maxSamplePeriod) {
|
||||
maxPeriod = sampleUsecs(maxSamplePeriod, reference);
|
||||
|
||||
srate <<= UPSHIFT;
|
||||
reference <<= UPSHIFT;
|
||||
|
||||
this->srate.est = limit(srate, reference);
|
||||
this->srate.var = srate >> 12;
|
||||
last = 0;
|
||||
this->reference = reference;
|
||||
samples = ((this->srate.est >> UPSHIFT) * 12) << 5;
|
||||
usecs = 12000000 << 5;
|
||||
sumq.reset();
|
||||
}
|
||||
|
||||
void RateEst::feed(long samplesIn, const usec_t now) {
|
||||
usec_t usecsIn = now - last;
|
||||
|
||||
if (last && usecsIn < maxPeriod) {
|
||||
sumq.push(samplesIn, usecsIn);
|
||||
|
||||
while ((usecsIn = sumq.usecs()) > 100000) {
|
||||
samplesIn = sumq.samples();
|
||||
sumq.pop();
|
||||
|
||||
if (std::abs(static_cast<long>(samplesIn * (1000000.0f * UP) / usecsIn) - reference) < reference >> 1) {
|
||||
samples += (samplesIn - sumq.samples()) << 5;
|
||||
usecs += (usecsIn - sumq.usecs()) << 5;
|
||||
|
||||
long est = static_cast<long>(samples * (1000000.0f * UP) / usecs + 0.5f);
|
||||
est = limit((srate.est * 31 + est + 16) >> 5, reference);
|
||||
srate.var = (srate.var * 15 + std::abs(est - srate.est) + 8) >> 4;
|
||||
srate.est = est;
|
||||
|
||||
if (usecs > 16000000 << 5) {
|
||||
samples = (samples * 3 + 2) >> 2;
|
||||
usecs = (usecs * 3 + 2) >> 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last = now;
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef RATEEST_H
|
||||
#define RATEEST_H
|
||||
|
||||
#include "usec.h"
|
||||
#include <deque>
|
||||
#include <utility>
|
||||
|
||||
class RateEst {
|
||||
public:
|
||||
struct Result {
|
||||
long est;
|
||||
long var;
|
||||
};
|
||||
|
||||
private:
|
||||
class SumQueue {
|
||||
typedef std::pair<long, usec_t> pair_t;
|
||||
typedef std::deque<pair_t> q_t;
|
||||
|
||||
q_t q;
|
||||
long samples_;
|
||||
usec_t usecs_;
|
||||
|
||||
public:
|
||||
SumQueue() : samples_(0), usecs_(0) {}
|
||||
void reset();
|
||||
long samples() const { return samples_; }
|
||||
usec_t usecs() const { return usecs_; }
|
||||
void push(long samples, usec_t usecs);
|
||||
void pop();
|
||||
};
|
||||
|
||||
enum { UPSHIFT = 5 };
|
||||
enum { UP = 1 << UPSHIFT };
|
||||
|
||||
Result srate;
|
||||
SumQueue sumq;
|
||||
usec_t last;
|
||||
usec_t usecs;
|
||||
usec_t maxPeriod;
|
||||
long reference;
|
||||
long samples;
|
||||
|
||||
public:
|
||||
RateEst(long srate = 0) { init(srate); }
|
||||
RateEst(long srate, long reference) { init(srate, reference); }
|
||||
void init(long srate) { init(srate, srate); }
|
||||
void init(long srate, long reference) { init(srate, reference, reference); }
|
||||
void init(long srate, long reference, long maxSamplePeriod);
|
||||
void reset() { last = 0; }
|
||||
void feed(long samples, usec_t usecs = getusecs());
|
||||
const Result result() const { const Result res = { (srate.est + UP / 2) >> UPSHIFT, (srate.var + UP / 2) >> UPSHIFT }; return res; }
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,100 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef BLACKMANSINC_H
|
||||
#define BLACKMANSINC_H
|
||||
|
||||
#include "convoluter.h"
|
||||
#include "subresampler.h"
|
||||
#include "makesinckernel.h"
|
||||
#include "cic4.h"
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
template<unsigned channels, unsigned phases>
|
||||
class BlackmanSinc : public SubResampler {
|
||||
PolyPhaseConvoluter<channels, phases> convoluters[channels];
|
||||
short *kernel;
|
||||
|
||||
static double blackmanWin(const long i, const long M) {
|
||||
static const double PI = 3.14159265358979323846;
|
||||
return 0.42 - 0.5 * std::cos(2 * PI * i / M) + 0.08 * std::cos(4 * PI * i / M);
|
||||
}
|
||||
|
||||
void init(unsigned div, unsigned phaseLen, double fc);
|
||||
|
||||
public:
|
||||
enum { MUL = phases };
|
||||
|
||||
typedef Cic4<channels> Cic;
|
||||
static float cicLimit() { return 4.7f; }
|
||||
|
||||
class RollOff {
|
||||
static unsigned toTaps(const float rollOffWidth) {
|
||||
static const float widthTimesTaps = 4.5f;
|
||||
return std::ceil(widthTimesTaps / rollOffWidth);
|
||||
}
|
||||
|
||||
static float toFc(const float rollOffStart, const int taps) {
|
||||
static const float startToFcDeltaTimesTaps = 1.69f;
|
||||
return startToFcDeltaTimesTaps / taps + rollOffStart;
|
||||
}
|
||||
|
||||
public:
|
||||
const unsigned taps;
|
||||
const float fc;
|
||||
|
||||
RollOff(float rollOffStart, float rollOffWidth) : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) {}
|
||||
};
|
||||
|
||||
BlackmanSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); }
|
||||
BlackmanSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); }
|
||||
~BlackmanSinc() { delete[] kernel; }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
void adjustDiv(unsigned div);
|
||||
unsigned mul() const { return MUL; }
|
||||
unsigned div() const { return convoluters[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void BlackmanSinc<channels, phases>::init(const unsigned div, const unsigned phaseLen, const double fc) {
|
||||
kernel = new short[phaseLen * phases];
|
||||
|
||||
makeSincKernel(kernel, phases, phaseLen, fc, blackmanWin);
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].reset(kernel, phaseLen, div);
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
std::size_t BlackmanSinc<channels, phases>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
samplesOut = convoluters[i].filter(out + i, in + i, inlen);
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void BlackmanSinc<channels, phases>::adjustDiv(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].adjustDiv(div);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,118 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "chainresampler.h"
|
||||
|
||||
float ChainResampler::get2ChainMidRatio(const float ratio, const float rollOff) {
|
||||
return std::sqrt(0.5f * rollOff * ratio) + 1;
|
||||
}
|
||||
|
||||
float ChainResampler::get2ChainCost(const float ratio, const float rollOff, const float midRatio) {
|
||||
return midRatio * ratio / ((midRatio - 1) * 2) + midRatio / rollOff;
|
||||
}
|
||||
|
||||
float ChainResampler::get3ChainRatio1(float ratio1, const float rollOff, const float ratio) {
|
||||
for (unsigned n = 8; n--;) {
|
||||
ratio1 = std::sqrt(ratio - ratio / get3ChainRatio2(ratio1, rollOff)) + 1;
|
||||
}
|
||||
|
||||
return ratio1;
|
||||
}
|
||||
|
||||
float ChainResampler::get3ChainCost(const float ratio, const float rollOff, const float ratio1, const float ratio2) {
|
||||
return ratio1 * ratio / ((ratio1 - 1) * 2) + ratio2 * ratio1 / ((ratio2 - 1) * 2) + ratio2 / rollOff;
|
||||
}
|
||||
|
||||
std::size_t ChainResampler::reallocateBuffer() {
|
||||
std::size_t bufSz[2] = { 0, 0 };
|
||||
std::size_t inSz = periodSize;
|
||||
int i = -1;
|
||||
|
||||
for (list_t::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
inSz = (inSz * (*it)->mul() - 1) / (*it)->div() + 1;
|
||||
|
||||
++i;
|
||||
|
||||
if (inSz > bufSz[i&1])
|
||||
bufSz[i&1] = inSz;
|
||||
}
|
||||
|
||||
if (inSz >= bufSz[i&1])
|
||||
bufSz[i&1] = 0;
|
||||
|
||||
if (bufferSize < bufSz[0] + bufSz[1]) {
|
||||
delete[] buffer;
|
||||
buffer = (bufferSize = bufSz[0] + bufSz[1]) ? new short[bufferSize * channels] : NULL;
|
||||
}
|
||||
|
||||
buffer2 = bufSz[1] ? buffer + bufSz[0] * channels : NULL;
|
||||
|
||||
return (maxOut_ = inSz);
|
||||
}
|
||||
|
||||
void ChainResampler::adjustRate(const long inRate, const long outRate) {
|
||||
unsigned long mul, div;
|
||||
|
||||
exactRatio(mul, div);
|
||||
|
||||
bigSinc->adjustDiv(static_cast<double>(inRate) * mul / (static_cast<double>(div / bigSinc->div()) * outRate) + 0.5);
|
||||
|
||||
reallocateBuffer();
|
||||
setRate(inRate, outRate);
|
||||
}
|
||||
|
||||
void ChainResampler::exactRatio(unsigned long &mul, unsigned long &div) const {
|
||||
mul = 1;
|
||||
div = 1;
|
||||
|
||||
for (list_t::const_iterator it = list.begin(); it != list.end(); ++it) {
|
||||
mul *= (*it)->mul();
|
||||
div *= (*it)->div();
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t ChainResampler::resample(short *const out, const short *const in, std::size_t inlen) {
|
||||
assert(inlen <= periodSize);
|
||||
|
||||
short *const buf = buffer != buffer2 ? buffer : out;
|
||||
short *const buf2 = buffer2 ? buffer2 : out;
|
||||
|
||||
const short *inbuf = in;
|
||||
short *outbuf = NULL;
|
||||
|
||||
for (list_t::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
outbuf = ++list_t::iterator(it) == list.end() ? out : (inbuf == buf ? buf2 : buf);
|
||||
inlen = (*it)->resample(outbuf, inbuf, inlen);
|
||||
inbuf = outbuf;
|
||||
}
|
||||
|
||||
return inlen;
|
||||
}
|
||||
|
||||
void ChainResampler::uninit() {
|
||||
delete[] buffer;
|
||||
buffer2 = buffer = NULL;
|
||||
bufferSize = 0;
|
||||
periodSize = 0;
|
||||
bigSinc = NULL;
|
||||
|
||||
for (list_t::iterator it = list.begin(); it != list.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
list.clear();
|
||||
}
|
|
@ -1,189 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CHAINRESAMPLER_H
|
||||
#define CHAINRESAMPLER_H
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
#include "subresampler.h"
|
||||
#include "resampler.h"
|
||||
#include "upsampler.h"
|
||||
|
||||
class ChainResampler : public Resampler {
|
||||
enum { channels = 2 };
|
||||
|
||||
typedef std::list<SubResampler*> list_t;
|
||||
|
||||
list_t list;
|
||||
SubResampler *bigSinc;
|
||||
short *buffer;
|
||||
short *buffer2;
|
||||
std::size_t bufferSize;
|
||||
std::size_t periodSize;
|
||||
std::size_t maxOut_;
|
||||
|
||||
static float get1ChainCost(const float ratio, const float rollOff) {
|
||||
return ratio / rollOff;
|
||||
}
|
||||
|
||||
static float get2ChainMidRatio(float ratio, float rollOff);
|
||||
static float get2ChainCost(float ratio, float rollOff, float midRatio);
|
||||
|
||||
static float get3ChainRatio2(const float ratio1, const float rollOff) {
|
||||
return get2ChainMidRatio(ratio1, rollOff);
|
||||
}
|
||||
|
||||
static float get3ChainRatio1(float ratio1, float rollOff, float ratio);
|
||||
static float get3ChainCost(float ratio, float rollOff, float ratio1, float ratio2);
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t downinit(long inRate, long outRate, std::size_t periodSize);
|
||||
|
||||
std::size_t reallocateBuffer();
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t upinit(long inRate, long outRate, std::size_t periodSize);
|
||||
|
||||
public:
|
||||
ChainResampler() : bigSinc(NULL), buffer(NULL), buffer2(NULL), bufferSize(0), periodSize(0) {}
|
||||
~ChainResampler() { uninit(); }
|
||||
|
||||
void adjustRate(long inRate, long outRate);
|
||||
void exactRatio(unsigned long &mul, unsigned long &div) const;
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t init(long inRate, long outRate, std::size_t periodSize);
|
||||
std::size_t maxOut(std::size_t /*inlen*/) const { return maxOut_; }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
void uninit();
|
||||
};
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t ChainResampler::init(const long inRate, const long outRate, const std::size_t periodSize) {
|
||||
setRate(inRate, outRate);
|
||||
|
||||
if (outRate > inRate)
|
||||
return upinit<Sinc>(inRate, outRate, periodSize);
|
||||
else
|
||||
return downinit<Sinc>(inRate, outRate, periodSize);
|
||||
}
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t ChainResampler::downinit(const long inRate, const long outRate, const std::size_t periodSize) {
|
||||
typedef Sinc<channels,2048> BigSinc;
|
||||
typedef Sinc<channels,32> SmallSinc;
|
||||
|
||||
uninit();
|
||||
this->periodSize = periodSize;
|
||||
|
||||
|
||||
const float rollOff = std::max((outRate - 36000.0f + outRate - 40000.0f) / outRate, 0.2f);
|
||||
|
||||
double ratio = static_cast<double>(inRate) / outRate;
|
||||
|
||||
while (ratio >= BigSinc::cicLimit() * 2) {
|
||||
const int div = std::min<int>(static_cast<int>(ratio / BigSinc::cicLimit()), BigSinc::Cic::MAX_DIV);
|
||||
|
||||
list.push_back(new typename BigSinc::Cic(div));
|
||||
ratio /= div;
|
||||
}
|
||||
|
||||
{
|
||||
int div_2c = ratio * SmallSinc::MUL / get2ChainMidRatio(ratio, rollOff) + 0.5f;
|
||||
double ratio_2c = ratio * SmallSinc::MUL / div_2c;
|
||||
float cost_2c = get2ChainCost(ratio, rollOff, ratio_2c);
|
||||
|
||||
if (cost_2c < get1ChainCost(ratio, rollOff)) {
|
||||
const int div1_3c = ratio * SmallSinc::MUL / get3ChainRatio1(ratio_2c, rollOff, ratio) + 0.5f;
|
||||
const double ratio1_3c = ratio * SmallSinc::MUL / div1_3c;
|
||||
const int div2_3c = ratio1_3c * SmallSinc::MUL / get3ChainRatio2(ratio1_3c, rollOff) + 0.5f;
|
||||
const double ratio2_3c = ratio1_3c * SmallSinc::MUL / div2_3c;
|
||||
|
||||
if (get3ChainCost(ratio, rollOff, ratio1_3c, ratio2_3c) < cost_2c) {
|
||||
list.push_back(new SmallSinc(div1_3c, typename SmallSinc::RollOff(0.5f / ratio, (ratio1_3c - 1) / ratio)));
|
||||
ratio = ratio1_3c;
|
||||
div_2c = div2_3c;
|
||||
ratio_2c = ratio2_3c;
|
||||
}
|
||||
|
||||
list.push_back(new SmallSinc(div_2c, typename SmallSinc::RollOff(0.5f / ratio, (ratio_2c - 1) / ratio)));
|
||||
ratio = ratio_2c;
|
||||
}
|
||||
}
|
||||
|
||||
list.push_back(bigSinc = new BigSinc(BigSinc::MUL * ratio + 0.5,
|
||||
typename BigSinc::RollOff(0.5f * (1 + std::max((outRate - 40000.0f) / outRate, 0.0f) - rollOff) / ratio, 0.5f * rollOff / ratio)));
|
||||
|
||||
return reallocateBuffer();
|
||||
}
|
||||
|
||||
template<template<unsigned,unsigned> class Sinc>
|
||||
std::size_t ChainResampler::upinit(const long inRate, const long outRate, const std::size_t periodSize) {
|
||||
typedef Sinc<channels,2048> BigSinc;
|
||||
typedef Sinc<channels,32> SmallSinc;
|
||||
|
||||
uninit();
|
||||
this->periodSize = periodSize;
|
||||
|
||||
const float rollOff = std::max((inRate - 36000.0f) / inRate, 0.2f);
|
||||
|
||||
double ratio = static_cast<double>(outRate) / inRate;
|
||||
|
||||
// Spectral images above 20 kHz assumed inaudible
|
||||
{
|
||||
const int div = outRate / std::max(inRate, 40000l);
|
||||
|
||||
if (div >= 2) {
|
||||
list.push_front(new Upsampler<channels>(div));
|
||||
ratio /= div;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int div_2c = get2ChainMidRatio(ratio, rollOff) * SmallSinc::MUL / ratio + 0.5f;
|
||||
double ratio_2c = ratio * div_2c / SmallSinc::MUL;
|
||||
float cost_2c = get2ChainCost(ratio, rollOff, ratio_2c);
|
||||
|
||||
if (cost_2c < get1ChainCost(ratio, rollOff)) {
|
||||
const int div1_3c = get3ChainRatio1(ratio_2c, rollOff, ratio) * SmallSinc::MUL / ratio + 0.5f;
|
||||
const double ratio1_3c = ratio * div1_3c / SmallSinc::MUL;
|
||||
const int div2_3c = get3ChainRatio2(ratio1_3c, rollOff) * SmallSinc::MUL / ratio1_3c + 0.5f;
|
||||
const double ratio2_3c = ratio1_3c * div2_3c / SmallSinc::MUL;
|
||||
|
||||
if (get3ChainCost(ratio, rollOff, ratio1_3c, ratio2_3c) < cost_2c) {
|
||||
list.push_front(new SmallSinc(div1_3c, typename SmallSinc::RollOff(0.5f / ratio1_3c, (ratio1_3c - 1) / ratio1_3c)));
|
||||
ratio = ratio1_3c;
|
||||
div_2c = div2_3c;
|
||||
ratio_2c = ratio2_3c;
|
||||
}
|
||||
|
||||
list.push_front(new SmallSinc(div_2c, typename SmallSinc::RollOff(0.5f / ratio_2c, (ratio_2c - 1) / ratio_2c)));
|
||||
ratio = ratio_2c;
|
||||
}
|
||||
}
|
||||
|
||||
list.push_front(bigSinc = new BigSinc(BigSinc::MUL / ratio + 0.5, typename BigSinc::RollOff(0.5f * (1 - rollOff), 0.5f * rollOff)));
|
||||
|
||||
return reallocateBuffer();
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,198 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CIC2_H
|
||||
#define CIC2_H
|
||||
|
||||
#include "subresampler.h"
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic2Core {
|
||||
// enum { BUFLEN = 64 };
|
||||
// unsigned long buf[BUFLEN];
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned long prev1;
|
||||
unsigned long prev2;
|
||||
unsigned div_;
|
||||
unsigned nextdivn;
|
||||
// unsigned bufpos;
|
||||
|
||||
public:
|
||||
Cic2Core(const unsigned div = 2) {
|
||||
reset(div);
|
||||
}
|
||||
|
||||
unsigned div() const { return div_; }
|
||||
std::size_t filter(short *out, const short *in, std::size_t inlen);
|
||||
void reset(unsigned div);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic2Core<channels>::reset(const unsigned div) {
|
||||
sum2 = sum1 = 0;
|
||||
prev2 = prev1 = 0;
|
||||
this->div_ = div;
|
||||
nextdivn = div;
|
||||
// bufpos = div - 1;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic2Core<channels>::filter(short *out, const short *const in, std::size_t inlen) {
|
||||
// const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_;
|
||||
const std::size_t produced = (inlen + div_ - nextdivn) / div_;
|
||||
const long mul = 0x10000 / (div_ * div_); // trouble if div is too large, may be better to only support power of 2 div
|
||||
const short *s = in;
|
||||
|
||||
/*unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
|
||||
while (inlen >> 2) {
|
||||
unsigned n = (inlen < BUFLEN ? inlen >> 2 : BUFLEN >> 2);
|
||||
const unsigned end = n * 4;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
unsigned long s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
buf[i++] = sm2 += s1;
|
||||
buf[i++] = sm2 += sm1;
|
||||
s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
buf[i++] = sm2 += s1;
|
||||
buf[i++] = sm2 += sm1;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < end) {
|
||||
const unsigned long out2 = buf[bufpos] - prev2;
|
||||
prev2 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= end;
|
||||
inlen -= end;
|
||||
}
|
||||
|
||||
if (inlen) {
|
||||
unsigned n = inlen;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
buf[i++] = sm2 += sm1;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < inlen) {
|
||||
const unsigned long out2 = buf[bufpos] - prev2;
|
||||
prev2 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= inlen;
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;*/
|
||||
|
||||
unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
|
||||
if (inlen >= nextdivn) {
|
||||
unsigned divn = nextdivn;
|
||||
std::size_t n = produced;
|
||||
|
||||
do {
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
} while (--divn);
|
||||
|
||||
const unsigned long out2 = sm2 - prev2;
|
||||
prev2 = sm2;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
|
||||
divn = div_;
|
||||
} while (--n);
|
||||
|
||||
nextdivn = div_;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned divn = (in + inlen * channels - s) / channels;
|
||||
nextdivn -= divn;
|
||||
|
||||
while (divn--) {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
}
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
|
||||
return produced;
|
||||
}
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic2 : public SubResampler {
|
||||
Cic2Core<channels> cics[channels];
|
||||
|
||||
public:
|
||||
enum { MAX_DIV = 64 };
|
||||
Cic2(unsigned div);
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
unsigned mul() const { return 1; }
|
||||
unsigned div() const { return cics[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
Cic2<channels>::Cic2(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
cics[i].reset(div);
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic2<channels>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i) {
|
||||
samplesOut = cics[i].filter(out + i, in + i, inlen);
|
||||
}
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,382 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CIC3_H
|
||||
#define CIC3_H
|
||||
|
||||
#include "subresampler.h"
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic3Core {
|
||||
// enum { BUFLEN = 64 };
|
||||
// unsigned long buf[BUFLEN];
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned long sum3;
|
||||
unsigned long prev1;
|
||||
unsigned long prev2;
|
||||
unsigned long prev3;
|
||||
unsigned div_;
|
||||
unsigned nextdivn;
|
||||
// unsigned bufpos;
|
||||
|
||||
public:
|
||||
Cic3Core(const unsigned div = 1) {
|
||||
reset(div);
|
||||
}
|
||||
|
||||
unsigned div() const { return div_; }
|
||||
std::size_t filter(short *out, const short *in, std::size_t inlen);
|
||||
void reset(unsigned div);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic3Core<channels>::reset(const unsigned div) {
|
||||
sum3 = sum2 = sum1 = 0;
|
||||
prev3 = prev2 = prev1 = 0;
|
||||
this->div_ = div;
|
||||
nextdivn = div;
|
||||
// bufpos = div - 1;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic3Core<channels>::filter(short *out, const short *const in, std::size_t inlen) {
|
||||
// const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_;
|
||||
const std::size_t produced = (inlen + div_ - nextdivn) / div_;
|
||||
const long mul = 0x10000 / (div_ * div_ * div_); // trouble if div is too large, may be better to only support power of 2 div
|
||||
const short *s = in;
|
||||
|
||||
/*unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
|
||||
while (inlen >> 1) {
|
||||
unsigned n = (inlen < BUFLEN ? inlen >> 1 : BUFLEN >> 1);
|
||||
const unsigned end = n * 2;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
unsigned long s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
unsigned long s2 = sm2 += s1;
|
||||
sm2 += sm1;
|
||||
buf[i++] = sm3 += s2;
|
||||
buf[i++] = sm3 += sm2;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < end) {
|
||||
const unsigned long out3 = buf[bufpos] - prev3;
|
||||
prev3 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= end;
|
||||
inlen -= end;
|
||||
}
|
||||
|
||||
if (inlen) {
|
||||
unsigned n = inlen;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
buf[i++] = sm3 += sm2;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < inlen) {
|
||||
const unsigned long out3 = buf[bufpos] - prev3;
|
||||
prev3 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= inlen;
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;*/
|
||||
|
||||
|
||||
unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
|
||||
if (inlen >= nextdivn) {
|
||||
unsigned divn = nextdivn;
|
||||
std::size_t n = produced;
|
||||
|
||||
do {
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
s += channels;
|
||||
} while (--divn);
|
||||
|
||||
const unsigned long out3 = sm3 - prev3;
|
||||
prev3 = sm3;
|
||||
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
|
||||
divn = div_;
|
||||
} while (--n);
|
||||
|
||||
nextdivn = div_;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned divn = (in + inlen * channels - s) / channels;
|
||||
nextdivn -= divn;
|
||||
|
||||
while (divn--) {
|
||||
sm1 += static_cast<long>(*s);
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
s += channels;
|
||||
}
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;
|
||||
|
||||
return produced;
|
||||
}
|
||||
|
||||
/*template<unsigned channels>
|
||||
class Cic3EvenOddCore {
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned long sum3;
|
||||
unsigned long prev1;
|
||||
unsigned long prev2;
|
||||
unsigned long prev3;
|
||||
unsigned div_;
|
||||
unsigned nextdivn;
|
||||
|
||||
static int getMul(unsigned div) {
|
||||
return 0x10000 / (div * div * div); // trouble if div is too large, may be better to only support power of 2 div
|
||||
}
|
||||
|
||||
void filterEven(short *out, const short *s, std::size_t n);
|
||||
void filterOdd(short *out, const short *s, std::size_t n);
|
||||
|
||||
public:
|
||||
Cic3EvenOddCore(const unsigned div = 2) {
|
||||
reset(div);
|
||||
}
|
||||
|
||||
unsigned div() const { return div_; }
|
||||
std::size_t filter(short *out, const short *in, std::size_t inlen);
|
||||
void reset(unsigned div);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic3EvenOddCore<channels>::reset(const unsigned div) {
|
||||
sum3 = sum2 = sum1 = 0;
|
||||
prev3 = prev2 = prev1 = 0;
|
||||
this->div_ = div;
|
||||
nextdivn = div;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic3EvenOddCore<channels>::filterEven(short *out, const short *s, std::size_t n) {
|
||||
const int mul = getMul(div_);
|
||||
unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
|
||||
while (n--) {
|
||||
{
|
||||
unsigned sn = div_ >> 1;
|
||||
|
||||
do {
|
||||
unsigned long s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
unsigned long s2 = sm2 += s1;
|
||||
sm2 += sm1;
|
||||
sm3 += s2;
|
||||
sm3 += sm2;
|
||||
} while (--sn);
|
||||
}
|
||||
|
||||
const unsigned long out3 = sm3 - prev3;
|
||||
prev3 = sm3;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic3EvenOddCore<channels>::filterOdd(short *out, const short *s, std::size_t n) {
|
||||
const int mul = getMul(div_);
|
||||
unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
|
||||
while (n--) {
|
||||
{
|
||||
unsigned sn = div_ >> 1;
|
||||
|
||||
do {
|
||||
unsigned long s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
unsigned long s2 = sm2 += s1;
|
||||
sm2 += sm1;
|
||||
sm3 += s2;
|
||||
sm3 += sm2;
|
||||
} while (--sn);
|
||||
}
|
||||
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
|
||||
const unsigned long out3 = sm3 - prev3;
|
||||
prev3 = sm3;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic3EvenOddCore<channels>::filter(short *out, const short *const in, std::size_t inlen) {
|
||||
short *const outStart = out;
|
||||
const short *s = in;
|
||||
|
||||
if (inlen >= nextdivn) {
|
||||
{
|
||||
{
|
||||
unsigned divn = nextdivn;
|
||||
|
||||
do {
|
||||
sum1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sum2 += sum1;
|
||||
sum3 += sum2;
|
||||
} while (--divn);
|
||||
}
|
||||
|
||||
const unsigned long out3 = sum3 - prev3;
|
||||
prev3 = sum3;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
*out = static_cast<long>(out2 - prev1) * getMul(div_) / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
std::size_t n = (inlen - nextdivn) / div_;
|
||||
|
||||
if (div_ & 1)
|
||||
filterOdd(out, s, n);
|
||||
else
|
||||
filterEven(out, s, n);
|
||||
|
||||
s += n * div_ * channels;
|
||||
out += n * channels;
|
||||
nextdivn = div_;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned divn = inlen - (s - in) / channels;
|
||||
nextdivn -= divn;
|
||||
|
||||
while (divn--) {
|
||||
sum1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sum2 += sum1;
|
||||
sum3 += sum2;
|
||||
}
|
||||
}
|
||||
|
||||
return (out - outStart) / channels;
|
||||
}*/
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic3 : public SubResampler {
|
||||
Cic3Core<channels> cics[channels];
|
||||
|
||||
public:
|
||||
enum { MAX_DIV = 23 };
|
||||
Cic3(unsigned div);
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
unsigned mul() const { return 1; }
|
||||
unsigned div() const { return cics[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
Cic3<channels>::Cic3(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
cics[i].reset(div);
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic3<channels>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i) {
|
||||
samplesOut = cics[i].filter(out + i, in + i, inlen);
|
||||
}
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,237 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CIC4_H
|
||||
#define CIC4_H
|
||||
|
||||
#include "subresampler.h"
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic4Core {
|
||||
enum { BUFLEN = 64 };
|
||||
unsigned long buf[BUFLEN];
|
||||
unsigned long sum1;
|
||||
unsigned long sum2;
|
||||
unsigned long sum3;
|
||||
unsigned long sum4;
|
||||
unsigned long prev1;
|
||||
unsigned long prev2;
|
||||
unsigned long prev3;
|
||||
unsigned long prev4;
|
||||
unsigned div_;
|
||||
// unsigned nextdivn;
|
||||
unsigned bufpos;
|
||||
|
||||
public:
|
||||
Cic4Core(const unsigned div = 1) {
|
||||
reset(div);
|
||||
}
|
||||
|
||||
unsigned div() const { return div_; }
|
||||
std::size_t filter(short *out, const short *in, std::size_t inlen);
|
||||
void reset(unsigned div);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
void Cic4Core<channels>::reset(const unsigned div) {
|
||||
sum4 = sum3 = sum2 = sum1 = 0;
|
||||
prev4 = prev3 = prev2 = prev1 = 0;
|
||||
this->div_ = div;
|
||||
// nextdivn = div;
|
||||
bufpos = div - 1;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic4Core<channels>::filter(short *out, const short *const in, std::size_t inlen) {
|
||||
const std::size_t produced = (inlen + div_ - (bufpos + 1)) / div_;
|
||||
// const std::size_t produced = (inlen + div_ - nextdivn) / div_;
|
||||
const long mul = 0x10000 / (div_ * div_ * div_ * div_); // trouble if div is too large, may be better to only support power of 2 div
|
||||
const short *s = in;
|
||||
|
||||
unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
unsigned long sm4 = sum4;
|
||||
|
||||
while (inlen >> 2) {
|
||||
unsigned n = (inlen < BUFLEN ? inlen >> 2 : BUFLEN >> 2);
|
||||
const unsigned end = n * 4;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
unsigned long s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
unsigned long s2 = sm2 += s1;
|
||||
sm2 += sm1;
|
||||
unsigned long s3 = sm3 += s2;
|
||||
sm3 += sm2;
|
||||
buf[i++] = sm4 += s3;
|
||||
buf[i++] = sm4 += sm3;
|
||||
s1 = sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
s2 = sm2 += s1;
|
||||
sm2 += sm1;
|
||||
s3 = sm3 += s2;
|
||||
sm3 += sm2;
|
||||
buf[i++] = sm4 += s3;
|
||||
buf[i++] = sm4 += sm3;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < end) {
|
||||
const unsigned long out4 = buf[bufpos] - prev4;
|
||||
prev4 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
const unsigned long out3 = out4 - prev3;
|
||||
prev3 = out4;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= end;
|
||||
inlen -= end;
|
||||
}
|
||||
|
||||
if (inlen) {
|
||||
unsigned n = inlen;
|
||||
unsigned i = 0;
|
||||
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
buf[i++] = sm4 += sm3;
|
||||
} while (--n);
|
||||
|
||||
while (bufpos < inlen) {
|
||||
const unsigned long out4 = buf[bufpos] - prev4;
|
||||
prev4 = buf[bufpos];
|
||||
bufpos += div_;
|
||||
|
||||
const unsigned long out3 = out4 - prev3;
|
||||
prev3 = out4;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
bufpos -= inlen;
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;
|
||||
sum4 = sm4;
|
||||
|
||||
/*unsigned long sm1 = sum1;
|
||||
unsigned long sm2 = sum2;
|
||||
unsigned long sm3 = sum3;
|
||||
unsigned long sm4 = sum4;
|
||||
|
||||
if (produced) {
|
||||
unsigned divn = nextdivn;
|
||||
std::size_t n = produced;
|
||||
|
||||
do {
|
||||
do {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
sm4 += sm3;
|
||||
} while (--divn);
|
||||
|
||||
const unsigned long out4 = sm4 - prev4;
|
||||
prev4 = sm4;
|
||||
const unsigned long out3 = out4 - prev3;
|
||||
prev3 = out4;
|
||||
const unsigned long out2 = out3 - prev2;
|
||||
prev2 = out3;
|
||||
*out = static_cast<long>(out2 - prev1) * mul / 0x10000;
|
||||
prev1 = out2;
|
||||
out += channels;
|
||||
|
||||
divn = div_;
|
||||
} while (--n);
|
||||
|
||||
nextdivn = div_;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned divn = (in + inlen * channels - s) / channels;
|
||||
nextdivn -= divn;
|
||||
|
||||
while (divn--) {
|
||||
sm1 += static_cast<long>(*s);
|
||||
s += channels;
|
||||
sm2 += sm1;
|
||||
sm3 += sm2;
|
||||
sm4 += sm3;
|
||||
}
|
||||
}
|
||||
|
||||
sum1 = sm1;
|
||||
sum2 = sm2;
|
||||
sum3 = sm3;
|
||||
sum4 = sm4;*/
|
||||
|
||||
return produced;
|
||||
}
|
||||
|
||||
template<unsigned channels>
|
||||
class Cic4 : public SubResampler {
|
||||
Cic4Core<channels> cics[channels];
|
||||
|
||||
public:
|
||||
enum { MAX_DIV = 13 };
|
||||
Cic4(unsigned div);
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
unsigned mul() const { return 1; }
|
||||
unsigned div() const { return cics[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
Cic4<channels>::Cic4(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
cics[i].reset(div);
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Cic4<channels>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i) {
|
||||
samplesOut = cics[i].filter(out + i, in + i, inlen);
|
||||
}
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,156 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CONVOLUTER_H
|
||||
#define CONVOLUTER_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
template<unsigned channels, unsigned phases>
|
||||
class PolyPhaseConvoluter {
|
||||
const short *kernel;
|
||||
short *prevbuf;
|
||||
|
||||
unsigned phaseLen;
|
||||
unsigned div_;
|
||||
unsigned x_;
|
||||
|
||||
public:
|
||||
PolyPhaseConvoluter() : kernel(NULL), prevbuf(NULL), phaseLen(0), div_(0), x_(0) {}
|
||||
PolyPhaseConvoluter(const short *kernel, unsigned phaseLen, unsigned div) { reset(kernel, phaseLen, div); }
|
||||
~PolyPhaseConvoluter() { delete[] prevbuf; }
|
||||
void reset(const short *kernel, unsigned phaseLen, unsigned div);
|
||||
std::size_t filter(short *out, const short *in, std::size_t inlen);
|
||||
void adjustDiv(const unsigned div) { this->div_ = div; }
|
||||
unsigned div() const { return div_; }
|
||||
};
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void PolyPhaseConvoluter<channels, phases>::reset(const short *const kernel, const unsigned phaseLen, const unsigned div) {
|
||||
this->kernel = kernel;
|
||||
this->phaseLen = phaseLen;
|
||||
this->div_ = div;
|
||||
x_ = 0;
|
||||
delete[] prevbuf;
|
||||
prevbuf = new short[phaseLen];
|
||||
std::fill(prevbuf, prevbuf + phaseLen, 0);
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
std::size_t PolyPhaseConvoluter<channels, phases>::filter(short *out, const short *const in, std::size_t inlen) {
|
||||
if (!kernel || !inlen)
|
||||
return 0;
|
||||
|
||||
/*for (std::size_t x = 0; x < inlen + M; ++x) {
|
||||
const int end = x < inlen ? M + 1 : inlen + M - x;
|
||||
int j = x < M ? M - x : 0;
|
||||
j += (phases - (x - M + j) % phases) % phases; // adjust j so we don't start on a virtual 0 sample
|
||||
|
||||
for (; j < end; j += phases) {
|
||||
buffer[x] += kernel[j] * start[(x - M + j) / phases];
|
||||
}
|
||||
}*/
|
||||
|
||||
/*for (std::size_t x = 0; x < inlen + M; ++x) {
|
||||
const int end = x < inlen ? M + 1 : inlen + M - x;
|
||||
int j = x < M ? M - x : 0;
|
||||
j += (phases - (x - M + j) % phases) % phases; // adjust j so we don't start on a virtual 0 sample
|
||||
const short *k = kernel + (j % phases) * phaseLen + j / phases;
|
||||
const short *s = start + (x - M + j) / phases;
|
||||
int n = ((end - j) + phases - 1) / phases;
|
||||
|
||||
do {
|
||||
buffer[x] += *k++ * *s++;
|
||||
} while (--n);
|
||||
}*/
|
||||
|
||||
const std::size_t M = phaseLen * phases - 1;
|
||||
inlen *= phases;
|
||||
std::size_t x = x_;
|
||||
|
||||
for (; x < (M < inlen ? M : inlen); x += div_) {
|
||||
long acc = 0;
|
||||
const unsigned phase = (phases - (x + 1) % phases) % phases; // adjust phase so we don't start on a virtual 0 sample
|
||||
const short *s = prevbuf + (x + 1 + phase) / phases;
|
||||
const short *k = kernel + phase * phaseLen;
|
||||
unsigned n = prevbuf + phaseLen - s;
|
||||
|
||||
while (n--) {
|
||||
acc += *k++ * *s++;
|
||||
}
|
||||
|
||||
s = in;
|
||||
n = x / phases + 1;
|
||||
|
||||
do {
|
||||
acc += *k++ * *s;
|
||||
s += channels;
|
||||
} while (--n);
|
||||
|
||||
*out = acc / 0x10000;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
for (; x < inlen; x += div_) {
|
||||
long acc = 0;
|
||||
const unsigned phase = (phases - (x - M) % phases) % phases; // adjust phase so we don't start on a virtual 0 sample
|
||||
const short *s = in + ((x - M + phase) / phases) * channels;
|
||||
const short *k = kernel + phase * phaseLen;
|
||||
// unsigned n = (M + 1/* - phase + phases - 1*/) / phases;
|
||||
unsigned n = phaseLen;
|
||||
|
||||
do {
|
||||
acc += *k++ * *s;
|
||||
s += channels;
|
||||
} while (--n);
|
||||
|
||||
*out = acc / 0x10000;
|
||||
out += channels;
|
||||
}
|
||||
|
||||
const std::size_t produced = (x - x_) / div_;
|
||||
x_ = x - inlen;
|
||||
|
||||
inlen /= phases;
|
||||
|
||||
{
|
||||
short *p = prevbuf;
|
||||
const short *s = in + (inlen - phaseLen) * channels;
|
||||
unsigned n = phaseLen;
|
||||
|
||||
if (inlen < phaseLen) {
|
||||
const unsigned i = phaseLen - inlen;
|
||||
|
||||
std::memmove(p, p + inlen, i * sizeof(short));
|
||||
|
||||
p += i;
|
||||
n -= i;
|
||||
s = in;
|
||||
}
|
||||
|
||||
do {
|
||||
*p++ = *s;
|
||||
s += channels;
|
||||
} while (--n);
|
||||
}
|
||||
|
||||
return produced;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,100 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef HAMMINGSINC_H
|
||||
#define HAMMINGSINC_H
|
||||
|
||||
#include "convoluter.h"
|
||||
#include "subresampler.h"
|
||||
#include "makesinckernel.h"
|
||||
#include "cic3.h"
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
template<unsigned channels, unsigned phases>
|
||||
class HammingSinc : public SubResampler {
|
||||
PolyPhaseConvoluter<channels, phases> convoluters[channels];
|
||||
short *kernel;
|
||||
|
||||
static double hammingWin(const long i, const long M) {
|
||||
static const double PI = 3.14159265358979323846;
|
||||
return 0.53836 - 0.46164 * std::cos(2 * PI * i / M);
|
||||
}
|
||||
|
||||
void init(unsigned div, unsigned phaseLen, double fc);
|
||||
|
||||
public:
|
||||
enum { MUL = phases };
|
||||
|
||||
typedef Cic3<channels> Cic;
|
||||
static float cicLimit() { return 4.2f; }
|
||||
|
||||
class RollOff {
|
||||
static unsigned toTaps(const float rollOffWidth) {
|
||||
static const float widthTimesTaps = 3.0f;
|
||||
return std::ceil(widthTimesTaps / rollOffWidth);
|
||||
}
|
||||
|
||||
static float toFc(const float rollOffStart, const int taps) {
|
||||
static const float startToFcDeltaTimesTaps = 1.27f;
|
||||
return startToFcDeltaTimesTaps / taps + rollOffStart;
|
||||
}
|
||||
|
||||
public:
|
||||
const unsigned taps;
|
||||
const float fc;
|
||||
|
||||
RollOff(float rollOffStart, float rollOffWidth) : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) {}
|
||||
};
|
||||
|
||||
HammingSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); }
|
||||
HammingSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); }
|
||||
~HammingSinc() { delete[] kernel; }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
void adjustDiv(unsigned div);
|
||||
unsigned mul() const { return MUL; }
|
||||
unsigned div() const { return convoluters[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void HammingSinc<channels, phases>::init(const unsigned div, const unsigned phaseLen, const double fc) {
|
||||
kernel = new short[phaseLen * phases];
|
||||
|
||||
makeSincKernel(kernel, phases, phaseLen, fc, hammingWin);
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].reset(kernel, phaseLen, div);
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
std::size_t HammingSinc<channels, phases>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
samplesOut = convoluters[i].filter(out + i, in + i, inlen);
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void HammingSinc<channels, phases>::adjustDiv(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].adjustDiv(div);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,129 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef LININT_H
|
||||
#define LININT_H
|
||||
|
||||
#include <cstddef>
|
||||
#include "resampler.h"
|
||||
#include "u48div.h"
|
||||
|
||||
template<unsigned channels>
|
||||
class LinintCore {
|
||||
unsigned long ratio;
|
||||
std::size_t pos_;
|
||||
unsigned fracPos_;
|
||||
int prevSample_;
|
||||
|
||||
public:
|
||||
LinintCore(long inRate = 1, long outRate = 1) { init(inRate, outRate); }
|
||||
void adjustRate(long inRate, long outRate) { ratio = (static_cast<double>(inRate) / outRate) * 0x10000 + 0.5; }
|
||||
void exactRatio(unsigned long &mul, unsigned long &div) const { mul = 0x10000; div = ratio; }
|
||||
void init(long inRate, long outRate);
|
||||
std::size_t maxOut(std::size_t inlen) const { return inlen ? u48div(inlen - 1, 0xFFFF, ratio) + 1 : 0; }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
void LinintCore<channels>::init(const long inRate, const long outRate) {
|
||||
adjustRate(inRate, outRate);
|
||||
pos_ = (ratio >> 16) + 1;
|
||||
fracPos_ = ratio & 0xFFFF;
|
||||
prevSample_ = 0;
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t LinintCore<channels>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t opos = 0;
|
||||
std::size_t pos = pos_;
|
||||
unsigned fracPos = fracPos_;
|
||||
int prevSample = prevSample_;
|
||||
|
||||
if (pos < inlen) {
|
||||
if (pos != 0)
|
||||
prevSample = in[(pos-1) * channels];
|
||||
|
||||
for (;;) {
|
||||
out[opos] = prevSample + (in[pos * channels] - prevSample) * static_cast<long>(fracPos) / 0x10000;
|
||||
opos += channels;
|
||||
|
||||
{
|
||||
const unsigned long next = ratio + fracPos;
|
||||
|
||||
pos += next >> 16;
|
||||
fracPos = next & 0xFFFF;
|
||||
}
|
||||
|
||||
if (pos < inlen) {
|
||||
prevSample = in[(pos-1) * channels];
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
if (pos == inlen)
|
||||
prevSample = in[(pos-1) * channels];
|
||||
}
|
||||
|
||||
// const std::size_t produced = ((pos - pos_) * 0x10000 + fracPos - fracPos_) / ratio;
|
||||
|
||||
pos_ = pos - inlen;
|
||||
fracPos_ = fracPos;
|
||||
prevSample_ = prevSample;
|
||||
|
||||
return opos / channels;
|
||||
}
|
||||
|
||||
template<unsigned channels>
|
||||
class Linint : public Resampler {
|
||||
LinintCore<channels> cores[channels];
|
||||
|
||||
public:
|
||||
Linint(long inRate, long outRate);
|
||||
void adjustRate(long inRate, long outRate);
|
||||
void exactRatio(unsigned long &mul, unsigned long &div) const { cores[0].exactRatio(mul, div); }
|
||||
std::size_t maxOut(std::size_t inlen) const { return cores[0].maxOut(inlen); }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
Linint<channels>::Linint(const long inRate, const long outRate) {
|
||||
setRate(inRate, outRate);
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
cores[i].init(inRate, outRate);
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
void Linint<channels>::adjustRate(const long inRate, const long outRate) {
|
||||
setRate(inRate, outRate);
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
cores[i].adjustRate(inRate, outRate);
|
||||
}
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Linint<channels>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t outlen = 0;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
outlen = cores[i].resample(out + i, in + i, inlen);
|
||||
|
||||
return outlen;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,152 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef MAKE_SINC_KERNEL_H
|
||||
#define MAKE_SINC_KERNEL_H
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
template<class Window>
|
||||
void makeSincKernel(short *const kernel, const unsigned phases, const unsigned phaseLen, double fc, Window win) {
|
||||
static const double PI = 3.14159265358979323846;
|
||||
fc /= phases;
|
||||
|
||||
/*{
|
||||
double *const dkernel = new double[phaseLen * phases];
|
||||
const long M = static_cast<long>(phaseLen) * phases - 1;
|
||||
|
||||
for (long i = 0; i < M + 1; ++i) {
|
||||
const double sinc = i * 2 == M ?
|
||||
PI * fc :
|
||||
std::sin(PI * fc * (i * 2 - M)) / (i * 2 - M);
|
||||
|
||||
dkernel[(i % phases) * phaseLen + i / phases] = win(i, M) * sinc;
|
||||
}
|
||||
|
||||
double maxabsgain = 0;
|
||||
|
||||
for (unsigned ph = 0; ph < phases; ++ph) {
|
||||
double gain = 0;
|
||||
double absgain = 0;
|
||||
|
||||
for (unsigned i = 0; i < phaseLen; ++i) {
|
||||
gain += dkernel[ph * phaseLen + i];
|
||||
absgain += std::abs(dkernel[ph * phaseLen + i]);
|
||||
}
|
||||
|
||||
gain = 1.0 / gain;
|
||||
|
||||
// Per phase normalization to avoid DC fluctuations.
|
||||
for (unsigned i = 0; i < phaseLen; ++i)
|
||||
dkernel[ph * phaseLen + i] *= gain;
|
||||
|
||||
absgain *= gain;
|
||||
|
||||
if (absgain > maxabsgain)
|
||||
maxabsgain = absgain;
|
||||
}
|
||||
|
||||
const double gain = 0x10000 / maxabsgain;
|
||||
|
||||
for (long i = 0; i < M + 1; ++i)
|
||||
kernel[i] = std::floor(dkernel[i] * gain + 0.5);
|
||||
|
||||
delete[] dkernel;
|
||||
}*/
|
||||
|
||||
// The following is equivalent to the more readable version above
|
||||
|
||||
const long M = static_cast<long>(phaseLen) * phases - 1;
|
||||
|
||||
double *const dkernel = new double[M / 2 + 1];
|
||||
|
||||
{
|
||||
double *dk = dkernel;
|
||||
|
||||
for (unsigned ph = 0; ph < phases; ++ph) {
|
||||
for (long i = ph; i < M / 2 + 1; i += phases) {
|
||||
const double sinc = i * 2 == M ?
|
||||
PI * fc :
|
||||
std::sin(PI * fc * (i * 2 - M)) / (i * 2 - M);
|
||||
|
||||
*dk++ = win(i, M) * sinc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double maxabsgain = 0.0;
|
||||
|
||||
{
|
||||
double *dkp1 = dkernel;
|
||||
double *dkp2 = dkernel + M / 2;
|
||||
|
||||
for (unsigned ph = 0; ph < (phases + 1) / 2; ++ph) {
|
||||
double gain = 0.0;
|
||||
double absgain = 0.0;
|
||||
|
||||
{
|
||||
const double *kp1 = dkp1;
|
||||
const double *kp2 = dkp2;
|
||||
long i = ph;
|
||||
|
||||
for (; i < M / 2 + 1; i += phases) {
|
||||
gain += *kp1;
|
||||
absgain += std::abs(*kp1++);
|
||||
}
|
||||
|
||||
for (; i < M + 1; i += phases) {
|
||||
gain += *kp2;
|
||||
absgain += std::abs(*kp2--);
|
||||
}
|
||||
}
|
||||
|
||||
gain = 1.0 / gain;
|
||||
|
||||
long i = ph;
|
||||
|
||||
for (; i < M / 2 + 1; i += phases)
|
||||
*dkp1++ *= gain;
|
||||
|
||||
if (dkp1 < dkp2) {
|
||||
for (; i < M + 1; i += phases)
|
||||
*dkp2-- *= gain;
|
||||
}
|
||||
|
||||
absgain *= gain;
|
||||
|
||||
if (absgain > maxabsgain)
|
||||
maxabsgain = absgain;
|
||||
}
|
||||
}
|
||||
|
||||
const double gain = 0x10000 / maxabsgain;
|
||||
const double *dk = dkernel;
|
||||
|
||||
for (unsigned ph = 0; ph < phases; ++ph) {
|
||||
short *k = kernel + ph * phaseLen;
|
||||
short *km = kernel + M - ph * phaseLen;
|
||||
|
||||
for (long i = ph; i < M / 2 + 1; i += phases)
|
||||
*km-- = *k++ = std::floor(*dk++ * gain + 0.5);
|
||||
}
|
||||
|
||||
delete[] dkernel;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,99 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef RECTSINC_H
|
||||
#define RECTSINC_H
|
||||
|
||||
#include "convoluter.h"
|
||||
#include "subresampler.h"
|
||||
#include "makesinckernel.h"
|
||||
#include "cic2.h"
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
template<unsigned channels, unsigned phases>
|
||||
class RectSinc : public SubResampler {
|
||||
PolyPhaseConvoluter<channels, phases> convoluters[channels];
|
||||
short *kernel;
|
||||
|
||||
static double rectWin(const long /*i*/, const long /*M*/) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void init(unsigned div, unsigned phaseLen, double fc);
|
||||
|
||||
public:
|
||||
enum { MUL = phases };
|
||||
|
||||
typedef Cic2<channels> Cic;
|
||||
static float cicLimit() { return 2.0f; }
|
||||
|
||||
class RollOff {
|
||||
static unsigned toTaps(const float rollOffWidth) {
|
||||
static const float widthTimesTaps = 0.9f;
|
||||
return std::ceil(widthTimesTaps / rollOffWidth);
|
||||
}
|
||||
|
||||
static float toFc(const float rollOffStart, const int taps) {
|
||||
static const float startToFcDeltaTimesTaps = 0.43f;
|
||||
return startToFcDeltaTimesTaps / taps + rollOffStart;
|
||||
}
|
||||
|
||||
public:
|
||||
const unsigned taps;
|
||||
const float fc;
|
||||
|
||||
RollOff(float rollOffStart, float rollOffWidth) : taps(toTaps(rollOffWidth)), fc(toFc(rollOffStart, taps)) {}
|
||||
};
|
||||
|
||||
RectSinc(unsigned div, unsigned phaseLen, double fc) { init(div, phaseLen, fc); }
|
||||
RectSinc(unsigned div, RollOff ro) { init(div, ro.taps, ro.fc); }
|
||||
~RectSinc() { delete[] kernel; }
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
void adjustDiv(unsigned div);
|
||||
unsigned mul() const { return MUL; }
|
||||
unsigned div() const { return convoluters[0].div(); }
|
||||
};
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void RectSinc<channels, phases>::init(const unsigned div, const unsigned phaseLen, const double fc) {
|
||||
kernel = new short[phaseLen * phases];
|
||||
|
||||
makeSincKernel(kernel, phases, phaseLen, fc, rectWin);
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].reset(kernel, phaseLen, div);
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
std::size_t RectSinc<channels, phases>::resample(short *const out, const short *const in, const std::size_t inlen) {
|
||||
std::size_t samplesOut;
|
||||
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
samplesOut = convoluters[i].filter(out + i, in + i, inlen);
|
||||
|
||||
return samplesOut;
|
||||
}
|
||||
|
||||
template<const unsigned channels, const unsigned phases>
|
||||
void RectSinc<channels, phases>::adjustDiv(const unsigned div) {
|
||||
for (unsigned i = 0; i < channels; ++i)
|
||||
convoluters[i].adjustDiv(div);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,43 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef RESAMPLER_H
|
||||
#define RESAMPLER_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class Resampler {
|
||||
long inRate_;
|
||||
long outRate_;
|
||||
|
||||
protected:
|
||||
void setRate(const long inRate, const long outRate) { inRate_ = inRate; outRate_ = outRate; }
|
||||
|
||||
public:
|
||||
Resampler() : inRate_(0), outRate_(0) {}
|
||||
long inRate() const { return inRate_; }
|
||||
long outRate() const { return outRate_; }
|
||||
|
||||
virtual void adjustRate(long inRate, long outRate) = 0;
|
||||
virtual void exactRatio(unsigned long &mul, unsigned long &div) const = 0;
|
||||
virtual std::size_t maxOut(std::size_t inlen) const = 0;
|
||||
virtual std::size_t resample(short *out, const short *in, std::size_t inlen) = 0;
|
||||
virtual ~Resampler() {}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,61 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "resamplerinfo.h"
|
||||
#include "chainresampler.h"
|
||||
#include "hammingsinc.h"
|
||||
#include "blackmansinc.h"
|
||||
#include "rectsinc.h"
|
||||
#include "linint.h"
|
||||
|
||||
struct LinintInfo {
|
||||
static Resampler* create(long inRate, long outRate, std::size_t) { return new Linint<2>(inRate, outRate); }
|
||||
};
|
||||
|
||||
struct RectsincInfo {
|
||||
static Resampler* create(long inRate, long outRate, std::size_t periodSz) {
|
||||
ChainResampler *r = new ChainResampler;
|
||||
r->init<RectSinc>(inRate, outRate, periodSz);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
struct HammingsincInfo {
|
||||
static Resampler* create(long inRate, long outRate, std::size_t periodSz) {
|
||||
ChainResampler *r = new ChainResampler;
|
||||
r->init<HammingSinc>(inRate, outRate, periodSz);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlackmansincInfo {
|
||||
static Resampler* create(long inRate, long outRate, std::size_t periodSz) {
|
||||
ChainResampler *r = new ChainResampler;
|
||||
r->init<BlackmanSinc>(inRate, outRate, periodSz);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
const ResamplerInfo ResamplerInfo::resamplers[] = {
|
||||
{ "2-tap linear interpolation", LinintInfo::create },
|
||||
{ "Rectangular windowed sinc (~20 dB SNR)", RectsincInfo::create },
|
||||
{ "Hamming windowed sinc (~50 dB SNR)", HammingsincInfo::create },
|
||||
{ "Blackman windowed sinc (~70 dB SNR)", BlackmansincInfo::create }
|
||||
};
|
||||
|
||||
const unsigned ResamplerInfo::num_ = sizeof(ResamplerInfo::resamplers) / sizeof(ResamplerInfo);
|
|
@ -1,36 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef RESAMPLER_INFO_H
|
||||
#define RESAMPLER_INFO_H
|
||||
|
||||
#include "resampler.h"
|
||||
|
||||
struct ResamplerInfo {
|
||||
const char *desc;
|
||||
Resampler* (*create)(long inRate, long outRate, std::size_t periodSz);
|
||||
|
||||
static unsigned num() { return num_; }
|
||||
static const ResamplerInfo& get(unsigned n) { return resamplers[n]; }
|
||||
|
||||
private:
|
||||
static const ResamplerInfo resamplers[];
|
||||
static const unsigned num_;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef SUBRESAMPLER_H
|
||||
#define SUBRESAMPLER_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class SubResampler {
|
||||
public:
|
||||
virtual std::size_t resample(short *out, const short *in, std::size_t inlen) = 0;
|
||||
virtual unsigned mul() const = 0;
|
||||
virtual unsigned div() const = 0;
|
||||
virtual void adjustDiv(unsigned /*div*/) {}
|
||||
virtual ~SubResampler() {}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,54 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "u48div.h"
|
||||
|
||||
unsigned long u48div(unsigned long num1, unsigned num2, const unsigned long den) {
|
||||
unsigned long res = 0;
|
||||
unsigned s = 16;
|
||||
|
||||
do {
|
||||
if (num1 < 0x10000) {
|
||||
num1 <<= s;
|
||||
num1 |= num2 & ((1 << s) - 1);
|
||||
s = 0;
|
||||
} else {
|
||||
if (num1 < 0x1000000) {
|
||||
const unsigned maxs = s < 8 ? s : 8;
|
||||
num1 <<= maxs;
|
||||
num1 |= (num2 >> (s -= maxs)) & ((1 << maxs) - 1);
|
||||
}
|
||||
|
||||
if (num1 < 0x10000000) {
|
||||
const unsigned maxs = s < 4 ? s : 4;
|
||||
num1 <<= maxs;
|
||||
num1 |= (num2 >> (s -= maxs)) & ((1 << maxs) - 1);
|
||||
}
|
||||
|
||||
while (num1 < den && s) {
|
||||
num1 <<= 1; // if this overflows we're screwed
|
||||
num1 |= num2 >> --s & 1;
|
||||
}
|
||||
}
|
||||
|
||||
res += (num1 / den) << s;
|
||||
num1 = (num1 % den);
|
||||
} while (s);
|
||||
|
||||
return res;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef U48DIV_H
|
||||
#define U48DIV_H
|
||||
|
||||
unsigned long u48div(unsigned long num1, unsigned num2, unsigned long den);
|
||||
|
||||
#endif
|
|
@ -1,51 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef UPSAMPLER_H
|
||||
#define UPSAMPLER_H
|
||||
|
||||
#include "subresampler.h"
|
||||
#include <cstring>
|
||||
|
||||
template<unsigned channels>
|
||||
class Upsampler : public SubResampler {
|
||||
unsigned mul_;
|
||||
|
||||
public:
|
||||
Upsampler(const unsigned mul) : mul_(mul) {}
|
||||
std::size_t resample(short *out, const short *in, std::size_t inlen);
|
||||
unsigned mul() const { return mul_; }
|
||||
unsigned div() const { return 1; }
|
||||
};
|
||||
|
||||
template<const unsigned channels>
|
||||
std::size_t Upsampler<channels>::resample(short *out, const short *in, std::size_t inlen) {
|
||||
if (inlen) {
|
||||
std::memset(out, 0, inlen * mul_ * sizeof(short) * channels);
|
||||
|
||||
do {
|
||||
std::memcpy(out, in, sizeof(short) * channels);
|
||||
in += channels;
|
||||
out += mul_ * channels;
|
||||
} while (--inlen);
|
||||
}
|
||||
|
||||
return inlen * mul_;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,112 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef RINGBUFFER_H
|
||||
#define RINGBUFFER_H
|
||||
|
||||
#include "array.h"
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
template<typename T>
|
||||
class RingBuffer {
|
||||
Array<T> buf;
|
||||
std::size_t sz;
|
||||
std::size_t rpos;
|
||||
std::size_t wpos;
|
||||
|
||||
public:
|
||||
RingBuffer(const std::size_t sz_in = 0) : sz(0), rpos(0), wpos(0) { reset(sz_in); }
|
||||
|
||||
std::size_t avail() const {
|
||||
return (wpos < rpos ? 0 : sz) + rpos - wpos - 1;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
wpos = rpos = 0;
|
||||
}
|
||||
|
||||
void fill(T value);
|
||||
|
||||
void read(T *out, std::size_t num);
|
||||
|
||||
void reset(std::size_t sz_in);
|
||||
|
||||
std::size_t size() const {
|
||||
return sz - 1;
|
||||
}
|
||||
|
||||
std::size_t used() const {
|
||||
return (wpos < rpos ? sz : 0) + wpos - rpos;
|
||||
}
|
||||
|
||||
void write(const T *in, std::size_t num);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void RingBuffer<T>::fill(const T value) {
|
||||
std::fill(buf + 0, buf + sz, value);
|
||||
rpos = 0;
|
||||
wpos = sz - 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RingBuffer<T>::read(T *out, std::size_t num) {
|
||||
if (rpos + num > sz) {
|
||||
const std::size_t n = sz - rpos;
|
||||
|
||||
std::memcpy(out, buf + rpos, n * sizeof(T));
|
||||
|
||||
rpos = 0;
|
||||
num -= n;
|
||||
out += n;
|
||||
}
|
||||
|
||||
std::memcpy(out, buf + rpos, num * sizeof(T));
|
||||
|
||||
if ((rpos += num) == sz)
|
||||
rpos = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RingBuffer<T>::reset(const std::size_t sz_in) {
|
||||
sz = sz_in + 1;
|
||||
rpos = wpos = 0;
|
||||
buf.reset(sz_in ? sz : 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RingBuffer<T>::write(const T *in, std::size_t num) {
|
||||
if (wpos + num > sz) {
|
||||
const std::size_t n = sz - wpos;
|
||||
|
||||
std::memcpy(buf + wpos, in, n * sizeof(T));
|
||||
|
||||
wpos = 0;
|
||||
num -= n;
|
||||
in += n;
|
||||
}
|
||||
|
||||
std::memcpy(buf + wpos, in, num * sizeof(T));
|
||||
|
||||
if ((wpos += num) == sz)
|
||||
wpos = 0;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef USEC_H
|
||||
#define USEC_H
|
||||
|
||||
typedef unsigned long usec_t;
|
||||
|
||||
static inline usec_t negate(usec_t t) {
|
||||
return usec_t(0) - t;
|
||||
}
|
||||
|
||||
usec_t getusecs();
|
||||
void usecsleep(usec_t usecs);
|
||||
|
||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_FILTERINFO_H
|
||||
#define GAMBATTE_FILTERINFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Gambatte {
|
||||
struct FilterInfo {
|
||||
std::string handle;
|
||||
unsigned int outWidth;
|
||||
unsigned int outHeight;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,84 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_H
|
||||
#define GAMBATTE_H
|
||||
|
||||
class CPU;
|
||||
|
||||
#include "videoblitter.h"
|
||||
#include "inputstate.h"
|
||||
#include "inputstategetter.h"
|
||||
#include "memoryinterface.h"
|
||||
#include "filterinfo.h"
|
||||
#include "int.h"
|
||||
#include <vector>
|
||||
|
||||
namespace Gambatte {
|
||||
class GB {
|
||||
CPU *const z80;
|
||||
int stateNo;
|
||||
|
||||
void loadState(const char *filepath, bool osdMessage);
|
||||
|
||||
public:
|
||||
GB();
|
||||
~GB();
|
||||
bool load(bool forceDmg = false);
|
||||
void save();
|
||||
|
||||
/** Emulates until at least 'samples' stereo sound samples are produced in the supplied buffer.
|
||||
* There are 35112 stereo sound samples in a video frame.
|
||||
* May run for uptil 2064 stereo samples too long.
|
||||
* A stereo sample consists of two native endian 2s complement 16-bit PCM samples,
|
||||
* with the left sample preceding the right one. Usually casting soundBuf to/from
|
||||
* short* is OK and recommended. The reason for not using a short* in the interface
|
||||
* is to avoid implementation defined behaviour without compromising performance.
|
||||
*
|
||||
* @param soundBuf buffer with space >= samples + 2064
|
||||
* @param samples number of stereo samples to produce
|
||||
* @return actual number of samples produced
|
||||
*/
|
||||
unsigned runFor(uint32_t *soundBuf, unsigned samples);
|
||||
void updateVideo();
|
||||
unsigned lyCounter();
|
||||
|
||||
void reset();
|
||||
void setVideoBlitter(VideoBlitter *vb);
|
||||
void videoBufferChange();
|
||||
unsigned videoWidth() const;
|
||||
unsigned videoHeight() const;
|
||||
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32);
|
||||
|
||||
void setVideoFilter(unsigned n);
|
||||
std::vector<const FilterInfo*> filterInfo() const;
|
||||
void setInputStateGetter(InputStateGetter *getInput);
|
||||
void setMemoryInterface(MemoryInterface *memoryInterface);
|
||||
|
||||
void set_savedir(const char *sdir);
|
||||
bool isCgb() const;
|
||||
void saveState();
|
||||
void loadState();
|
||||
void saveState(const char *filepath);
|
||||
void loadState(const char *filepath);
|
||||
void selectState(int n);
|
||||
int currentState() const { return stateNo; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_INPUTSTATE_H
|
||||
#define GAMBATTE_INPUTSTATE_H
|
||||
|
||||
namespace Gambatte {
|
||||
struct InputState {
|
||||
unsigned joypadId;
|
||||
bool startButton, selectButton, bButton, aButton;
|
||||
bool dpadDown, dpadUp, dpadLeft, dpadRight;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_INPUTSTATEGETTER_H
|
||||
#define GAMBATTE_INPUTSTATEGETTER_H
|
||||
|
||||
namespace Gambatte {
|
||||
class InputStateGetter {
|
||||
public:
|
||||
virtual ~InputStateGetter() {};
|
||||
virtual const InputState& operator()() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,62 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_INT_H
|
||||
#define GAMBATTE_INT_H
|
||||
|
||||
#ifdef HAVE_CSTDINT
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Gambatte {
|
||||
using std::uint_least32_t;
|
||||
using std::uint_least16_t;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_STDINT_H)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Gambatte {
|
||||
using ::uint_least32_t;
|
||||
using ::uint_least16_t;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
namespace Gambatte {
|
||||
#ifdef CHAR_LEAST_32
|
||||
typedef unsigned char uint_least32_t;
|
||||
#elif defined(SHORT_LEAST_32)
|
||||
typedef unsigned short uint_least32_t;
|
||||
#elif defined(INT_LEAST_32)
|
||||
typedef unsigned uint_least32_t;
|
||||
#else
|
||||
typedef unsigned long uint_least32_t;
|
||||
#endif
|
||||
|
||||
#ifdef CHAR_LEAST_16
|
||||
typedef unsigned char uint_least16_t;
|
||||
#else
|
||||
typedef unsigned short uint_least16_t;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef GAMBATTE_MEMORYINTERFACE_H
|
||||
#define GAMBATTE_MEMORYINTERFACE_H
|
||||
|
||||
namespace Gambatte {
|
||||
|
||||
struct MemoryBuffer {
|
||||
void *data;
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
class MemoryInterface {
|
||||
public:
|
||||
virtual MemoryBuffer loadRomData() = 0;
|
||||
virtual MemoryBuffer loadRamData() = 0;
|
||||
virtual MemoryBuffer loadRtcData() = 0;
|
||||
|
||||
virtual MemoryBuffer saveRamData(unsigned size) = 0;
|
||||
virtual MemoryBuffer saveRtcData() = 0;
|
||||
|
||||
virtual void joypWrite(bool /*p15*/, bool /*p14*/) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef GAMBATTE_VIDEOBLITTER_H
|
||||
#define GAMBATTE_VIDEOBLITTER_H
|
||||
|
||||
namespace Gambatte {
|
||||
|
||||
struct PixelBuffer {
|
||||
enum Format { RGB32, RGB16, UYVY };
|
||||
|
||||
void *pixels;
|
||||
Format format;
|
||||
unsigned pitch;
|
||||
|
||||
PixelBuffer() : pixels(0), format(RGB32), pitch(0) {}
|
||||
};
|
||||
|
||||
class VideoBlitter {
|
||||
public:
|
||||
virtual void setBufferDimensions(unsigned width, unsigned height) = 0;
|
||||
virtual const PixelBuffer inBuffer() = 0;
|
||||
virtual void blit() = 0;
|
||||
virtual ~VideoBlitter() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,328 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
The following font bitmaps (static const unsigned char *_bits[]), only used
|
||||
as data and included in this source file for convenience, are derived from
|
||||
the Bitstream Vera Sans font, which is distributed under the following
|
||||
copyright:
|
||||
|
||||
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
|
||||
is a trademark of Bitstream, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of the fonts accompanying this license ("Fonts") and associated
|
||||
documentation files (the "Font Software"), to reproduce and distribute the
|
||||
Font Software, including without limitation the rights to use, copy, merge,
|
||||
publish, distribute, and/or sell copies of the Font Software, and to permit
|
||||
persons to whom the Font Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
The above copyright and trademark notices and this permission notice shall
|
||||
be included in all copies of one or more of the Font Software typefaces.
|
||||
|
||||
The Font Software may be modified, altered, or added to, and in particular
|
||||
the designs of glyphs or characters in the Fonts may be modified and
|
||||
additional glyphs or characters may be added to the Fonts, only if the fonts
|
||||
are renamed to names not containing either the words "Bitstream" or the word
|
||||
"Vera".
|
||||
|
||||
This License becomes null and void to the extent applicable to Fonts or Font
|
||||
Software that has been modified and is distributed under the "Bitstream Vera"
|
||||
names.
|
||||
|
||||
The Font Software may be sold as part of a larger software package but no
|
||||
copy of one or more of the Font Software typefaces may be sold by itself.
|
||||
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM
|
||||
OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR
|
||||
CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the names of Gnome, the Gnome
|
||||
Foundation, and Bitstream Inc., shall not be used in advertising or
|
||||
otherwise to promote the sale, use or other dealings in this Font Software
|
||||
without prior written authorization from the Gnome Foundation or
|
||||
Bitstream Inc., respectively. For further information, contact: fonts at
|
||||
gnome dot org.
|
||||
*/
|
||||
|
||||
#include "bitmap_font.h"
|
||||
|
||||
static const unsigned char n0_bits[] = { 0x68,
|
||||
0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char n1_bits[] = { 0x68,
|
||||
0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e };
|
||||
|
||||
static const unsigned char n2_bits[] = { 0x68,
|
||||
0x00, 0x1c, 0x22, 0x20, 0x10, 0x08, 0x04, 0x3e };
|
||||
|
||||
static const unsigned char n3_bits[] = { 0x68,
|
||||
0x00, 0x1c, 0x22, 0x20, 0x1c, 0x20, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char n4_bits[] = { 0x68,
|
||||
0x00, 0x18, 0x18, 0x14, 0x12, 0x3e, 0x10, 0x10 };
|
||||
|
||||
static const unsigned char n5_bits[] = { 0x68,
|
||||
0x00, 0x1e, 0x02, 0x1e, 0x20, 0x20, 0x20, 0x1e };
|
||||
|
||||
static const unsigned char n6_bits[] = { 0x68,
|
||||
0x00, 0x3c, 0x06, 0x02, 0x1e, 0x22, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char n7_bits[] = { 0x68,
|
||||
0x00, 0x3e, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04 };
|
||||
|
||||
static const unsigned char n8_bits[] = { 0x68,
|
||||
0x00, 0x1c, 0x22, 0x22, 0x1c, 0x22, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char n9_bits[] = { 0x68,
|
||||
0x00, 0x1c, 0x22, 0x22, 0x3c, 0x20, 0x30, 0x1e };
|
||||
|
||||
static const unsigned char A_bits[] = { 0x78,
|
||||
0x00, 0x08, 0x14, 0x14, 0x22, 0x3e, 0x22, 0x41 };
|
||||
|
||||
static const unsigned char a_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x1c, 0x20, 0x3c, 0x22, 0x3e };
|
||||
|
||||
static const unsigned char B_bits[] = { 0x78,
|
||||
0x00, 0x1e, 0x22, 0x22, 0x1e, 0x22, 0x22, 0x1e };
|
||||
|
||||
static const unsigned char b_bits[] = { 0x68,
|
||||
0x02, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x1e };
|
||||
|
||||
static const unsigned char C_bits[] = { 0x88,
|
||||
0x00, 0x38, 0x44, 0x02, 0x02, 0x02, 0x44, 0x38 };
|
||||
|
||||
static const unsigned char c_bits[] = { 0x58,
|
||||
0x00, 0x00, 0x00, 0x1c, 0x02, 0x02, 0x02, 0x1c };
|
||||
|
||||
static const unsigned char D_bits[] = { 0x88,
|
||||
0x00, 0x3e, 0x62, 0x42, 0x42, 0x42, 0x62, 0x3e };
|
||||
|
||||
static const unsigned char d_bits[] = { 0x68,
|
||||
0x20, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x3c };
|
||||
|
||||
static const unsigned char E_bits[] = { 0x78,
|
||||
0x00, 0x3e, 0x02, 0x02, 0x3e, 0x02, 0x02, 0x3e };
|
||||
|
||||
static const unsigned char e_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x02, 0x3c };
|
||||
|
||||
static const unsigned char F_bits[] = { 0x68,
|
||||
0x00, 0x1e, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char f_bits[] = { 0x48,
|
||||
0x0e, 0x02, 0x02, 0x07, 0x02, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char G_bits[] = { 0x88,
|
||||
0x00, 0x3c, 0x46, 0x02, 0x72, 0x42, 0x46, 0x3c };
|
||||
|
||||
static const unsigned char g_bits[] = { 0x6a,
|
||||
0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x1c };
|
||||
|
||||
static const unsigned char H_bits[] = { 0x88,
|
||||
0x00, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42 };
|
||||
|
||||
static const unsigned char h_bits[] = { 0x68,
|
||||
0x02, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22 };
|
||||
|
||||
static const unsigned char I_bits[] = { 0x38,
|
||||
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char i_bits[] = { 0x28,
|
||||
0x02, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char J_bits[] = { 0x4a,
|
||||
0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03 };
|
||||
|
||||
static const unsigned char j_bits[] = { 0x2a,
|
||||
0x02, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03 };
|
||||
|
||||
static const unsigned char K_bits[] = { 0x78,
|
||||
0x00, 0x22, 0x12, 0x0a, 0x06, 0x0a, 0x12, 0x22 };
|
||||
|
||||
static const unsigned char k_bits[] = { 0x58,
|
||||
0x02, 0x02, 0x02, 0x12, 0x0a, 0x06, 0x0a, 0x12 };
|
||||
|
||||
static const unsigned char L_bits[] = { 0x68,
|
||||
0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x3e };
|
||||
|
||||
static const unsigned char l_bits[] = { 0x28,
|
||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char M_bits[] = { 0x98,
|
||||
0x00, 0x00, 0x82, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xaa, 0x00, 0xaa, 0x00,
|
||||
0x92, 0x00, 0x82, 0x00 };
|
||||
|
||||
static const unsigned char m_bits[] = { 0xa8,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x01, 0x22, 0x02, 0x22, 0x02,
|
||||
0x22, 0x02, 0x22, 0x02 };
|
||||
|
||||
static const unsigned char N_bits[] = { 0x88,
|
||||
0x00, 0x42, 0x46, 0x4a, 0x4a, 0x52, 0x62, 0x42 };
|
||||
|
||||
static const unsigned char n_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x22 };
|
||||
|
||||
static const unsigned char O_bits[] = { 0x88,
|
||||
0x00, 0x3c, 0x66, 0x42, 0x42, 0x42, 0x66, 0x3c };
|
||||
|
||||
static const unsigned char o_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char P_bits[] = { 0x78,
|
||||
0x00, 0x1e, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char p_bits[] = { 0x6a,
|
||||
0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char Q_bits[] = { 0x89,
|
||||
0x00, 0x3c, 0x66, 0x42, 0x42, 0x42, 0x26, 0x1c, 0x20 };
|
||||
|
||||
static const unsigned char q_bits[] = { 0x6a,
|
||||
0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20 };
|
||||
|
||||
static const unsigned char R_bits[] = { 0x78,
|
||||
0x00, 0x1e, 0x22, 0x22, 0x1e, 0x12, 0x22, 0x42 };
|
||||
|
||||
static const unsigned char r_bits[] = { 0x48,
|
||||
0x00, 0x00, 0x00, 0x0e, 0x02, 0x02, 0x02, 0x02 };
|
||||
|
||||
static const unsigned char S_bits[] = { 0x78,
|
||||
0x00, 0x1c, 0x22, 0x02, 0x1c, 0x20, 0x22, 0x1c };
|
||||
|
||||
static const unsigned char s_bits[] = { 0x58,
|
||||
0x00, 0x00, 0x00, 0x1e, 0x02, 0x1c, 0x10, 0x1e };
|
||||
|
||||
static const unsigned char T_bits[] = { 0x58,
|
||||
0x00, 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04 };
|
||||
|
||||
static const unsigned char t_bits[] = { 0x48,
|
||||
0x00, 0x02, 0x02, 0x0f, 0x02, 0x02, 0x02, 0x0e };
|
||||
|
||||
static const unsigned char U_bits[] = { 0x88,
|
||||
0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c };
|
||||
|
||||
static const unsigned char u_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x3c };
|
||||
|
||||
static const unsigned char V_bits[] = { 0x78,
|
||||
0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08 };
|
||||
|
||||
static const unsigned char v_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08 };
|
||||
|
||||
static const unsigned char W_bits[] = { 0x98,
|
||||
0x00, 0x00, 0x11, 0x01, 0x11, 0x01, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00,
|
||||
0x44, 0x00, 0x44, 0x00 };
|
||||
|
||||
static const unsigned char w_bits[] = { 0x88,
|
||||
0x00, 0x00, 0x00, 0x92, 0xaa, 0xaa, 0x44, 0x44 };
|
||||
|
||||
static const unsigned char X_bits[] = { 0x68,
|
||||
0x00, 0x21, 0x12, 0x0c, 0x0c, 0x0c, 0x12, 0x21 };
|
||||
|
||||
static const unsigned char x_bits[] = { 0x68,
|
||||
0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22 };
|
||||
|
||||
static const unsigned char Y_bits[] = { 0x78,
|
||||
0x00, 0x41, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08 };
|
||||
|
||||
static const unsigned char y_bits[] = { 0x6a,
|
||||
0x00, 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x06 };
|
||||
|
||||
static const unsigned char Z_bits[] = { 0x68,
|
||||
0x00, 0x3f, 0x10, 0x08, 0x0c, 0x04, 0x02, 0x3f };
|
||||
|
||||
static const unsigned char z_bits[] = { 0x58,
|
||||
0x00, 0x00, 0x00, 0x1e, 0x10, 0x08, 0x04, 0x1e };
|
||||
|
||||
static const unsigned char SPC_bits[] = { 0x38,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
namespace BitmapFont {
|
||||
const unsigned char *const font[] = {
|
||||
0,
|
||||
n0_bits, n1_bits, n2_bits, n3_bits, n4_bits, n5_bits, n6_bits, n7_bits, n8_bits, n9_bits,
|
||||
A_bits, B_bits, C_bits, D_bits, E_bits, F_bits, G_bits, H_bits, I_bits, J_bits, K_bits, L_bits, M_bits,
|
||||
N_bits, O_bits, P_bits, Q_bits, R_bits, S_bits, T_bits, U_bits, V_bits, W_bits, X_bits, Y_bits, Z_bits,
|
||||
a_bits, b_bits, c_bits, d_bits, e_bits, f_bits, g_bits, h_bits, i_bits, j_bits, k_bits, l_bits, m_bits,
|
||||
n_bits, o_bits, p_bits, q_bits, r_bits, s_bits, t_bits, u_bits, v_bits, w_bits, x_bits, y_bits, z_bits,
|
||||
SPC_bits
|
||||
};
|
||||
|
||||
unsigned getWidth(const char *chars) {
|
||||
unsigned w = 0;
|
||||
|
||||
while (const int character = *chars++) {
|
||||
w += *font[character] >> 4;
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
class Rgb32Fill {
|
||||
const unsigned long color;
|
||||
|
||||
public:
|
||||
Rgb32Fill(unsigned long color) : color(color) {}
|
||||
|
||||
void operator()(Gambatte::uint_least32_t *dest, unsigned /*pitch*/) {
|
||||
*dest = color;
|
||||
}
|
||||
};
|
||||
|
||||
void print(Gambatte::uint_least32_t *dest, const unsigned pitch, const unsigned long color, const char *chars) {
|
||||
print(dest, pitch, Rgb32Fill(color), chars);
|
||||
}
|
||||
|
||||
static void reverse(char *first, char *last) {
|
||||
while (first < last) {
|
||||
const int tmp = *first;
|
||||
|
||||
*first = *last;
|
||||
*last = tmp;
|
||||
|
||||
++first;
|
||||
--last;
|
||||
}
|
||||
}
|
||||
|
||||
void utoa(unsigned u, char *a) {
|
||||
char *aa = a;
|
||||
|
||||
while (u > 9) {
|
||||
const unsigned div = u / 10;
|
||||
const unsigned rem = u % 10;
|
||||
|
||||
u = div;
|
||||
*aa++ = rem + N0;
|
||||
}
|
||||
|
||||
*aa = u + N0;
|
||||
|
||||
reverse(a, aa);
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef BITMAP_FONT_H
|
||||
#define BITMAP_FONT_H
|
||||
|
||||
#include "int.h"
|
||||
|
||||
namespace BitmapFont {
|
||||
enum Char {
|
||||
NUL,
|
||||
N0, N1, N2, N3, N4, N5, N6, N7, N8, N9,
|
||||
A, B, C, D, E, F, G, H, I, J, K, L, M,
|
||||
N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
|
||||
a, b, c, d, e, f, g, h, i, j, k, l, m,
|
||||
n, o, p, q, r, s, t, u, v, w, x, y, z,
|
||||
SPC
|
||||
};
|
||||
|
||||
enum { HEIGHT = 10 };
|
||||
enum { MAX_WIDTH = 9 };
|
||||
enum { NUMBER_WIDTH = 6 };
|
||||
|
||||
unsigned getWidth(const char *chars);
|
||||
|
||||
// struct Fill { void operator()(RandomAccessIterator dest, unsigned pitch) { fill pixels at dest } }
|
||||
template<class RandomAccessIterator, class Fill>
|
||||
void print(RandomAccessIterator dest, unsigned pitch, Fill fill, const char *chars);
|
||||
|
||||
void print(Gambatte::uint_least32_t *dest, unsigned pitch, unsigned long color, const char *chars);
|
||||
void utoa(unsigned u, char *a);
|
||||
|
||||
// --- INTERFACE END ---
|
||||
|
||||
|
||||
|
||||
extern const unsigned char *const font[];
|
||||
|
||||
template<class RandomAccessIterator, class Fill>
|
||||
void print(RandomAccessIterator dest, const unsigned pitch, Fill fill, const char *chars) {
|
||||
while (const int character = *chars++) {
|
||||
RandomAccessIterator dst = dest;
|
||||
const unsigned char *s = font[character];
|
||||
|
||||
const unsigned width = *s >> 4;
|
||||
unsigned h = *s++ & 0xF;
|
||||
|
||||
while (h--) {
|
||||
RandomAccessIterator d = dst;
|
||||
|
||||
unsigned line = *s++;
|
||||
|
||||
if (width > 8)
|
||||
line |= *s++ << 8;
|
||||
|
||||
while (line) {
|
||||
if (line & 1)
|
||||
fill(d, pitch);
|
||||
|
||||
line >>= 1;
|
||||
++d;
|
||||
}
|
||||
|
||||
dst += pitch;
|
||||
}
|
||||
|
||||
dest += width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,96 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "colorconversion.h"
|
||||
#include <algorithm>
|
||||
|
||||
Rgb32ToUyvy::Rgb32ToUyvy() {
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
const CacheUnit c = { 0, 128ul << 24 | 16ul << 16 | 128 << 8 | 16 };
|
||||
#else
|
||||
const CacheUnit c = { 0, 16ul << 24 | 128ul << 16 | 16 << 8 | 128 };
|
||||
#endif
|
||||
std::fill(cache, cache + cache_size, c);
|
||||
}
|
||||
|
||||
void Rgb32ToUyvy::operator()(const Gambatte::uint_least32_t *s, Gambatte::uint_least32_t *d, const unsigned w, unsigned h, const unsigned d_pitch) {
|
||||
while (h--) {
|
||||
for (const Gambatte::uint_least32_t *const ends = s + w; s != ends;) {
|
||||
if ((cache[*s & cache_mask].rgb32 - *s) | (cache[*(s+1) & cache_mask].rgb32 - *(s+1))) {
|
||||
cache[*s & cache_mask].rgb32 = *s;
|
||||
cache[*(s+1) & cache_mask].rgb32 = *(s+1);
|
||||
|
||||
const unsigned long r = (*s >> 16 & 0x000000FF) | (*(s+1) & 0x00FF0000);
|
||||
const unsigned long g = (*s >> 8 & 0x000000FF) | (*(s+1) << 8 & 0x00FF0000);
|
||||
const unsigned long b = (*s & 0x000000FF) | (*(s+1) << 16 & 0x00FF0000);
|
||||
|
||||
const unsigned long y = r * 66 + g * 129 + b * 25 + (16 * 256 + 128) * 0x00010001ul;
|
||||
const unsigned long u = b * 112 - r * 38 - g * 74 + (128 * 256 + 128) * 0x00010001ul;
|
||||
const unsigned long v = r * 112 - g * 94 - b * 18 + (128 * 256 + 128) * 0x00010001ul;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
*d++ = cache[*s & cache_mask].uyvy = (u << 16 & 0xFF000000) | (y << 8 & 0x00FF0000) | (v & 0x0000FF00) | (y >> 8 & 0x000000FF);
|
||||
*d++ = cache[*(s+1) & cache_mask].uyvy = (u & 0xFF000000) | (y >> 8 & 0x00FF0000) | (v >> 16 & 0x0000FF00) | y >> 24;
|
||||
#else
|
||||
*d++ = cache[*s & cache_mask].uyvy = (y << 16 & 0xFF000000) | (v << 8 & 0x00FF0000) | (y & 0x0000FF00) | (u >> 8 & 0x000000FF);
|
||||
*d++ = cache[*(s+1) & cache_mask].uyvy = (y & 0xFF000000) | (v >> 8 & 0x00FF0000) | (y >> 16 & 0x0000FF00) | u >> 24;
|
||||
#endif
|
||||
} else {
|
||||
*d++ = cache[*s & cache_mask].uyvy;
|
||||
*d++ = cache[*(s+1) & cache_mask].uyvy;
|
||||
}
|
||||
|
||||
s += 2;
|
||||
}
|
||||
|
||||
d += d_pitch - w;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long rgb32ToUyvy(unsigned long rgb32) {
|
||||
const unsigned r = rgb32 >> 16 & 0xFF;
|
||||
const unsigned g = rgb32 >> 8 & 0xFF;
|
||||
const unsigned b = rgb32 & 0xFF;
|
||||
|
||||
const unsigned long y = (r * 66 + g * 129 + b * 25 + 16 * 256 + 128) >> 8;
|
||||
const unsigned long u = (b * 112 - r * 38 - g * 74 + 128 * 256 + 128) >> 8;
|
||||
const unsigned long v = (r * 112 - g * 94 - b * 18 + 128 * 256 + 128) >> 8;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
return u << 24 | y << 16 | v << 8 | y;
|
||||
#else
|
||||
return y << 24 | v << 16 | y << 8 | u;
|
||||
#endif
|
||||
}
|
||||
|
||||
void rgb32ToRgb16(const Gambatte::uint_least32_t *s, Gambatte::uint_least16_t *d, const unsigned w, unsigned h, const unsigned dstPitch) {
|
||||
do {
|
||||
unsigned n = w;
|
||||
|
||||
do {
|
||||
*d++ = (*s >> 8 & 0xF800) | (*s >> 5 & 0x07E0) | (*s >> 3 & 0x001F);
|
||||
++s;
|
||||
} while (--n);
|
||||
|
||||
d += dstPitch - w;
|
||||
} while (--h);
|
||||
}
|
||||
|
||||
unsigned rgb32ToRgb16(const unsigned long rgb32) {
|
||||
return (rgb32 >> 8 & 0xF800) | (rgb32 >> 5 & 0x07E0) | (rgb32 >> 3 & 0x001F);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef COLORCONVERSION_H
|
||||
#define COLORCONVERSION_H
|
||||
|
||||
#include "int.h"
|
||||
#include <algorithm>
|
||||
|
||||
class Rgb32ToUyvy {
|
||||
struct CacheUnit {
|
||||
Gambatte::uint_least32_t rgb32;
|
||||
Gambatte::uint_least32_t uyvy;
|
||||
};
|
||||
|
||||
enum { cache_size = 0x100 };
|
||||
enum { cache_mask = cache_size - 1 };
|
||||
|
||||
CacheUnit cache[cache_size];
|
||||
|
||||
public:
|
||||
Rgb32ToUyvy();
|
||||
void operator()(const Gambatte::uint_least32_t *s, Gambatte::uint_least32_t *d, unsigned w, unsigned h, unsigned dstPitch);
|
||||
};
|
||||
|
||||
unsigned long rgb32ToUyvy(unsigned long rgb32);
|
||||
|
||||
void rgb32ToRgb16(const Gambatte::uint_least32_t *s, Gambatte::uint_least16_t *d, unsigned w, unsigned h, unsigned dstPitch);
|
||||
unsigned rgb32ToRgb16(unsigned long rgb32);
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -1,117 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aam<EFBFBD>s *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
class SaveState;
|
||||
|
||||
#include "int.h"
|
||||
#include "memory.h"
|
||||
|
||||
class CPU {
|
||||
Memory memory;
|
||||
|
||||
unsigned long cycleCounter_;
|
||||
|
||||
unsigned short PC_;
|
||||
unsigned short SP;
|
||||
|
||||
unsigned HF1, HF2, ZF, CF;
|
||||
|
||||
unsigned char A_, B, C, D, E, /*F,*/ H, L;
|
||||
|
||||
bool skip;
|
||||
bool halted;
|
||||
|
||||
void process(unsigned long cycles);
|
||||
|
||||
public:
|
||||
|
||||
CPU();
|
||||
// void halt();
|
||||
|
||||
// unsigned interrupt(unsigned address, unsigned cycleCounter);
|
||||
|
||||
void runFor(unsigned long cycles);
|
||||
void updateVideo();
|
||||
unsigned lyCounter();
|
||||
void setStatePtrs(SaveState &state);
|
||||
void saveState(SaveState &state);
|
||||
void loadState(const SaveState &state);
|
||||
|
||||
void loadSavedata() { memory.loadSavedata(); }
|
||||
void saveSavedata() { memory.saveSavedata(); }
|
||||
|
||||
void setVideoBlitter(Gambatte::VideoBlitter *vb) {
|
||||
memory.setVideoBlitter(vb);
|
||||
}
|
||||
|
||||
void videoBufferChange() {
|
||||
memory.videoBufferChange();
|
||||
}
|
||||
|
||||
unsigned int videoWidth() const {
|
||||
return memory.videoWidth();
|
||||
}
|
||||
|
||||
unsigned int videoHeight() const {
|
||||
return memory.videoHeight();
|
||||
}
|
||||
|
||||
void setVideoFilter(const unsigned int n) {
|
||||
memory.setVideoFilter(n);
|
||||
}
|
||||
|
||||
std::vector<const Gambatte::FilterInfo*> filterInfo() const {
|
||||
return memory.filterInfo();
|
||||
}
|
||||
|
||||
void setInputStateGetter(Gambatte::InputStateGetter *getInput) {
|
||||
memory.setInputStateGetter(getInput);
|
||||
}
|
||||
|
||||
void setMemoryInterface(Gambatte::MemoryInterface *memoryInterface) {
|
||||
memory.setMemoryInterface(memoryInterface);
|
||||
}
|
||||
|
||||
void set_savedir(const char *sdir) {
|
||||
memory.set_savedir(sdir);
|
||||
}
|
||||
|
||||
const std::string saveBasePath() const {
|
||||
return memory.saveBasePath();
|
||||
}
|
||||
|
||||
void setOsdElement(std::auto_ptr<OsdElement> osdElement) {
|
||||
memory.setOsdElement(osdElement);
|
||||
}
|
||||
|
||||
bool load(bool forceDmg);
|
||||
|
||||
void setSoundBuffer(Gambatte::uint_least32_t *const buf) { memory.setSoundBuffer(buf); }
|
||||
unsigned fillSoundBuffer() { return memory.fillSoundBuffer(cycleCounter_); }
|
||||
|
||||
bool isCgb() const { return memory.isCgb(); }
|
||||
|
||||
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) {
|
||||
memory.setDmgPaletteColor(palNum, colorNum, rgb32);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,160 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2007 by Sindre Aamås *
|
||||
* aamas@stud.ntnu.no *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License version 2 as *
|
||||
* published by the Free Software Foundation. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License version 2 for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* version 2 along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef EVENT_QUEUE_H
|
||||
#define EVENT_QUEUE_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
template<typename T, class Comparer>
|
||||
class event_queue {
|
||||
Comparer comparer;
|
||||
T *const a;
|
||||
const std::size_t capacity_;
|
||||
std::size_t size_;
|
||||
|
||||
|
||||
std::size_t indexOf(T e);
|
||||
void internalDec(std::size_t i, T e);
|
||||
template<bool child2BoundsCheck> void internalInc(std::size_t i, T e);
|
||||
|
||||
public:
|
||||
event_queue(std::size_t capacity, const Comparer &comparer);
|
||||
~event_queue();
|
||||
|
||||
std::size_t capacity() const {
|
||||
return capacity_;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
void dec(const T oldE, const T newE) {
|
||||
internalDec(indexOf(oldE), newE);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return size_ == 0;
|
||||
}
|
||||
|
||||
void inc(const T oldE, const T newE) {
|
||||
internalInc<true>(indexOf(oldE), newE);
|
||||
}
|
||||
|
||||
void modify_root(const T newRoot) {
|
||||
internalInc<true>(0, newRoot);
|
||||
}
|
||||
|
||||
void pop() {
|
||||
internalInc<false>(0, a[--size_]);
|
||||
}
|
||||
|
||||
void push(const T e) {
|
||||
internalDec(size_++, e);
|
||||
}
|
||||
|
||||
void remove(T e);
|
||||
|
||||
std::size_t size() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
T top() const {
|
||||
return a[0];
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, class Comparer>
|
||||
event_queue<T,Comparer>::event_queue(const std::size_t capacity, const Comparer &comparer_in) :
|
||||
comparer(comparer_in),
|
||||
a(new T[capacity]),
|
||||
capacity_(capacity),
|
||||
size_(0)
|
||||
{}
|
||||
|
||||
template<typename T, class Comparer>
|
||||
event_queue<T,Comparer>::~event_queue() {
|
||||
delete[] a;
|
||||
}
|
||||
|
||||
template<typename T, class Comparer>
|
||||
std::size_t event_queue<T,Comparer>::indexOf(const T e) {
|
||||
std::size_t i = 0;
|
||||
|
||||
while (a[i] != e)
|
||||
++i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename T, class Comparer>
|
||||
void event_queue<T,Comparer>::internalDec(std::size_t i, const T e) {
|
||||
a[i] = e;
|
||||
|
||||
while (i != 0) {
|
||||
const std::size_t parentI = (i - 1) >> 1;
|
||||
|
||||
if (!comparer.less(e, a[parentI]))
|
||||
break;
|
||||
|
||||
a[i] = a[parentI];
|
||||
a[parentI] = e;
|
||||
i = parentI;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, class Comparer>
|
||||
template<const bool child2BoundsCheck>
|
||||
void event_queue<T,Comparer>::internalInc(std::size_t i, const T e) {
|
||||
a[i] = e;
|
||||
|
||||
for (;;) {
|
||||
std::size_t childI = i * 2 + 1;
|
||||
|
||||
if (childI >= size_)
|
||||
break;
|
||||
|
||||
if ((!child2BoundsCheck || childI + 1 < size_) && comparer.less(a[childI + 1], a[childI]))
|
||||
++childI;
|
||||
|
||||
if (!comparer.less(a[childI], e))
|
||||
break;
|
||||
|
||||
a[i] = a[childI];
|
||||
a[childI] = e;
|
||||
i = childI;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, class Comparer>
|
||||
void event_queue<T,Comparer>::remove(const T e) {
|
||||
std::size_t i = indexOf(e);
|
||||
|
||||
while (i != 0) {
|
||||
const std::size_t parentI = (i - 1) >> 1;
|
||||
|
||||
a[i] = a[parentI];
|
||||
a[parentI] = e;
|
||||
i = parentI;
|
||||
}
|
||||
|
||||
pop();
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||
/***************************************************************************
|
||||
Copyright (C) 2007 by Nach
|
||||
http://nsrt.edgeemu.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License version 2 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 2 along with this program; if not, write to the
|
||||
Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
***************************************************************************/
|
||||
|
||||
#include "file.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static const unsigned int MAX_FILE_NAME = 512;
|
||||
|
||||
File::File(const char *filename) : stream(filename, ios::in | ios::binary), is_zip(false), fsize(0), count(0)
|
||||
{
|
||||
if (stream)
|
||||
{
|
||||
stream.seekg(0, ios::end);
|
||||
fsize = stream.tellg();
|
||||
stream.seekg(0, ios::beg);
|
||||
}
|
||||
}
|
||||
|
||||
File::~File()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void File::rewind()
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
stream.seekg(0, ios::beg);
|
||||
}
|
||||
}
|
||||
|
||||
bool File::is_open()
|
||||
{
|
||||
return(stream.is_open());
|
||||
}
|
||||
|
||||
void File::close()
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
void File::read(char *buffer, size_t amount)
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
stream.read(buffer, amount);
|
||||
count = stream.gcount();
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/***************************************************************************
|
||||
Copyright (C) 2007 by Nach
|
||||
http://nsrt.edgeemu.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License version 2 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 2 along with this program; if not, write to the
|
||||
Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
***************************************************************************/
|
||||
|
||||
#include <fstream>
|
||||
|
||||
class File {
|
||||
private:
|
||||
std::ifstream stream;
|
||||
bool is_zip; //Change this to an enum later
|
||||
std::size_t fsize, count;
|
||||
void *zipfile;
|
||||
bool zip_sub_open;
|
||||
|
||||
void zip(const char *filename);
|
||||
|
||||
public:
|
||||
File(const char *filename);
|
||||
~File();
|
||||
void rewind();
|
||||
bool is_open();
|
||||
void close();
|
||||
std::size_t size() const { return fsize; };
|
||||
void read(char *buffer, std::size_t amount);
|
||||
std::size_t gcount() const { return count; }
|
||||
bool fail() const { return stream.fail(); }
|
||||
};
|
|
@ -1,167 +0,0 @@
|
|||
/***************************************************************************
|
||||
Copyright (C) 2007 by Nach
|
||||
http://nsrt.edgeemu.com
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2 as
|
||||
published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License version 2 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
version 2 along with this program; if not, write to the
|
||||
Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
***************************************************************************/
|
||||
|
||||
#include "file.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace zlib {
|
||||
#include "unzip/unzip.h"
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
using namespace zlib;
|
||||
|
||||
static const unsigned int MAX_FILE_NAME = 512;
|
||||
|
||||
File::File(const char *filename) : stream(filename, ios::in | ios::binary), is_zip(false), fsize(0), count(0)
|
||||
{
|
||||
if (stream)
|
||||
{
|
||||
char temp[4];
|
||||
stream.read(temp, sizeof(temp));
|
||||
|
||||
//check for standard zip 'magic number'
|
||||
if ((temp[0] == 'P') && (temp[1] == 'K') && (temp[2] == 3) && (temp[3] == 4))
|
||||
{
|
||||
stream.close();
|
||||
is_zip = true;
|
||||
zip(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream.seekg(0, ios::end);
|
||||
fsize = stream.tellg();
|
||||
stream.seekg(0, ios::beg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void File::zip(const char *filename)
|
||||
{
|
||||
zipfile = unzOpen(filename);
|
||||
if (zipfile)
|
||||
{
|
||||
zip_sub_open = false;
|
||||
|
||||
unz_file_info cFileInfo;
|
||||
char ourFile[MAX_FILE_NAME] = { '\n' };
|
||||
|
||||
for (int cFile = unzGoToFirstFile((unzFile)zipfile); cFile == UNZ_OK; cFile = unzGoToNextFile((unzFile)zipfile))
|
||||
{
|
||||
//Temporary char array for file name
|
||||
char cFileName[MAX_FILE_NAME];
|
||||
|
||||
//Gets info on current file, and places it in cFileInfo
|
||||
unzGetCurrentFileInfo((unzFile)zipfile, &cFileInfo, cFileName, MAX_FILE_NAME, 0, 0, 0, 0);
|
||||
|
||||
//Check for largest file which should be the ROM
|
||||
if ((size_t)cFileInfo.uncompressed_size > fsize)
|
||||
{
|
||||
strcpy(ourFile, cFileName);
|
||||
fsize = (size_t)cFileInfo.uncompressed_size;
|
||||
}
|
||||
}
|
||||
|
||||
if (ourFile[0] != '\n')
|
||||
{
|
||||
//Sets current file to the file we liked before
|
||||
unzLocateFile((unzFile)zipfile, ourFile, 1);
|
||||
|
||||
if (unzOpenCurrentFile((unzFile)zipfile) == UNZ_OK)
|
||||
{
|
||||
zip_sub_open = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!zip_sub_open)
|
||||
{
|
||||
unzClose((unzFile)zipfile);
|
||||
zipfile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File::~File()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void File::rewind()
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
if (!is_zip)
|
||||
{
|
||||
stream.seekg(0, ios::beg);
|
||||
}
|
||||
else
|
||||
{
|
||||
unzCloseCurrentFile((unzFile)zipfile);
|
||||
unzOpenCurrentFile((unzFile)zipfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool File::is_open()
|
||||
{
|
||||
if (!is_zip)
|
||||
{
|
||||
return(stream.is_open());
|
||||
}
|
||||
return(zipfile && zip_sub_open);
|
||||
}
|
||||
|
||||
void File::close()
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
if (!is_zip)
|
||||
{
|
||||
stream.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
unzOpenCurrentFile((unzFile)zipfile);
|
||||
unzClose((unzFile)zipfile);
|
||||
zipfile = 0;
|
||||
zip_sub_open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void File::read(char *buffer, size_t amount)
|
||||
{
|
||||
if (is_open())
|
||||
{
|
||||
if (!is_zip)
|
||||
{
|
||||
stream.read(buffer, amount);
|
||||
count = stream.gcount();
|
||||
}
|
||||
else
|
||||
{
|
||||
count = (size_t)unzReadCurrentFile((unzFile)zipfile, buffer, amount);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const unsigned long* pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,177 +0,0 @@
|
|||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <zlib.h>
|
||||
#include "ioapi.h"
|
||||
|
||||
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func OF((
|
||||
voidpf opaque,
|
||||
const char* filename,
|
||||
int mode));
|
||||
|
||||
uLong ZCALLBACK fread_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size));
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size));
|
||||
|
||||
long ZCALLBACK ftell_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
long ZCALLBACK fseek_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin));
|
||||
|
||||
int ZCALLBACK fclose_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
int ZCALLBACK ferror_file_func OF((
|
||||
voidpf opaque,
|
||||
voidpf stream));
|
||||
|
||||
|
||||
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
|
||||
voidpf opaque;
|
||||
const char* filename;
|
||||
int mode;
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char* mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else
|
||||
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename!=NULL) && (mode_fopen != NULL))
|
||||
file = fopen(filename, mode_fopen);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
const void* buf;
|
||||
uLong size;
|
||||
{
|
||||
uLong ret;
|
||||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK ftell_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
long ret;
|
||||
ret = ftell((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
uLong offset;
|
||||
int origin;
|
||||
{
|
||||
int fseek_origin=0;
|
||||
long ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default: return -1;
|
||||
}
|
||||
ret = 0;
|
||||
fseek((FILE *)stream, offset, fseek_origin);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK fclose_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = fclose((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK ferror_file_func (opaque, stream)
|
||||
voidpf opaque;
|
||||
voidpf stream;
|
||||
{
|
||||
int ret;
|
||||
ret = ferror((FILE *)stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_fopen_filefunc (pzlib_filefunc_def)
|
||||
zlib_filefunc_def* pzlib_filefunc_def;
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#define _ZLIBIOAPI_H
|
||||
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
|
||||
#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
|
||||
|
||||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
|
||||
#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
|
||||
#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
|
||||
#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue