osize:		equ	100
maxstretch:	equ	300	;don't forget the table set

*****************************************************************
*	Calculate a huge table full of strecthing values	*
*	Osize should be set to the original size of the object.	*
*	Maxstretch is the widest (or highest) osize will be	*
*	stretched across.					*
*****************************************************************
start:
	move.l	4(a7),a3		base page
	move.l	#mystack,a7
	move.l	$c(a3),d0		text len
	add.l	$14(a3),d0		data len
	add.l	$1c(a3),d0		BSS len
	add.l	#$100,d0		basepage
	move.l	d0,-(sp)
	move.l	a3,-(sp)
	clr.w	-(sp)
	move.w	#$4a,-(sp)
	trap	#1			shrink memory
	lea	12(sp),sp


	pea	fseltitle
	pea	fselsp			;get the PNT file
	jsr	_fileselector
	add.l	#8,sp
	cmpi.l	#1,d0
	bne	exit




stretchcalc:
	lea	array,a0
	move.w	#maxstretch-1,d7
	moveq	#1,d3
scl:
	bsr	dx2		;calc table
	addq.l	#1,d3
	dbf	d7,scl


	jsr	_openfile		;open the file
	pea	array
	move.l	#arrayend,d0
	sub.l	#array,d0
	move.l	d0,-(sp)
	jsr	_writetofile		;write it out
	add.l	#8,sp
	jsr	_closefile

	lea	_myfp,a0
.loop:
	tst.b	(a0)+
	bne	.loop
	subq.l	#4,a0
	move.b	#'O',(a0)+
	move.b	#'F',(a0)+
	move.b	#'F',(a0)+
	moveq	#0,d0

	jsr	_openfile		;open the file
	pea	stablestarts
	move.l	#tableend,d0
	sub.l	#stablestarts,d0
	move.l	d0,-(sp)
	jsr	_writetofile		;write it out
	add.l	#8,sp
	jsr	_closefile

exit:
	clr.w	-(sp)
	trap	#1

	include	'file.s'

fseltitle:	dc.b	'name the stretch table',0
fselsp:		dc.b	'TAB',0
	even
*********************************************************
*	Routine to calculate stretchy stuff		*
*	Pass x width in d3				*
*	block address in d0
*	array to fill in a0				*
*********************************************************
dx2:
	movem.l	d0-d7/a1-a6,-(sp)
	move	#osize,d2
	moveq	#0,d7
	move.w 	d3,d0		;dy
	subq.w	#1,d0
	moveq	#0,d5
lineloopdx2:
	move.w 	d7,(a0)+
	add.w 	d2,d5
testdx2:
	cmp.w 	d3,d5
	blt.s 	noacrossdx2
	sub.w 	d3,d5
	addq.w	#1,d7
	bra.s 	testdx2
noacrossdx2:
	dbra 	d0,lineloopdx2
*	move.w	#-1,-2(a0)
nolinedx2:
	movem.l	(sp)+,d0-d7/a1-a6
	rts

		ds.l	1000
mystack:	ds.l	1

*****************************************************************
*	This builds a lookup table for the stretch array	*
*	base on factorial (I think!)				*
*****************************************************************
stablestarts:
n	set	1
	rept	300
	dc.l	((n+(n*n))/2)*2		;for words
n	set	n+1
	endr
tableend:

array:		ds.w	(maxstretch+(maxstretch*maxstretch))/2
arrayend:

