Akalabeth: porting from AppleSoft BASIC to GWBASIC.

Akalabeth's skeleton
I was wandering on Internet after reading that Mystery House by Sierra Online had the BASIC source available and in the public domain, didn't found the game but instead found Akalabeth source code.
Akalabeth has the rare privilege of being the first RPG game widely sold. Made by a team of people? no. A big company? no. It was programmed by a high-school teenager in the Apple II computers available at the school during the summer of 1979.
Surely we can imagine a bunch of boisterous teenagers testing the game in the school and playing endlessly while giving suggestions to the author.
Happens he worked at Clear Lake City, Texas at a ComputerLand and demo'ed the game to his boss, who consented to sell the game in the store for $20. The game was packed as a floppy disk inside a Ziploc bag with photocopied instructions.
California Pacific Computer Company received a copy of the game and contacted the teenager to publish the game. He flew to California with his parents and signed a contract to receive $5 USD for each copy sold.
He sold 30,000 copies, and this way Richard Garriott started one of the most prolific series of RPG games: Ultima. In fact Akalabeth is also known as Ultima 0 (zero).
Apparently the name derives from Tolkien's Akallabêth, part of The Silmarillion. Even the final enemy is called Balrog. Apart from the names no other reference to Tolkien exists.

Original platform

Lets return to Akalabeth, it is written in Applesoft BASIC. This BASIC language resembles strongly Microsoft BASIC but includes its own extensions for the Apple II graphics.
Many things aren't doable using BASIC statements so the programmers needs to resort to using CALL, POKE and PEEK to access directly the ROM routines and the RAM values.
The site archive.org contains several copies of Akalabeth source code and I've found missing parts in the two copies available, but fortunately the missing parts are different in each one, so I could made up a good source version.
Later while doing the porting I found a commented version of the Akalabeth BASIC code missing some of the graphics routines.

Target platform

I decided to port it to GW-Basic and make it to run over Windows XP using VirtualBox in a Mac computer. One of the difficult things is that the CGA mode isn't emulated properly by VirtualBox, so INPUT doesn't work correctly while in 320x200x4 colors graphics mode (SCREEN 1) and CLS doesn't do anything! Even worst, if the program crashes in graphics mode, you're unable to enter any BASIC command.
Other important thing is that the computer is way too fast even with slow BASIC, so I needed to add delays to be able to see the game information.
A final note is that there exists a version of Akalabeth ported to MS-DOS but the source code isn't available, so we don't know if it's still BASIC.

AppleSoft BASIC unique things

Akalabeth's orc
The video section of Apple II allows you to have high-resolution graphics in the top area of screen (280x160 pixels), and a text window of 40x4 characters in the bottom area of the screen.
This text window can scroll like a small window. But in GW-Basic we don't have anything like this. So I added erasing the area and delays as needed.
Another thing are the "useful" ROM routines, like doing CALL 62450 to clear the high-resolution screen, or CALL -868 to clear till the end of current screen line.
HTAB(x) allows to position horizontally the cursor, it was replaced with LOCATE ,x
VTAB(x) allows to position vertically the cursor, similarly replaced with LOCATE x,
Perhaps the most misunderstood thing would be PEEK(-16384) it was essentially identical to INKEY$ of GW-Basic, but of course it adds a whole degree of complexity because the codes for special keys. Not a thing in any webpage but I found the (non-searchable!) Apple II Reference Manual page 7 and all was there.
Another thing very different versus GW-Basic is that only the first 2 letters are useful as a variable name in AppleSoft BASIC, this means: CENTER, CENTE, CENT, CEN and CE all refer to same variable, and this is completely different for GW-Basic where every name is different. I knew this from the start but still cause some difficulties when drawing ladders, because I forgot to convert a BASE name and it was BA in other places, causing steps of ladder to not appear.
The function RND can be called in two ways: a negative argument and a positive argument. The first one sets up the random number generator, the second one advances the random number generator. For GW-Basic this means replacing the first with RANDOMIZE and the second with RND without argument.
Last and not least, HPLOT is the star of the graphics core of AppleSoft BASIC. It can be used to plot a point using HPLOT x,y or to draw a line using HPLOT x1,y1 TO x2,y2. Or to draw several lines using HPLOT x1,y1 TO x2,y2 TO x3,y3 TO x4,y4.
GW-Basic provides for a single point using PSET (x,y), a line using LINE (x1,y1)-(x2,y2) and continues lines using LINE -(x3,y3).
At some point converting all the vectorial graphics caused a buffer overflow in the GW-Basic interpreter because exceeded 255 characters in a line.
Sometimes I preferred to enter the program using a text editor (TextEdit in Mac) and also had to convert UNIX end of lines (a single \n) to MSDOS end of lines (\r\n)
A simple Perl command line did the effect:
perl -pe 's/\r\n|\n|\r/\r\n/g' aka.bas >aka2.bas

Final fantasy... err bug.

A bug that bothered me a lot made it to look like the player moved randomly while attacking. It results the enemies can move! but in moving it added +.5 probably to correct a floating-point rounding bug in AppleSoft BASIC but this caused to round to 1 creating a closer wall in GW-Basic. Lines 4040, 4046 and 4080 were the culprit.

The ported game.

Akalabeth game running in GW-Basic
The final result of porting is simply astonishing. Akalabeth has two game modes, a bird-view of world map and then a 3D viewing of dungeons. Also has randomly generated dungeons, missions, multiple weapons, stats for your character, 10 different enemies, fight/battle, hidden walls and traps.
For a 1979 BASIC game that was simply amazing! I can see clearly that if somehow I could be at a computer store at the time (of course using a time machine), I would have bought a copy!
Be sure to buy a weapon in your first try and also all the food you can.
Move with arrows, press Enter to enter into places.
Then enter the palace of Lord British (the bigger square in map), enter your name and say Y to start a quest to kill a monster (it will be your objective). Enter the dungeon (marked with a X) using Enter and move with arrows, use A to attack if you find something ugly. If you think there's no exit, check for false walls.

