From 28a945f72864aae5dbc0da783628a7c0873bb467 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 12 Mar 2020 21:51:21 -0700 Subject: [PATCH] Added ability for player to move around the tunnels in Wumpus. --- examples/wump/wump.pvvs | 2 +- examples/wump/wump_ui.pvvs | 166 ++++++++++++++++++++++++++++++++++++- 2 files changed, 166 insertions(+), 2 deletions(-) diff --git a/examples/wump/wump.pvvs b/examples/wump/wump.pvvs index 799b24e..01284a9 100644 --- a/examples/wump/wump.pvvs +++ b/examples/wump/wump.pvvs @@ -33,7 +33,7 @@ NSTTSSTTSTTN | JSR > 10011011 (print_cave_description) @ Main game loop NSSVTSSTTSTSN | MARK: 10011010 (wump_loop) NSTTSTSSSSTN | JSR > 10100001 (print_room_stats) -A"Move or shoot? (m-s)\n" +A"Move or shoot? (m/s)\n" SSSSN | PUSH 0 (number of string substitutions) NSTTSSSN | JSR > 1000 (printf) NSTTSTSSSTSN | JSR > 10100010 (move_or_shoot) diff --git a/examples/wump/wump_ui.pvvs b/examples/wump/wump_ui.pvvs index 88ff4b0..fa5c2a7 100644 --- a/examples/wump/wump_ui.pvvs +++ b/examples/wump/wump_ui.pvvs @@ -58,6 +58,170 @@ TNSS | PUTCHAR TNSS | PUTCHAR NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ is_room_adjacent +@ Description: +@ Checks if 'room_number' is adjacent to the player's current room. +@ Call Stack: +@ room_number <-- TOS +@ Return Stack: +@ (1 or 0) for true/false <-- TOS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#include +NSSVTSTSSTSSN | MARK: 10100100 (is_room_adjacent) + +SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number_of_tunnels_per_room) +TTT | LOAD +SSSTN | PUSH +1 +TSST | SUBTRACT + +@ TOS> tunnel_index, destination_room_num +NSSVTSTSSTSSSSSSSSSSN | MARK: 10100100 00000000 (is_room_adjacent:main_loop) +SSSTSN | PUSH +2 +NSTTTSSN | JSR > 1100 (deepdup) +SSSTSN | PUSH +2 +NSTTTSSN | JSR > 1100 (deepdup) +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player_location) +TTT | LOAD +NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) +TSST | SUBTRACT +NTSTSTSSTSSSSSSSSSTN | BRZ > 10100100 00000001 (is_room_adjacent:found_tunnel) +SSSTN | PUSH +1 +TSST | SUBTRACT +SNS | DUP +NTTTSTSSTSSSSSSSSTSN | BMI > 10100100 00000010 (is_room_adjacent:no_match) +NSNTSTSSTSSSSSSSSSSN | JMP > 10100100 00000000 (is_room_adjacent:main_loop) + +NSSVTSTSSTSSSSSSSSSTN | MARK: 10100100 00000001 (is_room_adjacent:found_tunnel) +SNN | DROP +SNN | DROP +SSSTN | PUSH +1 +NTN | RTS + +NSSVTSTSSTSSSSSSSSTSN | MARK: 10100100 00000010 (is_room_adjacent:no_match) +SNN | DROP +SNN | DROP +SSSSN | PUSH 0 +NTN | RTS + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ move_player +@ Description: +@ Prompts the player for a room number. Moves to that room, checking the new +@ environment and executing consequences (fell in a pit, etc) as appropriate. +@ Call Stack: +@ +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#include +#include +#include +NSSVTSTSSSTTN | MARK: 10100011 (move_player) + +A"To which room do you wish to move?\n" +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NSTTSSTTSSTN | JSR > 10011001 (get_line) +SSSTTSSSSSSSSSSSSN | PUSH 0x3000 (USER_INPUT_BUFFER address) +NSTTTSSSSN | JSR > 110000 (atoi) +SNN | DROP + +@ The desired room number is now on the TOS. Verify that it is valid. +SNS | DUP +NSTTSTSSTSSN | JSR > 10100100 (is_room_adjacent) +NTSTSTSSSTTSSSSSSSTN | BRZ > 10100011 00000001 (invalid room number) +NSNTSTSSSTTSSSSSSSSN | JMP > 10100011 00000000 (valid room number) + +NSSVTSTSSSTTSSSSSSSTN | MARK: 10100011 00000001 (invalid room number) +@ TOS> room_number +SNN | DROP +A"*Oof!* (you hit the wall)\n" +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NSTTSSSSN | JSR > 10000 (random) +SSSTTSN | PUSH 6 (chance) +TSTT | MODULO +NTSTSTSSSTTSSSSSSTSN | BRZ > 10100011 00000010 (woke the wumpus) +NTN | RTS +NSSVTSTSSSTTSSSSSSTSN | MARK: 10100011 00000010 (woke the wumpus) +A"Your colorful comments awaken the wumpus!\n" +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NSTTSSSSN | JSR > 10000 (random) +SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number of tunnels per room) +TSTT | MODULO +SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus location) +TTT | LOAD +NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) +SSSTSSSSSSSSSTTTN | PUSH 0x1007 (ptr to wumpus location) +SNT | SWAP +TTS | STORE +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +TTT | LOAD +NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus) +NTSTSTSSSTTSSSSSSTTN | BRZ > 10100011 00000011 (wumpus did not move to player) +NSTTTTTTTTTSSSSSSSSN | JSR > 11111111 00000000 (wump_kill) +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NNN | DIE +NSSVTSTSSSTTSSSSSSTTN | MARK: 10100011 00000011 (wumpus did not move to player) +NTN | RTS + +NSSVTSTSSSTTSSSSSSSSN | MARK: 10100011 00000000 (valid room number) +@ TOS> room_number +@ Move player to new room +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +SNT | SWAP +TTS | STORE +@ Check for wumpus in new player location +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +TTT | LOAD +NSTTSTSSSSSN | JSR > 10100000 (room_has_wumpus) +NTSTSTSSSTTSSSSSTSSN | BRZ > 10100011 00000100 (no wumpus in new room) +NSTTTTTTTTTSSSSSSSSN | JSR > 11111111 00000000 (wump_kill) +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NNN | DIE +NSSVTSTSSSTTSSSSSTSSN | MARK: 10100011 00000100 (no wumpus in new room) +@ Check for pits in new player location +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +TTT | LOAD +NSTTSSSTTSTN | JSR > 10001101 (room_has_pits) +NTSTSTSSSTTSSSSSTSTN | BRZ > 10100011 00000101 (no pits in new room) +NSTTSSSSN | JSR > 10000 (random) +SSSTTSN | PUSH 6 (chance) +TSTT | MODULO +NTSTSTSSSTTSSSSSTTSN | BRZ > 10100011 00000110 (survived the pits) +NSTTTTTTTTTSSSSSTSTN | JSR > 11111111 00000101 (pit_kill) +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NNN | DIE +NSSVTSTSSSTTSSSSSTTSN | MARK: 10100011 00000110 (survived the pits) +NSTTTTTTTTTSSSSSTTSN | JSR > 11111111 00000110 (pit_survive) +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NSSVTSTSSSTTSSSSSTSTN | MARK: 10100011 00000101 (no pits in new room) +@ Check for bats in new player location +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +TTT | LOAD +NSTTSSSTTSSN | JSR > 10001100 (room_has_bats) +NTSTSTSSSTTSSSSSTTSN | BRZ > 10100011 00000110 (no bats in new room) +A"*flap* *flap* *flap* (humongous bats pick you up and move you!)\n" +SSSSN | PUSH 0 (number of string substitutions) +NSTTSSSN | JSR > 1000 (printf) +NSTTSSSSN | JSR > 10000 (random) +SSSTSSSSSSSSSSTTN | PUSH 0x1003 (ptr to number of tunnels per room) +TSTT | MODULO +SSSTSSSSSSSSSTTSN | PUSH 0x1006 (ptr to player location) +TTT | LOAD +NSTTSSSTSSSN | JSR > 10001000 (get_tunnel_destination) +NSNTSTSSSTTSSSSSSSSN | JMP > 10100011 00000000 (valid room number) +NSSVTSTSSSTTSSSSSTTSN | MARK: 10100011 00000110 (no bats in new room) +NTN | RTS + @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Name: @ move_or_shoot @@ -93,7 +257,7 @@ NSNTSTSSSTSN | JMP > 10100010 (move_or_shoot) @ User typed 'm' NSSVTSTSSSTSSSSSSSSSN | MARK: 10100010 00000000 (move) -@ TODO: JSR move +NSTTSTSSSTTN | JSR > 10100011 (move_player) NTN | RTS @ User typed 's' -- 2.20.1