Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.78 KB | None | 0 0
  1. /* ssprite.c - Simple Sprite example
  2. **
  3. ** SAS/C V5.10a
  4. ** lc -b1 -cfist -v -y ssprite.c
  5. ** blink FROM LIB:c.o ssprite.o LIB LIB:lc.lib LIB:amiga.lib TO ssprite
  6. */
  7. #include <exec/types.h>
  8. #include <graphics/gfx.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/gfxmacros.h>
  11. #include <graphics/sprite.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <intuition/screens.h>
  14. #include <hardware/custom.h>
  15. #include <hardware/dmabits.h>
  16. #include <libraries/dos.h>
  17.  
  18. #include <clib/graphics_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/alib_stdio_protos.h>
  22.  
  23. #include <stdlib.h>
  24.  
  25. struct GfxBase *GfxBase = NULL;
  26. struct IntuitionBase *IntuitionBase = NULL;
  27. extern struct Custom far custom ;
  28.  
  29. /* real boring sprite data */
  30.  
  31. UWORD rgb4[32] =
  32. {
  33.     0x0000,0x0CDF,0x0424,0x0633,0x0853,0x0D72,0x0D96,0x0EB9,
  34.     0x0FE3,0x09D5,0x06B3,0x09AB,0x0463,0x0542,0x0343,0x0447,
  35.     0x0368,0x056D,0x069F,0x06CD,0x0878,0x0FFF,0x0396,0x0223,
  36.     0x0666,0x0555,0x0748,0x0A33,0x0D56,0x0D7B,0x0894,0x0873
  37. };
  38.  
  39.  UWORD chip sprite_data[] = {
  40.     0, 0,           /* position control           */
  41.     0x3ffc,0x7ffe,
  42.     0xffff,0xffff,
  43.     0xffff,0xffff,
  44.     0xffff,0x7ffe,
  45.     0x7ffe,0x3ffc,
  46.     0x1008,0x381c,
  47.     0x3c3c,0x2004,
  48.     0x1248,0x0a50,
  49.     0x3ffc,0x4002,
  50.     0x9c39,0x8001,
  51.     0xbc3d,0xe7e7,
  52.     0xbc3d,0x4002,
  53.     0x63c6,0x300c,
  54.     0x1ff8,0x27e4,
  55.     0x23c4,0x3ffc,
  56.     0x1ff8,0x0e70,
  57.     0, 0            /* reserved, must init to 0 0 */
  58.  };
  59.  
  60. VOID main(int argc, char **argv)
  61. {
  62. struct SimpleSprite    sprite = {0};
  63. struct ViewPort        *viewport;
  64.  
  65. WORD sprite_num;
  66. SHORT delta_move, ktr1, ktr2, color_reg;
  67. struct Screen *screen;
  68. int return_code;
  69.  
  70. return_code = RETURN_OK;
  71.  
  72. if (NULL == (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",37L)))
  73.     return_code = RETURN_FAIL;
  74. else
  75.     {
  76.     if (NULL == (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37L)))
  77.         return_code = RETURN_FAIL;
  78.     else
  79.         {
  80.         /* opened library, need a viewport to render a sprite over. */
  81.         if (NULL == (screen = OpenScreenTagList(NULL, NULL)))
  82.             return_code = RETURN_FAIL;
  83.         else
  84.             {
  85.             viewport = &screen->ViewPort;
  86.             if (-1 == (sprite_num = GetSprite(&sprite, 2)))
  87.                 return_code = RETURN_WARN;
  88.             else
  89.                 {
  90.                 /* Calculate the correct base color register number, */
  91.                 /* set up the color registers.                       */
  92.                 //color_reg = 16 + ((sprite_num & 0x06) << 1);
  93.                 //printf("color_reg=%d\n", color_reg);
  94.                 //SetRGB4(viewport, color_reg + 1, 12,  3,  8);
  95.                 //SetRGB4(viewport, color_reg + 2, 13, 13, 13);
  96.                 //SetRGB4(viewport, color_reg + 3,  4,  4, 15);
  97.                 LoadRGB4(viewport, &rgb4[0], 32);
  98.  
  99.  
  100.                 sprite.x = 0;       /* initialize position and size info    */
  101.                 sprite.y = 0;       /* to match that shown in sprite_data   */
  102.                 sprite.height = 16;  /* so system knows layout of data later */
  103.  
  104.                 /* install sprite data and move sprite to start position. */
  105.                 ChangeSprite(NULL, &sprite, (APTR)sprite_data);
  106.                 MoveSprite(NULL, &sprite, 30, 0);
  107.  
  108.                 /* move the sprite back and forth. */
  109.                 for ( ktr1 = 0, delta_move = 1;
  110.                       ktr1 < 6; ktr1++, delta_move = -delta_move)
  111.                     {
  112.                     for ( ktr2 = 0; ktr2 < 100; ktr2++)
  113.                         {
  114.                         MoveSprite( NULL, &sprite, (LONG)(sprite.x + delta_move),
  115.                                     (LONG)(sprite.y + delta_move) );
  116.                         WaitTOF(); /* one move per video frame */
  117.  
  118.                         /* Show the effect of turning off sprite DMA. */
  119.                         if (ktr2 == 40) OFF_SPRITE ;
  120.                         if (ktr2 == 60) ON_SPRITE ;
  121.                         }
  122.                     }
  123.                 /* NOTE:  if you turn off the sprite at the wrong time (when it
  124.                 ** is being displayed), the sprite will appear as a vertical bar
  125.                 ** on the screen.  To really get rid of the sprite, you must
  126.                 ** OFF_SPRITE while it is not displayed.  This is hard in a
  127.                 ** multi-tasking system (the solution is not addressed in
  128.                 ** this program).
  129.                 */
  130.                 ON_SPRITE ; /* just to be sure */
  131.                 FreeSprite((WORD)sprite_num);
  132.                 }
  133.             (VOID) CloseScreen(screen);
  134.             }
  135.         CloseLibrary((struct Library *)IntuitionBase);
  136.         }
  137.     CloseLibrary((struct Library *)GfxBase);
  138.     }
  139. exit(return_code);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement