forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.cpp
3872 lines (3610 loc) · 86 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 "cia.h"
#include "xwin.h"
#include "identify.h"
#include "audio.h"
#include "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"
int debugger_active;
static uaecptr skipaddr_start, skipaddr_end;
static int skipaddr_doskip;
static uae_u32 skipins;
static int do_skip;
static int debug_rewind;
static int memwatch_enabled, memwatch_triggered;
static uae_u16 sr_bpmask, sr_bpvalue;
int debugging;
int exception_debugging;
int no_trace_exceptions;
int debug_copper = 0;
int debug_dma = 0;
int debug_sprite_mask = 0xff;
int debug_illegal = 0;
uae_u64 debug_illegal_mask;
static uaecptr processptr;
static uae_char *processname;
static uaecptr debug_copper_pc;
extern int audio_channel_mask;
extern int inputdevice_logging;
void deactivate_debugger (void)
{
debugger_active = 0;
debugging = 0;
exception_debugging = 0;
processptr = 0;
xfree (processname);
processname = NULL;
}
void activate_debugger (void)
{
do_skip = 0;
if (debugger_active)
return;
debugger_active = 1;
set_special (SPCFLAG_BRK);
debugging = 1;
mmu_triggered = 0;
}
int firsthist = 0;
int lasthist = 0;
static struct regstruct history[MAX_HIST];
static TCHAR help[] = {
L" HELP for UAE Debugger\n"
L" -----------------------\n\n"
L" g [<address>] Start execution at the current address or <address>.\n"
L" c Dump state of the CIA, disk drives and custom registers.\n"
L" r Dump state of the CPU.\n"
L" r <reg> <value> Modify CPU registers (Dx,Ax,USP,ISP,VBR,...).\n"
L" m <address> [<lines>] Memory dump starting at <address>.\n"
L" d <address> [<lines>] Disassembly starting at <address>.\n"
L" t [instructions] Step one or more instructions.\n"
L" z Step through one instruction - useful for JSR, DBRA etc.\n"
L" f Step forward until PC in RAM (\"boot block finder\").\n"
L" f <address> Add/remove breakpoint.\n"
L" fa <address> [<start>] [<end>]\n"
L" Find effective address <address>.\n"
L" fi Step forward until PC points to RTS, RTD or RTE.\n"
L" fi <opcode> Step forward until PC points to <opcode>.\n"
L" fp \"<name>\"/<addr> Step forward until process <name> or <addr> is active.\n"
L" fl List breakpoints.\n"
L" fd Remove all breakpoints.\n"
L" fs <val> <mask> Break when (SR & mask) = val.\n"
L" f <addr1> <addr2> Step forward until <addr1> <= PC <= <addr2>.\n"
L" e Dump contents of all custom registers, ea = AGA colors.\n"
L" i [<addr>] Dump contents of interrupt and trap vectors.\n"
L" il [<mask>] Exception breakpoint.\n"
L" o <0-2|addr> [<lines>]View memory as Copper instructions.\n"
L" od Enable/disable Copper vpos/hpos tracing.\n"
L" ot Copper single step trace.\n"
L" ob <addr> Copper breakpoint.\n"
L" H[H] <cnt> Show PC history (HH=full CPU info) <cnt> instructions.\n"
L" C <value> Search for values like energy or lifes in games.\n"
L" Cl List currently found trainer addresses.\n"
L" D[idxzs <[max diff]>] Deep trainer. i=new value must be larger, d=smaller,\n"
L" x = must be same, z = must be different, s = restart.\n"
L" W <address> <value[.x]> Write into Amiga memory.\n"
L" w <num> <address> <length> <R/W/I/F/C> [<value>[.x]] (read/write/opcode/freeze/mustchange).\n"
L" Add/remove memory watchpoints.\n"
L" wd [<0-1>] Enable illegal access logger. 1 = enable break.\n"
L" S <file> <addr> <n> Save a block of Amiga memory.\n"
L" s \"<string>\"/<values> [<addr>] [<length>]\n"
L" Search for string/bytes.\n"
L" T or Tt Show exec tasks and their PCs.\n"
L" Td,Tl,Tr Show devices, libraries or resources.\n"
L" b Step to previous state capture position.\n"
L" M<a/b/s> <val> Enable or disable audio channels, bitplanes or sprites.\n"
L" sp <addr> [<addr2][<size>] Dump sprite information.\n"
L" di <mode> [<track>] Break on disk access. R=DMA read,W=write,RW=both,P=PIO.\n"
L" Also enables level 1 disk logging.\n"
L" did <log level> Enable disk logging.\n"
L" dj [<level bitmask>] Enable joystick/mouse input debugging.\n"
L" smc [<0-1>] Enable self-modifying code detector. 1 = enable break.\n"
L" dm Dump current address space map.\n"
L" v <vpos> [<hpos>] Show DMA data (accurate only in cycle-exact mode).\n"
L" v [-1 to -4] = enable visual DMA debugger.\n"
L" ?<value> Hex/Bin/Dec converter.\n"
#ifdef _WIN32
L" x Close debugger.\n"
L" xx Switch between console and GUI debugger.\n"
L" mg <address> Memory dump starting at <address> in GUI.\n"
L" dg <address> Disassembly starting at <address> in GUI.\n"
#endif
L" q Quit the emulator. You don't want to use this command.\n\n"
};
void debug_help (void)
{
console_out (help);
}
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;
}
static void ignore_ws (TCHAR **c)
{
while (**c && _istspace(**c))
(*c)++;
}
static uae_u32 readint (TCHAR **c);
static uae_u32 readbin (TCHAR **c);
static uae_u32 readhex (TCHAR **c);
static int readregx (TCHAR **c, uae_u32 *valp)
{
int i;
uae_u32 addr;
TCHAR *p = *c;
TCHAR tmp[10];
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;
if (_totupper (tmp[0]) == 'R') {
memmove (tmp, tmp + 1, sizeof (tmp) - sizeof (TCHAR));
extra = 1;
}
if (!_tcscmp (tmp, L"USP")) {
addr = regs.usp;
(*c) += 3;
} else if (!_tcscmp (tmp, L"VBR")) {
addr = regs.vbr;
(*c) += 3;
} else if (!_tcscmp (tmp, L"MSP")) {
addr = regs.msp;
(*c) += 3;
} else if (!_tcscmp (tmp, L"ISP")) {
addr = regs.isp;
(*c) += 3;
} else if (!_tcscmp (tmp, L"PC")) {
addr = regs.pc;
(*c) += 2;
} else if (tmp[0] == 'A' || tmp[0] == 'D') {
int reg = 0;
if (tmp[0] == 'A')
reg += 8;
reg += tmp[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 uae_u32 readbinx (TCHAR **c)
{
uae_u32 val = 0;
ignore_ws (c);
for (;;) {
TCHAR nc = **c;
if (nc != '1' && nc != '0')
break;
(*c)++;
val <<= 1;
if (nc == '1')
val |= 1;
}
return val;
}
static uae_u32 readhexx (TCHAR **c)
{
uae_u32 val = 0;
TCHAR nc;
ignore_ws (c);
while (isxdigit (nc = **c)) {
(*c)++;
val *= 16;
nc = _totupper (nc);
if (isdigit (nc)) {
val += nc - '0';
} else {
val += nc - 'A' + 10;
}
}
return val;
}
static uae_u32 readintx (TCHAR **c)
{
uae_u32 val = 0;
TCHAR nc;
int negative = 0;
ignore_ws (c);
if (**c == '-')
negative = 1, (*c)++;
while (isdigit (nc = **c)) {
(*c)++;
val *= 10;
val += nc - '0';
}
return val * (negative ? -1 : 1);
}
static int checkvaltype (TCHAR **c, uae_u32 *val)
{
TCHAR nc;
ignore_ws (c);
nc = _totupper (**c);
if (nc == '!') {
(*c)++;
*val = readintx (c);
return 1;
}
if (nc == '$') {
(*c)++;
*val = readhexx (c);
return 1;
}
if (nc == '0' && _totupper ((*c)[1]) == 'X') {
(*c)+= 2;
*val = readhexx (c);
return 1;
}
if (nc == '%') {
(*c)++;
*val = readbinx (c);
return 1;
}
if (nc >= 'A' && nc <= 'Z' && nc != 'A' && nc != 'D') {
if (readregx (c, val))
return 1;
}
return 0;
}
static int readsize (int val, TCHAR **c)
{
if ((*c)[0] == '.') {
(*c)++;
TCHAR cc = _totupper ((*c)[0]);
(*c)++;
if (cc == 'B')
return 1;
if (cc == 'W')
return 2;
if (cc == '3')
return 3;
if (cc == 'L')
return 4;
}
if (val > 255 || val < -127)
return 2;
if (val > 65535 || val < -32767)
return 4;
return 1;
}
static uae_u32 readint (TCHAR **c)
{
uae_u32 val;
if (checkvaltype (c, &val))
return val;
return readintx (c);
}
static uae_u32 readhex (TCHAR **c)
{
uae_u32 val;
if (checkvaltype (c, &val))
return val;
return readhexx (c);
}
static uae_u32 readint (TCHAR **c, int *size)
{
uae_u32 val = readint (c);
*size = readsize (val, c);
return val;
}
static uae_u32 readhex (TCHAR **c, int *size)
{
uae_u32 val = readhex (c);
*size = readsize (val, c);
return val;
}
static uae_u32 readbin (TCHAR **c)
{
uae_u32 val;
if (checkvaltype (c, &val))
return val;
return readbinx (c);
}
static TCHAR next_char (TCHAR **c)
{
ignore_ws (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 next_string (TCHAR **c, TCHAR *out, int max, int forceupper)
{
TCHAR *p = out;
int startmarker = 0;
if (**c == '\"') {
startmarker = 1;
(*c)++;
}
*p = 0;
while (**c != 0) {
if (**c == '\"' && startmarker)
break;
if (**c == 32 && !startmarker) {
ignore_ws (c);
break;
}
*p = next_char (c);
if (forceupper)
*p = _totupper(*p);
*++p = 0;
max--;
if (max <= 1)
break;
}
return _tcslen (out);
}
static void converter (TCHAR **c)
{
uae_u32 v = readint (c);
TCHAR s[100];
TCHAR *p = s;
int i;
for (i = 0; i < 32; i++)
s[i] = (v & (1 << (31 - i))) ? '1' : '0';
s[i] = 0;
console_out_f (L"0x%08X = %%%s = %u = %d\n", v, s, v, (uae_s32)v);
}
int notinrom (void)
{
uaecptr pc = munge24 (m68k_getpc ());
if (pc < 0x00e00000 || pc > 0x00ffffff)
return 1;
return 0;
}
static uae_u32 lastaddr (void)
{
if (currprefs.z3fastmem_size)
return z3fastmem_start + currprefs.z3fastmem_size;
if (currprefs.mbresmem_high_size)
return a3000hmem_start + currprefs.mbresmem_high_size;
if (currprefs.mbresmem_low_size)
return a3000lmem_start + currprefs.mbresmem_low_size;
if (currprefs.bogomem_size)
return bogomem_start + currprefs.bogomem_size;
if (currprefs.fastmem_size)
return fastmem_start + currprefs.fastmem_size;
return currprefs.chipmem_size;
}
static uaecptr nextaddr2 (uaecptr addr, int *next)
{
uaecptr prev, prevx;
int size, sizex;
if (addr >= lastaddr ()) {
*next = -1;
return 0xffffffff;
}
prev = currprefs.z3fastmem_start;
size = currprefs.z3fastmem_size;
if (currprefs.mbresmem_high_size) {
sizex = size;
prevx = prev;
size = currprefs.mbresmem_high_size;
prev = a3000hmem_start;
if (addr == prev + size) {
*next = prevx + sizex;
return prevx;
}
}
if (currprefs.mbresmem_low_size) {
prevx = prev;
sizex = size;
size = currprefs.mbresmem_low_size;
prev = a3000lmem_start;
if (addr == prev + size) {
*next = prevx + sizex;
return prevx;
}
}
if (currprefs.bogomem_size) {
sizex = size;
prevx = prev;
size = currprefs.bogomem_size;
prev = bogomem_start;
if (addr == prev + size) {
*next = prevx + sizex;
return prevx;
}
}
if (currprefs.fastmem_size) {
sizex = size;
prevx = prev;
size = currprefs.fastmem_size;
prev = fastmem_start;
if (addr == prev + size) {
*next = prevx + sizex;
return prevx;
}
}
sizex = size;
prevx = prev;
size = currprefs.chipmem_size;
if (addr == size) {
*next = prevx + sizex;
return prevx;
}
if (addr == 1)
*next = size;
return addr;
}
static uaecptr nextaddr (uaecptr addr, uaecptr last, uaecptr *end)
{
uaecptr paddr = addr;
int next;
if (last && 0) {
if (addr >= last)
return 0xffffffff;
return addr + 1;
}
if (addr == 0xffffffff) {
if (end)
*end = currprefs.chipmem_size;
return 0;
}
if (end)
next = *end;
addr = nextaddr2 (addr + 1, &next);
if (end)
*end = next;
#if 0
if (next && addr != 0xffffffff) {
uaecptr xa = addr;
if (xa == 1)
xa = 0;
console_out_f ("%08X -> %08X (%08X)...\n", xa, xa + next - 1, next);
}
#endif
return addr;
}
int safe_addr(uaecptr addr, int size)
{
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;
}
uaecptr dumpmem2 (uaecptr addr, TCHAR *out, int osize)
{
int i, cols = 8;
int nonsafe = 0;
if (osize <= (9 + cols * 5 + 1 + 2 * cols))
return addr;
_stprintf (out, L"%08lX ", addr);
for (i = 0; i < cols; i++) {
uae_u8 b1, b2;
b1 = b2 = 0;
if (safe_addr(addr, 2)) {
b1 = get_byte (addr + 0);
b2 = get_byte (addr + 1);
_stprintf (out + 9 + i * 5, L"%02X%02X ", b1, b2);
out[9 + cols * 5 + 1 + i * 2 + 0] = b1 >= 32 && b1 < 127 ? b1 : '.';
out[9 + cols * 5 + 1 + i * 2 + 1] = b2 >= 32 && b2 < 127 ? b2 : '.';
} else {
nonsafe++;
_tcscpy (out + 9 + i * 5, L"**** ");
out[9 + cols * 5 + 1 + i * 2 + 0] = '*';
out[9 + cols * 5 + 1 + i * 2 + 1] = '*';
}
addr += 2;
}
out[9 + cols * 5] = ' ';
out[9 + cols * 5 + 1 + 2 * cols] = 0;
if (nonsafe == cols) {
addrbank *ab = &get_mem_bank (addr);
if (ab->name)
memcpy (out + (9 + 4 + 1) * sizeof (TCHAR), ab->name, _tcslen (ab->name) * sizeof (TCHAR));
}
return addr;
}
static void dumpmem (uaecptr addr, uaecptr *nxmem, int lines)
{
TCHAR line[MAX_LINEWIDTH + 1];
for (;lines--;) {
addr = dumpmem2 (addr, line, sizeof(line));
debug_out (L"%s", line);
if (!debug_out (L"\n"))
break;
}
*nxmem = addr;
}
static void dump_custom_regs (int aga)
{
int len, i, j, end;
uae_u8 *p1, *p2, *p3, *p4;
if (aga) {
dump_aga_custom();
return;
}
p1 = p2 = save_custom (&len, 0, 1);
p1 += 4; // skip chipset type
for (i = 0; i < 4; i++) {
p4 = p1 + 0xa0 + i * 16;
p3 = save_audio (i, &len, 0);
p4[0] = p3[12];
p4[1] = p3[13];
p4[2] = p3[14];
p4[3] = p3[15];
p4[4] = p3[4];
p4[5] = p3[5];
p4[6] = p3[8];
p4[7] = p3[9];
p4[8] = 0;
p4[9] = p3[1];
p4[10] = p3[10];
p4[11] = p3[11];
free (p3);
}
end = 0;
while (custd[end].name)
end++;
end++;
end /= 2;
for (i = 0; i < end; i++) {
uae_u16 v1, v2;
int addr1, addr2;
j = end + i;
addr1 = custd[i].adr & 0x1ff;
addr2 = custd[j].adr & 0x1ff;
v1 = (p1[addr1 + 0] << 8) | p1[addr1 + 1];
v2 = (p1[addr2 + 0] << 8) | p1[addr2 + 1];
console_out_f (L"%03X %s\t%04X\t%03X %s\t%04X\n",
addr1, custd[i].name, v1,
addr2, custd[j].name, v2);
}
free (p2);
}
static void dump_vectors (uaecptr addr)
{
int i = 0, j = 0;
if (addr == 0xffffffff)
addr = regs.vbr;
while (int_labels[i].name || trap_labels[j].name) {
if (int_labels[i].name) {
console_out_f (L"$%08X %02d: %12s $%08X ", int_labels[i].adr + addr, int_labels[i].adr / 4,
int_labels[i].name, get_long (int_labels[i].adr + addr));
i++;
}
if (trap_labels[j].name) {
console_out_f (L"$%08X %02d: %12s $%08X", trap_labels[j].adr + addr, trap_labels[j].adr / 4,
trap_labels[j].name, get_long (trap_labels[j].adr + addr));
j++;
}
console_out (L"\n");
}
}
static void disassemble_wait (FILE *file, unsigned long insn)
{
int vp, hp, ve, he, bfd, v_mask, h_mask;
int doout = 0;
vp = (insn & 0xff000000) >> 24;
hp = (insn & 0x00fe0000) >> 16;
ve = (insn & 0x00007f00) >> 8;
he = (insn & 0x000000fe);
bfd = (insn & 0x00008000) >> 15;
/* bit15 can never be masked out*/
v_mask = vp & (ve | 0x80);
h_mask = hp & he;
if (v_mask > 0) {
doout = 1;
console_out (L"vpos ");
if (ve != 0x7f) {
console_out_f (L"& 0x%02x ", ve);
}
console_out_f (L">= 0x%02x", v_mask);
}
if (he > 0) {
if (v_mask > 0) {
console_out (L" and");
}
console_out (L" hpos ");
if (he != 0xfe) {
console_out_f (L"& 0x%02x ", he);
}
console_out_f (L">= 0x%02x", h_mask);
} else {
if (doout)
console_out (L", ");
console_out (L", ignore horizontal");
}
console_out_f (L"\n \t; VP %02x, VE %02x; HP %02x, HE %02x; BFD %d\n",
vp, ve, hp, he, bfd);
}
#define NR_COPPER_RECORDS 100000
/* Record copper activity for the debugger. */
struct cop_rec
{
int hpos, vpos;
uaecptr addr;
};
static struct cop_rec *cop_record[2];
static int nr_cop_records[2], curr_cop_set;
#define NR_DMA_REC_HPOS 256
#define NR_DMA_REC_VPOS 1000
static struct dma_rec *dma_record[2];
static int dma_record_toggle;
void record_dma_reset (void)
{
int v, h;
struct dma_rec *dr, *dr2;
if (!dma_record[0])
return;
dma_record_toggle ^= 1;
dr = dma_record[dma_record_toggle];
for (v = 0; v < NR_DMA_REC_VPOS; v++) {
for (h = 0; h < NR_DMA_REC_HPOS; h++) {
dr2 = &dr[v * NR_DMA_REC_HPOS + h];
memset (dr2, 0, sizeof (struct dma_rec));
dr2->reg = 0xffff;
dr2->addr = 0xffffffff;
}
}
}
void record_copper_reset (void)
{
/* Start a new set of copper records. */
curr_cop_set ^= 1;
nr_cop_records[curr_cop_set] = 0;
}
STATIC_INLINE uae_u32 ledcolor (uae_u32 c, uae_u32 *rc, uae_u32 *gc, uae_u32 *bc, uae_u32 *a)
{
uae_u32 v = rc[(c >> 16) & 0xff] | gc[(c >> 8) & 0xff] | bc[(c >> 0) & 0xff];
if (a)
v |= a[255 - ((c >> 24) & 0xff)];
return v;
}
STATIC_INLINE void putpixel (uae_u8 *buf, int bpp, int x, xcolnr c8)
{
if (x <= 0)
return;
switch (bpp) {
case 1:
buf[x] = (uae_u8)c8;
break;
case 2:
{
uae_u16 *p = (uae_u16*)buf + x;
*p = (uae_u16)c8;
break;
}
case 3:
/* no 24 bit yet */
break;
case 4:
{
uae_u32 *p = (uae_u32*)buf + x;
*p = c8;
break;
}
}
}
#define lc(x) ledcolor (x, xredcolors, xgreencolors, xbluecolors, NULL);
void debug_draw_cycles (uae_u8 *buf, int bpp, int line, int width, int height, uae_u32 *xredcolors, uae_u32 *xgreencolors, uae_u32 *xbluescolors)
{
int y, x, xx, dx, xplus, yplus;
struct dma_rec *dr;
int t;
uae_u32 cc[DMARECORD_MAX];
if (debug_dma >= 4)
yplus = 2;
else
yplus = 1;
if (debug_dma >= 3)
xplus = 2;
else
xplus = 1;
t = dma_record_toggle ^ 1;
y = line / yplus - 8;
if (y < 0)
return;
if (y > maxvpos)
return;
if (y >= height)
return;
dx = width - xplus * ((maxhpos + 1) & ~1) - 16;
cc[0] = lc(0x222222);
cc[DMARECORD_REFRESH] = lc(0x444444);
cc[DMARECORD_CPU] = lc(0x888888);
cc[DMARECORD_COPPER] = lc(0xeeee00);
cc[DMARECORD_AUDIO] = lc(0xff0000);
cc[DMARECORD_BLITTER] = lc(0x00ff00);
cc[DMARECORD_BLITTER_LINE] = lc(0x008800);
cc[DMARECORD_BITPLANE] = lc(0x0000ff);
cc[DMARECORD_SPRITE] = lc(0xff00ff);
cc[DMARECORD_DISK] = lc(0xffffff);
for (x = 0; x < maxhpos; x++) {
uae_u32 c = cc[0];
xx = x * xplus + dx;
dr = &dma_record[t][y * NR_DMA_REC_HPOS + x];
if (dr->reg != 0xffff) {
c = cc[dr->type];
}
putpixel (buf, bpp, xx, c);
if (xplus)
putpixel (buf, bpp, xx + 1, c);
}
}
void record_dma_event (int evt, int hpos, int vpos)
{
struct dma_rec *dr;
if (!dma_record[0])
return;
if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS)
return;
dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos];
dr->evt |= evt;
}
struct dma_rec *record_dma (uae_u16 reg, uae_u16 dat, uae_u32 addr, int hpos, int vpos, int type)
{
struct dma_rec *dr;
if (!dma_record[0]) {
dma_record[0] = xmalloc (struct dma_rec, NR_DMA_REC_HPOS * NR_DMA_REC_VPOS);
dma_record[1] = xmalloc (struct dma_rec, NR_DMA_REC_HPOS * NR_DMA_REC_VPOS);
dma_record_toggle = 0;
record_dma_reset ();
}
if (hpos >= NR_DMA_REC_HPOS || vpos >= NR_DMA_REC_VPOS)
return NULL;
dr = &dma_record[dma_record_toggle][vpos * NR_DMA_REC_HPOS + hpos];
if (dr->reg != 0xffff) {
write_log (L"DMA conflict: v=%d h=%d OREG=%04X NREG=%04X\n", vpos, hpos, dr->reg, reg);
return dr;
}
dr->reg = reg;
dr->dat = dat;
dr->addr = addr;
dr->type = type;
return dr;
}
static void decode_dma_record (int hpos, int vpos, int toggle)
{
struct dma_rec *dr;
int h, i, maxh;
if (!dma_record[0])
return;
dr = &dma_record[dma_record_toggle ^ toggle][vpos * NR_DMA_REC_HPOS];
console_out_f (L"Line: %02X %3d HPOS %02X %3d:\n", vpos, vpos, hpos, hpos);
h = hpos;
dr += hpos;
maxh = hpos + 80;
if (maxh > maxhpos)
maxh = maxhpos;
while (h < maxh) {
int col = 9;
int cols = 8;
TCHAR l1[81];
TCHAR l2[81];
TCHAR l3[81];
TCHAR l4[81];
for (i = 0; i < cols && h < maxh; i++, h++, dr++) {
int cl = i * col, cl2;
int r = dr->reg;
TCHAR *sr;
sr = L" ";
if (dr->type == DMARECORD_COPPER)
sr = L"COP ";
else if (dr->type == DMARECORD_BLITTER)
sr = L"BLT ";
else if (dr->type == DMARECORD_REFRESH)
sr = L"RFS ";
else if (dr->type == DMARECORD_AUDIO)
sr = L"AUD ";
else if (dr->type == DMARECORD_DISK)
sr = L"DSK ";
else if (dr->type == DMARECORD_SPRITE)
sr = L"SPR ";
_stprintf (l1 + cl, L"[%02X %3d]", h, h);
_tcscpy (l4 + cl, L" ");
if (r != 0xffff) {
if (r & 0x1000) {
if ((r & 0x0100) == 0x0000)
_tcscpy (l2 + cl, L" CPU-R ");
else if ((r & 0x0100) == 0x0100)
_tcscpy (l2 + cl, L" CPU-W ");
if ((r & 0xff) == 4)
l2[cl + 7] = 'L';
if ((r & 0xff) == 2)
l2[cl + 7] = 'W';
if ((r & 0xff) == 1)
l2[cl + 7] = 'B';
} else {
_stprintf (l2 + cl, L"%4s %03X", sr, r);
}
_stprintf (l3 + cl, L" %04X", dr->dat);
if (dr->addr != 0xffffffff)
_stprintf (l4 + cl, L"%08X", dr->addr & 0x00ffffff);
} else {
_tcscpy (l2 + cl, L" ");
_tcscpy (l3 + cl, L" ");
}
cl2 = cl;
if (dr->evt & DMA_EVENT_BLITNASTY)
l3[cl2++] = 'N';
if (dr->evt & DMA_EVENT_BLITFINISHED)
l3[cl2++] = 'B';
if (dr->evt & DMA_EVENT_BLITIRQ)
l3[cl2++] = 'b';
if (dr->evt & DMA_EVENT_BPLFETCHUPDATE)
l3[cl2++] = 'p';
if (dr->evt & DMA_EVENT_COPPERWAKE)
l3[cl2++] = 'W';
if (dr->evt & DMA_EVENT_CPUIRQ)
l3[cl2++] = 'I';
if (dr->evt & DMA_EVENT_INTREQ)
l3[cl2++] = 'i';
if (i < cols - 1 && h < maxh - 1) {
l1[cl + col - 1] = 32;
l2[cl + col - 1] = 32;
l3[cl + col - 1] = 32;
l4[cl + col - 1] = 32;
}
}
console_out_f (L"%s\n", l1);
console_out_f (L"%s\n", l2);
console_out_f (L"%s\n", l3);
console_out_f (L"%s\n", l4);
console_out_f (L"\n");
}
}
void record_copper (uaecptr addr, int hpos, int vpos)
{
int t = nr_cop_records[curr_cop_set];
if (!cop_record[0]) {
cop_record[0] = xmalloc (struct cop_rec, NR_COPPER_RECORDS);
cop_record[1] = xmalloc (struct cop_rec, NR_COPPER_RECORDS);
}
if (t < NR_COPPER_RECORDS) {