source: branches/virtcpu fixed int/UInstructionWriter.pas

Last change on this file was 215, checked in by chronos, 4 years ago
  • Added: TMachine class which contains CPU and peripherals.
  • Added: Execute TCpu inside background thread.
File size: 3.0 KB
Line 
1unit UInstructionWriter;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UCpu;
9
10type
11 { TInstructionWriter }
12
13 TInstructionWriter = class
14 private
15 public
16 Cpu: TCpu;
17 IP: T;
18 procedure Write(Value: T);
19 procedure NoOperation;
20 procedure Load(R1, R2: Integer);
21 procedure Halt;
22 procedure LoadConst(R, Value: Integer);
23 procedure LoadMemory(R1, R2: Integer);
24 procedure StoreMemory(R1, R2: Integer);
25 procedure Neg(R: Integer);
26 procedure Input(R1, R2: Integer);
27 procedure Output(R1, R2: Integer);
28 procedure Subtract(R1, R2: Integer);
29 procedure Jump(Addr: Integer);
30 procedure JumpCond(Addr: Integer);
31 procedure TestZero(R: Integer);
32 {$IFDEF EXT_REL_JUMP}procedure JumpRelative(Addr: Integer);{$ENDIF}
33 procedure SysCall;
34 procedure Increment(R: Integer);
35 procedure Decrement(R: Integer);
36 constructor Create;
37 end;
38
39
40implementation
41
42{ TInstructionWriter }
43
44procedure TInstructionWriter.NoOperation;
45begin
46 Write(T(opNop));
47end;
48
49procedure TInstructionWriter.Load(R1, R2: Integer);
50begin
51 Write(T(opLoad));
52 Write(R1);
53 Write(R2);
54end;
55
56procedure TInstructionWriter.Halt;
57begin
58 Write(T(opHalt));
59end;
60
61procedure TInstructionWriter.LoadConst(R, Value: Integer);
62begin
63 Write(T(opLoadConst));
64 Write(R);
65 Write(Value);
66end;
67
68procedure TInstructionWriter.LoadMemory(R1, R2: Integer);
69begin
70 Write(T(opLoadMem));
71 Write(R1);
72 Write(R2);
73end;
74
75procedure TInstructionWriter.StoreMemory(R1, R2: Integer);
76begin
77 Write(T(opStoreMem));
78 Write(R1);
79 Write(R2);
80end;
81
82procedure TInstructionWriter.Neg(R: Integer);
83begin
84 Write(T(opNeg));
85 Write(R);
86end;
87
88procedure TInstructionWriter.Input(R1, R2: Integer);
89begin
90 Write(T(opInput));
91 Write(R1);
92 Write(R2);
93end;
94
95procedure TInstructionWriter.Output(R1, R2: Integer);
96begin
97 Write(T(opOutput));
98 Write(R1);
99 Write(R2);
100end;
101
102procedure TInstructionWriter.Subtract(R1, R2: Integer);
103begin
104 Write(T(opSub));
105 Write(R1);
106 Write(R2);
107end;
108
109procedure TInstructionWriter.Jump(Addr: Integer);
110begin
111 Write(T(opJump));
112 Write(Addr);
113end;
114
115procedure TInstructionWriter.JumpCond(Addr: Integer);
116begin
117 Write(T(opJumpCond));
118 Write(Addr);
119end;
120
121procedure TInstructionWriter.TestZero(R: Integer);
122begin
123 Write(T(opTestZero));
124 Write(R);
125end;
126
127procedure TInstructionWriter.SysCall;
128begin
129 Write(T(opSysCall));
130end;
131
132{$IFDEF EXT_REL_JUMP}
133procedure TInstructionWriter.JumpRelative(Addr: Integer);
134begin
135 Write(T(opJumpRel));
136 Write(Addr - IP - 1);
137end;
138{$ENDIF}
139
140procedure TInstructionWriter.Increment(R: Integer);
141begin
142 Write(T(opInc));
143 Write(R);
144end;
145
146procedure TInstructionWriter.Decrement(R: Integer);
147begin
148 Write(T(opDec));
149 Write(R);
150end;
151
152constructor TInstructionWriter.Create;
153begin
154 IP := 0;
155 Cpu := nil;
156end;
157
158procedure TInstructionWriter.Write(Value: T);
159begin
160 Cpu.Memory[IP] := Value;
161 Inc(IP);
162end;
163
164
165end.
166
Note: See TracBrowser for help on using the repository browser.