Report sprite collisions read in the middle of a raster line up to the beam - #337
Merged
highbyte merged 1 commit intoSep 17, 2026
Conversation
…e beam A read of $D01E or $D01F during a line reports the collisions of the sprite pixels the beam has passed, up to four pixels before the start of the read's cycle, and clears the register as that cycle ends, so the collisions of the twelve pixels in between are lost and the rest of the line's show in the next read. Established by VICE's sprite-sprite-collision-cycle, sprite-gfx-collision-cycle, spritevssprite and spriterestart test programs, which now pass. The VIC-II derives the current line's sprite runs up to the read's pixel without committing the sprite data registers and latches the overlaps in that window; the line's end latches the remainder. For sprite-to-background the sequencer pixel generator draws the read's own cycle early and checks the runs against the line's foreground pixels, through IVic2CycleRenderer.LatchSpriteBackgroundCollisions.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Reads of the sprite collision registers (
$D01E,$D01F) in the middle of a raster line now report what the chip reports:Until now both registers were latched only when a line ended, so a program that polls a register twice on a line, or at a fixed cycle, saw the whole line's collisions or none.
How
Vic2: the line-end derivation of sprite output runs can run up to a pixel without committing the sprite data registers. A$D01Eread derives the current line's runs up to the read's pixel and latches the overlaps in that window; a per-line marker makes the line's end latch only the remainder. Reads after the display decision of cycle 58 are clamped there.Vic2SpriteManager.LatchLineSpriteCollisions(line, fromPixel, toPixel)replacesEndLineSpriteCollisions(line): run masks are clipped to the pixel window.IVic2CycleRenderer.LatchSpriteBackgroundCollisions: for$D01Fthe sequencer pixel generator catches up, draws the read's own cycle early (a read changes nothing, and the graphics under the last reported pixels are that cycle's), checks the runs against the line's foreground pixels in the window and keeps its own marker for the line-end pass. The background check is one helper shared by both paths. The legacy generator is unchanged (default interface method).Verification
spritevssprite,spriterestart,spritecollisions/sprite-sprite-collision-cycle,spritecollisions/sprite-gfx-collision-cycle. No other result changed.Vic2CollisionReadTimingTests(10 cases): report threshold, clear at the end of the read's cycle, line-end latch, for both registers.