Nametable not being rendered

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
Zero One
Posts: 4
Joined: Sun May 22, 2016 4:47 am
Location: England, UK
Contact:

Nametable not being rendered

Post by Zero One »

I've just started looking into writing stuff for the NES, and I'm currently trying to get something to display. I've drawn tiles for "HELO" and I'm successfully loading them into a nametable in my NMI routine. When I view the nametables in FCEUX, I can clearly see the word "H E L L O" drawn out as I've specified in my code, along with the correct palette. However, I'm not actually seeing them being drawn to the screen in FCEUX, and I can't see where my mistake is. Here's my NMI routine:

Code: Select all

nmi:
    bit PPUSTAT ; Reset address latch
    lda #$20    ; Write to nametable 0
    sta PPUADDR ; MSB
    lda #$88
    sta PPUADDR ; LSB
    ldx #00
    loadloop:
        lda bg1, x
        sta PPUDATA
        inx
        cpx #17
        bne loadloop
    bit PPUSTAT
    lda #$3F
    sta PPUADDR
    lda #$00
    sta PPUADDR
    ldx #00
    loadpalettes:
        lda palettes, x
        sta PPUDATA
        inx
        cpx #32
        bne loadpalettes
    bit PPUSTAT
    lda #00     ; Reset scroll to 0, 0
    sta PPUSCRL
    sta PPUSCRL
    lda %10000000
    sta PPUCTRL
    rti
Nametable.png
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Nametable not being rendered

Post by rainwarrior »

I don't see a write to $2001 (PPUMASK) in there to enable the screen. wiki

It's also a little odd to use your nmi handler to enable NMI via $2000 (PPUCTRL)? If the NMI handler is being run, this is already enabled. Edit: My mistake. Tokumaru points out what it's for below.
Last edited by rainwarrior on Fri Apr 29, 2022 7:22 pm, edited 1 time in total.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Nametable not being rendered

Post by Quietust »

rainwarrior wrote: Fri Apr 29, 2022 5:10 pm I don't see a write to $2001 (PPUMASK) in there to enable the screen. wiki

It's also a little odd to use your nmi handler to enable NMI via $2000 (PPUCTRL)? If the NMI handler is being run, this is already enabled.
Not only that, but there's an additional typo in there: instead of loading an immediate value, it's reading from zeropage.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Nametable not being rendered

Post by tokumaru »

rainwarrior wrote: Fri Apr 29, 2022 5:10 pmIt's also a little odd to use your nmi handler to enable NMI via $2000 (PPUCTRL)? If the NMI handler is being run, this is already enabled.
A $2000 write in the NMI handler is important as part of the process of setting the scroll. The missing # that Quietust mentioned is a big problem though.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Nametable not being rendered

Post by rainwarrior »

Oops, yes that's correct.
User avatar
Zero One
Posts: 4
Joined: Sun May 22, 2016 4:47 am
Location: England, UK
Contact:

Re: Nametable not being rendered

Post by Zero One »

hello.png
hello.png (7.36 KiB) Viewed 630 times
Thanks for the help! The write to PPUMASK to enable the screen is done elsewhere; that's why you're not seeing it in the NMI function. Is there ever a point in VBLANK I need to disable the screen?

As for the problem, it was that accidental read from zeropage that was the issue. Making it an immediate value solved the issue. A little annoying to have been literally one character away from it the whole time, but I've got nametable rendering working, so I'm quite pleased with that. Next thing to tackle I guess will be OAM stuff and seeing if I can get a sprite rendering, then moving.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Nametable not being rendered

Post by rainwarrior »

Zero One wrote: Sat Apr 30, 2022 10:59 amThanks for the help! The write to PPUMASK to enable the screen is done elsewhere; that's why you're not seeing it in the NMI function. Is there ever a point in VBLANK I need to disable the screen?
My general recommendation is to only enable or disable the screen within vblank, in normal situations.

The reason is that it's immediate. So if you enable somewhere in the middle of a frame, you'll see half of that frame get rendered, with bad scrolling. Similarly for disabling it, you'll get half a frame of background colour, though at least the top half will still look normal.


Otherwise, no there's not normally a need to disable it during vblank as rendering is already suspended at that time. You might extend the period you can upload to the PPU with forced blanking, by intentionally keeping it off past the end of vblank and turning back on mid-frame, with very careful timing, but this is a very tricky technique.

Disabling rendering for a forced blank mid-frame (e.g. if you want to make a forced blank near the bottom of the picture and start uploading to the PPU before the NMI begins) can be done but proper timing for this is even trickier.

Finally, turning off one of sprites or background, but not both, is safe to do anywhere, as it doesn't suspend the rendering operation it just hides a layer. That's sometimes useful for e.g. hiding sprites over a status bar.
Post Reply