diff --git a/doc/sdvxhook/sdvxio-kfca.md b/doc/sdvxhook/sdvxio-kfca.md index 970fc94..3a506f5 100644 --- a/doc/sdvxhook/sdvxio-kfca.md +++ b/doc/sdvxhook/sdvxio-kfca.md @@ -3,12 +3,14 @@ Thus, it allows you to use a KFCA device board with *any* version of SDVX that i # Setup * Rename sdvxio-kfca.dll to sdvxio.dll. -* Ensure that your gamestart.bat actually injects the appropriate sdvxhook dll, +* Ensure that your gamestart.bat actually injects the appropriate sdvxhook dll for example: ``` -launcher -K iidxhook2.dll soundvoltex.dll ...* +launcher -K sdvxhook2.dll soundvoltex.dll ...* ``` +or that the application otherwise uses sdvxio.dll + * sdvxio-kfca expects a KFCA device on COM3 by default -* You can change the port by settings the SDVXIO_KFCA_PORT envvar +* You can change the port and baudrate by editing the sdvxio-kfca.conf that should be created by default * If there is also an ICCA device on the same ACIO bus, it cannot be used with eamio-icca at this time * Please connect any additional acio devices to their own port (ex: SDVX5 expects an ICCA by itself on COM2) diff --git a/src/main/sdvxio-kfca/Module.mk b/src/main/sdvxio-kfca/Module.mk index 744ab9e..257d071 100644 --- a/src/main/sdvxio-kfca/Module.mk +++ b/src/main/sdvxio-kfca/Module.mk @@ -3,8 +3,10 @@ dlls += sdvxio-kfca libs_sdvxio-kfca := \ geninput \ aciodrv \ + cconfig \ util \ src_sdvxio-kfca := \ sdvxio.c \ + config-kfca.c \ diff --git a/src/main/sdvxio-kfca/config-kfca.c b/src/main/sdvxio-kfca/config-kfca.c new file mode 100644 index 0000000..c94697d --- /dev/null +++ b/src/main/sdvxio-kfca/config-kfca.c @@ -0,0 +1,56 @@ +#include "cconfig/cconfig-util.h" + +#include "sdvxio-kfca/config-kfca.h" + +#include "util/log.h" + +SDVXIO_KFCA_CONFIG_KFCA_H +#define SDVXIO_KFCA_CONFIG_KFCA_PORT_KEY "kfca.port" +#define SDVXIO_KFCA_CONFIG_KFCA_BAUD_KEY "kfca.baud" + +#define SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_PORT_VALUE "COM3" +#define SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_BAUD_VALUE 57600 + +void sdvxio_kfca_config_kfca_init(struct cconfig *config) +{ + cconfig_util_set_str( + config, + SDVXIO_KFCA_CONFIG_KFCA_PORT_KEY, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_PORT_VALUE, + "KFCA ACIO serial port"); + + cconfig_util_set_int( + config, + SDVXIO_KFCA_CONFIG_KFCA_BAUD_KEY, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_BAUD_VALUE, + "KFCA ACIO bus baudrate (real devices expect 57600)"); +} + +void sdvxio_kfca_config_kfca_get( + struct sdvxio_kfca_config_kfca *config_kfca, struct cconfig *config) +{ + if (!cconfig_util_get_str( + config, + SDVXIO_KFCA_CONFIG_KFCA_PORT_KEY, + config_kfca->port, + sizeof(config_kfca->port) - 1, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_PORT_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%s'", + SDVXIO_KFCA_CONFIG_KFCA_PORT_KEY, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_PORT_VALUE); + } + + if (!cconfig_util_get_int( + config, + SDVXIO_KFCA_CONFIG_KFCA_BAUD_KEY, + &config_kfca->baud, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_BAUD_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + SDVXIO_KFCA_CONFIG_KFCA_BAUD_KEY, + SDVXIO_KFCA_CONFIG_KFCA_DEFAULT_BAUD_VALUE); + } +} diff --git a/src/main/sdvxio-kfca/config-kfca.h b/src/main/sdvxio-kfca/config-kfca.h new file mode 100644 index 0000000..36d8b1d --- /dev/null +++ b/src/main/sdvxio-kfca/config-kfca.h @@ -0,0 +1,18 @@ +#ifndef SDVXIO_KFCA_CONFIG_KFCA_H +#define SDVXIO_KFCA_CONFIG_KFCA_H + +#include + +#include "cconfig/cconfig.h" + +struct sdvxio_kfca_config_kfca { + char port[64]; + int32_t baud; +}; + +void sdvxio_kfca_config_kfca_init(struct cconfig *config); + +void sdvxio_kfca_config_kfca_get( + struct sdvxio_kfca_config_kfca *config_kfca, struct cconfig *config); + +#endif \ No newline at end of file diff --git a/src/main/sdvxio-kfca/sdvxio.c b/src/main/sdvxio-kfca/sdvxio.c index 4222a49..8f1d6f3 100644 --- a/src/main/sdvxio-kfca/sdvxio.c +++ b/src/main/sdvxio-kfca/sdvxio.c @@ -6,9 +6,13 @@ #include "bemanitools/glue.h" #include "bemanitools/sdvxio.h" +#include "cconfig/cconfig-main.h" + #include "aciodrv/device.h" #include "aciodrv/kfca.h" +#include "sdvxio-kfca/config-kfca.h" + #define LOG_MODULE "sdvxio-kfca" #define log_misc(...) sdvx_io_log_misc(LOG_MODULE, __VA_ARGS__) @@ -48,16 +52,33 @@ bool sdvx_io_init( thread_join_t thread_join, thread_destroy_t thread_destroy) { - const char* default_port = "COM3"; - const char* selected_port = getenv("SDVXIO_KFCA_PORT"); - if (!selected_port) { - selected_port = default_port; + struct cconfig *config; + struct sdvxio_kfca_config_kfca config_kfca; + + config = cconfig_init(); + + sdvxio_kfca_config_kfca_init(config); + + if (!cconfig_main_config_init( + config, + "--kfca-config", + "sdvxio-kfca.conf", + "--help", + "-h", + "sdvxio-kfca", + CCONFIG_CMD_USAGE_OUT_STDOUT)) { + cconfig_finit(config); + exit(EXIT_FAILURE); } - if (!aciodrv_device_open(selected_port, 57600)) { - log_info("Opening acio device on [%s] failed", selected_port); - return -1; + sdvxio_kfca_config_kfca_get(&config_kfca, config); + + cconfig_finit(config); + + if (!aciodrv_device_open(config_kfca.port, config_kfca.baud)) { + log_info("Opening acio device on [%s] failed", config_kfca.port); + return 0; } log_info("Opening acio device successful");