Skip to content

Instantly share code, notes, and snippets.

@Slipyx
Last active August 17, 2016 08:40
Show Gist options
  • Save Slipyx/91614ec94f2251109e67 to your computer and use it in GitHub Desktop.
Save Slipyx/91614ec94f2251109e67 to your computer and use it in GitHub Desktop.
PS1 Psy-Q SDK LIBPAD example code for controller input. No analog or actuator use yet.
// Must manually link to LIBPAD.LIB for compiling
#include <LIBPAD.H>
// Pad terminal type masks. First four bits of padData[1]
#define PADTT_DIG 0x40 // 16 button controller (no analog)
#define PADTT_ANA 0x70 // Analog controller
// All 16 16bit button bit masks. Button state bit is 0 if pressed.
#define PADLeft 0x8000
#define PADDown 0x4000
#define PADRight 0x2000
#define PADUp 0x1000
#define PADStart 0x800
#define PADR3 0x400
#define PADL3 0x200
#define PADSelect 0x100
#define PADSquare 0x80
#define PADCross 0x40
#define PADCircle 0x20
#define PADTriangle 0x10
#define PADRB1 0x8
#define PADLB1 0x4
#define PADRB2 0x2
#define PADLB2 0x1
u_char padData[34]; // Raw pad data
u_short padButtons = 0; // Complete 16bit button state from bytes 3 & 4 of padData
u_char padIsAnalog = 0; // boolean for analog detection
#define PadButtonDown( b ) ((padButtons & b) == 0)
// Initalize pad and start communicating every vblank
InitPadDirect( padData, 0 );
PadStartCom();
// In main loop
for ( ; ; ) {
// Update analog detection boolean
padIsAnalog = (padData[1] & PADTT_ANA) == PADTT_ANA;
// Merge bytes 3 & 4 of padData to a seperate 16bit button state ready for masking
padButtons = (padData[2] << 8) + padData[3];
// Since button state bit is 0 if pressed, binary and will return 0 if pressed
if ( PadButtonDown( PADLeft ) ) // Pad left is pressed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment