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
$183c a0 9e ldy #$9e $183e a2 19 ldx #$19 $1840 18 clc $1841 10 fa bpl $083d
The code location can't be $183c, can't it? Also the SHX instruction behaves unpredictable when a page is crossed, so I'm afraid this one won't work.
Btw, maybe you could summarize all the known allowed code locations where any SHX or SHY variant could work?
high byte of address written to, when: +--------+------------------+---------------+ | | no DMA on cycleN | DMA on cycleN | +--------+------------------+---------------+ |page | | | |not | H | H | |crossed | | | +--------+------------------+---------------+ |page | | | |crossed | X&(H+1) | X&(H+1) | | | | | +--------+------------------+---------------+ value written, when: +--------+------------------+---------------+ | | no DMA on cycleN | DMA on cycleN | +--------+------------------+---------------+ |page | | | |not | X&(H+1) | X | |crossed | | | +--------+------------------+---------------+ |page | | | |crossed | X&(H+1) | X | | | | | +--------+------------------+---------------+
Thanks! I should have looked at the latest version of the "No More Secrets" document.
[...]The (currently) shortest code that can be placed anywhere was proposed in post #44.
Quiss came up with a very bright idea in post #50 that uses the instabilities of the SHX instruction. It uses less RAM, but it has some restrictions on code location. Shorter variants were found, but they have much stronger location restrictions.
ldx #initval ldy #<(zp_pos+1) loop: shx $ffff,y lda <($100 + zp_pos - initval),x beq loop
ldy #init_value ;Init code sync: lax $dc04 sbx #51 sty ZP ;RRW instruction. Part of init code. cpx $dc04 bne sync:
The STA $ZP instruction (see post #44) can be made part of the init code, which reduces the timer-based stabilization approach to effectively 10 bytes: ldy #init_value ;Init code sync: lax $dc04 sbx #51 sty ZP ;RRW instruction. Part of init code. cpx $dc04 bne sync: STY ABS is also allowed, in combination with SBX #52. If I'm not mistaken, this should work on PAL, NTSC, and DREAN, but the loop exit cycle may depend on the system.