掌叔
2009-02-12 09:46:12
摘自:[url]http://www.iacger.com[/url]
作者:newcreat
做prx的傻瓜流程
1. 写main.c,makefile,export.exp,这里用sdk自带的testprx
[code=c]/*
* PSP Software Development Kit - [url]http://www.pspdev.org[/url]
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Simple PRX example.
*
* Copyright © 2005 James Forshaw <[email]tyranid@gmail.com[/email]>
*
* : main.c 1531 2005-12-07 18:27:12Z tyranid $
*/
#include
#include
PSP_MODULE_INFO("TESTPRX", 0x1000, 1, 1);
#define WELCOME_MESSAGE "Hello from the PRXn"
int main(int argc, char **argv)
{
int i;
printf(WELCOME_MESSAGE);
for(i = 0; i < argc; i++)
{
printf("Arg %d: %sn", i, argv);
}
sceKernelSleepThread();
return 0;
}
/* Exported function returns the address of module_info */
void* getModuleInfo(void)
{
return (void *) &module_info;
}[/code]
makefile:
[code=c]TARGET = mymodule
OBJS = main.o
# Define to build this as a prx (instead of a static elf)
BUILD_PRX=1
# Define the name of our custom exports (minus the .exp extension)
PRX_EXPORTS=exports.exp
USE_PSPSDK_LIBC = 1
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak[/code]
写exports.exp,各项意义请看上面的原理红字就是需要改的部分,其他的不需要动.
[code=c]# Define the exports for the prx
PSP_BEGIN_EXPORTS
# These four lines are mandatory (although you can add other functions like module_stop)
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
# Export our function
PSP_EXPORT_START(MyLib, 0, 0x0001)
PSP_EXPORT_FUNC_HASH(getModuleInfo)
PSP_EXPORT_END
PSP_END_EXPORTS[/code]
2 输入make 回车,会看到生成一个prx
3 输入psp-build-exports -s exports.exp 回车,会看到生成一个MyLib.S备用.(文件名会是PSP_EXPORT_START(MyLib, 0, 0x0001)里定的那个)getModuleInfo()就是要导出的函数。
4 测试这个prx,另外建个目录 写main.c,makefile,并把MyLib.S烤进去.
main.c:
[code=c]/*
* PSP Software Development Kit - [url]http://www.pspdev.org[/url]
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Basic harness for loading prxes (for proving a point)
*
* Copyright © 2005 Marcus R. Brown <[email]mrbrown@ocgnet.org[/email]>
* Copyright © 2005 James Forshaw <[email]tyranid@gmail.com[/email]>
* Copyright © 2005 John Kelley <[email]ps2dev@kelley.ca[/email]>
*
* : main.c 1095 2005-09-27 21:02:16Z jim $
*/
#include
#include
#include
#include
#include
PSP_MODULE_INFO("PRXLOADER", 0x1000, 1, 1);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(0);
/* Define printf, just to make typing easier */
#define printf pspDebugScreenPrintf
/* Exit callback */
int exit_callback(int arg1, int arg2, void *arg)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
void CallbackThread(void *arg)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", (void*) CallbackThread, 0x11, 0xFA0, 0xa0000000, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
SceUID load_module(const char *path, int flags, int type)
{
SceKernelLMOption option;
SceUID mpid;
/* If the type is 0, then load the module in the kernel partition, otherwise load it
in the user partition. */
if (type == 0) {
mpid = 1;
} else {
mpid = 2;
}
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = mpid;
option.mpiddata = mpid;
option.position = 0;
option.access = 1;
return sceKernelLoadModule(path, flags, type > 0 ? &option : NULL);
}
/* Imported function */
void *getModuleInfo(void);
int main(void)
{
SceUID modid;
SceModule *mod;
int i;
int ret;
int fd;
pspDebugScreenInit();
/* Install all our funky err thingamybobs */
pspDebugInstallKprintfHandler(NULL);
pspDebugInstallErrorHandler(NULL);
pspDebugInstallStdoutHandler(pspDebugScreenPrintData);
pspSdkInstallNoPlainModuleCheckPatch();
SetupCallbacks();
/* Start mymodule.prx and dump its information */
printf("nStart my modulen");
modid = load_module("ms0:/mymodule.prx", 0, 0);
printf("Module ID %08Xn", modid);
mod = sceKernelFindModuleByUID(modid);
printf("mod %pn", mod);
if(mod != NULL)
{
printf("Attr %04X, Version %x.%xn", mod->attribute, mod->version[0], mod->version[1]);
printf("Name %sn", mod->modname);
printf("Text %08X, Size %08X, Data Size %08Xn", mod->text_addr, mod->text_size, mod->data_size);
printf("Entry Addr %08Xn", mod->entry_addr);
printf("Stub %p %08X, Ent %p %08Xn", mod->stub_top, mod->stub_size, mod->ent_top, mod->ent_size);
for(i = 0; i < mod->nsegment; i++)
{
printf("Segment[%d] %08X %08Xn", i, mod->segmentaddr, mod->segmentsize);
}
ret = sceKernelStartModule(modid, 0, NULL, &fd, NULL);
/* Let's test the module's exports */
printf("Module Info %pn", getModuleInfo());
}
/* Let's bug out */
sceKernelExitDeleteThread(0);
return 0;
}[/code]
makefile
[quote]TARGET = prxloader
OBJS = main.o MyLib.o
USE_PSPSDK_LIBC = 1
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Sample PRX Loader
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak[/quote]
5 make 生成.PBP,将xxx.PBP和xxx.prx考到小p.
6 gameover.
wk80904344
2010-05-30 01:53:49
楼主好强大,prx是插件的东东吗?
我正好想学做插件,由于系统刷到了5.50gen,现在小p电量过低不待机了,是死机,想自己做个电量剩余10%的时候小p转入待机状态的插件,能指点1、2吗?谢谢
wuchanghyz
2010-08-30 16:47:53
晕了,这个程序 无法运行。。。。
返回现实说是游戏无法开始 错误代码:80020148