program MEM_CON(input,output,output,VSTUP,mem,desc);
    {uses crt;}
{------------------------------------------------------------------------------}
  const
    depth = 256;
    width = 8;
    default_char = ' ';
{------------------------------------------------------------------------------}
{  type
    t_line = string[16];
    t_line_sh = string[7];}
{------------------------------------------------------------------------------}
  var
    VSTUP: text;
    Mem:   text;
    Desc:  text;
    znak:  char;
    pocet_znaku:  integer;
    i:            integer;
    zacatek:      integer;
    konec:        integer;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
Begin
{------------------------------------------------------------------------------}
  
  pocet_znaku := 0;
  
  assign(VSTUP,'ROM_1.txt');
  reset(VSTUP);

  assign(mem,'ROM_1.coe');
  rewrite(mem);

  assign(desc,'ROM_1_d.txt');
  rewrite(desc);

  writeln(mem,'; Initialization file for a 8-bit wide by 256 deep RAM');
  writeln(mem,'memory_initialization_radix = 10;');
  writeln(mem,'memory_initialization_vector =');
  writeln(mem);

  writeln(desc,'COE description file');
  writeln(desc);
  write(desc,pocet_znaku);
  write(desc,', "');
  zacatek := pocet_znaku;

  while not eof(vstup) do begin
    read(VSTUP,znak);

    if ord(znak) = 13 then begin
      write(desc,'", ');
      write(desc,(pocet_znaku-zacatek));
      writeln(desc,'ch');
    end
    else begin
      if ord(znak) = 10 then begin
        zacatek := pocet_znaku;
        write(desc,pocet_znaku);
        write(desc,', "');
      end
      else begin
        write(desc,znak);
        write(mem,ord(znak));
        write(mem,' ');
        pocet_znaku := pocet_znaku + 1;
        if (pocet_znaku mod 16) = 0 then writeln(mem);
        if (pocet_znaku mod 64) = 0 then writeln(mem);
      end
    end
  end;

  write(desc,'", ');
  write(desc,(pocet_znaku-zacatek));
  writeln(desc,'ch');

  for i:= (pocet_znaku + 1) to 256 do begin
      write(mem,ord(default_char));
      write(mem,' ');
      if (i mod 16) = 0 then writeln(mem);
      if (i mod 64) = 0 then writeln(mem);
  end;

  writeln(mem);

{------------------------------------------------------------------------------}
  close(mem);
  close(desc);
  close(VSTUP);
  writeln('Done!');
  readln;
{------------------------------------------------------------------------------}
end.