;Circle Example
;--------------
;This an example of 2 circles blitted onto a planar screen at different
;levels.  Move the green circle over the red circle to get an idea of the
;effect you can achieve with a planar screen.
;
;The screen is double buffered and in hi-res, just to be a bit different
;from the other demos.  The circles are removed from the screen using the
;CLEAR mode and a RestoreList.

	opt	o+,c+

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"games/games_lib.i"
	INCLUDE	"games/games.i
CALL	MACRO
	jsr	_LVO\1(a6)
	ENDM

SPEED	=	5

	SECTION	"BOB",CODE

;===========================================================================;
;                             INITIALISE DEMO
;===========================================================================;

Start:	MOVEM.L	A0-A6/D1-D7,-(SP)
	move.l	($4).w,a6
	lea	GMS_Name(pc),a1
	moveq	#$00,d0
	CALL	OpenLibrary
	move.l	d0,GMS_Base
	beq.s	.Error_GMS

	move.l	GMS_Base(pc),a6
	sub.l	a0,a0
	CALL	SetUserPrefs

	CALL	AllocBlitter
	bne.s	.Error_Blitter

	lea	Screen(pc),a0
	CALL	Add_Screen
	tst.w	d0
	bne.s	.Error_Screen

	lea	BOB_List(pc),a1
	CALL	Init_BOB	;Initialise the BOB.
	tst.w	d0
	bne.s	.Error_BOB

	moveq	#2,d0	;d0 = 2 buffers.
	moveq	#4,d1	;d1 = 2 BOB Entries.
	CALL	Init_RestoreList
	move.l	d0,RestoreList
	beq.s	.Error_RestoreList

	CALL	Show_Screen

	moveq	#JPORT1,d0	;Initialise Port.
	CALL	Read_Mouse

	bsr.s	Main

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	move.l	RestoreList(pc),d0
	CALL	Free_RestoreList
.Error_RestoreList
	move.l	GMS_Base(pc),a6
	lea	BOB_List(pc),a1
	CALL	Free_BOB
.Error_BOB
	move.l	GMS_Base(pc),a6
	lea	Screen(pc),a0
	CALL	Delete_Screen
.Error_Screen
	CALL	FreeBlitter
.Error_Blitter
	move.l	GMS_Base(pc),a1
	move.l	($4).w,a6
	CALL	CloseLibrary
.Error_GMS
	MOVEM.L	(SP)+,A0-A6/D1-D7
	moveq	#$00,d0
	rts

;===========================================================================;
;                                MAIN LOOP
;===========================================================================;

Main:	moveq	#$00,d7
.loop	lea	BOB_Circle1(pc),a1
	moveq	#JPORT1,d0
	moveq	#JT_ZBXY,d1
	CALL	Read_JoyPort	;Go get port status.
	move.w	d0,d1
	ext.w	d0
	add.w	d0,BOB_YPos(a1)
	asr.w	#8,d1
	add.w	d1,BOB_XPos(a1)
	btst	#MB_LMB,d0
	bne.s	.done

.draw	lea	Screen(pc),a0
	move.l	RestoreList(pc),a1
	CALL	Restore_List	;Clear all buffered BOB's.

	lea	BOB_List(pc),a1
	move.l	RestoreList(pc),a2
	CALL	Draw_BOBList	;Go and draw all circles.
	CALL	Wait_OSVBL
	CALL	SwapBuffers
	bra.s	.loop
.done	rts

;===========================================================================;
;                                  DATA
;===========================================================================;

RestoreList:
	dc.l	0

GMS_Name:
	dc.b	"games.library",0
	even
GMS_Base:
	dc.l	0

AMT_PLANES =	4

