Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3ds: Support building with SDL 1.2 and 2.x. #406

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion arch/3ds/CONFIG.3DS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh

./config.sh --platform 3ds --enable-release --enable-meter --disable-utils \
--enable-tremor --disable-screenshots --enable-stdio-redirect "$@"
--disable-sdl --enable-tremor --disable-screenshots \
--enable-stdio-redirect "$@"

14 changes: 14 additions & 0 deletions arch/3ds/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ endif

MACHDEP = -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mword-relocations

ifneq (${BUILD_SDL},)
# devkitPro's SDL 1.2 port accidentally defines key_press and key_release as
# global symbols.
ARCH_CFLAGS += -Dkey_press=mzx_key_press -Dkey_release=mzx_key_release
endif

ARCH_CFLAGS += ${EXTRA_INCLUDES} ${MACHDEP} -DARM11 -D__3DS__ -Iarch/3ds
ARCH_CXXFLAGS += ${ARCH_CFLAGS}
ARCH_LDFLAGS += ${EXTRA_LIBS} ${MACHDEP} -specs=3dsx.specs
Expand Down Expand Up @@ -120,7 +126,15 @@ clean:

build := ${build_root}/3ds/megazeux
build: package ${build}
ifeq ($(BUILD_SDL),)
${CP} arch/3ds/pad.config ${build}
else
ifeq ($(BUILD_LIBSDL2),)
${CP} arch/3ds/pad.config.sdl12 ${build}/pad.config
else
${CP} arch/3ds/pad.config.sdl2 ${build}/pad.config
endif
endif
${CP} ${mzxrun}.3dsx ${build}
ifneq (${BUILD_EDITOR},)
${CP} ${mzx}.3dsx ${build}
Expand Down
28 changes: 28 additions & 0 deletions arch/3ds/pad.config.sdl12
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Axis 1/2: Circle pad x/y
# Hat: Directional pad
# Button1: Start
# Button2: A
# Button3: B
# Button4: X
# Button5: Y
# Button6: Left shoulder
# Button7: Right shoulder
# Button8: Select
# Button9: ZL (NOTE: New 3DS only)
# Button10: ZR (NOTE: New 3DS only)

joy1hat = act_up, act_down, act_left, act_right
joy1axis1 = act_l_left, act_l_right
joy1axis2 = act_l_up, act_l_down
joy1button1 = act_start
joy1button2 = act_a
joy1button3 = act_b
joy1button4 = act_x
joy1button5 = act_y
joy1button6 = act_lshoulder
joy1button7 = act_rshoulder
joy1button8 = act_select
joy1button9 = act_ltrigger
joy1button10 = act_rtrigger
joy1.axis_lx = 1
joy1.axis_ly = 2
34 changes: 34 additions & 0 deletions arch/3ds/pad.config.sdl2
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Axis 1/2: Circle pad x/y
# Button1: A
# Button2: B
# Button3: Select
# Button4: Start
# Button5: Right
# Button6: Left
# Button7: Up
# Button8: Down
# Button9: Right shoulder
# Button10: Left shoulder
# Button11: X
# Button12: Y
# Button15: ZL (NOTE: New 3DS only)
# Button16: ZR (NOTE: New 3DS only)

joy1axis1 = act_l_left, act_l_right
joy1axis2 = act_l_up, act_l_down
joy1button1 = act_a
joy1button2 = act_b
joy1button3 = act_select
joy1button4 = act_start
joy1button5 = act_right
joy1button6 = act_left
joy1button7 = act_up
joy1button8 = act_down
joy1button9 = act_rshoulder
joy1button10 = act_lshoulder
joy1button11 = act_x
joy1button12 = act_y
joy1button15 = act_ltrigger
joy1button16 = act_rtrigger
joy1.axis_lx = 1
joy1.axis_ly = 2
24 changes: 22 additions & 2 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,7 @@ echo "LICENSEDIR=$LICENSEDIR" >> platform.inc
#
# Platform-specific libraries, or SDL?
#
if [ "$PLATFORM" = "3ds" ] ||
[ "$PLATFORM" = "nds" ] ||
if [ "$PLATFORM" = "nds" ] ||
[ "$PLATFORM" = "nds-blocksds" ] ||
[ "$PLATFORM" = "djgpp" ] ||
[ "$PLATFORM" = "dreamcast" ] ||
Expand Down Expand Up @@ -877,6 +876,18 @@ if [ "$PLATFORM" = "3ds" ]; then
IPV6="false"
fi

