From 3dd6054a1ee77dcff31ad2cd2baa653cef192644 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Sun, 3 Dec 2023 21:34:38 +0100 Subject: [PATCH] chusan, fgo, mu3: fixed LED 15093 board --- board/led15093.c | 31 +++++++++++++------------------ board/led15093.h | 9 ++++----- carolhook/dllmain.c | 2 +- chunihook/config.c | 3 +-- chunihook/dllmain.c | 2 +- chusanhook/config.c | 34 +++++++++++----------------------- chusanhook/dllmain.c | 28 +++++++++++++++++++++++++++- dist/chusan/segatools.ini | 7 +++---- dist/fgo/segatools.ini | 4 ++-- fgohook/config.c | 5 ++--- fgohook/dllmain.c | 2 +- hooklib/printer.c | 6 +++--- mu3hook/config.h | 2 ++ mu3hook/dllmain.c | 8 +++++++- platform/dipsw.c | 5 ++--- 15 files changed, 80 insertions(+), 68 deletions(-) diff --git a/board/led15093.c b/board/led15093.c index c00e39f..c18b1b0 100644 --- a/board/led15093.c +++ b/board/led15093.c @@ -24,7 +24,6 @@ #include "board/led15093-cmd.h" #include "board/led15093-frame.h" - #include "board/led15093.h" #include "hook/iobuf.h" @@ -101,43 +100,39 @@ static char led15093_chip_num[5]; static char led15093_boot_chip_num[5]; static uint8_t led15093_fw_ver; static uint16_t led15093_fw_sum; -static uint8_t led15093_host_adr = 255; +static uint8_t led15093_board_adr = 1; +static uint8_t led15093_host_adr = 1; -HRESULT led15093_hook_init( - const struct led15093_config *cfg, - unsigned int port_no_0, - unsigned int port_no_1) +HRESULT led15093_hook_init(const struct led15093_config *cfg, unsigned int first_port, + unsigned int num_boards, uint8_t board_adr, uint8_t host_adr) { + assert(cfg != NULL); - unsigned int port_no[2] = {port_no_0, port_no_1}; if (!cfg->enable) { return S_FALSE; } - for (int i = 0; i < led15093_nboards; i++) { - if (cfg->port_no[i] != 0) { - port_no[i] = cfg->port_no[i]; - } + if (cfg->port_no != 0) { + first_port = cfg->port_no; } + led15093_board_adr = board_adr; + led15093_host_adr = host_adr; + memcpy(led15093_board_num, cfg->board_number, sizeof(led15093_board_num)); memcpy(led15093_chip_num, cfg->chip_number, sizeof(led15093_chip_num)); memcpy(led15093_boot_chip_num, cfg->boot_chip_number, sizeof(led15093_boot_chip_num)); led15093_fw_ver = cfg->fw_ver; led15093_fw_sum = cfg->fw_sum; - for (int i = 0; i < led15093_nboards; i++) + for (int i = 0; i < num_boards; i++) { _led15093_per_board_vars *vb = &led15093_per_board_vars[i]; InitializeCriticalSection(&vb->lock); - if (port_no[i] == 0) { - continue; - } - - uart_init(&vb->boarduart, port_no[i]); + uart_init(&vb->boarduart, first_port + i); if (cfg->high_baudrate) { vb->boarduart.baud.BaudRate = 460800; } else { @@ -160,7 +155,7 @@ HRESULT led15093_hook_init( led15093_clear_status(i, 1 + j); led15093_clear_report(i, 1 + j); vn->boardstatus[3] = 1; // DIPSW1 ON - vn->boardadr = 1 + j; + vn->boardadr = led15093_board_adr + j; vn->enable_bootloader = false; vn->enable_response = true; } diff --git a/board/led15093.h b/board/led15093.h index ae4c27c..4e1b7f4 100644 --- a/board/led15093.h +++ b/board/led15093.h @@ -8,7 +8,7 @@ struct led15093_config { bool enable; bool high_baudrate; - unsigned int port_no[2]; + unsigned int port_no; char board_number[8]; char chip_number[5]; char boot_chip_number[5]; @@ -16,7 +16,6 @@ struct led15093_config { uint16_t fw_sum; }; -HRESULT led15093_hook_init( - const struct led15093_config *cfg, - unsigned int port_no_0, - unsigned int port_no_1); +HRESULT led15093_hook_init(const struct led15093_config *cfg, unsigned int first_port, + unsigned int num_boards, uint8_t board_adr, uint8_t host_adr); + diff --git a/carolhook/dllmain.c b/carolhook/dllmain.c index 6ff4c9f..3e86f6d 100644 --- a/carolhook/dllmain.c +++ b/carolhook/dllmain.c @@ -102,7 +102,7 @@ static DWORD CALLBACK carol_pre_startup(void) goto fail; } - hr = sg_reader_hook_init(&carol_hook_cfg.aime, 10, carol_hook_mod); + hr = sg_reader_hook_init(&carol_hook_cfg.aime, 10, 1, carol_hook_mod); if (FAILED(hr)) { goto fail; diff --git a/chunihook/config.c b/chunihook/config.c index 92e99de..99b9c3a 100644 --- a/chunihook/config.c +++ b/chunihook/config.c @@ -55,8 +55,7 @@ void led15093_config_load(struct led15093_config *cfg, const wchar_t *filename) memset(cfg->boot_chip_number, ' ', sizeof(cfg->boot_chip_number)); cfg->enable = GetPrivateProfileIntW(L"led15093", L"enable", 1, filename); - cfg->port_no[0] = GetPrivateProfileIntW(L"led15093", L"portNo0", 0, filename); - cfg->port_no[1] = GetPrivateProfileIntW(L"led15093", L"portNo1", 0, filename); + cfg->port_no = 0; cfg->high_baudrate = GetPrivateProfileIntW(L"led15093", L"highBaudrate", 0, filename); cfg->fw_ver = GetPrivateProfileIntW(L"led15093", L"fwVer", 0x90, filename); cfg->fw_sum = GetPrivateProfileIntW(L"led15093", L"fwSum", 0xadf7, filename); diff --git a/chunihook/dllmain.c b/chunihook/dllmain.c index 7035943..d598672 100644 --- a/chunihook/dllmain.c +++ b/chunihook/dllmain.c @@ -96,7 +96,7 @@ static DWORD CALLBACK chuni_pre_startup(void) goto fail; } - hr = led15093_hook_init(&chuni_hook_cfg.led15093, 10, 11); + hr = led15093_hook_init(&chuni_hook_cfg.led15093, 10, 2, 2, 1); if (FAILED(hr)) { goto fail; diff --git a/chusanhook/config.c b/chusanhook/config.c index f585926..f3ff50e 100644 --- a/chusanhook/config.c +++ b/chusanhook/config.c @@ -14,20 +14,20 @@ // Check windows #if _WIN32 || _WIN64 - #if _WIN64 - #define ENV64BIT - #else - #define ENV32BIT - #endif + #if _WIN64 + #define ENV64BIT + #else + #define ENV32BIT + #endif #endif // Check GCC #if __GNUC__ - #if __x86_64__ || __ppc64__ - #define ENV64BIT - #else - #define ENV32BIT - #endif + #if __x86_64__ || __ppc64__ + #define ENV64BIT + #else + #define ENV32BIT + #endif #endif void chuni_dll_config_load( @@ -84,18 +84,7 @@ void led15093_config_load(struct led15093_config *cfg, const wchar_t *filename) memset(cfg->boot_chip_number, ' ', sizeof(cfg->boot_chip_number)); cfg->enable = GetPrivateProfileIntW(L"led15093", L"enable", 1, filename); - cvt_port = GetPrivateProfileIntW(L"led15093", L"cvtPort", 0, filename); - - if (!cvt_port) { - // SP mode: COM20, COM21 - cfg->port_no[0] = 20; - cfg->port_no[1] = 21; - } else { - // CVT mode: COM2, COM3 - cfg->port_no[0] = 2; - cfg->port_no[1] = 3; - } - + cfg->port_no = 0; cfg->high_baudrate = GetPrivateProfileIntW(L"led15093", L"highBaudrate", 0, filename); cfg->fw_ver = GetPrivateProfileIntW(L"led15093", L"fwVer", 0x90, filename); cfg->fw_sum = GetPrivateProfileIntW(L"led15093", L"fwSum", 0xadf7, filename); @@ -143,7 +132,6 @@ void led15093_config_load(struct led15093_config *cfg, const wchar_t *filename) } } - void chusan_hook_config_load( struct chusan_hook_config *cfg, const wchar_t *filename) diff --git a/chusanhook/dllmain.c b/chusanhook/dllmain.c index 3375158..cd66dbd 100644 --- a/chusanhook/dllmain.c +++ b/chusanhook/dllmain.c @@ -99,7 +99,33 @@ static DWORD CALLBACK chusan_pre_startup(void) goto fail; } - hr = led15093_hook_init(&chusan_hook_cfg.led15093, 20, 21); + bool *dipsw = &chusan_hook_cfg.platform.dipsw.dipsw[0]; + + if (dipsw[1] != dipsw[2]) { + dprintf("DipSw: DipSw2 and 3 must be set to the same value!\n"); + goto fail; + } + + for (int i = 0; i < 3; i++) { + switch (i) { + case 0: + dprintf("DipSw: NetInstall: %s\n", dipsw[0] ? "Server" : "Client"); + break; + + case 1: + dprintf("DipSw: Monitor Type: %dFPS\n", dipsw[1] ? 60 : 120); + break; + + case 2: + dprintf("DipSw: Aime Reader: %s\n", dipsw[2] ? "CVT" : "SP"); + + break; + } + } + + unsigned int first_port = dipsw[1] ? 2 : 20; + + hr = led15093_hook_init(&chusan_hook_cfg.led15093, first_port, 2, 2, 1); if (FAILED(hr)) { goto fail; diff --git a/dist/chusan/segatools.ini b/dist/chusan/segatools.ini index dc6e2ae..df17ac3 100644 --- a/dist/chusan/segatools.ini +++ b/dist/chusan/segatools.ini @@ -46,22 +46,21 @@ enable=1 dipsw1=1 ; Monitor type: 0 = 120FPS (SP), 1 = 60FPS (CVT) dipsw2=1 -; Aime reader hardware type: 0 = SP, 1 = CVT +; Aime reader hardware type: 0 = SP, 1 = CVT. Both dipsw2 and dipsw3 must be +; the same value. dipsw3=1 [gfx] ; Force the game to run windowed. windowed=1 ; Add a frame to the game window if running windowed. -framed=1 +framed=0 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 [led15093] ; 837-15093-06 LED strip emulation setting. enable=1 -; Set to 1 if running game in 60FPS (CVT) mode. -cvtPort=0 [chuniio] ; Uncomment this if you have custom chuniio implementation. diff --git a/dist/fgo/segatools.ini b/dist/fgo/segatools.ini index 18e2bbb..d106aaf 100644 --- a/dist/fgo/segatools.ini +++ b/dist/fgo/segatools.ini @@ -64,8 +64,8 @@ portNo=17 [led15093] ; 837-15093-06 LED board emulation setting. enable=1 -; COM port number for the first LED board. Has to be the same as the FTDI port. -portNo0=17 +; COM port number for the LED board. Has to be the same as the FTDI port. +portNo=17 ; ----------------------------------------------------------------------------- ; Input settings diff --git a/fgohook/config.c b/fgohook/config.c index 3253568..4b05e97 100644 --- a/fgohook/config.c +++ b/fgohook/config.c @@ -47,11 +47,10 @@ void led15093_config_load(struct led15093_config *cfg, const wchar_t *filename) memset(cfg->boot_chip_number, ' ', sizeof(cfg->boot_chip_number)); cfg->enable = GetPrivateProfileIntW(L"led15093", L"enable", 1, filename); - cfg->port_no[0] = GetPrivateProfileIntW(L"led15093", L"portNo0", 0, filename); - cfg->port_no[1] = GetPrivateProfileIntW(L"led15093", L"portNo1", 0, filename); + cfg->port_no = GetPrivateProfileIntW(L"led15093", L"portNo", 0, filename); cfg->high_baudrate = GetPrivateProfileIntW(L"led15093", L"highBaudrate", 0, filename); cfg->fw_ver = GetPrivateProfileIntW(L"led15093", L"fwVer", 0xA0, filename); - cfg->fw_sum = GetPrivateProfileIntW(L"led15093", L"fwSum", 0xaa53, filename); + cfg->fw_sum = GetPrivateProfileIntW(L"led15093", L"fwSum", 0xAA53, filename); GetPrivateProfileStringW( L"led15093", diff --git a/fgohook/dllmain.c b/fgohook/dllmain.c index 6dc722c..fcac111 100644 --- a/fgohook/dllmain.c +++ b/fgohook/dllmain.c @@ -96,7 +96,7 @@ static DWORD CALLBACK fgo_pre_startup(void) goto fail; } - hr = led15093_hook_init(&fgo_hook_cfg.led15093, 17, 0); + hr = led15093_hook_init(&fgo_hook_cfg.led15093, 17, 1, 1, 2); if (FAILED(hr)) { goto fail; diff --git a/hooklib/printer.c b/hooklib/printer.c index bdc913c..1ef5a0c 100644 --- a/hooklib/printer.c +++ b/hooklib/printer.c @@ -1042,7 +1042,7 @@ static HRESULT deck_frame_encode_byte(struct iobuf *dest, uint8_t byte) { return S_OK; } -// C310FWDLusb stubs +// C3XXFWDLusb stubs int fwdlusb_open(uint16_t *rResult) { dprintf("Printer: C3XXFWDLusb: %s\n", __func__); @@ -1674,7 +1674,7 @@ int chcusb_getPrinterInfo(uint16_t tagNumber, uint8_t *rBuffer, uint32_t *rLen) break; case 20: // printMode - dprintf("Printer: C3xxusb: Unimpl tagNumber 20\n"); + dprintf("Printer: C3XXusb: Unimpl tagNumber 20\n"); break; case 26: // getPrinterSerial @@ -1683,7 +1683,7 @@ int chcusb_getPrinterInfo(uint16_t tagNumber, uint8_t *rBuffer, uint32_t *rLen) break; case 30: // TODO - dprintf("Printer: C3xxusb: Unimpl tagNumber 30\n"); + dprintf("Printer: C3XXusb: Unimpl tagNumber 30\n"); break; case 31: // TODO, possibly CardRFIDCheck? diff --git a/mu3hook/config.h b/mu3hook/config.h index 58af239..1273983 100644 --- a/mu3hook/config.h +++ b/mu3hook/config.h @@ -3,6 +3,7 @@ #include #include "board/config.h" +#include "board/led15093.h" #include "gfxhook/gfx.h" @@ -18,6 +19,7 @@ struct mu3_hook_config { struct dvd_config dvd; struct io4_config io4; struct gfx_config gfx; + struct led15093_config led15093; struct mu3_dll_config dll; }; diff --git a/mu3hook/dllmain.c b/mu3hook/dllmain.c index dd01104..b867345 100644 --- a/mu3hook/dllmain.c +++ b/mu3hook/dllmain.c @@ -61,7 +61,13 @@ static DWORD CALLBACK mu3_pre_startup(void) goto fail; } - hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1, mu3_hook_mod); + hr = led15093_hook_init(&mu3_hook_cfg.led15093, 3, 1, 1, 2); + + if (FAILED(hr)) { + return hr; + } + + hr = sg_reader_hook_init(&mu3_hook_cfg.aime, 1, 1, mu3_hook_mod); if (FAILED(hr)) { goto fail; diff --git a/platform/dipsw.c b/platform/dipsw.c index ee6dd91..b9caf44 100644 --- a/platform/dipsw.c +++ b/platform/dipsw.c @@ -74,7 +74,7 @@ static void dipsw_read_sysfile(const wchar_t *sys_file) if (f == NULL) { - dprintf("First run detected, DipSw settings can only be applied AFTER the first run\n"); + dprintf("DipSw: First run detected, DipSw settings can only be applied AFTER the first run\n"); return; } @@ -84,7 +84,7 @@ static void dipsw_read_sysfile(const wchar_t *sys_file) if (file_size != 0x6000) { - dprintf("Invalid sysfile.dat file size\n"); + dprintf("DipSw: Invalid sysfile.dat file size\n"); fclose(f); return; @@ -94,7 +94,6 @@ static void dipsw_read_sysfile(const wchar_t *sys_file) fread(dip_switches.data, 1, file_size, f); fclose(f); - // memcpy(dip_switches.dip_switch_block, dip_switches.data + 0x2800, BLOCK_SIZE); memcpy(&dip_switches.dip_switch_block, dip_switches.data + 0x2800, BLOCK_SIZE); }