     //    Bit2-0 Palette number  **CGB Mode Only**     (OBP0-7)
 
     let spriteHeight = 16 if self.SpriteSize else 8;
-    let i: int64 = 39;
+    let i = 0;
     let n = 0;
     let offset = uint64(self.LY) * DISP_WIDTH;
 
-    while i >= 0 {
+    while i < 40 {
       let s = *((self.OAM as *Sprite) + i);
       let sy = int16(s.Y) - 16;
       let sx = int16(s.X) - 8;


            // Another sprite was drawn and the drawn sprite is < on the
            // X-axis
            if bits.Test(pixelCache, 1) and (xCache < uint8(sx + 8)) {
              x += 1;
              continue;
            }

      if (sy <= int16(self.LY)) and (sy + spriteHeight) > int16(self.LY) {

        // A maximum 10 sprites per line are allowed
        // n += 1;
        if n >= 10 { break; }

        // Calculate y-index into the tile (applying y-mirroring)
        let tileY = uint8(int16(self.LY) - sy);
