Uses crt,dos,colorsel;
Type mytype=record
             x1,y1,x2,y2:integer;
             index:byte;
            end;
Var i,j,k,l:integer;
    r:registers;
    mas:array[1..1250] of mytype;
    f:text;
    st:string;
    coordx,coordy,color,bx:integer;
Procedure putpixelxy(x,y,color:integer);
var count1:longint;
 begin
  count1:=y*320+x;
  mem[$a000:count1+0000]:=color;
 end;

{Procedure contur(var x,y,color:integer);
var xs,xy:integer;
begin
 xs:=x;ys:=y;
 For i:= 1 to i do
  begin
   If (x>=mas[i].x1) and (x<=mas[i].x2) and
      (y>=mas[i].y1) and (y<=mas[i].y2) and (mas[i].index=color) then
    begin
     xs:=mas[i].x1;
     ys:=mas[i].y1;
    end;
  end;
 If (xs<>x) and (ys<>y) then
  contur(x,y,color)
 else
  begin

  end;

end;}
Begin
 st:=paramstr(1);
 Assign(f,st);
 Reset(f);
 readln(f,st);
 i:=0;
 While not(eof(f)) do
  begin
   Inc(i);
   Read(f,mas[i].index);
   Read(f,mas[i].x1);
   Read(f,mas[i].y1);
   Read(f,mas[i].x2);
   Read(f,mas[i].y2);
  end;
 r.ax:=$0000;
 Intr($33,r);
 If r.ax=$0000 then
  begin
   WriteLn('Sorry, but driver for mouse not installed');
   halt;
  end;
 r.ah:=$00;
 r.al:=$13;
 Intr($10,r);
 For j:= 1 to 239 do
  begin
   r.ax:=$1010;
   r.bx:=j;
   r.ch:=((j and 3)*255) div 3;
   r.cl:=(((j shr 2) and 7)*255) div 7;
   r.dh:=((j shr 5)*255) div 7;
   Intr($10,r);
  end;
  For j:= 1 to i do
   begin
    For k:= mas[j].x1 to mas[j].x2 do
     begin
      For l:= mas[j].y1 to mas[j].y2 do
       begin
        putpixelxy(k,l,mas[j].index);
       end;
     end;
   end;
 r.ax:=$0001;
 Intr($33,r);
   r.ax:=$0003;
   Intr($33,r);
 While not keypressed do
  begin
   Delay(10);
   r.ax:=$0003;
   Intr($33,r);
   coordx:=r.cx div 2;
   coordy:=r.dx div 2;
   If r.bx=1 then
    begin
     For i:= 1 to i do
      begin
       If (coordx>=mas[i].x1) and (coordx<=mas[i].x2) and
          (coordy>=mas[i].y1) and (coordy<=mas[i].y2) then
           color:=mas[i].index;
       {contur(coordx,coordy,color);}
      end;
     k:=0;
     l:=0;
     r.bx:=0;
     bx:=0;
     While bx<>1 do
      begin
       r.ax:=$0003;
       Intr($33,r);
       bx:=r.bx;
       If  k=63 then l:=1;
       If k=0 then l:=0;
       delay(10);
       If l=0 then Inc(k) else dec(k);
       r.ax:=$1010;
       r.bx:=color;
       r.ch:=k;
       r.cl:=k;
       r.dh:=k;
       Intr($10,r);
      end;
     r.ax:=$1010;
     r.bx:=color;
     r.dh:=((color shr 5)*255) div 7;
     r.cl:=(((color shr 2) and 7)*255) div 7;
     r.ch:=((color and 3)*255) div 3;
     Intr($10,r);
    end;
  end;
End.