1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-24 05:20:10 +01:00

amex/cfg.c: Add libamex INI configuration system

This commit is contained in:
Tau 2019-05-04 13:11:59 -04:00
parent 364267ba66
commit 68ec23e3c8
3 changed files with 143 additions and 0 deletions

92
amex/cfg.c Normal file
View File

@ -0,0 +1,92 @@
#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "amex/cfg.h"
void ds_config_load(struct ds_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
cfg->enable = GetPrivateProfileIntW(L"ds", L"enable", 1, filename);
cfg->region = GetPrivateProfileIntW(L"ds", L"region", 1, filename);
GetPrivateProfileStringW(
L"ds",
L"serialNo",
L"AAVE-01A99999999",
cfg->serial_no,
_countof(cfg->serial_no),
filename);
}
void eeprom_config_load(struct eeprom_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
cfg->enable = GetPrivateProfileIntW(L"eeprom", L"enable", 1, filename);
GetPrivateProfileStringW(
L"eeprom",
L"path",
L"DEVICE\\eeprom.bin",
cfg->path,
_countof(cfg->path),
filename);
}
void gpio_config_load(struct gpio_config *cfg, const wchar_t *filename)
{
wchar_t name[7];
size_t i;
assert(cfg != NULL);
cfg->enable = GetPrivateProfileIntW(L"gpio", L"enable", 1, filename);
cfg->vk_sw1 = GetPrivateProfileIntW(L"gpio", L"sw1", VK_F1, filename);
cfg->vk_sw2 = GetPrivateProfileIntW(L"gpio", L"sw2", VK_F2, 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);
}
}
void jvs_config_load(struct jvs_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
cfg->enable = GetPrivateProfileIntW(L"jvs", L"enable", 1, filename);
}
void sram_config_load(struct sram_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
cfg->enable = GetPrivateProfileIntW(L"sram", L"enable", 1, filename);
GetPrivateProfileStringW(
L"sram",
L"path",
L"DEVICE\\sram.bin",
cfg->path,
_countof(cfg->path),
filename);
}
void amex_config_load(struct amex_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
ds_config_load(&cfg->ds, filename);
eeprom_config_load(&cfg->eeprom, filename);
gpio_config_load(&cfg->gpio, filename);
jvs_config_load(&cfg->jvs, filename);
sram_config_load(&cfg->sram, filename);
}

49
amex/cfg.h Normal file
View File

@ -0,0 +1,49 @@
#pragma once
#include <windows.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
struct ds_config {
bool enable;
uint8_t region;
wchar_t serial_no[17];
};
struct eeprom_config {
bool enable;
wchar_t path[MAX_PATH];
};
struct gpio_config {
bool enable;
uint8_t vk_sw1;
uint8_t vk_sw2;
bool dipsw[8];
};
struct jvs_config {
bool enable;
};
struct sram_config {
bool enable;
wchar_t path[MAX_PATH];
};
struct amex_config {
struct ds_config ds;
struct eeprom_config eeprom;
struct gpio_config gpio;
struct jvs_config jvs;
struct sram_config sram;
};
void ds_config_load(struct ds_config *cfg, const wchar_t *filename);
void eeprom_config_load(struct eeprom_config *cfg, const wchar_t *filename);
void gpio_config_load(struct gpio_config *cfg, const wchar_t *filename);
void jvs_config_load(struct jvs_config *cfg, const wchar_t *filename);
void sram_config_load(struct sram_config *cfg, const wchar_t *filename);
void amex_config_load(struct amex_config *cfg, const wchar_t *filename);

View File

@ -9,6 +9,8 @@ amex_lib = static_library(
sources : [ sources : [
'amex.c', 'amex.c',
'amex.h', 'amex.h',
'cfg.c',
'cfg.h',
'ds.c', 'ds.c',
'ds.h', 'ds.h',
'eeprom.c', 'eeprom.c',