1
0
mirror of synced 2024-11-24 05:50:12 +01:00
bananatools/tekkenhook/jvs.c
Kevin Trocolli cd10a98dcc tekken: fix io
platform: add gethostbyname hook
2023-11-12 05:13:44 -05:00

119 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 "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;
uint16_t gamebtn = 0;
//dprintf("Tekken JVS: Read Switches\n");
assert(out != NULL);
assert(tekken_dll.jvs_poll != NULL);
tekken_dll.jvs_poll(&opbtn, &gamebtn);
out->system = 0;
out->p1 = 0;
out->p2 = 0;
if (opbtn & 0x01) { // Test
out->system = 0x80;
}
if (opbtn & 0x02) { // Service
out->p1 |= 0x4000;
}
if (gamebtn & 0x01) { // Up
out->p1 |= 0x2000;
}
if (gamebtn & 0x02) { // Down
out->p1 |= 0x1000;
}
if (gamebtn & 0x04) { // Left
out->p1 |= 0x0800;
}
if (gamebtn & 0x08) { // Right
out->p1 |= 0x0400;
}
if (gamebtn & 0x10) { // Start
out->p1 |= 0x8000;
}
if (gamebtn & 0x20) { // P1B1
out->p1 |= 0x0200;
}
if (gamebtn & 0x40) { // P1B2
out->p1 |= 0x0100;
}
if (gamebtn & 0x80) { // P1B3
out->p1 |= 0x0040;
}
if (gamebtn & 0x100) { // P1B4
out->p1 |= 0x0020;
}
}
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);
}