Changeset 89
- Timestamp:
- Sep 30, 2016, 10:13:35 PM (8 years ago)
- Location:
- branches/virt simple
- Files:
-
- 6 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/UCompiler.pas
r88 r89 53 53 OutValue: Integer; 54 54 begin 55 Line := Trim(Line); 56 // Strip comments 57 if Pos(';', Line) > 0 then begin 58 Line := Trim(Copy(Line, 1, Pos(';', Line) - 1)); 59 end; 60 if Line = '' then Exit; 55 61 Name := Trim(GetPart(Line, ' ')); 56 62 OpcodeIndex := GetOpcodeFromName(Name); -
branches/virt simple/UFormMain.lfm
r88 r89 150 150 Top = 31 151 151 Width = 502 152 Font.Name = 'Liberation Mono' 153 ParentFont = False 152 154 ScrollBars = ssAutoBoth 153 155 TabOrder = 5 … … 164 166 Left = 532 165 167 Height = 25 166 Top = 7 59168 Top = 760 167 169 Width = 100 168 170 Caption = 'Compile' 169 171 OnClick = ButtonCompileClick 170 172 TabOrder = 6 173 end 174 object ButtonStart: TButton 175 Left = 664 176 Height = 25 177 Top = 760 178 Width = 100 179 Caption = 'Start' 180 OnClick = ButtonStartClick 181 TabOrder = 7 182 end 183 object ButtonStop: TButton 184 Left = 784 185 Height = 25 186 Top = 760 187 Width = 100 188 Caption = 'Stop' 189 OnClick = ButtonStopClick 190 TabOrder = 8 171 191 end 172 192 object Timer1: TTimer … … 176 196 top = 205 177 197 end 198 object ActionList1: TActionList 199 left = 1051 200 top = 808 201 object ASave: TAction 202 Caption = 'Save' 203 OnExecute = ASaveExecute 204 ShortCut = 16467 205 end 206 end 178 207 end -
branches/virt simple/UFormMain.pas
r88 r89 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, 9 ExtCtrls, StdCtrls, fgl, UMachine, UBigInt, UCompiler;9 ExtCtrls, StdCtrls, ActnList, fgl, UMachine, UBigInt, UCompiler; 10 10 11 11 type 12 12 13 { TMachineThread }14 15 TMachineThread = class(TThread)16 Machine: TMachine;17 procedure Execute; override;18 end;19 20 13 { TForm1 } 21 14 22 15 TForm1 = class(TForm) 16 ASave: TAction; 17 ActionList1: TActionList; 23 18 ButtonCompile: TButton; 19 ButtonStart: TButton; 20 ButtonStop: TButton; 24 21 Label1: TLabel; 25 22 Label2: TLabel; … … 35 32 MemoOutput: TMemo; 36 33 Timer1: TTimer; 34 procedure ASaveExecute(Sender: TObject); 37 35 procedure ButtonCompileClick(Sender: TObject); 36 procedure ButtonStartClick(Sender: TObject); 37 procedure ButtonStopClick(Sender: TObject); 38 38 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 39 39 procedure FormCreate(Sender: TObject); … … 46 46 procedure Timer1Timer(Sender: TObject); 47 47 private 48 MachineThread: TMachineThread;49 48 Console: string; 50 49 procedure ReloadMemory; 51 50 procedure DoSystemCall(Index: Integer); 51 procedure UpdateInterface; 52 52 public 53 53 Machine: TMachine; … … 65 65 {$R *.lfm} 66 66 67 { TMachineThread }68 69 procedure TMachineThread.Execute;70 begin71 Machine.Run;72 end;73 74 67 { TForm1 } 75 68 … … 83 76 procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); 84 77 begin 85 Machine.Terminated := True; 86 MachineThread.WaitFor; 87 MemoSource.Lines.SaveToFile(DefaultFileName); 78 Machine.Stop; 79 ASave.Execute; 88 80 end; 89 81 … … 94 86 end; 95 87 88 procedure TForm1.ASaveExecute(Sender: TObject); 89 begin 90 MemoSource.Lines.SaveToFile(DefaultFileName); 91 end; 92 93 procedure TForm1.ButtonStartClick(Sender: TObject); 94 begin 95 Machine.Start; 96 UpdateInterface; 97 end; 98 99 procedure TForm1.ButtonStopClick(Sender: TObject); 100 begin 101 Machine.Stop; 102 UpdateInterface; 103 end; 104 96 105 procedure TForm1.FormDestroy(Sender: TObject); 97 106 begin … … 104 113 MemoSource.Lines.LoadFromFile(DefaultFileName); 105 114 ReloadMemory; 115 UpdateInterface; 106 116 with Machine do begin 107 117 Init(32000, 16); 108 with Instructions do begin118 { with Instructions do begin 109 119 AddInst(opNoOperation); 110 120 AddInst(opIncrement, ptRegister, False, 0); … … 122 132 AddInst(opHalt); 123 133 end; 124 MachineThread := TMachineThread.Create(True); 125 MachineThread.Machine := Machine; 126 MachineThread.Start; 134 } 127 135 end; 128 136 end; … … 200 208 end; 201 209 210 procedure TForm1.UpdateInterface; 211 begin 212 ButtonStart.Enabled := not Machine.Running; 213 ButtonStop.Enabled := Machine.Running; 214 end; 215 202 216 end. 203 217 -
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; -
branches/virt simple/example.vasm
r88 r89 6 6 PUSH -1 7 7 POP [10] 8 JR 0 8 LD R0, 65 9 SYS 0 ; Output character 10 LD R0, 1000 11 SYS 2 ; Delay 1 second 12 JP 0 9 13 LD [R4], [R3] 10 14 HALT
Note:
See TracChangeset
for help on using the changeset viewer.