nxu/term.tal

255 lines
5.7 KiB
Tal
Raw Normal View History

2022-11-06 21:49:02 -05:00
|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
@dirty $1 ( screen needs redraw? )
@tint $1 ( draw mode. 01=regular, 04=inverted )
@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 )
@bg-frame $2
@bg-counter $1
|0100
( 32 characters = 256 pixels )
#0020 .rows STZ2
#0040 .cols STZ2
( set screen height/width based on rows/cols )
.rows LDZ2 #30 SFT2 .Screen/h DEO2
.cols LDZ2 #30 SFT2 .Screen/w DEO2
( set colors )
#0ff3 .System/r DEO2
#0fd5 .System/g DEO2
#2f66 .System/b DEO2
( #08f3 .System/r DEO2
#0cd5 .System/g DEO2
#0b66 .System/b DEO2 )
( clear screen for initial draw )
;clear-screen JSR2
( draw background )
#0000 .bg-frame STZ2
#00 .bg-counter STZ
( #0000 ;draw-background JSR2 )
( set up interrupts )
;redraw .Screen/vect DEO2 ( set up screen )
;on-key .Controller/vect DEO2 ( set up keyboard )
( return )
BRK
@draw-background ( frame* -> )
STH2
STH2kr #70 SFT2 ;cyber ADD2 #0048 ADD2 .Screen/addr DEO2
LIT2r 000f LIT2 0000
&loop1
DUP2 #30 SFT2 .Screen/y DEO2
DUP2 .cols LDZ2 OVR2 SUB2 ,hline JSR
INC2 DUP2 STH2kr LTH2 ,&loop1 JCN
POP2 POP2r
STH2kr #70 SFT2 ;cyber ADD2 #0040 ADD2 .Screen/addr DEO2
LIT2r 0020 LIT2 0011
&loop2
DUP2 #30 SFT2 .Screen/y DEO2
.rows LDZ2 OVR2 INC2 SUB2 .cols LDZ2 OVR2 SUB2 ,hline JSR
INC2 DUP2 STH2kr LTH2 ,&loop2 JCN
POP2 POP2r
POP2r JMP2r
@dline ( n -> )
#0000 SWP2 SUB2 STH2
&loop
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
#02 .Screen/sprite DEO
INC2r STH2kr ORA ,&loop JCN
POP2r JMP2r
@hline ( x1 x2 -> )
STH2 &loop
DUP2 #30 SFT2 .Screen/x DEO2
#02 .Screen/sprite DEO
INC2 DUP2 STH2kr LTH2 ,&loop JCN
POP2 POP2r JMP2r
@vline ( y1 y2 -> )
STH2 &loop
DUP2 #30 SFT2 .Screen/y DEO2
#02 .Screen/sprite DEO
INC2 DUP2 STH2kr LTH2 ,&loop JCN
POP2 POP2r JMP2r
@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
@redraw
.bg-counter LDZ DUP ,&done-bg JCN
.bg-frame LDZ2
( DUP2 NIP LIT "a ADD #18 DEO #0a #18 DEO )
DUP2 ;draw-background JSR2
INC2 #0007 AND2 .bg-frame STZ2
&done-bg
INC #03 AND .bg-counter STZ
#41 .tint STZ
.dirty LDZ #00 EQU ,&done JCN
;screen STH2
#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
DUP2 .cols LDZ2 LTH2 ,&xloop JCN
POP2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
INC2
DUP2 .rows LDZ2 LTH2 ,&yloop JCN
POP2 POP2r
;show-cursor JSR2
#00 .dirty STZ
&done BRK
@hide-cursor
#41 .tint STZ
;draw-cursor JMP2
@show-cursor
#44 .tint STZ
;draw-cursor 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
@on-key
.Controller/key DEI #00 EQU ,&skip JCN
.Controller/key DEI ;read JSR2
&skip BRK
@read ( byte^ -> )
DUP #07 EQU ;read-bel JCN2
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-normal JMP2
@read-bel JMP2r
@read-bs POP ;scroll JMP2
@read-tab POP POP2r #0000 DIV
@read-esc JMP2r
@read-del JMP2r
@read-cr ( 0d -> )
POP
;hide-cursor JSR2
#0000 .cur-x STZ2
;down JMP2
@read-nl ( 0a -> )
,read-cr JMP
@forward ( -> )
.cur-x LDZ2 INC2 DUP2 .cols LDZ2 LTH2 ,&ok JCN
POP2 #0000 .cur-x STZ2 ;down JMP2
&ok .cur-x 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
@scroll
;end-screen STH2
;screen .cols LDZ2 ADD2 STH2
&loop
STH2kr LDA #20 STH2kr STA
STH2kr .cols LDZ2 SUB2 STA
INC2r GTH2kr STHr ,&loop JCN
POP2r POP2r
#01 .dirty STZ
;show-cursor JMP2
@cursor-addr ( -> addr* )
.cur-y LDZ2 .cols LDZ2 MUL2
.cur-x LDZ2 ADD2 ;screen ADD2
JMP2r
@read-normal ( c -> )
;hide-cursor JSR2
DUP ;cursor-addr JSR2 STA
;draw-tile JSR2
;forward JMP2
( 0 <= c < 256 )
@draw-tile ( c^ -> )
DUP #80 LTH
,draw-7bit JCN
,draw-8bit JMP
( 0 <= index < 128 )
@load-tile ( index^ -> )
#00 SWP #30 SFT2
;ascii ADD2 .Screen/addr DEO2
JMP2r
( 0 <= c < 128 )
@draw-7bit ( c^ -> )
;load-tile JSR2
.tint LDZ .Screen/sprite DEO
JMP2r
( 128 <= c < 256 )
@draw-8bit ( 8bit^ -> )
#80 SUB ;load-tile JSR2
.tint LDZ #05 EOR .Screen/sprite DEO
JMP2r
( 128 1-bit 8x8 tiles for ASCII 7-bit characters )
@ascii
~chr/ascii.tal
( cyber background )
@cyber
~chr/cyber.tal
( screen to store characters for redraw, etc. )
@screen $0800 ( 64 x 32 )
@end-screen
( northwest=10 north=40 northeast=28 )
( west=30 center=56 east=38 )
( southwest=20 south=48 southeast=08 )
@bg-layout $0800