Merge pull request #301 from SimpleTease1/patch1

libretro changes
This commit is contained in:
Lior Halphon 2020-10-11 02:42:02 +03:00 committed by GitHub
commit 919a88ec23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1108 additions and 425 deletions

View File

@ -4,7 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <err.h>
void opts(uint8_t byte, uint8_t *options) void opts(uint8_t byte, uint8_t *options)
{ {
@ -18,7 +17,8 @@ void write_all(int fd, const void *buf, size_t count) {
while (count) { while (count) {
ssize_t written = write(fd, buf, count); ssize_t written = write(fd, buf, count);
if (written < 0) { if (written < 0) {
err(1, "write"); fprintf(stderr, "write");
exit(1);
} }
count -= written; count -= written;
buf += written; buf += written;

View File

@ -36,7 +36,7 @@ ifeq ($(MAKECMDGOALS),)
MAKECMDGOALS := $(DEFAULT) MAKECMDGOALS := $(DEFAULT)
endif endif
VERSION := 0.13.6 include version.mk
export VERSION export VERSION
CONF ?= debug CONF ?= debug
SDL_AUDIO_DRIVER ?= sdl SDL_AUDIO_DRIVER ?= sdl

View File

@ -17,8 +17,6 @@ filter_out2 = $(call filter_out1,$(call filter_out1,$1))
unixpath = $(subst \,/,$1) unixpath = $(subst \,/,$1)
unixcygpath = /$(subst :,,$(call unixpath,$1)) unixcygpath = /$(subst :,,$(call unixpath,$1))
CFLAGS += -DSAMEBOY_CORE_VERSION=\"$(VERSION)\"
ifeq ($(platform),) ifeq ($(platform),)
platform = unix platform = unix
ifeq ($(shell uname -a),) ifeq ($(shell uname -a),)
@ -51,7 +49,7 @@ ifeq ($(platform), win)
INCFLAGS += -I Windows INCFLAGS += -I Windows
endif endif
CORE_DIR += .. CORE_DIR = ../
TARGET_NAME = sameboy TARGET_NAME = sameboy
LIBM = -lm LIBM = -lm
@ -91,17 +89,57 @@ else ifeq ($(platform), linux-portable)
fpic := -fPIC -nostdlib fpic := -fPIC -nostdlib
SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T
LIBM := LIBM :=
# (armv7 a7, hard point, neon based) ###
# NESC, SNESC, C64 mini
else ifeq ($(platform), classic_armv7_a7)
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC
SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
CFLAGS += -Ofast \
-flto=4 -fwhole-program -fuse-linker-plugin \
-fdata-sections -ffunction-sections -Wl,--gc-sections \
-fno-stack-protector -fno-ident -fomit-frame-pointer \
-falign-functions=1 -falign-jumps=1 -falign-loops=1 \
-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
-fmerge-all-constants -fno-math-errno \
-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
CXXFLAGS += $(CFLAGS)
CPPFLAGS += $(CFLAGS)
ASFLAGS += $(CFLAGS)
HAVE_NEON = 1
ARCH = arm
BUILTIN_GPU = neon
USE_DYNAREC = 1
ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
CFLAGS += -march=armv7-a
else
CFLAGS += -march=armv7ve
# If gcc is 5.0 or later
ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
LDFLAGS += -static-libgcc -static-libstdc++
endif
endif
#######################################
# Nintendo Switch (libtransistor) # Nintendo Switch (libtransistor)
else ifeq ($(platform), switch) else ifeq ($(platform), switch)
TARGET := $(TARGET_NAME)_libretro_$(platform).a TARGET := $(TARGET_NAME)_libretro_$(platform).a
include $(LIBTRANSISTOR_HOME)/libtransistor.mk include $(LIBTRANSISTOR_HOME)/libtransistor.mk
CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls
STATIC_LINKING=1 STATIC_LINKING=1
# Nintendo Switch (libnx)
else ifeq ($(platform), libnx)
include $(DEVKITPRO)/libnx/switch_rules
TARGET := $(TARGET_NAME)_libretro_$(platform).a
DEFINES += -DSWITCH=1 -D__SWITCH__ -DARM
CFLAGS += $(DEFINES) -fPIE -I$(LIBNX)/include/ -ffunction-sections -fdata-sections -ftls-model=local-exec
CFLAGS += -march=armv8-a -mtune=cortex-a57 -mtp=soft -mcpu=cortex-a57+crc+fp+simd -ffast-math
CXXFLAGS := $(ASFLAGS) $(CFLAGS)
STATIC_LINKING = 1
# Nintendo WiiU # Nintendo WiiU
else ifeq ($(platform), wiiu) else ifeq ($(platform), wiiu)
TARGET := $(TARGET_NAME)_libretro_$(platform).a TARGET := $(TARGET_NAME)_libretro_$(platform).a
CC = $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT) CC ?= $(DEVKITPPC)/bin/powerpc-eabi-gcc$(EXE_EXT)
AR = $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT) AR ?= $(DEVKITPPC)/bin/powerpc-eabi-ar$(EXE_EXT)
CFLAGS += -DGEKKO -DHW_RVL -DWIIU -mwup -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST -I$(DEVKITPRO)/libogc/include CFLAGS += -DGEKKO -DHW_RVL -DWIIU -mwup -mcpu=750 -meabi -mhard-float -D__ppc__ -DMSB_FIRST -I$(DEVKITPRO)/libogc/include
CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int CFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int
STATIC_LINKING = 1 STATIC_LINKING = 1
@ -140,7 +178,7 @@ else ifeq ($(platform), emscripten)
fpic := -fPIC fpic := -fPIC
SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined SHARED := -shared -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
else ifeq ($(platform), vita) else ifeq ($(platform), vita)
TARGET := $(TARGET_NAME)_vita.a TARGET := $(TARGET_NAME)_libretro_vita.a
CC = arm-vita-eabi-gcc CC = arm-vita-eabi-gcc
AR = arm-vita-eabi-ar AR = arm-vita-eabi-ar
CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls CFLAGS += -Wl,-q -O3 -fno-short-enums -fno-optimize-sibling-calls
@ -172,14 +210,14 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix)) TargetArchMoniker = $(subst $(WinPartition)_,,$(PlatformSuffix))
CC = cl.exe CC ?= cl.exe
CXX = cl.exe CXX ?= cl.exe
LD = link.exe LD ?= link.exe
reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul))) reg_query = $(call filter_out2,$(subst $2,,$(shell reg query "$2" -v "$1" 2>nul)))
fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1)) fix_path = $(subst $(SPACE),\ ,$(subst \,/,$1))
ProgramFiles86w := $(shell cmd /c "echo %PROGRAMFILES(x86)%") ProgramFiles86w := $(shell cmd //c "echo %PROGRAMFILES(x86)%")
ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)") ProgramFiles86 := $(shell cygpath "$(ProgramFiles86w)")
WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0) WindowsSdkDir ?= $(call reg_query,InstallationFolder,HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0)
@ -242,7 +280,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform)))
LDFLAGS += -DLL LDFLAGS += -DLL
else else
CC = gcc CC ?= gcc
TARGET := $(TARGET_NAME)_libretro.dll TARGET := $(TARGET_NAME)_libretro.dll
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=$(CORE_DIR)/libretro/link.T -Wl,--no-undefined
endif endif
@ -262,6 +300,8 @@ endif
include Makefile.common include Makefile.common
CFLAGS += -DSAMEBOY_CORE_VERSION=\"$(VERSION)\"
OBJECTS := $(patsubst $(CORE_DIR)/%.c,$(CORE_DIR)/build/obj/%_libretro.c.o,$(SOURCES_C)) OBJECTS := $(patsubst $(CORE_DIR)/%.c,$(CORE_DIR)/build/obj/%_libretro.c.o,$(SOURCES_C))
OBJOUT = -o OBJOUT = -o

