环境
本文所用环境包括:
- Ubuntu 8.10
- PSP 1000 3.71 M33
- SDK 是 2009.03.30 从 svn.ps2dev.org 主分支取的最新版本。
安装 PSP SDK
- 从这里下载安装脚本;
- 以普通用户身份运行 install_psp_tool2.sh,按照提示操作即可。
若没有错误提示就说明是安装成功了。
PSP 系统版本与 HomeBrew 开发
不同 PSP 系统版本的程序在源码、Makefile 文件上有区别,因此在开发自己的
PSP 应用时需要根据不同的 PSP 系统做不同的处理。目前主要有三种系统
(1.0, 1.5,和 3.xx),下面以 helloworld 为例,分别介绍在不同版本系统上开
发自己的 PSP 应用。
1.0 系统与 1.5 系统
对于 1.0 系统和 1.5 系统,在程序源码上没有区别,但编译方式有所不同。
helloworld 源码如下所示:
/// Hello World - My First App for the PSP
#include <pspkernel.h>
#include <pspdebug.h>
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main()
{
pspDebugScreenInit();
SetupCallbacks();
printf("Hello World");
sceKernelSleepThread();
return 0;
}
Makefile 文件源码:
TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
要生成 1.0 系统需要的EBOOT.PBP文件直接运行 make 即可。
要生成1.5需要的两个文件夹 xxx和xxx%,运行 make kxploit。另外,也可运行make SCEkxploit, make SCEkxploit 和make kxploit 一样,不过两个文件名称为 __SCE__xxx和%__SCE__xxx,这样那个%__SCE__xxx文件夹在PSP的game菜单中就不会显示为corrupted。
3.xx 系统
与 1.0 和 1.5 不同,3.xx固件要求你的自制软件以prx格式运行,它的源码和
Makefile 都有所不同。
在 Makefile 文件中,添加如下语句至 Makefile 以编译prx(在 include $(PSPSDK)/lib/build.mak 这一行前):
BUILD_PRX = 1
PSP_FW_VERSION = 371
关于源码,需要设置你的软件为用户模式,在 3.xx 系统中自制软件需以用户模式启动。要达此目的,将PSP_MODULE_INFO 中的第2个参数改为 0。大多数软件还需要增加堆栈(heap)大小。堆栈大小是指malloc可用的内存量。我自己设为20mb。以下代码应置于你自己的源代码之前(通常是 main.c):
PSP_MODULE_INFO("My Homebrew", 0, 1, 0);
PSP_HEAP_SIZE_KB(20480);
或者你可以用PSP_HEAP_SIZE_MAX();前提是你用的toolchain是在2007年9月30
日以后编译的(修订号2321)。它将尽可能分配最大的堆栈。请注意要使用此方
法你需要重新编译整个toolchain(或者至少pspsdk和newlib),否则你的软件
会因Exception - Bus错误(数据)崩溃。
修改后的 helloworld 源码如下所示:
#include <pspkernel.h>
#include <pspdebug.h>
PSP_MODULE_INFO ("Hello World", 0, 0, 1);
PSP_HEAP_SIZE_KB (20480);
//Exit callback
int exit_callback (int arg1, int arg2, void *common)
{
sceKernelExitGame ();
return 0;
}
//Callback thread
int CallbackThread (SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback ("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback (cbid);
sceKernelSleepThreadCB();
return 0;
}
//Sets up the callback thread and returns its thread id
int SetupCallbacks (void)
{
int thid = 0;
thid = sceKernelCreateThread ("update_thread", CallbackThread,
0x11, 0xFA0, 0, 0);
if (thid !=0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main()
{
pspDebugScreenInit();
SetupCallbacks();
pspDebugScreenPrintf("Hello World");
sceKernelSleepThread();
return 0;
}
修改后的 Makefile 文件如下所示:
TARGET = hello
OBJS = main.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World
PSPSDK=$(shell psp-config --pspsdk-path)
BUILD_PRX = 1
PSP_FW_VERSION = 371
include $(PSPSDK)/lib/build.mak
这里有篇文章,专门介绍了“转换1.50自制程序为3.xx程序的方法(翻译版)”
上面的 3.xx 系统 helloworld 程序已在我的 PSP 中测试通过。
PSP Error Message
这里列出了 PSP 所有错误号对应的故障,在调试程序时非常有用。
http://www.pspmod.com/forums/psp-misc-guides/14557-psp-error-message-thread.html
安装其它库
http://gezhi.org/node/211
3.71M33 专用 1.50核心補丁V2
该补丁可使 PSP1000 3.71M33 系统上运行 1.5 系统的程序。该补丁是对内核增
加内容,不是代替。
打补丁按如下步骤:
- 下载 1.50 核心补丁 V2 后解压,将 UPDATE 文件夹放到 PSP/GAME 目录下;
- 下载 1.50 官方软件更新文件后解压,将 EBOOT.PBP 改名为 150.PBP 放到
记忆棒根目录下;
- 在 PSP 上运行 1.50 核心补丁 V2,进入后按 X 键即可进行更新,完成后
自动回到 XMB。
|