; File: pasmove.text
; Date: 15-Dec-80

        IDENT   PASMOVE
        
        GLOBAL  %_MOVEL,%_MOVER,%_FILLC,%_SCANE,%_SCANN
        
;
; $_MOVEL - Moveleft
;
; Parameters: ST.L - From Address
;             ST.L - To Address
;             ST.W - # Bytes to move
;

%_MOVEL 
        MOVE.L  (SP)+,A2        ; Pop return address
        MOVE.W  (SP)+,D0        ; Pop # bytes
        MOVE.L  (SP)+,A0        ; Pop TO address
        MOVE.L  (SP)+,A1        ; Pop FROM address
        BRA.S   L_TEST
L_LOOP  MOVE.B  (A1)+,(A0)+
L_TEST  SUBQ.W  #1,D0
        BPL.S   L_LOOP
        JMP     (A2)
        
;
; $_MOVER - Moveright
;
; Parameters: ST.L - From Address
;             ST.L - To Address
;             ST.W - # Bytes to move
;

%_MOVER 
        MOVE.L  (SP)+,A2        ; Pop return address
        MOVE.W  (SP)+,D0        ; Pop # bytes
        MOVE.L  (SP)+,A0        ; Pop TO address
        MOVE.L  (SP)+,A1        ; Pop FROM address
        ADDA.W  D0,A0
        ADDA.W  D0,A1
        BRA.S   R_TEST
R_LOOP  MOVE.B  -(A1),-(A0)
R_TEST  SUBQ.W  #1,D0
        BPL.S   R_LOOP
        JMP     (A2)
        
;
; $_FILLC - Fillchar
;
; Parameters: ST.L - Address to fill
;             ST.W - # Bytes
;             ST.W - Char
;

%_FILLC 
        MOVE.L  (SP)+,A2        ; Pop return address
        MOVE.W  (SP)+,D0        ; Pop character
        MOVE.W  (SP)+,D1        ; Pop # bytes
        MOVE.L  (SP)+,A0        ; Pop address to fill
        BRA.S   F_TEST
F_LOOP  MOVE.B  D0,(A0)+
F_TEST  SUBQ.W  #1,D1
        BPL.S   F_LOOP
        JMP     (A2)

;
; $_SCANE - Scan equal
;
; Parameters: ST.W - Length to scan
;             ST.W - Character to scan for
;             ST.L - Address to scan
;
; Result:     ST.W - Result
;
; All registers are preserved.
;

%_SCANE 
        MOVEM.L D0-D2/A0,-(SP)
        CLR.W   D2              ; The Result
        MOVE.L  20(SP),A0       ; Address to scan
        MOVE.W  24(SP),D0       ; Character to scan for
        MOVE.W  26(SP),D1       ; Length to scan
        BEQ.S   SE_DONE
        BMI.S   SE_MI
EP_LOOP CMP.B   (A0)+,D0
        BEQ.S   SE_DONE
        ADDQ.W  #1,D2           ; Bump result
        SUBQ.W  #1,D1
        BGT.S   EP_LOOP
        BRA.S   SE_DONE
SE_MI   ADDQ.L  #1,A0
EM_LOOP CMP.B   -(A0),D0
        BEQ.S   SE_DONE
        SUBQ.W  #1,D2
        ADDQ.W  #1,D1
        BMI.S   EM_LOOP
SE_DONE MOVE.W  D2,26(SP)       ; Store the result
        MOVE.L  16(SP),22(SP)   ; Set up return address
        MOVEM.L (SP)+,D0-D2/A0
        ADDQ.L  #6,SP
        RTS

;
; $_SCANN - Scan not equal
;
; Parameters: ST.W - Length to scan
;             ST.W - Character to scan for
;             ST.L - Address to scan
;
; Result:     ST.W - Result
;
; All registers are preserved.
;

%_SCANN 
        MOVEM.L D0-D2/A0,-(SP)
        CLR.W   D2              ; The Result
        MOVE.L  20(SP),A0       ; Address to scan
        MOVE.W  24(SP),D0       ; Character to scan for
        MOVE.W  26(SP),D1       ; Length to scan
        BEQ.S   SN_DONE
        BMI.S   SN_MI
NP_LOOP CMP.B   (A0)+,D0
        BNE.S   SN_DONE
        ADDQ.W  #1,D2           ; Bump result
        SUBQ.W  #1,D1
        BGT.S   NP_LOOP
        BRA.S   SN_DONE
SN_MI   ADDQ.L  #1,A0
NM_LOOP CMP.B   -(A0),D0
        BNE.S   SN_DONE
        SUBQ.W  #1,D2
        ADDQ.W  #1,D1
        BMI.S   NM_LOOP
SN_DONE MOVE.W  D2,26(SP)       ; Store the result
        MOVE.L  16(SP),22(SP)   ; Set up return address
        MOVEM.L (SP)+,D0-D2/A0
        ADDQ.L  #6,SP
        RTS

        END

