]> git.sesse.net Git - pistorm/commitdiff
Update config_file.h, emulator.c, and amiga-platform.c
authorbeeanyew <beeanyew@gmail.com>
Fri, 1 Jan 2021 13:46:23 +0000 (14:46 +0100)
committerbeeanyew <beeanyew@gmail.com>
Fri, 1 Jan 2021 13:46:23 +0000 (14:46 +0100)
config_file/config_file.h
emulator.c
platforms/amiga/amiga-platform.c

index 2e8cbae50bcf51468ec4895ff2533278d4d23b68..4a3e5f407b7686a6761b925e1f5f2b1a35daf6c8 100644 (file)
@@ -81,6 +81,7 @@ struct platform_config {
 
   int (*platform_initial_setup)(struct emulator_config *cfg);
   void (*handle_reset)(struct emulator_config *cfg);
+  void (*shutdown)(struct emulator_config *cfg);
   void (*setvar)(char *var, char *val);
 };
 
index 51a6f0cfa61dd8c91b861ccc9b4fe288170965c6..1a14062b21ad5a77a7f331410de56be4f82d22a9 100644 (file)
@@ -161,6 +161,10 @@ void sigint_handler(int sig_num) {
   if (mem_fd)
     close(mem_fd);
 
+  if (cfg->platform->shutdown) {
+    cfg->platform->shutdown(cfg);
+  }
+
   exit(0);
 }
 
index 4f947b89948b8cef8b7699ffdbb0e649d35e5fb4..12d80a4d81f5c23b8c62f2a588e96a2e7776fa62 100644 (file)
@@ -28,6 +28,7 @@ char *z3_autoconf_zap_id = "^3_autoconf_fast";
 extern const char *op_type_names[OP_TYPE_NUM];
 extern uint8_t cdtv_mode;
 extern uint8_t rtc_type;
+extern unsigned char cdtv_sram[32 * SIZE_KILO];
 
 #define min(a, b) (a < b) ? a : b
 #define max(a, b) (a > b) ? a : b
@@ -213,6 +214,15 @@ int setup_platform_amiga(struct emulator_config *cfg) {
     }
 
     adjust_ranges_amiga(cfg);
+
+    if (cdtv_mode) {
+        FILE *in = fopen("data/cdtv.sram", "rb");
+        if (in != NULL) {
+            printf("Loaded CDTV SRAM.\n");
+            fread(cdtv_sram, 32 * SIZE_KILO, 1, in);
+            fclose(in);
+        }
+    }
     
     return 0;
 }
@@ -256,6 +266,21 @@ void handle_reset_amiga(struct emulator_config *cfg) {
     adjust_ranges_amiga(cfg);
 }
 
+void shutdown_platform_amiga(struct emulator_config *cfg) {
+    if (cfg) {}
+    if (cdtv_mode) {
+        FILE *out = fopen("data/cdtv.sram", "wb+");
+        if (out != NULL) {
+            printf("Saving CDTV SRAM.\n");
+            fwrite(cdtv_sram, 32 * SIZE_KILO, 1, out);
+            fclose(out);
+        }
+        else {
+            printf("Failed to write CDTV SRAM to disk.\n");
+        }
+    }
+}
+
 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
     cfg->register_read = handle_register_read_amiga;
     cfg->register_write = handle_register_write_amiga;
@@ -263,6 +288,7 @@ void create_platform_amiga(struct platform_config *cfg, char *subsys) {
     cfg->custom_write = custom_write_amiga;
     cfg->platform_initial_setup = setup_platform_amiga;
     cfg->handle_reset = handle_reset_amiga;
+    cfg->shutdown = shutdown_platform_amiga;
 
     cfg->setvar = setvar_amiga;
     cfg->id = PLATFORM_AMIGA;