Terminal control/Cursor movement: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 20: Line 20:
20 PRINT CHR$(9);:REM cursor one position right
20 PRINT CHR$(9);:REM cursor one position right
30 GO SUB 500: REM get cursor position
30 GO SUB 500: REM get cursor position
40 IF cr<22 THEN LET cr=cr+1: GO SUB 550: REM cursor down one line
40 IF cr>0 THEN LET cr=cr-1: GO SUB 550: REM cursor up one line
50 POKE 23688,33: REM cursor to beginning of the line
50 IF cr<22 THEN LET cr=cr+1: GO SUB 550: REM cursor down one line
60 POKE 23688,0: REM cursor to end of line
60 POKE 23688,33: REM cursor to beginning of the line
70 POKE 23688,33:POKE 23689,24: REM cursor to top left
70 POKE 23688,0: REM cursor to end of line
80 POKE 23688,33:POKE 23689,24: REM cursor to top left
80 REM bottom two rows are reserved for input and errors
90 REM bottom two rows are reserved for input and errors
90 REM so we reserve those lines here
100 REM so we reserve those lines here
100 POKE 23688,0: POKE 23689,2: REM bottom right
110 POKE 23688,0: POKE 23689,2: REM bottom right


499 STOP: REM do not overrun into subroutines
499 STOP: REM do not overrun into subroutines

Revision as of 01:17, 23 July 2011

Terminal control/Cursor movement is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The task is to demonstrate how to achieve movement of the terminal cursor:

  • Demonstrate how to move the cursor one position to the left
  • Demonstrate how to move the cursor one position to the right
  • Demonstrate how to move the cursor up one line (without affecting its horizontal position)
  • Demonstrate how to move the cursor down one line (without affecting its horizontal position)
  • Demonstrate how to move the cursor to the beginning of the line
  • Demonstrate how to move the cursor to the end of the line
  • Demonstrate how to move the cursor to the top left corner of the screen
  • Demonstrate 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).


ZX Spectrum Basic

<lang zxbasic>10 PRINT CHR$(8);:REM cursor one position left 20 PRINT CHR$(9);:REM cursor one position right 30 GO SUB 500: REM get cursor position 40 IF cr>0 THEN LET cr=cr-1: GO SUB 550: REM cursor up one line 50 IF cr<22 THEN LET cr=cr+1: GO SUB 550: REM cursor down one line 60 POKE 23688,33: REM cursor to beginning of the line 70 POKE 23688,0: REM cursor to end of line 80 POKE 23688,33:POKE 23689,24: REM cursor to top left 90 REM bottom two rows are reserved for input and errors 100 REM so we reserve those lines here 110 POKE 23688,0: POKE 23689,2: REM bottom right

499 STOP: REM do not overrun into subroutines

500 REM get cursor position 510 LET cc=33-PEEK 23688:REM current column 520 LET cr=24-PEEK 23689:REM current row 530 RETURN

550 REM set cursor position 560 PRINT AT cr,cc; 570 RETURN

600 REM alternative set cursor position 610 POKE 23688,33-cc 620 POKE 23689,24-cr 630 RETURN</lang>