Basic PRX Template Please
-
- Posts: 87
- Joined: Mon Jan 08, 2007 12:16 pm
- Location: Australia
Basic PRX Template Please
I was wondering if someone can post a template and makefile for a basic prx file that will run within the xmb, i think i already asked this somewhere but im not sure where and cant find it again, and my current attempts at writing a prx that will display hello world in the top corner of the xmb just wont compile so if someone can post the entire code ill work from there thanks
there are already templates for most uses in pspsdk
under the samples directory ...next time do a proper
search ...and remember if your wanting things to run
in the xmb then you must make that prx run in VSH mode
and have sufficient heap size and do not use pspsdk LIBC
but use the psp Kernel LIBC ...this you can specify in your
makefile ...course once your using kernel libc there is no
more point for VSH mode ;)
heres to add to the confusion
cheers
under the samples directory ...next time do a proper
search ...and remember if your wanting things to run
in the xmb then you must make that prx run in VSH mode
and have sufficient heap size and do not use pspsdk LIBC
but use the psp Kernel LIBC ...this you can specify in your
makefile ...course once your using kernel libc there is no
more point for VSH mode ;)
heres to add to the confusion
cheers
10011011 00101010 11010111 10001001 10111010
-
- Posts: 87
- Joined: Mon Jan 08, 2007 12:16 pm
- Location: Australia
these samples are the ones under prx yes? all i have is a prx loader and a text prx example and both really dont help me the test prx isnt threaded and im not too savy on threading it so it doesnt stop use of the xmb, and i have not done any programs in vsh mode or using the kernel yet, so this is a learning curve for me and i just wanted a good place to start from some good example or a template that i can see what is going on, because i cant find to many good examples sorry but i would like someone to post an example im sure its not too hard
EDIT: does this look like a decent start for a prx?
here is my make file
but when i try to compile it i get this error and it doesn't compile
EDIT: does this look like a decent start for a prx?
Code: Select all
#include <pspctrl.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>
#define printf pspDebugScreenPrintf
PSP_MODULE_INFO("percentometer", 0x1000, 1, 0);
PSP_MAIN_THREAD_ATTR(0);
void CheckCleanExit(void) {
SceUID thids[50];
int thid_count = 0;
int i;
//SceUID fd;
//SceUID memid;
SceKernelThreadInfo thinfo;
//if sceKernelExitGame was called, exit before the system crashes
sceKernelGetThreadmanIdList(SCE_KERNEL_TMID_Thread,thids,50,&thid_count);
for(i=0;i<thid_count;i++)
{
memset(&thinfo,0,sizeof(SceKernelThreadInfo));
thinfo.size = sizeof(SceKernelThreadInfo);
sceKernelReferThreadStatus(thids[i],&thinfo);
if(strcmp(&thinfo.name[0],"SceKernelLoadExecThread")==0)
{
sceKernelSelfStopUnloadModule(0, 0, NULL);
}
}
}
int MainThread (SceSize args, void *argp) {
while (1) {
CheckCleanExit();
pspDebugScreenInit();
printf("Hello People");
sceKernelDelayThread(10000);
}
return 0;
}
int module_start(SceSize args, void *argp) {
SceUID thid;
thid = sceKernelCreateThread("percentometer", MainThread, 0x18, 0x1000, 0, NULL);
if (thid >= 0) sceKernelStartThread(thid, args, argp);
return 0;
}
int module_stop(void) {
return 0;
}
Code: Select all
TARGET = percentometer
OBJS = main.o
CFLAGS = -g -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LIBS = -losl -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LDFLAGS =
BUILD_PRX = 1
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
-
- Posts: 87
- Joined: Mon Jan 08, 2007 12:16 pm
- Location: Australia
No, not really. These are two different (although related) concepts:reefbarman wrote:oh so the main thread is not the same as the main function in this case??
a) Having no "main" function, means that you don't want / need the crt0 and initialization that the SDK performs for you and that your module just needs an entry point, usually "module_start". If you have a main means that you expect your application / module to start at the well known int main (int argc, char *argv[])
b) Having or not having a "main thread" is another thing. "main" here means "the first one", unrelated to the classical "main" symbol in C.
f you have a main thread, that means that when a module is loaded and started, a new thread is created that executes the module entry point, or main (thus you can give it a name, and attributes). If you decide to create a module without main thread, the entry point is run by the caller thread, (you need to be careful what you do then, such as sleeping, etc.)
In your case, according to the source, you do have a main thread (with the ATTR macro) and you are not providing the "main" function. What I would do in this case (I do it commonly in pure export PRX) is the following:
In the Makefile
LDFLAGS += -mno-crt0 -nostartfiles
without the -mno-crt0 -nostartfiles the sdk is expecting a "int main ()" somewhere, explaining the linking error. Furthermore, that's why you also get the "duplicate module_start" symbol since without those options the module_start is managed by the SDK, which ends up calling your main function (in the same or a new main thread :o) ).
In other words, the sdk already defines a module_start and end ups calling your main unless you put -mno-crt0 -nostartfiles
Whether you need or not a main thread is a design decision. If the tasks to be performed in your entry point are simple (e.g. all it does it create another thread, or even just return so you export functions) you may not need a main thread.
For this, just add
PSP_NO_CREATE_MAIN_THREAD()
instead of the PSP_MAIN_THREAD_ATTR
Common practice seems to be that if you don't need a main thread, the module_start seems enough, and no need to define a main function, unless you do complex things. If you want a separate thread, let the sdk (crt0 and startup files) define the thread proc for you, parse the arguments and call your int main (int argc, char*argv[])