AKALABETH
=========
      by Richard Garriott
       1980 California Pacific Computer Company
       1998 Origin Systems
ZX Spectrum version by Battle Bunny, August-December 2016

Apple-II uses TEXT mode (24 rows * 40 cols)
           or HGR  mode (280*160 pixels with 4 text input rows at bottom);
and only the first two characters are significant in variable names.

FUNCTIONS
---------
DEF FN a(a$)=USR 65304
	Draw dungeon line graphic described in a$
DEF FN c()=FN p(23621)
	Get current program line number
DEF FN c$(c$)=CHR$ (CODE c$-(32 AND (c$>="a" AND c$<="z")))
	Make character in c$() upper case.
DEF FN d$(c$)=CHR$ (CODE c$-95+(111 AND c$=" ")):
	Calculate dungeon line graphic code from CHR$ code
DEF FN e$(c$)=CHR$ 16+CHR$ ((CODE c$-143+(111 AND c$=" ") OR c$>"{F}")+(6 AND c$>"{F}"))+c$
	Calculate dungeon map graphic code from CHR$ code
DEF FN g()=FN p(FN p(23613)+2)
	Get GO SUB return line number
DEF FN i(c$)=1+(VAL "06612345666"(VAL c$+2 OR la<=0) OR mi)
	Calculate colour for dungeon line graphic
DEF FN n(n)=INT (n+0.5) AND n>0
	Round number to nearest integer; reset to zero if -ve.
DEF FN p(a)=PEEK a+256*PEEK (a+1)
	PEEK a 16-bit integer from addresses a,a+1.
DEF FN q()=INT (SQR RND*21+4)
	Calculate a random stat
DEF FN r(a)=191
	GO SUB line to emulate Apple-II RND function.
DEF FN s$(t$)=VAL$ (("FN c$(t$)+FN s$(t$(2 TO))" AND LEN t$>1)+("FN c$(t$)" AND LEN t$=1))
	Make text in t$() all upper case.
DEF FN v()=FN p(23641)-1-FN p(23627)
	Get size of VARS area
DEF FN x(x)=(12-x AND x<12)+x+(267-x AND x>267): HPLOT -> PLOT
	Convert a 280-col X-HPLOT coord to a 256-col X-PLOT coord
DEF FN d(x,d)=x-(d AND d<0)-(d-255 AND d>255)
	Convert a 280-col X-TO coord to a 256-col X-DRAW coord
DEF FN z(r$)=8100
	GO SUB line to print r$ text in lower screen; scroll if needed.


NUMERIC CONSTANTS
-----------------
axm              139 Apple-II X coordinate mid-point
axx              279 Apple-II X coordinate maximum
aym              79  Apple-II Y coordinate mid-point
azx              0.91397849 (=255/279) dungeon PoV X-axis conversion ratio
C8,CM            800,1000
DEFA             23563 DEFADD
DATD             23639 DATADD
HGR              75 sub-routine line
HOME             80 sub-routine line
O,N,Q,B,R,V      0,1,2,3,4,5
k6,k7,k8,k9      6,7,8,9
kA,kB,kC,kD,kE   10,11,12,13,14
 F, G, H, I, J   15,16,17,18,19
w0,1,2,3,4,5,8   20,21,22,23,24,25,28
h0,h2,h3         30,32,33
F0,F5,L0,L8,R0   40,45,50,58,60
m0               150
INKD             18 sub-routine line
p2,p3,p4,p5      65532,65533,65534,65535 (text window parameters)
SEED             23670 SEED
TEXT             85 sub-routine line
VARS             23627 VARS

NUMERIC ARRAYS
--------------
* All screen coordinate values in data arrays & BASIC statements have been
  adjusted for the Spectrum in PLOT & DRAW statements thus:
     PLOT FN x(X)-12,175-Y
     DRAW FN d(X,PEEK 23677+X),-Y
where "PEEK 23677" is the last X-plot and:
     DEF FN x(x)=(12-x AND x<12)+x+(267-x AND x>267)
     DEF FN d(x,d)=x-(d AND d<0)-(d-255 AND d>255)
  As on the Spectrum Y=0 at the bottom and on the Apple-II Y=0 at the top,
  adjustments to Y have opposite signs.
* An Apple-II   array element with DIM 'A' rows has 'A+1' rows numbered 0->A.
* A ZX Spectrum array element with DIM 'Z' rows has 'Z'   rows numbered 1->Z.

USED:	a,B,c,d,e,F,G,H,I,J,k,L,m,n,O,p,Q,R,s,t,u,V,W,X,Y,Z
FREE:

