Changeset 9 for branches/ByteArray/Devices/Memory.pas
- Timestamp:
- Aug 6, 2024, 10:31:16 PM (2 months ago)
- Location:
- branches/ByteArray
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray
-
Property svn:ignore
set to
lib
heaptrclog.trc
ByteArray
ByteArray.dbg
ByteArray.lps
ByteArray.res
-
Property svn:ignore
set to
-
branches/ByteArray/Devices/Memory.pas
r5 r9 4 4 5 5 uses 6 Classes, SysUtils, BigInt, Channel, Device;6 Classes, SysUtils, Int, Channel, Device; 7 7 8 8 type … … 10 10 { TMemory } 11 11 12 TMemory = class(T Device)12 TMemory = class(TChannelDevice) 13 13 private 14 FSize: Integer;14 FSize: TInt; 15 15 FData: PByte; 16 function GetSize: Integer;17 procedure SetSize(AValue: Integer);16 function GetSize: TInt; 17 procedure SetSize(AValue: TInt); 18 18 procedure CheckGrow(Address: Integer); 19 19 public 20 Position: Integer;20 Position: TInt; 21 21 Grow: Boolean; 22 22 procedure Assign(Source: TMemory); 23 function Read(Address: T BigInt; ASize: TBigIntSize): TBigInt;24 function ReadPos(ASize: Byte): T BigInt;25 procedure Write(Address: T BigInt; ASize: TBigIntSize; Value: TBigInt);26 procedure WritePos(ASize: Byte; Value: T BigInt);23 function Read(Address: TInt; ASize: TIntSize): TInt; 24 function ReadPos(ASize: Byte): TInt; 25 procedure Write(Address: TInt; ASize: TIntSize; Value: TInt); 26 procedure WritePos(ASize: Byte; Value: TInt); 27 27 procedure WriteStringPos(Value: string); 28 28 procedure WriteMemoryPos(Memory: TMemory); 29 function GetAddressCount: Integer; override;30 29 procedure SetChannel(Channel: TChannel); override; 31 30 procedure SaveToFile(FileName: string); 31 procedure LoadFromFile(FileName: string); 32 32 procedure FillZero; 33 33 procedure Clear; 34 property Size: Integerread FSize write SetSize;34 property Size: TInt read FSize write SetSize; 35 35 destructor Destroy; override; 36 36 end; … … 44 44 { TMemory } 45 45 46 function TMemory.GetSize: Integer;46 function TMemory.GetSize: TInt; 47 47 begin 48 48 Result := MemSize(FData); 49 49 end; 50 50 51 procedure TMemory.SetSize(AValue: Integer);51 procedure TMemory.SetSize(AValue: TInt); 52 52 begin 53 53 FSize := AValue; … … 68 68 end; 69 69 70 function TMemory.Read(Address: T BigInt; ASize: TBigIntSize): TBigInt;70 function TMemory.Read(Address: TInt; ASize: TIntSize): TInt; 71 71 begin 72 72 if Address + ASize > FSize then raise Exception.Create(SOutOfRange); … … 79 79 end; 80 80 81 function TMemory.ReadPos(ASize: Byte): T BigInt;81 function TMemory.ReadPos(ASize: Byte): TInt; 82 82 begin 83 83 Result := Read(Position, ASize); … … 85 85 end; 86 86 87 procedure TMemory.Write(Address: T BigInt; ASize: TBigIntSize; Value: TBigInt);87 procedure TMemory.Write(Address: TInt; ASize: TIntSize; Value: TInt); 88 88 begin 89 89 if Address + ASize > FSize then raise Exception.Create(SOutOfRange); … … 96 96 end; 97 97 98 procedure TMemory.WritePos(ASize: Byte; Value: T BigInt);98 procedure TMemory.WritePos(ASize: Byte; Value: TInt); 99 99 begin 100 100 CheckGrow(Position + ASize); … … 126 126 end; 127 127 128 function TMemory.GetAddressCount: Integer;129 begin130 Result := FSize;131 end;132 133 128 procedure TMemory.SetChannel(Channel: TChannel); 134 129 begin 135 130 Channel.Read := Read; 136 131 Channel.Write := Write; 132 Channel.GetSize := GetSize; 137 133 end; 138 134 … … 168 164 end; 169 165 166 procedure TMemory.LoadFromFile(FileName: string); 167 var 168 F: TFileStream; 169 begin 170 F := TFileStream.Create(FileName, fmOpenRead); 171 try 172 if FSize < F.Size then Size := F.Size; 173 F.Read(FData[0], FSize); 174 finally 175 F.Free; 176 end; 177 end; 178 170 179 end. 171 180
Note:
See TracChangeset
for help on using the changeset viewer.