summaryrefslogtreecommitdiff
path: root/src/video_core/regs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/regs.h')
-rw-r--r--src/video_core/regs.h68
1 files changed, 23 insertions, 45 deletions
diff --git a/src/video_core/regs.h b/src/video_core/regs.h
index f25edde27..86826088b 100644
--- a/src/video_core/regs.h
+++ b/src/video_core/regs.h
@@ -45,46 +45,31 @@ namespace Pica {
45#endif // _MSC_VER 45#endif // _MSC_VER
46 46
47struct Regs { 47struct Regs {
48 INSERT_PADDING_WORDS(0x10); 48 static constexpr size_t NUM_REGS = 0x300;
49 u32 trigger_irq; 49
50 INSERT_PADDING_WORDS(0x2f); 50 union {
51 RasterizerRegs rasterizer; 51 struct {
52 TexturingRegs texturing; 52 INSERT_PADDING_WORDS(0x10);
53 FramebufferRegs framebuffer; 53 u32 trigger_irq;
54 LightingRegs lighting; 54 INSERT_PADDING_WORDS(0x2f);
55 PipelineRegs pipeline; 55 RasterizerRegs rasterizer;
56 ShaderRegs gs; 56 TexturingRegs texturing;
57 ShaderRegs vs; 57 FramebufferRegs framebuffer;
58 INSERT_PADDING_WORDS(0x20); 58 LightingRegs lighting;
59 59 PipelineRegs pipeline;
60 // Map register indices to names readable by humans 60 ShaderRegs gs;
61 // Used for debugging purposes, so performance is not an issue here 61 ShaderRegs vs;
62 static std::string GetCommandName(int index); 62 INSERT_PADDING_WORDS(0x20);
63 63 };
64 static constexpr size_t NumIds() { 64 std::array<u32, NUM_REGS> reg_array;
65 return sizeof(Regs) / sizeof(u32); 65 };
66 } 66
67 67 /// Map register indices to names readable by humans
68 const u32& operator[](int index) const { 68 static const char* GetRegisterName(u16 index);
69 const u32* content = reinterpret_cast<const u32*>(this);
70 return content[index];
71 }
72
73 u32& operator[](int index) {
74 u32* content = reinterpret_cast<u32*>(this);
75 return content[index];
76 }
77
78private:
79 /*
80 * Most physical addresses which Pica registers refer to are 8-byte aligned.
81 * This function should be used to get the address from a raw register value.
82 */
83 static inline u32 DecodeAddressRegister(u32 register_value) {
84 return register_value * 8;
85 }
86}; 69};
87 70
71static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "Regs struct has wrong size");
72
88// TODO: MSVC does not support using offsetof() on non-static data members even though this 73// TODO: MSVC does not support using offsetof() on non-static data members even though this
89// is technically allowed since C++11. This macro should be enabled once MSVC adds 74// is technically allowed since C++11. This macro should be enabled once MSVC adds
90// support for that. 75// support for that.
@@ -154,11 +139,4 @@ ASSERT_REG_POSITION(vs, 0x2b0);
154#undef ASSERT_REG_POSITION 139#undef ASSERT_REG_POSITION
155#endif // !defined(_MSC_VER) 140#endif // !defined(_MSC_VER)
156 141
157// The total number of registers is chosen arbitrarily, but let's make sure it's not some odd value
158// anyway.
159static_assert(sizeof(Regs) <= 0x300 * sizeof(u32),
160 "Register set structure larger than it should be");
161static_assert(sizeof(Regs) >= 0x300 * sizeof(u32),
162 "Register set structure smaller than it should be");
163
164} // namespace Pica 142} // namespace Pica