1 | unit IntMemory;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Int;
|
---|
7 |
|
---|
8 | type
|
---|
9 |
|
---|
10 | { TIntMemory }
|
---|
11 |
|
---|
12 | TIntMemory = class
|
---|
13 | private
|
---|
14 | FData: array of TInt;
|
---|
15 | FPosition: TInt;
|
---|
16 | function GetSize: TInt;
|
---|
17 | procedure SetSize(AValue: TInt);
|
---|
18 | public
|
---|
19 | procedure Write(Address, Data: TInt);
|
---|
20 | function Read(Address: TInt): TInt;
|
---|
21 | procedure WritePos(Data: TInt);
|
---|
22 | function ReadPos: TInt;
|
---|
23 | procedure CopyFrom(Source: TIntMemory; Dst, Src, Count: TInt);
|
---|
24 | procedure WriteStringPos(Value: string);
|
---|
25 | property Size: TInt read GetSize write SetSize;
|
---|
26 | property Position: TInt read FPosition write FPosition;
|
---|
27 | property Items[Index: TInt]: TInt read Read write Write; default;
|
---|
28 | end;
|
---|
29 |
|
---|
30 |
|
---|
31 | implementation
|
---|
32 |
|
---|
33 | { TIntMemory }
|
---|
34 |
|
---|
35 | function TIntMemory.GetSize: TInt;
|
---|
36 | begin
|
---|
37 | Result := Length(FData);
|
---|
38 | end;
|
---|
39 |
|
---|
40 | procedure TIntMemory.SetSize(AValue: TInt);
|
---|
41 | begin
|
---|
42 | SetLength(FData, AValue);
|
---|
43 | end;
|
---|
44 |
|
---|
45 | procedure TIntMemory.Write(Address, Data: TInt);
|
---|
46 | begin
|
---|
47 | FData[Address] := Data;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | function TIntMemory.Read(Address: TInt): TInt;
|
---|
51 | begin
|
---|
52 | Result := FData[Address];
|
---|
53 | end;
|
---|
54 |
|
---|
55 | procedure TIntMemory.WritePos(Data: TInt);
|
---|
56 | begin
|
---|
57 | Write(FPosition, Data);
|
---|
58 | Inc(FPosition);
|
---|
59 | end;
|
---|
60 |
|
---|
61 | function TIntMemory.ReadPos: TInt;
|
---|
62 | begin
|
---|
63 | Result := Read(FPosition);
|
---|
64 | Inc(FPosition);
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TIntMemory.CopyFrom(Source: TIntMemory; Dst, Src, Count: TInt);
|
---|
68 | var
|
---|
69 | I: Integer;
|
---|
70 | begin
|
---|
71 | for I := 0 to Count - 1 do begin
|
---|
72 | Write(Dst, Source.Read(Src));
|
---|
73 | Inc(Dst);
|
---|
74 | Inc(Src);
|
---|
75 | end;
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TIntMemory.WriteStringPos(Value: string);
|
---|
79 | var
|
---|
80 | I: Integer;
|
---|
81 | begin
|
---|
82 | if Length(Value) > 0 then begin
|
---|
83 | if Position + Length(Value) > Size then Size := Position + Length(Value);
|
---|
84 | for I := 0 to Length(Value) - 1 do
|
---|
85 | Items[Position + I] := Ord(Value[I + 1]);
|
---|
86 | Inc(FPosition, Length(Value));
|
---|
87 | end;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | end.
|
---|
91 |
|
---|