Cite as
vinheim3/lufia2-disasm
Original
https://github.com/vinheim3/lufia2-disasm
Pinned
vinheim3/lufia2-disasm @ aab38945686daa6af3a9f6cbe8262977d97863b2
Accessed
2026-11-08
Licence
none stated (no LICENSE or README in the repository)
Credit
Daniel Jianoran (vinheim3). The WLA-DX sources are split into code/bank_000.s to code/bank_027.s, with extracted resources under data/.
Notes
WLA-DX source for the USA ROM (`Makefile`, wla-65816), 41 MB. It has no README and no commit message describing its state. `cmp.sh` compares a build with `original/lufia2.sfc`, which the repository does not ship, so it was not built here. Bank $83's Ancient Cave routines sit in code/bank_003.s, and the RAM names (e.g. `wAncientCaveFloorPlus1`) are the disassembler's. Line numbers in quotes refer to the pinned commit.

Cited on

Claims (23)

Each of the 224 monsters has a record reached through a table of 224 offsets at $96:85C0: the battle loader copies its 13-letter name, four words from +$11 to +$17, and four bytes from +$19 to +$1C, which it doubles into words; the routine at $81:FBDB reads the experience and gold it pays as words at +$1D and +$1F; and a list of three-byte entries from +$21, ended by 0, holds the drop: in an entry of kind 3 the low 9 bits name the item and the top 7 bits give the chance in percent. Terror Wave names the four words HP, MP, attack, and defense, the four bytes agility, intelligence, guts, and magic resistance, and the byte at +$0D the level. 132 monsters carry a drop. HP runs up to 65535 (Egg Dragon) and experience up to 60000 (Egg Dragon).code/bank_001.s L18568–18633code/bank_001.s L18396–18439code/bank_001.s L18522–18541code/bank_000.s L398–430Code
All seven characters share one experience curve: reaching level 2 takes 10 experience, level 10 2891, level 50 1548710, and level 99 9999999. The game computes it rather than storing it. Starting from a step of 20 (stored as 5120, in 1/256ths), each level adds the step to a running sum and then grows the step by step × (f + 1) / 256, where f is a factor that changes every eight levels: 190, 64, 49, 31, 17, 13, 5, 2, 2, 1, 1, 1, 1. The requirement is the sum / 256 − 10, except that reaching level 99 takes 9,999,999 flat: at level 98 the routine returns that figure instead.code/bank_001.s L18195–18326Code
Each enemy shown on a field map stands for an enemy group the map lists: when the map places an encounter actor, the game takes the actor's slot, reads the group in that slot of the map's encounter list, and sets up that slot's enemies from it. In the Ancient Cave the list is read from memory, where the cave writes it, rather than from the ROM.code/bank_000.s L7040–7053code/bank_001.s L435–497Code
Once an action isn't rejected by the target's status or interrupted, its damage is a base value scaled, given a random bonus, cut by half the target's defense, halved, and trimmed by a factor: X = base × scale / 16; X + X × v / 256, with v random from 0 to the action's variance − 1; less half the target's defense, at least 0; halved; then less X × F / 256, where F is the action's damage-factor byte. First a roll from 0 to 99 is made against the action's chance byte: below it, the action's own scale stands and the target's defense counts as 0, a heavier hit that ignores defense; otherwise the scale is 16, times 1. Healing takes the scale and the random bonus only. A scaled base past 65,535 runs into a $00 byte in the code rather than a result. The base, chance, scale, variance, defense, and factor come from the action's battle script, which isn't read here, and the lines read hold no miss test.code/bank_005.s L12249–12400code/bank_000.s L397–430Code
Each defeated enemy can drop its item: the game needs a roll from 0 to 99 below the drop's chance, which is half the high byte of the stored drop word, and then a 1 on a roll from 0 to 3, so a chance of 40 drops on about 10% of kills. It rolls for each drop entry in the enemy's list, a later success replacing an earlier one, and stops rolling once the battle has won an item, so a battle pays at most one dropped item.code/bank_001.s L18396–18450code/bank_001.s L18522–18541Code
Running from a battle has no roll in the code read: unless the battle's special-encounter flag is set, the party gets away at once. A battle loaded from the game's list of special encounters sets the flag, and there the attempt fails with a message and the battle goes on. When an enemy or the capsule monster runs, it alone leaves: it takes the status a defeated fighter gets, and the battle goes on. The routine's caller and the routines it calls aren't read, so a roll made there isn't ruled out.code/bank_001.s L6126–6232code/bank_001.s L397–432Code
Taking a hit from an enemy fills a party member's IP gauge, more for a hit that takes a larger share of the HP the member had. The gain is m × g / 256 + 12, at most 255, where m = (256 − cos a) × 2, with a the hit's share of the member's HP in 256ths divided by 4 and rounded (64 is a right angle, so m runs from near 0 to 512), and g is the low byte of a word in the member's battle record times 128 / 100, at most 255 (199 instead when the word is $C800 or more). The gauge stops at 255. In the HP-change routine read, only an enemy's hit that leaves the member standing adds IP; a member who is knocked out drops to 0.code/bank_005.s L12772–12890code/bank_005.s L14074–14092Code
The Ancient Cave has 99 floors, and the game builds each of the first 98 at random as the party reaches it; the 99th is a fixed map. Entering clears the floor count and arriving on the cave's map with a count of 0 sets it to 1; each floor is built with the count as its number and the count rises by one after it, and when the count stands at 99 the game loads the fixed map instead of building one.code/bank_003.s L7795–7810code/bank_003.s L4813–4827code/bank_003.s L4881–4886code/bank_004.s L1129–1130Code
No Ancient Cave floor has a seed of its own. The builder draws on the random generator the rest of the game uses, after first spending between 1 and 32 of its numbers, one more than the frame counter's low five bits. That generator is a table of 55 bytes, stirred by XOR each time its numbers run out; it is seeded at power-on and again from a byte kept in the save whenever a save is loaded.code/bank_003.s L4803–4811code/bank_000.s L433–455code/bank_000.s L504–520code/bank_000.s L55–57code/bank_000.s L2999–3008code/bank_000.s L459–503Code
Each Ancient Cave floor is built rather than picked from stock maps. The builder lays out up to seven rectangular rooms, each one to four cells wide and one to four tall (the size the average of two draws), working left to right in bands down a grid 16 cells wide, and keeps a room only if it ends before column 9 and row 15 as the code counts; a room of a single cell is widened by one. Later passes, which the decompilation names for linking the floor, removing duplicate links, placing the start, the treasure room, the objects and chests, and drawing the cells, finish the floor.code/bank_003.s L2714–2797Code
Which enemies an Ancient Cave floor can hold depends only on its number: each enemy placed on floor N is entry 2(N − 1) plus a random 0 to 5 of a 200-entry table, so each floor has six kinds, a floor shares four of them with the next, and each entry serves three floors. A floor makes 4 to 7 tries to place an enemy, each at a random spot of a random cell, and a try fails when no cell is found or the spot is beside the start or another object; a treasure room adds up to 13 more, and a floor holds at most 20.code/bank_003.s L4029–4068Code
An Ancient Cave floor has at most eight chests. The builder scans the grid for 2-by-2 blocks of cells in one room and tries a chest in each block, marking it used, until eight are placed or the grid scan ends; one floor in 16 can also get a treasure room, a 2-by-2 block that takes up to eight chest tries of its own and a cluster of up to 13 enemies.code/bank_003.s L4171–4184Code
Each Ancient Cave floor rolls the contents of its chests before it lays out its rooms: eight rolls of a byte from 0 to 255, one per chest. A roll of 174 or more gives a weapon, 129 to 173 a piece of armour, 99 to 128 a spell scroll for a spell none of the four party members knows (or else a restorative), 94 to 98 a blue chest, 36 to 93 a restorative, and 0 to 35 another consumable. Weapons, spells, blue chests and the other consumables are drawn evenly from their lists, and armour evenly from the first n mod 128 items of its list of n (lufia-ii/cave-armor-wrap); the restorative takes the average of two draws, so the middle of its list of nine comes up most. When an Iris treasure or Providence takes the first chest, the rolls fill the other seven.code/bank_003.s L2620–2711code/bank_003.s L10714–10767Code
Weapon and armour chests deepen with the floor: the builder lists, for each floor, every item marked as found in the field and not marked as excluded whose price is under (floor + 1) × 1,000 gold, or any price from floor 60 on, in item order; items of type 1 go on the weapon list and the rest on the armour list.code/bank_003.s L2478–2555Code
From floor 10 on, Ancient Cave armour chests give only body armour. The chest pick halves the low byte of the list's length in bytes, so a list of more than 127 items is drawn from only its first n − 128: the armour list reaches 129 items at floor 10, where every armour chest holds its first item, an Apron, and from floor 60 it holds 185 and draws from the first 57, all body armour, which comes first in item order. Shields, helmets, rings and jewels come out of armour chests only on floors 1 to 9; the weapon list never passes 88 items and is drawn whole.code/bank_003.s L2645–2666code/bank_003.s L4770–4777Code
On each floor the Ancient Cave builds, there is a 5-in-256 chance that the game picks one of the nine Iris treasures at random for the floor's first chest. The treasure goes in only if it hasn't been picked before in this visit and the player hasn't already earned it: one bit per treasure, cleared on entry, marks it picked even when the chest isn't placed, and its event flag, set when the party leaves with it, marks it earned. No floor number is tested.code/bank_003.s L2557–2594code/bank_004.s L1129–1135Code
From floor 21 on, an Ancient Cave floor's first chest can hold Providence (item $2D): the chance is about the floor number in 60, so certain from floor 60, unless an Iris treasure took the chest. Once a chest holding Providence has been opened, no more are placed in that visit.code/bank_003.s L2596–2618Code
Entering the Ancient Cave takes everything from the party except its blue-chest items. The game moves each item on the blue list from the bag and from the four party members' equipment to a list of its own, saves a copy of the party, then clears all but the first 14 bytes of each of the seven members' records, the bag, the gold and the play time, puts 10 Potions in the bag, gives back the blue items, and rebuilds the seven members from their default records; when the byte at $0A7F, which neither source names, is 7, it also returns every capsule monster to level 1, a step no probe has covered.code/bank_004.s L1136–1201code/bank_004.s L1205–1235code/bank_004.s L1274–1347code/bank_002.s L10098–10100Code
When an Ancient Cave visit ends without a wipe, the party keeps its Iris treasures and its blue-list items and nothing else: the game collects every Iris treasure in the bag, setting its event flag, then every blue-list item in the bag or in any of the seven members' equipment, restores the copy of the party saved at the entrance, gives the collected items back, and adds the time spent inside to the restored play time. Iris treasures are collected from the bag only, and blue items brought in but no longer held are not returned.code/bank_004.s L1355–1392code/bank_004.s L1395–1477code/bank_004.s L1479–1617code/bank_004.s L1620–1651Code
A party wipe in the Ancient Cave, a battle there or on its bottom floor that ends with every party member down, ends the visit with nothing gained. The game marks the visit lost, clears the party again without giving back its blue items, and counts the defeat; when the party then leaves, the exit skips the collecting, restores the copy saved at the entrance, and returns only the blue items the party brought in, so that visit's blue-chest finds and Iris treasures are lost.code/bank_004.s L1727–1748code/bank_003.s L597–609Code
Between visits the game keeps, outside the copy the exit restores, a count of entries and one of wipes, the total time spent in the cave, and the deepest floor reached; what else carries over is the Iris flags and the blue items as the party holds them.code/bank_004.s L1121–1128code/bank_003.s L4780–4785Code
The Ancient Cave changes its look and music in three bands of floors: floors 1 to 20, 21 to 40, and 41 to 98 each take their own block set, map header and music, chosen by (floor − 1) ÷ 10 from a 10-entry table; within a band the palette changes every two floors, through four.code/bank_003.s L4788–4794code/bank_003.s L4830–4872Code
Depth changes four things in the Ancient Cave and, in the code read here, nothing else: which six enemy kinds a floor can hold, the price ceiling of its weapon and armour chests, whether and how often Providence can appear, and the floor's look and music. The same count also picks the fixed bottom map at 99 and is kept as the deepest floor reached. The enemies keep the stats of their monster records; no routine that reads the floor number touches them.code/bank_003.s L4040–4043Code