diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index 66615ab..e818b7e 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -65,6 +65,7 @@ static const struct ezusb_iidx_emu_node *ezusb_iidx_emu_msg_v2_nodes[256] = { [EZUSB_IIDX_MSG_NODE_WDT] = &ezusb_iidx_emu_node_wdt, }; +static enum ezusb_iidx_emu_msg_io_board_type ezusb_iidx_emu_msg_io_board_type; static const struct ezusb_iidx_emu_node **ezusb_iidx_emu_node_handler; static uint8_t ezusb_iidx_emu_msg_status = 0; static uint8_t ezusb_iidx_emu_msg_seq_no = 0; @@ -72,8 +73,16 @@ static uint8_t ezusb_iidx_emu_msg_read_cur_node = 0; /* ------------------------------------------------------------------------ */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void) +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( + enum ezusb_iidx_emu_msg_io_board_type io_board_type) { + if (io_board_type < 0 || + io_board_type >= EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT) { + log_fatal("Invalid io board type %d specified", io_board_type); + } + + ezusb_iidx_emu_msg_io_board_type = io_board_type; + /* Init all nodes */ for (uint32_t i = 0; i < 256; i++) { /* "Constructor" optional */ @@ -85,6 +94,9 @@ struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void) ezusb_iidx_emu_node_handler = ezusb_iidx_emu_msg_nodes; + log_info("Initialized, io board type: %d", + ezusb_iidx_emu_msg_io_board_type); + return &ezusb_iidx_emu_msg_hook; } @@ -163,9 +175,21 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) otherwise the game's fpga check will fail */ msg_resp->fpga2_check_flag_unkn = 2; -#ifdef EZUSB_IIDX_EMU_D01_BOARD - msg_resp->inverted_pad &= ~(1 << 4); -#endif + switch (ezusb_iidx_emu_msg_io_board_type) { + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_C02: + // noop + break; + + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_D01: + msg_resp->inverted_pad &= ~(1 << 4); + break; + + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT: + default: + log_fatal("Illegal state, unhandled board type: %d", + ezusb_iidx_emu_msg_io_board_type); + break; + } read->pos = sizeof(*msg_resp); diff --git a/src/main/ezusb-iidx-emu/msg.h b/src/main/ezusb-iidx-emu/msg.h index 83d2bd6..e0198da 100644 --- a/src/main/ezusb-iidx-emu/msg.h +++ b/src/main/ezusb-iidx-emu/msg.h @@ -8,16 +8,26 @@ #include "ezusb-emu/msg.h" +enum ezusb_iidx_emu_msg_io_board_type { + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_C02 = 0, + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_D01 = 1, + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT = 2, +}; + /** - * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This + * Init the fully emulated IIDX msg backend for a EZUSB board. This * activates the "old" V1 node handling backend which was used on iidx 09 to 13. * On iidx14, the firmware was updated and removed nodes that were not used * anymore, e.g. serial card reader handling. * + * @param io_board_type Type of IO board to emulate. Note that this impacts the + * security data which is different on some game versions, e.g. 10th + * style. * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void); +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( + enum ezusb_iidx_emu_msg_io_board_type io_board_type); /** * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This