2019-08-30 23:05:52 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "board/io4.h"
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
#include "mu3hook/mu3-dll.h"
|
2019-08-30 23:05:52 +00:00
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
|
|
|
static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state);
|
2023-07-13 22:54:30 +00:00
|
|
|
static uint16_t coins;
|
2019-08-30 23:05:52 +00:00
|
|
|
|
|
|
|
static const struct io4_ops mu3_io4_ops = {
|
|
|
|
.poll = mu3_io4_poll,
|
|
|
|
};
|
|
|
|
|
2020-10-07 17:26:12 +00:00
|
|
|
HRESULT mu3_io4_hook_init(const struct io4_config *cfg)
|
2019-08-30 23:05:52 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
assert(mu3_dll.init != NULL);
|
|
|
|
|
2020-10-07 17:26:12 +00:00
|
|
|
hr = io4_hook_init(cfg, &mu3_io4_ops, NULL);
|
2019-08-30 23:05:52 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
return mu3_dll.init();
|
2019-08-30 23:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state)
|
|
|
|
{
|
|
|
|
uint8_t opbtn;
|
|
|
|
uint8_t left;
|
|
|
|
uint8_t right;
|
|
|
|
int16_t lever;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
assert(mu3_dll.poll != NULL);
|
|
|
|
assert(mu3_dll.get_opbtns != NULL);
|
|
|
|
assert(mu3_dll.get_gamebtns != NULL);
|
|
|
|
assert(mu3_dll.get_lever != NULL);
|
|
|
|
|
2019-08-30 23:05:52 +00:00
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
hr = mu3_dll.poll();
|
2019-08-30 23:05:52 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
opbtn = 0;
|
|
|
|
left = 0;
|
|
|
|
right = 0;
|
|
|
|
lever = 0;
|
|
|
|
|
2021-06-06 18:23:55 +00:00
|
|
|
mu3_dll.get_opbtns(&opbtn);
|
|
|
|
mu3_dll.get_gamebtns(&left, &right);
|
|
|
|
mu3_dll.get_lever(&lever);
|
2019-08-30 23:05:52 +00:00
|
|
|
|
|
|
|
if (opbtn & MU3_IO_OPBTN_TEST) {
|
|
|
|
state->buttons[0] |= IO4_BUTTON_TEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opbtn & MU3_IO_OPBTN_SERVICE) {
|
|
|
|
state->buttons[0] |= IO4_BUTTON_SERVICE;
|
|
|
|
}
|
|
|
|
|
2023-07-13 22:54:30 +00:00
|
|
|
if (opbtn & MU3_IO_OPBTN_COIN) {
|
|
|
|
coins++;
|
|
|
|
}
|
|
|
|
state->chutes[0] = coins << 8;
|
|
|
|
|
2019-08-30 23:05:52 +00:00
|
|
|
if (left & MU3_IO_GAMEBTN_1) {
|
|
|
|
state->buttons[0] |= 1 << 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left & MU3_IO_GAMEBTN_2) {
|
|
|
|
state->buttons[0] |= 1 << 5;
|
|
|
|
}
|
|
|
|
|
2019-11-04 00:55:02 +00:00
|
|
|
if (left & MU3_IO_GAMEBTN_3) {
|
2019-08-30 23:05:52 +00:00
|
|
|
state->buttons[0] |= 1 << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right & MU3_IO_GAMEBTN_1) {
|
|
|
|
state->buttons[0] |= 1 << 1;
|
|
|
|
}
|
|
|
|
|
2019-11-04 00:55:02 +00:00
|
|
|
if (right & MU3_IO_GAMEBTN_2) {
|
2019-08-30 23:05:52 +00:00
|
|
|
state->buttons[1] |= 1 << 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right & MU3_IO_GAMEBTN_3) {
|
|
|
|
state->buttons[0] |= 1 << 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left & MU3_IO_GAMEBTN_MENU) {
|
|
|
|
state->buttons[1] |= 1 << 14;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right & MU3_IO_GAMEBTN_MENU) {
|
|
|
|
state->buttons[0] |= 1 << 13;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(left & MU3_IO_GAMEBTN_SIDE)) {
|
|
|
|
state->buttons[1] |= 1 << 15; /* L-Side, active-low */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(right & MU3_IO_GAMEBTN_SIDE)) {
|
|
|
|
state->buttons[0] |= 1 << 14; /* R-Side, active-low */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lever increases right-to-left, not left-to-right.
|
|
|
|
|
|
|
|
Use 0x7FFF as the center point instead of 0x8000; the latter would
|
|
|
|
overflow when the lever pos is INT16_MIN. */
|
|
|
|
|
|
|
|
state->adcs[0] = 0x7FFF - lever;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|