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