2019-05-03 02:12:06 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <process.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "chuniio/chuniio.h"
|
2019-11-17 18:11:49 +00:00
|
|
|
#include "chuniio/config.h"
|
2019-05-03 02:12:06 +00:00
|
|
|
|
|
|
|
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx);
|
|
|
|
|
|
|
|
static bool chuni_io_coin;
|
|
|
|
static uint16_t chuni_io_coins;
|
|
|
|
static uint8_t chuni_io_hand_pos;
|
|
|
|
static HANDLE chuni_io_slider_thread;
|
|
|
|
static bool chuni_io_slider_stop_flag;
|
2019-11-17 18:11:49 +00:00
|
|
|
static struct chuni_io_config chuni_io_cfg;
|
2019-05-03 02:12:06 +00:00
|
|
|
|
2021-05-31 16:52:53 +00:00
|
|
|
uint16_t chuni_io_get_api_version(void)
|
|
|
|
{
|
2021-05-31 17:00:22 +00:00
|
|
|
return 0x0101;
|
2021-05-31 16:52:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 18:01:03 +00:00
|
|
|
HRESULT chuni_io_jvs_init(void)
|
2019-05-03 02:12:06 +00:00
|
|
|
{
|
2019-11-17 18:11:49 +00:00
|
|
|
chuni_io_config_load(&chuni_io_cfg, L".\\segatools.ini");
|
|
|
|
|
2019-05-03 02:12:06 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-03 21:41:39 +00:00
|
|
|
void chuni_io_jvs_read_coin_counter(uint16_t *out)
|
2019-05-03 02:12:06 +00:00
|
|
|
{
|
2019-08-03 21:41:39 +00:00
|
|
|
if (out == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-17 18:11:49 +00:00
|
|
|
if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) {
|
2019-05-03 02:12:06 +00:00
|
|
|
if (!chuni_io_coin) {
|
|
|
|
chuni_io_coin = true;
|
|
|
|
chuni_io_coins++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chuni_io_coin = false;
|
|
|
|
}
|
|
|
|
|
2019-08-03 21:41:39 +00:00
|
|
|
*out = chuni_io_coins;
|
2019-05-03 02:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2019-11-17 18:11:49 +00:00
|
|
|
if (GetAsyncKeyState(chuni_io_cfg.vk_test)) {
|
2019-05-03 02:12:06 +00:00
|
|
|
*opbtn |= 0x01; /* Test */
|
|
|
|
}
|
|
|
|
|
2019-11-17 18:11:49 +00:00
|
|
|
if (GetAsyncKeyState(chuni_io_cfg.vk_service)) {
|
2019-05-03 02:12:06 +00:00
|
|
|
*opbtn |= 0x02; /* Service */
|
|
|
|
}
|
|
|
|
|
2019-11-17 18:11:49 +00:00
|
|
|
if (GetAsyncKeyState(chuni_io_cfg.vk_ir)) {
|
2019-05-03 02:12:06 +00:00
|
|
|
if (chuni_io_hand_pos < 6) {
|
|
|
|
chuni_io_hand_pos++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (chuni_io_hand_pos > 0) {
|
|
|
|
chuni_io_hand_pos--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < 6 ; i++) {
|
|
|
|
if (chuni_io_hand_pos > i) {
|
|
|
|
*beams |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-03 18:01:03 +00:00
|
|
|
HRESULT chuni_io_slider_init(void)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-03 02:12:06 +00:00
|
|
|
void chuni_io_slider_start(chuni_io_slider_callback_t callback)
|
|
|
|
{
|
|
|
|
if (chuni_io_slider_thread != NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chuni_io_slider_thread = (HANDLE) _beginthreadex(
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
chuni_io_slider_thread_proc,
|
|
|
|
callback,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void chuni_io_slider_stop(void)
|
|
|
|
{
|
|
|
|
if (chuni_io_slider_thread == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chuni_io_slider_stop_flag = true;
|
|
|
|
|
|
|
|
WaitForSingleObject(chuni_io_slider_thread, INFINITE);
|
|
|
|
CloseHandle(chuni_io_slider_thread);
|
|
|
|
chuni_io_slider_thread = NULL;
|
|
|
|
chuni_io_slider_stop_flag = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void chuni_io_slider_set_leds(const uint8_t *rgb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx)
|
|
|
|
{
|
|
|
|
chuni_io_slider_callback_t callback;
|
|
|
|
uint8_t pressure[32];
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
callback = ctx;
|
|
|
|
|
|
|
|
while (!chuni_io_slider_stop_flag) {
|
2019-11-17 18:11:49 +00:00
|
|
|
for (i = 0 ; i < _countof(pressure) ; i++) {
|
|
|
|
if (GetAsyncKeyState(chuni_io_cfg.vk_cell[i]) & 0x8000) {
|
|
|
|
pressure[i] = 128;
|
2019-05-03 02:12:06 +00:00
|
|
|
} else {
|
2019-11-17 18:11:49 +00:00
|
|
|
pressure[i] = 0;
|
2019-05-03 02:12:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(pressure);
|
|
|
|
Sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|