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