diff --git a/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs b/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs index c0b2e43005..bfc9d097ac 100644 --- a/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/NESGraphicsConfig.cs @@ -99,7 +99,7 @@ namespace BizHawk.Client.EmuHawk if (palette != null && palette.Exists) { - var data = NES.Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette.Name)); + var data = Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette.Name)); if (showmsg) GlobalWin.OSD.AddMessage("Palette file loaded: " + palette.Name); return data; } @@ -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[,])NES.Palettes.QuickNESPalette.Clone(); + return (int[,])Palettes.QuickNESPalette.Clone(); } } else // checkbox unchecked: we're reusing whatever palette was set diff --git a/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs b/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs index 5d0dd438c0..e1e5d94758 100644 --- a/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs +++ b/BizHawk.Client.EmuHawk/config/NES/QuickNesConfig.cs @@ -88,7 +88,7 @@ namespace BizHawk.Client.EmuHawk if (palette != null && palette.Exists) { - var data = Emulation.Cores.Nintendo.NES.NES.Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette.Name)); + var data = Emulation.Cores.Nintendo.NES.Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette.Name)); Settings.SetNesHawkPalette(data); SetPaletteImage(); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs index 3c4be1e729..fb0b92d6c4 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs @@ -1,185 +1,180 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { - partial class NES + public static class Palettes { - public static class Palettes + static float[] rtmul = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f }; + static float[] gtmul = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f }; + static float[] btmul = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f }; + + public static void ApplyDeemphasis(ref int r, ref int g, ref int b, int deemph_bits) { - static float[] rtmul = { 1.239f, 0.794f, 1.019f, 0.905f, 1.023f, 0.741f, 0.75f }; - static float[] gtmul = { 0.915f, 1.086f, 0.98f, 1.026f, 0.908f, 0.987f, 0.75f }; - static float[] btmul = { 0.743f, 0.882f, 0.653f, 1.277f, 0.979f, 0.101f, 0.75f }; + //DEEMPH BITS MAY BE ORDERED WRONG. PLEASE CHECK + if (deemph_bits == 0) return; + int d = deemph_bits - 1; + r = (int)(r * rtmul[d]); + g = (int)(g * gtmul[d]); + b = (int)(b * btmul[d]); + if (r > 0xFF) r = 0xFF; + if (g > 0xFF) g = 0xFF; + if (b > 0xFF) b = 0xFF; + } - public static void ApplyDeemphasis(ref int r, ref int g, ref int b, int deemph_bits) + /// + /// 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) + /// + /// 192 or 1536 bytes, the contents of the palette file + public static int[,] Load_FCEUX_Palette(byte[] fileContents) + { + //'validate' file, solely by length + if (fileContents.Length == 1536) { } + else if (fileContents.Length != 192) return null; + + int[,] ret = new int[64, 3]; + int i = 0; + for (int c = 0; c < 64; c++) { - //DEEMPH BITS MAY BE ORDERED WRONG. PLEASE CHECK - if (deemph_bits == 0) return; - int d = deemph_bits - 1; - r = (int)(r * rtmul[d]); - g = (int)(g * gtmul[d]); - b = (int)(b * btmul[d]); - if (r > 0xFF) r = 0xFF; - if (g > 0xFF) g = 0xFF; - if (b > 0xFF) b = 0xFF; + for (int z = 0; z < 3; z++) + ret[c, z] = fileContents[i++]; } + return ret; + } - /// - /// 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) - /// - /// 192 or 1536 bytes, the contents of the palette file - public static int[,] Load_FCEUX_Palette(byte[] fileContents) - { - //'validate' file, solely by length - if (fileContents.Length == 1536) { } - else if (fileContents.Length != 192) return null; - - int[,] ret = new int[64, 3]; - int i = 0; - for (int c = 0; c < 64; c++) - { - for (int z = 0; z < 3; z++) - ret[c, z] = fileContents[i++]; - } - return ret; - } - - const int SHIFT = 2; - public static int[,] FCEUX_Standard = new int[,] - { - { 0x1D<> 4); int wramnon = iNES2Wram(data[10] & 15); @@ -103,6 +103,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES return true; } - } } \ No newline at end of file