Task

Demonstrate how to achieve movement of the terminal cursor:

 how to move the cursor one position to the left
 how to move the cursor one position to the right
 how to move the cursor up one line (without affecting its horizontal position)
 how to move the cursor down one line (without affecting its horizontal position)
 how to move the cursor to the beginning of the line
 how to move the cursor to the end of the line
 how to move the cursor to the top left corner of the screen
 how to move the cursor to the bottom right corner of the screen


For the purpose of this task, it is not permitted to overwrite any characters or attributes on any part of the screen (so outputting a space is not a suitable solution to achieve a movement to the right).



Handling of out of bounds locomotion
This task has no specific requirements to trap or correct cursor movement beyond the terminal boundaries, so the implementer should decide what behavior fits best in terms of the chosen language.   Explanatory notes may be added to clarify how an out of bounds action would behave and the generation of error messages relating to an out of bounds cursor position is permitted.




PROC Wait(BYTE frames)
  BYTE RTCLOK=$14
  frames==+RTCLOK
  WHILE frames#RTCLOK DO OD
RETURN
 
PROC Main()
  BYTE
    d=[50],
    CH=$02FC, ;Internal hardware value for last key pressed
    ROWCRS=$0054 ;Current cursor row
  CARD COLCRS=$0055 ;Current cursor column
 
  Graphics(0)
  Position(2,2)
  Print("Press any key to start demonstration.")
  Position(20,10)
  Put(28) Put(29) ;trick to show the new cursor pos
  DO UNTIL CH#$FF OD
  CH=$FF
 
  Wait(d) Put(30) ;move cursor left
  Wait(d) Put(31) ;move cursor right
  Wait(d) Put(28) ;move cursor up
  Wait(d) Put(29) ;move cursor down
 
  Wait(d) Position(0,ROWCRS) ;move to the beginning of the line
  Put(28) Put(29) ;trick to show the new cursor pos
 
  Wait(d) Position(39,ROWCRS) ;move to the end of the line
  Put(28) Put(29) ;trick to show the new cursor pos
 
  Wait(d) Position(0,0) ;move to the top-left corner
  Put(28) Put(29) ;trick to show the new cursor pos
 
  Wait(d) Position(39,23) ;move to the bottom-right corner
  Put(29) Put(28) ;trick to show the new cursor pos
 
  Wait(d)
RETURN