1 | unit Core;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, ActnList, Controls, Forms, Machine, Memory, Message,
|
---|
7 | Disassembler, Assembler, FormCpu, FormDevices, FormHelp, FormMessages,
|
---|
8 | FormMain, FormDisassembler;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TCore }
|
---|
13 |
|
---|
14 | TCore = class(TDataModule)
|
---|
15 | AHelp: TAction;
|
---|
16 | ADisassembler: TAction;
|
---|
17 | ACpu: TAction;
|
---|
18 | ADevices: TAction;
|
---|
19 | ARunToCursor: TAction;
|
---|
20 | AStop: TAction;
|
---|
21 | AStepOver: TAction;
|
---|
22 | AStepOut: TAction;
|
---|
23 | AStepInto: TAction;
|
---|
24 | APause: TAction;
|
---|
25 | ARun: TAction;
|
---|
26 | ACompile: TAction;
|
---|
27 | AExit: TAction;
|
---|
28 | ActionList1: TActionList;
|
---|
29 | ImageList1: TImageList;
|
---|
30 | procedure ACompileExecute(Sender: TObject);
|
---|
31 | procedure ACpuExecute(Sender: TObject);
|
---|
32 | procedure ADevicesExecute(Sender: TObject);
|
---|
33 | procedure ADisassemblerExecute(Sender: TObject);
|
---|
34 | procedure AExitExecute(Sender: TObject);
|
---|
35 | procedure AHelpExecute(Sender: TObject);
|
---|
36 | procedure ARunExecute(Sender: TObject);
|
---|
37 | procedure AStopExecute(Sender: TObject);
|
---|
38 | procedure DataModuleCreate(Sender: TObject);
|
---|
39 | procedure DataModuleDestroy(Sender: TObject);
|
---|
40 | private
|
---|
41 | FormCpu: TFormCpu;
|
---|
42 | FormDevices: TFormDevices;
|
---|
43 | FormHelp: TFormHelp;
|
---|
44 | FormMain: TFormMain;
|
---|
45 | FormDisassembler: TFormDisassembler;
|
---|
46 | public
|
---|
47 | Assembler: TAssembler;
|
---|
48 | Disassembler: TDisassembler;
|
---|
49 | Machine: TMachine;
|
---|
50 | CompiledProgram: TMemory;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | var
|
---|
54 | Core: TCore;
|
---|
55 |
|
---|
56 |
|
---|
57 | implementation
|
---|
58 |
|
---|
59 | {$R *.lfm}
|
---|
60 |
|
---|
61 | uses
|
---|
62 | FormScreen, FormAssembler, FormConsole;
|
---|
63 |
|
---|
64 | { TCore }
|
---|
65 |
|
---|
66 | procedure TCore.AExitExecute(Sender: TObject);
|
---|
67 | begin
|
---|
68 | Application.Terminate;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TCore.AHelpExecute(Sender: TObject);
|
---|
72 | begin
|
---|
73 | if not Assigned(FormHelp) then
|
---|
74 | FormHelp := TFormHelp.Create(nil);
|
---|
75 | FormHelp.Show;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TCore.ARunExecute(Sender: TObject);
|
---|
79 | begin
|
---|
80 | ACompile.Execute;
|
---|
81 | Machine.PowerOn;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | procedure TCore.AStopExecute(Sender: TObject);
|
---|
85 | begin
|
---|
86 | Machine.PowerOff;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TCore.DataModuleCreate(Sender: TObject);
|
---|
90 | begin
|
---|
91 | Machine := TMachine.Create;
|
---|
92 | CompiledProgram := TMemory.Create;
|
---|
93 | Assembler := TAssembler.Create;
|
---|
94 | Disassembler := TDisassembler.Create;
|
---|
95 | FormMain := TFormMain.Create(nil);
|
---|
96 | FormMain.Show;
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
---|
100 | begin
|
---|
101 | if Assigned(FormCpu) then FreeAndNil(FormCpu);
|
---|
102 | if Assigned(FormDevices) then FreeAndNil(FormDevices);
|
---|
103 | if Assigned(FormHelp) then FreeAndNil(FormHelp);
|
---|
104 | if Assigned(FormDisassembler) then FreeAndNil(FormDisassembler);
|
---|
105 | FreeAndNil(FormMain);
|
---|
106 | FreeAndNil(Disassembler);
|
---|
107 | FreeAndNil(Assembler);
|
---|
108 | FreeAndNil(CompiledProgram);
|
---|
109 | FreeAndNil(Machine);
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TCore.ACompileExecute(Sender: TObject);
|
---|
113 | begin
|
---|
114 | AStop.Execute;
|
---|
115 | with Assembler do begin
|
---|
116 | Compile(FormMain.FormAssembler.SynEdit1.Lines.Text);
|
---|
117 | //Memory.SaveToFile('compiled.bin');
|
---|
118 | CompiledProgram.Assign(Memory);
|
---|
119 | Machine.Memory.Position := 0;
|
---|
120 | Machine.Memory.WriteMemory(CompiledProgram);
|
---|
121 | end;
|
---|
122 | if FormMain.FormMessages.Visible then
|
---|
123 | FormMain.FormMessages.Reload;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TCore.ACpuExecute(Sender: TObject);
|
---|
127 | begin
|
---|
128 | if not Assigned(FormCpu) then
|
---|
129 | FormCpu := TFormCpu.Create(nil);
|
---|
130 | FormCpu.Cpu := Machine.Cpu;
|
---|
131 | FormCpu.Show;
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TCore.ADevicesExecute(Sender: TObject);
|
---|
135 | begin
|
---|
136 | if not Assigned(FormDevices) then
|
---|
137 | FormDevices := TFormDevices.Create(nil);
|
---|
138 | FormDevices.Devices := Machine.Devices;
|
---|
139 | FormDevices.Show;
|
---|
140 | end;
|
---|
141 |
|
---|
142 | procedure TCore.ADisassemblerExecute(Sender: TObject);
|
---|
143 | begin
|
---|
144 | if not Assigned(FormDisassembler) then
|
---|
145 | FormDisassembler := TFormDisassembler.Create(nil);
|
---|
146 | with Disassembler do begin
|
---|
147 | Memory := CompiledProgram;
|
---|
148 | Disassemble(FormDisassembler.MemoCode.Lines);
|
---|
149 | end;
|
---|
150 | FormDisassembler.Show;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | end.
|
---|
154 |
|
---|