
 Include "equ.h"
 Include "impequ.h"


 SECTION CLIPS,CODE,PUBLIC

***************************************************
***						***
***************************************************
dumbentry:
	clr.l	d0
	rts

	dc.l	"IMPO"		; magik number for pic import
	dc.w	201
	dc.l	0

table:	dc.l	0
	dc.l	name,special,check,CLIPS


*********************************
*  Is it really ProDraw Clips?  *
*********************************
check:	move.l	table,a0
	move.l	buff1(a0),a1
	move.l	(a1),a1
	cmp.l	#"PDPF",(a1)
	bne	never
        move.w  #23,d0
        lea     special,a0
        move.w  #1,(a0)                 ;reset special count
        addq.l  #6,a0
check1: clr.l   (a0)+                   ;clear out special table 
        dbf     d0,check1
        bra     getclips        

***********************************
***                             ***
***********************************
getclips:
        move.l	table,a1                ;get actual length of file
	move.l	flen(a1),a0
	move.l	(a0),length
        move.l  length,length2          ;save for later
        
        move.l	table,a0
	move.l	f_openr(a0),a0
	jsr	(a0)
	beq	never        
        
        lea     strtab,a0
        move.l  a0,strtabptr
        
        bsr     pgetl           ;skip the first 8 bytes
        bsr     pgetl
        subq.l  #8,length       ;adjust for the previous bytes

getclip:
	bsr	pgetl		;get chunk type in temp
	move.l	d0,temp
	bsr	pgetl           ;get chunk length in clength
	move.l	d0,clength
	subq.l	#8,length       ;sub 8 from length of file left
        move.l  length,d0
        tst.l   clength         ;is there any data in this chunk?
        beq     gt2             ;no
        
	move.l	temp,d0
        cmp.l   #'CLNM',d0      ;did i find a clip name chunk?
        beq     gt1             ;yes!
        bsr     skip
        bra     getclip
        
gt1:    jsr     clnm            ;do clip name chunk stuff

gt2:    tst.l	length          ;is there any data left in the CLIP?
        bmi     gt3
	bne	getclip         ;yes - so look for more CLNM chunks
        
gt3:    move.l	table,a0        ;no more data so close file and return
	move.l	f_closer(a0),a0
	jsr	(a0)
        
        bra     right


***********************************
***                             ***
***********************************
CLIPS:	move.l	sp,savesp
        
        move.l	table,a0
	move.l	f_openr(a0),a0
	jsr	(a0)
	bne	impobj
        
        rts


*********************************
*                               *
*********************************
impobj:	
        move.l	table,a0
	move.l	o_open(a0),a0
	jsr	(a0)
	beq	abort0

        clr.l   flag                    ;set flag to 0
        move.w  #0,coltabindex          ;reset the color tab index to the beg.
        move.l  #76800,xscale
        move.l  #76800,yscale

        move.l  table,a0
        move.l  spclnum(a0),a0
        move.w  (a0),clipnum            ;get the clip they want to import
        tst.w   clipnum
        beq     imob0
        
        bset    #2,flag                 ;do only 1 clip
        
imob0:  bsr     getpicinfo
        
