How bizarre! A self modifying code is what I actually thought of overnight having slept on it.
I thought this could actually be much closer aligned to the OP's, Oman395, original thoughts i.e. can an address "shared" between the X and Y registers be used to access memory.
In essence, the code below does what a "STA X:Y" instruction would do where X=lsb and Y=msb. The STA $1234 is just a sacrificial address to ensure the correct LDA instruction is generated by the assembler. Oh, and you couldn't run it in ROM!
Code:
; smc = self modifying code location.
; -> smc + 0 = $8D (LDA absolute from non-zero page address).
; -> smc + 1 = lsb of absolute address.
; -> smc + 2 = msb of absolute address.
;
; X holds the lsb of the address.
; Y holds the msb of the address.
;
; Acts as a pseudo "STA X:Y" instruction.
.ORG $200
LDX #$00 ; X = $00
LDY #$40 ; Y = $40
LDA #$FF ; A = $FF
loopy STY smc+2 ; Overwrite the msb
loopx STX smc+1 ; Overwrite the lsb
smc STA $1234 ; Absolute non-zeropage
INX ; X = X + 1
BNE loopx ; X <> 0 goto loopx
INY ; Y = Y + 1
CPY #$80 ; Does Y - $80 == 0
BNE loopy ; If yes goto loopy
BRK ; End
It takes longer (213,637 clock cycles) but, somehow, seems more elegant (IMHO).
I also worried what the reception to self modifying code would be - glad to see nothing is ruled out.
Such as code that has 64 lines of STA instructions (STA $4000,Y; STA $4100,Y; STA $4200,Y ... STA $7F00,Y). Much faster (2.55 times), but takes up more memory.