-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcimg.pas
320 lines (287 loc) · 7.44 KB
/
arcimg.pas
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
uses dos,crt;
type DDTP=record
filla:array[0..2] of byte;
sectorsize:byte;
lastsector:byte;
gap:byte;
translength:byte;
sectorgap:byte;
fillbyte:byte;
fillb:word;
end;
type address_fields=record
cylinder:byte;
head:byte;
sector:byte;
bytes_per_sec:byte;
end;
var prompt,command:string;
buffer:array[1..5120] of byte;
last_buff:integer;
no_dsk,arc_disk:boolean;
pDDTP:^DDTP;
vDDTP:DDTP;
oldDDTP:pointer;
total_filesize:longint;
arc_title:string;
job:string;
outfile:file;
key:char;
AvTRACK:byte;
AvSECTOR:byte;
AvHEAD:byte;
read_result:byte;
format_result:byte;
sectors_to_read:byte;
re_read_count:byte;
numread:integer;
function upstr(s:string):string;
var i:integer;
begin
for i:=1 to length(s) do s[i]:=upcase(s[i]);
upstr:=s;
end;
procedure init_arc_dsk;
begin
asm {Init Disk system}
mov ah,0
mov dl,0
int $13
end;
getintvec($1e,oldDDTP);
pDDTP:=oldDDTP;
vDDTP:=pDDTP^;
vDDTP.sectorsize:=3; {1024 bytes}
vDDTP.lastsector:=4;
setintvec($1e,@vddtp);
last_buff:=-1;
end;
function sec_offs(vTRACK,vSECTOR,vHEAD:byte):integer;
var tmp:integer;
begin
sec_offs:=(vTRACK*10)+(vHEAD*5)+vSECTOR;
end;
function format_arc_track(vTRACK,vSECTOR,vHEAD:byte):byte;
var result:byte;
af:address_fields;
af_seg:word;
af_ofs:word;
begin
if ((vHEAD in[0,1]) and (vTRACK in[0..79]) and (vSECTOR in[0..4])) then
begin
with af do
begin
cylinder:=vTRACK;
head:=vHEAD;
sector:=vSECTOR;
bytes_per_sec:=3; {1024 byte sectors}
end;
af_seg:=seg(af); af_ofs:=ofs(af);
asm
mov ah,$05
mov al,$01
mov ch,vTRACK
mov cl,vSECTOR
mov dh,vHEAD
mov dl,0
mov es,af_seg
mov bx,af_ofs
int $13
mov result,ah
end;
end;
format_arc_track:=result;
end;
function read_arc_sectors(vSECTORS,vTRACK,vSECTOR,vHEAD:byte):byte;
var buf_seg,buf_ofs:word;
result:byte;
begin
if ((vSECTORS in[1..5]) and (vHEAD in[0,1]) and
(vTRACK in[0..79]) and (vSECTOR in[0..4])) then
begin
buf_seg:=seg(buffer[1]); buf_ofs:=ofs(buffer[1]);
asm {Read a sector}
mov ah,2
mov al,vSECTORS
mov ch,vTRACK
mov cl,vSECTOR
mov dh,vHEAD
mov dl,0
mov es,buf_seg
mov bx,buf_ofs
int $13
mov result,ah
end;
last_buff:=sec_offs(vTRACK,vSECTOR,vHEAD);
read_arc_sectors:=result;
end
else read_arc_sectors:=$ff;
end;
function write_arc_sectors(vSECTORS,vTRACK,vSECTOR,vHEAD:byte):byte;
var buf_seg,buf_ofs:word;
result:byte;
begin
if ((vSECTORS in[1..5]) and (vHEAD in[0,1]) and
(vTRACK in[0..79]) and (vSECTOR in[0..4])) then
begin
buf_seg:=seg(buffer[1]); buf_ofs:=ofs(buffer[1]);
asm {Write a sector}
mov ah,3
mov al,vSECTORS
mov ch,vTRACK
mov cl,vSECTOR
mov dh,vHEAD
mov dl,0
mov es,buf_seg
mov bx,buf_ofs
int $13
mov result,ah
end;
write_arc_sectors:=result;
end
else write_arc_sectors:=$ff;
end;
procedure done_arc_dsk;
begin
if oldDDTP<>nil then setintvec($1e,oldDDTP);
oldDDTP:=nil;
arc_disk:=false;
last_buff:=-1;
end;
function is_arc_dsk:boolean;
var result:byte;
begin
init_arc_dsk;
result:=read_arc_sectors(1,0,0,0);
if result<>128 then no_dsk:=false else no_dsk:=true;
if result=6 then result:=read_arc_sectors(1,0,0,0);
is_arc_dsk:=(result=0);
end;
procedure ver;
begin
writeln(#13#10'Archimedes disk image program for PC');
writeln('Version 1.1 - Jasper Renow-Clarke 1997,99');
end;
procedure show_syntax;
begin
ver;
writeln('Syntax :');
writeln(' ARCIMG diskimage [operation]'#13#10);
writeln(' Operations :');
writeln(' /read - Reads disk into image (Default)');
writeln(' /write - Writes disk from image');
writeln(' (Disk must be formatted already using real Archimedes)');
writeln(' /format - Formats disk (Doesnt Work !!!)');
halt;
end;
begin
if paramcount < 1 then show_syntax;
ver;
arc_disk:=false; no_dsk:=true; job:='/read';
if paramcount>1 then job:=paramstr(2);
if job='/format' then {/format}
begin
writeln('Formating Archimedes disk ... (Doesnt Work !!!)');
init_arc_dsk;
AvHEAD:=0; AvSECTOR:=0; AvTRACK:=0;
repeat
format_result:=format_arc_track(AvTRACK,AvSECTOR,AvHEAD);
inc(AvSECTOR);
if AvSECTOR=5 then
begin
AvSECTOR:=0;
inc(AvHEAD);
if AvHEAD=2 then
begin
AvHEAD:=0;
inc(AvTRACK);
if (AvTRACK>79) then AvTRACK:=255 else write(AvTRACK:3);
end;
end;
until (AvTRACK=255) or keypressed;
done_arc_dsk;
end;
if job='/write' then {/write}
if is_arc_dsk then
begin
writeln('Archimedes disk in drive A');
writeln('Writing disk from image : ',paramstr(1));
arc_disk:=true;
AvHEAD:=0; AvSECTOR:=0; AvTRACK:=0;
sectors_to_read:=5;
assign(outfile, paramstr(1));
reset(outfile,1);
{Main loop to make diskimage}
repeat
{Clear Buffer}
fillchar(buffer,sizeof(buffer),$AF);
blockread(outfile,buffer,sectors_to_read*1024,numread);
if numread>0 then
begin
read_result:=write_arc_sectors(sectors_to_read,AvTRACK,AvSECTOR,AvHEAD);
if read_result=0 then
if AvHEAD=1 then write(AvTRACK:3);
end;
inc(AvHEAD);
if AvHEAD=2 then
begin
AvHEAD:=0;
inc(AvTRACK);
if (AvTRACK>79) then AvTRACK:=255;
end;
until (AvTRACK=255) or keypressed;
close(outfile);
writeln;
writeln(#13#10'Finished writing disk from image');
end;
if job='/read' then {/read (default)}
if is_arc_dsk then
begin
writeln('Archimedes disk in drive A');
writeln('Reading image from disk : ', paramstr(1));
arc_disk:=true;
AvHEAD:=0; AvSECTOR:=0; AvTRACK:=0;
sectors_to_read:=5;
assign(outfile, paramstr(1));
rewrite(outfile,1);
{Main loop to make diskimage}
repeat
read_result:=read_arc_sectors(sectors_to_read,AvTRACK,AvSECTOR,AvHEAD);
if read_result <> 0 then {Attempt to read those 5 individualy}
begin
textcolor(red);
for re_read_count:=AvTRACK to AvTRACK+5 do
begin
read_result:=read_arc_sectors(1,re_read_count,AvSECTOR,AvHEAD);
if read_result=0 then
blockwrite(outfile,buffer,1024)
else
write(re_read_count:3);
end;
textcolor(lightgray); writeln;
end
else
begin
if AvHEAD=1 then write(AvTRACK:3);
blockwrite(outfile,buffer,sectors_to_read*1024);
end;
inc(AvHEAD);
if AvHEAD=2 then
begin
AvHEAD:=0;
inc(AvTRACK);
if (AvTRACK>79) then AvTRACK:=255;
end;
until (AvTRACK=255) or keypressed;
close(outfile);
writeln;
writeln(#13#10'Finished reading image from disk');
end
else
begin
writeln('Not an Archimedes disk');
done_arc_dsk;
end;
if no_dsk then writeln('No disk in drive A');
if arc_disk then done_arc_dsk;
end.