Skip to content

Commit 7e2d8b8

Browse files
committed
feat: get rom paths from configuration file
1 parent 4cacacc commit 7e2d8b8

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/bios.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "bios.h"
22

3+
#include "conf.h"
34
#include "units.h"
45

56
#include <stdio.h>
@@ -13,7 +14,18 @@
1314
static zuint8 bios[ROM_BIOS_SIZE] = {0};
1415

1516
void rom_bios_init(void) {
16-
FILE *fp = fopen(ROM_BIOS_PATH, "rb");
17+
const char *rom_path = ROM_BIOS_PATH;
18+
const char *rom_path_cfg = conf_getString("path", "bios_rom");
19+
20+
if (rom_path_cfg != NULL)
21+
rom_path = rom_path_cfg;
22+
23+
LOG_INFO("Loading BIOS rom from %s\n\r", rom_path);
24+
25+
FILE *fp = fopen(rom_path, "rb");
26+
27+
LOG_INFO("%s\n\r", rom_path);
28+
1729
if (fp == NULL) {
1830
LOG_ERR("missing bios rom file\n");
1931
abort();

src/conf.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ static const char *CONF_PATH_HOME =
2121
#include "log.h"
2222

2323
// Emulator dynamic configuration
24-
static struct { bool cge_installed; } conf;
24+
static struct {
25+
bool cge_installed;
26+
ceda_string_t *bios_rom_path;
27+
ceda_string_t *char_rom_path;
28+
ceda_string_t *cge_rom_path;
29+
} conf;
2530

2631
typedef enum conf_type_t {
2732
CONF_NONE,
@@ -41,6 +46,9 @@ typedef struct conf_tuple_t {
4146

4247
static conf_tuple_t conf_tuples[] = {
4348
{"mod", "cge_installed", CONF_BOOL, &conf.cge_installed},
49+
{"path", "bios_rom", CONF_STR, &conf.bios_rom_path},
50+
{"path", "char_rom", CONF_STR, &conf.char_rom_path},
51+
{"path", "cge_rom", CONF_STR, &conf.cge_rom_path},
4452
{NULL, NULL, CONF_NONE, NULL},
4553
};
4654

@@ -192,6 +200,15 @@ bool *conf_getBool(const char *section, const char *key) {
192200
return conf_getType(conf_tuples, section, key, CONF_BOOL);
193201
}
194202

203+
const char *conf_getString(const char *section, const char *key) {
204+
ceda_string_t **string = conf_getType(conf_tuples, section, key, CONF_STR);
205+
206+
if (string == NULL || *string == NULL)
207+
return NULL;
208+
209+
return ceda_string_data(*string);
210+
}
211+
195212
#if defined(CEDA_TEST)
196213

197214
#include "hexdump.h"

src/video.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,16 @@ void video_init(CEDAModule *mod) {
321321

322322
// load character generator rom
323323
{
324-
FILE *fp = fopen(CHAR_ROM_PATH, "rb");
324+
const char *rom_path = CHAR_ROM_PATH;
325+
const char *rom_path_cfg = conf_getString("path", "char_rom");
326+
327+
if (rom_path_cfg != NULL)
328+
rom_path = rom_path_cfg;
329+
330+
LOG_INFO("Loading char rom from %s\n\r", rom_path);
331+
332+
FILE *fp = fopen(rom_path, "rb");
333+
325334
if (fp == NULL) {
326335
LOG_ERR("missing char rom file\n");
327336
abort();
@@ -345,7 +354,16 @@ void video_init(CEDAModule *mod) {
345354
cge_installed = *conf_cge_installed;
346355

347356
if (cge_installed) {
348-
FILE *fp = fopen(CGE_ROM_PATH, "rb");
357+
const char *rom_path = CGE_ROM_PATH;
358+
const char *rom_path_cfg = conf_getString("path", "cge_rom");
359+
360+
if (rom_path_cfg != NULL)
361+
rom_path = rom_path_cfg;
362+
363+
LOG_INFO("Loading CGE rom from %s\n\r", rom_path);
364+
365+
FILE *fp = fopen(rom_path, "rb");
366+
349367
if (fp == NULL) {
350368
LOG_WARN("cge: extended char rom not found\n");
351369
return;

0 commit comments

Comments
 (0)