%begin
%include "inc:level1.imp"
%integer sym,xp,yp,speed
%constinteger cr=13,esc=27,fast=16,slow=1

%routine grid(%integer k)
%integer i
  line(0,i,1000,i) %for i=0,k,1000
  line(i,0,i,1000) %for i=0,k,1000
%end

clear
colour(1); grid(10)
colour(2); enable(\1); grid(50)
colour(4); enable(\3); grid(100)
xp = 0; yp=0; speed=fast
printstring("Cursor keys to move, HOME to change speed fast/slow"); newline
prompt("")
%cycle
  offset(-xp,-yp)
  write(xp,4); write(yp,4)
  %cycle
    readsymbol(sym)
    %stopif sym=nl
  %repeatuntil sym=esc
  readsymbol(sym) %until 'A'<=sym<='H'
  speed = speed!!(fast!!slow) %if sym='H'
  yp = yp+speed %if sym='A'
  yp = yp-speed %if sym='B'
  xp = xp+speed %if sym='C'
  xp = xp-speed %if sym='D'
  printsymbol(cr)
%repeat
%endofprogram
