home *** CD-ROM | disk | FTP | other *** search
- #include "manic.h"
- #include "functions.h"
- #include "gfxdata/gfxdata.h"
- #include "gfxlibs/gfx.h"
- #include "sndlibs/snd.h"
- #include <string.h>
-
-
- /* In the RISC OS version, some of the routines below are in ARM assembler.
- * So we *don't* want to define them here!
- */
-
-
- static void DrawSun (void);
-
-
- int
- PaletteFade (const unsigned char *pal1, unsigned char *pal2)
- {
- int count = 768, changed = 0;
-
- while (--count >= 0) {
- if (*pal1 != *pal2) {
- changed = 1;
- if (*pal1 > *pal2)
- *pal2 += 1;
- else
- *pal2 -= 1;
- }
- pal1++;
- pal2++;
- }
- return changed;
- }
-
- /* ////////////////////////////////////////////////////////////
- // Rotate end of palette
- //////////////////////////////////////////////////////////// */
- void
- RotPal (void)
- {
- BYTE temp1, temp2, temp3;
-
- temp1 = PALover[720];
- temp2 = PALover[721];
- temp3 = PALover[722];
- memmove (&PALover[720], &PALover[723], 42);
- PALover[762] = temp1;
- PALover[763] = temp2;
- PALover[764] = temp3;
- }
-
- /* ////////////////////////////////////////////////////////////
- // Print Text
- //////////////////////////////////////////////////////////// */
- void
- FontPrint (int xpos, int ypos, const char * text)
- {
- int count = 0, count2, count3;
- int currentx, currenty;
- int alpha;
- const BYTE *fonty;
-
- currentx = ((xpos & 127) * 8) | ((xpos & 128) ? 4 : 0);
- currenty = ((ypos & 127) * 8) | ((ypos & 128) ? 4 : 0);
-
- while (*text) {
- alpha = (int) *text++;
- while (alpha == 170) {
- currentx = 0;
- currenty += 8;
- alpha = (int) *text++;
- }
- alpha -= 32;
- if (++count == 33)
- return;
- fonty = fontb + alpha * 8;
-
- ypos = currenty;
- for (count2 = 0; count2 < 8; count2++) {
- xpos = currentx;
- for (count3 = 0; count3 < 8; count3++) {
- mm_gfx_putpixel (xpos++, ypos, (*fonty & 1 << count3) ? INK : PAPER);
- }
- fonty++;
- ypos++;
- }
- mm_gfx_setdirty (currentx, currenty, 7, 7);
- currentx += 8;
- }
- }
-
- /* ////////////////////////////////////////////////////////////
- // Print Text
- //////////////////////////////////////////////////////////// */
- void
- FontPrint2 (int xpos, int ypos, const char * text)
- {
- int count = 0, count2, count3;
- int currentx, currenty;
- int alpha;
- const BYTE *fonty, *fonty2;
-
- currentx = ((xpos & 127) * 8) | ((xpos & 128) ? 4 : 0);
- currenty = ((ypos & 127) * 8) | ((ypos & 128) ? 4 : 0);
-
- while (*text) {
- alpha = (int) *text++;
- if (alpha == 170) {
- currentx = 0;
- currenty += 8;
- alpha = (int) *text++;
- }
- alpha -= 32;
- if (++count == 33)
- return;
-
- fonty = fontb + alpha * 8;
- fonty2 = GFXfant + alpha * 8;
-
- ypos = currenty;
- for (count2 = 0; count2 < 8; count2++) {
- xpos = currentx;
- for (count3 = 0; count3 < 8; count3++) {
- if (*fonty & 1 << count3)
- mm_gfx_putpixel (xpos, ypos, 0);
- else if (*fonty2 & 1 << count3) {
- BYTE data = mm_gfx_getpixel (xpos, ypos);
- BYTE data2 = (data & 15) + 3;
- mm_gfx_putpixel (xpos, ypos,
- (data & 240) | (data2 > 15 ? 15 : data2));
- }
- xpos++;
- }
- fonty++;
- fonty2++;
- ypos++;
- }
- mm_gfx_setdirty (currentx, currenty, 7, 7);
- currentx += 8;
- }
- }
-
- /* ////////////////////////////////////////////////////////////
- // Draw Air Background
- //////////////////////////////////////////////////////////// */
- void
- DrawAirBG (void)
- {
- PlotXY (0, 136, GFXair, 256, 8);
- FontPrint2 (0, 17, "AIR");
- }
-
- /* ////////////////////////////////////////////////////////////
- // Do Sun
- //////////////////////////////////////////////////////////// */
- void
- DoSun (void)
- {
- if (SUN.m == 1)
- DrawSun ();
- }
-
- /* ////////////////////////////////////////////////////////////
- // Draw Sun
- //////////////////////////////////////////////////////////// */
- static void
- DrawSun (void)
- {
- BYTE data;
- int x, y;
-
- for (y = SUN.h - 1; y >= 0; --y)
- for (x = 23; x >= 0; --x) {
- SUN.buff[old][(y * 24) + x] = mm_gfx_getpixel (60 + x, SUN.y + y);
- data = GFXsun[(y * 24) + x];
- if (data)
- mm_gfx_putpixel (60 + x, SUN.y + y, data);
- }
-
- SUN.yold[old] = SUN.y;
- SUN.hold[old] = SUN.h;
- }
-
- /* ////////////////////////////////////////////////////////////
- // Remove Sun
- //////////////////////////////////////////////////////////// */
- void
- RemoveSun (void)
- {
- if (SUN.yold[old] < UNDEF)
- PlotXY (60, SUN.yold[old], SUN.buff[old], 24, SUN.hold[old]);
- }
-
- /* ////////////////////////////////////////////////////////////
- // Draw Final Screen Background
- //////////////////////////////////////////////////////////// */
- void
- DrawFinal (void)
- {
- PlotXYink (0, 0, GFXfinal, 0, cBG.paper, 256, 64);
- }
-
-
- /* ////////////////////////////////////////////////////////////
- // Show a Long Word
- //////////////////////////////////////////////////////////// */
- void
- ShowSix (int xpos, int ypos, unsigned long data)
- {
- char printtext[12];
- sprintf (printtext, "%06lu", data);
- FontPrint (xpos, ypos, printtext);
- }
-
- /* ////////////////////////////////////////////////////////////
- // Print Text Small
- //////////////////////////////////////////////////////////// */
- void
- FontPrintSmall (int xpos, int ypos, const char * text)
- {
- int count2, count3;
- int currentx, currenty;
- int alpha;
- const BYTE *fonty;
-
- currentx = xpos *= 4;
- currenty = ypos *= 6;
-
- while (*text) {
- alpha = (int) *text++;
-
- if (alpha == 170) {
- currentx = 0;
- currenty += 8;
- alpha = (int) *text++;
- }
- if (alpha == '`') {
- INK = *text++ - 96;
- alpha = (int) *text++;
- }
-
- alpha -= 32;
- if (alpha > 64)
- alpha -= 32;
- fonty = fonts + alpha * 6;
-
- ypos = currenty;
- for (count2 = 0; count2 < 6; count2++) {
- xpos = currentx;
- for (count3 = 0; count3 < 4; count3++) {
- mm_gfx_putpixel (xpos, ypos, (*fonty & 1 << count3) ? INK : PAPER);
- xpos++;
- }
- fonty++;
- ypos++;
- }
- mm_gfx_setdirty (currentx, currenty, 3, 5);
- currentx += 4;
- }
- }
-
-
- /* ////////////////////////////////////////////////////////////
- // Generic 8*8 plotting routines
- //////////////////////////////////////////////////////////// */
- void
- Plot8back (int xpos, int ypos, BYTE paper)
- {
- if (xpos < UNDEF)
- mm_gfx_fillbox (xpos * 8, ypos * 8, 8, 8, paper);
- }
-
- void
- Plot8ink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper)
- {
- if (xpos < UNDEF)
- PlotXYink (xpos * 8, ypos * 8, block, ink, paper, 8, 8);
- }
-
- /* ////////////////////////////////////////////////////////////
- // Generic 16*16 plotting routines
- //////////////////////////////////////////////////////////// */
- void
- Plot16back (int xpos, int ypos, BYTE paper)
- {
- if (xpos < UNDEF)
- mm_gfx_fillbox (xpos, ypos, 16, 16, paper);
- }
-
- void
- Plot16 (int xpos, int ypos, const BYTE *block)
- {
- if (xpos < UNDEF)
- PlotXY (xpos, ypos, block, 16, 16);
- }
-
- void
- Plot16mask (int xpos, int ypos, const BYTE *block)
- {
- if (xpos < UNDEF)
- PlotXYmask (xpos, ypos, block, 16, 16);
- }
-
- void
- Plot16ink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper)
- {
- if (xpos < UNDEF)
- PlotXYink (xpos, ypos, block, ink, paper, 16, 16);
- }
-
- void
- Plot16mask_ink (int xpos, int ypos, const BYTE *block, BYTE ink)
- {
- if (xpos < UNDEF)
- PlotXYmask_ink (xpos, ypos, block, ink, 16, 16);
- }
-
- /* ////////////////////////////////////////////////////////////
- // Generic variable size plotting routines
- //////////////////////////////////////////////////////////// */
- void
- PlotXYback (int xpos, int ypos, BYTE paper, int width, int height)
- {
- mm_gfx_fillbox (xpos, ypos, width, height, paper);
- }
-
- #ifndef __riscos
- void
- PlotXY (int xpos, int ypos, const BYTE *block, int width, int height)
- {
- int x, y;
- block += width * height;
-
- for (y = height - 1; y >= 0; --y)
- for (x = width - 1; x >= 0; --x)
- mm_gfx_putpixel (xpos + x, ypos + y, *--block);
- }
-
- void
- PlotXYmask (int xpos, int ypos, const BYTE *block, int width, int height)
- {
- int x, y;
- block += width * height;
-
- for (y = height - 1; y >= 0; --y)
- for (x = width - 1; x >= 0; --x)
- if (*--block)
- mm_gfx_putpixel (xpos + x, ypos + y, *block);
- }
-
- void
- PlotXYink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper,
- int width, int height)
- {
- int x, y;
- block += width * height;
- for (y = height - 1; y >= 0; --y)
- for (x = width - 1; x >= 0; --x) {
- BYTE data = *--block;
- mm_gfx_putpixel (xpos + x, ypos + y,
- data ? data + ink * 16 : paper);
- }
- }
-
- void
- PlotXYmask_ink (int xpos, int ypos, const BYTE *block, BYTE ink,
- int width, int height)
- {
- int x, y;
- block += width * height;
- for (y = height - 1; y >= 0; --y)
- for (x = width - 1; x >= 0; --x)
- if (*--block)
- mm_gfx_putpixel (xpos + x, ypos + y, *block + ink * 16);
- }
-
- /* ////////////////////////////////////////////////////////////
- // Special plotting routines
- //////////////////////////////////////////////////////////// */
- void
- PlotShiny (int xpos, int ypos, const BYTE *block, BYTE bright, int size)
- {
- int x, y;
- if (xpos >= UNDEF)
- return;
- block += size * size;
- for (y = size - 1; y >= 0; --y)
- for (x = size - 1; x >= 0; --x) {
- BYTE data = *--block;
- if (data) {
- BYTE temp = (data & 15) - bright;
- if (temp > 15)
- temp = 0;
- mm_gfx_putpixel (xpos + x, ypos + y, (data & 240) | temp);
- }
- }
- }
-
- /* ////////////////////////////////////////////////////////////
- // Fade to blue
- //////////////////////////////////////////////////////////// */
- void
- FadeToBlue (void)
- {
- static const struct
- {
- BYTE x, y;
- }
- fade[8][4] =
- {
- { {0, 0}, {2, 2}, {0, 2}, {2, 0} },
- { {3, 0}, {1, 2}, {3, 2}, {1, 0} },
- { {1, 1}, {3, 3}, {1, 3}, {3, 1} },
- { {2, 1}, {0, 3}, {2, 3}, {0, 1} },
- { {0, 1}, {2, 3}, {0, 3}, {2, 1} },
- { {3, 1}, {1, 3}, {3, 3}, {1, 1} },
- { {1, 0}, {3, 2}, {1, 2}, {3, 0} },
- { {2, 0}, {0, 2}, {2, 2}, {0, 0} }
- };
- int i, j, x, y;
-
- static const BYTE map[64] =
- {
- 26,23,21,19,18,19,20,20,20,20,19,21,23,26,20,16, // 240-250
- 31,30,24,21,21,20,19,19,31,30,23,21,21,19,18,16, // 0-15
- 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, // others
- 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
- };
-
- for (i = 0; i < 8; i++) {
- for (y = 124; y >= 0; y -= 4)
- for (x = 252; x >= 0; x -= 4)
- for (j = 3; j >= 0; --j) {
- int px = x + fade[i][j].x, py = y + fade[i][j].y;
- mm_gfx_putpixel (px, py, map[(mm_gfx_getpixel (px, py) + 16) & 63]);
- }
- mm_gfx_flush ();
- mm_gfx_waitvr ();
- mm_snd_update ();
- }
- }
- #endif /* !__riscos */
-