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 9 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 @@ -88,6 +88,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 @@ -99,3 +107,4 @@ workflows:
- 3ds
- amigaos-m68k
- vita
- psp
27 changes: 26 additions & 1 deletion 3rdParty/StormLib/src/StormPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@

#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_PLATFORM_DEFINED

#endif

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

Expand Down Expand Up @@ -364,7 +389,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
34 changes: 34 additions & 0 deletions CMake/psp_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#General compilation options
set(NONET ON)
set(USE_SDL1 ON)
set(NOSOUND ON)

# keeping the 3DS defaults for now
# Streaming audio is broken on the 3DS as of 25 Mar 2021:
# https://github.com/devkitPro/SDL/issues/72
set(DISABLE_STREAMING_MUSIC ON)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is no longer needed, it was due to a bug that has since been resolved.
PSP does not have enough RAM to run non-streaming audio

set(DISABLE_STREAMING_SOUNDS ON)

#Force scaling, for now..
set(SDL1_VIDEO_MODE_FLAGS SDL_FULLSCREEN)
set(DEFAULT_WIDTH 640)
set(DEFAULT_HEIGHT 480)

#SDL Joystick axis mapping (circle-pad)
# set(JOY_AXIS_LEFTX 0)
# set(JOY_AXIS_LEFTY 1)
#SDL Joystick button mapping (A / B and X / Y inverted)
# set(JOY_BUTTON_A 2)
# set(JOY_BUTTON_B 1)
# set(JOY_BUTTON_X 4)
# set(JOY_BUTTON_Y 3)
# set(JOY_BUTTON_LEFTSHOULDER 5)
# set(JOY_BUTTON_RIGHTSHOULDER 6)
# set(JOY_BUTTON_BACK 7)
# set(JOY_BUTTON_START 0)
# set(JOY_BUTTON_DPAD_DOWN 8)
# set(JOY_BUTTON_DPAD_LEFT 9)
# set(JOY_BUTTON_DPAD_UP 10)
# set(JOY_BUTTON_DPAD_RIGHT 11)
# set(JOY_BUTTON_TRIGGERLEFT 12)
# set(JOY_BUTTON_TRIGGERRIGHT 13)
49 changes: 42 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ if(SWITCH)
include(switch_defs)
endif()

if(PSP)
include("$ENV{PSPDEV}/psp/share/cmake/PSP.cmake" REQUIRED)
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 @@ -187,7 +192,7 @@ if(NOT NOSOUND)
endif()
endif()

if(NOT N3DS)
if(NOT N3DS AND NOT PSP)
find_package(Threads REQUIRED)
endif()

Expand All @@ -212,10 +217,12 @@ if(NOT fmt_FOUND)
add_subdirectory(3rdParty/libfmt)
endif()

