public void renderBitmap() { //byte[] imageArray = new byte[(16 * 24) * (16 * 21) * 4]; //16x16 with 4 bits per pixel m_wb = new WriteableBitmap(640, 200, 96, 96, PixelFormats.Bgra32, BitmapPalettes.WebPalette); int width = Convert.ToInt32(widthBox.Text); int stride = Convert.ToInt32(strideBox.Text); int height = Convert.ToInt32(heightBox.Text); int bytesPerLines = width + stride; Int32Rect rect = new Int32Rect(); if (doubleCheck.IsChecked ?? true) { rect.Width = 2; } else { rect.Width = 1; } rect.Height = 1; C64RAM ramObjc = C64RAM.getInstace(); byte[] ram = ramObjc.getRAM(); for (int y = 0; y < height * 8; ++y) { int startAddress = m_startAddress + (y * bytesPerLines); rect.Y = y; for (int x = 0; x < width; ++x) { byte r = ram[startAddress + x]; for (int p = 0; p < 8; p += 1) { rect.X = x * 8 * rect.Width + p * rect.Width; if ((r & 128) == 128) { m_wb.WritePixels(rect, VICPallete.getSafePalBGR32(1), 8 /*4*rect.Width*/, 0); } else { m_wb.WritePixels(rect, VICPallete.getSafePalBGR32(0), 8 /*4*rect.Width*/, 0); } r = (byte)(r << 1); //get next pixel } // p } } canvas.Source = m_wb; }
public static void renderChar(int addr, int charX, int charY, bool multicolour, int charColour, int backgroundColour, int mulCol0, int mulCol1, WriteableBitmap wb) { byte[] ram; //check to see if we are using an extra charset if (addr < (int)eExtraCharsets.extraCharsetStart) { C64RAM ramObjc = C64RAM.getInstace(); ram = ramObjc.getRAM(); } else { if (addr >= (int)eExtraCharsets.hexCharset1 && addr < (int)eExtraCharsets.hexCharset1 + 0x800) { ram = charsetHex1; addr &= 0x7ff; } else if (addr >= (int)eExtraCharsets.hexCharset2 && addr < (int)eExtraCharsets.hexCharset2 + 0x800) { ram = charsetHex2; addr &= 0x7ff; } else if (addr >= (int)eExtraCharsets.hexCharset3 && addr < (int)eExtraCharsets.hexCharset3 + 0x800) { ram = charsetHex3; addr &= 0x7ff; } else if (addr >= (int)eExtraCharsets.charrom_lo && addr < (int)eExtraCharsets.charrom_hi + 0x800) { ram = charsetCHARROM; addr &= 0xfff; } else { C64RAM ramObjc = C64RAM.getInstace(); ram = ramObjc.getRAM(); } } Int32Rect rect = new Int32Rect(); if (multicolour) { rect.Width = 2; } else { rect.Width = 1; } rect.Height = 1; int spriteTLX = charX * 8; int spriteTLY = charY * 8; for (int sy = 0; sy < 8; ++sy) { rect.Y = spriteTLY + sy; for (int sx = 0; sx < 1; ++sx) { byte r = ram[addr]; //int bitmapIndex = ((spriteTLY + sy) * (24 * 4)) + ((spriteTLX + (sx*8)) * 4); if (multicolour) { for (int p = 0; p < 8; p += 2) { rect.X = spriteTLX + (sx * 8) + p; switch (r & 192) { default: case 0: //%00 wb.WritePixels(rect, VICPallete.getSafePalBGR32(backgroundColour), 8, 0); break; case 64: //%01 wb.WritePixels(rect, VICPallete.getSafePalBGR32(mulCol0), 8, 0); break; case 128: //%10 wb.WritePixels(rect, VICPallete.getSafePalBGR32(mulCol1), 8, 0); break; case 192: //%11 wb.WritePixels(rect, VICPallete.getSafePalBGR32(charColour), 8, 0); break; } r = (byte)(r << 2); //get next pixel } } else { for (int p = 0; p < 8; ++p) { rect.X = spriteTLX + (sx * 8) + p; if ((r & 128) == 128) { wb.WritePixels(rect, VICPallete.getSafePalBGR32(charColour), 4, 0); } else { wb.WritePixels(rect, VICPallete.getSafePalBGR32(backgroundColour), 4, 0); } r = (byte)(r << 1); //get next pixel } // p } addr++; } //sx } //sy }
void renderSprite(int addr, int spriteX, int spriteY, bool multicolour, int sprColour, WriteableBitmap wb) { C64RAM ramObjc = C64RAM.getInstace(); byte[] ram = ramObjc.getRAM(); Int32Rect rect = new Int32Rect(); if (multicolour) { rect.Width = 2; } else { rect.Width = 1; } rect.Height = 1; int spriteTLX = spriteX * 24; int spriteTLY = spriteY * 21; for (int sy = 0; sy < 21; ++sy) { rect.Y = spriteTLY + sy; for (int sx = 0; sx < 3; ++sx) { byte r = ram[addr]; //int bitmapIndex = ((spriteTLY + sy) * (24 * 4)) + ((spriteTLX + (sx*8)) * 4); if (multicolour) { for (int p = 0; p < 8; p += 2) { rect.X = spriteTLX + (sx * 8) + p; switch (r & 192) { default: case 0: //%00 wb.WritePixels(rect, VICPallete.getSafePalBGR32(m_backgroundColour), 8, 0); break; case 64: //%01 wb.WritePixels(rect, VICPallete.getSafePalBGR32(m_mulCol0), 8, 0); break; case 128: //%10 wb.WritePixels(rect, VICPallete.getSafePalBGR32(sprColour), 8, 0); break; case 192: //%11 wb.WritePixels(rect, VICPallete.getSafePalBGR32(m_mulCol1), 8, 0); break; } r = (byte)(r << 2); //get next pixel } } else { for (int p = 0; p < 8; ++p) { rect.X = spriteTLX + (sx * 8) + p; if ((r & 128) == 128) { wb.WritePixels(rect, VICPallete.getSafePalBGR32(sprColour), 4, 0); } else { wb.WritePixels(rect, VICPallete.getSafePalBGR32(m_backgroundColour), 4, 0); } r = (byte)(r << 1); //get next pixel } // p } addr++; } //sx } //sy }