for(int i = 0; i < 240; i+=2) { for(int m = 1; m < mosaicX; m++) { line[i] = line[i-1]; i++;
if(mosaicX > 1) { int m = 1; for(int i = 0; i < 239; i++) { line[i+1] = line[i]; m++; if(m == mosaicX) { m = 1; i++; }
inline void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs,                              u32 *line){  u16 *palette = (u16 *)paletteRAM;  u8 *charBase = &vram[((control >> 2) & 0x03) * 0x4000];  u16 *screenBase = (u16 *)&vram[((control >> 8) & 0x1f) * 0x800];  u32 prio = ((control & 3)<<25) + 0x1000000;  int sizeX = 256;  int sizeY = 256;  switch((control >> 14) & 3) {  case 0:    break;  case 1:    sizeX = 512;    break;  case 2:    sizeY = 512;    break;  case 3:    sizeX = 512;    sizeY = 512;    break;  }  int maskX = sizeX-1;  int maskY = sizeY-1;    bool mosaicOn = (control & 0x40) ? true : false;  int xxx = hofs & maskX;  int yyy = (vofs + VCOUNT) & maskY;  int mosaicX = (MOSAIC & 0x000F)+1;  int mosaicY = ((MOSAIC & 0x00F0)>>4)+1;  if(mosaicOn) {    if((VCOUNT % mosaicY) != 0) {      mosaicY = (VCOUNT / mosaicY) * mosaicY;      yyy = (vofs + mosaicY) & maskY;    }  }  if(yyy > 255 && sizeY > 256) {    yyy &= 255;    screenBase += 0x400;    if(sizeX > 256)      screenBase += 0x400;  }    int yshift = ((yyy>>3)<<5);  if((control) & 0x80) {    u16 *screenSource = screenBase + 0x400 * (xxx>>8) + ((xxx & 255)>>3) + yshift;    for(int x = 0; x < 240; x++) {      u16 data = READ16LE(screenSource);            int tile = data & 0x3FF;      int tileX = (xxx & 7);      int tileY = yyy & 7;            if(data & 0x0400)        tileX = 7 - tileX;      if(data & 0x0800)        tileY = 7 - tileY;            u8 color = charBase[tile * 64 + tileY * 8 + tileX];            line[x] = color ? (READ16LE(&palette[color]) | prio): 0x80000000;            if(data & 0x0400) {        if(tileX == 0)          screenSource++;      } else if(tileX == 7)        screenSource++;      xxx++;      if(xxx == 256) {        if(sizeX > 256)          screenSource = screenBase + 0x400 + yshift;        else {          screenSource = screenBase + yshift;          xxx = 0;        }      } else if(xxx >= sizeX) {        xxx = 0;        screenSource = screenBase + yshift;      }    }  } else {    u16 *screenSource = screenBase + 0x400*(xxx>>8)+((xxx&255)>>3) +      yshift;    for(int x = 0; x < 240; x++) {      u16 data = READ16LE(screenSource);              int tile = data & 0x3FF;      int tileX = (xxx & 7);      int tileY = yyy & 7;      if(data & 0x0400)        tileX = 7 - tileX;      if(data & 0x0800)        tileY = 7 - tileY;      u8 color = charBase[(tile<<5) + (tileY<<2) + (tileX>>1)];      if(tileX & 1) {        color = (color >> 4);      } else {        color &= 0x0F;      }            int pal = (READ16LE(screenSource)>>8) & 0xF0;      line[x] = color ? (READ16LE(&palette[pal + color])|prio): 0x80000000;      if(data & 0x0400) {        if(tileX == 0)          screenSource++;      } else if(tileX == 7)        screenSource++;      xxx++;      if(xxx == 256) {        if(sizeX > 256)          screenSource = screenBase + 0x400 + yshift;        else {          screenSource = screenBase + yshift;          xxx = 0;        }      } else if(xxx >= sizeX) {        xxx = 0;        screenSource = screenBase + yshift;      }    }  }  if(mosaicOn) {    for(int i = 0; i < 240; i+=2) {      for(int m = 1; m < mosaicX; m++) {        line[i] = line[i-1]; i++;      }    }  }}