forked from audetto/AppleWin
/
Debugger_Display.cpp
3723 lines (3065 loc) · 103 KB
/
Debugger_Display.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
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2019, Tom Charlesworth, Michael Pohoreski
Copyright (C) 2020, Tom Charlesworth, Michael Pohoreski, Cyril Lambin
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Description: Debugger
*
* Author: Copyright (C) 2006-2020 Michael Pohoreski, (C) 2020 Cyril Lambin
*/
#include "StdAfx.h"
#include "Debug.h"
#include "Debugger_Display.h"
#include "Debugger_Disassembler.h"
#include "../Core.h"
#include "../Interface.h"
#include "../CPU.h"
#include "../Windows/Win32Frame.h"
#include "../LanguageCard.h"
#include "../CardManager.h"
#include "../Memory.h"
#include "../Mockingboard.h"
#include "../NTSC.h"
// NEW UI debugging - force display ALL meta-info (regs, stack, bp, watches, zp) for debugging purposes
#define DEBUG_FORCE_DISPLAY 0
#define SOFTSWITCH_OLD 0
#define SOFTSWITCH_LANGCARD 1
#if _DEBUG
#define DEBUG_FONT_NO_BACKGROUND_CHAR 0
#define DEBUG_FONT_NO_BACKGROUND_TEXT 0
#define DEBUG_FONT_NO_BACKGROUND_FILL_CON 0
#define DEBUG_FONT_NO_BACKGROUND_FILL_INFO 0
#define DEBUG_FONT_NO_BACKGROUND_FILL_MAIN 0
// no top console line
#define DEBUG_BACKGROUND 0
#endif
#define DISPLAY_MEMORY_TITLE 1
// #define DISPLAY_BREAKPOINT_TITLE 1
// #define DISPLAY_WATCH_TITLE 1
// Public _________________________________________________________________________________________
// Font
FontConfig_t g_aFontConfig[ NUM_FONTS ];
// Private ________________________________________________________________________________________
char g_aDebuggerVirtualTextScreen[ DEBUG_VIRTUAL_TEXT_HEIGHT ][ DEBUG_VIRTUAL_TEXT_WIDTH ];
// HACK HACK HACK
//g_nDisasmWinHeight
WindowSplit_t *g_pDisplayWindow = 0; // HACK
// HACK
// Display - Win32
static HDC g_hDebuggerMemDC = NULL;
static HBITMAP g_hDebuggerMemBM = NULL;
static LPBITMAPINFO g_pDebuggerMemFramebufferinfo = NULL;
static bgra_t* g_pDebuggerMemFramebits = NULL;
static HDC g_hConsoleFontDC = NULL;
static HBITMAP g_hConsoleFontBitmap = NULL;
static LPBITMAPINFO g_hConsoleFontFramebufferinfo = NULL;
static bgra_t* g_hConsoleFontFramebits;
char g_cConsoleBrushFG_r;
char g_cConsoleBrushFG_g;
char g_cConsoleBrushFG_b;
char g_cConsoleBrushBG_r;
char g_cConsoleBrushBG_g;
char g_cConsoleBrushBG_b;
static HBRUSH g_hConsoleBrushFG = NULL;
static HBRUSH g_hConsoleBrushBG = NULL;
// NOTE: Keep in sync ConsoleColors_e g_anConsoleColor !
COLORREF g_anConsoleColor[ NUM_CONSOLE_COLORS ] =
{ // # <Bright Blue Green Red>
RGB( 0, 0, 0 ), // 0 0000 K
RGB( 255, 32, 32 ), // 1 1001 R
RGB( 0, 255, 0 ), // 2 1010 G
RGB( 255, 255, 0 ), // 3 1011 Y
RGB( 64, 64, 255 ), // 4 1100 B
RGB( 255, 0, 255 ), // 5 1101 M Purple/Magenta now used for warnings.
RGB( 0, 255, 255 ), // 6 1110 C
RGB( 255, 255, 255 ), // 7 1111 W
RGB( 255, 128, 0 ), // 8 0011 Orange
RGB( 128, 128, 128 ), // 9 0111 Grey
RGB( 80, 192, 255 ) // Lite Blue
};
// Drawing
// Width
const int DISPLAY_WIDTH = 560;
// New Font = 50.5 char * 7 px/char = 353.5
const int DISPLAY_DISASM_RIGHT = 353 ;
#if USE_APPLE_FONT
// Horizontal Column (pixels) of Stack & Regs
const int INFO_COL_1 = (51 * CONSOLE_FONT_WIDTH);
const int DISPLAY_REGS_COLUMN = INFO_COL_1;
const int DISPLAY_FLAG_COLUMN = INFO_COL_1;
const int DISPLAY_STACK_COLUMN = INFO_COL_1;
const int DISPLAY_TARGETS_COLUMN = INFO_COL_1;
const int DISPLAY_ZEROPAGE_COLUMN = INFO_COL_1;
const int DISPLAY_SOFTSWITCH_COLUMN = INFO_COL_1 - (CONSOLE_FONT_WIDTH/2) + 1; // 1/2 char width padding around soft switches
// Horizontal Column (pixels) of BPs, Watches
const int INFO_COL_2 = (62 * 7); // nFontWidth
const int DISPLAY_BP_COLUMN = INFO_COL_2;
const int DISPLAY_WATCHES_COLUMN = INFO_COL_2;
// Horizontal Column (pixels) of VideoScannerInfo & Mem
const int INFO_COL_3 = (63 * 7); // nFontWidth
const int DISPLAY_MINIMEM_COLUMN = INFO_COL_3;
const int DISPLAY_VIDEO_SCANNER_COLUMN = INFO_COL_3;
const int DISPLAY_IRQ_COLUMN = INFO_COL_3 + (12 * 7); // (12 chars from v/h-pos) * nFontWidth
#else
const int DISPLAY_CPU_INFO_LEFT_COLUMN = SCREENSPLIT1; // TC: SCREENSPLIT1 is not defined anywhere in the .sln!
const int DISPLAY_REGS_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN;
const int DISPLAY_FLAG_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN;
const int DISPLAY_STACK_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN;
const int DISPLAY_TARGETS_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN;
const int DISPLAY_ZEROPAGE_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN;
const int DISPLAY_SOFTSWITCH_COLUMN = DISPLAY_CPU_INFO_LEFT_COLUMN - (CONSOLE_FONT_WIDTH/2);
const int SCREENSPLIT2 = SCREENSPLIT1 + (12 * 7); // moved left 3 chars to show B. prefix in breakpoint #, W. prefix in watch #
const int DISPLAY_BP_COLUMN = SCREENSPLIT2;
const int DISPLAY_WATCHES_COLUMN = SCREENSPLIT2;
const int DISPLAY_MINIMEM_COLUMN = SCREENSPLIT2; // nFontWidth
const int DISPLAY_VIDEO_SCANNER_COLUMN = SCREENSPLIT2;
#endif
int MAX_DISPLAY_REGS_LINES = 7;
int MAX_DISPLAY_STACK_LINES = 8;
int MAX_DISPLAY_TARGET_PTR_LINES = 2;
int MAX_DISPLAY_ZEROPAGE_LINES = 8;
// int MAX_DISPLAY_BREAKPOINTS_LINES = 7; // 7
// int MAX_DISPLAY_WATCHES_LINES = 8; // 8
int MAX_DISPLAY_MEMORY_LINES_1 = 4; // 4
int MAX_DISPLAY_MEMORY_LINES_2 = 4; // 4 // 2
int g_nDisplayMemoryLines;
// Height
// const int DISPLAY_LINES = 24; // FIXME: Should be pixels
// 304 = bottom of disassembly
// 368 = bottom console
// 384 = 16 * 24 very bottom
// const int DEFAULT_HEIGHT = 16;
VideoScannerDisplayInfo g_videoScannerDisplayInfo;
static char ColorizeSpecialChar( char * sText, BYTE nData, const MemoryView_e iView,
const int iTxtBackground = BG_INFO , const int iTxtForeground = FG_DISASM_CHAR,
const int iHighBackground = BG_INFO_CHAR, const int iHighForeground = FG_INFO_CHAR_HI,
const int iLowBackground = BG_INFO_CHAR, const int iLowForeground = FG_INFO_CHAR_LO );
char FormatCharTxtAsci ( const BYTE b, bool * pWasAsci_ );
void DrawSubWindow_Code ( int iWindow );
void DrawSubWindow_IO (Update_t bUpdate);
void DrawSubWindow_Source (Update_t bUpdate);
void DrawSubWindow_Source2 (Update_t bUpdate);
void DrawSubWindow_Symbols (Update_t bUpdate);
void DrawSubWindow_ZeroPage (Update_t bUpdate);
void DrawWindowBottom ( Update_t bUpdate, int iWindow );
void DrawRegister(int line, LPCTSTR name, int bytes, WORD value, int iSource = 0);
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_6n77.asp
enum WinROP4_e
{
DSna = 0x00220326,
DPSao = 0x00EA02E9,
};
/*
Reverse Polish Notation
a Bitwise AND
n Bitwise NOT (inverse)
o Bitwise OR
x Bitwise exclusive OR (XOR)
Pen(P) 1 1 0 0 Decimal Result
Dest(D) 1 0 1 0 Boolean Operation
R2_BLACK 0 0 0 0 0 0
R2_NOTMERGEPEN 0 0 0 1 1 ~(P | D)
R2_MASKNOTPEN 0 0 1 0 2 ~P & D
R2_NOTCOPYPEN 0 0 1 1 3 ~P
R2_MASKPENNOT 0 1 0 0 4 P & ~D
R2_NOT 0 1 0 1 5 ~D
R2_XORPEN 0 1 1 0 6 P ^ D
R2_NOTMASKPEN 0 1 1 1 7 ~(P & D)
R2_MASKPEN 1 0 0 0 8 P & D
R2_NOTXORPEN 1 0 0 1 9 ~(P ^ D)
R2_NOPR2_NOP 1 0 1 0 10 D
R2_MERGENOTPEN 1 0 1 1 11 ~P | D
R2_COPYPEN 1 1 0 0 12 P (default)
R2_MERGEPENNOT 1 1 0 1 13 P | ~D
R2_MERGEPEN 1 1 1 0 14 P | D
R2_WHITE 1 1 1 1 15 1
*/
#if DEBUG_FONT_ROP
const DWORD aROP4[ 256 ] =
{
0x00000042, // BLACKNESS
0x00010289, // DPSoon
0x00020C89, // DPSona
0x000300AA, // PSon
0x00040C88, // SDPona
0x000500A9, // DPon
0x00060865, // PDSxnon
0x000702C5, // PDSaon
0x00080F08, // SDPnaa
0x00090245, // PDSxon
0x000A0329, // DPna
0x000B0B2A, // PSDnaon
0x000C0324, // SPna
0x000D0B25, // PDSnaon
0x000E08A5, // PDSonon
0x000F0001, // Pn
0x00100C85, // PDSona
0x001100A6, // DSon NOTSRCERASE
0x00120868, // SDPxnon
0x001302C8, // SDPaon
0x00140869, // DPSxnon
0x001502C9, // DPSaon
0x00165CCA, // PSDPSanaxx // 16
0x00171D54, // SSPxDSxaxn
0x00180D59, // SPxPDxa
0x00191CC8, // SDPSanaxn
0x001A06C5, // PDSPaox
0x001B0768, // SDPSxaxn
0x001C06CA, // PSDPaox
0x001D0766, // DSPDxaxn
0x001E01A5, // PDSox
0x001F0385, // PDSoan
0x00200F09, // DPSnaa
0x00210248, // SDPxon
0x00220326, // DSna
0x00230B24, // SPDnaon
0x00240D55, // SPxDSxa
0x00251CC5, // PDSPanaxn
0x002606C8, // SDPSaox
0x00271868, // SDPSxnox
0x00280369, // DPSxa
0x002916CA, // PSDPSaoxxn
0x002A0CC9, // DPSana
0x002B1D58, // SSPxPDxaxn
0x002C0784, // SPDSoax
0x002D060A, // PSDnox
0x002E064A, // PSDPxox
0x002F0E2A, // PSDnoan
0x0030032A, // PSna
0x00310B28, // SDPnaon
0x00320688, // SDPSoox
0x00330008, // Sn // 33 NOTSRCCOPY
0x003406C4, // SPDSaox
0x00351864, // SPDSxnox
0x003601A8, // SDPox
0x00370388, // SDPoan
0x0038078A, // PSDPoax
0x00390604, // SPDnox
0x003A0644, // SPDSxox
0x003B0E24, // SPDnoan
0x003C004A, // PSx
0x003D18A4, // SPDSonox
0x003E1B24, // SPDSnaox
0x003F00EA, // PSan
0x00400F0A, // PSDnaa
0x00410249, // DPSxon
0x00420D5D, // SDxPDxa
0x00431CC4, // SPDSanaxn
0x00440328, // SDna // 44 SRCERASE
0x00450B29, // DPSnaon
0x004606C6, // DSPDaox
0x0047076A, // PSDPxaxn
0x00480368, // SDPxa
0x004916C5, // PDSPDaoxxn
0x004A0789, // DPSDoax
0x004B0605, // PDSnox
0x004C0CC8, // SDPana
0x004D1954, // SSPxDSxoxn
0x004E0645, // PDSPxox
0x004F0E25, // PDSnoan
0x00500325, // PDna
0x00510B26, // DSPnaon
0x005206C9, // DPSDaox
0x00530764, // SPDSxaxn
0x005408A9, // DPSonon
0x00550009, // Dn // 55 DSTINVERT
0x005601A9, // DPSox
0x00570389, // DPSoan
0x00580785, // PDSPoax
0x00590609, // DPSnox
0x005A0049, // DPx // 5A PATINVERT
0x005B18A9, // DPSDonox
0x005C0649, // DPSDxox
0x005D0E29, // DPSnoan
0x005E1B29, // DPSDnaox
0x005F00E9, // DPan
0x00600365, // PDSxa
0x006116C6, // DSPDSaoxxn
0x00620786, // DSPDoax
0x00630608, // SDPnox
0x00640788, // SDPSoax
0x00650606, // DSPnox
0x00660046, // DSx // 66 SRCINVERT
0x006718A8, // SDPSonox
0x006858A6, // DSPDSonoxxn
0x00690145, // PDSxxn
0x006A01E9, // DPSax
0x006B178A, // PSDPSoaxxn
0x006C01E8, // SDPax
0x006D1785, // PDSPDoaxxn
0x006E1E28, // SDPSnoax
0x006F0C65, // PDSxnan
0x00700CC5, // PDSana
0x00711D5C, // SSDxPDxaxn
0x00720648, // SDPSxox
0x00730E28, // SDPnoan
0x00740646, // DSPDxox
0x00750E26, // DSPnoan
0x00761B28, // SDPSnaox
0x007700E6, // DSan
0x007801E5, // PDSax
0x00791786, // DSPDSoaxxn
0x007A1E29, // DPSDnoax
0x007B0C68, // SDPxnan
0x007C1E24, // SPDSnoax
0x007D0C69, // DPSxnan
0x007E0955, // SPxDSxo
0x007F03C9, // DPSaan
0x008003E9, // DPSaa
0x00810975, // SPxDSxon
0x00820C49, // DPSxna
0x00831E04, // SPDSnoaxn
0x00840C48, // SDPxna
0x00851E05, // PDSPnoaxn
0x008617A6, // DSPDSoaxx
0x008701C5, // PDSaxn
0x008800C6, // DSa // 88 SRCAND
0x00891B08, // SDPSnaoxn
0x008A0E06, // DSPnoa
0x008B0666, // DSPDxoxn
0x008C0E08, // SDPnoa
0x008D0668, // SDPSxoxn
0x008E1D7C, // SSDxPDxax
0x008F0CE5, // PDSanan
0x00900C45, // PDSxna
0x00911E08, // SDPSnoaxn
0x009217A9, // DPSDPoaxx
0x009301C4, // SPDaxn
0x009417AA, // PSDPSoaxx
0x009501C9, // DPSaxn
0x00960169, // DPSxx
0x0097588A, // PSDPSonoxx
0x00981888, // SDPSonoxn
0x00990066, // DSxn
0x009A0709, // DPSnax
0x009B07A8, // SDPSoaxn
0x009C0704, // SPDnax
0x009D07A6, // DSPDoaxn
0x009E16E6, // DSPDSaoxx
0x009F0345, // PDSxan
0x00A000C9, // DPa
0x00A11B05, // PDSPnaoxn
0x00A20E09, // DPSnoa
0x00A30669, // DPSDxoxn
0x00A41885, // PDSPonoxn
0x00A50065, // PDxn
0x00A60706, // DSPnax
0x00A707A5, // PDSPoaxn
0x00A803A9, // DPSoa
0x00A90189, // DPSoxn
0x00AA0029, // D // AA DSTCOPY
0x00AB0889, // DPSono
0x00AC0744, // SPDSxax
0x00AD06E9, // DPSDaoxn
0x00AE0B06, // DSPnao
0x00AF0229, // DPno
0x00B00E05, // PDSnoa
0x00B10665, // PDSPxoxn
0x00B21974, // SSPxDSxox
0x00B30CE8, // SDPanan
0x00B4070A, // PSDnax
0x00B507A9, // DPSDoaxn
0x00B616E9, // DPSDPaoxx
0x00B70348, // SDPxan
0x00B8074A, // PSDPxax
0x00B906E6, // DSPDaoxn
0x00BA0B09, // DPSnao
0x00BB0226, // DSno // BB MERGEPAINT
0x00BC1CE4, // SPDSanax
0x00BD0D7D, // SDxPDxan
0x00BE0269, // DPSxo
0x00BF08C9, // DPSano
0x00C000CA, // PSa // C0 MERGECOPY
0x00C11B04, // SPDSnaoxn
0x00C21884, // SPDSonoxn
0x00C3006A, // PSxn
0x00C40E04, // SPDnoa
0x00C50664, // SPDSxoxn
0x00C60708, // SDPnax
0x00C707AA, // PSDPoaxn
0x00C803A8, // SDPoa
0x00C90184, // SPDoxn
0x00CA0749, // DPSDxax
0x00CB06E4, // SPDSaoxn
0x00CC0020, // S // CC SRCCOPY
0x00CD0888, // SDPono
0x00CE0B08, // SDPnao
0x00CF0224, // SPno
0x00D00E0A, // PSDnoa
0x00D1066A, // PSDPxoxn
0x00D20705, // PDSnax
0x00D307A4, // SPDSoaxn
0x00D41D78, // SSPxPDxax
0x00D50CE9, // DPSanan
0x00D616EA, // PSDPSaoxx
0x00D70349, // DPSxan
0x00D80745, // PDSPxax
0x00D906E8, // SDPSaoxn
0x00DA1CE9, // DPSDanax
0x00DB0D75, // SPxDSxan
0x00DC0B04, // SPDnao
0x00DD0228, // SDno
0x00DE0268, // SDPxo
0x00DF08C8, // SDPano
0x00E003A5, // PDSoa
0x00E10185, // PDSoxn
0x00E20746, // DSPDxax
0x00E306EA, // PSDPaoxn
0x00E40748, // SDPSxax
0x00E506E5, // PDSPaoxn
0x00E61CE8, // SDPSanax
0x00E70D79, // SPxPDxan
0x00E81D74, // SSPxDSxax
0x00E95CE6, // DSPDSanaxxn
0x00EA02E9, // DPSao
0x00EB0849, // DPSxno
0x00EC02E8, // SDPao
0x00ED0848, // SDPxno
0x00EE0086, // DSo // EE SRCPAINT
0x00EF0A08, // SDPnoo
0x00F00021, // P // F0 PATCOPY
0x00F10885, // PDSono
0x00F20B05, // PDSnao
0x00F3022A, // PSno
0x00F40B0A, // PSDnao
0x00F50225, // PDno
0x00F60265, // PDSxo
0x00F708C5, // PDSano
0x00F802E5, // PDSao
0x00F90845, // PDSxno
0x00FA0089, // DPo
0x00FB0A09, // DPSnoo // FB PATPAINT
0x00FC008A, // PSo
0x00FD0A0A, // PSDnoo
0x00FE02A9, // DPSoo
0x00FF0062 // _WHITE // FF WHITENESS
};
#endif
// PATPAINT
// MERGECOPY
// SRCINVERT
// SRCCOPY
// 0xAA00EC
// 0x00EC02E8
#if DEBUG_FONT_ROP
static iRop4 = 0;
#endif
//===========================================================================
HDC GetDebuggerMemDC(void)
{
if (!g_hDebuggerMemDC)
{
Win32Frame& win32Frame = Win32Frame::GetWin32Frame();
HDC hFrameDC = win32Frame.FrameGetDC();
g_hDebuggerMemDC = CreateCompatibleDC(hFrameDC);
// CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER
g_pDebuggerMemFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
memset(g_pDebuggerMemFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
g_pDebuggerMemFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
g_pDebuggerMemFramebufferinfo->bmiHeader.biWidth = 560;
g_pDebuggerMemFramebufferinfo->bmiHeader.biHeight = 384;
g_pDebuggerMemFramebufferinfo->bmiHeader.biPlanes = 1;
g_pDebuggerMemFramebufferinfo->bmiHeader.biBitCount = 32;
g_pDebuggerMemFramebufferinfo->bmiHeader.biCompression = BI_RGB;
g_pDebuggerMemFramebufferinfo->bmiHeader.biClrUsed = 0;
// CREATE THE FRAME BUFFER DIB SECTION
g_hDebuggerMemBM = CreateDIBSection(
hFrameDC,
g_pDebuggerMemFramebufferinfo,
DIB_RGB_COLORS,
(LPVOID*)&g_pDebuggerMemFramebits, 0, 0
);
SelectObject(g_hDebuggerMemDC, g_hDebuggerMemBM);
}
_ASSERT(g_hDebuggerMemDC); // TC: Could this be NULL?
return g_hDebuggerMemDC;
}
void ReleaseDebuggerMemDC(void)
{
if (g_hDebuggerMemDC)
{
DeleteObject(g_hDebuggerMemBM);
g_hDebuggerMemBM = NULL;
DeleteDC(g_hDebuggerMemDC);
g_hDebuggerMemDC = NULL;
Win32Frame& win32Frame = Win32Frame::GetWin32Frame();
win32Frame.FrameReleaseDC();
delete [] g_pDebuggerMemFramebufferinfo;
g_pDebuggerMemFramebufferinfo = NULL;
g_pDebuggerMemFramebits = NULL;
}
}
HDC GetConsoleFontDC(void)
{
if (!g_hConsoleFontDC)
{
Win32Frame& win32Frame = Win32Frame::GetWin32Frame();
HDC hFrameDC = win32Frame.FrameGetDC();
g_hConsoleFontDC = CreateCompatibleDC(hFrameDC);
// CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER
g_hConsoleFontFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
memset(g_hConsoleFontFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
g_hConsoleFontFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
g_hConsoleFontFramebufferinfo->bmiHeader.biWidth = CONSOLE_FONT_BITMAP_WIDTH;
g_hConsoleFontFramebufferinfo->bmiHeader.biHeight = CONSOLE_FONT_BITMAP_HEIGHT;
g_hConsoleFontFramebufferinfo->bmiHeader.biPlanes = 1;
g_hConsoleFontFramebufferinfo->bmiHeader.biBitCount = 32;
g_hConsoleFontFramebufferinfo->bmiHeader.biCompression = BI_RGB;
g_hConsoleFontFramebufferinfo->bmiHeader.biClrUsed = 0;
// CREATE THE FRAME BUFFER DIB SECTION
g_hConsoleFontBitmap = CreateDIBSection(
hFrameDC,
g_hConsoleFontFramebufferinfo,
DIB_RGB_COLORS,
(LPVOID*)&g_hConsoleFontFramebits, 0, 0
);
SelectObject(g_hConsoleFontDC, g_hConsoleFontBitmap);
// DRAW THE SOURCE IMAGE INTO THE SOURCE BIT BUFFER
HDC tmpDC = CreateCompatibleDC(hFrameDC);
// Pre-scaled bitmap
HBITMAP tmpFont = LoadBitmap(win32Frame.g_hInstance, TEXT("IDB_DEBUG_FONT_7x8")); // Bitmap must be 112x128 as defined above
SelectObject(tmpDC, tmpFont);
BitBlt(g_hConsoleFontDC, 0, 0, CONSOLE_FONT_BITMAP_WIDTH, CONSOLE_FONT_BITMAP_HEIGHT,
tmpDC, 0, 0,
SRCCOPY);
DeleteDC(tmpDC);
DeleteObject(tmpFont);
}
_ASSERT(g_hConsoleFontDC);
return g_hConsoleFontDC;
}
void ReleaseConsoleFontDC(void)
{
if (g_hConsoleFontDC)
{
DeleteDC( g_hConsoleFontDC );
g_hConsoleFontDC = NULL;
DeleteObject( g_hConsoleFontBitmap );
g_hConsoleFontBitmap = NULL;
delete [] g_hConsoleFontFramebufferinfo;
g_hConsoleFontFramebufferinfo = NULL;
g_hConsoleFontFramebits = NULL;
}
DeleteObject( g_hConsoleBrushFG );
g_hConsoleBrushFG = NULL;
DeleteObject( g_hConsoleBrushBG );
g_hConsoleBrushBG = NULL;
}
void StretchBltMemToFrameDC(void)
{
Win32Frame& win32Frame = Win32Frame::GetWin32Frame();
int nViewportCX, nViewportCY;
win32Frame.GetViewportCXCY(nViewportCX, nViewportCY);
int xdest = win32Frame.IsFullScreen() ? win32Frame.GetFullScreenOffsetX() : GetVideo().GetFrameBufferCentringOffsetX() * win32Frame.GetViewportScale();
int ydest = win32Frame.IsFullScreen() ? win32Frame.GetFullScreenOffsetY() : GetVideo().GetFrameBufferCentringOffsetY() * win32Frame.GetViewportScale();
int wdest = nViewportCX;
int hdest = nViewportCY;
BOOL bRes = StretchBlt(
win32Frame.FrameGetDC(), // HDC hdcDest,
xdest, ydest, // int nXOriginDest, int nYOriginDest,
wdest, hdest, // int nWidthDest, int nHeightDest,
GetDebuggerMemDC(), // HDC hdcSrc,
0, 0, // int nXOriginSrc, int nYOriginSrc,
GetVideo().GetFrameBufferBorderlessWidth(), GetVideo().GetFrameBufferBorderlessHeight(), // int nWidthSrc, int nHeightSrc,
SRCCOPY // DWORD dwRop
);
}
// Font: Apple Text
//===========================================================================
void DebuggerSetColorFG( COLORREF nRGB )
{
#if USE_APPLE_FONT
if (g_hConsoleBrushFG)
{
SelectObject( GetDebuggerMemDC(), GetStockObject(NULL_BRUSH) );
DeleteObject( g_hConsoleBrushFG );
g_hConsoleBrushFG = NULL;
}
g_hConsoleBrushFG = CreateSolidBrush(nRGB);
g_cConsoleBrushFG_r = nRGB & 0xFF;
g_cConsoleBrushFG_g = (nRGB>>8) & 0xFF;
g_cConsoleBrushFG_b = (nRGB>>16) & 0xFF;
#else
SetTextColor( GetDebuggerMemDC(), nRGB );
#endif
}
//===================================================
void DebuggerSetColorBG( COLORREF nRGB, bool bTransparent )
{
#if USE_APPLE_FONT
if (g_hConsoleBrushBG)
{
SelectObject( GetDebuggerMemDC(), GetStockObject(NULL_BRUSH) );
DeleteObject( g_hConsoleBrushBG );
g_hConsoleBrushBG = NULL;
}
if (! bTransparent)
{
g_hConsoleBrushBG = CreateSolidBrush( nRGB );
}
// Transparency seems to be never used...
g_cConsoleBrushBG_r = nRGB & 0xFF;
g_cConsoleBrushBG_g = (nRGB >> 8) & 0xFF;
g_cConsoleBrushBG_b = (nRGB >> 16) & 0xFF;
#else
SetBkColor( GetDebuggerMemDC(), nRGB );
#endif
}
// @param glyph Specifies a native glyph from the 16x16 chars Apple Font Texture.
//===========================================================================
static void PrintGlyph( const int xDst, const int yDst, const int glyph )
{
HDC hDstDC = GetDebuggerMemDC();
int xSrc = (glyph % CONSOLE_FONT_NUM_CHARS_PER_ROW) * CONSOLE_FONT_GRID_X;
int ySrc = (glyph / CONSOLE_FONT_NUM_CHARS_PER_ROW) * CONSOLE_FONT_GRID_Y;
_ASSERT(ySrc < CONSOLE_FONT_BITMAP_HEIGHT);
// BUG #239 - (Debugger) Save debugger "text screen" to clipboard / file
// if( g_bDebuggerVirtualTextCapture )
//
{
#if _DEBUG
if ((xDst < 0) || (yDst < 0))
GetFrame().FrameMessageBox("X or Y out of bounds!", "PrintGlyph()", MB_OK );
#endif
int col = xDst / CONSOLE_FONT_WIDTH ;
int row = yDst / CONSOLE_FONT_HEIGHT;
// if( !g_bDebuggerCopyInfoPane )
// if( col < 50
if (xDst > DISPLAY_DISASM_RIGHT) // INFO_COL_2 // DISPLAY_CPU_INFO_LEFT_COLUMN
col++;
if ((col < DEBUG_VIRTUAL_TEXT_WIDTH)
&& (row < DEBUG_VIRTUAL_TEXT_HEIGHT))
g_aDebuggerVirtualTextScreen[ row ][ col ] = glyph;
}
// Manual print of character. A lot faster than BitBlt, which must be avoided.
int index_src = (CONSOLE_FONT_BITMAP_HEIGHT - 1 - ySrc) * CONSOLE_FONT_NUM_CHARS_PER_ROW * CONSOLE_FONT_GRID_X + xSrc; // font bitmap
int index_dst = (DISPLAY_HEIGHT - 1 - yDst) * DEBUG_VIRTUAL_TEXT_WIDTH * CONSOLE_FONT_GRID_X + xDst; // debugger bitmap
for (int yy = 0; yy < CONSOLE_FONT_GRID_Y; yy++)
{
for (int xx = 0; xx < CONSOLE_FONT_GRID_X; xx++)
{
char fontpx = g_hConsoleFontFramebits[index_src + xx].g; // Should be same for R/G/B anyway (greyscale)
g_pDebuggerMemFramebits[index_dst + xx].r = (g_cConsoleBrushBG_r & ~fontpx) | (g_cConsoleBrushFG_r & fontpx);
g_pDebuggerMemFramebits[index_dst + xx].g = (g_cConsoleBrushBG_g & ~fontpx) | (g_cConsoleBrushFG_g & fontpx);
g_pDebuggerMemFramebits[index_dst + xx].b = (g_cConsoleBrushBG_b & ~fontpx) | (g_cConsoleBrushFG_b & fontpx);
}
index_src -= CONSOLE_FONT_NUM_CHARS_PER_ROW * CONSOLE_FONT_GRID_X;
index_dst -= DEBUG_VIRTUAL_TEXT_WIDTH * CONSOLE_FONT_GRID_X;
}
}
//===========================================================================
void DebuggerPrint ( int x, int y, const char *pText )
{
const int nLeft = x;
char c;
const char *p = pText;
while ((c = *p))
{
if (c == '\n')
{
x = nLeft;
y += CONSOLE_FONT_HEIGHT;
p++;
continue;
}
c &= 0x7F;
PrintGlyph( x, y, c );
x += CONSOLE_FONT_WIDTH;
p++;
}
}
//===========================================================================
void DebuggerPrintColor( int x, int y, const conchar_t * pText )
{
int nLeft = x;
conchar_t g;
const conchar_t *pSrc = pText;
if( !pText)
return;
while ((g = (*pSrc)))
{
if (g == '\n')
{
x = nLeft;
y += CONSOLE_FONT_HEIGHT;
pSrc++;
continue;
}
if (ConsoleColor_IsColorOrMouse( g ))
{
if (ConsoleColor_IsColor( g ))
{
DebuggerSetColorFG( ConsoleColor_GetColor( g ) );
}
g = ConsoleChar_GetChar( g );
}
PrintGlyph( x, y, (char) (g & _CONSOLE_COLOR_MASK) );
x += CONSOLE_FONT_WIDTH;
pSrc++;
}
}
// Utility ________________________________________________________________________________________
//===========================================================================
bool CanDrawDebugger()
{
if (DebugGetVideoMode(NULL))
return false;
if ((g_nAppMode == MODE_DEBUG) || (g_nAppMode == MODE_STEPPING))
return true;
return false;
}
//===========================================================================
int PrintText ( const char * pText, RECT & rRect )
{
#if _DEBUG
if (! pText)
GetFrame().FrameMessageBox("pText = NULL!", "DrawText()", MB_OK );
#endif
int nLen = strlen( pText );
#if !DEBUG_FONT_NO_BACKGROUND_TEXT
FillBackground(rRect.left, rRect.top, rRect.right, rRect.bottom);
#endif
DebuggerPrint( rRect.left, rRect.top, pText );
return nLen;
}
//===========================================================================
void PrintTextColor ( const conchar_t *pText, RECT & rRect )
{
#if !DEBUG_FONT_NO_BACKGROUND_TEXT
FillBackground(rRect.left, rRect.top, rRect.right, rRect.bottom);
#endif
DebuggerPrintColor( rRect.left, rRect.top, pText );
}
//===========================================================================
void FillBackground(long left, long top, long right, long bottom)
{
long index_dst = (384-bottom) * 80 * CONSOLE_FONT_GRID_X;
for (long x = left; x < right; x++)
{
g_pDebuggerMemFramebits[index_dst + x].r = g_cConsoleBrushBG_r;
g_pDebuggerMemFramebits[index_dst + x].g = g_cConsoleBrushBG_g;
g_pDebuggerMemFramebits[index_dst + x].b = g_cConsoleBrushBG_b;
}
if (top != bottom)
{
bgra_t* src = g_pDebuggerMemFramebits + (index_dst + left);
bgra_t* dst = src + (80 * CONSOLE_FONT_GRID_X);
size_t size = (right - left) * sizeof(bgra_t);
for (int i = 0; i < bottom - top - 1; i++)
{
memcpy((void*)dst, (void*)src, size);
dst += 80 * CONSOLE_FONT_GRID_X ;
}
}
}
// Updates the horizontal cursor
//===========================================================================
int PrintTextCursorX ( const char * pText, RECT & rRect )
{
int nChars = 0;
if (pText)
{
nChars = PrintText( pText, rRect );
int nFontWidth = g_aFontConfig[ FONT_DISASM_DEFAULT ]._nFontWidthAvg;
rRect.left += (nFontWidth * nChars);
}
return nChars;
}
//===========================================================================
int PrintTextCursorY ( const char * pText, RECT & rRect )
{
int nChars = PrintText( pText, rRect );
rRect.top += g_nFontHeight;
rRect.bottom += g_nFontHeight;
return nChars;
}
//===========================================================================
void SetupColorsHiLoBits ( bool bHighBit, bool bCtrlBit,
const int iBackground, const int iForeground,
const int iColorHiBG , const int iColorHiFG,
const int iColorLoBG , const int iColorLoFG )
{
// 4 cases:
// Hi Lo Background Foreground -> just map Lo -> FG, Hi -> BG
// 0 0 normal normal BG_INFO FG_DISASM_CHAR (dark cyan bright cyan)
// 0 1 normal LoFG BG_INFO FG_DISASM_OPCODE (dark cyan yellow)
// 1 0 HiBG normal BG_INFO_CHAR FG_DISASM_CHAR (mid cyan bright cyan)
// 1 1 HiBG LoFG BG_INFO_CHAR FG_DISASM_OPCODE (mid cyan yellow)
DebuggerSetColorBG( DebuggerGetColor( iBackground ));
DebuggerSetColorFG( DebuggerGetColor( iForeground ));
if (bHighBit)
{
DebuggerSetColorBG( DebuggerGetColor( iColorHiBG ));
DebuggerSetColorFG( DebuggerGetColor( iColorHiFG )); // was iForeground
}
if (bCtrlBit)
{
DebuggerSetColorBG( DebuggerGetColor( iColorLoBG ));
DebuggerSetColorFG( DebuggerGetColor( iColorLoFG ));
}
}
// To flush out color bugs... swap: iAsciBackground & iHighBackground
//===========================================================================
char ColorizeSpecialChar( char * sText, BYTE nData, const MemoryView_e iView,
const int iAsciBackground /*= 0 */, const int iTextForeground /*= FG_DISASM_CHAR */,
const int iHighBackground /*= BG_INFO_CHAR*/, const int iHighForeground /*= FG_INFO_CHAR_HI*/,
const int iCtrlBackground /*= BG_INFO_CHAR*/, const int iCtrlForeground /*= FG_INFO_CHAR_LO*/ )
{
bool bHighBit = false;
bool bCtrlBit = false;
int iTextBG = iAsciBackground;
int iHighBG = iHighBackground;
int iCtrlBG = iCtrlBackground;
int iTextFG = iTextForeground;
int iHighFG = iHighForeground;
int iCtrlFG = iCtrlForeground;
BYTE nByte = FormatCharTxtHigh( nData, & bHighBit );
char nChar = FormatCharTxtCtrl( nByte, & bCtrlBit );
switch (iView)
{
case MEM_VIEW_ASCII:
iHighBG = iTextBG;
iCtrlBG = iTextBG;
break;
case MEM_VIEW_APPLE:
iHighBG = iTextBG;
if (!bHighBit)
{
iTextBG = iCtrlBG;
}
if (bCtrlBit)
{
iTextFG = iCtrlFG;
if (bHighBit)
{
iHighFG = iTextFG;
}
}
bCtrlBit = false;
break;
default: break;
}
if (sText)
sprintf( sText, "%c", nChar );
#if OLD_CONSOLE_COLOR
if (sText)
{
if (ConsoleColor_IsEscapeMeta( nChar ))
sprintf( sText, "%c%c", nChar, nChar );
else