Universal background color
Moderator: Moderators
Universal background color
I've been trying to get started with the very most basic PPU programming. I took Blargg's simple demo (the one that just powers up the PPU and then plays a single note of sound) and added
lda #$1e ; turn rendering on
sta $2001
lda #$11 ; set universal background color to some kind of blue
sta $3F00
... and yet all I'm getting is grey when running my .nes in the emulator. What am I missing? I have no data in my char segment. Do I need to?
lda #$1e ; turn rendering on
sta $2001
lda #$11 ; set universal background color to some kind of blue
sta $3F00
... and yet all I'm getting is grey when running my .nes in the emulator. What am I missing? I have no data in my char segment. Do I need to?
Last edited by Dafydd on Fri Feb 22, 2013 9:17 am, edited 1 time in total.
-
unregistered
- Posts: 1193
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: Universal background color
Good morning... what comes to my mind is that maybe you should change the color of the background before turning on rendering. Hope someone else can really help you with this. 
Re: Universal background color
Didn't help, but thanks anyway 
Re: Universal background color
Wait, you used a
sta $3f00
instruction ?!?
You probably mean something like :
lda #$3f
sta $2006
lda #$00
sta $2006
lda #$whatever
sta $2007
sta $3f00
instruction ?!?
You probably mean something like :
lda #$3f
sta $2006
lda #$00
sta $2006
lda #$whatever
sta $2007
Re: Universal background color
I was just about to write something similar, yes. I'd missed the part about not being able to write to PPU memory directly. Thanks!
EDIT: Weeee, it's working!
EDIT: Weeee, it's working!
Re: Universal background color
Don't forget to read $2002 before setting the PPU address, if you're at all not sure the state of the internal flag that keeps track of whether the next $2006 write sets the high or low byte of the address.
Re: Universal background color
I figured that part out too. Thanks though!
I tried loading the resulting ROM in an emulator and it works as expected, but on my PowerPak I get a random mess of red and white (looks a lot like the pizza sprites from the TMNT games, but zoomed to 800%). I'm guessing it's because I don't have any CHR ROM so the game is just drawing whatever was in VRAM when starting the game (i.e. from the PowerPak menu). I should probably clear VRAM as well as CPU RAM after / during PPU warmup as well, right?
I tried loading the resulting ROM in an emulator and it works as expected, but on my PowerPak I get a random mess of red and white (looks a lot like the pizza sprites from the TMNT games, but zoomed to 800%). I'm guessing it's because I don't have any CHR ROM so the game is just drawing whatever was in VRAM when starting the game (i.e. from the PowerPak menu). I should probably clear VRAM as well as CPU RAM after / during PPU warmup as well, right?
Re: Universal background color
Nope, don't touch VRAM. You don't read it, so it doesn't need set up. Anything needing to be set up will be written by the routines to upload graphics, or will just be in ROM.
Re: Universal background color
What about the pattern name tables, palettes and stuff? Don't they need to be cleared? (I might be confusing VRAM with something else.)
Re: Universal background color
Why would they need "cleared"? They will be cleared when you write the data you need to be there to them. Unless you display a un-setup screen/palette. 
Re: Universal background color
Couldn't the same be said for CPU RAM, then? In the example code, CPU RAM is being cleared while waiting for the PPU to stabilize (as we don't know for sure it's all zeroes when starting up. My computer does the same when booting afaik). I guess it's more of a convenience rather than anything else, but still.
It's a little off-topic, but I added some code that changes the background color if the zapper trigger is pressed, and it results in what looks like a random nametable where non-zero characters are being spread out on the screen, mostly on the left edge. Is this because I'm writing to $2007 while not in VBLANK or something?
It's a little off-topic, but I added some code that changes the background color if the zapper trigger is pressed, and it results in what looks like a random nametable where non-zero characters are being spread out on the screen, mostly on the left edge. Is this because I'm writing to $2007 while not in VBLANK or something?
Re: Universal background color
Yeah. But it's harder to code for the CPU because you use so many variables. While the program will control what you see on the screen, so there is 100% no reason to clear it, unless you're a bad programmer.
But you can not clear CPU RAM. It's just when that happens, it's VERY hard to make sure your game boots+runs right all the time, as you may go to check a variable that hasn't been initialized right.
But you can not clear CPU RAM. It's just when that happens, it's VERY hard to make sure your game boots+runs right all the time, as you may go to check a variable that hasn't been initialized right.
Re: Universal background color
I'm a pretty bad programmer until further notice (at least as far as NES and assembler are concerned), so I think I'll keep running the RAM clearing routine ^^
Writing to $3F00 only once during a frame seems to have fixed the issue. I'll keep that in mind.
Writing to $3F00 only once during a frame seems to have fixed the issue. I'll keep that in mind.
Re: Universal background color
That bug you described above is because you have to write $2000 and $2005 2x after doing all your $2006 stuff before the screen displays. You'll learn why when you get father in to the wiki. 
Re: Universal background color
Clearing RAM helps to stabilize some bugs, but it also gives a good chance for them to remain unnoticed. Some emulators clears RAM anyway, but HW does not, so when you don't clear RAM, it could be a surprise that program is unstable when running on the real HW. To clear or not to clear, that is the question. I think it may be a good idea to clear it, but sometimes try to change the clear value to something other than zero, just to see if you have forgot to initialize some variable.