1984 · Brøderbund Software · Apple II

Karateka

This minisite was contributed by air. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/apple2/karateka with me to Gold.

What the code does that the game never tells the player: a trap with a safe way through, an opening that kills a hero who runs in, a demonstration fighter who cannot aim low, and two pieces of the game that never run.

01 · The guards' brain

Secret: a guard's chance of stepping in is read from the stage's own entry jump

When a guard in the stance decides against a blow, a fourth table decides whether he steps in or holds his place. That table has five entries, one for each distance from 7 to 11 columns, and only the first belongs to it. The other four are the stage's entry: the jump the engine takes into the stage, and the stage's number.

Loading the listings…

The bytes are read from each stage's listing. The brain reads the table as $BFF2 + the distance ($6C35-$6C3B): a random number below the byte, and the guard steps in.

The brain's four tables sit at the very end of each stage, $BFE1 to $BFFD, read as a base plus the distance, and the distance is held to 7 to 11. For the first three tables those reads stay among the stage's thresholds. For the fourth they run from $BFF9 to $BFFD: one byte of $80, then JMP $B700 at $BFFA, where the engine enters every stage ($020C), then the stage's number at $BFFD, which the loader checks. A guard holding back 9 columns from the hero never steps in, because the chance is $00, the low byte of $B700. At 10 columns he steps in 183 times in 256, from the high byte, $B7. At 11 the chance is the stage number: 1 in 256 on the cliff, 4 in 256 against Akuma. In the title the jump goes to $B760, so the demonstration's guard holding back at 9 columns steps in 96 times in 256 where every other guard never does.

Whether the table was meant to be longer, or the entry was moved onto its end, the code does not say. The brain calculator on How it works shows the whole decision.

02 · The palace

Secret: the portcullis can be sprung from one step short

At the end of the palace hall the portcullis is a trap: it falls whenever the hero stands under it, faster than he can run clear, and it kills him. A punch or a kick thrown from one step short sets it off harmlessly, and he can walk through as it rises.

The hero in front of the raised portcullis at the end of the palace hall The portcullis down, the hero dead beneath it

The portcullis up, and fallen on a hero who ran under it. Apple2TS, from the palace's snapshot (reference/).

While the portcullis is up and still, a living hero at columns $1E to $21 sets it falling ($B93D). Falling with its bottom at row $82 or lower, it crushes a hero at columns $1F to $21 ($B967). There is a second way to set it off: with no guard alive, a hero at column $1D or more who kicks, or punches at full stretch, sets it falling too ($B951), and column $1D is one step short of the place where it crushes him. Sprung that way, it rests for 20 frames and then rises a step a frame, and it is not tested again until it is all the way up. A hero who runs at it while it rises gets through. A hero who comes at it while it is down to row $7C or more bounces off it ($BA1A).

03 · Akuma

Secret: Akuma's first kicks kill a hero who runs into his room

Akuma does not fight by the brain at first. As the hero comes into room 6, Akuma is sent a kick on every frame, and the kicks are never refused and never knocked back. A hero who runs in dies of the first. A hero who comes in the stance is knocked back into room 5, and from then on Akuma fights like any guard.

The hero and Akuma, in a robe and horned helmet, trading blows in room 6 The fight with Akuma, Mariko watching from the right

The fight with Akuma, after his opening kicks. Apple2TS, from the last stage's snapshot (reference/).

Entering room 6 sets $58 ($B368). While it is set and the hero lives, the stage sends Akuma the kick command itself ($B8BA), with the count that holds a fighter's blows back after a hit cleared ($24) and his recoil turned off ($5A), so the brain never runs for him ($B895). Going back into room 5 clears $58 ($B345). In Apple2TS, from the stage's start with room 5 opened, a hero who ran into room 6 died of the first kick, and one who came in the stance was knocked back into room 5, after which Akuma fought by the brain.

04 · Mariko

Secret: Mariko decides at column 19 whether to kick the hero

With Akuma beaten, the hero must come to Mariko standing. Whether she kicks him is settled at one column, and by the pose she took on the frames before.

Mariko kicking the hero, who came to her in the fighting stance The hero and Mariko embracing

The hero who came in the stance, and the one who came standing. Apple2TS, from the last stage's snapshot (reference/).

Once Akuma is beaten, Mariko's routine (mariko_last, $BB05) looks at the hero once a frame. Left of column $13 (19), she holds out an arm (pose $20) while he stands and takes another pose ($24) while he is in the stance. At column 19 or more, if her arm is not out, she kicks (pose $21), and the kick kills him ($B91D). If it is out, the embrace begins at column $16 (22): twenty steps of her poses from a table ($BB72), and then the closing words.

