timer:
	bsr	gosup
	move.l	$4ba,started
	move.L	#100000,d0
tl:
	move.l	d0,-(sp)
	bsr	start
	move.l	(sp)+,d0
	subq.l	#1,d0
	bpl	tl

	move.l	$4ba,d0
	sub.l	started,d0
	moveq	#10,d1
	moveq	#0,d2
	moveq	#0,d3
	bsr	prtnum
	move.w	#1,-(sp)
	trap	#1
	addq.l	#2,sp
	bsr	gouser
	bra	stop


*****************************************
*	number in d0.l			*
*	d1.l is base			*
*	d2,x cursor			*
*	d3,y cursor			*
*****************************************
prtnum:
	movem.l	d0/d1,-(sp)
	lea	posstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
	move.b	d3,10(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
	move.b	d2,11(a0)	
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d0/d1

	lea	linebuffer,a0
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
loop1:
	divu	d1,d0
	swap	d0
	addi	#'0',d0
	cmpi.w	#'9',d0
	ble.s	ok
	addq.w	#7,d0
ok:
	move.b	d0,-(a0)
	clr	d0
	swap	d0
	bne	loop1
loop2:
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts

linebuffer:
	ds.l	5
digits:
	dc.b	0
posstring:	dc.b	27,'Y',0,0,' ',' ',' ',' ',27,'Y',0,0,0
	even


gosup:
	clr.l	-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp
	move.l	d0,savesp
	rts
gouser:
	move.l	savesp,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp
	rts

savesp:	dc.l	0
started:	dc.l	0




start:
	lea	source,a1
	lea	destination,a0
	move.w	#2,d4		;bf width for set = magnification
	moveq	#0,d5		;offset destination
	moveq	#0,d6		;height of source
	move.w	#15,a2		;counter for 15 shifts
	move.w	#15,a3
	movem.l	d4-d6/a0-a3,-(sp)

	move.w	(a1)+,d0
	move.w	(a1)+,d1
	move.w	(a1)+,d2
	move.w	(a1)+,d3
magloop1:
	move.w	a3,d7		;number of bits to test=width of source
magloop2:
p0test:
	lsl.w	#1,d0
	bcc.s	p0clear			;bit was 0 so go clear in dest
	dc.w	%1110111011010000	;bfset	a0{d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	bra.s	p1test
p0clear:
*	dc.w	%1110110011010000	;bfclr	a1{d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
p1test:
	lsl.w	#1,d1
	bcc.s	p1clear			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	2(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	2
	bra.s	p2test
p1clear:
*	dc.w	%1110110011101000	;bfclr	2(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	2
p2test:
	lsl.w	#1,d2
	bcc.s	p2clear			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	4(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	4
	bra.s	p3test
p2clear:
*	dc.w	%1110110011101000	;bfclr	4(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	4
p3test:
	lsl.w	#1,d3
	bcc.s	p3clear			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	6(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	6
	bra.s	bot4done
p3clear:
*	dc.w	%1110110011101000	;bfclr	6(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	6

bot4done:					;All planes done
	sub.w	#1,a2		;count shifts
	cmp.w	#-1,a2
	bne.s	offok
	move.w	#15,a2
	addq.l	#8,a1
	move.w	(a1)+,d0
	move.w	(a1)+,d1
	move.w	(a1)+,d2
	move.w	(a1)+,d3
offok:
	add.w	d4,d5		;advance destination by magnification
	andi.w	#15,d5
	bne	offok2
	lea	16(a0),a0
offok2:
	dbf	d7,magloop2
	dbf	d6,magloop1

	movem.l	(sp)+,d4-d6/a0-a3
	addq.l	#8,a0
	addq.l	#8,a1
	move.w	(a1)+,d0
	move.w	(a1)+,d1
	move.w	(a1)+,d2
	move.w	(a1)+,d3

magloop1b:
	move.w	a3,d7		;number of bits to test=width of source
magloop2b:
p0testb:
	lsl.w	#1,d0
	bcc.s	p0clearb			;bit was 0 so go clear in dest
	dc.w	%1110111011010000	;bfset	a0{d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	bra.s	p1testb
p0clearb:
*	dc.w	%1110110011010000	;bfclr	a1{d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
p1testb:
	lsl.w	#1,d1
	bcc.s	p1clearb			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	2(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	2
	bra.s	p2testb
p1clearb:
*	dc.w	%1110110011101000	;bfclr	2(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	2
p2testb:
	lsl.w	#1,d2
	bcc.s	p2clearb			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	4(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	4
	bra.s	p3testb
p2clearb:
*	dc.w	%1110110011101000	;bfclr	4(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	4
p3testb:
	lsl.w	#1,d3
	bcc.s	p3clearb			;bit was 0 so go clear in dest
	dc.w	%1110111011101000	;bfset	6(a0){d5:d4}
	dc.w	%0000100101100100	;set dest with proper width
	dc.w	6
	bra.s	bot4doneb
p3clearb:
*	dc.w	%1110110011101000	;bfclr	6(a0){d5:d4}
*	dc.w	%0000100101100100	;set dest with proper width
*	dc.w	6

bot4doneb:					;All planes done
	sub.w	#1,a2		;count shifts
	cmp.w	#-1,a2
	bne.s	offokb
	move.w	#15,a2
	addq.l	#8,a1
	move.w	(a1)+,d0
	move.w	(a1)+,d1
	move.w	(a1)+,d2
	move.w	(a1)+,d3
offokb:
	add.w	d4,d5		;advance destination by magnification
	andi.w	#15,d5
	bne	offok2b
	lea	16(a0),a0
offok2b:
	dbf	d7,magloop2b
	dbf	d6,magloop1b
	RTS




stop:
	nop
	nop

	clr.w	-(sp)
	trap	#1




source:
	dc.w	%1000000000000001
	dc.w	%1100000000000000
	dc.w	%1110000000000001
	dc.w	%1111000000000000
	dc.w	%1111100000000001
	dc.w	%1111110000000000
	dc.w	%1111111000000001
	dc.w	%1111111100000000



destination:
	ds.w	16
	DC.W	-1