



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





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