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