Also, another programming advice. Many, many times, you do something for all 8 directions (repeating almost the same thing 8 or 9 times), or for one of 8 directions (having a big "case" which inside has almost the same thing 8 times). This bad, because if you want to change something in the copied routine, you have to change it 8 times. This can be solved by
const dx: Array[1..9] of Integer = (-1,0,1,-1,0,1,-1,0,1);
const dy: Array[1..9] of Integer = (1,1,1,0,0,0,-1,-1,-1);
and then replacing case routine by just x := realx(xpos+dx[r]); y := realy(ypos+dy[r]);, and similarly replacing a similar thing 8 times by a FOR loop. (I have not read carefully, but I suppose there is also no reason to pretend that a 9 is a 5. Just go on with an array of size 9 and ignore the 5th element.)