home *** CD-ROM | disk | FTP | other *** search
/ Season's Greetings & Games Unlimited / XMAS_cd1.iso / 4dos / cards / xmas / xmas.c < prev    next >
Text File  |  1991-06-02  |  7KB  |  252 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *            xmas.c ---  Merry Christmas to everybody!!!               *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "xmas.h"
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <fastgraf.h>
  12.  
  13. #define OK       1
  14.  
  15. int seed;
  16. int hidden;
  17. int visual;
  18.  
  19. int flakex[900];
  20. int flakey[900];
  21.  
  22. char string[2500];
  23.  
  24. char jingle[]=
  25. "T255O5L4CAGFL2CL8CCL4CAGFL2D.L4P"
  26. "L4DA#AGL2E.L4PO+CCO-A#GL2A.L4P"
  27. "L4CAGFL2C.L8L4PCAGFL2DL4PD"
  28. "DA#AGO+CCCCDCO-A#GL2F.L4P"
  29. "AAL2AL4AAL2AL4AO+CO-F.L8GL2A.L4P"
  30. "A#A#A#.L8A#L4A#AAL8AAL4AGGAL2GO+CO-"
  31. "L4AAL2AL4AAL2AL4AO+CO-F.L8GL2A.L4P"
  32. "A#A#A#.L8A#L4A#AAL8AAL4O+CCO-A#GL2F.L1P";
  33.  
  34. char silent[] =
  35. "T150O3S0L4G.L8S1AL4GL2E.S0L4G."
  36. "L8AS1L4GL2E.O+DL4DL2O-B.O+CL4CL2O-G.AL4AO+S0C."
  37. "O-L8BS+L4AG.L8AL4GL2E.AL4AO+C.O-L8BL4AG.L8AL4GL2E.O+DL4DF.L8D"
  38. "L4O-BL2O+S0C.E.S1L4C.O-L8GL4EG.L8FL4D L1 0- CP";
  39.  
  40. char tree[] =
  41. "T100O3O-L4CL8F.L16FL4FGL8A.L16AL4A.L8AGAL4A#EGFC"
  42. "L8F.L16FL4FGL8A.L16AL4A.L8AGAL4A#EGF.O+L8C"
  43. "CO-AO+L4D.L8CCO-A#L4A#.L8A#A#GL4O+C.L8O-A#A#AL4AC"
  44. "L8F.L16FL4FGL8A.L16AL4A.L8AGAL4A#EGFL1P";
  45.  
  46. char child[] =
  47. "T80O3L8GL4A#L8O+CD.L16D#L8DL4CO-L8AF."
  48. "L16GL8AL4A#L8GG.L16F#L8GL4AL8F#L4DL8G"
  49. "L4A#L8O+CD.L16D#L8DL4CL8O-AF.L16GL8AL8A#.L16AL8GF#."
  50. "L16EL8F#L4G.G.O+F.L8F.L16EL8DL4CO-L8AF.L16G"
  51. "L8AL4A#L8GG.L16F#L8GL4AL8F#L4D.L4O+F.L8F."
  52. "L16EL8DL4CO-L8AL8F.L16GL8AA#.L16AL8G"
  53. "L8F#.L16EL8F#L4G.G.L1P";
  54.  
  55. char manger[] =
  56. "T150O3L4DD.L8CL4O-BBAGGF#EL2DL4D"
  57. "D.L8EL4DDAF#EDGL2BO+L4D"
  58. "L4D.L8CL4O-BS0BS1AGGF#EL2DL4D"
  59. "L4O+C.O-L8BL4ABAGAEF#L2GL1P"
  60. "T150O3L4DD.L8CL4O-BBAGGF#EL2DL4D"
  61. "D.L8EL4DDAF#EDGL2BO+L4D"
  62. "L4D.L8CL4O-BS0BS1AGGF#EL2DL4D"
  63. "L4O+C.O-L8BL4ABAGAEF#L2GL1P$";
  64.  
  65. /**********************************************************************\
  66. *                                                                     *
  67. *                                 main                                 *
  68. *                                                                      *
  69. \**********************************************************************/
  70.  
  71. int colors[] = {0,46,2,3,12,5,20,7,56,57,58,59,60,61,62,63};
  72.  
  73. void main()
  74. {
  75.    unsigned char key,aux;
  76.    int i,j;
  77.    int index;
  78.  
  79.    if (fg_egacheck() != 4) 
  80.    {
  81.       printf("\n");
  82.       printf("This program requires an EGA with 256K \n");
  83.       printf("and an enhanced color display (ECD).\n\n");
  84.       printf("If an EGA is present, it must be the active adaptor.\n");
  85.       exit(0);
  86.    }
  87.  
  88.    init_graphics();
  89.    fg_palettes(colors);
  90.  
  91.    fg_setpage(visual);
  92.    fg_waitfor(1);
  93.  
  94.    strcpy(string,jingle);
  95.    strcat(string,silent);
  96.    strcat(string,tree);
  97.    strcat(string,child);
  98.    strcat(string,manger);
  99.  
  100.    fg_move(0,349);
  101.    fg_dispfile("xmas.ppr",640,1);
  102.  
  103.    fg_transfer(0,639,0,349,0,349,visual,hidden);
  104.  
  105.    index = 0;
  106.    for (i = 0; i < 175; i++)
  107.    {
  108.       for (j = 0; j < 5; j++)
  109.       {
  110.          flakex[index] = j * 104+irandom(0,104);
  111.          flakey[index] = -2*i;
  112.          index++;
  113.       }
  114.    }
  115.  
  116.    for (i = 0; i < 200; i+=2)
  117.       flakey[i] -= 350;
  118.  
  119.    for (i = 0; i < 400; i+=3)
  120.       flakey[i] -= 350;
  121.  
  122.    for (i = 1; i < 875; i+=4)
  123.       flakey[i] -= 350;
  124.  
  125.    fg_setpage(visual);
  126.    fg_setcolor(15);
  127.    fg_move(0,365);
  128.  
  129.    fg_waitfor(18);
  130.  
  131.    while(1)
  132.    {
  133.       fg_intkey(&key,&aux);
  134.       if (key == 27)
  135.          quit_graphics(); 
  136.  
  137.       if (fg_numlock()) 
  138.       {
  139.          if (fg_playing())
  140.              fg_hush();
  141.       }
  142.       else 
  143.       {  
  144.          if (!fg_playing())
  145.             fg_musicb(string,-1);
  146.       }
  147.  
  148.       for (i = 0; i < 875; i++)
  149.       {
  150.          if (flakey[i] > 0)
  151.             fg_restore(flakex[i],flakex[i]+1,flakey[i],flakey[i]+1);
  152.  
  153.          flakex[i] += irandom(-1,1);
  154.          if (flakex[i] > 518) 
  155.             flakex[i] = 2;
  156.          else if (flakex[i] < 0) 
  157.             flakex[i] =518;
  158.  
  159.          flakey[i] += irandom(0,3);
  160.          if (flakey[i] > 349) 
  161.             flakey[i] = -350;
  162.  
  163.          if (flakey[i] > 0)
  164.             fg_rect(flakex[i],flakex[i]+1,flakey[i],flakey[i]+1);
  165.       }
  166.    }
  167. }
  168.  
  169. /**********************************************************************\
  170. *                                                                      *
  171. *      init_graphics -- initialize the graphics environment            *
  172. *                                                                      *
  173. \**********************************************************************/
  174.  
  175. init_graphics()
  176. {
  177.  
  178.    /* set mode to high-res EGA (640X350) */
  179.  
  180.    fg_setmode(16);
  181.  
  182.    /* set up visual and hidden pages */
  183.  
  184.    fg_setpage(0);
  185.    fg_setvpage(0);
  186.    fg_sethpage(1);
  187.  
  188.    visual = 0;
  189.    hidden = 1;   
  190.  
  191.    fg_setnum(0);
  192.    getseed();
  193.  
  194.    return(OK);
  195. }
  196.  
  197. /**********************************************************************\
  198. *                                                                      *
  199. *    quit_graphics -- return the computer to its original state        *
  200. *                                                                      *
  201. \**********************************************************************/
  202.  
  203. void quit_graphics()
  204. {
  205.  
  206.    /* turn off the music */
  207.  
  208.    fg_hush();
  209.  
  210.    /* set the mode to whatever it was originally */
  211.  
  212.    fg_setmode(3);
  213.  
  214.    /* if screen attributes were set, reset them and clear the screen*/
  215.  
  216.    fg_reset();
  217.    exit(0);
  218. }
  219.  
  220. /**********************************************************************\
  221. *                                                                      *
  222. *        getseed -- get a seed for the random number generator         *
  223. *                                                                      *
  224. \**********************************************************************/
  225.  
  226. getseed()
  227. {
  228.    long fg_getclock();
  229.  
  230.    seed = (int)(fg_getclock() & 0x7FFF);
  231.    return(OK);
  232. }
  233.  
  234. /**********************************************************************\
  235. *                                                                      *
  236. *              irandom -- Ted's random number generator                *
  237. *                                                                      *
  238. \**********************************************************************/
  239.  
  240. irandom(min,max)
  241. int min;
  242. int max;
  243. {
  244.    int temp;
  245.  
  246.    temp = seed ^ (seed >> 7);
  247.    seed = ((temp << 8) ^ temp) & 0x7FFF;
  248.    return((seed % (max-min+1)) + min);
  249. }
  250.  
  251.  
  252.