| 49 | 49 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,119 @@ |
| 1 |
+( Project by Alex Schroeder - https://alexschroeder.ch ) |
|
| 2 |
+ |
|
| 3 |
+%RTN { JMP2r }
|
|
| 4 |
+%INCR { SWP #01 ADD SWP }
|
|
| 5 |
+%CELL { #1000 }
|
|
| 6 |
+%NEXT { #2000 }
|
|
| 7 |
+ |
|
| 8 |
+( devices ) |
|
| 9 |
+ |
|
| 10 |
+|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
| 11 |
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] |
|
| 12 |
+|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
|
| 13 |
+ |
|
| 14 |
+|0000 |
|
| 15 |
+ |
|
| 16 |
+( program ) |
|
| 17 |
+ |
|
| 18 |
+@seed [ &x $1 &w $2 &s $2 ] |
|
| 19 |
+ |
|
| 20 |
+|0100 ( -> ) |
|
| 21 |
+ |
|
| 22 |
+ ( theme ) |
|
| 23 |
+ #2aac .System/r DEO2 |
|
| 24 |
+ #269b .System/g DEO2 |
|
| 25 |
+ #378d .System/b DEO2 |
|
| 26 |
+ |
|
| 27 |
+ ;seed-line JSR2 |
|
| 28 |
+ |
|
| 29 |
+ ( run for a few generations ) |
|
| 30 |
+ #00 #ff |
|
| 31 |
+ &loop |
|
| 32 |
+ OVR #00 SWP ;print-line JSR2 |
|
| 33 |
+ ;compute-next JSR2 |
|
| 34 |
+ ;copy-next JSR2 |
|
| 35 |
+ ( incr ) INCR |
|
| 36 |
+ ( loop ) LTHk ,&loop JCN |
|
| 37 |
+ POP2 |
|
| 38 |
+ |
|
| 39 |
+BRK |
|
| 40 |
+ |
|
| 41 |
+@print-line ( y -- ) |
|
| 42 |
+ |
|
| 43 |
+ ( set ) .Screen/y DEO2 |
|
| 44 |
+ ( loop through cells ) |
|
| 45 |
+ #00 #ff |
|
| 46 |
+ &loop |
|
| 47 |
+ ( copy ) OVR #00 SWP DUP2 |
|
| 48 |
+ ( pos ) .Screen/x DEO2 |
|
| 49 |
+ ( addr ) CELL ADD2 |
|
| 50 |
+ ( draw ) LDA .Screen/color DEO |
|
| 51 |
+ ( incr ) INCR |
|
| 52 |
+ ( loop ) LTHk ,&loop JCN |
|
| 53 |
+ POP2 |
|
| 54 |
+ |
|
| 55 |
+RTN |
|
| 56 |
+ |
|
| 57 |
+@compute-next ( -- ) |
|
| 58 |
+ |
|
| 59 |
+ ( loop through 62 cells ) |
|
| 60 |
+ #01 #fe |
|
| 61 |
+ &loop |
|
| 62 |
+ OVR DUP DUP ( three copies of the counter ) |
|
| 63 |
+ #01 SUB #00 SWP CELL ADD2 LDA |
|
| 64 |
+ SWP |
|
| 65 |
+ #01 ADD #00 SWP CELL ADD2 LDA |
|
| 66 |
+ ( the cell dies if the neighbors are either both dead or both alive, i.e. Rule 90 ) |
|
| 67 |
+ NEQ |
|
| 68 |
+ ( one copy of the counter and the life value ) |
|
| 69 |
+ SWP #00 SWP NEXT ADD2 STA |
|
| 70 |
+ ( incr ) INCR |
|
| 71 |
+ ( loop ) LTHk ,&loop JCN |
|
| 72 |
+ POP2 |
|
| 73 |
+ |
|
| 74 |
+RTN |
|
| 75 |
+ |
|
| 76 |
+@copy-next ( -- ) |
|
| 77 |
+ |
|
| 78 |
+ ( loop through cells ) |
|
| 79 |
+ #00 #ff |
|
| 80 |
+ &loop |
|
| 81 |
+ OVR DUP ( two copies of the counter ) |
|
| 82 |
+ #00 SWP NEXT ADD2 LDA ( one copy of the counter and the value ) |
|
| 83 |
+ SWP #00 SWP CELL ADD2 STA |
|
| 84 |
+ ( incr ) INCR |
|
| 85 |
+ ( loop ) LTHk ,&loop JCN |
|
| 86 |
+ POP2 |
|
| 87 |
+ |
|
| 88 |
+RTN |
|
| 89 |
+ |
|
| 90 |
+@seed-line ( -- ) |
|
| 91 |
+ |
|
| 92 |
+ .DateTime/second DEI .seed/x STZ |
|
| 93 |
+ #0000 .seed/w STZ2 |
|
| 94 |
+ #e2a9 .seed/s STZ2 |
|
| 95 |
+ ( loop through cells ) |
|
| 96 |
+ #01 #fe |
|
| 97 |
+ &loop |
|
| 98 |
+ OVR ( one copy of the counter ) |
|
| 99 |
+ ;rand JSR2 |
|
| 100 |
+ #10 AND ( pick a bit ) |
|
| 101 |
+ SWP #00 SWP CELL ADD2 STA |
|
| 102 |
+ ( incr ) INCR |
|
| 103 |
+ ( loop ) LTHk ,&loop JCN |
|
| 104 |
+ POP2 |
|
| 105 |
+ |
|
| 106 |
+RTN |
|
| 107 |
+ |
|
| 108 |
+( https://en.wikipedia.org/wiki/Middle-square_method ) |
|
| 109 |
+ |
|
| 110 |
+@rand ( -- 1 ) |
|
| 111 |
+ |
|
| 112 |
+ .seed/x LDZ #00 SWP DUP2 MUL2 |
|
| 113 |
+ .seed/w LDZ2 .seed/s LDZ2 ADD2 |
|
| 114 |
+ DUP2 .seed/w STZ2 |
|
| 115 |
+ ADD2 |
|
| 116 |
+ #04 SFT SWP #40 SFT ADD |
|
| 117 |
+ DUP .seed/x STZ |
|
| 118 |
+ |
|
| 119 |
+RTN |
|
| 0 | 120 |
\ No newline at end of file |
| ... | ... |
@@ -160,4 +160,28 @@ RTN |
| 160 | 160 |
|
| 161 | 161 |
RTN |
| 162 | 162 |
|
| 163 |
+@line-hor ( x0* x1* y* color -- ) |
|
| 164 |
+ |
|
| 165 |
+ STH .Screen/y DEO2 |
|
| 166 |
+ &loop |
|
| 167 |
+ ( save ) OVR2 .Screen/x DEO2 |
|
| 168 |
+ ( draw ) STHkr .Screen/color DEO |
|
| 169 |
+ ( incr ) SWP2 #0002 ++ SWP2 |
|
| 170 |
+ LTH2k ,&loop JCN |
|
| 171 |
+ POP2 POP2 POPr |
|
| 172 |
+ |
|
| 173 |
+RTN |
|
| 174 |
+ |
|
| 175 |
+@line-ver ( x* y0* y1* color -- ) |
|
| 176 |
+ |
|
| 177 |
+ STH ROT2 .Screen/x DEO2 |
|
| 178 |
+ &loop |
|
| 179 |
+ ( save ) OVR2 .Screen/y DEO2 |
|
| 180 |
+ ( draw ) STHkr .Screen/color DEO |
|
| 181 |
+ ( incr ) SWP2 #0002 ++ SWP2 |
|
| 182 |
+ LTH2k ,&loop JCN |
|
| 183 |
+ POP2 POP2 POPr |
|
| 184 |
+ |
|
| 185 |
+RTN |
|
| 186 |
+ |
|
| 163 | 187 |
@checker_icn [ f0f0 f0f0 0f0f 0f0f ] |