Universal background color

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

User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Universal background color

Post by Dafydd »

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?
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

Post by unregistered »

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. :)
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

Didn't help, but thanks anyway :)
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Re: Universal background color

Post by Bregalad »

Wait, you used a

sta $3f00

instruction ?!?

You probably mean something like :

lda #$3f
sta $2006
lda #$00
sta $2006
lda #$whatever
sta $2007
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

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! :D
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: Universal background color

Post by blargg »

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.
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

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?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Universal background color

Post by 3gengames »

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.
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

What about the pattern name tables, palettes and stuff? Don't they need to be cleared? (I might be confusing VRAM with something else.)
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Universal background color

Post by 3gengames »

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. :)
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

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?
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Universal background color

Post by 3gengames »

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.
User avatar
Dafydd
Posts: 114
Joined: Sun Mar 16, 2008 1:45 am
Location: Uppsala, Sweden

Re: Universal background color

Post by Dafydd »

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.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Universal background color

Post by 3gengames »

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. :)
Shiru
Posts: 1161
Joined: Sat Jan 23, 2010 11:41 pm

Re: Universal background color

Post by Shiru »

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.
Post Reply