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

PSP port #1918

wants to merge 24 commits into from

Conversation

stefanmielke
Copy link
Contributor

@stefanmielke stefanmielke commented May 9, 2021

Draft PR for PSP support.

Got so far as to build and create the EBOOT. But it generates a corrupted file that can't be executed (crashes on real PSP, works fine on PPSSPP).

Also tested Linux build to see if any changes would affect it. Would be nice to review those, as I had to remove "std::to_string" support for it to build.

@@ -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.

# 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

//-----------------------------------------------------------------------------
// 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

@@ -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.

Source/init.cpp Outdated
HANDLE fh = nullptr;
if (!SFileOpenFile("ui_art\\title.pcx", &fh))
if (!SFileOpenFile("ui_art\\title.pcx", &fh)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the formatting-only changes

@@ -723,4 +723,26 @@ 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

@@ -22,6 +22,11 @@

#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu)

#ifdef __PSP__
// PSP has the wrong definition on SDL_config.h, so we use ours
#define SDL_snprintf devilution::snprintf
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 SDL instead

Copy link
Member

Choose a reason for hiding this comment

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

its in draft mode so i think some hacks are expected for now :)

@stefanmielke
Copy link
Contributor Author

@AJenbo @glebm still haven't gotten any more progress than being able to run on PPSSPP.

On real hardware it crashes on StormLib/SBaseCommon.h:459 on method DecryptMpqBlock when it tries to access DataBlock[i] after the first time it goes in the method (when pvDataBlock has been 'added' with the first move on the method that calls this one). Everything seems to work if I force fail this method (the menu loads without any assets, but I'm able to go ingame and it generates the save file as expected, or exit the game).

We still have the issues @glebm linked on PSPSDK end (pspdev/newlib#1 and pspdev/newlib#2). For now I redirected snprintf to sprintf and vsnprintf to vsprintf without major issues, but even copying the whole code for those 2 methods didn't change anything.

Also tried to use the PSPSDK sceIo* methods on Stormlib, but unfortunately sceIoRead is not returning the correct bytes read (and probably reading more than it should).

I'm adding a list of things missing from this port as a checklist on the original PR comment to keep track.

Copy link
Member

@AJenbo AJenbo left a comment

Choose a reason for hiding this comment

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

321

Comment on lines +7 to +9
#ifdef __PSP__
#include "miniwin/miniwin.h"
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Contributor Author

@stefanmielke stefanmielke May 15, 2021

Choose a reason for hiding this comment

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

It's needed for the SDL_snprintf redirect to work. SDL_snprintf calls snprintf, and we redirect snprintf to sprintf for now.


#if defined(__3DS__)
retval = SDL_strdup("sdmc:/3ds/devilutionx/");
return retval;
#endif
#if defined(__PSP__)
{
// replacement for strdup
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hopefully the newlib 3 branch has strdup and other missing functions

@AJenbo
Copy link
Member

AJenbo commented Jul 2, 2022

@stefanmielke both StormLib, snprintf, and vsnprintf have been removed as dependencies so this should probably workout much better if rebased :)

@AJenbo
Copy link
Member

AJenbo commented Mar 10, 2023

Things are now in a much better state so I did a fresh draft for this :)
#5869

I have tested the game in the PPSSPP emulator but it still need to be test it on hardware.

@AJenbo AJenbo closed this Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants