Re: [Tuxnes-devel] Trying to add SDL Renderer
Brought to you by:
tmmm
From: Jim U. <ji...@3e...> - 2002-03-10 16:19:35
|
At 07:41am on 2002 March 10, W. Michael Petullo did write: > > I'm trying to add an SDL renderer to tuxnes. Eventually this will give > > us full-screen support and additional platforms for free. > > [...] > > I have the basic renderer working, though I don't really understand > tuxnes's color code (UpdateColor.* functions). As I understand it, > the NES is only able to display 24 colors at once. Because of this, > the emulator's palette must be updated to the appropriate colors for each > frame and these colors have to be mapped to a display's 8-, 16-, 24-, > or 32-bit colorspace. The palette stuff is confusing. The first time it took me a while to figure it out. The second time (when I went back and converted it to use hardware palette entries) again took me a while, so I took notes that time: ---- Palette conversion: paletteDC[] holds the 64 16-bit DC versions of the 64 total NES colors. palette[] holds 25 16-bit RGB565 values, all of which are cornfusing. The 2 NES palettes have 16 entries each, broken down into 4 groups of 4. Color 0 is transparent (letting the background (or background color) shine through). Color 0 is mirrored to 4, 8, 12. Also, color 0 is mirrored between the two palettes. In this array: 0..11 are the current tile colors. 0,1,2 correspond to colors 1, 2, and 3. 3,4,5 and 6,7,8 are 5, 6, 7 and 9, 10, 11. 9,10,11 are 13, 14, and 15. 12..23 are the current sprite colors. 24 is the current background color, set in UpdateColors. Methinks this was a (misguided?) attempt to save space. tilecolor is the 2-bit value from the attribute table. curpal[] holds 4 16-bit RGB565 values corresponding to the 4 possible colors for the current tile. The index into curpal is the 2-bit value from the name table. curpal[0] is always set to the value in palette[24] upon entering drawimage. curpal[1,2,3] are set to palette[0,1,2], [3,4,5], [6,7,8], or [9,10,11] depending on the value of tilecolor (2 bits provides 4 selections). ------------------------ The following code does not use hardware palette entries (i.e. not PseudoColor). The code in InitDisplay that converts the 32-bit NES_palette values into 16-bit RGB565 native values is: for (x=0; x < 64; x++) { /* RGB565 */ uint8 r,g,b; r = (NES_palette[x] >> 16 >> 3) & 0x1f; g = (NES_palette[x] >> 8 >> 2) & 0x3f; b = (NES_palette[x] >> 3) & 0x1f; paletteDC[x] = (r << 11) | (g << 5) | (b); } The update colors function is very simple (except for the unnecessarily complicated palette array organization): void UpdateColorsDC(void) { int x; palette[24] = paletteDC[VRAM[0x3f00] & 63]; for (x = 0; x < 24; x++) { palette[x] = paletteDC[VRAM[0x3f01 + x + (x / 3)] & 63]; } This should get you started. I have hardware palette code too if you need it. -- "closing my eyes, i got a glimpse of several entities moving in front of a giant complex control panel. the creatures were bipedal and of about human size. it was impossible to say more other than they did not move like the giant insect creatures i have seen clearly under the influence of stropharia mushrooms." -- zarkov, "a hit of dmt 10/9/84" ji...@3e... / 0x43340710 / 517B C658 D2CB 260D 3E1F 5ED1 6DB3 FBB9 4334 0710 |