Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ssprite.c - Simple Sprite example
- **
- ** SAS/C V5.10a
- ** lc -b1 -cfist -v -y ssprite.c
- ** blink FROM LIB:c.o ssprite.o LIB LIB:lc.lib LIB:amiga.lib TO ssprite
- */
- #include <exec/types.h>
- #include <graphics/gfx.h>
- #include <graphics/gfxbase.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/sprite.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/screens.h>
- #include <hardware/custom.h>
- #include <hardware/dmabits.h>
- #include <libraries/dos.h>
- #include <clib/graphics_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/alib_stdio_protos.h>
- #include <stdlib.h>
- struct GfxBase *GfxBase = NULL;
- struct IntuitionBase *IntuitionBase = NULL;
- extern struct Custom far custom ;
- /* real boring sprite data */
- UWORD rgb4[32] =
- {
- 0x0000,0x0CDF,0x0424,0x0633,0x0853,0x0D72,0x0D96,0x0EB9,
- 0x0FE3,0x09D5,0x06B3,0x09AB,0x0463,0x0542,0x0343,0x0447,
- 0x0368,0x056D,0x069F,0x06CD,0x0878,0x0FFF,0x0396,0x0223,
- 0x0666,0x0555,0x0748,0x0A33,0x0D56,0x0D7B,0x0894,0x0873
- };
- UWORD chip sprite_data[] = {
- 0, 0, /* position control */
- 0x3ffc,0x7ffe,
- 0xffff,0xffff,
- 0xffff,0xffff,
- 0xffff,0x7ffe,
- 0x7ffe,0x3ffc,
- 0x1008,0x381c,
- 0x3c3c,0x2004,
- 0x1248,0x0a50,
- 0x3ffc,0x4002,
- 0x9c39,0x8001,
- 0xbc3d,0xe7e7,
- 0xbc3d,0x4002,
- 0x63c6,0x300c,
- 0x1ff8,0x27e4,
- 0x23c4,0x3ffc,
- 0x1ff8,0x0e70,
- 0, 0 /* reserved, must init to 0 0 */
- };
- VOID main(int argc, char **argv)
- {
- struct SimpleSprite sprite = {0};
- struct ViewPort *viewport;
- WORD sprite_num;
- SHORT delta_move, ktr1, ktr2, color_reg;
- struct Screen *screen;
- int return_code;
- return_code = RETURN_OK;
- if (NULL == (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",37L)))
- return_code = RETURN_FAIL;
- else
- {
- if (NULL == (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37L)))
- return_code = RETURN_FAIL;
- else
- {
- /* opened library, need a viewport to render a sprite over. */
- if (NULL == (screen = OpenScreenTagList(NULL, NULL)))
- return_code = RETURN_FAIL;
- else
- {
- viewport = &screen->ViewPort;
- if (-1 == (sprite_num = GetSprite(&sprite, 2)))
- return_code = RETURN_WARN;
- else
- {
- /* Calculate the correct base color register number, */
- /* set up the color registers. */
- //color_reg = 16 + ((sprite_num & 0x06) << 1);
- //printf("color_reg=%d\n", color_reg);
- //SetRGB4(viewport, color_reg + 1, 12, 3, 8);
- //SetRGB4(viewport, color_reg + 2, 13, 13, 13);
- //SetRGB4(viewport, color_reg + 3, 4, 4, 15);
- LoadRGB4(viewport, &rgb4[0], 32);
- sprite.x = 0; /* initialize position and size info */
- sprite.y = 0; /* to match that shown in sprite_data */
- sprite.height = 16; /* so system knows layout of data later */
- /* install sprite data and move sprite to start position. */
- ChangeSprite(NULL, &sprite, (APTR)sprite_data);
- MoveSprite(NULL, &sprite, 30, 0);
- /* move the sprite back and forth. */
- for ( ktr1 = 0, delta_move = 1;
- ktr1 < 6; ktr1++, delta_move = -delta_move)
- {
- for ( ktr2 = 0; ktr2 < 100; ktr2++)
- {
- MoveSprite( NULL, &sprite, (LONG)(sprite.x + delta_move),
- (LONG)(sprite.y + delta_move) );
- WaitTOF(); /* one move per video frame */
- /* Show the effect of turning off sprite DMA. */
- if (ktr2 == 40) OFF_SPRITE ;
- if (ktr2 == 60) ON_SPRITE ;
- }
- }
- /* NOTE: if you turn off the sprite at the wrong time (when it
- ** is being displayed), the sprite will appear as a vertical bar
- ** on the screen. To really get rid of the sprite, you must
- ** OFF_SPRITE while it is not displayed. This is hard in a
- ** multi-tasking system (the solution is not addressed in
- ** this program).
- */
- ON_SPRITE ; /* just to be sure */
- FreeSprite((WORD)sprite_num);
- }
- (VOID) CloseScreen(screen);
- }
- CloseLibrary((struct Library *)IntuitionBase);
- }
- CloseLibrary((struct Library *)GfxBase);
- }
- exit(return_code);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement