From 232838707b95722a7012413a69e081110d528a55 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Sun, 28 Mar 2021 12:33:42 +0100 Subject: [PATCH] Add OpenDingux Beta support --- source/opendingux/Makefile.rg350_odbeta | 90 +++++++++++++++++++++++++ source/opendingux/main.c | 3 +- source/opendingux/port.c | 33 +++++++++ source/opendingux/port.h | 1 + 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 source/opendingux/Makefile.rg350_odbeta diff --git a/source/opendingux/Makefile.rg350_odbeta b/source/opendingux/Makefile.rg350_odbeta new file mode 100644 index 0000000..fad04fb --- /dev/null +++ b/source/opendingux/Makefile.rg350_odbeta @@ -0,0 +1,90 @@ +RG350=1 +DINGUX_BETA=1 + +TARGET := regba + +TOOLCHAIN_DIR := /opt/gcw0-toolchain/usr/bin +CROSS_COMPILE ?= $(TOOLCHAIN_DIR)/mipsel-gcw0-linux-uclibc- +CC := $(CROSS_COMPILE)gcc +STRIP := $(CROSS_COMPILE)strip +HUGEEDIT := /opt/gcw0-toolchain/bin/hugeedit + +SYSROOT := $(shell $(CC) --print-sysroot) +SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags) +SDL_LIBS := $(shell $(SYSROOT)/usr/bin/sdl-config --libs) + +OBJS := main.o draw.o port.o port-asm.o od-input.o ../video.o \ + ../input.o ../bios.o ../zip.o ../sound.o ../mips/stub.o \ + ../stats.o ../memory.o ../cpu_common.o ../cpu_asm.o od-sound.o \ + ../sha1.o imageio.o ../unifont.o gui.o od-memory.o settings.o \ + cc_lut.o + +HEADERS := cheats.h ../common.h ../cpu_common.h ../cpu.h draw.h main.h \ + ../input.h ../memory.h message.h ../mips/emit.h ../sound.h \ + ../stats.h ../video.h ../zip.h port.h od-sound.h ../sha1.h \ + imageio.h ../unifont.h od-input.h settings.h cc_lut.h + +INCLUDE := -I. -I.. -I../mips +OPTIMIZE = -O2 -mno-mips16 -mplt -mno-shared \ + -fomit-frame-pointer -fno-builtin -fno-common \ + -ffast-math -ftree-vectorize -funswitch-loops \ + -fno-strict-aliasing -fdata-sections -flto + +DEFS := -DGCW_ZERO -DMIPS_XBURST \ + -DSCREEN_WIDTH=320 -DSCREEN_HEIGHT=240 \ + -DGIT_VERSION=$(shell git describe --always) + +ifdef RG350 + DEFS += -DRG350 + DEFS += -DUSE_MMAP +else + DEFS += -DLOAD_ALL_ROM +endif +HAS_MIPS32R2 := $(shell echo | $(CC) -dM -E - |grep _MIPS_ARCH_MIPS32R2) +ifneq ($(HAS_MIPS32R2),) + DEFS += -DMIPS_32R2 + OPTIMIZE += -mips32r2 -mtune=mips32r2 +else + OPTIMIZE += -mips32 -march=mips32 +endif +ifdef DINGUX_BETA + DEFS += -DDINGUX_BETA +endif + +CFLAGS := $(SDL_CFLAGS) -Wall -Wno-unused-variable -Wno-write-strings -Wno-sign-compare \ + -fno-caller-saves \ + $(DEFS) $(INCLUDE) $(OPTIMIZE) +ASFLAGS := $(CFLAGS) -D__ASSEMBLY__ +LDFLAGS := $(CFLAGS) $(SDL_LIBS) -lpthread -lz -lm -lpng -s \ + -zcommon-page-size=2097152 -zmax-page-size=2097152 -lhugetlbfs + +DATA_TO_CLEAN := .opk_data $(TARGET)_rg350_odbeta.opk + +include ../Makefile.rules + +.PHONY: all opk + +all: $(TARGET) + +opk: $(TARGET)_rg350_odbeta.opk + +$(TARGET)_rg350_odbeta.opk: $(TARGET) + $(SUM) " OPK $@" + $(CMD)rm -rf .opk_data + $(CMD)cp -r data .opk_data + $(CMD)cp ../../game_config.txt .opk_data + $(CMD)cp ../../bios/gba_bios.bin .opk_data + $(CMD)cp $< .opk_data/regba.gcw0 + $(CMD)$(HUGEEDIT) --text --data .opk_data/regba.gcw0 + $(CMD)$(STRIP) .opk_data/regba.gcw0 + $(CMD)$(TOOLCHAIN_DIR)/mksquashfs .opk_data $@ -all-root -noappend -no-exports -no-xattrs -no-progress >/dev/null + +# The two below declarations ensure that editing a .c file recompiles only that +# file, but editing a .h file recompiles everything. +# Courtesy of Maarten ter Huurne. + +# Each object file depends on its corresponding source file. +$(C_OBJS): %.o: %.c + +# Object files all depend on all the headers. +$(OBJS): $(HEADERS) diff --git a/source/opendingux/main.c b/source/opendingux/main.c index 794e945..e9653cb 100644 --- a/source/opendingux/main.c +++ b/source/opendingux/main.c @@ -578,8 +578,7 @@ static void quit_common() #if !defined(NO_SCALING) /* It is good manners to leave IPU scaling in * the default state when quitting an application */ - SetIpuKeepAspectRatio(true); - SetIpuFilterType(IPU_FILTER_BICUBIC); + ResetIpu(); #endif } diff --git a/source/opendingux/port.c b/source/opendingux/port.c index f622e85..47df136 100644 --- a/source/opendingux/port.c +++ b/source/opendingux/port.c @@ -20,6 +20,10 @@ #include "common.h" #include +#if defined(DINGUX_BETA) +#include +#endif + uint32_t PerGameBootFromBIOS; uint32_t BootFromBIOS; uint32_t PerGameShowFPS; @@ -37,6 +41,9 @@ uint32_t IpuFilterType; #define DINGUX_SHARPNESS_UPSCALING_FILE "/sys/devices/platform/jz-lcd.0/sharpness_upscaling" #define DINGUX_SHARPNESS_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/sharpness_downscaling" +#define DINGUX_SCALING_MODE_ENVAR "SDL_VIDEO_KMSDRM_SCALING_MODE" +#define DINGUX_SCALING_SHARPNESS_ENVAR "SDL_VIDEO_KMSDRM_SCALING_SHARPNESS" + static bool _IpuAllowDownscalingSet = false; static bool _IpuAllowDownscaling; static bool _IpuKeepAspectRatioSet = false; @@ -46,6 +53,7 @@ static enum ipu_filter_type _IpuFilterType; void SetIpuAllowDownscaling(bool AllowDownscaling) { +#if !defined(DINGUX_BETA) FILE *allow_downscaling_file = NULL; if (_IpuAllowDownscalingSet && @@ -58,6 +66,7 @@ void SetIpuAllowDownscaling(bool AllowDownscaling) fputs(AllowDownscaling ? "1" : "0", allow_downscaling_file); fclose(allow_downscaling_file); } +#endif _IpuAllowDownscalingSet = true; _IpuAllowDownscaling = AllowDownscaling; @@ -65,18 +74,25 @@ void SetIpuAllowDownscaling(bool AllowDownscaling) void SetIpuKeepAspectRatio(bool KeepAspect) { +#if !defined(DINGUX_BETA) FILE *keep_aspect_file = NULL; +#endif if (_IpuKeepAspectRatioSet && (_IpuKeepAspectRatio == KeepAspect)) return; +#if defined(DINGUX_BETA) + setenv(DINGUX_SCALING_MODE_ENVAR, + KeepAspect ? "1" : "0", 1); +#else keep_aspect_file = fopen(DINGUX_KEEP_ASPECT_FILE, "wb"); if (keep_aspect_file) { fputs(KeepAspect ? "1" : "0", keep_aspect_file); fclose(keep_aspect_file); } +#endif _IpuKeepAspectRatioSet = true; _IpuKeepAspectRatio = KeepAspect; @@ -92,8 +108,10 @@ void SetIpuFilterType(enum ipu_filter_type FilterType) * Default bicubic sharpness factor is * (-0.125 * 8) = -1.0 */ const char *sharpness_str = "8"; +#if !defined(DINGUX_BETA) FILE *sharpness_upscaling_file = NULL; FILE *sharpness_downscaling_file = NULL; +#endif if (_IpuFilterTypeSet && (_IpuFilterType == FilterType)) @@ -115,6 +133,9 @@ void SetIpuFilterType(enum ipu_filter_type FilterType) break; } +#if defined(DINGUX_BETA) + setenv(DINGUX_SCALING_SHARPNESS_ENVAR, sharpness_str, 1); +#else /* Set upscaling sharpness */ sharpness_upscaling_file = fopen(DINGUX_SHARPNESS_UPSCALING_FILE, "wb"); if (sharpness_upscaling_file) @@ -130,11 +151,23 @@ void SetIpuFilterType(enum ipu_filter_type FilterType) fputs(sharpness_str, sharpness_downscaling_file); fclose(sharpness_downscaling_file); } +#endif _IpuFilterTypeSet = true; _IpuFilterType = FilterType; } +void ResetIpu(void) +{ +#if defined(DINGUX_BETA) + unsetenv(DINGUX_SCALING_MODE_ENVAR); + unsetenv(DINGUX_SCALING_SHARPNESS_ENVAR); +#else + SetIpuKeepAspectRatio(true); + SetIpuFilterType(IPU_FILTER_BICUBIC); +#endif +} + void ReGBA_Trace(const char* Format, ...) { char* line = malloc(82); diff --git a/source/opendingux/port.h b/source/opendingux/port.h index 4d8476c..bba86bb 100644 --- a/source/opendingux/port.h +++ b/source/opendingux/port.h @@ -135,5 +135,6 @@ extern uint32_t IpuFilterType; extern void SetIpuAllowDownscaling(bool AllowDownscaling); extern void SetIpuKeepAspectRatio(bool KeepAspect); extern void SetIpuFilterType(enum ipu_filter_type FilterType); +extern void ResetIpu(void); #endif