kcpmtk/undump.pas

162 lines
3.2 KiB
Plaintext

program undump;
{
undump is a program to take the output fr
and put it into binary format.
}
{$I 'common.pas'}
{$I 'binary.pas'}
{$I 'ihex.pas'}
procedure PrnHelp;
begin
WriteLn('UNDUMP V1.0');
WriteLn('Converts DUMP.COM output to Intel Hex format');
WriteLn('');
WriteLn('Usage:');
WriteLn(' UNDUMP.COM [-BH] [INFILE] OUTFILE');
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('');
WriteLn('Options:');
WriteLn(' -B : Write in binary format (the default is Intel');
WriteLn(' hex format.');
WriteLn(' -H : Show this help message.');
Halt;
end;
Procedure DumpIHex(iname, oname : FilePath);
var
inf : Text;
outf : Text;
line : LnStr;
rec : IRec;
nlc : Byte; { newline count }
begin
nlc := 0;
if iname <> '' then
begin
Assign(inf, iname);
Reset(inf);
end else inf := Input;
if oname <> '' then
begin
Assign(outf, oname);
Rewrite(outf);
end else outf := Output;
while not EOF(inf) do
begin
ReadLn(inf, line);
if (Line <> '') then
begin
rec := RdDumpLn(line);
WrRec(rec, outf);
nlc := 0;
end else nlc := nlc + 1;
if nlc > 0 then Exit;
end;
Close(inf);
Writeln(outf, IRecEOF);
Flush(outf);
Close(outf);
end;
Procedure DumpBinary(iname, oname : FilePath);
var
inf : Text;
outf : File of Byte;
line : LnStr;
rec : IRec;
nlc : Byte; { newline count }
i : Byte;
begin
nlc := 0;
if iname <> '' then
begin
Assign(inf, iname);
Reset(inf);
end else inf := Input;
if oname = '' then
PrnHelp;
Assign(outf, oname);
Rewrite(outf);
while not EOF(inf) do
begin
ReadLn(inf, line);
if (Line <> '') then
begin
rec := RdDumpLn(line);
for i := 1 to rec.Count do
Write(outf, rec.Data[i]);
nlc := 0;
end else nlc := nlc + 1;
if nlc > 0 then Exit;
end;
Close(inf);
Close(outf);
end;
var
i, argc : Integer;
opts : record
Binary : Boolean;
ShoVer : Boolean;
InFile : FilePath;
OutFile : FilePath;
end;
param : String[32];
paramc : Char;
begin
opts.Binary := False;
opts.ShoVer := False;
opts.InFile := '';
opts.OutFile := '';
argc := ParamCount;
i := 1;
param := ParamStr(i);
while param[1] = '-' do
begin
paramc := UpCase(param[2]);
case paramc of
'B': opts.Binary := True;
'H': opts.ShoVer := True;
else
PrnHelp;
end;
i := i + 1;
param := ParamStr(i);
argc := argc - 1;
end;
if opts.ShoVer then PrnHelp();
i := ParamCount - argc + 1;
if i = 1 then opts.OutFile := ParamStr(ParamCount);
if i > 1 then
begin
opts.InFile := ParamStr(i);
opts.OutFile := ParamStr(i+1);
end;
if opts.Binary then
DumpBinary(opts.InFile, opts.OutFile)
else
DumpIHex(opts.InFile, opts.OutFile);
end.