82 lines
1.7 KiB
C
82 lines
1.7 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 analog_out = 0;
|
||
|
uint16_t coin_ct = 0;
|
||
|
uint16_t service_ct = 0;
|
||
|
sao_dll.get_opbtns(&opbtn_out);
|
||
|
sao_dll.get_drum_analog(&analog_out);
|
||
|
sao_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;
|
||
|
}
|