Screen:	dc.l	"GSV1",0	;Structure version.
	dc.l	0,0,0	;Screen_Mem1/2/3
	dc.l	0	;Screen link.
	dc.l	Palette	;Address of screen palette.
	dc.l	0	;Address of rasterlist.
	dc.l	8	;Amt of colours in palette.
	dc.w	640,256	;Screen Width and Height.
	dc.w	640/8,256	;Picture Width and Height.
	dc.w	AMT_PLANES	;Amt of planes.
	dc.w	0,0	;X/Y screen offset.
	dc.w	0,0	;X/Y picture offset.
	dc.l	DBLBUFFER	;Special attributes.
	dc.w	HIRES|COL12BIT	;Screen Mode.
	dc.b	PLANAR	;Screen Type
	dc.b	0	;Reserved.
	even

Palette	dc.w	$000,$f00,$0f0,$ff0,$00f,$000,$0ff,$000

;---------------------------------------------------------------------------;

BOB_List:
	dc.l	"LIST"
	dc.l	BOB_Circle1
	dc.l	BOB_Circle2
	dc.l	BOB_Circle3
	dc.l	LISTEND

BOB_Circle1:
	dc.l	BBV1,0	;Structure version.
	dc.w	BUFFER2	;Blit to buffer 1.
	dc.l	CircleGfx,CircleGfx	;Graphics and Mask data.
	dc.w	0	;Current frame.
	dc.l	.Frame	;Pointer to frame list.
	dc.w	96/8	;Modulo (skip in source) in bytes.
	dc.w	96/8,83	;Width in bytes, Height in pixels.
	dc.w	100,40	;X/Y destination.
	dc.w	0,0	;Border restriction LeftX,TopY.
	dc.w	0,0	;Border restrictions RightX,EndY.
	dc.w	1,1	;1st Plane, Amount of planes.
	dc.l	0	;Plane Size.
	dc.w	CLIP|MASK|CLEAR	;Attributes.
	dc.l	0	;Picture Struct (Bob Origin)
.Frame	dc.w	0,0,0,0
	dc.l	-1

BOB_Circle2:
	dc.l	BBV1,0	;Structure version.
	dc.w	BUFFER2	;Blit to buffer 1.
	dc.l	CircleGfx,CircleGfx	;Graphics and Mask data.
	dc.w	0	;Current frame.
	dc.l	.Frame	;Pointer to frame list.
	dc.w	96/8	;Modulo (skip in source) in bytes.
	dc.w	96/8,83	;Width in bytes, Height in pixels.
	dc.w	278,86	;X/Y destination.
	dc.w	0,0	;Border restriction LeftX,TopY.
	dc.w	0,0	;Border restrictions RightX,EndY.
	dc.w	0,1	;1st Plane, Amount of planes.
	dc.l	0	;Plane Size, not required.
	dc.w	CLEAR	;Attributes.
	dc.l	0	;Picture Struct (Bob Origin)
.Frame	dc.w	0,0,0,0
	dc.l	-1

BOB_Circle3:
	dc.l	BBV1,0	;Structure version.
	dc.w	BUFFER2	;Blit to buffer 1.
	dc.l	CircleGfx,CircleGfx	;Graphics and Mask data.
	dc.w	0	;Current frame.
	dc.l	.Frame	;Pointer to frame list.
	dc.w	96/8	;Modulo (skip in source) in bytes.
	dc.w	96/8,83	;Width in bytes, Height in pixels.
	dc.w	450,150	;X/Y destination.
	dc.w	0,0	;Border restriction LeftX,TopY.
	dc.w	0,0	;Border restrictions RightX,EndY.
	dc.w	2,1	;1st Plane, Amount of planes.
	dc.l	0	;Plane Size, not required.
	dc.w	CLEAR|MASK	;Attributes.
	dc.l	0	;Picture Struct (Bob Origin)
.Frame	dc.w	0,0,0,0
	dc.l	-1

;===========================================================================;
;                         ALL CHIP RAM DATA HERE
;===========================================================================;

	SECTION	"Graphics",DATA_C

CircleGfx:
	INCBIN	"GAMESLIB:Data/BOB_Circle.raw"

