コード例 #1
0
ファイル: teledisk.cpp プロジェクト: djdron/zxtune
    void DecodeRLE(const uint8_t* data, std::size_t size, Dump& result)
    {
      Dump tmp;
      tmp.reserve(MAX_SECTOR_SIZE);
      ByteStream stream(data, size);
      while (!stream.Eof())
      {
        const uint_t len = 2 * stream.GetByte();
        Require(!stream.Eof());
        const uint_t count = stream.GetByte();
        Require(count != 0);

        const bool isRLE = len != 0;
        const uint_t blockSize = isRLE ? len : count;
        Require(stream.GetRestBytes() >= blockSize);
        for (uint_t idx = 0; idx != blockSize; ++idx)
        {
          tmp.push_back(stream.GetByte());
        }
        if (isRLE)
        {
          Require(CopyFromBack(len, tmp, len * (count - 1)));
        }
      }
      result.swap(tmp);
    }
コード例 #2
0
ファイル: fulldiskimage.cpp プロジェクト: fgroen/zxtune
    bool DecodeData()
    {
      const uint8_t* const rawData = static_cast<const uint8_t*>(Header.ID);
      const std::size_t dataOffset = fromLE(Header.DataOffset);
      const uint_t cylinders = fromLE(Header.Cylinders);
      const uint_t sides = fromLE(Header.Sides);

      Dump result;
      result.reserve(FDI_MAX_SIZE);
      std::size_t trackInfoOffset = sizeof(Header) + fromLE(Header.InfoSize);
      std::size_t rawSize = dataOffset;
      for (uint_t cyl = 0; cyl != cylinders; ++cyl)
      {
        for (uint_t sid = 0; sid != sides; ++sid)
        {
          if (trackInfoOffset + sizeof(RawTrack) > Limit)
          {
            return false;
          }

          const RawTrack* const trackInfo = safe_ptr_cast<const RawTrack*>(rawData + trackInfoOffset);
          typedef std::vector<SectorDescr> SectorDescrs;
          //collect sectors reference
          SectorDescrs sectors;
          sectors.reserve(trackInfo->SectorsCount);
          for (std::size_t secNum = 0; secNum != trackInfo->SectorsCount; ++secNum)
          {
            const RawTrack::Sector* const sector = trackInfo->Sectors + secNum;
            const std::size_t secSize = 128 << sector->Size;
            //since there's no information about head number (always 0), do not check it
            //assert(sector->Head == sid);
            if (sector->Cylinder != cyl)
            {
              return false;
            }
            const std::size_t offset = dataOffset + fromLE(sector->Offset) + fromLE(trackInfo->Offset);
            if (offset + secSize > Limit)
            {
              return false;
            }
            sectors.push_back(SectorDescr(sector->Number, rawData + offset, rawData + offset + secSize));
            rawSize = std::max(rawSize, offset + secSize);
          }

          //sort by number
          std::sort(sectors.begin(), sectors.end());
          //and gather data
          for (SectorDescrs::const_iterator it = sectors.begin(), lim = sectors.end(); it != lim; ++it)
          {
            result.insert(result.end(), it->Begin, it->End);
          }
          //calculate next track by offset
          trackInfoOffset += sizeof(*trackInfo) + (trackInfo->SectorsCount - 1) * sizeof(trackInfo->Sectors);
        }
      }
      UsedSize = rawSize;
      Decoded.swap(result);
      return true;
    }
コード例 #3
0
ファイル: teledisk.cpp プロジェクト: djdron/zxtune
 void DecodeR2P(const uint8_t* data, std::size_t size, Dump& result)
 {
   Require(size % sizeof(R2PEntry) == 0);
   Dump tmp;
   tmp.reserve(MAX_SECTOR_SIZE);
   for (const R2PEntry* it = safe_ptr_cast<const R2PEntry*>(data), *lim = it + size / sizeof(*it); it != lim; ++it)
   {
     const uint_t count = fromLE(it->Count);
     Require(count != 0);
     tmp.push_back(it->Data[0]);
     tmp.push_back(it->Data[1]);
     Require(CopyFromBack(sizeof(it->Data), tmp, sizeof(it->Data) * (count - 1)));
   }
   result.swap(tmp);
 }