Removed mai2io dll

This commit is contained in:
whowechina 2023-10-14 14:43:48 +08:00
parent 9679b95de9
commit 7c80402246
6 changed files with 0 additions and 430 deletions

View File

@ -1,50 +0,0 @@
#include <windows.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.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);
cfg->swap_btn = GetPrivateProfileIntW(L"io4", L"swap", '4', 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);
}
}

View File

@ -1,19 +0,0 @@
#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];
uint8_t swap_btn;
};
void mai2_io_config_load(
struct mai2_io_config *cfg,
const wchar_t *filename);

View File

@ -1,232 +0,0 @@
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <stdint.h>
#include <stdbool.h>
#include <hidsdi.h>
#include <setupapi.h>
#include "mai2io/mai2io.h"
#include "mai2io/config.h"
static FILE *logfile;
static GUID hidclass_guid = {0x745a17a0, 0x74d3, 0x11d0, {0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda}};
static BOOLEAN get_device_path(char *lPath, uint16_t vid, uint16_t pid, int8_t mi, const char *skip)
{
const GUID *guid = &hidclass_guid;
HidD_GetHidGuid(&hidclass_guid);
// Get device interface info set handle
// for all devices attached to system
HDEVINFO hDevInfo = SetupDiGetClassDevs(guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // Function class devices.
if (hDevInfo == INVALID_HANDLE_VALUE) {
return FALSE;
}
// Retrieve a context structure for a device interface of a device information set.
BYTE buf[1024];
PSP_DEVICE_INTERFACE_DETAIL_DATA pspdidd = (PSP_DEVICE_INTERFACE_DETAIL_DATA)buf;
SP_DEVICE_INTERFACE_DATA spdid;
SP_DEVINFO_DATA spdd;
DWORD dwSize;
char pidstr[16];
char vidstr[16];
char mistr[16];
sprintf(pidstr, "pid_%04x&", pid);
sprintf(vidstr, "vid_%04x&", vid);
sprintf(mistr, "&mi_%02x", mi);
printf("Looking up `%s` skip `%s`.\n", vidstr,
skip ? skip : "none");
spdid.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for (DWORD i = 0; SetupDiEnumDeviceInterfaces(hDevInfo, NULL, guid, i, &spdid); i++) {
dwSize = 0;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &spdid, NULL, 0, &dwSize, NULL);
if (dwSize == 0 || dwSize > sizeof(buf)) {
continue;
}
pspdidd->cbSize = sizeof(*pspdidd);
ZeroMemory((PVOID)&spdd, sizeof(spdd));
spdd.cbSize = sizeof(spdd);
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo, &spdid, pspdidd,
dwSize, &dwSize, &spdd)) {
continue;
}
if (strstr(pspdidd->DevicePath, vidstr) == NULL ||
((mi != -1) && strstr(pspdidd->DevicePath, mistr) == NULL)) {
continue;
}
if (skip != NULL && strcmp(pspdidd->DevicePath, skip) == 0) {
fprintf(logfile, "DevicePath already used: %s\n", skip);
continue;
}
fprintf(logfile, "Found Device: %s\n", pspdidd->DevicePath);
strcpy(lPath, pspdidd->DevicePath);
SetupDiDestroyDeviceInfoList(hDevInfo);
return TRUE;
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return FALSE;
}
HANDLE hid_open_device(uint16_t vid, uint16_t pid, uint8_t mi, bool first)
{
static char path1[256];
static char path2[256];
char *path = first ? path1 : path2;
const char *skip = first ? NULL : path1;
if (!get_device_path(path, vid, pid, mi, skip)) {
return INVALID_HANDLE_VALUE;
}
fprintf(logfile, "Opening Device: %s\n", path);
fflush(logfile);
return CreateFile(path, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
}
static bool hid_get_report(HANDLE handle, uint8_t *buf, uint8_t report_id, uint8_t size)
{
DWORD bytesRead = 0;
uint8_t tmp_buf[128];
tmp_buf[0] = report_id;
if (!ReadFile(handle, tmp_buf, 3 * size, &bytesRead, NULL)) {
return false;
}
if (bytesRead == 0 || bytesRead % size != 0) {
return false;
}
/* only the latest report */
memcpy(buf, tmp_buf + bytesRead - size, size);
return true;
}
static uint8_t mai2_opbtn;
static uint16_t mai2_p1_btn;
static uint16_t mai2_p2_btn;
static struct mai2_io_config mai2_io_cfg;
static bool mai2_io_coin;
uint16_t mai2_io_get_api_version(void)
{
return 0x0100;
}
static HANDLE joy1_handle;
static HANDLE joy2_handle;
HRESULT mai2_io_init(void)
{
mai2_io_config_load(&mai2_io_cfg, L".\\segatools.ini");
logfile = fopen(".\\mai2_log.txt", "w+");
joy1_handle = hid_open_device(0x0f0d, 0x0092, 0, true);
fprintf(logfile, "Handle1: %Id\n", (intptr_t)joy1_handle);
fflush(logfile);
joy2_handle = hid_open_device(0x0f0d, 0x0092, 0, false);
fprintf(logfile, "Handle2: %Id\n", (intptr_t)joy2_handle);
fflush(logfile);
if (joy1_handle != INVALID_HANDLE_VALUE) {
fprintf(logfile, "Joy1 OK\n");
HidD_SetNumInputBuffers(joy1_handle, 2);
}
if (joy2_handle != INVALID_HANDLE_VALUE) {
fprintf(logfile, "Joy2 OK\n");
HidD_SetNumInputBuffers(joy2_handle, 2);
}
fprintf(logfile, "MAI2 JOY Init Done\n");
fflush(logfile);
fclose(logfile);
return S_OK;
}
#pragma pack(1)
typedef struct joy_report_s {
uint8_t report_id;
uint16_t buttons; // 16 buttons; see JoystickButtons_t for bit mapping
uint8_t HAT; // HAT switch; one nibble w/ unused nibble
uint32_t axis;
uint8_t VendorSpec;
} joy_report_t;
HRESULT mai2_io_poll(void)
{
uint8_t opbtn = 0;
if (GetAsyncKeyState(mai2_io_cfg.vk_test) & 0x8000) {
opbtn |= MAI2_IO_OPBTN_TEST;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_service) & 0x8000) {
opbtn |= MAI2_IO_OPBTN_SERVICE;
}
if (GetAsyncKeyState(mai2_io_cfg.vk_coin) & 0x8000) {
if (!mai2_io_coin) {
mai2_io_coin = true;
opbtn |= MAI2_IO_OPBTN_COIN;
}
} else {
mai2_io_coin = false;
}
mai2_opbtn = opbtn;
if (joy1_handle != INVALID_HANDLE_VALUE) {
joy_report_t joy_data;
if (hid_get_report(joy1_handle, (uint8_t *)&joy_data, 0x01, sizeof(joy_data))) {
if (mai2_io_cfg.swap_btn) {
mai2_p2_btn = joy_data.buttons;
} else {
mai2_p1_btn = joy_data.buttons;
}
}
}
if (joy2_handle != INVALID_HANDLE_VALUE) {
joy_report_t joy_data;
if (hid_get_report(joy2_handle, (uint8_t *)&joy_data, 0x01, sizeof(joy_data))) {
if (mai2_io_cfg.swap_btn) {
mai2_p1_btn = joy_data.buttons;
} else {
mai2_p2_btn = joy_data.buttons;
}
}
}
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_p1_btn;
}
if (player2 != NULL ){
*player2 = mai2_p2_btn;
}
}

