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 CARTRIDGE2K_HXX
19#define CARTRIDGE2K_HXX
20
21class System;
22
23#include "bspf.hxx"
24#include "Cart.hxx"
25#ifdef DEBUGGER_SUPPORT
26 #include "Cart2KWidget.hxx"
27#endif
28
29/**
30 This is the standard Atari 2K cartridge. These cartridges are not
31 bankswitched, however, the data repeats twice in the 2600's 4K cartridge
32 addressing space. For 'Sub2K' ROMs (ROMs less than 2K in size), the
33 data repeats in intervals based on the size of the ROM (which will
34 always be a power of 2).
35
36 @author Stephen Anthony
37*/
38class Cartridge2K : public Cartridge
39{
40 friend class Cartridge2KWidget;
41
42 public:
43 /**
44 Create a new cartridge using the specified image
45
46 @param image Pointer to the ROM image
47 @param size The size of the ROM image (<= 2048 bytes)
48 @param md5 The md5sum of the ROM image
49 @param settings A reference to the various settings (read-only)
50 */
51 Cartridge2K(const ByteBuffer& image, size_t size, const string& md5,
52 const Settings& settings);
53 virtual ~Cartridge2K() = default;
54
55 public:
56 /**
57 Reset cartridge to its power-on state
58 */
59 void reset() override;
60
61 /**
62 Install cartridge in the specified system. Invoked by the system
63 when the cartridge is attached to it.
64
65 @param system The system the device should install itself in
66 */
67 void install(System& system) override;
68
69 /**
70 Patch the cartridge ROM.
71
72 @param address The ROM address to patch
73 @param value The value to place into the address
74 @return Success or failure of the patch operation
75 */
76 bool patch(uInt16 address, uInt8 value) override;
77
78 /**
79 Access the internal ROM image for this cartridge.
80
81 @param size Set to the size of the internal ROM image data
82 @return A pointer to the internal ROM image data
83 */
84 const uInt8* getImage(size_t& size) const override;
85
86 /**
87 Save the current state of this cart to the given Serializer.
88
89 @param out The Serializer object to use
90 @return False on any errors, else true
91 */
92 bool save(Serializer& out) const override;
93
94 /**
95 Load the current state of this cart from the given Serializer.
96
97 @param in The Serializer object to use
98 @return False on any errors, else true
99 */
100 bool load(Serializer& in) override;
101
102 /**
103 Get a descriptor for the device name (used in error checking).
104
105 @return The name of the object
106 */
107 string name() const override { return "Cartridge2K"; }
108
109 #ifdef DEBUGGER_SUPPORT
110 /**
111 Get debugger widget responsible for accessing the inner workings
112 of the cart.
113 */
114 CartDebugWidget* debugWidget(GuiObject* boss, const GUI::Font& lfont,
115 const GUI::Font& nfont, int x, int y, int w, int h) override
116 {
117 return new Cartridge2KWidget(boss, lfont, nfont, x, y, w, h, *this);
118 }
119 #endif
120
121 /**
122 Get the byte at the specified address.
123
124 @return The byte at the specified address
125 */
126 uInt8 peek(uInt16 address) override { return myImage[address & myMask]; }
127
128 private:
129 // Pointer to a dynamically allocated ROM image of the cartridge
130 ByteBuffer myImage;
131
132 // Size of the ROM image
133 size_t mySize;
134
135 // Mask to use for mirroring
136 uInt16 myMask;
137
138 private:
139 // Following constructors and assignment operators not supported
140 Cartridge2K() = delete;
141 Cartridge2K(const Cartridge2K&) = delete;
142 Cartridge2K(Cartridge2K&&) = delete;
143 Cartridge2K& operator=(const Cartridge2K&) = delete;
144 Cartridge2K& operator=(Cartridge2K&&) = delete;
145};
146
147#endif
148