home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / manboetc / rain.c < prev    next >
Text File  |  1990-06-14  |  7KB  |  283 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <egb.h>
  5. #include <mos.h>
  6.  
  7. /*    Size=(8,8)        */
  8. char rain_xor[]={
  9.         0x08,0x08,0x14,0x14,0x22,0x22,0x26,0x1C};
  10.  
  11. /*    Size=(32,32)        */
  12. char rain1_xor[]={
  13.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  14.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  15.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  17.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  18.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19.         0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,
  20.         0x00,0x00,0x80,0x00,0x00,0x01,0xC0,0x00,
  21.         0x00,0x01,0x40,0x00,0x00,0x0A,0x28,0x00,
  22.         0x00,0x12,0x24,0x00,0x00,0x11,0xC4,0x00,
  23.         0x00,0x08,0x08,0x00,0x00,0x07,0xF0,0x00,
  24.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  25.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  26.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  27.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  28.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29.  
  30.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  37.         0x00,0x0F,0xF8,0x00,0x00,0x30,0x06,0x00,
  38.         0x00,0x40,0x81,0x00,0x00,0x8A,0xA8,0x80,
  39.         0x01,0x12,0x24,0x40,0x01,0x11,0xC4,0x40,
  40.         0x01,0x08,0x08,0x40,0x00,0x87,0xF0,0x80,
  41.         0x00,0x40,0x01,0x00,0x00,0x38,0x0E,0x00,
  42.         0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,
  43.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46.  
  47.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52.         0x00,0x00,0x00,0x00,0x00,0x1F,0x14,0x00,
  53.         0x00,0x40,0x01,0x00,0x00,0x00,0x00,0x60,
  54.         0x02,0x0F,0xF8,0x10,0x04,0x30,0x06,0x00,
  55.         0x08,0x40,0x01,0x08,0x00,0x89,0x48,0x80,
  56.         0x11,0x12,0x24,0x44,0x11,0x11,0x44,0x44,
  57.         0x11,0x08,0x08,0x44,0x00,0x87,0xF0,0x84,
  58.         0x08,0x40,0x01,0x00,0x02,0x38,0x0E,0x10,
  59.         0x03,0x07,0xF0,0x00,0x00,0x80,0x00,0xE0,
  60.         0x00,0x60,0x03,0x00,0x00,0x07,0x88,0x00,
  61.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63.  
  64.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68.         0x00,0x14,0x48,0x00,0x00,0x40,0x02,0x80,
  69.         0x05,0x00,0x00,0x20,0x08,0x14,0xD4,0x08,
  70.         0x00,0x40,0x01,0x00,0x21,0x00,0x00,0x42,
  71.         0x02,0x0A,0x88,0x10,0x44,0x30,0x06,0x00,
  72.         0x08,0x40,0x01,0x09,0x00,0x88,0x08,0x80,
  73.         0x90,0x10,0x04,0x04,0x90,0x00,0x00,0x04,
  74.         0x90,0x08,0x08,0x01,0x00,0x85,0x50,0x84,
  75.         0x08,0x40,0x01,0x01,0x02,0x38,0x0E,0x10,
  76.         0x42,0x04,0xB0,0x00,0x40,0x80,0x00,0x22,
  77.         0x08,0x20,0x03,0x00,0x00,0x06,0xA8,0x18,
  78.         0x01,0x00,0x00,0x40,0x00,0x27,0x8E,0x00,
  79.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  80.  
  81. #define NUM 96
  82. #define COLOR 2
  83. #define DROPOUT 432
  84. #define RND 512
  85. #define WAIT 15
  86.  
  87. struct    RAIN    {
  88.                     short    x ;
  89.                     short    y ;
  90.                     char    pat ;
  91.             } ;
  92.  
  93. int        downSp = 16 ;
  94.  
  95. #define work mwork+2560
  96.  
  97. char    mwork[4096] ;
  98. struct    RAIN rain[NUM] ;
  99.  
  100. void main()
  101. {
  102.     extern    void setRain(struct RAIN *) ;
  103.     extern    void moveRain() ;
  104.     extern    void dispRain() ;
  105.  
  106.     int        i ;
  107. /*
  108.     EGB_init(work,1536) ;
  109.     EGB_resolution(work,0,0x3) ;
  110.     EGB_resolution(work,1,0x3) ;
  111.     EGB_writePage(work,0x0) ;
  112.     EGB_displayPage(work,0,3) ;
  113. */
  114.     EGB_resolution(work,0,0x43) ;
  115.     EGB_resolution(work,1,0x43) ;
  116.     EGB_writePage(work,0x40) ;
  117.  
  118.     for (i = 0 ; i < NUM ; i++)
  119.         setRain(&rain[i]) ;
  120.  
  121.     EGB_writeMode(work,4) ;
  122.     moveRain() ;
  123.     dispRain() ;
  124. }
  125.  
  126. void moveRain()
  127. {
  128.     extern    void setRain(struct RAIN *) ;
  129.     extern    void setPalette() ;
  130.  
  131.     int        i = 0 ;
  132.     int        max = 1 ;
  133.     int        busy = 0 ;
  134.     int        ch,x,y ;
  135.     char    para[64] ;
  136.  
  137.     MOS_start(mwork,4096) ;
  138.  
  139.     EGB_color(work,0,COLOR) ;
  140.     do
  141.     {
  142.         if (busy == 0)
  143.         {
  144.             if (rain[i].pat == 0)
  145.             {
  146.                 DWORD(para + 0) = (unsigned int)rain_xor ;
  147.                 WORD(para + 4) = 0x14 ;
  148.                 WORD(para + 6) = rain[i].x ;
  149.                 WORD(para + 8) = rain[i].y + downSp ;
  150.                 WORD(para + 10) = rain[i].x+7 ;
  151.                 WORD(para + 12) = rain[i].y+7 + downSp ;
  152.                 EGB_putBlockColor(work,0,para) ;
  153.                 WORD(para + 8) = rain[i].y ;
  154.                 WORD(para + 12) = rain[i].y+7 ;
  155.                 EGB_putBlockColor(work,0,para) ;
  156.  
  157.                 rain[i].y += downSp ;
  158.             }
  159.  
  160.             if (rain[i].y > DROPOUT)
  161.             {
  162.                 WORD(para + 4) = 0x14 ;
  163.                 WORD(para + 6) = rain[i].x - 12 ;
  164.                 WORD(para + 8) = rain[i].y -12 ;
  165.                 WORD(para + 10) = rain[i].x -12 +31 ;
  166.                 WORD(para + 12) = rain[i].y -12 +31 ;
  167.                 if (rain[i].pat < 4)
  168.                 {
  169.                     DWORD(para) = (unsigned int)(rain1_xor+128*rain[i].pat) ;
  170.                     EGB_putBlockColor(work,0,para) ;
  171.                 }
  172.                 if (rain[i].pat != 0)
  173.                 {
  174.                     DWORD(para)=(unsigned int)(rain1_xor+128*(rain[i].pat-1)) ;
  175.                 }
  176.                 else
  177.                 {
  178.                     DWORD(para + 0) = (unsigned int)rain_xor ;
  179.                     WORD(para + 6) = rain[i].x ;
  180.                     WORD(para + 8) = rain[i].y ;
  181.                     WORD(para + 10) = rain[i].x+7 ;
  182.                     WORD(para + 12) = rain[i].y+7 ;
  183.                 }
  184.                 EGB_putBlockColor(work,0,para) ;
  185.                 rain[i].pat++ ;
  186.             }
  187.  
  188.             if (rain[i].pat == 5)
  189.                 setRain(&rain[i]) ;
  190.  
  191.             i++ ;
  192.             if (i == max)
  193.             {
  194.                 busy = i ;
  195.                 i = 0 ;
  196.             }
  197.         }
  198.         else
  199.         {
  200.             DWORD(para + 0) = (unsigned int)rain_xor ;
  201.             WORD(para + 4) = 0x14 ;
  202.             WORD(para + 6) = 640 ;
  203.             WORD(para + 8) = 0 ;
  204.             WORD(para + 10) = 640+WAIT ;
  205.             WORD(para + 12) = WAIT ;
  206.             EGB_putBlockColor(work,0,para) ;
  207.             busy++ ;
  208.             if (busy > NUM) busy = 0 ;
  209.         }
  210.  
  211.         if (max < NUM)
  212.             if ((rand() % RND) == 0)
  213.             {
  214.                 max++ ;
  215.                 if ((max & 0xf) == 0)
  216.                     setPalette() ;
  217.             }
  218.  
  219.         MOS_rdpos(&ch,&x,&y) ;
  220.     } while (!ch) ;
  221.     MOS_end() ;
  222. }
  223.  
  224. void dispRain()
  225. {
  226.     int        i ;
  227.     char    para[64] ;
  228.  
  229.     EGB_color(work,0,COLOR) ;
  230.     for (i = 0 ; i < NUM ; i++)
  231.     {
  232.         if (rain[i].pat == 0)
  233.         {
  234.             DWORD(para + 0) = (unsigned int)rain_xor ;
  235.             WORD(para + 6) = rain[i].x ;
  236.             WORD(para + 8) = rain[i].y ;
  237.             WORD(para + 10) = rain[i].x+7 ;
  238.             WORD(para + 12) = rain[i].y+7 ;
  239.         }
  240.         else
  241.         {
  242.             DWORD(para + 0) = (unsigned int)(rain1_xor+128*(rain[i].pat-1)) ;
  243.             WORD(para + 6) = rain[i].x - 12 ;
  244.             WORD(para + 8) = rain[i].y -12 ;
  245.             WORD(para + 10) = rain[i].x -12 +31 ;
  246.             WORD(para + 12) = rain[i].y -12 +31 ;
  247.         }
  248.         WORD(para + 4) = 0x14 ;
  249.         EGB_putBlockColor(work,0,para) ;
  250.     }
  251. }
  252.  
  253. void setRain(data)
  254. struct RAIN *data ;
  255. {
  256.     data->x = (((unsigned) rand()) % 640) ;
  257.     data->y = -16 - (rand() & 0xf);
  258.     data->pat = 0 ;
  259. }
  260.  
  261. void setPalette()
  262. {
  263.     int        i ;
  264.     int        j ;
  265.     int        data ;
  266.     char    ch ;
  267.  
  268.     for (i = 0 ; i < 16 ; i++)
  269.     {
  270.         j = 0xfd90 ;
  271.         outp(j,i) ;
  272.         for (j += 2 ; j < 0xfd98 ; j +=2)
  273.         {
  274.             ch = inp(j) ;
  275.             data = ch ;
  276.             data -= 16 ;
  277.             if (data < 0) data = 0 ;
  278.             ch = data ;
  279.             outp(j,ch) ;
  280.         }
  281.     }
  282. }
  283.