a pitifully newbie question

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
Celius
Posts: 2158
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

a pitifully newbie question

Post by Celius »

Okay, I really SHOULD already know this, but I don't because I've just used tepples "name" program to make backgrounds. Now. I tried to make just a simple hello world program, and tried changing the attributes manually, and it works, but it skips a section each time. Like do this:

lda #$23
sta $2006
lda #$C0
sta $2006

lda #$01
sta $2007
sta $2007

and it will make 1 2x2 section pallete #$01 rather than #$00, and it will skip one, then color the one right after that. I am sure all of you know that, and know what the heck the deal is. This is why I'm coming to you. Can you help me? Thanks.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

In the following... when I use the term "block", I mean 2x2 tile squares (16x16 pixels)

Each one byte of the attribute data contains data for FOUR blocks. So everytime you write to the attribute table, you're changing 4 blocks' attribute data (a whole 32x32 pixel area on the screen).

You're writing $01 to the attribute table.. each 2 bits of that byte will set the color for one of the blocks in the respective area.

$01 -> %00000001 -> 00, 00, 00, 01

So you're only setting the upper-left block of the 32x32 area to use palette 1, and the upper-right block is still using palette 0 (along with both lower blocks).

For greater detail on how the attribute table works, I recommend you browse nestech's attribute table section.


To clarify why this is skipping a block:

1) Attribute table starts out zero'd out. So it looks like the following (upper-left corner of the attr table):

000000..
000000..
000000..
000000..
....

2) You're first write to the attribute table (write $01) sets the upper left block to use palette 1, all other blocks in the same area to use palette 0. Attr table now looks like the following (changed sections bolded):

100000..
000000..
000000..
000000..
....

3) The address is incremented on that write, so your next write (another write of $01) changes the next attribute area in the same manner (changed sections bolded):

101000..
000000..
000000..
000000..
....
Celius
Posts: 2158
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Oh, thank you! That cleared a whole lot up for me! Thanks Disch! :)
Post Reply