initstabilise lda $d012 ldx #10 ; 2 - dex ; (10 * 5) + 4 bpl - ; 54 nop ; 2 eor $d012 - $ff,x; 5 = 63 bne initstabilise; 7 = 70 [...]; timer setup
What an awful thread.. fell down the rabbit hole, turned utterly insane, lost several days of sleep...
Quiss' original approach is short and elegant, but opcode rewriting confuses my old brain. Adding a single byte to it's size, the flexibility can be increased somewhat (from 64 to 112 possible pages) and no opcode rewrites, just operand rewrite. * = $xy00, where x=$0-$f and y=$0-$6 loop: ldy #$08 ldx #$0a shx loop,y jmp loop $xx0A: Loop times kept at either 10 or 12 cycles, depending on address choice.
* = $xy00, where x=$0-$f and y=$0-$6 loop: ldy #$08 ldx #$0a shx loop,y jmp loop $xx0A:
As an added bonus, A is not touched - which may or may not matter in your overall timer setup. So, it's obvious my priority is not size, but readability - and I find this approach a tad more readable ;-)
Still, I think the sniplet presented in post#90 (and all variants thereof) is best regarding trade-off between readability and size. And it imposes almost no restriction on the highbyte that can be used;)
ldy #$01 loop: ldx #243 (or any other badline) cpx $d012 bne *-3 shy $ffff, x lda $ff, x beq loop
.segment Copyfaults08a3 [start=$08a3] !: ldx jump_in: #SHX_ABSY ; .by LDY_IMM, $08 cpx #$00 bne !- // ... further init code, like starting a timer ...
.macro Copyfaults_QuissSHXmethod_unrestricted( initval, zp_pos ) { ldx #initval ldy #<(zp_pos+1) !: shx $ffff,y lda <($100 + zp_pos - initval),x beq !- }
BasicUpstart2( program ) program: sei !: lda runner: #24 asl ; asl ; asl ; adc #$33 sta badline ldy #1 !: ldx badline: #$3b // (or any other badline?) !: cpx $d012 bne !- shy $ffff, x lda $ff, x beq !-- inc $d020 dec $d020 lda $dc01 cmp #$ef bne !-- !: cmp $dc01 beq !- dec runner bne !---- // change to "bpl": program gets stuck lda #24 sta runner bne !----
.segment Copyfaults08a3 [start=$08a3] !: ldx jump_in: #SHX_ABSY ; .by LDY_IMM, $08 cpx #$00 bne !-
.cerror * != $08a3, "sync not at $08a3" sync = * + 1 ldx #$9e ldy #8 cpx #0 bne sync