-
Notifications
You must be signed in to change notification settings - Fork 5
/
DebugDisplayUnit.pas
4186 lines (3958 loc) · 128 KB
/
DebugDisplayUnit.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
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}
{$APPTYPE GUI}
unit DebugDisplayUnit;
interface
uses
Windows, Messages, SysUtils, ExtCtrls, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Math, SerialUnit;
const
ele_end = 0; // elements
ele_dis = 1;
ele_nam = 2;
ele_key = 3;
ele_num = 4;
ele_str = 5;
dis_logic = 0; // displays
dis_scope = 1;
dis_scope_xy = 2;
dis_fft = 3;
dis_spectro = 4;
dis_plot = 5;
dis_term = 6;
dis_bitmap = 7;
dis_midi = 8;
key_black = 0; // color group
key_white = 1;
key_orange = 2;
key_blue = 3;
key_green = 4;
key_cyan = 5;
key_red = 6;
key_magenta = 7;
key_yellow = 8;
key_gray = 9;
key_lut1 = 10; // color-mode group
key_lut2 = 11;
key_lut4 = 12;
key_lut8 = 13;
key_luma8 = 14;
key_luma8w = 15;
key_luma8x = 16;
key_hsv8 = 17;
key_hsv8w = 18;
key_hsv8x = 19;
key_rgbi8 = 20;
key_rgbi8w = 21;
key_rgbi8x = 22;
key_rgb8 = 23;
key_hsv16 = 24;
key_hsv16w = 25;
key_hsv16x = 26;
key_rgb16 = 27;
key_rgb24 = 28;
key_longs_1bit = 29; // packed-data group
key_longs_2bit = 30;
key_longs_4bit = 31;
key_longs_8bit = 32;
key_longs_16bit = 33;
key_words_1bit = 34;
key_words_2bit = 35;
key_words_4bit = 36;
key_words_8bit = 37;
key_bytes_1bit = 38;
key_bytes_2bit = 39;
key_bytes_4bit = 40;
key_alt = 41; // keywords
key_auto = 42;
key_backcolor = 43;
key_box = 44;
key_cartesian = 45;
key_channel = 46;
key_circle = 47;
key_clear = 48;
key_close = 49;
key_color = 50;
key_depth = 51;
key_dot = 52;
key_dotsize = 53;
key_hidexy = 54;
key_holdoff = 55;
key_line = 56;
key_linesize = 57;
key_logscale = 58;
key_lutcolors = 59;
key_mag = 60;
key_obox = 61;
key_opacity = 62;
key_origin = 63;
key_oval = 64;
key_pc_key = 65;
key_pc_mouse = 66;
key_polar = 67;
key_pos = 68;
key_precise = 69;
key_range = 70;
key_rate = 71;
key_samples = 72;
key_save = 73;
key_scroll = 74;
key_set = 75;
key_signed = 76;
key_size = 77;
key_spacing = 78;
key_sparse = 79;
key_sprite = 80;
key_spritedef = 81;
key_text = 82;
key_textangle = 83;
key_textsize = 84;
key_textstyle = 85;
key_title = 86;
key_trace = 87;
key_trigger = 88;
key_update = 89;
key_window = 90;
TypeName : array [dis_logic..dis_midi] of string = (
'LOGIC',
'SCOPE',
'SCOPE_XY',
'FFT',
'SPECTRO',
'PLOT',
'TERM',
'BITMAP',
'MIDI' );
PackDef : array [key_longs_1bit..key_bytes_4bit] of integer = (
0 shl 16 + 1 shl 8 + 32, // key_longs_1bit
0 shl 16 + 2 shl 8 + 16, // key_longs_2bit
0 shl 16 + 4 shl 8 + 8, // key_longs_4bit
0 shl 16 + 8 shl 8 + 4, // key_longs_8bit
0 shl 16 + 16 shl 8 + 2, // key_longs_16bit
0 shl 16 + 1 shl 8 + 16, // key_words_1bit
0 shl 16 + 2 shl 8 + 8, // key_words_2bit
0 shl 16 + 4 shl 8 + 4, // key_words_4bit
0 shl 16 + 8 shl 8 + 2, // key_words_8bit
0 shl 16 + 1 shl 8 + 8, // key_bytes_1bit
0 shl 16 + 2 shl 8 + 4, // key_bytes_2bit
0 shl 16 + 4 shl 8 + 2); // key_bytes_4bit
DataSetsExp = 11;
DataSets = 1 shl DataSetsExp;
Channels = 8;
TopChannel = Channels - 1;
LogicChannels = 32;
TopLogicChannel = LogicChannels - 1;
LogicSets = DataSets;
LogicPtrMask = LogicSets - 1;
FFTexpMax = DataSetsExp;
FFTmax = DataSets;
Y_SetSize = Channels;
Y_Sets = DataSets;
Y_PtrMask = Y_Sets - 1;
XY_Elements = 2;
XY_SetSize = Channels * XY_Elements;
XY_Sets = DataSets;
XY_PtrMask = XY_Sets - 1;
SPECTRO_Samples = DataSets;
SPECTRO_PtrMask = SPECTRO_Samples - 1;
clRed = $FF0000;
clLime = $00FF00;
clBlue = $3F3FFF;
clYellow = $FFFF00;
clMagenta = $FF00FF;
clCyan = $00FFFF;
clOrange = $FF7F00;
clOlive = $7F7F00;
clWhite = $FFFFFF;
clBlack = $000000;
clGray = $404040;
clGray2 = $808080;
clGray3 = $D0D0D0;
DefaultBackColor = clBlack;
DefaultGridColor = clGray;
DefaultPlotColor = clCyan;
DefaultTextColor = clWhite;
DefaultLineSize = 1;
DefaultDotSize = 1;
DefaultTextSize = 10;
DefaultTextStyle = 1;
DefaultCols = 40;
DefaultRows = 20;
fft_default = 512;
SmoothFillMax = DataSets;
scope_wmin = 32;
scope_wmax = SmoothFillMax;
scope_hmin = 32;
scope_hmax = SmoothFillMax;
scope_xy_wmin = 32;
scope_xy_wmax = SmoothFillMax;
plot_wmin = 32;
plot_wmax = SmoothFillMax;
plot_hmin = 32;
plot_hmax = SmoothFillMax;
term_colmin = 1;
term_colmax = 256;
term_rowmin = 1;
term_rowmax = 256;
bitmap_wmin = 1;
bitmap_wmax = SmoothFillMax;
bitmap_hmin = 1;
bitmap_hmax = SmoothFillMax;
MidiSizeBase = 8;
MidiSizeFactor = 4;
SpriteMax = 256;
SpriteMaxX = 32;
SpriteMaxY = 32;
DefaultScopeColors : array[0..7] of integer = (clLime, clRed, clCyan, clYellow, clMagenta, clBlue, clOrange, clOlive);
DefaultTermColors : array[0..7] of integer = (clOrange, clBlack, clBlack, clOrange, clLime, clBlack, clBlack, clLime);
type
TDebugDisplayForm = class(TForm)
MouseWheelTimer : TTimer;
KeyTimer : TTimer;
private
DisplayType : integer;
ChrHeight : integer;
ChrWidth : integer;
Bitmap : array [0..1] of TBitmap;
BitmapLine : array [0..SmoothFillMax - 1] of Pointer;
DesktopDC : HDC;
DesktopBitmap : TBitmap;
CursorMask : TBitmap;
CursorColor : TBitmap;
CursorInfo : TIconInfo;
CursorWidth : integer;
CursorHeight : integer;
CaptionStr : string;
CaptionPos : boolean;
vBitmapWidth : integer;
vBitmapHeight : integer;
vClientWidth : integer;
vClientHeight : integer;
vWidth : integer;
vHeight : integer;
vMarginLeft : integer;
vMarginRight : integer;
vMarginTop : integer;
vMarginBottom : integer;
vRange : integer;
vSamples : integer;
vRate : integer;
vRateCount : integer;
vSpacing : integer;
vTriggerMask : integer;
vTriggerMatch : integer;
vTriggerChannel : integer;
vTriggerArm : integer;
vTriggerFire : integer;
vTriggerOffset : integer;
vArmed : boolean;
vTriggered : boolean;
vHoldOff : integer;
vHoldOffCount : integer;
vToggle : boolean;
vLogicIndex : integer;
vLogicLabel : array [0..TopLogicChannel] of string;
vLogicColor : array [0..TopLogicChannel] of integer;
vLabel : array [0..TopChannel] of string;
vAuto : array [0..TopChannel] of boolean;
vHigh : array [0..TopChannel] of integer;
vLow : array [0..TopChannel] of integer;
vMag : array [0..TopChannel] of integer;
vTall : array [0..TopChannel] of integer;
vBase : array [0..TopChannel] of integer;
vGrid : array [0..TopChannel] of integer;
vColor : array [0..TopChannel] of integer;
vLut : array [0..255] of integer;
vColorTune : integer;
vPolar : boolean;
vTwoPi : int64;
vTheta : integer;
vBackColor : integer;
vGridColor : integer;
vPlotColor : integer;
vTextAngle : integer;
vTextColor : integer;
vTextBackColor : integer;
vUpdate : boolean;
vUpdateFlag : boolean;
vLogScale : boolean;
vDirX : boolean;
vDirY : boolean;
vHideXY : boolean;
vOffsetX : integer;
vOffsetY : integer;
vColorMode : integer;
vTrace : integer;
vPixelX : integer;
vPixelY : integer;
vLineSize : integer;
vDotSize : integer;
vDotSizeY : integer;
vSparse : integer;
vTextSize : integer;
vTextStyle : integer;
vOpacity : byte;
vPrecise : byte;
vCols : integer;
vRows : integer;
vCol : integer;
vRow : integer;
vIndex : integer;
vScale : extended;
vMouseWheel : integer;
vKeyPress : byte;
vPackAlt : boolean;
vPackSignx : boolean;
vPackMask : integer;
vPackShift : integer;
vPackCount : integer;
ptr : integer;
val : integer;
LogicSampleBuff : array [0..LogicSets - 1] of integer;
Y_SampleBuff : array [0..Y_Sets * Y_SetSize - 1] of integer;
XY_SampleBuff : array [0..XY_Sets * XY_SetSize - 1] of integer;
SPECTRO_SampleBuff : array [0..SPECTRO_Samples - 1] of integer;
PolarColors : array [0..255] of integer;
MidiSize : integer;
MidiKeySize : integer;
MidiKeyFirst : integer;
MidiKeyLast : integer;
MidiOffset : integer;
MidiChannel : integer;
MidiState : integer;
MidiNote : integer;
MidiBlack : array [0..127] of boolean;
MidiLeft : array [0..127] of integer;
MidiRight : array [0..127] of integer;
MidiBottom : array [0..127] of integer;
MidiNumX : array [0..127] of integer;
MidiVelocity : array [0..127] of integer;
FFTexp : integer;
FFTmag : integer;
FFTfirst : integer;
FFTlast : integer;
FFTsin : array [0..FFTmax - 1] of int64;
FFTcos : array [0..FFTmax - 1] of int64;
FFTwin : array [0..FFTmax - 1] of int64;
FFTreal : array [0..FFTmax - 1] of int64;
FFTimag : array [0..FFTmax - 1] of int64;
FFTsamp : array [0..FFTmax - 1] of integer;
FFTpower : array [0..FFTmax div 2 - 1] of integer;
FFTangle : array [0..FFTmax div 2 - 1] of integer;
SpritePixels : array [0..SpriteMax * SpriteMaxX * SpriteMaxY - 1] of byte;
SpriteColors : array [0..SpriteMax * 256 - 1] of integer;
SpriteSizeX : array [0..SpriteMax - 1] of byte;
SpriteSizeY : array [0..SpriteMax - 1] of byte;
SamplePtr : integer;
SamplePop : integer;
FontAngle : integer;
OldFontHandle : hFont;
NewFontHandle : hFont;
NewLogFont : TLogFont;
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 FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: boolean);
procedure FormMouseWheelTimerTick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyTimerTick(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormMove(var Msg: TWMMove); message WM_WINDOWPOSCHANGED;
procedure FormDestroy(Sender: TObject);
procedure UpdateDisplay(Index: integer);
procedure LOGIC_Configure;
procedure LOGIC_Update;
procedure LOGIC_Draw;
procedure SCOPE_Configure;
procedure SCOPE_Update;
procedure SCOPE_Draw;
procedure SCOPE_XY_Configure;
procedure SCOPE_XY_Update;
procedure SCOPE_XY_Plot(x, y, color: integer; opacity: byte);
procedure FFT_Configure;
procedure FFT_Update;
procedure FFT_Draw;
procedure SPECTRO_Configure;
procedure SPECTRO_Update;
procedure SPECTRO_Draw;
procedure PLOT_Configure;
procedure PLOT_Update;
procedure PLOT_GetXY(var x, y: integer);
procedure TERM_Configure;
procedure TERM_Update;
procedure TERM_Chr(c: Char);
procedure BITMAP_Configure;
procedure BITMAP_Update;
procedure MIDI_Configure;
procedure MIDI_Update;
procedure MIDI_Draw(Clear: boolean);
procedure MIDI_DrawKey(i, OffColor, OnColor, r: integer);
procedure KeyTitle;
function KeyVal(var v: integer): boolean;
function KeyBool(var v: boolean): boolean;
function KeyValWithin(var v: integer; bottom, top: integer): boolean;
procedure KeyPos;
procedure KeySize(var x, y: integer; wmin, wmax, hmin, hmax: integer);
procedure KeyTwoPi;
function KeyColor(var c: integer): boolean;
procedure KeyColorMode;
procedure KeyLutColors;
procedure KeyPack;
procedure KeyTextSize;
procedure KeySave;
procedure SetCaption(s: string);
procedure SetDefaults;
procedure SetTextMetrics;
procedure SetSize(MarginLeft, MarginTop, MarginRight, MarginBottom: integer);
procedure SetLogicLabelColor(ChannelLabel: string; Number, ColorIndex: integer);
procedure SetTrace(Path: integer; ModifyRate: boolean);
procedure StepTrace;
procedure PolarToCartesian(var rho_x, theta_y: integer);
procedure MakeTextAngle(var a: integer);
function RateCycle: boolean;
function TranslateColor(p, mode: integer): integer;
function WinRGB(p: integer): integer;
function GetBackground: integer;
procedure SetPolarColors;
procedure ClearBitmap;
function AlphaBlend(a, b: integer; x: byte): integer;
procedure DrawLineDot(x, y, color: integer; first: boolean);
procedure PlotPixel(p: integer);
procedure ScrollBitmap(x, y: integer);
procedure AngleTextOut(x, y: integer; s: string; style, angle: integer);
procedure BitmapToCanvas(Level: integer);
procedure SendMousePos;
procedure SendKeyPress;
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;
function NextKey: boolean;
function NextNum: boolean;
function NextStr: boolean;
function NextEnd: boolean;
function NextElement(Element: integer): boolean;
procedure SetPack(val: integer; alt, signx: boolean);
function NewPack: integer;
function UnPack(var v: integer): integer;
procedure PrepareFFT;
procedure PerformFFT;
function Rev32(i: integer): int64;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
uses GlobalUnit, DebugUnit;
//////////////////////
// Event Routines //
//////////////////////
constructor TDebugDisplayForm.Create(AOwner: TComponent);
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;
OnMouseWheel := FormMouseWheel;
OnKeyPress := FormKeyPress;
OnKeyDown := FormKeyDown;
OnPaint := FormPaint;
OnDestroy := FormDestroy;
MouseWheelTimer := TTimer.Create(Self);
MouseWheelTimer.OnTimer := FormMouseWheelTimerTick;
MouseWheelTimer.Enabled := False;
KeyTimer := TTimer.Create(Self);
KeyTimer.OnTimer := FormKeyTimerTick;
KeyTimer.Enabled := False;
end;
destructor TDebugDisplayForm.Destroy;
begin
MouseWheelTimer.Free;
KeyTimer.Free;
inherited Destroy;
end;
procedure TDebugDisplayForm.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
inherited;
Msg.Result := Msg.Result or DLGC_WANTTAB;
end;
procedure TDebugDisplayForm.FormCreate(Sender: TObject);
begin
// Set up display bitmaps
Bitmap[0] := TBitmap.Create;
Bitmap[0].PixelFormat := pf24bit;
Bitmap[1] := TBitmap.Create;
Bitmap[1].PixelFormat := pf24bit;
Bitmap[0].Canvas.Font.Name := FontName;
vTextSize := FontSize;
SetTextMetrics;
// Set up cursor bitmaps
CursorMask := TBitmap.Create;
CursorMask.PixelFormat := pf24bit;
CursorColor := TBitmap.Create;
CursorColor.PixelFormat := pf24bit;
CursorColor.Canvas.Font.Name := FontName;
CursorColor.Canvas.Font.Size := FontSize;
CursorColor.Canvas.Font.Style := [];
CursorWidth := CursorColor.Canvas.TextWidth('-2147483648,-2147483648') + 16; // assure maximum values will fit
CursorHeight := CursorColor.Canvas.TextHeight('X') + 16; // no need to resize, faster
CursorMask.Width := CursorWidth;
CursorMask.Height := CursorHeight;
CursorColor.Width := CursorWidth;
CursorColor.Height := CursorHeight;
// Set up screen-capture bitmap and handle
DesktopBitmap := TBitmap.Create;
DesktopDC := GetWindowDC(GetDesktopWindow);
// Set up polar colors
SetPolarColors;
// Init font angle
FontAngle := 0;
// Determine mode
DisplayType := P2.DebugDisplayValue[0];
SetCaption(PChar(P2.DebugDisplayValue[1]) + ' - ' + TypeName[DisplayType]);
// Set initial position
Left := P2.DebugDisplayLeft;
Top := P2.DebugDisplayTop;
// Configure DEBUG display window
SetDefaults;
ptr := 2;
case DisplayType of
dis_logic : LOGIC_Configure;
dis_scope : SCOPE_Configure;
dis_scope_xy : SCOPE_XY_Configure;
dis_fft : FFT_Configure;
dis_spectro : SPECTRO_Configure;
dis_plot : PLOT_Configure;
dis_term : TERM_Configure;
dis_bitmap : BITMAP_Configure;
dis_midi : MIDI_Configure;
end;
Show;
end;
procedure TDebugDisplayForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
DebugCursor = 5; // user cursors are positive, system cursors are negative
var
Str: string;
Rf, Tf, Xf, Yf: extended;
ScaledX, ScaledY, Bias: int64;
StrW, StrH, W, H: integer;
Quadrant: integer;
TextX, TextY, CursX, CursY: integer;
begin
Str := '';
case DisplayType of
dis_logic:
begin
if (X >= vMarginLeft) and (X < vMarginLeft + vWidth)
and (Y >= vMarginTop) and (Y < vMarginTop + vHeight) then
Str := IntToStr(-(vMarginLeft + vWidth - 1 - X) div vSpacing) + ',' + IntToStr((vMarginTop + vHeight - 1 - Y) div ChrHeight)
else
Str := '';
end;
dis_fft, dis_scope:
begin
if (X >= vMarginLeft) and (X < vMarginLeft + vWidth)
and (Y >= vMarginTop) and (Y < vMarginTop + vHeight) then
Str := IntToStr(X - vMarginLeft) + ',' + IntToStr(vMarginTop + vHeight - 1 - Y)
else
Str := '';
end;
dis_scope_xy:
if not vPolar then
begin
ScaledX := X - ClientWidth div 2;
ScaledY := ClientWidth div 2 - Y;
if vLogScale then
begin
Rf := Power(2, Hypot(ScaledX, ScaledY) / (vWidth div 2) * Log2(Int64(vRange) + 1)) - 1;
Tf := ArcTan2(ScaledX, ScaledY);
SinCos(Tf, Xf, Yf);
ScaledX := Round(Rf * Xf);
ScaledY := Round(Rf * Yf);
end
else
begin
Bias := Round(vWidth / vRange / 4); // Bias centers values spanning multiple pixels
if ScaledX < 0 then Dec(ScaledX, Bias) else Inc(ScaledX, Bias);
if ScaledY < 0 then Dec(ScaledY, Bias) else Inc(ScaledY, Bias);
ScaledX := Round(ScaledX / vScale);
ScaledY := Round(ScaledY / vScale);
end;
Str := IntToStr(ScaledX) + ',' + IntToStr(ScaledY);
end
else
begin
ScaledX := X - ClientWidth div 2;
ScaledY := ClientWidth div 2 - Y;
Rf := Hypot(ScaledX, ScaledY);
if vLogScale then
Rf := Power(2, Rf / (vWidth div 2) * Log2(Int64(vRange) + 1)) - 1
else
Rf := Round(Rf / vScale);
Tf := ArcTan2(ScaledY, ScaledX) / (Pi * 2);
ScaledX := Round(Rf);
ScaledY := Round(Tf * vTwoPi) - vTheta;
if (vTwoPi = $100000000) or (vTwoPi = -$100000000) then
Str := IntToStr(ScaledX) + ',$' + IntToHex(ScaledY and $FFFFFFFF, 8) + '*'
else
begin
if ScaledY < 0 then Inc(ScaledY, Abs(vTwoPi));
Str := IntToStr(ScaledX) + ',' + IntToStr(ScaledY) + '*';
end;
end;
dis_plot:
begin
if vDirX then TextX := (ClientWidth - X) else TextX := X;
if vDirY then TextY := Y else TextY := (ClientHeight - Y);
Str := IntToStr(TextX div vDotSize) + ',' + IntToStr(TextY div vDotSizeY);
end;
dis_term:
begin
if (X >= vMarginLeft) and (X < vMarginLeft + ChrWidth * vCols)
and (Y >= vMarginTop) and (Y < vMarginTop + ChrHeight * vRows) then
Str := IntToStr((X - vMarginLeft) div ChrWidth) + ',' + IntToStr((Y - vMarginTop) div ChrHeight)
else
Str := '';
end;
dis_spectro, dis_bitmap:
Str := IntToStr(X div vDotSize) + ',' + IntToStr(Y div vDotSizeY);
end;
// Get measurement cursor dimensions
if vHideXY then Str := '';
StrW := CursorColor.Canvas.TextWidth(Str) + 1; // + 1 prevents cursor rendering glitch
StrH := CursorHeight - 16; // computed in FormCreate
W := StrW + 16;
H := CursorHeight;
// Handle justification
if X >= ClientWidth div 2 then Quadrant := 1 else Quadrant := 0;
if Y >= ClientHeight div 2 then Quadrant := Quadrant or 2;
case Quadrant of
0: begin
TextX := 16;
TextY := 16;
CursX := 9;
CursY := 9;
end;
1: begin
TextX := 0;
TextY := 16;
CursX := W - 9;
CursY := 9;
end;
2: begin
TextX := 16;
TextY := 0;
CursX := 9;
CursY := H - 9;
end;
3: begin
TextX := 0;
TextY := 0;
CursX := W - 9;
CursY := H - 9;
end;
end;
// Clear color bitmap
CursorColor.Canvas.Brush.Color := clBlack;
CursorColor.Canvas.FillRect(Rect(0, 0, CursorWidth, CursorHeight));
// Clear mask bitmap
CursorMask.Canvas.Brush.Color := clWhite;
CursorMask.Canvas.FillRect(Rect(0, 0, CursorWidth, CursorHeight));
// If text present, add to bitmaps
if Str <> '' then
begin
// Draw text on color bitmap
CursorColor.Canvas.Brush.Color := WinRGB(vBackColor);
CursorColor.Canvas.Font.Color := WinRGB(vGridColor); //vBackColor xor $FFFFFF;
CursorColor.Canvas.TextRect(Rect(TextX, TextY, TextX + StrW, TextY + StrH), TextX, TextY, Str);
// Draw text rectangle on mask bitmap
CursorMask.Canvas.Brush.Color := clBlack;
CursorMask.Canvas.FillRect(Rect(TextX, TextY, TextX + StrW, TextY + StrH));
end;
// Draw cross on color bitmap
CursorColor.Canvas.Pen.Color := WinRGB(vBackColor) xor $FFFFFF;
CursorColor.Canvas.MoveTo(CursX + 0, CursY - 8);
CursorColor.Canvas.LineTo(CursX + 0, CursY + 8);
CursorColor.Canvas.MoveTo(CursX - 8, CursY + 0);
CursorColor.Canvas.LineTo(CursX + 8, CursY + 0);
// Draw cross on mask bitmap
CursorMask.Canvas.Pen.Color := clBlack;
CursorMask.Canvas.MoveTo(CursX + 0, CursY - 8);
CursorMask.Canvas.LineTo(CursX + 0, CursY + 8);
CursorMask.Canvas.MoveTo(CursX - 8, CursY + 0);
CursorMask.Canvas.LineTo(CursX + 8, CursY + 0);
// Set up cursor
CursorInfo.fIcon := False;
CursorInfo.xHotSpot := CursX;
CursorInfo.yHotSpot := CursY;
CursorInfo.hbmMask := CursorMask.Handle;
CursorInfo.hbmColor := CursorColor.Handle;
Screen.Cursors[DebugCursor] := CreateIconIndirect(CursorInfo);
Cursor := DebugCursor;
Perform(CM_CURSORCHANGED, 0, 0);
end;
procedure TDebugDisplayForm.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: boolean);
begin
if WheelDelta > 0 then vMouseWheel := 1 else vMouseWheel := -1;
MouseWheelTimer.Enabled := False; // reset timer to cancel vMouseWheel in case it's not used in 100ms
MouseWheelTimer.Interval := 100;
MouseWheelTimer.Enabled := True;
end;
procedure TDebugDisplayForm.FormMouseWheelTimerTick(Sender: TObject);
begin
MouseWheelTimer.Enabled := False; // 100ms reached, disable timer and cancel vMouseWheel
vMouseWheel := 0;
end;
procedure TDebugDisplayForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
vKeyPress := Byte(Key); // capture keys from OnKeyPress
KeyTimer.Enabled := False; // reset timer to cancel vKeyPress in case it's not used in 100ms
KeyTimer.Interval := 100;
KeyTimer.Enabled := True;
end;
procedure TDebugDisplayForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
k: Char;
begin
case Key of // capture keys missed by OnKeyPress
kLeft: k := Chr(1);
kRight: k := Chr(2);
kUp: k := Chr(3);
kDown: k := Chr(4);
kHome: k := Chr(5);
kEnd: k := Chr(6);
kDelete: k := Chr(7);
kInsert: k := Chr(10);
kPageUp: k := Chr(11);
kPageDown: k := Chr(12);
else Exit;
end;
FormKeyPress(Self, k); Exit;
end;
procedure TDebugDisplayForm.FormKeyTimerTick(Sender: TObject);
begin
KeyTimer.Enabled := False; // 100ms reached, disable timer and cancel vKeyPress
vKeyPress := 0;
end;
procedure TDebugDisplayForm.FormPaint(Sender: TObject);
begin
BitmapToCanvas(1);
end;
procedure TDebugDisplayForm.FormMove(var Msg: TWMMove);
begin
inherited;
Caption := CaptionStr + ' (' + IntToStr(Left) + ', ' + IntToStr(Top) + ')';
CaptionPos := True;
end;
procedure TDebugDisplayForm.FormDestroy(Sender: TObject);
begin
Bitmap[0].Free;
Bitmap[1].Free;
CursorColor.Free;
CursorMask.Free;
ReleaseDC(GetDesktopWindow, DesktopDC);
DesktopBitmap.Free;
end;
//////////////////////
// Update Display //
//////////////////////
procedure TDebugDisplayForm.UpdateDisplay(Index: integer);
begin
ptr := Index;
case DisplayType of
dis_logic : LOGIC_Update;
dis_scope : SCOPE_Update;
dis_scope_xy : SCOPE_XY_Update;
dis_fft : FFT_Update;
dis_spectro : SPECTRO_Update;
dis_plot : PLOT_Update;
dis_term : TERM_Update;
dis_bitmap : BITMAP_Update;
dis_midi : MIDI_Update;
end;
// Restore caption if showing window position
if CaptionPos then
begin
Caption := CaptionStr;
CaptionPos := False;
end;
end;
/////////////
// LOGIC //
/////////////
procedure TDebugDisplayForm.LOGIC_Configure;
var
i, v: integer;
s: string;
begin
// Set unique defaults
vSamples := 32;
vSpacing := 8;
vRate := 1;
vLogicIndex := 0;
vTextSize := FontSize;
// Process any parameters
while not NextEnd do
begin
if NextNum then Break; // number not allowed
if NextKey then
case val of
key_title:
KeyTitle;
key_pos:
KeyPos;
key_samples:
KeyValWithin(vSamples, 4, LogicSets - 1);
key_spacing:
KeyValWithin(vSpacing, 2, 32);
key_rate:
KeyValWithin(vRate, 1, LogicSets);
key_linesize:
KeyValWithin(vLineSize, 1, 7);
key_textsize:
KeyTextSize;
key_color:
if KeyColor(vBackColor)
then KeyColor(vGridColor);
key_hidexy:
vHideXY := True;
key_longs_1bit..key_bytes_4bit:
KeyPack;
end
else
if NextStr then
begin
// Enter a label name
s := PChar(val);
if vIndex <> Channels then Inc(vIndex);
SetLogicLabelColor(s, -1, vIndex - 1);
if not KeyValWithin(v, 1, LogicChannels) then Continue;
if v > 1 then
begin
Dec(vLogicIndex);
for i := 0 to v - 1 do SetLogicLabelColor(s, i, vIndex - 1);
end;
KeyColor(vColor[vIndex - 1]);
end;
end;
// If no labels specified, do 32 channels
if vLogicIndex = 0 then
begin
for i := 0 to LogicChannels - 1 do
begin
vLogicLabel[i] := IntToStr(i);
vLogicColor[i] := 0;
end;
vLogicIndex := LogicChannels;
end
else MaxLimit(vLogicIndex, LogicChannels);
// Reset trigger data
vTriggerMask := 0;
vTriggerMatch := 1;
vTriggerOffset := vSamples div 2;
vHoldOff := vSamples;
// Set channel metrics
v := 0;
for i := 0 to vLogicIndex - 1 do MinLimit(v, Length(vLogicLabel[i]) + 2);
// Set form metrics
SetTextMetrics;
vWidth := vSamples * vSpacing;
vHeight := vLogicIndex * ChrHeight;
SetSize(v * ChrWidth, ChrHeight, ChrHeight, ChrHeight);
end;
procedure TDebugDisplayForm.LOGIC_Update;
var
i, t, v: integer;
begin
while not NextEnd do
begin
if NextStr then Break; // string not allowed
if NextKey then
case val of
key_trigger: