Check if a file exists? Threads in a prx?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Check if a file exists? Threads in a prx?

Post by fergie4000 »

is there any way to do this in a prx? i have it working in an eboot, but the same code doesn't seem to work. can anyone point me in the right direction?

i am trying to make 2 threads in the prx. i have these:

Code: Select all

/* fat_plugin -- alias for module_start. Creates plugin worker thread and exits */

int fat_plugin (SceSize argc, void* argp)
{
	u32 func = 0x80000000 | (u32)fat_ninja;
	SceUID thread = sceKernelCreateThread("fat_ninja",(void*)func, 0x30, 0x10000, 0, NULL);
	if (thread >= 0) {
		sceKernelStartThread (thread, argc, argp);
	}
	return 0;
}

/* ninja_plugin -- alias for module_start. Creates plugin worker thread and exits */

int ninja_plugin (SceSize argc, void* argp)
{
	u32 func = 0x80000000 | (u32)ninja_style;
	SceUID thread = sceKernelCreateThread("ninja_style",(void*)func, 0x30, 0x10000, 0, NULL);
	if (thread >= 0) {
		sceKernelStartThread (thread, argc, argp);
	}
	return 0;
}
and

Code: Select all

int module_start (SceSize argc, void* argp) __attribute__((alias("fat_plugin")));
int module_start (SceSize argc, void* argp) __attribute__((alias("ninja_plugin")));
but i'm not sure what it all means for example what is the 0x30?
tia
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

Post by Anissian »

I don't know exactly what you are trying to do, a more detailed explanation of the problem would help. Maybe you are confusing the concept of module entry point and the action of launching a thread?. In any case, yes, it is possible to lauch a thread from the PRX, and that's what the code seems to be trying.


First, a given module should have a single entry point (usually named module:start, the alias is to give it another name). e.g. the part

int fat_plugin (SceSize argc, void* argp)

defines the (a) "module entry point". it could be named "module_start" without the alias line (it seems that you are incorrectly? aliasing module_start to two different functions, fat and ninja). Use just one.

Something like

Code: Select all

int module_start (SceSize argc, void* argp)
{
   u32 func = 0x80000000 | (u32)ninja_style;
   SceUID thread = sceKernelCreateThread("ninja_style",(void*)func, 0x30, 0x10000, 0, NULL);
   if (thread >= 0) {
      sceKernelStartThread (thread, argc, argp);
   }
   return 0;
}
Once the module is started, it creates and starts the thread, who will execute the ninja_style function.

Otoh, is that supposed to be in kernel mode, I guess? (ORing with the 0x8000... address?) bear in mind that OE firmwares require a user mode PRX inside the EBOOT.PBP if you put them in e.g. GAME303 dir.

