Repository navigation
feat(artifacts): inspect Sega Mega Drive and Genesis ROM headers offline - #14895
Conversation
These ROMs are inventoried as containers. A plain image matches when the four bytes at offset 0x100 are SEGA; an SMD dump matches the copier mark 0xAA 0xBB and a block count whose de-interleaved bytes carry SEGA, then the odd and even halves are merged into the linear image. The root record stores the 68000 vectors, header strings, declared and computed word checksum, ROM and RAM ranges, devices, external RAM, and region, with members vectors.bin, header.bin, and program.bin (SMD members carry an image offset and a null file range). A checksum or range disagreement leaves coverage unknown, 32X and Sega CD remain labels only, and a file past 8 MiB or 512 SMD blocks is refused under the named fixed ceilings before its body is buffered; the shared region reader maps that refusal onto the typed allowance, and the guide, CLI, supported-targets table, CI scopes, and ceiling registry include the format.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70ab7e80a6
ℹ️ 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".
[Medium impact] The latest changes appear safe to merge; no new actionable issues were found. SummaryAdds offline Mega Drive and Genesis ROM inspection and extraction for plain images and SMD dumps.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Local ROM file] --> B{Recognized layout}
B -->|Plain| D[Linear image]
B -->|SMD| C[De-interleave blocks]
C --> D
D --> E[Parse header and vectors]
E --> F[Metadata and limitations]
E --> G[Extractable members]
F --> H[CLI and MCP inventory]
G --> I[Contained extraction]
Reviews (13) · Last reviewed commit: "fix(artifacts): keep truncated region fa..." · Reviewed by Greptile |
…mbiguous regions A header that declares work RAM as 0xE0FF0000-0xE0FFFFFF, the SGDK default, was reported outside the work-RAM window because the check compared full 32-bit values. The 68000 drives 24 address lines, so the window check now compares bus addresses; metadata keeps the declared values. A region field of a lone A, B or E is both a classic region letter and a one-digit mask, and references disagree on which it is. It was reported as letters with no limitation. It is now region_style ambiguous, keeps both readings in region_characters and region_mask, and records a limitation.
|
Review pass on this PR, with one commit added on top: 3061c9f. The two open review threads were already fixed by earlier commits on this branch; I replied to each with the evidence and resolved them. Defects fixed in 3061c9f:
Both regressions fail on the previous decoder. Checked against references and found consistent:
Noted, not changed:
Sources: DeepWiki on Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3061c9f470
ℹ️ 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".
|
CI note: "Test shard (6/12)" and "Portable tests" fail on this PR's merge with That text comes from #14881 on |
… SMD half layout Header field offsets and lengths were literals repeated at each read, and device support was sliced twice from separate literals. One TEXT_FIELDS table, the named numeric offsets and the EXTERNAL_RAM block now hold the layout, citing SGDK's rom_head.c and Genesis Plus GX's getrominfo and sram_init. SMD recognition and de-interleaving each encoded which block half holds the odd bytes. Both now use SMD_ODD_HALF and SMD_EVEN_HALF, and the decoder takes the block count from the de-interleaved image instead of recomputing it from the file size. The SMD round-trip test only checked the fixture against its own inverse. It now also pins the fixture's file bytes to the Genesis Plus GX deinterleave_block layout.
|
Brittleness pass, pushed as 9cc5e59. Found and fixed:
References disagree, kept visible rather than picked silently:
Deliberately left: Sources:
Validation: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cc5e59c92
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9ef0ebe39b
ℹ️ 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".
…mps before ESP images Header addresses were compared in three places with two rules: the RAM check masked to 24 bits while the reset-PC check compared raw 32-bit values, and neither knew the work-RAM mirror. One owner now holds the MC68000 24-bit bus (the top byte is not driven) and the Mega Drive work RAM, 64 KiB mirrored through 0xE00000-0xFFFFFF (Genesis Plus GX gen_init maps pages 0xE0-0xFF to it). The reset PC is checked against the ROM range on that bus, so 0xFF000200 fetches from 0x200, and a RAM range is work RAM when it covers at most 64 KiB inside the mirror, such as 0xE00000-0xE0FFFF. Metadata keeps the declared values. An SMD dump of 233 or 489 blocks has 0xE9, the ESP image magic, in its copier header's block-count byte, so the ESP image recognizer claimed it. The shared recognizer table now decides the SMD layout, whose signature also needs the AA BB mark, interleaved SEGA bytes and an exact size, before the ESP recognizers, and the plain layout keeps its place after the leading-magic formats.
# Conflicts: # .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md # .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md # docs/.vitepress/documentation.ts # docs/README.md # docs/getting-started/cli.md # docs/reference/supported-targets.md # scripts/ci/scopes.mjs # scripts/verify/fixed-ceiling-registry.json # src/application/binary/TargetFormatVocabularies.test.ts # src/artifacts/artifactFormats.ts # src/domain/analysisView/artifactInventoryView.ts # src/domain/artifactFormatMetadata.ts # src/domain/artifactFormatRecognition.test.ts # src/domain/artifactFormatRecognition.ts # src/domain/artifactGraph.ts # src/domain/formatMetadata/packageAndGameMetadata.ts # src/domain/native/peOverlay.ts # src/domain/targetFormats.ts # src/resources/ArtifactReader.ts # tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc7eb79cea
ℹ️ 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".
The reset PC check already masked the top address byte, but ROM ordering, extent, the nonzero-start note and the checksum window still used the raw declared endpoints. A 0x400-byte image declaring 0xFF000000-0xFF0002FF summed through 0x3FF instead of 0x2FF, and a full 0xFF000000-0xFF0003FF alias was marked incomplete. Derive bus addresses once in the parser and keep the declared values in metadata.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ec772e2f8
ℹ️ 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".
# Conflicts: # docs/reference/supported-targets.md
The ROM range was ordered on the 68000 bus, but the RAM range and the external RAM range still compared raw 32-bit endpoints. A header whose endpoints alias through different top bytes, such as RAM 0xE0FF0000-0x00FFFFFF, was reported as reversed even though the bus range is the 0xFF0000-0xFFFFFF work RAM. The bus owner now has one ordering rule, busOrdered, and the ROM, RAM and external RAM checks all use it. Declared values stay in metadata. A range whose end wraps past the 24-bit bus, such as 0xFF0000-0x1000000, is now reported as reversed, which is what the bus sees.
… Drive bus addresses A region decoder could only report malformed, limit or unsupported, and the shared DecodedRegionArtifactReader mapped every kind but malformed to a fixed-limit refusal. A recognized Mega Drive header cut short was therefore reported as malformed, and an unsupported region failure would have surfaced as a limit. RegionDecodeFailure now has truncated, with the measured extent, and the reader maps each kind to its own typed failure: malformed, truncated, unsupported or limit. The header checks already interpret ROM, RAM and reset addresses on the 68000's 24-bit bus, but metadata exposed only the stored longwords, so the raw m68k hand-off told callers to load at the stored ROM start. A header that stores 0xFF000000 then loads at the wrong address. ROM and RAM ranges now carry bus_start and bus_end, the reset vector carries reset_pc_bus, and the guide and skill hand off with rom.bus_start.
Summary
A Sega Mega Drive or Genesis cartridge image comes back from REA as an unknown blob today. A plain dump or an interleaved SMD copier dump gives no vector table, header strings, checksum, or ROM and RAM ranges, and no linear program image to hand to raw m68k analysis.
This adds an offline
mega-drive-romartifact format.inspect-artifactandextract-artifact(and the MCPinspect_artifact/extract_artifacttools) read the 68000 vector table and the header at0x100, verify the declared checksum against the word sum, and listvectors.bin,header.binandprogram.binas members. An SMD dump is de-interleaved soprogram.binis the same linear image a plain dump holds. Nothing is executed. No issue exists for this; it is a format-inspection and ordinary-extraction addition within the supported contribution scope.Problem and expected behavior
Use case: given
game.binorgame.smd, see the system string, titles, serial, devices, region, reset vector, declared and computed checksum, and ROM and RAM ranges, then extractprogram.binand open it asraw-binarywitharchitecture: "m68k".Observable outcome:
0x100areSEGA, regardless of filename. An SMD dump is recognized when bytes 8 and 9 are0xAA 0xBB, byte 0 matches the 16 KiB block count, and the de-interleaved bytes carrySEGA. An ELF, Mach-O, DOS MZ or FAT header keeps its own format even whenSEGAsits at0x100.format_metadata(kind: "mega-drive-rom") reportslayout,smd_blocks,system_kind, the header strings withraw_hex,devices,initial_ssp,reset_pc, all 64 vectors,checksum.declared/computed/matches,rom,ram,external_ramandregion.vectors.bin,header.binandprogram.bin. For an SMD dumpsource_locationis null andimage_offset(inkind: "mega-drive-rom-entry") gives the position in the linear image.completeonly when the header has no limitations. A checksum mismatch, a reversed or oversized ROM or RAM range, an odd or out-of-rangereset_pc, an unknown external RAM type, unprintable header bytes, a 32X or Sega CD system string (labelled, not decoded) or an SMD split flag leaves coverageunknownwith a limitation naming the problem.0x200bytes is refused. A file past 8 MiB, or an SMD dump past 512 blocks, is refused under a named fixed ceiling before its bytes are buffered.Change and scope
src/domain/megaDriveRom.tsowns parsing: recognition, SMD de-interleave, header and vector facts, the bounded word checksum, range checks, members and limitations.src/artifacts/MegaDriveRomArtifactReader.tsreads the image through the sharedDecodedRegionArtifactReader. That reader gains an optionallimitFailurehook (andRegionDecodeFailurean optionalceilingid) so a format can map a limit refusal onto its registered fixed allowance; formats that do not set it keep the generic fixed-limit failure unchanged.artifactFormatRecognition.ts, registration inartifactFormats.ts,mega-drive-romandmega-drive-rom-entrymetadata inartifactFormatMetadata.tsandpackageAndGameMetadata.ts, inventory view, artifact graph, target format, reader type and PE overlay leading-format wiring, a CI scope entry, and two entries inscripts/verify/fixed-ceiling-registry.json.The Mega Drive ROM byte ceiling) and an SMD dump at 512 blocks of 16 KiB plus the 512-byte copier header (The Mega Drive SMD block ceiling), which is the same image. 8 MiB is the linear cartridge window this reader admits; a larger image needs a bank mapper it does not decode. These are format ceilings, not tunable budgets, so they are notREA_settings.docs/guides/firmware/mega-drive-roms.md, a row indocs/reference/supported-targets.md(the table's column widths were re-aligned by the formatter, which accounts for most of that file's diff), CLI examples indocs/getting-started/cli.md,docs/reference/limits-and-recovery.md, the docs index and sidebar, and the skill references under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.Not included: 32X and Sega CD structures beyond the system-string label, multi-part SMD sets (the split flag is reported and the file is read as one image), and any disassembly or vector-table discovery in raw m68k.
Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the Author readiness and
Author checklist unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
megaDriveRom.tsproduces the header facts, de-interleaved image and member ranges; the reader, inventory graph and inventory view consume them without reparsing raw bytes.mega-drive-rom.mega-drive-rom; existing formats unchanged. Formats with an executable or filesystem header keep priority over aSEGAmarker at0x100.mega-drive-romandmega-drive-rom-entrymetadata shapes. Plain-image members carry their file ranges and SHA-256; SMD members carryimage_offsetand a nullsource_location, because their bytes are not one file range.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/megaDriveRom.test.ts(14 tests: the same facts from a plain image and its SMD dump, Genesis, 32X and Sega CD system strings, a checksum mismatch and a bounded sum, ROM and RAM ranges that disagree with the image, unprintable fields and unknown device letters, external RAM descriptors, region styles, odd and out-of-rangereset_pc, the SMD split flag, a truncated header, SMD recognition from a classification prefix, and the size ceilings),src/artifacts/MegaDriveRomArtifactReader.test.ts(inventory and extraction of the sameprogram.binfrom both layouts),src/artifacts/MegaDriveRomArtifactReader.boundaries.test.ts(a short header, an SMD dump past the block ceiling refused without reading the body, a file past the byte ceiling, a plain image the size of a maximum SMD dump, and unknown coverage for a checksum mismatch with a reversed ROM range), plus cases insrc/domain/artifactFormatRecognition.test.ts,src/application/binary/TargetFormatVocabularies.test.tsandtests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. Fixtures are built insrc/domain/megaDriveRom.fixture.ts.mega-drive-romformat value or reader, so a cartridge image is not recognized there. The CLI output below is executed against this branch.rea inspect-artifact sample.bin --jsonon a 32 KiB image built from the test fixture helpers. Excerpt of the rootformat_metadata:{ "layout": "plain", "smd_blocks": null, "system_kind": "genesis", "system": "SEGA GENESIS", "overseas_title": "SAMPLE CART", "serial": "GM 00001234", "devices": ["J", "6"], "initial_ssp": 16711680, "reset_pc": 512, "checksum": { "declared": 32768, "computed": 32768, "matches": true, "summed_bytes": 32256 }, "rom": { "start": 0, "end": 32767 }, "ram": { "start": 16711680, "end": 16777215 }, "external_ram": { "present": true, "type": 248, "battery_backed": true, "access": "byte-odd", "start": 2097153, "end": 2113535 }, "region": "JUE" }Coverage was
{"scope":"container-entries","status":"complete"}and the members were:{"logical_path":"header.bin","declared_size":256,"source_location":{"offset":256,"length":256}} {"logical_path":"program.bin","declared_size":32768,"source_location":{"offset":0,"length":32768}} {"logical_path":"vectors.bin","declared_size":256,"source_location":{"offset":0,"length":256}}The same image written as a 2-block SMD dump (
sample.smd) reported"layout": "smd","smd_blocks": 2, the same header facts and checksum, andsource_location: nullon all three members.rea extract-artifact sample.smd --output-root <dir> --jsonwrotevectors.bin,header.binandprogram.binwithcontainment_verified: true, and the extractedprogram.binhas SHA-2560c4c0aaf0f73fb5cf5b218d9a8d4891ed7138c02826e99c7919d4b766b3356e4, identical toshasum -a 256of the plainsample.bin.Limitation example: a copy with the declared checksum set to
0x1234returned coverage{"scope":"container-entries","status":"unknown"}and the limitation "Declared checksum 0x1234 does not match the computed word sum 0x8000."Refusal example: an 8,421,376-byte file exited 1 with
"message":"file is 8421376 bytes, exceeding the fixed 8388608-byte Mega Drive ROM ceiling"and"refusal":{"kind":"fixed_ceiling","allowance":"The Mega Drive ROM byte ceiling","limit":8388608,"unit":"bytes"}.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
Not a boundary fix. The reader's boundary tests cover a truncated header, both size ceilings refused before the body is read, and malformed ranges. Cancellation is handled by the shared decoded-region reader and is not separately tested for this format.
For evidence-bearing changes:
Validation performed
npx vitest runon the six test files above: 6 files, 125 tests passed.npm run lint: exit 0, including the numericREA_limits and fixed-ceilings verification ("Fixed ceilings: 68 declarations registered").node scripts/rea.mjs inspect-artifactandextract-artifacton generated plain and SMD images: output as shown above.Compatibility, safety, and release
mega-drive-rom.textand kept inraw_hex. Both size ceilings are checked before any image bytes are buffered, and the checksum loop is bounded by the image size.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