source: branches/bigint/IntMemory.pas

Last change on this file was 8, checked in by chronos, 3 months ago
  • Added: Common package.
  • Added: Memory form to show content of memory.
File size: 1.7 KB
Line 
1unit IntMemory;
2
3interface
4
5uses
6 Classes, SysUtils, Int;
7
8type
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
31implementation
32
33{ TIntMemory }
34
35function TIntMemory.GetSize: TInt;
36begin
37 Result := Length(FData);
38end;
39
40procedure TIntMemory.SetSize(AValue: TInt);
41begin
42 SetLength(FData, AValue);
43end;
44
45procedure TIntMemory.Write(Address, Data: TInt);
46begin
47 FData[Address] := Data;
48end;
49
50function TIntMemory.Read(Address: TInt): TInt;
51begin
52 Result := FData[Address];
53end;
54
55procedure TIntMemory.WritePos(Data: TInt);
56begin
57 Write(FPosition, Data);
58 Inc(FPosition);
59end;
60
61function TIntMemory.ReadPos: TInt;
62begin
63 Result := Read(FPosition);
64 Inc(FPosition);
65end;
66
67procedure TIntMemory.CopyFrom(Source: TIntMemory; Dst, Src, Count: TInt);
68var
69 I: Integer;
70begin
71 for I := 0 to Count - 1 do begin
72 Write(Dst, Source.Read(Src));
73 Inc(Dst);
74 Inc(Src);
75 end;
76end;
77
78procedure TIntMemory.WriteStringPos(Value: string);
79var
80 I: Integer;
81begin
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;
88end;
89
90end.
91
Note: See TracBrowser for help on using the repository browser.