VAR
   fo : TEXT;
   fi : FILE;
   buf : ARRAY [1..1024] OF BYTE;
   rez : INTEGER;

   nfi: STRING;
   i, j, k  : INTEGER;


CONST
   bc : INTEGER = 0;
   POMOC: BYTE = 2;

PROCEDURE DoNum(b: BYTE);label skip;BEGIN

   IF bc = 0 THEN BEGIN
      if POMOC=0 then WriteLn(fo);
      if POMOC=1 then WriteLn(fo,'"');
      POMOC:=0;
      if (b=10) or (b=13) then begin Write(fo,' DB ',b,',');Goto skip end;
      if b<>ord('"') then begin Write(fo, ' DB "', chr(b));POMOC:=1; end else Write(fo, ' DB ',b,',');
   END ELSE BEGIN
      if (POMOC=0) and (b<>10) and (b<>13) and (b<>ord('"')) then Write(fo,'"');
      if (POMOC=1) and ((b=10) or (b=13) or (b=ord('"'))) then Write(fo,'",');
      POMOC:=0;
      if (b=10) or (b=13) then begin Write(fo,b,',');Goto skip end;
      if b<>ord('"') then begin Write(fo,chr(b));POMOC:=1; end else Write(fo,b,',');
   END;

skip:
   bc := (bc + 1) MOD 74;
END;

BEGIN
   IF ParamCount <> 2 THEN BEGIN
      WriteLn('Binary file to ASM/TP ASM source converter by Chris.');
      WriteLn('   Usage: BIN_ASM <infile> <outfile>');
      HALT
   END;
   nfi := ParamStr(1);
   Assign(fo, ParamStr(2));
   ReWrite(fo);
   WriteLn(fo, ';(*----- File created with BIN_ASM from file ', nfi, '. -----*)');
   WriteLn(fo);
   Assign(fi, nfi);
{$I-}
   Reset(fi,1);
{$I+}
   if IOResult = 0 then
     Writeln('File size in bytes: ', FileSize(fi))
   else begin
     Writeln('File ',nfi,' not found');
     Halt;
   end;
   REPEAT
      BlockRead(fi, buf, Sizeof(buf), rez);
      IF rez <> 0 THEN FOR i := 1 TO rez DO DoNum(buf[i]);
   UNTIL rez = 0;
   Close(fi);
   IF buf[i]<>ord('"') then WriteLn(fo,'"') else WriteLn(fo);
   Close(fo)
END.


