8000 Nintendo Switch Port by WinterMute · Pull Request #1067 · chocolate-doom/chocolate-doom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Nintendo Switch Port #1067

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ GPATH
GRTAGS
GTAGS
/HTML/

# Nintendo Switch binaries
*.nro
*.nacp

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ branches:
only:
- master
- sdl2-branch
- switch-port

14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ case "$host" in
;;
esac

dnl - platform, for use with game console ports
AC_ARG_WITH([platform],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this just duplicates what the --host argument does:

https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Specifying-Target-Triplets.html

I expect devkitpro probably defines a triplet for the Switch that you can use (although I don't know a lot about it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't build Switch specific tools, we're using a standard aarch64-none-elf triplet & using the same tools for a few baremetal (newlib based) targets we're playing with. Adding this option would let us build, for instance, chocolate doom for bare metal Rpi3 if anyone felt like it ;o)

AC_HELP_STRING([--with-platform],[build for specific platform]),
[], [with_platform=default])

AC_CHECK_TOOL(OBJDUMP, objdump, )
AC_CHECK_TOOL(STRIP, strip, )

Expand All @@ -111,9 +116,18 @@ AS_IF([test "x$enable_werror" = "xyes"], [
CFLAGS="$CFLAGS -Werror"
])

AS_IF([test "x$with_platform" = "xswitch"], [
CFLAGS="-fPIC -march=armv8-a -mtune=cortex-a57 -mtp=soft -ftls-model=local-exec $CFLAGS"
CPPFLAGS="-D__SWITCH__ $CPPFLAGS -isystem /opt/devkitpro/libnx/include"
LIBS="$LIBS -L/opt/devkitpro/libnx/lib -lnx -lm"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too crazy about the hard-coded /opt paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using pacman for the devkitPro toolchains & distributing a bunch of precompiled libraries which kind of necessitates hard coded paths unfortunately. I can use ${DEVKITPRO} here maybe - I'll have a think & see if I can come up with something that seems less hacky.

LDFLAGS="-fPIE -specs=/opt/devkitpro/libnx/switch.specs"
])

AM_CONDITIONAL(HAVE_WINDRES, test "$WINDRES" != "")
AM_CONDITIONAL(HAVE_PYTHON, $HAVE_PYTHON)

AM_CONDITIONAL(BUILD_SWITCH, [test "$with_platform" = "switch"])

dnl Automake v1.8.0 is required, please upgrade!

AM_INIT_AUTOMAKE([1.8.0 foreign])
Expand Down
1 change: 1 addition & 0 deletions data/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ EXTRA_DIST= \
README \
doom.ico \
doom8.ico \
doom.jpg \
Copy link
Member
6302

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can't be accepted since it contains copyrighted material.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I'll ask around and see if we can get some original artwork for the Switch icons.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chocolate Doom logo?

This somewhat comes back to my question in the main reply. It's certainly worth upstreaming some of the more general portability fixes, but maybe the Switch stuff belongs more naturally in a fork.

doom.png \
setup.ico \
setup8.ico \
Expand Down
Binary file added data/doom.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion opl/examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ AM_CFLAGS = -I$(top_srcdir)/opl

noinst_PROGRAMS=droplay

droplay_LDADD = ../libopl.a @LDFLAGS@ @SDL_LIBS@ @SDLMIXER_LIBS@
droplay_LDADD = ../libopl.a @SDL_LIBS@ @SDLMIXER_LIBS@
droplay_SOURCES = droplay.c

41 changes: 37 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ execgames_PROGRAMS = @PROGRAM_PREFIX@doom \
@PROGRAM_PREFIX@strife \
@PROGRAM_PREFIX@server

if BUILD_SWITCH

else

noinst_PROGRAMS = @PROGRAM_PREFIX@setup

SETUP_BINARIES = @PROGRAM_PREFIX@doom-setup$(EXEEXT) \
@PROGRAM_PREFIX@heretic-setup$(EXEEXT) \
@PROGRAM_PREFIX@hexen-setup$(EXEEXT) \
@PROGRAM_PREFIX@strife-setup$(EXEEXT)

execgames_SCRIPTS = $(SETUP_BINARIES)

endif

AM_CFLAGS = -I$(top_srcdir)/textscreen \
-I$(top_srcdir)/opl \
-I$(top_srcdir)/pcsound \
Expand Down Expand Up @@ -48,7 +53,7 @@ net_structrw.c net_structrw.h \
z_native.c z_zone.h

@PROGRAM_PREFIX@server_SOURCES=$(COMMON_SOURCE_FILES) $(DEDSERV_FILES)
@PROGRAM_PREFIX@server_LDADD = @LDFLAGS@ @SDLNET_LIBS@
@PROGRAM_PREFIX@server_LDADD = @SDLNET_LIBS@

