1pub mod nes6502;
2
3pub use nes6502::Nes6502;
4
5#[derive(Debug, Clone, Copy, Default, PartialEq)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[cfg_attr(feature = "serde", serde(transparent))]
8#[repr(transparent)]
9pub struct Reg<T: Copy> {
10 inner: T,
11}
12
13macro_rules! default_impl {
14 ( $( $name:ident ),*) => {
15 $(impl $crate::chip::cpu::Reg<$name> {
16 pub fn inc(&mut self) {
17 self.inner = self.inner.wrapping_add(1)
18 }
19 pub fn dec(&mut self) {
20 self.inner = self.inner.wrapping_sub(1)
21 }
22 }
23 impl ::std::convert::From<$name> for $crate::chip::cpu::Reg<$name> {
24 fn from(value: $name) -> Self {
25 Self { inner: value }
26 }
27 }
28
29 impl ::std::ops::Deref for $crate::chip::cpu::Reg<$name> {
30 type Target = $name;
31
32 fn deref(&self) -> &Self::Target {
33 &self.inner
34 }
35 }
36
37 impl ::std::ops::Add for $crate::chip::cpu::Reg<$name> {
38 type Output = Self;
39
40 fn add(self, rhs: Self) -> Self::Output {
41 self.inner.wrapping_add(rhs.inner).into()
42 }
43 }
44
45 impl ::std::ops::Add<$name> for $crate::chip::cpu::Reg<$name> {
46 type Output = Self;
47
48 fn add(self, rhs: $name) -> Self::Output {
49 self.inner.wrapping_add(rhs).into()
50 }
51 }
52
53 impl ::std::ops::AddAssign<$name> for $crate::chip::cpu::Reg<$name> {
54 fn add_assign(&mut self, other: $name) {
55 self.inner = self.inner.wrapping_add(other)
56 }
57 }
58
59 impl ::std::ops::Sub for $crate::chip::cpu::Reg<$name> {
60 type Output = Self;
61
62 fn sub(self, rhs: Self) -> Self::Output {
63 self.inner.wrapping_sub(rhs.inner).into()
64 }
65 }
66
67 impl ::std::ops::Sub<$name> for $crate::chip::cpu::Reg<$name> {
68 type Output = Self;
69
70 fn sub(self, rhs: $name) -> Self::Output {
71 self.inner.wrapping_sub(rhs).into()
72 }
73 }
74
75 impl ::std::ops::SubAssign<$name> for $crate::chip::cpu::Reg<$name> {
76 fn sub_assign(&mut self, other: $name) {
77 self.inner = self.inner.wrapping_sub(other)
78 }
79 }
80
81 impl ::std::ops::BitAnd for $crate::chip::cpu::Reg<$name> {
82 type Output = Self;
83
84 fn bitand(mut self, rhs: Self) -> Self::Output {
85 self.inner &= rhs.inner;
86 self
87 }
88 }
89
90 impl ::std::ops::BitAnd<$name> for $crate::chip::cpu::Reg<$name> {
91 type Output = Self;
92
93 fn bitand(mut self, rhs: $name) -> Self::Output {
94 self.inner &= rhs;
95 self
96 }
97 }
98
99 impl ::std::ops::BitAndAssign<$name> for $crate::chip::cpu::Reg<$name> {
100 fn bitand_assign(&mut self, other: $name) {
101 self.inner = self.inner & other
102 }
103 }
104
105 impl ::std::ops::BitOr for $crate::chip::cpu::Reg<$name> {
106 type Output = Self;
107
108 fn bitor(mut self, rhs: Self) -> Self::Output {
109 self.inner |= rhs.inner;
110 self
111 }
112 }
113
114 impl ::std::ops::BitOr<$name> for $crate::chip::cpu::Reg<$name> {
115 type Output = Self;
116
117 fn bitor(mut self, rhs: $name) -> Self::Output {
118 self.inner |= rhs;
119 self
120 }
121 }
122
123 impl ::std::ops::BitOrAssign<$name> for $crate::chip::cpu::Reg<$name> {
124 fn bitor_assign(&mut self, other: $name) {
125 self.inner = self.inner | other
126 }
127 }
128
129 impl ::std::ops::BitXor for $crate::chip::cpu::Reg<$name> {
130 type Output = Self;
131
132 fn bitxor(mut self, rhs: Self) -> Self::Output {
133 self.inner ^= rhs.inner;
134 self
135 }
136 }
137
138 impl ::std::ops::BitXor<$name> for $crate::chip::cpu::Reg<$name> {
139 type Output = Self;
140
141 fn bitxor(mut self, rhs: $name) -> Self::Output {
142 self.inner ^= rhs;
143 self
144 }
145 }
146
147 impl ::std::ops::BitXorAssign<$name> for $crate::chip::cpu::Reg<$name> {
148 fn bitxor_assign(&mut self, other: $name) {
149 self.inner = self.inner ^ other
150 }
151 }
152
153 impl ::std::ops::Shl for $crate::chip::cpu::Reg<$name> {
154 type Output = Self;
155
156 fn shl(mut self, rhs: Self) -> Self::Output {
157 self.inner <<= rhs.inner;
158 self
159 }
160 }
161
162 impl ::std::ops::Shl<$name> for $crate::chip::cpu::Reg<$name> {
163 type Output = Self;
164
165 fn shl(mut self, rhs: $name) -> Self::Output {
166 self.inner <<= rhs;
167 self
168 }
169 }
170
171 impl ::std::ops::ShlAssign<$name> for $crate::chip::cpu::Reg<$name> {
172 fn shl_assign(&mut self, other: $name) {
173 self.inner = self.inner << other
174 }
175 }
176
177 impl ::std::ops::Shr for $crate::chip::cpu::Reg<$name> {
178 type Output = Self;
179
180 fn shr(mut self, rhs: Self) -> Self::Output {
181 self.inner >>= rhs.inner;
182 self
183 }
184 }
185
186 impl ::std::ops::Shr<$name> for $crate::chip::cpu::Reg<$name> {
187 type Output = Self;
188
189 fn shr(mut self, rhs: $name) -> Self::Output {
190 self.inner >>= rhs;
191 self
192 }
193 }
194
195 impl ::std::ops::ShrAssign<$name> for $crate::chip::cpu::Reg<$name> {
196 fn shr_assign(&mut self, other: $name) {
197 self.inner = self.inner >> other
198 }
199 }
200
201 impl ::std::cmp::PartialEq<$name> for $crate::chip::cpu::Reg<$name> {
202 fn eq(&self, other: &$name) -> bool {
203 self.inner.eq(other)
204 }
205 }
206
207 impl ::std::cmp::PartialOrd<$name> for $crate::chip::cpu::Reg<$name> {
208 fn partial_cmp(&self, other: &$name) -> ::std::option::Option<::std::cmp::Ordering> {
209 self.inner.partial_cmp(other)
210 }
211 }
212 )*
213 };
214}
215
216default_impl!(u8, u16);