2021-12-21 05:02:17 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdint.h>
|
2022-01-08 22:19:10 +00:00
|
|
|
#include <process.h>
|
2021-12-21 05:02:17 +00:00
|
|
|
|
|
|
|
#include "mercuryio/mercuryio.h"
|
|
|
|
#include "mercuryio/config.h"
|
|
|
|
|
2022-01-08 22:19:10 +00:00
|
|
|
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx);
|
|
|
|
|
2021-12-21 05:02:17 +00:00
|
|
|
static uint8_t mercury_opbtn;
|
2022-01-08 07:25:42 +00:00
|
|
|
static uint8_t mercury_gamebtn;
|
2021-12-21 05:02:17 +00:00
|
|
|
static struct mercury_io_config mercury_io_cfg;
|
2022-01-08 22:19:10 +00:00
|
|
|
static bool mercury_io_touch_stop_flag;
|
|
|
|
static HANDLE mercury_io_touch_thread;
|
2021-12-21 05:02:17 +00:00
|
|
|
|
|
|
|
uint16_t mercury_io_get_api_version(void)
|
|
|
|
{
|
|
|
|
return 0x0100;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT mercury_io_init(void)
|
|
|
|
{
|
|
|
|
mercury_io_config_load(&mercury_io_cfg, L".\\segatools.ini");
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT mercury_io_poll(void)
|
|
|
|
{
|
|
|
|
mercury_opbtn = 0;
|
2022-01-08 07:25:42 +00:00
|
|
|
mercury_gamebtn = 0;
|
2021-12-21 05:02:17 +00:00
|
|
|
|
|
|
|
if (GetAsyncKeyState(mercury_io_cfg.vk_test)) {
|
2021-12-23 04:23:42 +00:00
|
|
|
mercury_opbtn |= MERCURY_IO_OPBTN_TEST;
|
2021-12-21 05:02:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetAsyncKeyState(mercury_io_cfg.vk_service)) {
|
2021-12-23 04:23:42 +00:00
|
|
|
mercury_opbtn |= MERCURY_IO_OPBTN_SERVICE;
|
2021-12-21 05:02:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 07:25:42 +00:00
|
|
|
if (GetAsyncKeyState(mercury_io_cfg.vk_vol_up)) {
|
|
|
|
mercury_gamebtn |= MERCURY_IO_GAMEBTN_VOL_UP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetAsyncKeyState(mercury_io_cfg.vk_vol_down)) {
|
|
|
|
mercury_gamebtn |= MERCURY_IO_GAMEBTN_VOL_DOWN;
|
|
|
|
}
|
|
|
|
|
2021-12-21 05:02:17 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mercury_io_get_opbtns(uint8_t *opbtn)
|
|
|
|
{
|
|
|
|
if (opbtn != NULL) {
|
|
|
|
*opbtn = mercury_opbtn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 07:25:42 +00:00
|
|
|
void mercury_io_get_gamebtns(uint8_t *gamebtn)
|
2021-12-21 05:02:17 +00:00
|
|
|
{
|
2022-01-08 07:25:42 +00:00
|
|
|
if (gamebtn != NULL) {
|
|
|
|
*gamebtn = mercury_gamebtn;
|
|
|
|
}
|
2021-12-30 05:51:44 +00:00
|
|
|
}
|
2021-12-30 18:57:05 +00:00
|
|
|
|
2022-01-04 05:10:46 +00:00
|
|
|
HRESULT mercury_io_touch_init(void)
|
2021-12-30 18:57:05 +00:00
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
2022-01-08 07:25:42 +00:00
|
|
|
|
2022-01-08 22:19:10 +00:00
|
|
|
void mercury_io_touch_start(mercury_io_touch_callback_t callback)
|
2022-01-08 07:25:42 +00:00
|
|
|
{
|
2022-01-08 22:19:10 +00:00
|
|
|
if (mercury_io_touch_thread != NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mercury_io_touch_thread = (HANDLE) _beginthreadex(
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
mercury_io_touch_thread_proc,
|
|
|
|
callback,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx)
|
|
|
|
{
|
|
|
|
mercury_io_touch_callback_t callback;
|
|
|
|
uint8_t pressure[240];
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
callback = ctx;
|
|
|
|
|
|
|
|
while (!mercury_io_touch_stop_flag) {
|
|
|
|
for (i = 0 ; i < _countof(pressure) ; i++) {
|
|
|
|
if (GetAsyncKeyState(mercury_io_cfg.vk_cell[i]) & 0x8000) {
|
|
|
|
pressure[i] = 128;
|
|
|
|
} else {
|
|
|
|
pressure[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(pressure);
|
|
|
|
Sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-01-08 07:25:42 +00:00
|
|
|
}
|