
 Include "equ.h"
 Include "impequ.h"

CR      equ	$d
LF      equ	$a

 SECTION ADOBEILL,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,ADOBEILL


**********************************************
*  Is it really an AdobeIllustator Document  *
**********************************************
check:	move.l	table,a0
	move.l	buff1(a0),a1
	move.l	(a1),a1
        
        clr.l   estart                  ;incase it is not an IBM EPS file
        
        lea	ibmepsfhdr,a2           ;check for IBMEPS file
ck1:	cmp.b	(a2)+,(a1)+
	bne	ck11                    ;if not, next check (ascii eps)
	tst.b	(a2)
	bne	ck1
        
        move.b  (a1)+,estart+3 
        move.b  (a1)+,estart+2 
        move.b  (a1)+,estart+1 
        move.b  (a1)+,estart
        move.l  estart,d0
        cmp.l   #4096,d0                ;is eps start outside of buffer range?
        bcc     never                   ;yes, so I can't bring it in.
        bra     ck21                    ;go for it!

ck11:   move.l	table,a0                ;check for MacBinary EPS file
	move.l	buff1(a0),a1
	move.l	(a1),a1
        add.l   #65,a1
        
        lea     test,a0
        moveq   #3,d0
ck12:   cmp.b   (a1)+,(a0)+
        bne     ck21
        dbf     d0,ck12
        move.l  #128,estart             ;point to the data fork

ck21:   move.l  table,a0
        move.l  buff1(a0),a1            ;move to start of EPS data
        move.l  (a1),a1
        add.l   estart,a1
        
        lea	epsfhdr,a2              ;check for "%!PS-Adobe"
ck2:	cmp.b	(a2)+,(a1)+
	bne	never                   ;if not, get out
	tst.b	(a2)
	bne	ck2
ck3:    cmp.b   #"%",(a1)+
        bne     ck3
        move.l  a1,a0
        
        lea     signature1,a2           ;check for "%%Creator: Adobe Illustrator"
ck4:	cmp.b	(a2)+,(a1)+
	bne	ck5
	tst.b	(a2)
	bne	ck4
        bra     right
        
ck5:    lea     signature2,a2           ;check for "%%Creator:Adobe Illustrator"
ck6:	cmp.b	(a2)+,(a0)+
	bne	never
	tst.b	(a2)
	bne	ck6
        bra     right


***********************************
***                             ***
***********************************
ADOBEILL:
	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

        move.l  table,a0
        move.l  o_begingroup(a0),a0
        jsr     (a0)
        
        clr.l   mptr
        move.b  #0,object+ob_LColor
        move.b  #0,object+ob_LType
        move.w  #0,object+ob_LWidth
        move.b  #0,object+ob_FColor
        move.b  #0,object+ob_FType
        bsr     getpic
        
        move.l  table,a0
        move.l  o_endgroup(a0),a0
        jsr     (a0)
	
        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)

        
*********************************
*                               *
*********************************
getpic:
        move.l  estart,d0       ;f_skip kludge for PgS2.0 (fixed in 2.1)
        beq     gp1             ;if 0 do not skip anything
        
        move.l  d0,d1
        swap    d1
        and.l   #$0000ffff,d0   ;clear out upper word in d0
ekldg1: move.w  d1,-(sp)
        move.l  table,a0
        move.l  f_skip(a0),a0   ;seek start of eps data in disk file
        jsr     (a0)
        beq     errrts
        move.w  (sp)+,d1
        move.l  #$0000ffff,d0
        dbf     d1,ekldg1
        
        cmp.l   #$00010000,estart
        bcs     gp1
        move.w  #1,d0
        move.l  table,a0
        move.l  f_skip(a0),a0 
        jsr     (a0)
        beq     errrts
        
gp1:    bsr     pget            ;look for the "%%BoundingBox:"
        cmp.b   #"%",d0
        bne     gp1
        lea     bbox,a0
gp2:    bsr     pget
        move.b  (a0)+,d1
        cmp.b   d0,d1
        bne     gp1
        tst.b   (a0)
        bne     gp2
        bsr     getnum
        move.l  d0,xleft
        bsr     getnum
        move.l  d0,ybottom
        bsr     getnum
        move.l  d0,xright
        bsr     getnum
        move.l  d0,ytop
        
gp3:    bsr     pget            ;look for the "%%EndSetup"
        cmp.b   #"%",d0
        bne     gp3
        lea     endsetup,a0
