| 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 CARTRIDGE4KSC_HXX |
| 19 | #define CARTRIDGE4KSC_HXX |
| 20 | |
| 21 | class System; |
| 22 | |
| 23 | #include "bspf.hxx" |
| 24 | #include "Cart.hxx" |
| 25 | #ifdef DEBUGGER_SUPPORT |
| 26 | #include "Cart4KSCWidget.hxx" |
| 27 | #endif |
| 28 | |
| 29 | /** |
| 30 | Cartridge class used for 4K games with 128 bytes of RAM. |
| 31 | RAM read port is $1080 - $10FF, write port is $1000 - $107F. |
| 32 | */ |
| 33 | |
| 34 | class Cartridge4KSC : public Cartridge |
| 35 | { |
| 36 | friend class Cartridge4KSCWidget; |
| 37 | |
| 38 | public: |
| 39 | /** |
| 40 | Create a new cartridge using the specified image |
| 41 | |
| 42 | @param image Pointer to the ROM image |
| 43 | @param size The size of the ROM image |
| 44 | @param md5 The md5sum of the ROM image |
| 45 | @param settings A reference to the various settings (read-only) |
| 46 | */ |
| 47 | Cartridge4KSC(const ByteBuffer& image, size_t size, const string& md5, |
| 48 | const Settings& settings); |
| 49 | virtual ~Cartridge4KSC() = default; |
| 50 | |
| 51 | public: |
| 52 | /** |
| 53 | Reset device to its power-on state |
| 54 | */ |
| 55 | void reset() override; |
| 56 | |
| 57 | /** |
| 58 | Install cartridge in the specified system. Invoked by the system |
| 59 | when the cartridge is attached to it. |
| 60 | |
| 61 | @param system The system the device should install itself in |
| 62 | */ |
| 63 | void install(System& system) override; |
| 64 | |
| 65 | /** |
| 66 | Patch the cartridge ROM. |
| 67 | |
| 68 | @param address The ROM address to patch |
| 69 | @param value The value to place into the address |
| 70 | @return Success or failure of the patch operation |
| 71 | */ |
| 72 | bool patch(uInt16 address, uInt8 value) override; |
| 73 | |
| 74 | /** |
| 75 | Access the internal ROM image for this cartridge. |
| 76 | |
| 77 | @param size Set to the size of the internal ROM image data |
| 78 | @return A pointer to the internal ROM image data |
| 79 | */ |
| 80 | const uInt8* getImage(size_t& size) const override; |
| 81 | |
| 82 | /** |
| 83 | Save the current state of this cart to the given Serializer. |
| 84 | |
| 85 | @param out The Serializer object to use |
| 86 | @return False on any errors, else true |
| 87 | */ |
| 88 | bool save(Serializer& out) const override; |
| 89 | |
| 90 | /** |
| 91 | Load the current state of this cart from the given Serializer. |
| 92 | |
| 93 | @param in The Serializer object to use |
| 94 | @return False on any errors, else true |
| 95 | */ |
| 96 | bool load(Serializer& in) override; |
| 97 | |
| 98 | /** |
| 99 | Get a descriptor for the device name (used in error checking). |
| 100 | |
| 101 | @return The name of the object |
| 102 | */ |
| 103 | string name() const override { return "Cartridge4KSC" ; } |
| 104 | |
| 105 | #ifdef DEBUGGER_SUPPORT |
| 106 | /** |
| 107 | Get debugger widget responsible for accessing the inner workings |
| 108 | of the cart. |
| 109 | */ |
| 110 | CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont, |
| 111 | const GUI::Font& nfont, int x, int y, int w, int h) override |
| 112 | { |
| 113 | return new Cartridge4KSCWidget(boss, lfont, nfont, x, y, w, h, *this); |
| 114 | } |
| 115 | #endif |
| 116 | |
| 117 | public: |
| 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; |
| 124 | |
| 125 | /** |
| 126 | Change the byte at the specified address to the given value |
| 127 | |
| 128 | @param address The address where the value should be stored |
| 129 | @param value The value to be stored at the address |
| 130 | @return True if the poke changed the device address space, else false |
| 131 | */ |
| 132 | bool poke(uInt16 address, uInt8 value) override; |
| 133 | |
| 134 | private: |
| 135 | // The 4K ROM image of the cartridge |
| 136 | std::array<uInt8, 4_KB> myImage; |
| 137 | |
| 138 | // The 128 bytes of RAM |
| 139 | std::array<uInt8, 128> myRAM; |
| 140 | |
| 141 | private: |
| 142 | // Following constructors and assignment operators not supported |
| 143 | Cartridge4KSC() = delete; |
| 144 | Cartridge4KSC(const Cartridge4KSC&) = delete; |
| 145 | Cartridge4KSC(Cartridge4KSC&&) = delete; |
| 146 | Cartridge4KSC& operator=(const Cartridge4KSC&) = delete; |
| 147 | Cartridge4KSC& operator=(Cartridge4KSC&&) = delete; |
| 148 | }; |
| 149 | |
| 150 | #endif |
| 151 | |