コード例 #1
0
ファイル: metaapi.cpp プロジェクト: camgunz/eternity
//
// MetaObject::toString
//
// Virtual method for conversion of metaobjects into strings. As with the prior
// C implementation, the returned string pointer is a static buffer and should
// not be cached. The default toString method creates a hex dump representation
// of the object. This should be pretty interesting in C++...
// 04/03/11: Altered to use new ZoneObject functionality so that the entire
// object, including all subclasses, are dumped properly. Really cool ;)
//
const char *MetaObject::toString() const
{
   static qstring qstr;
   size_t bytestoprint = getZoneSize();
   const byte *data    = reinterpret_cast<const byte *>(getBlockPtr());
   
   qstr.clearOrCreate(128);

   if(!bytestoprint) // Not a zone object? Can only dump the base class.
   {
      bytestoprint = sizeof(*this);
      data = reinterpret_cast<const byte *>(this); // Not evil, I swear :P
   }

   while(bytestoprint)
   {
      int i;

      // print up to 12 bytes on each line
      for(i = 0; i < 12 && bytestoprint; ++i, --bytestoprint)
      {
         byte val = *data++;
         char bytes[4] = { 0 };

         sprintf(bytes, "%02x ", val);

         qstr += bytes;
      }
      qstr += '\n';
   }

   return qstr.constPtr();
}
コード例 #2
0
ファイル: memory.c プロジェクト: brian-kelley/ObsidianOS
static void setBlockStatus(Block b, int code)
{
    int level = getBlockLevel(b);
    byte* table; //start of table for parent blocks, or top-level block.
    byte mask = 0b11;
    if(level == 0)
        table = (byte*) megMap;
    else
        table = (byte*) getBlockPtr(getParentBlock(b));
    int baseIndex = b.levels[level];
    byte* entry = table + (baseIndex / 4); //2 bits per entry
    int shift = 6 - (2 * (baseIndex % 4));  //trust me it works
    byte newVal = *entry & ~(mask << shift);
    newVal |= (code << shift);
    *entry = newVal;
}
コード例 #3
0
ファイル: memory.c プロジェクト: brian-kelley/ObsidianOS
//Return a BlockStatus value or -1 on error
static int getBlockStatus(Block b)
{
    if(!validBlock(b))
        return -1;
    int level = getBlockLevel(b);
    byte* table; //start of table for parent blocks, or top-level block.
    byte mask = 0b11;
    int shift;
    //set table to address of block status bitmap of parent
    if(level == 0)
        table = (byte*) megMap;
    else
        table = (byte*) getBlockPtr(getParentBlock(b));
    int baseIndex = b.levels[level];
    byte entry = *(table + (baseIndex / 4)); //2 bits per entry
    shift = 6 - (2 * (baseIndex % 4));  //trust me it works
    return (entry & (mask << shift)) >> shift;
}
コード例 #4
0
ファイル: memory.c プロジェクト: brian-kelley/ObsidianOS
void* mmAlloc(size_t size)
{
    /*
    puts("");
    for(int j = 0; j < 60; j++)
        putchar('*');
    puts(""); */
    //printf("Allocating %lu bytes\n", size);
    int parentLevel = 2;  //start with smallest block and count up
    while(blockSize[parentLevel] < size)
    {
        parentLevel--;
    }
    int level = parentLevel + 1;
    if(level < 0 || level >= LEVELS)
    {
        //puts("WARNING: Couldn't pick a good block size.");
        level = 0;
    }
    size_t bsize = blockSize[level];
    int numBlocks = size / bsize;
    if(size % bsize)
        numBlocks++;
    //printf("Allocating a group of %d blocks of level %d\n", numBlocks, level);
    Block first;
    bool success = allocBlocks(level, numBlocks, &first);
    if(success)
    {
        //printf("Allocated %lu bytes, block: ", size);
        //printBlock(first);
        //puts("");
        return getBlockPtr(first);
    }
    else
    {
        //puts("Allocation failed!");
        return NULL;
    }
}
コード例 #5
0
ファイル: Memory.cpp プロジェクト: HolaRobo/utaustinvilla3d
const MemoryBlock* Memory::getBlockPtrByName(const std::string &name) const {
    return getBlockPtr(name);
}
コード例 #6
0
ファイル: Memory.cpp プロジェクト: HolaRobo/utaustinvilla3d
void Memory::setBlockLogging(const std::string &name, bool log_block) {
    getBlockPtr(name)->log_block = log_block;
}
コード例 #7
0
ファイル: Memory.cpp プロジェクト: Nani90/nao-robots
const MemoryBlock* Memory::getBlockPtrByName(const std::string &name) const {
  return getBlockPtr(name,MemoryOwner::UNKNOWN);
}
コード例 #8
0
ファイル: Memory.cpp プロジェクト: Nani90/nao-robots
void Memory::setBlockLogging(const std::string &name, bool log_block) {
  MemoryBlock *block = getBlockPtr(name,MemoryOwner::UNKNOWN);
  if (block != NULL)
    block->log_block = log_block;
}