home *** CD-ROM | disk | FTP | other *** search
- ;-------T-------T------------------------T----------------------------------;
- ;Raining BOB's Demo
- ;------------------
- ;This is a demonstration of raining bobs, which I use as a test routine to
- ;see how fast some of my blitter routines are. It's a good example of using
- ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
- ;screen. **120** 16 colour 16x8 bobs just manage to run at full speed on my
- ;A1200+FAST, change the value if you have a faster machine (600 can be very
- ;interesting :-).
- ;
- ;Technical notes
- ;---------------
- ;This demo takes direct advantage of some special GMS blitting features,
- ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
- ;alignment (gain: 15%). That allows us to have 25% more BOB's on screen!
- ;
- ;The fact that GMS will use the CPU to draw and clear images when the blitter
- ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
- ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
- ;Given that such a function would have to be called 120 times with newly
- ;calculated parameters each time to draw, and 120 times to do the clears, we
- ;are probably looking at least 65% faster... is that good enough?
-
- INCDIR "INCLUDES:"
- INCLUDE "exec/exec_lib.i"
- INCLUDE "games/games_lib.i"
- INCLUDE "games/games.i"
-
- CALL MACRO
- jsr _LVO\1(a6)
- ENDM
-
- MAX_IMAGES = 120
-
- SECTION "RainingBOBs",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
- sub.l a0,a0
- CALL SetUserPrefs
-
- CALL AllocBlitter
- tst.w d0
- bne.s .Error_Blitter
-
- lea PIC_Bobs(pc),a1
- CALL LoadPic
- tst.w d0
- bne.s .Error_Picture
-
- lea Screen(pc),a0
- move.w PIC_Planes(a1),GS_Planes(a0)
- move.l PIC_Palette(a1),GS_Palette(a0)
-
- CALL AddScreen
- tst.w d0
- bne.s .Error_Screen
-
- moveq #2,d0 ;d0 = 2 buffers.
- move.w #MAX_IMAGES,d1 ;d1 = Maximum amount of images.
- CALL InitRestore
- move.l d0,RestoreList
- beq.s .Error_RestoreList
-
- lea BOB_Spinner(pc),a1 ;Initialise the BOB.
- CALL InitBOB
- tst.w d0
- bne.s .Error_BOB
-
- CALL ShowScreen
-
- bsr.s Main
-
- .ReturnToDOS
- move.l GMS_Base(pc),a6
- lea BOB_Spinner(pc),a1
- CALL FreeBOB
- .Error_BOB
- move.l RestoreList(pc),d0
- CALL FreeRestore
- .Error_RestoreList
- lea Screen(pc),a0
- CALL DeleteScreen
- .Error_Screen
- lea PIC_Bobs(pc),a1
- CALL FreePic
- .Error_Picture
- CALL FreeBlitter
- .Error_Blitter
- move.l ($4).w,a6
- move.l GMS_Base(pc),a1
- CALL CloseLibrary
- .Error_GMS
- MOVEM.L (SP)+,A0-A6/D1-D7
- moveq #$00,d0
- rts
-
- ;===========================================================================;
- ; DEMO CODE
- ;===========================================================================;
-
- Main: move.l GMS_Base(pc),a6 ;a6 = GMSBase.
- moveq #$00,d7
-
- lea Screen(pc),a0 ;a0 = GameScreen.
- move.l MB_EntryList(a1),a2 ;a2 = First entry.
- move.w MB_AmtEntries(a1),d2
- subq.w #1,d2
- .create bsr Regenerate_BOB
-
- move.w GS_ScrHeight(a0),d1
- CALL FastRandom
- move.w d0,BE_YCoord(a2)
-
- lea NBE_SIZEOF(a2),a2
- dbra d2,.create
-
- ;---------------------------------------------------------------------------;
-
- Loop: addq.w #1,d7
- move.l MB_EntryList(a1),a2 ;a2 = First entry.
- move.w MB_AmtEntries(a1),d2
- subq.w #1,d2
- .update bsr.s Update_BOB
- lea NBE_SIZEOF(a2),a2
- dbra d2,.update
-
- move.l RestoreList(pc),a1 ;a1 = RestoreList.
- CALL Restore
-
- move.l a1,a2 ;a2 = RestoreList.
- lea BOB_Spinner(pc),a1 ;a1 = BOB to draw.
- moveq #BUFFER2,d0
- CALL DrawBOB ;>> = Draw the BOB
- CALL WaitSVBL ;>> = Wait for VBL.
- CALL SwapBuffers ;>> = Swap the buffers.
-
- moveq #JPORT1,d0 ;d0 = JoyPort2
- moveq #JT_ZBXY,d1 ;d1 = Bit switch type.
- CALL ReadJoyPort ;>> = Go get port status.
- btst #MB_LMB,d0
- beq.s Loop
- rts
-
- ;===========================================================================;
- ; UPDATE A BOB
- ;===========================================================================;
- ;Function: Moves the entity according to its internal settings.
- ;Requires: a1 = BOB structure.
- ; a2 = Entry to update.
-
- Update_BOB:
- move.w BE_YCoord(a2),d0 ;d0 = YCoord
- add.w BE_Speed(a2),d0 ;d0 = (YCoord)+YSpeed
- cmp.w GS_ScrHeight(a0),d0
- blt.s .YOkay
- bsr Regenerate_BOB
- bra.s .Animate
- .YOkay move.w d0,BE_YCoord(a2)
-
- .Animate
- tst.w BE_Locked(a2)
- beq.s .exit
- move.w d7,d6
- and.w #%00000011,d6
- bne.s .exit
- move.w BE_FChange(a2),d1
- bgt.s .Positive
-
- .Negative
- cmp.w #1,BE_Set(a2)
- bgt.s .NBlue
- beq.s .NGreen
- .NRed add.w d1,BE_Frame(a2)
- tst BE_Frame(a2)
- bge.s .exit
- move.w #1,BE_FChange(a2)
- clr.w BE_Frame(a2)
- rts
- .NGreen add.w d1,BE_Frame(a2)
- cmp.w #4,BE_Frame(a2)
- bge.s .done
- move.w #1,BE_FChange(a2)
- move.w #4,BE_Frame(a2)
- rts
- .NBlue add.w d1,BE_Frame(a2)
- cmp.w #8,BE_Frame(a2)
- bge.s .done
- move.w #1,BE_FChange(a2)
- move.w #8,BE_Frame(a2)
- .exit rts
-
- .Positive
- cmp.w #1,BE_Set(a2)
- bgt.s .PBlue
- beq.s .PGreen
- .PRed add.w d1,BE_Frame(a2)
- cmp.w #3,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #2,BE_Frame(a2)
- rts
- .PGreen add.w d1,BE_Frame(a2)
- cmp.w #7,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #6,BE_Frame(a2)
- rts
- .PBlue add.w d1,BE_Frame(a2)
- cmp.w #11,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #10,BE_Frame(a2)
- .done rts
-
- ;===========================================================================;
- ; REGENERATE BOB ENTITY
- ;===========================================================================;
- ;Function: Regenerates an entity with completely new data.
- ;Requires: a2 = Entry to update.
-
- Regenerate_BOB:
- move.w GS_ScrWidth(a0),d1
- CALL FastRandom
- subq.w #4,d0
- and.w #%1111111111111000,d0
- move.w d0,BE_XCoord(a2)
-
- moveq #8,d1
- CALL FastRandom
- addq.w #2,d0
- move.w d0,BE_Speed(a2)
-
- moveq #12,d1
- CALL FastRandom
- move.w d0,BE_Frame(a2)
- move.b .Sets(pc,d0.w),BE_Set+1(a2)
-
- move.w #-8,BE_YCoord(a2)
- move.w #1,BE_FChange(a2)
- eor.w #1,BE_Locked(a2)
- rts
-
- .Sets dc.b 0,0,0,0
- dc.b 1,1,1,1
- dc.b 2,2,2,2
-
- ;===========================================================================;
- ; DATA
- ;===========================================================================;
-
- GMS_Name:
- dc.b "games.library",0
- even
- GMS_Base:
- dc.l 0
-
- RestoreList:
- dc.l 0
-
- Screen: dc.l GSV1,0 ;Structure version.
- dc.l 0,0,0 ;Screen Memory 1/2/3.
- dc.l 0 ;Screen link.
- dc.l 0 ;Address of screen palette.
- dc.l 0 ;Address of rasterlist.
- dc.l 0 ;Amount of colours in palette.
- dc.w 320,256 ;Screen Width and Height.
- dc.w 0,0,0 ;Picture Width, ByteWidth, Height.
- dc.w 0 ;Amount 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 COL12BIT|LORES ;Screen Mode.
- dc.w ILBM ;Screen Type
-
- ;---------------------------------------------------------------------------;
-
- PIC_Bobs:
- dc.l PCV1,0 ;Version header.
- dc.l 0 ;Source data.
- dc.w 0,0,0 ;Width, Height.
- dc.w 0 ;Amount of Planes.
- dc.l 0 ;Amount of colours.
- dc.l 0 ;Source palette.
- dc.w LORES|COL12BIT ;Screen mode.
- dc.w ILBM ;Destination
- dc.l VIDEOMEM|GETPALETTE ;Parameters.
- dc.l .File
- .File dc.b "GAMESLIB:data/IFF.Pulse",0
- even
-
- ;---------------------------------------------------------------------------;
-
- STRUCTURE NBE,BE_SIZEOF
- WORD BE_Speed
- WORD BE_Set ;0 = Red, 1 = Green, 2 = Blue.
- WORD BE_FChange
- WORD BE_Locked
- LABEL NBE_SIZEOF
-
- BOB_Spinner:
- dc.l MBV1,0 ;Structure version.
- dc.l 0,0 ;Graphics and Mask data.
- dc.w MAX_IMAGES ;Amount of entries.
- dc.l .Frames ;Pointer to frame list.
- dc.w 0 ;Modulo (skip in source) in bytes.
- dc.w 16,16/8,8 ;Width in bytes, Height in pixels.
- dc.l Images ;Coordinate and frame list.
- 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.l CLIP|GENMASKS|CLEAR|CLRNOMASK ;Attributes.
- dc.l PIC_Bobs ;Picture Structure (Bob Origin)
- dc.w NBE_SIZEOF ;Entry size for images.
-
- .Frames dc.w 00,8*0,0,0 ;RED
- dc.w 00,8*1,0,0
- dc.w 00,8*2,0,0
- dc.w 00,8*3,0,0
- dc.w 16,8*0,0,0 ;GREEN
- dc.w 16,8*1,0,0
- dc.w 16,8*2,0,0
- dc.w 16,8*3,0,0
- dc.w 32,8*0,0,0 ;BLUE
- dc.w 32,8*1,0,0
- dc.w 32,8*2,0,0
- dc.w 32,8*3,0,0
- dc.l -1
-
- SECTION Images,BSS
-
- Images ds.b NBE_SIZEOF*MAX_IMAGES ;X/Y/Frame/Speed/Set/FChange/Locked
-
-