         while x < 8 {
           if (sprite_x + x >= 0) and (sprite_x + x < 160) {
             // Make a bitmask for the pixel being rendered
-            let pixel_mask = 0x80 >> ((sprite_x + x) % 8);
+            let pixel_mask = 0x80 >> (if testb(sprite_flags, 5) { 7 - x; } else { x; });
 
             // Check the color bits for that pixel
             let palette_lo = if *(vram + td_address) & pixel_mask != 0 { 1; } else { 0; };


            // Combine them into a single index from 0 to 3
            let palette_index = uint8((palette_hi << 1) | palette_lo);

            // Palette
            let color = if testb(sprite_flags, 4) {
              (gpu_obj0_palette >> (palette_index * 2)) & 0x3;
            } else {
              (gpu_obj1_palette >> (palette_index * 2)) & 0x3;
            };

            // Push pixel to framebuffer
            *(gpu_framebuffer + (int64(gpu_line) * 160) + (sprite_x + x)) = color;
          }

          x += 1;


      if sprite_y <= int16(gpu_line) and (sprite_y + 8) > int16(gpu_line) {

        total += 1;
        if total > 10 {
          // No more sprites
          break;
        }

        let tile_y: int16 = int16(gpu_line) - sprite_y;
        let td_address: int16 = sprite_tile * 16 + int16(tile_y) * 2;

