; © 2014-2019, 2021, 2022, 2025, 2026 Richard Dymond (rjdymond@gmail.com)

[Fact:tunes:Tunes]
The tune played on the title screen is <i>The Blue Danube</i> by Johann Strauss
II. The tune played during gameplay is <i>In the Hall of the Mountain King</i>
by Edvard Grieg.

[Fact:takingABreak:Taking a BREAK]
The game quits if BREAK - that is, CAPS SHIFT and SPACE - is pressed (see
#R34801).

[Fact:6031769:6031769]
If you type the digits 6031769 at any point during the game, a cheat mode is
activated that enables Willy to teleport to any cavern; a boot appears next to
Willy's remaining lives to show that the cheat mode has been activated.

For example, to teleport to #R51200(The Vat), hold down keys '2' and '3', and
then press '6' to activate the teleporter. For a list of all the caverns and
their teleport codes, see the #LINK(Caverns)(Caverns page).

The number 6031769 comes from Matthew Smith's driving licence, "with an error
in it and twisted round a bit" (as he put it in an interview for issue 48 of
<i>Retro Gamer</i> magazine).

[Fact:stuckOn16:Stuck on 16]
In #R60416(The Sixteenth Cavern), Willy can get stuck if he enters the area
below the portal before collecting all the items outside that area:

#PUSHS
#POKES61045,255
#UDGTABLE { #WILLY15,12,56,4,10,4,9,6(stuck_on_16) } TABLE#
#POPS

If that happens, he will have to wait until the air runs out before getting a
second chance to escape from the cavern.

See also #FACT(noWayOut)().

[Fact:noSwordfishForCheats:No swordfish for cheats]
The game ending - with Willy above ground and the portal in #R64512(The Final
Barrier) changed to the #R45792(swordfish) graphic - is not shown if
#FACT(6031769)(cheat mode) is activated (see #R36919).

[Fact:unusedCrumblingFloor:Unused crumbling floor]
The crumbling floor tile in #R58368(Skylab Landing Bay) is unique to that
cavern, and also not used.

#UDGTABLE { #UDG58931,2(crumbling_floor_13) } TABLE#

To place a couple of these tiles in the cavern in order to see them crumble:

POKE 58811,10: POKE 58812,10: POKE 58930,10

[Fact:unusedConveyors:Unused conveyors]
Every cavern definition contains a conveyor definition, and every conveyor has
non-zero length and is animated by the routine at #R37125. But there are two
caverns in which the conveyor is hidden or otherwise unusable.