gp4:    bsr     pget
        move.b  (a0)+,d1
        cmp.b   d0,d1
        bne     gp3
        tst.b   (a0)
        bne     gp4
        bsr     setobjdef
        clr.l   numindex
        bsr     newobj          ;start up with a new obj
        
gp5:    bsr     getnum
        cmp.l   #0,d1           ;did I get a number?
        bne     gp6             ;no
        lea     numtable,a0
        move.l  numindex,d1
        move.l  d0,0(a0,d1.l)
        addq.l  #4,numindex
        bra     gp5

gp6:    cmp.l   #1,d1           ;did I get a drawing command?
        bne     gp7             ;no, so it must the end of the data
        lea     routines,a0     ;yes, so get address of command and do it
        lsl.l   #2,d0
        move.l  0(a0,d0.l),a0
        jsr     (a0)
        clr.l   numindex
        bra     gp5
        
gp7:	tst.l   mptr
        beq     rrts
        
        move.l  mptr,a0
        move.l  table,a1
        move.l  m_delete(a1),a1
        jsr     (a1)
        move.l  #0,mptr
        
rrts:   rts

**********************************
**                              **
**********************************
getnum:	bsr     fget
        bsr     checkcom        ;did I get a postscript command?
        beq     gt0             ;no
        move.b  d1,d0
        moveq   #1,d1           ;d1=1 means a command is in d0
        rts
        
gt0:	bsr     checkend        ;check for end of data "%%Trailer"
        beq     gt1             ;no
        moveq   #2,d1           ;d1=2 means end of data
        rts
        
gt1:    moveq	#0,d0           ;check for a number
	moveq	#1,d2
	cmp.b	#"-",d1
	beq	gtnm2
	cmp.b	#"0",d1
	bcs	gt2
	cmp.b	#"9",d1
	bls	gtnm1
        
gt2:    cmp.b   #"(",d1         ;check for a string marker
        bne     gt4             ;no
        lea     chartable,a0
        moveq   #0,d2
gt3:    bsr     fget
        cmp.b   #")",d1
        beq     gt39
        move.b  d1,0(a0,d2.l)
        addq.l  #1,d2
        bra     gt3
        
gt39:   clr.b   0(a0,d2.l)      ;null terminate string
        move.l  d2,charcount    ;store the length of the string
        bra     getnum
        
gt4:    cmp.b   #"[",d1         ;check for a array marker
        bne     gt6             ;no
gt5:    bsr     getarray        ;yes, so get the array
        bra     getnum
        
gt6:    cmp.b   #"]",d1         ;check for end of array
        bne     gt7             ;nope
        rts                     ;yes, so return to caller (getarray)

gt7:    cmp.b   #"/",d1         ;check for a literal name 
        bne     getnum          ;nope
gt8:    bsr     fget            ;read chars until a space
        cmp.b   #" ",d1
        bne     gt8
        bra     getnum

gtnm1:	moveq	#0,d0           ;got a number
	moveq	#0,d2           ;clear negative number flag
        bra     gtnm21
        
gtnm2:	bsr     fget
gtnm21: tst.b   d1
        beq	gtnm9
	cmp.b	#"-",d1
	bne	gtnm3
	moveq	#1,d2
	bra	gtnm2
gtnm3:	cmp.b	#" ",d1
	beq	gtnm9
	cmp.b	#CR,d1
	beq	gtnm9
	cmp.b	#LF,d1
	beq	gtnm9
	cmp.b	#".",d1
	beq	gtnm11          ;get decimal part
	sub.b	#"0",d1
	bcs	gtnm9
	cmp.b	#9,d1
	bhi	gtnm9
	move.l	d0,-(sp)
	lsl.l	#2,d0		;*4
	add.l	(sp)+,d0	;*5
	lsl.l	#1,d0		;*10
	and.l	#$ff,d1
	add.l	d1,d0
	bra	gtnm2

gtnm9:	mulu    #100,d0
        tst.w	d2              ;is it a negative number
	beq	gtnm10          ;no
	neg.l	d0
gtnm10: clr.l   d1              ;d1=0 means a number is in d0
	rts

gtnm11: mulu    #100,d0
        move.l  d0,fint         ;save integer part for later
        moveq   #0,d0
        move.l  #2,dcount
        
