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