(back to project page)

Caverns of Freitag Variables

In Applesoft, all variables have global scope. Strings, numeric variables, and arrays live in different namespaces however, so M$ and M$(0) are separate entities. All values are initialized to zero or the empty string if not set explicitly.

Var Description Initial Value
AA%(35)Monster attack damage (actual is (random 1-N) * 0.7).
ARNumber of arrows.12
AXPlayer position within window, X coord (0-9).1
AYPlayer position within window, Y coord (0-8).4
BHBase (max) hit points.125
BXMonster data ptr: X coordinate (170 bytes).16384
BTMonster data ptr: type (170 bytes).BY+170 (16724)
BYMonster data ptr: Y coordinate (170 bytes).BX+170 (16554)
C0Highest object number for monster.36
C2(never used)256
C9(never used)9
CXWindow position X coord (left 0-70).0
CYWindow position Y coord (top 0-71).35
DPDisplay mode: 0=hi-res, 1=text, 2=map.1
ELExperience Level: 1-9.1
ENExperience required for next level. Doubles every time you level up.25 * SL%
EPExperience points.0
GPGold pieces.
H4Low health warning (0-2); used to avoid repeating "you're dying" messages.
HH(35)Monster hit points (also experience points).
HPCurrent hit points.125
HWCurrent weapon: 1=sword, 2=bow.1
K9Map width.MY+1 (80)
KL%Total kills (not used).
M$Message to show.
M$(35)Monster names.
MH%(175)Monster hit points.
MLMap location, i.e. memory address where the map data is stored.40960 ($A000)
MSMagic sword (1-3), value indicates bonus.
MXMax map X coordinate.79
MYMax map Y coordinate.79
NMNumber of active monsters (max 169).110
NN$Player's character name (16 chars max).
O9Bool: set for important messages (dying, teleported, etc) that should appear on hi-res screen even when messages are disabled.
RN$(9)Rank names, displayed on the text screen Cannon Fodder, Stable Boy, etc.
RRRun-away counter. You get (24 - SL%) steps, after which the speed wears off and enemies get a 4-move burst.0
S2Bool: set to 1 when stuck to a mimic.
SHMagic shield (1-3), value indicates bonus.
SL%Skill level (1-9), selected by player.0
SMBool: Show Messages (when in hi-res mode)0
T0Previous contents of square we're standing on; holds C0+2 if we're standing on the Inn, otherwise 0.C0+2 (38)
TB?32704 ($7FC0)
TN%Total number of turns taken (not used).
XPlayer position, map X coordinate (CX+AX) (0-79).
YPlayer position, map Y coordinate (CY+AY) (0-79).
XLLowest AX value for local display (must scroll if lower).1
XRHighest AX value for local display (must scroll if higher).8
YLLowest AY value for local display (must scroll if lower).1
YRHighest AY value for local display (must scroll if higher).7
ZACommonly-used temp variable.0
ZWPlayer icon index (18=sword, 16/17/19/20=bow, 25=bird)0
ZXCommonly-used temp variable.0
ZYCommonly-used temp variable.0

Memory from $4000-41ff holds 3 bytes of state {X,Y,type} for up to 170 monsters. Slot 0 isn't used for a mob (a result of 0 from the "what monster did you hit" code means you hit a dragon part), so the actual limit is 169. This state is accessed by both Applesoft and CF.OBJ. $4000-40a9 holds the X coordinate, $40aa-4153 holds the Y coordinate, and $4154-41fd holds the type (same value stored in the map). One possible reason the limit of 170 monsters was chosen is that floor(512/3)=170.

The 80x80 map uses one byte per square ($a000-b8ff; PEEK(ML + Y * K9 + X)). The possible values are:

  1. empty
  2. wall
  3. player
  4. Serpent
  5. Electric Moth
  6. Mad Robot
  7. Burbleblort
  8. Griffin
  9. Flamebat
  10. Invisoid
  11. Thunderbug
  12. Coldcrystal
  13. Phoenix
  14. Mimic
  15. Healer
  16. Wizard
  17. (player, bow upward)
  18. (player, bow to left)
  19. (player, sword)
  20. (player, bow to right)
  21. (player, bow downward)
  22. (fuzzy worm?)
  23. (tiger?)
  24. (helmet?)
  25. (spider?)
  26. (player, bird mode)
  27. (flame ball?)
  28. (ant?)
  29. (blank)
  30. (coldcrystal #2?)
  31. Dwagon (upper left / head)
  32. Dwagon (upper middle)
  33. Dwagon (lower left)
  34. Dwagon (lower middle)
  35. Dwagon (upper right)
  36. Dwagon (lower right) (normalized value)
  37. (blank) [C0]
  38. chest [C0+1]
  39. the Inn [C0+2]
  40. "poof" (monster killed) [C0+3]

Entries in (parenthesis) aren't stored in the map, but the type index is used to access entries in the bitmap atlas. Types 21-24 and 26-27 appear to be monsters for which graphics were designed but they weren't included in the game.

Testing

If you want to do some tests without worrying about dying, try this:


Copyright 2020 by Andy McFadden