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

AKALABETH_ZX48gd is the final full release version, which has all of my intended enhancements and has been speeded up enough so that it now plays reasonably well at normal Spectrum emulation speed. To reduce the size and increase the speed I discarded all of the code, tables and data relating to run-time calculation of graphics coordinates, replacing them with tables of pre-calculated coordinates.

In the BASIC listings, these encodings are recognised by the loader:
{00}-{FF} converted to corresponding hex byte
          eg. VAL "{BA}({BB}{A5}*21+4)" becomes VAL "INT (SQR RND*21+4)"
{A}-{U}   converted to corresponding UDG character
The loader merges the program in three parts, lines 3-362, 701-799 and 800-9999, as the text listing is too big (82kb) to load in one go. Refer to documentation in TXT2Emu.ZIP for a full explanation of the loader.
(The loader is only needed if loading from .BAS files, not .TAP or .Z80.)

Some sections of the code cannot be LISTed as they hold graphics data. These are: 41-45, 53, 110-157, 700-799, 9990-9991 . Refer to the .BAS listings for the content of these sections. I've discarded the Apple-II/ZX Spectrum composite listing, as the code for this final version has changed so substantially from the original that there's not much basis for comparison (although it looks & plays much the same).

Typical RAM stats are:
PROG size= 34,873; VARS size= 5077; free RAM= 1,390.

Suggestions for enhancements and any error reports can be sent to:
	withinthehills@gmail.com

New features
------------
+ New inventory items: arrows, oil, lamp, compass, map
+ Sometimes find maps, arrows, oil in chests.
+ Overlaid map & compass displays (optional, if in inventory)
+ Bow needs arrows; Lamp needs oil; Map & Compass need Lamp in dungeon.
+ Don't refresh the display when the player hasn't moved or turned
 (eg. move blocked by mountains or a wall, or during combat).
+ Z=auto-attack on/off (non-magic only)
+ Attack will auto-select weapon if there's only one (or Fists if none).
+ Give "Fists" a damage rating of 0.5 .
+ Use STOP (SymbolShift+A) key to quickly exit game.
+ Use different graphics/colours for human/toad/lizardman on dungeon map.
+ Make use of Stamina (c(4,1)) & Wisdom (c(5,1)) (see "Formulae").
+ Show dungeon elements (walls, etc.) in different colours.
+ The red INK used for creatures overrides other colours in the display.
+ Type a '?' for a list of the option letters for the current prompt.
+ Synchronise game/RND sequence via "lucky number".
+ Level preview map is shown while level is being constructed.
+ Add a "Sell" option to the shop (SymbolShift+Letter).
+ Show 'task' (target creature assigned by Lord British) on Status screen.

Keys (in Play)
----
Apart from the four direction keys and when typing in a number, selections just need a single keypress of the capitalised letter in the option text (eg. "Magic amulet" = M, "lamp Oil" = O). Type a '?' (SymbolShift+C) to see the available option keys for the current prompt.
5,6,7,8    (overground) west,south,north,east
5,6,7,8    (underground)left,reverse,forward,right
X          (overground) enter dungeon/town/castle/refuge (if outside same)
X          (overground) suspend game & return to menu (from Refuge point)
X          (underground)leave dungeon (if at a level 1 UP ladder)
X          (underground)go up/down 1 level  (if at an UP/DOWN ladder)
X          (underground)go    down 1 level  (if at a trapdoor)
A          attack (creature, underground)
S          player's stats & inventory
Z          auto-attack on/off (non-magic only)
P          pause on/off (when 'on', pauses after each combat round)
new inventory items
C          compass on/off (requires oil & lit lamp when underground)
L          lamp on/off    (automatic on entering/leaving dungeons)
M          map on/off     (requires oil & lit lamp when underground)
new shop items
O          oil (for lamp)
A          arrows (for bow)
STOP       (SymbolShift+A, from anywhere) abandon game & return to menu

* The dungeon layouts are determined by the "lucky number", the overground location of the entrance, and the dungeon level within that location. Leaving and then re-entering a level will rebuild that level, its layout & occupants remaining the same.
* The overground layout and starting location are determined by the "lucky number" alone.
* A lit lamp uses up oil at half the rate that food is used up.
* You can move around the dungeons without having a lit lamp, but the map & compass won't be available, the map won't be updated, dexterity will be halved and the display will be darker.
* A dungeon map will be updated as long as there is oil in the lamp; it's not necessary to have the map 'on' (visible) all of the time while on the dungeon levels.
* Dungeon maps are keyed to the dungeon+level on which they were first opened. A map for a level will only be available if either you have one which was previously used on that level, or you have one which hasn't been used at all.
* The game uses two banks of UDGs for the overground and underground maps, held in lines 9991 & 9990 respectively of the program listing.
* Arrows (and thrown axes) which have hit a creature are automatically retrieved if it is killed, otherwise they are lost.
* The "MIRACLE OF RESURRECTION" restores your character with no gold and random food, H.P., oil.
* When the compass is open underground, some extra location information is shown in the stats area:
  + level number (1st number);
  + row/col position & facing within level (2nd&3rd numbers, (1,1) at top left)   The row/col facing may be one of; -, ~, +; one of the facings will be '-' or '+' and the other will be '~'. The row facing is '-' for North and '+' for South; the col facing is '-' for West and '+' for East.


