Changeset 172 for branches/virtualcpu4/UFormMain.pas
- Timestamp:
- Apr 10, 2019, 11:49:27 PM (6 years ago)
- Location:
- branches/virtualcpu4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4
- Property svn:ignore
-
old new 1 1 lib 2 2 virtucpu4.exe 3 virtucpu4 3 4 *.lps 4 5 *.res
-
- Property svn:ignore
-
branches/virtualcpu4/UFormMain.pas
r171 r172 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, 9 ComCtrls, UCpu, UInstructionWriter ;9 ComCtrls, UCpu, UInstructionWriter, syncobjs; 10 10 11 11 type … … 32 32 procedure Timer1Timer(Sender: TObject); 33 33 private 34 KeyInputBuffer: array of Char; 34 InputBuffer: string; 35 OutputBuffer: string; 36 Lock: TCriticalSection; 35 37 function CpuInput(Port: TAddress): TRegister; 36 38 procedure CpuOutput(Port: TAddress; Value: TRegister); … … 67 69 procedure TFormMain.FormCreate(Sender: TObject); 68 70 begin 71 Lock := TCriticalSection.Create; 69 72 Cpu := TCpu.Create; 70 73 Cpu.OnInput := CpuInput; … … 80 83 InstructionWriter.Free; 81 84 Cpu.Free; 85 Lock.Free; 82 86 end; 83 87 … … 120 124 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char); 121 125 begin 122 SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1); 123 KeyInputBuffer[High(KeyInputBuffer)] := Key; 126 Lock.Acquire; 127 InputBuffer := InputBuffer + Key; 128 Lock.Release; 124 129 end; 125 130 … … 129 134 ReloadMemoryDump; 130 135 ReloadRegisterDump; 136 Lock.Acquire; 137 Memo1.Lines.Text := Memo1.Lines.Text + OutputBuffer; 138 SetLength(OutputBuffer, 0); 139 Lock.Release; 131 140 end; 132 141 … … 186 195 case Port of 187 196 0: begin 188 while (Length(KeyInputBuffer) = 0) and not Cpu.Terminated do begin 197 Lock.Acquire; 198 while (Length(InputBuffer) = 0) and not Cpu.Terminated do begin 199 Lock.Release; 189 200 Sleep(100); 201 Lock.Acquire; 190 202 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); 203 if Length(InputBuffer) > 0 then begin 204 Result.B := Ord(InputBuffer[1]); 205 Delete(InputBuffer, 1, 1); 196 206 end else Result.B := 0; 207 Lock.Release; 197 208 end; 198 209 end; … … 202 213 begin 203 214 case Port of 204 0: Memo1.Lines.Text := Memo1.Lines.Text + Char(Value.B); 215 0: begin 216 Lock.Acquire; 217 OutputBuffer := OutputBuffer + Char(Value.B); 218 Lock.Release; 219 end; 205 220 end; 206 221 end;
Note:
See TracChangeset
for help on using the changeset viewer.