[%  PROCESS ps/mm    UNLESS global.ps.loaded.mm;
    PROCESS ps/clip  UNLESS global.ps.loaded.clip;
    PROCESS ps/tiles UNLESS global.ps.loaded.tiles;
    global.ps.loaded.tilemap = 1;
-%]
/tilemap {
    gsave
    /tilemap-mapx clip-xsize 15 div def
    /tilemap-mapy clip-ysize 15 div def
    /tilemap-gapx tilemap-mapx 5 div def
    /tilemap-gapy tilemap-gapx def
    /tilemap-xsize tilemap-mapx tilemap-gapx add def
    /tilemap-ysize tilemap-mapy tilemap-gapy add def
    /tilemap-xorg clip-blx tilemap-gapx add def
    /tilemap-yorg clip-try tilemap-ysize tiles-ny mul sub def
    % foreach tile in x
    0 1 tiles-nx 1 sub {
        /tilemap-tx exch def
        % foreach tile in y
        0 1 tiles-ny 1 sub {
            /tilemap-ty exch def
            % fill tile if current page
            tilemap-tx tilepage-x eq tilemap-ty tilepage-y eq and {
                tilemap-xorg tilemap-tx tilemap-xsize mul add
                tilemap-yorg tilemap-ty tilemap-ysize mul add
                tilemap-mapx tilemap-mapy .9 setgray rectfill
                0.2 setgray
                0.5 setlinewidth
            } {
                0.5 setgray
                0.5 setlinewidth
            } ifelse
            % outline tile
            tilemap-xorg tilemap-tx tilemap-xsize mul add
            tilemap-yorg tilemap-ty tilemap-ysize mul add
            tilemap-mapx tilemap-mapy rectstroke
        } for
    } for
    grestore
} def
