add core scanning system

This commit is contained in:
zeromus 2011-07-31 19:46:42 +00:00
parent 64e38e83c8
commit f356d5b354
3 changed files with 295 additions and 248 deletions

View File

@ -8,6 +8,7 @@ using BizHawk.Emulation.CPUs.M6502;
namespace BizHawk.Emulation.Consoles.Nintendo
{
[CoreVersion("0.0.0.1",FriendlyName="NESHawk")]
public partial class NES : IEmulator
{
//hardware/state

View File

@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
@ -8,7 +9,7 @@ using System.Text;
namespace BizHawk
{
public struct Tuple<T1,T2> : IEquatable<Tuple<T1, T2>>
public struct Tuple<T1, T2> : IEquatable<Tuple<T1, T2>>
{
private readonly T1 first;
private readonly T2 second;
@ -41,6 +42,45 @@ namespace BizHawk
}
}
[AttributeUsage(AttributeTargets.Class)]
public class CoreVersion : Attribute
{
public CoreVersion(string version)
{
this.Version = version;
}
public string Version { get; set; }
public string FriendlyName { get; set; }
}
public static class Introspection
{
public class CoreInfo
{
public string ClassName, Version, FriendlyName;
}
public static List<CoreInfo> GetCoreInfo()
{
var ret = new List<CoreInfo>();
//scan types in this assembly to find ones that implement boards to add them to the list
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
var attrs = type.GetCustomAttributes(typeof(CoreVersion), true);
if (attrs.Length == 0) continue;
var cv = (CoreVersion)attrs[0];
var ci = new CoreInfo();
ci.ClassName = type.Name;
ci.FriendlyName = cv.FriendlyName;
if (string.IsNullOrEmpty(ci.FriendlyName)) ci.FriendlyName = ci.ClassName;
ci.Version = cv.Version;
ret.Add(ci);
}
return ret;
}
}
public static class Extensions
{
public static void CopyTo(this Stream src, Stream dest)
@ -122,7 +162,7 @@ namespace BizHawk
{
foreach (string opt in options)
{
if (opt.Equals(str,StringComparison.CurrentCultureIgnoreCase)) return true;
if (opt.Equals(str, StringComparison.CurrentCultureIgnoreCase)) return true;
}
return false;
}
@ -221,7 +261,7 @@ namespace BizHawk
public static void SaveAsHex(this byte[] buffer, TextWriter writer)
{
for (int i=0; i<buffer.Length; i++)
for (int i = 0; i < buffer.Length; i++)
{
writer.Write("{0:X2}", buffer[i]);
}
@ -318,9 +358,9 @@ namespace BizHawk
{
if (hex.Length % 2 != 0)
throw new Exception("Hex value string does not appear to be properly formatted.");
for (int i=0; i<buffer.Length && i*2<hex.Length; i++)
for (int i = 0; i < buffer.Length && i * 2 < hex.Length; i++)
{
string bytehex = "" + hex[i*2] + hex[i*2 + 1];
string bytehex = "" + hex[i * 2] + hex[i * 2 + 1];
buffer[i] = byte.Parse(bytehex, NumberStyles.HexNumber);
}
}
@ -342,7 +382,7 @@ namespace BizHawk
throw new Exception("Hex value string does not appear to be properly formatted.");
for (int i = 0; i < buffer.Length && i * 4 < hex.Length; i++)
{
string ushorthex = "" + hex[i*4] + hex[(i*4)+1] + hex[(i*4)+2] + hex[(i*4)+3];
string ushorthex = "" + hex[i * 4] + hex[(i * 4) + 1] + hex[(i * 4) + 2] + hex[(i * 4) + 3];
buffer[i] = ushort.Parse(ushorthex, NumberStyles.HexNumber);
}
}
@ -368,12 +408,12 @@ namespace BizHawk
{
public static int ARGB(byte red, byte green, byte blue)
{
return (int) ((uint)((red << 0x10) | (green << 8) | blue | (0xFF << 0x18)));
return (int)((uint)((red << 0x10) | (green << 8) | blue | (0xFF << 0x18)));
}
public static int ARGB(byte red, byte green, byte blue, byte alpha)
{
return (int) ((uint)((red << 0x10) | (green << 8) | blue | (alpha << 0x18)));
return (int)((uint)((red << 0x10) | (green << 8) | blue | (alpha << 0x18)));
}
public static int Luminosity(byte lum)
@ -462,7 +502,7 @@ namespace BizHawk
{
MemoryStream ms = new MemoryStream();
if (str.Length % 2 != 0) throw new ArgumentException();
int len = str.Length/2;
int len = str.Length / 2;
for (int i = 0; i < len; i++)
{
int d = 0;
@ -494,11 +534,11 @@ namespace BizHawk
public static short[] ByteBufferToShortBuffer(byte[] buf)
{
int num = buf.Length/2;
int num = buf.Length / 2;
short[] ret = new short[num];
for (int i = 0; i < num; i++)
{
ret[i] =(short)(buf[i * 2] | (buf[i * 2 + 1] << 8));
ret[i] = (short)(buf[i * 2] | (buf[i * 2 + 1] << 8));
}
return ret;
}
@ -510,7 +550,7 @@ namespace BizHawk
for (int i = 0; i < num; i++)
{
ret[i * 2 + 0] = (byte)(buf[i] & 0xFF);
ret[i * 2 + 1] = (byte)((buf[i]>>8) & 0xFF);
ret[i * 2 + 1] = (byte)((buf[i] >> 8) & 0xFF);
}
return ret;
}
@ -583,14 +623,14 @@ namespace BizHawk
Decimal OneGigaByte = OneMegaByte * 1024M;
string suffix;
if (size > 1024*1024*1024)
if (size > 1024 * 1024 * 1024)
{
size /= 1024*1024*1024;
size /= 1024 * 1024 * 1024;
suffix = "GB";
}
else if (size > 1024*1024)
else if (size > 1024 * 1024)
{
size /= 1024*1024;
size /= 1024 * 1024;
suffix = "MB";
}
else if (size > 1024)
@ -643,7 +683,7 @@ namespace BizHawk
{
sections.Push(name);
if (IsText)
if (IsWriter) { tw.WriteLine("[{0}]", name);}
if (IsWriter) { tw.WriteLine("[{0}]", name); }
else { tr.ReadLine(); }
}
@ -659,7 +699,7 @@ namespace BizHawk
{
if (typeof(T).BaseType != typeof(System.Enum))
throw new InvalidOperationException();
if(isText) SyncEnumText<T>(name, ref val);
if (isText) SyncEnumText<T>(name, ref val);
else if (IsReader) val = (T)Enum.ToObject(typeof(T), br.ReadInt32());
else bw.Write(Convert.ToInt32(val));
}
@ -907,7 +947,7 @@ namespace BizHawk
void Read(ref int val) { val = br.ReadInt32(); }
void Write(ref int val) { bw.Write(val); }
void ReadText(string name, ref int val) { val = int.Parse(tr.ReadLine().Split(' ')[1].Replace("0x",""), NumberStyles.HexNumber); }
void ReadText(string name, ref int val) { val = int.Parse(tr.ReadLine().Split(' ')[1].Replace("0x", ""), NumberStyles.HexNumber); }
void WriteText(string name, ref int val) { tw.WriteLine("{0} 0x{1:X8}", name, val); }
void Read(ref bool val) { val = br.ReadBoolean(); }

View File

@ -87,6 +87,12 @@ namespace BizHawk.MultiClient
Global.CoreInputComm = new CoreInputComm();
SyncCoreInputComm();
Console.WriteLine("Scanning cores:");
foreach (var ci in Introspection.GetCoreInfo())
{
Console.WriteLine("{0} - {1} ({2})", ci.FriendlyName, ci.Version, ci.ClassName);
}
Database.LoadDatabase(PathManager.GetExeDirectoryAbsolute() + "\\gamedb.txt");
SyncPresentationMode();