aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2021-11-22 14:40:59 +0800
committerGitHub <noreply@github.com>2021-11-22 14:40:59 +0800
commit45123e1b968d1883fed9b8526157ce2c4bffc4a7 (patch)
treed20c80fbd4f5a5d1d3972669625972cea6b3684d /libpsn00b/include
parent538f28cfbbbb8163ab8a96de77d6887123856c81 (diff)
parent9b00e5f7ff163a8fc6f341dbf237d90c61dadddc (diff)
downloadpsn00bsdk-45123e1b968d1883fed9b8526157ce2c4bffc4a7.tar.gz
Merge pull request #43 from spicyjpeg/cmake
Even more CMake fixes, submodules, pads example
Diffstat (limited to 'libpsn00b/include')
-rw-r--r--libpsn00b/include/malloc.h14
-rw-r--r--libpsn00b/include/psxapi.h32
-rw-r--r--libpsn00b/include/psxpad.h203
-rw-r--r--libpsn00b/include/stdint.h16
-rw-r--r--libpsn00b/include/stdlib.h28
-rw-r--r--libpsn00b/include/sys/types.h16
6 files changed, 213 insertions, 96 deletions
diff --git a/libpsn00b/include/malloc.h b/libpsn00b/include/malloc.h
index d94823f..75c3711 100644
--- a/libpsn00b/include/malloc.h
+++ b/libpsn00b/include/malloc.h
@@ -1,18 +1,8 @@
#ifndef _MALLOC_H
#define _MALLOC_H
-#ifdef __cplusplus
-extern "C" {
-#endif
+#warning "<malloc.h> is deprecated, include <stdlib.h> instead"
-unsigned int *GetBSSend();
-void InitHeap(unsigned int *addr, int size);
-int SetHeapSize(int size);
-void *malloc(int size);
-void free(void *ptr);
-
-#ifdef __cplusplus
-}
-#endif
+#include <stdlib.h>
#endif // _MALLOC_H \ No newline at end of file
diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h
index 9e92568..ec0dfea 100644
--- a/libpsn00b/include/psxapi.h
+++ b/libpsn00b/include/psxapi.h
@@ -32,6 +32,35 @@
#define RCntMdFR 0x0000
#define RCntMdGATE 0x0010
+typedef struct { // Thread control block
+ int status;
+ int mode;
+ union {
+ unsigned int reg[37];
+ struct {
+ unsigned int zero, at;
+ unsigned int v0, v1;
+ unsigned int a0, a1, a2, a3;
+ unsigned int t0, t1, t2, t3, t4, t5, t6, t7;
+ unsigned int s0, s1, s2, s3, s4, s5, s6, s7;
+ unsigned int t8, t9;
+ unsigned int k0, k1;
+ unsigned int gp, sp, fp, ra;
+
+ unsigned int cop0r14;
+ unsigned int hi;
+ unsigned int lo;
+ unsigned int cop0r12;
+ unsigned int cop0r13;
+ };
+ };
+ int _reserved[9];
+} TCB;
+
+typedef struct { // Process control block
+ TCB *thread;
+} PCB;
+
typedef struct { // Device control block
char *name;
int flags;
@@ -182,6 +211,9 @@ void ChangeClearRCnt(int t, int m);
int Exec(struct EXEC *exec, int argc, char **argv);
void FlushCache(void);
+// Misc functions
+int GetSystemInfo(int index);
+
void _boot(void);
#ifdef __cplusplus
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
diff --git a/libpsn00b/include/stdint.h b/libpsn00b/include/stdint.h
new file mode 100644
index 0000000..83acb00
--- /dev/null
+++ b/libpsn00b/include/stdint.h
@@ -0,0 +1,16 @@
+#ifndef _STDINT_H
+#define _STDINT_H
+
+typedef unsigned int size_t;
+
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+
+#endif // _STDINT_H \ No newline at end of file
diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h
index 474eba6..de3ab47 100644
--- a/libpsn00b/include/stdlib.h
+++ b/libpsn00b/include/stdlib.h
@@ -19,34 +19,16 @@ extern long atol(char *s);
extern char atob(char *s); // Is this right?
*/
-// Random number functions (not yet implemented)
-
-/*
-int rand();
-void srand(unsigned int seed);
-*/
-
// Quick sort (not yet implemented)
//void qsort(void *base , int nel , int width , int (*cmp)(const void *,const void *));
-// Memory allocation functions (not yet implemented, avoid using BIOS as they are reportedly buggy)
-
-/*
-#warning "malloc() family of functions NEEDS MORE TESTING"
-
-void *malloc(int size);
-void free(void *buf);
-void *calloc(int number, int size);
-void *realloc(void *buf , int n);
-*/
-
#ifdef __cplusplus
extern "C" {
#endif
extern int __argc;
-extern char __argv[];
+extern const char **__argv;
int rand();
void srand(unsigned long seed);
@@ -64,6 +46,14 @@ long atol(const char *s);
double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
+// Memory allocation functions
+unsigned int *GetBSSend();
+void InitHeap(unsigned int *addr, int size);
+int SetHeapSize(int size);
+void *malloc(int size);
+void *calloc(int number, int size);
+void free(void *ptr);
+
#ifdef __cplusplus
}
#endif
diff --git a/libpsn00b/include/sys/types.h b/libpsn00b/include/sys/types.h
index aee197e..da43590 100644
--- a/libpsn00b/include/sys/types.h
+++ b/libpsn00b/include/sys/types.h
@@ -1,21 +1,13 @@
#ifndef _TYPES_H
#define _TYPES_H
+//#warning "<sys/types.h> and u_* types are deprecated, include <stdint.h> instead"
+
+//#include <stdint.h>
+
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
-typedef unsigned int size_t;
-
-typedef char int8_t;
-typedef short int16_t;
-typedef int int32_t;
-typedef long long int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long uint64_t;
-
#endif // _TYPES_H \ No newline at end of file