.title Byte Processing Routines ; DECUS C Calling Format ; ; jsr r5,csv$ ;save r2,r3, and r4 ; ;r5 is parameter base ; ;c$pmtr(r5) is first argument ; ;c$pmtr+2(r5) is second argument ; ;... ; ;return args in r0 ; ... ; user code ; ... ; ; jmp cret$ ;restore r2-r5 and return ; rts pc ;does the same (cret$ follows csv$) ; ; csv$ and cret$ need be used only if arguments are used ; ; ; Macro routines for special functions ; .psect c$code ; ; intswap ; swap byte positions integer ; ; in: 0 1 ; lobyte hibyte ; out: 0 1 ; hibyte lobyte ; intswap:: jsr r5,csv$ mov c$pmtr(r5),r0 swab r0 ;swap bytes of integer rts pc ; ; longswap ; swap byte positions long ; ; in: 0 1 2 3 ; 2nd 3rd 0th 1st ; out: 0 1 2 3 ; 3rd 2nd 1st 0th ; longswap:: jsr r5,csv$ mov c$pmtr(r5),r0 ;high word swab r0 ;swap bytes of word mov c$pmtr+2(r5),r1 ;low word swab r1 ;swap bytes of word rts pc ; ; movebytes ; arbitrary byte moves of any count ; usage: ; movebytes(to,from,n); ; note: ; buffers should not overlap ; movebytes:: jsr r5,csv$ mov c$pmtr(r5),r2 ;destination buffer address mov c$pmtr+2(r5),r1 ;source buffer address mov c$pmtr+4(r5),r0 ;byte count beq 6$ ;none - exit cmp #9.,r0 ;break point for fast word copy bhi 3$ mov r1,-(sp) ;check mismatched byte boundarys add r2,(sp) ror (sp)+ ;'c'=1 if odd/even or even/odd bcs 3$ ;no choice - slow copy bit #1,r1 ;odd byte ? beq 1$ ;no - skip movb (r1)+,(r2)+ ;get to even byte dec r0 1$: mov r0,-(sp) ;save count ash #-3,r0 ;divide by 8. 2$: mov (r1)+,(r2)+ ;copy word data quickly mov (r1)+,(r2)+ mov (r1)+,(r2)+ mov (r1)+,(r2)+ sob r0,2$ ;loop for 4 word groups mov (sp)+,r0 ;retrieve count bic #^C7,r0 ;remaining bytes beq 6$ ;none - exit 3$: cmp #4.,r0 ;break point for fast byte copy bhi 5$ mov r0,-(sp) ;save count ash #-2,r0 ;divide by 4 4$: movb (r1)+,(r2)+ ;copy byte data quickly movb (r1)+,(r2)+ movb (r1)+,(r2)+ movb (r1)+,(r2)+ sob r0,4$ ;loop for 4 byte groups mov (sp)+,r0 ;retrieve count bic #^C3,r0 ;remaining bytes beq 6$ ;none - exit 5$: movb (r1)+,(r2)+ ;copy a byte at a time sob r0,5$ 6$: rts pc .end