I'm trying to iterate through two different sections of memory (for C64).
Let's say for example that I have:
Code:
lda #<BUFFER
sta ZP10
lda #>BUFFER
sta ZP11
lda #<SCREEN
sta ZP12
lda #>SCREEN
sta ZP13
ldx #00
ldy #40
lda (ZP10), y // get the 40th character from buffer
sta (ZP12), x // store at position 0 on the screen
It seems you cannot use X as an indirect offset like you can Y.
However, my assembler (KickAssembler) compiles this just fine. It even runs. But it obviously doesn't work.
The only way I can get indirect addressing to work that way is to always use Y. Which can be tedious sometimes.
Does anyone know why this is?
BTW, if anyone is curious, this is my *nearly* full screen scrolling (not smooth) with color. As you can see, I don't use "indirect X".
Code:
.align $100
* = * "Map.DrawMap"
DrawMap: {
.label COL = ZP.TEMP1
lda #$00
sta COL
ldx #<MAP_BUFFER // X contains the LOW byte. Character column.
ldy #>MAP_BUFFER // Y contains the HIGH byte of the MAP_BUFFER (character row)
stx ZP.MapTemp // ZP.MapTemp contains MAP_BUFFER address
sty ZP.MapTemp + 1
ldx #$00
ldy ZP.MapX
!loop:
lda #>MAP_BUFFER
sta ZP.MapTemp + 1
.for(var i = 0; i < 18; i++) {
lda (ZP.MapTemp), y
sta SCR_BUFFER + (i * 40), x
sty ZP.TEMP1
tay
lda ATTR_DATA, y
sta VIC.COLOR_RAM + (i * 40), x
ldy ZP.TEMP1
inc ZP.MapTemp + 1
}
inx
iny
cpx #40
beq !exit+
jmp !loop-
!exit:
rts
}