; STR_CMP -- bounded unsigned-byte lexicographic compare.
; Inputs: $10/$11 A pointer, $12 A cap; $13/$14 B pointer, $15 B cap.
; Output: $0 status; $8=FFh (A<B), 00h (equal), 01h (A>B) on success;
; $8=0 on failure. Both strings prevalidated through their NUL.
; Requires: str_abi.inc included exactly once. No code dependencies.
; Input registers $10..$15, RAM preserved. Clobbers $0,$8,$9,$16..$18,
; $20,IX,flags. Preconditions: same UA-selected bank; $SY=1; zero initializers are immediates;
; all declared spans fit without 16-bit wrapping.
#LIST
STR_CMP:
LD $8,0
LD $0,STR_BCAP
AN $12,$12
JR Z,_STR_CMP_RET
AN $15,$15
JR Z,_STR_CMP_RET
; Validate A fully, even if lexical difference occurs early.
LD $9,0
PRE IX,$10
_STR_CMP_VA:
LD $16,(IX+$9)
AN $16,$16
JR Z,_SC_B_INIT
AD $9,$SY
LD $18,$9
SBC $18,$12
JR C,_STR_CMP_VA
JR _SC_UNTERM
_SC_B_INIT:
LD $9,0
PRE IX,$13
_STR_CMP_VB:
LD $16,(IX+$9)
AN $16,$16
JR Z,_SC_CINIT
AD $9,$SY
LD $18,$9
SBC $18,$15
JR C,_STR_CMP_VB
_SC_UNTERM:
LD $0,STR_UNTR
_STR_CMP_RET:
RTN
_SC_CINIT:
LD $9,0
_STR_CMP_LOOP:
PRE IX,$10
LD $16,(IX+$9)
PRE IX,$13
LD $17,(IX+$9)
LD $18,$16
SBC $18,$17
JR Z,_SC_EQBYT
JR C,_STR_CMP_LESS
LD $8,$SY
JR _STR_CMP_OK
_STR_CMP_LESS:
LD $8,&HFF
JR _STR_CMP_OK
_SC_EQBYT:
AN $16,$16
JR Z,_STR_CMP_OK
AD $9,$SY
JR _STR_CMP_LOOP
_STR_CMP_OK:
LD $0,STR_OK
RTN