Skip to content

Commit a5ad923

Browse files
authored
Merge pull request #1929 from nicolasnoble/tpage-getters-setters
Adding getters and setters to the TPage attribute.
2 parents dec9cd9 + d722aa3 commit a5ad923

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/mips/psyqo/primitives/common.hh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,34 @@ struct TexInfo {
142142
};
143143
static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");
144144

145+
struct TPageAttr;
146+
/**
147+
* @brief A primitive's tpage location.
148+
*
149+
* @details This represents the location of a texture page in the VRAM space, and is
150+
* used in the `TPageAttr` struct. This can be used to easily set the page location
151+
* in a primitive's attribute while keeping the other attributes intact.
152+
*/
153+
struct 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+
};
171+
static_assert(sizeof(TPageLoc) == sizeof(uint8_t), "TPageLoc is not 8 bits");
172+
145173
/**
146174
* @brief A primitive's tpage attribute.
147175
*
@@ -156,6 +184,21 @@ static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits");
156184
* as the compiler will better optimize the former sequence of operations.
157185
*/
158186
struct TPageAttr {
187+
TPageAttr() {}
188+
TPageAttr(TPageAttr&& other) : info(other.info) {}
189+
TPageAttr(const TPageAttr& other) : info(other.info) {}
190+
TPageAttr& operator=(TPageAttr&& other) {
191+
info = other.info;
192+
return *this;
193+
}
194+
TPageAttr& operator=(const TPageAttr& other) {
195+
info = other.info;
196+
return *this;
197+
}
198+
TPageAttr& copy(const TPageAttr& other) {
199+
info = other.info;
200+
return *this;
201+
}
159202
TPageAttr& setPageX(uint8_t x) {
160203
info &= ~0x000f;
161204
x &= 0x000f;
@@ -168,6 +211,11 @@ struct TPageAttr {
168211
info |= y << 4;
169212
return *this;
170213
}
214+
TPageAttr& setPageLoc(TPageLoc loc) {
215+
info &= ~0x001f;
216+
info |= loc.info;
217+
return *this;
218+
}
171219
TPageAttr& set(Prim::TPageAttr::SemiTrans trans) {
172220
info &= ~0x0060;
173221
uint32_t t = static_cast<uint32_t>(trans);
@@ -196,6 +244,17 @@ struct TPageAttr {
196244
info |= 0x0400;
197245
return *this;
198246
}
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; }
250+
Prim::TPageAttr::SemiTrans getSemiTrans() const {
251+
return static_cast<Prim::TPageAttr::SemiTrans>((info >> 5) & 0x0003);
252+
}
253+
Prim::TPageAttr::ColorMode getColorMode() const {
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; }
199258

200259
private:
201260
uint16_t info = 0;

0 commit comments

Comments
 (0)