This is an old revision of the document!
Improved Clock Slide
by *lft*
Sometimes we want to delay a variable number of cycles, e.g. during VSP or when setting up a stable raster.
A typical way of handling a variable delay is to use a clock slide. In the following example, we start somewhere in a given range of cycles, we want to end up exactly at cycle 50, and we've computed the corresponding number of cycles to skip in A.
; number of cycles to skip ahead in A sta branch+1 ; 31..41 branch bpl * ; 35..45 lda #$a9 ; 38 lda #$a9 ; 40 lda #$a9 ; 42 lda #$a9 ; 44 lda $eaa5 ; 46 ; at cycle 50
Notice that the operands are reinterpreted as opcodes depending on where we land on the slide. For instance, the final lda $eaa5
is encoded as ad a5 ea
and takes 4 cycles. Skipping the first byte, we get a5 ea
(lda $ea
, 3 cycles). Skipping also the second byte, we get ea
(nop
, 2 cycles).
The length of the clockslide depends on the maximum jitter we have to support, and we pay a corresponding penalty in the form of useless waiting cycles. In the example, the maximum supported jitter is 10 cycles (41-31), and the minimum overhead cost is 9 cycles (50-41).
Now here comes the improvement: