source: branches/configured machine/CpuBitWidth.pas

Last change on this file was 239, checked in by chronos, 16 months ago
File size: 5.8 KB
Line 
1unit CpuBitWidth;
2
3interface
4
5uses
6 Classes, SysUtils, AddressableArea;
7
8type
9 TInstruction = (inNop, inHalt,
10 inLoad1, inLoad2, inLoad4, inLoad8,
11 inLoadMem1, inLoadMem2, inLoadMem4, inLoadMem8,
12 inStoreMem1, inStoreMem2, inStoreMem4, inStoreMem8,
13 inInput1, inInput2, inInput4, inInput8,
14 inOutput1, inOutput2, inOutput4, inOutput8);
15
16 { TCpuBitWidth1 }
17
18 TCpuBitWidth1 = class
19 Memory: TAddressableArea1;
20 IO: TAddressableArea1;
21 Halted: Boolean;
22 PC: Byte;
23 A: Byte;
24 function Read1: Byte;
25 procedure Write1(Data: Byte);
26 procedure Reset;
27 procedure Run;
28 procedure Step;
29 end;
30
31 { TCpuBitWidth2 }
32
33 TCpuBitWidth2 = class
34 Memory: TAddressableArea2;
35 IO: TAddressableArea2;
36 Halted: Boolean;
37 PC: Word;
38 A: Word;
39 function Read1: Byte;
40 function Read2: Word;
41 procedure Write1(Data: Byte);
42 procedure Write2(Data: Word);
43 procedure Reset;
44 procedure Run;
45 procedure Step;
46 end;
47
48 { TCpuBitWidth4 }
49
50 TCpuBitWidth4 = class
51 Memory: TAddressableArea4;
52 IO: TAddressableArea4;
53 Halted: Boolean;
54 PC: Cardinal;
55 A: Cardinal;
56 function Read1: Byte;
57 function Read2: Word;
58 function Read4: Cardinal;
59 procedure Reset;
60 procedure Run;
61 procedure Step;
62 end;
63
64 { TCpuBitWidth8 }
65
66 TCpuBitWidth8 = class
67 Memory: TAddressableArea8;
68 IO: TAddressableArea8;
69 Halted: Boolean;
70 PC: DWord;
71 A: DWord;
72 function Read1: Byte;
73 function Read2: Word;
74 function Read4: Cardinal;
75 function Read8: DWord;
76 procedure Reset;
77 procedure Run;
78 procedure Step;
79 end;
80
81implementation
82
83{ TCpuBitWidth4 }
84
85function TCpuBitWidth4.Read1: Byte;
86begin
87 Result := Memory.Read1(PC);
88 Inc(PC);
89end;
90
91function TCpuBitWidth4.Read2: Word;
92begin
93 Result := Memory.Read2(PC);
94 Inc(PC, 2);
95end;
96
97function TCpuBitWidth4.Read4: Cardinal;
98begin
99 Result := Memory.Read4(PC);
100 Inc(PC, 4);
101end;
102
103procedure TCpuBitWidth4.Reset;
104begin
105 PC := 0;
106 A := 0;
107end;
108
109procedure TCpuBitWidth4.Run;
110begin
111 Reset;
112 while not Halted do
113 Step;
114end;
115
116procedure TCpuBitWidth4.Step;
117var
118 Opcode: TInstruction;
119begin
120 Opcode := TInstruction(Read1);
121 case Opcode of
122 inNop: ;
123 inHalt: Halted := True;
124 inLoad1: A := Read1;
125 inLoad2: A := Read2;
126 inLoad4: A := Read4;
127 inLoadMem1: A := Memory.Read1(Read4);
128 inLoadMem2: A := Memory.Read2(Read4);
129 inLoadMem4: A := Memory.Read4(Read4);
130 inStoreMem1: Memory.Write1(Read4, A);
131 inStoreMem2: Memory.Write2(Read4, A);
132 inStoreMem4: Memory.Write4(Read4, A);
133 inInput1: A := IO.Read1(Read4);
134 inInput2: A := IO.Read2(Read4);
135 inInput4: A := IO.Read4(Read4);
136 inOutput1: IO.Write1(Read4, A);
137 inOutput2: IO.Write2(Read4, A);
138 inOutput4: IO.Write4(Read4, A);
139 end;
140end;
141
142{ TCpuBitWidth2 }
143
144function TCpuBitWidth2.Read1: Byte;
145begin
146 Result := Memory.Read1(PC);
147 Inc(PC);
148end;
149
150function TCpuBitWidth2.Read2: Word;
151begin
152 Result := Memory.Read2(PC);
153 Inc(PC, 2);
154end;
155
156procedure TCpuBitWidth2.Write1(Data: Byte);
157begin
158 Memory.Write1(PC, Data);
159 Inc(PC);
160end;
161
162procedure TCpuBitWidth2.Write2(Data: Word);
163begin
164 Memory.Write2(PC, Data);
165 Inc(PC, 2);
166end;
167
168procedure TCpuBitWidth2.Reset;
169begin
170 PC := 0;
171 A := 0;
172end;
173
174procedure TCpuBitWidth2.Run;
175begin
176 Reset;
177 while not Halted do
178 Step;
179end;
180
181procedure TCpuBitWidth2.Step;
182var
183 Opcode: TInstruction;
184begin
185 Opcode := TInstruction(Read1);
186 case Opcode of
187 inNop: ;
188 inHalt: Halted := True;
189 inLoad1: A := Read1;
190 inLoad2: A := Read2;
191 inLoadMem1: A := Memory.Read1(Read2);
192 inLoadMem2: A := Memory.Read2(Read2);
193 inStoreMem1: Memory.Write1(Read2, A);
194 inStoreMem2: Memory.Write2(Read2, A);
195 inInput1: A := IO.Read1(Read2);
196 inInput2: A := IO.Read2(Read2);
197 inOutput1: IO.Write1(Read2, A);
198 inOutput2: IO.Write2(Read2, A);
199 end;
200end;
201
202{ TCpuBitWidth8 }
203
204function TCpuBitWidth8.Read1: Byte;
205begin
206 Result := Memory.Read1(PC);
207 Inc(PC);
208end;
209
210function TCpuBitWidth8.Read2: Word;
211begin
212 Result := Memory.Read2(PC);
213 Inc(PC, 2);
214end;
215
216function TCpuBitWidth8.Read4: Cardinal;
217begin
218 Result := Memory.Read4(PC);
219 Inc(PC, 4);
220end;
221
222function TCpuBitWidth8.Read8: DWord;
223begin
224 Result := Memory.Read8(PC);
225 Inc(PC, 8);
226end;
227
228procedure TCpuBitWidth8.Reset;
229begin
230 PC := 0;
231 A := 0;
232end;
233
234procedure TCpuBitWidth8.Run;
235begin
236 Reset;
237 while not Halted do
238 Step;
239end;
240
241procedure TCpuBitWidth8.Step;
242var
243 Opcode: TInstruction;
244begin
245 Opcode := TInstruction(Read1);
246 case Opcode of
247 inNop: ;
248 inHalt: Halted := True;
249 inLoad1: A := Read1;
250 inLoad2: A := Read2;
251 inLoad4: A := Read4;
252 inLoad8: A := Read8;
253 inLoadMem1: A := Memory.Read1(Read8);
254 inLoadMem2: A := Memory.Read2(Read8);
255 inLoadMem4: A := Memory.Read4(Read8);
256 inLoadMem8: A := Memory.Read8(Read8);
257 inStoreMem1: Memory.Write1(Read8, A);
258 inStoreMem2: Memory.Write2(Read8, A);
259 inStoreMem4: Memory.Write4(Read8, A);
260 inStoreMem8: Memory.Write8(Read8, A);
261 inInput1: A := IO.Read1(Read8);
262 inInput2: A := IO.Read2(Read8);
263 inInput4: A := IO.Read4(Read8);
264 inInput8: A := IO.Read8(Read8);
265 inOutput1: IO.Write1(Read8, A);
266 inOutput2: IO.Write2(Read8, A);
267 inOutput4: IO.Write4(Read8, A);
268 inOutput8: IO.Write8(Read8, A);
269 end;
270end;
271
272{ TCpuBitWidth1 }
273
274function TCpuBitWidth1.Read1: Byte;
275begin
276 Result := Memory.Read1(PC);
277 Inc(PC);
278end;
279
280procedure TCpuBitWidth1.Write1(Data: Byte);
281begin
282 Memory.Write1(PC, Data);
283 Inc(PC);
284end;
285
286procedure TCpuBitWidth1.Reset;
287begin
288 PC := 0;
289 A := 0;
290end;
291
292procedure TCpuBitWidth1.Run;
293begin
294 Reset;
295 while not Halted do
296 Step;
297end;
298
299procedure TCpuBitWidth1.Step;
300var
301 Opcode: TInstruction;
302begin
303 Opcode := TInstruction(Read1);
304 case Opcode of
305 inNop: ;
306 inHalt: Halted := True;
307 inLoad1: A := Read1;
308 inLoadMem1: A := Memory.Read1(Read1);
309 inStoreMem1: Memory.Write1(Read1, A);
310 inInput1: A := IO.Read1(Read1);
311 inOutput1: IO.Write1(Read1, A);
312 end;
313end;
314
315end.
316
Note: See TracBrowser for help on using the repository browser.