#ifmain ;-----------------------------------------------------------------------
                    #ListOff
                    #Uses     mcu.inc
                    #ListOn
#endif ;------------------------------------------------------------------------
?_OBJECT_?
;*******************************************************************************
; Purpose: Return the length of an ASCIZ string
; Input  : HX -> string
; Output : A = Length
;        : CCR matches RegA contents (a welcome side effect)
; Note(s): Returned length is zero when string is longer than 255

StringLength        macro     [[#]StringVariable] ;if no parm, use current HX
          #ifb ~@~
                    call      ~0~
                    mexit
          #endif
                    #push
                    #spauto   :sp
                    pshhx
                    @@lea     ~@~
                    call      ~0~
                    pulhx
                    #pull
                    endm

;-------------------------------------------------------------------------------

                    #spauto

StringLength        proc
                    pshhx
                    clra
Loop@@              tst       ,x
                    beq       Done@@              ;on ASCIZ terminator, done
                    aix       #1                  ;bump up pointer
                    dbnza     Loop@@
Done@@              nega                          ;(now CCR matches A value)
                    pulhx
                    rtc

                    #sp
;*******************************************************************************
                    #Exit
;*******************************************************************************
                    @EndStats