O100 sub (square [x0] [y0] [z0] [zr] [f1] [f2])
        (cut a 1x1 square)
        (#1 = z0 = depth of cut)
        (#2 = zr = retract after cut)
        (#3 = f1 = feed to cutting depth)
        (#4 = f2 = feed for square)
        (assumes already at safety height)
G0 X0 Y0
        (Can replace the following 4-6 lines with custon code)
G1 Z#1 F#3
G1 X1 F#4
G1 Y1
G1 X0
G1 Y0
G0 Z#2

O100 endsub

O200 sub (l2r [x0] [y0] [dx] [count] [z0] [zr] [f1] [f2])
        (#1 = x0 = least x coordinate)
        (#2 = y0 = common y coordinate for all squares)
        (#3 = dx = increment between x coordinates)
        (#4 = count = number of squares in row)
        (#5 = z0 = depth of cut)
        (#6 = zr = retract after cut)
        (#7 = f1 = feed to cutting depth)
        (#8 = f2 = feed for square)
        (cut squares from left to right at constant Y)
(#9 = temporary for count of squares in row)
#9=0
O210 while [#9 LT #4]

G0 X[#1+#9*#3] Y#2
G92 X0 Y0
O100 call [#5] [#6] [#7] [#8]
G92.1

#9=[#9+1]
O210 endwhile
O200 endsub

O300 sub (r2l [x0] [y0] [dx] [count] [z0] [zr] [f1] [f2])
        (parameters as for O200 sub)
        (cut squares from right to left at constant Y)
#9=[#4-1]
O310 while [#9 GE 0]

G0 X[#1+#9*#3] Y#2
G92 X0 Y0
O100 call [#5] [#6] [#7] [#8]
G92.1

#9=[#9-1]
O310 endwhile
O300 endsub

O400 sub (squares [x0] [y0] [dx] [dy] [xcount] [ycount] [z0] [zr] [f1] [f2])
        (#1 = x0 = least x coordinate)
        (#2 = y0 = least y coordinate)
        (#3 = dx = increment between x coordinates)
        (#4 = dy = increment between y coordinates)
        (#5 = xcount = number of squares in row)
        (#6 = ycount = number of rows)
        (#7 = z0 = depth of cut)
        (#8 = zr = retract after cut)
        (#9 = f1 = feed to cutting depth)
       (#10 = f2 = feed for square)
(#11 = temporary for count of rows)
#11=0
O410 while [#11 LE #6]
O420 if [[#11 MOD 2] EQ 0]
O200 call [#1] [#2+#11*#4] [#3] [#5] [#7] [#8] [#9] [#10]
O420 else
O300 call [#1] [#2+#11*#4] [#3] [#5] [#7] [#8] [#9] [#10]
O420 endif
#11=[#11+1]
O410 endwhile
O400 endsub

G92.1

G20
M3 S1000
O400 call [0] [0] [1.5] [1.5] [4] [5] [-1] [1] [12] [30]
M2

Add a code snippet to your website: www.paste.org