Welcome to Hackers Alliance!

How your PSP gets button input

  • Archived

    The forum is archived and used for testing. It is currently read-only to visitors.
    It has been upgraded from vBulletin 3.8.x to XenForo for security purposes and future-proofing. Proprietary code and modifications (such as code database and HA bot) are broken with XenForo and will stay only with vBulletin.

-LeetGamer-

Coder
Coder
Oct 17, 2010
66
2
0
Tutorial by -LeetGamer-

This tutorial will explain how your PSP reads button input.

You need to know these things before reading this:
  • Variables
  • Enumerations
  • Structures

These are somewhat simple concepts and a quick google search can get you up to date fast, if you know any form of coding at all just read the tutorial, you should be able to get what I am saying.

The header file for this can be found at: C:\pspsdk\psp\sdk\include\pspctrl.h

-----------------------------------------------------------------------------------------------------

On line 34 we have an enumeration called PspCtrlButtons:

Code:
enum PspCtrlButtons
{
	/** Select button. */
	PSP_CTRL_SELECT     = 0x000001,
	/** Start button. */
	PSP_CTRL_START      = 0x000008,
	/** Up D-Pad button. */
	PSP_CTRL_UP         = 0x000010,
	/** Right D-Pad button. */
	PSP_CTRL_RIGHT      = 0x000020,
	/** Down D-Pad button. */
	PSP_CTRL_DOWN      	= 0x000040,
	/** Left D-Pad button. */
	PSP_CTRL_LEFT      	= 0x000080,
	/** Left trigger. */
	PSP_CTRL_LTRIGGER   = 0x000100,
	/** Right trigger. */
	PSP_CTRL_RTRIGGER   = 0x000200,
	/** Triangle button. */
	PSP_CTRL_TRIANGLE   = 0x001000,
	/** Circle button. */
	PSP_CTRL_CIRCLE     = 0x002000,
	/** Cross button. */
	PSP_CTRL_CROSS      = 0x004000,
	/** Square button. */
	PSP_CTRL_SQUARE     = 0x008000,
	/** Home button. In user mode this bit is set if the exit dialog is visible. */
	PSP_CTRL_HOME       = 0x010000,
	/** Hold button. */
	PSP_CTRL_HOLD       = 0x020000,
	/** Music Note button. */
	PSP_CTRL_NOTE       = 0x800000,
	/** Screen button. */
	PSP_CTRL_SCREEN     = 0x400000,
	/** Volume up button. */
	PSP_CTRL_VOLUP      = 0x100000,
	/** Volume down button. */
	PSP_CTRL_VOLDOWN    = 0x200000,
	/** Wlan switch up. */
	PSP_CTRL_WLAN_UP    = 0x040000,
	/** Remote hold position. */
	PSP_CTRL_REMOTE     = 0x080000,	
	/** Disc present. */
	PSP_CTRL_DISC       = 0x1000000,
	/** Memory stick present. */
	PSP_CTRL_MS         = 0x2000000,
};
As you can see every form of input on the PSP has a hex value. Most PSP MIPS coders will notice that the button values for most games are the same here. That is because this is where the button values are.

Now that the PSP has a value for each button we can just say something like PSP_CTRL_CROSS and it will know what is going on.

-----------------------------------------------------------------------------------------------------

On line 92 we have a structure:

Code:
/** Returned controller data */
typedef struct SceCtrlData {
	/** The current read frame. */
	unsigned int 	TimeStamp;
	/** Bit mask containing zero or more of ::PspCtrlButtons. */
	unsigned int 	Buttons;
	/** Analogue stick, X axis. */
	unsigned char 	Lx;
	/** Analogue stick, Y axis. */
	unsigned char 	Ly;
	/** Reserved. */
	unsigned char 	Rsrv[6];
} SceCtrlData;
This structure is returned after a button is pressed, each member of the structure has some information on what what pressed.

TimeStamp: The current read frame (Don't know much on this)
Buttons: Holds the hexadecimal value (That was in the first enum) for the button pressed
Lx: Holds the X axis for the analogs position
Ly: Holds teh Y axis for the analogs position
Rsrv [6]: N/A

-----------------------------------------------------------------------------------------------------

On line 168 we have a function:

Code:
int sceCtrlReadBufferPositive(SceCtrlData *pad_data, int count);
This fuction is going to get a pointer of the SceCtrlData structure you made (its made like this:

Code:
SceCtrlData pad; // or use what ever name you want, most people use "pad"
)

and we need this argument so the function knows where to return the pad data. The count is usually set to 1

This functions job is to return the structure called "SceCtrlData", which I showed above, and then we can use a if statement like I am about to show you

-----------------------------------------------------------------------------------------------------

After this the game/homebrew uses some code like this:

if (pad.Buttons & PSP_CTRL_CROSS)
{
sceKernelExitGame ();
}

that code will exit to the xmb from the game/homebrew once you press X.

-----------------------------------------------------------------------------------------------------

Well, that is it. Now you know how your PSP checks button input. Kinda pointless to know if you don't program for the PSP, but whatever :p

If I left out anything or had any errors please let me know.
 
This site has been archived and is no longer accepting new content.

About us

  • Hackers Alliance is a small community forum about gaming and console hacking. Join our humble community to share ideas, game cheats, mods, and be part of an amazing growing community!

Quick Navigation

User Menu