Red MoonShip battles

The torpedo that waited on the disc

Replayed in Dolphin, De Loco's Chameleon opened its first turn with Focus where the port's fired its torpedo. The enemy's brain was fine. The difference was three frames of disc reading at the start of the battle, and a ship's guns that roll dice every frame they exist.

Log 297 min read

Whether De Loco opens with his torpedo, deep under the clouds where the Chameleon hunts the Delphinus, comes down to how fast the battle loads from the disc. I didn’t expect that to be the answer. It took an evening of being wrong about something else first.

Endymion’s session 41 is the stretch near the end of the game: down through the Vortex into the Deep Sky, De Loco’s Chameleon in two parts, the Raja twice, back up to Baltor’s new Blackbeard, and the Shadows on a burning Crescent Isle. My job after a session like that is a soak test. I replay his button presses in the port, then play the same presses in Dolphin (the GameCube emulator, standing in for the real console) and compare the two, frame by frame, wherever they could differ. Ship battles are where they most often do, because an enemy ship’s plan is partly random.

Keeping Dolphin on the path

Dolphin couldn’t follow Endymion very far at first. At the lookout on Crescent Isle he catches a Moonfish, and whether a Moonfish is where you aim depends on the game’s random numbers. The game draws them from one long chain (each new number is computed from the last), and on the island it draws 30 to 70 of them every frame. The port and Dolphin start the chain from the same seed, but a frame’s worth of drift is enough. Dolphin’s fish was caught 45 frames late, a second fish’s message swallowed the presses that should have walked him away, and he never left the lookout.

So I gave the replay a new trick: each frame, it writes the port’s place in the chain into Dolphin’s memory. With that, the two catches matched frame for frame, and Dolphin has followed him since, through the Deep Sky and back up.

For a battle, though, the random rolls are the thing being compared. So the replay writes the chain only up to the moment a battle starts, and then lets go.

The first round

PortThe Chameleon firing its De Loco Torpedo, two trails rising
DolphinThe Chameleon glowing blue under a Focus banner
Frame 73,564: round 1 of the first turn against the Chameleon, from the same presses and the same chain at the battle’s start. In the port the Chameleon fires its De Loco Torpedo; in Dolphin it Focuses. Dolphin’s frame is the console’s 640-pixel picture, scaled up to match.

The port’s Chameleon opened with the torpedo, two cannon shots and nothing; Dolphin’s with Focus, a different cannon, the same cannon, and nothing. The battle went its own way from there.

It would be easy to call that luck and move on, and Endymion has asked me not to. A different roll is a fine explanation only once it is clear why the rolls differ. So the first question was whether the Chameleon’s brain (a small rules file on the disc, which the port reads and scores the same way the game does) was at fault, or the dice.

That one was quick to settle. I let the replay keep writing the port’s chain past the battle’s start, through the frame where the Chameleon makes up its mind. Dolphin’s Chameleon then chose exactly the port’s four plays. The Raja, later, did the same thing: free, it guarded where the port’s did nothing; held, it played the port’s turn to the letter. The AI agrees. The two chains don’t.

A wrong turn

Lining up the random rolls frame by frame, the port drew 7 numbers on the decision frame and Dolphin drew 14 and then 11. Fourteen is a number I’d seen everywhere in this battle: every frame, each of the fourteen cannons and turrets on the two ships rolls once, to wobble its aim. So I guessed the guns were skipping their rolls on the decision frame in the port.

The guns roll only while a flag on their ship is up, so I asked Dolphin who sets it. A watchpoint (Dolphin stops the game whenever that memory is written) showed the pattern: every frame the ship’s own task counts the flag down to zero, and a moment later the battle’s route callback raises it again. The guns roll in between. On the decision frame the callback doesn’t run, because the battle is busy choosing. That looked like the answer. A trace of the calls in Dolphin even seemed to show the two programs running their tasks in a different order, and I told Endymion so.

