Skip to content

Commit

Permalink
Add Nintendo Switch support
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed Nov 4, 2019
1 parent 4e950f4 commit e52751b
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.d
*.o
build
hode
hode.ini
setup.cfg
68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
project(hode)

cmake_minimum_required(VERSION 3.0)

include(FindPkgConfig)

set(CMAKE_CXX_FLAGS "-g -Wall -pedantic -MMD ${CMAKE_CXX_FLAGS}")

pkg_check_modules(SDL2 sdl2 REQUIRED)

include_directories(
${SDL2_INCLUDE_DIRS}
)

add_executable(${CMAKE_PROJECT_NAME}
andy.cpp
benchmark.cpp
fileio.cpp
fs_posix.cpp
game.cpp
level1_rock.cpp
level2_fort.cpp
level3_pwr1.cpp
level4_isld.cpp
level5_lava.cpp
level6_pwr2.cpp
level7_lar1.cpp
level8_lar2.cpp
level9_dark.cpp
lzw.cpp
main.cpp
menu.cpp
mixer.cpp
monsters.cpp
paf.cpp
random.cpp
resource.cpp
screenshot.cpp
sound.cpp
staticres.cpp
system_sdl2.cpp
util.cpp
video.cpp
scaler_nearest.cpp
scaler_xbr.cpp
3p/inih/ini.c
3p/libxbr-standalone/xbr.c
)

target_link_libraries(${CMAKE_PROJECT_NAME}
${SDL2_LIBRARIES}
)

if(SWITCH_LIBNX)
set(CMAKE_C_FLAGS "-O2 -ffunction-sections -fdata-sections -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -ftls-model=local-exec")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
include_directories($ENV{DEVKITPRO}/libnx/include)
add_definitions(-D__SWITCH__)
add_custom_target(${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}
COMMAND nacptool --create "Heart of Darkness" "cyx, usineur" "0.2.0" ${CMAKE_PROJECT_NAME}.nacp
COMMAND elf2nro ${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/res/icon.jpg --nacp=${CMAKE_PROJECT_NAME}.nacp
)
add_custom_target(nxlink
COMMAND nxlink -a $(SWITCHIP) ${CMAKE_PROJECT_NAME}.nro -s -p ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.nro
DEPENDS ${CMAKE_PROJECT_NAME}.nro
)
endif(SWITCH_LIBNX)
2 changes: 1 addition & 1 deletion game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ void Game::levelMainLoop() {
}
_rnd.update();
_system->processEvents();
if (_system->inp.keyPressed(SYS_INP_ESC)) { // display exit confirmation screen
if (_system->inp.keyPressed(SYS_INP_ESC) || _system->inp.escape) { // display exit confirmation screen
if (displayHintScreen(-1, 0)) {
_system->inp.quit = true;
return;
Expand Down
2 changes: 1 addition & 1 deletion intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdlib.h>
#include <assert.h>

#ifdef _WIN32
#if defined(_WIN32) || defined(__SWITCH__)
#define le16toh(x) x
#define le32toh(x) x
#define htole16(x) x
Expand Down
11 changes: 11 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "system.h"
#include "video.h"

#ifdef __SWITCH__
#include <switch.h>
#endif

static const char *_title = "Heart of Darkness";

static const char *_configIni = "hode.ini";
Expand Down Expand Up @@ -120,6 +124,10 @@ static int handleConfigIni(void *userdata, const char *section, const char *name
}

int main(int argc, char *argv[]) {
#ifdef __SWITCH__
socketInitializeDefault();
nxlinkStdio();
#endif
char *dataPath = 0;
int level = 0;
int checkpoint = 0;
Expand Down Expand Up @@ -213,5 +221,8 @@ int main(int argc, char *argv[]) {
g->_mix.fini();
delete g;
free(dataPath);
#ifdef __SWITCH__
socketExit();
#endif
return 0;
}
2 changes: 1 addition & 1 deletion paf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void PafPlayer::mainLoop() {
_system->copyRect(0, 0, kVideoWidth, kVideoHeight, _pageBuffers[_currentPageBuffer], 256);
_system->updateScreen(false);
_system->processEvents();
if (_system->inp.quit || _system->inp.keyPressed(SYS_INP_ESC)) {
if (_system->inp.quit || _system->inp.keyPressed(SYS_INP_ESC) || _system->inp.escape) {
break;
}

Expand Down
Binary file added res/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions system.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

struct PlayerInput {
uint8_t prevMask, mask;
bool escape;
bool quit;
bool screenshot;

Expand Down
2 changes: 1 addition & 1 deletion system_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void System_SDL2::processEvents() {
break;
case SDL_CONTROLLER_BUTTON_BACK:
case SDL_CONTROLLER_BUTTON_START:
inp.quit = pressed;
inp.escape = pressed;
break;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
if (pressed) {
Expand Down

0 comments on commit e52751b

Please sign in to comment.