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 10 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
8 changes: 7 additions & 1 deletion 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 Expand Up @@ -1434,7 +1441,6 @@ static bool FlatStream_CreateMirror(TBlockStream * pStream)
// which would take long time on larger files.
return true;
}

static TFileStream * FlatStream_Open(const TCHAR * szFileName, DWORD dwStreamFlags)
{
TBlockStream * pStream;
Expand Down
6 changes: 3 additions & 3 deletions 3rdParty/StormLib/src/SFileOpenArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ LCID WINAPI SFileSetLocale(LCID lcNewLocale)
// dwPriority - When SFileOpenFileEx called, this contains the search priority for searched archives
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes in this file look like formatting-only changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of those were leftovers from when I was debugging. I'll remove them.

// dwFlags - See MPQ_OPEN_XXX in StormLib.h
// phMpq - Pointer to store open archive handle

bool WINAPI SFileOpenArchive(
const TCHAR * szMpqName,
DWORD dwPriority,
Expand Down Expand Up @@ -232,7 +231,7 @@ bool WINAPI SFileOpenArchive(
// If not forcing MPQ v 1.0, also use file bitmap
dwStreamFlags |= (dwFlags & MPQ_OPEN_FORCE_MPQ_V1) ? 0 : STREAM_FLAG_USE_BITMAP;

// Open the MPQ archive file
//Open the MPQ archive file
pStream = FileStream_OpenFile(szMpqName, dwStreamFlags);
if(pStream == NULL)
return false;
Expand All @@ -241,8 +240,9 @@ bool WINAPI SFileOpenArchive(
if(nError == ERROR_SUCCESS)
{
FileStream_GetSize(pStream, &FileSize);
if(FileSize < MPQ_HEADER_SIZE_V1)
if(FileSize < MPQ_HEADER_SIZE_V1) {
nError = ERROR_BAD_FORMAT;
}
}

// Allocate the MPQhandle
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
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
33 changes: 20 additions & 13 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ static void diablo_init()
SFileEnableDirectAccess(true);
init_archives();
was_archives_init = true;

if (forceSpawn)
gbIsSpawn = true;
if (forceDiablo)
Expand All @@ -688,7 +687,10 @@ static void diablo_init()

LanguageInitialize();

// todo (PSP): fix crash here. we probably need a better implementation of 'snprintf' on 'misc_msg.cpp'
#ifndef __PSP__
SetApplicationVersions();
#endif

for (size_t i = 0; i < sizeof(spszMsgTbl) / sizeof(spszMsgTbl[0]); i++) {
if (strlen(sgOptions.Chat.szHotKeyMsgs[i]) != 0) {
Expand Down Expand Up @@ -780,7 +782,6 @@ int DiabloMain(int argc, char **argv)
diablo_splash();
mainmenu_loop();
diablo_deinit();

return 0;
}

Expand Down Expand Up @@ -2121,16 +2122,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 @@ -2199,8 +2203,11 @@ void initKeymapActions()
},
});
for (int i = 0; i < 8; ++i) {
keymapper.addAction({
std::string("BeltItem") + std::to_string(i + 1),
char buffer[20];
snprintf(buffer, 20, "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
Loading