Monday, March 7, 2011

PSP Programming Tutorial for Windows + SDL (Without Cygwin)

PSP Programming Tutorial for Windows (C/C++)
Plus SDL with out Cygwin


This tutorial that i have written will teach you step by step how to set up you psp development environment for windows in less than 15 minutes and without the need to install any large files or Shells (Cygwin).

Before i begin i would like to thank heimdall for the excellent Win32 toolchain and pspsdk installer. (Minimalist PSPSDK for Windows)
Also i would like to add, If you are new to C/C++ I would highly recommend you begin your programming adventure on a computer, not the psp. For serious "want to be" programmers, i would highly recommend taking courses at your local community college.

------

-INSTALLATION-

1. Click the following link to download the Win32 native toolchain and pspsdk installer (Created by Heimdall).

2. Download the file: "pspsdk-setup-0.9.2.exe" from sourceforge.

3. Run the file that was just downloaded and when it asks where to install change "C:/pspsdk" to "C:/pspdev". The rest just press next til finished.

4. Congratulations, You have just installed the pspsdk, toolchain, and libraries needed to program on the psp.

5. You should now have a folder inside your harddrive named pspdev. (C:/pspdev/)

------

-SETUP-

6. Open up Notepad and paste the following code:

Code:
set path=%path%;c:\pspdev\bin
set PSPSDK=C:\pspdev\psp\sdk
cmd
7. Save the file as: "start.bat", Save as type: "all files", and place it inside C:/pspdev/

8. Open "start.bat". The following information should be displayed

Code:
C:\pspdev>set path=C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;c:\Py
thon22;C:\Program Files\QuickTime\QTSystem\;
C:\Program Files\Subversion\bin;C:/p
spdev/bin;C:/pspdev/bin;;;;;C:\pspdev\bin;c:\pspdev\bin

C:\pspdev>set PSPSDK=C:\pspdev\psp\sdk

C:\pspdev>cmd
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\pspdev>




9. Congratulations, You have just setup your handy dandy compiler.

--------

-COMPILING/CREATING PROGRAMS-

10. You are now ready to create your first eboot. How?

11. When using the command prompt, it is important to know how to move from folder to folder.
The simple yet effective way to do so is by the following:

12. Open "start.bat" once again.

13. Type: "cd psp", now press enter. You are now inside the folder "psp" which is inside of "pspdev" (C:/pspdev/psp/)

14. To go back to the pspdev folder (C:/pspdev/), Type "cd..", now press enter.

15. To move into a folder that is inside another folder, such as (C:/pspdev/psp/sdk/), Type: "cd psp/sdk", now press enter.
The same can also be achieved by typing "cd psp", press enter, "cd sdk", press enter. Both will take you to (C:/pspdev/psp/sdk/)

16. We are currently in (C:/pspdev/psp/sdk/). We need to go back to (C:/pspdev/). Type "cd..", press enter, "cd..", press enter

17. Now that we are back in (C:/pspdev/) and you now understand how to move from folder to folder, it is time to compile a working eboot for your psp.

18. Type: "cd psp/sdk/samples/controller/basic", press enter. We are now in (C:/pspdev/psp/sdk/samples/controller/basic/).

19. Inside this file is C source code and a makefile. You can not compile a program for the psp without a makefile.

20. Now type: "make", press enter. The following should display:

Code:
C:\pspdev\psp\sdk\samples\controller\basic>make
psp-gcc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall 
-D_PSP_FW_VERSION=150   -c
 -o main.o main.c
psp-gcc -I. -IC:/pspdev/psp/sdk/include -O2 -G0 -Wall 
-D_PSP_FW_VERSION=150  -L.
 -LC:/pspdev/psp/sdk/lib   main.o  -lpspdebug 
