PlayStation Portable (PSP) : Getting start develop game with CodeBlocks and devkitPSP

PlayStation Portable (PSP) : Getting start develop game with CodeBlocks and devkitPSP

Test on:
- Mac OS X El Capitan
- PlayStation Portable (PSP) E1000 **playable psx game an eboot file
- Memory Stick PRO Duo 32GB for PSP
- PSP USB Data Cable
- CodeBlocks v13.12
- devkitPSP r16-1


  Why PSP?  
      I'm interesting in console game development long time ago but MOST!! limitation not allow Thailand indie game developer to do such a thing like this, so when i got a chance to do, i'll do my best for make me close to a little my dream. If you were not interest in old-fashion of this Sony's device, just skip this tutorial. It's not useful for you and waste your time.

     Thanks an awesome man, here: http://forums.qj.net/psp-development-forum/81882-tutorial-setting-up-code-blocks-devkitpsp.html , this link really help me a lot for create game on psp, It's seem to be 100% possibility develop on latest version of CodeBlocks, PSP and El Capitan (too strictly)

      I can do this in 3 hours, it's feel great when i'm see my stuff run and show on psp screen and this thing done from never and noobs but you're too strong and better than me, OK, if you ready to journey an old-time travel, then prepare your weapons.

  Pre-require  
      You need at least 2 images for display icon and background of game but i'm making 3 images. The third is optional for info.
- icon_80x80.png
- bg_480x272.png
- info_310x180.png  (optional)

You must download CodeBlocks and install from their instruction : e.g. CodeBlocks-13.12-mac.zip
http://www.codeblocks.org/downloads/26

And download devkitPSP compress file then extract file : e.g. devkitPSP_r16-1-osx.tar.bz2
https://sourceforge.net/projects/devkitpro/files/devkitPSP/

I'm not focus on pre-require, you can easy done install CodeBlocks and extract devkitPSP.


  Setup CodeBlocks environment  
      1. Launch CodeBlocks then goto Settings > Compiler...


      2. Tab "Global compiler settings" should be selected (hilight blue) and under Selected compiler should be "GNU GCC Compiler".


      3. Click on "Copy" button, the small dialog "Add new compiler" will be display. Then type "DevKitPSP" and click "OK".


      4. Under Selected compiler choose "DevKitPSP" and click "Set as default".


      5. Click tab "Linker settings" on right-hand side under "Other linker options:" paste this text in blank field "-lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel" , don't create newline just leave it overflow like below image.


      6. Click tab "Search directories" and click tab "Compiler", you should see blank field under policy then click button "Add" and browse to your devkitPSP directories 6 paths and click "OK" like this
- [yourPath]/devkitPSP/lib
- [yourPath]/devkitPSP/psp/lib
- [yourPath]/devkitPSP/psp/sdk/lib
- [yourPath]/devkitPSP/include
- [yourPath]/devkitPSP/psp/include
- [yourPath]/devkitPSP/psp/sdk/include


      7. Leave selected "Search directories" and click tab "Linker", you should see blank field under policy then click button "Add" and browse to your devkitPSP directories 3 paths and click "OK like this.
- [yourPath]/devkitPSP/lib
- [yourPath]/devkitPSP/psp/lib
- [yourPath]/devkitPSP/psp/sdk/lib


      8. Click tab "Toolchain executables", see under "Compiler's installation directory" set to devkitPSP like this:
- [yourPath]/devkitPSP

Then click tab "Program Files" and edit text filed like below:
- C compiler: psp-gcc
- C++ compiler: psp-g++
- Linker for dynamic libs: psp-g++
- Linker for static libs: psp-ar
- Debugger: GDB/CDB debugger : Default
- Resource compiler:
- Make program: make
click "OK"


  Create first PSP project  
      1. On CodeBlocks goto File > New > Project...


      2. Leave selected tab "Projects", click "Empty project" then click button "Go".


      3. Empty project wizard display just click "Next >".


      4. Create your project name under "Project title:" and choose where your project should be save under "Folder to create project in:" then click "Next >".


      5. Make sure under "Compiler:" is "DevKitPSP" and click "Finish".


      6. Your new empty project were created. Let's see on left-space.



  Create main program  
      1. On CodeBlocks goto File > New > File...


      2. Leave selected tab "Files", click on "C/C++ source" then click "Go".


      3. Prompt C/C++ source wizard display just click "Next >".


      4. Choose "C" and click "Next >".



      5. Under "Filename with full path:", type "main.c" and make sure it's selected to full path to your project name, Check box "Add file to active project", "Debug" and "Release" also, Click "Finish".



      6. Your workspace will change to main.c file for coding.


      7. Add this sample code into main file just simply copy paste. This
[ start code ]

// Hello World - A simple "Hello World" Application.

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

