private void SetPixel(IDisplay display, Cpu cpu, byte xStart, byte xOffset, byte y, byte sprite, byte mask) { var x = (byte)((xStart + xOffset) % 64); var isPixelSetOnScreen = display.GetPixel(x, y); var isSettingOfPixelRequested = ((sprite & mask) > 0); // XOR operation if (isPixelSetOnScreen && isSettingOfPixelRequested) { display.ClearPixel(x, y); cpu.V[0xF] = 1; } else if (!isPixelSetOnScreen && isSettingOfPixelRequested) { display.SetPixel(x, y); } }