| 1 | //============================================================================ |
|---|---|
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #include <sstream> |
| 19 | |
| 20 | #include "M6502.hxx" |
| 21 | #include "System.hxx" |
| 22 | #include "Debugger.hxx" |
| 23 | #include "CartDebug.hxx" |
| 24 | #include "TIADebug.hxx" |
| 25 | |
| 26 | #include "CpuDebug.hxx" |
| 27 | |
| 28 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 29 | CpuDebug::CpuDebug(Debugger& dbg, Console& console) |
| 30 | : DebuggerSystem(dbg, console), |
| 31 | my6502(mySystem.m6502()) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 36 | const DebuggerState& CpuDebug::getState() |
| 37 | { |
| 38 | myState.PC = my6502.PC; |
| 39 | myState.SP = my6502.SP; |
| 40 | myState.PS = my6502.PS(); |
| 41 | myState.A = my6502.A; |
| 42 | myState.X = my6502.X; |
| 43 | myState.Y = my6502.Y; |
| 44 | |
| 45 | myState.srcS = my6502.lastSrcAddressS(); |
| 46 | myState.srcA = my6502.lastSrcAddressA(); |
| 47 | myState.srcX = my6502.lastSrcAddressX(); |
| 48 | myState.srcY = my6502.lastSrcAddressY(); |
| 49 | |
| 50 | Debugger::set_bits(myState.PS, myState.PSbits); |
| 51 | |
| 52 | return myState; |
| 53 | } |
| 54 | |
| 55 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 56 | void CpuDebug::saveOldState() |
| 57 | { |
| 58 | myOldState.PC = my6502.PC; |
| 59 | myOldState.SP = my6502.SP; |
| 60 | myOldState.PS = my6502.PS(); |
| 61 | myOldState.A = my6502.A; |
| 62 | myOldState.X = my6502.X; |
| 63 | myOldState.Y = my6502.Y; |
| 64 | |
| 65 | myOldState.srcS = my6502.lastSrcAddressS(); |
| 66 | myOldState.srcA = my6502.lastSrcAddressA(); |
| 67 | myOldState.srcX = my6502.lastSrcAddressX(); |
| 68 | myOldState.srcY = my6502.lastSrcAddressY(); |
| 69 | |
| 70 | Debugger::set_bits(myOldState.PS, myOldState.PSbits); |
| 71 | } |
| 72 | |
| 73 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 74 | int CpuDebug::pc() const |
| 75 | { |
| 76 | return mySystem.m6502().PC; |
| 77 | } |
| 78 | |
| 79 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 80 | int CpuDebug::sp() const |
| 81 | { |
| 82 | return mySystem.m6502().SP; |
| 83 | } |
| 84 | |
| 85 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 86 | int CpuDebug::a() const |
| 87 | { |
| 88 | return mySystem.m6502().A; |
| 89 | } |
| 90 | |
| 91 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 92 | int CpuDebug::x() const |
| 93 | { |
| 94 | return mySystem.m6502().X; |
| 95 | } |
| 96 | |
| 97 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 98 | int CpuDebug::y() const |
| 99 | { |
| 100 | return mySystem.m6502().Y; |
| 101 | } |
| 102 | |
| 103 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 104 | int CpuDebug::n() const |
| 105 | { |
| 106 | return mySystem.m6502().N; |
| 107 | } |
| 108 | |
| 109 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 110 | int CpuDebug::v() const |
| 111 | { |
| 112 | return mySystem.m6502().V; |
| 113 | } |
| 114 | |
| 115 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 116 | int CpuDebug::b() const |
| 117 | { |
| 118 | return mySystem.m6502().B; |
| 119 | } |
| 120 | |
| 121 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 122 | int CpuDebug::d() const |
| 123 | { |
| 124 | return mySystem.m6502().D; |
| 125 | } |
| 126 | |
| 127 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 128 | int CpuDebug::i() const |
| 129 | { |
| 130 | return mySystem.m6502().I; |
| 131 | } |
| 132 | |
| 133 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 134 | int CpuDebug::z() const |
| 135 | { |
| 136 | return !mySystem.m6502().notZ; |
| 137 | } |
| 138 | |
| 139 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 140 | int CpuDebug::c() const |
| 141 | { |
| 142 | return mySystem.m6502().C; |
| 143 | } |
| 144 | |
| 145 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 146 | int CpuDebug::icycles() const |
| 147 | { |
| 148 | return mySystem.m6502().icycles; |
| 149 | } |
| 150 | |
| 151 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 152 | void CpuDebug::setPC(int pc) |
| 153 | { |
| 154 | my6502.PC = uInt16(pc); |
| 155 | } |
| 156 | |
| 157 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 158 | void CpuDebug::setSP(int sp) |
| 159 | { |
| 160 | my6502.SP = uInt8(sp); |
| 161 | } |
| 162 | |
| 163 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 164 | void CpuDebug::setPS(int ps) |
| 165 | { |
| 166 | my6502.PS(ps); |
| 167 | } |
| 168 | |
| 169 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 170 | void CpuDebug::setA(int a) |
| 171 | { |
| 172 | my6502.A = uInt8(a); |
| 173 | } |
| 174 | |
| 175 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 176 | void CpuDebug::setX(int x) |
| 177 | { |
| 178 | my6502.X = uInt8(x); |
| 179 | } |
| 180 | |
| 181 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 182 | void CpuDebug::setY(int y) |
| 183 | { |
| 184 | my6502.Y = uInt8(y); |
| 185 | } |
| 186 | |
| 187 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 188 | void CpuDebug::setN(bool on) |
| 189 | { |
| 190 | my6502.N = on; |
| 191 | } |
| 192 | |
| 193 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 194 | void CpuDebug::setV(bool on) |
| 195 | { |
| 196 | my6502.V = on; |
| 197 | } |
| 198 | |
| 199 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 200 | void CpuDebug::setB(bool) |
| 201 | { |
| 202 | // nop - B is always true |
| 203 | } |
| 204 | |
| 205 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 206 | void CpuDebug::setD(bool on) |
| 207 | { |
| 208 | my6502.D = on; |
| 209 | } |
| 210 | |
| 211 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 212 | void CpuDebug::setI(bool on) |
| 213 | { |
| 214 | my6502.I = on; |
| 215 | } |
| 216 | |
| 217 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 218 | void CpuDebug::setZ(bool on) |
| 219 | { |
| 220 | my6502.notZ = !on; |
| 221 | } |
| 222 | |
| 223 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 224 | void CpuDebug::setC(bool on) |
| 225 | { |
| 226 | my6502.C = on; |
| 227 | } |
| 228 | |
| 229 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 230 | void CpuDebug::setCycles(int cycles) |
| 231 | { |
| 232 | my6502.icycles = cycles; |
| 233 | } |
| 234 | |
| 235 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 236 | void CpuDebug::toggleN() |
| 237 | { |
| 238 | my6502.N = !my6502.N; |
| 239 | } |
| 240 | |
| 241 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 242 | void CpuDebug::toggleV() |
| 243 | { |
| 244 | my6502.V = !my6502.V; |
| 245 | } |
| 246 | |
| 247 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 248 | void CpuDebug::toggleB() |
| 249 | { |
| 250 | // nop - B is always true |
| 251 | } |
| 252 | |
| 253 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 254 | void CpuDebug::toggleD() |
| 255 | { |
| 256 | my6502.D = !my6502.D; |
| 257 | } |
| 258 | |
| 259 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 260 | void CpuDebug::toggleI() |
| 261 | { |
| 262 | my6502.I = !my6502.I; |
| 263 | } |
| 264 | |
| 265 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 266 | void CpuDebug::toggleZ() |
| 267 | { |
| 268 | my6502.notZ = !my6502.notZ; |
| 269 | } |
| 270 | |
| 271 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 272 | void CpuDebug::toggleC() |
| 273 | { |
| 274 | my6502.C = !my6502.C; |
| 275 | } |
| 276 |