(*
Simple UCSD File HEX Dump Program
Dumps the blocks of a file with leading offset
and trailing checksum byte.
Martin Hepperle, 2025
*)
Program DumpFile;
Type
String2 = String[2];
Byte = 0..255;
Nibble = 0..15;
Buffer = Packed Array[0..511] of Char;
BytePack = Packed Record
Case Integer of
0 : (b : Byte);
1 : (n0 : Nibble; n1 : Nibble);
End;
WordPack = Packed Record
Case Integer of
0 : (w : Integer);
1 : (n0 : Nibble; n1 : Nibble; n2 : Nibble; n3 : Nibble);
End;
Var
fOut : Text;
fIn : File;
fileName : String;
outDevice : String;
aByte : BytePack;
aWord : WordPack;
HexDigit : Packed Array[0..15] of Char;
daBuffer : Buffer;
addr, blk, i, col, iRet, csum : Integer;
Begin
HexDigit := '0123456789ABCDEF';
(* the name of the file to dump *)
fileName := 'FILL.TEXT';
(* write the dump to this device*)
outDevice := 'REMOUT:';
outDevice := 'CONSOLE:';
WriteLn('Dumping ',fileName,' to ',outDevice);
Reset(fIn,fileName);
Rewrite(fOut,outDevice)
WriteLn(fOut,'*FILE:',fileName);
blk := 0;
addr := 0;
While Not Eof(fIn) Do
Begin
iRet := BlockRead(fIn,daBuffer,1,blk);
blk := Succ(blk);
If iRet = 1 Then
Begin
col := 0;
csum := 0;
(* first row *)
aWord.w := addr;
Write(fOut,':',HexDigit[aWord.n3],HexDigit[aWord.n2],
HexDigit[aWord.n1],HexDigit[aWord.n0],':');
For i:=0 to 511 Do
Begin
aByte.b := Ord(daBuffer[i]);
Write(fOut,HexDigit[aByte.n1],HexDigit[aByte.n0]);
(* add and mask lower byte *)
csum := csum + aByte.b;
col := Succ(col);
(* 32 bytes per row *)
If col = 32 Then Begin
(* UCSD style: mask lower byte of checksum *)
aByte.b := Ord(Odd(csum) And Odd(255));
WriteLn(fOut,':',HexDigit[aByte.n1],HexDigit[aByte.n0]);
col := 0;
csum := 0;
addr := addr + 32;
If i < 511 Then
Begin
(* prepare start of next row *)
aWord.w := addr;
Write(fOut,':',HexDigit[aWord.n3],HexDigit[aWord.n2],
HexDigit[aWord.n1],HexDigit[aWord.n0],':');
End;
End; (* if col = 32 *)
End; (* For i := 0 *)
End; (* If iRet = 1 *)
End; (* While *)
WriteLn(fOut,'*EOF*');
Close(fIn);
Close(fOut);
End.