Repository navigation
feat(artifacts): inventory Nintendo 64 ROM images and normalize byte order offline - #14911
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The reviewed code appears safe to merge, with no new actionable findings. SummaryAdds offline Nintendo 64 ROM inspection and big-endian extraction for all three dump orders.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Local ROM] --> B[Detect byte order]
B --> C[Check size and member allowance]
C --> D[Normalize header and checksum bytes]
D --> E[Report header, CIC, CRC and limitations]
E --> F{Source order}
F -->|z64| G[Serve stored ranges]
F -->|v64 or n64| H[Swap member bytes]
G --> I[Hash or extract members]
H --> I
Reviews (4) · Last reviewed commit: "fix(n64): keep the present bytes of a fi..." · Reviewed by Greptile |
|
Maintainer follow-up in 698a82b: both review threads are fixed, plus one more defect from a whole-PR review. Fixed
Checked against reference implementations and left unchanged
Not changed, for the maintainer to decide: the 64 MiB ceiling is registered with class Validation: N64 and recognition source tests (129), the standalone-formats boundary test, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 698a82b397
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Brittleness pass, in 4ce9291. Found and fixed
Checked against sources
Left as is, deliberately
Validation: the N64 and recognition source tests, the standalone-formats boundary test, Sources were read through DeepWiki: mupen64plus/mupen64plus-core, project64/project64 and DragonMinded/libdragon. Context7 had no N64 format sources. |
…order offline An n64-rom image is recognized from the first word in z64 (80 37 12 40), v64 (37 80 40 12), or n64 (40 12 37 80) order plus a 4-byte-aligned boot address in KSEG0 or KSEG1. The reader normalizes the cartridge header and serves header.bin, ipl3.bin, and program.z64 in big-endian order, swapping v64 and n64 bytes and recording that swap as decoded. It names the IPL3/CIC variant from the CRC32 of bytes 0x40..0x1000 and, for a known variant, recomputes the CRC pair over the 1 MiB window; a mismatch, unknown CIC, short window, or non-zero reserved header bytes leave coverage unknown, and a file above 64 MiB is refused before any swap. Comparison ignores n64-rom and n64-rom-entry metadata so dump order is not treated as a content change, and decoded members share the idle-abort helper the Switch executable reader now calls.
…wap unit Charge artifact_limits.expanded_bytes from the file size and byte order before the checksum window is read and swapped. The member layout now has one owner, n64RomRegions, which the parser and the allowance both use. The length rule follows the order's swap unit, as in mupen64plus-core: a z64 image of any length needs no swap, a v64 image needs an even length and an n64 image a multiple of 4. The guide now says that a printable destination byte outside the known table keeps its code with a null destination_name.
…dress check Header offsets, the first-word magics, the CIC 6105 table offset and the KSEG bounds are now named constants with their reference sources, and recognition and parsing share one boot-address decision. A closed-form test checks the cartridge checksum on an all-zero window for every CIC, derived from the checksum routine rather than from n64CartridgeCrc.
4ce9291 to
ab30da5
Compare
…sum window The checksum routine now reads one defined window, n64ChecksumWindow: the image through 0x101000 with only the bytes past a shorter file taken as zero. A z64 or v64 image that ends inside a word keeps that word's bytes instead of losing the whole word. The limitation now says how many bytes were assumed.
Summary
Nintendo 64 cartridge dumps circulate in three byte orders: big-endian
.z64, 16-bit byte-swapped.v64and 32-bit little-endian.n64. REA does not recognize any of them today, soinspect-artifactcannot report the cartridge header or the boot-code (CIC/IPL3) variant, and a disassembler handed a swapped dump sees the wrong bytes.This adds an
n64-romartifact format.inspect-artifactandextract-artifactrecognize all three orders from the first word (the file name does not matter), report the header, name the IPL3 variant from its CRC32, recompute the cartridge CRC pair when the variant is known, and extract a big-endianprogram.z64withheader.binandipl3.bin. Nothing is executed or patched. No issue exists for this; it is a read-only format-inspection addition within the supported contribution scope.Problem and expected behavior
Use case: given
game.v64, find out what the cartridge is, which boot code it carries and whether its CRC pair is consistent, then get a big-endian image to open in a MIPS loader.Observable outcome:
format_metadata(kind: "n64-rom") reportssource_order,rom_bytes,clock_rate,boot_address,libultra_release,title_asciiandtitle_raw_hex, media,cartridge_id, destination code and name, andversion, all read after normalizing to big-endian.ipl3_crc32namescic(6101,6102/7101,6103/7103,6105/7105,6106/7106orunknown). For a known variant,crcismatchormismatchwith the declared and computed pairs; otherwise it isnot-checked. A mismatch is reported and the file is not corrected.header.bin(64 bytes),ipl3.bin(0x40..0x1000, omitted when the file is shorter) andprogram.z64(the whole ROM, big-endian). A z64 dump serves stored ranges; a v64 or n64 dump serves members decoded with one byte-order swap, and entry metadata saysdecoded: true.0x1000, non-zero reserved header bytes and a CRC mismatch are limitations, and coverage isunknownwhenever one is present. A length that is not a multiple of 4 or an implausible boot address is refused. A file above 64 MiB is refused with the fixed allowancen64.rom_bytes.Change and scope
src/domain/n64Rom.ts: byte-order detection and swap, recognition, header decoding, the IPL3 table, the CRC routines (including the 6105/7105 boot-code XOR) and limitations. A z64 input is returned without a copy.src/artifacts/N64RomArtifactReader.ts: the positional reader. z64 members are stored ranges; v64 and n64 members are decoded on read.src/artifacts/OwnedArtifactStream.ts: newdecodedArtifactMemberSource, the cancellation wiring for a member whose bytes come from a decode step.SwitchExecutableArtifactReaderhad the same wiring inline; it now uses this helper, so both decoded-member readers share one owner. Switch behavior is unchanged and its tests pass.artifactFormats.ts,artifactFormatRecognition.ts,artifactFormatMetadata.ts,packageAndGameMetadata.ts,targetFormats.ts,artifactGraph.ts,artifactInventoryView.ts,ArtifactReader.tsand the PE overlay format list.compare-artifactsdoes not countsource_orderordecodedas a metadata change, so a z64 dump and a swapped dump of the same program compare as the same members.docs/guides/firmware/n64-roms.md, CLI examples indocs/getting-started/cli.md,docs/reference/limits-and-recovery.md, one row indocs/reference/supported-targets.md, the docs index and sidebar, and the skill references under.agents/skills/reverse-engineer-anything/and.cursor-plugin/. The 64 MiB ceiling is registered inscripts/verify/fixed-ceiling-registry.json, andscripts/ci/scopes.mjsmaps the new files.Not included: loading
program.z64as MIPS inside REA. The Ghidra MIPS lane admits ELF only andraw-binaryhas no MIPS architecture; routing raw console images through an installed Ghidra language is the open design in #5657. The guide gives the facts for an external big-endian MIPS loader instead (map file offset0x1000atboot_address).Contract and boundary impact
n64Rom.tsinterprets the header once after byte-order normalization; the reader, metadata and comparison consume its parsed facts.inspect-artifact,extract-artifactandcompare-artifactsgain one format,n64-rom.n64-romandn64-rom-entrymetadata.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): none committed; authored skill references updated under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/domain/n64Rom.test.ts(13 tests: the three orders normalize to the same facts, CRC match and mismatch, the 6105/7105 XOR, a short checksum window, unknown IPL3, a file ending inside IPL3, non-zero reserved bytes, truncated header, odd length, implausible boot address, the 64 MiB ceiling),src/artifacts/N64RomArtifactReader.test.ts(7) andsrc/artifacts/N64RomArtifactReader.boundaries.test.ts(10, including cancelling a decoded v64 or n64 member before and during its read), plus entries inartifactFormatRecognition.test.ts,artifactComparison.test.ts,TargetFormatVocabularies.test.tsandtests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. Fixtures are built insrc/domain/n64Rom.fixture.ts. The Switch NSO tests andOwnedArtifactStream.test.tscover the shared helper's other caller.cic: "unknown"andcrc: not-checkedfor these files, which is the documented behavior for an unknown IPL3.rea inspect-artifact game.v64 --json:game.z64andgame.n64gave the same values exceptsource_order.rea extract-artifact game.v64 --jsonwroteheader.bin(64 bytes),ipl3.bin(4032) andprogram.z64(12288), each withkind: "n64-rom-entry",source_order: "v64",decoded: true. The extractedprogram.z64has the same SHA-256 asgame.z64(bdc1acd0...).rea inspect-artifact bad-crc.z64 --jsonreportedcrc.status: "mismatch"(declared_crc14240843241,computed_crc14240843240) with the limitation "Declared CRC1 0xfcc621e9 and CRC2 0x1c461555 differ from computed CRC1 0xfcc621e8 and CRC2 0x1c461555 for CIC 6102/7101."rea inspect-artifact odd.z64 --jsonon a 12,289-byte file exited 1 withunsupported_target,file_format_rejected: "Nintendo 64 ROM length 12289 is not a multiple of 4, so byte order cannot be normalized".Not a boundary fix. The new reader's boundary tests cover truncation, the size ceiling, the expansion budget and cancellation of decoded members.
For evidence-bearing changes:
Validation performed
npx vitest runon the N64, Switch,OwnedArtifactStream, recognition, comparison, vocabulary and standalone-format test files: 10 files, 241 tests passed.npm run lint: passed. Its fixed-ceilings step accepts the newn64.rom_bytesentry.node scripts/rea.mjs inspect-artifactandextract-artifacton the fixture-built ROMs: output as shown above.Compatibility, safety, and release
decodedArtifactMemberSourceis a new export; the Switch reader's cancellation behavior is unchanged.artifact_limits.expanded_bytesbefore hashing, and decoded member streams honor caller cancellation.AI was used for assistance.
Author readiness
Human owner: @mvanhorn
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.Demo