-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
executable file
·333 lines (290 loc) · 8.07 KB
/
main.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
unit main;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ComCtrls, ExtCtrls, SynEdit, SynCompletion,
SynHighlighterAny, Cpu, InOutUtils;
type
{ TMainForm }
TMainForm = class(TForm)
ListView1: TListView;
ListView2: TListView;
PopupMenu1: TPopupMenu;
AddBreakPoint1: TMenuItem;
Button1: TButton;
GroupBox1: TGroupBox;
MainMenu1: TMainMenu;
File1: TMenuItem;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
LabeledEdit5: TLabeledEdit;
LabeledEdit6: TLabeledEdit;
LabeledEdit7: TLabeledEdit;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
LabeledEdit8: TLabeledEdit;
Button2: TButton;
Button3: TButton;
ASMCodeEditor1: TSynEdit;
SynAnySyn1: TSynAnySyn;
SynAnySyn2: TSynAnySyn;
SynCompletion1: TSynCompletion;
MicrocodeEdit1: TSynEdit;
Timer1: TTimer;
Save1: TMenuItem;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
Opent1: TMenuItem;
N1: TMenuItem;
Exit1: TMenuItem;
new1: TMenuItem;
N2: TMenuItem;
About1: TMenuItem;
About2: TMenuItem;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
ApplicationEvents1: TApplicationProperties;
Settings1: TMenuItem;
CpuSimSettings1: TMenuItem;
Panel1: TPanel;
Panel2: TPanel;
GroupBox4: TGroupBox;
Splitter1: TSplitter;
GroupBox2: TGroupBox;
Edit2: TEdit;
GroupBox3: TGroupBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Opent1Click(Sender: TObject);
procedure new1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
procedure About2Click(Sender: TObject);
procedure CpuSimSettings1Click(Sender: TObject);
procedure LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure LabeledEdit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
procedure SetCrMInstr(crPoz: String);
procedure RefreshCpuStat;
procedure visualSwap;
// Procedure WNDPROC(var msg:TMessage);override;
end;
var
MainForm: TMainForm;
cmpCpu: TCPU;
codPos: Integer = 0;
keys: array[0..255] of boolean;
implementation
uses about, Settings;
{$R *.lfm}
{Procedure TMainForm.WNDPROC(var msg:TMessage);
begin
INHERITED;
case msg.Msg of
WM_VKEYTOITEM:
begin
ShowMessage('OK');
end;
end;
end;}
procedure TMainForm.visualSwap;
begin
end;
procedure TMainForm.RefreshCpuStat;
var
tmpAcLow, tmpCIL, tmpINTR: Boolean;
begin
cmpCPU.getCpuIntr( tmpCil, tmpACLOw, tmpINTR);
CheckBox2.Checked := tmpCil;
CheckBox1.Checked := tmpACLOW;
CheckBox3.Checked := tmpINTR;
end;//procedure TMainForm.RefreshCpuStat;
procedure TMainForm.SetCrMInstr(crPoz: String);
var
List1: TStringList;
begin
List1 := TStringList.Create;
try
List1.Delimiter := '|';
List1.StrictDelimiter := true;
List1.DelimitedText := crPoz;
if List1.Count = 3 then
begin
edit2.Text := List1[1];
MicrocodeEdit1.Lines.BeginUpdate;
MicrocodeEdit1.CaretY := StrToInt(List1[0]);
MicrocodeEdit1.SelectLine(true);
MicrocodeEdit1.Lines.EndUpdate;
end;
finally
List1.Free;
end;
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
if cmpCPU.GetCPUStatus then
begin
cmpCPU.setCpuIntr(CheckBox2.Checked, CheckBox1.Checked, CheckBox3.Checked);
SetCrMInstr(cmpCpu.instructionStep);
RefreshCpuStat;
end
else
begin
cmpCPU.LoadCode(ASMCodeEditor1.Lines);
cmpCPU.setCpuIntr(CheckBox2.Checked, CheckBox1.Checked, CheckBox3.Checked);
SetCrMInstr(cmpCpu.instructionStep);
RefreshCpuStat;
end;
visualSwap;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
cmpCpu := TCPU.Create(Image1);
cmpCPU.RegAssign(LabeledEdit1, ListView1, LabeledEdit2, LabeledEdit3, LabeledEdit4, LabeledEdit5, LabeledEdit6, LabeledEdit7, ListView2, LabeledEdit8);
cmpCPU.readMicroCod(ExtractFilePath(Application.ExeName)+'microcod.dat');
cmpCPU.cpuInit;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
if key<256 then Keys[key]:=true;
end;
procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if key<256 then Keys[key]:=false;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
if cmpCPU.GetCPUStatus then
begin
cmpCPU.setCpuIntr(CheckBox2.Checked, CheckBox1.Checked, CheckBox3.Checked);
SetCrMInstr(cmpCpu.instructionStep);
RefreshCpuStat;
end
else
begin
Button3Click(Sender);
end;
visualSwap;
end;
procedure TMainForm.Button3Click(Sender: TObject);
begin
if Button3.Caption = 'Run' then
begin
if not cmpCPU.GetCPUStatus then
begin
cmpCPU.setCpuIntr(CheckBox2.Checked, CheckBox1.Checked, CheckBox3.Checked);
cmpCPU.LoadCode(ASMCodeEditor1.Lines);
end;
timer1.Enabled := true;
Button3.Caption := 'Stop';
end
else
begin
timer1.Enabled := false;
Button3.Caption := 'Run';
end;
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
MicrocodeEdit1.Lines.LoadFromFile(ExtractFilePath(Application.ExeName)+'microcod.dat');
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
SetCrMInstr(' ');
cmpCPU.cpuInit;
end;
procedure TMainForm.Save1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
ASMCodeEditor1.Lines.SaveToFile(SaveDialog1.FileName);
end;
procedure TMainForm.Opent1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
ASMCodeEditor1.Lines.LoadFromFile(OpenDialog1.FileName);
Button2Click(Sender);
end;
end;
procedure TMainForm.new1Click(Sender: TObject);
begin
ASMCodeEditor1.Lines.Clear;
Button2Click(Sender);
end;
procedure TMainForm.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainForm.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
const
slp:integer= 50;
begin
if (getActiveWindow() = MainForm.Handle)and(GroupBox1.Enabled) then
begin
done := true;
if keys[118] then
begin
Button1Click(sender);
delay(slp);
end;
if keys[120] then
begin
Button3Click(sender);
Delay(slp);
end;
if keys[113] then
begin
Button2Click(sender);
Delay(slp);
end;
application.ProcessMessages;
end;
end;
procedure TMainForm.About2Click(Sender: TObject);
var
i: Integer;
begin
AboutForm.Show;
for i:=1 to 255 do
begin
AboutForm.AlphaBlendValue := i;
application.ProcessMessages;
end;
end;
procedure TMainForm.CpuSimSettings1Click(Sender: TObject);
begin
SettingsForm.Show;
end;
procedure TMainForm.LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key <> ord('1')) and (key <> ord('0')) and (key <> 37) and (key <> 38) and (key <> 39) and (key <> 40) and (key <> 8) and (key <> 46) and (key <> 13) and (key <> 35) and (key <> 36) then
begin
Key := 0;
end;
end;
procedure TMainForm.LabeledEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> '1') and (key <> '0') and (key <> #37) and (key <> #38) and (key <> #39) and (key <> #40) and (key <> #8) and (key <> #46) and (key <> #13) and (key <> #35) and (key <> #36) then
begin
Key := #0;
end;
end;
end.