8/01/2006

USBSample for USB4eLoaderGTA Released

with "USB for eLoader GTA"
you can also add USB mode to your app :)

main.c

/*
 * USBSample for USB4eLoaderGTA v1.01 by 0okm
 * Thanks hitchhikr, John_K & PSPPet
 */
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <string.h>

#include <pspusb.h>
#include <pspusbstor.h>

PSP_MODULE_INFO("USBSample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);

/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

//make this global so we can check it in the exit_callback
u32 state;

int main(void)
{
    u32 oldButtons = 0;
    u32 retVal;
    state = 0;

    pspDebugScreenInit();
    pspDebugScreenClear();

    //setup Pad
    SceCtrlData pad;
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(0);

    //print header now in case we have any errors
    printf("USBSample for USB4eLoaderGTA v1.01 by 0okm\n");
    printf("Thanks hitchhikr, John_K & PSPPet\n\n");

    retVal = 0;

    //if everything worked we now enter our main loop
    for (;;)
    {
        sceCtrlReadBufferPositive(&pad, 1);
        state = sceUsbGetState();
        pspDebugScreenSetXY(0, 3);
        printf("%-14s: %s\n", "USB Driver", state & PSP_USB_ACTIVATED ? "activated     " : "deactivated");
        printf("%-14s: %s\n", "USB Cable", state & PSP_USB_CABLE_CONNECTED ? "connected    " : "disconnected");
        printf("%-14s: %s\n", "USB Connection", state & PSP_USB_CONNECTION_ESTABLISHED ? "established" : "not present");
        printf("\nPress X to establish or destroy the USB connection\n");
        printf("\nPress O to Exit\n\n");

        if (oldButtons != pad.Buttons)
        {
            if (pad.Buttons & PSP_CTRL_CROSS)
            {
                if (state & PSP_USB_ACTIVATED)
                    retVal = sceUsbDeactivate(0x1c8);
                else
                    retVal = sceUsbActivate(0x1c8);
            }
            if (pad.Buttons & PSP_CTRL_CIRCLE)
            {
                //cleanup drivers
                if (state & PSP_USB_ACTIVATED)
                {
                    retVal = sceUsbDeactivate(0);
                    if (retVal != 0)
                        sceDisplayWaitVblankStart();
                        printf("Error calling sceUsbDeactivate (0x%08X)\n", retVal);
                }
                sceKernelExitGame();
            }
        }
        oldButtons = pad.Buttons;
        sceDisplayWaitVblankStart();
    }

    sceKernelExitGame();
    return 0;
}


Makefile

TARGET = USBSample
OBJS = main.o

INCDIR = 
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LIBS = -lpspusb -lpspusbstor
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = USBSample for USB4eLoaderGTA
PSP_EBOOT_ICON = ICON0.PNG

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

0 Comments:

Post a Comment

<< Home