     
     @inline(__always) private func drawGraphicsPixel(_ i: Int) -> Int? {
         var graphicsPixel: Int? = nil
-        if state.bmm {
-            if state.mcm {
-                switch (state.graphicsShiftRegister & 0xC0) >> 6 {
+        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.pipe.graphicsVideoMatrix & 0xF0) >> 4)]
+                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b1c)]
                 case 2:
-                    graphicsPixel = Int(state.pipe.graphicsVideoMatrix & 0x0F)
+                    graphicsPixel = Int(state.colorPipe.b2c)
                 case 3:
-                    graphicsPixel = Int(state.pipe.graphicsColorLine)
+                    graphicsPixel = Int(state.pipe.graphicsColorLine) & 0x07
                 default:
                     break
                 }
-                if i % 2 == 1 {
-                    state.graphicsShiftRegister <<= 2
-                }
-            } else {
-                if state.graphicsShiftRegister >> 7 == 0 {
-                    state.screenBuffer[state.bufferPosition] = colors[Int(state.pipe.graphicsVideoMatrix & 0x0F)]
-                } else {
-                    graphicsPixel = Int((state.pipe.graphicsVideoMatrix & 0xF0) >> 4)
-                }
-                state.graphicsShiftRegister <<= 1
-            }
-        } else if (!state.mcm && !state.bmm) || (state.mcm && state.pipe.graphicsColorLine & 0x08 == 0) {
-            if state.graphicsShiftRegister >> 7 != 0 {
-                graphicsPixel = Int(state.pipe.graphicsColorLine)
-            } else {
-                if state.ecm {
-                    switch (state.pipe.graphicsVideoMatrix & 0xC0) >> 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
-                    }
-                } else {
-                    state.screenBuffer[state.bufferPosition] = colors[Int(state.colorPipe.b0c)]
-                }
-            }
-            state.graphicsShiftRegister <<= 1
-        } else {
-            switch (state.graphicsShiftRegister & 0xC0) >> 6 {
+            }
+        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.colorPipe.b1c)]
+                state.screenBuffer[state.bufferPosition] = colors[Int((state.pipe.graphicsVideoMatrix & 0xF0) >> 4)]
             case 2:
-                graphicsPixel = Int(state.colorPipe.b2c)
+                graphicsPixel = Int(state.pipe.graphicsVideoMatrix & 0x0F)
             case 3:
-                graphicsPixel = Int(state.pipe.graphicsColorLine) & 0x07
+                graphicsPixel = Int(state.pipe.graphicsColorLine)
             default:
                 break
             }
-            if i % 2 == 1 {
-                state.graphicsShiftRegister <<= 2
-            }
-        }
+        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
     }
     

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

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