转载注明出处:http://blog.csdn.net/yf210yf/article/details/38084587
1.创建testkey.c
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.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()
{
int counter = 0;
int i = 0;
SceCtrlData pad;
pspDebugScreenInit();
SetupCallbacks();
printf("Hello World! snail\n");
printf("Press [X] To Start the Timer\n");
while(1)
{
sceCtrlReadBufferPositive(&pad, 1); //获取按键值
if(pad.Buttons & PSP_CTRL_CIRCLE)
{
break;
}
printf("Press [O] To Stop the Timer\n");
printf("Counter: %i\n", counter);
counter++;
for(i=0; i<5; i++)
{
sceDisplayWaitVblankStart();
}
}
pspDebugScreenClear(); //清除屏幕
printf("Counter Finished.");
printf("Final Count: %i", counter);
sceKernelSleepThread();
return 0;
}
2.写makefile
TARGET = testkey
OBJS = testkey.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
3.make
snail@vm:snail3.testkey$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -c -o testkey.o testkey.c
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -L. -L/usr/local/pspdev/psp/sdk/lib testkey.o -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o testkey.elf
psp-fixup-imports testkey.elf
mksfo 'Hello World' PARAM.SFO
psp-strip testkey.elf -o testkey_strip.elf
pack-pbp EBOOT.PBP PARAM.SFO NULL \
NULL NULL NULL \
NULL testkey_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] 75020 bytes | testkey_strip.elf
[7] 0 bytes | NULL
rm -f testkey_strip.elf
snail@vm:snail3.testkey$
4.测试