This is my "I'ma noob helpme!" topic... (only one

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

Moderators: cheriff, TyRaNiD

Post Reply
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

This is my "I'ma noob helpme!" topic... (only one

Post by Heretic »

Ok, I apologize, these topics annoy me sometimes too, but I've really tried to find answers to these questions, and nothing is definitive...

Lets see, first off, I am a decent C++ programmer, I've definitely used quite a handful of languages though. I am also currently learning MIPS assembly in a class, and it was really cool when the professor put up an overhead of a torn-up psp and said it was run on the mips architecture: this was the first time I really cared about psp homebrew. So I came online and started trying to find answers to how one would go doing this. Unfortunately, I failed. Miserably. Right now I have cygwin installed, after much trouble I got Hello World to compile, then upon running it... more failure. It was at this point I realized that I have no clue what I'm doing, and I would like to know a few things before I get serious with starting to make some homebrew apps. Any help is truly appreciated...

1)The most basic part of it all...
The eboot loader. I still have no clue what it is, what it does, but I know it is the key to everything. If someone could enlighten me about that first off, that would be great. (I think I get how the GTA one works (i dont really get the tiff thing), but I still don't know what the loader itself is)

2)Firmware Questions...
I know most of this, but theres a couple things I still dont get. I have firmware 2.0 and I am happy NOT downgrading as of now. Two things I need to know here are:
a) What exactly is the Kernel? I know I can't touch it, but what funtionality do I lose from it? I read a sticky by Fanjita about it, but it only said more or less what I CAN do with ver 2.0, so I'm still confused.
b) What is "user mode" and "kernel mode"?

3) Development Choices...
I see basically 3 choices here, but I don't really know the pros and cons of each. First, theres C. Tried and true, all I would really have to do is learn the library functions and I'm good to go (which seems to be harder than it sounds, as I havent found a tutorial yet) Then, theres LUA. After looking at a tutorial in the LUA board it seems like a very clean approach to PSP programming. But what drawbacks are there? Do I have less options for features (like WiFi, IR, so on, and so forth), or is the only real tradeoff the fact that its a scripted language? Finally, I could (theoretically) just program in MIPS assembly code. I would love to try and make new hacks this way, but I will admit I don't know enough about machine architecture yet for this to even be viable. (Plus, knowing me, all I'd end up making is a $250 paperweight)

Anyway, thats all, sorry for the length of it... I really do appreciate any help given to me in my infant stages of psp dev. I also realize that to reach the end of this length of text (not to mention replying) would have taken considerable time, and I thank you for it. I hope to become an active member of what so far looks to be a mighty fine forum.
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Hi, welcome :)

First of all, you seem to already be on the way and knowing how to program in C++ is a huge advantage.

first, Id recommend these tutorials:

http://www.scriptscribbler.com/psp/tutorials/

After completing them you should be a bit more comfortable with programming for the PSP. Then if you need more, you can download peoples apps that have the source code attached from the PSP sites (ps2dev.org, pspupdates, psp3d, psp-hacks etc) Don't feel bad about looking at other peoples sourcecode, thats why they released it.

Don't forget to look at the samples for the PSP included with the sdk! These are commonly found down deep in "C:\cygwin\usr\local\pspdev\psp\sdk\samples".

And keep a watch on these forums.

Kernel mode and user mode differ in that user mode doesn't give access to some of the system like kernel mode does. Some functions only work in kernel mode, but all that will become clearer after gettin through some tutorials/sourcecode study.

The eboot loader provides a way of running code you have developed. In firmware 1.5, you can run eboots without the need of a loader, instead of running "make", as you would for v1.0, you just do "make kxploit" and it creates 2 folders: YOURAPP and YOURAPP%. you just copy them to your mem stick at /PSP/GAME/ and run it through the standard PSP program manager.

hope that has helped in some small way - I am quite new, only "been around" since xmas and am no expert either :)
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

The EBOOT Loader is fairly easy to describe.

The native PSP format for applications run from the memory stick is to bundle them in a file called EBOOT.PBP. You can find info about that file format elsewhere on this forum, but basically it's a bundle of subfiles, consisting of metadata about the app, icons / videos / sound-effects to present the app to the user in the menu, and the app itself in ELF-format. Official EBOOT.PBP files from Sony are digitally-signed, and the PSP is generally choosy about running unsigned files. All homebrew apps are unsigned, because we don't have the appropriate private key.

