neshawk&quicknes: properly support using 512 byte palette files deemph entries instead of just ignoring them
This commit is contained in:
parent
4fd55da52a
commit
ee0992158d
|
@ -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
|
||||
|
|
|
@ -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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -20,19 +20,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="fileContents">192 or 1536 bytes, the contents of the palette file</param>
|
||||
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<<SHIFT, 0x1D<<SHIFT, 0x1D<<SHIFT }, /* Value 0 */
|
||||
{ 0x09<<SHIFT, 0x06<<SHIFT, 0x23<<SHIFT }, /* Value 1 */
|
||||
|
@ -109,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
{ 0x00<<SHIFT, 0x00<<SHIFT, 0x00<<SHIFT }, /* Value 63 */
|
||||
};
|
||||
|
||||
public static int[,] QuickNESPalette =
|
||||
public static byte[,] QuickNESPalette =
|
||||
{
|
||||
{102, 102, 102},
|
||||
{0, 42, 136},
|
||||
|
|
|
@ -104,22 +104,39 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
|
|||
SetDefaultColors();
|
||||
}
|
||||
|
||||
public void SetNesHawkPalette(int[,] pal)
|
||||
public void SetNesHawkPalette(byte[,] pal)
|
||||
{
|
||||
if (pal.GetLength(0) != 64 || pal.GetLength(1) != 3)
|
||||
//TODO - support 512 color palettes
|
||||
int nColors = pal.GetLength(0);
|
||||
int nElems = pal.GetLength(1);
|
||||
if (!(nColors == 64 || nColors == 512) || nElems != 3)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
for (int c = 0; c < 512; c++)
|
||||
if (nColors == 512)
|
||||
{
|
||||
int a = c & 63;
|
||||
byte[] inp = { (byte)pal[a, 0], (byte)pal[a, 1], (byte)pal[a, 2] };
|
||||
byte[] outp = new byte[3];
|
||||
Nes_NTSC_Colors.Emphasis(inp, outp, c);
|
||||
_Palette[c * 3] = outp[0];
|
||||
_Palette[c * 3 + 1] = outp[1];
|
||||
_Palette[c * 3 + 2] = outp[2];
|
||||
//just copy the palette directly
|
||||
for (int c = 0; c < nColors; c++)
|
||||
{
|
||||
_Palette[c * 3 + 0] = pal[c, 0];
|
||||
_Palette[c * 3 + 1] = pal[c, 1];
|
||||
_Palette[c * 3 + 2] = pal[c, 2];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//use quickNES's deemph calculator
|
||||
for (int c = 0; c < 64; c++)
|
||||
{
|
||||
int a = c & 63;
|
||||
byte[] inp = { (byte)pal[a, 0], (byte)pal[a, 1], (byte)pal[a, 2] };
|
||||
byte[] outp = new byte[3];
|
||||
Nes_NTSC_Colors.Emphasis(inp, outp, c);
|
||||
_Palette[c * 3] = outp[0];
|
||||
_Palette[c * 3 + 1] = outp[1];
|
||||
_Palette[c * 3 + 2] = outp[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue