Files
goldeneye-pc-port/port/src/romdata.c
T
James Dansereau 5ea46fabc1 PC port: full compile + link milestone (ge007.x86_64.exe builds clean)
All ~235 translation units now compile and the target links under MSYS2
GCC 16 + CMake/Ninja (ninja ge007 -k 0: 236/236, zero errors). N64 build
untouched; every src/ change is -DPORT-gated.

Portability fixes (findings D7-D17 in docs/PCPortResearch.md section 11):
- AI X-macro system: SWITCH() call sites activated to the author's
  hand-written byte-identical references under PORT; port/shim/
  bondaicommands.h + bondconstants.h + CPPLib.h re-emit the IDO paste
  tricks (isSubroutine, file-record macros, generated CALL) GCC-clean.
- 64-bit pointer-in-word initializers: monAnim jump targets now go
  through an index table resolved by the interpreter (chrai.h/propobj.c);
  UsetuplenZ.c credits pointer PORT-gated to 0.
- IDO printf engine compiled for PC (xprintf/xlitob/xldtob) with a
  shadow xstdio.h resolving the _Printf prototype clash.
- Host-libc gaps stubbed in port/: bcopy/bzero, __libm_qnan_f,
  tlbmanage*, g_ViXScales/YScales; chrObjRandom PRNG ported from .s.

Asset data strategy (D16): single-file assets compiled for real
(animation tables, fonts, textures, rareware logo); obseg per-file .c
excluded (colliding file-local globals the N64 build isolates via
per-ELF linking); 758 ROM-derived table symbols + ramrom_* + segment
markers stubbed in port/src/assetstubs.c / n64stubs.c.

fast3d is a no-op placeholder (port/src/gfxstub.c) until Phase 2 brings
in the real software RSP. Binary not yet runnable end-to-end: ROM
loading in romdata.c is still a TODO.
2026-08-20 20:27:06 -04:00

90 lines
2.4 KiB
C

/*
* ROM loading: reads the .z64 ROM from the data dir and exposes its segments.
*
* The N64 build links assets in from the ROM at fixed addresses. The PC port
* loads the ROM file into a heap image and maps the game's data segments into
* it, then patches the segment table so asset references resolve.
*
* Modelled on the PD port's port/src/romdata.c (~605 lines).
*
* STATUS: scaffolding stub — implement during Phase 1.
*
* NOTE: GE's ROM layout (segments, asset offsets) differs from PD's. The
* segment table and asset map must be derived from this decomp's
* ge007.ld / imagelist.u.csv / assets/ layout. See docs/PCPortResearch.md.
*/
#include <stdlib.h>
#include <string.h>
#include "platform.h"
#include "system.h"
#include "fs.h"
#include "romdata.h"
static u8 *rom = NULL;
static u32 romSize = 0;
/* Expected ROM file names per region (place one in the data/ dir). */
static const char *romFileName(void)
{
#if GE007_IS_PAL
return "ge007.pal-final.z64";
#else
return "ge007.ntsc-final.z64";
#endif
}
int romdataInit(void)
{
static char pathBuf[1024 + 64];
snprintf(pathBuf, sizeof(pathBuf), "$S/%s", romFileName());
const char *path = sysResolvePath(pathBuf);
/* TODO(Phase 1):
* - open + read the whole ROM into `rom`
* - validate the N64 magic ("Nintendo" @ 0x100) + region
* - build the segment map (code/data/assets) from the decomp's layout
* - patch the game's segment table so IMAGESEG / asset refs resolve
*/
sysLogPrintf(LOG_INFO, "romdataInit: loading %s (TODO Phase 1)", path);
FSFile *f = fsOpen(path, "rb");
if (!f) {
sysLogPrintf(LOG_ERROR, "romdataInit: cannot open %s", path);
return -1;
}
romSize = (u32)fsSize(f);
rom = (u8 *)malloc(romSize);
if (!rom || fsRead(f, rom, romSize) != (int32_t)romSize) {
sysLogPrintf(LOG_ERROR, "romdataInit: failed to read ROM");
fsClose(f);
return -1;
}
fsClose(f);
if (romSize < 0x104 || memcmp(rom + 0x100, "Nintendo", 8) != 0) {
sysLogPrintf(LOG_ERROR, "romdataInit: bad N64 ROM magic");
return -1;
}
return 0;
}
void romdataDestroy(void)
{
free(rom);
rom = NULL;
romSize = 0;
}
const u8 *romdataGetRom(void) { return rom; }
u32 romdataGetRomSize(void) { return romSize; }
const void *romdataMapVa(u32 va)
{
/* TODO(Phase 1): map an N64 RDRAM VA (0xA0000000+) into the image. */
(void)va;
return NULL;
}