I am still trying to compile the prx of "RemaPSP" application to work on PSP 4.01 M33 firmware...
http://localhost.geek.nz/remapsp/remapspsrc.zip
Please help me to complete this job..
1.
I have installed 'devkitPro' tool on my windowsXP PC, and set the path with the PSP bin folder.
Is this tool everthing required to compile a prx file?
Just run 'make' in the directory of source directory?
2.
Could anyone tell me where I can find a open source code of a prx file including 'makefile' which works on PSP 4.01 M33 firmware ?
The required function is very simple..
: A text menu pops up when the specific buttons are pressed during a game.
just like 'alternative VSH' or 'cwcheat'..
3.
This is the hardest part to me..
'RemaPSP' interferes with every control signal by hooking the controller function such as :
sceCtrlPeekBufferPositive
sceCtrlPeekBufferNegative
sceCtrlReadBufferPositive
sceCtrlReadBufferNegative
sceCtrlPeekLatch
sceCtrlReadLatch
I have extracted the related codes below.
Does this code still work on PSP 4.01 M33 firmware?
I doubt the address values of the 'mainHookSave' variable..
Are these values changed for each firmware? How can I get them?
-------------------------------------------------------------------------------------
< main.c : function hook >
Code: Select all
typedef struct MainHook
{
ModuleFunc modfunc;
char modname[32];
char libname[32];
u32 nid;
void *func;
} MainHook;
MainHook mainHookSave[MAIN_HOOK_NBR] =
{
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0x3A622550, sceCtrlPeekBufferPositiveFake },
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0xC152080A, sceCtrlPeekBufferNegativeFake },
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0x1F803938, sceCtrlReadBufferPositiveFake },
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0x60B81F86, sceCtrlReadBufferNegativeFake },
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0xb1d0e5cd, sceCtrlPeekLatchFake },
{ { 0, NULL }, "sceController_Service", "sceCtrl", 0x0b588501, sceCtrlReadLatchFake },
};
mainThread()
{
.....
// Patch syscall table, here the program use jmp func in stub table, so patch not applied here but in all user modules
for (x=0;x<MAIN_HOOK_NBR;x++)
{
ret = moduleHookFunc(&mainHookSave[x].modfunc, sceKernelSearchModuleByName(mainHookSave[x].modname), mainHookSave[x].libname, mainHookSave[x].nid, mainHookSave[x].func);
}
.....
}
int module_start (SceSize args, void *argp)
{
.....
thid = sceKernelCreateThread("RemapspMain",mainThread,8,0x10000,0,NULL);
if (thid >= 0) sceKernelStartThread(thid,args,argp);
.....
}
< module.c >
Code: Select all
u32 moduleHookFunc (ModuleFunc *modfunc, SceUID modid, const char *library, SceUID nid, void *func)
{
u32 *addr;
// Verify parameters
if ((!(modfunc)) || (!(library)) || (!(func))) return 1;
// Find address of function in entry table and get pointer in entry table
addr = moduleFindFunc(moduleFindLibrary(modid,library),nid);
// If not found
if (!(addr)) return 2;
// Copy address of function in structure
modfunc->addr = *addr;
// Find address of function in syscall table and get pointer in syscall table
modfunc->sysaddr = moduleFindSyscallFunc(modfunc->addr);
// If not found
if (!(modfunc->sysaddr)) return 3;
// Hook function (copy func address to syscall table, overwrite old func)
return moduleHookAddr(modfunc->sysaddr,(u32) func);
}
u32 moduleHookAddr (u32 *addr, u32 func)
{
int x;
// Verify parameters
if (!(addr)) return 1;
// Disable interrupts
x = pspSdkDisableInterrupts();
// Patch address
*addr = func;
// Apply to cache
sceKernelDcacheWritebackInvalidateRange(addr,sizeof(addr));
sceKernelIcacheInvalidateRange(addr,sizeof(addr));
// Enable interrupts
pspSdkEnableInterrupts(x);
return 0;
}
u32 *moduleFindSyscallFunc (u32 func)
{
u8 **syscall;
ModuleSyscallHeader *sysheader;
u32 *systable;
int size, x;
// Get syscall table
asm("cfc0 %0, $12\n" : "=r"(syscall));
// Exit if failed
if (!(syscall)) return NULL;
// Get syscall header
sysheader = (ModuleSyscallHeader *) *syscall;
// Get syscall table
systable = (u32 *) ((*syscall) + sizeof(ModuleSyscallHeader));
// Get syscall size
size = (sysheader->size - sizeof(ModuleSyscallHeader)) / sizeof(u32);
// Search function
for (x=0;x<size;x++)
{
if (systable[x] == func) return &systable[x];
}
return NULL;
}
u32 *moduleFindFunc (SceLibraryEntryTable *entryTable, SceUID nid)
{
u32 *entry;
int x;
// Verify parameters
if (!(entryTable)) return NULL;
// Find entry table
entry = (u32 *) entryTable->entrytable;
// NID loop
for (x=0;x<entryTable->stubcount;x++)
{
// Find function address
if (entry[x] == nid) return &entry[x + entryTable->stubcount + entryTable->vstubcount];
}
return NULL;
}
SceLibraryEntryTable *moduleFindLibrary (SceUID modid, const char *library)
{
SceModule *mod;
SceLibraryEntryTable *entryTable, *entryEnd;
// Find memory of module
mod = sceKernelFindModuleByUID(modid);
// If bad module
if ((((long) mod) & 0xFF000000) != 0x88000000) return NULL;
if ((mod->stub_top - mod->ent_top) < 40) return NULL;
// Find entry table
entryTable = (SceLibraryEntryTable *) ((u32 *) mod->ent_top);
entryEnd = (SceLibraryEntryTable *) (((u8 *) mod->ent_top) + mod->ent_size);
// Entry table loop
while (entryTable < entryEnd)
{
// Find name
if (entryTable->libname) // first entry (module info) has name = NULL
{
if (!(strcmp(entryTable->libname,library))) return entryTable;
}
// Next entry
entryTable = (SceLibraryEntryTable *) (((u32 *) entryTable) + entryTable->len);
}
// Not found
return NULL;
}
< main.c : alternative control functions >
Code: Select all
int sceCtrlPeekBufferPositiveFake(SceCtrlData *pad_data, int count)
{
u32 k1;
k1 = pspSdkSetK1(0);
int res = ((FUNC_CTRL) mainHookSave[0].modfunc.addr)(pad_data, count);
overrideControls(pad_data); # control signal overriding
pspSdkSetK1(k1);
return res;
}
int sceCtrlPeekBufferNegativeFake(SceCtrlData *pad_data, int count)
{
u32 k1;
k1 = pspSdkSetK1(0);
int res = ((FUNC_CTRL) mainHookSave[1].modfunc.addr)(pad_data, count);
overrideControls(pad_data);
pspSdkSetK1(k1);
return res;
}
int sceCtrlReadBufferPositiveFake(SceCtrlData *pad_data, int count)
{
u32 k1;
k1 = pspSdkSetK1(0);
int res = ((FUNC_CTRL) mainHookSave[2].modfunc.addr)(pad_data, count);
overrideControls(pad_data);
pspSdkSetK1(k1);
return res;
}
int sceCtrlReadBufferNegativeFake(SceCtrlData *pad_data, int count)
{
u32 k1;
k1 = pspSdkSetK1(0);
int res = ((FUNC_CTRL) mainHookSave[3].modfunc.addr)(pad_data, count);
overrideControls(pad_data);
pspSdkSetK1(k1);
return res;
}
int sceCtrlPeekLatchFake(SceCtrlLatch *latch_data)
{
SceCtrlData pad;
int res = sceCtrlPeekBufferPositiveFake(&pad, 1);
//Gen new Latch
latch_data->uiMake = (previousPressed ^ pad.Buttons) & pad.Buttons;
latch_data->uiBreak = (previousPressed ^ pad.Buttons) & previousPressed;
latch_data->uiPress = pad.Buttons;
latch_data->uiRelease = ~pad.Buttons;
previousPressed = pad.Buttons;
return res;
}
int sceCtrlReadLatchFake(SceCtrlLatch *latch_data)
{
SceCtrlData pad;
int res = sceCtrlPeekBufferPositiveFake(&pad, 1);
//For one reason or another this is no good. Makes games run too slow
//int res = sceCtrlReadBufferPositiveFake(&pad, 1);
//Gen new Latch
latch_data->uiMake = (previousPressed ^ pad.Buttons) & pad.Buttons;
latch_data->uiBreak = (previousPressed ^ pad.Buttons) & previousPressed;
latch_data->uiPress = pad.Buttons;
latch_data->uiRelease = ~pad.Buttons;
previousPressed = pad.Buttons;
return res;
}
4.
Is this makefile valid to achieve a prx file for PSP 4.01 M33 ?
---------------------------------------------------------------------------------
Code: Select all
TARGET = remapsp
OBJS = main.o Utils/module.o exports.o conf.o wifi.o menu.o multiselect.o blit.o launchmenu.o NKLIB.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_KERNEL_LIBC = 1
USE_KERNEL_LIBS = 1
INCDIR =
CFLAGS = -Os -G0 -Wall -fno-strict-aliasing -fno-builtin-printf
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpsphprm -lpsppower -lpspsdk -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpspge -lpsprtc -lpspumd
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak