private static IContainer ConfigureApplication(MainForm mainForm) { var builder = new ContainerBuilder(); builder.RegisterType<InputSource>().As<IInputSource>().SingleInstance(); builder.RegisterInstance(mainForm).As<IPresenter>(); builder.RegisterType<Cpu>().As<ICpu>().SingleInstance(); builder.RegisterType<Emulator>().As<IEmulator>().SingleInstance(); builder.RegisterType<Memory>().As<IMemory>().SingleInstance(); builder.RegisterType<Ppu>().As<IPpu>().SingleInstance(); builder.RegisterType<StolenPpu>(); //var cartridge = new Cartridge("../../../LeetNES/roms/nestest.nes"); var cartridge = new Cartridge("../../../LeetNES/roms/Bomberman (U).nes"); builder.RegisterInstance(cartridge).As<ICartridge>(); var instructionTypes = typeof(IInstruction).Assembly.GetTypes().Where(f => typeof(IInstruction).IsAssignableFrom(f) && !f.IsAbstract).ToArray(); builder.RegisterTypes(instructionTypes).As<IInstruction>(); return builder.Build(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var mainForm = new MainForm(); using (var container = ConfigureApplication(mainForm)) { Task.Factory.StartNew(() => { // ReSharper disable AccessToDisposedClosure var emulator = container.Resolve<IEmulator>(); var memory = container.Resolve<IMemory>(); // ReSharper restore AccessToDisposedClosure memory.SetCartridge(container.Resolve<ICartridge>()); emulator.Reset(); for (;;) { emulator.Step(); } }, TaskCreationOptions.LongRunning); Application.Run(mainForm); } }