private void DrawTiles(Bitmap bitmap, int layer, bool bkgrnd) { // There are four possible tilesets to choose from int addrTileset = MemoryMap.TILE_CONTROL_REGISTER_ADDR + layer * 8; int reg = VICKY.ReadByte(addrTileset - MemoryMap.VICKY_BASE_ADDR); // if the set is not enabled, we're done. if ((reg & 0x01) == 00) { return; } // This is hard coded for now int lines = 52; int lutIndex = (reg & 14) >> 1; // 8 possible LUTs bool striding = (reg & 0x80) == 0x80; int tilesetAddress = VICKY.ReadLong(addrTileset + 1 - MemoryMap.VICKY_BASE_ADDR); int strideX = VICKY.ReadWord(addrTileset + 4 - MemoryMap.VICKY_BASE_ADDR); int strideY = VICKY.ReadWord(addrTileset + 6 - MemoryMap.VICKY_BASE_ADDR); // Now read the tilemap int tilemapAddress = 0xAF5000 + 0x800 * layer; BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); IntPtr p = bitmapData.Scan0; int colOffset = bkgrnd ? (80 - ColumnsVisible) / 2 * charWidth / tileSize : 0; int lineOffset = bkgrnd ? (60 - lines) / 2 * charHeight / tileSize : 0; for (int tileRow = lineOffset; tileRow < (30 - lineOffset); tileRow++) { for (int tileCol = colOffset; tileCol < (40 - colOffset); tileCol++) { int tile = VICKY.ReadByte(tilemapAddress + tileCol + tileRow * 64 - MemoryMap.VICKY_BASE_ADDR); int pixelIndex = 0; int value = 0; // Tiles are 16 x 16 for (int line = 0; line < 16; line++) { for (int col = 0; col < 16; col++) { // Lookup the pixel in the tileset //pixelIndex = VRAM.ReadByte(tilesetAddress + ((tile / 16) * 256 * 16 + (tile % 16) * 16) + col + line * strideX); //fix split out static video start address value pixelIndex = FoenixSystem.Current.MemoryManager.ReadByte(MemoryMap.VIDEO_START + tilesetAddress + ((tile / 16) * 256 * 16 + (tile % 16) * 16) + col + line * strideX); if (pixelIndex != 0) { value = (int)graphicsLUT[lutIndex * 256 + pixelIndex]; if (gammaCorrection != null) { //value = (int)((blue << 16) + (green << 8) + red + 0xFF000000); value = (int)((gammaCorrection[(value & 0x00FF0000) >> 0x10] << 0x10) + (gammaCorrection[0x100 + ((value & 0x0000FF00) >> 0x08)] << 0x08) + (gammaCorrection[0x200 + (value & 0x000000FF)]) + 0xFF000000); } System.Runtime.InteropServices.Marshal.WriteInt32(p, (line * bitmap.Width + col + tileCol * 16 + tileRow * 16 * 640) * 4, value); } } } } } bitmap.UnlockBits(bitmapData); }