(life.tal) Minor cleanup

This commit is contained in:
neauoire 2022-02-08 20:04:18 -08:00
parent db431f75fe
commit 5abb885eb5
1 changed files with 66 additions and 44 deletions

View File

@ -4,9 +4,9 @@
Any live cell with more than three live neighbours dies, as if by overpopulation. 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. ) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. )
%+ { ADD } %- { SUB } %+ { ADD } %- { SUB }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ } %< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %++ { ADD2 } %-- { SUB2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
%2/ { #01 SFT } %2/ { #01 SFT }
@ -16,17 +16,19 @@
%40** { #60 SFT2 } %40** { #60 SFT2 }
%8MOD { #07 AND } %2MOD { #01 AND } %8MOD { #07 AND } %2MOD { #01 AND }
%TOS { #00 SWP } %TOS { #00 SWP }
%RTN { JMP2r } %RTN { JMP2r }
%SFL { #40 SFT SFT } %SFL { #40 SFT SFT }
%WIDTH { #40 } %HEIGHT { #40 } %WIDTH { #40 }
%WIDTH-MOD { #3f AND } %HEIGHT-MOD { #3f AND } %HEIGHT { #40 }
%LENGTH { #0200 }
%WIDTH-MOD { #3f AND }
%HEIGHT-MOD { #3f AND }
%IN-RANGE { INCk SWP SUB2 GTH } %IN-RANGE { INCk SWP SUB2 GTH }
%BANK1 { #8000 } %BANK2 { #a000 } %BANK1 { #8000 } %BANK2 { #a000 }
%GET-SIZE { WIDTH TOS 8// 40** }
%GET-ITERATORS { SWP2k POP NIP } %GET-ITERATORS { SWP2k POP NIP }
%GET-ITER { OVR2 NIP OVR SWP } %GET-ITER { OVR2 NIP OVR SWP }
@ -37,7 +39,7 @@
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ] |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 ] |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 |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 ] |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 ] |80 @Controller [ &vector $2 &button $1 &key $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
@ -55,9 +57,9 @@
|0100 ( -> ) |0100 ( -> )
( theme ) ( theme )
#02cf .System/r DEO2 #02cf .System/r DEO2
#02ff .System/g DEO2 #02ff .System/g DEO2
#024f .System/b DEO2 #024f .System/b DEO2
( vectors ) ( vectors )
@ -89,14 +91,10 @@ BRK
( incr frame ) .world/frame LDZ INC [ DUP ] .world/frame STZ ( incr frame ) .world/frame LDZ INC [ DUP ] .world/frame STZ
( reset count ) #0000 .world/count STZ2 ( reset count ) #0000 .world/count STZ2
#03 AND #00 = #01 JCN [ BRK ] #03 AND #00 = #01 JCN [ BRK ]
( clear buffer ) ( clear buffer )
BANK2 STH2k GET-SIZE ++ STH2r BANK2 LENGTH ;mclr JSR2
&clear-loop
DUP2 #0000 SWP2 STA2
INC2 INC2 GTH2k ,&clear-loop JCN
POP2 POP2
( run grid ) ( run grid )
#00 HEIGHT #00 HEIGHT
@ -116,12 +114,7 @@ BRK
POP2 POP2
( move buffer ) ( move buffer )
BANK2 DUP2 GET-SIZE ++ SWP2 BANK2 BANK1 LENGTH ;mcpy JSR2
&copy-loop
DUP2 LDA2k
SWP2 #2000 -- STA2
INC2 INC2 GTH2k ,&copy-loop JCN
POP2 POP2
;draw-grid JSR2 ;draw-grid JSR2
@ -150,7 +143,7 @@ RTN
.world/count LDZ2 INC2 .world/count STZ2 .world/count LDZ2 INC2 .world/count STZ2
( save in buffer ) ( save in buffer )
STH2 STH2
DUP2 POP 8MOD #01 SWP SFL DUP2 POP 8MOD #01 SWP SFL
LDAkr STHr SWP ORA LDAkr STHr SWP ORA
STH2r STA STH2r STA
@ -159,14 +152,14 @@ RTN
@on-mouse ( -> ) @on-mouse ( -> )
( clear last cursor ) ( clear last cursor )
;cursor .Screen/addr DEO2 ;cursor .Screen/addr DEO2
.pointer/x LDZ2 .Screen/x DEO2 .pointer/x LDZ2 .Screen/x DEO2
.pointer/y LDZ2 .Screen/y DEO2 .pointer/y LDZ2 .Screen/y DEO2
#40 .Screen/sprite DEO #40 .Screen/sprite DEO
( record pointer positions ) ( record pointer positions )
.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
( colorize on state ) ( colorize on state )
#42 [ .Mouse/state DEI #00 ! ] + .Screen/sprite DEO #42 [ .Mouse/state DEI #00 ! ] + .Screen/sprite DEO
@ -187,8 +180,6 @@ BRK
@on-control ( -> ) @on-control ( -> )
.Controller/key DEI #00 ! #01 JCN [ BRK ]
.Controller/key DEI #20 ! ,&no-toggle JCN .Controller/key DEI #20 ! ,&no-toggle JCN
;on-frame ;on-frame
.Screen/vector DEI2 ;on-frame-paused == ,&swap JCN .Screen/vector DEI2 ;on-frame-paused == ,&swap JCN
@ -197,6 +188,11 @@ BRK
.Screen/vector DEO2 .Screen/vector DEO2
&no-toggle &no-toggle
.Controller/button DEI #08 ! ,&no-reset JCN
BANK1 #1000 ;mclr JSR2
BANK2 #1000 ;mclr JSR2
&no-reset
BRK BRK
@draw-grid ( -- ) @draw-grid ( -- )
@ -210,10 +206,10 @@ BRK
HEIGHT #00 HEIGHT #00
&ver &ver
#00 OVR 2** .anchor/y LDZ2 ++ .Screen/y DEO2 DUP TOS 2** .anchor/y LDZ2 ++ .Screen/y DEO2
WIDTH #00 WIDTH #00
&hor &hor
#00 OVR 2** .anchor/x LDZ2 ++ .Screen/x DEO2 DUP TOS 2** .anchor/x LDZ2 ++ .Screen/x DEO2
GET-ITER ,get-cell JSR INC .Screen/pixel DEO GET-ITER ,get-cell JSR INC .Screen/pixel DEO
INC GTHk ,&hor JCN INC GTHk ,&hor JCN
POP2 POP2
@ -232,7 +228,7 @@ RTN
@set-cell ( x y -- ) @set-cell ( x y -- )
DUP2 ,get-index JSR STH2 DUP2 ,get-index JSR STH2
POP 8MOD #01 SWP SFL POP 8MOD #01 SWP SFL
LDAkr STHr SWP ORA LDAkr STHr SWP ORA
STH2r STA STH2r STA
@ -249,12 +245,12 @@ RTN
@get-cell ( x y -- cell ) @get-cell ( x y -- cell )
DUP2 ,get-index JSR LDA DUP2 ,get-index JSR LDA
NIP SWP NIP SWP
8MOD 8MOD
SFT 2MOD SFT 2MOD
RTN RTN
@get-neighbours ( x y -- neighbours ) @get-neighbours ( x y -- neighbours )
@ -272,21 +268,47 @@ RTN
@draw-short ( short* color -- ) @draw-short ( short* color -- )
;draw-char/color STA STH
SWP ,draw-byte JSR SWP STHkr ,draw-byte JSR
STHr
@draw-byte ( byte -- ) @draw-byte ( byte color -- )
DUP #04 SFT ,draw-char JSR STH
#0f AND DUP #04 SFT STHkr ,draw-hex JSR #0f AND
STHr
@draw-char ( char -- ) @draw-hex ( char color -- )
TOS 8** ;font-hex ++ .Screen/addr DEO2 SWP TOS 8** ;font-hex ++ .Screen/addr DEO2
[ LIT &color $1 ] .Screen/sprite DEO .Screen/sprite DEO
RTN RTN
@mclr ( addr* len* -- )
OVR2 ++ SWP2
&loop
STH2k #00 STH2r STA
INC2 GTH2k ,&loop JCN
POP2 POP2
JMP2r
@mcpy ( src* dst* len* -- )
SWP2 STH2
OVR2 ++ SWP2
&loop
LDAk STH2kr STA INC2r
INC2 GTH2k ,&loop JCN
POP2 POP2
POP2r
JMP2r
( input )
@on-input ( -> ) @on-input ( -> )
,&main JSR ,&main JSR
BRK BRK
@ -347,7 +369,7 @@ RTN
;on-input .Console/vector DEO2 ;on-input .Console/vector DEO2
BRK BRK
@cursor @cursor
80c0 e0f0 f8e0 1000 80c0 e0f0 f8e0 1000
@font-hex @font-hex