示例#1
0
/* Detach a disk image from the true drive emulation. */
int drive_image_detach(disk_image_t *image, unsigned int unit)
{
    unsigned int dnr, i;
    drive_t *drive;

    if (unit < 8 || unit >= 8 + DRIVE_NUM) {
        return -1;
    }

    dnr = unit - 8;
    drive = drive_context[dnr]->drive;

    if (drive->image != NULL) {
        switch (image->type) {
            case DISK_IMAGE_TYPE_D64:
            case DISK_IMAGE_TYPE_D67:
            case DISK_IMAGE_TYPE_D71:
            case DISK_IMAGE_TYPE_G64:
            case DISK_IMAGE_TYPE_P64:
            case DISK_IMAGE_TYPE_X64:
                disk_image_detach_log(image, driveimage_log, unit);
                break;
            default:
                return -1;
        }
    }

    if (drive->P64_image_loaded && drive->P64_dirty) {
        drive->P64_dirty = 0;
        if (disk_image_write_p64_image(drive->image) < 0) {
            log_error(drive->log, "Cannot write disk image back.");
        }
    } else {
        drive_gcr_data_writeback(drive);
    }

    for (i = 0; i < MAX_GCR_TRACKS; i++) {
        if (drive->gcr->tracks[i].data) {
            lib_free(drive->gcr->tracks[i].data);
            drive->gcr->tracks[i].data = NULL;
            drive->gcr->tracks[i].size = 0;
        }
    }
    drive->detach_clk = drive_clk[dnr];
    drive->GCR_image_loaded = 0;
    drive->P64_image_loaded = 0;
    drive->read_only = 0;
    drive->image = NULL;
    drive_set_half_track(drive->current_half_track, drive->side, drive);

    return 0;
}
示例#2
0
void drive_gcr_data_writeback_all(void)
{
    drive_t *drive;
    unsigned int i;

    for (i = 0; i < DRIVE_NUM; i++) {
        drive = drive_context[i]->drive;
        drive_gcr_data_writeback(drive);
        if (drive->P64_image_loaded && drive->image && drive->image->p64) {
            if (drive->image->type == DISK_IMAGE_TYPE_P64) {
                if (drive->P64_dirty) {
                    drive->P64_dirty = 0;
                    disk_image_write_p64_image(drive->image);
                }
            }
        }
    }
}