-
Notifications
You must be signed in to change notification settings - Fork 0
/
uIOPortForm.pas
449 lines (408 loc) · 14.6 KB
/
uIOPortForm.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
unit uIOPortForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, Grids, uResourceStrings, uView, uProcessor,
StdCtrls, Menus, uMisc, Registry;
type
TIOPortsRefreshRequestEvent = procedure(Listener: IIOPorts) of object;
TIOPortsUpdateRequestEvent = procedure(PortNo: Byte; Value: Byte) of object;
TIOPortsActiveRequestEvent = procedure(Active: Boolean) of object;
TIOPortsFileRequestEvent = procedure(Filename: TFilename) of object;
TIOPortsFileResetRequestEvent = procedure of object;
TIOPortForm = class(TForm, ILanguage, IRadixView, IIOPorts, IRegistry, IProcessor)
sgIOPort: TStringGrid;
PopupMenu: TPopupMenu;
miClose: TMenuItem;
N1: TMenuItem;
miStayOnTop: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
gbPortFile: TGroupBox;
cbPortActive: TCheckBox;
sbFile: TSpeedButton;
sbClose: TSpeedButton;
iIN: TImage;
iOUT: TImage;
iOUTClose: TImage;
iINClose: TImage;
sbResetFile: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure sgIOPortDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure miCloseClick(Sender: TObject);
procedure miStayOnTopClick(Sender: TObject);
procedure sgIOPortKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure sgIOPortDblClick(Sender: TObject);
procedure sgIOPortSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
procedure cbPortActiveClick(Sender: TObject);
procedure sbFileClick(Sender: TObject);
procedure sbCloseClick(Sender: TObject);
procedure sbResetFileClick(Sender: TObject);
private
_Block: Boolean;
_BlockActive: Boolean;
_Width: Integer;
_PortType: TPortType;
_CanEdit: Boolean;
_Radix: TRadix;
_ARow: Integer;
_ACol: Integer;
_OnIPortsRefreshRequest: TIOPortsRefreshRequestEvent;
_OnIPortsUpdateRequest: TIOPortsUpdateRequestEvent;
_OnOPortsRefreshRequest: TIOPortsRefreshRequestEvent;
_OnPortsActiveRequest: TIOPortsActiveRequestEvent;
_OnPortsFileRequest: TIOPortsFileRequestEvent;
_OnPortFileResetRequest: TIOPortsFileResetRequestEvent;
procedure setPortType(Value: TPortType);
procedure setCanEdit(Value: Boolean);
procedure RefreshObject(Sender: TObject);
procedure Reset(Sender: TObject);
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);
property CanEdit: Boolean read _CanEdit write setCanEdit;
public
procedure LoadLanguage;
procedure RadixChange(Radix: TRadix; View: TView);
property PortType: TPortType read _PortType write setPortType;
property OnIPortsRefreshRequest: TIOPortsRefreshRequestEvent read _OnIPortsRefreshRequest write _OnIPortsRefreshRequest;
property OnIPortsUpdateRequest: TIOPortsUpdateRequestEvent read _OnIPortsUpdateRequest write _OnIPortsUpdateRequest;
property OnOPortsRefreshRequest: TIOPortsRefreshRequestEvent read _OnOPortsRefreshRequest write _OnOPortsRefreshRequest;
property OnPortsActiveRequest: TIOPortsActiveRequestEvent read _OnPortsActiveRequest write _OnPortsActiveRequest;
property OnPortsFileRequest: TIOPortsFileRequestEvent read _OnPortsFileRequest write _OnPortsFileRequest;
property OnPortFileResetRequest: TIOPortsFileResetRequestEvent read _OnPortFileResetRequest write _OnPortFileResetRequest;
end;
var
IPortForm: TIOPortForm;
OPortForm: TIOPortForm;
implementation
uses uEditForm;
{$R *.dfm}
procedure TIOPortForm.FormCreate(Sender: TObject);
begin
_BlockActive:= false;
_Block:= false;
_Radix:= rOctal;
sgIOPort.ColCount:= 3;
sgIOPort.ColWidths[0]:= 70;
sgIOPort.ColWidths[1]:= 70;
sgIOPort.ColWidths[2]:= 0;
sgIOPort.Cells[2,0]:= '';
ClientHeight:= sgIOPort.RowHeights[0] * 9 + gbPortFile.Height;
_ARow:= -1;
_ACol:= -1;
LoadLanguage;
PortType:= ptUnknown;
end;
procedure TIOPortForm.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
if not _Block then
NewWidth:= _Width;
end;
procedure TIOPortForm.sgIOPortDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ARow = 0) or (ACol = 0) then
sgIOPort.Canvas.Brush.Color:= sgIOPort.FixedColor
else
sgIOPort.Canvas.Brush.Color:= sgIOPort.Color;
sgIOPort.Canvas.FillRect(Rect);
if (ACol = 1) and (sgIOPort.Cells[2,ARow] <> '') then
sgIOPort.Canvas.Font.Color:= clRed
else
if (ACol = 1) and (ARow = 0) and not CanEdit then
sgIOPort.Canvas.Font.Color:= clGrayText
else
sgIOPort.Canvas.Font.Color:= clWindowText;
Rect.Top:= Rect.Top + ((sgIOPort.RowHeights[ARow] -
sgIOPort.Canvas.TextHeight(sgIOPort.Cells[ACol,ARow]))) div 2;
if ARow = 0 then
Rect.Left:= Rect.Left + (sgIOPort.ColWidths[ACol] -
sgIOPort.Canvas.TextWidth(sgIOPort.Cells[ACol,ARow])) div 2
else
Rect.Left:= Rect.Right - 4 - sgIOPort.Canvas.TextWidth(sgIOPort.Cells[ACol,ARow]);
sgIOPort.Canvas.TextOut(Rect.Left,Rect.Top,sgIOPort.Cells[ACol,ARow]);
end;
procedure TIOPortForm.miCloseClick(Sender: TObject);
begin
Close;
end;
procedure TIOPortForm.miStayOnTopClick(Sender: TObject);
begin
if miStayOnTop.Checked then
FormStyle:= fsNormal
else
FormStyle:= fsStayOnTop;
miStayOnTop.Checked:= not miStayOnTop.Checked;
end;
procedure TIOPortForm.sgIOPortSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
CanSelect:= ACol < 2;
if CanSelect then
begin
_ARow:= ARow;
_ACol:= ACol;
end;
end;
procedure TIOPortForm.sgIOPortDblClick(Sender: TObject);
var
C: Boolean;
P: TPoint;
begin
if (_ARow > 0) and (_ACol = 1) and (PortType = ptIN) and CanEdit then
begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= RadixToWord(sgIOPort.Cells[_ACol,_ARow],_Radix,vLong,C);
if (EditForm.ShowModal(_Radix,vLong,8,P) = mrOk) and Assigned(OnIPortsUpdateRequest) then
OnIPortsUpdateRequest(_ARow-1+Ti8008IPorts.FirstPortNo,EditForm.Value);
end;
end;
procedure TIOPortForm.sgIOPortKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
sgIOPortDblClick(Sender);
end;
procedure TIOPortForm.cbPortActiveClick(Sender: TObject);
begin
if not _BlockActive and Assigned(OnPortsActiveRequest) then
OnPortsActiveRequest(cbPortActive.Checked);
end;
procedure TIOPortForm.sbResetFileClick(Sender: TObject);
begin
if Assigned(OnPortFileResetRequest) then
OnPortFileResetRequest;
end;
procedure TIOPortForm.sbFileClick(Sender: TObject);
var
Filename: TFilename;
begin
case PortType of
ptIN : if Assigned(OnPortsFileRequest) and OpenDialog.Execute then
begin
Filename:= ChangeFileExt(OpenDialog.FileName,'.pin');
OnPortsFileRequest(Filename);
sbFile.Enabled:= false;
sbResetFile.Enabled:= true;
sbClose.Enabled:= true;
cbPortActive.Enabled:= true;
end;
ptOUT : if Assigned(OnPortsFileRequest) and SaveDialog.Execute then
begin
Filename:= ChangeFileExt(SaveDialog.FileName,'.pout');
OnPortsFileRequest(FileName);
sbFile.Enabled:= false;
sbClose.Enabled:= true;
cbPortActive.Enabled:= true;
end;
end
end;
procedure TIOPortForm.sbCloseClick(Sender: TObject);
begin
if Assigned(OnPortsFileRequest) then
begin
OnPortsFileRequest('');
sbFile.Enabled:= true;
sbResetFile.Enabled:= false;
sbClose.Enabled:= false;
cbPortActive.Enabled:= false;
end;
end;
procedure TIOPortForm.setPortType(Value: TPortType);
begin
_Block:= true;
_PortType:= Value;
case PortType of
ptIN : begin
Caption:= 'i8008 IN - Ports';
sgIOPort.RowCount:= Ti8008IPorts.Count + 1;
sgIOPort.FixedRows:= 1;
ClientWidth:= 160;
_Width:= Width;
iIN.Visible:= false;
iINClose.Visible:= false;
iOUT.Visible:= false;
iOUTClose.Visible:= false;
sbFile.Glyph:= iIN.Picture.Bitmap;
sbClose.Glyph:= iINClose.Picture.Bitmap;
sbFile.Enabled:= true;
sbClose.Enabled:= false;
sbResetFile.Visible:= true;
sbResetFile.Enabled:= false;
cbPortActive.Enabled:= false;
CanEdit:= true;
end;
ptOUT : begin
Caption:= 'i8008 OUT - Ports';
sgIOPort.RowCount:= Ti8008OPorts.Count + 1;
sgIOPort.FixedRows:= 1;
ClientWidth:= 160;
_Width:= Width;
iIN.Visible:= false;
iINClose.Visible:= false;
iOUT.Visible:= false;
iOUTClose.Visible:= false;
sbFile.Glyph:= iOUT.Picture.Bitmap;
sbClose.Glyph:= iOUTClose.Picture.Bitmap;
sbFile.Enabled:= true;
sbClose.Enabled:= false;
sbResetFile.Visible:= false;
cbPortActive.Enabled:= false;
CanEdit:= false;
end;
else begin
Caption:= 'i8008 Ports';
sgIOPort.RowCount:= 1;
ClientWidth:= 160;
_Width:= Width;
iIN.Visible:= false;
iINClose.Visible:= false;
iOUT.Visible:= false;
iOUTClose.Visible:= false;
sbFile.Enabled:= false;
sbClose.Enabled:= false;
CanEdit:= false;
end;
end;
if (PortType = ptIN) and Assigned(OnIPortsRefreshRequest) then
OnIPortsRefreshRequest(Self);
if (PortType = ptOUT) and Assigned(OnOPortsRefreshRequest) then
OnOPortsRefreshRequest(Self);
_Block:= false;
end;
procedure TIOPortForm.setCanEdit(Value: Boolean);
begin
_CanEdit:= (Porttype = ptIn) and Value;
sgIOPort.Invalidate;
end;
procedure TIOPortForm.RefreshObject(Sender: TObject);
var
i, iFirstPortNo: Integer;
Bits: Byte;
begin
if (Sender is TIOPorts) and
((Sender as TIOPorts).PortType = PortType) and not (PortType = ptUnknown) then
begin
case (Sender as TIOPorts).PortType of
ptIN : Bits:= 3;
ptOUT : Bits:= 5;
else Bits:= 16;
end;
iFirstPortNo:= (Sender as TIOPorts).FirstPortNo;
for i:= 0 to (Sender as TIOPorts).Count-1 do
begin
sgIOPort.Cells[0,i+1]:= WordToRadix(i+iFirstPortNo,_Radix,vLong,Bits);
sgIOPort.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[i+iFirstPortNo],
_Radix,vLong,8);
end;
end;
sgIOPort.Invalidate;
end;
procedure TIOPortForm.Reset(Sender: TObject);
var
i, iFirstPortNo: Integer;
Bits: Byte;
begin
if (Sender is TIOPorts) and
((Sender as TIOPorts).PortType = PortType) and not (PortType = ptUnknown) then
begin
case (Sender as TIOPorts).PortType of
ptIN : Bits:= 3;
ptOUT : Bits:= 5;
else Bits:= 16;
end;
iFirstPortNo:= (Sender as TIOPorts).FirstPortNo;
for i:= 0 to (Sender as TIOPorts).Count-1 do
begin
sgIOPort.Cells[2,i+1]:= '';
sgIOPort.Cells[0,i+1]:= WordToRadix(i+iFirstPortNo,_Radix,vLong,Bits);
sgIOPort.Cells[1,i+1]:= WordToRadix((Sender as TIOPorts).Value[i+iFirstPortNo],
_Radix,vLong,8);
end;
end;
end;
procedure TIOPortForm.PortUpdate(Sender: TObject; Index: Byte; Value: Byte);
var
sValue: String;
begin
if (Sender is TIOPorts) and
((Sender as TIOPorts).PortType = PortType) and not (PortType = ptUnknown) then
begin
Index:= Index - (Sender as TIOPorts).FirstPortNo;
sValue:= WordToRadix(Value,_Radix,vLong,8);
if sValue <> sgIOPort.Cells[1,Index+1] then
sgIOPort.Cells[2,Index+1]:= '*';
sgIOPort.Cells[1,Index+1]:= sValue;
end
end;
procedure TIOPortForm.PortAction(Sender: TObject; Active: Boolean);
begin
_BlockActive:= true;
cbPortActive.Checked:= Active;
CanEdit:= not Active;
_BlockActive:= false;
end;
procedure TIOPortForm.BeforeCycle(Sender: TObject);
var
i: Integer;
begin
for i:= 1 to sgIOPort.RowCount-1 do
begin
sgIOPort.Cells[2,i]:= '';
sgIOPort.Cells[1,i]:= sgIOPort.Cells[1,i];
end;
end;
procedure TIOPortForm.AfterCycle(Sender: TObject);
begin
end;
procedure TIOPortForm.StateChange(Sender: TObject; Halt: Boolean);
begin
end;
procedure TIOPortForm.LoadData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,false) then
RegistryList.LoadFormSettings(Self,true);
end;
procedure TIOPortForm.SaveData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,true) then
RegistryList.SaveFormSettings(Self,true);
end;
procedure TIOPortForm.LoadLanguage;
begin
sgIOPort.Cells[0,0]:= getString(rsPortAddress);
sgIOPort.Cells[1,0]:= getString(rsValue);
miClose.Caption:= getString(rsClose);
miStayOnTop.Caption:= getString(rsStayOnTop);
gbPortFile.Caption:= ' '+getString(rs_p_File)+' ';
cbPortActive.Caption:= getString(rs_p_Active);
sbResetFile.Hint:= getString(rs_p_ResetFile);
case PortType of
ptIN : sbFile.Caption:= getString(rs_p_Open);
ptOUT : sbFile.Caption:= getString(rs_p_Save);
else sbFile.Caption:= '';
end;
sbClose.Caption:= getString(rs_p_Close);
OpenDialog.Title:= getString(rs_p_OpenDialog);
SaveDialog.Title:= getString(rs_p_SaveDialog);
OpenDialog.Filter:= getString(rs_p_OpenFilter);
SaveDialog.Filter:= getString(rs_p_SaveFilter);
end;
procedure TIOPortForm.RadixChange(Radix: TRadix; View: TView);
begin
if Radix = rDecimalNeg then Radix:= rDecimal;
_Radix:= Radix;
end;
end.