gtnm12: bsr     fget
        tst.b   d1
        beq	gtnm19
	cmp.b	#" ",d1
	beq	gtnm19
	cmp.b	#CR,d1
	beq	gtnm19
	cmp.b	#LF,d1
	beq	gtnm19
	sub.b	#"0",d1
	bcs	gtnm19
	cmp.b	#9,d1
	bhi	gtnm19
	move.l	d0,-(sp)
	lsl.l	#2,d0		;*4
	add.l	(sp)+,d0	;*5
	lsl.l	#1,d0		;*10
	and.l	#$ff,d1
	add.l	d1,d0
        subq.l  #1,dcount       ;decrement decimal counter (only need 2)
        bne     gtnm12          ;if not done, keep going
        
gtnm13: bsr     fget            ;skip numbers until a non-number
	beq	gtnm19
	sub.b	#"0",d1
	bcs	gtnm19
	cmp.w	#9,d1
	bhi	gtnm19
	bra	gtnm13
        
gtnm19: tst.l   dcount
        beq     gtnm20
        move.l	d0,-(sp)
	lsl.l	#2,d0		;*4
	add.l	(sp)+,d0	;*5
	lsl.l	#1,d0		;*10
        subq.l  #1,dcount       ;decrement decimal counter (only need 2)
        bne     gtnm19          ;if not done, keep going

gtnm20: add.l   d0,fint         ;add decimnal part to the integer part
        move.l  fint,d0         ;get number into d0
        tst.w   d2              ;is this a negative number?
        beq     gtnm22          ;no
        neg.l   d0 
gtnm22: moveq   #0,d1           ;d1=0 means a number is in d0
        rts

***********************************
***				***
***********************************
checkcom:
        lea	commands,a0             ;check for any drawing command 
        clr.l   d3
cc1:    move.b  (a0)+,d2
        cmp.b   d1,d2
        beq     cc2
        addq.l  #1,d3
        tst.b   (a0)
        bne     cc1
        moveq   #0,d0                   ;return no
        rts

cc2:    move.l  d3,d1
        moveq   #1,d0                   ;return yes
        rts
        
***********************************
***				***
***********************************        
checkend:
        cmp.b   #"%",d1
        bne     ce7
        
        lea	dataend,a0              ;check for "%%Trailer"
ce1:    bsr     pget
        move.b  (a0)+,d2
        cmp.b   d0,d2
        bne     ce5
        tst.b   (a0)
        bne     ce1
        moveq   #1,d0                   ;return yes
        rts
        
ce5:    cmp.b   #CR,d0                  ;skip until end of line
        beq     ce7
        cmp.b   #LF,d0
        beq     ce7
        bsr     pget
        bra     ce5
        
ce7:    moveq   #0,d0                   ;return no
        rts
        
*********************************
*                               *
*********************************
getarray:
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,0(a0)
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,4(a0)
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,8(a0)
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,12(a0)
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,16(a0)
        bsr     getnum
        tst.l   d1
        bne     gta1
        lea     array,a0
        move.l  d0,20(a0)
        
gta1:   rts
        
*********************************
*                               *
*********************************
newobj:
        move.l	#ply_Sizeof+2,d0
	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),a1
        lea     ply_Sizeof(a1),a1
        move.b  #tpoly,object+ob_Type
        move.w  #NEWPATH,(a1)+
        move.l  #ply_Sizeof+2,len       ;set starting length of poly stuff
        move.w  #1,numcom               ;set poly command counter to 1
        move.l  #$7fffffff,object+ob_Left
        move.l  #$7fffffff,object+ob_Top
        move.l  #$80000000,object+ob_Right
        move.l  #$80000000,object+ob_Bottom
        bclr    #0,flag                 ;new obj has no data (yet...)
        rts

*********************************
*                               *
*********************************
d:
        rts

*********************************
*                               *
*********************************
g:
        lea     numtable,a0
        move.l  (a0),d0
        move.l  #100,d1
        sub.l   d0,d1
        move.l  d1,d0
        tst.l   d0                      ;check for 0% black (white)
        bne     g1                      ;nope
        move.b  #9,object+ob_FType
        move.b  #0,object+ob_FColor
        rts
        
g1:     cmp.l   #100,d0                 ;check for 100% black (black)
        bne     g2
        move.b  #9,object+ob_FType
        move.b  #1,object+ob_FColor
        rts
        
g2:     bset    #7,d0
        move.b  d0,object+ob_FType      ;percentage fill type
        move.b  #1,object+ob_FColor     ;set color to black
        rts

