*******************************************************************************
* simple triple buffering example
*******************************************************************************
* INFO	shows how to work with a FullRes triple buffered display
* NOTE	- experiment with the display definition parameters
*	- LMB to exit anytime
*******************************************************************************

	machine	68020

	include	INCLUDES:libraries/tcs.i
	include	INCLUDES:libraries/tcs_lib.i



*******************************************************************************
* custom display definitions
*******************************************************************************

DSPLWD	=	320	;our TCS display width and
DSPLHT	=	256	;height in 140 ns pixels
SCRWD	=	320	;TCS screen width and
SCRHT	=	256	;height in pixels
DSPLX0	=	$81*4	;display start
DSPLY0	=	$2c	;position (SHRES pixels)
DSPLX1	=	DSPLX0+DSPLWD*4	;display end
DSPLY1	=	DSPLY0+DSPLHT	;position (SHRES pixels)
DSPLBRTNS	=	256	;max brightness
GFXCTXT	=	0
CWBTM	=	0
CWTOP	=	0
CWRT	=	0
CWLF	=	0
VDOMODE	set	TCS_VM_RGBW | TCS_VMf_FullRes ;TCS display video mode
VDOMODE	set	VDOMODE | TCS_VMf_TriBuf



*******************************************************************************
* code start
*******************************************************************************

	include	/includes/shl_strtup.i



*******************************************************************************
* init
*******************************************************************************

_PrgInit	move.w	#0,ccr	;OK!
	rts



*******************************************************************************
* main
*******************************************************************************

_PrgMain	move.l	#TriBufHndlr,([_VBR.l],$6c.w) ;set level3 autovector
	move.w	#$c020,$dff09a	;set INTENA.VERTB

.lp	movea.l	DIAdr,a0	;our display
	moveq.l	#0,d0	;x0
	moveq.l	#0,d1	;y0
	move.w	#SCRWD-1,d2	;x1
	move.w	#SCRHT-1,d3	;y1
	move.b	#255,d4	;color
	CALLTCS	DrwFrm0	;mark screen with a rectangle

	movea.l	DIAdr,a0	;render FullRes screen
	CALLTCS	CPUFRPass0	;to make changes visible

	movea.l	DIAdr,a0	;acknowledge screen
	CALLTCS	TriUpd	;rendering completion

	btst.b	#6,$bfe001
	bne.s	.lp	;if not LMB...
	rts



*******************************************************************************
* cleanup
*******************************************************************************

_PrgClnUp	rts



*******************************************************************************
* triple buffer handler (level 3 interrupt handler)
*******************************************************************************

TriBufHndlr	btst.b	#5,$dff01f
	beq.s	.exit	;if not INTREQR.VERTB...
	movem.l	d0-d1/a0-a1/a6,-(sp)

	movea.l	DIAdr,a0
	CALLTCS	TriSwp	;swap screen buffers

	movem.l	(sp)+,d0-d1/a0-a1/a6
.exit	move.w	#$70,$dff09c	;clr INTREQ.BLIT/VERTB/COPER
	rte



*******************************************************************************
* data
*******************************************************************************

	include	/includes/dat.i
