%begin
   %include "level1:graphinc.imp"
 ! %external %routine %spec quad %alias "FRED_GRAPHICS_QUAD" %c
 !             (%integer x0, y0, x1, y1, x2, y2, x3, y3)


   %routine cursor(%integer %name x, y)
      %own %integer ol = 0, or = 0, ob = 0, ot = 0,
                    cx=688, cy=512, ti = 0
      %integer ox, oy, l, r, t, b
   !  %while cputime<ti %cycle; %repeat
   !  ti = ti+10
      ox = x
      oy = y
      cx = cx+rel mouse x
      cy = cy+rel mouse y
      cx = 0 %if cx<0
      cx = 687<<1 %if cx>687<<1
      cy = 0 %if cy<0
      cy = 511<<1 %if cy>511<<1
      x = cx>>1
      y = cy>>1
      %if x#ox %or y#oy %start
         l = x-8
         r = x+8
         b = y-8
         t = y+8
         l = 0 %if l<0
         r = 687 %if r>687
         b = 0 %if b<0
         t = 511 %if t>511
         enable(7)
         colour(0)
         line(ol, oy, or, oy)
         line(ox, ob, ox, ot)
         colour(7)
         line(l, y, r, y)
         line(x, b, x, t)
         ox = x
         oy = y
         ol = l
         or = r
         ob = b
         ot = t
      %finish
   %end
   %routine getxy(%integer %name x, y)

      %while mouse buttons&2#0 %cycle; %repeat
      %while mouse buttons&2=0 %cycle
         cursor(x, y)
      %repeat
   %end
   %routine rband(%integer x0, y0, %integer %name x1, y1)
      %integer ox, oy
      x1 = x0
      y1 = y0
      %while mouse buttons&2#0 %cycle; %repeat
      %while mouse buttons&2=0 %cycle
         ox = x1
         oy = y1
         cursor(x1, y1)
         %if ox#x1 %or oy#y1 %start
            enable(7)
            colour(0)
            line(x0, y0, ox, oy)
            colour(7)
            line(x0, y0, x1, y1)
         %finish
      %repeat
      enable(7)
      colour(0)
      line(x0, y0, x1, y1)
   %end
   %routine rband2(%integer x0, y0, x2, y2, %integer %name x1, y1)
      %integer ox, oy
      x1 = x0
      y1 = y0
      %while mouse buttons&2#0 %cycle; %repeat
      %while mouse buttons&2=0 %cycle
         ox = x1
         oy = y1
         cursor(x1, y1)
         %if ox#x1 %or oy#y1 %start
            enable(7)
            colour(0)
            line(x0, y0, ox, oy)
            line(ox, oy, x2, y2)
            colour(7)
            line(x0, y0, x1, y1)
            colour(3)
            line(x1, y1, x2, y2)
         %finish
      %repeat
      enable(7)
      colour(0)
      line(x0, y0, x1, y1)
      line(x1, y1, x2, y2)
   %end
   %integer x0, y0, x1, y1, x2, y2, x3, y3
   %on %event 0 %start
      print symbol(27)
      print symbol('R')
      %stop
   %finish


   %cycle
      clear
      x0 = 0
      y0 = 0
      getxy(x0, y0)
      rband(x0, y0, x1, y1)
      enable(8)
      colour(8)
      line(x0, y0, x1, y1)
      rband2(x1, y1, x0, y0, x2, y2)
      enable(8)
      colour(8)
      line(x1, y1, x2, y2)
      rband2(x2, y2, x0, y0, x3, y3)
      %while mouse buttons&2#0 %cycle; %repeat
      clear
      enable(15)
      colour(14)
      line(x0, y0, x1, y1)
      line(x1, y1, x2, y2)
      line(x2, y2, x3, y3)
      line(x3, y3, x0, y0)
      enable(7)
      colour(3)
 !    quad(x0, y0, x1, y1, x2, y2, x3, y3)
      %while mouse buttons&2=0 %cycle; %repeat
   %repeat
%end %of %program
