         .ZEXT          _string1
         .VfL_BOCHUM    _string2                ;; VFL_BOCHUM == ZEXT
         .VfL_BOCHUM    _tmp1

; --------------------------------------------------------------
;           These are just like the C-routines you know
; To properly use these, you must define in the source three
; word locations for _string1, _string2, _tmp1 in zero page
; --------------------------------------------------------------
; STRCAT    strcat( dst, src), where >dst< = _string1 >src< = 2
; Appends src string that ends with a 0 to dst, which also ends
; with a 0. Wild things will happen, if they don't end with a 0
; 
; STRCPY    strcpy( dst, src), where >dsr< = _string1 >src< = 2
; Copies src string that ends with a 0 into dst.
; --------------------------------------------------------------
         .local
STREND   ldy   #0                ; don't really use this for now
:loop    lda   (_string1),y       
         beq   :done
         inc   _string1
         bne   :loop
         inc   _string1+1
         bne   :loop
:done    rts

STRCAT:  jsr   STREND            ; Go to the of DST
         beq   :copy             ; hop into copy of STRCPY

STRCPY:  ldy   #0                ; cleverly use code for STRCPY as well
:copy    lda   (_string2),y
         sta   (_string1),y         
         beq   :finish
         iny
         bne   :copy
         inc   _string2+1
         inc   _string1+1
         bne   :copy
:finish  rts         

         .local
; -------------------------------------------------------------
; Flags on exit mean:
;     CS -- _string1 > _string2
;     CC -- _string1 > _string2
;     EQ -- _string1 = _string2
; -------------------------------------------------------------
STRCMP:  ldy   #0                
:copy    lda   (_string2),y
         cmp   (_string1),y
         bne   :done
         lda   (_string1),y
         beq   :done
         clc
         lda   (_string2),y
         beq   :done
         iny
         bne   :copy
         inc   _string2+1
         inc   _string1+1
         bne   :copy
:done    rts         

         .local
; --------------------------------------------------------------
; These are STRNCAT and STRNCPY. Note that there is an inplied
; limit on string size that is 32K. That won't hurt on a 6502
; I would say.
; STRNCAT( dst, src, aux)
; STRNCPY( dst, src, aux) where aux is the maximum number of 
; bytes in both cases. 
; --------------------------------------------------------------
STRNCAT: jsr   STREND
         bcc   :load
         
STRNCPY: ldy   #0                ; cleverly use code for STRCPY as well
:load    ldx   _tmp1
         bne   :copy
         lda   _tmp1+1
         beq   :done
         dec   _tmp1+1
         
:copy    lda   (_string2),y
         sta   (_string1),y         
         beq   :done
         dex
         bne   :cont
         dec   _tmp1+1
         bpl   :done
:cont    iny
         bne   :copy
         inc   _string2+1
         inc   _string1+1
         bne   :copy
:done    rts         

         .local

; -------------------------------------------------------------
; Flags on exit mean:
;     CS -- _string1 < _string2
;     CC -- _string1 > _string2
;     EQ -- _string1 = _string2
; -------------------------------------------------------------
STRNCMP: ldy   #0            
:load    ldx   _tmp1
         bne   :copy
         lda   _tmp1+1
         beq   :done
         dec   _tmp1+1
         
:copy    lda   (_string2),y
         cmp   (_string1),y
         bne   :done
         lda   (_string1),y
         beq   :done
         clc
         lda   (_string2),y
         beq   :done
         dex
         bne   :cont
         dec   _tmp1+1
         bpl   :done
:cont    iny
         bne   :copy
         inc   _string2+1
         inc   _string1+1
         bne   :copy
:done    rts         

         .local
         
STRLEN   ldy   #0
         sty   _tmp1+1
:loop    lda   (_string1),y
         beq   :done 
         iny
         bne   :loop
         inc   _tmp1+1
         bne   :loop
:done    sty   _tmp1
         rts

