The fifteen pyramids

King's Valley is a maze game set in pyramids: the explorer enters a chamber, collects the jewels scattered around it, and leaves through the door that opens once he has them all. Along the way there are mummies that kill him on contact, brick floors he can dig holes through, revolving doors, knives to throw and trap walls that come down from the ceiling.

Everything below comes from the binary, not from playing. Where something could not be confirmed, it says so.

Fifteen pyramids, in a ring

tabla_de_habitaciones (0x6D68) holds nineteen words: the first fifteen are a pointer to each level's descriptor, and the last four are the base of each of the four wall pattern types.

Each descriptor starts with up to four band bytes. A band is sixteen columns of wall, and its byte gives the type (high nibble) and the index within that type (low nibble). The list ends at the band whose high nibble is 3 — and that band is drawn too, which is the detail this project got wrong at first. See Findings.

Counted properly, the rooms split very regularly:

The two-screen rooms are why the explorer's horizontal position needs two whole bytes.

After the bands the descriptor lists, in this order: the four exit doors, the mummies, the jewels, the knives, the pickaxes, the revolving doors, the trap walls and the ladders. Every descriptor ends exactly where the next one begins, which is how we know the reading is right down to the byte.

Each door carries the number of the pyramid it leads to, and laid out those numbers make a closed ring: 1 to 2 to 3 ... to 15 and back to 1. The screen between pyramids is the valley map, with the fifteen of them on a winding path and the word GOAL at the end.

# columns jewels mummies knives pickaxes revolving doors trap walls ladders
1 32 4 2 1 0 0 0 8
2 64 5 3 3 7 2 2 13
3 32 5 2 2 3 0 1 7
4 64 6 2 3 9 1 0 16
5 32 4 2 1 5 0 1 10
6 64 6 3 2 10 1 2 16
7 32 5 2 2 3 0 0 8
8 64 5 3 4 7 1 3 12
9 32 4 1 2 6 0 0 7
10 64 6 3 3 6 0 3 13
11 32 5 2 1 4 2 0 10
12 64 6 3 3 8 2 1 12
13 32 5 2 1 8 0 0 10
14 64 6 2 2 12 1 0 11
15 32 6 2 2 6 0 0 8
total   78 34 32 94 10 13 161

How a room is drawn

carga_la_sala (0x6A90) does not draw into VRAM: it unpacks bit by bit the wall pattern into a RAM buffer starting at 0xE700. Each pattern byte gives eight cells, and each bit says wall (0x12) or hole (0x00). Whatever the bands do not cover has already been filled with 0x14 by borra_sala.

The buffer has a row stride of 96 bytes, not 16 or 48. That figure comes from two independent directions: from the unpacking's ld a,050h plus the sixteen inc de the row itself already advanced (16+80=96), and from the arithmetic in lee_celda_de_sala, which multiplies the row by 96 with five add hl,hl and one addition. Two different routines — one writing the buffer, one reading it — land on the same number without copying it from each other.

Only afterwards does vuelca_la_vista (0x5D31) copy a 22-row by 32-column window of that buffer into the name table, translating each cell with traduce_celda_a_patron.

The cell types

A cell byte's high nibble says what class it is, and its low nibble picks one entry inside that class. traduce_celda_a_patron (0x5D52) turns that into a tile number through the table at 0x5D68:

nibble what it is
0x0x hole: what you walk through and fall through
0x1x floor and wall, plus the ends of a ladder where it meets a platform
0x2x ladder rungs — 0x20/0x21 leaning right, 0x22/0x23 leaning left
0x3x a knife lying on the floor (0x31 and 0x32 if it landed on a rung)
0x4x a jewel — 0x43 to 0x48, one per colour — and its three sparkles
0x5x a revolving door
0x6x, 0x7x the exit door and the lever that opens it
0x8x a pickaxe

An earlier version of this page had 0x5x as "the block that can be dug out" and 0x2x/0x3x as "the two that accept the diagonal step", both classified by use because nobody had drawn them. Drawn, they are a revolving door and a ladder: the diagonal step is climbing.

The fifteen rooms

Under each picture is where it comes from and what is on it.

The first: four jewels, eight ladders, one knife and two mummies

The first: four jewels, eight ladders, one knife and two mummies

The second, two screens wide: seven pickaxes, two revolving doors and two trap walls

The second, two screens wide: seven pickaxes, two revolving doors and two trap walls

The third: five jewels, and the first trap wall in a one-screen room

The third: five jewels, and the first trap wall in a one-screen room

The fourth, with sixteen ladders: the most in the game

The fourth, with sixteen ladders: the most in the game

The fifth, the one the demo plays when nobody touches anything

The fifth, the one the demo plays when nobody touches anything

The sixth: ten pickaxes, and the change to the second group's stone

The sixth: ten pickaxes, and the change to the second group's stone

The seventh, no revolving doors and no traps: just ladders and jewels

The seventh, no revolving doors and no traps: just ladders and jewels

The eighth, with three trap walls and four knives

The eighth, with three trap walls and four knives

The ninth, the only one with a single mummy

The ninth, the only one with a single mummy

The tenth, now in the third group's red stone

The tenth, now in the third group's red stone

The eleventh: two revolving doors in a one-screen room

The eleventh: two revolving doors in a one-screen room

The twelfth, with eight pickaxes and two revolving doors

The twelfth, with eight pickaxes and two revolving doors

The thirteenth: eight pickaxes and no traps

The thirteenth: eight pickaxes and no traps

The fourteenth, twelve pickaxes -the most- and the last group's green stone

The fourteenth, twelve pickaxes -the most- and the last group's green stone

The last: six jewels, and its exit leads back to the first pyramid

The last: six jewels, and its exit leads back to the first pyramid