Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gpu"/> class.
        /// </summary>
        /// <param name="gameBoyConfig">The game boy configuration.</param>
        /// <param name="interruptFlagsRegister">The interrupt flags register.</param>
        /// <param name="gpuRegisters">The gpu registers.</param>
        /// <param name="renderer">The renderer.</param>
        /// <param name="timer">The timer.</param>
        public Gpu(IGameBoyConfig gameBoyConfig,
                   IInterruptFlagsRegister interruptFlagsRegister,
                   IGpuRegisters gpuRegisters,
                   IRenderer renderer,
                   IInstructionTimer timer)
        {
            _interruptFlagsRegister = interruptFlagsRegister;
            _gpuRegisters           = gpuRegisters;
            _renderer = renderer;

            _spriteRam = new ArrayBackedMemoryBank(SpriteRamConfig);
            _tileRam   = new ArrayBackedMemoryBank(MapRamConfig);

            _gpuRegisters.GpuMode = GpuMode.VerticalBlank;
            _currentTimings       = 0;

            _gpuRegisters.GpuMode = GpuMode.VerticalBlank;
            _currentTimings       = 0;
            _gpuRegisters.CurrentScanlineRegister.Scanline = 0x92;

            if (gameBoyConfig.RunGpu)
            {
                timer.TimingSync += Sync;
            }

            _lcdBuffer = new Frame(LcdWidth, LcdHeight);
            _paintingTaskCompletionSource = new TaskCompletionSource <bool>();
            _disposed = false;

            Task.Factory.StartNew(() => PaintLoop().Wait(), TaskCreationOptions.LongRunning);

            var timerFrequency = TimeSpan.FromSeconds(1);

            _metricsTimer = new Timer(UpdateMetricsCallback, null, timerFrequency, timerFrequency);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameBoyHardwareModule"/> class.
 /// </summary>
 /// <param name="gameBoyConfig">The game boy configuration.</param>
 public GameBoyHardwareModule(IGameBoyConfig gameBoyConfig)
 {
     _gameBoyConfig = gameBoyConfig;
     PlatformConfig = new GameBoyPlatformConfig(gameBoyConfig, new CartridgeFactory());
 }
Example #3
0
        /// <summary>
        /// Registers the dependencies required to bootstrap a GameBoy.
        /// You will also ned to register a <see cref="IRenderer"/>.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="gameBoyConfig">The game boy configuration.</param>
        /// <returns></returns>
        public static ContainerBuilder RegisterGameBoy(this ContainerBuilder builder, IGameBoyConfig gameBoyConfig)
        {
            var module = new GameBoyHardwareModule(gameBoyConfig);

            builder.RegisterModule(module);
            var z80Module = new Z80Module(GameBoyHardwareModule.RuntimeConfig, module.PlatformConfig);

            builder.RegisterModule(z80Module);
            return(builder);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameBoyPlatformConfig"/> class.
 /// </summary>
 /// <param name="gameBoyConfig">The game boy configuration.</param>
 /// <param name="cartridgeFactory">The cartridge factory.</param>
 public GameBoyPlatformConfig(IGameBoyConfig gameBoyConfig, ICartridgeFactory cartridgeFactory)
 {
     _gameBoyConfig    = gameBoyConfig;
     _cartridgeFactory = cartridgeFactory;
 }