| 1 | unit UFormMain;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
|---|
| 9 | StdCtrls, ExtCtrls, UMachine, UInstructionWriter, UCpu;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 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 |
|
|---|
| 42 | var
|
|---|
| 43 | FormMain: TFormMain;
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | implementation
|
|---|
| 47 |
|
|---|
| 48 | {$R *.lfm}
|
|---|
| 49 |
|
|---|
| 50 | uses
|
|---|
| 51 | UFormConsole, UFormMemory, UFormScreen, UFormCpuState, UFormAssembler,
|
|---|
| 52 | UFormDisassembler;
|
|---|
| 53 |
|
|---|
| 54 | { TFormMain }
|
|---|
| 55 |
|
|---|
| 56 | procedure TFormMain.FormShow(Sender: TObject);
|
|---|
| 57 | var
|
|---|
| 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;
|
|---|
| 67 | begin
|
|---|
| 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;
|
|---|
| 103 | end;
|
|---|
| 104 |
|
|---|
| 105 | procedure TFormMain.FormDestroy(Sender: TObject);
|
|---|
| 106 | begin
|
|---|
| 107 | FreeAndNil(InstructionWriter);
|
|---|
| 108 | FreeAndNil(Machine);
|
|---|
| 109 | end;
|
|---|
| 110 |
|
|---|
| 111 | procedure TFormMain.FormCreate(Sender: TObject);
|
|---|
| 112 | begin
|
|---|
| 113 | Machine := TMachine.Create(nil);
|
|---|
| 114 | InstructionWriter := TInstructionWriter.Create;
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | procedure TFormMain.ButtonStartClick(Sender: TObject);
|
|---|
| 118 | begin
|
|---|
| 119 | Machine.Cpu.Start;
|
|---|
| 120 | end;
|
|---|
| 121 |
|
|---|
| 122 | procedure TFormMain.ButtonStopClick(Sender: TObject);
|
|---|
| 123 | begin
|
|---|
| 124 | Machine.Cpu.Stop;
|
|---|
| 125 | end;
|
|---|
| 126 |
|
|---|
| 127 | procedure TFormMain.ButtonAssemblerClick(Sender: TObject);
|
|---|
| 128 | begin
|
|---|
| 129 | if not Assigned(FormAssembler) then
|
|---|
| 130 | FormAssembler := TFormAssembler.Create(Self);
|
|---|
| 131 | FormAssembler.Assembler.InstructionWriter.Memory := Machine.Memory;
|
|---|
| 132 | FormAssembler.Show;
|
|---|
| 133 | end;
|
|---|
| 134 |
|
|---|
| 135 | procedure TFormMain.ButtonConsoleClick(Sender: TObject);
|
|---|
| 136 | begin
|
|---|
| 137 | if not Assigned(FormConsole) then
|
|---|
| 138 | FormConsole := TFormConsole.Create(nil);
|
|---|
| 139 | FormConsole.Machine := Machine;
|
|---|
| 140 | FormConsole.Show;
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | procedure TFormMain.ButtonCpuStateClick(Sender: TObject);
|
|---|
| 144 | begin
|
|---|
| 145 | if not Assigned(FormCpuState) then
|
|---|
| 146 | FormCpuState := TFormCpuState.Create(Self);
|
|---|
| 147 | FormCpuState.Machine := Machine;
|
|---|
| 148 | FormCpuState.Show;
|
|---|
| 149 | FormCpuState.Reload;
|
|---|
| 150 | end;
|
|---|
| 151 |
|
|---|
| 152 | procedure TFormMain.ButtonDisassemblerClick(Sender: TObject);
|
|---|
| 153 | begin
|
|---|
| 154 | if not Assigned(FormDisassembler) then
|
|---|
| 155 | FormDisassembler := TFormDisassembler.Create(Self);
|
|---|
| 156 | FormDisassembler.Disassembler.Cpu := Machine.Cpu;
|
|---|
| 157 | FormDisassembler.Show;
|
|---|
| 158 | FormDisassembler.Reload;
|
|---|
| 159 | end;
|
|---|
| 160 |
|
|---|
| 161 | procedure TFormMain.ButtonMemoryClick(Sender: TObject);
|
|---|
| 162 | begin
|
|---|
| 163 | if not Assigned(FormMemory) then
|
|---|
| 164 | FormMemory := TFormMemory.Create(Self);
|
|---|
| 165 | FormMemory.Machine := Machine;
|
|---|
| 166 | FormMemory.Show;
|
|---|
| 167 | FormMemory.Reload;
|
|---|
| 168 | end;
|
|---|
| 169 |
|
|---|
| 170 | procedure TFormMain.ButtonScreenClick(Sender: TObject);
|
|---|
| 171 | begin
|
|---|
| 172 | if not Assigned(FormScreen) then
|
|---|
| 173 | FormScreen := TFormScreen.Create(Self);
|
|---|
| 174 | FormScreen.Machine := Machine;
|
|---|
| 175 | FormScreen.Show;
|
|---|
| 176 | FormScreen.Reload;
|
|---|
| 177 | end;
|
|---|
| 178 |
|
|---|
| 179 | end.
|
|---|
| 180 |
|
|---|