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