source: branches/configured machine/Memory.pas

Last change on this file was 239, checked in by chronos, 16 months ago
File size: 1.8 KB
Line 
1unit Memory;
2
3interface
4
5uses
6 Classes, SysUtils, AddressableArea;
7
8type
9 { TMemory1 }
10
11 TMemory1 = class(TAddressableArea1)
12 private
13 FSize: Integer;
14 FData: PByte;
15 procedure SetSize(AValue: Integer);
16 public
17 procedure Write1(Address: Byte; Data: Byte); override;
18 function Read1(Address: Byte): Byte; override;
19 property Data: PByte read FData;
20 property Size: Integer read FSize write SetSize;
21 end;
22
23 { TMemory2 }
24
25 TMemory2 = class(TAddressableArea2)
26 private
27 FSize: Integer;
28 FData: PByte;
29 procedure SetSize(AValue: Integer);
30 public
31 procedure Write1(Address: Word; Data: Byte); override;
32 procedure Write2(Address: Word; Data: Word); override;
33 function Read1(Address: Word): Byte; override;
34 function Read2(Address: Word): Word; override;
35 property Data: PByte read FData;
36 property Size: Integer read FSize write SetSize;
37 end;
38
39
40implementation
41
42{ TMemory2 }
43
44procedure TMemory2.SetSize(AValue: Integer);
45begin
46 if FSize = AValue then Exit;
47 FSize := AValue;
48 FData := ReAllocMem(FData, FSize);
49end;
50
51procedure TMemory2.Write1(Address: Word; Data: Byte);
52begin
53 (FData + Address)^ := Data;
54end;
55
56procedure TMemory2.Write2(Address: Word; Data: Word);
57begin
58 PWord(FData + Address)^ := Data;
59end;
60
61function TMemory2.Read1(Address: Word): Byte;
62begin
63 Result := (FData + Address)^;
64end;
65
66function TMemory2.Read2(Address: Word): Word;
67begin
68 Result := PWord(FData + Address)^;
69end;
70
71{ TMemory1 }
72
73procedure TMemory1.SetSize(AValue: Integer);
74begin
75 if FSize = AValue then Exit;
76 FSize := AValue;
77 FData := ReAllocMem(FData, FSize);
78end;
79
80procedure TMemory1.Write1(Address: Byte; Data: Byte);
81begin
82 (FData + Address)^ := Data;
83end;
84
85function TMemory1.Read1(Address: Byte): Byte;
86begin
87 Result := (FData + Address)^;
88end;
89
90end.
91
Note: See TracBrowser for help on using the repository browser.