Avoid doing OpenDevice on a handler.
[AROS-Contrib.git] / Games / Bomber / BomberSprites.c
blobc07786510e70aa0f5fb7f505c68532332dd186eb
1 #include <string.h> /* memset() */
3 //Load the sprites
4 void LoadSprites ()
6 FILE *SSFFile;
7 unsigned char RGBPal [256][3];
8 int DAC;
10 //Assign memory to sprite buffer
11 SpriteBuf = (char *)malloc (64000);
13 //Load graphics data from file
14 SSFFile = fopen ("Bomber0.ssf", "rb");
15 fread (SpriteBuf, 7, 1, SSFFile);
16 fread (SpriteBuf, 320, 200, SSFFile);
17 fread (RGBPal, 3, 256, SSFFile);
18 fclose (SSFFile);
20 //Convert palette
21 for (DAC = 0; DAC < 256; DAC++) {
22 RGBPal [DAC][0] <<= 2;
23 RGBPal [DAC][1] <<= 2;
24 RGBPal [DAC][2] <<= 2;
25 Palette [DAC] = (RGBPal [DAC][2]) +
26 (RGBPal [DAC][1] << 8) +
27 (RGBPal [DAC][0] << 16);
31 //Load the sprites
32 void LoadBlocks ()
34 FILE *SSFFile;
35 unsigned char Pixel;
36 unsigned char RGBPal [256][3];
37 int DAC, o1, o2;
38 char *RawBuf;
40 //Assign memory to sprite buffer
41 RawBuf = (char *)malloc (64000);
43 //Load graphics data from file
44 SSFFile = fopen ("Bomber1.ssf", "rb");
45 fread (RawBuf, 7, 1, SSFFile);
46 fread (RawBuf, 320, 200, SSFFile);
47 fread (RGBPal, 3, 256, SSFFile);
48 fclose (SSFFile);
50 BlocksBuf = RawBuf;
52 #if 0
53 //Convert palette
54 for (DAC = 0; DAC < 256; DAC++) {
55 RGBPal [DAC][0] <<= 2;
56 RGBPal [DAC][1] <<= 2;
57 RGBPal [DAC][2] <<= 2;
58 Palette [DAC] = (RGBPal [DAC][0]) +
59 (RGBPal [DAC][1] << 8) +
60 (RGBPal [DAC][2] << 16);
63 //Save as 24bit data
64 o2 = 0;
65 for (o1 = 0; o1 < 64000; o1++) {
66 Pixel = RawBuf [o1];
67 BlocksBuf [o2++] = RGBPal [Pixel][2];
68 BlocksBuf [o2++] = RGBPal [Pixel][1];
69 BlocksBuf [o2++] = RGBPal [Pixel][0];
71 #endif
74 //This reads a pixel from the sprite buffer
75 unsigned char _ReadPixel (int x, int y)
77 return SpriteBuf [(y << 8) + (y << 6) + x];
80 void Blit (int x, int y, int x1, int y1, int w, int h)
82 int yt;
84 #if 0
85 x *= 3;
86 x1 *= 3;
87 w *= 3;
88 #endif
90 //Do blits
91 for (yt = 0; yt < h; yt++)
92 memcpy ((char *)TargetData + (y + yt) * WIDTH + x,
93 (char *)BlocksBuf + (y1 + yt) * 320 + x1,
94 w);
98 //This draws a sprite onto the device context
99 void DrawBlock (int x, int y, int x1, int y1)
101 int yt;
103 //Convert coordinates
104 x *= 16;
105 y *= 16;
106 x1 *= 16;
107 y1 *= 16;
109 //Draw each pixel
110 for (yt = 0; yt < 16; yt++)
111 memcpy ((char *)TargetData + (y + yt) * WIDTH + x,
112 (char *)BlocksBuf + (y1 + yt) * 320 + x1,
113 16);
116 //This draws a transparent sprite onto the device context
117 void DrawTSprite (int x, int y, int x1, int y1, int xs, int ys)
119 int xt, yt;
120 unsigned char c;
122 for (xt = 0; xt < xs; xt++) for (yt = 0; yt < ys; yt++) {
123 c = _ReadPixel (x1 + xt, y1 + yt);
124 if (c) MainBitmapData[(y + yt) * WIDTH + x + xt] = c;