home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / IYONIX / MANICMINER / SOURCE.ZIP / manicminer-1.6.3 / c / graph < prev    next >
Encoding:
Text File  |  2000-12-09  |  10.2 KB  |  444 lines

  1. #include "manic.h"
  2. #include "functions.h"
  3. #include "gfxdata/gfxdata.h"
  4. #include "gfxlibs/gfx.h"
  5. #include "sndlibs/snd.h"
  6. #include <string.h>
  7.  
  8.  
  9. /* In the RISC OS version, some of the routines below are in ARM assembler.
  10.  * So we *don't* want to define them here!
  11.  */
  12.  
  13.  
  14. static void DrawSun (void);
  15.  
  16.  
  17. int
  18. PaletteFade (const unsigned char *pal1, unsigned char *pal2)
  19. {
  20.   int count = 768, changed = 0;
  21.  
  22.   while (--count >= 0) {
  23.     if (*pal1 != *pal2) {
  24.       changed = 1;
  25.       if (*pal1 > *pal2)
  26.     *pal2 += 1;
  27.       else
  28.     *pal2 -= 1;
  29.     }
  30.     pal1++;
  31.     pal2++;
  32.   }
  33.   return changed;
  34. }
  35.  
  36. /* ////////////////////////////////////////////////////////////
  37. //    Rotate end of palette
  38. //////////////////////////////////////////////////////////// */
  39. void
  40. RotPal (void)
  41. {
  42.   BYTE temp1, temp2, temp3;
  43.  
  44.   temp1 = PALover[720];
  45.   temp2 = PALover[721];
  46.   temp3 = PALover[722];
  47.   memmove (&PALover[720], &PALover[723], 42);
  48.   PALover[762] = temp1;
  49.   PALover[763] = temp2;
  50.   PALover[764] = temp3;
  51. }
  52.  
  53. /* ////////////////////////////////////////////////////////////
  54. //    Print Text
  55. //////////////////////////////////////////////////////////// */
  56. void
  57. FontPrint (int xpos, int ypos, const char * text)
  58. {
  59.   int count = 0, count2, count3;
  60.   int currentx, currenty;
  61.   int alpha;
  62.   const BYTE *fonty;
  63.  
  64.   currentx = ((xpos & 127) * 8) | ((xpos & 128) ? 4 : 0);
  65.   currenty = ((ypos & 127) * 8) | ((ypos & 128) ? 4 : 0);
  66.  
  67.   while (*text) {
  68.     alpha = (int) *text++;
  69.     while (alpha == 170) {
  70.       currentx = 0;
  71.       currenty += 8;
  72.       alpha = (int) *text++;
  73.     }
  74.     alpha -= 32;
  75.     if (++count == 33)
  76.       return;
  77.     fonty = fontb + alpha * 8;
  78.  
  79.     ypos = currenty;
  80.     for (count2 = 0; count2 < 8; count2++) {
  81.       xpos = currentx;
  82.       for (count3 = 0; count3 < 8; count3++) {
  83.     mm_gfx_putpixel (xpos++, ypos, (*fonty & 1 << count3) ? INK : PAPER);
  84.       }
  85.       fonty++;
  86.       ypos++;
  87.     }
  88.     mm_gfx_setdirty (currentx, currenty, 7, 7);
  89.     currentx += 8;
  90.   }
  91. }
  92.  
  93. /* ////////////////////////////////////////////////////////////
  94. //    Print Text
  95. //////////////////////////////////////////////////////////// */
  96. void
  97. FontPrint2 (int xpos, int ypos, const char * text)
  98. {
  99.   int count = 0, count2, count3;
  100.   int currentx, currenty;
  101.   int alpha;
  102.   const BYTE *fonty, *fonty2;
  103.  
  104.   currentx = ((xpos & 127) * 8) | ((xpos & 128) ? 4 : 0);
  105.   currenty = ((ypos & 127) * 8) | ((ypos & 128) ? 4 : 0);
  106.  
  107.   while (*text) {
  108.     alpha = (int) *text++;
  109.     if (alpha == 170) {
  110.       currentx = 0;
  111.       currenty += 8;
  112.       alpha = (int) *text++;
  113.     }
  114.     alpha -= 32;
  115.     if (++count == 33)
  116.       return;
  117.  
  118.     fonty = fontb + alpha * 8;
  119.     fonty2 = GFXfant + alpha * 8;
  120.  
  121.     ypos = currenty;
  122.     for (count2 = 0; count2 < 8; count2++) {
  123.       xpos = currentx;
  124.       for (count3 = 0; count3 < 8; count3++) {
  125.     if (*fonty & 1 << count3)
  126.       mm_gfx_putpixel (xpos, ypos, 0);
  127.     else if (*fonty2 & 1 << count3) {
  128.       BYTE data = mm_gfx_getpixel (xpos, ypos);
  129.       BYTE data2 = (data & 15) + 3;
  130.       mm_gfx_putpixel (xpos, ypos,
  131.                (data & 240) | (data2 > 15 ? 15 : data2));
  132.     }
  133.     xpos++;
  134.       }
  135.       fonty++;
  136.       fonty2++;
  137.       ypos++;
  138.     }
  139.     mm_gfx_setdirty (currentx, currenty, 7, 7);
  140.     currentx += 8;
  141.   }
  142. }
  143.  
  144. /* ////////////////////////////////////////////////////////////
  145. //    Draw Air Background
  146. //////////////////////////////////////////////////////////// */
  147. void
  148. DrawAirBG (void)
  149. {
  150.   PlotXY (0, 136, GFXair, 256, 8);
  151.   FontPrint2 (0, 17, "AIR");
  152. }
  153.  
  154. /* ////////////////////////////////////////////////////////////
  155. //    Do Sun
  156. //////////////////////////////////////////////////////////// */
  157. void
  158. DoSun (void)
  159. {
  160.   if (SUN.m == 1)
  161.     DrawSun ();
  162. }
  163.  
  164. /* ////////////////////////////////////////////////////////////
  165. //    Draw Sun
  166. //////////////////////////////////////////////////////////// */
  167. static void
  168. DrawSun (void)
  169. {
  170.   BYTE data;
  171.   int x, y;
  172.  
  173.   for (y = SUN.h - 1; y >= 0; --y)
  174.     for (x = 23; x >= 0; --x) {
  175.       SUN.buff[old][(y * 24) + x] = mm_gfx_getpixel (60 + x, SUN.y + y);
  176.       data = GFXsun[(y * 24) + x];
  177.       if (data)
  178.     mm_gfx_putpixel (60 + x, SUN.y + y, data);
  179.     }
  180.  
  181.   SUN.yold[old] = SUN.y;
  182.   SUN.hold[old] = SUN.h;
  183. }
  184.  
  185. /* ////////////////////////////////////////////////////////////
  186. //    Remove Sun
  187. //////////////////////////////////////////////////////////// */
  188. void
  189. RemoveSun (void)
  190. {
  191.   if (SUN.yold[old] < UNDEF)
  192.     PlotXY (60, SUN.yold[old], SUN.buff[old], 24, SUN.hold[old]);
  193. }
  194.  
  195. /* ////////////////////////////////////////////////////////////
  196. //    Draw Final Screen Background
  197. //////////////////////////////////////////////////////////// */
  198. void
  199. DrawFinal (void)
  200. {
  201.   PlotXYink (0, 0, GFXfinal, 0, cBG.paper, 256, 64);
  202. }
  203.  
  204.  
  205. /* ////////////////////////////////////////////////////////////
  206. //    Show a Long Word
  207. //////////////////////////////////////////////////////////// */
  208. void
  209. ShowSix (int xpos, int ypos, unsigned long data)
  210. {
  211.   char printtext[12];
  212.   sprintf (printtext, "%06lu", data);
  213.   FontPrint (xpos, ypos, printtext);
  214. }
  215.  
  216. /* ////////////////////////////////////////////////////////////
  217. //    Print Text Small
  218. //////////////////////////////////////////////////////////// */
  219. void
  220. FontPrintSmall (int xpos, int ypos, const char * text)
  221. {
  222.   int count2, count3;
  223.   int currentx, currenty;
  224.   int alpha;
  225.   const BYTE *fonty;
  226.  
  227.   currentx = xpos *= 4;
  228.   currenty = ypos *= 6;
  229.  
  230.   while (*text) {
  231.     alpha = (int) *text++;
  232.  
  233.     if (alpha == 170) {
  234.       currentx = 0;
  235.       currenty += 8;
  236.       alpha = (int) *text++;
  237.     }
  238.     if (alpha == '`') {
  239.       INK = *text++ - 96;
  240.       alpha = (int) *text++;
  241.     }
  242.  
  243.     alpha -= 32;
  244.     if (alpha > 64)
  245.       alpha -= 32;
  246.     fonty = fonts + alpha * 6;
  247.  
  248.     ypos = currenty;
  249.     for (count2 = 0; count2 < 6; count2++) {
  250.       xpos = currentx;
  251.       for (count3 = 0; count3 < 4; count3++) {
  252.     mm_gfx_putpixel (xpos, ypos, (*fonty & 1 << count3) ? INK : PAPER);
  253.     xpos++;
  254.       }
  255.       fonty++;
  256.       ypos++;
  257.     }
  258.     mm_gfx_setdirty (currentx, currenty, 3, 5);
  259.     currentx += 4;
  260.   }
  261. }
  262.  
  263.  
  264. /* ////////////////////////////////////////////////////////////
  265. //    Generic 8*8 plotting routines
  266. //////////////////////////////////////////////////////////// */
  267. void
  268. Plot8back (int xpos, int ypos, BYTE paper)
  269. {
  270.   if (xpos < UNDEF)
  271.     mm_gfx_fillbox (xpos * 8, ypos * 8, 8, 8, paper);
  272. }
  273.  
  274. void
  275. Plot8ink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper)
  276. {
  277.   if (xpos < UNDEF)
  278.     PlotXYink (xpos * 8, ypos * 8, block, ink, paper, 8, 8);
  279. }
  280.  
  281. /* ////////////////////////////////////////////////////////////
  282. //    Generic 16*16 plotting routines
  283. //////////////////////////////////////////////////////////// */
  284. void
  285. Plot16back (int xpos, int ypos, BYTE paper)
  286. {
  287.   if (xpos < UNDEF)
  288.     mm_gfx_fillbox (xpos, ypos, 16, 16, paper);
  289. }
  290.  
  291. void
  292. Plot16 (int xpos, int ypos, const BYTE *block)
  293. {
  294.   if (xpos < UNDEF)
  295.     PlotXY (xpos, ypos, block, 16, 16);
  296. }
  297.  
  298. void
  299. Plot16mask (int xpos, int ypos, const BYTE *block)
  300. {
  301.   if (xpos < UNDEF)
  302.     PlotXYmask (xpos, ypos, block, 16, 16);
  303. }
  304.  
  305. void
  306. Plot16ink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper)
  307. {
  308.   if (xpos < UNDEF)
  309.     PlotXYink (xpos, ypos, block, ink, paper, 16, 16);
  310. }
  311.  
  312. void
  313. Plot16mask_ink (int xpos, int ypos, const BYTE *block, BYTE ink)
  314. {
  315.   if (xpos < UNDEF)
  316.     PlotXYmask_ink (xpos, ypos, block, ink, 16, 16);
  317. }
  318.  
  319. /* ////////////////////////////////////////////////////////////
  320. //    Generic variable size plotting routines
  321. //////////////////////////////////////////////////////////// */
  322. void
  323. PlotXYback (int xpos, int ypos, BYTE paper, int width, int height)
  324. {
  325.   mm_gfx_fillbox (xpos, ypos, width, height, paper);
  326. }
  327.  
  328. #ifndef __riscos
  329. void
  330. PlotXY (int xpos, int ypos, const BYTE *block, int width, int height)
  331. {
  332.   int x, y;
  333.   block += width * height;
  334.  
  335.   for (y = height - 1; y >= 0; --y)
  336.     for (x = width - 1; x >= 0; --x)
  337.       mm_gfx_putpixel (xpos + x, ypos + y, *--block);
  338. }
  339.  
  340. void
  341. PlotXYmask (int xpos, int ypos, const BYTE *block, int width, int height)
  342. {
  343.   int x, y;
  344.   block += width * height;
  345.  
  346.   for (y = height - 1; y >= 0; --y)
  347.     for (x = width - 1; x >= 0; --x)
  348.       if (*--block)
  349.     mm_gfx_putpixel (xpos + x, ypos + y, *block);
  350. }
  351.  
  352. void
  353. PlotXYink (int xpos, int ypos, const BYTE *block, BYTE ink, BYTE paper,
  354.        int width, int height)
  355. {
  356.   int x, y;
  357.   block += width * height;
  358.   for (y = height - 1; y >= 0; --y)
  359.     for (x = width - 1; x >= 0; --x) {
  360.       BYTE data = *--block;
  361.       mm_gfx_putpixel (xpos + x, ypos + y,
  362.                data ? data + ink * 16 : paper);
  363.     }
  364. }
  365.  
  366. void
  367. PlotXYmask_ink (int xpos, int ypos, const BYTE *block, BYTE ink,
  368.        int width, int height)
  369. {
  370.   int x, y;
  371.   block += width * height;
  372.   for (y = height - 1; y >= 0; --y)
  373.     for (x = width - 1; x >= 0; --x)
  374.       if (*--block)
  375.     mm_gfx_putpixel (xpos + x, ypos + y, *block + ink * 16);
  376. }
  377.  
  378. /* ////////////////////////////////////////////////////////////
  379. //    Special plotting routines
  380. //////////////////////////////////////////////////////////// */
  381. void
  382. PlotShiny (int xpos, int ypos, const BYTE *block, BYTE bright, int size)
  383. {
  384.   int x, y;
  385.   if (xpos >= UNDEF)
  386.     return;
  387.   block += size * size;
  388.   for (y = size - 1; y >= 0; --y)
  389.     for (x = size - 1; x >= 0; --x) {
  390.       BYTE data = *--block;
  391.       if (data) {
  392.     BYTE temp = (data & 15) - bright;
  393.     if (temp > 15)
  394.       temp = 0;
  395.     mm_gfx_putpixel (xpos + x, ypos + y, (data & 240) | temp);
  396.       }
  397.     }
  398. }
  399.  
  400. /* ////////////////////////////////////////////////////////////
  401. //    Fade to blue
  402. //////////////////////////////////////////////////////////// */
  403. void
  404. FadeToBlue (void)
  405. {
  406.   static const struct
  407.   {
  408.     BYTE x, y;
  409.   }
  410.   fade[8][4] =
  411.   {
  412.     { {0, 0}, {2, 2}, {0, 2}, {2, 0} },
  413.     { {3, 0}, {1, 2}, {3, 2}, {1, 0} },
  414.     { {1, 1}, {3, 3}, {1, 3}, {3, 1} },
  415.     { {2, 1}, {0, 3}, {2, 3}, {0, 1} },
  416.     { {0, 1}, {2, 3}, {0, 3}, {2, 1} },
  417.     { {3, 1}, {1, 3}, {3, 3}, {1, 1} },
  418.     { {1, 0}, {3, 2}, {1, 2}, {3, 0} },
  419.     { {2, 0}, {0, 2}, {2, 2}, {0, 0} }
  420.   };
  421.   int i, j, x, y;
  422.  
  423.   static const BYTE map[64] =
  424.   {
  425.     26,23,21,19,18,19,20,20,20,20,19,21,23,26,20,16, // 240-250
  426.     31,30,24,21,21,20,19,19,31,30,23,21,21,19,18,16, // 0-15
  427.     16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, // others
  428.     16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
  429.   };
  430.  
  431.   for (i = 0; i < 8; i++) {
  432.     for (y = 124; y >= 0; y -= 4)
  433.       for (x = 252; x >= 0; x -= 4)
  434.     for (j = 3; j >= 0; --j) {
  435.       int px = x + fade[i][j].x, py = y + fade[i][j].y;
  436.       mm_gfx_putpixel (px, py, map[(mm_gfx_getpixel (px, py) + 16) & 63]);
  437.     }
  438.     mm_gfx_flush ();
  439.     mm_gfx_waitvr ();
  440.     mm_snd_update ();
  441.   }
  442. }
  443. #endif /* !__riscos */
  444.