Ejemplo n.º 1
0
        public async Task RunAsync(string cartridgeResource)
        {
            var cartridge = GetCartridgeBinary(cartridgeResource);
            var config    = new StaticGameBoyConfig(cartridge, GameBoyType.GameBoy, false);

            var builder = new ContainerBuilder();

            builder.RegisterType <NullRenderer>().As <IRenderer>().SingleInstance();
            builder.RegisterGameBoy(config);

            using (var container = builder.Build())
                using (var scope = container.BeginLifetimeScope())
                    using (var ownedCore = scope.Resolve <Owned <ICpuCore> >())
                    {
                        var core = ownedCore.Value;
                        var io   = core.GetPeripheralOfType <IGameBoyMemoryMappedIo>();

                        var serialPort = new BlarggTestSerialPort(Timeout);
                        io.HardwareRegisters.SerialPort.Connect(serialPort);

                        using (var cancellation = new CancellationTokenSource())
                        {
                            var token       = cancellation.Token;
                            var coreProcess = Task.Run(() => core.StartCoreProcessAsync(token), token);
                            cancellation.CancelAfter(Timeout + TimeSpan.FromMinutes(1));
                            while (!cancellation.IsCancellationRequested)
                            {
                                var word = serialPort.WaitForNextWord();
                                if (word == null)
                                {
                                    throw new Exception("Couldn't get next word");
                                }

                                if (word == "Failed" || word == "Passed")
                                {
                                    await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);

                                    cancellation.Cancel();

                                    word.ShouldBe("Passed");
                                    return;
                                }
                            }
                        }
                    }
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            var builder = new ContainerBuilder();

            builder.Populate(services);

            builder.RegisterType <SingleCoreWebSocketContext>().As <IWebSocketContext>().SingleInstance();
            builder.RegisterType <WebSocketRenderer>().As <IRenderer>().As <IWebSocketRenderer>().InZ80Scope();
            builder.RegisterType <WebSocketMessageSerializer>().As <IWebSocketMessageSerializer>().SingleInstance();

            var cartridge = GetCartridgeBinary();
            var config    = new StaticGameBoyConfig(cartridge, GameBoyType.GameBoy, true);

            builder.RegisterGameBoy(config);
            var container = builder.Build();

            return(new AutofacServiceProvider(container));
        }