1
0
mirror of synced 2024-12-17 22:55:52 +01:00
bananatools/mkachook/jvs.c
Kevin Trocolli 8ff356b84c add games
2023-09-18 04:05:22 -04:00

100 lines
2.1 KiB
C

#include <windows.h>
#include <assert.h>
#include <process.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "hook/iobuf.h"
#include "hook/iohook.h"
#include "hooklib/uart.h"
#include "hooklib/fdshark.h"
#include "util/dprintf.h"
#include "util/dump.h"
#include "board/najv4.h"
#include "mkachook/jvs.h"
#include "mkachook/mkac-dll.h"
static void mkac_jvs_read_switches(void *ctx, struct najv4_switch_state *out);
static void mkac_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out);
static const struct najv4_ops mkac_jvs_najv4_ops = {
.read_switches = mkac_jvs_read_switches,
.read_coin_counter = mkac_jvs_read_coin_counter,
};
static struct najv4 mkac_jvs_najv4;
HRESULT mkac_jvs_init(struct jvs_node **out)
{
HRESULT hr;
assert(out != NULL);
assert(mkac_dll.jvs_init != NULL);
dprintf("mkac JVS: Starting IO backend\n");
hr = mkac_dll.jvs_init();
if (FAILED(hr)) {
dprintf("mkac JVS: Backend error, I/O disconnected: %x\n", (int) hr);
return hr;
}
najv4_init(&mkac_jvs_najv4, NULL, &mkac_jvs_najv4_ops, NULL);
*out = najv4_to_jvs_node(&mkac_jvs_najv4);
return S_OK;
}
static void mkac_jvs_read_switches(void *ctx, struct najv4_switch_state *out)
{
uint8_t opbtn = 0;
//dprintf("mkac JVS: Read Switches\n");
assert(out != NULL);
assert(mkac_dll.jvs_poll != NULL);
mkac_dll.jvs_poll(&opbtn);
out->system = 0;
out->p1 = 0;
out->p2 = 0;
if (opbtn & 0x01) { // Test
out->system = 0x80;
}
if (opbtn & 0x02) { // Service
out->p1 |= 0x4000;
}
if (opbtn & 0x04) { // Up
out->p1 |= 0x2000;
}
if (opbtn & 0x08) { // Down
out->p1 |= 0x1000;
}
if (opbtn & 0x10) { // Enter
out->p1 |= 0x0200;
}
}
static void mkac_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out)
{
//dprintf("mkac JVS: Read coin counter\n");
assert(out != NULL);
assert(mkac_dll.jvs_read_coin_counter != NULL);
if (slot_no > 0) {
return;
}
mkac_dll.jvs_read_coin_counter(out);
}