Skip to content

Follow the VIC-II sprite counters per cycle and draw per-line sprites from them - #325

Merged
highbyte merged 2 commits into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-y-expand
Sep 10, 2026
Merged

Follow the VIC-II sprite counters per cycle and draw per-line sprites from them#325
highbyte merged 2 commits into
feature/cpu-cycle-enginefrom
feature/c64-vic2-sprite-y-expand

Conversation

@highbyte

Copy link
Copy Markdown
Owner

Summary

  • The VIC-II keeps each sprite's data counter, its base and the expansion flip-flop as the chip does, with the checks in cycles 15, 16, 55, 56 and 58 applied as the raster advances. A change of the Y-expand bit lands before or after the cycle 55 check according to its own cycle, clearing the bit sets the flip-flop at once, and the DMA ends when the counter base reaches 63. That gives the 23-line sprite of VICE's d017 tests and the sprite stretcher of the demos. The bus stall model anticipates the compare that starts a sprite.
  • With per-line sprites on, the sequencer pixel generator draws each raster line's sprites from the bytes the chip fetched for it instead of a band captured at the sprite's start, so pointer, data, position and expansion changes mid-sprite show on the line they reach. The frame-level sprite path and the legacy generator are unchanged.
  • Performance: the sprite events skip all work while no sprite is enabled or fetching and are applied behind one compare per raster advance; the model's per-line constants are cached instead of fetched through abstract properties on every advance; the generator counts its line and cycle along instead of dividing per cycle.
  • New sample SpriteStretch (a diamond stretched by a wave through per-line $D017 writes, in a bad-line-free band). Two sprite-only demos in Download & Run, For Your Sprites Only and Unfortunate Coincidence, with a requiresPerLineSprites flag that switches per-line sprites on for a program.

Validation

  • 467 C64 tests, full suite 2935 passed, 9 skipped. New tests: Vic2SpriteDmaTests (compare and display cycles, 21 and 42 rows, expand bit cleared mid-sprite before and after the cycle 55 check, hold and release of a row, redisplay by a rewritten Y) and a per-line render test of the d017 case.
  • VICE test programs: spritedma 4/4 on PAL and NTSC (were 0/4); 113 tests across ten suites with the same 18 known differences as before (videomode residuals, gfxfetch, disable-bad).
  • Commando (two snapshots, D64 PAL and NTSC) and Giana Sisters (D64 PAL and NTSC) render byte-identical to the integration branch; one 60-frame Commando run differs by 4 pixels where a sprite's last row is now clipped by its own line's border span.
  • Frame benchmark on the integration branch and this branch, alternating (MacBook Air M1, .NET 10.0.203): without sprites level within the run-to-run spread; with eight visible sprites +3 to +9%, the counters and fetch state of fetching sprites per line.
  • SonarCloud branch analysis clean at Major and above.

… from them

The VIC-II now keeps each sprite's data counter, its base and the expansion
flip-flop as the chip does, with the checks in cycles 15, 16, 55, 56 and 58
applied as the raster advances. A change of the Y-expand bit lands before or
after the cycle 55 check according to its own cycle, clearing the bit sets the
flip-flop at once, and the DMA ends when the counter base reaches 63. That
gives the 23-line sprite of VICE's d017 tests and the sprite stretcher of the
demos, and the bus stall model anticipates the compare that starts a sprite.

With per-line sprites on, the sequencer pixel generator draws each raster line's
sprites from the bytes the chip fetched for it instead of a band captured at
the sprite's start, so pointer, data, position and expansion changes mid-sprite
show on the line they reach. The frame-level path and the legacy generator are
unchanged.

The sprite events skip all work while no sprite is enabled or fetching and are
applied behind one compare per raster advance; the model's per-line constants
are cached rather than fetched through abstract properties on every advance.

New sample SpriteStretch, and two sprite-only demos in Download & Run with a
flag that switches per-line sprites on for them.
…ing per cycle

The per-instruction loop derives the raster line and the cycle within it once and counts them along, and looks the screen line up in a table filled from the model at setup, instead of a 64-bit division, a modulo and a virtual call on every cycle. Same output; measured neutral within noise on this machine.
@sonarqubecloud

Copy link
Copy Markdown

@highbyte
highbyte merged commit 2403bc8 into feature/cpu-cycle-engine Sep 10, 2026
10 checks passed
@highbyte
highbyte deleted the feature/c64-vic2-sprite-y-expand branch September 10, 2026 17:55
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