It is currently Sat Nov 17, 2018 10:39 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Jun 21, 2018 2:25 am 
Offline

Joined: Thu Mar 17, 2016 1:09 am
Posts: 2
Hello,

So I'm using CHR-RAM instead of ROM in my project and I want to update a tile in the pattern table on the fly. Everything is working fine except the code is updating tiles at $1110 and $1000 when I only want to update the tile at $1110. For some reason the "LDA patternDataPoLo" seems to be causing it even though it has the same value ($#10) which I checked with fceux. if I use Immediate addressing it seems to work fine and only the tile at $1110 is being updated. I know I'm missing something here but it's driving me insane. Any pointers or tips how I can debug this?

This is what I have at the start of NMI

Code:
NMI:
  LDA #$00
  STA $2003
  LDA #$02
  STA $4014       ; sprite DMA from $0200

    LDA isTileUpdate
    BEQ @SkipTileUpdate
    LDA $2002             ; read PPU status to reset the high/low latch
    LDA ppuAddressHi
    STA $2006             ; write the high byte of $2000 address
    LDA ppuAddressLo
    STA $2006             ; write the low byte of $2000 address

    LDA $2007
    TAY
    LSR
    LSR
    LSR
    LSR
    CLC
    ADC #$10
    STA patternDataPoHi
    TYA
    AND #%00001111
    ASL
    ASL
    ASL
    ASL
    STA patternDataPoLo

    LDA $2002         ; read PPU status to reset the high/low latch
    LDA patternDataPoHi
    STA $2006         ; write the high byte of $1000 address
    LDA patternDataPoLo
    ;LDA #$10 ;IF I USE THIS INSTEAD OF LDA patternDataPoLo then it works without a glitch
    STA $2006 ; write the low byte of $1000 address

    lda #%01011010
    sta $2007
@SkipTileUpdate:


Top
 Profile  
 
PostPosted: Thu Jun 21, 2018 3:07 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10974
Location: Rio de Janeiro - Brazil
I'm not sure why you're using a value from VRAM to calculate the address of the pattern to change, but VRAM reads are buffered, so the first value you get must be discarded, as only values from the second read onward will be valid. Try adding another LDA $2007 immediately after the one you have and see if that changes anything.


Top
 Profile  
 
PostPosted: Thu Jun 21, 2018 3:44 am 
Offline

Joined: Thu Mar 17, 2016 1:09 am
Posts: 2
You are a genius sir. Thank you! :D

I'm just experimenting with CHR RAM at the moment and trying to do some painting. :)
The calculation is pointless I know. I'll replace it with a lookup table but for now it works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group