source: trunk/Core.pas

Last change on this file was 4, checked in by chronos, 16 months ago
  • Fixed: Memory leaks.
File size: 4.6 KB
Line 
1unit Core;
2
3interface
4
5uses
6 Classes, SysUtils, ActnList, Controls, FormMain, Forms, ExtCtrls, FormMemory,
7 SharpMz800, FormDisassembler, FormCpu, FormScreen;
8
9type
10
11 { TCore }
12
13 TCore = class(TDataModule)
14 AViewScreen: TAction;
15 AViewCpu: TAction;
16 AStop: TAction;
17 AStepOut: TAction;
18 ARun: TAction;
19 AStepIn: TAction;
20 AStepOver: TAction;
21 ARunToCursor: TAction;
22 APause: TAction;
23 AViewDissssembler: TAction;
24 AViewMemory: TAction;
25 AExit: TAction;
26 ActionList1: TActionList;
27 ImageList1: TImageList;
28 TimerUpdate: TTimer;
29 procedure AExitExecute(Sender: TObject);
30 procedure APauseExecute(Sender: TObject);
31 procedure ARunExecute(Sender: TObject);
32 procedure AStepInExecute(Sender: TObject);
33 procedure AStepOutExecute(Sender: TObject);
34 procedure AStepOverExecute(Sender: TObject);
35 procedure AStopExecute(Sender: TObject);
36 procedure AViewCpuExecute(Sender: TObject);
37 procedure AViewDissssemblerExecute(Sender: TObject);
38 procedure AViewMemoryExecute(Sender: TObject);
39 procedure AViewScreenExecute(Sender: TObject);
40 procedure DataModuleCreate(Sender: TObject);
41 procedure DataModuleDestroy(Sender: TObject);
42 procedure TimerUpdateTimer(Sender: TObject);
43 private
44 LastPc: Word;
45 public
46 FormMain: TFormMain;
47 FormMemory: TFormMemory;
48 FormDisassembler: TFormDisassembler;
49 FormCpu: TFormCpu;
50 FormScreen: TFormScreen;
51 SharpMz800: TSharpMz800;
52 procedure UpdateDisassemblerPos;
53 procedure UpdateInterface;
54 end;
55
56var
57 Core: TCore;
58
59
60implementation
61
62{$R *.lfm}
63
64uses
65 CpuZ80;
66
67{ TCore }
68
69procedure TCore.DataModuleCreate(Sender: TObject);
70begin
71 SharpMz800 := TSharpMz800.Create;
72// SharpMz800.PowerOn;
73 FormMain := TFormMain.Create(nil);
74 FormMain.Show;
75end;
76
77procedure TCore.AExitExecute(Sender: TObject);
78begin
79 Application.Terminate;
80end;
81
82procedure TCore.APauseExecute(Sender: TObject);
83begin
84 SharpMz800.Cpu.Running := False;
85 UpdateInterface;
86end;
87
88procedure TCore.ARunExecute(Sender: TObject);
89begin
90 SharpMz800.Cpu.Running := True;
91 UpdateInterface;
92end;
93
94procedure TCore.AStepInExecute(Sender: TObject);
95begin
96 SharpMz800.Cpu.DebugMode := dmStepIn;
97 SharpMz800.Cpu.Running := True;
98 UpdateInterface;
99end;
100
101procedure TCore.AStepOutExecute(Sender: TObject);
102begin
103 SharpMz800.Cpu.DebugMode := dmStepOut;
104 SharpMz800.Cpu.Running := True;
105 UpdateInterface;
106end;
107
108procedure TCore.AStepOverExecute(Sender: TObject);
109begin
110 SharpMz800.Cpu.DebugMode := dmStepOver;
111 SharpMz800.Cpu.Running := True;
112 UpdateInterface;
113end;
114
115procedure TCore.AStopExecute(Sender: TObject);
116begin
117 SharpMz800.Cpu.Running := False;
118 SharpMz800.Cpu.Reset;
119 UpdateInterface;
120end;
121
122procedure TCore.AViewCpuExecute(Sender: TObject);
123begin
124 if not Assigned(FormCpu) then begin
125 FormCpu := TFormCpu.Create(nil);
126 FormCpu.Cpu := SharpMz800.Cpu;
127 end;
128 FormCpu.Show;
129end;
130
131procedure TCore.AViewDissssemblerExecute(Sender: TObject);
132begin
133 if not Assigned(FormDisassembler) then begin
134 FormDisassembler := TFormDisassembler.Create(nil);
135 FormDisassembler.Disassembler.Memory := SharpMz800.MappedMemory;
136 end;
137 FormDisassembler.Show;
138end;
139
140procedure TCore.AViewMemoryExecute(Sender: TObject);
141begin
142 if not Assigned(FormMemory) then begin
143 FormMemory := TFormMemory.Create(nil);
144 FormMemory.Size := SharpMz800.MappedMemory.Size;
145 FormMemory.Memory := SharpMz800.MappedMemory;
146 end;
147 FormMemory.Show;
148end;
149
150procedure TCore.AViewScreenExecute(Sender: TObject);
151begin
152 if not Assigned(FormScreen) then begin
153 FormScreen := TFormScreen.Create(nil);
154 end;
155 FormScreen.Show;
156end;
157
158procedure TCore.DataModuleDestroy(Sender: TObject);
159begin
160 if Assigned(FormCpu) then FreeAndNil(FormCpu);
161 if Assigned(FormDisassembler) then FreeAndNil(FormDisassembler);
162 if Assigned(FormMemory) then FreeAndNil(FormMemory);
163 if Assigned(FormScreen) then FreeAndNil(FormScreen);
164 FreeAndNil(FormMain);
165 FreeAndNil(SharpMz800);
166end;
167
168procedure TCore.TimerUpdateTimer(Sender: TObject);
169begin
170 UpdateDisassemblerPos;
171 UpdateInterface;
172end;
173
174procedure TCore.UpdateDisassemblerPos;
175begin
176 if LastPc <> SharpMz800.Cpu.Pc then begin
177 if Assigned(FormDisassembler) then
178 FormDisassembler.SelectAddress(SharpMz800.Cpu.PC);
179 LastPc := SharpMz800.Cpu.Pc;
180 end;
181end;
182
183procedure TCore.UpdateInterface;
184begin
185 ARun.Enabled := not SharpMz800.Cpu.Running;
186 AStop.Enabled := SharpMz800.Cpu.Running;
187 APause.Enabled := SharpMz800.Cpu.Running;
188 AStepIn.Enabled := not SharpMz800.Cpu.Running;
189 AStepOut.Enabled := not SharpMz800.Cpu.Running;
190 AStepOver.Enabled := not SharpMz800.Cpu.Running;
191 ARunToCursor.Enabled := not SharpMz800.Cpu.Running;
192end;
193
194end.
195
Note: See TracBrowser for help on using the repository browser.