Comments (7)
I was interested in this, too. Here's what I found.
First, it's worth mentioning that PSPSDK's libc has a #define _NFILE 16
which limits the number of fopen()
handles, if you use that library.
I wrote a test application which tried to open as many different files as possible via sceIoOpen
in read-only mode, until the call would fail, and tested it via PSPLINK (too lazy to test it as an EBOOT.PBP).
The application was able to open 56 different files simultaneously. What I think is most interesting is that the highest file descriptor value it could get was 63 (if we include 0, that makes 64 file descriptors, which makes sense to me since it's a power of two).
The smallest file descriptor value (the first) the application could get was 7. Probably the first 3 are stdin, stdout and sterr, and either the 5 others are reserved by the kernel, or used by PSPLINK.
I guess it's reasonable to assume that the kernel reserves 8 file descriptors, and supports up to 64 (per-module? system-wide? idk). These are nice power of two integers.
(edit) I'm testing on a PSP SLIM 2000, with firmware version 6.35.
from pspsdk.
Thanks so much for your reply!
Since the application was able to open 56 different files simultaneously, why PSPSDK's libc has a #define _NFILE 16 ? Is it something like early PSP hardware / software limitation? How could PPSSPP ignore the limitation of _NFILE 16? Is it a hack?
from pspsdk.
why PSPSDK's libc has a #define _NFILE 16 ?
idk, hopefully an expert out there knows, but my I guess is, it could have been a copy-paste or just an educated guess.
How could PPSSPP ignore the limitation of _NFILE 16 ?
Regardless of PPSSPP, the "real" existing PSP games do not use the PSPSDK's libc (which is unofficial), hence I'm pretty sure the limitation is not there (or is way bigger). Not even all homebrew PSP games are guaranteed to use it, because there are various alternatives (e.g newlib).
When building a homebrew PSP game with the current SDK, you can set USE_PSPSDK_LIBC=1
when calling make
if you want to use PSPSDK's libc. The alternatives are USE_KERNEL_LIBC=1
, or newlib (see src/base/build_prx.mak
).
Knowing that, PPSSPP is basically a PSP kernel running on high-end platforms such as PCs. One could look at the source on GitHub if they're so inclined, but I'm guessing at some point they're just using the host's fopen() or equivalent, which has practically no limitation (what's the FOPEN_MAX on PC ? :) ).
from pspsdk.
Thanks so much! That is very important information for me!
Actually I am maintaining the PSP version of a homebrew classic RPG cross-platform reimplementation. I encountered two main problems. One of them is this FOPEN_MAX limiatation. Though I solved it with conditional compilation, but this makes my code unsuitable for being merged into the main stream (The other one is "If bpp is 8, repeated SDL_SetVideoMode calling will cause Display error." pspdev/psplibraries#37 ) .
Thanks again! :)
from pspsdk.
Sorry, I just finished a file demo:
OpenFileTest.zip
It seems only 10 files could be opened simultaneously (fd number 3~12).
Am I doing something wrong? Thanks!
from pspsdk.
In addition, how do we achieve suspend-resume? If a file is being read when suspending, it seems that the pointer position can not be saved? Edit: Solved, but do I have to handle it all by myself? I am not sure whether my solution is stable.
for (int i = 3; i < 13; i++) {
printf("PSP_POWER_CB_SUSPENDING i = %d \n", i);
if (__psp_descriptormap[i]) {
fileseekpoints[i] = ftell(i); // It stops here. Edit: Sorry, I confused fd and fp.
}
}
from pspsdk.
Hello @PalMusicFan,
About 2 years after, I'm coming for closing the issue and giving you more information. About how it is working after the new POSIX
toolchain.
I have modified your example:
int main(int argc, char** argv)
{
SetupCallbacks();
atexit(sceKernelExitGame);
pspDebugScreenInit();
int fd;
char pathname[30];
for (int i = 1; i <= 69; i++) {
sprintf(pathname, "%02d.txt", i);
printf("Opening %s: ", pathname);
if ((fd = open(pathname, O_RDONLY)) < 0) {
printf("Failed\n");
break;
}
printf("OK, fd: %i\n", fd);
sceKernelDelayThread(100000);
}
sceKernelDelayThread(10000000);
sceKernelExitGame();
return 0;
}
I have tried in both places PPSSPP
and real PSP
, in both it behaves exactly the same, and limitation looks to be a PSP OS
limitation:
Looks to be that maxium fd
files you can open in PSP are 60
, having in mind that:
fd = 0
is forsceKernelStdin
fd = 1
is forsceKernelStdout
fd = 2
is forsceKernelStderr
You can see this info here:
https://github.com/pspdev/pspsdk/blob/master/src/libcglue/fdman.c#L48-L60
And forPPSSPP
: https://github.com/hrydgard/ppsspp/blob/aefc21f4a36e8add2378f1f3d12c08bf6d78a133/Core/HLE/sceIo.cpp#L122
So fd = 3
would be the first id when an user open a file in his program.
Having in mind that your app needs to open 56 files simultaneously, I think that your problem will be solved with the new toolchain.
Thanks!
from pspsdk.
Related Issues (20)
- Trying to Compile sm-64 port, and I get this error related to the sdk HOT 3
- [ISSUE] SDL2_mixer: undefined reference to `ov_*` HOT 5
- SIO sample firmware version limitation HOT 2
- Remove Corrupt PrxEncrypter from Tools HOT 6
- add a sample for pspge HOT 1
- Header(s) cannot be included warning-free with `-Wundef` HOT 3
- Global/Static variables never initialized HOT 1
- Remove -G0 flag in build_prx.mak ? HOT 2
- Wrong freetype path HOT 2
- sceGeEdramSetSize not working properly HOT 2
- sceUtilityLoadNetModule, audio and thread issue HOT 5
- `__retarget_lock_init.o, error: invalid type argument of ‘->’` HOT 6
- Environmental Variables HOT 4
- undefined reference to `sceKernelVolatileMemTryLock' HOT 2
- Missing header in psprtc.h HOT 2
- Missing `remove(const char *path)` HOT 3
- new dependency on pthread-embedded HOT 11
- configure doesn't set default CFLAGS HOT 3
- CMake using the incorect OUTPUT_NAME but stripping. HOT 8
- libpspdmac doesn't work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pspsdk.