-
Notifications
You must be signed in to change notification settings - Fork 0
/
uStackForm.pas
229 lines (202 loc) · 6.88 KB
/
uStackForm.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
unit uStackForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, Menus, uResourceStrings, uProcessor, uView,
Buttons, StdCtrls, uEditForm, Registry, uMisc;
type
TStackPointerUpdateRequestEvent = procedure(Value: Byte) of object;
TStackUpdateRequestEvent = procedure(Index: Byte; Value: Word) of object;
TStackForm = class(TForm, IStack, ILanguage, IRadixView, IRegistry)
PopupMenu: TPopupMenu;
miClose: TMenuItem;
N1: TMenuItem;
miStayOnTop: TMenuItem;
iStackPointer: TImage;
sgStack: TStringGrid;
procedure miCloseClick(Sender: TObject);
procedure miStayOnTopClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure sgStackDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure sgStackDblClick(Sender: TObject);
procedure sgStackSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure sgStackKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
_StackPointer: Integer;
_ARow: Integer;
_ACol: Integer;
_Radix: TRadix;
_View: TView;
_OnSPUpdateRequest: TStackPointerUpdateRequestEvent;
_OnStackUpdateRequest: TStackUpdateRequestEvent;
procedure RefreshObject(Sender: TObject);
procedure Reset(Sender: TObject);
procedure SPChanged(Sender: TObject; SP: Byte);
procedure Change(Sender: TObject; Index: Byte; Value: Word);
procedure Push(Sender: TObject; Index: Byte; Value: Word);
procedure Pop(Sender: TObject; Index: Byte; Value: Word);
procedure LoadData(RegistryList: TRegistryList);
procedure SaveData(RegistryList: TRegistryList);
public
procedure LoadLanguage;
procedure RadixChange(Radix: TRadix; View: TView);
property OnStackPointerUpdateRequest: TStackPointerUpdateRequestEvent read _OnSPUpdateRequest write _OnSPUpdateRequest;
property OnStackUpdateRequest: TStackUpdateRequestEvent read _OnStackUpdateRequest write _OnStackUpdateRequest;
end;
var
StackForm: TStackForm;
implementation
{$R *.dfm}
procedure TStackForm.FormCreate(Sender: TObject);
var
i: Integer;
begin
_ARow:= 0;
_ACol:= 0;
_StackPointer:= -1;
_Radix:= rOctal;
_View:= vShort;
sgStack.ColCount:= 3;
sgStack.RowCount:= Ti8008Stack.Size+1;
for i:= 1 to sgStack.RowCount do
sgStack.Cells[0,i]:= IntToStr(i-1);
sgStack.ColWidths[0]:= 50;
sgStack.ColWidths[1]:= 100;
sgStack.ColWidths[2]:= 24;
sgStack.Width:= 174;
sgStack.Height:= sgStack.RowHeights[0] * (sgStack.RowCount + 1);
sgStack.Canvas.CopyMode:= cmMergeCopy;
AutoSize:= true;
LoadLanguage;
end;
procedure TStackForm.miCloseClick(Sender: TObject);
begin
Close;
end;
procedure TStackForm.miStayOnTopClick(Sender: TObject);
begin
if miStayOnTop.Checked then
FormStyle:= fsNormal
else
FormStyle:= fsStayOnTop;
miStayOnTop.Checked:= not miStayOnTop.Checked;
end;
procedure TStackForm.sgStackDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ARow = 0) or (ACol = 0) then
sgStack.Canvas.Brush.Color:= sgStack.FixedColor
else
sgStack.Canvas.Brush.Color:= sgStack.Color;
sgStack.Canvas.FillRect(Rect);
if ACol < 2 then
begin
Rect.Top:= Rect.Top + ((sgStack.RowHeights[ARow] -
sgStack.Canvas.TextHeight(sgStack.Cells[ACol,ARow]))) div 2;
if ARow = 0 then
Rect.Left:= Rect.Left + (sgStack.ColWidths[ACol] -
sgStack.Canvas.TextWidth(sgStack.Cells[ACol,ARow])) div 2
else
Rect.Left:= Rect.Right - 4 - sgStack.Canvas.TextWidth(sgStack.Cells[ACol,ARow]);
sgStack.Canvas.TextOut(Rect.Left,Rect.Top,sgStack.Cells[ACol,ARow]);
end
else
if (ARow-1) = _StackPointer then
sgStack.Canvas.CopyRect(Rect,iStackPointer.Canvas,Bounds(0,0,24,24));
end;
procedure TStackForm.sgStackSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
_ARow:= ARow;
_ACol:= ACol;
end;
procedure TStackForm.sgStackDblClick(Sender: TObject);
var
C: Boolean;
P: TPoint;
begin
if _ARow > 0 then
case _ACol of
1: begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= RadixToWord(sgStack.Cells[_ACol,_ARow],_Radix,_View,C);
if (EditForm.ShowModal(_Radix,_View,14,P) = mrOk) and Assigned(OnStackUpdateRequest) then
OnStackUpdateRequest(_ARow-1,EditForm.Value);
end;
2: if Assigned(OnStackPointerUpdateRequest) then
OnStackPointerUpdateRequest(_ARow-1);
end;
end;
procedure TStackForm.sgStackKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
sgStackDblClick(Sender);
end;
procedure TStackForm.RefreshObject(Sender: TObject);
var
i: Integer;
begin
if Sender is Ti8008Stack then
begin
_StackPointer:= (Sender as Ti8008Stack).StackPointer;
for i:= 1 to sgStack.RowCount do
sgStack.Cells[1,i]:= WordToRadix((Sender as Ti8008Stack).Items[i-1],_Radix,_View,14);
end;
end;
procedure TStackForm.Reset(Sender: TObject);
var
i: Integer;
begin
if Sender is Ti8008Stack then
begin
_StackPointer:= (Sender as Ti8008Stack).StackPointer;
for i:= 1 to sgStack.RowCount do
sgStack.Cells[1,i]:= WordToRadix((Sender as Ti8008Stack).Items[i-1],_Radix,_View,14);
end;
end;
procedure TStackForm.SPChanged(Sender: TObject; SP: Byte);
begin
_StackPointer:= SP;
sgStack.Invalidate;
end;
procedure TStackForm.Change(Sender: TObject; Index: Byte; Value: Word);
begin
sgStack.Cells[1,Index+1]:= WordToRadix(Value,_Radix,_View,14);
end;
procedure TStackForm.Push(Sender: TObject; Index: Byte; Value: Word);
begin
sgStack.Cells[1,Index+1]:= WordToRadix(Value,_Radix,_View,14);
end;
procedure TStackForm.Pop(Sender: TObject; Index: Byte; Value: Word);
begin
sgStack.Cells[1,Index+1]:= WordToRadix(Value,_Radix,_View,14);
end;
procedure TStackForm.LoadData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,false) then
RegistryList.LoadFormSettings(Self,false);
end;
procedure TStackForm.SaveData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,true) then
RegistryList.SaveFormSettings(Self,false);
end;
procedure TStackForm.LoadLanguage;
begin
sgStack.Cells[0,0]:= getString(rsAddress);
sgStack.Cells[1,0]:= getString(rsValue);
miClose.Caption:= getString(rsClose);
miStayOnTop.Caption:= getString(rsStayOnTop);
end;
procedure TStackForm.RadixChange(Radix: TRadix; View: TView);
begin
if Radix = rDecimalNeg then Radix:= rDecimal;
_Radix:= Radix;
_View:= View;
end;
end.