public Emulator() { _cartridge = new Cartridge(); _gpu = new GPU(); _timer = new Timer(); _divideRegister = new DivideRegister(); _joypad = new Joypad(); _apu = new APU(); _mmu = new MMU(_cartridge, _gpu, _timer, _divideRegister, _joypad, _apu); _cpu = new CPU(_mmu); _cpu.OnClockTick += UpdateSystems; }
public MMU(Cartridge cart, GPU gpu, Timer timer, DivideRegister divideRegister, Joypad joypad, APU apu) { var memoryUnits = new List <IMemoryUnit> { cart, gpu, _workRAM, joypad, divideRegister, timer, apu, new DMAController() }; MessageBus.Instance.OnReadByte = ReadByte; MessageBus.Instance.OnWriteByte = WriteByte; for (var address = 0; address < MemorySchema.MAX_RAM_SIZE; address++) { foreach (var memoryUnit in memoryUnits) { if (memoryUnit.CanReadWriteByte(address)) { _memoryUnitLookup[address] = memoryUnit; break; } } if (!_memoryUnitLookup.ContainsKey(address)) { _memoryUnitLookup[address] = _mainMemory; } } }