-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBRHeader.cpp
More file actions
126 lines (105 loc) · 3.71 KB
/
BRHeader.cpp
File metadata and controls
126 lines (105 loc) · 3.71 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <memory.h>
#include "BRHeader.h"
#include "alignment.h"
//////////////////////////////////////////////////////////////////////////////
// Block Header
// Lengths
#define BRH__W_RSIZE_LEN sizeof (uint16_t)
#define BRH__W_RTYPE_LEN sizeof (uint16_t)
#define BRH__L_FLAGS_LEN sizeof (uint32_t)
#define BRH__V_BADDATA_LEN sizeof (uint8_t)
#define BRH__V_DIRECTORY_LEN sizeof (uint8_t)
#define BRH__V_NONSEQUENTIAL_LEN sizeof (uint8_t)
#define BRH__V_BLOCKERRS_LEN sizeof (uint8_t)
#define BRH__V_ALIAS_ENTRY_LEN sizeof (uint8_t)
#define BRH__V_HEADONLY_LEN sizeof (uint8_t)
#define BRH__L_ADDRESS_LEN sizeof (uint32_t)
#define BRH__W_BLOCKFLAGS_LEN sizeof (uint16_t)
#define BRH__W_RESERVED_LEN sizeof (uint16_t)
// Addresses
#define BRH__W_RSIZE_ADDR 0
#define BRH__W_RTYPE_ADDR (BRH__W_RSIZE_ADDR + BRH__W_RSIZE_LEN)
#define BRH__L_FLAGS_ADDR (BRH__W_RTYPE_ADDR + BRH__W_RTYPE_LEN)
#define BRH__V_BADDATA_ADDR BRH__L_FLAGS_ADDR
#define BRH__V_DIRECTORY_ADDR BRH__L_FLAGS_ADDR
#define BRH__V_NONSEQUENTIAL_ADDR BRH__L_FLAGS_ADDR
#define BRH__V_BLOCKERRS_ADDR BRH__L_FLAGS_ADDR
#define BRH__V_ALIAS_ENTRY_ADDR BRH__L_FLAGS_ADDR
#define BRH__V_HEADONLY_ADDR BRH__L_FLAGS_ADDR
#define BRH__L_ADDRESS_ADDR (BRH__L_FLAGS_ADDR + BRH__L_FLAGS_LEN)
#define BRH__W_BLOCKFLAGS_ADDR (BRH__L_ADDRESS_ADDR + BRH__L_ADDRESS_LEN)
#define BRH__W_RESERVED_ADDR (BRH__W_BLOCKFLAGS_ADDR + BRH__W_BLOCKFLAGS_LEN)
#define BRH__LENGTH (BRH__W_RESERVED_ADDR + BRH__W_RESERVED_LEN)
BRHeader::BRHeader ()
{
}
void BRHeader::Clean ()
{
delete (m_cBuffer);
}
void BRHeader::LoadBRHeader (uint8_t* cBuffer)
{
// Allocate the Char Buffer
m_cBuffer = new uint8_t[BRH__LENGTH];
// Map each data element
m_W_RSIZE = (uint16_t*) &m_cBuffer[BRH__W_RSIZE_ADDR];
m_W_RTYPE = (uint16_t*) &m_cBuffer[BRH__W_RTYPE_ADDR];
m_L_FLAGS = (uint32_t*) &m_cBuffer[BRH__L_FLAGS_ADDR];
m_V_BADDATA = (uint8_t*) &m_cBuffer[BRH__V_BADDATA_ADDR];
m_V_DIRECTORY = (uint8_t*) &m_cBuffer[BRH__V_DIRECTORY_ADDR];
m_V_NONSEQUENTIAL = (uint8_t*) &m_cBuffer[BRH__V_NONSEQUENTIAL_ADDR];
m_V_BLOCKERRS = (uint8_t*) &m_cBuffer[BRH__V_BLOCKERRS_ADDR];
m_V_ALIAS_ENTRY = (uint8_t*) &m_cBuffer[BRH__V_ALIAS_ENTRY_ADDR];
m_V_HEADONLY = (uint8_t*) &m_cBuffer[BRH__V_HEADONLY_ADDR];
m_L_ADDRESS = (uint32_t*) &m_cBuffer[BRH__L_ADDRESS_ADDR];
m_W_BLOCKFLAGS = (uint16_t*) &m_cBuffer[BRH__W_BLOCKFLAGS_ADDR];
memcpy (m_cBuffer, cBuffer, BRH__LENGTH * sizeof (uint8_t));
}
uint16_t BRHeader::W_RSIZE ()
{
return SWAPSHORT (*m_W_RSIZE);
}
uint16_t BRHeader::W_RTYPE ()
{
return SWAPSHORT (*m_W_RTYPE);
}
uint32_t BRHeader::L_FLAGS ()
{
return SWAPLONG (*m_L_FLAGS);
}
bool BRHeader::V_BADDATA ()
{
return (*m_V_BADDATA & 0x80) == 0x80;
}
bool BRHeader::V_DIRECTORY ()
{
return (*m_V_DIRECTORY & 0x40) == 0x40;
}
bool BRHeader::V_NONSEQUENTIAL ()
{
return (*m_V_NONSEQUENTIAL & 0x20) == 0x20;
}
bool BRHeader::V_BLOCKERRS ()
{
return (*m_V_BLOCKERRS & 0x10) == 0x10;
}
bool BRHeader::V_ALIAS_ENTRY ()
{
return (*m_V_ALIAS_ENTRY & 0x08) == 0x08;
}
bool BRHeader::V_HEADONLY ()
{
return (*m_V_HEADONLY & 0x04) == 0x04;
}
uint32_t BRHeader::L_ADDRESS ()
{
return SWAPLONG (*m_L_ADDRESS);
}
uint16_t BRHeader::W_BLOCKFLAGS ()
{
return SWAPSHORT (*m_W_BLOCKFLAGS);
}
uint32_t BRHeader::GetLength ()
{
return BRH__LENGTH;
}