05 · Bowing

Secret: bow to a guard 13 columns away and he bows back

The manual lists B for a bow. A guard who is standing, not yet in the stance, answers it with a bow of his own, as long as the hero is 13 columns away or more.

The hero and a guard bowing to each other on the cliff

The hero bowing on the cliff, and the guard 13 columns off bowing back. Apple2TS, from the cliff's snapshot (reference/).

A guard standing still is handled by the first part of the brain ($6B56). Nearer than 13 columns, or with the hero in the stance, he takes the stance himself. Otherwise, when the hero's legs are in the bow's sequence ($65 = $1A), the guard is sent the bow command, $C2, and runs the same poses, $0B, $0C and $0D.

06 · The demonstration

Bug: the demonstration's hero never aims a low blow

The fight that plays itself at the title has a brain of its own for the hero. Its choice of height has one branch the wrong way round, so his blows are high two times in three, middle the third, and never low.

engine $6C80 CMP #$55 ; the guards' height engine $6C82 BCS $6C88 ; $55 or more: test against $AA engine $6C84 LDA #$FF ; below $55: high ... engine $6C88 CMP #$AA ; below $AA: middle, else low title $A0B2 CMP #$55 ; the demonstration hero's height title $A0B4 BCC $A0BA ; below $55: test against $AA title $A0B6 LDA #$FF ; $55 or more: high ... title $A0BA CMP #$AA ; reached only below $55, so always below $AA: middle

The guards' routine ($6C71) gives high below $55, middle below $AA and low above. The demonstration's ($A0AF) branches to the second test with BCC where the guards' branches with BCS, so the test against $AA is reached only with numbers below $55, which always pass it. A low blow would need a number of $AA or more there, and none can arrive.

07 · The hawk

Secret: the dungeon's hawk can be killed, the palace's only driven off

In the palace, a hawk struck by a kick or a punch flies off and comes back later. In the dungeon the hawk is the last opponent, with arrows of its own, and the last blow brings it down in a burst of feathers.

The hawk struck by the hero in the palace hall The hawk attacking the hero in the dungeon

The palace's hawk struck, and the dungeon's. Apple2TS (reference/).

Kicking open room 4's doorway brings the hawk in as the opponent (hawk_comes, $BA62: $4D = 5). Beating the guard before it has already set the hero's most arrows to 23 and the hawk's to 5, and the hawk's never come back ($B820). Each strike costs it an arrow (hawk_move, $A806), and with the last it falls as three pictures of feathers ($A876). While it lives the hero cannot leave room 4 ($B362). The palace's hawk is never an opponent: struck, it only turns and flies off to the right ($B589).

08 · Code that never runs

Secret: the guards were given a step back, and never take it

The guards' brain holds a step back, complete and correct. There is no jump or branch to it, so a guard in the stance never retreats.

Seven bytes at $6C4B, LDA #$FF, STA $29, JMP $6540, would set the stick backwards ($29 = $FF) and carry out the command, as the step forward does with $29 = 1. They sit between a JMP ($6C48) and the step forward ($6C52), and there is no jump or branch to them in any of the six parts. The demonstration's own hero does step back: its brain is a separate routine in the title ($A000).

09 · Code that never runs

Secret: a cheat that leaves the opponent one arrow has lost its key

Among the handlers of the special keys is one that sets the opponent's arrows to one and beeps, as the other special keys beep. There is no key that runs it.

The handler is LDA #1 and STA $B7 at $7742, then a branch to the beep the other keys share ($771F). There is no key test, jump or branch to it in any of the six parts, so it reads as a cheat whose key was taken out. Which key it once answered is not in the code.

10 · The last stage

Bug: one of Akuma's pictures lands on a jump in the dungeon's code

The last stage loads over the dungeon's code, and one of its pictures is a byte longer than the space before $B000. Its last byte lands where the dungeon keeps a jump.

The picture is a mask for the foot of Akuma's robe ($AFE4), 9 rows of 3 bytes, so it ends at $B000. In the dungeon, $B000 is JMP $B006, the routine that draws the stairs. In the last stage it is $AA, then the dungeon's $06 $B0: read as code, TAX and ASL $B0, which would double the hero's most arrows. $B000 is called only on the first screen of a stage ($44 = 0), and the hero cannot get back there in the last stage: room 1's door is shut behind him, and the stage keeps him at column 7 or more in the first room ($BA01).