;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)
;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
pha lda $dd04 eor #7 sta *+4 bpl *+2 cmp #$c9 cmp #$c9 bit $ea24 bit $ea24 jmp *+8 nop nop jmp *+3 txa pha tya pha
>>> b1={2,3,4} >>> b2={2,3,4,5,6,8} >>> set([x+y for x in b1 for y in b2]) {4, 5, 6, 7, 8, 9, 10, 11, 12}
ldy $dc04 lda frag1,y sta rna+1 lda frag2,y sta rna+2 rna: .byt 0,0,0
ldy $dc04 lda opcodes,y sta mod mod .byt $00,$1b,$a9,$13,$ea ; 18-27 cycles later...
y code cycles trashes 1 a9 1b|a9 13|ea 6 2 a5 1b|a9 13|ea 7 3 b5 1b|a9 13|ea 8 4 06 1b|a9 13|ea 9 1b 5 a1 1b|a9 13|ea 10 6 ea|1b a9 13|ea 11 13a9,y 7 ad 1b a9|13 ea 12 (ea),y 8 99 1b a9|13 ea 13 a91b,y (ea),y 9 0e 1b a9|13 ea 14 a91b (ea),y 10 1b 1b a9|13 ea 15 a91b,y (ea),y
ldy $dc04 lda $xxnn,y
;A=1..8 *=$1000 clc adc #$ff-8;A=8-A so result will be 7 0 in A eor #$ff sta corr+1 ;self-writing code, the bpl jump-address = A corr bpl *+2 ;the jump to (A) dependent byte (13 cycles so far) cmp #$c9 ;A=8->A=0->BPL +2 cmp #$c9 ; cmp #$c9 ; cmp $ea ;3 =9 (13+9=22 max delay)