2021-09-15 23:24:19 +00:00
|
|
|
#ifndef ULTRA64_CONTROLLER_H
|
|
|
|
#define ULTRA64_CONTROLLER_H
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-12-01 00:08:57 +00:00
|
|
|
#include "message.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-07-30 19:41:32 +00:00
|
|
|
#define CHNL_ERR(readFormat) (((readFormat).rxsize & CHNL_ERR_MASK) >> 4)
|
|
|
|
|
2020-06-17 11:16:30 +00:00
|
|
|
#define BLOCKSIZE 32
|
|
|
|
#define MAXCONTROLLERS 4
|
2020-07-07 00:15:01 +00:00
|
|
|
#define PFS_ONE_PAGE 8
|
|
|
|
|
|
|
|
#define PFS_PAGE_SIZE (BLOCKSIZE*PFS_ONE_PAGE)
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2020-04-19 01:40:27 +00:00
|
|
|
#define CONT_CMD_REQUEST_STATUS 0
|
|
|
|
#define CONT_CMD_READ_BUTTON 1
|
|
|
|
#define CONT_CMD_READ_MEMPACK 2
|
|
|
|
#define CONT_CMD_WRITE_MEMPACK 3
|
|
|
|
#define CONT_CMD_READ_EEPROM 4
|
|
|
|
#define CONT_CMD_WRITE_EEPROM 5
|
|
|
|
#define CONT_CMD_RESET 0xFF
|
|
|
|
|
|
|
|
#define CONT_CMD_REQUEST_STATUS_TX 1
|
|
|
|
#define CONT_CMD_READ_BUTTON_TX 1
|
|
|
|
#define CONT_CMD_READ_MEMPACK_TX 3
|
|
|
|
#define CONT_CMD_WRITE_MEMPACK_TX 35
|
|
|
|
#define CONT_CMD_READ_EEPROM_TX 2
|
|
|
|
#define CONT_CMD_WRITE_EEPROM_TX 10
|
|
|
|
#define CONT_CMD_RESET_TX 1
|
|
|
|
|
|
|
|
#define CONT_CMD_REQUEST_STATUS_RX 3
|
|
|
|
#define CONT_CMD_READ_BUTTON_RX 4
|
|
|
|
#define CONT_CMD_READ_MEMPACK_RX 33
|
|
|
|
#define CONT_CMD_WRITE_MEMPACK_RX 1
|
|
|
|
#define CONT_CMD_READ_EEPROM_RX 8
|
|
|
|
#define CONT_CMD_WRITE_EEPROM_RX 1
|
|
|
|
#define CONT_CMD_RESET_RX 3
|
|
|
|
|
|
|
|
#define CONT_CMD_NOP 0xFF
|
|
|
|
#define CONT_CMD_END 0xFE // Indicates end of a command
|
|
|
|
#define CONT_CMD_EXE 1 // Set pif ram status byte to this to do a command
|
2022-07-30 19:41:32 +00:00
|
|
|
#define CONT_CMD_SKIP_CHNL 0 // Skip channel
|
2020-04-19 01:40:27 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */
|
|
|
|
#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */
|
|
|
|
#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */
|
|
|
|
#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */
|
|
|
|
#define CONT_ERR_NOT_READY 12
|
|
|
|
#define CONT_ERR_VOICE_MEMORY 13
|
|
|
|
#define CONT_ERR_VOICE_WORD 14
|
|
|
|
#define CONT_ERR_VOICE_NO_RESPONSE 15
|
2020-06-17 11:16:30 +00:00
|
|
|
|
|
|
|
|
2020-04-19 01:40:27 +00:00
|
|
|
#define DIR_STATUS_EMPTY 0
|
|
|
|
#define DIR_STATUS_UNKNOWN 1
|
|
|
|
#define DIR_STATUS_OCCUPIED 2
|
|
|
|
|
2020-06-17 11:16:30 +00:00
|
|
|
#define PFS_FORCE 1
|
|
|
|
#define PFS_DELETE 1
|
|
|
|
|
|
|
|
#define PFS_LABEL_AREA 7
|
|
|
|
|
|
|
|
#define PFS_ERR_NOPACK 1
|
|
|
|
|
|
|
|
/* controller errors */
|
|
|
|
#define CONT_NO_RESPONSE_ERROR 0x8
|
|
|
|
#define CONT_OVERRUN_ERROR 0x4
|
|
|
|
|
|
|
|
/* Controller type */
|
|
|
|
#define CONT_ABSOLUTE 0x0001
|
|
|
|
#define CONT_RELATIVE 0x0002
|
|
|
|
#define CONT_JOYPORT 0x0004
|
2020-10-03 15:22:44 +00:00
|
|
|
#define CONT_EEPROM 0x8000
|
|
|
|
#define CONT_EEP16K 0x4000
|
|
|
|
#define CONT_TYPE_MASK 0x1F07
|
|
|
|
#define CONT_TYPE_NORMAL 0x0005
|
|
|
|
#define CONT_TYPE_MOUSE 0x0002
|
|
|
|
#define CONT_TYPE_VOICE 0x0100
|
2020-06-17 11:16:30 +00:00
|
|
|
|
|
|
|
/* Controller status */
|
|
|
|
#define CONT_CARD_ON 0x01
|
|
|
|
#define CONT_CARD_PULL 0x02
|
|
|
|
#define CONT_ADDR_CRC_ER 0x04
|
2020-10-03 15:22:44 +00:00
|
|
|
#define CONT_EEPROM_BUSY 0x80
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2022-07-30 19:41:32 +00:00
|
|
|
/* Accessory detection */
|
|
|
|
#define CONT_ADDR_DETECT 0x8000
|
|
|
|
|
|
|
|
// Rumble
|
|
|
|
#define CONT_ADDR_RUMBLE 0xC000
|
|
|
|
|
|
|
|
// Controller Pak / Transfer Pak
|
|
|
|
#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different
|
|
|
|
#define CONT_ADDR_GB_BANK 0xA000
|
|
|
|
#define CONT_ADDR_GB_STATUS 0xB000
|
|
|
|
|
|
|
|
// Addresses sent to controller accessories are in blocks, not bytes
|
|
|
|
#define CONT_BLOCKS(x) ((x) / BLOCKSIZE)
|
|
|
|
|
|
|
|
// Block addresses of the above
|
|
|
|
#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT)
|
|
|
|
#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE)
|
|
|
|
#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER)
|
|
|
|
#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK)
|
|
|
|
#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS)
|
|
|
|
|
2024-02-28 00:01:47 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
// Ensure data cache coherency for OSPifRam structures by aligning to the data cache line size.
|
|
|
|
// On older compilers such as IDO this was done by placing each OSPifRam at the top of the file it is declared in,
|
|
|
|
// however file alignment should not be relied on in general.
|
|
|
|
__attribute__((aligned(0x10)))
|
|
|
|
#endif
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef union OSPifRam {
|
2022-02-11 23:23:57 +00:00
|
|
|
struct {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u32 ram[15];
|
|
|
|
/* 0x3C */ u32 status;
|
2022-02-11 23:23:57 +00:00
|
|
|
};
|
|
|
|
u64 force_structure_alignment;
|
2020-10-03 15:22:44 +00:00
|
|
|
} OSPifRam; // size = 0x40
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct OSContStatus {
|
2022-01-23 23:09:02 +00:00
|
|
|
/* 0x00 */ u16 type;
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x02 */ u8 status;
|
|
|
|
/* 0x03 */ u8 errno;
|
|
|
|
} OSContStatus; // size = 0x04
|
2020-04-14 17:17:25 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct OSContPad {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u16 button;
|
|
|
|
/* 0x02 */ s8 stick_x;
|
|
|
|
/* 0x03 */ s8 stick_y;
|
|
|
|
/* 0x04 */ u8 errno;
|
|
|
|
} OSContPad; // size = 0x06
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct OSContRamIo {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ void* address;
|
|
|
|
/* 0x04 */ u8 databuffer[32];
|
|
|
|
/* 0x24 */ u8 addressCrc;
|
|
|
|
/* 0x25 */ u8 dataCrc;
|
|
|
|
/* 0x26 */ u8 errno;
|
|
|
|
} OSContRamIo; // size = 0x28
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct __OSContRequesFormat {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u8 align;
|
|
|
|
/* 0x01 */ u8 txsize;
|
|
|
|
/* 0x02 */ u8 rxsize;
|
2022-07-30 19:41:32 +00:00
|
|
|
/* 0x03 */ u8 cmd;
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x04 */ u8 typeh;
|
|
|
|
/* 0x05 */ u8 typel;
|
|
|
|
/* 0x06 */ u8 status;
|
|
|
|
/* 0x07 */ u8 align1;
|
2022-07-30 19:41:32 +00:00
|
|
|
} __OSContRequesFormat; // size = 0x8
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct __OSContRequesFormatShort {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u8 txsize;
|
|
|
|
/* 0x01 */ u8 rxsize;
|
2022-07-30 19:41:32 +00:00
|
|
|
/* 0x02 */ u8 cmd;
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x03 */ u8 typeh;
|
|
|
|
/* 0x04 */ u8 typel;
|
|
|
|
/* 0x05 */ u8 status;
|
2022-07-30 19:41:32 +00:00
|
|
|
} __OSContRequesFormatShort; // size = 0x6
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct __OSContRamReadFormat {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u8 unk_00;
|
|
|
|
/* 0x01 */ u8 txsize;
|
|
|
|
/* 0x02 */ u8 rxsize;
|
2022-07-30 19:41:32 +00:00
|
|
|
/* 0x03 */ u8 cmd;
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x04 */ u8 hi;
|
|
|
|
/* 0x05 */ u8 lo;
|
|
|
|
/* 0x06 */ u8 data[BLOCKSIZE];
|
|
|
|
/* 0x26 */ u8 datacrc;
|
2022-07-30 19:41:32 +00:00
|
|
|
} __OSContRamReadFormat; // size = 0x27
|
|
|
|
|
|
|
|
#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr))
|
2020-06-17 11:16:30 +00:00
|
|
|
|
2024-08-12 07:07:48 +00:00
|
|
|
typedef struct __OSContReadFormat {
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x00 */ u8 align;
|
|
|
|
/* 0x01 */ u8 txsize;
|
|
|
|
/* 0x02 */ u8 rxsize;
|
2022-07-30 19:41:32 +00:00
|
|
|
/* 0x03 */ u8 cmd;
|
2020-10-03 15:22:44 +00:00
|
|
|
/* 0x04 */ u16 button;
|
|
|
|
/* 0x06 */ s8 joyX;
|
|
|
|
/* 0x07 */ s8 joyY;
|
2022-07-30 19:41:32 +00:00
|
|
|
} __OSContReadFormat; // size = 0x8
|
2020-10-03 15:22:44 +00:00
|
|
|
|
|
|
|
#endif
|