This test is a culmination of the research I've done since this post in the general FDS emulation thread: viewtopic.php?p=302540#p302540
Here's the summary I have for it on my WIP article for hardware-verified register behaviours:
The discovery of this watchdog has been a fairly major revelation for me, since it means that commercial FDS games have quite literally been held together by a previously unknown feature this whole time. (as in, the watchdog is the only thing stopping games from executing decayed PRG-RAM contents). I've been working hard to research/document it so future FDS homebrew devs aren't caught out by this when testing their programs on real hardware. The ideal outcome is for emulators like Mesen2 to at least simulate the IRQs in order to aid with debugging.The 2C33 refreshes DRAM rows on CPU cycles spent accessing areas outside of PRG-RAM. The DRAM Refresh Watchdog tracks these refresh cycles along with CPU cycles. If interrupts are enabled in $4023.D7, the watchdog will assert an interrupt after a certain number of CPU cycles without enough refresh cycles. This is primarily triggered by small infinite loops (e.g. "everything in NMI") and long stretches of code which only access PRG-RAM. The currently known low-level implementation is as follows:
Ignoring the watchdog (by using SEI instructions, or disabling it via $4023) appears to result in DRAM decaying during the aforementioned scenarios. The exact behavior is currently not well understood and likely varies between RAM adapters. In particular, RAM adapters containing 4 DRAM chips may behave differently from RAM adapters containing only 1 DRAM chip.
- 7-bit refresh counter - reset to 0 while $4023.D0 = 0, increment on every CPU cycle spent accessing memory outside of PRG-RAM, pause on CPU cycles accessing PRG-RAM. This counter determines the DRAM row to refresh, much like how the Z80's R register is typically used.
- 12-bit CPU cycle timer - reset to all 1s (4095) while $4023.D0 = 0, reload with 3245 when refresh counter overflows, otherwise decrement on every CPU cycle. IRQ is asserted when the cycle timer underflows while $4023.D7 = 1.
The safest known approach for handling the watchdog is to check for $4030.D1 in the IRQ handler and call Delay131 ($E149) if the bit is set. The BIOS' default IRQ handler performs a similar operation, thus it is suitable for programs which do not use other IRQ sources.
Now to the program itself. This brand new FDS-4030D1-Addr program combines two of my previous programs into one package:
- FDS-4030D1-Test - raster display for Delay131 execution in IRQ handler
- older versions of FDS-4030D1-Addr - print IRQ return addresses during NOPslide execution
(file attachment + GitHub release will be made soon)
Example capture from my Sharp Twin Famicom: