Battle_Script_Pro.Form1.FindFreeSpace C# (CSharp) Method

FindFreeSpace() private method

private FindFreeSpace ( int dataSize, int startLocation, byte rom ) : int
dataSize int
startLocation int
rom byte
return int
        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;
        }
Form1