Skip to content

feat(artifacts): inspect Sega Mega Drive and Genesis ROM headers offline - #14895

Merged
morluto merged 14 commits into
morluto:mainfrom
mvanhorn:fix/mega-drive-rom-header
Nov 27, 2026
Merged

morluto merged 14 commits into
morluto:mainfrom
mvanhorn:fix/mega-drive-rom-header

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

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-rom artifact format. inspect-artifact and extract-artifact (and the MCP inspect_artifact / extract_artifact tools) read the 68000 vector table and the header at 0x100, verify the declared checksum against the word sum, and list vectors.bin, header.bin and program.bin as members. An SMD dump is de-interleaved so program.bin is 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.bin or game.smd, see the system string, titles, serial, devices, region, reset vector, declared and computed checksum, and ROM and RAM ranges, then extract program.bin and open it as raw-binary with architecture: "m68k".

Observable outcome:

  • A plain image is recognized when the four bytes at 0x100 are SEGA, regardless of filename. An SMD dump is recognized when bytes 8 and 9 are 0xAA 0xBB, byte 0 matches the 16 KiB block count, and the de-interleaved bytes carry SEGA. An ELF, Mach-O, DOS MZ or FAT header keeps its own format even when SEGA sits at 0x100.
  • The root format_metadata (kind: "mega-drive-rom") reports layout, smd_blocks, system_kind, the header strings with raw_hex, devices, initial_ssp, reset_pc, all 64 vectors, checksum.declared / computed / matches, rom, ram, external_ram and region.
  • Members are vectors.bin, header.bin and program.bin. For an SMD dump source_location is null and image_offset (in kind: "mega-drive-rom-entry") gives the position in the linear image.
  • Coverage is complete only when the header has no limitations. A checksum mismatch, a reversed or oversized ROM or RAM range, an odd or out-of-range reset_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 coverage unknown with a limitation naming the problem.
  • A header shorter than 0x200 bytes 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.ts owns parsing: recognition, SMD de-interleave, header and vector facts, the bounded word checksum, range checks, members and limitations.
  • src/artifacts/MegaDriveRomArtifactReader.ts reads the image through the shared DecodedRegionArtifactReader. That reader gains an optional limitFailure hook (and RegionDecodeFailure an optional ceiling id) 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.
  • Recognition in artifactFormatRecognition.ts, registration in artifactFormats.ts, mega-drive-rom and mega-drive-rom-entry metadata in artifactFormatMetadata.ts and packageAndGameMetadata.ts, inventory view, artifact graph, target format, reader type and PE overlay leading-format wiring, a CI scope entry, and two entries in scripts/verify/fixed-ceiling-registry.json.
  • Fixed bounds: the linear image is capped at 8 MiB (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 not REA_ settings.
  • Docs: new docs/guides/firmware/mega-drive-roms.md, a row in docs/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 in docs/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

  • Semantic owner and earliest changed stage: megaDriveRom.ts produces the header facts, de-interleaved image and member ranges; the reader, inventory graph and inventory view consume them without reparsing raw bytes.
  • Contribution scope fit and linked maintainer decision: format inspection and ordinary extraction of a local file; not applicable (no target execution, injection, mutation, or protection recovery).
  • CLI and MCP/tool-catalog contract: no new tools or parameters. Existing artifact tools recognize one more format value, mega-drive-rom.
  • Provider, bridge, target-format, or platform compatibility: new target format mega-drive-rom; existing formats unchanged. Formats with an executable or filesystem header keep priority over a SEGA marker at 0x100.
  • Evidence, artifact, provenance, or reconstruction contract: new mega-drive-rom and mega-drive-rom-entry metadata shapes. Plain-image members carry their file ranges and SHA-256; SMD members carry image_offset and a null source_location, because their bytes are not one file range.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; 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.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: 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-range reset_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 same program.bin from 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 in src/domain/artifactFormatRecognition.test.ts, src/application/binary/TargetFormatVocabularies.test.ts and tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. Fixtures are built in src/domain/megaDriveRom.fixture.ts.
  • Base reproduction or other evidence: source-derived. The base revision has no mega-drive-rom format value or reader, so a cartridge image is not recognized there. The CLI output below is executed against this branch.
  • User-visible CLI/MCP output (if applicable): executed, rea inspect-artifact sample.bin --json on a 32 KiB image built from the test fixture helpers. Excerpt of the root format_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, and source_location: null on all three members. rea extract-artifact sample.smd --output-root <dir> --json wrote vectors.bin, header.bin and program.bin with containment_verified: true, and the extracted program.bin has SHA-256 0c4c0aaf0f73fb5cf5b218d9a8d4891ed7138c02826e99c7919d4b766b3356e4, identical to shasum -a 256 of the plain sample.bin.

Limitation example: a copy with the declared checksum set to 0x1234 returned 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"}.

  • Remaining proof gaps: tested against synthetic ROMs built from the public header layout. No commercial or homebrew cartridge dump was used. The MCP tools were not exercised directly; they share the inventory and extraction path the CLI uses.

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:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run on the six test files above: 6 files, 125 tests passed.
  • npm run lint: exit 0, including the numeric REA_ limits and fixed-ceilings verification ("Fixed ceilings: 68 declarations registered").
  • node scripts/rea.mjs inspect-artifact and extract-artifact on generated plain and SMD images: output as shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; offline parsing only, run on macOS with Node 24.
  • Package or release metadata impact: one new format value, mega-drive-rom.
  • Security, privacy, process, or containment review: reads a local file only and extracts through the existing contained extraction path. Header strings are target-derived and untrusted; unprintable bytes are replaced in text and kept in raw_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

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Demo

demo

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T21:46:54.764263Z ca64f07 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/megaDriveRom.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The latest changes appear safe to merge; no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The latest changes appear safe to merge; no new actionable issues were found.

Summary

Adds offline Mega Drive and Genesis ROM inspection and extraction for plain images and SMD dumps.

  • Mega Drive ROMs now reveal their headers and extract as a linear program image.
  • Shared region readers now keep truncation details and map named size limits.

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]
Loading

