private int FindFreeSpace(int dataSize, int startLocation, byte[] rom)
{
bool spaceFound = false;
while (!spaceFound)
{
for (int i = 0; i <= dataSize; i++)
{
if (startLocation + dataSize <= rom.Length)
{
if (rom[startLocation + i] != freeSpaceByte)
{
break;
}
else if (i == dataSize)
{
spaceFound = true;
break;
}
}
else
{
spaceFound = true;
MessageBox.Show("No free space could be found in the alloted area. Try widening the search parameters.");
startLocation = Int32.MaxValue;
break;
}
}
if (!spaceFound)
{
startLocation++;
}
}
return startLocation;
}