X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=config_file%2Fconfig_file.c;h=f848ba51cd00bfa762ef7abaa59078aa7520cff6;hb=ce1c064e71706992b3de778af96aa9321575b114;hp=0d736c546a0b0acc95c603c16dac38bbef217176;hpb=47c3c3a059c5c7c9e22110961d3b40edd5c92df4;p=pistorm diff --git a/config_file/config_file.c b/config_file/config_file.c index 0d736c5..f848ba5 100644 --- a/config_file/config_file.c +++ b/config_file/config_file.c @@ -27,7 +27,8 @@ const char *map_type_names[MAPTYPE_NUM] = { "rom", "ram", "register", - "ram (no alloc)", + "ram_noalloc", + "wtcram", }; const char *config_item_names[CONFITEM_NUM] = { @@ -51,6 +52,8 @@ const char *mapcmd_names[MAPCMD_NUM] = { "file", "ovl", "id", + "autodump_file", + "autodump_mem", }; int get_config_item_type(char *cmd) { @@ -191,7 +194,7 @@ void get_next_string(char *str, char *str_out, int *strpos, char separator) { } } -void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id) { +void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id, unsigned int autodump) { unsigned int index = 0, file_size = 0; FILE *in = NULL; @@ -211,6 +214,9 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad cfg->map_high[index] = addr + size; cfg->map_mirror[index] = mirr_addr; if (strlen(map_id)) { + if (cfg->map_id[index]) { + free(cfg->map_id[index]); + } cfg->map_id[index] = (char *)malloc(strlen(map_id) + 1); strcpy(cfg->map_id[index], map_id); } @@ -220,20 +226,48 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad printf("[CFG] Adding %d byte (%d MB) RAM mapping %s...\n", size, size / 1024 / 1024, map_id); cfg->map_data[index] = (unsigned char *)filename; break; + case MAPTYPE_RAM_WTC: + printf("[CFG] Allocating %d bytes for Write-Through Cached RAM mapping (%.1f MB)...\n", size, (float)size / 1024.0f / 1024.0f); + goto alloc_mapram; + break; case MAPTYPE_RAM: printf("[CFG] Allocating %d bytes for RAM mapping (%d MB)...\n", size, size / 1024 / 1024); +alloc_mapram: cfg->map_data[index] = (unsigned char *)malloc(size); if (!cfg->map_data[index]) { printf("[CFG] ERROR: Unable to allocate memory for mapped RAM!\n"); goto mapping_failed; } memset(cfg->map_data[index], 0x00, size); + if (type == MAPTYPE_RAM_WTC) { + // This may look a bit weird, but it adds a read range for the WTC RAM. Writes still go through to the mapped read/write functions. + m68k_add_rom_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]); + } break; case MAPTYPE_ROM: in = fopen(filename, "rb"); if (!in) { - printf("[CFG] Failed to open file %s for ROM mapping. Using onboard ROM instead, if available.\n", filename); - goto mapping_failed; + if (!autodump) { + printf("[CFG] Failed to open file %s for ROM mapping. Using onboard ROM instead, if available.\n", filename); + goto mapping_failed; + } else if (autodump == MAPCMD_AUTODUMP_FILE) { + printf("[CFG] Could not open file %s for ROM mapping. Autodump flag is set, dumping to file.\n", filename); + dump_range_to_file(cfg->map_offset[index], cfg->map_size[index], filename); + in = fopen(filename, "rb"); + if (in == NULL) { + printf("[CFG] Could not open dumped file for reading. Using onboard ROM instead, if available.\n"); + goto mapping_failed; + } + } else if (autodump == MAPCMD_AUTODUMP_MEM) { + printf("[CFG] Could not open file %s for ROM mapping. Autodump flag is set, dumping to memory.\n", filename); + cfg->map_data[index] = dump_range_to_memory(cfg->map_offset[index], cfg->map_size[index]); + cfg->rom_size[index] = cfg->map_size[index]; + if (cfg->map_data[index] == NULL) { + printf("[CFG] Could not dump range to memory. Using onboard ROM instead, if available.\n"); + goto mapping_failed; + } + goto skip_file_ops; + } } fseek(in, 0, SEEK_END); file_size = (int)ftell(in); @@ -250,8 +284,10 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad } memset(cfg->map_data[index], 0x00, cfg->map_size[index]); fread(cfg->map_data[index], cfg->rom_size[index], 1, in); - fclose(in); - displayRomInfo(cfg->map_data[index]); + if (in) + fclose(in); +skip_file_ops: + displayRomInfo(cfg->map_data[index], cfg->rom_size[index]); if (cfg->map_size[index] == cfg->rom_size[index]) m68k_add_rom_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]); break; @@ -283,7 +319,9 @@ void free_config_file(struct emulator_config *cfg) { for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) { if (cfg->map_data[i]) { - free(cfg->map_data[i]); + if (cfg->map_type[i] != MAPTYPE_RAM_NOALLOC) { + free(cfg->map_data[i]); + } cfg->map_data[i] = NULL; } if (cfg->map_id[i]) { @@ -291,6 +329,7 @@ void free_config_file(struct emulator_config *cfg) { cfg->map_id[i] = NULL; } } + if (cfg->mouse_file) { free(cfg->mouse_file); cfg->mouse_file = NULL; @@ -348,7 +387,7 @@ struct emulator_config *load_config_file(char *filename) { cfg->cpu_type = get_m68k_cpu_type(parse_line + str_pos); break; case CONFITEM_MAP: { - unsigned int maptype = 0, mapsize = 0, mapaddr = 0; + unsigned int maptype = 0, mapsize = 0, mapaddr = 0, autodump = 0; unsigned int mirraddr = ((unsigned int)-1); char mapfile[128], mapid[128]; memset(mapfile, 0x00, 128); @@ -393,12 +432,16 @@ struct emulator_config *load_config_file(char *filename) { get_next_string(parse_line, cur_cmd, &str_pos, ' '); mirraddr = get_int(cur_cmd); break; + case MAPCMD_AUTODUMP_FILE: + case MAPCMD_AUTODUMP_MEM: + autodump = get_map_cmd(cur_cmd); + break; default: printf("[CFG] Unknown/unhandled map argument %s on line %d.\n", cur_cmd, cur_line); break; } } - add_mapping(cfg, maptype, mapaddr, mapsize, mirraddr, mapfile, mapid); + add_mapping(cfg, maptype, mapaddr, mapsize, mirraddr, mapfile, mapid, autodump); break; } @@ -511,9 +554,24 @@ int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address) { for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) { if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_data[i]) continue; - if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) - return i; + else if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) { + if (cfg->map_type[i] == MAPTYPE_RAM || cfg->map_type[i] == MAPTYPE_RAM_NOALLOC || cfg->map_type[i] == MAPTYPE_ROM) + return i; + } } return -1; } + +uint8_t *get_mapped_data_pointer_by_address(struct emulator_config *cfg, uint32_t address) { + for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) { + if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_data[i]) + continue; + else if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) { + if (cfg->map_type[i] == MAPTYPE_RAM || cfg->map_type[i] == MAPTYPE_RAM_NOALLOC || cfg->map_type[i] == MAPTYPE_ROM) + return cfg->map_data[i] + (address - cfg->map_offset[i]); + } + } + + return NULL; +}