Example #1
0
        public GameBoy(string romPath)
        {
            _logger = new Logger();

            _mainMemory    = new MainMemory();
            _dmaController = new DmaController(_mainMemory);

            _timer  = new Timer(_mainMemory);
            _joypad = new Joypad();

            _serialController = new SerialController(_mainMemory);

            _pixelProcessingUnit = new PixelProcessingUnit(_mainMemory, _logger);
            _audioProcessingUnit = new AudioProcessingUnit();

            IRandomAccessMemory mainMemoryProxy = new MainMemoryDmaProxy(_mainMemory, _dmaController);

            _cpuCore = new CpuCore(mainMemoryProxy, new CpuState(), _logger);

            IRomLoader romLoader = new FileRomLoader(romPath);

            _ramManager = new FileRamManager(Path.ChangeExtension(romPath, ".sav"));

            _memoryBankController = MBCFactory.CreateMBC(romLoader);
            _memoryBankController.LoadRam(_ramManager);

            _mainMemory.RegisterMemoryAccessDelegate(_memoryBankController as IMemoryAccessDelegate);
            _mainMemory.RegisterMemoryAccessDelegate(_pixelProcessingUnit);
            _mainMemory.RegisterMemoryAccessDelegate(_timer);
            _mainMemory.RegisterMemoryAccessDelegate(_joypad);
            _mainMemory.RegisterMemoryAccessDelegate(_audioProcessingUnit);
            _mainMemory.RegisterMemoryAccessDelegate(_serialController);
        }