diff --git a/.gitignore b/.gitignore index 352e2da..e551916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.d *.o +build hode hode.ini setup.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c0d0ff1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +project(hode) + +cmake_minimum_required(VERSION 3.0) + +include(FindPkgConfig) + +set(CMAKE_CXX_FLAGS "-g -Wall -pedantic -MMD ${CMAKE_CXX_FLAGS}") +if(VITA) + set(ENV{PKG_CONFIG_PATH} "$ENV{VITASDK}/arm-vita-eabi/lib/pkgconfig") +endif(VITA) + +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_STATIC_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) + +if(VITA) + include("${VITASDK}/share/vita.cmake" REQUIRED) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fpermissive") + vita_create_self(eboot.bin ${CMAKE_PROJECT_NAME} UNSAFE) + vita_create_vpk(${CMAKE_PROJECT_NAME}.vpk "HODEVITA1" eboot.bin + NAME ${CMAKE_PROJECT_NAME} + FILE res/icon0.png sce_sys/icon0.png + FILE res/bg.png sce_sys/livearea/contents/bg.png + FILE res/startup.png sce_sys/livearea/contents/startup.png + FILE res/template.xml sce_sys/livearea/contents/template.xml +) +endif(VITA) diff --git a/game.cpp b/game.cpp index db6eadf..dda556b 100644 --- a/game.cpp +++ b/game.cpp @@ -14,7 +14,11 @@ #include "video.h" // menu settings and player progress +#ifdef __vita__ +static const char *_setupCfg = "ux0:data/hode/setup.cfg"; +#else static const char *_setupCfg = "setup.cfg"; +#endif // starting level cutscene number static const uint8_t _cutscenes[] = { 0, 2, 4, 5, 6, 8, 10, 14, 19 }; @@ -2737,7 +2741,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; diff --git a/intern.h b/intern.h index 7e396c5..5cc136a 100644 --- a/intern.h +++ b/intern.h @@ -12,7 +12,7 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) || defined(__SWITCH__) || defined(__vita__) #define le16toh(x) x #define le32toh(x) x #define htole16(x) x diff --git a/main.cpp b/main.cpp index ec4fc81..62108fb 100644 --- a/main.cpp +++ b/main.cpp @@ -18,9 +18,17 @@ #include "system.h" #include "video.h" +#ifdef __SWITCH__ +#include +#endif + static const char *_title = "Heart of Darkness"; +#ifdef __vita__ +static const char *_configIni = "ux0:data/hode/hode.ini"; +#else static const char *_configIni = "hode.ini"; +#endif static const char *_usage = "hode - Heart of Darkness Interpreter\n" @@ -126,8 +134,17 @@ static int handleConfigIni(void *userdata, const char *section, const char *name } int main(int argc, char *argv[]) { +#ifdef __SWITCH__ + socketInitializeDefault(); + nxlinkStdio(); +#endif +#ifdef __vita__ + const char *dataPath = "ux0:data/hode"; + const char *savePath = "ux0:data/hode"; +#else char *dataPath = 0; char *savePath = 0; +#endif int level = 0; int checkpoint = 0; bool resume = true; @@ -223,7 +240,12 @@ int main(int argc, char *argv[]) { _system->stopAudio(); g->_mix.fini(); delete g; +#ifndef __vita__ free(dataPath); free(savePath); +#endif +#ifdef __SWITCH__ + socketExit(); +#endif return 0; } diff --git a/monsters.cpp b/monsters.cpp index 94ad9f7..e385add 100644 --- a/monsters.cpp +++ b/monsters.cpp @@ -2656,8 +2656,13 @@ int Game::mstUpdateTaskMonsterObject1(Task *t) { if ((m->monsterInfos[946] & 2) == 0) { MstWalkNode *walkPath = m->walkNode; int vf = READ_LE_UINT32(m->monsterInfos + 904); +#ifdef __vita__ + int vb = MAX(m->unk88, walkPath->coords[1][1] + vf); + int va = MIN(m->unk84, walkPath->coords[0][1] - vf); +#else int vb = MAX(m->unk88, walkPath->coords[1][1] + vf); int va = MIN(m->unk84, walkPath->coords[0][1] - vf); +#endif const uint32_t indexUnk36 = walkPath->movingBoundsIndex2; assert(indexUnk36 != kNone); const uint32_t indexUnk49 = _res->_mstMovingBoundsIndexData[indexUnk36].indexUnk49; diff --git a/paf.cpp b/paf.cpp index e5dd2fe..73884b6 100644 --- a/paf.cpp +++ b/paf.cpp @@ -487,7 +487,7 @@ void PafPlayer::mainLoop() { _system->copyRect(0, 0, kVideoWidth, kVideoHeight, _pageBuffers[_currentPageBuffer], kVideoWidth); _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; } diff --git a/res/bg.png b/res/bg.png new file mode 100644 index 0000000..5ec0d9c Binary files /dev/null and b/res/bg.png differ diff --git a/res/icon.jpg b/res/icon.jpg new file mode 100644 index 0000000..7df26d5 Binary files /dev/null and b/res/icon.jpg differ diff --git a/res/icon0.png b/res/icon0.png new file mode 100644 index 0000000..9a758a8 Binary files /dev/null and b/res/icon0.png differ diff --git a/res/startup.png b/res/startup.png new file mode 100644 index 0000000..860d50b Binary files /dev/null and b/res/startup.png differ diff --git a/res/template.xml b/res/template.xml new file mode 100644 index 0000000..160de1b --- /dev/null +++ b/res/template.xml @@ -0,0 +1,10 @@ + + + + + bg.png + + + startup.png + + diff --git a/sound.cpp b/sound.cpp index 6ba1688..bdf1ee0 100644 --- a/sound.cpp +++ b/sound.cpp @@ -844,7 +844,11 @@ SssObject *Game::startSoundObject(int bankIndex, int sampleIndex, uint32_t flags if (sample->framesCount != 0) { SssFilter *filter = &_res->_sssFilters[bank->sssFilter]; +#ifdef __vita__ + const int priority = CLIP(filter->priorityCurrent + sample->initPriority, 0l, 7l); +#else const int priority = CLIP(filter->priorityCurrent + sample->initPriority, 0, 7); +#endif uint32_t flags1 = flags & 0xFFF0F000; flags1 |= ((sampleIndex & 0xF) << 16) | (bankIndex & 0xFFF); SssObject *so = addSoundObject(pcm, priority, flags1, flags); @@ -1054,13 +1058,21 @@ void Game::setSoundObjectPanning(SssObject *so) { int volume = ((so->filter->volumeCurrent >> 16) * so->volume) >> 7; int panning = 0; if (so->panningPtr) { +#ifdef __vita__ + int priority = CLIP(so->priority + so->filter->priorityCurrent, 0l, 7l); +#else int priority = CLIP(so->priority + so->filter->priorityCurrent, 0, 7); +#endif if (so->panning == -2) { volume = 0; panning = kDefaultSoundPanning; priority = 0; } else { +#ifdef __vita__ + panning = CLIP(so->panning, 0l, 128l); +#else panning = CLIP(so->panning, 0, 128); +#endif volume >>= 2; priority /= 2; } @@ -1071,7 +1083,11 @@ void Game::setSoundObjectPanning(SssObject *so) { } } } else { +#ifdef __vita__ + panning = CLIP(so->panning + (so->filter->panningCurrent >> 16), 0l, 128l); +#else panning = CLIP(so->panning + (so->filter->panningCurrent >> 16), 0, 128); +#endif } if (so->pcm == 0) { return; diff --git a/system.h b/system.h index a1fe7c4..5e37a3d 100644 --- a/system.h +++ b/system.h @@ -19,6 +19,7 @@ struct PlayerInput { uint8_t prevMask, mask; + bool escape; bool quit; bool screenshot; diff --git a/system_sdl2.cpp b/system_sdl2.cpp index b7b4e1b..594ed37 100644 --- a/system_sdl2.cpp +++ b/system_sdl2.cpp @@ -551,7 +551,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) {