]> git.sesse.net Git - pistorm/blobdiff - config_file/config_file.c
Add dumb framebuffer RTG
[pistorm] / config_file / config_file.c
index c7fcccc0668ce63a3a0d008a60d0a26691d00a49..4ac96707a0ff989d0a70cae730264e01c0d2ef74 100644 (file)
@@ -1,4 +1,4 @@
-#include "config_file.h"
+#include "../platforms/platforms.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -32,6 +32,8 @@ const char *config_item_names[CONFITEM_NUM] = {
   "loopcycles",
   "mouse",
   "keyboard",
+  "platform",
+  "setvar",
 };
 
 const char *mapcmd_names[MAPCMD_NUM] = {
@@ -183,6 +185,7 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad
   cfg->map_type[index] = type;
   cfg->map_offset[index] = addr;
   cfg->map_size[index] = size;
+  cfg->map_high[index] = addr + size;
   cfg->map_mirror[index] = mirr_addr;
   if (strlen(map_id)) {
     cfg->map_id[index] = (char *)malloc(strlen(map_id) + 1);
@@ -209,15 +212,17 @@ void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int ad
       file_size = (int)ftell(in);
       if (size == 0) {
         cfg->map_size[index] = file_size;
+        cfg->map_high[index] = addr + cfg->map_size[index];
       }
       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 +231,9 @@ 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_high[index] - 1, cfg->map_id[index] ? cfg->map_id[index] : "None");
+  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]);
 
   return;
 
@@ -351,6 +358,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(cfg, var_name, var_value);
+
+        break;
+      }
       case CONFITEM_NONE:
       default:
         printf("Unknown config item %s on line %d.\n", cur_cmd, cur_line);
@@ -378,3 +413,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;
+}