Data to pull for drawing pixels

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
DarylTechNES
Posts: 10
Joined: Sun May 10, 2015 5:01 pm

Data to pull for drawing pixels

Post by DarylTechNES » Sun May 10, 2015 5:09 pm

I'm writing an NES emulator and I'm trying to figure out where to pull the data from drawing pixels. Is there something out there as an example that shows what needs to be accessed on the PPU memory for pulling the color for a particular pixel?

For example, to draw pixel 0:

I look at 0x0000 and 0x0008 to get the least significant bits of the color for pixel 0.

tepples
Posts: 22277
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Data to pull for drawing pixels

Post by tepples » Sun May 10, 2015 6:43 pm

DarylTechNES wrote:I'm writing an NES emulator
Have you tried joining an existing open-source emulator project?

I'm of the opinion that everyone who wants to make an NES emulator should program at least "hello world" as an NES homebrew ROM before making an NES emulator. That way, you can at least make test ROMs that exercise the subset of functionality that you have implemented.

User avatar
tokumaru
Posts: 11991
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Data to pull for drawing pixels

Post by tokumaru » Sun May 10, 2015 7:34 pm

DarylTechNES wrote:Is there something out there as an example that shows what needs to be accessed on the PPU memory for pulling the color for a particular pixel?
The wiki has tons of information about rendering:

http://wiki.nesdev.com/w/index.php/PPU_rendering
http://wiki.nesdev.com/w/index.php/PPU_nametables
http://wiki.nesdev.com/w/index.php/PPU_attribute_tables
http://wiki.nesdev.com/w/index.php/PPU_scrolling
http://wiki.nesdev.com/w/index.php/Mirroring
http://wiki.nesdev.com/w/index.php/PPU_ ... evaluation
http://wiki.nesdev.com/w/index.php/PPU_sprite_priority
For example, to draw pixel 0:

I look at 0x0000 and 0x0008 to get the least significant bits of the color for pixel 0.
You'll not find answers as simple as this. The information for each pixel will not come from fixed memory positions, since scrolling allows the background to be moved around. Each pixel is a combination of pattern table bits (located through the scrolling position and name table data) and palette bits (loaded from the attribute table), overlaid with sprite pixels (calculated from data in the OAM and pattern tables). I couldn't possibly summarize the whole process in a single forum post, so please take a look at what the wiki has to say and ask here about the parts that aren't clear.

User avatar
Petruza
Posts: 311
Joined: Mon Dec 22, 2008 10:45 pm
Location: Argentina

Re: Data to pull for drawing pixels

Post by Petruza » Mon May 18, 2015 9:02 am

DarylTechNES wrote: For example, to draw pixel 0:
I look at 0x0000 and 0x0008 to get the least significant bits of the color for pixel 0.
Yes, that's for pixel 0 of tile 0 of a given pattern table.
Then you have to look up the nametable entries or sprites that use that tile, figure out which palette they use from the attribute table in case of background tiles, then figure out the position of the sprite or the tile based on scroll registers, and then you get where in the screen the pixel shows up.
As it's been said before, you'd better read the wikis and other documentation from nesdev.com to form a basic picture of how the NES architecture is laid out.

User avatar
tokumaru
Posts: 11991
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Data to pull for drawing pixels

Post by tokumaru » Mon May 18, 2015 10:02 am

Oh, I forgot to suggest something I always do when people are not familiar with the PPU, no matter if they are programming emulators or games: load several different games in FCEUX (and/or other emulators with similar debugging tools) and abuse the hell out of the PPU debugging tools. Look at the palettes, pattern tables, name tables, sprites, etc. as you observe the resulting picture in the main emulator window. That should help you piece everything together.

Once you understand the basic concept (which memory is used for what purpose), you'll have a high-level understanding of how NES graphics work. That should be enough to get some simple games working, but anything that interacts with the PPU while the screen is rendering will fail. To properly emulate those you'll have to understand the actual order in which the NES does things, and try to emulate that as best as you can.

snarfblam
Posts: 143
Joined: Fri May 13, 2011 7:36 pm

Re: Data to pull for drawing pixels

Post by snarfblam » Mon May 18, 2015 2:55 pm

You can also edit PPU memory on the fly in the hex editor and see how it affects things. Might help you more easily draw connections between debugger windows, memory maps, and format documentation.

Post Reply