Link against common native-ppc Krn code, reduces code duplication.
[AROS.git] / rom / dosboot / bootanim.c
blob5012a9f70440be9531e233f1b614175ef36ec366
1 /*
2 * This animation code draws a picture centered on the screen
3 * and flashes a specified region once per second.
4 */
6 #include <aros/debug.h>
7 #include <intuition/screens.h>
8 #include <proto/exec.h>
9 #include <proto/graphics.h>
11 #include "dosboot_intern.h"
12 #include "nomedia_image.h"
13 #include "nomedia_anim.h"
15 struct AnimData
17 UBYTE *picture;
18 UBYTE frame;
19 UWORD x;
20 UWORD y;
23 static const UBYTE *unpack_byterun1(const UBYTE *source, UBYTE *dest, LONG unpackedsize)
25 UBYTE r;
26 BYTE c;
28 for(;;)
30 c = (BYTE)(*source++);
31 if (c >= 0)
33 while(c-- >= 0)
35 *dest++ = *source++;
36 if (--unpackedsize <= 0) return source;
39 else if (c != -128)
41 c = -c;
42 r = *source++;
44 while(c-- >= 0)
46 *dest++ = r;
47 if (--unpackedsize <= 0) return source;
53 APTR anim_Init(struct Screen *scr, struct DOSBootBase *DOSBootBase)
55 D(bug("Screen: %dx%dx%d\nImage: %dx%dx%d\n",
56 scr->Width, scr->Height, scr->RastPort.BitMap->Depth,
57 NOMEDIA_WIDTH, NOMEDIA_HEIGHT, NOMEDIA_PLANES));
58 if ((scr->Width >= NOMEDIA_WIDTH) && (scr->Height >= NOMEDIA_HEIGHT) &&
59 (scr->RastPort.BitMap->Depth >= NOMEDIA_PLANES))
61 struct AnimData *ad = AllocMem(sizeof(struct AnimData), MEMF_ANY);
62 ULONG size = NOMEDIA_WIDTH * NOMEDIA_HEIGHT;
64 if (ad)
66 ad->picture = AllocVec(size, MEMF_ANY);
68 if (ad->picture)
70 ULONG i;
72 unpack_byterun1(nomedia_data, ad->picture, size);
74 for (i = 0; i < NOMEDIA_COLORS; i++)
75 SetRGB32(&scr->ViewPort, i, (nomedia_pal[i] << 8) & 0xFF000000,
76 (nomedia_pal[i] << 16) & 0xFF000000, (nomedia_pal[i] << 24) & 0xFF000000);
78 SetAPen(&scr->RastPort, 0);
79 RectFill(&scr->RastPort, 0, 0, scr->Width, scr->Height);
81 ad->x = (scr->Width - NOMEDIA_WIDTH ) >> 1;
82 ad->y = (scr->Height - NOMEDIA_HEIGHT) >> 1;
83 WriteChunkyPixels(&scr->RastPort, ad->x, ad->y, ad->x + NOMEDIA_WIDTH - 1, ad->y + NOMEDIA_HEIGHT - 1,
84 ad->picture, NOMEDIA_WIDTH);
86 ad->frame = 0;
87 DOSBootBase->animData = ad;
88 DOSBootBase->delayTicks = 25; /* We run at 2 frames per second */
89 return ad;
91 FreeMem(ad, sizeof(struct AnimData));
94 return NULL;
97 void anim_Animate(struct Screen *scr, struct DOSBootBase *DOSBootBase)
99 struct AnimData *ad = DOSBootBase->animData;
101 ad->frame = !ad->frame;
102 if (ad->frame)
103 RectFill(&scr->RastPort, ad->x + FLASH_X, ad->y + FLASH_Y,
104 ad->x + FLASH_X + FLASH_WIDTH - 1, ad->y + FLASH_Y + FLASH_HEIGHT - 1);
105 else
107 WriteChunkyPixels(&scr->RastPort, ad->x + FLASH_X, ad->y + FLASH_Y,
108 ad->x + FLASH_X + FLASH_WIDTH - 1, ad->y + FLASH_Y + FLASH_HEIGHT - 1,
109 ad->picture + FLASH_X, NOMEDIA_WIDTH);
113 void anim_Stop(struct DOSBootBase *DOSBootBase)
115 struct AnimData *ad = DOSBootBase->animData;
117 if (ad)
119 FreeVec(ad->picture);
120 FreeMem(ad, sizeof(struct AnimData));
122 DOSBootBase->animData = NULL;