source: branches/virtualcpu4/UInstructionReader.pas

Last change on this file was 184, checked in by chronos, 6 years ago
  • Added: Basic assembler window.
File size: 1.9 KB
Line 
1unit UInstructionReader;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, UCpu;
9
10type
11
12 { TInstructionReader }
13
14 TInstructionReader = class
15 protected
16 public
17 Cpu: TCpu;
18 IP: Integer;
19 Prefix: Boolean;
20 DataSize: TBitWidth;
21 DataSizeBase: TBitWidth;
22 AddrSize: TBitWidth;
23 AddrSizeBase: TBitWidth;
24 procedure Init;
25 function Read8: Byte; inline;
26 function Read16: Word; inline;
27 function Read32: DWord; inline;
28 function Read64: QWord; inline;
29 function ReadAddress: TAddress; inline;
30 function ReadAddressSigned: TAddressSigned; inline;
31 function ReadData: QWord;
32 end;
33
34implementation
35
36{ TInstructionReader }
37
38procedure TInstructionReader.Init;
39begin
40 DataSizeBase := Cpu.DataSizeBase;
41 DataSize := DataSizeBase;
42 AddrSizeBase := Cpu.AddrSizeBase;
43 AddrSize := AddrSizeBase;
44 IP := 0;
45 Prefix := False;
46end;
47
48function TInstructionReader.Read8: Byte;
49begin
50 Result := PByte(Cpu.Memory + IP)^;
51 Inc(IP);
52end;
53
54function TInstructionReader.Read16: Word;
55begin
56 Result := PWord(Cpu.Memory + IP)^;
57 Inc(IP, SizeOf(Word));
58end;
59
60function TInstructionReader.Read32: DWord;
61begin
62 Result := PDWord(Cpu.Memory + IP)^;
63 Inc(IP, SizeOf(DWord));
64end;
65
66function TInstructionReader.Read64: QWord;
67begin
68 Result := PQWord(Cpu.Memory + IP)^;
69 Inc(IP, SizeOf(QWord));
70end;
71
72function TInstructionReader.ReadAddress: TAddress;
73begin
74 case AddrSize of
75 bw8: Result := Read8;
76 bw16: Result := Read16;
77 bw32: Result := Read32;
78 bw64: Result := Read64;
79 end;
80end;
81
82function TInstructionReader.ReadAddressSigned: TAddressSigned;
83begin
84 case AddrSize of
85 bw8: Result := ShortInt(Read8);
86 bw16: Result := SmallInt(Read16);
87 bw32: Result := Integer(Read32);
88 bw64: Result := Int64(Read64);
89 end;
90end;
91
92function TInstructionReader.ReadData: QWord;
93begin
94 case DataSize of
95 bw8: Result := Read8;
96 bw16: Result := Read16;
97 bw32: Result := Read32;
98 bw64: Result := Read64;
99 end;
100end;
101
102end.
103
Note: See TracBrowser for help on using the repository browser.