Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / graphics / getsprite.c
blob5e73b30c869f3d48d29f93540087bae5c0d34d24
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function GetSprite()
6 Lang: english
7 */
8 #include <graphics/gfxbase.h>
9 #include <graphics/sprite.h>
10 #include <proto/exec.h>
11 #include "graphics_intern.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/graphics.h>
18 AROS_LH2(WORD, GetSprite,
20 /* SYNOPSIS */
21 AROS_LHA(struct SimpleSprite *, sprite, A0),
22 AROS_LHA(WORD , pick , D0),
24 /* LOCATION */
25 struct GfxBase *, GfxBase, 68, Graphics)
27 /* FUNCTION
28 Try to get a hardware sprite for the simple sprite manager.
29 There are eight sprites available in the system and by calling
30 this function you can allocate one for yourself. You have to
31 call this function before talking to other sprite routines.
32 If you want a 15 color sprite, you must allocate both sprites
33 (see the manual!) and set the SPRITE_ATTACHED bit in the
34 odd sprite's posctldata array.
37 INPUTS
38 sprite - pointer to a SimpleSprite structure
39 pick - number of the sprite (0-7) of -1 if you just want
40 the next available sprite
42 RESULT
43 -1 - if the selected sprite is not available (pick was 0-7) or
44 no further sprites are available (pick was -1). -1 will
45 also be found in the SimpleSprite structure.
46 0-7: The sprite number of your allocated sprite. The number will
47 also be found in the SimpleSprite structure.
49 NOTES
51 EXAMPLE
53 BUGS
54 On some machines this will never return anything else than -1!
56 SEE ALSO
57 FreeSprite(), ChangeSprite(), MoveSprite(), GetSprite(), graphics/sprite.h
59 INTERNALS
61 HISTORY
63 *****************************************************************************/
65 AROS_LIBFUNC_INIT
67 UBYTE SearchMask;
69 if (pick > 7 && pick != -1) {
70 pick = -1;
71 } else {
72 /* let nobody else interrupt us while we're looking for a free
73 * sprite
75 Disable();
77 if (-1 == pick) {
78 LONG Count = 0;
79 /* user just wants the next available sprite */
80 SearchMask = 0x01;
82 /* look for the first not allocated sprite */
83 while (0 != (GfxBase->SpriteReserved & SearchMask) && Count < 8) {
84 SearchMask <<= 1;
85 Count++;
88 if (8 != Count) {
89 /* we were able to allocated a free sprite */
90 /* mark the sprite as reserved for the user */
91 GfxBase->SpriteReserved |= SearchMask;
92 pick = Count;
93 } else {
94 /* no sprite was available for the user */
95 pick = -1;
98 } else {
99 /* user wants one specific sprite */
100 SearchMask = 0x01 << pick;
102 /* is that sprite still available? */
103 if (0 == (GfxBase->SpriteReserved & SearchMask) ) {
104 /* yes -> mark it as reserved for the user */
105 GfxBase->SpriteReserved |= SearchMask;
106 } else {
107 /* no, it's not available any more */
108 pick = -1;
111 Enable();
114 sprite->num = pick;
116 return pick;
117 AROS_LIBFUNC_EXIT
118 } /* GetSprite */