1 | {$IFDEF INTERFACE}
|
---|
2 | TGMemory = class
|
---|
3 | private
|
---|
4 | FData: PByte;
|
---|
5 | procedure SetSize(Value: TGMemoryData);
|
---|
6 | function GetSize: TGMemoryData;
|
---|
7 | public
|
---|
8 | Position: TGMemoryData;
|
---|
9 | {$IF TGMemoryWidth>=8}
|
---|
10 | function Read8(Address: TGMemoryData): Byte;
|
---|
11 | procedure Write8(Address: TGMemoryData; Data: Byte);
|
---|
12 | function ReadPos8: Byte;
|
---|
13 | procedure WritePos8(Data: Byte);
|
---|
14 | {$ENDIF}
|
---|
15 | {$IF TGMemoryWidth>=16}
|
---|
16 | function Read16(Address: TGMemoryData): Word;
|
---|
17 | procedure Write16(Address: TGMemoryData; Data: Word);
|
---|
18 | function ReadPos16: Word;
|
---|
19 | procedure WritePos16(Data: Word);
|
---|
20 | {$ENDIF}
|
---|
21 | {$IF TGMemoryWidth>=32}
|
---|
22 | function Read32(Address: TGMemoryData): DWord;
|
---|
23 | procedure Write32(Address: TGMemoryData; Data: DWord);
|
---|
24 | function ReadPos32: DWord;
|
---|
25 | procedure WritePos32(Data: DWord);
|
---|
26 | {$ENDIF}
|
---|
27 | {$IF TGMemoryWidth>=64}
|
---|
28 | function Read64(Address: TGMemoryData): QWord;
|
---|
29 | procedure Write64(Address: TGMemoryData; Data: QWord);
|
---|
30 | function ReadPos64: QWord;
|
---|
31 | procedure WritePos64(Data: QWord);
|
---|
32 | {$ENDIF}
|
---|
33 | procedure Clean;
|
---|
34 | procedure SetDataBus(Channel: TGMemoryAddrChannel);
|
---|
35 | property Size: TGMemoryData read GetSize write SetSize;
|
---|
36 | end;
|
---|
37 |
|
---|
38 | {$UNDEF INTERFACE}
|
---|
39 | {$ENDIF}
|
---|
40 |
|
---|
41 | {$IFDEF IMPLEMENTATION}
|
---|
42 |
|
---|
43 | procedure TGMemory.Clean;
|
---|
44 | begin
|
---|
45 | FillChar(FData^, Size, 0);
|
---|
46 | end;
|
---|
47 |
|
---|
48 | procedure TGMemory.SetSize(Value: TGMemoryData);
|
---|
49 | begin
|
---|
50 | FData := ReAllocMem(FData, Value);
|
---|
51 | end;
|
---|
52 |
|
---|
53 | function TGMemory.GetSize: TGMemoryData;
|
---|
54 | begin
|
---|
55 | Result := MemSize(FData);
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TGMemory.SetDataBus(Channel: TGMemoryAddrChannel);
|
---|
59 | begin
|
---|
60 | {$IF TGMemoryWidth>=8}
|
---|
61 | Channel.Read8 := Read8;
|
---|
62 | Channel.Write8 := Write8;
|
---|
63 | {$ENDIF}
|
---|
64 | {$IF TGMemoryWidth>=16}
|
---|
65 | Channel.Read16 := Read16;
|
---|
66 | Channel.Write16 := Write16;
|
---|
67 | {$ENDIF}
|
---|
68 | {$IF TGMemoryWidth>=32}
|
---|
69 | Channel.Read32 := Read32;
|
---|
70 | Channel.Write32 := Write32;
|
---|
71 | {$ENDIF}
|
---|
72 | {$IF TGMemoryWidth>=64}
|
---|
73 | Channel.Read64 := Read64;
|
---|
74 | Channel.Write64 := Write64;
|
---|
75 | {$ENDIF}
|
---|
76 | end;
|
---|
77 |
|
---|
78 | {$IF TGMemoryWidth>=8}
|
---|
79 | function TGMemory.Read8(Address: TGMemoryData): Byte;
|
---|
80 | begin
|
---|
81 | Result := PByte(FData + Address)^;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | procedure TGMemory.Write8(Address: TGMemoryData; Data: Byte);
|
---|
85 | begin
|
---|
86 | PByte(FData + Address)^ := Data;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | function TGMemory.ReadPos8: Byte;
|
---|
90 | begin
|
---|
91 | Result := PByte(FData + Position)^;
|
---|
92 | Inc(Position);
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TGMemory.WritePos8(Data: Byte);
|
---|
96 | begin
|
---|
97 | PByte(FData + Position)^ := Data;
|
---|
98 | Inc(Position);
|
---|
99 | end;
|
---|
100 | {$ENDIF}
|
---|
101 |
|
---|
102 | {$IF TGMemoryWidth>=16}
|
---|
103 | function TGMemory.Read16(Address: TGMemoryData): Word;
|
---|
104 | begin
|
---|
105 | Result := PWord(FData + Address)^;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TGMemory.Write16(Address: TGMemoryData; Data: Word);
|
---|
109 | begin
|
---|
110 | PWord(FData + Address)^ := Data;
|
---|
111 | end;
|
---|
112 |
|
---|
113 | function TGMemory.ReadPos16: Word;
|
---|
114 | begin
|
---|
115 | Result := PWord(FData + Position)^;
|
---|
116 | Inc(Position, SizeOf(Word));
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TGMemory.WritePos16(Data: Word);
|
---|
120 | begin
|
---|
121 | PWord(FData + Position)^ := Data;
|
---|
122 | Inc(Position, SizeOf(Word));
|
---|
123 | end;
|
---|
124 | {$ENDIF}
|
---|
125 |
|
---|
126 | {$IF TGMemoryWidth>=32}
|
---|
127 | function TGMemory.Read32(Address: TGMemoryData): DWord;
|
---|
128 | begin
|
---|
129 | Result := PDWord(FData + Address)^;
|
---|
130 | end;
|
---|
131 |
|
---|
132 | procedure TGMemory.Write32(Address: TGMemoryData; Data: DWord);
|
---|
133 | begin
|
---|
134 | PDWord(FData + Address)^ := Data;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | function TGMemory.ReadPos32: DWord;
|
---|
138 | begin
|
---|
139 | Result := PDWord(FData + Position)^;
|
---|
140 | Inc(Position, SizeOf(DWord));
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TGMemory.WritePos32(Data: DWord);
|
---|
144 | begin
|
---|
145 | PDWord(FData + Position)^ := Data;
|
---|
146 | Inc(Position, SizeOf(DWord));
|
---|
147 | end;
|
---|
148 | {$ENDIF}
|
---|
149 |
|
---|
150 | {$IF TGMemoryWidth>=64}
|
---|
151 | function TGMemory.Read64(Address: TGMemoryData): QWord;
|
---|
152 | begin
|
---|
153 | Result := PQWord(FData + Address)^;
|
---|
154 | end;
|
---|
155 |
|
---|
156 | procedure TGMemory.Write64(Address: TGMemoryData; Data: QWord);
|
---|
157 | begin
|
---|
158 | PQWord(FData + Address)^ := Data;
|
---|
159 | end;
|
---|
160 |
|
---|
161 | function TGMemory.ReadPos64: QWord;
|
---|
162 | begin
|
---|
163 | Result := PQWord(FData + Position)^;
|
---|
164 | Inc(Position, SizeOf(QWord));
|
---|
165 | end;
|
---|
166 |
|
---|
167 | procedure TGMemory.WritePos64(Data: QWord);
|
---|
168 | begin
|
---|
169 | PQWord(FData + Position)^ := Data;
|
---|
170 | Inc(Position, SizeOf(QWord));
|
---|
171 | end;
|
---|
172 | {$ENDIF}
|
---|
173 |
|
---|
174 | {$UNDEF IMPLEMENTATION}
|
---|
175 | {$ENDIF}
|
---|