-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.pas
More file actions
66 lines (58 loc) · 2.3 KB
/
Program.pas
File metadata and controls
66 lines (58 loc) · 2.3 KB
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
namespace D64;
type
Program = class
public
class method Main(args: array of String): Int32;
begin
writeLn('Commondore D64 File Reader.');
writeLn('Created by marc hoffman.');
writeLn('Use at your own risk.');
writeLn();
if length(args) < 1 then begin
writeLn("Syntax: D64 <filename.d64> <command>");
writeLn();
writeLn("Commands:");
writeLn();
writeLn(" --dir (print directory listing)");
writeLn(" --extract-file <0-based index> <destination> (extarct file to local disk)");
writeLn();
exit 1;
end;
var lDisk := new DiskImage withFile(args[0]);
if length(args) > 1 then begin
case args[1] of
"--dir": begin
writeLn(#""0 "{lDisk.Name}" {lDisk.Directory.DOSType}"");
for each f in lDisk.Files do
writeLn(#""{f.Size} "{f.Name}" {f.FileType}"");
writeLn(#"{lDisk.Directory.FreeSectors} BLOCKS FREE ({lDisk.Directory.FreeSectors*lDisk.Format.SectorSize} BYTES)");
end;
"--files": begin
for i: Int32 := 0 to lDisk.Files.Count-1 do begin
var f := lDisk.Files[i];
&write(#""{i}: {f.Size} "{f.Name}" {if not f.Closed then "*"}{f.FileType}"");
if f.FileType in ["PRG"] then
&write(#", {f.GetBytes.Length} bytes on disk");
if f.Closed and (f.LoadAddress ≠ $0801) then
&write(#", loads to ${Convert.ToHexString(f.LoadAddress, 4)}");
writeLn();
end;
end;
"--extract-file": begin
if length(args) > 3 then begin
var lIndex := Convert.TryToInt32(args[2]);
if 0 <= lIndex < lDisk.Files.Count then begin
var lFile := lDisk.Files[lIndex];
var lBytes := lFile.GetBytes();
File.WriteBinary(args[3], lBytes);
writeLn(#"Wrote {lBytes.Length} bytes to {args[3]}");
end
else
writeLn("Invalid file index.");
end;
end;
end;
end;
end;
end;
end.