Changeset 89 for branches/virt simple/UMachine.pas
- Timestamp:
- Sep 30, 2016, 10:13:35 PM (8 years ago)
- Location:
- branches/virt simple
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virt simple
-
Property svn:ignore
set to
lib
project1
project1.lps
-
Property svn:ignore
set to
-
branches/virt simple/UMachine.pas
r88 r89 63 63 TSystemCallEvent = procedure(Index: TValue) of object; 64 64 65 TMachineThread = class; 66 65 67 { TMachine } 66 68 … … 70 72 FOnPortOut: TPortOutEvent; 71 73 FOnSystemCall: TSystemCallEvent; 74 FRunning: Boolean; 72 75 InstructionHandlers: array[TOpcode] of TInstructionHandler; 76 Thread: TMachineThread; 73 77 function GetValue(Param: TParam): TValue; 74 78 procedure InstructionAdd; … … 103 107 procedure Init(MemorySize, RegisterCount: Integer); 104 108 procedure Run; 109 procedure Start; 110 procedure Stop; 105 111 constructor Create; 106 112 destructor Destroy; override; 113 property Running: Boolean read FRunning; 107 114 property OnPortOut: TPortOutEvent read FOnPortOut write FOnPortOut; 108 115 property OnPortIn: TPortInEvent read FOnPortIn write FOnPortIn; … … 110 117 end; 111 118 119 { TMachineThread } 120 121 TMachineThread = class(TThread) 122 Machine: TMachine; 123 procedure Execute; override; 124 end; 125 112 126 113 127 implementation 128 129 { TMachineThread } 130 131 procedure TMachineThread.Execute; 132 begin 133 Machine.Run; 134 end; 114 135 115 136 … … 369 390 begin 370 391 while not Terminated do begin 371 with TInstruction(Instructions[IP]) do 372 if Assigned(InstructionHandlers[Opcode]) then 373 InstructionHandlers[Opcode] 374 else raise Exception.Create('Unsupported instruction opcode ' + OpcodeString[Opcode]); 392 if IP < Instructions.Count then begin 393 with TInstruction(Instructions[IP]) do 394 if Assigned(InstructionHandlers[Opcode]) then 395 InstructionHandlers[Opcode] 396 else raise Exception.Create('Unsupported instruction opcode ' + OpcodeString[Opcode]); 397 end else raise Exception.Create('Reached end of program memory'); 375 398 Inc(IP); 399 end; 400 end; 401 402 procedure TMachine.Start; 403 begin 404 if not Running then begin 405 Terminated := False; 406 Thread := TMachineThread.Create(True); 407 Thread.Machine := Self; 408 Thread.Start; 409 FRunning := True; 410 end; 411 end; 412 413 procedure TMachine.Stop; 414 begin 415 if Running then begin 416 Terminated := True; 417 Thread.Terminate; 418 Thread.WaitFor; 419 FreeAndNil(Thread); 420 FRunning := False; 376 421 end; 377 422 end;
Note:
See TracChangeset
for help on using the changeset viewer.