u16 *screenSource = screenBase + ((y>>3)*32);
int yy = y & 255;  if(y == 256 && sizeY > 256) { screenBase += 0x400; if(sizeX > 256) screenBase += 0x400; } u16 *screenSource = screenBase + ((yy>>3)*32);
void MapView::renderTextScreen(u16 control){  u16 *palette = (u16 *)paletteRAM;  u8 *charBase = &vram[((control >> 2) & 0x03) * 0x4000];  u16 *screenBase = (u16 *)&vram[((control >> 8) & 0x1f) * 0x800];  u8 *bmp = data;  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;  }  w = sizeX;  h = sizeY;    if(control & 0x80) {    for(int y = 0; y < sizeY; y++) {      u16 *screenSource = screenBase + ((y>>3)*32);      for(int x = 0; x < sizeX; x++) {        u16 data = *screenSource;              int tile = data & 0x3FF;        int tileX = (x & 7);        int tileY = y & 7;                if(data & 0x0400)          tileX = 7 - tileX;        if(data & 0x0800)          tileY = 7 - tileY;        u8 c = charBase[tile * 64 + tileY * 8 + tileX];                u16 color = palette[c];                *bmp++ = ((color >> 10) & 0x1f) << 3;        *bmp++ = ((color >> 5) & 0x1f) << 3;        *bmp++ = (color & 0x1f) << 3;                    if(data & 0x0400) {          if(tileX == 0)            screenSource++;        } else if(tileX == 7)          screenSource++;        if(x == 255 && sizeX > 256) {          screenSource = screenBase + 0x400 + ((y>>3)*32);        }      }    }  } else {    for(int y = 0; y < sizeY; y++) {      u16 *screenSource = screenBase + ((y>>3)*32);      for(int x = 0; x < sizeX; x++) {        u16 data = *screenSource;                int tile = data & 0x3FF;        int tileX = (x & 7);        int tileY = y & 7;        if(data & 0x0400)          tileX = 7 - tileX;        if(data & 0x0800)          tileY = 7 - tileY;                u8 color = charBase[tile * 32 + tileY * 4 + (tileX>>1)];                if(tileX & 1) {          color = (color >> 4);        } else {          color &= 0x0F;        }        int pal = (*screenSource>>8) & 0xF0;        u16 color2 = palette[pal + color];        *bmp++ = ((color2 >> 10) & 0x1f) << 3;        *bmp++ = ((color2 >> 5) & 0x1f) << 3;        *bmp++ = (color2 & 0x1f) << 3;                if(data & 0x0400) {          if(tileX == 0)            screenSource++;        } else if(tileX == 7)          screenSource++;        if(x == 255 && sizeX > 256) {          screenSource = screenBase + 0x400 + ((y>>3)*32);        }              }    }  }  /*  switch(bg) {  case 0:    renderView(BG0HOFS<<8, BG0VOFS<<8,               0x100, 0x000,               0x000, 0x100,               (sizeX -1) <<8,               (sizeY -1) << 8,               true);    break;  case 1:    renderView(BG1HOFS<<8, BG1VOFS<<8,               0x100, 0x000,               0x000, 0x100,               (sizeX -1) <<8,               (sizeY -1) << 8,               true);    break;  case 2:    renderView(BG2HOFS<<8, BG2VOFS<<8,               0x100, 0x000,               0x000, 0x100,               (sizeX -1) <<8,               (sizeY -1) << 8,               true);    break;  case 3:    renderView(BG3HOFS<<8, BG3VOFS<<8,               0x100, 0x000,               0x000, 0x100,               (sizeX -1) <<8,               (sizeY -1) << 8,               true);    break;  }  */}