|
|
1.1 root 1: /* 1.1.1.3 ! root 2: * Transdisk V4.2 ! 3: * Copyright 1995-97 Bernd Schmidt, Marcus Sundberg, Stefan Ropke, ! 4: * Rodney Hester, Joanne Dow 1.1 root 5: * 1.1.1.3 ! root 6: * Use DICE and 2.0 includes or above to compile. SAS C should work too. 1.1 root 7: */ 8: 9: #include <stdio.h> 1.1.1.3 ! root 10: #include <math.h> ! 11: #include <stdlib.h> ! 12: #include <strings.h> 1.1 root 13: 14: #include <exec/devices.h> 15: #include <exec/io.h> 16: #include <exec/memory.h> 17: #include <devices/trackdisk.h> 18: 19: #include <clib/alib_protos.h> 20: #include <clib/exec_protos.h> 21: 1.1.1.3 ! root 22: static void usage(void); ! 23: ! 24: static void usage(void) 1.1 root 25: { 26: fprintf(stderr, "Usage: transdisk options\n"); 27: fprintf(stderr, "Recognized options:\n"); 1.1.1.2 root 28: fprintf(stderr, "-h: Assume device is high density\n"); 1.1 root 29: fprintf(stderr, "-d device unit: Use this device instead of DF0:\n"); 30: fprintf(stderr, "-s n: Begin transfer at track n\n"); 31: fprintf(stderr, "-e n: End transfer at track n\n"); 32: fprintf(stderr, "-w filename: writes the ADF file <filename> to disk\n\n"); 33: fprintf(stderr, "Example:\n"); 34: fprintf(stderr, "transdisk >RAM:df1.adf.1 -d trackdisk 1 -s 0 -e 39\n"); 35: fprintf(stderr, "transfers the first half of the floppy in DF1: into\n"); 36: fprintf(stderr, "a file in the RAM disk.\n"); 37: fprintf(stderr, "Or:\n"); 38: fprintf(stderr, "transdisk -w test.adf\n"); 39: fprintf(stderr, "writes the ADF-file test.adf to the disk in df0:\n"); 40: } 41: 42: int main(int argc, char **argv) 43: { 44: char *filename, *openMode="rb"; 45: FILE *ADFFile; 46: int write=0; 47: struct IOStdReq *ioreq; 48: struct MsgPort *port; 49: 50: UBYTE *buffer; 51: char devicebuf[256]; 52: char *devicename = "trackdisk.device"; 53: char devicenum = 0; 54: int i; 55: int starttr = 0, endtr = 79; 1.1.1.2 root 56: int sectors = 11; 1.1 root 57: 58: for (i = 1; i < argc;) { 59: if (argv[i][0] != '-' || argv[i][2] != 0) { 60: usage(); 61: exit(1); 62: } 63: switch (argv[i][1]) { 1.1.1.2 root 64: case 'h': 65: sectors = 22; 66: i++; 67: break; 1.1 root 68: case 'd': 69: if (i+2 >= argc) { 70: usage(); 71: exit(1); 72: } 73: devicenum = atoi(argv[i+2]); 74: sprintf(devicebuf, "%s.device", argv[i+1]); 75: devicename = devicebuf; 76: i += 3; 77: break; 78: case 's': 79: if (i+1 >= argc) { 80: usage(); 81: exit(1); 82: } 83: starttr = atoi(argv[i+1]); 84: i += 2; 85: break; 86: case 'e': 87: if (i+1 >= argc) { 88: usage(); 89: exit(1); 90: } 91: endtr = atoi(argv[i+1]); 92: i += 2; 93: break; 94: case 'w': 95: if (i+1 >= argc) { 96: usage(); 97: exit(1); 98: } 99: filename=argv[i+1]; 100: write=1; 101: i += 2; 102: break; 103: default: 104: usage(); 105: exit(1); 106: } 107: } 108: fprintf(stderr,"Using %s unit %d\n", devicename, devicenum); 1.1.1.2 root 109: fprintf(stderr,"Tracks are %d sectors\n", sectors); 1.1 root 110: fprintf(stderr,"First track %d, last track %d\n", starttr, endtr); 1.1.1.2 root 111: 1.1 root 112: buffer = AllocMem(512, MEMF_CHIP); 113: if (write) { 114: ADFFile = fopen(filename,openMode); 115: 116: if (!ADFFile) { 117: fprintf(stderr,"Error while opening input file\n"); 118: exit (1); 119: } 120: } 121: 122: port = CreatePort(0, 0); 123: if (port) { 124: ioreq = CreateStdIO(port); 125: if (ioreq) { 1.1.1.3 ! root 126: if (OpenDevice(devicename, devicenum, (struct IORequest *) ioreq, 0) == 0) { 1.1 root 127: int tr, sec; 128: 129: ioreq->io_Command = write ? CMD_WRITE : CMD_READ; 130: ioreq->io_Length = 512; 131: ioreq->io_Data = buffer; 132: for (tr = starttr*2; tr < (endtr+1)*2; tr++) { 133: fprintf(stderr,"Track: %d\r",tr/2); 1.1.1.2 root 134: for (sec = 0; sec < sectors; sec++) { 1.1 root 135: fflush(stderr); 136: if (write) 137: if (fread(buffer, sizeof(UBYTE), 512, ADFFile) < 512) { 1.1.1.2 root 138: fprintf(stderr, "Error: ADF file to short?\n"); 1.1 root 139: exit(1); 140: } 1.1.1.2 root 141: ioreq->io_Offset = 512 * (tr * sectors + sec); 1.1.1.3 ! root 142: DoIO( (struct IORequest *) ioreq); 1.1 root 143: if (!write) 144: fwrite(buffer, sizeof(UBYTE), 512, stdout); 145: } 146: } 147: if (write) { /* Make sure the last track is written to disk */ 148: ioreq->io_Command = CMD_UPDATE; 1.1.1.3 ! root 149: DoIO( (struct IORequest *) ioreq); 1.1 root 150: } 151: ioreq->io_Command = TD_MOTOR; /* Turn Disk-motor off */ 152: ioreq->io_Length = 0; 1.1.1.3 ! root 153: DoIO( (struct IORequest *) ioreq); ! 154: CloseDevice( (struct IORequest *) ioreq); 1.1 root 155: } else 156: fprintf(stderr,"Unable to open %s unit %d\n", devicename, devicenum); 157: DeleteStdIO(ioreq); 158: } 1.1.1.3 ! root 159: DeletePort(port); 1.1 root 160: } 161: fprintf(stderr,"\n"); 162: FreeMem(buffer, 512); 163: if (write) 164: fclose (ADFFile); 165: return 0; 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.