示例#1
0
int fsimage_read_sector(const disk_image_t *image, uint8_t *buf, const disk_addr_t *dadr)
{
    fsimage_t *fsimage;

    fsimage = image->media.fsimage;

    if (fsimage->fd == NULL) {
        log_error(fsimage_log, "Attempt to read without disk image.");
        return CBMDOS_IPE_NOT_READY;
    }

    switch (image->type) {
        case DISK_IMAGE_TYPE_D64:
        case DISK_IMAGE_TYPE_D67:
        case DISK_IMAGE_TYPE_D71:
        case DISK_IMAGE_TYPE_D81:
        case DISK_IMAGE_TYPE_D80:
        case DISK_IMAGE_TYPE_D82:
        case DISK_IMAGE_TYPE_X64:
        case DISK_IMAGE_TYPE_D1M:
        case DISK_IMAGE_TYPE_D2M:
        case DISK_IMAGE_TYPE_D4M:
            return fsimage_dxx_read_sector(image, buf, dadr);
        case DISK_IMAGE_TYPE_G64:
        case DISK_IMAGE_TYPE_G71:
            return fsimage_gcr_read_sector(image, buf, dadr);
        case DISK_IMAGE_TYPE_P64:
            return fsimage_p64_read_sector(image, buf, dadr);
        default:
            log_error(fsimage_log,
                      "Unknown disk image type %i.  Cannot read sector.",
                      image->type);
            return CBMDOS_IPE_NOT_READY;
    }
}
示例#2
0
int fsimage_read_sector(disk_image_t *image, BYTE *buf, unsigned int track,
                        unsigned int sector)
{
	int sectors;
	long offset;
	fsimage_t *fsimage;

	fsimage = image->media.fsimage;

	if (fsimage->fd == NULL)
	{
		#ifdef CELL_DEBUG
		printf("ERROR: Attempt to read without disk image.\n");
		#endif
		return 74;
	}

	switch (image->type) {
		case DISK_IMAGE_TYPE_D64:
		case DISK_IMAGE_TYPE_D67:
		case DISK_IMAGE_TYPE_D71:
		case DISK_IMAGE_TYPE_D81:
		case DISK_IMAGE_TYPE_D80:
		case DISK_IMAGE_TYPE_D82:
		case DISK_IMAGE_TYPE_X64:
			sectors = disk_image_check_sector(image, track, sector);

			if (sectors < 0)
			{
				#ifdef CELL_DEBUG
				printf("ERROR: Track %i, Sector %i out of bounds.\n", track, sector);
				#endif
				return 66;
			}

			offset = sectors << 8;

			if (image->type == DISK_IMAGE_TYPE_X64)
				offset += X64_HEADER_LENGTH;

			fseek(fsimage->fd, offset, SEEK_SET);

			if (fread((char *)buf, 256, 1, fsimage->fd) < 1)
			{
				#ifdef CELL_DEBUG
				printf("ERROR: Error reading T:%i S:%i from disk image.\n", track, sector);
				#endif
				return -1;
			}

			if (fsimage->error_info != NULL) {
				switch (fsimage->error_info[sectors]) {
					case 0x0:
					case 0x1:
						return CBMDOS_IPE_OK;               /* 0 */
					case 0x2:
						return CBMDOS_IPE_READ_ERROR_BNF;   /* 20 */
					case 0x3:
						return CBMDOS_IPE_READ_ERROR_SYNC;  /* 21 */
					case 0x4:
						return CBMDOS_IPE_READ_ERROR_DATA;  /* 22 */
					case 0x5:
						return CBMDOS_IPE_READ_ERROR_CHK;   /* 23 */ 
					case 0x7:
						return CBMDOS_IPE_WRITE_ERROR_VER;  /* 25 */
					case 0x8:
						return CBMDOS_IPE_WRITE_PROTECT_ON; /* 26 */
					case 0x9:
						return CBMDOS_IPE_READ_ERROR_BCHK;  /* 27 */
					case 0xA:
						return CBMDOS_IPE_WRITE_ERROR_BIG;  /* 28 */
					case 0xB:
						return CBMDOS_IPE_DISK_ID_MISMATCH; /* 29 */
					case 0xF:
						return CBMDOS_IPE_NOT_READY;        /* 74 */
					case 0x10:
						return CBMDOS_IPE_READ_ERROR_GCR;   /* 24 */
					default:
						return 0;
				}
			}
			break;
		case DISK_IMAGE_TYPE_G64:
			if (fsimage_gcr_read_sector(image, buf, track, sector) < 0)
				return -1;
			break;
		default:
			#ifdef CELL_DEBUG
			printf("ERROR: Unknown disk image type %i.  Cannot read sector.", image->type);
			#endif
			return -1;
	}
	return 0;
}