anchor.diff:    _6 = (1 shl 6);
     _7 = (1 shl 7);
   
  +  NOT_TOP_MASK = not (_0 or _1 or _2);
  +  NOT_RIGHT_MASK = not (_2 or _3 or _4);
  +  NOT_BOTTOM_MASK = not (_4 or _5 or _6);
  +  NOT_LEFT_MASK = not (_6 or _7 or _0);
  +
     DEFAULT_MASKS: array[TTileMapKind] of Word = (
       {mkSimple}     (_1 or _3 or _5 or _7) * $0101,
       {mkDiagonal}   $FF * $0101,
  
positive.code:     NodeBuffers: PCPFNodeBuffers;
    {$endif}
  begin
    MaxI := Self.Width - 1;
    MaxJ := Self.Height - 1;
    Rounded := (Self.Kind = mkDiagonalEx);
    CellOffsets := @Self.FInfo.CellOffsets;
    Cell := @Self.FInfo.CellArray[0];
  
negative.code:   until (False);
  end;
  
  
  {$ifNdef CPFLIB}
  procedure TTileMapClear(const Self: TTileMap); forward;
  procedure TTileMap.Clear;
  begin
    FCallAddress := ReturnAddress;
    TTileMapClear(Self);
  end;
  procedure TTileMapClear(const Self: TTileMap);
  {$else}
  procedure TTileMap.Clear;
  {$endif}
  const
    HEXAGONAL_CELL_EVEN = $01000000 or (_0 or _1 or _3 or _5 or _6 or _7) shl 8;
    HEXAGONAL_CELL_ODD = $01000000 or (_1 or _2 or _3 or _4 or _5 or _7) shl 8;
  var
    i: NativeInt;
    Cell: PCPFCell;
    MaximumI, Size: NativeInt;
    NotRightMask: Integer{Byte};
  begin
    // release nodes
    Self.ReleaseAllocatedNodes(False);
    Self.FNodes.Heuristed.First.Next := @Self.FNodes.Heuristed.Last;
    Self.FNodes.Heuristed.Last.Prev := @Self.FNodes.Heuristed.First;
    Self.FActualInfo.FinishPoint.X := -1;
    Self.FActualInfo.FinishPoint.Y := -1;
  
    // cells
    if (Self.Kind = mkHexagonal) then
    begin
      Cell := @Self.FInfo.CellArray[0];
      Size := Self.Width * SizeOf(TCPFCell);
  
      for i := 0 to NativeInt(Self.Height shr 1) - 1 do
      begin
        FillCardinal(PCardinal(Cell), Size shr 2, HEXAGONAL_CELL_EVEN);
        Inc(NativeInt(Cell), Size);
        FillCardinal(PCardinal(Cell), Size shr 2, HEXAGONAL_CELL_ODD);
        Inc(NativeInt(Cell), Size);
      end;
  
      if (Self.Height and 1 <> 0) then
        FillCardinal(PCardinal(Cell), Size shr 2, HEXAGONAL_CELL_EVEN);
    end else
    begin
      FillCardinal(PCardinal(Self.FInfo.CellArray), Self.FCellCount,
       (Cardinal(DEFAULT_MASKS[Self.Kind]) and $ff00) or $01000000);
    end;
    Self.FActualInfo.TilesChanged := True;
  
    // around cells
    MaximumI:= Self.Width - 1;
    NotRightMask := NOT_RIGHT_MASK;
    if (Self.Kind = mkHexagonal) then NotRightMask := NotRightMask and not (_1 or _5);
    Cell := @Self.FInfo.CellArray[0];
    begin
      // top
      Cell.Mask := Cell.Mask and (NOT_LEFT_MASK and NOT_TOP_MASK);
      Inc(Cell);
      for i := 1 to MaximumI do
      begin
        Cell.Mask := Cell.Mask and NOT_TOP_MASK;
        Inc(Cell);
      end;
      Cell.Mask := Cell.Mask and Integer(NotRightMask and NOT_TOP_MASK);
      Inc(Cell);
  
      // each line
      for i := 1 to NativeInt(Self.FHeight) - 2 do
      begin
        Cell.Mask := Cell.Mask and NOT_LEFT_MASK;
        Inc(Cell, MaximumI);
        Cell.Mask := Cell.Mask and NotRightMask;
        Inc(Cell);
      end;
  
      // bottom
      Cell.Mask := Cell.Mask and (NOT_LEFT_MASK and NOT_BOTTOM_MASK);
      Inc(Cell);
      for i := 1 to MaximumI do
      begin
        Cell.Mask := Cell.Mask and NOT_BOTTOM_MASK;
        Inc(Cell);
      end;
      Cell.Mask := Cell.Mask and Integer(NotRightMask and NOT_BOTTOM_MASK);
    end;
  
    // hexagonal odd right
    if (Self.Kind = mkHexagonal) and (MaximumI <> 0) then
    begin
      Size := (MaximumI + 1) * SizeOf(TCPFCell);
      Cell := @Self.FInfo.CellArray[MaximumI*2 + 1];
  
      for i := 0 to NativeInt(Self.Height shr 1) - 1 do
      begin
        Cell.Mask := Cell.Mask and NOT_BOTTOM_MASK;
        Inc(NativeInt(Cell), Size);
      end;
    end;
  
    // sectors
    if (Self.SectorTest) then
    begin
      Size := (SizeOf(Byte) * Self.FCellCount + 3) and -4;
      if (Self.FActualInfo.Sectors = nil) then Self.CPFGetMem(Pointer(Self.FActualInfo.Sectors), Size);
      FillCardinal(PCardinal(Self.FActualInfo.Sectors), Size shr 2, $02020202);
      Self.FActualInfo.SectorsChanged := False;
    end else
    begin
      Self.FActualInfo.SectorsChanged := True;
    end;
  end;
  
  function TTileMap.GetTile(const X, Y: Word): Byte;
  