home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / osborne / rain.c < prev    next >
Text File  |  1994-07-13  |  3KB  |  152 lines

  1. #include "a:bdscio.h"
  2.  
  3. /* TERMINAL RAIN */
  4. /* Adapted from Berkeley's "rain" for the Osbourne 1 */
  5. /* By Dan Sunday.  4-1-82 */
  6.  
  7.  
  8.  
  9. main(argc,argv)
  10. char *argv[];
  11. {
  12.         int x, y, j, t;
  13.         int xpos[5], ypos[5];
  14.     int xloc, yloc;
  15.  
  16.     nrand(-1,0x74b5,0xc3b6,0x4dd3);
  17.     puts(CLEARS);    /* clear the screen */
  18.     cursor(26,26);    /* hide the cursor */
  19.  
  20.         for (j=5;--j>=0;) {
  21.                 xpos[j] = (nrand(1) & 0x1f) + (nrand(1) & 0xf) + 2;
  22.                 ypos[j] = (nrand(1) & 0xf) + (nrand(1) & 3) + 2;
  23.         }
  24.  
  25.  
  26.         for (j=0;;) {
  27.                 xloc = x = (nrand(1) & 0x1f) + (nrand(1) & 0xf) + 2;
  28.                 yloc = y = (nrand(1) & 0xf) + (nrand(1) & 3) + 2;
  29.                 pushch(yloc,xloc,'.');
  30.                 yloc = ypos[j];
  31.         xloc = xpos[j];
  32.                 pushch(yloc,xloc,'o');
  33.  
  34.                 if (j==0) j=4; 
  35.                 else --j;
  36.                 yloc = ypos[j];
  37.         xloc = xpos[j];
  38.                 pushch(yloc,xloc,'O');
  39.  
  40.                 if (j==0) j=4; 
  41.                 else --j;
  42.  
  43.                 yloc = ypos[j]-1;
  44.         xloc = xpos[j];
  45.                 pushch(yloc,xloc,'-');
  46.  
  47.                 ++yloc;
  48.         --xloc;
  49.                 pushstr(yloc,xloc,"|.|");
  50.  
  51.         ++yloc;
  52.         ++xloc;
  53.                 pushch(yloc,xloc,'-');
  54.  
  55.                 if (j==0) j=4; 
  56.                 else --j;
  57.  
  58.                 yloc = ypos[j]-2;
  59.         xloc = xpos[j];
  60.                 pushch(yloc,xloc,'-');
  61.  
  62.         ++yloc;
  63.         --xloc;
  64.                 pushstr(yloc,xloc,"/ \\");
  65.  
  66.         ++yloc;
  67.         --xloc;
  68.                 pushstr(yloc,xloc,"| O |");
  69.  
  70.         ++yloc;
  71.         ++xloc;
  72.                 pushstr(yloc,xloc,"\\ /");
  73.  
  74.         ++yloc;
  75.         ++xloc;
  76.                 pushch(yloc,xloc,'-');
  77.  
  78.                 if (j==0) j=4; 
  79.                 else --j;
  80.  
  81.                 yloc = ypos[j]-2;
  82.         xloc = xpos[j];
  83.                 pushch(yloc,xloc,' ');
  84.  
  85.         ++yloc;
  86.         --xloc;
  87.                 pushstr(yloc,xloc,"    ");
  88.  
  89.         ++yloc;
  90.         --xloc;
  91.                 pushstr(yloc,xloc,"     ");
  92.  
  93.         ++yloc;
  94.         ++xloc;
  95.                 pushstr(yloc,xloc,"    ");
  96.  
  97.         ++yloc;
  98.         ++xloc;
  99.                 pushch(yloc,xloc,' ');
  100.  
  101.                 xpos[j]=x; 
  102.                 ypos[j]=y;
  103.  
  104.     t = 2000;
  105.     while (t--)
  106.         ;
  107.     if (isakey()) {
  108.         if (fetch() == (CTRL 'c')) {
  109.             puts(CLEARS);
  110.             exit(0);
  111.         }
  112.     }
  113.         }
  114. }
  115.  
  116.  
  117. cursor (y,x)        /* move cursor to (y,x) */
  118. {
  119.     puts("\033=");
  120.     putch (y+' ');
  121.     putch (x+' ');
  122. }
  123.  
  124.  
  125. isakey()
  126. {    return bios(2);
  127. }
  128.  
  129.  
  130. fetch()
  131. {    return bios(3);
  132. }
  133.  
  134.  
  135. pushch (y,x,c)
  136. char c;
  137. {
  138.     char *p;
  139.     p = (y << 7) + x + 0xf000;
  140.     *p = c;
  141. }
  142.  
  143.  
  144. pushstr (y,x,s)
  145. char *s;
  146. {
  147.     char *p;
  148.     p = (y << 7) + x + 0xf000;
  149.     while (*s)
  150.         *p++ = *s++;
  151. }
  152.