Overview
Stable raster is the Commodore 64 technique for achieving cycle-exact synchronisation with the VIC-II’s raster beam. Because the CPU and VIC-II share the bus, interrupt timing has inherent jitter (0-7 cycles). The stable raster technique eliminates this jitter, enabling perfectly timed mid-screen effects.
Fast Facts
| Aspect | Detail |
|---|
| Problem | IRQ timing varies by 0-7 cycles |
| Solution | Double-IRQ with self-modifying code |
| Precision | Cycle-exact (0 jitter) |
| Used for | Border removal, split screens, colour bars |
The Jitter Problem
When a raster interrupt fires, the CPU might be mid-instruction:
| Instruction Length | Jitter |
|---|
| 2 cycles | 0-2 cycle variation |
| 3 cycles | 0-3 cycle variation |
| 7 cycles | 0-7 cycle variation |
This jitter causes visible glitches in timing-sensitive effects.
The Double-IRQ Solution
The technique uses two interrupts:
| IRQ | Purpose |
|---|
| First IRQ | Sets up second IRQ one line later |
| Second IRQ | Triggers inside a long NOP slide |
Step by Step
- First IRQ fires with unknown jitter
- Set second IRQ for next raster line
- Execute NOP slide (many 2-cycle NOPs)
- Second IRQ fires inside NOP slide
- Jitter is now only 0-1 cycles
- Measure exact cycle position
- Compensate with calculated delay
Code Structure
; First IRQ - unstable, sets up second
first_irq:
lda #<second_irq
sta $0314
inc $d012 ; Next line
; ... acknowledge IRQ
rti
; Second IRQ - stabilised
second_irq:
; NOP slide for consistent entry point
nop : nop : nop : nop : nop : nop : nop
; Now cycle-exact
; ... do stable raster effect
Why It Works
| Mechanism | Effect |
|---|
| NOP slide | All instructions same length (2 cycles) |
| Maximum jitter = 1 | Only 0 or 1 cycle variation |
| Cycle counting | Determine exact position |
| Branch compensation | Conditional delay to align |
Applications
| Effect | Requirement |
|---|
| Border removal | Exact $D011 writes |
| Raster bars | Colour changes per line |
| Split screens | Mode changes mid-frame |
| FLD effects | Flexible Line Distance |
| Tech-tech | Multi-colour text |
Historical Development
| Era | Advancement |
|---|
| 1986 | Basic double-IRQ discovered |
| 1987 | Refined techniques |
| 1990s | Demo scene mastery |
| Today | Still essential for C64 effects |
| Factor | Impact |
|---|
| CPU time | Two IRQs per stable point |
| Code space | NOP slides, handler code |
| Complexity | Requires deep understanding |
Modern Relevance
Understanding stable raster teaches:
- Interrupt handling fundamentals
- Cycle-exact timing
- Hardware synchronisation
- Why modern GPUs use VSync
See Also