From ad5fbc1f5b01fd9a367697325b2fe118c106c42e Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Mon, 27 Apr 2020 10:19:29 -0700 Subject: [PATCH] sdvxhook2: Add option to force headphone detection on --- dist/sdvx5/sdvxhook2.conf | 3 +++ src/main/sdvxhook2/bi2a.c | 9 ++++++++- src/main/sdvxhook2/bi2a.h | 2 +- src/main/sdvxhook2/config-io.c | 20 ++++++++++++++++++++ src/main/sdvxhook2/config-io.h | 1 + src/main/sdvxhook2/dllmain.c | 2 +- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/dist/sdvx5/sdvxhook2.conf b/dist/sdvx5/sdvxhook2.conf index 87e4d57..eb6c4b1 100644 --- a/dist/sdvx5/sdvxhook2.conf +++ b/dist/sdvx5/sdvxhook2.conf @@ -7,6 +7,9 @@ io.disable_bio2_emu=false # Disables the poll limiter, warning very high CPU usage may arise io.disable_poll_limiter=false +# Forces game to think headphones are attached +io.force_headphones=false + # Run the game in a framed window (requires windowed option) gfx.framed=true diff --git a/src/main/sdvxhook2/bi2a.c b/src/main/sdvxhook2/bi2a.c index 7e6ce8f..4e5a1d9 100644 --- a/src/main/sdvxhook2/bi2a.c +++ b/src/main/sdvxhook2/bi2a.c @@ -25,8 +25,10 @@ kfca_amp_control(struct ac_io_emu *emu, const struct ac_io_message *req); static bool poll_delay; +static bool force_headphones_on; + void bio2_emu_bi2a_init( - struct bio2emu_port *bio2_emu, bool disable_poll_limiter) + struct bio2emu_port *bio2_emu, bool disable_poll_limiter, bool force_headphones) { bio2emu_port_init(bio2_emu); @@ -35,6 +37,8 @@ void bio2_emu_bi2a_init( if (!poll_delay) { log_warning("bio2_emu_bi2a_init: poll_delay has been disabled"); } + + force_headphones_on = force_headphones; } void bio2_emu_bi2a_dispatch_request( @@ -240,6 +244,9 @@ bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req) pin->buttons_1.b_start = check_pin(gpio0, SDVX_IO_IN_GPIO_0_START); pin->buttons_1.b_headphone = check_pin(gpio0, SDVX_IO_IN_GPIO_0_HEADPHONE); + if (force_headphones_on) { + pin->buttons_1.b_headphone = 1; + } pin->buttons_1.b_a = check_pin(gpio0, SDVX_IO_IN_GPIO_0_A); pin->buttons_1.b_b = check_pin(gpio0, SDVX_IO_IN_GPIO_0_B); pin->buttons_1.b_c = check_pin(gpio0, SDVX_IO_IN_GPIO_0_C); diff --git a/src/main/sdvxhook2/bi2a.h b/src/main/sdvxhook2/bi2a.h index 5d4fc96..d65b655 100644 --- a/src/main/sdvxhook2/bi2a.h +++ b/src/main/sdvxhook2/bi2a.h @@ -83,7 +83,7 @@ _Static_assert( "bio2_bi2a_state_out is the wrong size"); #pragma pack(pop) -void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter); +void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter, bool force_headphones); void bio2_emu_bi2a_dispatch_request( struct bio2emu_port *bio2port, const struct ac_io_message *req); diff --git a/src/main/sdvxhook2/config-io.c b/src/main/sdvxhook2/config-io.c index 26f4224..5e0a7ba 100644 --- a/src/main/sdvxhook2/config-io.c +++ b/src/main/sdvxhook2/config-io.c @@ -8,10 +8,12 @@ "io.disable_card_reader_emu" #define SDVXHOOK2_CONFIG_IO_DISABLE_BIO2_EMU_KEY "io.disable_bio2_emu" #define SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY "io.disable_poll_limiter" +#define SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY "io.force_headphones" #define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE false #define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false #define SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE false +#define SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE false void sdvxhook2_config_io_init(struct cconfig *config) { @@ -33,6 +35,12 @@ void sdvxhook2_config_io_init(struct cconfig *config) SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE, "Disables the poll limiter, warning very high CPU usage may arise"); + + cconfig_util_set_bool( + config, + SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY, + SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE, + "Forces game to think headphones are attached"); } void sdvxhook2_config_io_get( @@ -73,4 +81,16 @@ void sdvxhook2_config_io_get( SDVXHOOK2_CONFIG_IO_DISABLE_POLL_LIMITER_KEY, SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE); } + + if (!cconfig_util_get_bool( + config, + SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY, + &config_io->force_headphones, + SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + SDVXHOOK2_CONFIG_IO_FORCE_HEADPHONES_KEY, + SDVXHOOK2_CONFIG_IO_DEFAULT_FORCE_HEADPHONES_VALUE); + } } diff --git a/src/main/sdvxhook2/config-io.h b/src/main/sdvxhook2/config-io.h index 610bd47..6cbd721 100644 --- a/src/main/sdvxhook2/config-io.h +++ b/src/main/sdvxhook2/config-io.h @@ -9,6 +9,7 @@ struct sdvxhook2_config_io { bool disable_card_reader_emu; bool disable_bio2_emu; bool disable_poll_limiter; + bool force_headphones; }; void sdvxhook2_config_io_init(struct cconfig *config); diff --git a/src/main/sdvxhook2/dllmain.c b/src/main/sdvxhook2/dllmain.c index 71fcde8..d534223 100644 --- a/src/main/sdvxhook2/dllmain.c +++ b/src/main/sdvxhook2/dllmain.c @@ -121,7 +121,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_bio2_emu) { bio2emu_init(); - bio2_emu_bi2a_init(&bio2_emu, config_io.disable_poll_limiter); + bio2_emu_bi2a_init(&bio2_emu, config_io.disable_poll_limiter, config_io.force_headphones); } if (!config_io.disable_card_reader_emu) {