Magic squares of singly even order

Magic squares of singly even order
You are encouraged to solve this task according to the task description, using any language you may know.

A magic square is an NxN square matrix whose numbers consist of consecutive numbers arranged so that the sum of each row and column, and both diagonals are equal to the same sum (which is called the magic number or magic constant).

A magic square of singly even order has a size that is a multiple of 4, plus 2 (e.g. 6, 10, 14). This means that the subsquares have an odd size, which plays a role in the construction.

-- fill pattern a c -- d b -- main loop for creating magic square in section a -- the value for b,c and d is derived from a while true do if sq[x1,y1]=0 then x2 = x1+sq_d_2 y2 = y1+sq_d_2 sq[x1,y1] = r -- a sq[x2,y2] = r+q2 -- b sq[x2,y1] = r+q2*2 -- c sq[x1,y2] = r+q2*3 -- d if mod(r,sq_d_2)=0 then y1 += 1 else x1 += 1 y1 -= 1 end if r += 1 end if if x1>sq_d_2 then x1 = 1 while sq[x1,y1] <> 0 do x1 += 1 end while end if if y1<1 then y1 = sq_d_2 while sq[x1,y1] <> 0 do y1 -= 1 end while end if if r>q2 then exit end if end while

-- swap left side for y1=1 to sq_d_2 do y2 = y1+sq_d_2 for x1=1 to l do sq = swap(sq, x1,y1, x1,y2) end for end for