Example #1
0
void vdrive_detach_image(disk_image_t *image, unsigned int unit,
                         vdrive_t *vdrive)
{
	if (image == NULL)
		return;

	disk_image_detach_log(image, 0, unit);
	vdrive_close_all_channels(vdrive);
	vdrive->image = NULL;
}
Example #2
0
void vdrive_detach_image(disk_image_t *image, unsigned int unit,
                         vdrive_t *vdrive)
{
    if (image == NULL) {
        return;
    }

    disk_image_detach_log(image, vdrive_log, unit);
    vdrive_close_all_channels(vdrive);
    lib_free(vdrive->bam);
    vdrive->bam = NULL;
    vdrive->image = NULL;
}
Example #3
0
static int vdrive_command_initialize(vdrive_t *vdrive)
{
    vdrive_close_all_channels(vdrive);

    if ((vdrive->image_format == VDRIVE_IMAGE_FORMAT_1581) ||
        (vdrive->image_format == VDRIVE_IMAGE_FORMAT_4000)) {
        /* reset BAM/Dir/Partition to root */
        vdrive_set_disk_geometry(vdrive);
    }

    /* Update BAM in memory.  */
    if (vdrive->image != NULL) {
        vdrive_bam_read_bam(vdrive);
    }

    return CBMDOS_IPE_OK;
}
Example #4
0
void vdrive_detach_image(disk_image_t *image, unsigned int unit,
                         vdrive_t *vdrive)
{
	if (image == NULL)
		return;

    switch(image->type) {
      case DISK_IMAGE_TYPE_D64:
        disk_image_detach_log(image, vdrive_log, unit, "D64");
        break;
      case DISK_IMAGE_TYPE_D67:
        disk_image_detach_log(image, vdrive_log, unit, "D67");
        break;
      case DISK_IMAGE_TYPE_D71:
        disk_image_detach_log(image, vdrive_log, unit, "D71");
        break;
      case DISK_IMAGE_TYPE_D81:
        disk_image_detach_log(image, vdrive_log, unit, "D81");
        break;
      case DISK_IMAGE_TYPE_D80:
        disk_image_detach_log(image, vdrive_log, unit, "D80");
        break;
      case DISK_IMAGE_TYPE_D82:
        disk_image_detach_log(image, vdrive_log, unit, "D82");
        break;
      case DISK_IMAGE_TYPE_G64:
        disk_image_detach_log(image, vdrive_log, unit, "G64");
        break;
      case DISK_IMAGE_TYPE_X64:
        disk_image_detach_log(image, vdrive_log, unit, "X64");
        break;
      default:
        return;
    }
    vdrive_close_all_channels(vdrive);
    vdrive->image = NULL;
}
Example #5
0
int vdrive_command_execute(vdrive_t *vdrive, const BYTE *buf,
                           unsigned int length)
{
    int status = CBMDOS_IPE_INVAL;
    BYTE *p, *minus;
    char *name;

    if (!length)
        return CBMDOS_IPE_OK;
    if (length > IP_MAX_COMMAND_LEN) {
        vdrive_command_set_error(vdrive, CBMDOS_IPE_LONG_LINE, 0, 0);
        return CBMDOS_IPE_LONG_LINE;
    }

    if (buf[length - 1] == 0x0d) {
        --length; /* chop CR character */
    }

    p = lib_malloc(length + 1);
    memcpy(p, buf, length);
    p[length] = 0;

    minus = (BYTE *)memchr(p, '-', length);
    name = (char *)memchr(p, ':', length);

#ifdef DEBUG_DRIVE
    log_debug("Command '%c' (%s).", *p, p);
#endif

    switch (*p) {
      case 'M':
      case 'P':
        break;          /* In binary commands, colons are data */
      default:
        if (name) {     /* Fix name length */
            length -= (BYTE *)name - p;
        }
    }

    switch (*p) {
      case 'C':         /* Copy */
        if (p[1] == 'D' && vdrive->image_format == VDRIVE_IMAGE_FORMAT_4000) {
            if (!name) { /* CD_ doesn't allow a : */
                name = (char *)(p + 1);
            }
            status = vdrive_command_chdir(vdrive, (BYTE *)name, length);
        } else {
            status = vdrive_command_copy(vdrive, (char *)name, length);
        }
        break;

      case '/':         /* change partition */
        if ((vdrive->image_format == VDRIVE_IMAGE_FORMAT_1581) ||
            (vdrive->image_format == VDRIVE_IMAGE_FORMAT_4000)) {
            if (!name) { /* handle "/dir" */
                name = (char *)(p + 1);
                --length;
            }
            status = vdrive_command_chpart(vdrive, (BYTE *)name, length);
        }
        break;

#if 0
      case 'D':         /* Duplicate is unused */
        break;
#endif

      case 'R':         /* Rename */
        status = vdrive_command_rename(vdrive, (BYTE *)name, length);
        break;

      case 'S':         /* Scratch */
        status = vdrive_command_scratch(vdrive, (BYTE *)name, length);
        break;

      case 'I':
        status = vdrive_command_initialize(vdrive);
        break;

      case 'N':
        /* Skip ":" at the start of the name.  */
        status = vdrive_command_format(vdrive,
                                       (name == NULL) ? NULL : name + 1);
        break;

      case 'V':
        status = vdrive_command_validate(vdrive);
        break;

      case 'B': /* Block, Buffer */
        if (!name)      /* B-x does not require a : */
            name = (char *)(p + 2);
        if (minus) {
            status = vdrive_command_block(vdrive, minus[1], name + 1);
        }
        break;

      case 'M': /* Memory */
        if (minus) {
            status = vdrive_command_memory(vdrive, minus + 1, length);
        }
        break;

      case 'P': /* Position */
        status = vdrive_command_position(vdrive, p, length);
        break;

      case 'U': /* User */
        if (!name) {    /* Colons are optional */
            name = (char *)(p + 1);
        }
        switch (p[1] & 0x0f) {
          case 1: /* UA */
            if (name)
                status = vdrive_command_block(vdrive, (unsigned char)0xd2, name + 1);
            break;

          case 2: /* UB */
            if (name)
                status = vdrive_command_block(vdrive, (unsigned char)0xd7, name + 1);
            break;

          case 3: /* Jumps */
          case 4:
          case 5:
          case 6:
          case 7:
          case 8:
            status = CBMDOS_IPE_NOT_READY;
            break;

          case 9: /* UI */
            if (p[2] == '-' || p[2] == '+') {
                status = CBMDOS_IPE_OK; /* Set IEC bus speed */
                break;
            }
            /* Fall through. */
          case 10: /* U:, UJ */
            vdrive_close_all_channels(vdrive); /* Warm/Cold reset */
            status = CBMDOS_IPE_DOS_VERSION;
            break;

          default: /* U0, UK..UO */
            if (p[1] == '0') {
                status = CBMDOS_IPE_OK;
                break;
            }
            status = CBMDOS_IPE_NOT_READY;
            break;
        } /* Un */
        break;

      default:
        break;
    } /* commands */

    if (status == CBMDOS_IPE_INVAL) {
        log_error(vdrive_command_log, "Wrong command `%s'.", p);
    }

    vdrive_command_set_error(vdrive, status, 0, 0);

    lib_free((char *)p);
    return status;
}