On firmware v1.0 you could run unsigned EBOOT.PBP files directly from the Game menu, on v1.5 you're not supposed to be able to but there's a hack called Kxploit that makes it possible. On v2.0 and beyond, it's not possible to run stuff directly from the Game menu.

The EBOOT Loader aims to provide the same platform for homebrew on v2.0+ as was present on v1.0 and v1.5. The goal is that homebrew written for those firmwares can be run with the EBOOT Loader, without any modification.

So, you can just consider it as a mapping layer that helps traditional homebrew feel at home in whatever execution environment is necessary on the later firmwares.

In slightly more detail, its main tasks are:
  • Provide an alternative menu to select homebrew
  • Extract the ELF code from the EBOOT.PBP, and load into memory
  • Fix up all the function imports (i.e. run-time linking)
  • Patch bits of the app that are incompatible with user mode
  • Run it
  • Provide some hooks to allow exit, since the HOME button is disabled.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
_mcinek
Posts: 5
Joined: Thu Jan 26, 2006 9:21 pm

Post by _mcinek »

Hi there Heretic!

I 'm new here too, but I wan't to encourage you to use assembly code! I've managed to write 'hello world' in a week, not having any assembler experience before (on any platform!). A lot of useful documentation is on the net of course, starting from MIPS site when you can get processor instructions, to end with great psp hack's sites when you can found ie. 'Yet Another PSP Doc' with lot of useful information or all system syscalls list.

About EBOOT loader - as far as I know it is some kind of exploit which obey sony protection and can load unsigned code into memory and run in.

User and Kernel mode - Correct me if I'm wrong, kernel is a layer between hardware and software. User mode is much more restricted - you just can't call certain functions, and as a matter of fact, you propably can't brick psp in any way. You're gonna need kernel mode if you would like to use lowlevel hardware functions.

Hope this helps a little
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

Ugh... nothing works. Period.

I seriously don't want to just write LUA scripts, because I feel like I may learn a little bit by doing the (slightly) lower-level programming, but after going through this tutorial http://www.scriptscribbler.com/psp/tuto ... sson02.htm (and failing miserably) I'm starting to lose hope. Hopefully you guys can help me better than people on the qj.net forums, I'll try to be as detailed as possible in my explanation:

Note I'm using the psptoolchain in cygwin
So I copy/paste the source from the tutorial, copy/paste the makefile, and go to compile. At first, I had some issues, but I'll skip describing my week of anger that was all caused because I didn't see the compiler output where it says: "no sceModuleInfo section found."
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

what is your problem you are
facing at the moment? is it enviroment
setup or compiling error ...please
provide descriptive accounts of your
errors and surely one of many who
have shared your problem will come
forward with a common solution

it always helps if you paste what make
errors come up from your shell
10011011 00101010 11010111 10001001 10111010
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

Okay this is the source I tried first:

Code: Select all

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

#define printf pspDebugScreenPrintf

 /* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
	sceKernelExitGame&#40;&#41;;
    return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
    int cbid;

    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;

    sceKernelSleepThreadCB&#40;&#41;;

    return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
    int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41; &#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int main&#40;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	printf&#40;"Hello, psp."&#41;;

	sceKernelSleepThread&#40;&#41;;
	return 0;	
	
&#125;
And I got this output (image link isnt broken, but you may have to go to "View Image"):
Image

so then I thought maybe I need the PSP_MODULE_INFO function, so I added it to my main function resulting in:

Code: Select all

/*All other functions are the same...*/

...

int main&#40;&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	PSP_MODULE_INFO&#40;"HIWORLD",PSP_MODULE_USER,1,1&#41;;
	SetupCallbacks&#40;&#41;;
	printf&#40;"Hello, psp."&#41;;

	sceKernelSleepThread&#40;&#41;;
	return 0;	
	
&#125;
And this time my compiler gave me this output (again, you must "View Image"):
Image

Thanks all and I hope I can get this running soon...
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

this is how PSP_MODULE_INFO macro is
properly used on psp

Code: Select all

/**
 * Program Description Goes Here
 */

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

/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf

/* Define the module info section */
/**
 * 0x1000 = kernel mode elf/prx
 * 0/0x0000 = user mode elf/prx
 */
