#16216 - LOst? - Tue Feb 10, 2004 7:59 pm
I want to rotate a few palette indexes during my game, but I got a slowdown problem. Is it possible to copy a whole palette array every frame with the GBA without slowdowns in the game loop? Have you tired it? Is it possible to redirect the palette pointer to another RAM address? (probably not)
I can live with slowdowns really, but not when i have to do the copy during a HBlank interrupt!! That's like killing the fucking game. Help me please!
#16217 - poslundc - Tue Feb 10, 2004 8:10 pm
You've got plenty of time to change the palette during VBlank. VBlank lasts for 68 scanlines or 83,776 cycles, and copying an array from IWRAM to Palette RAM using DMA should only take 384 cycles (according to Cowbite).
Changing the palette during HBlank is another matter. You don't have long enough to change the entire palette before the next scanline starts drawing. But there aren't very many effects that would require this anyhow.
You cannot change where the palette is located in VRAM.
Dan.
Last edited by poslundc on Tue Feb 10, 2004 8:11 pm; edited 1 time in total
#16218 - sajiimori - Tue Feb 10, 2004 8:11 pm
There is plenty of time to copy the entire obj + bg palettes many times per frame.
Hblank is another story. tepples did the math earlier to figure out how many palette entries you can expect to copy during hblank, but I don't remember the figure. Suffice to say that there is not enough time to copy a whole 256 color palette, but there is enough to copy a 16 color one.
Edit: Dan you fiend!! :-P
#16219 - poslundc - Tue Feb 10, 2004 8:21 pm
sajiimori wrote: |
Edit: Dan you fiend!! :-P |
Haha, I even had time to look stuff up in Cowbite, although I was in such a hurry to beat everyone to it that I did my math incorrectly and had to go back and edit it afterwards. We should start keeping score or something. Or get lives. ;)
Dan.
#16238 - tepples - Wed Feb 11, 2004 2:11 am
"Or get lives" you mean extra lives?
If you're copying from EWRAM to the palette, you can probably move a 2-byte color every 4 cycles. Because Hblank is approximately 256 cycles long, this means you can update four 16-color palettes in one scanline, but this leaves little time left for any other sort of raster effect.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#16241 - poslundc - Wed Feb 11, 2004 3:11 am
tepples wrote: |
"Or get lives" you mean extra lives? |
Way to lower the bar for all of us, tepples. ;)
Quote: |
If you're copying from EWRAM to the palette, you can probably move a 2-byte color every 4 cycles. Because Hblank is approximately 256 cycles long, this means you can update four 16-color palettes in one scanline, but this leaves little time left for any other sort of raster effect. |
If you're serious about doing it during HBlank, I'd think it would be worth using IWRAM as the source, since you can do a 32-bit transfer in 3 cycles versus 8 cycles from EWRAM.
Dan.
#16253 - tepples - Wed Feb 11, 2004 7:01 am
OK, assuming 32-bit 0ws source (e.g. IWRAM), 16-bit 0ws destination, 32-bit DMA, and <=256 cycles, you can copy two colors in three cycles, or about 160 or so colors in one Hblank. But now you have 160 colors per scanline times 160 scanlines per screen = 25600 colors per screen, or 51200 bytes per screen, overflowing IWRAM. Now you see why I chose EWRAM for the example rather than IWRAM.
However, if you only update palettes once every 8 scanlines, you have a more manageable 6400 bytes per screen, which will fit into IWRAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#16256 - LOst? - Wed Feb 11, 2004 8:25 am
Thanks for the info. I want to change the palette below a special scanline. A water effect, and maybe some register can do that effect? I looked at BLDMOD but it doesn't do the effect. How the hell can Sonic Advance 2 do this at the same time as using HBlank for bg effects? It changes all the palettes below a scanline.
[Images not permitted - Click here to view it]
What are they doing here?
#16265 - batblaster - Wed Feb 11, 2004 12:51 pm
I think you can try using a DMA function and copy all in one time , to manage the palette make an array of int in ram and copy it to palette in one time with DMA...
Is an Idea i've used this way to make some color effect...
_________________
Batblaster / 7 Raven Studios Co. Ltd
------------------------------------------
#16279 - poslundc - Wed Feb 11, 2004 3:47 pm
LOst? wrote: |
Thanks for the info. I want to change the palette below a special scanline. A water effect, and maybe some register can do that effect? I looked at BLDMOD but it doesn't do the effect. |
The effect is MUCH easier to achieve using BLDMOD. Just have an opaque, blue text background overtop of wherever you want the water to appear and set BLDMOD to alpha-blend the two layers, using 8 and 8 as your coefficients (50% of one layer and 50% of the other).
You can even do it without using the extra background if you change your backdrop colour to blue (set bg palette entry 0), set up the blend to be between your layer and the backdrop, and then either use an HBlank interrupt or a window to turn it on where you want it.
Quote: |
How the hell can Sonic Advance 2 do this at the same time as using HBlank for bg effects? It changes all the palettes below a scanline. |
I'm not sure what's going on in that picture. Are you 100% sure that the palette is changing at the water scanline? It shouldn't be possible for them to change both the background and object palettes in one scanline without it creating some small artifact on that scanline (which could be prevented by having a one-colour waterline for a single scanline that obscures everything, but it doesn't even seem like they have that).
Dan.
#16285 - DarkPhantom - Wed Feb 11, 2004 7:26 pm
I've noticed that effect also but I just assumed that they were using an alpha blending top layer to generate that effect. It is obvious that they are using somekind of palette manipulation in this case. From the screen shot we see that the two background palettes are identical save for the second having a blue/green hue and that would generate the effect we are seeing. I wouldn't have thought that copying an entire 256 color palette in one hblank was possible but, obviously, it is.
What's happening is to the sprite palette is more difficult to determine because these palettes don't seem to be completely identical like the background palettes. Reasonably, they must be keeping two versions of each palette in IWRAM and are copying them at the appropriate time using DMA 0 (which is the fastest). I still don't think you could copy both the background and the sprite in one hblank.
The obvious solution here is too copy the background the in the initial hblank that you want and then copy the sprite palette on the successive hblank. This means that you will have one scanline that is "underwater" for the background but not the sprites. This probobly won't matter because it's on the boundry between above and underwater so nobody will notice, it might even look natural since the object will be in the process of submerging at that point anyway.
This is a neato effect, I never would have though of it -- go Sega, Woo!!
_________________
"head straight for your goal by any means
there is a door that you've never opened
there is a window with a view you've never seen
get there no matter how long it takes"
-Theme of Shadow, Sonic Adventure 2
#16287 - poslundc - Wed Feb 11, 2004 8:12 pm
DarkPhantom wrote: |
The obvious solution here is too copy the background the in the initial hblank that you want and then copy the sprite palette on the successive hblank. This means that you will have one scanline that is "underwater" for the background but not the sprites. This probobly won't matter because it's on the boundry between above and underwater so nobody will notice, it might even look natural since the object will be in the process of submerging at that point anyway. |
It's not possible to copy even a single entire palette in a single HBlank.
HBlank is 228 cycles long. Even if you used a VCOUNT interrupt to prep for it the line before, and held it in a tight loop until HBlank so that you could maximize your usable cycles, you could only copy about 150 colours (or a little more than 50% of your palette) before the hardware starts drawing again.
So that's simply not how it's being done.
DMA0 is not "faster" than any of the other DMAs, it just takes priority over the others.
Again, I ask LOst, are you sure that's how it's being done? Because it wouldn't necessarily be very easy in VBA to distinguish changes in the palette for different scanlines. It seems much more likely to me than they are using REG_BLDMOD.
Dan.
#16293 - Miked0801 - Wed Feb 11, 2004 10:22 pm
My turn. We are updating all BG and Obj palettes on a line to allow a HUD at the bottom of the screen to be independant of the top. We just blast away - not caring about copying across HBlanks or not. We just make sure that BG is copied first and that the BG char(s) in which we do this is referencing palette 0 so that we don't get rainbows. Also, we make sure we don't have any sprites overlapping this area (that are visible) to prevent their rainbowing either. It takes just slightly over 1 scanline to do this with our scroll register split screening along with running through our fairly slow HBlank handler. I can study this further for better timing, but the morale is unlike the GBC, the GBA doesn't care as much if you copy stuff outside of HBlank period as long as you are careful.
#16299 - poslundc - Wed Feb 11, 2004 11:34 pm
The only way that could be what they're doing is if the waterline never spans tiles of more than a few palettes in a single screen, throughout the entire game. But this seems unlikely to me, as it woud mean imposing an unnecessary and complicated design constraint as well as a lot of extra programming and painstaking system design just to get out of using the effects register.
Then again, it turned out Mariokart switches modes halfway down the screen, so what do I know. :P
Dan.
#16302 - DarkPhantom - Thu Feb 12, 2004 12:53 am
poslundc wrote: |
DMA0 is not "faster" than any of the other DMAs, it just takes priority over the others. |
Yes, you are right, I misunderstood my documentation. It says that it is "faster" because you typically use it to transfer in RAM which is faster than transfering from ROM. My bad.
poslundc wrote: |
So that's simply not how it's being done. |
Okay, but then why does the palette have the blue/green hue on the last hblank compared to the first hblank?
poslundc wrote: |
It seems much more likely to me than they are using REG_BLDMOD. |
I totally understand that, and yes I agree that is a good technique but, the issue is how is Sonic 2 doing it? We see from the screen shot that palette has been modified somewhere between the first and last scanline? BLDMOD wouldn't have that effect would it?
Now, that I've checked the timing you are also correct that the hblank is too short for a full transfer. You had a good point about only using the first 100 or so colors but I don't think that is happening here either.
Miked0801 wrote: |
the morale is unlike the GBC, the GBA doesn't care as much if you copy stuff outside of HBlank period as long as you are careful |
Really? I read somewhere that the vram is locked during draws.
_________________
"head straight for your goal by any means
there is a door that you've never opened
there is a window with a view you've never seen
get there no matter how long it takes"
-Theme of Shadow, Sonic Adventure 2
#16306 - torne - Thu Feb 12, 2004 1:44 am
Nope, vram is not locked. On the GB/GBC writes during draw were 'lost' in some conditions; on the GBA extra wait states are inserted and the writes succeed (with the appropriate bizarre visual effects).
#16307 - tepples - Thu Feb 12, 2004 1:59 am
poslundc wrote: |
The only way that could be what they're doing is if the waterline never spans tiles of more than a few palettes in a single screen, throughout the entire game. But this seems unlikely to me |
When looking at how Sonic Advance games do their effects, imagine how you would do the same thing on a system with- no hardware blending
- only four 16-color palettes instead of 16
- only two text backgrounds instead of four
It seems much of how Sonic Advance works came ultimately from the restrictions of the Sega Genesis, with which many members of Sega's Sonic Team unit are probably intimately familiar; I'm guessing it was easier to port the Blast Processing Engine (the graphics engine behind Sonic 2 for Sega Genesis) to the GBA than to design an all-new system.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#16322 - LOst? - Thu Feb 12, 2004 2:24 pm
[Images not permitted - Click here to view it]
Here is a picture of a water level in Sonic Advance 1. It uses the palette switch but also a ripple effect in the background (only one bg though).
It seems they're using something called Y trigger to copy both the bg and the palette (DMA0!).
After the Hblank IRQs they use DMA3 to copy 0x80 dwords into the bg palette, and also DMA3 to copy 0x80 dwords into the sprite palette.
I want to be able to do Hblank ripple effect to! =P
Is this possible at all? I have enough problems with my standard Hblank IRQ for making effects with one bg.
Quote: |
I'm guessing it was easier to port the Blast Processing Engine (the graphics engine behind Sonic 2 for Sega Genesis) to the GBA than to design an all-new system. |
I don't want to start a discussion about their old engines for older consoles. They have used this technique for all their Sonic games, but not with this amount of colors! And btw, this engine is new and not based on the old, which was programmed in pure Motorola 68k assembler.
Now back on topic. I've been playing the new GBA Metroid game, and it uses a bg with BLDMOD effects for water, but I don't want to use that technique in my game.
#16326 - poslundc - Thu Feb 12, 2004 3:27 pm
LOst? wrote: |
It seems they're using something called Y trigger to copy both the bg and the palette (DMA0!).
After the Hblank IRQs they use DMA3 to copy 0x80 dwords into the bg palette, and also DMA3 to copy 0x80 dwords into the sprite palette. |
The Y-trigger would be a REG_VCOUNT interrupt. My guess is that they either just don't worry about there being some scanline differential as to where the waterline actually appears, or they wait for HBlank to occur and then make sure their backgrounds use the lower half of the palette wherever there's a transition to water.
The sprite palette swap shouldn't be a problem, since the sprite is obscured by the waterline, bubbles and other stuff when it enters the water. Plus the sprite probably only rarely gets near the left edge of the screen.
Quote: |
I want to be able to do Hblank ripple effect to! =P
Is this possible at all? I have enough problems with my standard Hblank IRQ for making effects with one bg. |
The ripple effect is relatively easy; just set up an array during VBlank for what the horizontal offset of the background should be for each scanline, then copy that value in during HBlank. Use a simple sinusoid to determine the values.
Quote: |
Now back on topic. I've been playing the new GBA Metroid game, and it uses a bg with BLDMOD effects for water, but I don't want to use that technique in my game. |
Suit yourself, but unless you've got a really, really important other use for the effects register, you should realize that it's the easiest and most sensible way to do it. Just because Sonic does it a more complicated way doesn't make it any better.
Dan.
#16327 - LOst? - Thu Feb 12, 2004 3:37 pm
[quote="poslundc"] LOst? wrote: |
Suit yourself, but unless you've got a really, really important other use for the effects register, you should realize that it's the easiest and most sensible way to do it. Just because Sonic does it a more complicated way doesn't make it any better. |
I know it doesn't make it any better, but I've grown up with palette effects =P
#16329 - LOst? - Thu Feb 12, 2004 5:58 pm
Okay, I managed to copy one palette array during 1 frame, where Sonic Advance manages to copy four arrays. And I use the same DMA settings.
Seriously, GCC must be slow.
#16334 - Miked0801 - Thu Feb 12, 2004 8:03 pm
HBlanks with speed concerns aren't the best place to use C code. Take a look at the mess that is generated in GCC for doing a DMA and laugh. In Asm, you preset all the DMAs before the HBlank, then tell it go at just the right instant. Much better.
#16340 - LOst? - Thu Feb 12, 2004 9:11 pm
I downloaded a new GCC version, and I got it to work!!!
You can see the water effect in my test ROM here:
http://logotypes.se/tmp/water.zip
Thank you for all the information!
#16360 - DarkPhantom - Fri Feb 13, 2004 5:39 am
So, what was the final soultion to the timing problem? The DMA doesn't actually fit during the hblank? Do we just ignore the problem or is it that the palettes are setup to acomidate the effect?
_________________
"head straight for your goal by any means
there is a door that you've never opened
there is a window with a view you've never seen
get there no matter how long it takes"
-Theme of Shadow, Sonic Adventure 2
#16365 - LOst? - Fri Feb 13, 2004 1:41 pm
DarkPhantom wrote: |
So, what was the final soultion to the timing problem? The DMA doesn't actually fit during the hblank? Do we just ignore the problem or is it that the palettes are setup to acomidate the effect? |
I believe one of the problems were when I used DMA3 in an interrupt. Another problem was my old GCC, that had a slowdown problem.
Now I can copy both bg and obj palettes every frame, + having the palette change when water shows up. That means I can now copy 256*4 palettes during one frame without slowdown problems. This is great!
#16374 - dagamer34 - Sat Feb 14, 2004 1:13 am
Good for a demo. Sometimes bad for a game. Then again, most of us don't get to the game stage now do we?
_________________
Little kids and Playstation 2's don't mix. :(
#16387 - alek - Sat Feb 14, 2004 10:52 am
I have what may be some stupid questions which belong in the beginner section but this was written here so I'll just post the questions here as well.
LOst? wrote: |
I believe one of the problems were when I used DMA3 in an interrupt. Another problem was my old GCC, that had a slowdown problem.
Now I can copy both bg and obj palettes every frame, + having the palette change when water shows up. That means I can now copy 256*4 palettes during one frame without slowdown problems. This is great! |
1.How do you check to see that there are no slowdowns?
2.Do you mean that you can copy a whole 256 palette during a single HBLANK?
#16391 - LOst? - Sat Feb 14, 2004 4:16 pm
alek wrote: |
I have what may be some stupid questions which belong in the beginner section but this was written here so I'll just post the questions here as well.
LOst? wrote: |
I believe one of the problems were when I used DMA3 in an interrupt. Another problem was my old GCC, that had a slowdown problem.
Now I can copy both bg and obj palettes every frame, + having the palette change when water shows up. That means I can now copy 256*4 palettes during one frame without slowdown problems. This is great! |
1.How do you check to see that there are no slowdowns?
2.Do you mean that you can copy a whole 256 palette during a single HBLANK? |
1. Just something I can see. There are so big differences in speed.
2. It looks like I can copy 512 palettes during one HBLANK, as long as I do it with DMA0 and during a VCOUNT interrupt.
#16398 - poslundc - Sat Feb 14, 2004 10:23 pm
LOst? wrote: |
2. It looks like I can copy 512 palettes during one HBLANK, as long as I do it with DMA0 and during a VCOUNT interrupt. |
Try it on hardware, and I guarantee you'll get tearing (rainbowing) on the scanline you're doing it for if your background uses more than 150 colours or so. You might not care if it's just going to a slightly bluer colourset and the screen is in constant motion (I don't think I would care), but don't kid yourself into thinking you can copy 512 entries (or even 256) in that sort of time frame.
You might also want to consider the potential effect that using DMA0 to copy 512 palette entries (or 1024 bytes) - which halts the CPU and blocks interrupts and other DMAs for 768 cycles - may have on other time-critical systems you might add, such as an audio mixer.
Dan.
#16576 - ScottLininger - Thu Feb 19, 2004 10:30 pm
I'd also test it on hardware before you go too far down the road. I recently has a very similar problem (changing palettes during the HBLANK)
It worked great on VisualBoy Advance. But it froze up on hardware. I had to go back to the drawing board and ended up using alpha transparency for the effect I wanted.
VisualBoy Advance is awesome, but it's definitely not perfect yet.
#16578 - headspin - Thu Feb 19, 2004 10:46 pm
Surely using a bg layer with an alpha transparency would be a better way to go, and much more processor friendly.
I mean a blue coloured tile moved around using the scroll registers would give the exact same effect.
I guess you see a game do it and you want to reproduce the effect. Or perhaps using up a valuable bg layer is the problem..
love the demo though
#16580 - poslundc - Thu Feb 19, 2004 10:49 pm
headspin wrote: |
Or perhaps using up a valuable bg layer is the problem.. |
You can do it without consuming a bg layer. Just set the backdrop colour to blue and either use a window to determine where the effect occurs or turn it on in an HBlank interrupt.
Dan.