forked from TeamTofuShop/segatools
chuniio: Break out Chunithm IO DLL
This commit is contained in:
130
chuniio/chuniio.c
Normal file
130
chuniio/chuniio.c
Normal file
@ -0,0 +1,130 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <process.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "chuniio/chuniio.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;
|
||||
|
||||
HRESULT chuni_io_init(void)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
uint16_t chuni_io_jvs_read_coin_counter(void)
|
||||
{
|
||||
if (GetAsyncKeyState('3')) {
|
||||
if (!chuni_io_coin) {
|
||||
chuni_io_coin = true;
|
||||
chuni_io_coins++;
|
||||
}
|
||||
} else {
|
||||
chuni_io_coin = false;
|
||||
}
|
||||
|
||||
return chuni_io_coins;
|
||||
}
|
||||
|
||||
void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (GetAsyncKeyState('1')) {
|
||||
*opbtn |= 0x01; /* Test */
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('2')) {
|
||||
*opbtn |= 0x02; /* Service */
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState(VK_SPACE)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void chuni_io_jvs_set_coin_blocker(bool open)
|
||||
{}
|
||||
|
||||
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_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 = 20;
|
||||
} else {
|
||||
pressure_val = 0;
|
||||
}
|
||||
|
||||
memset(&pressure[28 - 4 * i], pressure_val, 4);
|
||||
}
|
||||
|
||||
callback(pressure);
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
10
chuniio/chuniio.def
Normal file
10
chuniio/chuniio.def
Normal file
@ -0,0 +1,10 @@
|
||||
LIBRARY chuniio
|
||||
|
||||
EXPORTS
|
||||
chuni_io_init
|
||||
chuni_io_jvs_poll
|
||||
chuni_io_jvs_read_coin_counter
|
||||
chuni_io_jvs_set_coin_blocker
|
||||
chuni_io_slider_set_leds
|
||||
chuni_io_slider_start
|
||||
chuni_io_slider_stop
|
99
chuniio/chuniio.h
Normal file
99
chuniio/chuniio.h
Normal file
@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Initialize the Chunithm IO provider DLL. This is the first function to be
|
||||
called on this DLL. Returning failure from this function will cause the
|
||||
main application to immediately exit.
|
||||
|
||||
All subsequent calls may originate from arbitrary threads and some may
|
||||
overlap with each other. Ensuring synchronization inside your IO DLL is
|
||||
your responsibility. */
|
||||
|
||||
HRESULT chuni_io_init(void);
|
||||
|
||||
/* Poll JVS input.
|
||||
|
||||
opbtn returns the cabinet test/service state, where bit 0 is Test and Bit 1
|
||||
is Service.
|
||||
|
||||
beam returns the IR beams that are currently broken, where bit 0 is the
|
||||
lowest IR beam and bit 5 is the highest IR beam, for a total of six beams.
|
||||
|
||||
Both bit masks are active-high.
|
||||
|
||||
Note that you cannot instantly break the entire IR grid in a single frame to
|
||||
simulate hand movement; this will be judged as a miss. You need to simulate
|
||||
a gradual raising and lowering of the hands. Consult the proof-of-concept
|
||||
implementation for details. */
|
||||
|
||||
void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams);
|
||||
|
||||
/* Read the current state of the coin counter. This value should be incremented
|
||||
for every coin detected by the coin acceptor mechanism. This count does not
|
||||
need to persist beyond the lifetime of the process. */
|
||||
|
||||
uint16_t chuni_io_jvs_read_coin_counter(void);
|
||||
|
||||
/* Set the state of the coin blocker. Parameter is true if the blocker is
|
||||
disengaged (i.e. coins can be inserted) and false if the blocker is engaged
|
||||
(i.e. the coin slot should be physically blocked). */
|
||||
|
||||
void chuni_io_jvs_set_coin_blocker(bool open);
|
||||
|
||||
/* Chunithm touch slider layout:
|
||||
|
||||
^^^ Toward screen ^^^
|
||||
|
||||
----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|
||||
31 | 29 | 27 | 25 | 23 | 21 | 19 | 17 | 15 | 13 | 11 | 9 | 7 | 5 | 3 | 1 |
|
||||
----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|
||||
32 | 30 | 28 | 26 | 24 | 22 | 20 | 18 | 16 | 14 | 12 | 10 | 8 | 6 | 4 | 2 |
|
||||
----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|
||||
|
||||
There are a total of 32 regions on the touch slider. Each region can return
|
||||
an 8-bit pressure value. The operator menu allows the operator to adjust the
|
||||
pressure level at which a region is considered to be pressed; the factory
|
||||
default value for this setting is 20. */
|
||||
|
||||
/* Callback function supplied to your IO DLL. This must be called with a
|
||||
pointer to a 32-byte array of pressure values, one byte per slider cell.
|
||||
See above for layout and pressure threshold information.
|
||||
|
||||
The callback will copy the pressure state data out of your buffer before
|
||||
returning. The pointer will not be retained. */
|
||||
|
||||
typedef void (*chuni_io_slider_callback_t)(const uint8_t *state);
|
||||
|
||||
/* Start polling the slider. Your DLL must start a polling thread and call the
|
||||
supplied function periodically from that thread with new input state. The
|
||||
update interval is up to you, but if your input device doesn't have any
|
||||
preferred interval then 1 kHz is a reasonable maximum frequency.
|
||||
|
||||
Note that you do have to have to call the callback "occasionally" even if
|
||||
nothing is changing, otherwise the game will raise a comm timeout error. */
|
||||
|
||||
void chuni_io_slider_start(chuni_io_slider_callback_t callback);
|
||||
|
||||
/* Stop polling the slider. You must cease to invoke the input callback before
|
||||
returning from this function.
|
||||
|
||||
This *will* be called in the course of regular operation. For example,
|
||||
every time you go into the operator menu the slider and all of the other I/O
|
||||
on the cabinet gets restarted.
|
||||
|
||||
Following on from the above, the slider polling loop *will* be restarted
|
||||
after being stopped in the course of regular operation. Do not permanently
|
||||
tear down your input driver in response to this function call. */
|
||||
|
||||
void chuni_io_slider_stop(void);
|
||||
|
||||
/* Update the RGB lighting on the slider. A pointer to an array of 32 * 3 = 96
|
||||
bytes is supplied. The illuminated areas on the touch slider are some
|
||||
combination of rectangular regions and dividing lines between these regions
|
||||
but the exact mapping of this lighting control buffer is still TBD. */
|
||||
|
||||
void chuni_io_slider_set_leds(const uint8_t *rgb);
|
12
chuniio/meson.build
Normal file
12
chuniio/meson.build
Normal file
@ -0,0 +1,12 @@
|
||||
chuniio_dll = shared_library(
|
||||
'chuniio',
|
||||
name_prefix : '',
|
||||
include_directories : inc,
|
||||
implicit_include_directories : false,
|
||||
vs_module_defs : 'chuniio.def',
|
||||
c_pch : '../precompiled.h',
|
||||
sources : [
|
||||
'chuniio.c',
|
||||
'chuniio.h',
|
||||
],
|
||||
)
|
Reference in New Issue
Block a user