From 68ec23e3c82e92643e4889eb0b53614aa6c46fba Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 4 May 2019 13:11:59 -0400 Subject: [PATCH] amex/cfg.c: Add libamex INI configuration system --- amex/cfg.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ amex/cfg.h | 49 ++++++++++++++++++++++++++ amex/meson.build | 2 ++ 3 files changed, 143 insertions(+) create mode 100644 amex/cfg.c create mode 100644 amex/cfg.h diff --git a/amex/cfg.c b/amex/cfg.c new file mode 100644 index 0000000..bc8bb2d --- /dev/null +++ b/amex/cfg.c @@ -0,0 +1,92 @@ +#include + +#include +#include +#include +#include +#include + +#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); +} diff --git a/amex/cfg.h b/amex/cfg.h new file mode 100644 index 0000000..9c07f6d --- /dev/null +++ b/amex/cfg.h @@ -0,0 +1,49 @@ +#pragma once + +#include + +#include +#include +#include + +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); diff --git a/amex/meson.build b/amex/meson.build index d50418d..e5dc860 100644 --- a/amex/meson.build +++ b/amex/meson.build @@ -9,6 +9,8 @@ amex_lib = static_library( sources : [ 'amex.c', 'amex.h', + 'cfg.c', + 'cfg.h', 'ds.c', 'ds.h', 'eeprom.c',