*** new WritePixelLine8 (c) 1995 by Pawel Hernik, Günther Röhrich and others ***

	include "graphics/rastport.i"
	XREF _GfxBase
	XREF _linebuf
	XREF _WPBitMap
	XREF _WPPlane
   
        
	XDEF _newWPL8Pos

	cseg



_newWPL8Pos:
	movem.l	d0-a6,-(sp)
	sub.w	#16,sp
	move.l	a2,a0			;chunky
	
	move.l	rp_BitMap(a1),a1
	move.l	_WPBitMap,a2
*	move.b	bm_Depth(a1),bm_Depth(a2)

	move.l	_linebuf,a1
	move.l	a1,a2
	move.l	2*4+16(sp),d0
	add.w	#$1f,d0
	and.w	#~$1f,d0
	add.w	d0,a2
	move.l	#$00ff00ff,a3
	move.l	#$0f0f0f0f,a4
	
.sweep1st:
	movem.l (a0),d0-d7
	move.l  d4,a6
	move.w  d0,d4
	swap    d4   
	move.w  d4,d0
	move.w  a6,d4
	move.l  d5,a6
	move.w  d1,d5
	swap    d5   
	move.w  d5,d1
	move.w  a6,d5
	move.l  d6,a6
	move.w  d2,d6
	swap    d6   
	move.w  d6,d2
	move.w  a6,d6
	move.l  d7,a6
	move.w  d3,d7
	swap    d7   
	move.w  d7,d3
	move.w  a6,d7
	move.l  d7,a6
	move.l  d6,a5
	move.l  a3,d6
	move.l  a3,d7
	and.l   d0,d6
	and.l   d2,d7
	eor.l   d6,d0
	eor.l   d7,d2
	lsl.l   #8,d6
	lsr.l   #8,d2
	or.l    d2,d0
	or.l    d7,d6
	move.l  a3,d7
	move.l  a3,d2
	and.l   d1,d7
	and.l   d3,d2
	eor.l   d7,d1
	eor.l   d2,d3
	lsl.l   #8,d7
	lsr.l   #8,d3
	or.l    d3,d1
	or.l    d2,d7

	move.l  a4,d2
	move.l  a4,d3
	and.l   d0,d2
	and.l   d1,d3
	eor.l   d2,d0
	eor.l   d3,d1
	lsr.l   #4,d1
	or.l    d1,d0
	move.l  d0,(a1)+
	lsl.l	#4,d2
	or.l    d3,d2
	move.l	d2,(a1)+

	move.l  a4,d3
	move.l  a4,d1
	and.l   d6,d3
	and.l   d7,d1
	eor.l   d3,d6
	eor.l   d1,d7
	lsr.l   #4,d7
	or.l    d7,d6
	move.l	d6,(a1)+
	lsl.l	#4,d3
	or.l    d1,d3
	move.l	d3,(a1)+

	move.l  a6,d7
	move.l  a5,d6
	move.l  a3,d0
	move.l  a3,d1
	and.l   d4,d0
	and.l   d6,d1
	eor.l   d0,d4
	eor.l   d1,d6
	lsl.l   #8,d0
	lsr.l   #8,d6
	or.l    d6,d4
	or.l    d1,d0
	move.l  a3,d1
	move.l  a3,d6
	and.l   d5,d1
	and.l   d7,d6
	eor.l   d1,d5
	eor.l   d6,d7
	lsl.l   #8,d1
	lsr.l   #8,d7
	or.l    d7,d5
	or.l    d6,d1
	move.l  a4,d6
	move.l  a4,d7
	and.l   d4,d6
	and.l   d5,d7
	eor.l   d6,d4
	eor.l   d7,d5
	lsr.l   #4,d5
	or.l    d5,d4
	move.l  d4,(a1)+
	lsl.l   #4,d6
	or.l    d7,d6
	move.l  d6,(a1)+

	move.l  a4,d7
	move.l  a4,d5
	and.l   d0,d7
	and.l   d1,d5
	eor.l   d7,d0
	eor.l	d5,d1
	lsr.l	#4,d1
	or.l	d1,d0
	move.l	d0,(a1)+
	lsl.l	#4,d7
	or.l	d5,d7
	move.l	d7,(a1)+
	add.w	#32,a0
	cmp.l	a2,a1
	bne	.sweep1st

	move.l	_linebuf,a0
	move.l	_WPPlane,a1
	move.l  #$33333333,a5
	move.l  #$55555555,a6

