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 CARTRIDGEUA_HXX
19#define CARTRIDGEUA_HXX
20
21#include "bspf.hxx"
22#include "Cart.hxx"
23#include "System.hxx"
24#ifdef DEBUGGER_SUPPORT
25 #include "CartUAWidget.hxx"
26#endif
27
28/**
29 Cartridge class used for UA Limited's 8K bankswitched games. There
30 are two 4K banks, which are switched by accessing $0220 (bank 0) and
31 $0240 (bank 1).
32
33 @author Bradford W. Mott
34*/
35class CartridgeUA : public Cartridge
36{
37 friend class CartridgeUAWidget;
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 @param swapHotspots Swap hotspots
48 */
49 CartridgeUA(const ByteBuffer& image, size_t size, const string& md5,
50 const Settings& settings, bool swapHotspots = false);
51 virtual ~CartridgeUA() = default;
52
53 public:
54 /**
55 Reset device to its power-on state
56 */
57 void reset() override;
58
59 /**
60 Install cartridge in the specified system. Invoked by the system
61 when the cartridge is attached to it.
62
63 @param system The system the device should install itself in
64 */
65 void install(System& system) override;
66
67 /**
68 Install pages for the specified bank in the system.
69
70 @param bank The bank that should be installed in the system
71 */
72 bool bank(uInt16 bank) override;
73
74 /**
75 Get the current bank.
76
77 @param address The address to use when querying the bank
78 */
79 uInt16 getBank(uInt16 address = 0) const override;
80
81 /**
82 Query the number of banks supported by the cartridge.
83 */
84 uInt16 bankCount() const override;
85
86 /**
87 Patch the cartridge ROM.
88
89 @param address The ROM address to patch
90 @param value The value to place into the address
91 @return Success or failure of the patch operation
92 */
93 bool patch(uInt16 address, uInt8 value) override;
94
95 /**
96 Access the internal ROM image for this cartridge.
97
98 @param size Set to the size of the internal ROM image data
99 @return A pointer to the internal ROM image data
100 */
101 const uInt8* getImage(size_t& size) const override;
102
103 /**
104 Save the current state of this cart to the given Serializer.
105
106 @param out The Serializer object to use
107 @return False on any errors, else true
108 */
109 bool save(Serializer& out) const override;
110
111 /**
112 Load the current state of this cart from the given Serializer.
113
114 @param in The Serializer object to use
115 @return False on any errors, else true
116 */
117 bool load(Serializer& in) override;
118
119 /**
120 Get a descriptor for the device name (used in error checking).
121
122 @return The name of the object
123 */
124 string name() const override { return mySwappedHotspots ? "CartridgeUASW" : "CartridgeUA"; }
125
126 #ifdef DEBUGGER_SUPPORT
127 /**
128 Get debugger widget responsible for accessing the inner workings
129 of the cart.
130 */
131 CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont,
132 const GUI::Font& nfont, int x, int y, int w, int h) override
133 {
134 return new CartridgeUAWidget(boss, lfont, nfont, x, y, w, h, *this, mySwappedHotspots);
135 }
136 #endif
137
138 public:
139 /**
140 Get the byte at the specified address.
141
142 @return The byte at the specified address
143 */
144 uInt8 peek(uInt16 address) override;
145
146 /**
147 Change the byte at the specified address to the given value
148
149 @param address The address where the value should be stored
150 @param value The value to be stored at the address
151 @return True if the poke changed the device address space, else false
152 */
153 bool poke(uInt16 address, uInt8 value) override;
154
155 private:
156 // The 8K ROM image of the cartridge
157 std::array<uInt8, 8_KB> myImage;
158
159 // Previous Device's page access
160 std::array<System::PageAccess, 2> myHotSpotPageAccess;
161
162 // Indicates the offset into the ROM image (aligns to current bank)
163 uInt16 myBankOffset;
164
165 // Indicates if banks are swapped ("Mickey" cart)
166 bool mySwappedHotspots;
167
168 private:
169 // Following constructors and assignment operators not supported
170 CartridgeUA() = delete;
171 CartridgeUA(const CartridgeUA&) = delete;
172 CartridgeUA(CartridgeUA&&) = delete;
173 CartridgeUA& operator=(const CartridgeUA&) = delete;
174 CartridgeUA& operator=(CartridgeUA&&) = delete;
175};
176
177#endif
178