維尼的蜂巢

RealTime??!! It’s amazing!!!!

PSP Develope @2 八月 7, 2008

Filed under: psp — kevinlin @ 11:13 上午

上一篇 PSP Develope @1 把環境設定搞好了

接下來要來做個HelloWorld

在c:\cygwin\home\username 裡面隨便開個目錄 叫[helloworld]好了

建立main.c 到helloworld裡面

/// Hello World - My First App for the PSP

#include
<pspkernel.h>
//這理論上是每一個PSP程式都要include的
#include
<pspdebug.h>
//pspdebug.h包含了print到螢幕上的那個function

PSP_MODULE_INFO("Hello World", 0, 1, 1);
//上面是  程式名  後面是 mode (0 for user mode) 跟 major version 跟 minor version

// 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)
include $(PSPSDK)/lib/build.mak

makefile的解說

TARGET = helloworld Sets the name of the ELF file produced and also the name of the two folders if the program is kxploited or SCEkxploited.
OBJS = main.o Tells the compiler which files we need it to compile. In this case we just want our main.c file compiling into main.o
CFLAGS = -O2 -G0 -Wall Sets the options we want when compiling C files.
    -O2 Optimize even more. The compiler will perform all supported optimizations that do not involve a space-speed tradeoff.
    -G0 Allow referencing objects upto 0 bytes implicitly with the gp register.
    -Wall Turns on all optional warnings. We want our compiler to show every warning or error.
EXTRA_TARGETS = EBOOT.PBP Creates an eboot that we can use on the PSP from the ELF file built when we compile.
PSP_EBOOT_TITLE = Hello World The text which you can see in the XMB when selecting the program on the memory stick.
PSPSDK=$(shell psp-config –pspsdk-path) Sets ‘PSPSDK’ to the path where we have it installed using psp-config. Try it yourself, in the Cygwin prompt type psp-config –pspsdk-path, Cygwin will output the path to the PSPSDK.
include $(PSPSDK)/lib/build.mak Includes the code from the build.mak file in our makefile, like using #include in a C file would. build.mak contains extra instructions for the compiler which you need not worry about.

 

然後只要
– 打開cygwin
– cd HelloWorld
– make

就會看到下面的畫面

他產生的EBOOT.PBP就是執行檔了

把它丟到PSP的卡裡面 \PSP\GAME 這裡面

建立一個helloworld資料夾 把EBOOT.PBP丟進去 就可以直接執行了

 

大功告成

 

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s