Bitstream Interpretation Library (BIL)  0.1
V5CfgTileMapEntry.cpp
Go to the documentation of this file.
1 
10 
11 using namespace bil;
12 
13 
15 {
16  lowerHalf = false;
17  rowIndex = 0;
18  columnIndex = 0;
19  frameBeginIndex = 1;
20  frameEndIndex = 0;
21  wordBeginOffset = 1;
22  wordEndOffset = 0;
23 }
24 
25 
27 {
28  // calculate the amount of referenced words
29  if (where.wordEndOffset < where.wordBeginOffset) return 0;
30  size_t wordsPerFrame = (where.wordEndOffset - where.wordBeginOffset) + 1;
31  if (where.frameEndIndex < where.frameBeginIndex) return 0;
32  size_t frameCount = (where.frameEndIndex - where.frameBeginIndex) + 1;
33  return frameCount * wordsPerFrame;
34 }
35 
36 
37 size_t bil::getCfgData(boost::uint32_t* data, size_t dataWordCount,
38  const V5Configuration& src, const V5CfgTileMapEntry& where)
39 {
40  // get begin address of frame range
41  V5FrameAddress address(&(src.addressLayout()));
43  address.lowerHalf(where.lowerHalf);
44  address.rowIndex(where.rowIndex);
45  address.columnIndex(where.columnIndex);
46  address.frameIndex(where.frameBeginIndex);
47 
48  // get end address of frame range
49  V5FrameAddress endAdddress = address;
50  endAdddress.frameIndex(where.frameEndIndex);
51 
52  // get begin and end word offset
53  size_t wordOffset = where.wordBeginOffset;
54  if (V5CfgFrame::WORDCOUNT <= wordOffset) throw Exception();
55  size_t wordEndOffset = where.wordEndOffset;
56  if (V5CfgFrame::WORDCOUNT <= wordEndOffset) throw Exception();
57  if (wordEndOffset < wordOffset) return 0;
58 
59  // loop over all frames in designated range
60  boost::uint32_t* dataStart = data;
61  boost::uint32_t* dataEnd = data + dataWordCount;
62  while (address <= endAdddress)
63  {
64  // get frame at current address
65  const V5CfgFrame* frame = src.lookup(address);
66  if (0 == frame) throw Exception();
67 
68  // get pointers to designated range of data words
69  const boost::uint32_t* frameData = frame->data();
70  const boost::uint32_t* frameDataEnd = frameData + wordEndOffset;
71  frameData += wordOffset;
72 
73  // copy range
74  while (frameData <= frameDataEnd)
75  {
76  if (data >= dataEnd) throw Exception();
77  *(data++) = *(frameData++);
78  }
79 
80  // advance to next frame address
81  address.next();
82  }
83 
84  // return count of extracted words
85  return (data - dataStart);
86 }