bananatools/saohook/usio.c

100 lines
2.1 KiB
C

#include <windows.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "board/usio.h"
#include "saohook/sao-dll.h"
#include "util/dprintf.h"
bool sao_io_coin = false;
uint16_t sao_io_coins = 0;
static HRESULT sao_usio_poll(void *ctx, struct usio_state *state);
static const struct usio_ops sao_usio_ops = {
.poll = sao_usio_poll,
};
HRESULT sao_usio_hook_init(const struct usio_config *cfg)
{
HRESULT hr;
assert(sao_dll.init != NULL);
hr = usio_hook_init(cfg, &sao_usio_ops, NULL, NULL);
if (FAILED(hr)) {
return hr;
}
dprintf("Sao USIO: Init\n");
return sao_dll.init();
}
static HRESULT sao_usio_poll(void *ctx, struct usio_state *state)
{
uint8_t opbtn_out = 0;
uint8_t gamebtn_out = 0;
uint8_t x = 128;
uint8_t y = 128;
uint16_t coin_ct = 0;
uint16_t service_ct = 0;
sao_dll.get_opbtns(&opbtn_out);
sao_dll.get_analog(&x, &y);
sao_dll.read_coin_counter(&coin_ct, &service_ct);
sao_dll.get_gamebtns(&gamebtn_out);
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
}
if (gamebtn_out & 0x01) {
state->p1_btns |= 0x2000;
}
if (gamebtn_out & 0x02) {
state->p1_btns |= 0x1000;
}
if (gamebtn_out & 0x04) {
state->p1_btns |= 0x0800;
}
if (gamebtn_out & 0x08) {
state->p1_btns |= 0x4000;
}
if (gamebtn_out & 0x10) {
state->p1_btns |= 0x01;
}
if (gamebtn_out & 0x20) {
state->p1_btns |= 0x8000;
}
state->analog[0] = x << 8;
state->analog[1] = y << 8;
state->coins[0].current_coin_count = coin_ct;
state->service.current_coin_count = service_ct;
return S_OK;
}