From c7d8de25b2b8235f5e75df1ba0fe751f8dcbbd7e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 10 Nov 2020 20:30:37 -0500 Subject: [PATCH] ti84: use Grid subsystem Also, rename CLRLN to NEWLN and make it clear that it's only called on entering a new line. This way, we can set Z offset in there for the TI-84+ LCD driver. --- arch/z80/ti84/blk/605 | 1 + arch/z80/ti84/blk/606 | 6 +----- arch/z80/ti84/blk/607 | 2 +- arch/z80/ti84/blk/608 | 9 +++------ arch/z80/ti84/blk/609 | 19 ++++++++++--------- arch/z80/ti84/blk/610 | 4 ---- arch/z80/ti84/xcomp.fs | 6 ++++-- blk/263 | 3 ++- blk/270 | 1 + blk/402 | 8 ++++---- doc/protocol.txt | 15 ++++++++++++--- 11 files changed, 39 insertions(+), 35 deletions(-) delete mode 100644 arch/z80/ti84/blk/610 diff --git a/arch/z80/ti84/blk/605 b/arch/z80/ti84/blk/605 index 3196a22..0cc07fb 100644 --- a/arch/z80/ti84/blk/605 +++ b/arch/z80/ti84/blk/605 @@ -1,6 +1,7 @@ ( Required config: LCD_MEM ) : _mem+ [ LCD_MEM LITN ] @ + ; : FNTW 3 ; : FNTH 5 ; +: COLS 96 FNTW 1+ / ; : LINES 64 FNTH 1+ / ; ( Wait until the lcd is ready to receive a command. It's a bit weird to implement a waiting routine in asm, but the forth version is a bit heavy and we don't want to wait longer than diff --git a/arch/z80/ti84/blk/606 b/arch/z80/ti84/blk/606 index 8de9f3b..2c6929b 100644 --- a/arch/z80/ti84/blk/606 +++ b/arch/z80/ti84/blk/606 @@ -1,11 +1,7 @@ -( Current Y position on the LCD, that is, where we're going to - spit our next glyph. ) -: LCD_CURY 0 _mem+ ; -: LCD_CURX 1 _mem+ ; ( two pixel buffers that are 8 pixels wide (1b) by FNTH pixels high. This is where we compose our resulting pixels blocks when spitting a glyph. ) -: LCD_BUF 2 _mem+ ; +: LCD_BUF 0 _mem+ ; : _cmd 0x10 ( CMD ) PC! _wait ; : _data! 0x11 ( DATA ) PC! _wait ; : _data@ 0x11 ( DATA ) PC@ _wait ; diff --git a/arch/z80/ti84/blk/607 b/arch/z80/ti84/blk/607 index 14cc84c..fca2988 100644 --- a/arch/z80/ti84/blk/607 +++ b/arch/z80/ti84/blk/607 @@ -3,7 +3,7 @@ : _col! ( col -- ) 0x20 + _cmd ; : _row! ( row -- ) 0x80 + _cmd ; : LCD$ - H@ [ LCD_MEM LITN ] ! FNTH 2 * 2+ ALLOT + H@ [ LCD_MEM LITN ] ! FNTH 2 * ALLOT LCDON 0x01 ( 8-bit mode ) _cmd FNTH 1+ _zoff! ; diff --git a/arch/z80/ti84/blk/608 b/arch/z80/ti84/blk/608 index 32a9f08..dfc10cf 100644 --- a/arch/z80/ti84/blk/608 +++ b/arch/z80/ti84/blk/608 @@ -5,10 +5,7 @@ 11 0 DO 0 _data! LOOP _xinc 0 _data! LOOP ; -: _clrln ( n ) FNTH 1+ _clrrows ; +: NEWLN ( ln -- ) + DUP 1+ FNTH 1+ * _zoff! + FNTH 1+ * FNTH 1+ _clrrows ; : LCDCLR 0 64 _clrrows ; -( Changes the current line and go back to leftmost column ) -: _lf - LCD_CURY C@ FNTH 1+ + DUP 63 > IF DROP 0 THEN - DUP _clrln DUP FNTH 1+ + _zoff! - LCD_CURY C! 0 LCD_CURX C! ; diff --git a/arch/z80/ti84/blk/609 b/arch/z80/ti84/blk/609 index 8088608..e27cc14 100644 --- a/arch/z80/ti84/blk/609 +++ b/arch/z80/ti84/blk/609 @@ -1,15 +1,16 @@ -: _glyph> ( a -- ) - LCD_CURY C@ _row! LCD_CURX C@ 8 /MOD _col! ( a coff ) - _xinc _data@ DROP SWAP - FNTH 0 DO ( coff a ) +: _atrow! ( pos -- ) COLS / FNTH 1+ * _row! ; +: _tocol ( pos -- col off ) COLS MOD FNTW 1+ * 8 /MOD ; +: CELL! ( g pos -- ) + DUP _atrow! DUP _tocol _col! ROT ( pos coff g ) + FNTH * ~FNT + ( pos coff a ) + _xinc _data@ DROP + FNTH 0 DO ( pos coff a ) C@+ 2 PICK 8 -^ LSHIFT _data@ 8 LSHIFT OR LCD_BUF I + 2DUP FNTH + C! SWAP 8 RSHIFT SWAP C! LOOP 2DROP - LCD_CURY C@ _row! + DUP _atrow! FNTH 0 DO LCD_BUF I + C@ _data! LOOP - LCD_CURY C@ _row! LCD_CURX C@ 8 / 1+ _col! - FNTH 0 DO LCD_BUF FNTH + I + C@ _data! LOOP - LCD_CURX C@ FNTW + 1+ DUP LCD_CURX C! ( x ) - 96 FNTW - > IF _lf THEN ; + DUP _atrow! _tocol NIP 1+ _col! + FNTH 0 DO LCD_BUF FNTH + I + C@ _data! LOOP ; diff --git a/arch/z80/ti84/blk/610 b/arch/z80/ti84/blk/610 deleted file mode 100644 index b1f21b5..0000000 --- a/arch/z80/ti84/blk/610 +++ /dev/null @@ -1,4 +0,0 @@ -: (emit) - DUP 0xd = IF DROP _lf EXIT THEN - DUP 0x20 0x7e =><= NOT IF DROP EXIT THEN - 0x20 - FNTH * ~FNT + _glyph> ; diff --git a/arch/z80/ti84/xcomp.fs b/arch/z80/ti84/xcomp.fs index c40176f..a48c155 100644 --- a/arch/z80/ti84/xcomp.fs +++ b/arch/z80/ti84/xcomp.fs @@ -3,7 +3,8 @@ RS_ADDR 0x80 - CONSTANT SYSVARS 0x8000 CONSTANT HERESTART SYSVARS 0x70 + CONSTANT LCD_MEM -SYSVARS 0x72 + CONSTANT KBD_MEM +SYSVARS 0x72 + CONSTANT GRID_MEM +SYSVARS 0x74 + CONSTANT KBD_MEM 0x01 CONSTANT KBD_PORT 5 LOAD ( z80 assembler ) : ZFILL, ( u ) 0 DO 0 A, LOOP ; @@ -64,7 +65,8 @@ CURRENT @ XCURRENT ! 283 335 LOADR ( boot.z80 ) 353 LOAD ( xcomp core low ) CREATE ~FNT CPFNT3x5 -605 610 LOADR ( LCD low ) +605 609 LOADR ( LCD low ) +402 403 LOADR ( Grid ) 616 620 LOADR ( KBD low ) 390 LOAD ( xcomp core high ) (entry) _ diff --git a/blk/263 b/blk/263 index f6fb875..4b4adb8 100644 --- a/blk/263 +++ b/blk/263 @@ -7,7 +7,8 @@ CREATE XCURRENT 0 , DUP ORG @ > IF ORG @ - BIN( @ + THEN ; : XFIND XCURRENT @ SWAP _find DROP _xapply ; : XLITN LIT" (n)" XFIND , , ; -: X' XCON ' XCOFF ; : X['] XCON ' _xapply XLITN XCOFF ; +: X' XCON ' XCOFF ; : X'? XCON '? XCOFF ; +: X['] XCON ' _xapply XLITN XCOFF ; : XCOMPILE XCON ' _xapply XLITN LIT" ," FIND DROP _xapply , XCOFF ; : X[COMPILE] XCON ' _xapply , XCOFF ; diff --git a/blk/270 b/blk/270 index 52b5ff4..d110bcf 100644 --- a/blk/270 +++ b/blk/270 @@ -1,4 +1,5 @@ : CODE XCODE ; +: '? X'? ; : ['] X['] ; IMMEDIATE : COMPILE XCOMPILE ; IMMEDIATE : [COMPILE] X[COMPILE] ; IMMEDIATE diff --git a/blk/402 b/blk/402 index 67a9a87..c5c59ce 100644 --- a/blk/402 +++ b/blk/402 @@ -1,11 +1,11 @@ : XYPOS [ GRID_MEM LITN ] ; : _cl* COLS LINES * ; : AT-XY ( x y -- ) LINES * + _cl* MOD XYPOS ! ; -'? CLRLN NIP NOT [IF] -: CLRLN ( ln -- ) COLS * DUP COLS + SWAP DO 0 I CELL! LOOP ; +'? NEWLN NIP NOT [IF] +: NEWLN ( ln -- ) COLS * DUP COLS + SWAP DO 0 I CELL! LOOP ; [THEN] : _lf - XYPOS @ COLS / 1+ DUP CLRLN - COLS * _cl* MOD XYPOS ! ; + XYPOS @ COLS / 1+ LINES MOD DUP NEWLN + COLS * XYPOS ! ; : _bs 0 ( blank ) XYPOS @ TUCK CELL! ( pos ) 1- _cl* MOD XYPOS ! ; diff --git a/doc/protocol.txt b/doc/protocol.txt index 50c913f..fc833be 100644 --- a/doc/protocol.txt +++ b/doc/protocol.txt @@ -47,7 +47,7 @@ LINES -- n Number of lines in the device CELL! g pos -- Set glyph at pos Optional: -CLRLN ln -- Clear line number ln. +NEWLN ln -- "Enter" line ln "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. @@ -57,6 +57,15 @@ number of glyphs in the font, it's up to CELL! to ignore it. Glyph 0 is always blank. -If CLRLN is not defined, the grid system uses multiple CELL! +NEWLN is called when we "enter" a new line, that is, when we +overflow from previous line or when 0x0d ( ASCII CR ) is emit- +ted. + +When this is called, the line being entered should be cleared +of its contents. On some systems, some kinf of screen offset +might be have to be set to give a "scrolling" effect. Now's the +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 CLRLN. +Drivers for those devices should define NEWLINE.