;WritePlanarRGB(RGBArray *values, PLANEPTR *planearray, WORD bytes)
;				a0					a1					d2


			xdef		_WritePlanarRGB

SREGS		reg			d2/d3/d4/a2/a3/a4

_WritePlanarRGB:
			movem.l		SREGS,-(sp)

			moveq		#0,d1						; index into output planes

			move.l		d2,d3						; d3 <== bytes per row
			bra.s		70$
40$

; load up 24 bits of data each register

; first triplet
			move.b		2(a0),d4					; load up blue byte
			swap		d4							; put in byte 2
			move.b		1(a0),d4					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		0(a0),d4					; load up red byte in byte 0
; second triplet
			move.b		5(a0),d5					; load up blue byte
			swap		d4							; put in byte 2
			move.b		4(a0),d5					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		3(a0),d5					; load up red byte in byte 0
; third triplet
			move.b		8(a0),d6					; load up blue byte
			swap		d4							; put in byte 2
			move.b		7(a0),d6					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		6(a0),d6					; load up red byte in byte 0
; fourth triplet
			move.b		11(a0),d7					; load up blue byte
			swap		d4							; put in byte 2
			move.b		10(a0),d7					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		9(a0),d7					; load up red byte in byte 0

			lea			12(a0),a0					; after we're done, do next 4 trips

			move.l		a1,a4						; a4 <== start of Plane pointers
			moveq		#23,d2						; now, loop 24 times

50$			moveq		#0,d0						; clear out d0

			lsr.l		#1,d4						; 1st pixel
			addx.b		d0,d0
			lsr.l		#1,d5						; 2nd pixel
			addx.b		d0,d0
			lsr.l		#1,d6						; 3rd pixel
			addx.b		d0,d0
			lsr.l		#1,d7						; 4th pixel
			addx.b		d0,d0

			lsl.w		#4,d0						; put in upper half

			move.l		(a4)+,a2					; a2 <== next bitplane pointer
			move.b		d0,(a2,d1.l)				; d0 <== next pixel data word

			dbra		d2,50$						; loop to next plane

; load up 24 bits of data each register (again)

; first triplet
			move.b		2(a0),d4					; load up blue byte
			swap		d4							; put in byte 2
			move.b		1(a0),d4					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		0(a0),d4					; load up red byte in byte 0
; second triplet
			move.b		5(a0),d5					; load up blue byte
			swap		d4							; put in byte 2
			move.b		4(a0),d5					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		3(a0),d5					; load up red byte in byte 0
; third triplet
			move.b		8(a0),d6					; load up blue byte
			swap		d4							; put in byte 2
			move.b		7(a0),d6					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		6(a0),d6					; load up red byte in byte 0
; fourth triplet
			move.b		11(a0),d7					; load up blue byte
			swap		d4							; put in byte 2
			move.b		10(a0),d7					; load up green byte
			lsl.w		#8,d4						; put in byte 1
			move.b		9(a0),d7					; load up red byte in byte 0

			lea			12(a0),a0					; after we're done, do next 4 trips

			move.l		a1,a4						; a4 <== start of Plane pointers
			moveq		#23,d2						; now, loop 24 times

60$			moveq		#0,d0						; clear out d0

			lsr.l		#1,d4						; 1st pixel
			addx.b		d0,d0
			lsr.l		#1,d5						; 2nd pixel
			addx.b		d0,d0
			lsr.l		#1,d6						; 3rd pixel
			addx.b		d0,d0
			lsr.l		#1,d7						; 4th pixel
			addx.b		d0,d0

			lsl.w		#4,d0						; put in upper half

			move.l		(a4)+,a2					; a2 <== next bitplane pointer
			or.b		d0,(a2,d1.l)				; d0 <== next pixel data word

			dbra		d2,60$						; loop to next plane

			addq		#1,d1						; next byte
70$			dbra		d3,40$						; loop to next word

			movem.l		(sp)+,SREGS
			rts

			end