For sceKernelCreateThread , the parameters are the thread name, the thread proc (function to be exectued by the thread), the thread priority, the thread stack size, attributes and thread options (afaik, the thread options is usually NULL, maybe you can force the memory partition you want the thread stack to be placed at). You may want to look at the PSPSDK documentation for function parameters (http://psp.jim.sh/pspsdk-doc/) .

And last, the easiest way to check if a file exists (there are others) is to try to open it in read mode, and see if you fail.
Last edited by Anissian on Sat Mar 03, 2007 11:51 pm, edited 1 time in total.
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Post by fergie4000 »

ok. i am kinda trying to launch both threads at the same time, but when i use that neither works. how do i go about starting 2?
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

Post by Anissian »

Use a single entry point and then create two threads. This is a skeleton, a few things are missing (such as the exit callbacks for "home key", etc). Not sure if you want user mode, kernel mode, a main thread or not, or whether you don't want a "main" function.

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
...

PSP_MODULE_INFO&#40;"ModName", 0x1000, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;


int 
threadproc1 &#40;SceSize argc, void* argp&#41;
&#123;
/*    
     Your thread proc goes here

*/

   return 0;
&#125;


int 
threadproc2 &#40;SceSize argc, void* argp&#41;
&#123;
/*    
     Your thread proc goes here

*/

   return 0;
&#125;




int 
module_start &#40;SceSize argc, void* argp&#41;
&#123;
       u32 func1 = 0x80000000 | &#40;u32&#41;threadproc1;
       u32 func2 = 0x80000000 | &#40;u32&#41;threadproc2;

       SceUID thread1 = sceKernelCreateThread&#40;"thread1",&#40;void*&#41;func1,           0x30, 0x10000, 0, NULL&#41;;

       // argc and argp don't need to be the module entry point argc and argp
       if &#40;thread1 >= 0&#41; &#123;
              sceKernelStartThread &#40;thread1, argc, argp&#41;;
       &#125;
   

       SceUID thread2 = sceKernelCreateThread&#40;"thread2",&#40;void*&#41;func2,           0x30, 0x10000, 0, NULL&#41;;
       if &#40;thread2 >= 0&#41; &#123;
              sceKernelStartThread &#40;thread2, argc, argp&#41;;
       &#125;

       // you should wait for thread termination here
       return 0;
&#125;
The 0x8000... may not be needed. use (void*) threadproc1 and 2 instead of func.
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Post by fergie4000 »

ok now i think both threads are loading. is this code right?

Code: Select all

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;&#123;
		if &#40;pad.Buttons == 0&#41;
			reveal&#40;&#41;;
trying to make it reveal when no buttons are pressed[/code]
fergie4000
Posts: 25
Joined: Fri Jan 19, 2007 3:03 pm

Post by fergie4000 »

rather than making a pointless new thread i thought i would ask here. is it possible to use libpng in a prx? if so how? i get errors when i try, so does it need to be edited to work in a prx.

Code: Select all

$ make
psp-gcc -I/usr/local/pspdev/psp/sdk/include/libc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150  -L. -L/usr/local/ps
pdev/psp/sdk/lib -Wl,-q,-T/usr/local/pspdev/psp/sdk/lib/linkfile.prx -mno-crt0 -nostartfiles   main.o graphics.o framebuffer.o -lpspgu -lpng -ljp
eg -lz -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpsputility -lpspuser -lpspkernel -o mymodule.elf
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/bin/ld&#58; warning&#58; cannot find entry symbol module_start; defaulting to 0000000000000000
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngerror.o&#41;&#58; In function `png_warning'&#58;
pngerror.c&#58;&#40;.text+0x14c&#41;&#58; undefined reference to `_impure_ptr'
pngerror.c&#58;&#40;.text+0x14c&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
pngerror.c&#58;&#40;.text+0x1a8&#41;&#58; undefined reference to `_impure_ptr'
pngerror.c&#58;&#40;.text+0x1a8&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
pngerror.c&#58;&#40;.text+0x1ac&#41;&#58; undefined reference to `_impure_ptr'
pngerror.c&#58;&#40;.text+0x1ac&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngerror.o&#41;&#58; In function `png_error'&#58;
pngerror.c&#58;&#40;.text+0x2a8&#41;&#58; undefined reference to `_impure_ptr'
pngerror.c&#58;&#40;.text+0x2a8&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
pngerror.c&#58;&#40;.text+0x310&#41;&#58; undefined reference to `_impure_ptr'
pngerror.c&#58;&#40;.text+0x310&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngerror.o&#41;&#58;pngerror.c&#58;&#40;.text+0x314&#41;&#58; more undefined references to `_impure_ptr' follow
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngerror.o&#41;&#58; In function `png_error'&#58;
pngerror.c&#58;&#40;.text+0x314&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngrutil.o&#41;&#58; In function `png_handle_gAMA'&#58;
pngrutil.c&#58;&#40;.text+0xd08&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngrutil.o&#41;&#58; In function `png_handle_cHRM'&#58;
pngrutil.c&#58;&#40;.text+0x146c&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
pngrutil.c&#58;&#40;.text+0x14dc&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngrutil.o&#41;&#58; In function `png_handle_sRGB'&#58;
pngrutil.c&#58;&#40;.text+0x178c&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against `_impure_ptr'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngwrite.o&#41;&#58; In function `png_convert_from_time_t'&#58;
pngwrite.c&#58;&#40;.text+0xac4&#41;&#58; undefined reference to `gmtime'
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngwutil.o&#41;&#58; In function `png_write_cHRM'&#58;
pngwutil.c&#58;&#40;.text+0x10e8&#41;&#58; undefined reference to `_impure_ptr'
pngwutil.c&#58;&#40;.text+0x10e8&#41;&#58; additional relocation overflows omitted from the output
/usr/local/pspdev/psp/sdk/lib/libpng.a&#40;pngwutil.o&#41;&#58; In function `png_write_cHRM_fixed'&#58;
pngwutil.c&#58;&#40;.text+0x163c&#41;&#58; undefined reference to `_impure_ptr'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libjpeg.a&#40;jerror.o&#41;&#58; In function `output_message'&#58;
jerror.c&#58;&#40;.text+0x44&#41;&#58; undefined reference to `_impure_ptr'
/usr/local/pspdev/lib/gcc/psp/4.0.2/../../../../psp/lib/libjpeg.a&#40;jmemmgr.o&#41;&#58; In function `jinit_memory_mgr'&#58;
jmemmgr.c&#58;&#40;.text+0x153c&#41;&#58; undefined reference to `sscanf'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;mymodule.elf&#93; Error 1
hopefully all that means something to somebody.
tia
Post Reply