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 TexInfo {
139 uint8_t u;
140 uint8_t v;
142};
143static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");
144
145struct TPageAttr;
153struct TPageLoc {
154 TPageLoc& setPageX(uint8_t x) {
155 info &= ~0x000f;
156 x &= 0x000f;
157 info |= x;
158 return *this;
159 }
160 TPageLoc& setPageY(uint8_t y) {
161 info &= ~0x0010;
162 y &= 0x0001;
163 info |= y << 4;
164 return *this;
165 }
166
167 private:
168 TPageLoc(uint8_t i) : info(i) {}
169 uint8_t info = 0;
170 friend struct TPageAttr;
171};
172static_assert(sizeof(TPageLoc) == sizeof(uint8_t), "TPageLoc is not 8 bits");
173
187struct TPageAttr {
189 TPageAttr(TPageAttr&& other) : info(other.info) {}
190 TPageAttr(const TPageAttr& other) : info(other.info) {}
192 info = other.info;
193 return *this;
194 }
196 info = other.info;
197 return *this;
198 }
199 TPageAttr& copy(const TPageAttr& other) {
200 info = other.info;
201 return *this;
202 }
203 TPageAttr& setPageX(uint8_t x) {
204 info &= ~0x000f;
205 x &= 0x000f;
206 info |= x;
207 return *this;
208 }
209 TPageAttr& setPageY(uint8_t y) {
210 info &= ~0x0010;
211 y &= 0x0001;
212 info |= y << 4;
213 return *this;
214 }
216 info &= ~0x001f;
217 info |= loc.info;
218 return *this;
219 }
221 info &= ~0x0060;
222 uint32_t t = static_cast<uint32_t>(trans);
223 info |= t << 5;
224 return *this;
225 }
227 info &= ~0x0180;
228 uint32_t m = static_cast<uint32_t>(mode);
229 info |= m << 7;
230 return *this;
231 }
232 TPageAttr& setDithering(bool dithering) {
233 if (dithering) {
234 info |= 0x0200;
235 } else {
236 info &= ~0x0200;
237 }
238 return *this;
239 }
241 info &= ~0x0400;
242 return *this;
243 }
245 info |= 0x0400;
246 return *this;
247 }
248 uint8_t getPageX() const { return info & 0x000f; }
249 uint8_t getPageY() const { return (info >> 4) & 0x0001; }
250 TPageLoc getPageLoc() const { return TPageLoc(info & 0x001f); }
252 return static_cast<Prim::TPageAttr::SemiTrans>((info >> 5) & 0x0003);
253 }
255 return static_cast<Prim::TPageAttr::ColorMode>((info >> 7) & 0x0003);
256 }
257 bool hasDithering() const { return (info & 0x0200) != 0; }
258 bool isDisplayAreaEnabled() const { return (info & 0x0400) != 0; }
259
260 private:
261 uint16_t info = 0;
262};
263static_assert(sizeof(TPageAttr) == sizeof(uint16_t), "TPageAttr is not 16 bits");
264
270struct PageInfo {
271 uint8_t u;
272 uint8_t v;
274};
275static_assert(sizeof(PageInfo) == sizeof(uint32_t), "PageInfo is not 32 bits");
276
282struct UVCoords {
283 uint8_t u;
284 uint8_t v;
285};
286static_assert(sizeof(UVCoords) == sizeof(uint16_t), "UVCoords is not 16 bits");
287
294 uint8_t u;
295 uint8_t v;
296 uint16_t user;
297};
298static_assert(sizeof(UVCoordsPadded) == sizeof(uint32_t), "UVCoordsPadded is not 32 bits");
299
300} // namespace PrimPieces
301
302} // namespace psyqo
uint32_t t
Definition cop0.c:79
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:270
TPageAttr attr
Definition common.hh:273
uint8_t u
Definition common.hh:271
uint8_t v
Definition common.hh:272
A primitive's tpage attribute.
Definition common.hh:187
TPageAttr(TPageAttr &&other)
Definition common.hh:189
TPageAttr & enableDisplayArea()
Definition common.hh:244
uint8_t getPageY() const
Definition common.hh:249
bool isDisplayAreaEnabled() const
Definition common.hh:258
TPageAttr(const TPageAttr &other)
Definition common.hh:190
TPageLoc getPageLoc() const
Definition common.hh:250
TPageAttr & disableDisplayArea()
Definition common.hh:240
TPageAttr & set(Prim::TPageAttr::ColorMode mode)
Definition common.hh:226
bool hasDithering() const
Definition common.hh:257
TPageAttr & setPageLoc(TPageLoc loc)
Definition common.hh:215
Prim::TPageAttr::ColorMode getColorMode() const
Definition common.hh:254
Prim::TPageAttr::SemiTrans getSemiTrans() const
Definition common.hh:251
TPageAttr()
Definition common.hh:188
TPageAttr & operator=(TPageAttr &&other)
Definition common.hh:191
TPageAttr & copy(const TPageAttr &other)
Definition common.hh:199
TPageAttr & setPageY(uint8_t y)
Definition common.hh:209
uint8_t getPageX() const
Definition common.hh:248
TPageAttr & operator=(const TPageAttr &other)
Definition common.hh:195
TPageAttr & set(Prim::TPageAttr::SemiTrans trans)
Definition common.hh:220
TPageAttr & setPageX(uint8_t x)
Definition common.hh:203
TPageAttr & setDithering(bool dithering)
Definition common.hh:232
A primitive's tpage location.
Definition common.hh:153
TPageLoc & setPageY(uint8_t y)
Definition common.hh:160
TPageLoc & setPageX(uint8_t x)
Definition common.hh:154
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:293
uint8_t v
Definition common.hh:295
uint8_t u
Definition common.hh:294
uint16_t user
Definition common.hh:296
A primitive's UV coordinates attribute.
Definition common.hh:282
uint8_t u
Definition common.hh:283
uint8_t v
Definition common.hh:284
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:230
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