home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / BouncingBOBs.s next >
Encoding:
Text File  |  1997-02-11  |  8.8 KB  |  394 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Bouncing BOB's Demo
  3. ;-------------------
  4. ;This is a demonstration of bouncing bobs, an extension of the original
  5. ;Raining BOBs demo.
  6. ;
  7. ;It runs in HiRes Laced with a total of 35 large BOBs at 50 FPS ('020+FAST).
  8.  
  9.     INCDIR    "INCLUDES:"
  10.     INCLUDE    "exec/exec_lib.i"
  11.     INCLUDE    "games/games_lib.i"
  12.     INCLUDE    "games/games.i"
  13.  
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17.  
  18. MAX_IMAGES =    35
  19.  
  20.     SECTION    "BouncingBOBs",CODE
  21.  
  22. ;===========================================================================;
  23. ;                             INITIALISE DEMO
  24. ;===========================================================================;
  25.  
  26. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  27.     move.l    ($4).w,a6
  28.     lea    GMS_Name(pc),a1
  29.     moveq    #$00,d0
  30.     CALL    OpenLibrary
  31.     move.l    d0,GMS_Base
  32.     beq    .Error_GMS
  33.  
  34.     move.l    GMS_Base(pc),a6
  35.     sub.l    a0,a0
  36.     CALL    SetUserPrefs
  37.  
  38.     CALL    AllocBlitter
  39.     tst.w    d0
  40.     bne.s    .Error_Blitter
  41.  
  42.     lea    PIC_Bobs(pc),a1
  43.     CALL    LoadPic
  44.     tst.w    d0
  45.     bne.s    .Error_Picture
  46.  
  47.     lea    Screen(pc),a0
  48.     move.w    PIC_Planes(a1),GS_Planes(a0)
  49.     move.l    PIC_Palette(a1),GS_Palette(a0)
  50.  
  51.     CALL    AddScreen
  52.     tst.w    d0
  53.     bne.s    .Error_Screen
  54.  
  55.     moveq    #2,d0    ;d0 = 2 buffers.
  56.     move.w    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  57.     CALL    InitRestore
  58.     move.l    d0,RestoreList
  59.     beq.s    .Error_RestoreList
  60.  
  61.     lea    BOB_InitList(pc),a1    ;Initialise the BOBs.
  62.     CALL    InitBOB
  63.     tst.w    d0
  64.     bne.s    .Error_BOB
  65.  
  66.     CALL    ShowScreen
  67.  
  68.     bsr.s    Main
  69.  
  70. .ReturnToDOS
  71.     move.l    GMS_Base(pc),a6
  72.     lea    BOB_InitList(pc),a1
  73.     CALL    FreeBOB
  74. .Error_BOB
  75.     move.l    RestoreList(pc),d0
  76.     CALL    FreeRestore
  77. .Error_RestoreList
  78.     lea    Screen(pc),a0
  79.     CALL    DeleteScreen
  80. .Error_Screen
  81.     lea    PIC_Bobs(pc),a1
  82.     CALL    FreePic
  83. .Error_Picture
  84.     CALL    FreeBlitter
  85. .Error_Blitter
  86.     move.l    ($4).w,a6
  87.     move.l    GMS_Base(pc),a1
  88.     CALL    CloseLibrary
  89. .Error_GMS
  90.     MOVEM.L    (SP)+,A0-A6/D1-D7
  91.     moveq    #$00,d0
  92.     rts
  93.  
  94. ;===========================================================================;
  95. ;                                DEMO CODE
  96. ;===========================================================================;
  97.  
  98. Main:    move.l    GMS_Base(pc),a6    ;a6 = GMSBase.
  99.     lea    Screen(pc),a0    ;a0 = GameScreen.
  100.  
  101.     lea    BOB_Interlaced(pc),a1    ;a1 = BOB to draw.
  102.     move.w    GS_ScrWidth(a0),d0
  103.     sub.w    BOB_Width(a1),d0
  104.     move.w    d0,BOB_XCoord(a1)
  105.     moveq    #BUFFER2,d0    ;d0 = Buffer 2.
  106.     CALL    DrawBOB    ;>> = Draw the BOB
  107.     moveq    #BUFFER1,d0    ;d1 = Buffer 1.
  108.     CALL    DrawBOB    ;>> = Draw the BOB
  109.  
  110.     moveq    #$00,d7
  111.     lea    BOB_Ball(pc),a1
  112.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  113.     move.w    MB_AmtEntries(a1),d2    ;a2 = Amount of entries.
  114.     subq.w    #1,d2    ;d2 = --1 for loop.
  115.     moveq    #$00,d3
  116.  
  117. .create    eor.w    #1,d3
  118.  
  119.     moveq    #8,d1    ;Set Y speed here.
  120.     CALL    FastRandom
  121.     addq.w    #2,d0
  122.     move.w    d0,BE_YSpeed(a2)
  123.  
  124.     move.w    #8,d1    ;Set X speed here.
  125.     CALL    FastRandom
  126.     addq.w    #1,d0
  127.     move.w    d0,BE_XSpeed(a2)
  128.  
  129.     tst.w    d3
  130.     beq.s    .posx
  131.     neg.w    BE_XSpeed(a2)
  132. .posx
  133.     move.w    GS_ScrHeight(a0),d1    ;Starting Y coordinate.
  134.     asr.w    #1,d1
  135.     CALL    FastRandom
  136.     asr.w    #1,d1
  137.     add.w    d1,d0
  138.     move.w    d0,BE_YCoord(a2)
  139.  
  140.     move.w    GS_ScrWidth(a0),d1    ;Starting X coordinate.
  141.     CALL    FastRandom
  142.     move.w    d0,BE_XCoord(a2)
  143.  
  144.     moveq    #12,d1
  145.     CALL    FastRandom
  146.     move.w    d0,BE_Frame(a2)
  147.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  148.     move.w    #1,BE_FChange(a2)
  149.     move.w    d3,BE_Locked(a2)
  150.  
  151.     lea    NBE_SIZEOF(a2),a2
  152.     dbra    d2,.create
  153.     bra.s    Loop
  154.  
  155. .Sets    dc.b    0,0,0,0
  156.     dc.b    1,1,1,1
  157.     dc.b    2,2,2,2
  158.  
  159. ;---------------------------------------------------------------------------;
  160.  
  161. Loop:    addq.w    #1,d7
  162.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  163.     move.w    MB_AmtEntries(a1),d2
  164.     subq.w    #1,d2
  165. .update    bsr.s    UpdateBOB
  166.     lea    NBE_SIZEOF(a2),a2
  167.     dbra    d2,.update
  168.  
  169.     move.l    RestoreList(pc),a1    ;a1 = RestoreList.
  170.     CALL    Restore
  171.  
  172.     move.l    a1,a2    ;a2 = RestoreList.
  173.     lea    BOB_Ball(pc),a1    ;a1 = BOB to draw.
  174.     moveq    #BUFFER2,d0
  175.     CALL    DrawBOB    ;>> = Draw the BOB
  176.  
  177.     CALL    WaitSVBL    ;>> = Wait for VBL.
  178.     CALL    SwapBuffers    ;>> = Swap the buffers.
  179.  
  180.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  181.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  182.     CALL    ReadJoyPort    ;>> = Go get port status.
  183.     btst    #MB_LMB,d0
  184.     beq.s    Loop
  185.     rts
  186.  
  187. ;===========================================================================;
  188. ;                               UPDATE A BOB
  189. ;===========================================================================;
  190. ;Function: Moves the entity according to its internal settings.
  191. ;Requires: a1 = BOB structure.
  192. ;       a2 = Entry to update.
  193.  
  194. GRAVITY =    1
  195.  
  196. UpdateBOB:
  197.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  198.     add.w    BE_YSpeed(a2),d0    ;d0 = (YCoord)+YSpeed
  199.     cmp.w    GS_ScrHeight(a0),d0    ;d0 = Should this BOB bounce?
  200.     blt.s    .NoBounce    ;>> = No.
  201.     neg.w    BE_YSpeed(a2)    ;a2 = Bounce the BOB!
  202.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the BOB down.
  203.     bra.s    .CheckX
  204. .NoBounce
  205.     move.w    d0,BE_YCoord(a2)    ;d0 = Save the change.
  206.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the BOB down.
  207.  
  208. .CheckX    move.w    BE_XCoord(a2),d0
  209.     add.w    BE_XSpeed(a2),d0
  210.     cmp.w    GS_ScrWidth(a0),d0
  211.     bcs.s    .NoXBounce
  212.     neg.w    BE_XSpeed(a2)
  213.     bra.s    .Animate
  214. .NoXBounce
  215.     move.w    d0,BE_XCoord(a2)
  216.  
  217. ;---------------------------------------------------------------------------;
  218.  
  219. .Animate
  220.     tst.w    BE_Locked(a2)
  221.     beq.s    .exit
  222.     move.w    d7,d6
  223.     and.w    #%00000011,d6
  224.     bne.s    .exit
  225.     move.w    BE_FChange(a2),d1
  226.     bgt.s    .Positive
  227.  
  228. .Negative
  229.     cmp.w    #1,BE_Set(a2)
  230.     bgt.s    .NBlue
  231.     beq.s    .NGreen
  232. .NRed    add.w    d1,BE_Frame(a2)
  233.     tst    BE_Frame(a2)
  234.     bge.s    .exit
  235.     move.w    #1,BE_FChange(a2)
  236.     clr.w    BE_Frame(a2)
  237.     rts
  238. .NGreen    add.w    d1,BE_Frame(a2)
  239.     cmp.w    #4,BE_Frame(a2)
  240.     bge.s    .done
  241.     move.w    #1,BE_FChange(a2)
  242.     move.w    #4,BE_Frame(a2)
  243.     rts
  244. .NBlue    add.w    d1,BE_Frame(a2)
  245.     cmp.w    #8,BE_Frame(a2)
  246.     bge.s    .done
  247.     move.w    #1,BE_FChange(a2)
  248.     move.w    #8,BE_Frame(a2)
  249. .exit    rts
  250.  
  251. .Positive
  252.     cmp.w    #1,BE_Set(a2)
  253.     bgt.s    .PBlue
  254.     beq.s    .PGreen
  255. .PRed    add.w    d1,BE_Frame(a2)
  256.     cmp.w    #3,BE_Frame(a2)
  257.     ble.s    .done
  258.     move.w    #-1,BE_FChange(a2)
  259.     move.w    #2,BE_Frame(a2)
  260.     rts
  261. .PGreen    add.w    d1,BE_Frame(a2)
  262.     cmp.w    #7,BE_Frame(a2)
  263.     ble.s    .done
  264.     move.w    #-1,BE_FChange(a2)
  265.     move.w    #6,BE_Frame(a2)
  266.     rts
  267. .PBlue    add.w    d1,BE_Frame(a2)
  268.     cmp.w    #11,BE_Frame(a2)
  269.     ble.s    .done
  270.     move.w    #-1,BE_FChange(a2)
  271.     move.w    #10,BE_Frame(a2)
  272. .done    rts
  273.  
  274. ;===========================================================================;
  275. ;                                  DATA
  276. ;===========================================================================;
  277.  
  278. BOB_InitList:
  279.     dc.l    "LIST"
  280.     dc.l    BOB_Ball
  281.     dc.l    BOB_Interlaced
  282.     dc.l    LISTEND
  283.  
  284. GMS_Name:
  285.     dc.b    "games.library",0
  286.     even
  287. GMS_Base:
  288.     dc.l    0
  289.  
  290. RestoreList:
  291.     dc.l    0
  292.  
  293. Screen:    dc.l    GSV1,0    ;Structure version.
  294.     dc.l    0,0,0    ;Screen Memory 1/2/3.
  295.     dc.l    0    ;Screen link.
  296.     dc.l    0    ;Address of screen palette.
  297.     dc.l    .RasterList    ;Address of rasterlist.
  298.     dc.l    0    ;Amount of colours in palette.
  299.     dc.w    640,512    ;Screen Width and Height.
  300.     dc.w    0,0,0    ;Picture Width, ByteWidth, Height.
  301.     dc.w    0    ;Amount of planes.
  302.     dc.w    0,0    ;X/Y screen offset.
  303.     dc.w    0,0    ;X/Y picture offset.
  304.     dc.l    DBLBUFFER    ;Special attributes.
  305.     dc.w    COL12BIT|HIRES|LACED    ;Screen Mode.
  306.     dc.w    ILBM    ;Screen Type
  307.     even
  308.  
  309. .RasterList
  310.     COL12LIST 300,30,00,.ColourBar    ;Line, Skip, Colnum, ColourList.
  311.     RASTEND
  312.  
  313. .ColourBar
  314.     dc.w    $100,$200,$300,$400,$500,$600,$700
  315.     dc.w    -1
  316.  
  317. ;---------------------------------------------------------------------------;
  318.  
  319. PIC_Bobs:
  320.     dc.l    PCV1,0    ;Version header.
  321.     dc.l    0    ;Source data.
  322.     dc.w    0,0,0    ;Width, Height.
  323.     dc.w    0    ;Amount of Planes.
  324.     dc.l    0    ;Amount of colours.
  325.     dc.l    0    ;Source palette.
  326.     dc.w    LORES|COL12BIT    ;Screen mode.
  327.     dc.w    ILBM    ;Destination
  328.     dc.l    VIDEOMEM|GETPALETTE    ;Parameters.
  329.     dc.l    .File
  330. .File    dc.b    "GAMESLIB:data/IFF.HRPulse",0
  331.     even
  332.  
  333. ;---------------------------------------------------------------------------;
  334.  
  335.   STRUCTURE    NBE,BE_SIZEOF
  336.     WORD    BE_XSpeed
  337.     WORD    BE_YSpeed
  338.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  339.     WORD    BE_FChange
  340.     WORD    BE_Locked
  341.     LABEL    NBE_SIZEOF
  342.  
  343. BOB_Ball:
  344.     dc.l    MBV1,0    ;Structure version.
  345.     dc.l    0,0    ;Graphics and Mask data.
  346.     dc.w    MAX_IMAGES    ;Amount of entries.
  347.     dc.l    .Frames    ;Pointer to frame list.
  348.     dc.w    0    ;Modulo (skip in source) in bytes.
  349.     dc.w    32,32/8,16    ;Width in bytes, Height in pixels.
  350.     dc.l    Images    ;Coordinate and frame list.
  351.     dc.w    0,0    ;Border restriction LeftX,TopY.
  352.     dc.w    0,0    ;Border restrictions RightX,EndY.
  353.     dc.w    0,0    ;Amount of planes.
  354.     dc.l    0    ;Size of plane, not required.
  355.     dc.l    CLIP|GENMASKS|CLEAR|CLRNOMASK    ;Attributes.
  356.     dc.l    PIC_Bobs    ;Picture Structure (Bob Origin)
  357.     dc.w    NBE_SIZEOF    ;Entry size for images.
  358.  
  359. .Frames    dc.w    00,16*0,0,0    ;RED
  360.     dc.w    00,16*1,0,0
  361.     dc.w    00,16*2,0,0
  362.     dc.w    00,16*3,0,0
  363.     dc.w    32,16*0,0,0    ;GREEN
  364.     dc.w    32,16*1,0,0
  365.     dc.w    32,16*2,0,0
  366.     dc.w    32,16*3,0,0
  367.     dc.w    64,16*0,0,0    ;BLUE
  368.     dc.w    64,16*1,0,0
  369.     dc.w    64,16*2,0,0
  370.     dc.w    64,16*3,0,0
  371.     dc.l    -1
  372.  
  373. BOB_Interlaced:
  374.     dc.l    BBV1,0    ;Structure version.
  375.     dc.l    0,0    ;Graphics data.
  376.     dc.w    0    ;Current frame.
  377.     dc.l    .frames    ;Pointer to frame list.
  378.     dc.w    0    ;Modulo (skip in source) in bytes.
  379.     dc.w    96,0,7    ;Width, Width in bytes, Height.
  380.     dc.w    0,0    ;X/Y destination.
  381.     dc.w    0,0    ;Border restriction LeftX,TopY.
  382.     dc.w    0,0    ;Border restrictions RightX,EndY.
  383.     dc.w    0,0    ;Amount of planes.
  384.     dc.l    0    ;Size of plane, not required.
  385.     dc.l    GENMASKS    ;Attributes.
  386.     dc.l    PIC_Bobs    ;Picture struct (Bob origin).
  387. .frames    dc.w    000,16*4,0,0    ;0 X/Y Graphic, X/Y Mask
  388.     dc.l    -1
  389.  
  390.     SECTION    Images,BSS
  391.  
  392. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  393.  
  394.