home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Sprites / Sprites.s < prev   
Encoding:
Text File  |  1997-02-16  |  4.1 KB  |  156 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Sprite example
  3. ;--------------
  4. ;This example shows you how to set up a 16 colour OCS sprite with a doubled
  5. ;X axis (32 pixels width).  Those with hardware experience will know that it
  6. ;takes 4 sprite banks to do this successfully in OCS, which leaves you with
  7. ;another 4 banks to do with what you will.
  8. ;
  9. ;Notice that the screen is only 1 bitplane large, even though the sprite is
  10. ;16 colours.  This is because the sprite is independent of the screen
  11. ;bitmap.  You can access colours not in the screen by setting up a large
  12. ;palette and specifying the amount of colours in GS_AmtColours (in this
  13. ;case, we set 32 colours to access the sprite colour bank).
  14. ;
  15. ;Try moving the sprite around a bit with the mouse.  The LMB exits the demo.
  16.  
  17.     INCDIR    "INCLUDES:"
  18.     INCLUDE    "exec/exec_lib.i"
  19.     INCLUDE    "games/games_lib.i"
  20.     INCLUDE    "games/games.i"
  21.  
  22. CALL    MACRO
  23.     jsr    _LVO\1(a6)
  24.     ENDM
  25.  
  26.     SECTION    "Sprites",CODE
  27.  
  28. ;===========================================================================;
  29. ;                             INITIALISE DEMO
  30. ;===========================================================================;
  31.  
  32. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  33.     move.l    ($4).w,a6
  34.     lea    GMS_Name(pc),a1
  35.     moveq    #$00,d0
  36.     CALL    OpenLibrary
  37.     move.l    d0,GMS_Base
  38.     beq.s    .Error_GMS
  39.  
  40.     move.l    GMS_Base(pc),a6
  41.     sub.l    a0,a0
  42.     CALL    SetUserPrefs
  43.  
  44.     lea    Screen(pc),a0
  45.     CALL    AddScreen
  46.     tst.l    d0
  47.     bne.s    .Error_Screen
  48.  
  49.     lea    Sparkie(pc),a1
  50.     CALL    InitSprite
  51.     tst.l    d0
  52.     bne.s    .Error_Sparkie
  53.  
  54.     CALL    ShowScreen
  55.  
  56.     bsr.s    Main
  57.  
  58. .ReturnToDOS
  59.     move.l    GMS_Base(pc),a6
  60.     lea    Sparkie(pc),a1
  61.     CALL    FreeSprite
  62. .Error_Sparkie
  63.     lea    Screen(pc),a0
  64.     CALL    DeleteScreen
  65. .Error_Screen
  66.     move.l    GMS_Base(pc),a1
  67.     move.l    ($4).w,a6
  68.     CALL    CloseLibrary
  69. .Error_GMS
  70.     MOVEM.L    (SP)+,A0-A6/D1-D7
  71.     moveq    #$00,d0
  72.     rts
  73.  
  74. ;===========================================================================;
  75. ;                                MAIN LOOP
  76. ;===========================================================================;
  77.  
  78. Main:    move.l    GMS_Base(pc),a6
  79.     CALL    InitJoyPorts    ;Initialise ports.
  80. .loop    addq.w    #1,d7    ;Animation/Frame delay, so that
  81.     btst    #0,d7    ; our anim does not run too fast!
  82.     beq.s    .Mouse
  83.     cmp.w    #5,SPR_Frame(a1)    ;Do the animation for the sprite.
  84.     beq.s    .reset    ;(simply by increasing the frame
  85.     addq.w    #1,SPR_Frame(a1)    ; number).
  86.     bra.s    .Mouse
  87. .reset    clr.w    SPR_Frame(a1)
  88.  
  89. .Mouse    moveq    #JPORT1,d0    ;Read from port 1
  90.     CALL    ReadMouse    ;Go get mouse position.
  91.     move.w    d0,d1
  92.     asr.w    #8,d0
  93.     add.w    d0,SPR_XPos(a1)
  94.     ext.w    d1
  95.     add.w    d1,SPR_YPos(a1)
  96.     CALL    WaitSVBL    ;Wait for a VBL.
  97.     CALL    UpdateSprite    ;Put Sparkie on the screen.
  98.     btst    #MB_LMB,d0
  99.     beq.s    .loop
  100.     rts
  101.  
  102. ;===========================================================================;
  103. ;                                  DATA
  104. ;===========================================================================;
  105.  
  106. GMS_Name:
  107.     dc.b    "games.library",0
  108.     even
  109. GMS_Base:
  110.     dc.l    0
  111.  
  112. Sparkie    dc.l    SPV1,0    ;Structure version.
  113.     dc.w    0    ;Number 0.
  114.     dc.l    Gfx_Sparkie    ;Pointer to graphic.
  115.     dc.w    100,100    ;Beginning X/Y position
  116.     dc.w    0    ;Current frame.
  117.     dc.w    16,21    ;Width, Height.
  118.     dc.w    16    ;Amount of colours.
  119.     dc.w    16    ;Colour start in palette.
  120.     dc.w    2    ;Amount of planes.
  121.     dc.w    LORES    ;Resolution.
  122.     dc.w    0    ;PlayField position.
  123.     dc.w    XLONG    ;Special attributes.
  124.  
  125. AMT_PLANES =    1
  126.  
  127. Screen:    dc.l    GSV1,0
  128.     dc.l    0,0,0    ;Screen Memory 1/2/3.
  129.     dc.l    0    ;Screen link.
  130.     dc.l    .Palette    ;Address of the screen palette.
  131.     dc.l    0    ;Address of a ColourList.
  132.     dc.l    32    ;Amount of colours in the palette.
  133.     dc.w    320,256    ;Screen Width and Height.
  134.     dc.w    0,0,0    ;Picture Widths and Height.
  135.     dc.w    AMT_PLANES    ;Amount of planes.
  136.     dc.w    0,0    ;X/Y Screen offset.
  137.     dc.w    0,0    ;X/Y Picture offset.
  138.     dc.l    SPRITES|NOSCRBDR    ;Special attributes.
  139.     dc.w    LORES|COL12BIT    ;Screen mode.
  140.     dc.w    ILBM    ;Screen type
  141.  
  142. .Palette
  143.     dc.w    $000,$000,$000,$000,$000,$000,$000,$000
  144.     dc.w    $000,$688,$466,$344,$CC0,$980,$870,$650
  145.     dc.w    $1C2,$050,$B0B,$606,$F20,$910,$BBB,$FFF
  146.     dc.w    $0BF,$068,$568,$9BF,$FF0,$EE0,$BA0,$540
  147.  
  148. ;===========================================================================;
  149. ;                         ALL CHIP RAM DATA HERE
  150. ;===========================================================================;
  151.  
  152.     SECTION    "Graphics",DATA_C
  153.  
  154. Gfx_Sparkie:
  155.     INCBIN    "GAMESLIB:data/Sparkie.raw"
  156.