I'm working on some code that needs to draw data over what exists in a tile in CHR RAM, like adding a line with a pencil. I only care about one bit plane, so I need to read 8 bytes from the PPU, perform ORA, and write them back.
I don't have enough RAM to hold all of CHR RAM, so I need to read the data during VBLANK.
This is what I have right now:
It takes159153 cycles (if I counted correctly).
I feel like there should be a faster way to do it, but I'm not very knowledgeable about the PPU's internal state. Do I need to buffer the values, or is it possible to read, modify, then write to a value in the PPU?
EDIT: Saved some time using tokumaru's trick
I don't have enough RAM to hold all of CHR RAM, so I need to read the data during VBLANK.
This is what I have right now:
It takes
Code:
lda #>TILEADDRESS
sta $2006
lda #<TILEADDRESS
sta $2006
bit $2007 ; clear read buffer
lda $2007 ; read 8 bytes, store on zero page
sta tmp0
lda $2007
sta tmp1
lda $2007
sta tmp2
lda $2007
sta tmp3
lda $2007
sta tmp4
lda $2007
sta tmp5
ldy $2007
ldx $2007
lda #<TILEADDRESS
sta $2005 ; keep high byte
sta $2006 ; go back to tile address
; write 8 bytes, ora'd with bytes read.
lda tmp0
ora #val0
sta $2007
lda tmp1
ora #val1
sta $2007
lda tmp2
ora #val2
sta $2007
lda tmp3
ora #val3
sta $2007
lda tmp4
ora #val4
sta $2007
lda tmp5
ora #val5
sta $2007
tya
ora #val6
sta $2007
txa
ora #val7
sta $2007
sta $2006
lda #<TILEADDRESS
sta $2006
bit $2007 ; clear read buffer
lda $2007 ; read 8 bytes, store on zero page
sta tmp0
lda $2007
sta tmp1
lda $2007
sta tmp2
lda $2007
sta tmp3
lda $2007
sta tmp4
lda $2007
sta tmp5
ldy $2007
ldx $2007
lda #<TILEADDRESS
sta $2005 ; keep high byte
sta $2006 ; go back to tile address
; write 8 bytes, ora'd with bytes read.
lda tmp0
ora #val0
sta $2007
lda tmp1
ora #val1
sta $2007
lda tmp2
ora #val2
sta $2007
lda tmp3
ora #val3
sta $2007
lda tmp4
ora #val4
sta $2007
lda tmp5
ora #val5
sta $2007
tya
ora #val6
sta $2007
txa
ora #val7
sta $2007
I feel like there should be a faster way to do it, but I'm not very knowledgeable about the PPU's internal state. Do I need to buffer the values, or is it possible to read, modify, then write to a value in the PPU?
EDIT: Saved some time using tokumaru's trick