source: branches/virtcpu varint/Forms/UFormMain.pas

Last change on this file was 197, checked in by chronos, 5 years ago
  • Modified: All parts of virtual machine have own form in Forms subdirectory.
  • Modified: Main form moved to Forms subdirectory.
  • Modified: TCpu class moved to UCpu unit.
  • Added: Assembler and dissasembler forms.
File size: 4.1 KB
Line 
1unit UFormMain;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 StdCtrls, ExtCtrls, UMachine, UInstructionWriter, UCpu;
10
11type
12
13 { TFormMain }
14
15 TFormMain = class(TForm)
16 ButtonStart: TButton;
17 ButtonStop: TButton;
18 ButtonAssembler: TButton;
19 ButtonDisassembler: TButton;
20 ButtonCpuState: TButton;
21 ButtonScreen: TButton;
22 ButtonMemory: TButton;
23 ButtonConsole: TButton;
24 Timer1: TTimer;
25 procedure ButtonStartClick(Sender: TObject);
26 procedure ButtonStopClick(Sender: TObject);
27 procedure ButtonAssemblerClick(Sender: TObject);
28 procedure ButtonConsoleClick(Sender: TObject);
29 procedure ButtonCpuStateClick(Sender: TObject);
30 procedure ButtonDisassemblerClick(Sender: TObject);
31 procedure ButtonMemoryClick(Sender: TObject);
32 procedure ButtonScreenClick(Sender: TObject);
33 procedure FormCreate(Sender: TObject);
34 procedure FormDestroy(Sender: TObject);
35 procedure FormShow(Sender: TObject);
36 private
37 public
38 Machine: TMachine;
39 InstructionWriter: TInstructionWriter;
40 end;
41
42var
43 FormMain: TFormMain;
44
45
46implementation
47
48{$R *.lfm}
49
50uses
51 UFormConsole, UFormMemory, UFormScreen, UFormCpuState, UFormAssembler,
52 UFormDisassembler;
53
54{ TFormMain }
55
56procedure TFormMain.FormShow(Sender: TObject);
57var
58 LabelStart: Integer;
59 LabelPrint: Integer;
60 LabelPrintBack: Integer;
61 R0: Integer;
62 R1: Integer;
63 R2: Integer;
64 R3: Integer;
65 R4: Integer;
66 R5: Integer;
67begin
68 R0 := 0;
69 R1 := 1;
70 R2 := 2;
71 R3 := 3;
72 R4 := 4;
73 R5 := 5;
74 with InstructionWriter do begin
75 {NoOperation;
76 LoadConst(1, $ffff);
77 Load(0, 1);
78 LoadConst(2, $10);
79 StoreMemory(2, 0);
80 }
81 LabelPrint := $100;
82
83 LoadConst(R5, 0); // Always zero
84
85 LoadConst(R2, 0);
86 LoadConst(R0, 0);
87 LoadConst(R4, Ord('a'));
88 LabelStart := IP;
89 Input(R1, R5);
90 Output(R5, R1);
91 Subtract(R1, R4);
92 TestEqual(R1, R5);
93 JumpCond(LabelPrint);
94 LabelPrintBack := IP;
95 Increment(R2);
96 Jump(LabelStart);
97 Halt;
98 IP := LabelPrint;
99 LoadConst(R3, Ord('!'));
100 Output(0, R3);
101 Jump(LabelPrintBack)
102 end;
103end;
104
105procedure TFormMain.FormDestroy(Sender: TObject);
106begin
107 FreeAndNil(InstructionWriter);
108 FreeAndNil(Machine);
109end;
110
111procedure TFormMain.FormCreate(Sender: TObject);
112begin
113 Machine := TMachine.Create(nil);
114 InstructionWriter := TInstructionWriter.Create;
115end;
116
117procedure TFormMain.ButtonStartClick(Sender: TObject);
118begin
119 Machine.Cpu.Start;
120end;
121
122procedure TFormMain.ButtonStopClick(Sender: TObject);
123begin
124 Machine.Cpu.Stop;
125end;
126
127procedure TFormMain.ButtonAssemblerClick(Sender: TObject);
128begin
129 if not Assigned(FormAssembler) then
130 FormAssembler := TFormAssembler.Create(Self);
131 FormAssembler.Assembler.InstructionWriter.Memory := Machine.Memory;
132 FormAssembler.Show;
133end;
134
135procedure TFormMain.ButtonConsoleClick(Sender: TObject);
136begin
137 if not Assigned(FormConsole) then
138 FormConsole := TFormConsole.Create(nil);
139 FormConsole.Machine := Machine;
140 FormConsole.Show;
141end;
142
143procedure TFormMain.ButtonCpuStateClick(Sender: TObject);
144begin
145 if not Assigned(FormCpuState) then
146 FormCpuState := TFormCpuState.Create(Self);
147 FormCpuState.Machine := Machine;
148 FormCpuState.Show;
149 FormCpuState.Reload;
150end;
151
152procedure TFormMain.ButtonDisassemblerClick(Sender: TObject);
153begin
154 if not Assigned(FormDisassembler) then
155 FormDisassembler := TFormDisassembler.Create(Self);
156 FormDisassembler.Disassembler.Cpu := Machine.Cpu;
157 FormDisassembler.Show;
158 FormDisassembler.Reload;
159end;
160
161procedure TFormMain.ButtonMemoryClick(Sender: TObject);
162begin
163 if not Assigned(FormMemory) then
164 FormMemory := TFormMemory.Create(Self);
165 FormMemory.Machine := Machine;
166 FormMemory.Show;
167 FormMemory.Reload;
168end;
169
170procedure TFormMain.ButtonScreenClick(Sender: TObject);
171begin
172 if not Assigned(FormScreen) then
173 FormScreen := TFormScreen.Create(Self);
174 FormScreen.Machine := Machine;
175 FormScreen.Show;
176 FormScreen.Reload;
177end;
178
179end.
180
Note: See TracBrowser for help on using the repository browser.