1 | unit Cpu;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Memory;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TBitWidth = (bw8, bw16, bw32, bw64, bw128, bw256, bw512, bw1024);
|
---|
10 |
|
---|
11 | TOpcode = (opNop, opHalt, opLoadMem, opStoreMem, opIncrement, opDecrement,
|
---|
12 | opJump, opPush, opPop, opCall, opReturn, opInput, opOutput, opAdd,
|
---|
13 | opSubtract, opLoad,
|
---|
14 | opDataWidth8, opDataWidth16, opAddressWidth8, opAddressWidth16);
|
---|
15 |
|
---|
16 | { TValue }
|
---|
17 |
|
---|
18 | TValue = record
|
---|
19 | class function Create8(Value: Byte): TValue; static;
|
---|
20 | class function Create16(Value: Word): TValue; static;
|
---|
21 | class function Create32(Value: DWord): TValue; static;
|
---|
22 | class function Create64(Value: QWord): TValue; static;
|
---|
23 | case TBitWidth of
|
---|
24 | bw8: (Value8: Byte);
|
---|
25 | bw16: (Value16: Word);
|
---|
26 | bw32: (Value32: DWord);
|
---|
27 | bw64: (Value64: QWord);
|
---|
28 | end;
|
---|
29 |
|
---|
30 | TSignedValue = record
|
---|
31 | case TBitWidth of
|
---|
32 | bw8: (Value8: ShortInt);
|
---|
33 | bw16: (Value16: SmallInt);
|
---|
34 | bw32: (Value32: LongInt);
|
---|
35 | bw64: (Value64: Int64);
|
---|
36 | end;
|
---|
37 |
|
---|
38 | { TCpu }
|
---|
39 |
|
---|
40 | TCpu = class
|
---|
41 | private
|
---|
42 | FAddress: TValue;
|
---|
43 | FAddressWidth: TBitWidth;
|
---|
44 | FDataWidth: TBitWidth;
|
---|
45 | FFrequency: Integer;
|
---|
46 | FOnOutput: TNotifyEvent;
|
---|
47 | FOnInput: TNotifyEvent;
|
---|
48 | FOnRead: TNotifyEvent;
|
---|
49 | FOnWrite: TNotifyEvent;
|
---|
50 | function GetFrequency: Integer;
|
---|
51 | procedure SetAddressWidth(AValue: TBitWidth);
|
---|
52 | procedure SetFrequency(AValue: Integer);
|
---|
53 | procedure SetDataWidth(AValue: TBitWidth);
|
---|
54 | procedure Push(Data: TValue; BitWidth: TBitWidth);
|
---|
55 | procedure Pop(var Data: TValue; BitWidth: TBitWidth);
|
---|
56 | procedure DoRead;
|
---|
57 | procedure DoWrite;
|
---|
58 | procedure DoInput;
|
---|
59 | procedure DoOutput;
|
---|
60 | public
|
---|
61 | IP: TValue;
|
---|
62 | SP: TValue;
|
---|
63 | A: TValue;
|
---|
64 | Terminated: Boolean;
|
---|
65 | Data: TValue;
|
---|
66 | procedure Reset;
|
---|
67 | procedure Step;
|
---|
68 | procedure Run;
|
---|
69 | constructor Create;
|
---|
70 | destructor Destroy; override;
|
---|
71 | procedure AssignValue(var Dest: TValue; Source: TValue; Width: TBitWidth);
|
---|
72 | procedure ReadD8A8(var AAddress: TValue; var AData: TValue; Increment: Boolean);
|
---|
73 | procedure ReadD8A16(var AAddress: TValue; var AData: TValue; Increment: Boolean);
|
---|
74 | procedure ReadD16A8(var AAddress: TValue; var AData: TValue; Increment: Boolean);
|
---|
75 | procedure ReadD16A16(var AAddress: TValue; var AData: TValue; Increment: Boolean);
|
---|
76 | procedure Read(var Address: TValue; var Data: TValue; Increment: Boolean;
|
---|
77 | AddressWidth: TBitWidth; DataWidth: TBitWidth);
|
---|
78 | procedure ReadAddressA8(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
79 | procedure ReadAddressA16(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
80 | procedure ReadDataA8(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
81 | procedure ReadDataA16(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
82 | procedure ReadData(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
83 | procedure ReadAddress(var Address: TValue; var Data: TValue; Increment: Boolean);
|
---|
84 | procedure WriteD8A8(var Address: TValue; AData: TValue; Increment: Boolean);
|
---|
85 | procedure WriteD8A16(var Address: TValue; AData: TValue; Increment: Boolean);
|
---|
86 | procedure WriteD16A8(var Address: TValue; AData: TValue; Increment: Boolean);
|
---|
87 | procedure WriteD16A16(var Address: TValue; AData: TValue; Increment: Boolean);
|
---|
88 | procedure Write(var Address: TValue; Data: TValue; Increment: Boolean;
|
---|
89 | AddressWidth: TBitWidth; DataWidth: TBitWidth);
|
---|
90 | procedure WriteAddressA8(var Address: TValue; Data: TValue; Increment: Boolean);
|
---|
91 | procedure WriteAddressA16(var Address: TValue; Data: TValue; Increment: Boolean);
|
---|
92 | procedure WriteDataA8(var Address: TValue; Data: TValue; Increment: Boolean);
|
---|
93 | procedure WriteDataA16(var Address: TValue; Data: TValue; Increment: Boolean);
|
---|
94 | procedure WriteData(var Address: TValue; Value: TValue; Increment: Boolean);
|
---|
95 | procedure WriteAddress(var Address: TValue; Value: TValue; Increment: Boolean);
|
---|
96 | property Frequency: Integer read FFrequency write FFrequency;
|
---|
97 | property DataWidth: TBitWidth read FDataWidth write SetDataWidth;
|
---|
98 | property Address: TValue read FAddress;
|
---|
99 | property AddressWidth: TBitWidth read FAddressWidth write SetAddressWidth;
|
---|
100 | property OnInput: TNotifyEvent read FOnInput write FOnInput;
|
---|
101 | property OnOutput: TNotifyEvent read FOnOutput write FOnOutput;
|
---|
102 | property OnRead: TNotifyEvent read FOnRead write FOnRead;
|
---|
103 | property OnWrite: TNotifyEvent read FOnWrite write FOnWrite;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | const
|
---|
107 | BitWidthByteSize: array[TBitWidth] of Byte = (1, 2, 4, 8, 16, 32, 64, 128);
|
---|
108 |
|
---|
109 |
|
---|
110 | implementation
|
---|
111 |
|
---|
112 | { TValue }
|
---|
113 |
|
---|
114 | class function TValue.Create8(Value: Byte): TValue;
|
---|
115 | begin
|
---|
116 | Result.Value8 := Value;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | class function TValue.Create16(Value: Word): TValue;
|
---|
120 | begin
|
---|
121 | Result.Value16 := Value;
|
---|
122 | end;
|
---|
123 |
|
---|
124 | class function TValue.Create32(Value: DWord): TValue;
|
---|
125 | begin
|
---|
126 | Result.Value32 := Value;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | class function TValue.Create64(Value: QWord): TValue;
|
---|
130 | begin
|
---|
131 | Result.Value64 := Value;
|
---|
132 | end;
|
---|
133 |
|
---|
134 | procedure TCpu.ReadD8A8(var AAddress: TValue; var AData: TValue;
|
---|
135 | Increment: Boolean);
|
---|
136 | begin
|
---|
137 | FAddress.Value8 := AAddress.Value8;
|
---|
138 | DoRead;
|
---|
139 | AData.Value8 := Data.Value8;
|
---|
140 | if Increment then AAddress.Value8 := AAddress.Value8 + 1;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TCpu.ReadD8A16(var AAddress: TValue; var AData: TValue;
|
---|
144 | Increment: Boolean);
|
---|
145 | begin
|
---|
146 | FAddress.Value16 := AAddress.Value16;
|
---|
147 | DoRead;
|
---|
148 | AData.Value8 := Data.Value8;
|
---|
149 | if Increment then AAddress.Value16 := AAddress.Value16 + 1;
|
---|
150 | end;
|
---|
151 |
|
---|
152 | procedure TCpu.ReadD16A8(var AAddress: TValue; var AData: TValue;
|
---|
153 | Increment: Boolean);
|
---|
154 | begin
|
---|
155 | FAddress.Value8 := AAddress.Value8;
|
---|
156 | DoRead;
|
---|
157 | AData.Value16 := Data.Value16;
|
---|
158 | if Increment then AAddress.Value8 := AAddress.Value8 + 1;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | procedure TCpu.ReadD16A16(var AAddress: TValue; var AData: TValue;
|
---|
162 | Increment: Boolean);
|
---|
163 | begin
|
---|
164 | FAddress.Value16 := AAddress.Value16;
|
---|
165 | DoRead;
|
---|
166 | AData.Value16 := Data.Value16;
|
---|
167 | if Increment then AAddress.Value16 := AAddress.Value16 + 1;
|
---|
168 | end;
|
---|
169 |
|
---|
170 | procedure TCpu.Read(var Address: TValue; var Data: TValue; Increment: Boolean;
|
---|
171 | AddressWidth: TBitWidth; DataWidth: TBitWidth);
|
---|
172 | begin
|
---|
173 | case AddressWidth of
|
---|
174 | bw8: case DataWidth of
|
---|
175 | bw8: ReadD8A8(Address, Data, Increment);
|
---|
176 | bw16: ReadD16A8(Address, Data, Increment);
|
---|
177 | end;
|
---|
178 | bw16: case DataWidth of
|
---|
179 | bw8: ReadD8A16(Address, Data, Increment);
|
---|
180 | bw16: ReadD16A16(Address, Data, Increment);
|
---|
181 | end;
|
---|
182 | end;
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TCpu.ReadAddressA8(var Address: TValue; var Data: TValue;
|
---|
186 | Increment: Boolean);
|
---|
187 | begin
|
---|
188 | case AddressWidth of
|
---|
189 | bw8: ReadD8A8(Address, Data, Increment);
|
---|
190 | bw16: ReadD16A8(Address, Data, Increment);
|
---|
191 | end;
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TCpu.ReadAddressA16(var Address: TValue; var Data: TValue;
|
---|
195 | Increment: Boolean);
|
---|
196 | begin
|
---|
197 | case AddressWidth of
|
---|
198 | bw8: ReadD8A16(Address, Data, Increment);
|
---|
199 | bw16: ReadD16A16(Address, Data, Increment);
|
---|
200 | end;
|
---|
201 | end;
|
---|
202 |
|
---|
203 | procedure TCpu.ReadDataA8(var Address: TValue; var Data: TValue;
|
---|
204 | Increment: Boolean);
|
---|
205 | begin
|
---|
206 | case DataWidth of
|
---|
207 | bw8: ReadD8A8(Address, Data, Increment);
|
---|
208 | bw16: ReadD16A8(Address, Data, Increment);
|
---|
209 | end;
|
---|
210 | end;
|
---|
211 |
|
---|
212 | procedure TCpu.ReadDataA16(var Address: TValue; var Data: TValue;
|
---|
213 | Increment: Boolean);
|
---|
214 | begin
|
---|
215 | case DataWidth of
|
---|
216 | bw8: ReadD8A16(Address, Data, Increment);
|
---|
217 | bw16: ReadD16A16(Address, Data, Increment);
|
---|
218 | end;
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TCpu.ReadAddress(var Address: TValue; var Data: TValue;
|
---|
222 | Increment: Boolean);
|
---|
223 | begin
|
---|
224 | case AddressWidth of
|
---|
225 | bw8: ReadAddressA8(Address, Data, Increment);
|
---|
226 | bw16: ReadAddressA16(Address, Data, Increment);
|
---|
227 | end;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TCpu.ReadData(var Address: TValue; var Data: TValue;
|
---|
231 | Increment: Boolean);
|
---|
232 | begin
|
---|
233 | case AddressWidth of
|
---|
234 | bw8: ReadDataA8(Address, Data, Increment);
|
---|
235 | bw16: ReadDataA16(Address, Data, Increment);
|
---|
236 | end;
|
---|
237 | end;
|
---|
238 |
|
---|
239 | procedure TCpu.WriteD8A8(var Address: TValue; AData: TValue; Increment: Boolean);
|
---|
240 | begin
|
---|
241 | FAddress.Value8 := Address.Value8;
|
---|
242 | Data.Value8 := AData.Value8;
|
---|
243 | DoWrite;
|
---|
244 | if Increment then Address.Value8 := Address.Value8 + 1;
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure TCpu.WriteD8A16(var Address: TValue; AData: TValue; Increment: Boolean
|
---|
248 | );
|
---|
249 | begin
|
---|
250 | FAddress.Value16 := Address.Value16;
|
---|
251 | Data.Value8 := AData.Value8;
|
---|
252 | DoWrite;
|
---|
253 | if Increment then Address.Value16 := Address.Value16 + 1;
|
---|
254 | end;
|
---|
255 |
|
---|
256 | procedure TCpu.WriteD16A8(var Address: TValue; AData: TValue; Increment: Boolean
|
---|
257 | );
|
---|
258 | begin
|
---|
259 | FAddress.Value8 := Address.Value8;
|
---|
260 | Data.Value16 := AData.Value16;
|
---|
261 | DoWrite;
|
---|
262 | if Increment then Address.Value8 := Address.Value8 + 1;
|
---|
263 | end;
|
---|
264 |
|
---|
265 | procedure TCpu.WriteD16A16(var Address: TValue; AData: TValue; Increment: Boolean
|
---|
266 | );
|
---|
267 | begin
|
---|
268 | FAddress.Value16 := Address.Value16;
|
---|
269 | AData.Value16 := AData.Value16;
|
---|
270 | DoWrite;
|
---|
271 | if Increment then Address.Value16 := Address.Value16 + 1;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | procedure TCpu.Write(var Address: TValue; Data: TValue; Increment: Boolean;
|
---|
275 | AddressWidth: TBitWidth; DataWidth: TBitWidth);
|
---|
276 | begin
|
---|
277 | case AddressWidth of
|
---|
278 | bw8: case DataWidth of
|
---|
279 | bw8: WriteD8A8(Address, Data, Increment);
|
---|
280 | bw16: WriteD16A8(Address, Data, Increment);
|
---|
281 | end;
|
---|
282 | bw16: case DataWidth of
|
---|
283 | bw8: WriteD8A16(Address, Data, Increment);
|
---|
284 | bw16: WriteD16A16(Address, Data, Increment);
|
---|
285 | end;
|
---|
286 | end;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TCpu.WriteAddressA8(var Address: TValue; Data: TValue;
|
---|
290 | Increment: Boolean);
|
---|
291 | begin
|
---|
292 | case AddressWidth of
|
---|
293 | bw8: WriteD8A8(Address, Data, Increment);
|
---|
294 | bw16: WriteD16A8(Address, Data, Increment);
|
---|
295 | end;
|
---|
296 | end;
|
---|
297 |
|
---|
298 | procedure TCpu.WriteAddressA16(var Address: TValue; Data: TValue;
|
---|
299 | Increment: Boolean);
|
---|
300 | begin
|
---|
301 | case AddressWidth of
|
---|
302 | bw8: WriteD8A16(Address, Data, Increment);
|
---|
303 | bw16: WriteD16A16(Address, Data, Increment);
|
---|
304 | end;
|
---|
305 | end;
|
---|
306 |
|
---|
307 | procedure TCpu.WriteDataA8(var Address: TValue; Data: TValue; Increment: Boolean
|
---|
308 | );
|
---|
309 | begin
|
---|
310 | case DataWidth of
|
---|
311 | bw8: WriteD8A8(Address, Data, Increment);
|
---|
312 | bw16: WriteD16A8(Address, Data, Increment);
|
---|
313 | end;
|
---|
314 | end;
|
---|
315 |
|
---|
316 | procedure TCpu.WriteDataA16(var Address: TValue; Data: TValue;
|
---|
317 | Increment: Boolean);
|
---|
318 | begin
|
---|
319 | case DataWidth of
|
---|
320 | bw8: WriteD8A16(Address, Data, Increment);
|
---|
321 | bw16: WriteD16A16(Address, Data, Increment);
|
---|
322 | end;
|
---|
323 | end;
|
---|
324 |
|
---|
325 | procedure TCpu.WriteData(var Address: TValue; Value: TValue; Increment: Boolean
|
---|
326 | );
|
---|
327 | begin
|
---|
328 | case AddressWidth of
|
---|
329 | bw8: WriteDataA8(Address, Value, Increment);
|
---|
330 | bw16: WriteDataA16(Address, Value, Increment);
|
---|
331 | end;
|
---|
332 | end;
|
---|
333 |
|
---|
334 | procedure TCpu.WriteAddress(var Address: TValue; Value: TValue;
|
---|
335 | Increment: Boolean);
|
---|
336 | begin
|
---|
337 | case AddressWidth of
|
---|
338 | bw8: WriteAddressA8(Address, Value, Increment);
|
---|
339 | bw16: WriteAddressA16(Address, Value, Increment);
|
---|
340 | end;
|
---|
341 | end;
|
---|
342 |
|
---|
343 | procedure TCpu.Push(Data: TValue; BitWidth: TBitWidth);
|
---|
344 | begin
|
---|
345 | case AddressWidth of
|
---|
346 | bw8: SP.Value8 := SP.Value8 - BitWidthByteSize[BitWidth];
|
---|
347 | bw16: SP.Value16 := SP.Value16 - BitWidthByteSize[BitWidth];
|
---|
348 | end;
|
---|
349 | WriteData(SP, Data, False);
|
---|
350 | end;
|
---|
351 |
|
---|
352 | procedure TCpu.Pop(var Data: TValue; BitWidth: TBitWidth);
|
---|
353 | begin
|
---|
354 | ReadData(SP, Data, False);
|
---|
355 | case AddressWidth of
|
---|
356 | bw8: SP.Value8 := SP.Value8 + BitWidthByteSize[BitWidth];
|
---|
357 | bw16: SP.Value16 := SP.Value16 + BitWidthByteSize[BitWidth];
|
---|
358 | end;
|
---|
359 | end;
|
---|
360 |
|
---|
361 | procedure TCpu.DoRead;
|
---|
362 | begin
|
---|
363 | if Assigned(FOnRead) then FOnRead(Self);
|
---|
364 | end;
|
---|
365 |
|
---|
366 | procedure TCpu.DoWrite;
|
---|
367 | begin
|
---|
368 | if Assigned(FOnWrite) then FOnWrite(Self);
|
---|
369 | end;
|
---|
370 |
|
---|
371 | procedure TCpu.DoInput;
|
---|
372 | begin
|
---|
373 | if Assigned(FOnInput) then FOnInput(Self);
|
---|
374 | end;
|
---|
375 |
|
---|
376 | procedure TCpu.DoOutput;
|
---|
377 | begin
|
---|
378 | if Assigned(FOnOutput) then FOnOutput(Self);
|
---|
379 | end;
|
---|
380 |
|
---|
381 | procedure TCpu.Reset;
|
---|
382 | begin
|
---|
383 | Terminated := False;
|
---|
384 | A.Value64 := 0;
|
---|
385 | IP.Value64 := 0;
|
---|
386 | SP.Value64 := 0;
|
---|
387 | end;
|
---|
388 |
|
---|
389 | function TCpu.GetFrequency: Integer;
|
---|
390 | begin
|
---|
391 | Result := FFrequency;
|
---|
392 | end;
|
---|
393 |
|
---|
394 | procedure TCpu.SetAddressWidth(AValue: TBitWidth);
|
---|
395 | begin
|
---|
396 | if FAddressWidth = AValue then Exit;
|
---|
397 | FAddressWidth := AValue;
|
---|
398 | end;
|
---|
399 |
|
---|
400 | procedure TCpu.SetFrequency(AValue: Integer);
|
---|
401 | begin
|
---|
402 | FFrequency := AValue;
|
---|
403 | end;
|
---|
404 |
|
---|
405 | procedure TCpu.SetDataWidth(AValue: TBitWidth);
|
---|
406 | begin
|
---|
407 | if FDataWidth = AValue then Exit;
|
---|
408 | FDataWidth := AValue;
|
---|
409 | end;
|
---|
410 |
|
---|
411 | procedure TCpu.Step;
|
---|
412 | var
|
---|
413 | Opcode: TOpcode;
|
---|
414 | Data: TValue;
|
---|
415 | Addr: TValue;
|
---|
416 | LastWidth: TBitWidth;
|
---|
417 | begin
|
---|
418 | Read(IP, Data, True, AddressWidth, bw8);
|
---|
419 | Opcode := TOpcode(Data.Value8);
|
---|
420 | case Opcode of
|
---|
421 | opNop: ; // Do nothing
|
---|
422 | opHalt: Terminated := True;
|
---|
423 | opLoad: ReadData(IP, A, True);
|
---|
424 | opLoadMem: begin
|
---|
425 | ReadAddress(IP, Addr, True);
|
---|
426 | ReadData(Addr, A, False);
|
---|
427 | end;
|
---|
428 | opStoreMem: begin
|
---|
429 | ReadAddress(IP, Addr, True);
|
---|
430 | WriteData(Addr, A, False);
|
---|
431 | end;
|
---|
432 | opIncrement: case DataWidth of
|
---|
433 | bw8: A.Value8 := A.Value8 + 1;
|
---|
434 | bw16: A.Value16 := A.Value16 + 1;
|
---|
435 | end;
|
---|
436 | opDecrement: case DataWidth of
|
---|
437 | bw8: A.Value8 := A.Value8 - 1;
|
---|
438 | bw16: A.Value16 := A.Value16 - 1;
|
---|
439 | end;
|
---|
440 | opJump: begin
|
---|
441 | ReadAddress(IP, Addr, True);
|
---|
442 | IP := Addr;
|
---|
443 | end;
|
---|
444 | opPush: Push(A, DataWidth);
|
---|
445 | opPop: Pop(A, DataWidth);
|
---|
446 | opCall: begin
|
---|
447 | ReadAddress(IP, Addr, True);
|
---|
448 | Push(Addr, AddressWidth);
|
---|
449 | IP := Addr;
|
---|
450 | end;
|
---|
451 | opReturn: begin
|
---|
452 | Pop(Addr, AddressWidth);
|
---|
453 | IP := Addr;
|
---|
454 | end;
|
---|
455 | opAdd: begin
|
---|
456 | ReadData(IP, Data, True);
|
---|
457 | case DataWidth of
|
---|
458 | bw8: A.Value8 := A.Value8 + Data.Value8;
|
---|
459 | bw16: A.Value16 := A.Value16 + Data.Value16;
|
---|
460 | end;
|
---|
461 | end;
|
---|
462 | opSubtract: begin
|
---|
463 | ReadData(IP, Data, True);
|
---|
464 | case DataWidth of
|
---|
465 | bw8: A.Value8 := A.Value8 - Data.Value8;
|
---|
466 | bw16: A.Value16 := A.Value16 - Data.Value16;
|
---|
467 | end;
|
---|
468 | end;
|
---|
469 | opInput: begin
|
---|
470 | ReadAddress(IP, FAddress, True);
|
---|
471 | DoInput;
|
---|
472 | AssignValue(A, Data, DataWidth);
|
---|
473 | end;
|
---|
474 | opOutput: begin
|
---|
475 | ReadAddress(IP, FAddress, True);
|
---|
476 | AssignValue(Data, A, DataWidth);
|
---|
477 | DoOutput;
|
---|
478 | end;
|
---|
479 | opDataWidth8: if DataWidth <> bw8 then begin
|
---|
480 | LastWidth := DataWidth;
|
---|
481 | DataWidth := bw8;
|
---|
482 | Step;
|
---|
483 | DataWidth := LastWidth;
|
---|
484 | end;
|
---|
485 | opDataWidth16: if DataWidth <> bw16 then begin
|
---|
486 | LastWidth := DataWidth;
|
---|
487 | DataWidth := bw16;
|
---|
488 | Step;
|
---|
489 | DataWidth := LastWidth;
|
---|
490 | end;
|
---|
491 | opAddressWidth8: if AddressWidth <> bw8 then begin
|
---|
492 | LastWidth := AddressWidth;
|
---|
493 | AddressWidth := bw8;
|
---|
494 | Step;
|
---|
495 | AddressWidth := LastWidth;
|
---|
496 | end;
|
---|
497 | opAddressWidth16: if AddressWidth <> bw16 then begin
|
---|
498 | LastWidth := AddressWidth;
|
---|
499 | AddressWidth := bw16;
|
---|
500 | Step;
|
---|
501 | AddressWidth := LastWidth;
|
---|
502 | end;
|
---|
503 | end;
|
---|
504 | end;
|
---|
505 |
|
---|
506 | procedure TCpu.Run;
|
---|
507 | begin
|
---|
508 | Reset;
|
---|
509 | while not Terminated do
|
---|
510 | Step;
|
---|
511 | end;
|
---|
512 |
|
---|
513 | constructor TCpu.Create;
|
---|
514 | begin
|
---|
515 | end;
|
---|
516 |
|
---|
517 | destructor TCpu.Destroy;
|
---|
518 | begin
|
---|
519 | inherited;
|
---|
520 | end;
|
---|
521 |
|
---|
522 | procedure TCpu.AssignValue(var Dest: TValue; Source: TValue; Width: TBitWidth);
|
---|
523 | begin
|
---|
524 | case Width of
|
---|
525 | bw8: Dest.Value8 := Source.Value8;
|
---|
526 | end;
|
---|
527 | end;
|
---|
528 |
|
---|
529 | end.
|
---|
530 |
|
---|