more progress

This commit is contained in:
~d6 2023-01-22 21:07:10 -05:00
parent 927aece263
commit 9189fb270b
1 changed files with 88 additions and 29 deletions

117
term.tal
View File

@ -1,22 +1,52 @@
( ANSI sequences )
( )
( set attributes: ESC [ x ; ... m -> 0:reset 1:bright 2:dim 7:reverse )
( get cursor position: ESC [ 6 n -> ESC [ $row ; $col R )
( enable line wrap: ESC [ 7 h )
( disable line wrap: ESC [ 7 l )
( )
( move cursor home: ESC [ H )
( move cursor: ESC [ $row ; $col H )
( move up: ESC [ $n A )
( move down: ESC [ $n B )
( move forward: ESC [ $n C )
( move back: ESC [ $n D )
( )
( erase from cursor to end of line: ESC [ K )
( erase from start of line to cursor: ESC [ 1 K )
( erase line: ESC [ 2 K )
( erase from current line to bottom: ESC [ J )
( erase from current line to top: ESC [ 1 J )
( erase screen: ESC [ 2 J )
|00 @System [ &vect $2 &pad $6 &r $2 &g $2 &b $2 ]
|10 @Console [ &vect $2 &r $1 &pad $5 &w $1 ]
|20 @Screen [ &vect $2 &w $2 &h $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|80 @Controller [ &vect $2 &button $1 &key $1 ]
|0000
@tint $1 ( draw mode. 01=regular, 04=inverted )
@dirty? $1 ( screen needs redraw? )
@rows $2 ( height in characters )
@cols $2 ( width in characters )
@cur-x $2 ( cursor x: 0 <= cur-x < cols )
@cur-y $2 ( cursor y: 0 <= cur-y < rows )
@tint $1 ( draw mode. 01=regular, 04=inverted )
@dirty? $1 ( screen needs redraw? )
@rows $2 ( height in characters )
@cols $2 ( width in characters )
@cur-x $2 ( cursor x: 0 <= cur-x < cols )
@cur-y $2 ( cursor y: 0 <= cur-y < rows )
@max-x $2 ( cols-1 )
@max-y $2 ( rows-1 )
|0100
( 80 cols x 24 rows )
#0028 .rows STZ2
#0050 .cols STZ2
( set max row/col )
.rows LDZ2 #0001 SUB2 .max-y STZ2
.cols LDZ2 #0001 SUB2 .max-x STZ2
( set initial cursor )
#0000 .cur-x STZ2
#0000 .cur-y STZ2
( set screen height/width based on rows/cols )
.rows LDZ2 #30 SFT2 .Screen/h DEO2
.cols LDZ2 #30 SFT2 .Screen/w DEO2
@ -32,11 +62,17 @@
( set up interrupts )
;redraw .Screen/vect DEO2 ( set up screen )
;on-key .Controller/vect DEO2 ( set up keyboard )
;on-input .Console/vect DEO2 ( set up stdin )
;on-read .Console/vect DEO2 ( set up stdin )
( return )
BRK
@min ( x* y* -> min* )
LTH2k JMP SWP2 POP2 JMP2r
( @max ( x* y* -> max* )
LTH2k JMP SWP2 NIP2 JMP2r )
@clear-screen
#01 .dirty? STZ
;screen STH2
@ -116,21 +152,24 @@
&c1 LIT "@ SUB
&done .Console/w DEO BRK
@on-input
@on-read
.Console/r DEI
DUP ,&ok JCN POP BRK
&ok #41 .tint STZ
;read JSR2 BRK
@read ( byte^ -> )
DUP #07 EQU ;read-bel JCN2
@read ( c^ -> )
DUP #20 LTH ;read-ctrl JCN2
DUP #7f EQU ;read-del JCN2
;read-printable JMP2
@read-ctrl ( c^ -> )
DUP #07 EQU ;read-bel JCN2 ( TODO: flash )
DUP #08 EQU ;read-bs JCN2
DUP #09 EQU ;read-tab JCN2
DUP #0a EQU ;read-nl JCN2
DUP #0d EQU ;read-cr JCN2
DUP #1b EQU ;read-esc JCN2
DUP #7f EQU ;read-del JCN2
;read-printable JMP2
( TODO: we need line-editing! )
@read-bel POP JMP2r
@ -152,33 +191,53 @@
@read-cr ( 0d -> )
POP ;hide-cursor JSR2 #0000 .cur-x STZ2 JMP2r
@at-max-y ( -> true? )
.cur-y LDZ2 .max-y LDZ2 EQU2 JMP2r
@read-nl ( 0a -> )
POP ;hide-cursor JSR2 ;down JMP2
POP ;hide-cursor JSR2
,at-max-y JSR ;scroll JCN2 ;down JMP2
@read-printable ( c -> )
DUP ;cursor-addr JSR2 STA
;draw-tile JSR2
;forward JMP2
@forward ( -> )
.cur-x LDZ2 INC2 DUP2 .cols LDZ2 LTH2 ,&ok JCN
POP2 #0000 .cur-x STZ2 ;down JMP2
&ok .cur-x STZ2
@forward-n ( n* -> )
;hide-cursor JSR2
.cur-x LDZ2 ADD2 .max-x LDZ2 ;min JSR2 .cur-x STZ2
;show-cursor JMP2
@back ( -> )
.cur-x LDZ2 #0000 GTH2 ,&continue JCN
POP2 POP JMP2r
&continue ( addr^ value* )
@forward ( -> )
#0001 ,forward-n JMP
@back-n ( n* -> )
;hide-cursor JSR2
.cur-x LDZ2 #0001 SUB2 .cur-x STZ2
.cur-x LDZ2 GTH2k ,&zero JCN
SWP2 SUB2 ,&done JMP
&zero POP2 POP2 #0000
&done .cur-x STZ2 ;show-cursor JMP2
@back ( -> )
#0001 ,back-n JMP
@up-n ( n* -> )
;hide-cursor JSR2
.cur-y LDZ2 GTH2k ,&zero JCN
SWP2 SUB2 ,&done JMP
&zero POP2 POP2 #0000
&done .cur-y STZ2 ;show-cursor JMP2
@up ( -> )
#0001 ,up-n JMP
@down-n ( n* -> )
;hide-cursor JSR2
.cur-y LDZ2 ADD2 .max-y LDZ2 ;min JSR2 .cur-y STZ2
;show-cursor JMP2
@down ( -> )
.cur-y LDZ2 INC2 DUP2 .rows LDZ2 LTH2 ,&ok JCN
POP2 ;scroll JMP2
&ok .cur-y STZ2
;show-cursor JMP2
#0001 ,down-n JMP
@scroll
;end-screen STH2
@ -228,6 +287,6 @@
@screen $0c80 ( 80 x 40 )
@end-screen
( store attributes for redraw, etc. )
( ( store attributes for redraw, etc. )
@attrs $0c80 ( 80 x 40 )
@end-attrs
@end-attrs )