14
14
// See the file "License.txt" for information on usage and redistribution of
15
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
17
// $Id: CartDebug.hxx 2579 2013-01-04 19:49:01Z stephena $
17
// $Id: CartDebug.hxx 2747 2013-06-17 15:57:41Z stephena $
18
18
//============================================================================
20
20
#ifndef CART_DEBUG_HXX
21
21
#define CART_DEBUG_HXX
24
class CartDebugWidget;
45
46
IntArray ram; // The actual data values
46
47
IntArray rport; // Address for reading from RAM
47
48
IntArray wport; // Address for writing to RAM
49
string bank; // Current banking layout
50
52
class CartDebug : public DebuggerSystem
58
VALID_ENTRY = 1 << 0, /* addresses that can have a label placed in front of it.
60
REFERENCED = 1 << 0, /* code somewhere in the program references it,
61
i.e. LDA $F372 referenced $F372 */
62
VALID_ENTRY = 1 << 1, /* addresses that can have a label placed in front of it.
59
63
A good counterexample would be "FF00: LDA $FE00"; $FF01
60
64
would be in the middle of a multi-byte instruction, and
61
65
therefore cannot be labelled. */
62
REFERENCED = 1 << 1, /* code somewhere in the program references it,
63
i.e. LDA $F372 referenced $F372 */
65
67
// The following correspond to specific types that can be set within the
66
68
// debugger, or specified in a Distella cfg file, and are listed in order
67
69
// of decreasing hierarchy
69
SKIP = 1 << 7, // TODO - document this
70
CODE = 1 << 6, // disassemble-able code segments
71
CODE = 1 << 7, // disassemble-able code segments
72
TCODE = 1 << 6, // (tentative) disassemble-able code segments
71
73
GFX = 1 << 5, // addresses loaded into GRPx registers
72
74
PGFX = 1 << 4, // addresses loaded into PFx registers
73
75
DATA = 1 << 3, // addresses loaded into registers other than GRPx / PFx
98
100
void saveOldState();
99
101
string toString();
103
// Used to get/set the debug widget, which contains cart-specific
105
CartDebugWidget* getDebugWidget() const { return myDebugWidget; }
106
void setDebugWidget(CartDebugWidget* w) { myDebugWidget = w; }
101
108
// The following assume that the given addresses are using the
102
109
// correct read/write port ranges; no checking will be done to
134
141
Disassemble from the given address using the Distella disassembler
135
142
Address-to-label mappings (and vice-versa) are also determined here
137
@param resolvedata Whether to determine code vs data sections
138
@param force Force a re-disassembly, even if the state hasn't changed
144
@param force Force a re-disassembly, even if the state hasn't changed
140
146
@return True if disassembly changed from previous call, else false
142
bool disassemble(const string& resolvedata, bool force = false);
148
bool disassemble(bool force = false);
145
151
Get the results from the most recent call to disassemble()
188
194
Get the current bank in use by the cartridge.
196
int getBank(); // non-const because of use in YaccParser
193
199
Get the total number of banks supported by the cartridge.
201
int bankCount() const;
198
204
Get the name/type of the cartridge.
200
string getCartType();
206
string getCartType() const;
203
209
Add a label and associated address.
221
227
If places is not -1 and a label hasn't been defined, return a
222
228
formatted hexidecimal address
224
const string& getLabel(uInt16 addr, bool isRead, int places = -1) const;
230
bool getLabel(ostream& buf, uInt16 addr, bool isRead, int places = -1) const;
231
string getLabel(uInt16 addr, bool isRead, int places = -1) const;
225
232
int getAddress(const string& label) const;
228
Load user equates from the given symbol file (as generated by DASM).
230
string loadSymbolFile(string file = "");
233
Load/save Distella config file (Distella directives)
235
string loadConfigFile(string file = "");
236
string saveConfigFile(string file = "");
235
Load user equates from symbol file (as generated by DASM).
237
string loadSymbolFile();
240
Load/save Distella config files (Distella directives)
242
string loadConfigFile();
243
string saveConfigFile();
246
Save disassembly and ROM file
248
string saveDisassembly();
239
252
Show Distella directives (both set by the user and determined by Distella)
263
276
// Determine 'type' of address (ie, what part of the system accessed)
270
283
AddrType addressType(uInt16 addr) const;
285
struct DirectiveTag {
277
290
typedef list<uInt16> AddressList;
278
291
typedef list<DirectiveTag> DirectiveList;
281
294
uInt16 start; // start of address space
282
295
uInt16 end; // end of address space
283
296
uInt16 offset; // ORG value
284
297
uInt16 size; // size of a bank (in bytes)
285
298
AddressList addressList; // addresses which PC has hit
286
299
DirectiveList directiveList; // overrides for automatic code determination
301
BankInfo() : start(0), end(0), offset(0), size(0) { }
303
friend ostream& operator<<(ostream& os, const BankInfo& b)
305
os << "start=$" << HEX4 << b.start << ", end=$" << HEX4 << b.end
306
<< ", offset=$" << HEX4 << b.offset << ", size=" << dec << b.size
309
AddressList::const_iterator i;
310
for(i = b.addressList.begin(); i != b.addressList.end(); ++i)
311
os << HEX4 << *i << " ";
289
317
// Address type information determined by Distella
290
318
uInt8 myDisLabels[0x1000], myDisDirectives[0x1000];
320
// Information on equates used in the disassembly
321
struct ReservedEquates {
324
bool IOReadWrite[24];
328
ReservedEquates myReserved;
292
330
// Actually call DiStella to fill the DisassemblyList structure
293
331
// Return whether the search address was actually in the list
294
bool fillDisassemblyList(BankInfo& bankinfo, bool resolvedata, uInt16 search);
332
bool fillDisassemblyList(BankInfo& bankinfo, uInt16 search);
296
334
// Analyze of bank of ROM, generating a list of Distella directives
297
335
// based on its disassembly
298
336
void getBankDirectives(ostream& buf, BankInfo& info) const;
338
// Get disassembly enum type from 'flags', taking precendence into account
339
DisasmType disasmTypeAbsolute(uInt8 flags) const;
300
341
// Convert disassembly enum type to corresponding string and append to buf
301
342
void disasmTypeAsString(ostream& buf, DisasmType type) const;
338
381
// The maximum length of all labels currently defined
339
382
uInt16 myLabelLength;
384
// Filenames to use for various I/O (currently these are hardcoded)
385
string mySymbolFile, myCfgFile, myDisasmFile, myRomFile;
341
387
/// Table of instruction mnemonics
342
static const char* ourTIAMnemonicR[16]; // read mode
343
static const char* ourTIAMnemonicW[64]; // write mode
388
static const char* ourTIAMnemonicR[16]; // read mode
389
static const char* ourTIAMnemonicW[64]; // write mode
344
390
static const char* ourIOMnemonic[24];
391
static const char* ourZPMnemonic[128];