imob1:	move.l	table,a0
	move.l	o_close(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	f_closer(a0),a0
        jsr     (a0)
        rts

***********************************
***                             ***
***********************************
abortobj:
	move.l	table,a0
	move.l	o_abort(a0),a0
	jsr	(a0)

abort0:	move.l	table,a0
	move.l	f_closer(a0),a0
	jmp	(a0)

        
*********************************
*                               *
*********************************
getpicinfo:
        move.l  length2,length  ;get actual length of file
        
        bsr	pgetl		;"PDPF"
	bsr	pgetl		;length of clip file (not always correct)
        subq.l  #8,length       ;adjust for prev 8 bytes

getchunk:
	bsr	pgetl		;get chunk type in temp
	move.l	d0,temp
	bsr	pgetl           ;get chunk length in clength
	move.l	d0,clength
	subq.l  #8,length       ;sub 8 from length of file left
        tst.l   clength         ;is there any data in this chunk?
        bne     gc0             ;yes
        
        move.l  temp,d0         ;handle special chunks (0 length) here
        cmp.l   #'CFIN',d0
        beq     cfin
        cmp.l   #'CLIP',d0
        beq     clip
        cmp.l   #'COLR',d0
        beq     colr
        cmp.l   #'OFIN',d0
        beq     ofin
        bra     gc2             ;ignore ones I do not deal with
        
gc0:	move.l	temp,d0
        
	lea	chunks-4,a0     ;get address of chunk table
	move.w	numchunks,d1    ;number of chunks in table

gc1:	lea	4(a0),a0        ;get address of next chunk type
	cmp.l	(a0)+,d0        
	dbeq	d1,gc1          ;loop until end of table or a match
        
	move.l	(a0),a0         ;get address of routine to use for this chunk
	jsr	(a0)            ;do it

gc2:    tst.l	length          ;is there any data left in the CLIP?
        ;bmi     rrts
	bne	getchunk        ;yes
                
rrts:	rts                     ;everything is OK


***********************************
***	SPECIAL CHUNK		***
***********************************
cfin:   btst    #4,flag                 ;is there a color to be defined still?
        beq     gc2
        
        bsr     addcolor
        bra     gc2
         
***********************************
***				***
***********************************
cflg:   bsr     skip
        rts
                
***********************************
***	SPECIAL CHUNK   	***
***********************************
clip:   btst    #2,flag                 ;do i want all or just one obj?
        beq     clip1                   ;all
        
        subq.w  #1,clipnum              ;decrement the clip count
        tst.w   clipnum                 ;have i found the one i want yet?
        bne     clip2                   ;no
        
clip1:  move.l  table,a0
        move.l  o_begingroup(a0),a0
        jsr     (a0)
        
clip2:  ;bset    #7,flag                 ;get the  clips bounding box
        bra     gc2
        
***********************************
***	SPECIAL CHUNK   	***
***********************************
clnm:   lea     special,a2
        addq.l  #6,a2                   ;move a2 to first opening in special
        
        move.w  #25,d0                  ;find next opening in table
clnm1:  tst.l   (a2)+
        beq     clnm2
        dbf     d0,clnm1
        
        bra     skip                    ;skip the data if no more room
              
clnm2:  move.l  strtabptr,a0            ;store the actual addr of the memory 
        move.l  a0,-4(a2)
        
        lea     special,a2
        addq.w  #1,(a2)                 ;add 1 to special count
        
        move.l  clength,d1
        subq.l  #1,d1
        
clnm3:  move.l  a0,-(sp)                ;get name into allocated memory
        move.w  d1,-(sp)
        bsr     pget
        move.w  (sp)+,d1
        move.l  (sp)+,a0
        move.b  d0,(a0)+
        dbf     d1,clnm3
        
        clr.b   (a0)+                    ;null terminate the string
        move.l  a0,strtabptr
        bra     adjlen 
        
***********************************
***				***
***********************************
cnam:   btst    #4,flag                 ;is there a color to be defined still?
        beq     cnam0                   ;no
        bsr     addcolor

cnam0:  lea     colorname,a0
        move.l  clength,d1
        move.w  d1,cnamlen
                
cnam1:  move.l  a0,-(sp)
        move.w  d1,-(sp)
        bsr     pget
        move.w  (sp)+,d1
        move.l  (sp)+,a0
        move.b  d0,(a0)+
        subq.l  #1,d1
        bne     cnam1
        bra     adjlen
        
***********************************
***	SPECIAL CHUNK		***
***********************************
colr:   btst    #4,flag                 ;is there a color to be defined still?
        beq     gc2                     ;no
        
        bsr     addcolor
        bra     gc2
        
***********************************
***				***
***********************************
data:   tst.w   clipnum                 ;have i found the clip i want yet?
        bne     skip                    ;no
        
        btst    #0,flag                 ;do i deal with this obj?
        beq     skip                    ;no
        
        move.l  objtype,d0              ;test for obj types I do deal with
        cmp.l   #'BEZ4',d0              ;is it a BEZ4 obj?
        beq     bez4                    ;yes

        cmp.l   #'CIRC',d0              ;is it a CIRC obj
        beq     circ                    ;yes
        
        bra     skip
        
***********************************
***				***
***********************************        
dbox:   tst.w   clipnum                 ;have i found the clip i want yet?
        bne     skip                    ;no
        
        btst    #5,flag                 ;I am doing a compound obj?
        bne     dbox3                   ;yes, so store this data for later
        
        bsr     xgetppi
        move.l  d0,object+ob_Left
        move.l  d0,leftoffset
        bsr     ygetppi
        move.l  d0,object+ob_Top
        move.l  d0,topoffset
        bsr     xgetppi
        move.l  d0,object+ob_Right
        bsr     ygetppi
        move.l  d0,object+ob_Bottom      
        bra     dbox4
        
dbox3:  bsr     xgetppi
        move.l  d0,leftoffset
        bsr     ygetppi
        move.l  d0,topoffset
        bsr     pgetl
        bsr     pgetl
                
dbox4:  bra     adjlen

        
***********************************
***				***
***********************************
fill:   tst.w   clipnum
        bne     skip
        
        btst    #5,flag                 ;am I in a compound obj?
        bne     skip                    ;yes!
        
        bsr     pgetw
        move.w  d0,fillcolor
        bsr     pgetw
        move.w  d0,fillflags
        bra     adjlen
        
***********************************
***				***
***********************************
line:   tst.w   clipnum
        bne     skip
        
        btst    #5,flag                 ;am I im a compound object?
        bne     skip                    ;yes!
                
        bsr     pget                    ;skip this byte (?)
        bsr     pget                    ;get the color of the object
        lea     colortab,a0
        and.l   #$000000ff,d0           ;get rid of extra garbage
        move.b  0(a0,d0.w),d1
        move.b  d1,object+ob_LColor
        move.b  #1,object+ob_LType
        
        bsr     pget                    ;skip the line join type
        cmp.b   #1,d0
        bne     ln0
        move.b  #2,object+ob_LBegin
        move.b  #2,object+ob_LEnd
        
ln0:    bsr     pget                    ;skip this byte (?)
        bsr     pgetl                   ;get the line weight and scale it
        clr.l   d1
        clr.l   d2
        move.w  #100,d1
        bsr     Mulu1632
        move.w  #1067,d2
        bsr     Divu1648
        move.w  d0,object+ob_LWidth
        
        cmp.l   #8,clength
        beq     line1
        
        move.l  clength,d2
        sub.l   #9,d2
        
line0:  move.w  d2,-(sp)
        bsr     pget
        move.w  (sp)+,d2
        dbf     d2,line0
        
line1:  bra     adjlen

***********************************
***				***
***********************************
obj:    tst.w   clipnum                 ;have i found the clip i want yet?
        bne     skip                    ;no

        btst    #5,flag                 ;am I inside a compound object?
        bne     obj0                    ;yes
        bsr     setobjdef               ;set up objects default values

obj0:   bsr     pgetl
        move.l  d0,objtype
        cmp.l   #'BEZ4',d0
        bne     obj1
        bset    #0,flag                 ;bit0 - do i deal with the object
        bra     adjlen
        
obj1:   cmp.l   #'CIRC',d0
        bne     obj2
        bset    #0,flag
        bra     adjlen
        
obj2:   bra     adjlen                

***********************************
***	SPECIAL CHUNK		***
***********************************
ofin:   tst.w   clipnum                 ;have i found the clip i want yet?
        bne     gc2                     ;no
        
        move.l  table,a0
        move.l  o_endgroup(a0),a0
        jsr     (a0)
        bra     gc2

***********************************
***				***
***********************************        
oflg:   tst.w   clipnum                 ;have i found the clip i want yet?
        bne     skip                    ;no
        
        bsr     pgetl
        move.l  d0,oflgdata
        bra     adjlen

***********************************
***				***
***********************************
pymc:   bset    #4,flag
        bsr     pgetw
        move.w  d0,yellow
        bsr     pgetw
        move.w  d0,magenta
        bsr     pgetw
        move.w  d0,cyan
        bsr     pgetw
        move.w  d0,black
        bra     adjlen

***********************************
***				***
***********************************
sclf:
        bsr     pgetl
        move.l  d0,xscale
        bsr     pgetl
        move.l  d0,yscale
        bra     adjlen
        
***********************************
***				***
***********************************
stxt:   tst.w   clipnum
        bne     skip
        
        bsr     pgetl                   ;skip the first 4 long words
        bsr     pgetl
        bsr     pgetl
        bsr     pgetl
        bsr     pgetw
        cmp.w   #$2000,d0               ;the character is in the top
        bne     stxt1                   ;check for a space ($20)
        bclr    #0,flag                 ;do not deal with spaces
        
stxt1:  bra     adjlen

***********************************
***				***
***********************************
vbox:   bsr     skip
        rts


***********************************
***				***
***********************************
ymck:   bset    #4,flag                 ;need to define color
        bsr     pgetw
        move.w  d0,yellow
        bsr     pgetw
        move.w  d0,magenta
        bsr     pgetw
        move.w  d0,cyan
        bsr     pgetw
        move.w  d0,black
        bra     adjlen


***********************************
***				***
***********************************        
addcolor:
        bclr    #4,flag                 ;color has been defined
        move.w  yellow,d0
        mulu    #10000,d0
        divu    #$3ff,d0
        move.w  d0,color+cl_Yellow
        
        move.w  magenta,d0
        mulu    #10000,d0
        divu    #$3ff,d0
        move.w  d0,color+cl_Magenta
        
        move.w  cyan,d0
        mulu    #10000,d0
        divu    #$3ff,d0
        move.w  d0,color+cl_Cyan
        
        move.w  black,d0
        mulu    #10000,d0
        divu    #$3ff,d0
        move.w  d0,color+cl_Black
        
        clr.w   color+cl_Type
        clr.w   color+cl_Map
        
        lea     colorname,a0            ;copy the color name into cl_Name
        lea     color+cl_Name,a1
        move.w  cnamlen,d0
        subq.b  #1,d0
        cmp.w   #24,d0                  ;can only have a 24 char name
        bcs     addc1
        move.w  #23,d0
addc1:  move.b  (a0)+,(a1)+
        dbf     d0,addc1
      
        clr.b   (a1)                    ;null terminate name
        lea     color,a0
        move.l  table,a1
        move.l  newcolor(a1),a1
        jsr     (a1)
        move.l  d0,saved0
        
        lea     color,a0
        move.l  table,a1
        move.l  findcolorname(a1),a1
        jsr     (a1)
        cmp.w   #$ffff,d0
        bne     addc2
        
        move.l  saved0,d0

addc2:  move.w  coltabindex,d1
        lea     colortab,a1
        move.b  d0,0(a1,d1.w)           ;store pgs color equiv
        addq.w  #1,coltabindex
        rts
        
***********************************
***				***
***********************************
skip:	move.l	clength,d0
	add.l	#1,d0
	bclr	#0,d0
	sub.l	d0,length

sk1:	move.l	d0,-(sp)
	bsr	pgetw
	move.l	(sp)+,d0
	sub.l	#2,d0
	bgt	sk1
	rts

        
***********************************
***				***
***********************************
adjlen:	move.l	clength,d0
	btst	#0,d0
	beq	al1
	bsr	pget
	move.l	clength,d0
	add.l	#1,d0

al1:	sub.l	d0,length
	rts

*********************************
*                               *
*********************************
pgetl:	move.l	table,a1
	move.l	f_getl(a1),a1
	jsr	(a1)
	beq	errrts
	rts

*********************************
*                               *
*********************************
pgetw:	move.l	table,a1
	move.l	f_getw(a1),a1
	jsr	(a1)
	beq	errrts
        and.l   #$0000ffff,d0           ;clean up d0
	rts

*********************************
*                               *
*********************************
pget:	move.l	table,a1
	move.l	f_get(a1),a1
	jsr	(a1)
	beq	errrts
        and.l   #$000000ff,d0           ;clean up d0
	rts

***********************************
***                             ***
***********************************
xgetppi:
        movem.l a0/a1,-(sp)
        bsr     pgetl
        btst    #31,d0
        beq     xgt1
        neg.l   d0
        move.l  #7200,d1
        bsr     Muls1632
        move.l  xscale,d2
        bsr     Divs3248
        neg.l   d0
        bra     xgt2

xgt1:   move.l  #7200,d1
        bsr     Muls1632
        move.l  xscale,d2
        bsr     Divs3248

xgt2:   movem.l (sp)+,a0/a1
        rts


***********************************
***                             ***
***********************************
ygetppi:
        movem.l a0/a1,-(sp)
        bsr     pgetl
        btst    #31,d0
        beq     ygt1
        neg.l   d0
        move.l  #7200,d1
        bsr     Muls1632
        move.l  yscale,d2
        bsr     Divs3248
        neg.l   d0
        bra     ygt2
        
ygt1:   move.l  #7200,d1
        bsr     Muls1632
        move.l  yscale,d2
        bsr     Divs3248
        
ygt2:   movem.l (sp)+,a0/a1
        rts

***********************************
***                             ***
***********************************
getppix:
        bsr     xgetppi
        
        btst    #5,flag
        beq     gtpix1
        
        move.l  leftoffset,d1
        add.l   d1,d0
        ;sub.l   object+ob_Left,d0
        bsr     checkLR
        
        btst    #31,d0
        beq     gtpix2
        clr.l   d0
        bra     gtpix2
        
gtpix1: bsr     checkR

gtpix2: rts
       
***********************************
***                             ***
***********************************
getppiy:
        bsr     ygetppi
        
        btst    #5,flag
        beq     gtpiy1
        
        move.l  topoffset,d1
        add.l   d1,d0
        ;sub.l   object+ob_Top,d0
        bsr     checkTB
        
        btst    #31,d0
        beq     gtpiy2
        clr.l   d0
        bra     gtpiy2
        
gtpiy1: bsr     checkB

gtpiy2: rts
        
***************************
***                     ***
***************************
putobj:	move.l	table,a1
	move.l	o_obj(a1),a1
	lea	object,a0
	jsr	(a1)
        beq     errrts
                
        rts
        
***************************
***                     ***
***************************
setobjdef:
        clr.b   object+ob_Flag
        clr.w   object+ob_Slant
        clr.w   object+ob_Twist
        
        move.b  #1,object+ob_LColor     ;black line
        move.b  #1,object+ob_LType      ;line type = solid
        move.w  #50,object+ob_LWidth    ;line width (0.5 point)
        
        move.b  #1,object+ob_FColor     ;set color to black
        move.b  #0,object+ob_FType      ;fill type 0 = none
        
        clr.b   object+ob_LBegin
        clr.b   object+ob_LEnd
        clr.w   object+ob_HStandOff   
        clr.w   object+ob_VStandOff
        rts

   
***********************************
***				***
***********************************        
bez4:   
        bclr    #0,flag                 ;clear the ok obj flag for next obj
        bsr     pgetw                   ;skip this word (number of things)
        move.l  clength,d0
        subq.l  #2,d0
        lsr.l   #3,d0                   ;divide by 8 to get number of points
        move.w  d0,count
        clr.l   prevptx                 ;clear the previous point
        clr.l   prevpty
        clr.l   prevctx                 ;clear the previous control point
        clr.l   prevcty
        clr.w   curvecount              ;clear the CURVETO counter
        
	mulu	#20,d0		        ;max bytes per line = 20, min = 10
        
        move.l  oflgdata,d1             ;is this the start of a compound obj?
        btst    #13,d1
        bne     bez0                    ;yes!
        
        btst    #5,flag                 ;am I doing a compound object?
        beq     bez01                   ;no
        
        move.l  mptr,a0                 ;get address of memory into a0
        move.l  table,a1                ;d0 = amount to grow by (see above)
        move.l  m_grow(a1),a1
        jsr     (a1)
        beq     errrts                  ;get out if could not get memory
        
        move.l  mptr,a0
        move.l  (a0),a0
        add.l   len,a0                  ;set a0 to end of last object
        move.l  a0,pptr
        bclr    #1,flag                 ;set first point flag to NOT FOUND
        bset    #6,flag                 ;set up to use leftoffset and topoffset        
        bra     bez10                   ;start doing next set of points
        
bez0:   bset    #5,flag                 ;set up flag for a compound object
        bset    #6,flag
        
bez01:  btst    #3,flag                 ;is this a close poly?
        bne     bez1                    ;yes
        tst.w   fillflags               ;is the oply filled?
        bne     bez1                    ;yes
        
        add.l   #ply_Sizeof+4,d0        ;4 = newpath+strokepath
        bra     bez2
        
bez1:   add.l	#ply_Sizeof+6,d0	;6 = new+close+(fill or stroke)

bez2:	clr.w	d1                      ;m_alloc memory for object data
	clr.w	d2
	move.l	table,a0
	move.l	m_alloc(a0),a0
	jsr	(a0)
	beq	errrts

	move.l	a0,mptr
	move.l	(a0),a4
	lea	ply_Sizeof(a4),a4
	move.l	a4,pptr

        move.b  #tpoly,object+ob_Type
        move.w  count,d0
        move.l  pptr,a0
        move.w  #NEWPATH,(a0)+
        bclr    #1,flag                 ;clear first point flag - not found
        move.l  #ply_Sizeof+2,len       ;set starting length of poly stuff
        move.w  #1,numcom               ;set poly command counter to 1
        
bez10:  clr.l   d7

        btst    #1,flag                 ;is this the first point?
        bne     bez14                   ;no
                  
bez13:  move.w  #MOVETO,(a0)+
        bsr     getppix
        move.l  d0,(a0)+
        bsr     getppiy
        move.l  d0,(a0)+
        
        bsr     getppix                  ;skip the first point
        bsr     getppiy
        
        move.w  #CURVETO,(a0)+          ;bezier curve - first control point
        bsr     getppix
        move.l  d0,(a0)+
        bsr     getppiy
        move.l  d0,(a0)+
        
        subq.w  #2,count
        add.l   #10,len                 ;add in for moveto command
        addq.w  #1,numcom
        bset    #1,flag                 ;I found the first point
        bra     bez15
        
bez14:  move.w  #CURVETO,(a0)+          ;bezier curve - first control point
        bsr     getppix
        move.l  d0,(a0)+
        bsr     getppiy
        move.l  d0,(a0)+

bez15:  bsr     getppix                 ;get the end point of the curve
        move.l  d0,point2x
        bsr     getppiy
        move.l  d0,point2y
        
        bsr     getppix                 ;second control point
        move.l  d0,(a0)+ 
        bsr     getppiy
        move.l  d0,(a0)+
                
        move.l  point2x,(a0)+           ;store the end point
        move.l  point2y,(a0)+
        
        addq.w  #1,curvecount
        subq.w  #3,count
        add.l   #26,len                 ;uses three points in pagestream
        addq.w  #1,numcom               ; and 1 command
        
bez19:  cmp.w   #2,count                ;if 1 or 0 I am done
        bcc     bez10                   ;not done yet...
        
        btst    #5,flag                 ;is this part of a compound object?
        beq     bez198                  ;no
       
        move.l  oflgdata,d0
        btst    #10,d0                  ;if yes - is this the last object?
        bne     bez198                  ;yes, finish obj off
        
        cmp.w   #0,count
        beq     bez191
        bsr     getppix                  ;skip the last point
        bsr     getppiy
bez191: bra     adjlen                  ;set up for next obj
        
bez198: cmp.w   #1,count
        bne     bez200
        
        bsr     xgetppi                    ;the last point is the control point
        move.l  d0,prevctx
        bsr     ygetppi                 ;of the next curve
        move.l  d0,prevcty

bez200: move.l  oflgdata,d0             ;move flag into d0 for 32 bit testing
        btst    #4,d0                   ;is it a close poly?
        beq     bez201                  ;no!
        
        move.w  #CLOSEPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len

bez201: tst.w   fillflags               ;is it filled?
        beq     bez202                  ;no

        lea     colortab,a1
        move.w  fillcolor,d0
        move.b  0(a1,d0.w),d1
        move.b  d1,object+ob_FColor     ;set the objects color
        move.b  #9,object+ob_FType      ;yes - set fill type to #9 (solid)
        move.w  #FILLPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len
        
        bra     bez203
        
        ;move.b  #1,object+ob_FColor     ;set the objects color to 1 (Black)
        ;move.b  #0,object+ob_FType      ;yes - set fill type to 0 (none)
        ; 
        ;move.w  #STROKEPATH,(a0)+
        ;addq.w  #1,numcom
        ;addq.l  #2,len
        ; 
        ;bra     bez203
  
bez202: move.w  #STROKEPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len
        
bez203: move.l  mptr,a0
        move.l  (a0),a0
        clr.l   d0
        move.l  len,d0
        move.l  d0,ply_Length(a0)
        
        move.l  object+ob_Right,d0
        sub.l   object+ob_Left,d0
        move.l  d0,ply_Width(a0)
        
        move.l  object+ob_Bottom,d0
        sub.l   object+ob_Top,d0
        move.l  d0,ply_Height(a0)
        
        move.w  #100,ply_XScale(a0)
        move.w  #100,ply_YScale(a0)
        move.w  numcom,ply_Count(a0)
        
        tst.w   object+ob_LWidth
        bne     bez204
        
        move.b  #1,object+ob_LColor
        move.b  #0,object+ob_LType
                
bez204: cmp.w   #1,curvecount           ;2 curves could mean a line
        bne     bez210
        
        move.l  pptr,a0                 ;get address of poly data
        
        move.l  4(a0),d0                ;x coord of MOVETO
        move.l  8(a0),d1                ;y coord of MOVETO
        cmp.l   14(a0),d0               ;compare to control point 1 of CURVETO
        ;beq     bez205
        bne     bez210
        cmp.l   18(a0),d1
        ;beq     bez205
        bne     bez210
        ;bra     bez210
        
bez205: move.l  30(a0),d2               ;x coord of end point
        move.l  34(a0),d3               ;y coord of end point
        cmp.l   22(a0),d2               ;compare to control point 2 of CURVETO
        ;beq     bez206
        bne     bez210
        cmp.l   26(a0),d3
        ;beq     bez206
        bne     bez210
        ;bra     bez210
        
bez206: move.b  #thvln,object+ob_Type   ;force a hori/vert line to start with
        cmp.l   d2,d0                   ;is it a horizontal line?
        beq     bez207                  ;yes
        cmp.l   d3,d1                   ;is it a vertical line?
        beq     bez207                  ;yes
        
        move.b  #tdln,object+ob_Type    ;object is a diag line
    
bez207: cmp.l   d2,d0                   ;is end point x > moveto point x
        bcs     bez208                  ;yes
        move.l  object+ob_Left,d4
        move.l  object+ob_Right,object+ob_Left
        move.l  d4,object+ob_Right
        
bez208: cmp.l   d3,d1                   ;is the end point y > moveto point y 
        bcs     bez209                  ;yes
        move.l  object+ob_Top,d4
        move.l  object+ob_Bottom,object+ob_Top
        move.l  d4,object+ob_Bottom
        
bez209: bsr     putobj
        bra     bez23
        
bez210: btst    #5,flag
        beq     bez211
        
        move.l  mptr,a0
        move.l  (a0),a0
        lea     ply_Sizeof(a0),a0
        clr.l   d0
        move.w  numcom,d0
        bsr     adjcoords

bez211: bsr     putobj

	move.l	mptr,a0
	move.l	(a0),a0
	move.l	(a0),d0
	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	errrts

	move.l	mptr,a1
	move.l	(a1),a1
	move.l	(a1),d0
	lsr.l	#1,d0
        move.l  d0,d1
        swap    d1
	bra	bez22
bez21:	move.w	(a1)+,(a0)+
bez22:	dbf	d0,bez21
        dbf     d1,bez21
        
bez23:  move.l  mptr,a0
        move.l  table,a1
        move.l  m_delete(a1),a1
        jsr     (a1)

        bclr    #5,flag                 ;clear the compound object flag
        bra     adjlen

   
***********************************
***				***
***********************************        
circ:   bsr     xgetppi                 ;get the box width
        move.l  d0,w
        bsr     ygetppi                 ;get the box height
        move.l  d0,h
        
        bsr     xgetppi
        lsl.l   #1,d0
        move.l  d0,cw                   ;circle width (Diameter)
        lsr.l   #1,d0
        move.l  d0,cw2
        lsr.l   #1,d0
        move.l  d0,cw4
        add.l   cw2,d0
        move.l  d0,cw34
        move.l  #0,cw0
        
        bsr     ygetppi
        lsl.l   #1,d0
        move.l  d0,ch                   ;circle height (Diameter)
        lsr.l   #1,d0
        move.l  d0,ch2
        lsr.l   #1,d0
        move.l  d0,ch4
        add.l   ch2,d0
        move.l  d0,ch34
        move.l  #0,ch0
        
        bsr     pgetl
        move.l  d0,rotation
        bsr     pgetl
        bsr     pgetl
        
        move.l  oflgdata,d1             ;is this the start of a compound obj?
        btst    #13,d1
        beq     circ0                   ;no
        
        bset    #5,flag
        
circ0:  btst    #5,flag
        beq     cir00
                
        move.l  leftoffset,d0           ;if yes, adjust coords
        ;sub.l   object+ob_Left,d0
        add.l   d0,cw
        add.l   d0,cw2
        add.l   d0,cw4
        add.l   d0,cw34
        add.l   d0,cw0
        move.l  cw0,d0
        bsr     checkR
        move.l  cw,d0
        bsr     checkR
        
        move.l  topoffset,d0
        ;sub.l   object+ob_Top,d0
        add.l   d0,ch
        add.l   d0,ch2
        add.l   d0,ch4
        add.l   d0,ch34
        add.l   d0,ch0
        move.l  ch0,d0
        bsr     checkB
        move.l  ch,d0
        bsr     checkB
        bra     circ1

cir00:  move.l  object+ob_Left,d0       ;calculate PgS bounding box
        add.l   cw,d0
        move.l  d0,object+ob_Right
        move.l  object+ob_Top,d0
        add.l   ch,d0
        move.l  d0,object+ob_Bottom
        
        move.l  h,d0                    ;adjust Top down
        move.l  ch2,d1
        sub.l   d1,d0
        add.l   d0,object+ob_Top
        
        move.l  w,d0                    ;adjust the Right left
        move.l  cw2,d1
        sub.l   d0,d1
        sub.l   d1,object+ob_Right
        
        move.l  object+ob_Right,d0       ;calculate PgS new bounding box
        sub.l   cw,d0
        move.l  d0,object+ob_Left
        move.l  object+ob_Top,d0
        add.l   ch,d0
        move.l  d0,object+ob_Bottom
        
        bclr    #0,flag                 ;clear the ok obj flag for next obj
        clr.l   prevptx                 ;clear the previous point
        clr.l   prevpty
        clr.l   prevctx                 ;clear the previous control point
        clr.l   prevcty
        
circ1:  move.l  #114,d0                 ;amount of memory needed
        
        move.l  oflgdata,d1             ;is this the start of a compound obj?
        btst    #13,d1
        bne     cir0                    ;yes!
        
        btst    #5,flag                 ;am I doing a compound object?
        beq     cir01                   ;no
        
        move.l  mptr,a0                 ;get address of memory into a0
        move.l  table,a1                ;d0 = amount to grow by (see above)
        move.l  m_grow(a1),a1
        jsr     (a1)
        beq     errrts                  ;get out if could not get memory
        
        move.l  mptr,a0
        move.l  (a0),a0
        add.l   len,a0                  ;set a0 to end of last object
        move.l  a0,pptr
        bset    #6,flag                 ;set up to use leftoffset and topoffset        
        bra     cir10                   ;start doing next set of points
        
cir0:   bset    #5,flag                 ;set up flag for a compound object
        bset    #6,flag
        
cir01:  add.l	#ply_Sizeof+6,d0	;6 = new+close+(fill or stroke)

cir2:	clr.w	d1                      ;m_alloc memory for object data
	clr.w	d2
	move.l	table,a0
	move.l	m_alloc(a0),a0
	jsr	(a0)
	beq	errrts

	move.l	a0,mptr
	move.l	(a0),a4
	lea	ply_Sizeof(a4),a4
	move.l	a4,pptr

        move.b  #tpoly,object+ob_Type
        move.l  pptr,a0
        move.w  #NEWPATH,(a0)+
        move.w  #1,numcom
        move.l  #ply_Sizeof+2,len       ;set starting length of poly stuff
        
cir10:  move.w  #MOVETO,(a0)+
        move.l  cw0,(a0)+
        move.l  ch2,(a0)+

        move.w  #CURVETO,(a0)+
        move.l  cw0,(a0)+
        move.l  ch4,(a0)+
        move.l  cw4,(a0)+
        move.l  ch0,(a0)+
        move.l  cw2,(a0)+
        move.l  ch0,(a0)+

        move.w  #CURVETO,(a0)+
        move.l  cw34,(a0)+
        move.l  ch0,(a0)+
        move.l  cw,(a0)+
        move.l  ch4,(a0)+
        move.l  cw,(a0)+
        move.l  ch2,(a0)+

        move.w  #CURVETO,(a0)+
        move.l  cw,(a0)+
        move.l  ch34,(a0)+
        move.l  cw34,(a0)+
        move.l  ch,(a0)+
        move.l  cw2,(a0)+
        move.l  ch,(a0)+

        move.w  #CURVETO,(a0)+          ;bezier curve - first control point
        move.l  cw4,(a0)+
        move.l  ch,(a0)+
        move.l  cw0,(a0)+
        move.l  ch34,(a0)+
        move.l  cw0,(a0)+
        move.l  ch2,(a0)+
                
        add.l   #114,len                ;add in for moveto & curveto commands
        addq.w  #5,numcom
        bclr    #6,flag                 ;do not use leftoffset and topoffset
        btst    #5,flag                 ;is this part of a compound object?
        beq     cir200                  ;no
       
        move.l  oflgdata,d0
        btst    #10,d0                  ;if yes - is this the last object?
        beq     adjlen                  ;yes, so end object
        
cir200: move.l  oflgdata,d0             ;move flag into d0 for 32 bit testing
        btst    #4,d0                   ;is it a close poly?
        beq     cir201                  ;no, so check for fill
        
        move.w  #CLOSEPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len
        move.b  #1,object+ob_FColor     ;set the objects color to 1 (Black)
        move.b  #0,object+ob_FType      ;yes - set fill type to 0 (none)
        
cir201: tst.w   fillflags               ;is it filled?
        beq     cir202                  ;no, so stroke it
  
        lea     colortab,a1
        move.w  fillcolor,d0
        move.b  0(a1,d0.w),d1
        move.b  d1,object+ob_FColor     ;set the objects color
        move.b  #9,object+ob_FType      ;yes - set fill type to #9 (solid)
        move.w  #FILLPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len
        
        bra     cir203
        
cir202: move.w  #STROKEPATH,(a0)+
        addq.w  #1,numcom
        addq.l  #2,len
        
cir203: move.l  mptr,a0
        move.l  (a0),a0
        move.l  len,d0
        move.l  d0,ply_Length(a0)
        
        move.l  object+ob_Right,d0
        sub.l   object+ob_Left,d0
        move.l  d0,ply_Width(a0)
        
        move.l  object+ob_Bottom,d0
        sub.l   object+ob_Top,d0
        move.l  d0,ply_Height(a0)
        
        move.w  #100,ply_XScale(a0)
        move.w  #100,ply_YScale(a0)
        move.w  numcom,ply_Count(a0)
        
        tst.w   object+ob_LWidth
        bne     cir210
        
        move.b  #1,object+ob_LColor
        move.b  #0,object+ob_LType

cir210: move.l  rotation,d0             ;get the rotation in radians
        beq     cirt1
        mulu    #18000,d0               ;convert to degress
        clr.l   d1   
        move.l  #31415,d2
        bsr     Divu1648
        move.w  #36000,d1               ;reverse the rotation
        sub.w   d0,d1
        move.w  d1,object+ob_Twist
        move.w  d1,object+ob_Slant
        
cirt1:  btst    #5,flag
        beq     cir211
        
        move.l  mptr,a0
        move.l  (a0),a0
        lea     ply_Sizeof(a0),a0
        clr.l   d0
        move.w  numcom,d0
        bsr     adjcoords

cir211: bsr     putobj

	move.l	mptr,a0
	move.l	(a0),a0
	move.l	(a0),d0
	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	errrts

	move.l	mptr,a1
	move.l	(a1),a1
	move.l	(a1),d0
	lsr.l	#1,d0
        move.l  d0,d1
        swap    d1
	bra	cir22
cir21:	move.w	(a1)+,(a0)+
cir22:	dbf	d0,cir21
        dbf     d1,cir21


cir23:  move.l  mptr,a0
        move.l  table,a1
        move.l  m_delete(a1),a1
        jsr     (a1)

        bclr    #5,flag                 ;clear compound object flag
        bra     adjlen


***********************************
***				***
***********************************
errrts:
        move.l	savesp,sp
        jmp     abortobj
        

***********************************
***				***
***********************************
Mulu1632:
	move.l	table,a0
	move.l	mulu1632(a0),a0
	jmp	(a0)

***********************************
***				***
***********************************
Muls1632:
	move.l	table,a0
	move.l	muls1632(a0),a0
	jmp	(a0)


***********************************
***				***
***********************************
Mulu3232:
	move.l	table,a0
	move.l	mulu3232(a0),a0
	jmp	(a0)


***********************************
***				***
***********************************
Divu1648:
	move.l	table,a0
	move.l	divu1648(a0),a0
	jmp	(a0)

***********************************
***				***
***********************************
Divs3248:
	move.l	table,a0
	move.l	divs3248(a0),a0
	jmp	(a0)

*******************************************************************
***	called when the import routine choosen finds something	***
***	wrong with the file loaded.				***
*******************************************************************
never:	clr.w	d0
	rts

maybe:	move.w	#1,d0
	rts

right:	move.w	#2,d0
	rts


;************************** TEMP *********************************
        
***************************
***                     ***
***************************
checkLR:
        cmp.l   object+ob_Left,d0
        bge     checkR
        move.l  d0,object+ob_Left
        
checkR: cmp.l   object+ob_Right,d0
        ble     cklr2
        move.l  d0,object+ob_Right          
cklr2:  rts
        
***************************
***                     ***
***************************
checkTB:
        cmp.l   object+ob_Top,d0
        bge     checkB
        move.l  d0,object+ob_Top
        
checkB: cmp.l   object+ob_Bottom,d0
        ble     cktb2
        move.l  d0,object+ob_Bottom
cktb2:  rts


***************************
***                     ***
***************************
adjcoords:                              ;a0 = start address
        move.l  object+ob_Left,d1       ;d0 = number of 'commands'
        move.l  object+ob_Top,d2
        bra     adjc3
        
adjc1:  move.w  (a0)+,d3
        cmp.w   #STROKEPATH,d3          ;skip STROKEPATH
        beq     adjc3
        
        cmp.w   #FILLPATH,d3            ;skip FILLPATH
        beq     adjc3    
        
        cmp.w   #NEWPATH,d3             ;skip NEWPATH
        beq     adjc3
        
        cmp.w   #CLOSEPATH,d3           ;skip CLOSEPATH
        beq     adjc3
        
        cmp.w   #CURVETO,d3
        beq     adjc2
        
        sub.l   d1,(a0)+                ;LINETO & MOVETO have 1 point
        sub.l   d2,(a0)+
        bra     adjc3        
        
adjc2:  sub.l   d1,(a0)+                ;CURVETO has 3 points
        sub.l   d2,(a0)+
        sub.l   d1,(a0)+
        sub.l   d2,(a0)+
        sub.l   d1,(a0)+
        sub.l   d2,(a0)+
        
adjc3:  dbf     d0,adjc1
        rts


*************************************************************
*************************************************************
 SECTION DR2D,DATA,PUBLIC

chunks: dc.l    "CFIN",cfin
        dc.l    "CFLG",cflg
        dc.l    "CNAM",cnam
        dc.l    "COLR",colr
        dc.l    "DATA",data
        dc.l    "DBOX",dbox
        dc.l    "FILL",fill
        dc.l    "LINE",line
        dc.l    "OBJ ",obj
        dc.l    "OFLG",oflg
        dc.l    "PYMC",pymc
        dc.l    "SCLF",sclf
        dc.l    "STXT",stxt
        dc.l    "VBOX",vbox
        dc.l    "YMCK",ymck
        dc.l    0,skip
                
numchunks:      
        dc.w    15

special:
	dc.w	1
	dc.l	spcl1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

version:        dc.b    "$VER: "
name:	        dc.b	"ProDraw Clips v2.1.6",0

spcl1:	dc.b	"All Clips",0


 SECTION DR2D,BSS,PUBLIC
savesp:		ds.l	1
length:		ds.l	1
clength:	ds.l	1
temp:		ds.l	1
object:		ds.w	ob_SizeOf/2
color:          ds.w    cl_Sizeof/2


flag:           ds.l    1   
colortab:       ds.b    256
strtab:         ds.b    1024
colorname:      ds.b    64
cnamlen:        ds.w    1
clipnum:        ds.w    1
strtabptr:      ds.l    1
count:          ds.w    1
numcom:         ds.w    1
prevptx:        ds.l    1
prevpty:        ds.l    1
prevctx:        ds.l    1
prevcty:        ds.l    1
point2x:        ds.l    1
point2y:        ds.l    1
mptr:           ds.l    1
pptr:           ds.l    1
oflgdata:       ds.l    1
len:            ds.l    1
linewidth:      ds.w    1
fillcolor:      ds.w    1
fillflags:      ds.w    1
coltabindex:    ds.w    1
objtype:        ds.l    1
curvecount:     ds.w    1
yellow:         ds.w    1
magenta:        ds.w    1
cyan:           ds.w    1
black:          ds.w    1
leftoffset:     ds.l    1
topoffset:      ds.l    1
cw:             ds.l    1
cw0:            ds.l    1
cw2:            ds.l    1
cw4:            ds.l    1
cw34:           ds.l    1
ch:             ds.l    1
ch0:            ds.l    1
ch2:            ds.l    1
ch4:            ds.l    1
ch34:           ds.l    1
rotation:       ds.l    1
xscale:         ds.l    1
yscale:         ds.l    1
saved0:         ds.l    1
savea0:         ds.l    1
w:              ds.l    1
h:              ds.l    1
length2:        ds.l    1

************************** CHANGES ******************************************
;
;       version 2.1.6
;
;       - fixed a bug when "growing" memory. It was using the return value when
;         the function was not supposed to be returning anything valid.
;
;       - added a version string so "version prodraw.import" will report the
;         version of the module.
;
;       - fixed a bug that would cause PgS to crash when the object was pasted.
;         (the o_end call was never made to match the o_begingroup call)
;       
;       - changed the way the various implementaions of the PDRF chunk length
;         is handle - it is now ignored. The module uses the length of the 
;         file instead.
;
;       - added "clean up" code the pget? calls for d0
;
;
;       version 2.1.5   (uploaded 4/19/91)
;
;       - fixed bug when importing compound object. the default object defs
;         were getting set each time a new part of the compound obj came in.
;         this means object data such as line color and width were being set to
;         the defaults instead of the actual values wanted.
;
;       - added support for rounded ends on lines
;
;
;       version 2.1.4  (uploaded 3/29/91 ?)
;
;       - syndesis files are now imported. they were writing their files a
;         little differently than ProDraw. they did not include a COLR "chunk"
;         at the start of each color - only the color section. also the PDPF
;         length did not include the entire file as prodraw does - it was 4
;         bytes short. (it did not include the PDPF tag).
;
;       - bug fix: sometimes a clip would exit without getting to the paste
;         cursor, this was due to a routine corrupting the counting register
;         used to skip extra data not needed. This has been fixed.
;
;       - changed the way compound objects are delt with, this fixed several
;         problems with them.
;
;       - bug fix: if a circle object started a compound object it was not
;         detected and problems would result. This has been fixed.
;
;       - objects are now better aligned with other objects.
;
;       - filled open polygons are now supported.
;
;       - rotated circles are placed correctly now.
;
;
;       version 2.1.3   (shipped with PgS2.1  12/7/90)
;
;       - bug fixes: when importing older clips
;
;       - misc bugs when importing a bitmap traced object
;         (not completly fixed yet)
;
;
;       version 2.1.2   (uploaded 11/15/90 ?)
;
;       - added support for compound objects (holes&cutouts now supported)
;
;       - circles are now converted into 4 bezier curves
;
;
;       version 2.1.1   (uploaded 11/2/90)
;
;       - the size is closer to the size in prodraw
;
;
;       version 2.1.0   (uploaded w/ pagestream2.1.3)
;
;       - initial release
