; ======================================================================
; CS617 chapter01-u32calc-v2: r005 candidate reusable decimal parser.
; UPARSE32DEC accepts a caller-owned decimal ASCII field in UA=14 RAM.
;
; Entry: IX points to string; $12 = byte length (0..255), no NUL
; traversal. $SX=1, $SY=1, $SZ=0, system stack initialized.
; Output: $4 = 0 success, 1 overflow, 2 nondecimal digit, 3 empty.
; On SUCCESS, $15..$18 = U32, little-endian words.
; On FAILURE, $15..$18 are unspecified partial state, not a result.
; All intermediate arithmetic is checked by UDECAPP, never wrapped.
; IX, $12 unchanged; clobbers $0..$11, $13, $14, CPU flags.
; Dependencies: UDECAPP, UMUL32, UADD32; no app-specific symbols.
; This is a LIBRARY CANDIDATE, not a promoted lib-set-01 API.
; It intentionally accepts only digits (no signs or whitespace).
; ======================================================================
#LIST
UPARSE32DEC:
        SBW     $15,$15
        SBW     $17,$17
        LD      $13,0
        AN      $12,$12
        JP      Z,UP32D_EMPTY
UP32D_LOOP:
        LD      $5,(IX+$13)
        SBC     $5,&H30
        JP      C,UP32D_BAD
        SBC     $5,&H3A
        JP      NC,UP32D_BAD
        SB      $5,&H30
        CAL     UDECAPP
        AN      $4,$4
        JP      NZ,UP32D_OVERFLOW
        AD      $13,$SY
        SBC     $13,$12
        JP      C,UP32D_LOOP
        LD      $4,0
        RTN
UP32D_EMPTY:
        LD      $4,3
        RTN
UP32D_BAD:
        LD      $4,2
        RTN
UP32D_OVERFLOW:
        LD      $4,1
        RTN
