mu3: added lights hook

This commit is contained in:
2024-05-12 22:02:53 +02:00
parent b77ce7b457
commit 9fe98b227b
22 changed files with 669 additions and 58 deletions

View File

@ -11,10 +11,13 @@
#include "util/dprintf.h"
static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state);
static HRESULT mu3_io4_write_gpio(uint8_t* payload, size_t len);
static uint16_t coins;
static const struct io4_ops mu3_io4_ops = {
.poll = mu3_io4_poll,
.write_gpio = mu3_io4_write_gpio,
};
HRESULT mu3_io4_hook_init(const struct io4_config *cfg)
@ -124,3 +127,46 @@ static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state)
return S_OK;
}
static HRESULT mu3_io4_write_gpio(uint8_t* payload, size_t len)
{
// Just fast fail if there aren't enough bytes in the payload
if (len < 3)
return S_OK;
// This command is used for lights in Ongeki, but it only contains button lights,
// and only in the first 3 bytes of the payload; everything else is padding to
// make the payload 62 bytes. The rest of the cabinet lights and the side button
// lights are handled separately, by the 15093 lights controller.
uint32_t lights_data = (uint32_t) ((uint8_t)(payload[0]) << 24 |
(uint8_t)(payload[1]) << 16 |
(uint8_t)(payload[2]) << 8);
// Since Sega uses an odd ordering for the first part of the bitfield,
// let's normalize the data and just send over bytes for the receiver
// to interpret as RGB values.
uint8_t rgb_out[6 * 3] = {
lights_data & MU3_IO_LED_L1_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L1_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L1_B ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L2_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L2_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L2_B ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L3_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L3_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_L3_B ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R1_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R1_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R1_B ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R2_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R2_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R2_B ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R3_R ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R3_G ? 0xFF : 0x00,
lights_data & MU3_IO_LED_R3_B ? 0xFF : 0x00,
};
mu3_io_led_set_colors(1, rgb_out);
return S_OK;
}