-lpspdisplay -lpspge -lpspctrl -lp
spsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl 
-lpspnet_resolver -lpsputility -
lpspuser -lpspkernel -o controller_basic.elf
psp-fixup-imports controller_basic.elf
psp-strip controller_basic.elf -o controller_basic_strip.elf
pack-pbp EBOOT.PBP PARAM.SFO NULL  \
        NULL NULL NULL  \
        NULL  controller_basic_strip.elf NULL
[0]        408 bytes | PARAM.SFO
[1]          0 bytes | NULL
[2]          0 bytes | NULL
[3]          0 bytes | NULL
[4]          0 bytes | NULL
[5]          0 bytes | NULL
[6]      58508 bytes | controller_basic_strip.elf
[7]          0 bytes | NULL
C:/pspdev/bin/rm -f controller_basic_strip.elf

C:\pspdev\psp\sdk\samples\controller\basic>










21. Congratulations, You just compiled your first program for the psp.

22. Go to (C:/pspdev/psp/sdk/samples/controller/basic/) and copy the EBOOT you just compiled and place it in a new folder inside of your psp, in the (PSP/GAME) folder.

23. Now go try it out!

24. Its time to code =].

---------------

-CODING-

1. The next step is writing your own code. Now you can certainly go ahead and code in notepad, but it is not a good idea. Downloading a program to code on is certainly a good idea.

2. I recommend usind devcpp (bloodshed). Devcpp can be used to code C and CPP on just about anything (Google it). The way i have my setup is i create a new project and save it in a folder inside of (C:/pspdev/).

3. Then begin to code or add code to the project and save the code and makefile using devcpp.

4. I then use the compiler we made "start.bat" and go to the folder where my project is and type make.

5. Thats it. It works great this way for me.

6. If you need help with coding for the psp or are new, Go to PSP-Programming.com for a great tutorial for the psp. Just start on lesson 2.

------

Further Links:
Heimdall - MinPSPW
forums.ps2dev.org :: View topic - Win32 native Toolchain for PSPSDK
jetCube


------
-SDL for PSP-

1. After hours of forum jumping and testing i was finally able to put together a makefile that would work with SDK and compiler we created without cygwin.

2. All of the libraries needed for SDL to run correctly, including SDL Mixer, TTF, and Image, have been installed already (and correctly) thanks to Heimdalls installer.

3. Here is the Makefile I have been using for a game i am making:

Code:
TARGET = Ohaspii
OBJS = main.o Title.o sdlFunction.o mp3player.o

PSPSDK = $(shell psp-config --pspsdk-path)
PSPDEV = $(shell psp-config -d)
PSPBIN = $(PSPDEV)/bin
SDL_CONFIG = $(PSPBIN)/sdl-config

CFLAGS = -O2 -G0 -Wall -D PSP
CFLAGS += $(shell $(SDL_CONFIG) --cflags)
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBS = -lstdc++ -lSDL_ttf -lfreetype -lSDL_image -ljpeg 
-lpng -lz -lm -lSDL_mixer -lvorbisidec -lmikmod 
-lmad $(shell $(SDL_CONFIG) --libs)
LIBS += -lpspaudiolib -lpspaudio -lpsppower

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Ohaspii

include $(PSPSDK)/lib/build.mak






With this makefile you should have no problem using sdl for the psp. Obviously you will need to change the TARGET, OBJ, and TITLE values. It took me a long time to figure out the order of the LIBS but this worked for me, goodluck.

9 comments:

  1. Damn...This has helped me a ton!


    Thanks!

    ReplyDelete
  2. No problem friend, if you have a blog follow me and ill follow you :). Take care!

    ReplyDelete
  3. That may have just made my life a TON easier. Thanks :)

    ReplyDelete
  4. Damned cool! I need to brush up on my C++, but when I do I'd love to try this out.

    ReplyDelete
  5. Thanks, exactly what I've been looking for. hopefully can put this into practice later tonight.

    ReplyDelete
  6. I hope I can try this later, this is some useful information.

    ReplyDelete