Cannot get sprites to display

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
AzimuthFE
Posts: 17
Joined: Thu Jun 09, 2016 4:46 pm

Cannot get sprites to display

Post by AzimuthFE »

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.
pongoam.png
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.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Cannot get sprites to display

Post by psycopathicteen »

Maybe there's no sprite palettes. Sprites use the 2nd half of the color palette table.
niconii
Posts: 219
Joined: Sun Mar 27, 2016 7:56 pm

Re: Cannot get sprites to display

Post by niconii »

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.
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: Cannot get sprites to display

Post by 93143 »

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?
AzimuthFE
Posts: 17
Joined: Thu Jun 09, 2016 4:46 pm

Re: Cannot get sprites to display

Post by AzimuthFE »

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.
fsnes000.png
fsnes000.png (556 Bytes) Viewed 4224 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: Select all

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?
lint
Posts: 25
Joined: Thu May 15, 2008 4:05 am

Re: Cannot get sprites to display

Post by lint »

Don't you have to enable NMI during V-Blank (or forced V-Blank) ?
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Cannot get sprites to display

Post by koitsu »

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.
lint
Posts: 25
Joined: Thu May 15, 2008 4:05 am

Re: Cannot get sprites to display

Post by lint »

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.
https://twitter.com/Lint_
http://snesdev.antihero.org/ [depecated blog, new one coming one of these days]
ccovell
Posts: 1045
Joined: Sun Mar 19, 2006 9:44 pm
Location: Japan
Contact:

Re: Cannot get sprites to display

Post by ccovell »

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?
AzimuthFE
Posts: 17
Joined: Thu Jun 09, 2016 4:46 pm

Re: Cannot get sprites to display

Post by AzimuthFE »

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:
higanmessedup.png
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.
adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Victoria, BC

Re: Cannot get sprites to display

Post by adam_smasher »

If something changes every time, then it relies on uninitialized data i.e. you're not initializing something you need to.
AzimuthFE
Posts: 17
Joined: Thu Jun 09, 2016 4:46 pm

Re: Cannot get sprites to display

Post by AzimuthFE »

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.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Cannot get sprites to display

Post by koitsu »

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).
Attachments
Capture.PNG
Post Reply