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