| 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 CARTRIDGE4K_HXX | 
|---|
| 19 | #define CARTRIDGE4K_HXX | 
|---|
| 20 |  | 
|---|
| 21 | class System; | 
|---|
| 22 |  | 
|---|
| 23 | #include "bspf.hxx" | 
|---|
| 24 | #include "Cart.hxx" | 
|---|
| 25 | #ifdef DEBUGGER_SUPPORT | 
|---|
| 26 | #include "Cart4KWidget.hxx" | 
|---|
| 27 | #endif | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 | This is the standard Atari 4K cartridge.  These cartridges are | 
|---|
| 31 | not bankswitched. | 
|---|
| 32 |  | 
|---|
| 33 | @author  Bradford W. Mott | 
|---|
| 34 | */ | 
|---|
| 35 | class Cartridge4K : public Cartridge | 
|---|
| 36 | { | 
|---|
| 37 | friend class Cartridge4KWidget; | 
|---|
| 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 | Cartridge4K(const ByteBuffer& image, size_t size, const string& md5, | 
|---|
| 49 | const Settings& settings); | 
|---|
| 50 | virtual ~Cartridge4K() = default; | 
|---|
| 51 |  | 
|---|
| 52 | public: | 
|---|
| 53 | /** | 
|---|
| 54 | Reset cartridge 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 | Patch the cartridge ROM. | 
|---|
| 68 |  | 
|---|
| 69 | @param address  The ROM address to patch | 
|---|
| 70 | @param value    The value to place into the address | 
|---|
| 71 | @return    Success or failure of the patch operation | 
|---|
| 72 | */ | 
|---|
| 73 | bool patch(uInt16 address, uInt8 value) override; | 
|---|
| 74 |  | 
|---|
| 75 | /** | 
|---|
| 76 | Access the internal ROM image for this cartridge. | 
|---|
| 77 |  | 
|---|
| 78 | @param size  Set to the size of the internal ROM image data | 
|---|
| 79 | @return  A pointer to the internal ROM image data | 
|---|
| 80 | */ | 
|---|
| 81 | const uInt8* getImage(size_t& size) const override; | 
|---|
| 82 |  | 
|---|
| 83 | /** | 
|---|
| 84 | Save the current state of this cart to the given Serializer. | 
|---|
| 85 |  | 
|---|
| 86 | @param out  The Serializer object to use | 
|---|
| 87 | @return  False on any errors, else true | 
|---|
| 88 | */ | 
|---|
| 89 | bool save(Serializer& out) const override { return true; } | 
|---|
| 90 |  | 
|---|
| 91 | /** | 
|---|
| 92 | Load the current state of this cart from the given Serializer. | 
|---|
| 93 |  | 
|---|
| 94 | @param in  The Serializer object to use | 
|---|
| 95 | @return  False on any errors, else true | 
|---|
| 96 | */ | 
|---|
| 97 | bool load(Serializer& in) override { return true; } | 
|---|
| 98 |  | 
|---|
| 99 | /** | 
|---|
| 100 | Get a descriptor for the device name (used in error checking). | 
|---|
| 101 |  | 
|---|
| 102 | @return The name of the object | 
|---|
| 103 | */ | 
|---|
| 104 | string name() const override { return "Cartridge4K"; } | 
|---|
| 105 |  | 
|---|
| 106 | #ifdef DEBUGGER_SUPPORT | 
|---|
| 107 | /** | 
|---|
| 108 | Get debugger widget responsible for accessing the inner workings | 
|---|
| 109 | of the cart. | 
|---|
| 110 | */ | 
|---|
| 111 | CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont, | 
|---|
| 112 | const GUI::Font& nfont, int x, int y, int w, int h) override | 
|---|
| 113 | { | 
|---|
| 114 | return new Cartridge4KWidget(boss, lfont, nfont, x, y, w, h, *this); | 
|---|
| 115 | } | 
|---|
| 116 | #endif | 
|---|
| 117 |  | 
|---|
| 118 | /** | 
|---|
| 119 | Get the byte at the specified address. | 
|---|
| 120 |  | 
|---|
| 121 | @return The byte at the specified address | 
|---|
| 122 | */ | 
|---|
| 123 | uInt8 peek(uInt16 address) override { return myImage[address & 0x0FFF]; } | 
|---|
| 124 |  | 
|---|
| 125 | private: | 
|---|
| 126 | // The 4K ROM image for the cartridge | 
|---|
| 127 | std::array<uInt8, 4_KB> myImage; | 
|---|
| 128 |  | 
|---|
| 129 | private: | 
|---|
| 130 | // Following constructors and assignment operators not supported | 
|---|
| 131 | Cartridge4K() = delete; | 
|---|
| 132 | Cartridge4K(const Cartridge4K&) = delete; | 
|---|
| 133 | Cartridge4K(Cartridge4K&&) = delete; | 
|---|
| 134 | Cartridge4K& operator=(const Cartridge4K&) = delete; | 
|---|
| 135 | Cartridge4K& operator=(Cartridge4K&&) = delete; | 
|---|
| 136 | }; | 
|---|
| 137 |  | 
|---|
| 138 | #endif | 
|---|
| 139 |  | 
|---|