]> git.sesse.net Git - pistorm/blobdiff - config_file/config_file.c
Do not free MAPTYPE_RAM_NOALLOC mapped data
[pistorm] / config_file / config_file.c
index a482041037b515aea652391f26e1acdbe6f48b76..12ba4b4e99955384a09dc5f833f954bc1ec14c63 100644 (file)
@@ -306,7 +306,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]) {
@@ -314,6 +316,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;
@@ -538,9 +541,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;
+}