aboutsummaryrefslogtreecommitdiff
path: root/games/SameBoy
diff options
context:
space:
mode:
Diffstat (limited to 'games/SameBoy')
-rw-r--r--games/SameBoy/SameBoy.SlackBuild48
-rw-r--r--games/SameBoy/SameBoy.info6
-rw-r--r--games/SameBoy/datadir.patch175
-rw-r--r--games/SameBoy/joypad.patch66
-rw-r--r--games/SameBoy/sameboy_libretro-info1
-rw-r--r--games/SameBoy/sdl.patch62
-rw-r--r--games/SameBoy/sound.patch26
7 files changed, 358 insertions, 26 deletions
diff --git a/games/SameBoy/SameBoy.SlackBuild b/games/SameBoy/SameBoy.SlackBuild
index 35d46e0c84392..eacc94ccaf757 100644
--- a/games/SameBoy/SameBoy.SlackBuild
+++ b/games/SameBoy/SameBoy.SlackBuild
@@ -25,7 +25,7 @@
PRGNAM=SameBoy
LIBNAM=$(printf %s $PRGNAM | tr 'A-Z' 'a-z')_libretro
SRCNAM=${LIBNAM%%_*}
-VERSION=${VERSION:-0.11.1}
+VERSION=${VERSION:-0.11.2}
RGBVERS=${RGBVERS:-0.3.7}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
@@ -69,6 +69,27 @@ else
CONF=release
fi
+# Add a build-time option to change the resources directory.
+# https://github.com/LIJI32/SameBoy/commit/91904df5e8cc7370776c37bdb46467a81887a6b4
+# https://github.com/LIJI32/SameBoy/pull/129
+# https://github.com/LIJI32/SameBoy/issues/39
+patch -p1 < $CWD/datadir.patch
+
+# Reconnect the joypad when SameBoy starts directly to a ROM
+# https://github.com/LIJI32/SameBoy/commit/7ffed9c43cd533c4ab16ab9d8b0879a39a00a02b
+# https://github.com/LIJI32/SameBoy/issues/131
+patch -p1 < $CWD/joypad.patch
+
+# Apply the SDL 2.0.6 audio workaround to everything except Windows
+# https://github.com/LIJI32/SameBoy/commit/453673a2a653a45d8ee378ba5335f98df5e22efa
+# https://github.com/LIJI32/SameBoy/issues/130
+patch -p1 < $CWD/sdl.patch
+
+# Adjust DAC attributes to fix LADX’s crackling audio
+# https://github.com/LIJI32/SameBoy/commit/94136f5741b7484189af048830126c4bad04ac11
+# https://github.com/LIJI32/SameBoy/issues/125
+patch -p1 < $CWD/sound.patch
+
PATH="$TMP/$PRGNAM-$VERSION/rgbds-$RGBVERS/bin:$PATH"
make -C rgbds-$RGBVERS Q=
@@ -77,29 +98,10 @@ make -C rgbds-$RGBVERS install Q= \
DESTDIR=./
if pkg-config --exists sdl2; then
- make CONF=$CONF
+ make CONF=$CONF DATA_DIR=/usr/share/games/$SRCNAM/
mkdir -p $PKG/usr/games $PKG/usr/share/games
cp -av build/bin/SDL $PKG/usr/share/games/$SRCNAM
-
-# SameBoy SDL doesn't work with FHS paths yet
-# https://github.com/LIJI32/SameBoy/issues/39
-cat > $PKG/usr/games/$SRCNAM <<EOF
-#!/bin/sh
-set -euf
-CWD="\$(pwd)"
-cd /usr/share/games/$SRCNAM
-
-if [ "\${1:-}" ]; then
- case "\$1" in
- /* ) ./$SRCNAM "\$1" ;;
- * ) ./$SRCNAM "\$CWD/\$1" ;;
- esac
-else
- ./$SRCNAM
-fi
-EOF
-
- chmod 0755 $PKG/usr/games/$SRCNAM
+ mv $PKG/usr/share/games/$SRCNAM/$SRCNAM $PKG/usr/games
else
make bootroms
fi
@@ -110,7 +112,7 @@ install -Dm0644 build/bin/$LIBNAM.so \
$PKG/usr/lib${LIBDIRSUFFIX}/libretro/$LIBNAM.so
# sameboy_libretro.info from:
-# https://raw.githubusercontent.com/libretro/libretro-super/908c0384b9642bb013c9d282a3cde1911fd29aa7/dist/info/sameboy_libretro.info
+# https://raw.githubusercontent.com/libretro/libretro-super/88176482b14e22b744b129bee84f27cb196936a9/dist/info/sameboy_libretro.info
install -Dm0644 $CWD/$LIBNAM-info \
$PKG/usr/lib${LIBDIRSUFFIX}/libretro/info/$LIBNAM.info
diff --git a/games/SameBoy/SameBoy.info b/games/SameBoy/SameBoy.info
index aaddc6d12a516..e4747e7762fa7 100644
--- a/games/SameBoy/SameBoy.info
+++ b/games/SameBoy/SameBoy.info
@@ -1,9 +1,9 @@
PRGNAM="SameBoy"
-VERSION="0.11.1"
+VERSION="0.11.2"
HOMEPAGE="https://sameboy.github.io/"
-DOWNLOAD="https://github.com/LIJI32/SameBoy/archive/v0.11.1/SameBoy-0.11.1.tar.gz \
+DOWNLOAD="https://github.com/LIJI32/SameBoy/archive/v0.11.2/SameBoy-0.11.2.tar.gz \
https://github.com/rednex/rgbds/releases/download/v0.3.7/rgbds-0.3.7.tar.gz"
-MD5SUM="fa3273894656d5ca8812e6007cf23b2f \
+MD5SUM="ce83f1981c3298174d45c28004a22fdc \
2e11f14dfcedc0b5db6f8b2781efb9c9"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
diff --git a/games/SameBoy/datadir.patch b/games/SameBoy/datadir.patch
new file mode 100644
index 0000000000000..7d721cf46d40c
--- /dev/null
+++ b/games/SameBoy/datadir.patch
@@ -0,0 +1,175 @@
+From 91904df5e8cc7370776c37bdb46467a81887a6b4 Mon Sep 17 00:00:00 2001
+From: NieDzejkob <niedzejkob@gmail.com>
+Date: Fri, 9 Nov 2018 23:20:57 +0100
+Subject: [PATCH] Add a build-time option to change the resources directory.
+
+Normally, SameBoy would use executable-relative paths for any
+resource files, which posed problems for packaging the software
+by distributions, which usually prefer FHS-compliant file locations.
+
+This commit makes it possible to specify an alternative base
+directory with a compile-time environment variable.
+---
+ Makefile | 4 ++++
+ README.md | 4 +++-
+ SDL/gui.c | 2 +-
+ SDL/main.c | 4 ++--
+ SDL/shader.c | 4 ++--
+ SDL/utils.c | 16 ++++++++++------
+ SDL/utils.h | 4 ++--
+ 7 files changed, 24 insertions(+), 14 deletions(-)
+
+diff --git a/Makefile b/Makefile
+index 330f2c81..7038ee98 100755
+--- a/Makefile
++++ b/Makefile
+@@ -33,6 +33,10 @@ BIN := build/bin
+ OBJ := build/obj
+ BOOTROMS_DIR ?= $(BIN)/BootROMs
+
++ifdef DATA_DIR
++CFLAGS += -DDATA_DIR="\"$(DATA_DIR)\""
++endif
++
+ # Set tools
+
+ # Use clang if it's available.
+diff --git a/README.md b/README.md
+index b1a2011d..91e0bf6c 100644
+--- a/README.md
++++ b/README.md
+@@ -46,6 +46,8 @@ On Windows, SameBoy also requires:
+ * [GnuWin](http://gnuwin32.sourceforge.net/)
+ * Running vcvars32 before running make. Make sure all required tools and libraries are in %PATH% and %lib%, respectively.
+
+-To compile, simply run `make`. The targets are cocoa (Default for macOS), sdl (Default for everything else), libretro, bootroms and tester. You may also specify CONF=debug (default), CONF=release or CONF=native_release to control optimization and symbols. native_release is faster than release, but is optimized to the host's CPU and therefore is not portable. You may set BOOTROMS_DIR=... to a directory containing precompiled dmg_boot.bin and cgb_boot.bin files, otherwise the build system will compile and use SameBoy's own boot ROMs.
++To compile, simply run `make`. The targets are `cocoa` (Default for macOS), `sdl` (Default for everything else), `libretro`, `bootroms` and `tester`. You may also specify `CONF=debug` (default), `CONF=release` or `CONF=native_release` to control optimization and symbols. `native_release` is faster than `release`, but is optimized to the host's CPU and therefore is not portable. You may set `BOOTROMS_DIR=...` to a directory containing precompiled `dmg_boot.bin` and `cgb_boot.bin` files, otherwise the build system will compile and use SameBoy's own boot ROMs.
++
++By default, the SDL port will look for resource files with a path relative to executable. If you are packaging SameBoy, you may wish to override this by setting the `DATA_DIR` variable during compilation to the target path of the directory containing all files (apart from the executable, that's not necessary) from the `build/bin/SDL` directory in the source tree. Make sure the variable ends with a `/` character.
+
+ SameBoy was compiled and tested on macOS, Ubuntu and 32-bit Windows 7.
+diff --git a/SDL/gui.c b/SDL/gui.c
+index d43d939a..c32eec4d 100644
+--- a/SDL/gui.c
++++ b/SDL/gui.c
+@@ -746,7 +746,7 @@ void run_gui(bool is_running)
+ /* Draw the background screen */
+ static SDL_Surface *converted_background = NULL;
+ if (!converted_background) {
+- SDL_Surface *background = SDL_LoadBMP(executable_relative_path("background.bmp"));
++ SDL_Surface *background = SDL_LoadBMP(resource_path("background.bmp"));
+ SDL_SetPaletteColors(background->format->palette, gui_palette, 0, 4);
+ converted_background = SDL_ConvertSurface(background, pixel_format, 0);
+ SDL_LockSurface(converted_background);
+diff --git a/SDL/main.c b/SDL/main.c
+index 0cf1c79d..34e2f80d 100755
+--- a/SDL/main.c
++++ b/SDL/main.c
+@@ -426,7 +426,7 @@ static void run(void)
+ bool error = false;
+ start_capturing_logs();
+ const char * const boot_roms[] = {"dmg_boot.bin", "cgb_boot.bin", "agb_boot.bin"};
+- error = GB_load_boot_rom(&gb, executable_relative_path(boot_roms[configuration.model]));
++ error = GB_load_boot_rom(&gb, resource_path(boot_roms[configuration.model]));
+ end_capturing_logs(true, error);
+
+ start_capturing_logs();
+@@ -442,7 +442,7 @@ static void run(void)
+ GB_load_battery(&gb, battery_save_path);
+
+ /* Configure symbols */
+- GB_debugger_load_symbol_file(&gb, executable_relative_path("registers.sym"));
++ GB_debugger_load_symbol_file(&gb, resource_path("registers.sym"));
+
+ char symbols_path[path_length + 5];
+ replace_extension(filename, path_length, symbols_path, ".sym");
+diff --git a/SDL/shader.c b/SDL/shader.c
+index 5b41b2a8..ed45c42f 100644
+--- a/SDL/shader.c
++++ b/SDL/shader.c
+@@ -78,7 +78,7 @@ bool init_shader_with_name(shader_t *shader, const char *name)
+ static signed long filter_token_location = 0;
+
+ if (!master_shader_code[0]) {
+- FILE *master_shader_f = fopen(executable_relative_path("Shaders/MasterShader.fsh"), "r");
++ FILE *master_shader_f = fopen(resource_path("Shaders/MasterShader.fsh"), "r");
+ if (!master_shader_f) return false;
+ fread(master_shader_code, 1, sizeof(master_shader_code) - 1, master_shader_f);
+ fclose(master_shader_f);
+@@ -92,7 +92,7 @@ bool init_shader_with_name(shader_t *shader, const char *name)
+ char shader_path[1024];
+ sprintf(shader_path, "Shaders/%s.fsh", name);
+
+- FILE *shader_f = fopen(executable_relative_path(shader_path), "r");
++ FILE *shader_f = fopen(resource_path(shader_path), "r");
+ if (!shader_f) return false;
+ memset(shader_code, 0, sizeof(shader_code));
+ fread(shader_code, 1, sizeof(shader_code) - 1, shader_f);
+diff --git a/SDL/utils.c b/SDL/utils.c
+index 539e3518..eee6ce65 100644
+--- a/SDL/utils.c
++++ b/SDL/utils.c
+@@ -3,8 +3,11 @@
+ #include <string.h>
+ #include "utils.h"
+
+-const char *executable_folder(void)
++const char *resource_folder(void)
+ {
++#ifdef DATA_DIR
++ return DATA_DIR;
++#else
+ static const char *ret = NULL;
+ if (!ret) {
+ ret = SDL_GetBasePath();
+@@ -13,21 +16,22 @@ const char *executable_folder(void)
+ }
+ }
+ return ret;
++#endif
+ }
+
+-char *executable_relative_path(const char *filename)
++char *resource_path(const char *filename)
+ {
+ static char path[1024];
+- snprintf(path, sizeof(path), "%s%s", executable_folder(), filename);
++ snprintf(path, sizeof(path), "%s%s", resource_folder(), filename);
+ return path;
+ }
+
+-
++
+ void replace_extension(const char *src, size_t length, char *dest, const char *ext)
+ {
+ memcpy(dest, src, length);
+ dest[length] = 0;
+-
++
+ /* Remove extension */
+ for (size_t i = length; i--;) {
+ if (dest[i] == '/') break;
+@@ -36,7 +40,7 @@ void replace_extension(const char *src, size_t length, char *dest, const char *e
+ break;
+ }
+ }
+-
++
+ /* Add new extension */
+ strcat(dest, ext);
+ }
+diff --git a/SDL/utils.h b/SDL/utils.h
+index 7995da90..216e723e 100644
+--- a/SDL/utils.h
++++ b/SDL/utils.h
+@@ -2,8 +2,8 @@
+ #define utils_h
+ #include <stddef.h>
+
+-const char *executable_folder(void);
+-char *executable_relative_path(const char *filename);
++const char *resource_folder(void);
++char *resource_path(const char *filename);
+ void replace_extension(const char *src, size_t length, char *dest, const char *ext);
+
+ #endif /* utils_h */
diff --git a/games/SameBoy/joypad.patch b/games/SameBoy/joypad.patch
new file mode 100644
index 0000000000000..fc089e4223592
--- /dev/null
+++ b/games/SameBoy/joypad.patch
@@ -0,0 +1,66 @@
+From 7ffed9c43cd533c4ab16ab9d8b0879a39a00a02b Mon Sep 17 00:00:00 2001
+From: Lior Halphon <LIJI32@gmail.com>
+Date: Sat, 10 Nov 2018 19:39:57 +0200
+Subject: [PATCH] Reconnect the joypad when SameBoy starts directly to a ROM
+ (fixes #131)
+
+---
+ SDL/gui.c | 10 ++++++++--
+ SDL/gui.h | 1 +
+ SDL/main.c | 3 +++
+ 3 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/SDL/gui.c b/SDL/gui.c
+index c32eec4d..ed9f3573 100644
+--- a/SDL/gui.c
++++ b/SDL/gui.c
+@@ -721,8 +721,7 @@ joypad_axis_t get_joypad_axis(uint8_t physical_axis)
+ }
+
+
+-extern void set_filename(const char *new_filename, bool new_should_free);
+-void run_gui(bool is_running)
++void connect_joypad(void)
+ {
+ if (joystick && !SDL_NumJoysticks()) {
+ if (controller) {
+@@ -743,6 +742,13 @@ void run_gui(bool is_running)
+ joystick = SDL_JoystickOpen(0);
+ }
+ }
++}
++
++extern void set_filename(const char *new_filename, bool new_should_free);
++void run_gui(bool is_running)
++{
++ connect_joypad();
++
+ /* Draw the background screen */
+ static SDL_Surface *converted_background = NULL;
+ if (!converted_background) {
+diff --git a/SDL/gui.h b/SDL/gui.h
+index 9893eb61..4d106143 100644
+--- a/SDL/gui.h
++++ b/SDL/gui.h
+@@ -92,6 +92,7 @@ extern configuration_t configuration;
+ void update_viewport(void);
+ void run_gui(bool is_running);
+ void render_texture(void *pixels, void *previous);
++void connect_joypad(void);
+
+ joypad_button_t get_joypad_button(uint8_t physical_button);
+ joypad_axis_t get_joypad_axis(uint8_t physical_axis);
+diff --git a/SDL/main.c b/SDL/main.c
+index 7db59be4..99facf8d 100755
+--- a/SDL/main.c
++++ b/SDL/main.c
+@@ -616,6 +616,9 @@ int main(int argc, char **argv)
+ if (filename == NULL) {
+ run_gui(false);
+ }
++ else {
++ connect_joypad();
++ }
+ SDL_PauseAudioDevice(device_id, 0);
+ run(); // Never returns
+ return 0;
diff --git a/games/SameBoy/sameboy_libretro-info b/games/SameBoy/sameboy_libretro-info
index ec60c3c2a4427..e68c38fea4626 100644
--- a/games/SameBoy/sameboy_libretro-info
+++ b/games/SameBoy/sameboy_libretro-info
@@ -5,6 +5,7 @@ corename = "SameBoy"
manufacturer = "Nintendo"
categories = "Emulator"
systemname = "Game Boy/Game Boy Color"
+systemid = "game_boy"
database = "Nintendo - Game Boy|Nintendo - Game Boy Color"
license = "MIT"
permissions = ""
diff --git a/games/SameBoy/sdl.patch b/games/SameBoy/sdl.patch
new file mode 100644
index 0000000000000..053a2a3747242
--- /dev/null
+++ b/games/SameBoy/sdl.patch
@@ -0,0 +1,62 @@
+From 453673a2a653a45d8ee378ba5335f98df5e22efa Mon Sep 17 00:00:00 2001
+From: Lior Halphon <LIJI32@gmail.com>
+Date: Sat, 10 Nov 2018 18:58:22 +0200
+Subject: [PATCH] Apply the SDL 2.0.6 audio workaround to everything except
+ Windows, check the linked version instead of the headers version. Fixes #130
+
+---
+ SDL/main.c | 38 ++++++++++++++++++++++----------------
+ 1 file changed, 22 insertions(+), 16 deletions(-)
+
+diff --git a/SDL/main.c b/SDL/main.c
+index c21a96f9..7db59be4 100755
+--- a/SDL/main.c
++++ b/SDL/main.c
+@@ -559,25 +559,31 @@ int main(int argc, char **argv)
+ want_aspec.freq = AUDIO_FREQUENCY;
+ want_aspec.format = AUDIO_S16SYS;
+ want_aspec.channels = 2;
+-#if SDL_COMPILEDVERSION >= 2005 && defined(__APPLE__)
+- /* SDL 2.0.5 on macOS introduced a bug where certain combinations of buffer lengths and frequencies
++ want_aspec.samples = 512;
++
++ SDL_version _sdl_version;
++ SDL_GetVersion(&_sdl_version);
++ unsigned sdl_version = _sdl_version.major * 1000 + _sdl_version.minor * 100 + _sdl_version.patch;
++
++#ifndef _WIN32
++ /* SDL 2.0.5 on macOS and Linux introduced a bug where certain combinations of buffer lengths and frequencies
+ fail to produce audio correctly. */
+- want_aspec.samples = 2048;
++ if (sdl_version >= 2005) {
++ want_aspec.samples = 2048;
++ }
+ #else
+- want_aspec.samples = 512;
+-#endif
+-
+-#if SDL_COMPILEDVERSION >= 2006 && defined(_WIN32)
+- /* SDL 2.0.6 offers WASAPI support which allows for much lower audio buffer lengths which at least
+- theoretically reduces lagging. */
+- want_aspec.samples = 32;
+-#endif
+-
+-#if SDL_COMPILEDVERSION <= 2005 && defined(_WIN32)
+- /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency
+- to 44100 because otherwise we would get garbled audio output.*/
+- want_aspec.freq = 44100;
++ if (sdl_version >= 2006) {
++ /* SDL 2.0.6 offers WASAPI support which allows for much lower audio buffer lengths which at least
++ theoretically reduces lagging. */
++ want_aspec.samples = 32;
++ }
++ else {
++ /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency
++ to 44100 because otherwise we would get garbled audio output.*/
++ want_aspec.freq = 44100;
++ }
+ #endif
++
+
+ want_aspec.callback = audio_callback;
+ want_aspec.userdata = &gb;
diff --git a/games/SameBoy/sound.patch b/games/SameBoy/sound.patch
new file mode 100644
index 0000000000000..ce1a52a703a5e
--- /dev/null
+++ b/games/SameBoy/sound.patch
@@ -0,0 +1,26 @@
+From 94136f5741b7484189af048830126c4bad04ac11 Mon Sep 17 00:00:00 2001
+From: Lior Halphon <LIJI32@gmail.com>
+Date: Sat, 10 Nov 2018 19:14:18 +0200
+Subject: [PATCH] =?UTF-8?q?Adjust=20DAC=20attributes=20to=20fix=20LADX?=
+ =?UTF-8?q?=E2=80=99s=20crackling=20audio=20(Fixes=20#125)=20while=20keepi?=
+ =?UTF-8?q?ng=20Cannon=20Fodder=E2=80=99s=20buzzing=20reasonable=20(Proper?=
+ =?UTF-8?q?=20audio=20measurements=20still=20required)?=
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+---
+ Core/apu.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Core/apu.h b/Core/apu.h
+index 01ca1321..ab42055b 100644
+--- a/Core/apu.h
++++ b/Core/apu.h
+@@ -12,7 +12,7 @@
+ They are known to be incorrect (Some analog test ROM sound different),
+ but are good enough approximations to fix Cannon Fodder's terrible audio.
+ It also varies by model. */
+-#define DAC_DECAY_SPEED (1000000)
++#define DAC_DECAY_SPEED 50000
+ #define DAC_ATTACK_SPEED 1000