Changeset 171 for branches/virtualcpu4/UFormMain.pas
- Timestamp:
- Apr 10, 2019, 4:00:46 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UFormMain.pas
r170 r171 1 1 unit UFormMain; 2 2 3 {$mode objfpc}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface … … 17 17 ButtonStop: TButton; 18 18 Label1: TLabel; 19 Label2: TLabel; 19 20 ListViewMemory: TListView; 20 21 ListViewRegisters: TListView; 22 Memo1: TMemo; 21 23 Timer1: TTimer; 22 24 procedure ButtonStartClick(Sender: TObject); … … 27 29 procedure ListViewMemoryData(Sender: TObject; Item: TListItem); 28 30 procedure ListViewRegistersData(Sender: TObject; Item: TListItem); 31 procedure Memo1KeyPress(Sender: TObject; var Key: char); 29 32 procedure Timer1Timer(Sender: TObject); 30 33 private 34 KeyInputBuffer: array of Char; 35 function CpuInput(Port: TAddress): TRegister; 36 procedure CpuOutput(Port: TAddress; Value: TRegister); 31 37 procedure ReloadMemoryDump; 32 38 procedure ReloadRegisterDump; … … 62 68 begin 63 69 Cpu := TCpu.Create; 70 Cpu.OnInput := CpuInput; 71 Cpu.OnOutput := CpuOutput; 64 72 Cpu.DataSize := bw16; 65 73 Cpu.AddressSize := bw16; … … 110 118 end; 111 119 120 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char); 121 begin 122 SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1); 123 KeyInputBuffer[High(KeyInputBuffer)] := Key; 124 end; 125 112 126 procedure TFormMain.Timer1Timer(Sender: TObject); 113 127 begin … … 133 147 R1: Byte; 134 148 R2: Byte; 149 R3: Byte; 135 150 LabelStart: Integer; 151 LabelText: Integer; 152 LabelPrint: Integer; 136 153 begin 137 154 R1 := 1; 138 155 R2 := 2; 156 R3 := 3; 139 157 with InstructionWriter do begin 158 LabelText := 200; 159 LoadConst(R1, LabelText); 160 LoadConst(R2, 12); 161 LabelPrint := IP; 162 DataPrefix8; LoadMem(R3, R1); 163 DataPrefix8; Output(0, R3); 164 Increment(R1); 165 Decrement(R2); 166 Test(R2); 167 JumpNotZero(LabelPrint); 168 140 169 LoadConst(R1, 100); 170 LabelStart := IP; 171 Increment(R1); 141 172 LoadConst(R2, 100); 142 LabelStart := IP;143 Increment(R1);144 173 DataPrefix8; StoreMem(R2, R1); 174 DataPrefix8; Input(R2, 0); 175 DataPrefix8; Output(0, R2); 145 176 Jump(LabelStart); 146 177 Halt; 147 end; 148 end; 178 IP := LabelText; 179 WriteString('Hello World!'); 180 end; 181 end; 182 183 function TFormMain.CpuInput(Port: TAddress): TRegister; 184 begin 185 Result.Q := 0; 186 case Port of 187 0: begin 188 while (Length(KeyInputBuffer) = 0) and not Cpu.Terminated do begin 189 Sleep(100); 190 end; 191 if Length(KeyInputBuffer) > 0 then begin 192 Result.B := Ord(KeyInputBuffer[0]); 193 if Length(KeyInputBuffer) > 1 then 194 Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1); 195 SetLength(KeyInputBuffer, Length(KeyInputBuffer) - 1); 196 end else Result.B := 0; 197 end; 198 end; 199 end; 200 201 procedure TFormMain.CpuOutput(Port: TAddress; Value: TRegister); 202 begin 203 case Port of 204 0: Memo1.Lines.Text := Memo1.Lines.Text + Char(Value.B); 205 end; 206 end; 207 149 208 150 209
Note:
See TracChangeset
for help on using the changeset viewer.