Wow! Well done Yolo, sounds like progress at last!! Can't wait to see the changes
I still haven't got round to using the info you gave me on Airborne im using my older hack to get that working and added differennt wheel sensitivities /port_minmax's through a dip switch menu that changes your wheel to a different calibration and goes through EMA filtering. The fix for the compact version of race drivin' was easier than i thought lol. The test menu calibration is still gimped but you can just skip it.
https://github.com/Madcadden/mame/tree/Madcadden-Hard-Drivin-Race-Drivin-MAME-Build
Code: [Select]
PORT_BIT( 0x4000, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_TOGGLE PORT_NAME("Center Wheel Edge") /* center edge on steering wheel, IPT_ACTIVE_HIGH fixes the steering alignment in game! */
Code: [Select]
#include <numeric> // For std::accumulate
// Function to calculate the Exponential Moving Average (EMA)
uint16_t harddriv_state::calculate_ema(uint16_t new_value) {
static float ema_wheel = 0.0; // Persistent storage of EMA across calls
static bool ema_initialized = false; // To check if ema_wheel is initialized
static const float alpha = 0.082; // Smoothing constant
if (!ema_initialized) {
ema_wheel = new_value; // Initialize EMA with the first raw value
ema_initialized = true;
} else {
ema_wheel = alpha * new_value + (1 - alpha) * ema_wheel;
}
// Ensure the last digit of the EMA output is always zero
return static_cast<uint16_t>(ema_wheel) & 0xFFF0;
}
// Main function to handle wheel input and apply adjustments
uint16_t harddriv_state::hdc68k_wheel_r() {
static const uint16_t g_latchpoint = 0x8000; // Center point for wheel edge detection
static bool initialized = false; // To ensure the initial setup is done only once
static int16_t last_offset = 0; // To store the last offset applied
static int wheel_edge_zero_count = 0; // Counter for how many times wheel edge has been set to 0
static int resets_recorded = 0; // Counter to delay offset recording
// Initial setup
if (!initialized) {
m_hdc68k_wheel_edge = 1; // Set the edge to 1 at the start of the game
initialized = true; // Prevent further initialization
}
uint16_t new_wheel_raw = m_12badc[0].read_safe(0xffff) << 4;
uint16_t ema_wheel = calculate_ema(new_wheel_raw) << 3;
// If the game has reset the wheel edge to 0, handle the deviation
if (m_hdc68k_wheel_edge == 0) {
wheel_edge_zero_count++; // Increment the counter each time wheel edge is 0
// Record adjustment only after the first reset is recorded
if (resets_recorded > 0) {
// Check for deviation from the center point
if (ema_wheel != g_latchpoint) {
int16_t adjustment = g_latchpoint - ema_wheel; // Calculate the necessary adjustment
ema_wheel += adjustment; // Correct the EMA to the center point
last_offset = adjustment; // Store the last offset applied
} else {
last_offset = 0; // No offset needed if already at center
}
}
resets_recorded++; // Increment resets recorded after processing
m_hdc68k_wheel_edge = 1; // Set the wheel edge back to 1 after handling the adjustment
}
// Debugging output
popmessage("Wheel Raw: %04X, EMA Wheel: %04X, Last Offset: %d, Edge: %d, Edge 0 Count: %d, Resets Recorded: %d",
new_wheel_raw, ema_wheel, last_offset, m_hdc68k_wheel_edge, wheel_edge_zero_count, resets_recorded);
return ema_wheel; // Use the adjusted EMA directly
}
Code: [Select]
// Handlers for the wheel and port inputs
m_maincpu->space(AS_PROGRAM).install_read_handler(0x400000, 0x400001, read16smo_delegate(*this, FUNC(harddriv_state::hdc68k_wheel_r)));
m_maincpu->space(AS_PROGRAM).install_write_handler(0x408000, 0x408001, write16smo_delegate(*this, FUNC(harddriv_state::hdc68k_wheel_edge_reset_w)));
m_maincpu->space(AS_PROGRAM).install_read_handler(0xa80000, 0xafffff, read16smo_delegate(*this, FUNC(harddriv_state::hda68k_port1_r)));
Code: [Select]
class harddriv_state : public device_t
{
public:
void reset_wheel_offset(); // Function to reset the wheel offset
harddriv_state(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
void driver_msp(machine_config &config);
@@ -98,8 +102,21 @@ class harddriv_state : public device_t
void video_int_write_line(int state);
void sound_int_write_line(int state);
//New method declarations for steering logic
uint16_t hdc68k_wheel_r(); // Ensure this is declared only once
uint16_t custom_steering_logic();
uint16_t original_steering_logic();
// Add your EMA function declaration here
uint16_t calculate_ema(uint16_t new_value); // Corrected declaration
protected:
int16_t wheel_offset = 0; // Make wheel_offset a member variable
void init_video();
INTERRUPT_GEN_MEMBER(hd68k_irq_gen);
TIMER_CALLBACK_MEMBER(deferred_adsp_bank_switch);
TIMER_CALLBACK_MEMBER(rddsp32_sync_cb);
@@ -122,7 +139,7 @@ class harddriv_state : public device_t
uint16_t hd68k_adc12_r();
uint16_t hdc68k_port1_r();
uint16_t hda68k_port1_r();
// uint16_t hdc68k_wheel_r();
uint16_t hd68k_sound_reset_r();
void hd68k_adc_control_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);