(screen.tal) Optimizations

This commit is contained in:
neauoire 2022-11-10 09:21:02 -08:00
parent 4270d48422
commit adae0a0348
5 changed files with 19 additions and 481 deletions

View File

@ -27,7 +27,7 @@
.DateTime/year DEI2 #a0 SFT2 EOR2 ;prng/y STA2
;prng/x LDA2 ;prng/y LDA2 EOR2
;rabbits STH2 #0f05 &loop-x
LIT2r =rabbits #0f05 &loop-x
#0f05 &loop-y
ROTk SWP STH2kr STA2 POP
INC2r INC2r

View File

@ -6,8 +6,8 @@
|0000
@count $2
@center &x $2 &y $2
@count $2
@center &x $2 &y $2
|0100 ( -> )
@ -60,11 +60,11 @@ BRK
#00 .Screen/auto DEO
( table )
;preview_icn .Screen/addr DEO2
#00 #00
#0000
&loop
( move ) DUP #0f AND #40 SFT #01 SFT #00 SWP
( move ) #00 OVR #0f AND [ #40 SFT #01 SFT ]
.center/x LDZ2 #0060 SUB2 ADD2 .Screen/x DEO2
( move ) DUP #f0 AND #01 SFT #00 SWP
( move ) #00 OVR #f0 AND #01 SFT
.center/y LDZ2 #0038 SUB2 ADD2 .Screen/y DEO2
( draw ) DUP .Screen/sprite DEO
INC NEQk ,&loop JCN
@ -74,13 +74,13 @@ JMP2r
@draw-1bpp ( -- )
#10 #00
#1000
&loop
( color ) STHk
( y ) DUP #02 SFT [ #00 SWP ] #40 SFT2
[ .center/y LDZ2 #0038 SUB2 ADD2 ] STH2
( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2
[ .center/x LDZ2 #0010 SUB2 ADD2 ]
( y ) #00 OVR #42 SFT2
.center/y LDZ2 #0038 SUB2 ADD2 STH2
( x ) #00 OVR #03 AND #40 SFT2 #0040 ADD2
.center/x LDZ2 #0010 SUB2 ADD2
STH2r STHr #00 ,draw-circle JSR
INC GTHk ,&loop JCN
POP2
@ -89,13 +89,13 @@ JMP2r
@draw-2bpp ( -- )
#10 #00
#1000
&loop
( color ) STHk
( y ) DUP #02 SFT [ #00 SWP ] #40 SFT2
[ .center/y LDZ2 #0008 ADD2 ADD2 ] STH2
( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2
[ .center/x LDZ2 #0010 SUB2 ADD2 ]
( y ) #00 OVR #42 SFT2
.center/y LDZ2 #0008 ADD2 ADD2 STH2
( x ) #00 OVR #03 AND #40 SFT2 #0040 ADD2
.center/x LDZ2 #0010 SUB2 ADD2
STH2r STHr #80 ,draw-circle JSR
INC GTHk ,&loop JCN
POP2
@ -121,14 +121,9 @@ JMP2r
@draw-short ( short* -- )
SWP ,draw-byte JSR
@draw-byte ( byte -- )
DUP #04 SFT ,draw-hex JSR #0f AND
@draw-hex ( char -- )
SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&hex JSR #0f AND
&hex ( char -- )
#00 SWP #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
#01 .Screen/sprite DEO

View File

@ -1,15 +0,0 @@
X::=~_
Y::=~*
Z::=~`
_.::=._X
_*::=*_Y
._|::=.Z-|
*_|::=Z
..-::=.-.
**-::=*-.
*.-::=*-*
.*-::=.-*
@.-::=@_.
@*-::=@_*
::=
@_*...............................|

View File

@ -1,287 +0,0 @@
( Copy of demos/life.tal, but with in infinite loop in the Screen vector )
( Game Of Life:
Any live cell with fewer than two live neighbours dies, as if by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. )
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|80 @Controller &vector $2 &button $1 &key $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1
|0000
@world &frame $1 &count $2
@anchor &x $2 &y $2 &x2 $2 &y2 $2
@pointer &x $2 &y $2
|0100 ( -> )
( theme )
#02cf .System/r DEO2
#02ff .System/g DEO2
#024f .System/b DEO2
( resize )
#00c0 .Screen/width DEO2
#00c0 .Screen/height DEO2
( vectors )
;on-frame .Screen/vector DEO2
;on-mouse .Mouse/vector DEO2
;on-control .Controller/vector DEO2
( glider )
#07 #03 ;set-cell JSR2
#07 #04 ;set-cell JSR2
#05 #04 ;set-cell JSR2
#07 #05 ;set-cell JSR2
#06 #05 ;set-cell JSR2
( center )
.Screen/width DEI2 #01 SFT2 #0040 SUB2
DUP2 .anchor/x STZ2
#007e ADD2 .anchor/x2 STZ2
.Screen/height DEI2 #01 SFT2 #0040 SUB2
DUP2 .anchor/y STZ2
#007e ADD2 .anchor/y2 STZ2
BRK
@on-frame ( -> )
( Because an interrupted infinite loop will (almost certainly) leave
items on the stacks, clear both stacks here. )
#00 .System/wst DEO
#00 .System/rst DEO
.Mouse/state DEI #00 EQU #01 JCN [ BRK ]
#0000 .world/count STZ2
.world/frame LDZ INC
DUP .world/frame STZ
#03 AND #00 EQU #01 JCN [ BRK ]
&infinite-loop
;run JSR2
,&infinite-loop JMP
&paused
BRK
@on-mouse ( -> )
( clear last cursor )
;cursor .Screen/addr DEO2
.pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2
#40 .Screen/sprite DEO
( record pointer positions )
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
( colorize on state )
#42 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/sprite DEO
( on touch in rect )
.Mouse/state DEI #00 NEQ #01 JCN [ BRK ]
.Mouse/x DEI2 .Mouse/y DEI2 .anchor ;within-rect JSR2 JMP [ BRK ]
( paint )
.Mouse/x DEI2 .anchor/x LDZ2 SUB2 #01 SFT NIP
.Mouse/y DEI2 .anchor/y LDZ2 SUB2 #01 SFT NIP
;set-cell JSR2
( draw )
;draw-grid JSR2
BRK
@on-control ( -> )
( toggle play )
.Controller/key DEI #20 NEQ ,&no-toggle JCN
;on-frame
.Screen/vector DEI2 ;on-frame/paused EQU2 ,&swap JCN
POP2 ;on-frame/paused
&swap
.Screen/vector DEO2
&no-toggle
( clear on home )
.Controller/button DEI #08 NEQ ,&no-reset JCN
;bank1 #0400 ;mclr JSR2
&no-reset
BRK
@run ( -- )
( clear buffer )
;bank2 #1000 ;mclr JSR2
( run grid )
#4000
&ver
STHk
#4000
&hor
DUP STHkr ,run-cell JSR
INC GTHk ,&hor JCN
POP2
POPr
INC GTHk ,&ver JCN
POP2
( move buffer )
;bank2 ;bank1 #1000 ;mcpy JSR2
( draw )
;draw-grid JSR2
JMP2r
@run-cell ( x y -- )
( x y ) DUP2
( neighbours ) DUP2 ;get-neighbours JSR2
( state ) ROT ROT ;get-cell JSR2
#00 EQU ,&dead JCN
DUP #02 LTH ,&dies JCN
DUP #03 GTH ,&dies JCN
POP ,&save JSR JMP2r
&dies POP POP2 JMP2r
&dead
DUP #03 EQU ,&birth JCN POP POP2 JMP2r
&birth POP ,&save JSR JMP2r
JMP2r
&save ( x y -- )
STH2 #01 STH2r ,get-index JSR [ #1000 ADD2 ] STA
.world/count LDZ2 INC2 .world/count STZ2
JMP2r
@get-index ( x y -- index* )
( y ) #3f AND #00 SWP #60 SFT2
( x ) ROT #3f AND #00 SWP ADD2
;bank1 ADD2
JMP2r
@set-cell ( x y -- )
STH2 #01 STH2r ,get-index JSR STA
JMP2r
@get-cell ( x y -- cell )
,get-index JSR LDA
JMP2r
@get-neighbours ( x y -- neighbours )
,&origin STR2
LITr 00
#0800
&loop
#00 OVR #10 SFT2 ;&mask ADD2 LDA2 [ LIT2 &origin $2 ]
ROT ADD STH ADD STHr ;get-cell JSR2 STH ADDr
INC GTHk ,&loop JCN
POP2
STHr
JMP2r
&mask ffff 00ff 01ff ff00 0100 ff01 0001 0101
@draw-grid ( -- )
( draw cell count )
.anchor/x LDZ2 .Screen/x DEO2
.anchor/y2 LDZ2 #0008 ADD2 .Screen/y DEO2
#01 .Screen/auto DEO
.world/count LDZ2 ;draw-short JSR2
#00 .Screen/auto DEO
#4000
&ver
#00 OVR #10 SFT2 .anchor/y LDZ2 ADD2 .Screen/y DEO2
STHk
#4000
&hor
#00 OVR #10 SFT2 .anchor/x LDZ2 ADD2 .Screen/x DEO2
DUP STHkr ;get-cell JSR2 INC .Screen/pixel DEO
INC GTHk ,&hor JCN
POP2
POPr
INC GTHk ,&ver JCN
POP2
JMP2r
@draw-short ( short* -- )
SWP ,draw-byte JSR
@draw-byte ( byte color -- )
DUP #04 SFT ,draw-hex JSR #0f AND
@draw-hex ( char color -- )
#00 SWP #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
#03 .Screen/sprite DEO
JMP2r
@within-rect ( x* y* rect -- flag )
STH
( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 LTH2 ,&skip JCN
( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN
SWP2
( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN
( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN
POP2 POP2 POPr
#01
JMP2r
&skip
POP2 POP2 POPr
#00
JMP2r
@mclr ( addr* len* -- )
OVR2 ADD2 SWP2
&loop
STH2k #00 STH2r STA
INC2 GTH2k ,&loop JCN
POP2 POP2
JMP2r
@mcpy ( src* dst* len* -- )
SWP2 STH2
OVR2 ADD2 SWP2
&loop
LDAk STH2kr STA INC2r
INC2 GTH2k ,&loop JCN
POP2 POP2
POP2r
JMP2r
@cursor
80c0 e0f0 f8e0 1000
@font-hex
7c82 8282 8282 7c00
3010 1010 1010 3800
7c82 027c 8080 fe00
7c82 021c 0282 7c00
2242 82fe 0202 0200
fe80 807c 0282 7c00
7c82 80fc 8282 7c00
fe82 0408 0810 1000
7c82 827c 8282 7c00
7c82 827e 0202 0200
7c82 82fe 8282 8200
fc82 82fc 8282 fc00
7c82 8080 8082 7c00
fc82 8282 8282 fc00
fe80 80f0 8080 fe00
fe80 80f0 8080 8000
@bank1 $1000 @bank2

View File

@ -1,155 +0,0 @@
( thue interpreter
usage: thue.rom demo.t )
|10 @Console &vector $2 &read $1 &pad $5 &write $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|0000
@src $40
@ptr $2
@len $2
|0100 ( -> )
;on-console .Console/vector DEO2
BRK
@on-console ( -> )
;src STH2
( read )
.Console/read DEI
DUP #20 LTH OVR #7f GTH ORA ,&end JCN
STH2kr ;slen JSR2 #003f GTH2 ,&end JCN
STH2r ;sput JSR2 BRK
&end
POP
( parse )
STH2r .File/name DEO2
#0001 .File/length DEO2
;program .ptr STZ2
&s
;&buf .File/read DEO2
.File/success DEI2 #0000 EQU2 ,&eof JCN
[ LIT &buf $1 ] ;walk JSR2
,&s JMP
&eof
( assemble )
;program/assembly .ptr STZ2
;program
&w
( save ) DUP2 .ptr LDZ2 STA2
( incr ) .ptr LDZ2k INC2 INC2 ROT STZ2
( next ) &eos INC2 LDAk ,&eos JCN INC2
LDAk ,&w JCN
( save acc )
INC2 ;program/accumulator ;scpy JSR2
( run )
&eval ,step JSR ,&eval JCN
#010f DEO
BRK
@step ( -- done )
;program/assembly
&while
DUP2 ;run-rule JSR2 ,&found JCN
#0004 ADD2 LDA2k ORA ,&while JCN
POP2
#00
JMP2r
&found #01 JMP2r
@walk ( char -- )
.ptr LDZ2 STA
( check for left-side )
.ptr LDZ2 #0002 SUB2 ;&marker ;scmp JSR2 #01 NEQ ,&no-marker JCN
#00 .ptr LDZ2 #0002 SUB2 STA
.ptr LDZ2k #0002 SUB2 ROT STZ2
.len LDZ2k INC2 ROT STZ2
&no-marker
( check for right-side )
.ptr LDZ2 LDA #0a NEQ ,&no-lb JCN
#00 .ptr LDZ2 STA
&no-lb
.ptr LDZ2k INC2 ROT STZ2
JMP2r
&marker "::= $1
@run-rule ( rule* -- )
LDA2k ,&a STR2
INC2 INC2 LDA2 ,&b STR2
;program/accumulator
&w
[ LIT2 &a $2 ] OVR2 ;sseg JSR2 #01 NEQ ,&no-found JCN
,&b LDR2 LDA LIT "~ EQU ,&output JCN
( shift ) DUP2 [ ,&b LDR2 ;slen JSR2 ,&a LDR2 ;slen JSR2 SUB2 ] ;ssft JSR2
( write ) [ LIT2 &b $2 ] SWP2 OVR2 ;slen JSR2 ;mcpy JSR2
POP2 #01 JMP2r
&no-found
INC2 LDAk ,&w JCN
POP2
#00
JMP2r
&output
,&a LDR2 ;slen JSR2 #0000 SWP2 SUB2 ;ssft JSR2
POP2 ,&b LDR2 INC2
LDAk LIT "` NEQ ,&no-lb JCN
#0a18 DEO #01 JMP2r
&no-lb
,print-str JSR #01
JMP2r
@print-str ( str* -- )
&while
LDAk #18 DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@ssft ( str* len* -- )
STH2 DUP2k ;slen JSR2 ADD2 STH2r
DUP2 #8000 GTH2 ,&l JCN
ORAk ,&r JCN
POP2 POP2 POP2
JMP2r
&l #8000 SWP2 SUB2 #8000 ADD2 ,msfl JSR JMP2r
&r ,msfr JSR JMP2r
( stdlib )
@mcpy ( src* dst* len* -- ) SWP2 STH2 OVR2 ADD2 SWP2 &l LDAk STH2kr STA INC2r INC2 GTH2k ,&l JCN POP2 POP2 POP2r JMP2r
@msfl ( b* a* len* -- ) STH2 SWP2 EQU2k ,&e JCN &l DUP2k STH2kr ADD2 LDA ROT ROT STA INC2 GTH2k ,&l JCN POP2 POP2 &e POP2r JMP2r
@msfr ( b* a* len* -- ) STH2 EQU2k ,&e JCN &l DUP2 LDAk ROT ROT STH2kr ADD2 STA #0001 SUB2 LTH2k ,&l JCN POP2 POP2 &e POP2r JMP2r
@scap ( str* -- end* ) LDAk #00 NEQ JMP JMP2r &w INC2 LDAk ,&w JCN JMP2r
@sput ( chr str* -- ) ,scap JSR STA JMP2r
@slen ( str* -- len* ) DUP2 ,scap JSR SWP2 SUB2 JMP2r
@scpy ( src* dst* -- ) STH2 &w LDAk STH2kr STA INC2r INC2 LDAk ,&w JCN POP2 #00 STH2r STA JMP2r
@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ,&e JCN NEQk ,&e JCN POP2 INC2 INC2r ,&l JMP &e NIP2 POP2r EQU JMP2r
@sseg ( a* b* -- f ) STH2 &l LDAk LDAkr STHr NEQ ,&e JCN INC2k LDA #00 EQU ,&e JCN INC2 INC2r ,&l JMP &e LDA LDAr STHr EQU JMP2r
$10
@program $4000
&assembly $4000
&accumulator $4000