forked from TeamTofuShop/segatools
idac: added dipswitch support (beta)
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include "platform/pcbid.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform/vfs.h"
|
||||
#include "platform/dipsw.h"
|
||||
|
||||
void platform_config_load(struct platform_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
@ -37,6 +38,7 @@ void platform_config_load(struct platform_config *cfg, const wchar_t *filename)
|
||||
netenv_config_load(&cfg->netenv, filename);
|
||||
nusec_config_load(&cfg->nusec, filename);
|
||||
vfs_config_load(&cfg->vfs, filename);
|
||||
dipsw_config_load(&cfg->dipsw, filename);
|
||||
}
|
||||
|
||||
void amvideo_config_load(struct amvideo_config *cfg, const wchar_t *filename)
|
||||
@ -317,3 +319,21 @@ void vfs_config_load(struct vfs_config *cfg, const wchar_t *filename)
|
||||
filename);
|
||||
}
|
||||
|
||||
void dipsw_config_load(struct dipsw_config *cfg, const wchar_t *filename)
|
||||
{
|
||||
wchar_t name[7];
|
||||
size_t i;
|
||||
|
||||
assert(cfg != NULL);
|
||||
assert(filename != NULL);
|
||||
|
||||
cfg->enable = GetPrivateProfileIntW(L"gpio", L"enable", 1, filename);
|
||||
|
||||
wcscpy_s(name, _countof(name), L"dipsw0");
|
||||
|
||||
for (i = 0 ; i < 8 ; i++) {
|
||||
name[5] = L'1' + i;
|
||||
cfg->dipsw[i] = GetPrivateProfileIntW(L"gpio", name, 0, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "platform/pcbid.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform/vfs.h"
|
||||
#include "platform/dipsw.h"
|
||||
|
||||
void platform_config_load(
|
||||
struct platform_config *cfg,
|
||||
@ -32,3 +33,4 @@ void netenv_config_load(struct netenv_config *cfg, const wchar_t *filename);
|
||||
void nusec_config_load(struct nusec_config *cfg, const wchar_t *filename);
|
||||
void pcbid_config_load(struct pcbid_config *cfg, const wchar_t *filename);
|
||||
void vfs_config_load(struct vfs_config *cfg, const wchar_t *filename);
|
||||
void dipsw_config_load(struct dipsw_config *cfg, const wchar_t *filename);
|
||||
|
153
platform/dipsw.c
Normal file
153
platform/dipsw.c
Normal file
@ -0,0 +1,153 @@
|
||||
#include <windows.h>
|
||||
#include <ntstatus.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
// #include <zlib.h>
|
||||
|
||||
#include "platform/dipsw.h"
|
||||
#include "platform/vfs.h"
|
||||
|
||||
#include "util/dprintf.h"
|
||||
#include "util/str.h"
|
||||
#include "util/crc.h"
|
||||
|
||||
#define DATA_SIZE 503
|
||||
#define BLOCK_SIZE (sizeof(uint32_t) + 4 + 1 + DATA_SIZE)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t checksum;
|
||||
char padding_1[4];
|
||||
uint8_t dip_switches;
|
||||
char data[DATA_SIZE];
|
||||
} DipSwitchBlock;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DipSwitchBlock dip_switch_block;
|
||||
char *data;
|
||||
} DipSwitches;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static DipSwitches dip_switches;
|
||||
|
||||
static struct dipsw_config dipsw_config;
|
||||
static struct vfs_config vfs_config;
|
||||
|
||||
static void dipsw_read_sysfile(const wchar_t *sys_file);
|
||||
static void dipsw_save_sysfile(const wchar_t *sys_file);
|
||||
|
||||
HRESULT dipsw_init(const struct dipsw_config *cfg, const struct vfs_config *vfs_cfg)
|
||||
{
|
||||
HRESULT hr;
|
||||
wchar_t sys_file_path[MAX_PATH];
|
||||
|
||||
assert(cfg != NULL);
|
||||
assert(vfs_cfg != NULL);
|
||||
|
||||
if (!cfg->enable)
|
||||
{
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
memcpy(&dipsw_config, cfg, sizeof(*cfg));
|
||||
|
||||
sys_file_path[0] = L'\0';
|
||||
// concatenate vfs_config.amfs with L"sysfile.dat"
|
||||
wcsncpy(sys_file_path, vfs_cfg->amfs, MAX_PATH);
|
||||
wcsncat(sys_file_path, L"\\sysfile.dat", MAX_PATH);
|
||||
|
||||
dipsw_read_sysfile(sys_file_path);
|
||||
|
||||
// now write the dipsw_config.dipsw to the dip_switch_block
|
||||
dipsw_save_sysfile(sys_file_path);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void dipsw_read_sysfile(const wchar_t *sys_file)
|
||||
{
|
||||
FILE *f = _wfopen(sys_file, L"r");
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
dprintf("First run detected, DipSw settings can only be applied AFTER the first run\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
long file_size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
if (file_size != 0x6000)
|
||||
{
|
||||
dprintf("Invalid sysfile.dat file size\n");
|
||||
fclose(f);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dip_switches.data = malloc(file_size);
|
||||
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);
|
||||
}
|
||||
|
||||
static void dipsw_save_sysfile(const wchar_t *sys_file)
|
||||
{
|
||||
uint8_t dipsw = 0;
|
||||
// open the sysfile.dat for writing in bytes mode
|
||||
FILE *f = _wfopen(sys_file, L"rb+");
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// write the dipsw_config.dipsw to the dip_switch_block
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (dipsw_config.dipsw[i])
|
||||
{
|
||||
// print which dipsw is enabled
|
||||
dprintf("DipSw: DipSw%d=1 set\n", i + 1);
|
||||
dipsw |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
dip_switches.dip_switch_block.dip_switches = dipsw;
|
||||
|
||||
// calculate the new checksum, skip the old crc32 value
|
||||
// which is at the beginning of the block, thats's why the +4
|
||||
// conver the struct to chars in order for the crc32 calculation to work
|
||||
dip_switches.dip_switch_block.checksum = crc32(
|
||||
(char *)&dip_switches.dip_switch_block + 4, BLOCK_SIZE - 4, 0);
|
||||
|
||||
// build the new dip switch block
|
||||
char block[BLOCK_SIZE];
|
||||
memcpy(block, (char *)&dip_switches.dip_switch_block, BLOCK_SIZE);
|
||||
|
||||
// replace the old block with the new one
|
||||
memcpy(dip_switches.data + 0x2800, block, BLOCK_SIZE);
|
||||
memcpy(dip_switches.data + 0x5800, block, BLOCK_SIZE);
|
||||
|
||||
// print the dip_switch_block in hex
|
||||
/*
|
||||
dprintf("DipSw Block: ");
|
||||
for (size_t i = 0; i < BLOCK_SIZE; i++)
|
||||
{
|
||||
dprintf("%02X ", ((uint8_t *)&dip_switches.dip_switch_block)[i]);
|
||||
}
|
||||
dprintf("\n");
|
||||
*/
|
||||
|
||||
fwrite(dip_switches.data, 1, 0x6000, f);
|
||||
|
||||
fclose(f);
|
||||
}
|
15
platform/dipsw.h
Normal file
15
platform/dipsw.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "platform/vfs.h"
|
||||
|
||||
struct dipsw_config {
|
||||
bool enable;
|
||||
bool dipsw[8];
|
||||
};
|
||||
|
||||
HRESULT dipsw_init(const struct dipsw_config *cfg, const struct vfs_config *vfs_cfg);
|
@ -79,5 +79,13 @@ HRESULT dns_platform_hook_init(const struct dns_config *cfg)
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Disable api/polling to the original servers
|
||||
|
||||
hr = dns_hook_push(L"amlog.sys-all.net", NULL);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -32,5 +32,7 @@ platform_lib = static_library(
|
||||
'platform.h',
|
||||
'vfs.c',
|
||||
'vfs.h',
|
||||
'dipsw.c',
|
||||
'dipsw.h',
|
||||
],
|
||||
)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "platform/pcbid.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform/vfs.h"
|
||||
#include "platform/dipsw.h"
|
||||
|
||||
HRESULT platform_hook_init(
|
||||
const struct platform_config *cfg,
|
||||
@ -80,5 +81,11 @@ HRESULT platform_hook_init(
|
||||
return hr;
|
||||
}
|
||||
|
||||
hr = dipsw_init(&cfg->dipsw, &cfg->vfs);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "platform/nusec.h"
|
||||
#include "platform/pcbid.h"
|
||||
#include "platform/vfs.h"
|
||||
#include "platform/dipsw.h"
|
||||
|
||||
struct platform_config {
|
||||
struct amvideo_config amvideo;
|
||||
@ -24,6 +25,7 @@ struct platform_config {
|
||||
struct netenv_config netenv;
|
||||
struct nusec_config nusec;
|
||||
struct vfs_config vfs;
|
||||
struct dipsw_config dipsw;
|
||||
};
|
||||
|
||||
HRESULT platform_hook_init(
|
||||
|
@ -28,7 +28,9 @@ static HRESULT vfs_reg_read_amfs(void *bytes, uint32_t *nbytes);
|
||||
static HRESULT vfs_reg_read_appdata(void *bytes, uint32_t *nbytes);
|
||||
|
||||
static wchar_t vfs_nthome_real[MAX_PATH];
|
||||
static const wchar_t vfs_nthome[] = L"C:\\Documents and Settings\\AppUser";
|
||||
// new home for ALLS
|
||||
static const wchar_t vfs_nthome[] = L"C:\\Users\\AppUser";
|
||||
// static const wchar_t vfs_nthome[] = L"C:\\Documents and Settings\\AppUser";
|
||||
static const size_t vfs_nthome_len = _countof(vfs_nthome) - 1;
|
||||
|
||||
static const wchar_t vfs_option[] = L"C:\\Mount\\Option";
|
||||
@ -273,8 +275,8 @@ static HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count)
|
||||
}
|
||||
|
||||
switch (src[0]) {
|
||||
case L'D': // later AMDaemon versions default to D: for AMFS if it can't find it
|
||||
case L'd':
|
||||
// case L'D': // later AMDaemon versions default to D: for AMFS if it can't find it
|
||||
// case L'd':
|
||||
case L'e':
|
||||
case L'E':
|
||||
redir = vfs_config.amfs;
|
||||
|
Reference in New Issue
Block a user