*********************************
*                               *
*********************************
G:
        lea     numtable,a0
        move.l  (a0),d0
        cmp.l   #100,d0                 ;check for 100% black (black)
        beq     G1                      ;yes
        
        cmp.l   #0,d0                   ;check for 0% black (white)
        beq     G2                      ;yes
        
        move.l  d0,12(a0)               ;else add a new color
        clr.l   (a0)
        clr.l   4(a0)
        clr.l   8(a0)
        bsr     addcolor                ;returns PGScolor in d0
        move.b  d0,object+ob_LColor     ;set the line color
        move.b  #1,object+ob_LType      ;line type = solid
        bra     G3
        
G1:     move.b  #1,object+ob_LType      ;fill type = solid
        move.b  #0,object+ob_LColor     ;fill color = black
        bra     G3
        
G2:     move.b  #1,object+ob_LType      ;fill type = solid
        move.b  #1,object+ob_LColor     ;fill color = white
        
G3:     rts

*********************************
*                               *
*********************************
i:
        rts

*********************************
*                               *
*********************************
j:
        lea     numtable,a0
        move.l  (a0),d0
        cmp.l   #100,d0                 ;check for rouned ends
        bne     j1                      ;no
        move.b   #2,object+ob_LBegin
        move.b   #2,object+ob_LEnd
        rts

j1:     move.b   #0,object+ob_LBegin
        move.b   #0,object+ob_LEnd
        rts

*********************************
*                               *
*********************************
J:
        lea     numtable,a0
        move.l  (a0),d0
        cmp.l   #100,d0                 ;check for rounded ends
        bne     J1                      ;no
        move.b   #2,object+ob_LBegin
        move.b   #2,object+ob_LEnd
        rts

J1:     move.b   #0,object+ob_LBegin
        move.b   #0,object+ob_LEnd
        rts

*********************************
*                               *
*********************************
k:      bsr     addcolor                        ;returns Pgscolor in d0
        move.b  #9,object+ob_FType
        move.b  d0,object+ob_FColor
        rts
        
*********************************
*                               *
*********************************
K:      bsr     addcolor                        ;returns Pgscolor in d0
        move.b  #1,object+ob_LType
        move.b  d0,object+ob_LColor
        rts

*********************************
*                               *
*********************************
M:
        rts

*********************************
*                               *
*********************************
w:
        lea     numtable,a0
        move.l  (a0),d0
        move.w  d0,object+ob_LWidth    ;line width
        rts

*********************************
*                               *
*********************************
z:
        rts

*********************************
*                               *
*********************************
Z:
        rts

*********************************
*                               *
*********************************
C:
c:
        bset    #0,flag                 ;this obj has data
        bset    #2,flag                 ;set the line flag ignore bit
        move.l  #26,d0                  ;need to grow memory by 26
        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
        lea     numtable,a1
        
        move.w  #CURVETO,(a0)+          ;put the command
        
        move.l  0(a1),d0
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  4(a1),d0
        bsr     checkTB
        move.l  d0,(a0)+
        
        move.l  8(a1),d0
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  12(a1),d0
        bsr     checkTB
        move.l  d0,(a0)+
        
        move.l  16(a1),d0
        move.l  d0,curx
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  20(a1),d0
        move.l  d0,cury
        bsr     checkTB
        move.l  d0,(a0)+
        
        add.l   #26,len                 ;adjust the counters
        addq.w  #1,numcom
        rts

*********************************
*                               *
*********************************
L:
l:
        bset    #0,flag                 ;this obj has data
        btst    #1,flag                 ;has the line flag been set yet?
        bne     l1                      ;yes, so set the line flag ignore bit
        bset    #1,flag                 ;else, set the line flag
        bra     l2
l1:     bset    #2,flag                 ;set the line flag ignore bit
l2:     move.l  #10,d0                  ;need to grow memory by 8
        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
        lea     numtable,a1
        
        move.w  #LINETO,(a0)+           ;put the command
        
        move.l  (a1),d0
        move.l  d0,curx
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  4(a1),d0
        move.l  d0,cury
        bsr     checkTB
        move.l  d0,(a0)+
        
        add.l   #10,len                 ;adjust the counters
        addq.w  #1,numcom
        rts

*********************************
*                               *
*********************************
m:
        move.l  #10,d0                   ;need to grow memory by 8
        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
        lea     numtable,a1
        
        move.w  #MOVETO,(a0)+           ;put the command
        
        move.l  0(a1),d0
        move.l  d0,curx
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  4(a1),d0
        move.l  d0,cury
        bsr     checkTB
        move.l  d0,(a0)+
        
        add.l   #10,len                 ;adjust the counters
        addq.w  #1,numcom
        rts

