diff --git a/binary.pas b/binary.pas index cb90476..46cb039 100644 --- a/binary.pas +++ b/binary.pas @@ -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 @@ -103,7 +103,7 @@ begin end; -function WriteByte(bval : Byte): BStr; +function WriteByte(bval : Byte): BStr; var s : BStr; begin @@ -113,6 +113,7 @@ begin WriteByte := s; end; + function WriteWord(bval : Integer): WStr; var s : WStr; diff --git a/dump.pas b/dump.pas index 174d912..f8a482d 100644 --- a/dump.pas +++ b/dump.pas @@ -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. \ No newline at end of file +end. diff --git a/test.pas b/test.pas index 93e5771..31e3f0f 100644 --- a/test.pas +++ b/test.pas @@ -13,6 +13,4 @@ begin begin WriteLn(I, '->', WriteByte(I)); end; - - LowVideo; end. diff --git a/undump.pas b/undump.pas index c72ca6a..49a498d 100644 --- a/undump.pas +++ b/undump.pas @@ -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;