[NES] setup a little palette performance optimization for debug tools

This commit is contained in:
zeromus 2011-03-13 02:48:45 +00:00
parent ac3acfd721
commit ae61bf3926
3 changed files with 35 additions and 7 deletions

View File

@ -22,7 +22,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
INESBoard board; //the board hardware that is currently driving things
//user configuration
int[,] palette; //TBD!!
int[,] palette = new int[64,3];
int[] palette_compiled = new int[64];
IPortDevice[] ports;
public void HardReset()
@ -155,7 +156,26 @@ namespace BizHawk.Emulation.Consoles.Nintendo
cpu.PendingCycles -= 512;
}
public int ConvertColor(int pixel)
/// <summary>
/// sets the provided palette as current
/// </summary>
void SetPalette(int[,] pal)
{
Array.Copy(pal,palette,64*3);
for(int i=0;i<64;i++)
{
int r = palette[i, 0];
int g = palette[i, 1];
int b = palette[i, 2];
palette_compiled[i] = (int)unchecked((int)0xFF000000 | (r << 16) | (g << 8) | b);
}
}
/// <summary>
/// Converts an internal NES core pixel value (includes deemph bits) to an rgb int.
/// </summary>
int CompleteDecodeColor(int pixel)
{
int deemph = pixel >> 8;
int palentry = pixel & 0xFF;
@ -166,6 +186,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
return (r << 16) | (g << 8) | b;
}
/// <summary>
/// looks up an internal NES pixel value to an rgb int.
/// </summary>
public int LookupColor(int pixel)
{
return palette_compiled[pixel];
}
public byte ReadMemory(ushort addr)
{
if (addr < 0x0800) return ram[addr];

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public NES()
{
BootGodDB.Initialize();
palette = Palettes.FCEUX_Standard;
SetPalette(Palettes.FCEUX_Standard);
}
public enum EMirrorType
@ -56,7 +56,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
for (int x = 0; x < 256; x++)
{
int pixel = emu.ppu.xbuf[i];
pixels[i] = emu.ConvertColor(pixel);
pixels[i] = emu.CompleteDecodeColor(pixel);
i++;
}
return pixels;

View File

@ -69,7 +69,7 @@ namespace BizHawk.MultiClient
//Pattern Viewer
for (int x = 0; x < 16; x++)
{
PaletteView.bgPalettes[x].SetValue(Nes.ConvertColor(Nes.ppu.PALRAM[PaletteView.bgPalettes[x].address]));
PaletteView.bgPalettes[x].SetValue(Nes.LookupColor(Nes.ppu.PALRAM[PaletteView.bgPalettes[x].address]));
PaletteView.spritePalettes[x].SetValue(Nes.ppu.PALRAM[PaletteView.spritePalettes[x].address]);
}
PaletteView.Refresh();
@ -99,8 +99,8 @@ namespace BizHawk.MultiClient
byte value = (byte)(b0 + (b1 << 1));
byte value2 = (byte)(b2 + (b3 << 1));
int cvalue = Nes.ConvertColor(Nes.ppu.PALRAM[value + (PatternView.Pal0 * 4)]);
int cvalue2 = Nes.ConvertColor(Nes.ppu.PALRAM[value2 + (PatternView.Pal1 * 4)]);
int cvalue = Nes.LookupColor(Nes.ppu.PALRAM[value + (PatternView.Pal0 * 4)]);
int cvalue2 = Nes.LookupColor(Nes.ppu.PALRAM[value2 + (PatternView.Pal1 * 4)]);
unchecked
{
cvalue = cvalue | (int)0xFF000000;