EDIT: tweaked the -36 IDs from X32/Y32 to X24/Y16 - the actual auto-assigned IDs of the first expansion module on a -36
To expound on RBPLC's idea, create 2 bit blocks, _X and _Y (or something else close to X/Y), then use BYTE casts (or WORD or DWORD casts) to quickly copy the individual bits across (MAPIO is slow compared to BYTE sized memory copies). MEMCOPY is fast - it's memory-based "copy" (vs. value based "copy"). Change all your logic to use _X and _Y, not X/Y.
So in your -36
in $tTopOfScan code block
MEMCOPY X24:UB _X0:UB 8 // I guessed 8 BYTEs, or 64 X's
in $tBottomOfScan code-block
MEMCOPY _Y0:UB Y16:UB 8 // again, guessed 8 BYTEs, or 64 Y's
When you get your -M, change those two instructions to
MEMCOPY X0:UB _X0:UB 8
and
MEMCOPY _Y0:UB Y0:UB 8
the logic just continues to utilize _X and _Y elements, not the actual X/Y elements.
Yeah, it's a hack - and can be confusing, especially on your test system where the X/Y IDs do NOT match.
The benefit is that the _X ID's and _Y ID's would match the engineering drawings in both the -M and -36 systems - and in the final -M system, the actual X/Y IDs would also match.