# Source files used by the game binaries (chocolate-doom, etc.)

Expand Down Expand Up @@ -128,10 +133,11 @@ EXTRA_LIBS = \
$(top_builddir)/textscreen/libtextscreen.a \
$(top_builddir)/pcsound/libpcsound.a \
$(top_builddir)/opl/libopl.a \
@LDFLAGS@ \
@PNG_LIBS@ \
@SDL_LIBS@ \
@SDLMIXER_LIBS@ \
@SDLNET_LIBS@
@SDLNET_LIBS@ \
@SAMPLERATE_LIBS@

if HAVE_WINDRES
@PROGRAM_PREFIX@doom_SOURCES=$(SOURCE_FILES_WITH_DEH) resource.rc
Expand Down Expand Up @@ -198,6 +204,9 @@ net_query.c net_query.h \
net_structrw.c net_structrw.h \
z_native.c z_zone.h

if BUILD_SWITCH

else
if HAVE_WINDRES
@PROGRAM_PREFIX@setup_SOURCES=$(SETUP_FILES) $(COMMON_SOURCE_FILES) setup-res.rc
else
Expand All @@ -206,6 +215,7 @@ endif
@PROGRAM_PREFIX@setup_LDADD = setup/libsetup.a \
$(top_builddir)/textscreen/libtextscreen.a \
@LDFLAGS@ @SDL_LIBS@ @SDLMIXER_LIBS@ @SDLNET_LIBS@
endif

EXTRA_DIST = \
CMakeLists.txt \
Expand Down Expand Up @@ -279,3 +289,26 @@ mus2mid : $(MUS2MID_SRC_FILES)
$(CC) -DSTANDALONE -I$(top_builddir) $(CFLAGS) @LDFLAGS@ \
$(MUS2MID_SRC_FILES) -o $@

if BUILD_SWITCH
all-local: @PROGRAM_PREFIX@doom.nro \
@PROGRAM_PREFIX@heretic.nro \
@PROGRAM_PREFIX@hexen.nro \
@PROGRAM_PREFIX@strife.nro

@PROGRAM_PREFIX@doom.nro: @PROGRAM_PREFIX@doom @PROGRAM_PREFIX@doom.nacp
elf2nro @PROGRAM_PREFIX@doom $@ --nacp=@PROGRAM_PREFIX@doom.nacp --icon=$(top_srcdir)/data/doom.jpg

@PROGRAM_PREFIX@heretic.nro: @PROGRAM_PREFIX@heretic @PROGRAM_PREFIX@heretic.nacp
elf2nro @PROGRAM_PREFIX@heretic $@ --nacp=@PROGRAM_PREFIX@heretic.nacp

@PROGRAM_PREFIX@hexen.nro: @PROGRAM_PREFIX@hexen @PROGRAM_PREFIX@hexen.nacp
elf2nro @PROGRAM_PREFIX@hexen $@ --nacp=@PROGRAM_PREFIX@hexen.nacp

@PROGRAM_PREFIX@strife.nro: @PROGRAM_PREFIX@strife @PROGRAM_PREFIX@strife.nacp
elf2nro @PROGRAM_PREFIX@strife $@ --nacp=@PROGRAM_PREFIX@strife.nacp

%.nacp: $(MAKEFILE_LIST)
nacptool --create "$*" "SwitchBrew Team" "$(VERSION)" $@


endif
6 changes: 5 additions & 1 deletion src/i_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ static SDL_Joystick *joystick = NULL;
// Configuration variables:

// Standard default.cfg Joystick enable/disable

// always enable on Switch
#ifdef __SWITCH__
static int usejoystick = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleaner way to do this is to set an override in I_BindJoystickVariables(), eg.

#ifdef __SWITCH__
    usejoystick = 1;
#endif

Or alternatively (probably better) use SDL_GetPlatform() instead.

#else
static int usejoystick = 0;
#endif

// SDL GUID and index of the joystick to use.
static char *joystick_guid = "";
Expand Down
67 changes: 65 additions & 2 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,67 @@ static void I_ToggleFullScreen(void)
}
}

extern void I_HandleKeyboardEvent(SDL_Event *sdlevent);

struct EventMap {
int button;
SDL_Keycode sym;
SDL_Scancode scan;
};

void sendKeypress(SDL_Event *ev, int sym, int scancode) {
SDL_Event ev_new;
memset(&ev_new, 0, sizeof(SDL_Event));
ev_new.key.keysym.sym = sym;
ev_new.key.keysym.scancode = scancode;
if (ev->type == SDL_JOYBUTTONDOWN) {
ev_new.type = ev_new.key.type = SDL_KEYDOWN;
ev_new.key.state = SDL_PRESSED;
} else if (ev->type == SDL_JOYBUTTONUP) {
ev_new.type = ev_new.key.type = SDL_KEYUP;
ev_new.key.state = SDL_RELEASED;
}

I_HandleKeyboardEvent(&ev_new);
}

