1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-27 22:40:48 +01:00

Wire up libamex config

This commit is contained in:
Tau 2019-05-04 13:12:20 -04:00
parent 68ec23e3c8
commit c19d140589
18 changed files with 186 additions and 64 deletions

View File

@ -1,3 +1,5 @@
#include <windows.h>
#include "amex/amex.h"
#include "amex/ds.h"
#include "amex/eeprom.h"
@ -5,11 +7,41 @@
#include "amex/jvs.h"
#include "amex/sram.h"
void amex_hook_init(void)
HRESULT amex_hook_init(const struct amex_config *cfg)
{
ds_hook_init();
eeprom_hook_init();
gpio_hook_init();
jvs_hook_init();
sram_hook_init();
HRESULT hr;
assert(cfg != NULL);
hr = ds_hook_init(&cfg->ds);
if (FAILED(hr)) {
return hr;
}
hr = eeprom_hook_init(&cfg->eeprom);
if (FAILED(hr)) {
return hr;
}
hr = gpio_hook_init(&cfg->gpio);
if (FAILED(hr)) {
return hr;
}
hr = jvs_hook_init(&cfg->jvs);
if (FAILED(hr)) {
return hr;
}
hr = sram_hook_init(&cfg->sram);
if (FAILED(hr)) {
return hr;
}
return S_OK;
}

View File

@ -1,3 +1,7 @@
#pragma once
void amex_hook_init(void);
#include <windows.h>
#include "amex/cfg.h"
HRESULT amex_hook_init(const struct amex_config *cfg);

View File

