125 lines
2.6 KiB
C
125 lines
2.6 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 "exvs2hook/jvs.h"
|
|
#include "exvs2hook/exvs2-dll.h"
|
|
|
|
static void exvs2_jvs_read_switches(void *ctx, struct najv4_switch_state *out);
|
|
static void exvs2_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out);
|
|
|
|
static const struct najv4_ops exvs2_jvs_najv4_ops = {
|
|
.read_switches = exvs2_jvs_read_switches,
|
|
.read_coin_counter = exvs2_jvs_read_coin_counter,
|
|
};
|
|
|
|
static struct najv4 exvs2_jvs_najv4;
|
|
|
|
HRESULT exvs2_jvs_init(struct jvs_node **out)
|
|
{
|
|
HRESULT hr;
|
|
|
|
assert(out != NULL);
|
|
assert(exvs2_dll.jvs_init != NULL);
|
|
|
|
dprintf("exvs2 JVS: Starting IO backend\n");
|
|
hr = exvs2_dll.jvs_init();
|
|
|
|
if (FAILED(hr)) {
|
|
dprintf("exvs2 JVS: Backend error, I/O disconnected: %x\n", (int) hr);
|
|
|
|
return hr;
|
|
}
|
|
|
|
najv4_init(&exvs2_jvs_najv4, NULL, &exvs2_jvs_najv4_ops, NULL);
|
|
*out = najv4_to_jvs_node(&exvs2_jvs_najv4);
|
|
|
|
return S_OK;
|
|
}
|
|
|
|
static void exvs2_jvs_read_switches(void *ctx, struct najv4_switch_state *out)
|
|
{
|
|
uint8_t opbtn = 0;
|
|
uint16_t gamebtn = 0;
|
|
|
|
assert(out != NULL);
|
|
assert(exvs2_dll.jvs_poll != NULL);
|
|
|
|
exvs2_dll.jvs_poll(&opbtn, &gamebtn);
|
|
|
|
out->system = 0;
|
|
out->p1 = 0;
|
|
out->p2 = 0;
|
|
|
|
|
|
if (opbtn & EXVS2_IO_OPBTN_TEST) { // Test
|
|
out->system = 0x80;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_4) { // Btn4
|
|
out->p1 |= 0x40;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_3) { // Btn3
|
|
out->p1 |= 0x80;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_2) { // Btn2
|
|
out->p1 |= 0x100;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_1) { // Btn1
|
|
out->p1 |= 0x200;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_RIGHT) { // Right
|
|
out->p1 |= 0x400;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_LEFT) { // Left
|
|
out->p1 |= 0x800;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_DOWN) { // Down
|
|
out->p1 |= 0x1000;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_UP) { // Up
|
|
out->p1 |= 0x2000;
|
|
}
|
|
|
|
if (opbtn & EXVS2_IO_OPBTN_SERVICE) { // Service
|
|
out->p1 |= 0x4000;
|
|
}
|
|
|
|
if (gamebtn & EXVS2_IO_GAMEBTN_START) { // Start
|
|
out->p1 = 0x8000;
|
|
}
|
|
}
|
|
|
|
static void exvs2_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out)
|
|
{
|
|
assert(out != NULL);
|
|
assert(exvs2_dll.jvs_read_coin_counter != NULL);
|
|
|
|
if (slot_no > 0) {
|
|
return;
|
|
}
|
|
|
|
exvs2_dll.jvs_read_coin_counter(out);
|
|
} |