*********************************
*                               *
*********************************
t:
        rts
*********************************
*                               *
*********************************
T:
        rts
        
*********************************
*                               *
*********************************
V:
v:
        bset    #0,flag                 ;this obj has data
        bset    #2,flag                 ;set the line flag ignore bit
        move.l  #26,d0                  ;need to grow memory by 26
        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
        lea     numtable,a1
        
        move.w  #CURVETO,(a0)+          ;put the command
        
        move.l  curx,(a0)+
        move.l  cury,(a0)+
        
        move.l  0(a1),d0
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  4(a1),d0
        bsr     checkTB
        move.l  d0,(a0)+
        
        move.l  8(a1),d0
        move.l  d0,curx
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  12(a1),d0
        move.l  d0,cury
        bsr     checkTB
        move.l  d0,(a0)+
        
        add.l   #26,len                 ;adjust the counters
        addq.w  #1,numcom
        rts


*********************************
*                               *
*********************************
Y:
y:
        bset    #0,flag                 ;this obj has data
        bset    #2,flag                 ;set the line flag ignore bit
        move.l  #26,d0                  ;need to grow memory by 26
        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
        lea     numtable,a1
        
        move.w  #CURVETO,(a0)+          ;put the command
        
        move.l  0(a1),d0
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  4(a1),d0
        bsr     checkTB
        move.l  d0,(a0)+
        
        move.l  8(a1),(a0)+
        move.l  12(a1),(a0)+
        
        move.l  8(a1),d0
        move.l  d0,curx
        bsr     checkLR
        move.l  d0,(a0)+
        
        move.l  12(a1),d0
        move.l  d0,cury
        bsr     checkTB
        move.l  d0,(a0)+        
        
        add.l   #26,len                 ;adjust the counters
        addq.w  #1,numcom
        rts

*********************************
*                               *
*********************************
b:
        move.l  #4,d0                   ;need to grow memory by 4
        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.w  #CLOSEPATH,(a0)+        ;put the command
        move.w  #FILLPATH,(a0)+
        add.l   #4,len                  ;adjust the counters
        addq.w  #2,numcom
        bsr     finishobj
        rts

*********************************
*                               *
*********************************
B:
        move.l  #2,d0                   ;need to grow memory by 2
        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.w  #FILLPATH,(a0)+
        add.l   #2,len                  ;adjust the counters
        addq.w  #1,numcom
        bsr     finishobj
        rts

*********************************
*                               *
*********************************
f:
        move.l  #4,d0                   ;need to grow memory by 2
        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.w  #CLOSEPATH,(a0)+        ;put the command
        move.w  #FILLPATH,(a0)+
        add.l   #4,len                  ;adjust the counters
        addq.w  #2,numcom
        
        move.b  object+ob_LType,holdbyte
        clr.b   object+ob_LType
        bsr     finishobj
        move.b  holdbyte,object+ob_LType
        rts

*********************************
*                               *
*********************************
F:
        move.l  #2,d0                   ;need to grow memory by 2
        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.w  #FILLPATH,(a0)+
        add.l   #2,len                  ;adjust the counters
        addq.w  #1,numcom
        
        move.b  object+ob_LType,holdbyte
        clr.b   object+ob_LType
        bsr     finishobj
        move.b  holdbyte,object+ob_LType
        rts

*********************************
*                               *
*********************************
h:
n:
        move.l  #2,d0                   ;need to grow memory by 2
        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.w  #CLOSEPATH,(a0)+
        add.l   #2,len                  ;adjust the counters
        addq.w  #1,numcom
        
        move.b  object+ob_LType,holdbyte
        move.b  object+ob_FType,holdbyte2
        clr.b   object+ob_LType
        clr.b   object+ob_FType
        bsr     finishobj
        move.b  holdbyte,object+ob_LType
        move.b  holdbyte2,object+ob_FType
        rts

*********************************
*                               *
*********************************
H:
N:
        bsr     finishobj
        rts

*********************************
*                               *
*********************************
s:
        move.l  #4,d0                   ;need to grow memory by 4
        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.w  #CLOSEPATH,(a0)+        ;put the command
        move.w  #STROKEPATH,(a0)+
        add.l   #4,len                  ;adjust the counters
        addq.w  #2,numcom
        
        move.b  object+ob_FType,holdbyte
        clr.b   object+ob_FType
        bsr     finishobj
        move.b  holdbyte,object+ob_FType
        rts

