Added `shoot` function to Hunt the Wumpus (and updated README path).
[vvhitespace] / examples / hunt-the-wumpus / wump_game.pvvs
CommitLineData
2da74194
AT
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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
21NSSVTSSSTSSSN | 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.
25NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
26TSSN | MULTIPLY
27SSSTSN | PUSH +2
28TSSS | ADD
29TSSS | ADD
30SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (ROOM_DATA_BASE address)
31TSSS | ADD
32TTT | LOAD
33NTN | 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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
46NSSVTSSSTSTTN | MARK: 10001011 (get_room_struct_size)
47SSSTSSSSSSSSSSTTN | PUSH 0x1003 (GAME_DATA_BASE+3 = links_per_room address)
48TTT | LOAD
49SSSTSN | PUSH +2
50TSSS | ADD
51NTN | 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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
64NSSVTSSSTTSSN | 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.
68NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
69TSSN | MULTIPLY
70SSSTN | PUSH +1
71TSSS | ADD
72SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address)
73TSSS | ADD
74TTT | LOAD
75NTN | 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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
88NSSVTSSSTTSTN | 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.
92NSTTSSSTSTTN | JSR > 10001011 (get_room_struct_size)
93TSSN | MULTIPLY
94SSSTSSSSSSSSSSSSSN | PUSH 0x2000 (GAME_DATA_BASE address)
95TSSS | ADD
96TTT | LOAD
97NTN | 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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
110NSSVTSTSSSSSN | MARK: 10100000 (room_has_wumpus)
111SSSTSSSSSSSSSTTTN | PUSH 0x1007 (wumpus_location address)
112TTT | LOAD
113TSST | SUBTRACT
114NTSTSTSSSSSSSSSSSSSN | BRZ > 10100000 00000000 (room_has_wumpus:true)
115SSSSN | PUSH 0 (false)
116NTN | RTS
117NSSVTSTSSSSSSSSSSSSSN | MARK: 10100000 00000000 (room_has_wumpus:true)
118SSSTN | PUSH 1 (true)
119NTN | 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>
133NSSVTSSTTTSSN | 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.
137SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
138TTT | LOAD
139SSSTN | PUSH 1
140TSST | SUBTRACT
141
142@ Check one nearby room on each pass through this loop.
143@ TOS> tunnel_index, room_number
144NSSVTSSTTTSSSSSSSSSSN | MARK: 10011100 00000000 (are_bats_near:loop)
145SNS | DUP
146SSSTTN | PUSH 3
147NSTTTSSN | JSR > 1100 (deepdup)
148NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
149NSTTSSSTTSSN | JSR > 10001100 (room_has_bats)
150NTSTSSTTTSSSSSSSSSTN | BRZ > 10011100 00000001 (no_bats_in_this_room)
151@ Found bats. Clean up and return.
152SNN | DROP
153SNN | DROP
154SSSTN | PUSH 1
155NTN | RTS
156NSSVTSSTTTSSSSSSSSSTN | MARK: 10011100 00000001 (no_bats_in_this_room)
157@ Test for end of loop.
158SNS | DUP
159NTSTSSTTTSSSSSSSSTSN | 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.
162SSSTN | PUSH 1
163TSST | SUBTRACT
164NSNTSSTTTSSSSSSSSSSN | JMP > 10011100 00000000 (are_bats_near:loop)
165@ No bats found in nearby rooms. Clean up and return.
166NSSVTSSTTTSSSSSSSSTSN | MARK: 10011100 00000010 (are_bats_near:loop_end)
167SNN | DROP
168SNN | DROP
169SSSSN | PUSH 0
170NTN | 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>
184NSSVTSSTTTSTN | 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.
188SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
189TTT | LOAD
190SSSTN | PUSH 1
191TSST | SUBTRACT
192
193@ Check one nearby room on each pass through this loop.
194@ TOS> tunnel_index, room_number
195NSSVTSSTTTSTSSSSSSSSN | MARK: 10011101 00000000 (are_pits_near:loop)
196SNS | DUP
197SSSTTN | PUSH 3
198NSTTTSSN | JSR > 1100 (deepdup)
199NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
200NSTTSSSTTSTN | JSR > 10001101 (room_has_pits)
201NTSTSSTTTSTSSSSSSSTN | BRZ > 10011101 00000001 (no_pits_in_this_room)
202@ Found pits. Clean up and return.
203SNN | DROP
204SNN | DROP
205SSSTN | PUSH 1
206NTN | RTS
207NSSVTSSTTTSTSSSSSSSTN | MARK: 10011101 00000001 (no_pits_in_this_room)
208@ Test for end of loop.
209SNS | DUP
210NTSTSSTTTSTSSSSSSTSN | 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.
213SSSTN | PUSH 1
214TSST | SUBTRACT
215NSNTSSTTTSTSSSSSSSSN | JMP > 10011101 00000000 (are_pits_near:loop)
216@ No pits found in nearby rooms. Clean up and return.
217NSSVTSSTTTSTSSSSSSTSN | MARK: 10011101 00000010 (are_pits_near:loop_end)
218SNN | DROP
219SNN | DROP
220SSSSN | PUSH 0
221NTN | 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>
235NSSVTSSTTTTTN | 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.
239SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
240TTT | LOAD
241SSSTN | PUSH 1
242TSST | SUBTRACT
243
244@ Check one nearby room on each pass through this loop.
245@ TOS> tunnel_index, room_number
246NSSVTSSTTTTTSSSSSSSSN | MARK: 10011111 00000000 (is_wumpus_very_near:loop)
247SNS | DUP
248SSSTTN | PUSH 3
249NSTTTSSN | JSR > 1100 (deepdup)
250NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
251NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
252NTSTSSTTTTTSSSSSSSTN | BRZ > 10011111 00000001 (no_wumpus_in_this_room)
253@ Found wumpus. Clean up and return.
254SNN | DROP
255SNN | DROP
256SSSTN | PUSH 1
257NTN | RTS
258NSSVTSSTTTTTSSSSSSSTN | MARK: 10011111 00000001 (no_wumpus_in_this_room)
259@ Test for end of loop.
260SNS | DUP
261NTSTSSTTTTTSSSSSSTSN | 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.
264SSSTN | PUSH 1
265TSST | SUBTRACT
266NSNTSSTTTTTSSSSSSSSN | JMP > 10011111 00000000 (is_wumpus_very_near:loop)
267@ No wumpus found in nearby rooms. Clean up and return.
268NSSVTSSTTTTTSSSSSSTSN | MARK: 10011111 00000010 (is_wumpus_very_near:loop_end)
269SNN | DROP
270SNN | DROP
271SSSSN | PUSH 0
272NTN | 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>
286NSSVTSSTTTTSN | 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.
290SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
291TTT | LOAD
292SSSTN | PUSH 1
293TSST | SUBTRACT
294
295@ Check one nearby room and its connecting rooms on each pass through this loop.
296@ TOS> tunnel_index, room_number
297NSSVTSSTTTTSSSSSSSSSN | MARK: 10011110 00000000 (is_wumpus_near:loop)
298SNS | DUP
299SSSTTN | PUSH 3
300NSTTTSSN | JSR > 1100 (deepdup)
301NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
302@ TOS> tunnel_endpoint, tunnel_index, room_number
303SNS | DUP
304NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
305SSSTN | PUSH 1
306TSST | SUBTRACT
307NTSTSSTTTTSSSSSSSTTN | BRZ > 10011110 00000011 (found_wumpus_one_hop)
308NSTTSSTTTTTN | JSR > 10011111 (is_wumpus_very_near)
309SSSTN | PUSH 1
310TSST | SUBTRACT
311NTSTSSTTTTSSSSSSTSSN | BRZ > 10011110 00000100 (found_wumpus_two_hops)
312@ Test for end of loop.
313SNS | DUP
314NTSTSSTTTTSSSSSSSTSN | 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.
317SSSTN | PUSH 1
318TSST | SUBTRACT
319NSNTSSTTTTSSSSSSSSSN | JMP > 10011110 00000000 (is_wumpus_near:loop)
320
321@ No wumpus found in nearby rooms. Clean up and return.
322NSSVTSSTTTTSSSSSSSTSN | MARK: 10011110 00000010 (is_wumpus_near:loop_end)
323SNN | DROP
324SNN | DROP
325SSSSN | PUSH 0
326NTN | RTS
327
328@ Found wumpus. Clean up and return.
329NSSVTSSTTTTSSSSSSSTTN | MARK: 10011110 00000011 (found_wumpus_one_hop)
330SNN | DROP
331NSSVTSSTTTTSSSSSSTSSN | MARK: 10011110 00000100 (found_wumpus_two_hops)
332SNN | DROP
333SNN | DROP
334SSSTN | PUSH 1
335NTN | RTS
336
310931d2
AT
337@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
338@ Name:
339@ seed_rng
340@ Description:
341@ Generate seed from keyboard input.
342@ Call Stack:
343@ <empty>
344@ Return Stack:
345@ <empty>
346@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
347#include <logic.pvvs>
348NSSVTSSSSSTTN | MARK: 10000011 (seed_rng)
349
350SSSTSSSSN | PUSH 16 (loop counter)
351SSSSN | PUSH 0 (rng seed)
352
353NSSVTSSSSSTTSSSSSSSSN | MARK: 10000011 00000000 (seed_rng:main loop)
354@ Get character from user and print ASCII '.' as feedback.
355SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
356TNTS | GETCHAR
357SSSTSTTTSN | PUSH ASCII '.'
358TNSS | PUTCHAR
359@ Left shift the seed by 4 bits.
360SSSTSSN | PUSH 4 (shift count)
361NSTTSTTSTN | JSR > 101101 (lshift)
362@ XOR seed with character from user.
363SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
364TTT | LOAD
365NSTTSTSTTN | JSR > 101011 (xor)
366@ Decrement counter
367SNT | SWAP
368SSSTN | PUSH +1
369TSST | SUBTRACT
370@ Test for loop completion
371SNS | DUP
372NTSTSSSSSTTSSSSSSSTN | BRZ > 10000011 00000001 (seed_rng:cleanup and return)
373SNT | SWAP
374NSNTSSSSSTTSSSSSSSSN | JMP > 10000011 00000000 (seed_rng:main loop)
375
376@ Store seed, clean up and return.
377NSSVTSSSSSTTSSSSSSSTN | MARK: 10000011 00000001 (seed_rng:cleanup and return)
378SNN | DROP
379SSSSN | PUSH 0 (seed address)
380SNT | SWAP
381TTS | STORE
382SSSTSTSN | PUSH ASCII '\n'
383SSSTSTSN | PUSH ASCII '\n'
384TNSS | PUTCHAR
385TNSS | PUTCHAR
386NTN | RTS
387
388@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
389@ Name:
2d81bb77 390@ are_rooms_adjacent
310931d2 391@ Description:
2d81bb77 392@ Checks if 'room_number_1' is adjacent to 'room_number_2'.
310931d2 393@ Call Stack:
2d81bb77
AT
394@ room_number_2
395@ room_number_1 <-- TOS
310931d2
AT
396@ Return Stack:
397@ (1 or 0) for true/false <-- TOS
398@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
399#include <stack.pvvs>
2d81bb77 400NSSVTSTSSTSSN | MARK: 10100100 (are_rooms_adjacent)
310931d2
AT
401
402SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number_of_tunnels_per_room)
403TTT | LOAD
404SSSTN | PUSH +1
405TSST | SUBTRACT
406
2d81bb77
AT
407@ TOS> tunnel_index, room_number_1, room_number_2
408NSSVTSTSSTSSSSSSSSSSN | MARK: 10100100 00000000 (main_loop)
409SSSTTN | PUSH +3
310931d2 410NSTTTSSN | JSR > 1100 (deepdup)
2d81bb77 411SSSTTN | PUSH +3
310931d2 412NSTTTSSN | JSR > 1100 (deepdup)
2d81bb77
AT
413SSSTTN | PUSH +3
414NSTTTSSN | JSR > 1100 (deepdup)
415SNT | SWAP
310931d2
AT
416NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
417TSST | SUBTRACT
2d81bb77 418NTSTSTSSTSSSSSSSSSTN | BRZ > 10100100 00000001 (found_tunnel)
310931d2
AT
419SSSTN | PUSH +1
420TSST | SUBTRACT
421SNS | DUP
2d81bb77
AT
422NTTTSTSSTSSSSSSSSTSN | BMI > 10100100 00000010 (no_match)
423NSNTSTSSTSSSSSSSSSSN | JMP > 10100100 00000000 (main_loop)
310931d2 424
2d81bb77
AT
425NSSVTSTSSTSSSSSSSSSTN | MARK: 10100100 00000001 (found_tunnel)
426SNN | DROP
310931d2
AT
427SNN | DROP
428SNN | DROP
429SSSTN | PUSH +1
430NTN | RTS
431
2d81bb77
AT
432NSSVTSTSSTSSSSSSSSTSN | MARK: 10100100 00000010 (no_match)
433SNN | DROP
310931d2
AT
434SNN | DROP
435SNN | DROP
436SSSSN | PUSH 0
437NTN | RTS
438
439@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
440@ Name:
441@ move_player
442@ Description:
443@ Prompts the player for a room number. Moves to that room, checking the new
444@ environment and executing consequences (fell in a pit, etc) as appropriate.
445@ Call Stack:
446@ <empty>
447@ Return Stack:
448@ <empty>
449@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
450#include <stdio.pvvs>
451#include <convert.pvvs>
452#include <math.pvvs>
453#include <string.pvvs>
454NSSVTSTSSSTTN | MARK: 10100011 (move_player)
455
456A"To which room do you wish to move?\n"
457SSSSN | PUSH 0 (number of string substitutions)
458NSTTSSSN | JSR > 1000 (printf)
459SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer address)
460SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer size)
461NSTTSSSTSN | JSR > 100010 (get_user_string)
462SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
463NSTTTSSSSN | JSR > 110000 (atoi)
464SNN | DROP
465
466@ The desired room number is now on the TOS. Verify that it is valid.
467SNS | DUP
2d81bb77
AT
468SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player_location)
469TTT | LOAD
470NSTTSTSSTSSN | JSR > 10100100 (are_rooms_adjacent)
310931d2
AT
471NTSTSTSSSTTSSSSSSSTN | BRZ > 10100011 00000001 (invalid room number)
472NSNTSTSSSTTSSSSSSSSN | JMP > 10100011 00000000 (valid room number)
473
474NSSVTSTSSSTTSSSSSSSTN | MARK: 10100011 00000001 (invalid room number)
475@ TOS> room_number
476SNN | DROP
477A"*Oof!* (you hit the wall)\n"
478SSSSN | PUSH 0 (number of string substitutions)
479NSTTSSSN | JSR > 1000 (printf)
480NSTTSSTTN | JSR > 10011 (fastrand)
481SSSTTSN | PUSH 6 (chance)
482TSTT | MODULO
483NTSTSTSSSTTSSSSSSTSN | BRZ > 10100011 00000010 (woke the wumpus)
484NTN | RTS
485NSSVTSTSSSTTSSSSSSTSN | MARK: 10100011 00000010 (woke the wumpus)
486A"Your colorful comments awaken the wumpus!\n"
487SSSSN | PUSH 0 (number of string substitutions)
488NSTTSSSN | JSR > 1000 (printf)
489NSTTSSTTN | JSR > 10011 (fastrand)
490SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number of tunnels per room)
491TSTT | MODULO
492SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus location)
493TTT | LOAD
494NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
495SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus location)
496SNT | SWAP
497TTS | STORE
498SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
499TTT | LOAD
500NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
501NTSTSTSSSTTSSSSSSTTN | BRZ > 10100011 00000011 (wumpus did not move to player)
502NSTTTTTTTTTSSSSSSSSN | JSR > 11111111 00000000 (wump_kill)
503SSSSN | PUSH 0 (number of string substitutions)
504NSTTSSSN | JSR > 1000 (printf)
505NNN | DIE
506NSSVTSTSSSTTSSSSSSTTN | MARK: 10100011 00000011 (wumpus did not move to player)
507NTN | RTS
508
509NSSVTSTSSSTTSSSSSSSSN | MARK: 10100011 00000000 (valid room number)
510@ TOS> room_number
511@ Move player to new room
512SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
513SNT | SWAP
514TTS | STORE
515@ Check for wumpus in new player location
516SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
517TTT | LOAD
518NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
519NTSTSTSSSTTSSSSSTSSN | BRZ > 10100011 00000100 (no wumpus in new room)
520NSTTTTTTTTTSSSSSSSSN | JSR > 11111111 00000000 (wump_kill)
521SSSSN | PUSH 0 (number of string substitutions)
522NSTTSSSN | JSR > 1000 (printf)
523NNN | DIE
524NSSVTSTSSSTTSSSSSTSSN | MARK: 10100011 00000100 (no wumpus in new room)
525@ Check for pits in new player location
526SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
527TTT | LOAD
528NSTTSSSTTSTN | JSR > 10001101 (room_has_pits)
529NTSTSTSSSTTSSSSSTSTN | BRZ > 10100011 00000101 (no pits in new room)
530NSTTSSTTN | JSR > 10011 (fastrand)
531SSSTTSN | PUSH 6 (chance)
532TSTT | MODULO
533NTSTSTSSSTTSSSSSTTSN | BRZ > 10100011 00000110 (survived the pits)
534NSTTTTTTTTTSSSSSTSTN | JSR > 11111111 00000101 (pit_kill)
535SSSSN | PUSH 0 (number of string substitutions)
536NSTTSSSN | JSR > 1000 (printf)
537NNN | DIE
538NSSVTSTSSSTTSSSSSTTSN | MARK: 10100011 00000110 (survived the pits)
539NSTTTTTTTTTSSSSSTTSN | JSR > 11111111 00000110 (pit_survive)
540SSSSN | PUSH 0 (number of string substitutions)
541NSTTSSSN | JSR > 1000 (printf)
542NSSVTSTSSSTTSSSSSTSTN | MARK: 10100011 00000101 (no pits in new room)
543@ Check for bats in new player location
544SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
545TTT | LOAD
546NSTTSSSTTSSN | JSR > 10001100 (room_has_bats)
547NTSTSTSSSTTSSSSSTTSN | BRZ > 10100011 00000110 (no bats in new room)
548A"*flap* *flap* *flap* (humongous bats pick you up and move you!)\n"
549SSSSN | PUSH 0 (number of string substitutions)
550NSTTSSSN | JSR > 1000 (printf)
551NSTTSSTTN | JSR > 10011 (fastrand)
552SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number of tunnels per room)
553TSTT | MODULO
554SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location)
555TTT | LOAD
556NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
557NSNTSTSSSTTSSSSSSSSN | JMP > 10100011 00000000 (valid room number)
558NSSVTSTSSSTTSSSSSTTSN | MARK: 10100011 00000110 (no bats in new room)
559NTN | RTS
560
2d81bb77
AT
561@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
562@ Name:
563@ shoot_arrow
564@ Description:
565@ Prompt user for list of rooms. Shoots an arrow through each room, checking
566@ the new environment and executing consequences (fell in a pit, etc) as
567@ appropriate.
568@ Call Stack:
569@ <empty>
570@ Return Stack:
571@ <empty>
572@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
573#include <string.pvvs>
574#include <stack.pvvs>
575#include <stdio.pvvs>
576#include <math.pvvs>
577#include <wump_strings.pvvs>
578NSSVTSSTTSSTN | MARK: 10011001 (shoot_arrow)
579
580A"Through which rooms do you wish to shoot your arrow?\n(type %u room numbers separated by spaces)\n"
581SSSTSSSSSSSSSTSSN | PUSH 0x1004 (ptr to max_arrow_flight_distance)
582TTT | LOAD
583SSSTN | PUSH 1 (number of string substitutions)
584NSTTSSSN | JSR > 1000 (printf)
585SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer address)
586SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer size)
587NSTTSSSTSN | JSR > 100010 (get_user_string)
588
589@ Loop, converting one room number from the user string per pass.
590@ But first, prepare the stack for the loop.
591SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
592SSSTSSSSSSSSSTSSN | PUSH 0x1004 (ptr to max_arrow_flight_distance)
593TTT | LOAD
594@ TOS> loop_counter, ptr_to_user_string
595NSSVTSSTTSSTSSSSSSSSN | MARK: 10011001 00000000 (process_room_loop)
596@ Test for end of loop (counter == 0)
597SNS | DUP
598NTSTSSTTSSTSSSSSSSTN | BRZ > 10011001 00000001 (end of process_room_loop)
599@ Now jump forward in the user string to the next ASCII digit (or null term).
600SNT | SWAP
601NSSVTSSTTSSTSSSSSSTSN | MARK: 10011001 00000010 (next_ascii_digit_loop)
602SNS | DUP
603TTT | LOAD
604SNS | DUP
605NSTTSSSSTN | JSR > 100001 (isdigit)
606NTSTSSTTSSTSSSSSSTTN | BRZ > 10011001 00000011 (ascii_term_test)
607SNN | DROP
608NSNTSSTTSSTSSSSSTSSN | JMP > 10011001 00000100 (next_ascii_digit_loop_end)
609NSSVTSSTTSSTSSSSSSTTN | MARK: 10011001 00000011 (ascii_term_test)
610NTSTSSTTSSTSSSSSTSSN | BRZ > 10011001 00000100 (next_ascii_digit_loop_end)
611SSSTN | PUSH 1
612TSSS | ADD
613NSNTSSTTSSTSSSSSSTSN | JMP > 10011001 00000010 (next_ascii_digit_loop)
614NSSVTSSTTSSTSSSSSTSSN | MARK: 10011001 00000100 (next_ascii_digit_loop_end)
615@ Call atoi with the newly updated pointer to process another room number.
616NSTTTSSSSN | JSR > 110000 (atoi)
617SNT | SWAP
618SSSTTN | PUSH 3 (rotation_depth)
619NSTTSTSN | JSR > 1010 (stackrotate)
620@ Decrement the loop counter and loop again.
621SNT | SWAP
622SSSTN | PUSH 1
623TSST | SUBTRACT
624NSNTSSTTSSTSSSSSSSSN | JMP > 10011001 00000000 (process_room_loop)
625@ Loop is complete. Moving on.
626NSSVTSSTTSSTSSSSSSSTN | MARK: 10011001 00000001 (end of process_room_loop)
627SNN | DROP
628SNN | DROP
629
630@ Stack now contains only integers for room numbers (zero padded to full count).
631@ They are in reverse order, so reverse again.
632@ Temporarily use the USER_INPUT_BUFFER as a loop counter.
633SSSTTSSSSSSSSSSSSN | PUSH 0x3000
634SSSTSSSSSSSSSTSSN | PUSH 0x1004 (ptr to max_arrow_flight_distance)
635TTT | LOAD
636TTS | STORE
637@ Now perform the reversal.
638NSSVTSSTTSSTSSSSSTSTN | MARK: 10011001 00000101 (reverse_loop)
639@ First shift the TOS element back to its final location.
640SSSTTSSSSSSSSSSSSN | PUSH 0x3000
641TTT | LOAD
642NSTTSTSN | JSR > 1010 (stackrotate)
643@ Now decrement the loop counter.
644SSSTTSSSSSSSSSSSSN | PUSH 0x3000
645TTT | LOAD
646SSSTN | PUSH 1
647TSST | SUBTRACT
648@ And check for the end of loop condition (counter < 2)
649SNS | DUP
650SSSTN | PUSH 1
651TSST | SUBTRACT
652NTSTSSTTSSTSSSSSTTSN | BRZ > 10011001 00000110 (reverse_loop_end)
653@ The loop continues. Store the new loop counter and go around again.
654SSSTTSSSSSSSSSSSSN | PUSH 0x3000
655SNT | SWAP
656TTS | STORE
657NSNTSSTTSSTSSSSSTSTN | JMP > 10011001 00000101 (reverse_loop)
658@ End of loop. Clean up and continue.
659NSSVTSSTTSSTSSSSSTTSN | MARK: 10011001 00000110 (reverse_loop_end)
660SNN | DROP
661
662@@@@@ Initialization complete. @@@@@
663
664@ Stack now contains a list room numbers as integers, in order.
665
666@ Put a loop index and the starting location of the arrow on the stack.
667SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player_location, now arrow_location)
668TTT | LOAD
669SSSTSSSSSSSSSTSSN | PUSH 0x1004 (ptr to max_arrow_flight_distance)
670TTT | LOAD
671
672@ TOS> loop_index, arrow_location, list_of_room_numbers ...
673@ Move the arrow through a new room for each pass of the loop.
674NSSVTSSTTSSTSSSSSTTTN | MARK: 10011001 00000111 (arrow_loop)
675@ Check loop index for end of loop condition (index==0).
676SNS | DUP
677NTSTSSTTSSTSSSSTTSTN | BRZ > 10011001 00001101 (loop_end)
678@ Is the requested room number connected to the arrows current room?
679SNT | SWAP
680SNS | DUP
681SSSTSSN | PUSH 4
682NSTTTSSN | JSR > 1100 (deepdup)
683NSTTSTSSTSSN | JSR > 10100100 (are_rooms_adjacent)
684NTSTSSTTSSTSSSSTSSSN | BRZ > 10011001 00001000 (not_adjacent)
685@ Room was adjacent. Print update for user, clean up stack and jump ahead.
686SSSTTSSSSSSSSSSSSN | PUSH 0x3000
687SNT | SWAP
688TTS | STORE
689SNT | SWAP
690SSSTTSSSSSSSSSSSTN | PUSH 0x3001
691SNT | SWAP
692TTS | STORE
693A"The arrow sails out of room %u and enters room %u.\n"
694SSSTTSSSSSSSSSSSTN | PUSH 0x3001
695TTT | LOAD
696SSSTTSSSSSSSSSSSSN | PUSH 0x3000
697TTT | LOAD
698SSSTSN | PUSH 2
699NSTTSSSN | JSR > 1000 (printf)
700SSSTTSSSSSSSSSSSTN | PUSH 0x3001
701TTT | LOAD
702SNT | SWAP
703SSSTTSSSSSSSSSSSSN | PUSH 0x3000
704TTT | LOAD
705SNT | SWAP
706NSNTSSTTSSTSSSSTSSTN | JMP > 10011001 00001001 (room_is_valid)
707@ Room was not adjacent. Select a random adjacent room for the arrow.
708NSSVTSSTTSSTSSSSTSSSN | MARK: 10011001 00001000 (not_adjacent)
709SSSTTN | PUSH 3
710NSTTSTTN | JSR > 1011 (stackrotatereverse)
711@ TOS> (invalid) room_number, arrow_location, loop_index, rest_of_room_numbers ...
712@ Start a message to the user.
713@ First, store two values we will need when printing the user message.
714SSSTTSSSSSSSSSSSSN | PUSH 0x3000
715SNT | SWAP
716TTS | STORE
717SSSTTSSSSSSSSSSSTN | PUSH 0x3001
718SNT | SWAP
719TTS | STORE
720A"*thunk* The arrow can't find a way from room %u to room %u "
721SSSTTSSSSSSSSSSSSN | PUSH 0x3000
722TTT | LOAD
723SSSTTSSSSSSSSSSSTN | PUSH 0x3001
724TTT | LOAD
725SSSTSN | PUSH 2
726NSTTSSSN | JSR > 1000 (printf)
727@ Now locate a random, connected room for the arrow to visit.
728NSTTSSSSN | JSR > 10000 (random)
729SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number_of_tunnels_per_room)
730TTT | LOAD
731TSTT | MODULO
732SSSTTSSSSSSSSSSSTN | PUSH 0x3001
733TTT | LOAD
734NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
735@ Now finish the message to the user.
736SSSTTSSSSSSSSSSSSN | PUSH 0x3000
737SNT | SWAP
738TTS | STORE
739A"and flys randomly into room %u!\n"
740SSSTTSSSSSSSSSSSSN | PUSH 0x3000
741TTT | LOAD
742SSSTN | PUSH 1
743NSTTSSSN | JSR > 1000 (printf)
744@ And cleanup the stack before continuing onward.
745SSSTTSSSSSSSSSSSSN | PUSH 0x3000
746TTT | LOAD
747SNT | SWAP
748SSSTTSSSSSSSSSSSTN | PUSH 0x3001
749TTT | LOAD
750SNT | SWAP
751
752NSSVTSSTTSSTSSSSTSSTN | MARK: 10011001 00001001 (room_is_valid)
753@ TOS> loop_index, arrow_location, list_of_room_numbers ...
754SSSTTN | PUSH 3
755NSTTSTSN | JSR > 1010 (stackrotate)
756SNN | DROP
757@ TOS> (new) arrow_location, loop_index, (smaller) list_of_room_numbers ...
758@ Does new room contain a wumpus?
759SNS | DUP
760NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus)
761NTSTSSTTSSTSSSSTSTSN | BRZ > 10011001 00001010 (no_wumpus_here)
762@ Player slew the wumpus!
763NSTTTTTTTTTSSSSSSSTN | JSR > 11111111 00000001 (kill_wump)
764SSSSN | PUSH 0
765NSTTSSSN | JSR > 1000 (printf)
766NNN | DIE
767@ No wumpus here. Does the new room contain the player?
768NSSVTSSTTSSTSSSSTSTSN | MARK: 10011001 00001010 (no_wumpus_here)
769SNS | DUP
770SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player_location)
771TTT | LOAD
772TSST | SUBTRACT
773NTSTSSTTSSTSSSSTSTTN | BRZ > 10011001 00001011 (player_shot_self)
774NSNTSSTTSSTSSSSTTSSN | JMP > 10011001 00001100 (no_events_in_room)
775NSSVTSSTTSSTSSSSTSTTN | MARK: 10011001 00001011 (player_shot_self)
776@ Player hit by own arrow!
777NSTTTTTTTTTSSSSSSTTN | JSR > 11111111 00000011 (shoot_self)
778SSSSN | PUSH 0
779NSTTSSSN | JSR > 1000 (printf)
780NNN | DIE
781@ No player here. Update loop index, cleanup stack and loop again.
782NSSVTSSTTSSTSSSSTTSSN | MARK: 10011001 00001100 (no_events_in_room)
783SNT | SWAP
784SSSTN | PUSH 1
785TSST | SUBTRACT
786NSNTSSTTSSTSSSSSTTTN | JMP > 10011001 00000111 (arrow_loop)
787NSSVTSSTTSSTSSSSTTSTN | MARK: 10011001 00001101 (loop_end)
788SNN | DROP
789SNN | DROP
790A"The arrows wavers in its flight and can go no further!\n"
791SSSSN | PUSH 0
792NSTTSSSN | JSR > 1000 (printf)
793
794@ Since the player did not kill the wumpus, there is a chance it will wake and move.
795NSTTSSSSN | JSR > 10000 (random)
796SSSTTSN | PUSH 6
797TSTT | MODULO
798NTSTSSTTSSTSSSSTTTSN | BRZ > 10011001 00001110 (move_wumpus)
799NSNTSSTTSSTSSSTSSSSN | JMP > 10011001 00010000 (wumpus_continues_to_slumber)
800NSSVTSSTTSSTSSSSTTTSN | MARK: 10011001 00001110 (move_wumpus)
801@ Move the wumpus to a random connected room.
802NSTTSSSSN | JSR > 10000 (random)
803SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number_of_tunnels_per_room)
804TTT | LOAD
805TSTT | MODULO
806SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus_location)
807TTT | LOAD
808NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
809SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus_location)
810SNT | SWAP
811TTS | STORE
812@ Did the wumpus enter the player room?
813SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus_location)
814TTT | LOAD
815SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player_location)
816TTT | LOAD
817TSST | SUBTRACT
818NTSTSSTTSSTSSSSTTTTN | BRZ > 10011001 00001111 (player_death)
819NSNTSSTTSSTSSSTSSSSN | JMP > 10011001 00010000 (wumpus_continues_to_slumber)
820NSSVTSSTTSSTSSSSTTTTN | MARK: 10011001 00001111 (player_death)
821NSTTTTTTTTTSSSSSSSSN | JSR > 11111111 00000000 (wump_kill)
822SSSSN | PUSH 0
823NSTTSSSN | JSR > 1000 (printf)
824NNN | DIE
825
826NSSVTSSTTSSTSSSTSSSSN | MARK: 10011001 00010000 (wumpus_continues_to_slumber)
827@ Decrement the number of arrows.
828SSSTSSSSSSSSSTSTN | PUSH 0x1005 (ptr to number_of_arrows)
829TTT | LOAD
830SSSTN | PUSH 1
831TSST | SUBTRACT
832SNS | DUP
833SSSTSSSSSSSSSTSTN | PUSH 0x1005 (ptr to number_of_arrows)
834SNT | SWAP
835TTS | STORE
836@ Check for empty quiver.
837NTSTSSTTSSTSSSTSSSTN | BRZ > 10011001 00010001 (empty_quiver)
838NTN | RTS
839NSSVTSSTTSSTSSSTSSSTN | MARK: 10011001 00010001 (empty_quiver)
840NSTTTTTTTTTSSSSSSTSN | JSR > 11111111 00000010 (no_arrows)
841SSSSN | PUSH 0
842NSTTSSSN | JSR > 1000 (printf)
843NNN | DIE
844
310931d2
AT
845@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
846@ Name:
847@ move_or_shoot
848@ Description:
849@ Parse user input, branching to the appropriate subroutine to move or shoot.
850@ This function does not perform any boundary checks/limits.
851@ Call Stack:
852@ <empty>
853@ Return Stack:
854@ <empty>
855@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
856#include <stdio.pvvs>
857#include <string.pvvs>
858NSSVTSTSSSTSN | MARK: 10100010 (move_or_shoot)
859
860SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer address)
861SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer size)
862NSTTSSSTSN | JSR > 100010 (get_user_string)
863
864@ Examine the first character of the user input buffer for 'm' or 's'.
865@ If character is something else, prompt user to try again.
866SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
867TTT | LOAD
868SSSSTTSTTSTN | PUSH 109 (ASCII 'm')
869TSST | SUBTRACT
870NTSTSTSSSTSSSSSSSSSN | BRZ > 10100010 00000000 (move)
871SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
872TTT | LOAD
873SSSSTTTSSTTN | PUSH 115 (ASCII 's')
874TSST | SUBTRACT
875NTSTSTSSSTSSSSSSSSTN | BRZ > 10100010 00000001 (shoot)
876NSTTTTTTTTTSSSSTSSSN | JSR > 11111111 00001000 (problem_with_input)
877SSSSN | PUSH 0 (number of string substitutions)
878NSTTSSSN | JSR > 1000 (printf)
879NSNTSTSSSTSN | JMP > 10100010 (move_or_shoot)
880
881@ User typed 'm'
882NSSVTSTSSSTSSSSSSSSSN | MARK: 10100010 00000000 (move)
883NSTTSTSSSTTN | JSR > 10100011 (move_player)
884NTN | RTS
885
886@ User typed 's'
887NSSVTSTSSSTSSSSSSSSTN | MARK: 10100010 00000001 (shoot)
2d81bb77 888NSTTSSTTSSTN | JSR > 10011001 (shoot_arrow)
310931d2
AT
889NTN | RTS
890
891@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
892@ Name:
893@ get_answer
894@ Description:
895@ Parse user input, returning 0 if user string started with 'n' or 1 if 'y'.
896@ This function does not perform any boundary checks/limits.
897@ Call Stack:
898@ <empty>
899@ Return Stack:
900@ (1 or 0 for True/False) <--- TOS
901@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
902#include <stdio.pvvs>
903#include <string.pvvs>
904NSSVTSSTTSSSN | MARK: 10011000 (get_answer)
905
906@ TODO: Consider extending the GETCHAR instruction in VVS to indicate an empty
907@ buffer instead of blocking. This would allow a character by character
908@ check without printing a slew of retry messages if the buffer is
909@ non-empty.
910SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer address)
911SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (buffer size)
912NSTTSSSTSN | JSR > 100010 (get_user_string)
913
914@ Examine the first character of the user input buffer for 'y' or 'n'.
915@ If character is something else, prompt user to try again.
916SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
917TTT | LOAD
918SSSSTTTTSSTN | PUSH 121 (ASCII 'y')
919TSST | SUBTRACT
920NTSTSSTTSSSSSSSSSSSN | BRZ > 10011000 00000000 (answer: yes)
921SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
922TTT | LOAD
923SSSSTTSTTTSN | PUSH 110 (ASCII 'n')
924TSST | SUBTRACT
925NTSTSSTTSSSSSSSSSSTN | BRZ > 10011000 00000001 (answer: no)
926NSTTTTTTTTTSSSSTSSSN | JSR > 11111111 00001000 (problem_with_input)
927SSSSN | PUSH 0 (number of string substitutions)
928NSTTSSSN | JSR > 1000 (printf)
929NSNTSSTTSSSN | JMP > 10011000 (get_answer)
930
931@ User typed 'y'
932NSSVTSSTTSSSSSSSSSSSN | MARK: 10011000 00000000 (answer: yes)
933SSSTN | PUSH 1
934NTN | RTS
935
936@ User typed 'n'
937NSSVTSSTTSSSSSSSSSSTN | MARK: 10011000 00000001 (answer: no)
938SSSSN | PUSH 0
939NTN | RTS
940
941@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
942@ Name:
943@ print_cave_description
944@ Description:
945@ Prints information about the cave (number of rooms, etc).
946@ Call Stack:
947@ <empty>
948@ Return Stack:
949@ <empty>
950@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
951#include <stdio.pvvs>
952NSSVTSSTTSTTN | MARK: 10011011 (print_cave_description)
953NSTTTTTTTTTSSSSTSTSN | JSR > 11111111 00001010 (cave_description)
954SSSTSSSSSSSSSTSTN | PUSH 0x1005 (number_of_arrows address)
955TTT | LOAD
956SSSTSSSSSSSSSSSTN | PUSH 0x1001 (number_of_pits address)
957TTT | LOAD
958SSSTSSSSSSSSSSTSN | PUSH 0x1002 (number_of_bats address)
959TTT | LOAD
960SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_tunnels address)
961TTT | LOAD
962SSSTSSSSSSSSSSSSN | PUSH 0x1000 (number_of_rooms address)
963TTT | LOAD
964SSSTSTN | PUSH 5 (number of substitions)
965NSTTSSSN | JSR > 1000 (printf)
966NTN | RTS
967
968@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
969@ Name:
970@ print_room_stats
971@ Description:
972@ Prints information about current room and hints about nearby rooms.
973@ Call Stack:
974@ <empty>
975@ Return Stack:
976@ <empty>
977@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
978#include <wump_game.pvvs>
979#include <stdio.pvvs>
980#include <stack.pvvs>
981NSSVTSTSSSSTN | MARK: 10100001 (print_room_stats)
982
983@ Print location and arrow quantity remaining.
2d81bb77 984A"\n----------\n\nYou are in room %u of the cave and have %u arrows remaining.\n"
310931d2
AT
985SSSTSSSSSSSSSTSTN | PUSH 0x1005 (number_of_arrows address)
986TTT | LOAD
987SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
988TTT | LOAD
989SSSTSN | PUSH 2 (number of substitutions)
990NSTTSSSN | JSR > 1000 (printf)
991
992@ Print if bats/pits/wumpus nearby.
993SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
994TTT | LOAD
995SNS | DUP
996NSTTSSTTTSSN | JSR > 10011100 (are_bats_near)
997NTSTSTSSSSTSSSSSSSSN | BRZ > 10100001 00000000 (no_bats)
998A"*rustle* (Bats must be nearby.)\n"
999SSSSN | PUSH 0 (number of substitutions)
1000NSTTSSSN | JSR > 1000 (printf)
1001NSSVTSTSSSSTSSSSSSSSN | MARK: 10100001 00000000 (no_bats)
1002SNS | DUP
1003NSTTSSTTTSTN | JSR > 10011101 (are_pits_near)
1004NTSTSTSSSSTSSSSSSSTN | BRZ > 10100001 00000001 (no_pits)
1005A"*whoosh* (You feel a draft from nearby pits.)\n"
1006SSSSN | PUSH 0 (number of substitutions)
1007NSTTSSSN | JSR > 1000 (printf)
1008NSSVTSTSSSSTSSSSSSSTN | MARK: 10100001 00000001 (no_pits)
1009NSTTSSTTTTSN | JSR > 10011110 (is_wumpus_near)
1010NTSTSTSSSSTSSSSSSTSN | BRZ > 10100001 00000010 (no_wumpus)
1011A"*sniff* (You smell the evil Wumpus nearby!)\n"
1012SSSSN | PUSH 0 (number of substitutions)
1013NSTTSSSN | JSR > 1000 (printf)
1014NSSVTSTSSSSTSSSSSSTSN | MARK: 10100001 00000010 (no_wumpus)
1015
1016@ Print a list of nearby rooms.
1017A"This room contains tunnels to the following rooms:"
1018SSSSN | PUSH 0 (number of substitutions)
1019NSTTSSSN | JSR > 1000 (printf)
1020SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
1021TTT | LOAD
1022SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
1023TTT | LOAD
1024SSSTN | PUSH 1
1025TSST | SUBTRACT
1026@ Print one room on each pass through this loop.
1027@ TOS> tunnel_index, room_number
1028NSSVTSTSSSSTSSSSSSTTN | MARK: 10100001 00000011 (print_room_list_loop)
1029A" %u"
1030SSSTSTN | PUSH 5
1031NSTTTSSN | JSR > 1100 (deepdup)
1032SSSTTTN | PUSH 7
1033NSTTTSSN | JSR > 1100 (deepdup)
1034NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
1035SSSTN | PUSH 1 (number of substitutions)
1036NSTTSSSN | JSR > 1000 (printf)
1037@ Test for end of loop
1038SNS | DUP
1039NTSTSTSSSSTSSSSSTSSN | BRZ > 10100001 00000100 (print_room_list_loop_end)
1040SSSTN | PUSH 1
1041TSST | SUBTRACT
1042NSNTSTSSSSTSSSSSSTTN | JMP > 10100001 00000011 (print_room_list_loop)
1043@ Clean up and return.
1044NSSVTSTSSSSTSSSSSTSSN | MARK: 10100001 00000100 (print_room_list_loop_end)
1045SSSTSTSN | PUSH 10 (ASCII '\n')
1046TNSS | PUTCHAR
1047SNN | DROP
1048SNN | DROP
1049NTN | RTS
1050
2da74194 1051#endif