From: beeanyew Date: Fri, 1 Jan 2021 13:46:23 +0000 (+0100) Subject: Update config_file.h, emulator.c, and amiga-platform.c X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e4c00f2d33dfd2b3ea4c859798f05782f8d8150f;p=pistorm Update config_file.h, emulator.c, and amiga-platform.c --- diff --git a/config_file/config_file.h b/config_file/config_file.h index 2e8cbae..4a3e5f4 100644 --- a/config_file/config_file.h +++ b/config_file/config_file.h @@ -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); }; diff --git a/emulator.c b/emulator.c index 51a6f0c..1a14062 100644 --- a/emulator.c +++ b/emulator.c @@ -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); } diff --git a/platforms/amiga/amiga-platform.c b/platforms/amiga/amiga-platform.c index 4f947b8..12d80a4 100644 --- a/platforms/amiga/amiga-platform.c +++ b/platforms/amiga/amiga-platform.c @@ -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;