Fix for initialization of scalos preferences library. Library is now loaded only...
[AROS-Contrib.git] / Games / Bomber / BomberSprites.c
blobc2e660b115de706dc66cc90edb820e7978187b52
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 RGBPal [256][3];
36 #if 0
37 unsigned char Pixel;
38 int DAC, o1, o2;
39 #endif
40 char *RawBuf;
42 //Assign memory to sprite buffer
43 RawBuf = (char *)malloc (64000);
45 //Load graphics data from file
46 SSFFile = fopen ("Bomber1.ssf", "rb");
47 fread (RawBuf, 7, 1, SSFFile);
48 fread (RawBuf, 320, 200, SSFFile);
49 fread (RGBPal, 3, 256, SSFFile);
50 fclose (SSFFile);
52 BlocksBuf = RawBuf;
54 #if 0
55 //Convert palette
56 for (DAC = 0; DAC < 256; DAC++) {
57 RGBPal [DAC][0] <<= 2;
58 RGBPal [DAC][1] <<= 2;
59 RGBPal [DAC][2] <<= 2;
60 Palette [DAC] = (RGBPal [DAC][0]) +
61 (RGBPal [DAC][1] << 8) +
62 (RGBPal [DAC][2] << 16);
65 //Save as 24bit data
66 o2 = 0;
67 for (o1 = 0; o1 < 64000; o1++) {
68 Pixel = RawBuf [o1];
69 BlocksBuf [o2++] = RGBPal [Pixel][2];
70 BlocksBuf [o2++] = RGBPal [Pixel][1];
71 BlocksBuf [o2++] = RGBPal [Pixel][0];
73 #endif
76 //This reads a pixel from the sprite buffer
77 unsigned char _ReadPixel (int x, int y)
79 return SpriteBuf [(y << 8) + (y << 6) + x];
82 void Blit (int x, int y, int x1, int y1, int w, int h)
84 int yt;
86 #if 0
87 x *= 3;
88 x1 *= 3;
89 w *= 3;
90 #endif
92 //Do blits
93 for (yt = 0; yt < h; yt++)
94 memcpy ((char *)TargetData + (y + yt) * WIDTH + x,
95 (char *)BlocksBuf + (y1 + yt) * 320 + x1,
96 w);
100 //This draws a sprite onto the device context
101 void DrawBlock (int x, int y, int x1, int y1)
103 int yt;
105 //Convert coordinates
106 x *= 16;
107 y *= 16;
108 x1 *= 16;
109 y1 *= 16;
111 //Draw each pixel
112 for (yt = 0; yt < 16; yt++)
113 memcpy ((char *)TargetData + (y + yt) * WIDTH + x,
114 (char *)BlocksBuf + (y1 + yt) * 320 + x1,
115 16);
118 //This draws a transparent sprite onto the device context
119 void DrawTSprite (int x, int y, int x1, int y1, int xs, int ys)
121 int xt, yt;
122 unsigned char c;
124 for (xt = 0; xt < xs; xt++) for (yt = 0; yt < ys; yt++) {
125 c = _ReadPixel (x1 + xt, y1 + yt);
126 if (c) MainBitmapData[(y + yt) * WIDTH + x + xt] = c;