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 DEVICE_HXX |
19 | #define DEVICE_HXX |
20 | |
21 | class System; |
22 | |
23 | #include "Console.hxx" |
24 | #include "Serializable.hxx" |
25 | #include "bspf.hxx" |
26 | |
27 | /** |
28 | Abstract base class for devices which can be attached to a 6502 |
29 | based system. |
30 | |
31 | @author Bradford W. Mott |
32 | */ |
33 | class Device : public Serializable |
34 | { |
35 | public: |
36 | Device() : mySystem(nullptr) { } |
37 | virtual ~Device() = default; |
38 | |
39 | public: |
40 | /** |
41 | Reset device to its power-on state. |
42 | |
43 | *DO NOT* call this method until the device has been attached to |
44 | the System. In fact, it should never be necessary to call this |
45 | method directly at all. |
46 | */ |
47 | virtual void reset() = 0; |
48 | |
49 | /** |
50 | Notification method invoked by the system when the console type |
51 | has changed. It may be necessary to override this method for |
52 | devices that want to know about console changes. |
53 | |
54 | @param timing Enum representing the new console type |
55 | */ |
56 | virtual void consoleChanged(ConsoleTiming timing) { } |
57 | |
58 | /** |
59 | Install device in the specified system. Invoked by the system |
60 | when the device is attached to it. |
61 | |
62 | @param system The system the device should install itself in |
63 | */ |
64 | virtual void install(System& system) = 0; |
65 | |
66 | /** |
67 | Save the current state of this device to the given Serializer. |
68 | |
69 | @param out The Serializer object to use |
70 | @return False on any errors, else true |
71 | */ |
72 | virtual bool save(Serializer& out) const override = 0; |
73 | |
74 | /** |
75 | Load the current state of this device from the given Serializer. |
76 | |
77 | @param in The Serializer object to use |
78 | @return False on any errors, else true |
79 | */ |
80 | virtual bool load(Serializer& in) override = 0; |
81 | |
82 | public: |
83 | /** |
84 | Get the byte at the specified address |
85 | |
86 | @return The byte at the specified address |
87 | */ |
88 | virtual uInt8 peek(uInt16 address) = 0; |
89 | |
90 | /** |
91 | Change the byte at the specified address to the given value |
92 | |
93 | @param address The address where the value should be stored |
94 | @param value The value to be stored at the address |
95 | |
96 | @return True if the poke changed the device address space, else false |
97 | */ |
98 | virtual bool poke(uInt16 address, uInt8 value) { return false; } |
99 | |
100 | /** |
101 | Query the given address for its disassembly flags |
102 | |
103 | @param address The address to modify |
104 | */ |
105 | virtual uInt8 getAccessFlags(uInt16 address) const { return 0; } |
106 | |
107 | /** |
108 | Change the given address type to use the given disassembly flags |
109 | |
110 | @param address The address to modify |
111 | @param flags A bitfield of DisasmType directives for the given address |
112 | */ |
113 | virtual void setAccessFlags(uInt16 address, uInt8 flags) { } |
114 | |
115 | protected: |
116 | /// Pointer to the system the device is installed in or the null pointer |
117 | System* mySystem; |
118 | |
119 | private: |
120 | // Following constructors and assignment operators not supported |
121 | Device(const Device&) = delete; |
122 | Device(Device&&) = delete; |
123 | Device& operator=(const Device&) = delete; |
124 | Device& operator=(Device&&) = delete; |
125 | }; |
126 | |
127 | #endif |
128 | |