mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2024-11-13 18:00:49 +01:00
iidxhook9: Add turntable multiplier
This commit is contained in:
parent
d9cb953b67
commit
89c3ada28f
3
dist/iidx/iidxhook-27.conf
vendored
3
dist/iidx/iidxhook-27.conf
vendored
@ -16,6 +16,9 @@ io.disable_cams=false
|
||||
# Disables the built in file hooks, requiring manual file creation
|
||||
io.disable_file_hooks=false
|
||||
|
||||
# Turntable sensitivity multiplier (1.0 is default)
|
||||
io.tt_multiplier=1.0
|
||||
|
||||
# Disables the camera emulation
|
||||
cam.disable_emu=false
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
|
||||
#include <windows.h> /* for _BitScanForward */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "acioemu/emu.h"
|
||||
#include "util/math.h"
|
||||
|
||||
#include "bemanitools/iidxio.h"
|
||||
|
||||
@ -27,6 +29,11 @@ static bool poll_delay;
|
||||
static bool coin_latch;
|
||||
static uint8_t coin_count;
|
||||
|
||||
static bool tt_multiplier_set;
|
||||
static float tt_multiplier = 1.f;
|
||||
static uint8_t tt_accum[2];
|
||||
static int16_t tt_last[2];
|
||||
|
||||
int get_default_slider_valid(size_t idx)
|
||||
{
|
||||
if (default_sliders[idx] >= 0 && default_sliders[idx] <= 15) {
|
||||
@ -36,6 +43,12 @@ int get_default_slider_valid(size_t idx)
|
||||
}
|
||||
}
|
||||
|
||||
void bio2_emu_bi2a_set_tt_multiplier(float multiplier)
|
||||
{
|
||||
tt_multiplier_set = true;
|
||||
tt_multiplier = multiplier;
|
||||
}
|
||||
|
||||
void bio2_emu_bi2a_init(
|
||||
struct bio2emu_port *bio2_emu, bool disable_poll_limiter)
|
||||
{
|
||||
@ -158,6 +171,15 @@ static void bio2_emu_bi2a_send_status(
|
||||
ac_io_emu_response_push(emu, &resp, 0);
|
||||
}
|
||||
|
||||
static int16_t tt_mult_delta(size_t tt_no) {
|
||||
int16_t current_tt = iidx_io_ep2_get_turntable(tt_no);
|
||||
int16_t delta = get_wrapped_delta_s16(current_tt, tt_last[tt_no], 256);
|
||||
|
||||
tt_last[tt_no] = current_tt;
|
||||
|
||||
return round(delta * tt_multiplier);
|
||||
}
|
||||
|
||||
static void
|
||||
bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req)
|
||||
{
|
||||
@ -233,8 +255,16 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req)
|
||||
return bio2_emu_bi2a_send_status(emu, req, 0);
|
||||
}
|
||||
|
||||
body->TURNTABLE1 = iidx_io_ep2_get_turntable(0);
|
||||
body->TURNTABLE2 = iidx_io_ep2_get_turntable(1);
|
||||
if (tt_multiplier_set) {
|
||||
tt_accum[0] += tt_mult_delta(0);
|
||||
tt_accum[1] += tt_mult_delta(1);
|
||||
|
||||
body->TURNTABLE1 = tt_accum[0];
|
||||
body->TURNTABLE2 = tt_accum[1];
|
||||
} else {
|
||||
body->TURNTABLE1 = iidx_io_ep2_get_turntable(0);
|
||||
body->TURNTABLE2 = iidx_io_ep2_get_turntable(1);
|
||||
}
|
||||
|
||||
body->SLIDER1.s_val = get_default_slider_valid(0) ?
|
||||
default_sliders[0] :
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "bio2emu/emu.h"
|
||||
|
||||
void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter);
|
||||
void bio2_emu_bi2a_set_tt_multiplier(float multiplier);
|
||||
void bio2_emu_bi2a_dispatch_request(
|
||||
struct bio2emu_port *bio2port, const struct ac_io_message *req);
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#define IIDXHOOK9_CONFIG_IO_LIGHTNING_MODE_KEY "io.lightning_mode"
|
||||
#define IIDXHOOK9_CONFIG_IO_DISABLE_CAMS_KEY "io.disable_cams"
|
||||
#define IIDXHOOK9_CONFIG_IO_DISABLE_FILE_HOOKS_KEY "io.disable_file_hooks"
|
||||
#define IIDXHOOK9_CONFIG_IO_TT_MULTIPLIER_KEY "io.tt_multiplier"
|
||||
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE false
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false
|
||||
@ -18,6 +19,7 @@
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_LIGHTNING_MODE_VALUE false
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_CAMS_VALUE false
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE false
|
||||
#define IIDXHOOK9_CONFIG_IO_DEFAULT_TT_MULTIPLIER_VALUE 1.0
|
||||
|
||||
void iidxhook9_config_io_init(struct cconfig *config)
|
||||
{
|
||||
@ -57,6 +59,12 @@ void iidxhook9_config_io_init(struct cconfig *config)
|
||||
IIDXHOOK9_CONFIG_IO_DISABLE_FILE_HOOKS_KEY,
|
||||
IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE,
|
||||
"Disables the built in file hooks, requiring manual file creation");
|
||||
|
||||
cconfig_util_set_float(
|
||||
config,
|
||||
IIDXHOOK9_CONFIG_IO_TT_MULTIPLIER_KEY,
|
||||
IIDXHOOK9_CONFIG_IO_DEFAULT_TT_MULTIPLIER_VALUE,
|
||||
"Turntable sensitivity multiplier (1.0 is default)");
|
||||
}
|
||||
|
||||
void iidxhook9_config_io_get(
|
||||
@ -133,4 +141,16 @@ void iidxhook9_config_io_get(
|
||||
IIDXHOOK9_CONFIG_IO_DISABLE_FILE_HOOKS_KEY,
|
||||
IIDXHOOK9_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE);
|
||||
}
|
||||
|
||||
if (!cconfig_util_get_float(
|
||||
config,
|
||||
IIDXHOOK9_CONFIG_IO_TT_MULTIPLIER_KEY,
|
||||
&config_io->tt_multiplier,
|
||||
IIDXHOOK9_CONFIG_IO_DEFAULT_TT_MULTIPLIER_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%f'",
|
||||
IIDXHOOK9_CONFIG_IO_TT_MULTIPLIER_KEY,
|
||||
IIDXHOOK9_CONFIG_IO_DEFAULT_TT_MULTIPLIER_VALUE);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ struct iidxhook9_config_io {
|
||||
bool lightning_mode;
|
||||
bool disable_cams;
|
||||
bool disable_file_hooks;
|
||||
float tt_multiplier;
|
||||
};
|
||||
|
||||
void iidxhook9_config_io_init(struct cconfig *config);
|
||||
|
@ -10,6 +10,7 @@ src_util := \
|
||||
iobuf.c \
|
||||
list.c \
|
||||
log.c \
|
||||
math.c \
|
||||
mem.c \
|
||||
msg-thread.c \
|
||||
net.c \
|
||||
|
22
src/main/util/math.c
Normal file
22
src/main/util/math.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include "util/math.h"
|
||||
|
||||
int16_t get_wrapped_delta_s16(int16_t val, int16_t last, int16_t bound) {
|
||||
int16_t half_point = bound / 2;
|
||||
|
||||
int16_t delta = val - last;
|
||||
|
||||
if (delta > half_point) {
|
||||
delta -= bound;
|
||||
}
|
||||
|
||||
if (delta < -half_point) {
|
||||
delta += bound;
|
||||
}
|
||||
|
||||
// delta is now between (-half_point - half_point)
|
||||
return delta;
|
||||
}
|
||||
|
||||
int16_t sign_s16(int16_t x) {
|
||||
return (x > 0) - (x < 0);
|
||||
}
|
9
src/main/util/math.h
Normal file
9
src/main/util/math.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef UTIL_MATH_H
|
||||
#define UTIL_MATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int16_t get_wrapped_delta_s16(int16_t val, int16_t last, int16_t bound);
|
||||
int16_t sign_s16(int16_t x);
|
||||
|
||||
#endif
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "bemanitools/sdvxio.h"
|
||||
#include "util/log.h"
|
||||
#include "util/math.h"
|
||||
#include "util/thread.h"
|
||||
#include "vigemstub/helper.h"
|
||||
|
||||
@ -22,25 +23,6 @@ int16_t convert_analog_to_s16(uint16_t val)
|
||||
return (int64_t)(val * 64);
|
||||
}
|
||||
|
||||
int16_t get_relative_delta(int16_t val, int16_t last)
|
||||
{
|
||||
// val is 10 bit
|
||||
const int16_t half_point = 512; // 2^9
|
||||
|
||||
int16_t delta = val - last;
|
||||
|
||||
if (delta > half_point) {
|
||||
delta -= 1024;
|
||||
}
|
||||
|
||||
if (delta < -half_point) {
|
||||
delta += 1024;
|
||||
}
|
||||
|
||||
// delta is now between (-512 - 512)
|
||||
return delta;
|
||||
}
|
||||
|
||||
int16_t filter_floor(int32_t value, int16_t floor) {
|
||||
if (abs(value) < floor) {
|
||||
return 0;
|
||||
@ -58,7 +40,8 @@ int16_t filter_floor(int32_t value, int16_t floor) {
|
||||
int32_t convert_relative_analog(
|
||||
uint16_t val, uint16_t last, int32_t buffered_last, int16_t multiplier)
|
||||
{
|
||||
int16_t delta = get_relative_delta(val, last);
|
||||
// val is 10 bit
|
||||
int16_t delta = get_wrapped_delta_s16(val, last, 1024);
|
||||
|
||||
if (delta == 0) {
|
||||
// ease the stick back to 0 like a real stick would
|
||||
|
Loading…
Reference in New Issue
Block a user