Skip to content

Invert the sprite Y-expansion flip-flop a cycle later, as the chip does - #338

Merged
highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-crunch-variants
Sep 17, 2026
Merged

highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-crunch-variants

Conversation

@highbyte

Copy link
Copy Markdown
Owner

What

The Y-expansion flip-flop of a sprite is inverted while its $D017 bit is set. The VIC-II article puts that inversion in the first phase of cycle 55; on the chip it is a cycle later: a bit set by a write in cycle 55 is still inverted (the row is held, the sprite stretcher case), a bit set in cycle 56 is not. We held the row only for writes up to cycle 54.

Established by VICE's spritecrunch2 test programs, which clear and set $D017 on every line and move the second write a cycle later every eight lines.

How

Vic2: the inversion moves from the sprite event of the first DMA compare (cycle 55) to that of the second (cycle 56), before the compare. Sprites the first compare has just started are left out: their flip-flop was cleared there, and a Y-expanded sprite still shows its first row twice.

Verification

  • VICE test programs (274 runs, PAL and NTSC): 245 → 250 match. Newly matching: spritecrunch/spritecrunch2-25 to -29. No other result changed, including the other nineteen sprite suites.
  • New unit test The_flip_flop_inversion_sees_a_y_expand_bit_set_in_cycle_55: set in cycle 55 holds the row, in cycle 56 it does not.
  • 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 (sequencer with per-line sprites 1347/1320 → 1342/1318 µs/frame).

A Y-expand bit set by a write in cycle 55 is still inverted, one set in cycle
56 is not: the inversion the VIC-II article puts in the first phase of cycle
55 happens a cycle later on the chip. VICE's spritecrunch2 test programs clear
and set $D017 on every line with the second write a cycle later every eight
lines, and hold the sprite's row for as long as the set lands by cycle 55;
their 25 to 29 variants now match.

The inversion moves from the sprite event of the first DMA compare to that of
the second, and leaves out the sprites the first compare has just started, so
a Y-expanded sprite still shows its first row twice.
@sonarqubecloud

Copy link
Copy Markdown

@highbyte
highbyte merged commit e96027d into feature/cpu-cycle-engine Sep 17, 2026
9 checks passed
@highbyte
highbyte deleted the feature/c64-vic2-sprite-crunch-variants branch September 17, 2026 18:07
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