*--------!-!-!-!-!-!-!-!-----------------!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!R
*********************************************
*
*        8290.6 GST 75/0.00
*
*        Library of block & string operations
*
*********************************************
;
;        Jump Table of Entrypoints
;        =========================
 
 
         JMP      XCOMPSTR                   0: compare strings
         JMP      XCOPYSTR                   4: copy strings
         JMP      XCOPYBLK                   8: copy memory block
         JMP      XCOFILL                    C: fill memory block
 
         PAGE
*********************************************
*
*        XCOMPSTR
*        ========
*
*        This routine compares two strings.
*
*        Entry:  A0    first string
*                A1    second string
*
*        Exit:   D0.L  -1  (A0) < (A1)
*                       0  (A0) = (A1)
*                      +1  (A0) > (A1)
 
 
 
RCOMPSTR REG D1/A2-A3
 
XCOMPSTR:
         MOVEM.L   RCOMPSTR,-(A7)            save registers
         MOVE.W    (A0),D0                   length of the A0 string
         CMP.W     (A1),D0                   see which is smaller ...
         BLE       XCOMPS10                  ... and get smaller ...
           MOVE.W    (A1),D0                 ... into D0
         XCOMPS10:
*
*        D0 now contains the length of the shorter string
*
*        Compare the strings until a difference is found or the
*        shorter string is exhausted.
*
         LEA     2(A0),A2
         LEA     2(A1),A3
 
         BRA     XCOMPS16                    check for zero length
         XCOMPS15:
           CMP.B     (A2)+,(A3)+             compare a byte
           BLT       XCOMPS20                (A0) > (A1)
           BGT       XCOMPS30                (A0) < (A1)
         XCOMPS16:
         DBRA      D0,XCOMPS15
  
*        The strings are equal as far as they go;  the shorter one
*        is smaller or they are equal.
*
         MOVE.W      (A1),D0
         CMP.W       (A0),D0
         BLT         XCOMPS20
         BGT         XCOMPS30
*
*        (A0) = (A1)
*
         MOVE.L      #0,D0
         BRA         XCOMPS99
*
*        (A0) > (A1)
*
         XCOMPS20:
         MOVE.L      #1,D0
         BRA         XCOMPS99
*
*        (A0) < (A1)
*
         XCOMPS30:
         MOVE.L      #-1,D0                  falls through ...
*
*        Finished
*
         XCOMPS99:
         MOVEM.L   (A7)+,RCOMPSTR
         RTS
         PAGE
*********************************************
*
*        XCOPYSTR
*        ========
*
*        Copy a string.
*
*        Entry:  A0    source string
*                A1    destination memory area
*
*        Exit:
*
XCOPYSTR
         MOVE.L    D0,-(A7)                  preserve D0
*
*        Use XCOPYBLK to copy 2 bytes more than the string length
*        count (to include the string length count).
*
         MOVE.W    (A0),D0
         ADD.W     #2,D0                     length of string length
 
         BSR.S     XCOPYBLK
 
         MOVE.L    (A7)+,D0
         RTS
         PAGE
*********************************************
*
*        XCOPYBLK
*        ========
*
*        Copy a block of memory.  If the destination area is at a higher
*        address than the source then the copy
*        will be done backwards.
*
*        Entry:  D0.W  number of bytes to copy
*                A0    source
*                A1    destination
 
 
 
RCOPYBLK REG D0/A0-A1
 
XCOPYBLK MOVEM.L RCOPYBLK,-(A7)
*
*        The copy is done forwards unless:
*
*            A0 < A1
*
*        in which case it is done backwards.
*
         CMP.L     A0,A1
         BGT       XCOPYB50                  backwards if A0 < A1
*
*        Forwards copy
*
         SUB.W     #1,D0                     prepare loop counter
         BMI       XCOPYB99                  branch if copying 0 bytes
 
XCOPYB20
         MOVE.B    (A0)+,(A1)+               copy a byte
         DBRA      D0,XCOPYB20               loop until finished
 
         BRA       XCOPYB99
*
*        Copy backwards:  point A0 and A1 to the ends of the areas first
*
XCOPYB50
         ADD.W     D0,A0
         ADD.W     D0,A1
         SUB.W     #1,D0                     prepare loop counter
         BMI       XCOPYB99                  don't try to copy 0 bytes !
*
XCOPYB60
         MOVE.B    -(A0),-(A1)               copy a byte
         DBRA      D0,XCOPYB60
 
*
*        Finished
*        
XCOPYB99
         MOVEM.L   (A7)+,RCOPYBLK
         RTS
         PAGE
*********************************************
*
*        XCOFILL
*        =======
*
*        Fill an area of memory with a given byte value.
*
*        Entry:  D0.W  number of bytes to fill
*                D1.B  byte value
*                A0    destination
*
*        Exit:
 
 
RCOFILL  REG D0/A0
 
 
XCOFILL  MOVEM.L RCOFILL,-(A7)
 
         BRA     COFILL11                    check for 0 bytes
 
         COFILL10:
           MOVE.B   D1,(A0)+
         COFILL11:
         DBRA    D0,COFILL10
 
 
         MOVEM.L (A7)+,RCOFILL
         RTS
 
         END
