home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug005.arc / FALLOUT.C < prev    next >
Text File  |  1979-12-31  |  7KB  |  205 lines

  1. /*    FALLOUT for the Colour Microbee
  2.  
  3.     This is a logical extension of "flyby.c" written by Leor Zolman
  4.            July 18, 1980 (I promise to stop playing with the H19
  5.                   and put more work into the v1.4 code
  6.                   optimizer...tomorrow!)
  7. */                  
  8. #include "bdscio.h"
  9. #define MAXTHINGS 50    /* Maximum # of objects on the screen at once */
  10. #define INACTIVE  0
  11.  
  12. struct thing {
  13.     char what;    /* Either an Ascii value, or INACTIVE */
  14.     char rev;    /* True if character to be displayed in reverse */
  15.     int rowp;    /* Row position of thing */
  16.     int colp;    /* Column position of thing */
  17.     int speedd;    /* Down speed    */
  18.     int speeda;    /* Across speed (signed to indicate left or right) */
  19.     char trail;    /* True if displaying trail */
  20.     char zigzag;    /* True if zigzag-ing */
  21.     int zigmag;    /* if zigzag-ing, magnitude of zig and zag */
  22.     int zigpos;    /* Count of how many zigs or zags have been done */
  23.     char colour;    /* Colour of the thing */
  24. };
  25.  
  26. char halt;        /* goes true when user aborts */
  27. int length,width;    /* length and width of the screen */
  28. /*---------------------------------------------------------------------------*/
  29. main(argc,argv)
  30. char **argv;
  31. {
  32.     struct thing thingtab[MAXTHINGS], *thingie;
  33.     int dspeedt[20], aspeedt[20];    /* Tables of possible speeds    */
  34.     int i,j,nthings;    /* loop variables, and # of active things */
  35.     char inrev;        /* true if in reverse video */
  36.     char trails;        /* true if displaying all trails */
  37.     char insert_mode;    /* true when insert mode is activated */
  38.     char point_source;    /* true if all things coming from one point */
  39.     int source_point;    /* if point_source true, the horiz pos */
  40.     char nuffink;        /* black foreground and background */
  41.  
  42.     initw(dspeedt,"1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5");
  43.     initw(aspeedt,"0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7");
  44.     point_source = trails = insert_mode = FALSE;
  45.     nuffink = 0;
  46. /*---------------------------------------------------------------------------*/
  47. if (fullsize() == TRUE) {
  48.     length=25;    width=80; }
  49. else {
  50.     length=17;    width=64;
  51.     call(0xe01e);        /* set it up for 64 * 16 screen image */
  52.     call(0xe02a); }        /* copy in correct inverse characters */
  53.  
  54. start:    
  55. nthings = getnum();        /* get number of things to display */
  56. puts(CLEARS);    puts(OUTAREV);
  57. outp(8,78);            /* set up for colour RAM and guns on full */
  58. for (i=0,j=0xf800; i<2048; i++,j++) 
  59.     poke(j,nuffink);     /* clear the colour byte */
  60. outp(8,0);            /* get back to normal inverse PCG RAM */
  61. halt = inrev = FALSE;
  62. for (i=0; i<nthings; i++)     /* clear out the table of things */
  63.     thingtab[i].what = INACTIVE;
  64.  
  65. /*---------------------------------------------------------------------------*/
  66. loop:
  67. if (!(rand() % 99)) {                /* if point source off, make */
  68.     point_source = TRUE;            /* it tough to get it turned */
  69.     source_point = rand() % (width-1);    /* on..                       */
  70. } else if (point_source && !(rand() % 50))     /* easier to turn off..      */
  71.         point_source = FALSE;
  72.  
  73. if (trails)
  74.     if (!(rand() % 2))            /* if trails on, lean toward */
  75.         trails = FALSE;            /* toward turning them off   */
  76.     else     trails = TRUE;
  77. else if (!(rand() % (MAXTHINGS - nthings + 20)))    /* if trails off   */
  78.         trails = TRUE;            /* lean to keeping 'em off */
  79.  
  80. if (!(rand() % ((2 * MAXTHINGS + 5) - nthings * 2 ))) 
  81.     puts(CLEARS);                /* clear the screen */
  82. if (!(rand() % 200)) 
  83.     insert_mode = !insert_mode;
  84.  
  85. for (i=0; i<nthings; i++) {         /* now process each thing in turn */
  86.     thingie = thingtab[i];         /* get pointer to current thing */
  87.  
  88.     if (!thingie -> what) {            /* if it is inactive, create it: */
  89.         thingie -> what = rand() % 128;
  90.         if (!(rand() % 5))    /* sometimes put thing into inverse */
  91.             thingie -> what += 128;
  92.         thingie -> colour = rand() % 8;
  93.         if (rand() % 2) thingie -> colour += 16;
  94.         thingie -> trail = rand() % 30 ? trails : !trails;
  95.         thingie -> speedd = dspeedt[rand() % 20];
  96.         thingie -> speeda = aspeedt[rand() % 20] *
  97.                     ((rand() % 2) * 2 - 1);
  98.         if (thingie -> zigzag = !(rand() % 5)) {
  99.             thingie -> zigmag = (rand() % 25 + 2) 
  100.                     / abs(thingie -> speeda);
  101.             thingie -> zigpos = thingie -> zigmag / 2;
  102.         }
  103.         thingie -> rowp = -1;
  104.  
  105.         if (!point_source)
  106.             thingie -> colp = thingie -> zigzag ?
  107.             thingie->zigzag / 2 + 1 + 
  108.             rand() % (width - thingie -> zigmag) :
  109.             rand() % width;
  110.         else
  111.             thingie -> colp = source_point;
  112.      }
  113.      else {                /* else move it down one iteration */
  114.         if (!thingie -> trail)  /* if don't need trails, erase last */
  115.             gotoxy(thingie -> rowp, thingie -> colp,
  116.                 ' ', nuffink);     
  117.  
  118.         if (thingie -> zigzag     /* if in zigzag mode and gone too far*/
  119.         && ++thingie -> zigpos > thingie -> zigmag) {
  120.             thingie -> zigpos = 0;    /* then reverse direction  */
  121.             thingie -> speeda = -thingie -> speeda;
  122.             }
  123.         thingie -> rowp += thingie -> speedd;
  124.         thingie -> colp += thingie -> speeda;
  125.  
  126.         if (thingie -> rowp < length
  127.         && thingie -> colp > -1
  128.         && thingie -> colp < width )
  129.             gotoxy(thingie -> rowp, thingie -> colp,
  130.                 thingie -> what, thingie -> colour);
  131.         else                 
  132.             thingie -> what = INACTIVE;
  133.     }
  134. }
  135. if (!halt)
  136.     goto loop;
  137. else    goto start;
  138. }
  139. /*---------------------------------------------------------------------------*/
  140. gotoxy(row,column,what,colour)
  141. char    what,colour;
  142. {    char c2;
  143.     int colorram,screen,work;
  144.     if (row < length && column < width) {    /* if still on the screen */
  145.         work = row * width + column;    /* find relative position */
  146.         screen = work + 0xf000;        /* address in screen RAM */
  147.         colorram = work + 0xf800;    /* address in colour RAM */
  148.         outp(8,78);            /* turn on colour RAM */
  149.         poke (colorram,colour);        /* set the colour byte */
  150.         outp(8,14);            /* turn off colour RAM */
  151.         poke (screen,what);        /* put it into screen RAM */
  152.     }
  153.     if (!bios(2)) return;
  154.     if ((c2 = bios(3)) != 0x13) 
  155.         halt = 1;
  156.     if (c2 == 0x13)
  157.             while (1) {
  158.             while (!bios(2)) rand();
  159.             if (bios(3) == 0x11) 
  160.                 break;
  161.              }
  162. }
  163. /*---------------------------------------------------------------------------*/
  164. getnum()
  165. {    int    i,j,n;
  166.     puts(CLEARS);
  167.     outp(8,78);            /* set up for colour RAM and guns on full */
  168.     for (i=0,j=0xf800; i<2048; i++,j++) 
  169.         poke(j,5);         /* set to magenta on black */
  170.     outp(8,14);            /* get back to normal inverse PCG RAM */
  171.     
  172.     printf("\n\nWelcome to Microbee Fallout!\n\n");
  173.     puts(INTOREV);
  174.     n=0;    
  175.     while (n < 1 || n > MAXTHINGS) {
  176.         printf("\rHow many things should I display (1-%d,",MAXTHINGS);
  177.         srand1(" or q to quit) ?   \b\b");
  178.         if (!scanf("%d", &n)) {
  179.             puts(OUTAREV);
  180.             exit();
  181.         }
  182.     }
  183.     return(n);
  184. }
  185. /*---------------------------------------------------------------------------*/
  186. fullsize()
  187. {    char    c;        /* to hold the character sent by the user */
  188.     int     i,j;
  189.     puts(CLEARS);
  190.     outp(8,78);            /* set up for colour RAM and guns on full */
  191.     for (i=0,j=0xf800; i<2048; i++,j++) 
  192.         poke(j,5);         /* set to magenta on black */
  193.     outp(8,14);            /* get back to normal inverse PCG RAM */
  194.     printf("\n\nWelcome to Microbee Fallout!\n\n");
  195.  
  196.     c=' ';
  197.     do {    printf("\rDo you want a 64 * 16 screen? y/n ");
  198.         c = toupper(getchar());    }
  199.     while (c != 'Y' && c != 'N');
  200.     if (c == 'Y')
  201.         return(FALSE);
  202.     else    return(TRUE);
  203. }
  204.  
  205.