forked from TeamTofuShop/segatools
idzio: Break out Initial D Zero IO DLL
This commit is contained in:
151
idzio/idzio.c
Normal file
151
idzio/idzio.c
Normal file
@ -0,0 +1,151 @@
|
||||
#include <windows.h>
|
||||
#include <xinput.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "idzio/idzio.h"
|
||||
|
||||
static bool idz_io_coin;
|
||||
static uint16_t idz_io_coins;
|
||||
static bool idz_io_shifting;
|
||||
static uint8_t idz_io_gear;
|
||||
|
||||
HRESULT idz_io_init(void)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void idz_io_jvs_read_buttons(uint8_t *opbtn_out, uint8_t *gamebtn_out)
|
||||
{
|
||||
uint8_t opbtn;
|
||||
uint8_t gamebtn;
|
||||
XINPUT_STATE xi;
|
||||
WORD xb;
|
||||
|
||||
opbtn = 0;
|
||||
gamebtn = 0;
|
||||
|
||||
/* Update test/service buttons */
|
||||
|
||||
if (GetAsyncKeyState('1')) {
|
||||
opbtn |= IDZ_IO_OPBTN_TEST;
|
||||
}
|
||||
|
||||
if (GetAsyncKeyState('2')) {
|
||||
opbtn |= IDZ_IO_OPBTN_SERVICE;
|
||||
}
|
||||
|
||||
/* Update gameplay buttons */
|
||||
|
||||
memset(&xi, 0, sizeof(xi));
|
||||
XInputGetState(0, &xi);
|
||||
xb = xi.Gamepad.wButtons;
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_DPAD_UP) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_UP;
|
||||
}
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_DPAD_DOWN) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_DOWN;
|
||||
}
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_DPAD_LEFT) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_LEFT;
|
||||
}
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_DPAD_RIGHT) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_RIGHT;
|
||||
}
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_START) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_START;
|
||||
}
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_BACK) {
|
||||
gamebtn |= IDZ_IO_GAMEBTN_VIEW_CHANGE;
|
||||
}
|
||||
|
||||
*opbtn_out = opbtn;
|
||||
*gamebtn_out = gamebtn;
|
||||
}
|
||||
|
||||
void idz_io_jvs_read_shifter(uint8_t *gear)
|
||||
{
|
||||
bool shift_inc;
|
||||
bool shift_dec;
|
||||
XINPUT_STATE xi;
|
||||
WORD xb;
|
||||
|
||||
memset(&xi, 0, sizeof(xi));
|
||||
XInputGetState(0, &xi);
|
||||
xb = xi.Gamepad.wButtons;
|
||||
|
||||
if (xb & XINPUT_GAMEPAD_START) {
|
||||
idz_io_gear = 0; /* Reset to Neutral when start is pressed */
|
||||
}
|
||||
|
||||
shift_inc = xb & (XINPUT_GAMEPAD_X | XINPUT_GAMEPAD_RIGHT_SHOULDER);
|
||||
shift_dec = xb & (XINPUT_GAMEPAD_Y | XINPUT_GAMEPAD_LEFT_SHOULDER);
|
||||
|
||||
if (!idz_io_shifting) {
|
||||
if (shift_inc && idz_io_gear < 6) {
|
||||
idz_io_gear++;
|
||||
}
|
||||
|
||||
if (shift_dec && idz_io_gear > 0) {
|
||||
idz_io_gear--;
|
||||
}
|
||||
}
|
||||
|
||||
idz_io_shifting = shift_inc || shift_dec;
|
||||
*gear = idz_io_gear;
|
||||
}
|
||||
|
||||
void idz_io_jvs_read_analogs(struct idz_io_analog_state *out)
|
||||
{
|
||||
XINPUT_STATE xi;
|
||||
int left;
|
||||
int right;
|
||||
|
||||
memset(&xi, 0, sizeof(xi));
|
||||
XInputGetState(0, &xi);
|
||||
|
||||
left = xi.Gamepad.sThumbLX;
|
||||
|
||||
if (left < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
left += XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE;
|
||||
} else if (left > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
left -= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE;
|
||||
} else {
|
||||
left = 0;
|
||||
}
|
||||
|
||||
right = xi.Gamepad.sThumbRX;
|
||||
|
||||
if (right < -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) {
|
||||
right += XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
} else if (right > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) {
|
||||
right -= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
} else {
|
||||
right = 0;
|
||||
}
|
||||
|
||||
out->wheel = (left + right) / 2;
|
||||
out->accel = xi.Gamepad.bRightTrigger << 8;
|
||||
out->brake = xi.Gamepad.bLeftTrigger << 8;
|
||||
}
|
||||
|
||||
uint16_t idz_io_jvs_read_coin_counter(void)
|
||||
{
|
||||
if (GetAsyncKeyState('3')) {
|
||||
if (!idz_io_coin) {
|
||||
idz_io_coin = true;
|
||||
idz_io_coins++;
|
||||
}
|
||||
} else {
|
||||
idz_io_coin = false;
|
||||
}
|
||||
|
||||
return idz_io_coins;
|
||||
}
|
8
idzio/idzio.def
Normal file
8
idzio/idzio.def
Normal file
@ -0,0 +1,8 @@
|
||||
LIBRARY idzio
|
||||
|
||||
EXPORTS
|
||||
idz_io_init
|
||||
idz_io_jvs_read_analogs
|
||||
idz_io_jvs_read_buttons
|
||||
idz_io_jvs_read_coin_counter
|
||||
idz_io_jvs_read_shifter
|
37
idzio/idzio.h
Normal file
37
idzio/idzio.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
IDZ_IO_OPBTN_TEST = 0x01,
|
||||
IDZ_IO_OPBTN_SERVICE = 0x02,
|
||||
};
|
||||
|
||||
enum {
|
||||
IDZ_IO_GAMEBTN_UP = 0x01,
|
||||
IDZ_IO_GAMEBTN_DOWN = 0x02,
|
||||
IDZ_IO_GAMEBTN_LEFT = 0x04,
|
||||
IDZ_IO_GAMEBTN_RIGHT = 0x08,
|
||||
IDZ_IO_GAMEBTN_START = 0x10,
|
||||
IDZ_IO_GAMEBTN_VIEW_CHANGE = 0x20,
|
||||
};
|
||||
|
||||
struct idz_io_analog_state {
|
||||
int16_t wheel;
|
||||
uint16_t accel;
|
||||
uint16_t brake;
|
||||
};
|
||||
|
||||
HRESULT idz_io_init(void);
|
||||
|
||||
void idz_io_jvs_read_analogs(struct idz_io_analog_state *out);
|
||||
|
||||
void idz_io_jvs_read_buttons(uint8_t *opbtn, uint8_t *gamebtn);
|
||||
|
||||
void idz_io_jvs_read_shifter(uint8_t *gear);
|
||||
|
||||
uint16_t idz_io_jvs_read_coin_counter(void);
|
||||
|
||||
// TODO force feedback once that gets reverse engineered
|
15
idzio/meson.build
Normal file
15
idzio/meson.build
Normal file
@ -0,0 +1,15 @@
|
||||
idzio_dll = shared_library(
|
||||
'idzio',
|
||||
name_prefix : '',
|
||||
include_directories : inc,
|
||||
implicit_include_directories : false,
|
||||
vs_module_defs : 'idzio.def',
|
||||
c_pch : '../precompiled.h',
|
||||
dependencies : [
|
||||
xinput_lib,
|
||||
],
|
||||
sources : [
|
||||
'idzio.c',
|
||||
'idzio.h',
|
||||
],
|
||||
)
|
Reference in New Issue
Block a user