; ======================================================================
; STR_LEN -- candidate r001, bounded NUL-terminated byte length.
; Dependencies: str_abi.inc included once by composer; no code helpers.
;
; Input:  $10/$11 = 16-bit RAM pointer, $12 = readable capacity (1..255).
; Output: $0 = ST_*; $8 = text length (0..254) on success, 0 on error.
; Preconditions: UA selects the pointer's RAM bank; $SY=1; zero initializers are immediates;
;   the declared capacity fits a contiguous address range without wrap.
; Unchanged: input $10..$12 and RAM. Clobbered: $0,$8,$9,$16,IX,flags.
; No keyboard, display, serial, private RAM, or recursion dependencies.
; ======================================================================
#LIST
STR_LEN:
        LD      $8,0
        LD      $0,STR_BCAP
        AN      $12,$12
        JR      Z,STR_LEN_RET
        PRE     IX,$10
STR_LEN_SCAN:
        LD      $16,(IX+$8)
        AN      $16,$16
        JR      Z,STR_LEN_OK
        AD      $8,$SY
        LD      $9,$8
        SBC     $9,$12
        JR      C,STR_LEN_SCAN
        LD      $8,0
        LD      $0,STR_UNTR
STR_LEN_RET:
        RTN
STR_LEN_OK:
        LD      $0,STR_OK
        RTN
