diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-12-18 15:44:22 +0100 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-12-18 15:44:22 +0100 |
| commit | b3fc13c36c4ed666e34e292a9ed7d45ae4f49454 (patch) | |
| tree | 5a6af613dc529cd5dd5c6ef022be44d2508a6782 /examples/io/system573/k573io.h | |
| parent | 3b7c46ab74548a9a79bfb867551c51dd877c8f4d (diff) | |
| download | psn00bsdk-b3fc13c36c4ed666e34e292a9ed7d45ae4f49454.tar.gz | |
Rearrange hwregs_c.h and k573io.h, add clz intrinsics
Diffstat (limited to 'examples/io/system573/k573io.h')
| -rw-r--r-- | examples/io/system573/k573io.h | 274 |
1 files changed, 134 insertions, 140 deletions
diff --git a/examples/io/system573/k573io.h b/examples/io/system573/k573io.h index 8655237..552a93c 100644 --- a/examples/io/system573/k573io.h +++ b/examples/io/system573/k573io.h @@ -1,57 +1,49 @@ /* * PSn00bSDK Konami System 573 example (I/O driver) * (C) 2022 spicyjpeg - MPL licensed + * + * Reference: https://psx-spx.consoledev.net/konamisystem573/#register-map */ #ifndef __K573IO_H #define __K573IO_H #include <stdint.h> +#include <hwregs_c.h> /* Register definitions */ -#define K573_BANK_SWITCH *((volatile uint16_t *) 0xbf500000) -#define K573_IDE_RESET *((volatile uint16_t *) 0xbf560000) -#define K573_WATCHDOG *((volatile uint16_t *) 0xbf5c0000) -#define K573_EXT_OUT *((volatile uint16_t *) 0xbf600000) -#define K573_JVS_INPUT *((volatile uint16_t *) 0xbf680000) -#define K573_SECURITY_OUT *((volatile uint16_t *) 0xbf6a0000) - -#define K573_FLASH ((volatile uint16_t *) 0xbf000000) -#define K573_IO_CHIP ((volatile uint16_t *) 0xbf400000) -#define K573_IDE_CS0 ((volatile uint16_t *) 0xbf480000) -#define K573_IDE_CS1 ((volatile uint16_t *) 0xbf4c0000) -#define K573_RTC ((volatile uint16_t *) 0xbf620000) -#define K573_IO_BOARD ((volatile uint16_t *) 0xbf640000) - -typedef enum _K573_IOChipRegister { - IO_REG_OUT0 = 0x0, - IO_REG_IN0 = 0x0, - IO_REG_IN1_LOW = 0x2, - IO_REG_IN1_HIGH = 0x3, - IO_REG_IN2 = 0x4, - IO_REG_IN3_LOW = 0x6, - IO_REG_IN3_HIGH = 0x7 -} K573_IOChipRegister; +#define K573_MISC_OUT _MMIO16(EXP1BASE | 0x400000) +#define K573_DIP_CART_IN _MMIO16(EXP1BASE | 0x400004) +#define K573_MISC_IN _MMIO16(EXP1BASE | 0x400006) +#define K573_JAMMA_IN _MMIO16(EXP1BASE | 0x400008) +#define K573_JVS_RX_DATA _MMIO16(EXP1BASE | 0x40000a) +#define K573_EXT_IN_P1 _MMIO16(EXP1BASE | 0x40000c) +#define K573_EXT_IN_P2 _MMIO16(EXP1BASE | 0x40000e) + +#define K573_BANK_SEL _MMIO16(EXP1BASE | 0x500000) +#define K573_JVS_RESET _MMIO16(EXP1BASE | 0x520000) +#define K573_IDE_RESET _MMIO16(EXP1BASE | 0x560000) +#define K573_WATCHDOG _MMIO16(EXP1BASE | 0x5c0000) +#define K573_EXT_OUT _MMIO16(EXP1BASE | 0x600000) +#define K573_JVS_TX_DATA _MMIO16(EXP1BASE | 0x680000) +#define K573_CART_OUT _MMIO16(EXP1BASE | 0x6a0000) + +#define K573_FLASH _ADDR16(EXP1BASE | 0x000000) +#define K573_IDE_CS0 _ADDR16(EXP1BASE | 0x480000) +#define K573_IDE_CS1 _ADDR16(EXP1BASE | 0x4c0000) +#define K573_RTC _ADDR16(EXP1BASE | 0x620000) +#define K573_IO_BOARD _ADDR16(EXP1BASE | 0x640000) typedef enum _K573_IOBoardRegister { - ANALOG_IO_REG_LIGHTS0 = 0x40, - ANALOG_IO_REG_LIGHTS1 = 0x44, - ANALOG_IO_REG_LIGHTS2 = 0x48, - ANALOG_IO_REG_LIGHTS3 = 0x4c, + ANALOG_IO_REG_LIGHTS_A = 0x40, + ANALOG_IO_REG_LIGHTS_B = 0x44, + ANALOG_IO_REG_LIGHTS_C = 0x48, + ANALOG_IO_REG_LIGHTS_D = 0x4c, - // The digital I/O board has a lot more registers than these, but there - // seems to be no DIGITAL_IO_LIGHTS6 register. WTF - DIGITAL_IO_REG_LIGHTS1 = 0x70, - DIGITAL_IO_REG_LIGHTS0 = 0x71, - DIGITAL_IO_REG_LIGHTS3 = 0x72, - DIGITAL_IO_REG_LIGHTS7 = 0x73, - DIGITAL_IO_REG_DS2401 = 0x77, DIGITAL_IO_REG_FPGA_STATUS = 0x7b, - DIGITAL_IO_REG_FPGA_UPLOAD = 0x7c, - DIGITAL_IO_REG_LIGHTS4 = 0x7d, - DIGITAL_IO_REG_LIGHTS5 = 0x7e, - DIGITAL_IO_REG_LIGHTS2 = 0x7f, + DIGITAL_IO_REG_FPGA_PROGRAM = 0x7c, + DIGITAL_IO_REG_FPGA_DATA = 0x7d, FISHBAIT_IO_REG_UNKNOWN = 0x08, FISHBAIT_IO_REG_MOTOR = 0x40, @@ -74,10 +66,22 @@ typedef enum _K573_RTCRegister { RTC_REG_YEAR = 0x1fff } K573_RTCRegister; -/* Inputs and lights bitfields */ - -typedef enum _K573_JAMMAInputs { - // IO_REG_IN2 bits 0-15 +/* Bitfields */ + +typedef enum _K573_MiscOutFlag { + MISC_OUT_ADC_MOSI = 1 << 0, + MISC_OUT_ADC_CS = 1 << 1, + MISC_OUT_ADC_SCK = 1 << 2, + MISC_OUT_COIN_COUNTER1 = 1 << 3, + MISC_OUT_COIN_COUNTER2 = 1 << 4, + MISC_OUT_AMP_ENABLE = 1 << 5, + MISC_OUT_CDDA_ENABLE = 1 << 6, + MISC_OUT_SPU_ENABLE = 1 << 7, + MISC_OUT_MCU_CLOCK = 1 << 8 +} K573_MiscOutFlag; + +typedef enum _K573_JAMMAInput { + // K573_JAMMA_IN bits 0-15 JAMMA_P2_LEFT = 1 << 0, JAMMA_P2_RIGHT = 1 << 1, JAMMA_P2_UP = 1 << 2, @@ -95,108 +99,114 @@ typedef enum _K573_JAMMAInputs { JAMMA_P1_BUTTON3 = 1 << 14, JAMMA_P1_START = 1 << 15, - // IO_REG_IN3_LOW bits 8-11 + // K573_EXT_IN_P1 bits 8-11 JAMMA_P1_BUTTON4 = 1 << 16, JAMMA_P1_BUTTON5 = 1 << 17, JAMMA_TEST = 1 << 18, JAMMA_P1_BUTTON6 = 1 << 19, - // IO_REG_IN3_HIGH bits 8-11 + // K573_EXT_IN_P2 bits 8-11 JAMMA_P2_BUTTON4 = 1 << 20, JAMMA_P2_BUTTON5 = 1 << 21, JAMMA_UNKNOWN = 1 << 22, JAMMA_P2_BUTTON6 = 1 << 23, - // IO_REG_IN1_HIGH bits 8-12 + // K573_MISC_IN bits 8-12 JAMMA_COIN1 = 1 << 24, JAMMA_COIN2 = 1 << 25, JAMMA_PCMCIA1 = 1 << 26, JAMMA_PCMCIA2 = 1 << 27, JAMMA_SERVICE = 1 << 28, - // IO_REG_IN1_LOW bits 0-2 + // K573_DIP_CART_IN bits 0-2 JAMMA_DIP1 = 1 << 29, JAMMA_DIP2 = 1 << 30, JAMMA_DIP3 = 1 << 31 -} K573_JAMMAInputs; +} K573_JAMMAInput; typedef enum _K573_Light { + LIGHT_A0 = 1 << 0, + LIGHT_A1 = 1 << 1, + LIGHT_A2 = 1 << 2, + LIGHT_A3 = 1 << 3, + LIGHT_A4 = 1 << 4, + LIGHT_A5 = 1 << 5, + LIGHT_A6 = 1 << 6, + LIGHT_A7 = 1 << 7, + LIGHT_B0 = 1 << 8, + LIGHT_B1 = 1 << 9, + LIGHT_B2 = 1 << 10, + LIGHT_B3 = 1 << 11, + LIGHT_B4 = 1 << 12, + LIGHT_B5 = 1 << 13, + LIGHT_B6 = 1 << 14, + LIGHT_B7 = 1 << 15, + LIGHT_C0 = 1 << 16, + LIGHT_C1 = 1 << 17, + LIGHT_C2 = 1 << 18, + LIGHT_C3 = 1 << 19, + LIGHT_C4 = 1 << 20, + LIGHT_C5 = 1 << 21, + LIGHT_C6 = 1 << 22, + LIGHT_C7 = 1 << 23, + LIGHT_D0 = 1 << 24, + LIGHT_D1 = 1 << 25, + LIGHT_D2 = 1 << 26, + LIGHT_D3 = 1 << 27, + // Dance Dance Revolution (2-player) - DDR_LIGHT_P1_UP = 1 << 0, - DDR_LIGHT_P1_LEFT = 1 << 1, - DDR_LIGHT_P1_RIGHT = 1 << 2, - DDR_LIGHT_P1_DOWN = 1 << 3, - DDR_LIGHT_P1_MUX_DATA = 1 << 4, // Used for stage commands - DDR_LIGHT_P1_MUX_CLK = 1 << 7, // Used for stage commands - DDR_LIGHT_P2_UP = 1 << 8, - DDR_LIGHT_P2_LEFT = 1 << 9, - DDR_LIGHT_P2_RIGHT = 1 << 10, - DDR_LIGHT_P2_DOWN = 1 << 11, - DDR_LIGHT_P2_MUX_DATA = 1 << 12, // Used for stage commands - DDR_LIGHT_P2_MUX_CLK = 1 << 15, // Used for stage commands - DDR_LIGHT_P1_BUTTONS = 1 << 17, - DDR_LIGHT_P2_BUTTONS = 1 << 18, - DDR_LIGHT_MARQUEE_BR = 1 << 20, - DDR_LIGHT_MARQUEE_BL = 1 << 21, - DDR_LIGHT_MARQUEE_TL = 1 << 22, - DDR_LIGHT_MARQUEE_TR = 1 << 23, - DDR_LIGHT_SPEAKER_DIGITAL = 1 << 28, // Speaker neon on digital I/O boards - DDR_LIGHT_SPEARKER_ANALOG = 1 << 30, // Speaker neon on analog I/O boards + LIGHT_DDR_P1_UP = 1 << 0, + LIGHT_DDR_P1_DOWN = 1 << 1, + LIGHT_DDR_P1_LEFT = 1 << 2, + LIGHT_DDR_P1_RIGHT = 1 << 3, + LIGHT_DDR_P1_IO_DATA = 1 << 4, + LIGHT_DDR_P1_IO_CLK = 1 << 5, + LIGHT_DDR_P2_UP = 1 << 8, + LIGHT_DDR_P2_DOWN = 1 << 9, + LIGHT_DDR_P2_LEFT = 1 << 10, + LIGHT_DDR_P2_RIGHT = 1 << 11, + LIGHT_DDR_P2_IO_DATA = 1 << 12, + LIGHT_DDR_P2_IO_CLK = 1 << 13, + LIGHT_DDR_P1_BUTTONS = 1 << 18, + LIGHT_DDR_P2_BUTTONS = 1 << 19, + LIGHT_DDR_MARQUEE_BR = 1 << 20, + LIGHT_DDR_MARQUEE_TR = 1 << 21, + LIGHT_DDR_MARQUEE_BL = 1 << 22, + LIGHT_DDR_MARQUEE_TL = 1 << 23, + LIGHT_DDR_SPEAKER = 1 << 24, // Dance Dance Revolution Solo - DDRSOLO_LIGHT_EXTRA4 = 1 << 8, - DDRSOLO_LIGHT_EXTRA2 = 1 << 9, - DDRSOLO_LIGHT_EXTRA1 = 1 << 10, - DDRSOLO_LIGHT_EXTRA3 = 1 << 11, - DDRSOLO_LIGHT_SPEAKER = 1 << 16, - DDRSOLO_LIGHT_BUTTONS = 1 << 20, - DDRSOLO_LIGHT_BODY_CENTER = 1 << 21, - DDRSOLO_LIGHT_BODY_RIGHT = 1 << 22, - DDRSOLO_LIGHT_BODY_LEFT = 1 << 23, + LIGHT_SOLO_SPEAKER = 1 << 16, + LIGHT_SOLO_BUTTONS = 1 << 20, + LIGHT_SOLO_BODY_LEFT = 1 << 21, + LIGHT_SOLO_BODY_CENTER = 1 << 22, + LIGHT_SOLO_BODY_RIGHT = 1 << 23, // DrumMania 1st Mix - DM_LIGHT_HIHAT = 1 << 16, - DM_LIGHT_HIGH_TOM = 1 << 17, - DM_LIGHT_LOW_TOM = 1 << 18, - DM_LIGHT_SNARE = 1 << 19, - DM_LIGHT_CYMBAL = 1 << 20, - DM_LIGHT_START_BUTTON = 1 << 21, - DM_LIGHT_SELECT_BUTTON = 1 << 22, - DM_LIGHT_NEON_BOTTOM = 1 << 27, - DM_LIGHT_SPOT = 1 << 30, - DM_LIGHT_NEON_TOP = 1 << 31, + LIGHT_DM_HIHAT = 1 << 16, + LIGHT_DM_SNARE = 1 << 17, + LIGHT_DM_HIGH_TOM = 1 << 18, + LIGHT_DM_LOW_TOM = 1 << 19, + LIGHT_DM_CYMBAL = 1 << 20, + LIGHT_DM_START_BUTTON = 1 << 22, + LIGHT_DM_SELECT_BUTTON = 1 << 23, + LIGHT_DM_SPOT = 1 << 24, + LIGHT_DM_NEON_TOP = 1 << 25, + LIGHT_DM_NEON_BOTTOM = 1 << 27, // DrumMania 2nd Mix and later - DM2_LIGHT_HIHAT = 1 << 0, - DM2_LIGHT_HIGH_TOM = 1 << 1, - DM2_LIGHT_LOW_TOM = 1 << 2, - DM2_LIGHT_SNARE = 1 << 3, - DM2_LIGHT_SPOT = 1 << 8, - DM2_LIGHT_NEON_TOP = 1 << 9, - DM2_LIGHT_NEON_BOTTOM = 1 << 11, - DM2_LIGHT_CYMBAL = 1 << 12, - DM2_LIGHT_START_BUTTON = 1 << 13, - DM2_LIGHT_SELECT_BUTTON = 1 << 14 + LIGHT_DM2_HIHAT = 1 << 0, + LIGHT_DM2_SNARE = 1 << 1, + LIGHT_DM2_HIGH_TOM = 1 << 2, + LIGHT_DM2_LOW_TOM = 1 << 3, + LIGHT_DM2_SPOT = 1 << 8, + LIGHT_DM2_NEON_BOTTOM = 1 << 9, + LIGHT_DM2_NEON_TOP = 1 << 10, + LIGHT_DM2_CYMBAL = 1 << 12, + LIGHT_DM2_START_BUTTON = 1 << 14, + LIGHT_DM2_SELECT_BUTTON = 1 << 15 } K573_Light; -/* System information structures */ - -typedef enum _K573_IOBoardType { - IO_TYPE_ANALOG = 0, // Light control board (early Bemani) - IO_TYPE_DIGITAL = 1, // Light control + MP3 playback board (late Bemani) - IO_TYPE_FISHBAIT = 2, // Fishing reel controls interface (Fisherman's Bait) - IO_TYPE_GUNMANIA = 3, // Gun control board (Gun Mania) - IO_TYPE_KARAOKE = 4, // Karaoke I/O + video mux board (DDR Karaoke Mix) - IO_TYPE_SERIAL = 5 // Serial port (debug?) board (Great Bishi Bashi Champ) - // TODO: does PunchMania have its own board? -} K573_IOBoardType; - -typedef enum _K573_DDRStageType { - DDR_TYPE_NONE = 0, - DDR_TYPE_2PLAYER = 1, - DDR_TYPE_SOLO = 2 -} K573_DDRStageType; - /* Public API */ #define K573_RESET_WATCHDOG() { \ @@ -208,43 +218,27 @@ extern "C" { #endif /** - * @brief Returns a bitfield containing the state of all JAMMA inputs and DIP + * @brief Returns the state of JAMMA inputs and DIP switches. + * + * @details Returns a bitfield containing the state of all JAMMA inputs and DIP * switches. All bits are inverted as they represent the actual signal levels * on the JAMMA pins (i.e. normally pulled up by resistors, shorted to ground * when a button is pressed). * - * @return Inverted logical OR of K573_JAMMAInputs flags + * @return Binary OR of K573_JAMMAInputs flags */ uint32_t K573_GetJAMMAInputs(void); /** - * @brief Sets the 32 light outputs provided by the the analog and digital I/O - * boards to match the provided bitfield. K573_SetBoardType(IO_TYPE_ANALOG) or - * K573_SetBoardType(IO_TYPE_DIGITAL) must be called beforehand to set the I/O - * board type. - * - * @param lights Non-inverted logical OR of K573_Light flags - */ -void K573_SetLights(uint32_t lights); - -/** - * @brief Sets the installed I/O board type. Currently only IO_TYPE_ANALOG and - * IO_TYPE_DIGITAL are supported. + * @brief Sets light outputs on the analog I/O board. * - * @param type - */ -void K573_SetBoardType(K573_IOBoardType type); - -/** - * @brief Sends a command to the multiplexer PCB embedded into DDR stage units - * (if the system is a DDR cabinet) by bitbanging it through the light outputs. - * K573_SetBoardType(IO_TYPE_ANALOG) or K573_SetBoardType(IO_TYPE_DIGITAL) must - * be called beforehand to set the I/O board type. + * @details Sets the 32 light outputs provided by the analog I/O board (if + * installed) to match the provided bitfield. No other I/O boards are currently + * supported. * - * @param value - * @param length Number of bits to send (1-32) + * @param lights Binary OR of K573_Light flags */ -//void K573_DDRStageCommand(uint32_t value, uint32_t length); +void K573_SetAnalogLights(uint32_t lights); /** * @brief Initializes the expansion port registers to enable System 573 I/O |
