Issue with reading VRAM with auto-increment (via ASM)
Posted: Sun Nov 26, 2023 5:21 am
I'm new to assembly and am having a hard time understanding why my code to read VRAM is behaving the way it does. I'm using x16emu r45 and cc65 to assemble.
I followed along with Matt Heffernan's "Hello VERA" tutorial ... https://www.youtube.com/watch?v=Wn8-unoaWSc ... (the slide at around 8:48)
I tried writing my own code to read 5 bytes of VRAM at address $1B000 (the tutorial is based on an old emulator, so it uses $00000)
(variable names above are based on Matt's tutorial's naming conventions). The first read works perfectly. But every subsequent read (i.e. LDA $9F23) just returns $20. That's not what's in memory (I checked via x16emu's debugger)
By my understanding, the "stride" should auto-increment behind the scenes, such that my next LDA gets the next VRAM addr's value. It seems to work perfectly for writes (STA) but not for reads (LDA).
If I change my code to just make 5 distinct reads, incrementing the addr myself (and setting stride zero) then it works fine. But that's horribly inefficient. I can't for the life of me figure out what I'm doing wrong with the stride/loop approach. Any advice is appreciated.
I followed along with Matt Heffernan's "Hello VERA" tutorial ... https://www.youtube.com/watch?v=Wn8-unoaWSc ... (the slide at around 8:48)
I tried writing my own code to read 5 bytes of VRAM at address $1B000 (the tutorial is based on an old emulator, so it uses $00000)
Code: Select all
stz VERA_ctrl ; ADDRSEL=0
lda #($10 | ^VRAM_ADDR) ; Stride 0001xxxx
sta VERA_addr_bank
lda #>VRAM_ADDR
sta VERA_addr_high
lda #<VRAM_ADDR
sta VERA_addr_low
ldx #5
@read_loop:
lda VERA_data0 ; read from VRAM
jsr print_hex ; Matt's subroutine to print .A as a hex string
dex
bne @read_loop
By my understanding, the "stride" should auto-increment behind the scenes, such that my next LDA gets the next VRAM addr's value. It seems to work perfectly for writes (STA) but not for reads (LDA).
If I change my code to just make 5 distinct reads, incrementing the addr myself (and setting stride zero) then it works fine. But that's horribly inefficient. I can't for the life of me figure out what I'm doing wrong with the stride/loop approach. Any advice is appreciated.