Files
reverse-engineering-anything/docs/getting-started
ba1ddffd7e feat(artifacts): inspect Sega Mega Drive and Genesis ROM headers offline (#14895)
* feat(artifacts): inspect Sega Mega Drive and Genesis ROM headers offline

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.

* Address review feedback

* Address review feedback

* Address review feedback

* fix(artifacts): read Mega Drive work RAM on the 24-bit bus and keep ambiguous 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.

* refactor(artifacts): name Mega Drive header fields once and share the 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.

* fix(artifacts): model the Mega Drive 68000 bus once and decide SMD dumps 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.

* fix(docs): restore separate Mega Drive and N64 entries after the main merge

* fix(mega-drive): read ROM range and checksum window on the 24-bit bus

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.

* fix(artifacts): order every Mega Drive header range on the 24-bit bus

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.

* fix(artifacts): keep truncated region failures typed and publish Mega 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.

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-11-27 22:25:43 +00:00
..