Skip to content

Commit 7d0660d

Browse files
committed
docs: align handbook cartridge policy
1 parent da5e208 commit 7d0660d

5 files changed

Lines changed: 157 additions & 25 deletions

File tree

AI/ARCHITECTURE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ to immediately materialize as a separate directory.
227227
- decoded cartridge capability model including cartridge type, ROM size, RAM size, CGB flag, and SGB flag
228228
- explicit capability metadata for battery-backed RAM, RTC, and rumble derived from the validated header type
229229
- central cartridge factory and validation policy
230+
- typed loader result that separates supported cartridge construction from structured special / unsupported classification, preserving raw `0x0147`, detected name, category, and reason
230231
- concrete cartridge devices such as `NoMbcCartridge`, `Mbc1Cartridge`, `Mbc2Cartridge`, `Mbc3Cartridge`, and `Mbc5Cartridge`
231232
- No MBC family support, including the `0x00`, `0x08`, and `0x09` header variants
232233
- MBC implementations
233-
- explicit first-pass taxonomy such as `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, `Mbc5`, and `Unsupported`
234+
- explicit supported-family taxonomy such as `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, and `Mbc5`, plus structured unsupported categories rather than one opaque `Unsupported`
235+
- reserved typed variant space for close derivatives such as `MBC30` and future `MBC1M`
236+
- separate classification path for special multicarts, documented-but-unsupported mappers, accessory cartridges, experimental heuristics, and unknown codes
234237
- explicit separation between raw mapper register state, header-derived wiring / variant metadata, mapper-local RAM organization, and helper logic that resolves effective ROM and RAM banks
235238
- cartridge-visible RAM, whether external or mapper-local to the mapper
236239
- RTC-backed cartridges

