 MACRO
&lab Int2Hex &a1
&lab ph2 &a1(1)
 ph4 &a1(2)
 ph2 &a1(3)
 Tool $220b
 mend
 MACRO
&lab ErrWriteLine &a1
&lab ph4 &a1
 Tool $1b0c
 mend
 MACRO
&lab ErrWriteString &a1
&lab ph4 &a1
 Tool $1d0c
 mend
 MACRO
&lab ErrWriteCString &a1
&lab ph4 &a1
 Tool $210c
 mend
 MACRO
&lab tool &a1
&lab ldx #&a1
 jsl $e10000
 mend
 MACRO
&lab ph2 &parm
 lclc &char
&lab anop
 aif c:&parm=0,.done
&char amid &parm,1,1
 aif "&char"="#",.immediate
 aif "&char"="@",.at
 aif s:longa=1,.chk
 rep #%00100000
.chk
 aif "&char"<>"{",.absolute
&char amid &parm,l:&parm,1
 aif "&char"<>"}",.error
&parm amid &parm,2,l:&parm-2
 lda (&parm)
 pha
 ago .shorten
.absolute
 lda &parm
 pha
 ago .shorten
.immediate
&parm amid &parm,2,l:&parm-1
 pea &parm
 ago .done
.at
&char amid &parm,2,1
 ph&char
.shorten
 aif s:longa=1,.done
 sep #%00100000
.done
 mexit
.error
 mnote "Missing closing '}'",16
 mend
 MACRO
&lab ph4 &parm
 lclc &char
 lclc &char1
 lclc &char2
&lab anop
&char amid &parm,1,1
 aif "&char"="#",.immediate
 aif "&char"="@",.at
 aif s:longa=1,.chk1
 rep #%00100000
.chk1
 aif "&char"<>"{",.chk2
&char amid &parm,l:&parm,1
 aif "&char"<>"}",.error
&parm amid &parm,2,l:&parm-2
 ldy #2
 lda (&parm),y
 pha
 lda (&parm)
 pha
 ago .shorten
.chk2
 aif "&char"<>"[",.absolute
 ldy #2
 lda &parm,y
 pha
 lda &parm
 pha
 ago .shorten
.absolute
 lda &parm+2
 pha
 lda &parm
 pha
 ago .shorten
.at
&char1 amid &parm,2,1
&char2 setc &char1
 ph&char1
 aif l:&parm<3,.chk2a
&char2 amid &parm,3,1
.chk2a
 ph&char2
 ago .shorten
.immediate
&parm amid &parm,2,l:&parm-1
 pea +(&parm)|-16
 pea &parm
 ago .done
.shorten
 aif s:longa=1,.done
 sep #%00100000
.done
 mexit
.error
 mnote "Missing closing '}'",16
 mend
 MACRO
&lab Str &string
&lab dc i1'L:&string'
 dc c"&string"
 mend
 MACRO
&lab proc &rg
&lab anop
 aif c:&rg,.cc
 lclc &rg
.cc
 aif c:&reg,.dd
 gblc &reg
.dd
&reg setc ""
 phb
 aif l:&rg=0,.bb
&reg setc &rg
 lcla &plen
 lclc &ch
 lcla &i
&plen seta l:&reg
&i seta 0
.aa
 aif &i=&plen,.bb
&i seta &i+1
&ch amid &reg,&i,1
 ph&ch
 ago ^aa
.bb
 phk
 plb
 mend
 MACRO
&lab procendL
&lab anop
 lclc &ch
 lcla &plen
&plen seta l:&reg
.aa
 aif &plen=0,.bb
&ch amid &reg,&plen,1
 pl&ch
&plen seta &plen-1
 ago ^aa
.bb
 plb
 rtl
 mend
 MACRO
&lab add2 &arg1,&arg2,&dest
 lclc &char
&lab clc
&char amid &arg1,1,1
 aif "&char"="@",.at1
 lda &arg1
 ago .add
.at1
&char amid &arg1,2,1
 aif "&char"="x",.x1
 aif "&char"="X",.x1
 aif "&char"="y",.y1
 aif "&char"="Y",.y1
 ago .add
.x1
 txa
 ago .add
.y1
 tya
.add
 adc &arg2
&char amid &dest,1,1
 aif "&char"="@",.at2
 sta &dest
 ago .b
.at2
&char amid &dest,2,1
 aif "&char"="x",.x2
 aif "&char"="X",.x2
 aif "&char"="y",.y2
 aif "&char"="Y",.y2
 ago .b
.x2
 tax
 ago .b
.y2
 tay
.b
 mend
 MACRO
&lab name
&lab anop
 aif DebugSymbols=0,.pastName
 brl pastName&SYSCNT
 dc i'$7771'
 dc i1'L:&lab',c'&lab'
pastName&SYSCNT anop
.pastName
 MEND
