-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunitdebugcpustate.pas
527 lines (431 loc) · 13.5 KB
/
unitdebugcpustate.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
unit UnitDebugCpuState;
// Copyright 2022-2025 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
{$i zxinc.inc}
interface
uses
Classes, SysUtils, BGRABitmap, BGRABitmapTypes, BGRAPolygon,
Z80Processor, UnitFrameWordDisplay, CommonFunctionsLCL, Controls, Graphics,
StdCtrls;
type
TFlagsCtrl = class(TCustomControl)
public
const
DefColour = $fefdf8;
strict private
FFlagCtrls: array of TCustomControl;
public
constructor Create(AOwner: TComponent); override;
constructor Create(AOwner: TComponent; FlagCtrls: array of AnsiString; const LabelsLeft: Boolean; AVertical: Boolean);
procedure SetValues(AValue: Byte);
end;
TDebugCpuState = class(TCustomControl)
private
FrAF: TFrameWordDisplay;
FrBC: TFrameWordDisplay;
FrDE: TFrameWordDisplay;
FrHL: TFrameWordDisplay;
FrAF1: TFrameWordDisplay;
FrBC1: TFrameWordDisplay;
FrDE1: TFrameWordDisplay;
FrHL1: TFrameWordDisplay;
FrIx: TFrameWordDisplay;
FrIy: TFrameWordDisplay;
FrI: TFrameWordDisplay;
FrR: TFrameWordDisplay;
FrPC: TFrameWordDisplay;
FrSP: TFrameWordDisplay;
FrWZ: TFrameWordDisplay;
FlCtrlsFlags: TFlagsCtrl;
FlCtrlsIff: TFlagsCtrl;
FlCtrlsInterruptPin: TFlagsCtrl;
FlCtrlsHalt: TFlagsCtrl;
InterruptModeCtrl: TCustomControl;
LabInterruptMode: TLabel;
LabInterruptModeValue: TLabel;
RegistersContainer: TCustomControl;
FlagsContainer: TCustomControl;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetAll(const AProc: TProcessor);
end;
implementation
type
TFlagCtrl = class(TCustomControl)
strict private
type
TPaintCtrl = class(TGraphicControl)
private
class var
BmpFalse: TBGRABitmap;
BmpTrue: TBGRABitmap;
private
class procedure Init;
class procedure Final;
public
FValue: Boolean;
procedure Paint; override;
end;
private
class procedure Init;
class procedure Final;
strict private
FLabelLeft: Boolean;
FPaintCtrl: TPaintCtrl;
Lab: TLabel;
public
constructor Create(AOwner: TComponent); override;
procedure SetValue(const AValue: Boolean);
procedure SetLabelLeft(const AValue: Boolean);
procedure SetLabel(const ACaption: AnsiString);
end;
{ TFlagCtrl.TPaintCtrl }
class procedure TFlagCtrl.TPaintCtrl.Init;
var
BPix, BPix1, BPix2: TBGRAPixel;
begin
BmpTrue := TBGRABitmap.Create(12, 12, BGRAPixelTransparent);
BmpFalse := TBGRABitmap.Create(12, 12, BGRAPixelTransparent);
BPix.FromColor($a0c0b0);
BPix1.FromColor(clNavy);
BPix2.FromColor($f2edf0);
BmpFalse.FillEllipseLinearColorAntialias(5, 5, 5, 5, BPix2, BGRAWhite);
BmpFalse.Ellipse(5, 5, 4.3, 4.3, BPix, 1.0, TDrawMode.dmSet);
BmpTrue.FillEllipseLinearColorAntialias(5, 5, 5, 5, BGRAWhite, BPix1);
BmpTrue.Ellipse(5, 5, 4.3, 4.3, BPix, 1.0, TDrawMode.dmSet);
end;
class procedure TFlagCtrl.TPaintCtrl.Final;
begin
BmpFalse.Free;
BmpTrue.Free;
end;
procedure TFlagCtrl.TPaintCtrl.Paint;
var
B: TBGRABitmap;
begin
inherited Paint;
if FValue then
B := BmpTrue
else
B := BmpFalse;
B.Draw(Canvas, 0, 0, False);
end;
{ TFlagsCtrl }
constructor TFlagsCtrl.Create(AOwner: TComponent);
begin
Create(AOwner, [''], True, False);
end;
constructor TFlagsCtrl.Create(AOwner: TComponent;
FlagCtrls: array of AnsiString; const LabelsLeft: Boolean; AVertical: Boolean
);
var
Fl, FlPrev: TFlagCtrl;
N, FlagsCount: Integer;
begin
inherited Create(AOwner);
Color := DefColour;
BorderStyle := bsSingle;
FlagsCount := Length(FlagCtrls);
if FlagsCount > 8 then
FlagsCount := 8;
SetLength(FFlagCtrls, FlagsCount);
if LabelsLeft then
N := 3
else
N := 1;
FlPrev := nil;
while FlagsCount > 0 do begin
Dec(FlagsCount);
Fl := TFlagCtrl.Create(Self);
FFlagCtrls[FlagsCount] := Fl;
Fl.SetValue(Odd(FlagsCount));
Fl.SetLabel(FlagCtrls[FlagsCount]);
Fl.SetLabelLeft(LabelsLeft);
Fl.Anchors := [];
if FlPrev = nil then begin
Fl.AnchorParallel(akTop, 1, Self);
Fl.AnchorParallel(akRight, 1, Self);
end else if not AVertical then begin
Fl.AnchorParallel(akTop, 1, Self);
Fl.AnchorToNeighbour(akRight, N, FlPrev);
end else begin
Fl.AnchorToNeighbour(akTop, 1, FlPrev);
Fl.AnchorParallel(akRight, 1, Self);
end;
FlPrev := Fl;
Fl.Parent := Self;
end;
AutoSize := True;
end;
procedure TFlagsCtrl.SetValues(AValue: Byte);
var
I: Integer;
begin
for I := Low(FFlagCtrls) to High(FFlagCtrls) do begin
TFlagCtrl(FFlagCtrls[High(FFlagCtrls) - I]).SetValue((AValue shr I) and 1 <> 0);
end;
end;
{ TFlagCtrl }
class procedure TFlagCtrl.Init;
begin
TPaintCtrl.Init;
end;
class procedure TFlagCtrl.Final;
begin
TPaintCtrl.Final;
end;
constructor TFlagCtrl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPaintCtrl := TPaintCtrl.Create(Self);
FPaintCtrl.FValue := False;
FPaintCtrl.ParentColor := True;
//FPaintCtrl.Color := clWhite;
Lab := TLabel.Create(Self);
Lab.ShowAccelChar := False;
Lab.Caption := '';
FPaintCtrl.AutoSize := False;
FPaintCtrl.Width := 12;
FPaintCtrl.Height := FPaintCtrl.Width;
FPaintCtrl.Parent := Self;
Lab.Parent := Self;
FLabelLeft := True;
SetLabelLeft(False);
Constraints.MinWidth := 26;
AutoSize := True;
TabStop := False;
end;
procedure TFlagCtrl.SetValue(const AValue: Boolean);
begin
if AValue xor FPaintCtrl.FValue then begin
FPaintCtrl.FValue := AValue;
FPaintCtrl.Invalidate;
end;
end;
procedure TFlagCtrl.SetLabelLeft(const AValue: Boolean);
begin
if FLabelLeft xor AValue then begin
FLabelLeft := AValue;
Lab.Anchors := [];
FPaintCtrl.Anchors := [];
if AValue then begin
FPaintCtrl.AnchorVerticalCenterTo(Self);
FPaintCtrl.AnchorParallel(akRight, 0, Self);
Lab.AnchorVerticalCenterTo(Self);
Lab.AnchorToNeighbour(akRight, 2, FPaintCtrl);
end else begin
FPaintCtrl.AnchorHorizontalCenterTo(Self);
FPaintCtrl.AnchorParallel(akTop, 0, Self);
Lab.AnchorHorizontalCenterTo(Self);
Lab.AnchorToNeighbour(akTop, 0, FPaintCtrl);
end;
FPaintCtrl.BorderSpacing.Around := 1;
Lab.BorderSpacing.Around := 1;
end;
end;
procedure TFlagCtrl.SetLabel(const ACaption: AnsiString);
begin
Lab.Caption := ACaption;
Lab.Visible := ACaption <> '';
end;
{ TDebugCpuState }
constructor TDebugCpuState.Create(AOwner: TComponent);
const
SpcRegs = 3;
begin
inherited Create(AOwner);
FrAF := TFrameWordDisplay.MakeNew('AF:');
FrBC := TFrameWordDisplay.MakeNew('BC:');
FrDE := TFrameWordDisplay.MakeNew('DE:');
FrHL := TFrameWordDisplay.MakeNew('HL:');
FrAF1 := TFrameWordDisplay.MakeNew('AF'':');
FrBC1 := TFrameWordDisplay.MakeNew('BC'':');
FrDE1 := TFrameWordDisplay.MakeNew('DE'':');
FrHL1 := TFrameWordDisplay.MakeNew('HL'':');
FrIx := TFrameWordDisplay.MakeNew('IX:');
FrIy := TFrameWordDisplay.MakeNew('IY:');
FrWZ := TFrameWordDisplay.MakeNew('WZ:');
FrI := TFrameWordDisplay.MakeNew('I:');
FrI.ByteMode := True;
FrR := TFrameWordDisplay.MakeNew('R:');
FrR.ByteMode := True;
FrSP := TFrameWordDisplay.MakeNew('SP:');
FrPC := TFrameWordDisplay.MakeNew('PC:');
RegistersContainer := TCustomControl.Create(nil);
FrAF.AnchorParallel(akLeft, 0, RegistersContainer);
FrAF.AnchorParallel(akTop, 0, RegistersContainer);
FrBC.AnchorParallel(akLeft, 0, FrAF);
FrDE.AnchorParallel(akLeft, 0, FrAF);
FrHL.AnchorParallel(akLeft, 0, FrAF);
FrIx.AnchorParallel(akLeft, 0, FrAF);
FrPC.AnchorParallel(akLeft, 0, FrAF);
FrBC.AnchorToNeighbour(akTop, SpcRegs, FrAF);
FrDE.AnchorToNeighbour(akTop, SpcRegs, FrBC);
FrHL.AnchorToNeighbour(akTop, SpcRegs, FrDE);
FrIx.AnchorToNeighbour(akTop, SpcRegs, FrHL);
FrPC.AnchorToNeighbour(akTop, SpcRegs, FrIx);
FrAF1.AnchorToNeighbour(akLeft, SpcRegs, FrAF);
FrBC1.AnchorParallel(akLeft, 0, FrAF1);
FrDE1.AnchorParallel(akLeft, 0, FrAF1);
FrHL1.AnchorParallel(akLeft, 0, FrAF1);
FrIy.AnchorParallel(akLeft, 0, FrAF1);
FrSP.AnchorParallel(akLeft, 0, FrAF1);
FrAF1.AnchorParallel(akTop, 0, FrAF);
FrBC1.AnchorToNeighbour(akTop, SpcRegs, FrAF1);
FrDE1.AnchorToNeighbour(akTop, SpcRegs, FrBC1);
FrHL1.AnchorToNeighbour(akTop, SpcRegs, FrDE1);
FrIy.AnchorToNeighbour(akTop, SpcRegs, FrHL1);
FrSP.AnchorToNeighbour(akTop, SpcRegs, FrIy);
FrI.AnchorParallel(akLeft, 0, FrAF);
FrI.AnchorToNeighbour(akTop, SpcRegs, FrPC);
FrR.AnchorParallel(akLeft, 0, FrI);
FrR.AnchorToNeighbour(akTop, SpcRegs, FrI);
FrWZ.AnchorParallel(akLeft, 0, FrAF);
FrWZ.AnchorToNeighbour(akTop, SpcRegs, FrR);
FrAF.Parent := RegistersContainer;
FrBC.Parent := RegistersContainer;
FrDE.Parent := RegistersContainer;
FrHL.Parent := RegistersContainer;
FrAF1.Parent := RegistersContainer;
FrBC1.Parent := RegistersContainer;
FrDE1.Parent := RegistersContainer;
FrHL1.Parent := RegistersContainer;
FrIx.Parent := RegistersContainer;
FrIy.Parent := RegistersContainer;
FrI.Parent := RegistersContainer;
FrR.Parent := RegistersContainer;
FrPC.Parent := RegistersContainer;
FrSP.Parent := RegistersContainer;
FrWZ.Parent := RegistersContainer;
FlagsContainer := TCustomControl.Create(nil);
FlCtrlsFlags := TFlagsCtrl.Create(nil, ['S', 'Z', '5', 'H', '3', 'PV', 'N', 'C'], False, False);
FlCtrlsIff := TFlagsCtrl.Create(nil, ['Iff1', 'Iff2'], True, False);
FlCtrlsInterruptPin := TFlagsCtrl.Create(nil, ['interrupt pin'], True, False);
FlCtrlsHalt := TFlagsCtrl.Create(nil, ['halt'], True, False);
FlCtrlsInterruptPin.Anchors := [];
FlCtrlsHalt.Anchors := [];
FlCtrlsIff.Anchors := [];
FlCtrlsFlags.Anchors := [];
FlCtrlsFlags.AnchorParallel(akLeft, 0, FlagsContainer);
FlCtrlsFlags.AnchorParallel(akTop, 0, FlagsContainer);
FlCtrlsIff.AnchorParallel(akLeft, 0, FlagsContainer);
FlCtrlsIff.AnchorToNeighbour(akTop, 3, FlCtrlsFlags);
FlCtrlsHalt.AnchorToNeighbour(akLeft, SpcRegs, FlCtrlsIff);
FlCtrlsHalt.AnchorParallel(akTop, 0, FlCtrlsIff);
FlCtrlsInterruptPin.AnchorToNeighbour(akLeft, SpcRegs, FlCtrlsHalt);
FlCtrlsInterruptPin.AnchorParallel(akTop, 0, FlCtrlsIff);
FlCtrlsFlags.Parent := FlagsContainer;
FlCtrlsIff.Parent := FlagsContainer;
FlCtrlsInterruptPin.Parent := FlagsContainer;
FlCtrlsHalt.Parent := FlagsContainer;
InterruptModeCtrl := TCustomControl.Create(nil);
LabInterruptMode := TLabel.Create(nil);
LabInterruptModeValue := TLabel.Create(nil);
InterruptModeCtrl.BorderStyle := bsSingle;
InterruptModeCtrl.AnchorParallel(akLeft, 0, FrAF1);
InterruptModeCtrl.AnchorParallel(akTop, 0, FrI);
InterruptModeCtrl.Hint := 'Interrupt mode (0, 1 or 2)';
InterruptModeCtrl.ShowHint := True;
LabInterruptMode.Caption := 'IM:';
LabInterruptModeValue.Font := TCommonFunctionsLCL.GetMonoFont();
LabInterruptModeValue.Font.Style := LabInterruptModeValue.Font.Style + [fsBold];
LabInterruptModeValue.Caption := ' ';
LabInterruptMode.AnchorParallel(akLeft, 0, InterruptModeCtrl);
LabInterruptMode.AnchorParallel(akBottom, 0, InterruptModeCtrl);
LabInterruptMode.Layout := TTextLayout.tlBottom;
LabInterruptModeValue.Layout := TTextLayout.tlBottom;
LabInterruptModeValue.AnchorToNeighbour(akLeft, 2, LabInterruptMode);
LabInterruptModeValue.AnchorParallel(akBottom, 0, InterruptModeCtrl);
LabInterruptMode.BorderSpacing.Around := 1;
LabInterruptModeValue.BorderSpacing.Around := 1;
LabInterruptMode.Parent := InterruptModeCtrl;
LabInterruptModeValue.Parent := InterruptModeCtrl;
InterruptModeCtrl.Parent := RegistersContainer;
InterruptModeCtrl.AutoSize := True;
InterruptModeCtrl.Color := FlCtrlsHalt.Color;
FlagsContainer.AnchorToNeighbour(akLeft, SpcRegs, InterruptModeCtrl);
FlagsContainer.AnchorParallel(akTop, 0, InterruptModeCtrl);
FlagsContainer.AutoSize := True;
RegistersContainer.AnchorParallel(akTop, SpcRegs, Self);
RegistersContainer.AnchorParallel(akLeft, SpcRegs, Self);
RegistersContainer.AutoSize := True;
FlagsContainer.Parent := RegistersContainer;
RegistersContainer.Parent := Self;
AutoSize := True;
end;
destructor TDebugCpuState.Destroy;
begin
FrAF.Free;
FrBC.Free;
FrDE.Free;
FrHL.Free;
FrAF1.Free;
FrBC1.Free;
FrDE1.Free;
FrHL1.Free;
FrIx.Free;
FrIy.Free;
FrI.Free;
FrR.Free;
FrPC.Free;
FrSP.Free;
FrWZ.Free;
RegistersContainer.Free;
InterruptModeCtrl.Free;
LabInterruptMode.Free;
LabInterruptModeValue.Free;
FlCtrlsHalt.Free;
FlCtrlsInterruptPin.Free;
FlCtrlsFlags.Free;
FlCtrlsIff.Free;
FlagsContainer.Free;
inherited Destroy;
end;
procedure TDebugCpuState.SetAll(const AProc: TProcessor);
var
B: Byte;
begin
if Assigned(AProc) then begin
FrSP.Value := AProc.RegSP;
FrPC.Value := AProc.RegPC;
FrI.Value := AProc.RegI;
FrR.Value := AProc.RegR;
FrWZ.Value := AProc.RegWZ;
FrIx.Value := AProc.Ix;
FrIy.Value := AProc.Iy;
FrAF.Value := AProc.RegAF;
FrBC.Value := AProc.RegBC;
FrDE.Value := AProc.RegDE;
FrHL.Value := AProc.RegHL;
FrAF1.Value := AProc.RegAF1;
FrBC1.Value := AProc.RegBC1;
FrDE1.Value := AProc.RegDE1;
FrHL1.Value := AProc.RegHL1;
FlCtrlsFlags.SetValues(AProc.RegF);
if AProc.Iff1 then
B := 2
else
B := 0;
if AProc.Iff2 then
B := B + 1;
FlCtrlsIff.SetValues(B);
if AProc.Halt then
B := 1
else
B := 0;
FlCtrlsHalt.SetValues(B);
if AProc.IntPin then
B := 1
else
B := 0;
FlCtrlsInterruptPin.SetValues(B);
LabInterruptModeValue.Caption := AProc.InterruptMode.ToString;
end;
end;
initialization
TFlagCtrl.Init;
finalization
TFlagCtrl.Final;
end.