| 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 CARTRIDGEF8_HXX | 
|---|
| 19 | #define CARTRIDGEF8_HXX | 
|---|
| 20 |  | 
|---|
| 21 | class System; | 
|---|
| 22 |  | 
|---|
| 23 | #include "bspf.hxx" | 
|---|
| 24 | #include "Cart.hxx" | 
|---|
| 25 | #ifdef DEBUGGER_SUPPORT | 
|---|
| 26 | #include "CartF8Widget.hxx" | 
|---|
| 27 | #endif | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 | Cartridge class used for Atari's 8K bankswitched games.  There are two | 
|---|
| 31 | 4K banks, accessible by read/write to $1FF8 - $1FF9. | 
|---|
| 32 |  | 
|---|
| 33 | @author  Bradford W. Mott | 
|---|
| 34 | */ | 
|---|
| 35 | class CartridgeF8 : public Cartridge | 
|---|
| 36 | { | 
|---|
| 37 | friend class CartridgeF8Widget; | 
|---|
| 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 | CartridgeF8(const ByteBuffer& image, size_t size, const string& md5, | 
|---|
| 49 | const Settings& settings); | 
|---|
| 50 | virtual ~CartridgeF8() = 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 "CartridgeF8"; } | 
|---|
| 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 CartridgeF8Widget(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 | private: | 
|---|
| 162 | // Following constructors and assignment operators not supported | 
|---|
| 163 | CartridgeF8() = delete; | 
|---|
| 164 | CartridgeF8(const CartridgeF8&) = delete; | 
|---|
| 165 | CartridgeF8(CartridgeF8&&) = delete; | 
|---|
| 166 | CartridgeF8& operator=(const CartridgeF8&) = delete; | 
|---|
| 167 | CartridgeF8& operator=(CartridgeF8&&) = delete; | 
|---|
| 168 | }; | 
|---|
| 169 |  | 
|---|
| 170 | #endif | 
|---|
| 171 |  | 
|---|