2019-05-05 00:47:34 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "idzio/backend.h"
|
2019-09-29 05:29:12 +02:00
|
|
|
#include "idzio/config.h"
|
2019-05-09 20:28:30 +02:00
|
|
|
#include "idzio/di.h"
|
2019-05-05 00:47:34 +02:00
|
|
|
#include "idzio/idzio.h"
|
|
|
|
#include "idzio/xi.h"
|
|
|
|
|
2019-09-29 05:29:12 +02:00
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "util/str.h"
|
|
|
|
|
2019-05-09 20:28:30 +02:00
|
|
|
static HMODULE idz_io_hmodule;
|
2019-09-29 05:29:12 +02:00
|
|
|
static struct idz_io_config idz_io_cfg;
|
2019-05-05 00:47:34 +02:00
|
|
|
static const struct idz_io_backend *idz_io_backend;
|
|
|
|
static bool idz_io_coin;
|
|
|
|
static uint16_t idz_io_coins;
|
|
|
|
|
2019-11-03 19:01:03 +01:00
|
|
|
HRESULT idz_io_jvs_init(void)
|
2019-05-05 00:47:34 +02:00
|
|
|
{
|
2019-09-29 05:29:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-05-05 00:47:34 +02:00
|
|
|
assert(idz_io_backend == NULL);
|
|
|
|
|
2019-09-29 05:29:12 +02:00
|
|
|
idz_io_config_load(&idz_io_cfg, L".\\segatools.ini");
|
|
|
|
|
|
|
|
if (wstr_ieq(idz_io_cfg.mode, L"dinput")) {
|
|
|
|
hr = idz_di_init(&idz_io_cfg.di, idz_io_hmodule, &idz_io_backend);
|
|
|
|
} else if (wstr_ieq(idz_io_cfg.mode, L"xinput")) {
|
2019-11-22 01:59:08 +01:00
|
|
|
hr = idz_xi_init(&idz_io_cfg.xi, &idz_io_backend);
|
2019-09-29 05:29:12 +02:00
|
|
|
} else {
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
dprintf("IDZ IO: Invalid IO mode \"%S\", use dinput or xinput\n",
|
|
|
|
idz_io_cfg.mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2019-05-05 00:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void idz_io_jvs_read_buttons(uint8_t *opbtn_out, uint8_t *gamebtn_out)
|
|
|
|
{
|
|
|
|
uint8_t opbtn;
|
|
|
|
|
|
|
|
assert(idz_io_backend != NULL);
|
|
|
|
assert(opbtn_out != NULL);
|
|
|
|
assert(gamebtn_out != NULL);
|
|
|
|
|
|
|
|
opbtn = 0;
|
|
|
|
|
2019-11-17 19:16:50 +01:00
|
|
|
if (GetAsyncKeyState(idz_io_cfg.vk_test) & 0x8000) {
|
2019-05-05 00:47:34 +02:00
|
|
|
opbtn |= IDZ_IO_OPBTN_TEST;
|
|
|
|
}
|
|
|
|
|
2019-11-17 19:16:50 +01:00
|
|
|
if (GetAsyncKeyState(idz_io_cfg.vk_service) & 0x8000) {
|
2019-05-05 00:47:34 +02:00
|
|
|
opbtn |= IDZ_IO_OPBTN_SERVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*opbtn_out = opbtn;
|
|
|
|
|
|
|
|
idz_io_backend->jvs_read_buttons(gamebtn_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void idz_io_jvs_read_shifter(uint8_t *gear)
|
|
|
|
{
|
|
|
|
assert(gear != NULL);
|
|
|
|
assert(idz_io_backend != NULL);
|
|
|
|
|
|
|
|
idz_io_backend->jvs_read_shifter(gear);
|
|
|
|
}
|
|
|
|
|
2019-10-22 04:12:05 +02:00
|
|
|
void idz_io_jvs_read_analogs(struct idz_io_analog_state *out)
|
2019-05-05 00:47:34 +02:00
|
|
|
{
|
2019-10-22 04:12:05 +02:00
|
|
|
struct idz_io_analog_state tmp;
|
|
|
|
|
|
|
|
assert(out != NULL);
|
2019-05-05 00:47:34 +02:00
|
|
|
assert(idz_io_backend != NULL);
|
|
|
|
|
2019-10-22 04:12:05 +02:00
|
|
|
idz_io_backend->jvs_read_analogs(&tmp);
|
|
|
|
|
|
|
|
/* Apply steering wheel restriction. Real cabs only report about 77% of
|
|
|
|
the IO-3's max ADC output value when the wheel is turned to either of
|
|
|
|
its maximum positions. To match this behavior we set the default value
|
2019-11-24 18:59:02 +01:00
|
|
|
for the wheel restriction config parameter to 97 (out of 128). This
|
2019-10-22 04:12:05 +02:00
|
|
|
scaling factor is applied using fixed-point arithmetic below. */
|
|
|
|
|
2019-11-24 18:59:02 +01:00
|
|
|
out->wheel = (tmp.wheel * idz_io_cfg.restrict_) / 128;
|
2019-10-22 04:12:05 +02:00
|
|
|
out->accel = tmp.accel;
|
|
|
|
out->brake = tmp.brake;
|
2019-05-05 00:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void idz_io_jvs_read_coin_counter(uint16_t *out)
|
|
|
|
{
|
|
|
|
assert(out != NULL);
|
|
|
|
|
|
|
|
/* Coin counter is not backend-specific */
|
|
|
|
|
2019-09-29 05:29:12 +02:00
|
|
|
if ( idz_io_cfg.vk_coin &&
|
|
|
|
(GetAsyncKeyState(idz_io_cfg.vk_coin) & 0x8000)) {
|
2019-05-05 00:47:34 +02:00
|
|
|
if (!idz_io_coin) {
|
|
|
|
idz_io_coin = true;
|
|
|
|
idz_io_coins++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
idz_io_coin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = idz_io_coins;
|
|
|
|
}
|
2019-05-09 20:28:30 +02:00
|
|
|
|
|
|
|
BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx)
|
|
|
|
{
|
|
|
|
if (reason == DLL_PROCESS_ATTACH) {
|
|
|
|
idz_io_hmodule = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|