Skip to content

Commit

Permalink
Merge pull request #5 from jdgleaver/dingux-beta
Browse files Browse the repository at this point in the history
Add OpenDingux Beta support
  • Loading branch information
jdgleaver authored Mar 28, 2021
2 parents 2f2ed85 + 2328387 commit b9a993c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
90 changes: 90 additions & 0 deletions source/opendingux/Makefile.rg350_odbeta
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions source/opendingux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
33 changes: 33 additions & 0 deletions source/opendingux/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "common.h"
#include <stdarg.h>

#if defined(DINGUX_BETA)
#include <stdlib.h>
#endif

uint32_t PerGameBootFromBIOS;
uint32_t BootFromBIOS;
uint32_t PerGameShowFPS;
Expand All @@ -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;
Expand All @@ -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 &&
Expand All @@ -58,25 +66,33 @@ void SetIpuAllowDownscaling(bool AllowDownscaling)
fputs(AllowDownscaling ? "1" : "0", allow_downscaling_file);
fclose(allow_downscaling_file);
}
#endif

_IpuAllowDownscalingSet = true;
_IpuAllowDownscaling = 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;
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions source/opendingux/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b9a993c

Please sign in to comment.