-
Notifications
You must be signed in to change notification settings - Fork 0
/
DI.PAS
321 lines (290 loc) · 7.94 KB
/
DI.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
321
{ 1.44MB floppy holds 18 sectors/track - totally 80 tracks/side, doublesided }
const
driveNo : byte = 0;
sfxImage : boolean = false;
imaSfx : boolean = false;
var
imageFile : string;
driveName : string;
buf : array[1..512*18] of char;
f : file;
side, track, sector, res : byte;
y : integer;
c : char;
function ucase(s : string) : string;
var
x : byte;
begin
for x := 1 to length(s) do
s[x] := upcase(s[x]);
ucase := s;
end;
function readkey : char; assembler;
asm
mov ah, 0
int 16h
end;
procedure gotoxy(x, y : byte); assembler;
asm
mov ah, 2 (* function *)
mov dh, y (* row *)
mov dl, x (* column *)
dec dh
dec dl
mov bh, 0 (* page *)
int 10h (* execute *)
end;
function wherex : byte; assembler;
asm
mov ah, 3 (* function *)
mov bh, 0 (* page *)
int 10h (* run *)
inc dl
mov al, dl (* return *)
end;
function wherey : byte; assembler;
asm
mov ah, 3 (* function *)
mov bh, 0 (* page *)
int 10h (* run *)
inc dh
mov al, dh (* return *)
end;
function split(path : string) : string;
var
x : integer;
s : string;
begin
s := '';
for x := length(path) downto 1 do begin
if (path[x] = '\') or (path[x] = '/') then break;
s := path[x] + s;
end;
split := s;
end;
function int2str(i : integer) : string;
var
s : string;
begin
str(i, s);
int2str := s;
end;
function one(s : string) : char;
begin
one := s[1];
end;
function sect(op, side, track, sect : byte) : byte; assembler;
asm
lea bx, buf (* es:bx point to our buffer *)
mov ax, ds
mov es, ax
mov ah, op (* read/write *)
mov al, 18 (* sectorcount *)
mov dl, driveNo (* drive *)
mov dh, side (* side (1 or 0) *)
mov ch, track (* track *)
mov cl, sect (* sector *)
int 13h
mov al, 0
jnc @end
mov al, ah
@end:
end;
procedure doRestore;
label
restoreResume;
begin
writeln('Restoring Image ''' + ucase(split(imageFile)) + '''');
assign(f, imageFile);
reset(f, 1);
if imaSfx = true then begin
seek(f, filesize(f) - 80*2*18*512);
end;
write('Restoring ' + driveName + ', ');
for track := 0 to 79 do begin
for side := 0 to 1 do begin
gotoxy(15, wherey);
write('Head ' + int2str(side) + ', Track ' + int2str(track) + ', Sector #1-18');
sector := 1;
while sector < 19 do begin
blockread(f, buf, sizeof(buf));
res := Sect(3, side, track, sector);
if res <> 0 then begin
{ error... try 3 times... }
for y := 1 to 3 do begin
asm { reset diskdrive }
mov ah, 0
int 13h
end;
if sect(3, side, track, sector) = 0 then goto restoreResume;
end;
writeln;
writeln('Error #' + int2str(res) + ', Aborting');
close(f);
exit;
end;
restoreResume:
sector := sector + 18;
end;
end;
end;
close(f);
gotoxy(1, wherey);
write('==> 100% ' + ucase(split(imageFile)));
while wherex <> 80 do write(' ');
writeln;
end;
procedure doImage;
label
imageResume;
var
numRead, numWritten : word;
j : file;
begin
if sfxImage = true then begin
if pos('.', split(imageFile)) = 0 then
imageFile := imageFile + '.EXE';
end else
if pos('.', split(imageFile)) = 0 then
imageFile := imageFile + '.IMG';
writeln('Creating Image ''' + ucase(split(imageFile)) + '''');
assign(f, imageFile);
rewrite(f, 1);
if sfxImage = true then begin
write('Building SFX Header...');
assign(j, paramStr(0));
reset(j, 1);
repeat
blockRead(j, buf, sizeOf(Buf), numRead);
blockWrite(f, buf, numRead, numWritten);
until (numRead = 0) or (numWritten <> numRead);
close(j);
writeln(' OK');
end;
write('Imaging ' + driveName + ', ');
for track := 0 to 79 do begin
for side := 0 to 1 do begin
gotoxy(13, wherey);
write('Head ' + int2str(side) + ', Track ' + int2str(track) + ', Sector #1-18');
sector := 1;
while sector < 19 do begin
res := Sect(2, side, track, sector);
if res <> 0 then begin
{ error... try 3 times... }
for y := 1 to 3 do begin
asm { reset diskdrive }
mov ah, 0
int 13h
end;
if sect(2, side, track, sector) = 0 then goto imageResume;
end;
writeln;
writeln('Error #' + int2str(res) + ', Aborting');
close(f);
exit;
end;
imageResume:
blockwrite(f, buf, sizeof(buf));
sector := sector + 18;
end;
end;
end;
close(f);
gotoxy(1, wherey);
write('==> 100% ' + ucase(split(imageFile)));
while wherex <> 80 do write(' ');
writeln;
end;
procedure doHelp;
begin
writeln('DI [/R] [/S] [Drive] [Filename]');
writeln;
writeln(' [Drive] Source or Destination diskdrive');
writeln(' [Filename] Name of file to create or read');
writeln(' /R Restore [Filename] to [Drive]');
writeln(' /S Create SelF-eXtracting image (.EXE)');
end;
begin
if wherex <> 1 then writeln;
write('DiskImager 1.1, Copyright (C) 1999 by Port Jackson Computing');
imaSfx := false;
imageFile := '';
driveName := '';
assign(f, paramStr(0));
reset(f, 1);
if (fileSize(f) > 15668) then begin
writeln(' - SFX Image');
imaSfx := true;
end else writeln;
close(f);
writeln;
{ find drive }
for y := 1 to paramCount do begin
if ucase(paramStr(y)) = 'A:' then begin
driveName := 'A:';
driveNo := 0;
break;
end;
if ucase(paramStr(y)) = 'B:' then begin
driveName := 'B:';
driveNo := 1;
break;
end;
end;
if (imaSfx = true) and (driveName = '') then begin
{ we are a sfx archive & the user didnt specify destination }
write('Drive where to Restore Image: ');
c := readkey;
if (upcase(c) = 'A') then begin
writeln('A:');
driveName := 'A:';
driveNo := 0;
end;
if (upcase(c) = 'B') then begin
writeln('B:');
driveName := 'B:';
driveNo := 0;
end;
if (driveName = '') then begin
writeln(split(paramStr(0)) + ' [Drive to Restore Image to]');
exit;
end;
end;
if (imaSfx = true) then begin
{ im a sfx, the user has specified the destination }
imageFile := paramStr(0);
doRestore;
exit;
end;
{ find filename }
for y := 1 to paramCount do begin
if (ucase(paramStr(y)) <> 'A:') and (ucase(paramStr(y)) <> 'B:')
and (one(paramStr(y)) <> '/') then begin
imageFile := paramStr(y);
break;
end;
end;
{ check parameters }
for y := 1 to paramCount do begin
if (ucase(paramStr(y)) = '/R') then begin
if (imageFile <> '') and (driveName <> '') then begin
doRestore;
exit;
end else begin
doHelp;
exit;
end;
end;
end;
for y := 1 to paramCount do begin
if (ucase(paramStr(y)) = '/S') then begin
sfxImage := true;
break;
end;
end;
if (imageFile <> '') and (driveName <> '') then begin
doImage;
exit;
end;
doHelp;
end.