progress on attributes

This commit is contained in:
~d6 2023-01-25 12:11:16 -05:00
parent eaa57c67fd
commit d58d7c167c
1 changed files with 136 additions and 107 deletions

243
term.tal
View File

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