Ejemplo n.º 1
0
Archivo: mfdc.c Proyecto: ProtoSD/simh
/* Detach routine */
t_stat mfdc_detach(UNIT *uptr)
{
    t_stat r;
    int8 i;

    for(i = 0; i < MFDC_MAX_DRIVES; i++) {
        if(mfdc_dev.units[i].fileref == uptr->fileref) {
            break;
        }
    }

    if (i >= MFDC_MAX_DRIVES)
        return SCPE_ARG;

    DBG_PRINT(("Detach MFDC%d\n", i));
    r = diskClose(&mfdc_info->drive[i].imd);
    if (r != SCPE_OK)
        return r;

    r = detach_unit(uptr);  /* detach unit */
    if (r != SCPE_OK)
        return r;

    return SCPE_OK;
}
Ejemplo n.º 2
0
static t_stat hdsk_detach(UNIT *uptr) {
    t_stat result;
    int32 unitIndex;
    if (uptr == NULL)
        return SCPE_IERR;
    if (is_imd(uptr)) {
        unitIndex = find_unit_index(uptr);
        if (unitIndex == -1)
            return SCPE_IERR;
        assert((0 <= unitIndex) && (unitIndex < HDSK_NUMBER));
        diskClose(&hdsk_imd[unitIndex]);
    }
    result = detach_unit(uptr);
    uptr -> capac = HDSK_CAPACITY;
    uptr -> HDSK_FORMAT_TYPE = 0;
    uptr -> HDSK_SECTOR_SIZE = 0;
    uptr -> HDSK_SECTORS_PER_TRACK = 0;
    uptr -> HDSK_NUMBER_OF_TRACKS = 0;
    return result;
}
Ejemplo n.º 3
0
/* Detach routine */
static t_stat vfdhd_detach(UNIT *uptr)
{
    t_stat r;
    int8 i;

    for(i = 0; i < VFDHD_MAX_DRIVES; i++) {
        if(vfdhd_dev.units[i].fileref == uptr->fileref) {
            break;
        }
    }

    DBG_PRINT(("Detach VFDHD%d\n", i));
    r = diskClose(&vfdhd_info->drive[i].imd);
    if (r != SCPE_OK)
        return r;

    r = detach_unit(uptr);  /* detach unit */
    if (r != SCPE_OK)
        return r;

    return SCPE_OK;
}
Ejemplo n.º 4
0
/* Detach routine */
t_stat i8272_detach(UNIT *uptr)
{
    t_stat r;
    int8 i;

    i = find_unit_index(uptr);

    if (i == -1) {
        return (SCPE_IERR);
    }

    DBG_PRINT(("Detach I8272%d\n", i));
    r = diskClose(&i8272_info->drive[i].imd);
    i8272_info->drive[i].ready = 0;
    if (r != SCPE_OK)
        return r;

    r = detach_unit(uptr);  /* detach unit */
    if (r != SCPE_OK)
        return r;

    return SCPE_OK;
}
Ejemplo n.º 5
0
/* Detach routine */
t_stat wd179x_detach(UNIT *uptr)
{
    t_stat r;
    int8 i;

    i = find_unit_index(uptr);

    if (i == -1) {
        return SCPE_IERR;
    }

    DBG_PRINT(("Detach WD179X%d\n", i));
    r = diskClose(&wd179x_info->drive[i].imd);
    wd179x_info->drive[i].ready = 0;
    if (r != SCPE_OK)
        return r;

    r = detach_unit(uptr);  /* detach unit */
    if (r != SCPE_OK)
        return r;

    return SCPE_OK;
}
Ejemplo n.º 6
0
/*
 * Create an ImageDisk (IMD) file.  This function just creates the comment header, and allows
 * the user to enter a comment.  After the IMD is created, it must be formatted with a format
 * program on the simulated operating system, ie CP/M, CDOS, 86-DOS.
 *
 * If the IMD file already exists, the user will be given the option of overwriting it.
 */
t_stat diskCreate(FILE *fileref, const char *ctlr_comment)
{
    DISK_INFO *myDisk = NULL;
    char *comment;
    char *curptr;
    char *result;
    uint8 answer;
    int32 len, remaining;

    if(fileref == NULL) {
        return (SCPE_OPENERR);
    }

    if(sim_fsize(fileref) != 0) {
        sim_printf("SIM_IMD: Disk image already has data, do you want to overwrite it? ");
        answer = getchar();

        if((answer != 'y') && (answer != 'Y')) {
            return (SCPE_OPENERR);
        }
    }

    if((curptr = comment = (char *)calloc(1, MAX_COMMENT_LEN)) == 0) {
        sim_printf("Memory allocation failure.\n");
        return (SCPE_MEM);
    }

    sim_printf("SIM_IMD: Enter a comment for this disk.\n"
               "SIM_IMD: Terminate with a '.' on an otherwise blank line.\n");
    remaining = MAX_COMMENT_LEN;
    do {
        sim_printf("IMD> ");
        result = fgets(curptr, remaining - 3, stdin);
        if ((result == NULL) || (strcmp(curptr, ".\n") == 0)) {
            remaining = 0;
        } else {
            len = strlen(curptr) - 1;
            if (curptr[len] != '\n')
                len++;
            remaining -= len;
            curptr += len;
            *curptr++ = 0x0d;
            *curptr++ = 0x0a;
        }
    } while (remaining > 4);
    *curptr = 0x00;

    /* rewind to the beginning of the file. */
    rewind(fileref);

    /* Erase the contents of the IMD file in case we are overwriting an existing image. */
    if (sim_set_fsize(fileref, (t_addr)ftell (fileref)) == -1) {
        sim_printf("SIM_IMD: Error overwriting disk image.\n");
        return(SCPE_OPENERR);
    }

    fprintf(fileref, "IMD SIMH %s %s\n", __DATE__, __TIME__);
    fputs(comment, fileref);
    free(comment);
    fprintf(fileref, "\n\n$Id: sim_imd.c 1999 2008-07-22 04:25:28Z hharte $\n");
    fprintf(fileref, "%s\n", ctlr_comment);
    fputc(0x1A, fileref); /* EOF marker for IMD comment. */
    fflush(fileref);

    if((myDisk = diskOpen(fileref, 0)) == NULL) {
        sim_printf("SIM_IMD: Error opening disk for format.\n");
        return(SCPE_OPENERR);
    }

    if(diskFormat(myDisk) != SCPE_OK) {
        sim_printf("SIM_IMD: error formatting disk.\n");
    }

    return diskClose(&myDisk);
}