Skip to content

Commit da64be0

Browse files
committed
docs: tighten DMG hardening handbook consistency
1 parent 2e14f71 commit da64be0

11 files changed

Lines changed: 171 additions & 9 deletions

File tree

AI/ARCHITECTURE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ to immediately materialize as a separate directory.
301301
- watchpoints
302302
- snapshots
303303
- state inspection
304+
- targeted subsystem viewers or equivalent structured dumps for CPU, scheduler, PPU, DMA, APU, IRQ, and cartridge state
304305
- internal analysis and comparison tools
305306
- utilities for synchronization and trace-debug workflows
306307

AI/REFERENCES.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ Primary documentation should be consulted before using emulator source code as g
1818
## Test ROMs and executable references
1919

2020
- blargg test ROMs
21+
- retrio/gb-test-roms — https://github.com/retrio/gb-test-roms
2122
- dmg-acid2 — https://github.com/mattcurrie/dmg-acid2
2223
- cgb-acid2 — https://github.com/mattcurrie/cgb-acid2
2324
- mealybug-tearoom-tests — https://github.com/mattcurrie/mealybug-tearoom-tests
2425
- Mooneye GB test suite — https://github.com/Gekkio/mooneye-gb
26+
- SameSuite — https://github.com/LIJI32/SameSuite
27+
- GB Accuracy Tests — see the awesome-gbdev testing section below
28+
- 144p Test Suite — see the awesome-gbdev testing section below
29+
- MBC3 RTC test ROMs — see the awesome-gbdev testing section below
2530

2631
## Community indexes
2732

2833
- gbdev resources — https://gbdev.io/resources/
2934
- awesome-gbdev — https://github.com/gbdev/awesome-gbdev
35+
- use the awesome-gbdev testing section to discover and cross-check broader external DMG-closure suites that are not listed above directly
3036

3137
## Audio references
3238

@@ -61,10 +67,10 @@ This default order balances coverage, maintainability, and accessibility; it is
6167

6268
## Practical specialization by reference
6369

64-
- SameBoy: best general reference and the practical ceiling for DMG/CGB behavior, LCD timing, audio, and compatibility study.
70+
- SameBoy: best general reference and the practical ceiling for DMG/CGB behavior, LCD timing, audio, and compatibility study; use it as the primary DMG differential oracle when comparable traces or observables are available.
6571
- binjgb: strong reference for timing, CPU/bus behavior, and compact architecture.
6672
- GameRoy: useful reference for idiomatic Rust-oriented structure.
6773
- accurateboy: especially valuable for PPU, fetcher, and pixel FIFO behavior.
6874
- Mooneye GB: strong documentary and edge-case reasoning reference.
6975
- Danger Boy: useful smaller codebase for DMG timing study.
70-
- Gambatte: historical high-accuracy reference and a strong corroborating oracle for practical accuracy and corner cases.
76+
- Gambatte: historical high-accuracy reference and a strong corroborating oracle for practical accuracy and corner cases; use it as the secondary DMG differential oracle when triangulation or arbitration is needed.

AI/ROADMAP.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,68 @@ Build the audio subsystem as a real temporal part of the hardware, integrated wi
11571157

11581158
---
11591159

