lineOBJ[sx] = spritePalette[palette+color] | prio;
lineOBJ[sx] = FROM16LE(spritePalette[palette+color]) | prio;
void inline gfxDrawSprites(u32 *lineOBJ){  int m=0;  gfxClearArray(lineOBJ);  if(layerEnable & 0x1000) {    u16 *sprites = (u16 *)oam;    u16 *spritePalette = &((u16 *)paletteRAM)[256];    int mosaicY = ((MOSAIC & 0xF000)>>12) + 1;    int mosaicX = ((MOSAIC & 0xF00)>>8) + 1;        for(int x = 0; x < 128 ; x++) {      u16 a0 = *sprites++;      u16 a1 = *sprites++;      u16 a2 = *sprites++;      sprites++;      // ignore OBJ-WIN      if((a0 & 0x0c00) == 0x0800)         continue;            int sizeY = 8;      int sizeX = 8;            switch(((a0 >>12) & 0x0c)|(a1>>14)) {      case 0:        break;      case 1:        sizeX = sizeY = 16;        break;      case 2:        sizeX = sizeY = 32;        break;      case 3:        sizeX = sizeY = 64;        break;      case 4:        sizeX = 16;        break;      case 5:        sizeX = 32;        break;      case 6:        sizeX = 32;        sizeY = 16;        break;      case 7:        sizeX = 64;        sizeY = 32;        break;      case 8:        sizeY = 16;        break;      case 9:        sizeY = 32;        break;      case 10:        sizeX = 16;        sizeY = 32;        break;      case 11:        sizeX = 32;        sizeY = 64;        break;      default:        continue;      }      int sy = (a0 & 255);      if(sy > 160)        sy -= 256;            if(a0 & 0x0100) {        int fieldX = sizeX;        int fieldY = sizeY;        if(a0 & 0x0200) {          fieldX <<= 1;          fieldY <<= 1;        }                int t = VCOUNT - sy;        if((t >= 0) && (t < fieldY)) {          int sx = (a1 & 0x1FF);          if((sx < 240) || (((sx + fieldX) & 511) < 240)) {            // int t2 = t - (fieldY >> 1);            int rot = (a1 >> 9) & 0x1F;            u16 *OAM = (u16 *)oam;            int dx = OAM[3 + (rot << 4)];            if(dx & 0x8000)              dx |= 0xFFFF8000;            int dmx = OAM[7 + (rot << 4)];            if(dmx & 0x8000)              dmx |= 0xFFFF8000;            int dy = OAM[11 + (rot << 4)];            if(dy & 0x8000)              dy |= 0xFFFF8000;            int dmy = OAM[15 + (rot << 4)];            if(dmy & 0x8000)              dmy |= 0xFFFF8000;                        if(a0 & 0x1000) {              t -= (t % mosaicY);            }            int realX = ((sizeX) << 7) - (fieldX >> 1)*dx - (fieldY>>1)*dmx              + t * dmx;            int realY = ((sizeY) << 7) - (fieldX >> 1)*dy - (fieldY>>1)*dmy              + t * dmy;            u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);                        if(a0 & 0x2000) {              int c = (a2 & 0x3FF);              if((DISPCNT & 7) > 2 && (c < 512))                continue;              int inc = 32;              if(DISPCNT & 0x40)                inc = sizeX >> 2;              else                c &= 0x3FE;              for(int x = 0; x < fieldX; x++) {                int xxx = realX >> 8;                int yyy = realY >> 8;                                if(xxx < 0 || xxx >= sizeX ||                   yyy < 0 || yyy >= sizeY ||                   sx >= 240);                else {                  u32 color = vram[0x10000 + (((c + (yyy>>3) * inc)*                                    32 + (yyy & 7) * 8 + (xxx >> 3) * 64 +                                    (xxx & 7))&0x7FFF)];                  if(color && (prio < (lineOBJ[sx]&0xFF000000))) {                      lineOBJ[sx] = spritePalette[color] | prio;                  }                  if (a0 & 0x1000) {                    if (m)                      lineOBJ[sx]=lineOBJ[sx-1];                    m++;                    if (m==mosaicX)                      m=0;                  }                }                sx = (sx+1)&511;;                realX += dx;                realY += dy;              }            } else {              int c = (a2 & 0x3FF);              if((DISPCNT & 7) > 2 && (c < 512))                continue;                            int inc = 32;              if(DISPCNT & 0x40)                inc = sizeX >> 3;              int palette = (a2 >> 8) & 0xF0;                               for(int x = 0; x < fieldX; x++) {                int xxx = realX >> 8;                int yyy = realY >> 8;                if(xxx < 0 || xxx >= sizeX ||                   yyy < 0 || yyy >= sizeY ||                   sx >= 240);                else {                  u32 color = vram[0x10000 + (((c + (yyy>>3) * inc)*                                               32 + (yyy & 7) * 4 + (xxx >> 3) * 32 +                                               ((xxx & 7)>>1))&0x7FFF)];                  if(xxx & 1)                    color >>= 4;                  else                    color &= 0x0F;                                    if(color && (prio < (lineOBJ[sx]&0xFF000000))) {                    lineOBJ[sx] = spritePalette[palette+color] | prio;                  }                }                if (a0 & 0x1000) {                  if (m)                    lineOBJ[sx]=lineOBJ[sx-1];                  m++;                  if (m==mosaicX)                    m=0;                }                sx = (sx+1)&511;;                realX += dx;                realY += dy;                              }                   }          }        }      } else {        int t = VCOUNT - sy;        if((t >= 0) && (t < sizeY)) {          int sx = (a1 & 0x1FF);          if(((sx < 240)||(((sx+sizeX)&511)<240)) && !(a0 & 0x0200)) {            if(a0 & 0x2000) {              if(a1 & 0x2000)                t = sizeY - t - 1;              int c = (a2 & 0x3FF);              if((DISPCNT & 7) > 2 && (c < 512))                continue;                            int inc = 32;              if(DISPCNT & 0x40) {                inc = sizeX >> 2;              } else {                c &= 0x3FE;              }              int xxx = 0;              if(a1 & 0x1000)                xxx = sizeX-1;              if(a0 & 0x1000) {                t -= (t % mosaicY);              }              int address = 0x10000 + ((((c+ (t>>3) * inc) << 5)                + ((t & 7) << 3) + ((xxx>>3)<<6) + (xxx & 7)) & 0x7FFF);                              if(a1 & 0x1000)                xxx = 7;              u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);                                  for(int xx = 0; xx < sizeX; xx++) {                if(sx < 240) {                  u8 color = vram[address];                  if(color && (prio < (lineOBJ[sx] & 0xFF000000))) {                    lineOBJ[sx] = spritePalette[color] | prio;                  }                  if (a0 & 0x1000) {                    if (m)                      lineOBJ[sx]=lineOBJ[sx-1];                    m++;                    if (m==mosaicX)                      m=0;                  }                }                                  sx = (sx+1) & 511;                if(a1 & 0x1000) {                  xxx--;                  address--;                  if(xxx == -1) {                    address -= 56;                    xxx = 7;                  }                  if(address < 0x10000)                    address += 0x8000;                } else {                  xxx++;                  address++;                  if(xxx == 8) {                    address += 56;                    xxx = 0;                  }                  if(address > 0x17fff)                    address -= 0x8000;                }              }            } else {              if(a1 & 0x2000)                t = sizeY - t - 1;              int c = (a2 & 0x3FF);              if((DISPCNT & 7) > 2 && (c < 512))                continue;                            int inc = 32;              if(DISPCNT & 0x40) {                inc = sizeX >> 3;              }              int xxx = 0;              if(a1 & 0x1000)                xxx = sizeX - 1;                                  if(a0 & 0x1000) {                  t -= (t % mosaicY);                }              int address = 0x10000 + (((c + (t>>3) * inc) * 32                + (t & 7) * 4 + (xxx>>3) * 32 + ((xxx & 7) >> 1))&0x7FFF);              u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00)<<6);              int palette = (a2 >> 8) & 0xF0;                       if(a1 & 0x1000) {                xxx = 7;                for(int xx = sizeX - 1; xx >= 0; xx--) {                  if(sx < 240) {                    u8 color = vram[address];                    if(xx & 1) {                      color = (color >> 4);                    } else                      color &= 0x0F;                                        if(color && (prio < (lineOBJ[sx] & 0xFF000000))) {                      lineOBJ[sx] = spritePalette[palette + color] | prio;                    }                  }                  if (a0 & 0x1000) {                    if (m)                      lineOBJ[sx]=lineOBJ[sx-1];                    m++;                    if (m==mosaicX)                      m=0;                  }                  sx = (sx+1) & 511;                  xxx--;                  if(!(xx & 1))                    address--;                  if(xxx == -1) {                    xxx = 7;                    address -= 28;                  }                  if(address < 0x10000)                    address += 0x8000;                }                         } else {                        for(int xx = 0; xx < sizeX; xx++) {                  if(sx < 240) {                    u8 color = vram[address];                    if(xx & 1) {                      color = (color >> 4);                    } else                      color &= 0x0F;                                        if(color && (prio < (lineOBJ[sx] & 0xFF000000))) {                      lineOBJ[sx] = spritePalette[palette + color] | prio;                    }                  }                  if (a0 & 0x1000) {                    if (m)                      lineOBJ[sx]=lineOBJ[sx-1];                    m++;                    if (m==mosaicX)                      m=0;                  }                  sx = (sx+1) & 511;                  xxx++;                  if(xx & 1)                    address++;                  if(xxx == 8) {                    address += 28;                    xxx = 0;                  }                  if(address > 0x17fff)                    address -= 0x8000;                }                         }            }          }        }      }    }  }}