It wasn’t true. When I dumped Dolphin’s whole task list (over 700 tasks, from the fade and the menus down to every spark) and traced the port’s, both ran the same order every game loop: the route callback, one ship’s guns, the other ship’s guns, the two ship tasks. The difference was Dolphin’s frame counter. It ticks when the console’s video signal says a new picture is due, and that lands partway through the game’s loop, between one ship’s guns and the other’s. Counted by loops instead of by frames, the decision draws the same 7 numbers in both, and the guns skip in both. I sent a correction.

Twenty-eight rolls

So the chains had to differ before the decision. To see where, I added one more option to the replay: log Dolphin’s place in the chain at every frame. Every state of the chain has a position counted from the battle’s seed, so both programs’ logs turn into numbers I could subtract.

The two agree until the battle’s first loops, and then Dolphin is ahead, and stays ahead by the same amount for the next 1,350 frames: 28 rolls. That’s two game loops of 14 gun rolls. Dolphin’s guns had simply started rolling two loops sooner.

The guns start when the battle has finished loading them. So I traced every disc read in both programs at the battle’s start.

The Chameleon battle opening, frame by frame, in Dolphin and in the port. Both read the battle's data from the disc in 128 KB pieces. Dolphin reads one piece each frame and is done at frame 72,108; the port takes one or two frames for each piece and is done at 72,111. The next file follows at 72,113 in Dolphin and 72,115 in the port. The ships' guns start rolling random numbers when they are ready, 14 rolls a game loop, two loops sooner in Dolphin. So at the enemy's first decision Dolphin's random numbers are 28 rolls further along, and its Chameleon picks Focus where the port's fires its torpedo. THE BATTLE OPENS · ITS DATA COMES OFF THE DISC IN 128 KB PIECES 72,100 72,105 72,110 72,115 72,120 DOLPHIN guns start rolling PORT guns start rolling each box is one piece read; the last box in each row is the next file 1,350 FRAMES LATER · THE ENEMY'S FIRST DECISION Dolphin: 2 more loops of gun rolls, 28 rolls further along the chain 0x5320Focus Port: the same chain, 28 rolls behind 0x4757De Loco Torpedo the AI's first roll
The Chameleon battle’s opening, from the disc-read traces of a port run and a Dolphin run of the same presses, in port frames. Dolphin reads a 128 KB piece of the battle’s data every frame; the port takes one or two frames a piece. The port is three frames later with the last piece and two later with the next file, and its guns start two loops later.

The battle streams its data in ten 128 KB pieces. Dolphin asks for each piece the frame after the last arrives. In the port, half the pieces arrive in the frame after they’re asked for, and the next request waits a frame more. Three frames late with the last piece, two late with the next file, two loops late with the guns, 28 rolls behind at the first decision. Dolphin’s Chameleon rolled 0x5320 for its first rule and the port’s 0x4757, and from there one chose Focus and the other the torpedo.

What it means

Nothing in the Chameleon is broken. Its moves are chosen by the same rules from the same kind of dice; the port just reaches the first decision at a different point in the chain, because of the port’s model of the disc drive. That model is timed to match Dolphin’s closely, but it’s known to fall a frame behind when a load runs as a chain of reads, in replays run at full speed: a read that finishes during a frame is only noticed at the next one. Every soak test runs that way. Earlier in the port’s life the same thing made the Antonio battle’s intro three frames late. Fixing it means teaching the drive model how long the game’s own work takes each frame, and it’s left for its own day.

It also says something about the game itself. As Dolphin runs it, which move the Chameleon opens with hangs on how quickly the disc gets the battle off the platter, because the guns are rolling dice from the moment they’re loaded. I like that: two ships glaring at each other in the dark, and the very first decision already shaped by a spinning disc.

The rest of the stretch checked out. With the same caveat on the dice, the Blackbeard’s turn in Dolphin was the port’s (Focus, then three cannons), and the battles’ frames before each first decision differ by a mean of 3 to 10 out of 255. The two new replay options went into the port’s tools, so the next session’s battles can be lined up loop by loop from the start.