| ... | ... |
@@ -5,7 +5,7 @@ |
| 5 | 5 |
|
| 6 | 6 |
|0000 |
| 7 | 7 |
|
| 8 |
- @ball &x $2 &y $2 |
|
| 8 |
+ @ball &x $2 &y $2 &vx $2 &vy $2 |
|
| 9 | 9 |
@timer $1 |
| 10 | 10 |
@frame $1 |
| 11 | 11 |
|
| ... | ... |
@@ -13,9 +13,9 @@ |
| 13 | 13 |
|
| 14 | 14 |
( vectors ) |
| 15 | 15 |
;on-frame .Screen/vector DEO2 |
| 16 |
- ( theme ) |
|
| 17 |
- #aff0 .System/r DEO2 |
|
| 18 |
- #af00 .System/g DEO2 |
|
| 16 |
+ ( theme ) |
|
| 17 |
+ #aff0 .System/r DEO2 |
|
| 18 |
+ #af00 .System/g DEO2 |
|
| 19 | 19 |
#af00 .System/b DEO2 |
| 20 | 20 |
( screen size ) |
| 21 | 21 |
#0140 .Screen/width DEO2 |
| ... | ... |
@@ -23,11 +23,12 @@ |
| 23 | 23 |
( inital position ) |
| 24 | 24 |
#0020 .ball/x STZ2 |
| 25 | 25 |
#0020 .ball/y STZ2 |
| 26 |
- |
|
| 26 |
+ ( initial velocity ) |
|
| 27 |
+ #0002 .ball/vx STZ2 |
|
| 28 |
+ #0000 .ball/vy STZ2 |
|
| 29 |
+ ( once ) |
|
| 27 | 30 |
;make-shadow JSR2 |
| 28 |
- |
|
| 29 | 31 |
;draw-background JSR2 |
| 30 |
- ;draw-shadow JSR2 |
|
| 31 | 32 |
|
| 32 | 33 |
BRK |
| 33 | 34 |
|
| ... | ... |
@@ -39,44 +40,54 @@ BRK |
| 39 | 40 |
#00 .timer STZ |
| 40 | 41 |
( 12 frames animation ) |
| 41 | 42 |
.frame LDZ INC DUP #0c NEQ MUL .frame STZ |
| 42 |
- ;move-ball JSR2 |
|
| 43 |
+ ,move-ball JSR |
|
| 43 | 44 |
|
| 44 | 45 |
BRK |
| 45 | 46 |
|
| 46 |
-@make-shadow ( -- ) |
|
| 47 |
+@clear-ball ( -- ) |
|
| 47 | 48 |
|
| 48 |
- ;bg ;shadow #0188 ;mcpy JSR2 |
|
| 49 |
- #0188 #0000 |
|
| 50 |
- &loop |
|
| 51 |
- DUP2 ;shadow ADD2 LDA2k #aa55 AND2 SWP2 STA2 |
|
| 52 |
- INC2 INC2 GTH2k ,&loop JCN |
|
| 53 |
- POP2 POP2 |
|
| 49 |
+ .ball/x LDZ2 .Screen/x DEO2 |
|
| 50 |
+ .ball/y LDZ2 .Screen/y DEO2 |
|
| 51 |
+ #76 .Screen/auto DEO |
|
| 52 |
+ #0800 |
|
| 53 |
+ &loop-bg |
|
| 54 |
+ #40 .Screen/sprite DEO |
|
| 55 |
+ INC GTHk ,&loop-bg JCN |
|
| 56 |
+ POP2 |
|
| 54 | 57 |
|
| 55 | 58 |
JMP2r |
| 56 | 59 |
|
| 57 | 60 |
@move-ball ( -- ) |
| 58 | 61 |
|
| 59 |
- ( .ball/x LDZ2k INC2 INC2 ROT STZ2 ) |
|
| 60 |
- ;draw-ball JSR2 |
|
| 62 |
+ ,clear-ball JSR |
|
| 63 |
+ .ball/vy LDZ2k INC2 STH2k ROT STZ2 |
|
| 64 |
+ .ball/y LDZ2k STH2r ADD2 ,check-flip-vy JSR ROT STZ2 |
|
| 65 |
+ ,draw-ball JSR |
|
| 61 | 66 |
|
| 62 | 67 |
JMP2r |
| 63 | 68 |
|
| 64 |
-@draw-shadow ( -- ) |
|
| 69 |
+@check-flip-vy ( y -- y ) |
|
| 70 |
+ |
|
| 71 |
+ DUP2 #0028 ADD2 |
|
| 72 |
+ .Screen/height DEI2 #0028 SUB2 |
|
| 73 |
+ GTH2 ,&flip JCN ,&else JMP |
|
| 74 |
+ &flip .ball/vy LDZ2k #ffff EOR2 ( INC2 ) ROT STZ2 |
|
| 75 |
+ &else |
|
| 76 |
+ |
|
| 77 |
+JMP2r |
|
| 78 |
+ |
|
| 79 |
+@draw-ball ( -- ) |
|
| 65 | 80 |
|
| 81 |
+ ( shadow ) |
|
| 66 | 82 |
.ball/x LDZ2 #0008 ADD2 .Screen/x DEO2 |
| 67 | 83 |
.ball/y LDZ2 #0008 ADD2 .Screen/y DEO2 |
| 68 | 84 |
;shadow .Screen/addr DEO2 |
| 69 | 85 |
#66 .Screen/auto DEO |
| 70 | 86 |
#0700 |
| 71 |
- &loop-bg |
|
| 72 |
- #0f .Screen/sprite DEO |
|
| 73 |
- INC GTHk ,&loop-bg JCN |
|
| 87 |
+ &loop-shadow |
|
| 88 |
+ #4f .Screen/sprite DEO |
|
| 89 |
+ INC GTHk ,&loop-shadow JCN |
|
| 74 | 90 |
POP2 |
| 75 |
- |
|
| 76 |
-JMP2r |
|
| 77 |
- |
|
| 78 |
-@draw-ball ( -- ) |
|
| 79 |
- |
|
| 80 | 91 |
.frame LDZ |
| 81 | 92 |
( bg ) |
| 82 | 93 |
DUP #06 DIV INC #05 MUL #40 ADD STH |
| ... | ... |
@@ -111,33 +122,44 @@ JMP2r |
| 111 | 122 |
#01 .Screen/auto DEO |
| 112 | 123 |
;hor-icn .Screen/addr DEO2 |
| 113 | 124 |
.Screen/height DEI2 #04 SFT2 NIP #04 SUB #00 |
| 114 |
- &ver |
|
| 125 |
+ &horver |
|
| 115 | 126 |
#0020 .Screen/x DEO2 |
| 116 | 127 |
#00 OVR #40 SFT2 #0020 ADD2 .Screen/y DEO2 |
| 117 | 128 |
.Screen/width DEI2 #03 SFT2 NIP #08 SUB #00 |
| 118 |
- &hor |
|
| 129 |
+ &horhor |
|
| 119 | 130 |
#0f .Screen/sprite DEO |
| 120 |
- INC GTHk ,&hor JCN |
|
| 131 |
+ INC GTHk ,&horhor JCN |
|
| 121 | 132 |
POP2 |
| 122 |
- INC GTHk ,&ver JCN |
|
| 133 |
+ INC GTHk ,&horver JCN |
|
| 123 | 134 |
POP2 |
| 124 | 135 |
( ver lines ) |
| 125 | 136 |
#02 .Screen/auto DEO |
| 126 | 137 |
;ver-icn .Screen/addr DEO2 |
| 127 | 138 |
.Screen/width DEI2 #04 SFT2 NIP #03 SUB #00 |
| 128 |
- &ver2 |
|
| 139 |
+ &verver |
|
| 129 | 140 |
#0027 .Screen/y DEO2 |
| 130 | 141 |
#00 OVR #40 SFT2 #0019 ADD2 .Screen/x DEO2 |
| 131 | 142 |
.Screen/height DEI2 #03 SFT2 NIP #0a SUB #00 |
| 132 |
- &hor2 |
|
| 143 |
+ &verhor |
|
| 133 | 144 |
#0f .Screen/sprite DEO |
| 134 |
- INC GTHk ,&hor2 JCN |
|
| 145 |
+ INC GTHk ,&verhor JCN |
|
| 135 | 146 |
POP2 |
| 136 |
- INC GTHk ,&ver2 JCN |
|
| 147 |
+ INC GTHk ,&verver JCN |
|
| 137 | 148 |
POP2 |
| 138 | 149 |
|
| 139 | 150 |
JMP2r |
| 140 | 151 |
|
| 152 |
+@make-shadow ( -- ) |
|
| 153 |
+ |
|
| 154 |
+ ;bg ;shadow #0188 ;mcpy JSR2 |
|
| 155 |
+ #0188 #0000 |
|
| 156 |
+ &loop |
|
| 157 |
+ DUP2 ;shadow ADD2 LDA2k #aa55 AND2 SWP2 STA2 |
|
| 158 |
+ INC2 INC2 GTH2k ,&loop JCN |
|
| 159 |
+ POP2 POP2 |
|
| 160 |
+ |
|
| 161 |
+JMP2r |
|
| 162 |
+ |
|
| 141 | 163 |
@mcpy ( src* dst* len* -- ) |
| 142 | 164 |
|
| 143 | 165 |
SWP2 STH2 |
| ... | ... |
@@ -150,9 +172,9 @@ JMP2r |
| 150 | 172 |
|
| 151 | 173 |
JMP2r |
| 152 | 174 |
|
| 153 |
-@hor-icn |
|
| 175 |
+@hor-icn |
|
| 154 | 176 |
0000 0000 0000 00ff |
| 155 |
-@ver-icn |
|
| 177 |
+@ver-icn |
|
| 156 | 178 |
0101 0101 0101 0101 |
| 157 | 179 |
|
| 158 | 180 |
@ball-icn ( 56 x 56 ) |
| ... | ... |
@@ -166,10 +188,10 @@ JMP2r |
| 166 | 188 |
e0e0 e000 3c3f 7f7f 0303 0707 0787 fff1 fefe fefc fcfc fcfc 1804 0606 0e0e 0e0e |
| 167 | 189 |
3e1e 1e1e 1e0e 0f0f fe1c 0003 0303 0303 0000 0080 f1ff fefe 7fff ffff ffff 3f07 |
| 168 | 190 |
f0e0 e0e0 c0c0 8080 3800 070f 0f1f 1f3f 0e0c 0cfc e0c0 c080 0f09 0400 0001 0000 |
| 169 |
- 0303 c37b 3c3c 9e1e fcfc fcfc f818 040f 0000 0101 0303 078f 80e0 feff fffe fcf8 |
|
| 191 |
+ 0303 c37b 3c3c 9e1e fcfc fcfc f818 040f 0000 0101 0303 078f 80e0 feff fffe fcf8 |
|
| 170 | 192 |
3f7f 7f3e 0603 070e 8000 0000 0000 0000 0000 0000 0000 0000 0e1e 0500 0000 0000 |
| 171 | 193 |
0f0f 0f4f 2703 0200 ffe1 c080 030f 1e00 f0e0 00f9 f8c0 0000 3c70 e0c0 0000 0000 |
| 172 |
- 0000 0000 0000 0000 |
|
| 194 |
+ 0000 0000 0000 0000 |
|
| 173 | 195 |
( 01 ) |
| 174 | 196 |
0000 0000 0000 0000 0000 0000 0204 0800 0001 0f7c 101c 3fff 00e7 8307 0f3f ff0f |
| 175 | 197 |
0040 0cdc c083 8101 0000 0000 80a0 c0e4 0000 0000 0000 0000 0000 0003 0103 0307 |
| ... | ... |
@@ -183,7 +205,7 @@ JMP2r |
| 183 | 205 |
0707 c7ff 7838 bc1c f8f8 f0f0 f010 1c1f 0103 0307 070f 0f9f 00e0 fefe fcf8 f0e0 |
| 184 | 206 |
7ffe fe3c 0407 0f1e 0000 0000 4000 0000 0000 0000 0000 0000 0c1e 0400 0000 0000 |
| 185 | 207 |
1f1f 1fdf 2607 0200 cfc1 8001 071f 1c00 e0c0 41fb f080 0000 38f0 e0c0 0000 0000 |
| 186 |
- 0000 0000 0000 0000 |
|
| 208 |
+ 0000 0000 0000 0000 |
|
| 187 | 209 |
( 02 ) |
| 188 | 210 |
0000 0000 0000 0000 0000 0000 0000 0001 0001 1ff8 003c fefe 00e7 030f 3f7f 7f0e |
| 189 | 211 |
0000 1cd8 8003 0303 0000 0000 80c0 c0c4 0000 0000 0000 0000 0000 0103 0307 070f |
| ... | ... |
@@ -197,7 +219,7 @@ JMP2r |
| 197 | 219 |
0f0f cff7 7078 3818 e0e0 e0e0 e020 3c3f 0707 0f0f 1f1f 3fbf 01e1 fdf8 f0f0 e0c0 |
| 198 | 220 |
fefc fc38 000f 1e3c 1000 2000 4000 0000 0000 0000 0000 0000 1c1c 0400 0000 0000 |
| 199 | 221 |
3f3f 3ffe 6407 0300 8f01 0103 0f3f 1800 8080 c3ff e008 0000 78f0 c080 0000 0000 |
| 200 |
- 0000 0000 0000 0000 |
|
| 222 |
+ 0000 0000 0000 0000 |
|
| 201 | 223 |
( 03 ) |
| 202 | 224 |
0000 0000 0000 0000 0000 0000 0000 0003 0001 1ef0 207d fcf8 00c7 071f 7ffe 7c0c |
| 203 | 225 |
0080 1c9a 0407 0707 0000 0000 80c0 80cc 0000 0000 0000 0000 0000 0103 0307 070f |
| ... | ... |
@@ -211,7 +233,7 @@ JMP2r |
| 211 | 233 |
1f1f dfe7 e070 3038 c0c0 c080 8060 7c7f 1f1f 3f3f 3f7f 7f7f 07e7 f1f0 e0c0 8080 |
| 212 | 234 |
fcf8 f830 081f 3e7c 1020 2040 4080 0000 0000 0000 0000 0000 181c 0200 0000 0000 |
| 213 | 235 |
7f7e 3efc 440f 0100 0f00 030f 1f3e 1800 0003 c7f7 c108 0000 f8e0 c080 0000 0000 |
| 214 |
- 0000 0000 0000 0000 |
|
| 236 |
+ 0000 0000 0000 0000 |
|
| 215 | 237 |
( 04 ) |
| 216 | 238 |
0000 0000 0000 0000 0000 0000 0000 0103 0001 1ce0 60ff f8f0 0087 0f3f fefc 7800 |
| 217 | 239 |
0080 3c1a 0d0f 0f0f 0000 0000 8040 808c 0000 0000 0000 0000 0000 0103 0307 070e |
| ... | ... |
@@ -225,7 +247,7 @@ JMP2r |
| 225 | 247 |
3f3f ffc7 e060 7030 0000 0000 00e0 fdfe 3f7f 7fff ffff ff7e 0fff e1c0 8080 0001 |
| 226 | 248 |
f8f0 f020 387f fcf8 3020 6040 c080 0000 0000 0000 0000 0000 1818 0200 0000 0000 |
| 227 | 249 |
7c7c 7cb8 400f 0100 0e02 0f1f 3f7c d000 0307 cfe7 0318 8000 f0e0 c000 0000 0000 |
| 228 |
- 0000 0000 0000 0000 |
|
| 250 |
+ 0000 0000 0000 0000 |
|
| 229 | 251 |
( 05 ) |
| 230 | 252 |
0000 0000 0000 0000 0000 0000 0001 0307 0001 18c0 e1fb f0e0 0087 1f7e fcf8 7010 |
| 231 | 253 |
0080 7012 0d1f 1f1f 0000 0000 0040 100c 0000 0000 0000 0000 0000 0103 0306 060c |
| ... | ... |
@@ -239,7 +261,7 @@ JMP2r |
| 239 | 261 |
7e7e bec6 c1e1 6130 0000 0101 01e3 fffc ffff ffff fffe fe7c 3fdf 8100 0000 0103 |
| 240 | 262 |
e0e0 c000 79fe fcf0 3060 60c0 c080 0000 0000 0000 0000 0000 3008 0200 0000 0000 |
| 241 | 263 |
f8f8 f8b0 480e 0100 080e 1f3f 7ef8 e100 070f df87 0318 8000 e0c0 8000 0000 0000 |
| 242 |
- 0000 0000 0000 0000 |
|
| 264 |
+ 0000 0000 0000 0000 |
|
| 243 | 265 |
|
| 244 | 266 |
@bg |
| 245 | 267 |
0000 0000 0000 0000 0000 0000 0307 0f3f |
| ... | ... |
@@ -266,6 +288,6 @@ JMP2r |
| 266 | 288 |
0000 0000 0000 0000 3f1f 0701 0000 0000 |
| 267 | 289 |
ffff ffff 7f3f 0300 ffff ffff ffff ff00 |
| 268 | 290 |
ffff ffff fff8 8000 fcf0 e0c0 0000 0000 |
| 269 |
- 0000 0000 0000 0000 |
|
| 291 |
+ 0000 0000 0000 0000 |
|
| 270 | 292 |
|
| 271 | 293 |
@shadow $0188 |
| 272 | 294 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,275 @@ |
| 1 |
+( bunnymark.tal ) |
|
| 2 |
+ |
|
| 3 |
+( November 2021, Kira Oakley ) |
|
| 4 |
+( March 2022, Devine Lu Linvega ) |
|
| 5 |
+ |
|
| 6 |
+|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 &debug $1 &halt $1 |
|
| 7 |
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
| 8 |
+|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1 |
|
| 9 |
+|b0 @Date &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 |
|
| 10 |
+ |
|
| 11 |
+|0000 |
|
| 12 |
+ |
|
| 13 |
+ @frames $2 |
|
| 14 |
+ @last $1 |
|
| 15 |
+ |
|
| 16 |
+|0100 ( -> ) |
|
| 17 |
+ |
|
| 18 |
+ ( set system colors ) |
|
| 19 |
+ #2ce9 .System/r DEO2 |
|
| 20 |
+ #01c0 .System/g DEO2 |
|
| 21 |
+ #2ce5 .System/b DEO2 |
|
| 22 |
+ |
|
| 23 |
+ ( interrupts ) |
|
| 24 |
+ ;on-frame .Screen/vector DEO2 |
|
| 25 |
+ |
|
| 26 |
+ ( draw "FPS:" and "BUNNIES:" and instructions labels ) |
|
| 27 |
+ .Screen/width DEI2 #0046 SUB2 #0008 ;text/fps #42 ;draw-str JSR2 |
|
| 28 |
+ #0004 #0008 ;text/bunnies #42 ;draw-str JSR2 |
|
| 29 |
+ .Screen/width DEI2 #0002 DIV2 #0050 SUB2 #0008 ;text/instructions #43 ;draw-str JSR2 |
|
| 30 |
+ #0028 #0008 #0000 ;draw-dec JSR2 |
|
| 31 |
+ |
|
| 32 |
+ ( seed prng ) |
|
| 33 |
+ #04 ;rand/a STA |
|
| 34 |
+ |
|
| 35 |
+BRK |
|
| 36 |
+ |
|
| 37 |
+@on-frame ( -> ) |
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+ ( frames++ ) |
|
| 41 |
+ .frames LDZ2k INC2 ROT STZ2 |
|
| 42 |
+ .Date/second DEI .last LDZ EQU ,&post-fps-update JCN |
|
| 43 |
+ ( fps update ) |
|
| 44 |
+ ( update last-secs ) .Date/second DEI .last STZ |
|
| 45 |
+ ( update fps label ) .Screen/width DEI2 #002b SUB2 #0008 .frames LDZ2 ;draw-dec JSR2 |
|
| 46 |
+ ( reset frames counter ) #0000 .frames STZ2 |
|
| 47 |
+ |
|
| 48 |
+ &post-fps-update |
|
| 49 |
+ ( mouse input to add/remove bunnies ) |
|
| 50 |
+ .Mouse/state DEI #01 EQU ,&add JCN |
|
| 51 |
+ .Mouse/state DEI #01 GTH ,&remove JCN |
|
| 52 |
+ ,&done JMP |
|
| 53 |
+ &add |
|
| 54 |
+ ;add-bunny JSR2 ,&done JMP |
|
| 55 |
+ &remove |
|
| 56 |
+ ;remove-bunny JSR2 ,&done JMP |
|
| 57 |
+ &done |
|
| 58 |
+ |
|
| 59 |
+ ( loop from 0 to ;sprite/length to make all ;draw-bunny calls ) |
|
| 60 |
+ [ ;sprite/length LDA2 ] #0000 |
|
| 61 |
+ &loop |
|
| 62 |
+ EQU2k ,&bail JCN |
|
| 63 |
+ DUP2 ,draw-bunny JSR |
|
| 64 |
+ INC2 ,&loop JMP |
|
| 65 |
+ &bail |
|
| 66 |
+ POP2 POP2 |
|
| 67 |
+ |
|
| 68 |
+BRK |
|
| 69 |
+ |
|
| 70 |
+@draw-bunny ( idx -- ) |
|
| 71 |
+ |
|
| 72 |
+ ( compute the offset to the beginning of this bunny's data ) |
|
| 73 |
+ [ #30 SFT2 ;sprite/array ADD2 ] |
|
| 74 |
+ |
|
| 75 |
+ ( clear the old sprite location ) |
|
| 76 |
+ ( top ) |
|
| 77 |
+ [ LDA2k ] #05 SFT2 .Screen/x DEO2 |
|
| 78 |
+ [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 |
|
| 79 |
+ #00 ;draw-sprite JSR2 |
|
| 80 |
+ |
|
| 81 |
+ ( move the sprite by its velocity ) |
|
| 82 |
+ [ LDA2k ] [ OVR2 #0004 ADD2 LDA2 ] ADD2 OVR2 STA2 |
|
| 83 |
+ [ DUP2 #0002 ADD2 LDA2 ] [ OVR2 #0006 ADD2 LDA2 ] ADD2 OVR2 #0002 ADD2 STA2 |
|
| 84 |
+ |
|
| 85 |
+ ( check for right wall collision + bounce x ) |
|
| 86 |
+ [ DUP2 #0004 ADD2 LDA2 ] #0f SFT2 #0001 EQU2 ,&skip-max-x JCN |
|
| 87 |
+ [ LDA2k ] #05 SFT2 #0008 ADD2 [ .Screen/width DEI2 ] LTH2 ,&skip-max-x JCN |
|
| 88 |
+ [ DUP2 #0004 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0004 ADD2 STA2 ] |
|
| 89 |
+ &skip-max-x |
|
| 90 |
+ ( check for bottom wall collision + bounce y ) |
|
| 91 |
+ [ DUP2 #0006 ADD2 LDA2 ] #0f SFT2 #0001 EQU2 ,&skip-max-y JCN |
|
| 92 |
+ [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 #0008 ADD2 [ .Screen/height DEI2 ] LTH2 ,&skip-max-y JCN |
|
| 93 |
+ [ DUP2 #0006 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0006 ADD2 STA2 ] |
|
| 94 |
+ &skip-max-y |
|
| 95 |
+ ( check for left wall collision + bounce x ) |
|
| 96 |
+ [ LDA2k ] #0f SFT2 #0000 EQU2 ,&skip-min-x JCN |
|
| 97 |
+ [ DUP2 #0004 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0004 ADD2 STA2 ] |
|
| 98 |
+ &skip-min-x |
|
| 99 |
+ ( check for top wall collision + bounce x ) |
|
| 100 |
+ [ DUP2 #0002 ADD2 LDA2 ] #0f SFT2 #0000 EQU2 ,&skip-min-y JCN |
|
| 101 |
+ [ DUP2 #0006 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0006 ADD2 STA2 ] |
|
| 102 |
+ &skip-min-y |
|
| 103 |
+ |
|
| 104 |
+ ( ( apply gravity ) ) |
|
| 105 |
+ [ DUP2 #0006 ADD2 LDA2 ] #0004 ADD2 OVR2 #0006 ADD2 STA2 |
|
| 106 |
+ |
|
| 107 |
+ ( draw the sprite ) |
|
| 108 |
+ ( top ) |
|
| 109 |
+ [ LDA2k ] #05 SFT2 .Screen/x DEO2 |
|
| 110 |
+ [ #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 |
|
| 111 |
+ #85 ,draw-sprite JSR |
|
| 112 |
+ |
|
| 113 |
+JMP2r |
|
| 114 |
+ |
|
| 115 |
+@draw-sprite ( color -- ) |
|
| 116 |
+ |
|
| 117 |
+ #15 .Screen/auto DEO |
|
| 118 |
+ ;bunny-chr .Screen/addr DEO2 |
|
| 119 |
+ .Screen/sprite DEO |
|
| 120 |
+ #00 .Screen/auto DEO |
|
| 121 |
+ |
|
| 122 |
+JMP2r |
|
| 123 |
+ |
|
| 124 |
+@add-bunny ( -- ) |
|
| 125 |
+ |
|
| 126 |
+ ;sprite/length LDA2 |
|
| 127 |
+ ( cap bunny count at 65535 ) |
|
| 128 |
+ DUP2 #ffff EQU2 ,&bail JCN |
|
| 129 |
+ ( compute the offset to the beginning of this new bunny's data ) |
|
| 130 |
+ DUP2 #30 SFT2 ;sprite/array ADD2 |
|
| 131 |
+ ( populate the new bunny's x/y/xvel/yvel with random values ) |
|
| 132 |
+ #00 [ ;rand JSR2 ] OVR2 STA2 |
|
| 133 |
+ [ ;rand JSR2 #1f AND ] [ ;rand JSR2 ] OVR2 #0002 ADD2 STA2 |
|
| 134 |
+ #00 [ ;rand JSR2 #7f AND ] OVR2 #0004 ADD2 STA2 |
|
| 135 |
+ #00 [ ;rand JSR2 #7f AND ] OVR2 #0006 ADD2 STA2 |
|
| 136 |
+ ( pop ptr to bunny data ) POP2 |
|
| 137 |
+ ( write new increased array length ) |
|
| 138 |
+ INC2 DUP2 ;sprite/length STA2 |
|
| 139 |
+ ( update label ) |
|
| 140 |
+ STH2k #0028 #0008 STH2r ;draw-dec JSR2 |
|
| 141 |
+ &bail |
|
| 142 |
+ ( pop sprite/length ) POP2 |
|
| 143 |
+ |
|
| 144 |
+JMP2r |
|
| 145 |
+ |
|
| 146 |
+@draw-str ( x* y* text* color -- ) |
|
| 147 |
+ |
|
| 148 |
+ #01 .Screen/auto DEO |
|
| 149 |
+ STH |
|
| 150 |
+ SWP2 .Screen/y DEO2 |
|
| 151 |
+ SWP2 .Screen/x DEO2 |
|
| 152 |
+ &loop |
|
| 153 |
+ LDAk #20 SUB #00 SWP #30 SFT2 ;font ADD2 .Screen/addr DEO2 |
|
| 154 |
+ STHkr .Screen/sprite DEO |
|
| 155 |
+ INC2 LDAk ,&loop JCN |
|
| 156 |
+ POP2 |
|
| 157 |
+ STHr POP |
|
| 158 |
+ #00 .Screen/auto DEO |
|
| 159 |
+ |
|
| 160 |
+JMP2r |
|
| 161 |
+ |
|
| 162 |
+@draw-dec ( x* y* num* -- ) |
|
| 163 |
+ |
|
| 164 |
+ #01 .Screen/auto DEO |
|
| 165 |
+ SWP2 .Screen/y DEO2 |
|
| 166 |
+ SWP2 .Screen/x DEO2 |
|
| 167 |
+ #2710 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 |
|
| 168 |
+ #03e8 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 |
|
| 169 |
+ #0064 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 NIP |
|
| 170 |
+ #0a DIVk DUP ,&digit JSR MUL SUB |
|
| 171 |
+ ,&digit JSR |
|
| 172 |
+ #00 .Screen/auto DEO |
|
| 173 |
+ |
|
| 174 |
+JMP2r |
|
| 175 |
+ &digit ( num -- ) |
|
| 176 |
+ #30 SFT #00 SWP ;font/num ADD2 .Screen/addr DEO2 |
|
| 177 |
+ #41 .Screen/sprite DEO |
|
| 178 |
+ JMP2r |
|
| 179 |
+ |
|
| 180 |
+@remove-bunny ( -- ) |
|
| 181 |
+ |
|
| 182 |
+ ;sprite/length LDA2 |
|
| 183 |
+ ( don't let length go below 0 ) |
|
| 184 |
+ DUP2 #0000 EQU2 ,&bail JCN |
|
| 185 |
+ ( clear the old sprite location ) |
|
| 186 |
+ DUP2 #0001 SUB2 #30 SFT2 ;sprite/array ADD2 |
|
| 187 |
+ ( top ) |
|
| 188 |
+ [ LDA2k ] #05 SFT2 .Screen/x DEO2 |
|
| 189 |
+ [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 |
|
| 190 |
+ ( clear ) |
|
| 191 |
+ #00 ;draw-sprite JSR2 |
|
| 192 |
+ POP2 |
|
| 193 |
+ #0001 SUB2 DUP2 ;sprite/length STA2 |
|
| 194 |
+ ( update label ) |
|
| 195 |
+ STH2k #0028 #0008 STH2r ;draw-dec JSR2 |
|
| 196 |
+ &bail |
|
| 197 |
+ POP2 |
|
| 198 |
+ |
|
| 199 |
+JMP2r |
|
| 200 |
+ |
|
| 201 |
+( PRNG code taken from flappy.tal -- thanks! ) |
|
| 202 |
+ |
|
| 203 |
+@rand ( -- number ) |
|
| 204 |
+ |
|
| 205 |
+ ( local vars ) |
|
| 206 |
+ #04 JMP |
|
| 207 |
+ &x $1 &y $1 &z $1 &a $1 |
|
| 208 |
+ ( 8-bit PRNG https://github.com/edrosten/8bit_rng ) |
|
| 209 |
+ ( t = x ^ (x << 4) ) |
|
| 210 |
+ ,&x LDR DUP #40 SFT EOR |
|
| 211 |
+ ( x = y ) |
|
| 212 |
+ ,&y LDR ,&x STR |
|
| 213 |
+ ( y = z ) |
|
| 214 |
+ ,&z LDR ,&y STR |
|
| 215 |
+ ( z = a ) |
|
| 216 |
+ ,&a LDR DUP ,&z STR |
|
| 217 |
+ ( a = z ^ t ^ (z >> 1) ^ (t << 1) ) |
|
| 218 |
+ DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR |
|
| 219 |
+ DUP ,&a STR |
|
| 220 |
+ |
|
| 221 |
+JMP2r |
|
| 222 |
+ |
|
| 223 |
+( static string data ) |
|
| 224 |
+ |
|
| 225 |
+@text |
|
| 226 |
+ &fps "FPS: 00 |
|
| 227 |
+ &bunnies "BUNS: 00 |
|
| 228 |
+ &instructions "CLICK 20 "TO 20 "ADD 20 "BUNNIES! 00 |
|
| 229 |
+ |
|
| 230 |
+@font ( atari8.uf1 ) |
|
| 231 |
+ 0000 0000 0000 0000 6060 6060 6000 6000 |
|
| 232 |
+ 6666 6600 0000 0000 006c fe6c 6cfe 6c00 |
|
| 233 |
+ 183e 603c 067c 1800 0066 6c18 3066 4600 |
|
| 234 |
+ 386c 3870 decc 7600 6060 6000 0000 0000 |
|
| 235 |
+ 0e1c 1818 181c 0e00 7038 1818 1838 7000 |
|
| 236 |
+ 0066 3cff 3c66 0000 0018 187e 1818 0000 |
|
| 237 |
+ 0000 0000 0030 3060 0000 007e 0000 0000 |
|
| 238 |
+ 0000 0000 0018 1800 0206 0c18 3060 4000 |
|
| 239 |
+ &num |
|
| 240 |
+ 3c66 6e76 6666 3c00 1838 1818 1818 7e00 |
|
| 241 |
+ 3c66 060c 1830 7e00 7e0c 180c 0666 3c00 |
|
| 242 |
+ 0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00 |
|
| 243 |
+ 3c60 607c 6666 3c00 7e06 0c18 3030 3000 |
|
| 244 |
+ 3c66 663c 6666 3c00 3c66 663e 060c 3800 |
|
| 245 |
+ 0060 6000 6060 0000 0030 3000 3030 6000 |
|
| 246 |
+ 0c18 3060 3018 0c00 0000 7e00 007e 0000 |
|
| 247 |
+ 6030 180c 1830 6000 3c66 060c 1800 1800 |
|
| 248 |
+ 3c66 6e6a 6e60 3e00 183c 6666 7e66 6600 |
|
| 249 |
+ 7c66 667c 6666 7c00 3c66 6060 6066 3c00 |
|
| 250 |
+ 786c 6666 666c 7800 7e60 607c 6060 7e00 |
|
| 251 |
+ 7e60 607c 6060 6000 3e60 606e 6666 3e00 |
|
| 252 |
+ 6666 667e 6666 6600 7830 3030 3030 7800 |
|
| 253 |
+ 0606 0606 0666 3c00 666c 7870 786c 6600 |
|
| 254 |
+ 6060 6060 6060 7e00 c6ee fed6 c6c6 c600 |
|
| 255 |
+ 6676 7e7e 6e66 6600 3c66 6666 6666 3c00 |
|
| 256 |
+ 7c66 667c 6060 6000 3c66 6666 766c 3600 |
|
| 257 |
+ 7c66 667c 6c66 6600 3c66 603c 0666 3c00 |
|
| 258 |
+ 7e18 1818 1818 1800 6666 6666 6666 3e00 |
|
| 259 |
+ 6666 6666 663c 1800 c6c6 c6d6 feee c600 |
|
| 260 |
+ 6666 3c18 3c66 6600 6666 663c 1818 1800 |
|
| 261 |
+ 7e06 0c18 3060 7e00 7860 6060 6060 7800 |
|
| 262 |
+ |
|
| 263 |
+@bunny-chr |
|
| 264 |
+ 2466 6600 2424 003c 4200 007e 7e7e 7e7e |
|
| 265 |
+ 1818 3c3c 1800 0000 ff66 4242 667e 4242 |
|
| 266 |
+ |
|
| 267 |
+( beginning of sprite pixel data + array ) |
|
| 268 |
+ |
|
| 269 |
+@sprite |
|
| 270 |
+ &length $2 |
|
| 271 |
+ &array |
|
| 272 |
+ &x 0600 |
|
| 273 |
+ &y 0500 |
|
| 274 |
+ &xvel 0060 |
|
| 275 |
+ &yvel 0010 |