coastline 0.0.4
Loading...
Searching...
No Matches
controller.h
Go to the documentation of this file.
1#ifndef LIBULTRA_IO_CONTROLLER_H
2#define LIBULTRA_IO_CONTROLLER_H
3
9
10#include <ultra64.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16/* Commands of the joybus. */
17#define CONT_CMD_REQUEST_STATUS 0
18#define CONT_CMD_READ_BUTTON 1
19#define CONT_CMD_READ_MEMPACK 2
20#define CONT_CMD_WRITE_MEMPACK 3
21#define CONT_CMD_RESET 0xFF
22
23/* The bytes each command sends and receives. */
24#define CONT_CMD_REQUEST_STATUS_TX 1
25#define CONT_CMD_REQUEST_STATUS_RX 3
26#define CONT_CMD_READ_BUTTON_TX 1
27#define CONT_CMD_READ_BUTTON_RX 4
28#define CONT_CMD_READ_MEMPACK_TX 3
29#define CONT_CMD_READ_MEMPACK_RX 33
30#define CONT_CMD_WRITE_MEMPACK_TX 35
31#define CONT_CMD_WRITE_MEMPACK_RX 1
32
33/* Bytes of the PIF RAM that are not commands. */
34#define CONT_CMD_EXE 1
35#define CONT_CMD_NOP 0xFF
36#define CONT_CMD_END 0xFE
37
39#define CHNL_ERR(format) (((format).rxsize & 0xC0) >> 4)
40
41/* The layout of the Controller Pak, read and written in blocks of 32 bytes. */
42#define BLOCKSIZE 32
43#define PFS_ONE_PAGE 8
44#define PFS_ID_0AREA 1
45#define PFS_ID_1AREA 3
46#define PFS_ID_2AREA 4
47#define PFS_ID_3AREA 6
48#define PFS_LABEL_AREA 7
49#define PFS_BANK_LAPPED_BY 0x400
50#define PFS_MAX_BANKS 62
51#define PFS_INODE_SIZE_PER_PAGE 128
52#define DEF_DIR_PAGES 2
53
54/* Page table entries with special meanings. */
55#define PFS_EOF 1
56#define PFS_PAGE_NOT_USED 3
57
59#define DIR_STATUS_OCCUPIED 0x02
60
62#define MOTOR_ADDRESS 0x600
63
65#define ERRCK(fn) \
66 ret = (fn); \
67 if (ret != 0) { \
68 return ret; \
69 }
70
72#define SET_ACTIVEBANK_TO_ZERO \
73 if (pfs->activebank != 0) { \
74 pfs->activebank = 0; \
75 ERRCK(__osPfsSelectBank(pfs)); \
76 }
77
79typedef struct {
82} OSPifRam;
83
84typedef struct {
85 u8 dummy;
86 u8 txsize;
87 u8 rxsize;
88 u8 cmd;
89 u8 typeh;
90 u8 typel;
91 u8 status;
92 u8 dummy1;
93} __OSContRequesFormat;
94
95typedef struct {
96 u8 dummy;
97 u8 txsize;
98 u8 rxsize;
99 u8 cmd;
100 u16 button;
101 s8 stick_x;
102 s8 stick_y;
103} __OSContReadFormat;
104
105typedef struct {
106 u8 dummy;
107 u8 txsize;
108 u8 rxsize;
109 u8 cmd;
110 u16 address;
111 u8 data[BLOCKSIZE];
112 u8 datacrc;
113} __OSContRamReadFormat;
114
115typedef struct {
116 u32 repaired;
117 u32 random;
118 u64 serial_mid;
119 u64 serial_low;
120 u16 deviceid;
121 u8 banks;
122 u8 version;
123 u16 checksum;
124 u16 inverted_checksum;
126} __OSPackId;
127
128typedef union {
129 struct {
130 u8 bank;
131 u8 page;
132 } inode_t;
133 u16 ipage;
134} __OSInodeUnit;
135
136typedef struct {
137 __OSInodeUnit inode_page[128];
138} __OSInode;
139
140typedef struct {
141 u32 game_code;
142 u16 company_code;
143 __OSInodeUnit start_page;
144 u8 status;
145 s8 reserved;
146 u16 data_sum;
147 u8 ext_name[4];
148 u8 game_name[16];
149} __OSDir;
150
151typedef struct {
152 __OSInode inode;
153 u8 bank;
154 u8 map[256];
155} __OSInodeCache;
156
163extern OSPifRam __osContPifRam;
164
171extern OSPifRam __osPfsPifRam;
172
179extern u8 __osContLastCmd;
180
187extern u8 __osMaxControllers;
188
195extern u32 __osContinitialized;
196
203extern OSMesgQueue __osEepromTimerQ;
204
211extern OSMesg __osEepromTimerMsg;
212
219extern OSPifRam _MotorStopData[MAXCONTROLLERS];
220
227extern OSPifRam _MotorStartData[MAXCONTROLLERS];
228
235extern u8 _motorstopbuf[BLOCKSIZE];
236
243extern u8 _motorstartbuf[BLOCKSIZE];
244
251void __osContGetInitData(u8 *pattern, OSContStatus *data);
252
259void __osPackRequestData(u8 cmd);
260
267void __osPackReadData(void);
268
275u8 __osContAddressCrc(u16 addr);
276
283u8 __osContDataCrc(u8 *data);
284
291s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer);
292
299void __osPackRamReadData(int channel, u16 address);
300
307s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force);
308
315void __osPackRamWriteData(int channel, u16 address, u8 *buffer);
316
323s32 __osPfsGetStatus(OSMesgQueue *queue, int channel);
324
331void __osPfsRequestData(u8 cmd);
332
339void __osPfsGetInitData(u8 *pattern, OSContStatus *data);
340
347u16 __osSumcalc(u8 *ptr, int length);
348
355s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum);
356
363s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid);
364
371s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp);
372
379s32 __osGetId(OSPfs *pfs);
380
387s32 __osCheckId(OSPfs *pfs);
388
395s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank);
396
403s32 __osPfsSelectBank(OSPfs *pfs);
404
405#if TGR_REGION == TGR_REGION_JP || TGR_REGION == TGR_REGION_EU
406/* The joybus commands of the EEPROM. */
407#define CONT_CMD_READ_EEPROM 4
408#define CONT_CMD_WRITE_EEPROM 5
409
410/* The bytes each EEPROM command sends and receives. */
411#define CONT_CMD_READ_EEPROM_TX 2
412#define CONT_CMD_READ_EEPROM_RX 8
413#define CONT_CMD_WRITE_EEPROM_TX \
414 10
415
416#define CONT_CMD_WRITE_EEPROM_RX 1
417
418typedef struct {
419 u8 txsize;
420 u8 rxsize;
422 u8 cmd;
423 u8 address;
424 u8 data[EEPROM_BLOCK_SIZE];
425} __OSContEepromFormat;
426
431extern OSPifRam __osEepPifRam;
432
437extern OSTimer __osEepromTimer;
438
443void __osPackEepWriteData(u8 address, u8 *buffer);
444
449s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data);
450
455void __osPackEepReadData(u8 address);
456#endif /* TGR_REGION == TGR_REGION_JP || TGR_REGION == TGR_REGION_EU */
457
458#ifdef __cplusplus
459}
460#endif
461
462#endif /* LIBULTRA_IO_CONTROLLER_H */
T data(T... args)
#define BLOCKSIZE
Definition controller.h:42
struct OSTimer_s OSTimer
A timer that sends a message when it expires, once or periodically.
struct OSMesgQueue_s OSMesgQueue
A message queue: a ring of messages and the threads blocked sending or receiving.
void * OSMesg
Definition os.h:73
#define EEPROM_BLOCK_SIZE
The bytes of a block of the EEPROM.
Definition os_cont.h:420
#define MAXCONTROLLERS
The ports of the console.
Definition os_cont.h:17
What osContInit() learns of a controller.
Definition os_cont.h:98
An open Controller Pak.
Definition os_cont.h:115
The 64 bytes of the PIF RAM.
Definition controller.h:79
u32 ramarray[15]
Definition controller.h:80
u32 pifstatus
Definition controller.h:81
Umbrella header of the reconstructed libultra.
unsigned int u32
Definition ultratypes.h:20
signed char s8
Definition ultratypes.h:23
unsigned short u16
Definition ultratypes.h:19
int s32
Definition ultratypes.h:25
unsigned long long u64
Definition ultratypes.h:21
unsigned char u8
Definition ultratypes.h:18