From ae61bf39266653a0f4dc7096662ed5677b63eac4 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 13 Mar 2011 02:48:45 +0000 Subject: [PATCH] [NES] setup a little palette performance optimization for debug tools --- .../Consoles/Nintendo/NES/Core.cs | 32 +++++++++++++++++-- .../Consoles/Nintendo/NES/NES.cs | 4 +-- BizHawk.MultiClient/NEStools/NESPPU.cs | 6 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index a6b9586942..ce63714596 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -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) + /// + /// sets the provided palette as current + /// + 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); + } + } + + + /// + /// Converts an internal NES core pixel value (includes deemph bits) to an rgb int. + /// + 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; } + /// + /// looks up an internal NES pixel value to an rgb int. + /// + public int LookupColor(int pixel) + { + return palette_compiled[pixel]; + } + public byte ReadMemory(ushort addr) { if (addr < 0x0800) return ram[addr]; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index e468c88aaa..77a06d6efc 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -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; diff --git a/BizHawk.MultiClient/NEStools/NESPPU.cs b/BizHawk.MultiClient/NEStools/NESPPU.cs index 0f95183ae7..fd92cfa03e 100644 --- a/BizHawk.MultiClient/NEStools/NESPPU.cs +++ b/BizHawk.MultiClient/NEStools/NESPPU.cs @@ -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;