AI/ROADMAP.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Build the real foundation of the emulated system on top of which CPU, timer, DMA
270270
- base cartridge interface for the No MBC family and later MBC-backed devices
271271
- `No MBC` as the first closed reference cartridge rather than a generic fallback path
272272
- cartridge integration with the bus
273-
- central cartridge factory that selects `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, `Mbc5`, or explicit `Unsupported` from `0x0147`
273+
- central cartridge factory that selects a supported device or a structured special / unsupported classification from `0x0147`
274274
- explicit validation of declared ROM/RAM metadata against the loaded image with a configurable policy
275275
- clean separation between bus logic and cartridge-specific logic
276276

@@ -301,6 +301,7 @@ Build the real foundation of the emulated system on top of which CPU, timer, DMA
301301
- the cartridge subsystem parses `0x0100-0x014F` into a typed header structure and preserves CGB/SGB compatibility flags for later work
302302
- a functional No MBC cartridge family exists as the first closed reference cartridge, covering `0x00`, `0x08`, `0x09`, linear `32 KiB` ROM, optional linear `8 KiB` RAM, and ignored ROM-space writes with no hidden bank state
303303
- cartridge implementation selection comes from `0x0147` rather than from ROM-size heuristics
304+
- special and unsupported cartridge types are classified explicitly with raw `0x0147`, detected name, category, and reason rather than one opaque fallback bucket
304305
- declared ROM size and RAM size are validated explicitly instead of being trusted silently
305306
- the bus can access `0x0000-0x7FFF` and `0xA000-0xBFFF` through a base cartridge interface without knowing which MBC is active
306307
- ROM-space writes are routed as cartridge commands instead of fake ROM mutations
@@ -349,9 +350,9 @@ They do not move full joypad, serial, audio, or timing-complete PPU implementati
349350
2. Define the base cartridge interface.
350351
Acceptance criteria: the bus can read `0x0000-0x7FFF` and `0xA000-0xBFFF` without knowing the active MBC, ROM-space writes route to cartridge commands, and header bytes remain visible through ordinary ROM bank `0` reads.
351352
3. Add the cartridge factory.
352-
Acceptance criteria: the loader selects `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, `Mbc5`, or explicit `Unsupported` from `0x0147`, and unsupported types produce clear diagnostics.
353+
Acceptance criteria: the loader selects `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, `Mbc5`, or a structured special / unsupported classification from `0x0147`, and unsupported types preserve raw `0x0147`, detected name, category, and reason for diagnostics.
353354
4. Close validation and diagnostics policy.
354-
Acceptance criteria: ROM-size and RAM-size metadata are checked explicitly, size mismatches produce useful warnings or errors, special ROM-size codes are not ignored silently, and the project exposes a configurable strict-versus-permissive policy.
355+
Acceptance criteria: ROM-size and RAM-size metadata are checked explicitly, size mismatches produce useful warnings or errors, special ROM-size codes are not ignored silently, documented-but-unsupported cartridge types fail in a controlled way without mapper fallback, and the project exposes a configurable strict-versus-permissive policy with heuristics disabled by default in strict mode.
355356

356357
##### No MBC milestone
357358

@@ -780,6 +781,7 @@ Extend `cartridge/` from the closed No MBC baseline to banked commercial cartrid
780781
- standard MBC2 support with address-bit-`8` control decode, internal `512 x 4-bit` RAM, echo aliasing, and explicit header validation
781782
- banking and RTC support for MBC3
782783
- banking support for MBC5
784+
- special-cartridge taxonomy and unsupported policy covering `MBC30`, multicarts, documented-but-unsupported mapper families, accessory cartridges, and optional heuristics
783785
- functional mapper-controlled external RAM beyond the No MBC linear baseline
784786
- typed cartridge persistence contracts for full backing stores such as linear SRAM, banked SRAM, MBC2 nibble RAM, and MBC3 SRAM plus RTC
785787
- portable persistence boundaries across frontends and tools
@@ -866,6 +868,24 @@ Extend `cartridge/` from the closed No MBC baseline to banked commercial cartrid
866868
Scope: unit tests, integration tests, ROM-based coverage, and at least one trusted oracle comparison for bank-selection and rumble edge cases.
867869
Acceptance criteria: tests cover header types `0x19..=0x1E`, bank `0` visibility in the switchable region, bank `0x1FF`, `9`-bit ROM-bank selection across the `0xFF -> 0x100` boundary, RAM-enable behavior, SRAM behavior for `8 KiB` / `32 KiB` / `128 KiB`, RAM-bank masking, rumble on/off, and size-validation diagnostics.
868870

871+
#### Special-cartridge and unsupported-policy sequencing inside Phase 6
872+
873+
1. Establish the special-cartridge taxonomy and unsupported categories.
874+
Scope: one central classification path for `Supported`, `PlannedVariant`, `DocumentedButUnsupported`, `ExperimentalHeuristic`, `AccessorySpecialCase`, and `UnknownCode`, plus stable names for `MBC30`, `MBC1M`, `MMM01`, `M161`, `HuC1`, `HuC-3`, `MBC6`, `MBC7`, `Pocket Camera`, `Bandai TAMA5`, `EMS`, `Bung`, and `Wisdom Tree`.
875+
Acceptance criteria: the loader produces stable classification for all of those cases, the frontend does not need to reparse headers to explain them, and the classification preserves raw `0x0147`, detected name, category, and reason.
876+
2. Add explicit `MBC30` detection.
877+
Scope: detect the `MBC3`-family plus `64 KiB` SRAM case as `MBC30`, return a typed planned variant or supported variant entry point instead of ordinary standard `MBC3`, and reserve matching persistence / banking work.
878+
Acceptance criteria: `MBC3 + 64 KiB SRAM` never falls through to standard `MBC3`, loader diagnostics name `MBC30` explicitly, and the code path is ready for future concrete `MBC30` implementation.
879+
3. Add multicart and near-variant classification.
880+
Scope: classify `MMM01` from `0x0B..=0x0D`, reserve future `MBC1M` as a distinct `MBC1`-family variant, keep `M161` in a multicart-special path, and avoid assuming that `MMM01` boot/header handling is identical to standard cartridges.
881+
Acceptance criteria: `0x0B`, `0x0C`, and `0x0D` are emitted as `MMM01`, `MBC1M` remains a separate future variant instead of being merged into standard `MBC1`, and multicarts do not silently degrade to ordinary `MBC1` or `NoMbc`.
882+
4. Enforce controlled failure for documented special hardware.
883+
Scope: explicit diagnostics for `HuC1`, `HuC-3`, `MBC6`, `MBC7`, `Pocket Camera`, `Bandai TAMA5`, and `M161`, plus a hard rule against automatic fallback to `MBC1`, `MBC3`, `MBC5`, or other nearby supported mappers.
884+
Acceptance criteria: those types fail with clear messages naming the exact detected cartridge, `UnknownCode` reports the raw `0x0147` byte, and no silent degradations or fake "best effort" mapper substitutions remain.
885+
5. Add optional experimental heuristic mode.
886+
Scope: isolate `EMS`, `Bung`, and `Wisdom Tree` detection behind an explicit dev / experimental loader policy, keep strict default behavior header-driven, and document that heuristic paths are lower priority than `MBC30`, multicarts, and documented special hardware.
887+
Acceptance criteria: heuristic detection is off by default, can be enabled explicitly for development and research, and diagnostics clearly state when a classification came from heuristics instead of a standard header mapping.
888+
869889
#### Persistence sequencing inside Phase 6
870890

871891
1. Define the cartridge persistent-state contract.
@@ -892,6 +912,7 @@ Extend `cartridge/` from the closed No MBC baseline to banked commercial cartrid
892912
- standard MBC2 behavior is modeled inside cartridge devices with explicit address-bit-`8` control decode, internal nibble RAM semantics, and mapper-local validation rather than generic external-SRAM assumptions
893913
- standard MBC3 behavior is modeled inside cartridge devices with explicit RAM-bank versus RTC-register selection, live-versus-latched RTC state, and a reserved future MBC30 extension point
894914
- MBC5 behavior is modeled inside cartridge devices with explicit `9`-bit ROM-bank state, valid switchable-region bank `0`, explicit RAM / battery / rumble variant handling, and observable cartridge-local rumble state
915+
- special cartridges and unsupported cases are classified explicitly, fail in a controlled way, and do not silently fall back to nearby supported mappers
895916
- RTC and persistence are properly encapsulated
896917
- hardware-style persistence stores full cartridge backing stores rather than whichever `0xA000-0xBFFF` mapping happened to be visible
897918
- only battery-backed cartridges auto-persist by default, while full emulator save states remain a separate system
@@ -1111,15 +1132,16 @@ Build the audio subsystem as a real temporal part of the hardware, integrated wi
11111132
26. MBC2
11121133
27. MBC3
11131134
28. MBC5
1114-
29. Banked external RAM, battery, RTC, persistence
1115-
1116-
30. General APU architecture
1117-
31. APU frame sequencer
1118-
32. APU channel 1
1119-
33. APU channel 2
1120-
34. APU channel 3
1121-
35. APU channel 4
1122-
36. Mixing, output, DACs, power control, and audio edge cases
1135+
29. Special cartridges and unsupported policy
1136+
30. Banked external RAM, battery, RTC, persistence
1137+
1138+
31. General APU architecture
1139+
32. APU frame sequencer
1140+
33. APU channel 1
1141+
34. APU channel 2
1142+
35. APU channel 3
1143+
36. APU channel 4
1144+
37. Mixing, output, DACs, power control, and audio edge cases
11231145

11241146
---
11251147

AI/TESTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ For timer behavior, include internal-counter-derived `DIV`, DIV-write glitches,
8888
For bus behavior, include blocked-access cases, boot ROM remapping, next-fetch behavior after `FF50`, and DMA-related contention whenever suitable tests exist.
8989
Include direct-boot routing checks that verify boot ROM is already unmapped, the ordinary cartridge ROM map is visible again across `0x0000-0x7FFF`, and DMG-mode reads of CGB-only registers return `0xFF` whenever suitable tests exist.
9090
Include region-contract tests for fixed ROM, switchable ROM, VRAM, cartridge external space, WRAM, echo RAM, OAM, unusable space, MMIO, HRAM, and `IE`, including aliasing, blocked-access semantics, and ownership-by-device whenever suitable tests exist.
91-
For cartridge loading and mapper selection, include tests for header parsing of `0x0143`, `0x0146`, `0x0147`, `0x0148`, and `0x0149`, explicit ROM-size versus file-size validation, unsupported-type diagnostics, and the `MBC2` internal-RAM special case whenever suitable tests exist.
91+
For cartridge loading and mapper selection, include tests for header parsing of `0x0143`, `0x0146`, `0x0147`, `0x0148`, and `0x0149`, explicit ROM-size versus file-size validation, structured unsupported-type diagnostics, and the `MBC2` internal-RAM special case whenever suitable tests exist.
92+
Include cartridge-loader classification tests for `Supported`, `PlannedVariant`, `DocumentedButUnsupported`, `ExperimentalHeuristic`, `AccessorySpecialCase`, and `UnknownCode`, preserving the raw `0x0147` byte, detected cartridge name, category, and diagnostic reason.
93+
Include tests that documented special cartridges such as `MBC30`, `MMM01`, `M161`, `HuC1`, `HuC-3`, `MBC6`, `MBC7`, `Pocket Camera`, and `Bandai TAMA5` are identified explicitly and do not silently fall back to nearby supported mappers.
94+
Keep heuristic `EMS` / `Bung` / `Wisdom Tree` detection behind an explicit experimental loader policy in tests as well; strict-mode coverage should confirm that those heuristics stay disabled by default.
9295
For the `No MBC` family, include explicit coverage for `0x00`, `0x08`, and `0x09`, linear `0x0000-0x7FFF` reads with no bank state, ignored `0x0000-0x7FFF` writes, `32 KiB` ROM validation, and explicit diagnostics when No MBC declares impossible ROM or RAM sizes.
9396
Include tests that `0xA000-0xBFFF` distinguishes absent RAM from present linear `8 KiB` RAM and that battery only changes persistence expectations rather than the visible map.
9497
Use No MBC as the first closed cartridge baseline for boot-overlay and post-boot routing checks so `FF50` handoff, `0x0100-0x014F` visibility, and ordinary cartridge reads are validated before mapper banking enters the picture.

0 commit comments

Comments
 (0)