-
Notifications
You must be signed in to change notification settings - Fork 1
/
prng.tal
64 lines (51 loc) · 1.24 KB
/
prng.tal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
( variables )
|0000
( program )
|0100 ( -> )
( theme )
#0fff .System/r DEO2
#0fff .System/g DEO2
#0fff .System/b DEO2
( random seed )
#01 ;rand/a STA
( vector )
;on-frame .Screen/vector DEO2
BRK
@on-frame ( -- )
( y = 0 )
#00
&loop-y
( y -> Screen/y )
DUP #00 SWP .Screen/y DEO2
( r = rand, x = 0 )
;rand JSR2 #00
&loop-x
( x -> Screen/x )
DUP #00 SWP .Screen/x DEO2
( x < r -> Screen/pixel )
GTHk .Screen/pixel DEO
( loop until ++x == 0 )
INC DUP ,&loop-x JCN
POP2
( loop until ++y == 0 )
INC DUP ,&loop-y JCN
POP
BRK
@rand ( -- number )
( 8-bit PRNG https://github.com/edrosten/8bit_rng )
( t = x ^ (x << 4) )
,&x LDR DUP #40 SFT EOR
( x = y )
,&y LDR ,&x STR
( y = z )
,&z LDR ,&y STR
( z = a )
,&a LDR DUP ,&z STR
( a = z ^ t ^ (z >> 1) ^ (t << 1) )
DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR
DUP ,&a STR
JMP2r
&x $1 &y $1 &z $1 &a $1