;setting the CIA1-timerA to beam in the program beginning: ----------------------------------------------------------- sei ;we don't want lost cycles by IRQ calls :) sync cmp $d012 ;scan for begin rasterline (A=$11 after first return) bne *-3 ;wait if not reached rasterline #$11 yet ldy #8 ;the walue for cia timer fetch & for y-delay loop sty $dc04 ;CIA Timer will count from 8,8 down to 7,6,5,4,3,2,1 dey ;Y=Y-1 (8 iterations: 7,6,5,4,3,2,1,0) bne *-1 ;loop needed to complete the poll-delay with 39 cycles sty $dc05 ;no need Hi-byte for timer at all (or it will mess up) sta $dc0e,y ;forced restart of the timer to value 8 (set in dc04) lda #$11 ;value for d012 scan and for timerstart in dc0e cmp $d012 ;check if line ended (new line) or not (same line) sty $d015 ;switch off sprites, they eat cycles when fetched bne sync ;if line changed after 63 cycles, resyncronize it! .... the rest (this is also a stable-timed point, can be used for sg.) B;EXAMPLE-using timerA to stabilize 7 cycle jitter when using CMPd012: ----------------------------------------------------------------------- scan ldx #$31 ;a good value that's not badline, in border and 1=white cpx $d012 ;scan rasterline bne *-3 ;wait until rasterline will be $31 lda $dc04 ;check timer A, here it jitters between 7...1 eor #7 ;A=7-A so jitter will be 0...6 in A sta corr+1 ;self-writing code, the bpl jump-address = A corr bpl *+2 ;the jump to timer (A) dependent byte cmp #$c9 ;if A=0, cmp#$c9; if A=1, cmp #$c9 again 2 cycles later cmp #$c9 ;if A=2, cmp#$c9, if A=3, CMP #$EA 2 cycles later bit $ea24 ;if A=4,bit$ea24; if A=5, bit $ea, if A=6, only NOP stx $d020 ;x was 1 so border is white at the stable cycle sty $d020 ;y ended in 0 in sync routine, so border black after 4 cycles jmp scan ;go to the raster again (or can go new raster)
lda $dc04 ;check timer A, here it jitters between 7...1 eor #7 ;A=7-A so jitter will be 0...6 in A sta corr+1 ;self-writing code, the bpl jump-address = A corr bpl *+2 ;the jump to timer (A) dependent byte cmp #$c9 ;if A=0, cmp#$c9; if A=1, cmp #$c9 again 2 cycles later cmp #$c9 ;if A=2, cmp#$c9, if A=3, CMP #$EA 2 cycles later bit $ea24 ;if A=4,bit$ea24; if A=5, bit $ea, if A=6, only NOP bit $ea24 ;IMPORTANT to handle 8th cycle jitter
;setting the CIA1-timerA to beam in the program beginning: ;----------------------------------------------------------- sei ;we don't want lost cycles by IRQ calls ;) sync lda#$1c cmp$d012 ; scan for line to force DMA bne *-3 sta $d011 ;trigger badline to absorb jitter lda #$11 ldy #8 ;the walue for cia timer fetch & for y-delay loop sty $dc04 ;CIA Timer will count from 8,8 down to 7,6,5,4,3,2,1 ldy#0 sty $dc05 ;no need Hi-byte for timer at all (or it will mess up) sta $dc0e,y ;forced restart of the timer to value 8 (set in dc04) dec $d011 ;undo tiny scroll from above bmi sync ;oops, we were in the bottom border