100 lines
2.1 KiB
C
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 "tekkenhook/jvs.h"
|
||
|
#include "tekkenhook/tekken-dll.h"
|
||
|
|
||
|
static void tekken_jvs_read_switches(void *ctx, struct najv4_switch_state *out);
|
||
|
static void tekken_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out);
|
||
|
|
||
|
static const struct najv4_ops tekken_jvs_najv4_ops = {
|
||
|
.read_switches = tekken_jvs_read_switches,
|
||
|
.read_coin_counter = tekken_jvs_read_coin_counter,
|
||
|
};
|
||
|
|
||
|
static struct najv4 tekken_jvs_najv4;
|
||
|
|
||
|
HRESULT tekken_jvs_init(struct jvs_node **out)
|
||
|
{
|
||
|
HRESULT hr;
|
||
|
|
||
|
assert(out != NULL);
|
||
|
assert(tekken_dll.jvs_init != NULL);
|
||
|
|
||
|
dprintf("Tekken JVS: Starting IO backend\n");
|
||
|
hr = tekken_dll.jvs_init();
|
||
|
|
||
|
if (FAILED(hr)) {
|
||
|
dprintf("Tekken JVS: Backend error, I/O disconnected: %x\n", (int) hr);
|
||
|
|
||
|
return hr;
|
||
|
}
|
||
|
|
||
|
najv4_init(&tekken_jvs_najv4, NULL, &tekken_jvs_najv4_ops, NULL);
|
||
|
*out = najv4_to_jvs_node(&tekken_jvs_najv4);
|
||
|
|
||
|
return S_OK;
|
||
|
}
|
||
|
|
||
|
static void tekken_jvs_read_switches(void *ctx, struct najv4_switch_state *out)
|
||
|
{
|
||
|
uint8_t opbtn = 0;
|
||
|
|
||
|
//dprintf("Tekken JVS: Read Switches\n");
|
||
|
|
||
|
assert(out != NULL);
|
||
|
assert(tekken_dll.jvs_poll != NULL);
|
||
|
|
||
|
tekken_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 tekken_jvs_read_coin_counter(void *ctx, uint8_t slot_no, uint16_t *out)
|
||
|
{
|
||
|
//dprintf("Tekken JVS: Read coin counter\n");
|
||
|
|
||
|
assert(out != NULL);
|
||
|
assert(tekken_dll.jvs_read_coin_counter != NULL);
|
||
|
|
||
|
if (slot_no > 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
tekken_dll.jvs_read_coin_counter(out);
|
||
|
}
|