Reviews (13) · Last reviewed commit: "fix(artifacts): keep truncated region fa..." · Reviewed by Greptile

Comment thread src/domain/megaDriveRom.ts Resolved
Comment thread src/domain/megaDriveRom.ts Resolved
Comment thread src/domain/megaDriveRom.fixture.ts Resolved
mvanhorn and others added 4 commits November 27, 2026 06:08
…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.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

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:

  • SGDK work-RAM headers were wrongly incomplete. SGDK's default header (src/boot/rom_head.c) declares work RAM as 0xE0FF0000–0xE0FFFFFF, but the window check compared full 32-bit values. Every SGDK-built ROM was therefore reported with an out-of-window RAM limitation and incomplete coverage. The 68000 drives 24 address lines, so the check now compares bus addresses (declared & 0x00FFFFFF). Metadata still keeps the declared values, and a range that wraps past the 24-bit bus is still reported.
  • A lone A, B or E region was silently decoded as letters. Each of these is both a classic region letter and a one-digit mask. Genesis Plus GX's get_region reads a lone E as Europe but A and B as hex nibbles, so references disagree. The field is now region_style: "ambiguous", with both readings kept in region_characters and region_mask and a limitation recorded. The schema enum, its doc comment and the guide are updated.

Both regressions fail on the previous decoder.

Checked against references and found consistent:

  • The header field offsets and sizes, including the RA SRAM block at 0x1B0 with its type byte at 0x1B2 and start and end at 0x1B4/0x1B8.
  • The checksum: big-endian words from 0x200, with a trailing half word skipped.
  • The MC68000 vector names.
  • SMD de-interleaving: the first half of each 16 KiB block holds the odd bytes.

Noted, not changed:

  • Genesis Plus GX sums the checksum to the loaded size; this module sums to the declared ROM end and reports the difference. That is a deliberate choice.
  • Genesis Plus GX also detects byte-swapped dumps and copier headers without the AA BB marker. Those files are left unrecognized here rather than misread.

Sources: DeepWiki on ekeeke/Genesis-Plus-GX (core/loadrom.c: getrominfo, get_region, load_rom, sram_init) and on Stephane-D/SGDK (src/boot/rom_head.c and src/boot/sega.s), plus the MC68000 exception vector table. DeepWiki couldn't serve ares or BlastEm.

