2019-03-05 19:34:43 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2019-09-01 15:40:25 +00:00
|
|
|
#include <assert.h>
|
2019-03-05 19:34:43 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "amex/jvs.h"
|
|
|
|
|
|
|
|
#include "board/io3.h"
|
|
|
|
|
|
|
|
#include "idzhook/jvs.h"
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
#include "idzio/idzio.h"
|
|
|
|
|
2019-03-05 19:34:43 +00:00
|
|
|
#include "jvs/jvs-bus.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
|
2019-05-03 19:57:12 +00:00
|
|
|
static void idz_jvs_read_analogs(
|
|
|
|
void *ctx,
|
|
|
|
uint16_t *analogs,
|
|
|
|
uint8_t nanalogs);
|
2019-03-05 19:34:43 +00:00
|
|
|
static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out);
|
2019-08-03 21:41:39 +00:00
|
|
|
static void idz_jvs_read_coin_counter(
|
|
|
|
void *ctx,
|
|
|
|
uint8_t slot_no,
|
|
|
|
uint16_t *out);
|
2019-03-05 19:34:43 +00:00
|
|
|
|
|
|
|
static const struct io3_ops idz_jvs_io3_ops = {
|
2019-05-02 23:38:39 +00:00
|
|
|
.read_switches = idz_jvs_read_switches,
|
2019-05-03 19:57:12 +00:00
|
|
|
.read_analogs = idz_jvs_read_analogs,
|
2019-05-02 23:38:39 +00:00
|
|
|
.read_coin_counter = idz_jvs_read_coin_counter,
|
2019-03-05 19:34:43 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 18:25:31 +00:00
|
|
|
static const uint16_t idz_jvs_gear_signals[] = {
|
|
|
|
/* Neutral */
|
|
|
|
0x0000,
|
|
|
|
/* 1: Left|Up */
|
|
|
|
0x2800,
|
|
|
|
/* 2: Left|Down */
|
|
|
|
0x1800,
|
|
|
|
/* 3: Up */
|
|
|
|
0x2000,
|
|
|
|
/* 4: Down */
|
|
|
|
0x1000,
|
|
|
|
/* 5: Right|Up */
|
|
|
|
0x2400,
|
|
|
|
/* 6: Right|Down */
|
|
|
|
0x1400,
|
|
|
|
};
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
static struct io3 idz_jvs_io3;
|
|
|
|
|
2019-11-03 18:01:03 +00:00
|
|
|
HRESULT idz_jvs_init(struct jvs_node **out)
|
2019-03-05 19:34:43 +00:00
|
|
|
{
|
2019-05-04 00:36:23 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-11-03 18:01:03 +00:00
|
|
|
assert(out != NULL);
|
|
|
|
|
|
|
|
dprintf("JVS I/O: Starting Initial D Zero backend DLL\n");
|
|
|
|
hr = idz_io_jvs_init();
|
2019-05-04 00:36:23 +00:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2019-11-03 18:01:03 +00:00
|
|
|
dprintf("JVS I/O: Backend error, I/O disconnected; %x\n", (int) hr);
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-03-05 19:34:43 +00:00
|
|
|
io3_init(&idz_jvs_io3, NULL, &idz_jvs_io3_ops, NULL);
|
2019-11-03 18:01:03 +00:00
|
|
|
*out = io3_to_jvs_node(&idz_jvs_io3);
|
2019-05-04 00:36:23 +00:00
|
|
|
|
|
|
|
return S_OK;
|
2019-03-05 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out)
|
|
|
|
{
|
2019-05-04 00:36:23 +00:00
|
|
|
uint8_t opbtn;
|
|
|
|
uint8_t gamebtn;
|
|
|
|
uint8_t gear;
|
2019-03-05 19:34:43 +00:00
|
|
|
|
|
|
|
assert(out != NULL);
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
opbtn = 0;
|
|
|
|
gamebtn = 0;
|
|
|
|
gear = 0;
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
idz_io_jvs_read_buttons(&opbtn, &gamebtn);
|
|
|
|
idz_io_jvs_read_shifter(&gear);
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
/* Update gameplay buttons */
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_UP) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 13;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_DOWN) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 12;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_LEFT) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 11;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_RIGHT) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 10;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_START) {
|
|
|
|
out->p1 |= 1 << 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gamebtn & IDZ_IO_GAMEBTN_VIEW_CHANGE) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 9;
|
|
|
|
}
|
|
|
|
|
2019-04-08 18:25:31 +00:00
|
|
|
/* Update simulated six-speed shifter */
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (gear > 6) {
|
|
|
|
gear = 6;
|
2019-04-08 18:25:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
out->p2 = idz_jvs_gear_signals[gear];
|
2019-04-08 18:25:31 +00:00
|
|
|
|
2019-03-05 19:34:43 +00:00
|
|
|
/* Update test/service buttons */
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (opbtn & IDZ_IO_OPBTN_TEST) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->system = 0x80;
|
|
|
|
} else {
|
|
|
|
out->system = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
if (opbtn & IDZ_IO_OPBTN_SERVICE) {
|
2019-03-05 19:34:43 +00:00
|
|
|
out->p1 |= 1 << 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 19:57:12 +00:00
|
|
|
static void idz_jvs_read_analogs(
|
|
|
|
void *ctx,
|
|
|
|
uint16_t *analogs,
|
|
|
|
uint8_t nanalogs)
|
2019-03-05 19:34:43 +00:00
|
|
|
{
|
2019-05-04 00:36:23 +00:00
|
|
|
struct idz_io_analog_state state;
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-03 19:57:12 +00:00
|
|
|
assert(analogs != NULL);
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-04 00:36:23 +00:00
|
|
|
memset(&state, 0, sizeof(state));
|
|
|
|
idz_io_jvs_read_analogs(&state);
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-03 19:57:12 +00:00
|
|
|
if (nanalogs > 0) {
|
2019-05-04 00:36:23 +00:00
|
|
|
analogs[0] = 0x8000 + state.wheel;
|
2019-05-03 19:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nanalogs > 1) {
|
2019-05-04 00:36:23 +00:00
|
|
|
analogs[1] = state.accel;
|
2019-05-03 19:57:12 +00:00
|
|
|
}
|
2019-03-05 19:34:43 +00:00
|
|
|
|
2019-05-03 19:57:12 +00:00
|
|
|
if (nanalogs > 2) {
|
2019-05-04 00:36:23 +00:00
|
|
|
analogs[2] = state.brake;
|
2019-03-05 19:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 21:41:39 +00:00
|
|
|
static void idz_jvs_read_coin_counter(
|
|
|
|
void *ctx,
|
|
|
|
uint8_t slot_no,
|
|
|
|
uint16_t *out)
|
2019-03-05 19:34:43 +00:00
|
|
|
{
|
|
|
|
if (slot_no > 0) {
|
2019-08-03 21:41:39 +00:00
|
|
|
return;
|
2019-03-05 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 21:41:39 +00:00
|
|
|
idz_io_jvs_read_coin_counter(out);
|
2019-03-05 19:34:43 +00:00
|
|
|
}
|