Skip to content

Do not hold the CPU for a sprite enabled after the line's DMA compares - #340

Merged
highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-enable-timing
Sep 18, 2026
Merged

highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-enable-timing

Conversation

@highbyte

Copy link
Copy Markdown
Owner

What

A sprite enabled (or moved onto the raster line) after the line's two DMA compares, in cycles 55 and 56, does not start fetching on that line. The VIC-II model already had that right, but the bus stall model still gave such a sprite a BA-low window, so a CPU read near the end of the line was held for up to three cycles for a fetch that never happens.

Why it happened

Vic2BusStalls.BuildWindows counts a sprite that is about to start (enabled, DMA off, Y on the line) among the fetching ones, so that sprite 0's window, which begins in the same cycle as the first compare, is seen before that compare has run. The prediction was used for the whole line. It is now used only until the second compare has been made; from there the VIC-II's DMA state is final for the line.

Verification

  • VICE test programs (274 runs, PAL and NTSC): 252 → 254 match. Newly matching: spriteenable/spriteenable4 and spriteenable4_ntsc, which enable sprites 0-2 in cycle 57 of the line their Y names and draw a timing bar with the code that follows. No other result changed; the sprite and DMA suites are 129 of 129.
  • New unit test A_sprite_enabled_after_the_compares_takes_no_bus_on_that_line: enabled in cycle 55, a read in cycle 57 waits three cycles; enabled in cycle 57, none.
  • Games (Commando, Giana Sisters; PAL, NTSC, snapshots) and fourteen demos at three frame counts render byte-identically before and after.
  • Performance (MacBook Air M1, For Your Sprites Only): unchanged in every configuration.

The bus stall model counts a sprite that is about to start (enabled, DMA off,
Y on the line) among the fetching ones, so that sprite 0's BA window is seen
before the compare in cycle 55 has run. That prediction was kept for the whole
line: a sprite enabled, or moved onto the line, after both compares got a
window although it does not start there, and a read was held for a fetch that
never happens. The prediction now ends with the second compare.

VICE's spriteenable4 test programs enable sprites 0-2 in cycle 57 of the line
their Y names and time the code that follows; they now match on PAL and NTSC.
@sonarqubecloud

Copy link
Copy Markdown

@highbyte
highbyte merged commit 39ac5b0 into feature/cpu-cycle-engine Sep 18, 2026
10 of 16 checks passed
@highbyte
highbyte deleted the feature/c64-vic2-sprite-enable-timing branch September 18, 2026 11:26
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