Basic PRX Template Please

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

Moderators: cheriff, TyRaNiD

Post Reply
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Basic PRX Template Please

Post by reefbarman »

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
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

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
10011011 00101010 11010111 10001001 10111010
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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?

Code: Select all

#include <pspctrl.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>

#define printf pspDebugScreenPrintf

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

void CheckCleanExit&#40;void&#41; &#123;

   SceUID thids&#91;50&#93;;
   int thid_count = 0;
   int i;
   //SceUID fd;
   //SceUID memid;
   SceKernelThreadInfo thinfo;

   //if sceKernelExitGame was called, exit before the system crashes
   sceKernelGetThreadmanIdList&#40;SCE_KERNEL_TMID_Thread,thids,50,&thid_count&#41;;
   for&#40;i=0;i<thid_count;i++&#41;
   &#123;
      memset&#40;&thinfo,0,sizeof&#40;SceKernelThreadInfo&#41;&#41;;
      thinfo.size = sizeof&#40;SceKernelThreadInfo&#41;;
           
      sceKernelReferThreadStatus&#40;thids&#91;i&#93;,&thinfo&#41;;

      if&#40;strcmp&#40;&thinfo.name&#91;0&#93;,"SceKernelLoadExecThread"&#41;==0&#41;
      &#123;
         sceKernelSelfStopUnloadModule&#40;0, 0, NULL&#41;;
      &#125;
   &#125;

&#125;

int MainThread &#40;SceSize args, void *argp&#41; &#123;

  while &#40;1&#41; &#123;
	
	 CheckCleanExit&#40;&#41;;
	 pspDebugScreenInit&#40;&#41;;
	 printf&#40;"Hello People"&#41;;
     sceKernelDelayThread&#40;10000&#41;;

  &#125;

  return 0;

&#125;

int module_start&#40;SceSize args, void *argp&#41; &#123;

  SceUID thid;

  thid = sceKernelCreateThread&#40;"percentometer", MainThread, 0x18, 0x1000, 0, NULL&#41;;
  if &#40;thid >= 0&#41; sceKernelStartThread&#40;thid, args, argp&#41;;

  return 0;

&#125;

int module_stop&#40;void&#41; &#123;

  return 0;

&#125;
here is my make file

Code: Select all

TARGET = percentometer
OBJS = main.o

CFLAGS =  -g -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LIBS = -losl -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LDFLAGS =

BUILD_PRX = 1

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
but when i try to compile it i get this error and it doesn't compile
Image
User avatar
harleyg
Posts: 123
Joined: Wed Oct 05, 2005 6:15 am

Post by harleyg »

You need a main function.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

oh so the main thread is not the same as the main function in this case??
Anissian
Posts: 16
Joined: Fri Jan 26, 2007 8:40 pm

Post by Anissian »

reefbarman wrote:oh so the main thread is not the same as the main function in this case??
No, not really. These are two different (although related) concepts:

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[])
Post Reply