mai2: segatools added

This commit is contained in:
2023-07-14 01:00:28 +02:00
parent 01be6ee33c
commit 0ee081ca1b
20 changed files with 1000 additions and 0 deletions

48
mai2io/config.c Normal file
View File

@ -0,0 +1,48 @@
#include <windows.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include "mai2io/config.h"
/*
Maimai DX Default key binding
1P: self-explanatory
2P: (Numpad) 8, 9, 6, 3, 2, 1, 4, 7, *
*/
static const int mai2_io_1p_default[] = {'W', 'E', 'D', 'C', 'X', 'Z', 'A', 'Q', '3'};
static const int mai2_io_2p_default[] = {0x68, 0x69, 0x66, 0x63, 0x62, 0x61, 0x64, 0x67, 0x54};
void mai2_io_config_load(
struct mai2_io_config *cfg,
const wchar_t *filename)
{
wchar_t key[16];
int i;
assert(cfg != NULL);
assert(filename != NULL);
cfg->vk_test = GetPrivateProfileIntW(L"io4", L"test", '1', filename);
cfg->vk_service = GetPrivateProfileIntW(L"io4", L"service", '2', filename);
cfg->vk_coin = GetPrivateProfileIntW(L"io4", L"coin", '3', filename);
for (i = 0 ; i < 9 ; i++) {
swprintf_s(key, _countof(key), L"1p_btn%i", i + 1);
cfg->vk_1p_btn[i] = GetPrivateProfileIntW(
L"button",
key,
mai2_io_1p_default[i],
filename);
}
for (i = 0 ; i < 9 ; i++) {
swprintf_s(key, _countof(key), L"2p_btn%i", i + 1);
cfg->vk_2p_btn[i] = GetPrivateProfileIntW(
L"button",
key,
mai2_io_2p_default[i],
filename);
}
}

18
mai2io/config.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
struct mai2_io_config {
uint8_t vk_test;
uint8_t vk_service;
uint8_t vk_coin;
uint8_t vk_1p_btn[9];
uint8_t vk_2p_btn[9];
};
void mai2_io_config_load(
struct mai2_io_config *cfg,
const wchar_t *filename);

143
mai2io/mai2io.c Normal file
View File

@ -0,0 +1,143 @@
#include <windows.h>
#include <limits.h>
#include <stdint.h>
#include "mai2io/mai2io.h"
#include "mai2io/config.h"
static uint8_t mai2_opbtn;
static uint16_t mai2_player1_btn;
static uint16_t mai2_player2_btn;
static struct mai2_io_config mai2_io_cfg;
static bool mai2_io_coin;
uint16_t mai2_io_get_api_version(void)
{
return 0x0100;
}
HRESULT mai2_io_init(void)
{
mai2_io_config_load(&mai2_io_cfg, L".\\segatools.ini");
return S_OK;
}
HRESULT mai2_io_poll(void)
{
mai2_opbtn = 0;
mai2_player1_btn = 0;
mai2_player2_btn = 0;
if (GetAsyncKeyState(mai2_io_cfg.vk_test) & 0x8000) {
mai2_opbtn |= MAI2_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_service) & 0x8000) {
mai2_opbtn |= MAI2_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_coin) & 0x8000) {
if (!mai2_io_coin) {
mai2_io_coin = true;
mai2_opbtn |= MAI2_IO_OPBTN_COIN;
}
} else {
mai2_io_coin = false;
}
//Player 1
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[0])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_1;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[1])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_2;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[2])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_3;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[3])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_4;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[4])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_5;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[5])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_6;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[6])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_7;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[7])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_8;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_1p_btn[8])) {
mai2_player1_btn |= MAI2_IO_GAMEBTN_SELECT;
}
//Player 2
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[0])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_1;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[1])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_2;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[2])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_3;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[3])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_4;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[4])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_5;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[5])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_6;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[6])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_7;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[7])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_8;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_2p_btn[8])) {
mai2_player2_btn |= MAI2_IO_GAMEBTN_SELECT;
}
return S_OK;
}
void mai2_io_get_opbtns(uint8_t *opbtn)
{
if (opbtn != NULL) {
*opbtn = mai2_opbtn;
}
}
void mai2_io_get_gamebtns(uint16_t *player1, uint16_t *player2)
{
if (player1 != NULL) {
*player1 = mai2_player1_btn;
}
if (player2 != NULL ){
*player2 = mai2_player2_btn;
}
}

68
mai2io/mai2io.h Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include <windows.h>
#include <stdint.h>
enum {
MAI2_IO_OPBTN_TEST = 0x01,
MAI2_IO_OPBTN_SERVICE = 0x02,
MAI2_IO_OPBTN_COIN = 0x04,
};
enum {
MAI2_IO_GAMEBTN_1 = 0x01,
MAI2_IO_GAMEBTN_2 = 0x02,
MAI2_IO_GAMEBTN_3 = 0x04,
MAI2_IO_GAMEBTN_4 = 0x08,
MAI2_IO_GAMEBTN_5 = 0x10,
MAI2_IO_GAMEBTN_6 = 0x20,
MAI2_IO_GAMEBTN_7 = 0x40,
MAI2_IO_GAMEBTN_8 = 0x80,
MAI2_IO_GAMEBTN_SELECT = 0x100,
};
/* Get the version of the Maimai IO API that this DLL supports. This
function should return a positive 16-bit integer, where the high byte is
the major version and the low byte is the minor version (as defined by the
Semantic Versioning standard).
The latest API version as of this writing is 0x0100. */
uint16_t mai2_io_get_api_version(void);
/* Initialize the IO DLL. This is the second function that will be called on
your DLL, after mai2_io_get_api_version.
All subsequent calls to this API may originate from arbitrary threads.
Minimum API version: 0x0100 */
HRESULT mai2_io_init(void);
/* Send any queued outputs (of which there are currently none, though this may
change in subsequent API versions) and retrieve any new inputs.
Minimum API version: 0x0100 */
HRESULT mai2_io_poll(void);
/* Get the state of the cabinet's operator buttons as of the last poll. See
MAI2_IO_OPBTN enum above: this contains bit mask definitions for button
states returned in *opbtn. All buttons are active-high.
Minimum API version: 0x0100 */
void mai2_io_get_opbtns(uint8_t *opbtn);
/* Get the state of the cabinet's gameplay buttons as of the last poll. See
MAI2_IO_GAMEBTN enum above for bit mask definitions. Inputs are split into
a left hand side set of inputs and a right hand side set of inputs: the bit
mappings are the same in both cases.
All buttons are active-high, even though some buttons' electrical signals
on a real cabinet are active-low.
Minimum API version: 0x0100 */
void mai2_io_get_gamebtns(uint16_t *player1, uint16_t *player2);

13
mai2io/meson.build Normal file
View File

@ -0,0 +1,13 @@
mai2io_lib = static_library(
'mai2io',
name_prefix : '',
include_directories : inc,
implicit_include_directories : false,
c_pch : '../precompiled.h',
sources : [
'mai2io.c',
'mai2io.h',
'config.c',
'config.h',
],
)