Mario Kart 64
Loading...
Searching...
No Matches
controller.h
Go to the documentation of this file.
1#ifndef _CONTROLLER_H
2#define _CONTROLLER_H
3#include <PR/os_internal.h>
4#include <PR/os.h>
5#include <PR/rcp.h>
6
7// should go somewhere else but
8#define ARRLEN(x) ((s32) (sizeof(x) / sizeof(x[0])))
9#define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4)
10
11typedef struct {
12 /* 0x0 */ u32 ramarray[15];
13 /* 0x3C */ u32 pifstatus;
14} OSPifRam;
15
16typedef struct {
17 /* 0x0 */ u8 dummy;
18 /* 0x1 */ u8 txsize;
19 /* 0x2 */ u8 rxsize;
20 /* 0x3 */ u8 cmd;
21 /* 0x4 */ u16 button;
22 /* 0x6 */ s8 stick_x;
23 /* 0x7 */ s8 stick_y;
25
26typedef struct {
27 /* 0x0 */ u8 dummy;
28 /* 0x1 */ u8 txsize;
29 /* 0x2 */ u8 rxsize;
30 /* 0x3 */ u8 cmd;
31 /* 0x4 */ u8 typeh;
32 /* 0x5 */ u8 typel;
33 /* 0x6 */ u8 status;
34 /* 0x7 */ u8 dummy1;
36
37typedef struct {
38 /* 0x0 */ u8 txsize;
39 /* 0x1 */ u8 rxsize;
40 /* 0x2 */ u8 cmd;
41 /* 0x3 */ u8 typeh;
42 /* 0x4 */ u8 typel;
43 /* 0x5 */ u8 status;
45
46typedef struct {
47 /* 0x0 */ u8 dummy;
48 /* 0x1 */ u8 txsize;
49 /* 0x2 */ u8 rxsize;
50 /* 0x3 */ u8 cmd;
51 /* 0x4 */ u16 address;
52 /* 0x6 */ u8 data[BLOCKSIZE];
53 /* 0x26 */ u8 datacrc;
55
56typedef union {
57 /* 0x0 */ struct {
58 /* 0x0 */ u8 bank;
59 /* 0x1 */ u8 page;
60 } inode_t;
61 /* 0x0 */ u16 ipage;
63
64typedef struct {
65 /* 0x0 */ u32 game_code;
66 /* 0x4 */ u16 company_code;
68 /* 0x8 */ u8 status;
69 /* 0x9 */ s8 reserved;
70 /* 0xA */ u16 data_sum;
71 /* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN];
72 /* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN];
73} __OSDir;
74
75typedef struct {
76 /* 0x0 */ __OSInodeUnit inode_page[128];
77} __OSInode;
78
79typedef struct {
80 /* 0x0 */ u32 repaired;
81 /* 0x4 */ u32 random;
82 /* 0x8 */ u64 serial_mid;
83 /* 0x10 */ u64 serial_low;
84 /* 0x18 */ u16 deviceid;
85 /* 0x1A */ u8 banks;
86 /* 0x1B */ u8 version;
87 /* 0x1C */ u16 checksum;
90
91typedef struct {
92 /* 0x0 */ u8 txsize;
93 /* 0x1 */ u8 rxsize;
94 /* 0x2 */ u8 cmd;
95 /* 0x3 */ u8 address;
96 /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE];
98
99// from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage
100#define CONT_CMD_REQUEST_STATUS 0
101#define CONT_CMD_READ_BUTTON 1
102#define CONT_CMD_READ_MEMPACK 2
103#define CONT_CMD_WRITE_MEMPACK 3
104#define CONT_CMD_READ_EEPROM 4
105#define CONT_CMD_WRITE_EEPROM 5
106#define CONT_CMD_RESET 0xff
107
108#define CONT_CMD_REQUEST_STATUS_TX 1
109#define CONT_CMD_READ_BUTTON_TX 1
110#define CONT_CMD_READ_MEMPACK_TX 3
111#define CONT_CMD_WRITE_MEMPACK_TX 35
112#define CONT_CMD_READ_EEPROM_TX 2
113#define CONT_CMD_WRITE_EEPROM_TX 10
114#define CONT_CMD_RESET_TX 1
115
116#define CONT_CMD_REQUEST_STATUS_RX 3
117#define CONT_CMD_READ_BUTTON_RX 4
118#define CONT_CMD_READ_MEMPACK_RX 33
119#define CONT_CMD_WRITE_MEMPACK_RX 1
120#define CONT_CMD_READ_EEPROM_RX 8
121#define CONT_CMD_WRITE_EEPROM_RX 1
122#define CONT_CMD_RESET_RX 3
123
124#define CONT_CMD_NOP 0xff
125#define CONT_CMD_END 0xfe // indicates end of a command
126#define CONT_CMD_EXE 1 // set pif ram status byte to this to do a command
127
128#define DIR_STATUS_EMPTY 0
129#define DIR_STATUS_UNKNOWN 1
130#define DIR_STATUS_OCCUPIED 2
131
132typedef struct {
133 /* 0x0 */ __OSInode inode;
134 /* 0x100 */ u8 bank;
135 /* 0x101 */ u8 map[256];
137
138extern s32 __osEepStatus(OSMesgQueue*, OSContStatus*);
139u16 __osSumcalc(u8* ptr, int length);
140s32 __osIdCheckSum(u16* ptr, u16* csum, u16* icsum);
141s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid);
142s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp);
143s32 __osGetId(OSPfs* pfs);
144s32 __osCheckId(OSPfs* pfs);
145s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank);
146s32 __osPfsSelectBank(OSPfs* pfs);
147s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared,
148 int* last_page);
149s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 start_page, u16* sum, u8 bank, __OSInodeUnit* last_page,
150 int flag);
151s32 __osBlockSum(OSPfs* pfs, u8 page_no, u16* sum, u8 bank);
152s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer);
153s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force);
154void __osContGetInitData(u8* bitpattern, OSContStatus* status);
155void __osPackRequestData(u8 command);
156void __osPfsRequestData(u8 cmd);
157void __osPfsGetInitData(u8* pattern, OSContStatus* data);
159u8 __osContDataCrc(u8* data);
160s32 __osPfsGetStatus(OSMesgQueue* queue, int channel);
161
162extern u8 __osContLastCmd;
164extern OSMesg __osEepromTimerMsg;
165extern OSMesgQueue __osEepromTimerQ;
170
171// some version of this almost certainly existed since there's plenty of times where it's used right before a return 0
172#define ERRCK(fn) \
173 ret = fn; \
174 if (ret != 0) \
175 return ret;
176
177#define SET_ACTIVEBANK_TO_ZERO \
178 if (pfs->activebank != 0) { \
179 pfs->activebank = 0; \
180 ERRCK(__osPfsSelectBank(pfs)) \
181 }
182
183#define PFS_CHECK_ID \
184 if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \
185 return PFS_ERR_NEW_PACK;
186#endif
187
188#define PFS_CHECK_STATUS \
189 if ((pfs->status & PFS_INITIALIZED) == 0) \
190 return PFS_ERR_INVALID;
191
192#define PFS_GET_STATUS \
193 __osSiGetAccess(); \
194 ret = __osPfsGetStatus(queue, channel); \
195 __osSiRelAccess(); \
196 if (ret != 0) \
197 return ret;
s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum)
Definition contpfs.c:17
OSPifRam __osPfsPifRam
Definition osPfsIsPlug.c:6
OSMesgQueue __osEepromTimerQ
s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page)
Definition osPfsAllocateFile.c:112
u8 __osContDataCrc(u8 *data)
Definition crc.c:23
s32 __osPfsGetStatus(OSMesgQueue *queue, int channel)
Definition osPfsInit.c:27
s32 __osPfsSelectBank(OSPfs *pfs)
Definition contpfs.c:270
s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer)
Definition contramread.c:8
u8 __osContAddressCrc(u16 addr)
Definition crc.c:3
void __osContGetInitData(u8 *bitpattern, OSContStatus *status)
Definition osContInit.c:48
OSPifRam __osContPifRam
Definition osContInit.c:12
OSTimer __osEepromTimer
u16 __osSumcalc(u8 *ptr, int length)
Definition contpfs.c:4
void __osPackRequestData(u8 command)
Definition osContInit.c:69
s32 __osCheckId(OSPfs *pfs)
Definition contpfs.c:188
s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp)
Definition contpfs.c:110
s32 __osEepStatus(OSMesgQueue *, OSContStatus *)
Definition osEepromWrite.c:85
s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag)
Definition osPfsDeleteFile.c:62
OSPifRam __osEepPifRam
Definition osEepromWrite.c:5
void __osPfsRequestData(u8 cmd)
Definition osPfsIsPlug.c:49
s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank)
Definition contpfs.c:212
s32 __osGetId(OSPfs *pfs)
Definition contpfs.c:143
void __osPfsGetInitData(u8 *pattern, OSContStatus *data)
Definition osPfsIsPlug.c:78
u8 _osContNumControllers
Definition osContInit.c:14
s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force)
Definition contramwrite.c:8
s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank)
Definition osPfsDeleteFile.c:112
OSMesg __osEepromTimerMsg
u8 __osContLastCmd
Definition osContInit.c:13
s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid)
Definition contpfs.c:33
unsigned long long int u64
Definition llconv.c:2
#define PFS_FILE_EXT_LEN
Definition os.h:410
#define EEPROM_BLOCK_SIZE
Definition os.h:444
#define PFS_FILE_NAME_LEN
Definition os.h:409
#define BLOCKSIZE
Definition os.h:411
Definition controller.h:11
u32 pifstatus
Definition controller.h:13
Definition os_time.h:9
Definition controller.h:91
u8 address
Definition controller.h:95
u8 txsize
Definition controller.h:92
u8 cmd
Definition controller.h:94
u8 rxsize
Definition controller.h:93
Definition controller.h:46
u8 txsize
Definition controller.h:48
u8 dummy
Definition controller.h:47
u8 rxsize
Definition controller.h:49
u8 cmd
Definition controller.h:50
u8 datacrc
Definition controller.h:53
u16 address
Definition controller.h:51
Definition controller.h:16
u8 cmd
Definition controller.h:20
u8 dummy
Definition controller.h:17
u8 rxsize
Definition controller.h:19
s8 stick_y
Definition controller.h:23
s8 stick_x
Definition controller.h:22
u16 button
Definition controller.h:21
u8 txsize
Definition controller.h:18
Definition controller.h:37
u8 typel
Definition controller.h:42
u8 status
Definition controller.h:43
u8 typeh
Definition controller.h:41
u8 txsize
Definition controller.h:38
u8 rxsize
Definition controller.h:39
u8 cmd
Definition controller.h:40
Definition controller.h:26
u8 txsize
Definition controller.h:28
u8 cmd
Definition controller.h:30
u8 typeh
Definition controller.h:31
u8 status
Definition controller.h:33
u8 dummy
Definition controller.h:27
u8 rxsize
Definition controller.h:29
u8 typel
Definition controller.h:32
u8 dummy1
Definition controller.h:34
Definition controller.h:64
u8 status
Definition controller.h:68
__OSInodeUnit start_page
Definition controller.h:67
u16 company_code
Definition controller.h:66
u16 data_sum
Definition controller.h:70
u32 game_code
Definition controller.h:65
s8 reserved
Definition controller.h:69
Definition controller.h:132
u8 bank
Definition controller.h:134
__OSInode inode
Definition controller.h:133
Definition controller.h:75
Definition controller.h:79
u8 banks
Definition controller.h:85
u32 random
Definition controller.h:81
u16 checksum
Definition controller.h:87
u16 deviceid
Definition controller.h:84
u8 version
Definition controller.h:86
u32 repaired
Definition controller.h:80
u16 inverted_checksum
Definition controller.h:88
u64 serial_low
Definition controller.h:83
u64 serial_mid
Definition controller.h:82
signed int s32
Definition ultratypes.h:15
unsigned int u32
Definition ultratypes.h:16
signed char s8
Definition ultratypes.h:11
unsigned short int u16
Definition ultratypes.h:14
unsigned char u8
Definition ultratypes.h:12
Definition controller.h:56
u8 bank
Definition controller.h:58
u8 page
Definition controller.h:59
u16 ipage
Definition controller.h:61