forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Basic PRX Template Please

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Wed Feb 14, 2007 9:52 pm    Post subject: Basic PRX Template Please Reply with quote

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
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Thu Feb 15, 2007 12:09 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Thu Feb 15, 2007 10:35 am    Post subject: Reply with quote

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:
#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;

}


here is my make file
Code:
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


but when i try to compile it i get this error and it doesn't compile
Back to top
View user's profile Send private message
harleyg



Joined: 05 Oct 2005
Posts: 123

PostPosted: Thu Feb 15, 2007 9:37 pm    Post subject: Reply with quote

You need a main function.
Back to top
View user's profile Send private message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Thu Feb 15, 2007 10:31 pm    Post subject: Reply with quote

oh so the main thread is not the same as the main function in this case??
Back to top
View user's profile Send private message
Anissian



Joined: 26 Jan 2007
Posts: 16

PostPosted: Fri Feb 16, 2007 1:42 am    Post subject: Reply with quote

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[])
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group