public void CopyRows(Palette src, int srcRow, int dstRow, int numRows) { Array.Copy(src.data, srcRow * 16, data, dstRow * 16, numRows * 16); }
public byte AddAbility(ItemType item) { byte animGfxNum = (byte)(Rom.NumOfAnimGfx + item - ItemType.Long); // find empty spot in palette int palRow = 15; for (int r = 1; r < 14; r++) { ushort color = palette.GetColor(r, 1); bool blank = true; for (int c = 2; c < 16; c++) { if (palette.GetColor(r, c) != color) { blank = false; break; } } if (blank) { Palette itemPal = item.AbilityPalette(); palette.CopyRows(itemPal, 0, r, 1); palRow = r + 2; break; } } // find empty spot in animGfx int animGfxSlot = 0; for (int i = 0; i < 0x10; i++) { if (animTileset[i * 3] == 0) { animTileset[i * 3] = animGfxNum; animGfxSlot = i; break; } } // find empty spot in tile table int blockNum = 0x4C; int tileVal = 0x40; for (int i = 0x4C; i < 0x50; i++) { int offset = i * 4 + 1; if (tilemap[offset] == 0x40 && tilemap[offset + 1] == 0x40 && tilemap[offset + 2] == 0x40 && tilemap[offset + 3] == 0x40) { tileVal = (palRow << 12) | (animGfxSlot * 4); tilemap[offset] = (ushort)tileVal; tilemap[offset + 1] = (ushort)(tileVal + 1); tilemap[offset + 2] = (ushort)(tileVal + 2); tilemap[offset + 3] = (ushort)(tileVal + 3); blockNum = i; break; } } // fix Tilemap400 int tm400Offset = rom.Tilemap400Offset + (0xD0 + item - ItemType.Long) * 8; rom.Write16(tm400Offset, (ushort)tileVal); rom.Write16(tm400Offset + 2, (ushort)(tileVal + 1)); rom.Write16(tm400Offset + 4, (ushort)(tileVal + 2)); rom.Write16(tm400Offset + 6, (ushort)(tileVal + 3)); return((byte)blockNum); }