	XREF _HSTDATA,_HSTADR

	MACHINE 68020
	SECTION "CODE",CODE
 MACRO WRITES
	;nop
	swap	\1
	rol.w	#8,\1
	move.w	\1,(a6)		; write one word of data byteswapped
	;nop
	swap	\1
	rol.w	#8,\1
	move.w	\1,(a6)		; write one word of data byteswapped
	ENDM
	
; void hst2gsp32(	register __a0 	ubyte *hstadr,
;			register __d0 	ulong gspadr,
;			register __d6 	ushort width)
; 	transfers length Bytes from host to gsp with byteswap (one scan-line max)
;	width multiple of 32 required !

	XDEF	_hst2gsp32

_hst2gsp32:
	movem.l	d0-d6/a0/a3-a4/a6,-(sp)
	movea.l	_HSTDATA,a6			; DataRegister in a6
	ori.w	#$8800,2(a6)		; set (INCW /*| HLT*/) in CONTROL ( 6(A2) = HSTCTRL )
	
	lsr.w	#5,d6		; width is now 32-byte blocks aligned
	subq.w	#1,d6		; adjust for xloop
	
	swap	d0			; gspaddress endian swap
	move.l	d0,-4(a6)	; write the gspaddress (-4:HSTDATA)
		
.xmainloop:
	movem.l	(a0)+,d0-d5/a3-a4	; get 8 * 4 = 32 Pixels (Bytes) from hostmem
	WRITES	d0
	WRITES	d1
	WRITES	d2
	WRITES	d3
	WRITES	d4
	WRITES	d5
	move.l	a3,d3		; restore
	WRITES	d3
	move.l	a4,d4		; restore
	WRITES	d4
	dbf	d6,.xmainloop	; any more 32 byte blocks ?
	
	andi.w	#$67ff,2(a6)	; start gsp, no INCR/INCW
	movem.l	(sp)+,d0-d6/a0/a3-a4/a6
	rts

