-
Notifications
You must be signed in to change notification settings - Fork 609
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
base: master
Are you sure you want to change the base?
Nintendo Switch Port #1067
Changes from all commits
8d25a90
0c28827
f0880ca
a76315e
20b0443
70ce3b4
fe67bf6
0f97468
e9d91a3
b3a69b4
e982aa1
ff61a3b
012a787
b89a85f
e04a4af
001a3e7
c45bbb7
679661f
49d498a
be91737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,8 @@ GPATH | |
GRTAGS | ||
GTAGS | ||
/HTML/ | ||
|
||
# Nintendo Switch binaries | ||
*.nro | ||
*.nacp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ branches: | |
only: | ||
- master | ||
- sdl2-branch | ||
- switch-port | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,11 @@ case "$host" in | |
;; | ||
esac | ||
|
||
dnl - platform, for use with game console ports | ||
AC_ARG_WITH([platform], | ||
AC_HELP_STRING([--with-platform],[build for specific platform]), | ||
[], [with_platform=default]) | ||
|
||
AC_CHECK_TOOL(OBJDUMP, objdump, ) | ||
AC_CHECK_TOOL(STRIP, strip, ) | ||
|
||
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not too crazy about the hard-coded /opt paths. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ EXTRA_DIST= \ | |
README \ | ||
doom.ico \ | ||
doom8.ico \ | ||
doom.jpg \ | ||
6302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file can't be accepted since it contains copyrighted material. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cleaner way to do this is to set an override in
Or alternatively (probably better) use |
||
#else | ||
static int usejoystick = 0; | ||
#endif | ||
|
||
// SDL GUID and index of the joystick to use. | ||
static char *joystick_guid = ""; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -438,7 +496,12 @@ void I_GetEvent(void) | |
I_HandleMouseEvent(&sdlevent); | ||
} | ||
break; | ||
|
||
// Translate some gamepad events to keys to allow menu navigation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -2175,6 +2176,7 @@ static char *GetDefaultConfigDir(void) | |
result = SDL_GetPrefPath("", PACKAGE_TARNAME); | ||
return result; | ||
#endif /* #ifndef _WIN32 */ | ||
#endif /* #ifndef __SWITCH__ */ | ||
return M_StringDuplicate(""); | ||
} | ||
|
||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
// Make the directory if it doesn't already exist: | ||
M_MakeDirectory(configdir); | ||
} | ||
|
||
M_MakeDirectory(configdir); | ||
} | ||
|
||
// | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)