*/**//*/*//*//*/*//*//*/*/*//*/*/*/*//*/*/*/*//*//*//*///*/*/
bitcode:clr.l   d4
        cmpi.w  xmin,d0
        bge     b1
        or.b    #8,d4
b1:     cmpi.w  xmax,d0
        ble     b2
        or.b    #4,d4
b2:     cmpi.w  ymin,d1
        bge     b3
        or.b    #1,d4
b3:     cmpi.w  ymax,d1
        ble     b4
        or.b    #2,d4
b4:     move.w  d4,cbits
        rts
*****
bit2:   clr.l   d5
        cmpi.w  xmin,d2
        bge     b5
        or.b    #8,d5
b5:     cmpi.w  xmax,d2
        ble     b6
        or.b    #4,d5
b6:     cmpi.w  ymin,d3
        bge     b7
        or.b    #1,d5
b7:     cmpi.w  ymax,d3
        ble     b8
        or.b    #2,d5
b8:     move.w  d5,cbits2
        rts
********************************************************
clipit: bsr     bitcode
        bsr     bit2
clipit2:or.b    d4,d5
        tst.b   d5
        beq     cliphome        ;finish if
        move.w  cbits,d4
        move.w  d2,xsav
        move.w  d3,ysav
        move.w  cbits2,d5
clip1:  and.b   d4,d5
        tst.b   d5
        bgt     clipb           ;home if line completely out
        move.w  cbits,d4
        move.w  cbits2,d5
        sub.w   d0,d2           ;d1 has dx
        move.w  d2,dx
        sub.w   d1,d3           ;d3 has dy
        move.w  d3,dy
        move.w  xsav,d2
        move.w  ysav,d3
        tst.w   d4
        beq     clip2   ;if x1<xmin
        cmpi.w  xmin,d0 ;y1=y1+dy*(xmin-x1)/dx
        bge     c1      
        move.w  xmin,d7         ;put xmin in d7
        sub.w   d0,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d1,d7
        move.w  d7,d1
        move.w  xmin,d0         ;x1=xmin
        bra     c4
c1:     cmpi.w  xmax,d0         ;if x1>xmax
        ble     c2              ;y1=y1+dy*(xmax-x1)/dx
        move.w  xmax,d7         ;put xmax in d7
        sub.w   d0,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d1,d7
        move.w  d7,d1
        move.w  xmax,d0         ;x1=xmax
        bra     c4
c2:     cmpi.w  ymin,d1         ;if y1<ymin
        bge     c3
        move.w  ymin,d7         ;put ymin in d7
        sub.w   d1,d7
        muls    dx,d7           ;multiply by dx
        divs    dy,d7
        add.w   d0,d7
        move.w  d7,d0
        move.w  ymin,d1         ;y1=ymin
        bra     c4
c3:     cmpi.w  ymax,d1         ;if y1>xmax
        ble     c4
        move.w  ymax,d7         ;put ymax in d7
        sub.w   d1,d7
        muls    dx,d7           ;multiply by dy
        divs    dy,d7
        add.w   d0,d7
        move.w  d7,d0
        move.w  ymax,d1         ;y1=ymax
c4:     bsr     bitcode
        bra     cliploop
******
clip2:  cmpi.w  xmin,d2 ;y1=y1+dy*(xmin-x1)/dx
        bge     cc1     
        move.w  xmin,d7         ;put xmin in d7
        sub.w   d2,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d3,d7
        move.w  d7,d3
        move.w  xmin,d2         ;x2=xmin
        bra     cc4
cc1:    cmpi.w  xmax,d2         ;if x2>xmax
        ble     cc2
        move.w  xmax,d7         ;put xmax in d7
        sub.w   d2,d7
        muls    dy,d7           ;multiply by dy
        divs    dx,d7
        add.w   d3,d7
        move.w  d7,d3
        move.w  xmax,d2         ;x1=xmax
        bra     cc4
cc2:    cmpi.w  ymin,d3         ;if y1<ymin
        bge     cc3
        move.w  ymin,d7         ;put ymin in d7
        sub.w   d3,d7
        muls    dx,d7           ;multiply by dx
        divs    dy,d7
        add.w   d2,d7
        move.w  d7,d2
        move.w  ymin,d3         ;y1=ymin
        bra     cc4
cc3:    cmpi.w  ymax,d3         ;if y1>xmax
        ble     cc4
        move.w  ymax,d7         ;put ymax in d7
        sub.w   d3,d7
        muls    dx,d7           ;multiply by dy
        divs    dy,d7
        add.w   d2,d7
        move.w  d7,d2
        move.w  ymax,d3         ;y1=ymax
*       bra     cliploop        
cc4:    bsr     bit2
        bra     cliploop

cliploop:
        bra     clipit2
cliphome:
*       movem.l d0-d7/a0-a6,-(sp)
        move.l  linepar,a0
        move.w  d0,38(a0)
        move.w  d1,40(a0)
        move.w  d2,42(a0)
        move.w  d3,44(a0)
        dc.w    $a003
*       movem.l (sp)+,d0-d7/a0-a6

clipb:  rts

