Skip to content

Commit

Permalink
Merge branch 'sf/tubecfg'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Fosdick committed Dec 1, 2023
2 parents 42b2767 + 02e3676 commit 75b130f
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 102 deletions.
55 changes: 40 additions & 15 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,45 @@ ALLEGRO_CONFIG *bem_cfg;
int get_config_int(const char *sect, const char *key, int ival)
{
const char *str = al_get_config_value(bem_cfg, sect, key);
if (str)
ival = atoi(str);
else if (sect && (str = al_get_config_value(bem_cfg, NULL, key))) {
ival = atoi(str);
al_remove_config_key(bem_cfg, "", key);
if (!str && sect) {
if ((str = al_get_config_value(bem_cfg, NULL, key)))
al_remove_config_key(bem_cfg, "", key);
}
if (str) {
char *end;
long nval = strtol(str, &end, 0);
if (end > str && !end[0])
ival = nval;
else if (sect)
log_warn("config: section '%s', key '%s': invalid integer %s", sect, key, str);
else
log_warn("config: global section, key '%s': invalid integer %s", key, str);
}
return ival;
}

static bool parse_bool(const char *value)
{
return strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0 || atoi(value) > 0;
}

bool get_config_bool(const char *sect, const char *key, bool bval)
{
const char *str = al_get_config_value(bem_cfg, sect, key);
if (str)
bval = parse_bool(str);
else if (sect && (str = al_get_config_value(bem_cfg, NULL, key))) {
bval = parse_bool(str);
al_remove_config_key(bem_cfg, "", key);
if (!str && sect) {
if ((str = al_get_config_value(bem_cfg, NULL, key)))
al_remove_config_key(bem_cfg, "", key);
}
if (str) {
if (strcasecmp(str, "true") == 0 || strcasecmp(str, "yes") == 0)
bval = true;
else if (strcasecmp(str, "false") == 0 || strcasecmp(str, "no") == 0)
bval = false;
else {
char *end;
long nval = strtol(str, &end, 0);
if (end > str && !end[0])
bval = (nval > 0);
else if (sect)
log_warn("config: section '%s', key '%s': invalid boolean %s", sect, key, str);
else
log_warn("config: global section, key '%s': invalid boolean %s", key, str);
}
}
return bval;
}
Expand Down Expand Up @@ -243,6 +260,14 @@ void set_config_int(const char *sect, const char *key, int value)
al_set_config_value(bem_cfg, sect, key, buf);
}

void set_config_hex(const char *sect, const char *key, unsigned value)
{
char buf[11];

snprintf(buf, sizeof buf, "0x%x", value);
al_set_config_value(bem_cfg, sect, key, buf);
}

void set_config_bool(const char *sect, const char *key, bool value)
{
al_set_config_value(bem_cfg, sect, key, value ? "true" : "false");
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bool get_config_bool(const char *sect, const char *key, bool bdefault);
const char *get_config_string(const char *sect, const char *key, const char *sdefault);
ALLEGRO_COLOR get_config_colour(const char *sect, const char *key, ALLEGRO_COLOR cdefault);
void set_config_int(const char *sect, const char *key, int value);
void set_config_hex(const char *sect, const char *key, unsigned value);
void set_config_bool(const char *sect, const char *key, bool value);
void set_config_string(const char *sect, const char *key, const char *value);

Expand Down
4 changes: 2 additions & 2 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void enable_tube_debug(void)
debug_step = 1;
debug_tube = 1;
log_info("debugger: debugging of tube CPU enabled");
tubes[curtube].debug->debug_enable(1);
tubes[curtube].cpu->debug->debug_enable(1);
}
}