1160+
### Phase 8 — Block AP: final DMG hardening, differential validation, and closure
1161+
1162+
This phase is the roadmap home for the final DMG closure work. Parts of it should begin earlier, but the block only closes once the project can justify DMG correctness through layered evidence on the shared T-cycle model rather than through informal game compatibility.
1163+
1164+
#### Goal
1165+
1166+
Close the DMG core with a formal validation matrix, strong differential and determinism tooling, and explicit closure criteria that leave no major blind hardware areas behind.
1167+
1168+
#### Modules involved
1169+
1170+
- `tests/`
1171+
- `gb-test-runner/`
1172+
- `debugger/`
1173+
- `scheduler/`
1174+
- subsystem cores as needed for per-area traces and inspections
1175+
- frontend or tooling adapters only where they are needed for capture, visualization, or artifact export
1176+
1177+
#### Deliverables
1178+
1179+
- formal DMG hardening matrix with layers `A/B/C/D/E`, severity classes, and explicit `must-pass` areas
1180+
- automated external-ROM harness with timeout, pass/fail policy, framebuffer and serial capture, and retained failure artifacts
1181+
- differential comparison tooling for SameBoy and Gambatte with first-divergence reporting and short T-cycle windows
1182+
- deterministic replay, save/load determinism, and longer-running soak coverage
1183+
- minimum closure-ready debugging tooling: traces, breakpoints, watchpoints, snapshots, and targeted subsystem viewers
1184+
- explicit DMG closure checklist covering internal suites, external suites, differential comparison, determinism, save/load determinism, and primary cartridge families
1185+
1186+
#### Recommended sequencing inside Phase 8
1187+
1188+
1. Formalize the DMG hardening matrix and closure severity policy.
1189+
Scope: define layers `A/B/C/D/E`, `must-pass` versus non-blocking categories, minimum DMG closure suites, and the rule that no single layer substitutes for another.
1190+
Acceptance criteria: the project docs name the closure layers explicitly, identify the blocking hardware areas for DMG closure, and define a stable checklist instead of relying on informal compatibility claims.
1191+
2. Build the external ROM harness and minimum closure suites.
1192+
Scope: automate CPU / interrupt ROMs, `dmg-acid2`, and `mealybug-tearoom-tests`; support framebuffer and serial capture; define timeouts, pass/fail rules, and retained artifacts; and keep explicit reserved follow-up slots for broader closure suites such as Mooneye / Gekkio coverage, SameSuite, GB Accuracy Tests, 144p Test Suite, and MBC3 RTC-focused ROMs.
1193+
Acceptance criteria: the minimum DMG closure ROM suites run without manual screen inspection, every case has a timeout plus explicit pass/fail policy, and the harness can preserve enough output to debug failures offline.
1194+
3. Add differential comparison against SameBoy and Gambatte.
1195+
Scope: end-of-test comparison, end-of-instruction comparison, short T-cycle-window comparison, and first-divergence localization with archived context.
1196+
Acceptance criteria: SameBoy acts as the default primary DMG oracle, Gambatte is available for triangulation, disagreements between the oracles are marked for arbitration rather than auto-pass, and the tooling can report the first divergence instead of only a final mismatch.
1197+
4. Close the minimum debugging and inspection tooling.
1198+
Scope: instruction / micro-op / short-window T-cycle tracing, breakpoints and watchpoints on `PC`, memory, MMIO, and cartridge-bank state, plus fast inspection of CPU, scheduler, bus owner, PPU mode / dot / `LY`, DMA, timer, APU, and cartridge / MBC state.
1199+
Acceptance criteria: a blocking divergence can be localized without a long blind rerun, and the project has practical viewers or equivalent dumps for PPU, cartridge / MBC, APU, and IRQ state.
1200+
5. Lock determinism, replay, save/load determinism, soak, and regression retention.
1201+
Scope: same-ROM replay with identical input stream and injected time source, mid-run save/load equivalence, longer-running soak cases, and a permanent regression path for every important hardening bug.
1202+
Acceptance criteria: repeated runs converge exactly under the same inputs and injected time source, save/load continuation matches uninterrupted execution, soak coverage includes at least one real game plus long-running synthetic coverage, and fixed hardening bugs leave behind permanent regression assets.
1203+
1204+
#### Done criteria
1205+
1206+
- core unit and short integration suites for the blocking DMG areas are green
1207+
- the minimum external closure suites are green
1208+
- differential comparison either shows no unexplained divergence in the covered scenarios or records the remaining arbitrations explicitly
1209+
- deterministic replay and save/load determinism are green
1210+
- no severe open correctness bugs remain in `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, or `Mbc5`
1211+
- the project has an explicit DMG closure checklist instead of relying on a general compatibility impression
1212+
1213+
#### Risks if omitted or overly simplified
1214+
1215+
- false confidence from a few booting games or one passing smoke suite
1216+
- unresolved blind spots in scheduler ordering, timing, or cartridge behavior
1217+
- repeated rediscovery of the same bugs because regressions were never turned into permanent assets
1218+
- inability to explain oracle divergences without expensive manual debugging sessions
1219+
1220+
---
1221+
11601222
## Final order summary
11611223

11621224
1. Test model and test ROM strategy
@@ -1203,6 +1265,11 @@ Build the audio subsystem as a real temporal part of the hardware, integrated wi
12031265
35. APU channel 3
12041266
36. APU channel 4
12051267
37. Mixing, output, DACs, power control, and audio edge cases
1268+
38. Formal DMG hardening matrix, severity classes, and closure checklist
1269+
39. Automated external ROM harness and minimum closure suites
1270+
40. Differential comparison against SameBoy and Gambatte
1271+
41. Deterministic replay, save/load determinism, and soak coverage
1272+
42. Final DMG closure and regression-retention pass
12061273

12071274
---
12081275

@@ -1252,6 +1319,10 @@ Suggested entry style:
12521319

12531320
- None currently.
12541321

1322+
### Phase 8 — Block AP: final DMG hardening, differential validation, and closure
1323+
1324+
- None currently.
1325+
12551326
---
12561327

12571328
## Final notes

AI/TESTING.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Use multiple layers:
88
- subsystem integration tests
99
- ROM-based validation
1010
- oracle comparisons where useful
11+
- determinism, replay, and longer-running regression coverage
1112

1213
## Authority and scope
1314

@@ -25,6 +26,49 @@ Every subsystem change should aim to leave behind one of these:
2526
- a documented oracle comparison when timing or ordering is under review
2627
- a characterization test before structural refactors in behavior-sensitive code
2728

29+
## Final DMG hardening policy
30+
31+
- Do not treat "boots a few commercial games" or "one final framebuffer looks right" as DMG closure.
32+
- Final DMG hardening must demonstrate, at the same time, subsystem-local correctness, deterministic behavior on the shared T-cycle timeline, differential agreement with trusted oracles, and enough tooling to explain a divergence without blind refactoring.
33+
- Use a formal multilayer validation matrix rather than one oversized suite or informal compatibility anecdotes.
34+
- No single layer substitutes for another: unit tests do not replace test ROMs, test ROMs do not replace differential comparison, and differential comparison does not replace determinism or replay.
35+
36+
## Final DMG hardening matrix
37+
38+
- `Layer A`: focused unit tests per subsystem, including CPU micro-ops and state machine behavior, interrupts and `IME` / `HALT` / `STOP`, timer and divider edges, bus arbitration, PPU mode timing plus fetcher/FIFOs/window/sprites, DMA, joypad, serial, cartridge/MBC behavior, APU channel and mixer behavior, and exact save-state restore paths.
39+
- `Layer B`: short integration tests for timing-coupled interactions such as timer plus interrupts, DMA plus bus plus CPU, PPU plus DMA plus VRAM/OAM blocking, serial plus interrupt plus scheduler, joypad plus `STOP` / `HALT` plus interrupt, cartridge plus bus plus boot-ROM overlay, and APU plus `DIV-APU` plus MMIO writes.
40+
- `Layer C`: external test ROM suites grouped by hardware category and run through automation rather than manual screen inspection.
41+
- `Layer D`: differential comparison against trusted emulator oracles, with the ability to localize the first divergence instead of reporting only one final mismatch.
42+
- `Layer E`: determinism, replay, save/load determinism, soak, and regression-retention coverage over medium and long runs.
43+
- For this T-cycle-based core, the matrix should support several validation granularities: end of test, end of instruction, and short per-T-cycle windows when a timing-sensitive divergence needs to be isolated.
44+
- Every corrected bug should end up attached to at least one permanent layer in this matrix.
45+
46+
## External ROM harness policy
47+
48+
- Test ROM execution must be automatable; manual inspection of the LCD is an auxiliary debugging aid, not the primary acceptance path.
49+
- The harness should support at least framebuffer capture and serial / link-port capture when the ROM exposes machine-readable output there.
50+
- Prefer serial / link-port capture for suites such as Blargg `cpu_instrs` when that path is available, because it avoids treating a scrolling framebuffer as the primary machine-readable result channel.
51+
- Each ROM case should define a timeout, an explicit pass/fail rule, and retained failure artifacts such as serial output, framebuffer output, trace excerpts, and optional snapshots.
52+
- The minimum DMG closure baseline should include automated CPU / interrupt coverage through `retrio/gb-test-roms` or equivalent Blargg automation, `dmg-acid2` for basic DMG PPU validation, and `mealybug-tearoom-tests` for fine PPU rendering / timing validation.
53+
- Keep explicit roadmap space for broader closure suites such as Mooneye / Gekkio coverage, SameSuite, GB Accuracy Tests, 144p Test Suite, and MBC3 RTC-focused ROMs.
54+
55+
## Differential oracle policy
56+
57+
- Use SameBoy as the primary differential oracle for DMG behavior whenever comparable observables are available.
58+
- Use Gambatte as a secondary oracle when triangulation adds value or when a SameBoy-only result still needs corroboration.
59+
- Differential comparison should support at least three granularities: end of test, end of instruction, and short T-cycle windows for reduced scenarios.
60+
- Prefer a clear "first point of divergence" workflow over one final hash or framebuffer mismatch.
61+
- When SameBoy and Gambatte agree and this project differs, treat the discrepancy as a project bug by default until evidence shows otherwise.
62+
- When the oracles disagree, mark the case as requiring arbitration rather than silently accepting one side as correct.
63+
64+
## Validation tooling requirements
65+
66+
- Hardening-ready validation requires trace logging at instruction level, micro-op level, and short T-cycle windows.
67+
- Breakpoints and watchpoints should cover at least `PC`, memory addresses, MMIO registers, and cartridge-bank or mapper-visible state.
68+
- Fast state inspection should expose CPU, scheduler, current bus owner, PPU mode / dot / `LY`, active DMA state, timer pipeline state, APU state, and cartridge / MBC state.
69+
- Specialized debug views for PPU internals, cartridge / MBC banks and raw registers, APU channels plus final mix, and IRQ / `IF` / `IE` / `IME` state are strongly recommended because they shorten divergence analysis substantially.
70+
- Instrumentation must not alter the core's hardware-visible behavior or reorder the shared T-cycle timeline.
71+
2872
## New-code baseline
2973

3074
- New production code should normally introduce automated unit tests or integration tests in the same change.
@@ -155,10 +199,15 @@ Include dedicated CH4 quirk tests for ordinary `15`-bit mode, ordinary `7`-bit m
155199

156200
## Recommended external validation sources
157201

202+
- retrio/gb-test-roms
158203
- blargg test ROMs
159204
- Mooneye tests
160205
- dmg-acid2 / cgb-acid2
161206
- mealybug-tearoom-tests
207+
- SameSuite
208+
- GB Accuracy Tests
209+
- 144p Test Suite
210+
- MBC3 RTC test ROMs
162211

163212
## Behavioral cross-check policy
164213

@@ -174,13 +223,34 @@ When a change affects observable timing or ordering:
174223
- Tests should prefer reproducible stepping and explicit expected state over fuzzy assertions.
175224
- Instrumentation should not change hardware-visible behavior.
176225
- Battery-backed RTC persistence tests must use an injected or otherwise explicit time source rather than the host wall clock.
226+
- Determinism coverage should include replay from the same ROM plus input stream, save/load determinism, and at least some longer-running soak cases.
227+
- "Same ROM + same input stream + same injected time source => same result" is the intended project contract.
228+
- Save/load determinism should prove that saving, restoring, and continuing produces the same result as uninterrupted execution.
229+
- Soak coverage should include at least one real game, one longer-running test ROM, and one or two cases with APU activity plus banked cartridges.
177230

178231
## Regression policy
179232

180-
Every fixed bug should leave behind:
233+
- Every fixed bug should leave behind at least one permanent regression asset.
234+
- Use a focused unit or integration test when the bug is local to one subsystem or one cross-subsystem interaction.
235+
- Use a ROM-based reproduction case when the bug is systemic or easiest to demonstrate through an external suite.
236+
- Use a stored differential case when the bug was discovered by comparison against SameBoy, Gambatte, or another explicit oracle.
237+
- Keep regression organization by subsystem or hardware area so repeated failures do not disappear into one catch-all bucket.
238+
- Differential regressions should preserve enough reproduction context to rerun them quickly, including the ROM, input stream, injected seed or time source when relevant, first divergence point, and an optional snapshot when that reduces debug time.
239+
240+
## Severity and DMG closure policy
241+
242+
- Classify failures by closure impact instead of treating all red tests as equally important.
243+
- Treat scheduler ordering, CPU / interrupts, timer, PPU timing, DMA, primary cartridge families, basic joypad / serial behavior, and save/load determinism as `must-pass` DMG closure areas.
244+
- Treat finer APU behavior, serial edge cases beyond the baseline path, and RTC-specific long-tail work as high-importance compatibility items unless the roadmap explicitly promotes them to `must-pass`.
245+
- Keep optional tooling polish, special-cartridge heuristics, and experimental paths outside the `must-pass` gate unless they are needed to explain or reproduce a blocking core bug.
246+
- Do not declare DMG closed while `NoMbc`, `Mbc1`, `Mbc2`, `Mbc3`, or `Mbc5` still have open severe correctness bugs, or while CPU / interrupts, timer, PPU, DMA, basic joypad / serial, or save/load determinism coverage is still failing.
247+
- Keep a project-visible DMG closure checklist that includes internal core suites, minimum external suites, differential comparison, determinism, save/load determinism, and primary cartridge-family status.
248+
249+
## CI stratification policy
181250

182-
- a focused automated test, or
183-
- a documented ROM-based reproduction case
251+
- The regular CI path should always run critical unit tests, critical short integration tests, a stable subset of external ROMs, and save/load determinism coverage.
252+
- Longer differential runs, soak tests, and broader external ROM inventories may live in nightly or manual suites, but they must remain documented and runnable.
253+
- Failure artifacts should include enough information to debug without rerunning blindly, such as logs, optional snapshots, framebuffer output when relevant, and a diff against the reference output when one exists.
184254

185255
## Test organization policy
186256

AI/TIMING-AND-ACCURACY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ When implementing timing:
3939
- state which source supports the model
4040
- avoid claiming global cycle accuracy from local evidence
4141

42+
## Closure and validation claims
43+
44+
- Do not treat "boots a few games" as evidence that DMG timing is closed.
45+
- Do not treat one matching final framebuffer as sufficient evidence for a timing-sensitive subsystem when the path to that output is still unverified.
46+
- Closing a timing-sensitive DMG subsystem should rest on layered evidence: focused automated tests, ROM-based validation, trusted-oracle comparison, and determinism checks.
47+
- Because this project is T-cycle based, the validation stack should be able to compare behavior at end-of-test, end-of-instruction, and short per-T-cycle windows when locating the first divergence matters.
48+
- If coarser summaries are used for ergonomics, keep a path back to the underlying T-cycle ordering rather than hiding it behind aggregate instruction or frame-level claims.
49+
- Trace, comparison, and debugging instrumentation must preserve the same hardware-visible T-cycle behavior they are trying to explain.
50+
4251
## Modeling policy
4352

4453
- Prefer explicit clock ownership.

0 commit comments

Comments
 (0)