*********************************
*                               *
*********************************
S:
        move.l  #2,d0                   ;need to grow memory by 2
        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.w  #STROKEPATH,(a0)+
        add.l   #2,len                  ;adjust the counters
        addq.w  #1,numcom
        
        move.b  object+ob_FType,holdbyte
        clr.b   object+ob_FType
        bsr     finishobj
        move.b  holdbyte,object+ob_FType
        rts

*********************************
*                               *
*********************************
u:
        ;move.l  table,a0
        ;move.l  o_begingroup(a0),a0
        ;jsr     (a0)
        rts

*********************************
*                               *
*********************************
U:
        ;move.l  table,a0
        ;move.l  o_endgroup(a0),a0
        ;jsr     (a0)
        rts

*********************************
*                               *
*********************************
p:
        rts

*********************************
*                               *
*********************************
O:
        rts

*********************************
*                               *
*********************************
Q:
        rts
        
*********************************
*                               *
*********************************
q:
        rts

        
***************************
***                     ***
***************************
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  a0,savea0
        move.l  d0,saved0
        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

        move.l  saved0,d0
        move.l  savea0,a0
        
        move.l  object+ob_Bottom,d1
        sub.l   object+ob_Top,d1
        bra     adjc19

adjc11: move.w  (a0)+,d3                ;get the command
        
        cmp.w   #STROKEPATH,d3          ;skip STROKEPATH
        beq     adjc19
        
        cmp.w   #FILLPATH,d3            ;skip FILLPATH
        beq     adjc19   
        
        cmp.w   #NEWPATH,d3             ;skip NEWPATH
        beq     adjc19
        
        cmp.w   #CLOSEPATH,d3           ;skip CLOSEPATH
        beq     adjc19
        
        cmp.w   #CURVETO,d3
        beq     adjc12
        
        add.l   #4,a0                   ;skip the X coord
        move.l  (a0),d2                 ;adjust the Y coord
        neg.l   d2
        add.l   d1,d2
        move.l  d2,(a0)+
        bra     adjc19
        
adjc12: add.l   #4,a0                   ;skip over the X coord
        move.l  (a0),d2                 ;adjust the Y coord
        neg.l   d2
        add.l   d1,d2
        move.l  d2,(a0)+
        
        add.l   #4,a0                   ;skip over the X coord
        move.l  (a0),d2                 ;adjust the Y coord
        neg.l   d2
        add.l   d1,d2
        move.l  d2,(a0)+
        
        add.l   #4,a0                   ;skip over the X coord
        move.l  (a0),d2                 ;adjust the Y coord
        neg.l   d2
        add.l   d1,d2
        move.l  d2,(a0)+
        
adjc19: dbf     d0,adjc11        
        
adjc20: rts

***********************************
***				***
***********************************
adjobj:
        move.l  object+ob_Top,d1
        move.l  object+ob_Bottom,object+ob_Top
        move.l  d1,object+ob_Bottom
        
        move.l  ytop,d1
        sub.l   ybottom,d1
        move.l  object+ob_Top,d2
        neg.l   d2
        add.l   d1,d2
        move.l  d2,object+ob_Top
        
        move.l  object+ob_Bottom,d2
        neg.l   d2
        add.l   d1,d2
        move.l  d2,object+ob_Bottom
        
adjo2:  rts

***************************
***                     ***
***************************
setobjdef:
        clr.b   object+ob_Flag
        clr.w   object+ob_Slant
        clr.w   object+ob_Twist        
        clr.w   object+ob_HStandOff   
        clr.w   object+ob_VStandOff
        rts
        
***********************************
***                             ***
***********************************
finishobj:
        btst    #0,flag                 ;does this obj have any data?
        beq     fini4                   ;no, so get out

        btst    #2,flag                 ;should I ignore the line flag bit?
        bne     fini0                   ;yes
        
        btst    #1,flag                 ;is the data only 1 lineto command?
        beq     fini0                   ;no, so handle object as a poly
        
        ;handle object as a line object
lin1:   move.b  #thvln,object+ob_Type   ;force a hori/vert line to start with
        move.l  object+ob_Left,d0
        move.l  object+ob_Right,d2
        move.l  object+ob_Top,d1
        move.l  object+ob_Bottom,d3
        cmp.l   d2,d0                   ;is it a horizontal line?
        beq     lin2                    ;yes
        cmp.l   d3,d1                   ;is it a vertical line?
        beq     lin2                    ;yes
        move.b  #tdln,object+ob_Type    ;object is a diag line

