STDMETHODIMP CDisk::apform(IGeometry *g, long cylinder, short head, short filler) { HRESULT hr; DSK_GEOMETRY geom; g_to_dg(g, &geom); hr = MapError(dsk_apform(m_driver, &geom, cylinder, head, (unsigned char)filler)); dg_to_g(&geom, g); return hr; }
int do_format(char *outfile, char *outtyp, char *outcomp, int forcehead, dsk_format_t format) { DSK_PDRIVER outdr = NULL; dsk_err_t e; dsk_pcyl_t cyl; dsk_phead_t head; DSK_GEOMETRY dg; dsk_cchar_t fdesc; dsk_reportfunc_set(report, report_end); e = dsk_creat(&outdr, outfile, outtyp, outcomp); if (!e) e = dsk_set_retry(outdr, retries); if (!e && forcehead >= 0) e = dsk_set_forcehead(outdr, forcehead); if (!e) e = dg_stdformat(&dg, format, NULL, &fdesc); if (!e) { printf("Formatting %s as %s\n", outfile, fdesc); for (cyl = 0; cyl < dg.dg_cylinders; cyl++) { for (head = 0; head < dg.dg_heads; head++) { printf("Cyl %02d/%02d Head %d/%d\r", cyl +1, dg.dg_cylinders, head+1, dg.dg_heads); fflush(stdout); if (!e) e = dsk_apform(outdr, &dg, cyl, head, 0xE5); if (e) break; } } } /* Create a disc spec on the first sector, if the format's recognised */ if (!e) { unsigned char bootsec[512]; unsigned int do_bootsec = 0; memset(bootsec, 0xE5, sizeof(bootsec)); switch(format) { case FMT_180K: memcpy(bootsec, spec180, 10); do_bootsec = 1; break; case FMT_CPCSYS: memcpy(bootsec, spec169, 10); do_bootsec = 1; break; case FMT_CPCDATA: break; case FMT_200K: memcpy(bootsec, spec200, 10); do_bootsec = 1; break; case FMT_720K: memcpy(bootsec, spec720, 10); do_bootsec = 1; break; case FMT_800K: memcpy(bootsec, spec800, 10); do_bootsec = 1; break; default: break; } if (do_bootsec) e = dsk_lwrite(outdr, &dg, bootsec, 0); } printf("\r \r"); if (outdr) dsk_close(&outdr); if (e) { fprintf(stderr, "%s\n", dsk_strerror(e)); return 1; } return 0; }
int main(int argc, char *argv[]) { FILE *fp; struct disk_side *sides, *curr_side; struct disk_track *curr_track; struct disk_sector *curr_sector; DSK_GEOMETRY geom; DSK_PDRIVER newdisk; DSK_FORMAT *format; dsk_err_t err; int i; char *secdata; if (argc != 3) { fprintf(stderr, "usage: %s infile outfile\n", argv[0]); exit(1); } fp = fopen(argv[1], "r"); if (fp == NULL) { fprintf(stderr, "unable to open file: %s\n", argv[1]); exit(1); } sides = parse_image(fp); memset(&geom, 0, sizeof(DSK_GEOMETRY)); geom.dg_cylinders = max_tracks; geom.dg_heads = max_sides; geom.dg_sectors = max_sectors; geom.dg_secbase = 1; /* perhaps this should be determined from file? */ geom.dg_secsize = sector_size; format = malloc(geom.dg_sectors*sizeof(DSK_FORMAT)); secdata = malloc(geom.dg_secsize); if ((format == NULL) || (secdata == NULL)) { fprintf(stderr, "main: out of memory\n"); exit(1); } if (dsk_creat(&newdisk, argv[2], "dsk", NULL) != DSK_ERR_OK) { fprintf(stderr, "main: error in dsk_creat\n"); exit(1); } for (i=0; i<max_sides; i++) if (dsk_apform(newdisk, &geom, 0, i, 0xE5) != DSK_ERR_OK) { fprintf(stderr, "main: error formatting inital cylinder\n"); exit(1); } curr_side = sides; while (curr_side != NULL) { /* printf("Side = %i\n", curr_side->id); */ curr_track = curr_side->tracks; while (curr_track != NULL) { /*printf(" Track = %i\n", curr_track->id); */ curr_sector = curr_track->sectors; i = 0; while (curr_sector != NULL) { /* printf(" Sector = %i\n", curr_sector->id);*/ format[i].fmt_cylinder = curr_sector->logical_track; format[i].fmt_head = curr_sector->logical_side; format[i].fmt_sector = curr_sector->id; format[i].fmt_secsize = curr_sector->length; curr_sector = curr_sector->next; i++; } if ((err = dsk_pformat(newdisk, &geom, curr_track->id, curr_side->id, format, 0xE5)) != DSK_ERR_OK) { fprintf(stderr, "main: error in dsk_pformat(%i)\n", err); exit(1); } curr_sector = curr_track->sectors; while (curr_sector != NULL) { fseek(fp, curr_sector->ofs, SEEK_SET); if (fread(secdata, 1, curr_sector->length, fp) != curr_sector->length) { fprintf(stderr, "main: error reading input file sector\n"); exit(1); } if ((err = dsk_xwrite(newdisk, &geom, secdata, curr_track->id, curr_side->id, curr_sector->logical_track, curr_sector->logical_side, curr_sector->id, curr_sector->length, 0)) != DSK_ERR_OK) { fprintf(stderr, "main: error in dsk_pwrite (%i, sec=%i, side=%i, track=%i) \n", err, curr_sector->id, curr_sector->logical_side, curr_sector->logical_track); exit(1); } curr_sector = curr_sector->next; } curr_track = curr_track->next; } curr_side = curr_side->next; } printf("Sides: %2i Tracks: %2i Sectors: %2i\n", max_sides, max_tracks, max_sectors); dsk_close(&newdisk); fclose(fp); return 0; }
int do_test(char *outfile, char *outtyp, char *outcomp, int forcehead) { DSK_PDRIVER outdr = NULL; dsk_err_t e; DSK_GEOMETRY dg, dg2; static DSK_FORMAT fmt[9] = { { 0, 0, 1, 512 }, { 0, 0, 3, 512 }, { 3, 1, 5, 512 }, { 0, 0, 7, 512 }, { 0, 0, 9, 512 }, { 0, 1, 2, 512 }, { 0, 0, 4, 512 }, { 2, 0, 6, 512 }, { 0, 0, 8, 512 }, }; static DSK_FORMAT fmt2[9] = { { 4, 0, 1, 512 }, { 4, 0, 3, 512 }, { 4, 0, 5, 512 }, { 4, 0, 7, 512 }, { 4, 0, 9, 512 }, { 4, 0, 2, 512 }, { 4, 0, 4, 512 }, { 4, 0, 6, 512 }, { 4, 0, 8, 512 }, }; DSK_FORMAT secid, *pfmt; char *comment; unsigned char status; dsk_psect_t count, n; char *optname; int value; dsk_reportfunc_set(report, report_end); dg_stdformat(&dg, FMT_180K, NULL, NULL); if (t80) dg.dg_cylinders = 80; printf("Checking dsk_creat\n"); e = dsk_creat(&outdr, outfile, outtyp, outcomp); CHECKERR("dsk_creat") else { dsk_set_option(outdr, "REMOTE:TESTING", 1); printf("Checking set_comment\n"); e = dsk_set_comment(outdr, "Example comment"); CHECKERR3("dsk_set_comment"); printf("Checking pformat\n"); e = dsk_pformat(outdr, &dg, 0, 0, fmt, 0xE5); CHECKERR("dsk_pformat") printf("Checking apform\n"); e = dsk_apform(outdr, &dg, 1, 0, 0xF6); CHECKERR("dsk_apform") printf("Checking lformat\n"); e = dsk_lformat(outdr, &dg, 2, fmt2, 0xD4); CHECKERR("dsk_pformat") printf("Checking ptrackids\n"); e = dsk_ptrackids(outdr, &dg, 0, 0, &count, &pfmt); CHECKERR("dsk_ptrackids") else { dsk_psect_t n; printf("Cyl Head Sec Size\n"); printf("-----------------\n"); for (n = 0; n < count; n++) { printf("%3d %3d %3d %4d\n", pfmt[n].fmt_cylinder, pfmt[n].fmt_head, pfmt[n].fmt_sector, (int)pfmt[n].fmt_secsize); } printf("-----------------\n"); dsk_free(pfmt); } memset(secbuf, 0, sizeof(secbuf)); memcpy(secbuf, spec180, sizeof(spec180)); printf("Checking dsk_lwrite\n"); e = dsk_lwrite(outdr, &dg, secbuf, 0); CHECKERR("dsk_lwrite") strcpy((char *)secbuf, "Cyl=3 Head=1 Sec=5"); printf("Checking dsk_xwrite\n"); e = dsk_xwrite(outdr, &dg, secbuf, 0, 0, 3, 1, 5, 512, 0); CHECKERR("dsk_xwrite") printf("Checking dsk_psecid\n"); e = dsk_psecid(outdr, &dg, 1, 0, &secid); CHECKERR("dsk_psecid") else { printf("%3d %3d %3d %4d\n", secid.fmt_cylinder, secid.fmt_head, secid.fmt_sector, (int)secid.fmt_secsize); if (secid.fmt_cylinder != 1 || secid.fmt_head != 0 || secid.fmt_secsize != 512) { ++failures; printf("-- mismatch!\n"); } } } if (outdr) { dsk_close(&outdr); CHECKERR("dsk_close") } printf("Checking dsk_open\n"); e = dsk_open(&outdr, outfile, outtyp, outcomp); CHECKERR("dsk_open") else { dsk_set_option(outdr, "REMOTE:TESTING", 1); printf("Checking dsk_getgeom\n"); e = dsk_getgeom(outdr, &dg2); if (t80 && dg2.dg_cylinders == 40) dg2.dg_cylinders = 80; CHECKERR("dsk_getgeom") else if (memcmp(&dg, &dg2, sizeof(dg))) { ++failures; printf("-- mismatch!\n"); printf("Cyls: %3d %3d\n", dg.dg_cylinders, dg2.dg_cylinders); printf("Heads: %3d %3d\n", dg.dg_heads, dg2.dg_heads); printf("Secs: %3d %3d\n", dg.dg_sectors, dg2.dg_sectors); } printf("Checking dsk_lread\n"); e = dsk_lread(outdr, &dg, secbuf, 0); CHECKERR("dsk_lread") else if (memcmp(secbuf, spec180, sizeof(spec180))) { ++failures; printf("-- mismatch!\n"); } printf("Checking dsk_xread\n"); e = dsk_xread(outdr, &dg, secbuf, 0, 0, 3, 1, 5, 512, NULL); CHECKERR("dsk_xread") else if (strcmp((char *)secbuf, "Cyl=3 Head=1 Sec=5")) { ++failures; printf("-- mismatch!\n"); } printf("Checking dsk_lseek\n"); e = dsk_lseek(outdr, &dg, 1); CHECKERR("dsk_lseek") printf("Checking dsk_drive_status\n"); e = dsk_drive_status(outdr, &dg, 0, &status); CHECKERR("dsk_drive_status") else printf("-- status=0x%02x\n", status); printf("Checking dsk_tread\n"); e = dsk_ptread(outdr, &dg, trkbuf, 1, 0); CHECKERR("dsk_ptread") else { for (n = 0; n < 4608; n++) if (trkbuf[n] != 0xF6) { printf("-- mismatch!\n"); ++failures; break; } } printf("Checking dsk_xtread\n"); e = dsk_xtread(outdr, &dg, trkbuf, 2, 0, 4, 0); CHECKERR("dsk_xtread") else { for (n = 0; n < 4608; n++) if (trkbuf[n] != 0xD4) { printf("-- mismatch!\n"); ++failures; break; } } printf("Checking dsk_option_enum\n"); e = dsk_option_enum(outdr, 0, &optname); CHECKERR("dsk_option_enum") else { printf("-- first option is %s\n", optname); } if (!optname) optname = "dummy"; printf("Checking dsk_get_option(%s)\n", optname); e = dsk_get_option(outdr, optname, &value); CHECKERR2("dsk_get_option") else { printf("-- value=%d\n", value); } printf("Checking dsk_set_option(example, 2)\n"); e = dsk_set_option(outdr, "example", 2); CHECKERR2("dsk_set_option") printf("Checking dsk_rtread\n"); e = dsk_rtread(outdr, &dg, trkbuf, 0, 0, 0); CHECKERR3("dsk_rtread") printf("Checking dsk_get_comment\n"); e = dsk_get_comment(outdr, &comment); CHECKERR3("dsk_get_comment") else if (comment) printf("-- comment=%s\n", comment); } if (outdr) { dsk_close(&outdr); CHECKERR("dsk_close") } printf("\n"); printf("Failed calls (failure important): %2d\n", failures); printf("Failed calls (failure unimportant): %2d\n", warnings); printf("Unimplemented functions: %2d\n", unimpl); printf("Unimplemented functions over RPC: %2d\n", rpcunimp); return failures; }