int drive_snapshot_read_module(snapshot_t *s) { BYTE major_version, minor_version; int i; snapshot_module_t *m; char snap_module_name[] = "DRIVE"; DWORD rotation_table_ptr[DRIVE_NUM]; CLOCK attach_clk[DRIVE_NUM]; CLOCK detach_clk[DRIVE_NUM]; CLOCK attach_detach_clk[DRIVE_NUM]; int drive_true_emulation; int sync_factor; drive_t *drive; int dummy; int half_track[DRIVE_NUM]; m = snapshot_module_open(s, snap_module_name, &major_version, &minor_version); if (m == NULL) { /* If this module is not found true emulation is off. */ resources_set_int("DriveTrueEmulation", 0); return 0; } drive_gcr_data_writeback_all(); if (major_version > DRIVE_SNAP_MAJOR || minor_version > DRIVE_SNAP_MINOR) { log_error(drive_snapshot_log, "Snapshot module version (%d.%d) newer than %d.%d.", major_version, minor_version, DRIVE_SNAP_MAJOR, DRIVE_SNAP_MINOR); } /* If this module exists true emulation is enabled. */ /* XXX drive_true_emulation = 1 */ resources_set_int("DriveTrueEmulation", 1); if (SMR_DW_INT(m, &sync_factor) < 0) { snapshot_module_close(m); return -1; } /* TODO: NUM_DRIVES drives instead of 2 */ for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; /* Partially read 1.0 snapshots */ if (major_version == 1 && minor_version == 0) { if (0 || SMR_DW_UL(m, &(drive->snap_accum)) < 0 || SMR_DW(m, &(attach_clk[i])) < 0 || SMR_DW_INT(m, &dummy) < 0 || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0 || SMR_B_INT(m, &(drive->clock_frequency)) < 0 || SMR_W_INT(m, &half_track[i]) < 0 || SMR_DW(m, &(detach_clk[i])) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B_INT(m, &(drive->extend_image_policy)) < 0 || SMR_B_INT(m, &dummy) < 0 || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0 || SMR_B(m, &(drive->GCR_read)) < 0 || SMR_B(m, &(drive->GCR_write_value)) < 0 || SMR_B_INT(m, &(drive->idling_method)) < 0 || SMR_B_INT(m, &dummy) < 0 || SMR_B_INT(m, &(drive->parallel_cable)) < 0 || SMR_B_INT(m, &(drive->read_only)) < 0 || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0 || SMR_DW(m, &rotation_table_ptr[i]) < 0 || SMR_DW_UINT(m, &(drive->type)) < 0 ) { snapshot_module_close(m); return -1; } /* Partially read 1.1 snapshots */ } else if (major_version == 1 && minor_version == 1) { if (0 || SMR_DW(m, &(attach_clk[i])) < 0 || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0 || SMR_B_INT(m, &(drive->clock_frequency)) < 0 || SMR_W_INT(m, &half_track[i]) < 0 || SMR_DW(m, &(detach_clk[i])) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B_INT(m, &(drive->extend_image_policy)) < 0 || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0 || SMR_B(m, &(drive->GCR_read)) < 0 || SMR_B(m, &(drive->GCR_write_value)) < 0 || SMR_B_INT(m, &(drive->idling_method)) < 0 || SMR_B_INT(m, &(drive->parallel_cable)) < 0 || SMR_B_INT(m, &(drive->read_only)) < 0 || SMR_DW(m, &rotation_table_ptr[i]) < 0 || SMR_DW_UINT(m, &(drive->type)) < 0 || SMR_DW_UL(m, &(drive->snap_accum)) < 0 || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0 || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0 || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0 || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0 || SMR_B(m, &(drive->snap_last_write_data)) < 0 || SMR_DW_INT(m, &(drive->snap_seed)) < 0 ) { snapshot_module_close(m); return -1; } /* Partially read 1.2 snapshots */ } else if (major_version == 1 && minor_version == 2) { if (0 || SMR_DW(m, &(attach_clk[i])) < 0 || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0 || SMR_B_INT(m, &(drive->clock_frequency)) < 0 || SMR_W_INT(m, &half_track[i]) < 0 || SMR_DW(m, &(detach_clk[i])) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B_INT(m, &(drive->extend_image_policy)) < 0 || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0 || SMR_B(m, &(drive->GCR_read)) < 0 || SMR_B(m, &(drive->GCR_write_value)) < 0 || SMR_B_INT(m, &(drive->idling_method)) < 0 || SMR_B_INT(m, &(drive->parallel_cable)) < 0 || SMR_B_INT(m, &(drive->read_only)) < 0 || SMR_DW(m, &rotation_table_ptr[i]) < 0 || SMR_DW_UINT(m, &(drive->type)) < 0 || SMR_DW_UL(m, &(drive->snap_accum)) < 0 || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0 || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0 || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0 || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0 || SMR_B(m, &(drive->snap_last_write_data)) < 0 || SMR_DW_INT(m, &(drive->snap_seed)) < 0 || SMR_DW(m, &(drive->snap_speed_zone)) < 0 || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0 || SMR_DW(m, &(drive->snap_ue7_counter)) < 0 || SMR_DW(m, &(drive->snap_uf4_counter)) < 0 || SMR_DW(m, &(drive->snap_fr_randcount)) < 0 || SMR_DW(m, &(drive->snap_filter_counter)) < 0 || SMR_DW(m, &(drive->snap_filter_state)) < 0 || SMR_DW(m, &(drive->snap_filter_last_state)) < 0 || SMR_DW(m, &(drive->snap_write_flux)) < 0 || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0 || SMR_DW(m, &(drive->snap_xorShift32)) < 0 ) { snapshot_module_close(m); return -1; } } else if (major_version == 1 && minor_version == 3) { if (0 || SMR_DW(m, &(attach_clk[i])) < 0 || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0 || SMR_B_INT(m, &(drive->clock_frequency)) < 0 || SMR_W_INT(m, &half_track[i]) < 0 || SMR_DW(m, &(detach_clk[i])) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B_INT(m, &(drive->extend_image_policy)) < 0 || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0 || SMR_B(m, &(drive->GCR_read)) < 0 || SMR_B(m, &(drive->GCR_write_value)) < 0 || SMR_B_INT(m, &(drive->idling_method)) < 0 || SMR_B_INT(m, &(drive->parallel_cable)) < 0 || SMR_B_INT(m, &(drive->read_only)) < 0 || SMR_DW(m, &rotation_table_ptr[i]) < 0 || SMR_DW_UINT(m, &(drive->type)) < 0 || SMR_DW_UL(m, &(drive->snap_accum)) < 0 || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0 || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0 || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0 || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0 || SMR_B(m, &(drive->snap_last_write_data)) < 0 || SMR_DW_INT(m, &(drive->snap_seed)) < 0 || SMR_DW(m, &(drive->snap_speed_zone)) < 0 || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0 || SMR_DW(m, &(drive->snap_ue7_counter)) < 0 || SMR_DW(m, &(drive->snap_uf4_counter)) < 0 || SMR_DW(m, &(drive->snap_fr_randcount)) < 0 || SMR_DW(m, &(drive->snap_filter_counter)) < 0 || SMR_DW(m, &(drive->snap_filter_state)) < 0 || SMR_DW(m, &(drive->snap_filter_last_state)) < 0 || SMR_DW(m, &(drive->snap_write_flux)) < 0 || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0 || SMR_DW(m, &(drive->snap_xorShift32)) < 0 || SMR_DW(m, &(drive->snap_so_delay)) < 0 ) { snapshot_module_close(m); return -1; } } else { if (0 || SMR_DW(m, &(attach_clk[i])) < 0 || SMR_B_INT(m, (int *)&(drive->byte_ready_level)) < 0 || SMR_B_INT(m, &(drive->clock_frequency)) < 0 || SMR_W_INT(m, &half_track[i]) < 0 || SMR_DW(m, &(detach_clk[i])) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B(m, (BYTE *)&dummy) < 0 || SMR_B_INT(m, &(drive->extend_image_policy)) < 0 || SMR_DW_UINT(m, &(drive->GCR_head_offset)) < 0 || SMR_B(m, &(drive->GCR_read)) < 0 || SMR_B(m, &(drive->GCR_write_value)) < 0 || SMR_B_INT(m, &(drive->idling_method)) < 0 || SMR_B_INT(m, &(drive->parallel_cable)) < 0 || SMR_B_INT(m, &(drive->read_only)) < 0 || SMR_DW(m, &rotation_table_ptr[i]) < 0 || SMR_DW_UINT(m, &(drive->type)) < 0 || SMR_DW_UL(m, &(drive->snap_accum)) < 0 || SMR_DW(m, &(drive->snap_rotation_last_clk)) < 0 || SMR_DW_INT(m, &(drive->snap_bit_counter)) < 0 || SMR_DW_INT(m, &(drive->snap_zero_count)) < 0 || SMR_W_INT(m, &(drive->snap_last_read_data)) < 0 || SMR_B(m, &(drive->snap_last_write_data)) < 0 || SMR_DW_INT(m, &(drive->snap_seed)) < 0 || SMR_DW(m, &(drive->snap_speed_zone)) < 0 || SMR_DW(m, &(drive->snap_ue7_dcba)) < 0 || SMR_DW(m, &(drive->snap_ue7_counter)) < 0 || SMR_DW(m, &(drive->snap_uf4_counter)) < 0 || SMR_DW(m, &(drive->snap_fr_randcount)) < 0 || SMR_DW(m, &(drive->snap_filter_counter)) < 0 || SMR_DW(m, &(drive->snap_filter_state)) < 0 || SMR_DW(m, &(drive->snap_filter_last_state)) < 0 || SMR_DW(m, &(drive->snap_write_flux)) < 0 || SMR_DW(m, &(drive->snap_PulseHeadPosition)) < 0 || SMR_DW(m, &(drive->snap_xorShift32)) < 0 || SMR_DW(m, &(drive->snap_so_delay)) < 0 || SMR_DW(m, &(drive->snap_cycle_index)) < 0 || SMR_DW(m, &(drive->snap_ref_advance)) < 0 || SMR_DW(m, &(drive->snap_req_ref_cycles)) < 0 ) { snapshot_module_close(m); return -1; } } } /* this one is new, so don't test so stay compatible with old snapshots */ for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; SMR_DW(m, &(attach_detach_clk[i])); } /* these are even newer */ for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; SMR_B_INT(m, (int *)&(drive->byte_ready_edge)); SMR_B_INT(m, (int *)&(drive->byte_ready_active)); } snapshot_module_close(m); m = NULL; rotation_table_set(rotation_table_ptr); drive = drive_context[0]->drive; switch (drive->type) { case DRIVE_TYPE_1540: case DRIVE_TYPE_1541: case DRIVE_TYPE_1541II: case DRIVE_TYPE_1551: case DRIVE_TYPE_1570: case DRIVE_TYPE_1571: case DRIVE_TYPE_1571CR: case DRIVE_TYPE_1581: case DRIVE_TYPE_2000: case DRIVE_TYPE_4000: case DRIVE_TYPE_2031: case DRIVE_TYPE_1001: case DRIVE_TYPE_2040: case DRIVE_TYPE_3040: case DRIVE_TYPE_4040: case DRIVE_TYPE_8050: case DRIVE_TYPE_8250: drive->enable = 1; machine_drive_rom_setup_image(0); drivemem_init(drive_context[0], drive->type); resources_set_int("Drive8IdleMethod", drive->idling_method); driverom_initialize_traps(drive); drive_set_active_led_color(drive->type, 0); machine_bus_status_drivetype_set(8, 1); break; case DRIVE_TYPE_NONE: drive_disable(drive_context[0]); machine_bus_status_drivetype_set(8, 0); break; default: return -1; } drive = drive_context[1]->drive; switch (drive->type) { case DRIVE_TYPE_1540: case DRIVE_TYPE_1541: case DRIVE_TYPE_1541II: case DRIVE_TYPE_1551: case DRIVE_TYPE_1570: case DRIVE_TYPE_1571: case DRIVE_TYPE_1581: case DRIVE_TYPE_2000: case DRIVE_TYPE_4000: case DRIVE_TYPE_2031: case DRIVE_TYPE_1001: /* drive 1 does not allow dual disk drive */ drive->enable = 1; machine_drive_rom_setup_image(1); drivemem_init(drive_context[1], drive->type); resources_set_int("Drive9IdleMethod", drive->idling_method); driverom_initialize_traps(drive); drive_set_active_led_color(drive->type, 1); machine_bus_status_drivetype_set(9, 1); break; case DRIVE_TYPE_NONE: case DRIVE_TYPE_8050: case DRIVE_TYPE_8250: drive_disable(drive_context[1]); machine_bus_status_drivetype_set(9, 0); break; default: return -1; } /* Clear parallel cable before undumping parallel port values. */ for (i = 0; i < DRIVE_PC_NUM; i++) { parallel_cable_drive_write(i, 0xff, PARALLEL_WRITE, 0); parallel_cable_drive_write(i, 0xff, PARALLEL_WRITE, 1); } for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (drive->enable) { if (drive->type == DRIVE_TYPE_2000 || drive->type == DRIVE_TYPE_4000) { if (drivecpu65c02_snapshot_read_module(drive_context[i], s) < 0) { return -1; } } else { if (drivecpu_snapshot_read_module(drive_context[i], s) < 0) { return -1; } } if (machine_drive_snapshot_read(drive_context[i], s) < 0) { return -1; } } } if (drive_snapshot_read_image_module(s, 0) < 0 || drive_snapshot_read_gcrimage_module(s, 0) < 0 || drive_snapshot_read_p64image_module(s, 0) < 0) { return -1; } if (drive_snapshot_read_image_module(s, 1) < 0 || drive_snapshot_read_gcrimage_module(s, 1) < 0 || drive_snapshot_read_p64image_module(s, 1) < 0) { return -1; } if (driverom_snapshot_read(s, drive_context[0]->drive) < 0) { return -1; } if (driverom_snapshot_read(s, drive_context[1]->drive) < 0) { return -1; } for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (drive->type != DRIVE_TYPE_NONE) { drive_enable(drive_context[i]); drive->attach_clk = attach_clk[i]; drive->detach_clk = detach_clk[i]; drive->attach_detach_clk = attach_detach_clk[i]; } } for (i = 0; i < 2; i++) { int side = 0; drive = drive_context[i]->drive; if (drive->type == DRIVE_TYPE_1570 || drive->type == DRIVE_TYPE_1571 || drive->type == DRIVE_TYPE_1571CR) { if (half_track[i] > (DRIVE_HALFTRACKS_1571 + 1)) { side = 1; half_track[i] -= DRIVE_HALFTRACKS_1571; } } drive_set_half_track(half_track[i], side, drive); resources_set_int("MachineVideoStandard", sync_factor); } /* stop currently active drive sounds (bug #3539422) * FIXME: when the drive sound emulation becomes more precise, we might * want/need to save a snapshot of its current state too */ drive_sound_stop(); iec_update_ports_embedded(); drive_update_ui_status(); resources_get_int("DriveTrueEmulation", &drive_true_emulation); if (vdrive_snapshot_module_read(s, drive_true_emulation ? 10 : 8) < 0) { return -1; } return 0; }
void machine_drive_flush(void) { drive_gcr_data_writeback_all(); }
int drive_snapshot_write_module(snapshot_t *s, int save_disks, int save_roms) { int i; char snap_module_name[] = "DRIVE"; snapshot_module_t *m; DWORD rotation_table_ptr[DRIVE_NUM]; BYTE GCR_image[4], P64_image[4]; int drive_true_emulation; int sync_factor; drive_t *drive; resources_get_int("DriveTrueEmulation", &drive_true_emulation); if (vdrive_snapshot_module_write(s, drive_true_emulation ? 10 : 8) < 0) { return -1; } if (!drive_true_emulation) { return 0; } drive_gcr_data_writeback_all(); rotation_table_get(rotation_table_ptr); for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; GCR_image[i] = (drive->GCR_image_loaded == 0 || !save_disks) ? 0 : 1; P64_image[i] = (drive->P64_image_loaded == 0 || !save_disks) ? 0 : 1; } m = snapshot_module_create(s, snap_module_name, DRIVE_SNAP_MAJOR, DRIVE_SNAP_MINOR); if (m == NULL) { return -1; } resources_get_int("MachineVideoStandard", &sync_factor); if (SMW_DW(m, (DWORD)sync_factor) < 0) { if (m != NULL) { snapshot_module_close(m); } return -1; } /* TODO: NUM_DRIVES drives instead of 2 */ for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (0 || SMW_DW(m, (DWORD)(drive->attach_clk)) < 0 || SMW_B(m, (BYTE)(drive->byte_ready_level)) < 0 || SMW_B(m, (BYTE)(drive->clock_frequency)) < 0 || SMW_W(m, (WORD)(drive->current_half_track + (drive->side * DRIVE_HALFTRACKS_1571))) < 0 || SMW_DW(m, (DWORD)(drive->detach_clk)) < 0 || SMW_B(m, (BYTE)0) < 0 || SMW_B(m, (BYTE)0) < 0 || SMW_B(m, (BYTE)(drive->extend_image_policy)) < 0 || SMW_DW(m, (DWORD)(drive->GCR_head_offset)) < 0 || SMW_B(m, (BYTE)(drive->GCR_read)) < 0 || SMW_B(m, (BYTE)(drive->GCR_write_value)) < 0 || SMW_B(m, (BYTE)(drive->idling_method)) < 0 || SMW_B(m, (BYTE)(drive->parallel_cable)) < 0 || SMW_B(m, (BYTE)(drive->read_only)) < 0 || SMW_DW(m, (DWORD)(rotation_table_ptr[i])) < 0 || SMW_DW(m, (DWORD)(drive->type)) < 0 /* rotation */ || SMW_DW(m, (DWORD)(drive->snap_accum)) < 0 || SMW_DW(m, (DWORD)(drive->snap_rotation_last_clk)) < 0 || SMW_DW(m, (DWORD)(drive->snap_bit_counter)) < 0 || SMW_DW(m, (DWORD)(drive->snap_zero_count)) < 0 || SMW_W(m, (WORD)(drive->snap_last_read_data)) < 0 || SMW_B(m, (BYTE)(drive->snap_last_write_data)) < 0 || SMW_DW(m, (BYTE)(drive->snap_seed)) < 0 || SMW_DW(m, (DWORD)(drive->snap_speed_zone)) < 0 || SMW_DW(m, (DWORD)(drive->snap_ue7_dcba)) < 0 || SMW_DW(m, (DWORD)(drive->snap_ue7_counter)) < 0 || SMW_DW(m, (DWORD)(drive->snap_uf4_counter)) < 0 || SMW_DW(m, (DWORD)(drive->snap_fr_randcount)) < 0 || SMW_DW(m, (DWORD)(drive->snap_filter_counter)) < 0 || SMW_DW(m, (DWORD)(drive->snap_filter_state)) < 0 || SMW_DW(m, (DWORD)(drive->snap_filter_last_state)) < 0 || SMW_DW(m, (DWORD)(drive->snap_write_flux)) < 0 || SMW_DW(m, (DWORD)(drive->snap_PulseHeadPosition)) < 0 || SMW_DW(m, (DWORD)(drive->snap_xorShift32)) < 0 || SMW_DW(m, (DWORD)(drive->snap_so_delay)) < 0 || SMW_DW(m, (DWORD)(drive->snap_cycle_index)) < 0 || SMW_DW(m, (DWORD)(drive->snap_ref_advance)) < 0 || SMW_DW(m, (DWORD)(drive->snap_req_ref_cycles)) < 0 ) { if (m != NULL) { snapshot_module_close(m); } return -1; } } /* new snapshot members */ for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (0 || SMW_DW(m, (DWORD)(drive->attach_detach_clk)) < 0 ) { if (m != NULL) { snapshot_module_close(m); } return -1; } } for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (0 || SMW_B(m, (BYTE)(drive->byte_ready_edge)) < 0 || SMW_B(m, (BYTE)(drive->byte_ready_active)) < 0 ) { if (m != NULL) { snapshot_module_close(m); } return -1; } } if (snapshot_module_close(m) < 0) { return -1; } for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (drive->enable) { if (drive->type == DRIVE_TYPE_2000 || drive->type == DRIVE_TYPE_4000) { if (drivecpu65c02_snapshot_write_module(drive_context[i], s) < 0) { return -1; } } else { if (drivecpu_snapshot_write_module(drive_context[i], s) < 0) { return -1; } } if (machine_drive_snapshot_write(drive_context[i], s) < 0) { return -1; } } } if (save_disks) { if (GCR_image[0] > 0) { if (drive_snapshot_write_gcrimage_module(s, 0) < 0) { return -1; } } else if (P64_image[0] > 0) { if (drive_snapshot_write_p64image_module(s, 0) < 0) { return -1; } } else { if (drive_snapshot_write_image_module(s, 0) < 0) { return -1; } } if (GCR_image[1] > 0) { if (drive_snapshot_write_gcrimage_module(s, 1) < 0) { return -1; } } else if (P64_image[1] > 0) { if (drive_snapshot_write_p64image_module(s, 1) < 0) { return -1; } } else { if (drive_snapshot_write_image_module(s, 1) < 0) { return -1; } } } for (i = 0; i < 2; i++) { drive = drive_context[i]->drive; if (save_roms && drive->enable) { if (driverom_snapshot_write(s, drive) < 0) { return -1; } } } return 0; }