-
Notifications
You must be signed in to change notification settings - Fork 0
/
uDisAssemblerForm.pas
214 lines (185 loc) · 5.88 KB
/
uDisAssemblerForm.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
unit uDisAssemblerForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uResourceStrings, uView, uDisAssembler, uProcessor, StdCtrls,
ExtCtrls, Menus, EnhCtrls, uMisc, Registry;
type
TProgramCounterUpdateRequestEvent = procedure(Address: Word) of object;
TDisAssemblerForm = class(TForm, ILanguage, IRadixView, IProgramCounter, IProcessor, IRAM, IRegistry)
pDisAssemble: TPanel;
pCode0: TPanel;
pCode1: TPanel;
pCode2: TPanel;
pCode3: TPanel;
pCode4: TPanel;
pCode5: TPanel;
LblSourcecode: TLabel;
Label1: TLabel;
iArrow: TImage;
bDivider: TBevel;
Label2: TLabel;
PopupMenu: TPopupMenu;
miClose: TMenuItem;
N1: TMenuItem;
miStayOnTop: TMenuItem;
eePC: TEnhancedEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure miCloseClick(Sender: TObject);
procedure miStayOnTopClick(Sender: TObject);
procedure ePCKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure ePCClick(Sender: TObject);
private
_pCodes: array [0..6] of TPanel;
_DisAssembler: Ti8008DisAssembler;
_SourceCode: TStringList;
_Radix: TRadix;
_View: TView;
_ProgramCounterUpdateRequest: TProgramCounterUpdateRequestEvent;
procedure ShowSourceCode;
procedure RefreshObject(Sender: TObject);
procedure Reset(Sender: TObject);
procedure PCUpdate(Sender: TObject; Value: Word);
procedure BeforeCycle(Sender: TObject);
procedure AfterCycle(Sender: TObject);
procedure StateChange(Sender: TObject; Halt: Boolean);
procedure RAMUpdate(Sender: TObject; Address: Word; Value: Byte);
procedure LoadData(RegistryList: TRegistryList);
procedure SaveData(RegistryList: TRegistryList);
procedure setProcessor(Value: Ti8008Processor);
function getProcessor: Ti8008Processor;
public
procedure LoadLanguage;
procedure RadixChange(Radix: TRadix; View: TView);
property Processor: Ti8008Processor read getProcessor write setProcessor;
property OnProgramCounterUpdateRequest: TProgramCounterUpdateRequestEvent read _ProgramCounterUpdateRequest write _ProgramCounterUpdateRequest;
end;
var
DisAssemblerForm: TDisAssemblerForm;
implementation
uses uEditForm;
{$R *.dfm}
procedure TDisAssemblerForm.FormCreate(Sender: TObject);
begin
_Radix:= rOctal;
_View:= vShort;
_DisAssembler:= Ti8008DisAssembler.Create;
_SourceCode:= TStringList.Create;
_pCodes[0]:= pCode0;
_pCodes[1]:= pCode1;
_pCodes[2]:= pCode2;
_pCodes[3]:= pCode3;
_pCodes[4]:= pCode4;
_pCodes[5]:= pCode5;
AutoSize:= true;
LoadLanguage;
end;
procedure TDisAssemblerForm.FormDestroy(Sender: TObject);
begin
_SourceCode.Free;
_DisAssembler.Free;
end;
procedure TDisAssemblerForm.ePCClick(Sender: TObject);
var
C: Boolean;
P: TPoint;
begin
if (Sender is TEnhancedEdit) then
begin
P.X:= Mouse.CursorPos.X;
P.Y:= Mouse.CursorPos.Y;
EditForm.Value:= RadixToWord((Sender as TEnhancedEdit).Text,_Radix,_View,C);
if (EditForm.ShowModal(_Radix,_View,14,P) = mrOk) and Assigned(OnProgramCounterUpdateRequest) then
OnProgramCounterUpdateRequest(EditForm.Value);
end;
end;
procedure TDisAssemblerForm.ePCKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
ePCClick(Sender);
end;
procedure TDisAssemblerForm.miCloseClick(Sender: TObject);
begin
Close;
end;
procedure TDisAssemblerForm.miStayOnTopClick(Sender: TObject);
begin
if miStayOnTop.Checked then
FormStyle:= fsNormal
else
FormStyle:= fsStayOnTop;
miStayOnTop.Checked:= not miStayOnTop.Checked;
end;
procedure TDisAssemblerForm.ShowSourceCode;
var
i: Byte;
begin
_DisAssembler.Disassemble(_SourceCode);
for i:= 0 to High(_pCodes)-1 do
_pCodes[i].Caption:= _SourceCode.Strings[i];
end;
procedure TDisAssemblerForm.RefreshObject(Sender: TObject);
begin
if Sender is Ti8008Stack then
eePC.Text:= WordToRadix((Sender as Ti8008Stack).ProgramCounter,_Radix,_View,14);
ShowSourceCode;
end;
procedure TDisAssemblerForm.Reset(Sender: TObject);
begin
if Sender is Ti8008Stack then
eePC.Text:= WordToRadix((Sender as Ti8008Stack).ProgramCounter,_Radix,_View,14);
ShowSourceCode;
end;
procedure TDisAssemblerForm.PCUpdate(Sender: TObject; Value: Word);
begin
if Sender is Ti8008Stack then
eePC.Text:= WordToRadix((Sender as Ti8008Stack).ProgramCounter,_Radix,_View,14);
ShowSourceCode;
end;
procedure TDisAssemblerForm.BeforeCycle(Sender: TObject);
begin
ShowSourceCode;
end;
procedure TDisAssemblerForm.AfterCycle(Sender: TObject);
begin
end;
procedure TDisAssemblerForm.StateChange(Sender: TObject; Halt: Boolean);
begin
end;
procedure TDisAssemblerForm.RAMUpdate(Sender: TObject; Address: Word; Value: Byte);
begin
ShowSourceCode;
end;
procedure TDisAssemblerForm.LoadData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,false) then
RegistryList.LoadFormSettings(Self,false);
end;
procedure TDisAssemblerForm.SaveData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,true) then
RegistryList.SaveFormSettings(Self,false);
end;
procedure TDisAssemblerForm.setProcessor(Value: Ti8008Processor);
begin
_DisAssembler.Processor:= Value;
end;
function TDisAssemblerForm.getProcessor: Ti8008Processor;
begin
result:= _DisAssembler.Processor;
end;
procedure TDisAssemblerForm.LoadLanguage;
begin
LblSourcecode.Caption:= getString(rsSourcecode);
end;
procedure TDisAssemblerForm.RadixChange(Radix: TRadix; View: TView);
begin
if Radix = rDecimalNeg then Radix:= rDecimal;
_Radix:= Radix;
_View:= View;
_DisAssembler.Radix:= Radix;
_DisAssembler.View:= View;
end;
end.