unsafe void DrawBG(int *pal) { int bgheight = vdp.FrameHeight == 192 ? 224 : 256; int maxtile = bgheight * 4; if (bgheight != bmpViewBG.bmp.Height) { bmpViewBG.Height = bgheight; bmpViewBG.ChangeBitmapSize(256, bgheight); } var lockdata = bmpViewBG.bmp.LockBits(new Rectangle(0, 0, 256, bgheight), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); int *dest = (int *)lockdata.Scan0; int pitch = lockdata.Stride / sizeof(int); fixed(byte *src = vdp.PatternBuffer) fixed(byte *vram = vdp.VRAM) { short *map = (short *)(vram + vdp.CalcNameTableBase()); for (int tile = 0; tile < maxtile; tile++) { short bgent = *map++; bool hflip = (bgent & 1 << 9) != 0; bool vflip = (bgent & 1 << 10) != 0; int * tpal = pal + ((bgent & 1 << 11) >> 7); int srcaddr = (bgent & 511) * 64; int tx = tile & 31; int ty = tile >> 5; int destaddr = ty * 8 * pitch + tx * 8; Draw8x8hv(src + srcaddr, dest + destaddr, pitch, tpal, hflip, vflip); } } bmpViewBG.bmp.UnlockBits(lockdata); bmpViewBG.Refresh(); }