forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.cpp
7824 lines (7297 loc) · 187 KB
/
debug.cpp
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* UAE - The Un*x Amiga Emulator
*
* Debugger
*
* (c) 1995 Bernd Schmidt
* (c) 2006 Toni Wilen
*
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include <signal.h>
#include "options.h"
#include "uae.h"
#include "memory.h"
#include "custom.h"
#include "newcpu.h"
#include "cpu_prefetch.h"
#include "debug.h"
#include "disasm.h"
#include "debugmem.h"
#include "cia.h"
#include "xwin.h"
#include "identify.h"
#include "audio.h"
#include "sounddep/sound.h"
#include "disk.h"
#include "savestate.h"
#include "autoconf.h"
#include "akiko.h"
#include "inputdevice.h"
#include "crc32.h"
#include "cpummu.h"
#include "rommgr.h"
#include "inputrecord.h"
#include "calc.h"
#include "cpummu.h"
#include "cpummu030.h"
#include "ar.h"
#include "pci.h"
#include "ppc/ppcd.h"
#include "uae/io.h"
#include "uae/ppc.h"
#include "drawing.h"
#include "devices.h"
#include "blitter.h"
#include "ini.h"
#include "readcpu.h"
#include "cputbl.h"
#include "keybuf.h"
static int trace_mode;
static uae_u32 trace_param[3];
int debugger_active;
static int debug_rewind;
static int memwatch_triggered;
static int inside_debugger;
int debugger_used;
int memwatch_access_validator;
int memwatch_enabled;
int debugging;
int exception_debugging;
int no_trace_exceptions;
int debug_copper = 0;
int debug_dma = 0, debug_heatmap = 0;
int debug_sprite_mask = 0xff;
int debug_illegal = 0;
uae_u64 debug_illegal_mask;
static int debug_mmu_mode;
static bool break_if_enforcer;
static uaecptr debug_pc;
static int trace_cycles;
static int last_hpos1, last_hpos2;
static int last_vpos1, last_vpos2;
static int last_frame = -1;
static uae_u32 last_cycles1, last_cycles2;
static uaecptr processptr;
static uae_char *processname;
static uaecptr debug_copper_pc;
extern int audio_channel_mask;
extern int inputdevice_logging;
static void debug_cycles(void)
{
trace_cycles = 1;
last_cycles2 = get_cycles();
last_vpos2 = vpos;
last_hpos2 = current_hpos();
}
void deactivate_debugger (void)
{
inside_debugger = 0;
debugger_active = 0;
debugging = 0;
exception_debugging = 0;
processptr = 0;
xfree (processname);
processname = NULL;
debugmem_enable();
debug_pc = 0xffffffff;
keybuf_ignore_next_release();
}
void activate_debugger (void)
{
disasm_init();
if (isfullscreen() > 0)
return;
debugger_load_libraries();
debugger_used = 1;
inside_debugger = 1;
debug_pc = 0xffffffff;
trace_mode = 0;
if (debugger_active) {
// already in debugger but some break point triggered
// during disassembly etc..
return;
}
debug_cycles();
debugger_active = 1;
set_special (SPCFLAG_BRK);
debugging = 1;
mmu_triggered = 0;
debugmem_disable();
}
void activate_debugger_new(void)
{
activate_debugger();
debug_pc = M68K_GETPC;
}
void activate_debugger_new_pc(uaecptr pc, int len)
{
activate_debugger();
trace_mode = TRACE_RANGE_PC;
trace_param[0] = pc;
trace_param[1] = pc + len;
}
bool debug_enforcer(void)
{
if (!break_if_enforcer)
return false;
activate_debugger();
return true;
}
int firsthist = 0;
int lasthist = 0;
struct cpuhistory {
struct regstruct regs;
int fp, vpos, hpos;
};
static struct cpuhistory history[MAX_HIST];
static const TCHAR help[] = {
_T(" HELP for UAE Debugger\n")
_T(" -----------------------\n\n")
_T(" g [<address>] Start execution at the current address or <address>.\n")
_T(" c Dump state of the CIA, disk drives and custom registers.\n")
_T(" r Dump state of the CPU.\n")
_T(" r <reg> <value> Modify CPU registers (Dx,Ax,USP,ISP,VBR,...).\n")
_T(" rc[d] Show CPU instruction or data cache contents.\n")
_T(" m <address> [<lines>] Memory dump starting at <address>.\n")
_T(" a <address> Assembler.\n")
_T(" d <address> [<lines>] Disassembly starting at <address>.\n")
_T(" t [instructions] Step one or more instructions.\n")
_T(" z Step through one instruction - useful for JSR, DBRA etc.\n")
_T(" f Step forward until PC in RAM (\"boot block finder\").\n")
_T(" f <address> Add/remove breakpoint.\n")
_T(" fa <address> [<start>] [<end>]\n")
_T(" Find effective address <address>.\n")
_T(" fi Step forward until PC points to RTS, RTD or RTE.\n")
_T(" fi <opcode> [<w2>] [<w3>] Step forward until PC points to <opcode>.\n")
_T(" fp \"<name>\"/<addr> Step forward until process <name> or <addr> is active.\n")
_T(" fl List breakpoints.\n")
_T(" fd Remove all breakpoints.\n")
_T(" fs <lines to wait> | <vpos> <hpos> Wait n scanlines/position.\n")
_T(" fc <CCKs to wait> Wait n color clocks.\n")
_T(" fo <num> <reg> <oper> <val> [<mask> <val2>] Conditional register breakpoint.\n")
_T(" reg=Dx,Ax,PC,USP,ISP,VBR,SR. oper:!=,==,<,>,>=,<=,-,!- (-=val to val2 range).\n")
_T(" f <addr1> <addr2> Step forward until <addr1> <= PC <= <addr2>.\n")
_T(" e[x] Dump contents of all custom registers, ea = AGA colors.\n")
_T(" i [<addr>] Dump contents of interrupt and trap vectors.\n")
_T(" il [<mask>] Exception breakpoint.\n")
_T(" o <0-2|addr> [<lines>]View memory as Copper instructions.\n")
_T(" od Enable/disable Copper vpos/hpos tracing.\n")
_T(" ot Copper single step trace.\n")
_T(" ob <addr> Copper breakpoint.\n")
_T(" H[H] <cnt> Show PC history (HH=full CPU info) <cnt> instructions.\n")
_T(" C <value> Search for values like energy or lifes in games.\n")
_T(" Cl List currently found trainer addresses.\n")
_T(" D[idxzs <[max diff]>] Deep trainer. i=new value must be larger, d=smaller,\n")
_T(" x = must be same, z = must be different, s = restart.\n")
_T(" W <addr> <values[.x] separated by space> Write into Amiga memory.\n")
_T(" W <addr> 'string' Write into Amiga memory.\n")
_T(" Wf <addr> <endaddr> <bytes or string like above>, fill memory.\n")
_T(" Wc <addr> <endaddr> <destaddr>, copy memory.\n")
_T(" w <num> <address> <length> <R/W/I> <F/C/L/N> [<value>[.x]] (read/write/opcode) (freeze/mustchange/logonly/nobreak).\n")
_T(" Add/remove memory watchpoints.\n")
_T(" wd [<0-1>] Enable illegal access logger. 1 = enable break.\n")
_T(" L <file> <addr> [<n>] Load a block of Amiga memory.\n")
_T(" S <file> <addr> <n> Save a block of Amiga memory.\n")
_T(" s \"<string>\"/<values> [<addr>] [<length>]\n")
_T(" Search for string/bytes.\n")
_T(" T or Tt Show exec tasks and their PCs.\n")
_T(" Td,Tl,Tr,Tp,Ts,TS,Ti,TO,TM,Tf Show devs, libs, resources, ports, semaphores,\n")
_T(" residents, interrupts, doslist, memorylist, fsres.\n")
_T(" b Step to previous state capture position.\n")
_T(" M<a/b/s> <val> Enable or disable audio channels, bitplanes or sprites.\n")
_T(" sp <addr> [<addr2][<size>] Dump sprite information.\n")
_T(" di <mode> [<track>] Break on disk access. R=DMA read,W=write,RW=both,P=PIO.\n")
_T(" Also enables level 1 disk logging.\n")
_T(" did <log level> Enable disk logging.\n")
_T(" dj [<level bitmask>] Enable joystick/mouse input debugging.\n")
_T(" smc [<0-1>] Enable self-modifying code detector. 1 = enable break.\n")
_T(" dm Dump current address space map.\n")
_T(" v <vpos> [<hpos>] Show DMA data (accurate only in cycle-exact mode).\n")
_T(" v [-1 to -4] = enable visual DMA debugger.\n")
_T(" vh [<ratio> <lines>] \"Heat map\"\n")
_T(" I <custom event> Send custom event string\n")
_T(" ?<value> Hex ($ and 0x)/Bin (%)/Dec (!) converter and calculator.\n")
#ifdef _WIN32
_T(" x Close debugger.\n")
_T(" xx Switch between console and GUI debugger.\n")
_T(" mg <address> Memory dump starting at <address> in GUI.\n")
_T(" dg <address> Disassembly starting at <address> in GUI.\n")
#endif
_T(" q Quit the emulator. You don't want to use this command.\n\n")
};
void debug_help (void)
{
console_out (help);
}
struct mw_acc {
uae_u32 mask;
const TCHAR *name;
};
static const struct mw_acc memwatch_access_masks[] =
{
{ MW_MASK_ALL, _T("ALL") },
{ MW_MASK_NONE, _T("NONE") },
{ MW_MASK_ALL & ~(MW_MASK_CPU_I | MW_MASK_CPU_D_R | MW_MASK_CPU_D_W), _T("DMA") },
{ MW_MASK_BLITTER_A | MW_MASK_BLITTER_B | MW_MASK_BLITTER_C | MW_MASK_BLITTER_D_N | MW_MASK_BLITTER_D_L | MW_MASK_BLITTER_D_F, _T("BLT") },
{ MW_MASK_BLITTER_D_N | MW_MASK_BLITTER_D_L | MW_MASK_BLITTER_D_F, _T("BLTD") },
{ MW_MASK_AUDIO_0 | MW_MASK_AUDIO_1 | MW_MASK_AUDIO_2 | MW_MASK_AUDIO_3, _T("AUD") },
{ MW_MASK_BPL_0 | MW_MASK_BPL_1 | MW_MASK_BPL_2 | MW_MASK_BPL_3 |
MW_MASK_BPL_4 | MW_MASK_BPL_5 | MW_MASK_BPL_6 | MW_MASK_BPL_7, _T("BPL") },
{ MW_MASK_SPR_0 | MW_MASK_SPR_1 | MW_MASK_SPR_2 | MW_MASK_SPR_3 |
MW_MASK_SPR_4 | MW_MASK_SPR_5 | MW_MASK_SPR_6 | MW_MASK_SPR_7, _T("SPR") },
{ MW_MASK_CPU_I | MW_MASK_CPU_D_R | MW_MASK_CPU_D_W, _T("CPU") },
{ MW_MASK_CPU_D_R | MW_MASK_CPU_D_W, _T("CPUD") },
{ MW_MASK_CPU_I, _T("CPUI") },
{ MW_MASK_CPU_D_R, _T("CPUDR") },
{ MW_MASK_CPU_D_W, _T("CPUDW") },
{ MW_MASK_COPPER, _T("COP") },
{ MW_MASK_BLITTER_A, _T("BLTA") },
{ MW_MASK_BLITTER_B, _T("BLTB") },
{ MW_MASK_BLITTER_C, _T("BLTC") },
{ MW_MASK_BLITTER_D_N, _T("BLTDN") },
{ MW_MASK_BLITTER_D_L, _T("BLTDL") },
{ MW_MASK_BLITTER_D_F, _T("BLTDF") },
{ MW_MASK_DISK, _T("DSK") },
{ MW_MASK_AUDIO_0, _T("AUD0") },
{ MW_MASK_AUDIO_1, _T("AUD1") },
{ MW_MASK_AUDIO_2, _T("AUD2") },
{ MW_MASK_AUDIO_3, _T("AUD3") },
{ MW_MASK_BPL_0, _T("BPL0") },
{ MW_MASK_BPL_1, _T("BPL1") },
{ MW_MASK_BPL_2, _T("BPL2") },
{ MW_MASK_BPL_3, _T("BPL3") },
{ MW_MASK_BPL_4, _T("BPL4") },
{ MW_MASK_BPL_5, _T("BPL5") },
{ MW_MASK_BPL_6, _T("BPL6") },
{ MW_MASK_BPL_7, _T("BPL7") },
{ MW_MASK_SPR_0, _T("SPR0") },
{ MW_MASK_SPR_1, _T("SPR1") },
{ MW_MASK_SPR_2, _T("SPR2") },
{ MW_MASK_SPR_3, _T("SPR3") },
{ MW_MASK_SPR_4, _T("SPR4") },
{ MW_MASK_SPR_5, _T("SPR5") },
{ MW_MASK_SPR_6, _T("SPR6") },
{ MW_MASK_SPR_7, _T("SPR7") },
{ 0, NULL },
};
static void mw_help(void)
{
for (int i = 0; memwatch_access_masks[i].mask; i++) {
console_out_f(_T("%s "), memwatch_access_masks[i].name);
}
console_out_f(_T("\n"));
}
static int debug_linecounter;
#define MAX_LINECOUNTER 1000
static int debug_out (const TCHAR *format, ...)
{
va_list parms;
TCHAR buffer[4000];
va_start (parms, format);
_vsntprintf (buffer, 4000 - 1, format, parms);
va_end (parms);
console_out (buffer);
if (debug_linecounter < MAX_LINECOUNTER)
debug_linecounter++;
if (debug_linecounter >= MAX_LINECOUNTER)
return 0;
return 1;
}
uae_u32 get_byte_debug (uaecptr addr)
{
uae_u32 v = 0xff;
if (debug_mmu_mode) {
flagtype olds = regs.s;
regs.s = (debug_mmu_mode & 4) != 0;
TRY(p) {
if (currprefs.mmu_model == 68030) {
v = mmu030_get_generic (addr, debug_mmu_mode, sz_byte, MMU030_SSW_SIZE_B);
} else {
if (debug_mmu_mode & 1) {
bool odd = (addr & 1) != 0;
addr &= ~1;
v = mmu_get_iword(addr, sz_byte);
if (!odd)
v >>= 8;
} else {
v = mmu_get_user_byte (addr, regs.s != 0, false, sz_byte, false);
}
}
} CATCH(p) {
} ENDTRY
regs.s = olds;
} else {
v = get_byte (addr);
}
return v;
}
uae_u32 get_word_debug (uaecptr addr)
{
uae_u32 v = 0xffff;
if (debug_mmu_mode) {
flagtype olds = regs.s;
regs.s = (debug_mmu_mode & 4) != 0;
TRY(p) {
if (currprefs.mmu_model == 68030) {
v = mmu030_get_generic (addr, debug_mmu_mode, sz_word, MMU030_SSW_SIZE_W);
} else {
if (debug_mmu_mode & 1) {
v = mmu_get_iword(addr, sz_word);
} else {
v = mmu_get_user_word (addr, regs.s != 0, false, sz_word, false);
}
}
} CATCH(p) {
} ENDTRY
regs.s = olds;
} else {
v = get_word (addr);
}
return v;
}
uae_u32 get_long_debug (uaecptr addr)
{
uae_u32 v = 0xffffffff;
if (debug_mmu_mode) {
flagtype olds = regs.s;
regs.s = (debug_mmu_mode & 4) != 0;
TRY(p) {
if (currprefs.mmu_model == 68030) {
v = mmu030_get_generic (addr, debug_mmu_mode, sz_long, MMU030_SSW_SIZE_L);
} else {
if (debug_mmu_mode & 1) {
v = mmu_get_ilong(addr, sz_long);
} else {
v = mmu_get_user_long (addr, regs.s != 0, false, sz_long, false);
}
}
} CATCH(p) {
} ENDTRY
regs.s = olds;
} else {
v = get_long (addr);
}
return v;
}
uae_u32 get_iword_debug (uaecptr addr)
{
if (debug_mmu_mode) {
return get_word_debug (addr);
} else {
if (valid_address (addr, 2))
return get_word (addr);
return 0xffff;
}
}
uae_u32 get_ilong_debug (uaecptr addr)
{
if (debug_mmu_mode) {
return get_long_debug (addr);
} else {
if (valid_address (addr, 4))
return get_long (addr);
return 0xffffffff;
}
}
uae_u8 *get_real_address_debug(uaecptr addr)
{
if (debug_mmu_mode) {
flagtype olds = regs.s;
TRY(p) {
if (currprefs.mmu_model >= 68040)
addr = mmu_translate(addr, 0, regs.s != 0, (debug_mmu_mode & 1), false, 0);
else
addr = mmu030_translate(addr, regs.s != 0, (debug_mmu_mode & 1), false);
} CATCH(p) {
} ENDTRY
}
return get_real_address(addr);
}
int debug_safe_addr (uaecptr addr, int size)
{
if (debug_mmu_mode) {
flagtype olds = regs.s;
regs.s = (debug_mmu_mode & 4) != 0;
TRY(p) {
if (currprefs.mmu_model >= 68040)
addr = mmu_translate (addr, 0, regs.s != 0, (debug_mmu_mode & 1), false, size);
else
addr = mmu030_translate (addr, regs.s != 0, (debug_mmu_mode & 1), false);
} CATCH(p) {
STOPTRY;
return 0;
} ENDTRY
regs.s = olds;
}
addrbank *ab = &get_mem_bank (addr);
if (!ab)
return 0;
if (ab->flags & ABFLAG_SAFE)
return 1;
if (!ab->check (addr, size))
return 0;
if (ab->flags & (ABFLAG_RAM | ABFLAG_ROM | ABFLAG_ROMIN | ABFLAG_SAFE))
return 1;
return 0;
}
static bool iscancel (int counter)
{
static int cnt;
cnt++;
if (cnt < counter)
return false;
cnt = 0;
if (!console_isch ())
return false;
console_getch ();
return true;
}
static bool isoperator(TCHAR **cp)
{
TCHAR c = **cp;
return c == '+' || c == '-' || c == '/' || c == '*' || c == '(' || c == ')';
}
static void ignore_ws (TCHAR **c)
{
while (**c && _istspace(**c))
(*c)++;
}
static TCHAR peekchar (TCHAR **c)
{
return **c;
}
static TCHAR readchar (TCHAR **c)
{
TCHAR cc = **c;
(*c)++;
return cc;
}
static TCHAR next_char(TCHAR **c)
{
ignore_ws (c);
return *(*c)++;
}
static TCHAR next_char2(TCHAR **c)
{
return *(*c)++;
}
static TCHAR peek_next_char (TCHAR **c)
{
TCHAR *pc = *c;
return pc[1];
}
static int more_params(TCHAR **c)
{
ignore_ws(c);
return (**c) != 0;
}
static int more_params2(TCHAR **c)
{
return (**c) != 0;
}
static uae_u32 readint (TCHAR **c);
static uae_u32 readbin (TCHAR **c);
static uae_u32 readhex (TCHAR **c);
static const TCHAR *debugoper[] = {
_T("=="),
_T("!="),
_T("<="),
_T(">="),
_T("<"),
_T(">"),
_T("-"),
_T("!-"),
NULL
};
static int getoperidx(TCHAR **c)
{
int i;
TCHAR *p = *c;
TCHAR tmp[10];
int extra = 0;
i = 0;
while (p[i]) {
tmp[i] = _totupper(p[i]);
if (i >= sizeof(tmp) / sizeof(TCHAR) - 1)
break;
i++;
}
tmp[i] = 0;
if (!_tcsncmp(tmp, _T("!="), 2)) {
(*c) += 2;
return BREAKPOINT_CMP_NEQUAL;
} else if (!_tcsncmp(tmp, _T("=="), 2)) {
(*c) += 2;
return BREAKPOINT_CMP_EQUAL;
} else if (!_tcsncmp(tmp, _T(">="), 2)) {
(*c) += 2;
return BREAKPOINT_CMP_LARGER_EQUAL;
} else if (!_tcsncmp(tmp, _T("<="), 2)) {
(*c) += 2;
return BREAKPOINT_CMP_SMALLER_EQUAL;
} else if (!_tcsncmp(tmp, _T(">"), 1)) {
(*c) += 1;
return BREAKPOINT_CMP_LARGER;
} else if (!_tcsncmp(tmp, _T("<"), 1)) {
(*c) += 1;
return BREAKPOINT_CMP_SMALLER;
} else if (!_tcsncmp(tmp, _T("-"), 1)) {
(*c) += 1;
return BREAKPOINT_CMP_RANGE;
} else if (!_tcsncmp(tmp, _T("!-"), 2)) {
(*c) += 2;
return BREAKPOINT_CMP_NRANGE;
}
return -1;
}
static const TCHAR *debugregs[] = {
_T("D0"),
_T("D1"),
_T("D2"),
_T("D3"),
_T("D4"),
_T("D5"),
_T("D6"),
_T("D7"),
_T("A0"),
_T("A1"),
_T("A2"),
_T("A3"),
_T("A4"),
_T("A5"),
_T("A6"),
_T("A7"),
_T("PC"),
_T("USP"),
_T("MSP"),
_T("ISP"),
_T("VBR"),
_T("SR"),
_T("CCR"),
_T("CACR"),
_T("CAAR"),
_T("SFC"),
_T("DFC"),
_T("TC"),
_T("ITT0"),
_T("ITT1"),
_T("DTT0"),
_T("DTT1"),
_T("BUSC"),
_T("PCR"),
NULL
};
static int getregidx(TCHAR **c)
{
int i;
TCHAR *p = *c;
TCHAR tmp[10];
int extra = 0;
i = 0;
while (p[i]) {
tmp[i] = _totupper(p[i]);
if (i >= sizeof(tmp) / sizeof(TCHAR) - 1)
break;
i++;
}
tmp[i] = 0;
for (int i = 0; debugregs[i]; i++) {
if (!_tcsncmp(tmp, debugregs[i], _tcslen(debugregs[i]))) {
(*c) += _tcslen(debugregs[i]);
return i;
}
}
return -1;
}
static uae_u32 returnregx(int regid)
{
if (regid < BREAKPOINT_REG_PC)
return regs.regs[regid];
switch(regid)
{
case BREAKPOINT_REG_PC:
return M68K_GETPC;
case BREAKPOINT_REG_USP:
return regs.usp;
case BREAKPOINT_REG_MSP:
return regs.msp;
case BREAKPOINT_REG_ISP:
return regs.isp;
case BREAKPOINT_REG_VBR:
return regs.vbr;
case BREAKPOINT_REG_SR:
MakeSR();
return regs.sr;
case BREAKPOINT_REG_CCR:
MakeSR();
return regs.sr & 31;
case BREAKPOINT_REG_CACR:
return regs.cacr;
case BREAKPOINT_REG_CAAR:
return regs.caar;
case BREAKPOINT_REG_SFC:
return regs.sfc;
case BREAKPOINT_REG_DFC:
return regs.dfc;
case BREAKPOINT_REG_TC:
if (currprefs.cpu_model == 68030)
return tc_030;
return regs.tcr;
case BREAKPOINT_REG_ITT0:
if (currprefs.cpu_model == 68030)
return tt0_030;
return regs.itt0;
case BREAKPOINT_REG_ITT1:
if (currprefs.cpu_model == 68030)
return tt1_030;
return regs.itt1;
case BREAKPOINT_REG_DTT0:
return regs.dtt0;
case BREAKPOINT_REG_DTT1:
return regs.dtt1;
case BREAKPOINT_REG_BUSC:
return regs.buscr;
case BREAKPOINT_REG_PCR:
return regs.fpcr;
}
return 0;
}
static int readregx (TCHAR **c, uae_u32 *valp)
{
int i;
uae_u32 addr;
TCHAR *p = *c;
TCHAR tmp[10], *tp;
int extra = 0;
addr = 0;
i = 0;
while (p[i]) {
tmp[i] = _totupper (p[i]);
if (i >= sizeof (tmp) / sizeof (TCHAR) - 1)
break;
i++;
}
tmp[i] = 0;
tp = tmp;
if (_totupper (tmp[0]) == 'R') {
tp = tmp + 1;
extra = 1;
}
if (!_tcsncmp (tp, _T("USP"), 3)) {
addr = regs.usp;
(*c) += 3;
} else if (!_tcsncmp (tp, _T("VBR"), 3)) {
addr = regs.vbr;
(*c) += 3;
} else if (!_tcsncmp (tp, _T("MSP"), 3)) {
addr = regs.msp;
(*c) += 3;
} else if (!_tcsncmp (tp, _T("ISP"), 3)) {
addr = regs.isp;
(*c) += 3;
} else if (!_tcsncmp (tp, _T("PC"), 2)) {
addr = regs.pc;
(*c) += 2;
} else if (tp[0] == 'A' || tp[0] == 'D') {
int reg = 0;
if (tp[0] == 'A')
reg += 8;
reg += tp[1] - '0';
if (reg < 0 || reg > 15)
return 0;
addr = regs.regs[reg];
(*c) += 2;
} else {
return 0;
}
*valp = addr;
(*c) += extra;
return 1;
}
static bool readbinx (TCHAR **c, uae_u32 *valp)
{
uae_u32 val = 0;
bool first = true;
ignore_ws (c);
for (;;) {
TCHAR nc = **c;
if (nc != '1' && nc != '0') {
if (first)
return false;
break;
}
first = false;
(*c)++;
val <<= 1;
if (nc == '1')
val |= 1;
}
*valp = val;
return true;
}
static bool readhexx (TCHAR **c, uae_u32 *valp)
{
uae_u32 val = 0;
TCHAR nc;
ignore_ws (c);
if (!isxdigit (peekchar (c)))
return false;
while (isxdigit (nc = **c)) {
(*c)++;
val *= 16;
nc = _totupper (nc);
if (isdigit (nc)) {
val += nc - '0';
} else {
val += nc - 'A' + 10;
}
}
*valp = val;
return true;
}
static bool readintx (TCHAR **c, uae_u32 *valp)
{
uae_u32 val = 0;
TCHAR nc;
int negative = 0;
ignore_ws (c);
if (**c == '-')
negative = 1, (*c)++;
if (!isdigit (peekchar (c)))
return false;
while (isdigit (nc = **c)) {
(*c)++;
val *= 10;
val += nc - '0';
}
*valp = val * (negative ? -1 : 1);
return true;
}
static int checkvaltype2 (TCHAR **c, uae_u32 *val, TCHAR def)
{
TCHAR nc;
ignore_ws (c);
nc = _totupper (**c);
if (nc == '!') {
(*c)++;
return readintx (c, val) ? 1 : 0;
}
if (nc == '$') {
(*c)++;
return readhexx (c, val) ? 1 : 0;
}
if (nc == '0' && _totupper ((*c)[1]) == 'X') {
(*c)+= 2;
return readhexx (c, val) ? 1 : 0;
}
if (nc == '%') {
(*c)++;
return readbinx (c, val) ? 1: 0;
}
if (nc >= 'A' && nc <= 'Z' && nc != 'A' && nc != 'D') {
if (readregx (c, val))
return 1;
}
TCHAR name[256];
name[0] = 0;
for (int i = 0; i < sizeof name / sizeof(TCHAR) - 1; i++) {
nc = (*c)[i];
if (nc == 0 || nc == ' ')
break;
name[i] = nc;
name[i + 1] = 0;
}
if (name[0]) {
TCHAR *np = name;
if (*np == '#')
np++;
if (debugmem_get_symbol_value(np, val)) {
(*c) += _tcslen(name);
return 1;
}
}
if (def == '!') {
return readintx (c, val) ? -1 : 0;
} else if (def == '$') {
return readhexx (c, val) ? -1 : 0;
} else if (def == '%') {
return readbinx (c, val) ? -1 : 0;
}
return 0;
}
static int readsize (int val, TCHAR **c)
{
TCHAR cc = _totupper (readchar(c));
if (cc == 'B')
return 1;
if (cc == 'W')
return 2;
if (cc == '3')
return 3;
if (cc == 'L')
return 4;
return 0;
}
static int checkvaltype (TCHAR **cp, uae_u32 *val, int *size, TCHAR def)
{
TCHAR form[256], *p;
bool gotop = false;
double out;
form[0] = 0;
if (size)
*size = 0;
p = form;
for (;;) {
uae_u32 v;
if (!checkvaltype2 (cp, &v, def))
return 0;
*val = v;
// stupid but works!
_stprintf(p, _T("%u"), v);
p += _tcslen (p);
if (peekchar (cp) == '.') {
readchar (cp);
if (size)
*size = readsize (v, cp);
}
if (!isoperator (cp))
break;
gotop = true;
*p++= readchar (cp);
*p = 0;
}
if (!gotop) {
if (size && *size == 0) {
uae_s32 v = (uae_s32)(*val);
if (v > 65535 || v < -32767) {
*size = 4;
} else if (v > 255 || v < -127) {
*size = 2;
} else {
*size = 1;
}
}
return 1;
}
if (calc (form, &out)) {
*val = (uae_u32)out;
if (size && *size == 0) {
uae_s32 v = (uae_s32)(*val);
if (v > 255 || v < -127) {
*size = 2;
} else if (v > 65535 || v < -32767) {
*size = 4;
} else {
*size = 1;
}
}
return 1;
}
return 0;
}
static uae_u32 readnum (TCHAR **c, int *size, TCHAR def)
{
uae_u32 val;
if (checkvaltype (c, &val, size, def))
return val;
return 0;
}
static uae_u32 readint (TCHAR **c)
{
int size;
return readnum (c, &size, '!');
}
static uae_u32 readhex (TCHAR **c)
{
int size;
return readnum (c, &size, '$');
}
static uae_u32 readbin (TCHAR **c)
{
int size;
return readnum (c, &size, '%');
}
static uae_u32 readint (TCHAR **c, int *size)
{
return readnum (c, size, '!');
}
static uae_u32 readhex (TCHAR **c, int *size)
{
return readnum (c, size, '$');
}
static int next_string (TCHAR **c, TCHAR *out, int max, int forceupper)
{
TCHAR *p = out;
int startmarker = 0;