Cannot get sprites to display

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Cannot get sprites to display
by on (#173159)
I am trying to create a simple Pong game for the snes. I have got the background to appear but I cannot get the sprites to appear.

Attachment:
pongoam.png
pongoam.png [ 22.03 KiB | Viewed 2771 times ]


As you can see, the correct values are appearing in OAM, but the sprite preview is completely blankand they do not appear on screen. I have enabled the OAM in register $212c, what have I missed? Sorry if I have missed something dumb but I have searched the forum and the snes developer's manual and I am kind of at the end of my tether here.
Re: Cannot get sprites to display
by on (#173161)
Maybe there's no sprite palettes. Sprites use the 2nd half of the color palette table.
Re: Cannot get sprites to display
by on (#173167)
Also note that even with the palette set, color 0 of that palette will always be transparent regardless of what value you set it to, so if the sprite pixels are all 0, it won't show up at all.
Re: Cannot get sprites to display
by on (#173175)
Are you sure the graphics data for the sprites is in the right place in VRAM, and that you've pointed the PPU at it via $2101?
Re: Cannot get sprites to display
by on (#173180)
I copied the palette entries to the second half of the table and it worked first time. I knew it would be something stupid like that. :oops: Oh well, I'll know next time.

Thank you everyone for your answers.

Edit: I have a couple more questions to ask. Now that the sprites are appearing, they seem to be vertically stretched.

Attachment:
fsnes000.png
fsnes000.png [ 556 Bytes | Viewed 2692 times ]


The sprite on the right is supposed to be square. Is this because I'm not using a scanline filter?

The other thing I wanted to ask was about fading the screen in and out. This is my code for both

Code:
transitiontogame:      //fadeout screen
   sep   #$20
   lda   #$80
   sta   $4200
   dec   {DISPLAY_REG}      //shadow of $2100 in ram
   bpl   .stillfading
   jmp   loadgame
.stillfading:
   wai
   jmp transitiontogame

fadeintogame:             //fade into game
   sep   #$20
   inc   {DISPLAY_REG}
   lda   {DISPLAY_REG}
   cmp   #$0f
   bcc   .stillfading
   jmp   gamelogic
.stillfading:
   wai
   jmp   fadeintogame

//DISPLAY_REG is only copied to $2100 during vblank


The weird thing is these routines work in snes9x but not in bsnes. I'm guessing this is because bsnes is supremely accurate and stricter about writing to the registers. Is there a more appropriate way to fade the screen in and out?
Re: Cannot get sprites to display
by on (#173181)
Don't you have to enable NMI during V-Blank (or forced V-Blank) ?
Re: Cannot get sprites to display
by on (#173183)
Yes, reading $4210 once has to be done in one's NMI routine.

I don't see anything "immediately" wrong (but it's almost 0300 here) with the code in question, but I'm not sure that manipulating $2100 directly like that is ideal. inc (on a memory location or direct page) effectively does a read-write-increment-write operation (i.e. inc $2100 is actually the equivalent of lda $2100, sta $2100, inc, sta $2100). So, I would suggest keeping track of your "screen fade value" in direct page or RAM somewhere, and then reading/writing that to $2100. If you want an example of screen fading, the little demo I made as part of my SNES documentation back in the 90s included source for it.

Edit: oh, one thing I did notice: you're re-writing $80 to $4200 every fade in phase. I don't know what that's actually going to do to NMI. You should really only be doing that once. You don't need to keep doing it. Try changing your jmp to a label that does the dec. Or just go look at my old code. Honestly the screen fade stuff isn't that hard.
Re: Cannot get sprites to display
by on (#173184)
koitsu : At first i tough that myself too, then I saw the last line of the code provided : DISPLAY_REG is only copied to $2100 during vblank
My point is that I think that NMI isnt even enabled (cause it have to be done during forced V-Blank), so DISPLAY_REG value is never copied into $2100. snes9x don't care about that ... bsnes is more accurate on that one.
Re: Cannot get sprites to display
by on (#173192)
AzimuthFE wrote:
The sprite on the right is supposed to be square. Is this because I'm not using a scanline filter?


You're using 4 sprites, and all of them are pointing to char #65, which appears to be a 4x8 white block, is it not?
Re: Cannot get sprites to display
by on (#173198)
Thank you for your replies. I should have made it clear that the NMI is already enabled when the program enters these routines. I write #$80 to this register to disable the joypad. Having said that I did move the write outside the loop. I watched the fade frame-by-frame and it does seem to be working; it's just harder to perceive in bsnes than snes9x.

I tried it in higan-performance and it works fine. It even does the fade in the same way snes9x does. However, when I open the rom in higan-accuracy this happens:

Attachment:
higanmessedup.png
higanmessedup.png [ 43.43 KiB | Viewed 2629 times ]


The amount that it is shifted varies each time I open the rom.

ccovell wrote:

You're using 4 sprites, and all of them are pointing to char #65, which appears to be a 4x8 white block, is it not?


O.O really? I am just making a complete ass of myself in this thread aren't I? I changed the character and it worked. Thanks.
Re: Cannot get sprites to display
by on (#173208)
If something changes every time, then it relies on uninitialized data i.e. you're not initializing something you need to.
Re: Cannot get sprites to display
by on (#173249)
adam_smasher wrote:
If something changes every time, then it relies on uninitialized data i.e. you're not initializing something you need to.


Yup. I used a rather lazy loop to initialize the registers (a loop storing #$00 to $2100,x until x reached #$44). I added a loop that explicitly writes #$00 twice to each scroll register and it works. Thanks to everyone for the help.
Re: Cannot get sprites to display
by on (#173274)
AzimuthFE wrote:
adam_smasher wrote:
If something changes every time, then it relies on uninitialized data i.e. you're not initializing something you need to.


Yup. I used a rather lazy loop to initialize the registers (a loop storing #$00 to $2100,x until x reached #$44). I added a loop that explicitly writes #$00 twice to each scroll register and it works. Thanks to everyone for the help.

If by "initialise" you're talking about actually initialising the console itself on reset, writing $00 to all the registers is incorrect. The official documentation clearly outlines what all the values need to be (you can exclude $2104, $2118, $2119, and $2122).