Switching VRAM.

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
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Switching VRAM.

Post by nineTENdo »

hello anyone,

Ive been having problems switching the VRAM to the $1000 page in my CHR. i made a demo that writes a different nametable on the hit of a button. All works well until i tried to switch the VRAM. All that shows is my newly written nametable with the spirtes in the $0000 page of my CHR. Ive been poking around in the $2000 with little success. While im at it. what is the backround portion of the VRAM for(ie. 00000100).

thanks for the help.
el

p.s. does it have anything to with the fact that im using NESASM. i poked around in the header with little success.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

What do you mean "switching the VRAM"? $1000 is always CHR. Whether it's CHR-ROM or CHR-RAM depends on the mapper and board configuration you're using. Only a handful support both CHR-ROM and CHR-RAM at the same time (and I doubt you're using one), so if you're trying to turn your ROM into RAM -- that's not going to work.

I don't know if that's what you're trying to do or not -- I don't really understand your question =x
While im at it. what is the backround portion of the VRAM for(ie. 00000100).
???

background portion of VRAM? Do you mean the nametables?

I don't know what 00000100 is supposed to be -- are you talking about bit 2 of some register? Which register?

$2000.2 changes the PPU Address increment rate -- you can select between incrementing by 1 or incrementing by 32 (by 32 is useful for drawing columns of tiles to the nametable)

$2001.2 enables/disabled sprite clipping on the left-most 8 pixels of the screen. With clipping enabled, sprite pixels will be hidden on the left 8 columns.

But neither of those seem to have anything to do with "background portion of the VRAM" so I'm even more confused.


<minor rant> it's really hard to answer questions when they're poorly written. Try to articulate your thoughts a little better -- we're not mind readers, and we shouldn't have to try and decipher what you're asking. </minor rant>
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

I think it might have something to do with switching the background between the $0000 and $1000 pattern tables, or possibly switching the 8x8 pixel sprites between the $0000 and $1000 pattern tables.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

Disch wrote:What do you mean "switching the VRAM"? $1000 is always CHR.

From what I understand the pattern table is sprites arranged in CHR files.


And im kind of confused about at CHR starting at $1000. what starts at $0000 when the bit 3 of $2000 is clear on initialization.

I am confused about what vRAM and CHR have to do with one another now.

What im really trying to do is use the sprites table located at $1000-1FFF in my CHR file. to write a different nametable with different sprites, other than those located in my CHR file a $0000-0FFF.

What i assume is that the vRAM already points to this location ($0000) when clearing $2000 on initialization.

Disch wrote:background portion of VRAM? Do you mean the nametables?

I don't know what 00000100 is supposed to be -- are you talking about bit 2 of some register? Which register?
My mistake i meant bit 4 the Background Tile Table. i was unshure what it was.

thanks for your help
el



P.s. Basiclly if you cant understand what im trying to ask. Im confusing $0000 of VRAM (BIT 3 of $2000 clear) to $0000-0FFF of CHR file and $1000 of VRAM to $1000-$1FFF CHR as being related.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

nineTENdo wrote:
From what I understand the pattern table is sprites arranged in CHR files.


And im kind of confused about at CHR starting at $1000. what starts at $0000 when the bit 3 of $2000 is clear on initialization.
You can think of it like there are two pattern tables -- a "left" one ($0000-$0FFF) and a "right" one ($1000-$1FFF). Each pattern table holds 4K of CHR (which equates to 256 8x8 tiles). This means there are 512 tiles in your pattern tables at all times.

Since the BG can only select from 256 tiles, you use bit 4 of $2000 to select which pattern table the BG gets its tile graphics from. Setting the bit will make the BG use the "right" pattern table ($1xxx) and clearing it will make the BG use the "left" pattern table ($0xxx)

8x8 Sprites are in the same boat. They can only choose from 256 tiles -- so bit 3 of $2000 selects which pattern table they get their graphics from.

8x16 sprites, on the other hand, can use the whole 512 tiles -- so bit 3 of $2000 is ignored completely when using 8x16 sprites.

If you want a visual example -- load up a game like Super Mario Bros. in FCEUXD (or any emu with a pattern table viewer). Notice how all the graphics for sprites occupy the left pattern table, and all the graphics for the BG occupy the right.
I am confused about what vRAM and CHR have to do with one another now.
VRAM is like a generic term for PPU memory. CHR is a specific area of PPU memory. I find the term "VRAM" to be somewhat misleading on the NES, since it's not always RAM (CHR is often ROM, for example).

Anyway... the term "VRAM" usually encompasses all of CHR, Nametables, Attribute tables, and Palettes.

- CHR is the actual 8x8 graphics (ie: your pattern tables)
- Nametables is how those graphics are arranged on the BG
- Attribute tables (which are like a subsection of the nametable) assign which parts of the BG get which palette
- Palettes are the colors to be displayed.

- "VRAM" could be any of the above.
What im really trying to do is use the sprites table located at $1000-1FFF in my CHR file. to write a different nametable with different sprites, other than those located in my CHR file a $0000-0FFF.
You're getting your terms crossed. Sprites do not use name tables. Name tables are for the BG only. You're probably thinking of pattern tables.

All you have to do, in this case (assuming you're using 8x8 sprites), is set bit 3 of $2000. That's it.

LDA #%00001000
STA $2000

Just remember that writing to $2000 changes several things -- not just that one bit. The above code, for example, would also disable NMIs, switch to 8x8 sprites, set the PPU Address increment to 1, etc, etc.

If you're using 8x16 sprites -- then each sprite can pick which pattern table it gets its tiles from. The low bit of the tile ID (byte 2 in OAM/Sprite mem) selects which pattern table for each sprite. So if you want them all to use the right table -- then make sure you're using all odd tile IDs.
What i assume is that the vRAM already points to this location ($0000) when clearing $2000 on initialization.
Right... when you write 0 to $2000, both BG and sprites will be using $0xxx for patterns. To change that you'll have to write to $2000 again with a new value.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

If you didn't understand what Disch was saying, I'll explain it again.
nineTENdo wrote:
Disch wrote:What do you mean "switching the VRAM"? $1000 is always CHR.
From what I understand the pattern table is sprites arranged in CHR files.
Yes, the pattern table is the same thing as CHR: an 8192 byte block of memory in PPU space $0000-$1FFF. It is divided into two halves, each 4096 ($1000) bytes in size. These are the first half starting at $0000, and the second half starting at. Several emulators such as Nesticle and Nintendulator have menu options to display the pattern table data separately from the emulated NES output. Traditionally, pattern table $0000 goes on the left, and pattern table $1000 goes on the right, hence the common names "left pattern table" and "right pattern table".

But "sprites" are something separate. A "sprite" is an individual moving object. Each sprite has the number of a tile, and multiple sprites can reference one tile (e.g. multiple identical Goombas).

In this case, a cart has "VROM" or "CHR ROM" if the CHR is stored in a ROM directly connected to the PPU bus. It has "VRAM" or "CHR RAM" if the tile data is stored in a ROM connected to the CPU bus (the PRG ROM), and the CPU copies it into a RAM chip connected to the PPU bus (the CHR RAM). This CHR RAM is 8 KiB in size except for fewer than a dozen games.
And im kind of confused about at CHR starting at $1000. what starts at $0000 when the bit 3 of $2000 is clear on initialization.
When you write to $2000, one of the bits change which half of the pattern table is used for the background, and another changes which half is used for 8x8 pixel sprites.
I am confused about what vRAM and CHR have to do with one another now.
VRAM has two areas: CHR RAM, which is on the cartridge and usually 8 KiB in size, and nametable RAM, which is usually inside the NES and 2 KiB in size. Some cartridges don't have a CHR RAM; instead, they have a CHR ROM.
What im really trying to do is use the sprites table located at $1000-1FFF in my CHR file. to write a different nametable with different sprites, other than those located in my CHR file a $0000-0FFF.
"Nametable" has nothing to do with "sprites". The data stored in the pattern tables is called "tiles". To have the nametable use the second half of the pattern table, that is, $1000-$1FFF, you just write a new value to $2000.
P.s. Basiclly if you cant understand what im trying to ask. Im confusing $0000 of VRAM (BIT 3 of $2000 clear) to $0000-0FFF of CHR file and $1000 of VRAM to $1000-$1FFF CHR as being related.
Here's one thing you might have missed: You can write to $2000 multiple times while the NES is powered on. If you turn off the bit, the first half ($0000) is used. If you turn on the bit, the second half ($1000) is used. But changing the bit affects all the tiles or all the sprites on the screen, so you won't be able to use tiles from both halves of the pattern table without more advanced trickery.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

ok i got scared there for a sec. i forgot that one portion is for bg and the other for sprites. what i didnt know is that they can be in either left or right pattern tables and that to choose which ones you want you must let $2000 know. if this is the case im guessing some games used different mappers to swap out for other pattern tables. this must be the case. games like battletoads use a whole pattern table for just the title leaving little space for backrounds and sprites. i read somewhere that CHR ROM games cant switch and need CHR RAM to do that.

again thanks for the help and going above and beyond the call of duty.
el
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

nineTENdo wrote:i read somewhere that CHR ROM games cant switch and need CHR RAM to do that.
That's actually a little backwards.

Usually (over 99.9% of the time) games that have CHR-RAM just have 8K of CHR-RAM and they don't swap it out at all. The reason they can have more graphics is because it's RAM -- which means it's writable... meaning you can "draw" new tiles to the pattern tables by writing to that area in PPU memory ($0000-1FFF) -- just like you write tiles to the nametables (which is at $2xxx)

CHR-ROM is ROM (Read Only Memory) and so it's not writable. Which means games have to swap out different pages if they want more graphics.

In either case... CHR-RAM, or swappable CHR-ROM... it's possible to have more than 512 tiles total. You just can't have more than 512 at any one given time (though there are exceptions to this rule, of course -- like MMC5. But that's another issue)
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

A lot of people refers tiles as "sprites" even if those are BG tiles.

Also, for me VRAM is NameTable RAM, possibly CHRRAM, but usually the first. At least the official Nintendo terminology found on cartridge's or NES mainboard's seregraphy states CHRRAM as it, and Nametable RAM as VRAM, while CPU RAM is WRAM, no matter if it's located at $000-$7ff or $6000-$7fff. SRAM has only be used by reverse engeeners to refer $6000-$7fff CPU RAM, or sometimes SRAM specifically means that this area is battery-backede, but Nintendo never used this therm as far we know.

VRAM in itself means Vido-RAM, it could also be applied to CHRRAM or Palette RAM, but I'd discourage this to avoid confusion. VROM would in "theory" apply to Name Table ROM, but only a few japanese Namco games features this, so I guess this is the equivalent to CHRROM since it's the only common video-ROM. Most other consoles, such as the SNES, only have a generic VRAM chip in the console that the user is free to use for tiles (pattern table), the equivalent of nametables, and then the start adress of each used pattern table/name table (in NES equivalent terms) is selectable. The NES only have fixed start adresses (that is $0000 for pattern table #0, $1000 for pattern table #1, $2000 for nametable #0, $2400 for nametable #1, etc...) and have only 2k of internal RAM, wich is VERY likely to be used as nametable RAM (however it's techincally possible to put it as other uses), and the cartridge needs to have it's own memory chip either RAM or ROM for pattern table. The NES is the only console ever as far I know wich features CHRROM at all. I may be wrong tough.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Bregalad wrote:The NES is the only console ever as far I know wich features CHRROM at all.
Odyssey 2 and Intellivision had CHR ROM in the console.
Post Reply