Skip to content

cpu: mirror chip RAM across the chip window by Agnus address reach#197

Merged
LinuxJedi merged 2 commits into
mainfrom
fix/chip-window-agnus-reach
Jul 15, 2026
Merged

cpu: mirror chip RAM across the chip window by Agnus address reach#197
LinuxJedi merged 2 commits into
mainfrom
fix/chip-window-agnus-reach

Conversation

@LinuxJedi

Copy link
Copy Markdown
Owner

Fixes #196.

Root cause

The Action Replay freeze-disk loader on the attached disk restores the frozen machine from inside Supervisor() with SP = $100000. On a real 512K OCS A500 that works because the 8371 Agnus only decodes A1-A18: the 512K chip RAM image mirrors across the whole $000000-$1FFFFF chip window, so the stack pushes at $0FFFFC land at physical $7FFFC (top of chip RAM).

Copperline decoded chip RAM only within its fitted size, leaving the rest of the window unmapped: the loader's pushes vanished into open bus, the return popped 0, and the resulting exception cascade rebooted the machine. The guru #00000287.00C05170 is KS 1.3 displaying the stored garbage alert after that reboot (the "address" is the CLI task in slow RAM), which is why it appears "at the end of loading". Adding more chip RAM (1MB) hid the problem because $0FFFFC then had real RAM behind it.

Fix

CPU-side chip decode now models the real address path: the motherboard decode (Gary and equivalents) routes the whole $000000-$1FFFFF window to Agnus, which decodes only its DRAM reach (the existing AgnusRevision::dma_addr_capability_mask()):

  • OCS 8370/8371: the 512K image repeats at $080000/$100000/$180000
  • 8372A: the 1M image repeats at $100000 (A20 unused); an unfitted second bank stays open bus
  • 8375/Alice: the full window is decoded, no behaviour change

One helper (CpuBus::chip_window_offset) feeds every CPU path (reads, writes, prefetch, caches, GDB, debugger views). Writes through an image repeat report the canonical chip address to watchpoints and UI highlights.

Verification

  • The issue's freeze disk now restores and the game resumes on KS1.3 / OCS / 512K chip + 512K slow, matching vAmiga on the identical config (A500_OCS_1MB) and the reporter's real A500
  • Kickstart chip sizing still detects the wrap: AmigaTestKit reports Chip 0.50/Slow 0.50 MB on KS 1.2 and 1.3, OCS and 8372A, and Chip 1.00 MB with 1M fitted
  • Two new unit tests cover the reach model (real-CPU access through mirrors + per-revision alias/open-bus decode); the debugger mem-find test now walks the alias hits
  • Full unit suite, all 20 golden probes (unchanged, no re-bless), image regressions (except the known host-flaky ocs_bpu7_ham perf test), clippy and fmt all pass
  • Model documented in docs/internals/chipset.md

The motherboard decode (Gary and equivalents) routes the whole
$000000-$1FFFFF window to Agnus, which only decodes as many address
bits as its DRAM reach, so the fitted chip RAM image repeats across
the window: an OCS 8370/8371 mirrors its 512K image at
$080000/$100000/$180000, the 1M 8372A (A20 unused) repeats its image
at $100000, and the 2M 8375/Alice decode the full window. Within one
image, addresses past the fitted RAM select no DRAM bank and stay
open bus, e.g. $080000-$0FFFFF on an 8372A with 512K fitted.

Copperline previously decoded chip RAM only within its fitted size and
left the rest of the window unmapped. Action Replay freeze-disk
loaders park the supervisor stack at $100000 on a 512K OCS machine and
rely on the pushes landing at the top of chip RAM; without the mirror
the pushes vanished, the return popped 0, and the exception cascade
rebooted into a garbage guru (issue #196, Brian the Lion AR freeze on
512K chip + 512K slow). With the mirror the freeze restores and the
game resumes, matching real OCS hardware and vAmiga.

Writes through an image repeat report the canonical chip address to
watchpoints and UI highlights. Kickstart's chip sizing detects the
wrap and still reports the fitted size (verified with AmigaTestKit on
KS 1.2/1.3 x OCS/8372A with 512K and 1M chip). The debugger memory
find now walks the alias hits, so its test asserts the image-repeat
addresses.

Fixes #196
Copilot AI review requested due to automatic review settings July 15, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes incorrect CPU-visible chip RAM decoding by mirroring the fitted chip RAM image across the full $000000–$1FFFFF chip window according to the active Agnus revision’s address reach, matching real hardware behavior (fixes #196).

Changes:

  • Add CPU-side chip-window decoding via CpuBus::chip_window_offset, using AgnusRevision::dma_addr_capability_mask() to model per-revision mirroring and open-bus gaps.
  • Update debugger/UI memory-find test expectations to include mirror hits across the chip window.
  • Document the chip-window mirroring model and introduce a shared CHIP_WINDOW_SIZE constant.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/video/window/tests.rs Updates debugger mem-find UI test to expect repeated matches at chip RAM mirror addresses.
src/memory.rs Introduces CHIP_WINDOW_SIZE and documents the motherboard-to-Agnus chip window behavior.
src/cpu.rs Implements chip-window address folding for CPU plain-memory decode and adds unit tests for mirroring/open-bus behavior.
docs/internals/chipset.md Documents CPU-visible chip RAM reach/mirroring and the Action Replay regression example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cpu.rs Outdated
A chip write through an Agnus image repeat lands in one RAM cell that
is CPU-visible at several addresses, and watchpoints store the address
the user set them on. Note the CPU bus address and the canonical chip
address (when they differ) so watches and UI highlights fire whichever
alias they were set on.
@LinuxJedi LinuxJedi merged commit 42d6e35 into main Jul 15, 2026
9 checks passed
@LinuxJedi LinuxJedi deleted the fix/chip-window-agnus-reach branch July 15, 2026 18:12
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.

A perhaps interesting memory config behaviour

2 participants