]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/amiga-platform.c
Fix config reload?
[pistorm] / platforms / amiga / amiga-platform.c
index 819eda4f523110197aed36170b85a28f7cd70b52..09aa7bd1e6f11cb7869b8b3910cbe1f09bfcd8e0 100644 (file)
@@ -40,7 +40,7 @@ extern int ac_z3_pic_count;
 extern int ac_z3_done;
 extern int ac_z3_type[AC_PIC_LIMIT];
 extern int ac_z3_index[AC_PIC_LIMIT];
-extern int gayle_emulation_enabled;
+extern uint8_t gayle_emulation_enabled;
 
 char *z2_autoconf_id = "z2_autoconf_fast";
 char *z2_autoconf_zap_id = "^2_autoconf_fast";
@@ -57,7 +57,7 @@ extern unsigned int a314_base;
 #define max(a, b) (a > b) ? a : b
 
 uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0, kick13_mode = 0, pistorm_dev_enabled = 1;
-uint8_t a314_emulation_enabled = 0;
+uint8_t a314_emulation_enabled = 0, a314_initialized = 0;
 
 extern uint32_t piscsi_base, pistorm_dev_base;
 
@@ -116,17 +116,18 @@ inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, uns
     }
 
     if (a314_emulation_enabled && addr >= a314_base && addr < a314_base + (64 * SIZE_KILO)) {
+        //printf("%s read from A314 @$%.8X\n", op_type_names[type], addr);
         switch (type) {
             case OP_TYPE_BYTE:
-                *val = a314_read_memory_8(addr);
+                *val = a314_read_memory_8(addr - a314_base);
                 return 1;
                 break;
             case OP_TYPE_WORD:
-                *val = a314_read_memory_16(addr);
+                *val = a314_read_memory_16(addr - a314_base);
                 return 1;                
                 break;
             case OP_TYPE_LONGWORD:
-                *val = a314_read_memory_32(addr);
+                *val = a314_read_memory_32(addr - a314_base);
                 return 1;
                 break;
             default:
@@ -202,9 +203,10 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un
     }
 
     if (a314_emulation_enabled && addr >= a314_base && addr < a314_base + (64 * SIZE_KILO)) {
+        //printf("%s write to A314 @$%.8X: %d\n", op_type_names[type], addr, val);
         switch (type) {
             case OP_TYPE_BYTE:
-                a314_write_memory_8(addr, val);
+                a314_write_memory_8(addr - a314_base, val);
                 return 1;
                 break;
             case OP_TYPE_WORD:
@@ -438,16 +440,22 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) {
         kick13_mode = 1;
     }
     if CHKVAR("a314") {
-        int32_t res = a314_init();
-        if (res != 0) {
-            printf("[AMIGA] Failed to enable A314 emulation, error return code: %d.\n", res);
+        if (!a314_initialized) {
+            int32_t res = a314_init();
+            if (res != 0) {
+                printf("[AMIGA] Failed to enable A314 emulation, error return code: %d.\n", res);
+            } else {
+                printf("[AMIGA] A314 emulation enabled.\n");
+                add_z2_pic(ACTYPE_A314, 0);
+                a314_emulation_enabled = 1;
+                a314_initialized = 1;
+            }
         } else {
-            printf("[AMIGA] A314 emulation enabled.\n");
             add_z2_pic(ACTYPE_A314, 0);
             a314_emulation_enabled = 1;
         }
     }
-    if CHKVAR("a314conf") {
+    if CHKVAR("a314_conf") {
         if (val && strlen(val) != 0) {
             a314_set_config_file(val);
         }
@@ -529,6 +537,7 @@ void handle_reset_amiga(struct emulator_config *cfg) {
 }
 
 void shutdown_platform_amiga(struct emulator_config *cfg) {
+    printf("[AMIGA] Performing Amiga platform shutdown.\n");
     if (cfg) {}
     if (cdtv_mode) {
         FILE *out = fopen("data/cdtv.sram", "wb+");
@@ -543,6 +552,7 @@ void shutdown_platform_amiga(struct emulator_config *cfg) {
     }
     if (cfg->platform->subsys) {
         free(cfg->platform->subsys);
+        cfg->platform->subsys = NULL;
     }
     if (piscsi_enabled) {
         piscsi_shutdown();