aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-07 18:57:48 +0100
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-07 18:57:48 +0100
commitb3ef4c5874f579c968f2d26843d0db420e9ed40e (patch)
tree85f60b460901bfe14b1cb6b30eeedadd6398eee3 /libpsn00b/include
parentc377ec612422ac82afe034d92eedb45fb8a17a39 (diff)
downloadpsn00bsdk-b3ef4c5874f579c968f2d26843d0db420e9ed40e.tar.gz
Added io/pads example, psxpad.h definitions, bugfixes
Diffstat (limited to 'libpsn00b/include')
-rw-r--r--libpsn00b/include/psxpad.h203
1 files changed, 150 insertions, 53 deletions
diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h
index 01aff06..d152896 100644
--- a/libpsn00b/include/psxpad.h
+++ b/libpsn00b/include/psxpad.h
@@ -3,10 +3,12 @@
* 2019 Lameguy64 / Meido-Tek Productions
*
* Currently only provides a bunch of definitions and a few structs but no
- * handling functions yet. Use the code in pad.s in one of the sample
- * programs for the meantime instead.
+ * handling functions yet. See the io/pads example for a simple manual pollling
+ * implementation (with support for DualShock 2 controllers).
*
* Work in progress, subject to change significantly in future releases.
+ *
+ * Reference: https://gist.github.com/scanlime/5042071
*/
#ifndef _PSXPAD_H
@@ -50,58 +52,153 @@
#define GCON_TRIGGER 8192
#define GCON_B 16384
-// Struct for digital, joystick, dual analog and Dualshock controllers
-typedef struct {
- unsigned char stat; // Status
- unsigned char len:4; // Data length (in halfwords)
- unsigned char type:4; // Device type:
- // 0x4 - digital pad
- // 0x5 - analog joystick
- // 0x7 - dual analog & Dualshock
- unsigned short btn; // Button states
- unsigned char rs_x,rs_y; // Right stick coordinates
- unsigned char ls_x,ls_y; // Left stick coordinates
+typedef enum {
+ PAD_ID_MOUSE = 0x1, // Sony PS1 mouse
+ PAD_ID_NEGCON = 0x2, // Namco neGcon
+ PAD_ID_IRQ10_GUN = 0x3, // "Konami" lightgun without composite video passthrough
+ PAD_ID_DIGITAL = 0x4, // Digital pad or Dual Analog/DualShock in digital mode
+ PAD_ID_ANALOG_STICK = 0x5, // Flight stick or Dual Analog in green LED mode
+ PAD_ID_GUNCON = 0x6, // Namco Guncon (lightgun with composite video passthrough)
+ PAD_ID_ANALOG = 0x7, // Dual Analog/DualShock in analog (red LED) mode
+ PAD_ID_MULTITAP = 0x8, // Multitap adapter (when tap_mode == 1)
+ PAD_ID_JOGCON = 0xe, // Namco Jogcon
+ PAD_ID_CONFIG_MODE = 0xf, // Dual Analog/DualShock in config mode (if len == 0x3)
+ PAD_ID_NONE = 0xf // No pad connected (if len == 0xf)
+} PAD_TYPEID;
+
+// Controller command definitions
+typedef enum {
+ PAD_CMD_INIT_PRESSURE = '@', // Initialize DS2 button pressure sensors (in config mode)
+ PAD_CMD_READ = 'B', // Read pad state and set rumble
+ PAD_CMD_CONFIG_MODE = 'C', // Toggle DualShock configuration mode
+ PAD_CMD_SET_ANALOG = 'D', // Set analog mode/LED state (in config mode)
+ PAD_CMD_GET_ANALOG = 'E', // Get analog mode/LED state (in config mode)
+ PAD_CMD_REQUEST_CONFIG = 'M', // Configure request/unlock vibration (in config mode)
+ PAD_CMD_RESPONSE_CONFIG = 'O' // Configure response/unlock DS2 pressure (in config mode)
+} PAD_COMMAND;
+
+// Memory card command/response definitions
+typedef enum {
+ MCD_CMD_READ = 'R', // Read sector
+ MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information
+ MCD_CMD_WRITE = 'W' // Write sector
+} MCD_COMMAND;
+
+typedef enum {
+ MCD_STAT_OK = 'G',
+ MCD_STAT_BAD_CHECKSUM = 'N',
+ MCD_STAT_BAD_SECTOR = 0xff
+} MCD_STATUS;
+
+#define MCD_CMD_READ_LEN 139
+#define MCD_CMD_IDENTIFY_LEN 9
+#define MCD_CMD_WRITE_LEN 137
+
+// Memory card status flags
+#define MCD_FLAG_WRITE_ERROR 4 // Last write command failed
+#define MCD_FLAG_NOT_WRITTEN 8 // No writes have been issued yet
+#define MCD_FLAG_UNKNOWN 16 // Might be set on third-party cards
+
+// Struct for data returned by controllers
+typedef struct _PADTYPE {
+ union { // Header:
+ struct __attribute__((packed)) { // When parsing data returned by BIOS:
+ unsigned char stat; // Status
+ unsigned char len:4; // Payload length / 2, 0 for multitap
+ unsigned char type:4; // Device type (PAD_TYPEID)
+ };
+ struct __attribute__((packed)) { // When parsing raw controller response:
+ unsigned char len:4; // Payload length / 2, 0 for multitap
+ unsigned char type:4; // Device type (PAD_TYPEID)
+ unsigned char prefix; // Must be 0x5a
+ } raw;
+ };
+ struct { // Payload:
+ unsigned short btn; // Button states
+ union {
+ struct { // Analog controller:
+ unsigned char rs_x,rs_y; // Right stick coordinates
+ unsigned char ls_x,ls_y; // Left stick coordinates
+ unsigned char press[12]; // Button pressure (DualShock 2 only)
+ };
+ struct { // Mouse:
+ char x_mov; // X movement of mouse
+ char y_mov; // Y movement of mouse
+ };
+ struct { // neGcon:
+ unsigned char twist; // Controller twist
+ unsigned char btn_i; // I button value
+ unsigned char btn_ii; // II button value
+ unsigned char trg_l; // L trigger value
+ };
+ struct { // Jogcon:
+ unsigned short jog_rot; // Jog rotation
+ };
+ struct { // Guncon:
+ unsigned short gun_x; // Gun X position in dotclocks
+ unsigned short gun_y; // Gun Y position in scanlines
+ };
+ };
+ };
} PADTYPE;
-// Struct for a mouse controller
-typedef struct {
- unsigned char stat;
- unsigned char len:4;
- unsigned char type:4; // Device type (0x1)
- unsigned short btn;
- char x_mov; // X movement of mouse
- char y_mov; // Y movement of mouse
-} MOUSETYPE;
-
-// Struct for a neGcon controller (for Namco neGcon)
-typedef struct {
- unsigned char stat;
- unsigned char len:4;
- unsigned char type:4; // (0x2)
- unsigned short btn;
- unsigned char twist; // Controller twist
- unsigned char btn_i; // I button value
- unsigned char btn_ii; // II button value
- unsigned char trg_l; // L trigger value
-} NCONTYPE;
-
-// Struct for a Jogcon controller (for Namco Jogcon)
-typedef struct {
- unsigned char stat;
- unsigned char len:4;
- unsigned char type:4; // (0xE)
- unsigned short btn;
- unsigned short jog_rot; // Jog rotation
-} JCONTYPE;
-
-// Struct for a Gun-Con controller (for Namco Gun-Con)
-typedef struct {
- unsigned char status;
- unsigned char len:4;
- unsigned char type:4; // (0x6)
- unsigned short btn;
- unsigned short gun_x; // Gun X position in dotclocks
- unsigned short gun_y; // Gun Y position in scanlines
-} GCONTYPE;
+typedef struct _MCDRESPONSE {
+ unsigned char flags; // Status flags
+ unsigned char type1; // Must be 0x5a
+ unsigned char type2; // Must be 0x5d
+ union {
+ struct { // MCD_CMD_READ response:
+ unsigned char dummy[2];
+ unsigned char ack1; // Must be 0x5c
+ unsigned char ack2; // Must be 0x5d
+ unsigned char lba_h;
+ unsigned char lba_l;
+ unsigned char data[128];
+ unsigned char checksum; // = lba_h ^ lba_l ^ data
+ unsigned char stat; // Status (MCD_STATUS)
+ } read;
+ struct { // MCD_CMD_IDENTIFY response:
+ unsigned char ack1; // Must be 0x5c
+ unsigned char ack2; // Must be 0x5d
+ unsigned char size_h; // Card capacity bits 8-15 (0x04 = 128KB)
+ unsigned char size_l; // Card capacity bits 0-7 (0x00 = 128KB)
+ unsigned char blksize_h; // Sector size bits 8-15 (must be 0x00)
+ unsigned char blksize_l; // Sector size bits 0-7 (must be 0x80)
+ } identify;
+ struct { // MCD_CMD_WRITE response:
+ unsigned char dummy[131];
+ unsigned char ack1; // Must be 0x5c
+ unsigned char ack2; // Must be 0x5d
+ unsigned char stat; // Status (MCD_STATUS)
+ } write;
+ };
+} MCDRESPONSE;
+
+//typedef PADTYPE MOUSETYPE;
+//typedef PADTYPE NCONTYPE;
+//typedef PADTYPE JCONTYPE;
+//typedef PADTYPE GCONTYPE;
+
+// Structs for raw controller request
+typedef struct _PADREQUEST {
+ unsigned char addr; // Must be 0x01 (or 02/03/04 for multitap pads)
+ unsigned char cmd; // Command (PAD_COMMAND)
+ unsigned char tap_mode; // 0x01 to enable multitap response
+ unsigned char motor_r; // Right motor control (on/off)
+ unsigned char motor_l; // Left motor control (PWM)
+ unsigned char dummy[4];
+} PADREQUEST;
+
+// Structs for raw memory card request
+typedef struct _MCDREQUEST {
+ unsigned char addr; // Must be 0x81 (or 02/03/04 for multitap cards)
+ unsigned char cmd; // Command (MCD_COMMAND)
+ unsigned char dummy[2];
+ unsigned char lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY)
+ unsigned char lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY)
+ unsigned char data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY)
+ unsigned char checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only)
+ unsigned char dummy2[3];
+} MCDREQUEST;
#endif \ No newline at end of file