source: branches/templates/Devices/Memory.inc

Last change on this file was 44, checked in by chronos, 14 months ago
  • Added: More devices.
File size: 3.8 KB
Line 
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
43procedure TGMemory.Clean;
44begin
45 FillChar(FData^, Size, 0);
46end;
47
48procedure TGMemory.SetSize(Value: TGMemoryData);
49begin
50 FData := ReAllocMem(FData, Value);
51end;
52
53function TGMemory.GetSize: TGMemoryData;
54begin
55 Result := MemSize(FData);
56end;
57
58procedure TGMemory.SetDataBus(Channel: TGMemoryAddrChannel);
59begin
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}
76end;
77
78{$IF TGMemoryWidth>=8}
79function TGMemory.Read8(Address: TGMemoryData): Byte;
80begin
81 Result := PByte(FData + Address)^;
82end;
83
84procedure TGMemory.Write8(Address: TGMemoryData; Data: Byte);
85begin
86 PByte(FData + Address)^ := Data;
87end;
88
89function TGMemory.ReadPos8: Byte;
90begin
91 Result := PByte(FData + Position)^;
92 Inc(Position);
93end;
94
95procedure TGMemory.WritePos8(Data: Byte);
96begin
97 PByte(FData + Position)^ := Data;
98 Inc(Position);
99end;
100{$ENDIF}
101
102{$IF TGMemoryWidth>=16}
103function TGMemory.Read16(Address: TGMemoryData): Word;
104begin
105 Result := PWord(FData + Address)^;
106end;
107
108procedure TGMemory.Write16(Address: TGMemoryData; Data: Word);
109begin
110 PWord(FData + Address)^ := Data;
111end;
112
113function TGMemory.ReadPos16: Word;
114begin
115 Result := PWord(FData + Position)^;
116 Inc(Position, SizeOf(Word));
117end;
118
119procedure TGMemory.WritePos16(Data: Word);
120begin
121 PWord(FData + Position)^ := Data;
122 Inc(Position, SizeOf(Word));
123end;
124{$ENDIF}
125
126{$IF TGMemoryWidth>=32}
127function TGMemory.Read32(Address: TGMemoryData): DWord;
128begin
129 Result := PDWord(FData + Address)^;
130end;
131
132procedure TGMemory.Write32(Address: TGMemoryData; Data: DWord);
133begin
134 PDWord(FData + Address)^ := Data;
135end;
136
137function TGMemory.ReadPos32: DWord;
138begin
139 Result := PDWord(FData + Position)^;
140 Inc(Position, SizeOf(DWord));
141end;
142
143procedure TGMemory.WritePos32(Data: DWord);
144begin
145 PDWord(FData + Position)^ := Data;
146 Inc(Position, SizeOf(DWord));
147end;
148{$ENDIF}
149
150{$IF TGMemoryWidth>=64}
151function TGMemory.Read64(Address: TGMemoryData): QWord;
152begin
153 Result := PQWord(FData + Address)^;
154end;
155
156procedure TGMemory.Write64(Address: TGMemoryData; Data: QWord);
157begin
158 PQWord(FData + Address)^ := Data;
159end;
160
161function TGMemory.ReadPos64: QWord;
162begin
163 Result := PQWord(FData + Position)^;
164 Inc(Position, SizeOf(QWord));
165end;
166
167procedure TGMemory.WritePos64(Data: QWord);
168begin
169 PQWord(FData + Position)^ := Data;
170 Inc(Position, SizeOf(QWord));
171end;
172{$ENDIF}
173
174{$UNDEF IMPLEMENTATION}
175{$ENDIF}
Note: See TracBrowser for help on using the repository browser.