idac: 837-15070 board implementation

This commit is contained in:
2024-06-23 21:21:57 +02:00
parent 4e58d3b9a2
commit 7e5e0f132e
18 changed files with 1825 additions and 8 deletions

View File

@ -13,6 +13,43 @@
#include "platform/config.h"
#include "platform/platform.h"
void led15070_config_load(struct led15070_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
wchar_t tmpstr[16];
cfg->enable = GetPrivateProfileIntW(L"led15070", L"enable", 1, filename);
cfg->port_no = GetPrivateProfileIntW(L"led15070", L"portNo", 0, filename);
cfg->fw_ver = GetPrivateProfileIntW(L"led15070", L"fwVer", 0x90, filename);
/* TODO: Unknown, no firmware file available */
cfg->fw_sum = GetPrivateProfileIntW(L"led15070", L"fwSum", 0x0000, filename);
GetPrivateProfileStringW(
L"led15070",
L"boardNumber",
L"15070-02",
tmpstr,
_countof(tmpstr),
filename);
size_t n = wcstombs(cfg->board_number, tmpstr, sizeof(cfg->board_number));
for (int i = n; i < sizeof(cfg->board_number); i++)
{
cfg->board_number[i] = ' ';
}
GetPrivateProfileStringW(
L"led15070",
L"eepromPath",
L"DEVICE",
cfg->eeprom_path,
_countof(cfg->eeprom_path),
filename);
}
void idac_dll_config_load(
struct idac_dll_config *cfg,
const wchar_t *filename)
@ -42,6 +79,7 @@ void idac_hook_config_load(
zinput_config_load(&cfg->zinput, filename);
dvd_config_load(&cfg->dvd, filename);
io4_config_load(&cfg->io4, filename);
led15070_config_load(&cfg->led15070, filename);
}
void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename)

View File

@ -4,6 +4,7 @@
#include <stddef.h>
#include "board/config.h"
#include "board/led15070.h"
#include "hooklib/dvd.h"
@ -19,6 +20,7 @@ struct idac_hook_config {
struct io4_config io4;
struct idac_dll_config dll;
struct zinput_config zinput;
struct led15070_config led15070;
};
void idac_dll_config_load(

View File

@ -67,24 +67,31 @@ static DWORD CALLBACK idac_pre_startup(void)
goto fail;
}
hr = sg_reader_hook_init(&idac_hook_cfg.aime, 3, 3, idac_hook_mod);
if (FAILED(hr)) {
goto fail;
}
hr = idac_dll_init(&idac_hook_cfg.dll, idac_hook_mod);
if (FAILED(hr)) {
goto fail;
}
hr = sg_reader_hook_init(&idac_hook_cfg.aime, 3, 3, idac_hook_mod);
if (FAILED(hr)) {
goto fail;
}
hr = idac_io4_hook_init(&idac_hook_cfg.io4);
if (FAILED(hr)) {
goto fail;
}
hr = led15070_hook_init(&idac_hook_cfg.led15070, idac_dll.led_init,
idac_dll.led_set_fet_output, NULL, idac_dll.led_gs_update, 2, 1);
if (FAILED(hr)) {
goto fail;
}
/* Initialize debug helpers */
spike_hook_init(L".\\segatools.ini");

View File

@ -24,6 +24,18 @@ const struct dll_bind_sym idac_dll_syms[] = {
}, {
.sym = "idac_io_get_analogs",
.off = offsetof(struct idac_dll, get_analogs),
}, {
.sym = "idac_io_led_init",
.off = offsetof(struct idac_dll, led_init),
}, {
.sym = "idac_io_led_set_fet_output",
.off = offsetof(struct idac_dll, led_set_fet_output),
}, {
.sym = "idac_io_led_gs_update",
.off = offsetof(struct idac_dll, led_gs_update),
}, {
.sym = "idac_io_led_set_leds",
.off = offsetof(struct idac_dll, led_set_leds),
}
};

View File

@ -11,6 +11,10 @@ struct idac_dll {
void (*get_gamebtns)(uint8_t *gamebtn);
void (*get_shifter)(uint8_t *gear);
void (*get_analogs)(struct idac_io_analog_state *out);
HRESULT (*led_init)(void);
void (*led_set_fet_output)(const uint8_t *rgb);
void (*led_gs_update)(const uint8_t *rgb);
void (*led_set_leds)(const uint8_t *rgb);
};
struct idac_dll_config {

View File

@ -17,3 +17,7 @@ EXPORTS
idac_io_get_gamebtns
idac_io_get_shifter
idac_io_get_analogs
idac_io_led_init
idac_io_led_set_fet_output
idac_io_led_gs_update
idac_io_led_set_leds

View File

@ -11,10 +11,12 @@
#include "util/dprintf.h"
static HRESULT idac_io4_poll(void *ctx, struct io4_state *state);
static HRESULT idac_io4_write_gpio(uint8_t* payload, size_t len);
static uint16_t coins;
static const struct io4_ops idac_io4_ops = {
.poll = idac_io4_poll,
.write_gpio = idac_io4_write_gpio
};
static const uint16_t idac_gear_signals[] = {
@ -128,3 +130,34 @@ static HRESULT idac_io4_poll(void *ctx, struct io4_state *state)
return S_OK;
}
static HRESULT idac_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 IDAC, 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 15070 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 ON/OFF values.
uint8_t rgb_out[6] = {
lights_data & IDAC_IO_LED_START ? 0xFF : 0x00,
lights_data & IDAC_IO_LED_VIEW_CHANGE ? 0xFF : 0x00,
lights_data & IDAC_IO_LED_UP ? 0xFF : 0x00,
lights_data & IDAC_IO_LED_DOWN ? 0xFF : 0x00,
lights_data & IDAC_IO_LED_RIGHT ? 0xFF : 0x00,
lights_data & IDAC_IO_LED_LEFT ? 0xFF : 0x00,
};
idac_dll.led_set_leds(rgb_out);
return S_OK;
}