| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,194 @@ |
| 1 |
+( uxnasm projects/examples/demos/snake.tal bin/snake.rom && uxnemu bin/snake.rom ) |
|
| 2 |
+ |
|
| 3 |
+%+ { ADD } %- { SUB } %/ { DIV }
|
|
| 4 |
+%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
|
|
| 5 |
+%++ { ADD2 } %-- { SUB2 } %// { DIV2 }
|
|
| 6 |
+%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
|
|
| 7 |
+%2/ { #01 SFT } %2* { #10 SFT }
|
|
| 8 |
+%8// { #03 SFT2 } %8** { #30 SFT2 }
|
|
| 9 |
+%MOD { DIVk MUL SUB }
|
|
| 10 |
+%RTN { JMP2r }
|
|
| 11 |
+%TOS { #00 SWP }
|
|
| 12 |
+%SWP? { #01 JCN SWP }
|
|
| 13 |
+%BRK? { #01 JCN BRK }
|
|
| 14 |
+ |
|
| 15 |
+%DEBUG { ;print-hex JSR2 #0a .Console/write DEO }
|
|
| 16 |
+%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO }
|
|
| 17 |
+ |
|
| 18 |
+( devices ) |
|
| 19 |
+ |
|
| 20 |
+|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
|
| 21 |
+|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
|
| 22 |
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
| 23 |
+|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
|
| 24 |
+|80 @Controller [ &vector $2 &button $1 &key $1 ] |
|
| 25 |
+|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
|
| 26 |
+ |
|
| 27 |
+( variables ) |
|
| 28 |
+ |
|
| 29 |
+|0000 |
|
| 30 |
+ |
|
| 31 |
+( program ) |
|
| 32 |
+ |
|
| 33 |
+@arena |
|
| 34 |
+ &w $1 &h $1 &timer $1 |
|
| 35 |
+@apple |
|
| 36 |
+ &x $1 &y $1 |
|
| 37 |
+@snake |
|
| 38 |
+ &direction $1 &length $1 |
|
| 39 |
+ &x $1 &y $1 |
|
| 40 |
+ &tail |
|
| 41 |
+ |
|
| 42 |
+|0100 ( -> ) |
|
| 43 |
+ |
|
| 44 |
+ ( theme ) |
|
| 45 |
+ #0f2f .System/r DEO2 |
|
| 46 |
+ #0ff2 .System/g DEO2 |
|
| 47 |
+ #0022 .System/b DEO2 |
|
| 48 |
+ |
|
| 49 |
+ ( vectors ) |
|
| 50 |
+ ;on-frame .Screen/vector DEO2 |
|
| 51 |
+ ;on-button .Controller/vector DEO2 |
|
| 52 |
+ |
|
| 53 |
+ ( resize ) |
|
| 54 |
+ #00c0 .Screen/width DEO2 |
|
| 55 |
+ #0100 .Screen/height DEO2 |
|
| 56 |
+ |
|
| 57 |
+ .Screen/width DEI2 8// NIP .arena/w STZ |
|
| 58 |
+ .Screen/height DEI2 8// NIP .arena/h STZ |
|
| 59 |
+ |
|
| 60 |
+ ( put snake ) |
|
| 61 |
+ .arena/w LDZ 2/ #01 - .snake/x STZ |
|
| 62 |
+ .arena/h LDZ 2/ #01 - .snake/y STZ |
|
| 63 |
+ |
|
| 64 |
+ ;add-apple JSR2 |
|
| 65 |
+ |
|
| 66 |
+BRK |
|
| 67 |
+ |
|
| 68 |
+@on-frame ( -> ) |
|
| 69 |
+ |
|
| 70 |
+ .arena/timer LDZ INC DUP .arena/timer STZ |
|
| 71 |
+ #06 = BRK? |
|
| 72 |
+ |
|
| 73 |
+ #00 ;draw-snake JSR2 |
|
| 74 |
+ ;move JSR2 |
|
| 75 |
+ #02 ;draw-snake JSR2 |
|
| 76 |
+ |
|
| 77 |
+ ( reset ) #00 .arena/timer STZ |
|
| 78 |
+ |
|
| 79 |
+BRK |
|
| 80 |
+ |
|
| 81 |
+@on-button ( -> ) |
|
| 82 |
+ |
|
| 83 |
+ .Controller/button DEI #04 SFT |
|
| 84 |
+ DUP #00 = ,&skip JCN |
|
| 85 |
+ DUP .snake/direction STZ |
|
| 86 |
+ &skip |
|
| 87 |
+ POP |
|
| 88 |
+ |
|
| 89 |
+BRK |
|
| 90 |
+ |
|
| 91 |
+@move ( -- ) |
|
| 92 |
+ |
|
| 93 |
+ ( tail ) |
|
| 94 |
+ .snake/x LDZ2 STH2 |
|
| 95 |
+ .snake/length LDZ #00 |
|
| 96 |
+ &loop |
|
| 97 |
+ DUP 2* .snake/tail + LDZ2 STH2 |
|
| 98 |
+ SWP2r |
|
| 99 |
+ DUP 2* .snake/tail + STH2r ROT STZ2 |
|
| 100 |
+ INC GTHk ,&loop JCN |
|
| 101 |
+ POP2 |
|
| 102 |
+ POP2r |
|
| 103 |
+ |
|
| 104 |
+ .snake/direction LDZ |
|
| 105 |
+ DUP #01 ! ,&no-up JCN |
|
| 106 |
+ .snake/y LDZ #01 - |
|
| 107 |
+ .arena/h LDZ LTHk SWP? POP |
|
| 108 |
+ .snake/y STZ |
|
| 109 |
+ &no-up |
|
| 110 |
+ DUP #02 ! ,&no-down JCN |
|
| 111 |
+ .snake/y LDZ INC |
|
| 112 |
+ .arena/h LDZ MOD |
|
| 113 |
+ .snake/y STZ |
|
| 114 |
+ &no-down |
|
| 115 |
+ DUP #04 ! ,&no-left JCN |
|
| 116 |
+ .snake/x LDZ #01 - |
|
| 117 |
+ .arena/w LDZ LTHk SWP? POP |
|
| 118 |
+ .snake/x STZ |
|
| 119 |
+ &no-left |
|
| 120 |
+ DUP #08 ! ,&no-right JCN |
|
| 121 |
+ .snake/x LDZ INC |
|
| 122 |
+ .arena/w LDZ MOD |
|
| 123 |
+ .snake/x STZ |
|
| 124 |
+ &no-right |
|
| 125 |
+ POP |
|
| 126 |
+ |
|
| 127 |
+ ( detect collision ) |
|
| 128 |
+ .snake/x LDZ .apple/x LDZ ! ,&no-collision JCN |
|
| 129 |
+ .snake/y LDZ .apple/y LDZ ! ,&no-collision JCN |
|
| 130 |
+ #00 ;draw-apple JSR2 |
|
| 131 |
+ .snake/length LDZ INC DUP DEBUG .snake/length STZ |
|
| 132 |
+ ;add-apple JSR2 |
|
| 133 |
+ ;move JSR2 |
|
| 134 |
+ &no-collision |
|
| 135 |
+ |
|
| 136 |
+RTN |
|
| 137 |
+ |
|
| 138 |
+@add-apple ( -- ) |
|
| 139 |
+ |
|
| 140 |
+ ( seed ) |
|
| 141 |
+ .DateTime/hour DEI2 .DateTime/minute DEI2 MUL2 #1234 MUL2 + |
|
| 142 |
+ .arena/w LDZ MOD .apple/x STZ |
|
| 143 |
+ .DateTime/hour DEI2 .DateTime/minute DEI2 MUL2 #abcd MUL2 + |
|
| 144 |
+ .arena/h LDZ MOD .apple/y STZ |
|
| 145 |
+ |
|
| 146 |
+ #03 ;draw-apple JSR2 |
|
| 147 |
+ |
|
| 148 |
+RTN |
|
| 149 |
+ |
|
| 150 |
+@draw-snake ( color -- ) |
|
| 151 |
+ |
|
| 152 |
+ .snake/x LDZ TOS 8** .Screen/x DEO2 |
|
| 153 |
+ .snake/y LDZ TOS 8** .Screen/y DEO2 |
|
| 154 |
+ ;snake-icns .Screen/addr DEO2 |
|
| 155 |
+ STHk .Screen/sprite DEO |
|
| 156 |
+ |
|
| 157 |
+ ( draw tail ) |
|
| 158 |
+ .snake/length LDZ #00 |
|
| 159 |
+ &loop |
|
| 160 |
+ DUP 2* .snake/tail + LDZ TOS 8** .Screen/x DEO2 |
|
| 161 |
+ DUP 2* .snake/tail + INC LDZ TOS 8** .Screen/y DEO2 |
|
| 162 |
+ STHkr .Screen/sprite DEO |
|
| 163 |
+ INC GTHk ,&loop JCN |
|
| 164 |
+ POP2 |
|
| 165 |
+ POPr |
|
| 166 |
+ |
|
| 167 |
+RTN |
|
| 168 |
+ |
|
| 169 |
+@draw-apple ( color -- ) |
|
| 170 |
+ .apple/x LDZ TOS 8** .Screen/x DEO2 |
|
| 171 |
+ .apple/y LDZ TOS 8** .Screen/y DEO2 |
|
| 172 |
+ ;apple-icn .Screen/addr DEO2 |
|
| 173 |
+ .Screen/sprite DEO |
|
| 174 |
+ RTN |
|
| 175 |
+ |
|
| 176 |
+RTN |
|
| 177 |
+ |
|
| 178 |
+@print-hex ( value -- ) |
|
| 179 |
+ |
|
| 180 |
+ STHk #04 SFT ,&parse JSR .Console/write DEO |
|
| 181 |
+ STHr #0f AND ,&parse JSR .Console/write DEO |
|
| 182 |
+ RTN |
|
| 183 |
+ &parse ( value -- char ) |
|
| 184 |
+ DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN |
|
| 185 |
+ |
|
| 186 |
+RTN |
|
| 187 |
+ |
|
| 188 |
+( assets ) |
|
| 189 |
+ |
|
| 190 |
+@snake-icns |
|
| 191 |
+ ffff ffff ffff ffff |
|
| 192 |
+@apple-icn |
|
| 193 |
+ ffff ffff ffff ffff |
|
| 194 |
+ |