lin2:   cmp.l   d2,d0                   ;is right edge > left edge
        bcs     lin3                    ;yes, so do nothing
        move.l  d2,object+ob_Left       ;else, switch 'em
        move.l  d0,object+ob_Right
        
lin3:   cmp.l   d3,d1                   ;is bottom edge > top edge 
        bcs     lin4                    ;yes, so do nothing
        move.l  d3,object+ob_Top        ;else switch 'em
        move.l  d1,object+ob_Bottom
        
lin4:   bsr     putobj
        bra     fini4                   ;free mem for object and exit

fini0:  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,d1
        sub.l   object+ob_Left,d1
        move.l  d1,ply_Width(a0)
        
        move.l  object+ob_Bottom,d0
        sub.l   object+ob_Top,d0
        move.l  d0,ply_Height(a0)
        
        add.l   d1,d0                   ;does the objetc have any dimension?
        tst.l   d0                      ;
        beq     fini4                   ;no, so throw it away
                
        move.w  #100,ply_XScale(a0)
        move.w  #100,ply_YScale(a0)
        move.w  numcom,ply_Count(a0)
        
        tst.w   object+ob_LWidth
        bne     fini1
        
        move.b  #1,object+ob_LColor
        move.b  #0,object+ob_LType
     
fini1:  move.l  mptr,a0
        move.l  (a0),a0
        lea     ply_Sizeof(a0),a0
        clr.l   d0
        move.w  numcom,d0
        bsr     adjcoords
        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	fini3
fini2:	move.w	(a1)+,(a0)+
fini3:	dbf	d0,fini2
        dbf     d1,fini3

fini4:  move.l  mptr,a0
        move.l  table,a1
        move.l  m_delete(a1),a1
        jsr     (a1)
        move.l  #0,mptr
        bsr     newobj          ;set up for next object
        bclr    #1,flag         ;clear the bit flags
        bclr    #2,flag
        rts

***********************************
***				***
***********************************
addcolor:
        clr.l   d3
        lea     numtable,a0
addc4:  move.l  0(a0),d0
        mulu    #100,d0
        move.w  d0,color+cl_Cyan
        move.l  4(a0),d0
        mulu    #100,d0
        move.w  d0,color+cl_Magenta
        move.l  8(a0),d0
        mulu    #100,d0
        move.w  d0,color+cl_Yellow
        move.l  12(a0),d0
        mulu    #100,d0
        move.w  d0,color+cl_Black
        clr.w   color+cl_Type
        clr.w   color+cl_Map
        
        move.w  color+cl_Cyan,d0
        mulu    #255,d0
        divu    #10000,d0
        and.l   #$0000ffff,d0
        bsr     hex2ascii
        move.b  d0,colorname+5
        move.b  d1,colorname+6
        
        move.w  color+cl_Magenta,d0
        mulu    #255,d0
        divu    #10000,d0
        and.l   #$0000ffff,d0
        bsr     hex2ascii
        move.b  d0,colorname+7
        move.b  d1,colorname+8
        
        move.w  color+cl_Yellow,d0
        mulu    #255,d0
        divu    #10000,d0
        and.l   #$0000ffff,d0
        bsr     hex2ascii
        move.b  d0,colorname+9
        move.b  d1,colorname+10
        
        move.w  color+cl_Black,d0
        mulu    #255,d0
        divu    #10000,d0
        and.l   #$0000ffff,d0
        bsr     hex2ascii
        move.b  d0,colorname+11
        move.b  d1,colorname+12

        lea     colorname,a0            ;copy the color name into cl_Name
        lea     color+cl_Name,a1
        move.w  #13,d0
addc5:  move.b  (a0)+,(a1)+
        dbf     d0,addc5
      
        lea     color,a0                ;add the color to the global color tab
        move.l  table,a1
        move.l  newcolor(a1),a1
        jsr     (a1)
        move.l  d0,saved0
        
        lea     color,a0                ;add the color to the doc color tab
        move.l  table,a1
        move.l  findcolorname(a1),a1
        jsr     (a1)
        cmp.w   #$ffff,d0
        bne     addc51
        
        move.l  saved0,d0
        
addc51: 
addc6:  rts


***********************************
***				***
***********************************
hex2ascii:
        move.b  d0,d1
        and.b   #$f0,d0                 ;d0 = upper nibble
        lsr.b   #4,d0
        and.b   #$0f,d1                 ;d1 = lower nibble
        
        cmp.b   #$0a,d0                 ;is d0 greater or equal to 10
        bcc     h2a1                    ;yes
        or.b    #$30,d0                 ;if not make it into the ascii of 0-9
        bra     h2a2
