Added move_or_shoot function to Wumpus example.
[vvhitespace] / examples / wump / wump_ui.pvvs
CommitLineData
2da74194
AT
1#ifndef WUMP_UI
2#define WUMP_UI
3
4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
5@ This files contains user interface functions for Hunt the Wumpus.
6@ (c) 2019 Aaron Taylor <ataylor at subgeniuskitty dot com>
7@ See LICENSE.txt file for copyright and license details.
8@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
9
10@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
11@ Name:
12@ seed_rng
13@ Description:
14@ Generate seed from keyboard input.
15@ Call Stack:
16@ <empty>
17@ Return Stack:
18@ <empty>
19@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
20#include <logic.pvvs>
21NSSVTSSSSSTTN | MARK: 10000011 (seed_rng)
22
23SSSTSSSSN | PUSH 16 (loop counter)
24SSSSN | PUSH 0 (rng seed)
25
26NSSVTSSSSSTTSSSSSSSSN | MARK: 10000011 00000000 (seed_rng:main loop)
27@ Get character from user and print ASCII '.' as feedback.
28SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
29TNTS | GETCHAR
30SSSTSTTTSN | PUSH ASCII '.'
31TNSS | PUTCHAR
32@ Left shift the seed by 4 bits.
33SSSTSSN | PUSH 4 (shift count)
34NSTTSTTSTN | JSR > 101101 (lshift)
35@ XOR seed with character from user.
36SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
37TTT | LOAD
38NSTTSTSTTN | JSR > 101011 (xor)
39@ Decrement counter
40SNT | SWAP
41SSSTN | PUSH +1
42TSST | SUBTRACT
43@ Test for loop completion
44SNS | DUP
45NTSTSSSSSTTSSSSSSSTN | BRZ > 10000011 00000001 (seed_rng:cleanup and return)
46SNT | SWAP
47NSNTSSSSSTTSSSSSSSSN | JMP > 10000011 00000000 (seed_rng:main loop)
48
49@ Store seed, clean up and return.
50NSSVTSSSSSTTSSSSSSSTN | MARK: 10000011 00000001 (seed_rng:cleanup and return)
51SNN | DROP
52SSSSN | PUSH 0 (seed address)
53SNT | SWAP
54TTS | STORE
55SSSTSTSN | PUSH ASCII '\n'
56SSSTSTSN | PUSH ASCII '\n'
57TNSS | PUTCHAR
58TNSS | PUTCHAR
59NTN | RTS
60
f0e3023d
AT
61@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
62@ Name:
63@ move_or_shoot
64@ Description:
65@ Parse user input, branching to the appropriate subroutine to move or shoot.
66@ This function does not perform any boundary checks/limits.
67@ Call Stack:
68@ <empty>
69@ Return Stack:
70@ <empty>
71@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
72#include <stdio.pvvs>
73NSSVTSTSSSTSN | MARK: 10100010 (move_or_shoot)
74
75NSTTSSTTSSTN | JSR > 10011001 (get_line)
76
77@ Examine the first character of the user input buffer for 'm' or 's'.
78@ If character is something else, prompt user to try again.
79SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
80TTT | LOAD
81SSSSTTSTTSTN | PUSH 109 (ASCII 'm')
82TSST | SUBTRACT
83NTSTSTSSSTSSSSSSSSSN | BRZ > 10100010 00000000 (move)
84SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
85TTT | LOAD
86SSSSTTTSSTTN | PUSH 115 (ASCII 's')
87TSST | SUBTRACT
88NTSTSTSSSTSSSSSSSSTN | BRZ > 10100010 00000001 (shoot)
89NSTTTTTTTTTSSSSTSSSN | JSR > 11111111 00001000 (problem_with_input)
90SSSSN | PUSH 0 (number of string substitutions)
91NSTTSSSN | JSR > 1000 (printf)
92NSNTSTSSSTSN | JMP > 10100010 (move_or_shoot)
93
94@ User typed 'm'
95NSSVTSTSSSTSSSSSSSSSN | MARK: 10100010 00000000 (move)
96@ TODO: JSR move
97NTN | RTS
98
99@ User typed 's'
100NSSVTSTSSSTSSSSSSSSTN | MARK: 10100010 00000001 (shoot)
101@ TODO: JSR shoot
102NTN | RTS
103
2da74194
AT
104@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
105@ Name:
106@ get_answer
107@ Description:
108@ Parse user input, returning 0 if user string started with 'n' or 1 if 'y'.
109@ This function does not perform any boundary checks/limits.
110@ Call Stack:
111@ <empty>
112@ Return Stack:
113@ (1 or 0 for True/False) <--- TOS
114@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
115#include <stdio.pvvs>
116NSSVTSSTTSSSN | MARK: 10011000 (get_answer)
117
118@ TODO: Consider extending the GETCHAR instruction in VVS to indicate an empty
119@ buffer instead of blocking. This would allow a character by character
120@ check without printing a slew of retry messages if the buffer is
121@ non-empty.
122NSTTSSTTSSTN | JSR > 10011001 (get_line)
123
124@ Examine the first character of the user input buffer for 'y' or 'n'.
125@ If character is something else, prompt user to try again.
126SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
127TTT | LOAD
128SSSSTTTTSSTN | PUSH 121 (ASCII 'y')
129TSST | SUBTRACT
130NTSTSSTTSSSSSSSSSSSN | BRZ > 10011000 00000000 (answer: yes)
131SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
132TTT | LOAD
133SSSSTTSTTTSN | PUSH 110 (ASCII 'n')
134TSST | SUBTRACT
135NTSTSSTTSSSSSSSSSSTN | BRZ > 10011000 00000001 (answer: no)
f0e3023d 136NSTTTTTTTTTSSSSTSSSN | JSR > 11111111 00001000 (problem_with_input)
2da74194
AT
137SSSSN | PUSH 0 (number of string substitutions)
138NSTTSSSN | JSR > 1000 (printf)
139NSNTSSTTSSSN | JMP > 10011000 (get_answer)
140
141@ User typed 'y'
142NSSVTSSTTSSSSSSSSSSSN | MARK: 10011000 00000000 (answer: yes)
143SSSTN | PUSH 1
144NTN | RTS
145
146@ User typed 'n'
147NSSVTSSTTSSSSSSSSSSTN | MARK: 10011000 00000001 (answer: no)
148SSSSN | PUSH 0
149NTN | RTS
150
151@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
152@ Name:
153@ get_line
154@ Description:
155@ Read one line of user input and store in buffer.
156@ Appends null terminator to end of string.
157@ This function does not perform any boundary checks/limits.
158@ Call Stack:
159@ <empty>
160@ Return Stack:
161@ <empty>
162@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
163NSSVTSSTTSSTN | MARK: 10011001 (get_line)
164
165@ Get one character from user on each pass through this loop.
166@ Terminate loop when line break character is received.
167SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address)
168NSSVTSSTTSSTSSSSSSSSN | MARK: 10011001 00000000 (input loop)
169SNS | DUP
170SNS | DUP
171TNTS | GETCHAR
172TTT | LOAD
173SNS | DUP
174TNSS | PUTCHAR
175SSSTSTSN | PUSH 10 (ASCII '\n')
176TSST | SUBTRACT
177NTSTSSTTSSTSSSSSSSTN | BRZ > 10011001 00000001 (input loop:terminate)
178@ Character was not ENTER. Increment buffer pointer and loop again.
179SSSTN | PUSH 1
180TSSS | ADD
181NSNTSSTTSSTSSSSSSSSN | JMP > 10011001 00000000 (input loop)
182@ Character was ENTER. Overwrite the line feed with a null term and return.
183NSSVTSSTTSSTSSSSSSSTN | MARK: 10011001 00000001 (input loop:terminate)
184SSSSN | PUSH 0 (ASCII '\0')
185TTS | STORE
186NTN | RTS
187
188@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
189@ Name:
190@ print_cave_description
191@ Description:
192@ Prints information about the cave (number of rooms, etc).
193@ Call Stack:
194@ <empty>
195@ Return Stack:
196@ <empty>
197@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
198#include <stdio.pvvs>
199NSSVTSSTTSTTN | MARK: 10011011 (print_cave_description)
200NSTTTTTTTTTSSSSTSTSN | JSR > 11111111 00001010 (cave_description)
201SSSTSSSSSSSSSTSTN | PUSH 0x1005 (number_of_arrows address)
202TTT | LOAD
203SSSTSSSSSSSSSSSTN | PUSH 0x1001 (number_of_pits address)
204TTT | LOAD
205SSSTSSSSSSSSSSTSN | PUSH 0x1002 (number_of_bats address)
206TTT | LOAD
207SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_tunnels address)
208TTT | LOAD
209SSSTSSSSSSSSSSSSN | PUSH 0x1000 (number_of_rooms address)
210TTT | LOAD
211SSSTSTN | PUSH 5 (number of substitions)
212NSTTSSSN | JSR > 1000 (printf)
213NTN | RTS
214
215@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
216@ Name:
217@ print_room_stats
218@ Description:
219@ Prints information about current room and hints about nearby rooms.
220@ Call Stack:
221@ <empty>
222@ Return Stack:
223@ <empty>
224@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
225#include <wump_game.pvvs>
226#include <stdio.pvvs>
227#include <stack.pvvs>
228NSSVTSTSSSSTN | MARK: 10100001 (print_room_stats)
229
230@ Print location and arrow quantity remaining.
231A"You are in room %u of the cave and have %u arrows remaining.\n"
232SSSTSSSSSSSSSTSTN | PUSH 0x1005 (number_of_arrows address)
233TTT | LOAD
234SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
235TTT | LOAD
236SSSTSN | PUSH 2 (number of substitutions)
237NSTTSSSN | JSR > 1000 (printf)
238
239@ Print if bats/pits/wumpus nearby.
240SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
241TTT | LOAD
242SNS | DUP
243NSTTSSTTTSSN | JSR > 10011100 (are_bats_near)
244NTSTSTSSSSTSSSSSSSSN | BRZ > 10100001 00000000 (no_bats)
245A"*rustle* (Bats must be nearby.)\n"
246SSSSN | PUSH 0 (number of substitutions)
247NSTTSSSN | JSR > 1000 (printf)
248NSSVTSTSSSSTSSSSSSSSN | MARK: 10100001 00000000 (no_bats)
249SNS | DUP
250NSTTSSTTTSTN | JSR > 10011101 (are_pits_near)
251NTSTSTSSSSTSSSSSSSTN | BRZ > 10100001 00000001 (no_pits)
252A"*whoosh* (You feel a draft from nearby pits.)\n"
253SSSSN | PUSH 0 (number of substitutions)
254NSTTSSSN | JSR > 1000 (printf)
255NSSVTSTSSSSTSSSSSSSTN | MARK: 10100001 00000001 (no_pits)
256NSTTSSTTTTSN | JSR > 10011110 (is_wumpus_near)
257NTSTSTSSSSTSSSSSSTSN | BRZ > 10100001 00000010 (no_wumpus)
258A"*sniff* (You smell the evil Wumpus nearby!)\n"
259SSSSN | PUSH 0 (number of substitutions)
260NSTTSSSN | JSR > 1000 (printf)
261NSSVTSTSSSSTSSSSSSTSN | MARK: 10100001 00000010 (no_wumpus)
262
263@ Print a list of nearby rooms.
264A"This room contains tunnels to the following rooms:"
265SSSSN | PUSH 0 (number of substitutions)
266NSTTSSSN | JSR > 1000 (printf)
267SSSTSSSSSSSSSTTSN | PUSH 0x1006 (player_location address)
268TTT | LOAD
269SSSTSSSSSSSSSSTTN | PUSH 0x1003 (number_of_links_per_room address)
270TTT | LOAD
271SSSTN | PUSH 1
272TSST | SUBTRACT
273@ Print one room on each pass through this loop.
274@ TOS> tunnel_index, room_number
275NSSVTSTSSSSTSSSSSSTTN | MARK: 10100001 00000011 (print_room_list_loop)
276A" %u"
277SSSTSTN | PUSH 5
278NSTTTSSN | JSR > 1100 (deepdup)
279SSSTTTN | PUSH 7
280NSTTTSSN | JSR > 1100 (deepdup)
281NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination)
282SSSTN | PUSH 1 (number of substitutions)
283NSTTSSSN | JSR > 1000 (printf)
284@ Test for end of loop
285SNS | DUP
286NTSTSTSSSSTSSSSSTSSN | BRZ > 10100001 00000100 (print_room_list_loop_end)
287SSSTN | PUSH 1
288TSST | SUBTRACT
289NSNTSTSSSSTSSSSSSTTN | JMP > 10100001 00000011 (print_room_list_loop)
290@ Clean up and return.
291NSSVTSTSSSSTSSSSSTSSN | MARK: 10100001 00000100 (print_room_list_loop_end)
292SSSTSTSN | PUSH 10 (ASCII '\n')
293TNSS | PUTCHAR
294SNN | DROP
295SNN | DROP
296NTN | RTS
297
298#endif