forked from dolphin-emu/fifoplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDffFile.h
209 lines (178 loc) · 3.67 KB
/
DffFile.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef FIFOPLAYER_DFFFILE_H
#define FIFOPLAYER_DFFFILE_H
#include "CommonTypes.h"
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#else // asumming libogc
#include <gctypes.h>
#endif
#if BYTE_ORDER==BIG_ENDIAN
static uint64_t le64toh(uint64_t val)
{
return ((val&0xff)<<56)|((val&0xff00)<<40)|((val&0xff0000)<<24)|((val&0xff000000)<<8) |
((val&0xff00000000)>>8)|((val&0xff0000000000)>>24)|((val&0xff000000000000)>>40)|((val&0xff00000000000000)>>56);
}
static uint32_t le32toh(uint32_t val)
{
return ((val&0xff)<<24)|((val&0xff00)<<8)|((val&0xff0000)>>8)|((val&0xff000000)>>24);
}
static uint32_t h32tole(uint32_t val)
{
return le32toh(val);
}
static uint16_t le16toh(uint16_t val)
{
return ((val&0xff)<<8)|((val&0xff00)>>8);
}
static uint32_t h16tole(uint32_t val)
{
return le16toh(val);
}
static uint64_t be64toh(uint64_t val)
{
return val;
}
static uint32_t be32toh(uint32_t val)
{
return val;
}
static uint16_t be16toh(uint16_t val)
{
return val;
}
#elif BYTE_ORDER==LITTLE_ENDIAN
// endian.h should have taken care of defining these...
#endif
#pragma pack(push, 4)
union DffFileHeader {
struct {
// Version 1 data
u32 fileId;
u32 file_version;
u32 min_loader_version;
u64 bpMemOffset;
u32 bpMemSize;
u64 cpMemOffset;
u32 cpMemSize;
u64 xfMemOffset;
u32 xfMemSize;
u64 xfRegsOffset;
u32 xfRegsSize;
u64 frameListOffset;
u32 frameCount;
u32 flags;
// Version 2 data
u32 viMemOffset;
u32 viMemSize;
};
u32 rawData[32];
void FixEndianness()
{
fileId = le32toh(fileId);
file_version = le32toh(file_version);
min_loader_version = le32toh(min_loader_version);
bpMemOffset = le64toh(bpMemOffset);
bpMemSize = le32toh(bpMemSize);
cpMemOffset = le64toh(cpMemOffset);
cpMemSize = le32toh(cpMemSize);
xfMemOffset = le64toh(xfMemOffset);
xfMemSize = le32toh(xfMemSize);
xfRegsOffset = le64toh(xfRegsOffset);
xfRegsSize = le32toh(xfRegsSize);
frameListOffset = le64toh(frameListOffset);
frameCount = le32toh(frameCount);
flags = le32toh(flags);
viMemOffset = le32toh(viMemOffset);
viMemSize = le32toh(viMemSize);
}
};
union DffFrameInfo
{
struct
{
// Version 1 data
u64 fifoDataOffset;
u32 fifoDataSize;
u32 fifoStart;
u32 fifoEnd;
u64 memoryUpdatesOffset;
u32 numMemoryUpdates;
// Version 2 data
u64 asyncEventsOffset;
u32 numAsyncEvents;
};
u32 rawData[16];
void FixEndianness()
{
fifoDataOffset = le64toh(fifoDataOffset);
fifoDataSize = le32toh(fifoDataSize);
fifoStart = le32toh(fifoStart);
fifoEnd = le32toh(fifoEnd);
memoryUpdatesOffset = le64toh(memoryUpdatesOffset);
numMemoryUpdates = le32toh(numMemoryUpdates);
asyncEventsOffset = le64toh(asyncEventsOffset);
numAsyncEvents = le32toh(numAsyncEvents);
}
};
struct DffMemoryUpdate
{
enum Type
{
TEXTURE_MAP = 0x01,
XF_DATA = 0x02,
VERTEX_STREAM = 0x04,
TMEM = 0x08,
};
u32 fifoPosition;
u32 address;
u64 dataOffset;
u32 dataSize;
u8 type;
void FixEndianness()
{
fifoPosition = le32toh(fifoPosition);
address = le32toh(address);
dataOffset = le64toh(dataOffset);
dataSize = le32toh(dataSize);
}
};
struct DffAsyncEvent
{
enum Type
{
VI_WRITE16 = 0x00,
VI_WRITE32 = 0x01,
};
u32 fifoPosition;
u8 type;
union
{
struct
{
u32 addr;
u16 data;
} vi_write16;
struct
{
u32 addr;
u32 data;
} vi_write32;
u32 data[2];
};
void FixEndianness()
{
fifoPosition = le32toh(fifoPosition);
if (type == VI_WRITE16)
{
vi_write16.addr = le32toh(vi_write16.addr);
vi_write16.data = le16toh(vi_write16.data);
}
else if (type == VI_WRITE32)
{
vi_write32.addr = le32toh(vi_write32.addr);
vi_write32.data = le32toh(vi_write32.data);
}
}
};
#pragma pack(pop)
#endif // FIFOPLAYER_DFFFILE_H