The command loop and command handling is done in lines 1000–1700.
First we go to the bottom of the screen and print the prompt. CALL -868
clears the line to the right of the cursor:
1000 VTAB (24): PRINT "COMMAND? ";: CALL - 868
Then we loop until we get a key press:
1001 X = PEEK ( - 16384): IF X < 128 THEN 1001
We see how much memory is available (not yet sure why):
1002 Q = FRE (0)
and reset the keyboard:
1010 POKE - 16368,0
Many commands are handled differently depending on whether we're outside or inside.
These commands are:
CR
(141) NORTH 1100 or FORWARD 1150RIGHT ARROW
(149) EAST 1200 or TURN RIGHT 1250LEFT ARROW
(136) WEST 1300 or TURN LEFT 1350/
(175) SOUTH 1400 or TURN AROUND 1450X
(216) GO 1500 or 1550A
or 27
(193 or 155) ATTACK 1600 or 1650SGN(INOUT)
will be 0 if we're outside and 1 if we're inside.
1030 IF X = 141 THEN ON SGN (INOUT) + 1 GOTO 1100,1150
1040 IF X = 149 THEN ON SGN (INOUT) + 1 GOTO 1200,1250
1050 IF X = 136 THEN ON SGN (INOUT) + 1 GOTO 1300,1350
1060 IF X = 175 THEN ON SGN (INOUT) + 1 GOTO 1400,1450
1070 IF X = 216 THEN ON SGN (INOUT) + 1 GOTO 1500,1550
1080 IF X = 193 OR X = 155 THEN ON SGN (INOUT) + 1 GOTO 1600,1650
SPACE
passes:
1081 IF X = 160 THEN PRINT "PASS": GOTO 1090
S
shows stats/inventory:
1085 IF X = 211 THEN 1700
P
toggles PAUSE ON/OFF which we store as PA
(1 for ON, 0 for OFF):
1086 IF X = 208 THEN IF PA = 1 THEN PA = 0: PRINT "PAUSE OFF": GOTO 1000
1087 IF X = 208 THEN IF PA = 0 THEN PA = 1: PRINT "PAUSE ON": GOTO 1000
Note that PAUSE ON/OFF doesn't call the Post-Command code (so doesn't reduce food, etc)
Any other keys and we print "HUH?" and go back to the start of this routine:
1089 PRINT "HUH?": GOTO 1000
Once the command is executed we normally GOTO line 1090.
First we reduce food by 1 (or 0.1 if we're inside). If FOOD hits 0 then we set HIT POINTS to 0 too, announce the player has starved and go to line 1093 (which in turn will send us to the Death routine at 6000)
1090 PW(0) = PW(0) - 1 + SGN (INOUT) * .9: IF PW(0) < 0 THEN C(0) = 0: PRINT : PRINT "YOU HAVE STARVED!!!!!": GOTO 1093
If we haven't starved, though, we update our FOOD / HIT POINTS / GOLD display:
1091 POKE 33,40: VTAB (22): HTAB (30): PRINT "FOOD=";PW(0);: CALL - 868: VTAB (23): HTAB (30): PRINT "H.P.=";C(0);: CALL - 868: VTAB (24): HTAB (30): PRINT "GOLD=";C(5);: CALL - 868: POKE 33,29: HTAB (1)
We round our FOOD to one decimal place.
1092 PW(0) = INT (PW(0) * 10) / 10
If HIT POINTS are zero or less, we go to the Death handling routine:
1093 IF C(0) < = 0 THEN 6000
If we're in a dungeon (IN
is same as INOUT
) we move the monsters around. If this has resulted in HIT POINTS being zero or less, we go back to the previous line to go to the Death handling routine.
1095 IF IN > 0 THEN GOSUB 4000: IF C(0) < = 0 THEN 1093
The following is the same as line 1091. I guess we do it again because the monster movement in the previous line may have changed some values.
1096 POKE 33,40: VTAB (22): HTAB (30): PRINT "FOOD=";PW(0);: CALL - 868: VTAB (23): HTAB (30): PRINT "H.P.=";C(0);: CALL - 868: VTAB (24): HTAB (30): PRINT "GOLD=";C(5);: CALL - 868: POKE 33,29: HTAB (1)
Not yet sure what GOSUB 100 or GOSUB 200 do. Perhaps draw.
1097 IF INOUT = 0 THEN GOSUB 100: GOTO 1000
1098 IF INOUT > 0 THEN GOSUB 200: GOTO 1000