;BOB example
;-----------
;This example blits a Worm from an IFF file on to a double buffered screen.
;There is no RESTORE or CLEAR mode used in this demo, so the background
;is never put back.

	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	.Error_GMS

	move.l	GMS_Base(pc),a6	;Activate user preferences.
	sub.l	a0,a0
	CALL	SetUserPrefs

	CALL	AllocBlitter
	tst.w	d0
	bne	.Error_Blitter

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

;---------------------------------------------------------------------------;
;Load a picture into the background of the screen.

	lea	Picture(pc),a1		;Load the picture.
	move.l	GS_MemPtr2(a0),PIC_Data(a1)
	CALL	LoadPic
	tst.w	d0
	bne.s	.Error_Picture

	lea	Screen(pc),a0
	CALL	SwapBuffers
	moveq	#BUFFER1,d0
	moveq	#BUFFER2,d1
	CALL	CopyBuffer

;---------------------------------------------------------------------------;
;Load the BOB file in.  This contains the graphics data that we are
;going to draw to the screen.

	lea	PIC_Bobs(pc),a1	;Load the picture that contains
	CALL	LoadPic	;our BOB.
	tst.w	d0
	bne.s	.Error_BOBPic

	lea	Screen(pc),a0	;Initialise the BOB so that it is
	lea	BOB_Rambo(pc),a1	;ready for drawing.
	CALL	Init_BOB
	tst.w	d0
	bne.s	.Error_BOB

	CALL	Show_Screen

	bsr.s	Main

.ReturnToDOS
	move.l	GMS_Base(pc),a6
	lea	BOB_Rambo(pc),a1
	CALL	Free_BOB
.Error_BOB
	move.l	GMS_Base(pc),a6
	lea	PIC_Bobs(pc),a1
	CALL	FreePic
.Error_BOBPic
	move.l	GMS_Base(pc),a6
	lea	Picture(pc),a1
	CALL	FreePic
.Error_Picture
	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:	move.l	GMS_Base(pc),a6
	moveq	#$00,d7
Loop:	CALL	Draw_BOB	;Blit the bob.
	CALL	Wait_OSVBL	;Wait for VBL.
	CALL	SwapBuffers

	addq.w	#1,d7
	cmp.w	#SPEED,d7
	ble.s	.move
	moveq	#$00,d7
	addq.w	#1,BOB_Frame(a1)
	cmp.w	#8,BOB_Frame(a1)
	blt.s	.move
	clr.w	BOB_Frame(a1)

.move	moveq	#JPORT1,d0	;Read the mouse, then update the
	moveq	#JT_ZBXY,d1	;BOB's X and Y co-ordinates.
	CALL	Read_JoyPort
	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
	beq.s	Loop
	rts

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

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

AMT_PLANES =	5

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	32	;Amt of colours in palette.
	dc.w	320,256	;Screen Width and Height.
	dc.w	320/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	LORES|COL12BIT	;Screen Mode.
	dc.b	INTERLEAVED	;Screen Type
	dc.b	0	;Reserved.
	even

Palette	dc.w	$000,$130,$FCB,$FA9,$D88,$965,$644,$211
	dc.w	$400,$444,$FF0,$432,$CC0,$150,$501,$880
	dc.w	$261,$271,$382,$492,$5A3,$5B4,$677,$6C4
	dc.w	$788,$9AA,$BCC,$801,$901,$A02,$701,$601

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

Picture	dc.l	PCV1,0	;Version header.
	dc.l	0	;Source data.
	dc.w	320/8,256	;Width, Height.
	dc.w	AMT_PLANES	;Amount of Planes.
	dc.l	32	;Amount of colours.
	dc.l	Palette	;Source palette (remap).
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	0	;Parameters.
	dc.l	.File
.File	dc.b	"GAMESLIB:data/IFF.Pic320",0
	even

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

PIC_Bobs:
	dc.l	PCV1,0	;Version header.
	dc.l	0	;Source data.
	dc.w	320/8,256	;Width, Height.
	dc.w	AMT_PLANES	;Amount of Planes.
	dc.l	0	;Amount of colours.
	dc.l	Palette	;Source palette (remap).
	dc.w	LORES|COL12BIT	;Screen mode.
	dc.w	INTERLEAVED	;Destination
	dc.l	VIDEOMEM	;Parameters.
	dc.l	.File
.File	dc.b	"GAMESLIB:data/IFF.Rambo",0
	even

BOB_Rambo:
	dc.l	BBV1,0	;Structure version.
	dc.w	BUFFER2	;Blit to buffer 1.
	dc.w	0	;Current frame.
	dc.l	0,0	;Graphics data.
	dc.l	.Frames	;Pointer to frame list.
	dc.w	0	;Modulo (skip in source) in bytes.
	dc.w	32/8,24	;Width in bytes, Height in pixels.
	dc.w	100,100	;X/Y destination.
	dc.w	0,0	;Border restriction LeftX,TopY.
	dc.w	0,0	;Border restrictions RightX,EndY.
	dc.w	0,0	;Amount of planes.
	dc.l	0	;Size of plane, not required.
	dc.w	CLIP|MASK	;Attributes.
	dc.l	PIC_Bobs	;Picture struct (Bob origin).
.Frames	dc.w	000,0,000,24	;X/Y Graphic, X/Y Mask
	dc.w	032,0,032,24	;...
	dc.w	064,0,064,24
	dc.w	096,0,096,24
	dc.w	128,0,128,24
	dc.w	160,0,160,24
	dc.w	192,0,192,24
	dc.w	224,0,224,24
	dc.w	256,0,256,24
	dc.w	288,0,288,24
	dc.l	-1

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

