working dump.com.

This commit is contained in:
Kyle Isom 2023-10-03 23:07:58 -07:00
parent a60a6a3f59
commit b4210061e8
4 changed files with 89 additions and 32 deletions

View File

@ -9,7 +9,7 @@ WStr = String[4]; { String representing a u16. }
BinFile = File of Byte; BinFile = File of Byte;
Procedure ExpandFile(var fil : BinFile; var pos : Integer; pad : Integer); procedure ExpandFile(var fil : BinFile; var pos : Integer; pad : Integer);
var var
i : Integer; i : Integer;
begin begin
@ -113,6 +113,7 @@ begin
WriteByte := s; WriteByte := s;
end; end;
function WriteWord(bval : Integer): WStr; function WriteWord(bval : Integer): WStr;
var var
s : WStr; s : WStr;

105
dump.pas
View File

@ -9,42 +9,105 @@ program dump;
{$I 'common.pas'} {$I 'common.pas'}
procedure DumpChunk( type
var src : BinFile; FileChunk = Array [1 .. 16] of Byte;
var dst : Text;
var addr : Integer,
var chunk : Byte); procedure PrnHelp;
var
buffer : array [1 .. 16] of Byte;
begin begin
Write(dst, WriteWord(addr)); WriteLn('DUMP V1.0');
Write(dst, ' '); WriteLn('Hexadecimal dump binary files.');
WriteLn('');
WriteLn('Usage:');
WriteLn(' DUMP.COM SOURCE [DEST]');
WriteLn(' If only one argument is provided, DUMP will');
WriteLn(' output to the console.');
WriteLn('');
end; end;
procedure DumpFile(var src : BinFile; var dst : Text);
procedure DumpChunk(
var Dest : Text;
var Addr : Integer;
Buffer : FileChunk;
Chunk : Byte);
var
I : Byte;
begin
Write(Dest, WriteWord(Addr));
for I := 1 to Chunk do
begin
Write(Dest, ' ');
Write(Dest, WriteByte(Buffer[I]));
end;
WriteLn(Dest, '');
Addr := Addr + Chunk;
end;
procedure DumpFile(var Source : BinFile; var Dest : Text);
label finished;
const Chunk = 16;
var var
Address : Integer; Address : Integer;
Size : Integer; Size : Integer;
Buffer : array [1 .. 16] of Byte; Buffer : FileChunk;
Chunk : Byte; Cursor : Byte;
begin begin
Address := 0; Address := 0;
Size := FileSize(src); Cursor := 0;
Chunk := IMin($10, Size);
FillChar(Buffer, $10, $0); FillChar(Buffer, $10, $0);
WriteLn('Chunk: ', Chunk); while not EOF(Source) do
begin
Cursor := Cursor + 1;
Read(Source, Buffer[Cursor]);
if EOF(Source) then goto finished;
if Cursor = Chunk then
begin
DumpChunk(Dest, Address, Buffer, Chunk);
Cursor := 0;
end;
end;
finished:
if Cursor > 0 then
DumpChunk(Dest, Address, Buffer, Chunk);
Close(Dest);
end; end;
var var
inf : BinFile; IName : FilePath;
OName : FilePath;
Source : BinFile;
Dest : Text;
begin begin
Assign(inf, 'dump.bin'); IName := '';
Reset(inf); OName := '';
case ParamCount of
0 : PrnHelp;
1 : IName := ParamStr(1);
2 : begin
IName := ParamStr(1);
OName := ParamStr(2);
end;
end;
Assign(Source, IName);
Reset(Source);
if OName <> '' then
begin
Assign(Dest, OName);
Rewrite(Dest);
end else Assign(Dest, Output);
DumpFile(inf, Output); DumpFile(inf, Output);
end. end.

View File

@ -13,6 +13,4 @@ begin
begin begin
WriteLn(I, '->', WriteByte(I)); WriteLn(I, '->', WriteByte(I));
end; end;
LowVideo;
end. end.

View File

@ -15,7 +15,7 @@ begin
WriteLn(''); WriteLn('');
WriteLn('Usage:'); WriteLn('Usage:');
WriteLn(' UNDUMP.COM [-BH] [INFILE] OUTFILE'); WriteLn(' UNDUMP.COM [-BH] [INFILE] OUTFILE');
WriteLn(' If only one argumet is given, it will be assigned'); WriteLn(' If only one argument is given, it will be assigned');
WriteLn(' to the output file and input will be set to standard'); WriteLn(' to the output file and input will be set to standard');
WriteLn(' output.'); WriteLn(' output.');
WriteLn(''); WriteLn('');
@ -77,7 +77,6 @@ var
rec : IRec; rec : IRec;
nlc : Byte; { newline count } nlc : Byte; { newline count }
i : Byte; i : Byte;
pos : Integer;
begin begin
nlc := 0; nlc := 0;
if iname <> '' then if iname <> '' then
@ -98,10 +97,6 @@ begin
if (Line <> '') then if (Line <> '') then
begin begin
rec := RdDumpLn(line); rec := RdDumpLn(line);
pos := FilePos(outf);
if pos > rec.Addr then
ExpandFile(outf, pos, pos-rec.Addr);
if pos <> rec.Addr then Seek(outf, rec.Addr-pos);
for i := 1 to rec.Count do for i := 1 to rec.Count do
Write(outf, rec.Data[i]); Write(outf, rec.Data[i]);
nlc := 0; nlc := 0;