| 1 | #ifndef WUMP_GAME |
| 2 | #define WUMP_GAME |
| 3 | |
| 4 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 5 | @ (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com> |
| 6 | @ See LICENSE.txt file for copyright and license details. |
| 7 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 8 | |
| 9 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 10 | @ Name: |
| 11 | @ get_tunnel_destination |
| 12 | @ Description: |
| 13 | @ Returns the room number corresponding to the destination of a tunnel |
| 14 | @ specified by room and slot. |
| 15 | @ Call Stack: |
| 16 | @ slot |
| 17 | @ room_number <-- TOS |
| 18 | @ Return Stack: |
| 19 | @ dst_room_number <-- TOS |
| 20 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 21 | NSSVTSSSTSSSN | MARK: 10001000 (get_tunnel_destination) |
| 22 | @ The pointer we seek is: |
| 23 | @ (room_number * room_struct_size) + 2 + slot + ROOM_DATA_BASE |
| 24 | @ Where the '+2' accounts for the pit and bat booleans. |
| 25 | NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size) |
| 26 | TSSN | MULTIPLY |
| 27 | SSSTSN | PUSH +2 |
| 28 | TSSS | ADD |
| 29 | TSSS | ADD |
| 30 | SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (ROOM_DATA_BASE address) |
| 31 | TSSS | ADD |
| 32 | TTT | LOAD |
| 33 | NTN | RTS |
| 34 | |
| 35 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 36 | @ Name: |
| 37 | @ get_room_struct_size |
| 38 | @ Description: |
| 39 | @ Returns the size in words of the data structure for a single room. |
| 40 | @ For example, with 3 links plus bat and pit booleans, the size is 5 words. |
| 41 | @ Call Stack: |
| 42 | @ <empty> |
| 43 | @ Return Stack: |
| 44 | @ size <-- TOS |
| 45 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 46 | NSSVTSSSTSTTN | MARK: 10001011 (get_room_struct_size) |
| 47 | SSSTSSSSSSSSSSTTN | PUSH 0x1003 (GAME_DATA_BASE+3 = links_per_room address) |
| 48 | TTT | LOAD |
| 49 | SSSTSN | PUSH +2 |
| 50 | TSSS | ADD |
| 51 | NTN | RTS |
| 52 | |
| 53 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 54 | @ Name: |
| 55 | @ room_has_bats |
| 56 | @ Description: |
| 57 | @ Check if room_number contains bats. |
| 58 | @ Returns 1 or 0 representing true or false. |
| 59 | @ Call Stack: |
| 60 | @ room_number <-- TOS |
| 61 | @ Return Stack: |
| 62 | @ 1 or 0 <-- TOS |
| 63 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 64 | NSSVTSSSTTSSN | MARK: 10001100 (room_has_bats) |
| 65 | @ We seek the pointer: |
| 66 | @ (room_number * room_struct_size) + 1 + ROOM_DATA_BASE |
| 67 | @ where '+1' accounts for the offset of the bat boolean in the desired room. |
| 68 | NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size) |
| 69 | TSSN | MULTIPLY |
| 70 | SSSTN | PUSH +1 |
| 71 | TSSS | ADD |
| 72 | SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address) |
| 73 | TSSS | ADD |
| 74 | TTT | LOAD |
| 75 | NTN | RTS |
| 76 | |
| 77 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 78 | @ Name: |
| 79 | @ room_has_pits |
| 80 | @ Description: |
| 81 | @ Check if room_number contains pits. |
| 82 | @ Returns 1 or 0 representing true or false. |
| 83 | @ Call Stack: |
| 84 | @ room_number <-- TOS |
| 85 | @ Return Stack: |
| 86 | @ 1 or 0 <-- TOS |
| 87 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 88 | NSSVTSSSTTSTN | MARK: 10001101 (room_has_pits) |
| 89 | @ We seek the pointer: |
| 90 | @ (room_number * room_struct_size) + 0 + ROOM_DATA_BASE |
| 91 | @ where '+0' accounts for the offset of the pit boolean in the desired room. |
| 92 | NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size) |
| 93 | TSSN | MULTIPLY |
| 94 | SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address) |
| 95 | TSSS | ADD |
| 96 | TTT | LOAD |
| 97 | NTN | RTS |
| 98 | |
| 99 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 100 | @ Name: |
| 101 | @ room_has_wumpus |
| 102 | @ Description: |
| 103 | @ Check if room contains wumpus. |
| 104 | @ Returns 1 or 0 representing true or false. |
| 105 | @ Call Stack: |
| 106 | @ room_number <-- TOS |
| 107 | @ Return Stack: |
| 108 | @ 1 or 0 <-- TOS |
| 109 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 110 | NSSVTSTSSSSSN | MARK: 10100000 (room_has_wumpus) |
| 111 | SSSTSSSSSSSSSTTTN | PUSH 0x1007 (wumpus_location address) |
| 112 | TTT | LOAD |
| 113 | TSST | SUBTRACT |
| 114 | NTSTSTSSSSSSSSSSSSSN | BRZ > 10100000 00000000 (room_has_wumpus:true) |
| 115 | SSSSN | PUSH 0 (false) |
| 116 | NTN | RTS |
| 117 | NSSVTSTSSSSSSSSSSSSSN | MARK: 10100000 00000000 (room_has_wumpus:true) |
| 118 | SSSTN | PUSH 1 (true) |
| 119 | NTN | RTS |
| 120 | |
| 121 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 122 | @ Name: |
| 123 | @ are_bats_near |
| 124 | @ Description: |
| 125 | @ Given a room number, checks rooms within one hop for bats. |
| 126 | @ Returns 1 if bats are present or 0 if no bats. |
| 127 | @ Call Stack: |
| 128 | @ room_number <-- TOS |
| 129 | @ Return Stack: |
| 130 | @ 1 or 0 <-- TOS |
| 131 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 132 | #include <stack.pvvs> |
| 133 | NSSVTSSTTTSSN | MARK: 10011100 (are_bats_near) |
| 134 | |
| 135 | @ Prepare the stack by loading the number of links per room and decrementing. |
| 136 | @ We will loop until this reaches 0 or we find bats. |
| 137 | SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address) |
| 138 | TTT | LOAD |
| 139 | SSSTN | PUSH 1 |
| 140 | TSST | SUBTRACT |
| 141 | |
| 142 | @ Check one nearby room on each pass through this loop. |
| 143 | @ TOS> tunnel_index, room_number |
| 144 | NSSVTSSTTTSSSSSSSSSSN | MARK: 10011100 00000000 (are_bats_near:loop) |
| 145 | SNS | DUP |
| 146 | SSSTTN | PUSH 3 |
| 147 | NSTTTSSN | JSR > 1100 (deepdup) |
| 148 | NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) |
| 149 | NSTTSSSTTSSN | JSR > 10001100 (room_has_bats) |
| 150 | NTSTSSTTTSSSSSSSSSTN | BRZ > 10011100 00000001 (no_bats_in_this_room) |
| 151 | @ Found bats. Clean up and return. |
| 152 | SNN | DROP |
| 153 | SNN | DROP |
| 154 | SSSTN | PUSH 1 |
| 155 | NTN | RTS |
| 156 | NSSVTSSTTTSSSSSSSSSTN | MARK: 10011100 00000001 (no_bats_in_this_room) |
| 157 | @ Test for end of loop. |
| 158 | SNS | DUP |
| 159 | NTSTSSTTTSSSSSSSSTSN | BRZ > 10011100 00000010 (are_bats_near:loop_end) |
| 160 | @ No bats found yet, but still need to check some rooms. |
| 161 | @ Decrement tunnel index and loop again. |
| 162 | SSSTN | PUSH 1 |
| 163 | TSST | SUBTRACT |
| 164 | NSNTSSTTTSSSSSSSSSSN | JMP > 10011100 00000000 (are_bats_near:loop) |
| 165 | @ No bats found in nearby rooms. Clean up and return. |
| 166 | NSSVTSSTTTSSSSSSSSTSN | MARK: 10011100 00000010 (are_bats_near:loop_end) |
| 167 | SNN | DROP |
| 168 | SNN | DROP |
| 169 | SSSSN | PUSH 0 |
| 170 | NTN | RTS |
| 171 | |
| 172 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 173 | @ Name: |
| 174 | @ are_pits_near |
| 175 | @ Description: |
| 176 | @ Given a room number, checks rooms within one hop for pits. |
| 177 | @ Returns 1 if pits are present or 0 if no pits. |
| 178 | @ Call Stack: |
| 179 | @ room_number <-- TOS |
| 180 | @ Return Stack: |
| 181 | @ 1 or 0 <-- TOS |
| 182 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 183 | #include <stack.pvvs> |
| 184 | NSSVTSSTTTSTN | MARK: 10011101 (are_pits_near) |
| 185 | |
| 186 | @ Prepare the stack by loading the number of links per room and decrementing. |
| 187 | @ We will loop until this reaches 0 or we find pits. |
| 188 | SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address) |
| 189 | TTT | LOAD |
| 190 | SSSTN | PUSH 1 |
| 191 | TSST | SUBTRACT |
| 192 | |
| 193 | @ Check one nearby room on each pass through this loop. |
| 194 | @ TOS> tunnel_index, room_number |
| 195 | NSSVTSSTTTSTSSSSSSSSN | MARK: 10011101 00000000 (are_pits_near:loop) |
| 196 | SNS | DUP |
| 197 | SSSTTN | PUSH 3 |
| 198 | NSTTTSSN | JSR > 1100 (deepdup) |
| 199 | NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) |
| 200 | NSTTSSSTTSTN | JSR > 10001101 (room_has_pits) |
| 201 | NTSTSSTTTSTSSSSSSSTN | BRZ > 10011101 00000001 (no_pits_in_this_room) |
| 202 | @ Found pits. Clean up and return. |
| 203 | SNN | DROP |
| 204 | SNN | DROP |
| 205 | SSSTN | PUSH 1 |
| 206 | NTN | RTS |
| 207 | NSSVTSSTTTSTSSSSSSSTN | MARK: 10011101 00000001 (no_pits_in_this_room) |
| 208 | @ Test for end of loop. |
| 209 | SNS | DUP |
| 210 | NTSTSSTTTSTSSSSSSTSN | BRZ > 10011101 00000010 (are_pits_near:loop_end) |
| 211 | @ No pits found yet, but still need to check some rooms. |
| 212 | @ Decrement tunnel index and loop again. |
| 213 | SSSTN | PUSH 1 |
| 214 | TSST | SUBTRACT |
| 215 | NSNTSSTTTSTSSSSSSSSN | JMP > 10011101 00000000 (are_pits_near:loop) |
| 216 | @ No pits found in nearby rooms. Clean up and return. |
| 217 | NSSVTSSTTTSTSSSSSSTSN | MARK: 10011101 00000010 (are_pits_near:loop_end) |
| 218 | SNN | DROP |
| 219 | SNN | DROP |
| 220 | SSSSN | PUSH 0 |
| 221 | NTN | RTS |
| 222 | |
| 223 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 224 | @ Name: |
| 225 | @ is_wumpus_very_near |
| 226 | @ Description: |
| 227 | @ Given a room number, checks rooms within one hop for the wumpus. |
| 228 | @ Returns 1 if wumpus is present, otherwise 0. |
| 229 | @ Call Stack: |
| 230 | @ room_number <-- TOS |
| 231 | @ Return Stack: |
| 232 | @ 1 or 0 <-- TOS |
| 233 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 234 | #include <stack.pvvs> |
| 235 | NSSVTSSTTTTTN | MARK: 10011111 (is_wumpus_very_near) |
| 236 | |
| 237 | @ Prepare the stack by loading the number of links per room and decrementing. |
| 238 | @ We will loop until this reaches 0 or we find the wumpus. |
| 239 | SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address) |
| 240 | TTT | LOAD |
| 241 | SSSTN | PUSH 1 |
| 242 | TSST | SUBTRACT |
| 243 | |
| 244 | @ Check one nearby room on each pass through this loop. |
| 245 | @ TOS> tunnel_index, room_number |
| 246 | NSSVTSSTTTTTSSSSSSSSN | MARK: 10011111 00000000 (is_wumpus_very_near:loop) |
| 247 | SNS | DUP |
| 248 | SSSTTN | PUSH 3 |
| 249 | NSTTTSSN | JSR > 1100 (deepdup) |
| 250 | NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) |
| 251 | NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus) |
| 252 | NTSTSSTTTTTSSSSSSSTN | BRZ > 10011111 00000001 (no_wumpus_in_this_room) |
| 253 | @ Found wumpus. Clean up and return. |
| 254 | SNN | DROP |
| 255 | SNN | DROP |
| 256 | SSSTN | PUSH 1 |
| 257 | NTN | RTS |
| 258 | NSSVTSSTTTTTSSSSSSSTN | MARK: 10011111 00000001 (no_wumpus_in_this_room) |
| 259 | @ Test for end of loop. |
| 260 | SNS | DUP |
| 261 | NTSTSSTTTTTSSSSSSTSN | BRZ > 10011111 00000010 (is_wumpus_very_near:loop_end) |
| 262 | @ No wumpus found yet, but still need to check some rooms. |
| 263 | @ Decrement tunnel index and loop again. |
| 264 | SSSTN | PUSH 1 |
| 265 | TSST | SUBTRACT |
| 266 | NSNTSSTTTTTSSSSSSSSN | JMP > 10011111 00000000 (is_wumpus_very_near:loop) |
| 267 | @ No wumpus found in nearby rooms. Clean up and return. |
| 268 | NSSVTSSTTTTTSSSSSSTSN | MARK: 10011111 00000010 (is_wumpus_very_near:loop_end) |
| 269 | SNN | DROP |
| 270 | SNN | DROP |
| 271 | SSSSN | PUSH 0 |
| 272 | NTN | RTS |
| 273 | |
| 274 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 275 | @ Name: |
| 276 | @ is_wumpus_near |
| 277 | @ Description: |
| 278 | @ Given a room number, checks rooms within two hops for the wumpus. |
| 279 | @ Returns 1 if wumpus is present, otherwise 0. |
| 280 | @ Call Stack: |
| 281 | @ room_number <-- TOS |
| 282 | @ Return Stack: |
| 283 | @ 1 or 0 <-- TOS |
| 284 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 285 | #include <stack.pvvs> |
| 286 | NSSVTSSTTTTSN | MARK: 10011110 (is_wumpus_near) |
| 287 | |
| 288 | @ Prepare the stack by loading the number of links per room and decrementing. |
| 289 | @ We will loop until this reaches 0 or we find the wumpus. |
| 290 | SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address) |
| 291 | TTT | LOAD |
| 292 | SSSTN | PUSH 1 |
| 293 | TSST | SUBTRACT |
| 294 | |
| 295 | @ Check one nearby room and its connecting rooms on each pass through this loop. |
| 296 | @ TOS> tunnel_index, room_number |
| 297 | NSSVTSSTTTTSSSSSSSSSN | MARK: 10011110 00000000 (is_wumpus_near:loop) |
| 298 | SNS | DUP |
| 299 | SSSTTN | PUSH 3 |
| 300 | NSTTTSSN | JSR > 1100 (deepdup) |
| 301 | NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) |
| 302 | @ TOS> tunnel_endpoint, tunnel_index, room_number |
| 303 | SNS | DUP |
| 304 | NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus) |
| 305 | SSSTN | PUSH 1 |
| 306 | TSST | SUBTRACT |
| 307 | NTSTSSTTTTSSSSSSSTTN | BRZ > 10011110 00000011 (found_wumpus_one_hop) |
| 308 | NSTTSSTTTTTN | JSR > 10011111 (is_wumpus_very_near) |
| 309 | SSSTN | PUSH 1 |
| 310 | TSST | SUBTRACT |
| 311 | NTSTSSTTTTSSSSSSTSSN | BRZ > 10011110 00000100 (found_wumpus_two_hops) |
| 312 | @ Test for end of loop. |
| 313 | SNS | DUP |
| 314 | NTSTSSTTTTSSSSSSSTSN | BRZ > 10011110 00000010 (is_wumpus_near:loop_end) |
| 315 | @ No wumpus found yet, but still need to check some rooms. |
| 316 | @ Decrement tunnel index and loop again. |
| 317 | SSSTN | PUSH 1 |
| 318 | TSST | SUBTRACT |
| 319 | NSNTSSTTTTSSSSSSSSSN | JMP > 10011110 00000000 (is_wumpus_near:loop) |
| 320 | |
| 321 | @ No wumpus found in nearby rooms. Clean up and return. |
| 322 | NSSVTSSTTTTSSSSSSSTSN | MARK: 10011110 00000010 (is_wumpus_near:loop_end) |
| 323 | SNN | DROP |
| 324 | SNN | DROP |
| 325 | SSSSN | PUSH 0 |
| 326 | NTN | RTS |
| 327 | |
| 328 | @ Found wumpus. Clean up and return. |
| 329 | NSSVTSSTTTTSSSSSSSTTN | MARK: 10011110 00000011 (found_wumpus_one_hop) |
| 330 | SNN | DROP |
| 331 | NSSVTSSTTTTSSSSSSTSSN | MARK: 10011110 00000100 (found_wumpus_two_hops) |
| 332 | SNN | DROP |
| 333 | SNN | DROP |
| 334 | SSSTN | PUSH 1 |
| 335 | NTN | RTS |
| 336 | |
| 337 | #endif |