Changeset 197 for branches/virtcpu varint/Forms
- Timestamp:
- Sep 22, 2019, 9:31:49 PM (5 years ago)
- Location:
- branches/virtcpu varint/Forms
- Files:
-
- 13 added
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/virtcpu varint/Forms/UFormMain.lfm
r196 r197 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 OnKeyPress = FormKeyPress13 12 OnShow = FormShow 14 13 LCLVersion = '2.0.2.0' 15 object ListViewMemory: TListView 16 Left = 618 17 Height = 824 18 Top = 48 19 Width = 880 20 Columns = < 21 item 22 Caption = 'Address' 23 Width = 120 24 end 25 item 26 Width = 745 27 end> 28 Font.Name = 'Liberation Mono' 29 OwnerData = True 30 ParentFont = False 31 TabOrder = 0 32 ViewStyle = vsReport 33 OnData = ListViewMemoryData 34 end 35 object ListViewRegisters: TListView 36 Left = 374 37 Height = 824 38 Top = 49 39 Width = 230 40 Columns = < 41 item 42 Caption = 'Register' 43 Width = 96 44 end 45 item 46 Width = 120 47 end> 48 Font.Name = 'Liberation Mono' 49 OwnerData = True 50 ParentFont = False 51 TabOrder = 1 52 ViewStyle = vsReport 53 OnData = ListViewRegistersData 54 end 55 object Memo1: TMemo 56 Left = 19 57 Height = 637 58 Top = 29 59 Width = 341 60 OnKeyPress = Memo1KeyPress 61 ParentFont = False 62 ReadOnly = True 63 TabOrder = 2 64 end 65 object Button1: TButton 14 object ButtonStart: TButton 66 15 Left = 247 67 16 Height = 37 … … 69 18 Width = 113 70 19 Caption = 'Start' 71 OnClick = Button 1Click20 OnClick = ButtonStartClick 72 21 ParentFont = False 73 TabOrder = 322 TabOrder = 0 74 23 end 75 object Button 2: TButton24 object ButtonStop: TButton 76 25 Left = 106 77 26 Height = 37 … … 79 28 Width = 113 80 29 Caption = 'Stop' 81 OnClick = Button 2Click30 OnClick = ButtonStopClick 82 31 ParentFont = False 32 TabOrder = 1 33 end 34 object ButtonConsole: TButton 35 Left = 44 36 Height = 38 37 Top = 37 38 Width = 113 39 Caption = 'Console' 40 OnClick = ButtonConsoleClick 41 TabOrder = 2 42 end 43 object ButtonMemory: TButton 44 Left = 46 45 Height = 38 46 Top = 86 47 Width = 113 48 Caption = 'Memory' 49 OnClick = ButtonMemoryClick 50 TabOrder = 3 51 end 52 object ButtonScreen: TButton 53 Left = 47 54 Height = 38 55 Top = 139 56 Width = 113 57 Caption = 'Screen' 58 OnClick = ButtonScreenClick 83 59 TabOrder = 4 84 60 end 85 object LabelTicks: TLabel 86 Left = 19 87 Height = 26 88 Top = 734 89 Width = 48 90 Caption = 'Ticks:' 91 ParentColor = False 92 ParentFont = False 61 object ButtonCpuState: TButton 62 Left = 44 63 Height = 38 64 Top = 192 65 Width = 113 66 Caption = 'CPU state' 67 OnClick = ButtonCpuStateClick 68 TabOrder = 5 69 end 70 object ButtonAssembler: TButton 71 Left = 358 72 Height = 38 73 Top = 48 74 Width = 169 75 Caption = 'Assembler' 76 OnClick = ButtonAssemblerClick 77 TabOrder = 6 78 end 79 object ButtonDisassembler: TButton 80 Left = 358 81 Height = 38 82 Top = 104 83 Width = 170 84 Caption = 'Disassembler' 85 OnClick = ButtonDisassemblerClick 86 TabOrder = 7 93 87 end 94 88 object Timer1: TTimer 95 89 Interval = 500 96 OnTimer = Timer1Timer97 90 left = 271 98 91 top = 810 -
branches/virtcpu varint/Forms/UFormMain.pas
r196 r197 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 StdCtrls, ExtCtrls, UMachine, UInstructionWriter ;9 StdCtrls, ExtCtrls, UMachine, UInstructionWriter, UCpu; 10 10 11 11 type … … 14 14 15 15 TFormMain = class(TForm) 16 Button1: TButton; 17 Button2: TButton; 18 LabelTicks: TLabel; 19 ListViewMemory: TListView; 20 ListViewRegisters: TListView; 21 Memo1: TMemo; 16 ButtonStart: TButton; 17 ButtonStop: TButton; 18 ButtonAssembler: TButton; 19 ButtonDisassembler: TButton; 20 ButtonCpuState: TButton; 21 ButtonScreen: TButton; 22 ButtonMemory: TButton; 23 ButtonConsole: TButton; 22 24 Timer1: TTimer; 23 procedure Button1Click(Sender: TObject); 24 procedure Button2Click(Sender: TObject); 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); 25 33 procedure FormCreate(Sender: TObject); 26 34 procedure FormDestroy(Sender: TObject); 27 procedure FormKeyPress(Sender: TObject; var Key: char);28 35 procedure FormShow(Sender: TObject); 29 procedure ListViewMemoryData(Sender: TObject; Item: TListItem);30 procedure ListViewRegistersData(Sender: TObject; Item: TListItem);31 procedure Memo1KeyPress(Sender: TObject; var Key: char);32 procedure Timer1Timer(Sender: TObject);33 36 private 34 KeyInputBuffer: array of Char;35 procedure ReloadMemoryDump;36 procedure ReloadRegisterDump;37 function CpuInput(Port: T): T;38 procedure CpuOutput(Port, Value: T);39 37 public 40 38 Machine: TMachine; … … 45 43 FormMain: TFormMain; 46 44 47 const48 ItemsPerLine = 16;49 50 45 51 46 implementation 52 47 53 48 {$R *.lfm} 49 50 uses 51 UFormConsole, UFormMemory, UFormScreen, UFormCpuState, UFormAssembler, 52 UFormDisassembler; 54 53 55 54 { TFormMain } … … 110 109 end; 111 110 112 procedure TFormMain.FormKeyPress(Sender: TObject; var Key: char);113 begin114 end;115 116 111 procedure TFormMain.FormCreate(Sender: TObject); 117 112 begin 118 113 Machine := TMachine.Create(nil); 119 Machine.Cpu.OnInput := CpuInput;120 Machine.Cpu.OnOutput := CpuOutput;121 114 InstructionWriter := TInstructionWriter.Create; 122 InstructionWriter.Cpu := Machine.Cpu;123 115 end; 124 116 125 procedure TFormMain.Button 1Click(Sender: TObject);117 procedure TFormMain.ButtonStartClick(Sender: TObject); 126 118 begin 127 119 Machine.Cpu.Start; 128 120 end; 129 121 130 procedure TFormMain.Button 2Click(Sender: TObject);122 procedure TFormMain.ButtonStopClick(Sender: TObject); 131 123 begin 132 124 Machine.Cpu.Stop; 133 125 end; 134 126 135 procedure TFormMain.ListViewMemoryData(Sender: TObject; Item: TListItem); 136 var 137 Line: string; 138 I: Integer; 127 procedure TFormMain.ButtonAssemblerClick(Sender: TObject); 139 128 begin 140 if Item.Index < Machine.MemorySize div ItemsPerLine then begin 141 Line := ''; 142 for I := 0 to ItemsPerLine - 1 do 143 Line := Line + IntToHex(PByte(NativeUInt(Machine.Memory) + Item.Index * ItemsPerLine + I)^, 2) + ' '; 144 Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8); 145 Item.SubItems.Add(Line); 146 end; 129 if not Assigned(FormAssembler) then 130 FormAssembler := TFormAssembler.Create(Self); 131 FormAssembler.Assembler.InstructionWriter.Memory := Machine.Memory; 132 FormAssembler.Show; 147 133 end; 148 134 149 procedure TFormMain. ListViewRegistersData(Sender: TObject; Item: TListItem);135 procedure TFormMain.ButtonConsoleClick(Sender: TObject); 150 136 begin 151 if Item.Index < Length(Machine.Cpu.Registers) + 1 then begin 152 if Item.Index = 0 then begin 153 Item.Caption := 'IP'; 154 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.IP), 8)); 155 end else 156 if Item.Index = 1 then begin 157 Item.Caption := 'SP'; 158 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.SP), 8)); 159 end else begin 160 Item.Caption := 'R' + IntToStr(Item.Index - 2); 161 Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.Registers[Item.Index - 2]), 8)); 162 end; 163 end; 137 if not Assigned(FormConsole) then 138 FormConsole := TFormConsole.Create(nil); 139 FormConsole.Machine := Machine; 140 FormConsole.Show; 164 141 end; 165 142 166 procedure TFormMain. Memo1KeyPress(Sender: TObject; var Key: char);143 procedure TFormMain.ButtonCpuStateClick(Sender: TObject); 167 144 begin 168 SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1); 169 KeyInputBuffer[High(KeyInputBuffer)] := Key; 145 if not Assigned(FormCpuState) then 146 FormCpuState := TFormCpuState.Create(Self); 147 FormCpuState.Machine := Machine; 148 FormCpuState.Show; 149 FormCpuState.Reload; 170 150 end; 171 151 172 procedure TFormMain. Timer1Timer(Sender: TObject);152 procedure TFormMain.ButtonDisassemblerClick(Sender: TObject); 173 153 begin 174 ReloadMemoryDump; 175 ReloadRegisterDump; 176 LabelTicks.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks); 154 if not Assigned(FormDisassembler) then 155 FormDisassembler := TFormDisassembler.Create(Self); 156 FormDisassembler.Disassembler.Cpu := Machine.Cpu; 157 FormDisassembler.Show; 158 FormDisassembler.Reload; 177 159 end; 178 160 179 procedure TFormMain. ReloadMemoryDump;161 procedure TFormMain.ButtonMemoryClick(Sender: TObject); 180 162 begin 181 ListViewMemory.Items.Count := Machine.MemorySize div ItemsPerLine; 182 ListViewMemory.Refresh; 163 if not Assigned(FormMemory) then 164 FormMemory := TFormMemory.Create(Self); 165 FormMemory.Machine := Machine; 166 FormMemory.Show; 167 FormMemory.Reload; 183 168 end; 184 169 185 procedure TFormMain. ReloadRegisterDump;170 procedure TFormMain.ButtonScreenClick(Sender: TObject); 186 171 begin 187 ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers); 188 ListViewRegisters.Refresh; 189 end; 190 191 function TFormMain.CpuInput(Port: T): T; 192 begin 193 Result := 0; 194 case Integer(Port) of 195 0: begin 196 while (Length(KeyInputBuffer) = 0) and not Machine.Cpu.Terminated do begin 197 Sleep(100); 198 Application.ProcessMessages; 199 end; 200 if Length(KeyInputBuffer) > 0 then begin 201 Result := Ord(KeyInputBuffer[0]); 202 if Length(KeyInputBuffer) > 1 then 203 Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1); 204 SetLength(KeyInputBuffer, Length(KeyInputBuffer) - 1); 205 end else Result := 0; 206 end; 207 end; 208 end; 209 210 procedure TFormMain.CpuOutput(Port, Value: T); 211 begin 212 case Integer(Port) of 213 0: Memo1.Lines.Text := Memo1.Lines.Text + Char(Value); 214 end; 172 if not Assigned(FormScreen) then 173 FormScreen := TFormScreen.Create(Self); 174 FormScreen.Machine := Machine; 175 FormScreen.Show; 176 FormScreen.Reload; 215 177 end; 216 178
Note:
See TracChangeset
for help on using the changeset viewer.