View File

@ -1,8 +0,0 @@
LIBRARY mai2io
EXPORTS
mai2_io_get_api_version
mai2_io_init
mai2_io_poll
mai2_io_get_opbtns
mai2_io_get_gamebtns

View File

@ -1,68 +0,0 @@
#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);

View File

@ -1,53 +0,0 @@
project('mai2io_dll', 'c', version: '0.1.0')
add_project_arguments(
'-DCOBJMACROS',
'-DDIRECTINPUT_VERSION=0x0800',
'-DWIN32_LEAN_AND_MEAN',
'-D_WIN32_WINNT=_WIN32_WINNT_WIN7',
'-DMINGW_HAS_SECURE_API=1',
language: 'c',
)
# Use get_argument_syntax() instead once Meson 0.49.0 releases
if meson.get_compiler('c').get_id() != 'msvc'
add_project_arguments(
'-ffunction-sections',
'-fdata-sections',
language: 'c',
)
add_project_link_arguments(
'-Wl,--enable-stdcall-fixup',
'-Wl,--exclude-all-symbols',
'-Wl,--gc-sections',
'-static-libgcc',
language: 'c',
)
endif
cc = meson.get_compiler('c')
hid_lib = cc.find_library('hid')
setupapi_lib = cc.find_library('setupapi')
inc = include_directories('.')
mai2io_lib = shared_library(
'mai2io',
name_prefix : '',
include_directories : [inc, '../'],
vs_module_defs : 'mai2io.def',
implicit_include_directories : false,
dependencies : [
hid_lib,
setupapi_lib,
],
sources : [
'mai2io.c',
'mai2io.h',
'config.c',
'config.h',
],
)