h2a1:   add.b   #55,d0                  ;make it ascii A-F

h2a2:   cmp.b   #$0a,d1
        bcc     h2a3
        or.b    #$30,d1
        bra     h2a4
h2a3:   add.b   #55,d1

h2a4:   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  a0,-(sp)
        move.l	table,a0
	move.l	f_get(a0),a0
	jsr	(a0)
	beq	errrts
        and.l   #$000000ff,d0                   ;clean up d0
        move.l  (sp)+,a0
	rts

*********************************
*                               *
*********************************
fget:	movem.l d0/d2-d4/a0-a2,-(sp)
        move.l	table,a0
	move.l	f_get(a0),a0
	jsr	(a0)
	beq	errrts
        and.l   #$000000ff,d0
        move.l  d0,d1
        movem.l (sp)+,d0/d2-d4/a0-a2
	rts

***************************
***                     ***
***************************
putobj:	bsr     adjobj
        move.l	table,a1
	move.l	o_obj(a1),a1
	lea	object,a0
	jsr	(a1)
        beq     errrts
                
        rts
        
***********************************
***				***
***********************************
errrts:
        move.l	savesp,sp
        tst.l   mptr
        beq     er1
        
        move.l  mptr,a0
        move.l  table,a1
        move.l  m_delete(a1),a1
        jsr     (a1)
        move.l  #0,mptr
        
er1:    jmp     abortobj
        

*******************************************************************
***	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
        
*************************************************************
*************************************************************
 SECTION ADOBEILL,DATA,PUBLIC

special:
	dc.w	1
	dc.l	spcl1,0

routines:       dc.l    d,g,G,i,j,J,k,K,M,w,z,Z,c,C,l,L,m,t,T,v,V,y,Y
                dc.l    b,B,f,F,n,N,s,S,u,U,p,H,h,O,Q,q,0

version:        dc.b    0,"$VER: "
name:	        dc.b	"Illustrator v2.1.2",0

spcl1:	dc.b	"Object",0

holdbyte:       dc.b    0
holdbyte2:      dc.b    0

colorname:      dc.b    "Adobe00000000",0

bbox:		dc.b	"%BoundingBox:",0
epsfhdr:        dc.b    "%!PS-Adobe",0
signature1:     dc.b    "%Creator: Adobe Illustrator",0
signature2:     dc.b    "%Creator:Adobe Illustrator",0
endsetup:       dc.b    "%EndSetup",0
note:           dc.b    "%Note:",0
dataend:        dc.b    "%Trailer",0
commands:       dc.b    "dgGijJkKMwzZcClLmtTvVyYbBfFnNsSuUpHhOQq",0
ibmepsfhdr:	dc.b	$c5,$d0,$d3,$c6,0
test:           dc.b    "EPSF",0


*************************************************************
*************************************************************
 SECTION ADOBEILL,BSS,PUBLIC
savesp:		ds.l	1
temp:		ds.l	1
object:		ds.w	ob_SizeOf/2
color:          ds.w    cl_Sizeof/2
xleft:          ds.l    1
xright:         ds.l    1
ybottom:        ds.l    1
ytop:           ds.l    1
numindex:       ds.l    1
numcom:         ds.w    1
mptr:           ds.l    1
len:            ds.l    1
curx:           ds.l    1
cury:           ds.l    1
flag:           ds.l    1
savea0:         ds.l    1
saved0:         ds.l    1
fint:           ds.l    1
dcount:         ds.l    1
estart:         ds.l    1
numtable:       ds.l    64
array:          ds.l    6
charcount:      ds.l    1
chartable:      ds.b    256

************************** CHANGES ******************************************
;
;       version 2.1.2
;
;       - added "clean up" code to pget? for d0
;
;
;       version 2.1.1
;
;       - added support for the H and h commands
;
;       - added ability to skip the Q,q,O commands
;
;       - added a version string for 'version illustrator.import' to work
;
;       - added support for Mac Eps files (w/ mac file headers)
;
;       - fixed a bug when "growing" memory - did not matter in Amiga verison
;         but caused crashes on the Atari.
;
;       - fixed bug when importing line objects - I now change them to actaul
;         line objects and not poly objects that are only 1 line.
;

;
;
;       version 2.1.0
;
;       - initial release