Validation:

  • build:cached, check:fast, docs:check and the advertised-schema check pass.
  • test:local on the Mega Drive, recognition and format-vocabulary tests passes: 5 files, 116 tests.
  • test:focused on artifactProvider.standaloneFormats passes.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/megaDriveRom.ts Resolved
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

CI note: "Test shard (6/12)" and "Portable tests" fail on this PR's merge with main, not on its own changes. The failing test is tests/boundary/cli/cliOptionAliases.test.ts, which reports -thin in the help of inspect-dwarf-units, inspect-go-binary, inspect-native-initializers and inspect-rust-binary.

That text comes from #14881 on main ("as lipo -thin does"). The test passes on this branch, which doesn't contain #14881. The fix is in #14912. Once it lands, this PR's CI should pass on a rerun.

… 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.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Brittleness pass, pushed as 9cc5e59.

Found and fixed:

  • Magic offsets. Header field offsets and lengths were literals repeated at each read, and device support was sliced twice from separate literals. One TEXT_FIELDS table now holds them, along with named checksum, ROM and RAM offsets and an EXTERNAL_RAM block for the marker, type, start and end. Each cites SGDK rom_head.c and Genesis Plus GX getrominfo/sram_init.
  • Duplicated SMD decision. Recognition (smdSegaFileOffset) and deinterleaveSmd each encoded which block half holds the odd bytes. Both now use SMD_ODD_HALF/SMD_EVEN_HALF, and the block count comes from the de-interleaved image instead of being recomputed.
  • Mirror test. The SMD test only round-tripped the fixture through its own inverse, so a wrong half order in both would pass. It now pins the fixture's file bytes to Genesis Plus GX deinterleave_block: second half to even offsets, first half to odd.
  • From the earlier commit 3061c9f:
    • The work-RAM check compared full 32-bit values, so SGDK's 0xE0FF0000 headers were wrongly reported as incomplete.
    • A lone A/B/E region was decoded by first match. It is now reported as ambiguous, with both readings, because the references disagree.

References disagree, kept visible rather than picked silently:

  • Checksum end. Genesis Plus GX sums to the loaded size; this module sums to the declared ROM end and reports a range past the image or a mismatch.
  • 0x180–0x18D. SGDK declares one 14-byte serial; Genesis Plus GX reads a 2-byte type and a 12-byte product ID; this module keeps the common 12-byte serial plus 2-byte revision. All three keep raw_hex. I left this split as is because changing it would change the metadata contract, and nothing is lost.
  • SMD detection. Genesis Plus GX also accepts a copier header without AA BB and a byte-swapped BIN. This module leaves those unrecognized rather than guessing.

Deliberately left: parseMegaDriveImage still exceeds oxlint's function-length and complexity limits. Splitting it is a larger change than these fixes need.

Sources:

  • DeepWiki on ekeeke/Genesis-Plus-GX (core/loadrom.c: getrominfo, get_region, load_rom, deinterleave_block, sram_init).
  • DeepWiki on Stephane-D/SGDK (src/boot/rom_head.c, src/boot/sega.s).
  • The MC68000 exception vector table.
  • DeepWiki could not serve ares or BlastEm.

Validation: test:local on the four Mega Drive and recognition files passes (52 tests), as do oxlint and oxfmt. CI on this head still needs #14912 on main; see the earlier note.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/megaDriveRom.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/artifactFormatRecognition.ts Resolved
…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.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 18:27
@morluto
morluto disabled auto-merge November 27, 2026 20:01
# 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
Comment thread docs/.vitepress/documentation.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/megaDriveRom.ts Resolved
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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/domain/megaDriveRom.ts Resolved
# 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.
Comment thread src/domain/megaDriveRom.ts Resolved
Comment thread docs/guides/firmware/mega-drive-roms.md Resolved
… 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.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 21:46
@morluto
morluto merged commit ba1ddff into morluto:main Nov 27, 2026
57 checks passed
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Appreciate you landing these, @morluto. This PR lets REA read Mega Drive and Genesis ROM headers offline, and #14897 lists Mach-O function starts and data-in-code entries for stripped binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants