browser

contains.xyw

contains.xyw
calendarsave
; Pushes $01 if s1 contains s2, $00 otherwise
; s1 s2 -> f
; xw: index of string
; yw: index of fragment
; y : internal index within fragment
.label contains 
   POPyw POPxw ; save both addresses to xw and yw
   $00 POPy ; set y to zero
   .label contains.checks
     ; if at end of fragment, all good
     LDByw $00 EQU contains.ok JCNw
     ; if at end of string, fail
     LDBxw $00 EQU contains.fail JCNw
     ; check if contents of indexes are different
     LDBxyw NEQ contains.different JCNw
     ; otherwise they are matching 
     ; increment internal fragment index
     INCy
     ; increment both indexes 
     INCxyw
     contains.checks JMPw
   .label contains.str.incr
     ; increment only string
     INCxw
     contains.checks JMPw
   .label contains.different
     ; letters are different
     ; if started matching fragment, reset
     PSHy contains.reset JCNw
     ; otherwise increment string index
     contains.str.incr JMPw
   .label contains.reset
     ; reset fragment scan 
     PSHyw $00 PSHy SUBw POPyw
     ; reset string scan
     PSHxw $00 PSHy SUBw POPxw
     $00 POPy
     contains.str.incr JMPw
   .label contains.fail
     ; no match
     $00 RTS
   .label contains.ok
     ; fragment is contained in string
     $01 RTS