home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / RainingBOBs.s < prev    next >
Encoding:
Text File  |  1997-02-16  |  8.3 KB  |  346 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Raining BOB's Demo
  3. ;------------------
  4. ;This is a demonstration of raining bobs, which I use as a test routine to
  5. ;see how fast some of my blitter routines are.  It's a good example of using
  6. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  7. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  8. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  9. ;interesting :-).
  10. ;
  11. ;Technical notes
  12. ;---------------
  13. ;This demo takes direct advantage of some special GMS blitting features,
  14. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  15. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  16. ;
  17. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  18. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  19. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  20. ;Given that such a function would have to be called 120 times with newly
  21. ;calculated parameters each time to draw, and 120 times to do the clears, we
  22. ;are probably looking at least 65% faster... is that good enough?
  23.  
  24.     INCDIR    "INCLUDES:"
  25.     INCLUDE    "exec/exec_lib.i"
  26.     INCLUDE    "games/games_lib.i"
  27.     INCLUDE    "games/games.i"
  28.  
  29. CALL    MACRO
  30.     jsr    _LVO\1(a6)
  31.     ENDM
  32.  
  33. MAX_IMAGES =    120
  34.  
  35.     SECTION    "RainingBOBs",CODE
  36.  
  37. ;===========================================================================;
  38. ;                             INITIALISE DEMO
  39. ;===========================================================================;
  40.  
  41. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  42.     move.l    ($4).w,a6
  43.     lea    GMS_Name(pc),a1
  44.     moveq    #$00,d0
  45.     CALL    OpenLibrary
  46.     move.l    d0,GMS_Base
  47.     beq    .Error_GMS
  48.  
  49.     move.l    GMS_Base(pc),a6
  50.     sub.l    a0,a0
  51.     CALL    SetUserPrefs
  52.  
  53.     CALL    AllocBlitter
  54.     tst.w    d0
  55.     bne.s    .Error_Blitter
  56.  
  57.     lea    PIC_Bobs(pc),a1
  58.     CALL    LoadPic
  59.     tst.w    d0
  60.     bne.s    .Error_Picture
  61.  
  62.     lea    Screen(pc),a0
  63.     move.w    PIC_Planes(a1),GS_Planes(a0)
  64.     move.l    PIC_Palette(a1),GS_Palette(a0)
  65.  
  66.     CALL    AddScreen
  67.     tst.w    d0
  68.     bne.s    .Error_Screen
  69.  
  70.     moveq    #2,d0    ;d0 = 2 buffers.
  71.     move.w    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  72.     CALL    InitRestore
  73.     move.l    d0,RestoreList
  74.     beq.s    .Error_RestoreList
  75.  
  76.     lea    BOB_Spinner(pc),a1    ;Initialise the BOB.
  77.     CALL    InitBOB
  78.     tst.w    d0
  79.     bne.s    .Error_BOB
  80.  
  81.     CALL    ShowScreen
  82.  
  83.     bsr.s    Main
  84.  
  85. .ReturnToDOS
  86.     move.l    GMS_Base(pc),a6
  87.     lea    BOB_Spinner(pc),a1
  88.     CALL    FreeBOB
  89. .Error_BOB
  90.     move.l    RestoreList(pc),d0
  91.     CALL    FreeRestore
  92. .Error_RestoreList
  93.     lea    Screen(pc),a0
  94.     CALL    DeleteScreen
  95. .Error_Screen
  96.     lea    PIC_Bobs(pc),a1
  97.     CALL    FreePic
  98. .Error_Picture
  99.     CALL    FreeBlitter
  100. .Error_Blitter
  101.     move.l    ($4).w,a6
  102.     move.l    GMS_Base(pc),a1
  103.     CALL    CloseLibrary
  104. .Error_GMS
  105.     MOVEM.L    (SP)+,A0-A6/D1-D7
  106.     moveq    #$00,d0
  107.     rts
  108.  
  109. ;===========================================================================;
  110. ;                                DEMO CODE
  111. ;===========================================================================;
  112.  
  113. Main:    move.l    GMS_Base(pc),a6    ;a6 = GMSBase.
  114.     moveq    #$00,d7
  115.  
  116.     lea    Screen(pc),a0    ;a0 = GameScreen.
  117.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  118.     move.w    MB_AmtEntries(a1),d2
  119.     subq.w    #1,d2
  120. .create    bsr    Regenerate_BOB
  121.  
  122.     move.w    GS_ScrHeight(a0),d1
  123.     CALL    FastRandom
  124.     move.w    d0,BE_YCoord(a2)
  125.  
  126.     lea    NBE_SIZEOF(a2),a2
  127.     dbra    d2,.create
  128.  
  129. ;---------------------------------------------------------------------------;
  130.  
  131. Loop:    addq.w    #1,d7
  132.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  133.     move.w    MB_AmtEntries(a1),d2
  134.     subq.w    #1,d2
  135. .update    bsr.s    Update_BOB
  136.     lea    NBE_SIZEOF(a2),a2
  137.     dbra    d2,.update
  138.  
  139.     move.l    RestoreList(pc),a1    ;a1 = RestoreList.
  140.     CALL    Restore
  141.  
  142.     move.l    a1,a2    ;a2 = RestoreList.
  143.     lea    BOB_Spinner(pc),a1    ;a1 = BOB to draw.
  144.     moveq    #BUFFER2,d0
  145.     CALL    DrawBOB    ;>> = Draw the BOB
  146.     CALL    WaitSVBL    ;>> = Wait for VBL.
  147.     CALL    SwapBuffers    ;>> = Swap the buffers.
  148.  
  149.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  150.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  151.     CALL    ReadJoyPort    ;>> = Go get port status.
  152.     btst    #MB_LMB,d0
  153.     beq.s    Loop
  154.     rts
  155.  
  156. ;===========================================================================;
  157. ;                               UPDATE A BOB
  158. ;===========================================================================;
  159. ;Function: Moves the entity according to its internal settings.
  160. ;Requires: a1 = BOB structure.
  161. ;       a2 = Entry to update.
  162.  
  163. Update_BOB:
  164.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  165.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  166.     cmp.w    GS_ScrHeight(a0),d0
  167.     blt.s    .YOkay
  168.     bsr    Regenerate_BOB
  169.     bra.s    .Animate
  170. .YOkay    move.w    d0,BE_YCoord(a2)
  171.  
  172. .Animate
  173.     tst.w    BE_Locked(a2)
  174.     beq.s    .exit
  175.     move.w    d7,d6
  176.     and.w    #%00000011,d6
  177.     bne.s    .exit
  178.     move.w    BE_FChange(a2),d1
  179.     bgt.s    .Positive
  180.  
  181. .Negative
  182.     cmp.w    #1,BE_Set(a2)
  183.     bgt.s    .NBlue
  184.     beq.s    .NGreen
  185. .NRed    add.w    d1,BE_Frame(a2)
  186.     tst    BE_Frame(a2)
  187.     bge.s    .exit
  188.     move.w    #1,BE_FChange(a2)
  189.     clr.w    BE_Frame(a2)
  190.     rts
  191. .NGreen    add.w    d1,BE_Frame(a2)
  192.     cmp.w    #4,BE_Frame(a2)
  193.     bge.s    .done
  194.     move.w    #1,BE_FChange(a2)
  195.     move.w    #4,BE_Frame(a2)
  196.     rts
  197. .NBlue    add.w    d1,BE_Frame(a2)
  198.     cmp.w    #8,BE_Frame(a2)
  199.     bge.s    .done
  200.     move.w    #1,BE_FChange(a2)
  201.     move.w    #8,BE_Frame(a2)
  202. .exit    rts
  203.  
  204. .Positive
  205.     cmp.w    #1,BE_Set(a2)
  206.     bgt.s    .PBlue
  207.     beq.s    .PGreen
  208. .PRed    add.w    d1,BE_Frame(a2)
  209.     cmp.w    #3,BE_Frame(a2)
  210.     ble.s    .done
  211.     move.w    #-1,BE_FChange(a2)
  212.     move.w    #2,BE_Frame(a2)
  213.     rts
  214. .PGreen    add.w    d1,BE_Frame(a2)
  215.     cmp.w    #7,BE_Frame(a2)
  216.     ble.s    .done
  217.     move.w    #-1,BE_FChange(a2)
  218.     move.w    #6,BE_Frame(a2)
  219.     rts
  220. .PBlue    add.w    d1,BE_Frame(a2)
  221.     cmp.w    #11,BE_Frame(a2)
  222.     ble.s    .done
  223.     move.w    #-1,BE_FChange(a2)
  224.     move.w    #10,BE_Frame(a2)
  225. .done    rts
  226.  
  227. ;===========================================================================;
  228. ;                            REGENERATE BOB ENTITY
  229. ;===========================================================================;
  230. ;Function: Regenerates an entity with completely new data.
  231. ;Requires: a2 = Entry to update.
  232.  
  233. Regenerate_BOB:
  234.     move.w    GS_ScrWidth(a0),d1
  235.     CALL    FastRandom
  236.     subq.w    #4,d0
  237.     and.w    #%1111111111111000,d0
  238.     move.w    d0,BE_XCoord(a2)
  239.  
  240.     moveq    #8,d1
  241.     CALL    FastRandom
  242.     addq.w    #2,d0
  243.     move.w    d0,BE_Speed(a2)
  244.  
  245.     moveq    #12,d1
  246.     CALL    FastRandom
  247.     move.w    d0,BE_Frame(a2)
  248.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  249.  
  250.     move.w    #-8,BE_YCoord(a2)
  251.     move.w    #1,BE_FChange(a2)
  252.     eor.w    #1,BE_Locked(a2)
  253.     rts
  254.  
  255. .Sets    dc.b    0,0,0,0
  256.     dc.b    1,1,1,1
  257.     dc.b    2,2,2,2
  258.  
  259. ;===========================================================================;
  260. ;                                  DATA
  261. ;===========================================================================;
  262.  
  263. GMS_Name:
  264.     dc.b    "games.library",0
  265.     even
  266. GMS_Base:
  267.     dc.l    0
  268.  
  269. RestoreList:
  270.     dc.l    0
  271.  
  272. Screen:    dc.l    GSV1,0    ;Structure version.
  273.     dc.l    0,0,0    ;Screen Memory 1/2/3.
  274.     dc.l    0    ;Screen link.
  275.     dc.l    0    ;Address of screen palette.
  276.     dc.l    0    ;Address of rasterlist.
  277.     dc.l    0    ;Amount of colours in palette.
  278.     dc.w    320,256    ;Screen Width and Height.
  279.     dc.w    0,0,0    ;Picture Width, ByteWidth, Height.
  280.     dc.w    0    ;Amount of planes.
  281.     dc.w    0,0    ;X/Y screen offset.
  282.     dc.w    0,0    ;X/Y picture offset.
  283.     dc.l    DBLBUFFER    ;Special attributes.
  284.     dc.w    COL12BIT|LORES    ;Screen Mode.
  285.     dc.w    ILBM    ;Screen Type
  286.  
  287. ;---------------------------------------------------------------------------;
  288.  
  289. PIC_Bobs:
  290.     dc.l    PCV1,0    ;Version header.
  291.     dc.l    0    ;Source data.
  292.     dc.w    0,0,0    ;Width, Height.
  293.     dc.w    0    ;Amount of Planes.
  294.     dc.l    0    ;Amount of colours.
  295.     dc.l    0    ;Source palette.
  296.     dc.w    LORES|COL12BIT    ;Screen mode.
  297.     dc.w    ILBM    ;Destination
  298.     dc.l    VIDEOMEM|GETPALETTE    ;Parameters.
  299.     dc.l    .File
  300. .File    dc.b    "GAMESLIB:data/IFF.Pulse",0
  301.     even
  302.  
  303. ;---------------------------------------------------------------------------;
  304.  
  305.   STRUCTURE    NBE,BE_SIZEOF
  306.     WORD    BE_Speed
  307.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  308.     WORD    BE_FChange
  309.     WORD    BE_Locked
  310.     LABEL    NBE_SIZEOF
  311.  
  312. BOB_Spinner:
  313.     dc.l    MBV1,0    ;Structure version.
  314.     dc.l    0,0    ;Graphics and Mask data.
  315.     dc.w    MAX_IMAGES    ;Amount of entries.
  316.     dc.l    .Frames    ;Pointer to frame list.
  317.     dc.w    0    ;Modulo (skip in source) in bytes.
  318.     dc.w    16,16/8,8    ;Width in bytes, Height in pixels.
  319.     dc.l    Images    ;Coordinate and frame list.
  320.     dc.w    0,0    ;Border restriction LeftX,TopY.
  321.     dc.w    0,0    ;Border restrictions RightX,EndY.
  322.     dc.w    0,0    ;Amount of planes.
  323.     dc.l    0    ;Size of plane, not required.
  324.     dc.l    CLIP|GENMASKS|CLEAR|CLRNOMASK    ;Attributes.
  325.     dc.l    PIC_Bobs    ;Picture Structure (Bob Origin)
  326.     dc.w    NBE_SIZEOF    ;Entry size for images.
  327.  
  328. .Frames    dc.w    00,8*0,0,0    ;RED
  329.     dc.w    00,8*1,0,0
  330.     dc.w    00,8*2,0,0
  331.     dc.w    00,8*3,0,0
  332.     dc.w    16,8*0,0,0    ;GREEN
  333.     dc.w    16,8*1,0,0
  334.     dc.w    16,8*2,0,0
  335.     dc.w    16,8*3,0,0
  336.     dc.w    32,8*0,0,0    ;BLUE
  337.     dc.w    32,8*1,0,0
  338.     dc.w    32,8*2,0,0
  339.     dc.w    32,8*3,0,0
  340.     dc.l    -1
  341.  
  342.     SECTION    Images,BSS
  343.  
  344. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  345.  
  346.