void TranslateEvent(SDL_Event *ev, const struct EventMap *btnmap, int btnmaps) {

int i;

for (i=0; i<btnmaps; i++ ) {
if (btnmap[i].button == ev->jbutton.button ) break;
}

if (i != btnmaps) {
sendKeypress(ev,btnmap[i].sym, btnmap[i].scan);
}
}

extern boolean askforquit __attribute__((weak));
extern int messageToPrint __attribute__((weak));

static void TranslateJoystickEvent(SDL_Event *ev) {
static const struct EventMap menu_btnmap[] = {
{ 0, SDLK_RETURN, SDL_SCANCODE_RETURN }, // A Button
{ 13, SDLK_UP, SDL_SCANCODE_UP }, // Up
{ 15, SDLK_DOWN, SDL_SCANCODE_DOWN }, // Down
{ 12, SDLK_LEFT, SDL_SCANCODE_LEFT }, // Left
{ 14, SDLK_RIGHT, SDL_SCANCODE_RIGHT }, // Right
{ 11, SDLK_ESCAPE, SDL_SCANCODE_ESCAPE }, // -
{ 1, SDLK_BACKSPACE, SDL_SCANCODE_BACKSPACE }, // B
};

if ( (&askforquit && askforquit) || (&messageToPrint && messageToPrint)) {
int btn = ev->jbutton.button;
if (btn == 3) sendKeypress(ev, SDLK_y, SDL_SCANCODE_Y);
if (btn == 1) sendKeypress(ev, SDLK_n, SDL_SCANCODE_N);
}
TranslateEvent(ev, menu_btnmap, sizeof(menu_btnmap)/sizeof(menu_btnmap[0]));
}

void I_GetEvent(void)
{
extern void I_HandleKeyboardEvent(SDL_Event *sdlevent);
extern void I_HandleMouseEvent(SDL_Event *sdlevent);
SDL_Event sdlevent;

Expand Down Expand Up @@ -438,7 +496,12 @@ void I_GetEvent(void)
I_HandleMouseEvent(&sdlevent);
}
break;

// Translate some gamepad events to keys to allow menu navigation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems very hacky. I'd rather see the code in m_menu.c extended to support joystick navigation. Indeed, this has already been done somewhat - see #890 and #893 for some prior art.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my mental todo list is port that prior work to heretic,Hexen&strife

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I should add @WinterMute I'd be very interested to know what is missing from the existing gamepad-menu support from your perspective

// in games that don't support joystick menu controls (Heretic, Hexen)
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
TranslateJoystickEvent(&sdlevent);
break;
case SDL_QUIT:
if (screensaver_mode)
{
Expand Down
8 changes: 5 additions & 3 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,7 @@ float M_GetFloatVariable(const char *name)

static char *GetDefaultConfigDir(void)
{
#ifndef __SWITCH__
#if !defined(_WIN32) || defined(_WIN32_WCE)

// Configuration settings are stored in an OS-appropriate path
Expand All @@ -2175,6 +2176,7 @@ static char *GetDefaultConfigDir(void)
result = SDL_GetPrefPath("", PACKAGE_TARNAME);
return result;
#endif /* #ifndef _WIN32 */
#endif /* #ifndef __SWITCH__ */
return M_StringDuplicate("");
}

Expand All @@ -2201,11 +2203,11 @@ void M_SetConfigDir(const char *dir)
if (strcmp(configdir, "") != 0)
{
printf("Using %s for configuration and saves\n", configdir);
}
// Make the directory if it doesn't already exist:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdir with "" as path crashes on Switch atm. This seems like it might possibly be UB elsewhere too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think I misread this last night when I was reviewing. I guess it shouldn't ever make sense to mkdir("") anyway, so this should be fine.


// Make the directory if it doesn't already exist:
M_MakeDirectory(configdir);
}

M_MakeDirectory(configdir);
}

//
Expand Down
2 changes: 2 additions & 0 deletions src/m_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ char *M_TempFile(const char *s)
{
tempdir = ".";
}
#elif defined(__SWITCH__)
tempdir = ".";
#else
// In Unix, just use /tmp.

Expand Down
7 changes: 6 additions & 1 deletion textscreen/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ CTAGS_ARGS=-I TXT_UNCAST_ARG+

# build this directory before the examples directory.

SUBDIRS = fonts . examples
SUBDIRS = fonts .

if BUILD_SWITCH
else
SUBDIRS += examples
endif

noinst_LIBRARIES=libtextscreen.a

Expand Down
0