Exemple #1
0
int fsimage_gcr_read_sector(const disk_image_t *image, BYTE *buf, const disk_addr_t *dadr)
{
    fdc_err_t rf;

    if (dadr->track > image->tracks) {
        log_error(fsimage_gcr_log,
                  "Track %i out of bounds.  Cannot read GCR track.",
                  dadr->track);
        return -1;
    }

    if (image->gcr == NULL) {
        disk_track_t raw;
        if (fsimage_gcr_read_track(image, dadr->track, &raw) < 0) {
            return -1;
        }
        if (raw.data == NULL) {
            return CBMDOS_IPE_NOT_READY;
        }
        rf = gcr_read_sector(&raw, buf, (BYTE)dadr->sector);
        lib_free(raw.data);
    } else {
        rf = gcr_read_sector(&image->gcr->tracks[(dadr->track * 2) - 2], buf, (BYTE)dadr->sector);
    }
    if (rf != CBMDOS_FDC_ERR_OK) {
        log_error(fsimage_gcr_log,
                  "Cannot find track: %i sector: %i within GCR image.",
                  dadr->track, dadr->sector);
        switch (rf) {
            case CBMDOS_FDC_ERR_HEADER:
                return CBMDOS_IPE_READ_ERROR_BNF; /* 20 */
            case CBMDOS_FDC_ERR_SYNC:
                return CBMDOS_IPE_READ_ERROR_SYNC; /* 21 */
            case CBMDOS_FDC_ERR_NOBLOCK:
                return CBMDOS_IPE_READ_ERROR_DATA; /* 22 */
            case CBMDOS_FDC_ERR_DCHECK:
                return CBMDOS_IPE_READ_ERROR_CHK; /* 23 */
            case CBMDOS_FDC_ERR_VERIFY:
                return CBMDOS_IPE_WRITE_ERROR_VER; /* 25 */
            case CBMDOS_FDC_ERR_WPROT:
                return CBMDOS_IPE_WRITE_PROTECT_ON; /* 26 */
            case CBMDOS_FDC_ERR_HCHECK:
                return CBMDOS_IPE_READ_ERROR_BCHK; /* 27 */
            case CBMDOS_FDC_ERR_BLENGTH:
                return CBMDOS_IPE_WRITE_ERROR_BIG; /* 28 */
            case CBMDOS_FDC_ERR_ID:
                return CBMDOS_IPE_DISK_ID_MISMATCH; /* 29 */
            case CBMDOS_FDC_ERR_DRIVE:
                return CBMDOS_IPE_NOT_READY;    /* 74 */
            case CBMDOS_FDC_ERR_DECODE:
                return CBMDOS_IPE_READ_ERROR_GCR; /* 24 */
            default:
                return CBMDOS_IPE_NOT_READY;
        }
    }
    return CBMDOS_IPE_OK;
}
Exemple #2
0
int fsimage_gcr_write_sector(disk_image_t *image, const BYTE *buf,
                             const disk_addr_t *dadr)
{
    if (dadr->track > image->tracks) {
        log_error(fsimage_gcr_log,
                  "Track %i out of bounds.  Cannot write GCR sector",
                  dadr->track);
        return -1;
    }

    if (image->gcr == NULL) {
        disk_track_t raw;
        if (fsimage_gcr_read_track(image, dadr->track, &raw) < 0
            || raw.data == NULL) {
            return -1;
        }
        if (gcr_write_sector(&raw, buf, (BYTE)dadr->sector) != CBMDOS_FDC_ERR_OK) {
            log_error(fsimage_gcr_log,
                      "Could not find track %i sector %i in disk image",
                      dadr->track, dadr->sector);
            lib_free(raw.data);
            return -1;
        }
        if (fsimage_gcr_write_track(image, dadr->track, &raw) < 0) {
            lib_free(raw.data);
            return -1;
        }
        lib_free(raw.data);
    } else {
        if (gcr_write_sector(&image->gcr->tracks[(dadr->track * 2) - 2], buf, (BYTE)dadr->sector) != CBMDOS_FDC_ERR_OK) {
            log_error(fsimage_gcr_log,
                      "Could not find track %i sector %i in disk image",
                      dadr->track, dadr->sector);
            return -1;
        }
        if (fsimage_gcr_write_track(image, dadr->track, &image->gcr->tracks[(dadr->track * 2) - 2]) < 0) {
            log_error(fsimage_gcr_log,
                      "Failed writing track %i to disk image.", dadr->track);
            return -1;
        }
    }

    return 0;
}
Exemple #3
0
int disk_image_read_track(disk_image_t *image, unsigned int track,
                          BYTE *gcr_data, int *gcr_track_size)
{
    return fsimage_gcr_read_track(image, track, gcr_data, gcr_track_size);
}