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