From bfbb7103efeea82217f31f6bfbda1120c6b70ede Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Sun, 2 Aug 2020 23:02:13 -0700 Subject: [PATCH] bio2emu: refactor BIO2 emulation --- Module.mk | 1 + src/main/acio/kfca.h | 2 + .../{iidxhook8/bi2a.h => bio2/bi2a-iidx.h} | 21 +---- src/main/bio2/bi2a-sdvx.h | 75 ++++++++++++++++++ src/main/bio2/bio2.h | 15 ++++ src/main/bio2emu-iidx/Module.mk | 7 ++ src/main/{iidxhook8 => bio2emu-iidx}/bi2a.c | 5 +- src/main/bio2emu-iidx/bi2a.h | 12 +++ src/main/bio2emu/setupapi.c | 4 +- src/main/iidxhook8/Module.mk | 2 +- src/main/iidxhook8/dllmain.c | 2 +- src/main/sdvxhook2/bi2a.h | 76 +------------------ 12 files changed, 122 insertions(+), 100 deletions(-) rename src/main/{iidxhook8/bi2a.h => bio2/bi2a-iidx.h} (83%) create mode 100644 src/main/bio2/bi2a-sdvx.h create mode 100644 src/main/bio2/bio2.h create mode 100644 src/main/bio2emu-iidx/Module.mk rename src/main/{iidxhook8 => bio2emu-iidx}/bi2a.c (99%) create mode 100644 src/main/bio2emu-iidx/bi2a.h diff --git a/Module.mk b/Module.mk index a623237..d0d975f 100644 --- a/Module.mk +++ b/Module.mk @@ -79,6 +79,7 @@ include src/main/acioemu/Module.mk include src/main/aciotest/Module.mk include src/main/asio/Module.mk include src/main/bio2emu/Module.mk +include src/main/bio2emu-iidx/Module.mk include src/main/bsthook/Module.mk include src/main/bstio/Module.mk include src/main/camhook/Module.mk diff --git a/src/main/acio/kfca.h b/src/main/acio/kfca.h index d8b31c3..13fbe4b 100644 --- a/src/main/acio/kfca.h +++ b/src/main/acio/kfca.h @@ -1,6 +1,8 @@ #ifndef AC_IO_KFCA_H #define AC_IO_KFCA_H +#include + #define AC_IO_CMD_KFCA_POLL 0x0113 #define AC_IO_CMD_KFCA_WATCHDOG 0x0120 #define AC_IO_CMD_KFCA_AMP_CONTROL 0x0128 diff --git a/src/main/iidxhook8/bi2a.h b/src/main/bio2/bi2a-iidx.h similarity index 83% rename from src/main/iidxhook8/bi2a.h rename to src/main/bio2/bi2a-iidx.h index 46a4d82..b219682 100644 --- a/src/main/iidxhook8/bi2a.h +++ b/src/main/bio2/bi2a-iidx.h @@ -1,18 +1,7 @@ -#ifndef IIDXHOOK_BI2A_H -#define IIDXHOOK_BI2A_H +#ifndef BIO2_BI2A_IIDX +#define BIO2_BI2A_IIDX -#include -#include -#include - -#include "bio2emu/emu.h" - -enum bio2_iidx_cmd { - // Custom Stuff - BIO2_BI2A_CMD_UNK_0100 = 0x0100, - BIO2_BI2A_CMD_UNK_0120 = 0x0120, - BIO2_BI2A_CMD_POLL = 0x0152, -}; +#include "bio2/bio2.h" #pragma pack(push, 1) struct bi2a_iidx_slider { @@ -114,8 +103,4 @@ _Static_assert( "bi2a_iidx_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_dispatch_request( - struct bio2emu_port *bio2port, const struct ac_io_message *req); - #endif diff --git a/src/main/bio2/bi2a-sdvx.h b/src/main/bio2/bi2a-sdvx.h new file mode 100644 index 0000000..d75d909 --- /dev/null +++ b/src/main/bio2/bi2a-sdvx.h @@ -0,0 +1,75 @@ +#ifndef BIO2_BI2A_SDVX +#define BIO2_BI2A_SDVX + +#include "bio2/bio2.h" + +#pragma pack(push, 1) +struct bi2a_sdvx_analog { + uint16_t unk1 : 1; + uint16_t a_coin : 1; + uint16_t a_service : 1; + uint16_t a_test : 1; + uint16_t unk2 : 2; + uint16_t a_val : 10; +}; + +struct bi2a_sdvx_buttons1 { + uint8_t b_fxl : 1; + uint8_t b_d : 1; + uint8_t b_c : 1; + uint8_t b_b : 1; + uint8_t b_a : 1; + uint8_t b_start : 1; + uint8_t b_recorder : 1; + uint8_t b_headphone : 1; +}; + +struct bi2a_sdvx_buttons2 { + uint8_t unk : 5; + uint8_t b_ex2 : 1; + uint8_t b_ex1 : 1; + uint8_t b_fxr : 1; +}; + +struct bio2_bi2a_state { + union { + uint16_t raw[8]; + struct { + struct bi2a_sdvx_analog analogs[4]; + uint8_t unk_1; // coin mech? + struct bi2a_sdvx_buttons1 buttons_1; + struct bi2a_sdvx_buttons2 buttons_2; + uint8_t unk_2[5]; + }; + }; +}; + +struct bio2_bi2a_state_out { + uint8_t unk1[2]; + uint8_t c_block; + uint8_t woof_r; + uint8_t woof_g; + uint8_t unk2; + uint8_t woof_b; + uint8_t controller[3]; + uint8_t unk3; + uint8_t gpio[7]; // START, ABCD, FXL, FXR + uint8_t unk4[3]; + uint8_t generator[3]; + uint8_t unk5[3]; + uint8_t gpio2[3]; // pop, titleL, titleR + uint8_t unk6; + uint8_t wingUpper[3]; + uint8_t wingLower[3]; + uint8_t unk7[3]; +}; + +_Static_assert( + sizeof(struct bio2_bi2a_state) == 16, + "bio2_bi2a_state_in is the wrong size"); +_Static_assert( + sizeof(struct bio2_bi2a_state_out) == 40, + "bio2_bi2a_state_out is the wrong size"); +#pragma pack(pop) + +#endif diff --git a/src/main/bio2/bio2.h b/src/main/bio2/bio2.h new file mode 100644 index 0000000..c30067f --- /dev/null +++ b/src/main/bio2/bio2.h @@ -0,0 +1,15 @@ +#ifndef BIO2_BIO2 +#define BIO2_BIO2 + +#include +#include +#include + +enum bio2_bi2a_cmd { + // Custom Stuff + BIO2_BI2A_CMD_UNK_0100 = 0x0100, + BIO2_BI2A_CMD_UNK_0120 = 0x0120, + BIO2_BI2A_CMD_POLL = 0x0152, // For IIDX +}; + +#endif \ No newline at end of file diff --git a/src/main/bio2emu-iidx/Module.mk b/src/main/bio2emu-iidx/Module.mk new file mode 100644 index 0000000..aa9e7d1 --- /dev/null +++ b/src/main/bio2emu-iidx/Module.mk @@ -0,0 +1,7 @@ +libs += bio2emu-iidx + +libs_bio2emu-iidx := \ + bio2emu \ + +src_bio2emu-iidx := \ + bi2a.c \ diff --git a/src/main/iidxhook8/bi2a.c b/src/main/bio2emu-iidx/bi2a.c similarity index 99% rename from src/main/iidxhook8/bi2a.c rename to src/main/bio2emu-iidx/bi2a.c index d419e2e..c590f29 100644 --- a/src/main/iidxhook8/bi2a.c +++ b/src/main/bio2emu-iidx/bi2a.c @@ -1,7 +1,6 @@ -#define LOG_MODULE "bio2emu-bi2a" +#define LOG_MODULE "bio2emu-iidx" -#include "iidxhook8/bi2a.h" -#include "bio2emu/emu.h" +#include "bio2emu-iidx/bi2a.h" #include /* for _BitScanForward */ diff --git a/src/main/bio2emu-iidx/bi2a.h b/src/main/bio2emu-iidx/bi2a.h new file mode 100644 index 0000000..c8e3d55 --- /dev/null +++ b/src/main/bio2emu-iidx/bi2a.h @@ -0,0 +1,12 @@ +#ifndef BIO2EMU_IIDX_BI2A_H +#define BIO2EMU_IIDX_BI2A_H + +#include "bio2/bi2a-iidx.h" + +#include "bio2emu/emu.h" + +void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter); +void bio2_emu_bi2a_dispatch_request( + struct bio2emu_port *bio2port, const struct ac_io_message *req); + +#endif diff --git a/src/main/bio2emu/setupapi.c b/src/main/bio2emu/setupapi.c index ac33ec8..5dbfffc 100644 --- a/src/main/bio2emu/setupapi.c +++ b/src/main/bio2emu/setupapi.c @@ -350,8 +350,8 @@ static CONFIGRET my_CM_Get_Device_IDA( log_info("%s: Injecting custom parent ID for BIO2", __FUNCTION__); strcpy(Buffer, devpath); - Buffer[devpathsize - 1] = - '\0' + (dnDevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); + Buffer[devpathsize - 2] = + '0' + (dnDevInst & CUSTOM_DEVICE_INSTANCE_IDXMASK); log_info("%s: %s", __FUNCTION__, Buffer); return CR_SUCCESS; } diff --git a/src/main/iidxhook8/Module.mk b/src/main/iidxhook8/Module.mk index 9d2f8a3..f51688c 100644 --- a/src/main/iidxhook8/Module.mk +++ b/src/main/iidxhook8/Module.mk @@ -15,6 +15,7 @@ libs_iidxhook8 := \ iidxhook-util \ acioemu \ bio2emu \ + bio2emu-iidx \ camhook \ iidxio \ hook \ @@ -24,6 +25,5 @@ libs_iidxhook8 := \ eamio \ src_iidxhook8 := \ - bi2a.c \ config-io.c \ dllmain.c \ diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 862609c..a17abaa 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -24,7 +24,7 @@ #include "iidxhook-util/log-server.h" #include "bio2emu/emu.h" -#include "iidxhook8/bi2a.h" +#include "bio2emu-iidx/bi2a.h" #include "camhook/cam.h" #include "camhook/config-cam.h" diff --git a/src/main/sdvxhook2/bi2a.h b/src/main/sdvxhook2/bi2a.h index d65b655..f0444e7 100644 --- a/src/main/sdvxhook2/bi2a.h +++ b/src/main/sdvxhook2/bi2a.h @@ -6,82 +6,8 @@ #include #include "bio2emu/emu.h" +#include "bio2/bi2a-sdvx.h" -enum bio2_bi2a_cmd { - // Custom Stuff - BIO2_BI2A_CMD_UNK_0100 = 0x0100, - BIO2_BI2A_CMD_UNK_0120 = 0x0120, - BIO2_BI2A_CMD_POLL = 0x0152, -}; - -#pragma pack(push, 1) -struct bi2a_sdvx_analog { - uint16_t unk1 : 1; - uint16_t a_coin : 1; - uint16_t a_service : 1; - uint16_t a_test : 1; - uint16_t unk2 : 2; - uint16_t a_val : 10; -}; - -struct bi2a_sdvx_buttons1 { - uint8_t b_fxl : 1; - uint8_t b_d : 1; - uint8_t b_c : 1; - uint8_t b_b : 1; - uint8_t b_a : 1; - uint8_t b_start : 1; - uint8_t b_recorder : 1; - uint8_t b_headphone : 1; -}; - -struct bi2a_sdvx_buttons2 { - uint8_t unk : 5; - uint8_t b_ex2 : 1; - uint8_t b_ex1 : 1; - uint8_t b_fxr : 1; -}; - -struct bio2_bi2a_state { - union { - uint16_t raw[8]; - struct { - struct bi2a_sdvx_analog analogs[4]; - uint8_t unk_1; // coin mech? - struct bi2a_sdvx_buttons1 buttons_1; - struct bi2a_sdvx_buttons2 buttons_2; - uint8_t unk_2[5]; - }; - }; -}; - -struct bio2_bi2a_state_out { - uint8_t unk1[2]; - uint8_t c_block; - uint8_t woof_r; - uint8_t woof_g; - uint8_t unk2; - uint8_t woof_b; - uint8_t controller[3]; - uint8_t unk3; - uint8_t gpio[7]; // START, ABCD, FXL, FXR - uint8_t unk4[3]; - uint8_t generator[3]; - uint8_t unk5[3]; - uint8_t gpio2[3]; // pop, titleL, titleR - uint8_t unk6; - uint8_t wingUpper[3]; - uint8_t wingLower[3]; - uint8_t unk7[3]; -}; - -_Static_assert( - sizeof(struct bio2_bi2a_state) == 16, - "bio2_bi2a_state_in is the wrong size"); -_Static_assert( - sizeof(struct bio2_bi2a_state_out) == 40, - "bio2_bi2a_state_out is the wrong size"); -#pragma pack(pop) void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter, bool force_headphones); void bio2_emu_bi2a_dispatch_request(