View File

@ -1,3 +1,5 @@
include $(CORE_DIR)/version.mk
INCFLAGS := -I$(CORE_DIR) INCFLAGS := -I$(CORE_DIR)
SOURCES_C := $(CORE_DIR)/Core/gb.c \ SOURCES_C := $(CORE_DIR)/Core/gb.c \

View File

@ -8,7 +8,7 @@ include $(CORE_DIR)/libretro/Makefile.common
GENERATED_SOURCES := $(filter %_boot.c,$(SOURCES_C)) GENERATED_SOURCES := $(filter %_boot.c,$(SOURCES_C))
COREFLAGS := -DINLINE=inline -D__LIBRETRO__ -DGB_INTERNAL $(INCFLAGS) -DSAMEBOY_CORE_VERSION=\"$(VERSION)\" -Wno-multichar COREFLAGS := -DINLINE=inline -D__LIBRETRO__ -DGB_INTERNAL $(INCFLAGS) -DSAMEBOY_CORE_VERSION=\"$(VERSION)\" -Wno-multichar -DANDROID
GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)" GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
ifneq ($(GIT_VERSION)," unknown") ifneq ($(GIT_VERSION)," unknown")

View File

@ -85,6 +85,8 @@ static retro_audio_sample_t audio_sample_cb;
static retro_input_poll_t input_poll_cb; static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb; static retro_input_state_t input_state_cb;
static bool libretro_supports_bitmasks = false;
static unsigned emulated_devices = 1; static unsigned emulated_devices = 1;
static bool initialized = false; static bool initialized = false;
static unsigned screen_layout = 0; static unsigned screen_layout = 0;
@ -119,24 +121,39 @@ static struct retro_rumble_interface rumble;
static void GB_update_keys_status(GB_gameboy_t *gb, unsigned port) static void GB_update_keys_status(GB_gameboy_t *gb, unsigned port)
{ {
uint16_t joypad_bits = 0;
input_poll_cb(); input_poll_cb();
if (libretro_supports_bitmasks) {
joypad_bits = input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
}
else {
unsigned j;
for (j = 0; j < (RETRO_DEVICE_ID_JOYPAD_R3+1); j++) {
if (input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, j)) {
joypad_bits |= (1 << j);
}
}
}
GB_set_key_state_for_player(gb, GB_KEY_RIGHT, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_RIGHT, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT));
GB_set_key_state_for_player(gb, GB_KEY_LEFT, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_LEFT, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT));
GB_set_key_state_for_player(gb, GB_KEY_UP, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_UP, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_UP));
GB_set_key_state_for_player(gb, GB_KEY_DOWN, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_DOWN, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_DOWN));
GB_set_key_state_for_player(gb, GB_KEY_A, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_A, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_A));
GB_set_key_state_for_player(gb, GB_KEY_B, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_B, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_B));
GB_set_key_state_for_player(gb, GB_KEY_SELECT, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_SELECT, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_SELECT));
GB_set_key_state_for_player(gb, GB_KEY_START, emulated_devices == 1 ? port : 0, GB_set_key_state_for_player(gb, GB_KEY_START, emulated_devices == 1 ? port : 0,
input_state_cb(port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START)); joypad_bits & (1 << RETRO_DEVICE_ID_JOYPAD_START));
} }
@ -207,7 +224,7 @@ static retro_environment_t environ_cb;
static const struct retro_variable vars_single[] = { static const struct retro_variable vars_single[] = {
{ "sameboy_color_correction_mode", "Color correction; emulate hardware|preserve brightness|reduce contrast|off|correct curves" }, { "sameboy_color_correction_mode", "Color correction; emulate hardware|preserve brightness|reduce contrast|off|correct curves" },
{ "sameboy_high_pass_filter_mode", "High-pass filter; accurate|remove dc offset|off" }, { "sameboy_high_pass_filter_mode", "High-pass filter; accurate|remove dc offset|off" },
{ "sameboy_model", "Emulated model; Auto|Game Boy|Game Boy Color|Game Boy Advance|Super Game Boy|Super Game Boy 2" }, { "sameboy_model", "Emulated model (Restart game); Auto|Game Boy|Game Boy Color|Game Boy Advance|Super Game Boy|Super Game Boy 2" },
{ "sameboy_border", "Display border; Super Game Boy only|always|never" }, { "sameboy_border", "Display border; Super Game Boy only|always|never" },
{ "sameboy_rumble", "Enable rumble; rumble-enabled games|all games|never" }, { "sameboy_rumble", "Enable rumble; rumble-enabled games|all games|never" },
{ NULL } { NULL }
@ -219,8 +236,8 @@ static const struct retro_variable vars_dual[] = {
/*{ "sameboy_ir", "Infrared Sensor Emulation; disabled|enabled" },*/ /*{ "sameboy_ir", "Infrared Sensor Emulation; disabled|enabled" },*/
{ "sameboy_screen_layout", "Screen layout; top-down|left-right" }, { "sameboy_screen_layout", "Screen layout; top-down|left-right" },
{ "sameboy_audio_output", "Audio output; Game Boy #1|Game Boy #2" }, { "sameboy_audio_output", "Audio output; Game Boy #1|Game Boy #2" },
{ "sameboy_model_1", "Emulated model for Game Boy #1; Auto|Game Boy|Game Boy Color|Game Boy Advance" }, { "sameboy_model_1", "Emulated model for Game Boy #1 (Restart game); Auto|Game Boy|Game Boy Color|Game Boy Advance" },
{ "sameboy_model_2", "Emulated model for Game Boy #2; Auto|Game Boy|Game Boy Color|Game Boy Advance" }, { "sameboy_model_2", "Emulated model for Game Boy #2 (Restart game); Auto|Game Boy|Game Boy Color|Game Boy Advance" },
{ "sameboy_color_correction_mode_1", "Color correction for Game Boy #1; emulate hardware|preserve brightness|reduce contrast|off|correct curves" }, { "sameboy_color_correction_mode_1", "Color correction for Game Boy #1; emulate hardware|preserve brightness|reduce contrast|off|correct curves" },
{ "sameboy_color_correction_mode_2", "Color correction for Game Boy #2; emulate hardware|preserve brightness|reduce contrast|off|correct curves" }, { "sameboy_color_correction_mode_2", "Color correction for Game Boy #2; emulate hardware|preserve brightness|reduce contrast|off|correct curves" },
{ "sameboy_high_pass_filter_mode_1", "High-pass filter for Game Boy #1; accurate|remove dc offset|off" }, { "sameboy_high_pass_filter_mode_1", "High-pass filter for Game Boy #1; accurate|remove dc offset|off" },
@ -601,11 +618,7 @@ static void check_variables()
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
} }
if (new_model != model[0]) {
geometry_updated = true;
model[0] = new_model; model[0] = new_model;
init_for_current_model(0);
}
} }
var.key = "sameboy_border"; var.key = "sameboy_border";
@ -747,10 +760,7 @@ static void check_variables()
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
} }
if (model[0] != new_model) {
model[0] = new_model; model[0] = new_model;
init_for_current_model(0);
}
} }
var.key = "sameboy_model_2"; var.key = "sameboy_model_2";
@ -776,10 +786,7 @@ static void check_variables()
new_model = MODEL_AUTO; new_model = MODEL_AUTO;
} }
if (model[1] != new_model) {
model[1] = new_model; model[1] = new_model;
init_for_current_model(1);
}
} }
var.key = "sameboy_screen_layout"; var.key = "sameboy_screen_layout";
@ -850,6 +857,10 @@ void retro_init(void)
else { else {
log_cb = fallback_log; log_cb = fallback_log;
} }
if (environ_cb(RETRO_ENVIRONMENT_GET_INPUT_BITMASKS, NULL)) {
libretro_supports_bitmasks = true;
}
} }
void retro_deinit(void) void retro_deinit(void)
@ -858,6 +869,8 @@ void retro_deinit(void)
free(frame_buf_copy); free(frame_buf_copy);
frame_buf = NULL; frame_buf = NULL;
frame_buf_copy = NULL; frame_buf_copy = NULL;
libretro_supports_bitmasks = false;
} }
unsigned retro_api_version(void) unsigned retro_api_version(void)
@ -947,10 +960,14 @@ void retro_set_video_refresh(retro_video_refresh_t cb)
void retro_reset(void) void retro_reset(void)
{ {
check_variables();
for (int i = 0; i < emulated_devices; i++) { for (int i = 0; i < emulated_devices; i++) {
init_for_current_model(i);
GB_reset(&gameboy[i]); GB_reset(&gameboy[i]);
} }
geometry_updated = true;
} }
void retro_run(void) void retro_run(void)

File diff suppressed because it is too large Load Diff

1
version.mk Normal file
View File

@ -0,0 +1 @@
VERSION := 0.13.6