using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using AxibugEmuOnline.Client.UNES.Controller; using AxibugEmuOnline.Client.UNES.Mapper; namespace AxibugEmuOnline.Client.UNES { public class Emulator { private static readonly Dictionary> Mappers = (from type in Assembly.GetExecutingAssembly().GetTypes() let def = (MapperDef)type.GetCustomAttributes(typeof(MapperDef), true).FirstOrDefault() where def != null select new { def, type }).ToDictionary(a => a.def.Id, a => new KeyValuePair(a.type, a.def)); public IController Controller; public readonly CPU CPU; public readonly PPU PPU; public readonly BaseMapper Mapper; public readonly Cartridge Cartridge; public Emulator(byte[] bytes, IController controller) { Cartridge = new Cartridge(bytes); if (!Mappers.ContainsKey(Cartridge.MapperNumber)) { throw new NotImplementedException($"unsupported mapper {Cartridge.MapperNumber}"); } Mapper = (BaseMapper)Activator.CreateInstance(Mappers[Cartridge.MapperNumber].Key, this); CPU = new CPU(this); PPU = new PPU(this); Controller = controller; // Load(); } } }