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
158struct TPageAttr {
159 TPageAttr& setPageX(uint8_t x) {
160 info &= ~0x000f;
161 x &= 0x000f;
162 info |= x;
163 return *this;
164 }
165 TPageAttr& setPageY(uint8_t y) {
166 info &= ~0x0010;
167 y &= 0x0001;
168 info |= y << 4;
169 return *this;
170 }
172 info &= ~0x0060;
173 uint32_t t = static_cast<uint32_t>(trans);
174 info |= t << 5;
175 return *this;
176 }
178 info &= ~0x0180;
179 uint32_t m = static_cast<uint32_t>(mode);
180 info |= m << 7;
181 return *this;
182 }
183 TPageAttr& setDithering(bool dithering) {
184 if (dithering) {
185 info |= 0x0200;
186 } else {
187 info &= ~0x0200;
188 }
189 return *this;
190 }
192 info &= ~0x0400;
193 return *this;
194 }
196 info |= 0x0400;
197 return *this;
198 }
199
200 private:
201 uint16_t info = 0;
202};
203static_assert(sizeof(TPageAttr) == sizeof(uint16_t), "TPageAttr is not 16 bits");
204
210struct PageInfo {
211 uint8_t u;
212 uint8_t v;
214};
215static_assert(sizeof(PageInfo) == sizeof(uint32_t), "PageInfo is not 32 bits");
216
222struct UVCoords {
223 uint8_t u;
224 uint8_t v;
225};
226static_assert(sizeof(UVCoords) == sizeof(uint16_t), "UVCoords is not 16 bits");
227
234 uint8_t u;
235 uint8_t v;
236 uint16_t user;
237};
238static_assert(sizeof(UVCoordsPadded) == sizeof(uint32_t), "UVCoordsPadded is not 32 bits");
239
240} // namespace PrimPieces
241
242} // 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 cdrom-loader.hh:39
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:210
TPageAttr attr
Definition common.hh:213
uint8_t u
Definition common.hh:211
uint8_t v
Definition common.hh:212
A primitive's tpage attribute.
Definition common.hh:158
TPageAttr & enableDisplayArea()
Definition common.hh:195
TPageAttr & disableDisplayArea()
Definition common.hh:191
TPageAttr & set(Prim::TPageAttr::ColorMode mode)
Definition common.hh:177
TPageAttr & setPageY(uint8_t y)
Definition common.hh:165
TPageAttr & set(Prim::TPageAttr::SemiTrans trans)
Definition common.hh:171
TPageAttr & setPageX(uint8_t x)
Definition common.hh:159
TPageAttr & setDithering(bool dithering)
Definition common.hh:183
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:233
uint8_t v
Definition common.hh:235
uint8_t u
Definition common.hh:234
uint16_t user
Definition common.hh:236
A primitive's UV coordinates attribute.
Definition common.hh:222
uint8_t u
Definition common.hh:223
uint8_t v
Definition common.hh:224
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