| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,230 @@ |
| 1 |
+( devices ) |
|
| 2 |
+ |
|
| 3 |
+|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
|
| 4 |
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
| 5 |
+|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
|
| 6 |
+ |
|
| 7 |
+( variables ) |
|
| 8 |
+ |
|
| 9 |
+|0000 |
|
| 10 |
+ |
|
| 11 |
+( program ) |
|
| 12 |
+ |
|
| 13 |
+|0100 @Reset ( -> ) |
|
| 14 |
+ ( seed prng (must be nonzero) ) |
|
| 15 |
+ #00 .DateTime/second DEI |
|
| 16 |
+ #00 .DateTime/minute DEI #60 SFT2 EOR2 |
|
| 17 |
+ #00 .DateTime/hour DEI #c0 SFT2 EOR2 ;prng/x STA2 |
|
| 18 |
+ #00 .DateTime/hour DEI #04 SFT2 |
|
| 19 |
+ #00 .DateTime/day DEI #10 SFT2 EOR2 |
|
| 20 |
+ #00 .DateTime/month DEI #60 SFT2 EOR2 |
|
| 21 |
+ .DateTime/year DEI2 #a0 SFT2 EOR2 ;prng/y STA2 |
|
| 22 |
+ ;prng/x LDA2 ;prng/y LDA2 EOR2 |
|
| 23 |
+ |
|
| 24 |
+ ;rabbits STH2 #0f05 &loop-x |
|
| 25 |
+ #0f05 &loop-y |
|
| 26 |
+ ROTk SWP STH2kr STA2 POP |
|
| 27 |
+ INC2r INC2r |
|
| 28 |
+ INC |
|
| 29 |
+ GTHk ,&loop-y JCN |
|
| 30 |
+ POP2 |
|
| 31 |
+ INC |
|
| 32 |
+ GTHk ,&loop-x JCN |
|
| 33 |
+ POP2 POP2r |
|
| 34 |
+ ( fall through ) |
|
| 35 |
+ |
|
| 36 |
+@repeat |
|
| 37 |
+ ;init-occupancy JSR2 |
|
| 38 |
+ #00 ;precalc-frame STA |
|
| 39 |
+ ;precalculate-vector .Screen/vector DEO2 |
|
| 40 |
+ BRK |
|
| 41 |
+ |
|
| 42 |
+@init-occupancy ( -- ) |
|
| 43 |
+ #1400 &loop-y |
|
| 44 |
+ #1400 &loop-x |
|
| 45 |
+ ROTk #00 ;set-occupied JSR2 POP |
|
| 46 |
+ INC |
|
| 47 |
+ GTHk ,&loop-x JCN |
|
| 48 |
+ POP2 |
|
| 49 |
+ INC |
|
| 50 |
+ GTHk ,&loop-y JCN |
|
| 51 |
+ POP2 |
|
| 52 |
+ ;rabbits |
|
| 53 |
+ DUP2 #00c8 ADD2 SWP2 &loop-rabbits |
|
| 54 |
+ LDA2k #01 ;set-occupied JSR2 |
|
| 55 |
+ INC2 INC2 |
|
| 56 |
+ GTH2k ,&loop-rabbits JCN |
|
| 57 |
+ POP2 POP2 |
|
| 58 |
+ JMP2r |
|
| 59 |
+ |
|
| 60 |
+@precalculate-vector ( -> ) |
|
| 61 |
+ ,precalculate JSR BRK |
|
| 62 |
+ |
|
| 63 |
+@precalculate ( -- ) |
|
| 64 |
+ ;rabbits #00c8 OVR ,precalc-frame LDR MUL2 ADD2 ( first rabbit address ) |
|
| 65 |
+ DUP2 #00c8 ADD2 SWP2 &loop-rabbits |
|
| 66 |
+ DUP2 ,move-rabbit JSR |
|
| 67 |
+ INC2 INC2 |
|
| 68 |
+ GTH2k ,&loop-rabbits JCN |
|
| 69 |
+ POP2 POP2 |
|
| 70 |
+ ,precalc-frame LDR INC DUP ,precalc-frame STR |
|
| 71 |
+ #05 EQU JMP JMP2r |
|
| 72 |
+ ;display-init JSR2 |
|
| 73 |
+ ;display .Screen/vector DEO2 |
|
| 74 |
+ JMP2r |
|
| 75 |
+ |
|
| 76 |
+@precalc-frame $1 |
|
| 77 |
+ |
|
| 78 |
+@set-occupied ( x y value -- ) |
|
| 79 |
+ STH |
|
| 80 |
+ #00 SWP #0014 MUL2 ( x yoffset* / value ) |
|
| 81 |
+ ROT #00 SWP ADD2 ( offset* / value ) |
|
| 82 |
+ ;occupied ADD2 STH2 STAr |
|
| 83 |
+ JMP2r |
|
| 84 |
+ |
|
| 85 |
+@move-rabbit ( addr* -- ) |
|
| 86 |
+ STH2k LDA2 ( x y / addr* ) |
|
| 87 |
+ DUP2 #00 ,set-occupied JSR |
|
| 88 |
+ ;&possible-moves ( x y possible* / addr* ) |
|
| 89 |
+ OVR2 #01 SUB ,&check-move JSR ( up ) |
|
| 90 |
+ OVR2 #01 ADD ,&check-move JSR ( down ) |
|
| 91 |
+ OVR2 #0100 SUB2 ,&check-move JSR ( left ) |
|
| 92 |
+ OVR2 #0100 ADD2 ,&check-move JSR ( right ) |
|
| 93 |
+ ;&possible-moves SUB2 ( x y num-possible-times-2* / addr* ) |
|
| 94 |
+ DUP ,&can-move JCN |
|
| 95 |
+ POP2 |
|
| 96 |
+ &write ( x y / addr* ) |
|
| 97 |
+ DUP2 #01 ,set-occupied JSR |
|
| 98 |
+ STH2r #00c8 ADD2 STA2 |
|
| 99 |
+ JMP2r |
|
| 100 |
+ |
|
| 101 |
+ &can-move ( x y num-possible-times-2* / addr* ) |
|
| 102 |
+ NIP2 ( num-possible-times-2* / addr* ) |
|
| 103 |
+ ,prng JSR SWP2 DIV2k MUL2 SUB2 #fe AND ( chosen-move* / addr* ) |
|
| 104 |
+ ;&possible-moves ADD2 LDA2 |
|
| 105 |
+ ,&write JMP |
|
| 106 |
+ |
|
| 107 |
+ &check-move ( possible* new-x new-y -- possible'* ) |
|
| 108 |
+ DUP2 ,get-occupied JSR ,&blocked JCN |
|
| 109 |
+ OVR2r LIT2r 00c8 SUB2r ( possible* new-x new-y / previous-frame-addr* ) |
|
| 110 |
+ &check-history-loop |
|
| 111 |
+ ;rabbits INC2 STH2kr GTH2 ,&history-okay JCN |
|
| 112 |
+ DUP2 STH2kr LDA2 EQU2 ,&history-clash JCN |
|
| 113 |
+ LIT2r 00c8 SUB2r |
|
| 114 |
+ ,&check-history-loop JMP |
|
| 115 |
+ &history-okay |
|
| 116 |
+ POP2r |
|
| 117 |
+ OVR2 STA2 INC2 INC2 |
|
| 118 |
+ JMP2r |
|
| 119 |
+ &history-clash ( possible* new-x new-y / previous-frame-addr* ) |
|
| 120 |
+ POP2r |
|
| 121 |
+ &blocked ( possible* new-x new-y ) |
|
| 122 |
+ POP2 |
|
| 123 |
+ JMP2r |
|
| 124 |
+ |
|
| 125 |
+ &possible-moves $10 |
|
| 126 |
+ |
|
| 127 |
+@get-occupied ( x y -- value ) |
|
| 128 |
+ #00 SWP #0014 MUL2 ( x yoffset* ) |
|
| 129 |
+ ROT #00 SWP ADD2 ( offset* ) |
|
| 130 |
+ ;occupied ADD2 LDA |
|
| 131 |
+ JMP2r |
|
| 132 |
+ |
|
| 133 |
+@prng ( -- number* ) |
|
| 134 |
+ LIT2 &x $2 |
|
| 135 |
+ DUP2 #50 SFT2 EOR2 |
|
| 136 |
+ DUP2 #03 SFT2 EOR2 |
|
| 137 |
+ LIT2 &y $2 DUP2 ,&x STR2 |
|
| 138 |
+ DUP2 #01 SFT2 EOR2 EOR2 |
|
| 139 |
+ ,&y STR2k POP |
|
| 140 |
+ JMP2r |
|
| 141 |
+ |
|
| 142 |
+@display-init ( -- ) |
|
| 143 |
+ .Screen/width DEI2 #01 SFT2 #0050 SUB2 ;display-rabbit/xoffset STA2 |
|
| 144 |
+ .Screen/height DEI2 #01 SFT2 #0050 SUB2 ;display-rabbit/yoffset STA2 |
|
| 145 |
+ ;rabbit-sprite .Screen/addr DEO2 |
|
| 146 |
+ JMP2r |
|
| 147 |
+ |
|
| 148 |
+@display-rabbit ( color n counter -- ) |
|
| 149 |
+ OVR LTHk ,&finish JCN |
|
| 150 |
+ SUB ( color n timeline ) |
|
| 151 |
+ DUP #63 GTH ,&start JCN |
|
| 152 |
+ #17 DIVk STHk MUL SUB ( color n stage-timeline / frame ) |
|
| 153 |
+ DUP #07 GTH ,&static JCN |
|
| 154 |
+ ( rabbit is in-between two frames ) |
|
| 155 |
+ #08 OVR SUB ,&from-weight STR |
|
| 156 |
+ ,&to-weight STR ( color n / frame ) |
|
| 157 |
+ #00 SWP #10 SFT2 ;rabbits ADD2 #00c8 #00 STHr MUL2 ADD2 ( color from-addr* ) |
|
| 158 |
+ LDA2k STH2 #00c8 ADD2 LDA2 |
|
| 159 |
+ &draw ( color to-x to-y / from-x from-y ) |
|
| 160 |
+ STHr ,&mix JSR LIT2 &yoffset $2 ADD2 .Screen/y DEO2 |
|
| 161 |
+ STHr ,&mix JSR LIT2 &xoffset $2 ADD2 .Screen/x DEO2 |
|
| 162 |
+ .Screen/sprite DEO |
|
| 163 |
+ JMP2r |
|
| 164 |
+ |
|
| 165 |
+ &mix ( to-z from-z -- mixed* ) |
|
| 166 |
+ #00 SWP LIT2 00 &from-weight 00 MUL2 ( to-n from-mixed* ) |
|
| 167 |
+ ROT #00 SWP LIT2 00 &to-weight 00 MUL2 ADD2 |
|
| 168 |
+ JMP2r |
|
| 169 |
+ |
|
| 170 |
+ &finish ( color n counter n ) |
|
| 171 |
+ POP |
|
| 172 |
+ LITr ff ,&static JMP |
|
| 173 |
+ &start ( color n counter ) |
|
| 174 |
+ LITr 04 |
|
| 175 |
+ &static ( color n counter / frame ) |
|
| 176 |
+ INCr |
|
| 177 |
+ POP |
|
| 178 |
+ #00 SWP #10 SFT2 ;rabbits ADD2 #00c8 #00 STHr MUL2 ADD2 |
|
| 179 |
+ LDA2 STH2k |
|
| 180 |
+ ,&draw JMP |
|
| 181 |
+ |
|
| 182 |
+@display-counter $1 |
|
| 183 |
+ |
|
| 184 |
+@display ( -> ) |
|
| 185 |
+ ,display-counter LDR #01 SUB DUP ,display-counter STR |
|
| 186 |
+ DUP #f0 LTH ,&skip-palette JCN |
|
| 187 |
+ #ff OVR SUB #00 |
|
| 188 |
+ DUP2 .System/r DEO2 |
|
| 189 |
+ DUP2 .System/g DEO2 |
|
| 190 |
+ .System/b DEO2 |
|
| 191 |
+ &skip-palette |
|
| 192 |
+ INCk #0000 &clear-loop |
|
| 193 |
+ ROTk ;display-rabbit JSR2 |
|
| 194 |
+ INC |
|
| 195 |
+ DUP #64 LTH ,&clear-loop JCN |
|
| 196 |
+ POP2 POP |
|
| 197 |
+ #0500 &draw-loop |
|
| 198 |
+ ROTk ;display-rabbit JSR2 |
|
| 199 |
+ INC |
|
| 200 |
+ DUP #64 LTH ,&draw-loop JCN |
|
| 201 |
+ POP2 |
|
| 202 |
+ ,&no-finish JCN |
|
| 203 |
+ ;sunset .Screen/vector DEO2 |
|
| 204 |
+ &no-finish |
|
| 205 |
+ BRK |
|
| 206 |
+ |
|
| 207 |
+@sunset ( -> ) |
|
| 208 |
+ ;display-counter LDA #02 SUB DUP ;display-counter STA |
|
| 209 |
+ DUP #1f GTH ,&skip-palette JCN |
|
| 210 |
+ DUP #01 SFT #00 |
|
| 211 |
+ DUP2 .System/r DEO2 |
|
| 212 |
+ DUP2 .System/g DEO2 |
|
| 213 |
+ .System/b DEO2 |
|
| 214 |
+ #6400 &draw-loop |
|
| 215 |
+ #05 OVR #00 ;display-rabbit JSR2 |
|
| 216 |
+ INC |
|
| 217 |
+ GTHk ,&draw-loop JCN |
|
| 218 |
+ POP2 |
|
| 219 |
+ &skip-palette |
|
| 220 |
+ ,&no-finish JCN |
|
| 221 |
+ ;repeat JMP2 |
|
| 222 |
+ &no-finish |
|
| 223 |
+ BRK |
|
| 224 |
+ |
|
| 225 |
+@rabbit-sprite 003c 7e7e 7e7e 3c00 |
|
| 226 |
+ |
|
| 227 |
+@occupied $190 |
|
| 228 |
+ |
|
| 229 |
+@rabbits |
|
| 230 |
+ |