#include #include #include #include #include #include #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 "ferrumhook/jvs.h" #include "ferrumhook/ferrum-dll.h" static void ferrum_jvs_read_switches(void *ctx, struct najv4_switch_state *out); static void ferrum_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out); static const struct najv4_ops ferrum_jvs_najv4_ops = { .read_switches = ferrum_jvs_read_switches, .read_coin_counter = ferrum_jvs_read_coin_counter, }; static struct najv4 ferrum_jvs_najv4; HRESULT ferrum_jvs_init(struct jvs_node **out) { HRESULT hr; assert(out != NULL); assert(ferrum_dll.jvs_init != NULL); dprintf("Ferrum JVS: Starting IO backend\n"); hr = ferrum_dll.jvs_init(); if (FAILED(hr)) { dprintf("Ferrum JVS: Backend error, I/O disconnected: %x\n", (int) hr); return hr; } najv4_init(&ferrum_jvs_najv4, NULL, &ferrum_jvs_najv4_ops, NULL); *out = najv4_to_jvs_node(&ferrum_jvs_najv4); return S_OK; } static void ferrum_jvs_read_switches(void *ctx, struct najv4_switch_state *out) { uint8_t opbtn = 0; //dprintf("Ferrum JVS: Read Switches\n"); assert(out != NULL); assert(ferrum_dll.jvs_poll != NULL); ferrum_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 ferrum_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out) { //dprintf("Ferrum JVS: Read coin counter\n"); assert(out != NULL); assert(ferrum_dll.jvs_read_coin_counter != NULL); if (slot_no > 0) { return; } ferrum_dll.jvs_read_coin_counter(out); }