Screen Transitioning

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Lucradan
Posts: 101
Joined: Wed Sep 21, 2016 12:08 pm

Screen Transitioning

Post by Lucradan »

I appreciate all the help this forum has given me so far, but I'm back with another problem.

I currently have a menu screen where you select the next screen by using the d-pad (up, down) and the SELECT button.

This menu works fine, but when it transitions to the next screen I get a strange effect were the top of the screen is filled will a block of 0's.
Untitled.png
I am using FCEUX as my emulator and confirmed that the nametable was correctly loaded in the PPU.

I included the ASM6 Project in the .ZIP file attached.

I've included a PDF of the game engine flowchart to help describe the flow.
Attachments
NES Game Engine.pdf
(243.19 KiB) Downloaded 120 times
MenuTest.zip
(41.1 KiB) Downloaded 120 times
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Screen Transitioning

Post by tokumaru »

Are you setting the scroll before turning rendering back on after the NT update?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Screen Transitioning

Post by rainwarrior »

After writing to the PPU with $2006 the scroll position has been overwritten and you need to restore it, usually with two writes to $2005, which will take effect at the end of the next vblank. Your program does not appear to write to $2005 at all?

Maybe this article will help: https://wiki.nesdev.com/w/index.php/PPU_scrolling
User avatar
Lucradan
Posts: 101
Joined: Wed Sep 21, 2016 12:08 pm

Re: Screen Transitioning

Post by Lucradan »

rainwarrior wrote:After writing to the PPU with $2006 the scroll position has been overwritten and you need to restore it, usually with two writes to $2005, which will take effect at the end of the next vblank. Your program does not appear to write to $2005 at all?
I wasn't trying to attempt scrolling during the transition.
It should be reloading the new nametable, attributes, sprites, etc. over the old table data.
I guess I am just not understanding the write to $2005.

I'll play around with it an see where it should go in the game engine.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Screen Transitioning

Post by tokumaru »

Lucradan wrote:I wasn't trying to attempt scrolling during the transition.
That doesn't matter. The internal registers used by the PPU to write/read to/from VRAM are the same that are used for rendering/scrolling. If you mess with VRAM, you mess with the scroll, so the scroll must be restored before the picture is displayed, preferably every frame. This means selecting a name table through the lower 2 bits of register $2000, as well as the vertical and horizontal scroll positions through register $2005. Ideally you should do that every frame, after any VRAM updates you might have in your vblank handler.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Screen Transitioning

Post by Bregalad »

Just to make it clear - rewriting to $2005/$2005/$2000 is necessary at the end of each VBlank which had VRAM updates (because $2006 was used, and $2006 is basically $2005 with bits reordered so writing to one register pairs affects the other). Since you usually have VRAM updates often enough, it's simpler to write to $2005/$2005/$2000 every frame without asking questions as Tokumaru suggests. However technically you have to do it only when $2006 was used.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Screen Transitioning

Post by tokumaru »

That's true. The reason I often suggest setting the scroll every frame is because there are more things that can affect the scroll than just VRAM updates during vblank, such as status bars or other raster effects, so instead of detailing all of that it's just easier to suggest resetting the scroll every frame.
User avatar
Lucradan
Posts: 101
Joined: Wed Sep 21, 2016 12:08 pm

Re: Screen Transitioning

Post by Lucradan »

Thank you everyone.

When I got a chance to play with it, I found all I had to to do was add a few lines to the EnableRendering NMI Code

Code: Select all

LBL.NMI.EnableRendering:
  LDA #%00011110
  STA $2001

  LDA VAR.NMIState.Wait
  STA VAR.NMIState

  ;******New Code**************
  LDA #%10010000   ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
  STA $2000
  LDA #$00        ;;tell the ppu there is no background scrolling
  STA $2005
  STA $2005
  ;****************************

  RTS
This also fixed an issue when I would get a screen full of 0's for a few frames in between the transition.

Next stop is to build a sprite animation engine and then RLE Compression.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Screen Transitioning

Post by dougeff »

Next stop is to build a sprite animation engine and then RLE Compression.
You could use existing libraries, like neslib.s, which works with NES screen tool.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply