diff options
| author | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-06-27 22:18:11 +0200 |
|---|---|---|
| committer | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-06-27 22:18:11 +0200 |
| commit | ef776e728cfa67fbca38bb375152b336fa0b5200 (patch) | |
| tree | 4eea0faf910d2671446c3f1ff1b9714d23e53cb7 | |
| parent | f56ade9b10c7c2d37f1b0af9191560cd5f0295b4 (diff) | |
| download | psn00bsdk-ef776e728cfa67fbca38bb375152b336fa0b5200.tar.gz | |
Clean up io/system573 example and libpsxpress
| -rw-r--r-- | examples/io/system573/k573io.c | 7 | ||||
| -rw-r--r-- | examples/io/system573/k573io.h | 38 | ||||
| -rw-r--r-- | examples/io/system573/main.c | 2 | ||||
| -rw-r--r-- | libpsn00b/include/psxpress.h | 10 | ||||
| -rw-r--r-- | libpsn00b/psxpress/mdec.c | 24 |
5 files changed, 47 insertions, 34 deletions
diff --git a/examples/io/system573/k573io.c b/examples/io/system573/k573io.c index bc13852..53c109f 100644 --- a/examples/io/system573/k573io.c +++ b/examples/io/system573/k573io.c @@ -75,7 +75,7 @@ uint32_t K573_GetJAMMAInputs(void) { inputs |= ((K573_IO_CHIP[IO_REG_IN1_HIGH] >> 8) & 0x1f) << 24; inputs |= (K573_IO_CHIP[IO_REG_IN1_LOW] & 0x07) << 29; - return inputs; + return ~inputs; } void K573_SetLights(uint32_t lights) { @@ -120,5 +120,10 @@ void K573_Init(void) { EXP1_ADDR = 0x1f000000; EXP1_DELAY_SIZE = 0x24173f47; // 573 BIOS uses this value + // Bit 6 of this register controls the audio DAC and must be set, otherwise + // no sound will be output. Most of the other bits are data clocks/strobes + // and should be pulled high when not in use. + K573_IO_CHIP[IO_REG_OUT0] = 0x01e7; + K573_RESET_WATCHDOG(); } diff --git a/examples/io/system573/k573io.h b/examples/io/system573/k573io.h index 7095a7c..424e3e4 100644 --- a/examples/io/system573/k573io.h +++ b/examples/io/system573/k573io.h @@ -25,6 +25,7 @@ #define K573_IO_BOARD ((volatile uint16_t *) 0x1f640000) typedef enum _K573_IOChipRegister { + IO_REG_OUT0 = 0x0, IO_REG_IN0 = 0x0, IO_REG_IN1_LOW = 0x2, IO_REG_IN1_HIGH = 0x3, @@ -34,26 +35,29 @@ typedef enum _K573_IOChipRegister { } K573_IOChipRegister; 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_LIGHTS0 = 0x40, + ANALOG_IO_REG_LIGHTS1 = 0x44, + ANALOG_IO_REG_LIGHTS2 = 0x48, + ANALOG_IO_REG_LIGHTS3 = 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_LIGHTS4 = 0x7d, - DIGITAL_IO_REG_LIGHTS5 = 0x7e, - DIGITAL_IO_REG_LIGHTS2 = 0x7f, - - FISHBAIT_IO_REG_UNKNOWN = 0x08, - FISHBAIT_IO_REG_MOTOR = 0x40, - FISHBAIT_IO_REG_BRAKE = 0x44, - FISHBAIT_IO_REG_ENCODER = 0x4c, - FISHBAIT_IO_REG_RESET_Y = 0x50 + 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, + + FISHBAIT_IO_REG_UNKNOWN = 0x08, + FISHBAIT_IO_REG_MOTOR = 0x40, + FISHBAIT_IO_REG_BRAKE = 0x44, + FISHBAIT_IO_REG_ENCODER = 0x4c, + FISHBAIT_IO_REG_RESET_Y = 0x50 } K573_IOBoardRegister; // The 573's real-time clock chip is an M48T58, which behaves like a standard diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 64722d7..3404ee4 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -207,7 +207,7 @@ int main(int argc, const char* argv[]) { // Change the currently active light if the test button on the 573's // front panel is pressed. DDR non-light outputs are skipped. - if ((last_inputs & JAMMA_TEST) && !(inputs & JAMMA_TEST)) { + if (!(last_inputs & JAMMA_TEST) && (inputs & JAMMA_TEST)) { current_light++; if ( (current_light == 4) || // DDR_LIGHT_P1_MUX_DATA diff --git a/libpsn00b/include/psxpress.h b/libpsn00b/include/psxpress.h index b060170..6203c2a 100644 --- a/libpsn00b/include/psxpress.h +++ b/libpsn00b/include/psxpress.h @@ -40,7 +40,7 @@ extern "C" { * * @param mode */ -void DecDCTReset(int32_t mode); +void DecDCTReset(int mode); /** * @brief Uploads the specified decoding environment's quantization tables and @@ -61,7 +61,7 @@ void DecDCTReset(int32_t mode); * @param env Pointer to DECDCTENV or 0 for default tables * @param mono 0 for color (normal), 1 for monochrome */ -void DecDCTPutEnv(const DECDCTENV *env, int32_t mono); +void DecDCTPutEnv(const DECDCTENV *env, int mono); /** * @brief Sets up the MDEC to start fetching and decoding a stream from the @@ -79,7 +79,7 @@ void DecDCTPutEnv(const DECDCTENV *env, int32_t mono); * @param data * @param mode DECDCT_MODE_* or -1 */ -void DecDCTin(const uint32_t *data, int32_t mode); +void DecDCTin(const uint32_t *data, int mode); /** * @brief Configures the MDEC to automatically fetch data (the input stream, @@ -113,7 +113,7 @@ void DecDCTinRaw(const uint32_t *data, size_t length); * @param mode * @return 0 or -1 in case of a timeout (mode = 0) / MDEC busy flag (mode = 1) */ -int32_t DecDCTinSync(int32_t mode); +int DecDCTinSync(int mode); /** * @brief Configures the MDEC to automatically transfer decoded image data in @@ -144,7 +144,7 @@ void DecDCTout(uint32_t *data, size_t length); * @param mode * @return 0 or -1 in case of a timeout (mode = 0) / DMA busy flag (mode = 1) */ -int32_t DecDCToutSync(int32_t mode); +int DecDCToutSync(int mode); #ifdef __cplusplus } diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c index ca4c75a..ba190d4 100644 --- a/libpsn00b/psxpress/mdec.c +++ b/libpsn00b/psxpress/mdec.c @@ -9,7 +9,8 @@ #include <psxpress.h> #include <hwregs_c.h> -#define MDEC_SYNC_TIMEOUT 0x1000000 +#define DMA_CHUNK_LENGTH 32 +#define MDEC_SYNC_TIMEOUT 0x1000000 /* Default IDCT matrix and quantization tables */ @@ -82,7 +83,7 @@ static const DECDCTENV _default_mdec_env = { /* Public API */ -void DecDCTReset(int32_t mode) { +void DecDCTReset(int mode) { EnterCriticalSection(); DMA_DPCR |= 0x000000bb; // Enable DMA0 and DMA1 @@ -96,7 +97,7 @@ void DecDCTReset(int32_t mode) { DecDCTPutEnv(0, 0); } -void DecDCTPutEnv(const DECDCTENV *env, int32_t mono) { +void DecDCTPutEnv(const DECDCTENV *env, int mono) { const DECDCTENV *_env = env ? env : &_default_mdec_env; DecDCTinSync(0); @@ -109,7 +110,7 @@ void DecDCTPutEnv(const DECDCTENV *env, int32_t mono) { DecDCTinSync(0); } -void DecDCTin(const uint32_t *data, int32_t mode) { +void DecDCTin(const uint32_t *data, int mode) { uint32_t header = *data; if (mode == DECDCT_MODE_RAW) MDEC0 = header; @@ -125,16 +126,19 @@ void DecDCTin(const uint32_t *data, int32_t mode) { // data length as an argument rather than parsing it from the first 4 bytes of // the stream. void DecDCTinRaw(const uint32_t *data, size_t length) { + // NOTE: if length >= DMA_CHUNK_LENGTH then it also has to be a multiple of + // DMA_CHUNK_LENGTH, otherwise the DMA channel will get stuck waiting for + // more data indefinitely. DMA_MADR(0) = (uint32_t) data; - if (length < 32) + if (length < DMA_CHUNK_LENGTH) DMA_BCR(0) = 0x00010000 | length; else - DMA_BCR(0) = 0x00000020 | ((length / 32) << 16); + DMA_BCR(0) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); DMA_CHCR(0) = 0x01000201; } -int32_t DecDCTinSync(int32_t mode) { +int DecDCTinSync(int mode) { if (mode) return (MDEC1 >> 29) & 1; @@ -151,15 +155,15 @@ void DecDCTout(uint32_t *data, size_t length) { DecDCToutSync(0); DMA_MADR(1) = (uint32_t) data; - if (length < 32) + if (length < DMA_CHUNK_LENGTH) DMA_BCR(1) = 0x00010000 | length; else - DMA_BCR(1) = 0x00000020 | ((length / 32) << 16); + DMA_BCR(1) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16); DMA_CHCR(1) = 0x01000200; } -int32_t DecDCToutSync(int32_t mode) { +int DecDCToutSync(int mode) { if (mode) return (DMA_CHCR(1) >> 24) & 1; |
