int finalexpansion_snapshot_read_module(snapshot_t *s) { BYTE vmajor, vminor; snapshot_module_t *m; BYTE *cart_flash = NULL; m = snapshot_module_open(s, SNAP_MODULE_NAME, &vmajor, &vminor); if (m == NULL) { return -1; } if (vmajor != VIC20CART_DUMP_VER_MAJOR) { snapshot_module_close(m); return -1; } if (!cart_ram) { cart_ram = lib_malloc(CART_RAM_SIZE); } if (!cart_flash) { cart_flash = lib_malloc(CART_ROM_SIZE); } flash040core_init(&flash_state, maincpu_alarm_context, FLASH040_TYPE_B, cart_flash); if (0 || (SMR_B(m, ®ister_a) < 0) || (SMR_B(m, ®ister_b) < 0) || (SMR_B(m, &lock_bit) < 0) || (SMR_BA(m, cart_ram, CART_RAM_SIZE) < 0) || (SMR_BA(m, flash_state.flash_data, CART_ROM_SIZE) < 0)) { snapshot_module_close(m); flash040core_shutdown(&flash_state); lib_free(cart_ram); lib_free(cart_flash); cart_ram = NULL; cart_flash = NULL; return -1; } snapshot_module_close(m); if ((flash040core_snapshot_read_module(s, &flash_state, FLASH_SNAP_MODULE_NAME) < 0)) { flash040core_shutdown(&flash_state); lib_free(cart_ram); lib_free(cart_flash); cart_ram = NULL; cart_flash = NULL; return -1; } mem_cart_blocks = VIC_CART_RAM123 | VIC_CART_BLK1 | VIC_CART_BLK2 | VIC_CART_BLK3 | VIC_CART_BLK5 | VIC_CART_IO2 | VIC_CART_IO3; mem_initialize_memory(); return 0; }
int easyflash_snapshot_read_module(snapshot_t *s) { BYTE vmajor, vminor; snapshot_module_t *m; m = snapshot_module_open(s, SNAP_MODULE_NAME, &vmajor, &vminor); if (m == NULL) { return -1; } if ((vmajor != CART_DUMP_VER_MAJOR) || (vminor != CART_DUMP_VER_MINOR)) { snapshot_module_close(m); return -1; } if (0 || (SMR_B_INT(m, &easyflash_jumper) < 0) || (SMR_B(m, &easyflash_register_00) < 0) || (SMR_B(m, &easyflash_register_02) < 0) || (SMR_BA(m, easyflash_ram, 256) < 0) || (SMR_BA(m, roml_banks, 0x80000) < 0) || (SMR_BA(m, romh_banks, 0x80000) < 0)) { snapshot_module_close(m); return -1; } snapshot_module_close(m); easyflash_state_low = lib_malloc(sizeof(flash040_context_t)); easyflash_state_high = lib_malloc(sizeof(flash040_context_t)); flash040core_init(easyflash_state_low, maincpu_alarm_context, FLASH040_TYPE_B, roml_banks); flash040core_init(easyflash_state_high, maincpu_alarm_context, FLASH040_TYPE_B, romh_banks); if (0 || (flash040core_snapshot_read_module(s, easyflash_state_low, FLASH_SNAP_MODULE_NAME) < 0) || (flash040core_snapshot_read_module(s, easyflash_state_low, FLASH_SNAP_MODULE_NAME) < 0)) { flash040core_shutdown(easyflash_state_low); flash040core_shutdown(easyflash_state_high); lib_free(easyflash_state_low); lib_free(easyflash_state_high); return -1; } easyflash_common_attach("dummy"); /* remove dummy filename, set filetype to none */ lib_free(easyflash_filename); easyflash_filename = NULL; easyflash_filetype = 0; return 0; }
void easyflash_detach(void) { if (easyflash_crt_write) { easyflash_flush_image(); } flash040core_shutdown(easyflash_state_low); flash040core_shutdown(easyflash_state_high); lib_free(easyflash_state_low); lib_free(easyflash_state_high); lib_free(easyflash_filename); easyflash_filename = NULL; io_source_unregister(easyflash_io1_list_item); io_source_unregister(easyflash_io2_list_item); easyflash_io1_list_item = NULL; easyflash_io2_list_item = NULL; c64export_remove(&export_res); }
int vic_fp_snapshot_read_module(snapshot_t *s) { BYTE vmajor, vminor; snapshot_module_t *m; m = snapshot_module_open(s, SNAP_MODULE_NAME, &vmajor, &vminor); if (m == NULL) { return -1; } if (vmajor != VIC20CART_DUMP_VER_MAJOR) { snapshot_module_close(m); return -1; } if (!cart_ram) { cart_ram = lib_malloc(CART_RAM_SIZE); } if (!cart_rom) { cart_rom = lib_malloc(CART_ROM_SIZE); } flash040core_init(&flash_state, maincpu_alarm_context, FLASH040_TYPE_032B_A0_1_SWAP, cart_rom); if (0 || (SMR_B(m, &cart_bank_reg) < 0) || (SMR_B(m, &cart_cfg_reg) < 0) || (SMR_BA(m, cart_ram, CART_RAM_SIZE) < 0) || (SMR_BA(m, cart_rom, CART_ROM_SIZE) < 0)) { snapshot_module_close(m); lib_free(cart_ram); lib_free(cart_rom); cart_ram = NULL; cart_rom = NULL; return -1; } snapshot_module_close(m); if ((flash040core_snapshot_read_module(s, &flash_state, FLASH_SNAP_MODULE_NAME) < 0)) { flash040core_shutdown(&flash_state); lib_free(cart_ram); lib_free(cart_rom); cart_ram = NULL; cart_rom = NULL; return -1; } CART_CFG_INIT(cart_cfg_reg); mem_cart_blocks = VIC_CART_RAM123 | VIC_CART_BLK1 | VIC_CART_BLK2 | VIC_CART_BLK3 | VIC_CART_BLK5 | VIC_CART_IO2; mem_initialize_memory(); return 0; }
void finalexpansion_detach(void) { /* try to write back cartridge contents if write back is enabled and cartridge wasn't from a snapshot */ if (finalexpansion_writeback && !cartridge_is_from_snapshot) { if (flash_state.flash_dirty) { int n; FILE *fd; n = 0; log_message(fe_log, "Flash dirty, trying to write back..."); fd = fopen(cartfile, "wb"); if (fd) { n = fwrite(flash_state.flash_data, (size_t)CART_ROM_SIZE, 1, fd); fclose(fd); } if (n < 1) { log_message(fe_log, "Failed to write back image `%s'!", cartfile); } else { log_message(fe_log, "Wrote back image `%s'.", cartfile); } } else { log_message(fe_log, "Flash clean, skipping write back."); } } mem_cart_blocks = 0; mem_initialize_memory(); lib_free(flash_state.flash_data); flash040core_shutdown(&flash_state); lib_free(cart_ram); cart_ram = NULL; lib_free(cartfile); cartfile = NULL; if (finalexpansion_list_item != NULL) { io_source_unregister(finalexpansion_list_item); finalexpansion_list_item = NULL; } }