@ -5,7 +5,6 @@
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "amex/ds.h"
@ -46,29 +45,29 @@ static HRESULT ds_ioctl_get_geometry(struct irp *irp);
static HRESULT ds_ioctl_setup(struct irp *irp);
static HRESULT ds_ioctl_read_sector(struct irp *irp);
static const char ds_serial_file[] = "DEVICE/pcbid.txt";
static struct ds_eeprom ds_eeprom;
static HANDLE ds_fd;
HRESULT ds_hook_init(void)
HRESULT ds_hook_init(const struct ds_config *cfg)
{
HRESULT hr;
int region;
FILE *f;
region = 0x01; /* Japan; use this default if ds.txt read fails */
memset(&ds_eeprom, 0, sizeof(ds_eeprom));
assert(cfg != NULL);
f = fopen(ds_serial_file, "r");
if (f != NULL) {
fscanf(f, "%16s %x", ds_eeprom.serial_no, &region);
fclose(f);
} else {
dprintf("Failed to open %s\n", ds_serial_file);
if (!cfg->enable) {
return S_FALSE;
}
ds_eeprom.region = region;
memset(&ds_eeprom, 0, sizeof(ds_eeprom));
wcstombs_s(
NULL,
ds_eeprom.serial_no,
_countof(ds_eeprom.serial_no),
cfg->serial_no,
_countof(cfg->serial_no) - 1);
ds_eeprom.region = cfg->region;
ds_eeprom.crc32 = crc32(&ds_eeprom.unk_04, 0x1C, 0);
hr = iohook_push_handler(ds_handle_irp);

View File

@ -2,6 +2,8 @@
#include <windows.h>
#include "amex/cfg.h"
DEFINE_GUID(
ds_guid,
0x279A9F67,
@ -9,4 +11,4 @@ DEFINE_GUID(
0x41C9,
0xA4, 0xC4, 0xDF, 0xDB, 0x8A, 0xE8, 0xE5, 0xE0);
HRESULT ds_hook_init(void);
HRESULT ds_hook_init(const struct ds_config *cfg);

View File

@ -10,6 +10,7 @@
#include <assert.h>
#include "amex/cfg.h"
#include "amex/eeprom.h"
#include "amex/nvram.h"
@ -29,11 +30,17 @@ static HRESULT eeprom_ioctl_get_geometry(struct irp *irp);
static HANDLE eeprom_file;
HRESULT eeprom_hook_init(void)
HRESULT eeprom_hook_init(const struct eeprom_config *cfg)
{
HRESULT hr;
hr = nvram_open_file(&eeprom_file, L"DEVICE\\eeprom.bin", 0x2000);
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
hr = nvram_open_file(&eeprom_file, cfg->path, 0x2000);
if (FAILED(hr)) {
return hr;

View File

@ -2,6 +2,8 @@
#include <windows.h>
#include "amex/cfg.h"
DEFINE_GUID(
eeprom_guid,
0xB7970F0C,
@ -9,4 +11,4 @@ DEFINE_GUID(
0x45FF,
0x96, 0x18, 0x0A, 0x24, 0x00, 0x94, 0xB2, 0x71);
HRESULT eeprom_hook_init(void);
HRESULT eeprom_hook_init(const struct eeprom_config *cfg);

View File

@ -54,10 +54,6 @@ static HRESULT gpio_ioctl_get_dipsw(struct irp *irp);
static HRESULT gpio_ioctl_describe(struct irp *irp);
static HRESULT gpio_ioctl_set_leds(struct irp *irp);
static HANDLE gpio_fd;
static uint8_t gpio_dipsw;
static const char gpio_dipsw_file[] = "DEVICE/dipsw.txt";
static const struct gpio_ports gpio_ports = {
.ports = {
{
@ -75,27 +71,35 @@ static const struct gpio_ports gpio_ports = {
static_assert(sizeof(gpio_ports) == 129, "GPIO port map size");
void gpio_hook_init(void)
static HANDLE gpio_fd;
static struct gpio_config gpio_config;
HRESULT gpio_hook_init(const struct gpio_config *cfg)
{
FILE *f;
int ival;
HRESULT hr;
f = fopen(gpio_dipsw_file, "r");
assert(cfg != NULL);
if (f != NULL) {
ival = 0;
fscanf(f, "%02x", &ival);
gpio_dipsw = ival;
fclose(f);
dprintf("Set DIPSW to %02x\n", gpio_dipsw);
} else {
dprintf("Failed to open %s\n", gpio_dipsw_file);
if (!cfg->enable) {
return S_FALSE;
}
memcpy(&gpio_config, cfg, sizeof(*cfg));
gpio_fd = iohook_open_dummy_fd();
iohook_push_handler(gpio_handle_irp);
setupapi_add_phantom_dev(&gpio_guid, L"$gpio");
hr = iohook_push_handler(gpio_handle_irp);
if (FAILED(hr)) {
return hr;
}
hr = setupapi_add_phantom_dev(&gpio_guid, L"$gpio");
if (FAILED(hr)) {
return hr;
}
return S_OK;
}
static HRESULT gpio_handle_irp(struct irp *irp)
@ -161,8 +165,16 @@ static HRESULT gpio_handle_ioctl(struct irp *irp)
static HRESULT gpio_ioctl_get_dipsw(struct irp *irp)
{
uint32_t dipsw;
size_t i;
dipsw = 0;
for (i = 0 ; i < 8 ; i++) {
if (gpio_config.dipsw[i]) {
dipsw |= 1 << i;
}
}
dipsw = gpio_dipsw;
//dprintf("GPIO: Get dipsw %08x\n", dipsw);
return iobuf_write_le32(&irp->read, dipsw);
@ -177,6 +189,14 @@ static HRESULT gpio_ioctl_get_psw(struct irp *irp)
/* Bit 0 == SW1 == Alt. Test */
/* Bit 1 == SW2 == Alt. Service */
if (gpio_config.vk_sw1 && (GetAsyncKeyState(gpio_config.vk_sw1) & 0x8000)) {
result |= 1 << 0;
}
if (gpio_config.vk_sw2 && (GetAsyncKeyState(gpio_config.vk_sw2) & 0x8000)) {
result |= 1 << 1;
}
return iobuf_write_le32(&irp->read, result);
}

View File

@ -2,6 +2,8 @@
#include <windows.h>
#include "amex/cfg.h"
DEFINE_GUID(
gpio_guid,
0xE9A26688,
@ -9,4 +11,4 @@ DEFINE_GUID(
0x44FA,
0xBF, 0xEE, 0x59, 0xDD, 0x16, 0x15, 0x56, 0x6C);
void gpio_hook_init(void);
HRESULT gpio_hook_init(const struct gpio_config *cfg);

View File

@ -37,11 +37,30 @@ static HRESULT jvs_ioctl_transact(struct irp *irp);
static HANDLE jvs_fd;
static struct jvs_node *jvs_root;
void jvs_hook_init(void)
HRESULT jvs_hook_init(const struct jvs_config *cfg)
{
HRESULT hr;
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
jvs_fd = iohook_open_dummy_fd();
iohook_push_handler(jvs_handle_irp);
setupapi_add_phantom_dev(&jvs_guid, L"$jvs");
hr = iohook_push_handler(jvs_handle_irp);
if (FAILED(hr)) {
return hr;
}
hr = setupapi_add_phantom_dev(&jvs_guid, L"$jvs");
if (FAILED(hr)) {
return hr;
}
return S_OK;
}
void jvs_attach(struct jvs_node *root)

View File

@ -2,6 +2,8 @@
#include <windows.h>
#include "amex/cfg.h"
#include "jvs/jvs-bus.h"
DEFINE_GUID(
@ -11,5 +13,5 @@ DEFINE_GUID(
0x4288,
0xAA, 0x00, 0x6C, 0x00, 0xD7, 0x67, 0xBD, 0xBF);
void jvs_hook_init(void);
HRESULT jvs_hook_init(const struct jvs_config *cfg);
void jvs_attach(struct jvs_node *root);

View File

@ -8,7 +8,7 @@
#include "util/dprintf.h"
HRESULT nvram_open_file(HANDLE *out, wchar_t *path, size_t size)
HRESULT nvram_open_file(HANDLE *out, const wchar_t *path, size_t size)
{
LARGE_INTEGER cur_size;
LARGE_INTEGER pos;

View File

@ -4,4 +4,4 @@
#include <stddef.h>
HRESULT nvram_open_file(HANDLE *out, wchar_t *path, size_t size);
HRESULT nvram_open_file(HANDLE *out, const wchar_t *path, size_t size);

View File

@ -27,11 +27,17 @@ static HRESULT sram_ioctl_get_geometry(struct irp *irp);
static HANDLE sram_file;
HRESULT sram_hook_init(void)
HRESULT sram_hook_init(const struct sram_config *cfg)
{
HRESULT hr;
hr = nvram_open_file(&sram_file, L"DEVICE\\sram.bin", 0x80000);
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
hr = nvram_open_file(&sram_file, cfg->path, 0x80000);
if (FAILED(hr)) {
return hr;

View File

@ -2,6 +2,8 @@
#include <windows.h>
#include "amex/cfg.h"
DEFINE_GUID(
sram_guid,
0x741B5FCA,
@ -9,4 +11,4 @@ DEFINE_GUID(
0x4443,
0xA7, 0xA0, 0x57, 0xCA, 0x7B, 0x50, 0x6A, 0x49);
HRESULT sram_hook_init(void);
HRESULT sram_hook_init(const struct sram_config *cfg);

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include "amex/amex.h"
#include "amex/cfg.h"
#include "chunihook/jvs.h"
#include "chunihook/slider.h"
@ -26,6 +27,7 @@ static process_entry_t chuni_startup;
static DWORD CALLBACK chuni_pre_startup(void)
{
struct amex_config amex_cfg;
HMODULE d3dc;
dprintf("--- Begin chuni_pre_startup ---\n");
@ -53,12 +55,16 @@ static DWORD CALLBACK chuni_pre_startup(void)
/* Initialize AMEX emulation */
amex_hook_init();
amex_config_load(&amex_cfg, L".\\segatools.ini");
amex_hook_init(&amex_cfg);
/* Initialize Chunithm board emulation */
if (amex_cfg.jvs.enable) {
chunithm_jvs_init();
}
slider_hook_init();
chunithm_jvs_init();
/* Initialize debug helpers */

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include "amex/amex.h"
#include "amex/cfg.h"
#include "board/sg-reader.h"
@ -26,6 +27,8 @@ static process_entry_t diva_startup;
static DWORD CALLBACK diva_pre_startup(void)
{
struct amex_config amex_cfg;
dprintf("--- Begin diva_pre_startup ---\n");
/* Hook Win32 APIs */
@ -40,11 +43,15 @@ static DWORD CALLBACK diva_pre_startup(void)
/* Initialize AMEX emulation */
amex_hook_init();
amex_config_load(&amex_cfg, L".\\segatools.ini");
amex_hook_init(&amex_cfg);
/* Initialize Project Diva I/O board emulation */
diva_jvs_init();
if (amex_cfg.jvs.enable) {
diva_jvs_init();
}
sg_reader_hook_init(10);
slider_hook_init();

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include "amex/amex.h"
#include "amex/cfg.h"
#include "board/sg-reader.h"
@ -25,6 +26,8 @@ static process_entry_t idz_startup;
static DWORD CALLBACK idz_pre_startup(void)
{
struct amex_config amex_cfg;
dprintf("--- Begin idz_pre_startup ---\n");
/* Hook Win32 APIs */
@ -39,13 +42,17 @@ static DWORD CALLBACK idz_pre_startup(void)
/* Initialize AMEX emulation */
amex_hook_init();
amex_config_load(&amex_cfg, L".\\segatools.ini");
amex_hook_init(&amex_cfg);
/* Initialize Initial D Zero I/O board emulation */
idz_jvs_init();
sg_reader_hook_init(10);
if (amex_cfg.jvs.enable) {
idz_jvs_init();
}
/* Initialize debug helpers */
spike_hook_init("idzspike.txt");

View File

@ -1,5 +1,6 @@
#include <windows.h>
#include "amex/cfg.h"
#include "amex/ds.h"
#include "hook/process.h"
@ -14,13 +15,17 @@ static process_entry_t app_startup;
static DWORD CALLBACK app_pre_startup(void)
{
struct ds_config ds_cfg;
dprintf("--- Begin %s ---\n", __func__);
spike_hook_init("minispike.txt");
ds_config_load(&ds_cfg, L".\\segatools.ini");
clock_hook_init();
ds_hook_init();
ds_hook_init(&ds_cfg);
nusec_hook_init();
spike_hook_init("minispike.txt");
dprintf("--- End %s ---\n", __func__);
return app_startup();