.sweep2nd:
	move.l	(a0),d0
	move.l	8(a0),d1
	move.l	16(a0),d2
	move.l	24(a0),d3

	move.l	a5,d6
	move.l	a5,d7
	and.l	d0,d6
	and.l	d2,d7
	eor.l	d6,d0
	eor.l	d7,d2
	lsl.l	#2,d6
	lsr.l	#2,d2
	or.l	d2,d0
	or.l	d7,d6
	move.l	a5,d7
	move.l	a5,d2
	and.l	d1,d7
	and.l	d3,d2
	eor.l	d7,d1
	eor.l	d2,d3
	lsl.l	#2,d7
	lsr.l	#2,d3
	or.l	d3,d1
	or.l	d2,d7
	move.l	a6,d2
	move.l	a6,d3
	and.l	d0,d2
	and.l	d1,d3
	eor.l	d2,d0
	eor.l	d3,d1
	lsr.l	#1,d1
	or.l	d1,d0
	move.l	d0,256*7(a1)
	add.l	d2,d2
	or.l	d3,d2
	move.l	d2,256*6(a1)

	move.l	a6,d3
	move.l	a6,d1
	and.l	d6,d3
	and.l	d7,d1
	eor.l	d3,d6
	eor.l	d1,d7
	lsr.l	#1,d7
	or.l	d7,d6
	move.l	d6,256*5(a1)
	add.l	d3,d3
	or.l	d1,d3
	move.l	d3,256*4(a1)

	move.l	4(a0),d0
	move.l	12(a0),d1
	move.l	20(a0),d2
	move.l	28(a0),d3

	move.l	a5,d6
	move.l	a5,d7
	and.l	d0,d6
	and.l	d2,d7
	eor.l	d6,d0
	eor.l	d7,d2
	lsl.l	#2,d6
	lsr.l	#2,d2
	or.l	d2,d0
	or.l	d7,d6
	move.l	a5,d7
	move.l	a5,d2
	and.l	d1,d7
	and.l	d3,d2
	eor.l	d7,d1
	eor.l	d2,d3
	lsl.l	#2,d7
	lsr.l	#2,d3
	or.l	d3,d1
	or.l	d2,d7
	move.l	a6,d2
	move.l	a6,d3
	and.l	d0,d2
	and.l	d1,d3
	eor.l	d2,d0
	eor.l	d3,d1
	lsr.l	#1,d1
	or.l	d1,d0
	move.l	d0,256*3(a1)
	add.l	d2,d2
	or.l	d3,d2
	move.l	d2,256*2(a1)
	
	move.l	a6,d3
	move.l	a6,d1
	and.l	d6,d3
	and.l	d7,d1
	eor.l	d3,d6
	eor.l	d1,d7
	lsr.l	#1,d7
	or.l	d7,d6
	move.l	d6,256*1(a1)
	add.l	d3,d3
	or.l	d1,d3
	move.l	d3,(a1)+

	add.w	#32,a0
	cmp.l	a2,a0
	bne	.sweep2nd

	move.l	_WPBitMap,a0	;src bm (_mybitmap)
	move.l	8*4+16(sp),a1		;screen rp (rp=a0)
	moveq	#0,d0
	moveq	#0,d1
	move.l	2*4+16(sp),d4		;size x (d2)
	moveq	#1,d5			;size y
	move.l	0*4+16(sp),d2		;dest x (d0)
	move.l	1*4+16(sp),d3		;dest y (d1)
	move.b	#$c0,d6
	move.l  _GfxBase,a6
	jsr	-$25e(a6)   ;BltBitMapRastPort

	add.w	#16,sp
	movem.l	(sp)+,d0-a6
	move.l	d2,d0
	rts



wd		=0
wd16		=2
htm1		=4
row		=6
chunkytmp	=8
ret		=12
;^ 16 bytes on stack

;wd:		dc.w	0
;wd16:		dc.w	0
;htm1:		dc.w	0
;row:		dc.w	0
;chunkytmp:	dc.l	0	;tmp address
;ret:		dc.l	0
