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