~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/debugger/CartDebug.hxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2013-06-28 09:53:13 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20130628095313-j8jkkgxpvx1t18ym
Tags: 3.9-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
16
16
//
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
//============================================================================
19
19
 
20
20
#ifndef CART_DEBUG_HXX
21
21
#define CART_DEBUG_HXX
22
22
 
23
23
class Settings;
 
24
class CartDebugWidget;
24
25
 
25
26
#include <map>
26
27
#include <set>
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
48
50
};
49
51
 
50
52
class CartDebug : public DebuggerSystem
55
57
  public:
56
58
    enum DisasmType {
57
59
      NONE        = 0,
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 */
64
66
 
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
68
70
      //
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
83
85
      bool hllabel;
84
86
    };
85
87
    typedef Common::Array<DisassemblyTag> DisassemblyList;
86
 
    typedef struct {
 
88
    struct Disassembly {
87
89
      DisassemblyList list;
88
90
      int fieldwidth;
89
 
    } Disassembly;
 
91
    };
90
92
 
91
93
  public:
92
94
    CartDebug(Debugger& dbg, Console& console, const OSystem& osystem);
98
100
    void saveOldState();
99
101
    string toString();
100
102
 
 
103
    // Used to get/set the debug widget, which contains cart-specific
 
104
    // functionality
 
105
    CartDebugWidget* getDebugWidget() const { return myDebugWidget; }
 
106
    void setDebugWidget(CartDebugWidget* w) { myDebugWidget = w; }
 
107
 
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
103
110
    // confirm this.
134
141
      Disassemble from the given address using the Distella disassembler
135
142
      Address-to-label mappings (and vice-versa) are also determined here
136
143
 
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
139
145
 
140
146
      @return  True if disassembly changed from previous call, else false
141
147
    */
142
 
    bool disassemble(const string& resolvedata, bool force = false);
 
148
    bool disassemble(bool force = false);
143
149
 
144
150
    /**
145
151
      Get the results from the most recent call to disassemble()
187
193
    /**
188
194
      Get the current bank in use by the cartridge.
189
195
    */
190
 
    int getBank();
 
196
    int getBank();  // non-const because of use in YaccParser
191
197
 
192
198
    /**
193
199
      Get the total number of banks supported by the cartridge.
194
200
    */
195
 
    int bankCount();
 
201
    int bankCount() const;
196
202
 
197
203
    /**
198
204
      Get the name/type of the cartridge.
199
205
    */
200
 
    string getCartType();
 
206
    string getCartType() const;
201
207
 
202
208
    /**
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
223
229
    */
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;
226
233
 
227
234
    /**
228
 
      Load user equates from the given symbol file (as generated by DASM).
229
 
    */
230
 
    string loadSymbolFile(string file = "");
231
 
 
232
 
    /**
233
 
      Load/save Distella config file (Distella directives)
234
 
    */
235
 
    string loadConfigFile(string file = "");
236
 
    string saveConfigFile(string file = "");
 
235
      Load user equates from symbol file (as generated by DASM).
 
236
    */
 
237
    string loadSymbolFile();
 
238
 
 
239
    /**
 
240
      Load/save Distella config files (Distella directives)
 
241
    */
 
242
    string loadConfigFile();
 
243
    string saveConfigFile();
 
244
 
 
245
    /**
 
246
      Save disassembly and ROM file
 
247
    */
 
248
    string saveDisassembly();
 
249
    string saveRom();
237
250
 
238
251
    /**
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)
264
277
    enum AddrType {
265
278
      ADDR_TIA,
266
 
      ADDR_RAM,
267
 
      ADDR_RIOT,
 
279
      ADDR_IO,
 
280
      ADDR_ZPRAM,
268
281
      ADDR_ROM
269
282
    };
270
283
    AddrType addressType(uInt16 addr) const;
271
284
 
272
 
    typedef struct {
 
285
    struct DirectiveTag {
273
286
      DisasmType type;
274
287
      uInt16 start;
275
288
      uInt16 end;
276
 
    } DirectiveTag;
 
289
    };
277
290
    typedef list<uInt16> AddressList;
278
291
    typedef list<DirectiveTag> DirectiveList;
279
292
 
280
 
    typedef struct {
 
293
    struct BankInfo {
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
287
 
    } BankInfo;
 
300
 
 
301
      BankInfo() : start(0), end(0), offset(0), size(0) { }
 
302
#if 0
 
303
      friend ostream& operator<<(ostream& os, const BankInfo& b)
 
304
      {
 
305
        os << "start=$" << HEX4 << b.start << ", end=$" << HEX4 << b.end
 
306
           << ", offset=$" << HEX4 << b.offset << ", size=" << dec << b.size
 
307
           << endl
 
308
           << "addrlist: ";
 
309
        AddressList::const_iterator i;
 
310
        for(i = b.addressList.begin(); i != b.addressList.end(); ++i)
 
311
          os << HEX4 << *i << " ";
 
312
        return os;
 
313
      }
 
314
#endif
 
315
    };
288
316
 
289
317
    // Address type information determined by Distella
290
318
    uInt8 myDisLabels[0x1000], myDisDirectives[0x1000];
291
319
 
 
320
    // Information on equates used in the disassembly
 
321
    struct ReservedEquates {
 
322
      bool TIARead[16];
 
323
      bool TIAWrite[64];
 
324
      bool IOReadWrite[24];
 
325
      bool ZPRAM[128];
 
326
      AddrToLabel Label;
 
327
    };
 
328
    ReservedEquates myReserved;
 
329
 
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);
295
333
 
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;
299
337
 
 
338
    // Get disassembly enum type from 'flags', taking precendence into account
 
339
    DisasmType disasmTypeAbsolute(uInt8 flags) const;
 
340
 
300
341
    // Convert disassembly enum type to corresponding string and append to buf
301
342
    void disasmTypeAsString(ostream& buf, DisasmType type) const;
302
343
 
310
351
    CartState myState;
311
352
    CartState myOldState;
312
353
 
 
354
    CartDebugWidget* myDebugWidget;
 
355
 
313
356
    // A complete record of relevant diassembly information for each bank
314
357
    Common::Array<BankInfo> myBankInfo;
315
358
 
338
381
    // The maximum length of all labels currently defined
339
382
    uInt16 myLabelLength;
340
383
 
 
384
    // Filenames to use for various I/O (currently these are hardcoded)
 
385
    string mySymbolFile, myCfgFile, myDisasmFile, myRomFile;
 
386
 
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];
345
392
};
346
393
 
347
394
#endif