Read Palette Data Bytes

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

User avatar
Movax12
Posts: 529
Joined: Sun Jan 02, 2011 11:50 am

Re: Read Palette Data Bytes

Post by Movax12 »

Of course they aren't. I use PLA \ STA in NMI, it works quite well. I start my vram buffer at $0100 and increment an index variable. This and the stack pointer move towards each other. In NMI I save the SP and set it to $FF. PLA now starts at $0100. Restore the SP when done.
Edit2: I see I misunderstood: BUILDING the buffers with stack instructions is the point of the previous post.


thefox, I don't understand how to use PHA to make things better, can you explain more? edit: I think I get it, but yes the buffer would be backwards resulting in slower vram writes.. it doesn't seem to be that useful.
Last edited by Movax12 on Sat Jan 12, 2013 1:54 am, edited 1 time in total.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Read Palette Data Bytes

Post by thefox »

Dwedit wrote:If you use interrupts, stack tricks for building the buffers are out of the question.
I hadn't though about that, but I don't think it should be a problem if the buffer has a couple of bytes of spare space. E.g. if an NMI occurs during the building, the return address will write to the PPU buffer, yes, but not over the existing buffer values. When the NMI returns the only result is that the buffer will have some garbage in it (which will get overwritten by more buffer data or a terminating byte anyways).
Movax12 wrote:thefox, I don't understand how to use PHA to make things better, can you explain more? edit: I think I get it, but yes the buffer would be backwards resulting in slower vram writes.. it doesn't seem to be that useful.
The VRAM writes would be slightly slower, yes, because an index register (X) needs to be modified unlike with PLA, but if LDA foo,X is unrolled I don't think it should be significantly slower. I guess it could turn out to be significant if a lot of small transfers are made. Dunno.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Read Palette Data Bytes

Post by tokumaru »

thefox wrote:if LDA foo,X is unrolled I don't think it should be significantly slower.
I don't think it would be slower at all. Unrolled PLAs and unrolled LDA foo, X require some logic to skip some of the leading writes, in case the amount of bytes to transfer is variable. Both require you to set the index of the first element to copy (the PLA way even needs TXS, which the other method doesn't need).
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: Read Palette Data Bytes

Post by blargg »

Dwedit wrote:If you use interrupts, stack tricks for building the buffers are out of the question.
Why so? When a program pushes bytes on the stack and then pulls them off, interrupts don't disturb this. This is equivalent.

EDIT: added context, sorry. I had thought my post was just after Dwedit's, but hadn't seen that there was a second page. thefox covered what I was getting at regarding the non-interference of interrupts to this buffering.
Last edited by blargg on Sat Jan 12, 2013 12:45 pm, edited 1 time in total.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Read Palette Data Bytes

Post by tokumaru »

Why what? The TXS? Well, once the NMI fires, if your buffer was at the top of the stack it isn't anymore. Even if you use "waiting for VBlank" instead of NMIs for VRAM updates you still might have more than one buffer or it/they might not necessarily be the last thing you put on the stack. If you're using the stack for buffering VRAM data, you'll most likely need to manipulate the stack pointer.
User avatar
Raccoon
Posts: 22
Joined: Tue Nov 30, 2010 9:22 am
Location: France

Re: Read Palette Data Bytes

Post by Raccoon »

Ho those guy are awesome.

Certainly this post have derivate a little, but for sure you've help me a lot and advice me.

At first glance I haven't plane to use the stack to buffer my PPU works.
Because I wasn't thinking of it, tricky care about the Interrupts (JSR RTS) during buffer build would be a pain ? You really need to save it in somewhere else ?

For know because of little time I have, I will let it this for later. (but maybe will need to understanding it more).

So know I have done my PPU Palette Data Update entirely in one frame (so the simpler way), using a Buffer ($00 → $20). Also before this buffer was Update, I build it in the main program. I've succes doing faddings (from black) and generate random palette colors (just for fun).

If someone want, ask it, I will share my "little devs".
Post Reply