Drawing attributes vertically

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Drawing attributes vertically

Post by DRW »

What is the typical way if I want to write the color attribute values into the PPU in a vertical way (for example when I have horizontal scrolling)?

For tiles, I can set bit 2 of PPUCTRL if I want to write tiles vertically, so it increments the PPU address by 32 after each write.
But is there also a good way to do this for attributes, incrementing by 8 for each write, or using some trick? Or do I indeed have to re-initialize the two address bytes manually for each write?
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Drawing attributes vertically

Post by calima »

No trick, have to set the addr every byte. Or just write the full 64 bytes in one go.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Drawing attributes vertically

Post by Dwedit »

Either set the address every write, or use 32 increment mode just to get two writes in.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Drawing attributes vertically

Post by DRW »

Alright, thanks. Looks like there's no way around it then.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Drawing attributes vertically

Post by tokumaru »

What I normally do for attributes is use increment 32 mode and write pairs of attribute bytes. Since 32 is equivalent to 4 attribute rows, the pairs are: 0 and 4, 1 and 5, 2 and 6, 3 and 7. If I'm scrolling vertically and the screen is between name tables, I don't bother with with partial updates, I just update all 16 bytes of the column (if using horizontal mirroring or 4-screen, otherwise it'll just be 8 bytes anyway) even though only some of them are visible. Updating all 16 bytes in pairs is faster than 9 bytes in ones.
Last edited by tokumaru on Mon Mar 07, 2022 1:53 pm, edited 1 time in total.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Drawing attributes vertically

Post by Dwedit »

I would keep a copy of the entire attribute tables in RAM, it makes it much simpler when you want to update them in VRAM.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Drawing attributes vertically

Post by DRW »

tokumaru wrote: Mon Mar 07, 2022 11:26 am What I normally do for attributes is use increment 32 mode and write pairs of attribute bytes. Since 32 is equivalent to 4 attribute rows, the pairs are: 0 and 4, 1 and 5, 2 and 6, 3 and 7.
That's a pretty good idea. Reduces half of the initialization data.
Dwedit wrote: Mon Mar 07, 2022 12:56 pm I would keep a copy of the entire attribute tables in RAM, it makes it much simpler when you want to update them in VRAM.
That's the one thing I want to avoid in my current constellation. That's why I designed meta tiles of 32 x 32 pixels, so that each meta tile has its own attributes value and bit manipulation and wasting 128 bytes in RAM isn't necessary.
My game "City Trouble":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
Post Reply