From b1e162b8a3987a188891cc117842e7b0c699dddc Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 16 Nov 2020 09:11:47 -0500 Subject: [PATCH] grid: change the meaning of CELL! Replace the "g" arg (glyph) with "c" (character). The reason why "g" was used was to save a "0x20 -" operation at all CELL! implementations, but this came with too big a drawback: it made CELL! hardly usable outside of the Grid subsystem, mostly because the user of CELL! would often have to do "0x20 -". For example, I want the SMS's Pad driver to use CELL! directly instead of having to do EMIT+XYPOS-messing-around. I would have had to do a "0x20 -" there. --- arch/z80/sms/Makefile | 2 +- arch/z80/sms/blk.fs | 6 +++--- arch/z80/ti84/Makefile | 2 +- arch/z80/ti84/blk.fs | 6 +++--- blk.fs | 10 +++++----- cvm/forth.fs | 2 +- doc/protocol.txt | 10 +++++----- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/z80/sms/Makefile b/arch/z80/sms/Makefile index 1f4b9ae..a9c3a23 100644 --- a/arch/z80/sms/Makefile +++ b/arch/z80/sms/Makefile @@ -15,7 +15,7 @@ $(SMSROM): $(BLKPACK): $(MAKE) -C ../tools -blkfs: $(BLKPACK) +blkfs: $(BLKPACK) $(BASE)/blk.fs blk.fs cat $(BASE)/blk.fs blk.fs | $(BLKPACK) > $@ $(STAGE): diff --git a/arch/z80/sms/blk.fs b/arch/z80/sms/blk.fs index 516435a..b3e295f 100644 --- a/arch/z80/sms/blk.fs +++ b/arch/z80/sms/blk.fs @@ -27,9 +27,9 @@ always stay zero. ) : _sfont ( a -- Send font to VDP ) 7 0 DO C@+ _data 3 _zero LOOP DROP ( blank row ) 4 _zero ; -: CELL! ( tilenum pos ) - 2 * 0x7800 OR _ctl ( tilenum ) - 0x5e MOD _data 1 _zero ; +: CELL! ( c pos ) + 2 * 0x7800 OR _ctl ( c ) + 0x20 - ( glyph ) 0x5e MOD _data 0 _data ; ( ----- 604 ) : VDP$ 9 0 DO _idat I 2 * + @ _ctl LOOP _blank diff --git a/arch/z80/ti84/Makefile b/arch/z80/ti84/Makefile index 50b5a7e..599df30 100644 --- a/arch/z80/ti84/Makefile +++ b/arch/z80/ti84/Makefile @@ -15,7 +15,7 @@ $(TARGET): xcomp.fs $(STAGE) blkfs $(BLKPACK): $(MAKE) -C ../tools -blkfs: $(BLKPACK) +blkfs: $(BLKPACK) $(BASE)/blk.fs blk.fs cat $(BASE)/blk.fs blk.fs | $(BLKPACK) > $@ $(STAGE): diff --git a/arch/z80/ti84/blk.fs b/arch/z80/ti84/blk.fs index 061f78f..9fd1d78 100644 --- a/arch/z80/ti84/blk.fs +++ b/arch/z80/ti84/blk.fs @@ -110,9 +110,9 @@ CODE _wait ( ----- 609 ) : _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 ) +: CELL! ( c pos -- ) + DUP _atrow! DUP _tocol _col! ROT ( pos coff c ) + 0x20 - FNTH * ~FNT + ( pos coff a ) _xinc _data@ DROP FNTH 0 DO ( pos coff a ) C@+ 2 PICK 8 -^ LSHIFT diff --git a/blk.fs b/blk.fs index 9b94928..7787f46 100644 --- a/blk.fs +++ b/blk.fs @@ -2218,7 +2218,7 @@ Load range: B402-B403 : 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 ; +: NEWLN ( ln -- ) COLS * DUP COLS + SWAP DO 0x20 I CELL! LOOP ; [THEN] : _lf XYMODE C@ IF EXIT THEN XYPOS @ COLS / 1+ LINES MOD DUP NEWLN @@ -2228,7 +2228,7 @@ Load range: B402-B403 : (emit) DUP 0x08 = IF DROP _bs EXIT THEN DUP 0x0d = IF DROP _lf EXIT THEN - 0x20 - DUP 0< IF DROP EXIT THEN + DUP 0x20 < IF DROP EXIT THEN XYPOS @ CELL! XYPOS @ 1+ DUP COLS MOD IF XYPOS! ELSE _lf THEN ; : GRID$ 0 XYPOS! 0 XYMODE C! ; @@ -2795,15 +2795,15 @@ them. We insert a blank one at the end of those 7. ) : _sfont ( a -- Send font to TMS ) 7 0 DO C@+ _data LOOP DROP ( blank row ) 0 _data ; -: CELL! ( tilenum pos ) +: CELL! ( c pos ) 0x7800 OR _ctl ( tilenum ) - 0x5e MOD _data ; + 0x20 - ( glyph ) 0x5e MOD _data ; : COLS 40 ; : LINES 24 ; : TMS$ 0x8100 _ctl ( blank screen ) _blank 0x4000 _ctl 0x5e 0 DO ~FNT I 7 * + _sfont LOOP 0x820e _ctl ( name table 0x3800 ) - 0x8400 _ctl ( patter table 0x0000 ) + 0x8400 _ctl ( pattern table 0x0000 ) 0x87f0 _ctl ( colors 0 and 1 ) 0x8000 _ctl 0x81d0 _ctl ( text mode, display on ) ; ( ----- 520 ) diff --git a/cvm/forth.fs b/cvm/forth.fs index ad37562..52b0ec2 100644 --- a/cvm/forth.fs +++ b/cvm/forth.fs @@ -1,6 +1,6 @@ : COLS 80 ; : LINES 32 ; : CURSOR! ( pos -- ) COLS /MOD 6 PC! ( y ) 5 PC! ( x ) ; -: CELL! ( g pos -- ) CURSOR! 0x20 + 0 PC! ; +: CELL! ( c pos -- ) CURSOR! 0 PC! ; : NEWLN ( ln -- ) DROP 0xa 0 PC! ; SYSVARS 0x70 + CONSTANT GRID_MEM diff --git a/doc/protocol.txt b/doc/protocol.txt index e92d6f4..1da55ac 100644 --- a/doc/protocol.txt +++ b/doc/protocol.txt @@ -44,7 +44,7 @@ allows random access to it. COLS -- n Number of columns in the device LINES -- n Number of lines in the device -CELL! g pos -- Set glyph at pos +CELL! c pos -- Set character at pos Optional: NEWLN ln -- "Enter" line ln @@ -53,10 +53,10 @@ 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. -A glyph is ASCII-0x20. If the resulting glyph number exceeds the -number of glyphs in the font, it's up to CELL! to ignore it. - -Glyph 0 is always blank. +CELL! is not expected to be called with an out-of-range char- +acter. For example, glyphs are often mapped starting at 0x20 +(space). On most systems, CELL! should not be called with c < +0x20.If it is, CELL! should do nothing. NEWLN is called when we "enter" a new line, that is, when we overflow from previous line or when 0x0d ( ASCII CR ) is emit-