prng.tal (1939B)
1 ( pseudo-random number generator, 2 based on two 16-bit xorshift algorithms by George Marsaglia 3 http://www.jstatsoft.org/v08/i14/paper ) 4 5 ( devices ) 6 7 |00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] 8 |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 9 |c0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] 10 11 ( variables ) 12 13 |0000 14 15 ( program ) 16 17 |0100 ( -> ) 18 ( init ) 19 ;on-frame .Screen/vector DEO2 20 21 ( seed prng (must be nonzero) ) 22 #00 .DateTime/second DEI 23 #00 .DateTime/minute DEI #60 SFT2 EOR2 24 #00 .DateTime/hour DEI #c0 SFT2 EOR2 ;prng2/x STA2 25 #00 .DateTime/hour DEI #04 SFT2 26 #00 .DateTime/day DEI #10 SFT2 EOR2 27 #00 .DateTime/month DEI #60 SFT2 EOR2 28 .DateTime/year DEI2 #a0 SFT2 EOR2 ;prng2/y STA2 29 ;prng2/x LDA2 ;prng2/y LDA2 EOR2 30 ORAk ,&non-zero JCN INC2 &non-zero 31 ;prng/seed STA2 32 33 ( theme ) 34 #0fe5 .System/r DEO2 35 #0fc5 .System/g DEO2 36 #0f25 .System/b DEO2 37 BRK 38 39 @on-frame ( -> ) 40 #c0 41 &loop 42 ,draw-pixel JSR 43 INC 44 DUP ,&loop JCN 45 POP 46 BRK 47 48 @draw-pixel 49 ,prng2 JSR 50 #00 SWP .Screen/x DEO2 51 #00 SWP .Screen/y DEO2 52 #01 .Screen/pixel DEO 53 JMP2r 54 55 @prng ( -- number* ) 56 ( returns the next number in a 65,535-long sequence, 57 which is never zero but every other 16-bit number 58 appears once before the sequence repeats ) 59 ( http://www.retroprogramming.com/2017/07/xorshift-pseudorandom-numbers-in-z80.html ) 60 ,&seed LDR2 61 DUP2 #70 SFT2 EOR2 62 DUP2 #09 SFT2 EOR2 63 DUP2 #80 SFT2 EOR2 64 ,&seed STR2k POP 65 JMP2r 66 67 &seed $2 68 69 @prng2 ( -- number* ) 70 ( returns the next number in a (2^32-1)-long sequence ) 71 ( http://b2d-f9r.blogspot.com/2010/08/16-bit-xorshift-rng-now-with-more.html ) 72 ,&x LDR2 73 DUP2 #50 SFT2 EOR2 74 DUP2 #03 SFT2 EOR2 75 ,&y LDR2 DUP2 ,&x STR2 76 DUP2 #01 SFT2 EOR2 EOR2 77 ,&y STR2k POP 78 JMP2r 79 80 &x $2 81 &y $2 82