PPU problems.. (Again)

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
PPU problems.. (Again)
by on (#58813)
Okay, so I'm getting back into this NES game I've been working on. The problem is, I can't get the PPU tile drawing right. I'm trying to write 2 text strings on the screen. Then the player presses A and they disapear and the game goes into play mode. The problem is, whenever I press A, one of the text strings go away, but the other doesn't. How can I fix this were they both go away?

Relevant part of code:
Code:
    Text:
   LDA $2002   ;Read PPU status to reset it (It is reset by reading from it)
   LDA #$32    ;\ High byte
   STA $2006   ;/
   LDA #$00    ;\ Low byte
   STA $2006   ;/
   LDX #$00    ;We start at 00
Text2:
   LDA backg,x ;Load from text table from data section below
   STA $2007   ;And we write it to the PPU I/O
   INX         ;We set the start of a loop
   CPX #$07
   BNE Text2 ;Loop if not zero

    Text3:
   LDA $2002   ;Read PPU status to reset it (It is reset by reading from it)
   LDA #$31    ;\ High byte
   STA $2006   ;/
   LDA #$00    ;\ Low byte
   STA $2006   ;/
   LDX #$00    ;We start at 00
Text4:
   LDA backg1,x ;Load from text table from data section below
   STA $2007   ;And we write it to the PPU I/O
   INX         ;We set the start of a loop
   CPX #$0C
   BNE Text4 ;Loop if not zero


And then a check if the player presses A, (I've got it setup where pressing A just INCs the game state.):
Code:
DisplayGraphics:
   LDA gamestate
   CMP #$01
   BNE Return1
    set:
   LDA $2002   ;Rest during game play
   LDA #$32    ;\ High byte
   STA $2006   ;/
   LDA #$00    ;\ Low byte
   STA $2006   ;/


And then finally: (Just in case you might need it)
Code:
backg1:
  .db $1D,$1E,$26,$28,$02,$1B,$32,$02,$39,$24,$3A,$29

backg:
  .db $29,$2B,$1E,$2C,$2C,$03,$1A,$FF

by on (#58823)
First of all, why are you using VRAM addresses $3200 and $3100? The name tables stay at $2000-$2FFF, so that's what you should use. I do believe that $3000 is a mirror of $2000, but using mirrors is confusing, and you shouldn't do it unless it's necessary.

The code that is supposed to erase the strings is using the same address as the first string. But you didn't show what comes after you set the address. You should be writing the tiles that are supposed to overwrite the string (probably just a blank tile). And then you'd have to do the same for the other string. I can't say what's wrong unless I see more of what's under the label "DisplayGraphics".

Also, keep in mind that you can only write data to VRAM during VBlank or when rendering is disabled.

by on (#58824)
Well, actually, I didn't do anything after the DisplayGraphics except going in to create an auto increasing timer for a sprites X position and drawing the sprites. So, I guess this is the problem?

And to keep out further confusion here is the entire source.

by on (#58853)
Took a peek at the code.

When A is pressed, it sets the gamestate to #$01, which will eventually take the game into the "set:" branch of DisplayGraphics. Once there, you set the target PPU address by writing twice to $2006. But then you stop and don't draw anything.

If you want to draw over the text, you will need to make writes to $2007 after you set the target PPU address. To erase the text you drew, you will have to draw a string of blank tiles over them.

It's not clear to me why one of your lines is getting erased at all. Unless I'm missing something, nothing is getting drawn to the screen (other than sprites).

Also, your PressedA code bleeds over into PressedB, so pressing A will store #$01 into the fireflag too.