Ignore:
Timestamp:
Oct 25, 2023, 12:33:07 AM (7 months ago)
Author:
chronos
Message:
  • Added: Common package.
  • Modified: Improved BigInt class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ByteArray/Devices/Memory.pas

    r46 r47  
    1717  public
    1818    Position: Integer;
    19     function Read(Address: TBigInt; Size: Byte): TBigInt;
    20     function ReadPos(Size: Byte): TBigInt;
    21     procedure Write(Address: TBigInt; Size: Byte; Value: TBigInt);
    22     procedure WritePos(Size: Byte; Value: TBigInt);
     19    function Read(Address: TBigInt; ASize: TBigIntSize): TBigInt;
     20    function ReadPos(ASize: Byte): TBigInt;
     21    procedure Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt);
     22    procedure WritePos(ASize: Byte; Value: TBigInt);
    2323    procedure WriteStringPos(Value: string);
    2424    function GetAddressCount: Integer; override;
     
    3030
    3131implementation
     32
     33resourcestring
     34  SOutOfRange = 'Out of range';
    3235
    3336{ TMemory }
     
    4346end;
    4447
    45 function TMemory.Read(Address: TBigInt; Size: Byte): TBigInt;
     48function TMemory.Read(Address: TBigInt; ASize: TBigIntSize): TBigInt;
    4649begin
    47   case Size of
     50  if Address + ASize >= Size then raise Exception.Create(SOutOfRange);
     51  case ASize of
    4852    1: Result := PByte(FData + Integer(Address))^;
    4953    2: Result := PWord(FData + Integer(Address))^;
     
    5357end;
    5458
    55 function TMemory.ReadPos(Size: Byte): TBigInt;
     59function TMemory.ReadPos(ASize: Byte): TBigInt;
    5660begin
    57   Result := Read(Position, Size);
     61  Result := Read(Position, ASize);
    5862end;
    5963
    60 procedure TMemory.Write(Address: TBigInt; Size: Byte; Value: TBigInt);
     64procedure TMemory.Write(Address: TBigInt; ASize: TBigIntSize; Value: TBigInt);
    6165begin
    62   case Size of
     66  if Address + ASize >= Size then raise Exception.Create(SOutOfRange);
     67  case ASize of
    6368    1: PByte(FData + Integer(Address))^ := Value;
    6469    2: PWord(FData + Integer(Address))^ := Value;
     
    6873end;
    6974
    70 procedure TMemory.WritePos(Size: Byte; Value: TBigInt);
     75procedure TMemory.WritePos(ASize: Byte; Value: TBigInt);
    7176begin
    72   Write(Position, Size, Value);
     77  Write(Position, ASize, Value);
    7378end;
    7479
Note: See TracChangeset for help on using the changeset viewer.