Nugget
psyqo
primitives
common.hh
1
/*
2
3
MIT License
4
5
Copyright (c) 2022 PCSX-Redux authors
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in all
15
copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
SOFTWARE.
24
25
*/
26
27
#pragma once
28
29
#include <stdint.h>
30
31
namespace
psyqo {
32
47
union
Vertex
{
48
struct
{
49
union
{
50
int16_t x, u, s, w;
51
};
52
union
{
53
int16_t y, v, t, h;
54
};
55
};
56
int32_t packed;
57
};
58
static_assert(
sizeof
(
Vertex
) ==
sizeof
(uint32_t),
"Vertex is not 32 bits"
);
59
74
struct
Rect
{
75
union
{
76
Vertex
a, pos;
77
};
78
union
{
79
Vertex
b, size;
80
};
81
bool
isEmpty() {
return
(size.w == 0) && (size.h == 0); }
82
};
83
static_assert(
sizeof
(
Rect
) ==
sizeof
(uint64_t),
"Rect is not 64 bits"
);
84
91
union
Color
{
92
struct
{
93
uint8_t r, g, b;
94
};
95
uint32_t packed;
96
};
97
static_assert(
sizeof
(
Color
) ==
sizeof
(uint32_t),
"Color is not 32 bits"
);
98
99
namespace
Prim {
100
112
struct
ClutIndex
{
113
ClutIndex
() {}
114
ClutIndex
(
Vertex
v) :
ClutIndex
(v.x >> 4, v.y) {}
115
ClutIndex
(uint16_t x, uint16_t y) : index((y << 6) | x) {}
116
117
private
:
118
uint16_t index = 0;
119
};
120
static_assert(
sizeof
(
ClutIndex
) ==
sizeof
(uint16_t),
"ClutIndex is not 16 bits"
);
121
129
struct
TexInfo
{
130
uint8_t u;
131
uint8_t v;
132
ClutIndex
clut;
133
};
134
static_assert(
sizeof
(
TexInfo
) ==
sizeof
(uint32_t),
"TexInfo is not 32 bits"
);
135
149
struct
TPageAttr
{
150
TPageAttr
& setPageX(uint8_t x) {
151
info
&= ~0x000f;
152
x &= 0x000f;
153
info
|= x;
154
return
*
this
;
155
}
156
TPageAttr
& setPageY(uint8_t y) {
157
info
&= ~0x0010;
158
y &= 0x0001;
159
info
|= y << 4;
160
return
*
this
;
161
}
162
enum
SemiTrans { HalfBackAndHalfFront, FullBackAndFullFront, FullBackSubFullFront, FullBackAndQuarterFront };
163
TPageAttr
& set(SemiTrans trans) {
164
info
&= ~0x0060;
165
uint32_t t =
static_cast<
uint32_t
>
(trans);
166
info
|= t << 5;
167
return
*
this
;
168
}
169
enum
ColorMode { Tex4Bits, Tex8Bits, Tex16Bits };
170
TPageAttr
& set(ColorMode mode) {
171
info
&= ~0x0180;
172
uint32_t m =
static_cast<
uint32_t
>
(mode);
173
info
|= m << 7;
174
return
*
this
;
175
}
176
TPageAttr
& setDithering(
bool
dithering) {
177
if
(dithering) {
178
info
|= 0x0200;
179
}
else
{
180
info
&= ~0x0200;
181
}
182
return
*
this
;
183
}
184
TPageAttr
& disableDisplayArea() {
185
info
&= ~0x0400;
186
return
*
this
;
187
}
188
TPageAttr
& enableDisplayArea() {
189
info
|= 0x0400;
190
return
*
this
;
191
}
192
193
private
:
194
uint16_t
info
= 0;
195
};
196
static_assert(
sizeof
(
TPageAttr
) ==
sizeof
(uint16_t),
"TPageAttr is not 16 bits"
);
197
203
struct
PageInfo
{
204
uint8_t u;
205
uint8_t v;
206
TPageAttr
attr;
207
};
208
static_assert(
sizeof
(
PageInfo
) ==
sizeof
(uint32_t),
"PageInfo is not 32 bits"
);
209
215
struct
UVCoords
{
216
uint8_t u;
217
uint8_t v;
218
};
219
static_assert(
sizeof
(
UVCoords
) ==
sizeof
(uint16_t),
"UVCoords is not 16 bits"
);
220
226
struct
UVCoordsPadded
{
227
uint8_t u;
228
uint8_t v;
229
230
private
:
231
uint16_t padding;
232
};
233
static_assert(
sizeof
(
UVCoordsPadded
) ==
sizeof
(uint32_t),
"UVCoordsPadded is not 32 bits"
);
234
235
}
// namespace Prim
236
237
}
// namespace psyqo
psyqo::Prim::ClutIndex
A primitive's CLUT command.
Definition:
common.hh:112
psyqo::Prim::PageInfo
A primitive's page info attribute.
Definition:
common.hh:203
psyqo::Prim::TPageAttr
A primitive's tpage attribute.
Definition:
common.hh:149
psyqo::Prim::TexInfo
A primitive's texture information.
Definition:
common.hh:129
psyqo::Prim::UVCoordsPadded
A primitive's UV coordinates attribute.
Definition:
common.hh:226
psyqo::Prim::UVCoords
A primitive's UV coordinates attribute.
Definition:
common.hh:215
psyqo::Rect
The Rect struct.
Definition:
common.hh:74
s_info
Definition:
xprintf.c:115
psyqo::Color
The Color struct.
Definition:
common.hh:91
psyqo::Vertex
The Vertex struct.
Definition:
common.hh:47
Generated by
1.9.1