 Include "equ.h"
 Include "impequ.h"

QUOTE	equ	"\""
BACK	equ	"\\"

 SECTION aegis,CODE,PUBLIC

*******************************************
***  object format			***
*******************************************
dummy:	clr.l	d0
	rts

	dc.l	"IMPO"
	dc.w	201
	dc.l	0

table:	dc.l	0
	dc.l	name,special,check,aegis

*
* Aegis Draw File
*
check:	move.l	table,a0
	move.l	buff1(a0),a1
	move.l	(a1),a1
	cmp.b	#"8",(a1)+
	bne	never
	cmp.b	#"1",(a1)+
	bne	never
	cmp.b	#"0",(a1)+
	bne	never
	cmp.b	#"8",(a1)+
	bne	never
	cmp.b	#"6",(a1)+
	bne	never
	moveq	#2,d0
rrts:	rts
*
*
*
aegis:	move.l	sp,savesp

	lea	object,a0
	clr.b	ob_Flag(a0)
	clr.w	ob_Slant(a0)
	clr.w	ob_Twist(a0)
	move.b	#1,ob_LColor(a0)		;black line
	move.b	#1,ob_FColor(a0)		;black fill
	clr.b	ob_LBegin(a0)
	clr.b	ob_LEnd(a0)
	clr.w	ob_HStandOff(a0)
	clr.w	ob_VStandOff(a0)

	lea	colormap,a0
;	move.w	#0,(a0)+		;white
;	move.w	#1,(a0)+		;black
	moveq	#29,d0
dcmap1:	move.w	#-1,(a0)+		;undefined
	dbf	d0,dcmap1

;	lea	clrnm0,a0
;	move.l	table,a1
;	move.l	findcolorname(a1),a1
;	jsr	(a1)
;	tst.w	d0
;	bmi	dcmap2
;	move.w	d0,colormap+0
;
;dcmap2:	lea	clrnm1,a0
;	move.l	table,a1
;	move.l	findcolorname(a1),a1
;	jsr	(a1)
;	tst.w	d0
;	bmi	dcmap3
;	move.w	d0,colormap+2


