1 | //============================================================================ |
2 | // |
3 | // MM MM 6666 555555 0000 2222 |
4 | // MMMM MMMM 66 66 55 00 00 22 22 |
5 | // MM MMM MM 66 55 00 00 22 |
6 | // MM M MM 66666 55555 00 00 22222 -- "A 6502 Microprocessor Emulator" |
7 | // MM MM 66 66 55 00 00 22 |
8 | // MM MM 66 66 55 55 00 00 22 |
9 | // MM MM 6666 5555 0000 222222 |
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 | #ifndef DISPATCH_RESULT_HXX |
19 | #define DISPATCH_RESULT_HXX |
20 | |
21 | #include "bspf.hxx" |
22 | |
23 | class DispatchResult |
24 | { |
25 | public: |
26 | enum class Status { invalid, ok, debugger, fatal }; |
27 | |
28 | public: |
29 | |
30 | DispatchResult() |
31 | : myStatus(Status::invalid), myCycles(0), myAddress(0), myWasReadTrap(false) { } |
32 | |
33 | Status getStatus() const { return myStatus; } |
34 | |
35 | uInt64 getCycles() const { return myCycles; } |
36 | |
37 | const string& getMessage() const { assertStatus(Status::debugger, Status::fatal); return myMessage; } |
38 | |
39 | int getAddress() const { assertStatus(Status::debugger); return myAddress; } |
40 | |
41 | bool wasReadTrap() const { assertStatus(Status::debugger); return myWasReadTrap; } |
42 | |
43 | bool isSuccess() const; |
44 | |
45 | void setOk(uInt64 cycles); |
46 | |
47 | void setDebugger(uInt64 cycles, const string& message = "" , int address = -1, bool wasReadTrap = true); |
48 | |
49 | void setFatal(uInt64 cycles); |
50 | |
51 | void setMessage(const string& message); |
52 | |
53 | private: |
54 | |
55 | void assertStatus(Status status) const |
56 | { |
57 | if (myStatus != status) throw runtime_error("invalid status for operation" ); |
58 | } |
59 | |
60 | template<class ...Ts> void assertStatus(Status status, Ts... more) const |
61 | { |
62 | if (myStatus == status) return; |
63 | |
64 | assertStatus(more...); |
65 | } |
66 | |
67 | private: |
68 | |
69 | Status myStatus; |
70 | |
71 | uInt64 myCycles; |
72 | |
73 | string myMessage; |
74 | |
75 | int myAddress; |
76 | |
77 | bool myWasReadTrap; |
78 | }; |
79 | |
80 | #endif // DISPATCH_RESULT_HXX |
81 | |