1
0
mirror of synced 2024-11-30 16:24:27 +01:00
bananatools/taikohook/usio.c

89 lines
1.9 KiB
C
Raw Normal View History

#include <windows.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "board/usio.h"
#include "taikohook/taiko-dll.h"
#include "util/dprintf.h"
bool taiko_io_coin = false;
uint16_t taiko_io_coins = 0;
static HRESULT taiko_usio_poll(void *ctx, struct usio_state *state);
static const struct usio_ops taiko_usio_ops = {
.poll = taiko_usio_poll,
};
HRESULT taiko_usio_hook_init(const struct usio_config *cfg)
{
HRESULT hr;
2023-07-29 08:51:58 +02:00
HANDLE modAmfw;
assert(taiko_dll.init != NULL);
2023-07-29 08:51:58 +02:00
modAmfw = GetModuleHandle("AMFrameWork.dll");
if (modAmfw == NULL) {
dprintf("Taiko USIO: AMFrameWork.dll not loaded, cannot hook bnusio.\n");
return S_OK;
}
hr = usio_hook_init(cfg, &taiko_usio_ops, NULL, modAmfw);
if (FAILED(hr)) {
return hr;
}
dprintf("Taiko USIO: Init\n");
return taiko_dll.init();
}
static HRESULT taiko_usio_poll(void *ctx, struct usio_state *state)
{
2023-07-29 08:51:58 +02:00
uint8_t opbtn_out = 0;
uint8_t analog_out = 0;
uint16_t coin_ct = 0;
uint16_t service_ct = 0;
taiko_dll.get_opbtns(&opbtn_out);
taiko_dll.get_drum_analog(&analog_out);
taiko_dll.read_coin_counter(&coin_ct, &service_ct);
state->op_btns = 0;
state->p1_btns = 0;
state->p2_btns = 0;
if (opbtn_out & 0x01) {
state->op_btns |= 0x80; // Test
}
if (opbtn_out & 0x02) {
state->p1_btns |= 0x40; // Service
}
if (opbtn_out & 0x04) {
state->p1_btns |= 0x20; // Up
}
if (opbtn_out & 0x08) {
state->p1_btns |= 0x10; // Down
}
if (opbtn_out & 0x10) {
state->p1_btns |= 0x02; // Enter
}
for (int i = 0; i < _countof(state->analog); i++) {
if (analog_out & 1 << i) {
state->analog[i] = 0x3FFF;
} else {
state->analog[i] = 0x00;
}
}
state->coins[0].current_coin_count = coin_ct;
state->service.current_coin_count = service_ct;
return S_OK;
}