Nugget
Loading...
Searching...
No Matches
common.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31namespace psyqo {
32
47union Vertex {
48 struct {
49 union {
50 int16_t x, u, s, w;
51 };
52 union {
53 int16_t y, v, t, h;
54 };
55 };
57};
58static_assert(sizeof(Vertex) == sizeof(uint32_t), "Vertex is not 32 bits");
59
74struct Rect {
75 union {
77 };
78 union {
80 };
81 bool isEmpty() { return (size.w == 0) && (size.h == 0); }
82};
83static_assert(sizeof(Rect) == sizeof(uint64_t), "Rect is not 64 bits");
84
91union Color {
92 struct {
93 uint8_t r, g, b, user;
94 };
96};
97static_assert(sizeof(Color) == sizeof(uint32_t), "Color is not 32 bits");
98
99namespace Prim::TPageAttr {
102} // namespace Prim::TPageAttr
103
104namespace Prim {
106}
107
108namespace PrimPieces {
109
121struct ClutIndex {
123 ClutIndex(Vertex v) : ClutIndex(v.x >> 4, v.y) {}
124 ClutIndex(uint16_t x, uint16_t y) : index((y << 6) | x) {}
125
126 private:
127 uint16_t index = 0;
128};
129static_assert(sizeof(ClutIndex) == sizeof(uint16_t), "ClutIndex is not 16 bits");
130
138struct alignas(uint32_t) TexInfo {
139 uint8_t u;
140 uint8_t v;
142};
143static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");
144static_assert(alignof(TexInfo) == alignof(uint32_t), "TexInfo is not 32-bit aligned");
145
146struct TPageAttr;
154struct TPageLoc {
155 TPageLoc& setPageX(uint8_t x) {
156 info &= ~0x000f;
157 x &= 0x000f;
158 info |= x;
159 return *this;
160 }
161 TPageLoc& setPageY(uint8_t y) {
162 info &= ~0x0010;
163 y &= 0x0001;
164 info |= y << 4;
165 return *this;
166 }
167
168 private:
169 TPageLoc(uint8_t i) : info(i) {}
170 uint8_t info = 0;
171 friend struct TPageAttr;
172};
173static_assert(sizeof(TPageLoc) == sizeof(uint8_t), "TPageLoc is not 8 bits");
174
188struct TPageAttr {
190 TPageAttr(TPageAttr&& other) : info(other.info) {}
191 TPageAttr(const TPageAttr& other) : info(other.info) {}
193 info = other.info;
194 return *this;
195 }
197 info = other.info;
198 return *this;
199 }
200 TPageAttr& copy(const TPageAttr& other) {
201 info = other.info;
202 return *this;
203 }
204 TPageAttr& setPageX(uint8_t x) {
205 info &= ~0x000f;
206 x &= 0x000f;
207 info |= x;
208 return *this;
209 }
210 TPageAttr& setPageY(uint8_t y) {
211 info &= ~0x0010;
212 y &= 0x0001;
213 info |= y << 4;
214 return *this;
215 }
217 info &= ~0x001f;
218 info |= loc.info;
219 return *this;
220 }
222 info &= ~0x0060;
223 uint32_t t = static_cast<uint32_t>(trans);
224 info |= t << 5;
225 return *this;
226 }
228 info &= ~0x0180;
229 uint32_t m = static_cast<uint32_t>(mode);
230 info |= m << 7;
231 return *this;
232 }
233 TPageAttr& setDithering(bool dithering) {
234 if (dithering) {
235 info |= 0x0200;
236 } else {
237 info &= ~0x0200;
238 }
239 return *this;
240 }
242 info &= ~0x0400;
243 return *this;
244 }
246 info |= 0x0400;
247 return *this;
248 }
249 uint8_t getPageX() const { return info & 0x000f; }
250 uint8_t getPageY() const { return (info >> 4) & 0x0001; }
251 TPageLoc getPageLoc() const { return TPageLoc(info & 0x001f); }
253 return static_cast<Prim::TPageAttr::SemiTrans>((info >> 5) & 0x0003);
254 }
256 return static_cast<Prim::TPageAttr::ColorMode>((info >> 7) & 0x0003);
257 }
258 bool hasDithering() const { return (info & 0x0200) != 0; }
259 bool isDisplayAreaEnabled() const { return (info & 0x0400) != 0; }
260
261 private:
262 uint16_t info = 0;
263};
264static_assert(sizeof(TPageAttr) == sizeof(uint16_t), "TPageAttr is not 16 bits");
265
271struct alignas(uint32_t) PageInfo {
272 uint8_t u;
273 uint8_t v;
275};
276static_assert(sizeof(PageInfo) == sizeof(uint32_t), "PageInfo is not 32 bits");
277static_assert(alignof(PageInfo) == alignof(uint32_t), "PageInfo is not 32-bit aligned");
278
284struct UVCoords {
285 uint8_t u;
286 uint8_t v;
287};
288static_assert(sizeof(UVCoords) == sizeof(uint16_t), "UVCoords is not 16 bits");
289
296 uint8_t u;
297 uint8_t v;
298 uint16_t user;
299};
300static_assert(sizeof(UVCoordsPadded) == sizeof(uint32_t), "UVCoordsPadded is not 32 bits");
301
302} // namespace PrimPieces
303
304} // namespace psyqo
uint32_t t
Definition cop0.c:79
int i
Definition gte-regio.c:287
ColorMode
Definition common.hh:101
@ Tex16Bits
Definition common.hh:101
@ Tex4Bits
Definition common.hh:101
@ Tex8Bits
Definition common.hh:101
SemiTrans
Definition common.hh:100
@ HalfBackAndHalfFront
Definition common.hh:100
@ FullBackAndFullFront
Definition common.hh:100
@ FullBackSubFullFront
Definition common.hh:100
@ FullBackAndQuarterFront
Definition common.hh:100
Transparency
Definition common.hh:105
Definition lua.hh:38
A primitive's CLUT command.
Definition common.hh:121
ClutIndex(Vertex v)
Definition common.hh:123
ClutIndex()
Definition common.hh:122
ClutIndex(uint16_t x, uint16_t y)
Definition common.hh:124
A primitive's page info attribute.
Definition common.hh:271
TPageAttr attr
Definition common.hh:274
uint8_t u
Definition common.hh:272
uint8_t v
Definition common.hh:273
A primitive's tpage attribute.
Definition common.hh:188
TPageAttr(TPageAttr &&other)
Definition common.hh:190
TPageAttr & enableDisplayArea()
Definition common.hh:245
uint8_t getPageY() const
Definition common.hh:250
bool isDisplayAreaEnabled() const
Definition common.hh:259
TPageAttr(const TPageAttr &other)
Definition common.hh:191
TPageLoc getPageLoc() const
Definition common.hh:251
TPageAttr & disableDisplayArea()
Definition common.hh:241
TPageAttr & set(Prim::TPageAttr::ColorMode mode)
Definition common.hh:227
bool hasDithering() const
Definition common.hh:258
TPageAttr & setPageLoc(TPageLoc loc)
Definition common.hh:216
Prim::TPageAttr::ColorMode getColorMode() const
Definition common.hh:255
Prim::TPageAttr::SemiTrans getSemiTrans() const
Definition common.hh:252
TPageAttr()
Definition common.hh:189
TPageAttr & operator=(TPageAttr &&other)
Definition common.hh:192
TPageAttr & copy(const TPageAttr &other)
Definition common.hh:200
TPageAttr & setPageY(uint8_t y)
Definition common.hh:210
uint8_t getPageX() const
Definition common.hh:249
TPageAttr & operator=(const TPageAttr &other)
Definition common.hh:196
TPageAttr & set(Prim::TPageAttr::SemiTrans trans)
Definition common.hh:221
TPageAttr & setPageX(uint8_t x)
Definition common.hh:204
TPageAttr & setDithering(bool dithering)
Definition common.hh:233
A primitive's tpage location.
Definition common.hh:154
TPageLoc & setPageY(uint8_t y)
Definition common.hh:161
TPageLoc & setPageX(uint8_t x)
Definition common.hh:155
A primitive's texture information.
Definition common.hh:138
uint8_t v
Definition common.hh:140
ClutIndex clut
Definition common.hh:141
uint8_t u
Definition common.hh:139
A primitive's UV coordinates attribute.
Definition common.hh:295
uint8_t v
Definition common.hh:297
uint8_t u
Definition common.hh:296
uint16_t user
Definition common.hh:298
A primitive's UV coordinates attribute.
Definition common.hh:284
uint8_t u
Definition common.hh:285
uint8_t v
Definition common.hh:286
The Rect struct.
Definition common.hh:74
Vertex size
Definition common.hh:79
Vertex b
Definition common.hh:79
Vertex a
Definition common.hh:76
Vertex pos
Definition common.hh:76
bool isEmpty()
Definition common.hh:81
Definition xprintf.c:112
static void uint32_t mode
Definition syscalls.h:231
void uint32_t(classId, spec)
The Color struct.
Definition common.hh:91
uint8_t user
Definition common.hh:93
uint8_t g
Definition common.hh:93
uint8_t b
Definition common.hh:93
uint32_t packed
Definition common.hh:95
uint8_t r
Definition common.hh:93
The Vertex struct.
Definition common.hh:47
int16_t h
Definition common.hh:53
int16_t y
Definition common.hh:53
int16_t t
Definition common.hh:53
int16_t s
Definition common.hh:50
int16_t v
Definition common.hh:53
int16_t x
Definition common.hh:50
int16_t u
Definition common.hh:50
int16_t w
Definition common.hh:50
uint32_t packed
Definition common.hh:56