mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-08 08:10:30 -10:00
Compare commits
212
Commits
v0.2
...
v0.4-final
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c901df57 | ||
|
|
f2cc19d1a7 | ||
|
|
ad55829890 | ||
|
|
6b8eea6363 | ||
|
|
b2d214ee79 | ||
|
|
f5fb113563 | ||
|
|
844a523706 | ||
|
|
d05379b340 | ||
|
|
006948b973 | ||
|
|
e5196026a1 | ||
|
|
66d18e4ad7 | ||
|
|
b539df1ccd | ||
|
|
c0117bfbb6 | ||
|
|
074234f182 | ||
|
|
bab03ba8c5 | ||
|
|
4878a283ed | ||
|
|
d3eed4f8c4 | ||
|
|
647db4d5de | ||
|
|
3455f83fa7 | ||
|
|
f730ba4043 | ||
|
|
caf87b1198 | ||
|
|
1706763a4c | ||
|
|
c1b8cdb35b | ||
|
|
936b7f5395 | ||
|
|
a01e3347f7 | ||
|
|
142411c08c | ||
|
|
29808c4421 | ||
|
|
48dcd174a7 | ||
|
|
6c85e6e702 | ||
|
|
e484e22e2f | ||
|
|
8ef54de812 | ||
|
|
c1d5a6e140 | ||
|
|
ea153f9df2 | ||
|
|
1ba9854070 | ||
|
|
012e955a05 | ||
|
|
37c0b49a99 | ||
|
|
de30ce9ef5 | ||
|
|
027a21278e | ||
|
|
f77fe62ab0 | ||
|
|
d42c35e1aa | ||
|
|
d5761b6385 | ||
|
|
bb3ab3b49c | ||
|
|
0441725045 | ||
|
|
ac4e6e89a4 | ||
|
|
12d21cf7a6 | ||
|
|
3fda3effda | ||
|
|
7e07b821aa | ||
|
|
e502a8b566 | ||
|
|
ec51ceb010 | ||
|
|
3fa037daee | ||
|
|
46c6955cfe | ||
|
|
252425c35c | ||
|
|
d309d472e1 | ||
|
|
898c4e8c6c | ||
|
|
56ac7b4649 | ||
|
|
9dd05b7101 | ||
|
|
e2daab9ce9 | ||
|
|
ef19ea7a85 | ||
|
|
01cf24f15f | ||
|
|
f870080497 | ||
|
|
c5942ec5a2 | ||
|
|
50d78fb804 | ||
|
|
8053aca3c3 | ||
|
|
0f3171edea | ||
|
|
6b478b9dda | ||
|
|
caaa9cea40 | ||
|
|
ea7f8f5552 | ||
|
|
69caca6017 | ||
|
|
703cfadf63 | ||
|
|
adfd461c3e | ||
|
|
bb79dbaa98 | ||
|
|
394de09907 | ||
|
|
560cafccaf | ||
|
|
0b09032164 | ||
|
|
1ee7162784 | ||
|
|
4949a131f8 | ||
|
|
8b241c3deb | ||
|
|
78c457b996 | ||
|
|
0be1b0b88b | ||
|
|
3ef0276b2a | ||
|
|
42d19f1a35 | ||
|
|
1cf9381cb0 | ||
|
|
f94dc125e5 | ||
|
|
96b978d55a | ||
|
|
ec367d333d | ||
|
|
9535097894 | ||
|
|
b541c27226 | ||
|
|
41b2af66d5 | ||
|
|
84b2b9c7a5 | ||
|
|
52c8d96dca | ||
|
|
8c6519a53b | ||
|
|
336adb9f85 | ||
|
|
7053006e77 | ||
|
|
bbf4804d12 | ||
|
|
7c16424ba3 | ||
|
|
de9dc686ac | ||
|
|
069e9b574f | ||
|
|
d5319a879a | ||
|
|
f64880aee1 | ||
|
|
fed1857918 | ||
|
|
9aeb40155e | ||
|
|
e49aeb1071 | ||
|
|
13f8ec6f3b | ||
|
|
f75c6df270 | ||
|
|
60b0afce95 | ||
|
|
f24653768f | ||
|
|
f135972a6b | ||
|
|
42c68e21a2 | ||
|
|
e8865060ca | ||
|
|
b07827a856 | ||
|
|
0735398e64 | ||
|
|
ec2d10e069 | ||
|
|
4cdb6151e5 | ||
|
|
e482b1bd18 | ||
|
|
9be3c13a07 | ||
|
|
8a4bcacf88 | ||
|
|
6b9b37b528 | ||
|
|
8e87c1ff19 | ||
|
|
aa648c1a49 | ||
|
|
056a590671 | ||
|
|
97f2503794 | ||
|
|
143079efbe | ||
|
|
7bcc173c5f | ||
|
|
0485f783b3 | ||
|
|
f3c07325bd | ||
|
|
e8eabb0102 | ||
|
|
b73f5e77ff | ||
|
|
d07712b308 | ||
|
|
89ba64d27f | ||
|
|
1a6f112d8a | ||
|
|
70e8681487 | ||
|
|
17ae0f72df | ||
|
|
466485e62e | ||
|
|
f6ee0845f2 | ||
|
|
df1eee1a74 | ||
|
|
46b46ba0b1 | ||
|
|
a763848644 | ||
|
|
9ba2d6c9fa | ||
|
|
fd1367e257 | ||
|
|
85dbc05ded | ||
|
|
1eea7786bc | ||
|
|
d039bedad4 | ||
|
|
ad6719426c | ||
|
|
719e4942ce | ||
|
|
ad9a08aea6 | ||
|
|
604fe709d5 | ||
|
|
81e8368099 | ||
|
|
2137ca8e3f | ||
|
|
672824539c | ||
|
|
1915be5aea | ||
|
|
bdea56370d | ||
|
|
e5e0c33ed6 | ||
|
|
d0c10e7523 | ||
|
|
91d2cea259 | ||
|
|
d9e2072733 | ||
|
|
820b124165 | ||
|
|
caf3eb7b05 | ||
|
|
1b5e63f024 | ||
|
|
93202f191c | ||
|
|
3033fb6791 | ||
|
|
87589609bf | ||
|
|
757514242d | ||
|
|
359d228632 | ||
|
|
24dda40863 | ||
|
|
6c0eebd4bf | ||
|
|
31db2a30bb | ||
|
|
5e241d79c8 | ||
|
|
96389ef83b | ||
|
|
af010712f3 | ||
|
|
c2896db558 | ||
|
|
57eebebcdd | ||
|
|
9ad9cbd7de | ||
|
|
1b5adde885 | ||
|
|
ca35dd79d2 | ||
|
|
491f2e3e76 | ||
|
|
b6591e21cd | ||
|
|
67ed89729d | ||
|
|
6033e75dc4 | ||
|
|
5f8993cb83 | ||
|
|
2446300dd9 | ||
|
|
b97c45df78 | ||
|
|
9034e82298 | ||
|
|
ae395f05e1 | ||
|
|
0c1d359091 | ||
|
|
dd8a9c67c9 | ||
|
|
de331bcd9e | ||
|
|
a81d6bc247 | ||
|
|
47d0b12d40 | ||
|
|
849e9aa734 | ||
|
|
351e098da1 | ||
|
|
c5f825eaa5 | ||
|
|
d0a4102efa | ||
|
|
3aa4181380 | ||
|
|
43dc30c3a5 | ||
|
|
98e6613df0 | ||
|
|
3ce07891e4 | ||
|
|
2ff47ab7c4 | ||
|
|
8ba639c7d5 | ||
|
|
e0403e4dae | ||
|
|
7776525c96 | ||
|
|
25fe9b7f58 | ||
|
|
fff7aba8ec | ||
|
|
e83f3ed444 | ||
|
|
334f11d5bc | ||
|
|
5bcde44684 | ||
|
|
2459793f9c | ||
|
|
cadd7b9728 | ||
|
|
644f247026 | ||
|
|
8c1ef3051d | ||
|
|
d296e15f26 | ||
|
|
5a5cd46f9b | ||
|
|
20d9345a4e |
No files matched your search
@@ -1,3 +1,5 @@
|
||||
*.o
|
||||
ssnes
|
||||
/config.h
|
||||
/config.mk
|
||||
/tools/ssnes-joyconfig
|
||||
@@ -2,22 +2,35 @@ include config.mk
|
||||
|
||||
TARGET = ssnes tools/ssnes-joyconfig
|
||||
|
||||
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.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 strl.o
|
||||
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
|
||||
HEADERS = $(wildcard */*.h) $(wildcard *.h)
|
||||
|
||||
LIBS =
|
||||
LIBS = -lm
|
||||
DEFINES = -DHAVE_CONFIG_H
|
||||
|
||||
ifneq ($(findstring Darwin,$(shell uname -a)),)
|
||||
OSX := 1
|
||||
LIBS += -framework AppKit
|
||||
else
|
||||
OSX := 0
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_SRC), 1)
|
||||
LIBS += $(SRC_LIBS)
|
||||
DEFINES += $(SRC_CFLAGS)
|
||||
else
|
||||
OBJ += audio/hermite.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_CONFIGFILE), 1)
|
||||
OBJ += conf/config_file.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_NETPLAY), 1)
|
||||
OBJ += netplay.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_RSOUND), 1)
|
||||
OBJ += audio/rsound.o
|
||||
LIBS += -lrsound
|
||||
@@ -36,17 +49,41 @@ ifeq ($(HAVE_ROAR), 1)
|
||||
endif
|
||||
ifeq ($(HAVE_AL), 1)
|
||||
OBJ += audio/openal.o
|
||||
ifeq ($(OSX),1)
|
||||
LIBS += -framework OpenAL
|
||||
else
|
||||
LIBS += -lopenal
|
||||
endif
|
||||
endif
|
||||
ifeq ($(HAVE_JACK),1)
|
||||
OBJ += audio/jack.o
|
||||
LIBS += -ljack
|
||||
LIBS += $(JACK_LIBS)
|
||||
DEFINES += $(JACK_CFLAGS)
|
||||
endif
|
||||
ifeq ($(HAVE_PULSE), 1)
|
||||
OBJ += audio/pulse.o
|
||||
LIBS += $(PULSE_LIBS)
|
||||
DEFINES += $(PULSE_CFLAGS)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_SDL), 1)
|
||||
OBJ += gfx/gl.o input/sdl.o audio/sdl.o audio/buffer.o
|
||||
LIBS += $(SDL_LIBS) -lGL
|
||||
DEFINES += $(SDL_CFLAGS)
|
||||
LIBS += $(SDL_LIBS)
|
||||
ifeq ($(OSX),1)
|
||||
LIBS += -framework OpenGL
|
||||
else
|
||||
LIBS += -lGL
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FBO), 1)
|
||||
DEFINES += -DHAVE_FBO
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_XVIDEO), 1)
|
||||
OBJ += gfx/xvideo.o input/x11_input.o
|
||||
LIBS += -lXv -lX11
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_CG), 1)
|
||||
@@ -61,11 +98,7 @@ ifeq ($(HAVE_XML), 1)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FILTER), 1)
|
||||
OBJ += hqflt/hq.o
|
||||
OBJ += hqflt/grayscale.o
|
||||
OBJ += hqflt/bleed.o
|
||||
OBJ += hqflt/ntsc.o
|
||||
OBJ += hqflt/snes_ntsc/snes_ntsc.o
|
||||
LIBS += -ldl
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FREETYPE), 1)
|
||||
@@ -86,11 +119,20 @@ else
|
||||
LIBS += $(libsnes)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_STRL), 1)
|
||||
DEFINES += -DHAVE_STRL
|
||||
endif
|
||||
|
||||
ifneq ($(V),1)
|
||||
Q := @
|
||||
endif
|
||||
|
||||
CFLAGS = -Wall -O3 -g -std=gnu99 -I.
|
||||
CFLAGS += -Wall -O3 -g -I.
|
||||
ifneq ($(findstring icc,$(CC)),)
|
||||
CFLAGS += -std=c99
|
||||
else
|
||||
CFLAGS += -std=gnu99
|
||||
endif
|
||||
|
||||
all: $(TARGET) config.mk
|
||||
|
||||
@@ -116,10 +158,12 @@ install: $(TARGET)
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1
|
||||
install -m755 $(TARGET) $(DESTDIR)$(PREFIX)/bin
|
||||
install -m644 ssnes.cfg $(DESTDIR)/etc/ssnes.cfg
|
||||
install -m644 docs/{ssnes,ssnes-joyconfig}.1 $(DESTDIR)$(PREFIX)/share/man/man1
|
||||
install -m644 docs/ssnes.1 $(DESTDIR)$(PREFIX)/share/man/man1
|
||||
install -m644 docs/ssnes-joyconfig.1 $(DESTDIR)$(PREFIX)/share/man/man1
|
||||
install -m755 ssnes-zip $(DESTDIR)$(PREFIX)/bin
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/{ssnes,ssnes-joyconfig}
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/{ssnes,ssnes-joyconfig,ssnes-zip}
|
||||
rm -f $(DESTDIR)/etc/ssnes.cfg
|
||||
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/{ssnes,ssnes-joyconfig}.1
|
||||
|
||||
|
||||
+36
-4
@@ -1,18 +1,23 @@
|
||||
TARGET = ssnes.exe
|
||||
JTARGET = ssnes-joyconfig.exe
|
||||
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.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 ups.o strl.o
|
||||
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
|
||||
HAVE_SRC = 1
|
||||
HAVE_SRC = 0
|
||||
HAVE_SDL = 1
|
||||
HAVE_XML = 1
|
||||
HAVE_FREETYPE = 1
|
||||
HAVE_XAUDIO = 1
|
||||
HAVE_RSOUND = 1
|
||||
HAVE_FILTER = 1
|
||||
HAVE_NETPLAY = 1
|
||||
HAVE_FBO = 1
|
||||
libsnes ?= -lsnes
|
||||
|
||||
LIBS =
|
||||
LIBS = -lm
|
||||
DEFINES = -I. -DHAVE_CONFIGFILE
|
||||
LDFLAGS = -L. -static-libgcc -s
|
||||
|
||||
@@ -23,6 +28,8 @@ 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)
|
||||
@@ -31,12 +38,33 @@ ifeq ($(HAVE_SDL), 1)
|
||||
DEFINES += $(SDL_CFLAGS) -DHAVE_SDL
|
||||
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
|
||||
DEFINES += $(XML_CFLAGS) -DHAVE_XML
|
||||
LIBS += -lxml2
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FILTER), 1)
|
||||
DEFINES += -DHAVE_FILTER
|
||||
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
|
||||
@@ -49,6 +77,10 @@ else
|
||||
LIBS += $(libsnes)
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_FBO), 1)
|
||||
DEFINES += -DHAVE_FBO
|
||||
endif
|
||||
|
||||
ifneq ($(V),1)
|
||||
Q := @
|
||||
endif
|
||||
@@ -84,7 +116,7 @@ clean:
|
||||
rm -f tools/*.o
|
||||
|
||||
dist: all
|
||||
zip -r ssnes-win32-0.2.zip $(TARGET) ssnes.cfg snes.dll libxml2.dll iconv.dll zlib1.dll SDL.dll libsamplerate-0.dll freetype6.dll $(JTARGET)
|
||||
zip -r ssnes-win32-0.4-beta.zip $(TARGET) ssnes.cfg snes.dll libxml2.dll iconv.dll zlib1.dll SDL.dll freetype6.dll xaudio-c.dll rsound.dll pthreadGC2.dll README.win32.txt $(JTARGET)
|
||||
|
||||
libs:
|
||||
wget https://github.com/downloads/Themaister/SSNES/SSNES-win32-libs.zip --no-check-certificate
|
||||
|
||||
@@ -18,15 +18,15 @@ SSNES requires these libraries to build:
|
||||
|
||||
- [libsnes](http://byuu.org/bsnes/)
|
||||
- SDL
|
||||
- libsamplerate
|
||||
|
||||
SSNES can utilize these libraries if enabled:
|
||||
|
||||
- nvidia-cg-toolkit
|
||||
- libxml2 (bSNES XML shaders)
|
||||
- libfreetype2 (TTF font rendering on screen)
|
||||
- libsamplerate
|
||||
|
||||
SSNES needs one of these audio driver libraries:
|
||||
SSNES needs at least one of these audio driver libraries:
|
||||
|
||||
- ALSA
|
||||
- OSS
|
||||
@@ -35,6 +35,8 @@ SSNES needs one of these audio driver libraries:
|
||||
- OpenAL
|
||||
- JACK
|
||||
- SDL
|
||||
- XAudio2 (Win32)
|
||||
- PulseAudio
|
||||
|
||||
# Building libsnes
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
===================================================
|
||||
SSNES - Simple Super Nintendo Emulator System
|
||||
===================================================
|
||||
|
||||
SSNES is a simplistic emulator frontend designed for use without any GUI.
|
||||
It is used from command line, but is designed to play well with eventual GUI frontends,
|
||||
as the configuration file format is very simple.
|
||||
|
||||
This allows for great portability and focus on what matters in a frontend, such as video and audio performance.
|
||||
Its core libraries for video and input are OpenGL and SDL, with many different audio library supported.
|
||||
|
||||
On first use you should get accustomed to how SSNES works.
|
||||
|
||||
- SSNES emphasizes simplicity. It has no graphical user interface, and is primarily used through the command line.
|
||||
It is recommended for experienced users.
|
||||
It is possible though to create a GUI which can use SSNES.
|
||||
|
||||
- SSNES isn't dependant on any emulator core, such as bSNES, SNES9x or ZSNES.
|
||||
SSNES only talks to the libsnes interface,
|
||||
which was created initially by bSNES but it has an implementation available for SNES9x as well.
|
||||
|
||||
- SSNES is configured through a config file. In the Win32 distribution, there should be a ssnes.cfg included.
|
||||
This config file serves as a base for your custom configuration file.
|
||||
It is recommended that you go through the config file and alter any configurations you might use.
|
||||
This is a good way to learn about the features SSNES have.
|
||||
It is possible to pick which configuration file you want with the '-c' flag.
|
||||
E.g.: ssnes.exe -c myconfig.cfg rom.sfc.
|
||||
|
||||
- When unsure which command line flags to use, use the command: ssnes.exe --help.
|
||||
|
||||
- When something is not working as expected, try using verbose logging first to see what is happening:
|
||||
E.g.: ssnes.exe -v romfile.sfc
|
||||
If something is not working, and you want to file a bug report,
|
||||
please include console output with the -v flag turned on.
|
||||
|
||||
- SSNES does not support zipped roms directly. It only supports roms with extentions .sfc and .smc.
|
||||
However, SSNES can read roms from stdin,
|
||||
which makes it possible to create wrapper programs that can support every zip format under the sun.
|
||||
This can also be performed by a GUI frontend.
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
// Hermite resampler based on bsnes' audio library.
|
||||
|
||||
#include "hermite.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAX_CHANS 8
|
||||
|
||||
struct hermite_resampler
|
||||
{
|
||||
float chan_data[MAX_CHANS][4];
|
||||
double r_frac;
|
||||
unsigned chans;
|
||||
};
|
||||
|
||||
static inline float hermite_kernel(float mu1, float a, float b, float c, float d)
|
||||
{
|
||||
float mu2, mu3, m0, m1, a0, a1, a2, a3;
|
||||
|
||||
mu2 = mu1 * mu1;
|
||||
mu3 = mu2 * mu1;
|
||||
|
||||
m0 = (c - a) * 0.5;
|
||||
m1 = (d - b) * 0.5;
|
||||
|
||||
a0 = +2 * mu3 - 3 * mu2 + 1;
|
||||
a1 = mu3 - 2 * mu2 + mu1;
|
||||
a2 = mu3 - mu2;
|
||||
a3 = -2 * mu3 + 3 * mu2;
|
||||
|
||||
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
|
||||
}
|
||||
|
||||
hermite_resampler_t *hermite_new(unsigned channels)
|
||||
{
|
||||
if (channels > MAX_CHANS)
|
||||
return NULL;
|
||||
|
||||
hermite_resampler_t *re = calloc(1, sizeof(*re));
|
||||
if (!re)
|
||||
return NULL;
|
||||
re->chans = channels;
|
||||
return re;
|
||||
}
|
||||
|
||||
void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
|
||||
{
|
||||
double r_step = 1.0 / data->src_ratio;
|
||||
size_t processed_out = 0;
|
||||
size_t processed_in = 0;
|
||||
|
||||
size_t in_frames = data->input_frames;
|
||||
size_t out_frames = data->output_frames;
|
||||
const float *in_data = data->data_in;
|
||||
float *out_data = data->data_out;
|
||||
|
||||
while (processed_in < in_frames && processed_out < out_frames)
|
||||
{
|
||||
while (re->r_frac <= 1.0 && processed_out < out_frames)
|
||||
{
|
||||
re->r_frac += r_step;
|
||||
for (unsigned i = 0; i < re->chans; i++)
|
||||
{
|
||||
float res = hermite_kernel(re->r_frac,
|
||||
re->chan_data[i][0], re->chan_data[i][1], re->chan_data[i][2], re->chan_data[i][3]);
|
||||
*out_data++ = res;
|
||||
}
|
||||
processed_out++;
|
||||
}
|
||||
|
||||
if (re->r_frac >= 1.0)
|
||||
{
|
||||
re->r_frac -= 1.0;
|
||||
|
||||
for (unsigned i = 0; i < re->chans; i++)
|
||||
{
|
||||
re->chan_data[i][0] = re->chan_data[i][1];
|
||||
re->chan_data[i][1] = re->chan_data[i][2];
|
||||
re->chan_data[i][2] = re->chan_data[i][3];
|
||||
re->chan_data[i][3] = *in_data++;
|
||||
}
|
||||
processed_in++;
|
||||
}
|
||||
}
|
||||
|
||||
data->input_frames_used = processed_in;
|
||||
data->output_frames_gen = processed_out;
|
||||
}
|
||||
|
||||
void hermite_free(hermite_resampler_t *re)
|
||||
{
|
||||
free(re);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
// Hermite resampler based on bsnes' audio library.
|
||||
// Attempts to be similiar to the libsamplerate process interface.
|
||||
|
||||
#ifndef __SSNES_HERMITE_H
|
||||
#define __SSNES_HERMITE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct hermite_resampler hermite_resampler_t;
|
||||
|
||||
hermite_resampler_t *hermite_new(unsigned channels);
|
||||
|
||||
struct hermite_data
|
||||
{
|
||||
const float *data_in;
|
||||
float *data_out;
|
||||
|
||||
size_t input_frames;
|
||||
size_t output_frames;
|
||||
|
||||
size_t input_frames_used;
|
||||
size_t output_frames_gen;
|
||||
|
||||
bool end_of_input; // Just used to clone the SRC API.
|
||||
double src_ratio;
|
||||
};
|
||||
|
||||
void hermite_process(hermite_resampler_t *re, struct hermite_data *data);
|
||||
void hermite_free(hermite_resampler_t *re);
|
||||
|
||||
#endif
|
||||
|
||||
+9
-1
@@ -103,7 +103,15 @@ static size_t find_buffersize(jack_t *jd, int latency)
|
||||
{
|
||||
int frames = latency * g_settings.audio.out_rate / 1000;
|
||||
|
||||
int jack_latency = jack_port_get_total_latency(jd->client, jd->ports[0]);
|
||||
jack_latency_range_t range;
|
||||
int jack_latency = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
jack_port_get_latency_range(jd->ports[i], JackPlaybackLatency, &range);
|
||||
if (range.max > jack_latency)
|
||||
jack_latency = range.max;
|
||||
}
|
||||
|
||||
SSNES_LOG("JACK: Jack latency is %d frames.\n", jack_latency);
|
||||
|
||||
int buffer_frames = frames - jack_latency;
|
||||
|
||||
@@ -17,8 +17,15 @@
|
||||
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
/* 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 "general.h"
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
pa_threaded_mainloop *mainloop;
|
||||
pa_context *context;
|
||||
pa_stream *stream;
|
||||
bool nonblock;
|
||||
} pa_t;
|
||||
|
||||
static void __pulse_free(void *data)
|
||||
{
|
||||
pa_t *pa = data;
|
||||
if (pa)
|
||||
{
|
||||
if (pa->mainloop)
|
||||
pa_threaded_mainloop_stop(pa->mainloop);
|
||||
|
||||
if (pa->stream)
|
||||
{
|
||||
pa_stream_disconnect(pa->stream);
|
||||
pa_stream_unref(pa->stream);
|
||||
}
|
||||
|
||||
if (pa->context)
|
||||
{
|
||||
pa_context_disconnect(pa->context);
|
||||
pa_context_unref(pa->context);
|
||||
}
|
||||
|
||||
if (pa->mainloop)
|
||||
pa_threaded_mainloop_free(pa->mainloop);
|
||||
|
||||
free(pa);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
switch (pa_context_get_state(c))
|
||||
{
|
||||
case PA_CONTEXT_READY:
|
||||
case PA_CONTEXT_TERMINATED:
|
||||
case PA_CONTEXT_FAILED:
|
||||
pa_threaded_mainloop_signal(pa->mainloop, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void stream_state_cb(pa_stream *s, void *data)
|
||||
{
|
||||
pa_t *pa = data;
|
||||
switch (pa_stream_get_state(s)) {
|
||||
case PA_STREAM_READY:
|
||||
case PA_STREAM_FAILED:
|
||||
case PA_STREAM_TERMINATED:
|
||||
pa_threaded_mainloop_signal(pa->mainloop, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void stream_request_cb(pa_stream *s, size_t length, void *data)
|
||||
{
|
||||
(void)length;
|
||||
(void)s;
|
||||
pa_t *pa = data;
|
||||
pa_threaded_mainloop_signal(pa->mainloop, 0);
|
||||
}
|
||||
|
||||
static void stream_latency_update_cb(pa_stream *s, void *data)
|
||||
{
|
||||
(void)s;
|
||||
pa_t *pa = data;
|
||||
pa_threaded_mainloop_signal(pa->mainloop, 0);
|
||||
}
|
||||
|
||||
static void* __pulse_init(const char* device, int rate, int latency)
|
||||
{
|
||||
pa_t *pa = calloc(1, sizeof(*pa));
|
||||
if (!pa)
|
||||
goto error;
|
||||
|
||||
pa->mainloop = pa_threaded_mainloop_new();
|
||||
if (!pa->mainloop)
|
||||
goto error;
|
||||
|
||||
pa->context = pa_context_new(pa_threaded_mainloop_get_api(pa->mainloop), "SSNES");
|
||||
if (!pa->context)
|
||||
goto error;
|
||||
|
||||
pa_context_set_state_callback(pa->context, context_state_cb, pa);
|
||||
|
||||
if (pa_context_connect(pa->context, device, PA_CONTEXT_NOFLAGS, NULL) < 0)
|
||||
goto error;
|
||||
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
if (pa_threaded_mainloop_start(pa->mainloop) < 0)
|
||||
goto error;
|
||||
|
||||
pa_threaded_mainloop_wait(pa->mainloop);
|
||||
|
||||
if (pa_context_get_state(pa->context) != PA_CONTEXT_READY)
|
||||
goto unlock_error;
|
||||
|
||||
pa_sample_spec spec = {
|
||||
.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE,
|
||||
.channels = 2,
|
||||
.rate = rate
|
||||
};
|
||||
|
||||
pa->stream = pa_stream_new(pa->context, "audio", &spec, NULL);
|
||||
if (!pa->stream)
|
||||
goto unlock_error;
|
||||
|
||||
pa_stream_set_state_callback(pa->stream, stream_state_cb, pa);
|
||||
pa_stream_set_write_callback(pa->stream, stream_request_cb, pa);
|
||||
pa_stream_set_latency_update_callback(pa->stream, stream_latency_update_cb, pa);
|
||||
|
||||
pa_buffer_attr buffer_attr = {
|
||||
.maxlength = -1,
|
||||
.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec),
|
||||
.prebuf = -1,
|
||||
.minreq = -1,
|
||||
.fragsize = -1
|
||||
};
|
||||
|
||||
if (pa_stream_connect_playback(pa->stream, NULL, &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0)
|
||||
goto error;
|
||||
|
||||
pa_threaded_mainloop_wait(pa->mainloop);
|
||||
|
||||
if (pa_stream_get_state(pa->stream) != PA_STREAM_READY)
|
||||
goto unlock_error;
|
||||
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
|
||||
return pa;
|
||||
|
||||
unlock_error:
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
error:
|
||||
__pulse_free(pa);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ssize_t __pulse_write(void* data, const void* buf, size_t size)
|
||||
{
|
||||
pa_t *pa = data;
|
||||
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
unsigned length = pa_stream_writable_size(pa->stream);
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
while (length < size)
|
||||
{
|
||||
pa_threaded_mainloop_wait(pa->mainloop);
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
length = pa_stream_writable_size(pa->stream);
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
|
||||
if (pa->nonblock)
|
||||
break;
|
||||
}
|
||||
|
||||
size_t write_size = length < size ? length : size;
|
||||
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
pa_stream_write(pa->stream, buf, write_size, NULL, 0LL, PA_SEEK_RELATIVE);
|
||||
pa_threaded_mainloop_unlock(pa->mainloop);
|
||||
return write_size;
|
||||
}
|
||||
|
||||
static bool __pulse_stop(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool __pulse_start(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __pulse_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
pa_t *pa = data;
|
||||
pa->nonblock = state;
|
||||
}
|
||||
|
||||
static bool __pulse_use_float(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
const audio_driver_t audio_pulse = {
|
||||
.init = __pulse_init,
|
||||
.write = __pulse_write,
|
||||
.stop = __pulse_stop,
|
||||
.start = __pulse_start,
|
||||
.set_nonblock_state = __pulse_set_nonblock_state,
|
||||
.use_float = __pulse_use_float,
|
||||
.free = __pulse_free,
|
||||
.ident = "pulse"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+10
-7
@@ -22,6 +22,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "general.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -37,13 +38,14 @@ static void* __roar_init(const char* device, int rate, int latency)
|
||||
return NULL;
|
||||
|
||||
roar_vs_t *vss;
|
||||
if ( (vss = roar_vs_new_simple(NULL, NULL, rate, 2, ROAR_CODEC_PCM_S_LE, 16, ROAR_DIR_PLAY, &err)) == NULL )
|
||||
if ((vss = roar_vs_new_simple(device, "SSNES", rate, 2, ROAR_CODEC_PCM_S, 16, ROAR_DIR_PLAY, &err)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "roar_vs: \"%s\"\n", roar_vs_strerr(err));
|
||||
SSNES_ERR("RoarAudio: \"%s\"\n", roar_vs_strerr(err));
|
||||
free(roar);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
roar_vs_role(vss, ROAR_ROLE_GAME, NULL);
|
||||
roar->vss = vss;
|
||||
|
||||
return roar;
|
||||
@@ -54,19 +56,20 @@ static ssize_t __roar_write(void* data, const void* buf, size_t size)
|
||||
roar_t *roar = data;
|
||||
ssize_t rc;
|
||||
|
||||
if ( size == 0 )
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
int err;
|
||||
size_t written = 0;
|
||||
while (written < size)
|
||||
{
|
||||
if ((rc = roar_vs_write(roar->vss, (const char*)buf + written, size - written, &err)) < size)
|
||||
size_t write_amt = size - written;
|
||||
if ((rc = roar_vs_write(roar->vss, (const char*)buf + written, write_amt, &err)) < write_amt)
|
||||
{
|
||||
if (rc < 0)
|
||||
if (roar->nonblocking)
|
||||
return rc;
|
||||
else if (rc < 0)
|
||||
return -1;
|
||||
else if (roar->nonblocking)
|
||||
return 0;
|
||||
}
|
||||
written += rc;
|
||||
}
|
||||
|
||||
+77
-30
@@ -19,15 +19,41 @@
|
||||
#include "driver.h"
|
||||
#include <stdlib.h>
|
||||
#include <rsound.h>
|
||||
#include "buffer.h"
|
||||
#include <stdbool.h>
|
||||
#include "SDL.h"
|
||||
|
||||
typedef struct rsd
|
||||
{
|
||||
rsound_t *rd;
|
||||
int latency;
|
||||
int rate;
|
||||
int nonblock;
|
||||
bool nonblock;
|
||||
volatile bool has_error;
|
||||
|
||||
rsound_fifo_buffer_t *buffer;
|
||||
|
||||
SDL_mutex *cond_lock;
|
||||
SDL_cond *cond;
|
||||
} rsd_t;
|
||||
|
||||
static ssize_t audio_cb(void *data, size_t bytes, void *userdata)
|
||||
{
|
||||
rsd_t *rsd = userdata;
|
||||
|
||||
size_t avail = rsnd_fifo_read_avail(rsd->buffer);
|
||||
size_t write_size = bytes > avail ? avail : bytes;
|
||||
rsnd_fifo_read(rsd->buffer, data, write_size);
|
||||
SDL_CondSignal(rsd->cond);
|
||||
|
||||
return write_size;
|
||||
}
|
||||
|
||||
static void err_cb(void *userdata)
|
||||
{
|
||||
rsd_t *rsd = userdata;
|
||||
rsd->has_error = true;
|
||||
SDL_CondSignal(rsd->cond);
|
||||
}
|
||||
|
||||
static void* __rsd_init(const char* device, int rate, int latency)
|
||||
{
|
||||
rsd_t *rsd = calloc(1, sizeof(rsd_t));
|
||||
@@ -42,17 +68,25 @@ static void* __rsd_init(const char* device, int rate, int latency)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rsd->cond_lock = SDL_CreateMutex();
|
||||
rsd->cond = SDL_CreateCond();
|
||||
|
||||
rsd->buffer = rsnd_fifo_new(1024 * 4);
|
||||
|
||||
int channels = 2;
|
||||
int format = RSD_S16_NE;
|
||||
|
||||
rsd_set_param(rd, RSD_CHANNELS, &channels);
|
||||
rsd_set_param(rd, RSD_SAMPLERATE, &rate);
|
||||
rsd_set_param(rd, RSD_LATENCY, &latency);
|
||||
|
||||
if ( device != NULL )
|
||||
rsd_set_param(rd, RSD_HOST, (void*)device);
|
||||
|
||||
rsd_set_param(rd, RSD_FORMAT, &format);
|
||||
|
||||
rsd_set_callback(rd, audio_cb, err_cb, 256, rsd);
|
||||
|
||||
if ( rsd_start(rd) < 0 )
|
||||
{
|
||||
free(rsd);
|
||||
@@ -60,14 +94,7 @@ static void* __rsd_init(const char* device, int rate, int latency)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int min_latency = (rsd_delay_ms(rd) > latency) ? (rsd_delay_ms(rd) * 3 / 2) : latency;
|
||||
|
||||
rsd_set_param(rd, RSD_LATENCY, &min_latency);
|
||||
|
||||
rsd->rd = rd;
|
||||
rsd->latency = min_latency;
|
||||
rsd->rate = rate;
|
||||
|
||||
return rsd;
|
||||
}
|
||||
|
||||
@@ -75,26 +102,46 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
|
||||
{
|
||||
rsd_t *rsd = data;
|
||||
|
||||
if ( (rsd_delay_ms(rsd->rd) > rsd->latency || rsd_get_avail(rsd->rd) < size) && rsd->nonblock )
|
||||
return 0;
|
||||
|
||||
if ( size == 0 )
|
||||
return 0;
|
||||
|
||||
rsd_delay_wait(rsd->rd);
|
||||
if ( rsd_write(rsd->rd, buf, size) == 0 )
|
||||
if (rsd->has_error)
|
||||
return -1;
|
||||
|
||||
if ( rsd_delay_ms(rsd->rd) < rsd->latency/2 )
|
||||
if (rsd->nonblock)
|
||||
{
|
||||
int ms = rsd->latency/2;
|
||||
size_t size = (ms * rsd->rate * 4) / 1000;
|
||||
void *temp = calloc(1, size);
|
||||
rsd_write(rsd->rd, temp, size);
|
||||
free(temp);
|
||||
rsd_callback_lock(rsd->rd);
|
||||
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
|
||||
size_t write_amt = avail > size ? size : avail;
|
||||
rsnd_fifo_write(rsd->buffer, buf, write_amt);
|
||||
rsd_callback_unlock(rsd->rd);
|
||||
return write_amt;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t written = 0;
|
||||
while (written < size && !rsd->has_error)
|
||||
{
|
||||
rsd_callback_lock(rsd->rd);
|
||||
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
|
||||
|
||||
return size;
|
||||
if (avail == 0)
|
||||
{
|
||||
rsd_callback_unlock(rsd->rd);
|
||||
if (!rsd->has_error)
|
||||
{
|
||||
SDL_mutexP(rsd->cond_lock);
|
||||
SDL_CondWait(rsd->cond, rsd->cond_lock);
|
||||
SDL_mutexV(rsd->cond_lock);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t write_amt = size - written > avail ? avail : size - written;
|
||||
rsnd_fifo_write(rsd->buffer, (const char*)buf + written, write_amt);
|
||||
rsd_callback_unlock(rsd->rd);
|
||||
written += write_amt;
|
||||
}
|
||||
}
|
||||
return written;
|
||||
}
|
||||
}
|
||||
|
||||
static bool __rsd_stop(void *data)
|
||||
@@ -126,6 +173,11 @@ static void __rsd_free(void *data)
|
||||
|
||||
rsd_stop(rsd->rd);
|
||||
rsd_free(rsd->rd);
|
||||
|
||||
rsnd_fifo_free(rsd->buffer);
|
||||
SDL_DestroyMutex(rsd->cond_lock);
|
||||
SDL_DestroyCond(rsd->cond);
|
||||
|
||||
free(rsd);
|
||||
}
|
||||
|
||||
@@ -138,9 +190,4 @@ const audio_driver_t audio_rsound = {
|
||||
.free = __rsd_free,
|
||||
.ident = "rsound"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-13
@@ -51,19 +51,6 @@ static void sdl_audio_cb(void *data, Uint8 *stream, int len)
|
||||
memset(stream + write_size, 0, len - write_size);
|
||||
}
|
||||
|
||||
// Interesting hack from http://www-graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
static inline uint32_t next_pow2(uint32_t v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline int find_num_frames(int rate, int latency)
|
||||
{
|
||||
int frames = (rate * latency) / 1000;
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/* 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 "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, int rate, int latency)
|
||||
{
|
||||
if (!init_lib())
|
||||
return NULL;
|
||||
|
||||
xa_t *xa = calloc(1, sizeof(xa_t));
|
||||
if (xa == NULL)
|
||||
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);
|
||||
if (!xa->xa)
|
||||
{
|
||||
SSNES_ERR("Failed to init XAudio2.\n");
|
||||
free(xa);
|
||||
return NULL;
|
||||
}
|
||||
return xa;
|
||||
}
|
||||
|
||||
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);
|
||||
if (avail < size)
|
||||
size = avail;
|
||||
}
|
||||
return pxawrite(xa->xa, buf, size);
|
||||
}
|
||||
|
||||
static bool __xa_stop(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __xa_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
xa_t *xa = data;
|
||||
xa->nonblock = state;
|
||||
}
|
||||
|
||||
static bool __xa_start(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __xa_free(void *data)
|
||||
{
|
||||
xa_t *xa = data;
|
||||
if (xa && xa->xa)
|
||||
{
|
||||
if (pxafree)
|
||||
pxafree(xa->xa);
|
||||
free(xa);
|
||||
}
|
||||
deinit_lib();
|
||||
}
|
||||
|
||||
const audio_driver_t audio_xa = {
|
||||
.init = __xa_init,
|
||||
.write = __xa_write,
|
||||
.stop = __xa_stop,
|
||||
.start = __xa_start,
|
||||
.set_nonblock_state = __xa_set_nonblock_state,
|
||||
.free = __xa_free,
|
||||
.ident = "xaudio"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/* 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 "autosave.h"
|
||||
#include "SDL.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "general.h"
|
||||
|
||||
struct autosave
|
||||
{
|
||||
volatile bool quit;
|
||||
SDL_mutex *lock;
|
||||
|
||||
SDL_mutex *cond_lock;
|
||||
SDL_cond *cond;
|
||||
SDL_Thread *thread;
|
||||
|
||||
void *buffer;
|
||||
const void *snes_buffer;
|
||||
const char *path;
|
||||
size_t bufsize;
|
||||
unsigned interval;
|
||||
};
|
||||
|
||||
static int autosave_thread(void *data)
|
||||
{
|
||||
autosave_t *save = data;
|
||||
while (!save->quit)
|
||||
{
|
||||
autosave_lock(save);
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
SDL_mutexP(save->cond_lock);
|
||||
if (!save->quit)
|
||||
SDL_CondWaitTimeout(save->cond, save->cond_lock, save->interval * 1000);
|
||||
SDL_mutexV(save->cond_lock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
autosave_t *autosave_new(const char *path, const void *data, size_t size, unsigned interval)
|
||||
{
|
||||
autosave_t *handle = calloc(1, sizeof(*handle));
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
handle->bufsize = size;
|
||||
handle->interval = interval;
|
||||
handle->path = path;
|
||||
handle->buffer = malloc(size);
|
||||
handle->snes_buffer = data;
|
||||
|
||||
if (!handle->buffer)
|
||||
{
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle->lock = SDL_CreateMutex();
|
||||
handle->cond_lock = SDL_CreateMutex();
|
||||
handle->cond = SDL_CreateCond();
|
||||
|
||||
handle->thread = SDL_CreateThread(autosave_thread, handle);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void autosave_lock(autosave_t *handle)
|
||||
{
|
||||
SDL_mutexP(handle->lock);
|
||||
}
|
||||
|
||||
void autosave_unlock(autosave_t *handle)
|
||||
{
|
||||
SDL_mutexV(handle->lock);
|
||||
}
|
||||
|
||||
void autosave_free(autosave_t *handle)
|
||||
{
|
||||
SDL_mutexP(handle->cond_lock);
|
||||
handle->quit = true;
|
||||
SDL_mutexV(handle->cond_lock);
|
||||
SDL_CondSignal(handle->cond);
|
||||
SDL_WaitThread(handle->thread, NULL);
|
||||
|
||||
SDL_DestroyMutex(handle->lock);
|
||||
SDL_DestroyMutex(handle->cond_lock);
|
||||
SDL_DestroyCond(handle->cond);
|
||||
|
||||
free(handle->buffer);
|
||||
free(handle);
|
||||
}
|
||||
|
||||
void lock_autosave(void)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(g_extern.autosave)/sizeof(g_extern.autosave[0]); i++)
|
||||
{
|
||||
if (g_extern.autosave[i])
|
||||
autosave_lock(g_extern.autosave[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_autosave(void)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(g_extern.autosave)/sizeof(g_extern.autosave[0]); i++)
|
||||
{
|
||||
if (g_extern.autosave[i])
|
||||
autosave_unlock(g_extern.autosave[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/* 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_AUTOSAVE_H
|
||||
#define __SSNES_AUTOSAVE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct autosave autosave_t;
|
||||
|
||||
autosave_t *autosave_new(const char *path, const void *data, size_t size, unsigned interval);
|
||||
void autosave_lock(autosave_t *handle);
|
||||
void autosave_unlock(autosave_t *handle);
|
||||
void autosave_free(autosave_t *handle);
|
||||
|
||||
void lock_autosave(void);
|
||||
void unlock_autosave(void);
|
||||
|
||||
#endif
|
||||
+73
-21
@@ -31,20 +31,19 @@
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
#include <SDL/SDL.h>
|
||||
#include "SDL.h"
|
||||
#else
|
||||
#error HAVE_SDL is not defined!
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
#include <samplerate.h>
|
||||
#else
|
||||
#error HAVE_SRC is not defined!
|
||||
#endif
|
||||
|
||||
|
||||
///////////////// Drivers
|
||||
#define VIDEO_GL 0
|
||||
#define VIDEO_XVIDEO 11
|
||||
////////////////////////
|
||||
#define AUDIO_RSOUND 1
|
||||
#define AUDIO_OSS 2
|
||||
@@ -53,29 +52,46 @@
|
||||
#define AUDIO_AL 5
|
||||
#define AUDIO_JACK 6
|
||||
#define AUDIO_SDL 8
|
||||
#define AUDIO_XAUDIO 9
|
||||
#define AUDIO_PULSE 10
|
||||
////////////////////////
|
||||
#define INPUT_SDL 7
|
||||
#define INPUT_X 12
|
||||
////////////////////////
|
||||
|
||||
#if defined(HAVE_SDL)
|
||||
#define VIDEO_DEFAULT_DRIVER VIDEO_GL
|
||||
|
||||
#if HAVE_ALSA
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_ALSA
|
||||
#elif HAVE_OSS
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_OSS
|
||||
#elif HAVE_JACK
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_JACK
|
||||
#elif HAVE_RSOUND
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_RSOUND
|
||||
#elif HAVE_ROAR
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_ROAR
|
||||
#elif HAVE_AL
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_AL
|
||||
#elif HAVE_SDL
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_SDL
|
||||
#elif defined(HAVE_XVIDEO)
|
||||
#define VIDEO_DEFAULT_DRIVER VIDEO_XVIDEO
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ALSA)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_ALSA
|
||||
#elif defined(HAVE_PULSE)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_PULSE
|
||||
#elif defined(HAVE_OSS)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_OSS
|
||||
#elif defined(HAVE_JACK)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_JACK
|
||||
#elif defined(HAVE_AL)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_AL
|
||||
#elif defined(HAVE_SDL)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_SDL
|
||||
#elif defined(HAVE_XAUDIO)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_XAUDIO
|
||||
#elif defined(HAVE_RSOUND)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_RSOUND
|
||||
#elif defined(HAVE_ROAR)
|
||||
#define AUDIO_DEFAULT_DRIVER AUDIO_ROAR
|
||||
#else
|
||||
#error Need at least one audio driver!
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SDL)
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_SDL
|
||||
#elif defined(HAVE_XVIDEO)
|
||||
#define INPUT_DEFAULT_DRIVER INPUT_X
|
||||
#endif
|
||||
|
||||
|
||||
////////////////
|
||||
@@ -88,8 +104,8 @@ static const float yscale = 3.0; // Real y res = 224 * yscale
|
||||
|
||||
// Fullscreen
|
||||
static const bool fullscreen = false; // To start in Fullscreen or not
|
||||
static const unsigned fullscreen_x = 1280;
|
||||
static const unsigned fullscreen_y = 720;
|
||||
static const unsigned fullscreen_x = 0; // Fullscreen resolution. A value of 0 uses the desktop resolution.
|
||||
static const unsigned fullscreen_y = 0;
|
||||
|
||||
// Video VSYNC (recommended)
|
||||
static const bool vsync = true;
|
||||
@@ -107,6 +123,12 @@ static const unsigned font_size = 48;
|
||||
static const float message_pos_offset_x = 0.05;
|
||||
static const float message_pos_offset_y = 0.05;
|
||||
|
||||
// Render-to-texture before rendering to screen (multi-pass shaders)
|
||||
static const bool render_to_texture = false;
|
||||
static const float fbo_scale_x = 2.0;
|
||||
static const float fbo_scale_y = 2.0;
|
||||
static const bool second_pass_smooth = true;
|
||||
|
||||
#define SNES_ASPECT_RATIO (4.0/3)
|
||||
|
||||
////////////////
|
||||
@@ -121,7 +143,10 @@ static const unsigned out_rate = 48000;
|
||||
|
||||
// Input samplerate from libSNES.
|
||||
// Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled.
|
||||
static const unsigned in_rate = 31980;
|
||||
static const float in_rate = 31980.0;
|
||||
|
||||
// When changing input rate on-the-fly
|
||||
static const float audio_rate_step = 0.25;
|
||||
|
||||
// Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults.
|
||||
static const char* audio_device = NULL;
|
||||
@@ -133,9 +158,28 @@ static const int out_latency = 64;
|
||||
static const bool audio_sync = true;
|
||||
|
||||
// Defines the quality (and cpu reqirements) of samplerate conversion.
|
||||
#ifdef HAVE_SRC
|
||||
#define SAMPLERATE_QUALITY SRC_LINEAR
|
||||
#endif
|
||||
|
||||
// Enables use of rewind. This will incur some memory footprint depending on the save state buffer.
|
||||
// This rewind only works when using bSNES core atm.
|
||||
static const bool rewind_enable = false;
|
||||
|
||||
// The buffer size for the rewind buffer. This needs to be about 15-20MB per minute. Very game dependant.
|
||||
static const unsigned rewind_buffer_size = 20 << 20; // 20MiB
|
||||
|
||||
// How many frames to rewind at a time.
|
||||
static const unsigned rewind_granularity = 1;
|
||||
|
||||
// Pause gameplay when gameplay loses focus.
|
||||
static const bool pause_nonactive = true;
|
||||
|
||||
// Saves non-volatile SRAM at a regular interval. It is measured in seconds. A value of 0 disables autosave.
|
||||
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;
|
||||
|
||||
|
||||
////////////////////
|
||||
@@ -171,6 +215,14 @@ static const struct snes_keybind snes_keybinds_1[] = {
|
||||
{ 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 },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
|
||||
@@ -50,6 +50,18 @@ static const bool _jack_supp = true;
|
||||
static const bool _jack_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PULSE
|
||||
static const bool _pulse_supp = true;
|
||||
#else
|
||||
static const bool _pulse_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XAUDIO
|
||||
static const bool _xaudio_supp = true;
|
||||
#else
|
||||
static const bool _xaudio_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FILTER
|
||||
static const bool _filter_supp = true;
|
||||
#else
|
||||
@@ -68,6 +80,12 @@ static const bool _xml_supp = true;
|
||||
static const bool _xml_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FBO
|
||||
static const bool _fbo_supp = true;
|
||||
#else
|
||||
static const bool _fbo_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
static const bool _dynamic_supp = true;
|
||||
#else
|
||||
@@ -98,4 +116,10 @@ static const bool _freetype_supp = true;
|
||||
static const bool _freetype_supp = false;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETPLAY
|
||||
static const bool _netplay_supp = true;
|
||||
#else
|
||||
static const bool _netplay_supp = false;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -34,6 +34,10 @@ Use config file found in PATH as a base. Old configuration values can be overwri
|
||||
\fB--output PATH, -o PATH\fR
|
||||
Writes the final config to a file, rather than \fBstdout\fR. If -i and -o point to the same file, the file found in PATH will simply be updated with the new configs.
|
||||
|
||||
.TP
|
||||
\fB--misc, -m\fR
|
||||
Also configure some binds that aren't directly related to SNES emulation, such as save states, fullscreen toggling, etc.
|
||||
|
||||
.TP
|
||||
\fB--help, -h\fR
|
||||
Prints help message.
|
||||
|
||||
+28
-1
@@ -47,7 +47,7 @@ Should this not be defined, \fBssnes\fR will look in platform specific paths to
|
||||
/etc/ssnes.cfg (when installed), or ssnes.cfg in the source tarball serves as a skeleton configuration file.
|
||||
|
||||
.IP
|
||||
Unix-like systems will look in $XDG_CONFIG_HOME/ssnes/ssnes.cfg first. Then it will try $HOME/.ssnesrc. 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.
|
||||
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.
|
||||
|
||||
.IP
|
||||
Windows will look in ssnes.cfg in same folder where ssnes.exe resides.
|
||||
@@ -100,9 +100,36 @@ Connects a four-way multitap into port 2 of the SNES. This allows for up to 5 pl
|
||||
\fB--record PATH, -r PATH\fR
|
||||
Activates video recording of gameplay into PATH. Video recording options can be configured in config file.
|
||||
|
||||
.TP
|
||||
\fB--bsvplay PATH, -P PATH\fR
|
||||
Play back a movie recorded in the .bsv format (bSNES). Cart ROM and movie file need to correspond.
|
||||
It also requires to play back with the same libsnes backend that was used for recording.
|
||||
|
||||
.TP
|
||||
\fB--verbose, -v\fR
|
||||
Activates verbose logging.
|
||||
|
||||
.TP
|
||||
\fB--host, -H\fR
|
||||
Be the host of netplay. Waits until a player connects. The host will always assume player 1.
|
||||
|
||||
.TP
|
||||
\fB--connect SERVER, -C SERVER\fR
|
||||
Connect to a host of netplay. Will always assume player 2.
|
||||
|
||||
.TP
|
||||
\fB--frames FRAMES, -F FRAMES\fR
|
||||
Sync frames to use when using netplay. More frames allow for more latency, but requires more CPU power.
|
||||
Set FRAMES to 0 to have perfect sync. 0 frames is only suitable for LAN. Defaults to 0.
|
||||
|
||||
.TP
|
||||
\fB--port PORT\fR
|
||||
Network port used for netplay. This defaults to 55435. This option affects both TCP and UDP.
|
||||
|
||||
.TP
|
||||
\fB--ups PATCH, -U PATCH\fR
|
||||
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.
|
||||
|
||||
.SH "SEE ALSO"
|
||||
\fBssnes-joyconfig\fR(1)
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
#include "file.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "hqflt/filters.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@@ -49,18 +50,30 @@ static const audio_driver_t *audio_drivers[] = {
|
||||
#ifdef HAVE_SDL
|
||||
&audio_sdl,
|
||||
#endif
|
||||
#ifdef HAVE_XAUDIO
|
||||
&audio_xa,
|
||||
#endif
|
||||
#ifdef HAVE_PULSE
|
||||
&audio_pulse,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const video_driver_t *video_drivers[] = {
|
||||
#ifdef HAVE_SDL
|
||||
&video_gl,
|
||||
#endif
|
||||
#ifdef HAVE_XVIDEO
|
||||
&video_xvideo,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const input_driver_t *input_drivers[] = {
|
||||
#ifdef HAVE_SDL
|
||||
&input_sdl,
|
||||
#endif
|
||||
//#ifdef HAVE_XVIDEO
|
||||
// &input_x,
|
||||
//#endif
|
||||
};
|
||||
|
||||
static void find_audio_driver(void)
|
||||
@@ -160,10 +173,16 @@ void init_audio(void)
|
||||
else
|
||||
g_extern.audio_data.chunk_size = g_extern.audio_data.block_chunk_size;
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
int err;
|
||||
g_extern.source = src_new(g_settings.audio.src_quality, 2, &err);
|
||||
if (!g_extern.source)
|
||||
g_extern.audio_data.source = src_new(g_settings.audio.src_quality, 2, &err);
|
||||
if (!g_extern.audio_data.source)
|
||||
g_extern.audio_active = false;
|
||||
#else
|
||||
g_extern.audio_data.source = hermite_new(2);
|
||||
if (!g_extern.audio_data.source)
|
||||
g_extern.audio_active = false;
|
||||
#endif
|
||||
|
||||
size_t max_bufsamples = g_extern.audio_data.block_chunk_size > g_extern.audio_data.nonblock_chunk_size ?
|
||||
g_extern.audio_data.block_chunk_size : g_extern.audio_data.nonblock_chunk_size;
|
||||
@@ -186,36 +205,135 @@ void uninit_audio(void)
|
||||
if ( driver.audio_data && driver.audio )
|
||||
driver.audio->free(driver.audio_data);
|
||||
|
||||
if ( g_extern.source )
|
||||
src_delete(g_extern.source);
|
||||
if ( g_extern.audio_data.source )
|
||||
{
|
||||
#ifdef HAVE_SRC
|
||||
src_delete(g_extern.audio_data.source);
|
||||
#else
|
||||
hermite_free(g_extern.audio_data.source);
|
||||
#endif
|
||||
}
|
||||
|
||||
free(g_extern.audio_data.data); g_extern.audio_data.data = NULL;
|
||||
free(g_extern.audio_data.outsamples); g_extern.audio_data.outsamples = NULL;
|
||||
free(g_extern.audio_data.conv_outsamples); g_extern.audio_data.conv_outsamples = NULL;
|
||||
}
|
||||
|
||||
#ifdef HAVE_FILTER
|
||||
static void init_filter(void)
|
||||
{
|
||||
if (g_extern.filter.active)
|
||||
return;
|
||||
if (*g_settings.video.filter_path == '\0')
|
||||
return;
|
||||
|
||||
SSNES_LOG("Loading bSNES filter from \"%s\"\n", g_settings.video.filter_path);
|
||||
g_extern.filter.lib = dylib_load(g_settings.video.filter_path);
|
||||
if (!g_extern.filter.lib)
|
||||
{
|
||||
SSNES_ERR("Failed to load filter \"%s\"\n", g_settings.video.filter_path);
|
||||
return;
|
||||
}
|
||||
|
||||
g_extern.filter.psize = dylib_proc(g_extern.filter.lib, "filter_size");
|
||||
g_extern.filter.prender = dylib_proc(g_extern.filter.lib, "filter_render");
|
||||
if (!g_extern.filter.psize || !g_extern.filter.prender)
|
||||
{
|
||||
SSNES_ERR("Failed to find functions in filter...\n");
|
||||
dylib_close(g_extern.filter.lib);
|
||||
g_extern.filter.lib = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
g_extern.filter.active = true;
|
||||
|
||||
unsigned width = 512;
|
||||
unsigned height = 512;
|
||||
g_extern.filter.psize(&width, &height);
|
||||
|
||||
unsigned pow2_x = next_pow2(ceil(width));
|
||||
unsigned pow2_y = next_pow2(ceil(height));
|
||||
unsigned maxsize = pow2_x > pow2_y ? pow2_x : pow2_y;
|
||||
g_extern.filter.scale = maxsize / 256;
|
||||
|
||||
g_extern.filter.buffer = malloc(256 * 256 * g_extern.filter.scale * g_extern.filter.scale * sizeof(uint32_t));
|
||||
g_extern.filter.pitch = 256 * g_extern.filter.scale * sizeof(uint32_t);
|
||||
assert(g_extern.filter.buffer);
|
||||
|
||||
g_extern.filter.colormap = malloc(32768 * sizeof(uint32_t));
|
||||
assert(g_extern.filter.colormap);
|
||||
|
||||
// Set up conversion map from 16-bit XBGR1555 to 32-bit RGBA.
|
||||
for (int i = 0; i < 32768; i++)
|
||||
{
|
||||
unsigned r = (i >> 10) & 31;
|
||||
unsigned g = (i >> 5) & 31;
|
||||
unsigned b = (i >> 0) & 31;
|
||||
|
||||
r = (r << 3) | (r >> 2);
|
||||
g = (g << 3) | (g >> 2);
|
||||
b = (b << 3) | (b >> 2);
|
||||
g_extern.filter.colormap[i] = (r << 24) | (g << 16) | (b << 8);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void deinit_filter(void)
|
||||
{
|
||||
if (g_extern.filter.active)
|
||||
{
|
||||
g_extern.filter.active = false;
|
||||
dylib_close(g_extern.filter.lib);
|
||||
g_extern.filter.lib = NULL;
|
||||
free(g_extern.filter.buffer);
|
||||
free(g_extern.filter.colormap);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_XML
|
||||
static void init_shader_dir(void)
|
||||
{
|
||||
if (!*g_settings.video.shader_dir)
|
||||
return;
|
||||
|
||||
g_extern.shader_dir.elems = dir_list_new(g_settings.video.shader_dir, ".shader");
|
||||
g_extern.shader_dir.size = 0;
|
||||
g_extern.shader_dir.ptr = 0;
|
||||
if (g_extern.shader_dir.elems)
|
||||
{
|
||||
while (g_extern.shader_dir.elems[g_extern.shader_dir.size])
|
||||
{
|
||||
SSNES_LOG("Found shader \"%s\"\n", g_extern.shader_dir.elems[g_extern.shader_dir.size]);
|
||||
g_extern.shader_dir.size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void deinit_shader_dir(void)
|
||||
{
|
||||
// It handles NULL, no worries :D
|
||||
dir_list_free(g_extern.shader_dir.elems);
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_video_input(void)
|
||||
{
|
||||
int scale = 2;
|
||||
#ifdef HAVE_FILTER
|
||||
init_filter();
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XML
|
||||
init_shader_dir();
|
||||
#endif
|
||||
|
||||
// We use at least 512x512 textures to accomodate for hi-res games.
|
||||
unsigned scale = 2;
|
||||
|
||||
find_video_driver();
|
||||
find_input_driver();
|
||||
|
||||
// We multiply scales with 2 to allow for hi-res games.
|
||||
#if HAVE_FILTER
|
||||
switch (g_settings.video.filter)
|
||||
{
|
||||
case FILTER_HQ2X:
|
||||
scale = 4;
|
||||
break;
|
||||
case FILTER_HQ4X:
|
||||
case FILTER_NTSC:
|
||||
scale = 8;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (g_extern.filter.active)
|
||||
scale = g_extern.filter.scale;
|
||||
|
||||
video_info_t video = {
|
||||
.width = (g_settings.video.fullscreen) ? g_settings.video.fullscreen_x : (296 * g_settings.video.xscale),
|
||||
@@ -225,6 +343,7 @@ void init_video_input(void)
|
||||
.force_aspect = g_settings.video.force_aspect,
|
||||
.smooth = g_settings.video.smooth,
|
||||
.input_scale = scale,
|
||||
.rgb32 = g_extern.filter.active
|
||||
};
|
||||
|
||||
const input_driver_t *tmp = driver.input;
|
||||
@@ -264,31 +383,13 @@ void uninit_video_input(void)
|
||||
|
||||
if ( driver.input_data != driver.video_data && driver.input )
|
||||
driver.input->free(driver.input_data);
|
||||
|
||||
deinit_filter();
|
||||
|
||||
#ifdef HAVE_XML
|
||||
deinit_shader_dir();
|
||||
#endif
|
||||
}
|
||||
|
||||
driver_t driver;
|
||||
|
||||
#if 0
|
||||
driver_t driver = {
|
||||
#if VIDEO_DRIVER == VIDEO_GL
|
||||
.video = &video_gl,
|
||||
#else
|
||||
#error "Define a valid video driver in config.h"
|
||||
#endif
|
||||
|
||||
#if AUDIO_DRIVER == AUDIO_ALSA
|
||||
.audio = &audio_alsa,
|
||||
#elif AUDIO_DRIVER == AUDIO_RSOUND
|
||||
.audio = &audio_rsound,
|
||||
#elif AUDIO_DRIVER == AUDIO_OSS
|
||||
.audio = &audio_oss,
|
||||
#elif AUDIO_DRIVER == AUDIO_ROAR
|
||||
.audio = &audio_roar,
|
||||
#elif AUDIO_DRIVER == AUDIO_AL
|
||||
.audio = &audio_openal,
|
||||
#else
|
||||
#error "Define a valid audio driver in config.h"
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -34,8 +34,17 @@ enum
|
||||
SSNES_QUIT_KEY,
|
||||
SSNES_STATE_SLOT_PLUS,
|
||||
SSNES_STATE_SLOT_MINUS,
|
||||
SSNES_AUDIO_INPUT_RATE_PLUS,
|
||||
SSNES_AUDIO_INPUT_RATE_MINUS,
|
||||
SSNES_REWIND,
|
||||
SSNES_MOVIE_RECORD_TOGGLE,
|
||||
SSNES_PAUSE_TOGGLE,
|
||||
SSNES_RESET,
|
||||
SSNES_SHADER_NEXT,
|
||||
SSNES_SHADER_PREV,
|
||||
};
|
||||
|
||||
|
||||
struct snes_keybind
|
||||
{
|
||||
int id;
|
||||
@@ -53,6 +62,7 @@ typedef struct video_info
|
||||
bool force_aspect;
|
||||
bool smooth;
|
||||
int input_scale; // HQ2X => 2, HQ4X => 4, None => 1
|
||||
bool rgb32; // Use 32-bit RGBA rather than native XBGR1555.
|
||||
} video_info_t;
|
||||
|
||||
typedef struct audio_driver
|
||||
@@ -67,15 +77,14 @@ typedef struct audio_driver
|
||||
const char *ident;
|
||||
} audio_driver_t;
|
||||
|
||||
#define AXIS_NEG(x) ((uint32_t)(x << 16) | 0xFFFF)
|
||||
#define AXIS_NEG(x) (((uint32_t)(x) << 16) | 0xFFFFU)
|
||||
#define AXIS_POS(x) ((uint32_t)(x) | 0xFFFF0000U)
|
||||
#define AXIS_NONE ((uint32_t)0xFFFFFFFFU)
|
||||
#define AXIS_NONE (0xFFFFFFFFU)
|
||||
|
||||
#define AXIS_NEG_GET(x) ((x >> 16) & 0xFFFF)
|
||||
#define AXIS_POS_GET(x) (x & 0xFFFF)
|
||||
#define AXIS_NONE ((uint32_t)0xFFFFFFFFU)
|
||||
#define AXIS_NEG_GET(x) (((uint32_t)(x) >> 16) & 0xFFFFU)
|
||||
#define AXIS_POS_GET(x) ((uint32_t)(x) & 0xFFFFU)
|
||||
|
||||
#define NO_BTN 0xFFFF // I hope no joypad will ever have this many buttons ... ;)
|
||||
#define NO_BTN ((uint16_t)0xFFFFU) // I hope no joypad will ever have this many buttons ... ;)
|
||||
|
||||
#define HAT_UP_MASK (1 << 15)
|
||||
#define HAT_DOWN_MASK (1 << 14)
|
||||
@@ -101,10 +110,12 @@ typedef struct video_driver
|
||||
{
|
||||
void* (*init)(video_info_t *video, const input_driver_t **input, void **input_data);
|
||||
// Should the video driver act as an input driver as well? :) The video init might preinitialize an input driver to override the settings in case the video driver relies on input driver for event handling, e.g.
|
||||
bool (*frame)(void* data, const uint16_t* frame, unsigned width, unsigned height, unsigned pitch, const char *msg); // msg is for showing a message on the screen along with the video frame.
|
||||
bool (*frame)(void* data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg); // msg is for showing a message on the screen along with the video frame.
|
||||
void (*set_nonblock_state)(void* data, bool toggle); // Should we care about syncing to vblank? Fast forwarding.
|
||||
// Is the window still active?
|
||||
bool (*alive)(void *data);
|
||||
bool (*focus)(void *data); // Does the window have focus?
|
||||
bool (*xml_shader)(void *data, const char *path); // Sets XML-shader. Might not be implemented.
|
||||
void (*free)(void* data);
|
||||
const char *ident;
|
||||
} video_driver_t;
|
||||
@@ -138,8 +149,12 @@ extern const audio_driver_t audio_roar;
|
||||
extern const audio_driver_t audio_openal;
|
||||
extern const audio_driver_t audio_jack;
|
||||
extern const audio_driver_t audio_sdl;
|
||||
extern const audio_driver_t audio_xa;
|
||||
extern const audio_driver_t audio_pulse;
|
||||
extern const video_driver_t video_gl;
|
||||
extern const video_driver_t video_xvideo;
|
||||
extern const input_driver_t input_sdl;
|
||||
extern const input_driver_t input_x;
|
||||
////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
@@ -25,31 +25,28 @@
|
||||
|
||||
#include <libsnes.hpp>
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define SYM(x) do { \
|
||||
p##x = ((void*)GetProcAddress(lib_handle, #x)); \
|
||||
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
||||
} while(0)
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#define SYM(x) do { \
|
||||
p##x = dlsym(lib_handle, #x); \
|
||||
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
||||
} while(0)
|
||||
#endif // _WIN32
|
||||
#endif // HAVE_DYNAMIC
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
#ifdef _WIN32
|
||||
static HMODULE lib_handle;
|
||||
#else
|
||||
static void *lib_handle = NULL;
|
||||
#endif
|
||||
#define DLSYM(lib, x) dylib_proc(lib, #x)
|
||||
|
||||
#define SYM(x) do { \
|
||||
p##x = DLSYM(lib_handle, x); \
|
||||
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
||||
} while(0)
|
||||
|
||||
#define OPT_SYM(x) do { \
|
||||
p##x = DLSYM(lib_handle, x); \
|
||||
} while(0)
|
||||
|
||||
static dylib_t lib_handle = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
void (*psnes_init)(void);
|
||||
|
||||
void (*psnes_set_video_refresh)(snes_video_refresh_t);
|
||||
@@ -57,8 +54,10 @@ void (*psnes_set_audio_sample)(snes_audio_sample_t);
|
||||
void (*psnes_set_input_poll)(snes_input_poll_t);
|
||||
void (*psnes_set_input_state)(snes_input_state_t);
|
||||
|
||||
void (*psnes_reset)(void);
|
||||
void (*psnes_run)(void);
|
||||
|
||||
const char *(*psnes_library_id)(void) = NULL;
|
||||
unsigned (*psnes_library_revision_minor)(void);
|
||||
unsigned (*psnes_library_revision_major)(void);
|
||||
|
||||
@@ -97,11 +96,7 @@ void (*psnes_term)(void);
|
||||
static void load_dynamic(void)
|
||||
{
|
||||
SSNES_LOG("Loading dynamic libsnes from: \"%s\"\n", g_settings.libsnes);
|
||||
#ifdef _WIN32
|
||||
lib_handle = LoadLibrary(g_settings.libsnes);
|
||||
#else
|
||||
lib_handle = dlopen(g_settings.libsnes, RTLD_LAZY);
|
||||
#endif
|
||||
lib_handle = dylib_load(g_settings.libsnes);
|
||||
if (!lib_handle)
|
||||
{
|
||||
SSNES_ERR("Failed to open dynamic library: \"%s\"\n", g_settings.libsnes);
|
||||
@@ -113,8 +108,10 @@ static void load_dynamic(void)
|
||||
SYM(snes_set_audio_sample);
|
||||
SYM(snes_set_input_poll);
|
||||
SYM(snes_set_input_state);
|
||||
OPT_SYM(snes_library_id);
|
||||
SYM(snes_library_revision_minor);
|
||||
SYM(snes_library_revision_major);
|
||||
SYM(snes_reset);
|
||||
SYM(snes_run);
|
||||
SYM(snes_get_region);
|
||||
SYM(snes_load_cartridge_normal);
|
||||
@@ -148,6 +145,7 @@ static void set_statics(void)
|
||||
SSYM(snes_set_input_state);
|
||||
SSYM(snes_library_revision_minor);
|
||||
SSYM(snes_library_revision_major);
|
||||
SSYM(snes_reset);
|
||||
SSYM(snes_run);
|
||||
SSYM(snes_get_region);
|
||||
SSYM(snes_load_cartridge_normal);
|
||||
@@ -186,12 +184,39 @@ void uninit_dlsym(void)
|
||||
{
|
||||
#ifdef HAVE_DYNAMIC
|
||||
if (lib_handle)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(lib_handle);
|
||||
#else
|
||||
dlclose(lib_handle);
|
||||
#endif
|
||||
}
|
||||
dylib_close(lib_handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Platform independent dylib loading.
|
||||
dylib_t dylib_load(const char *path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return LoadLibrary(path);
|
||||
#else
|
||||
return dlopen(path, RTLD_LAZY);
|
||||
#endif
|
||||
}
|
||||
|
||||
void* dylib_proc(dylib_t lib, const char *proc)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
void *sym = (void*)GetProcAddress(lib, proc);
|
||||
#else
|
||||
void *sym = dlsym(lib, proc);
|
||||
#endif
|
||||
|
||||
if (!sym)
|
||||
SSNES_WARN("Failed to load symbol \"%s\"\n", proc);
|
||||
return sym;
|
||||
}
|
||||
|
||||
void dylib_close(dylib_t lib)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FreeLibrary(lib);
|
||||
#else
|
||||
dlclose(lib);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
void init_dlsym(void);
|
||||
void uninit_dlsym(void);
|
||||
|
||||
typedef void *dylib_t;
|
||||
|
||||
dylib_t dylib_load(const char *path);
|
||||
void dylib_close(dylib_t lib);
|
||||
void* dylib_proc(dylib_t lib, const char *proc);
|
||||
|
||||
extern void (*psnes_init)(void);
|
||||
|
||||
extern void (*psnes_set_video_refresh)(snes_video_refresh_t);
|
||||
@@ -31,6 +37,7 @@ extern void (*psnes_set_audio_sample)(snes_audio_sample_t);
|
||||
extern void (*psnes_set_input_poll)(snes_input_poll_t);
|
||||
extern void (*psnes_set_input_state)(snes_input_state_t);
|
||||
|
||||
extern const char* (*psnes_library_id)(void);
|
||||
extern unsigned (*psnes_library_revision_minor)(void);
|
||||
extern unsigned (*psnes_library_revision_major)(void);
|
||||
|
||||
@@ -49,7 +56,6 @@ extern bool (*psnes_load_cartridge_sufami_turbo)(
|
||||
const char*, const uint8_t*, unsigned,
|
||||
const char*, const uint8_t*, unsigned);
|
||||
|
||||
|
||||
extern void (*psnes_set_controller_port_device)(bool, unsigned);
|
||||
|
||||
extern bool (*psnes_get_region)(void);
|
||||
@@ -58,6 +64,7 @@ extern unsigned (*psnes_serialize_size)(void);
|
||||
extern bool (*psnes_serialize)(uint8_t*, unsigned);
|
||||
extern bool (*psnes_unserialize)(const uint8_t*, unsigned);
|
||||
|
||||
extern void (*psnes_reset)(void);
|
||||
extern void (*psnes_run)(void);
|
||||
|
||||
extern void (*psnes_set_cartridge_basename)(const char*);
|
||||
|
||||
@@ -22,80 +22,18 @@
|
||||
#include <libsnes.hpp>
|
||||
#include <string.h>
|
||||
#include "dynamic.h"
|
||||
#include "movie.h"
|
||||
#include "ups.h"
|
||||
#include "strl.h"
|
||||
|
||||
// Load SNES rom only. Applies a hack for headered ROMs.
|
||||
static ssize_t read_rom_file(FILE* file, void** buf)
|
||||
{
|
||||
ssize_t ret;
|
||||
if (file == NULL) // stdin
|
||||
{
|
||||
SSNES_LOG("Reading ROM from stdin ...\n");
|
||||
size_t buf_size = 0xFFFFF; // Some initial guesstimate.
|
||||
size_t buf_ptr = 0;
|
||||
char *rom_buf = malloc(buf_size);
|
||||
if (rom_buf == NULL)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
size_t ret = fread(rom_buf + buf_ptr, 1, buf_size - buf_ptr, stdin);
|
||||
buf_ptr += ret;
|
||||
|
||||
// We've reached the end
|
||||
if (buf_ptr < buf_size)
|
||||
break;
|
||||
|
||||
rom_buf = realloc(rom_buf, buf_size * 2);
|
||||
if (rom_buf == NULL)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf_size *= 2;
|
||||
}
|
||||
|
||||
if ((buf_ptr & 0x7fff) == 512)
|
||||
{
|
||||
memmove(rom_buf, rom_buf + 512, buf_ptr - 512);
|
||||
buf_ptr -= 512;
|
||||
}
|
||||
|
||||
*buf = rom_buf;
|
||||
ret = buf_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(file, 0, SEEK_END);
|
||||
long length = ftell(file);
|
||||
rewind(file);
|
||||
if ((length & 0x7fff) == 512)
|
||||
{
|
||||
length -= 512;
|
||||
fseek(file, 512, SEEK_SET);
|
||||
}
|
||||
|
||||
void *rom_buf = malloc(length);
|
||||
if ( rom_buf == NULL )
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( fread(rom_buf, 1, length, file) < length )
|
||||
{
|
||||
SSNES_ERR("Didn't read whole file.\n");
|
||||
free(rom_buf);
|
||||
return -1;
|
||||
}
|
||||
*buf = rom_buf;
|
||||
ret = length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
// Generic file loader.
|
||||
static ssize_t read_file(const char *path, void **buf)
|
||||
@@ -103,10 +41,7 @@ static ssize_t read_file(const char *path, void **buf)
|
||||
void *rom_buf = NULL;
|
||||
FILE *file = fopen(path, "rb");
|
||||
if (!file)
|
||||
{
|
||||
SSNES_ERR("Couldn't open file: \"%s\"\n", path);
|
||||
goto error;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long len = ftell(file);
|
||||
@@ -134,15 +69,123 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Load SNES rom only. Applies a hack for headered ROMs.
|
||||
static ssize_t read_rom_file(FILE* file, void** buf)
|
||||
{
|
||||
ssize_t ret = 0;
|
||||
uint8_t *ret_buf = NULL;
|
||||
|
||||
if (file == NULL) // stdin
|
||||
{
|
||||
#ifdef _WIN32
|
||||
setmode(0, O_BINARY);
|
||||
#endif
|
||||
|
||||
SSNES_LOG("Reading ROM from stdin ...\n");
|
||||
size_t buf_size = 0xFFFFF; // Some initial guesstimate.
|
||||
size_t buf_ptr = 0;
|
||||
uint8_t *rom_buf = malloc(buf_size);
|
||||
if (rom_buf == NULL)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
size_t ret = fread(rom_buf + buf_ptr, 1, buf_size - buf_ptr, stdin);
|
||||
buf_ptr += ret;
|
||||
|
||||
// We've reached the end
|
||||
if (buf_ptr < buf_size)
|
||||
break;
|
||||
|
||||
rom_buf = realloc(rom_buf, buf_size * 2);
|
||||
if (rom_buf == NULL)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf_size *= 2;
|
||||
}
|
||||
|
||||
ret_buf = rom_buf;
|
||||
ret = buf_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(file, 0, SEEK_END);
|
||||
ret = ftell(file);
|
||||
rewind(file);
|
||||
|
||||
void *rom_buf = malloc(ret);
|
||||
if (rom_buf == NULL)
|
||||
{
|
||||
SSNES_ERR("Couldn't allocate memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fread(rom_buf, 1, ret, file) < ret)
|
||||
{
|
||||
SSNES_ERR("Didn't read whole file.\n");
|
||||
free(rom_buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
memmove(ret_buf, ret_buf + 512, ret - 512);
|
||||
ret -= 512;
|
||||
}
|
||||
|
||||
g_extern.cart_crc = crc32_calculate(ret_buf, ret);
|
||||
*buf = ret_buf;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// Dump stuff to file.
|
||||
static bool dump_to_file(const char *path, const void *data, size_t size)
|
||||
{
|
||||
FILE *file = fopen(path, "wb");
|
||||
if (!file)
|
||||
{
|
||||
SSNES_ERR("Couldn't dump to file %s\n", path);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite(data, 1, size, file);
|
||||
@@ -169,6 +212,8 @@ bool save_state(const char* path)
|
||||
psnes_serialize(data, size);
|
||||
bool ret = dump_to_file(path, data, size);
|
||||
free(data);
|
||||
if (!ret)
|
||||
SSNES_ERR("Failed to save state to \"%s\".\n", path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -179,7 +224,7 @@ bool load_state(const char* path)
|
||||
ssize_t size = read_file(path, &buf);
|
||||
if (size < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to load state.\n");
|
||||
SSNES_ERR("Failed to load state from \"%s\".\n", path);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -213,7 +258,7 @@ 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 )
|
||||
if (data && size > 0)
|
||||
dump_to_file(path, data, size);
|
||||
}
|
||||
|
||||
@@ -232,14 +277,7 @@ static bool load_sgb_rom(void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
extra_rom = fopen(g_extern.gb_rom_path, "rb");
|
||||
if (!extra_rom)
|
||||
{
|
||||
SSNES_ERR("Couldn't open GameBoy ROM!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((extra_rom_len = read_rom_file(extra_rom, &extra_rom_buf)) == -1)
|
||||
if ((extra_rom_len = read_file(g_extern.gb_rom_path, &extra_rom_buf)) == -1)
|
||||
{
|
||||
SSNES_ERR("Cannot read GameBoy rom.\n");
|
||||
goto error;
|
||||
@@ -286,14 +324,7 @@ static bool load_bsx_rom(bool slotted)
|
||||
goto error;
|
||||
}
|
||||
|
||||
extra_rom = fopen(g_extern.bsx_rom_path, "rb");
|
||||
if (!extra_rom)
|
||||
{
|
||||
SSNES_ERR("Couldn't open BSX game rom!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((extra_rom_len = read_rom_file(extra_rom, &extra_rom_buf)) == -1)
|
||||
if ((extra_rom_len = read_file(g_extern.bsx_rom_path, &extra_rom_buf)) == -1)
|
||||
{
|
||||
SSNES_ERR("Cannot read BSX game rom.\n");
|
||||
goto error;
|
||||
@@ -302,12 +333,12 @@ static bool load_bsx_rom(bool slotted)
|
||||
if (slotted)
|
||||
{
|
||||
if (!psnes_load_cartridge_bsx_slotted(
|
||||
NULL, rom_buf, rom_len,
|
||||
NULL, extra_rom_buf, extra_rom_len))
|
||||
{
|
||||
SSNES_ERR("Cannot load BSX slotted rom.\n");
|
||||
goto error;
|
||||
}
|
||||
NULL, rom_buf, rom_len,
|
||||
NULL, extra_rom_buf, extra_rom_len))
|
||||
{
|
||||
SSNES_ERR("Cannot load BSX slotted rom.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@@ -360,16 +391,9 @@ static bool load_sufami_rom(void)
|
||||
{
|
||||
if (strlen(roms[i]) > 0)
|
||||
{
|
||||
extra_rom[i] = fopen(roms[i], "rb");
|
||||
if (!extra_rom[i])
|
||||
if ((extra_rom_len[i] = read_file(roms[i], &extra_rom_buf[i])) == -1)
|
||||
{
|
||||
SSNES_ERR("Couldn't open BSX game rom!\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((extra_rom_len[i] = read_rom_file(extra_rom[i], &extra_rom_buf[i])) == -1)
|
||||
{
|
||||
SSNES_ERR("Cannot read BSX game rom.\n");
|
||||
SSNES_ERR("Cannot read Sufami game rom.\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -474,3 +498,126 @@ bool init_rom_file(enum ssnes_game_type type)
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
#ifdef _WIN32
|
||||
WIN32_FIND_DATAW ffd;
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
|
||||
|
||||
size_t final_off = MAX_PATH + path_len + 2;
|
||||
|
||||
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;
|
||||
|
||||
hFind = FindFirstFileW(wchar_buf, &ffd);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
goto error;
|
||||
#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)
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
dir_list = calloc(cur_size, sizeof(char*));
|
||||
if (!dir_list)
|
||||
goto error;
|
||||
|
||||
#ifdef _WIN32 // Hard to read? Blame non-POSIX heathens!
|
||||
do
|
||||
#else
|
||||
while ((entry = readdir(directory)))
|
||||
#endif
|
||||
{
|
||||
// Not a perfect search of course, but hopefully good enough in practice.
|
||||
#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 (ext && !strstr(utf8_buf, ext))
|
||||
continue;
|
||||
#else
|
||||
if (ext && !strstr(entry->d_name, ext))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
dir_list[cur_ptr] = malloc(final_off);
|
||||
if (!dir_list[cur_ptr])
|
||||
goto error;
|
||||
|
||||
strcpy(dir_list[cur_ptr], dir);
|
||||
#ifdef _WIN32
|
||||
dir_list[cur_ptr][path_len] = '\\';
|
||||
strcpy(&dir_list[cur_ptr][path_len + 1], utf8_buf);
|
||||
#else
|
||||
dir_list[cur_ptr][path_len] = '/';
|
||||
strcpy(&dir_list[cur_ptr][path_len + 1], entry->d_name);
|
||||
#endif
|
||||
dir_list[cur_ptr][final_off - 1] = '\0';
|
||||
|
||||
cur_ptr++;
|
||||
if (cur_ptr + 1 == cur_size) // Need to reserve for NULL.
|
||||
{
|
||||
cur_size *= 2;
|
||||
dir_list = realloc(dir_list, cur_size * sizeof(char*));
|
||||
if (!dir_list)
|
||||
goto error;
|
||||
|
||||
// Make sure it's all NULL'd out since we cannot rely on realloc to do this.
|
||||
memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*));
|
||||
}
|
||||
}
|
||||
#ifdef _WIN32
|
||||
while (FindNextFileW(hFind, &ffd) != 0);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
FindClose(hFind);
|
||||
#else
|
||||
closedir(directory);
|
||||
#endif
|
||||
return dir_list;
|
||||
|
||||
error:
|
||||
SSNES_ERR("Failed to open directory: \"%s\"\n", dir);
|
||||
#ifdef _WIN32
|
||||
if (hFind != INVALID_HANDLE_VALUE)
|
||||
FindClose(hFind);
|
||||
#else
|
||||
if (directory)
|
||||
closedir(directory);
|
||||
#endif
|
||||
dir_list_free(dir_list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void dir_list_free(char **dir_list)
|
||||
{
|
||||
if (!dir_list)
|
||||
return;
|
||||
|
||||
char **orig = dir_list;
|
||||
while (*dir_list)
|
||||
free(*dir_list++);
|
||||
free(orig);
|
||||
}
|
||||
@@ -34,4 +34,8 @@ void save_ram_file(const char* path, int type);
|
||||
|
||||
bool init_rom_file(enum ssnes_game_type type);
|
||||
|
||||
// Returns a NULL-terminated list of files in a directory with full paths.
|
||||
char** dir_list_new(const char *dir, const char *ext);
|
||||
void dir_list_free(char **dir_list);
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,11 @@
|
||||
#include <stdio.h>
|
||||
#include "record/ffemu.h"
|
||||
#include "message.h"
|
||||
#include "rewind.h"
|
||||
#include "movie.h"
|
||||
#include "autosave.h"
|
||||
#include "netplay.h"
|
||||
#include "dynamic.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@@ -31,12 +36,24 @@
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
#include <samplerate.h>
|
||||
#else
|
||||
#include "audio/hermite.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_PLAYERS 5
|
||||
#define MAX_BINDS 20 // Needs to be increased every time there are new binds added.
|
||||
#define MAX_BINDS 28 // Needs to be increased every time there are new binds added.
|
||||
#define SSNES_NO_JOYPAD 0xFFFF
|
||||
|
||||
enum ssnes_shader_type
|
||||
{
|
||||
SSNES_SHADER_CG,
|
||||
SSNES_SHADER_BSNES,
|
||||
SSNES_SHADER_AUTO,
|
||||
SSNES_SHADER_NONE
|
||||
};
|
||||
|
||||
// All config related settings go here.
|
||||
struct settings
|
||||
{
|
||||
struct
|
||||
@@ -53,7 +70,15 @@ struct settings
|
||||
float aspect_ratio;
|
||||
char cg_shader_path[256];
|
||||
char bsnes_shader_path[256];
|
||||
unsigned filter;
|
||||
char filter_path[256];
|
||||
enum ssnes_shader_type shader_type;
|
||||
|
||||
bool render_to_texture;
|
||||
double fbo_scale_x;
|
||||
double fbo_scale_y;
|
||||
char second_pass_shader[256];
|
||||
bool second_pass_smooth;
|
||||
char shader_dir[256];
|
||||
|
||||
char font_path[256];
|
||||
unsigned font_size;
|
||||
@@ -67,7 +92,8 @@ struct settings
|
||||
char driver[32];
|
||||
bool enable;
|
||||
unsigned out_rate;
|
||||
unsigned in_rate;
|
||||
float in_rate;
|
||||
float rate_step;
|
||||
char device[256];
|
||||
unsigned latency;
|
||||
bool sync;
|
||||
@@ -80,9 +106,17 @@ struct settings
|
||||
struct snes_keybind binds[MAX_PLAYERS][MAX_BINDS];
|
||||
float axis_threshold;
|
||||
unsigned joypad_map[MAX_PLAYERS];
|
||||
bool netplay_client_swap_input;
|
||||
} input;
|
||||
|
||||
char libsnes[256];
|
||||
|
||||
bool rewind_enable;
|
||||
unsigned rewind_buffer_size;
|
||||
unsigned rewind_granularity;
|
||||
|
||||
bool pause_nonactive;
|
||||
unsigned autosave_interval;
|
||||
};
|
||||
|
||||
enum ssnes_game_type
|
||||
@@ -94,10 +128,11 @@ enum ssnes_game_type
|
||||
SSNES_CART_SUFAMI,
|
||||
};
|
||||
|
||||
|
||||
// All run-time- / command line flag-related globals go here.
|
||||
struct global
|
||||
{
|
||||
bool verbose;
|
||||
SRC_STATE *source;
|
||||
bool audio_active;
|
||||
bool video_active;
|
||||
|
||||
@@ -109,10 +144,13 @@ struct global
|
||||
|
||||
FILE *rom_file;
|
||||
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];
|
||||
bool has_set_save_path;
|
||||
bool has_set_state_path;
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
char config_path[256];
|
||||
@@ -125,11 +163,18 @@ struct global
|
||||
char savefile_name_asrm[512];
|
||||
char savefile_name_bsrm[512];
|
||||
char savestate_name[256];
|
||||
char ups_name[512];
|
||||
|
||||
unsigned state_slot;
|
||||
|
||||
struct
|
||||
{
|
||||
#ifdef HAVE_SRC
|
||||
SRC_STATE *source;
|
||||
#else
|
||||
hermite_resampler_t *source;
|
||||
#endif
|
||||
|
||||
float *data;
|
||||
size_t data_ptr;
|
||||
size_t chunk_size;
|
||||
@@ -142,13 +187,62 @@ struct global
|
||||
int16_t *conv_outsamples;
|
||||
} audio_data;
|
||||
|
||||
struct
|
||||
{
|
||||
bool active;
|
||||
uint32_t *buffer;
|
||||
uint32_t *colormap;
|
||||
unsigned pitch;
|
||||
dylib_t lib;
|
||||
unsigned scale;
|
||||
|
||||
void (*psize)(unsigned *width, unsigned *height);
|
||||
void (*prender)(uint32_t *colormap, uint32_t *output, unsigned outpitch,
|
||||
const uint16_t *input, unsigned pitch, unsigned width, unsigned height);
|
||||
} filter;
|
||||
|
||||
msg_queue_t *msg_queue;
|
||||
|
||||
// Rewind support.
|
||||
state_manager_t *state_manager;
|
||||
void *state_buf;
|
||||
bool frame_is_reverse;
|
||||
|
||||
// Movie record support
|
||||
bsv_movie_t *bsv_movie;
|
||||
char bsv_movie_path[256];
|
||||
bool bsv_movie_end;
|
||||
bool bsv_movie_playback;
|
||||
|
||||
// Pausing support
|
||||
bool is_paused;
|
||||
|
||||
// Autosave support.
|
||||
autosave_t *autosave[2];
|
||||
|
||||
// Netplay.
|
||||
netplay_t *netplay;
|
||||
char netplay_server[256];
|
||||
bool netplay_enable;
|
||||
bool netplay_is_client;
|
||||
unsigned netplay_sync_frames;
|
||||
uint16_t netplay_port;
|
||||
|
||||
// FFmpeg record.
|
||||
#ifdef HAVE_FFMPEG
|
||||
ffemu_t *rec;
|
||||
char record_path[256];
|
||||
bool recording;
|
||||
#endif
|
||||
|
||||
char title_buf[64];
|
||||
|
||||
struct
|
||||
{
|
||||
char** elems;
|
||||
size_t size;
|
||||
size_t ptr;
|
||||
} shader_dir;
|
||||
};
|
||||
|
||||
void parse_config(void);
|
||||
@@ -172,4 +266,18 @@ extern struct global g_extern;
|
||||
fflush(stderr); \
|
||||
} while(0)
|
||||
|
||||
static inline uint32_t next_pow2(uint32_t v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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 "gfx_common.h"
|
||||
#include "general.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
|
||||
{
|
||||
float time = new_tv->tv_sec - tv->tv_sec + (new_tv->tv_usec - tv->tv_usec)/1000000.0;
|
||||
return frames/time;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
gettimeofday(&tv, NULL);
|
||||
snprintf(buf, size, g_extern.title_buf);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if ((frames % 180) == 0 && frames > 0)
|
||||
{
|
||||
gettimeofday(&new_tv, NULL);
|
||||
struct timeval tmp_tv = tv;
|
||||
tv = new_tv;
|
||||
|
||||
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);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
frames++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* 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 __GFX_COMMON_H
|
||||
#define __GFX_COMMON_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool gfx_window_title(char *buf, size_t size);
|
||||
|
||||
#endif
|
||||
+38
-1
@@ -20,6 +20,15 @@
|
||||
|
||||
#include "general.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glext.h>
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#endif
|
||||
|
||||
static inline bool gl_check_error(void)
|
||||
{
|
||||
int error = glGetError();
|
||||
@@ -29,7 +38,7 @@ static inline bool gl_check_error(void)
|
||||
SSNES_ERR("GL: Invalid enum.\n");
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
SSNES_ERR("GL: Invalid value.\n");
|
||||
SSNES_ERR("GL: Invalid value. (You're not alone.)\n");
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
SSNES_ERR("GL: Invalid operation.\n");
|
||||
@@ -56,4 +65,32 @@ static inline bool gl_check_error(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
struct gl_fbo_rect
|
||||
{
|
||||
unsigned img_width;
|
||||
unsigned img_height;
|
||||
unsigned max_img_width;
|
||||
unsigned max_img_height;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
};
|
||||
|
||||
enum gl_scale_type
|
||||
{
|
||||
SSNES_SCALE_ABSOLUTE,
|
||||
SSNES_SCALE_INPUT,
|
||||
SSNES_SCALE_VIEWPORT
|
||||
};
|
||||
|
||||
struct gl_fbo_scale
|
||||
{
|
||||
enum gl_scale_type type_x;
|
||||
enum gl_scale_type type_y;
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
unsigned abs_x;
|
||||
unsigned abs_y;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
#endif
|
||||
+100
-47
@@ -19,6 +19,7 @@
|
||||
#include <Cg/cg.h>
|
||||
#include <Cg/cgGL.h>
|
||||
#include "general.h"
|
||||
#include <string.h>
|
||||
|
||||
// Used when we call deactivate() since just unbinding the program didn't seem to work... :(
|
||||
static const char* stock_cg_program =
|
||||
@@ -55,21 +56,28 @@ static const char* stock_cg_program =
|
||||
|
||||
|
||||
static CGcontext cgCtx;
|
||||
static CGprogram cgFPrg;
|
||||
static CGprogram cgVPrg;
|
||||
static CGprogram cgSFPrg;
|
||||
static CGprogram cgSVPrg;
|
||||
static CGprofile cgFProf;
|
||||
static CGprofile cgVProf;
|
||||
static CGparameter cg_video_size, cg_texture_size, cg_output_size;
|
||||
static CGparameter cg_Vvideo_size, cg_Vtexture_size, cg_Voutput_size; // Vertexes
|
||||
static CGparameter cg_mvp_matrix;
|
||||
struct cg_program
|
||||
{
|
||||
CGprogram vprg;
|
||||
CGprogram fprg;
|
||||
CGparameter vid_size_f;
|
||||
CGparameter tex_size_f;
|
||||
CGparameter out_size_f;
|
||||
CGparameter vid_size_v;
|
||||
CGparameter tex_size_v;
|
||||
CGparameter out_size_v;
|
||||
CGparameter mvp;
|
||||
};
|
||||
|
||||
static struct cg_program prg[3];
|
||||
static bool cg_active = false;
|
||||
static CGprofile cgVProf, cgFProf;
|
||||
static unsigned active_index = 0;
|
||||
|
||||
void gl_cg_set_proj_matrix(void)
|
||||
{
|
||||
if (cg_active)
|
||||
cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
|
||||
void gl_cg_set_params(unsigned width, unsigned height,
|
||||
@@ -78,13 +86,13 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
{
|
||||
if (cg_active)
|
||||
{
|
||||
cgGLSetParameter2f(cg_video_size, width, height);
|
||||
cgGLSetParameter2f(cg_texture_size, tex_width, tex_height);
|
||||
cgGLSetParameter2f(cg_output_size, out_width, out_height);
|
||||
cgGLSetParameter2f(prg[active_index].vid_size_f, width, height);
|
||||
cgGLSetParameter2f(prg[active_index].tex_size_f, tex_width, tex_height);
|
||||
cgGLSetParameter2f(prg[active_index].out_size_f, out_width, out_height);
|
||||
|
||||
cgGLSetParameter2f(cg_Vvideo_size, width, height);
|
||||
cgGLSetParameter2f(cg_Vtexture_size, tex_width, tex_height);
|
||||
cgGLSetParameter2f(cg_Voutput_size, out_width, out_height);
|
||||
cgGLSetParameter2f(prg[active_index].vid_size_v, width, height);
|
||||
cgGLSetParameter2f(prg[active_index].tex_size_v, tex_width, tex_height);
|
||||
cgGLSetParameter2f(prg[active_index].out_size_v, out_width, out_height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,17 +100,22 @@ void gl_cg_deinit(void)
|
||||
{
|
||||
if (cg_active)
|
||||
cgDestroyContext(cgCtx);
|
||||
cg_active = false;
|
||||
}
|
||||
|
||||
bool gl_cg_init(const char *path)
|
||||
{
|
||||
SSNES_LOG("Loading Cg file: %s\n", path);
|
||||
if (strlen(g_settings.video.second_pass_shader) > 0)
|
||||
SSNES_LOG("Loading 2nd pass: %s\n", g_settings.video.second_pass_shader);
|
||||
|
||||
cgCtx = cgCreateContext();
|
||||
if (cgCtx == NULL)
|
||||
{
|
||||
SSNES_ERR("Failed to create Cg context\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
||||
cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX);
|
||||
if (cgFProf == CG_PROFILE_UNKNOWN || cgVProf == CG_PROFILE_UNKNOWN)
|
||||
@@ -112,54 +125,94 @@ bool gl_cg_init(const char *path)
|
||||
}
|
||||
cgGLSetOptimalOptions(cgFProf);
|
||||
cgGLSetOptimalOptions(cgVProf);
|
||||
cgFPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgFProf, "main_fragment", 0);
|
||||
cgVPrg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgVProf, "main_vertex", 0);
|
||||
cgSFPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_cg_program, cgFProf, "main_fragment", 0);
|
||||
cgSVPrg = cgCreateProgram(cgCtx, CG_SOURCE, stock_cg_program, cgVProf, "main_vertex", 0);
|
||||
if (cgFPrg == NULL || cgVPrg == NULL || cgSFPrg == NULL || cgSVPrg == 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);
|
||||
|
||||
prg[1].fprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgFProf, "main_fragment", 0);
|
||||
prg[1].vprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, path, cgVProf, "main_vertex", 0);
|
||||
|
||||
if (strlen(g_settings.video.second_pass_shader) > 0)
|
||||
{
|
||||
CGerror err = cgGetError();
|
||||
SSNES_ERR("CG error: %s\n", cgGetErrorString(err));
|
||||
return false;
|
||||
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);
|
||||
}
|
||||
cgGLLoadProgram(cgFPrg);
|
||||
cgGLLoadProgram(cgVPrg);
|
||||
cgGLLoadProgram(cgSFPrg);
|
||||
cgGLLoadProgram(cgSVPrg);
|
||||
else
|
||||
prg[2] = prg[0];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (prg[i].fprg == NULL || prg[i].vprg == NULL)
|
||||
{
|
||||
CGerror err = cgGetError();
|
||||
SSNES_ERR("CG error: %s\n", cgGetErrorString(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
cgGLLoadProgram(prg[i].fprg);
|
||||
cgGLLoadProgram(prg[i].vprg);
|
||||
}
|
||||
|
||||
cgGLEnableProfile(cgFProf);
|
||||
cgGLEnableProfile(cgVProf);
|
||||
cgGLBindProgram(cgFPrg);
|
||||
cgGLBindProgram(cgVPrg);
|
||||
|
||||
cg_video_size = cgGetNamedParameter(cgFPrg, "IN.video_size");
|
||||
cg_texture_size = cgGetNamedParameter(cgFPrg, "IN.texture_size");
|
||||
cg_output_size = cgGetNamedParameter(cgFPrg, "IN.output_size");
|
||||
cg_Vvideo_size = cgGetNamedParameter(cgVPrg, "IN.video_size");
|
||||
cg_Vtexture_size = cgGetNamedParameter(cgVPrg, "IN.texture_size");
|
||||
cg_Voutput_size = cgGetNamedParameter(cgVPrg, "IN.output_size");
|
||||
cg_mvp_matrix = cgGetNamedParameter(cgVPrg, "modelViewProj");
|
||||
cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
cg_mvp_matrix = cgGetNamedParameter(cgSVPrg, "modelViewProj");
|
||||
cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
cgGLBindProgram(prg[i].fprg);
|
||||
cgGLBindProgram(prg[i].vprg);
|
||||
|
||||
prg[i].vid_size_f = cgGetNamedParameter(prg[i].fprg, "IN.video_size");
|
||||
prg[i].tex_size_f = cgGetNamedParameter(prg[i].fprg, "IN.texture_size");
|
||||
prg[i].out_size_f = cgGetNamedParameter(prg[i].fprg, "IN.output_size");
|
||||
prg[i].vid_size_v = cgGetNamedParameter(prg[i].vprg, "IN.video_size");
|
||||
prg[i].tex_size_v = cgGetNamedParameter(prg[i].vprg, "IN.texture_size");
|
||||
prg[i].out_size_v = cgGetNamedParameter(prg[i].vprg, "IN.output_size");
|
||||
prg[i].mvp = cgGetNamedParameter(prg[i].vprg, "modelViewProj");
|
||||
cgGLSetStateMatrixParameter(prg[i].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
|
||||
cgGLBindProgram(prg[1].fprg);
|
||||
cgGLBindProgram(prg[1].vprg);
|
||||
|
||||
cg_active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void gl_cg_activate(void)
|
||||
void gl_cg_use(unsigned index)
|
||||
{
|
||||
if (cg_active)
|
||||
{
|
||||
cgGLBindProgram(cgFPrg);
|
||||
cgGLBindProgram(cgVPrg);
|
||||
active_index = index;
|
||||
cgGLBindProgram(prg[index].vprg);
|
||||
cgGLBindProgram(prg[index].fprg);
|
||||
}
|
||||
}
|
||||
|
||||
// Just load a dummy shader.
|
||||
void gl_cg_deactivate(void)
|
||||
unsigned gl_cg_num(void)
|
||||
{
|
||||
if (cg_active)
|
||||
{
|
||||
cgGLBindProgram(cgSFPrg);
|
||||
cgGLBindProgram(cgSVPrg);
|
||||
if (prg[0].fprg == prg[2].fprg)
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool gl_cg_filter_type(unsigned index, bool *smooth)
|
||||
{
|
||||
(void)index;
|
||||
(void)smooth;
|
||||
// We don't really care since .cg doesn't have those kinds of semantics by itself ...
|
||||
return false;
|
||||
}
|
||||
|
||||
void gl_cg_shader_scale(unsigned index, struct gl_fbo_scale *scale)
|
||||
{
|
||||
(void)index;
|
||||
// We don't really care since .cg doesn't have those kinds of semantics by itself ...
|
||||
scale->valid = false;
|
||||
}
|
||||
+7
-2
@@ -20,6 +20,7 @@
|
||||
#define __SSNES_CG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "gl_common.h"
|
||||
|
||||
bool gl_cg_init(const char *path);
|
||||
|
||||
@@ -31,7 +32,11 @@ void gl_cg_set_params(unsigned width, unsigned height,
|
||||
unsigned tex_width, unsigned tex_height,
|
||||
unsigned out_width, unsigned out_height);
|
||||
|
||||
void gl_cg_activate(void);
|
||||
void gl_cg_deactivate(void);
|
||||
void gl_cg_use(unsigned index);
|
||||
|
||||
unsigned gl_cg_num(void);
|
||||
|
||||
bool gl_cg_filter_type(unsigned index, bool *smooth);
|
||||
void gl_cg_shader_scale(unsigned index, struct gl_fbo_scale *scale);
|
||||
|
||||
#endif
|
||||
+460
-88
@@ -15,27 +15,50 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//
|
||||
// GLSL code here is mostly copypasted from bSNES.
|
||||
//
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "general.h"
|
||||
#include "shader_glsl.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define NO_SDL_GLEXT
|
||||
#include <GL/gl.h>
|
||||
#include "SDL.h"
|
||||
#include "SDL_opengl.h"
|
||||
#include <stdlib.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include "gl_common.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define pglCreateProgram glCreateProgram
|
||||
#define pglUseProgram glUseProgram
|
||||
#define pglCreateShader glCreateShader
|
||||
#define pglDeleteShader glDeleteShader
|
||||
#define pglShaderSource glShaderSource
|
||||
#define pglCompileShader glCompileShader
|
||||
#define pglAttachShader glAttachShader
|
||||
#define pglDetachShader glDetachShader
|
||||
#define pglLinkProgram glLinkProgram
|
||||
#define pglGetUniformLocation glGetUniformLocation
|
||||
#define pglUniform1i glUniform1i
|
||||
#define pglUniform2fv glUniform2fv
|
||||
#define pglUniform4fv glUniform4fv
|
||||
#define pglGetShaderiv glGetShaderiv
|
||||
#define pglGetShaderInfoLog glGetShaderInfoLog
|
||||
#define pglGetProgramiv glGetProgramiv
|
||||
#define pglGetProgramInfoLog glGetProgramInfoLog
|
||||
#define pglDeleteProgram glDeleteProgram
|
||||
#define pglGetAttachedShaders glGetAttachedShaders
|
||||
#else
|
||||
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
|
||||
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
|
||||
static PFNGLCREATESHADERPROC pglCreateShader = NULL;
|
||||
@@ -53,13 +76,204 @@ static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
|
||||
static PFNGLGETSHADERINFOLOGPROC pglGetShaderInfoLog = NULL;
|
||||
static PFNGLGETPROGRAMIVPROC pglGetProgramiv = NULL;
|
||||
static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog = NULL;
|
||||
static PFNGLDELETEPROGRAMPROC pglDeleteProgram = NULL;
|
||||
static PFNGLGETATTACHEDSHADERSPROC pglGetAttachedShaders = NULL;
|
||||
#endif
|
||||
|
||||
#define MAX_PROGRAMS 16
|
||||
|
||||
enum filter_type
|
||||
{
|
||||
SSNES_GL_NOFORCE,
|
||||
SSNES_GL_LINEAR,
|
||||
SSNES_GL_NEAREST
|
||||
};
|
||||
|
||||
static bool glsl_enable = false;
|
||||
static GLuint gl_program;
|
||||
static GLuint fragment_shader;
|
||||
static GLuint vertex_shader;
|
||||
static GLuint gl_program[MAX_PROGRAMS] = {0};
|
||||
static enum filter_type gl_filter_type[MAX_PROGRAMS] = {SSNES_GL_NOFORCE};
|
||||
static struct gl_fbo_scale gl_scale[MAX_PROGRAMS];
|
||||
static unsigned gl_num_programs = 0;
|
||||
static unsigned active_index = 0;
|
||||
|
||||
static bool get_xml_shaders(const char *path, char **vertex_shader, char **fragment_shader)
|
||||
struct shader_program
|
||||
{
|
||||
char *vertex;
|
||||
char *fragment;
|
||||
enum filter_type filter;
|
||||
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
unsigned abs_x;
|
||||
unsigned abs_y;
|
||||
enum gl_scale_type type_x;
|
||||
enum gl_scale_type type_y;
|
||||
|
||||
bool valid_scale;
|
||||
};
|
||||
|
||||
static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr)
|
||||
{
|
||||
prog->scale_x = 1.0;
|
||||
prog->scale_y = 1.0;
|
||||
prog->type_x = prog->type_y = SSNES_SCALE_INPUT;
|
||||
prog->valid_scale = false;
|
||||
|
||||
// Check if shader forces a certain texture filtering.
|
||||
xmlChar *attr = xmlGetProp(ptr, (const xmlChar*)"filter");
|
||||
if (attr)
|
||||
{
|
||||
if (strcmp((const char*)attr, "nearest") == 0)
|
||||
{
|
||||
prog->filter = SSNES_GL_NEAREST;
|
||||
SSNES_LOG("XML: Shader forces GL_NEAREST.\n");
|
||||
}
|
||||
else if (strcmp((const char*)attr, "linear") == 0)
|
||||
{
|
||||
prog->filter = SSNES_GL_LINEAR;
|
||||
SSNES_LOG("XML: Shader forces GL_LINEAR.\n");
|
||||
}
|
||||
else
|
||||
SSNES_WARN("XML: Invalid property for filter.\n");
|
||||
|
||||
xmlFree(attr);
|
||||
}
|
||||
else
|
||||
prog->filter = SSNES_GL_NOFORCE;
|
||||
|
||||
// Check for scaling attributes *lots of code <_<*
|
||||
xmlChar *attr_scale = xmlGetProp(ptr, (const xmlChar*)"scale");
|
||||
xmlChar *attr_scale_x = xmlGetProp(ptr, (const xmlChar*)"scale_x");
|
||||
xmlChar *attr_scale_y = xmlGetProp(ptr, (const xmlChar*)"scale_y");
|
||||
xmlChar *attr_size = xmlGetProp(ptr, (const xmlChar*)"size");
|
||||
xmlChar *attr_size_x = xmlGetProp(ptr, (const xmlChar*)"size_x");
|
||||
xmlChar *attr_size_y = xmlGetProp(ptr, (const xmlChar*)"size_y");
|
||||
xmlChar *attr_outscale = xmlGetProp(ptr, (const xmlChar*)"outscale");
|
||||
xmlChar *attr_outscale_x = xmlGetProp(ptr, (const xmlChar*)"outscale_x");
|
||||
xmlChar *attr_outscale_y = xmlGetProp(ptr, (const xmlChar*)"outscale_y");
|
||||
|
||||
unsigned x_attr_cnt = 0, y_attr_cnt = 0;
|
||||
|
||||
if (attr_scale)
|
||||
{
|
||||
float scale = strtod((const char*)attr_scale, NULL);
|
||||
prog->scale_x = scale;
|
||||
prog->scale_y = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = prog->type_y = SSNES_SCALE_INPUT;
|
||||
SSNES_LOG("Got scale attr: %.1f\n", scale);
|
||||
x_attr_cnt++;
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_scale_x)
|
||||
{
|
||||
float scale = strtod((const char*)attr_scale_x, NULL);
|
||||
prog->scale_x = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = SSNES_SCALE_INPUT;
|
||||
SSNES_LOG("Got scale_x attr: %.1f\n", scale);
|
||||
x_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_scale_y)
|
||||
{
|
||||
float scale = strtod((const char*)attr_scale_y, NULL);
|
||||
prog->scale_y = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_y = SSNES_SCALE_INPUT;
|
||||
SSNES_LOG("Got scale_y attr: %.1f\n", scale);
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_size)
|
||||
{
|
||||
prog->abs_x = prog->abs_y = strtoul((const char*)attr_size, NULL, 0);
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = prog->type_y = SSNES_SCALE_ABSOLUTE;
|
||||
SSNES_LOG("Got size attr: %u\n", prog->abs_x);
|
||||
x_attr_cnt++;
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_size_x)
|
||||
{
|
||||
prog->abs_x = strtoul((const char*)attr_size_x, NULL, 0);
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = SSNES_SCALE_ABSOLUTE;
|
||||
SSNES_LOG("Got size_x attr: %u\n", prog->abs_x);
|
||||
x_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_size_y)
|
||||
{
|
||||
prog->abs_y = strtoul((const char*)attr_size_y, NULL, 0);
|
||||
prog->valid_scale = true;
|
||||
prog->type_y = SSNES_SCALE_ABSOLUTE;
|
||||
SSNES_LOG("Got size_y attr: %u\n", prog->abs_y);
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_outscale)
|
||||
{
|
||||
float scale = strtod((const char*)attr_outscale, NULL);
|
||||
prog->scale_x = scale;
|
||||
prog->scale_y = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = prog->type_y = SSNES_SCALE_VIEWPORT;
|
||||
SSNES_LOG("Got outscale attr: %.1f\n", scale);
|
||||
x_attr_cnt++;
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_outscale_x)
|
||||
{
|
||||
float scale = strtod((const char*)attr_outscale_x, NULL);
|
||||
prog->scale_x = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_x = SSNES_SCALE_VIEWPORT;
|
||||
SSNES_LOG("Got outscale_x attr: %.1f\n", scale);
|
||||
x_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_outscale_y)
|
||||
{
|
||||
float scale = strtod((const char*)attr_outscale_y, NULL);
|
||||
prog->scale_y = scale;
|
||||
prog->valid_scale = true;
|
||||
prog->type_y = SSNES_SCALE_VIEWPORT;
|
||||
SSNES_LOG("Got outscale_y attr: %.1f\n", scale);
|
||||
y_attr_cnt++;
|
||||
}
|
||||
|
||||
if (attr_scale)
|
||||
xmlFree(attr_scale);
|
||||
if (attr_scale_x)
|
||||
xmlFree(attr_scale_x);
|
||||
if (attr_scale_y)
|
||||
xmlFree(attr_scale_y);
|
||||
if (attr_size)
|
||||
xmlFree(attr_size);
|
||||
if (attr_size_x)
|
||||
xmlFree(attr_size_x);
|
||||
if (attr_size_y)
|
||||
xmlFree(attr_size_y);
|
||||
if (attr_outscale)
|
||||
xmlFree(attr_outscale);
|
||||
if (attr_outscale_x)
|
||||
xmlFree(attr_outscale_x);
|
||||
if (attr_outscale_y)
|
||||
xmlFree(attr_outscale_y);
|
||||
|
||||
if (x_attr_cnt > 1)
|
||||
return false;
|
||||
if (y_attr_cnt > 1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static unsigned get_xml_shaders(const char *path, struct shader_program *prog, size_t size)
|
||||
{
|
||||
LIBXML_TEST_VERSION;
|
||||
|
||||
@@ -91,18 +305,26 @@ static bool get_xml_shaders(const char *path, char **vertex_shader, char **fragm
|
||||
if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "shader") == 0)
|
||||
{
|
||||
xmlChar *attr;
|
||||
if ((attr = xmlGetProp(cur, (const xmlChar*)"language")) && strcmp((const char*)attr, "GLSL") == 0)
|
||||
attr = xmlGetProp(cur, (const xmlChar*)"language");
|
||||
if (attr && strcmp((const char*)attr, "GLSL") == 0)
|
||||
{
|
||||
xmlFree(attr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (attr)
|
||||
xmlFree(attr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cur) // We couldn't find any GLSL shader :(
|
||||
goto error;
|
||||
|
||||
bool vertex_found = false;
|
||||
bool fragment_found = false;
|
||||
unsigned num = 0;
|
||||
memset(prog, 0, sizeof(struct shader_program) * size);
|
||||
|
||||
// Iterate to check if we find fragment and/or vertex shaders.
|
||||
for (cur = cur->children; cur; cur = cur->next)
|
||||
for (cur = cur->children; cur && num < size; cur = cur->next)
|
||||
{
|
||||
if (cur->type != XML_ELEMENT_NODE)
|
||||
continue;
|
||||
@@ -111,37 +333,45 @@ static bool get_xml_shaders(const char *path, char **vertex_shader, char **fragm
|
||||
if (!content)
|
||||
continue;
|
||||
|
||||
if (strcmp((const char*)cur->name, "vertex") == 0 && !vertex_found)
|
||||
if (strcmp((const char*)cur->name, "vertex") == 0)
|
||||
{
|
||||
*vertex_shader = malloc(xmlStrlen(content) + 1);
|
||||
strcpy(*vertex_shader, (const char*)content);
|
||||
vertex_found = true;
|
||||
if (prog[num].vertex)
|
||||
{
|
||||
SSNES_ERR("Cannot have more than one vertex shader in a program.\n");
|
||||
xmlFree(content);
|
||||
goto error;
|
||||
}
|
||||
|
||||
prog[num].vertex = (char*)content;
|
||||
}
|
||||
else if (strcmp((const char*)cur->name, "fragment") == 0 && !fragment_found)
|
||||
else if (strcmp((const char*)cur->name, "fragment") == 0)
|
||||
{
|
||||
*fragment_shader = malloc(xmlStrlen(content) + 1);
|
||||
strcpy(*fragment_shader, (const char*)content);
|
||||
fragment_found = true;
|
||||
prog[num].fragment = (char*)content;
|
||||
if (!get_xml_attrs(&prog[num], cur))
|
||||
{
|
||||
SSNES_ERR("XML shader attributes do not comply with specifications.\n");
|
||||
goto error;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!vertex_found && !fragment_found)
|
||||
if (num == 0)
|
||||
{
|
||||
SSNES_ERR("Couldn't find vertex shader nor fragment shader in XML file.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
xmlFreeDoc(doc);
|
||||
xmlFreeParserCtxt(ctx);
|
||||
return true;
|
||||
return num;
|
||||
|
||||
error:
|
||||
SSNES_ERR("Failed to load XML shader ...\n");
|
||||
if (doc)
|
||||
xmlFreeDoc(doc);
|
||||
xmlFreeParserCtxt(ctx);
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_shader_log(GLuint obj)
|
||||
@@ -172,33 +402,114 @@ static void print_linker_log(GLuint obj)
|
||||
SSNES_LOG("Linker log: %s\n", info_log);
|
||||
}
|
||||
|
||||
static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size_t num)
|
||||
{
|
||||
for (unsigned i = 0; i < num; i++)
|
||||
{
|
||||
gl_prog[i] = pglCreateProgram();
|
||||
|
||||
if (!gl_check_error() || gl_prog[i] == 0)
|
||||
{
|
||||
SSNES_ERR("Failed to create GL program #%u.\n", i);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progs[i].vertex)
|
||||
{
|
||||
SSNES_LOG("Found GLSL vertex shader.\n");
|
||||
GLuint shader = pglCreateShader(GL_VERTEX_SHADER);
|
||||
pglShaderSource(shader, 1, (const char**)&progs[i].vertex, 0);
|
||||
pglCompileShader(shader);
|
||||
print_shader_log(shader);
|
||||
|
||||
pglAttachShader(gl_prog[i], shader);
|
||||
free(progs[i].vertex);
|
||||
}
|
||||
|
||||
if (!gl_check_error())
|
||||
{
|
||||
SSNES_ERR("Failed to compile vertex shader #%u\n", i);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progs[i].fragment)
|
||||
{
|
||||
SSNES_LOG("Found GLSL fragment shader.\n");
|
||||
GLuint shader = pglCreateShader(GL_FRAGMENT_SHADER);
|
||||
pglShaderSource(shader, 1, (const char**)&progs[i].fragment, 0);
|
||||
pglCompileShader(shader);
|
||||
print_shader_log(shader);
|
||||
|
||||
pglAttachShader(gl_prog[i], shader);
|
||||
free(progs[i].fragment);
|
||||
}
|
||||
|
||||
if (!gl_check_error())
|
||||
{
|
||||
SSNES_ERR("Failed to compile fragment shader #%u\n", i);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progs[i].vertex || progs[i].fragment)
|
||||
{
|
||||
SSNES_LOG("Linking GLSL program.\n");
|
||||
pglLinkProgram(gl_prog[i]);
|
||||
pglUseProgram(gl_prog[i]);
|
||||
print_linker_log(gl_prog[i]);
|
||||
|
||||
GLint location = pglGetUniformLocation(gl_prog[i], "rubyTexture");
|
||||
pglUniform1i(location, 0);
|
||||
pglUseProgram(0);
|
||||
}
|
||||
|
||||
if (!gl_check_error())
|
||||
{
|
||||
SSNES_ERR("Failed to link program #%u\n", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define LOAD_GL_SYM(SYM) if (!(pgl##SYM)) pgl##SYM = SDL_GL_GetProcAddress("gl" #SYM)
|
||||
|
||||
bool gl_glsl_init(const char *path)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
// Load shader functions.
|
||||
pglCreateProgram = SDL_GL_GetProcAddress("glCreateProgram");
|
||||
pglUseProgram = SDL_GL_GetProcAddress("glUseProgram");
|
||||
pglCreateShader = SDL_GL_GetProcAddress("glCreateShader");
|
||||
pglDeleteShader = SDL_GL_GetProcAddress("glDeleteShader");
|
||||
pglShaderSource = SDL_GL_GetProcAddress("glShaderSource");
|
||||
pglCompileShader = SDL_GL_GetProcAddress("glCompileShader");
|
||||
pglAttachShader = SDL_GL_GetProcAddress("glAttachShader");
|
||||
pglDetachShader = SDL_GL_GetProcAddress("glDetachShader");
|
||||
pglLinkProgram = SDL_GL_GetProcAddress("glLinkProgram");
|
||||
pglGetUniformLocation = SDL_GL_GetProcAddress("glGetUniformLocation");
|
||||
pglUniform1i = SDL_GL_GetProcAddress("glUniform1i");
|
||||
pglUniform2fv = SDL_GL_GetProcAddress("glUniform2fv");
|
||||
pglUniform4fv = SDL_GL_GetProcAddress("glUniform4fv");
|
||||
pglGetShaderiv = SDL_GL_GetProcAddress("glGetShaderiv");
|
||||
pglGetShaderInfoLog = SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
||||
pglGetProgramiv = SDL_GL_GetProcAddress("glGetProgramiv");
|
||||
pglGetProgramInfoLog = SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||
LOAD_GL_SYM(CreateProgram);
|
||||
LOAD_GL_SYM(UseProgram);
|
||||
LOAD_GL_SYM(CreateShader);
|
||||
LOAD_GL_SYM(DeleteShader);
|
||||
LOAD_GL_SYM(ShaderSource);
|
||||
LOAD_GL_SYM(CompileShader);
|
||||
LOAD_GL_SYM(AttachShader);
|
||||
LOAD_GL_SYM(DetachShader);
|
||||
LOAD_GL_SYM(LinkProgram);
|
||||
LOAD_GL_SYM(GetUniformLocation);
|
||||
LOAD_GL_SYM(Uniform1i);
|
||||
LOAD_GL_SYM(Uniform2fv);
|
||||
LOAD_GL_SYM(Uniform4fv);
|
||||
LOAD_GL_SYM(GetShaderiv);
|
||||
LOAD_GL_SYM(GetShaderInfoLog);
|
||||
LOAD_GL_SYM(GetProgramiv);
|
||||
LOAD_GL_SYM(GetProgramInfoLog);
|
||||
LOAD_GL_SYM(DeleteProgram);
|
||||
LOAD_GL_SYM(GetAttachedShaders);
|
||||
#endif
|
||||
|
||||
SSNES_LOG("Checking GLSL shader support ...\n");
|
||||
#ifdef __APPLE__
|
||||
const bool shader_support = true;
|
||||
#else
|
||||
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
|
||||
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
|
||||
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
|
||||
&& pglUniform1i && pglUniform2fv && pglUniform4fv
|
||||
&& pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog;
|
||||
&& pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog
|
||||
&& pglDeleteProgram && pglGetAttachedShaders;
|
||||
#endif
|
||||
|
||||
if (!shader_support)
|
||||
{
|
||||
@@ -206,88 +517,149 @@ bool gl_glsl_init(const char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
gl_program = pglCreateProgram();
|
||||
struct shader_program progs[MAX_PROGRAMS];
|
||||
unsigned num_progs = get_xml_shaders(path, progs, MAX_PROGRAMS - 1);
|
||||
|
||||
char *vertex_prog = NULL;
|
||||
char *fragment_prog = NULL;
|
||||
if (!get_xml_shaders(path, &vertex_prog, &fragment_prog))
|
||||
if (num_progs == 0)
|
||||
{
|
||||
SSNES_ERR("Couldn't find any valid shaders in XML file.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < num_progs; i++)
|
||||
{
|
||||
gl_filter_type[i + 1] = progs[i].filter;
|
||||
gl_scale[i + 1].type_x = progs[i].type_x;
|
||||
gl_scale[i + 1].type_y = progs[i].type_y;
|
||||
gl_scale[i + 1].scale_x = progs[i].scale_x;
|
||||
gl_scale[i + 1].scale_y = progs[i].scale_y;
|
||||
gl_scale[i + 1].abs_x = progs[i].abs_x;
|
||||
gl_scale[i + 1].abs_y = progs[i].abs_y;
|
||||
gl_scale[i + 1].valid = progs[i].valid_scale;
|
||||
}
|
||||
|
||||
if (!compile_programs(&gl_program[1], progs, num_progs))
|
||||
return false;
|
||||
|
||||
if (vertex_prog)
|
||||
// SSNES custom two-pass with two different files.
|
||||
if (num_progs == 1 && *g_settings.video.second_pass_shader)
|
||||
{
|
||||
vertex_shader = pglCreateShader(GL_VERTEX_SHADER);
|
||||
pglShaderSource(vertex_shader, 1, (const char**)&vertex_prog, 0);
|
||||
pglCompileShader(vertex_shader);
|
||||
print_shader_log(vertex_shader);
|
||||
|
||||
pglAttachShader(gl_program, vertex_shader);
|
||||
free(vertex_prog);
|
||||
}
|
||||
if (fragment_prog)
|
||||
{
|
||||
fragment_shader = pglCreateShader(GL_FRAGMENT_SHADER);
|
||||
pglShaderSource(fragment_shader, 1, (const char**)&fragment_prog, 0);
|
||||
pglCompileShader(fragment_shader);
|
||||
print_shader_log(fragment_shader);
|
||||
|
||||
pglAttachShader(gl_program, fragment_shader);
|
||||
free(fragment_prog);
|
||||
}
|
||||
|
||||
if (vertex_prog || fragment_prog)
|
||||
{
|
||||
pglLinkProgram(gl_program);
|
||||
pglUseProgram(gl_program);
|
||||
print_linker_log(gl_program);
|
||||
|
||||
GLint location = pglGetUniformLocation(gl_program, "rubyTexture");
|
||||
pglUniform1i(location, 0);
|
||||
unsigned secondary_progs = get_xml_shaders(g_settings.video.second_pass_shader, progs, 1);
|
||||
if (secondary_progs == 1)
|
||||
{
|
||||
compile_programs(&gl_program[2], progs, 1);
|
||||
num_progs++;
|
||||
}
|
||||
else
|
||||
{
|
||||
SSNES_ERR("Did not find valid shader in secondary shader file.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gl_check_error())
|
||||
return false;
|
||||
|
||||
glsl_enable = true;
|
||||
gl_num_programs = num_progs;
|
||||
return true;
|
||||
}
|
||||
|
||||
void gl_glsl_deinit(void)
|
||||
{}
|
||||
{
|
||||
if (glsl_enable)
|
||||
{
|
||||
pglUseProgram(0);
|
||||
for (int i = 1; i < MAX_PROGRAMS; i++)
|
||||
{
|
||||
if (gl_program[i] == 0)
|
||||
break;
|
||||
|
||||
GLsizei count;
|
||||
GLuint shaders[2];
|
||||
|
||||
pglGetAttachedShaders(gl_program[i], 2, &count, shaders);
|
||||
for (GLsizei j = 0; j < count; j++)
|
||||
{
|
||||
pglDetachShader(gl_program[i], shaders[j]);
|
||||
pglDeleteShader(shaders[j]);
|
||||
}
|
||||
|
||||
pglDeleteProgram(gl_program[i]);
|
||||
}
|
||||
}
|
||||
|
||||
memset(gl_program, 0, sizeof(gl_program));
|
||||
glsl_enable = false;
|
||||
active_index = 0;
|
||||
}
|
||||
|
||||
void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
unsigned tex_width, unsigned tex_height,
|
||||
unsigned out_width, unsigned out_height)
|
||||
{
|
||||
if (glsl_enable)
|
||||
if (glsl_enable && gl_program[active_index] > 0)
|
||||
{
|
||||
GLint location;
|
||||
|
||||
float inputSize[2] = {width, height};
|
||||
location = pglGetUniformLocation(gl_program, "rubyInputSize");
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyInputSize");
|
||||
pglUniform2fv(location, 1, inputSize);
|
||||
|
||||
float outputSize[2] = {out_width, out_height};
|
||||
location = pglGetUniformLocation(gl_program, "rubyOutputSize");
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyOutputSize");
|
||||
pglUniform2fv(location, 1, outputSize);
|
||||
|
||||
float textureSize[2] = {tex_width, tex_height};
|
||||
location = pglGetUniformLocation(gl_program, "rubyTextureSize");
|
||||
location = pglGetUniformLocation(gl_program[active_index], "rubyTextureSize");
|
||||
pglUniform2fv(location, 1, textureSize);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void gl_glsl_set_proj_matrix(void)
|
||||
{}
|
||||
|
||||
void gl_glsl_activate(void)
|
||||
void gl_glsl_use(unsigned index)
|
||||
{
|
||||
if (glsl_enable)
|
||||
pglUseProgram(gl_program);
|
||||
{
|
||||
active_index = index;
|
||||
pglUseProgram(gl_program[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void gl_glsl_deactivate(void)
|
||||
unsigned gl_glsl_num(void)
|
||||
{
|
||||
return gl_num_programs;
|
||||
}
|
||||
|
||||
bool gl_glsl_filter_type(unsigned index, bool *smooth)
|
||||
{
|
||||
if (!glsl_enable)
|
||||
return false;
|
||||
|
||||
switch (gl_filter_type[index])
|
||||
{
|
||||
case SSNES_GL_NOFORCE:
|
||||
return false;
|
||||
|
||||
case SSNES_GL_NEAREST:
|
||||
*smooth = false;
|
||||
return true;
|
||||
|
||||
case SSNES_GL_LINEAR:
|
||||
*smooth = true;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void gl_glsl_shader_scale(unsigned index, struct gl_fbo_scale *scale)
|
||||
{
|
||||
if (glsl_enable)
|
||||
pglUseProgram(0);
|
||||
*scale = gl_scale[index];
|
||||
else
|
||||
scale->valid = false;
|
||||
}
|
||||
+7
-2
@@ -20,6 +20,7 @@
|
||||
#define __SSNES_GLSL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "gl_common.h"
|
||||
|
||||
bool gl_glsl_init(const char *path);
|
||||
|
||||
@@ -31,7 +32,11 @@ void gl_glsl_set_params(unsigned width, unsigned height,
|
||||
unsigned tex_width, unsigned tex_height,
|
||||
unsigned out_width, unsigned out_height);
|
||||
|
||||
void gl_glsl_activate(void);
|
||||
void gl_glsl_deactivate(void);
|
||||
void gl_glsl_use(unsigned index);
|
||||
|
||||
unsigned gl_glsl_num(void);
|
||||
|
||||
bool gl_glsl_filter_type(unsigned index, bool *smooth);
|
||||
void gl_glsl_shader_scale(unsigned index, struct gl_fbo_scale *scale);
|
||||
|
||||
#endif
|
||||
+724
@@ -0,0 +1,724 @@
|
||||
/* 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 "general.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <math.h>
|
||||
#ifdef HAVE_FREETYPE
|
||||
#include "fonts.h"
|
||||
#endif
|
||||
#include "gfx_common.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <X11/extensions/Xv.h>
|
||||
#include <X11/extensions/Xvlib.h>
|
||||
|
||||
// Adapted from bSNES and MPlayer source.
|
||||
|
||||
typedef struct xv xv_t;
|
||||
struct xv
|
||||
{
|
||||
Display *display;
|
||||
GC gc;
|
||||
Window window;
|
||||
Colormap colormap;
|
||||
XShmSegmentInfo shminfo;
|
||||
|
||||
Atom quit_atom;
|
||||
bool focus;
|
||||
|
||||
XvPortID port;
|
||||
int depth;
|
||||
int visualid;
|
||||
|
||||
XvImage *image;
|
||||
uint32_t fourcc;
|
||||
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool keep_aspect;
|
||||
|
||||
uint8_t *ytable;
|
||||
uint8_t *utable;
|
||||
uint8_t *vtable;
|
||||
unsigned luma_i;
|
||||
unsigned chroma_i;
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
font_renderer_t *font;
|
||||
#endif
|
||||
|
||||
void (*render_func)(xv_t*, const void *frame, unsigned width, unsigned height, unsigned pitch);
|
||||
};
|
||||
|
||||
static void xv_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
xv_t *xv = data;
|
||||
Atom atom = XInternAtom(xv->display, "XV_SYNC_TO_VBLANK", true);
|
||||
if (atom != None && xv->port >= 0)
|
||||
XvSetPortAttribute(xv->display, xv->port, atom, !state);
|
||||
else
|
||||
SSNES_WARN("Failed to set SYNC_TO_VBLANK attribute.\n");
|
||||
}
|
||||
|
||||
static volatile sig_atomic_t g_quit = 0;
|
||||
static void sighandler(int sig)
|
||||
{
|
||||
g_quit = 1;
|
||||
}
|
||||
|
||||
static void init_yuv_tables(xv_t *xv)
|
||||
{
|
||||
xv->ytable = malloc(0x8000);
|
||||
xv->utable = malloc(0x8000);
|
||||
xv->vtable = malloc(0x8000);
|
||||
|
||||
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
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Source: MPlayer
|
||||
static void hide_mouse(xv_t *xv)
|
||||
{
|
||||
Cursor no_ptr;
|
||||
Pixmap bm_no;
|
||||
XColor black, dummy;
|
||||
Colormap colormap;
|
||||
static char bm_no_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
colormap = DefaultColormap(xv->display, DefaultScreen(xv->display));
|
||||
if (!XAllocNamedColor(xv->display, colormap, "black", &black, &dummy))
|
||||
return;
|
||||
|
||||
bm_no = XCreateBitmapFromData(xv->display, xv->window, bm_no_data, 8, 8);
|
||||
no_ptr = XCreatePixmapCursor(xv->display, bm_no, bm_no, &black, &black, 0, 0);
|
||||
XDefineCursor(xv->display, xv->window, no_ptr);
|
||||
XFreeCursor(xv->display, no_ptr);
|
||||
if (bm_no != None)
|
||||
XFreePixmap(xv->display, bm_no);
|
||||
XFreeColors(xv->display, colormap, &black.pixel, 1, 0);
|
||||
}
|
||||
|
||||
static Atom XA_NET_WM_STATE;
|
||||
static Atom XA_NET_WM_STATE_FULLSCREEN;
|
||||
#define XA_INIT(x) XA##x = XInternAtom(xv->display, #x, False)
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
|
||||
// Source: MPlayer
|
||||
static void set_fullscreen(xv_t *xv)
|
||||
{
|
||||
XA_INIT(_NET_WM_STATE);
|
||||
XA_INIT(_NET_WM_STATE_FULLSCREEN);
|
||||
|
||||
if (!XA_NET_WM_STATE || !XA_NET_WM_STATE_FULLSCREEN)
|
||||
{
|
||||
SSNES_WARN("X11: Cannot set fullscreen.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
XEvent xev;
|
||||
|
||||
xev.xclient.type = ClientMessage;
|
||||
xev.xclient.serial = 0;
|
||||
xev.xclient.send_event = True;
|
||||
xev.xclient.message_type = XA_NET_WM_STATE;
|
||||
xev.xclient.window = xv->window;
|
||||
xev.xclient.format = 32;
|
||||
xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
|
||||
xev.xclient.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
|
||||
xev.xclient.data.l[2] = 0;
|
||||
xev.xclient.data.l[3] = 0;
|
||||
xev.xclient.data.l[4] = 0;
|
||||
|
||||
XSendEvent(xv->display, DefaultRootWindow(xv->display), False,
|
||||
SubstructureRedirectMask | SubstructureNotifyMask,
|
||||
&xev);
|
||||
}
|
||||
|
||||
static void xv_init_font(xv_t *xv, const char *font_path, unsigned font_size)
|
||||
{
|
||||
#ifdef HAVE_FREETYPE
|
||||
if (*font_path)
|
||||
{
|
||||
xv->font = font_renderer_new(font_path, font_size);
|
||||
if (!xv->font)
|
||||
SSNES_WARN("Failed to init font\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// We render @ 2x scale to combat chroma downsampling. Also makes fonts more bearable :)
|
||||
static void render16_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
|
||||
{
|
||||
const uint16_t *input = input_;
|
||||
uint8_t *output = (uint8_t*)xv->image->data;
|
||||
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
for (unsigned x = 0; x < width; x++)
|
||||
{
|
||||
uint16_t p = *input++;
|
||||
|
||||
uint8_t y0 = xv->ytable[p];
|
||||
uint8_t u = xv->utable[p];
|
||||
uint8_t v = xv->vtable[p];
|
||||
|
||||
unsigned img_width = xv->width << 1;
|
||||
output[0] = output[img_width] = y0;
|
||||
output[1] = output[img_width + 1] = u;
|
||||
output[2] = output[img_width + 2] = y0;
|
||||
output[3] = output[img_width + 3] = v;
|
||||
output += 4;
|
||||
}
|
||||
|
||||
input += (pitch >> 1) - width;
|
||||
output += (xv->width - width) << 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void render16_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
|
||||
{
|
||||
const uint16_t *input = input_;
|
||||
uint8_t *output = (uint8_t*)xv->image->data;
|
||||
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
for (unsigned x = 0; x < width; x++)
|
||||
{
|
||||
uint16_t p = *input++;
|
||||
|
||||
uint8_t y0 = xv->ytable[p];
|
||||
uint8_t u = xv->utable[p];
|
||||
uint8_t v = xv->vtable[p];
|
||||
|
||||
unsigned img_width = xv->width << 1;
|
||||
output[0] = output[img_width] = u;
|
||||
output[1] = output[img_width + 1] = y0;
|
||||
output[2] = output[img_width + 2] = v;
|
||||
output[3] = output[img_width + 3] = y0;
|
||||
output += 4;
|
||||
}
|
||||
|
||||
input += (pitch >> 1) - width;
|
||||
output += (xv->width - width) << 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
|
||||
{
|
||||
const uint32_t *input = input_;
|
||||
uint8_t *output = (uint8_t*)xv->image->data;
|
||||
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
for (unsigned x = 0; x < width; x++)
|
||||
{
|
||||
uint32_t p = *input++;
|
||||
p = ((p >> 17) & 0x7c00) | ((p >> 14) & 0x03e0) | ((p >> 11) & 0x1f); // RGBA -> RGB15
|
||||
|
||||
uint8_t y0 = xv->ytable[p];
|
||||
uint8_t u = xv->utable[p];
|
||||
uint8_t v = xv->vtable[p];
|
||||
|
||||
unsigned img_width = xv->width << 1;
|
||||
output[0] = output[img_width] = y0;
|
||||
output[1] = output[img_width + 1] = u;
|
||||
output[2] = output[img_width + 2] = y0;
|
||||
output[3] = output[img_width + 3] = v;
|
||||
output += 4;
|
||||
}
|
||||
|
||||
input += (pitch >> 2) - width;
|
||||
output += (xv->width - width) << 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
|
||||
{
|
||||
const uint32_t *input = input_;
|
||||
uint16_t *output = (uint16_t*)xv->image->data;
|
||||
|
||||
for (unsigned y = 0; y < height; y++)
|
||||
{
|
||||
for (unsigned x = 0; x < width; x++)
|
||||
{
|
||||
uint32_t p = *input++;
|
||||
p = ((p >> 17) & 0x7c00) | ((p >> 14) & 0x03e0) | ((p >> 11) & 0x1f); // RGBA -> RGB15
|
||||
|
||||
uint8_t y0 = xv->ytable[p];
|
||||
uint8_t u = xv->utable[p];
|
||||
uint8_t v = xv->vtable[p];
|
||||
|
||||
unsigned img_width = xv->width << 1;
|
||||
output[0] = output[img_width] = u;
|
||||
output[1] = output[img_width + 1] = y0;
|
||||
output[2] = output[img_width + 2] = v;
|
||||
output[3] = output[img_width + 3] = y0;
|
||||
output += 4;
|
||||
}
|
||||
|
||||
input += (pitch >> 2) - width;
|
||||
output += (xv->width - width) << 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void* xv_init(video_info_t *video, const input_driver_t **input, void **input_data)
|
||||
{
|
||||
xv_t *xv = calloc(1, sizeof(*xv));
|
||||
if (!xv)
|
||||
return NULL;
|
||||
|
||||
xv->display = XOpenDisplay(NULL);
|
||||
|
||||
if (!XShmQueryExtension(xv->display))
|
||||
{
|
||||
SSNES_ERR("XVideo: XShm extension not found.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
xv->keep_aspect = video->force_aspect;
|
||||
|
||||
// Find an appropriate Xv port.
|
||||
xv->port = -1;
|
||||
XvAdaptorInfo *adaptor_info;
|
||||
unsigned adaptor_count = 0;
|
||||
XvQueryAdaptors(xv->display, DefaultRootWindow(xv->display), &adaptor_count, &adaptor_info);
|
||||
for (unsigned i = 0; i < adaptor_count; i++)
|
||||
{
|
||||
// Find adaptor that supports both input (memory->drawable) and image (drawable->screen) masks.
|
||||
if (adaptor_info[i].num_formats < 1) continue;
|
||||
if (!(adaptor_info[i].type & XvInputMask)) continue;
|
||||
if (!(adaptor_info[i].type & XvImageMask)) continue;
|
||||
|
||||
xv->port = adaptor_info[i].base_id;
|
||||
xv->depth = adaptor_info[i].formats->depth;
|
||||
xv->visualid = adaptor_info[i].formats->visual_id;
|
||||
break;
|
||||
}
|
||||
XvFreeAdaptorInfo(adaptor_info);
|
||||
|
||||
if (xv->port < 0)
|
||||
{
|
||||
SSNES_ERR("XVideo: Failed to find valid XvPort.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
XVisualInfo visualtemplate;
|
||||
visualtemplate.visualid = xv->visualid;
|
||||
visualtemplate.screen = DefaultScreen(xv->display);
|
||||
visualtemplate.depth = xv->depth;
|
||||
visualtemplate.visual = 0;
|
||||
int visualmatches = 0;
|
||||
XVisualInfo *visualinfo = XGetVisualInfo(xv->display, VisualIDMask | VisualScreenMask | VisualDepthMask, &visualtemplate, &visualmatches);
|
||||
if (visualmatches < 1 || !visualinfo->visual)
|
||||
{
|
||||
if (visualinfo) XFree(visualinfo);
|
||||
SSNES_ERR("XVideo: Unable to find Xv-compatible visual.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
xv->colormap = XCreateColormap(xv->display, DefaultRootWindow(xv->display), visualinfo->visual, AllocNone);
|
||||
XSetWindowAttributes attributes;
|
||||
attributes.colormap = xv->colormap;
|
||||
attributes.border_pixel = 0;
|
||||
attributes.event_mask = StructureNotifyMask | DestroyNotify | ClientMessage;
|
||||
|
||||
unsigned width = video->fullscreen ? ((video->width == 0) ? 256 : video->width) : video->width;
|
||||
unsigned height = video->fullscreen ? ((video->height == 0) ? 224 : video->height) : video->height;
|
||||
xv->window = XCreateWindow(xv->display, DefaultRootWindow(xv->display),
|
||||
0, 0, width, height,
|
||||
0, xv->depth, InputOutput, visualinfo->visual,
|
||||
CWColormap | CWBorderPixel | CWEventMask, &attributes);
|
||||
|
||||
XFree(visualinfo);
|
||||
XSetWindowBackground(xv->display, xv->window, 0);
|
||||
|
||||
XMapWindow(xv->display, xv->window);
|
||||
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
XStoreName(xv->display, xv->window, buf);
|
||||
|
||||
if (video->fullscreen)
|
||||
set_fullscreen(xv);
|
||||
hide_mouse(xv);
|
||||
|
||||
xv->gc = XCreateGC(xv->display, xv->window, 0, 0);
|
||||
|
||||
// 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);
|
||||
|
||||
int format_count;
|
||||
XvImageFormatValues *format = XvListImageFormats(xv->display, xv->port, &format_count);
|
||||
|
||||
bool has_format = false;
|
||||
for (int i = 0; i < format_count; i++)
|
||||
{
|
||||
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
|
||||
{
|
||||
if (format[i].component_order[0] == 'Y' && format[i].component_order[1] == 'U'
|
||||
&& format[i].component_order[2] == 'Y' && format[i].component_order[3] == 'V')
|
||||
{
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_format) for (int i = 0; i < format_count; i++)
|
||||
{
|
||||
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
|
||||
{
|
||||
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;
|
||||
xv->chroma_i = 0; xv->luma_i = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(format);
|
||||
if (!has_format)
|
||||
{
|
||||
SSNES_ERR("XVideo: unable to find a supported image format.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
xv->width = 512;
|
||||
xv->height = 512;
|
||||
|
||||
xv->image = XvShmCreateImage(xv->display, xv->port, xv->fourcc, NULL, xv->width, xv->height, &xv->shminfo);
|
||||
if (!xv->image)
|
||||
{
|
||||
SSNES_ERR("XVideo: XShmCreateImage failed.\n");
|
||||
goto error;
|
||||
}
|
||||
xv->width = xv->image->width;
|
||||
xv->height = xv->image->height;
|
||||
|
||||
xv->shminfo.shmid = shmget(IPC_PRIVATE, xv->image->data_size, IPC_CREAT | 0777);
|
||||
xv->shminfo.shmaddr = xv->image->data = shmat(xv->shminfo.shmid, NULL, 0);
|
||||
xv->shminfo.readOnly = false;
|
||||
if (!XShmAttach(xv->display, &xv->shminfo))
|
||||
{
|
||||
SSNES_ERR("XVideo: XShmAttach failed.\n");
|
||||
goto error;
|
||||
}
|
||||
XSync(xv->display, False);
|
||||
memset(xv->image->data, 128, xv->image->data_size);
|
||||
|
||||
xv->quit_atom = XInternAtom(xv->display, "WM_DELETE_WINDOW", False);
|
||||
if (xv->quit_atom)
|
||||
XSetWMProtocols(xv->display, xv->window, &xv->quit_atom, 1);
|
||||
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = sighandler;
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
sigaction(SIGTERM, &sa, NULL);
|
||||
|
||||
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)
|
||||
{
|
||||
*input = &input_x;
|
||||
*input_data = xinput;
|
||||
}
|
||||
else
|
||||
*input = NULL;
|
||||
|
||||
init_yuv_tables(xv);
|
||||
return xv;
|
||||
|
||||
error:
|
||||
free(xv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool check_resize(xv_t *xv, unsigned width, unsigned height)
|
||||
{
|
||||
// We render @ 2x scale to combat chroma downsampling.
|
||||
if (xv->width != (width << 1) || xv->height != (height << 1))
|
||||
{
|
||||
xv->width = width << 1;
|
||||
xv->height = height << 1;
|
||||
|
||||
XShmDetach(xv->display, &xv->shminfo);
|
||||
shmdt(xv->shminfo.shmaddr);
|
||||
shmctl(xv->shminfo.shmid, IPC_RMID, NULL);
|
||||
XFree(xv->image);
|
||||
|
||||
memset(&xv->shminfo, 0, sizeof(xv->shminfo));
|
||||
xv->image = XvShmCreateImage(xv->display, xv->port, xv->fourcc, NULL, xv->width, xv->height, &xv->shminfo);
|
||||
if (xv->image == None)
|
||||
{
|
||||
SSNES_ERR("Failed to create image.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
xv->width = xv->image->width;
|
||||
xv->height = xv->image->height;
|
||||
|
||||
xv->shminfo.shmid = shmget(IPC_PRIVATE, xv->image->data_size, IPC_CREAT | 0777);
|
||||
if (xv->shminfo.shmid < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to init SHM.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
xv->shminfo.shmaddr = xv->image->data = shmat(xv->shminfo.shmid, NULL, 0);
|
||||
xv->shminfo.readOnly = false;
|
||||
|
||||
if (!XShmAttach(xv->display, &xv->shminfo))
|
||||
{
|
||||
SSNES_ERR("Failed to reattch XvShm image.\n");
|
||||
return false;
|
||||
}
|
||||
XSync(xv->display, False);
|
||||
memset(xv->image->data, 128, xv->image->data_size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void calc_out_rect(bool keep_aspect, unsigned *x, unsigned *y, unsigned *width, unsigned *height, unsigned vp_width, unsigned vp_height)
|
||||
{
|
||||
if (!keep_aspect)
|
||||
{
|
||||
*x = 0; *y = 0; *width = vp_width; *height = vp_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
float desired_aspect = g_settings.video.aspect_ratio;
|
||||
float device_aspect = (float)vp_width / vp_height;
|
||||
|
||||
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
||||
// assume they are actually equal.
|
||||
if (fabs(device_aspect - desired_aspect) < 0.0001)
|
||||
{
|
||||
*x = 0; *y = 0; *width = vp_width; *height = vp_height;
|
||||
}
|
||||
else if (device_aspect > desired_aspect)
|
||||
{
|
||||
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
||||
*x = vp_width * (0.5 - delta); *y = 0; *width = 2.0 * vp_width * delta; *height = vp_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
||||
*x = 0; *y = vp_height * (0.5 - delta); *width = vp_width; *height = 2.0 * vp_height * delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Is there some way to render directly like GL? :(
|
||||
static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned height)
|
||||
{
|
||||
#ifdef HAVE_FREETYPE
|
||||
if (!xv->font)
|
||||
return;
|
||||
|
||||
struct font_output_list out;
|
||||
font_renderer_msg(xv->font, msg, &out);
|
||||
struct font_output *head = out.head;
|
||||
|
||||
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;
|
||||
|
||||
while (head)
|
||||
{
|
||||
int base_x = _base_x + head->off_x;
|
||||
int base_y = _base_y - head->off_y;
|
||||
if (base_y >= 0)
|
||||
{
|
||||
for (int y = 0; y < head->height && (base_y + y) < height; y++)
|
||||
{
|
||||
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);
|
||||
|
||||
for (int x = 0; x < (head->width << 1) && (base_x + x) < width; x += 2)
|
||||
{
|
||||
// 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;
|
||||
|
||||
// Blend chroma
|
||||
blended = (128 * blend + ((256 - blend) * (unsigned)out[x + chroma_i])) >> 8;
|
||||
blended = blended > 255 ? 255 : blended;
|
||||
out[x + chroma_i] = blended;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
head = head->next;
|
||||
}
|
||||
|
||||
font_renderer_free_output(&out);
|
||||
#else
|
||||
(void)xv;
|
||||
(void)msg;
|
||||
(void)width;
|
||||
(void)height;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool xv_frame(void *data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
|
||||
{
|
||||
xv_t *xv = data;
|
||||
|
||||
if (!check_resize(xv, width, height))
|
||||
return false;
|
||||
|
||||
XWindowAttributes target;
|
||||
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);
|
||||
XvShmPutImage(xv->display, xv->port, xv->window, xv->gc, xv->image,
|
||||
0, 0, width << 1, height << 1,
|
||||
x, y, owidth, oheight,
|
||||
true);
|
||||
XSync(xv->display, False);
|
||||
|
||||
char buf[128];
|
||||
if (gfx_window_title(buf, sizeof(buf)))
|
||||
XStoreName(xv->display, xv->window, buf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool xv_alive(void *data)
|
||||
{
|
||||
xv_t *xv = data;
|
||||
|
||||
XEvent event;
|
||||
while (XPending(xv->display))
|
||||
{
|
||||
XNextEvent(xv->display, &event);
|
||||
switch (event.type)
|
||||
{
|
||||
case ClientMessage:
|
||||
if (event.xclient.data.l[0] == xv->quit_atom)
|
||||
return false;
|
||||
break;
|
||||
case DestroyNotify:
|
||||
return false;
|
||||
case MapNotify: // Find something that works better.
|
||||
xv->focus = true;
|
||||
break;
|
||||
case UnmapNotify:
|
||||
xv->focus = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return !g_quit;
|
||||
}
|
||||
|
||||
static bool xv_focus(void *data)
|
||||
{
|
||||
xv_t *xv = data;
|
||||
return xv->focus;
|
||||
}
|
||||
|
||||
|
||||
static void xv_free(void *data)
|
||||
{
|
||||
xv_t *xv = data;
|
||||
XShmDetach(xv->display, &xv->shminfo);
|
||||
shmdt(xv->shminfo.shmaddr);
|
||||
shmctl(xv->shminfo.shmid, IPC_RMID, NULL);
|
||||
XFree(xv->image);
|
||||
|
||||
if(xv->window)
|
||||
XUnmapWindow(xv->display, xv->window);
|
||||
if(xv->colormap)
|
||||
XFreeColormap(xv->display, xv->colormap);
|
||||
|
||||
XCloseDisplay(xv->display);
|
||||
|
||||
free(xv->ytable);
|
||||
free(xv->utable);
|
||||
free(xv->vtable);
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
if (xv->font)
|
||||
font_renderer_free(xv->font);
|
||||
#endif
|
||||
|
||||
free(xv);
|
||||
}
|
||||
|
||||
const video_driver_t video_xvideo = {
|
||||
.init = xv_init,
|
||||
.frame = xv_frame,
|
||||
.alive = xv_alive,
|
||||
.set_nonblock_state = xv_set_nonblock_state,
|
||||
.focus = xv_focus,
|
||||
.free = xv_free,
|
||||
.ident = "xvideo"
|
||||
};
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "bleed.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void bleed_filter(uint16_t *data, int width, int height)
|
||||
{
|
||||
uint16_t tmp[4];
|
||||
int ptr = 0;
|
||||
uint16_t r[4];
|
||||
uint16_t g[4];
|
||||
uint16_t b[4];
|
||||
uint16_t bleed_r;
|
||||
uint16_t bleed_g;
|
||||
uint16_t bleed_b;
|
||||
float rand_map[4];
|
||||
|
||||
for (int h = 0; h < height; h++ )
|
||||
{
|
||||
memcpy(tmp, data, sizeof(tmp));
|
||||
ptr = 3;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rand_map[i] = (rand() % 20)/1000.0; // 0.02 * 4 = 0.08
|
||||
}
|
||||
|
||||
for (int i = 3; i < width; i++, ptr++)
|
||||
{
|
||||
tmp[ptr & 0x3] = data[i];
|
||||
for (int y = 0; y < 4; y++)
|
||||
{
|
||||
r[y] = (tmp[(ptr + y) & 0x3] >> 10) & 0x1F;
|
||||
g[y] = (tmp[(ptr + y) & 0x3] >> 5) & 0x1F;
|
||||
b[y] = (tmp[(ptr + y) & 0x3] >> 0) & 0x1F;
|
||||
}
|
||||
|
||||
bleed_r = r[0] * (0.05 + rand_map[0] ) + r[1] * (0.10 + rand_map[1] ) + r[2] * (0.20 + rand_map[2]) + r[3] * (0.57 + rand_map[3] ); // 0.92
|
||||
bleed_g = g[0] * (0.03 + rand_map[2]/3) + g[1] * (0.10 + rand_map[0]/3) + g[2] * (0.20 + rand_map[3]/3) + g[3] * (0.63 + rand_map[1]/3); // 0.96
|
||||
bleed_b = b[0] * (0.05 + rand_map[3] ) + b[1] * (0.10 + rand_map[2] ) + b[2] * (0.20 + rand_map[1]) + b[3] * (0.57 + rand_map[0] ); // 0.92
|
||||
|
||||
data[i] = (bleed_r << 10) | (bleed_g << 5) | (bleed_b);
|
||||
}
|
||||
data += width;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void bleed_filter(uint16_t *data, int width, int height);
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright (C) 2007 guest(r) - [email protected]
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
The 2xSaL shader processes a gfx. surface and redraws it 2x finer.
|
||||
|
||||
A linear post-resize can fit the image to any resolution.
|
||||
|
||||
Note: set scaler to normal2x.
|
||||
|
||||
*/
|
||||
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct input
|
||||
{
|
||||
float2 video_size;
|
||||
float2 texture_size;
|
||||
float2 output_size;
|
||||
};
|
||||
|
||||
struct deltas
|
||||
{
|
||||
float2 UL, UR, DL, DR;
|
||||
};
|
||||
|
||||
|
||||
output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s_p : TEXUNIT0)
|
||||
{
|
||||
float2 texsize = IN.texture_size;
|
||||
float dx = pow(texsize.x, -1.0) * 0.25;
|
||||
float dy = pow(texsize.y, -1.0) * 0.25;
|
||||
float3 dt = float3(1.0, 1.0, 1.0);
|
||||
|
||||
deltas VAR = {
|
||||
tex + float2(-dx, -dy),
|
||||
tex + float2(dx, -dy),
|
||||
tex + float2(-dx, dy),
|
||||
tex + float2(dx, dy)
|
||||
};
|
||||
|
||||
float3 c00 = tex2D(s_p, VAR.UL).xyz;
|
||||
float3 c20 = tex2D(s_p, VAR.UR).xyz;
|
||||
float3 c02 = tex2D(s_p, VAR.DL).xyz;
|
||||
float3 c22 = tex2D(s_p, VAR.DR).xyz;
|
||||
|
||||
float m1=dot(abs(c00-c22),dt)+0.001;
|
||||
float m2=dot(abs(c02-c20),dt)+0.001;
|
||||
|
||||
output OUT;
|
||||
OUT.color = float4((m1*(c02+c20)+m2*(c22+c00))/(2.0*(m1+m2)),1.0);
|
||||
return OUT;
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
float Luminance = 0.09f;
|
||||
static const float fMiddleGray = 0.18f;
|
||||
static const float fWhiteCutoff = 0.8f;
|
||||
|
||||
#define NUM 13
|
||||
|
||||
float2 PixelOffsets[NUM] =
|
||||
{
|
||||
{ -0.006, -0.006 },
|
||||
{ -0.005, -0.005 },
|
||||
{ -0.004, -0.004 },
|
||||
{ -0.003, -0.003 },
|
||||
{ -0.002, -0.002 },
|
||||
{ -0.001, -0.001 },
|
||||
{ 0.000, 0.000 },
|
||||
{ 0.001, 0.001 },
|
||||
{ 0.002, 0.002 },
|
||||
{ 0.003, 0.003 },
|
||||
{ 0.004, 0.004 },
|
||||
{ 0.005, 0.005 },
|
||||
{ 0.006, 0.006 },
|
||||
};
|
||||
|
||||
static const float BlurWeights[NUM] =
|
||||
{
|
||||
0.002216,
|
||||
0.008764,
|
||||
0.026995,
|
||||
0.064759,
|
||||
0.120985,
|
||||
0.176033,
|
||||
0.199471,
|
||||
0.176033,
|
||||
0.120985,
|
||||
0.064759,
|
||||
0.026995,
|
||||
0.008764,
|
||||
0.002216,
|
||||
};
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
|
||||
output main_fragment( float2 Tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0 )
|
||||
{
|
||||
float2 BloomSettings;
|
||||
BloomSettings.x = 1;
|
||||
BloomSettings.y = 0.3;
|
||||
|
||||
float3 pixel;
|
||||
float3 Color = 0;
|
||||
|
||||
for(int i = 0; i < NUM; i++)
|
||||
{
|
||||
pixel = tex2D(s0, Tex + PixelOffsets[i] * 5.0f)+BloomSettings.y;
|
||||
|
||||
pixel *= fMiddleGray / (Luminance + 0.001f);
|
||||
pixel *= (1.0f + (pixel / (fWhiteCutoff * fWhiteCutoff)));
|
||||
pixel -= 5.0f;
|
||||
|
||||
pixel = max(pixel,0.0f);
|
||||
pixel /= (10.0f + pixel);
|
||||
|
||||
Color += pixel * BlurWeights[i];
|
||||
}
|
||||
|
||||
Color *= BloomSettings.x;
|
||||
|
||||
output OUT;
|
||||
OUT.color = float4(Color,1.0) + tex2D(s0,Tex);
|
||||
return OUT;
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
const float2 samples[12]
|
||||
= {
|
||||
-0.326212, -0.405805,
|
||||
-0.840144, -0.073580,
|
||||
-0.695914, 0.457137,
|
||||
-0.203345, 0.620716,
|
||||
0.962340, -0.194983,
|
||||
0.473434, -0.480026,
|
||||
0.519456, 0.767022,
|
||||
0.185461, -0.893124,
|
||||
0.507431, 0.064425,
|
||||
0.896420, 0.412458,
|
||||
-0.321940, -0.932615,
|
||||
-0.791559, -0.597705
|
||||
};
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 col : COLOR;
|
||||
};
|
||||
|
||||
output main_fragment(in float2 Tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0 )
|
||||
{
|
||||
float4 color = tex2D( s0, Tex.xy);
|
||||
float BlurFactor = 0.0025; //set between 0.001 and 0.05
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
color += tex2D(s0, Tex + BlurFactor * samples[i]);
|
||||
}
|
||||
|
||||
output OUT;
|
||||
OUT.col = color / 13;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
#define TEX2D(c) tex2D(decal,(c))
|
||||
#define PI 3.141592653589
|
||||
#define phase 0.0
|
||||
#define gamma 2.5
|
||||
#define distortion 0.04
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct input
|
||||
{
|
||||
float2 video_size;
|
||||
float2 texture_size;
|
||||
float2 output_size;
|
||||
};
|
||||
|
||||
float2 barrelDistortion(float2 coord)
|
||||
{
|
||||
float2 cc = coord - 0.5;
|
||||
float dist = dot(cc, cc);
|
||||
return coord + cc * (dist + distortion * dist * dist) * distortion;
|
||||
}
|
||||
|
||||
output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN)
|
||||
{
|
||||
output OUT;
|
||||
|
||||
float2 rubyInputSize = IN.video_size;
|
||||
float2 rubyOutputSize = IN.output_size;
|
||||
float2 rubyTextureSize = IN.texture_size;
|
||||
|
||||
float2 xy = barrelDistortion(texCoord.xy);
|
||||
float2 one = 1.0/rubyTextureSize;
|
||||
xy = xy + float2(0.0 , -0.5 * (phase + (1-phase) * rubyInputSize.y/rubyOutputSize.y) * one.y);
|
||||
float4 texels[8];
|
||||
texels[0] = TEX2D(xy + float2(-one.x,0.0));
|
||||
texels[1] = TEX2D(xy);
|
||||
texels[2] = TEX2D(xy + float2(one.x, 0.0));
|
||||
texels[3] = TEX2D(xy + float2(2 * one.x, 0.0));
|
||||
texels[4] = TEX2D(xy + float2(-one.x,one.y));
|
||||
texels[5] = TEX2D(xy + float2(0.0, one.y));
|
||||
texels[6] = TEX2D(xy + one);
|
||||
texels[7] = TEX2D(xy + float2(2 * one.x, one.y));
|
||||
|
||||
|
||||
float2 uv_ratio = frac(xy*rubyTextureSize);
|
||||
|
||||
float4 col, col2;
|
||||
|
||||
float4 coeffs = float4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x);
|
||||
coeffs = (sin(PI * coeffs) * sin(PI * coeffs / 2.0)) / (coeffs * coeffs);
|
||||
coeffs = coeffs / (coeffs.x+coeffs.y+coeffs.z+coeffs.w);
|
||||
|
||||
col = clamp(coeffs.x * texels[0] + coeffs.y * texels[1] + coeffs.z * texels[2] + coeffs.w * texels[3], 0.0, 1.0);
|
||||
col2 = clamp(coeffs.x * texels[4] + coeffs.y * texels[5] + coeffs.z * texels[6] + coeffs.w * texels[7], 0.0, 1.0);
|
||||
col = pow(col, gamma);
|
||||
col2 = pow(col2, gamma);
|
||||
|
||||
float4 wid = 2 + 2 * pow(col, 4.0);
|
||||
float4 weights = uv_ratio.y/0.3;
|
||||
weights = 0.51*exp(-pow(weights*sqrt(2/wid),wid))/0.3/(0.6+0.2*wid);
|
||||
wid = 2 + 4 * pow(col2,4.0);
|
||||
float4 weights2 = (1.0-uv_ratio.y)/0.3;
|
||||
weights2 = 0.51*exp(-pow(weights2*sqrt(2/wid),wid))/0.3/(0.6+0.2*wid);
|
||||
|
||||
float4 mcol = 1.0;
|
||||
if ( fmod(xy.x*rubyOutputSize.x,2.0) < 1.0)
|
||||
mcol.g = 0.7;
|
||||
else
|
||||
mcol.rb = 0.7;
|
||||
|
||||
//OUT.color = pow(mcol*(col * weights + col2 * weights2), 1.0/2.2);
|
||||
OUT.color = 1.0;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct input
|
||||
{
|
||||
float2 video_size;
|
||||
float2 texture_size;
|
||||
float2 output_size;
|
||||
};
|
||||
|
||||
const float mx = 0.325; // start smoothing wt.
|
||||
const float k = -0.250; // wt. decrease factor
|
||||
const float max_w = 0.25; // max filter weigth
|
||||
const float min_w =-0.05; // min filter weigth
|
||||
const float lum_add = 0.25; // effects smoothing
|
||||
|
||||
output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN)
|
||||
{
|
||||
float x = 0.5 * (1.0 / IN.texture_size.x);
|
||||
float y = 0.5 * (1.0 / IN.texture_size.y);
|
||||
float2 dg1 = float2( x, y);
|
||||
float2 dg2 = float2(-x, y);
|
||||
float2 dx = float2(x, 0.0);
|
||||
float2 dy = float2(0.0, y);
|
||||
|
||||
float4 TexCoord[5];
|
||||
TexCoord[0] = float4(texCoord, 0.0, 0.0);
|
||||
TexCoord[1].xy = TexCoord[0].xy - dg1;
|
||||
TexCoord[1].zw = TexCoord[0].xy - dy;
|
||||
TexCoord[2].xy = TexCoord[0].xy - dg2;
|
||||
TexCoord[2].zw = TexCoord[0].xy + dx;
|
||||
TexCoord[3].xy = TexCoord[0].xy + dg1;
|
||||
TexCoord[3].zw = TexCoord[0].xy + dy;
|
||||
TexCoord[4].xy = TexCoord[0].xy + dg2;
|
||||
TexCoord[4].zw = TexCoord[0].xy - dx;
|
||||
|
||||
float3 c00 = tex2D(decal, TexCoord[1].xy).xyz;
|
||||
float3 c10 = tex2D(decal, TexCoord[1].zw).xyz;
|
||||
float3 c20 = tex2D(decal, TexCoord[2].xy).xyz;
|
||||
float3 c01 = tex2D(decal, TexCoord[4].zw).xyz;
|
||||
float3 c11 = tex2D(decal, TexCoord[0].xy).xyz;
|
||||
float3 c21 = tex2D(decal, TexCoord[2].zw).xyz;
|
||||
float3 c02 = tex2D(decal, TexCoord[4].xy).xyz;
|
||||
float3 c12 = tex2D(decal, TexCoord[3].zw).xyz;
|
||||
float3 c22 = tex2D(decal, TexCoord[3].xy).xyz;
|
||||
float3 dt = float3(1.0, 1.0, 1.0);
|
||||
|
||||
float md1 = dot(abs(c00 - c22), dt);
|
||||
float md2 = dot(abs(c02 - c20), dt);
|
||||
|
||||
float w1 = dot(abs(c22 - c11), dt) * md2;
|
||||
float w2 = dot(abs(c02 - c11), dt) * md1;
|
||||
float w3 = dot(abs(c00 - c11), dt) * md2;
|
||||
float w4 = dot(abs(c20 - c11), dt) * md1;
|
||||
|
||||
float t1 = w1 + w3;
|
||||
float t2 = w2 + w4;
|
||||
float ww = max(t1, t2) + 0.0001;
|
||||
|
||||
c11 = (w1 * c00 + w2 * c20 + w3 * c22 + w4 * c02 + ww * c11) / (t1 + t2 + ww);
|
||||
|
||||
float lc1 = k / (0.12 * dot(c10 + c12 + c11, dt) + lum_add);
|
||||
float lc2 = k / (0.12 * dot(c01 + c21 + c11, dt) + lum_add);
|
||||
|
||||
w1 = clamp(lc1 * dot(abs(c11 - c10), dt) + mx, min_w, max_w);
|
||||
w2 = clamp(lc2 * dot(abs(c11 - c21), dt) + mx, min_w, max_w);
|
||||
w3 = clamp(lc1 * dot(abs(c11 - c12), dt) + mx, min_w, max_w);
|
||||
w4 = clamp(lc2 * dot(abs(c11 - c01), dt) + mx, min_w, max_w);
|
||||
|
||||
output OUT;
|
||||
OUT.color = float4(w1 * c10 + w2 * c21 + w3 * c12 + w4 * c01 + (1.0 - w1 - w2 - w3 - w4) * c11, 1.0);
|
||||
return OUT;
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
Author: Themaister
|
||||
License: Public domain
|
||||
*/
|
||||
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct input
|
||||
{
|
||||
float2 video_size;
|
||||
float2 texture_size;
|
||||
float2 output_size;
|
||||
};
|
||||
|
||||
struct deltas
|
||||
{
|
||||
float2 UL, UR, DL, DR;
|
||||
};
|
||||
|
||||
float3 quad_inter(float3 x0, float3 x1, float3 x2, float x)
|
||||
{
|
||||
float3 poly[3];
|
||||
poly[2] = 0.5*x0 - x1 + 0.5*x2;
|
||||
poly[1] = -1.5*x0 + 2.0*x1 - 0.5*x2;
|
||||
poly[0] = x0;
|
||||
return poly[2] * x * x + poly[1] * x + poly[0];
|
||||
}
|
||||
|
||||
output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s0 : TEXUNIT0)
|
||||
{
|
||||
float2 texsize = IN.texture_size;
|
||||
float sharpness = 2.0;
|
||||
float dx = float(pow(sharpness * texsize.x, -1.0));
|
||||
float dy = float(pow(sharpness * texsize.y, -1.0));
|
||||
|
||||
float3 c00 = tex2D(s0, tex + float2(-dx, -dy)).xyz;
|
||||
float3 c01 = tex2D(s0, tex + float2(-dx, 0)).xyz;
|
||||
float3 c02 = tex2D(s0, tex + float2(-dx, dy)).xyz;
|
||||
float3 c10 = tex2D(s0, tex + float2(0, -dy)).xyz;
|
||||
float3 c11 = tex2D(s0, tex + float2(0, 0)).xyz;
|
||||
float3 c12 = tex2D(s0, tex + float2(0, dy)).xyz;
|
||||
float3 c20 = tex2D(s0, tex + float2(dx, -dy)).xyz;
|
||||
float3 c21 = tex2D(s0, tex + float2(dx, 0)).xyz;
|
||||
float3 c22 = tex2D(s0, tex + float2(dx, dy)).xyz;
|
||||
|
||||
float frac_amt_x = frac(tex.x * texsize.x);
|
||||
float frac_amt_y = frac(tex.y * texsize.y);
|
||||
float3 loval = quad_inter(c00, c10, c20, frac_amt_x + 0.5);
|
||||
float3 midval = quad_inter(c01, c11, c21, frac_amt_x + 0.5);
|
||||
float3 hival = quad_inter(c02, c12, c22, frac_amt_x + 0.5);
|
||||
float3 res = quad_inter(loval, midval, hival, frac_amt_y + 0.5);
|
||||
|
||||
output OUT;
|
||||
|
||||
// Bilinear!
|
||||
// float3 first = lerp(c00, c20, frac(tex.x * texsize.x + 0.5));
|
||||
// float3 second = lerp(c02, c22, frac(tex.x * texsize.x + 0.5));
|
||||
// float3 res = lerp(first, second, frac(tex.y * texsize.y + 0.5));
|
||||
// OUT.color = float4(res, 1.0);
|
||||
|
||||
|
||||
OUT.color = float4(res, 1.0);
|
||||
return OUT;
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct input
|
||||
{
|
||||
float2 video_size;
|
||||
float2 texture_size;
|
||||
float2 output_size;
|
||||
};
|
||||
|
||||
output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN)
|
||||
{
|
||||
output OUT;
|
||||
|
||||
float winHeight = IN.output_size.y;
|
||||
float4 tex_color = tex2D(decal, texCoord);
|
||||
|
||||
OUT.color = (1.0 - 0.60 * floor(fmod(texCoord.y * winHeight, 2.0))) * tex_color;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
/* Default Vertex shader */
|
||||
void main_vertex
|
||||
(
|
||||
float4 position : POSITION,
|
||||
float4 color : COLOR,
|
||||
float2 texCoord : TEXCOORD0,
|
||||
|
||||
uniform float4x4 modelViewProj,
|
||||
|
||||
out float4 oPosition : POSITION,
|
||||
out float4 oColor : COLOR,
|
||||
out float2 otexCoord : TEXCOORD
|
||||
)
|
||||
{
|
||||
oPosition = mul(modelViewProj, position);
|
||||
oColor = color;
|
||||
otexCoord = texCoord;
|
||||
}
|
||||
|
||||
struct output
|
||||
{
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
output main_fragment( in float2 Tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0 )
|
||||
{
|
||||
float4 Color = tex2D( s0, Tex.xy );
|
||||
float Sharpenfactor = 30; //Make this between 10 and 50;
|
||||
|
||||
Color -= tex2D( s0, Tex.xy+0.0001)*Sharpenfactor;
|
||||
Color += tex2D( s0, Tex.xy-0.0001)*Sharpenfactor;
|
||||
|
||||
Color.a = 1.0;
|
||||
output OUT;
|
||||
OUT.color = Color;
|
||||
return OUT;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/* Very simple grayscale filter.
|
||||
* Author: Hans-Kristian Arntzen
|
||||
* License: Public domain
|
||||
*/
|
||||
|
||||
#include "grayscale.h"
|
||||
|
||||
// Input format 0RRRRRGGGGGBBBBB. Colors themselves could be switched around.
|
||||
void grayscale_filter(uint16_t *data, int width, int height)
|
||||
{
|
||||
for (int i = 0; i < width * height; i++ )
|
||||
{
|
||||
int r, g, b, color;
|
||||
r = (data[i] >> 10) & 0x1F;
|
||||
g = (data[i] >> 5) & 0x1F;
|
||||
b = (data[i] >> 0) & 0x1F;
|
||||
|
||||
color = (int)(r * 0.3 + g * 0.59 + b * 0.11);
|
||||
data[i] = (color << 10) | (color << 5) | color;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
/* Very simple grayscale filter.
|
||||
* Author: Hans-Kristian Arntzen
|
||||
* License: Public domain
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
void grayscale_filter(uint16_t *data, int width, int height);
|
||||
-555
@@ -1,555 +0,0 @@
|
||||
/* This source code is Copyright (C) 2006-2009 by WolfWings. */
|
||||
/* It is, however, released under the ISC license. */
|
||||
/* en.wikipedia.org/wiki/ISC_Licence */
|
||||
/* --------------------------------------------------------- */
|
||||
/* It is a formula-level rederiviation of the HQ2x technique */
|
||||
/* and is, thus, not a derivative work of the original code, */
|
||||
/* only the original equations behind the code. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pastlib.h"
|
||||
|
||||
static const uint8_t blends_2x[14*4] = {
|
||||
/* 5 2 4 1 */
|
||||
|
||||
8, 4, 4, 0,
|
||||
8, 4, 0, 4,
|
||||
8, 0, 4, 4,
|
||||
16, 0, 0, 0,
|
||||
12, 4, 0, 0,
|
||||
12, 0, 4, 0,
|
||||
12, 0, 0, 4,
|
||||
|
||||
4, 6, 6, 0, /* Interp9 */
|
||||
12, 2, 2, 0, /* Interp7 */
|
||||
14, 1, 1, 0, /* Interp10*/
|
||||
10, 4, 2, 0, /* Interp6 */
|
||||
10, 2, 4, 0, /* Interp6 */
|
||||
4, 6, 6, 0, /* Added for secondary blending used in HQ4x */
|
||||
8, 4, 4, 0, /* Added for secondary blending used in HQ4x */
|
||||
};
|
||||
|
||||
static const uint8_t blends_4x[14*16] = {
|
||||
/* 5 2 4 1 5 2 4 1 5 2 4 1 5 2 4 1 */
|
||||
|
||||
8, 4, 4, 0, 10, 4, 2, 0, 10, 2, 4, 0, 12, 2, 2, 0, /* Needs to be split. B */
|
||||
10, 0, 0, 6, 10, 4, 0, 2, 12, 0, 0, 4, 14, 0, 0, 2,
|
||||
10, 0, 0, 6, 10, 0, 4, 2, 12, 0, 0, 4, 14, 0, 0, 2,
|
||||
16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, /* Solid colors */
|
||||
10, 6, 0, 0, 10, 6, 0, 0, 14, 2, 0, 0, 14, 2, 0, 0,
|
||||
10, 0, 6, 0, 14, 0, 2, 0, 10, 0, 6, 0, 14, 0, 2, 0,
|
||||
10, 0, 0, 6, 12, 0, 0, 4, 12, 0, 0, 4, 14, 0, 0, 2,
|
||||
0, 8, 8, 0, 4, 8, 4, 0, 0, 6,10, 0, 12, 2, 2, 0, /* Needs to be split. A */
|
||||
8, 4, 4, 0, 12, 4, 0, 0, 12, 0, 4, 0, 16, 0, 0, 0,
|
||||
8, 4, 4, 0, 16, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0,
|
||||
12, 4, 0, 0, 4,12, 0, 0, 10, 0, 4, 0, 14, 0, 2, 0,
|
||||
12, 0, 4, 0, 10, 4, 0, 0, 4, 0,12, 0, 14, 2, 0, 0,
|
||||
0, 8, 8, 0, 0,10, 6, 0, 4, 4, 8, 0, 12, 2, 2, 0, /* Needs to be split. A */
|
||||
0, 8, 8, 0, 8, 8, 0, 0, 8, 0, 8, 0, 16, 0, 0, 0, /* Needs to be split. B */
|
||||
};
|
||||
|
||||
static const uint8_t tree_hq[0x800] = {
|
||||
/* 6 6 6 6 6 6 6 6
|
||||
* 2 2 2 2 2 2 2 2
|
||||
* 4 4 4 4 4 4 4 4
|
||||
* 8 8 8 8 8 8 8 8
|
||||
*/
|
||||
0, 0, 2, 2, 1, 1,13,13, 0, 0, 2, 2, 1, 1,13, 8, /* */
|
||||
0, 0, 2, 2, 1, 1,12, 6, 0, 0, 2, 2, 1, 1, 8, 8, /* 3 */
|
||||
0, 0, 5,10, 4, 4,13,13, 0, 0, 5, 5,11, 4,13,13, /* 1 */
|
||||
0, 0, 5,10, 4, 4,12,13, 0, 0, 5, 5,11, 4,13,13, /* 31 */
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 6, 8, /* 7 */
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6, /* 3 7 */
|
||||
0, 0, 5,10, 4, 4, 7,13, 0, 0, 5, 5,11, 4,13,13, /* 17 */
|
||||
0, 0, 5,10, 4, 4, 9, 9, 0, 0, 5,10,11,11, 9, 9, /* 317 */
|
||||
0, 0, 2, 2, 1, 1,13, 8, 0, 0, 2, 2, 1, 1, 8, 8, /* 9 */
|
||||
0, 0, 2, 2, 1, 1,12, 8, 0, 0, 2, 2, 1, 1, 8, 6, /* 3 9 */
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13, /* 1 9 */
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5, 4, 4,12,13, /* 31 9 */
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 8, 6, /* 79 */
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6, /* 3 79 */
|
||||
0, 0, 5, 5, 4, 4, 7, 7, 0, 0, 5, 5, 4, 4,13,13, /* 179 */
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5, 4, 4, 9, 9, /* 3179 */
|
||||
/* DIFF26 */
|
||||
0, 0, 2, 2, 1, 1,13,13, 0, 0, 2, 2, 1, 1,13, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 6, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5,11, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5,11, 4,13,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 6, 8,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 7,13, 0, 0, 5, 5,11, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5,11,11, 9, 9,
|
||||
0, 0, 2, 2, 1, 1,13, 8, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5, 4, 4,12,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 7, 7, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5, 4, 4, 9, 9,
|
||||
/* DIFF24 */
|
||||
0, 0, 2, 2, 1, 1, 6, 3, 0, 0, 2, 2, 1, 1, 3, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5,10,11,11, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
/* DIFF26 DIFF24 */
|
||||
0, 0, 2, 2, 1, 1, 6, 3, 0, 0, 2, 2, 1, 1, 3, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5,11, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5,11,11, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
/* DIFF84 */
|
||||
0, 0, 2, 2, 1, 1,13,13, 0, 0, 2, 2, 1, 1,13, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 6, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 5,10, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5,10, 4, 4,12,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 6, 8,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5,10, 4, 4, 7,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5,10, 4, 4, 9, 9, 0, 0, 5,10, 4, 4, 9, 9,
|
||||
0, 0, 2, 2, 1, 1,13, 8, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5, 4, 4,12,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 7, 7, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5, 4, 4, 9, 9,
|
||||
/* DIFF26 DIFF84 */
|
||||
0, 0, 2, 2, 1, 1,13,13, 0, 0, 2, 2, 1, 1,13, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 6, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 6, 8,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 7,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5, 4, 4, 9, 9,
|
||||
0, 0, 2, 2, 1, 1,13, 8, 0, 0, 2, 2, 1, 1, 8, 8,
|
||||
0, 0, 2, 2, 1, 1,12, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 5, 5, 4, 4,13,13, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4,12,13, 0, 0, 5, 5, 4, 4,12,13,
|
||||
0, 0, 2, 2, 1, 1, 7, 8, 0, 0, 2, 2, 1, 1, 8, 6,
|
||||
0, 0, 2, 2, 1, 1, 8, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 7, 7, 0, 0, 5, 5, 4, 4,13,13,
|
||||
0, 0, 5, 5, 4, 4, 9, 9, 0, 0, 5, 5, 4, 4, 9, 9,
|
||||
/* DIFF24 DIFF84 */
|
||||
0, 0, 2, 2, 1, 1, 6, 3, 0, 0, 2, 2, 1, 1, 3, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5,10, 4, 4, 3, 3, 0, 0, 5,10, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
/* DIFF26 DIFF24 DIFF84 */
|
||||
0, 0, 2, 2, 1, 1, 6, 3, 0, 0, 2, 2, 1, 1, 3, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 2, 2, 1, 1, 6, 6, 0, 0, 2, 2, 1, 1, 6, 6,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3,
|
||||
0, 0, 5, 5, 4, 4, 3, 3, 0, 0, 5, 5, 4, 4, 3, 3};
|
||||
|
||||
#define RB(y,u,v) (((y)&0x3FF)<<22)|(((u)&0x3FF)<<11)|((v)&0x3FF)
|
||||
#define GO(y,v) ((((y)+64)&0x3FF)<<22)|(16<<11)|(((v)+16)&0x3FF)
|
||||
static const uint32_t DiffTable[128] = {
|
||||
RB(-85, 160, 80), RB(-83, 155, 77), RB(-80, 150, 75), RB(-77, 145, 72),
|
||||
RB(-75, 140, 70), RB(-72, 135, 67), RB(-69, 130, 65), RB(-67, 125, 62),
|
||||
RB(-64, 120, 60), RB(-61, 115, 57), RB(-59, 110, 55), RB(-56, 105, 52),
|
||||
RB(-53, 100, 50), RB(-51, 95, 47), RB(-48, 90, 45), RB(-45, 85, 42),
|
||||
RB(-43, 80, 40), RB(-40, 75, 37), RB(-37, 70, 35), RB(-35, 65, 32),
|
||||
RB(-32, 60, 30), RB(-29, 55, 27), RB(-27, 50, 25), RB(-24, 45, 22),
|
||||
RB(-21, 40, 20), RB(-19, 35, 17), RB(-16, 30, 15), RB(-13, 25, 12),
|
||||
RB(-11, 20, 10), RB( -8, 15, 7), RB( -5, 10, 5), RB( -3, 5, 2),
|
||||
RB( 0, 0, 0), RB( 2, -5, -2), RB( 5, -10, -5), RB( 7, -15, -7),
|
||||
RB( 10, -20, -10), RB( 13, -25, -12), RB( 15, -30, -15), RB( 18, -35, -17),
|
||||
RB( 21, -40, -20), RB( 23, -45, -22), RB( 26, -50, -25), RB( 29, -55, -27),
|
||||
RB( 31, -60, -30), RB( 34, -65, -32), RB( 37, -70, -35), RB( 39, -75, -37),
|
||||
RB( 42, -80, -40), RB( 45, -85, -42), RB( 47, -90, -45), RB( 50, -95, -47),
|
||||
RB( 53,-100, -50), RB( 55,-105, -52), RB( 58,-110, -55), RB( 61,-115, -57),
|
||||
RB( 63,-120, -60), RB( 66,-125, -62), RB( 69,-130, -65), RB( 71,-135, -67),
|
||||
RB( 74,-140, -70), RB( 77,-145, -72), RB( 79,-150, -75), RB( 82,-155, -77),
|
||||
GO(-84, -160), GO(-81, -155), GO(-78, -150), GO(-76, -145),
|
||||
GO(-73, -140), GO(-70, -135), GO(-68, -130), GO(-65, -125),
|
||||
GO(-63, -120), GO(-60, -115), GO(-57, -110), GO(-55, -105),
|
||||
GO(-52, -100), GO(-49, -95), GO(-47, -90), GO(-44, -85),
|
||||
GO(-42, -80), GO(-39, -75), GO(-36, -70), GO(-34, -65),
|
||||
GO(-31, -60), GO(-28, -55), GO(-26, -50), GO(-23, -45),
|
||||
GO(-21, -40), GO(-18, -35), GO(-15, -30), GO(-13, -25),
|
||||
GO(-10, -20), GO( -7, -15), GO( -5, -10), GO( -2, -5),
|
||||
GO( 0, 0), GO( 2, 4), GO( 5, 9), GO( 7, 14),
|
||||
GO( 10, 19), GO( 13, 24), GO( 15, 29), GO( 18, 34),
|
||||
GO( 21, 39), GO( 23, 44), GO( 26, 49), GO( 28, 54),
|
||||
GO( 31, 59), GO( 34, 64), GO( 36, 69), GO( 39, 74),
|
||||
GO( 42, 79), GO( 44, 84), GO( 47, 89), GO( 49, 94),
|
||||
GO( 52, 99), GO( 55, 104), GO( 57, 109), GO( 60, 114),
|
||||
GO( 63, 119), GO( 65, 124), GO( 68, 129), GO( 70, 134),
|
||||
GO( 73, 139), GO( 76, 144), GO( 78, 149), GO( 81, 154)};
|
||||
|
||||
inline static int ExpandedDiff (uint32_t c0, uint32_t c1) {
|
||||
uint32_t r, g;
|
||||
g = c0;
|
||||
g += 0x4008020;
|
||||
g -= c1;
|
||||
r = DiffTable[(int)((unsigned char)g) + 0];
|
||||
r ^= (0x3FF << 11);
|
||||
g >>= 10;
|
||||
r += DiffTable[(int)((unsigned char)g) + 0];
|
||||
g >>= 11;
|
||||
r += DiffTable[(int)((unsigned char)g) + 64];
|
||||
r &= 0xE01F03E0;
|
||||
return r;
|
||||
}
|
||||
|
||||
#define DIFF56 0x001
|
||||
#define DIFF52 0x002
|
||||
#define DIFF54 0x004
|
||||
#define DIFF58 0x008
|
||||
#define DIFF53 0x010
|
||||
#define DIFF51 0x020
|
||||
#define DIFF57 0x040
|
||||
#define DIFF59 0x080
|
||||
#define DIFF26 0x100
|
||||
#define DIFF24 0x200
|
||||
#define DIFF84 0x400
|
||||
#define DIFF86 0x800
|
||||
|
||||
/* lastLineDiffs is previous line's 52, 53, 26, all >> 1 */
|
||||
|
||||
static uint8_t lastLineDiffs[__PAST_LIBRARY_WIDTH];
|
||||
|
||||
#define RotatePattern(x) ((((x) & 0x777) << 1) | (((x) & 0x888) >> 3))
|
||||
|
||||
void ProcessHQ2x(const pixel * restrict in, pixel * restrict out) {
|
||||
signed int y, x;
|
||||
unsigned int pattern, newpattern;
|
||||
uint32_t pixels[9];
|
||||
int prevline, nextline;
|
||||
|
||||
memset(lastLineDiffs, 0, sizeof(lastLineDiffs));
|
||||
prevline = 1;
|
||||
nextline = 1 + __PAST_LIBRARY_WIDTH;
|
||||
y = __PAST_LIBRARY_HEIGHT - 1;
|
||||
|
||||
do {
|
||||
pixels[1-1] =
|
||||
pixels[2-1] = RGBUnpack(in[prevline-1]); /* Pixel 2 */
|
||||
pixels[3-1] = RGBUnpack(in[prevline ]); /* Pixel 3 */
|
||||
|
||||
pixels[4-1] =
|
||||
pixels[5-1] = RGBUnpack(in[ 0]); /* Pixel 5 */
|
||||
pixels[6-1] = RGBUnpack(in[ 1]); /* Pixel 6 */
|
||||
|
||||
pixels[7-1] =
|
||||
pixels[8-1] = RGBUnpack(in[nextline-1]); /* Pixel 8 */
|
||||
pixels[9-1] = RGBUnpack(in[nextline ]); /* Pixel 9 */
|
||||
|
||||
pattern = 0;
|
||||
|
||||
x = __PAST_LIBRARY_WIDTH - 1;
|
||||
do {
|
||||
newpattern = 0;
|
||||
if (pattern & DIFF26) newpattern |= DIFF51;
|
||||
if (pattern & DIFF56) newpattern |= DIFF54;
|
||||
if (pattern & DIFF86) newpattern |= DIFF57;
|
||||
if (pattern & DIFF53) newpattern |= DIFF24;
|
||||
if (pattern & DIFF59) newpattern |= DIFF84;
|
||||
|
||||
if (lastLineDiffs[x] & (DIFF52 >> 1)) newpattern |= DIFF58;
|
||||
if (lastLineDiffs[x] & (DIFF26 >> 1)) newpattern |= DIFF59;
|
||||
if (lastLineDiffs[x] & (DIFF53 >> 1)) newpattern |= DIFF86;
|
||||
|
||||
pattern = newpattern;
|
||||
|
||||
if (ExpandedDiff(pixels[5-1], pixels[2-1])) pattern |= DIFF52;
|
||||
if (ExpandedDiff(pixels[5-1], pixels[3-1])) pattern |= DIFF53;
|
||||
if (ExpandedDiff(pixels[5-1], pixels[6-1])) pattern |= DIFF56;
|
||||
if (ExpandedDiff(pixels[2-1], pixels[6-1])) pattern |= DIFF26;
|
||||
lastLineDiffs[x] = pattern >> 1;
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[ 0] =
|
||||
RGBPack(((pixels[5-1] * blends_2x[(newpattern * 4) + 0]) +
|
||||
(pixels[2-1] * blends_2x[(newpattern * 4) + 1]) +
|
||||
(pixels[4-1] * blends_2x[(newpattern * 4) + 2]) +
|
||||
(pixels[1-1] * blends_2x[(newpattern * 4) + 3])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[ 1] =
|
||||
RGBPack(((pixels[5-1] * blends_2x[(newpattern * 4) + 0]) +
|
||||
(pixels[6-1] * blends_2x[(newpattern * 4) + 1]) +
|
||||
(pixels[2-1] * blends_2x[(newpattern * 4) + 2]) +
|
||||
(pixels[3-1] * blends_2x[(newpattern * 4) + 3])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[(__PAST_LIBRARY_WIDTH*2)+1] =
|
||||
RGBPack(((pixels[5-1] * blends_2x[(newpattern * 4) + 0]) +
|
||||
(pixels[8-1] * blends_2x[(newpattern * 4) + 1]) +
|
||||
(pixels[6-1] * blends_2x[(newpattern * 4) + 2]) +
|
||||
(pixels[9-1] * blends_2x[(newpattern * 4) + 3])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[(__PAST_LIBRARY_WIDTH*2) ] =
|
||||
RGBPack(((pixels[5-1] * blends_2x[(newpattern * 4) + 0]) +
|
||||
(pixels[4-1] * blends_2x[(newpattern * 4) + 1]) +
|
||||
(pixels[8-1] * blends_2x[(newpattern * 4) + 2]) +
|
||||
(pixels[7-1] * blends_2x[(newpattern * 4) + 3])) / 16);
|
||||
|
||||
out += 2;
|
||||
in++;
|
||||
x--;
|
||||
|
||||
if (x == 0) {
|
||||
pixels[1-1] = pixels[2-1];
|
||||
pixels[2-1] = pixels[3-1];
|
||||
pixels[4-1] = pixels[5-1];
|
||||
pixels[5-1] = pixels[6-1];
|
||||
pixels[7-1] = pixels[8-1];
|
||||
pixels[8-1] = pixels[9-1];
|
||||
continue;
|
||||
}
|
||||
|
||||
pixels[1-1] = pixels[2-1];
|
||||
pixels[2-1] = pixels[3-1];
|
||||
pixels[3-1] = RGBUnpack(in[prevline]); /* Pixel 3 */
|
||||
pixels[4-1] = pixels[5-1];
|
||||
pixels[5-1] = pixels[6-1];
|
||||
pixels[6-1] = RGBUnpack(in[1 ]); /* Pixel 6 */
|
||||
pixels[7-1] = pixels[8-1];
|
||||
pixels[8-1] = pixels[9-1];
|
||||
pixels[9-1] = RGBUnpack(in[nextline]); /* Pixel 9 */
|
||||
} while (x >= 0);
|
||||
|
||||
prevline = 1 - __PAST_LIBRARY_WIDTH;
|
||||
out += (__PAST_LIBRARY_WIDTH * 2);
|
||||
|
||||
y--;
|
||||
if (y > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nextline = 0;
|
||||
} while (y >= 0);
|
||||
}
|
||||
|
||||
void ProcessHQ4x(const pixel * restrict in, pixel * restrict out) {
|
||||
signed int y, x;
|
||||
unsigned int pattern, newpattern;
|
||||
uint32_t pixels[9];
|
||||
int prevline, nextline;
|
||||
|
||||
memset(lastLineDiffs, 0, sizeof(lastLineDiffs));
|
||||
prevline = 1;
|
||||
nextline = 1 + __PAST_LIBRARY_WIDTH;
|
||||
y = __PAST_LIBRARY_HEIGHT - 1;
|
||||
|
||||
do {
|
||||
pixels[1-1] =
|
||||
pixels[2-1] = RGBUnpack(in[prevline-1]); /* Pixel 2 */
|
||||
pixels[3-1] = RGBUnpack(in[prevline ]); /* Pixel 3 */
|
||||
|
||||
pixels[4-1] =
|
||||
pixels[5-1] = RGBUnpack(in[ 0]); /* Pixel 5 */
|
||||
pixels[6-1] = RGBUnpack(in[ 1]); /* Pixel 6 */
|
||||
|
||||
pixels[7-1] =
|
||||
pixels[8-1] = RGBUnpack(in[nextline-1]); /* Pixel 8 */
|
||||
pixels[9-1] = RGBUnpack(in[nextline ]); /* Pixel 9 */
|
||||
|
||||
pattern = 0;
|
||||
|
||||
x = __PAST_LIBRARY_WIDTH - 1;
|
||||
do {
|
||||
newpattern = 0;
|
||||
if (pattern & DIFF26) newpattern |= DIFF51;
|
||||
if (pattern & DIFF56) newpattern |= DIFF54;
|
||||
if (pattern & DIFF86) newpattern |= DIFF57;
|
||||
if (pattern & DIFF53) newpattern |= DIFF24;
|
||||
if (pattern & DIFF59) newpattern |= DIFF84;
|
||||
|
||||
if (lastLineDiffs[x] & (DIFF52 >> 1)) newpattern |= DIFF58;
|
||||
if (lastLineDiffs[x] & (DIFF26 >> 1)) newpattern |= DIFF59;
|
||||
if (lastLineDiffs[x] & (DIFF53 >> 1)) newpattern |= DIFF86;
|
||||
|
||||
pattern = newpattern;
|
||||
|
||||
if (ExpandedDiff(pixels[5-1], pixels[2-1])) pattern |= DIFF52;
|
||||
if (ExpandedDiff(pixels[5-1], pixels[3-1])) pattern |= DIFF53;
|
||||
if (ExpandedDiff(pixels[5-1], pixels[6-1])) pattern |= DIFF56;
|
||||
if (ExpandedDiff(pixels[2-1], pixels[6-1])) pattern |= DIFF26;
|
||||
lastLineDiffs[x] = pattern >> 1;
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[ 0] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x0]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 1 + 0x0]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 2 + 0x0]) +
|
||||
(pixels[1-1] * blends_4x[(newpattern * 16) + 3 + 0x0])) / 16);
|
||||
out[ 1] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x4]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 1 + 0x4]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 2 + 0x4]) +
|
||||
(pixels[1-1] * blends_4x[(newpattern * 16) + 3 + 0x4])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x4) ] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x8]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 1 + 0x8]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 2 + 0x8]) +
|
||||
(pixels[1-1] * blends_4x[(newpattern * 16) + 3 + 0x8])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x4)+1] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0xC]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 1 + 0xC]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 2 + 0xC]) +
|
||||
(pixels[1-1] * blends_4x[(newpattern * 16) + 3 + 0xC])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[ 3] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x0]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 1 + 0x0]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 2 + 0x0]) +
|
||||
(pixels[3-1] * blends_4x[(newpattern * 16) + 3 + 0x0])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x4)+3] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x4]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 1 + 0x4]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 2 + 0x4]) +
|
||||
(pixels[3-1] * blends_4x[(newpattern * 16) + 3 + 0x4])) / 16);
|
||||
out[ 2] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x8]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 1 + 0x8]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 2 + 0x8]) +
|
||||
(pixels[3-1] * blends_4x[(newpattern * 16) + 3 + 0x8])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x4)+2] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0xC]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 1 + 0xC]) +
|
||||
(pixels[2-1] * blends_4x[(newpattern * 16) + 2 + 0xC]) +
|
||||
(pixels[3-1] * blends_4x[(newpattern * 16) + 3 + 0xC])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[(__PAST_LIBRARY_WIDTH*0xC)+3] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x0]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 1 + 0x0]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 2 + 0x0]) +
|
||||
(pixels[9-1] * blends_4x[(newpattern * 16) + 3 + 0x0])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0xC)+2] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x4]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 1 + 0x4]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 2 + 0x4]) +
|
||||
(pixels[9-1] * blends_4x[(newpattern * 16) + 3 + 0x4])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x8)+3] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x8]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 1 + 0x8]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 2 + 0x8]) +
|
||||
(pixels[9-1] * blends_4x[(newpattern * 16) + 3 + 0x8])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x8)+2] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0xC]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 1 + 0xC]) +
|
||||
(pixels[6-1] * blends_4x[(newpattern * 16) + 2 + 0xC]) +
|
||||
(pixels[9-1] * blends_4x[(newpattern * 16) + 3 + 0xC])) / 16);
|
||||
|
||||
newpattern = tree_hq[pattern & 0x7FF];
|
||||
pattern = RotatePattern(pattern);
|
||||
out[(__PAST_LIBRARY_WIDTH*0xC) ] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x0]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 1 + 0x0]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 2 + 0x0]) +
|
||||
(pixels[7-1] * blends_4x[(newpattern * 16) + 3 + 0x0])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x8) ] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x4]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 1 + 0x4]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 2 + 0x4]) +
|
||||
(pixels[7-1] * blends_4x[(newpattern * 16) + 3 + 0x4])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0xC)+1] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0x8]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 1 + 0x8]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 2 + 0x8]) +
|
||||
(pixels[7-1] * blends_4x[(newpattern * 16) + 3 + 0x8])) / 16);
|
||||
out[(__PAST_LIBRARY_WIDTH*0x8)+1] =
|
||||
RGBPack(((pixels[5-1] * blends_4x[(newpattern * 16) + 0 + 0xC]) +
|
||||
(pixels[4-1] * blends_4x[(newpattern * 16) + 1 + 0xC]) +
|
||||
(pixels[8-1] * blends_4x[(newpattern * 16) + 2 + 0xC]) +
|
||||
(pixels[7-1] * blends_4x[(newpattern * 16) + 3 + 0xC])) / 16);
|
||||
|
||||
out += 4;
|
||||
in++;
|
||||
x--;
|
||||
|
||||
if (x == 0) {
|
||||
pixels[1-1] = pixels[2-1];
|
||||
pixels[2-1] = pixels[3-1];
|
||||
pixels[4-1] = pixels[5-1];
|
||||
pixels[5-1] = pixels[6-1];
|
||||
pixels[7-1] = pixels[8-1];
|
||||
pixels[8-1] = pixels[9-1];
|
||||
continue;
|
||||
}
|
||||
|
||||
pixels[1-1] = pixels[2-1];
|
||||
pixels[2-1] = pixels[3-1];
|
||||
pixels[3-1] = RGBUnpack(in[prevline]); /* Pixel 3 */
|
||||
pixels[4-1] = pixels[5-1];
|
||||
pixels[5-1] = pixels[6-1];
|
||||
pixels[6-1] = RGBUnpack(in[1 ]); /* Pixel 6 */
|
||||
pixels[7-1] = pixels[8-1];
|
||||
pixels[8-1] = pixels[9-1];
|
||||
pixels[9-1] = RGBUnpack(in[nextline]); /* Pixel 9 */
|
||||
} while (x >= 0);
|
||||
|
||||
prevline = 1 - __PAST_LIBRARY_WIDTH;
|
||||
out += (__PAST_LIBRARY_WIDTH * 0xC);
|
||||
|
||||
y--;
|
||||
if (y > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nextline = 0;
|
||||
} while (y >= 0);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "ntsc.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void ntsc_filter(uint16_t * restrict out, const uint16_t * restrict in, int width, int height)
|
||||
{
|
||||
static int phase = 0;
|
||||
static snes_ntsc_t ntsc;
|
||||
static bool inited = false;
|
||||
|
||||
if (inited == false)
|
||||
{
|
||||
snes_ntsc_init(&ntsc, &snes_ntsc_composite);
|
||||
inited = true;
|
||||
}
|
||||
|
||||
snes_ntsc_blit(&ntsc, in, width, phase, width, height, out, SNES_NTSC_OUT_WIDTH(width) * sizeof(uint16_t));
|
||||
phase ^= 1;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
#ifndef _NTSC_FILTER_H
|
||||
#define _NTSC_FILTER_H
|
||||
#include <stdint.h>
|
||||
#include "snes_ntsc/snes_ntsc.h"
|
||||
|
||||
void ntsc_filter(uint16_t * restrict out, const uint16_t * restrict in, int width, int height);
|
||||
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
/* This source code is Copyright (C) 2006-2009 by WolfWings. */
|
||||
/* It is, however, released under the ISC license. */
|
||||
/* en.wikipedia.org/wiki/ISC_Licence */
|
||||
/* --------------------------------------------------------- */
|
||||
/* It is a formula-level rederiviation of the HQ2x technique */
|
||||
/* and is, thus, not a derivative work of the original code, */
|
||||
/* only the original equations behind the code. */
|
||||
|
||||
#ifndef __PAST_LIBRARY_H
|
||||
#define __PAST_LIBRARY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __PAST_LIBRARY_WIDTH
|
||||
#define __PAST_LIBRARY_WIDTH 256
|
||||
#endif
|
||||
|
||||
#ifndef __PAST_LIBRARY_HEIGHT
|
||||
#define __PAST_LIBRARY_HEIGHT 224
|
||||
#endif
|
||||
|
||||
typedef uint16_t pixel;
|
||||
|
||||
/* These two functions are what need to be modified to interface other
|
||||
* pixel formats with the library. They need to return values inside a
|
||||
* format like this: (Red/Blue can be reversed.)
|
||||
*
|
||||
* 0000-00GG-GGG0-0000-0RRR-RR00-000B-BBBB
|
||||
*
|
||||
* This is VERY fast to create from 15-bit (NOT 16-bit) RGB/BGR, as
|
||||
* below.
|
||||
*
|
||||
* If you can't return data in this format, you'll have to rebuild the
|
||||
* ExpandedDiff function and DiffTable array to compensate, and possibly
|
||||
* change the blending functions in the Process* functions to handle any
|
||||
* guard-bits and masking.
|
||||
*/
|
||||
|
||||
static inline uint32_t RGBUnpack(pixel i) {
|
||||
uint32_t o = i;
|
||||
o = (o * 0x10001);
|
||||
o = o & 0x03E07C1F;
|
||||
return o;
|
||||
}
|
||||
static inline pixel RGBPack(uint32_t x) {
|
||||
x &= 0x03E07C1F;
|
||||
x |= (x >> 16);
|
||||
return x;
|
||||
}
|
||||
|
||||
void ProcessHQ2x(const pixel * restrict inbuffer, pixel * restrict outbuffer);
|
||||
void ProcessHQ4x(const pixel * restrict inbuffer, pixel * restrict outbuffer);
|
||||
|
||||
#endif /* __PAST_LIBRARY_H */
|
||||
@@ -1,251 +0,0 @@
|
||||
/* snes_ntsc 0.2.2. http://www.slack.net/~ant/ */
|
||||
|
||||
#include "snes_ntsc.h"
|
||||
|
||||
/* Copyright (C) 2006-2007 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
General Public License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version. This
|
||||
module is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details. You should have received a copy of the GNU Lesser General Public
|
||||
License along with this module; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
snes_ntsc_setup_t const snes_ntsc_monochrome = { 0,-1, 0, 0,.2, 0,.2,-.2,-.2,-1, 1, 0, 0 };
|
||||
snes_ntsc_setup_t const snes_ntsc_composite = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 };
|
||||
snes_ntsc_setup_t const snes_ntsc_svideo = { 0, 0, 0, 0,.2, 0,.2, -1, -1, 0, 1, 0, 0 };
|
||||
snes_ntsc_setup_t const snes_ntsc_rgb = { 0, 0, 0, 0,.2, 0,.7, -1, -1,-1, 1, 0, 0 };
|
||||
|
||||
#define alignment_count 3
|
||||
#define burst_count 3
|
||||
#define rescale_in 8
|
||||
#define rescale_out 7
|
||||
|
||||
#define artifacts_mid 1.0f
|
||||
#define fringing_mid 1.0f
|
||||
#define std_decoder_hue 0
|
||||
|
||||
#define rgb_bits 7 /* half normal range to allow for doubled hires pixels */
|
||||
#define gamma_size 32
|
||||
|
||||
#include "snes_ntsc_impl.h"
|
||||
|
||||
/* 3 input pixels -> 8 composite samples */
|
||||
pixel_info_t const snes_ntsc_pixels [alignment_count] = {
|
||||
{ PIXEL_OFFSET( -4, -9 ), { 1, 1, .6667f, 0 } },
|
||||
{ PIXEL_OFFSET( -2, -7 ), { .3333f, 1, 1, .3333f } },
|
||||
{ PIXEL_OFFSET( 0, -5 ), { 0, .6667f, 1, 1 } },
|
||||
};
|
||||
|
||||
static void merge_kernel_fields( snes_ntsc_rgb_t* io )
|
||||
{
|
||||
int n;
|
||||
for ( n = burst_size; n; --n )
|
||||
{
|
||||
snes_ntsc_rgb_t p0 = io [burst_size * 0] + rgb_bias;
|
||||
snes_ntsc_rgb_t p1 = io [burst_size * 1] + rgb_bias;
|
||||
snes_ntsc_rgb_t p2 = io [burst_size * 2] + rgb_bias;
|
||||
/* merge colors without losing precision */
|
||||
io [burst_size * 0] =
|
||||
((p0 + p1 - ((p0 ^ p1) & snes_ntsc_rgb_builder)) >> 1) - rgb_bias;
|
||||
io [burst_size * 1] =
|
||||
((p1 + p2 - ((p1 ^ p2) & snes_ntsc_rgb_builder)) >> 1) - rgb_bias;
|
||||
io [burst_size * 2] =
|
||||
((p2 + p0 - ((p2 ^ p0) & snes_ntsc_rgb_builder)) >> 1) - rgb_bias;
|
||||
++io;
|
||||
}
|
||||
}
|
||||
|
||||
static void correct_errors( snes_ntsc_rgb_t color, snes_ntsc_rgb_t* out )
|
||||
{
|
||||
int n;
|
||||
for ( n = burst_count; n; --n )
|
||||
{
|
||||
unsigned i;
|
||||
for ( i = 0; i < rgb_kernel_size / 2; i++ )
|
||||
{
|
||||
snes_ntsc_rgb_t error = color -
|
||||
out [i ] - out [(i+12)%14+14] - out [(i+10)%14+28] -
|
||||
out [i + 7] - out [i + 5 +14] - out [i + 3 +28];
|
||||
DISTRIBUTE_ERROR( i+3+28, i+5+14, i+7 );
|
||||
}
|
||||
out += alignment_count * rgb_kernel_size;
|
||||
}
|
||||
}
|
||||
|
||||
void snes_ntsc_init( snes_ntsc_t* ntsc, snes_ntsc_setup_t const* setup )
|
||||
{
|
||||
int merge_fields;
|
||||
int entry;
|
||||
init_t impl;
|
||||
if ( !setup )
|
||||
setup = &snes_ntsc_composite;
|
||||
init( &impl, setup );
|
||||
|
||||
merge_fields = setup->merge_fields;
|
||||
if ( setup->artifacts <= -1 && setup->fringing <= -1 )
|
||||
merge_fields = 1;
|
||||
|
||||
for ( entry = 0; entry < snes_ntsc_palette_size; entry++ )
|
||||
{
|
||||
/* Reduce number of significant bits of source color. Clearing the
|
||||
low bits of R and B were least notictable. Modifying green was too
|
||||
noticeable. */
|
||||
int ir = entry >> 8 & 0x1E;
|
||||
int ig = entry >> 4 & 0x1F;
|
||||
int ib = entry << 1 & 0x1E;
|
||||
|
||||
#if SNES_NTSC_BSNES_COLORTBL
|
||||
if ( setup->bsnes_colortbl )
|
||||
{
|
||||
int bgr15 = (ib << 10) | (ig << 5) | ir;
|
||||
unsigned long rgb16 = setup->bsnes_colortbl [bgr15];
|
||||
ir = rgb16 >> 11 & 0x1E;
|
||||
ig = rgb16 >> 6 & 0x1F;
|
||||
ib = rgb16 & 0x1E;
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
float rr = impl.to_float [ir];
|
||||
float gg = impl.to_float [ig];
|
||||
float bb = impl.to_float [ib];
|
||||
|
||||
float y, i, q = RGB_TO_YIQ( rr, gg, bb, y, i );
|
||||
|
||||
int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g );
|
||||
snes_ntsc_rgb_t rgb = PACK_RGB( r, g, b );
|
||||
|
||||
snes_ntsc_rgb_t* out = ntsc->table [entry];
|
||||
gen_kernel( &impl, y, i, q, out );
|
||||
if ( merge_fields )
|
||||
merge_kernel_fields( out );
|
||||
correct_errors( rgb, out );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SNES_NTSC_NO_BLITTERS
|
||||
|
||||
void snes_ntsc_blit( snes_ntsc_t const* ntsc, SNES_NTSC_IN_T const* input, long in_row_width,
|
||||
int burst_phase, int in_width, int in_height, void* rgb_out, long out_pitch )
|
||||
{
|
||||
int chunk_count = (in_width - 1) / snes_ntsc_in_chunk;
|
||||
for ( ; in_height; --in_height )
|
||||
{
|
||||
SNES_NTSC_IN_T const* line_in = input;
|
||||
SNES_NTSC_BEGIN_ROW( ntsc, burst_phase,
|
||||
snes_ntsc_black, snes_ntsc_black, SNES_NTSC_ADJ_IN( *line_in ) );
|
||||
snes_ntsc_out_t* restrict line_out = (snes_ntsc_out_t*) rgb_out;
|
||||
int n;
|
||||
++line_in;
|
||||
|
||||
for ( n = chunk_count; n; --n )
|
||||
{
|
||||
/* order of input and output pixels must not be altered */
|
||||
SNES_NTSC_COLOR_IN( 0, SNES_NTSC_ADJ_IN( line_in [0] ) );
|
||||
SNES_NTSC_RGB_OUT( 0, line_out [0], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 1, line_out [1], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 1, SNES_NTSC_ADJ_IN( line_in [1] ) );
|
||||
SNES_NTSC_RGB_OUT( 2, line_out [2], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 3, line_out [3], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 2, SNES_NTSC_ADJ_IN( line_in [2] ) );
|
||||
SNES_NTSC_RGB_OUT( 4, line_out [4], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 5, line_out [5], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 6, line_out [6], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
line_in += 3;
|
||||
line_out += 7;
|
||||
}
|
||||
|
||||
/* finish final pixels */
|
||||
SNES_NTSC_COLOR_IN( 0, snes_ntsc_black );
|
||||
SNES_NTSC_RGB_OUT( 0, line_out [0], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 1, line_out [1], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 1, snes_ntsc_black );
|
||||
SNES_NTSC_RGB_OUT( 2, line_out [2], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 3, line_out [3], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 2, snes_ntsc_black );
|
||||
SNES_NTSC_RGB_OUT( 4, line_out [4], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 5, line_out [5], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_RGB_OUT( 6, line_out [6], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
burst_phase = (burst_phase + 1) % snes_ntsc_burst_count;
|
||||
input += in_row_width;
|
||||
rgb_out = (char*) rgb_out + out_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void snes_ntsc_blit_hires( snes_ntsc_t const* ntsc, SNES_NTSC_IN_T const* input, long in_row_width,
|
||||
int burst_phase, int in_width, int in_height, void* rgb_out, long out_pitch )
|
||||
{
|
||||
int chunk_count = (in_width - 2) / (snes_ntsc_in_chunk * 2);
|
||||
for ( ; in_height; --in_height )
|
||||
{
|
||||
SNES_NTSC_IN_T const* line_in = input;
|
||||
SNES_NTSC_HIRES_ROW( ntsc, burst_phase,
|
||||
snes_ntsc_black, snes_ntsc_black, snes_ntsc_black,
|
||||
SNES_NTSC_ADJ_IN( line_in [0] ),
|
||||
SNES_NTSC_ADJ_IN( line_in [1] ) );
|
||||
snes_ntsc_out_t* restrict line_out = (snes_ntsc_out_t*) rgb_out;
|
||||
int n;
|
||||
line_in += 2;
|
||||
|
||||
for ( n = chunk_count; n; --n )
|
||||
{
|
||||
/* twice as many input pixels per chunk */
|
||||
SNES_NTSC_COLOR_IN( 0, SNES_NTSC_ADJ_IN( line_in [0] ) );
|
||||
SNES_NTSC_HIRES_OUT( 0, line_out [0], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 1, SNES_NTSC_ADJ_IN( line_in [1] ) );
|
||||
SNES_NTSC_HIRES_OUT( 1, line_out [1], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 2, SNES_NTSC_ADJ_IN( line_in [2] ) );
|
||||
SNES_NTSC_HIRES_OUT( 2, line_out [2], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 3, SNES_NTSC_ADJ_IN( line_in [3] ) );
|
||||
SNES_NTSC_HIRES_OUT( 3, line_out [3], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 4, SNES_NTSC_ADJ_IN( line_in [4] ) );
|
||||
SNES_NTSC_HIRES_OUT( 4, line_out [4], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 5, SNES_NTSC_ADJ_IN( line_in [5] ) );
|
||||
SNES_NTSC_HIRES_OUT( 5, line_out [5], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_HIRES_OUT( 6, line_out [6], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
line_in += 6;
|
||||
line_out += 7;
|
||||
}
|
||||
|
||||
SNES_NTSC_COLOR_IN( 0, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 0, line_out [0], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 1, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 1, line_out [1], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 2, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 2, line_out [2], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 3, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 3, line_out [3], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 4, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 4, line_out [4], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
SNES_NTSC_COLOR_IN( 5, snes_ntsc_black );
|
||||
SNES_NTSC_HIRES_OUT( 5, line_out [5], SNES_NTSC_OUT_DEPTH );
|
||||
SNES_NTSC_HIRES_OUT( 6, line_out [6], SNES_NTSC_OUT_DEPTH );
|
||||
|
||||
burst_phase = (burst_phase + 1) % snes_ntsc_burst_count;
|
||||
input += in_row_width;
|
||||
rgb_out = (char*) rgb_out + out_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,236 +0,0 @@
|
||||
/* SNES NTSC video filter */
|
||||
|
||||
/* snes_ntsc 0.2.2 */
|
||||
#ifndef SNES_NTSC_H
|
||||
#define SNES_NTSC_H
|
||||
|
||||
#include "snes_ntsc_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Image parameters, ranging from -1.0 to 1.0. Actual internal values shown
|
||||
in parenthesis and should remain fairly stable in future versions. */
|
||||
typedef struct snes_ntsc_setup_t
|
||||
{
|
||||
/* Basic parameters */
|
||||
double hue; /* -1 = -180 degrees +1 = +180 degrees */
|
||||
double saturation; /* -1 = grayscale (0.0) +1 = oversaturated colors (2.0) */
|
||||
double contrast; /* -1 = dark (0.5) +1 = light (1.5) */
|
||||
double brightness; /* -1 = dark (0.5) +1 = light (1.5) */
|
||||
double sharpness; /* edge contrast enhancement/blurring */
|
||||
|
||||
/* Advanced parameters */
|
||||
double gamma; /* -1 = dark (1.5) +1 = light (0.5) */
|
||||
double resolution; /* image resolution */
|
||||
double artifacts; /* artifacts caused by color changes */
|
||||
double fringing; /* color artifacts caused by brightness changes */
|
||||
double bleed; /* color bleed (color resolution reduction) */
|
||||
int merge_fields; /* if 1, merges even and odd fields together to reduce flicker */
|
||||
float const* decoder_matrix; /* optional RGB decoder matrix, 6 elements */
|
||||
|
||||
unsigned long const* bsnes_colortbl; /* undocumented; set to 0 */
|
||||
} snes_ntsc_setup_t;
|
||||
|
||||
/* Video format presets */
|
||||
extern snes_ntsc_setup_t const snes_ntsc_composite; /* color bleeding + artifacts */
|
||||
extern snes_ntsc_setup_t const snes_ntsc_svideo; /* color bleeding only */
|
||||
extern snes_ntsc_setup_t const snes_ntsc_rgb; /* crisp image */
|
||||
extern snes_ntsc_setup_t const snes_ntsc_monochrome;/* desaturated + artifacts */
|
||||
|
||||
/* Initializes and adjusts parameters. Can be called multiple times on the same
|
||||
snes_ntsc_t object. Can pass NULL for either parameter. */
|
||||
typedef struct snes_ntsc_t snes_ntsc_t;
|
||||
void snes_ntsc_init( snes_ntsc_t* ntsc, snes_ntsc_setup_t const* setup );
|
||||
|
||||
/* Filters one or more rows of pixels. Input pixel format is set by SNES_NTSC_IN_FORMAT
|
||||
and output RGB depth is set by SNES_NTSC_OUT_DEPTH. Both default to 16-bit RGB.
|
||||
In_row_width is the number of pixels to get to the next input row. Out_pitch
|
||||
is the number of *bytes* to get to the next output row. */
|
||||
void snes_ntsc_blit( snes_ntsc_t const* ntsc, SNES_NTSC_IN_T const* input,
|
||||
long in_row_width, int burst_phase, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch );
|
||||
|
||||
void snes_ntsc_blit_hires( snes_ntsc_t const* ntsc, SNES_NTSC_IN_T const* input,
|
||||
long in_row_width, int burst_phase, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch );
|
||||
|
||||
/* Number of output pixels written by low-res blitter for given input width. Width
|
||||
might be rounded down slightly; use SNES_NTSC_IN_WIDTH() on result to find rounded
|
||||
value. Guaranteed not to round 256 down at all. */
|
||||
#define SNES_NTSC_OUT_WIDTH( in_width ) \
|
||||
((((in_width) - 1) / snes_ntsc_in_chunk + 1) * snes_ntsc_out_chunk)
|
||||
|
||||
/* Number of low-res input pixels that will fit within given output width. Might be
|
||||
rounded down slightly; use SNES_NTSC_OUT_WIDTH() on result to find rounded
|
||||
value. */
|
||||
#define SNES_NTSC_IN_WIDTH( out_width ) \
|
||||
(((out_width) / snes_ntsc_out_chunk - 1) * snes_ntsc_in_chunk + 1)
|
||||
|
||||
|
||||
/* Interface for user-defined custom blitters */
|
||||
|
||||
enum { snes_ntsc_in_chunk = 3 }; /* number of input pixels read per chunk */
|
||||
enum { snes_ntsc_out_chunk = 7 }; /* number of output pixels generated per chunk */
|
||||
enum { snes_ntsc_black = 0 }; /* palette index for black */
|
||||
enum { snes_ntsc_burst_count = 3 }; /* burst phase cycles through 0, 1, and 2 */
|
||||
|
||||
/* Begins outputting row and starts three pixels. First pixel will be cut off a bit.
|
||||
Use snes_ntsc_black for unused pixels. Declares variables, so must be before first
|
||||
statement in a block (unless you're using C++). */
|
||||
#define SNES_NTSC_BEGIN_ROW( ntsc, burst, pixel0, pixel1, pixel2 ) \
|
||||
char const* ktable = \
|
||||
(char const*) (ntsc)->table + burst * (snes_ntsc_burst_size * sizeof (snes_ntsc_rgb_t));\
|
||||
SNES_NTSC_BEGIN_ROW_6_( pixel0, pixel1, pixel2, SNES_NTSC_IN_FORMAT, ktable )
|
||||
|
||||
/* Begins input pixel */
|
||||
#define SNES_NTSC_COLOR_IN( index, color ) \
|
||||
SNES_NTSC_COLOR_IN_( index, color, SNES_NTSC_IN_FORMAT, ktable )
|
||||
|
||||
/* Generates output pixel. Bits can be 24, 16, 15, 14, 32 (treated as 24), or 0:
|
||||
24: RRRRRRRR GGGGGGGG BBBBBBBB (8-8-8 RGB)
|
||||
16: RRRRRGGG GGGBBBBB (5-6-5 RGB)
|
||||
15: RRRRRGG GGGBBBBB (5-5-5 RGB)
|
||||
14: BBBBBGG GGGRRRRR (5-5-5 BGR, native SNES format)
|
||||
0: xxxRRRRR RRRxxGGG GGGGGxxB BBBBBBBx (native internal format; x = junk bits) */
|
||||
#define SNES_NTSC_RGB_OUT( index, rgb_out, bits ) \
|
||||
SNES_NTSC_RGB_OUT_14_( index, rgb_out, bits, 1 )
|
||||
|
||||
/* Hires equivalents */
|
||||
#define SNES_NTSC_HIRES_ROW( ntsc, burst, pixel1, pixel2, pixel3, pixel4, pixel5 ) \
|
||||
char const* ktable = \
|
||||
(char const*) (ntsc)->table + burst * (snes_ntsc_burst_size * sizeof (snes_ntsc_rgb_t));\
|
||||
unsigned const snes_ntsc_pixel1_ = (pixel1);\
|
||||
snes_ntsc_rgb_t const* kernel1 = SNES_NTSC_IN_FORMAT( ktable, snes_ntsc_pixel1_ );\
|
||||
unsigned const snes_ntsc_pixel2_ = (pixel2);\
|
||||
snes_ntsc_rgb_t const* kernel2 = SNES_NTSC_IN_FORMAT( ktable, snes_ntsc_pixel2_ );\
|
||||
unsigned const snes_ntsc_pixel3_ = (pixel3);\
|
||||
snes_ntsc_rgb_t const* kernel3 = SNES_NTSC_IN_FORMAT( ktable, snes_ntsc_pixel3_ );\
|
||||
unsigned const snes_ntsc_pixel4_ = (pixel4);\
|
||||
snes_ntsc_rgb_t const* kernel4 = SNES_NTSC_IN_FORMAT( ktable, snes_ntsc_pixel4_ );\
|
||||
unsigned const snes_ntsc_pixel5_ = (pixel5);\
|
||||
snes_ntsc_rgb_t const* kernel5 = SNES_NTSC_IN_FORMAT( ktable, snes_ntsc_pixel5_ );\
|
||||
snes_ntsc_rgb_t const* kernel0 = kernel1;\
|
||||
snes_ntsc_rgb_t const* kernelx0;\
|
||||
snes_ntsc_rgb_t const* kernelx1 = kernel1;\
|
||||
snes_ntsc_rgb_t const* kernelx2 = kernel1;\
|
||||
snes_ntsc_rgb_t const* kernelx3 = kernel1;\
|
||||
snes_ntsc_rgb_t const* kernelx4 = kernel1;\
|
||||
snes_ntsc_rgb_t const* kernelx5 = kernel1
|
||||
|
||||
#define SNES_NTSC_HIRES_OUT( x, rgb_out, bits ) {\
|
||||
snes_ntsc_rgb_t raw_ =\
|
||||
kernel0 [ x ] + kernel2 [(x+5)%7+14] + kernel4 [(x+3)%7+28] +\
|
||||
kernelx0 [(x+7)%7+7] + kernelx2 [(x+5)%7+21] + kernelx4 [(x+3)%7+35] +\
|
||||
kernel1 [(x+6)%7 ] + kernel3 [(x+4)%7+14] + kernel5 [(x+2)%7+28] +\
|
||||
kernelx1 [(x+6)%7+7] + kernelx3 [(x+4)%7+21] + kernelx5 [(x+2)%7+35];\
|
||||
SNES_NTSC_CLAMP_( raw_, 0 );\
|
||||
SNES_NTSC_RGB_OUT_( rgb_out, (bits), 0 );\
|
||||
}
|
||||
|
||||
|
||||
/* private */
|
||||
enum { snes_ntsc_entry_size = 128 };
|
||||
enum { snes_ntsc_palette_size = 0x2000 };
|
||||
typedef unsigned long snes_ntsc_rgb_t;
|
||||
struct snes_ntsc_t {
|
||||
snes_ntsc_rgb_t table [snes_ntsc_palette_size] [snes_ntsc_entry_size];
|
||||
};
|
||||
enum { snes_ntsc_burst_size = snes_ntsc_entry_size / snes_ntsc_burst_count };
|
||||
|
||||
#define SNES_NTSC_RGB16( ktable, n ) \
|
||||
(snes_ntsc_rgb_t const*) (ktable + ((n & 0x001E) | (n >> 1 & 0x03E0) | (n >> 2 & 0x3C00)) * \
|
||||
(snes_ntsc_entry_size / 2 * sizeof (snes_ntsc_rgb_t)))
|
||||
|
||||
#define SNES_NTSC_BGR15( ktable, n ) \
|
||||
(snes_ntsc_rgb_t const*) (ktable + ((n << 9 & 0x3C00) | (n & 0x03E0) | (n >> 10 & 0x001E)) * \
|
||||
(snes_ntsc_entry_size / 2 * sizeof (snes_ntsc_rgb_t)))
|
||||
|
||||
/* common 3->7 ntsc macros */
|
||||
#define SNES_NTSC_BEGIN_ROW_6_( pixel0, pixel1, pixel2, ENTRY, table ) \
|
||||
unsigned const snes_ntsc_pixel0_ = (pixel0);\
|
||||
snes_ntsc_rgb_t const* kernel0 = ENTRY( table, snes_ntsc_pixel0_ );\
|
||||
unsigned const snes_ntsc_pixel1_ = (pixel1);\
|
||||
snes_ntsc_rgb_t const* kernel1 = ENTRY( table, snes_ntsc_pixel1_ );\
|
||||
unsigned const snes_ntsc_pixel2_ = (pixel2);\
|
||||
snes_ntsc_rgb_t const* kernel2 = ENTRY( table, snes_ntsc_pixel2_ );\
|
||||
snes_ntsc_rgb_t const* kernelx0;\
|
||||
snes_ntsc_rgb_t const* kernelx1 = kernel0;\
|
||||
snes_ntsc_rgb_t const* kernelx2 = kernel0
|
||||
|
||||
#define SNES_NTSC_RGB_OUT_14_( x, rgb_out, bits, shift ) {\
|
||||
snes_ntsc_rgb_t raw_ =\
|
||||
kernel0 [x ] + kernel1 [(x+12)%7+14] + kernel2 [(x+10)%7+28] +\
|
||||
kernelx0 [(x+7)%14] + kernelx1 [(x+ 5)%7+21] + kernelx2 [(x+ 3)%7+35];\
|
||||
SNES_NTSC_CLAMP_( raw_, shift );\
|
||||
SNES_NTSC_RGB_OUT_( rgb_out, bits, shift );\
|
||||
}
|
||||
|
||||
/* common ntsc macros */
|
||||
#define snes_ntsc_rgb_builder ((1L << 21) | (1 << 11) | (1 << 1))
|
||||
#define snes_ntsc_clamp_mask (snes_ntsc_rgb_builder * 3 / 2)
|
||||
#define snes_ntsc_clamp_add (snes_ntsc_rgb_builder * 0x101)
|
||||
#define SNES_NTSC_CLAMP_( io, shift ) {\
|
||||
snes_ntsc_rgb_t sub = (io) >> (9-(shift)) & snes_ntsc_clamp_mask;\
|
||||
snes_ntsc_rgb_t clamp = snes_ntsc_clamp_add - sub;\
|
||||
io |= clamp;\
|
||||
clamp -= sub;\
|
||||
io &= clamp;\
|
||||
}
|
||||
|
||||
#define SNES_NTSC_COLOR_IN_( index, color, ENTRY, table ) {\
|
||||
unsigned color_;\
|
||||
kernelx##index = kernel##index;\
|
||||
kernel##index = (color_ = (color), ENTRY( table, color_ ));\
|
||||
}
|
||||
|
||||
/* x is always zero except in snes_ntsc library */
|
||||
/* original routine */
|
||||
#if 0
|
||||
#define SNES_NTSC_RGB_OUT_( rgb_out, bits, x ) {\
|
||||
if ( bits == 16 )\
|
||||
rgb_out = (raw_>>(13-x)& 0xF800)|(raw_>>(8-x)&0x07E0)|(raw_>>(4-x)&0x001F);\
|
||||
if ( bits == 24 || bits == 32 )\
|
||||
rgb_out = (raw_>>(5-x)&0xFF0000)|(raw_>>(3-x)&0xFF00)|(raw_>>(1-x)&0xFF);\
|
||||
if ( bits == 15 )\
|
||||
rgb_out = (raw_>>(14-x)& 0x7C00)|(raw_>>(9-x)&0x03E0)|(raw_>>(4-x)&0x001F);\
|
||||
if ( bits == 14 )\
|
||||
rgb_out = (raw_>>(24-x)& 0x001F)|(raw_>>(9-x)&0x03E0)|(raw_<<(6+x)&0x7C00);\
|
||||
if ( bits == 0 )\
|
||||
rgb_out = raw_ << x;\
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SNES_NTSC_RGB_OUT_( rgb_out, bits, x ) {\
|
||||
rgb_out = (raw_>>(14-x)& 0x7C00)|(raw_>>(9-x)&0x03E0)|(raw_>>(4-x)&0x001F);\
|
||||
}
|
||||
|
||||
// Custom SSNES routine for 15 bit.
|
||||
|
||||
/* custom bsnes routine -- hooks into bsnes colortable */
|
||||
#if 0
|
||||
#define SNES_NTSC_RGB_OUT_( rgb_out, bits, x ) {\
|
||||
if ( bits == 16 ) {\
|
||||
rgb_out = (raw_>>(13-x)& 0xF800)|(raw_>>(8-x)&0x07E0)|(raw_>>(4-x)&0x001F);\
|
||||
rgb_out = ((rgb_out&0xf800)>>11)|((rgb_out&0x07c0)>>1)|((rgb_out&0x001f)<<10);\
|
||||
rgb_out = colortable[rgb_out];\
|
||||
} else if ( bits == 24 || bits == 32 ) {\
|
||||
rgb_out = (raw_>>(5-x)&0xFF0000)|(raw_>>(3-x)&0xFF00)|(raw_>>(1-x)&0xFF);\
|
||||
rgb_out = ((rgb_out&0xf80000)>>19)|((rgb_out&0x00f800)>>6)|((rgb_out&0x0000f8)<<7);\
|
||||
rgb_out = colortable[rgb_out];\
|
||||
} else if ( bits == 15 ) {\
|
||||
rgb_out = (raw_>>(14-x)& 0x7C00)|(raw_>>(9-x)&0x03E0)|(raw_>>(4-x)&0x001F);\
|
||||
rgb_out = ((rgb_out&0x7c00)>>10)|((rgb_out&0x03e0))|((rgb_out&0x001f)<<10);\
|
||||
rgb_out = colortable[rgb_out];\
|
||||
} else {\
|
||||
rgb_out = raw_ << x;\
|
||||
}\
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
/* Configure library by modifying this file */
|
||||
|
||||
#ifndef SNES_NTSC_CONFIG_H
|
||||
#define SNES_NTSC_CONFIG_H
|
||||
|
||||
/* Format of source pixels */
|
||||
/* #define SNES_NTSC_IN_FORMAT SNES_NTSC_RGB16 */
|
||||
#define SNES_NTSC_IN_FORMAT SNES_NTSC_BGR15
|
||||
|
||||
/* The following affect the built-in blitter only; a custom blitter can
|
||||
handle things however it wants. */
|
||||
|
||||
/* Bits per pixel of output. Can be 15, 16, 32, or 24 (same as 32). */
|
||||
#define SNES_NTSC_OUT_DEPTH 15
|
||||
|
||||
/* Type of input pixel values */
|
||||
#define SNES_NTSC_IN_T unsigned short
|
||||
|
||||
/* Each raw pixel input value is passed through this. You might want to mask
|
||||
the pixel index if you use the high bits as flags, etc. */
|
||||
#define SNES_NTSC_ADJ_IN( in ) (((in >> 10) & 0x1F) | (in & 0x3E0) | ((in << 10) & 0x7C00))
|
||||
|
||||
|
||||
/* For each pixel, this is the basic operation:
|
||||
output_color = SNES_NTSC_ADJ_IN( SNES_NTSC_IN_T ) */
|
||||
|
||||
#endif
|
||||
@@ -1,439 +0,0 @@
|
||||
/* snes_ntsc 0.2.2. http://www.slack.net/~ant/ */
|
||||
|
||||
/* Common implementation of NTSC filters */
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Copyright (C) 2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
General Public License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version. This
|
||||
module is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details. You should have received a copy of the GNU Lesser General Public
|
||||
License along with this module; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#define DISABLE_CORRECTION 0
|
||||
|
||||
#undef PI
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
#ifndef LUMA_CUTOFF
|
||||
#define LUMA_CUTOFF 0.20
|
||||
#endif
|
||||
#ifndef gamma_size
|
||||
#define gamma_size 1
|
||||
#endif
|
||||
#ifndef rgb_bits
|
||||
#define rgb_bits 8
|
||||
#endif
|
||||
#ifndef artifacts_max
|
||||
#define artifacts_max (artifacts_mid * 1.5f)
|
||||
#endif
|
||||
#ifndef fringing_max
|
||||
#define fringing_max (fringing_mid * 2)
|
||||
#endif
|
||||
#ifndef STD_HUE_CONDITION
|
||||
#define STD_HUE_CONDITION( setup ) 1
|
||||
#endif
|
||||
|
||||
#define ext_decoder_hue (std_decoder_hue + 15)
|
||||
#define rgb_unit (1 << rgb_bits)
|
||||
#define rgb_offset (rgb_unit * 2 + 0.5f)
|
||||
|
||||
enum { burst_size = snes_ntsc_entry_size / burst_count };
|
||||
enum { kernel_half = 16 };
|
||||
enum { kernel_size = kernel_half * 2 + 1 };
|
||||
|
||||
typedef struct init_t
|
||||
{
|
||||
float to_rgb [burst_count * 6];
|
||||
float to_float [gamma_size];
|
||||
float contrast;
|
||||
float brightness;
|
||||
float artifacts;
|
||||
float fringing;
|
||||
float kernel [rescale_out * kernel_size * 2];
|
||||
} init_t;
|
||||
|
||||
#define ROTATE_IQ( i, q, sin_b, cos_b ) {\
|
||||
float t;\
|
||||
t = i * cos_b - q * sin_b;\
|
||||
q = i * sin_b + q * cos_b;\
|
||||
i = t;\
|
||||
}
|
||||
|
||||
static void init_filters( init_t* impl, snes_ntsc_setup_t const* setup )
|
||||
{
|
||||
#if rescale_out > 1
|
||||
float kernels [kernel_size * 2];
|
||||
#else
|
||||
float* const kernels = impl->kernel;
|
||||
#endif
|
||||
|
||||
/* generate luma (y) filter using sinc kernel */
|
||||
{
|
||||
/* sinc with rolloff (dsf) */
|
||||
float const rolloff = 1 + (float) setup->sharpness * (float) 0.032;
|
||||
float const maxh = 32;
|
||||
float const pow_a_n = (float) pow( rolloff, maxh );
|
||||
float sum;
|
||||
int i;
|
||||
/* quadratic mapping to reduce negative (blurring) range */
|
||||
float to_angle = (float) setup->resolution + 1;
|
||||
to_angle = PI / maxh * (float) LUMA_CUTOFF * (to_angle * to_angle + 1);
|
||||
|
||||
kernels [kernel_size * 3 / 2] = maxh; /* default center value */
|
||||
for ( i = 0; i < kernel_half * 2 + 1; i++ )
|
||||
{
|
||||
int x = i - kernel_half;
|
||||
float angle = x * to_angle;
|
||||
/* instability occurs at center point with rolloff very close to 1.0 */
|
||||
if ( x || pow_a_n > (float) 1.056 || pow_a_n < (float) 0.981 )
|
||||
{
|
||||
float rolloff_cos_a = rolloff * (float) cos( angle );
|
||||
float num = 1 - rolloff_cos_a -
|
||||
pow_a_n * (float) cos( maxh * angle ) +
|
||||
pow_a_n * rolloff * (float) cos( (maxh - 1) * angle );
|
||||
float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff;
|
||||
float dsf = num / den;
|
||||
kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - (float) 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
/* apply blackman window and find sum */
|
||||
sum = 0;
|
||||
for ( i = 0; i < kernel_half * 2 + 1; i++ )
|
||||
{
|
||||
float x = PI * 2 / (kernel_half * 2) * i;
|
||||
float blackman = 0.42f - 0.5f * (float) cos( x ) + 0.08f * (float) cos( x * 2 );
|
||||
sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman);
|
||||
}
|
||||
|
||||
/* normalize kernel */
|
||||
sum = 1.0f / sum;
|
||||
for ( i = 0; i < kernel_half * 2 + 1; i++ )
|
||||
{
|
||||
int x = kernel_size * 3 / 2 - kernel_half + i;
|
||||
kernels [x] *= sum;
|
||||
assert( kernels [x] == kernels [x] ); /* catch numerical instability */
|
||||
}
|
||||
}
|
||||
|
||||
/* generate chroma (iq) filter using gaussian kernel */
|
||||
{
|
||||
float const cutoff_factor = -0.03125f;
|
||||
float cutoff = (float) setup->bleed;
|
||||
int i;
|
||||
|
||||
if ( cutoff < 0 )
|
||||
{
|
||||
/* keep extreme value accessible only near upper end of scale (1.0) */
|
||||
cutoff *= cutoff;
|
||||
cutoff *= cutoff;
|
||||
cutoff *= cutoff;
|
||||
cutoff *= -30.0f / 0.65f;
|
||||
}
|
||||
cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff;
|
||||
|
||||
for ( i = -kernel_half; i <= kernel_half; i++ )
|
||||
kernels [kernel_size / 2 + i] = (float) exp( i * i * cutoff );
|
||||
|
||||
/* normalize even and odd phases separately */
|
||||
for ( i = 0; i < 2; i++ )
|
||||
{
|
||||
float sum = 0;
|
||||
int x;
|
||||
for ( x = i; x < kernel_size; x += 2 )
|
||||
sum += kernels [x];
|
||||
|
||||
sum = 1.0f / sum;
|
||||
for ( x = i; x < kernel_size; x += 2 )
|
||||
{
|
||||
kernels [x] *= sum;
|
||||
assert( kernels [x] == kernels [x] ); /* catch numerical instability */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
printf( "luma:\n" );
|
||||
for ( i = kernel_size; i < kernel_size * 2; i++ )
|
||||
printf( "%f\n", kernels [i] );
|
||||
printf( "chroma:\n" );
|
||||
for ( i = 0; i < kernel_size; i++ )
|
||||
printf( "%f\n", kernels [i] );
|
||||
*/
|
||||
|
||||
/* generate linear rescale kernels */
|
||||
#if rescale_out > 1
|
||||
{
|
||||
float weight = 1.0f;
|
||||
float* out = impl->kernel;
|
||||
int n = rescale_out;
|
||||
do
|
||||
{
|
||||
float remain = 0;
|
||||
int i;
|
||||
weight -= 1.0f / rescale_in;
|
||||
for ( i = 0; i < kernel_size * 2; i++ )
|
||||
{
|
||||
float cur = kernels [i];
|
||||
float m = cur * weight;
|
||||
*out++ = m + remain;
|
||||
remain = cur - m;
|
||||
}
|
||||
}
|
||||
while ( --n );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static float const default_decoder [6] =
|
||||
{ 0.956f, 0.621f, -0.272f, -0.647f, -1.105f, 1.702f };
|
||||
|
||||
static void init( init_t* impl, snes_ntsc_setup_t const* setup )
|
||||
{
|
||||
impl->brightness = (float) setup->brightness * (0.5f * rgb_unit) + rgb_offset;
|
||||
impl->contrast = (float) setup->contrast * (0.5f * rgb_unit) + rgb_unit;
|
||||
#ifdef default_palette_contrast
|
||||
if ( !setup->palette )
|
||||
impl->contrast *= default_palette_contrast;
|
||||
#endif
|
||||
|
||||
impl->artifacts = (float) setup->artifacts;
|
||||
if ( impl->artifacts > 0 )
|
||||
impl->artifacts *= artifacts_max - artifacts_mid;
|
||||
impl->artifacts = impl->artifacts * artifacts_mid + artifacts_mid;
|
||||
|
||||
impl->fringing = (float) setup->fringing;
|
||||
if ( impl->fringing > 0 )
|
||||
impl->fringing *= fringing_max - fringing_mid;
|
||||
impl->fringing = impl->fringing * fringing_mid + fringing_mid;
|
||||
|
||||
init_filters( impl, setup );
|
||||
|
||||
/* generate gamma table */
|
||||
if ( gamma_size > 1 )
|
||||
{
|
||||
float const to_float = 1.0f / (gamma_size - (gamma_size > 1));
|
||||
float const gamma = 1.1333f - (float) setup->gamma * 0.5f;
|
||||
/* match common PC's 2.2 gamma to TV's 2.65 gamma */
|
||||
int i;
|
||||
for ( i = 0; i < gamma_size; i++ )
|
||||
impl->to_float [i] =
|
||||
(float) pow( i * to_float, gamma ) * impl->contrast + impl->brightness;
|
||||
}
|
||||
|
||||
/* setup decoder matricies */
|
||||
{
|
||||
float hue = (float) setup->hue * PI + PI / 180 * ext_decoder_hue;
|
||||
float sat = (float) setup->saturation + 1;
|
||||
float const* decoder = setup->decoder_matrix;
|
||||
if ( !decoder )
|
||||
{
|
||||
decoder = default_decoder;
|
||||
if ( STD_HUE_CONDITION( setup ) )
|
||||
hue += PI / 180 * (std_decoder_hue - ext_decoder_hue);
|
||||
}
|
||||
|
||||
{
|
||||
float s = (float) sin( hue ) * sat;
|
||||
float c = (float) cos( hue ) * sat;
|
||||
float* out = impl->to_rgb;
|
||||
int n;
|
||||
|
||||
n = burst_count;
|
||||
do
|
||||
{
|
||||
float const* in = decoder;
|
||||
int n = 3;
|
||||
do
|
||||
{
|
||||
float i = *in++;
|
||||
float q = *in++;
|
||||
*out++ = i * c - q * s;
|
||||
*out++ = i * s + q * c;
|
||||
}
|
||||
while ( --n );
|
||||
if ( burst_count <= 1 )
|
||||
break;
|
||||
ROTATE_IQ( s, c, 0.866025f, -0.5f ); /* +120 degrees */
|
||||
}
|
||||
while ( --n );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* kernel generation */
|
||||
|
||||
#define RGB_TO_YIQ( r, g, b, y, i ) (\
|
||||
(y = (r) * 0.299f + (g) * 0.587f + (b) * 0.114f),\
|
||||
(i = (r) * 0.596f - (g) * 0.275f - (b) * 0.321f),\
|
||||
((r) * 0.212f - (g) * 0.523f + (b) * 0.311f)\
|
||||
)
|
||||
|
||||
#define YIQ_TO_RGB( y, i, q, to_rgb, type, r, g ) (\
|
||||
r = (type) (y + to_rgb [0] * i + to_rgb [1] * q),\
|
||||
g = (type) (y + to_rgb [2] * i + to_rgb [3] * q),\
|
||||
(type) (y + to_rgb [4] * i + to_rgb [5] * q)\
|
||||
)
|
||||
|
||||
#define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1)
|
||||
|
||||
enum { rgb_kernel_size = burst_size / alignment_count };
|
||||
enum { rgb_bias = rgb_unit * 2 * snes_ntsc_rgb_builder };
|
||||
|
||||
typedef struct pixel_info_t
|
||||
{
|
||||
int offset;
|
||||
float negate;
|
||||
float kernel [4];
|
||||
} pixel_info_t;
|
||||
|
||||
#if rescale_in > 1
|
||||
#define PIXEL_OFFSET_( ntsc, scaled ) \
|
||||
(kernel_size / 2 + ntsc + (scaled != 0) + (rescale_out - scaled) % rescale_out + \
|
||||
(kernel_size * 2 * scaled))
|
||||
|
||||
#define PIXEL_OFFSET( ntsc, scaled ) \
|
||||
PIXEL_OFFSET_( ((ntsc) - (scaled) / rescale_out * rescale_in),\
|
||||
(((scaled) + rescale_out * 10) % rescale_out) ),\
|
||||
(1.0f - (((ntsc) + 100) & 2))
|
||||
#else
|
||||
#define PIXEL_OFFSET( ntsc, scaled ) \
|
||||
(kernel_size / 2 + (ntsc) - (scaled)),\
|
||||
(1.0f - (((ntsc) + 100) & 2))
|
||||
#endif
|
||||
|
||||
extern pixel_info_t const snes_ntsc_pixels [alignment_count];
|
||||
|
||||
/* Generate pixel at all burst phases and column alignments */
|
||||
static void gen_kernel( init_t* impl, float y, float i, float q, snes_ntsc_rgb_t* out )
|
||||
{
|
||||
/* generate for each scanline burst phase */
|
||||
float const* to_rgb = impl->to_rgb;
|
||||
int burst_remain = burst_count;
|
||||
y -= rgb_offset;
|
||||
do
|
||||
{
|
||||
/* Encode yiq into *two* composite signals (to allow control over artifacting).
|
||||
Convolve these with kernels which: filter respective components, apply
|
||||
sharpening, and rescale horizontally. Convert resulting yiq to rgb and pack
|
||||
into integer. Based on algorithm by NewRisingSun. */
|
||||
pixel_info_t const* pixel = snes_ntsc_pixels;
|
||||
int alignment_remain = alignment_count;
|
||||
do
|
||||
{
|
||||
/* negate is -1 when composite starts at odd multiple of 2 */
|
||||
float const yy = y * impl->fringing * pixel->negate;
|
||||
float const ic0 = (i + yy) * pixel->kernel [0];
|
||||
float const qc1 = (q + yy) * pixel->kernel [1];
|
||||
float const ic2 = (i - yy) * pixel->kernel [2];
|
||||
float const qc3 = (q - yy) * pixel->kernel [3];
|
||||
|
||||
float const factor = impl->artifacts * pixel->negate;
|
||||
float const ii = i * factor;
|
||||
float const yc0 = (y + ii) * pixel->kernel [0];
|
||||
float const yc2 = (y - ii) * pixel->kernel [2];
|
||||
|
||||
float const qq = q * factor;
|
||||
float const yc1 = (y + qq) * pixel->kernel [1];
|
||||
float const yc3 = (y - qq) * pixel->kernel [3];
|
||||
|
||||
float const* k = &impl->kernel [pixel->offset];
|
||||
int n;
|
||||
++pixel;
|
||||
for ( n = rgb_kernel_size; n; --n )
|
||||
{
|
||||
float i = k[0]*ic0 + k[2]*ic2;
|
||||
float q = k[1]*qc1 + k[3]*qc3;
|
||||
float y = k[kernel_size+0]*yc0 + k[kernel_size+1]*yc1 +
|
||||
k[kernel_size+2]*yc2 + k[kernel_size+3]*yc3 + rgb_offset;
|
||||
if ( rescale_out <= 1 )
|
||||
k--;
|
||||
else if ( k < &impl->kernel [kernel_size * 2 * (rescale_out - 1)] )
|
||||
k += kernel_size * 2 - 1;
|
||||
else
|
||||
k -= kernel_size * 2 * (rescale_out - 1) + 2;
|
||||
{
|
||||
int r, g, b = YIQ_TO_RGB( y, i, q, to_rgb, int, r, g );
|
||||
*out++ = PACK_RGB( r, g, b ) - rgb_bias;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ( alignment_count > 1 && --alignment_remain );
|
||||
|
||||
if ( burst_count <= 1 )
|
||||
break;
|
||||
|
||||
to_rgb += 6;
|
||||
|
||||
ROTATE_IQ( i, q, -0.866025f, -0.5f ); /* -120 degrees */
|
||||
}
|
||||
while ( --burst_remain );
|
||||
}
|
||||
|
||||
static void correct_errors( snes_ntsc_rgb_t color, snes_ntsc_rgb_t* out );
|
||||
|
||||
#if DISABLE_CORRECTION
|
||||
#define CORRECT_ERROR( a ) { out [i] += rgb_bias; }
|
||||
#define DISTRIBUTE_ERROR( a, b, c ) { out [i] += rgb_bias; }
|
||||
#else
|
||||
#define CORRECT_ERROR( a ) { out [a] += error; }
|
||||
#define DISTRIBUTE_ERROR( a, b, c ) {\
|
||||
snes_ntsc_rgb_t fourth = (error + 2 * snes_ntsc_rgb_builder) >> 2;\
|
||||
fourth &= (rgb_bias >> 1) - snes_ntsc_rgb_builder;\
|
||||
fourth -= rgb_bias >> 2;\
|
||||
out [a] += fourth;\
|
||||
out [b] += fourth;\
|
||||
out [c] += fourth;\
|
||||
out [i] += error - (fourth * 3);\
|
||||
}
|
||||
#endif
|
||||
|
||||
#define RGB_PALETTE_OUT( rgb, out_ )\
|
||||
{\
|
||||
unsigned char* out = (out_);\
|
||||
snes_ntsc_rgb_t clamped = (rgb);\
|
||||
SNES_NTSC_CLAMP_( clamped, (8 - rgb_bits) );\
|
||||
out [0] = (unsigned char) (clamped >> 21);\
|
||||
out [1] = (unsigned char) (clamped >> 11);\
|
||||
out [2] = (unsigned char) (clamped >> 1);\
|
||||
}
|
||||
|
||||
/* blitter related */
|
||||
|
||||
#ifndef restrict
|
||||
#if defined (__GNUC__)
|
||||
#define restrict __restrict__
|
||||
#elif defined (_MSC_VER) && _MSC_VER > 1300
|
||||
#define restrict __restrict
|
||||
#else
|
||||
/* no support for restricted pointers */
|
||||
#define restrict
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if SNES_NTSC_OUT_DEPTH <= 16
|
||||
#if USHRT_MAX == 0xFFFF
|
||||
typedef unsigned short snes_ntsc_out_t;
|
||||
#else
|
||||
#error "Need 16-bit int type"
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if UINT_MAX == 0xFFFFFFFF
|
||||
typedef unsigned int snes_ntsc_out_t;
|
||||
#elif ULONG_MAX == 0xFFFFFFFF
|
||||
typedef unsigned long snes_ntsc_out_t;
|
||||
#else
|
||||
#error "Need 32-bit int type"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+5
-8
@@ -59,13 +59,10 @@ static void* sdl_input_init(void)
|
||||
sdl->num_buttons[i] = SDL_JoystickNumButtons(sdl->joysticks[i]);
|
||||
sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
SSNES_WARN("Desired SDL joystick #%u on port %u, but SDL can only detect %u joysticks ...\n",
|
||||
g_settings.input.joypad_map[i], i + 1, sdl->num_joysticks);
|
||||
}
|
||||
}
|
||||
|
||||
sdl->use_keyboard = true;
|
||||
|
||||
return sdl;
|
||||
}
|
||||
|
||||
@@ -146,7 +143,7 @@ static bool sdl_axis_pressed(sdl_input_t *sdl, int port_num, uint32_t joyaxis)
|
||||
|
||||
static bool sdl_is_pressed(sdl_input_t *sdl, int port_num, const struct snes_keybind *key)
|
||||
{
|
||||
if (sdl_key_pressed(key->key))
|
||||
if (sdl->use_keyboard && sdl_key_pressed(key->key))
|
||||
return true;
|
||||
if (sdl->joysticks[port_num] == NULL)
|
||||
return false;
|
||||
@@ -251,7 +248,7 @@ static int16_t sdl_input_state(void *data, const struct snes_keybind **binds, bo
|
||||
switch (device)
|
||||
{
|
||||
case SNES_DEVICE_JOYPAD:
|
||||
return sdl_joypad_device_state(data, binds, port == SNES_PORT_1 ? 0 : 1, device, index, id);
|
||||
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_1) ? 0 : 1, device, index, id);
|
||||
case SNES_DEVICE_MULTITAP:
|
||||
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_2) ? 1 + index : 0, device, index, id);
|
||||
case SNES_DEVICE_MOUSE:
|
||||
@@ -327,7 +324,7 @@ static void sdl_input_poll(void *data)
|
||||
*sdl->should_resize = true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ typedef struct sdl_input
|
||||
unsigned num_buttons[MAX_PLAYERS];
|
||||
unsigned num_hats[MAX_PLAYERS];
|
||||
unsigned num_joysticks;
|
||||
bool use_keyboard;
|
||||
|
||||
// A video driver could pre-init with the SDL driver and have it handle resizing events...
|
||||
bool *quitting;
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/* 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 "SDL.h"
|
||||
#include <stdbool.h>
|
||||
#include "general.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "ssnes_sdl_input.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
typedef struct x11_input
|
||||
{
|
||||
sdl_input_t *sdl;
|
||||
Display *display;
|
||||
char state[32];
|
||||
} x11_input_t;
|
||||
|
||||
struct key_bind
|
||||
{
|
||||
int x;
|
||||
int sdl;
|
||||
};
|
||||
|
||||
static int keysym_lut[SDLK_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_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 },
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void* x_input_init(void)
|
||||
{
|
||||
x11_input_t *x11 = calloc(1, sizeof(*x11));
|
||||
if (!x11)
|
||||
return NULL;
|
||||
|
||||
x11->display = XOpenDisplay(NULL);
|
||||
if (!x11->display)
|
||||
{
|
||||
free(x11);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
x11->sdl = input_sdl.init();
|
||||
if (!x11->sdl)
|
||||
{
|
||||
free(x11);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
init_lut();
|
||||
|
||||
x11->sdl->use_keyboard = false;
|
||||
return x11;
|
||||
}
|
||||
|
||||
static bool x_key_pressed(x11_input_t *x11, int key)
|
||||
{
|
||||
key = keysym_lut[key];
|
||||
int keycode = XKeysymToKeycode(x11->display, key);
|
||||
bool ret = x11->state[keycode >> 3] & (1 << (keycode & 7));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool x_is_pressed(x11_input_t *x11, const struct snes_keybind *binds, unsigned id)
|
||||
{
|
||||
for (int i = 0; binds[i].id != -1; i++)
|
||||
{
|
||||
if (binds[i].id == id)
|
||||
return x_key_pressed(x11, binds[i].key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool x_bind_button_pressed(void *data, int key)
|
||||
{
|
||||
x11_input_t *x11 = data;
|
||||
bool pressed = x_is_pressed(x11, g_settings.input.binds[0], key);
|
||||
if (!pressed)
|
||||
return input_sdl.key_pressed(x11->sdl, key);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static int16_t x_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
x11_input_t *x11 = data;
|
||||
bool pressed = false;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case SNES_DEVICE_JOYPAD:
|
||||
pressed = x_is_pressed(x11, binds[(port == SNES_PORT_1) ? 0 : 1], id);
|
||||
if (!pressed)
|
||||
pressed = input_sdl.input_state(x11->sdl, binds, port, device, index, id);
|
||||
return pressed;
|
||||
|
||||
case SNES_DEVICE_MULTITAP:
|
||||
pressed = x_is_pressed(x11, binds[(port == SNES_PORT_2) ? 1 + index : 0], id);
|
||||
if (!pressed)
|
||||
pressed = input_sdl.input_state(x11->sdl, binds, port, device, index, id);
|
||||
return pressed;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void x_input_free(void *data)
|
||||
{
|
||||
x11_input_t *x11 = data;
|
||||
input_sdl.free(x11->sdl);
|
||||
XCloseDisplay(x11->display);
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void x_input_poll(void *data)
|
||||
{
|
||||
x11_input_t *x11 = data;
|
||||
XQueryKeymap(x11->display, x11->state);
|
||||
input_sdl.poll(x11->sdl);
|
||||
}
|
||||
|
||||
const input_driver_t input_x = {
|
||||
.init = x_input_init,
|
||||
.poll = x_input_poll,
|
||||
.input_state = x_input_state,
|
||||
.key_pressed = x_bind_button_pressed,
|
||||
.free = x_input_free,
|
||||
.ident = "x"
|
||||
};
|
||||
|
||||
Executable
+133
@@ -0,0 +1,133 @@
|
||||
#ifndef LIBSNES_HPP
|
||||
#define LIBSNES_HPP
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SNES_PORT_1 0
|
||||
#define SNES_PORT_2 1
|
||||
|
||||
#define SNES_DEVICE_NONE 0
|
||||
#define SNES_DEVICE_JOYPAD 1
|
||||
#define SNES_DEVICE_MULTITAP 2
|
||||
#define SNES_DEVICE_MOUSE 3
|
||||
#define SNES_DEVICE_SUPER_SCOPE 4
|
||||
#define SNES_DEVICE_JUSTIFIER 5
|
||||
#define SNES_DEVICE_JUSTIFIERS 6
|
||||
|
||||
#define SNES_DEVICE_ID_JOYPAD_B 0
|
||||
#define SNES_DEVICE_ID_JOYPAD_Y 1
|
||||
#define SNES_DEVICE_ID_JOYPAD_SELECT 2
|
||||
#define SNES_DEVICE_ID_JOYPAD_START 3
|
||||
#define SNES_DEVICE_ID_JOYPAD_UP 4
|
||||
#define SNES_DEVICE_ID_JOYPAD_DOWN 5
|
||||
#define SNES_DEVICE_ID_JOYPAD_LEFT 6
|
||||
#define SNES_DEVICE_ID_JOYPAD_RIGHT 7
|
||||
#define SNES_DEVICE_ID_JOYPAD_A 8
|
||||
#define SNES_DEVICE_ID_JOYPAD_X 9
|
||||
#define SNES_DEVICE_ID_JOYPAD_L 10
|
||||
#define SNES_DEVICE_ID_JOYPAD_R 11
|
||||
|
||||
#define SNES_DEVICE_ID_MOUSE_X 0
|
||||
#define SNES_DEVICE_ID_MOUSE_Y 1
|
||||
#define SNES_DEVICE_ID_MOUSE_LEFT 2
|
||||
#define SNES_DEVICE_ID_MOUSE_RIGHT 3
|
||||
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_X 0
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_Y 1
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_TRIGGER 2
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_CURSOR 3
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_TURBO 4
|
||||
#define SNES_DEVICE_ID_SUPER_SCOPE_PAUSE 5
|
||||
|
||||
#define SNES_DEVICE_ID_JUSTIFIER_X 0
|
||||
#define SNES_DEVICE_ID_JUSTIFIER_Y 1
|
||||
#define SNES_DEVICE_ID_JUSTIFIER_TRIGGER 2
|
||||
#define SNES_DEVICE_ID_JUSTIFIER_START 3
|
||||
|
||||
#define SNES_REGION_NTSC 0
|
||||
#define SNES_REGION_PAL 1
|
||||
|
||||
#define SNES_MEMORY_CARTRIDGE_RAM 0
|
||||
#define SNES_MEMORY_CARTRIDGE_RTC 1
|
||||
#define SNES_MEMORY_BSX_RAM 2
|
||||
#define SNES_MEMORY_BSX_PRAM 3
|
||||
#define SNES_MEMORY_SUFAMI_TURBO_A_RAM 4
|
||||
#define SNES_MEMORY_SUFAMI_TURBO_B_RAM 5
|
||||
#define SNES_MEMORY_GAME_BOY_RAM 6
|
||||
#define SNES_MEMORY_GAME_BOY_RTC 7
|
||||
|
||||
#define SNES_MEMORY_WRAM 100
|
||||
#define SNES_MEMORY_APURAM 101
|
||||
#define SNES_MEMORY_VRAM 102
|
||||
#define SNES_MEMORY_OAM 103
|
||||
#define SNES_MEMORY_CGRAM 104
|
||||
|
||||
typedef void (*snes_video_refresh_t)(const uint16_t *data, unsigned width, unsigned height);
|
||||
typedef void (*snes_audio_sample_t)(uint16_t left, uint16_t right);
|
||||
typedef void (*snes_input_poll_t)(void);
|
||||
typedef int16_t (*snes_input_state_t)(bool port, unsigned device, unsigned index, unsigned id);
|
||||
|
||||
unsigned snes_library_revision_major(void);
|
||||
unsigned snes_library_revision_minor(void);
|
||||
|
||||
void snes_set_video_refresh(snes_video_refresh_t);
|
||||
void snes_set_audio_sample(snes_audio_sample_t);
|
||||
void snes_set_input_poll(snes_input_poll_t);
|
||||
void snes_set_input_state(snes_input_state_t);
|
||||
|
||||
void snes_set_controller_port_device(bool port, unsigned device);
|
||||
void snes_set_cartridge_basename(const char *basename);
|
||||
|
||||
void snes_init(void);
|
||||
void snes_term(void);
|
||||
void snes_power(void);
|
||||
void snes_reset(void);
|
||||
void snes_run(void);
|
||||
|
||||
unsigned snes_serialize_size(void);
|
||||
bool snes_serialize(uint8_t *data, unsigned size);
|
||||
bool snes_unserialize(const uint8_t *data, unsigned size);
|
||||
|
||||
void snes_cheat_reset(void);
|
||||
void snes_cheat_set(unsigned index, bool enabled, const char *code);
|
||||
|
||||
bool snes_load_cartridge_normal(
|
||||
const char *rom_xml, const uint8_t *rom_data, unsigned rom_size
|
||||
);
|
||||
|
||||
bool snes_load_cartridge_bsx_slotted(
|
||||
const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
|
||||
const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size
|
||||
);
|
||||
|
||||
bool snes_load_cartridge_bsx(
|
||||
const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
|
||||
const char *bsx_xml, const uint8_t *bsx_data, unsigned bsx_size
|
||||
);
|
||||
|
||||
bool snes_load_cartridge_sufami_turbo(
|
||||
const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
|
||||
const char *sta_xml, const uint8_t *sta_data, unsigned sta_size,
|
||||
const char *stb_xml, const uint8_t *stb_data, unsigned stb_size
|
||||
);
|
||||
|
||||
bool snes_load_cartridge_super_game_boy(
|
||||
const char *rom_xml, const uint8_t *rom_data, unsigned rom_size,
|
||||
const char *dmg_xml, const uint8_t *dmg_data, unsigned dmg_size
|
||||
);
|
||||
|
||||
void snes_unload_cartridge(void);
|
||||
|
||||
bool snes_get_region(void);
|
||||
uint8_t* snes_get_memory_data(unsigned id);
|
||||
unsigned snes_get_memory_size(unsigned id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,314 @@
|
||||
/* 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 "movie.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "general.h"
|
||||
#include "dynamic.h"
|
||||
#include <assert.h>
|
||||
|
||||
// CRC32 implementation taken from BSNES source :)
|
||||
|
||||
static const uint32_t crc32_table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
|
||||
uint32_t crc32_adjust(uint32_t crc32, uint8_t input)
|
||||
{
|
||||
return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff];
|
||||
}
|
||||
|
||||
uint32_t crc32_calculate(const uint8_t *data, unsigned length)
|
||||
{
|
||||
uint32_t crc32 = ~0;
|
||||
for(unsigned i = 0; i < length; i++)
|
||||
crc32 = crc32_adjust(crc32, data[i]);
|
||||
return ~crc32;
|
||||
}
|
||||
|
||||
struct bsv_movie
|
||||
{
|
||||
FILE *file;
|
||||
uint8_t *state;
|
||||
|
||||
long *frame_pos; // A ring buffer keeping track of many key presses were requested per frame.
|
||||
size_t frame_mask;
|
||||
uint16_t current_frame_count;
|
||||
size_t frame_ptr;
|
||||
|
||||
bool playback;
|
||||
unsigned min_file_pos;
|
||||
|
||||
bool first_rewind;
|
||||
bool did_rewind;
|
||||
};
|
||||
|
||||
#define BSV_MAGIC 0x42535631
|
||||
|
||||
#define MAGIC_INDEX 0
|
||||
#define SERIALIZER_INDEX 1
|
||||
#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)
|
||||
{
|
||||
if (is_little_endian()) // Little-endian
|
||||
return val;
|
||||
else
|
||||
return (val >> 24) | ((val >> 8) & 0xFF00) | ((val << 8) & 0xFF0000) | (val << 24);
|
||||
}
|
||||
|
||||
static inline uint16_t swap_if_big16(uint16_t val)
|
||||
{
|
||||
if (is_little_endian())
|
||||
return val;
|
||||
else
|
||||
return (val >> 8) | (val << 8);
|
||||
}
|
||||
|
||||
static bool init_playback(bsv_movie_t *handle, const char *path)
|
||||
{
|
||||
handle->playback = true;
|
||||
handle->file = fopen(path, "rb");
|
||||
if (!handle->file)
|
||||
{
|
||||
SSNES_ERR("Couldn't open BSV file \"%s\" for playback.\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t header[4] = {0};
|
||||
if (fread(header, sizeof(uint32_t), 4, handle->file) != 4)
|
||||
{
|
||||
SSNES_ERR("Couldn't read movie header!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (swap_if_big32(header[MAGIC_INDEX]) != BSV_MAGIC)
|
||||
{
|
||||
SSNES_ERR("Movie file is not a valid BSV1 file!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (swap_if_big32(header[CRC_INDEX]) != g_extern.cart_crc)
|
||||
{
|
||||
SSNES_ERR("Cart CRC32s differ! Cannot play back!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t state_size = swap_if_big32(header[STATE_SIZE_INDEX]);
|
||||
handle->state = malloc(state_size);
|
||||
if (!handle->state)
|
||||
return false;
|
||||
|
||||
handle->min_file_pos = sizeof(header) + state_size;
|
||||
|
||||
if (fread(handle->state, 1, state_size, handle->file) != state_size)
|
||||
{
|
||||
SSNES_ERR("Couldn't read state from movie.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (psnes_serialize_size() != state_size)
|
||||
{
|
||||
SSNES_ERR("Movie format seems to have a different serializer version. Cannot continue.\n");
|
||||
exit(1);
|
||||
}
|
||||
// Unserialize to start playback.
|
||||
psnes_unserialize(handle->state, state_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool init_record(bsv_movie_t *handle, const char *path)
|
||||
{
|
||||
handle->file = fopen(path, "wb");
|
||||
if (!handle->file)
|
||||
{
|
||||
SSNES_ERR("Couldn't open BSV \"%s\" for recording.\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t header[4] = {0};
|
||||
header[MAGIC_INDEX] = swap_if_big32(BSV_MAGIC);
|
||||
//header[SERIALIZER_INDEX] = 0; // TODO: Fix this.
|
||||
header[CRC_INDEX] = swap_if_big32(g_extern.cart_crc);
|
||||
|
||||
uint32_t state_size = psnes_serialize_size();
|
||||
header[STATE_SIZE_INDEX] = swap_if_big32(state_size);
|
||||
fwrite(header, 4, sizeof(uint32_t), handle->file);
|
||||
|
||||
handle->state = malloc(state_size);
|
||||
if (!handle->state)
|
||||
return false;
|
||||
|
||||
handle->min_file_pos = sizeof(header) + state_size;
|
||||
|
||||
psnes_serialize(handle->state, state_size);
|
||||
fwrite(handle->state, 1, state_size, handle->file);
|
||||
return true;
|
||||
}
|
||||
|
||||
void bsv_movie_free(bsv_movie_t *handle)
|
||||
{
|
||||
if (handle)
|
||||
{
|
||||
if (handle->file)
|
||||
fclose(handle->file);
|
||||
free(handle->state);
|
||||
free(handle->frame_pos);
|
||||
free(handle);
|
||||
}
|
||||
}
|
||||
|
||||
bool bsv_movie_get_input(bsv_movie_t *handle, int16_t *input)
|
||||
{
|
||||
if (fread(input, sizeof(int16_t), 1, handle->file) != 1)
|
||||
return false;
|
||||
|
||||
*input = swap_if_big16(*input);
|
||||
return true;
|
||||
}
|
||||
|
||||
void bsv_movie_set_input(bsv_movie_t *handle, int16_t input)
|
||||
{
|
||||
fwrite(&input, sizeof(int16_t), 1, handle->file);
|
||||
}
|
||||
|
||||
bsv_movie_t *bsv_movie_init(const char *path, enum ssnes_movie_type type)
|
||||
{
|
||||
bsv_movie_t *handle = calloc(1, sizeof(*handle));
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
if (type == SSNES_MOVIE_PLAYBACK)
|
||||
{
|
||||
if (!init_playback(handle, path))
|
||||
goto error;
|
||||
}
|
||||
else if (!init_record(handle, path))
|
||||
goto error;
|
||||
|
||||
if (!(handle->frame_pos = calloc((1 << 20), sizeof(long)))) // Just pick something really large :D
|
||||
goto error;
|
||||
handle->frame_mask = (1 << 20) - 1;
|
||||
|
||||
return handle;
|
||||
|
||||
error:
|
||||
bsv_movie_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bsv_movie_set_frame_start(bsv_movie_t *handle)
|
||||
{
|
||||
//fprintf(stderr, "Starting frame: %u, Pos: %ld\n", (unsigned)handle->frame_ptr, ftell(handle->file));
|
||||
handle->frame_pos[handle->frame_ptr] = ftell(handle->file);
|
||||
|
||||
}
|
||||
|
||||
void bsv_movie_set_frame_end(bsv_movie_t *handle)
|
||||
{
|
||||
//fprintf(stderr, "Frame++\n");
|
||||
handle->frame_ptr = (handle->frame_ptr + 1) & handle->frame_mask;
|
||||
|
||||
handle->first_rewind = !handle->did_rewind;
|
||||
handle->did_rewind = false;
|
||||
}
|
||||
|
||||
void bsv_movie_frame_rewind(bsv_movie_t *handle)
|
||||
{
|
||||
//fprintf(stderr, "Frame--\n");
|
||||
|
||||
handle->did_rewind = true;
|
||||
if (handle->frame_ptr <= 1)
|
||||
{
|
||||
handle->frame_ptr = 0;
|
||||
fseek(handle->file, handle->min_file_pos, SEEK_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle->frame_ptr = (handle->frame_ptr - (handle->first_rewind ? 1 : 2)) & handle->frame_mask;
|
||||
fseek(handle->file, handle->frame_pos[handle->frame_ptr], SEEK_SET);
|
||||
}
|
||||
|
||||
if (ftell(handle->file) <= (long)handle->min_file_pos)
|
||||
{
|
||||
if (!handle->playback)
|
||||
{
|
||||
fseek(handle->file, 4 * sizeof(uint32_t), SEEK_SET);
|
||||
psnes_serialize(handle->state, psnes_serialize_size());
|
||||
fwrite(handle->state, 1, psnes_serialize_size(), handle->file);
|
||||
}
|
||||
else
|
||||
fseek(handle->file, handle->min_file_pos, SEEK_SET);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* 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_MOVIE_H
|
||||
#define __SSNES_MOVIE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct bsv_movie bsv_movie_t;
|
||||
|
||||
enum ssnes_movie_type
|
||||
{
|
||||
SSNES_MOVIE_PLAYBACK,
|
||||
SSNES_MOVIE_RECORD,
|
||||
};
|
||||
|
||||
bsv_movie_t *bsv_movie_init(const char *path, enum ssnes_movie_type type);
|
||||
|
||||
// Playback
|
||||
bool bsv_movie_get_input(bsv_movie_t *handle, int16_t *input);
|
||||
|
||||
// Recording
|
||||
void bsv_movie_set_input(bsv_movie_t *handle, int16_t input);
|
||||
|
||||
// Used for rewinding while playback/record.
|
||||
void bsv_movie_set_frame_start(bsv_movie_t *handle); // Debugging purposes.
|
||||
void bsv_movie_set_frame_end(bsv_movie_t *handle);
|
||||
void bsv_movie_frame_rewind(bsv_movie_t *handle);
|
||||
|
||||
void bsv_movie_free(bsv_movie_t *handle);
|
||||
|
||||
uint32_t crc32_calculate(const uint8_t *data, unsigned length);
|
||||
uint32_t crc32_adjust(uint32_t crc32, uint8_t input);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,702 @@
|
||||
/* 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 "netplay.h"
|
||||
#include "general.h"
|
||||
#include "autosave.h"
|
||||
#include "dynamic.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
// Woohoo, Winsock has headers from the STONE AGE! :D
|
||||
#define close(x) closesocket(x)
|
||||
#define CONST_CAST (const char*)
|
||||
#define NONCONST_CAST (char*)
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#define CONST_CAST
|
||||
#define NONCONST_CAST
|
||||
#endif
|
||||
|
||||
|
||||
#define PREV_PTR(x) ((x) == 0 ? handle->buffer_size - 1 : (x) - 1)
|
||||
#define NEXT_PTR(x) ((x + 1) % handle->buffer_size)
|
||||
|
||||
struct delta_frame
|
||||
{
|
||||
uint8_t *state;
|
||||
|
||||
uint16_t real_input_state;
|
||||
uint16_t simulated_input_state;
|
||||
bool is_simulated;
|
||||
uint16_t self_state;
|
||||
bool used_real;
|
||||
};
|
||||
|
||||
#define UDP_FRAME_PACKETS 8
|
||||
|
||||
struct netplay
|
||||
{
|
||||
struct snes_callbacks cbs;
|
||||
int fd; // TCP connection for state sending, etc. Could perhaps be used for messaging later on. :)
|
||||
int udp_fd; // UDP connection for game state updates.
|
||||
unsigned port; // Which port is governed by netplay?
|
||||
bool has_connection;
|
||||
|
||||
struct delta_frame *buffer;
|
||||
size_t buffer_size;
|
||||
|
||||
size_t self_ptr; // Ptr where we are now.
|
||||
size_t other_ptr; // Points to the last reliable state that self ever had.
|
||||
size_t read_ptr; // Ptr to where we are reading. Generally, other_ptr <= read_ptr <= self_ptr.
|
||||
size_t tmp_ptr; // A temporary pointer used on replay.
|
||||
|
||||
size_t state_size;
|
||||
|
||||
size_t is_replay; // Are we replaying old frames?
|
||||
bool can_poll; // We don't want to poll several times on a frame.
|
||||
|
||||
uint32_t packet_buffer[UDP_FRAME_PACKETS * 2]; // To compat UDP packet loss we also send old data along with the packets.
|
||||
uint32_t frame_count;
|
||||
uint32_t read_frame_count;
|
||||
struct addrinfo *addr;
|
||||
struct sockaddr_storage their_addr;
|
||||
bool has_client_addr;
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
if (!netplay_should_skip(g_extern.netplay))
|
||||
netplay_callbacks(g_extern.netplay)->frame_cb(data, width, height);
|
||||
}
|
||||
|
||||
void audio_sample_net(uint16_t left, uint16_t right)
|
||||
{
|
||||
if (!netplay_should_skip(g_extern.netplay))
|
||||
netplay_callbacks(g_extern.netplay)->sample_cb(left, right);
|
||||
}
|
||||
|
||||
int16_t input_state_net(bool port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
if (netplay_is_alive(g_extern.netplay))
|
||||
return netplay_input_state(g_extern.netplay, port, device, index, id);
|
||||
else
|
||||
return netplay_callbacks(g_extern.netplay)->state_cb(port, device, index, id);
|
||||
}
|
||||
|
||||
static bool init_tcp_socket(netplay_t *handle, const char *server, uint16_t port)
|
||||
{
|
||||
struct addrinfo hints, *res = NULL;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
#ifdef _WIN32 // Lolol, no AF_UNSPEC, wtf.
|
||||
hints.ai_family = AF_INET;
|
||||
#else
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
#endif
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
if (!server)
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
char port_buf[16];
|
||||
snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port);
|
||||
if (getaddrinfo(server, port_buf, &hints, &res) < 0)
|
||||
return false;
|
||||
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
handle->fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
if (handle->fd < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to init socket...\n");
|
||||
|
||||
if (res)
|
||||
freeaddrinfo(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (server)
|
||||
{
|
||||
if (connect(handle->fd, res->ai_addr, res->ai_addrlen) < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to connect to server.\n");
|
||||
close(handle->fd);
|
||||
freeaddrinfo(res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int yes = 1;
|
||||
setsockopt(handle->fd, SOL_SOCKET, SO_REUSEADDR, CONST_CAST &yes, sizeof(int));
|
||||
|
||||
if (bind(handle->fd, res->ai_addr, res->ai_addrlen) < 0 || listen(handle->fd, 1) < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to bind socket.\n");
|
||||
close(handle->fd);
|
||||
freeaddrinfo(res);
|
||||
return false;
|
||||
}
|
||||
int new_fd = accept(handle->fd, NULL, NULL);
|
||||
if (new_fd < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to accept socket.\n");
|
||||
close(handle->fd);
|
||||
freeaddrinfo(res);
|
||||
return false;
|
||||
}
|
||||
close(handle->fd);
|
||||
handle->fd = new_fd;
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool init_udp_socket(netplay_t *handle, const char *server, uint16_t port)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
#ifdef _WIN32 // Lolol, no AF_UNSPEC, wtf.
|
||||
hints.ai_family = AF_INET;
|
||||
#else
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
#endif
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
if (!server)
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
char port_buf[16];
|
||||
snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port);
|
||||
if (getaddrinfo(server, port_buf, &hints, &handle->addr) < 0)
|
||||
return false;
|
||||
|
||||
if (!handle->addr)
|
||||
return false;
|
||||
|
||||
handle->udp_fd = socket(handle->addr->ai_family, handle->addr->ai_socktype, handle->addr->ai_protocol);
|
||||
if (handle->udp_fd < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to init socket...\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!server)
|
||||
{
|
||||
// Note sure if we have to do this for UDP, but hey :)
|
||||
int yes = 1;
|
||||
setsockopt(handle->udp_fd, SOL_SOCKET, SO_REUSEADDR, CONST_CAST &yes, sizeof(int));
|
||||
|
||||
if (bind(handle->udp_fd, handle->addr->ai_addr, handle->addr->ai_addrlen) < 0)
|
||||
{
|
||||
SSNES_ERR("Failed to bind socket.\n");
|
||||
close(handle->udp_fd);
|
||||
}
|
||||
|
||||
freeaddrinfo(handle->addr);
|
||||
handle->addr = NULL;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool init_socket(netplay_t *handle, const char *server, uint16_t port)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
|
||||
{
|
||||
WSACleanup();
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
signal(SIGPIPE, SIG_IGN); // Do not like SIGPIPE killing our app :(
|
||||
#endif
|
||||
|
||||
if (!init_tcp_socket(handle, server, port))
|
||||
return false;
|
||||
if (!init_udp_socket(handle, server, port))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netplay_can_poll(netplay_t *handle)
|
||||
{
|
||||
return handle->can_poll;
|
||||
}
|
||||
|
||||
static bool send_info(netplay_t *handle)
|
||||
{
|
||||
uint32_t header[3] = { htonl(g_extern.cart_crc), htonl(psnes_serialize_size()), htonl(psnes_get_memory_size(SNES_MEMORY_CARTRIDGE_RAM)) };
|
||||
if (send(handle->fd, CONST_CAST header, sizeof(header), 0) != sizeof(header))
|
||||
return false;
|
||||
|
||||
// Get SRAM data from Player 1 :)
|
||||
uint8_t *sram = psnes_get_memory_data(SNES_MEMORY_CARTRIDGE_RAM);
|
||||
unsigned sram_size = psnes_get_memory_size(SNES_MEMORY_CARTRIDGE_RAM);
|
||||
while (sram_size > 0)
|
||||
{
|
||||
ssize_t ret = recv(handle->fd, NONCONST_CAST sram, sram_size, 0);
|
||||
if (ret <= 0)
|
||||
{
|
||||
SSNES_ERR("Failed to receive SRAM data from host.\n");
|
||||
return false;
|
||||
}
|
||||
sram += ret;
|
||||
sram_size -= ret;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool get_info(netplay_t *handle)
|
||||
{
|
||||
uint32_t header[3];
|
||||
if (recv(handle->fd, NONCONST_CAST header, sizeof(header), 0) != sizeof(header))
|
||||
{
|
||||
SSNES_ERR("Failed to receive header from client.\n");
|
||||
return false;
|
||||
}
|
||||
if (g_extern.cart_crc != ntohl(header[0]))
|
||||
{
|
||||
SSNES_ERR("Cart CRC32s differ! Cannot use different games!\n");
|
||||
return false;
|
||||
}
|
||||
if (psnes_serialize_size() != ntohl(header[1]))
|
||||
{
|
||||
SSNES_ERR("Serialization sizes differ, make sure you're using exact same libsnes implementations!\n");
|
||||
return false;
|
||||
}
|
||||
if (psnes_get_memory_size(SNES_MEMORY_CARTRIDGE_RAM) != ntohl(header[2]))
|
||||
{
|
||||
SSNES_ERR("Cartridge SRAM sizes do not correspond!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send SRAM data to our Player 2 :)
|
||||
const uint8_t *sram = psnes_get_memory_data(SNES_MEMORY_CARTRIDGE_RAM);
|
||||
unsigned sram_size = psnes_get_memory_size(SNES_MEMORY_CARTRIDGE_RAM);
|
||||
while (sram_size > 0)
|
||||
{
|
||||
ssize_t ret = send(handle->fd, CONST_CAST sram, sram_size, 0);
|
||||
if (ret <= 0)
|
||||
{
|
||||
SSNES_ERR("Failed to send SRAM data to client.\n");
|
||||
return false;
|
||||
}
|
||||
sram += ret;
|
||||
sram_size -= ret;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void init_buffers(netplay_t *handle)
|
||||
{
|
||||
handle->buffer = calloc(handle->buffer_size, sizeof(*handle->buffer));
|
||||
handle->state_size = psnes_serialize_size();
|
||||
for (unsigned i = 0; i < handle->buffer_size; i++)
|
||||
{
|
||||
handle->buffer[i].state = malloc(handle->state_size);
|
||||
handle->buffer[i].is_simulated = true;
|
||||
}
|
||||
}
|
||||
|
||||
netplay_t *netplay_new(const char *server, uint16_t port, unsigned frames, const struct snes_callbacks *cb)
|
||||
{
|
||||
netplay_t *handle = calloc(1, sizeof(*handle));
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
handle->cbs = *cb;
|
||||
handle->port = server ? 0 : 1;
|
||||
|
||||
if (!init_socket(handle, server, port))
|
||||
{
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (server)
|
||||
{
|
||||
if (!send_info(handle))
|
||||
{
|
||||
close(handle->fd);
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!get_info(handle))
|
||||
{
|
||||
close(handle->fd);
|
||||
free(handle);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
handle->buffer_size = frames + 1;
|
||||
|
||||
init_buffers(handle);
|
||||
handle->has_connection = true;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
bool netplay_is_alive(netplay_t *handle)
|
||||
{
|
||||
return handle->has_connection;
|
||||
}
|
||||
|
||||
static bool send_chunk(netplay_t *handle)
|
||||
{
|
||||
const struct sockaddr *addr = NULL;
|
||||
if (handle->addr)
|
||||
addr = handle->addr->ai_addr;
|
||||
else if (handle->has_client_addr)
|
||||
addr = (const struct sockaddr*)&handle->their_addr;
|
||||
|
||||
if (addr)
|
||||
{
|
||||
if (sendto(handle->udp_fd, CONST_CAST handle->packet_buffer, sizeof(handle->packet_buffer), 0, addr, sizeof(struct sockaddr)) != sizeof(handle->packet_buffer))
|
||||
{
|
||||
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
|
||||
handle->has_connection = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#define MAX_RETRIES 64
|
||||
#define RETRY_MS 500
|
||||
|
||||
static int poll_input(netplay_t *handle, bool block)
|
||||
{
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(handle->udp_fd, &fds);
|
||||
FD_SET(handle->fd, &fds);
|
||||
int max_fd = (handle->fd > handle->udp_fd ? handle->fd : handle->udp_fd) + 1;
|
||||
|
||||
struct timeval tv = {
|
||||
.tv_sec = 0,
|
||||
.tv_usec = block ? (RETRY_MS * 1000) : 0
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
if (select(max_fd, &fds, NULL, NULL, &tv) < 0)
|
||||
return -1;
|
||||
|
||||
// Somewhat hacky, but we aren't using the TCP connection for anything useful atm.
|
||||
// Will probably add some proper messaging system here later.
|
||||
if (FD_ISSET(handle->fd, &fds))
|
||||
return -1;
|
||||
|
||||
if (FD_ISSET(handle->udp_fd, &fds))
|
||||
return 1;
|
||||
|
||||
if (block && !send_chunk(handle))
|
||||
{
|
||||
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
|
||||
handle->has_connection = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (block)
|
||||
SSNES_LOG("Network lag of %d ms, resending packet... Attempt %d of %d ...\n", RETRY_MS, i, MAX_RETRIES);
|
||||
|
||||
// Seems to be necessary on Win32.
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(handle->udp_fd, &fds);
|
||||
FD_SET(handle->fd, &fds);
|
||||
|
||||
} while ((i++ < MAX_RETRIES) && block);
|
||||
|
||||
if (block)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Grab our own input state and send this over the network.
|
||||
static bool get_self_input_state(netplay_t *handle)
|
||||
{
|
||||
struct delta_frame *ptr = &handle->buffer[handle->self_ptr];
|
||||
|
||||
uint32_t state = 0;
|
||||
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++)
|
||||
{
|
||||
int16_t tmp = cb(g_settings.input.netplay_client_swap_input ? 0 : !handle->port, SNES_DEVICE_JOYPAD, 0, i);
|
||||
state |= tmp ? 1 << i : 0;
|
||||
}
|
||||
}
|
||||
|
||||
memmove(handle->packet_buffer, handle->packet_buffer + 2, sizeof (handle->packet_buffer) - 2 * sizeof(uint32_t));
|
||||
handle->packet_buffer[(UDP_FRAME_PACKETS - 1) * 2] = htonl(handle->frame_count);
|
||||
handle->packet_buffer[(UDP_FRAME_PACKETS - 1) * 2 + 1] = htonl(state);
|
||||
|
||||
if (!send_chunk(handle))
|
||||
{
|
||||
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
|
||||
handle->has_connection = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
ptr->self_state = state;
|
||||
handle->self_ptr = NEXT_PTR(handle->self_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Somewhat better prediction. :P
|
||||
static void simulate_input(netplay_t *handle)
|
||||
{
|
||||
size_t ptr = PREV_PTR(handle->self_ptr);
|
||||
size_t prev = PREV_PTR(handle->read_ptr);
|
||||
|
||||
handle->buffer[ptr].simulated_input_state = handle->buffer[prev].real_input_state;
|
||||
handle->buffer[ptr].is_simulated = true;
|
||||
handle->buffer[ptr].used_real = false;
|
||||
}
|
||||
|
||||
static void parse_packet(netplay_t *handle, uint32_t *buffer, unsigned size)
|
||||
{
|
||||
for (unsigned i = 0; i < size * 2; i++)
|
||||
buffer[i] = ntohl(buffer[i]);
|
||||
|
||||
for (unsigned i = 0; i < size && handle->read_frame_count <= handle->frame_count; i++)
|
||||
{
|
||||
uint32_t frame = buffer[2 * i];
|
||||
uint32_t state = buffer[2 * i + 1];
|
||||
|
||||
if (frame == handle->read_frame_count)
|
||||
{
|
||||
handle->buffer[handle->read_ptr].is_simulated = false;
|
||||
handle->buffer[handle->read_ptr].real_input_state = state;
|
||||
handle->read_ptr = NEXT_PTR(handle->read_ptr);
|
||||
handle->read_frame_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool receive_data(netplay_t *handle, uint32_t *buffer, size_t size)
|
||||
{
|
||||
socklen_t addrlen = sizeof(handle->their_addr);
|
||||
if (recvfrom(handle->udp_fd, NONCONST_CAST buffer, size, 0, (struct sockaddr*)&handle->their_addr, &addrlen) != size)
|
||||
return false;
|
||||
handle->has_client_addr = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Poll network to see if we have anything new. If our network buffer is full, we simply have to block for new input data.
|
||||
bool netplay_poll(netplay_t *handle)
|
||||
{
|
||||
if (!handle->has_connection)
|
||||
return false;
|
||||
|
||||
handle->can_poll = false;
|
||||
|
||||
if (!get_self_input_state(handle))
|
||||
return false;
|
||||
|
||||
// We skip reading the first frame so the host has a change to grab our host info so we don't block forever :')
|
||||
if (handle->frame_count == 0)
|
||||
{
|
||||
handle->buffer[0].used_real = true;
|
||||
handle->buffer[0].is_simulated = false;
|
||||
handle->buffer[0].real_input_state = 0;
|
||||
handle->read_ptr = NEXT_PTR(handle->read_ptr);
|
||||
handle->read_frame_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
//fprintf(stderr, "Other ptr: %lu, Read ptr: %lu, Self ptr: %lu\n", handle->other_ptr, handle->read_ptr, handle->self_ptr);
|
||||
if (handle->buffer_size > 1)
|
||||
{
|
||||
assert(handle->other_ptr != handle->self_ptr);
|
||||
assert(handle->read_ptr != handle->self_ptr);
|
||||
}
|
||||
assert(handle->other_ptr == handle->read_ptr);
|
||||
|
||||
// We might have reached the end of the buffer, where we simply have to block.
|
||||
int res = poll_input(handle, handle->other_ptr == NEXT_PTR(handle->self_ptr));
|
||||
if (res == -1)
|
||||
{
|
||||
handle->has_connection = false;
|
||||
SSNES_WARN("Netplay connection timed out. Will continue without netplay.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (res == 1)
|
||||
{
|
||||
uint32_t first_read = handle->read_frame_count;
|
||||
do
|
||||
{
|
||||
uint32_t buffer[UDP_FRAME_PACKETS * 2];
|
||||
if (!receive_data(handle, buffer, sizeof(buffer)))
|
||||
{
|
||||
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
|
||||
handle->has_connection = false;
|
||||
return false;
|
||||
}
|
||||
parse_packet(handle, buffer, UDP_FRAME_PACKETS);
|
||||
|
||||
} while ((handle->read_frame_count <= handle->frame_count) &&
|
||||
poll_input(handle, (handle->other_ptr == NEXT_PTR(handle->self_ptr)) &&
|
||||
(first_read == handle->read_frame_count)) == 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cannot allow this. Should not happen though.
|
||||
if (NEXT_PTR(handle->self_ptr) == handle->other_ptr)
|
||||
{
|
||||
SSNES_WARN("Netplay connection hung up. Will continue without netplay.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (handle->read_ptr != handle->self_ptr)
|
||||
simulate_input(handle);
|
||||
else
|
||||
handle->buffer[PREV_PTR(handle->self_ptr)].used_real = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int16_t netplay_input_state(netplay_t *handle, bool port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
uint16_t input_state = 0;
|
||||
size_t ptr = 0;
|
||||
|
||||
if (handle->is_replay)
|
||||
ptr = handle->tmp_ptr;
|
||||
else
|
||||
ptr = PREV_PTR(handle->self_ptr);
|
||||
|
||||
if ((port ? 1 : 0) == handle->port)
|
||||
{
|
||||
if (handle->buffer[ptr].is_simulated)
|
||||
input_state = handle->buffer[ptr].simulated_input_state;
|
||||
else
|
||||
input_state = handle->buffer[ptr].real_input_state;
|
||||
}
|
||||
else
|
||||
input_state = handle->buffer[ptr].self_state;
|
||||
|
||||
return ((1 << id) & input_state) ? 1 : 0;
|
||||
}
|
||||
|
||||
void netplay_free(netplay_t *handle)
|
||||
{
|
||||
close(handle->fd);
|
||||
close(handle->udp_fd);
|
||||
|
||||
for (unsigned i = 0; i < handle->buffer_size; i++)
|
||||
free(handle->buffer[i].state);
|
||||
|
||||
free(handle->buffer);
|
||||
if (handle->addr)
|
||||
freeaddrinfo(handle->addr);
|
||||
free(handle);
|
||||
}
|
||||
|
||||
const struct snes_callbacks* netplay_callbacks(netplay_t *handle)
|
||||
{
|
||||
return &handle->cbs;
|
||||
}
|
||||
|
||||
bool netplay_should_skip(netplay_t *handle)
|
||||
{
|
||||
return handle->is_replay && handle->has_connection;
|
||||
}
|
||||
|
||||
void netplay_pre_frame(netplay_t *handle)
|
||||
{
|
||||
psnes_serialize(handle->buffer[handle->self_ptr].state, handle->state_size);
|
||||
handle->can_poll = true;
|
||||
}
|
||||
|
||||
// Here we check if we have new input and replay from recorded input.
|
||||
void netplay_post_frame(netplay_t *handle)
|
||||
{
|
||||
handle->frame_count++;
|
||||
|
||||
// Nothing to do...
|
||||
if (handle->other_ptr == handle->read_ptr)
|
||||
return;
|
||||
|
||||
// Skip ahead if we predicted correctly. Skip until our simulation failed.
|
||||
while (handle->other_ptr != handle->read_ptr)
|
||||
{
|
||||
struct delta_frame *ptr = &handle->buffer[handle->other_ptr];
|
||||
if ((ptr->simulated_input_state != ptr->real_input_state) && !ptr->used_real)
|
||||
break;
|
||||
handle->other_ptr = NEXT_PTR(handle->other_ptr);
|
||||
}
|
||||
|
||||
if (handle->other_ptr != handle->read_ptr)
|
||||
{
|
||||
// Replay frames
|
||||
handle->is_replay = true;
|
||||
handle->tmp_ptr = handle->other_ptr;
|
||||
psnes_unserialize(handle->buffer[handle->other_ptr].state, handle->state_size);
|
||||
while (handle->tmp_ptr != handle->self_ptr)
|
||||
{
|
||||
psnes_serialize(handle->buffer[handle->tmp_ptr].state, handle->state_size);
|
||||
lock_autosave();
|
||||
psnes_run();
|
||||
unlock_autosave();
|
||||
handle->tmp_ptr = NEXT_PTR(handle->tmp_ptr);
|
||||
}
|
||||
handle->other_ptr = handle->read_ptr;
|
||||
handle->is_replay = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/* 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_NETPLAY_H
|
||||
#define __SSNES_NETPLAY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <libsnes.hpp>
|
||||
|
||||
void input_poll_net(void);
|
||||
int16_t input_state_net(bool port, unsigned device, unsigned index, unsigned id);
|
||||
void video_frame_net(const uint16_t *data, unsigned width, unsigned height);
|
||||
void audio_sample_net(uint16_t left, uint16_t right);
|
||||
|
||||
typedef struct netplay netplay_t;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
// Creates a new netplay handle. A NULL host means we're hosting (player 1). :)
|
||||
netplay_t *netplay_new(const char *server, uint16_t port, unsigned frames, const struct snes_callbacks *cb);
|
||||
void netplay_free(netplay_t *handle);
|
||||
|
||||
// Call this before running snes_run()
|
||||
void netplay_pre_frame(netplay_t *handle);
|
||||
// Call this after running snes_run()
|
||||
void netplay_post_frame(netplay_t *handle);
|
||||
|
||||
// Checks if input port/index is controlled by netplay or not.
|
||||
bool netplay_is_alive(netplay_t *handle);
|
||||
|
||||
bool netplay_poll(netplay_t *handle);
|
||||
int16_t netplay_input_state(netplay_t *handle, bool port, unsigned device, unsigned index, unsigned id);
|
||||
|
||||
// If we're fast-forward replaying to resync, check if we should actually show frame.
|
||||
bool netplay_should_skip(netplay_t *handle);
|
||||
bool netplay_can_poll(netplay_t *handle);
|
||||
const struct snes_callbacks* netplay_callbacks(netplay_t *handle);
|
||||
|
||||
#endif
|
||||
+23
-5
@@ -15,12 +15,28 @@ if [ $HAVE_DYNAMIC != yes ]; then
|
||||
add_define_make libsnes $LIBSNES
|
||||
fi
|
||||
|
||||
check_lib FILTER -ldl dlopen
|
||||
check_lib NETPLAY -lc socket
|
||||
|
||||
check_lib ALSA -lasound snd_pcm_open
|
||||
check_header OSS sys/soundcard.h
|
||||
check_lib AL -lopenal alcOpenDevice
|
||||
check_lib RSOUND -lrsound rsd_init
|
||||
|
||||
if [ "$OS" = "Darwin" ]; then
|
||||
check_lib AL "-framework OpenAL" alcOpenDevice
|
||||
else
|
||||
check_lib AL -lopenal alcOpenDevice
|
||||
fi
|
||||
|
||||
if [ "$OS" = "Darwin" ]; then
|
||||
check_lib FBO "-framework OpenGL" glFramebufferTexture2D
|
||||
else
|
||||
check_lib FBO -lGL glFramebufferTexture2D
|
||||
fi
|
||||
|
||||
check_pkgconf RSOUND rsound 1.1
|
||||
check_lib ROAR -lroar roar_vs_new
|
||||
check_lib JACK -ljack jack_client_open
|
||||
check_pkgconf JACK jack 0.120.1
|
||||
check_pkgconf PULSE libpulse
|
||||
|
||||
check_pkgconf SDL sdl 1.2.10
|
||||
check_critical SDL "Cannot find SDL library."
|
||||
@@ -39,14 +55,16 @@ if [ $HAVE_FFMPEG != no ]; then
|
||||
fi
|
||||
|
||||
check_pkgconf SRC samplerate
|
||||
check_critical SRC "Cannot find libsamplerate."
|
||||
|
||||
check_lib DYNAMIC -ldl dlopen
|
||||
|
||||
check_pkgconf FREETYPE freetype2
|
||||
check_lib XVIDEO -lXv XvShmCreateImage
|
||||
|
||||
check_lib STRL -lc strlcpy
|
||||
|
||||
# Creates config.mk and config.h.
|
||||
VARS="ALSA OSS AL RSOUND ROAR JACK SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE"
|
||||
VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL FILTER CG XML DYNAMIC FFMPEG AVCODEC AVFORMAT AVCORE AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL"
|
||||
create_config_make config.mk $VARS
|
||||
create_config_header config.h $VARS
|
||||
|
||||
+7
-2
@@ -1,7 +1,7 @@
|
||||
. qb/qb.params.sh
|
||||
|
||||
PACKAGE_NAME=ssnes
|
||||
PACKAGE_VERSION=0.2
|
||||
PACKAGE_VERSION=0.4
|
||||
|
||||
# Adds a command line opt to ./configure --help
|
||||
# $1: Variable (HAVE_ALSA, HAVE_OSS, etc)
|
||||
@@ -10,14 +10,19 @@ PACKAGE_VERSION=0.2
|
||||
add_command_line_enable DYNAMIC "Enable dynamic loading of libsnes library." no
|
||||
add_command_line_string LIBSNES "libsnes library used" "-lsnes"
|
||||
add_command_line_enable FFMPEG "Enable FFmpeg recording support" no
|
||||
add_command_line_enable FILTER "Enable CPU filter support" no
|
||||
add_command_line_enable FILTER "Enable CPU filter support" auto
|
||||
add_command_line_enable NETPLAY "Enable netplay support" auto
|
||||
add_command_line_enable SRC "Enable libsamplerate support" no
|
||||
add_command_line_enable CONFIGFILE "Disable support for config file" yes
|
||||
add_command_line_enable CG "Enable Cg shader support" auto
|
||||
add_command_line_enable XML "Enable bSNES-style XML shader support" auto
|
||||
add_command_line_enable FBO "Enable render-to-texture (FBO) support" auto
|
||||
add_command_line_enable ALSA "Enable ALSA support" auto
|
||||
add_command_line_enable OSS "Enable OSS support" auto
|
||||
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 PULSE "Enable PulseAudio support" auto
|
||||
add_command_line_enable FREETYPE "Enable FreeType support" auto
|
||||
add_command_line_enable XVIDEO "Enable XVideo support" auto
|
||||
+2
-2
@@ -6,7 +6,7 @@ TEMP_EXE=.tmp
|
||||
|
||||
echo -n "Checking operating system ... "
|
||||
OS="Win32" # whatever ;D
|
||||
unamestr="`uname -o`"
|
||||
unamestr="`uname -a`"
|
||||
if [ ! -z "`echo $unamestr | grep -i Linux`" ]; then
|
||||
OS="Linux"
|
||||
elif [ ! -z "`echo $unamestr | grep -i Darwin`" ]; then
|
||||
@@ -50,7 +50,7 @@ if [ "$USE_LANG_CXX" = "yes" ]; then
|
||||
CXX=`which g++ c++ 2> /dev/null | grep ^/ | head -n 1`
|
||||
fi
|
||||
if [ -z $CXX ]; then
|
||||
echo "Could not find C compiler in path. Exiting ..."
|
||||
echo "Could not find C++ compiler in path. Exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
+2
-2
@@ -50,7 +50,7 @@ check_lib()
|
||||
|
||||
extralibs="$4"
|
||||
|
||||
$CC -o $TEMP_EXE $TEMP_C $INCLUDE_DIRS $LIBRARY_DIRS $extralibs $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
$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
|
||||
|
||||
@@ -75,7 +75,7 @@ check_lib_cxx()
|
||||
|
||||
extralibs="$4"
|
||||
|
||||
$CXX -o $TEMP_EXE $TEMP_CXX $INCLUDE_DIRS $LIBRARY_DIRS $extralibs $2 2>/dev/null >/dev/null && answer=yes && eval HAVE_$1=yes
|
||||
$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
|
||||
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ parse_input()
|
||||
case "$1" in
|
||||
|
||||
--prefix=*)
|
||||
prefix="`echo $1 | sed -e 's|^--prefix=\(\S\S*\)$|\1|' -e 's|\(\S\S*\)/$|\1|'`"
|
||||
prefix="`echo $1 | sed -e 's|^--prefix=||' -e 's|^\(.*\)/$|\1|'`"
|
||||
|
||||
if [ "$prefix" != "$1" ]; then
|
||||
PREFIX="$prefix"
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/* 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 "rewind.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
//#include <stdio.h>
|
||||
|
||||
struct state_manager
|
||||
{
|
||||
uint64_t *buffer;
|
||||
size_t buf_size;
|
||||
uint32_t *tmp_state;
|
||||
uint32_t *scratch_buf;
|
||||
size_t top_ptr;
|
||||
size_t bottom_ptr;
|
||||
size_t state_size;
|
||||
bool first_pop;
|
||||
};
|
||||
|
||||
state_manager_t *state_manager_new(size_t state_size, size_t buffer_size, void *init_buffer)
|
||||
{
|
||||
if (buffer_size <= state_size * 2 + 1) // Need a sufficient buffer size.
|
||||
return NULL;
|
||||
|
||||
state_manager_t *state = calloc(1, sizeof(*state));
|
||||
if (!state)
|
||||
return NULL;
|
||||
|
||||
assert(state_size % 4 == 0); // We need 4-byte aligned state_size to avoid having to enforce this with unneeded memcpy's!
|
||||
state->top_ptr = 1;
|
||||
state->state_size = (state_size + 3) >> 2; // Multiple of 4.
|
||||
state->buf_size = (buffer_size + 7) >> 3; // Multiple of 8.
|
||||
if (!(state->buffer = calloc(1, state->buf_size * sizeof(uint64_t))))
|
||||
goto error;
|
||||
if (!(state->tmp_state = calloc(1, state->state_size * sizeof(uint32_t))))
|
||||
goto error;
|
||||
|
||||
memcpy(state->tmp_state, init_buffer, state_size);
|
||||
|
||||
return state;
|
||||
|
||||
error:
|
||||
if (state)
|
||||
{
|
||||
free(state->buffer);
|
||||
free(state->tmp_state);
|
||||
free(state);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void state_manager_free(state_manager_t *state)
|
||||
{
|
||||
free(state->buffer);
|
||||
free(state->tmp_state);
|
||||
free(state);
|
||||
}
|
||||
|
||||
bool state_manager_pop(state_manager_t *state, void **data)
|
||||
{
|
||||
*data = state->tmp_state;
|
||||
if (state->first_pop)
|
||||
{
|
||||
state->first_pop = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state->top_ptr == 0)
|
||||
state->top_ptr = state->buf_size - 1;
|
||||
else
|
||||
state->top_ptr--;
|
||||
|
||||
if (state->top_ptr == state->bottom_ptr) // Our stack is completely empty... :v
|
||||
{
|
||||
state->top_ptr = (state->top_ptr + 1) % state->buf_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (state->buffer[state->top_ptr])
|
||||
{
|
||||
// Apply the xor patch.
|
||||
uint32_t addr = state->buffer[state->top_ptr] >> 32;
|
||||
uint32_t xor = state->buffer[state->top_ptr] & 0xFFFFFFFFU;
|
||||
state->tmp_state[addr] ^= xor;
|
||||
|
||||
if (state->top_ptr == 0)
|
||||
state->top_ptr = state->buf_size - 1;
|
||||
else
|
||||
state->top_ptr--;
|
||||
}
|
||||
|
||||
if (state->top_ptr == state->bottom_ptr) // Our stack is completely empty... :v
|
||||
{
|
||||
state->top_ptr = (state->top_ptr + 1) % state->buf_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void reassign_bottom(state_manager_t *state)
|
||||
{
|
||||
state->bottom_ptr = (state->top_ptr + 1) % state->buf_size;
|
||||
while (state->buffer[state->bottom_ptr]) // Skip ahead until we find the first 0 (boundary for state delta).
|
||||
state->bottom_ptr = (state->bottom_ptr + 1) % state->buf_size;
|
||||
}
|
||||
|
||||
static void generate_delta(state_manager_t *state, const void *data)
|
||||
{
|
||||
//unsigned patch_size = 0;
|
||||
bool crossed = false;
|
||||
const uint32_t *old_state = state->tmp_state;
|
||||
const uint32_t *new_state = data;
|
||||
|
||||
state->buffer[state->top_ptr++] = 0; // For each separate delta, we have a 0 value sentinel in between.
|
||||
if (state->top_ptr == state->bottom_ptr) // Check if top_ptr and bottom_ptr crossed each other, which means we need to delete old cruft.
|
||||
crossed = true;
|
||||
|
||||
for (uint64_t i = 0; i < state->state_size; i++)
|
||||
{
|
||||
uint64_t xor = old_state[i] ^ new_state[i];
|
||||
|
||||
// If the data differs (xor != 0), we push that xor on the stack with index and xor. This can be reversed by reapplying the xor.
|
||||
// This, if states don't really differ much, we'll save lots of space :) Hopefully this will work really well with save states.
|
||||
if (xor)
|
||||
{
|
||||
//patch_size++;
|
||||
state->buffer[state->top_ptr] = (i << 32) | xor;
|
||||
state->top_ptr = (state->top_ptr + 1) % state->buf_size;
|
||||
|
||||
if (state->top_ptr == state->bottom_ptr)
|
||||
crossed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (crossed)
|
||||
reassign_bottom(state);
|
||||
|
||||
//fprintf(stderr, "DELTA SIZE: %u, ORIG SIZE: %u\n", (unsigned)patch_size << 3, (unsigned)state->state_size << 2);
|
||||
}
|
||||
|
||||
bool state_manager_push(state_manager_t *state, const void *data)
|
||||
{
|
||||
generate_delta(state, data);
|
||||
memcpy(state->tmp_state, data, state->state_size * sizeof(uint32_t));
|
||||
state->first_pop = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* 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_REWIND_H
|
||||
#define __SSNES_REWIND_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct state_manager state_manager_t;
|
||||
|
||||
// Always pass in at least 4-byte aligned data and sizes!
|
||||
|
||||
state_manager_t *state_manager_new(size_t state_size, size_t buffer_size, void *init_buffer);
|
||||
void state_manager_free(state_manager_t *state);
|
||||
bool state_manager_pop(state_manager_t *state, void **data);
|
||||
bool state_manager_push(state_manager_t *state, const void *data);
|
||||
|
||||
#endif
|
||||
+260
-197
@@ -18,8 +18,7 @@
|
||||
#include "general.h"
|
||||
#include "conf/config_file.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "hqflt/filters.h"
|
||||
#include "strl.h"
|
||||
#include "config.def.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@@ -45,6 +44,9 @@ static void set_defaults(void)
|
||||
case VIDEO_GL:
|
||||
def_video = "gl";
|
||||
break;
|
||||
case VIDEO_XVIDEO:
|
||||
def_video = "xvideo";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -69,6 +71,12 @@ static void set_defaults(void)
|
||||
case AUDIO_SDL:
|
||||
def_audio = "sdl";
|
||||
break;
|
||||
case AUDIO_XAUDIO:
|
||||
def_audio = "xaudio";
|
||||
break;
|
||||
case AUDIO_PULSE:
|
||||
def_audio = "pulse";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -78,16 +86,19 @@ static void set_defaults(void)
|
||||
case INPUT_SDL:
|
||||
def_input = "sdl";
|
||||
break;
|
||||
case INPUT_X:
|
||||
def_input = "x";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (def_video)
|
||||
strncpy(g_settings.video.driver, def_video, sizeof(g_settings.video.driver) - 1);
|
||||
strlcpy(g_settings.video.driver, def_video, sizeof(g_settings.video.driver));
|
||||
if (def_audio)
|
||||
strncpy(g_settings.audio.driver, def_audio, sizeof(g_settings.audio.driver) - 1);
|
||||
strlcpy(g_settings.audio.driver, def_audio, sizeof(g_settings.audio.driver));
|
||||
if (def_input)
|
||||
strncpy(g_settings.input.driver, def_input, sizeof(g_settings.input.driver) - 1);
|
||||
strlcpy(g_settings.input.driver, def_input, sizeof(g_settings.input.driver));
|
||||
|
||||
g_settings.video.xscale = xscale;
|
||||
g_settings.video.yscale = yscale;
|
||||
@@ -98,9 +109,7 @@ static void set_defaults(void)
|
||||
g_settings.video.smooth = video_smooth;
|
||||
g_settings.video.force_aspect = force_aspect;
|
||||
g_settings.video.aspect_ratio = SNES_ASPECT_RATIO;
|
||||
#ifdef HAVE_FILTER
|
||||
g_settings.video.filter = FILTER_NONE;
|
||||
#endif
|
||||
g_settings.video.shader_type = SSNES_SHADER_AUTO;
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
g_settings.video.font_size = font_size;
|
||||
@@ -108,14 +117,31 @@ static void set_defaults(void)
|
||||
g_settings.video.msg_pos_y = message_pos_offset_y;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_XML)
|
||||
g_settings.video.render_to_texture = render_to_texture;
|
||||
g_settings.video.fbo_scale_x = fbo_scale_x;
|
||||
g_settings.video.fbo_scale_y = fbo_scale_y;
|
||||
g_settings.video.second_pass_smooth = second_pass_smooth;
|
||||
#endif
|
||||
|
||||
g_settings.audio.enable = audio_enable;
|
||||
g_settings.audio.out_rate = out_rate;
|
||||
g_settings.audio.in_rate = in_rate;
|
||||
g_settings.audio.rate_step = audio_rate_step;
|
||||
if (audio_device)
|
||||
strncpy(g_settings.audio.device, audio_device, sizeof(g_settings.audio.device));
|
||||
strlcpy(g_settings.audio.device, audio_device, sizeof(g_settings.audio.device));
|
||||
g_settings.audio.latency = out_latency;
|
||||
g_settings.audio.sync = audio_sync;
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
g_settings.audio.src_quality = SAMPLERATE_QUALITY;
|
||||
#endif
|
||||
|
||||
g_settings.rewind_enable = rewind_enable;
|
||||
g_settings.rewind_buffer_size = rewind_buffer_size;
|
||||
g_settings.rewind_granularity = rewind_granularity;
|
||||
g_settings.pause_nonactive = pause_nonactive;
|
||||
g_settings.autosave_interval = autosave_interval;
|
||||
|
||||
assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1));
|
||||
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_2));
|
||||
@@ -129,10 +155,10 @@ static void set_defaults(void)
|
||||
memcpy(g_settings.input.binds[4], snes_keybinds_5, sizeof(snes_keybinds_5));
|
||||
|
||||
g_settings.input.axis_threshold = AXIS_THRESHOLD;
|
||||
for (int i = 0; i < 2; i++)
|
||||
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;
|
||||
for (int i = 2; i < MAX_PLAYERS; i++)
|
||||
g_settings.input.joypad_map[i] = SSNES_NO_JOYPAD;
|
||||
|
||||
}
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
@@ -149,6 +175,80 @@ void parse_config(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static config_file_t *open_default_config_file(void)
|
||||
{
|
||||
config_file_t *conf = NULL;
|
||||
#ifdef _WIN32
|
||||
// Just do something for now.
|
||||
conf = config_file_new("ssnes.cfg");
|
||||
if (!conf)
|
||||
{
|
||||
const char *appdata = getenv("APPDATA");
|
||||
if (appdata)
|
||||
{
|
||||
char conf_path[strlen(appdata) + strlen("/ssnes.cfg ")];
|
||||
strcpy(conf_path, appdata);
|
||||
strcat(conf_path, "/ssnes.cfg");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
const char *home = getenv("HOME");
|
||||
if (home)
|
||||
{
|
||||
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
|
||||
strcpy(conf_path, home);
|
||||
strcat(conf_path, "/.ssnes.cfg");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
if (!conf)
|
||||
conf = config_file_new("/etc/ssnes.cfg");
|
||||
#else
|
||||
const char *xdg = getenv("XDG_CONFIG_HOME");
|
||||
if (!xdg)
|
||||
SSNES_WARN("XDG_CONFIG_HOME is not defined. Will look for config in $HOME/.ssnesrc ...\n");
|
||||
|
||||
const char *home = getenv("HOME");
|
||||
if (xdg)
|
||||
{
|
||||
char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")];
|
||||
strcpy(conf_path, xdg);
|
||||
strcat(conf_path, "/ssnes/ssnes.cfg");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
else if (home)
|
||||
{
|
||||
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
|
||||
strcpy(conf_path, home);
|
||||
strcat(conf_path, "/.ssnes.cfg");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
// Try this as a last chance...
|
||||
if (!conf)
|
||||
conf = config_file_new("/etc/ssnes.cfg");
|
||||
#endif
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
// Macros to ease config getting.
|
||||
#define CONFIG_GET_BOOL(var, key) if (config_get_bool(conf, key, &tmp_bool)) \
|
||||
g_settings.var = tmp_bool
|
||||
|
||||
#define CONFIG_GET_INT(var, key) if (config_get_int(conf, key, &tmp_int)) \
|
||||
g_settings.var = tmp_int
|
||||
|
||||
#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)
|
||||
|
||||
#ifdef HAVE_CONFIGFILE
|
||||
static void parse_config_file(void)
|
||||
{
|
||||
@@ -164,32 +264,7 @@ static void parse_config_file(void)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// Just do something for now.
|
||||
conf = config_file_new("ssnes.cfg");
|
||||
#else
|
||||
const char *xdg = getenv("XDG_CONFIG_HOME");
|
||||
const char *home = getenv("HOME");
|
||||
if (xdg)
|
||||
{
|
||||
char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")];
|
||||
strcpy(conf_path, xdg);
|
||||
strcat(conf_path, "/ssnes/ssnes.cfg");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
else if (home)
|
||||
{
|
||||
char conf_path[strlen(home) + strlen("/.ssnesrc ")];
|
||||
strcpy(conf_path, home);
|
||||
strcat(conf_path, "/.ssnesrc");
|
||||
conf = config_file_new(conf_path);
|
||||
}
|
||||
// Try this as a last chance...
|
||||
if (!conf)
|
||||
conf = config_file_new("/etc/ssnes.cfg");
|
||||
#endif
|
||||
}
|
||||
conf = open_default_config_file();
|
||||
|
||||
if (conf == NULL)
|
||||
return;
|
||||
@@ -202,138 +277,73 @@ static void parse_config_file(void)
|
||||
bool tmp_bool;
|
||||
char *tmp_str;
|
||||
|
||||
// Video settings.
|
||||
if (config_get_double(conf, "video_xscale", &tmp_double))
|
||||
g_settings.video.xscale = tmp_double;
|
||||
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");
|
||||
CONFIG_GET_BOOL(video.vsync, "video_vsync");
|
||||
CONFIG_GET_BOOL(video.smooth, "video_smooth");
|
||||
CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect");
|
||||
CONFIG_GET_DOUBLE(video.aspect_ratio, "video_aspect_ratio");
|
||||
|
||||
if (config_get_double(conf, "video_yscale", &tmp_double))
|
||||
g_settings.video.yscale = tmp_double;
|
||||
|
||||
if (config_get_int(conf, "video_fullscreen_x", &tmp_int))
|
||||
g_settings.video.fullscreen_x = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "video_fullscreen_y", &tmp_int))
|
||||
g_settings.video.fullscreen_y = tmp_int;
|
||||
|
||||
if (config_get_bool(conf, "video_fullscreen", &tmp_bool))
|
||||
g_settings.video.fullscreen = tmp_bool;
|
||||
|
||||
if (config_get_bool(conf, "video_vsync", &tmp_bool))
|
||||
g_settings.video.vsync = tmp_bool;
|
||||
|
||||
if (config_get_bool(conf, "video_smooth", &tmp_bool))
|
||||
g_settings.video.smooth = tmp_bool;
|
||||
|
||||
if (config_get_bool(conf, "video_force_aspect", &tmp_bool))
|
||||
g_settings.video.force_aspect = tmp_bool;
|
||||
|
||||
if (config_get_double(conf, "video_aspect_ratio", &tmp_double))
|
||||
g_settings.video.aspect_ratio = tmp_double;
|
||||
|
||||
if (config_get_string(conf, "video_cg_shader", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.video.cg_shader_path, tmp_str, sizeof(g_settings.video.cg_shader_path) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
|
||||
if (config_get_string(conf, "video_bsnes_shader", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.video.bsnes_shader_path, tmp_str, sizeof(g_settings.video.bsnes_shader_path) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader");
|
||||
CONFIG_GET_STRING(video.bsnes_shader_path, "video_bsnes_shader");
|
||||
CONFIG_GET_STRING(video.second_pass_shader, "video_second_pass_shader");
|
||||
CONFIG_GET_BOOL(video.render_to_texture, "video_render_to_texture");
|
||||
CONFIG_GET_DOUBLE(video.fbo_scale_x, "video_fbo_scale_x");
|
||||
CONFIG_GET_DOUBLE(video.fbo_scale_y, "video_fbo_scale_y");
|
||||
CONFIG_GET_BOOL(video.second_pass_smooth, "video_second_pass_smooth");
|
||||
|
||||
#ifdef HAVE_FREETYPE
|
||||
if (config_get_string(conf, "video_font_path", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.video.font_path, tmp_str, sizeof(g_settings.video.font_path) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
|
||||
if (config_get_int(conf, "video_font_size", &tmp_int))
|
||||
g_settings.video.font_size = tmp_int;
|
||||
|
||||
if (config_get_double(conf, "video_message_pos_x", &tmp_double))
|
||||
g_settings.video.msg_pos_x = tmp_double;
|
||||
if (config_get_double(conf, "video_message_pos_y", &tmp_double))
|
||||
g_settings.video.msg_pos_y = tmp_double;
|
||||
CONFIG_GET_STRING(video.font_path, "video_font_path");
|
||||
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");
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_FILTER
|
||||
if (config_get_string(conf, "video_filter", &tmp_str))
|
||||
CONFIG_GET_STRING(video.filter_path, "video_filter");
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_XML)
|
||||
if (config_get_string(conf, "video_shader_type", &tmp_str))
|
||||
{
|
||||
unsigned filter = 0;
|
||||
if (strcasecmp(FILTER_HQ2X_STR, tmp_str) == 0)
|
||||
filter = FILTER_HQ2X;
|
||||
else if (strcasecmp(FILTER_HQ4X_STR, tmp_str) == 0)
|
||||
filter = FILTER_HQ4X;
|
||||
else if (strcasecmp(FILTER_GRAYSCALE_STR, tmp_str) == 0)
|
||||
filter = FILTER_GRAYSCALE;
|
||||
else if (strcasecmp(FILTER_BLEED_STR, tmp_str) == 0)
|
||||
filter = FILTER_BLEED;
|
||||
else if (strcasecmp(FILTER_NTSC_STR, tmp_str) == 0)
|
||||
filter = FILTER_NTSC;
|
||||
else
|
||||
{
|
||||
SSNES_ERR(
|
||||
"Invalid filter... Valid filters are:\n"
|
||||
"\t%s\n"
|
||||
"\t%s\n"
|
||||
"\t%s\n"
|
||||
"\t%s\n"
|
||||
"\t%s\n",
|
||||
FILTER_HQ2X_STR, FILTER_HQ4X_STR, FILTER_GRAYSCALE_STR,
|
||||
FILTER_BLEED_STR, FILTER_NTSC_STR);
|
||||
exit(1);
|
||||
}
|
||||
if (strcmp("cg", tmp_str) == 0)
|
||||
g_settings.video.shader_type = SSNES_SHADER_CG;
|
||||
else if (strcmp("bsnes", tmp_str) == 0)
|
||||
g_settings.video.shader_type = SSNES_SHADER_BSNES;
|
||||
else if (strcmp("auto", tmp_str) == 0)
|
||||
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);
|
||||
g_settings.video.filter = filter;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Input Settings.
|
||||
if (config_get_double(conf, "input_axis_threshold", &tmp_double))
|
||||
g_settings.input.axis_threshold = tmp_double;
|
||||
#if defined(HAVE_XML)
|
||||
CONFIG_GET_STRING(video.shader_dir, "video_shader_dir");
|
||||
#endif
|
||||
|
||||
// Joypad mapping.
|
||||
if (config_get_int(conf, "input_player1_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[0] = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "input_player2_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[1] = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "input_player3_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[2] = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "input_player4_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[3] = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "input_player5_joypad_index", &tmp_int))
|
||||
g_settings.input.joypad_map[4] = tmp_int;
|
||||
CONFIG_GET_DOUBLE(input.axis_threshold, "input_axis_threshold");
|
||||
CONFIG_GET_BOOL(input.netplay_client_swap_input, "netplay_client_swap_input");
|
||||
CONFIG_GET_INT(input.joypad_map[0], "input_player1_joypad_index");
|
||||
CONFIG_GET_INT(input.joypad_map[1], "input_player2_joypad_index");
|
||||
CONFIG_GET_INT(input.joypad_map[2], "input_player3_joypad_index");
|
||||
CONFIG_GET_INT(input.joypad_map[3], "input_player4_joypad_index");
|
||||
CONFIG_GET_INT(input.joypad_map[4], "input_player5_joypad_index");
|
||||
|
||||
// Audio settings.
|
||||
if (config_get_bool(conf, "audio_enable", &tmp_bool))
|
||||
g_settings.audio.enable = tmp_bool;
|
||||
|
||||
if (config_get_int(conf, "audio_out_rate", &tmp_int))
|
||||
g_settings.audio.out_rate = tmp_int;
|
||||
|
||||
if (config_get_int(conf, "audio_in_rate", &tmp_int))
|
||||
g_settings.audio.in_rate = tmp_int;
|
||||
|
||||
if (config_get_string(conf, "audio_device", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.audio.device, tmp_str, sizeof(g_settings.audio.device) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
|
||||
if (config_get_int(conf, "audio_latency", &tmp_int))
|
||||
g_settings.audio.latency = tmp_int;
|
||||
|
||||
if (config_get_bool(conf, "audio_sync", &tmp_bool))
|
||||
g_settings.audio.sync = tmp_bool;
|
||||
CONFIG_GET_BOOL(audio.enable, "audio_enable");
|
||||
CONFIG_GET_INT(audio.out_rate, "audio_out_rate");
|
||||
CONFIG_GET_DOUBLE(audio.in_rate, "audio_in_rate");
|
||||
CONFIG_GET_DOUBLE(audio.rate_step, "audio_rate_step");
|
||||
CONFIG_GET_STRING(audio.device, "audio_device");
|
||||
CONFIG_GET_INT(audio.latency, "audio_latency");
|
||||
CONFIG_GET_BOOL(audio.sync, "audio_sync");
|
||||
|
||||
#ifdef HAVE_SRC
|
||||
if (config_get_int(conf, "audio_src_quality", &tmp_int))
|
||||
{
|
||||
int quals[] = { SRC_ZERO_ORDER_HOLD, SRC_LINEAR, SRC_SINC_FASTEST,
|
||||
@@ -342,27 +352,22 @@ static void parse_config_file(void)
|
||||
if (tmp_int > 0 && tmp_int < 6)
|
||||
g_settings.audio.src_quality = quals[tmp_int];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (config_get_string(conf, "video_driver", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.video.driver, tmp_str, sizeof(g_settings.video.driver) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
if (config_get_string(conf, "audio_driver", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.audio.driver, tmp_str, sizeof(g_settings.audio.driver) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
if (config_get_string(conf, "input_driver", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.input.driver, tmp_str, sizeof(g_settings.input.driver) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
if (config_get_string(conf, "libsnes_path", &tmp_str))
|
||||
{
|
||||
strncpy(g_settings.libsnes, tmp_str, sizeof(g_settings.libsnes) - 1);
|
||||
free(tmp_str);
|
||||
}
|
||||
CONFIG_GET_STRING(video.driver, "video_driver");
|
||||
CONFIG_GET_STRING(audio.driver, "audio_driver");
|
||||
CONFIG_GET_STRING(input.driver, "input_driver");
|
||||
CONFIG_GET_STRING(libsnes, "libsnes_path");
|
||||
|
||||
CONFIG_GET_BOOL(rewind_enable, "rewind_enable");
|
||||
|
||||
if (config_get_int(conf, "rewind_buffer_size", &tmp_int))
|
||||
g_settings.rewind_buffer_size = tmp_int * 1000000;
|
||||
|
||||
CONFIG_GET_INT(rewind_granularity, "rewind_granularity");
|
||||
|
||||
CONFIG_GET_BOOL(pause_nonactive, "pause_nonactive");
|
||||
CONFIG_GET_INT(autosave_interval, "autosave_interval");
|
||||
|
||||
read_keybinds(conf);
|
||||
|
||||
@@ -401,6 +406,14 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
|
||||
DECLARE_BIND(state_slot_decrease, SSNES_STATE_SLOT_MINUS)
|
||||
DECLARE_BIND(exit_emulator, SSNES_QUIT_KEY)
|
||||
DECLARE_BIND(toggle_fullscreen, SSNES_FULLSCREEN_TOGGLE_KEY)
|
||||
DECLARE_BIND(rate_step_up, SSNES_AUDIO_INPUT_RATE_PLUS)
|
||||
DECLARE_BIND(rate_step_down, SSNES_AUDIO_INPUT_RATE_MINUS)
|
||||
DECLARE_BIND(rewind, SSNES_REWIND)
|
||||
DECLARE_BIND(movie_record_toggle, SSNES_MOVIE_RECORD_TOGGLE)
|
||||
DECLARE_BIND(pause_toggle, SSNES_PAUSE_TOGGLE)
|
||||
DECLARE_BIND(reset, SSNES_RESET)
|
||||
DECLARE_BIND(shader_next, SSNES_SHADER_NEXT)
|
||||
DECLARE_BIND(shader_prev, SSNES_SHADER_PREV)
|
||||
},
|
||||
{
|
||||
DECLARE_BIND(player2_a, SNES_DEVICE_ID_JOYPAD_A)
|
||||
@@ -422,6 +435,14 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
|
||||
DECLARE_BIND(state_slot_decrease, SSNES_STATE_SLOT_MINUS)
|
||||
DECLARE_BIND(exit_emulator, SSNES_QUIT_KEY)
|
||||
DECLARE_BIND(toggle_fullscreen, SSNES_FULLSCREEN_TOGGLE_KEY)
|
||||
DECLARE_BIND(rate_step_up, SSNES_AUDIO_INPUT_RATE_PLUS)
|
||||
DECLARE_BIND(rate_step_down, SSNES_AUDIO_INPUT_RATE_MINUS)
|
||||
DECLARE_BIND(rewind, SSNES_REWIND)
|
||||
DECLARE_BIND(movie_record_toggle, SSNES_MOVIE_RECORD_TOGGLE)
|
||||
DECLARE_BIND(pause_toggle, SSNES_PAUSE_TOGGLE)
|
||||
DECLARE_BIND(reset, SSNES_RESET)
|
||||
DECLARE_BIND(shader_next, SSNES_SHADER_NEXT)
|
||||
DECLARE_BIND(shader_prev, SSNES_SHADER_PREV)
|
||||
},
|
||||
{
|
||||
DECLARE_BIND(player3_a, SNES_DEVICE_ID_JOYPAD_A)
|
||||
@@ -443,6 +464,14 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
|
||||
DECLARE_BIND(state_slot_decrease, SSNES_STATE_SLOT_MINUS)
|
||||
DECLARE_BIND(exit_emulator, SSNES_QUIT_KEY)
|
||||
DECLARE_BIND(toggle_fullscreen, SSNES_FULLSCREEN_TOGGLE_KEY)
|
||||
DECLARE_BIND(rate_step_up, SSNES_AUDIO_INPUT_RATE_PLUS)
|
||||
DECLARE_BIND(rate_step_down, SSNES_AUDIO_INPUT_RATE_MINUS)
|
||||
DECLARE_BIND(rewind, SSNES_REWIND)
|
||||
DECLARE_BIND(movie_record_toggle, SSNES_MOVIE_RECORD_TOGGLE)
|
||||
DECLARE_BIND(pause_toggle, SSNES_PAUSE_TOGGLE)
|
||||
DECLARE_BIND(reset, SSNES_RESET)
|
||||
DECLARE_BIND(shader_next, SSNES_SHADER_NEXT)
|
||||
DECLARE_BIND(shader_prev, SSNES_SHADER_PREV)
|
||||
},
|
||||
{
|
||||
DECLARE_BIND(player4_a, SNES_DEVICE_ID_JOYPAD_A)
|
||||
@@ -464,6 +493,14 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
|
||||
DECLARE_BIND(state_slot_decrease, SSNES_STATE_SLOT_MINUS)
|
||||
DECLARE_BIND(exit_emulator, SSNES_QUIT_KEY)
|
||||
DECLARE_BIND(toggle_fullscreen, SSNES_FULLSCREEN_TOGGLE_KEY)
|
||||
DECLARE_BIND(rate_step_up, SSNES_AUDIO_INPUT_RATE_PLUS)
|
||||
DECLARE_BIND(rate_step_down, SSNES_AUDIO_INPUT_RATE_MINUS)
|
||||
DECLARE_BIND(rewind, SSNES_REWIND)
|
||||
DECLARE_BIND(movie_record_toggle, SSNES_MOVIE_RECORD_TOGGLE)
|
||||
DECLARE_BIND(pause_toggle, SSNES_PAUSE_TOGGLE)
|
||||
DECLARE_BIND(reset, SSNES_RESET)
|
||||
DECLARE_BIND(shader_next, SSNES_SHADER_NEXT)
|
||||
DECLARE_BIND(shader_prev, SSNES_SHADER_PREV)
|
||||
},
|
||||
{
|
||||
DECLARE_BIND(player5_a, SNES_DEVICE_ID_JOYPAD_A)
|
||||
@@ -485,6 +522,14 @@ static const struct bind_map bind_maps[MAX_PLAYERS][MAX_BINDS - 1] = {
|
||||
DECLARE_BIND(state_slot_decrease, SSNES_STATE_SLOT_MINUS)
|
||||
DECLARE_BIND(exit_emulator, SSNES_QUIT_KEY)
|
||||
DECLARE_BIND(toggle_fullscreen, SSNES_FULLSCREEN_TOGGLE_KEY)
|
||||
DECLARE_BIND(rate_step_up, SSNES_AUDIO_INPUT_RATE_PLUS)
|
||||
DECLARE_BIND(rate_step_down, SSNES_AUDIO_INPUT_RATE_MINUS)
|
||||
DECLARE_BIND(rewind, SSNES_REWIND)
|
||||
DECLARE_BIND(movie_record_toggle, SSNES_MOVIE_RECORD_TOGGLE)
|
||||
DECLARE_BIND(pause_toggle, SSNES_PAUSE_TOGGLE)
|
||||
DECLARE_BIND(reset, SSNES_RESET)
|
||||
DECLARE_BIND(shader_next, SSNES_SHADER_NEXT)
|
||||
DECLARE_BIND(shader_prev, SSNES_SHADER_PREV)
|
||||
},
|
||||
};
|
||||
|
||||
@@ -511,6 +556,8 @@ static const struct key_map sdlk_map[] = {
|
||||
{ "alt", SDLK_LALT },
|
||||
{ "space", SDLK_SPACE },
|
||||
{ "escape", SDLK_ESCAPE },
|
||||
{ "kp_plus", SDLK_KP_PLUS },
|
||||
{ "kp_minus", SDLK_KP_MINUS },
|
||||
{ "f1", SDLK_F1 },
|
||||
{ "f2", SDLK_F2 },
|
||||
{ "f3", SDLK_F3 },
|
||||
@@ -523,6 +570,7 @@ static const struct key_map sdlk_map[] = {
|
||||
{ "f10", SDLK_F10 },
|
||||
{ "f11", SDLK_F11 },
|
||||
{ "f12", SDLK_F12 },
|
||||
{ "nul", SDLK_UNKNOWN },
|
||||
};
|
||||
|
||||
static struct snes_keybind *find_snes_bind(unsigned port, int id)
|
||||
@@ -556,6 +604,7 @@ static int find_sdlk_key(const char *str)
|
||||
return find_sdlk_bind(str);
|
||||
}
|
||||
|
||||
// Yes, this function needs a good refactor :)
|
||||
static void read_keybinds(config_file_t *conf)
|
||||
{
|
||||
char *tmp_key = NULL;
|
||||
@@ -570,6 +619,7 @@ static void read_keybinds(config_file_t *conf)
|
||||
if (!bind)
|
||||
continue;
|
||||
|
||||
// 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);
|
||||
@@ -581,40 +631,53 @@ static void read_keybinds(config_file_t *conf)
|
||||
tmp_key = NULL;
|
||||
}
|
||||
|
||||
// Check joybutton bind (hats too)
|
||||
if (bind_maps[j][i].btn && config_get_string(conf, bind_maps[j][i].btn, &tmp_btn))
|
||||
{
|
||||
const char *btn = tmp_btn;
|
||||
if (*btn++ == 'h')
|
||||
if (strcmp(tmp_btn, "nul") == 0)
|
||||
{
|
||||
if (isdigit(*btn))
|
||||
{
|
||||
char *dir = NULL;
|
||||
int hat = strtol(btn, &dir, 0);
|
||||
int hat_dir = 0;
|
||||
if (dir)
|
||||
{
|
||||
if (strcasecmp(dir, "up") == 0)
|
||||
hat_dir = HAT_UP_MASK;
|
||||
else if (strcasecmp(dir, "down") == 0)
|
||||
hat_dir = HAT_DOWN_MASK;
|
||||
else if (strcasecmp(dir, "left") == 0)
|
||||
hat_dir = HAT_LEFT_MASK;
|
||||
else if (strcasecmp(dir, "right") == 0)
|
||||
hat_dir = HAT_RIGHT_MASK;
|
||||
|
||||
if (hat_dir)
|
||||
bind->joykey = HAT_MAP(hat, hat_dir);
|
||||
}
|
||||
}
|
||||
bind->joykey = NO_BTN;
|
||||
}
|
||||
else
|
||||
bind->joykey = strtol(tmp_btn, NULL, 0);
|
||||
{
|
||||
if (*btn++ == 'h')
|
||||
{
|
||||
if (isdigit(*btn))
|
||||
{
|
||||
char *dir = NULL;
|
||||
int hat = strtol(btn, &dir, 0);
|
||||
int hat_dir = 0;
|
||||
if (dir)
|
||||
{
|
||||
if (strcasecmp(dir, "up") == 0)
|
||||
hat_dir = HAT_UP_MASK;
|
||||
else if (strcasecmp(dir, "down") == 0)
|
||||
hat_dir = HAT_DOWN_MASK;
|
||||
else if (strcasecmp(dir, "left") == 0)
|
||||
hat_dir = HAT_LEFT_MASK;
|
||||
else if (strcasecmp(dir, "right") == 0)
|
||||
hat_dir = HAT_RIGHT_MASK;
|
||||
|
||||
if (hat_dir)
|
||||
bind->joykey = HAT_MAP(hat, hat_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bind->joykey = strtol(tmp_btn, NULL, 0);
|
||||
}
|
||||
free(tmp_btn);
|
||||
}
|
||||
|
||||
// Check joyaxis binds.
|
||||
if (bind_maps[j][i].axis && config_get_string(conf, bind_maps[j][i].axis, &tmp_axis))
|
||||
{
|
||||
if (strlen(tmp_axis) >= 2 && (*tmp_axis == '+' || *tmp_axis == '-'))
|
||||
if (strcmp(tmp_axis, "nul") == 0)
|
||||
{
|
||||
bind->joyaxis = AXIS_NONE;
|
||||
}
|
||||
else if (strlen(tmp_axis) >= 2 && (*tmp_axis == '+' || *tmp_axis == '-'))
|
||||
{
|
||||
int axis = strtol(tmp_axis + 1, NULL, 0);
|
||||
if (*tmp_axis == '+')
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/bin/sh
|
||||
###
|
||||
## Wrapper script that enables loading of compressed roms for SSNES.
|
||||
## Author: Themaister
|
||||
## License: Do whatever you want with it.
|
||||
#
|
||||
|
||||
die()
|
||||
{
|
||||
echo "Error: $1"
|
||||
rm "$TMPROM"
|
||||
rm -r "$TMPDIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
die "Need at least one argument"
|
||||
fi
|
||||
|
||||
COMP_FILE="$1"
|
||||
TMPROM="`mktemp`"
|
||||
TMPDIR="`mktemp -d`"
|
||||
shift
|
||||
|
||||
extract_zip()
|
||||
{
|
||||
which unzip >/dev/null 2>&1 || die "Cannot find unzip"
|
||||
which zipinfo >/dev/null 2>&1 || die "Cannot find zipinfo"
|
||||
FILENAME="`zipinfo -1 \"$1\" | grep '\.s[mf]c$' | head -n1`"
|
||||
if [ -z "$FILENAME" ]; then
|
||||
die "Cannot find .smc nor .sfc file in archive"
|
||||
fi
|
||||
|
||||
unzip -p "$1" "$FILENAME" > "$TMPROM"
|
||||
}
|
||||
|
||||
extract_7z()
|
||||
{
|
||||
which 7z >/dev/null 2>&1 || die "Cannot find 7z"
|
||||
7z x "$1" -o"$TMPDIR" >/dev/null 2>&1 || die "Couldn't extract from archive"
|
||||
FILENAME="`ls \"$TMPDIR\" | grep '\.s[mf]c$' | head -n1`"
|
||||
if [ -z "$FILENAME" ]; then
|
||||
die "Cannot find .smc nor .sfc file in archive"
|
||||
fi
|
||||
|
||||
mv "${TMPDIR}/${FILENAME}" "$TMPROM"
|
||||
}
|
||||
|
||||
extract_rar()
|
||||
{
|
||||
which unrar >/dev/null 2>&1 || die "Cannot find unrar"
|
||||
unrar x "$1" "$TMPDIR" >/dev/null 2>&1 || die "Couldn't extract from archive"
|
||||
FILENAME="`ls \"$TMPDIR\" | grep '\.s[mf]c$' | head -n1`"
|
||||
if [ -z "$FILENAME" ]; then
|
||||
die "Cannot find .smc nor .sfc file in archive"
|
||||
fi
|
||||
|
||||
mv "${TMPDIR}/${FILENAME}" "$TMPROM"
|
||||
}
|
||||
|
||||
case "$COMP_FILE" in
|
||||
*.zip )
|
||||
extract_zip "$COMP_FILE"
|
||||
EXTENSION=".zip"
|
||||
;;
|
||||
*.7z )
|
||||
extract_7z "$COMP_FILE"
|
||||
EXTENSION=".7z"
|
||||
;;
|
||||
*.rar )
|
||||
extract_rar "$COMP_FILE"
|
||||
EXTENSION=".rar"
|
||||
;;
|
||||
* )
|
||||
die "Couldn't find valid zipped rom."
|
||||
;;
|
||||
esac
|
||||
|
||||
SAVENAME="`basename \"$COMP_FILE\" $EXTENSION`"
|
||||
DIRNAME="`dirname \"$COMP_FILE\"`"
|
||||
SAVENAME="${SAVENAME}.srm"
|
||||
echo "Savename: ${DIRNAME}/${SAVENAME}"
|
||||
|
||||
SSNES_PATH="`which ssnes`"
|
||||
if [ -z "$SSNES_PATH" ]; then
|
||||
die "Cannot find SSNES in path."
|
||||
fi
|
||||
|
||||
"$SSNES_PATH" "$TMPROM" -s "${DIRNAME}/${SAVENAME}" "$@"
|
||||
rm "$TMPROM"
|
||||
rm -r "$TMPDIR"
|
||||
@@ -9,9 +9,9 @@
|
||||
# video_xscale = 3.0
|
||||
# video_yscale = 3.0
|
||||
|
||||
# Fullscreen resolution
|
||||
# video_fullscreen_x = 1920
|
||||
# video_fullscreen_y = 1200
|
||||
# Fullscreen resolution. Resolution of 0 uses the resolution of the desktop.
|
||||
# video_fullscreen_x = 0
|
||||
# video_fullscreen_y = 0
|
||||
|
||||
# Start in fullscreen. Can be changed at runtime.
|
||||
# video_fullscreen = false
|
||||
@@ -19,7 +19,7 @@
|
||||
# Video vsync.
|
||||
# video_vsync = true
|
||||
|
||||
# Smoothens picture with bilinear filtering. Should be disabled if using Cg shaders.
|
||||
# Smoothens picture with bilinear filtering. Should be disabled if using pixel shaders.
|
||||
# video_smooth = true
|
||||
|
||||
# Forces rendering area to stay equal to SNES aspect ratio 4:3 or as defined in video_aspect_ratio.
|
||||
@@ -28,22 +28,45 @@
|
||||
# A floating point value for video aspect ratio (width / height)
|
||||
# video_aspect_ratio = 1.333
|
||||
|
||||
# Path to Cg shader. If enabled
|
||||
# Path to Cg shader.
|
||||
# video_cg_shader = "/path/to/cg/shader.cg"
|
||||
|
||||
# Path to bSNES-style XML shader. If both Cg shader path and XML shader path are defined, Cg shader will take priority.
|
||||
# Path to bSNES XML shader (GLSL only). If both Cg shader path and XML shader path are defined,
|
||||
# Cg shader will take priority unless overridden in video_shader_type.
|
||||
# video_bsnes_shader = "/path/to/bsnes/xml/shader.shader"
|
||||
|
||||
# CPU-based filter. Valid ones are: hq2x, hq4x, grayscale, bleed, ntsc.
|
||||
# video_filter = ntsc
|
||||
# Which shader type to use. Valid values are "cg", "bsnes", "none" and "auto"
|
||||
# video_shader_type = auto
|
||||
|
||||
# Defines a directory where XML shaders are kept.
|
||||
# video_shader_dir =
|
||||
|
||||
# Render to texture first. Useful when doing multi-pass shaders or control the output of shaders better.
|
||||
# video_render_to_texture = false
|
||||
|
||||
# Defines the video scale of render-to-texture.
|
||||
# The output FBO size is scaled by these amounts against the input size (typically 256 * 224 for SNES).
|
||||
# video_fbo_scale_x = 2.0
|
||||
# video_fbo_scale_y = 2.0
|
||||
|
||||
# Define shader to use for second pass (needs render-to-texture).
|
||||
# video_second_pass_shader = "/path/to/second/shader.{cg,shader}"
|
||||
|
||||
# Defines if bilinear filtering is used during second pass (needs render-to-texture).
|
||||
# video_second_pass_smooth = true
|
||||
|
||||
# CPU-based filter. Path to a bSNES CPU filter (*.filter)
|
||||
# video_filter =
|
||||
|
||||
# Path to a TTF font used for rendering messages. This path must be defined to enable fonts.
|
||||
# Do note that the _full_ path of the font is necessary!
|
||||
# video_font_path =
|
||||
|
||||
# Size of the TTF font rendered.
|
||||
# video_font_size = 48
|
||||
|
||||
# Offset for where messages will be placed on screen. Values are in range 0.0 to 1.0 for both x and y values.
|
||||
# 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
|
||||
|
||||
@@ -61,10 +84,13 @@
|
||||
# but lots of dropped frames. Reasonable values for this is 32000 +/- 100 Hz.
|
||||
# audio_in_rate = 31980
|
||||
|
||||
# Audio driver backend. Depending on configuration possible candidates are: alsa, oss, jack, rsound, roar, openal and sdl
|
||||
# When altering audio_in_rate on-the-fly, define by how much each time.
|
||||
# audio_rate_step = 0.25
|
||||
|
||||
# Audio driver backend. Depending on configuration possible candidates are: alsa, pulse, oss, jack, rsound, roar, openal, sdl and xaudio
|
||||
# audio_driver =
|
||||
|
||||
# Override the default audio device the audio_driver uses.
|
||||
# Override the default audio device the audio_driver uses. This is driver dependant. E.g. ALSA wants a PCM device, OSS wants a path (e.g. /dev/dsp), Jack wants portnames (e.g. system:playback1,system:playback_2), and so on ...
|
||||
# audio_device =
|
||||
|
||||
# Will sync (block) on audio. Recommended.
|
||||
@@ -73,7 +99,7 @@
|
||||
# Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency.
|
||||
# audio_latency = 64
|
||||
|
||||
# libsamplerate quality. Valid values are from 1 to 5. These values map to zero_order_hold, linear, sinc_fastest, sinc_medium and sinc_best.
|
||||
# libsamplerate quality. Valid values are from 1 to 5. These values map to zero_order_hold, linear, sinc_fastest, sinc_medium and sinc_best respectively.
|
||||
# audio_src_quality =
|
||||
|
||||
### Input
|
||||
@@ -85,6 +111,8 @@
|
||||
# input_axis_threshold = 0.5
|
||||
|
||||
# Keyboard input. Will recognize normal keypresses and special keys like "left", "right", and so on.
|
||||
# Keyboard input, Joypad and Joyaxis will all obey the "nul" bind, which disables the bind completely,
|
||||
# rather than relying on a default.
|
||||
# input_player1_a = x
|
||||
# input_player1_b = z
|
||||
# input_player1_y = a
|
||||
@@ -98,11 +126,14 @@
|
||||
# input_player1_up = up
|
||||
# input_player1_down = down
|
||||
|
||||
# If desired, it is possible to override which joypads are being used for player 1 and 2. First joypad available is 0.
|
||||
# If desired, it is possible to override which joypads are being used for player 1 through 5. First joypad available is 0.
|
||||
# input_player1_joypad_index = 0
|
||||
# input_player2_joypad_index = 1
|
||||
# input_player3_joypad_index = 2
|
||||
# input_player4_joypad_index = 3
|
||||
# input_player5_joypad_index = 4
|
||||
|
||||
# Joypad buttons. Figure these out by looking at jstest /dev/input/js0 output.
|
||||
# Joypad buttons. Figure these out by looking at jstest /dev/input/js0 output, or use ssnes-joyconfig.
|
||||
# You can use joypad hats with hnxx, where n is the hat, and xx is a string representing direction.
|
||||
# E.g. "h0up"
|
||||
# input_player1_a_btn = 1
|
||||
@@ -118,7 +149,7 @@
|
||||
# input_player1_up_btn = 13
|
||||
# input_player1_down_btn = 14
|
||||
|
||||
# Axis for DPAD.
|
||||
# Axis for SNES DPAD.
|
||||
# Needs to be either '+' or '-' in the first character signaling either positive or negative direction of the axis, then the axis number.
|
||||
# Do note that every other input option has the corresponding _btn and _axis binds as well; they are omitted here for clarity.
|
||||
# input_player1_left_axis = -0
|
||||
@@ -159,6 +190,8 @@
|
||||
# input_player2_up_axis = -1
|
||||
# input_player2_down_axis = +1
|
||||
|
||||
# This goes all the way to player 5, but again omitted for clarity.
|
||||
|
||||
# Toggles fullscreen.
|
||||
# input_toggle_fullscreen = f
|
||||
# Saves state.
|
||||
@@ -177,3 +210,45 @@
|
||||
# Key to exit emulator cleanly.
|
||||
# Killing it in any hard way (SIGTERM, SIGKILL, etc, will terminate emulator without saving RAM, etc.)
|
||||
# input_exit_emulator = escape
|
||||
|
||||
# Decrease/increase input sample rate on the fly. Amount to decrease/increase is defined by audio_rate_step.
|
||||
# input_rate_step_up = kp_plus
|
||||
# input_rate_step_down = kp_minus
|
||||
|
||||
# Applies next and previous XML shader in directory.
|
||||
# input_shader_next = m
|
||||
# input_shader_prev = n
|
||||
|
||||
# Enable rewinding. This will take a performance hit when playing, so it is disabled by default.
|
||||
# Do note that rewinding will only work properly when using bSNES libsnes core atm.
|
||||
# rewind_enable = false
|
||||
|
||||
# Rewinding buffer size in megabytes. Bigger rewinding buffer means you can rewind longer.
|
||||
# The buffer should be approx. 20MB per minute of buffer time.
|
||||
# rewind_buffer_size = 20
|
||||
|
||||
# Rewind granularity. When rewinding defined number of frames, you can rewind several frames at a time, increasing the rewinding speed.
|
||||
# rewind_granularity = 1
|
||||
|
||||
# Hold button down to rewind. Rewinding must be enabled.
|
||||
# input_rewind = r
|
||||
|
||||
# Toggle between recording and not.
|
||||
# input_movie_record_toggle = o
|
||||
|
||||
# Toggle between paused and non-paused state
|
||||
# input_pause_toggle = p
|
||||
|
||||
# Reset the emulated SNES.
|
||||
# input_reset = h
|
||||
|
||||
# Pause gameplay when window focus is lost.
|
||||
# pause_nonactive = true
|
||||
|
||||
# Autosaves the non-volatile SRAM at a regular interval. This is disabled by default unless set otherwise.
|
||||
# The interval is measured in seconds. A value of 0 disables autosave.
|
||||
# autosave_interval =
|
||||
|
||||
# When being client over netplay, use keybinds for player 1.
|
||||
# netplay_client_swap_input = false
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/* 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 "strl.h"
|
||||
|
||||
#ifndef HAVE_STRL
|
||||
// Implementation of strlcpy()/strlcat() based on OpenBSD.
|
||||
|
||||
size_t strlcpy(char *dest, const char *source, size_t size)
|
||||
{
|
||||
size_t src_size = 0;
|
||||
size_t n = size;
|
||||
|
||||
if (n)
|
||||
while (--n && (*dest++ = *source++)) src_size++;
|
||||
|
||||
if (!n)
|
||||
{
|
||||
if (size) *dest = '\0';
|
||||
while (*source++) src_size++;
|
||||
}
|
||||
|
||||
return src_size;
|
||||
}
|
||||
|
||||
size_t strlcat(char *dest, const char *source, size_t size)
|
||||
{
|
||||
size_t len = strlen(dest);
|
||||
dest += len;
|
||||
size -= len;
|
||||
return len + strlcpy(dest, source, size);
|
||||
}
|
||||
#endif
|
||||
+11
-22
@@ -15,32 +15,21 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __SSNES_STRL_H
|
||||
#define __SSNES_STRL_H
|
||||
|
||||
#ifndef __FILTERS_H
|
||||
#define __FILTERS_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FILTER
|
||||
#ifndef HAVE_STRL
|
||||
// Avoid possible naming collitions during link since we prefer to use the actual name.
|
||||
#define strlcpy(dst, src, size) __strlcpy_ssnes(dst, src, size)
|
||||
#define strlcat(dst, src, size) __strlcat_ssnes(dst, src, size)
|
||||
|
||||
#include "pastlib.h"
|
||||
#include "grayscale.h"
|
||||
#include "bleed.h"
|
||||
#include "ntsc.h"
|
||||
|
||||
#define FILTER_NONE 0
|
||||
#define FILTER_HQ2X 1
|
||||
#define FILTER_HQ4X 2
|
||||
#define FILTER_GRAYSCALE 3
|
||||
#define FILTER_BLEED 4
|
||||
#define FILTER_NTSC 5
|
||||
#define FILTER_HQ2X_STR "hq2x"
|
||||
#define FILTER_HQ4X_STR "hq4x"
|
||||
#define FILTER_GRAYSCALE_STR "grayscale"
|
||||
#define FILTER_BLEED_STR "bleed"
|
||||
#define FILTER_NTSC_STR "ntsc"
|
||||
size_t strlcpy(char *dest, const char *source, size_t size);
|
||||
size_t strlcat(char *dest, const char *source, size_t size);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+55
-13
@@ -27,6 +27,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include "general.h"
|
||||
|
||||
|
||||
@@ -34,6 +35,7 @@ static int g_player = 1;
|
||||
static int g_joypad = 0;
|
||||
static char *g_in_path = NULL;
|
||||
static char *g_out_path = NULL;
|
||||
static bool g_use_misc = false;
|
||||
|
||||
static void print_help(void)
|
||||
{
|
||||
@@ -47,6 +49,7 @@ static void print_help(void)
|
||||
puts("-i/--input: Input file to configure with. Binds will be added on or overwritten.");
|
||||
puts("\tIf not selected, an empty config will be used as a base.");
|
||||
puts("-o/--output: Output file to write to. If not selected, config file will be dumped to stdout.");
|
||||
puts("-m/--misc: Also configure various keybinds that are not directly SNES related. These configurations are for player 1 only.");
|
||||
puts("-h/--help: This help.");
|
||||
}
|
||||
|
||||
@@ -55,9 +58,13 @@ struct bind
|
||||
char *keystr;
|
||||
char *confbtn[MAX_PLAYERS];
|
||||
char *confaxis[MAX_PLAYERS];
|
||||
bool is_misc;
|
||||
};
|
||||
|
||||
#define BIND(x, k) { x, { "input_player1_" #k "_btn", "input_player2_" #k "_btn", "input_player3_" #k "_btn", "input_player4_" #k "_btn", "input_player5_" #k "_btn" }, {"input_player1_" #k "_axis", "input_player2_" #k "_axis", "input_player3_" #k "_axis", "input_player4_" #k "_axis", "input_player5_" #k "_axis"}},
|
||||
#define BIND(x, k) { x, { "input_player1_" #k "_btn", "input_player2_" #k "_btn", "input_player3_" #k "_btn", "input_player4_" #k "_btn", "input_player5_" #k "_btn" }, {"input_player1_" #k "_axis", "input_player2_" #k "_axis", "input_player3_" #k "_axis", "input_player4_" #k "_axis", "input_player5_" #k "_axis"}, false},
|
||||
|
||||
#define MISC_BIND(x, k) { x, { "input_" #k "_btn" }, { "input_" #k "_axis" }, true},
|
||||
|
||||
static struct bind binds[] = {
|
||||
BIND("A button (right)", a)
|
||||
BIND("B button (down)", b)
|
||||
@@ -71,9 +78,25 @@ static struct bind binds[] = {
|
||||
BIND("Up D-pad", up)
|
||||
BIND("Right D-pad", right)
|
||||
BIND("Down D-pad", down)
|
||||
|
||||
MISC_BIND("Save state", save_state)
|
||||
MISC_BIND("Load state", load_state)
|
||||
MISC_BIND("Exit emulator", exit_emulator)
|
||||
MISC_BIND("Toggle fullscreen", toggle_fullscreen)
|
||||
MISC_BIND("Save state slot increase", state_slot_increase)
|
||||
MISC_BIND("Save state slot decrease", state_slot_decrease)
|
||||
MISC_BIND("Toggle fast forward", toggle_fast_forward)
|
||||
MISC_BIND("Audio input rate step up", rate_step_up)
|
||||
MISC_BIND("Audio input rate step down", rate_step_down)
|
||||
MISC_BIND("Rewind", rewind)
|
||||
MISC_BIND("Movie recording toggle", movie_record_toggle)
|
||||
MISC_BIND("Pause", pause_toggle)
|
||||
MISC_BIND("Reset", reset)
|
||||
MISC_BIND("Next shader", shader_next)
|
||||
MISC_BIND("Previous shader", shader_prev)
|
||||
};
|
||||
|
||||
void get_binds(config_file_t *conf, int player, int joypad)
|
||||
static void get_binds(config_file_t *conf, int player, int joypad)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
@@ -95,20 +118,21 @@ void get_binds(config_file_t *conf, int player, int joypad)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
int last_axis = 0xFF;
|
||||
int last_pos = 0;
|
||||
int num_axes = SDL_JoystickNumAxes(joystick);
|
||||
int initial_axes[num_axes];
|
||||
|
||||
SDL_PumpEvents();
|
||||
SDL_JoystickUpdate();
|
||||
for (int i = 0; i < num_axes; i++)
|
||||
initial_axes[i] = SDL_JoystickGetAxis(joystick, i);
|
||||
|
||||
|
||||
fprintf(stderr, "Configuring binds for player #%d on joypad #%d (%s)\n", player + 1, joypad, SDL_JoystickName(joypad));
|
||||
fprintf(stderr, "Press Ctrl-C to exit early.\n");
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
for (unsigned i = 0; i < sizeof(binds) / sizeof(struct bind); i++)
|
||||
for (unsigned i = 0; i < sizeof(binds) / sizeof(struct bind) && (g_use_misc || !binds[i].is_misc) ; i++)
|
||||
{
|
||||
fprintf(stderr, "%s\n", binds[i].keystr);
|
||||
|
||||
@@ -116,6 +140,7 @@ void get_binds(config_file_t *conf, int player, int joypad)
|
||||
SDL_Event event;
|
||||
int value;
|
||||
const char *quark;
|
||||
unsigned player_index = binds[i].is_misc ? 0 : player;
|
||||
|
||||
while (SDL_WaitEvent(&event) && !done)
|
||||
{
|
||||
@@ -124,24 +149,36 @@ void get_binds(config_file_t *conf, int player, int joypad)
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
fprintf(stderr, "\tJoybutton pressed: %d\n", (int)event.jbutton.button);
|
||||
done = true;
|
||||
config_set_int(conf, binds[i].confbtn[player], event.jbutton.button);
|
||||
config_set_int(conf, binds[i].confbtn[player_index], event.jbutton.button);
|
||||
break;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (abs(event.jaxis.value) > 20000 &&
|
||||
abs((int)event.jaxis.value - initial_axes[event.jaxis.axis]) > 20000 &&
|
||||
event.jaxis.axis != last_axis)
|
||||
if ( // This is starting to look like Lisp! :D
|
||||
(abs((int)event.jaxis.value - initial_axes[event.jaxis.axis]) > 20000) &&
|
||||
(
|
||||
(event.jaxis.axis != last_axis) ||
|
||||
(
|
||||
(abs(event.jaxis.value) > 20000) &&
|
||||
(abs((int)event.jaxis.value - last_pos) > 20000)
|
||||
)
|
||||
)
|
||||
)
|
||||
{
|
||||
last_axis = event.jaxis.axis;
|
||||
last_pos = event.jaxis.value;
|
||||
fprintf(stderr, "\tJoyaxis moved: Axis %d, Value %d\n", (int)event.jaxis.axis, (int)event.jaxis.value);
|
||||
done = true;
|
||||
|
||||
char buf[8];
|
||||
snprintf(buf, sizeof(buf), event.jaxis.value > 0 ? "+%d" : "-%d", event.jaxis.axis);
|
||||
config_set_string(conf, binds[i].confaxis[player], buf);
|
||||
config_set_string(conf, binds[i].confaxis[player_index], buf);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
fprintf(stderr, ":V\n");
|
||||
break;
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
value = event.jhat.value;
|
||||
if (value & SDL_HAT_UP)
|
||||
@@ -160,7 +197,7 @@ void get_binds(config_file_t *conf, int player, int joypad)
|
||||
done = true;
|
||||
char buf[16];
|
||||
snprintf(buf, sizeof(buf), "h%d%s", event.jhat.hat, quark);
|
||||
config_set_string(conf, binds[i].confbtn[player], buf);
|
||||
config_set_string(conf, binds[i].confbtn[player_index], buf);
|
||||
break;
|
||||
|
||||
|
||||
@@ -180,13 +217,14 @@ end:
|
||||
|
||||
static void parse_input(int argc, char *argv[])
|
||||
{
|
||||
char optstring[] = "i:o:p:j:h";
|
||||
char optstring[] = "i:o:p:j:hm";
|
||||
struct option opts[] = {
|
||||
{ "input", 1, NULL, 'i' },
|
||||
{ "output", 1, NULL, 'o' },
|
||||
{ "player", 1, NULL, 'p' },
|
||||
{ "joypad", 1, NULL, 'j' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "misc", 0, NULL, 'm' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
@@ -211,6 +249,10 @@ static void parse_input(int argc, char *argv[])
|
||||
g_out_path = strdup(optarg);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
g_use_misc = true;
|
||||
break;
|
||||
|
||||
case 'j':
|
||||
g_joypad = strtol(optarg, NULL, 0);
|
||||
if (g_joypad < 0)
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/* 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 "ups.h"
|
||||
#include "movie.h"
|
||||
|
||||
struct ups_data
|
||||
{
|
||||
const uint8_t *patch_data, *source_data;
|
||||
uint8_t *target_data;
|
||||
unsigned patch_length, source_length, target_length;
|
||||
unsigned patch_offset, source_offset, target_offset;
|
||||
unsigned patch_checksum, source_checksum, target_checksum;
|
||||
};
|
||||
|
||||
static uint8_t patch_read(struct ups_data *data)
|
||||
{
|
||||
if (data->patch_offset < data->patch_length)
|
||||
{
|
||||
uint8_t n = data->patch_data[data->patch_offset++];
|
||||
data->patch_checksum = crc32_adjust(data->patch_checksum, n);
|
||||
return n;
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
static uint8_t source_read(struct ups_data *data)
|
||||
{
|
||||
if (data->source_offset < data->source_length)
|
||||
{
|
||||
uint8_t n = data->source_data[data->source_offset++];
|
||||
data->source_checksum = crc32_adjust(data->source_checksum, n);
|
||||
return n;
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
static void target_write(struct ups_data *data, uint8_t n)
|
||||
{
|
||||
if (data->target_offset < data->target_length)
|
||||
{
|
||||
data->target_data[data->target_offset] = n;
|
||||
data->target_checksum = crc32_adjust(data->target_checksum, n);
|
||||
}
|
||||
|
||||
data->target_offset++;
|
||||
}
|
||||
|
||||
static uint64_t decode(struct ups_data *data)
|
||||
{
|
||||
uint64_t offset = 0, shift = 1;
|
||||
while (true)
|
||||
{
|
||||
uint8_t x = patch_read(data);
|
||||
offset += (x & 0x7f) * shift;
|
||||
if (x & 0x80)
|
||||
break;
|
||||
shift <<= 7;
|
||||
offset += shift;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
ups_error_t ups_apply_patch(
|
||||
const uint8_t *patchdata, size_t patchlength,
|
||||
const uint8_t *sourcedata, size_t sourcelength,
|
||||
uint8_t *targetdata, size_t *targetlength)
|
||||
{
|
||||
struct ups_data data = {
|
||||
.patch_data = patchdata,
|
||||
.source_data = sourcedata,
|
||||
.target_data = targetdata,
|
||||
.patch_length = patchlength,
|
||||
.source_length = sourcelength,
|
||||
.target_length = *targetlength,
|
||||
.patch_checksum = ~0,
|
||||
.source_checksum = ~0,
|
||||
.target_checksum = ~0
|
||||
};
|
||||
|
||||
if (data.patch_length < 18)
|
||||
return UPS_PATCH_INVALID;
|
||||
if (patch_read(&data) != 'U')
|
||||
return UPS_PATCH_INVALID;
|
||||
if (patch_read(&data) != 'P')
|
||||
return UPS_PATCH_INVALID;
|
||||
if (patch_read(&data) != 'S')
|
||||
return UPS_PATCH_INVALID;
|
||||
if (patch_read(&data) != '1')
|
||||
return UPS_PATCH_INVALID;
|
||||
|
||||
unsigned source_read_length = decode(&data);
|
||||
unsigned target_read_length = decode(&data);
|
||||
|
||||
if (data.source_length != source_read_length && data.source_length != target_read_length)
|
||||
return UPS_SOURCE_INVALID;
|
||||
*targetlength = (data.source_length == source_read_length ? target_read_length : source_read_length);
|
||||
if (data.target_length < *targetlength)
|
||||
return UPS_TARGET_TOO_SMALL;
|
||||
data.target_length = *targetlength;
|
||||
|
||||
while (data.patch_offset < data.patch_length - 12)
|
||||
{
|
||||
unsigned length = decode(&data);
|
||||
while (length--)
|
||||
target_write(&data, source_read(&data));
|
||||
while (true)
|
||||
{
|
||||
uint8_t patch_xor = patch_read(&data);
|
||||
target_write(&data, patch_xor ^ source_read(&data));
|
||||
if (patch_xor == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
while (data.source_offset < data.source_length)
|
||||
target_write(&data, source_read(&data));
|
||||
while (data.target_offset < data.target_length)
|
||||
target_write(&data, source_read(&data));
|
||||
|
||||
uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0;
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
source_read_checksum |= patch_read(&data) << (i * 8);
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
target_read_checksum |= patch_read(&data) << (i * 8);
|
||||
|
||||
uint32_t patch_result_checksum = ~data.patch_checksum;
|
||||
data.source_checksum = ~data.source_checksum;
|
||||
data.target_checksum = ~data.target_checksum;
|
||||
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
patch_read_checksum |= patch_read(&data) << (i * 8);
|
||||
|
||||
if (patch_result_checksum != patch_read_checksum)
|
||||
return UPS_PATCH_INVALID;
|
||||
|
||||
if (data.source_checksum == source_read_checksum && data.source_length == source_read_length)
|
||||
{
|
||||
if (data.target_checksum == target_read_checksum && data.target_length == target_read_length)
|
||||
return UPS_SUCCESS;
|
||||
return UPS_TARGET_INVALID;
|
||||
}
|
||||
else if (data.source_checksum == target_read_checksum && data.source_length == target_read_length)
|
||||
{
|
||||
if (data.target_checksum == source_read_checksum && data.target_length == source_read_length)
|
||||
return UPS_SUCCESS;
|
||||
return UPS_TARGET_INVALID;
|
||||
}
|
||||
else
|
||||
return UPS_SOURCE_INVALID;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/* 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 __UPS_H
|
||||
#define __UPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// UPS implementation from bSNES.
|
||||
|
||||
typedef enum ups_error
|
||||
{
|
||||
UPS_UNKNOWN,
|
||||
UPS_SUCCESS,
|
||||
UPS_PATCH_INVALID,
|
||||
UPS_SOURCE_INVALID,
|
||||
UPS_TARGET_INVALID,
|
||||
UPS_TARGET_TOO_SMALL,
|
||||
UPS_PATCH_CHECKSUM_INVALID,
|
||||
UPS_SOURCE_CHECKSUM_INVALID,
|
||||
UPS_TARGET_CHECKSUM_INVALID
|
||||
} ups_error_t;
|
||||
|
||||
ups_error_t ups_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
|
||||
Reference in new issue
Block a user