Skip to content

Reimplement five VIC-II blocks independently of VICE's code - #343

Merged
highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-clean-room
Sep 18, 2026
Merged

highbyte merged 1 commit into
feature/cpu-cycle-enginefrom
feature/c64-vic2-clean-room

Conversation

@highbyte

Copy link
Copy Markdown
Owner

Why

The cycle-exact VIC-II learned several behaviours from VICE's emulator source. That is fine for behaviour, which is a fact about the chip, but five blocks ended up following VICE's GPL C code closely: the same logic and expressions under other names. This project is MIT licensed, so those blocks are replaced by code written independently.

What was replaced

Block Where
Graphics fetch address, with bitmap mode's one-cycle delay on the NMOS chips and the address mix in the cycle BMM changes Vic2RasterizerSequencerPixelGenerator (GraphicsFetchAddress)
Graphics data sequencer per pixel: loading at XSCROLL, pairs, mode changes at pixels 4/6/7, the MCM switch flash, colour selection per mode, fast paths Vic2RasterizerSequencerPixelGenerator (DrawGraphicsCycle and helpers)
Sprite data sequencer per pixel: X expansion, multicolour pairs, per-pixel priority, the halt at the sprite's own fetch Vic2SpriteManager.DecodeSpriteRun
Sprite data counters: the cycle 58 display decision, the cycle 16 update, rule 1 on $D017 writes, the sprite crunch Vic2
Vertical border flip-flop Vic2

How

  • Specification first: a behaviour-only specification of each block was written from the VIC-II article, VICE's test programs and the existing tests, with no code and no VICE identifiers.
  • Implementation from the specification only: the old bodies were removed, keeping the signatures the tests use. The replacements were written by an implementer who had the specification, the article, the test programs and the rest of this repository, but not VICE's source, the removed code or its history.
  • Similarity review: a structural comparison against VICE's code found no transliteration. The remaining resemblances are where the behaviour allows essentially one way to write it, such as the sprite crunch's bit merge or the bitmap-mode address rule.
  • Comments: comments that named VICE's source files or internal identifiers now describe the behaviour. Credit to VICE's test programs stays.

Verification

  • Tests: unchanged, and all pass.
  • VICE VIC-II test programs (274 runs, PAL and NTSC): identical results to before, including every pixel count (258 match their references, as before).
  • VICE CIA test programs: identical.
  • Games and demos: Commando and Giana Sisters (PAL, NTSC, snapshots) and fourteen demos at three frame counts render byte-identically.
  • Performance (MacBook Air M1, For Your Sprites Only): the sequencer with per-line sprites went from 1,314/1,321 to 1,270/1,262 µs/frame, and without them from 1,047/949 to 985/914. The other configurations are unchanged.

Five parts of the cycle-exact VIC-II followed VICE's (GPL) emulator source
closely: the graphics fetch address with bitmap mode's one-cycle delay, the
graphics data sequencer per pixel, the sprite data sequencer per pixel, the
sprite data counters (cycle 58 decision, cycle 16 update, crunch) and the
vertical border flip-flop. They are rewritten from a behaviour specification
by an implementer without access to VICE's source or the previous code, so the
project stays MIT licensed.

The behaviour is unchanged: the existing tests pass unchanged, all 274 VICE
VIC-II test program runs give the same result pixel for pixel, the CIA test
programs are unchanged, and games and demos render byte-identically. The new
graphics sequencer is slightly faster.

Comments that named VICE's source files or internal identifiers now describe
the behaviour instead; credit to VICE's test programs remains.
@sonarqubecloud

Copy link
Copy Markdown

@highbyte
highbyte merged commit 38aa24e into feature/cpu-cycle-engine Sep 18, 2026
9 checks passed
@highbyte
highbyte deleted the feature/c64-vic2-clean-room branch September 18, 2026 16:50
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