-
Notifications
You must be signed in to change notification settings - Fork 1
/
txbiterator.cpp
49 lines (43 loc) · 1.33 KB
/
txbiterator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//===----------------------------------------------------------------------===//
//
// The Descent map loader
//
// NAME : TxbReaderIterator
// PURPOSE : Providing an iterator over text in aDescent .TXB format.
// COPYRIGHT : (c) 2011 Sean Donnellan. All Rights Reserved.
// AUTHORS : Sean Donnellan ([email protected])
// DESCRIPTION : A decoder for the TXB file format that is used by Parallax
// Software in the computer game, Descent.
//
// The file format is as follows:
//
// A byte value of 0xA is a LF and for the game would be converted to CR LF.
// Other bytes are rotated by 2 bits to the left (so the most significant bits
// then it is XORed with 0xA7.
//
//===----------------------------------------------------------------------===//
#include "txbiterator.hpp"
char TxbReaderIterator::CurrentValue() const
{
if (*mySource == 0x0A)
{
return 0x0A;
}
return (((*mySource & 0x3F) << 2) + ((*mySource & 0xC0) >> 6)) ^ 0xA7;
}
TxbReaderIterator::TxbReaderIterator(const uint8_t* Source)
: mySource(Source), myValue(CurrentValue())
{
}
TxbReaderIterator& TxbReaderIterator::operator++()
{
myValue = CurrentValue();
mySource++;
return *this;
}
TxbReaderIterator TxbReaderIterator::operator++(int)
{
TxbReaderIterator previous = *this;
++(*this);
return previous;
}