Expand All @@ -313,7 +313,7 @@ static void disable_tube_debug(void)
{
if (curtube != -1)
{
tubes[curtube].debug->debug_enable(0);
tubes[curtube].cpu->debug->debug_enable(0);
log_info("debugger: debugging of tube CPU disabled");
debug_tube = 0;
debug_cons_close();
Expand Down
14 changes: 8 additions & 6 deletions src/gui-allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,17 @@ static ALLEGRO_MENU *create_tube_menu(void)
{
ALLEGRO_MENU *menu = al_create_menu();
ALLEGRO_MENU *sub = al_create_menu();
menu_map_t map[NUM_TUBES];
int i;

for (i = 0; i < NUM_TUBES; i++) {
menu_map_t *map = malloc(num_tubes * sizeof(menu_map_t));
if (!map) {
log_error("gui: unable to allocate tube menu");
return NULL;
}
for (int i = 0; i < num_tubes; ++i) {
map[i].label = tubes[i].name;
map[i].itemno = i;
}
add_sorted_set(menu, map, NUM_TUBES, IDM_TUBE, curtube);
for (i = 0; i < NUM_TUBE_SPEEDS; i++)
add_sorted_set(menu, map, num_tubes, IDM_TUBE, curtube);
for (int i = 0; i < NUM_TUBE_SPEEDS; i++)
add_radio_item(sub, tube_speeds[i].name, IDM_TUBE_SPEED, i, tube_speed_num);
al_append_menu_item(menu, "Tube speed", 0, 0, NULL, sub);
return menu;
Expand Down
2 changes: 1 addition & 1 deletion src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static void log_open_file(void) {
log_warn("log_open: unable to find suitable destination for log file");
}
if (log_fn) {
append = get_config_int(log_section, "append", 1);
append = get_config_bool(log_section, "append", 1);
if ((log_fp = fopen(log_fn, append ? "at" : "wt")) == NULL)
log_warn("log_open: unable to open log %s: %s", log_fn, strerror(errno));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void main_reset()
music5000_reset();
paula_reset();
sn_init();
if (curtube != -1) tubes[curtube].reset();
if (curtube != -1) tubes[curtube].cpu->reset();
else tube_exec = NULL;
tube_reset();
}
Expand Down Expand Up @@ -412,7 +412,7 @@ void main_key_break(void)
paula_reset();

if (curtube != -1)
tubes[curtube].reset();
tubes[curtube].cpu->reset();
tube_reset();
}

Expand Down
16 changes: 10 additions & 6 deletions src/mc68000tube.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

#include "b-em.h"
#include "cpu_debug.h"
#include "tube.h"
#include "config.h"
#include "model.h"
#include "mc68000tube.h"
#include "musahi/m68k.h"

static uint_least32_t mc68000_ram_size;
static uint8_t *mc68000_ram, *mc68000_rom;
static bool mc68000_debug_enabled = false;
static bool rom_low;
Expand Down Expand Up @@ -35,7 +37,7 @@ static uint8_t readmem(uint32_t addr)
}
else
{
uint8_t data = mc68000_ram[addr % MC68000_RAM_SIZE];
uint8_t data = mc68000_ram[addr % mc68000_ram_size];
log_debug("mc68000: read %08X as RAM -> %02X", addr, data);
return data;
}
Expand Down Expand Up @@ -96,7 +98,7 @@ static void writemem(uint32_t addr, uint8_t data)
else
{
log_debug("mc68000: write %08X as RAM <- %02X", addr, data);
mc68000_ram[addr % MC68000_RAM_SIZE] = data;
mc68000_ram[addr % mc68000_ram_size] = data;
}
}

Expand Down Expand Up @@ -145,7 +147,7 @@ static void mc68000_savestate(ZFILE *zfp)
m68k_get_context(buf);
savestate_zwrite(zfp, buf, bytes);
free(buf);
savestate_zwrite(zfp, mc68000_ram, MC68000_RAM_SIZE);
savestate_zwrite(zfp, mc68000_ram, mc68000_ram_size);
savestate_zwrite(zfp, mc68000_rom, MC68000_ROM_SIZE);
}
else
Expand All @@ -160,7 +162,7 @@ static void mc68000_loadstate(ZFILE *zfp)
savestate_zread(zfp, buf, bytes);
m68k_set_context(buf);
free(buf);
savestate_zread(zfp, mc68000_ram, MC68000_RAM_SIZE);
savestate_zread(zfp, mc68000_ram, mc68000_ram_size);
savestate_zread(zfp, mc68000_rom, MC68000_ROM_SIZE);
}
else
Expand All @@ -171,7 +173,9 @@ bool tube_68000_init(void *rom)
{
log_debug("mc68000: init");
if (!mc68000_ram) {
mc68000_ram = malloc(MC68000_RAM_SIZE);
const char *sect = tubes[curtube].cfgsect;
mc68000_ram_size = get_config_int(sect, "ramsize", MC68000_RAM_SIZE);
mc68000_ram = malloc(mc68000_ram_size);
if (!mc68000_ram) {
log_error("mc68000: unable to allocate RAM: %s", strerror(errno));
return false;
Expand Down
Loading

0 comments on commit 75b130f

Please sign in to comment.