I've been doing some reverse engineering on the final game (SFA US v1.0); found
some debug codes and some other things I'm still investigating, such as a lighting debug tool.
Also found an oddity: the function at 0x80048F10 in RAM. It's meant to get the size of a data file. If the file isn't loaded, it... deliberately crashes by writing to a NULL pointer. Like, here's the entire function:
80048f10 54 64 10 3A rlwinm r4,idx,0x2,0x0,0x1d ;r3 = idx (index of file to look up)
80048f14 3C 60 80 36 lis idx,0x8036
80048f18 38 63 F3 E8 subi idx,idx,offset dataFileBuffers
80048f1c 7C 03 20 2E lwzx r0,idx=>dataFileBuffers,r4 ; r0 = dataFileBuffers[idx]
80048f20 28 00 00 00 cmplwi r0,0x0 ; is buffer NULL? (file not loaded)
80048f24 41 82 00 14 beq kaboom ; let's just die then
80048f28 3C 60 80 36 lis idx,0x8036
80048f2c 38 63 F0 A8 subi idx,idx,offset dataFileSize
80048f30 7C 63 20 2E lwzx idx=>dataFileSize,idx,r4 ; r4 = dataFileSize[idx]
80048f34 4E 80 00 20 blr ; return r4
kaboom:
80048f38 38 00 00 00 li r0,0x0
80048f3c 98 00 00 00 stb r0,0x0(0) ; store 0 at address 0 (segfault)
80048f40 38 60 00 00 li idx,0x0 ; r3 = 0, but we never get here
80048f44 4E 80 00 20 blr ; return r3
At first I thought this was just someone being lazy and writing
*(NULL) = 0 as a way to trigger the panic handler instead of looking up the correct way. However I wonder if this was actually a linker error? I can imagine something like:
extern int someFlag;
[...]
#if DEBUG
int someFlag;
[...]
#endif
[...]
if(dataFileBuffers[idx] == NULL) {
someFlag = 0;
return 0;
}
gcc's linker would spit out an error that
someFlag isn't defined if
DEBUG isn't set, but perhaps the one they used only emits a warning and resolves the address to zero instead.
Anyway, it's nothing groundbreaking, just an oddity I wanted to document. I haven't seen any other code do this in the game; it always uses the normal error reporting functions instead.
____________________