Nugget
Loading...
Searching...
No Matches
hwregs.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2023 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::Hardware {
32
33enum class WriteQueue {
34 Use = true,
35 Bypass = false,
36};
37
38template <uint32_t offset, uint32_t BaseAddress, typename T>
40 static volatile T& access(int index = 0) { return *reinterpret_cast<volatile T*>(BaseAddress + offset + index); }
41 static volatile T* accessPtr(int index = 0) { return reinterpret_cast<volatile T*>(BaseAddress + offset + index); }
42};
43
44template <uint32_t offset, typename T = uint32_t, WriteQueue writeQueue = WriteQueue::Use,
45 typename Access = BasicAccess<offset, writeQueue == WriteQueue::Use ? 0x1f801000 : 0xbf801000, T>>
46struct Register {
47 static constexpr uint32_t BaseAddress = writeQueue == WriteQueue::Use ? 0x1f801000 : 0xbf801000;
48 void throwAway() const { *Access::accessPtr(); }
49 operator T() const { return access(); }
50 T operator=(T value) const {
51 access() = value;
52 return value;
53 }
54 T operator|=(T value) const {
55 T tmp = access();
56 tmp |= value;
57 access() = tmp;
58 return tmp;
59 }
60 T operator&=(T value) const {
61 T tmp = access();
62 tmp &= value;
63 access() = tmp;
64 return tmp;
65 }
66 T operator^=(T value) const {
67 T tmp = access();
68 tmp ^= value;
69 access() = tmp;
70 return tmp;
71 }
72 T operator++() const {
73 T tmp = access();
74 tmp++;
75 access() = tmp;
76 return tmp;
77 }
78 T operator++(int) const {
79 T tmp = access();
80 T ret = tmp;
81 tmp++;
82 access() = tmp;
83 return ret;
84 }
85 T operator--() const {
86 T tmp = access();
87 tmp--;
88 access() = tmp;
89 return tmp;
90 }
91 T operator--(int) const {
92 T tmp = access();
93 T ret = tmp;
94 tmp--;
95 access() = tmp;
96 return ret;
97 }
98 T operator+=(T value) const {
99 T tmp = access();
100 tmp += value;
101 access() = tmp;
102 return tmp;
103 }
104 T operator-=(T value) const {
105 T tmp = access();
106 tmp -= value;
107 access() = tmp;
108 return tmp;
109 }
110 T operator*=(T value) const {
111 T tmp = access();
112 tmp *= value;
113 access() = tmp;
114 return tmp;
115 }
116 T operator/=(T value) const {
117 T tmp = access();
118 tmp /= value;
119 access() = tmp;
120 return tmp;
121 }
122 T operator%=(T value) const {
123 T tmp = access();
124 tmp %= value;
125 access() = tmp;
126 return tmp;
127 }
128 T operator<<=(T value) const {
129 T tmp = access();
130 tmp <<= value;
131 access() = tmp;
132 return tmp;
133 }
134 T operator>>=(T value) const {
135 T tmp = access();
136 tmp >>= value;
137 access() = tmp;
138 return tmp;
139 }
140 T operator+(T value) const { return access() + value; }
141 T operator-(T value) const { return access() - value; }
142 T operator*(T value) const { return access() * value; }
143 T operator/(T value) const { return access() / value; }
144 T operator%(T value) const { return access() % value; }
145 T operator<<(T value) const { return access() << value; }
146 T operator>>(T value) const { return access() >> value; }
147 T operator&(T value) const { return access() & value; }
148 T operator|(T value) const { return access() | value; }
149 T operator^(T value) const { return access() ^ value; }
150 T operator~() const { return ~access(); }
151 T operator!() const { return !access(); }
152 T operator&&(T value) const { return access() && value; }
153 T operator||(T value) const { return access() || value; }
154 bool operator==(T value) const { return access() == value; }
155 bool operator!=(T value) const { return access() != value; }
156 bool operator<(T value) const { return access() < value; }
157 bool operator>(T value) const { return access() > value; }
158 bool operator<=(T value) const { return access() <= value; }
159 bool operator>=(T value) const { return access() >= value; }
160 T operator[](int index) const { return access(index); }
161
162 volatile T& access(int index = 0) const { return Access::access(index); }
163};
164
165} // namespace psyqo::Hardware
Definition cdrom.hh:31
WriteQueue
Definition hwregs.hh:33
Definition hwregs.hh:39
static volatile T & access(int index=0)
Definition hwregs.hh:40
static volatile T * accessPtr(int index=0)
Definition hwregs.hh:41
Definition hwregs.hh:46
T operator++(int) const
Definition hwregs.hh:78
T operator%=(T value) const
Definition hwregs.hh:122
bool operator<(T value) const
Definition hwregs.hh:156
T operator~() const
Definition hwregs.hh:150
T operator[](int index) const
Definition hwregs.hh:160
bool operator==(T value) const
Definition hwregs.hh:154
T operator=(T value) const
Definition hwregs.hh:50
T operator^=(T value) const
Definition hwregs.hh:66
T operator&=(T value) const
Definition hwregs.hh:60
bool operator>=(T value) const
Definition hwregs.hh:159
T operator^(T value) const
Definition hwregs.hh:149
bool operator<=(T value) const
Definition hwregs.hh:158
T operator+=(T value) const
Definition hwregs.hh:98
T operator&(T value) const
Definition hwregs.hh:147
static constexpr uint32_t BaseAddress
Definition hwregs.hh:47
T operator--() const
Definition hwregs.hh:85
T operator*(T value) const
Definition hwregs.hh:142
volatile T & access(int index=0) const
Definition hwregs.hh:162
T operator*=(T value) const
Definition hwregs.hh:110
T operator||(T value) const
Definition hwregs.hh:153
T operator|=(T value) const
Definition hwregs.hh:54
T operator--(int) const
Definition hwregs.hh:91
T operator/(T value) const
Definition hwregs.hh:143
bool operator!=(T value) const
Definition hwregs.hh:155
T operator<<(T value) const
Definition hwregs.hh:145
T operator/=(T value) const
Definition hwregs.hh:116
void throwAway() const
Definition hwregs.hh:48
T operator>>(T value) const
Definition hwregs.hh:146
T operator&&(T value) const
Definition hwregs.hh:152
T operator-=(T value) const
Definition hwregs.hh:104
T operator%(T value) const
Definition hwregs.hh:144
T operator+(T value) const
Definition hwregs.hh:140
T operator|(T value) const
Definition hwregs.hh:148
T operator++() const
Definition hwregs.hh:72
T operator!() const
Definition hwregs.hh:151
T operator-(T value) const
Definition hwregs.hh:141
T operator>>=(T value) const
Definition hwregs.hh:134
T operator<<=(T value) const
Definition hwregs.hh:128
bool operator>(T value) const
Definition hwregs.hh:157
static int value
Definition syscalls.h:534
static int ret
Definition syscalls.h:72
void uint32_t(classId, spec)