Code: Select all
#include <oslib/oslib.h>
#include "usb.h"
u32 state;
u32 retVal;
__attribute__ ((constructor))
void loaderInit()
{
pspKernelSetKernelPC();
pspSdkInstallNoDeviceCheckPatch();
pspDebugInstallKprintfHandler(NULL);
}
//helper function to make things easier
int LoadStartModule(char *path)
{
u32 loadResult;
u32 startResult;
int status;
loadResult = sceKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000)
return -1;
else
startResult =
sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
if (loadResult != startResult)
return -2;
return 0;
}
void StartModules()
{
state = 0;
//start necessary drivers
LoadStartModule("flash0:/kd/semawm.prx");
LoadStartModule("flash0:/kd/usbstor.prx");
LoadStartModule("flash0:/kd/usbstormgr.prx");
LoadStartModule("flash0:/kd/usbstorms.prx");
LoadStartModule("flash0:/kd/usbstorboot.prx");
//setup USB drivers
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Bus driver (0x%08X)\n", retVal);
sceKernelSleepThread();
}
retVal = sceUsbStart(PSP_USBSTOR_DRIVERNAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = sceUsbstorBootSetCapacity(0x800000);
if (retVal != 0) {
printf
("Error setting capacity with USB Mass Storage driver (0x%08X)\n",
retVal);
sceKernelSleepThread();
}
retVal = 0;
}
void USB()
{
state = sceUsbGetState();
if (state & PSP_USB_CABLE_CONNECTED) {
if (state & PSP_USB_ACTIVATED) {
//I'll add image blitting later
} else {
retVal = sceUsbActivate(0x1c8);
}
} else if (state & !PSP_USB_CABLE_CONNECTED) {
if (state & !PSP_USB_ACTIVATED) {
//do nothing!
} else {
retVal = sceUsbDeactivate(0x1c8);
}
}
}
Code: Select all
PSP_MODULE_INFO("Blah", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
If you need to see the whole source, I can give it to you, but I'm pretty sure there is something wrong with the usb.cpp file.
Another thing, Is there a quicker way of activating the usb, or is this the fastest way there is?