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;
Procedure ExpandFile(var fil : BinFile; var pos : Integer; pad : Integer);
procedure ExpandFile(var fil : BinFile; var pos : Integer; pad : Integer);
var
i : Integer;
begin
@ -113,6 +113,7 @@ begin
WriteByte := s;
end;
function WriteWord(bval : Integer): WStr;
var
s : WStr;

105
dump.pas
View File

@ -9,42 +9,105 @@ program dump;
{$I 'common.pas'}
procedure DumpChunk(
var src : BinFile;
var dst : Text;
var addr : Integer,
var chunk : Byte);
var
buffer : array [1 .. 16] of Byte;
type
FileChunk = Array [1 .. 16] of Byte;
procedure PrnHelp;
begin
Write(dst, WriteWord(addr));
Write(dst, ' ');
WriteLn('DUMP V1.0');
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;
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
Address : Integer;
Size : Integer;
Buffer : array [1 .. 16] of Byte;
Chunk : Byte;
Buffer : FileChunk;
Cursor : Byte;
begin
Address := 0;
Size := FileSize(src);
Chunk := IMin($10, Size);
Cursor := 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;
var
inf : BinFile;
IName : FilePath;
OName : FilePath;
Source : BinFile;
Dest : Text;
begin
Assign(inf, 'dump.bin');
Reset(inf);
IName := '';
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);
end.

View File

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

View File

@ -15,7 +15,7 @@ begin
WriteLn('');
WriteLn('Usage:');
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(' output.');
WriteLn('');
@ -77,7 +77,6 @@ var
rec : IRec;
nlc : Byte; { newline count }
i : Byte;
pos : Integer;
begin
nlc := 0;
if iname <> '' then
@ -98,10 +97,6 @@ begin
if (Line <> '') then
begin
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
Write(outf, rec.Data[i]);
nlc := 0;