67 lines
1.5 KiB
Tal
67 lines
1.5 KiB
Tal
( rainbow.tal )
|
|
|
|
%emit { #18 DEO }
|
|
%rows { #0018 }
|
|
%cols { #0050 }
|
|
%mod { DIVk MUL SUB }
|
|
%mod2 { DIV2k MUL2 SUB2 }
|
|
|
|
|0000
|
|
|
|
( pseudo-random number generator )
|
|
@rng [ &x $2 &y $2 ]
|
|
|
|
( read in regular expressions )
|
|
( and emit internal structures parsed )
|
|
|0100
|
|
;init-rng JSR2 ;draw #20 DEO2 BRK
|
|
|
|
( works for 0 <= n < 100 )
|
|
@emit-decimal ( n^ -> )
|
|
STHk #0a LTH ,&small JCN
|
|
STHkr #0a DIV LIT '0 ADD emit
|
|
&small STHr #0a mod LIT '0 ADD emit
|
|
JMP2r
|
|
|
|
( move to random spot, choose random color, draw char )
|
|
@random-pixel
|
|
#5b1b emit emit ( esc [ )
|
|
;random-short JSR2 rows mod2 NIP ;emit-decimal JSR2
|
|
LIT '; emit
|
|
;random-short JSR2 cols mod2 NIP ;emit-decimal JSR2
|
|
LIT 'H emit
|
|
|
|
#5b1b emit emit ( esc [ )
|
|
#3b31 emit emit ( 1 ; )
|
|
;random-short JSR2 #000a mod2 NIP #1e ADD ;emit-decimal JSR2
|
|
LIT 'm emit
|
|
|
|
LIT '# emit JMP2r
|
|
|
|
@draw ( -> )
|
|
;random-pixel JSR2
|
|
;random-pixel JSR2
|
|
;random-pixel JSR2
|
|
;random-pixel JSR2
|
|
BRK
|
|
|
|
@init-rng ( -> )
|
|
#00 #b5 DEI #003c MUL2
|
|
#00 #b6 DEI ADD2
|
|
#0001 ORA2 .rng/x STZ2
|
|
|
|
#00 #b3 DEI #0018 MUL2
|
|
#00 #b4 DEI ADD2
|
|
#0001 ORA2 .rng/y STZ2 JMP2r
|
|
|
|
@random-byte ( -> val^ )
|
|
;random-short JSR2 POP JMP2r
|
|
|
|
@random-short ( -> val* )
|
|
.rng/x LDZ2 DUP2 #50 SFT2 EOR2 ( tmp: x^[x<<5] )
|
|
.rng/y LDZ2 DUP2 .rng/x STZ2 ( tmp y )
|
|
DUP2 #01 SFT2 EOR2 ( tmp y^[y>>1] )
|
|
SWP2 DUP2 #03 SFT2 EOR2 ( y^[y>>1] tmp^[tmp>>3] )
|
|
EOR2 DUP2 .rng/y STZ2 ( y^[y>>1] ^ tmp^[tmp>>3] )
|
|
JMP2r
|