-
-
Notifications
You must be signed in to change notification settings - Fork 124
Adding getters and setters to the TPage attribute. #1929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolasnoble
merged 1 commit into
grumpycoders:main
from
nicolasnoble:tpage-getters-setters
May 18, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -142,6 +142,34 @@ struct TexInfo { | |||||||||||
}; | ||||||||||||
static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits"); | ||||||||||||
|
||||||||||||
struct TPageAttr; | ||||||||||||
/** | ||||||||||||
* @brief A primitive's tpage location. | ||||||||||||
* | ||||||||||||
* @details This represents the location of a texture page in the VRAM space, and is | ||||||||||||
* used in the `TPageAttr` struct. This can be used to easily set the page location | ||||||||||||
* in a primitive's attribute while keeping the other attributes intact. | ||||||||||||
*/ | ||||||||||||
struct TPageLoc { | ||||||||||||
TPageLoc& setPageX(uint8_t x) { | ||||||||||||
info &= ~0x000f; | ||||||||||||
x &= 0x000f; | ||||||||||||
info |= x; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
TPageLoc& setPageY(uint8_t y) { | ||||||||||||
info &= ~0x0010; | ||||||||||||
y &= 0x0001; | ||||||||||||
info |= y << 4; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
private: | ||||||||||||
uint8_t info = 0; | ||||||||||||
friend struct TPageAttr; | ||||||||||||
}; | ||||||||||||
static_assert(sizeof(TPageLoc) == sizeof(uint8_t), "TPageLoc is not 8 bits"); | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* @brief A primitive's tpage attribute. | ||||||||||||
* | ||||||||||||
|
@@ -156,6 +184,21 @@ static_assert(sizeof(TexInfo) == sizeof(uint32_t), "TexInfo is not 32 bits"); | |||||||||||
* as the compiler will better optimize the former sequence of operations. | ||||||||||||
*/ | ||||||||||||
struct TPageAttr { | ||||||||||||
TPageAttr() {} | ||||||||||||
TPageAttr(TPageAttr&& other) : info(other.info) {} | ||||||||||||
TPageAttr(const TPageAttr& other) : info(other.info) {} | ||||||||||||
TPageAttr& operator=(TPageAttr&& other) { | ||||||||||||
info = other.info; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
TPageAttr& operator=(const TPageAttr& other) { | ||||||||||||
info = other.info; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
TPageAttr& copy(const TPageAttr& other) { | ||||||||||||
info = other.info; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
Comment on lines
+198
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The copy() method in TPageAttr is redundant since the copy assignment operator already handles member-wise copying. Consider removing it to reduce duplication and simplify maintenance.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
TPageAttr& setPageX(uint8_t x) { | ||||||||||||
info &= ~0x000f; | ||||||||||||
x &= 0x000f; | ||||||||||||
|
@@ -168,6 +211,11 @@ struct TPageAttr { | |||||||||||
info |= y << 4; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
TPageAttr& setPageLoc(TPageLoc loc) { | ||||||||||||
info &= ~0x001f; | ||||||||||||
info |= loc.info; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
TPageAttr& set(Prim::TPageAttr::SemiTrans trans) { | ||||||||||||
info &= ~0x0060; | ||||||||||||
uint32_t t = static_cast<uint32_t>(trans); | ||||||||||||
|
@@ -196,6 +244,17 @@ struct TPageAttr { | |||||||||||
info |= 0x0400; | ||||||||||||
return *this; | ||||||||||||
} | ||||||||||||
uint8_t getPageX() const { return info & 0x000f; } | ||||||||||||
uint8_t getPageY() const { return (info >> 4) & 0x0001; } | ||||||||||||
uint8_t getPageLoc() const { return info & 0x001f; } | ||||||||||||
Prim::TPageAttr::SemiTrans getSemiTrans() const { | ||||||||||||
return static_cast<Prim::TPageAttr::SemiTrans>((info >> 5) & 0x0003); | ||||||||||||
} | ||||||||||||
Prim::TPageAttr::ColorMode getColorMode() const { | ||||||||||||
return static_cast<Prim::TPageAttr::ColorMode>((info >> 7) & 0x0003); | ||||||||||||
} | ||||||||||||
bool hasDithering() const { return (info & 0x0200) != 0; } | ||||||||||||
bool isDisplayAreaEnabled() const { return (info & 0x0400) != 0; } | ||||||||||||
|
||||||||||||
private: | ||||||||||||
uint16_t info = 0; | ||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Since the default constructor and the copy/move operators perform only trivial member-wise operations, you could consider using the default implementations (i.e., '= default') to reduce boilerplate code.
Copilot uses AI. Check for mistakes.