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 CARTRIDGE_CDF_HXX |
19 | #define CARTRIDGE_CDF_HXX |
20 | |
21 | class System; |
22 | class Thumbulator; |
23 | |
24 | #include "bspf.hxx" |
25 | #include "Cart.hxx" |
26 | |
27 | /** |
28 | Cartridge class used for CDF. |
29 | |
30 | There are seven 4K program banks, a 4K Display Data RAM, |
31 | 1K C Variable and Stack, and the CDF chip. |
32 | CDF chip access is mapped to $1000 - $103F (both read and write). |
33 | Program banks are accessible by read/write to $1FF5 - $1FFB. |
34 | |
35 | FIXME: THIS NEEDS TO BE UPDATED |
36 | |
37 | @authors: Darrell Spice Jr, Chris Walton, Fred Quimby, |
38 | Stephen Anthony, Bradford W. Mott |
39 | */ |
40 | class CartridgeCDF : public Cartridge |
41 | { |
42 | friend class CartridgeCDFWidget; |
43 | friend class CartridgeCDFInfoWidget; |
44 | friend class CartridgeRamCDFWidget; |
45 | |
46 | public: |
47 | |
48 | enum class CDFSubtype { |
49 | CDF0, |
50 | CDF1, |
51 | CDFJ |
52 | }; |
53 | |
54 | public: |
55 | /** |
56 | Create a new cartridge using the specified image |
57 | |
58 | @param image Pointer to the ROM image |
59 | @param size The size of the ROM image |
60 | @param md5 The md5sum of the ROM image |
61 | @param settings A reference to the various settings (read-only) |
62 | */ |
63 | CartridgeCDF(const ByteBuffer& image, size_t size, const string& md5, |
64 | const Settings& settings); |
65 | virtual ~CartridgeCDF() = default; |
66 | |
67 | public: |
68 | /** |
69 | Reset device to its power-on state |
70 | */ |
71 | void reset() override; |
72 | |
73 | /** |
74 | Notification method invoked by the system when the console type |
75 | has changed. We need this to inform the Thumbulator that the |
76 | timing has changed. |
77 | |
78 | @param timing Enum representing the new console type |
79 | */ |
80 | void consoleChanged(ConsoleTiming timing) override; |
81 | |
82 | /** |
83 | Install cartridge in the specified system. Invoked by the system |
84 | when the cartridge is attached to it. |
85 | |
86 | @param system The system the device should install itself in |
87 | */ |
88 | void install(System& system) override; |
89 | |
90 | /** |
91 | Install pages for the specified bank in the system. |
92 | |
93 | @param bank The bank that should be installed in the system |
94 | */ |
95 | bool bank(uInt16 bank) override; |
96 | |
97 | /** |
98 | Get the current bank. |
99 | |
100 | @param address The address to use when querying the bank |
101 | */ |
102 | uInt16 getBank(uInt16 address = 0) const override; |
103 | |
104 | /** |
105 | Query the number of banks supported by the cartridge. |
106 | */ |
107 | uInt16 bankCount() const override; |
108 | |
109 | /** |
110 | Patch the cartridge ROM. |
111 | |
112 | @param address The ROM address to patch |
113 | @param value The value to place into the address |
114 | @return Success or failure of the patch operation |
115 | */ |
116 | bool patch(uInt16 address, uInt8 value) override; |
117 | |
118 | /** |
119 | Access the internal ROM image for this cartridge. |
120 | |
121 | @param size Set to the size of the internal ROM image data |
122 | @return A pointer to the internal ROM image data |
123 | */ |
124 | const uInt8* getImage(size_t& size) const override; |
125 | |
126 | /** |
127 | Save the current state of this cart to the given Serializer. |
128 | |
129 | @param out The Serializer object to use |
130 | @return False on any errors, else true |
131 | */ |
132 | bool save(Serializer& out) const override; |
133 | |
134 | /** |
135 | Load the current state of this cart from the given Serializer. |
136 | |
137 | @param in The Serializer object to use |
138 | @return False on any errors, else true |
139 | */ |
140 | bool load(Serializer& in) override; |
141 | |
142 | /** |
143 | Get a descriptor for the device name (used in error checking). |
144 | |
145 | @return The name of the object |
146 | */ |
147 | string name() const override; |
148 | |
149 | /** |
150 | Used for Thumbulator to pass values back to the cartridge |
151 | */ |
152 | uInt32 thumbCallback(uInt8 function, uInt32 value1, uInt32 value2) override; |
153 | |
154 | #ifdef DEBUGGER_SUPPORT |
155 | /** |
156 | Get debugger widget responsible for accessing the inner workings |
157 | of the cart. |
158 | */ |
159 | CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont, |
160 | const GUI::Font& nfont, int x, int y, int w, int h) override; |
161 | CartDebugWidget* infoWidget(GuiObject* boss, const GUI::Font& lfont, |
162 | const GUI::Font& nfont, int x, int y, int w, int h) override; |
163 | #endif |
164 | |
165 | public: |
166 | /** |
167 | Get the byte at the specified address. |
168 | |
169 | @return The byte at the specified address |
170 | */ |
171 | uInt8 peek(uInt16 address) override; |
172 | |
173 | /** |
174 | Change the byte at the specified address to the given value |
175 | |
176 | @param address The address where the value should be stored |
177 | @param value The value to be stored at the address |
178 | @return True if the poke changed the device address space, else false |
179 | */ |
180 | bool poke(uInt16 address, uInt8 value) override; |
181 | |
182 | private: |
183 | /** |
184 | Sets the initial state of the DPC pointers and RAM |
185 | */ |
186 | void setInitialState(); |
187 | |
188 | /** |
189 | Updates any data fetchers in music mode based on the number of |
190 | CPU cycles which have passed since the last update. |
191 | */ |
192 | void updateMusicModeDataFetchers(); |
193 | |
194 | /** |
195 | Call Special Functions |
196 | */ |
197 | void callFunction(uInt8 value); |
198 | |
199 | uInt32 getDatastreamPointer(uInt8 index) const; |
200 | void setDatastreamPointer(uInt8 index, uInt32 value); |
201 | |
202 | uInt32 getDatastreamIncrement(uInt8 index) const; |
203 | void setDatastreamIncrement(uInt8 index, uInt32 value); |
204 | |
205 | uInt8 readFromDatastream(uInt8 index); |
206 | |
207 | uInt32 getWaveform(uInt8 index) const; |
208 | uInt32 getWaveformSize(uInt8 index) const; |
209 | uInt32 getSample(); |
210 | void setupVersion(); |
211 | |
212 | private: |
213 | // The 32K ROM image of the cartridge |
214 | std::array<uInt8, 32_KB> myImage; |
215 | |
216 | // Pointer to the 28K program ROM image of the cartridge |
217 | uInt8* myProgramImage; |
218 | |
219 | // Pointer to the 4K display ROM image of the cartridge |
220 | uInt8* myDisplayImage; |
221 | |
222 | // Pointer to the 2K CDF driver image in RAM |
223 | uInt8* myBusDriverImage; |
224 | |
225 | // The CDF 8k RAM image, used as: |
226 | // $0000 - 2K CDF driver |
227 | // $0800 - 4K Display Data |
228 | // $1800 - 2K C Variable & Stack |
229 | std::array<uInt8, 8_KB> myCDFRAM; |
230 | |
231 | // Pointer to the Thumb ARM emulator object |
232 | unique_ptr<Thumbulator> myThumbEmulator; |
233 | |
234 | // Indicates the offset into the ROM image (aligns to current bank) |
235 | uInt16 myBankOffset; |
236 | |
237 | // System cycle count from when the last update to music data fetchers occurred |
238 | uInt64 myAudioCycles; |
239 | |
240 | // ARM cycle count from when the last callFunction() occurred |
241 | uInt64 myARMCycles; |
242 | |
243 | // The audio routines in the driver run in 32-bit mode and take advantage |
244 | // of the FIQ Shadow Registers which are not accessible to 16-bit thumb |
245 | // code. As such, Thumbulator does not support them. The driver supplies a |
246 | // few 16-bit subroutines used to pass values from 16-bit to 32-bit. The |
247 | // Thumbulator will trap these calls and pass the appropriate information to |
248 | // the Cartridge Class via callFunction() so it can emulate the 32 bit audio routines. |
249 | |
250 | /* Register usage for audio: |
251 | r8 = channel0 accumulator |
252 | r9 = channel1 accumulator |
253 | r10 = channel2 accumulator |
254 | r11 = channel0 frequency |
255 | r12 = channel1 frequency |
256 | r13 = channel2 frequency |
257 | r14 = timer base */ |
258 | |
259 | // The music counters, ARM FIQ shadow registers r8, r9, r10 |
260 | std::array<uInt32, 3> myMusicCounters; |
261 | |
262 | // The music frequency, ARM FIQ shadow registers r11, r12, r13 |
263 | std::array<uInt32, 3> myMusicFrequencies; |
264 | |
265 | // The music waveform sizes |
266 | std::array<uInt8, 3> myMusicWaveformSize; |
267 | |
268 | // Fractional CDF music, OSC clocks unused during the last update |
269 | double myFractionalClocks; |
270 | |
271 | // Controls mode, lower nybble sets Fast Fetch, upper nybble sets audio |
272 | // -0 = Fast Fetch ON |
273 | // -F = Fast Fetch OFF |
274 | // 0- = Packed Digital Sample |
275 | // F- = 3 Voice Music |
276 | uInt8 myMode; |
277 | |
278 | // set to address of #value if last byte peeked was A9 (LDA #) |
279 | uInt16 myLDAimmediateOperandAddress; |
280 | |
281 | // set to address of the JMP operand if last byte peeked was 4C |
282 | // *and* the next two bytes in ROM are 00 00 |
283 | uInt16 myJMPoperandAddress; |
284 | |
285 | uInt8 myFastJumpActive; |
286 | |
287 | // Pointer to the array of datastream pointers |
288 | uInt16 myDatastreamBase; |
289 | |
290 | // Pointer to the array of datastream increments |
291 | uInt16 myDatastreamIncrementBase; |
292 | |
293 | // Pointer to the beginning of the waveform data block |
294 | uInt16 myWaveformBase; |
295 | |
296 | // Amplitude stream index |
297 | uInt8 myAmplitudeStream; |
298 | |
299 | // Mask for determining the index of the datastream during fastjump |
300 | uInt8 myFastjumpStreamIndexMask; |
301 | |
302 | // The currently selected fastjump stream |
303 | uInt8 myFastJumpStream; |
304 | |
305 | // CDF subtype |
306 | CDFSubtype myCDFSubtype; |
307 | |
308 | private: |
309 | // Following constructors and assignment operators not supported |
310 | CartridgeCDF() = delete; |
311 | CartridgeCDF(const CartridgeCDF&) = delete; |
312 | CartridgeCDF(CartridgeCDF&&) = delete; |
313 | CartridgeCDF& operator=(const CartridgeCDF&) = delete; |
314 | CartridgeCDF& operator=(CartridgeCDF&&) = delete; |
315 | }; |
316 | |
317 | #endif |
318 | |