~ubuntu-branches/debian/experimental/mednafen/experimental

« back to all changes in this revision

Viewing changes to src/nes/debug.cpp

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2014-11-08 11:36:07 UTC
  • mfrom: (1.2.18) (10.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20141108113607-3lbwsamqqhrso4hp
Tags: 0.9.36.5-1
* New upstream release, uploaded to expermiental for the Jessie freeze.
* Standards-Version 3.9.6, no change required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "debug.h"
22
22
#include "ppu/ppu.h"
23
23
#include "cart.h"
24
 
#include "../dis6502.h"
 
24
#include <mednafen/dis6502.h>
 
25
 
 
26
static void RedoHooks(void);
25
27
 
26
28
#define NUMBT 64
27
29
 
31
33
 uint32 to;
32
34
 uint32 vector;
33
35
 uint32 branch_count;
 
36
 bool valid;
34
37
};
35
38
 
36
39
static BTEntry BTEntries[NUMBT];
37
 
static int BTIndex = 0;
 
40
static int BTIndex;
 
41
static bool BTEnabled;
38
42
 
39
43
void NESDBG_AddBranchTrace(uint32 from, uint32 to, uint32 vector)
40
44
{
45
49
 
46
50
 //if(BTEntries[(BTIndex - 1) & 0xF] == PC) return;
47
51
 
48
 
 if(prevbt->from == from && prevbt->to == to && prevbt->vector == vector && prevbt->branch_count < 0xFFFFFFFF)
 
52
 if(prevbt->from == from && prevbt->to == to && prevbt->vector == vector && prevbt->branch_count < 0xFFFFFFFF && prevbt->valid)
49
53
  prevbt->branch_count++;
50
54
 else
51
55
 {
53
57
  BTEntries[BTIndex].to = to;
54
58
  BTEntries[BTIndex].vector = vector;
55
59
  BTEntries[BTIndex].branch_count = 1;
 
60
  BTEntries[BTIndex].valid = true;
56
61
 
57
62
  BTIndex = (BTIndex + 1) % NUMBT;
58
63
 }
59
64
}
60
65
 
 
66
static void EnableBranchTrace(bool enable)
 
67
{
 
68
 BTEnabled = enable;
 
69
 if(!enable)
 
70
 {
 
71
  BTIndex = 0;
 
72
  memset(BTEntries, 0, sizeof(BTEntries));
 
73
 }
 
74
 RedoHooks();
 
75
}
 
76
 
61
77
static std::vector<BranchTraceResult> GetBranchTrace(void)
62
78
{
63
79
 BranchTraceResult tmp;
67
83
 {
68
84
  const BTEntry *bt = &BTEntries[(x + BTIndex) % NUMBT];
69
85
 
 
86
  if(!bt->valid)
 
87
   continue;
 
88
 
70
89
  tmp.count = bt->branch_count;
71
90
  trio_snprintf(tmp.from, sizeof(tmp.from), "%04X", bt->from);
72
91
  trio_snprintf(tmp.to, sizeof(tmp.to), "%04X", bt->to);
234
253
 
235
254
static std::vector<NES_BPOINT> BreakPointsPC, BreakPointsRead, BreakPointsWrite;
236
255
 
237
 
static void (*CPUHook)(uint32 PC) = NULL;
 
256
static void (*CPUHook)(uint32 PC, bool) = NULL;
 
257
static bool CPUHookContinuous = false;
238
258
static bool FoundBPoint = 0;
239
 
static void (*BPCallB)(uint32 PC) = NULL;
240
 
 
241
 
void NESDBG_TestFoundBPoint(void)
242
 
{
243
 
 if(FoundBPoint)
244
 
 {
245
 
  BPCallB(X.PC);
246
 
 }
247
 
 FoundBPoint = 0;
248
 
}
249
259
 
250
260
static void CPUHandler(uint32 PC)
251
261
{
256
266
  {
257
267
   if(PC >= bpit->A[0] && PC <= bpit->A[1])
258
268
   {
259
 
    BPCallB(PC);
 
269
    FoundBPoint = true;
260
270
    break;
261
271
   }
262
272
  }
263
273
 
264
 
 if(CPUHook)
265
 
  CPUHook(PC);
 
274
 CPUHookContinuous |= FoundBPoint;
 
275
 if(CPUHookContinuous && CPUHook)
 
276
  CPUHook(PC, FoundBPoint);
 
277
 
 
278
 FoundBPoint = false;
266
279
}
267
280
 
268
281
static uint8 ReadHandler(X6502 *cur_X, unsigned int A)
302
315
  BWrite[A](A,V);
303
316
}
304
317
 
 
318
static void RedoHooks(void)
 
319
{
 
320
 X6502_Debug((CPUHook || BTEnabled) ? CPUHandler : NULL, (CPUHook && BreakPointsRead.size()) ? ReadHandler : NULL, (CPUHook && BreakPointsWrite.size()) ? WriteHandler : 0);
 
321
}
 
322
 
305
323
static void AddBreakPoint(int type, unsigned int A1, unsigned int A2, bool logical)
306
324
{
307
325
 NES_BPOINT tmp;
318
336
 else if(type == BPOINT_PC)
319
337
  BreakPointsPC.push_back(tmp);
320
338
 
321
 
 X6502_Debug(BreakPointsPC.size() ? CPUHandler : CPUHook, BreakPointsRead.size() ? ReadHandler : NULL, BreakPointsWrite.size() ? WriteHandler : 0);
 
339
 RedoHooks();
322
340
}
323
341
 
324
342
static void FlushBreakPoints(int type)
332
350
 else if(type == BPOINT_PC)
333
351
  BreakPointsPC.clear();
334
352
 
335
 
 X6502_Debug(BreakPointsPC.size() ? CPUHandler : CPUHook, BreakPointsRead.size() ? ReadHandler : NULL, BreakPointsWrite.size() ? WriteHandler : 0);
 
353
 RedoHooks();
336
354
}
337
355
 
338
 
static void SetCPUCallback(void (*callb)(uint32 PC))
 
356
static void SetCPUCallback(void (*callb)(uint32 PC, bool bpoint), bool continuous)
339
357
{
340
358
 CPUHook = callb;
341
 
 X6502_Debug(BreakPointsPC.size() ? CPUHandler : CPUHook, BreakPointsRead.size() ? ReadHandler : NULL, BreakPointsWrite.size() ? WriteHandler : 0);
342
 
}
 
359
 CPUHookContinuous = continuous;
343
360
 
344
 
static void SetBPCallback(void (*callb)(uint32 PC))
345
 
{
346
 
 BPCallB = callb;
 
361
 RedoHooks();
347
362
}
348
363
 
349
364
enum
500
515
 FlushBreakPoints,
501
516
 AddBreakPoint,
502
517
 SetCPUCallback,
503
 
 SetBPCallback,
 
518
 EnableBranchTrace,
504
519
 GetBranchTrace,
505
520
 NESPPU_SetGraphicsDecode,
506
521
};
507
522
 
508
523
bool NESDBG_Init(void)
509
524
{
 
525
 memset(BTEntries, 0, sizeof(BTEntries));
 
526
 BTIndex = 0;
 
527
 BTEnabled = false;
 
528
 
510
529
 MDFNDBG_AddRegGroup(&NESCPURegsGroup);
511
530
 MDFNDBG_AddRegGroup(&NESPPURegsGroup);
512
531