segatools2/divaio/divaio.c

134 lines
2.6 KiB
C
Raw Normal View History

2019-05-03 18:47:09 +00:00
#include <windows.h>
#include <process.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "divaio/divaio.h"
2020-06-06 19:10:43 +00:00
#include "divaio/config.h"
2019-05-03 18:47:09 +00:00
static unsigned int __stdcall diva_io_slider_thread_proc(void *ctx);
static bool diva_io_coin;
static uint16_t diva_io_coins;
static HANDLE diva_io_slider_thread;
static bool diva_io_slider_stop_flag;
2020-06-06 19:10:43 +00:00
static struct diva_io_config diva_io_cfg;
2019-05-03 18:47:09 +00:00
2021-06-06 13:40:55 +00:00
uint16_t diva_io_get_api_version(void)
{
return 0x0100;
}
2019-11-03 18:01:03 +00:00
HRESULT diva_io_jvs_init(void)
2019-05-03 18:47:09 +00:00
{
2020-06-06 19:10:43 +00:00
diva_io_config_load(&diva_io_cfg, L".\\segatools.ini");
2019-05-03 18:47:09 +00:00
return S_OK;
}
void diva_io_jvs_poll(uint8_t *opbtn_out, uint8_t *gamebtn_out)
{
uint8_t opbtn;
uint8_t gamebtn;
size_t i;
opbtn = 0;
2020-06-06 19:10:43 +00:00
if (GetAsyncKeyState(diva_io_cfg.vk_test) & 0x8000) {
opbtn |= 1;
2019-05-03 18:47:09 +00:00
}
2020-06-06 19:10:43 +00:00
if (GetAsyncKeyState(diva_io_cfg.vk_service) & 0x8000) {
opbtn |= 2;
}
for (i = 0 ; i < _countof(diva_io_cfg.vk_buttons) ; i++) {
if (GetAsyncKeyState(diva_io_cfg.vk_buttons[i]) & 0x8000) {
2019-05-03 18:47:09 +00:00
gamebtn |= 1 << i;
}
}
*opbtn_out = opbtn;
*gamebtn_out = gamebtn;
}
void diva_io_jvs_read_coin_counter(uint16_t *out)
2019-05-03 18:47:09 +00:00
{
if (out == NULL) {
return;
}
2020-06-06 19:10:43 +00:00
if (GetAsyncKeyState(diva_io_cfg.vk_coin) & 0x8000) {
2019-05-03 18:47:09 +00:00
if (!diva_io_coin) {
diva_io_coin = true;
diva_io_coins++;
}
} else {
diva_io_coin = false;
}
*out = diva_io_coins;
2019-05-03 18:47:09 +00:00
}
2019-11-03 18:01:03 +00:00
HRESULT diva_io_slider_init(void)
{
return S_OK;
}
2019-05-03 18:47:09 +00:00
void diva_io_slider_start(diva_io_slider_callback_t callback)
{
if (diva_io_slider_thread != NULL) {
return;
}
diva_io_slider_thread = (HANDLE) _beginthreadex(
NULL,
0,
diva_io_slider_thread_proc,
callback,
0,
NULL);
}
void diva_io_slider_stop(void)
{
diva_io_slider_stop_flag = true;
WaitForSingleObject(diva_io_slider_thread, INFINITE);
CloseHandle(diva_io_slider_thread);
diva_io_slider_thread = NULL;
diva_io_slider_stop_flag = false;
}
void diva_io_slider_set_leds(const uint8_t *rgb)
{}
static unsigned int __stdcall diva_io_slider_thread_proc(void *ctx)
{
diva_io_slider_callback_t callback;
uint8_t pressure_val;
uint8_t pressure[32];
size_t i;
callback = ctx;
while (!diva_io_slider_stop_flag) {
for (i = 0 ; i < 8 ; i++) {
2020-06-06 19:10:43 +00:00
if (GetAsyncKeyState(diva_io_cfg.vk_slider[i]) & 0x8000) {
2019-05-03 18:47:09 +00:00
pressure_val = 20;
} else {
pressure_val = 0;
}
memset(&pressure[4 * i], pressure_val, 4);
2019-05-03 18:47:09 +00:00
}
callback(pressure);
Sleep(1);
}
return 0;
}