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 sizeX = 8<<(a1>>14); int sizeY = sizeX;  if ((a0>>14) & 1) { if (sizeX<32) sizeX<<=1; if (sizeY>8) sizeY>>=1;
inline void gfxDrawOBJWin(u32 *lineOBJWin){  gfxClearArray(lineOBJWin);  if(layerEnable & 0x8000) {    u16 *sprites = (u16 *)oam;    // u16 *spritePalette = &((u16 *)paletteRAM)[256];    for(int x = 0; x < 128 ; x++) {      u16 a0 = READ16LE(sprites++);      u16 a1 = READ16LE(sprites++);      u16 a2 = READ16LE(sprites++);      sprites++;      // ignore non 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 = READ16LE(&OAM[3 + (rot << 4)]);            if(dx & 0x8000)              dx |= 0xFFFF8000;            int dmx = READ16LE(&OAM[7 + (rot << 4)]);            if(dmx & 0x8000)              dmx |= 0xFFFF8000;            int dy = READ16LE(&OAM[11 + (rot << 4)]);            if(dy & 0x8000)              dy |= 0xFFFF8000;            int dmy = READ16LE(&OAM[15 + (rot << 4)]);            if(dmy & 0x8000)              dmy |= 0xFFFF8000;                        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)<<5)                                    + ((yyy & 7)<<3) + ((xxx >> 3)<<6) +                                   (xxx & 7))&0x7fff)];                  if(color) {                    lineOBJWin[sx] = 1;                  }                }                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(x == 0 || x == (sizeX-1) ||                //                 t == 0 || t == (sizeY-1)) {                //                lineOBJ[sx] = 0x001F | prio;                //              } else {                  if(xxx < 0 || xxx >= sizeX ||                     yyy < 0 || yyy >= sizeY ||                     sx >= 240){                  } else {                    u32 color = vram[0x10000 + ((((c + (yyy>>3) * inc)<<5)                                     + ((yyy & 7)<<2) + ((xxx >> 3)<<5) +                                     ((xxx & 7)>>1))&0x7fff)];                    if(xxx & 1)                      color >>= 4;                    else                      color &= 0x0F;                                        if(color) {                      lineOBJWin[sx] = 1;                    }                  }                  //            }                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;              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) {                    lineOBJWin[sx] = 1;                  }                }                                  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;              int address = 0x10000 + ((((c + (t>>3) * inc)<<5)                + ((t & 7)<<2) + ((xxx>>3)<<5) + ((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) {                      lineOBJWin[sx] = 1;                    }                  }                  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) {                      lineOBJWin[sx] = 1;                    }                  }                  sx = (sx+1) & 511;                  xxx++;                  if(xx & 1)                    address++;                  if(xxx == 8) {                    address += 28;                    xxx = 0;                  }                  if(address > 0x17fff)                    address -= 0x8000;                }                         }            }          }        }      }    }  }}