#
# If the 3DS arch is enabled and SDL 1.2 is used, softscale is not
# available. On SDL 2.0, due to the rendering pipeline not supporting
# hardware acceleration as of writing, it is available, but with
# unsatisfactory performance. As a workaround, use the GP2X
# 320x240 renderer.
#
if [ "$PLATFORM" = "3ds" ] && [ "$SDL" = "true" ]; then
echo "Force-enabling GP2X 320x240 renderer (SDL on 3DS)."
GP2X="true"
fi

#
# If the Wii arch is enabled, some code has to be compile time
# enabled too.
Expand Down Expand Up @@ -1501,6 +1512,15 @@ if [ "$PLATFORM" = "wii" ] && [ "$SDL" = "false" ]; then
echo "BUILD_RENDER_GX=1" >> platform.inc
fi

#
# CTR renderer (3DS)
#
if [ "$PLATFORM" = "3ds" ] && [ "$SDL" = "false" ]; then
echo "Building custom CTR renderer."
echo "#define CONFIG_RENDER_CTR" >> src/config.h
echo "BUILD_RENDER_CTR=1" >> platform.inc
fi

#
# GP2X renderer
#
Expand Down
4 changes: 2 additions & 2 deletions docs/platform_matrix.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
var no_low_memory = subopt("NO", 5);
var no_updater = subopt("NO", 6);
var no_updater_unix = subopt("NO", 7);
var no_sdl_3ds = std("NO", 8);
var optional_sdl_3ds = std("NO / SDL 1.2 / SDL 2", 8);
var optional_sdl_wii = std("NO / SDL 1.2", 9);
var yes_but_8bpp = subopt("YES (8bpp)", 10);
var no_gl_switch = subopt("NO", 11);
Expand Down Expand Up @@ -168,7 +168,7 @@
adlib_engine: rad,
ogg_vorbis: tremor,
optimization: speed,
sdl: no_sdl_3ds,
sdl: optional_sdl_3ds,
editor: yes,
helpsys: yes,
audio: yes,
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ endif
endif

ifeq (${BUILD_3DS},1)
# SDL and platform_sdl.c takes care of all of this when enabled.
ifeq (${BUILD_SDL},)
core_cobjs += arch/3ds/shader_2d.shbin.o arch/3ds/shader_playfield.shbin.o
core_cobjs += arch/3ds/platform.o arch/3ds/render.o
core_cobjs += arch/3ds/event.o arch/3ds/audio.o
core_cobjs += arch/3ds/keyboard.o
endif
endif

ifeq (${BUILD_WII},1)
# SDL and platform_sdl.c takes care of all of this when enabled.
Expand Down
6 changes: 6 additions & 0 deletions src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
#endif

#ifdef CONFIG_3DS
#ifdef CONFIG_SDL
#define VIDEO_OUTPUT_DEFAULT "gp2x"
#define FULLSCREEN_WIDTH_DEFAULT 400
#define FULLSCREEN_HEIGHT_DEFAULT 240
#define FORCE_BPP_DEFAULT 16
#endif
#define VIDEO_RATIO_DEFAULT RATIO_CLASSIC_4_3
#define VFS_ENABLE_DEFAULT true
#define VFS_MAX_CACHE_SIZE_DEFAULT (1 << 25) /* 32 MiB */
Expand Down
7 changes: 4 additions & 3 deletions src/event_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,10 +1650,11 @@ void __warp_mouse(int x, int y)

void initialize_joysticks(void)
{
#if !SDL_VERSION_ATLEAST(2,0,0) || defined(CONFIG_SWITCH) || defined(CONFIG_PSVITA)
#if !SDL_VERSION_ATLEAST(2,0,0) || defined(CONFIG_SWITCH) || defined(CONFIG_PSVITA) \
|| defined(CONFIG_3DS)
// SDL 1.2 doesn't have joystick added/removed events.
// Switch SDL doesn't seem to generate these events at all on startup. The vita
// appears to have the same issue.
// Switch SDL doesn't seem to generate these events at all on startup. The Vita
// and 3DS appear to have the same issue.
int i, count;

count = SDL_NumJoysticks();
Expand Down
2 changes: 2 additions & 0 deletions src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ static const struct renderer_data renderers[] =
{ "nds", render_nds_register },
#endif
#if defined(CONFIG_3DS)
#if defined(CONFIG_RENDER_CTR)
{ "3ds", render_ctr_register },
#endif
#endif
#if defined(CONFIG_WII)
#if defined(CONFIG_RENDER_GX)
{ "gx", render_gx_register },
Expand Down