-
Notifications
You must be signed in to change notification settings - Fork 5
/
DebuggerUnit.pas
2899 lines (2737 loc) · 113 KB
/
DebuggerUnit.pas
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
unit DebuggerUnit;
interface
uses
Windows, Messages, SysUtils, ExtCtrls, Variants, Classes, Graphics, Controls,
Forms, Dialogs, Math;
const
mCOGN = 0; // debugger message longs
mBRKCZ = 1;
mBRKC = 2;
mBRKZ = 3;
mCTH2 = 4;
mCTL2 = 5;
mSTK0 = 6;
mSTK1 = 7;
mSTK2 = 8;
mSTK3 = 9;
mSTK4 = 10;
mSTK5 = 11;
mSTK6 = 12;
mSTK7 = 13;
mIRET = 14;
mFPTR = 15;
mPTRA = 16;
mPTRB = 17;
mFREQ = 18;
mCOND = 19;
DebuggerMsgSize = 20;
cRed = $FF0000;
cRed1 = $BF0000;
cRed2 = $7F0000;
cRed3 = $3F0000;
cRed4 = $1F0000;
cRed5 = $0F0000;
cGreen = $00FF00;
cGreen1 = $00BF00;
cGreen2 = $007F00;
cGreen3 = $003F00;
cGreen4 = $001F00;
cGreen5 = $000F00;
cBlue = $0000FF;
cBlue1 = $0000BF;
cBlue2 = $00007F;
cBlue3 = $00003F;
cBlue4 = $00001F;
cBlue5 = $00000F;
cYellow = $FFFF00;
cYellow1 = $BFBF00;
cYellow2 = $7F7F00;
cYellow3 = $3F3F00;
cYellow4 = $1F1F00;
cYellow5 = $0F0F00;
cMagenta = $FF00FF;
cMagenta1 = $BF00BF;
cMagenta2 = $7F007F;
cMagenta3 = $3F003F;
cMagenta4 = $1F001F;
cMagenta5 = $0F000F;
cCyan = $00FFFF;
cCyan1 = $00BFBF;
cCyan2 = $007F7F;
cCyan3 = $003F3F;
cCyan4 = $001F1F;
cCyan5 = $000F0F;
cOrange = $FF7F00;
cOrange1 = $BF5F00;
cOrange2 = $7F3F00;
cOrange3 = $3F1F00;
cOrange4 = $1F0F00;
cOrange5 = $0F0700;
cWhite = $FFFFFF;
cGray1 = $BFBFBF;
cGray2 = $7F7F7F;
cGray3 = $3F3F3F;
cGray4 = $1F1F1F;
cGray5 = $0F0F0F;
cBlack = $000000;
TopColor = 20;
ColorScheme : array [0..TopColor] of integer =
(cBlack, // cBackground
cYellow4, // cBox
cGreen4, // cBox2
cOrange2, // cBox3
cWhite, // cData
cGreen2, // cData2
cYellow5, // cDataDim
cOrange, // cIndicator
cYellow, // cName
cYellow3, // cHighSame
cYellow5, // cLowSame
cYellow, // cHighDiff
cYellow2, // cLowDiff
cYellow2, // cModeButton
cWhite, // cModeText
cYellow3, // cModeButtonDim
cYellow5, // cModeTextDim
cOrange1, // cCmdButton
cWhite, // cCmdText
cOrange3, // cCmdButtonDim
cOrange4); // cCmdTextDim
Cols = 123;
Rows = 77;
q1 = 1 shl 7;
q2 = 2 shl 7;
q3 = 3 shl 7;
REGMAPl = 2; REGMAPt = 1; REGMAPw = 9; REGMAPh = 75;
LUTMAPl = 13; LUTMAPt = 1; LUTMAPw = 9; LUTMAPh = 75;
CFl = 24; CFt = 1; CFw = 3; CFh = 2;
ZFl = 29; ZFt = 1; ZFw = 3; ZFh = 2;
PCl = 34; PCt = 1; PCw = 8; PCh = 2;
SKIPl = 44; SKIPt = 1; SKIPw = 41; SKIPh = 2;
XBYTEl = 87; XBYTEt = 1; XBYTEw = 12; XBYTEh = 2;
CTl = 101; CTt = 1; CTw = 20; CTh = 2;
DISl = 24; DISt = 4; DISw = 56; DISh = 32;
WATCHl = 82; WATCHt = 4; WATCHw = 12; WATCHh = 32;
SFRl = 96; SFRt = 4; SFRw = 18; SFRh = 32;
EVENTl = 116; EVENTt = 4; EVENTw = 5; EVENTh = 32;
EXECl = 24; EXECt = 35; EXECw = 4; EXECh = 4;
STACKl = 30; STACKt = 37; STACKw = 77; STACKh = 2;
INTl = 24; INTt = 40; INTw = 13; INTh = 6;
PTRl = 39; PTRt = 40; PTRw = 68; PTRh = 6;
STATUSl = 24; STATUSt = 47; STATUSw = 6; STATUSh = 6;
PINl = 32; PINt = 47; PINw = 75; PINh = 6;
SMARTl = 24; SMARTt = 54; SMARTw = 97; SMARTh = 2;
HUBl = 24; HUBt = 57; HUBw = 97; HUBh = 16;
HINTl = 29; HINTt = 74; HINTw = 92; HINTh = 2;
Bl = 109; Bt = 37; Bw = 12; Bh = 16;
bBREAKl = Bl+q3; bBREAKt = Bt+q1; bBREAKw = 5; bBREAKh = 2;
bADDRl = Bl+q3; bADDRt = Bt+2+q1; bADDRw = 5; bADDRh = 2;
bINT3El = Bl+q3; bINT3Et = Bt+4+q1; bINT3Ew = 5; bINT3Eh = 2;
bINT2El = Bl+q3; bINT2Et = Bt+6+q1; bINT2Ew = 5; bINT2Eh = 2;
bINT1El = Bl+q3; bINT1Et = Bt+8+q1; bINT1Ew = 5; bINT1Eh = 2;
bDEBUGl = Bl+q3; bDEBUGt = Bt+10+q1; bDEBUGw = 5; bDEBUGh = 2;
bINITl = Bl+7+q1; bINITt = Bt+q1; bINITw = 4; bINITh = 2;
bEVENTl = Bl+7+q1; bEVENTt = Bt+2+q1; bEVENTw = 4; bEVENTh = 2;
bINT3l = Bl+7+q1; bINT3t = Bt+4+q1; bINT3w = 4; bINT3h = 2;
bINT2l = Bl+7+q1; bINT2t = Bt+6+q1; bINT2w = 4; bINT2h = 2;
bINT1l = Bl+7+q1; bINT1t = Bt+8+q1; bINT1w = 4; bINT1h = 2;
bMAINl = Bl+7+q1; bMAINt = Bt+10+q1; bMAINw = 4; bMAINh = 2;
bGOl = Bl+1; bGOt = Bt+13; bGOw = 10; bGOh = 2;
DebugROM : array [0..7] of string =
('setq #$F ' + Chr(39) + 'DEBUG Entry',
'wrlong 0,#$FFF80-cog<<7',
'setq #$F',
'rdlong 0,#$FFFC0-cog<<7',
'jmp #\0',
'setq #$F ' + Chr(39) + 'DEBUG Exit',
'rdlong 0,#$FFF80-cog<<7',
'reti0');
ModeName : array [0..3] of string =
('MAIN', 'INT1', 'INT2', 'INT3');
EventName : array [0..15] of string =
('INT', 'CT1', 'CT2', 'CT3', 'SE1', 'SE2', 'SE3', 'SE4',
'PAT', 'FBW', 'XMT', 'XFI', 'XRO', 'XRL', 'ATN', 'QMT');
RegName : array [0..15] of string =
('IJMP3', 'IRET3', 'IJMP2', 'IRET2', 'IJMP1', 'IRET1',
' PA', ' PB', ' PTRA', ' PTRB',
' DIRA', ' DIRB', ' OUTA', ' OUTB', ' INA', ' INB');
dmPC = 0; // disassembly modes
dmCog = 1;
dmHub = 2;
DisLines = 16;
DisLineIdeal = 3;
DisScrollThreshold = 8;
StallCmd = $00000800;
HitDecayRate = 2;
PtrBytes = 14;
PtrCenter = 6;
CogSize = $400;
CogBlockSize = $10;
CogBlocks = CogSize div CogBlockSize;
HubSize = $7C000;
HubBlockSize = $1000;
HubBlocks = HubSize div HubBlockSize;
HubSubBlockSize = $80;
HubSubBlocks = HubSize div HubSubBlockSize;
HubBlockRatio = HubBlockSize div HubSubBlockSize;
HubMapWidth = 64;
HubMapHeight = HubSubBlocks div HubMapWidth;
RegWatchSize = $1F0;
RegWatchListSize = 16;
SmartPins = 64;
SmartWatchSize = SmartPins;
SmartWatchListSize = 7;
SmoothFillMax = 4096;
type
TDebuggerForm = class(TForm)
MouseMoveTimer : TTimer;
BreakpointTimer : TTimer;
ButtonTimer : TTimer;
private
CaptionStr : string;
CaptionPos : boolean;
DebuggerMsg : array [0..DebuggerMsgSize - 1] of integer;
cBackground : integer; // color scheme
cBox : integer;
cBox2 : integer;
cBox3 : integer;
cData : integer;
cData2 : integer;
cDataDim : integer;
cIndicator : integer;
cName : integer;
cHighSame : integer;
cLowSame : integer;
cHighDiff : integer;
cLowDiff : integer;
cModeButton : integer;
cModeText : integer;
cModeButtonDim : integer;
cModeTextDim : integer;
cCmdButton : integer;
cCmdText : integer;
cCmdButtonDim : integer;
cCmdTextDim : integer;
TextSize : integer;
ChrWidth : integer;
ChrHeight : integer;
BitmapWidth : integer;
BitmapHeight : integer;
Bitmap : array [0..2] of TBitmap;
BitmapLine : array [0..SmoothFillMax - 1] of PByte;
RegMap : TBitMap;
RegMapLine : array [0..$1FF] of pointer;
LutMap : TBitMap;
LutMapLine : array [0..$1FF] of pointer;
HubMap : TBitMap;
HubMapLine : array [0..$3F] of pointer;
RegBoxLeft, RegBoxTop, RegBoxRight, RegBoxBottom : integer;
RegMapLeft, RegMapTop, RegMapRight, RegMapBottom : integer;
LutBoxLeft, LutBoxTop, LutBoxRight, LutBoxBottom : integer;
LutMapLeft, LutMapTop, LutMapRight, LutMapBottom : integer;
CFLeft, CFTop, CFRight, CFBottom : integer;
ZFLeft, ZFTop, ZFRight, ZFBottom : integer;
PCLeft, PCTop, PCRight, PCBottom : integer;
SkipLeft, SkipTop, SkipRight, SkipBottom : integer;
XBYTELeft, XBYTETop, XBYTERight, XBYTEBottom : integer;
CTLeft, CTTop, CTRight, CTBottom : integer;
DisLeft, DisTop, DisRight, DisBottom : integer;
RegWatchLeft, RegWatchTop, RegWatchRight, RegWatchBottom : integer;
SFRBoxLeft, SFRBoxTop, SFRBoxRight, SFRBoxBottom : integer;
SFRDataLeft, SFRDataTop, SFRDataRight, SFRDataBottom : integer;
EventsBoxLeft, EventsBoxTop, EventsBoxRight, EventsBoxBottom : integer;
EventsLeft, EventsTop, EventsRight, EventsBottom : integer;
ExecLeft, ExecTop, ExecRight, ExecBottom : integer;
StackBoxLeft, StackBoxTop, StackBoxRight, StackBoxBottom : integer;
StackDataLeft, StackDataTop, StackDataRight, StackDataBottom : integer;
IntBoxLeft, IntBoxTop, IntBoxRight, IntBoxBottom : integer;
PtrBoxLeft, PtrBoxTop, PtrBoxRight, PtrBoxBottom : integer;
PtrAddrLeft, PtrAddrTop, PtrAddrRight, PtrAddrBottom : integer;
PtrDataLeft, PtrDataTop, PtrDataRight, PtrDataBottom : integer;
PtrChrLeft, PtrChrTop, PtrChrRight, PtrChrBottom : integer;
StatusLeft, StatusTop, StatusRight, StatusBottom : integer;
PinBoxLeft, PinBoxTop, PinBoxRight, PinBoxBottom : integer;
PinDataLeft, PinDataTop, PinDataRight, PinDataBottom : integer;
SmartWatchLeft, SmartWatchTop, SmartWatchRight, SmartWatchBottom : integer;
HubTabLeft, HubTabTop, HubTabRight, HubTabBottom : integer;
HubBoxLeft, HubBoxTop, HubBoxRight, HubBoxBottom : integer;
HubAddrLeft, HubAddrTop, HubAddrRight, HubAddrBottom : integer;
HubDataLeft, HubDataTop, HubDataRight, HubDataBottom : integer;
HubChrLeft, HubChrTop, HubChrRight, HubChrBottom : integer;
HubMapLeft, HubMapTop, HubMapRight, HubMapBottom : integer;
ButtonBoxLeft, ButtonBoxTop, ButtonBoxRight, ButtonBoxBottom : integer;
ButtonBreakLeft, ButtonBreakTop, ButtonBreakRight, ButtonBreakBottom : integer;
ButtonAddrLeft, ButtonAddrTop, ButtonAddrRight, ButtonAddrBottom : integer;
ButtonInt3ELeft, ButtonInt3ETop, ButtonInt3ERight, ButtonInt3EBottom : integer;
ButtonInt2ELeft, ButtonInt2ETop, ButtonInt2ERight, ButtonInt2EBottom : integer;
ButtonInt1ELeft, ButtonInt1ETop, ButtonInt1ERight, ButtonInt1EBottom : integer;
ButtonDebugLeft, ButtonDebugTop, ButtonDebugRight, ButtonDebugBottom : integer;
ButtonInitLeft, ButtonInitTop, ButtonInitRight, ButtonInitBottom : integer;
ButtonEventLeft, ButtonEventTop, ButtonEventRight, ButtonEventBottom : integer;
ButtonInt3Left, ButtonInt3Top, ButtonInt3Right, ButtonInt3Bottom : integer;
ButtonInt2Left, ButtonInt2Top, ButtonInt2Right, ButtonInt2Bottom : integer;
ButtonInt1Left, ButtonInt1Top, ButtonInt1Right, ButtonInt1Bottom : integer;
ButtonMainLeft, ButtonMainTop, ButtonMainRight, ButtonMainBottom : integer;
ButtonGoLeft, ButtonGoTop, ButtonGoRight, ButtonGoBottom : integer;
MouseX : integer;
MouseY : integer;
InRegBox : boolean;
InRegMap : boolean;
InLutBox : boolean;
InLutMap : boolean;
InCF : boolean;
InZF : boolean;
InPC : boolean;
InSkip : boolean;
InXBYTE : boolean;
InCT : boolean;
InDis : boolean;
InRegWatch : boolean;
InSFRBox : boolean;
InSFRData : boolean;
InEventsBox : boolean;
InEvents : boolean;
InExec : boolean;
InStackBox : boolean;
InStackData : boolean;
InIntBox : boolean;
InPtrBox : boolean;
InPtrAddr : boolean;
InPtrData : boolean;
InPtrChr : boolean;
InStatusBox : boolean;
InPinBox : boolean;
InPinData : boolean;
InSmartWatch : boolean;
InHubTab : boolean;
InHubBox : boolean;
InHubAddr : boolean;
InHubData : boolean;
InHubChr : boolean;
InHubMap : boolean;
InButtonBox : boolean;
InButtonBreak : boolean;
InButtonAddr : boolean;
InButtonInt3E : boolean;
InButtonInt2E : boolean;
InButtonInt1E : boolean;
InButtonDebug : boolean;
InButtonInit : boolean;
InButtonEvent : boolean;
InButtonInt3 : boolean;
InButtonInt2 : boolean;
InButtonInt1 : boolean;
InButtonMain : boolean;
InButtonGo : boolean;
CogImage : array [0..$3FF] of integer;
CogImageOld : array [0..$3FF] of integer;
CogImageHit : array [0..$3FF] of byte;
CogBlock : array [0..CogBlocks - 1] of integer;
CogBlockOld : array [0..CogBlocks - 1] of integer;
HubBlock : array [0..HubBlocks - 1] of integer;
HubBlockOld : array [0..HubBlocks - 1] of integer;
HubSubBlock : array [0..HubSubBlocks - 1] of integer;
HubSubBlockOld : array [0..HubSubBlocks - 1] of integer;
HubSubBlockHit : array [0..HubSubBlocks - 1] of byte;
SmartBuff : array [0..SmartPins - 1] of integer;
SmartBuffOld : array [0..SmartPins - 1] of integer;
WatchReg : array [0..RegWatchSize - 1] of word;
WatchRegList : array [0..RegWatchListSize - 1] of integer;
WatchSmart : array [0..SmartWatchSize - 1] of word;
WatchSmartList : array [0..SmartWatchListSize - 1] of integer;
WatchSmartAll : boolean;
BreakAddr : integer;
BreakEvent : integer;
BreakValue : integer;
StallBrk : integer;
RepeatMode : boolean;
FirstBreak : boolean;
OldPC : integer;
DisMode : integer;
CurDisMode : integer;
DisAddr : integer;
CurDisAddr : integer;
CogAddr : integer;
HubAddr : integer;
MapCogAddr : integer;
MapHubAddr : integer;
DisScrollTimer : integer;
OldTickCount : integer;
GoLeft : integer;
GoCaption : string;
GoState : integer;
Hint : string;
KeyShift : TShiftState;
SmoothFillSize : integer;
SmoothFillColor : integer;
SmoothFillBuff : array [0..SmoothFillMax * 3 - 1] of byte;
published
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormMouseMoveTimeout(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormMove(var Msg: TWMMove); message WM_WINDOWPOSCHANGED;
procedure FormPaint(Sender: TObject);
procedure FormBreakpointTimeout(Sender: TObject);
procedure FormButtonTimeout(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Breakpoint;
procedure DrawBaseBitmap;
procedure DrawBox(left, top, width, height, color, rim: integer; small: boolean);
procedure DrawText(left, top, color: integer; style: TFontStyles; str: string);
procedure DrawCheck(left, top, color: integer);
procedure DrawDelta(left, top, color: integer);
procedure DrawArrowUp(left, top, color: integer);
procedure DrawArrowRight(left, top, color: integer);
procedure DrawRegBin(left, top, value, color: integer);
procedure DrawPtrBytes(left, top, address: integer; buff:PByteArray);
procedure DrawInt(left, top, int: integer);
procedure DrawGoButton(ButtonColor, CaptionColor: integer);
procedure BlendPixel(var p:PByte; a, b: integer; alpha, shade: byte);
procedure BitmapToCanvas(Level: integer);
procedure ResetRegWatch;
procedure ResetSmartWatch;
procedure BoxBoundary(var Left, Top, Right, Bottom: integer; L, T, W, H, B: integer);
function Frac(x, y: integer): integer;
function MouseWithin(Left, Top, Right, Bottom, Cadence: integer; HintStr: string): boolean;
function WinRGB(c: integer): integer;
procedure SmoothShape(xc, yc, xs, ys, xro, yro, thick, color: integer; opacity: byte);
procedure SmoothFillSetup(size, color: integer);
procedure SmoothRect(x, y, xs, ys: integer; opacity: byte);
procedure SmoothFill(x, y, count: integer; opacity: byte);
procedure SmoothPlot(x, y: integer; opacity: byte);
procedure SmoothDot(x, y, radius, color: integer; opacity: byte);
procedure SmoothLine(x1, y1, x2, y2, radius, color: integer; opacity: byte);
procedure SmoothSlice(swapxy: boolean; x, yb, yt, color: integer; opacity: byte);
procedure SmoothPixel(swapxy: boolean; x, y, color: integer; opacity, opacity2: byte);
function SmoothClip(var x1, y1, x2, y2: integer): boolean;
function SmoothClipTest(x, y, lft, rgt, bot, top: integer): integer;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
uses GlobalUnit, SerialUnit;
////////////////////////
// Low-Level Events //
////////////////////////
constructor TDebuggerForm.Create(AOwner: TComponent);
var
i: integer;
begin
inherited CreateNew(AOwner);
BorderIcons := [biSystemMenu];
BorderStyle := bsDialog;
Font.Charset := DEFAULT_CHARSET;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
OldCreateOrder := False;
OnCreate := FormCreate;
OnMouseMove := FormMouseMove;
OnMouseDown := FormMouseDown;
OnMouseWheel := FormMouseWheel;
OnKeyDown := FormKeyDown;
OnKeyPress := FormKeyPress;
OnPaint := FormPaint;
OnDestroy := FormDestroy;
// Set up mouse-move timer
MouseMoveTimer := TTimer.Create(Self);
MouseMoveTimer.OnTimer := FormMouseMoveTimeout;
MouseMoveTimer.Enabled := False;
// Set up breakpoint timer
BreakpointTimer := TTimer.Create(Self);
BreakpointTimer.OnTimer := FormBreakpointTimeout;
BreakpointTimer.Enabled := False;
// Set up button timer
ButtonTimer := TTimer.Create(Self);
ButtonTimer.OnTimer := FormButtonTimeout;
ButtonTimer.Enabled := False;
end;
destructor TDebuggerForm.Destroy;
begin
MouseMoveTimer.Free;
BreakpointTimer.Free;
inherited Destroy;
end;
procedure TDebuggerForm.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
inherited;
Msg.Result := Msg.Result or DLGC_WANTTAB;
end;
//////////////
// Events //
//////////////
procedure TDebuggerForm.FormCreate(Sender: TObject);
var
i: integer;
begin
// Init arrays
for i := 0 to CogBlocks - 1 do CogBlock[i] := -1;
for i := 0 to HubBlocks - 1 do HubBlock[i] := -1;
for i := 0 to HubSubBlocks - 1 do HubSubBlockHit[i] := 255;
for i := 0 to $3FF do CogImageHit[i] := 255;
for i := 0 to SmartPins - 1 do SmartBuff[i] := -1;
ResetRegWatch;
ResetSmartWatch;
// Init miscellaneous
FirstBreak := True;
BreakAddr := $00000;
BreakEvent := 1;
StallBrk := StallCmd;
RepeatMode := False;
OldPC := -9; // -9 causes initial ideal line in disassembly window
DisMode := dmPC;
DisAddr := 0;
CogAddr := 0;
HubAddr := 0;
MapCogAddr := 0;
MapHubAddr := 0;
WatchSmartAll := False;
Hint := '';
DisScrollTimer := 0;
OldTickCount := 0;
GoLeft := bGOl;
GoCaption := '';
GoState := 0;
// Set up cog/lut/hub bitmaps
RegMap := TBitmap.Create;
RegMap.PixelFormat := pf24bit;
RegMap.Width := 32;
RegMap.Height := 512;
for i := 0 to 511 do RegMapLine[i] := RegMap.ScanLine[i];
LutMap := TBitmap.Create;
LutMap.PixelFormat := pf24bit;
LutMap.Width := 32;
LutMap.Height := 512;
for i := 0 to 511 do LutMapLine[i] := LutMap.ScanLine[i];
HubMap := TBitmap.Create;
HubMap.PixelFormat := pf24bit;
HubMap.Width := HubMapWidth;
HubMap.Height := HubMapHeight;
for i := 0 to HubMapHeight - 1 do HubMapLine[i] := HubMap.ScanLine[i];
// Set up display bitmaps
for i := 0 to 2 do
begin
Bitmap[i] := TBitmap.Create;
Bitmap[i].PixelFormat := pf24bit;
end;
// Trim text size if too large
Bitmap[0].Canvas.Font.Name := FontName;
TextSize := FontSize + 1;
repeat
Dec(TextSize);
Bitmap[0].Canvas.Font.Size := TextSize;
ChrWidth := Bitmap[0].Canvas.TextWidth('X');
ChrHeight := Bitmap[0].Canvas.TextHeight('X');
BitmapWidth := ChrWidth * Cols;
BitmapHeight := ChrHeight * Rows shr 1;
until BitmapWidth <= SmoothFillMax;
// Set display bitmap metrics
for i := 0 to 2 do
begin
Bitmap[i].Width := BitmapWidth;
Bitmap[i].Height := BitmapHeight;
end;
for i := 0 to BitmapHeight - 1 do BitmapLine[i] := Bitmap[0].ScanLine[i];
// Set color scheme
for i := 0 to TopColor do PIntegerArray(@cBackground)[i] := ColorScheme[i];
// Draw base bitmap and store for faster redraw
DrawBaseBitmap;
// Set window metrics
Left := P2.DebugDisplayLeft + DebuggerID * ChrHeight * 2;
Top := P2.DebugDisplayTop + DebuggerID * ChrHeight * 2;
ClientWidth := BitmapWidth;
ClientHeight := BitmapHeight;
// Set caption
CaptionStr := ('Debugger - Cog ' + Chr(DebuggerID + Byte('0')));
Caption := CaptionStr;
CaptionPos := False;
// Reset mouse-position variables
FormMouseMove(Self, [], 0, 0);
// Show window
Show;
end;
procedure TDebuggerForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
// Record mouse position here for all other mouse events
MouseX := X;
MouseY := Y;
// What box is the mouse in?
Hint := '';
InRegBox := MouseWithin(RegBoxLeft, RegBoxTop, RegBoxRight, RegBoxBottom, 0, 'Cog Register Bitmap/Heatmap');
InRegMap := MouseWithin(RegMapLeft, RegMapTop, RegMapRight, RegMapBottom, 0, 'Cog Register Bitmap/Heatmap | Click to lock disassembly to REG subrange');
InLutBox := MouseWithin(LutBoxLeft, LutBoxTop, LutBoxRight, LutBoxBottom, 0, 'LUT Register Bitmap/Heatmap');
InLutMap := MouseWithin(LutMapLeft, LutMapTop, LutMapRight, LutMapBottom, 0, 'LUT Register Bitmap/Heatmap | Click to lock disassembly to LUT subrange');
InCF := MouseWithin(CFLeft, CFTop, CFRight, CFBottom, 0, 'Carry Flag');
InZF := MouseWithin(ZFLeft, ZFTop, ZFRight, ZFBottom, 0, 'Zero Flag');
InPC := MouseWithin(PCLeft, PCTop, PCRight, PCBottom, 0, 'Program Counter | Click to lock disassembly to PC');
InSkip := MouseWithin(SkipLeft, SkipTop, SkipRight, SkipBottom, 0, 'Skip-Instruction Pattern');
InXBYTE := MouseWithin(XBYTELeft, XBYTETop, XBYTERight, XBYTEBottom, 0, '');
InCT := MouseWithin(CTLeft, CTTop, CTRight, CTBottom, 0, '');
InDis := MouseWithin(DisLeft, DisTop, DisRight, DisBottom, 0, 'L-Click to lock to PC | R-Click to toggle break address | Mousewheel {+Ctrl/Shift} scrolls');
InRegWatch := MouseWithin(RegWatchLeft, RegWatchTop, RegWatchRight, RegWatchBottom, 0, 'Register-Delta Watch List | Click or <R> to reset list');
InSFRBox := MouseWithin(SFRBoxLeft, SFRBoxTop, SFRBoxRight, SFRBoxBottom, 0, 'Special-Function Registers');
InSFRData := MouseWithin(SFRDataLeft, SFRDataTop, SFRDataRight, SFRDataBottom, 0, '');
InEventsBox := MouseWithin(EventsBoxLeft, EventsBoxTop, EventsBoxRight, EventsBoxBottom, 0, 'Event Flags');
InEvents := MouseWithin(EventsLeft, EventsTop, EventsRight, EventsBottom, 0, 'Event Flags | L-Click to break on ' + EventName[Within((MouseY - EventsTop) div ChrHeight, 0, 14) + 1] + ' event | R-Click to toggle'); // 'Within' is required since MouseY is potentially out-of-range
InExec := MouseWithin(ExecLeft, ExecTop, ExecRight, ExecBottom, 0, 'Instruction Disassembly');
InStackBox := MouseWithin(StackBoxLeft, StackBoxTop, StackBoxRight, StackBoxBottom, 0, 'Stack Registers (top..bottom)');
InStackData := MouseWithin(StackDataLeft, StackDataTop, StackDataRight, StackDataBottom, 9, '');
InIntBox := MouseWithin(IntBoxLeft, IntBoxTop, IntBoxRight, IntBoxBottom, 0, 'Interrupt Status');
InPtrBox := MouseWithin(PtrBoxLeft, PtrBoxTop, PtrBoxRight, PtrBoxBottom, 0, 'Pointers and Data');
InPtrAddr := MouseWithin(PtrAddrLeft, PtrAddrTop, PtrAddrRight, PtrAddrBottom, 0, '');
InPtrData := MouseWithin(PtrDataLeft, PtrDataTop, PtrDataRight, PtrDataBottom, 3, '');
InPtrChr := MouseWithin(PtrChrLeft, PtrChrTop, PtrChrRight, PtrChrBottom, 0, '');
InStatusBox := MouseWithin(StatusLeft, StatusTop, StatusRight, StatusBottom, 0, 'Indicators for COGINIT, STALLI, Streamer, Color Modulator, LUT sharing');
InPinBox := MouseWithin(PinBoxLeft, PinBoxTop, PinBoxRight, PinBoxBottom, 0, 'Pin Registers');
InPinData := MouseWithin(PinDataLeft, PinDataTop, PinDataRight, PinDataBottom, 9, '');
InSmartWatch := MouseWithin(SmartWatchLeft, SmartWatchTop, SmartWatchRight, SmartWatchBottom, 0, '');
InHubTab := MouseWithin(HubTabLeft, HubTabTop, HubTabRight, HubTabBottom, 0, 'Hub Data');
InHubBox := MouseWithin(HubBoxLeft, HubBoxTop, HubBoxRight, HubBoxBottom, 0, 'Hub Data | Mousewheel {+Ctrl/Shift} scrolls');
InHubAddr := MouseWithin(HubAddrLeft, HubAddrTop, HubAddrRight, HubAddrBottom, 0, 'Hub Data | Mousewheel changes HUB address digit(s)');
InHubData := MouseWithin(HubDataLeft, HubDataTop, HubDataRight, HubDataBottom, 3, '');
InHubChr := MouseWithin(HubChrLeft, HubChrTop, HubChrRight, HubChrBottom, 0, '');
InHubMap := MouseWithin(HubMapLeft, HubMapTop, HubMapRight, HubMapBottom, 0, 'HUB Heatmap | Click to lock HUB address');
InButtonBox := MouseWithin(ButtonBoxLeft, ButtonBoxTop, ButtonBoxRight, ButtonBoxBottom, 0, 'Break Control | Select break condition(s) and execute code');
InButtonBreak := MouseWithin(ButtonBreakLeft, ButtonBreakTop, ButtonBreakRight, ButtonBreakBottom, 0, 'Click or <B> to select asynchronous BREAK | Another cog must be in DEBUG for BREAK to work');
InButtonAddr := MouseWithin(ButtonAddrLeft, ButtonAddrTop, ButtonAddrRight, ButtonAddrBottom, 0, 'L-Click to break on PC address | R-Click to toggle | R-Click in disassembly to set address');
InButtonInt3E := MouseWithin(ButtonInt3ELeft, ButtonInt3ETop, ButtonInt3ERight, ButtonInt3EBottom, 0, 'L-Click to break on INT3 entry | R-Click to toggle');
InButtonInt2E := MouseWithin(ButtonInt2ELeft, ButtonInt2ETop, ButtonInt2ERight, ButtonInt2EBottom, 0, 'L-Click to break on INT2 entry | R-Click to toggle');
InButtonInt1E := MouseWithin(ButtonInt1ELeft, ButtonInt1ETop, ButtonInt1ERight, ButtonInt1EBottom, 0, 'L-Click to break on INT1 entry | R-Click to toggle');
InButtonDebug := MouseWithin(ButtonDebugLeft, ButtonDebugTop, ButtonDebugRight, ButtonDebugBottom, 0, 'L-Click to break on DEBUG | R-Click or <D> to toggle | DEBUG is exclusive to all but INIT');
InButtonInit := MouseWithin(ButtonInitLeft, ButtonInitTop, ButtonInitRight, ButtonInitBottom, 0, 'L-Click to break on COGINIT | R-Click or <I> to toggle | INIT is independent of all others');
InButtonEvent := MouseWithin(ButtonEventLeft, ButtonEventTop, ButtonEventRight, ButtonEventBottom, 0, 'L-Click to break on event | R-Click to toggle | Select event by clicking on CT1..QMT');
InButtonInt3 := MouseWithin(ButtonInt3Left, ButtonInt3Top, ButtonInt3Right, ButtonInt3Bottom, 0, 'L-Click to break on INT3 instructions (single-step) | R-Click to toggle');
InButtonInt2 := MouseWithin(ButtonInt2Left, ButtonInt2Top, ButtonInt2Right, ButtonInt2Bottom, 0, 'L-Click to break on INT2 instructions (single-step) | R-Click to toggle');
InButtonInt1 := MouseWithin(ButtonInt1Left, ButtonInt1Top, ButtonInt1Right, ButtonInt1Bottom, 0, 'L-Click to break on INT1 instructions (single-step) | R-Click to toggle');
InButtonMain := MouseWithin(ButtonMainLeft, ButtonMainTop, ButtonMainRight, ButtonMainBottom, 0, 'L-Click to break on MAIN instructions (single-step) | R-Click or <M> to toggle');
InButtonGo := MouseWithin(ButtonGoLeft, ButtonGoTop, ButtonGoRight, ButtonGoBottom, 0, '');
// Resolve any reg map address
if InRegMap then
MapCogAddr := Within((MouseY - RegMapTop) shl 9 div (RegMapBottom - RegMapTop) - 8, $000, $1F0)
// Resolve any lut map address
else if InLutMap then
MapCogAddr := Within((MouseY - LutMapTop) shl 9 div (LutMapBottom - LutMapTop) - 8, $000, $1F0) + $200
// Resolve any hub map address
else if InHubMap then
MapHubAddr := (MouseY - HubMapTop) * HubMapHeight div (HubMapBottom - HubMapTop) * HubMapWidth * HubSubBlockSize +
(MouseX - HubMapLeft) * HubMapWidth div (HubMapRight - HubMapLeft) * HubSubBlockSize;
// Reset mouse-move timer
MouseMoveTimer.Enabled := False;
MouseMoveTimer.Interval := 50;
MouseMoveTimer.Enabled := True;
end;
procedure TDebuggerForm.FormMouseMoveTimeout(Sender: TObject);
var
p: TPoint;
begin
p := ScreenToClient(Mouse.CursorPos); // is mouse off form?
if (p.x < 0) or (p.x >= ClientWidth) or
(p.y < 0) or (p.y >= ClientHeight) then
begin
FormMouseMove(Self, [], 0, 0); // signal mouse is now off form
MouseMoveTimer.Enabled := False; // cancel mouse-move timer
end;
end;
procedure TDebuggerForm.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i, j: integer;
LB, RB: boolean;
begin
LB := Button = mbLeft;
RB := Button = mbRight;
// In Go button?
if InButtonGo then
begin
// Start Go button timer and set state
ButtonTimer.Enabled := False;
ButtonTimer.Interval := 100;
ButtonTimer.Enabled := True;
GoState := 2;
// Break?
if BreakpointTimer.Enabled = False then
begin
RequestCOGBRK := RequestCOGBRK or 1 shl (DebuggerMsg[mCOGN] and 7);
StallBrk := StallCmd;
RepeatMode := False;
end
// Stop?
else if RepeatMode then
begin
StallBrk := StallCmd;
RepeatMode := False;
end
// Go-single?
else if LB then
StallBrk := BreakValue
// Go-repeat?
else if RB then
begin
OldTickCount := GetTickCount;
RepeatMode := True;
end;
end
// In MAIN button?
else if InButtonMain then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000001
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000001;
end
// In INT1 button?
else if InButtonInt1 then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000002
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000002;
end
// In INT2 button?
else if InButtonInt2 then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000004
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000004;
end
// In INT3 button?
else if InButtonInt3 then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000008
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000008;
end
// In DEBUG button?
else if InButtonDebug then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000010
else if RB then
BreakValue := BreakValue and $00000110 xor $00000010;
end
// In INT1E button?
else if InButtonInt1E then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000020
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000020;
end
// In INT2E button?
else if InButtonInt2E then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000040
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000040;
end
// In INT3E button?
else if InButtonInt3E then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000080
else if RB then
BreakValue := BreakValue and $FFFFFFEF xor $00000080;
end
// In INIT button?
else if InButtonInit then
begin
if LB then
BreakValue := BreakValue or $00000100 // bit 8 is used to convey COGINIT, but set on BRK before RETI0 to enable async break
else if RB then
BreakValue := BreakValue xor $00000100;
end
// In CT1..QMT or event button?
else if InEvents or InButtonEvent then
begin
if InEvents then
BreakEvent := (MouseY - EventsTop) div ChrHeight + 1;
if LB then
BreakValue := BreakValue and $00000100 or $00000200 or BreakEvent shl 12
else if RB then
begin
if BreakValue and $00000200 <> 0 then
BreakValue := BreakValue and $00000DEF
else
BreakValue := BreakValue and $00000BEF or $00000200 or BreakEvent shl 12;
end;
end
// In address breakpoint button?
else if inButtonAddr then
begin
if LB then
BreakValue := BreakValue and $00000100 or $00000400 or BreakAddr shl 12
else if RB then
begin
if BreakValue and $00000400 <> 0 then
BreakValue := BreakValue and $00000BEF
else
BreakValue := BreakValue and $00000DEF or $00000400 or BreakAddr shl 12;
end;
end
// In BREAK button?
else if InButtonBreak then
BreakValue := BreakValue and $00000100
// In REG/LUT map?
else if InRegMap or InLutMap then
begin
DisMode := dmCog;
CogAddr := MapCogAddr;
end
// In PC box?
else if InPC then
DisMode := dmPC
// In disassembly box?
else if InDis then
begin
// Lock disassembly to PC?
if LB then
DisMode := dmPC
// Set breakpoint?
else if RB then
begin
i := (MouseY - DisTop) div ChrHeight;
if (CurDisMode = dmHub) and (CurDisAddr + i shl 2 < $400) then Exit;
if (CurDisMode = dmHub) or (CurDisAddr >= $400) then
j := (CurDisAddr + i shl 2) and $FFFFF
else
j := (CurDisAddr + i) and $3FF;
if (BreakValue and $00000400 <> 0) and (BreakAddr = j) then
BreakValue := BreakValue and $00000BFF
else
begin
BreakAddr := j;
BreakValue := BreakValue and $00000DFF or $00000400 or BreakAddr shl 12;
end;
end;
end
// In register watch?
else if InRegWatch then
ResetRegWatch
// In SFR data?
else if InSFRData then
begin
i := (MouseY - SFRDataTop) div ChrHeight;
j := CogImage[$1F0 + i] and $FFFFF;
if (j < $400) and (i < 6) then // treat IJMP3..IRET1 as code pointers
begin
DisMode := dmCog;
CogAddr := j;
end
else // treat PA..PTRB as hub data pointers
begin
DisMode := dmHub;
HubAddr := j;
end;
end
// In stack data?
else if InStackData then // treat stack values as code pointers
begin
i := (MouseX - StackDataLeft) div ChrWidth;
j := DebuggerMsg[mSTK0 + i div 9] and $FFFFF;
if j < $400 then
begin
DisMode := dmCog;
CogAddr := j;
end
else
begin
DisMode := dmHub;
HubAddr := j;
end;
end
// In pointer addresses?
else if InPtrAddr then // treat pointer addresses as hub data pointers
begin
DisMode := dmHub;
HubAddr := DebuggerMsg[mFPTR + (MouseY - PtrAddrTop) div ChrHeight] and $FFFFF;
end
// In pointer data?
else if InPtrData then
begin
i := (MouseX - PtrDataLeft) div ChrWidth;
j := (DebuggerMsg[mFPTR + (MouseY - PtrDataTop) div ChrHeight] - PtrCenter) and $FFFFF;
DisMode := dmHub;
HubAddr := (j + i div 3) and $FFFFF;
end
// In pointer chr?
else if InPtrChr then
begin
i := (MouseX - PtrChrLeft) div ChrWidth;
j := (DebuggerMsg[mFPTR + (MouseY - PtrDataTop) div ChrHeight] - PtrCenter) and $FFFFF;
DisMode := dmHub;
HubAddr := (j + i) and $FFFFF;
end
// In smart pin watch?
else if InSmartWatch then
begin
ResetSmartWatch;
// Toggle smart pin watch?
if RB then
WatchSmartAll := not WatchSmartAll;
end
// In hub data or chr?
else if InHubData or InHubChr then
begin
if InHubData then
i := (MouseY - HubDataTop) div ChrHeight shl 4 +
(MouseX - HubDataLeft) div ChrWidth div 3
else
i := (MouseY - HubChrTop) div ChrHeight shl 4 +
(MouseX - HubChrLeft) div ChrWidth;
DisMode := dmHub;
HubAddr := (HubAddr + i) and $FFFFF;
end
// In hub map?
else if InHubMap then
HubAddr := MapHubAddr;
end;
procedure TDebuggerForm.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: boolean);
const
DisDeltas : array [0..3] of integer = (1, 4, 16, 32);
HubDeltas : array [0..3] of integer = (16, 1, 4, 128);
var
i, j, DisStep, HubStep: integer;
begin
if WheelDelta > 0 then i := -1 else i := 1;
j := Ord(ssShift in Shift) shl 1 or Ord(ssCtrl in Shift);
DisStep := i * DisDeltas[j];
HubStep := i * HubDeltas[j];
// In disassembly box?
if InDis then
begin
if DisMode = dmPC then // change dmPC to dmCog or dmHub to scroll freely
begin
if DisAddr < $400 then
begin
DisMode := dmCog;
CogAddr := DisAddr;
end
else
begin
DisMode := dmHub;
HubAddr := DisAddr;
end;
end;
case DisMode of