forked from Hay1tsme/segatools
186 lines
3.6 KiB
C
186 lines
3.6 KiB
C
|
#include <windows.h>
|
||
|
|
||
|
#include <assert.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
#include "board/io4.h"
|
||
|
|
||
|
#include "mai2hook/mai2-dll.h"
|
||
|
|
||
|
#include "util/dprintf.h"
|
||
|
|
||
|
bool mai2_io_coin = false;
|
||
|
uint16_t mai2_io_coins = 0;
|
||
|
|
||
|
static HRESULT mai2_io4_poll(void *ctx, struct io4_state *state);
|
||
|
static uint16_t coins;
|
||
|
|
||
|
static const struct io4_ops mai2_io4_ops = {
|
||
|
.poll = mai2_io4_poll,
|
||
|
};
|
||
|
|
||
|
HRESULT mai2_io4_hook_init(const struct io4_config *cfg)
|
||
|
{
|
||
|
HRESULT hr;
|
||
|
|
||
|
assert(mai2_dll.init != NULL);
|
||
|
|
||
|
hr = io4_hook_init(cfg, &mai2_io4_ops, NULL);
|
||
|
|
||
|
if (FAILED(hr)) {
|
||
|
return hr;
|
||
|
}
|
||
|
|
||
|
return mai2_dll.init();
|
||
|
}
|
||
|
|
||
|
static HRESULT mai2_io4_poll(void *ctx, struct io4_state *state)
|
||
|
{
|
||
|
uint8_t opbtn = 0;
|
||
|
uint8_t player1 = 0;
|
||
|
uint8_t player2 = 0;
|
||
|
HRESULT hr;
|
||
|
|
||
|
assert(mai2_dll.poll != NULL);
|
||
|
|
||
|
hr = mai2_dll.poll(&opbtn, &player1, &player2);
|
||
|
uint8_t opbtn;
|
||
|
uint16_t player1;
|
||
|
uint16_t player2;
|
||
|
HRESULT hr;
|
||
|
|
||
|
assert(mai2_dll.poll != NULL);
|
||
|
assert(mai2_dll.get_opbtns != NULL);
|
||
|
assert(mai2_dll.get_gamebtns != NULL);
|
||
|
|
||
|
memset(state, 0, sizeof(*state));
|
||
|
|
||
|
hr = mai2_dll.poll();
|
||
|
|
||
|
if (FAILED(hr)) {
|
||
|
return hr;
|
||
|
}
|
||
|
|
||
|
opbtn = 0;
|
||
|
player1 = 0;
|
||
|
player2 = 0;
|
||
|
|
||
|
mai2_dll.get_opbtns(&opbtn);
|
||
|
mai2_dll.get_gamebtns(&player1, &player2);
|
||
|
|
||
|
if (opbtn & MAI2_IO_OPBTN_TEST) {
|
||
|
state->buttons[0] |= IO4_BUTTON_TEST;
|
||
|
}
|
||
|
|
||
|
if (opbtn & MAI2_IO_OPBTN_SERVICE) {
|
||
|
state->buttons[0] |= IO4_BUTTON_SERVICE;
|
||
|
}
|
||
|
|
||
|
if (opbtn & MAI2_IO_P1_START) {
|
||
|
state->buttons[0] |= 1 << 1;
|
||
|
}
|
||
|
|
||
|
if (opbtn & MAI2_IO_P2_START) {
|
||
|
state->buttons[1] |= 1 << 4;
|
||
|
}
|
||
|
|
||
|
if (opbtn & MAI2_IO_OPBTN_COIN) {
|
||
|
coins++;
|
||
|
}
|
||
|
state->chutes[0] = coins << 8;
|
||
|
|
||
|
// Buttons around screen are active-low, select button is active-high
|
||
|
|
||
|
// Player 1
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_1)) {
|
||
|
state->buttons[0] |= 1 << 2;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_2)) {
|
||
|
state->buttons[0] |= 1 << 3;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_3)) {
|
||
|
state->buttons[0] |= 1 << 0;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_4)) {
|
||
|
state->buttons[0] |= 1 << 15;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_5)) {
|
||
|
state->buttons[0] |= 1 << 14;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_6)) {
|
||
|
state->buttons[0] |= 1 << 13;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_7)) {
|
||
|
state->buttons[0] |= 1 << 12;
|
||
|
}
|
||
|
|
||
|
if (!(player1 & MAI2_IO_GAMEBTN_8)) {
|
||
|
state->buttons[0] |= 1 << 11;
|
||
|
}
|
||
|
|
||
|
if (player1 & MAI2_IO_GAMEBTN_SELECT) {
|
||
|
state->buttons[0] |= 1 << 1;
|
||
|
}
|
||
|
|
||
|
// Player 2
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_1)) {
|
||
|
state->buttons[1] |= 1 << 2;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_2)) {
|
||
|
state->buttons[1] |= 1 << 3;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_3)) {
|
||
|
state->buttons[1] |= 1 << 0;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_4)) {
|
||
|
state->buttons[1] |= 1 << 15;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_5)) {
|
||
|
state->buttons[1] |= 1 << 14;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_6)) {
|
||
|
state->buttons[1] |= 1 << 13;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_7)) {
|
||
|
state->buttons[1] |= 1 << 12;
|
||
|
}
|
||
|
|
||
|
if (!(player2 & MAI2_IO_GAMEBTN_8)) {
|
||
|
state->buttons[1] |= 1 << 11;
|
||
|
}
|
||
|
|
||
|
|
||
|
if (opbtn & MAI2_IO_OPBTN_COIN) {
|
||
|
if (!mai2_io_coin) {
|
||
|
mai2_io_coin = true;
|
||
|
mai2_io_coins++;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
mai2_io_coin = false;
|
||
|
}
|
||
|
|
||
|
state->chutes[0] = 128 + 256 * mai2_io_coins;
|
||
|
if (player2 & MAI2_IO_GAMEBTN_SELECT) {
|
||
|
state->buttons[1] |= 1 << 4;
|
||
|
}
|
||
|
|
||
|
return S_OK;
|
||
|
}
|