PSP_MODULE_INFO&#40;"Title", 0x1000, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
/**
 * 0/0x0000 == kernel thread 
 * PSP_THREAD_ATTR_USER == user thread, default with user mode elf
 * PSP_THREAD_ATTR_VFPU == use the vfpu in the thread
 * PSP_THREAD_ATTR_USBWLAN == thread is part of usb/wlan api
 * PSP_THREAD_ATTR_VSH == thread is part of vsh api
 * PSP_THREAD_ATTR_SCRATCH_SRAM == use scratchpad in thread &#40;doesnt work on 1.0/1.51/1.52 psps&#41;
 * PSP_THREAD_ATTR_NO_FILLSTACK == disables filling the stack with 0xFF on creation 
 * PSP_THREAD_ATTR_CLEAR_STACK == clear the stack when the thread is deleted 
 * 
 * ** The Above attributes can be ORed together &#40; a | b &#41; **
 *
 * Example Below&#58; Above module info makes this elf/prx
 *                kernel mode, but below makes main thread
 *                run in user mode instead of default to kernel
 */
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

//////////////////////////////////////////////////////////////////////////////////////
 /* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
   sceKernelExitGame&#40;&#41;;
    return 0;
&#125;

//////////////////////////////////////////////////////////////////////////////////////
/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
    int cbid;

    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;

    sceKernelSleepThreadCB&#40;&#41;;

    return 0;
&#125;

//////////////////////////////////////////////////////////////////////////////////////
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
    int thid = 0;

   thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
   if&#40;thid >= 0&#41; &#123;
      sceKernelStartThread&#40;thid, 0, 0&#41;;
   &#125;

   return thid;
&#125;

//////////////////////////////////////////////////////////////////////////////////////
int main&#40;&#41;
&#123;
    //setup--------------------------------------------------------------------------
    //setup screen
    pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    pspDebugScreenSetXY&#40;0, 0&#41;;

    //must have this here or Home button wont work
    SetupCallbacks&#40;&#41;;

    //all systems go----------------------------------------------------------------
    printf&#40;"Hello World, PSP."&#41;;
    
    //below is not needed 
    //using sceKernelExitGame&#40;&#41;; is preferred 
    //for your purposes
    //sceKernelSleepThread&#40;&#41;;

    //end----------------------------------------------------------------------------
    sceKernelExitGame&#40;&#41;;

    //just for good luck &#58;&#41;
    return 0;   
   
&#125;
as you can see you had the right idea in mind just
improper placement of PSP_MODULE_INFO
which must come at the top of your main source file
and cannot reside in any function (including main() :P)....because it belongs to the preproccesor ...just like all # lines do

that should run just fine and i assume your makefile
is already properly setup also see how i added another
line of PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
if you use kernel mode for second param of PSP_MODULE_INFO
then your EBOOT.PBP would default to having a main thread
that is ...thats right kernel mode thread ... so with above you
set the main thread to be created in user mode thread :)
(...i know im repeating myself :P) thus the power of commenting ;)
even if you do decide to use a kernel mode thread as main
then its good practice just to use PSP_MAIN_THREAD_ATTR(0);
just to be remind yourself and others

cheers
Last edited by dot_blank on Fri Feb 10, 2006 4:23 am, edited 2 times in total.
10011011 00101010 11010111 10001001 10111010
fish
Posts: 25
Joined: Wed Feb 08, 2006 5:12 am

Post by fish »

I've not tried this but it should work, try:

Code: Select all

//#includes

PSP_MODULE_INFO&#40;"HIWORLD",PSP_MODULE_USER,1,1&#41;;

// Other fns

int main&#40;&#41;
&#123;
   pspDebugScreenInit&#40;&#41;;
   SetupCallbacks&#40;&#41;;
   printf&#40;"Hello, psp."&#41;;

   sceKernelSleepThread&#40;&#41;;
   return 0;   
   
&#125;
PSP_MODULE_INFO sets up the stuff to let the PSP know how it should run this code, if you have it in the function the PSP doesn't know how to run the code so it never gets to the bit where you tell it how to run the code.

That might be a bit of a convuluted explanation (and/or wrong):p[/code]
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

I finally got it working thank you all! I also got some other text output set up and now have "Hello psp" which I can direct on the screen using the arrow buttons. Its a start I suppose :)
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Post Reply