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

PSP port #1918

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61aebc1
Initial PSP port. Includes the pipeline to build
stefanmielke May 9, 2021
bffa425
Using SDL_Main instead; removed custom definition from psp_defs.cmake…
stefanmielke May 9, 2021
949afbf
fix need to alter psptoolchain's SDL_config.h to compile
stefanmielke May 9, 2021
cd4c65c
adding psp to circleci config
stefanmielke May 9, 2021
aa76765
forcing only PSP for now
stefanmielke May 9, 2021
5c445ae
setting build.sh to be run from root folder
stefanmielke May 9, 2021
24ad192
fixing circleci build for psp
stefanmielke May 9, 2021
f49b551
adding back other circleci jobs
stefanmielke May 9, 2021
5f5321a
fix config.yml indentation
stefanmielke May 9, 2021
58e5b18
changes made to boot the game, up until showing the intro or menu if …
stefanmielke May 9, 2021
392d8da
Reducing resolution, adding back streaming music and sounds (still di…
stefanmielke May 10, 2021
703d7c1
Using sprintf to replace snprintf (and removed custom implementation)…
stefanmielke May 10, 2021
87a6641
Rollback of changes in SFileOpenArchive.cpp
stefanmielke May 10, 2021
751197e
Rollback of changes in init.cpp
stefanmielke May 10, 2021
79ddbff
Rollback of changes in FileStream.cpp
stefanmielke May 10, 2021
c04de03
Rollback of more changes in SFileOpenArchive.cpp
stefanmielke May 10, 2021
d762a2b
Rollback of more style changes
stefanmielke May 10, 2021
3cef15a
Putting back SetApplicationVersions()
stefanmielke May 10, 2021
0192517
fix icon and background; set base path as ms0:/PSP/GAME/DevilutionX/;…
stefanmielke May 13, 2021
94e3168
Merge branch 'master' into psp
stefanmielke May 13, 2021
633e459
Merge branch 'master' into psp
stefanmielke May 13, 2021
0794731
adding back miniwin.h to fix SDL_snprintf redirect for PSP
stefanmielke May 13, 2021
76437aa
Removed workarounds on CMakeLists.txt
stefanmielke May 14, 2021
ce11c9e
Merge branch 'master' into psp
stefanmielke May 14, 2021
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
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ jobs:
- run: cmake -S. -Bbuild -GNinja -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DNIGHTLY_BUILD=ON
- run: cmake --build build -j 2
- store_artifacts: {path: ./build/devilutionx.vpk, destination: devilutionx.vpk}
psp:
docker:
- image: sharkwouter/pspdev
working_directory: ~/repo
steps:
- checkout
- run: sh Packaging/psp/build.sh
- store_artifacts: {path: ./EBOOT.PBP, destination: EBOOT.PBP}

workflows:
version: 2
Expand All @@ -96,3 +104,4 @@ workflows:
- 3ds
- amigaos-m68k
- vita
- psp
7 changes: 7 additions & 0 deletions 3rdParty/StormLib/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
// Local functions - platform-specific functions

#ifndef STORMLIB_WINDOWS

#ifdef __PSP__
static DWORD nLastError = ERROR_SUCCESS;
#else
static thread_local DWORD nLastError = ERROR_SUCCESS;
#endif

DWORD GetLastError()
{
Expand Down Expand Up @@ -366,11 +371,13 @@ static bool BaseFile_Resize(TFileStream * pStream, ULONGLONG NewFileSize)

#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX)
{
#ifndef __PSP__
if(ftruncate64((intptr_t)pStream->Base.File.hFile, (off64_t)NewFileSize) == -1)
{
nLastError = errno;
return false;
}
#endif

pStream->Base.File.FileSize = NewFileSize;
return true;
Expand Down
28 changes: 27 additions & 1 deletion 3rdParty/StormLib/src/StormPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@

#endif

//-----------------------------------------------------------------------------
// Defines for PSP platform

#if !defined(STORMLIB_PLATFORM_DEFINED) && defined(__PSP__)
Copy link
Collaborator

@glebm glebm May 10, 2021

Choose a reason for hiding this comment

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

Is this needed? These look like the defaults for an unknown platform


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>

#define STORMLIB_LITTLE_ENDIAN

#define STORMLIB_MAC
#define STORMLIB_PLATFORM_DEFINED

#endif

//-----------------------------------------------------------------------------
// Defines for Vita platform

Expand Down Expand Up @@ -364,7 +390,7 @@
#endif

// Platform-specific error codes for UNIX-based platforms
#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX)
#if defined(STORMLIB_MAC) || defined(STORMLIB_LINUX) || defined(__PSP__)
#define ERROR_SUCCESS 0
#define ERROR_FILE_NOT_FOUND ENOENT
#define ERROR_ACCESS_DENIED EPERM
Expand Down
27 changes: 27 additions & 0 deletions CMake/psp_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#General compilation options
set(NONET ON)
set(USE_SDL1 ON)
set(NOSOUND ON)

#Force scaling, for now..
# set(SDL1_VIDEO_MODE_FLAGS SDL_FULLSCREEN)
set(SDL1_VIDEO_MODE_BPP 8)
set(DEFAULT_WIDTH 480)
set(DEFAULT_HEIGHT 272)

#SDL Joystick axis mapping (analog)
set(JOY_AXIS_LEFTX 0)
set(JOY_AXIS_LEFTY 1)
#SDL Joystick button mapping
set(JOY_BUTTON_B 1)
set(JOY_BUTTON_A 2)
set(JOY_BUTTON_X 3)
set(JOY_BUTTON_Y 0)
set(JOY_BUTTON_LEFTSHOULDER 4)
set(JOY_BUTTON_RIGHTSHOULDER 5)
set(JOY_BUTTON_BACK 10)
set(JOY_BUTTON_START 11)
set(JOY_BUTTON_DPAD_UP 8)
set(JOY_BUTTON_DPAD_DOWN 6)
set(JOY_BUTTON_DPAD_LEFT 7)
set(JOY_BUTTON_DPAD_RIGHT 9)
41 changes: 39 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ if(SWITCH)
include(switch_defs)
endif()

if(PSP)
set(ASAN OFF)
set(UBSAN OFF)

include(psp_defs)
endif()

if(VITA)
# Work around a missing setting in the toolchain file.
# Fix sent upstream: https://github.com/vitasdk/vita-toolchain/pull/182
Expand Down Expand Up @@ -559,7 +566,7 @@ target_include_directories(${BIN_TARGET} PRIVATE
Source
${CMAKE_CURRENT_BINARY_DIR})

if(NOT N3DS)
if(NOT N3DS AND NOT PSP)
target_link_libraries(${BIN_TARGET} PUBLIC
Threads::Threads)
endif()
Expand Down Expand Up @@ -724,13 +731,24 @@ if(N3DS)
target_link_libraries(${BIN_TARGET} PRIVATE 3ds::citro3d 3ds::ctrulib)
endif()

if(PSP)
target_link_libraries(${BIN_TARGET} PRIVATE
-L${PSPDEV}/psp/lib -lg -lc -lz -lm -lGL -lvorbisidec -lmikmod -lpspvfpu -lfreetype
-L${PSPDEV}/psp/sdk/lib -lstdc++ -L${PSPDEV}/psp
-lpspdebug -lpspgu -lpspctrl -lpspge -lpspirkeyb -lpsppower -lpsppower_driver -lpspdisplay -lpsphprm -lpspsdk -lpsprtc
-lpspaudio -lpsputility -lpspnet_inet -lc -lpspuser)

target_link_options(${BIN_TARGET} PUBLIC -D_PSP_FW_VERSION=500)
target_compile_definitions(${BIN_TARGET} PRIVATE -Dmain=SDL_main -DPSP_LARGE_MEMORY=1)
endif()

target_compile_definitions(${BIN_TARGET} PRIVATE ${def_list})

if (GPERF)
target_link_libraries(${BIN_TARGET} PRIVATE ${GPERFTOOLS_LIBRARIES})
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT GPERF AND NOT HAIKU AND NOT VITA)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT GPERF AND NOT HAIKU AND NOT VITA AND NOT PSP)
target_link_libraries(${BIN_TARGET} PUBLIC "$<$<NOT:$<CONFIG:Debug>>:-static-libgcc;-static-libstdc++>")
endif()

Expand Down Expand Up @@ -858,6 +876,25 @@ if(N3DS)
add_cia_target(${BIN_TARGET} ${APP_RSF} ${APP_BANNER} ${APP_AUDIO} ${APP_ROMFS})
endif()

if(PSP)
set(EXTRA_TARGETS "EBOOT.PBP")
set(PSP_EBOOT_TITLE "DevilutionX")
set(PSP_LARGE_MEMORY 1)

if(BINARY_RELEASE)
set_target_properties(${BIN_TARGET} PROPERTIES COMPILE_FLAGS -fno-rtti -G0 -O2)
else()
set_target_properties(${BIN_TARGET} PROPERTIES COMPILE_FLAGS -fno-rtti -g -O0)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_PSP_FW_VERSION=500")

create_pbp_file(TARGET ${BIN_TARGET}
ICON_PATH "${PROJECT_SOURCE_DIR}/Packaging/psp/icon.png"
BACKGROUND_PATH "${PROJECT_SOURCE_DIR}/Packaging/psp/background.png"
)
endif()

if(CPACK)
if(NOT SYSTEM_BITS MATCHES x64 AND WIN32)
set(CPACK_PACKAGE_FILE_NAME "devilutionx")
Expand Down
8 changes: 8 additions & 0 deletions Packaging/psp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Building for PSP

Install psptoolchain from https://github.com/pspdev/psptoolchain

It should have set the ENV var "PSPDEV" to "/usr/local/pspdev" and added "$PSPDEV/bin" to PATH automatically. If not, just do it as stated on the github page.

After that you should run build.sh from this folder ("Packaging/psp)" and it will put EBOOT.PBP under "build/".
Binary file added Packaging/psp/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Packaging/psp/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# workaround until we find the real way to change -llibpthreads to -llibpthread-psp
cp ${PSPDEV}/psp/lib/libpthread-psp.a ${PSPDEV}/psp/lib/libpthreads.a

cmake . -DPSP=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${PSPDEV}/psp/share/cmake/PSP.cmake
make
Binary file added Packaging/psp/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 22 additions & 13 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ std::array<Keymapper::ActionIndex, 4> quickSpellActionIndexes;
/* rdata */

bool gbForceWindowed = false;
bool gbShowIntro = true;
bool leveldebug = false;
#ifdef __PSP__
// skipping intro as it messes up with the next screen
bool gbShowIntro = false;
#else
bool gbShowIntro = true;
#endif
#ifdef _DEBUG
bool monstdebug = false;
_monster_id DebugMonsters[10];
Expand Down Expand Up @@ -682,7 +687,6 @@ static void diablo_init()
SFileEnableDirectAccess(true);
init_archives();
was_archives_init = true;

if (forceSpawn)
gbIsSpawn = true;
if (forceDiablo)
Expand Down Expand Up @@ -784,7 +788,6 @@ int DiabloMain(int argc, char **argv)
diablo_splash();
mainmenu_loop();
diablo_deinit();

return 0;
}

Expand Down Expand Up @@ -2127,16 +2130,19 @@ void initKeymapActions()
});
#endif
for (int i = 0; i < 4; ++i) {
char buffer[20];
snprintf(buffer, 12, "QuickSpell%d", i + 1);

quickSpellActionIndexes[i] = keymapper.addAction({
std::string("QuickSpell") + std::to_string(i + 1),
DVL_VK_F5 + i,
[i]() {
if (spselflag) {
SetSpeedSpell(i);
return;
}
ToggleSpell(i);
},
buffer,
DVL_VK_F5 + i,
[i]() {
if (spselflag) {
SetSpeedSpell(i);
return;
}
ToggleSpell(i);
},
});
}
for (int i = 0; i < 4; ++i) {
Expand Down Expand Up @@ -2205,8 +2211,11 @@ void initKeymapActions()
},
});
for (int i = 0; i < 8; ++i) {
char buffer[20];
snprintf(buffer, 20, "BeltItem%d", i + 1);

keymapper.addAction({
std::string("BeltItem") + std::to_string(i + 1),
buffer,
'1' + i,
[i] {
if (!plr[myplr].SpdList[i].isEmpty() && plr[myplr].SpdList[i]._itype != ITYPE_GOLD) {
Expand Down
10 changes: 7 additions & 3 deletions Source/dvlnet/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ wrong_packet_type_exception::wrong_packet_type_exception(std::initializer_list<p
message_ = "Expected packet of type ";
const auto appendPacketType = [this](std::uint8_t t) {
const char *typeStr = packet_type_to_string(t);
if (typeStr != nullptr)
if (typeStr != nullptr) {
message_.append(typeStr);
else
message_.append(std::to_string(t));
}
else {
char buffer[5];
snprintf(buffer, 5, "%d", t);
message_.append(std::string(buffer));
}
};

constexpr char KJoinTypes[] = " or ";
Expand Down
2 changes: 1 addition & 1 deletion Source/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void init_archives()
std::string message;
for (std::size_t i = 0; i < paths.size(); ++i) {
char prefix[32];
std::snprintf(prefix, sizeof(prefix), "\n%6u. '", static_cast<unsigned>(i + 1));
snprintf(prefix, sizeof(prefix), "\n%6u. '", static_cast<unsigned>(i + 1));
message.append(prefix);
message.append(paths[i]);
message += '\'';
Expand Down
41 changes: 41 additions & 0 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,39 @@ extern "C" const char *__asan_default_options()
}
#endif

#ifdef __PSP__
#include <pspkernel.h>

PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_MAX();

int exit_callback(int arg1, int arg2, void* common){
sceKernelExitGame();
return 0;
}

int CallbackThread(SceSize args, void* argp) {
int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();

return 0;
}

int SetupCallbacks() {
int thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if (thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}

extern "C"
{
int SDL_main(int argc, char *argv[])
#else
int main(int argc, char **argv)
#endif
{
#ifdef RUN_TESTS
testing::InitGoogleTest(&argc, argv);
Expand All @@ -33,6 +65,11 @@ int main(int argc, char **argv)
#ifdef __3DS__
ctr_sys_init();
#endif
#ifdef __PSP__
SetupCallbacks();

#endif

#ifdef GPERF_HEAP_MAIN
HeapProfilerStart("main");
#endif
Expand All @@ -42,3 +79,7 @@ int main(int argc, char **argv)
#endif
return result;
}

#if __PSP__
}
#endif
12 changes: 12 additions & 0 deletions Source/miniwin/miniwin.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __PSP__
#include <cstdarg>
#endif

#include <cstdint>

#include <cctype>
Expand All @@ -10,6 +14,14 @@
#include <cstring>
#include <ctime>

#ifdef __PSP__
#define snprintf(buffer, size, format, ...) \
sprintf(buffer, format, __VA_ARGS__)
#define vsnprintf(buffer, size, format, ...) \
vsprintf(buffer, format, __VA_ARGS__)
#define strcasecmp strcmp
#endif

namespace devilution {

#ifndef MAX_PATH
Expand Down
Loading