The first unused conveyor is of length 1, defined at (0,19) in #R54272(The
Endorian Forest) (see #R54895). Instead of a conveyor, the space is occupied by
a background tile.

To show the conveyor:

POKE 54291,67

#UDGTABLE(gallery)
{ #CAVERN9,11,0,16,8,0(uc1_before) |
  #PUSHS
  #POKES54291,67
  #CAVERN9,11,0,16,8,6(uc1_after)
  #POPS }
{ Before | After }
TABLE#

The other unused conveyor is of length 3, defined at (9,7) in
#R62464(Amoebatrons' Revenge) (see #R63087). Instead of a conveyor, the space
is occupied by a platform, whose third row of pixels is animated as if it were
a conveyor (which is a #BUG(animatedPlatform)(bug)).

To replace the platform with conveyor tiles:

POKE 62759,4: POKE 62760,4: POKE 62761,4

#UDGTABLE(gallery)
{ #CAVERN17,0,5,16,8,2(uc2_before) |
  #PUSHS
  #POKES62759,4,3
  #CAVERN17,0,5,16,8,6(uc2_after)
  #POPS }
{ Before | After }
TABLE#

Note that this conveyor moves left to right, and so if it were activated it
would make the cavern unfinishable. To make the conveyor move right to left:

POKE #R63087(63087),0

[Fact:thePersistentItem:The persistent item]
The item below the portal in #R60416(The Sixteenth Cavern) does not disappear
if Willy leaves it till last and collects it by falling on it from above. The
reason for this is that the portal is opened as soon as Willy collects the
item, and the screen is not refreshed before he moves on to the next cavern.

#UDGTABLE { #CAVERN15,10,4,9,6,0(persistent_item) } TABLE#

[Fact:lightLogic:Light logic]
At times it might seem as if the light beam in #R63488(Solar Power Generator)
moves around at random, but in fact its movements are predictable and always
follow these simple rules (see #R36211):

#LIST
{ start travelling vertically downwards from the top of the cavern }
{ stop if a floor or wall is in the way }
{ change direction between vertically downwards and horizontally to the left if
  a guardian is in the way }
LIST#

In addition, for every frame that the light beam is in contact with Willy, the
air supply is reduced by an extra eight or twelve units - four for each of the
two or three cells of Willy's sprite that the beam touches - making nine or
thirteen units in total. For every eight units of air consumed, one vertical
line of pixels is removed from the right end of the air bar (see #R35388).

[Fact:topHalfTwice:Top half twice]
When #R64512(The Final Barrier) is drawn to the screen buffer at #R28672, the
graphic data for the top half of the cavern (at #R40960) is copied twice: once
after the first (pointless) run through the loop at #R35468, and again after
the second run through the loop has drawn the bottom half of the cavern.

[Fact:bottomHalfTwice:Bottom half twice]
After Willy has jumped through the portal in #R64512(The Final Barrier) to the
ground above, and the celebratory sound effect and colour-cycling effect have
finished, the bottom half of Willy's sprite can be seen dangling below the
swordfish graphic (where the portal was) while the remaining air supply
decreases to zero.

#UDGTABLE {
  #CFRAME19
  #COPY(18,1,4,8,2)(19,bht)
  #SFRAME(33376,1)(willy)
  #OVER(1,1,,,2)($f)(bht,willy)
  #OVER(1,5,,,2)($f)(bht,willy)
  #SFRAME(45792,1)(swordfish)
  #OVER(1,4,,,2)($f)(bht,swordfish)
  #UDGARRAY(4,1)(15616x32)(*blue)
  #OVER(0,0,,,1)($f)(bht,blue)
  #FRAMES(bht)({ScreenshotImagePath}/bottom_half_twice)
} TABLE#

This happens because the section of code at #R36926 draws Willy above ground,
but does not remove him from the portal entrance. And although his residual
bottom half is hidden briefly by setting the appropriate attribute values to 0
(INK 0: PAPER 0), it is left on display with an attribute value of 1 (INK 1:
PAPER 0) after the colour-cycling effect has finished.

[Fact:itemGraphics:Item graphics]
The commonest item graphic is the key, which appears in #R45056(Central
Cavern), #R47104(The Menagerie), #R48128(Abandoned Uranium Workings),
#R50176(Processing Plant), #R51200(The Vat), #R53248(Wacky Amoebatrons),
#R61440(The Warehouse), #R62464(Amoebatrons' Revenge), #R63488(Solar Power
Generator) and #R64512(The Final Barrier).

#UDGTABLE { #UDG45748,3(item00) } TABLE#

Next is the banana, which appears in #R52224(Miner Willy meets the Kong Beast)
and #R56320(Return of the Alien Kong Beast):

#UDGTABLE { #UDG52916,3(item07) } TABLE#

The other eight caverns have their own unique item graphics:

#UDGTABLE(gallery)
{ #R46080(The Cold Room)                   | #UDG46772,11(item01) }
{ #R49152(Eugene's Lair)                   | #UDG49844,19(item04) }
{ #R54272(The Endorian Forest)             | #UDG54964,3(item09) }
{ #R55296(Attack of the Mutant Telephones) | #UDG55988,3(item10) }
{ #R57344(Ore Refinery)                    | #UDG58036,3(item12) }
{ #R58368(Skylab Landing Bay)              | #UDG59060,11(item13) }
{ #R59392(The Bank)                        | #UDG60084,3(item14) }
{ #R60416(The Sixteenth Cavern)            | #UDG61108,3(item15) }
TABLE#

[Fact:itemCounts:Item counts]
Thirteen of the twenty caverns have a full set of five items.

#R52224(Miner Willy meets the Kong Beast), #R58368(Skylab Landing Bay) and
#R60416(The Sixteenth Cavern) each have four items.

#R59392(The Bank) and #R63488(Solar Power Generator) both have three items.

There are no caverns that have exactly two items.

#R53248(Wacky Amoebatrons) and #R62464(Amoebatrons' Revenge) both have only one
item.

[Fact:extraItems:Extra items]
#R59392(The Bank) has five items defined, but only three of them are used;
#R60416(The Sixteenth Cavern) also has five items defined, but only four of
them are used.

The two extra items in #R59392(The Bank) are at (6,19) and (13,30), shown here
in bright white:

#PUSHS
#POKES60036,71;60041,71
#UDGTABLE { #CAVERN(14,flags=5)(the_bank_extra_items) } TABLE#
#POPS

The extra item in #R60416(The Sixteenth Cavern) is at (5,26) - in the path of
the cyan guardian - shown here in bright white:

#PUSHS
#POKES61065,71;61140,188
#UDGTABLE { #CAVERN(15,flags=5)(the_sixteenth_cavern_extra_items) } TABLE#
#POPS

[Fact:fastestGuardians:The fastest guardians]
There are three guardians that move four pixels up or down every frame - faster
than any other guardians in the game: the white Skylab in #R58368(Skylab
Landing Bay), the magenta guardian in #R61440(The Warehouse), and the cyan
guardian in #R62464(Amoebatrons' Revenge).

[Fact:guardianColours:Guardian colours]
The most common guardian colour is yellow (21 instances), and the least common
colour is black (only one instance, in #R49152(Eugene's Lair)).

As for the other colours, there are 3 blue guardians, 10 red guardians, 12
magenta guardians, 13 green guardians, 14 cyan guardians, and 5 white
guardians.

[Fact:guardianCounts:Guardian counts]
The cavern with the most guardians is #R62464(Amoebatrons' Revenge), which has
eight (the maximum).

The cavern with the least guardians is #R45056(Central Cavern), which has only
one.

[Fact:guardiansNeedAClearPath:Guardians need a clear path]
The guardian-drawing code kills Willy if a guardian collides with anything
that's already been drawn in the cavern. This means, for example, that Willy is
killed if a guardian hits a nasty, a wall or the floor.

See this happen by placing a wall block in the path of the guardian in
#R45056(Central Cavern):

POKE 45327,22

[Fact:wrongFoot:Off on the wrong foot]
In some caverns, Willy starts off facing the wall, and so has to turn round
before navigating his way out:

#UDGTABLE(gallery)
{ #CAVERN12,26,12,6,4(wrong_foot1) |
  #CAVERN13,26,12,6,4(wrong_foot2) |
  #CAVERN16,0,2,6,4(wrong_foot3) }
{ #R57344(Ore Refinery) |
  #R58368(Skylab Landing Bay) |
  #R61440(The Warehouse) }
TABLE#

To make Willy start off facing the other way:

#PUSHS
#POKES57962,1;58986,1;62058,0
#UDGTABLE(gallery)
{ #CAVERN12,26,12,6,4,5(wrong_foot4) |
  #CAVERN13,26,12,6,4,5(wrong_foot5) |
  #CAVERN16,0,2,6,4,5(wrong_foot6) }
{ POKE #R57960(57962),1 | POKE #R58984(58986),1 | POKE #R62056(62058),0 }
TABLE#
#POPS

[Fact:variableAirSupply:Variable air supply]
The initial air supply varies from cavern to cavern by small amounts, because
of differences in the initial value of the game clock at #R32957 - #b128,
#b240, #b248 or #b252 - which is copied from byte #N701,,,1(0x) of the cavern
definition.

The caverns with the greatest initial air supply are #R45056(Central Cavern),
#R46080(The Cold Room), #R57344(Ore Refinery), #R59392(The Bank) and
#R64512(The Final Barrier), which initialise the game clock to #b252.

Next are #R54272(The Endorian Forest), #R58368(Skylab Landing Bay) and
#R60416(The Sixteenth Cavern), which initialise the game clock to #b248.

Then it's #R63488(Solar Power Generator), which initialises the game clock to
#b240.

The other 11 caverns initialise the game clock to #b128, which means the cell
at the right end of the air bar in those caverns starts off with only three
white pixel columns instead of seven.

[Fact:repeatingCaverns:Repeating caverns]
There are six caverns in which the guardians all return to their original
locations at the same time at least once before the air runs out:

<ul>
<li>#R45056(Central Cavern) - 28 times (every 64 frames)</li>
<li>#R46080(The Cold Room) - 12 times (every 144 frames)</li>
<li>#R48128(Abandoned Uranium Workings) - 22 times (every 80 frames)</li>
<li>#R52224(Miner Willy meets the Kong Beast) - once (after 1440 frames)</li>
<li>#R56320(Return of the Alien Kong Beast) - once (after 1440 frames)</li>
<li>#R59392(The Bank) - 3 times (every 528 frames)</li>
</ul>

Note that normal speed horizontal guardians are not drawn to the screen at
their initial locations when Willy enters a cavern, because they are moved once
before the cavern is first drawn; the same is true for each vertical guardian,
unless its initial position is at the top of its path and it is initially
moving up, or its initial position is at the bottom of its path and it is
initially moving down - in these cases it remains stationary for one frame
before changing direction.

[Fact:noWayOut:No way out of The Warehouse]
If too many of the crumbling floors have disappeared in #R61440(The Warehouse),
Willy won't be able to reach the portal. For example:

#PUSHS
#POKES61814,0,9;61846,0,9;62089,255
#UDGTABLE { #WILLY16,29,96,5,22,0,10,16,1(no_way_out) } TABLE#
#POPS

If that happens, he will have to wait until the air runs out before getting a
second chance to escape from the cavern.

See also #FACT(stuckOn16)().

[Fact:theUnreachableMillion:The unreachable million]
The score (at least, the part of it that is printed - see #R33829) rolls around
to zero when it hits a million.

[Fact:horizontalSkylabs:Horizontal Skylabs?]
There are three horizontal guardians defined in #R58368(Skylab Landing Bay),
but they're not used. We can only wonder what they might have looked like
before being replaced by the Skylabs.

[Fact:outOfBounds:Out of bounds]
There are two vertical guardians that start off in a location that they never
return to.

The first one is the bright magenta guardian in #R61440(The Warehouse). It
starts off at pixel y-coordinate 0 - the very top of the cavern - but does not
go above y=4 again after it has started moving (see #R62194).

The second one is the blue vertical guardian in #R63488(Solar Power Generator).
It starts off at pixel y-coordinate 80 - touching the platform that Willy is
standing on initially - but does not go below y=79 again after it has started
moving (see #R64235).

[Fact:sourceCodeRemnants:Source code remnants]
Before the game starts for the first time, the 512-byte cavern buffer at
#GBUF32768 contains source code remnants (shown below). The DB directives
define part of the title screen tune data at #R33902. There are more source
code remnants at #R37708.

#TABLE(asm,address-1,instruction,comment-1)
{ #N32768 | #S/DEFM/ "50,171,192,50,48,68" | }
{ #N32787 | #S/DEFW/ #n790 | =r3 790 DB "50,48,68,50,171,192,50,136,137" }
{ #N32789 | #S/DEFB/ #n34 }
{ #N32790 | #S/DEFM/ #n9,"DB",#n9,"50,48,68,50,171,192,50,136,137" }
{ #N32824 | #S/DEFW/ #n800 | =r3 800 DB "50,136,137,50,114,115,50,76,77" }
{ #N32826 | #S/DEFB/ #n34 }
{ #N32827 | #S/DEFM/ #n9,"DB",#n9,"50,136,137,50,114,115,50,76,77" }
{ #N32861 | #S/DEFW/ #n810 | =r5 810 DB "50,7?????????????92,50,38,48" }
{ #N32863 | #S/DEFB/ #n32 }
{ #N32864 | #S/DEFM/ #n9,"DB",#n9,"50,7" }
{ #N32872 | #S/DEFB/ #n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0,#n0 }
{ #N32885 | #S/DEFM/ "92,50,38,48" }
{ #N32896 | #S/DEFW/ #n820 | =r5 820 DB "50,38,4??50,171,192,50,48,68" }
{ #N32898 | #S/DEFB/ #n32 }
{ #N32899 | #S/DEFM/ #n9,"DB",#n9,"50,38,4" }
{ #N32910 | #S/DEFB/ #n255,#n0 }
{ #N32912 | #S/DEFM/ "50,171,192,50,48,68" }
{ #N32931 | #S/DEFW/ #n830 | =r7 830 DB "50,48,????0,171,19??50,136,137" }
{ #N32933 | #S/DEFB/ #n34 }
{ #N32934 | #S/DEFM/ #n9,"DB",#n9,"50,48," }
{ #N32944 | #S/DEFB/ #n0,#n0,#n0,#n0 }
{ #N32948 | #S/DEFM/ "0,171,19" }
{ #N32956 | #S/DEFB/ #n0,#n0 }
{ #N32958 | #S/DEFM/ "50,136,137" }
{ #N32968 | #S/DEFW/ #n840 | =r5 840 DB "50,136,137,???114,115,50,76,77" }
{ #N32970 | #S/DEFB/ #n34 }
{ #N32971 | #S/DEFM/ #n9,"DB",#n9,"50,136,137," }
{ #N32986 | #S/DEFB/ #n255,#n0,#n0 }
{ #N32989 | #S/DEFM/ "114,115,50,76,77" }
{ #N33005 | #S/DEFW/ #n850 | =r3 850 ?B "50,76,77,50,171,203,50,38,51" }
{ #N33007 | #S/DEFB/ #n32 }
{ #N33008 | #S/DEFM/ #n9,#n255,"B",#n9,"50,76,77,50,171,203,50,38,51" }
{ #N33040 | #S/DEFW/ #n860 | =r4 860 DB "50,38,51,50,171,203,50,51,64" }
{ #N33042 | #S/DEFB/ #n32 }
{ #N33043 | #S/DEFM/ #n9,"DB",#n9 }
{ #N33047 | #S/DEFM/ "50,38,51,50,171,203,50,51,64" }
{ #N33075 | #S/DEFW/ #n870 | =r3 870 DB "50,51,64,50,171,203,50,128,129" }
{ #N33077 | #S/DEFB/ #n34 }
{ #N33078 | #S/DEFM/ #n9,"DB",#n9,"50,51,64,50,171,203,50,128,129" }
{ #N33112 | #S/DEFW/ #n880 | =r3 880 DB "50,128,129,50,102,103,50,86,87" }
{ #N33114 | #S/DEFB/ #n34 }
{ #N33115 | #S/DEFM/ #n9,"DB",#n9,"50,128,129,50,102,103,50,86,87" }
{ #N33149 | #S/DEFW/ #n890 | =r3 890 DB "50,64,65,50,128,171,50,32,43" }
{ #N33151 | #S/DEFB/ #n32 }
{ #N33152 | #S/DEFM/ #n9,"DB",#n9,"50,64,65,50,128,171,50,32,43" }
{ #N33184 | #S/DEFW/ #n900 | =r3 900 DB "50,32,43,50,128,171,50,43,51" }
{ #N33186 | #S/DEFB/ #n32 }
{ #N33187 | #S/DEFM/ #n9,"DB",#n9,"50,32,43,50,128,171,50,43,51" }
{ #N33219 | #S/DEFW/ #n910 | =r3 910 DB "50,43,51,50,128,171,50,128,129" }
{ #N33221 | #S/DEFB/ #n34 }
{ #N33222 | #S/DEFM/ #n9,"DB",#n9,"50,43,51,50,128,171,50,128,129" }
{ #N33256 | #S/DEFW/ #n920 | =r3 920 DB "50,128,129,50,102............." }
{ #N33258 | #S/DEFB/ #n34 }
{ #N33259 | #S/DEFM/ #n9,"DB",#n9,"50,128,129,50,102" }
TABLE#
