From 388ba0b4a42398e6439d88f925e64343e1daa5df Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 17 Nov 2019 13:11:49 -0500 Subject: [PATCH] chuniio: Add input config --- chuniio/chuniio.c | 27 ++++++++++++--------------- chuniio/config.c | 43 +++++++++++++++++++++++++++++++++++++++++++ chuniio/config.h | 16 ++++++++++++++++ chuniio/meson.build | 2 ++ 4 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 chuniio/config.c create mode 100644 chuniio/config.h diff --git a/chuniio/chuniio.c b/chuniio/chuniio.c index 7823669b..be81d64f 100644 --- a/chuniio/chuniio.c +++ b/chuniio/chuniio.c @@ -5,21 +5,21 @@ #include #include "chuniio/chuniio.h" +#include "chuniio/config.h" static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx); -static const int chuni_io_slider_keys[] = { - 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', -}; - 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; +static struct chuni_io_config chuni_io_cfg; HRESULT chuni_io_jvs_init(void) { + chuni_io_config_load(&chuni_io_cfg, L".\\segatools.ini"); + return S_OK; } @@ -29,7 +29,7 @@ void chuni_io_jvs_read_coin_counter(uint16_t *out) return; } - if (GetAsyncKeyState('3')) { + if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) { if (!chuni_io_coin) { chuni_io_coin = true; chuni_io_coins++; @@ -45,15 +45,15 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams) { size_t i; - if (GetAsyncKeyState('1')) { + if (GetAsyncKeyState(chuni_io_cfg.vk_test)) { *opbtn |= 0x01; /* Test */ } - if (GetAsyncKeyState('2')) { + if (GetAsyncKeyState(chuni_io_cfg.vk_service)) { *opbtn |= 0x02; /* Service */ } - if (GetAsyncKeyState(VK_SPACE)) { + if (GetAsyncKeyState(chuni_io_cfg.vk_ir)) { if (chuni_io_hand_pos < 6) { chuni_io_hand_pos++; } @@ -114,21 +114,18 @@ 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_val; uint8_t pressure[32]; size_t i; callback = ctx; while (!chuni_io_slider_stop_flag) { - for (i = 0 ; i < 8 ; i++) { - if (GetAsyncKeyState(chuni_io_slider_keys[i]) & 0x8000) { - pressure_val = 128; + for (i = 0 ; i < _countof(pressure) ; i++) { + if (GetAsyncKeyState(chuni_io_cfg.vk_cell[i]) & 0x8000) { + pressure[i] = 128; } else { - pressure_val = 0; + pressure[i] = 0; } - - memset(&pressure[28 - 4 * i], pressure_val, 4); } callback(pressure); diff --git a/chuniio/config.c b/chuniio/config.c new file mode 100644 index 00000000..7365f2c3 --- /dev/null +++ b/chuniio/config.c @@ -0,0 +1,43 @@ +#include + +#include +#include +#include + +#include "chuniio/config.h" + +static const int chuni_io_default_cells[] = { + 'L', 'L', 'L', 'L', + 'K', 'K', 'K', 'K', + 'J', 'J', 'J', 'J', + 'H', 'H', 'H', 'H', + 'G', 'G', 'G', 'G', + 'F', 'F', 'F', 'F', + 'D', 'D', 'D', 'D', + 'S', 'S', 'S', 'S', +}; + +void chuni_io_config_load( + struct chuni_io_config *cfg, + const wchar_t *filename) +{ + wchar_t key[16]; + int i; + + assert(cfg != NULL); + assert(filename != NULL); + + cfg->vk_test = GetPrivateProfileIntW(L"io3", L"test", '1', filename); + cfg->vk_service = GetPrivateProfileIntW(L"io3", L"service", '2', filename); + cfg->vk_coin = GetPrivateProfileIntW(L"io3", L"coin", '3', filename); + cfg->vk_ir = GetPrivateProfileIntW(L"io3", L"ir", VK_SPACE, filename); + + for (i = 0 ; i < 32 ; i++) { + swprintf_s(key, _countof(key), L"cell%i", i + 1); + cfg->vk_cell[i] = GetPrivateProfileIntW( + L"slider", + key, + chuni_io_default_cells[i], + filename); + } +} diff --git a/chuniio/config.h b/chuniio/config.h new file mode 100644 index 00000000..fa2e2b0b --- /dev/null +++ b/chuniio/config.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +struct chuni_io_config { + uint8_t vk_test; + uint8_t vk_service; + uint8_t vk_coin; + uint8_t vk_ir; + uint8_t vk_cell[32]; +}; + +void chuni_io_config_load( + struct chuni_io_config *cfg, + const wchar_t *filename); diff --git a/chuniio/meson.build b/chuniio/meson.build index 78a974bc..2e15e4d4 100644 --- a/chuniio/meson.build +++ b/chuniio/meson.build @@ -8,5 +8,7 @@ chuniio_dll = shared_library( sources : [ 'chuniio.c', 'chuniio.h', + 'config.c', + 'config.h', ], )