mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-08 17:28:49 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ea5ba171a | ||
|
|
fa876b10a3 | ||
|
|
3c58d10eae | ||
|
|
a3ee8c8849 | ||
|
|
5e14b302bc | ||
|
|
efe3f943d5 | ||
|
|
38e7fc6659 | ||
|
|
a1ceb534de | ||
|
|
0d897dd65d | ||
|
|
721d73f451 | ||
|
|
e8bd64e898 | ||
|
|
7da7ab2ce7 | ||
|
|
3f6183ff15 | ||
|
|
642316a1e2 | ||
|
|
21c6b75839 | ||
|
|
87d34deb0c | ||
|
|
1b3408919c | ||
|
|
23516572b7 | ||
|
|
924848fdad | ||
|
|
4c40e56060 | ||
|
|
cf34444505 | ||
|
|
9ca5e4e470 | ||
|
|
32f2689b6a | ||
|
|
13ae61031f | ||
|
|
1ced96c5e9 | ||
|
|
0d905eb3f6 | ||
|
|
32a5460ea7 | ||
|
|
be5acff69c | ||
|
|
1b0ef5793e | ||
|
|
2bd0caae2e | ||
|
|
3045f2c478 | ||
|
|
1282a142d6 | ||
|
|
ac1a539d22 | ||
|
|
6f47775239 | ||
|
|
0823d72dee | ||
|
|
407ad94f58 | ||
|
|
b2b103362d | ||
|
|
231680944f | ||
|
|
ec7dab05e8 | ||
|
|
9588f6061f | ||
|
|
57c25dcb0b | ||
|
|
38763c4554 | ||
|
|
fac2ea00dd | ||
|
|
74782a1bea | ||
|
|
c1265e7227 | ||
|
|
f0841256e8 | ||
|
|
600efab1bd | ||
|
|
dc9dd2e6bf | ||
|
|
de8fe0e88c | ||
|
|
338432c35f | ||
|
|
11aeb05a6e | ||
|
|
e28a32d922 | ||
|
|
edac39cb2b | ||
|
|
c1954aa4a6 | ||
|
|
ef048fcfd5 | ||
|
|
48a1531d7c | ||
|
|
4b4686ae04 | ||
|
|
cb4a54fefe | ||
|
|
131b2386cd | ||
|
|
4d6d01228c | ||
|
|
a050955113 | ||
|
|
b02789d280 | ||
|
|
6f92d0588d | ||
|
|
45df48ab67 | ||
|
|
aba5c7722e | ||
|
|
07a1a1ee2f | ||
|
|
3b952973de | ||
|
|
ac4adebdf6 | ||
|
|
1bfd9716c5 | ||
|
|
702cf9c804 | ||
|
|
5993fffb64 | ||
|
|
58758d2818 | ||
|
|
21f88fcf39 | ||
|
|
e3f029a446 | ||
|
|
0694d8884f | ||
|
|
0730a34a5b | ||
|
|
f827bb4cbd | ||
|
|
eafd8d91d7 | ||
|
|
56a4d1ddac | ||
|
|
8d3f15602c | ||
|
|
7877c7939d | ||
|
|
c55263b956 | ||
|
|
96ce288120 | ||
|
|
e5326467a1 | ||
|
|
596d8d9985 | ||
|
|
b4b0be9118 | ||
|
|
00e5f0fe97 | ||
|
|
cb140c3691 | ||
|
|
ad85ccb42f | ||
|
|
97e50f15de | ||
|
|
071c03e194 | ||
|
|
6f47c21ce9 | ||
|
|
68bfda24ff | ||
|
|
4f2fbcb9bc | ||
|
|
90ab5dfc2f | ||
|
|
362cbe5deb | ||
|
|
e133662346 | ||
|
|
1fe83ab25a | ||
|
|
1d95b5ee22 | ||
|
|
9dc603d405 | ||
|
|
5cb2863e6e | ||
|
|
98cf4223ab | ||
|
|
ff7843cbe9 | ||
|
|
c4d6b0b7c1 | ||
|
|
fb739621ac | ||
|
|
24e8ca6856 | ||
|
|
1ff9b6a375 | ||
|
|
cb6086635c | ||
|
|
bce679df78 | ||
|
|
22e8c3d895 | ||
|
|
d2b06a92c5 | ||
|
|
3901934d97 | ||
|
|
a76b25aff9 | ||
|
|
343852af26 | ||
|
|
4395f124ca | ||
|
|
b16ff3024c | ||
|
|
bc23b421e1 | ||
|
|
d9cb85a8d5 | ||
|
|
7d1cc23d16 | ||
|
|
4496ed3c13 | ||
|
|
3f5b6a450e | ||
|
|
9e24474047 | ||
|
|
7c17ede1ef | ||
|
|
5d9805c3e5 | ||
|
|
b17617bed5 | ||
|
|
a405708f1c | ||
|
|
594e66704d | ||
|
|
50579aaeea | ||
|
|
38eb855b48 | ||
|
|
12cc85c8a5 | ||
|
|
5b12595c85 | ||
|
|
3753f0bfca | ||
|
|
14ae5e397a | ||
|
|
657b4ce8c7 | ||
|
|
777e6a5334 | ||
|
|
a2ec78320b | ||
|
|
1fb53627ac | ||
|
|
fc2a39cd58 | ||
|
|
7425e1f879 | ||
|
|
6a260a57dd | ||
|
|
dadd794ece | ||
|
|
706a3738b5 | ||
|
|
9aef33aabd | ||
|
|
ac4219bcde | ||
|
|
b337856f80 | ||
|
|
079a0100c0 | ||
|
|
014c3c90e0 | ||
|
|
4759e3411f | ||
|
|
4a05e50636 | ||
|
|
72c070f338 | ||
|
|
776291a137 | ||
|
|
f3cdb95b04 | ||
|
|
033860ceb9 | ||
|
|
ab601ee3dc | ||
|
|
783ab7acd5 | ||
|
|
19a46b1f8b | ||
|
|
508cfdbda7 | ||
|
|
d81b9ee0a7 | ||
|
|
36c6c21194 | ||
|
|
1631e940f6 | ||
|
|
2eeb1fa6d1 | ||
|
|
26ac00ad76 | ||
|
|
bafc4f596f | ||
|
|
eee89dddb1 | ||
|
|
089b4fbba0 | ||
|
|
80727cef5a | ||
|
|
346a9f2b4e | ||
|
|
363d8ca5b4 | ||
|
|
06a574225d | ||
|
|
fa777b8356 | ||
|
|
7cf01318cb | ||
|
|
7c538274b4 | ||
|
|
72fb694e97 | ||
|
|
59c92dddc3 | ||
|
|
3f60fdd106 | ||
|
|
d221c480e6 | ||
|
|
59d9ff0d29 | ||
|
|
d279ea79e8 | ||
|
|
77cf9423cc | ||
|
|
60b94bbe43 | ||
|
|
b6272f9653 | ||
|
|
25fce1a6c6 | ||
|
|
59229f99c5 |
No files matched your search
@@ -3,3 +3,6 @@ Hans-Kristian Arntzen - <[email protected]>
|
||||
|
||||
Devin J. Pohly - <[email protected]>
|
||||
- Joypad axis support
|
||||
|
||||
Chris Moeller - <[email protected]>
|
||||
- CoreAudio audio driver
|
||||
@@ -2,14 +2,14 @@ include config.mk
|
||||
|
||||
TARGET = ssnes tools/ssnes-joyconfig
|
||||
|
||||
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o strl.o screenshot.o
|
||||
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
|
||||
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o
|
||||
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o strl.o
|
||||
HEADERS = $(wildcard */*.h) $(wildcard *.h)
|
||||
|
||||
LIBS = -lm
|
||||
DEFINES = -DHAVE_CONFIG_H
|
||||
|
||||
ifneq ($(findstring Darwin,$(shell uname -a)),)
|
||||
ifneq ($(findstring Darwin,$(OS)),)
|
||||
OSX := 1
|
||||
LIBS += -framework AppKit
|
||||
else
|
||||
@@ -18,7 +18,7 @@ endif
|
||||
|
||||
BSD_LOCAL_INC =
|
||||
DYLIB_LIB = -ldl
|
||||
ifneq ($(findstring BSD,$(shell uname -a)),)
|
||||
ifneq ($(findstring BSD,$(OS)),)
|
||||
BSD_LOCAL_INC = -I/usr/local/include
|
||||
DYLIB_LIB = -lc
|
||||
endif
|
||||
@@ -40,7 +40,8 @@ endif
|
||||
|
||||
ifeq ($(HAVE_RSOUND), 1)
|
||||
OBJ += audio/rsound.o
|
||||
LIBS += -lrsound
|
||||
LIBS += $(RSOUND_LIBS)
|
||||
DEFINES += $(RSOUND_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_OSS), 1)
|
||||
@@ -55,11 +56,13 @@ endif
|
||||
|
||||
ifeq ($(HAVE_ALSA), 1)
|
||||
OBJ += audio/alsa.o
|
||||
LIBS += -lasound
|
||||
LIBS += $(ALSA_LIBS)
|
||||
DEFINES += $(ALSA_CFLAGS)
|
||||
endif
|
||||
ifeq ($(HAVE_ROAR), 1)
|
||||
OBJ += audio/roar.o
|
||||
LIBS += -lroar
|
||||
LIBS += $(ROAR_LIBS)
|
||||
DEFINES += $(ROAR_CFLAGS)
|
||||
endif
|
||||
ifeq ($(HAVE_AL), 1)
|
||||
OBJ += audio/openal.o
|
||||
@@ -80,8 +83,13 @@ ifeq ($(HAVE_PULSE), 1)
|
||||
DEFINES += $(PULSE_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_COREAUDIO), 1)
|
||||
OBJ += audio/coreaudio.o
|
||||
LIBS += -framework CoreServices -framework CoreAudio -framework AudioUnit
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_SDL), 1)
|
||||
OBJ += gfx/sdl.o gfx/gl.o input/sdl.o audio/sdl.o fifo_buffer.o
|
||||
OBJ += gfx/sdl.o gfx/gl.o gfx/sdlwrap.o input/sdl.o audio/sdl.o fifo_buffer.o
|
||||
DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC)
|
||||
LIBS += $(SDL_LIBS)
|
||||
ifeq ($(OSX),1)
|
||||
@@ -93,7 +101,8 @@ endif
|
||||
|
||||
ifeq ($(HAVE_XVIDEO), 1)
|
||||
OBJ += gfx/xvideo.o input/x11_input.o
|
||||
LIBS += -lX11 -lXext -lXv
|
||||
LIBS += $(XVIDEO_LIBS)
|
||||
DEFINES += $(XVIDEO_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_CG), 1)
|
||||
@@ -163,11 +172,11 @@ config.mk: configure qb/*
|
||||
@exit 1
|
||||
|
||||
ssnes: $(OBJ)
|
||||
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
|
||||
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
tools/ssnes-joyconfig: $(JOYCONFIG_OBJ)
|
||||
$(Q)$(CC) -o $@ $(JOYCONFIG_OBJ) $(SDL_LIBS) $(LDFLAGS)
|
||||
$(Q)$(CC) -o $@ $(JOYCONFIG_OBJ) $(SDL_LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
%.o: %.c config.h config.mk $(HEADERS)
|
||||
|
||||
@@ -1,46 +1,40 @@
|
||||
TARGET = ssnes.exe
|
||||
JTARGET = ssnes-joyconfig.exe
|
||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o strl.o screenshot.o
|
||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
|
||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o
|
||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o strl.o
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
|
||||
HAVE_DINPUT = 1
|
||||
HAVE_SRC = 0
|
||||
HAVE_SDL = 1
|
||||
HAVE_SDL_IMAGE = 1
|
||||
HAVE_XML = 1
|
||||
HAVE_FREETYPE = 1
|
||||
HAVE_XAUDIO = 1
|
||||
HAVE_RSOUND = 1
|
||||
HAVE_DSOUND = 1
|
||||
HAVE_SDL = 1
|
||||
HAVE_DYLIB = 1
|
||||
HAVE_NETPLAY = 1
|
||||
HAVE_FBO = 1
|
||||
HAVE_CG = 1
|
||||
HAVE_PYTHON = 1
|
||||
HAVE_FFMPEG = 0
|
||||
libsnes ?= -lsnes
|
||||
|
||||
LIBS = -lm
|
||||
DEFINES = -I. -DHAVE_CONFIGFILE
|
||||
LDFLAGS = -L. -static-libgcc -s
|
||||
|
||||
SRC_LIBS = -lsamplerate-0
|
||||
SDL_LIBS = -lSDL
|
||||
SDL_CFLAGS = -ISDL
|
||||
|
||||
ifeq ($(HAVE_SRC), 1)
|
||||
LIBS += $(SRC_LIBS)
|
||||
DEFINES += $(SRC_CFLAGS) -DHAVE_SRC
|
||||
else
|
||||
OBJ += audio/hermite.o
|
||||
ifeq ($(SLIM),)
|
||||
HAVE_SDL_IMAGE = 1
|
||||
HAVE_XML = 1
|
||||
HAVE_FREETYPE = 1
|
||||
HAVE_RSOUND = 1
|
||||
HAVE_FBO = 1
|
||||
HAVE_CG = 1
|
||||
HAVE_PYTHON = 1
|
||||
HAVE_FFMPEG = 1
|
||||
endif
|
||||
|
||||
libsnes ?= -lsnes
|
||||
|
||||
LIBS = -lm -lshlwapi
|
||||
DEFINES = -I. -DHAVE_CONFIGFILE
|
||||
LDFLAGS = -L. -static-libgcc -s
|
||||
LDCXXFLAGS = -static-libstdc++
|
||||
|
||||
ifeq ($(HAVE_SDL), 1)
|
||||
OBJ += gfx/sdl.o gfx/gl.o input/sdl.o audio/sdl.o fifo_buffer.o
|
||||
LIBS += $(SDL_LIBS) -lopengl32
|
||||
DEFINES += $(SDL_CFLAGS) -DHAVE_SDL
|
||||
OBJ += gfx/sdl.o gfx/gl.o gfx/sdlwrap.o input/sdl.o audio/sdl.o fifo_buffer.o
|
||||
LIBS += -lSDL -lopengl32
|
||||
DEFINES += -ISDL -DHAVE_SDL
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_SDL_IMAGE), 1)
|
||||
@@ -55,8 +49,15 @@ ifeq ($(HAVE_CG), 1)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_XAUDIO), 1)
|
||||
OBJ += audio/xaudio.o
|
||||
OBJ += audio/xaudio.o audio/xaudio-c/xaudio-c.o
|
||||
DEFINES += -DHAVE_XAUDIO
|
||||
LIBS += -lole32
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_DSOUND), 1)
|
||||
OBJ += audio/dsound.o
|
||||
DEFINES += -DHAVE_DSOUND
|
||||
LIBS += -ldxguid -ldsound
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_RSOUND), 1)
|
||||
@@ -67,8 +68,8 @@ endif
|
||||
|
||||
ifeq ($(HAVE_XML), 1)
|
||||
OBJ += gfx/shader_glsl.o gfx/image.o gfx/snes_state.o sha256.o cheats.o
|
||||
DEFINES += $(XML_CFLAGS) -DHAVE_XML
|
||||
LIBS += -lxml2
|
||||
DEFINES += -Ilibxml2 -DHAVE_XML
|
||||
LIBS += -lxml2 -liconv
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_DYLIB), 1)
|
||||
@@ -84,7 +85,7 @@ endif
|
||||
ifeq ($(HAVE_FREETYPE), 1)
|
||||
OBJ += gfx/fonts.o
|
||||
DEFINES += -DHAVE_FREETYPE -Ifreetype2
|
||||
LIBS += -lz -lfreetype6
|
||||
LIBS += -lfreetype -lz
|
||||
endif
|
||||
|
||||
ifeq ($(DYNAMIC), 1)
|
||||
@@ -109,13 +110,13 @@ endif
|
||||
|
||||
ifeq ($(HAVE_DINPUT), 1)
|
||||
LIBS += -ldinput8 -ldxguid -lole32
|
||||
DEFINES += -DHAVE_DINPUT -Iffmpeg
|
||||
DEFINES += -DHAVE_DINPUT
|
||||
OBJ += input/dinput.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FFMPEG), 1)
|
||||
LIBS += -lavformat -lavcodec -lavutil -lswscale -lws2_32 -lzlib1
|
||||
DEFINES += -DHAVE_FFMPEG
|
||||
LIBS += -lavformat -lavcodec -lavutil -lswscale -lws2_32 -lz
|
||||
DEFINES += -DHAVE_FFMPEG -Iffmpeg
|
||||
OBJ += record/ffemu.o
|
||||
endif
|
||||
|
||||
@@ -123,42 +124,53 @@ ifneq ($(V),1)
|
||||
Q := @
|
||||
endif
|
||||
|
||||
|
||||
CFLAGS = -Wall -O3 -std=gnu99 -I.
|
||||
CFLAGS += -Wall -O3 -std=gnu99 -I.
|
||||
CXXFLAGS += -Wall -O3 -pedantic -I.
|
||||
|
||||
all: $(TARGET) $(JTARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
|
||||
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) $(LDCXXFLAGS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
%.o: %.c
|
||||
$(Q)$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||
@$(if $(Q), $(shell echo echo CC $<),)
|
||||
|
||||
%.o: %.cpp
|
||||
$(Q)$(CXX) $(CXXFLAGS) $(DEFINES) -c -o $@ $<
|
||||
@$(if $(Q), $(shell echo echo CXX $<),)
|
||||
|
||||
|
||||
$(JTARGET): $(JOBJ)
|
||||
$(Q)$(CC) -o $@ $(JOBJ) $(SDL_LIBS) $(LDFLAGS)
|
||||
$(Q)$(CC) -o $@ $(JOBJ) -lSDL $(LDFLAGS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f audio/*.o
|
||||
rm -f audio/xaudio-c/*.o
|
||||
rm -f conf/*.o
|
||||
rm -f gfx/*.o
|
||||
rm -f gfx/py_state/*.o
|
||||
rm -f record/*.o
|
||||
rm -f hqflt/*.o
|
||||
rm -f input/*.o
|
||||
rm -f hqflt/snes_ntsc/*.o
|
||||
rm -f $(TARGET)
|
||||
rm -f ssnes-joyconfig.exe
|
||||
rm -f tools/*.o
|
||||
|
||||
dist: all
|
||||
zip -r ssnes-win32-0.6.zip $(TARGET) ssnes.cfg snes.dll libxml2.dll iconv.dll zlib1.dll SDL.dll freetype6.dll xaudio-c.dll rsound.dll pthreadGC2.dll cg.dll cgGL.dll libjpeg-8.dll libpng15-15.dll python32.dll SDL_image.dll $(JTARGET)
|
||||
dist_x86: all
|
||||
zip -r ssnes-win32-0.8.2.zip $(TARGET) $(JTARGET) ssnes.cfg snes.dll SDL.dll
|
||||
|
||||
libs:
|
||||
dist_x86_64: all
|
||||
zip -r ssnes-win64-0.8.2.zip $(TARGET) $(JTARGET) ssnes.cfg snes.dll SDL.dll
|
||||
|
||||
libs_x86:
|
||||
wget https://github.com/downloads/Themaister/SSNES/SSNES-win32-libs.zip --no-check-certificate
|
||||
unzip SSNES-win32-libs.zip
|
||||
|
||||
.PHONY: all install uninstall clean dist libs
|
||||
libs_x86_64:
|
||||
wget https://github.com/downloads/Themaister/SSNES/SSNES-win64-libs.zip --no-check-certificate
|
||||
unzip SSNES-win64-libs.zip
|
||||
|
||||
.PHONY: all install uninstall clean dist_x86 dist_x86_64 libs_x86 libs_x86_64
|
||||
-151
@@ -1,151 +0,0 @@
|
||||
TARGET = ssnes.exe
|
||||
JTARGET = ssnes-joyconfig.exe
|
||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o strl.o screenshot.o
|
||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
|
||||
HAVE_DINPUT = 1
|
||||
HAVE_SRC = 0
|
||||
HAVE_SDL = 1
|
||||
HAVE_XML = 1
|
||||
HAVE_FREETYPE = 1
|
||||
HAVE_XAUDIO = 1
|
||||
HAVE_RSOUND = 0
|
||||
HAVE_DYLIB = 1
|
||||
HAVE_NETPLAY = 1
|
||||
HAVE_FBO = 1
|
||||
HAVE_CG = 0
|
||||
HAVE_PYTHON = 0
|
||||
libsnes ?= -lsnes
|
||||
|
||||
LIBS = -lm
|
||||
DEFINES = -I. -DHAVE_CONFIGFILE
|
||||
LDFLAGS = -L. -static-libgcc -s
|
||||
|
||||
SRC_LIBS = -lsamplerate-0
|
||||
SDL_LIBS = -lmingw32 -lSDL -lSDLmain -lwinmm -mwindows -lm -luser32 -lgdi32 -lwinmm -ldxguid
|
||||
SDL_CFLAGS = -ISDL
|
||||
|
||||
ifeq ($(HAVE_SRC), 1)
|
||||
LIBS += $(SRC_LIBS)
|
||||
DEFINES += $(SRC_CFLAGS) -DHAVE_SRC
|
||||
else
|
||||
OBJ += audio/hermite.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_SDL), 1)
|
||||
OBJ += gfx/sdl.o gfx/gl.o input/sdl.o audio/sdl.o fifo_buffer.o
|
||||
LIBS += $(SDL_LIBS) -lopengl32
|
||||
DEFINES += $(SDL_CFLAGS) -DHAVE_SDL
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_CG), 1)
|
||||
OBJ += gfx/shader_cg.o
|
||||
LIBS += -lcg -lcgGL
|
||||
DEFINES += -DHAVE_CG
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_XAUDIO), 1)
|
||||
OBJ += audio/xaudio.o
|
||||
DEFINES += -DHAVE_XAUDIO
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_RSOUND), 1)
|
||||
OBJ += audio/rsound.o
|
||||
DEFINES += -DHAVE_RSOUND
|
||||
LIBS += -lrsound
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_XML), 1)
|
||||
OBJ += gfx/shader_glsl.o gfx/image.o gfx/snes_state.o sha256.o cheats.o
|
||||
DEFINES += $(XML_CFLAGS) -DHAVE_XML -DLIBXML_STATIC
|
||||
LIBS += -lxml2 -lz -lws2_32
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_DYLIB), 1)
|
||||
DEFINES += -DHAVE_DYLIB
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_NETPLAY), 1)
|
||||
DEFINES += -DHAVE_NETPLAY
|
||||
OBJ += netplay.o
|
||||
LIBS += -lws2_32
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FREETYPE), 1)
|
||||
OBJ += gfx/fonts.o
|
||||
DEFINES += -DHAVE_FREETYPE -Ifreetype2
|
||||
LIBS += -lz -lfreetype6
|
||||
endif
|
||||
|
||||
ifeq ($(DYNAMIC), 1)
|
||||
DEFINES += -DHAVE_DYNAMIC
|
||||
else
|
||||
LIBS += $(libsnes)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FBO), 1)
|
||||
DEFINES += -DHAVE_FBO
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_DYLIB), 1)
|
||||
OBJ += gfx/ext.o audio/ext.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_PYTHON), 1)
|
||||
LIBS += -lpython32
|
||||
DEFINES += -DHAVE_PYTHON -Ipython
|
||||
OBJ += gfx/py_state/py_state.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_DINPUT), 1)
|
||||
LIBS += -ldinput8 -ldxguid -lole32
|
||||
DEFINES += -DHAVE_DINPUT
|
||||
OBJ += input/dinput.o
|
||||
endif
|
||||
|
||||
|
||||
ifneq ($(V),1)
|
||||
Q := @
|
||||
endif
|
||||
|
||||
|
||||
CFLAGS = -Wall -O3 -std=gnu99 -I.
|
||||
|
||||
all: $(TARGET) $(JTARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
%.o: %.c
|
||||
$(Q)$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
|
||||
@$(if $(Q), $(shell echo echo CC $<),)
|
||||
|
||||
$(JTARGET): $(JOBJ)
|
||||
$(Q)$(CC) -o $@ $(JOBJ) $(SDL_LIBS) $(LDFLAGS)
|
||||
@$(if $(Q), $(shell echo echo LD $@),)
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f audio/*.o
|
||||
rm -f conf/*.o
|
||||
rm -f gfx/*.o
|
||||
rm -f record/*.o
|
||||
rm -f hqflt/*.o
|
||||
rm -f input/*.o
|
||||
rm -f hqflt/snes_ntsc/*.o
|
||||
rm -f $(TARGET)
|
||||
rm -f ssnes-joyconfig.exe
|
||||
rm -f tools/*.o
|
||||
|
||||
dist: all
|
||||
zip -r ssnes-win64-0.6.zip $(TARGET) ssnes.cfg snes.dll xaudio-c.dll README.win32.txt $(JTARGET)
|
||||
|
||||
libs:
|
||||
wget https://github.com/downloads/Themaister/SSNES/ssnes-win64-libs.zip --no-check-certificate
|
||||
unzip ssnes-win64-libs.zip
|
||||
|
||||
.PHONY: all install uninstall clean dist libs
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
|
||||
#include "driver.h"
|
||||
#include <stdlib.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <asoundlib.h>
|
||||
#include "general.h"
|
||||
|
||||
#define TRY_ALSA(x) if ( x < 0 ) { \
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011 - Chris Moeller
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
#include "fifo_buffer.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <CoreAudio/CoreAudio.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
#include <AudioUnit/AUComponent.h>
|
||||
|
||||
typedef struct coreaudio
|
||||
{
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t cond;
|
||||
|
||||
ComponentInstance dev;
|
||||
bool dev_alive;
|
||||
|
||||
fifo_buffer_t *buffer;
|
||||
bool nonblock;
|
||||
} coreaudio_t;
|
||||
|
||||
static void coreaudio_free(void *data)
|
||||
{
|
||||
coreaudio_t *dev = data;
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
if (dev->dev_alive)
|
||||
{
|
||||
AudioOutputUnitStop(dev->dev);
|
||||
CloseComponent(dev->dev);
|
||||
}
|
||||
|
||||
if (dev->buffer)
|
||||
fifo_free(dev->buffer);
|
||||
|
||||
pthread_mutex_destroy(&dev->lock);
|
||||
pthread_cond_destroy(&dev->cond);
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
static OSStatus audio_cb(void *userdata, AudioUnitRenderActionFlags *action_flags,
|
||||
const AudioTimeStamp *time_stamp, UInt32 bus_number,
|
||||
UInt32 number_frames, AudioBufferList *io_data)
|
||||
{
|
||||
coreaudio_t *dev = userdata;
|
||||
(void)time_stamp;
|
||||
(void)bus_number;
|
||||
(void)number_frames;
|
||||
|
||||
if (!io_data)
|
||||
return noErr;
|
||||
if (io_data->mNumberBuffers != 1)
|
||||
return noErr;
|
||||
|
||||
unsigned write_avail = io_data->mBuffers[0].mDataByteSize;
|
||||
void *outbuf = io_data->mBuffers[0].mData;
|
||||
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
if (fifo_read_avail(dev->buffer) < write_avail)
|
||||
{
|
||||
*action_flags = kAudioUnitRenderAction_OutputIsSilence;
|
||||
memset(outbuf, 0, write_avail); // Seems to be needed.
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
pthread_cond_signal(&dev->cond); // Technically possible to deadlock without.
|
||||
return noErr;
|
||||
}
|
||||
|
||||
fifo_read(dev->buffer, outbuf, write_avail);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
pthread_cond_signal(&dev->cond);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
static void* coreaudio_init(const char* device, unsigned rate, unsigned latency)
|
||||
{
|
||||
(void)device;
|
||||
|
||||
coreaudio_t *dev = calloc(1, sizeof(*dev));
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
CFRunLoopRef run_loop = NULL;
|
||||
AudioObjectPropertyAddress addr = {
|
||||
kAudioHardwarePropertyRunLoop,
|
||||
kAudioObjectPropertyScopeGlobal,
|
||||
kAudioObjectPropertyElementMaster
|
||||
};
|
||||
|
||||
pthread_mutex_init(&dev->lock, NULL);
|
||||
pthread_cond_init(&dev->cond, NULL);
|
||||
AudioObjectSetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL,
|
||||
sizeof(CFRunLoopRef), &run_loop);
|
||||
|
||||
ComponentDescription desc = {
|
||||
.componentType = kAudioUnitType_Output,
|
||||
.componentSubType = kAudioUnitSubType_HALOutput,
|
||||
.componentManufacturer = kAudioUnitManufacturer_Apple,
|
||||
};
|
||||
|
||||
Component comp = FindNextComponent(NULL, &desc);
|
||||
if (comp == NULL)
|
||||
goto error;
|
||||
|
||||
OSStatus res = OpenAComponent(comp, &dev->dev);
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
dev->dev_alive = true;
|
||||
|
||||
AudioStreamBasicDescription stream_desc = {
|
||||
.mSampleRate = rate,
|
||||
.mBitsPerChannel = sizeof(float) * CHAR_BIT,
|
||||
.mChannelsPerFrame = 2,
|
||||
.mBytesPerPacket = 2 * sizeof(float),
|
||||
.mBytesPerFrame = 2 * sizeof(float),
|
||||
.mFramesPerPacket = 1,
|
||||
.mFormatID = kAudioFormatLinearPCM,
|
||||
.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | (is_little_endian() ? 0 : kAudioFormatFlagIsBigEndian),
|
||||
};
|
||||
|
||||
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &stream_desc, sizeof(stream_desc));
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
AudioStreamBasicDescription real_desc;
|
||||
UInt32 i_size = sizeof(real_desc);
|
||||
res = AudioUnitGetProperty(dev->dev, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &real_desc, &i_size);
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
SSNES_LOG("[CoreAudio]: Using output sample rate of %.1f Hz\n", (float)real_desc.mSampleRate);
|
||||
g_settings.audio.out_rate = real_desc.mSampleRate;
|
||||
|
||||
if (real_desc.mChannelsPerFrame != stream_desc.mChannelsPerFrame)
|
||||
goto error;
|
||||
if (real_desc.mBitsPerChannel != stream_desc.mBitsPerChannel)
|
||||
goto error;
|
||||
if (real_desc.mFormatFlags != stream_desc.mFormatFlags)
|
||||
goto error;
|
||||
if (real_desc.mFormatID != stream_desc.mFormatID)
|
||||
goto error;
|
||||
|
||||
AudioChannelLayout layout = {
|
||||
.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelBitmap,
|
||||
.mChannelBitmap = (1 << 2) - 1,
|
||||
};
|
||||
|
||||
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_AudioChannelLayout,
|
||||
kAudioUnitScope_Input, 0, &layout, sizeof(layout));
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
AURenderCallbackStruct cb = {
|
||||
.inputProc = audio_cb,
|
||||
.inputProcRefCon = dev,
|
||||
};
|
||||
|
||||
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_SetRenderCallback,
|
||||
kAudioUnitScope_Input, 0, &cb, sizeof(cb));
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
res = AudioUnitInitialize(dev->dev);
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
size_t fifo_size = (latency * g_settings.audio.out_rate) / 1000;
|
||||
fifo_size *= 2 * sizeof(float);
|
||||
|
||||
dev->buffer = fifo_new(fifo_size);
|
||||
if (!dev->buffer)
|
||||
goto error;
|
||||
|
||||
SSNES_LOG("[CoreAudio]: Using buffer size of %u bytes: (latency = %u ms)\n", (unsigned)fifo_size, latency);
|
||||
|
||||
res = AudioOutputUnitStart(dev->dev);
|
||||
if (res != noErr)
|
||||
goto error;
|
||||
|
||||
return dev;
|
||||
|
||||
error:
|
||||
SSNES_ERR("[CoreAudio]: Failed to initialize driver ...\n");
|
||||
coreaudio_free(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ssize_t coreaudio_write(void* data, const void* buf_, size_t size)
|
||||
{
|
||||
coreaudio_t *dev = data;
|
||||
|
||||
const uint8_t *buf = buf_;
|
||||
size_t written = 0;
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
pthread_mutex_lock(&dev->lock);
|
||||
|
||||
size_t write_avail = fifo_write_avail(dev->buffer);
|
||||
if (write_avail > size)
|
||||
write_avail = size;
|
||||
|
||||
fifo_write(dev->buffer, buf, write_avail);
|
||||
buf += write_avail;
|
||||
written += write_avail;
|
||||
size -= write_avail;
|
||||
|
||||
if (dev->nonblock)
|
||||
{
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
break;
|
||||
}
|
||||
|
||||
if (write_avail == 0)
|
||||
pthread_cond_wait(&dev->cond, &dev->lock);
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
static bool coreaudio_stop(void *data)
|
||||
{
|
||||
coreaudio_t *dev = data;
|
||||
return AudioOutputUnitStop(dev->dev) == noErr;
|
||||
}
|
||||
|
||||
static void coreaudio_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
coreaudio_t *dev = data;
|
||||
dev->nonblock = state;
|
||||
}
|
||||
|
||||
static bool coreaudio_start(void *data)
|
||||
{
|
||||
coreaudio_t *dev = data;
|
||||
return AudioOutputUnitStart(dev->dev) == noErr;
|
||||
}
|
||||
|
||||
static bool coreaudio_use_float(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
const audio_driver_t audio_coreaudio = {
|
||||
.init = coreaudio_init,
|
||||
.write = coreaudio_write,
|
||||
.stop = coreaudio_stop,
|
||||
.start = coreaudio_start,
|
||||
.set_nonblock_state = coreaudio_set_nonblock_state,
|
||||
.free = coreaudio_free,
|
||||
.use_float = coreaudio_use_float,
|
||||
.ident = "coreaudio"
|
||||
};
|
||||
|
||||
+387
@@ -0,0 +1,387 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "driver.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <dsound.h>
|
||||
#include "fifo_buffer.h"
|
||||
#include "general.h"
|
||||
|
||||
typedef struct dsound
|
||||
{
|
||||
LPDIRECTSOUND ds;
|
||||
LPDIRECTSOUNDBUFFER dsb;
|
||||
HANDLE event;
|
||||
bool nonblock;
|
||||
|
||||
fifo_buffer_t *buffer;
|
||||
CRITICAL_SECTION crit;
|
||||
|
||||
volatile bool thread_alive;
|
||||
HANDLE thread;
|
||||
unsigned buffer_size;
|
||||
} dsound_t;
|
||||
|
||||
static inline unsigned write_avail(unsigned read_ptr, unsigned write_ptr, unsigned buffer_size)
|
||||
{
|
||||
return (read_ptr + buffer_size - write_ptr) % buffer_size;
|
||||
}
|
||||
|
||||
static inline void get_positions(dsound_t *ds, DWORD *read_ptr, DWORD *write_ptr)
|
||||
{
|
||||
IDirectSoundBuffer_GetCurrentPosition(ds->dsb, read_ptr, write_ptr);
|
||||
}
|
||||
|
||||
#define CHUNK_SIZE 256
|
||||
|
||||
struct audio_lock
|
||||
{
|
||||
void *chunk1;
|
||||
DWORD size1;
|
||||
void *chunk2;
|
||||
DWORD size2;
|
||||
};
|
||||
|
||||
static inline bool grab_region(dsound_t *ds, DWORD write_ptr, struct audio_lock *region)
|
||||
{
|
||||
HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0);
|
||||
if (res == DSERR_BUFFERLOST)
|
||||
{
|
||||
res = IDirectSoundBuffer_Restore(ds->dsb);
|
||||
if (res != DS_OK)
|
||||
return false;
|
||||
|
||||
res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0);
|
||||
if (res != DS_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *err;
|
||||
switch (res)
|
||||
{
|
||||
case DSERR_BUFFERLOST:
|
||||
err = "DSERR_BUFFERLOST";
|
||||
break;
|
||||
case DSERR_INVALIDCALL:
|
||||
err = "DSERR_INVALIDCALL";
|
||||
break;
|
||||
case DSERR_INVALIDPARAM:
|
||||
err = "DSERR_INVALIDPARAM";
|
||||
break;
|
||||
case DSERR_PRIOLEVELNEEDED:
|
||||
err = "DSERR_PRIOLEVELNEEDED";
|
||||
break;
|
||||
|
||||
default:
|
||||
err = NULL;
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
SSNES_WARN("[DirectSound error]: %s\n", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void release_region(dsound_t *ds, const struct audio_lock *region)
|
||||
{
|
||||
IDirectSoundBuffer_Unlock(ds->dsb, region->chunk1, region->size1, region->chunk2, region->size2);
|
||||
}
|
||||
|
||||
static DWORD CALLBACK dsound_thread(PVOID data)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
||||
|
||||
DWORD write_ptr;
|
||||
get_positions(ds, NULL, &write_ptr);
|
||||
write_ptr = (write_ptr + ds->buffer_size / 2) % ds->buffer_size;
|
||||
|
||||
while (ds->thread_alive)
|
||||
{
|
||||
DWORD read_ptr;
|
||||
get_positions(ds, &read_ptr, NULL);
|
||||
|
||||
DWORD avail = write_avail(read_ptr, write_ptr, ds->buffer_size);
|
||||
|
||||
EnterCriticalSection(&ds->crit);
|
||||
DWORD fifo_avail = fifo_read_avail(ds->buffer);
|
||||
LeaveCriticalSection(&ds->crit);
|
||||
|
||||
// No space to write, or we don't have data in our fifo, but we can wait some time before it underruns ...
|
||||
if (avail < CHUNK_SIZE || ((fifo_avail < CHUNK_SIZE) && (avail < ds->buffer_size / 2)))
|
||||
{
|
||||
Sleep(1);
|
||||
// We could opt for using the notification interface,
|
||||
// but it is not guaranteed to work, so use high priority sleeping patterns. :(
|
||||
}
|
||||
else if (fifo_avail < CHUNK_SIZE) // Got space to write, but nothing in FIFO (underrun), fill block with silence.
|
||||
{
|
||||
struct audio_lock region;
|
||||
if (!grab_region(ds, write_ptr, ®ion))
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
SetEvent(ds->event);
|
||||
break;
|
||||
}
|
||||
|
||||
memset(region.chunk1, 0, region.size1);
|
||||
memset(region.chunk2, 0, region.size2);
|
||||
|
||||
release_region(ds, ®ion);
|
||||
write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size;
|
||||
}
|
||||
else // All is good. Pull from it and notify FIFO :D
|
||||
{
|
||||
struct audio_lock region;
|
||||
if (!grab_region(ds, write_ptr, ®ion))
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
SetEvent(ds->event);
|
||||
break;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&ds->crit);
|
||||
if (region.chunk1)
|
||||
fifo_read(ds->buffer, region.chunk1, region.size1);
|
||||
if (region.chunk2)
|
||||
fifo_read(ds->buffer, region.chunk2, region.size2);
|
||||
LeaveCriticalSection(&ds->crit);
|
||||
|
||||
release_region(ds, ®ion);
|
||||
write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size;
|
||||
|
||||
SetEvent(ds->event);
|
||||
}
|
||||
}
|
||||
|
||||
ExitThread(0);
|
||||
}
|
||||
|
||||
static void dsound_stop_thread(dsound_t *ds)
|
||||
{
|
||||
if (ds->thread)
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
WaitForSingleObject(ds->thread, INFINITE);
|
||||
CloseHandle(ds->thread);
|
||||
ds->thread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool dsound_start_thread(dsound_t *ds)
|
||||
{
|
||||
if (!ds->thread)
|
||||
{
|
||||
ds->thread_alive = true;
|
||||
ds->thread = CreateThread(NULL, 0, dsound_thread, ds, 0, NULL);
|
||||
if (ds->thread == NULL)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dsound_clear_buffer(dsound_t *ds)
|
||||
{
|
||||
IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0);
|
||||
void *ptr;
|
||||
DWORD size;
|
||||
|
||||
if (IDirectSoundBuffer_Lock(ds->dsb, 0, 0, &ptr, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER) == DS_OK)
|
||||
{
|
||||
memset(ptr, 0, size);
|
||||
IDirectSoundBuffer_Unlock(ds->dsb, ptr, size, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void dsound_free(void *data)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
if (ds)
|
||||
{
|
||||
if (ds->thread)
|
||||
{
|
||||
ds->thread_alive = false;
|
||||
WaitForSingleObject(ds->thread, INFINITE);
|
||||
CloseHandle(ds->thread);
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&ds->crit);
|
||||
|
||||
if (ds->dsb)
|
||||
{
|
||||
IDirectSoundBuffer_Stop(ds->dsb);
|
||||
IDirectSoundBuffer_Release(ds->dsb);
|
||||
}
|
||||
|
||||
if (ds)
|
||||
IDirectSound_Release(ds->ds);
|
||||
|
||||
if (ds->event)
|
||||
CloseHandle(ds->event);
|
||||
|
||||
if (ds->buffer)
|
||||
fifo_free(ds->buffer);
|
||||
|
||||
free(ds);
|
||||
}
|
||||
}
|
||||
|
||||
static void* dsound_init(const char *device, unsigned rate, unsigned latency)
|
||||
{
|
||||
dsound_t *ds = calloc(1, sizeof(*ds));
|
||||
if (!ds)
|
||||
goto error;
|
||||
|
||||
InitializeCriticalSection(&ds->crit);
|
||||
|
||||
if (DirectSoundCreate(NULL, &ds->ds, NULL) != DS_OK)
|
||||
goto error;
|
||||
|
||||
if (IDirectSound_SetCooperativeLevel(ds->ds, GetDesktopWindow(), DSSCL_PRIORITY) != DS_OK)
|
||||
goto error;
|
||||
|
||||
WAVEFORMATEX wfx = {
|
||||
.wFormatTag = WAVE_FORMAT_PCM,
|
||||
.nChannels = 2,
|
||||
.nSamplesPerSec = rate,
|
||||
.wBitsPerSample = 16,
|
||||
.nBlockAlign = 2 * sizeof(int16_t),
|
||||
.nAvgBytesPerSec = rate * 2 * sizeof(int16_t),
|
||||
};
|
||||
|
||||
ds->buffer_size = (latency * wfx.nAvgBytesPerSec) / 1000;
|
||||
ds->buffer_size /= CHUNK_SIZE;
|
||||
ds->buffer_size *= CHUNK_SIZE;
|
||||
if (ds->buffer_size < 4 * CHUNK_SIZE)
|
||||
ds->buffer_size = 4 * CHUNK_SIZE;
|
||||
|
||||
SSNES_LOG("[DirectSound]: Setting buffer size of %u bytes\n", ds->buffer_size);
|
||||
SSNES_LOG("[DirectSound]: Latency = %u ms\n", (unsigned)((1000 * ds->buffer_size) / wfx.nAvgBytesPerSec));
|
||||
|
||||
DSBUFFERDESC bufdesc = {
|
||||
.dwSize = sizeof(DSBUFFERDESC),
|
||||
.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS,
|
||||
.dwBufferBytes = ds->buffer_size,
|
||||
.lpwfxFormat = &wfx,
|
||||
};
|
||||
|
||||
ds->event = CreateEvent(NULL, false, false, NULL);
|
||||
if (!ds->event)
|
||||
goto error;
|
||||
|
||||
ds->buffer = fifo_new(4 * 1024);
|
||||
if (!ds->buffer)
|
||||
goto error;
|
||||
|
||||
if (IDirectSound_CreateSoundBuffer(ds->ds, &bufdesc, &ds->dsb, 0) != DS_OK)
|
||||
goto error;
|
||||
|
||||
IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0);
|
||||
|
||||
dsound_clear_buffer(ds);
|
||||
|
||||
if (IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) != DS_OK)
|
||||
goto error;
|
||||
|
||||
if (!dsound_start_thread(ds))
|
||||
goto error;
|
||||
|
||||
return ds;
|
||||
|
||||
error:
|
||||
SSNES_ERR("[DirectSound] Error occured in init!\n");
|
||||
dsound_free(ds);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool dsound_stop(void *data)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
dsound_stop_thread(ds);
|
||||
return IDirectSoundBuffer_Stop(ds->dsb) == DS_OK;
|
||||
}
|
||||
|
||||
static bool dsound_start(void *data)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
dsound_clear_buffer(ds);
|
||||
|
||||
if (!dsound_start_thread(ds))
|
||||
return false;
|
||||
|
||||
return IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK;
|
||||
}
|
||||
|
||||
static void dsound_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
ds->nonblock = state;
|
||||
}
|
||||
|
||||
static ssize_t dsound_write(void *data, const void *buf_, size_t size)
|
||||
{
|
||||
dsound_t *ds = data;
|
||||
const uint8_t *buf = buf_;
|
||||
|
||||
if (!ds->thread_alive)
|
||||
return -1;
|
||||
|
||||
size_t written = 0;
|
||||
while (size > 0)
|
||||
{
|
||||
EnterCriticalSection(&ds->crit);
|
||||
size_t avail = fifo_write_avail(ds->buffer);
|
||||
if (avail > size)
|
||||
avail = size;
|
||||
|
||||
fifo_write(ds->buffer, buf, avail);
|
||||
LeaveCriticalSection(&ds->crit);
|
||||
|
||||
buf += avail;
|
||||
size -= avail;
|
||||
written += avail;
|
||||
|
||||
if (ds->nonblock || !ds->thread_alive)
|
||||
break;
|
||||
|
||||
if (avail == 0)
|
||||
WaitForSingleObject(ds->event, INFINITE);
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
|
||||
const audio_driver_t audio_dsound = {
|
||||
.init = dsound_init,
|
||||
.write = dsound_write,
|
||||
.stop = dsound_stop,
|
||||
.start = dsound_start,
|
||||
.set_nonblock_state = dsound_set_nonblock_state,
|
||||
.free = dsound_free,
|
||||
.ident = "dsound"
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
#define SSNES_TRUE 1
|
||||
#endif
|
||||
|
||||
#define SSNES_DSP_API_VERSION 2
|
||||
#define SSNES_DSP_API_VERSION 3
|
||||
|
||||
typedef struct ssnes_dsp_info
|
||||
{
|
||||
@@ -94,7 +94,7 @@ typedef struct ssnes_dsp_plugin
|
||||
void (*process)(void *data, ssnes_dsp_output_t *output,
|
||||
const ssnes_dsp_input_t *input);
|
||||
|
||||
// Frees the handle.
|
||||
// Frees the handle.
|
||||
void (*free)(void *data);
|
||||
|
||||
// API version used to compile the plugin.
|
||||
@@ -110,6 +110,11 @@ typedef struct ssnes_dsp_plugin
|
||||
|
||||
// Human readable identification string.
|
||||
const char *ident;
|
||||
|
||||
// Called every frame, allows creating a GUI main loop in the main thread.
|
||||
// GUI events can be processed here in a non-blocking fashion.
|
||||
// Can be set to NULL to ignore it.
|
||||
void (*events)(void *data);
|
||||
} ssnes_dsp_plugin_t;
|
||||
|
||||
// Called by SSNES at startup to get the callback struct.
|
||||
|
||||
+17
-18
@@ -127,9 +127,12 @@ static size_t find_buffersize(jack_t *jd, int latency)
|
||||
static void* __jack_init(const char* device, unsigned rate, unsigned latency)
|
||||
{
|
||||
jack_t *jd = calloc(1, sizeof(jack_t));
|
||||
if ( jd == NULL )
|
||||
if (!jd)
|
||||
return NULL;
|
||||
|
||||
pthread_cond_init(&jd->cond, NULL);
|
||||
pthread_mutex_init(&jd->cond_lock, NULL);
|
||||
|
||||
const char **jports = NULL;
|
||||
|
||||
jd->client = jack_client_open("SSNES", JackNullOption, NULL);
|
||||
@@ -148,7 +151,6 @@ static void* __jack_init(const char* device, unsigned rate, unsigned latency)
|
||||
SSNES_ERR("Failed to register ports.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
char *dest_ports[2];
|
||||
jports = jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
|
||||
@@ -158,6 +160,18 @@ static void* __jack_init(const char* device, unsigned rate, unsigned latency)
|
||||
goto error;
|
||||
}
|
||||
|
||||
size_t bufsize = find_buffersize(jd, latency);
|
||||
SSNES_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t)));
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
jd->buffer[i] = jack_ringbuffer_create(bufsize);
|
||||
if (jd->buffer[i] == NULL)
|
||||
{
|
||||
SSNES_ERR("Failed to create buffers.\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
int parsed = parse_ports(dest_ports, jports);
|
||||
|
||||
if (jack_activate(jd->client) < 0)
|
||||
@@ -178,22 +192,7 @@ static void* __jack_init(const char* device, unsigned rate, unsigned latency)
|
||||
for (int i = 0; i < parsed; i++)
|
||||
free(dest_ports[i]);
|
||||
|
||||
size_t bufsize = find_buffersize(jd, latency);
|
||||
|
||||
SSNES_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t)));
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
jd->buffer[i] = jack_ringbuffer_create(bufsize);
|
||||
if (jd->buffer[i] == NULL)
|
||||
{
|
||||
SSNES_ERR("Failed to create buffers.\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_cond_init(&jd->cond, NULL);
|
||||
pthread_mutex_init(&jd->cond_lock, NULL);
|
||||
|
||||
|
||||
jack_free(jports);
|
||||
return jd;
|
||||
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@
|
||||
#endif
|
||||
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_OSS_BSD
|
||||
@@ -68,7 +69,8 @@ static void* __oss_init(const char* device, unsigned rate, unsigned latency)
|
||||
}
|
||||
|
||||
int channels = 2;
|
||||
int format = AFMT_S16_LE;
|
||||
int format = is_little_endian() ?
|
||||
AFMT_S16_LE : AFMT_S16_BE;
|
||||
|
||||
if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0)
|
||||
{
|
||||
|
||||
@@ -59,18 +59,6 @@ static void __pulse_free(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint8_t is_little_endian(void)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16_t x;
|
||||
uint8_t y[2];
|
||||
} u;
|
||||
|
||||
u.x = 1;
|
||||
return u.y[0];
|
||||
}
|
||||
|
||||
static void context_state_cb(pa_context *c, void *data)
|
||||
{
|
||||
pa_t *pa = data;
|
||||
|
||||
@@ -196,9 +196,4 @@ const audio_driver_t audio_sdl = {
|
||||
.free = sdl_audio_free,
|
||||
.ident = "sdl"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
Simple C interface for XAudio2
|
||||
Author: Hans-Kristian Arntzen
|
||||
License: Public Domain
|
||||
*/
|
||||
|
||||
// This will currently only compile with MSVC2k10.
|
||||
// Should be compilable with some MinGW trickery as well.
|
||||
|
||||
#include "xaudio-c.h"
|
||||
|
||||
struct xaudio2 : public IXAudio2VoiceCallback
|
||||
{
|
||||
xaudio2(unsigned samplerate, unsigned channels, unsigned bits, unsigned size) :
|
||||
buf(nullptr), pXAudio2(nullptr), pMasterVoice(nullptr), pSourceVoice(nullptr),
|
||||
buffers(0), bufptr(0)
|
||||
{
|
||||
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
HRESULT hr;
|
||||
if (FAILED(hr = XAudio2Create(&pXAudio2, 0)))
|
||||
throw -1;
|
||||
if (FAILED(hr = pXAudio2->CreateMasteringVoice(
|
||||
&pMasterVoice, channels, samplerate, 0, 0, nullptr)))
|
||||
throw -1;
|
||||
WAVEFORMATEX wfx;
|
||||
wfx.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfx.nChannels = channels;
|
||||
wfx.nSamplesPerSec = samplerate;
|
||||
wfx.nBlockAlign = channels * bits / 8;
|
||||
wfx.wBitsPerSample = bits;
|
||||
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
||||
wfx.cbSize = 0;
|
||||
if (FAILED(hr = pXAudio2->CreateSourceVoice(
|
||||
&pSourceVoice, &wfx, XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO, this, nullptr, nullptr)))
|
||||
throw -1;
|
||||
|
||||
pSourceVoice->Start();
|
||||
|
||||
hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
if (!hEvent)
|
||||
throw -1;
|
||||
|
||||
max_buffers = 8;
|
||||
bufsize = size / max_buffers;
|
||||
buf = new uint8_t[bufsize * max_buffers];
|
||||
write_buffer = 0;
|
||||
}
|
||||
|
||||
~xaudio2()
|
||||
{
|
||||
if (pSourceVoice)
|
||||
{
|
||||
pSourceVoice->Stop();
|
||||
pSourceVoice->DestroyVoice();
|
||||
}
|
||||
|
||||
if (pMasterVoice)
|
||||
pMasterVoice->DestroyVoice();
|
||||
|
||||
if (pXAudio2)
|
||||
pXAudio2->Release();
|
||||
|
||||
if (hEvent)
|
||||
CloseHandle(hEvent);
|
||||
|
||||
if (buf)
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
size_t write_avail() const
|
||||
{
|
||||
return bufsize * (max_buffers - buffers - 1);
|
||||
}
|
||||
|
||||
size_t write(const void *buffer, size_t bytes)
|
||||
{
|
||||
size_t written = 0;
|
||||
while (written < bytes)
|
||||
{
|
||||
size_t need = min(bytes - written, bufsize - bufptr);
|
||||
memcpy((uint8_t*)buf + write_buffer * bufsize + bufptr, (const uint8_t*)buffer + written, need);
|
||||
written += need;
|
||||
bufptr += need;
|
||||
|
||||
if (bufptr == bufsize)
|
||||
{
|
||||
while (buffers == max_buffers - 1)
|
||||
WaitForSingleObject(hEvent, INFINITE);
|
||||
|
||||
XAUDIO2_BUFFER xa2buffer = {0};
|
||||
xa2buffer.AudioBytes = bufsize;
|
||||
xa2buffer.pAudioData = buf + write_buffer * bufsize;
|
||||
xa2buffer.pContext = nullptr;
|
||||
InterlockedIncrement(&buffers);
|
||||
pSourceVoice->SubmitSourceBuffer(&xa2buffer);
|
||||
bufptr = 0;
|
||||
write_buffer = (write_buffer + 1) % max_buffers;
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
STDMETHOD_(void, OnBufferStart) (void *) {}
|
||||
STDMETHOD_(void, OnBufferEnd) (void *)
|
||||
{
|
||||
InterlockedDecrement(&buffers);
|
||||
SetEvent(hEvent);
|
||||
}
|
||||
STDMETHOD_(void, OnLoopEnd) (void *) {}
|
||||
STDMETHOD_(void, OnStreamEnd) () {}
|
||||
STDMETHOD_(void, OnVoiceError) (void *, HRESULT) {}
|
||||
STDMETHOD_(void, OnVoiceProcessingPassEnd) ()
|
||||
{
|
||||
SetEvent(hEvent);
|
||||
}
|
||||
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
|
||||
|
||||
uint8_t *buf;
|
||||
IXAudio2 *pXAudio2;
|
||||
IXAudio2MasteringVoice *pMasterVoice;
|
||||
IXAudio2SourceVoice *pSourceVoice;
|
||||
HANDLE hEvent;
|
||||
|
||||
volatile long buffers;
|
||||
unsigned max_buffers;
|
||||
unsigned bufsize;
|
||||
unsigned bufptr;
|
||||
unsigned write_buffer;
|
||||
};
|
||||
|
||||
XAUDIOC_API xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, unsigned bits, size_t size)
|
||||
{
|
||||
xaudio2 *handle = nullptr;
|
||||
try {
|
||||
handle = new xaudio2(samplerate, channels, bits, size);
|
||||
} catch(...) { delete handle; return nullptr; }
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
XAUDIOC_API size_t xaudio2_write_avail(xaudio2_t *handle)
|
||||
{
|
||||
try {
|
||||
return handle->write_avail();
|
||||
} catch(...) { return 0; }
|
||||
}
|
||||
|
||||
XAUDIOC_API size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes)
|
||||
{
|
||||
try {
|
||||
return handle->write(buf, bytes);
|
||||
} catch(...) { return 0; }
|
||||
}
|
||||
|
||||
XAUDIOC_API void xaudio2_free(xaudio2_t *handle)
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
Simple C interface for XAudio2
|
||||
Author: Hans-Kristian Arntzen
|
||||
License: Public Domain
|
||||
*/
|
||||
|
||||
#ifndef XAUDIO_C_H
|
||||
#define XAUDIO_C_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef XAUDIOC_EXPORTS
|
||||
#define XAUDIOC_API __declspec(dllexport)
|
||||
#else
|
||||
#define XAUDIOC_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
typedef struct xaudio2 xaudio2_t;
|
||||
|
||||
XAUDIOC_API xaudio2_t* xaudio2_new(unsigned samplerate, unsigned channels, unsigned bits, size_t bufsize);
|
||||
XAUDIOC_API size_t xaudio2_write_avail(xaudio2_t *handle);
|
||||
XAUDIOC_API size_t xaudio2_write(xaudio2_t *handle, const void *data, size_t bytes);
|
||||
XAUDIOC_API void xaudio2_free(xaudio2_t *handle);
|
||||
|
||||
typedef xaudio2_t* (*xaudio2_new_t)(unsigned, unsigned, unsigned, size_t);
|
||||
typedef size_t (*xaudio2_write_avail_t)(xaudio2_t*);
|
||||
typedef size_t (*xaudio2_write_t)(xaudio2_t*, const void*, size_t);
|
||||
typedef void (*xaudio2_free_t)(xaudio2_t*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
Simple C interface for XAudio2
|
||||
Author: Hans-Kristian Arntzen
|
||||
License: Public Domain
|
||||
*/
|
||||
|
||||
#include "xaudio-c.h"
|
||||
#include "xaudio2.hpp"
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
|
||||
struct xaudio2 : public IXAudio2VoiceCallback
|
||||
{
|
||||
xaudio2(unsigned samplerate, unsigned channels, unsigned size) :
|
||||
buf(0), pXAudio2(0), pMasterVoice(0), pSourceVoice(0),
|
||||
buffers(0), bufptr(0)
|
||||
{
|
||||
CoInitializeEx(0, COINIT_MULTITHREADED);
|
||||
if (FAILED(XAudio2Create(&pXAudio2, 0)))
|
||||
throw -1;
|
||||
if (FAILED(pXAudio2->CreateMasteringVoice(
|
||||
&pMasterVoice, channels, samplerate, 0, 0, 0)))
|
||||
throw -1;
|
||||
|
||||
WAVEFORMATEX wfx;
|
||||
wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
|
||||
wfx.nChannels = channels;
|
||||
wfx.nSamplesPerSec = samplerate;
|
||||
wfx.nBlockAlign = channels * sizeof(float);
|
||||
wfx.wBitsPerSample = sizeof(float) * 8;
|
||||
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
|
||||
wfx.cbSize = 0;
|
||||
if (FAILED(pXAudio2->CreateSourceVoice(
|
||||
&pSourceVoice, &wfx, XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO, this, 0, 0)))
|
||||
throw -1;
|
||||
|
||||
hEvent = CreateEvent(0, FALSE, FALSE, 0);
|
||||
if (!hEvent)
|
||||
throw -1;
|
||||
|
||||
pSourceVoice->Start(0);
|
||||
|
||||
bufsize = size / max_buffers;
|
||||
buf = new uint8_t[bufsize * max_buffers];
|
||||
write_buffer = 0;
|
||||
}
|
||||
|
||||
virtual ~xaudio2()
|
||||
{
|
||||
if (pSourceVoice)
|
||||
{
|
||||
pSourceVoice->Stop(0);
|
||||
pSourceVoice->DestroyVoice();
|
||||
}
|
||||
|
||||
if (pMasterVoice)
|
||||
pMasterVoice->DestroyVoice();
|
||||
|
||||
if (pXAudio2)
|
||||
pXAudio2->Release();
|
||||
|
||||
if (hEvent)
|
||||
CloseHandle(hEvent);
|
||||
|
||||
if (buf)
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
size_t write_avail() const
|
||||
{
|
||||
return bufsize * (max_buffers - buffers - 1);
|
||||
}
|
||||
|
||||
size_t write(const void *buffer_, size_t bytes_)
|
||||
{
|
||||
unsigned bytes = bytes_;
|
||||
const uint8_t *buffer = reinterpret_cast<const uint8_t*>(buffer_);
|
||||
while (bytes > 0)
|
||||
{
|
||||
unsigned need = std::min(bytes, bufsize - bufptr);
|
||||
memcpy(buf + write_buffer * bufsize + bufptr,
|
||||
buffer, need);
|
||||
|
||||
bufptr += need;
|
||||
buffer += need;
|
||||
bytes -= need;
|
||||
|
||||
if (bufptr == bufsize)
|
||||
{
|
||||
WaitForSingleObject(hEvent, 0); // Clear out ready state.
|
||||
while (buffers == max_buffers - 1)
|
||||
WaitForSingleObject(hEvent, INFINITE);
|
||||
|
||||
XAUDIO2_BUFFER xa2buffer = {0};
|
||||
xa2buffer.AudioBytes = bufsize;
|
||||
xa2buffer.pAudioData = buf + write_buffer * bufsize;
|
||||
xa2buffer.pContext = 0;
|
||||
if (FAILED(pSourceVoice->SubmitSourceBuffer(&xa2buffer)))
|
||||
return 0;
|
||||
|
||||
InterlockedIncrement(&buffers);
|
||||
bufptr = 0;
|
||||
write_buffer = (write_buffer + 1) & (max_buffers_mask);
|
||||
}
|
||||
}
|
||||
|
||||
return bytes_;
|
||||
}
|
||||
|
||||
enum { max_buffers = 16, max_buffers_mask = max_buffers - 1 };
|
||||
|
||||
STDMETHOD_(void, OnBufferStart) (void *) {}
|
||||
STDMETHOD_(void, OnBufferEnd) (void *)
|
||||
{
|
||||
InterlockedDecrement(&buffers);
|
||||
SetEvent(hEvent);
|
||||
}
|
||||
STDMETHOD_(void, OnLoopEnd) (void *) {}
|
||||
STDMETHOD_(void, OnStreamEnd) () {}
|
||||
STDMETHOD_(void, OnVoiceError) (void *, HRESULT) {}
|
||||
STDMETHOD_(void, OnVoiceProcessingPassEnd) () {}
|
||||
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
|
||||
|
||||
uint8_t *buf;
|
||||
IXAudio2 *pXAudio2;
|
||||
IXAudio2MasteringVoice *pMasterVoice;
|
||||
IXAudio2SourceVoice *pSourceVoice;
|
||||
HANDLE hEvent;
|
||||
|
||||
volatile long buffers;
|
||||
unsigned bufsize;
|
||||
unsigned bufptr;
|
||||
unsigned write_buffer;
|
||||
};
|
||||
|
||||
xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, size_t size)
|
||||
{
|
||||
xaudio2 *handle = 0;
|
||||
try {
|
||||
handle = new xaudio2(samplerate, channels, size);
|
||||
} catch(...) { delete handle; return 0; }
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
size_t xaudio2_write_avail(xaudio2_t *handle)
|
||||
{
|
||||
try {
|
||||
return handle->write_avail();
|
||||
} catch(...) { return 0; }
|
||||
}
|
||||
|
||||
size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes)
|
||||
{
|
||||
try {
|
||||
return handle->write(buf, bytes);
|
||||
} catch(...) { return 0; }
|
||||
}
|
||||
|
||||
void xaudio2_free(xaudio2_t *handle)
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Simple C interface for XAudio2
|
||||
Author: Hans-Kristian Arntzen
|
||||
License: Public Domain
|
||||
*/
|
||||
|
||||
#ifndef XAUDIO_C_H
|
||||
#define XAUDIO_C_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct xaudio2 xaudio2_t;
|
||||
|
||||
xaudio2_t* xaudio2_new(unsigned samplerate, unsigned channels, size_t bufsize);
|
||||
size_t xaudio2_write_avail(xaudio2_t *handle);
|
||||
size_t xaudio2_write(xaudio2_t *handle, const void *data, size_t bytes);
|
||||
void xaudio2_free(xaudio2_t *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Executable
+329
@@ -0,0 +1,329 @@
|
||||
/*
|
||||
xaudio2.hpp (2010-08-14)
|
||||
author: OV2
|
||||
*/
|
||||
|
||||
#ifndef XAUDIO2_MINGW_H
|
||||
#define XAUDIO2_MINGW_H
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#include <basetyps.h>
|
||||
#include <objbase.h>
|
||||
#include <mmreg.h>
|
||||
|
||||
// 64-bit GCC fix
|
||||
#define GUID_EXT EXTERN_C
|
||||
#define GUID_SECT
|
||||
|
||||
#define DEFINE_GUID_X(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) GUID_EXT const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
|
||||
#define DEFINE_CLSID_X(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
DEFINE_GUID_X(CLSID_##className, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
|
||||
#define DEFINE_IID_X(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
DEFINE_GUID_X(IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
|
||||
#define X2DEFAULT(x) =x
|
||||
|
||||
DEFINE_CLSID_X(XAudio2, e21a7345, eb21, 468e, be, 50, 80, 4d, b9, 7c, f7, 08);
|
||||
DEFINE_CLSID_X(XAudio2_Debug, f7a76c21, 53d4, 46bb, ac, 53, 8b, 45, 9c, ae, 46, bd);
|
||||
DEFINE_IID_X(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
|
||||
|
||||
DECLARE_INTERFACE(IXAudio2Voice);
|
||||
|
||||
#define XAUDIO2_COMMIT_NOW 0
|
||||
#define XAUDIO2_DEFAULT_CHANNELS 0
|
||||
#define XAUDIO2_DEFAULT_SAMPLERATE 0
|
||||
#define XAUDIO2_DEFAULT_FREQ_RATIO 4.0f
|
||||
#define XAUDIO2_DEBUG_ENGINE 0x0001
|
||||
#define XAUDIO2_VOICE_NOSRC 0x0004
|
||||
|
||||
typedef enum XAUDIO2_DEVICE_ROLE
|
||||
{
|
||||
NotDefaultDevice = 0x0,
|
||||
DefaultConsoleDevice = 0x1,
|
||||
DefaultMultimediaDevice = 0x2,
|
||||
DefaultCommunicationsDevice = 0x4,
|
||||
DefaultGameDevice = 0x8,
|
||||
GlobalDefaultDevice = 0xf,
|
||||
InvalidDeviceRole = ~GlobalDefaultDevice
|
||||
} XAUDIO2_DEVICE_ROLE;
|
||||
|
||||
typedef struct XAUDIO2_DEVICE_DETAILS
|
||||
{
|
||||
WCHAR DeviceID[256];
|
||||
WCHAR DisplayName[256];
|
||||
XAUDIO2_DEVICE_ROLE Role;
|
||||
WAVEFORMATEXTENSIBLE OutputFormat;
|
||||
} XAUDIO2_DEVICE_DETAILS;
|
||||
|
||||
typedef struct XAUDIO2_VOICE_DETAILS
|
||||
{
|
||||
UINT32 CreationFlags;
|
||||
UINT32 InputChannels;
|
||||
UINT32 InputSampleRate;
|
||||
} XAUDIO2_VOICE_DETAILS;
|
||||
|
||||
typedef enum XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
|
||||
{
|
||||
Processor1 = 0x00000001,
|
||||
Processor2 = 0x00000002,
|
||||
Processor3 = 0x00000004,
|
||||
Processor4 = 0x00000008,
|
||||
Processor5 = 0x00000010,
|
||||
Processor6 = 0x00000020,
|
||||
Processor7 = 0x00000040,
|
||||
Processor8 = 0x00000080,
|
||||
Processor9 = 0x00000100,
|
||||
Processor10 = 0x00000200,
|
||||
Processor11 = 0x00000400,
|
||||
Processor12 = 0x00000800,
|
||||
Processor13 = 0x00001000,
|
||||
Processor14 = 0x00002000,
|
||||
Processor15 = 0x00004000,
|
||||
Processor16 = 0x00008000,
|
||||
Processor17 = 0x00010000,
|
||||
Processor18 = 0x00020000,
|
||||
Processor19 = 0x00040000,
|
||||
Processor20 = 0x00080000,
|
||||
Processor21 = 0x00100000,
|
||||
Processor22 = 0x00200000,
|
||||
Processor23 = 0x00400000,
|
||||
Processor24 = 0x00800000,
|
||||
Processor25 = 0x01000000,
|
||||
Processor26 = 0x02000000,
|
||||
Processor27 = 0x04000000,
|
||||
Processor28 = 0x08000000,
|
||||
Processor29 = 0x10000000,
|
||||
Processor30 = 0x20000000,
|
||||
Processor31 = 0x40000000,
|
||||
Processor32 = 0x80000000,
|
||||
XAUDIO2_ANY_PROCESSOR = 0xffffffff,
|
||||
XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
|
||||
} XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER, XAUDIO2_PROCESSOR;
|
||||
|
||||
typedef struct XAUDIO2_VOICE_SENDS
|
||||
{
|
||||
UINT32 OutputCount;
|
||||
IXAudio2Voice** pOutputVoices;
|
||||
} XAUDIO2_VOICE_SENDS;
|
||||
|
||||
typedef struct XAUDIO2_EFFECT_DESCRIPTOR
|
||||
{
|
||||
IUnknown* pEffect;
|
||||
BOOL InitialState;
|
||||
UINT32 OutputChannels;
|
||||
} XAUDIO2_EFFECT_DESCRIPTOR;
|
||||
|
||||
typedef struct XAUDIO2_EFFECT_CHAIN
|
||||
{
|
||||
UINT32 EffectCount;
|
||||
const XAUDIO2_EFFECT_DESCRIPTOR* pEffectDescriptors;
|
||||
} XAUDIO2_EFFECT_CHAIN;
|
||||
|
||||
typedef enum XAUDIO2_FILTER_TYPE
|
||||
{
|
||||
LowPassFilter,
|
||||
BandPassFilter,
|
||||
HighPassFilter
|
||||
} XAUDIO2_FILTER_TYPE;
|
||||
|
||||
typedef struct XAUDIO2_FILTER_PARAMETERS
|
||||
{
|
||||
XAUDIO2_FILTER_TYPE Type;
|
||||
float Frequency;
|
||||
float OneOverQ;
|
||||
|
||||
} XAUDIO2_FILTER_PARAMETERS;
|
||||
|
||||
typedef struct XAUDIO2_BUFFER
|
||||
{
|
||||
UINT32 Flags;
|
||||
UINT32 AudioBytes;
|
||||
const BYTE* pAudioData;
|
||||
UINT32 PlayBegin;
|
||||
UINT32 PlayLength;
|
||||
UINT32 LoopBegin;
|
||||
UINT32 LoopLength;
|
||||
UINT32 LoopCount;
|
||||
void* pContext;
|
||||
} XAUDIO2_BUFFER;
|
||||
|
||||
typedef struct XAUDIO2_BUFFER_WMA
|
||||
{
|
||||
const UINT32* pDecodedPacketCumulativeBytes;
|
||||
UINT32 PacketCount;
|
||||
} XAUDIO2_BUFFER_WMA;
|
||||
|
||||
typedef struct XAUDIO2_VOICE_STATE
|
||||
{
|
||||
void* pCurrentBufferContext;
|
||||
UINT32 BuffersQueued;
|
||||
UINT64 SamplesPlayed;
|
||||
} XAUDIO2_VOICE_STATE;
|
||||
|
||||
typedef struct XAUDIO2_PERFORMANCE_DATA
|
||||
{
|
||||
UINT64 AudioCyclesSinceLastQuery;
|
||||
UINT64 TotalCyclesSinceLastQuery;
|
||||
UINT32 MinimumCyclesPerQuantum;
|
||||
UINT32 MaximumCyclesPerQuantum;
|
||||
UINT32 MemoryUsageInBytes;
|
||||
UINT32 CurrentLatencyInSamples;
|
||||
UINT32 GlitchesSinceEngineStarted;
|
||||
UINT32 ActiveSourceVoiceCount;
|
||||
UINT32 TotalSourceVoiceCount;
|
||||
UINT32 ActiveSubmixVoiceCount;
|
||||
UINT32 TotalSubmixVoiceCount;
|
||||
UINT32 ActiveXmaSourceVoices;
|
||||
UINT32 ActiveXmaStreams;
|
||||
} XAUDIO2_PERFORMANCE_DATA;
|
||||
|
||||
typedef struct XAUDIO2_DEBUG_CONFIGURATION
|
||||
{
|
||||
UINT32 TraceMask;
|
||||
UINT32 BreakMask;
|
||||
BOOL LogThreadID;
|
||||
BOOL LogFileline;
|
||||
BOOL LogFunctionName;
|
||||
BOOL LogTiming;
|
||||
} XAUDIO2_DEBUG_CONFIGURATION;
|
||||
|
||||
DECLARE_INTERFACE(IXAudio2EngineCallback)
|
||||
{
|
||||
STDMETHOD_(void, OnProcessingPassStart) (THIS) PURE;
|
||||
STDMETHOD_(void, OnProcessingPassEnd) (THIS) PURE;
|
||||
STDMETHOD_(void, OnCriticalError) (THIS_ HRESULT Error) PURE;
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(IXAudio2VoiceCallback)
|
||||
{
|
||||
STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) PURE;
|
||||
STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) PURE;
|
||||
STDMETHOD_(void, OnStreamEnd) (THIS) PURE;
|
||||
STDMETHOD_(void, OnBufferStart) (THIS_ void* pBufferContext) PURE;
|
||||
STDMETHOD_(void, OnBufferEnd) (THIS_ void* pBufferContext) PURE;
|
||||
STDMETHOD_(void, OnLoopEnd) (THIS_ void* pBufferContext) PURE;
|
||||
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) PURE;
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(IXAudio2Voice)
|
||||
{
|
||||
#define Declare_IXAudio2Voice_Methods() \
|
||||
STDMETHOD_(void, GetVoiceDetails) (THIS_ XAUDIO2_VOICE_DETAILS* pVoiceDetails) PURE; \
|
||||
STDMETHOD(SetOutputVoices) (THIS_ const XAUDIO2_VOICE_SENDS* pSendList) PURE; \
|
||||
STDMETHOD(SetEffectChain) (THIS_ const XAUDIO2_EFFECT_CHAIN* pEffectChain) PURE; \
|
||||
STDMETHOD(EnableEffect) (THIS_ UINT32 EffectIndex, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD(DisableEffect) (THIS_ UINT32 EffectIndex, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD_(void, GetEffectState) (THIS_ UINT32 EffectIndex, BOOL* pEnabled) PURE; \
|
||||
STDMETHOD(SetEffectParameters) (THIS_ UINT32 EffectIndex, \
|
||||
const void* pParameters, \
|
||||
UINT32 ParametersByteSize, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD(GetEffectParameters) (THIS_ UINT32 EffectIndex, void* pParameters, \
|
||||
UINT32 ParametersByteSize) PURE; \
|
||||
STDMETHOD(SetFilterParameters) (THIS_ const XAUDIO2_FILTER_PARAMETERS* pParameters, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD_(void, GetFilterParameters) (THIS_ XAUDIO2_FILTER_PARAMETERS* pParameters) PURE; \
|
||||
STDMETHOD(SetVolume) (THIS_ float Volume, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD_(void, GetVolume) (THIS_ float* pVolume) PURE; \
|
||||
STDMETHOD(SetChannelVolumes) (THIS_ UINT32 Channels, const float* pVolumes, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD_(void, GetChannelVolumes) (THIS_ UINT32 Channels, float* pVolumes) PURE; \
|
||||
STDMETHOD(SetOutputMatrix) (THIS_ IXAudio2Voice* pDestinationVoice, \
|
||||
UINT32 SourceChannels, UINT32 DestinationChannels, \
|
||||
const float* pLevelMatrix, \
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
|
||||
STDMETHOD_(void, GetOutputMatrix) (THIS_ IXAudio2Voice* pDestinationVoice, \
|
||||
UINT32 SourceChannels, UINT32 DestinationChannels, \
|
||||
float* pLevelMatrix) PURE; \
|
||||
STDMETHOD_(void, DestroyVoice) (THIS) PURE
|
||||
|
||||
Declare_IXAudio2Voice_Methods();
|
||||
};
|
||||
|
||||
|
||||
DECLARE_INTERFACE_(IXAudio2MasteringVoice, IXAudio2Voice)
|
||||
{
|
||||
Declare_IXAudio2Voice_Methods();
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_(IXAudio2SubmixVoice, IXAudio2Voice)
|
||||
{
|
||||
Declare_IXAudio2Voice_Methods();
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_(IXAudio2SourceVoice, IXAudio2Voice)
|
||||
{
|
||||
Declare_IXAudio2Voice_Methods();
|
||||
STDMETHOD(Start) (THIS_ UINT32 Flags, UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
|
||||
STDMETHOD(Stop) (THIS_ UINT32 Flags, UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
|
||||
STDMETHOD(SubmitSourceBuffer) (THIS_ const XAUDIO2_BUFFER* pBuffer, const XAUDIO2_BUFFER_WMA* pBufferWMA X2DEFAULT(NULL)) PURE;
|
||||
STDMETHOD(FlushSourceBuffers) (THIS) PURE;
|
||||
STDMETHOD(Discontinuity) (THIS) PURE;
|
||||
STDMETHOD(ExitLoop) (THIS_ UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
|
||||
STDMETHOD_(void, GetState) (THIS_ XAUDIO2_VOICE_STATE* pVoiceState) PURE;
|
||||
STDMETHOD(SetFrequencyRatio) (THIS_ float Ratio,
|
||||
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
|
||||
STDMETHOD_(void, GetFrequencyRatio) (THIS_ float* pRatio) PURE;
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE_(IXAudio2, IUnknown)
|
||||
{
|
||||
STDMETHOD(QueryInterface) (THIS_ REFIID riid, void** ppvInterface) PURE;
|
||||
STDMETHOD_(ULONG, AddRef) (THIS) PURE;
|
||||
STDMETHOD_(ULONG, Release) (THIS) PURE;
|
||||
STDMETHOD(GetDeviceCount) (THIS_ UINT32* pCount) PURE;
|
||||
STDMETHOD(GetDeviceDetails) (THIS_ UINT32 Index, XAUDIO2_DEVICE_DETAILS* pDeviceDetails) PURE;
|
||||
STDMETHOD(Initialize) (THIS_ UINT32 Flags X2DEFAULT(0),
|
||||
XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR)) PURE;
|
||||
STDMETHOD(RegisterForCallbacks) (IXAudio2EngineCallback* pCallback) PURE;
|
||||
STDMETHOD_(void, UnregisterForCallbacks) (IXAudio2EngineCallback* pCallback) PURE;
|
||||
STDMETHOD(CreateSourceVoice) (THIS_ IXAudio2SourceVoice** ppSourceVoice,
|
||||
const WAVEFORMATEX* pSourceFormat,
|
||||
UINT32 Flags X2DEFAULT(0),
|
||||
float MaxFrequencyRatio X2DEFAULT(XAUDIO2_DEFAULT_FREQ_RATIO),
|
||||
IXAudio2VoiceCallback* pCallback X2DEFAULT(NULL),
|
||||
const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
|
||||
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
|
||||
STDMETHOD(CreateSubmixVoice) (THIS_ IXAudio2SubmixVoice** ppSubmixVoice,
|
||||
UINT32 InputChannels, UINT32 InputSampleRate,
|
||||
UINT32 Flags X2DEFAULT(0), UINT32 ProcessingStage X2DEFAULT(0),
|
||||
const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
|
||||
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
|
||||
STDMETHOD(CreateMasteringVoice) (THIS_ IXAudio2MasteringVoice** ppMasteringVoice,
|
||||
UINT32 InputChannels X2DEFAULT(XAUDIO2_DEFAULT_CHANNELS),
|
||||
UINT32 InputSampleRate X2DEFAULT(XAUDIO2_DEFAULT_SAMPLERATE),
|
||||
UINT32 Flags X2DEFAULT(0), UINT32 DeviceIndex X2DEFAULT(0),
|
||||
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
|
||||
STDMETHOD(StartEngine) (THIS) PURE;
|
||||
STDMETHOD_(void, StopEngine) (THIS) PURE;
|
||||
STDMETHOD(CommitChanges) (THIS_ UINT32 OperationSet) PURE;
|
||||
STDMETHOD_(void, GetPerformanceData) (THIS_ XAUDIO2_PERFORMANCE_DATA* pPerfData) PURE;
|
||||
STDMETHOD_(void, SetDebugConfiguration) (THIS_ const XAUDIO2_DEBUG_CONFIGURATION* pDebugConfiguration,
|
||||
void* pReserved X2DEFAULT(NULL)) PURE;
|
||||
};
|
||||
|
||||
static inline HRESULT XAudio2Create(IXAudio2** ppXAudio2, UINT32 Flags X2DEFAULT(0),
|
||||
XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR))
|
||||
{
|
||||
IXAudio2* pXAudio2;
|
||||
HRESULT hr = CoCreateInstance((Flags & XAUDIO2_DEBUG_ENGINE) ? CLSID_XAudio2_Debug : CLSID_XAudio2,
|
||||
NULL, CLSCTX_INPROC_SERVER, IID_IXAudio2, reinterpret_cast<void**>(&pXAudio2));
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pXAudio2->Initialize(Flags, XAudio2Processor);
|
||||
if (SUCCEEDED(hr))
|
||||
*ppXAudio2 = pXAudio2;
|
||||
else
|
||||
pXAudio2->Release();
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+19
-58
@@ -15,63 +15,19 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "driver.h"
|
||||
#include <stdlib.h>
|
||||
#include "xaudio-c.h"
|
||||
#include "xaudio-c/xaudio-c.h"
|
||||
#include "general.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
xaudio2_t *xa;
|
||||
bool nonblock;
|
||||
} xa_t;
|
||||
|
||||
static xaudio2_new_t pxanew = NULL;
|
||||
static xaudio2_write_t pxawrite = NULL;
|
||||
static xaudio2_write_avail_t pxawrite_avail = NULL;
|
||||
static xaudio2_free_t pxafree = NULL;
|
||||
static HMODULE lib = NULL;
|
||||
|
||||
#define LIB_NAME "xaudio-c.dll"
|
||||
#define SYM(X) ((void*)GetProcAddress(lib, "xaudio2_" #X))
|
||||
|
||||
static void deinit_lib(void)
|
||||
{
|
||||
FreeModule(lib);
|
||||
lib = NULL;
|
||||
}
|
||||
|
||||
static bool init_lib(void)
|
||||
{
|
||||
if (lib)
|
||||
return true;
|
||||
|
||||
lib = LoadLibrary(LIB_NAME);
|
||||
if (!lib)
|
||||
return false;
|
||||
|
||||
pxanew = SYM(new);
|
||||
pxawrite = SYM(write);
|
||||
pxawrite_avail = SYM(write_avail);
|
||||
pxafree = SYM(free);
|
||||
|
||||
if (!pxanew || !pxawrite || !pxawrite_avail || !pxafree)
|
||||
{
|
||||
deinit_lib();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void* __xa_init(const char* device, unsigned rate, unsigned latency)
|
||||
{
|
||||
if (!init_lib())
|
||||
return NULL;
|
||||
|
||||
if (latency < 8)
|
||||
latency = 8; // Do not allow shenanigans.
|
||||
|
||||
@@ -80,11 +36,10 @@ static void* __xa_init(const char* device, unsigned rate, unsigned latency)
|
||||
return NULL;
|
||||
|
||||
size_t bufsize = latency * rate / 1000;
|
||||
bufsize = next_pow2(bufsize);
|
||||
|
||||
SSNES_LOG("XAudio2: Requesting %d ms latency, using %d ms latency.\n", latency, (int)bufsize * 1000 / rate);
|
||||
|
||||
xa->xa = pxanew(rate, 2, 16, bufsize << 2);
|
||||
xa->xa = xaudio2_new(rate, 2, bufsize * 2 * sizeof(float));
|
||||
if (!xa->xa)
|
||||
{
|
||||
SSNES_ERR("Failed to init XAudio2.\n");
|
||||
@@ -99,11 +54,16 @@ static ssize_t __xa_write(void* data, const void* buf, size_t size)
|
||||
xa_t *xa = data;
|
||||
if (xa->nonblock)
|
||||
{
|
||||
size_t avail = pxawrite_avail(xa->xa);
|
||||
size_t avail = xaudio2_write_avail(xa->xa);
|
||||
if (avail == 0)
|
||||
return 0;
|
||||
if (avail < size)
|
||||
size = avail;
|
||||
}
|
||||
return pxawrite(xa->xa, buf, size);
|
||||
size_t ret = xaudio2_write(xa->xa, buf, size);
|
||||
if (ret == 0)
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool __xa_stop(void *data)
|
||||
@@ -124,16 +84,21 @@ static bool __xa_start(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool __xa_use_float(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __xa_free(void *data)
|
||||
{
|
||||
xa_t *xa = data;
|
||||
if (xa && xa->xa)
|
||||
if (xa)
|
||||
{
|
||||
if (pxafree)
|
||||
pxafree(xa->xa);
|
||||
if (xa->xa)
|
||||
xaudio2_free(xa->xa);
|
||||
free(xa);
|
||||
}
|
||||
deinit_lib();
|
||||
}
|
||||
|
||||
const audio_driver_t audio_xa = {
|
||||
@@ -142,12 +107,8 @@ const audio_driver_t audio_xa = {
|
||||
.stop = __xa_stop,
|
||||
.start = __xa_start,
|
||||
.set_nonblock_state = __xa_set_nonblock_state,
|
||||
.use_float = __xa_use_float,
|
||||
.free = __xa_free,
|
||||
.ident = "xaudio"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+28
-11
@@ -42,23 +42,39 @@ struct autosave
|
||||
static int autosave_thread(void *data)
|
||||
{
|
||||
autosave_t *save = data;
|
||||
|
||||
bool first_log = true;
|
||||
|
||||
while (!save->quit)
|
||||
{
|
||||
autosave_lock(save);
|
||||
memcpy(save->buffer, save->snes_buffer, save->bufsize);
|
||||
bool differ = memcmp(save->buffer, save->snes_buffer, save->bufsize) != 0;
|
||||
if (differ)
|
||||
memcpy(save->buffer, save->snes_buffer, save->bufsize);
|
||||
autosave_unlock(save);
|
||||
|
||||
// Should probably deal with this more elegantly.
|
||||
FILE *file = fopen(save->path, "wb");
|
||||
if (file)
|
||||
if (differ)
|
||||
{
|
||||
SSNES_LOG("Autosaving SRAM to \"%s\"\n", save->path);
|
||||
bool failed = false;
|
||||
failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize;
|
||||
failed |= fflush(file) != 0;
|
||||
failed |= fclose(file) != 0;
|
||||
if (failed)
|
||||
SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n");
|
||||
// Should probably deal with this more elegantly.
|
||||
FILE *file = fopen(save->path, "wb");
|
||||
if (file)
|
||||
{
|
||||
// Avoid spamming down stderr ... :)
|
||||
if (first_log)
|
||||
{
|
||||
SSNES_LOG("Autosaving SRAM to \"%s\", will continue to check every %u seconds ...\n", save->path, save->interval);
|
||||
first_log = false;
|
||||
}
|
||||
else
|
||||
SSNES_LOG("SRAM changed ... autosaving ...\n");
|
||||
|
||||
bool failed = false;
|
||||
failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize;
|
||||
failed |= fflush(file) != 0;
|
||||
failed |= fclose(file) != 0;
|
||||
if (failed)
|
||||
SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n");
|
||||
}
|
||||
}
|
||||
|
||||
SDL_mutexP(save->cond_lock);
|
||||
@@ -87,6 +103,7 @@ autosave_t *autosave_new(const char *path, const void *data, size_t size, unsign
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(handle->buffer, handle->snes_buffer, handle->bufsize);
|
||||
|
||||
handle->lock = SDL_CreateMutex();
|
||||
handle->cond_lock = SDL_CreateMutex();
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "bps.h"
|
||||
#include "movie.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum bps_mode
|
||||
{
|
||||
SOURCE_READ = 0,
|
||||
TARGET_READ,
|
||||
SOURCE_COPY,
|
||||
TARGET_COPY
|
||||
};
|
||||
|
||||
struct bps_data
|
||||
{
|
||||
const uint8_t *modify_data, *source_data;
|
||||
uint8_t *target_data;
|
||||
size_t modify_length, source_length, target_length;
|
||||
size_t modify_offset, source_offset, target_offset;
|
||||
uint32_t modify_checksum, source_checksum, target_checksum;
|
||||
|
||||
size_t source_relative_offset, target_relative_offset, output_offset;
|
||||
};
|
||||
|
||||
static uint8_t bps_read(struct bps_data *bps)
|
||||
{
|
||||
uint8_t data = bps->modify_data[bps->modify_offset++];
|
||||
bps->modify_checksum = crc32_adjust(bps->modify_checksum, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
static uint64_t bps_decode(struct bps_data *bps)
|
||||
{
|
||||
uint64_t data = 0, shift = 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
uint8_t x = bps_read(bps);
|
||||
data += (x & 0x7f) * shift;
|
||||
if (x & 0x80)
|
||||
break;
|
||||
shift <<= 7;
|
||||
data += shift;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static void bps_write(struct bps_data *bps, uint8_t data)
|
||||
{
|
||||
bps->target_data[bps->output_offset++] = data;
|
||||
bps->target_checksum = crc32_adjust(bps->target_checksum, data);
|
||||
}
|
||||
|
||||
bps_error_t bps_apply_patch(
|
||||
const uint8_t *modify_data, size_t modify_length,
|
||||
const uint8_t *source_data, size_t source_length,
|
||||
uint8_t *target_data, size_t *target_length)
|
||||
{
|
||||
if (modify_length < 19)
|
||||
return BPS_PATCH_TOO_SMALL;
|
||||
|
||||
struct bps_data bps = {
|
||||
.modify_data = modify_data,
|
||||
.modify_length = modify_length,
|
||||
.target_data = target_data,
|
||||
.target_length = *target_length,
|
||||
.source_data = source_data,
|
||||
.source_length = source_length,
|
||||
|
||||
.modify_checksum = ~0,
|
||||
.target_checksum = ~0,
|
||||
};
|
||||
|
||||
if ((bps_read(&bps) != 'B') || (bps_read(&bps) != 'P') || (bps_read(&bps) != 'S') || (bps_read(&bps) != '1'))
|
||||
return BPS_PATCH_INVALID_HEADER;
|
||||
|
||||
size_t modify_source_size = bps_decode(&bps);
|
||||
size_t modify_target_size = bps_decode(&bps);
|
||||
size_t modify_markup_size = bps_decode(&bps);
|
||||
for (size_t i = 0; i < modify_markup_size; i++)
|
||||
bps_read(&bps);
|
||||
|
||||
if (modify_source_size > bps.source_length)
|
||||
return BPS_SOURCE_TOO_SMALL;
|
||||
if (modify_target_size > bps.target_length)
|
||||
return BPS_TARGET_TOO_SMALL;
|
||||
|
||||
while (bps.modify_offset < bps.modify_length - 12)
|
||||
{
|
||||
size_t length = bps_decode(&bps);
|
||||
unsigned mode = length & 3;
|
||||
length = (length >> 2) + 1;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case SOURCE_READ:
|
||||
while (length--)
|
||||
bps_write(&bps, bps.source_data[bps.output_offset]);
|
||||
break;
|
||||
|
||||
case TARGET_READ:
|
||||
while (length--)
|
||||
bps_write(&bps, bps_read(&bps));
|
||||
break;
|
||||
|
||||
case SOURCE_COPY:
|
||||
case TARGET_COPY:
|
||||
{
|
||||
int offset = bps_decode(&bps);
|
||||
bool negative = offset & 1;
|
||||
offset >>= 1;
|
||||
if (negative)
|
||||
offset = -offset;
|
||||
|
||||
if (mode == SOURCE_COPY)
|
||||
{
|
||||
bps.source_offset += offset;
|
||||
while (length--)
|
||||
bps_write(&bps, bps.source_data[bps.source_offset++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
bps.target_offset += offset;
|
||||
while (length--)
|
||||
bps_write(&bps, bps.target_data[bps.target_offset++]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t modify_source_checksum = 0, modify_target_checksum = 0, modify_modify_checksum = 0;
|
||||
for (unsigned i = 0; i < 32; i += 8)
|
||||
modify_source_checksum |= bps_read(&bps) << i;
|
||||
for (unsigned i = 0; i < 32; i += 8)
|
||||
modify_target_checksum |= bps_read(&bps) << i;
|
||||
|
||||
uint32_t checksum = ~bps.modify_checksum;
|
||||
for (unsigned i = 0; i < 32; i += 8)
|
||||
modify_modify_checksum |= bps_read(&bps) << i;
|
||||
|
||||
bps.source_checksum = crc32_calculate(bps.source_data, bps.source_length);
|
||||
bps.target_checksum = ~bps.target_checksum;
|
||||
|
||||
if (bps.source_checksum != modify_source_checksum)
|
||||
return BPS_SOURCE_CHECKSUM_INVALID;
|
||||
if (bps.target_checksum != modify_target_checksum)
|
||||
return BPS_TARGET_CHECKSUM_INVALID;
|
||||
if (checksum != modify_modify_checksum)
|
||||
return BPS_PATCH_CHECKSUM_INVALID;
|
||||
|
||||
*target_length = modify_target_size;
|
||||
|
||||
return BPS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __BPS_H
|
||||
#define __BPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// BPS implementation from bSNES (nall::).
|
||||
|
||||
typedef enum bps_error
|
||||
{
|
||||
BPS_UNKNOWN,
|
||||
BPS_SUCCESS,
|
||||
BPS_PATCH_TOO_SMALL,
|
||||
BPS_PATCH_INVALID_HEADER,
|
||||
BPS_SOURCE_TOO_SMALL,
|
||||
BPS_TARGET_TOO_SMALL,
|
||||
BPS_SOURCE_CHECKSUM_INVALID,
|
||||
BPS_TARGET_CHECKSUM_INVALID,
|
||||
BPS_PATCH_CHECKSUM_INVALID
|
||||
} bps_error_t;
|
||||
|
||||
bps_error_t bps_apply_patch(
|
||||
const uint8_t *patch_data, size_t patch_length,
|
||||
const uint8_t *source_data, size_t source_length,
|
||||
uint8_t *target_data, size_t *target_length);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,10 +21,17 @@
|
||||
#include "general.h"
|
||||
#include "strl.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
#include "conf/config_file.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
@@ -51,7 +58,8 @@ static char* strcat_alloc(char *dest, const char *input)
|
||||
size_t required_len = dest_len + input_len + 1;
|
||||
|
||||
char *output = realloc(dest, required_len);
|
||||
assert(output);
|
||||
if (!output)
|
||||
return NULL;
|
||||
|
||||
if (dest)
|
||||
strlcat(output, input, required_len);
|
||||
@@ -61,62 +69,175 @@ static char* strcat_alloc(char *dest, const char *input)
|
||||
return output;
|
||||
}
|
||||
|
||||
static void xml_grab_cheat(struct cheat *cht, xmlNodePtr ptr)
|
||||
static bool xml_grab_cheat(struct cheat *cht, xmlNodePtr ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return false;
|
||||
|
||||
memset(cht, 0, sizeof(struct cheat));
|
||||
bool first = true;
|
||||
for (xmlNodePtr node = ptr; node; node = node->next)
|
||||
|
||||
for (; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (strcmp((const char*)node->name, "description") == 0)
|
||||
if (strcmp((const char*)ptr->name, "description") == 0)
|
||||
{
|
||||
cht->desc = (char*)xmlNodeGetContent(node);
|
||||
cht->desc = (char*)xmlNodeGetContent(ptr);
|
||||
}
|
||||
else if (strcmp((const char*)node->name, "code") == 0)
|
||||
else if (strcmp((const char*)ptr->name, "code") == 0)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
cht->code = strcat_alloc(cht->code, "+");
|
||||
if (!cht->code)
|
||||
return false;
|
||||
}
|
||||
|
||||
xmlChar *code = xmlNodeGetContent(node);
|
||||
assert(code);
|
||||
xmlChar *code = xmlNodeGetContent(ptr);
|
||||
if (!code)
|
||||
return false;
|
||||
|
||||
cht->code = strcat_alloc(cht->code, (const char*)code);
|
||||
xmlFree(code);
|
||||
if (!cht->code)
|
||||
return false;
|
||||
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void xml_grab_cheats(cheat_manager_t *handle, xmlNodePtr ptr)
|
||||
static bool xml_grab_cheats(cheat_manager_t *handle, xmlNodePtr ptr)
|
||||
{
|
||||
xmlNodePtr node = NULL;
|
||||
for (node = ptr; node; node = node->next)
|
||||
for (; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (strcmp((const char*)node->name, "name") == 0)
|
||||
if (strcmp((const char*)ptr->name, "name") == 0)
|
||||
{
|
||||
xmlChar *name = xmlNodeGetContent(node);
|
||||
xmlChar *name = xmlNodeGetContent(ptr);
|
||||
if (name)
|
||||
{
|
||||
SSNES_LOG("Found cheat for game: \"%s\"\n", name);
|
||||
xmlFree(name);
|
||||
}
|
||||
}
|
||||
else if (strcmp((const char*)node->name, "cheat") == 0)
|
||||
else if (strcmp((const char*)ptr->name, "cheat") == 0)
|
||||
{
|
||||
if (handle->size == handle->buf_size)
|
||||
{
|
||||
handle->buf_size *= 2;
|
||||
handle->cheats = realloc(handle->cheats, handle->buf_size * sizeof(struct cheat));
|
||||
assert(handle->cheats);
|
||||
if (!handle->cheats)
|
||||
return false;
|
||||
}
|
||||
|
||||
xml_grab_cheat(&handle->cheats[handle->size++], node->children);
|
||||
if (xml_grab_cheat(&handle->cheats[handle->size], ptr->children))
|
||||
handle->size++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void cheat_manager_apply_cheats(cheat_manager_t *handle)
|
||||
{
|
||||
unsigned index = 0;
|
||||
psnes_cheat_reset();
|
||||
for (unsigned i = 0; i < handle->size; i++)
|
||||
{
|
||||
if (handle->cheats[i].state)
|
||||
psnes_cheat_set(index++, true, handle->cheats[i].code);
|
||||
}
|
||||
}
|
||||
|
||||
static void cheat_manager_load_config(cheat_manager_t *handle, const char *path, const char *sha256)
|
||||
{
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
if (!(*path))
|
||||
return;
|
||||
|
||||
config_file_t *conf = config_file_new(path);
|
||||
if (!conf)
|
||||
return;
|
||||
|
||||
char *str;
|
||||
if (!config_get_string(conf, sha256, &str))
|
||||
{
|
||||
config_file_free(conf);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *num = strtok(str, ";");
|
||||
while (num)
|
||||
{
|
||||
unsigned index = strtoul(num, NULL, 0);
|
||||
if (index < handle->size)
|
||||
handle->cheats[index].state = true;
|
||||
|
||||
num = strtok(NULL, ";");
|
||||
}
|
||||
|
||||
free(str);
|
||||
config_file_free(conf);
|
||||
|
||||
cheat_manager_apply_cheats(handle);
|
||||
|
||||
#else
|
||||
(void)handle;
|
||||
(void)path;
|
||||
(void)sha256;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cheat_manager_save_config(cheat_manager_t *handle, const char *path, const char *sha256)
|
||||
{
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
if (!(*path))
|
||||
return;
|
||||
|
||||
config_file_t *conf = config_file_new(path);
|
||||
if (!conf)
|
||||
conf = config_file_new(NULL);
|
||||
|
||||
if (!conf)
|
||||
{
|
||||
SSNES_ERR("Cannot save XML cheat settings!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char conf_str[512] = {0};
|
||||
char tmp[32] = {0};
|
||||
|
||||
for (unsigned i = 0; i < handle->size; i++)
|
||||
{
|
||||
if (handle->cheats[i].state)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "%u;", i);
|
||||
strlcat(conf_str, tmp, sizeof(conf_str));
|
||||
}
|
||||
}
|
||||
|
||||
if (*conf_str)
|
||||
conf_str[strlen(conf_str) - 1] = '\0'; // Remove the trailing ';'
|
||||
|
||||
config_set_string(conf, sha256, conf_str);
|
||||
|
||||
if (!config_file_write(conf, path))
|
||||
SSNES_ERR("Failed to write XML cheat settings to \"%s\"! Check permissions!\n", path);
|
||||
|
||||
config_file_free(conf);
|
||||
|
||||
#else
|
||||
(void)handle;
|
||||
(void)path;
|
||||
(void)sha256;
|
||||
#endif
|
||||
}
|
||||
|
||||
cheat_manager_t* cheat_manager_new(const char *path)
|
||||
{
|
||||
LIBXML_TEST_VERSION;
|
||||
|
||||
psnes_cheat_reset();
|
||||
|
||||
xmlParserCtxtPtr ctx = NULL;
|
||||
@@ -125,8 +246,8 @@ cheat_manager_t* cheat_manager_new(const char *path)
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
handle->buf_size = 32;
|
||||
handle->cheats = malloc(handle->buf_size * sizeof(struct cheat));
|
||||
handle->buf_size = 1;
|
||||
handle->cheats = calloc(handle->buf_size, sizeof(struct cheat));
|
||||
if (!handle->cheats)
|
||||
{
|
||||
handle->buf_size = 0;
|
||||
@@ -172,7 +293,7 @@ cheat_manager_t* cheat_manager_new(const char *path)
|
||||
if (!sha256)
|
||||
continue;
|
||||
|
||||
if (memcmp(sha256, g_extern.sha256, 64) == 0)
|
||||
if (strcmp((const char*)sha256, g_extern.sha256) == 0)
|
||||
{
|
||||
xmlFree(sha256);
|
||||
break;
|
||||
@@ -185,7 +306,19 @@ cheat_manager_t* cheat_manager_new(const char *path)
|
||||
if (!cur)
|
||||
goto error;
|
||||
|
||||
xml_grab_cheats(handle, cur->children);
|
||||
if (!xml_grab_cheats(handle, cur->children))
|
||||
{
|
||||
SSNES_ERR("Failed to grab cheats. This should not happen.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (handle->size == 0)
|
||||
{
|
||||
SSNES_ERR("Did not find any cheats in XML file: %s\n", path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
cheat_manager_load_config(handle, g_settings.cheat_settings_path, g_extern.sha256);
|
||||
|
||||
xmlFreeDoc(doc);
|
||||
xmlFreeParserCtxt(ctx);
|
||||
@@ -207,6 +340,7 @@ void cheat_manager_free(cheat_manager_t *handle)
|
||||
|
||||
if (handle->cheats)
|
||||
{
|
||||
cheat_manager_save_config(handle, g_settings.cheat_settings_path, g_extern.sha256);
|
||||
for (unsigned i = 0; i < handle->size; i++)
|
||||
{
|
||||
xmlFree(handle->cheats[i].desc);
|
||||
@@ -228,18 +362,11 @@ static void cheat_manager_update(cheat_manager_t *handle)
|
||||
SSNES_LOG("%s\n", msg);
|
||||
}
|
||||
|
||||
|
||||
void cheat_manager_toggle(cheat_manager_t *handle)
|
||||
{
|
||||
handle->cheats[handle->ptr].state ^= true;
|
||||
|
||||
unsigned index = 0;
|
||||
psnes_cheat_reset();
|
||||
for (unsigned i = 0; i < handle->size; i++)
|
||||
{
|
||||
if (handle->cheats[handle->ptr].state)
|
||||
psnes_cheat_set(index++, true, handle->cheats[handle->ptr].code);
|
||||
}
|
||||
|
||||
cheat_manager_apply_cheats(handle);
|
||||
cheat_manager_update(handle);
|
||||
}
|
||||
|
||||
|
||||
+37
-5
@@ -21,6 +21,8 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include "strl.h"
|
||||
|
||||
struct entry_list
|
||||
{
|
||||
@@ -215,8 +217,15 @@ bool config_get_int(config_file_t *conf, const char *key, int *in)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
*in = strtol(list->value, NULL, 0);
|
||||
return true;
|
||||
errno = 0;
|
||||
int val = strtol(list->value, NULL, 0);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
return
|
||||
false;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
@@ -231,8 +240,15 @@ bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
*in = strtol(list->value, NULL, 16);
|
||||
return true;
|
||||
errno = 0;
|
||||
unsigned val = strtoul(list->value, NULL, 16);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
@@ -247,7 +263,7 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
if (strlen(list->value) > 1)
|
||||
if (list->value[0] && list->value[1])
|
||||
return false;
|
||||
*in = *list->value;
|
||||
return true;
|
||||
@@ -273,6 +289,22 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_array(config_file_t *conf, const char *key, char *buf, size_t size)
|
||||
{
|
||||
struct entry_list *list = conf->entries;
|
||||
|
||||
while (list != NULL)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
strlcpy(buf, list->value, size);
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
||||
{
|
||||
struct entry_list *list = conf->entries;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct config_file config_file_t;
|
||||
|
||||
@@ -48,6 +49,8 @@ bool config_get_hex(config_file_t *conf, const char *entry, unsigned *in);
|
||||
bool config_get_char(config_file_t *conf, const char *entry, char *in);
|
||||
// Extracts an allocated string in *in. This must be free()-d if this function succeeds.
|
||||
bool config_get_string(config_file_t *conf, const char *entry, char **in);
|
||||
// Extracts a string to a preallocated buffer. Avoid memory allocation.
|
||||
bool config_get_array(config_file_t *conf, const char *entry, char *in, size_t size);
|
||||
// Extracts a boolean from config. Valid boolean true are "true" and "1". Valid false are "false" and "0". Other values will be treated as an error.
|
||||
bool config_get_bool(config_file_t *conf, const char *entry, bool *in);
|
||||
|
||||
|
||||
+70
-54
@@ -30,17 +30,12 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
#include "SDL.h"
|
||||
#else
|
||||
#error "HAVE_SDL is not defined!"
|
||||
#endif
|
||||
#include "input/keysym.h"
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
#include <samplerate.h>
|
||||
#endif
|
||||
|
||||
|
||||
///////////////// Drivers
|
||||
#define VIDEO_GL 0
|
||||
#define VIDEO_XVIDEO 11
|
||||
@@ -57,6 +52,8 @@
|
||||
#define AUDIO_XAUDIO 9
|
||||
#define AUDIO_PULSE 10
|
||||
#define AUDIO_EXT 15
|
||||
#define AUDIO_DSOUND 16
|
||||
#define AUDIO_COREAUDIO 17
|
||||
////////////////////////
|
||||
#define INPUT_SDL 7
|
||||
#define INPUT_X 12
|
||||
@@ -82,8 +79,12 @@
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_OSS
|
||||
#elif defined(HAVE_JACK)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_JACK
|
||||
#elif defined(HAVE_COREAUDIO)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_COREAUDIO
|
||||
#elif defined(HAVE_AL)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_AL
|
||||
#elif defined(HAVE_DSOUND)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_DSOUND
|
||||
#elif defined(HAVE_SDL)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_SDL
|
||||
#elif defined(HAVE_XAUDIO)
|
||||
@@ -123,6 +124,9 @@ static const unsigned fullscreen_y = 0;
|
||||
// Force 16-bit colors.
|
||||
static const bool force_16bit = false;
|
||||
|
||||
// Forcibly disable composition. Only valid on Windows Vista/7 for now.
|
||||
static const bool disable_composition = false;
|
||||
|
||||
// Video VSYNC (recommended)
|
||||
static const bool vsync = true;
|
||||
|
||||
@@ -141,6 +145,8 @@ static const unsigned font_size = 48;
|
||||
// Offset for where messages will be placed on-screen. Values are in range [0.0, 1.0].
|
||||
static const float message_pos_offset_x = 0.05;
|
||||
static const float message_pos_offset_y = 0.05;
|
||||
// Color of the message.
|
||||
static const uint32_t message_color = 0xffffff; // RGB hex value.
|
||||
|
||||
// Render-to-texture before rendering to screen (multi-pass shaders)
|
||||
static const bool render_to_texture = false;
|
||||
@@ -148,6 +154,12 @@ static const float fbo_scale_x = 2.0;
|
||||
static const float fbo_scale_y = 2.0;
|
||||
static const bool second_pass_smooth = true;
|
||||
|
||||
// Record video assuming game runs hi-res.
|
||||
static const bool hires_record = false;
|
||||
|
||||
// Record post-filtered (CPU filter) video rather than raw SNES output.
|
||||
static const bool post_filter_record = false;
|
||||
|
||||
#define SNES_ASPECT_RATIO (4.0/3)
|
||||
|
||||
////////////////
|
||||
@@ -198,7 +210,11 @@ static const bool pause_nonactive = true;
|
||||
static const unsigned autosave_interval = 0;
|
||||
|
||||
// When being client over netplay, use keybinds for player 1 rather than player 2.
|
||||
static const bool netplay_client_swap_input = false;
|
||||
static const bool netplay_client_swap_input = true;
|
||||
|
||||
// On save state load, block SRAM from being overwritten.
|
||||
// This could potentially lead to buggy games.
|
||||
static const bool block_sram_overwrite = false;
|
||||
|
||||
|
||||
////////////////////
|
||||
@@ -207,64 +223,64 @@ static const bool netplay_client_swap_input = false;
|
||||
|
||||
// Axis threshold (between 0.0 and 1.0)
|
||||
// How far an axis must be tilted to result in a button press
|
||||
#define AXIS_THRESHOLD 0.5
|
||||
static const float axis_threshold = 0.5;
|
||||
|
||||
// To figure out which joypad buttons to use, check jstest or similar.
|
||||
// SDL sometimes reverses the axes for some odd reason, but hey. :D
|
||||
|
||||
// Player 1
|
||||
static const struct snes_keybind snes_keybinds_1[] = {
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_x, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_z, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_s, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_a, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_q, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_w, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_LEFT, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_RIGHT, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_UP, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_DOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_RETURN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_RSHIFT, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FAST_FORWARD_KEY, SDLK_SPACE, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FAST_FORWARD_HOLD_KEY, SDLK_l, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SAVE_STATE_KEY, SDLK_F2, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_LOAD_STATE_KEY, SDLK_F4, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FULLSCREEN_TOGGLE_KEY, SDLK_f, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_QUIT_KEY, SDLK_ESCAPE, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_STATE_SLOT_MINUS, SDLK_F6, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_STATE_SLOT_PLUS, SDLK_F7, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_AUDIO_INPUT_RATE_PLUS, SDLK_KP_PLUS, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_AUDIO_INPUT_RATE_MINUS, SDLK_KP_MINUS, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_REWIND, SDLK_r, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_MOVIE_RECORD_TOGGLE, SDLK_o, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_PAUSE_TOGGLE, SDLK_p, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_RESET, SDLK_h, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_NEXT, SDLK_m, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_PREV, SDLK_n, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_PLUS, SDLK_y, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_MINUS, SDLK_t, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_TOGGLE, SDLK_u, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SCREENSHOT, SDLK_PRINT, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_DSP_CONFIG, SDLK_c, NO_BTN, AXIS_NONE },
|
||||
// SNES button | keyboard key | js btn | js axis |
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, SK_x, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, SK_z, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, SK_s, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, SK_a, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, SK_q, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, SK_w, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, SK_LEFT, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SK_RIGHT, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, SK_UP, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, SK_DOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, SK_RETURN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, SK_RSHIFT, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FAST_FORWARD_KEY, SK_SPACE, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FAST_FORWARD_HOLD_KEY, SK_l, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SAVE_STATE_KEY, SK_F2, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_LOAD_STATE_KEY, SK_F4, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_FULLSCREEN_TOGGLE_KEY, SK_f, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_QUIT_KEY, SK_ESCAPE, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_STATE_SLOT_MINUS, SK_F6, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_STATE_SLOT_PLUS, SK_F7, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_AUDIO_INPUT_RATE_PLUS, SK_KP_PLUS, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_AUDIO_INPUT_RATE_MINUS, SK_KP_MINUS, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_REWIND, SK_r, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_MOVIE_RECORD_TOGGLE, SK_o, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_PAUSE_TOGGLE, SK_p, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_RESET, SK_h, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_NEXT, SK_m, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_PREV, SK_n, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_PLUS, SK_y, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_MINUS, SK_t, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_TOGGLE, SK_u, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SCREENSHOT, SK_PRINT, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_DSP_CONFIG, SK_c, NO_BTN, AXIS_NONE },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
// Player 2-5
|
||||
static const struct snes_keybind snes_keybinds_rest[] = {
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_A, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_B, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_X, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_Y, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_L, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_R, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_LEFT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_UP, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_DOWN, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_START, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ SNES_DEVICE_ID_JOYPAD_SELECT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ static const bool _sdl_supp = true;
|
||||
static const bool _sdl_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XVIDEO
|
||||
static const bool _xvideo_supp = true;
|
||||
#else
|
||||
static const bool _xvideo_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ALSA
|
||||
static const bool _alsa_supp = true;
|
||||
#else
|
||||
|
||||
+24
-2
@@ -32,19 +32,30 @@ Prints help text.
|
||||
Overrides the path used for save ram (*.srm).
|
||||
Without this flag, the save ram path will be inferred from the rom path name, and put in the same directory as the rom file with the extention replaced with '.srm'.
|
||||
When rom is loaded from \fBstdin\fR, this flag is mandatory to define as no path can be inferred.
|
||||
If PATH is a directory, SSNES will treat this as the save file directory, where the save file name will be inferred from the rom name.
|
||||
When loading a rom from stdin, the path must be a full path, however.
|
||||
|
||||
.TP
|
||||
\fB--savestate PATH, -S path\fR
|
||||
\fB--savestate PATH, -S PATH\fR
|
||||
Overrides the path used for save states.
|
||||
Without this flag, the save state path will be inferred from the rom path name, and put in the same directory as the rom file with the extention replace with '.state'.
|
||||
When rom is loaded from \fBstdin\fR, this flag is mandatory to define as no path can be inferred.
|
||||
If PATH is a directory, SSNES will treat this as the save state directory, where the state file name will be inferred from the rom name.
|
||||
When loading a rom from stdin, the path must be a full path, however.
|
||||
Do note that save states are bound to the libsnes implementation being used. Using a different libsnes could invalidate the save state file.
|
||||
|
||||
.TP
|
||||
\fB--fullscreen, -f\fR
|
||||
Always starts SSNES in fullscreen. Disregards settings in configuration file.
|
||||
|
||||
.TP
|
||||
\fB--config PATH, -c PATH\fR
|
||||
Sets the configuration file path. \fBssnes\fR will use this path to load the configuration file.
|
||||
Should this not be defined, \fBssnes\fR will look in platform specific paths to attempt finding the config file.
|
||||
/etc/ssnes.cfg (when installed), or ssnes.cfg in the source tarball serves as a skeleton configuration file.
|
||||
If PATH is a directory, SSNES will treat this as the config file directory, where the state file name will be inferred from the rom name (*.cfg).
|
||||
When loading a rom from stdin, the path must be a full path, however.
|
||||
If a config cannot be found when using directory path, the default config path will be used instead.
|
||||
|
||||
.IP
|
||||
Unix-like systems will look in $XDG_CONFIG_HOME/ssnes/ssnes.cfg first. Then it will try $HOME/.ssnes.cfg. Last, it will try /etc/ssnes.cfg. If no configuration is found, default settings will be assumed. A configuration file does not need to define every possible option, only those that should be overridden.
|
||||
@@ -101,7 +112,8 @@ Connects a four-way multitap into port 2 of the SNES. This allows for up to 5 pl
|
||||
|
||||
.TP
|
||||
\fB--record PATH, -r PATH\fR
|
||||
Activates video recording of gameplay into PATH. Video recording options can be configured in config file.
|
||||
Activates video recording of gameplay into PATH. Using .mkv extension is recommended.
|
||||
Codecs used are FFV1/FLAC, suitable for processing the material further.
|
||||
|
||||
.TP
|
||||
\fB--bsvplay PATH, -P PATH\fR
|
||||
@@ -134,6 +146,16 @@ Network port used for netplay. This defaults to 55435. This option affects both
|
||||
Attempts to apply an UPS patch to the current ROM image. No files are altered.
|
||||
If this flag is not specified, SSNES will look for a .ups file with same basename as ROM specified.
|
||||
|
||||
.TP
|
||||
\fB--bps PATCH\fR
|
||||
Attempts to apply a BPS patch to the current ROM image. No files are altered.
|
||||
If this flag is not specified, SSNES will look for a .bps file with same basename as ROM specified.
|
||||
|
||||
.TP
|
||||
\fB--xml MAP, -X MAP\fR
|
||||
Specifies path to XML memory map for the given ROM.
|
||||
If this flag is not specified, SSNES will look for a .xml file with same basename as ROM specified.
|
||||
|
||||
.TP
|
||||
\fB-D, --detach\fR
|
||||
Detach from the current console. This is currently only relevant for Microsoft Windows.
|
||||
|
||||
@@ -38,6 +38,9 @@ static const audio_driver_t *audio_drivers[] = {
|
||||
#ifdef HAVE_RSOUND
|
||||
&audio_rsound,
|
||||
#endif
|
||||
#ifdef HAVE_COREAUDIO
|
||||
&audio_coreaudio,
|
||||
#endif
|
||||
#ifdef HAVE_AL
|
||||
&audio_openal,
|
||||
#endif
|
||||
@@ -53,6 +56,9 @@ static const audio_driver_t *audio_drivers[] = {
|
||||
#ifdef HAVE_XAUDIO
|
||||
&audio_xa,
|
||||
#endif
|
||||
#ifdef HAVE_DSOUND
|
||||
&audio_dsound,
|
||||
#endif
|
||||
#ifdef HAVE_PULSE
|
||||
&audio_pulse,
|
||||
#endif
|
||||
@@ -162,7 +168,7 @@ static void init_dsp_plugin(void)
|
||||
}
|
||||
|
||||
const ssnes_dsp_plugin_t* (*SSNES_API_CALLTYPE plugin_init)(void) =
|
||||
(const ssnes_dsp_plugin_t *(*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init");
|
||||
(const ssnes_dsp_plugin_t *(SSNES_API_CALLTYPE*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init");
|
||||
if (!plugin_init)
|
||||
{
|
||||
SSNES_ERR("Failed to find symbol \"ssnes_dsp_plugin_init\" in DSP plugin.\n");
|
||||
@@ -184,7 +190,7 @@ static void init_dsp_plugin(void)
|
||||
|
||||
SSNES_LOG("Loaded DSP plugin: \"%s\"\n", g_extern.audio_data.dsp_plugin->ident ? g_extern.audio_data.dsp_plugin->ident : "Unknown");
|
||||
|
||||
ssnes_dsp_info_t info = {
|
||||
const ssnes_dsp_info_t info = {
|
||||
.input_rate = g_settings.audio.in_rate,
|
||||
.output_rate = g_settings.audio.out_rate
|
||||
};
|
||||
@@ -393,6 +399,9 @@ static void deinit_shader_dir(void)
|
||||
{
|
||||
// It handles NULL, no worries :D
|
||||
dir_list_free(g_extern.shader_dir.elems);
|
||||
g_extern.shader_dir.elems = NULL;
|
||||
g_extern.shader_dir.size = 0;
|
||||
g_extern.shader_dir.ptr = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -450,7 +459,7 @@ void init_video_input(void)
|
||||
const input_driver_t *tmp = driver.input;
|
||||
driver.video_data = driver.video->init(&video, &driver.input, &driver.input_data);
|
||||
|
||||
if ( driver.video_data == NULL )
|
||||
if (driver.video_data == NULL)
|
||||
{
|
||||
SSNES_ERR("Cannot open video driver ... Exiting ...\n");
|
||||
exit(1);
|
||||
@@ -463,7 +472,7 @@ void init_video_input(void)
|
||||
if (driver.input != NULL)
|
||||
{
|
||||
driver.input_data = driver.input->init();
|
||||
if ( driver.input_data == NULL )
|
||||
if (driver.input_data == NULL)
|
||||
{
|
||||
SSNES_ERR("Cannot init input driver. Exiting ...\n");
|
||||
exit(1);
|
||||
@@ -479,12 +488,12 @@ void init_video_input(void)
|
||||
|
||||
void uninit_video_input(void)
|
||||
{
|
||||
if ( driver.video_data && driver.video )
|
||||
driver.video->free(driver.video_data);
|
||||
|
||||
if ( driver.input_data != driver.video_data && driver.input )
|
||||
if (driver.input_data != driver.video_data && driver.input)
|
||||
driver.input->free(driver.input_data);
|
||||
|
||||
if (driver.video_data && driver.video)
|
||||
driver.video->free(driver.video_data);
|
||||
|
||||
deinit_filter();
|
||||
|
||||
#ifdef HAVE_XML
|
||||
|
||||
@@ -24,10 +24,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "input/keysym.h"
|
||||
|
||||
enum
|
||||
{
|
||||
SSNES_FAST_FORWARD_KEY = 0x666, // Hurr, durr
|
||||
SSNES_FAST_FORWARD_KEY = 12, // SNES has 12 buttons from 0-11 (libsnes.hpp)
|
||||
SSNES_FAST_FORWARD_HOLD_KEY,
|
||||
SSNES_LOAD_STATE_KEY,
|
||||
SSNES_SAVE_STATE_KEY,
|
||||
@@ -47,14 +48,16 @@ enum
|
||||
SSNES_CHEAT_INDEX_MINUS,
|
||||
SSNES_CHEAT_TOGGLE,
|
||||
SSNES_SCREENSHOT,
|
||||
SSNES_DSP_CONFIG
|
||||
SSNES_DSP_CONFIG,
|
||||
|
||||
SSNES_BIND_LIST_END
|
||||
};
|
||||
|
||||
|
||||
struct snes_keybind
|
||||
{
|
||||
int id;
|
||||
uint16_t key;
|
||||
enum ssnes_key key;
|
||||
uint16_t joykey;
|
||||
uint32_t joyaxis;
|
||||
};
|
||||
@@ -158,6 +161,8 @@ extern const audio_driver_t audio_sdl;
|
||||
extern const audio_driver_t audio_xa;
|
||||
extern const audio_driver_t audio_pulse;
|
||||
extern const audio_driver_t audio_ext;
|
||||
extern const audio_driver_t audio_dsound;
|
||||
extern const audio_driver_t audio_coreaudio;
|
||||
extern const video_driver_t video_gl;
|
||||
extern const video_driver_t video_xvideo;
|
||||
extern const video_driver_t video_sdl;
|
||||
|
||||
@@ -184,6 +184,26 @@ void init_dlsym(void)
|
||||
assert(sizeof(void*) == sizeof(void (*)(void)));
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
|
||||
#ifndef _WIN32 // Try to verify that -lsnes was not linked in from other modules
|
||||
// since loading it dynamically and with -l will fail hard.
|
||||
void *lib = dlopen(NULL, RTLD_LAZY);
|
||||
if (lib)
|
||||
{
|
||||
void *sym = dlsym(lib, "snes_init");
|
||||
if (sym)
|
||||
{
|
||||
SSNES_ERR("Serious problem! SSNES wants to load libsnes dyamically, but it is already linked!\n");
|
||||
SSNES_ERR("This could happen if other modules SSNES depends on link against libsnes directly.\n");
|
||||
SSNES_ERR("Proceeding could cause a crash! Aborting ...\n");
|
||||
dlclose(lib);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dlclose(lib);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strlen(g_settings.libsnes) > 0)
|
||||
load_dynamic();
|
||||
else
|
||||
|
||||
@@ -21,9 +21,12 @@
|
||||
#include <stdbool.h>
|
||||
#include <libsnes.hpp>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include "dynamic.h"
|
||||
#include "movie.h"
|
||||
#include "ups.h"
|
||||
#include "bps.h"
|
||||
#include "strl.h"
|
||||
|
||||
#ifdef HAVE_XML
|
||||
@@ -34,8 +37,10 @@
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <windows.h>
|
||||
#include <shlwapi.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
@@ -51,7 +56,7 @@ ssize_t read_file(const char *path, void **buf)
|
||||
long len = ftell(file);
|
||||
ssize_t rc = 0;
|
||||
rewind(file);
|
||||
rom_buf = malloc(len);
|
||||
rom_buf = malloc(len + 1);
|
||||
if (!rom_buf)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
@@ -62,6 +67,9 @@ ssize_t read_file(const char *path, void **buf)
|
||||
SSNES_WARN("Didn't read whole file.\n");
|
||||
|
||||
*buf = rom_buf;
|
||||
// Allow for easy reading of strings to be safe.
|
||||
// Will only work with sane character formatting (Unix).
|
||||
((char*)rom_buf)[len] = '\0';
|
||||
fclose(file);
|
||||
return rc;
|
||||
|
||||
@@ -73,6 +81,154 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Reads file content as one string.
|
||||
bool read_file_string(const char *path, char **buf)
|
||||
{
|
||||
*buf = NULL;
|
||||
FILE *file = fopen(path, "r");
|
||||
if (!file)
|
||||
goto error;
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long len = ftell(file) + 2; // Takes account of being able to read in EOF and '\0' at end.
|
||||
rewind(file);
|
||||
|
||||
*buf = calloc(len, sizeof(char));
|
||||
if (!*buf)
|
||||
goto error;
|
||||
|
||||
char *ptr = *buf;
|
||||
|
||||
while (ptr && !feof(file))
|
||||
{
|
||||
size_t bufsize = (size_t)(((ptrdiff_t)*buf + (ptrdiff_t)len) - (ptrdiff_t)ptr);
|
||||
fgets(ptr, bufsize, file);
|
||||
|
||||
ptr = strchr(ptr, '\0');
|
||||
}
|
||||
|
||||
ptr = strchr(ptr, EOF);
|
||||
if (ptr) *ptr = '\0';
|
||||
|
||||
fclose(file);
|
||||
return true;
|
||||
|
||||
error:
|
||||
if (file)
|
||||
fclose(file);
|
||||
if (*buf)
|
||||
free(*buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
enum patch_type
|
||||
{
|
||||
PATCH_NONE,
|
||||
PATCH_UPS,
|
||||
PATCH_BPS
|
||||
};
|
||||
|
||||
static void patch_rom(uint8_t **buf, ssize_t *size)
|
||||
{
|
||||
uint8_t *ret_buf = *buf;
|
||||
ssize_t ret_size = *size;
|
||||
|
||||
ssize_t patch_size = 0;
|
||||
void *patch_data = NULL;
|
||||
enum patch_type type = PATCH_NONE;
|
||||
|
||||
if (g_extern.ups_pref && g_extern.bps_pref)
|
||||
{
|
||||
SSNES_WARN("Both UPS and BPS patch explicitly defined, ignoring both ...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_extern.bps_pref && *g_extern.ups_name && (patch_size = read_file(g_extern.ups_name, &patch_data)) >= 0)
|
||||
type = PATCH_UPS;
|
||||
else if (!g_extern.ups_pref && *g_extern.bps_name && (patch_size = read_file(g_extern.bps_name, &patch_data)) >= 0)
|
||||
type = PATCH_BPS;
|
||||
|
||||
if (type == PATCH_NONE)
|
||||
{
|
||||
SSNES_LOG("Did not find a valid ROM patch.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case PATCH_UPS:
|
||||
SSNES_LOG("Found UPS file in \"%s\", attempting to patch ...\n", g_extern.ups_name);
|
||||
break;
|
||||
case PATCH_BPS:
|
||||
SSNES_LOG("Found BPS file in \"%s\", attempting to patch ...\n", g_extern.bps_name);
|
||||
break;
|
||||
|
||||
default:
|
||||
return; // Should not happen, but.
|
||||
}
|
||||
|
||||
size_t target_size = ret_size * 4; // Just to be sure ...
|
||||
uint8_t *patched_rom = malloc(target_size);
|
||||
if (!patched_rom)
|
||||
{
|
||||
SSNES_ERR("Failed to allocate memory for patched ROM ...\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
bool success = false;
|
||||
switch (type)
|
||||
{
|
||||
case PATCH_UPS:
|
||||
{
|
||||
ups_error_t err = ups_apply_patch(patch_data, patch_size, ret_buf, ret_size, patched_rom, &target_size);
|
||||
if (err == UPS_SUCCESS)
|
||||
{
|
||||
SSNES_LOG("ROM patched successfully (UPS)!\n");
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
SSNES_ERR("Failed to patch UPS: Error #%u\n", (unsigned)err);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PATCH_BPS:
|
||||
{
|
||||
bps_error_t err = bps_apply_patch(patch_data, patch_size, ret_buf, ret_size, patched_rom, &target_size);
|
||||
if (err == BPS_SUCCESS)
|
||||
{
|
||||
SSNES_LOG("ROM patched successfully (BPS)!\n");
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
SSNES_ERR("Failed to patch BPS: Error #%u\n", (unsigned)err);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
free(ret_buf);
|
||||
*buf = patched_rom;
|
||||
*size = target_size;
|
||||
}
|
||||
|
||||
if (patch_data)
|
||||
free(patch_data);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
*buf = ret_buf;
|
||||
*size = ret_size;
|
||||
if (patch_data)
|
||||
free(patch_data);
|
||||
}
|
||||
|
||||
// Load SNES rom only. Applies a hack for headered ROMs.
|
||||
static ssize_t read_rom_file(FILE* file, void** buf)
|
||||
{
|
||||
@@ -140,37 +296,6 @@ static ssize_t read_rom_file(FILE* file, void** buf)
|
||||
ret_buf = rom_buf;
|
||||
}
|
||||
|
||||
// Patch with UPS.
|
||||
ssize_t ups_patch_size;
|
||||
void *ups_patch = NULL;
|
||||
if (*g_extern.ups_name && (ups_patch_size = read_file(g_extern.ups_name, &ups_patch)) >= 0)
|
||||
{
|
||||
SSNES_LOG("Found UPS file in \"%s\", attempting to patch ...\n", g_extern.ups_name);
|
||||
|
||||
size_t target_size = ret * 4; // Just to be sure ...
|
||||
uint8_t *patched_rom = malloc(target_size);
|
||||
if (patched_rom)
|
||||
{
|
||||
ups_error_t err = ups_apply_patch(ups_patch, ups_patch_size, ret_buf, ret, patched_rom, &target_size);
|
||||
if (err == UPS_SUCCESS)
|
||||
{
|
||||
free(ret_buf);
|
||||
ret_buf = patched_rom;
|
||||
ret = target_size;
|
||||
SSNES_LOG("ROM patched successfully (UPS)!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
free(patched_rom);
|
||||
SSNES_LOG("ROM failed to patch (UPS).\n");
|
||||
}
|
||||
|
||||
free(ups_patch);
|
||||
}
|
||||
}
|
||||
else if (*g_extern.ups_name)
|
||||
SSNES_LOG("Could not find UPS patch in: \"%s\".\n", g_extern.ups_name);
|
||||
|
||||
// Remove copier header if present (512 first bytes).
|
||||
if ((ret & 0x7fff) == 512)
|
||||
{
|
||||
@@ -178,6 +303,9 @@ static ssize_t read_rom_file(FILE* file, void** buf)
|
||||
ret -= 512;
|
||||
}
|
||||
|
||||
// Attempt to apply a patch :)
|
||||
patch_rom(&ret_buf, &ret);
|
||||
|
||||
g_extern.cart_crc = crc32_calculate(ret_buf, ret);
|
||||
#ifdef HAVE_XML
|
||||
sha256_hash(g_extern.sha256, ret_buf, ret);
|
||||
@@ -196,13 +324,72 @@ static bool dump_to_file(const char *path, const void *data, size_t size)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
fwrite(data, 1, size, file);
|
||||
bool ret = fwrite(data, 1, size, file) == size;
|
||||
fclose(file);
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
bool save_state(const char* path)
|
||||
static const char *ramtype2str(int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SNES_MEMORY_CARTRIDGE_RAM:
|
||||
case SNES_MEMORY_GAME_BOY_RAM:
|
||||
case SNES_MEMORY_BSX_RAM:
|
||||
return ".srm";
|
||||
|
||||
case SNES_MEMORY_CARTRIDGE_RTC:
|
||||
case SNES_MEMORY_GAME_BOY_RTC:
|
||||
return ".rtc";
|
||||
|
||||
case SNES_MEMORY_BSX_PRAM:
|
||||
return ".pram";
|
||||
|
||||
case SNES_MEMORY_SUFAMI_TURBO_A_RAM:
|
||||
return ".aram";
|
||||
case SNES_MEMORY_SUFAMI_TURBO_B_RAM:
|
||||
return ".bram";
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to save valuable RAM data somewhere ...
|
||||
static void dump_to_file_desperate(const void *data, size_t size, int type)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char *base = getenv("APPDATA");
|
||||
#else
|
||||
const char *base = getenv("HOME");
|
||||
#endif
|
||||
|
||||
if (!base)
|
||||
goto error;
|
||||
|
||||
char path[MAXPATHLEN];
|
||||
snprintf(path, sizeof(path), "%s/SSNES-recovery-", base);
|
||||
char timebuf[MAXPATHLEN];
|
||||
|
||||
time_t time_;
|
||||
time(&time_);
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
|
||||
strlcat(path, timebuf, sizeof(path));
|
||||
strlcat(path, ramtype2str(type), sizeof(path));
|
||||
|
||||
if (dump_to_file(path, data, size))
|
||||
SSNES_WARN("Succeeded in saving RAM data to \"%s\". Phew! :D\n", path);
|
||||
else
|
||||
goto error;
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
SSNES_WARN("Failed ... Tough luck ... :(\n");
|
||||
}
|
||||
|
||||
bool save_state(const char *path)
|
||||
{
|
||||
SSNES_LOG("Saving state: \"%s\".\n", path);
|
||||
size_t size = psnes_serialize_size();
|
||||
@@ -225,7 +412,7 @@ bool save_state(const char* path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool load_state(const char* path)
|
||||
bool load_state(const char *path)
|
||||
{
|
||||
SSNES_LOG("Loading state: \"%s\".\n", path);
|
||||
void *buf = NULL;
|
||||
@@ -238,14 +425,81 @@ bool load_state(const char* path)
|
||||
else
|
||||
{
|
||||
SSNES_LOG("State size: %d bytes.\n", (int)size);
|
||||
|
||||
uint8_t *block_buf[2] = {NULL, NULL};
|
||||
int block_type[2] = {-1, -1};
|
||||
unsigned block_size[2] = {0};
|
||||
|
||||
if (g_settings.block_sram_overwrite)
|
||||
{
|
||||
SSNES_LOG("Blocking SRAM overwrite!\n");
|
||||
switch (g_extern.game_type)
|
||||
{
|
||||
case SSNES_CART_NORMAL:
|
||||
block_type[0] = SNES_MEMORY_CARTRIDGE_RAM;
|
||||
block_type[1] = SNES_MEMORY_CARTRIDGE_RTC;
|
||||
break;
|
||||
|
||||
case SSNES_CART_BSX:
|
||||
case SSNES_CART_BSX_SLOTTED:
|
||||
block_type[0] = SNES_MEMORY_BSX_RAM;
|
||||
block_type[1] = SNES_MEMORY_BSX_PRAM;
|
||||
break;
|
||||
|
||||
case SSNES_CART_SUFAMI:
|
||||
block_type[0] = SNES_MEMORY_SUFAMI_TURBO_A_RAM;
|
||||
block_type[1] = SNES_MEMORY_SUFAMI_TURBO_B_RAM;
|
||||
break;
|
||||
|
||||
case SSNES_CART_SGB:
|
||||
block_type[0] = SNES_MEMORY_GAME_BOY_RAM;
|
||||
block_type[1] = SNES_MEMORY_GAME_BOY_RTC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
if (block_type[i] != -1)
|
||||
block_size[i] = psnes_get_memory_size(block_type[i]);
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
if (block_size[i])
|
||||
block_buf[i] = malloc(block_size[i]);
|
||||
|
||||
// Backup current SRAM which is overwritten by unserialize.
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
if (block_buf[i])
|
||||
{
|
||||
const uint8_t *ptr = psnes_get_memory_data(block_type[i]);
|
||||
if (ptr)
|
||||
memcpy(block_buf[i], ptr, block_size[i]);
|
||||
}
|
||||
}
|
||||
|
||||
psnes_unserialize(buf, size);
|
||||
|
||||
// Flush back :D
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
if (block_buf[i])
|
||||
{
|
||||
uint8_t *ptr = psnes_get_memory_data(block_type[i]);
|
||||
if (ptr)
|
||||
memcpy(ptr, block_buf[i], block_size[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
if (block_buf[i])
|
||||
free(block_buf[i]);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
void load_ram_file(const char* path, int type)
|
||||
void load_ram_file(const char *path, int type)
|
||||
{
|
||||
size_t size = psnes_get_memory_size(type);
|
||||
uint8_t *data = psnes_get_memory_data(type);
|
||||
@@ -261,13 +515,34 @@ void load_ram_file(const char* path, int type)
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void save_ram_file(const char* path, int type)
|
||||
void save_ram_file(const char *path, int type)
|
||||
{
|
||||
size_t size = psnes_get_memory_size(type);
|
||||
uint8_t *data = psnes_get_memory_data(type);
|
||||
|
||||
if (data && size > 0)
|
||||
dump_to_file(path, data, size);
|
||||
{
|
||||
if (!dump_to_file(path, data, size))
|
||||
{
|
||||
SSNES_ERR("Failed to save SNES RAM!\n");
|
||||
SSNES_WARN("Attempting to recover ...\n");
|
||||
dump_to_file_desperate(data, size, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char* load_xml_map(const char *path)
|
||||
{
|
||||
char *xml_buf = NULL;
|
||||
if (*path)
|
||||
{
|
||||
if (!read_file_string(path, &xml_buf))
|
||||
SSNES_LOG("Did not find XML memory map in \"%s\"\n", path);
|
||||
else
|
||||
SSNES_LOG("Found XML memory map in \"%s\"\n", path);
|
||||
}
|
||||
|
||||
return xml_buf;
|
||||
}
|
||||
|
||||
static bool load_sgb_rom(void)
|
||||
@@ -291,14 +566,19 @@ static bool load_sgb_rom(void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
char *xml_buf = load_xml_map(g_extern.xml_name);
|
||||
|
||||
if (!psnes_load_cartridge_super_game_boy(
|
||||
NULL, rom_buf, rom_len,
|
||||
xml_buf, rom_buf, rom_len,
|
||||
NULL, extra_rom_buf, extra_rom_len))
|
||||
{
|
||||
SSNES_ERR("Cannot load SGB/GameBoy rom.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (xml_buf)
|
||||
free(xml_buf);
|
||||
|
||||
if (g_extern.rom_file)
|
||||
fclose(g_extern.rom_file);
|
||||
if (extra_rom)
|
||||
@@ -338,10 +618,12 @@ static bool load_bsx_rom(bool slotted)
|
||||
goto error;
|
||||
}
|
||||
|
||||
char *xml_buf = load_xml_map(g_extern.xml_name);
|
||||
|
||||
if (slotted)
|
||||
{
|
||||
if (!psnes_load_cartridge_bsx_slotted(
|
||||
NULL, rom_buf, rom_len,
|
||||
xml_buf, rom_buf, rom_len,
|
||||
NULL, extra_rom_buf, extra_rom_len))
|
||||
{
|
||||
SSNES_ERR("Cannot load BSX slotted rom.\n");
|
||||
@@ -360,6 +642,9 @@ static bool load_bsx_rom(bool slotted)
|
||||
}
|
||||
}
|
||||
|
||||
if (xml_buf)
|
||||
free(xml_buf);
|
||||
|
||||
if (g_extern.rom_file)
|
||||
fclose(g_extern.rom_file);
|
||||
if (extra_rom)
|
||||
@@ -407,8 +692,10 @@ static bool load_sufami_rom(void)
|
||||
}
|
||||
}
|
||||
|
||||
char *xml_buf = load_xml_map(g_extern.xml_name);
|
||||
|
||||
if (!psnes_load_cartridge_sufami_turbo(
|
||||
NULL, rom_buf, rom_len,
|
||||
xml_buf, rom_buf, rom_len,
|
||||
NULL, extra_rom_buf[0], extra_rom_len[0],
|
||||
NULL, extra_rom_buf[1], extra_rom_len[1]))
|
||||
{
|
||||
@@ -416,6 +703,8 @@ static bool load_sufami_rom(void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (xml_buf)
|
||||
free(xml_buf);
|
||||
|
||||
if (g_extern.rom_file)
|
||||
fclose(g_extern.rom_file);
|
||||
@@ -457,13 +746,18 @@ static bool load_normal_rom(void)
|
||||
|
||||
SSNES_LOG("ROM size: %d bytes\n", (int)rom_len);
|
||||
|
||||
if (!psnes_load_cartridge_normal(NULL, rom_buf, rom_len))
|
||||
char *xml_buf = load_xml_map(g_extern.xml_name);
|
||||
|
||||
if (!psnes_load_cartridge_normal(xml_buf, rom_buf, rom_len))
|
||||
{
|
||||
SSNES_ERR("ROM file is not valid!\n");
|
||||
free(rom_buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (xml_buf)
|
||||
free(xml_buf);
|
||||
|
||||
free(rom_buf);
|
||||
return true;
|
||||
}
|
||||
@@ -509,8 +803,6 @@ bool init_rom_file(enum ssnes_game_type type)
|
||||
// Yep, this is C alright ;)
|
||||
char** dir_list_new(const char *dir, const char *ext)
|
||||
{
|
||||
size_t path_len = strlen(dir);
|
||||
|
||||
size_t cur_ptr = 0;
|
||||
size_t cur_size = 32;
|
||||
char **dir_list = NULL;
|
||||
@@ -519,18 +811,18 @@ char** dir_list_new(const char *dir, const char *ext)
|
||||
WIN32_FIND_DATAW ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
|
||||
wchar_t wchar_buf[MAXPATHLEN];
|
||||
char utf8_buf[MAXPATHLEN];
|
||||
|
||||
size_t final_off = MAX_PATH + path_len + 2;
|
||||
if (strlcpy(utf8_buf, dir, sizeof(utf8_buf)) >= sizeof(utf8_buf))
|
||||
goto error;
|
||||
if (strlcat(utf8_buf, "/*", sizeof(utf8_buf)) >= sizeof(utf8_buf))
|
||||
goto error;
|
||||
if (strlcat(utf8_buf, ext, sizeof(utf8_buf)) >= sizeof(utf8_buf))
|
||||
goto error;
|
||||
|
||||
wchar_t wchar_buf[MAX_PATH + 1];
|
||||
char utf8_buf[MAX_PATH + 3];
|
||||
|
||||
strlcpy(utf8_buf, dir, sizeof(utf8_buf));
|
||||
strlcat(utf8_buf, "/*", sizeof(utf8_buf));
|
||||
utf8_buf[MAX_PATH + 2] = '\0';
|
||||
|
||||
int ret = MultiByteToWideChar(CP_UTF8, 0, utf8_buf, strlen(utf8_buf), wchar_buf, MAX_PATH);
|
||||
wchar_buf[ret] = 0;
|
||||
if (MultiByteToWideChar(CP_UTF8, 0, utf8_buf, -1, wchar_buf, MAXPATHLEN) == 0)
|
||||
goto error;
|
||||
|
||||
hFind = FindFirstFileW(wchar_buf, &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
@@ -538,7 +830,6 @@ char** dir_list_new(const char *dir, const char *ext)
|
||||
#else
|
||||
DIR *directory = NULL;
|
||||
const struct dirent *entry = NULL;
|
||||
size_t final_off = sizeof(entry->d_name) + path_len + 2;
|
||||
|
||||
directory = opendir(dir);
|
||||
if (!directory)
|
||||
@@ -559,8 +850,8 @@ char** dir_list_new(const char *dir, const char *ext)
|
||||
#ifdef _WIN32
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
continue;
|
||||
int ret = WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, wcslen(ffd.cFileName), utf8_buf, MAX_PATH, NULL, NULL);
|
||||
utf8_buf[ret] = '\0';
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, -1, utf8_buf, MAXPATHLEN, NULL, NULL) == 0)
|
||||
continue;
|
||||
if (ext && !strstr(utf8_buf, ext))
|
||||
continue;
|
||||
#else
|
||||
@@ -568,16 +859,16 @@ char** dir_list_new(const char *dir, const char *ext)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
dir_list[cur_ptr] = malloc(final_off);
|
||||
dir_list[cur_ptr] = malloc(MAXPATHLEN);
|
||||
if (!dir_list[cur_ptr])
|
||||
goto error;
|
||||
|
||||
strlcpy(dir_list[cur_ptr], dir, final_off);
|
||||
strlcat(dir_list[cur_ptr], "/", final_off);
|
||||
strlcpy(dir_list[cur_ptr], dir, MAXPATHLEN);
|
||||
strlcat(dir_list[cur_ptr], "/", MAXPATHLEN);
|
||||
#ifdef _WIN32
|
||||
strlcat(dir_list[cur_ptr], utf8_buf, final_off);
|
||||
strlcat(dir_list[cur_ptr], utf8_buf, MAXPATHLEN);
|
||||
#else
|
||||
strlcat(dir_list[cur_ptr], entry->d_name, final_off);
|
||||
strlcat(dir_list[cur_ptr], entry->d_name, MAXPATHLEN);
|
||||
#endif
|
||||
|
||||
cur_ptr++;
|
||||
@@ -594,7 +885,6 @@ char** dir_list_new(const char *dir, const char *ext)
|
||||
}
|
||||
#ifdef _WIN32
|
||||
while (FindNextFileW(hFind, &ffd) != 0);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -627,3 +917,64 @@ void dir_list_free(char **dir_list)
|
||||
free(*dir_list++);
|
||||
free(orig);
|
||||
}
|
||||
|
||||
bool path_is_directory(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
wchar_t buf[MAXPATHLEN];
|
||||
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, buf, MAXPATHLEN) == 0)
|
||||
return false;
|
||||
return PathIsDirectoryW(buf) == FILE_ATTRIBUTE_DIRECTORY;
|
||||
#else
|
||||
struct stat buf;
|
||||
if (stat(path, &buf) < 0)
|
||||
return false;
|
||||
|
||||
return S_ISDIR(buf.st_mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool path_file_exists(const char *path)
|
||||
{
|
||||
FILE *dummy = fopen(path, "rb");
|
||||
if (dummy)
|
||||
{
|
||||
fclose(dummy);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size)
|
||||
{
|
||||
char tmp_path[MAXPATHLEN];
|
||||
assert(strlcpy(tmp_path, in_path, sizeof(tmp_path)) < sizeof(tmp_path));
|
||||
char *tok = strrchr(tmp_path, '.');
|
||||
if (tok != NULL)
|
||||
*tok = '\0';
|
||||
assert(strlcpy(out_path, tmp_path, size) < size);
|
||||
assert(strlcat(out_path, replace, size) < size);
|
||||
}
|
||||
|
||||
void fill_pathname_noext(char *out_path, const char *in_path, const char *replace, size_t size)
|
||||
{
|
||||
assert(strlcpy(out_path, in_path, size) < size);
|
||||
assert(strlcat(out_path, replace, size) < size);
|
||||
}
|
||||
|
||||
void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replace, size_t size)
|
||||
{
|
||||
assert(strlcat(in_dir, "/", size) < size);
|
||||
|
||||
const char *base = strrchr(in_basename, '/');
|
||||
if (!base)
|
||||
base = strrchr(in_basename, '\\');
|
||||
|
||||
if (base)
|
||||
base++;
|
||||
else
|
||||
base = in_basename;
|
||||
|
||||
assert(strlcat(in_dir, base, size) < size);
|
||||
assert(strlcat(in_dir, replace, size) < size);
|
||||
}
|
||||
@@ -28,11 +28,11 @@
|
||||
|
||||
ssize_t read_file(const char *path, void **buf);
|
||||
|
||||
bool load_state(const char* path);
|
||||
bool save_state(const char* path);
|
||||
bool load_state(const char *path);
|
||||
bool save_state(const char *path);
|
||||
|
||||
void load_ram_file(const char* path, int type);
|
||||
void save_ram_file(const char* path, int type);
|
||||
void load_ram_file(const char *path, int type);
|
||||
void save_ram_file(const char *path, int type);
|
||||
|
||||
bool init_rom_file(enum ssnes_game_type type);
|
||||
|
||||
@@ -40,4 +40,16 @@ bool init_rom_file(enum ssnes_game_type type);
|
||||
char** dir_list_new(const char *dir, const char *ext);
|
||||
void dir_list_free(char **dir_list);
|
||||
|
||||
bool path_is_directory(const char *path);
|
||||
bool path_file_exists(const char *path);
|
||||
|
||||
// Path-name operations.
|
||||
// Replaces filename extension with replace.
|
||||
void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size);
|
||||
// Sets filename extension. Assumes in_path has no extension.
|
||||
void fill_pathname_noext(char *out_path, const char *in_path, const char *replace, size_t size);
|
||||
// Concatenates in_basename and replace to in_dir.
|
||||
void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replace, size_t size);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -42,9 +42,20 @@
|
||||
#include "audio/hermite.h"
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/param.h> // MAXPATHLEN
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#ifdef PATH_MAX
|
||||
#define MAXPATHLEN PATH_MAX
|
||||
#else
|
||||
#define MAXPATHLEN 512
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAX_PLAYERS 5
|
||||
#define MAX_BINDS 34 // Needs to be increased every time there are new binds added.
|
||||
#define MAX_BINDS (SSNES_BIND_LIST_END + 1)
|
||||
#define SSNES_NO_JOYPAD 0xFFFF
|
||||
|
||||
enum ssnes_shader_type
|
||||
@@ -71,26 +82,33 @@ struct settings
|
||||
bool force_aspect;
|
||||
bool crop_overscan;
|
||||
float aspect_ratio;
|
||||
char cg_shader_path[256];
|
||||
char bsnes_shader_path[256];
|
||||
char filter_path[256];
|
||||
char cg_shader_path[MAXPATHLEN];
|
||||
char bsnes_shader_path[MAXPATHLEN];
|
||||
char filter_path[MAXPATHLEN];
|
||||
enum ssnes_shader_type shader_type;
|
||||
|
||||
bool render_to_texture;
|
||||
double fbo_scale_x;
|
||||
double fbo_scale_y;
|
||||
char second_pass_shader[256];
|
||||
char second_pass_shader[MAXPATHLEN];
|
||||
bool second_pass_smooth;
|
||||
char shader_dir[256];
|
||||
char shader_dir[MAXPATHLEN];
|
||||
|
||||
char font_path[256];
|
||||
char font_path[MAXPATHLEN];
|
||||
unsigned font_size;
|
||||
float msg_pos_x;
|
||||
float msg_pos_y;
|
||||
float msg_color_r;
|
||||
float msg_color_g;
|
||||
float msg_color_b;
|
||||
|
||||
bool force_16bit;
|
||||
bool disable_composition;
|
||||
|
||||
char external_driver[256];
|
||||
bool hires_record;
|
||||
bool post_filter_record;
|
||||
|
||||
char external_driver[MAXPATHLEN];
|
||||
} video;
|
||||
|
||||
struct
|
||||
@@ -100,13 +118,13 @@ struct settings
|
||||
unsigned out_rate;
|
||||
float in_rate;
|
||||
float rate_step;
|
||||
char device[256];
|
||||
char device[MAXPATHLEN];
|
||||
unsigned latency;
|
||||
bool sync;
|
||||
int src_quality;
|
||||
|
||||
char dsp_plugin[256];
|
||||
char external_driver[256];
|
||||
char dsp_plugin[MAXPATHLEN];
|
||||
char external_driver[MAXPATHLEN];
|
||||
} audio;
|
||||
|
||||
struct
|
||||
@@ -118,10 +136,11 @@ struct settings
|
||||
bool netplay_client_swap_input;
|
||||
} input;
|
||||
|
||||
char libsnes[256];
|
||||
char cheat_database[256];
|
||||
char libsnes[MAXPATHLEN];
|
||||
char cheat_database[MAXPATHLEN];
|
||||
char cheat_settings_path[MAXPATHLEN];
|
||||
|
||||
char screenshot_directory[256];
|
||||
char screenshot_directory[MAXPATHLEN];
|
||||
|
||||
bool rewind_enable;
|
||||
unsigned rewind_buffer_size;
|
||||
@@ -129,6 +148,8 @@ struct settings
|
||||
|
||||
bool pause_nonactive;
|
||||
unsigned autosave_interval;
|
||||
|
||||
bool block_sram_overwrite;
|
||||
};
|
||||
|
||||
enum ssnes_game_type
|
||||
@@ -147,6 +168,7 @@ struct global
|
||||
bool verbose;
|
||||
bool audio_active;
|
||||
bool video_active;
|
||||
bool force_fullscreen;
|
||||
|
||||
bool has_mouse[2];
|
||||
bool has_scope[2];
|
||||
@@ -159,24 +181,29 @@ struct global
|
||||
enum ssnes_game_type game_type;
|
||||
uint32_t cart_crc;
|
||||
|
||||
char gb_rom_path[256];
|
||||
char bsx_rom_path[256];
|
||||
char sufami_rom_path[2][256];
|
||||
char gb_rom_path[MAXPATHLEN];
|
||||
char bsx_rom_path[MAXPATHLEN];
|
||||
char sufami_rom_path[2][MAXPATHLEN];
|
||||
bool has_set_save_path;
|
||||
bool has_set_state_path;
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
char config_path[256];
|
||||
char config_path[MAXPATHLEN];
|
||||
#endif
|
||||
|
||||
char basename[256];
|
||||
char savefile_name_srm[256];
|
||||
char savefile_name_rtc[512]; // Make sure that fill_pathname has space.
|
||||
char savefile_name_psrm[512];
|
||||
char savefile_name_asrm[512];
|
||||
char savefile_name_bsrm[512];
|
||||
char savestate_name[256];
|
||||
char ups_name[512];
|
||||
char basename[MAXPATHLEN];
|
||||
char savefile_name_srm[MAXPATHLEN];
|
||||
char savefile_name_rtc[MAXPATHLEN]; // Make sure that fill_pathname has space.
|
||||
char savefile_name_psrm[MAXPATHLEN];
|
||||
char savefile_name_asrm[MAXPATHLEN];
|
||||
char savefile_name_bsrm[MAXPATHLEN];
|
||||
char savestate_name[MAXPATHLEN];
|
||||
char xml_name[MAXPATHLEN];
|
||||
|
||||
bool ups_pref;
|
||||
bool bps_pref;
|
||||
char ups_name[MAXPATHLEN];
|
||||
char bps_name[MAXPATHLEN];
|
||||
|
||||
unsigned state_slot;
|
||||
|
||||
@@ -227,7 +254,7 @@ struct global
|
||||
|
||||
// Movie record support
|
||||
bsv_movie_t *bsv_movie;
|
||||
char bsv_movie_path[256];
|
||||
char bsv_movie_path[MAXPATHLEN];
|
||||
bool bsv_movie_end;
|
||||
bool bsv_movie_playback;
|
||||
|
||||
@@ -239,7 +266,7 @@ struct global
|
||||
|
||||
// Netplay.
|
||||
netplay_t *netplay;
|
||||
char netplay_server[256];
|
||||
char netplay_server[MAXPATHLEN];
|
||||
bool netplay_enable;
|
||||
bool netplay_is_client;
|
||||
unsigned netplay_sync_frames;
|
||||
@@ -248,7 +275,7 @@ struct global
|
||||
// FFmpeg record.
|
||||
#ifdef HAVE_FFMPEG
|
||||
ffemu_t *rec;
|
||||
char record_path[256];
|
||||
char record_path[MAXPATHLEN];
|
||||
bool recording;
|
||||
#endif
|
||||
|
||||
@@ -303,6 +330,18 @@ static inline uint32_t next_pow2(uint32_t v)
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline uint8_t is_little_endian(void)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16_t x;
|
||||
uint8_t y[2];
|
||||
} u;
|
||||
|
||||
u.x = 1;
|
||||
return u.y[0];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include "dynamic.h"
|
||||
#include "general.h"
|
||||
#include "sdlwrap.h"
|
||||
|
||||
static bool g_input_dead = true;
|
||||
static bool g_video_dead = true;
|
||||
@@ -224,6 +225,21 @@ static bool setup_video(ext_t *ext, const video_info_t *video, const input_drive
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *cg_shader = NULL;
|
||||
const char *xml_shader = NULL;
|
||||
enum ssnes_shader_type type = g_settings.video.shader_type;
|
||||
if ((type == SSNES_SHADER_CG || type == SSNES_SHADER_AUTO) && *g_settings.video.cg_shader_path)
|
||||
cg_shader = g_settings.video.cg_shader_path;
|
||||
else if ((type == SSNES_SHADER_BSNES || type == SSNES_SHADER_AUTO) && *g_settings.video.bsnes_shader_path)
|
||||
xml_shader = g_settings.video.bsnes_shader_path;
|
||||
|
||||
int font_color_r = g_settings.video.msg_color_r * 255;
|
||||
int font_color_g = g_settings.video.msg_color_g * 255;
|
||||
int font_color_b = g_settings.video.msg_color_b * 255;
|
||||
font_color_r = font_color_r > 255 ? 255 : (font_color_r < 0 ? 0 : font_color_r);
|
||||
font_color_g = font_color_g > 255 ? 255 : (font_color_g < 0 ? 0 : font_color_g);
|
||||
font_color_b = font_color_b > 255 ? 255 : (font_color_b < 0 ? 0 : font_color_b);
|
||||
|
||||
ssnes_video_info_t info = {
|
||||
.width = video->width,
|
||||
.height = video->height,
|
||||
@@ -234,10 +250,11 @@ static bool setup_video(ext_t *ext, const video_info_t *video, const input_drive
|
||||
.smooth = video->smooth,
|
||||
.input_scale = video->input_scale,
|
||||
.color_format = video->rgb32 ? SSNES_COLOR_FORMAT_ARGB8888 : SSNES_COLOR_FORMAT_XRGB1555,
|
||||
.xml_shader = g_settings.video.bsnes_shader_path,
|
||||
.cg_shader = g_settings.video.cg_shader_path,
|
||||
.xml_shader = xml_shader,
|
||||
.cg_shader = cg_shader,
|
||||
.ttf_font = *g_settings.video.font_path ? g_settings.video.font_path : NULL,
|
||||
.ttf_font_size = g_settings.video.font_size
|
||||
.ttf_font_size = g_settings.video.font_size,
|
||||
.ttf_font_color = (font_color_r << 16) | (font_color_g << 8) | (font_color_b << 0),
|
||||
};
|
||||
|
||||
const ssnes_input_driver_t *input_driver = NULL;
|
||||
|
||||
@@ -108,7 +108,7 @@ typedef struct ssnes_video_info
|
||||
// Can be disregarded.
|
||||
const char *ttf_font;
|
||||
unsigned ttf_font_size;
|
||||
|
||||
unsigned ttf_font_color; // Font color, in format RGB888.
|
||||
} ssnes_video_info_t;
|
||||
|
||||
// Some convenience macros.
|
||||
@@ -155,8 +155,9 @@ struct ssnes_keybind
|
||||
// last frame and current frame in the Y-axis.
|
||||
int analog_y;
|
||||
|
||||
// Keyboard key. The key values use the SDL keysyms,
|
||||
// Keyboard key. The key values use the SDL 1.2 keysyms,
|
||||
// which probably need to be transformed to the native format.
|
||||
// The actual keysyms SSNES uses are found in input/keysym.h.
|
||||
unsigned short key;
|
||||
|
||||
// Joypad key. Joypad POV (hats) are embedded into this key as well.
|
||||
|
||||
+62
-6
@@ -25,21 +25,26 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i
|
||||
return frames/time;
|
||||
}
|
||||
|
||||
static unsigned gl_frames = 0;
|
||||
|
||||
void gfx_window_title_reset(void)
|
||||
{
|
||||
gl_frames = 0;
|
||||
}
|
||||
|
||||
bool gfx_window_title(char *buf, size_t size)
|
||||
{
|
||||
static int frames = 0;
|
||||
static struct timeval tv;
|
||||
struct timeval new_tv;
|
||||
bool ret = false;
|
||||
|
||||
if (frames == 0)
|
||||
if (gl_frames == 0)
|
||||
{
|
||||
gettimeofday(&tv, NULL);
|
||||
snprintf(buf, size, "%s", g_extern.title_buf);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if ((frames % 180) == 0 && frames > 0)
|
||||
else if ((gl_frames % 180) == 0)
|
||||
{
|
||||
gettimeofday(&new_tv, NULL);
|
||||
struct timeval tmp_tv = tv;
|
||||
@@ -47,12 +52,63 @@ bool gfx_window_title(char *buf, size_t size)
|
||||
|
||||
float fps = tv_to_fps(&tmp_tv, &new_tv, 180);
|
||||
|
||||
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, frames);
|
||||
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, gl_frames);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
frames++;
|
||||
gl_frames++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include "dynamic.h"
|
||||
// We only load this library once, so we let it be unloaded at application shutdown,
|
||||
// since unloading it early seems to cause issues on some systems.
|
||||
|
||||
static dylib_t dwmlib = NULL;
|
||||
|
||||
static void gfx_dwm_shutdown(void)
|
||||
{
|
||||
if (dwmlib)
|
||||
dylib_close(dwmlib);
|
||||
}
|
||||
|
||||
void gfx_set_dwm(void)
|
||||
{
|
||||
static bool inited = false;
|
||||
if (inited)
|
||||
return;
|
||||
inited = true;
|
||||
|
||||
dwmlib = dylib_load("dwmapi.dll");
|
||||
if (!dwmlib)
|
||||
{
|
||||
SSNES_LOG("Did not find dwmapi.dll");
|
||||
return;
|
||||
}
|
||||
atexit(gfx_dwm_shutdown);
|
||||
|
||||
HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(dwmlib, "DwmEnableMMCSS");
|
||||
if (mmcss)
|
||||
{
|
||||
SSNES_LOG("Setting multimedia scheduling for DWM.\n");
|
||||
mmcss(TRUE);
|
||||
}
|
||||
|
||||
if (!g_settings.video.disable_composition)
|
||||
return;
|
||||
|
||||
HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(dwmlib, "DwmEnableComposition");
|
||||
if (!composition_enable)
|
||||
{
|
||||
SSNES_ERR("Did not find DwmEnableComposition ...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
HRESULT ret = composition_enable(0);
|
||||
if (FAILED(ret))
|
||||
SSNES_ERR("Failed to set composition state ...\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,5 +22,10 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
bool gfx_window_title(char *buf, size_t size);
|
||||
void gfx_window_title_reset(void);
|
||||
|
||||
#ifdef _WIN32
|
||||
void gfx_set_dwm(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "gl_common.h"
|
||||
#include "gfx_common.h"
|
||||
#include "sdlwrap.h"
|
||||
|
||||
#define NO_SDL_GLEXT
|
||||
#include "SDL.h"
|
||||
@@ -125,7 +126,9 @@ static inline bool load_gl_proc(void) { return true; }
|
||||
typedef struct gl
|
||||
{
|
||||
bool vsync;
|
||||
GLuint texture;
|
||||
GLuint texture[2];
|
||||
unsigned tex_index; // For use with PREV.
|
||||
struct gl_tex_info prev_info;
|
||||
GLuint tex_filter;
|
||||
|
||||
void *empty_buf;
|
||||
@@ -145,6 +148,7 @@ typedef struct gl
|
||||
|
||||
bool should_resize;
|
||||
bool quitting;
|
||||
bool fullscreen;
|
||||
bool keep_aspect;
|
||||
|
||||
unsigned full_x, full_y;
|
||||
@@ -153,8 +157,8 @@ typedef struct gl
|
||||
unsigned win_height;
|
||||
unsigned vp_width, vp_out_width;
|
||||
unsigned vp_height, vp_out_height;
|
||||
unsigned last_width;
|
||||
unsigned last_height;
|
||||
unsigned last_width[2];
|
||||
unsigned last_height[2];
|
||||
unsigned tex_w, tex_h;
|
||||
GLfloat tex_coords[8];
|
||||
#ifdef HAVE_FBO
|
||||
@@ -255,20 +259,21 @@ static void gl_shader_set_params(unsigned width, unsigned height,
|
||||
unsigned out_width, unsigned out_height,
|
||||
unsigned frame_count,
|
||||
const struct gl_tex_info *info,
|
||||
const struct gl_tex_info *prev_info,
|
||||
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
|
||||
{
|
||||
#ifdef HAVE_CG
|
||||
gl_cg_set_params(width, height,
|
||||
tex_width, tex_height,
|
||||
out_width, out_height,
|
||||
frame_count, info, fbo_info, fbo_info_cnt);
|
||||
frame_count, info, prev_info, fbo_info, fbo_info_cnt);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XML
|
||||
gl_glsl_set_params(width, height,
|
||||
tex_width, tex_height,
|
||||
out_width, out_height,
|
||||
frame_count, info, fbo_info, fbo_info_cnt);
|
||||
frame_count, info, prev_info, fbo_info, fbo_info_cnt);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -338,7 +343,7 @@ static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_s
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
}
|
||||
else
|
||||
SSNES_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path);
|
||||
@@ -495,7 +500,7 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_RGBA,
|
||||
0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_BGRA,
|
||||
GL_UNSIGNED_INT_8_8_8_8, NULL);
|
||||
}
|
||||
|
||||
@@ -618,6 +623,7 @@ static void gl_render_msg(gl_t *gl, const char *msg)
|
||||
// Need blending.
|
||||
// Using fixed function pipeline here since we cannot guarantee presence of shaders (would be kinda overkill anyways).
|
||||
glEnable(GL_BLEND);
|
||||
glColor4f(g_settings.video.msg_color_r, g_settings.video.msg_color_g, g_settings.video.msg_color_b, 1);
|
||||
|
||||
struct font_output_list out;
|
||||
font_renderer_msg(gl->font, msg, &out);
|
||||
@@ -650,10 +656,13 @@ static void gl_render_msg(gl_t *gl, const char *msg)
|
||||
}
|
||||
font_renderer_free_output(&out);
|
||||
|
||||
glColor4f(1, 1, 1, 1);
|
||||
|
||||
// Go back to old rendering path.
|
||||
glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), gl->tex_coords);
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes_flipped);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
#endif
|
||||
}
|
||||
@@ -681,26 +690,19 @@ static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yam
|
||||
|
||||
static void check_window(gl_t *gl)
|
||||
{
|
||||
SDL_Event event;
|
||||
bool quit, resize;
|
||||
|
||||
// Search for events we care about ...
|
||||
while (SDL_PollEvent(&event))
|
||||
sdlwrap_check_window(&quit,
|
||||
&resize, &gl->win_width, &gl->win_height,
|
||||
gl->frame_count);
|
||||
|
||||
if (quit)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
gl->quitting = true;
|
||||
break;
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
gl->should_resize = true;
|
||||
gl->win_width = event.resize.w;
|
||||
gl->win_height = event.resize.h;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
gl->quitting = true;
|
||||
}
|
||||
else if (resize)
|
||||
{
|
||||
gl->should_resize = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,6 +714,10 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
gl_shader_use(1);
|
||||
gl->frame_count++;
|
||||
|
||||
#if defined(HAVE_XML) || defined(HAVE_CG)
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
// Render to texture in first pass.
|
||||
if (gl->fbo_inited)
|
||||
@@ -767,7 +773,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
last_max_height = gl->fbo_rect[i].max_img_height;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]);
|
||||
gl->render_to_tex = true;
|
||||
set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true);
|
||||
@@ -777,7 +783,8 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
if (gl->should_resize)
|
||||
{
|
||||
gl->should_resize = false;
|
||||
SDL_SetVideoMode(gl->win_width, gl->win_height, 0, SDL_OPENGL | SDL_RESIZABLE | (g_settings.video.fullscreen ? SDL_FULLSCREEN : 0));
|
||||
|
||||
sdlwrap_set_video_mode(gl->win_width, gl->win_height, 0, g_settings.video.fullscreen);
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
if (!gl->render_to_tex)
|
||||
@@ -800,7 +807,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_RGBA,
|
||||
0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_BGRA,
|
||||
GL_UNSIGNED_INT_8_8_8_8, NULL);
|
||||
|
||||
pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0);
|
||||
@@ -814,7 +821,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
}
|
||||
|
||||
// Go back to what we're supposed to do, render to FBO #0 :D
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]);
|
||||
set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true);
|
||||
}
|
||||
@@ -823,10 +830,10 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((width != gl->last_width || height != gl->last_height) && gl->empty_buf) // Res change. need to clear out texture.
|
||||
if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index]) && gl->empty_buf) // Res change. need to clear out texture.
|
||||
{
|
||||
gl->last_width = width;
|
||||
gl->last_height = height;
|
||||
gl->last_width[gl->tex_index] = width;
|
||||
gl->last_height[gl->tex_index] = height;
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch));
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w);
|
||||
|
||||
@@ -839,17 +846,17 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
|
||||
set_texture_coords(gl->tex_coords, xamt, yamt);
|
||||
}
|
||||
|
||||
// Work around a certain issue a Cg where not using TEXUNIT0
|
||||
// in shader causes cgGLEnableTextureParameter() causes it
|
||||
// to bind to TEXUNIT0, to avoid really funny bugs, rebind
|
||||
// our texture.
|
||||
#ifdef HAVE_CG
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
#if defined(HAVE_XML) || defined(HAVE_CG)
|
||||
else if (width != gl->last_width[1 - gl->tex_index] || height != gl->last_height[1 - gl->tex_index])
|
||||
{
|
||||
GLfloat xamt = (GLfloat)width / gl->tex_w;
|
||||
GLfloat yamt = (GLfloat)height / gl->tex_h;
|
||||
set_texture_coords(gl->tex_coords, xamt, yamt);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
// Need to preserve the "flipped" state when in FBO too to have
|
||||
// Need to preserve the "flipped" state when in FBO as well to have
|
||||
// consistent texture coordinates.
|
||||
if (gl->render_to_tex)
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes);
|
||||
@@ -861,7 +868,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
gl->texture_fmt, frame);
|
||||
|
||||
struct gl_tex_info tex_info = {
|
||||
.tex = gl->texture,
|
||||
.tex = gl->texture[gl->tex_index],
|
||||
.input_size = {width, height},
|
||||
.tex_size = {gl->tex_w, gl->tex_h}
|
||||
};
|
||||
@@ -871,7 +878,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
gl_shader_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height, gl->frame_count,
|
||||
&tex_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
&tex_info, &gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
@@ -916,7 +923,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
|
||||
prev_rect->width, prev_rect->height,
|
||||
gl->vp_width, gl->vp_height, gl->frame_count,
|
||||
&tex_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
&tex_info, &gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
@@ -942,7 +949,7 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
gl_shader_set_params(prev_rect->img_width, prev_rect->img_height,
|
||||
prev_rect->width, prev_rect->height,
|
||||
gl->vp_width, gl->vp_height, gl->frame_count,
|
||||
&tex_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
&tex_info, &gl->prev_info, fbo_tex_info, fbo_tex_info_cnt);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes_flipped);
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
@@ -951,13 +958,19 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_XML) || defined(HAVE_CG)
|
||||
memcpy(&gl->prev_info, &tex_info, sizeof(tex_info));
|
||||
gl->tex_index = 1 - gl->tex_index;
|
||||
#endif
|
||||
|
||||
if (msg)
|
||||
gl_render_msg(gl, msg);
|
||||
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
SDL_WM_SetCaption(buf, NULL);
|
||||
SDL_GL_SwapBuffers();
|
||||
sdlwrap_wm_set_caption(buf);
|
||||
|
||||
sdlwrap_swap_buffers();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -970,7 +983,7 @@ static void gl_free(void *data)
|
||||
gl_shader_deinit();
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDeleteTextures(1, &gl->texture);
|
||||
glDeleteTextures(2, gl->texture);
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
if (gl->fbo_inited)
|
||||
@@ -979,7 +992,7 @@ static void gl_free(void *data)
|
||||
pglDeleteFramebuffers(gl->fbo_pass, gl->fbo);
|
||||
}
|
||||
#endif
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
sdlwrap_destroy();
|
||||
|
||||
if (gl->empty_buf)
|
||||
free(gl->empty_buf);
|
||||
@@ -993,31 +1006,17 @@ static void gl_set_nonblock_state(void *data, bool state)
|
||||
if (gl->vsync)
|
||||
{
|
||||
SSNES_LOG("GL VSync => %s\n", state ? "off" : "on");
|
||||
#ifdef _WIN32
|
||||
static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL;
|
||||
if (!wgl_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(wgl_swap_interval, "wglSwapIntervalEXT");
|
||||
}
|
||||
if (wgl_swap_interval) wgl_swap_interval(state ? 0 : 1);
|
||||
#else
|
||||
static int (*glx_swap_interval)(int) = NULL;
|
||||
if (!glx_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI");
|
||||
}
|
||||
if (!glx_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalMESA");
|
||||
}
|
||||
if (glx_swap_interval) glx_swap_interval(state ? 0 : 1);
|
||||
#endif
|
||||
sdlwrap_set_swap_interval(state ? 0 : 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void* gl_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
#ifdef _WIN32
|
||||
gfx_set_dwm();
|
||||
#endif
|
||||
|
||||
if (!sdlwrap_init())
|
||||
return NULL;
|
||||
|
||||
const SDL_VideoInfo *video_info = SDL_GetVideoInfo();
|
||||
@@ -1026,12 +1025,25 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
unsigned full_y = video_info->current_h;
|
||||
SSNES_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, video->vsync ? 1 : 0);
|
||||
sdlwrap_set_swap_interval(video->vsync ? 1 : 0, false);
|
||||
|
||||
if (!SDL_SetVideoMode(video->width, video->height, g_settings.video.force_16bit ? 16 : 0, SDL_OPENGL | SDL_RESIZABLE | (video->fullscreen ? SDL_FULLSCREEN : 0)))
|
||||
unsigned win_width = video->width;
|
||||
unsigned win_height = video->height;
|
||||
if (video->fullscreen && (win_width == 0) && (win_height == 0))
|
||||
{
|
||||
win_width = full_x;
|
||||
win_height = full_y;
|
||||
}
|
||||
|
||||
if (!sdlwrap_set_video_mode(win_width, win_height,
|
||||
g_settings.video.force_16bit ? 15 : 0, video->fullscreen))
|
||||
return NULL;
|
||||
|
||||
gfx_window_title_reset();
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
sdlwrap_wm_set_caption(buf);
|
||||
|
||||
// Remove that ugly mouse :D
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -1041,7 +1053,7 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
// Need to load dynamically :(
|
||||
if (!load_gl_proc())
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
sdlwrap_destroy();
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -1049,43 +1061,24 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
gl_t *gl = calloc(1, sizeof(gl_t));
|
||||
if (!gl)
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
sdlwrap_destroy();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gl->vsync = video->vsync;
|
||||
int attr = 0;
|
||||
SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &attr);
|
||||
if (attr <= 0 && video->vsync)
|
||||
{
|
||||
SSNES_WARN("SDL failed to setup VSync, attempting to recover using native calls!\n");
|
||||
gl_set_nonblock_state(gl, false);
|
||||
}
|
||||
attr = 0;
|
||||
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attr);
|
||||
if (attr <= 0)
|
||||
SSNES_WARN("GL double buffer has not been enabled!\n");
|
||||
|
||||
gl->fullscreen = video->fullscreen;
|
||||
|
||||
gl->full_x = full_x;
|
||||
gl->full_y = full_y;
|
||||
|
||||
if (video->fullscreen)
|
||||
{
|
||||
gl->win_width = video->width ? video->width : gl->full_x;
|
||||
gl->win_height = video->height ? video->height : gl->full_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
gl->win_width = video->width;
|
||||
gl->win_height = video->height;
|
||||
}
|
||||
gl->win_width = win_width;
|
||||
gl->win_height = win_height;
|
||||
|
||||
SSNES_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height);
|
||||
|
||||
if (!gl_shader_init())
|
||||
{
|
||||
SSNES_ERR("Shader init failed.\n");
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
sdlwrap_destroy();
|
||||
free(gl);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1119,22 +1112,21 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
SDL_WM_SetCaption(buf, NULL);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glGenTextures(1, &gl->texture);
|
||||
glGenTextures(2, gl->texture);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl->tex_filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter);
|
||||
}
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
@@ -1148,15 +1140,31 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
gl->tex_w = 256 * video->input_scale;
|
||||
gl->tex_h = 256 * video->input_scale;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, gl->tex_w, gl->tex_h, 0, gl->texture_type,
|
||||
gl->texture_fmt, NULL);
|
||||
|
||||
// Empty buffer that we use to clear out the texture with on res change.
|
||||
gl->empty_buf = calloc(gl->base_size, gl->tex_w * gl->tex_h);
|
||||
gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size);
|
||||
|
||||
gl->last_width = gl->tex_w;
|
||||
gl->last_height = gl->tex_h;
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[i]);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, gl->tex_w, gl->tex_h, 0, gl->texture_type,
|
||||
gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
gl->last_width[i] = gl->tex_w;
|
||||
gl->last_height[i] = gl->tex_h;
|
||||
}
|
||||
|
||||
gl->prev_info.tex = gl->texture[1 - gl->tex_index];
|
||||
gl->prev_info.input_size[0] = gl->tex_w;
|
||||
gl->prev_info.tex_size[0] = gl->tex_w;
|
||||
gl->prev_info.input_size[1] = gl->tex_h;
|
||||
gl->prev_info.tex_size[1] = gl->tex_h;
|
||||
memcpy(gl->prev_info.coord, tex_coords, sizeof(tex_coords));
|
||||
|
||||
// Hook up SDL input driver to get SDL_QUIT events and RESIZE.
|
||||
sdl_input_t *sdl_input = input_sdl.init();
|
||||
@@ -1172,7 +1180,7 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
|
||||
if (!gl_check_error())
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
sdlwrap_destroy();
|
||||
free(gl);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1189,7 +1197,7 @@ static bool gl_alive(void *data)
|
||||
static bool gl_focus(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
|
||||
return sdlwrap_window_has_focus();
|
||||
}
|
||||
|
||||
#ifdef HAVE_XML
|
||||
@@ -1215,7 +1223,7 @@ static bool gl_xml_shader(void *data, const char *path)
|
||||
gl->render_to_tex = false;
|
||||
gl->fbo_pass = 0;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture);
|
||||
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+3
-10
@@ -101,18 +101,11 @@ struct gl_fbo_scale
|
||||
struct gl_tex_info
|
||||
{
|
||||
GLuint tex;
|
||||
float input_size[2];
|
||||
float tex_size[2];
|
||||
float coord[8];
|
||||
GLfloat input_size[2];
|
||||
GLfloat tex_size[2];
|
||||
GLfloat coord[8];
|
||||
};
|
||||
|
||||
// Not legal to cast void* to fn-pointer. Need dirty hack to be compilant.
|
||||
// sizeof(void*) == sizeof(void (*)(void)) is asserted earlier.
|
||||
#define SDL_SYM_WRAP(sym, symbol) { \
|
||||
void *sym__ = SDL_GL_GetProcAddress(symbol); \
|
||||
memcpy(&(sym), &sym__, sizeof(void*)); \
|
||||
}
|
||||
|
||||
// Windows ... <_<
|
||||
#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32)
|
||||
extern PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture;
|
||||
|
||||
+8
-8
@@ -63,7 +63,7 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
|
||||
uint32_t g = (src[x] & fmt->Gmask) >> fmt->Gshift;
|
||||
uint32_t b = (src[x] & fmt->Bmask) >> fmt->Bshift;
|
||||
uint32_t a = (src[x] & fmt->Amask) >> fmt->Ashift;
|
||||
dst[x] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
dst[x] = (b << 24) | (g << 16) | (r << 8) | a;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
|
||||
uint32_t r = (color & fmt->Rmask) >> fmt->Rshift;
|
||||
uint32_t g = (color & fmt->Gmask) >> fmt->Gshift;
|
||||
uint32_t b = (color & fmt->Bmask) >> fmt->Bshift;
|
||||
dst[x] = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
||||
dst[x] = (b << 24) | (g << 16) | (r << 8) | 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,24 +148,24 @@ bool texture_image_load(const char *path, struct texture_image *out_img)
|
||||
{
|
||||
for (unsigned i = 0; i < width * height; i++)
|
||||
{
|
||||
uint32_t r = tmp[i * 4 + 2];
|
||||
uint32_t g = tmp[i * 4 + 1];
|
||||
uint32_t b = tmp[i * 4 + 0];
|
||||
uint32_t g = tmp[i * 4 + 1];
|
||||
uint32_t r = tmp[i * 4 + 2];
|
||||
uint32_t a = tmp[i * 4 + 3];
|
||||
|
||||
out_img->pixels[i] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
out_img->pixels[i] = (b << 24) | (g << 16) | (r << 8) | a;
|
||||
}
|
||||
}
|
||||
else if (bits == 24)
|
||||
{
|
||||
for (unsigned i = 0; i < width * height; i++)
|
||||
{
|
||||
uint32_t r = tmp[i * 3 + 2];
|
||||
uint32_t g = tmp[i * 3 + 1];
|
||||
uint32_t b = tmp[i * 3 + 0];
|
||||
uint32_t g = tmp[i * 3 + 1];
|
||||
uint32_t r = tmp[i * 3 + 2];
|
||||
uint32_t a = 0xff;
|
||||
|
||||
out_img->pixels[i] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||
out_img->pixels[i] = (b << 24) | (g << 16) | (r << 8) | a;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -45,11 +45,16 @@ struct sdl_video
|
||||
bool rgb32;
|
||||
bool upsample;
|
||||
|
||||
bool render32;
|
||||
|
||||
void (*convert_15_func)(uint16_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned, const SDL_PixelFormat*);
|
||||
void (*convert_32_func)(uint32_t*, unsigned, const uint32_t*, unsigned, unsigned, unsigned, const SDL_PixelFormat*);
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
font_renderer_t *font;
|
||||
uint8_t font_r;
|
||||
uint8_t font_g;
|
||||
uint8_t font_b;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -78,7 +83,29 @@ static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font
|
||||
if (*font_path)
|
||||
{
|
||||
vid->font = font_renderer_new(font_path, font_size);
|
||||
if (!vid->font)
|
||||
if (vid->font)
|
||||
{
|
||||
int r = g_settings.video.msg_color_r * 255;
|
||||
int g = g_settings.video.msg_color_g * 255;
|
||||
int b = g_settings.video.msg_color_b * 255;
|
||||
|
||||
r = r < 0 ? 0 : (r > 255 ? 255 : r);
|
||||
g = g < 0 ? 0 : (g > 255 ? 255 : g);
|
||||
b = b < 0 ? 0 : (b > 255 ? 255 : b);
|
||||
|
||||
// RGB888 -> RGB555
|
||||
if (!vid->render32)
|
||||
{
|
||||
r >>= 3;
|
||||
g >>= 3;
|
||||
b >>= 3;
|
||||
}
|
||||
|
||||
vid->font_r = r;
|
||||
vid->font_g = g;
|
||||
vid->font_b = b;
|
||||
}
|
||||
else
|
||||
SSNES_WARN("Failed to init font.\n");
|
||||
}
|
||||
#else
|
||||
@@ -128,9 +155,9 @@ static void sdl_render_msg_15(sdl_video_t *vid, SDL_Surface *buffer, const char
|
||||
unsigned g = (out_pix >> gshift) & 0x1f;
|
||||
unsigned b = (out_pix >> bshift) & 0x1f;
|
||||
|
||||
unsigned out_r = (r * (256 - blend) + 0x1f * blend) >> 8;
|
||||
unsigned out_g = (g * (256 - blend) + 0x1f * blend) >> 8;
|
||||
unsigned out_b = (b * (256 - blend) + 0x1f * blend) >> 8;
|
||||
unsigned out_r = (r * (256 - blend) + vid->font_r * blend) >> 8;
|
||||
unsigned out_g = (g * (256 - blend) + vid->font_g * blend) >> 8;
|
||||
unsigned out_b = (b * (256 - blend) + vid->font_b * blend) >> 8;
|
||||
out[x] = (out_r << rshift) | (out_g << gshift) | (out_b << bshift);
|
||||
}
|
||||
}
|
||||
@@ -189,9 +216,9 @@ static void sdl_render_msg_32(sdl_video_t *vid, SDL_Surface *buffer, const char
|
||||
unsigned g = (out_pix >> gshift) & 0xff;
|
||||
unsigned b = (out_pix >> bshift) & 0xff;
|
||||
|
||||
unsigned out_r = (r * (256 - blend) + 0xff * blend) >> 8;
|
||||
unsigned out_g = (g * (256 - blend) + 0xff * blend) >> 8;
|
||||
unsigned out_b = (b * (256 - blend) + 0xff * blend) >> 8;
|
||||
unsigned out_r = (r * (256 - blend) + vid->font_r * blend) >> 8;
|
||||
unsigned out_g = (g * (256 - blend) + vid->font_g * blend) >> 8;
|
||||
unsigned out_b = (b * (256 - blend) + vid->font_b * blend) >> 8;
|
||||
out[x] = (out_r << rshift) | (out_g << gshift) | (out_b << bshift);
|
||||
}
|
||||
}
|
||||
@@ -213,6 +240,10 @@ static void sdl_render_msg_32(sdl_video_t *vid, SDL_Surface *buffer, const char
|
||||
|
||||
static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
gfx_set_dwm();
|
||||
#endif
|
||||
|
||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||
|
||||
sdl_video_t *vid = calloc(1, sizeof(*vid));
|
||||
@@ -228,13 +259,15 @@ static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
if (!video->fullscreen)
|
||||
SSNES_LOG("Creating window @ %ux%u\n", video->width, video->height);
|
||||
|
||||
vid->screen = SDL_SetVideoMode(video->width, video->height, (g_settings.video.force_16bit || !video->rgb32) ? 15 : 32, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
|
||||
vid->render32 = video->rgb32 && !g_settings.video.force_16bit;
|
||||
vid->screen = SDL_SetVideoMode(video->width, video->height, vid->render32 ? 32 : 15, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
|
||||
|
||||
if (!vid->screen && !g_settings.video.force_16bit && !video->rgb32)
|
||||
{
|
||||
vid->upsample = true;
|
||||
vid->screen = SDL_SetVideoMode(video->width, video->height, 32, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
|
||||
SSNES_WARN("SDL: 15-bit colors failed, attempting 32-bit colors.\n");
|
||||
vid->render32 = true;
|
||||
}
|
||||
|
||||
if (!vid->screen)
|
||||
@@ -246,7 +279,7 @@ static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
const SDL_PixelFormat *fmt = vid->screen->format;
|
||||
if (!g_settings.video.force_16bit && (video->rgb32 || vid->upsample))
|
||||
if (vid->render32)
|
||||
{
|
||||
SSNES_LOG("SDL: Creating 32-bit buffer.\n");
|
||||
vid->buffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 256 * video->input_scale, 256 * video->input_scale, 32,
|
||||
@@ -281,7 +314,7 @@ static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
sdl_init_font(vid, g_settings.video.font_path, g_settings.video.font_size);
|
||||
|
||||
|
||||
if (fmt->Rshift == 10 && fmt->Gshift == 5 && fmt->Bshift == 0)
|
||||
if (fmt->Rshift == 10 && fmt->Gshift == 5 && fmt->Bshift == 0) // XRGB1555
|
||||
{
|
||||
SSNES_LOG("SDL: 15-bit format matches. Fast blit.\n");
|
||||
vid->convert_15_func = convert_15bit_15bit_direct;
|
||||
@@ -292,7 +325,7 @@ static void* sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
|
||||
vid->convert_15_func = convert_15bit_15bit_shift;
|
||||
}
|
||||
|
||||
if (fmt->Rshift == 16 && fmt->Gshift == 8 && fmt->Bshift == 0)
|
||||
if (fmt->Rshift == 16 && fmt->Gshift == 8 && fmt->Bshift == 0) // ARGB8888
|
||||
{
|
||||
SSNES_LOG("SDL: 32-bit format matches. Fast blit.\n");
|
||||
vid->convert_32_func = convert_32bit_32bit_direct;
|
||||
@@ -452,15 +485,7 @@ static bool sdl_gfx_frame(void *data, const void* frame, unsigned width, unsigne
|
||||
{
|
||||
vid->convert_32_func(vid->buffer->pixels, vid->buffer->pitch, frame, width, height, pitch, vid->screen->format);
|
||||
}
|
||||
|
||||
if (msg)
|
||||
{
|
||||
if ((!vid->rgb32 || g_settings.video.force_16bit) && !vid->upsample)
|
||||
sdl_render_msg_15(vid, vid->buffer, msg, width, height, vid->screen->format);
|
||||
else
|
||||
sdl_render_msg_32(vid, vid->buffer, msg, width, height, vid->screen->format);
|
||||
}
|
||||
|
||||
|
||||
if (SDL_MUSTLOCK(vid->buffer))
|
||||
SDL_UnlockSurface(vid->buffer);
|
||||
|
||||
@@ -480,6 +505,14 @@ static bool sdl_gfx_frame(void *data, const void* frame, unsigned width, unsigne
|
||||
|
||||
SDL_SoftStretch(vid->buffer, &src, vid->screen, &dest);
|
||||
|
||||
if (msg)
|
||||
{
|
||||
if ((!vid->rgb32 || g_settings.video.force_16bit) && !vid->upsample)
|
||||
sdl_render_msg_15(vid, vid->screen, msg, vid->screen->w, vid->screen->h, vid->screen->format);
|
||||
else
|
||||
sdl_render_msg_32(vid, vid->screen, msg, vid->screen->w, vid->screen->h, vid->screen->format);
|
||||
}
|
||||
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
SDL_WM_SetCaption(buf, NULL);
|
||||
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sdlwrap.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include "general.h"
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#endif
|
||||
|
||||
// SDL 1.2 is portable, sure, but you still need some platform specific workarounds ;)
|
||||
// Hopefully SDL 1.3 will solve this more cleanly :D
|
||||
// Welcome to #ifdef HELL! :D
|
||||
//
|
||||
|
||||
#if SDL_MODERN
|
||||
static SDL_Window* g_window;
|
||||
static SDL_GLContext g_ctx;
|
||||
#endif
|
||||
|
||||
static bool g_fullscreen;
|
||||
static unsigned g_interval;
|
||||
|
||||
void sdlwrap_set_swap_interval(unsigned interval, bool inited)
|
||||
{
|
||||
g_interval = interval;
|
||||
|
||||
#if SDL_MODERN
|
||||
if (g_window)
|
||||
SDL_GL_SetSwapInterval(g_interval);
|
||||
#else
|
||||
if (inited)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL;
|
||||
if (!wgl_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(wgl_swap_interval, "wglSwapIntervalEXT");
|
||||
}
|
||||
if (wgl_swap_interval) wgl_swap_interval(g_interval);
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
GLint val = g_interval;
|
||||
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &val);
|
||||
#else
|
||||
static int (*glx_swap_interval)(int) = NULL;
|
||||
if (!glx_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI");
|
||||
}
|
||||
if (!glx_swap_interval)
|
||||
{
|
||||
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalMESA");
|
||||
}
|
||||
if (glx_swap_interval)
|
||||
glx_swap_interval(g_interval);
|
||||
else
|
||||
SSNES_WARN("Could not find GLX VSync call. :(\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool sdlwrap_init(void)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
return SDL_VideoInit(NULL) == 0;
|
||||
#else
|
||||
return SDL_Init(SDL_INIT_VIDEO) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_MODERN
|
||||
void sdlwrap_destroy(void)
|
||||
{
|
||||
if (g_ctx)
|
||||
SDL_GL_DeleteContext(g_ctx);
|
||||
if (g_window)
|
||||
SDL_DestroyWindow(g_window);
|
||||
|
||||
g_ctx = NULL;
|
||||
g_window = NULL;
|
||||
SDL_VideoQuit();
|
||||
}
|
||||
#else
|
||||
void sdlwrap_destroy(void)
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool sdlwrap_set_video_mode(
|
||||
unsigned width, unsigned height,
|
||||
unsigned bits, bool fullscreen)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
if (g_window)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#if SDL_MODERN
|
||||
static const int resizable = SDL_WINDOW_RESIZABLE;
|
||||
#else
|
||||
#ifndef __APPLE__ // Resizing on OSX is broken in 1.2 it seems :)
|
||||
static const int resizable = SDL_RESIZABLE;
|
||||
#else
|
||||
static const int resizable = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
||||
#if !SDL_MODERN
|
||||
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_interval);
|
||||
#endif
|
||||
|
||||
#if SDL_MODERN
|
||||
if (bits == 15)
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
||||
}
|
||||
g_window = SDL_CreateWindow("SSNES", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (fullscreen ? SDL_WINDOW_FULLSCREEN : resizable));
|
||||
if (!g_window)
|
||||
return false;
|
||||
g_ctx = SDL_GL_CreateContext(g_window);
|
||||
#else
|
||||
if (!SDL_SetVideoMode(width, height, bits,
|
||||
SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : resizable)))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
int attr = 0;
|
||||
#if SDL_MODERN
|
||||
SDL_GL_SetSwapInterval(g_interval);
|
||||
#else
|
||||
SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &attr);
|
||||
if (attr <= 0 && g_interval)
|
||||
{
|
||||
SSNES_WARN("SDL failed to setup VSync, attempting to recover using native calls!\n");
|
||||
sdlwrap_set_swap_interval(g_interval, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
g_fullscreen = fullscreen;
|
||||
|
||||
attr = 0;
|
||||
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attr);
|
||||
if (attr <= 0)
|
||||
SSNES_WARN("GL double buffer has not been enabled!\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void sdlwrap_wm_set_caption(const char *str)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
SDL_SetWindowTitle(g_window, str);
|
||||
#else
|
||||
SDL_WM_SetCaption(str, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void sdlwrap_swap_buffers(void)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
SDL_GL_SwapWindow(g_window);
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool sdlwrap_key_pressed(int key)
|
||||
{
|
||||
int num_keys;
|
||||
#if SDL_MODERN
|
||||
Uint8 *keymap = SDL_GetKeyboardState(&num_keys);
|
||||
key = SDL_GetScancodeFromKey(key);
|
||||
if (key >= num_keys)
|
||||
return false;
|
||||
|
||||
return keymap[key];
|
||||
#else
|
||||
Uint8 *keymap = SDL_GetKeyState(&num_keys);
|
||||
if (key >= num_keys)
|
||||
return false;
|
||||
|
||||
return keymap[key];
|
||||
#endif
|
||||
}
|
||||
|
||||
// 1.2 specific workaround for tiling WMs. In 1.3 we call GetSize directly, so we don't need to rely on
|
||||
// proper event handling (I hope).
|
||||
#if !defined(__APPLE__) && !defined(_WIN32) && !SDL_MODERN
|
||||
static void sdlwrap_get_window_size(unsigned *width, unsigned *height)
|
||||
{
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
SDL_GetWMInfo(&info);
|
||||
XWindowAttributes target;
|
||||
|
||||
info.info.x11.lock_func();
|
||||
XGetWindowAttributes(info.info.x11.display, info.info.x11.window,
|
||||
&target);
|
||||
info.info.x11.unlock_func();
|
||||
|
||||
*width = target.width;
|
||||
*height = target.height;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sdlwrap_check_window(bool *quit,
|
||||
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
|
||||
{
|
||||
*quit = false;
|
||||
*resize = false;
|
||||
SDL_Event event;
|
||||
#if SDL_MODERN
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
*quit = true;
|
||||
return;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
*quit = true;
|
||||
return;
|
||||
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
*resize = true;
|
||||
*width = event.window.data1;
|
||||
*height = event.window.data2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*resize)
|
||||
{
|
||||
int w, h;
|
||||
SDL_GetWindowSize(g_window, &w, &h);
|
||||
if (*width != (unsigned)w || *height != (unsigned)h)
|
||||
{
|
||||
*resize = true;
|
||||
*width = w;
|
||||
*height = h;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
*quit = true;
|
||||
break;
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
*resize = true;
|
||||
*width = event.resize.w;
|
||||
*height = event.resize.h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(__APPLE__) && !defined(_WIN32)
|
||||
// Hack to workaround limitations in tiling WMs ...
|
||||
if (!*resize && !g_fullscreen)
|
||||
{
|
||||
unsigned new_width, new_height;
|
||||
sdlwrap_get_window_size(&new_width, &new_height);
|
||||
if ((new_width != *width || new_height != *height) || (frame_count == 10)) // Ugly hack :D
|
||||
{
|
||||
*resize = true;
|
||||
*width = new_width;
|
||||
*height = new_height;
|
||||
SSNES_LOG("GL: Verified window size: %u x %u\n", *width, *height);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
if (g_window)
|
||||
return SDL_GetWindowWMInfo(g_window, info);
|
||||
else
|
||||
return SDL_GetWMInfo(info) == 1;
|
||||
#else
|
||||
return SDL_GetWMInfo(info) == 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool sdlwrap_window_has_focus(void)
|
||||
{
|
||||
#if SDL_MODERN
|
||||
Uint32 flags = SDL_GetWindowFlags(g_window);
|
||||
flags &= SDL_WINDOW_INPUT_FOCUS;
|
||||
return flags == SDL_WINDOW_INPUT_FOCUS;
|
||||
#else
|
||||
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Compatibility wrapper between SDL 1.2/1.3 for OpenGL.
|
||||
// Wraps functions which differ in 1.2 and 1.3.
|
||||
|
||||
#ifndef __SDLWRAP_H
|
||||
#define __SDLWRAP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_version.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||
#define SDL_MODERN 1
|
||||
#else
|
||||
#define SDL_MODERN 0
|
||||
#endif
|
||||
|
||||
// Not legal to cast void* to fn-pointer. Need workaround to be compliant.
|
||||
#define SDL_SYM_WRAP(sym, symbol) { \
|
||||
assert(sizeof(void*) == sizeof(void (*)(void))); \
|
||||
void *sym__ = SDL_GL_GetProcAddress(symbol); \
|
||||
memcpy(&(sym), &sym__, sizeof(void*)); \
|
||||
}
|
||||
|
||||
void sdlwrap_set_swap_interval(unsigned interval, bool inited);
|
||||
|
||||
bool sdlwrap_set_video_mode(
|
||||
unsigned width, unsigned height,
|
||||
unsigned bits, bool fullscreen);
|
||||
|
||||
bool sdlwrap_init(void);
|
||||
void sdlwrap_destroy(void);
|
||||
|
||||
void sdlwrap_wm_set_caption(const char *str);
|
||||
|
||||
void sdlwrap_swap_buffers(void);
|
||||
|
||||
bool sdlwrap_key_pressed(int key);
|
||||
|
||||
void sdlwrap_check_window(bool *quit,
|
||||
bool *resize, unsigned *width, unsigned *height, unsigned frame_count);
|
||||
|
||||
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info);
|
||||
|
||||
bool sdlwrap_window_has_focus(void);
|
||||
|
||||
#endif
|
||||
|
||||
+65
-12
@@ -36,24 +36,24 @@ static const char* stock_cg_program =
|
||||
"void main_vertex"
|
||||
"("
|
||||
" float4 position : POSITION,"
|
||||
" float4 color : COLOR,"
|
||||
" float2 texCoord : TEXCOORD0,"
|
||||
" float4 color : COLOR,"
|
||||
""
|
||||
" uniform float4x4 modelViewProj,"
|
||||
""
|
||||
" out float4 oPosition : POSITION,"
|
||||
" out float4 oColor : COLOR,"
|
||||
" out float2 otexCoord : TEXCOORD0"
|
||||
" out float2 otexCoord : TEXCOORD0,"
|
||||
" out float4 oColor : COLOR"
|
||||
")"
|
||||
"{"
|
||||
" oPosition = mul(modelViewProj, position);"
|
||||
" oColor = color;"
|
||||
" otexCoord = texCoord;"
|
||||
" oColor = color;"
|
||||
"}"
|
||||
""
|
||||
"float4 main_fragment(float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR"
|
||||
"float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR"
|
||||
"{"
|
||||
" return tex2D(s0, tex);"
|
||||
" return color * tex2D(s0, tex);"
|
||||
"}";
|
||||
|
||||
#ifdef SSNES_CG_DEBUG
|
||||
@@ -112,6 +112,7 @@ struct cg_program
|
||||
|
||||
struct cg_fbo_params fbo[MAX_SHADERS];
|
||||
struct cg_fbo_params orig;
|
||||
struct cg_fbo_params prev;
|
||||
};
|
||||
|
||||
#define FILTER_UNSPEC 0
|
||||
@@ -148,6 +149,7 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
unsigned out_width, unsigned out_height,
|
||||
unsigned frame_count,
|
||||
const struct gl_tex_info *info,
|
||||
const struct gl_tex_info *prev_info,
|
||||
const struct gl_tex_info *fbo_info,
|
||||
unsigned fbo_info_cnt)
|
||||
{
|
||||
@@ -169,7 +171,6 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
if (param)
|
||||
{
|
||||
cgGLSetTextureParameter(param, info->tex);
|
||||
//fprintf(stderr, "ORIGtex = (%d) %d\n", cgGLGetTextureParameter(param), cgGLGetTextureEnum(param) - GL_TEXTURE0);
|
||||
cgGLEnableTextureParameter(param);
|
||||
}
|
||||
|
||||
@@ -183,6 +184,24 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
cgGLEnableClientState(prg[active_index].orig.coord);
|
||||
}
|
||||
|
||||
// Set prev texture
|
||||
param = prg[active_index].prev.tex;
|
||||
if (param)
|
||||
{
|
||||
cgGLSetTextureParameter(param, prev_info->tex);
|
||||
cgGLEnableTextureParameter(param);
|
||||
}
|
||||
|
||||
set_param_2f(prg[active_index].prev.vid_size_v, prev_info->input_size[0], prev_info->input_size[1]);
|
||||
set_param_2f(prg[active_index].prev.vid_size_f, prev_info->input_size[0], prev_info->input_size[1]);
|
||||
set_param_2f(prg[active_index].prev.tex_size_v, prev_info->tex_size[0], prev_info->tex_size[1]);
|
||||
set_param_2f(prg[active_index].prev.tex_size_f, prev_info->tex_size[0], prev_info->tex_size[1]);
|
||||
if (prg[active_index].prev.coord)
|
||||
{
|
||||
cgGLSetParameterPointer(prg[active_index].prev.coord, 2, GL_FLOAT, 0, prev_info->coord);
|
||||
cgGLEnableClientState(prg[active_index].prev.coord);
|
||||
}
|
||||
|
||||
// Set lookup textures.
|
||||
for (unsigned i = 0; i < lut_textures_num; i++)
|
||||
{
|
||||
@@ -191,7 +210,6 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
{
|
||||
cgGLSetTextureParameter(param, lut_textures[i]);
|
||||
cgGLEnableTextureParameter(param);
|
||||
//fprintf(stderr, "LUTtex = (%d) %d\n", cgGLGetTextureParameter(param), cgGLGetTextureEnum(param) - GL_TEXTURE0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,16 +291,31 @@ static bool load_plain(const char *path)
|
||||
if (strlen(g_settings.video.second_pass_shader) > 0)
|
||||
SSNES_LOG("Loading 2nd pass: %s\n", g_settings.video.second_pass_shader);
|
||||
|
||||
char *listing[3] = {NULL};
|
||||
const char *list = NULL;
|
||||
|
||||
prg[0].fprg = cgCreateProgram(cgCtx, CG_SOURCE, stock_cg_program, cgFProf, "main_fragment", 0);
|
||||
prg[0].vprg = cgCreateProgram(cgCtx, CG_SOURCE, stock_cg_program, cgVProf, "main_vertex", 0);
|
||||
|
||||
list = cgGetLastListing(cgCtx);
|
||||
if (list)
|
||||
listing[0] = strdup(list);
|
||||
|
||||
prg[1].fprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgFProf, "main_fragment", 0);
|
||||
prg[1].vprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgVProf, "main_vertex", 0);
|
||||
|
||||
list = cgGetLastListing(cgCtx);
|
||||
if (list)
|
||||
listing[1] = strdup(list);
|
||||
|
||||
if (strlen(g_settings.video.second_pass_shader) > 0)
|
||||
{
|
||||
prg[2].fprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, g_settings.video.second_pass_shader, cgFProf, "main_fragment", 0);
|
||||
prg[2].vprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, g_settings.video.second_pass_shader, cgVProf, "main_vertex", 0);
|
||||
|
||||
list = cgGetLastListing(cgCtx);
|
||||
if (list)
|
||||
listing[2] = strdup(list);
|
||||
cg_shader_num = 2;
|
||||
}
|
||||
else
|
||||
@@ -291,13 +324,15 @@ static bool load_plain(const char *path)
|
||||
cg_shader_num = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cg_shader_num + 1; i++)
|
||||
for (unsigned i = 0; i <= cg_shader_num; i++)
|
||||
{
|
||||
if (!prg[i].fprg || !prg[i].vprg)
|
||||
{
|
||||
CGerror err = cgGetError();
|
||||
SSNES_ERR("CG error: %s\n", cgGetErrorString(err));
|
||||
return false;
|
||||
if (listing[i])
|
||||
SSNES_ERR("%s\n", listing[i]);
|
||||
goto error;
|
||||
}
|
||||
|
||||
cgGLLoadProgram(prg[i].fprg);
|
||||
@@ -305,6 +340,14 @@ static bool load_plain(const char *path)
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
for (unsigned i = 0; i < 3; i++)
|
||||
{
|
||||
if (listing[i])
|
||||
free(listing[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#define print_buf(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__)
|
||||
@@ -358,7 +401,7 @@ static bool load_textures(const char *dir_path, config_file_t *conf)
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, img.width);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, img.width, img.height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img.pixels);
|
||||
0, GL_RGBA, img.width, img.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, img.pixels);
|
||||
|
||||
lut_textures_num++;
|
||||
|
||||
@@ -802,8 +845,11 @@ static bool load_preset(const char *path)
|
||||
|
||||
if (!prog->fprg || !prog->vprg)
|
||||
{
|
||||
const char *listing = cgGetLastListing(cgCtx);
|
||||
CGerror err = cgGetError();
|
||||
SSNES_ERR("CG error: %s\n", cgGetErrorString(err));
|
||||
if (listing)
|
||||
SSNES_ERR("%s\n", listing);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -878,7 +924,7 @@ bool gl_cg_init(const char *path)
|
||||
if (prg[0].mvp)
|
||||
cgGLSetStateMatrixParameter(prg[0].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
|
||||
for (unsigned i = 1; i < cg_shader_num + 1; i++)
|
||||
for (unsigned i = 1; i <= cg_shader_num; i++)
|
||||
{
|
||||
cgGLBindProgram(prg[i].fprg);
|
||||
cgGLBindProgram(prg[i].vprg);
|
||||
@@ -902,6 +948,13 @@ bool gl_cg_init(const char *path)
|
||||
prg[i].orig.tex_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.texture_size");
|
||||
prg[i].orig.coord = cgGetNamedParameter(prg[i].vprg, "ORIG.tex_coord");
|
||||
|
||||
prg[i].prev.tex = cgGetNamedParameter(prg[i].fprg, "PREV.texture");
|
||||
prg[i].prev.vid_size_v = cgGetNamedParameter(prg[i].vprg, "PREV.video_size");
|
||||
prg[i].prev.vid_size_f = cgGetNamedParameter(prg[i].fprg, "PREV.video_size");
|
||||
prg[i].prev.tex_size_v = cgGetNamedParameter(prg[i].vprg, "PREV.texture_size");
|
||||
prg[i].prev.tex_size_f = cgGetNamedParameter(prg[i].fprg, "PREV.texture_size");
|
||||
prg[i].prev.coord = cgGetNamedParameter(prg[i].vprg, "PREV.tex_coord");
|
||||
|
||||
for (unsigned j = 0; j < i - 1; j++)
|
||||
{
|
||||
char attr_buf[64];
|
||||
|
||||
@@ -33,6 +33,7 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
unsigned out_width, unsigned out_height,
|
||||
unsigned frame_count,
|
||||
const struct gl_tex_info *info,
|
||||
const struct gl_tex_info *prev_info,
|
||||
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt);
|
||||
|
||||
void gl_cg_use(unsigned index);
|
||||
|
||||
+40
-12
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
#define NO_SDL_GLEXT
|
||||
#include "SDL.h"
|
||||
#include "sdlwrap.h"
|
||||
#include "SDL_opengl.h"
|
||||
#include <stdlib.h>
|
||||
#include <libxml/parser.h>
|
||||
@@ -356,7 +356,7 @@ static bool get_texture_image(const char *shader_path, xmlNodePtr ptr)
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, img.width);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0, GL_RGBA, img.width, img.height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img.pixels);
|
||||
0, GL_RGBA, img.width, img.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, img.pixels);
|
||||
|
||||
pglActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
@@ -712,8 +712,8 @@ error:
|
||||
|
||||
static void print_shader_log(GLuint obj)
|
||||
{
|
||||
int info_len = 0;
|
||||
int max_len;
|
||||
GLint info_len = 0;
|
||||
GLint max_len;
|
||||
|
||||
pglGetShaderiv(obj, GL_INFO_LOG_LENGTH, &max_len);
|
||||
|
||||
@@ -726,8 +726,8 @@ static void print_shader_log(GLuint obj)
|
||||
|
||||
static void print_linker_log(GLuint obj)
|
||||
{
|
||||
int info_len = 0;
|
||||
int max_len;
|
||||
GLint info_len = 0;
|
||||
GLint max_len;
|
||||
|
||||
pglGetProgramiv(obj, GL_INFO_LOG_LENGTH, &max_len);
|
||||
|
||||
@@ -1005,8 +1005,16 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
unsigned out_width, unsigned out_height,
|
||||
unsigned frame_count,
|
||||
const struct gl_tex_info *info,
|
||||
const struct gl_tex_info *prev_info,
|
||||
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
|
||||
{
|
||||
// We enforce a certain layout for our various texture types in the texunits.
|
||||
// Unit 0: Regular SNES frame (rubyTexture).
|
||||
// Unit 1-A: LUT textures.
|
||||
// Unit A+1: Previous texture.
|
||||
// Unit A+2: Original texture.
|
||||
// Unit A+3-B: FBO textures.
|
||||
|
||||
if (glsl_enable && gl_program[active_index] > 0)
|
||||
{
|
||||
GLint location;
|
||||
@@ -1032,15 +1040,34 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
pglUniform1i(location, i + 1);
|
||||
}
|
||||
|
||||
// Set previous texture.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, prev_info->tex);
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevTexture");
|
||||
pglUniform1i(location, gl_teximage_cnt + 1);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevTextureSize");
|
||||
pglUniform2fv(location, 1, prev_info->tex_size);
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyPrevInputSize");
|
||||
pglUniform2fv(location, 1, prev_info->input_size);
|
||||
|
||||
// Pass texture coordinates.
|
||||
location = pglGetAttribLocation(gl_program[active_index], "rubyPrevTexCoord");
|
||||
if (location >= 0)
|
||||
{
|
||||
pglEnableVertexAttribArray(location);
|
||||
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, prev_info->coord);
|
||||
}
|
||||
|
||||
// Set original texture unless we're in first pass (pointless).
|
||||
if (active_index > 1)
|
||||
{
|
||||
// Bind original texture.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, info->tex);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTexture");
|
||||
pglUniform1i(location, gl_teximage_cnt + 1);
|
||||
pglUniform1i(location, gl_teximage_cnt + 2);
|
||||
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTextureSize");
|
||||
pglUniform2fv(location, 1, info->tex_size);
|
||||
@@ -1055,7 +1082,7 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, info->coord);
|
||||
}
|
||||
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 2;
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 3;
|
||||
|
||||
// Bind new texture in the chain.
|
||||
if (fbo_info_cnt > 0)
|
||||
@@ -1093,14 +1120,15 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
else
|
||||
{
|
||||
// First pass, so unbind everything to avoid collitions.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
|
||||
// Unbind ORIG.
|
||||
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 2;
|
||||
GLuint base_tex = GL_TEXTURE0 + gl_teximage_cnt + 3;
|
||||
// Unbind any lurking FBO passes.
|
||||
// Rendering to a texture that is bound to a texture unit
|
||||
// sounds very shaky ... ;)
|
||||
for (int i = 0; i < gl_num_programs; i++)
|
||||
for (unsigned i = 0; i < gl_num_programs; i++)
|
||||
{
|
||||
pglActiveTexture(GL_TEXTURE0 + base_tex + i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
@@ -33,6 +33,7 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
unsigned out_width, unsigned out_height,
|
||||
unsigned frame_counter,
|
||||
const struct gl_tex_info *info,
|
||||
const struct gl_tex_info *prev_info,
|
||||
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt);
|
||||
|
||||
void gl_glsl_use(unsigned index);
|
||||
|
||||
+104
-49
@@ -63,11 +63,17 @@ struct xv
|
||||
uint8_t *ytable;
|
||||
uint8_t *utable;
|
||||
uint8_t *vtable;
|
||||
unsigned luma_i;
|
||||
unsigned chroma_i;
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
font_renderer_t *font;
|
||||
|
||||
unsigned luma_index[2];
|
||||
unsigned chroma_u_index;
|
||||
unsigned chroma_v_index;
|
||||
|
||||
uint8_t font_y;
|
||||
uint8_t font_u;
|
||||
uint8_t font_v;
|
||||
#endif
|
||||
|
||||
void (*render_func)(xv_t*, const void *frame, unsigned width, unsigned height, unsigned pitch);
|
||||
@@ -89,6 +95,17 @@ static void sighandler(int sig)
|
||||
g_quit = 1;
|
||||
}
|
||||
|
||||
static inline void calculate_yuv(uint8_t *y, uint8_t *u, uint8_t *v, unsigned r, unsigned g, unsigned b)
|
||||
{
|
||||
int y_ = (int)(+((double)r * 0.257) + ((double)g * 0.504) + ((double)b * 0.098) + 16.0);
|
||||
int u_ = (int)(-((double)r * 0.148) - ((double)g * 0.291) + ((double)b * 0.439) + 128.0);
|
||||
int v_ = (int)(+((double)r * 0.439) - ((double)g * 0.368) - ((double)b * 0.071) + 128.0);
|
||||
|
||||
*y = y_ < 0 ? 0 : (y_ > 255 ? 255 : y_);
|
||||
*u = y_ < 0 ? 0 : (u_ > 255 ? 255 : u_);
|
||||
*v = v_ < 0 ? 0 : (v_ > 255 ? 255 : v_);
|
||||
}
|
||||
|
||||
static void init_yuv_tables(xv_t *xv)
|
||||
{
|
||||
xv->ytable = malloc(0x8000);
|
||||
@@ -98,18 +115,12 @@ static void init_yuv_tables(xv_t *xv)
|
||||
for (unsigned i = 0; i < 0x8000; i++)
|
||||
{
|
||||
// Extract RGB555 color data from i
|
||||
uint8_t r = (i >> 10) & 0x1F, g = (i >> 5) & 0x1F, b = (i) & 0x1F;
|
||||
r = (r << 3) | (r >> 2); //R5->R8
|
||||
g = (g << 3) | (g >> 2); //G5->G8
|
||||
b = (b << 3) | (b >> 2); //B5->B8
|
||||
unsigned r = (i >> 10) & 0x1F, g = (i >> 5) & 0x1F, b = (i) & 0x1F;
|
||||
r = (r << 3) | (r >> 2); // R5->R8
|
||||
g = (g << 3) | (g >> 2); // G5->G8
|
||||
b = (b << 3) | (b >> 2); // B5->B8
|
||||
|
||||
int y = (int)(+((double)r * 0.257) + ((double)g * 0.504) + ((double)b * 0.098) + 16.0);
|
||||
int u = (int)(-((double)r * 0.148) - ((double)g * 0.291) + ((double)b * 0.439) + 128.0);
|
||||
int v = (int)(+((double)r * 0.439) - ((double)g * 0.368) - ((double)b * 0.071) + 128.0);
|
||||
|
||||
xv->ytable[i] = y < 0 ? 0 : y > 255 ? 255 : y;
|
||||
xv->utable[i] = u < 0 ? 0 : u > 255 ? 255 : u;
|
||||
xv->vtable[i] = v < 0 ? 0 : v > 255 ? 255 : v;
|
||||
calculate_yuv(&xv->ytable[i], &xv->utable[i], &xv->vtable[i], r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +187,19 @@ static void xv_init_font(xv_t *xv, const char *font_path, unsigned font_size)
|
||||
if (*font_path)
|
||||
{
|
||||
xv->font = font_renderer_new(font_path, font_size);
|
||||
if (!xv->font)
|
||||
if (xv->font)
|
||||
{
|
||||
int r = g_settings.video.msg_color_r * 255;
|
||||
r = (r < 0 ? 0 : (r > 255 ? 255 : r));
|
||||
int g = g_settings.video.msg_color_g * 255;
|
||||
g = (g < 0 ? 0 : (g > 255 ? 255 : g));
|
||||
int b = g_settings.video.msg_color_b * 255;
|
||||
b = (b < 0 ? 0 : (b > 255 ? 255 : b));
|
||||
|
||||
calculate_yuv(&xv->font_y, &xv->font_u, &xv->font_v,
|
||||
r, g, b);
|
||||
}
|
||||
else
|
||||
SSNES_WARN("Failed to init font.\n");
|
||||
}
|
||||
#endif
|
||||
@@ -297,7 +320,6 @@ static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void* xv_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
||||
{
|
||||
xv_t *xv = calloc(1, sizeof(*xv));
|
||||
@@ -383,7 +405,7 @@ static void* xv_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
|
||||
// Set colorkey to auto paint, so that Xv video output is always visible
|
||||
Atom atom = XInternAtom(xv->display, "XV_AUTOPAINT_COLORKEY", true);
|
||||
if(atom != None) XvSetPortAttribute(xv->display, xv->port, atom, 1);
|
||||
if (atom != None) XvSetPortAttribute(xv->display, xv->port, atom, 1);
|
||||
|
||||
int format_count;
|
||||
XvImageFormatValues *format = XvListImageFormats(xv->display, xv->port, &format_count);
|
||||
@@ -399,29 +421,43 @@ static void* xv_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
has_format = true;
|
||||
xv->fourcc = format[i].id;
|
||||
xv->render_func = video->rgb32 ? render32_yuy2 : render16_yuy2;
|
||||
xv->luma_i = 0; xv->chroma_i = 1;
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
xv->luma_index[0] = 0;
|
||||
xv->luma_index[1] = 2;
|
||||
xv->chroma_u_index = 1;
|
||||
xv->chroma_v_index = 3;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_format) for (int i = 0; i < format_count; i++)
|
||||
if (!has_format)
|
||||
{
|
||||
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
|
||||
for (int i = 0; i < format_count; i++)
|
||||
{
|
||||
if (format[i].component_order[0] == 'U' && format[i].component_order[1] == 'Y'
|
||||
&& format[i].component_order[2] == 'V' && format[i].component_order[3] == 'Y')
|
||||
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
|
||||
{
|
||||
has_format = true;
|
||||
xv->fourcc = format[i].id;
|
||||
xv->render_func = video->rgb32 ? render32_uyvy : render16_uyvy;
|
||||
xv->chroma_i = 0; xv->luma_i = 1;
|
||||
break;
|
||||
if (format[i].component_order[0] == 'U' && format[i].component_order[1] == 'Y'
|
||||
&& format[i].component_order[2] == 'V' && format[i].component_order[3] == 'Y')
|
||||
{
|
||||
has_format = true;
|
||||
xv->fourcc = format[i].id;
|
||||
xv->render_func = video->rgb32 ? render32_uyvy : render16_uyvy;
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
xv->luma_index[0] = 1;
|
||||
xv->luma_index[1] = 3;
|
||||
xv->chroma_u_index = 0;
|
||||
xv->chroma_v_index = 2;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(format);
|
||||
if (!has_format)
|
||||
{
|
||||
@@ -466,8 +502,6 @@ static void* xv_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
xv_set_nonblock_state(xv, !video->vsync);
|
||||
xv->focus = true;
|
||||
|
||||
xv_init_font(xv, g_settings.video.font_path, g_settings.video.font_size);
|
||||
|
||||
void *xinput = input_x.init();
|
||||
if (xinput)
|
||||
{
|
||||
@@ -478,6 +512,8 @@ static void* xv_init(const video_info_t *video, const input_driver_t **input, vo
|
||||
*input = NULL;
|
||||
|
||||
init_yuv_tables(xv);
|
||||
xv_init_font(xv, g_settings.video.font_path, g_settings.video.font_size);
|
||||
|
||||
return xv;
|
||||
|
||||
error:
|
||||
@@ -561,6 +597,7 @@ static void calc_out_rect(bool keep_aspect, unsigned *x, unsigned *y, unsigned *
|
||||
}
|
||||
|
||||
// TODO: Is there some way to render directly like GL? :(
|
||||
// Hacky C code is hacky :D Yay.
|
||||
static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned height)
|
||||
{
|
||||
#ifdef HAVE_FREETYPE
|
||||
@@ -574,12 +611,17 @@ static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned he
|
||||
int _base_x = g_settings.video.msg_pos_x * width;
|
||||
int _base_y = height - g_settings.video.msg_pos_y * height;
|
||||
|
||||
unsigned luma_i = xv->luma_i;
|
||||
unsigned chroma_i = xv->chroma_i;
|
||||
unsigned luma_index[2] = { xv->luma_index[0], xv->luma_index[1] };
|
||||
unsigned chroma_u_index = xv->chroma_u_index;
|
||||
unsigned chroma_v_index = xv->chroma_v_index;
|
||||
|
||||
unsigned pitch = width << 1; // YUV formats used are 16 bpp.
|
||||
|
||||
while (head)
|
||||
{
|
||||
int base_x = _base_x + head->off_x;
|
||||
int base_x = (_base_x + head->off_x) << 1;
|
||||
base_x &= ~3; // Make sure we always start on the correct boundary so the indices are correct.
|
||||
|
||||
int base_y = _base_y - head->off_y;
|
||||
if (base_y >= 0)
|
||||
{
|
||||
@@ -588,21 +630,33 @@ static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned he
|
||||
if (base_x < 0)
|
||||
continue;
|
||||
|
||||
const uint8_t *a = head->output + head->pitch * y;
|
||||
uint8_t *out = (uint8_t*)xv->image->data + (base_y - head->height + y) * (width << 1) + (base_x << 1);
|
||||
const uint8_t * restrict a = head->output + head->pitch * y;
|
||||
uint8_t * restrict out = (uint8_t*)xv->image->data + (base_y - head->height + y) * pitch + base_x;
|
||||
|
||||
for (int x = 0; x < (head->width << 1) && (base_x + x) < width; x += 2)
|
||||
for (int x = 0; x < (head->width << 1) && (base_x + x) < pitch; x += 4)
|
||||
{
|
||||
// Blend luma
|
||||
uint8_t blend = a[x >> 1];
|
||||
unsigned blended = blend + (((256 - blend) * (unsigned)out[x + luma_i]) >> 8);
|
||||
blended = blended > 255 ? 255 : blended;
|
||||
out[x + luma_i] = blended;
|
||||
unsigned alpha[2];
|
||||
alpha[0] = a[(x >> 1) + 0];
|
||||
|
||||
// Blend chroma
|
||||
blended = (128 * blend + ((256 - blend) * (unsigned)out[x + chroma_i])) >> 8;
|
||||
blended = blended > 255 ? 255 : blended;
|
||||
out[x + chroma_i] = blended;
|
||||
if (((x >> 1) + 1) == head->width) // We reached the end, uhoh! Branching like a BOSS! :D
|
||||
alpha[1] = 0;
|
||||
else
|
||||
alpha[1] = a[(x >> 1) + 1];
|
||||
|
||||
unsigned alpha_sub = (alpha[0] + alpha[1]) >> 1; // Blended alpha for the sub-samples U/V channels.
|
||||
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
{
|
||||
unsigned blended = (xv->font_y * alpha[i] + ((256 - alpha[i]) * out[x + luma_index[i]])) >> 8;
|
||||
out[x + luma_index[i]] = blended;
|
||||
}
|
||||
|
||||
// Blend chroma channels
|
||||
unsigned blended = (xv->font_u * alpha_sub + ((256 - alpha_sub) * out[x + chroma_u_index])) >> 8;
|
||||
out[x + chroma_u_index] = blended;
|
||||
|
||||
blended = (xv->font_v * alpha_sub + ((256 - alpha_sub) * out[x + chroma_v_index])) >> 8;
|
||||
out[x + chroma_v_index] = blended;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -630,11 +684,12 @@ static bool xv_frame(void *data, const void* frame, unsigned width, unsigned hei
|
||||
XGetWindowAttributes(xv->display, xv->window, &target);
|
||||
xv->render_func(xv, frame, width, height, pitch);
|
||||
|
||||
if (msg)
|
||||
xv_render_msg(xv, msg, xv->width, xv->height);
|
||||
|
||||
unsigned x, y, owidth, oheight;
|
||||
calc_out_rect(xv->keep_aspect, &x, &y, &owidth, &oheight, target.width, target.height);
|
||||
|
||||
if (msg)
|
||||
xv_render_msg(xv, msg, width << 1, height << 1);
|
||||
|
||||
XvShmPutImage(xv->display, xv->port, xv->window, xv->gc, xv->image,
|
||||
0, 0, width << 1, height << 1,
|
||||
x, y, owidth, oheight,
|
||||
@@ -693,9 +748,9 @@ static void xv_free(void *data)
|
||||
shmctl(xv->shminfo.shmid, IPC_RMID, NULL);
|
||||
XFree(xv->image);
|
||||
|
||||
if(xv->window)
|
||||
if (xv->window)
|
||||
XUnmapWindow(xv->display, xv->window);
|
||||
if(xv->colormap)
|
||||
if (xv->colormap)
|
||||
XFreeColormap(xv->display, xv->colormap);
|
||||
|
||||
XCloseDisplay(xv->display);
|
||||
|
||||
+11
-3
@@ -15,13 +15,14 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ssnes_dinput.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include <stdbool.h>
|
||||
#include "ssnes_dinput.h"
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "../gfx/sdlwrap.h"
|
||||
|
||||
void sdl_dinput_free(sdl_dinput_t *di)
|
||||
{
|
||||
@@ -45,7 +46,7 @@ void sdl_dinput_free(sdl_dinput_t *di)
|
||||
|
||||
static BOOL CALLBACK enum_axes_cb(const DIDEVICEOBJECTINSTANCE *inst, void *p)
|
||||
{
|
||||
IDirectInputDevice8 *joypad = p;
|
||||
LPDIRECTINPUTDEVICE8 joypad = p;
|
||||
|
||||
DIPROPRANGE range;
|
||||
memset(&range, 0, sizeof(range));
|
||||
@@ -103,12 +104,19 @@ sdl_dinput_t* sdl_dinput_init(void)
|
||||
CoInitialize(NULL);
|
||||
|
||||
SDL_SysWMinfo info;
|
||||
if (!SDL_GetWMInfo(&info))
|
||||
SDL_VERSION(&info.version);
|
||||
|
||||
if (!sdlwrap_get_wm_info(&info))
|
||||
{
|
||||
SSNES_ERR("Failed to get SysWM info.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
#if SDL_MODERN
|
||||
di->hWnd = info.info.win.window;
|
||||
#else
|
||||
di->hWnd = info.window;
|
||||
#endif
|
||||
|
||||
if (FAILED(DirectInput8Create(
|
||||
GetModuleHandle(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8,
|
||||
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES 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 Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES 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 SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __SSNES_KEYSYM_H
|
||||
#define __SSNES_KEYSYM_H
|
||||
|
||||
// Global keysym table for SSNES.
|
||||
// As you may have noticed, it's the same as SDL 1.2 since I'm lazy.
|
||||
|
||||
enum ssnes_key
|
||||
{
|
||||
SK_UNKNOWN = 0,
|
||||
SK_FIRST = 0,
|
||||
SK_BACKSPACE = 8,
|
||||
SK_TAB = 9,
|
||||
SK_CLEAR = 12,
|
||||
SK_RETURN = 13,
|
||||
SK_PAUSE = 19,
|
||||
SK_ESCAPE = 27,
|
||||
SK_SPACE = 32,
|
||||
SK_EXCLAIM = 33,
|
||||
SK_QUOTEDBL = 34,
|
||||
SK_HASH = 35,
|
||||
SK_DOLLAR = 36,
|
||||
SK_AMPERSAND = 38,
|
||||
SK_QUOTE = 39,
|
||||
SK_LEFTPAREN = 40,
|
||||
SK_RIGHTPAREN = 41,
|
||||
SK_ASTERISK = 42,
|
||||
SK_PLUS = 43,
|
||||
SK_COMMA = 44,
|
||||
SK_MINUS = 45,
|
||||
SK_PERIOD = 46,
|
||||
SK_SLASH = 47,
|
||||
SK_0 = 48,
|
||||
SK_1 = 49,
|
||||
SK_2 = 50,
|
||||
SK_3 = 51,
|
||||
SK_4 = 52,
|
||||
SK_5 = 53,
|
||||
SK_6 = 54,
|
||||
SK_7 = 55,
|
||||
SK_8 = 56,
|
||||
SK_9 = 57,
|
||||
SK_COLON = 58,
|
||||
SK_SEMICOLON = 59,
|
||||
SK_LESS = 60,
|
||||
SK_EQUALS = 61,
|
||||
SK_GREATER = 62,
|
||||
SK_QUESTION = 63,
|
||||
SK_AT = 64,
|
||||
SK_LEFTBRACKET = 91,
|
||||
SK_BACKSLASH = 92,
|
||||
SK_RIGHTBRACKET = 93,
|
||||
SK_CARET = 94,
|
||||
SK_UNDERSCORE = 95,
|
||||
SK_BACKQUOTE = 96,
|
||||
SK_a = 97,
|
||||
SK_b = 98,
|
||||
SK_c = 99,
|
||||
SK_d = 100,
|
||||
SK_e = 101,
|
||||
SK_f = 102,
|
||||
SK_g = 103,
|
||||
SK_h = 104,
|
||||
SK_i = 105,
|
||||
SK_j = 106,
|
||||
SK_k = 107,
|
||||
SK_l = 108,
|
||||
SK_m = 109,
|
||||
SK_n = 110,
|
||||
SK_o = 111,
|
||||
SK_p = 112,
|
||||
SK_q = 113,
|
||||
SK_r = 114,
|
||||
SK_s = 115,
|
||||
SK_t = 116,
|
||||
SK_u = 117,
|
||||
SK_v = 118,
|
||||
SK_w = 119,
|
||||
SK_x = 120,
|
||||
SK_y = 121,
|
||||
SK_z = 122,
|
||||
SK_DELETE = 127,
|
||||
|
||||
SK_KP0 = 256,
|
||||
SK_KP1 = 257,
|
||||
SK_KP2 = 258,
|
||||
SK_KP3 = 259,
|
||||
SK_KP4 = 260,
|
||||
SK_KP5 = 261,
|
||||
SK_KP6 = 262,
|
||||
SK_KP7 = 263,
|
||||
SK_KP8 = 264,
|
||||
SK_KP9 = 265,
|
||||
SK_KP_PERIOD = 266,
|
||||
SK_KP_DIVIDE = 267,
|
||||
SK_KP_MULTIPLY = 268,
|
||||
SK_KP_MINUS = 269,
|
||||
SK_KP_PLUS = 270,
|
||||
SK_KP_ENTER = 271,
|
||||
SK_KP_EQUALS = 272,
|
||||
|
||||
SK_UP = 273,
|
||||
SK_DOWN = 274,
|
||||
SK_RIGHT = 275,
|
||||
SK_LEFT = 276,
|
||||
SK_INSERT = 277,
|
||||
SK_HOME = 278,
|
||||
SK_END = 279,
|
||||
SK_PAGEUP = 280,
|
||||
SK_PAGEDOWN = 281,
|
||||
|
||||
SK_F1 = 282,
|
||||
SK_F2 = 283,
|
||||
SK_F3 = 284,
|
||||
SK_F4 = 285,
|
||||
SK_F5 = 286,
|
||||
SK_F6 = 287,
|
||||
SK_F7 = 288,
|
||||
SK_F8 = 289,
|
||||
SK_F9 = 290,
|
||||
SK_F10 = 291,
|
||||
SK_F11 = 292,
|
||||
SK_F12 = 293,
|
||||
SK_F13 = 294,
|
||||
SK_F14 = 295,
|
||||
SK_F15 = 296,
|
||||
|
||||
SK_NUMLOCK = 300,
|
||||
SK_CAPSLOCK = 301,
|
||||
SK_SCROLLOCK = 302,
|
||||
SK_RSHIFT = 303,
|
||||
SK_LSHIFT = 304,
|
||||
SK_RCTRL = 305,
|
||||
SK_LCTRL = 306,
|
||||
SK_RALT = 307,
|
||||
SK_LALT = 308,
|
||||
SK_RMETA = 309,
|
||||
SK_LMETA = 310,
|
||||
SK_LSUPER = 311,
|
||||
SK_RSUPER = 312,
|
||||
SK_MODE = 313,
|
||||
SK_COMPOSE = 314,
|
||||
|
||||
SK_HELP = 315,
|
||||
SK_PRINT = 316,
|
||||
SK_SYSREQ = 317,
|
||||
SK_BREAK = 318,
|
||||
SK_MENU = 319,
|
||||
SK_POWER = 320,
|
||||
SK_EURO = 321,
|
||||
SK_UNDO = 322,
|
||||
|
||||
SK_LAST
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+99
-9
@@ -17,17 +17,114 @@
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
#include "SDL.h"
|
||||
#include "../gfx/sdlwrap.h"
|
||||
#include <stdbool.h>
|
||||
#include "general.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <libsnes.hpp>
|
||||
#include "ssnes_sdl_input.h"
|
||||
#include "keysym.h"
|
||||
|
||||
struct key_bind
|
||||
{
|
||||
unsigned sdl;
|
||||
enum ssnes_key sk;
|
||||
};
|
||||
|
||||
static unsigned keysym_lut[SK_LAST];
|
||||
static const struct key_bind lut_binds[] = {
|
||||
{ SDLK_LEFT, SK_LEFT },
|
||||
{ SDLK_RIGHT, SK_RIGHT },
|
||||
{ SDLK_UP, SK_UP },
|
||||
{ SDLK_DOWN, SK_DOWN },
|
||||
{ SDLK_RETURN, SK_RETURN },
|
||||
{ SDLK_TAB, SK_TAB },
|
||||
{ SDLK_INSERT, SK_INSERT },
|
||||
{ SDLK_DELETE, SK_DELETE },
|
||||
{ SDLK_RSHIFT, SK_RSHIFT },
|
||||
{ SDLK_LSHIFT, SK_LSHIFT },
|
||||
{ SDLK_LCTRL, SK_LCTRL },
|
||||
{ SDLK_LALT, SK_LALT },
|
||||
{ SDLK_SPACE, SK_SPACE },
|
||||
{ SDLK_ESCAPE, SK_ESCAPE },
|
||||
{ SDLK_BACKSPACE, SK_BACKSPACE },
|
||||
{ SDLK_KP_ENTER, SK_KP_ENTER },
|
||||
{ SDLK_KP_PLUS, SK_KP_PLUS },
|
||||
{ SDLK_KP_MINUS, SK_KP_MINUS },
|
||||
{ SDLK_KP_MULTIPLY, SK_KP_MULTIPLY },
|
||||
{ SDLK_KP_DIVIDE, SK_KP_DIVIDE },
|
||||
{ SDLK_BACKQUOTE, SK_BACKQUOTE },
|
||||
{ SDLK_KP0, SK_KP0 },
|
||||
{ SDLK_KP1, SK_KP1 },
|
||||
{ SDLK_KP2, SK_KP2 },
|
||||
{ SDLK_KP3, SK_KP3 },
|
||||
{ SDLK_KP4, SK_KP4 },
|
||||
{ SDLK_KP5, SK_KP5 },
|
||||
{ SDLK_KP6, SK_KP6 },
|
||||
{ SDLK_KP7, SK_KP7 },
|
||||
{ SDLK_KP8, SK_KP8 },
|
||||
{ SDLK_KP9, SK_KP9 },
|
||||
{ SDLK_0, SK_0 },
|
||||
{ SDLK_1, SK_1 },
|
||||
{ SDLK_2, SK_2 },
|
||||
{ SDLK_3, SK_3 },
|
||||
{ SDLK_4, SK_4 },
|
||||
{ SDLK_5, SK_5 },
|
||||
{ SDLK_6, SK_6 },
|
||||
{ SDLK_7, SK_7 },
|
||||
{ SDLK_8, SK_8 },
|
||||
{ SDLK_9, SK_9 },
|
||||
{ SDLK_F1, SK_F1 },
|
||||
{ SDLK_F2, SK_F2 },
|
||||
{ SDLK_F3, SK_F3 },
|
||||
{ SDLK_F4, SK_F4 },
|
||||
{ SDLK_F5, SK_F5 },
|
||||
{ SDLK_F6, SK_F6 },
|
||||
{ SDLK_F7, SK_F7 },
|
||||
{ SDLK_F8, SK_F8 },
|
||||
{ SDLK_F9, SK_F9 },
|
||||
{ SDLK_F10, SK_F10 },
|
||||
{ SDLK_F11, SK_F11 },
|
||||
{ SDLK_F12, SK_F12 },
|
||||
{ SDLK_a, SK_a },
|
||||
{ SDLK_b, SK_b },
|
||||
{ SDLK_c, SK_c },
|
||||
{ SDLK_d, SK_d },
|
||||
{ SDLK_e, SK_e },
|
||||
{ SDLK_f, SK_f },
|
||||
{ SDLK_g, SK_g },
|
||||
{ SDLK_h, SK_h },
|
||||
{ SDLK_i, SK_i },
|
||||
{ SDLK_j, SK_j },
|
||||
{ SDLK_k, SK_k },
|
||||
{ SDLK_l, SK_l },
|
||||
{ SDLK_m, SK_m },
|
||||
{ SDLK_n, SK_n },
|
||||
{ SDLK_o, SK_o },
|
||||
{ SDLK_p, SK_p },
|
||||
{ SDLK_q, SK_q },
|
||||
{ SDLK_r, SK_r },
|
||||
{ SDLK_s, SK_s },
|
||||
{ SDLK_t, SK_t },
|
||||
{ SDLK_u, SK_u },
|
||||
{ SDLK_v, SK_v },
|
||||
{ SDLK_w, SK_w },
|
||||
{ SDLK_x, SK_x },
|
||||
{ SDLK_y, SK_y },
|
||||
{ SDLK_z, SK_z },
|
||||
};
|
||||
|
||||
static void init_lut(void)
|
||||
{
|
||||
memset(keysym_lut, 0, sizeof(keysym_lut));
|
||||
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
|
||||
keysym_lut[lut_binds[i].sk] = lut_binds[i].sdl;
|
||||
}
|
||||
|
||||
static void* sdl_input_init(void)
|
||||
{
|
||||
init_lut();
|
||||
sdl_input_t *sdl = calloc(1, sizeof(*sdl));
|
||||
if (!sdl)
|
||||
return NULL;
|
||||
@@ -76,16 +173,9 @@ static void* sdl_input_init(void)
|
||||
return sdl;
|
||||
}
|
||||
|
||||
|
||||
static bool sdl_key_pressed(int key)
|
||||
{
|
||||
int num_keys;
|
||||
Uint8 *keymap = SDL_GetKeyState(&num_keys);
|
||||
|
||||
if (key >= num_keys)
|
||||
return false;
|
||||
|
||||
return keymap[key];
|
||||
return sdlwrap_key_pressed(keysym_lut[key]);
|
||||
}
|
||||
|
||||
#ifndef HAVE_DINPUT
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
typedef struct sdl_dinput
|
||||
{
|
||||
HWND hWnd;
|
||||
IDirectInput8 *ctx;
|
||||
IDirectInputDevice8 *joypad[MAX_PLAYERS];
|
||||
LPDIRECTINPUT8 ctx;
|
||||
LPDIRECTINPUTDEVICE8 joypad[MAX_PLAYERS];
|
||||
unsigned joypad_cnt;
|
||||
DIJOYSTATE2 joy_state[MAX_PLAYERS];
|
||||
} sdl_dinput_t;
|
||||
|
||||
+84
-85
@@ -23,6 +23,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "ssnes_sdl_input.h"
|
||||
#include "keysym.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
@@ -37,100 +38,98 @@ typedef struct x11_input
|
||||
|
||||
struct key_bind
|
||||
{
|
||||
int x;
|
||||
int sdl;
|
||||
unsigned x;
|
||||
enum ssnes_key sk;
|
||||
};
|
||||
|
||||
static int keysym_lut[SDLK_LAST];
|
||||
static unsigned keysym_lut[SK_LAST];
|
||||
static const struct key_bind lut_binds[] = {
|
||||
{ XK_Left, SDLK_LEFT },
|
||||
{ XK_Right, SDLK_RIGHT },
|
||||
{ XK_Up, SDLK_UP },
|
||||
{ XK_Down, SDLK_DOWN },
|
||||
{ XK_Return, SDLK_RETURN },
|
||||
{ XK_Tab, SDLK_TAB },
|
||||
{ XK_Insert, SDLK_INSERT },
|
||||
{ XK_Delete, SDLK_DELETE },
|
||||
{ XK_Shift_R, SDLK_RSHIFT },
|
||||
{ XK_Shift_L, SDLK_LSHIFT },
|
||||
{ XK_Control_L, SDLK_LCTRL },
|
||||
{ XK_Alt_L, SDLK_LALT },
|
||||
{ XK_space, SDLK_SPACE },
|
||||
{ XK_Escape, SDLK_ESCAPE },
|
||||
{ XK_KP_Add, SDLK_KP_PLUS },
|
||||
{ XK_KP_Subtract, SDLK_KP_MINUS },
|
||||
{ XK_BackSpace, SDLK_BACKSPACE },
|
||||
{ XK_KP_Enter, SDLK_KP_ENTER },
|
||||
{ XK_KP_Add, SDLK_KP_PLUS },
|
||||
{ XK_KP_Subtract, SDLK_KP_MINUS },
|
||||
{ XK_KP_Multiply, SDLK_KP_MULTIPLY },
|
||||
{ XK_KP_Divide, SDLK_KP_DIVIDE },
|
||||
{ XK_grave, SDLK_BACKQUOTE },
|
||||
{ XK_KP_0, SDLK_KP0 },
|
||||
{ XK_KP_1, SDLK_KP1 },
|
||||
{ XK_KP_2, SDLK_KP2 },
|
||||
{ XK_KP_3, SDLK_KP3 },
|
||||
{ XK_KP_4, SDLK_KP4 },
|
||||
{ XK_KP_5, SDLK_KP5 },
|
||||
{ XK_KP_6, SDLK_KP6 },
|
||||
{ XK_KP_7, SDLK_KP7 },
|
||||
{ XK_KP_8, SDLK_KP8 },
|
||||
{ XK_KP_9, SDLK_KP9 },
|
||||
{ XK_0, SDLK_0 },
|
||||
{ XK_1, SDLK_1 },
|
||||
{ XK_2, SDLK_2 },
|
||||
{ XK_3, SDLK_3 },
|
||||
{ XK_4, SDLK_4 },
|
||||
{ XK_5, SDLK_5 },
|
||||
{ XK_6, SDLK_6 },
|
||||
{ XK_7, SDLK_7 },
|
||||
{ XK_8, SDLK_8 },
|
||||
{ XK_9, SDLK_9 },
|
||||
{ XK_F1, SDLK_F1 },
|
||||
{ XK_F2, SDLK_F2 },
|
||||
{ XK_F3, SDLK_F3 },
|
||||
{ XK_F4, SDLK_F4 },
|
||||
{ XK_F5, SDLK_F5 },
|
||||
{ XK_F6, SDLK_F6 },
|
||||
{ XK_F7, SDLK_F7 },
|
||||
{ XK_F8, SDLK_F8 },
|
||||
{ XK_F9, SDLK_F9 },
|
||||
{ XK_F10, SDLK_F10 },
|
||||
{ XK_F11, SDLK_F11 },
|
||||
{ XK_F12, SDLK_F12 },
|
||||
{ XK_a, SDLK_a },
|
||||
{ XK_b, SDLK_b },
|
||||
{ XK_c, SDLK_c },
|
||||
{ XK_d, SDLK_d },
|
||||
{ XK_e, SDLK_e },
|
||||
{ XK_f, SDLK_f },
|
||||
{ XK_g, SDLK_g },
|
||||
{ XK_h, SDLK_h },
|
||||
{ XK_i, SDLK_i },
|
||||
{ XK_j, SDLK_j },
|
||||
{ XK_k, SDLK_k },
|
||||
{ XK_l, SDLK_l },
|
||||
{ XK_m, SDLK_m },
|
||||
{ XK_n, SDLK_n },
|
||||
{ XK_o, SDLK_o },
|
||||
{ XK_p, SDLK_p },
|
||||
{ XK_q, SDLK_q },
|
||||
{ XK_r, SDLK_r },
|
||||
{ XK_s, SDLK_s },
|
||||
{ XK_t, SDLK_t },
|
||||
{ XK_u, SDLK_u },
|
||||
{ XK_v, SDLK_v },
|
||||
{ XK_w, SDLK_w },
|
||||
{ XK_x, SDLK_x },
|
||||
{ XK_y, SDLK_y },
|
||||
{ XK_z, SDLK_z },
|
||||
{ XK_Left, SK_LEFT },
|
||||
{ XK_Right, SK_RIGHT },
|
||||
{ XK_Up, SK_UP },
|
||||
{ XK_Down, SK_DOWN },
|
||||
{ XK_Return, SK_RETURN },
|
||||
{ XK_Tab, SK_TAB },
|
||||
{ XK_Insert, SK_INSERT },
|
||||
{ XK_Delete, SK_DELETE },
|
||||
{ XK_Shift_R, SK_RSHIFT },
|
||||
{ XK_Shift_L, SK_LSHIFT },
|
||||
{ XK_Control_L, SK_LCTRL },
|
||||
{ XK_Alt_L, SK_LALT },
|
||||
{ XK_space, SK_SPACE },
|
||||
{ XK_Escape, SK_ESCAPE },
|
||||
{ XK_BackSpace, SK_BACKSPACE },
|
||||
{ XK_KP_Enter, SK_KP_ENTER },
|
||||
{ XK_KP_Add, SK_KP_PLUS },
|
||||
{ XK_KP_Subtract, SK_KP_MINUS },
|
||||
{ XK_KP_Multiply, SK_KP_MULTIPLY },
|
||||
{ XK_KP_Divide, SK_KP_DIVIDE },
|
||||
{ XK_grave, SK_BACKQUOTE },
|
||||
{ XK_KP_0, SK_KP0 },
|
||||
{ XK_KP_1, SK_KP1 },
|
||||
{ XK_KP_2, SK_KP2 },
|
||||
{ XK_KP_3, SK_KP3 },
|
||||
{ XK_KP_4, SK_KP4 },
|
||||
{ XK_KP_5, SK_KP5 },
|
||||
{ XK_KP_6, SK_KP6 },
|
||||
{ XK_KP_7, SK_KP7 },
|
||||
{ XK_KP_8, SK_KP8 },
|
||||
{ XK_KP_9, SK_KP9 },
|
||||
{ XK_0, SK_0 },
|
||||
{ XK_1, SK_1 },
|
||||
{ XK_2, SK_2 },
|
||||
{ XK_3, SK_3 },
|
||||
{ XK_4, SK_4 },
|
||||
{ XK_5, SK_5 },
|
||||
{ XK_6, SK_6 },
|
||||
{ XK_7, SK_7 },
|
||||
{ XK_8, SK_8 },
|
||||
{ XK_9, SK_9 },
|
||||
{ XK_F1, SK_F1 },
|
||||
{ XK_F2, SK_F2 },
|
||||
{ XK_F3, SK_F3 },
|
||||
{ XK_F4, SK_F4 },
|
||||
{ XK_F5, SK_F5 },
|
||||
{ XK_F6, SK_F6 },
|
||||
{ XK_F7, SK_F7 },
|
||||
{ XK_F8, SK_F8 },
|
||||
{ XK_F9, SK_F9 },
|
||||
{ XK_F10, SK_F10 },
|
||||
{ XK_F11, SK_F11 },
|
||||
{ XK_F12, SK_F12 },
|
||||
{ XK_a, SK_a },
|
||||
{ XK_b, SK_b },
|
||||
{ XK_c, SK_c },
|
||||
{ XK_d, SK_d },
|
||||
{ XK_e, SK_e },
|
||||
{ XK_f, SK_f },
|
||||
{ XK_g, SK_g },
|
||||
{ XK_h, SK_h },
|
||||
{ XK_i, SK_i },
|
||||
{ XK_j, SK_j },
|
||||
{ XK_k, SK_k },
|
||||
{ XK_l, SK_l },
|
||||
{ XK_m, SK_m },
|
||||
{ XK_n, SK_n },
|
||||
{ XK_o, SK_o },
|
||||
{ XK_p, SK_p },
|
||||
{ XK_q, SK_q },
|
||||
{ XK_r, SK_r },
|
||||
{ XK_s, SK_s },
|
||||
{ XK_t, SK_t },
|
||||
{ XK_u, SK_u },
|
||||
{ XK_v, SK_v },
|
||||
{ XK_w, SK_w },
|
||||
{ XK_x, SK_x },
|
||||
{ XK_y, SK_y },
|
||||
{ XK_z, SK_z },
|
||||
};
|
||||
|
||||
static void init_lut(void)
|
||||
{
|
||||
memset(keysym_lut, 0, sizeof(keysym_lut));
|
||||
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
|
||||
keysym_lut[lut_binds[i].sdl] = lut_binds[i].x;
|
||||
keysym_lut[lut_binds[i].sk] = lut_binds[i].x;
|
||||
}
|
||||
|
||||
static void* x_input_init(void)
|
||||
|
||||
@@ -107,18 +107,6 @@ struct bsv_movie
|
||||
#define CRC_INDEX 2
|
||||
#define STATE_SIZE_INDEX 3
|
||||
|
||||
static inline uint8_t is_little_endian(void)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint16_t u16;
|
||||
uint8_t u8[2];
|
||||
} u;
|
||||
|
||||
u.u16 = 1;
|
||||
return u.u8[0];
|
||||
}
|
||||
|
||||
// Convert to big-endian if needed
|
||||
static inline uint32_t swap_if_big32(uint32_t val)
|
||||
{
|
||||
|
||||
@@ -25,10 +25,12 @@
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <ws2tcpip.h>
|
||||
// Woohoo, Winsock has headers from the STONE AGE! :D
|
||||
#define close(x) closesocket(x)
|
||||
@@ -96,10 +98,7 @@ struct netplay
|
||||
void input_poll_net(void)
|
||||
{
|
||||
if (!netplay_should_skip(g_extern.netplay) && netplay_can_poll(g_extern.netplay))
|
||||
{
|
||||
netplay_callbacks(g_extern.netplay)->poll_cb();
|
||||
netplay_poll(g_extern.netplay);
|
||||
}
|
||||
}
|
||||
|
||||
void video_frame_net(const uint16_t *data, unsigned width, unsigned height)
|
||||
@@ -243,7 +242,7 @@ static bool init_socket(netplay_t *handle, const char *server, uint16_t port)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
|
||||
{
|
||||
WSACleanup();
|
||||
return false;
|
||||
@@ -470,7 +469,7 @@ static bool get_self_input_state(netplay_t *handle)
|
||||
if (handle->frame_count > 0) // First frame we always give zero input since relying on input from first frame screws up when we use -F 0.
|
||||
{
|
||||
snes_input_state_t cb = handle->cbs.state_cb;
|
||||
for (int i = 0; i <= 11; i++)
|
||||
for (unsigned i = 0; i <= 11; i++)
|
||||
{
|
||||
int16_t tmp = cb(g_settings.input.netplay_client_swap_input ? 0 : !handle->port, SNES_DEVICE_JOYPAD, 0, i);
|
||||
state |= tmp ? 1 << i : 0;
|
||||
@@ -659,6 +658,8 @@ void netplay_pre_frame(netplay_t *handle)
|
||||
{
|
||||
psnes_serialize(handle->buffer[handle->self_ptr].state, handle->state_size);
|
||||
handle->can_poll = true;
|
||||
|
||||
input_poll_net();
|
||||
}
|
||||
|
||||
// Here we check if we have new input and replay from recorded input.
|
||||
|
||||
@@ -34,7 +34,6 @@ struct snes_callbacks
|
||||
{
|
||||
snes_video_refresh_t frame_cb;
|
||||
snes_audio_sample_t sample_cb;
|
||||
snes_input_poll_t poll_cb;
|
||||
snes_input_state_t state_cb;
|
||||
};
|
||||
|
||||
|
||||
File renamed without changes.
+20
-5
@@ -3,6 +3,15 @@
|
||||
check_switch_c C99 -std=gnu99
|
||||
check_critical C99 "Cannot find C99 compatible compiler."
|
||||
|
||||
# There are still broken 64-bit Linux distros out there. :)
|
||||
if [ -d /usr/lib64 ]; then
|
||||
add_library_dirs /usr/lib64
|
||||
fi
|
||||
|
||||
if [ -d /opt/local/lib ]; then
|
||||
add_library_dirs /opt/local/lib
|
||||
fi
|
||||
|
||||
if [ "$OS" = BSD ]; then
|
||||
DYLIB=-lc
|
||||
else
|
||||
@@ -24,7 +33,7 @@ fi
|
||||
check_lib DYLIB $DYLIB dlopen
|
||||
check_lib NETPLAY -lc socket
|
||||
|
||||
check_lib ALSA -lasound snd_pcm_open
|
||||
check_pkgconf ALSA alsa
|
||||
check_header OSS sys/soundcard.h
|
||||
check_header OSS_BSD soundcard.h
|
||||
check_lib OSS_LIB -lossaudio
|
||||
@@ -42,14 +51,18 @@ else
|
||||
fi
|
||||
|
||||
check_pkgconf RSOUND rsound 1.1
|
||||
check_lib ROAR -lroar roar_vs_new
|
||||
check_pkgconf ROAR libroar
|
||||
check_pkgconf JACK jack 0.120.1
|
||||
check_pkgconf PULSE libpulse
|
||||
|
||||
check_lib COREAUDIO "-framework AudioUnit" AudioUnitInitialize
|
||||
|
||||
check_pkgconf SDL sdl 1.2.10
|
||||
check_critical SDL "Cannot find SDL library."
|
||||
|
||||
check_lib CG -lCg cgCreateContext
|
||||
# On some distros, -lCg doesn't link against -lstdc++ it seems ...
|
||||
check_lib_cxx CG -lCg cgCreateContext
|
||||
|
||||
check_pkgconf XML libxml-2.0
|
||||
check_pkgconf SDL_IMAGE SDL_image
|
||||
|
||||
@@ -67,14 +80,16 @@ check_pkgconf SRC samplerate
|
||||
check_lib DYNAMIC $DYLIB dlopen
|
||||
|
||||
check_pkgconf FREETYPE freetype2
|
||||
check_lib XVIDEO -lXv XvShmCreateImage
|
||||
check_pkgconf XVIDEO xv
|
||||
|
||||
check_lib STRL -lc strlcpy
|
||||
|
||||
check_pkgconf PYTHON python3
|
||||
|
||||
add_define_make OS $OS
|
||||
|
||||
# Creates config.mk and config.h.
|
||||
VARS="ALSA OSS OSS_BSD OSS_LIB AL RSOUND ROAR JACK PULSE SDL DYLIB CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL PYTHON"
|
||||
VARS="ALSA OSS OSS_BSD OSS_LIB AL RSOUND ROAR JACK COREAUDIO PULSE SDL DYLIB CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL PYTHON"
|
||||
create_config_make config.mk $VARS
|
||||
create_config_header config.h $VARS
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
. qb/qb.params.sh
|
||||
|
||||
PACKAGE_NAME=ssnes
|
||||
PACKAGE_VERSION=0.6
|
||||
PACKAGE_VERSION=0.8.2
|
||||
|
||||
# Adds a command line opt to ./configure --help
|
||||
# $1: Variable (HAVE_ALSA, HAVE_OSS, etc)
|
||||
@@ -23,6 +23,7 @@ add_command_line_enable RSOUND "Enable RSound support" auto
|
||||
add_command_line_enable ROAR "Enable RoarAudio support" auto
|
||||
add_command_line_enable AL "Enable OpenAL support" auto
|
||||
add_command_line_enable JACK "Enable JACK support" auto
|
||||
add_command_line_enable COREAUDIO "Enable CoreAudio support" auto
|
||||
add_command_line_enable PULSE "Enable PulseAudio support" auto
|
||||
add_command_line_enable FREETYPE "Enable FreeType support" auto
|
||||
add_command_line_enable XVIDEO "Enable XVideo support" auto
|
||||
|
||||
+13
-12
@@ -1,24 +1,25 @@
|
||||
. qb/conf.comp.sh
|
||||
. qb/config.comp.sh
|
||||
|
||||
TEMP_C=.tmp.c
|
||||
TEMP_CXX=.tmp.cxx
|
||||
TEMP_EXE=.tmp
|
||||
|
||||
echo -n "Checking operating system ... "
|
||||
ECHOBUF="Checking operating system ... "
|
||||
OS="Win32" # whatever ;D
|
||||
unamestr="`uname -a`"
|
||||
if [ ! -z "`echo $unamestr | grep -i Linux`" ]; then
|
||||
if [ ! -z "`echo "$unamestr" | grep -i Linux`" ]; then
|
||||
OS="Linux"
|
||||
elif [ ! -z "`echo $unamestr | grep -i Darwin`" ]; then
|
||||
elif [ ! -z "`echo "$unamestr" | grep -i Darwin`" ]; then
|
||||
OS="Darwin"
|
||||
elif [ ! -z "`echo $unamestr | grep -i BSD`" ]; then
|
||||
elif [ ! -z "`echo "$unamestr" | grep -i BSD`" ]; then
|
||||
OS="BSD"
|
||||
elif [ ! -z "`echo $unamestr | grep -i NT`" ]; then
|
||||
elif [ ! -z "`echo "$unamestr" | grep -i MINGW32`" ]; then
|
||||
OS="MinGW"
|
||||
elif [ ! -z "`echo "$unamestr" | grep -i NT`" ]; then
|
||||
OS="Cygwin"
|
||||
fi
|
||||
|
||||
echo $OS
|
||||
|
||||
echo $ECHOBUF $OS
|
||||
|
||||
# Checking for working C compiler
|
||||
if [ "$USE_LANG_C" = yes ]; then
|
||||
@@ -31,12 +32,12 @@ if [ "$USE_LANG_C" = yes ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "Checking if $CC is a suitable compiler ... "
|
||||
ECHOBUF="Checking if $CC is a suitable compiler ..."
|
||||
answer=no
|
||||
echo "#include <stdio.h>" > $TEMP_C
|
||||
echo "int main(void) { puts(\"Hai world!\"); return 0; }" >> $TEMP_C
|
||||
$CC -o $TEMP_EXE $TEMP_C 2>/dev/null >/dev/null && answer=yes
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_C $TEMP_EXE
|
||||
|
||||
@@ -54,12 +55,12 @@ if [ "$USE_LANG_CXX" = "yes" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -n "Checking if $CXX is a suitable compiler ... "
|
||||
ECHOBUF="Checking if $CXX is a suitable compiler ..."
|
||||
answer=no
|
||||
echo "#include <iostream>" > $TEMP_CXX
|
||||
echo "int main() { std::cout << \"Hai guise\" << std::endl; return 0; }" >> $TEMP_CXX
|
||||
$CXX -o $TEMP_EXE $TEMP_CXX 2>/dev/null >/dev/null && answer=yes
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_CXX $TEMP_EXE
|
||||
|
||||
|
||||
+52
-23
@@ -42,10 +42,10 @@ check_lib()
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
echo -n "Checking existence of $2 ..."
|
||||
ECHOBUF="Checking existence of $2 ..."
|
||||
echo "int main(void) { return 0; }" > $TEMP_C
|
||||
else
|
||||
echo -n "Checking function $3 in $2 ... "
|
||||
ECHOBUF="Checking function $3 in $2 ..."
|
||||
echo "void $3(void); int main(void) { $3(); return 0; }" > $TEMP_C
|
||||
fi
|
||||
|
||||
@@ -56,9 +56,9 @@ check_lib()
|
||||
|
||||
$CC -o $TEMP_EXE $TEMP_C $INCLUDE_DIRS $LIBRARY_DIRS $extralibs $CFLAGS $LDFLAGS $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_C $TEMP_EXE
|
||||
rm -f $TEMP_C $TEMP_EXE
|
||||
if [ "$tmpval" = "yes" ] && [ "$answer" = "no" ]; then
|
||||
echo "Forced to build with library $2, but cannot locate. Exiting ..."
|
||||
exit 1
|
||||
@@ -72,10 +72,10 @@ check_lib_cxx()
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
echo -n "Checking existence of $2 ..."
|
||||
echo "int main(void) { return 0; }" > $TEMP_C
|
||||
ECHOBUF="Checking existence of $2 ..."
|
||||
echo "int main() { return 0; }" > $TEMP_CXX
|
||||
else
|
||||
echo -n "Checking function $3 in $2 ... "
|
||||
ECHOBUF="Checking function $3 in $2 ..."
|
||||
echo "extern \"C\" { void $3(void); } int main() { $3(); }" > $TEMP_CXX
|
||||
fi
|
||||
|
||||
@@ -86,25 +86,55 @@ check_lib_cxx()
|
||||
|
||||
$CXX -o $TEMP_EXE $TEMP_CXX $INCLUDE_DIRS $LIBRARY_DIRS $extralibs $CFLAGS $LDFLAGS $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_CXX $TEMP_EXE
|
||||
rm -f $TEMP_CXX $TEMP_EXE
|
||||
if [ "$tmpval" = "yes" ] && [ "$answer" = "no" ]; then
|
||||
echo "Forced to build with library $2, but cannot locate. Exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_code_c()
|
||||
{
|
||||
tmpval="HAVE_$1"
|
||||
eval tmpval=\$$tmpval
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
ECHOBUF="Checking C code snippet \"$3\" ..."
|
||||
eval HAVE_$1=no
|
||||
answer=no
|
||||
$CC -o $TEMP_EXE $TEMP_C $INCLUDE_DIRS $LIBRARY_DIRS $2 $CFLAGS $LDFLAGS 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $ECHOBUF $answer
|
||||
rm -f $TEMP_C $TEMP_EXE
|
||||
}
|
||||
|
||||
check_code_cxx()
|
||||
{
|
||||
tmpval="HAVE_$1"
|
||||
eval tmpval=\$$tmpval
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
ECHOBUF="Checking C++ code snippet \"$3\" ..."
|
||||
eval HAVE_$1=no
|
||||
answer=no
|
||||
$CXX -o $TEMP_EXE $TEMP_CXX $INCLUDE_DIRS $LIBRARY_DIRS $2 $CXXFLAGS $LDFLAGS 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $ECHOBUF $answer
|
||||
rm -f $TEMP_CXX $TEMP_EXE
|
||||
}
|
||||
|
||||
locate_pkg_conf()
|
||||
{
|
||||
echo -n "Checking for pkg-config ... "
|
||||
ECHOBUF="Checking for pkg-config ... "
|
||||
PKG_CONF_PATH="`which pkg-config | grep ^/ | head -n1`"
|
||||
if [ -z $PKG_CONF_PATH ]; then
|
||||
echo "not found"
|
||||
echo "Cannot locate pkg-config. Exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
echo "$PKG_CONF_PATH"
|
||||
echo $ECHOBUF $PKG_CONF_PATH
|
||||
}
|
||||
|
||||
check_pkgconf()
|
||||
@@ -115,16 +145,16 @@ check_pkgconf()
|
||||
eval tmpval=\$$tmpval
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
echo -n "Checking presence of package $2"
|
||||
ECHOBUF="Checking presence of package $2"
|
||||
eval HAVE_$1=no
|
||||
eval $1_CFLAGS=""
|
||||
eval $1_LIBS=""
|
||||
answer=no
|
||||
minver=0.0
|
||||
[ ! -z $3 ] && minver=$3 && echo -n " with minimum version $minver"
|
||||
echo -n " ... "
|
||||
[ ! -z $3 ] && minver=$3 && ECHOBUF="$ECHOBUF with minimum version $minver"
|
||||
ECHOBUF="$ECHOBUF ... "
|
||||
pkg-config --atleast-version=$minver "$2" && eval HAVE_$1=yes && eval $1_CFLAGS='"`pkg-config $2 --cflags`"' && eval $1_LIBS='"`pkg-config $2 --libs`"' && answer=yes
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
PKG_CONF_USED="$PKG_CONF_USED $1"
|
||||
|
||||
@@ -140,7 +170,7 @@ check_header()
|
||||
eval tmpval=\$$tmpval
|
||||
[ "$tmpval" = "no" ] && return 0
|
||||
|
||||
echo -n "Checking presence of header file $2 ... "
|
||||
ECHOBUF="Checking presence of header file $2 ..."
|
||||
echo "#include<$2>" > $TEMP_C
|
||||
echo "int main(void) { return 0; }" >> $TEMP_C
|
||||
eval HAVE_$1=no
|
||||
@@ -148,7 +178,7 @@ check_header()
|
||||
|
||||
$CC -o $TEMP_EXE $TEMP_C $INCLUDE_DIRS 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_C $TEMP_EXE
|
||||
if [ "$tmpval" = "yes" ] && [ "$answer" = "no" ]; then
|
||||
@@ -159,7 +189,7 @@ check_header()
|
||||
|
||||
check_switch_c()
|
||||
{
|
||||
echo -n "Checking for availability of switch $2 in $CC ... "
|
||||
ECHOBUF="Checking for availability of switch $2 in $CC ..."
|
||||
if [ -z "$CC" ]; then
|
||||
echo "No C compiler, cannot check ..."
|
||||
exit 1
|
||||
@@ -169,14 +199,14 @@ check_switch_c()
|
||||
answer=no
|
||||
$CC -o $TEMP_EXE $TEMP_C $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_C $TEMP_EXE
|
||||
}
|
||||
|
||||
check_switch_cxx()
|
||||
{
|
||||
echo -n "Checking for availability of switch $2 in $CXX ... "
|
||||
ECHOBUF="Checking for availability of switch $2 in $CXX ... "
|
||||
if [ -z "$CXX" ]; then
|
||||
echo "No C++ compiler, cannot check ..."
|
||||
exit 1
|
||||
@@ -186,7 +216,7 @@ check_switch_cxx()
|
||||
answer=no
|
||||
$CXX -o $TEMP_EXE $TEMP_CXX $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
|
||||
echo $answer
|
||||
echo $ECHOBUF $answer
|
||||
|
||||
rm -rf $TEMP_CXX $TEMP_EXE
|
||||
}
|
||||
@@ -216,7 +246,7 @@ create_config_header()
|
||||
|
||||
echo "Creating config header: $outfile"
|
||||
|
||||
name="`echo __$outfile | sed 's|[\./]|_|g' | tr '[a-z]' '[A-Z]'`"
|
||||
name="`echo QB_${outfile}__ | sed 's|[\./]|_|g' | tr '[a-z]' '[A-Z]'`"
|
||||
echo "#ifndef $name" > "$outfile"
|
||||
echo "#define $name" >> "$outfile"
|
||||
echo "" >> "$outfile"
|
||||
@@ -260,7 +290,6 @@ output_define_make()
|
||||
|
||||
create_config_make()
|
||||
{
|
||||
|
||||
outfile="$1"
|
||||
shift
|
||||
|
||||
|
||||
+1
-2
@@ -64,8 +64,7 @@ print_sub_opt()
|
||||
lowertext="`echo $arg1 | tr '[A-Z]' '[a-z]'`"
|
||||
|
||||
if [ "$arg3" = "auto" ]; then
|
||||
echo -n "--enable-$lowertext: "
|
||||
echo $arg2
|
||||
echo "--enable-$lowertext: $arg2"
|
||||
echo "--disable-$lowertext"
|
||||
elif [ "$arg3" = "yes" ]; then
|
||||
echo "--disable-$lowertext: $arg2"
|
||||
|
||||
+36
-22
@@ -5,6 +5,7 @@
|
||||
#include <libavutil/opt.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libswscale/swscale.h>
|
||||
#include <libavutil/avconfig.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@@ -25,6 +26,9 @@ struct video_info
|
||||
uint8_t *outbuf;
|
||||
size_t outbuf_size;
|
||||
|
||||
int fmt;
|
||||
int pix_size;
|
||||
|
||||
AVFormatContext *format;
|
||||
|
||||
struct SwsContext *sws_ctx;
|
||||
@@ -41,8 +45,6 @@ struct audio_info
|
||||
|
||||
void *outbuf;
|
||||
size_t outbuf_size;
|
||||
|
||||
int pix_fmt;
|
||||
} audio;
|
||||
|
||||
struct muxer_info
|
||||
@@ -77,21 +79,20 @@ static bool init_audio(struct audio_info *audio, struct ffemu_params *param)
|
||||
if (!codec)
|
||||
return false;
|
||||
|
||||
audio->codec = avcodec_alloc_context();
|
||||
avcodec_get_context_defaults(audio->codec);
|
||||
audio->codec = avcodec_alloc_context3(codec);
|
||||
|
||||
audio->codec->sample_rate = param->samplerate;
|
||||
audio->codec->time_base = (AVRational) { 1, param->samplerate };
|
||||
audio->codec->channels = param->channels;
|
||||
audio->codec->sample_fmt = AV_SAMPLE_FMT_S16;
|
||||
if (avcodec_open(audio->codec, codec) != 0)
|
||||
if (avcodec_open2(audio->codec, codec, NULL) != 0)
|
||||
return false;
|
||||
|
||||
audio->buffer = av_malloc(audio->codec->frame_size * param->channels * sizeof(int16_t));
|
||||
if (!audio->buffer)
|
||||
return false;
|
||||
|
||||
audio->outbuf_size = 200000;
|
||||
audio->outbuf_size = 2000000;
|
||||
audio->outbuf = av_malloc(audio->outbuf_size);
|
||||
if (!audio->outbuf)
|
||||
return false;
|
||||
@@ -105,18 +106,31 @@ static bool init_video(struct video_info *video, struct ffemu_params *param)
|
||||
if (!codec)
|
||||
return false;
|
||||
|
||||
video->codec = avcodec_alloc_context();
|
||||
#if AV_HAVE_BIGENDIAN
|
||||
video->fmt = PIX_FMT_RGB555BE;
|
||||
#else
|
||||
video->fmt = PIX_FMT_RGB555LE;
|
||||
#endif
|
||||
video->pix_size = sizeof(uint16_t);
|
||||
if (param->rgb32)
|
||||
{
|
||||
video->fmt = PIX_FMT_RGB32;
|
||||
video->pix_size = sizeof(uint32_t);
|
||||
}
|
||||
|
||||
video->codec = avcodec_alloc_context3(codec);
|
||||
video->codec->width = param->out_width;
|
||||
video->codec->height = param->out_height;
|
||||
video->codec->time_base = (AVRational) {param->fps.den, param->fps.num};
|
||||
video->codec->pix_fmt = PIX_FMT_RGB32;
|
||||
video->codec->sample_aspect_ratio = av_d2q(param->aspect_ratio * param->out_height / param->out_width, 255);
|
||||
video->codec->thread_count = 2;
|
||||
|
||||
if (avcodec_open(video->codec, codec) != 0)
|
||||
if (avcodec_open2(video->codec, codec, NULL) != 0)
|
||||
return false;
|
||||
|
||||
// Allocate a big buffer :p ffmpeg API doesn't seem to give us some clues how big this buffer should be.
|
||||
video->outbuf_size = 2000000;
|
||||
video->outbuf_size = 1 << 23;
|
||||
video->outbuf = av_malloc(video->outbuf_size);
|
||||
|
||||
// Just to make sure we can handle the biggest frames. Seemed to crash with just 256 * 224.
|
||||
@@ -133,11 +147,7 @@ static bool init_muxer(ffemu_t *handle)
|
||||
AVFormatContext *ctx = avformat_alloc_context();
|
||||
av_strlcpy(ctx->filename, handle->params.filename, sizeof(ctx->filename));
|
||||
ctx->oformat = av_guess_format(NULL, ctx->filename, NULL);
|
||||
#ifdef AVIO_FLAG_WRITE
|
||||
if (avio_open(&ctx->pb, ctx->filename, AVIO_FLAG_WRITE) < 0)
|
||||
#else
|
||||
if (url_fopen(&ctx->pb, ctx->filename, URL_WRONLY) < 0)
|
||||
#endif
|
||||
{
|
||||
av_free(ctx);
|
||||
return false;
|
||||
@@ -159,7 +169,7 @@ static bool init_muxer(ffemu_t *handle)
|
||||
handle->audio.codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
||||
handle->muxer.astream = stream;
|
||||
|
||||
if (av_write_header(ctx) < 0)
|
||||
if (avformat_write_header(ctx, NULL) < 0)
|
||||
return false;
|
||||
|
||||
handle->muxer.ctx = ctx;
|
||||
@@ -177,7 +187,8 @@ static bool init_thread(ffemu_t *handle)
|
||||
assert(handle->cond = SDL_CreateCond());
|
||||
assert(handle->audio_fifo = fifo_new(32000 * sizeof(int16_t) * handle->params.channels * MAX_FRAMES / 60));
|
||||
assert(handle->attr_fifo = fifo_new(sizeof(struct ffemu_video_data) * MAX_FRAMES));
|
||||
assert(handle->video_fifo = fifo_new(handle->params.fb_width * handle->params.fb_height * sizeof(int16_t) * MAX_FRAMES));
|
||||
assert(handle->video_fifo = fifo_new(handle->params.fb_width * handle->params.fb_height *
|
||||
handle->video.pix_size * MAX_FRAMES));
|
||||
|
||||
handle->alive = true;
|
||||
handle->can_sleep = true;
|
||||
@@ -229,7 +240,6 @@ static void deinit_thread_buf(ffemu_t *handle)
|
||||
|
||||
ffemu_t *ffemu_new(const struct ffemu_params *params)
|
||||
{
|
||||
avcodec_init();
|
||||
av_register_all();
|
||||
|
||||
ffemu_t *handle = calloc(1, sizeof(*handle));
|
||||
@@ -365,18 +375,20 @@ int ffemu_push_audio(ffemu_t *handle, const struct ffemu_audio_data *data)
|
||||
|
||||
static int ffemu_push_video_thread(ffemu_t *handle, const struct ffemu_video_data *data)
|
||||
{
|
||||
handle->video.sws_ctx = sws_getCachedContext(handle->video.sws_ctx, data->width, data->height, PIX_FMT_RGB555LE,
|
||||
handle->video.sws_ctx = sws_getCachedContext(handle->video.sws_ctx, data->width, data->height, handle->video.fmt,
|
||||
handle->params.out_width, handle->params.out_height, PIX_FMT_RGB32, SWS_POINT,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
int linesize = data->pitch;
|
||||
|
||||
sws_scale(handle->video.sws_ctx, (const uint8_t* const*)&data->data, &linesize, 0, handle->params.out_width, handle->video.conv_frame->data, handle->video.conv_frame->linesize);
|
||||
sws_scale(handle->video.sws_ctx, (const uint8_t* const*)&data->data, &linesize, 0,
|
||||
handle->video.codec->height, handle->video.conv_frame->data, handle->video.conv_frame->linesize);
|
||||
|
||||
handle->video.conv_frame->pts = handle->video.frame_cnt;
|
||||
handle->video.conv_frame->display_picture_number = handle->video.frame_cnt;
|
||||
|
||||
int outsize = avcodec_encode_video(handle->video.codec, handle->video.outbuf, handle->video.outbuf_size, handle->video.conv_frame);
|
||||
int outsize = avcodec_encode_video(handle->video.codec, handle->video.outbuf,
|
||||
handle->video.outbuf_size, handle->video.conv_frame);
|
||||
|
||||
if (outsize < 0)
|
||||
return -1;
|
||||
@@ -387,7 +399,8 @@ static int ffemu_push_video_thread(ffemu_t *handle, const struct ffemu_video_dat
|
||||
pkt.data = handle->video.outbuf;
|
||||
pkt.size = outsize;
|
||||
|
||||
pkt.pts = av_rescale_q(handle->video.codec->coded_frame->pts, handle->video.codec->time_base, handle->muxer.vstream->time_base);
|
||||
pkt.pts = av_rescale_q(handle->video.codec->coded_frame->pts, handle->video.codec->time_base,
|
||||
handle->muxer.vstream->time_base);
|
||||
|
||||
if (handle->video.codec->coded_frame->key_frame)
|
||||
pkt.flags |= AV_PKT_FLAG_KEY;
|
||||
@@ -454,7 +467,7 @@ int ffemu_finalize(ffemu_t *handle)
|
||||
deinit_thread(handle);
|
||||
|
||||
// Push out frames still stuck in queue.
|
||||
uint16_t *video_buf = av_malloc(handle->params.fb_width * handle->params.fb_height * sizeof(uint16_t));
|
||||
void *video_buf = av_malloc(2 * handle->params.fb_width * handle->params.fb_height * handle->video.pix_size);
|
||||
if (video_buf)
|
||||
{
|
||||
struct ffemu_video_data attr_buf;
|
||||
@@ -524,7 +537,8 @@ static int SDLCALL ffemu_thread(void *data)
|
||||
{
|
||||
ffemu_t *ff = data;
|
||||
|
||||
uint16_t *video_buf = av_malloc(ff->params.fb_width * ff->params.fb_height * sizeof(uint16_t));
|
||||
// For some reason, FFmpeg has a tendency to crash if we don't overallocate a bit. :s
|
||||
void *video_buf = av_malloc(2 * ff->params.fb_width * ff->params.fb_height * ff->video.pix_size);
|
||||
assert(video_buf);
|
||||
|
||||
size_t audio_buf_size = 128 * ff->params.channels * sizeof(int16_t);
|
||||
|
||||
+3
-27
@@ -8,29 +8,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Available video codecs
|
||||
typedef enum ffemu_video_codec
|
||||
{
|
||||
FFEMU_VIDEO_FFV1,
|
||||
} ffemu_video_codec;
|
||||
|
||||
// Available audio codecs
|
||||
typedef enum ffemu_audio_codec
|
||||
{
|
||||
FFEMU_AUDIO_VORBIS,
|
||||
} ffemu_audio_codec;
|
||||
|
||||
// Available pixel formats
|
||||
typedef enum ffemu_pixel_format
|
||||
{
|
||||
FFEMU_FMT_XBGR1555,
|
||||
} ffemu_pixel_format;
|
||||
|
||||
typedef enum ffemu_rescaler
|
||||
{
|
||||
FFEMU_RESCALER_POINT
|
||||
} ffemu_rescaler;
|
||||
|
||||
struct ffemu_rational
|
||||
{
|
||||
unsigned num;
|
||||
@@ -40,9 +17,6 @@ struct ffemu_rational
|
||||
// Parameters passed to ffemu_new()
|
||||
struct ffemu_params
|
||||
{
|
||||
// Video codec to use. If not recording video, select FFEMU_VIDEO_NONE.
|
||||
ffemu_video_codec vcodec;
|
||||
|
||||
// Desired output resolution.
|
||||
unsigned out_width;
|
||||
unsigned out_height;
|
||||
@@ -68,6 +42,9 @@ struct ffemu_params
|
||||
// Audio channels.
|
||||
unsigned channels;
|
||||
|
||||
// If input is ARGB or XRGB1555.
|
||||
bool rgb32;
|
||||
|
||||
// Audio bits. Sample format is always signed PCM in native byte order.
|
||||
//unsigned bits;
|
||||
|
||||
@@ -107,7 +84,6 @@ int ffemu_push_audio(ffemu_t *handle, const struct ffemu_audio_data *data);
|
||||
int ffemu_finalize(ffemu_t *handle);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+150
-91
@@ -17,9 +17,11 @@
|
||||
|
||||
#include "general.h"
|
||||
#include "conf/config_file.h"
|
||||
#include "input/keysym.h"
|
||||
#include <assert.h>
|
||||
#include "strl.h"
|
||||
#include "config.def.h"
|
||||
#include "file.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@@ -28,6 +30,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
struct settings g_settings;
|
||||
struct global g_extern;
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
static void read_keybinds(config_file_t *conf);
|
||||
@@ -71,12 +74,18 @@ static void set_defaults(void)
|
||||
case AUDIO_ROAR:
|
||||
def_audio = "roar";
|
||||
break;
|
||||
case AUDIO_COREAUDIO:
|
||||
def_audio = "coreaudio";
|
||||
break;
|
||||
case AUDIO_AL:
|
||||
def_audio = "openal";
|
||||
break;
|
||||
case AUDIO_SDL:
|
||||
def_audio = "sdl";
|
||||
break;
|
||||
case AUDIO_DSOUND:
|
||||
def_audio = "dsound";
|
||||
break;
|
||||
case AUDIO_XAUDIO:
|
||||
def_audio = "xaudio";
|
||||
break;
|
||||
@@ -111,10 +120,11 @@ static void set_defaults(void)
|
||||
|
||||
g_settings.video.xscale = xscale;
|
||||
g_settings.video.yscale = yscale;
|
||||
g_settings.video.fullscreen = fullscreen;
|
||||
g_settings.video.fullscreen = g_extern.force_fullscreen ? true : fullscreen;
|
||||
g_settings.video.fullscreen_x = fullscreen_x;
|
||||
g_settings.video.fullscreen_y = fullscreen_y;
|
||||
g_settings.video.force_16bit = force_16bit;
|
||||
g_settings.video.disable_composition = disable_composition;
|
||||
g_settings.video.vsync = vsync;
|
||||
g_settings.video.smooth = video_smooth;
|
||||
g_settings.video.force_aspect = force_aspect;
|
||||
@@ -126,6 +136,10 @@ static void set_defaults(void)
|
||||
g_settings.video.font_size = font_size;
|
||||
g_settings.video.msg_pos_x = message_pos_offset_x;
|
||||
g_settings.video.msg_pos_y = message_pos_offset_y;
|
||||
|
||||
g_settings.video.msg_color_r = ((message_color >> 16) & 0xff) / 255.0f;
|
||||
g_settings.video.msg_color_g = ((message_color >> 8) & 0xff) / 255.0f;
|
||||
g_settings.video.msg_color_b = ((message_color >> 0) & 0xff) / 255.0f;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_XML)
|
||||
@@ -135,6 +149,9 @@ static void set_defaults(void)
|
||||
g_settings.video.second_pass_smooth = second_pass_smooth;
|
||||
#endif
|
||||
|
||||
g_settings.video.hires_record = hires_record;
|
||||
g_settings.video.post_filter_record = post_filter_record;
|
||||
|
||||
g_settings.audio.enable = audio_enable;
|
||||
g_settings.audio.out_rate = out_rate;
|
||||
g_settings.audio.in_rate = in_rate;
|
||||
@@ -154,13 +171,15 @@ static void set_defaults(void)
|
||||
g_settings.pause_nonactive = pause_nonactive;
|
||||
g_settings.autosave_interval = autosave_interval;
|
||||
|
||||
g_settings.block_sram_overwrite = block_sram_overwrite;
|
||||
|
||||
assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1));
|
||||
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_rest));
|
||||
memcpy(g_settings.input.binds[0], snes_keybinds_1, sizeof(snes_keybinds_1));
|
||||
for (unsigned i = 1; i < 5; i++)
|
||||
memcpy(g_settings.input.binds[i], snes_keybinds_rest, sizeof(snes_keybinds_rest));
|
||||
|
||||
g_settings.input.axis_threshold = AXIS_THRESHOLD;
|
||||
g_settings.input.axis_threshold = axis_threshold;
|
||||
g_settings.input.netplay_client_swap_input = netplay_client_swap_input;
|
||||
for (int i = 0; i < MAX_PLAYERS; i++)
|
||||
g_settings.input.joypad_map[i] = i;
|
||||
@@ -173,7 +192,6 @@ static void parse_config_file(void);
|
||||
|
||||
void parse_config(void)
|
||||
{
|
||||
memset(&g_settings, 0, sizeof(struct settings));
|
||||
set_defaults();
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
@@ -193,7 +211,7 @@ static config_file_t *open_default_config_file(void)
|
||||
const char *appdata = getenv("APPDATA");
|
||||
if (appdata)
|
||||
{
|
||||
char conf_path[strlen(appdata) + strlen("/ssnes.cfg ")];
|
||||
char conf_path[MAXPATHLEN];
|
||||
strlcpy(conf_path, appdata, sizeof(conf_path));
|
||||
strlcat(conf_path, "/ssnes.cfg", sizeof(conf_path));
|
||||
conf = config_file_new(conf_path);
|
||||
@@ -203,7 +221,7 @@ static config_file_t *open_default_config_file(void)
|
||||
const char *home = getenv("HOME");
|
||||
if (home)
|
||||
{
|
||||
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
|
||||
char conf_path[MAXPATHLEN];
|
||||
strlcpy(conf_path, home, sizeof(conf_path));
|
||||
strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path));
|
||||
conf = config_file_new(conf_path);
|
||||
@@ -218,14 +236,14 @@ static config_file_t *open_default_config_file(void)
|
||||
const char *home = getenv("HOME");
|
||||
if (xdg)
|
||||
{
|
||||
char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")];
|
||||
char conf_path[MAXPATHLEN];
|
||||
strlcpy(conf_path, xdg, sizeof(conf_path));
|
||||
strlcat(conf_path, "/ssnes/ssnes.cfg", sizeof(conf_path));
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
else if (home)
|
||||
{
|
||||
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
|
||||
char conf_path[MAXPATHLEN];
|
||||
strlcpy(conf_path, home, sizeof(conf_path));
|
||||
strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path));
|
||||
conf = config_file_new(conf_path);
|
||||
@@ -249,13 +267,8 @@ static config_file_t *open_default_config_file(void)
|
||||
#define CONFIG_GET_DOUBLE(var, key) if (config_get_double(conf, key, &tmp_double)) \
|
||||
g_settings.var = tmp_double
|
||||
|
||||
#define CONFIG_GET_STRING(var, key) do { \
|
||||
if (config_get_string(conf, key, &tmp_str)) \
|
||||
{ \
|
||||
strlcpy(g_settings.var, tmp_str, sizeof(g_settings.var)); \
|
||||
free(tmp_str); \
|
||||
} \
|
||||
} while(0)
|
||||
#define CONFIG_GET_STRING(var, key) \
|
||||
config_get_array(conf, key, g_settings.var, sizeof(g_settings.var))
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
static void parse_config_file(void)
|
||||
@@ -283,14 +296,20 @@ static void parse_config_file(void)
|
||||
int tmp_int;
|
||||
double tmp_double;
|
||||
bool tmp_bool;
|
||||
char *tmp_str;
|
||||
char tmp_str[MAXPATHLEN];
|
||||
|
||||
CONFIG_GET_DOUBLE(video.xscale, "video_xscale");
|
||||
CONFIG_GET_DOUBLE(video.yscale, "video_yscale");
|
||||
CONFIG_GET_INT(video.fullscreen_x, "video_fullscreen_x");
|
||||
CONFIG_GET_INT(video.fullscreen_y, "video_fullscreen_y");
|
||||
CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen");
|
||||
|
||||
if (!g_extern.force_fullscreen)
|
||||
{
|
||||
CONFIG_GET_BOOL(video.fullscreen, "video_fullscreen");
|
||||
}
|
||||
|
||||
CONFIG_GET_BOOL(video.force_16bit, "video_force_16bit");
|
||||
CONFIG_GET_BOOL(video.disable_composition, "video_disable_composition");
|
||||
CONFIG_GET_BOOL(video.vsync, "video_vsync");
|
||||
CONFIG_GET_BOOL(video.smooth, "video_smooth");
|
||||
CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect");
|
||||
@@ -310,8 +329,19 @@ static void parse_config_file(void)
|
||||
CONFIG_GET_INT(video.font_size, "video_font_size");
|
||||
CONFIG_GET_DOUBLE(video.msg_pos_x, "video_message_pos_x");
|
||||
CONFIG_GET_DOUBLE(video.msg_pos_y, "video_message_pos_y");
|
||||
|
||||
unsigned msg_color;
|
||||
if (config_get_hex(conf, "video_message_color", &msg_color))
|
||||
{
|
||||
g_settings.video.msg_color_r = ((msg_color >> 16) & 0xff) / 255.0f;
|
||||
g_settings.video.msg_color_g = ((msg_color >> 8) & 0xff) / 255.0f;
|
||||
g_settings.video.msg_color_b = ((msg_color >> 0) & 0xff) / 255.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
CONFIG_GET_BOOL(video.hires_record, "video_hires_record");
|
||||
CONFIG_GET_BOOL(video.post_filter_record, "video_post_filter_record");
|
||||
|
||||
#ifdef HAVE_DYLIB
|
||||
CONFIG_GET_STRING(video.filter_path, "video_filter");
|
||||
CONFIG_GET_STRING(video.external_driver, "video_external_driver");
|
||||
@@ -319,7 +349,7 @@ static void parse_config_file(void)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_XML)
|
||||
if (config_get_string(conf, "video_shader_type", &tmp_str))
|
||||
if (config_get_array(conf, "video_shader_type", tmp_str, sizeof(tmp_str)))
|
||||
{
|
||||
if (strcmp("cg", tmp_str) == 0)
|
||||
g_settings.video.shader_type = SSNES_SHADER_CG;
|
||||
@@ -329,8 +359,6 @@ static void parse_config_file(void)
|
||||
g_settings.video.shader_type = SSNES_SHADER_AUTO;
|
||||
else if (strcmp("none", tmp_str) == 0)
|
||||
g_settings.video.shader_type = SSNES_SHADER_NONE;
|
||||
|
||||
free(tmp_str);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -371,7 +399,13 @@ static void parse_config_file(void)
|
||||
CONFIG_GET_STRING(audio.dsp_plugin, "audio_dsp_plugin");
|
||||
CONFIG_GET_STRING(input.driver, "input_driver");
|
||||
CONFIG_GET_STRING(libsnes, "libsnes_path");
|
||||
|
||||
CONFIG_GET_STRING(screenshot_directory, "screenshot_directory");
|
||||
if (*g_settings.screenshot_directory && !path_is_directory(g_settings.screenshot_directory))
|
||||
{
|
||||
SSNES_WARN("screenshot_directory is not an existing directory, ignoring ...\n");
|
||||
*g_settings.screenshot_directory = '\0';
|
||||
}
|
||||
|
||||
CONFIG_GET_BOOL(rewind_enable, "rewind_enable");
|
||||
|
||||
@@ -384,6 +418,30 @@ static void parse_config_file(void)
|
||||
CONFIG_GET_INT(autosave_interval, "autosave_interval");
|
||||
|
||||
CONFIG_GET_STRING(cheat_database, "cheat_database_path");
|
||||
CONFIG_GET_STRING(cheat_settings_path, "cheat_settings_path");
|
||||
|
||||
CONFIG_GET_BOOL(block_sram_overwrite, "block_sram_overwrite");
|
||||
|
||||
if (!g_extern.has_set_save_path && config_get_array(conf, "savefile_directory", tmp_str, sizeof(tmp_str)))
|
||||
{
|
||||
if (path_is_directory(tmp_str))
|
||||
{
|
||||
strlcpy(g_extern.savefile_name_srm, tmp_str, sizeof(g_extern.savefile_name_srm));
|
||||
fill_pathname_dir(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
|
||||
}
|
||||
else
|
||||
SSNES_WARN("savefile_directory is not a directory, ignoring ...!\n");
|
||||
}
|
||||
if (!g_extern.has_set_state_path && config_get_array(conf, "savestate_directory", tmp_str, sizeof(tmp_str)))
|
||||
{
|
||||
if (path_is_directory(tmp_str))
|
||||
{
|
||||
strlcpy(g_extern.savestate_name, tmp_str, sizeof(g_extern.savestate_name));
|
||||
fill_pathname_dir(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
|
||||
}
|
||||
else
|
||||
SSNES_WARN("savestate_directory is not a directory, ignoring ...\n");
|
||||
}
|
||||
|
||||
read_keybinds(conf);
|
||||
|
||||
@@ -587,70 +645,71 @@ struct key_map
|
||||
|
||||
// Edit: Not portable to different input systems atm. Might move this map into the driver itself or something.
|
||||
// However, this should map nicely over to other systems aswell since the definition are mostly the same anyways.
|
||||
static const struct key_map sdlk_map[] = {
|
||||
{ "left", SDLK_LEFT },
|
||||
{ "right", SDLK_RIGHT },
|
||||
{ "up", SDLK_UP },
|
||||
{ "down", SDLK_DOWN },
|
||||
{ "enter", SDLK_RETURN },
|
||||
{ "kp_enter", SDLK_KP_ENTER },
|
||||
{ "tab", SDLK_TAB },
|
||||
{ "insert", SDLK_INSERT },
|
||||
{ "del", SDLK_DELETE },
|
||||
{ "end", SDLK_END },
|
||||
{ "home", SDLK_HOME },
|
||||
{ "rshift", SDLK_RSHIFT },
|
||||
{ "shift", SDLK_LSHIFT },
|
||||
{ "ctrl", SDLK_LCTRL },
|
||||
{ "alt", SDLK_LALT },
|
||||
{ "space", SDLK_SPACE },
|
||||
{ "escape", SDLK_ESCAPE },
|
||||
{ "add", SDLK_KP_PLUS },
|
||||
{ "subtract", SDLK_KP_MINUS },
|
||||
{ "f1", SDLK_F1 },
|
||||
{ "f2", SDLK_F2 },
|
||||
{ "f3", SDLK_F3 },
|
||||
{ "f4", SDLK_F4 },
|
||||
{ "f5", SDLK_F5 },
|
||||
{ "f6", SDLK_F6 },
|
||||
{ "f7", SDLK_F7 },
|
||||
{ "f8", SDLK_F8 },
|
||||
{ "f9", SDLK_F9 },
|
||||
{ "f10", SDLK_F10 },
|
||||
{ "f11", SDLK_F11 },
|
||||
{ "f12", SDLK_F12 },
|
||||
{ "num0", SDLK_0 },
|
||||
{ "num1", SDLK_1 },
|
||||
{ "num2", SDLK_2 },
|
||||
{ "num3", SDLK_3 },
|
||||
{ "num4", SDLK_4 },
|
||||
{ "num5", SDLK_5 },
|
||||
{ "num6", SDLK_6 },
|
||||
{ "num7", SDLK_7 },
|
||||
{ "num8", SDLK_8 },
|
||||
{ "num9", SDLK_9 },
|
||||
{ "pageup", SDLK_PAGEUP },
|
||||
{ "pagedown", SDLK_PAGEDOWN },
|
||||
{ "keypad0", SDLK_KP0 },
|
||||
{ "keypad1", SDLK_KP1 },
|
||||
{ "keypad2", SDLK_KP2 },
|
||||
{ "keypad3", SDLK_KP3 },
|
||||
{ "keypad4", SDLK_KP4 },
|
||||
{ "keypad5", SDLK_KP5 },
|
||||
{ "keypad6", SDLK_KP6 },
|
||||
{ "keypad7", SDLK_KP7 },
|
||||
{ "keypad8", SDLK_KP8 },
|
||||
{ "keypad9", SDLK_KP9 },
|
||||
{ "period", SDLK_PERIOD },
|
||||
{ "capslock", SDLK_CAPSLOCK },
|
||||
{ "numlock", SDLK_NUMLOCK },
|
||||
{ "backspace", SDLK_BACKSPACE },
|
||||
{ "multiply", SDLK_KP_MULTIPLY },
|
||||
{ "divide", SDLK_KP_DIVIDE },
|
||||
{ "print_screen", SDLK_PRINT },
|
||||
{ "scroll_lock", SDLK_SCROLLOCK },
|
||||
{ "tilde", SDLK_BACKQUOTE },
|
||||
{ "nul", SDLK_UNKNOWN },
|
||||
static const struct key_map sk_map[] = {
|
||||
{ "left", SK_LEFT },
|
||||
{ "right", SK_RIGHT },
|
||||
{ "up", SK_UP },
|
||||
{ "down", SK_DOWN },
|
||||
{ "enter", SK_RETURN },
|
||||
{ "kp_enter", SK_KP_ENTER },
|
||||
{ "tab", SK_TAB },
|
||||
{ "insert", SK_INSERT },
|
||||
{ "del", SK_DELETE },
|
||||
{ "end", SK_END },
|
||||
{ "home", SK_HOME },
|
||||
{ "rshift", SK_RSHIFT },
|
||||
{ "shift", SK_LSHIFT },
|
||||
{ "ctrl", SK_LCTRL },
|
||||
{ "alt", SK_LALT },
|
||||
{ "space", SK_SPACE },
|
||||
{ "escape", SK_ESCAPE },
|
||||
{ "add", SK_KP_PLUS },
|
||||
{ "subtract", SK_KP_MINUS },
|
||||
{ "f1", SK_F1 },
|
||||
{ "f2", SK_F2 },
|
||||
{ "f3", SK_F3 },
|
||||
{ "f4", SK_F4 },
|
||||
{ "f5", SK_F5 },
|
||||
{ "f6", SK_F6 },
|
||||
{ "f7", SK_F7 },
|
||||
{ "f8", SK_F8 },
|
||||
{ "f9", SK_F9 },
|
||||
{ "f10", SK_F10 },
|
||||
{ "f11", SK_F11 },
|
||||
{ "f12", SK_F12 },
|
||||
{ "num0", SK_0 },
|
||||
{ "num1", SK_1 },
|
||||
{ "num2", SK_2 },
|
||||
{ "num3", SK_3 },
|
||||
{ "num4", SK_4 },
|
||||
{ "num5", SK_5 },
|
||||
{ "num6", SK_6 },
|
||||
{ "num7", SK_7 },
|
||||
{ "num8", SK_8 },
|
||||
{ "num9", SK_9 },
|
||||
{ "pageup", SK_PAGEUP },
|
||||
{ "pagedown", SK_PAGEDOWN },
|
||||
{ "keypad0", SK_KP0 },
|
||||
{ "keypad1", SK_KP1 },
|
||||
{ "keypad2", SK_KP2 },
|
||||
{ "keypad3", SK_KP3 },
|
||||
{ "keypad4", SK_KP4 },
|
||||
{ "keypad5", SK_KP5 },
|
||||
{ "keypad6", SK_KP6 },
|
||||
{ "keypad7", SK_KP7 },
|
||||
{ "keypad8", SK_KP8 },
|
||||
{ "keypad9", SK_KP9 },
|
||||
{ "period", SK_PERIOD },
|
||||
{ "capslock", SK_CAPSLOCK },
|
||||
{ "numlock", SK_NUMLOCK },
|
||||
{ "backspace", SK_BACKSPACE },
|
||||
{ "multiply", SK_KP_MULTIPLY },
|
||||
{ "divide", SK_KP_DIVIDE },
|
||||
{ "print_screen", SK_PRINT },
|
||||
{ "scroll_lock", SK_SCROLLOCK },
|
||||
{ "tilde", SK_BACKQUOTE },
|
||||
{ "backquote", SK_BACKQUOTE },
|
||||
{ "nul", SK_UNKNOWN },
|
||||
};
|
||||
|
||||
static struct snes_keybind *find_snes_bind(unsigned port, int id)
|
||||
@@ -665,23 +724,23 @@ static struct snes_keybind *find_snes_bind(unsigned port, int id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int find_sdlk_bind(const char *str)
|
||||
static int find_sk_bind(const char *str)
|
||||
{
|
||||
for (int i = 0; i < sizeof(sdlk_map)/sizeof(struct key_map); i++)
|
||||
for (int i = 0; i < sizeof(sk_map)/sizeof(struct key_map); i++)
|
||||
{
|
||||
if (strcasecmp(sdlk_map[i].str, str) == 0)
|
||||
return sdlk_map[i].key;
|
||||
if (strcasecmp(sk_map[i].str, str) == 0)
|
||||
return sk_map[i].key;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int find_sdlk_key(const char *str)
|
||||
static int find_sk_key(const char *str)
|
||||
{
|
||||
// If the bind is a normal key-press ...
|
||||
if (strlen(str) == 1 && isalpha(*str))
|
||||
return (int)SDLK_a + (tolower(*str) - (int)'a');
|
||||
return (int)SK_a + (tolower(*str) - (int)'a');
|
||||
else // Check if we have a special mapping for it.
|
||||
return find_sdlk_bind(str);
|
||||
return find_sk_bind(str);
|
||||
}
|
||||
|
||||
// Yes, this function needs a good refactor :)
|
||||
@@ -702,7 +761,7 @@ static void read_keybinds(config_file_t *conf)
|
||||
// Check keybind
|
||||
if (bind_maps[j][i].key && config_get_string(conf, bind_maps[j][i].key, &tmp_key))
|
||||
{
|
||||
int key = find_sdlk_key(tmp_key);
|
||||
int key = find_sk_key(tmp_key);
|
||||
|
||||
if (key >= 0)
|
||||
bind->key = key;
|
||||
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/bin/sh
|
||||
###############
|
||||
# Build script which builds and packages SSNES for MinGW 32/64-bit.
|
||||
# Preferably build on Linux with a cross chain ... :D
|
||||
##########
|
||||
|
||||
####
|
||||
## Tweak these to suit your environment.
|
||||
## Not defining the variable will avoid building that target.
|
||||
## Set MINGW32_BASE and/or MINGW64_BASE to set toolchain prefix:
|
||||
## E.g.: i486-mingw32-gcc would get prefix "i486-mingw32".
|
||||
|
||||
BUILD_32BIT=yes
|
||||
BUILD_64BIT=yes
|
||||
BUILD_PHOENIX_GUI=yes
|
||||
|
||||
if [ ! -z "$NOBUILD_32BIT" ]; then
|
||||
BUILD_32BIT=no
|
||||
fi
|
||||
if [ ! -z "$NOBUILD_64BIT" ]; then
|
||||
BUILD_64BIT=no
|
||||
fi
|
||||
if [ ! -z "$NOBUILD_PHOENIX_GUI" ]; then
|
||||
BUILD_PHOENIX_GUI=no
|
||||
fi
|
||||
|
||||
########
|
||||
|
||||
die()
|
||||
{
|
||||
echo "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
message()
|
||||
{
|
||||
echo ""
|
||||
echo "================================"
|
||||
echo "$@"
|
||||
echo "================================"
|
||||
echo ""
|
||||
}
|
||||
|
||||
if [ ! -f "`which zip`" ]; then
|
||||
echo "Cannot find 'zip'. Cannot package, quitting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "`which unzip`" ]; then
|
||||
echo "Cannot find 'unzip'. Cannot unpack, quitting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "`which wget`" ]; then
|
||||
echo "Cannot find 'wget'. Cannot unpack, quitting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
do_phoenix_build()
|
||||
{
|
||||
message "Build Phoenix GUI"
|
||||
### Build Phoenix GUI
|
||||
if [ ! -d "Phoenix" ]; then
|
||||
git clone git://github.com/Themaister/SSNES-Phoenix.git Phoenix
|
||||
cd Phoenix
|
||||
else
|
||||
cd Phoenix
|
||||
git pull origin master
|
||||
fi
|
||||
|
||||
make -f Makefile.win32 clean || die "Failed to clean ..."
|
||||
make -f Makefile.win32 CC="$C_COMPILER" CXX="$CXX_COMPILER" WINDRES="$WINDRES" -j4 all || die "Failed to build ..."
|
||||
touch ssnes-phoenix.cfg
|
||||
cp ssnes-phoenix.cfg ssnes-phoenix.exe ../ || die "Failed to copy ..."
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
do_build()
|
||||
{
|
||||
SSNES_DIR="$1"
|
||||
LIBZIPNAME="$2"
|
||||
BUILDTYPE="$3"
|
||||
|
||||
if [ ! -d "$SSNES_DIR" ]; then
|
||||
git clone git://github.com/Themaister/SSNES.git "$SSNES_DIR"
|
||||
cd "$SSNES_DIR"
|
||||
else
|
||||
cd "$SSNES_DIR"
|
||||
git pull origin master
|
||||
fi
|
||||
|
||||
if [ ! -f "$LIBZIPNAME" ]; then
|
||||
make -f Makefile.win libs_${BUILDTYPE} || die "Failed to extract"
|
||||
fi
|
||||
|
||||
make -f Makefile.win clean || die "Failed to clean ..."
|
||||
make -f Makefile.win CC="$C_COMPILER" CXX="$CXX_COMPILER" -j4 all SLIM=1 || die "Failed to build ..."
|
||||
make -f Makefile.win CC="$C_COMPILER" CXX="$CXX_COMPILER" dist_${BUILDTYPE} SLIM=1 || die "Failed to dist ..."
|
||||
if [ -z "`find . | grep "ssnes-win"`" ]; then
|
||||
die "Did not find build ..."
|
||||
fi
|
||||
|
||||
if [ "$BUILD_PHOENIX_GUI" = "yes" ]; then
|
||||
do_phoenix_build
|
||||
fi
|
||||
|
||||
ZIP_BASE="`find . | grep "ssnes-win" | head -n1`"
|
||||
ZIP_SLIM="`echo $ZIP_BASE | sed -e 's|\.zip|-slim.zip|'`"
|
||||
ZIP_FULL="`echo $ZIP_BASE | sed -e 's|\.zip|-full.zip|'`"
|
||||
|
||||
if [ "$BUILD_PHOENIX_GUI" = "yes" ]; then
|
||||
zip "$ZIP_BASE" ssnes-phoenix.exe ssnes-phoenix.cfg
|
||||
fi
|
||||
mv -v "$ZIP_BASE" "../$ZIP_SLIM" || die "Failed to move final build ..."
|
||||
|
||||
make -f Makefile.win clean || die "Failed to clean ..."
|
||||
make -f Makefile.win CC="$C_COMPILER" CXX="$CXX_COMPILER" -j4 all || die "Failed to build ..."
|
||||
make -f Makefile.win CC="$C_COMPILER" CXX="$CXX_COMPILER" dist_${BUILDTYPE} || die "Failed to dist ..."
|
||||
|
||||
if [ "$BUILD_PHOENIX_GUI" = "yes" ]; then
|
||||
zip "$ZIP_BASE" ssnes-phoenix.exe ssnes-phoenix.cfg
|
||||
fi
|
||||
mv -v "$ZIP_BASE" "../$ZIP_FULL" || die "Failed to move final build ..."
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
if [ "$BUILD_32BIT" = yes ]; then
|
||||
message "Building for 32-bit!"
|
||||
C_COMPILER=${MINGW32_BASE}-gcc
|
||||
CXX_COMPILER=${MINGW32_BASE}-g++
|
||||
WINDRES=${MINGW32_BASE}-windres
|
||||
do_build "SSNES-w32" "SSNES-win32-libs.zip" "x86"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_64BIT" = yes ]; then
|
||||
message "Building for 64-bit!"
|
||||
C_COMPILER=${MINGW64_BASE}-gcc
|
||||
CXX_COMPILER=${MINGW64_BASE}-g++
|
||||
WINDRES=${MINGW64_BASE}-windres
|
||||
do_build "SSNES-w64" "SSNES-win64-libs.zip" "x86_64"
|
||||
fi
|
||||
|
||||
message "Built successfully! :)"
|
||||
|
||||
@@ -49,15 +49,9 @@
|
||||
#include "SDL.h"
|
||||
// OSX seems to really need -lSDLmain,
|
||||
// so we include SDL.h here so it can hack our main.
|
||||
// I had issues including this in Win32 for some reason. :)
|
||||
// We want to use -mconsole in Win32, so we need main().
|
||||
#endif
|
||||
|
||||
struct global g_extern = {
|
||||
.video_active = true,
|
||||
.audio_active = true,
|
||||
.game_type = SSNES_CART_NORMAL,
|
||||
};
|
||||
|
||||
// To avoid continous switching if we hold the button down, we require that the button must go from pressed, unpressed back to pressed to be able to toggle between then.
|
||||
static void set_fast_forward_button(bool new_button_state, bool new_hold_button_state)
|
||||
{
|
||||
@@ -96,7 +90,7 @@ static void set_fast_forward_button(bool new_button_state, bool new_hold_button_
|
||||
|
||||
static void take_screenshot(const uint16_t *frame, unsigned width, unsigned height)
|
||||
{
|
||||
if (!*(g_settings.screenshot_directory))
|
||||
if (!(*g_settings.screenshot_directory))
|
||||
return;
|
||||
|
||||
bool ret = screenshot_dump(g_settings.screenshot_directory, frame,
|
||||
@@ -142,14 +136,16 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
|
||||
if (g_extern.do_screenshot)
|
||||
take_screenshot(data, width, height);
|
||||
|
||||
// Slightly messy code,
|
||||
// but we really need to do processing before blocking on VSync for best possible scheduling.
|
||||
#ifdef HAVE_FFMPEG
|
||||
if (g_extern.recording)
|
||||
if (g_extern.recording && (!g_extern.filter.active || !g_settings.video.post_filter_record))
|
||||
{
|
||||
struct ffemu_video_data ffemu_data = {
|
||||
.data = data,
|
||||
.pitch = height == 448 || height == 478 ? 1024 : 2048,
|
||||
.width = width,
|
||||
.height = height
|
||||
.height = height,
|
||||
};
|
||||
ffemu_push_video(g_extern.rec, &ffemu_data);
|
||||
}
|
||||
@@ -165,6 +161,20 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height)
|
||||
g_extern.filter.psize(&owidth, &oheight);
|
||||
g_extern.filter.prender(g_extern.filter.colormap, g_extern.filter.buffer,
|
||||
g_extern.filter.pitch, data, (height == 448 || height == 478) ? 1024 : 2048, width, height);
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
if (g_extern.recording && g_settings.video.post_filter_record)
|
||||
{
|
||||
struct ffemu_video_data ffemu_data = {
|
||||
.data = g_extern.filter.buffer,
|
||||
.pitch = g_extern.filter.pitch,
|
||||
.width = owidth,
|
||||
.height = oheight,
|
||||
};
|
||||
ffemu_push_video(g_extern.rec, &ffemu_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!driver.video->frame(driver.video_data, g_extern.filter.buffer, owidth, oheight, g_extern.filter.pitch, msg))
|
||||
g_extern.video_active = false;
|
||||
}
|
||||
@@ -313,26 +323,8 @@ static int16_t input_state(bool port, unsigned device, unsigned index, unsigned
|
||||
return res;
|
||||
}
|
||||
|
||||
static void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size)
|
||||
{
|
||||
char tmp_path[strlen(in_path) + 1];
|
||||
strlcpy(tmp_path, in_path, sizeof(tmp_path));
|
||||
char *tok = NULL;
|
||||
tok = strrchr(tmp_path, '.');
|
||||
if (tok != NULL)
|
||||
*tok = '\0';
|
||||
assert(strlcpy(out_path, tmp_path, size) < size);
|
||||
assert(strlcat(out_path, replace, size) < size);
|
||||
}
|
||||
|
||||
static void fill_pathname_noext(char *out_path, const char *in_path, const char *replace, size_t size)
|
||||
{
|
||||
assert(strlcpy(out_path, in_path, size) < size);
|
||||
assert(strlcat(out_path, replace, size) < size);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SSNES_DEFAULT_CONF_PATH_STR "\n\tDefaults to ssnes.cfg in same directory as ssnes.exe."
|
||||
#define SSNES_DEFAULT_CONF_PATH_STR "\n\t\tDefaults to ssnes.cfg in same directory as ssnes.exe."
|
||||
#elif defined(__APPLE__)
|
||||
#define SSNES_DEFAULT_CONF_PATH_STR " Defaults to $HOME/.ssnes.cfg."
|
||||
#else
|
||||
@@ -340,7 +332,7 @@ static void fill_pathname_noext(char *out_path, const char *in_path, const char
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PACKAGE_VERSION "0.6"
|
||||
#define PACKAGE_VERSION "0.8.2"
|
||||
#endif
|
||||
|
||||
#include "config.features.h"
|
||||
@@ -351,6 +343,7 @@ static void print_features(void)
|
||||
puts("");
|
||||
puts("Features:");
|
||||
_PSUPP(sdl, "SDL", "SDL drivers");
|
||||
_PSUPP(xvideo, "XVideo", "XVideo output");
|
||||
_PSUPP(alsa, "ALSA", "audio driver");
|
||||
_PSUPP(oss, "OSS", "audio driver");
|
||||
_PSUPP(jack, "Jack", "audio driver");
|
||||
@@ -382,6 +375,7 @@ static void print_help(void)
|
||||
puts("Usage: ssnes [rom file] [options...]");
|
||||
puts("\t-h/--help: Show this help message.");
|
||||
puts("\t-s/--save: Path for save file (*.srm). Required when rom is input from stdin.");
|
||||
puts("\t-f/--fullscreen: Start SSNES in fullscreen regardless of config settings.");
|
||||
puts("\t-S/--savestate: Path to use for save states. If not selected, *.state will be assumed.");
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
puts("\t-c/--config: Path for config file." SSNES_DEFAULT_CONF_PATH_STR);
|
||||
@@ -407,10 +401,12 @@ static void print_help(void)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
puts("\t-r/--record: Path to record video file. Settings for video/audio codecs are found in config file.");
|
||||
puts("\t-r/--record: Path to record video file.\n\t\tUsing .mkv extension is recommended, and codecs used are FFV1/FLAC.");
|
||||
#endif
|
||||
puts("\t-v/--verbose: Verbose logging.");
|
||||
puts("\t-U/--ups: Specifies path for UPS patch that will be applied to ROM.");
|
||||
puts("\t--bps: Specifies path for BPS patch that will be applied to ROM.");
|
||||
puts("\t-X/--xml: Specifies path to XML memory map.");
|
||||
puts("\t-D/--detach: Detach SSNES from the running console. Not relevant for all platforms.\n");
|
||||
|
||||
print_features();
|
||||
@@ -418,12 +414,84 @@ static void print_help(void)
|
||||
|
||||
static void set_basename(const char *path)
|
||||
{
|
||||
char tmp[strlen(path) + 1];
|
||||
strlcpy(tmp, path, sizeof(tmp));
|
||||
char *dst = strrchr(tmp, '.');
|
||||
strlcpy(g_extern.basename, path, sizeof(g_extern.basename));
|
||||
char *dst = strrchr(g_extern.basename, '.');
|
||||
if (dst)
|
||||
*dst = '\0';
|
||||
strlcpy(g_extern.basename, tmp, sizeof(g_extern.basename));
|
||||
}
|
||||
|
||||
static void set_paths(const char *path)
|
||||
{
|
||||
set_basename(path);
|
||||
|
||||
SSNES_LOG("Opening file: \"%s\"\n", path);
|
||||
g_extern.rom_file = fopen(path, "rb");
|
||||
if (g_extern.rom_file == NULL)
|
||||
{
|
||||
SSNES_ERR("Could not open file: \"%s\"\n", path);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!g_extern.has_set_save_path)
|
||||
fill_pathname_noext(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
|
||||
if (!g_extern.has_set_state_path)
|
||||
fill_pathname_noext(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
|
||||
|
||||
if (path_is_directory(g_extern.savefile_name_srm))
|
||||
{
|
||||
fill_pathname_dir(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
|
||||
SSNES_LOG("Redirecting save file to \"%s\".\n", g_extern.savefile_name_srm);
|
||||
}
|
||||
if (path_is_directory(g_extern.savestate_name))
|
||||
{
|
||||
fill_pathname_dir(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
|
||||
SSNES_LOG("Redirecting save state to \"%s\".\n", g_extern.savestate_name);
|
||||
}
|
||||
if (*g_extern.config_path && path_is_directory(g_extern.config_path))
|
||||
{
|
||||
fill_pathname_dir(g_extern.config_path, g_extern.basename, ".cfg", sizeof(g_extern.config_path));
|
||||
SSNES_LOG("Redirecting config file to \"%s\".\n", g_extern.config_path);
|
||||
if (!path_file_exists(g_extern.config_path))
|
||||
{
|
||||
*g_extern.config_path = '\0';
|
||||
SSNES_LOG("Did not find config file. Using system default.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void verify_stdin_paths(void)
|
||||
{
|
||||
if (strlen(g_extern.savefile_name_srm) == 0)
|
||||
{
|
||||
SSNES_ERR("Need savefile path argument (--save) when reading rom from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
else if (strlen(g_extern.savestate_name) == 0)
|
||||
{
|
||||
SSNES_ERR("Need savestate path argument (--savestate) when reading rom from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (path_is_directory(g_extern.savefile_name_srm))
|
||||
{
|
||||
SSNES_ERR("Cannot specify directory for path argument (--save) when reading from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
else if (path_is_directory(g_extern.savestate_name))
|
||||
{
|
||||
SSNES_ERR("Cannot specify directory for path argument (--savestate) when reading from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
else if (path_is_directory(g_extern.config_path))
|
||||
{
|
||||
SSNES_ERR("Cannot specify directory for config file (--config) when reading from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_input(int argc, char *argv[])
|
||||
@@ -439,6 +507,7 @@ static void parse_input(int argc, char *argv[])
|
||||
struct option opts[] = {
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "save", 1, NULL, 's' },
|
||||
{ "fullscreen", 0, NULL, 'f' },
|
||||
#ifdef HAVE_FFMPEG
|
||||
{ "record", 1, NULL, 'r' },
|
||||
#endif
|
||||
@@ -464,6 +533,8 @@ static void parse_input(int argc, char *argv[])
|
||||
{ "frames", 1, NULL, 'F' },
|
||||
{ "port", 1, &val, 'p' },
|
||||
{ "ups", 1, NULL, 'U' },
|
||||
{ "bps", 1, &val, 'B' },
|
||||
{ "xml", 1, NULL, 'X' },
|
||||
{ "detach", 0, NULL, 'D' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
@@ -482,7 +553,7 @@ static void parse_input(int argc, char *argv[])
|
||||
#define CONFIG_FILE_ARG
|
||||
#endif
|
||||
|
||||
char optstring[] = "hs:vS:m:p4jJg:b:B:Y:Z:P:HC:F:U:DN:" FFMPEG_RECORD_ARG CONFIG_FILE_ARG;
|
||||
char optstring[] = "hs:fvS:m:p4jJg:b:B:Y:Z:P:HC:F:U:DN:X:" FFMPEG_RECORD_ARG CONFIG_FILE_ARG;
|
||||
for(;;)
|
||||
{
|
||||
val = 0;
|
||||
@@ -515,6 +586,10 @@ static void parse_input(int argc, char *argv[])
|
||||
g_extern.has_set_save_path = true;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
g_extern.force_fullscreen = true;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
strlcpy(g_extern.gb_rom_path, optarg, sizeof(g_extern.gb_rom_path));
|
||||
g_extern.game_type = SSNES_CART_SGB;
|
||||
@@ -610,6 +685,11 @@ static void parse_input(int argc, char *argv[])
|
||||
|
||||
case 'U':
|
||||
strlcpy(g_extern.ups_name, optarg, sizeof(g_extern.ups_name));
|
||||
g_extern.ups_pref = true;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
strlcpy(g_extern.xml_name, optarg, sizeof(g_extern.xml_name));
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
@@ -622,7 +702,11 @@ static void parse_input(int argc, char *argv[])
|
||||
switch (val)
|
||||
{
|
||||
case 'p':
|
||||
g_extern.netplay_port = strtol(optarg, NULL, 0);
|
||||
g_extern.netplay_port = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'B':
|
||||
strlcpy(g_extern.bps_name, optarg, sizeof(g_extern.bps_name));
|
||||
g_extern.bps_pref = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -640,34 +724,9 @@ static void parse_input(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
set_basename(argv[optind]);
|
||||
|
||||
SSNES_LOG("Opening file: \"%s\"\n", argv[optind]);
|
||||
g_extern.rom_file = fopen(argv[optind], "rb");
|
||||
if (g_extern.rom_file == NULL)
|
||||
{
|
||||
SSNES_ERR("Could not open file: \"%s\"\n", argv[optind]);
|
||||
exit(1);
|
||||
}
|
||||
// strl* would be nice :D
|
||||
if (!g_extern.has_set_save_path)
|
||||
fill_pathname_noext(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
|
||||
if (!g_extern.has_set_state_path)
|
||||
fill_pathname_noext(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
|
||||
}
|
||||
else if (strlen(g_extern.savefile_name_srm) == 0)
|
||||
{
|
||||
SSNES_ERR("Need savefile path argument (--save) when reading rom from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
else if (strlen(g_extern.savestate_name) == 0)
|
||||
{
|
||||
SSNES_ERR("Need savestate path argument (--savefile) when reading rom from stdin.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
set_paths(argv[optind]);
|
||||
else
|
||||
verify_stdin_paths();
|
||||
}
|
||||
|
||||
// TODO: Add rest of the controllers.
|
||||
@@ -779,9 +838,11 @@ static inline void save_files(void)
|
||||
#ifdef HAVE_FFMPEG
|
||||
static void init_recording(void)
|
||||
{
|
||||
// Hardcode these options at the moment. Should be specificed in the config file later on.
|
||||
if (g_extern.recording)
|
||||
{
|
||||
// Not perfectly SNES accurate, but this can be adjusted later during processing
|
||||
// and playback losslessly, and we please the containers more by
|
||||
// using "sane" values.
|
||||
struct ffemu_rational ntsc_fps = {60000, 1000};
|
||||
struct ffemu_rational pal_fps = {50000, 1000};
|
||||
struct ffemu_params params = {
|
||||
@@ -793,9 +854,29 @@ static void init_recording(void)
|
||||
.samplerate = 32000,
|
||||
.filename = g_extern.record_path,
|
||||
.fps = psnes_get_region() == SNES_REGION_NTSC ? ntsc_fps : pal_fps,
|
||||
.aspect_ratio = 4.0/3
|
||||
.aspect_ratio = 4.0 / 3,
|
||||
.rgb32 = false,
|
||||
};
|
||||
SSNES_LOG("Recording with FFmpeg to %s.\n", g_extern.record_path);
|
||||
|
||||
if (g_settings.video.hires_record)
|
||||
{
|
||||
params.out_width = 512;
|
||||
params.out_height = 448;
|
||||
}
|
||||
|
||||
if (g_settings.video.post_filter_record && g_extern.filter.active)
|
||||
{
|
||||
g_extern.filter.psize(¶ms.out_width, ¶ms.out_height);
|
||||
params.rgb32 = true;
|
||||
|
||||
unsigned max_width = 512;
|
||||
unsigned max_height = 512;
|
||||
g_extern.filter.psize(&max_width, &max_height);
|
||||
params.fb_width = g_extern.filter.pitch >> 2;
|
||||
params.fb_height = next_pow2(max_height);
|
||||
}
|
||||
|
||||
SSNES_LOG("Recording with FFmpeg to %s @ %ux%u. (FB size: %ux%u 32-bit: %s)\n", g_extern.record_path, params.out_width, params.out_height, params.fb_width, params.fb_height, params.rgb32 ? "yes" : "no");
|
||||
g_extern.rec = ffemu_new(¶ms);
|
||||
if (!g_extern.rec)
|
||||
{
|
||||
@@ -898,7 +979,6 @@ static void init_netplay(void)
|
||||
struct snes_callbacks cbs = {
|
||||
.frame_cb = video_frame,
|
||||
.sample_cb = audio_sample,
|
||||
.poll_cb = input_poll,
|
||||
.state_cb = input_state
|
||||
};
|
||||
|
||||
@@ -1027,8 +1107,17 @@ static void fill_pathnames(void)
|
||||
if (!g_extern.bsv_movie_playback)
|
||||
fill_pathname(g_extern.bsv_movie_path, g_extern.savefile_name_srm, "", sizeof(g_extern.bsv_movie_path));
|
||||
|
||||
if (!(*g_extern.ups_name) && *g_extern.basename)
|
||||
fill_pathname_noext(g_extern.ups_name, g_extern.basename, ".ups", sizeof(g_extern.ups_name));
|
||||
if (*g_extern.basename)
|
||||
{
|
||||
if (!(*g_extern.ups_name))
|
||||
fill_pathname_noext(g_extern.ups_name, g_extern.basename, ".ups", sizeof(g_extern.ups_name));
|
||||
|
||||
if (!(*g_extern.bps_name))
|
||||
fill_pathname_noext(g_extern.bps_name, g_extern.basename, ".bps", sizeof(g_extern.bps_name));
|
||||
|
||||
if (!(*g_extern.xml_name))
|
||||
fill_pathname_noext(g_extern.xml_name, g_extern.basename, ".xml", sizeof(g_extern.xml_name));
|
||||
}
|
||||
}
|
||||
|
||||
// Save or load state here.
|
||||
@@ -1038,7 +1127,7 @@ static void check_savestates(void)
|
||||
bool should_savestate = driver.input->key_pressed(driver.input_data, SSNES_SAVE_STATE_KEY);
|
||||
if (should_savestate && !old_should_savestate)
|
||||
{
|
||||
char save_path[strlen(g_extern.savestate_name) * 2];
|
||||
char save_path[MAXPATHLEN];
|
||||
|
||||
if (g_extern.state_slot > 0)
|
||||
snprintf(save_path, sizeof(save_path), "%s%u", g_extern.savestate_name, g_extern.state_slot);
|
||||
@@ -1064,7 +1153,7 @@ static void check_savestates(void)
|
||||
bool should_loadstate = driver.input->key_pressed(driver.input_data, SSNES_LOAD_STATE_KEY);
|
||||
if (!should_savestate && should_loadstate && !old_should_loadstate)
|
||||
{
|
||||
char load_path[strlen(g_extern.savestate_name) * 2];
|
||||
char load_path[MAXPATHLEN];
|
||||
|
||||
if (g_extern.state_slot > 0)
|
||||
snprintf(load_path, sizeof(load_path), "%s%u", g_extern.savestate_name, g_extern.state_slot);
|
||||
@@ -1354,7 +1443,6 @@ static void check_shader_dir(void)
|
||||
|
||||
old_pressed_next = pressed_next;
|
||||
old_pressed_prev = pressed_prev;
|
||||
|
||||
}
|
||||
|
||||
static void check_cheats(void)
|
||||
@@ -1460,16 +1548,27 @@ static void fill_title_buf(void)
|
||||
snprintf(g_extern.title_buf, sizeof(g_extern.title_buf), "SSNES");
|
||||
}
|
||||
|
||||
static void init_state(void)
|
||||
{
|
||||
// Make absolutely sure our big global structs are in-fact zeroed out.
|
||||
memset(&g_extern, 0, sizeof(g_extern));
|
||||
memset(&g_settings, 0, sizeof(g_settings));
|
||||
g_extern.video_active = true;
|
||||
g_extern.audio_active = true;
|
||||
g_extern.game_type = SSNES_CART_NORMAL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
init_state();
|
||||
|
||||
parse_input(argc, argv);
|
||||
parse_config();
|
||||
init_dlsym();
|
||||
fill_title_buf();
|
||||
|
||||
psnes_init();
|
||||
if (strlen(g_extern.basename) > 0)
|
||||
if (*g_extern.basename)
|
||||
psnes_set_cartridge_basename(g_extern.basename);
|
||||
|
||||
SSNES_LOG("Version of libsnes API: %u.%u\n", psnes_library_revision_major(), psnes_library_revision_minor());
|
||||
@@ -1479,10 +1578,6 @@ int main(int argc, char *argv[])
|
||||
if (!init_rom_file(g_extern.game_type))
|
||||
goto error;
|
||||
|
||||
#ifdef HAVE_XML
|
||||
init_cheats();
|
||||
#endif
|
||||
|
||||
init_msg_queue();
|
||||
init_movie();
|
||||
|
||||
@@ -1496,18 +1591,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!g_extern.netplay)
|
||||
init_rewind();
|
||||
|
||||
|
||||
#ifdef HAVE_NETPLAY
|
||||
psnes_set_video_refresh(g_extern.netplay ? video_frame_net : video_frame);
|
||||
psnes_set_audio_sample(g_extern.netplay ? audio_sample_net : audio_sample);
|
||||
psnes_set_input_poll(g_extern.netplay ? input_poll_net : input_poll);
|
||||
psnes_set_input_state(g_extern.netplay ? input_state_net : input_state);
|
||||
#else
|
||||
psnes_set_video_refresh(video_frame);
|
||||
psnes_set_audio_sample(audio_sample);
|
||||
psnes_set_input_poll(input_poll);
|
||||
psnes_set_input_state(input_state);
|
||||
#endif
|
||||
psnes_set_input_poll(input_poll);
|
||||
|
||||
init_controllers();
|
||||
|
||||
@@ -1517,10 +1611,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!g_extern.bsv_movie_playback && !g_extern.netplay_is_client)
|
||||
init_autosave();
|
||||
|
||||
#ifdef HAVE_XML
|
||||
if (!g_extern.netplay && !g_extern.bsv_movie)
|
||||
init_cheats();
|
||||
#endif
|
||||
|
||||
// Main loop
|
||||
for(;;)
|
||||
for (;;)
|
||||
{
|
||||
// DSP plugin GUI events.
|
||||
if (g_extern.audio_data.dsp_handle && g_extern.audio_data.dsp_plugin->events)
|
||||
g_extern.audio_data.dsp_plugin->events(g_extern.audio_data.dsp_handle);
|
||||
|
||||
// Time to drop?
|
||||
if (driver.input->key_pressed(driver.input_data, SSNES_QUIT_KEY) ||
|
||||
!driver.video->alive(driver.video_data) || g_extern.bsv_movie_end)
|
||||
@@ -1607,3 +1710,4 @@ error:
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
##### Config file for SSNES
|
||||
|
||||
# Save all save files (*.srm) to this directory. This includes related files like .bsv, .rtc, .psrm, etc ...
|
||||
# This will be overridden by explicit command line options.
|
||||
# savefile_directory =
|
||||
|
||||
# Save all save states (*.state) to this directory.
|
||||
# This will be overridden by explicit command line options.
|
||||
# savestate_directory =
|
||||
|
||||
## If enabled, load libsnes from a dynamic location.
|
||||
# libsnes_path = "/path/to/libsnes.so"
|
||||
|
||||
@@ -25,6 +33,9 @@
|
||||
# Force 16-bit colors. Apparently some video cards in use today have troubles with 32-bit ...
|
||||
# video_force_16bit = false
|
||||
|
||||
# Forcibly disable composition. Only works in Windows Vista/7 for now.
|
||||
# video_disable_composition = false
|
||||
|
||||
# Video vsync.
|
||||
# video_vsync = true
|
||||
|
||||
@@ -80,7 +91,11 @@
|
||||
# Offset for where messages will be placed on screen. Values are in range 0.0 to 1.0 for both x and y values.
|
||||
# [0.0, 0.0] maps to the lower left corner of the screen.
|
||||
# video_message_pos_x = 0.05
|
||||
# video_message_pox_y = 0.05
|
||||
# video_message_pos_y = 0.05
|
||||
|
||||
# Color for message. The value is treated as a hexadecimal value.
|
||||
# It is a regular RGB hex number, i.e. red is "ff0000".
|
||||
# video_message_color = ffffff
|
||||
|
||||
#### Audio
|
||||
|
||||
@@ -280,6 +295,11 @@
|
||||
# Path to XML cheat database (as used by bSNES).
|
||||
# cheat_database_path =
|
||||
|
||||
# Path to XML cheat config, a file which keeps track of which
|
||||
# cheat settings are used for individual games.
|
||||
# If the file does not exist, it will be created.
|
||||
# cheat_settings_path =
|
||||
|
||||
# Cheats.
|
||||
# input_cheat_index_plus = y
|
||||
# input_cheat_index_minus = t
|
||||
@@ -290,3 +310,13 @@
|
||||
|
||||
# Directory to dump screenshots to.
|
||||
# screenshot_directory =
|
||||
|
||||
# Records video assuming video is hi-res.
|
||||
# video_hires_record = false
|
||||
|
||||
# Records video after CPU video filter.
|
||||
# video_post_filter_record = false
|
||||
|
||||
# Block SRAM from being overwritten when loading save states.
|
||||
# Might potentially lead to buggy games.
|
||||
# block_sram_overwrite = false
|
||||
Reference in new issue
Block a user