Changeset 174 for branches/virtualcpu4/UFormMain.pas
- Timestamp:
- Apr 12, 2019, 12:06:05 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UFormMain.pas
r173 r174 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, 9 ComCtrls, UCpu, U InstructionWriter, syncobjs;9 ComCtrls, UCpu, UMachine, UInstructionWriter, syncobjs; 10 10 11 11 type … … 32 32 procedure Timer1Timer(Sender: TObject); 33 33 private 34 InputBuffer: string;35 OutputBuffer: string;36 Lock: TCriticalSection;37 function CpuInput(Port: TAddress): TRegister;38 procedure CpuOutput(Port: TAddress; Value: TRegister);39 34 procedure ReloadMemoryDump; 40 35 procedure ReloadRegisterDump; 41 36 procedure LoadProgram; 42 37 public 43 Cpu: TCpu;38 Machine: TMachine; 44 39 InstructionWriter: TInstructionWriter; 45 40 end; … … 59 54 procedure TFormMain.ButtonStartClick(Sender: TObject); 60 55 begin 61 Cpu.Start;56 Machine.Cpu.Start; 62 57 end; 63 58 64 59 procedure TFormMain.ButtonStopClick(Sender: TObject); 65 60 begin 66 Cpu.Stop;61 Machine.Cpu.Stop; 67 62 end; 68 63 69 64 procedure TFormMain.FormCreate(Sender: TObject); 70 65 begin 71 Lock := TCriticalSection.Create; 72 Cpu := TCpu.Create; 73 Cpu.OnInput := CpuInput; 74 Cpu.OnOutput := CpuOutput; 75 Cpu.DataSize := bw16; 76 Cpu.AddressSize := bw16; 66 Machine := TMachine.Create; 77 67 InstructionWriter := TInstructionWriter.Create; 78 InstructionWriter.Cpu := Cpu;68 InstructionWriter.Cpu := Machine.Cpu; 79 69 end; 80 70 … … 82 72 begin 83 73 InstructionWriter.Free; 84 Cpu.Free; 85 Lock.Free; 74 Machine.Free; 86 75 end; 87 76 … … 96 85 I: Integer; 97 86 begin 98 if Item.Index < Length( Cpu.Memory) div ItemsPerLine then begin87 if Item.Index < Length(Machine.Memory) div ItemsPerLine then begin 99 88 Line := ''; 100 89 for I := 0 to ItemsPerLine - 1 do 101 Line := Line + IntToHex( Cpu.Memory[Item.Index * ItemsPerLine + I], 2) + ' ';90 Line := Line + IntToHex(Machine.Memory[Item.Index * ItemsPerLine + I], 2) + ' '; 102 91 Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8); 103 92 Item.SubItems.Add(Line); … … 107 96 procedure TFormMain.ListViewRegistersData(Sender: TObject; Item: TListItem); 108 97 begin 109 if Item.Index < Length( Cpu.Registers) + 2 then begin98 if Item.Index < Length(Machine.Cpu.Registers) + 2 then begin 110 99 if Item.Index = 0 then begin 111 100 Item.Caption := 'IP'; 112 Item.SubItems.Add(IntToHex( Cpu.IP, 16));101 Item.SubItems.Add(IntToHex(Machine.Cpu.IP, 16)); 113 102 end else 114 103 if Item.Index = 1 then begin 115 104 Item.Caption := 'SP'; 116 Item.SubItems.Add(IntToHex( Cpu.SP, 16));105 Item.SubItems.Add(IntToHex(Machine.Cpu.SP, 16)); 117 106 end else begin 118 107 Item.Caption := 'R' + IntToStr(Item.Index - 2); 119 Item.SubItems.Add(IntToHex( Cpu.Registers[Item.Index - 2].D, 16));108 Item.SubItems.Add(IntToHex(Machine.Cpu.Registers[Item.Index - 2].D, 16)); 120 109 end; 121 110 end; … … 124 113 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char); 125 114 begin 126 Lock.Acquire;127 InputBuffer :=InputBuffer + Key;128 Lock.Release;115 Machine.LockInput.Acquire; 116 Machine.InputBuffer := Machine.InputBuffer + Key; 117 Machine.LockInput.Release; 129 118 end; 130 119 131 120 procedure TFormMain.Timer1Timer(Sender: TObject); 132 121 begin 133 Label1.Caption := 'Ticks: ' + IntToStr( Cpu.Ticks);122 Label1.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks); 134 123 ReloadMemoryDump; 135 124 ReloadRegisterDump; 136 Lock.Acquire;137 Memo1.Lines.Text := Memo1.Lines.Text + OutputBuffer;138 SetLength( OutputBuffer, 0);139 Lock.Release;125 Machine.LockOutput.Acquire; 126 Memo1.Lines.Text := Memo1.Lines.Text + Machine.OutputBuffer; 127 SetLength(Machine.OutputBuffer, 0); 128 Machine.LockOutput.Release; 140 129 end; 141 130 142 131 procedure TFormMain.ReloadMemoryDump; 143 132 begin 144 ListViewMemory.Items.Count := Length( Cpu.Memory) div ItemsPerLine;133 ListViewMemory.Items.Count := Length(Machine.Memory) div ItemsPerLine; 145 134 ListViewMemory.Refresh; 146 135 end; … … 148 137 procedure TFormMain.ReloadRegisterDump; 149 138 begin 150 ListViewRegisters.Items.Count := Length( Cpu.Registers);139 ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers); 151 140 ListViewRegisters.Refresh; 152 141 end; … … 190 179 end; 191 180 192 function TFormMain.CpuInput(Port: TAddress): TRegister;193 begin194 Result.Q := 0;195 case Port of196 0: begin197 Lock.Acquire;198 while (Length(InputBuffer) = 0) and not Cpu.Terminated do begin199 Lock.Release;200 Sleep(100);201 Lock.Acquire;202 end;203 if Length(InputBuffer) > 0 then begin204 Result.B := Ord(InputBuffer[1]);205 Delete(InputBuffer, 1, 1);206 end else Result.B := 0;207 Lock.Release;208 end;209 end;210 end;211 212 procedure TFormMain.CpuOutput(Port: TAddress; Value: TRegister);213 begin214 case Port of215 0: begin216 Lock.Acquire;217 OutputBuffer := OutputBuffer + Char(Value.B);218 Lock.Release;219 end;220 end;221 end;222 223 224 225 181 end. 226 182
Note:
See TracChangeset
for help on using the changeset viewer.