Exemplo n.º 1
0
void FreeSpaceListing::giveSpace(
                 int address,
                 int length) {
  // Check to see if we can add this space to an existing entry
  for (FreeSpaceList::iterator it = freeSpaceList_.begin();
       it != freeSpaceList_.end();
       it++) {
    // Ensure that we don't cross bank boundaries
    // (needs more thorough checking)
    if ((it->address() % LoadedROM::bankSize)) {
      // If this space comes exactly before an existing one,
      // modify the existing space with the new amount
      if (it->address() == address + length) {
        it->setAddress(address);
        it->setLength(it->length() + length);
        return;
      }
      // If this space comes exactly after an existing one,
      // modify the existing space with the new amount
      // as long as this would not cross a bank boundary
      else if ((address % LoadedROM::bankSize)
               && (it->address() + it->length() == address)) {
        it->setLength(it->length() + length);
        return;
      }
    }
  }
                 
  // No existing space found: add new entry
  freeSpaceList_.push_back(FreeSpaceListPair(address, length));
}
Exemplo n.º 2
0
void FreeSpaceListing::claimSpace(
                FreeSpaceList::iterator& position,
                int length) {
  // Throw if trying to claim more space than exists
  if (length > position->length()) {
    throw TGenericException(TALES_SRCANDLINE,
                           "FreeSpaceListing::claimSpace("
                           "FreeSpaceList::iterator,int",
                           std::string("Tried to claim ")
                           + StringConversion::toString(length)
                           + std::string(" bytes at position ")
                           + StringConversion::toString(position->address())
                           + std::string(" when only ")
                           + StringConversion::toString(position->length())
                           + std::string(" were available"));
  }
  
  // Increase address
  position->setAddress(position->address() + length);
  
  // Decrease length
  position->setLength(position->length() - length);
  
  // If all space at this address is claimed, remove it from the list
  if (position->length() == 0) {
    freeSpaceList_.erase(position);
  }
}