/* * Initiate a compare operation on a disk. */ static enum dpio_status DPDiskIOCompare(UNIT *uptr) { struct dpio_unit *iou = (struct dpio_unit *)uptr->up7; uint16 numcy = ((uptr->flags & UNIT_854) != 0) ? DP_854CY : DP_853CY; uint32 lba = DPLBA(iou); int i; if (iou->cylinder >= numcy) return DPIO_ADDRERR; /* * Report any error in the underlying container infrastructure as an * address error. */ if (sim_fseeko(uptr->fileref, lba * DP_NUMBY, SEEK_SET) || (sim_fread(iou->buf, sizeof(uint16), DP_NUMWD, uptr->fileref) != DP_NUMWD)) return DPIO_ADDRERR; for (i = 0; i < DP_NUMWD; i++) { if (iou->buf[i] != LoadFromMem(iou->CWA)) return DPIO_MISMATCH; iou->CWA++; if (iou->CWA == iou->LWA) { DPDiskIOIncSector(iou); return DPIO_DONE; } } DPDiskIOIncSector(iou); return DPIO_MORE; }
/* * Initiate a write operation on a disk. */ static enum dpio_status DPDiskIOWrite(UNIT *uptr) { struct dpio_unit *iou = (struct dpio_unit *)uptr->up7; uint16 numcy = ((uptr->flags & UNIT_854) != 0) ? DP_854CY : DP_853CY; uint32 lba = DPLBA(iou); t_bool fill = FALSE; int i; if (iou->cylinder >= numcy) return DPIO_ADDRERR; for (i = 0; i < DP_NUMWD; i++) { if (!fill) { iou->buf[i] = LoadFromMem(iou->CWA); iou->CWA++; if (iou->CWA == iou->LWA) fill = TRUE; } else iou->buf[i] = 0; } /* * Report any error in the underlying container infrastructure as an * address error. */ if (sim_fseeko(uptr->fileref, lba * DP_NUMBY, SEEK_SET) || (sim_fwrite(iou->buf, sizeof(uint16), DP_NUMWD, uptr->fileref) != DP_NUMWD)) return DPIO_ADDRERR; DPDiskIOIncSector(iou); return fill ? DPIO_DONE : DPIO_MORE; }
t_offset sim_fsize_ex (FILE *fp) { t_offset pos, sz; if (fp == NULL) return 0; pos = sim_ftell (fp); sim_fseek (fp, 0, SEEK_END); sz = sim_ftell (fp); sim_fseeko (fp, pos, SEEK_SET); return sz; }
/* Utility function to set the image type for a unit to the correct value. * Prints an error message in case a CPT image is presented and returns * SCPE_OPENERR in this case. Otherwise the return value is SCPE_OK */ t_stat assignDiskType(UNIT *uptr) { t_stat result = SCPE_OK; char header[4]; t_offset pos = sim_ftell(uptr->fileref); sim_fseek(uptr->fileref, (t_addr)0, SEEK_SET); if (fgets(header, 4, uptr->fileref) == NULL) uptr->u3 = IMAGE_TYPE_DSK; else if (strncmp(header, "IMD", 3) == 0) uptr->u3 = IMAGE_TYPE_IMD; else if(strncmp(header, "CPT", 3) == 0) { sim_printf("CPT images not yet supported.\n"); uptr->u3 = IMAGE_TYPE_CPT; result = SCPE_OPENERR; } else uptr->u3 = IMAGE_TYPE_DSK; sim_fseeko(uptr->fileref, pos, SEEK_SET); return result; }
int sim_fseek (FILE *st, t_addr offset, int whence) { return sim_fseeko (st, (t_offset)offset, whence); }