Giter VIP home page Giter VIP logo

Comments (7)

yoanlcq avatar yoanlcq commented on August 13, 2024 2

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.

PalMusicFan avatar PalMusicFan commented on August 13, 2024

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.

yoanlcq avatar yoanlcq commented on August 13, 2024

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.

PalMusicFan avatar PalMusicFan commented on August 13, 2024

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.

PalMusicFan avatar PalMusicFan commented on August 13, 2024

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.

PalMusicFan avatar PalMusicFan commented on August 13, 2024

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.

fjtrujy avatar fjtrujy commented on August 13, 2024

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:

Screenshot 2021-11-25 at 13 44 31

Looks to be that maxium fd files you can open in PSP are 60, having in mind that:

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.