             }
             if state.currentCycle >= 18 && state.currentCycle <= 57 && i == state.pipe.xScroll {
                 state.graphicsShiftRegister = state.pipe.graphicsData
+                state.graphicsMulticolorFlipFlop = true
             }
             let graphicsPixel = drawGraphicsPixel(i)
             let (spritePixel, topSprite, spriteCollisions) = drawSpritePixel(i)

        case 0x15:
            state.me = byte
        case 0x16:
            state.xScroll = byte & 0x07
            state.nextPipe.xScroll = state.xScroll
            state.csel = byte & 0x08 != 0
            borderComparison.left = state.csel ? 24 : 31
            borderComparison.right = state.csel ? 344 : 335
            state.mcm = byte & 0x10 != 0
        case 0x17:
            state.mye = byte
            for i in 0...7 {

    
    @inline(__always) private func drawGraphicsPixel(_ i: Int) -> Int? {
        var graphicsPixel: Int? = nil
        if state.pipe.mcm && state.pipe.graphicsColorLine & 0x08 != 0 {
            if state.graphicsMulticolorFlipFlop {
                state.graphicsPixelData = state.graphicsShiftRegister >> 6
            }
        } else {
            state.graphicsPixelData = state.graphicsShiftRegister >> 7
        }
        
        switch (state.ecm, state.bmm, state.pipe.mcm) {
        case (false, false, false): // Standard text mode (ECM/BMM/MCM=0/0/0)
            if state.graphicsPixelData != 0 {
                graphicsPixel = Int(state.pipe.graphicsColorLine)
            } else {
                state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
            }
        case (false, false, true): // Multicolor text mode (ECM/BMM/MCM=0/0/1)
            if state.pipe.graphicsColorLine & 0x08 == 0 {
                if state.graphicsPixelData != 0 {
                    graphicsPixel = Int(state.pipe.graphicsColorLine)
                } else {
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
                }
            } else {
                switch state.graphicsPixelData {
                case 0:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
                case 1:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b1c)]
                case 2:
                    graphicsPixel = Int(state.colorPipe.b2c)
                case 3:
                    graphicsPixel = Int(state.pipe.graphicsColorLine) & 0x07
                default:
                    break
                }
            }
        case (false, true, false): // Standard bitmap mode (ECM/BMM/MCM=0/1/0)
            if state.graphicsPixelData != 0 {
                graphicsPixel = Int((state.pipe.graphicsVideoMatrix & 0xF0) >> 4)
            } else {
                state.screenBuffer[state.bufferPosition] = colors[Int(state.pipe.graphicsVideoMatrix & 0x0F)]
            }
        case (false, true, true): // Multicolor bitmap mode (ECM/BMM/MCM=0/1/1)
            switch state.graphicsPixelData {
            case 0:
                state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
            case 1:
                state.screenBuffer[state.bufferPosition] = colors[Int((state.pipe.graphicsVideoMatrix & 0xF0) >> 4)]
            case 2:
                graphicsPixel = Int(state.pipe.graphicsVideoMatrix & 0x0F)
            case 3:
                graphicsPixel = Int(state.pipe.graphicsColorLine)
            default:
                break
            }
        case (true, false, false): // ECM text mode (ECM/BMM/MCM=1/0/0)
            if state.graphicsPixelData != 0 {
                graphicsPixel = Int(state.pipe.graphicsColorLine)
            } else {
                switch state.pipe.graphicsVideoMatrix >> 6 {
                case 0:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
                case 1:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b1c)]
                case 2:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b2c)]
                case 3:
                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b3c)]
                default:
                    break
                }
            }
        case (true, false, true): // Invalid text mode (ECM/BMM/MCM=1/0/1)
            if state.pipe.graphicsColorLine & 0x08 == 0 {
                if state.graphicsPixelData != 0 {
                    graphicsPixel = 0
                } else {
                    state.screenBuffer[state.bufferPosition] = colors[0]
                }
            } else {
                if state.graphicsPixelData > 1 {
                    graphicsPixel = 0
                } else {
                    state.screenBuffer[state.bufferPosition] = colors[0]
                }
            }
        case (true, true, false): // Invalid bitmap mode 1 (ECM/BMM/MCM=1/1/0)
            if state.graphicsPixelData != 0 {
                graphicsPixel = 0
            } else {
                state.screenBuffer[state.bufferPosition] = colors[0]
            }
        case (true, true, true): // Invalid bitmap mode 2 (ECM/BMM/MCM=1/1/1)
            if state.graphicsPixelData > 1 {
                graphicsPixel = 0
            } else {
                state.screenBuffer[state.bufferPosition] = colors[0]
            }
        }
        
        state.graphicsShiftRegister <<= 1
        state.graphicsMulticolorFlipFlop = !state.graphicsMulticolorFlipFlop
        
        return graphicsPixel
    }
    
