{$IFDEF INTERFACE} TGMemory = class private FData: PByte; procedure SetSize(Value: TGMemoryData); function GetSize: TGMemoryData; public Position: TGMemoryData; {$IF TGMemoryWidth>=8} function Read8(Address: TGMemoryData): Byte; procedure Write8(Address: TGMemoryData; Data: Byte); function ReadPos8: Byte; procedure WritePos8(Data: Byte); {$ENDIF} {$IF TGMemoryWidth>=16} function Read16(Address: TGMemoryData): Word; procedure Write16(Address: TGMemoryData; Data: Word); function ReadPos16: Word; procedure WritePos16(Data: Word); {$ENDIF} {$IF TGMemoryWidth>=32} function Read32(Address: TGMemoryData): DWord; procedure Write32(Address: TGMemoryData; Data: DWord); function ReadPos32: DWord; procedure WritePos32(Data: DWord); {$ENDIF} {$IF TGMemoryWidth>=64} function Read64(Address: TGMemoryData): QWord; procedure Write64(Address: TGMemoryData; Data: QWord); function ReadPos64: QWord; procedure WritePos64(Data: QWord); {$ENDIF} procedure Clean; procedure SetDataBus(Channel: TGMemoryAddrChannel); property Size: TGMemoryData read GetSize write SetSize; end; {$UNDEF INTERFACE} {$ENDIF} {$IFDEF IMPLEMENTATION} procedure TGMemory.Clean; begin FillChar(FData^, Size, 0); end; procedure TGMemory.SetSize(Value: TGMemoryData); begin FData := ReAllocMem(FData, Value); end; function TGMemory.GetSize: TGMemoryData; begin Result := MemSize(FData); end; procedure TGMemory.SetDataBus(Channel: TGMemoryAddrChannel); begin {$IF TGMemoryWidth>=8} Channel.Read8 := Read8; Channel.Write8 := Write8; {$ENDIF} {$IF TGMemoryWidth>=16} Channel.Read16 := Read16; Channel.Write16 := Write16; {$ENDIF} {$IF TGMemoryWidth>=32} Channel.Read32 := Read32; Channel.Write32 := Write32; {$ENDIF} {$IF TGMemoryWidth>=64} Channel.Read64 := Read64; Channel.Write64 := Write64; {$ENDIF} end; {$IF TGMemoryWidth>=8} function TGMemory.Read8(Address: TGMemoryData): Byte; begin Result := PByte(FData + Address)^; end; procedure TGMemory.Write8(Address: TGMemoryData; Data: Byte); begin PByte(FData + Address)^ := Data; end; function TGMemory.ReadPos8: Byte; begin Result := PByte(FData + Position)^; Inc(Position); end; procedure TGMemory.WritePos8(Data: Byte); begin PByte(FData + Position)^ := Data; Inc(Position); end; {$ENDIF} {$IF TGMemoryWidth>=16} function TGMemory.Read16(Address: TGMemoryData): Word; begin Result := PWord(FData + Address)^; end; procedure TGMemory.Write16(Address: TGMemoryData; Data: Word); begin PWord(FData + Address)^ := Data; end; function TGMemory.ReadPos16: Word; begin Result := PWord(FData + Position)^; Inc(Position, SizeOf(Word)); end; procedure TGMemory.WritePos16(Data: Word); begin PWord(FData + Position)^ := Data; Inc(Position, SizeOf(Word)); end; {$ENDIF} {$IF TGMemoryWidth>=32} function TGMemory.Read32(Address: TGMemoryData): DWord; begin Result := PDWord(FData + Address)^; end; procedure TGMemory.Write32(Address: TGMemoryData; Data: DWord); begin PDWord(FData + Address)^ := Data; end; function TGMemory.ReadPos32: DWord; begin Result := PDWord(FData + Position)^; Inc(Position, SizeOf(DWord)); end; procedure TGMemory.WritePos32(Data: DWord); begin PDWord(FData + Position)^ := Data; Inc(Position, SizeOf(DWord)); end; {$ENDIF} {$IF TGMemoryWidth>=64} function TGMemory.Read64(Address: TGMemoryData): QWord; begin Result := PQWord(FData + Address)^; end; procedure TGMemory.Write64(Address: TGMemoryData; Data: QWord); begin PQWord(FData + Address)^ := Data; end; function TGMemory.ReadPos64: QWord; begin Result := PQWord(FData + Position)^; Inc(Position, SizeOf(QWord)); end; procedure TGMemory.WritePos64(Data: QWord); begin PQWord(FData + Position)^ := Data; Inc(Position, SizeOf(QWord)); end; {$ENDIF} {$UNDEF IMPLEMENTATION} {$ENDIF}