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 | #ifndef CARTRIDGEX07_HXX |
19 | #define CARTRIDGEX07_HXX |
20 | |
21 | class System; |
22 | |
23 | #include "bspf.hxx" |
24 | #include "Cart.hxx" |
25 | #ifdef DEBUGGER_SUPPORT |
26 | #include "CartX07Widget.hxx" |
27 | #endif |
28 | |
29 | /** |
30 | Bankswitching method as defined/created by John Payson (aka Supercat) |
31 | and Fred Quimby (aka batari). |
32 | |
33 | This bankswitching method has 16 4K banks that can be accessed at |
34 | addresses $1000 to $1FFF. The bankswitching hotspots are all below |
35 | $1000. X07 uses two types of hotspots: |
36 | |
37 | 0 1xxx nnnn 1101 -- Switch to bank nnnn |
38 | 0 0xxx 0nxx xxxx -- If in bank 111x, switch to bank 111n. |
39 | In any other bank, do not switch. |
40 | |
41 | Note that the latter will hit on almost any TIA access. |
42 | |
43 | @author Eckhard Stolberg |
44 | */ |
45 | class CartridgeX07 : public Cartridge |
46 | { |
47 | friend class CartridgeX07Widget; |
48 | |
49 | public: |
50 | /** |
51 | Create a new cartridge using the specified image |
52 | |
53 | @param image Pointer to the ROM image |
54 | @param size The size of the ROM image |
55 | @param md5 The md5sum of the ROM image |
56 | @param settings A reference to the various settings (read-only) |
57 | */ |
58 | CartridgeX07(const ByteBuffer& image, size_t size, const string& md5, |
59 | const Settings& settings); |
60 | virtual ~CartridgeX07() = default; |
61 | |
62 | public: |
63 | /** |
64 | Reset device to its power-on state |
65 | */ |
66 | void reset() override; |
67 | |
68 | /** |
69 | Install cartridge in the specified system. Invoked by the system |
70 | when the cartridge is attached to it. |
71 | |
72 | @param system The system the device should install itself in |
73 | */ |
74 | void install(System& system) override; |
75 | |
76 | /** |
77 | Install pages for the specified bank in the system. |
78 | |
79 | @param bank The bank that should be installed in the system |
80 | */ |
81 | bool bank(uInt16 bank) override; |
82 | |
83 | /** |
84 | Get the current bank. |
85 | |
86 | @param address The address to use when querying the bank |
87 | */ |
88 | uInt16 getBank(uInt16 address = 0) const override; |
89 | |
90 | /** |
91 | Query the number of banks supported by the cartridge. |
92 | */ |
93 | uInt16 bankCount() const override; |
94 | |
95 | /** |
96 | Patch the cartridge ROM. |
97 | |
98 | @param address The ROM address to patch |
99 | @param value The value to place into the address |
100 | @return Success or failure of the patch operation |
101 | */ |
102 | bool patch(uInt16 address, uInt8 value) override; |
103 | |
104 | /** |
105 | Access the internal ROM image for this cartridge. |
106 | |
107 | @param size Set to the size of the internal ROM image data |
108 | @return A pointer to the internal ROM image data |
109 | */ |
110 | const uInt8* getImage(size_t& size) const override; |
111 | |
112 | /** |
113 | Save the current state of this cart to the given Serializer. |
114 | |
115 | @param out The Serializer object to use |
116 | @return False on any errors, else true |
117 | */ |
118 | bool save(Serializer& out) const override; |
119 | |
120 | /** |
121 | Load the current state of this cart from the given Serializer. |
122 | |
123 | @param in The Serializer object to use |
124 | @return False on any errors, else true |
125 | */ |
126 | bool load(Serializer& in) override; |
127 | |
128 | /** |
129 | Get a descriptor for the device name (used in error checking). |
130 | |
131 | @return The name of the object |
132 | */ |
133 | string name() const override { return "CartridgeX07" ; } |
134 | |
135 | #ifdef DEBUGGER_SUPPORT |
136 | /** |
137 | Get debugger widget responsible for accessing the inner workings |
138 | of the cart. |
139 | */ |
140 | CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont, |
141 | const GUI::Font& nfont, int x, int y, int w, int h) override |
142 | { |
143 | return new CartridgeX07Widget(boss, lfont, nfont, x, y, w, h, *this); |
144 | } |
145 | #endif |
146 | |
147 | public: |
148 | /** |
149 | Get the byte at the specified address. |
150 | |
151 | @return The byte at the specified address |
152 | */ |
153 | uInt8 peek(uInt16 address) override; |
154 | |
155 | /** |
156 | Change the byte at the specified address to the given value |
157 | |
158 | @param address The address where the value should be stored |
159 | @param value The value to be stored at the address |
160 | @return True if the poke changed the device address space, else false |
161 | */ |
162 | bool poke(uInt16 address, uInt8 value) override; |
163 | |
164 | private: |
165 | // The 64K ROM image of the cartridge |
166 | std::array<uInt8, 64_KB> myImage; |
167 | |
168 | // Indicates which bank is currently active |
169 | uInt16 myCurrentBank; |
170 | |
171 | private: |
172 | // Following constructors and assignment operators not supported |
173 | CartridgeX07() = delete; |
174 | CartridgeX07(const CartridgeX07&) = delete; |
175 | CartridgeX07(CartridgeX07&&) = delete; |
176 | CartridgeX07& operator=(const CartridgeX07&) = delete; |
177 | CartridgeX07& operator=(CartridgeX07&&) = delete; |
178 | }; |
179 | |
180 | #endif |
181 | |