1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2007 by Bradford W. Mott and the Stella team
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Cart.hxx,v 1.19 2007/06/14 13:47:50 stephena Exp $
//============================================================================
#ifndef CARTRIDGE_HXX
#define CARTRIDGE_HXX
class Cartridge;
class System;
class Properties;
class Settings;
#include <fstream>
#include "m6502/src/bspf/src/bspf.hxx"
#include "m6502/src/Device.hxx"
#include "Random.hxx"
#include "../common/Log.hpp"
/**
A cartridge is a device which contains the machine code for a
game and handles any bankswitching performed by the cartridge.
@author Bradford W. Mott
@version $Id: Cart.hxx,v 1.19 2007/06/14 13:47:50 stephena Exp $
*/
class Cartridge : public Device
{
public:
/**
Create a new cartridge object allocated on the heap. The
type of cartridge created depends on the properties object.
@param image A pointer to the ROM image
@param size The size of the ROM image
@param props The properties associated with the game
@param settings The settings associated with the system
@return Pointer to the new cartridge object allocated on the heap
*/
static Cartridge* create(const uInt8* image, uInt32 size,
const Properties& props, const Settings& settings, Random& rng);
/**
Create a new cartridge
*/
Cartridge();
/**
Destructor
*/
virtual ~Cartridge();
/**
Query some information about this cartridge.
*/
static const std::string& about() { return myAboutString; }
/**
Save the internal (patched) ROM image.
@param out The output file stream to save the image
*/
bool save(std::ofstream& out);
/** MGB: Added to drop warning on overloaded save() method. */
virtual bool save(Serializer& out) = 0;
/**
Lock/unlock bankswitching capability.
*/
void lockBank() { bankLocked = true; }
void unlockBank() { bankLocked = false; }
public:
//////////////////////////////////////////////////////////////////////
// The following methods are cart-specific and must be implemented
// in derived classes.
//////////////////////////////////////////////////////////////////////
/**
Set the specified bank.
*/
virtual void bank(uInt16 bank) = 0;
/**
Get the current bank.
@return The current bank, or -1 if bankswitching not supported
*/
virtual int bank() = 0;
/**
Query the number of banks supported by the cartridge.
*/
virtual int bankCount() = 0;
/**
Patch the cartridge ROM.
@param address The ROM address to patch
@param value The value to place into the address
@return Success or failure of the patch operation
*/
virtual bool patch(uInt16 address, uInt8 value) = 0;
/**
Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data
*/
virtual uInt8* getImage(int& size) = 0;
protected:
// If bankLocked is true, ignore attempts at bankswitching. This is used
// by the debugger, when disassembling/dumping ROM.
bool bankLocked;
private:
/**
Try to auto-detect the bankswitching type of the cartridge
@param image A pointer to the ROM image
@param size The size of the ROM image
@return The "best guess" for the cartridge type
*/
static std::string autodetectType(const uInt8* image, uInt32 size);
/**
Search the image for the specified byte signature
@param image A pointer to the ROM image
@param imagesize The size of the ROM image
@param signature The byte sequence to search for
@param sigsize The number of bytes in the signature
@param minhits The minimum number of times a signature is to be found
@return True if the signature was found at least 'minhits' time, else false
*/
static bool searchForBytes(const uInt8* image, uInt32 imagesize,
const uInt8* signature, uInt32 sigsize,
uInt32 minhits);
/**
Returns true if the image is probably a SuperChip (256 bytes RAM)
*/
static bool isProbablySC(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a 3F bankswitching cartridge
*/
static bool isProbably3F(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a 3E bankswitching cartridge
*/
static bool isProbably3E(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a E0 bankswitching cartridge
*/
static bool isProbablyE0(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a E7 bankswitching cartridge
*/
static bool isProbablyE7(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a UA bankswitching cartridge
*/
static bool isProbablyUA(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably a CV bankswitching cartridge
*/
static bool isProbablyCV(const uInt8* image, uInt32 size);
/**
Returns true if the image is probably an FE bankswitching cartridge
*/
static bool isProbablyFE(const uInt8* image, uInt32 size);
private:
// Contains info about this cartridge in string format
static std::string myAboutString;
// Copy constructor isn't supported by cartridges so make it private
Cartridge(const Cartridge&);
// Assignment operator isn't supported by cartridges so make it private
Cartridge& operator = (const Cartridge&);
};
#endif