| 1 | unit Core;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, ActnList, Controls, FormMain, Forms, ExtCtrls, FormMemory,
|
|---|
| 7 | SharpMz800, FormDisassembler, FormCpu, FormScreen;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 56 | var
|
|---|
| 57 | Core: TCore;
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | implementation
|
|---|
| 61 |
|
|---|
| 62 | {$R *.lfm}
|
|---|
| 63 |
|
|---|
| 64 | uses
|
|---|
| 65 | CpuZ80;
|
|---|
| 66 |
|
|---|
| 67 | { TCore }
|
|---|
| 68 |
|
|---|
| 69 | procedure TCore.DataModuleCreate(Sender: TObject);
|
|---|
| 70 | begin
|
|---|
| 71 | SharpMz800 := TSharpMz800.Create;
|
|---|
| 72 | // SharpMz800.PowerOn;
|
|---|
| 73 | FormMain := TFormMain.Create(nil);
|
|---|
| 74 | FormMain.Show;
|
|---|
| 75 | end;
|
|---|
| 76 |
|
|---|
| 77 | procedure TCore.AExitExecute(Sender: TObject);
|
|---|
| 78 | begin
|
|---|
| 79 | Application.Terminate;
|
|---|
| 80 | end;
|
|---|
| 81 |
|
|---|
| 82 | procedure TCore.APauseExecute(Sender: TObject);
|
|---|
| 83 | begin
|
|---|
| 84 | SharpMz800.Cpu.Running := False;
|
|---|
| 85 | UpdateInterface;
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | procedure TCore.ARunExecute(Sender: TObject);
|
|---|
| 89 | begin
|
|---|
| 90 | SharpMz800.Cpu.Running := True;
|
|---|
| 91 | UpdateInterface;
|
|---|
| 92 | end;
|
|---|
| 93 |
|
|---|
| 94 | procedure TCore.AStepInExecute(Sender: TObject);
|
|---|
| 95 | begin
|
|---|
| 96 | SharpMz800.Cpu.DebugMode := dmStepIn;
|
|---|
| 97 | SharpMz800.Cpu.Running := True;
|
|---|
| 98 | UpdateInterface;
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 | procedure TCore.AStepOutExecute(Sender: TObject);
|
|---|
| 102 | begin
|
|---|
| 103 | SharpMz800.Cpu.DebugMode := dmStepOut;
|
|---|
| 104 | SharpMz800.Cpu.Running := True;
|
|---|
| 105 | UpdateInterface;
|
|---|
| 106 | end;
|
|---|
| 107 |
|
|---|
| 108 | procedure TCore.AStepOverExecute(Sender: TObject);
|
|---|
| 109 | begin
|
|---|
| 110 | SharpMz800.Cpu.DebugMode := dmStepOver;
|
|---|
| 111 | SharpMz800.Cpu.Running := True;
|
|---|
| 112 | UpdateInterface;
|
|---|
| 113 | end;
|
|---|
| 114 |
|
|---|
| 115 | procedure TCore.AStopExecute(Sender: TObject);
|
|---|
| 116 | begin
|
|---|
| 117 | SharpMz800.Cpu.Running := False;
|
|---|
| 118 | SharpMz800.Cpu.Reset;
|
|---|
| 119 | UpdateInterface;
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 | procedure TCore.AViewCpuExecute(Sender: TObject);
|
|---|
| 123 | begin
|
|---|
| 124 | if not Assigned(FormCpu) then begin
|
|---|
| 125 | FormCpu := TFormCpu.Create(nil);
|
|---|
| 126 | FormCpu.Cpu := SharpMz800.Cpu;
|
|---|
| 127 | end;
|
|---|
| 128 | FormCpu.Show;
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | procedure TCore.AViewDissssemblerExecute(Sender: TObject);
|
|---|
| 132 | begin
|
|---|
| 133 | if not Assigned(FormDisassembler) then begin
|
|---|
| 134 | FormDisassembler := TFormDisassembler.Create(nil);
|
|---|
| 135 | FormDisassembler.Disassembler.Memory := SharpMz800.MappedMemory;
|
|---|
| 136 | end;
|
|---|
| 137 | FormDisassembler.Show;
|
|---|
| 138 | end;
|
|---|
| 139 |
|
|---|
| 140 | procedure TCore.AViewMemoryExecute(Sender: TObject);
|
|---|
| 141 | begin
|
|---|
| 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;
|
|---|
| 148 | end;
|
|---|
| 149 |
|
|---|
| 150 | procedure TCore.AViewScreenExecute(Sender: TObject);
|
|---|
| 151 | begin
|
|---|
| 152 | if not Assigned(FormScreen) then begin
|
|---|
| 153 | FormScreen := TFormScreen.Create(nil);
|
|---|
| 154 | end;
|
|---|
| 155 | FormScreen.Show;
|
|---|
| 156 | end;
|
|---|
| 157 |
|
|---|
| 158 | procedure TCore.DataModuleDestroy(Sender: TObject);
|
|---|
| 159 | begin
|
|---|
| 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);
|
|---|
| 166 | end;
|
|---|
| 167 |
|
|---|
| 168 | procedure TCore.TimerUpdateTimer(Sender: TObject);
|
|---|
| 169 | begin
|
|---|
| 170 | UpdateDisassemblerPos;
|
|---|
| 171 | UpdateInterface;
|
|---|
| 172 | end;
|
|---|
| 173 |
|
|---|
| 174 | procedure TCore.UpdateDisassemblerPos;
|
|---|
| 175 | begin
|
|---|
| 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;
|
|---|
| 181 | end;
|
|---|
| 182 |
|
|---|
| 183 | procedure TCore.UpdateInterface;
|
|---|
| 184 | begin
|
|---|
| 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;
|
|---|
| 192 | end;
|
|---|
| 193 |
|
|---|
| 194 | end.
|
|---|
| 195 |
|
|---|