forked from TeamTofuShop/segatools
divaio: Break out Project Diva IO DLL
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
|
||||
#include "board/io3.h"
|
||||
|
||||
#include "divaio/divaio.h"
|
||||
|
||||
#include "jvs/jvs-bus.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
@ -21,8 +23,6 @@ static const struct io3_ops diva_jvs_io3_ops = {
|
||||
};
|
||||
|
||||
static struct io3 diva_jvs_io3;
|
||||
static bool diva_jvs_coin;
|
||||
static uint16_t diva_jvs_coins;
|
||||
|
||||
void diva_jvs_init(void)
|
||||
{
|
||||
@ -32,42 +32,44 @@ void diva_jvs_init(void)
|
||||
|
||||
static void diva_jvs_read_switches(void *ctx, struct io3_switch_state *out)
|
||||
{
|
||||
uint8_t opbtn;
|
||||
uint8_t gamebtn;
|
||||
|
||||
assert(out != NULL);
|
||||
|
||||
/* Update gameplay buttons (P2 JVS input is not even polled) */
|
||||
opbtn = 0;
|
||||
gamebtn = 0;
|
||||
|
||||
if (GetAsyncKeyState('S')) {
|
||||
out->p1 |= 1 << 9;
|
||||
}
|
||||
diva_io_jvs_poll(&opbtn, &gamebtn);
|
||||
|
||||
if (GetAsyncKeyState('F')) {
|
||||
out->p1 |= 1 << 8;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('J')) {
|
||||
out->p1 |= 1 << 7;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('L')) {
|
||||
if (gamebtn & 0x01) {
|
||||
out->p1 |= 1 << 6;
|
||||
}
|
||||
|
||||
/* Update start button */
|
||||
if (gamebtn & 0x02) {
|
||||
out->p1 |= 1 << 7;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState(VK_SPACE)) {
|
||||
if (gamebtn & 0x04) {
|
||||
out->p1 |= 1 << 8;
|
||||
}
|
||||
|
||||
if (gamebtn & 0x08) {
|
||||
out->p1 |= 1 << 9;
|
||||
}
|
||||
|
||||
if (gamebtn & 0x10) {
|
||||
out->p1 |= 1 << 15;
|
||||
}
|
||||
|
||||
/* Update test/service buttons */
|
||||
|
||||
if (GetAsyncKeyState('1')) {
|
||||
if (opbtn & 0x01) {
|
||||
out->system = 0x80;
|
||||
} else {
|
||||
out->system = 0;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('2')) {
|
||||
out->p1 |= 0x4000;
|
||||
if (opbtn & 0x02) {
|
||||
out->p1 |= 1 << 14;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,15 +79,5 @@ static uint16_t diva_jvs_read_coin_counter(void *ctx, uint8_t slot_no)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('3')) {
|
||||
if (!diva_jvs_coin) {
|
||||
dprintf("Diva JVS: Coin drop\n");
|
||||
diva_jvs_coin = true;
|
||||
diva_jvs_coins++;
|
||||
}
|
||||
} else {
|
||||
diva_jvs_coin = false;
|
||||
}
|
||||
|
||||
return diva_jvs_coins;
|
||||
return diva_io_jvs_read_coin_counter();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ shared_library(
|
||||
aimeio_dll,
|
||||
amex_lib,
|
||||
board_lib,
|
||||
divaio_dll,
|
||||
jvs_lib,
|
||||
platform_lib,
|
||||
util_lib,
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <process.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@ -11,6 +10,8 @@
|
||||
|
||||
#include "divahook/slider-hook.h"
|
||||
|
||||
#include "divaio/divaio.h"
|
||||
|
||||
#include "hook/iobuf.h"
|
||||
#include "hook/iohook.h"
|
||||
|
||||
@ -29,16 +30,13 @@ static HRESULT slider_req_auto_scan_start(void);
|
||||
static HRESULT slider_req_auto_scan_stop(void);
|
||||
static HRESULT slider_req_set_led(const struct slider_req_set_led *req);
|
||||
|
||||
static unsigned int __stdcall slider_thread_proc(void *ctx);
|
||||
static void slider_res_auto_scan(const uint8_t *pressure);
|
||||
|
||||
static CRITICAL_SECTION slider_lock;
|
||||
static struct uart slider_uart;
|
||||
static uint8_t slider_written_bytes[520];
|
||||
static uint8_t slider_readable_bytes[520];
|
||||
|
||||
static HANDLE slider_thread;
|
||||
static bool slider_stop;
|
||||
|
||||
void slider_hook_init(void)
|
||||
{
|
||||
InitializeCriticalSection(&slider_lock);
|
||||
@ -175,24 +173,7 @@ static HRESULT slider_req_get_board_info(void)
|
||||
static HRESULT slider_req_auto_scan_start(void)
|
||||
{
|
||||
dprintf("Diva slider: Start slider thread\n");
|
||||
|
||||
if (slider_thread != NULL) {
|
||||
dprintf("Thread is already running\n");
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
slider_thread = (HANDLE) _beginthreadex(
|
||||
NULL,
|
||||
0,
|
||||
slider_thread_proc,
|
||||
NULL,
|
||||
0,
|
||||
NULL);
|
||||
|
||||
if (slider_thread == NULL) {
|
||||
dprintf("Thread launch failed\n");
|
||||
}
|
||||
diva_io_slider_start(slider_res_auto_scan);
|
||||
|
||||
/* This message is not acknowledged */
|
||||
|
||||
@ -205,19 +186,14 @@ static HRESULT slider_req_auto_scan_stop(void)
|
||||
|
||||
dprintf("Diva slider: Stop slider thread\n");
|
||||
|
||||
if (slider_thread != NULL) {
|
||||
slider_stop = true;
|
||||
LeaveCriticalSection(&slider_lock);
|
||||
/* IO DLL worker thread might attempt to invoke the callback (which needs
|
||||
to take slider_lock, which we are currently holding) before noticing that
|
||||
it needs to shut down. Unlock here so that we don't deadlock in that
|
||||
situation. */
|
||||
|
||||
WaitForSingleObject(slider_thread, INFINITE);
|
||||
CloseHandle(slider_thread);
|
||||
slider_thread = NULL;
|
||||
slider_stop = false;
|
||||
|
||||
dprintf("Diva slider: Thread has terminated\n");
|
||||
|
||||
EnterCriticalSection(&slider_lock);
|
||||
}
|
||||
LeaveCriticalSection(&slider_lock);
|
||||
diva_io_slider_stop();
|
||||
EnterCriticalSection(&slider_lock);
|
||||
|
||||
resp.sync = SLIDER_FRAME_SYNC;
|
||||
resp.cmd = SLIDER_CMD_AUTO_SCAN_STOP;
|
||||
@ -229,44 +205,21 @@ static HRESULT slider_req_auto_scan_stop(void)
|
||||
static HRESULT slider_req_set_led(const struct slider_req_set_led *req)
|
||||
{
|
||||
/* This message is not acknowledged */
|
||||
diva_io_slider_set_leds(req->payload.rgb);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static unsigned int WINAPI slider_thread_proc(void *ctx)
|
||||
static void slider_res_auto_scan(const uint8_t *pressure)
|
||||
{
|
||||
static const int keys[] = {
|
||||
'Q', 'W', 'E', 'R', 'U', 'I', 'O', 'P',
|
||||
};
|
||||
|
||||
struct slider_resp_auto_scan resp;
|
||||
uint8_t pressure;
|
||||
bool stop;
|
||||
size_t i;
|
||||
|
||||
for (;;) {
|
||||
resp.hdr.sync = SLIDER_FRAME_SYNC;
|
||||
resp.hdr.cmd = SLIDER_CMD_AUTO_SCAN;
|
||||
resp.hdr.nbytes = sizeof(resp.pressure);
|
||||
resp.hdr.sync = SLIDER_FRAME_SYNC;
|
||||
resp.hdr.cmd = SLIDER_CMD_AUTO_SCAN;
|
||||
resp.hdr.nbytes = sizeof(resp.pressure);
|
||||
memcpy(resp.pressure, pressure, sizeof(resp.pressure));
|
||||
|
||||
for (i = 0 ; i < 8 ; i++) {
|
||||
pressure = GetAsyncKeyState(keys[i]) ? 20 : 0;
|
||||
memset(&resp.pressure[28 - 4 * i], pressure, 4);
|
||||
}
|
||||
|
||||
EnterCriticalSection(&slider_lock);
|
||||
|
||||
stop = slider_stop;
|
||||
|
||||
if (!stop) {
|
||||
slider_frame_encode(&slider_uart.readable, &resp, sizeof(resp));
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&slider_lock);
|
||||
|
||||
if (stop) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Sleep(1);
|
||||
}
|
||||
EnterCriticalSection(&slider_lock);
|
||||
slider_frame_encode(&slider_uart.readable, &resp, sizeof(resp));
|
||||
LeaveCriticalSection(&slider_lock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user