PPU RAM not including cartridge

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
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

PPU RAM not including cartridge

Post by battagline »

I've been looking through the PPU documentation and I'm trying to figure out how much Memory the PPU has if you don't add any additional memory that it uses on the cartridge.

I know it can address 16K. If you remove the space dedicated to mirrors from the PPU Memory map it looks like it has about 12K of memory, but I seem to recall having read on one of the pages that the NES has 10K of PPU memory.

Would someone mind setting me straight?

Thanks
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: PPU RAM not including cartridge

Post by koitsu »

If there isn't CHR-RAM on the cartridge, and there's no CHR-ROM on the cartridge, then your pattern table (PPU $0000-1FFF) will be most likely gibberish/trash/gobbledegook.

Otherwise, the NES *natively* has memory for two nametables (1024 bytes each, which includes the attribute table), 16 bytes for palette, and an internal 256 bytes for OAM. (1024*2)+16+256 = $910 = 2320 bytes. This does not include internal buffers (say, a couple bytes) for latches and whatever else.

https://wiki.nesdev.com/w/index.php/PPU_memory_map is pretty clear (bottom part of the page).

I'm wondering why you're wondering this?

Edit: add mention of attribute tables.
Last edited by koitsu on Wed Nov 14, 2018 9:46 pm, edited 1 time in total.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: PPU RAM not including cartridge

Post by tepples »

If the cartridge provides no memory, the PPU is limited to 2 KiB (apart from OAM for sprite positions and CGRAM for palette). The only game I know of that's designed for this configuration (mapper 218) is nocash's Magic Floor, which allocates 1 KiB for a single nametable (single-screen mirroring) and 1 KiB for a 64-tile pattern table at $0000-$03FF (mirrored to $0400-$1FFF).

The 10 KiB figure probably comes from the smallest practical CHR ROM or CHR RAM on the cartridge (8 KiB) plus using the 2 KiB of PPU memory in the Control Deck for two nametables.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: PPU RAM not including cartridge

Post by tokumaru »

koitsu wrote:If there isn't CHR-RAM on the cartridge, and there's no CHR-ROM on the cartridge, then your pattern table (PPU $0000-1FFF) will be most likely gibberish/trash/gobbledegook.
Yeah, there's no way to produce real NES graphics without *something* inserted into the cartridge slot. In order to use the the internal VRAM for patterns, you need to some pins in the cartridge port connected together.
Otherwise, the NES *natively* has memory for two nametables (1024 bytes each, which includes the attribute table), 16 bytes for palette, and an internal 256 bytes for OAM. (1024*2)+16+256 = $910 = 2320 bytes. This does not include internal buffers (say, a couple bytes) for latches and whatever else.
Just to be a little pedantic: The palette actually has 28 physical entries (16 for the background, out of which only 13 are normally displayable, and 12 for sprites), but AFAIK the PPU doesn't store the upper 2 bits of a color entry (NES colors are only 6 bits after all), so the palette is more like 168 bits, the equivalent to 21 bytes. The same goes for the OAM: unimplemented bits in the sprite attribute byte are not kept, so the OAM is actually 1856 bits, the equivalent to 232 bytes. And there's more memory worth of other stuff we don't have direct access to, like secondary OAM, which the wiki says is 32 bytes.

Anyway, while 2KB of VRAM sounds really pitiful compared to the 10KB the NES normally has access to, I still think it's a fun setup to develop simpler games for. If you use 1KB for the background, you get 1KB for patterns, enough for 64 tiles, shared between sprites and the background. If you dynamically allocate tiles for active sprites and animate them by rewriting their patterns, and keep the backgrounds simple, it might be possible to make a game that doesn't feel too far off from earlier NES titles. You could also sacrifice some screen space in the single name table you have in order to get some extra tiles, depending on the kind of scrolling you're doing.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: PPU RAM not including cartridge

Post by rainwarrior »

Aside from the question of what goes into a cartridge...

Under most circumstances, if you put 0 in the CHR size field in the iNES header, you get 8k of CHR-RAM for just the pattern tables.

The nametables and palette are separate internal RAM. (2k nametable + 32 more bytes for palette.)

There are exceptions to this, and there's the iNES 2 thing that lets you specify CHR-RAM of any size, but that's the basic case.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: PPU RAM not including cartridge

Post by Bregalad »

battagline wrote:I've been looking through the PPU documentation and I'm trying to figure out how much Memory the PPU has if you don't add any additional memory that it uses on the cartridge.
The PPU has memory for OAM and the palettes. That's 256 bytes and 32 28 bytes respectively (with some individual bits missing). The rest is external and a cartridge can place anything (VRAM/VROM) should be placed in the 16k adress range you mention - or else the PPU won't be able to display anything.

