Ignore:
Timestamp:
Aug 6, 2024, 10:31:16 PM (2 months ago)
Author:
chronos
Message:
  • Modified: Optimized DeviceMapper read/write handlers calls without case statement.
  • Modified: Use TInt as base data type which can be redefined to different higher integer type. For start it is Int64.
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
  • branches/ByteArray/Devices/FrameBuffer.pas

    r5 r9  
    44
    55uses
    6   Classes, SysUtils, Device, Channel, Memory, BigInt;
     6  Classes, SysUtils, Device, Channel, Memory, Int;
    77
    88type
     
    1515    FOnChange: TNotifyEvent;
    1616    procedure DoChange;
     17    function ReadData(Size: TIntSize): TInt;
     18    function ReadPosition(Size: TIntSize): TInt;
     19    function ReadWidth(Size: TIntSize): TInt;
     20    function ReadHeight(Size: TIntSize): TInt;
     21    function ReadMode(Size: TIntSize): TInt;
     22    procedure WriteData(Size: TIntSize; Value: TInt);
     23    procedure WritePosition(Size: TIntSize; Value: TInt);
     24    procedure WriteWidth(Size: TIntSize; Value: TInt);
     25    procedure WriteHeight(Size: TIntSize; Value: TInt);
     26    procedure WriteMode(Size: TIntSize; Value: TInt);
    1727  public
    1828    Memory: TMemory;
     
    2232    Mode: TScreenMode;
    2333    procedure UpdateMode;
    24     function Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
    25     procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
    26     function GetAddressCount: Integer; override;
    27     procedure SetChannel(Channel: TChannel); override;
     34    function GetHandlers: THandlers; override;
    2835    constructor Create;
    2936    destructor Destroy; override;
     
    4148end;
    4249
     50function TFrameBuffer.ReadData(Size: TIntSize): TInt;
     51begin
     52  Result := Memory.Read(Position, Size);
     53  Inc(Position, Size);
     54end;
     55
     56function TFrameBuffer.ReadPosition(Size: TIntSize): TInt;
     57begin
     58  Result := Position;
     59end;
     60
     61function TFrameBuffer.ReadWidth(Size: TIntSize): TInt;
     62begin
     63  Result := Width;
     64end;
     65
     66function TFrameBuffer.ReadHeight(Size: TIntSize): TInt;
     67begin
     68  Result := Height;
     69end;
     70
     71function TFrameBuffer.ReadMode(Size: TIntSize): TInt;
     72begin
     73  Result := Byte(Mode);
     74end;
     75
     76procedure TFrameBuffer.WriteData(Size: TIntSize; Value: TInt);
     77begin
     78  Memory.Write(Position, Size, Value);
     79  Inc(Position, Size);
     80end;
     81
     82procedure TFrameBuffer.WritePosition(Size: TIntSize; Value: TInt);
     83begin
     84  Position := Value;
     85end;
     86
     87procedure TFrameBuffer.WriteWidth(Size: TIntSize; Value: TInt);
     88begin
     89  Width := Value;
     90  UpdateMode;
     91end;
     92
     93procedure TFrameBuffer.WriteHeight(Size: TIntSize; Value: TInt);
     94begin
     95  Height := Value;
     96  UpdateMode;
     97end;
     98
     99procedure TFrameBuffer.WriteMode(Size: TIntSize; Value: TInt);
     100begin
     101  Mode := TScreenMode(Integer(Value));
     102  UpdateMode;
     103end;
     104
    43105procedure TFrameBuffer.UpdateMode;
    44106begin
     
    47109end;
    48110
    49 function TFrameBuffer.Read(Address: TBigInt; Size: TBigIntSize): TBigInt;
     111function TFrameBuffer.GetHandlers: THandlers;
    50112begin
    51   case Integer(Address) of
    52     0: begin
    53       Result := Memory.Read(Position, Size);
    54       Inc(Position, Size);
    55     end;
    56     1: Result := Position;
    57     2: Result := Width;
    58     3: Result := Height;
    59     4: Result := Byte(Mode);
    60   end;
    61 end;
    62 
    63 procedure TFrameBuffer.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt);
    64 begin
    65   case Integer(Address) of
    66     0: begin
    67       Memory.Write(Position, Size, Value);
    68       Inc(Position, Size);
    69     end;
    70     1: Position := Value;
    71     2: begin
    72       Width := Value;
    73       UpdateMode;
    74     end;
    75     3: begin
    76       Height := Value;
    77       UpdateMode;
    78     end;
    79     4: begin
    80       Mode := TScreenMode(Integer(Value));
    81       UpdateMode;
    82     end;
    83   end;
    84   DoChange;
    85 end;
    86 
    87 function TFrameBuffer.GetAddressCount: Integer;
    88 begin
    89   Result := 5;
    90 end;
    91 
    92 procedure TFrameBuffer.SetChannel(Channel: TChannel);
    93 begin
    94   Channel.Read := Read;
    95   Channel.Write := Write;
     113  Result := THandlers.Create;
     114  Result.ReadHandlers.Add(ReadData);
     115  Result.ReadHandlers.Add(ReadPosition);
     116  Result.ReadHandlers.Add(ReadWidth);
     117  Result.ReadHandlers.Add(ReadHeight);
     118  Result.ReadHandlers.Add(ReadMode);
     119  Result.WriteHandlers.Add(WriteData);
     120  Result.WriteHandlers.Add(WritePosition);
     121  Result.WriteHandlers.Add(WriteWidth);
     122  Result.WriteHandlers.Add(WriteHeight);
     123  Result.WriteHandlers.Add(WriteMode);
    96124end;
    97125
Note: See TracChangeset for help on using the changeset viewer.