ZX Spectrum  /   Apple-II
-----------      --------
c(9,3)  {    C(5)  player's stats (range 4->24)
  c,1 = {val.1=HP,2=strength,3=dexterity,4=stamina,5=wisdom,6=gold,7=lamp,8=compass,9=map
(merged){    PW   (5)     player's inventory
  c,2 = {qty.1=rapier,2=axe,3=shield,4=bow,5=amulet,6=food,7=oil,8=arrows,9=arrow hits
  c,3 = {val.damage: 1,2,3,4,5, 6=weapon types carried (0-5),9=axe throw hits

e(min.5)         available dungeon level map codes

NUMERIC VARIABLES
-----------------
a                value returned from a USR call
dam              weapon damage
db               debug flag (infy HP, infy food)
dbase,dsize      start address of DATA block, size of a DATA block element
DFSZ             PEEK 23659 (DF_SZ)
di               distance (0->9)
dc,dr            facing direction; +/-1c=right/left, -/+1r=up/down
eat              rate of food consumption
en               flags the end of a dungeon PoV graphic display loop
hr1,hr2          compass pointers
huh              key input error flag
ID               current dungeon level map ID
io               dungeon level (0=outside)
ir,ic            row,col used in movement calculations
key              value returned by INKEY$
la,co,ma         lamp,compass,map quantity/status; corresponding to c([789],1)
                 (0=none, -n=not in use; +n=in use)
lk               level HP bonus
ln               lucky number (RND seed)
lp               level of play (difficulty)
lz               length of a string
m                screen mode: 2=TEXT, 0=HGR
mi               set to 'mn' of nearest visible creature (else 0)
mn               m$(creature) code in v$() (2nd UDG bank: "A"-"J")
nm               number of creatures
pa               pause on/off flag
pi               INK colour for player's icon
price            item price at shop
pr,pc            dungeon row,col coords
pt               location ID (row*length+col) for movement check
qr,qc            current row,col width in q$()
sold,snew        old,new SEED address of value
task             m$() row number of creature to kill
tr,tc; tk; te    terrain r,c coords; object code at t$(tr,tc); elements#
VC; VN, VS       game stage; size of initial,current VARS area
x1,x2            temp x coord storage
y1,y2,y3,y4      temp y coord storage
zlo,zhi          FN z(z$) parameter address
W,Z              temp storage
ww,w$            selected weapon code number,letter

d,k,p,s,t,u      FOR...NEXT control variables

USED:	a$(),c$(1),d$(),e$(),f$(10),g$(4),h$(),i$(1),j$(),k$(),
	l$(1),m$(),n$,o$,p$(1),q$(),r$(1),s$(),t$(),u$(),v$(),w$,x$,y$,z$
FREE:	b$
STRING ARRAYS
-------------
The notes above relating to numeric arrays also apply to string arrays.
a$(19*19*2)         array of dungeon coordinates (row,col)
d$(11,11) INT DNG% (10,10) complete dungeon map (aka.DN%)
e$(11,11*3)                explored dungeon map
v$(11,11)                  creature location map
              0=clear,1=wall,2=trap,3=concealed doorway,4=doorway,5=gold,6=n/a,7=ladder DOWN,8=ladder UP,9=trapdoor
h$(2,15)             compass points
  clockwise  3  W  7  S  1  N  5  E  9 & repeat ...
  start      1  N  3  W  5  E  7  S  9
  anticwise  5  E  1  N  7  S  3  W  9 & repeat ...
k$(13)              key string "7856XAZPSLCM"+"{E2}" ($E2="STOP")
                    (positions) 123456789ABC

m$(10,17+2+3) M$(10) creature descriptions (row 0 not used)
            (extra 2 bytes hold start&end of name pointers)
              1=Skeleton,2=Thief,3=Giant Rat,4=Orc,5=Viper,6=Carrion Crawler,7=Gremlin,8=Mimic,9=Daemon,10=Balrog
        {INT ML%  (10,1)  creature 'v$' dungeon location (row,col)
(merged){INT MZ%  (10,1)  creature 'v$' H.P.

o$(32)              32 spaces
q$(4,32)            saved lower screen
s$(2,9,14+2){ C$(5) stats descriptions (row 0 used)
            { 1=HP,2=strength,3=dexterity,4=stamina,5=wisdom,6=gold,7=lamp,8=compass,9=map
  (merged)  { W$(5) inventory item descriptions (row 0 used)
            { 1=rapier,2=axe,3=shield,4=bow,5=amulet,6=food,7=oil,8=arrows
            (extra 2 bytes hold start&end of name pointers)
t$(21,21) INT TE% (20,20) terrain map  (aka.TER%)
u$(21,21*3)   0=clear, 1=mountains, 2=refuge, 3=town, 4=dungeon, 5=castle
              (t$()=CHR$ codes, u$())=CHR$ & ATTR codes)

STRING VARIABLES
----------------
c$(1),l$(1),r$(1) d$() contents of 3 facing squares at 'di'[stance]
                 (1st UDG bank: "K"-"T")
i$(1)            INPUT character
n$               player's name
p$(1)            player's type ("F"ighter or "M"age)
w$,x$,y$,z$      text strings


-----------
end of file
-----------