├── .gitignore ├── prng.tal ├── checker.tal ├── decimal.tal ├── sprite.tal └── flappy.tal /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | /uxn 3 | /*.rom 4 | -------------------------------------------------------------------------------- /prng.tal: -------------------------------------------------------------------------------- 1 | ( devices ) 2 | 3 | |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] 4 | |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 5 | 6 | ( variables ) 7 | 8 | |0000 9 | 10 | ( program ) 11 | 12 | |0100 ( -> ) 13 | 14 | ( theme ) 15 | #0fff .System/r DEO2 16 | #0fff .System/g DEO2 17 | #0fff .System/b DEO2 18 | 19 | ( random seed ) 20 | #01 ;rand/a STA 21 | 22 | ( vector ) 23 | ;on-frame .Screen/vector DEO2 24 | 25 | BRK 26 | 27 | @on-frame ( -- ) 28 | ( y = 0 ) 29 | #00 30 | &loop-y 31 | ( y -> Screen/y ) 32 | DUP #00 SWP .Screen/y DEO2 33 | ( r = rand, x = 0 ) 34 | ;rand JSR2 #00 35 | &loop-x 36 | ( x -> Screen/x ) 37 | DUP #00 SWP .Screen/x DEO2 38 | ( x < r -> Screen/pixel ) 39 | GTHk .Screen/pixel DEO 40 | ( loop until ++x == 0 ) 41 | INC DUP ,&loop-x JCN 42 | POP2 43 | ( loop until ++y == 0 ) 44 | INC DUP ,&loop-y JCN 45 | POP 46 | BRK 47 | 48 | @rand ( -- number ) 49 | ( 8-bit PRNG https://github.com/edrosten/8bit_rng ) 50 | 51 | ( t = x ^ (x << 4) ) 52 | ,&x LDR DUP #40 SFT EOR 53 | ( x = y ) 54 | ,&y LDR ,&x STR 55 | ( y = z ) 56 | ,&z LDR ,&y STR 57 | ( z = a ) 58 | ,&a LDR DUP ,&z STR 59 | ( a = z ^ t ^ (z >> 1) ^ (t << 1) ) 60 | DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR 61 | DUP ,&a STR 62 | JMP2r 63 | 64 | &x $1 &y $1 &z $1 &a $1 65 | -------------------------------------------------------------------------------- /checker.tal: -------------------------------------------------------------------------------- 1 | ( devices ) 2 | 3 | |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] 4 | |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 5 | 6 | ( variables ) 7 | 8 | |0000 9 | 10 | @scroll [ &x $2 &y $2 ] 11 | 12 | ( program ) 13 | 14 | |0100 ( -> ) 15 | 16 | ( theme ) 17 | #2ee5 .System/r DEO2 18 | #23c5 .System/g DEO2 19 | #4225 .System/b DEO2 20 | 21 | ( vectors ) 22 | ;on-frame .Screen/vector DEO2 23 | 24 | BRK 25 | 26 | @on-frame ( -> ) 27 | ( scrolling ) 28 | .scroll/x LDZ2 #0002 ADD2 .scroll/x STZ2 29 | .scroll/y LDZ2 #0003 ADD2 .scroll/y STZ2 30 | 31 | ( y = 0 ) 32 | #0000 ,&y STR2 33 | 34 | &loop-y 35 | ( y ++ ) 36 | ,&y LDR2 INC2 DUP2 ,&y STR2 .Screen/y DEO2 37 | 38 | ( x = 0 ) 39 | #0000 ,&x STR2 40 | 41 | ( checker pattern ) 42 | ,&y POPk LDR 43 | .scroll/y INC LDZ ADD #20 AND 44 | .scroll/x INC LDZ EOR ,&chk STR 45 | 46 | &loop-x 47 | ( x ++ ) 48 | ,&x LDR2 INC2 DUP2 ,&x STR2 .Screen/x DEO2 49 | 50 | ( checker pattern ) 51 | ,&chk LDR INC DUP ,&chk STR #05 SFT #01 AND 52 | .Screen/pixel DEO 53 | 54 | ( jump if x < width ) 55 | ,&x LDR2 .Screen/width DEI2 LTH2 ,&loop-x JCN 56 | 57 | ( jump if y < height ) 58 | ,&y LDR2 .Screen/height DEI2 LTH2 ,&loop-y JCN 59 | 60 | BRK 61 | 62 | &x $2 63 | &y $2 64 | &chk $1 65 | 66 | -------------------------------------------------------------------------------- /decimal.tal: -------------------------------------------------------------------------------- 1 | ( devices ) 2 | 3 | |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] 4 | |20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 5 | &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 6 | 7 | ( variables ) 8 | 9 | |0000 10 | 11 | @count $2 12 | 13 | ( program ) 14 | 15 | |0100 ( -> ) 16 | 17 | #07ff .System/r DEO2 18 | #0e4f .System/g DEO2 19 | #0c4f .System/b DEO2 20 | ;step .Screen/vector DEO2 21 | 22 | BRK 23 | 24 | @step 25 | 26 | ( count ++ ) 27 | ;count LDA2 INC2 ;count STA2 28 | 29 | ( draw count ) 30 | #0010 #0010 ;count LDA2 #01 ;draw-dec JSR2 31 | 32 | BRK 33 | 34 | @draw-dec ( x* y* num* color -- ) 35 | 36 | STH ( use return stack to store color ) 37 | 38 | ( apply x* and y* ) 39 | STH2 [ .Screen/y DEO2 ] [ .Screen/x DEO2 ] STH2r 40 | 41 | ( x-axis auto increment ) 42 | #01 .Screen/auto DEO 43 | 44 | ( 10,000 ) 45 | #2710 DIV2k DUP2 NIP 46 | [ #30 SFT #00 SWP ] [ ;font-dec ADD2 .Screen/addr DEO2 ] 47 | STHkr .Screen/sprite DEO 48 | MUL2 SUB2 49 | 50 | ( 1,000 ) 51 | #03e8 DIV2k DUP2 NIP 52 | [ #30 SFT #00 SWP ] [ ;font-dec ADD2 .Screen/addr DEO2 ] 53 | STHkr .Screen/sprite DEO 54 | MUL2 SUB2 55 | 56 | ( 100 ) 57 | #0064 DIV2k DUP2 NIP 58 | [ #30 SFT #00 SWP ] [ ;font-dec ADD2 .Screen/addr DEO2 ] 59 | STHkr .Screen/sprite DEO 60 | MUL2 SUB2 NIP 61 | 62 | ( 10 ) 63 | #0a DIVk DUP 64 | [ #30 SFT #00 SWP ] [ ;font-dec ADD2 .Screen/addr DEO2 ] 65 | STHkr .Screen/sprite DEO 66 | MUL SUB 67 | 68 | ( 1 ) 69 | [ #30 SFT #00 SWP ] [ ;font-dec ADD2 .Screen/addr DEO2 ] 70 | STHr .Screen/sprite DEO 71 | 72 | JMP2r 73 | 74 | @font-dec 75 | 007c 8282 8282 827c 76 | 0030 1010 1010 1010 77 | 007c 8202 7c80 80fe 78 | 007c 8202 1c02 827c 79 | 000c 1424 4484 fe04 80 | 00fe 8080 7c02 827c 81 | 007c 8280 fc82 827c 82 | 007c 8202 1e02 0202 83 | 007c 8282 7c82 827c 84 | 007c 8282 7e02 827c 85 | -------------------------------------------------------------------------------- /sprite.tal: -------------------------------------------------------------------------------- 1 | ( devices ) 2 | 3 | |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] 4 | |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] 5 | 6 | ( variables ) 7 | 8 | |0000 9 | 10 | ( program ) 11 | 12 | |0100 ( -> ) 13 | 14 | ( theme ) 15 | #2fe5 .System/r DEO2 16 | #2fc5 .System/g DEO2 17 | #4f25 .System/b DEO2 18 | 19 | ( random seed ) 20 | #01 ;rand/a STA 21 | 22 | ( initialization ) 23 | #00 24 | &ball-init-loop 25 | DUP ;rand JSR2 #07 AND #01 ORA SWP STZ 26 | INC DUP ;rand JSR2 SWP STZ 27 | INC DUP ;rand JSR2 #07 AND #01 ORA SWP STZ 28 | INC DUP ;rand JSR2 SWP STZ 29 | INC DUP ,&ball-init-loop JCN 30 | POP 31 | 32 | ( vectors ) 33 | ;on-frame .Screen/vector DEO2 34 | 35 | BRK 36 | 37 | @on-frame ( -> ) 38 | ;sprite .Screen/addr DEO2 39 | 40 | ( clear ) 41 | #00 42 | &ball-clear-loop 43 | INC #00 OVR LDZ .Screen/x DEO2 44 | INC 45 | INC #00 OVR LDZ .Screen/y DEO2 46 | #00 .Screen/sprite DEO 47 | INC DUP ,&ball-clear-loop JCN 48 | POP 49 | 50 | ( move ) 51 | #00 52 | &ball-update-loop 53 | LDZk SWP INC LDZk ROT ADD SWP STZk NIP INC 54 | LDZk SWP INC LDZk ROT ADD SWP STZk NIP INC 55 | DUP ,&ball-update-loop JCN 56 | POP 57 | 58 | ( draw ) 59 | #00 60 | &ball-draw-loop 61 | INC #00 OVR LDZ .Screen/x DEO2 62 | INC 63 | INC #00 OVR LDZ .Screen/y DEO2 64 | #01 .Screen/sprite DEO 65 | INC DUP ,&ball-draw-loop JCN 66 | POP 67 | 68 | BRK 69 | 70 | @sprite 71 | 3c7e ffff ffff 7e3c 72 | 73 | @rand ( -- number ) 74 | ( 8-bit PRNG https://github.com/edrosten/8bit_rng ) 75 | 76 | ( t = x ^ (x << 4) ) 77 | ,&x LDR DUP #40 SFT EOR 78 | ( x = y ) 79 | ,&y LDR ,&x STR 80 | ( y = z ) 81 | ,&z LDR ,&y STR 82 | ( z = a ) 83 | ,&a LDR DUP ,&z STR 84 | ( a = z ^ t ^ (z >> 1) ^ (t << 1) ) 85 | DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR 86 | DUP ,&a STR 87 | JMP2r 88 | 89 | &x $1 &y $1 &z $1 &a $1 90 | -------------------------------------------------------------------------------- /flappy.tal: -------------------------------------------------------------------------------- 1 | ( flappy thing ) 2 | ( released under unlicense.org ) 3 | 4 | ( coding convention: roughly follows the standard forth and uxn conventions 5 | but uses the Captal Letters to express short values ) 6 | 7 | ( we use special representations to express y-axis values ) 8 | ( player: 4-bit fixed point numbers ) 9 | ( wall: sprite row numbers [divided by 8] ) 10 | 11 | ( macros ) 12 | 13 | %+ { ADD } %- { SUB } %* { MUL } %/ { DIV } 14 | %< { LTH } %> { GTH } %= { EQU } %! { NEQ } 15 | 16 | %++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } 17 | %<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } 18 | 19 | %NOT { #00 EQU } 20 | %DEC { #01 SUB } %DEC2 { #0001 SUB2 } 21 | 22 | %2* { #10 SFT } %4* { #20 SFT } %8* { #30 SFT } 23 | %2/ { #01 SFT } %4/ { #02 SFT } %8/ { #03 SFT } 24 | 25 | %2** { #10 SFT2 } %4** { #20 SFT2 } %8** { #30 SFT2 } 26 | %2// { #01 SFT2 } %4// { #02 SFT2 } %8// { #03 SFT2 } 27 | 28 | %RTN { JMP2r } 29 | 30 | ( devices ) 31 | 32 | |00 @system [ &Vector $2 &pad $6 &R $2 &G $2 &B $2 ] 33 | |20 @screen [ &Vector $2 &Width $2 &Height $2 &auto $1 &pad $1 34 | &X $2 &Y $2 &Addr $2 &pixel $1 &sprite $1 ] 35 | |80 @controller [ &Vector $2 &button $1 &key $1 ] 36 | 37 | ( constants ) 38 | 39 | %Gravity { #0004 } 40 | %Thrust { #0040 } 41 | %Player-x { #0100 } 42 | %Start-y { #0800 } 43 | %Scroll { #0004 } 44 | 45 | ( variables ) 46 | 47 | |0000 48 | 49 | @player [ &Y $2 &V $2 ] 50 | @wall [ &X $2 &y $1 &h $1 ] 51 | 52 | |0080 @score $2 53 | 54 | ( program ) 55 | 56 | |0100 ( -> ) 57 | 58 | ( theme ) 59 | #07ff .system/R DEO2 60 | #0e4f .system/G DEO2 61 | #0c4f .system/B DEO2 62 | 63 | ( random seed ) 64 | #03 ;rand/a STA 65 | 66 | ( vector ) 67 | ;step-game .screen/Vector DEO2 68 | 69 | ( game reset ) 70 | ;reset-game JSR2 71 | 72 | BRK 73 | 74 | @reset-game ( -> ) 75 | 76 | ;clear-screen JSR2 77 | 78 | ( player reset ) 79 | #40 ;draw-player JSR2 80 | Start-y .player/Y STZ2 81 | Thrust .player/V STZ2 82 | 83 | ( 1st wall ) 84 | ;init-wall JSR2 85 | #01 ;save-wall JSR2 86 | 87 | ( 2nd wall ) 88 | ;init-wall JSR2 89 | .wall/X LDZ2 #00c0 ++ .wall/X STZ2 90 | #02 ;save-wall JSR2 91 | 92 | ( 3rd wall ) 93 | ;init-wall JSR2 94 | .wall/X LDZ2 #0180 ++ .wall/X STZ2 95 | #03 ;save-wall JSR2 96 | 97 | ( reset score ) 98 | #0000 .score STZ2 99 | 100 | RTN 101 | 102 | @step-game ( -> ) 103 | 104 | ( player update ) 105 | [ #40 ;draw-player JSR2 ] [ ;update-player JSR2 ] 106 | 107 | ( 1st wall update ) 108 | [ #01 ;load-wall JSR2 ] [ ;update-wall JSR2 ] [ #01 ;save-wall JSR2 ] 109 | [ ;check-collision JSR2 ,&kill JCN ] [ ;draw-wall JSR2 ] 110 | 111 | ( 2nd wall update ) 112 | [ #02 ;load-wall JSR2 ] [ ;update-wall JSR2 ] [ #02 ;save-wall JSR2 ] 113 | [ ;check-collision JSR2 ,&kill JCN ] [ ;draw-wall JSR2 ] 114 | 115 | ( 3rd wall update ) 116 | [ #03 ;load-wall JSR2 ] [ ;update-wall JSR2 ] [ #03 ;save-wall JSR2 ] 117 | [ ;check-collision JSR2 ,&kill JCN ] [ ;draw-wall JSR2 ] 118 | 119 | ( player draw ) 120 | #4a ;draw-player JSR2 121 | 122 | ( score ) 123 | .score LDZ2 INC2 .score STZ2 124 | ;score LDZ2 #01 ;draw-score JSR2 125 | 126 | BRK 127 | 128 | &kill 129 | ( replace screen vector ) 130 | ;step-kill .screen/Vector DEO2 131 | .score LDZ2 #02 ;draw-score JSR2 132 | 133 | BRK 134 | 135 | @step-kill ( -> ) 136 | 137 | ( increment count until 32 ) 138 | ,&count LDR INC 139 | DUP #20 > ,&term JCN 140 | DUP ,&count STR 141 | 142 | ( blinking player with count&2 ) 143 | #01 AND #41 ADD ;draw-player JSR2 144 | 145 | BRK 146 | 147 | &term ( count -- ) 148 | 149 | ( reset all ) 150 | POP 151 | #00 ,&count STR 152 | ;reset-game JSR2 153 | ;step-game .screen/Vector DEO2 154 | 155 | BRK 156 | 157 | &count $1 158 | 159 | ( wall ) 160 | 161 | @init-wall ( -- ) 162 | 163 | ( X = Width ) 164 | .screen/Width DEI2 .wall/X STZ2 165 | 166 | ( y = [rand & 0x1f] + 1 ) 167 | ;rand JSR2 #1f AND #01 + .wall/y STZ 168 | 169 | ( h = 8 ) 170 | #08 .wall/h STZ 171 | 172 | RTN 173 | 174 | @update-wall ( -- ) 175 | 176 | ( jump to init-wall if X < -32 ) 177 | .wall/X LDZ2 #0020 ++ #8000 >> ;init-wall JCN2 178 | 179 | ( X -= Scroll ) 180 | .wall/X LDZ2 Scroll -- .wall/X STZ2 181 | 182 | RTN 183 | 184 | @draw-wall ( -- ) 185 | 186 | ( pipe from 0 to [y - 1] ) 187 | [ .wall/X LDZ2 ] [ #00 ] [ .wall/y LDZ DEC ] ;draw-pipe JSR2 188 | 189 | ( ring at [y - 1] ) 190 | [ .wall/X LDZ2 ] [ .wall/y LDZ DEC ] ;draw-ring JSR2 191 | 192 | ( ring at [y + h] ) 193 | [ .wall/X LDZ2 ] [ .wall/y LDZ .wall/h LDZ + ] ;draw-ring JSR2 194 | 195 | ( pipe from [y + h] to [height / 8 - y - h] ) 196 | ( X ) .wall/X LDZ2 197 | ( y ) .wall/y LDZ .wall/h LDZ + INC 198 | ( h ) .screen/Height DEI2 8// NIP .wall/y LDZ - .wall/h LDZ - 199 | ;draw-pipe JSR2 200 | 201 | RTN 202 | 203 | @draw-ring ( X y -- ) 204 | ( sprite position = X, y * 8 ) 205 | [ #00 SWP 8** .screen/Y DEO2 ] [ .screen/X DEO2 ] 206 | 207 | ( sprite pattern and auto increment ) 208 | [ ;&sprite .screen/Addr DEO2 ] [ #05 .screen/auto DEO ] 209 | 210 | ( draw sprites ) 211 | #01 .screen/sprite DEOk DEOk DEOk DEOk DEO 212 | 213 | RTN 214 | 215 | &sprite 216 | ffef efef efef ff00 217 | ffb9 bab9 bab9 ff00 218 | ff40 9040 a840 ff00 219 | ff01 0101 0101 ff00 220 | 0000 0000 0000 0000 221 | 222 | @draw-pipe ( X y h -- ) 223 | 224 | ( rs = h, &X = X, ws = Y * 8 ) 225 | [ STH ] [ ROT ROT ,&X STR2 ] [ #00 SWP 8** ] 226 | 227 | ( sprite auto increment ) 228 | #05 .screen/auto DEO 229 | 230 | &yloop 231 | ( set position ) 232 | [ ,&X LDR2 .screen/X DEO2 ] [ DUP2 .screen/Y DEO2 ] 233 | 234 | ( draw sprites with auto increment ) 235 | ;&sprite .screen/Addr DEO2 236 | #01 .screen/sprite DEOk DEOk DEOk DEOk DEO 237 | 238 | #0008 ++ ( next row ) 239 | STHr DEC STHk ,&yloop JCN ( loop until --h == 0 ) 240 | 241 | POP2 POPr 242 | 243 | RTN 244 | 245 | &X $2 246 | 247 | &sprite 248 | 3737 3737 3737 3737 249 | dcdd dcdd dcdd dcdd 250 | a054 a048 a054 a048 251 | 0404 0404 0404 0404 252 | 0000 0000 0000 0000 253 | 254 | ( wall multiplexer ) 255 | 256 | @save-wall ( idx -- ) 257 | 4* .wall/X + ( address of wall[idx] ) 258 | DUP .wall/X LDZ2 ROT STZ2 ( copy first word ) 259 | INC INC .wall/y LDZ2 ROT STZ2 ( copy second word ) 260 | RTN 261 | 262 | @load-wall ( idx -- ) 263 | 4* .wall/X + ( address of wall[idx] ) 264 | LDZ2k .wall/X STZ2 ( copy first word ) 265 | INC INC LDZ2 .wall/y STZ2 ( copy second word ) 266 | RTN 267 | 268 | ( player ) 269 | 270 | @update-player ( -- ) 271 | 272 | ( reset V on up-key press ) 273 | ;get-up-key JSR2 NOT ,&no-up JCN 274 | Thrust .player/V STZ2 275 | &no-up 276 | 277 | ( V += Gravity ) 278 | .player/V LDZ2 Gravity ++ .player/V STZ2 279 | 280 | ( Y += V - 0080 ) 281 | .player/Y LDZ2 .player/V LDZ2 ++ #0080 -- .player/Y STZ2 282 | 283 | RTN 284 | 285 | @check-collision ( -- hit ) 286 | 287 | ( x-check ) 288 | 289 | ( check: wall/X - player/X + 24 < 32 ) 290 | .wall/X LDZ2 Player-x -- #0018 ++ #0020 << 291 | 292 | ( return 0 on false ) 293 | ,&x-ok JCN 294 | #00 RTN 295 | &x-ok 296 | 297 | ( y-check ) 298 | 299 | ( temp = player/Y / 8 / 16 + 1 ) 300 | .player/Y LDZ2 #07 SFT2 NIP INC 301 | 302 | ( check: temp+1 > wall/y ) 303 | DUP INC .wall/y LDZ > 304 | 305 | ( return 1 on false ) 306 | ,&y-gth JCN 307 | POP #01 RTN 308 | &y-gth 309 | 310 | ( check: temp > wall/y + wall/h ) 311 | .wall/y LDZ .wall/h LDZ + > 312 | 313 | ( use result as return value ) 314 | RTN 315 | 316 | @draw-player ( color -- ) 317 | 318 | STH ( use return stack to store color ) 319 | 320 | ( sprite settings: pattern address and auto increment ) 321 | [ ;&sprite #00 .player/V LDZ2 #0080 >> #50 SFT2 ADD2 .screen/Addr DEO2 ] [ #05 .screen/auto DEO ] 322 | 323 | ( y-axis position ) 324 | .player/Y LDZ2 #04 SFT2 325 | 326 | ( first row ) 327 | [ Player-x .screen/X DEO2 ] [ DUP2 .screen/Y DEO2 ] 328 | STHrk .screen/sprite DEOk DEO 329 | 330 | ( second row ) 331 | [ Player-x .screen/X DEO2 ] [ #0008 ++ .screen/Y DEO2 ] 332 | STHr .screen/sprite DEOk DEO 333 | 334 | RTN 335 | &sprite 336 | 0000 0000 0001 0307 337 | 0010 3874 fec0 c0c0 338 | 0f1c 3870 0000 0000 339 | a070 7070 7030 1000 340 | ( down ) 341 | 1018 1c1e 0e05 0307 342 | 0010 3874 fec0 c0e0 343 | 0f1c 3870 0000 0000 344 | e000 0000 0000 0000 345 | 346 | ( misc ) 347 | 348 | @clear-screen ( -- ) 349 | 350 | ( sprite pattern and auto increment ) 351 | [ ;&sprite .screen/Addr DEO2 ] [ #01 .screen/auto DEO ] 352 | 353 | ( col = screen/Width / 8 ) 354 | .screen/Width DEI2 8// NIP ,&col STR 355 | 356 | ( ws: row count ) 357 | .screen/Height DEI2 8// NIP 358 | 359 | &y-loop 360 | DEC ( next row ) 361 | 362 | ( sprite position = 0, row * 8 ) 363 | [ #0000 .screen/X DEO2 ] [ DUP #00 SWP 8** .screen/Y DEO2 ] 364 | 365 | ( ws: DEO params, rs: column count ) 366 | [ #00 .screen/sprite ] [ ,&col LDR STH ] 367 | 368 | ( row fill ) 369 | &x-loop DEOk STHr DEC STHk ,&x-loop JCN 370 | 371 | POP2 POPr ( stack restore ) 372 | DUP ,&y-loop JCN ( loop until row == 0 ) 373 | POP 374 | 375 | RTN 376 | 377 | &col $1 378 | &sprite 0000 0000 0000 0000 379 | 380 | @get-up-key ( -- up ) 381 | 382 | .controller/button DEI #04 SFT #01 AND 383 | 384 | RTN 385 | 386 | @rand ( -- number ) 387 | 388 | ( 8-bit PRNG https://github.com/edrosten/8bit_rng ) 389 | 390 | ( t = x ^ (x << 4) ) 391 | ,&x LDR DUP #40 SFT EOR 392 | ( x = y ) 393 | ,&y LDR ,&x STR 394 | ( y = z ) 395 | ,&z LDR ,&y STR 396 | ( z = a ) 397 | ,&a LDR DUP ,&z STR 398 | ( a = z ^ t ^ (z >> 1) ^ (t << 1) ) 399 | DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR 400 | DUP ,&a STR 401 | 402 | RTN 403 | 404 | &x $1 &y $1 &z $1 &a $1 405 | 406 | @draw-score ( short* color -- ) 407 | 408 | #0010 .screen/X DEO2 409 | #0010 .screen/Y DEO2 410 | 411 | STH SWP 412 | DUP #04 SFT #00 SWP 8** ;font-hex ++ .screen/Addr DEO2 413 | ( draw ) STHkr .screen/sprite DEO 414 | #0f AND #00 SWP 8** ;font-hex ++ .screen/Addr DEO2 415 | #0018 .screen/X DEO2 416 | ( draw ) STHkr .screen/sprite DEO 417 | DUP #04 SFT #00 SWP 8** ;font-hex ++ .screen/Addr DEO2 418 | #0020 .screen/X DEO2 419 | ( draw ) STHkr .screen/sprite DEO 420 | #0f AND #00 SWP 8** ;font-hex ++ .screen/Addr DEO2 421 | #0028 .screen/X DEO2 422 | ( draw ) STHr .screen/sprite DEO 423 | 424 | RTN 425 | 426 | @font-hex 427 | 007c 8282 8282 827c 0030 1010 1010 1010 428 | 007c 8202 7c80 80fe 007c 8202 1c02 827c 429 | 000c 1424 4484 fe04 00fe 8080 7c02 827c 430 | 007c 8280 fc82 827c 007c 8202 1e02 0202 431 | 007c 8282 7c82 827c 007c 8282 7e02 827c 432 | 007c 8202 7e82 827e 00fc 8282 fc82 82fc 433 | 007c 8280 8080 827c 00fc 8282 8282 82fc 434 | 007c 8280 f080 827c 007c 8280 f080 8080 435 | --------------------------------------------------------------------------------