if(USE_SDL1)
if(USE_SDL1 AND NOT PSP)
find_package(SDL REQUIRED)
find_package(SDL_ttf REQUIRED)
include_directories(${SDL_INCLUDE_DIR})
elseif(PSP)
include_directories("$ENV{PSPDEV}/psp/include/SDL")
else()
find_package(SDL2 REQUIRED)
if(TARGET SDL2::SDL2)
Expand Down Expand Up @@ -537,7 +544,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 @@ -648,17 +655,21 @@ target_link_libraries(${BIN_TARGET} PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined
if(TSAN)
target_compile_options(${BIN_TARGET} PUBLIC -fsanitize=thread)
target_link_libraries(${BIN_TARGET} PUBLIC -fsanitize=thread)
else()
elseif(NOT PSP)
genex_for_option(ASAN)
target_compile_options(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>")
target_link_libraries(${BIN_TARGET} PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>")
endif()

if(USE_SDL1)
if(USE_SDL1 AND NOT PSP)
target_link_libraries(${BIN_TARGET} PRIVATE
${SDL_TTF_LIBRARY}
${SDL_LIBRARY})
target_compile_definitions(${BIN_TARGET} PRIVATE USE_SDL1)
elseif(PSP)
target_link_libraries(${BIN_TARGET} PRIVATE
${SDL_LIBRARY})
target_compile_definitions(${BIN_TARGET} PRIVATE USE_SDL1)
else()
target_link_libraries(${BIN_TARGET} PRIVATE
SDL2::SDL2
Expand Down Expand Up @@ -699,13 +710,24 @@ if(N3DS)
target_link_libraries(${BIN_TARGET} PRIVATE 3ds::citro3d 3ds::ctrulib)
endif()

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

target_compile_definitions(${BIN_TARGET} PRIVATE -Dmain=SDL_main)
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 HAIKU AND NOT VITA)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT HAIKU AND NOT VITA AND NOT PSP)
target_link_libraries(${BIN_TARGET} PUBLIC "$<$<NOT:$<CONFIG:Debug>>:-static-libgcc;-static-libstdc++>")
endif()

Expand All @@ -726,7 +748,7 @@ if(HAIKU)
target_link_libraries(${BIN_TARGET} PRIVATE network)
endif()

if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND NOT PSP)
# Change __FILE__ to only show the path relative to the project folder
get_target_property(devilutionx_SRCS ${BIN_TARGET} SOURCES)
foreach(SOURCE_FILE ${devilutionx_SRCS})
Expand Down Expand Up @@ -833,6 +855,19 @@ 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")
# may want to add these later
# set_target_properties(${BIN_TARGET} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
# set_target_properties(${BIN_TARGET} PROPERTIES COMPILE_FLAGS -fno-rtti -G0 -O2)

create_pbp_file(TARGET ${BIN_TARGET}
ICON_PATH "${PROJECT_SOURCE_DIR}/Packaging/resources/hellfire.png"
BACKGROUND_PATH "${PROJECT_SOURCE_DIR}/Packaging/resources/hellfire.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/".
2 changes: 2 additions & 0 deletions Packaging/psp/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
psp-cmake . -DPSPDEV=/usr/local/pspdev -DPSP=ON -DCMAKE_BUILD_TYPE=Release
make
28 changes: 17 additions & 11 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2121,16 +2121,19 @@ void initKeymapActions()
});
#endif
for (int i = 0; i < 4; ++i) {
char buffer[12];
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 @@ -2199,8 +2202,11 @@ void initKeymapActions()
},
});
for (int i = 0; i < 8; ++i) {
keymapper.addAction({
std::string("BeltItem") + std::to_string(i + 1),
char buffer[10];
snprintf(buffer, 10, "BeltItem%d", i + 1);

keymapper.addAction({
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
16 changes: 16 additions & 0 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ extern "C" const char *__asan_default_options()
}
#endif

#ifdef __PSP__
#include <pspkernel.h>
#include <pspdebug.h>

PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_MAX();

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,3 +45,7 @@ int main(int argc, char **argv)

return devilution::DiabloMain(argc, argv);
}

#if __PSP__
}
#endif
10 changes: 10 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 Down Expand Up @@ -60,6 +64,12 @@ bool TranslateMessage(const tagMSG *lpMsg);
void PushMessage(const tagMSG *lpMsg);
bool PostMessage(uint32_t Msg, int32_t wParam, int32_t lParam);

#ifdef __PSP__
int snprintf(char *s, size_t n, const char *format, ...);
int vsnprintf(char *s, size_t n, const char *format, va_list arg);
#define strcasecmp strcmp
#endif

#ifdef _MSC_VER
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
Expand Down
23 changes: 23 additions & 0 deletions Source/miniwin/misc_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,27 @@ bool PostMessage(uint32_t type, int32_t wParam, int32_t lParam)
return true;
}

#ifdef __PSP__

int snprintf(char *s, size_t n, const char *format, ...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be best to fix this in the PSP libc instead

{
char message[256];
va_list ap;
va_start(ap, format);
vsprintf(message, format, ap);
va_end(ap);

return sprintf(s, format, message); // Security?
}

int vsnprintf(char *s, size_t n, const char *format, va_list arg)
{
char message[256];
vsprintf(message, format, arg);

return sprintf(s, format, message); // Security?
}

#endif

} // namespace devilution
2 changes: 1 addition & 1 deletion Source/nthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool nthread_recv_turns(bool *pfSendAsync)
last_tick += gnTickDelay;
return true;
}
#ifdef __3DS__
#if defined(__3DS__) || defined(__PSP__)
return false;
#else
if (!SNetReceiveTurns(0, MAX_PLRS, (char **)glpMsgTbl, gdwMsgLenTbl, &player_state[0])) {
Expand Down
2 changes: 2 additions & 0 deletions Source/utils/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ bool ResizeFile(const char *path, std::uintmax_t size)
}
::CloseHandle(file);
return true;
#elif defined(__PSP__)
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some form of ResizeFile is unfortunately required for save games to work

Copy link
Member

Choose a reason for hiding this comment

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

While it would obviously require more code, the PSP has its own save data utility accessible to all games. It is fairly trivial to implement, you can either call the SceUtility functions when saving the game or implement the save data dialog and let players choose files so they can scroll through the fancy icons ;)

https://github.com/pspdev/pspsdk/blob/master/src/samples/savedata/utility/main.c

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.

PSP libc is supposed to already support ftruncate, not sure what's up with it missing

pspdev/newlib#1
pspdev/newlib#2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the problem on pspdev/psptoolchain#108. C++ for some reason doesn't have the functions C does.

#elif _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__)
return ::truncate(path, static_cast<off_t>(size)) == 0;
#else
Expand Down
Loading