1 | unit Memory;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, AddressableArea;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
40 | implementation
|
---|
41 |
|
---|
42 | { TMemory2 }
|
---|
43 |
|
---|
44 | procedure TMemory2.SetSize(AValue: Integer);
|
---|
45 | begin
|
---|
46 | if FSize = AValue then Exit;
|
---|
47 | FSize := AValue;
|
---|
48 | FData := ReAllocMem(FData, FSize);
|
---|
49 | end;
|
---|
50 |
|
---|
51 | procedure TMemory2.Write1(Address: Word; Data: Byte);
|
---|
52 | begin
|
---|
53 | (FData + Address)^ := Data;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TMemory2.Write2(Address: Word; Data: Word);
|
---|
57 | begin
|
---|
58 | PWord(FData + Address)^ := Data;
|
---|
59 | end;
|
---|
60 |
|
---|
61 | function TMemory2.Read1(Address: Word): Byte;
|
---|
62 | begin
|
---|
63 | Result := (FData + Address)^;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | function TMemory2.Read2(Address: Word): Word;
|
---|
67 | begin
|
---|
68 | Result := PWord(FData + Address)^;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | { TMemory1 }
|
---|
72 |
|
---|
73 | procedure TMemory1.SetSize(AValue: Integer);
|
---|
74 | begin
|
---|
75 | if FSize = AValue then Exit;
|
---|
76 | FSize := AValue;
|
---|
77 | FData := ReAllocMem(FData, FSize);
|
---|
78 | end;
|
---|
79 |
|
---|
80 | procedure TMemory1.Write1(Address: Byte; Data: Byte);
|
---|
81 | begin
|
---|
82 | (FData + Address)^ := Data;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | function TMemory1.Read1(Address: Byte): Byte;
|
---|
86 | begin
|
---|
87 | Result := (FData + Address)^;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | end.
|
---|
91 |
|
---|