segatools/divahook/jvs.c

110 lines
2.0 KiB
C
Raw Permalink Normal View History

#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "amex/jvs.h"
#include "board/io3.h"
2021-06-06 13:38:20 +00:00
#include "divahook/diva-dll.h"
2019-05-03 18:47:09 +00:00
#include "jvs/jvs-bus.h"
#include "util/dprintf.h"
static void diva_jvs_read_switches(void *ctx, struct io3_switch_state *out);
static void diva_jvs_read_coin_counter(
void *ctx,
uint8_t slot_no,
uint16_t *out);
static const struct io3_ops diva_jvs_io3_ops = {
.read_switches = diva_jvs_read_switches,
.read_coin_counter = diva_jvs_read_coin_counter,
};
static struct io3 diva_jvs_io3;
2019-11-03 18:01:03 +00:00
HRESULT diva_jvs_init(struct jvs_node **out)
{
2019-11-03 18:01:03 +00:00
HRESULT hr;
assert(out != NULL);
2021-06-06 13:38:20 +00:00
assert(diva_dll.jvs_init != NULL);
2019-11-03 18:01:03 +00:00
dprintf("JVS I/O: Starting Diva backend DLL\n");
2021-06-06 13:38:20 +00:00
hr = diva_dll.jvs_init();
2019-11-03 18:01:03 +00:00
if (FAILED(hr)) {
dprintf("JVS I/O: Backend error, I/O disconnected: %x\n", (int) hr);
return hr;
}
io3_init(&diva_jvs_io3, NULL, &diva_jvs_io3_ops, NULL);
2019-11-03 18:01:03 +00:00
*out = io3_to_jvs_node(&diva_jvs_io3);
return S_OK;
}
static void diva_jvs_read_switches(void *ctx, struct io3_switch_state *out)
{
2019-05-03 18:47:09 +00:00
uint8_t opbtn;
uint8_t gamebtn;
assert(out != NULL);
2021-06-06 13:38:20 +00:00
assert(diva_dll.jvs_poll != NULL);
2019-05-03 18:47:09 +00:00
opbtn = 0;
gamebtn = 0;
2021-06-06 13:38:20 +00:00
diva_dll.jvs_poll(&opbtn, &gamebtn);
2019-05-03 18:47:09 +00:00
if (gamebtn & 0x01) {
out->p1 |= 1 << 6;
}
2019-05-03 18:47:09 +00:00
if (gamebtn & 0x02) {
out->p1 |= 1 << 7;
}
2019-05-03 18:47:09 +00:00
if (gamebtn & 0x04) {
out->p1 |= 1 << 8;
}
2019-05-03 18:47:09 +00:00
if (gamebtn & 0x08) {
out->p1 |= 1 << 9;
}
2019-05-03 18:47:09 +00:00
if (gamebtn & 0x10) {
out->p1 |= 1 << 15;
}
2019-05-03 18:47:09 +00:00
if (opbtn & 0x01) {
out->system = 0x80;
} else {
out->system = 0;
}
2019-05-03 18:47:09 +00:00
if (opbtn & 0x02) {
out->p1 |= 1 << 14;
}
}
static void diva_jvs_read_coin_counter(
void *ctx,
uint8_t slot_no,
uint16_t *out)
{
2021-06-06 13:38:20 +00:00
assert(diva_dll.jvs_read_coin_counter != NULL);
if (slot_no > 0) {
return;
}
2021-06-06 13:38:20 +00:00
diva_dll.jvs_read_coin_counter(out);
}