forked from TeamTofuShop/segatools
Include chu2to3 engine
This commit is contained in:
@ -39,6 +39,50 @@ const struct dll_bind_sym chuni_dll_syms[] = {
|
||||
}
|
||||
};
|
||||
|
||||
const struct dll_bind_sym chu2to3_dll_syms[] = {
|
||||
{
|
||||
.sym = "chu2to3_io_jvs_init",
|
||||
.off = offsetof(struct chuni_dll, jvs_init),
|
||||
}, {
|
||||
.sym = "chu2to3_io_jvs_poll",
|
||||
.off = offsetof(struct chuni_dll, jvs_poll),
|
||||
}, {
|
||||
.sym = "chu2to3_io_jvs_read_coin_counter",
|
||||
.off = offsetof(struct chuni_dll, jvs_read_coin_counter),
|
||||
}, {
|
||||
.sym = "chu2to3_io_slider_init",
|
||||
.off = offsetof(struct chuni_dll, slider_init),
|
||||
}, {
|
||||
.sym = "chu2to3_io_slider_start",
|
||||
.off = offsetof(struct chuni_dll, slider_start),
|
||||
}, {
|
||||
.sym = "chu2to3_io_slider_stop",
|
||||
.off = offsetof(struct chuni_dll, slider_stop),
|
||||
}, {
|
||||
.sym = "chu2to3_io_slider_set_leds",
|
||||
.off = offsetof(struct chuni_dll, slider_set_leds),
|
||||
}, {
|
||||
.sym = "chu2to3_io_led_init",
|
||||
.off = offsetof(struct chuni_dll, led_init),
|
||||
}, {
|
||||
.sym = "chu2to3_io_led_set_colors",
|
||||
.off = offsetof(struct chuni_dll, led_set_leds),
|
||||
}
|
||||
};
|
||||
|
||||
/* Helper function to determine upon dll_bind failure whether the required functions were found
|
||||
NOTE: relies on symbols order declared above */
|
||||
static HRESULT has_enough_symbols(uint16_t version, uint8_t count)
|
||||
{
|
||||
if ( version <= 0x0101 && count == 7 )
|
||||
return S_OK;
|
||||
|
||||
if ( version >= 0x0102 && count == 9 )
|
||||
return S_OK;
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
struct chuni_dll chuni_dll;
|
||||
|
||||
// Copypasta DLL binding and diagnostic message boilerplate.
|
||||
@ -58,7 +102,12 @@ HRESULT chuni_dll_init(const struct chuni_dll_config *cfg, HINSTANCE self)
|
||||
assert(cfg != NULL);
|
||||
assert(self != NULL);
|
||||
|
||||
if (cfg->path[0] != L'\0') {
|
||||
owned = NULL;
|
||||
src = self;
|
||||
|
||||
if (cfg->chu2to3) {
|
||||
dprintf("Chunithm IO: using chu2to3 engine for IO DLL: %S\n", cfg->path);
|
||||
} else if (cfg->path[0] != L'\0') {
|
||||
owned = LoadLibraryW(cfg->path);
|
||||
|
||||
if (owned == NULL) {
|
||||
@ -72,12 +121,18 @@ HRESULT chuni_dll_init(const struct chuni_dll_config *cfg, HINSTANCE self)
|
||||
|
||||
dprintf("Chunithm IO: Using custom IO DLL: %S\n", cfg->path);
|
||||
src = owned;
|
||||
} else {
|
||||
owned = NULL;
|
||||
src = self;
|
||||
}
|
||||
|
||||
get_api_version = (void *) GetProcAddress(src, "chuni_io_get_api_version");
|
||||
if (cfg->chu2to3) {
|
||||
if (chu2to3_load_dll(cfg->path) != 0)
|
||||
dprintf("Could not init chu2to3 engine\n");
|
||||
|
||||
get_api_version = (void *) GetProcAddress(src, "chu2to3_io_get_api_version");
|
||||
}
|
||||
else
|
||||
{
|
||||
get_api_version = (void *) GetProcAddress(src, "chuni_io_get_api_version");
|
||||
}
|
||||
|
||||
if (get_api_version != NULL) {
|
||||
chuni_dll.api_version = get_api_version();
|
||||
@ -97,17 +152,26 @@ HRESULT chuni_dll_init(const struct chuni_dll_config *cfg, HINSTANCE self)
|
||||
goto end;
|
||||
}
|
||||
|
||||
sym = chuni_dll_syms;
|
||||
sym = cfg->chu2to3 ? chu2to3_dll_syms : chuni_dll_syms;
|
||||
const struct dll_bind_sym *init_sym = &sym[0];
|
||||
|
||||
hr = dll_bind(&chuni_dll, src, &sym, _countof(chuni_dll_syms));
|
||||
|
||||
if (FAILED(hr)) {
|
||||
if (src != self) {
|
||||
dprintf("Chunithm IO: Custom IO DLL does not provide function "
|
||||
"\"%s\". Please contact your IO DLL's developer for "
|
||||
"further assistance.\n",
|
||||
sym->sym);
|
||||
|
||||
goto end;
|
||||
// Might still be ok depending on external dll API version
|
||||
int bind_count = sym - init_sym;
|
||||
if ( has_enough_symbols(chuni_dll.api_version, bind_count) == S_OK )
|
||||
{
|
||||
hr = S_OK;
|
||||
} else {
|
||||
dprintf("Chunithm IO: Custom IO DLL does not provide function "
|
||||
"\"%s\". Please contact your IO DLL's developer for "
|
||||
"further assistance.\n",
|
||||
sym->sym);
|
||||
dprintf("imported %d symbols\n",bind_count);
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
dprintf("Internal error: could not reflect \"%s\"\n", sym->sym);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ struct chuni_dll {
|
||||
|
||||
struct chuni_dll_config {
|
||||
wchar_t path[MAX_PATH];
|
||||
uint8_t chu2to3;
|
||||
};
|
||||
|
||||
extern struct chuni_dll chuni_dll;
|
||||
|
@ -22,3 +22,13 @@ EXPORTS
|
||||
chuni_io_slider_stop
|
||||
chuni_io_led_init
|
||||
chuni_io_led_set_colors
|
||||
chu2to3_io_get_api_version
|
||||
chu2to3_io_jvs_init
|
||||
chu2to3_io_jvs_poll
|
||||
chu2to3_io_jvs_read_coin_counter
|
||||
chu2to3_io_slider_init
|
||||
chu2to3_io_slider_set_leds
|
||||
chu2to3_io_slider_start
|
||||
chu2to3_io_slider_stop
|
||||
chu2to3_io_led_init
|
||||
chu2to3_io_led_set_colors
|
||||
|
@ -39,16 +39,27 @@ void chuni_dll_config_load(
|
||||
|
||||
// Workaround for x64/x86 external IO dlls
|
||||
// path32 for 32bit, path64 for 64bit
|
||||
// for else.. is that possible? idk
|
||||
// path for 32bit only dlls (internal chu2to3 engine)
|
||||
|
||||
#if defined(ENV32BIT)
|
||||
GetPrivateProfileStringW(
|
||||
L"chuniio",
|
||||
L"path32",
|
||||
L"",
|
||||
cfg->path,
|
||||
_countof(cfg->path),
|
||||
filename);
|
||||
GetPrivateProfileStringW(
|
||||
L"chuniio",
|
||||
L"path",
|
||||
L"",
|
||||
cfg->path,
|
||||
_countof(cfg->path),
|
||||
filename);
|
||||
if (cfg->path[0] != L'\0') {
|
||||
cfg->chu2to3 = 1;
|
||||
} else {
|
||||
cfg->chu2to3 = 0;
|
||||
#if defined(ENV32BIT)
|
||||
GetPrivateProfileStringW(
|
||||
L"chuniio",
|
||||
L"path32",
|
||||
L"",
|
||||
cfg->path,
|
||||
_countof(cfg->path),
|
||||
filename);
|
||||
#elif defined(ENV64BIT)
|
||||
GetPrivateProfileStringW(
|
||||
L"chuniio",
|
||||
@ -60,7 +71,7 @@ void chuni_dll_config_load(
|
||||
#else
|
||||
#error "Unknown environment"
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void slider_config_load(struct slider_config *cfg, const wchar_t *filename)
|
||||
|
@ -129,11 +129,16 @@ static DWORD CALLBACK chusan_pre_startup(void)
|
||||
}
|
||||
}
|
||||
|
||||
hr = led15093_hook_init(&chusan_hook_cfg.led15093,
|
||||
chuni_dll.led_init, chuni_dll.led_set_leds, first_port, 2, 2, 1);
|
||||
if ( chuni_dll.led_init == NULL || chuni_dll.led_set_leds == NULL )
|
||||
{
|
||||
dprintf("IO DLL doesn't support led_init/led_set_leds, cannot start LED15093 hook\n");
|
||||
} else {
|
||||
hr = led15093_hook_init(&chusan_hook_cfg.led15093,
|
||||
chuni_dll.led_init, chuni_dll.led_set_leds, first_port, 2, 2, 1);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
goto fail;
|
||||
if (FAILED(hr)) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
hr = sg_reader_hook_init(&chusan_hook_cfg.aime, 4, is_cvt ? 2: 3, chusan_hook_mod);
|
||||
|
Reference in New Issue
Block a user