]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/amiga-platform.c
More tiny optimizations, some Z2/Z3 fixes
[pistorm] / platforms / amiga / amiga-platform.c
index 21a2c6270d1c8dd54fdaec3aec04e68e2cf5fd69..c2361e30b91d6f600e7d8049a5b7fb9f66039948 100644 (file)
@@ -26,6 +26,9 @@ char *z3_autoconf_zap_id = "^3_autoconf_fast";
 
 extern const char *op_type_names[OP_TYPE_NUM];
 
+#define min(a, b) (a < b) ? a : b
+#define max(a, b) (a > b) ? a : b
+
 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
     if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
         if (ac_z2_pic_count == 0) {
@@ -65,7 +68,7 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un
                 return -1;
             }
 
-            printf("Write to Z2 autoconf area.\n");
+            //printf("Write to Z2 autoconf area.\n");
             autoconfig_write_memory_8(cfg, addr, val);
             return 1;
         }
@@ -95,6 +98,45 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un
     return -1;
 }
 
+void adjust_ranges_amiga(struct emulator_config *cfg) {
+    cfg->mapped_high = 0;
+    cfg->mapped_low = 0;
+    cfg->custom_high = 0;
+    cfg->custom_low = 0;
+
+    // Set up the min/max ranges for mapped reads/writes
+    if (gayle_emulation_enabled) {
+        cfg->mapped_low = GAYLEBASE;
+        cfg->mapped_high = GAYLEBASE + GAYLESIZE;
+    }
+    for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
+        if (cfg->map_type[i] != MAPTYPE_NONE) {
+            if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
+                cfg->mapped_low = cfg->map_offset[i];
+            if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
+                cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
+        }
+    }
+
+    if (ac_z2_pic_count && !ac_z2_done) {
+        if (cfg->custom_low == 0)
+            cfg->custom_low = AC_Z2_BASE;
+        else
+            cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
+        cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
+    }
+    if (ac_z3_pic_count && !ac_z3_done) {
+        if (cfg->custom_low == 0)
+            cfg->custom_low = AC_Z3_BASE;
+        else
+            cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
+        cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
+    }
+
+    printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
+    printf("Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
+}
+
 int setup_platform_amiga(struct emulator_config *cfg) {
     if (cfg) {}
     printf("Performing setup for Amiga platform.\n");
@@ -163,23 +205,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
         }
     }
 
-    // Set up the min/max ranges for mapped reads/writes
-    for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
-        if (cfg->map_type[i] != MAPTYPE_NONE) {
-            if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->map_low) || cfg->map_low == 0)
-                cfg->map_low = cfg->map_offset[i];
-            if (cfg->map_offset[i] + cfg->map_size[i] > cfg->map_high)
-                cfg->map_high = cfg->map_offset[i] + cfg->map_size[i];
-        }
-    }
-
-    if (gayle_emulation_enabled) {
-        cfg->custom_low = GAYLEBASE;
-        cfg->custom_high = GAYLEBASE + GAYLESIZE;
-    }
-
-    printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
-    printf("Platform mapped range: %.8X-%.8X\n", cfg->map_low, cfg->map_high);
+    adjust_ranges_amiga(cfg);
     
     return 0;
 }
@@ -205,12 +231,20 @@ void setvar_amiga(char *var, char *val) {
     }
 }
 
+void handle_reset_amiga(struct emulator_config *cfg) {
+    ac_z3_done = 0;
+    ac_z2_done = 0;
+
+    adjust_ranges_amiga(cfg);
+}
+
 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
     cfg->register_read = handle_register_read_amiga;
     cfg->register_write = handle_register_write_amiga;
     cfg->custom_read = custom_read_amiga;
     cfg->custom_write = custom_write_amiga;
     cfg->platform_initial_setup = setup_platform_amiga;
+    cfg->handle_reset = handle_reset_amiga;
 
     cfg->setvar = setvar_amiga;
     cfg->id = PLATFORM_AMIGA;