The console has a 2k generic SRAM chip that the cartridge can use as VRAM anywhere in the PPU adress range. This chips is NOT part of the PPU itself. 99% of the time it is used at $2000-$3fff for name/attribute tables. Even though the chip is inside the console, it's control lines from the cartridges that determines how this chip is used.
Last edited by Bregalad on Thu Nov 15, 2018 1:22 am, edited 3 times in total.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: PPU RAM not including cartridge

Post by tokumaru »

Addressing this, specifically:
battagline wrote:I know it can address 16K. If you remove the space dedicated to mirrors from the PPU Memory map it looks like it has about 12K of memory, but I seem to recall having read on one of the pages that the NES has 10K of PPU memory.
You're right, the PPU can address 16KB of external memory (minus the 256 bytes in the $3F00-$3FFF range, which is used to access the internal palette RAM). The NES itself only has 2KB of VRAM built-in, which are normally used for name tables, mapped to the upper half of the PPU's address space (the 2KB are mirrored to fill the 8KB space). Cartridges are responsible for filling the bottom half with patterns. That's 10KB of video memory, the most common setup.

However, the cartridge connector on the NES is versatile enough that you can tweak the PPU memory mapping quite a bit. You can redirect pattern table access back to the console's built-in RAM, you can redirect name table access to the cartridge, you can map cartridge RAM/ROM to the entire $2000-$3F00 range in multiple configurations, including bankswitching, and even have the NES make do with just the internal 2KB, like mentioned in previous posts.

One thing to keep in mind is that even though the PPU can see almost 16KB of external memory at a time (i.e. ignoring bankswitching), only the lower 12KB are used by the PPU to generate a picture. The PPU itself doesn't do anything with whatever is mapped to $3000-$3FFF. If you have RAM there, great, you can write to it, read from it, but the PPU will not use that data for anything.
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: PPU RAM not including cartridge

Post by battagline »

Ok, so to make sure I understand, the bottom 8K (Pattern Table) is basically the CHR ROM chip that's on the cartridge.

The 2K of PPU RAM is used for 2 Nametables that are either horizontally or vertically mirrored.

That's a total of 10K

So where does the sprite data from the DMA go? Does it get copied into somewhere in the PPU's memory space?

Also, are the 32 bytes of palette data, is that on a separate chip somewhere or is the amout of RAM actually 2K + 32 bytes?

Thanks for the help
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: PPU RAM not including cartridge

Post by pubby »

OAM and palette memory are internal to the PPU. The palette is mapped into the same address space as name tables and pattern tables, but it is not the same physical memory. OAM has its own address space, which is why OAMADDR exists.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: PPU RAM not including cartridge

Post by tokumaru »

Both Koitsu and I mentioned palette and OAM already, I guess you weren't paying attention. Like I said before, even though palette RAM maps to a 32-byte range of memory ($3F00-$3F1F), there are only 28 physical palette entries inside the PPU (color 0 inesch of the 4 sprite palettes are mirrors of the respective color 0 in the background palettes). Also, since each bit of memory adds to the cost, the PPU doesn't store unused bits, so it only holds 6 bits per color, not a full byte.
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: PPU RAM not including cartridge

Post by battagline »

tokumaru wrote:I guess you weren't paying attention.
I'm always paying attention. I'm just a little slow, so I don't always understand everything ;-)

Anyway, I'm not trying to annoy you. I really do appreciate the help.
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: PPU RAM not including cartridge

Post by tokumaru »

I didn't mean to be rude, it's just that you did ask something that had already been answered.
User avatar
battagline
Posts: 152
Joined: Wed Sep 05, 2018 11:13 am
Location: Colorado
Contact:

Re: PPU RAM not including cartridge

Post by battagline »

tokumaru wrote:I didn't mean to be rude, it's just that you did ask something that had already been answered.
I know... sometimes I read through the responses and I don't pick up on everything mentioned.

What usually happens is I read, then I ponder, then I think of new questions. I probably should have a re-read step because this happens more often than it should. Sometimes you guys answer more questions than I ask, and if my mind isn't ready for that question at the time I read it, it just kind of goes over my head. If I re-read everything a second time, I would probably do a lot better at this.

Anyway, this community has been great and I'm sorry if I sometimes ask questions that have already been answered.

Thanks again,
Rick
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: PPU RAM not including cartridge

Post by Bregalad »

tokumaru wrote:Both Koitsu and I mentioned palette and OAM already, I guess you weren't paying attention.
I mentionned it too, so you're not paying attention either :p
Post Reply