From 7bfec5d9e9c8e56117dba47676749155cdd8499e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 16 Nov 2020 08:41:09 -0500 Subject: [PATCH] grid: Add CURSOR! to the grid protocol With the move of CVM's forth to the grid protocol, we've lost the cursor's visual indication. Now, we have it back. The challenge now is in implementing it in SMS' text mode. In mode 4, it's easy to mark a cell as inverted, but in text mode, that's not possible. --- blk.fs | 14 +++++++------- cvm/forth.fs | 4 ++-- doc/protocol.txt | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/blk.fs b/blk.fs index 8040a8b..9b94928 100644 --- a/blk.fs +++ b/blk.fs @@ -2214,24 +2214,24 @@ See doc/grid.txt. Load range: B402-B403 ( ----- 402 ) : XYPOS [ GRID_MEM LITN ] ; : XYMODE [ GRID_MEM LITN ] 2+ ; -: _cl* COLS LINES * ; -: AT-XY ( x y -- ) COLS * + _cl* MOD XYPOS ! ; +'? CURSOR! NIP NOT [IF] : CURSOR! DROP ; [THEN] +: XYPOS! COLS LINES * MOD DUP CURSOR! XYPOS ! ; +: AT-XY ( x y -- ) COLS * + XYPOS! ; '? NEWLN NIP NOT [IF] : NEWLN ( ln -- ) COLS * DUP COLS + SWAP DO 0 I CELL! LOOP ; [THEN] : _lf XYMODE C@ IF EXIT THEN XYPOS @ COLS / 1+ LINES MOD DUP NEWLN - COLS * XYPOS ! ; -: _bs 0 ( blank ) XYPOS @ TUCK CELL! ( pos ) 1- - _cl* MOD XYPOS ! ; + COLS * XYPOS! ; +: _bs 0 ( blank ) XYPOS @ TUCK CELL! ( pos ) 1- XYPOS! ; ( ----- 403 ) : (emit) DUP 0x08 = IF DROP _bs EXIT THEN DUP 0x0d = IF DROP _lf EXIT THEN 0x20 - DUP 0< IF DROP EXIT THEN XYPOS @ CELL! - XYPOS @ 1+ DUP COLS MOD IF XYPOS ! ELSE _lf THEN ; -: GRID$ 0 XYPOS ! 0 XYMODE C! ; + XYPOS @ 1+ DUP COLS MOD IF XYPOS! ELSE _lf THEN ; +: GRID$ 0 XYPOS! 0 XYMODE C! ; ( ----- 410 ) PS/2 keyboard subsystem diff --git a/cvm/forth.fs b/cvm/forth.fs index a6899bf..ad37562 100644 --- a/cvm/forth.fs +++ b/cvm/forth.fs @@ -1,6 +1,6 @@ : COLS 80 ; : LINES 32 ; -: CELL! ( g pos -- ) - COLS /MOD 6 PC! ( y ) 5 PC! ( x ) 0x20 + 0 PC! ; +: CURSOR! ( pos -- ) COLS /MOD 6 PC! ( y ) 5 PC! ( x ) ; +: CELL! ( g pos -- ) CURSOR! 0x20 + 0 PC! ; : NEWLN ( ln -- ) DROP 0xa 0 PC! ; SYSVARS 0x70 + CONSTANT GRID_MEM diff --git a/doc/protocol.txt b/doc/protocol.txt index fc833be..e92d6f4 100644 --- a/doc/protocol.txt +++ b/doc/protocol.txt @@ -48,6 +48,7 @@ CELL! g pos -- Set glyph at pos Optional: NEWLN ln -- "Enter" line ln +CURSOR! pos -- Set cursor's position "pos" is a simple number (y * cols) + x. For example, if we have 40 columns per line, the position (x, y) (12, 10) is 412. @@ -69,3 +70,7 @@ time. If it's not defined, the grid system uses multiple CELL! calls to clear it. On some devices, this is highly inefficient. Drivers for those devices should define NEWLINE. + +CURSOR! is called whenever we change the cursor's position. If +not implemented, it will be a noop. It is never called with an +out of range "pos" (greater than COLS*LINES).