/// <summary> /// Reads one byte from the specified bank, at the specified offset /// </summary> /// <param name="memoryType"></param> /// <param name="offset"></param> /// <returns></returns> public byte ReadByte(enumMemoryType memoryType, int offset) { switch (memoryType) { case enumMemoryType.CPU: return(_prgRom[CpuOffsetToPrgRomOffset(offset)]); case enumMemoryType.PPU: return(!ReadInterceptors.TryGetValue(offset, out currentReadInterceptor) ? _chrRom[offset] : currentReadInterceptor(offset)); default: throw new ArgumentOutOfRangeException(nameof(memoryType), memoryType, null); } }
/// <summary> /// Writes one byte to the specified bank, at the specified offset /// </summary> /// <param name="memoryType"></param> /// <param name="offset"></param> /// <param name="data"></param> public void WriteByte(enumMemoryType memoryType, int offset, byte data) { switch (memoryType) { case enumMemoryType.CPU: _prgRom[CpuOffsetToPrgRomOffset(offset)] = data; return; case enumMemoryType.PPU: if (!WriteInterceptors.TryGetValue(offset, out currentWriteInterceptor)) { _chrRom[offset] = data; } else { currentWriteInterceptor(offset, data); } return; default: throw new ArgumentOutOfRangeException(nameof(memoryType), memoryType, null); } }