Going from recollection, I got pretty decent results by waiting for line 0, then line 100 (pick a random, but different line) counting one frame, then repeating the cycle.
I'd also have written the code a bit differently. Instead of counting up from 0 to N, I'd have counted down from N to 0 (and held that counter in X or Y), something along this line (but it's been a long time since I wrote any code for a 6502, so slip-ups are likely):
ldx delayFrames lineZero: lda #200 bne lineZero ; wait for line 0 Line100: lda #200 cmp 100 bne line100 dec x ; now we've seen line 0 and 100, count one frame bne lineZero ; if we have more frames, keep counting ; Now `delayFrames` frames should have passed I don't recall thinking of it at the time, but you could probably streamline it a little bit:
ldx delayFrames lineZero: lda #200 bne lineZero ; wait for line = 0 NotZero: lda #200 beq NotZero ; wait for line != 0 dec x ; two different lines, count one frame bne lineZero ; if we have more frames, keep counting Should save a couple of bytes, anyway.
...but Raffzahn is right: the jiffy clock is usually easier.