X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=config_file%2Fconfig_file.c;h=1d41335bf350c6288e93a00c7aa8bc25533b4aa4;hb=34f7de3b9cda4a764f7f1378f728f60dd81ea276;hp=c7fcccc0668ce63a3a0d008a60d0a26691d00a49;hpb=37bb73e0c6425365607b7ea60b3384417d370b92;p=pistorm diff --git a/config_file/config_file.c b/config_file/config_file.c index c7fcccc..1d41335 100644 --- a/config_file/config_file.c +++ b/config_file/config_file.c @@ -1,4 +1,4 @@ -#include "config_file.h" +#include "../platforms/platforms.h" #include #include #include @@ -32,6 +32,8 @@ const char *config_item_names[CONFITEM_NUM] = { "loopcycles", "mouse", "keyboard", + "platform", + "setvar", }; const char *mapcmd_names[MAPCMD_NUM] = { @@ -212,12 +214,13 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad } fseek(in, 0, SEEK_SET); cfg->map_data[index] = (unsigned char *)calloc(1, cfg->map_size[index]); + cfg->rom_size[index] = (cfg->map_size[index] <= file_size) ? cfg->map_size[index] : file_size; if (!cfg->map_data[index]) { printf("ERROR: Unable to allocate memory for mapped ROM!\n"); goto mapping_failed; } memset(cfg->map_data[index], 0x00, cfg->map_size[index]); - fread(cfg->map_data[index], (cfg->map_size[index] <= file_size) ? cfg->map_size[index] : file_size, 1, in); + fread(cfg->map_data[index], cfg->rom_size[index], 1, in); fclose(in); break; case MAPTYPE_REGISTER: @@ -226,7 +229,7 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad break; } - printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX (%.8lX)\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, (uint64_t)cfg->map_data[index]); + printf("[MAP %d] Added %s mapping for range %.8lX-%.8lX ID: %s\n", index, map_type_names[type], cfg->map_offset[index], cfg->map_offset[index] + cfg->map_size[index] - 1, cfg->map_id[index] ? cfg->map_id[index] : "None"); return; @@ -351,6 +354,34 @@ struct emulator_config *load_config_file(char *filename) { cfg->keyboard_toggle_key = cur_cmd[0]; printf("Enabled keyboard event forwarding, toggle key %c.\n", cfg->keyboard_toggle_key); break; + case CONFITEM_PLATFORM: { + char platform_name[128], platform_sub[128]; + memset(platform_name, 0x00, 128); + memset(platform_sub, 0x00, 128); + get_next_string(parse_line, platform_name, &str_pos, ' '); + printf("Setting platform to %s", platform_name); + get_next_string(parse_line, platform_sub, &str_pos, ' '); + if (strlen(platform_sub)) + printf(" (sub: %s)", platform_sub); + printf("\n"); + cfg->platform = make_platform_config(platform_name, platform_sub); + break; + } + case CONFITEM_SETVAR: { + if (!cfg->platform) { + printf("Warning: esetvar used in config file with no platform specified.\n"); + break; + } + + char var_name[128], var_value[128]; + memset(var_name, 0x00, 128); + memset(var_value, 0x00, 128); + get_next_string(parse_line, var_name, &str_pos, ' '); + get_next_string(parse_line, var_value, &str_pos, ' '); + cfg->platform->setvar(var_name, var_value); + + break; + } case CONFITEM_NONE: default: printf("Unknown config item %s on line %d.\n", cur_cmd, cur_line); @@ -378,3 +409,17 @@ struct emulator_config *load_config_file(char *filename) { return cfg; } + +int get_named_mapped_item(struct emulator_config *cfg, char *name) { + if (strlen(name) == 0) + return -1; + + for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) { + if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_id[i]) + continue; + if (strcmp(name, cfg->map_id[i]) == 0) + return i; + } + + return -1; +}