source: branches/CpuSingleSize/Core.pas

Last change on this file was 238, checked in by chronos, 16 months ago
  • Modified: Removed U prefix from unit names.
  • Fixed: Memory leaks.
File size: 3.6 KB
Line 
1unit Core;
2
3interface
4
5uses
6 Classes, SysUtils, ActnList, Controls, Forms, Machine, Memory, Message,
7 Disassembler, Assembler, FormCpu, FormDevices, FormHelp, FormMessages,
8 FormMain, FormDisassembler;
9
10type
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
53var
54 Core: TCore;
55
56
57implementation
58
59{$R *.lfm}
60
61uses
62 FormScreen, FormAssembler, FormConsole;
63
64{ TCore }
65
66procedure TCore.AExitExecute(Sender: TObject);
67begin
68 Application.Terminate;
69end;
70
71procedure TCore.AHelpExecute(Sender: TObject);
72begin
73 if not Assigned(FormHelp) then
74 FormHelp := TFormHelp.Create(nil);
75 FormHelp.Show;
76end;
77
78procedure TCore.ARunExecute(Sender: TObject);
79begin
80 ACompile.Execute;
81 Machine.PowerOn;
82end;
83
84procedure TCore.AStopExecute(Sender: TObject);
85begin
86 Machine.PowerOff;
87end;
88
89procedure TCore.DataModuleCreate(Sender: TObject);
90begin
91 Machine := TMachine.Create;
92 CompiledProgram := TMemory.Create;
93 Assembler := TAssembler.Create;
94 Disassembler := TDisassembler.Create;
95 FormMain := TFormMain.Create(nil);
96 FormMain.Show;
97end;
98
99procedure TCore.DataModuleDestroy(Sender: TObject);
100begin
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);
110end;
111
112procedure TCore.ACompileExecute(Sender: TObject);
113begin
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;
124end;
125
126procedure TCore.ACpuExecute(Sender: TObject);
127begin
128 if not Assigned(FormCpu) then
129 FormCpu := TFormCpu.Create(nil);
130 FormCpu.Cpu := Machine.Cpu;
131 FormCpu.Show;
132end;
133
134procedure TCore.ADevicesExecute(Sender: TObject);
135begin
136 if not Assigned(FormDevices) then
137 FormDevices := TFormDevices.Create(nil);
138 FormDevices.Devices := Machine.Devices;
139 FormDevices.Show;
140end;
141
142procedure TCore.ADisassemblerExecute(Sender: TObject);
143begin
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;
151end;
152
153end.
154
Note: See TracBrowser for help on using the repository browser.