[NES] add loader for FCEUX format palettes and an example of how to set it
This commit is contained in:
parent
7f4e4916dd
commit
368c5266e5
|
@ -203,7 +203,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
/// <summary>
|
||||
/// sets the provided palette as current
|
||||
/// </summary>
|
||||
void SetPalette(int[,] pal)
|
||||
public void SetPalette(int[,] pal)
|
||||
{
|
||||
Array.Copy(pal,palette,64*3);
|
||||
for(int i=0;i<64*8;i++)
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
{
|
||||
partial class NES
|
||||
{
|
||||
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 };
|
||||
|
@ -29,6 +29,23 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
if (b > 0xFF) b = 0xFF;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a simple 192 byte (64 entry RGB888) palette which is FCEUX format (and probably other emulators as well)
|
||||
/// </summary>
|
||||
/// <param name="fileContents">192 bytes, the contents of the palette file</param>
|
||||
public static int[,] Load_FCEUX_Palette(byte[] fileContents)
|
||||
{
|
||||
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[,]
|
||||
{
|
||||
|
|
|
@ -43,6 +43,39 @@ namespace BizHawk
|
|||
|
||||
public static class Extensions
|
||||
{
|
||||
public static void CopyTo(this Stream src, Stream dest)
|
||||
{
|
||||
int size = (src.CanSeek) ? Math.Min((int)(src.Length - src.Position), 0x2000) : 0x2000;
|
||||
byte[] buffer = new byte[size];
|
||||
int n;
|
||||
do
|
||||
{
|
||||
n = src.Read(buffer, 0, buffer.Length);
|
||||
dest.Write(buffer, 0, n);
|
||||
} while (n != 0);
|
||||
}
|
||||
|
||||
public static void CopyTo(this MemoryStream src, Stream dest)
|
||||
{
|
||||
dest.Write(src.GetBuffer(), (int)src.Position, (int)(src.Length - src.Position));
|
||||
}
|
||||
|
||||
public static void CopyTo(this Stream src, MemoryStream dest)
|
||||
{
|
||||
if (src.CanSeek)
|
||||
{
|
||||
int pos = (int)dest.Position;
|
||||
int length = (int)(src.Length - src.Position) + pos;
|
||||
dest.SetLength(length);
|
||||
|
||||
while (pos < length)
|
||||
pos += src.Read(dest.GetBuffer(), pos, length - pos);
|
||||
}
|
||||
else
|
||||
src.CopyTo((Stream)dest);
|
||||
}
|
||||
|
||||
|
||||
public static bool IsBinary(this string str)
|
||||
{
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
|
|
|
@ -11,6 +11,29 @@ namespace BizHawk.MultiClient
|
|||
|
||||
public class HawkFile : IDisposable
|
||||
{
|
||||
public static bool ExistsAt(string path)
|
||||
{
|
||||
using (var file = new HawkFile(path))
|
||||
{
|
||||
return file.Exists;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
using (var file = new HawkFile(path))
|
||||
{
|
||||
if (!file.Exists) throw new FileNotFoundException(path);
|
||||
using (Stream stream = file.GetStream())
|
||||
{
|
||||
MemoryStream ms = new MemoryStream((int)stream.Length);
|
||||
stream.CopyTo(ms);
|
||||
return ms.GetBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// returns whether a bound file exists. if there is no bound file, it can't exist
|
||||
/// </summary>
|
||||
|
@ -90,7 +113,8 @@ namespace BizHawk.MultiClient
|
|||
public HawkFile(string path)
|
||||
{
|
||||
string autobind = null;
|
||||
if (IsCanonicalArchivePath(path))
|
||||
bool isArchivePath = IsCanonicalArchivePath(path);
|
||||
if (isArchivePath)
|
||||
{
|
||||
string[] parts = path.Split('|');
|
||||
path = parts[0];
|
||||
|
@ -114,7 +138,13 @@ namespace BizHawk.MultiClient
|
|||
//bind it later with the desired extensions.
|
||||
}
|
||||
|
||||
if (autobind != null)
|
||||
if (autobind == null)
|
||||
{
|
||||
//non-archive files can be automatically bound this way
|
||||
if (!isArchivePath)
|
||||
BindRoot();
|
||||
}
|
||||
else
|
||||
{
|
||||
autobind = autobind.ToUpperInvariant();
|
||||
for (int i = 0; i < extractor.ArchiveFileData.Count; i++)
|
||||
|
@ -189,7 +219,7 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// causes the root to be bound (in the case of non-archive files
|
||||
/// causes the root to be bound (in the case of non-archive files)
|
||||
/// </summary>
|
||||
void BindRoot()
|
||||
{
|
||||
|
|
|
@ -740,7 +740,15 @@ namespace BizHawk.MultiClient
|
|||
LoadTI83KeyPad();
|
||||
break;
|
||||
case "NES":
|
||||
nextEmulator = new NES();
|
||||
{
|
||||
NES nes = new NES();
|
||||
nextEmulator = nes;
|
||||
string palette_file = @"C:\svn\fceux\fceu\output\palettes\FCEU-15-nitsuja_new.pal";
|
||||
if (HawkFile.ExistsAt(palette_file))
|
||||
{
|
||||
nes.SetPalette(NES.Palettes.Load_FCEUX_Palette(HawkFile.ReadAllBytes(palette_file)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "GB":
|
||||
nextEmulator = new Gameboy();
|
||||
|
|
Loading…
Reference in New Issue