Keys (in new Menu)
----

Initial Menu Options
--------------------
I          Init    Set up the data tables for a new game
L          Load    Load a saved game
Q          Quit    Leave the game

Extra Menu Options (available after Init/Load)
------------------
S          Save    Save the current game
P          Play    Start a new game (after Init) or resume the current game

To return to the menu from the game you need to be at a Refuge point (the
small squares overground), then press X. (These squares had no function in
the original game.)

The game state is preserved on Quit, so Quit-RUN-Play will put you back in
the game where you were before. After BREAK/error this can be done manually
with "GO TO 9505", then RUN-Play. To unprotect the game (ie. to make the VARS
area visible and thus vulnerable to RUN/CLEAR), type "GO SUB 9510". To show
the current RAM usage, type "GO SUB 9500". (If PROG is around 39,000+ and
VARS is zero then VARS is there but hidden at the end of PROG.)

NOTE: This feature, which works on a real Spectrum, might break some emulators (because of the apparent gap between the end of the PROG space and the start of the VARS space). If this happens, remove the POKEs in lines 27 & 9511 and don't use the SAVE or LOAD options.

For (virtually) infy HP/food enter "debug" as your name when you first meet Lord British. (Up until then you'll just have to tough it out.)

Formulae
--------
Use of Food (c(4,1) = Stamina)
(Apple-II): PW(0)=PW(0)-1+SGN (INOUT)*.9: PW(0)=INT (PW(0)*10)/10
so 10 units of food would last 10 moves overground, 90 moves underground
(Spectrum): c(6,2)=c(6,2)-0.5+SGN io*0.4):
so 10 units of food would last 20 moves overground, 90 moves underground
Changed to:
(Spectrum,overground) : c(6,2)=c(6,2)-(0.65-c(4,1)/100)
(Spectrum,underground): c(6,2)=c(6,2)-(0.175-c(4,1)/200)

Use of Oil (new)
(Spectrum): c(7,2)=c(7,2)-(0.5+SGN io*0.4)/2

Creature HP
(Apple-II): MZ%(X,1)=X*2 + INOUT*2*LP
(Spectrum): m(u,k3)=u*2 + io*2*lp

Dungeon Experience (converted to extra HP when leaving dungeon)
(Apple-II): LK=LK+INT (MN*INOUT/2)
(Spectrum): lk=lk+INT (mn*io/2+0.5)

Attack Miss by Player IF ... (c(3,1) = Dexterity)
(Apple-II): IF MN<1 OR C(2) - RND(1)*25 < MN+INOUT
(Spectrum): IF mn<1 OR c(3,1)/(2 OR la>0) -RND*20 < mn+io

Attack Hit Damage to Creature (c(2,1) = Strength)
(Apple-II): IF cond ...DAM=literal ... DAM=(RND(1)*DAM + C(1)/5)
(Spectrum): LET dam=c(u,3): ... dam=RND*dam+c(2,1)/5

Attack Miss by Creature IF ... (c(3,2)=Shield, c(4,1)=Stamina)
(Apple-II): RND(1)*20 - SGN(PW(3)) - C(3)+ MM+INOUT < 0
(Spectrum): RND*20 - SGN c(3,2) - c(4,1)+ MN+io < 0

Attack Hit Damage to Player (c(1,1) = H.P.)
(Apple-II): C(0)=C(0)-INT (RND(1)*MM + INOUT)
(Spectrum): c(1,1)=c(1,1)-INT (RND*MN + io)

Magic Attack Damage to Creature (c(5,1) = Wisdom)
(Apple-II): DAM = 10 + INOUT
(Spectrum): dam = c(5,1)/2 + io

----------
BB, Dec'16

Changes 1.Jun'17
   4 Removed redundant "DEF FN p$(p,q)".
  12 Changed the title slightly.
  17 Shortened keys display so that it doesn't extend into stats box.
 890-891 Stopped surviving creatures from following player down levels.
 907 Simplified the location info display in the stats box.
4507 Shortened Gremlin message so that it doesn't extend into stats box.

Regarding your question, this works as per the original game, which did not keep any level history, as explained in the release notes. * The dungeon layouts are determined by the "lucky number", the overground location of the entrance, and the dungeon level within that location. Leaving and then re-entering a level will rebuild that level, its layout & occupants remaining the same.

Here's the correction for the subscript error. (The first option, as it was the easiest to do and was consistent with the original game.)
[code]
890	LET nm=O:
	FOR u=N TO kA:
		IF m$(u,w0 TO w1) <> CHR$ O+CHR$ O THEN
 			LET v$(CODE m$(u,w0),CODE m$(u,w1))=" "
891		IF VAL "u-3>io OR FN r(1)>0.4" THEN
			LET m$(u,w0 TO)=CHR$ O+CHR$ O+CHR$ O: NEXT u:
			RETURN
[/code]
The 'O' is a capital letter 'O'.

There's a few minor cosmetic changes to go in as well (see AKALABETH_ZX48ge_changes.TXT). (I'll update the archive in the next day or  two.)

The display now looks like this:
http://www.users.globalnet.co.uk/~jg27paw4/pourri/akalabeth_zx48gd-shoppe+l3.gif
If you're wondering where the Carrion Crawler is, it's in the hidden passage to the player's right.