// Draw the background and return it as blitimage. public BlitImage RenderBackground(int index) { if (index >= 0 && index < Backgrounds.Count) { BackgroundTiles tiles = ((Background)Backgrounds [index]).MyBackgroundTiles; if (tiles != null) { byte [] b = tiles.Render(ActiveTileSet); return(new BlitImage(b, 256)); } } var image = new BlitImage(256, 256); image.Black(); return(image); }
// Read data from ROM at given PC address. public override bool ReadFromROM(Rom rom, int addressPC) { int TilesPtr = 0; byte [] b = new byte [11]; rom.Seek(addressPC); if (!rom.Read(b, 0, 2)) { return(false); } int blockSize; int totalSize = 0; while (b [0] != 0 || b [1] != 0) { int type = Tools.ConcatBytes(b [0], b [1]); // Bytes.Add (b [0]); // Bytes.Add (b [1]); switch (type) { default: Console.WriteLine("Unknown BG block type found: {0}", Tools.IntToHex(type)); return(false); case 0x000A: case 0x000C: blockSize = 2; break; case 0x0004: blockSize = 7; break; case 0x0002: case 0x0008: blockSize = 9; break; case 0x000E: blockSize = 11; break; } if (!rom.Read(b, 2, blockSize - 2)) { return(false); } for (int i = 0; i < blockSize; i++) { Bytes.Add(b [i]); } if (type == 0x0004) { if (TilesPtr == 0) { TilesPtr = Tools.ConcatBytes(b [2], b [3], b [4]); } else { TilesPtr = 0; // [wip] still an ugly hack to skip Kraid background } } totalSize += blockSize; if (!rom.Read(b, 0, 2)) { return(false); } } if (TilesPtr != 0) { MyBackgroundTiles = new BackgroundTiles(); MyBackgroundTiles.ReadFromROM(rom, Tools.LRtoPC(TilesPtr)); } startAddressPC = addressPC; return(true); }