Palette question on 320x200x8

Started by
8 comments, last by Ferneu 20 years, 5 months ago
Nothing like some good ol'' fashioned VGA game programming huh? Now that I''ve already learned some basics, like writting to the VGA memory, loading BMPs... It was time to face the almighty palette! Setting the PAL to match the BMP''s one was kind of easy. Changing the RGB values of any color I want is not that hard eighter. But... You should know that my good old NES is still working and making a little kid happy (me by the way). Well, I believe you all should have played Mario at least once. The game had several enemies, among them all there were the green and red turtle. I don''t know if I''m right, but I think the NINTENDO GODs had just one single turtle sprite, and what they did was just some little palette party out there, changing the shell color to red or green whenever they had to. What I''m trying to do here is: load a BMP, a yellow square for instance. Changing it''s color to red or any other color I want is not a big deal. But how can I load it twice or more times on the screen and change just the color of one of them without affecting the others? Getting back to the Mario example, sometimes you could have both the red and green turtles at the sime time on the screen. How can I do it, besides creating two or more BMPs, one for each color I want?
Advertisement
Yeah, oldschool rooles!

The only way I can think of is to not only keep track of the vertical retrace, but also the horizontal retrace, and change the palette when the trace passes the frist sprite, making the colors for the sprite underneath it appear with another palette (I don''t remember the opcodes or asm code for it so don''t ask :-)

This is the same way as copperbars work btw, just chaning color 0.

However, I realize this is kinda hard to do in a game because two sprites of the same kind can appear on the same row as the other, so I guess NES never has the two same types on the same screen, am I right?

In that case, either they have some hardware hack or they have two seperate sprites, I don''t know anything how the sprite layout for mario is since I haven''t worked on nes at all, but run nesticle and pop up the sprite display, I''m sure you''ll get some answers there.

Good luck!
Albert "thec" Sandberg
-------------------------------------------http://www.thec.org
I think the only way to do it is to have two sprites. Of course you could have only one sprite on disk and when you load it, make a copy and shift your palette indices up to match the ''red turtle'' palette indices in your global palette.

No other way to do it if you are working in an 8 bit paletted display mode. You are really only talking about an 8x8 or 16x16 sprite with 1 byte per pixel so the cost is negligable.
Well thx both of you for the help.
The asm for the vert retrace I know.
I was using it to stop the flickering.

I''ll just search for some info on the horizontal retrace
and try it.

I haven''t played mario again since I''ve made the post,
but I''ll try again and check if I was wrong about the two
turtles appearing at once on the screen

Thx again
You''re using your own drawing routines? You could always have a lookup table to filter colors, if you plan to do this a lot. I would recommend having two sprites! The last game I was working on was using 122MB for bitmap memory, so I may be out of practice with the old school style
Jiia:
Yes, I''m using my own routines.

thec:
I think you were right when you said the NES could never had them both loaded at the same time. I''ve played some more but they never seemed to appear toghether on the screen. But I''m still willing to try what you''v told me about trace and check if it''ll work and if it''s not going to slow the game down too much.

THX for all the info
I''m not sure about the NES, but in the old times sprites could have sort of their "own" palette. Thus making it possible to use the same sprite and exchange their palette. Every sprite displayed had an index for their palette enabling you to have a red and a green turtle the same time but only needing one turtle sprite.

Now this is not possible without some hardware sprites which enable this feature. You probably can''t escape having a second sprite.

You could of course also use, like already mentioned, lookup tables; using them to emulate sprite palettes. Meaning, draw sprite A with palette 1 and sprite A again with palette 3. This also means to rework the drawing routines to use a lookup for every pixel drawn.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

NES sprites have their own palettes, as Endurion guessed. Take a look at the NES-era Final Fantasies, and you''ll notice how the characters are drawn using a minimalistic amount of colors, even though there are many more colors on the screen at once. I haven''t read any Super Mario asm code, but I bet they just chose the sprite palette to make coloured koopas.

I think they did this even on the SNES. If you look at the sprite tables of SNES games, you notice that the colours do not often match those on screen. Many of the enemies in Super Mario World were a weird beige shade in the sprite memory, and the palettes were stuck on at drawing time. I think SNES has 16 color-palettes for sprites, and NES has 4, but that is just a hunch.
That''s right. The NES had a maximum of 64 colors and the sprites had their own 2-bit (4 color) palettes. On the SNES system, the sprites palettes ranged from 1-bit to 8-bit.

I''ve absolutely no idea how to do this in asm, but in Windows GDI, I''d just switch palettes of the same turtle sprite before drawing.
Thx for all the info.
I still haven''t got enough time to test
using a look up table. Whenever I have some
free time on my hands I''ll try it.

Thanks

This topic is closed to new replies.

Advertisement