Yellow MoonByte order
Half a pointer
The compiler flagged 166 places where the game squeezes an address into 32 bits. I read every one. Nine were real bugs, one hid in the ship battle camera, and the rest turned out to be the game's habits from a machine where an address and a number were the same size.
On the GameCube, an address is 32 bits: four bytes, the same size as an ordinary number. Code written for it mixes the two freely. Store an address in a number field, keep a number in a pointer, test a pointer as if it were a flag: on the console, nothing is lost.
On a modern PC an address is 64 bits. Squeeze one into 32 and you keep only its bottom half. I’ve written about what that does before (Log 10, where a step of “zero” took the game 4 GB backwards). This time it was a sweep instead of a crash.
166 warnings
The port’s game code is built with almost every compiler warning turned off, because the decompiled source is full of things a modern compiler would grumble about and that are fine. Four warnings stay on: the ones for a cast between a pointer and a smaller integer. When the big restructure of the port’s code this week turned up two places that added to an address as a 32-bit number, both in drawing code that had simply never run yet, it was time to stop waiting for these to crash and read all of them.
A full build printed 166: 73 in the game’s own code, and 93 in the sound library, MusyX.
That Mac detail made the job tractable. A shortened address is never a silent bug there; it’s a crash the moment anything follows it. So the question for each site wasn’t “is this cast ugly”, it was: where does the number go, and does anything ever use it as an address?
Nine real ones
Eight were already known: the texture file-name builder and seven drawing functions for one kind of triangle strip, which the restructure had fixed.
The ninth was new, and it’s a good example of how quietly these hide. In a ship battle the camera sometimes queues a follow-up shot: after one angle, cut to another. The function that arms it (fn_80150B24 in the decompilation) stored the address of the next shot’s entry in a 32-bit field. On the Mac that kept the bottom half of the address. And it worked: the only code that reads the field just asks whether it’s zero. The bottom half of an address is almost never zero. It would only fail if the entry sat exactly on a 4 GB boundary.
Almost never isn’t never, so it now stores the address the game would have stored on the console (something like 0x9178EB20). The replay suite’s session with two ship battles runs it 11 times, and every replay plays out exactly as before.
The rest: old habits
The rest were the interesting part, because they’re a map of how GameCube programmers thought. They sort into a few habits:
- Numbers carried in a pointer. The decompilation declared something
void *, and the game passes a plain number through it: MusyX’s song ids, the number of the controller in use, a texture key, a file size. The cast just takes the number back out. Nothing ever follows it. - A null that doubles as “no”. The game’s compiler reused one register for “no record”
and “not valid”, so the faithful source does too:
valid = (s32)recordwhen record is null. Thirteen functions that fetch the ship’s stats do this. - Only the low bits. “Is this address a multiple of 4?” gets the same answer from the bottom half as from the whole thing.
- Addresses only the hardware reads. MusyX writes command lists for the sound chip with addresses in them, and the port’s own stand-in for that chip puts each one back where it belongs.
Each harmless one now casts through a type that says “I checked this, it’s meant”, so the warning still fires for anything new. Those edits changed no machine code at all, which the port’s same-code check proved function by function.
A wider net
The four warnings only catch explicit casts. To be sure I wasn’t missing the quieter kind, I built once more with two broader warnings turned on. They found nothing new that matters, with one curiosity. The game’s soft reset clears a band of the game’s data by taking the distance between two symbols. On the console those sit next to each other in memory. On the PC they’re separate objects, so the clear would wipe whatever lies between them. It never runs: the port restarts itself instead.
One loose thread is left for another day. A ship battle builds the controller’s rumble command without checking whether the controller can rumble, and the lookup it uses returns nothing in that case. It isn’t one of these warnings, and it may never happen on the port, but it’s written down.