dcmap3:	move.l	table,a0
	move.l	f_openr(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	o_open(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	o_begingroup(a0),a0
	jsr	(a0)
	beq	ofail

	clr.l	partlist

	bsr	integer			;magic number
	cmp.l	#81086,d0
	bne	ofail

	bsr	float			;left edge of drawing
	move.l	d0,dxoff
	bsr	float			;bottom edge of drawing
	move.l	d0,dyoff
	bsr	float			;width of drawing
	move.l	d0,dwidth
	bsr	float			;height of drawing
	move.l	d0,dheight
	bsr	integer			;unused flags
	bsr	float			;scale
	move.w	d0,dscale
	bsr	string			;name of the drawing
*
* get the parts definition
*
define:	bsr	integer
	cmp.w	#-1,d0
	beq	nopart

	move.w	dscale,cscale
	bsr	integer
	bsr	string
	bsr	float
	move.l	d0,cxoff
	move.l	d0,e_minx
	bsr	float
	move.l	d0,cyoff
	move.l	d0,e_miny
	bsr	float
	move.l	d0,e_maxx
	sub.l	e_minx,d0
	move.l	d0,cwidth
	bsr	float
	move.l	d0,e_maxy
	sub.l	e_miny,d0
	move.l	d0,cheight

	move.l	#122,d0
	clr.w	d1
	clr.w	d2
	move.l	table,a1
	move.l	m_alloc(a1),a1
	jsr	(a1)
	beq	ofail
	move.l	partlist,a1
	move.l	a0,partlist
	move.l	a0,curpart
	move.l	#122,curlength

	move.l	(a0),a0
	move.l	a1,(a0)+
	clr.w	(a0)+
	move.l	e_minx,(a0)+
	move.l	e_miny,(a0)+
	move.l	e_maxx,(a0)+
	move.l	e_maxy,(a0)+
	lea	strng,a1
prtnm1:	move.b	(a1)+,(a0)+
	bne	prtnm1

prtnm2:	bsr	integer
	cmp.w	#-1,d0
	beq	define
	move.w	d0,e_id
	move.b	#1,partflag
	bsr	getobject
	bra	prtnm2

*
* now get the drawing
*
nopart:	move.l	dxoff,cxoff
	move.l	dyoff,cyoff
	move.l	dwidth,cwidth
	move.l	dheight,cheight
	move.w	dscale,cscale
drawing:
	bsr	integer
	cmp.w	#-1,d0
	beq	done
	move.w	d0,e_id
	clr.b	partflag
	bsr	getobject
	bra	drawing

*
* end of input file.  close and flush buffer
*
done:	bsr	removepart


	move.l	table,a0
	move.l	o_endgroup(a0),a0
	jsr	(a0)
	beq	ofail

	move.l	table,a0
	move.l	o_close(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	f_closer(a0),a0
	jmp	(a0)
*
*
*
ofail:	move.l	savesp,sp

	bsr	removepart

	move.l	table,a0
	move.l	o_abort(a0),a0
	jsr	(a0)

	move.l	table,a0
	move.l	f_closer(a0),a0
	jmp	(a0)


removepart:
	tst.l	partlist
	beq	rrts
	move.l	partlist,a0
	move.l	(a0),a1
	move.l	(a1),partlist
	move.l	table,a1
	move.l	m_delete(a1),a1
	jsr	(a1)
	bra	removepart


getobject:
	bsr	integer
	move.w	d0,e_size
	bsr	coord
	move.l	d0,e_minx
	move.l	d1,e_miny
	bsr	coord
	move.l	d0,e_maxx
	move.l	d1,e_maxy
*
* get the color
*
	bsr	integer
	move.w	d0,e_color
	lsl.w	#1,d0
	lea	colormap,a0
	move.w	0(a0,d0.w),d0
	bpl	cmap9
	lea	color+cl_Name,a0
	lea	clrnm,a1
cmap1:	move.b	(a1)+,(a0)+
	bne	cmap1
	subq.l	#1,a0

	moveq	#0,d0
	move.w	e_color,d0
	divu	#10,d0
	tst.w	d0
	beq	cmap2
	or.b	#"0",d0
	move.b	d0,(a0)+
cmap2:	swap	d0
	or.b	#"0",d0
	move.b	d0,(a0)+
	clr.b	(a0)

	lea	color,a0
	move.w	#0,cl_Cyan(a0)
	move.w	#0,cl_Magenta(a0)
	move.w	#0,cl_Yellow(a0)
	move.w	#10000,cl_Black(a0)
	clr.w	cl_Map(a0)
	clr.w	cl_Type(a0)
	move.l	table,a1
	move.l	newcolor(a1),a1
	jsr	(a1)
	tst.w	d0
	bmi	cmap7

	lea	color,a0
	move.l	table,a1
	move.l	findcolorname(a1),a1
	jsr	(a1)
	tst.w	d0
	bpl	cmap8

cmap7:	moveq	#1,d0
cmap8:	lea	colormap,a0
	move.w	e_color,d1
	lsl.w	#1,d1
	move.w	d0,0(a0,d1.w)
cmap9:	move.b	d0,object+ob_LColor
	move.b	d0,object+ob_FColor
*
*
*
	bsr	integer
	move.w	d0,e_layer
	bsr	integer
	move.w	d0,e_pattern
	bsr	integer
	move.w	d0,e_weight
	bsr	integer
	move.w	d0,e_flags
	move.w	e_id,d0
	cmp.w	#8,d0
	bcc	rrts
	lsl.w	#2,d0
	jmp	etable(pc,d0.w)

*
*
*
etable:	bra.w	rrts
	bra.w	polygon
	bra.w	circle
	bra.w	text
	bra.w	dimension
	bra.w	part
	bra.w	arc
	bra.w	arc


*******************************************
***					***
*******************************************
polygon:
	move.l	e_minx,object+ob_Left
	move.l	e_maxy,object+ob_Top
	move.l	e_maxx,object+ob_Right
	move.l	e_miny,object+ob_Bottom
	move.b	#tpoly,object+ob_Type
	bsr	settypes
	clr.w	object+ob_Slant
	clr.w	object+ob_Twist

* length,width,height,xscl,yscl,cnt
* newpath
*  moveto x,y
*  lineto x,y
* stroke

	move.l	table,a0
	move.l	m_alloc(a0),a0
	tst.b	object+ob_FType
	beq	ply00
	move.l	#24,d0
	bra	ply0
ply00:	move.l	#22,d0
ply0:	clr.w	d1
	clr.w	d2
	jsr	(a0)
	move.l	a0,mptr
	move.l	#20,moff
	clr.w	count

ply1:	bsr	integer
	cmp.w	#0,d0
	beq	ply5

	move.l	table,a1
	move.l	m_grow(a1),a1
	move.l	#10,d0
	move.l	mptr,a0
	jsr	(a1)

	bsr	coord
	sub.l	object+ob_Left,d0
	sub.l	object+ob_Top,d1

	move.l	mptr,a0
	move.l	(a0),a0
	add.l	moff,a0
	tst.w	count
	bne	ply2
	move.w	#MOVETO,(a0)+
	bra	ply3
ply2:	move.w	#LINETO,(a0)+
ply3:	move.l	d0,(a0)+
	move.l	d1,(a0)+

	addq.w	#1,count
	add.l	#10,moff
	bra	ply1

ply5:	move.l	mptr,a0
	move.l	(a0),a0
	move.w	count,d0
	mulu	#10,d0		;* bytes per line
	tst.b	object+ob_FType
	beq	ply6
	add.l	#24,d0		;length,width,height,xscl,yscl,cnt,newpath,closepath,fillpath
	bra	ply7
ply6:	add.l	#22,d0		;length,width,height,xscl,yscl,cnt,newpath,strokepath
ply7:	move.l	d0,(a0)+
	move.l	object+ob_Right,d1
	sub.l	object+ob_Left,d1
	move.l	d1,(a0)+
	move.l	object+ob_Bottom,d1
	sub.l	object+ob_Top,d1
	move.l	d1,(a0)+
	move.w	#100,(a0)+
	move.w	#100,(a0)+
	move.w	count,d1
	addq.w	#2,d1			;+ newpath,stroke
	tst.b	object+ob_FType
	beq	ply8
	addq.w	#1,d1
ply8:	move.w	d1,(a0)+
	move.w	#NEWPATH,(a0)+

	move.l	mptr,a0
	move.l	(a0),a0
	add.l	moff,a0
	tst.b	object+ob_FType
	beq	ply9
	move.w	#CLOSEPATH,(a0)+
	move.w	#FILLPATH,(a0)+
	bra	ply10
ply9:	move.w	#STROKEPATH,(a0)+
*
ply10:	cmp.w	#2,count
	beq	plyline
	cmp.w	#5,count
	bne	notbox
	move.l	mptr,a0
	move.l	(a0),a0
	lea	20(a0),a0
	move.l	2+0(a0),d0
	move.l	2+4(a0),d1
	move.l	22+0(a0),d2
	move.l	22+4(a0),d3
	cmp.l	12+0(a0),d0
	bne	notbox
	cmp.l	12+4(a0),d3
	bne	notbox
	cmp.l	32+0(a0),d2
	bne	notbox
	cmp.l	32+4(a0),d1
	bne	notbox
	cmp.l	42+0(a0),d0
	bne	notbox
	cmp.l	42+4(a0),d1
	bne	notbox
	bra	plybox
notbox:	bsr	putobj
	move.l	mptr,a0
	move.l	(a0),a1
	move.l	(a1),d0
	bsr	copyhandle

	move.l	table,a1
	move.l	m_delete(a1),a1
	move.l	mptr,a0
	jmp	(a1)

plybox:
	move.b	#tbox,object+ob_Type
	bsr	putobj
	moveq	#0,d0
	bsr	oputw
	moveq	#0,d0
	bsr	oputw

	move.l	table,a1
	move.l	m_delete(a1),a1
	move.l	mptr,a0
	jmp	(a1)

plyline:
	move.b	#tdln,object+ob_Type
	move.l	mptr,a0
	move.l	(a0),a0
	lea	20(a0),a0
	move.l	2+0(a0),d0
	move.l	2+4(a0),d1
	move.l	12+0(a0),d2
	move.l	12+4(a0),d3
	add.l	object+ob_Left,d0
	add.l	object+ob_Top,d1
	add.l	object+ob_Left,d2
	add.l	object+ob_Top,d3
	move.l	d0,object+ob_Left
	move.l	d1,object+ob_Top
	move.l	d2,object+ob_Right
	move.l	d3,object+ob_Bottom

	bsr	putobj

	move.l	table,a1
	move.l	m_delete(a1),a1
	move.l	mptr,a0
	jmp	(a1)

*******************************************
***					***
*******************************************
circle:	bsr	coord		;center x,y
	move.l	d0,object+ob_Left
	move.l	d1,object+ob_Top
	move.l	d0,object+ob_Right
	move.l	d1,object+ob_Bottom
	bsr	delta		;radius
	sub.l	d0,object+ob_Left
	sub.l	d0,object+ob_Top
	add.l	d0,object+ob_Right
	add.l	d0,object+ob_Bottom
	move.b	#tcir,object+ob_Type
	bsr	settypes
	clr.w	object+ob_Slant
	clr.w	object+ob_Twist
	bsr	putobj
	move.w	#0,d0
	bsr	oputw
	move.w	#36000,d0
	bra	oputw


*******************************************
***					***
*******************************************
arc:	bsr	coord		;center x,y
	move.l	d0,object+ob_Left
	move.l	d1,object+ob_Top
	move.l	d0,object+ob_Right
	move.l	d1,object+ob_Bottom
	bsr	delta		;radius
	sub.l	d0,object+ob_Left
	sub.l	d0,object+ob_Top
	add.l	d0,object+ob_Right
	add.l	d0,object+ob_Bottom
	move.b	#tcir,object+ob_Type
	bsr	settypes
	clr.w	object+ob_Slant
	clr.w	object+ob_Twist
	bsr	putobj
	bsr	getangle
	bsr	oputw
	bsr	getangle
	bra	oputw

getangle:
	bsr	float		;start angle in radians
	move.w	#18000,d1
	jsr	Muls1632
	move.w	#3142,d2	;in degree
	jsr	Divs1648
getan1:	tst.l	d0
	bpl	getan2
	add.l	#36000,d0
	bra	getan1
getan2:	cmp.l	#36000,d0
	bcs	rrts
	sub.l	#36000,d0
	bra	getan2

*******************************************
***					***
*******************************************
text:	bsr	coord		;x,y text origin
	move.l	d0,object+ob_Left
	move.l	d1,object+ob_Top
	move.l	d0,object+ob_Right
	move.l	d1,object+ob_Bottom
	bsr	delta		;character width
	add.l	d0,object+ob_Right
	bsr	delta		;character height
	add.l	d0,object+ob_Bottom
	bsr	getangle	;rotation in radians
	move.w	d0,object+ob_Slant
	move.w	d0,object+ob_Twist
	clr.b	object+ob_LType
	move.w	#25,object+ob_LWidth
	clr.b	object+ob_FType
	move.b	#ttxt,object+ob_Type
	bsr	putobj

	lea	column,a0
	move.b	#1,cm_LCalc(a0)
	move.b	#1,cm_QCalc(a0)
	move.l	object+ob_Left,cm_Left(a0)
	move.l	object+ob_Top,cm_Top(a0)
	move.l	#$7fffff,cm_Right(a0)
	move.l	#$7fffff,cm_Bottom(a0)
	clr.w	cm_Flag(a0)

	move.l	#5000,cm_Font(a0)
	clr.l	cm_Attrb(a0)
	move.l	object+ob_Right,d0
	sub.l	object+ob_Left,d0
	move.l	d0,cm_XPoint(a0)
	move.l	object+ob_Bottom,d0
	sub.l	object+ob_Top,d0
	move.l	d0,cm_YPoint(a0)
	clr.w	cm_Spacing(a0)
	move.w	#$8000,cm_Lead(a0)
	clr.w	cm_BMod(a0)
	clr.w	cm_PIndent(a0)
	clr.w	cm_LIndent(a0)
	clr.w	cm_RIndent(a0)
	clr.b	cm_Tag(a0)
	clr.b	cm_Justify(a0)		;block left
	move.b	#9,cm_CFStyle(a0)
	move.b	object+ob_FColor,cm_CFColor(a0)
	move.b	#0,cm_CLStyle(a0)
	move.b	object+ob_LColor,cm_CLColor(a0)
	move.w	#100,cm_CLWidth(a0)
	clr.l	cm_Tabs(a0)

	lea	column,a0
	move.l	#cm_Sizeof,d0
	jsr	copypointer

	bsr	string
	lea	strng,a0
	moveq	#0,d0
txt1:	tst.b	(a0)+
	beq	txt2
	addq.l	#1,d0
	bra	txt1
txt2:	move.l	d0,-(sp)
	jsr	oputl
	move.l	(sp)+,d0
	addq.l	#1,d0
	bclr	#0,d0
	lea	strng,a0
	jsr	copypointer
	rts


*******************************************
***					***
*******************************************
dimension:
	bsr	coord		;x,y starting point
	bsr	coord		;x,y ending point
	bsr	delta		;character width
	bsr	delta		;character height
	rts


*******************************************
***					***
*******************************************
part:	tst.b	partflag	;can't have a part in a part definition
	bne	ofail

	bsr	string		;part name

	bsr	float
	move.l	d0,pxoffset
	bsr	float
	move.l	d0,pyoffset

	bsr	float		;x-scale
	move.w	d0,pxscale
	bsr	float		;y-scale
	move.w	d0,pyscale
	bsr	getangle	;part angle in radians
	move.w	d0,protate
	bsr	integer		;flags (unused)

	lea	partlist,a0
part1:	tst.l	(a0)
	beq	ofail		;no part found matching name
	move.l	(a0),a0
	move.l	a0,a3
	move.l	(a0),a0
	lea	22(a0),a1
	lea	strng,a2
part2:	cmp.b	(a1)+,(a2)+
	bne	part1
	tst.b	-1(a1)
	bne	part2

	move.w	4(a0),count
	move.l	6(a0),e_minx
	move.l	10(a0),e_miny
	move.l	14(a0),e_maxx
	move.l	18(a0),e_maxy

	move.l	pxoffset,d0
	sub.l	cxoff,d0
	add.l	e_minx,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648
	move.l	d0,pxoffset

	move.l	pyoffset,d0
	sub.l	cyoff,d0
	add.l	e_miny,d0
	neg.l	d0
	add.l	cheight,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648
	move.l	d0,pyoffset

	move.l	e_maxx,d0
	sub.l	e_minx,d0
	asr.l	#1,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648
	move.l	d0,e_ctrx

	move.l	e_maxy,d0
	sub.l	e_miny,d0
	asr.l	#1,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648
	move.l	d0,e_ctry

	move.w	protate,d0
	bsr	sincos
	move.w	d0,pcos
	move.w	d1,psin

	move.l	a3,curpart
	move.l	#122,curlength

	bra	part9
part3:	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	moveq	#ob_SizeOf/2-1,d7
	lea	object,a1
part4:	move.w	(a0)+,(a1)+
	dbf	d7,part4
	add.l	#ob_SizeOf,curlength


	move.w	protate,object+ob_Slant
	move.w	protate,object+ob_Twist

	move.l	object+ob_Left,d0
	sub.l	e_ctrx,d0
	move.w	pxscale,d1
	bsr	Muls1632
	move.w	#1000,d2
	bsr	Divs1648
	add.l	e_ctrx,d0
	move.l	d0,object+ob_Left

	move.l	object+ob_Top,d0
	sub.l	e_ctry,d0
	move.w	pyscale,d1
	bsr	Muls1632
	move.w	#1000,d2
	bsr	Divs1648
	add.l	e_ctry,d0
	move.l	d0,object+ob_Top

	move.l	object+ob_Right,d0
	sub.l	e_ctrx,d0
	move.w	pxscale,d1
	bsr	Muls1632
	move.w	#1000,d2
	bsr	Divs1648
	add.l	e_ctrx,d0
	move.l	d0,object+ob_Right

	move.l	object+ob_Bottom,d0
	sub.l	e_ctry,d0
	move.w	pyscale,d1
	bsr	Muls1632
	move.w	#1000,d2
	bsr	Divs1648
	add.l	e_ctry,d0
	move.l	d0,object+ob_Bottom

	move.l	object+ob_Left,d0
	add.l	object+ob_Right,d0
	asr.l	#1,d0
	sub.l	e_ctrx,d0
	move.l	d0,temp
	move.w	pcos,d1
	bsr	Muls1632
	move.w	d1,-(sp)
	move.l	d0,-(sp)

	move.l	object+ob_Top,d0
	add.l	object+ob_Bottom,d0
	asr.l	#1,d0
	sub.l	e_ctry,d0
	move.l	d0,temp+4
	move.w	psin,d1
	bsr	Muls1632
	add.l	(sp)+,d0
	move.w	(sp)+,d2
	addx.w	d2,d1
	lsl.l	#1,d0
	roxl.w	#1,d1
	move.w	d1,d0
	swap	d0
	sub.l	temp,d0
	move.l	d0,-(sp)


	move.l	temp,d0
	move.w	psin,d1
	bsr	Muls1632
	move.w	d1,-(sp)
	move.l	d0,-(sp)

	move.l	temp+4,d0
	move.w	pcos,d1
	bsr	Muls1632
	sub.l	(sp)+,d0
	move.w	(sp)+,d2
	subx.w	d2,d1
	lsl.l	#1,d0
	roxl.w	#1,d1
	move.w	d1,d0
	swap	d0
	sub.l	temp+4,d0
	move.l	d0,-(sp)

	move.l	object+ob_Left,d0
	move.l	object+ob_Top,d1
	move.l	object+ob_Right,d2
	move.l	object+ob_Bottom,d3
	add.l	(sp),d1
	add.l	(sp)+,d3
	add.l	(sp),d0
	add.l	(sp)+,d2
	add.l	pxoffset,d0
	add.l	pyoffset,d1
	add.l	pxoffset,d2
	add.l	pyoffset,d3
	move.l	d0,object+ob_Left
	move.l	d1,object+ob_Top
	move.l	d2,object+ob_Right
	move.l	d3,object+ob_Bottom

	moveq	#0,d0
	move.b	object+ob_Type,d0
	jsr	partobj(pc,d0.w)

part9:	subq.w	#1,count
	bcc	part3

	rts


partobj:
	bra.w	ofail
	bra.w	parttxt
	bra.w	parttxt
	bra.w	ofail
	bra.w	partply
	bra.w	partply
	bra.w	partbox
	bra.w	partbox
	bra.w	partln
	bra.w	partln
	bra.w	partcir
	bra.w	partcir
	bra.w	ofail


*******************************************
***					***
*******************************************
partply:
	bsr	putobj

* length,width,height,xscl,yscl,cnt
* newpath
*  moveto x,y
*  lineto x,y
* stroke

	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(a0)+,d0		;length
	move.l	(a0)+,d0		;width
	move.l	(a0)+,d0		;height
	moveq	#0,d0
	move.w	pxscale,d0
	divu	#10,d0
	move.w	d0,(a0)+		;xscl
	moveq	#0,d0
	move.w	pyscale,d0
	divu	#10,d0
	move.w	d0,(a0)+		;yscl
	move.w	(a0)+,d0		;count

	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(a0),d0

	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	ofail

	move.l	curpart,a1
	move.l	(a1),a1
	add.l	curlength,a1
	move.l	(a1),d0
	add.l	d0,curlength

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	pply2
pply1:	move.w	(a1)+,(a0)+
pply2:	dbf	d0,pply1
	dbf	d1,pply1

	rts

*******************************************
***					***
*******************************************
partcir:
	bsr	putobj

	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(a0),d0
	addq.l	#4,curlength
	bra	oputl


*******************************************
***					***
*******************************************
partbox:
	bsr	putobj

	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(a0),d0
	addq.l	#4,curlength
	bra	oputl


*******************************************
***					***
*******************************************
partln:
	bra	putobj


*******************************************
***					***
*******************************************
parttxt:
	bsr	putobj

	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	cm_Sizeof(a0),d0
	add.l	#cm_Sizeof+5,d0
	bclr	#0,d0

	move.l	d0,-(sp)
	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	ofail
	move.l	(sp)+,d0

	move.l	curpart,a1
	move.l	(a1),a1
	add.l	curlength,a1
	add.l	d0,curlength

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	ptxt2
ptxt1:	move.w	(a1)+,(a0)+
ptxt2:	dbf	d0,ptxt1
	dbf	d1,ptxt1

	rts



*******************************************
***					***
*******************************************
settypes:
	move.w	e_flags,d0
	btst	#0,d0
	bne	filled

	move.w	e_pattern,d0
	addq.w	#1,d0
	cmp.w	#6,d0
	bcs	setyp1
	moveq	#6,d0
setyp1:	move.b	d0,object+ob_LType
	move.w	e_weight,d0
	addq.w	#1,d0
	mulu	#50,d0
	move.w	d0,object+ob_LWidth		;5$ point line
	clr.b	object+ob_FType			;no fill
	rts

filled:
	lea	filltype,a0
	move.w	e_pattern,d0
	move.b	0(a0,d0.w),object+ob_FType
	move.b	#1,object+ob_LType
	move.w	#25,object+ob_LWidth
	rts

*******************************************
***					***
*******************************************
integer:
	clr.b	sign
	bsr	fget			;strip off leading non-digits
	beq	ofail
	cmp.b	#"-",d0
	beq	negint
	cmp.b	#"9",d0
	bhi	integer
	sub.b	#"0",d0
	bcs	integer
	moveq	#0,d1
	move.b	d0,d1
	moveq	#1,d4
	bra	int1

negint:	move.b	#1,sign
	moveq	#0,d1
	moveq	#0,d4
	bsr	int1
	neg.l	d0
	rts

int1:	move.l	d1,-(sp)
	jsr	fget
	beq	ofail
	move.b	d0,d3
	move.l	(sp)+,d1
	cmp.b	#"9",d0
	bhi	int2
	sub.b	#"0",d0
	bcs	int2
	addq.w	#1,d4
	move.l	d1,d2			;*10
	lsl.l	#2,d1
	add.l	d2,d1
	lsl.l	#1,d1
	and.l	#$ff,d0
	add.l	d0,d1
	bra	int1
int2:	move.l	d1,d0
	rts



coord:	bsr	float
	move.l	d0,-(sp)
	bsr	float
	move.l	d0,d1
	move.l	(sp)+,d0

sclcoord:
	move.l	d1,-(sp)

	sub.l	cxoff,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648

	move.l	(sp)+,d1
	move.l	d0,-(sp)
	move.l	d1,d0

	sub.l	cyoff,d0
	neg.l	d0
	add.l	cheight,d0
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bsr	Divs1648
	move.l	d0,d1
	move.l	(sp)+,d0
	rts

delta:	bsr	float
	move.w	#7200,d1
	bsr	Muls1632
	move.w	cscale,d2
	bra	Divs1648

float:	clr.l	finteger
	clr.l	fdecimal
	clr.l	fdplace
	clr.l	fexponent

	bsr	integer
	move.b	sign,sign1
	move.l	d0,finteger
	cmp.b	#".",d3
	bne	rtrnfloat
	bsr	integer
	move.l	d0,fdecimal
	move.l	d4,fdplace
	cmp.b	#"e",d3
	bne	rtrnfloat
	bsr	integer
	move.b	sign,sign2		;worthless
	move.l	d0,fexponent

rtrnfloat:
	move.l	finteger,d0
	move.l	fdplace,d2
	bra	rtft2
rtft1:	move.l	d0,d1			;*10
	asl.l	#2,d0
	add.l	d1,d0
	asl.l	#1,d0
rtft2:	dbf	d2,rtft1
	move.l	fdecimal,d1
	tst.b	sign1
	beq	rtft3
	neg.l	d1
rtft3:	add.l	d1,d0
	move.l	fexponent,d3
	sub.l	fdplace,d3
	addq.l	#3,d3
	tst.l	d3
	beq	rrts
	bmi	divft
	bra	rtft5
rtft4:	move.l	d0,d1			;*10
	asl.l	#2,d0
	add.l	d1,d0
	asl.l	#1,d0
rtft5:	dbf	d3,rtft4
	rts

divft:	neg.l	d3
	moveq	#1,d2
	bra	rtft9
rtft8:	move.l	d2,d1
	lsl.l	#2,d2
	add.l	d1,d2
	lsl.l	#1,d2
rtft9:	dbf	d3,rtft8
	moveq	#0,d1
	tst.l	d0
	bpl	rtft10
	move.l	#-1,d1
rtft10:	move.l	table,a0
	move.l	divs3248(a0),a0
	jmp	(a0)


string:
	bsr	fget
	beq	ofail
	cmp.b	#QUOTE,d0
	bne	string
	lea	strng,a0
str1:	move.l	a0,-(sp)
	bsr	fget
	beq	ofail
	cmp.b	#QUOTE,d0
	beq	str3
	cmp.b	#BACK,d0
	bne	str2
	bsr	fget
	beq	ofail
str2:	move.l	(sp)+,a0
	move.b	d0,(a0)+
	bra	str1
str3:	move.l	(sp)+,a0
	clr.b	(a0)
	lea	strng,a0
	rts


*******************************************
***					***
*******************************************
putobj:	tst.b	partflag
	bne	putobj1
	move.l	table,a1
	move.l	o_obj(a1),a1
	lea	object,a0
	jsr	(a1)
	beq	ofail
	rts

putobj1:
	move.l	curpart,a0
	move.l	#ob_SizeOf,d0
	move.l	table,a1
	move.l	m_grow(a1),a1
	jsr	(a1)
	beq	ofail

	move.l	curpart,a1
	move.l	(a1),a1
	addq.w	#1,4(a1)
	add.l	curlength,a1
	lea	object,a0
	moveq	#ob_SizeOf/2-1,d0
po1:	move.w	(a0)+,(a1)+
	dbf	d0,po1
	add.l	#ob_SizeOf,curlength
	rts

*******************************************
***					***
*******************************************
oputw:	tst.b	partflag
	bne	oputw1
	move.l	table,a0
	move.l	o_putw(a0),a0
	jsr	(a0)
	beq	ofail
	rts

oputw1:	move.w	d0,-(sp)
	move.l	curpart,a0
	move.l	#2,d0
	move.l	table,a1
	move.l	m_grow(a1),a1
	jsr	(a1)
	beq	ofail

	move.l	curpart,a1
	move.l	(a1),a1
	add.l	curlength,a1
	move.w	(sp)+,(a1)+
	add.l	#2,curlength
	rts


oputl:	tst.b	partflag
	bne	oputl1
	move.l	table,a0
	move.l	o_putl(a0),a0
	jsr	(a0)
	beq	ofail
	rts

oputl1:	move.l	d0,-(sp)
	move.l	curpart,a0
	move.l	#4,d0
	move.l	table,a1
	move.l	m_grow(a1),a1
	jsr	(a1)
	beq	ofail

	move.l	curpart,a1
	move.l	(a1),a1
	add.l	curlength,a1
	move.l	(sp)+,(a1)+
	add.l	#4,curlength
	rts

*******************************************
***					***
*******************************************
copyhandle:
	tst.b	partflag
	bne	copyh1

	move.l	a0,-(sp)
	move.l	d0,-(sp)

	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	ofail

	move.l	(sp)+,d0
	move.l	(sp)+,a1
	move.l	(a1),a1

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	cphdl2
cphdl1:	move.w	(a1)+,(a0)+
cphdl2:	dbf	d0,cphdl1
	dbf	d1,cphdl1
	rts

copyh1:	move.l	a0,-(sp)
	move.l	d0,-(sp)

	move.l	curpart,a0
	move.l	table,a1
	move.l	m_grow(a1),a1
	jsr	(a1)
	beq	ofail
	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(sp)+,d0
	add.l	d0,curlength
	move.l	(sp)+,a1
	move.l	(a1),a1

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	cphdl4
cphdl3:	move.w	(a1)+,(a0)+
cphdl4:	dbf	d0,cphdl3
	dbf	d1,cphdl3
	rts

*******************************************
***					***
*******************************************
copypointer:
	tst.b	partflag
	bne	copyp1

	move.l	a0,-(sp)
	move.l	d0,-(sp)

	move.l	table,a0
	move.l	o_malloc(a0),a0
	jsr	(a0)
	beq	ofail

	move.l	(sp)+,d0
	move.l	(sp)+,a1

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	cpptr2
cpptr1:	move.w	(a1)+,(a0)+
cpptr2:	dbf	d0,cpptr1
	dbf	d1,cpptr1
	rts

copyp1:	move.l	a0,-(sp)
	move.l	d0,-(sp)

	move.l	curpart,a0
	move.l	table,a1
	move.l	m_grow(a1),a1
	jsr	(a1)
	beq	ofail
	move.l	curpart,a0
	move.l	(a0),a0
	add.l	curlength,a0
	move.l	(sp)+,d0
	add.l	d0,curlength
	move.l	(sp)+,a1

	lsr.l	#1,d0
	move.l	d0,d1
	swap	d1
	bra	cpptr4
cpptr3:	move.w	(a1)+,(a0)+
cpptr4:	dbf	d0,cpptr3
	dbf	d1,cpptr3
	rts

*******************************************
***					***
*******************************************
fget:	move.l	table,a0
	move.l	f_get(a0),a0
	jmp	(a0)


Mulu1632:
	move.l	table,a0
	move.l	mulu1632(a0),a0
	jmp	(a0)

Divu1648:
	move.l	table,a0
	move.l	divu1648(a0),a0
	jmp	(a0)

Muls1632:
	move.l	table,a0
	move.l	muls1632(a0),a0
	jmp	(a0)

Divs1648:
	move.l	table,a0
	move.l	divs1648(a0),a0
	jmp	(a0)


sincos:	and.l	#$ffff,d0
	divu	#100,d0
	move.w	d0,-(sp)
	bsr	getang
	move.w	d0,d1
	move.w	(sp)+,d0
	add.w	#90,d0		;cos(ang) = sin (ang+90)

* and fall into getang

getang:	cmp.w	#360,d0
	bcs	geta1
	sub.w	#360,d0
	bra	getang
geta1:	moveq	#0,d2			;is it negative?
	cmp.w	#180,d0
	bcs	geta2
	sub.w	#180,d0
	moveq	#1,d2			;set negate bit
geta2:	cmp.w	#90,d0
	bcs	geta3
	sub.w	#180,d0
	neg.w	d0
geta3:	lsl.w	#1,d0
	lea	sintbl,a0
	move.w	0(a0,d0.w),d0
	tst.b	d2
	beq	rrts
	neg.w	d0
	rts

sintbl:
	dc.w	0,571,1143,1714,2285
	dc.w	2855,3425,3993,4560,5126
	dc.w	5690,6252,6812,7371,7927
	dc.w	8480,9032,9580,10125,10688
	dc.w	11207,11743,12275,12803,13327
	dc.w	13848,14364,14876,15383,15886
	dc.w	16383,16876,17364,17846,18323
	dc.w	18794,19260,19720,20173,20621
	dc.w	21062,21497,21926,22347,22762
	dc.w	23170,23571,23964,24351,24730
	dc.w	25101,25465,25821,26169,26509
	dc.w	26841,27165,27481,27788,28087
	dc.w	28377,28659,28932,29196,29451
	dc.w	29697,29935,30163,30381,30591
	dc.w	30791,30982,31164,31336,31498
	dc.w	31651,31794,31928,32051,32165
	dc.w	32270,32364,32449,32523,32588
	dc.w	32643,32688,32723,32748,32763
	dc.w	32767

*******************************************************************
***	called when the import routine choosen finds something	***
***	wrong with the file loaded.				***
*******************************************************************
notright:
	rts

never:	moveq	#0,d0
	rts

maybe:	moveq	#1,d0
	rts

right:	moveq	#2,d0
	rts

*************************************************************
*************************************************************
 SECTION aegis,DATA,PUBLIC


special:
	dc.w	1
	dc.l	spcl1

spcl1:	dc.b	"Object",0
name:	dc.b	"AegisDraw  v2.1.1",0

clrnm0:	dc.b	"AegisDraw#0",0
clrnm1:	dc.b	"AegisDraw#1",0
clrnm:	dc.b	"AegisDraw#",0

filltype:	dc.b	9,30,29,31,26,26,28,31

 SECTION aegis,BSS,PUBLIC

finteger:	ds.l	1
fdecimal:	ds.l	1
fdplace:	ds.l	1
fexponent:	ds.l	1

partlist:	ds.l	1
curpart:	ds.l	1
curlength:	ds.l	1

cxoff:		ds.l	1
cyoff:		ds.l	1
cwidth:		ds.l	1
cheight:	ds.l	1
cscale:		ds.w	1
dxoff:		ds.l	1
dyoff:		ds.l	1
dwidth:		ds.l	1
dheight:	ds.l	1
dscale:		ds.w	1
pxoffset:	ds.l	1
pyoffset:	ds.l	1
pxscale:	ds.w	1
pyscale:	ds.w	1
protate:	ds.w	1
pcos:		ds.w	1
psin:		ds.w	1
e_id:		ds.w	1
e_size:		ds.w	1
e_minx:		ds.l	1
e_miny:		ds.l	1
e_maxx:		ds.l	1
e_maxy:		ds.l	1
e_ctrx:		ds.l	1
e_ctry:		ds.l	1
e_color:	ds.w	1
e_layer:	ds.w	1
e_pattern:	ds.w	1
e_weight:	ds.w	1
e_flags:	ds.w	1

object:		ds.w	ob_SizeOf/2
column:		ds.w	cm_Sizeof/2
color:		ds.w	cl_Sizeof/2

strng:		ds.b	100
mptr:		ds.l	1
moff:		ds.l	1
count:		ds.w	1
savesp:		ds.l	1
partflag:	ds.b	1
sign:		ds.b	1
sign1:		ds.b	1
sign2:		ds.b	1
temp:		ds.l	2
colormap:	ds.w	32