PSP_MODULE_INFO("Hello World", 0, 1, 1);

// Exit callback
int ExitCallback(int Arg1, int Arg2, void *Common)
{
    sceKernelExitGame();
    return 0;
}

// Callback thread
int CallbackThread(SceSize Args, void *Argp)
{
    int CallbackId;

    CallbackId = sceKernelCreateCallback("Exit Callback", ExitCallback, NULL);
    sceKernelRegisterExitCallback(CallbackId);

    sceKernelSleepThreadCB();

    return 0;
}

// Sets up the callback thread and returns its thread id
int SetupCallbacks(void)
{
    int ThreadId = 0;

    ThreadId = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if (ThreadId >= 0)
    {
        sceKernelStartThread(ThreadId, 0, 0);
    }

    return ThreadId;
}

int main(int argc, char ** argv)
{
    pspDebugScreenInit();
    SetupCallbacks();

    pspDebugScreenPrintf ("GAME DEV TO DIED");
    pspDebugScreenPrintf ("ON");
    pspDebugScreenPrintf ("PSP is Awesome!!");
    sceDisplayWaitVblankStart();

    sceKernelSleepThread();

    return 0;
}


[ end - code ]


  Build and setting  
      1. Right-click on project and choose "Properties..."


      2. Click on tab "Build targets" make sure to add .elf to project name like below.
- Output filename: bin/Debug/HelloPSP.elf
and uncheck "Auto-generate filename extension", under "Build target files:" checked "main.c".



do the same thing for release mode.
- Output filename: bin/Release/HelloPSP.elf
and uncheck "Auto-generate filename extension", under "Build target files:" checked "main.c".
Click "OK".



      3. Right-click on project choose "Build options..."


      4. Click on tab "Linker settings", under "Other linker options:" add "-lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel" and click "OK".


do the same thing for release mode.


      5. Right-click on project name and choose "Build".


      6. Your build should be success without an error like below and you have got HelloPSP.elf inside bin/Debug folder.




  Create build script and eboot  
      1. Open text editor (i'm using Sublime Text) and create new text file name "BuildEboot.sh" save to [project]/bin/Debug/ and type below code like this:
[ start code ]

#Create EBOOT file

echo "-- Create EBOOT --"
#!/bin/bash
# init
function pause(){
   read -p "$*"
}

#Path to DevKitPSP
MSKFO_PATH="/Users/poraweeraksasin/Downloads/devkitPSP/bin/mksfo"
PSP_FIX_IMPORT_PATH="/Users/poraweeraksasin/Downloads/devkitPSP/bin/psp-fixup-imports"
PSP_STRIP_PATH="/Users/poraweeraksasin/Downloads/devkitPSP/bin/psp-strip"
PACK_PBP_PATH="/Users/poraweeraksasin/Downloads/devkitPSP/bin/pack-pbp"

#Path to Project
ELF_PATH="HelloPSP.elf"
TITLE_NAME="GameDevToDiedOnPSP"
SFO_NAME="GameDevToDiedOnPSP.sfo"
ICON_PATH="icon_80x80.png"
BG_PATH="bg_480x272.png"
INF_IMG_PATH="info_310x180.png"

#Execute command
$MSKFO_PATH $TITLE_NAME $SFO_NAME
$PSP_FIX_IMPORT_PATH $ELF_PATH
$PSP_STRIP_PATH $ELF_PATH -o stripped.elf
$PACK_PBP_PATH EBOOT.PBP $SFO_NAME $ICON_PATH NULL $INF_IMG_PATH $BG_PATH NULL stripped.elf NULL
rm $SFO_NAME
rm stripped.elf
pause 'Press [Enter] key to exit...'

[ end code ]


      2. Put your image "icon_80x80.png", "bg_480x272.png" and "info_310x180.png" into [project]/bin/Debug/


      3. Open Terminal type: "cd" and tap space then drag folder Debug and released on Terminal, then press "Enter".


      4. Type: sh ./BuildEboot.sh and press "Enter".


      5. Your "EBOOT.PBP" file was success created.


      6. Create new folder name "GameDevToDiedOnPSP" and copy "EBOOT.PBP" then paste into it.



  Install and Run on PSP  
      1. PSP goto Settings > USB Connection, press "x", connect PSP via psp usb data cable to mac, 





      2. Open drive from psp, copy folder "GameDevToDiedOnPSP" and paste into PSP/Game folder.


      3. Eject drive psp from mac, goto Game > Memory Stick, press "x" then see your result should be like this:


[ Free source code ]
Eboot file: http://sh.st/U4T2n
Source code: http://sh.st/U4Yx5

It's work :)
Credits: http://forums.qj.net/psp-development-forum/81882-tutorial-setting-up-code-blocks-devkitpsp.html


Comments