controller.h (5737B)
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 CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4) 9 10 typedef struct { 11 /* 0x00 */ u32 ramarray[15]; 12 /* 0x3C */ u32 pifstatus; 13 } OSPifRam; 14 15 typedef struct { 16 /* 0x0 */ u8 dummy; 17 /* 0x1 */ u8 txsize; 18 /* 0x2 */ u8 rxsize; 19 /* 0x3 */ u8 cmd; 20 /* 0x4 */ u16 button; 21 /* 0x6 */ s8 stick_x; 22 /* 0x7 */ s8 stick_y; 23 } __OSContReadFormat; 24 25 typedef struct { 26 /* 0x0 */ u8 dummy; 27 /* 0x1 */ u8 txsize; 28 /* 0x2 */ u8 rxsize; 29 /* 0x3 */ u8 cmd; 30 /* 0x4 */ u8 typeh; 31 /* 0x5 */ u8 typel; 32 /* 0x6 */ u8 status; 33 /* 0x7 */ u8 dummy1; 34 } __OSContRequesFormat; 35 36 typedef struct { 37 /* 0x0 */ u8 txsize; 38 /* 0x1 */ u8 rxsize; 39 /* 0x2 */ u8 cmd; 40 /* 0x3 */ u8 typeh; 41 /* 0x4 */ u8 typel; 42 /* 0x5 */ u8 status; 43 } __OSContRequesFormatShort; 44 45 typedef struct { 46 /* 0x0 */ u8 dummy; 47 /* 0x1 */ u8 txsize; 48 /* 0x2 */ u8 rxsize; 49 /* 0x3 */ u8 cmd; 50 /* 0x4 */ u16 address; 51 /* 0x6 */ u8 data[BLOCKSIZE]; 52 /* 0x26 */ u8 datacrc; 53 } __OSContRamReadFormat; 54 55 typedef union { 56 /* 0x0 */ struct 57 { 58 /* 0x0 */ u8 bank; 59 /* 0x1 */ u8 page; 60 } inode_t; 61 /* 0x0 */ u16 ipage; 62 } __OSInodeUnit; 63 64 typedef struct { 65 /* 0x0 */ u32 game_code; 66 /* 0x4 */ u16 company_code; 67 /* 0x6 */ __OSInodeUnit start_page; 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 75 typedef struct { 76 /* 0x0 */ __OSInodeUnit inode_page[128]; 77 } __OSInode; 78 79 typedef 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; 88 /* 0x1E */ u16 inverted_checksum; 89 } __OSPackId; 90 91 typedef struct { 92 /* 0x0 */ u8 txsize; 93 /* 0x1 */ u8 rxsize; 94 /* 0x2 */ u8 cmd; 95 /* 0x3 */ u8 address; 96 /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE]; 97 } __OSContEepromFormat; 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 132 133 typedef struct 134 { 135 /* 0x0 */ __OSInode inode; 136 /* 0x100 */ u8 bank; 137 /* 0x101 */ u8 map[256]; 138 } __OSInodeCache; 139 140 extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *); 141 u16 __osSumcalc(u8 *ptr, int length); 142 s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum); 143 s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid); 144 s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp); 145 s32 __osGetId(OSPfs *pfs); 146 s32 __osCheckId(OSPfs *pfs); 147 s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank); 148 s32 __osPfsSelectBank(OSPfs *pfs); 149 s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page); 150 s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag); 151 s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank); 152 s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer); 153 s32 __osContRamWrite(OSMesgQueue *mq, s32 channel, u16 address, u8 *buffer, s32 force); 154 void __osContGetInitData(u8 *pattern, OSContStatus *data); 155 void __osPackRequestData(u8 cmd); 156 void __osPfsRequestData(u8 cmd); 157 void __osPfsGetInitData(u8* pattern, OSContStatus* data); 158 u8 __osContAddressCrc(u16 addr); 159 u8 __osContDataCrc(u8 *data); 160 s32 __osPfsGetStatus(OSMesgQueue *queue, int channel); 161 162 extern u8 __osContLastCmd; 163 extern OSTimer __osEepromTimer; 164 extern OSMesg __osEepromTimerMsg[4]; 165 extern OSMesgQueue __osEepromTimerQ; 166 extern OSPifRam __osEepPifRam; 167 extern OSPifRam __osContPifRam; 168 extern OSPifRam __osPfsPifRam; 169 extern u8 __osMaxControllers; 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 { \ 180 pfs->activebank = 0; \ 181 ERRCK(__osPfsSelectBank(pfs)) \ 182 } 183 184 #define PFS_CHECK_ID \ 185 if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ 186 return PFS_ERR_NEW_PACK; 187 #endif 188 189 #define PFS_CHECK_STATUS \ 190 if ((pfs->status & PFS_INITIALIZED) == 0) \ 191 return PFS_ERR_INVALID; 192 193 #define PFS_GET_STATUS \ 194 __osSiGetAccess(); \ 195 ret = __osPfsGetStatus(queue, channel); \ 196 __osSiRelAccess(); \ 197 if (ret != 0) \ 198 return ret;