From d58d7c167c5f89e39b856bc61a3d9256d8883c20 Mon Sep 17 00:00:00 2001 From: d6 Date: Wed, 25 Jan 2023 12:11:16 -0500 Subject: [PATCH] progress on attributes --- term.tal | 243 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 136 insertions(+), 107 deletions(-) diff --git a/term.tal b/term.tal index 789e12d..c9263d8 100644 --- a/term.tal +++ b/term.tal @@ -41,6 +41,7 @@ |0000 @tint $1 ( draw mode. 01=regular, 04=inverted ) + @attr $1 ( 5 bits: RxxxBBFF ) @dirty? $1 ( screen needs redraw? ) @lastkey $1 ( last button press ) @rows $2 ( height in characters ) @@ -71,9 +72,13 @@ .cols LDZ2 #30 SFT2 .Screen/w DEO2 ( set colors ) - #0cf0 .System/r DEO2 - #0c88 .System/g DEO2 - #0c0f .System/b DEO2 + #07bf .System/r DEO2 + #07bf .System/g DEO2 + #07bf .System/b DEO2 + + ( set starting tint: reverse=0, bg=0, fg=2 ) + #02 .attr STZ + ;update-tint JSR2 ( clear screen for initial draw ) ;clear-screen JSR2 @@ -87,22 +92,24 @@ ;debug .File/name DEO2 #01 .File/append DEO +( #9999 #010e DEO ) + BRK @first-addr ( -> ) - ;screen JMP2r + ;cells JMP2r @bol-addr ( -> addr* ) - .cols LDZ2 .cur-y LDZ2 MUL2 ;screen ADD2 JMP2r + .cols LDZ2 .cur-y LDZ2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r @cur-addr ( -> addr* ) - ;bol-addr JSR2 .cur-x LDZ2 ADD2 JMP2r + .cols LDZ2 .cur-y LDZ2 MUL2 .cur-x LDZ2 ADD2 #0002 MUL2 ;cells ADD2 JMP2r @eol-addr ( -> addr* ) - .cols LDZ2 .cur-y LDZ2 INC2 MUL2 ;screen ADD2 JMP2r + .cols LDZ2 .cur-y LDZ2 INC2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r -@last-addr ( -> ) - .cols LDZ2 .rows LDZ2 MUL2 ;screen ADD2 JMP2r +@limit-addr ( -> ) + .cols LDZ2 .rows LDZ2 MUL2 #0002 MUL2 ;cells ADD2 JMP2r @min ( x* y* -> min* ) LTH2k JMP SWP2 POP2 JMP2r @@ -112,63 +119,62 @@ @clear-screen #01 .dirty? STZ - ;screen STH2 - #0000 &yloop - #0000 &xloop - #20 STH2kr STA INC2r - INC2 DUP2 .cols LDZ2 LTH2 ,&xloop JCN - POP2 - INC2 DUP2 .rows LDZ2 LTH2 ,&yloop JCN - POP2 POP2r - JMP2r + ;cells STH2 ( [addr*] ) + #0000 &yloop ( y* [addr*] y* ) + #0000 &xloop ( y* x* [addr*] ) + #4220 STH2kr STA2 ( y* x* [addr*] ) + INC2r INC2r ( y* x* [addr+2*] ) + INC2 DUP2 .cols LDZ2 ( y* x+1* x+1* cols* [addr+2*] ) + LTH2 ,&xloop JCN ( y* x+1* [addr+2*] ) + POP2 ( y* [addr*] ) + INC2 DUP2 .rows LDZ2 ( y+1* y+1* rows* [addr*] ) + LTH2 ,&yloop JCN ( y+1* [addr*] ) + POP2 POP2r JMP2r ( ) @redraw - #41 .tint STZ .dirty? LDZ #00 EQU ,&done JCN - ;screen STH2 + ;cells STH2 ( [addr*] ) #0000 DUP2 .Screen/y DEO2 &yloop #0000 DUP2 .Screen/x DEO2 &xloop - STH2kr LDA ;draw-tile JSR2 - .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 - INC2 INC2r + STH2kr LDA2 ;draw-cell JSR2 + .Screen/x DEI2k #0008 ADD2 ROT DEO2 + INC2 INC2r INC2r DUP2 .cols LDZ2 LTH2 ,&xloop JCN POP2 - .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 + .Screen/y DEI2k #0008 ADD2 ROT DEO2 INC2 DUP2 .rows LDZ2 LTH2 ,&yloop JCN POP2 POP2r - ;show-cursor JSR2 + ;draw-cursor JSR2 #00 .dirty? STZ &done BRK -@hide-cursor - .tint LDZ - #41 .tint STZ - ;draw-cursor JSR2 - .tint STZ JMP2r - -@show-cursor - .tint LDZ - #44 .tint STZ - ;draw-cursor JSR2 - .tint STZ JMP2r +@clear-cursor + .cur-x LDZ2 #30 SFT2 .Screen/x DEO2 + .cur-y LDZ2 #30 SFT2 .Screen/y DEO2 + ;cur-addr JSR2 LDA2 + ;draw-cell JMP2 @draw-cursor .cur-x LDZ2 #30 SFT2 .Screen/x DEO2 .cur-y LDZ2 #30 SFT2 .Screen/y DEO2 - .cur-y LDZ2 .cols LDZ2 MUL2 .cur-x LDZ2 ADD2 ;screen ADD2 LDA - ;draw-tile JMP2 + ;cur-addr JSR2 LDA2 + SWP ;reverse-tint JSR2 SWP + ;draw-cell JMP2 @on-button ( -> ) - .lastkey LDZ .Controller/button DEI STHk EOR STHr AND ( new-buttons ) + .lastkey LDZ ( last^ ) + .Controller/button DEI ( last^ button^ ) + STHk EOR ( last-xor-button^ [button^] ) + STHr AND ( last-xor-button&button^ ) DUP #10 AND #00 EQU ,&no-n JCN LIT "A ,arrow JSR &no-n DUP #20 AND #00 EQU ,&no-s JCN LIT "B ,arrow JSR &no-s DUP #40 AND #00 EQU ,&no-w JCN LIT "D ,arrow JSR &no-w DUP #80 AND #00 EQU ,&no-e JCN LIT "C ,arrow JSR - &no-e .Controller/button DEI .lastkey STZ BRK + &no-e POP .Controller/button DEI .lastkey STZ BRK ( send ESC [ $c ) @arrow ( c^ -> ) @@ -229,7 +235,7 @@ DUP LIT "d EQU ;exec-move-row JCN2 ( move cursor to row ) DUP LIT "h EQU ;exec-noop JCN2 ( enable line wrap ) DUP LIT "l EQU ;exec-noop JCN2 ( disable line wrap ) - DUP LIT "m EQU ;exec-noop JCN2 ( set attr ) + DUP LIT "m EQU ;exec-set-attr JCN2 ( set attr ) DUP LIT "n EQU ;exec-status JCN2 ( get status ) DUP LIT "A EQU ;exec-up JCN2 ( up ) DUP LIT "B EQU ;exec-down JCN2 ( down ) @@ -245,6 +251,28 @@ @exec-noop ( c^ -> ) POP BRK +@read-attr ( attr* -> ) + DUP2 #0000 NEQ2 ,&!0 JCN #02 .attr STZ ,&done JMP ( reset ) + &!0 DUP2 #0001 NEQ2 ,&!1 JCN #03 ,&set-fg JMP ( bright ) + &!1 DUP2 #0002 NEQ2 ,&!2 JCN #01 ,&set-fg JMP ( dim ) + &!2 DUP2 #0007 NEQ2 ,&!7 JCN .attr LDZk #80 ORA SWP STZ ,&done JMP ( reverse ) + &!7 ,&ignored JMP + + &set-fg .attr LDZ #fc AND ORA .attr STZ + &done ;update-tint JSR2 + &ignored POP2 JMP2r + +@exec-set-attr ( c^ -> ) + POP + ( BRK ( FIXME: gaining 4 bytes per ls -F ) ) + ;args/pos LDA2 ;args + &loop + LDA2k ;read-attr JSR2 + INC2 INC2 + LTH2k ,&done JCN ,&loop JMP + &done + POP2 POP2 BRK + @exec1 ( addr* -> ) STH2 #0001 ;read-arg-1 JSR2 STH2r JSR2 BRK @@ -272,11 +300,11 @@ DUP2 #0002 EQU2 ,&erase-full JCN POP2 BRK &erase-full - POP2 ;bol-addr JSR2 ;eol-addr JSR2 ;erase JSR2 BRK + POP2 ;bol-addr JSR2 ;eol-addr JSR2 ;erase JSR2 BRK &erase-to-end - POP2 ;cur-addr JSR2 ;eol-addr JSR2 ;erase JSR2 BRK + POP2 ;cur-addr JSR2 ;eol-addr JSR2 ;erase JSR2 BRK &erase-from-start - POP2 ;bol-addr JSR2 ;cur-addr JSR2 ;erase JSR2 BRK + POP2 ;bol-addr JSR2 ;cur-addr JSR2 ;erase JSR2 BRK @exec-erase-screen POP #0000 ;read-arg-1 JSR2 @@ -285,22 +313,24 @@ DUP2 #0002 EQU2 ,&erase-full JCN POP2 BRK &erase-full - POP2 ;first-addr JSR2 ;last-addr JSR2 ;erase JSR2 BRK + POP2 ;first-addr JSR2 ;limit-addr JSR2 ;erase JSR2 BRK &erase-to-end - POP2 ;bol-addr JSR2 ;last-addr JSR2 ;erase JSR2 BRK + POP2 ;bol-addr JSR2 ;limit-addr JSR2 ;erase JSR2 BRK &erase-from-start POP2 ;first-addr JSR2 ;eol-addr JSR2 ;erase JSR2 BRK ( TODO: needs to be smarter -- need to redraw tiles and keep x/y coords ) @erase ( start* end* -> ) - OVR2 SWP2 SUB2 STH2 ( start* [count=start-end*] ) - #20 ROT ROT ( 20 start* [count*] ) - &loop ( 20 addr* [i*] ) - STAk INC2 INC2r ( 20 addr+1* [i+1*] ) - ORAkr STHr ,&loop JCN ( 20 addr* [i+1*] ) - POP2r POP2 POP ( ) + EQU2k ,&skip JCN ( start* end* ) + OVR2 SWP2 ( start* start* end* ) + SUB2 STH2 #4220 SWP2 ( 4220 start* [count*] ) + &loop ( 4220 addr* [i*] ) + STA2k INC2 INC2 INC2r INC2r ( 4220 addr+2* [i+1*] ) + ORAkr STHr ,&loop JCN ( 4220 addr+2* [i+2*] ) + POP2r POP2 POP2 ( ) #01 .dirty? STZ ( ; FIXME just redraw affected tiles ) JMP2r ( ) + &skip POP2 POP2 JMP2r ( ) @exec-move-row ( c^ -> ) POP @@ -351,7 +381,7 @@ @on-read .Console/r DEI DUP ,&ok JCN POP BRK - &ok #41 .tint STZ + &ok ( #42 .tint STZ ) ;read JMP2 @read ( c^ -> ) @@ -372,9 +402,9 @@ @read-bs ( 08 -> ) POP - ;hide-cursor JSR2 + ;clear-cursor JSR2 #0001 ;back-n JSR2 - ;show-cursor JSR2 + ;draw-cursor JSR2 JMP2r @read-esc ( 1b -> ) @@ -388,84 +418,73 @@ POP .cur-x LDZ2 NIP #07 AND #08 SUB &loop - #20 DUP ;cursor-addr JSR2 STA - ;draw-tile JSR2 + .tint LDZ #20 DUP ;cur-addr JSR2 STA2 + ;draw-cell JSR2 ;forward JSR2 INC DUP ,&loop JCN POP JMP2r @read-cr ( 0d -> ) - POP ;hide-cursor JSR2 #0000 .cur-x STZ2 BRK + POP ;clear-cursor JSR2 #0000 .cur-x STZ2 BRK @at-max-y ( -> true? ) .cur-y LDZ2 .max-y LDZ2 EQU2 JMP2r @read-nl ( 0a -> ) - POP ;hide-cursor JSR2 + POP ;clear-cursor JSR2 ,at-max-y JSR ;scroll JCN2 ;down JSR2 BRK @read-printable ( c -> ) - DUP ;cursor-addr JSR2 STA - ;draw-tile JSR2 + .tint LDZ SWP DUP2 ;cur-addr JSR2 STA2 + ;draw-cell JSR2 ;forward JSR2 BRK @goto ( y* x* -> ) - ;hide-cursor JSR2 + ;clear-cursor JSR2 .max-x LDZ2 ;min JSR2 .cur-x STZ2 .max-y LDZ2 ;min JSR2 .cur-y STZ2 - ;show-cursor JMP2 + ;draw-cursor JMP2 @forward-n ( n* -> ) - ;hide-cursor JSR2 + ;clear-cursor JSR2 .cur-x LDZ2 ADD2 .max-x LDZ2 ;min JSR2 .cur-x STZ2 - ;show-cursor JMP2 + ;draw-cursor JMP2 @forward ( -> ) #0001 ,forward-n JMP @back-n ( n* -> ) - ;hide-cursor JSR2 + ;clear-cursor JSR2 .cur-x LDZ2 GTH2k ,&zero JCN SWP2 SUB2 ,&done JMP &zero POP2 POP2 #0000 - &done .cur-x STZ2 ;show-cursor JMP2 + &done .cur-x STZ2 ;draw-cursor JMP2 @up-n ( n* -> ) - ;hide-cursor JSR2 + ;clear-cursor JSR2 .cur-y LDZ2 GTH2k ,&zero JCN SWP2 SUB2 ,&done JMP &zero POP2 POP2 #0000 - &done .cur-y STZ2 ;show-cursor JMP2 + &done .cur-y STZ2 ;draw-cursor JMP2 @down-n ( n* -> ) - ;hide-cursor JSR2 + ;clear-cursor JSR2 .cur-y LDZ2 ADD2 .max-y LDZ2 ;min JSR2 .cur-y STZ2 - ;show-cursor JMP2 + ;draw-cursor JMP2 @down ( -> ) #0001 ,down-n JMP @scroll - ;end-screen STH2 - ;screen .cols LDZ2 ADD2 STH2 + ;limit-addr JSR2 STH2 + ;cells .cols LDZ2 #0002 MUL2 ADD2 STH2 &loop - STH2kr LDA #20 STH2kr STA - STH2kr .cols LDZ2 SUB2 STA - INC2r GTH2kr STHr ,&loop JCN + STH2kr LDA2 #4220 STH2kr STA2 + STH2kr .cols LDZ2 #0002 MUL2 SUB2 STA2 + INC2r INC2r GTH2kr STHr ,&loop JCN POP2r POP2r #01 .dirty? STZ - ;show-cursor JSR2 BRK - -@cursor-addr ( -> addr* ) - .cur-y LDZ2 .cols LDZ2 MUL2 - .cur-x LDZ2 ADD2 ;screen ADD2 - JMP2r - -( 0 <= c < 256 ) -@draw-tile ( c^ -> ) - DUP #80 LTH - ,draw-7bit JCN - ,draw-8bit JMP + ;draw-cursor JSR2 BRK ( 0 <= index < 128 ) @load-tile ( index^ -> ) @@ -473,21 +492,32 @@ ;ascii ADD2 .Screen/addr DEO2 JMP2r -( 0 <= c < 128 ) -@draw-7bit ( c^ -> ) - ;load-tile JSR2 - .tint LDZ .Screen/sprite DEO - JMP2r +( bits: Rx xx FF BB ) +( - R: reversed [0=normal, 1=reversed] ) +( - F: foreground [0:black, 1:dim, 2:normal, 3:bright] ) +( - B: background [0:black, 1:dim, 2:normal, 3:bright] ) +@update-tint ( -> ) + .attr LDZ + DUP #80 LTH ,&ok JCN + #80 EOR DUP #02 SFT SWP #20 SFT #0c AND ORA + &ok #40 ORA + .tint STZ JMP2r -( 128 <= c < 256 ) -@draw-8bit ( 8bit^ -> ) - #80 SUB ;load-tile JSR2 - .tint LDZ #05 EOR .Screen/sprite DEO - JMP2r +@reverse-tint ( tint^ -> tint^ ) + #0f AND ( x=tint&0f ) + DUP #02 SFT SWP ( x>>2 x ) + #03 AND #20 SFT ( x>>2 (x&3)<<2 ) + ORA #40 ORA ( res=40|x>>2|(x&3)<<2 ) + JMP2r ( res^ ) -( 128 1-bit 8x8 tiles for ASCII 7-bit characters ) -@ascii - ~chr/ascii.tal +( cell* = tint^ c^ ) +@draw-cell ( cell* -> ) + SWP STH ( c^ [tint^] ) + DUP #80 LTH ,&draw JCN ( c^ [tint^] ) + #80 SUB ( c-80^ [tint^] ) + &draw ;load-tile JSR2 ( [tint^] ) + STHr .Screen/sprite DEO ( ) + JMP2r ( ) @next-arg ( c^ -> ) POP @@ -518,10 +548,9 @@ ( store up to 8 arguments for control sequences ) @args $10 &pos $2 -( store characters for redraw, etc. ) -@screen $0c80 ( 80 x 40 ) -@end-screen +( 128 1-bit 8x8 tiles for ASCII 7-bit characters ) +@ascii + ~chr/ascii.tal -( ( store attributes for redraw, etc. ) -@attrs $0c80 ( 80 x 40 ) -@end-attrs ) +( store tint+char for each screen position ) +@cells $1900 ( 80 x 40 x 2 )