Skip to content

NES: Fixed GetInternalOpenBus returning external bus value by mistake.#82

Open
zdg-kinlon wants to merge 1 commit into
SourMesen:masterfrom
zdg-kinlon:master
Open

NES: Fixed GetInternalOpenBus returning external bus value by mistake.#82
zdg-kinlon wants to merge 1 commit into
SourMesen:masterfrom
zdg-kinlon:master

Conversation

@zdg-kinlon
Copy link
Copy Markdown

Summary

Fix OpenBusHandler::GetInternalOpenBus() returning external bus value

Description

Fixed a bug in OpenBusHandler where GetInternalOpenBus() incorrectly returned _externalOpenBus instead of _internalOpenBus.

Technical Details

  • Root Cause: The method returned _externalOpenBus when it should return _internalOpenBus.
  • Impact: While $ 4015 reads may appear unaffected in simple cases (since GetInternalOpenBus() is called before updating the bus), the bug breaks correctness whenever the internal and external bus values differ — such as after a $ 4015 read or in advanced mappers/debuggers that rely on accurate internal bus state.
  • Hardware Behavior: Reading $ 4015 does not drive the external bus; only the CPU's internal bus is updated. Thus, internal and external open bus values must be tracked separately.

APU#Status_($4015)
Note: The $ 4015 bit 5 uses the internal open bus value from before the read, which is correctly captured in the current call order. The bug primarily affects other consumers of GetInternalOpenBus() or future code relying on bus state separation.

It should return _internalOpenBus to correctly reflect CPU-internal open bus state, especially after reads like $ 4015.
Mokona pushed a commit to Mokona/MesenCE that referenced this pull request May 17, 2026
When DMC is enabled via $4015, it starts a timer for when the resulting load DMA needs to occur. When the frame ends, this timer can be decremented an extra time due to a call to NesApu::EndFrame that wasn't expected to have execution side effects. Stepping back can also trigger this because EndFrame is called from NesApu::Serialize. Sour suggested moving the DMC ProcessClock call out of this function to fix it, which works.

This fixes very rare failures in the AccuracyCoin Implicit DMA Abort test.
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.

1 participant