0 ON ERROR GOTO 4
1 REM AKALABETH, PORT TO GWBASIC BY NANOCHESS, JAN/28/2019 TO FEB/03/2019
4 CLS:KEY OFF
7 CLEAR:GOSUB 60000
8 RANDOMIZE ABS(LN)
9 LEVEL = 0
10 SCREEN 1:SCREEN 0:LOCATE 12:PRINT " WELCOME TO AKALABETH, WORLD OF DOOM!"
20 DIM DN%(10,10),TE%(20,20),XX%(10),YY%(10),PE%(10,3),LD%(10,5),CD%(10,3),FT%(10,5),LA%(10,3)
30 FOR X=0 TO 20:TE%(X,0)=1:TE%(0,X)=1:TE%(X,20)=1:TE%(20,X)=1:NEXT
35 LOCATE 23:PRINT "  (PLEASE WAIT)";
40 FOR X=1 TO 19:FOR Y=1 TO 19:TE%(X,Y)=INT(RND^5*4.5)
41 IF TE%(X,Y)=3 AND RND>.5 THEN TE%(X,Y)=0
42 NEXT:PRINT ".";:NEXT
50 TE%(INT(RND*19+1),INT(RND*19+1))=5:TX=INT(RND*19+1):TY=INT(RND*19+1):TE%(TX,TY)=3
51 XX%(0)=139:YY%(0)=79
52 FOR X=2 TO 20 STEP 2:XX%(X/2)=INT(ATN(1/X)/ATN(1)*140+.5):YY%(X/2)=INT(XX%(X/2)*4/7)
53 PE%(X/2,0)=139-XX%(X/2):PE%(X/2,1)=139+XX%(X/2):PE%(X/2,2)=79-YY%(X/2):PE%(X/2,3)=79+YY%(X/2):NEXT
54 PE%(0,0)=0:PE%(0,1)=279:PE%(0,2)=0:PE%(0,3)=159
55 FOR X=1 TO 10:CD%(X,0)=139-XX%(X)/3:CD%(X,1)=139+XX%(X)/3:CD%(X,2)=79-YY%(X)*.7:CD%(X,3)=79+YY%(X):NEXT:PRINT ".";
56 FOR X=0 TO 9:LD%(X,0)=(PE%(X,0)*2+PE%(X+1,0))/3:LD%(X,1)=(PE%(X,0)+2*PE%(X+1,0))/3:W=LD%(X,0)-PE%(X,0)
57 LD%(X,2)=PE%(X,2)+W*4/7:LD%(X,3)=PE%(X,2)+2*W*4/7:LD%(X,4)=(PE%(X,3)*2+PE%(X+1,3))/3:LD%(X,5)=(PE%(X,3)+2*PE%(X+1,3))/3
58 LD%(X,2)=LD%(X,4)-(LD%(X,4)-LD%(X,2))*.8:LD%(X,3)=LD%(X,5)-(LD%(X,5)-LD%(X,3))*.8:IF LD%(X,3)=LD%(X,4) THEN LD%(X,3)=LD%(X,3)-1
59 NEXT
60 FOR X=0 TO 9:FT%(X,0)=139-XX%(X)/3:FT%(X,1)=139+XX%(X)/3:FT%(X,2)=139-XX%(X+1)/3:FT%(X,3)=139+XX%(X+1)/3
61 FT%(X,4)=79+(YY%(X)*2+YY%(X+1))/3:FT%(X,5)=79+(YY%(X)+2*YY%(X+1))/3:NEXT
62 FOR X=0 TO 9:LA%(X,0)=(FT%(X,0)*2+FT%(X,1))/3:LA%(X,1)=(FT%(X,0)+2*FT%(X,1))/3:LA%(X,3)=FT%(X,4):LA%(X,2)=159-LA%(X,3):NEXT
68 COLOR 3
70 GOSUB 100:GOTO 1000
90 FOR X=0 TO 9:FOR Y=0 TO 5:PRINT LD%(X,Y);" ";:NEXT:PRINT:NEXT:INPUT Q$
100 GOSUB 60900:FOR Y=-1 TO 1:FOR X=-1 TO 1
105 LINE (138,75)-(142,75):LINE (140,73)-(140,77)
110 ZZ=TE%(TX+X,TY+Y):X1=65+(X+1)*50:Y1=(Y+1)*50
120 IF ZZ=2 THEN LINE (X1+20,Y1+20)-(X1+30,Y1+20):LINE -(X1+30,Y1+30):LINE -(X1+20,Y1+30):LINE -(X1+20,Y1+20)
130 IF ZZ=3 THEN LINE (X1+10,Y1+10)-(X1+20,Y1+10):LINE -(X1+20,Y1+40):LINE -(X1+10,Y1+40):LINE -(X1+10,Y1+30):LINE -(X1+40,Y1+30)
135 IF ZZ=3 THEN LINE -(X1+40,Y1+40):LINE -(X1+30,Y1+40):LINE -(X1+30,Y1+10):LINE -(X1+40,Y1+10):LINE -(X1+40,Y1+20):LINE -(X1+10,Y1+20):LINE -(X1+10,Y1+10)
140 IF ZZ=4 THEN LINE (X1+20,Y1+20)-(X1+30,Y1+30):LINE -(X1+20,Y1+30):LINE -(X1+30,Y1+20)
150 IF ZZ=5 THEN LINE (X1,Y1)-(X1+50,Y1):LINE -(X1+50,Y1+50):LINE -(X1,Y1+50):LINE -(X1,Y1):LINE (X1+10,Y1+10)-(X1+10,Y1+40)
155 IF ZZ=5 THEN LINE -(X1+40,Y1+40):LINE -(X1+40,Y1+10):LINE -(X1+10,Y1+10):LINE -(X1+40,Y1+40):LINE (X1+10,Y1+40)-(X1+40,Y1+10)
160 IF ZZ=1 THEN LINE (X1+10,Y1+50)-(X1+10,Y1+40):LINE -(X1+20,Y1+30):LINE -(X1+40,Y1+30):LINE -(X1+40,Y1+50):LINE (X1,Y1+10)-(X1+10,Y1+10):LINE (X1+50,Y1+10)-(X1+40,Y1+10):LINE (X1,Y1+40)-(X1+10,Y1+40):LINE (X1+40,Y1+40)-(X1+50,Y1+40)
170 IF ZZ=1 THEN LINE (X1+10,Y1)-(X1+10,Y1+20):LINE -(X1+20,Y1+20):LINE -(X1+20,Y1+30):LINE -(X1+30,Y1+30):LINE -(X1+30,Y1+10):LINE -(X1+40,Y1+10):LINE -(X1+40,Y1)
190 NEXT:NEXT:RETURN
200 GOSUB 60900:DI=0:COLOR 3
202 CE=DN%(PX+DX*DI,PY+DY*DI):LE=DN%(PX+DX*DI+DY,PY+DY*DI-DX):RI=DN%(PX+DX*DI-DY,PY+DY*DI+DX)
204 L1=PE%(DI,0):R1=PE%(DI,1):T1=PE%(DI,2):B1=PE%(DI,3):L2=PE%(DI+1,0):R2=PE%(DI+1,1):T2=PE%(DI+1,2):B2=PE%(DI+1,3)
205 CE=INT(CE):LE=INT(LE):RI=INT(RI)
206 MC=INT(CE/10):CE=CE-MC*10:LE=INT((LE/10-INT(LE/10))*10+.1):RI=INT((RI/10-INT(RI/10))*10+.1)
208 IF DI=0 THEN 216
210 IF CE=1 OR CE=3 OR CE=4 THEN LINE (L1,T1)-(R1,T1):LINE -(R1,B1):LINE -(L1,B1):LINE -(L1,T1)
212 IF CE=1 OR CE=3 THEN EN=1:GOTO 260
214 IF CE=4 THEN LINE (CD%(DI,0),CD%(DI,3))-(CD%(DI,0),CD%(DI,2)):LINE -(CD%(DI,1),CD%(DI,2)):LINE -(CD%(DI,1),CD%(DI,3)):EN=1:GOTO 260
216 IF LE=1 OR LE=3 OR LE=4 THEN LINE (L1,T1)-(L2,T2):LINE (L1,B1)-(L2,B2)
218 IF RI=1 OR RI=3 OR RI=4 THEN LINE (R1,T1)-(R2,T2):LINE (R1,B1)-(R2,B2)
220 IF LE=4 AND DI>0 THEN LINE (LD%(DI,0),LD%(DI,4))-(LD%(DI,0),LD%(DI,2)):LINE -(LD%(DI,1),LD%(DI,3)):LINE -(LD%(DI,1),LD%(DI,5))
222 IF LE=4 AND DI=0 THEN LINE (0,LD%(DI,2)-3)-(LD%(DI,1),LD%(DI,3)):LINE -(LD%(DI,1),LD%(DI,5))
224 IF RI=4 AND DI>0 THEN LINE (279-LD%(DI,0),LD%(DI,4))-(279-LD%(DI,0),LD%(DI,2)):LINE -(279-LD%(DI,1),LD%(DI,3)):LINE -(279-LD%(DI,1),LD%(DI,5))
226 IF RI=4 AND DI=0 THEN LINE (279,LD%(DI,2)-3)-(279-LD%(DI,1),LD%(DI,3)):LINE -(279-LD%(DI,1),LD%(DI,5))
228 IF LE=3 OR LE=1 OR LE=4 THEN 234
230 IF DI<>0 THEN LINE (L1,T1)-(L1,B1)
232 LINE (L1,T2)-(L2,T2):LINE -(L2,B2):LINE -(L1,B2)
234 IF RI=3 OR RI=1 OR RI=4 THEN 240
236 IF DI<>0 THEN LINE (R1,T1)-(R1,B1)
238 LINE (R1,T2)-(R2,T2):LINE -(R2,B2):LINE -(R1,B2)
240 IF CE=7 OR CE=9 THEN LINE (FT%(DI,0),FT%(DI,4))-(FT%(DI,2),FT%(DI,5)):LINE -(FT%(DI,3),FT%(DI,5)):LINE -(FT%(DI,1),FT%(DI,4)):LINE -(FT%(DI,0),FT%(DI,4))
242 IF CE=8 THEN LINE (FT%(DI,0),158-FT%(DI,4))-(FT%(DI,2),158-FT%(DI,5)):LINE -(FT%(DI,3),158-FT%(DI,5)):LINE -(FT%(DI,1),158-FT%(DI,4)):LINE -(FT%(DI,0),158-FT%(DI,4))
244 IF CE=7 OR CE=8 THEN BA=LA%(DI,3):TP=LA%(DI,2):LX=LA%(DI,0):RX=LA%(DI,1):LINE (LX,BA)-(LX,TP):LINE (RX,TP)-(RX,BA)
246 IF CE=7 OR CE=8 THEN Y1=(BA*4+TP)/5:Y2=(BA*3+TP*2)/5:Y3=(BA*2+TP*3)/5:Y4=(BA+TP*4)/5:LINE (LX,Y1)-(RX,Y1):LINE (LX,Y2)-(RX,Y2):LINE (LX,Y3)-(RX,Y3):LINE (LX,Y4)-(RX,Y4)
248 IF DI>0 AND CE=5 THEN LINE (139-10/DI,PE%(DI,3))-(139-10/DI,PE%(DI,3)-10/DI):LINE -(139+10/DI,PE%(DI,3)-10/DI):LINE -(139+10/DI,PE%(DI,3)):LINE -(139-10/DI,PE%(DI,3))
249 IF CE=5 AND DI>0 THEN COLOR 1:PRINT "CHEST!":COLOR 3
250 IF DI>0 AND CE=5 THEN LINE (139-10/DI,PE%(DI,3)-10/DI)-(139-5/DI,PE%(DI,3)-15/DI):LINE -(139+15/DI,PE%(DI,3)-15/DI):LINE -(139+15/DI,PE%(DI,3)-5/DI):LINE -(139+10/DI,PE%(DI,3))
252 IF DI>0 AND CE=5 THEN LINE (139+10/DI,PE%(DI,3)-10/DI)-(139+15/DI,PE%(DI,3)-15/DI)
260 IF MC<1 THEN 490
265 B=79+YY%(DI):C=139
266 COLOR 1:IF MC=8 THEN PRINT "CHEST!";:GOSUB 60868:PRINT:COLOR 3:GOTO 269
267 PRINT M$(MC);:GOSUB 60868:PRINT:COLOR 3
269 IF DI=0 THEN 490
270 ON MC GOTO 300,310,320,330,340,350,360,370,380,390
280 GOTO 490
300 LINE (C-23/DI,B)-(C-15/DI,B):LINE -(C-15/DI,B-15/DI):LINE -(C-8/DI,B-30/DI):LINE -(C+8/DI,B-30/DI):LINE -(C+15/DI,B-15/DI):LINE -(C+15/DI,B):LINE -(C+23/DI,B)
301 LINE (C,B-26/DI)-(C,B-65/DI):LINE (C-2/DI+.5,B-38/DI)-(C+2/DI+.5,B-38/DI):LINE (C-3/DI+.5,B-45/DI)-(C+3/DI+.5,B-45/DI):LINE (C-5/DI+.5,B-53/DI)-(C+5/DI+.5,B-53/DI)
302 LINE (C-23/DI,B-56/DI)-(C-30/DI,B-53/DI):LINE -(C-23/DI,B-45/DI):LINE -(C-23/DI,B-53/DI):LINE -(C-8/DI,B-38/DI)
303 LINE (C-15/DI,B-45/DI)-(C-8/DI,B-60/DI):LINE -(C+8/DI,B-60/DI):LINE -(C+15/DI,B-45/DI):LINE (C+15/DI,B-42/DI)-(C+15/DI,B-57/DI):LINE (C+12/DI,B-45/DI)-(C+20/DI,B-45/DI)
304 LINE (C,B-75/DI)-(C-5/DI+.5,B-80/DI):LINE -(C-8/DI,B-75/DI):LINE -(C-5/DI+.5,B-65/DI):LINE -(C+5/DI+.5,B-65/DI):LINE -(C+5/DI+.5,B-68/DI):LINE -(C-5/DI+.5,B-68/DI):LINE -(C-5/DI+.5,B-65/DI)
305 LINE -(C+5/DI+.5,B-65/DI):LINE -(C+8/DI,B-75/DI):LINE -(C+5/DI+.5,B-80/DI):LINE -(C-5/DI+.5,B-80/DI):PSET (C-5/DI+.5,B-72/DI):PSET (C+5/DI+.5,B-72/DI)
309 GOTO 490
310 LINE (C,B-56/DI)-(C,B-8/DI):LINE -(C+10/DI,B):LINE -(C+30/DI,B):LINE -(C+30/DI,B-45/DI):LINE -(C+10/DI,B-64/DI):LINE -(C,B-56/DI)
311 LINE -(C-10/DI,B-64/DI):LINE -(C-30/DI,B-45/DI):LINE -(C-30/DI,B):LINE -(C-10/DI,B):LINE -(C,B-8/DI)
312 LINE (C-10/DI,B-64/DI)-(C-10/DI,B-75/DI):LINE -(C,B-83/DI):LINE -(C+10/DI,B-75/DI):LINE -(C,B-79/DI):LINE -(C-10/DI,B-75/DI):LINE -(C,B-60/DI):LINE -(C+10/DI,B-75/DI):LINE -(C+10/DI,B-64/DI)
319 GOTO 490
320 LINE (C+5/DI,B-30/DI)-(C,B-25/DI):LINE -(C-5/DI,B-30/DI):LINE -(C-15/DI,B-5/DI):LINE -(C-10/DI,B):LINE -(C+10/DI,B):LINE -(C+15/DI,B-5/DI)
321 LINE -(C+20/DI,B-5/DI):LINE -(C+10/DI,B):LINE -(C+15/DI,B-5/DI):LINE -(C+5/DI,B-30/DI):LINE -(C+10/DI,B-40/DI):LINE -(C+3/DI+.5,B-35/DI):LINE -(C-3/DI+.5,B-35/DI):LINE -(C-10/DI,B-40/DI):LINE -(C-5/DI,B-30/DI)
322 LINE (C-5/DI,B-33/DI)-(C-3/DI+.5,B-30/DI):LINE (C+5/DI,B-33/DI)-(C+3/DI+.5,B-30/DI):LINE (C-5/DI,B-20/DI)-(C-5/DI,B-15/DI)
323 LINE (C+5/DI,B-20/DI)-(C+5/DI,B-15/DI):LINE (C-7+DI,B-20/DI)-(C-7/DI,B-15/DI):LINE (C+7/DI,B-20/DI)-(C+7/DI,B-15/DI)
329 GOTO 490
330 LINE (C,B)-(C-15/DI,B):LINE -(C-8/DI,B-8/DI):LINE -(C-8/DI,B-15/DI):LINE -(C-15/DI,B-23/DI):LINE -(C-15/DI,B-15/DI):LINE -(C-23/DI,B-23/DI)
331 LINE -(C-23/DI,B-45/DI):LINE -(C-15/DI,B-53/DI):LINE -(C-8/DI,B-53/DI):LINE -(C-15/DI,B-68/DI):LINE -(C-8/DI,B-75/DI):LINE -(C,B-75/DI)
332 LINE (C,B)-(C+15/DI,B):LINE -(C+8/DI,B-8/DI):LINE -(C+8/DI,B-15/DI):LINE -(C+15/DI,B-23/DI):LINE -(C+15/DI,B-15/DI):LINE -(C+23/DI,B-23/DI)
333 LINE -(C+23/DI,B-45/DI):LINE -(C+15/DI,B-53/DI):LINE -(C+8/DI,B-53/DI):LINE -(C+15/DI,B-68/DI):LINE -(C+8/DI,B-75/DI):LINE -(C,B-75/DI)
334 LINE (C-15/DI,B-68/DI)-(C+15/DI,B-68/DI):LINE (C-8/DI,B-53/DI)-(C+8/DI,B-53/DI):LINE (C-23/DI,B-15/DI)-(C+8/DI,B-45/DI)
335 LINE (C-8/DI,B-68/DI)-(C,B-60/DI):LINE -(C+8/DI,B-68/DI):LINE -(C+8/DI,B-60/DI):LINE -(C-8/DI,B-60/DI):LINE -(C-8/DI,B-68/DI)
336 LINE (C,B-38/DI)-(C-8/DI,B-38/DI):LINE -(C+8/DI,B-53/DI):LINE -(C+8/DI,B-45/DI):LINE -(C+15/DI,B-45/DI):LINE -(C,B-30/DI):LINE -(C,B-38/DI)
339 GOTO 490
340 LINE (C-10/DI,B-15/DI)-(C-10/DI,B-30/DI):LINE -(C-15/DI,B-20/DI):LINE -(C-15/DI,B-15/DI):LINE -(C-15/DI,B):LINE -(C+15/DI,B):LINE -(C+15/DI,B-15/DI):LINE  -(C-15/DI,B-15/DI)
341 LINE (C-15/DI,B-10/DI)-(C+15/DI,B-10/DI):LINE (C-15/DI,B-5/DI)-(C+15/DI,B-5/DI)
342 LINE (C,B-15/DI)-(C-5/DI,B-20/DI):LINE -(C-5/DI,B-35/DI):LINE -(C+5/DI,B-35/DI):LINE -(C+5/DI,B-20/DI):LINE -(C+10/DI,B-15/DI)
343 LINE (C-5/DI,B-20/DI)-(C+5/DI,B-20/DI):LINE (C-5/DI,B-25/DI)-(C+5/DI,B-25/DI):LINE (C-5/DI,B-30/DI)-(C+5/DI,B-30/DI)
344 LINE (C-10/DI,B-35/DI)-(C-10/DI,B-40/DI):LINE -(C-5/DI,B-45/DI):LINE -(C+5/DI,B-45/DI):LINE -(C+10/DI,B-40/DI):LINE -(C+10/DI,B-35/DI)
345 LINE (C-10/DI,B-40/DI)-(C,B-45/DI):LINE -(C+10/DI,B-40/DI)
346 LINE (C-5/DI,B-40/DI)-(C+5/DI,B-40/DI):LINE -(C+15/DI,B-30/DI):LINE -(C,B-40/DI):LINE -(C-15/DI,B-30/DI):LINE -(C-5/DI+.5,B-40/DI)
349 GOTO 490
350 LINE (C-20/DI,79-YY%(DI))-(C-20/DI,B-88/DI):LINE -(C-10/DI,B-83/DI):LINE -(C+10/DI,B-83/DI):LINE -(C+20/DI,B-88/DI):LINE -(C+20/DI,79-YY%(DI)):LINE -(C-20/DI,79-YY%(DI))
351 LINE (C-20/DI,B-88/DI)-(C-30/DI,B-83/DI):LINE -(C-30/DI,B-78/DI):LINE (C+20/DI,B-88/DI)-(C+30/DI,B-83/DI):LINE -(C+40/DI,B-83/DI)
352 LINE (C-15/DI,B-86/DI)-(C-20/DI,B-83/DI):LINE -(C-20/DI,B-78/DI):LINE -(C-30/DI,B-73/DI):LINE -(C-30/DI,B-68/DI):LINE -(C-20/DI,B-63/DI)
353 LINE (C-10/DI,B-83/DI)-(C-10/DI,B-58/DI):LINE -(C,B-50/DI):LINE (C+10/DI,B-83/DI)-(C+10/DI,B-78/DI):LINE -(C+20/DI,B-73/DI):LINE -(C+20/DI,B-40/DI)
354 LINE (C+15/DI,B-85/DI)-(C+20/DI,B-78/DI):LINE -(C+30/DI,B-76/DI):LINE -(C+30/DI,B-60/DI)
355 LINE (C,B-83/DI)-(C,B-73/DI):LINE -(C+10/DI,B-68/DI):LINE -(C+10/DI,B-63/DI):LINE -(C,B-58/DI)
359 GOTO 490
360 LINE (C+5/DI+.5,B-10/DI)-(C-5/DI+.5,B-10/DI):LINE -(C,B-15/DI):LINE -(C+10/DI,B-20/DI):LINE -(C+5/DI+.5,B-15/DI):LINE -(C+5/DI+.5,B-10/DI)
361 LINE -(C+7/DI+.5,B-6/DI):LINE -(C+5/DI+.5,B-3/DI):LINE -(C-5/DI+.5,B-3/DI):LINE -(C-7/DI+.5,B-6/DI):LINE -(C-5/DI+.5,B-10/DI)
362 LINE (C+2/DI+.5,B-3/DI)-(C+5/DI+.5,B):LINE -(C+8/DI,B):LINE (C-2/DI+.5,B-3/DI)-(C-5/DI+.5,B):LINE -(C-8/DI,B):PSET (C+3/DI+.5,B-8/DI):PSET (C-3/DI+.5,B-8/DI):LINE (C+3/DI+.5,B-5/DI)-(C-3/DI+.5,B-5/DI)
363 GOTO 490
370 LINE (139-10/DI,PE%(DI,3))-(139-10/DI,PE%(DI,3)-10/DI):LINE -(139+10/DI,PE%(DI,3)-10/DI):LINE -(139+10/DI,PE%(DI,3)):LINE -(139-10/DI,PE%(DI,3))
371 LINE (139-10/DI,PE%(DI,3)-10/DI)-(139-5/DI,PE%(DI,3)-15/DI):LINE -(139+15/DI,PE%(DI,3)-15/DI):LINE -(139+15/DI,PE%(DI,3)-5/DI):LINE -(139+10/DI,PE%(DI,3))
372 LINE (139+10/DI,PE%(DI,3)-10/DI)-(139+15/DI,PE%(DI,3)-15/DI)
373 GOTO 490
380 LINE (C-14/DI,B-46/DI)-(C-12/DI,B-37/DI):LINE -(C-20/DI,B-32/DI):LINE -(C-30/DI,B-32/DI):LINE -(C-22/DI,B-24/DI):LINE -(C-40/DI,B-17/DI):LINE -(C-40/DI,B-7/DI):LINE -(C-38/DI,B-5/DI):LINE -(C-40/DI,B-3/DI):LINE -(C-40/DI,B)
381 LINE -(C-36/DI,B):LINE -(C-34/DI,B-2/DI):LINE -(C-32/DI,B):LINE -(C-28/DI,B):LINE -(C-28/DI,B-3/DI):LINE -(C-30/DI,B-5/DI):LINE -(C-28/DI,B-7/DI):LINE -(C-28/DI,B-15/DI):LINE -(C,B-27/DI)
382 LINE (C+14/DI,B-46/DI)-(C+12/DI,B-37/DI):LINE -(C+20/DI,B-32/DI):LINE -(C+30/DI,B-32/DI):LINE -(C+22/DI,B-24/DI):LINE -(C+40/DI,B-17/DI):LINE -(C+40/DI,B-7/DI):LINE -(C+38/DI,B-5/DI):LINE -(C+40/DI,B-3/DI):LINE -(C+40/DI,B)
383 LINE -(C+36/DI,B):LINE -(C+34/DI,B-2/DI):LINE -(C+32/DI,B):LINE -(C+28/DI,B):LINE -(C+28/DI,B-3/DI):LINE -(C+30/DI,B-5/DI):LINE -(C+28/DI,B-7/DI):LINE -(C+28/DI,B-15/DI):LINE -(C,B-27/DI)
384 LINE (C+6/DI,B-48/DI)-(C+38/DI,B-41/DI):LINE -(C+40/DI,B-42/DI):LINE -(C+18/DI,B-56/DI):LINE -(C+12/DI,B-56/DI):LINE -(C+10/DI,B-57/DI):LINE -(C+8/DI,B-56/DI):LINE -(C-8/DI,B-56/DI):LINE -(C-10/DI,B-58/DI):LINE -(C+14/DI,B-58/DI)
385 LINE -(C+16/DI,B-59/DI)
386 LINE -(C+8/DI,B-63/DI):LINE -(C+6/DI,B-63/DI):LINE -(C+2/DI+.5,B-70/DI):LINE -(C+2/DI+.5,B-63/DI):LINE -(C-2/DI+.5,B-63/DI):LINE -(C-2/DI+.5,B-70/DI):LINE -(C-6/DI,B-63/DI):LINE -(C-8/DI,B-63/DI):LINE -(C-16/DI,B-59/DI):LINE -(C-14/DI,B-58/DI)
387 LINE -(C+10/DI,B-57/DI):LINE -(C-12/DI,B-56/DI):LINE -(C-18/DI,B-56/DI):LINE -(C-36/DI,B-47/DI):LINE -(C-36/DI,B-39/DI):LINE -(C-28/DI,B-41/DI):LINE -(C-28/DI,B-46/DI):LINE -(C-20/DI,B-50/DI):LINE -(C-18/DI,B-50/DI):LINE -(C-14/DI,B-46/DI)
388 GOTO 3087
390 LINE (C+6/DI,B-60/DI)-(C+30/DI,B-90/DI):LINE -(C+60/DI,B-30/DI):LINE -(C+60/DI,B-10/DI):LINE-(C+30/DI,B-40/DI):LINE -(C+15/DI,B-40/DI)
391 LINE (C-6/DI,B-60/DI)-(C-30/DI,B-90/DI):LINE -(C-60/DI,B-30/DI):LINE -(C-60/DI,B-10/DI):LINE -(C-30/DI,B-40/DI):LINE -(C-15/DI,B-40/DI)
392 LINE (C,B-25/DI)-(C+6/DI,B-25/DI):LINE -(C+10/DI,B-20/DI):LINE -(C+12/DI,B-10/DI):LINE -(C+10/DI,B-6/DI):LINE -(C+10/DI,B):LINE -(C+14/DI,B):LINE-(C+15/DI,B-5/DI):LINE -(C+16/DI,B):LINE -(C+20/DI,B)
393 LINE -(C+20/DI,B-6/DI):LINE -(C+18/DI,B-10/DI):LINE -(C+18/DI,B-20/DI):LINE -(C+15/DI,B-30/DI):LINE -(C+15/DI,B-45/DI):LINE -(C+40/DI,B-60/DI):LINE -(C+40/DI,B-70/DI)
394 LINE -(C+10/DI,B-55/DI):LINE -(C+6/DI,B-60/DI):LINE -(C+10/DI,B-74/DI):LINE -(C+6/DI,B-80/DI):LINE -(C+4/DI+.5,B-80/DI):LINE -(C+3/DI+.5,B-82/DI):LINE -(C+2/DI+.5,B-80/DI):LINE -(C,B-80/DI)
395 LINE (C,B-25/DI)-(C-6/DI,B-25/DI):LINE -(C-10/DI,B-20/DI):LINE -(C-12/DI,B-10/DI):LINE -(C-10/DI,B-6/DI):LINE -(C-10/DI,B):LINE -(C-14/DI,B):LINE -(C-15/DI,B-5/DI):LINE -(C-16/DI,B):LINE -(C-20/DI,B)
396 LINE -(C-20/DI,B-6/DI):LINE -(C-18/DI,B-10/DI):LINE -(C-18/DI,B-20/DI):LINE -(C-15/DI,B-30/DI):LINE -(C-15/DI,B-45/DI):LINE -(C-40/DI,B-60/DI):LINE -(C-40/DI,B-70/DI)
397 LINE -(C-10/DI,B-55/DI):LINE -(C-6/DI,B-60/DI):LINE -(C-10/DI,B-74/DI):LINE -(C-6/DI,B-80/DI):LINE -(C-4/DI+.5,B-80/DI):LINE -(C-3/DI+.5,B-82/DI):LINE -(C-2/DI+.5,B-80/DI):LINE -(C,B-80/DI)
398 LINE (C-6/DI,B-25/DI)-(C,B-6/DI):LINE -(C+10/DI,B):LINE -(C+4/DI+.5,B-8/DI):LINE -(C+6/DI,B-25/DI):LINE (C-40/DI,B-64/DI)-(C-40/DI,B-90/DI):LINE -(C-52/DI,B-80/DI):LINE -(C-52/DI,B-40/DI)
399 LINE (C+40/DI,B-86/DI)-(C+38/DI,B-92/DI):LINE -(C+42/DI,B-92/DI):LINE -(C+40/DI,B-86/DI):LINE -(C+40/DI,B-50/DI)
400 LINE (C+4/DI+.5,B-70/DI)-(C+6/DI,B-74/DI):LINE (C-4/DI+.5,B-70/DI)-(C-6/DI,B-74/DI):LINE (C,B-64/DI)-(C,B-60/DI):GOTO 490
490 IF EN=1 THEN EN=0:RETURN
491 DI=DI+1:GOTO 202
500 RANDOMIZE ABS(LN)-TX*10-TY*1000+IN*31.4
501 FOR X=1 TO 9:FOR Y=1 TO 9:DN%(X,Y)=0:NEXT:NEXT
510 FOR X=0 TO 10:DN%(X,0)=1:DN%(X,10)=1:DN%(0,X)=1:DN%(10,X)=1:NEXT
520 FOR X=2 TO 8 STEP 2:FOR Y=1 TO 9:DN%(X,Y)=1:DN%(Y,X)=1:NEXT:NEXT
530 FOR X=2 TO 8 STEP 2:FOR Y=1 TO 9 STEP 2
540 IF RND>.95 THEN DN%(X,Y)=2
541 IF RND>.95 THEN DN%(Y,X)=2
542 IF RND>.6 THEN DN%(Y,X)=3
543 IF RND>.6 THEN DN%(X,Y)=3
544 IF RND>.6 THEN DN%(X,Y)=4
545 IF RND>.6 THEN DN%(Y,X)=4
546 IF RND>.97 THEN DN%(Y,X)=9
547 IF RND>.97 THEN DN%(X,Y)=9
548 IF RND>.94 THEN DN%(X,Y)=5
549 IF RND>.94 THEN DN%(Y,X)=5
568 NEXT:NEXT
569 DN%(2,1)=0:IF IN/2=INT(IN/2) THEN DN%(7,3)=7:DN%(3,7)=8
570 IF IN/2<>INT(IN/2) THEN DN%(7,3)=8:DN%(3,7)=7
580 IF IN=1 THEN DN%(1,1)=8:DN%(7,3)=0
585 GOSUB 2000
590 RETURN
1000 GOSUB 60890:LINE (0,160)-(231,199),0,BF:LOCATE 21,1:PRINT "COMMAND? ";:GOSUB 60868
1001 X$=INKEY$:IF X$="" THEN 1001
1003 X=ASC(X$)
1004 IF LEN(X$)>1 THEN X2=ASC(MID$(X$,2)) ELSE X2=0
1030 IF X2=72 THEN ON SGN(IN)+1 GOTO 1100,1150
1040 IF X2=77 THEN ON SGN(IN)+1 GOTO 1200,1250
1050 IF X2=75 THEN ON SGN(IN)+1 GOTO 1300,1350
1060 IF X2=80 THEN ON SGN(IN)+1 GOTO 1400,1450
1070 IF X=13 THEN ON SGN(IN)+1 GOTO 1500,1550
1080 IF X=65 THEN ON SGN(IN)+1 GOTO 1600,1650
1081 IF X=32 THEN PRINT "PASS":GOTO 1090
1085 IF X=83 OR X=115 THEN 1700
1086 IF X=80 OR X=112 THEN IF PA=1 THEN PA=0:PRINT "PAUSE OFF":GOTO 1000
1087 IF X=80 OR X=112 THEN IF PA=0 THEN PA=1:PRINT "PAUSE ON":GOTO 1000
1089 PRINT "HUH?":GOTO 1000
1090 PW(0)=PW(0)-1+SGN(IN)*.9:IF PW(0)<0 THEN C(0)=0:PRINT:PRINT "YOU HAVE STARVED!!!!!":GOTO 1093
1091 LOCATE 22,30:PRINT "FOOD=";MID$(STR$(INT(PW(0)*10+0.5)/10),2);:GOSUB 60868:LOCATE 23,30:PRINT "H.P.=";C(0);:GOSUB 60868:LOCATE 24,30:PRINT "GOLD=";C(5);:GOSUB 60868:LOCATE 20,1
1092 PW(0)=INT(PW(0)*10)/10
1093 IF C(0)<=0 THEN 6000
1095 IF IN>0 THEN GOSUB 60890:LINE (0,160)-(231,199),0,BF:GOSUB 4000:IF C(0)<=0 THEN 1093
1096 LOCATE 22,30:PRINT "FOOD=";MID$(STR$(INT(PW(0)*10+0.5)/10),2);:GOSUB 60868:LOCATE 23,30:PRINT "H.P.=";C(0);:GOSUB 60868:LOCATE 24,30:PRINT "GOLD=";C(5);:GOSUB 60868:LOCATE 20,1
1097 IF IN=0 THEN GOSUB 100:GOTO 1000
1098 IF IN>0 THEN GOSUB 200:GOTO 1000
1100 PRINT "NORTH":IF TE%(TX,TY-1)=1 THEN PRINT "YOU CAN'T PASS THE MOUNTAINS":GOTO 1090
1110 TY=TY-1:GOTO 1090
1150 IF DN%(PX+DX,PY+DY)<>1 AND DN%(PX+DX,PY+DY)<10 THEN PX=PX+DX:PY=PY+DY
1155 PRINT "FORWARD"
1160 IF DN%(PX,PY)=2 THEN PRINT "AAARRRGGGHHH!!! A TRAP!":C(0)=C(0)-INT(RND*IN+3):MR=1:IN=IN+1:PRINT "FALLING TO LEVEL ";IN:GOSUB 500:GOSUB 60890:LINE (0,160)-(231,199),0,BF:GOTO 1090
1165 Z=0
1170 IF DN%(PX,PY)=5 THEN DN%(PX,PY)=0:PRINT "GOLD!!!!!":Z=INT(RND*5*IN+IN):PRINT Z;"-PIECES OF EIGHT":C(5)=C(5)+Z
1175 IF Z>0 THEN Z=INT(RND*6):PRINT "AND A ";W$(Z):PW(Z)=PW(Z)+1:GOTO 1090
1190 GOTO 1090
1200 PRINT "EAST":IF TE%(TX+1,TY)=1 THEN PRINT "YOU CAN'T PASS THE MOUNTAINS":GOTO 1090
1210 TX=TX+1:GOTO 1090
1250 PRINT "TURN RIGHT"
1255 IF DX<>0 THEN DY=DX:DX=0:GOTO 1090
1260 DX=-DY:DY=0:GOTO 1090
1300 PRINT "WEST":IF TE%(TX-1,TY)=1 THEN PRINT "YOU CAN'T PASS THE MOUNTAINS":GOTO 1090
1310 TX=TX-1:GOTO 1090
1350 PRINT "TURN LEFT"
1355 IF DX<>0 THEN DY=-DX:DX=0:GOTO 1090
1360 DX=DY:DY=0:GOTO 1090
1400 PRINT "SOUTH":IF TE%(TX,TY+1)=1 THEN PRINT "YOU CAN'T PASS THE MOUNTAINS":GOTO 1090
1410 TY=TY+1:GOTO 1090
1450 PRINT "TURN AROUND":DX=-DX:DY=-DY:GOTO 1090
1500 IF TE%(TX,TY)=3 THEN GOSUB 60080:GOSUB 60200:SCREEN 1:GOTO 1090
1510 IF TE%(TX,TY)=4 AND IN=0 THEN PRINT "GO DUNGEON":PRINT "PLEASE WAIT ":IN=1:GOSUB 500:DX=1:DY=0:PX=1:PY=1:GOTO 1090
1515 IF TE%(TX,TY)=5 THEN 7000
1520 PRINT "HUH?":GOTO 1000
1550 IF DN%(PX,PY)<>7 AND DN%(PX,PY)<>9 THEN 1580
1555 PRINT "GO DOWN TO LEVEL ";IN+1
1560 IN=IN+1:GOSUB 500:MR=1:GOTO 1090
1580 IF DN%(PX,PY)<>8 THEN PRINT "HUH?":GOTO 1090
1581 IF IN=1 THEN PRINT "LEAVE DUNGEON":IN=0:GOTO 1586
1584 PRINT "GO UP TO LEVEL ";IN-1
1585 IN=IN-1:GOSUB 500:MR=1
1586 IF IN=0 THEN PRINT "THOU HAST GAINED":PRINT LK;" HIT POINTS":C(0)=C(0)+LK:LK=0
1587 GOTO 1090
1600 GOTO 1090
1650 MN=0:DA=0:PRINT "ATTACK":PRINT "WHICH WEAPON ";:Q$=INPUT$(1)
1651 IF Q$="R" THEN DA=10:PRINT "RAPIER":IF PW(1)<1 THEN PRINT "NOT OWNED":GOTO 1650
1652 IF Q$="A" THEN DA=5:PRINT "AXE":IF PW(2)<1 THEN PRINT "NOT OWNED":GOTO 1650
1653 IF Q$="S" THEN DA=1:PRINT "SHIELD":IF PW(3)<1 THEN PRINT "NOT OWNED":GOTO 1650
1654 IF Q$="B" THEN DA=4:PRINT "BOW":IF PW(4)<1 THEN PRINT "NOT OWNED":GOTO 1650
1655 IF Q$="M" THEN PRINT "MAGIC AMULET":GOTO 1680
1656 IF Q$="B" AND PT$="M" THEN PRINT "MAGES CAN'T USE BOWS!":GOTO 1650
1657 IF Q$="R" AND PT$="M" THEN PRINT "MAGES CAN'T USE RAPIERS!":GOTO 1650
1659 IF DA=0 THEN PRINT "HANDS"
1660 IF DA=5 OR DA=4 THEN 1670
1661 MN=DN%(PX+DX,PY+DY)/10:MN=INT(MN)
1662 IF MN<1 OR C(2)-RND*25<MN+IN THEN PRINT "YOU MISSED":GOTO 1668
1663 PRINT "HIT!!! ":DA=(RND*DA+C(1)/5):MZ%(MN,1)=MZ%(MN,1)-DA
1664 PRINT M$(MN);"'S HIT POINTS=";MZ%(MN,1)
1665 IF MZ%(MN,1)<1 THEN PRINT "THOU HAST KILLED A ";M$(MN):PRINT "THOU SHALT RECEIVE":DA=INT(MN+IN):PRINT DA;" PIECES OF EIGHT"
1666 IF MZ%(MN,1)<1 THEN C(5)=INT(C(5)+DA):DN%(ML%(MN,0),ML%(MN,1))=DN%(ML%(MN,0),ML%(MN,1))-10*MN:MZ%(MN,0)=0
1667 LK=LK+INT(MN*IN/2):IF MN=TA THEN TA=-TA
1668 IF PA=1 THEN PRINT "-CR- TO CONT. ";:Q$=INPUT$(1) ELSE GOSUB 60890
1669 LINE (0,160)-(231,199),0,BF:GOTO 1090
1670 IF DA=5 THEN PRINT "TO THROW OR SWING:";:Q$=INPUT$(1):IF Q$<>"T" THEN PRINT "SWING":GOTO 1661
1671 IF DA=5 THEN PRINT "THROW":PW(2)=PW(2)-1
1672 FOR Y=1 TO 5:IF PX+DX*Y<1 OR PX+DX*Y>9 OR PY+DY*Y>9 OR PY+DY*Y<0 THEN 1662
1673 MN=DN%(PX+DX*Y,PY+DY*Y):MN=INT(MN/10):IF MN>0 THEN 1662
1674 NEXT:GOTO 1662
1680 IF PW(5)<1 THEN PRINT "NONE OWNED":GOTO 1650
1681 IF PT$="F" THEN Q=INT(RND*4+1):GOTO 1685
1682 PRINT "1-LADDER-UP","2-LADDER-DN":PRINT "3-KILL","4-BAD??":PRINT "CHOICE ";:Q$=INPUT$(1):Q=VAL(Q$):PRINT Q:IF Q<1 OR Q>4 THEN 1682
1683 IF RND>.75 THEN PRINT "LAST CHARGE ON THIS AMULET!":PW(5)=PW(5)-1
1685 ON Q GOTO 1686,1690,1691,1692
1686 PRINT "LADDER UP":DN%(PX,PY)=8:GOTO 1090
1690 PRINT "LADDER DOWN":DN%(PX,PY)=7:GOTO 1090
1691 PRINT "MAGIC ATTACK":DA=10+IN:GOTO 1672
1692 ON INT(RND*3+1) GOTO 1693,1695,1697
1693 PRINT "YOU HAVE BEEN TURNED":PRINT "INTO A TOAD!"
1694 FOR Z2=1 TO 4:C(Z2)=3:NEXT Z2:GOTO 1090
1695 PRINT "YOU HAVE BEEN TURNED":PRINT "INTO A LIZARD MAN":FOR Y=0 TO 4:C(Y)=INT(C(Y)*2.5):NEXT:GOTO 1090
1697 PRINT "BACKFIRE":C(0)=C(0)/2:GOTO 1090
1700 GOSUB 60080:CLS:PRINT "PRESS ENTER TO CONTINUE";:Q$=INPUT$(1):SCREEN 0:SCREEN 1:CLS:GOTO 1090
2000 NM=0:FOR X=1 TO 10
2005 MZ%(X,0)=0:MZ%(X,1)=X+3+IN
2010 IF X-2>IN OR RND>.4 THEN 2090
2020 ML%(X,0)=INT(RND*9+1):ML%(X,1)=INT(RND*9+1)
2030 IF DN%(ML%(X,0),ML%(X,1))<>0 THEN 2020
2040 IF ML%(X,0)=PX AND ML%(X,1)=PY THEN 2020
2050 DN%(ML%(X,0),ML%(X,1))=X*10
2051 MZ%(X,0)=1
2052 NM=NM+1
2055 MZ%(X,1)=X*2+IN*2*LP
2090 NEXT:RETURN
3087 LINE (C-28/DI,B-41/DI)-(C+30/DI,B-55/DI):LINE (C+28/DI,B-58/DI)-(C+22/DI,B-56/DI):LINE -(C+22/DI,B-53/DI):LINE -(C+28/DI,B-52/DI):LINE -(C+34/DI,B-54/DI):LINE -(C+20/DI,B-50/DI):LINE -(C+26/DI,B-47/DI)
3088 LINE (C+10/DI,B-58/DI)-(C+10/DI,B-61/DI):LINE -(C+4/DI,B-58/DI):LINE (C-10/DI,B-58/DI)-(C-10/DI,B-61/DI):LINE -(C-4/DI,B-58/DI):LINE (C+40/DI,B-9/DI)-(C+50/DI,B-12/DI):LINE -(C+40/DI,B-7/DI)
3089 LINE (C-8/DI,B-25/DI)-(C+6/DI,B-7/DI):LINE -(C+28/DI,B-7/DI):LINE -(C+28/DI,B-9/DI):LINE -(C+20/DI,B-9/DI):LINE -(C+6/DI,B-25/DI):GOTO 490
4000 FOR MM=1 TO 10:IF MZ%(MM,0)=0 THEN 4999
4010 RA=SQR((PX-ML%(MM,0))^2+(PY-ML%(MM,1))^2)
4011 IF MZ%(MM,1)<IN*LP THEN 4030
4020 IF RA<1.3 THEN 4500
4025 IF MM=8 AND RA<3 THEN 4999
4030 X1=SGN(PX-ML%(MM,0)):Y1=SGN(PY-ML%(MM,1))
4031 IF MZ%(MM,1)<IN*LP THEN X1=-X1:Y1=-Y1
4035 IF Y1=0 THEN 4045
4040 D=DN%(ML%(MM,0),ML%(MM,1)+Y1):IF D=1 OR D>9 OR D=2 THEN 4045
4042 X1=0:GOTO 4050
4045 Y1=0:IF X1=0 THEN 4050
4046 D=DN%(ML%(MM,0)+X1,ML%(MM,1)):IF D=1 OR D>9 OR D=2 THEN X1=0:GOTO 4081
4050 DN%(ML%(MM,0),ML%(MM,1))=DN%(ML%(MM,0),ML%(MM,1))-10*MM
4055 IF ML%(MM,0)+X1=PX AND ML%(MM,1)+Y1=PY THEN 4999
4060 ML%(MM,0)=ML%(MM,0)+X1:ML%(MM,1)=ML%(MM,1)+Y1
4080 DN%(ML%(MM,0),ML%(MM,1))=DN%(ML%(MM,0),ML%(MM,1))+10*MM
4081 IF X1<>0 OR Y1<>0 THEN 4999
4082 IF MZ%(MM,1)<IN*LP AND RA<1.3 THEN 4500
4083 IF MZ%(MM,1)<IN*LP THEN MZ%(MM,1)=MZ%(MM,1)+MM+IN
4499 GOTO 4999
4500 IF MM=2 OR MM=7 THEN 4600
4509 LOCATE 20,1:PRINT "YOU ARE BEING ATTACKED":PRINT "BY A ";M$(MM)
4510 IF RND*20-SGN(PW(3))-C(3)+MM+IN<0 THEN PRINT "MISSED":GOTO 4525
4520 PRINT "HIT":C(0)=C(0)-INT(RND*MM+IN)
4525 IF PA=1 THEN PRINT "-CR- TO CONT. ";:Q$=INPUT$(1) ELSE GOSUB 60890
4530 GOTO 4999
4600 IF RND<.5 THEN 4509
4610 IF MM=7 THEN PW(0)=INT(PW(0)/2):PRINT "A GREMLIN STOLE SOME FOOD":GOTO 4525
4620 ZZ=INT(RND*6):IF PW(ZZ)<1 THEN 4620
4630 PRINT "A THIEF STOLE A ";W$(ZZ):PW(ZZ)=PW(ZZ)-1:GOTO 4525
4999 NEXT:RETURN
6000 PRINT:PRINT:PRINT "        WE MOURN THE PASSING OF"
6005 IF LEN(PN$)>22 THEN PN$=""
6010 IF PN$="" THEN PN$="THE PEASANT"
6020 PN$=PN$+" AND HIS COMPUTER"
6030 LOCATE ,20-INT(LEN(PN$)/2):PRINT PN$
6035 PRINT "  TO INVOKE A MIRACLE OF RESURRECTION"
6040 PRINT "            <HIT ESC KEY>";
6050 IF INKEY$=CHR$(27) THEN 1
6060 GOTO 6050
7000 SCREEN 0:CLS
7010 IF PN$<>"" THEN 7500
7020 PRINT:PRINT:PRINT "     WELCOME PEASANT INTO THE HALLS OF":PRINT "THE MIGHTY LORD BRITISH. HEREIN THOU MAYCHOOSE TO DARE BATTLE WITH THE EVIL":PRINT "CREATURES OF THE DEPTHS, FOR GREAT":PRINT "REWARD!"
7030 PRINT:PRINT "WHAT IS THY NAME PEASANT ";:INPUT PN$
7040 PRINT "DOEST THOU WISH FOR GRAND ADVENTURE ? ";:Q$=INPUT$(1):IF Q$<>"Y" THEN PRINT:PRINT "THEN LEAVE AND BEGONE!":PN$="":PRINT:PRINT "        PRESS -SPACE TO CONT.";:Q$=INPUT$(1):GOTO 1090
7045 PRINT
7050 PRINT:PRINT "GOOD! THOU SHALT TRY TO BECOME A":PRINT "KNIGHT!!!":PRINT:PRINT "THY FIRST TASK IS TO GO INTO THE":PRINT "DUNGEONS AND TO RETURN ONLY AFTER":PRINT "KILLING A(N) ";:TA=INT(C(4)/3):PRINT M$(TA)
7060 PRINT:PRINT "    GO NOW UPON THIS QUEST, AND MAY":PRINT "LADY LUCK BE FAIR UNTO YOU.....":PRINT ".....ALSO I, BRITISH, HAVE INCREASED":PRINT "EACH OF THY ATTRIBUTES BY ONE!"
7070 PRINT:PRINT "         PRESS -SPACE- TO CONT.";:Q$=INPUT$(1):FOR X=0 TO 5:C(X)=C(X)+1:NEXT:CLS:GOTO 1090
7500 IF TA>0 THEN PRINT:PRINT:PRINT PN$;" WHY HAST THOU RETURNED?":PRINT "THOU MUST KILL A(N) ";M$(TA):PRINT "GO NOW AND COMPLETE THY QUEST!":PRINT:PRINT "       PRESS -SPACE- TO CONT.";:Q$=INPUT$(1):CLS:GOTO 1090
7510 PRINT:PRINT:PRINT:PRINT "AAHH!!......";PN$:PRINT:PRINT "THOU HAST ACOMPLISHED THY QUEST!":IF ABS(TA)=10 THEN 7900
7520 PRINT "UNFORTUNATELY, THIS IS NOT ENOUGH TO":PRINT "BECOME A KNIGHT.":TA=ABS(TA)+1:PRINT:PRINT "NOW THOU MUST KILL A(N) ";M$(TASK)
7530 GOTO 7060
7900 SCREEN 0:CLS:PRINT:PRINT:PRINT:PN$="LORD "+PN$:PRINT "           ";PN$;","
7910 PRINT "       THOU HAST PROVED THYSELF WORTHY":PRINT "OF KNIGHTHOOD, CONTINUE PLAY IF THOU":PRINT "DOTH WISH, BUT THOU HAST ACOMPLISHED":PRINT "THE MAIN OBJECTIVE OF THIS GAME..."
7920 IF LP=10 THEN 7950
7930 PRINT:PRINT "   NOW MAYBE THOU ART FOOLHEARTY":PRINT "ENOUGH TO TRY DIFFICULTY LEVEL ";LP+1
7940 GOTO 7070
7950 PRINT:PRINT "...CALL CALIFORNIA PACIFIC COMPUTER":PRINT "AT (415)-569-9126 TO REPORT THIS":PRINT "AMAZING FEAT!"
7990 GOTO 7070
50000 REM TEST MONSTERS (BY NANOCHESS)
50002 MC=1
50003 SCREEN 2,1:SCREEN 0
50004 SCREEN 1
50005 C=160:B=120:DI=1
50010 EN=1:GOSUB 270
50020 A$=INPUT$(1)
50025 MC=MC+1:IF MC<11 THEN 50003
50030 SCREEN 2,1:SCREEN 0
50040 END
60000 SCREEN 1:SCREEN 0:CLS:LOCATE 5:INPUT "TYPE THY LUCKY NUMBER.....";Q$:LN=VAL(Q$)
60005 LOCATE 7:INPUT "LEVEL OF PLAY(1-10)......";Q$:LP=INT(VAL(Q$))
60006 IF LP<1 OR LP>10 THEN 60005
60010 RANDOMIZE ABS(LN)
60020 DATA "HIT POINTS.....","STRENGTH.......","DEXTERITY......","STAMINA........","WISDOM.........","GOLD..........."
60025 DIM PW(5)
60030 DIM C$(5):FOR X=0 TO 5:READ C$(X):NEXT
60040 DIM C(5)
60041 DIM M$(10),ML%(10,1),MZ%(10,1)
60042 DATA "SKELETON","THIEF","GIANT RAT","ORC","VIPER","CARRION CRAWLER","GREMLIN","MIMIC","DAEMON","BALROG"
60043 FOR X=1 TO 10:READ M$(X):NEXT
60050 FOR X=0 TO 5:C(X)=INT(SQR(RND)*21+4):NEXT X
60060 CLS:LOCATE 8:FOR X=0 TO 5:PRINT C$(X);C(X):NEXT:PRINT:PRINT"SHALT THOU PLAY WITH THESE QUALITIES?":LOCATE ,20:LINE INPUT Q$:IF Q$<>"Y" THEN 60050
60061 LOCATE 15:PRINT:PRINT "AND SHALT THOU BE A FIGHTER OR A MAGE?":LOCATE ,20:LINE INPUT PT$
60062 IF PT$="M" OR PT$="F" THEN 60070
60063 GOTO 60061
60070 DIM W$(5):DATA "FOOD","RAPIER","AXE","SHIELD","BOW AND ARROWS","MAGIC AMULET":FOR X=0 TO 5:READ W$(X):NEXT
60075 GOSUB 60080:GOSUB 60200:RETURN
60080 SCREEN 0:CLS:PRINT:PRINT:PRINT "     STAT'S              WEAPONS":PRINT:FOR X=0 TO 5:PRINT C$(X);C(X);TAB(24);"0-";W$(X):NEXT
60081 LOCATE 11,18:PRINT "Q-QUIT"
60085 FOR Z=0 TO 5:LOCATE 5+Z,25-LEN(STR$(PW(Z))):PRINT PW(Z):NEXT
60090 LOCATE 17,5:PRINT "PRICE";:LOCATE ,15:PRINT "DAMAGE";:LOCATE ,25:PRINT "ITEM"
60100 FOR X=0 TO 5:LOCATE 19+X,25:PRINT W$(X);:NEXT X
60110 LOCATE 19,5:PRINT "1 FOR 10";:LOCATE,15:PRINT "N/A":LOCATE 20,5:PRINT "8";:LOCATE,15:PRINT "1-10":LOCATE 21,5:PRINT "5";:LOCATE,15:PRINT "1-5"
60120 LOCATE 22,5:PRINT "6";:LOCATE,15:PRINT "1":LOCATE 23,5:PRINT "3";:LOCATE,15:PRINT "1-4":LOCATE 24,5:PRINT "15";:LOCATE,15:PRINT "?????";:LOCATE 1,1
60130 RETURN
60200 LOCATE 13,1:PRINT"WELCOME TO THE ADVENTURE SHOP"
60210 GOSUB 60890:LOCATE 14,1:PRINT STRING$(120," "):LOCATE 14,1
60211 PRINT "WHICH ITEM SHALT THOU BUY ";:Q$=INPUT$(1):IF Q$="Q" THEN PRINT:PRINT "BYE":GOSUB 60890:SCREEN 0:CLS:RETURN
60215 Z=-1
60220 IF Q$="F" THEN PRINT "FOOD":Z=0:P=1
60221 IF Q$="R" THEN PRINT "RAPIER":Z=1:P=8
60222 IF Q$="A" THEN PRINT "AXE":Z=2:P=5
60223 IF Q$="S" THEN PRINT "SHIELD":Z=3:P=6
60224 IF Q$="B" THEN PRINT "BOW":Z=4:P=3
60225 IF Q$="M" THEN PRINT "AMULET":Z=5:P=15
60226 IF Z=-1 THEN PRINT Q$:PRINT "I'M SORRY WE DON'T HAVE THAT.":GOTO 60210
60227 IF Q$="R" AND PT$="M" THEN PRINT "I'M SORRY MAGES":PRINT "CAN'T USE THAT!":GOTO 60210
60228 IF Q$="B" AND PT$="M" THEN PRINT "I'M SORRY MAGES":PRINT "CAN'T USE THAT!":GOTO 60210
60230 IF C(5)-P<0 THEN PRINT "M'LORD THOU CAN NOT AFFORD THAT ITEM.":GOTO 60210
60235 IF Z=0 THEN PW(Z)=PW(Z)+9
60236 PW(Z)=PW(Z)+1:C(5)=C(5)-P
60237 LOCATE 10,16:PRINT C(5);"  "
60240 LOCATE 5+Z,25-LEN(STR$(PW(Z))):PRINT PW(Z);
60250 GOTO 60210
60868 CY=CSRLIN:CX=POS(0):IF CX>=39 THEN RETURN ELSE PRINT STRING$(39-CX," ");:LOCATE ,CX:RETURN
60890 X=TIMER
60891 IF TIMER-X<0.5 THEN 60891
60893 RETURN
60900 SCREEN 1:LINE (0,0)-(319,159),0,BF:RETURN

Notes on the MSX port

It's Microsoft BASIC, should it be easy? wrong!
In MSX BASIC there's no RANDOMIZE feature, it is same as AppleSoft RND, where a negative number as argument reinits random seed and a positive number generates next random number.
The INKEY$ returns directly the arrow codes simplifying that portion of code. Also you cannot use LOCATE/PRINT freely, you must open the graphical screen, setup cursor using PRESET and do PRINT #1.
Someone decided to change the order of arguments in LOCATE. While in GW-Basic the order is Row,Column based on 1 instead in MSX-Basic the order is Column,Row based on zero.
Last and not least, you cannot add rounding when accessing arrays or you'll access the next element, and the game screen is slightly smaller at 256x160 pixels instead of 280x160.
The only way to run this game in a real or emulated MSX is through a CAS file because the game doesn't fit with the disk operating system (it "eats" some RAM kilobytes). The CAS was generated by the very useful MSX CAS Packager and after loading it barely 3K are available for the in-game data.

Related links

Last modified: Feb/05/2019