
program playRCV;
uses crt,gfx3;

var l1,l2:integer;
     f:text;


procedure rnframe(where:word);
var w1,w2:word;
    c1,c2,loop:byte;
    ch:char;

begin
{  assign(f,s);
  reset(f);}
  w1:=0;
  repeat
    read(f,ch);
    c1:=ord(ch);
    if c1=64 then begin
      read(f,ch);
      loop:=ord(ch);
      if loop<254 then
      loop:=loop+1;
      read(f,ch);
      c1:=ord(ch);
      if w1+loop>63999 then loop:=63999-w1;
      for w2:=w1 to w1+loop do begin
         if c1<>128 then
         mem[where:w2]:=c1+random(1);
      end;
    end
    else begin
      loop:=1;
      if c1<>128 then
      mem[where:w1]:=c1;
   end;
    w1:=w1+loop;
  until w1>63998;
end;

procedure readpal;
var r,g,b:byte;
ch:char;
begin
  for l1:=1 to 255 do begin
     read(f,ch);
     r:=ord(ch);

     read(f,ch);
     g:=ord(ch);

     read(f,ch);
     b:=ord(ch);
     pal(l1,r,g,b);
  end;
end;

procedure showvid(w:word;tpf:integer);
var l1,count:integer;
    sticks:longint;
    f:text;

procedure rnframe(where:word);
var w1,w2:word;
    c1,c2,loop:byte;
    ch:char;

begin
{  assign(f,s);
  reset(f);}
  w1:=0;
  repeat
    read(f,ch);
    c1:=ord(ch);
    if c1=64 then begin
      read(f,ch);
      loop:=ord(ch);
      if loop<254 then
      loop:=loop+1;
      read(f,ch);
      c1:=ord(ch);
      if w1+loop>63999 then loop:=63999-w1;
      for w2:=w1 to w1+loop do begin
         if c1<>128 then
         mem[where:w2]:=c1+random(1);
      end;
    end
    else begin
      loop:=1;
      if c1<>128 then
      mem[where:w1]:=c1;
   end;
    w1:=w1+loop;
  until w1>63998;
end;

procedure readpal;
var r,g,b:byte;
    l1:integer;f
ch:char;
begin
  for l1:=1 to 255 do begin
     read(f,ch);
     r:=ord(ch);

     read(f,ch);
     g:=ord(ch);

     read(f,ch);
     b:=ord(ch);
     pal(l1,r,g,b);
  end;
end;


begin
  assign(f,'desol.rcv');
  reset(f);
  readpal;
  sticks:=ticks;
  count:=1;
  repeat
{    inc(count);}
    l2:=ticks;
    if l2>count*tpf+sticks  then begin
         inc(count);
         rnframe(w);
         flip(w,sega000);
     end;
    if eof(f) then begin
       reset(f);
       readpal;
    end;
 until keypressed;
 close(f);
end;



begin
  setmcga;
  setupvirtual;
  showvid(vaddr,5);
  settext;
end.