Changeset 196 for branches/virtcpu varint/UFormMain.pas
- Timestamp:
- Sep 22, 2019, 7:13:15 PM (5 years ago)
- Location:
- branches/virtcpu varint
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu varint
-
Property svn:ignore
set to
lib
virtcpu
virtcpu.lps
-
Property svn:ignore
set to
-
branches/virtcpu varint/UFormMain.pas
r195 r196 11 11 type 12 12 13 { TForm 1}14 15 TForm 1= class(TForm)13 { TFormMain } 14 15 TFormMain = class(TForm) 16 16 Button1: TButton; 17 17 Button2: TButton; … … 38 38 procedure CpuOutput(Port, Value: T); 39 39 public 40 Cpu: TCPU;40 Machine: TMachine; 41 41 InstructionWriter: TInstructionWriter; 42 42 end; 43 43 44 44 var 45 Form 1: TForm1;45 FormMain: TFormMain; 46 46 47 47 const … … 53 53 {$R *.lfm} 54 54 55 { TForm 1}56 57 procedure TForm 1.FormShow(Sender: TObject);55 { TFormMain } 56 57 procedure TFormMain.FormShow(Sender: TObject); 58 58 var 59 59 LabelStart: Integer; … … 104 104 end; 105 105 106 procedure TForm 1.FormDestroy(Sender: TObject);107 begin 108 InstructionWriter.Free;109 Cpu.Free;110 end; 111 112 procedure TForm 1.FormKeyPress(Sender: TObject; var Key: char);113 begin 114 end; 115 116 procedure TForm 1.FormCreate(Sender: TObject);117 begin 118 Cpu := TCPU.Create(nil);119 Cpu.OnInput := CpuInput;120 Cpu.OnOutput := CpuOutput;106 procedure TFormMain.FormDestroy(Sender: TObject); 107 begin 108 FreeAndNil(InstructionWriter); 109 FreeAndNil(Machine); 110 end; 111 112 procedure TFormMain.FormKeyPress(Sender: TObject; var Key: char); 113 begin 114 end; 115 116 procedure TFormMain.FormCreate(Sender: TObject); 117 begin 118 Machine := TMachine.Create(nil); 119 Machine.Cpu.OnInput := CpuInput; 120 Machine.Cpu.OnOutput := CpuOutput; 121 121 InstructionWriter := TInstructionWriter.Create; 122 InstructionWriter.Cpu := Cpu;123 end; 124 125 procedure TForm 1.Button1Click(Sender: TObject);126 begin 127 Cpu.Start;128 end; 129 130 procedure TForm 1.Button2Click(Sender: TObject);131 begin 132 Cpu.Stop;133 end; 134 135 procedure TForm 1.ListViewMemoryData(Sender: TObject; Item: TListItem);122 InstructionWriter.Cpu := Machine.Cpu; 123 end; 124 125 procedure TFormMain.Button1Click(Sender: TObject); 126 begin 127 Machine.Cpu.Start; 128 end; 129 130 procedure TFormMain.Button2Click(Sender: TObject); 131 begin 132 Machine.Cpu.Stop; 133 end; 134 135 procedure TFormMain.ListViewMemoryData(Sender: TObject; Item: TListItem); 136 136 var 137 137 Line: string; 138 138 I: Integer; 139 139 begin 140 if Item.Index < Length(Cpu.Memory)div ItemsPerLine then begin140 if Item.Index < Machine.MemorySize div ItemsPerLine then begin 141 141 Line := ''; 142 142 for I := 0 to ItemsPerLine - 1 do 143 Line := Line + IntToHex( Cpu.Memory[Item.Index * ItemsPerLine + I], 2) + ' ';143 Line := Line + IntToHex(PByte(NativeUInt(Machine.Memory) + Item.Index * ItemsPerLine + I)^, 2) + ' '; 144 144 Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8); 145 145 Item.SubItems.Add(Line); … … 147 147 end; 148 148 149 procedure TForm 1.ListViewRegistersData(Sender: TObject; Item: TListItem);150 begin 151 if Item.Index < Length( Cpu.Registers) + 1 then begin149 procedure TFormMain.ListViewRegistersData(Sender: TObject; Item: TListItem); 150 begin 151 if Item.Index < Length(Machine.Cpu.Registers) + 1 then begin 152 152 if Item.Index = 0 then begin 153 153 Item.Caption := 'IP'; 154 Item.SubItems.Add(IntToHex(Int64( Cpu.IP), 8));154 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.IP), 8)); 155 155 end else 156 156 if Item.Index = 1 then begin 157 157 Item.Caption := 'SP'; 158 Item.SubItems.Add(IntToHex(Int64( Cpu.SP), 8));158 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.SP), 8)); 159 159 end else begin 160 160 Item.Caption := 'R' + IntToStr(Item.Index - 2); 161 Item.SubItems.Add(IntToHex(Int64( Cpu.Registers[Item.Index - 2]), 8));161 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.Registers[Item.Index - 2]), 8)); 162 162 end; 163 163 end; 164 164 end; 165 165 166 procedure TForm 1.Memo1KeyPress(Sender: TObject; var Key: char);166 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char); 167 167 begin 168 168 SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1); … … 170 170 end; 171 171 172 procedure TForm 1.Timer1Timer(Sender: TObject);172 procedure TFormMain.Timer1Timer(Sender: TObject); 173 173 begin 174 174 ReloadMemoryDump; 175 175 ReloadRegisterDump; 176 LabelTicks.Caption := 'Ticks: ' + IntToStr( Cpu.Ticks);177 end; 178 179 procedure TForm 1.ReloadMemoryDump;180 begin 181 ListViewMemory.Items.Count := Length(Cpu.Memory)div ItemsPerLine;176 LabelTicks.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks); 177 end; 178 179 procedure TFormMain.ReloadMemoryDump; 180 begin 181 ListViewMemory.Items.Count := Machine.MemorySize div ItemsPerLine; 182 182 ListViewMemory.Refresh; 183 183 end; 184 184 185 procedure TForm 1.ReloadRegisterDump;186 begin 187 ListViewRegisters.Items.Count := Length( Cpu.Registers);185 procedure TFormMain.ReloadRegisterDump; 186 begin 187 ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers); 188 188 ListViewRegisters.Refresh; 189 189 end; 190 190 191 function TForm 1.CpuInput(Port: T): T;191 function TFormMain.CpuInput(Port: T): T; 192 192 begin 193 193 Result := 0; 194 194 case Integer(Port) of 195 195 0: begin 196 while (Length(KeyInputBuffer) = 0) and not Cpu.Terminated do begin196 while (Length(KeyInputBuffer) = 0) and not Machine.Cpu.Terminated do begin 197 197 Sleep(100); 198 198 Application.ProcessMessages; … … 208 208 end; 209 209 210 procedure TForm 1.CpuOutput(Port, Value: T);210 procedure TFormMain.CpuOutput(Port, Value: T); 211 211 begin 212 212 case Integer(Port) of
Note:
See TracChangeset
for help on using the changeset viewer.