diff --git a/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs b/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs index bfc9d097ac..ae0fd61962 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs @@ -89,7 +89,7 @@ namespace BizHawk.Client.EmuHawk pictureBoxPalette.Image = bmp; } - private int[,] ResolvePalette(bool showmsg = false) + private byte[,] ResolvePalette(bool showmsg = false) { if (AutoLoadPalette.Checked) // checkbox checked: try to load palette from file { @@ -111,7 +111,7 @@ namespace BizHawk.Client.EmuHawk else // no filename: interpret this as "reset to default" { if (showmsg) GlobalWin.OSD.AddMessage("Standard Palette set"); - return (int[,])Palettes.QuickNESPalette.Clone(); + return (byte[,])Palettes.QuickNESPalette.Clone(); } } else // checkbox unchecked: we're reusing whatever palette was set diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index db8f390432..7c43878a73 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -33,7 +33,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public bool irq_apu { get { return _irq_apu; } set { _irq_apu = value; } } //user configuration - int[,] palette = new int[64,3]; int[] palette_compiled = new int[64*8]; // new input system @@ -440,20 +439,38 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } /// - /// sets the provided palette as current + /// Sets the provided palette as current. + /// Applies the current deemph settings if needed to expand a 64-entry palette to 512 /// - private void SetPalette(int[,] pal) + private void SetPalette(byte[,] pal) { - Array.Copy(pal,palette,64*3); - for(int i=0;i<64*8;i++) + int nColors = pal.GetLength(0); + int nElems = pal.GetLength(1); + + if (nColors == 512) { - int d = i >> 6; - int c = i & 63; - int r = palette[c, 0]; - int g = palette[c, 1]; - int b = palette[c, 2]; - Palettes.ApplyDeemphasis(ref r, ref g, ref b, d); - palette_compiled[i] = (int)unchecked((int)0xFF000000 | (r << 16) | (g << 8) | b); + //just copy the palette directly + for (int c = 0; c < 64 * 8; c++) + { + int r = pal[c, 0]; + int g = pal[c, 1]; + int b = pal[c, 2]; + palette_compiled[c] = (int)unchecked((int)0xFF000000 | (r << 16) | (g << 8) | b); + } + } + else + { + //expand using deemph + for (int i = 0; i < 64 * 8; i++) + { + int d = i >> 6; + int c = i & 63; + int r = pal[c, 0]; + int g = pal[c, 1]; + int b = pal[c, 2]; + Palettes.ApplyDeemphasis(ref r, ref g, ref b, d); + palette_compiled[i] = (int)unchecked((int)0xFF000000 | (r << 16) | (g << 8) | b); + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs index 9c81ab5b3f..fed992396c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.ISettable.cs @@ -102,7 +102,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public int PAL_TopLine = 0; public int PAL_BottomLine = 239; - public int[,] Palette; + public byte[,] Palette; public int Square1 = 376; public int Square2 = 376; @@ -113,21 +113,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public NESSettings Clone() { var ret = (NESSettings)MemberwiseClone(); - ret.Palette = (int[,])ret.Palette.Clone(); + ret.Palette = (byte[,])ret.Palette.Clone(); return ret; } public NESSettings() { - Palette = (int[,])Palettes.QuickNESPalette.Clone(); + Palette = (byte[,])Palettes.QuickNESPalette.Clone(); } [Newtonsoft.Json.JsonConstructor] - public NESSettings(int[,] Palette) + public NESSettings(byte[,] Palette) { if (Palette == null) // only needed for SVN purposes - this.Palette = (int[,])Palettes.QuickNESPalette.Clone(); + // edit: what does this mean? + this.Palette = (byte[,])Palettes.QuickNESPalette.Clone(); else this.Palette = Palette; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs index fb0b92d6c4..568fda9b05 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs @@ -20,19 +20,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } /// - /// Loads a simple 192 byte (64 entry RGB888) or 1536 byte (64*8 = 512 entry) palette which is FCEUX format (and probably other emulators as well) - /// The 512-entry format is new and backwards compatible. (actually, the 512-entry format extra data isnt used yet, I just edited this to support the larger quicknes file i committed) + /// Loads a simple 192 byte (64 entry RGB888) or 1536 byte (64*8 = 512 entry) palette. FCEUX uses these, as do almost every NES emulator. /// /// 192 or 1536 bytes, the contents of the palette file - public static int[,] Load_FCEUX_Palette(byte[] fileContents) + public static byte[,] Load_FCEUX_Palette(byte[] fileContents) { - //'validate' file, solely by length - if (fileContents.Length == 1536) { } - else if (fileContents.Length != 192) return null; + int nColors; - int[,] ret = new int[64, 3]; + //'validate' file, solely by length + if (fileContents.Length == 1536) + { + nColors = 512; + } + else if (fileContents.Length == 192) + { + nColors = 64; + } + else + { + return null; + } + + byte[,] ret = new byte[nColors, 3]; int i = 0; - for (int c = 0; c < 64; c++) + for (int c = 0; c < nColors; c++) { for (int z = 0; z < 3; z++) ret[c, z] = fileContents[i++]; @@ -41,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } const int SHIFT = 2; - public static int[,] FCEUX_Standard = new int[,] + public static byte[,] FCEUX_Standard = new byte[,] { { 0x1D<