aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2022-01-17 15:57:04 +0100
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2022-01-17 15:57:04 +0100
commitde38196a978548b61c4b45115d24ef743b9eef90 (patch)
tree52cddb7f0f316724fa61dfdad91ee1804e29f62a
parentde9047f568f2f3509b56a2b566d7353cae616eb7 (diff)
downloadpsn00bsdk-de38196a978548b61c4b45115d24ef743b9eef90.tar.gz
Minor psxgpu/psxpad header changes
-rw-r--r--examples/io/pads/main.c37
-rw-r--r--libpsn00b/include/psxgpu.h2
-rw-r--r--libpsn00b/include/psxpad.h328
-rw-r--r--libpsn00b/psxetc/_dl_resolve_wrapper.s6
-rw-r--r--libpsn00b/psxgpu/gettimimage.c2
5 files changed, 203 insertions, 172 deletions
diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c
index 92beb1c..cc4ef56 100644
--- a/examples/io/pads/main.c
+++ b/examples/io/pads/main.c
@@ -118,16 +118,16 @@ static volatile uint8_t pad_buff[2][34];
static volatile size_t pad_buff_len[2];
static volatile uint32_t pad_digital_only[2] = { 0, 0 };
-// Just a wrapper around spi_new_request(). This does not send the command
+// Just a wrapper around SPI_CreateRequest(). This does not send the command
// immediately but adds it to the driver's request queue.
void send_pad_cmd(
- uint32_t port,
- PAD_COMMAND cmd,
- uint8_t arg1,
- uint8_t arg2,
- SPICALLBACK callback
+ uint32_t port,
+ PadCommand cmd,
+ uint8_t arg1,
+ uint8_t arg2,
+ SPI_Callback callback
) {
- SPIREQUEST *req = spi_new_request();
+ SPI_request *req = SPI_CreateRequest();
req->len = 9;
req->port = port;
@@ -150,12 +150,12 @@ void send_pad_cmd(
// actually a DualShock in digital mode by checking if it started identifying
// as CONFIG_MODE after receiving a configuration command.
void dualshock_init_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) {
- PADTYPE *pad = (PADTYPE *) buff;
+ PadResponse *pad = (PadResponse *) buff;
if (
(rx_len < 2) ||
- (pad->raw.prefix != 0x5a) ||
- (pad->raw.type != PAD_ID_CONFIG_MODE)
+ (pad->prefix != 0x5a) ||
+ (pad->type != PAD_ID_CONFIG_MODE)
) {
printf("no, pad is digital-only (len = %d)\n", rx_len);
@@ -187,7 +187,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) {
if (rx_len)
memcpy((void *) pad_buff[port], (void *) buff, rx_len);
- PADTYPE *pad = (PADTYPE *) buff;
+ PadResponse *pad = (PadResponse *) buff;
// If this pad identifies as a digital pad and hasn't been flagged as a
// digital-only pad already, attempt to put it into analog mode by entering
@@ -196,8 +196,8 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) {
// returning digital pad responses.
if (
rx_len &&
- (pad->raw.prefix == 0x5a) &&
- (pad->raw.type == PAD_ID_DIGITAL)
+ (pad->prefix == 0x5a) &&
+ (pad->type == PAD_ID_DIGITAL)
) {
if (!pad_digital_only[port]) {
printf("Detecting if pad %d supports config mode... ", port + 1);
@@ -221,7 +221,7 @@ static CONTEXT ctx;
int main(int argc, const char* argv[]) {
init_context(&ctx);
- spi_init(&poll_cb);
+ SPI_Init(&poll_cb);
uint32_t counter = 0;
@@ -238,15 +238,14 @@ int main(int argc, const char* argv[]) {
continue;
}
- PADTYPE *pad = (PADTYPE *) pad_buff[port];
- PAD_TYPEID type = pad->raw.type;
+ PadResponse *pad = (PadResponse *) pad_buff[port];
// According to nocash docs, there is a hardware bug in DualShock
// controllers that causes the prefix byte (normally 0x5a) to turn
// into 0x00 if the analog button is pressed after configuration
// commands have been used. Thus making sure the prefix is 0x5a
// isn't enough to reliably detect pads.
- /*if ((pad->raw.prefix != 0x5a) && (type != PAD_ID_ANALOG)) {
+ /*if ((pad->prefix != 0x5a) && (pad->type != PAD_ID_ANALOG)) {
FntPrint(-1, "\n\nPORT %d: INVALID RESPONSE\n", port + 1);
if ((counter % 64) < 32)
FntPrint(-1, " CHECK CONNECTION...");
@@ -258,8 +257,8 @@ int main(int argc, const char* argv[]) {
-1,
"\n\nPORT %d: %s (TYPE=%d)\n",
port + 1,
- PAD_TYPEIDS[type],
- type
+ PAD_TYPEIDS[pad->type],
+ pad->type
);
// Print a hexdump of the payload returned by the pad.
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index f50b841..f061219 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -609,7 +609,7 @@ void AddPrim(u_long* ot, void* pri);
// Function definitions (C)
-int GetTimInfo(u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */
+int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg); /* ORIGINAL */
DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h);
DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h);
diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h
index d152896..9638ec1 100644
--- a/libpsn00b/include/psxpad.h
+++ b/libpsn00b/include/psxpad.h
@@ -14,43 +14,48 @@
#ifndef _PSXPAD_H
#define _PSXPAD_H
-// Pad button definitions for digital pad, joystick, dual analog,
-// Dualshock and Jogcon
-#define PAD_SELECT 1
-#define PAD_L3 2
-#define PAD_R3 4
-#define PAD_START 8
-#define PAD_UP 16
-#define PAD_RIGHT 32
-#define PAD_DOWN 64
-#define PAD_LEFT 128
-#define PAD_L2 256
-#define PAD_R2 512
-#define PAD_L1 1024
-#define PAD_R1 2048
-#define PAD_TRIANGLE 4096
-#define PAD_CIRCLE 8192
-#define PAD_CROSS 16384
-#define PAD_SQUARE 32768
-
-// Mouse button definitions
-#define MOUSE_RIGHT 1024
-#define MOUSE_LEFT 2048
-
-// neGcon button definitions
-#define NCON_START 8
-#define NCON_UP 16
-#define NCON_RIGHT 32
-#define NCON_DOWN 64
-#define NCON_LEFT 128
-#define NCON_R 256
-#define NCON_B 512
-#define NCON_A 1024
-
-// Guncon button definitions
-#define GCON_A 8
-#define GCON_TRIGGER 8192
-#define GCON_B 16384
+#include <stdint.h>
+
+/* Controller type and button definitions */
+
+typedef enum {
+ // Standard pads, analog joystick, Jogcon
+ PAD_SELECT = 1 << 0,
+ PAD_L3 = 1 << 1,
+ PAD_R3 = 1 << 2,
+ PAD_START = 1 << 3,
+ PAD_UP = 1 << 4,
+ PAD_RIGHT = 1 << 5,
+ PAD_DOWN = 1 << 6,
+ PAD_LEFT = 1 << 7,
+ PAD_L2 = 1 << 8,
+ PAD_R2 = 1 << 9,
+ PAD_L1 = 1 << 10,
+ PAD_R1 = 1 << 11,
+ PAD_TRIANGLE = 1 << 12,
+ PAD_CIRCLE = 1 << 13,
+ PAD_CROSS = 1 << 14,
+ PAD_SQUARE = 1 << 15,
+
+ // Mouse
+ MOUSE_LEFT = 1 << 10,
+ MOUSE_RIGHT = 1 << 11,
+
+ // neGcon
+ NCON_START = 1 << 3,
+ NCON_UP = 1 << 4,
+ NCON_RIGHT = 1 << 5,
+ NCON_DOWN = 1 << 6,
+ NCON_LEFT = 1 << 7,
+ NCON_R = 1 << 8,
+ NCON_B = 1 << 9,
+ NCON_A = 1 << 10,
+
+ // Guncon
+ GCON_A = 1 << 3,
+ GCON_TRIGGER = 1 << 13,
+ GCON_B = 1 << 14
+} PadButton;
typedef enum {
PAD_ID_MOUSE = 0x1, // Sony PS1 mouse
@@ -64,9 +69,10 @@ typedef enum {
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;
+} PadTypeID;
+
+/* Pad and memory card commands */
-// 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
@@ -74,131 +80,155 @@ typedef enum {
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;
+ PAD_CMD_RESPONSE_CONFIG = 'O', // Configure response/unlock DS2 pressure (in config mode)
-// 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;
+ MCD_CMD_READ_SECTOR = 'R', // Read 128-byte sector
+ MCD_CMD_IDENTIFY = 'S', // Retrieve ID and card size information (Sony cards only)
+ MCD_CMD_WRITE_SECTOR = 'W' // Erase and write 128-byte sector
+} PadCommand;
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)
+} MemCardStatus;
+
+typedef enum {
+ MCD_FLAG_WRITE_ERROR = 1 << 2, // Last write command failed
+ MCD_FLAG_NOT_WRITTEN = 1 << 3, // No writes have been issued yet
+ MCD_FLAG_UNKNOWN = 1 << 4 // Might be set on third-party cards
+} MemCardStatusFlag;
+
+#define MEMCARD_CMD_READ_LEN 139
+#define MEMCARD_CMD_IDENTIFY_LEN 9
+#define MEMCARD_CMD_WRITE_LEN 137
+
+/* Controller response as returned by BIOS driver */
+
+typedef struct __attribute__((packed)) _PADTYPE {
+ uint8_t stat; // Status
+ uint8_t len:4; // Payload length / 2, 0 for multitap
+ uint8_t type:4; // Device type (PadTypeID)
+
+ uint16_t btn; // Button states
+ union {
+ struct { // Analog controller:
+ uint8_t rs_x,rs_y; // - Right stick coordinates
+ uint8_t ls_x,ls_y; // - Left stick coordinates
+ uint8_t press[12]; // - Button pressure (DualShock 2 only)
};
- 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
- };
+ struct { // Mouse:
+ int8_t x_mov; // - X movement of mouse
+ int8_t y_mov; // - Y movement of mouse
+ };
+ struct { // neGcon:
+ uint8_t twist; // - Controller twist
+ uint8_t btn_i; // - I button value
+ uint8_t btn_ii; // - II button value
+ uint8_t trg_l; // - L trigger value
+ };
+ struct { // Jogcon:
+ uint16_t jog_rot; // - Jog rotation
+ };
+ struct { // Guncon:
+ uint16_t gun_x; // - Gun X position in dotclocks
+ uint16_t gun_y; // - Gun Y position in scanlines
};
};
} PADTYPE;
-typedef struct _MCDRESPONSE {
- unsigned char flags; // Status flags
- unsigned char type1; // Must be 0x5a
- unsigned char type2; // Must be 0x5d
+//typedef struct _PADTYPE MOUSETYPE;
+//typedef struct _PADTYPE NCONTYPE;
+//typedef struct _PADTYPE JCONTYPE;
+//typedef struct _PADTYPE GCONTYPE;
+
+/* Raw responses */
+
+typedef struct __attribute__((packed)) _PadResponse {
+ uint8_t len:4; // Payload length / 2, 0 for multitap
+ uint8_t type:4; // Device type (PadTypeID)
+ uint8_t prefix; // Must be 0x5a
+
+ uint16_t btn; // Button states
+ union {
+ struct { // Analog controller:
+ uint8_t rs_x,rs_y; // - Right stick coordinates
+ uint8_t ls_x,ls_y; // - Left stick coordinates
+ uint8_t press[12]; // - Button pressure (DualShock 2 only)
+ };
+ struct { // Mouse:
+ int8_t x_mov; // - X movement of mouse
+ int8_t y_mov; // - Y movement of mouse
+ };
+ struct { // neGcon:
+ uint8_t twist; // - Controller twist
+ uint8_t btn_i; // - I button value
+ uint8_t btn_ii; // - II button value
+ uint8_t trg_l; // - L trigger value
+ };
+ struct { // Jogcon:
+ uint16_t jog_rot; // - Jog rotation
+ };
+ struct { // Guncon:
+ uint16_t gun_x; // - Gun X position in dotclocks
+ uint16_t gun_y; // - Gun Y position in scanlines
+ };
+ };
+} PadResponse;
+
+typedef struct __attribute__((packed)) _MemCardResponse {
+ uint8_t flags; // Status flags (MemCardStatusFlag)
+ uint8_t type1; // Must be 0x5a
+ uint8_t 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)
+ struct { // CMD_READ response:
+ uint8_t dummy[2];
+ uint8_t ack1; // Must be 0x5c
+ uint8_t ack2; // Must be 0x5d
+ uint8_t lba_h;
+ uint8_t lba_l;
+ uint8_t data[128];
+ uint8_t checksum; // = lba_h ^ lba_l ^ data
+ uint8_t stat; // Status (MemCardStatus)
} 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)
+ struct { // CMD_IDENTIFY response:
+ uint8_t ack1; // Must be 0x5c
+ uint8_t ack2; // Must be 0x5d
+ uint8_t size_h; // Card capacity bits 8-15 (0x04 = 128KB)
+ uint8_t size_l; // Card capacity bits 0-7 (0x00 = 128KB)
+ uint8_t blksize_h; // Sector size bits 8-15 (must be 0x00)
+ uint8_t 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)
+ struct { // CMD_WRITE response:
+ uint8_t dummy[131];
+ uint8_t ack1; // Must be 0x5c
+ uint8_t ack2; // Must be 0x5d
+ uint8_t stat; // Status (MemCardStatus)
} 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;
+} MemCardResponse;
+
+/* Raw requests */
+
+typedef struct __attribute__((packed)) _PadRequest {
+ uint8_t addr; // Must be 0x01 (or 02/03/04 for multitap pads)
+ uint8_t cmd; // Command (PadCommand)
+ uint8_t tap_mode; // 0x01 to enable multitap response
+ uint8_t motor_r; // Right motor control (on/off)
+ uint8_t motor_l; // Left motor control (PWM)
+ uint8_t dummy[4];
+} PadRequest;
+
+typedef struct __attribute__((packed)) _MemCardRequest {
+ uint8_t addr; // Must be 0x81 (or 02/03/04 for multitap cards)
+ uint8_t cmd; // Command (MemCardCommand)
+ uint8_t dummy[2];
+ uint8_t lba_h; // Sector address bits 8-15 (dummy for CMD_IDENTIFY)
+ uint8_t lba_l; // Sector address bits 0-7 (dummy for CMD_IDENTIFY)
+ uint8_t data[128]; // Sector payload (dummy for CMD_READ/CMD_IDENTIFY)
+ uint8_t checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only)
+ uint8_t dummy2[3];
+} MemCardRequest;
#endif \ No newline at end of file
diff --git a/libpsn00b/psxetc/_dl_resolve_wrapper.s b/libpsn00b/psxetc/_dl_resolve_wrapper.s
index 7f1132b..01ebf3a 100644
--- a/libpsn00b/psxetc/_dl_resolve_wrapper.s
+++ b/libpsn00b/psxetc/_dl_resolve_wrapper.s
@@ -48,7 +48,9 @@ _dl_resolve_wrapper:
jr $t0
nop
-.global _dl_credits
-.type _dl_credits, @object
+.section .data
+
+.global _dl_credits
+.type _dl_credits, @object
_dl_credits:
.asciiz "psxetc runtime dynamic linker by spicyjpeg\n"
diff --git a/libpsn00b/psxgpu/gettimimage.c b/libpsn00b/psxgpu/gettimimage.c
index d9cf1bf..5598e07 100644
--- a/libpsn00b/psxgpu/gettimimage.c
+++ b/libpsn00b/psxgpu/gettimimage.c
@@ -1,7 +1,7 @@
#include <sys/types.h>
#include <psxgpu.h>
-int GetTimInfo(u_long *tim, TIM_IMAGE *timimg) {
+int GetTimInfo(const u_long *tim, TIM_IMAGE *timimg) {
u_long *rtim;