*-------------------------------------------------------*
*	Draw in 16 bit true colour mode			*	
*-------------------------------------------------------*
both		equ	1	; Write in both FastRAM and on screen
longs		equ	1
get		equ	1
mul		equ	1	; Multiply rather than use table
shift		equ	1

	include		"pixelmac.dev"
	include		"..\vdi.inc"

	xdef		write_pixel
	xdef		read_pixel

	ifeq		shift
	xref		dot,lline,rline
	endc
	ifeq		mul
	xref		row
	endc


*----------
* Set pixel
*----------
* In:	a1	VDI struct, destination MFDB
*	d0	colour
*	d1	x
*	d2	y
* XXX:	d0-d3/d5/d7/a0-a1
write_pixel:
	move.l		d0,d3
	move.l		4(a1),d0
	beq		.normal

	move.l		d0,a0
	move.l		mfdb_address(a0),d0
	beq		.normal
	move.w		mfdb_wdwidth(a0),d5
	move.w		mfdb_bitplanes(a0),d7
	move.l		(a1),a1
	move.l		vwk_real_address(a1),a1
	move.l		wk_screen_mfdb_address(a1),a0
	cmp.l		a0,d0
	beq		.xnormal

	move.l		d0,a0
	add.w		d5,d5
	mulu.w		d7,d5
	mulu.w		d5,d2
	add.l		d2,a0

.no_shadow:
	add.w		d1,d1
	add.w		d1,a0
	move.w		d3,(a0)

	rts

* Write to normal screen, which means
* that a shadow buffer may be involved	
.normal:
	move.l		(a1),a1
	move.l		vwk_real_address(a1),a1

	ifne	mul
	move.l		wk_screen_mfdb_address(a1),a0
	endc

.xnormal:
	ifne	mul
	move.w		wk_screen_wrap(a1),d5
	mulu.w		d5,d2
	add.l		d2,a0
	endc
	ifeq	mul
	lea		row(pc),a0
	move.l		(a0,d2.w*4),a0
	endc

	ifne	both
	move.l		wk_screen_shadow_address(a1),d7
	beq		.no_shadow	; No shadow buffer available
	move.l		d7,a4
	add.l		d2,a4
	endc

	add.w		d1,d1
	add.w		d1,a0
	ifne	both
	add.w		d1,a4
	endc

	ifeq	both
	move.w		d3,(a0)
	endc
	ifne	both
	move.w		d3,(a4)
	move.w		d3,(a0)
	endc

	rts



*----------
* Get pixel
*----------
* In:	a1	VDI struct, source MFDB
*	d1	x
*	d2	y
* Out:	d0	colour
* XXX:	d1-d2/d5/d7/a0-a1
read_pixel:
	move.l		4(a1),d0
	beq		.normal

	move.l		d0,a0
	move.l		mfdb_address(a0),d0
	beq		.normal
	move.w		mfdb_wdwidth(a0),d5
	move.w		mfdb_bitplanes(a0),d7
	move.l		(a1),a1
	move.l		vwk_real_address(a1),a1
	move.l		wk_screen_mfdb_address(a1),a0
	cmp.l		a0,d0
	beq		.xnormal

	move.l		d0,a0
	add.w		d5,d5
	mulu.w		d7,d5
	mulu.w		d5,d2
	add.l		d2,a0

.no_shadow:
	add.w		d1,d1
	add.w		d1,a0
	move.w		(a0),d0

	rts

* Read from normal screen, which means
* that a shadow buffer may be involved	
.normal:
	move.l		(a1),a1
	move.l		vwk_real_address(a1),a1

	ifne	mul
	move.l		wk_screen_mfdb_address(a1),a0
	endc

.xnormal:
	ifne	mul
	move.w		wk_screen_wrap(a1),d5
	mulu.w		d5,d2
	add.l		d2,a0
	endc
	ifeq	mul
	lea		row(pc),a0
	move.l		(a0,d2.w*4),a0
	endc

	ifne	both
	move.l		wk_screen_shadow_address(a1),d7
	beq		.no_shadow	; No shadow buffer available
	move.l		d7,a4
	add.l		d2,a4
	endc

	add.w		d1,d1
	add.w		d1,a0
	ifne	both
	add.w		d1,a4
	endc

	ifeq	both
	move.w		(a0),d0
	endc
	ifne	both
	move.w		(a4),d0
	endc

	rts


	end
