-
Notifications
You must be signed in to change notification settings - Fork 0
/
uWatchForm.pas
538 lines (497 loc) · 18.1 KB
/
uWatchForm.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
unit uWatchForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, Grids, uResourceStrings, uView, uProcessor,
StdCtrls, Menus, uMisc, Registry, ImgList;
type
TRAMRefreshRequestEvent = procedure(Listener: IRAM) of object;
TRAMUpdateRequestEvent = procedure(Address: Word; Value: Byte) of object;
TIOPortsRefreshRequestEvent = procedure(Listener: IIOPorts) of object;
TIOPortsUpdateRequestEvent = procedure(PortNo: Byte; Value: Byte) of object;
TWatchForm = class(TForm, ILanguage, IRadixView, IRAM, IIOPorts, IRegistry, IProcessor)
sgWatch: TStringGrid;
PopupMenu: TPopupMenu;
miClose: TMenuItem;
N1: TMenuItem;
miStayOnTop: TMenuItem;
N2: TMenuItem;
miAddWatchRAM: TMenuItem;
miDelWatch: TMenuItem;
miDelAll: TMenuItem;
miAddWatchIPORT: TMenuItem;
miAddWatchOPort: TMenuItem;
iRAM: TImage;
iIPort: TImage;
iOPort: TImage;
ImageList: TImageList;
procedure FormCreate(Sender: TObject);
procedure sgWatchDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure miCloseClick(Sender: TObject);
procedure miStayOnTopClick(Sender: TObject);
procedure sgWatchKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sgWatchDblClick(Sender: TObject);
procedure sgWatchSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormDestroy(Sender: TObject);
procedure miAddWatchRAMClick(Sender: TObject);
procedure miDelWatchClick(Sender: TObject);
procedure miDelAllClick(Sender: TObject);
procedure miAddWatchIPORTClick(Sender: TObject);
procedure miAddWatchOPortClick(Sender: TObject);
procedure FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
private
_Block: Boolean;
_Width: Integer;
_WatchList: TWatchList;
_Radix: TRadix;
_View: TView;
_ARow: Integer;
_ACol: Integer;
_OnRAMRefreshRequest: TRAMRefreshRequestEvent;
_OnRAMUpdateRequest: TRAMUpdateRequestEvent;
_OnIPortsRefreshRequest: TIOPortsRefreshRequestEvent;
_OnIPortsUpdateRequest: TIOPortsUpdateRequestEvent;
_OnOPortsRefreshRequest: TIOPortsRefreshRequestEvent;
procedure RefreshObject(Sender: TObject);
procedure Reset(Sender: TObject);
procedure RAMUpdate(Sender: TObject; Address: Word; Value: Byte);
procedure PortUpdate(Sender: TObject; Index: Byte; Value: Byte);
procedure PortAction(Sender: TObject; Active: Boolean);
procedure BeforeCycle(Sender: TObject);
procedure AfterCycle(Sender: TObject);
procedure StateChange(Sender: TObject; Halt: Boolean);
procedure LoadData(RegistryList: TRegistryList);
procedure SaveData(RegistryList: TRegistryList);
public
procedure LoadLanguage;
procedure RadixChange(Radix: TRadix; View: TView);
property OnRAMRefreshRequest: TRAMRefreshRequestEvent read _OnRAMRefreshRequest write _OnRAMRefreshRequest;
property OnRAMUpdateRequest: TRAMUpdateRequestEvent read _OnRAMUpdateRequest write _OnRAMUpdateRequest;
property OnIPortsRefreshRequest: TIOPortsRefreshRequestEvent read _OnIPortsRefreshRequest write _OnIPortsRefreshRequest;
property OnIPortsUpdateRequest: TIOPortsUpdateRequestEvent read _OnIPortsUpdateRequest write _OnIPortsUpdateRequest;
property OnOPortsRefreshRequest: TIOPortsRefreshRequestEvent read _OnOPortsRefreshRequest write _OnOPortsRefreshRequest;
end;
var
WatchForm: TWatchForm;
implementation
uses uEditForm;
{$R *.dfm}
procedure TWatchForm.FormCreate(Sender: TObject);
begin
_Block:= true;
_WatchList:= TWatchList.Create;
_Radix:= rOctal;
_View:= vShort;
sgWatch.RowCount:= _WatchList.Count+1;
sgWatch.ColCount:= 4;
sgWatch.ColWidths[0]:= 100;
sgWatch.ColWidths[1]:= 100;
sgWatch.ColWidths[2]:= 24;
sgWatch.ColWidths[3]:= 0;
sgWatch.Cells[3,0]:= '';
sgWatch.Left:= 0;
sgWatch.Top:= 0;
ClientWidth:= 244;
ClientHeight:= sgWatch.RowHeights[0] * 10;
_Width:= Width;
sgWatch.Canvas.CopyMode:= cmMergeCopy;
_ARow:= -1;
_ACol:= -1;
LoadLanguage;
_Block:= false;
end;
procedure TWatchForm.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
if not _Block then
NewWidth:= _Width;
end;
procedure TWatchForm.FormDestroy(Sender: TObject);
begin
_WatchList.Free;
end;
procedure TWatchForm.sgWatchDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Item: TWatchItem;
begin
if (ARow = 0) or (ACol = 0) then
sgWatch.Canvas.Brush.Color:= sgWatch.FixedColor
else
sgWatch.Canvas.Brush.Color:= sgWatch.Color;
sgWatch.Canvas.FillRect(Rect);
if (ACol = 1) and (sgWatch.Cells[3,ARow] <> '') then
sgWatch.Canvas.Font.Color:= clRed
else
sgWatch.Canvas.Font.Color:= clWindowText;
if ACol < 2 then
begin
Rect.Top:= Rect.Top + ((sgWatch.RowHeights[ARow] -
sgWatch.Canvas.TextHeight(sgWatch.Cells[ACol,ARow]))) div 2;
if ARow = 0 then
Rect.Left:= Rect.Left + (sgWatch.ColWidths[ACol] -
sgWatch.Canvas.TextWidth(sgWatch.Cells[ACol,ARow])) div 2
else
Rect.Left:= Rect.Right - 4 - sgWatch.Canvas.TextWidth(sgWatch.Cells[ACol,ARow]);
sgWatch.Canvas.TextOut(Rect.Left,Rect.Top,sgWatch.Cells[ACol,ARow]);
end
else
if (ARow > 0) and (ACol = 2) then
begin
Item:= _WatchList.Item[ARow-1];
if Assigned(Item) then
case Item.WatchType of
wtRAM : sgWatch.Canvas.CopyRect(Rect,iRAM.Canvas,Bounds(0,0,24,24));
wtIPort : sgWatch.Canvas.CopyRect(Rect,iIPort.Canvas,Bounds(0,0,24,24));
wtOPort : sgWatch.Canvas.CopyRect(Rect,iOPort.Canvas,Bounds(0,0,24,24));
end;
end;
end;
procedure TWatchForm.miCloseClick(Sender: TObject);
begin
Close;
end;
procedure TWatchForm.miStayOnTopClick(Sender: TObject);
begin
if miStayOnTop.Checked then
FormStyle:= fsNormal
else
FormStyle:= fsStayOnTop;
miStayOnTop.Checked:= not miStayOnTop.Checked;
end;
procedure TWatchForm.miAddWatchRAMClick(Sender: TObject);
var
P: TPoint;
result: Integer;
begin
if Assigned(OnRAMRefreshRequest) then
begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= 0;
if _Radix = rDecimalNeg then result:= EditForm.ShowModal(rDecimal,_View,14,P)
else result:= EditForm.ShowModal(_Radix,_View,14,P);
if (result = mrOk) then
begin
if _WatchList.AddressExists(EditForm.Value,wtRAM) then
MessageDlg(getString(rsExistingAddress),mtInformation,[mbOk],0)
else
begin
_WatchList.Add(EditForm.Value,wtRAM);
sgWatch.RowCount:= _WatchList.Count+1;
sgWatch.Cells[3,sgWatch.RowCount-1];
sgWatch.FixedRows:= 1;
OnRAMRefreshRequest(Self);
end;
end;
end;
end;
procedure TWatchForm.miAddWatchIPORTClick(Sender: TObject);
var
P: TPoint;
result: Integer;
begin
if Assigned(OnIPortsRefreshRequest) then
begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= Ti8008IPorts.FirstPortNo;
if _Radix = rDecimalNeg then result:= EditForm.ShowModal(rDecimal,vLong,3,P)
else result:= EditForm.ShowModal(_Radix,vLong,3,P);
if (result = mrOk) then
begin
if (EditForm.Value >= Ti8008IPorts.FirstPortNo) and
(EditForm.Value < Ti8008IPorts.FirstPortNo+Ti8008IPorts.Count) then
begin
if _WatchList.AddressExists(EditForm.Value,wtIPort) then
MessageDlg(getString(rsExistingAddress),mtInformation,[mbOk],0)
else begin
_WatchList.Add(EditForm.Value,wtIPort);
sgWatch.RowCount:= _WatchList.Count+1;
sgWatch.Cells[3,sgWatch.RowCount-1];
sgWatch.FixedRows:= 1;
OnIPortsRefreshRequest(Self);
end;
end
else
MessageDlg(getString(rsInvalidPortAddress),mtError,[mbOk],0)
end;
end;
end;
procedure TWatchForm.miAddWatchOPortClick(Sender: TObject);
var
P: TPoint;
result: Integer;
begin
if Assigned(OnIPortsRefreshRequest) then
begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= Ti8008OPorts.FirstPortNo;
if _Radix = rDecimalNeg then result:= EditForm.ShowModal(rDecimal,vLong,5,P)
else result:= EditForm.ShowModal(_Radix,vLong,5,P);
if (result = mrOk) then
begin
if (EditForm.Value >= Ti8008OPorts.FirstPortNo) and
(EditForm.Value < Ti8008OPorts.FirstPortNo+Ti8008OPorts.Count) then
begin
if _WatchList.AddressExists(EditForm.Value,wtOPort) then
MessageDlg(getString(rsExistingAddress),mtInformation,[mbOk],0)
else
begin
_WatchList.Add(EditForm.Value,wtOPort);
sgWatch.RowCount:= _WatchList.Count+1;
sgWatch.Cells[3,sgWatch.RowCount-1];
sgWatch.FixedRows:= 1;
OnIPortsRefreshRequest(Self);
end;
end
else
MessageDlg(getString(rsInvalidPortAddress),mtError,[mbOk],0)
end;
end;
end;
procedure TWatchForm.miDelWatchClick(Sender: TObject);
begin
if Assigned(OnRAMRefreshRequest) then
begin
_WatchList.Delete(_ARow-1);
sgWatch.RowCount:= _WatchList.Count+1;
OnRAMRefreshRequest(Self);
OnIPortsRefreshRequest(Self);
OnOPortsRefreshRequest(Self);
end;
end;
procedure TWatchForm.miDelAllClick(Sender: TObject);
begin
if Assigned(OnRAMRefreshRequest) and
Assigned(OnIPortsRefreshRequest) and
Assigned(OnOPortsRefreshRequest) then
begin
_WatchList.Clear;
sgWatch.RowCount:= _WatchList.Count+1;
OnRAMRefreshRequest(Self);
OnIPortsRefreshRequest(Self);
OnOPortsRefreshRequest(Self);
end;
end;
procedure TWatchForm.sgWatchSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
CanSelect:= ACol < 3;
if CanSelect then begin
_ARow:= ARow;
_ACol:= ACol;
end;
end;
procedure TWatchForm.sgWatchDblClick(Sender: TObject);
var
C: Boolean;
P: TPoint;
Item: TWatchItem;
result: Integer;
begin
if (_ARow > 0) and (_ACol = 1) then begin
Item:= _WatchList.Item[_ARow-1];
if Assigned(Item) and not (Item.WatchType = wtOPort) then begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
if Item.WatchType = wtRAM then begin
EditForm.Value:= RadixToWord(sgWatch.Cells[_ACol,_ARow],_Radix,vLong,C);
if (EditForm.ShowModal(_Radix,vLong,8,P) = mrOk) and Assigned(OnRAMUpdateRequest) then
OnRAMUpdateRequest(Item.Address,EditForm.Value);
end else if Item.WatchType = wtIPort then begin
if _Radix = rDecimalNeg then begin
EditForm.Value:= RadixToWord(sgWatch.Cells[_ACol,_ARow],rDecimal,vLong,C);
result:= EditForm.ShowModal(rDecimal,vLong,8,P)
end else begin
EditForm.Value:= RadixToWord(sgWatch.Cells[_ACol,_ARow],_Radix,vLong,C);
result:= EditForm.ShowModal(_Radix,vLong,8,P);
end;
if (result = mrOk) and Assigned(OnIPortsUpdateRequest) then
OnIPortsUpdateRequest(Item.Address,EditForm.Value);
end;
end;
end;
end;
procedure TWatchForm.sgWatchKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then sgWatchDblClick(Sender);
if Key = VK_DELETE then miDelWatchClick(Sender);
end;
procedure TWatchForm.RefreshObject(Sender: TObject);
var
i: Integer;
Bits: Byte;
Item: TWatchItem;
Address: Word;
begin
if Sender is Ti8008RAM then begin
for i:= 0 to _WatchList.Count-1 do begin
Item:= _WatchList.Item[i];
if Assigned(Item) and (Item.WatchType = wtRAM) then begin
Address:= Item.Address;
sgWatch.Cells[0,i+1]:= WordToRadix(Address,_Radix,_View,14);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as Ti8008RAM).RAM[Address],
_Radix,vLong,8);
end;
end;
end else if (Sender is TIOPorts) then begin
for i:= 0 to _WatchList.Count-1 do begin
Item:= _WatchList.Item[i];
if Assigned(Item) and (Item.WatchType in [wtIPort, wtOPort]) then begin
Address:= Item.Address;
case (Sender as TIOPorts).PortType of
ptIN : Bits:= 3;
ptOUT : Bits:= 5;
else Bits:= 16;
end;
if _Radix = rDecimalNeg then begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,rDecimal,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
rDecimal,vLong,8);
end else begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,_Radix,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
_Radix,vLong,8);
end;
end;
end;
end;
sgWatch.Invalidate;
end;
procedure TWatchForm.Reset(Sender: TObject);
var
i: Integer;
Bits: Byte;
Item: TWatchItem;
Address: Word;
begin
if Sender is Ti8008RAM then begin
for i:= 0 to _WatchList.Count-1 do begin
Item:= _WatchList.Item[i];
if Assigned(Item) and (Item.WatchType = wtRAM) then begin
Address:= Item.Address;
sgWatch.Cells[3,i+1]:= '';
sgWatch.Cells[0,i+1]:= WordToRadix(Address,_Radix,_View,14);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as Ti8008RAM).RAM[Address],
_Radix,vLong,8);
end;
end;
end else if (Sender is TIOPorts) then begin
for i:= 0 to _WatchList.Count-1 do begin
Item:= _WatchList.Item[i];
if Assigned(Item) and (Item.WatchType = wtIPort) and ((Sender as TIOPorts).PortType = ptIN) then begin
Address:= Item.Address;
Bits:= 3;
sgWatch.Cells[3,i+1]:= '';
if _Radix = rDecimalNeg then begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,rDecimal,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
rDecimal,vLong,8);
end else begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,_Radix,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
_Radix,vLong,8);
end;
end else if Assigned(Item) and (Item.WatchType = wtOPort) and ((Sender as TIOPorts).PortType = ptOUT) then begin
Address:= Item.Address;
Bits:= 5;
sgWatch.Cells[3,i+1]:= '';
if _Radix = rDecimalNeg then begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,rDecimal,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
rDecimal,vLong,8);
end else begin
sgWatch.Cells[0,i+1]:= WordToRadix(Address,_Radix,vLong,Bits);
sgWatch.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[Address],
_Radix,vLong,8);
end;
end
end;
end;
end;
procedure TWatchForm.RAMUpdate(Sender: TObject; Address: Word; Value: Byte);
var
Index: Integer;
sValue: String;
begin
Index:= _WatchList.FindAddress(Address,wtRAM);
if Index >= 0 then begin
sValue:= WordToRadix(Value,_Radix,vLong,8);
if sValue <> sgWatch.Cells[1,Index+1] then sgWatch.Cells[3,Index+1]:= '*';
sgWatch.Cells[1,Index+1]:= sValue;
end;
end;
procedure TWatchForm.PortUpdate(Sender: TObject; Index: Byte; Value: Byte);
var
lIndex: Integer;
sValue: String;
begin
if (Sender is TIOPorts) then begin
case (Sender as TIOPorts).PortType of
ptIN : lIndex:= _WatchList.FindAddress(Index,wtIPort);
ptOUT : lIndex:= _WatchList.FindAddress(Index,wtOPort);
else lIndex:= -1;
end;
if lIndex >= 0 then begin
if _Radix = rDecimalNeg then sValue:= WordToRadix(Value,rDecimal,vLong,8)
else sValue:= WordToRadix(Value,_Radix,vLong,8);
if sValue <> sgWatch.Cells[1,lIndex+1] then sgWatch.Cells[3,lIndex+1]:= '*';
sgWatch.Cells[1,lIndex+1]:= sValue;
end;
end
end;
procedure TWatchForm.PortAction(Sender: TObject; Active: Boolean);
begin
end;
procedure TWatchForm.BeforeCycle(Sender: TObject);
var
i: Integer;
begin
for i:= 1 to sgWatch.RowCount-1 do
begin
sgWatch.Cells[3,i]:= '';
sgWatch.Cells[1,i]:= sgWatch.Cells[1,i];
end;
end;
procedure TWatchForm.AfterCycle(Sender: TObject);
begin
end;
procedure TWatchForm.StateChange(Sender: TObject; Halt: Boolean);
begin
end;
procedure TWatchForm.LoadData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,false) then
RegistryList.LoadFormSettings(Self,true);
end;
procedure TWatchForm.SaveData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,true) then
RegistryList.SaveFormSettings(Self,true);
end;
procedure TWatchForm.LoadLanguage;
begin
Caption:= 'i8008 '+getString(rsWatch);
sgWatch.Cells[0,0]:= getString(rsAddress);
sgWatch.Cells[1,0]:= getString(rsValue);
miAddWatchRAM.Caption:= getString(rsAddWatchRAM);
miAddWatchIPort.Caption:= getString(rsAddWatchIPort);
miAddWatchOPort.Caption:= getString(rsAddWatchOPort);
miDelWatch.Caption:= getString(rsDelWatch);
miDelAll.Caption:= getString(rsDelAll);
miClose.Caption:= getString(rsClose);
miStayOnTop.Caption:= getString(rsStayOnTop);
end;
procedure TWatchForm.RadixChange(Radix: TRadix; View: TView);
begin
_Radix:= Radix;
_View:= View;
end;
end.