home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Blitter / BlitWorm.s < prev    next >
Encoding:
Text File  |  1997-02-11  |  6.8 KB  |  310 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;BOB example
  3. ;-----------
  4. ;This example blits a Worm from an IFF file onto a double buffered screen.
  5. ;The RESTORE mode is used to put the background back.
  6.  
  7.     INCDIR    "INCLUDES:"
  8.     INCLUDE    "exec/exec_lib.i"
  9.     INCLUDE    "games/games_lib.i"
  10.     INCLUDE    "games/games.i"
  11.  
  12. CALL    MACRO
  13.     jsr    _LVO\1(a6)
  14.     ENDM
  15.  
  16.     SECTION    "BOB",CODE
  17.  
  18. ;===========================================================================;
  19. ;                             INITIALISE DEMO
  20. ;===========================================================================;
  21.  
  22. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  23.     move.l    ($4).w,a6
  24.     lea    GMS_Name(pc),a1
  25.     moveq    #$00,d0
  26.     CALL    OpenLibrary
  27.     move.l    d0,GMS_Base
  28.     beq    .Error_GMS
  29.  
  30.     move.l    GMS_Base(pc),a6    ;Activate user preferences.
  31.     sub.l    a0,a0
  32.     CALL    SetUserPrefs
  33.  
  34.     CALL    AllocBlitter    ;Allocate the blitter.
  35.     tst.w    d0
  36.     bne    .Error_Blitter
  37.  
  38.     CALL    AllocAudio    ;Allocate the audio channels.
  39.     tst.w    d0
  40.     bne    .Error_Audio
  41.  
  42.     lea    Screen(pc),a0    ;Initialise the screen.
  43.     CALL    AddScreen
  44.     tst.w    d0
  45.     bne    .Error_Screen
  46.  
  47. ;---------------------------------------------------------------------------;
  48. ;Load a picture into the background of the screen.
  49.  
  50.     lea    PIC_Background(pc),a1    ;Load the picture.
  51.     move.l    GS_MemPtr2(a0),PIC_Data(a1)
  52.     CALL    LoadPic
  53.     tst.w    d0
  54.     bne    .Error_Picture
  55.  
  56.     move.l    PIC_Palette(a1),GS_Palette(a0)
  57.     CALL    UpdatePalette
  58.  
  59.     lea    Screen(pc),a0
  60.     CALL    SwapBuffers
  61.     moveq    #BUFFER1,d0
  62.     moveq    #BUFFER2,d1
  63.     CALL    CopyBuffer
  64.  
  65. ;---------------------------------------------------------------------------;
  66. ;Initialise the restorelist.
  67.  
  68.     moveq    #2,d0    ;2 buffers.
  69.     moveq    #1,d1    ;1 BOB Entry.
  70.     CALL    InitRestore
  71.     move.l    d0,RestoreList
  72.     beq.s    .Error_RestoreList
  73.  
  74. ;---------------------------------------------------------------------------;
  75. ;Load the BOB file in.  This contains the graphics data that we are
  76. ;going to draw to the screen.
  77.  
  78.     lea    PIC_Bobs(pc),a1    ;Load the picture that contains
  79.     CALL    LoadPic    ;our BOB.
  80.     tst.w    d0
  81.     bne.s    .Error_BOBPic
  82.  
  83.     lea    Screen(pc),a0    ;Initialise the BOB so that it is
  84.     lea    BOB_Rambo(pc),a1    ;ready for drawing.
  85.     CALL    InitBOB
  86.     tst.w    d0
  87.     bne.s    .Error_BOB
  88.  
  89.     lea    SND_Rambo(pc),a0
  90.     CALL    InitSound
  91.     tst.w    d0
  92.     bne.s    .Error_Sound
  93.  
  94.     lea    Screen(pc),a0
  95.     CALL    ShowScreen
  96.  
  97.     bsr.s    Main
  98.  
  99. .ReturnToDOS
  100.     move.l    GMS_Base(pc),a6
  101.     lea    SND_Rambo(pc),a0
  102.     CALL    FreeSound
  103. .Error_Sound
  104.     lea    BOB_Rambo(pc),a1
  105.     CALL    FreeBOB
  106. .Error_BOB
  107.     lea    PIC_Bobs(pc),a1
  108.     CALL    FreePic
  109. .Error_BOBPic
  110.     move.l    RestoreList(pc),d0
  111.     CALL    FreeRestore
  112. .Error_RestoreList
  113.     lea    PIC_Background(pc),a1
  114.     CALL    FreePic
  115. .Error_Picture
  116.     lea    Screen(pc),a0
  117.     CALL    DeleteScreen
  118. .Error_Screen
  119.     CALL    FreeAudio
  120. .Error_Audio
  121.     CALL    FreeBlitter
  122. .Error_Blitter
  123.     move.l    GMS_Base(pc),a1
  124.     move.l    ($4).w,a6
  125.     CALL    CloseLibrary
  126. .Error_GMS
  127.     MOVEM.L    (SP)+,A0-A6/D1-D7
  128.     moveq    #$00,d0
  129.     rts
  130.  
  131. ;===========================================================================;
  132. ;                                MAIN LOOP
  133. ;===========================================================================;
  134.  
  135. SPEED    =    5
  136. FIRESPEED =    1
  137.  
  138. Main:    move.l    GMS_Base(pc),a6
  139.     CALL    InitJoyPorts
  140.     moveq    #$00,d7
  141.  
  142. .Loop    lea    Screen(pc),a0
  143.     move.l    RestoreList(pc),a1
  144.     CALL    Restore
  145.  
  146.     lea    BOB_Rambo(pc),a1
  147.     move.l    RestoreList(pc),a2
  148.     move.w    #BUFFER2,d0
  149.     CALL    DrawBOB    ;Blit the bob.
  150.     CALL    WaitSVBL    ;Wait for VBL.
  151.     CALL    SwapBuffers
  152.     addq.w    #1,d7
  153.  
  154.     tst.b    FireState
  155.     bne.s    .FireOn
  156.  
  157.     cmp.w    #SPEED,d7
  158.     ble.s    .Move
  159.     moveq    #$00,d7
  160.     addq.w    #1,BOB_Frame(a1)
  161.     cmp.w    #9,BOB_Frame(a1)
  162.     blt.s    .Move
  163.     clr.w    BOB_Frame(a1)
  164.     bra.s    .Move
  165.  
  166. .FireOn    cmp.w    #FIRESPEED,d7
  167.     ble.s    .Move
  168.     moveq    #$00,d7
  169.     cmp.w    #10,BOB_Frame(a1)
  170.     bge.s    .On
  171.     move.w    #9,BOB_Frame(a1)
  172.  
  173. .On    addq.w    #1,BOB_Frame(a1)
  174.     cmp.w    #13,BOB_Frame(a1)
  175.     blt.s    .Move
  176.  
  177.     lea    SND_Rambo(pc),a0
  178.     CALL    PlaySound
  179.  
  180.     btst    #MB_LMB,d0
  181.     beq.s    .Off
  182.     move.w    #11,BOB_Frame(a1)
  183.     bra.s    .Move
  184.  
  185. .Off    clr.w    BOB_Frame(a1)
  186.     clr.b    FireState
  187.  
  188. .Move    moveq    #JPORT1,d0    ;Read the mouse, then update the
  189.     moveq    #JT_ZBXY,d1    ;BOB's X and Y co-ordinates.
  190.     CALL    ReadJoyPort
  191.     move.w    d0,d1
  192.     ext.w    d0
  193.     add.w    d0,BOB_YPos(a1)
  194.     asr.w    #8,d1
  195.     add.w    d1,BOB_XPos(a1)
  196.  
  197.     btst    #MB_LMB,d0
  198.     beq.s    .chkRMB
  199.     st    FireState    ;Set fire to on.
  200. .chkRMB    btst    #MB_RMB,d0
  201.     beq    .Loop
  202.     rts
  203.  
  204. FireState:
  205.     dc.b    0
  206.     even
  207.  
  208. ;===========================================================================;
  209. ;                                  DATA
  210. ;===========================================================================;
  211.  
  212. GMS_Name:     dc.b  "games.library",0
  213.           even
  214. GMS_Base:     dc.l  0
  215. RestoreList:  dc.l  0
  216.  
  217. AMT_PLANES =    5
  218.  
  219. Screen:    dc.l    GSV1,0    ;Version header.
  220.     dc.l    0,0,0    ;Screen memory 1/2/3.
  221.     dc.l    0    ;Screen link.
  222.     dc.l    0    ;Address of screen palette.
  223.     dc.l    0    ;Address of rasterlist.
  224.     dc.l    0    ;Amount of colours in palette.
  225.     dc.w    320,256    ;Screen Width and Height.
  226.     dc.w    320,320/8,256    ;Picture Width and Height.
  227.     dc.w    AMT_PLANES    ;Amount of planes.
  228.     dc.w    0,0    ;X/Y screen offset.
  229.     dc.w    0,0    ;X/Y picture offset.
  230.     dc.l    DBLBUFFER    ;Special attributes.
  231.     dc.w    LORES|COL12BIT    ;Screen Mode.
  232.     dc.w    PLANAR    ;Screen Type
  233.     even
  234.  
  235. PIC_Background:
  236.     dc.l    PCV1,0    ;Version header.
  237.     dc.l    0    ;Source data.
  238.     dc.w    320,320/8,256    ;Width, Height.
  239.     dc.w    AMT_PLANES    ;Amount of Planes.
  240.     dc.l    0    ;Amount of colours.
  241.     dc.l    0    ;Source palette (remap).
  242.     dc.w    LORES|COL12BIT    ;Screen mode.
  243.     dc.w    PLANAR    ;Destination
  244.     dc.l    GETPALETTE    ;Parameters.
  245.     dc.l    .File
  246. .File    dc.b    "GAMESLIB:data/IFF.Pic320",0
  247.     even
  248.  
  249. ;---------------------------------------------------------------------------;
  250.  
  251. PIC_Bobs:
  252.     dc.l    PCV1,0    ;Version header.
  253.     dc.l    0    ;Source data.
  254.     dc.w    0,0,0    ;Width, Height.
  255.     dc.w    AMT_PLANES    ;Amount of Planes.
  256.     dc.l    0    ;Amount of colours.
  257.     dc.l    0    ;Source palette.
  258.     dc.w    LORES|COL12BIT    ;Screen mode.
  259.     dc.w    PLANAR    ;Destination
  260.     dc.l    BLITMEM    ;Parameters.
  261.     dc.l    .File
  262. .File    dc.b    "GAMESLIB:data/IFF.Rambo",0
  263.     even
  264.  
  265. BOB_Rambo:
  266.     dc.l    BBV1,0    ;Structure version.
  267.     dc.l    0,0    ;Graphics data.
  268.     dc.w    0    ;Current frame.
  269.     dc.l    .Frames    ;Pointer to frame list.
  270.     dc.w    0    ;Modulo (skip in source) in bytes.
  271.     dc.w    32,0,24    ;Width, Width in bytes, Height.
  272.     dc.w    150,150    ;X/Y destination.
  273.     dc.w    32,32    ;Border restriction LeftX,TopY.
  274.     dc.w    320-32,256-32    ;Border restrictions RightX,EndY.
  275.     dc.w    0,0    ;Amount of planes.
  276.     dc.l    0    ;Size of plane, not required.
  277.     dc.l    GENMASKS|CLIP|RESTORE    ;Attributes.
  278.     dc.l    PIC_Bobs    ;Picture struct (Bob origin).
  279. .Frames    dc.w    000,000,0,0    ;0 X/Y Graphic, X/Y Mask
  280.     dc.w    032,000,0,0    ;1 ...
  281.     dc.w    064,000,0,0    ;2
  282.     dc.w    096,000,0,0    ;3
  283.     dc.w    128,000,0,0    ;4
  284.     dc.w    160,000,0,0    ;5
  285.     dc.w    192,000,0,0    ;6
  286.     dc.w    224,000,0,0    ;7
  287.     dc.w    256,000,0,0    ;8
  288.     dc.w    288,000,0,0    ;9
  289.     dc.w    000,048,0,0    ;10
  290.     dc.w    032,048,0,0    ;11
  291.     dc.w    064,048,0,0    ;12
  292.     dc.l    -1
  293.  
  294. SND_Rambo:
  295.     dc.l    SMV1,0    ;Structure version.
  296.     dc.w    CHANNEL1    ;Channel to play through.
  297.     dc.w    0    ;Priority.
  298.     dc.l    0    ;Sample header
  299.     dc.l    0    ;Sample address.
  300.     dc.l    0    ;Sample length.
  301.     dc.w    OCT_C2S    ;Sample period.
  302.     dc.w    100    ;Sample volume.
  303.     dc.l    0    ;Sound attributes.
  304.     dc.l    .File    ;Sound file.
  305. .File    dc.b    "GAMESLIB:data/SND.Rambo",0
  306.     even
  307.  
  308. ;---------------------------------------------------------------------------;
  309.  
  310.