home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG005.ARC
/
FALLOUT.C
< prev
next >
Wrap
Text File
|
1979-12-31
|
7KB
|
205 lines
/* FALLOUT for the Colour Microbee
This is a logical extension of "flyby.c" written by Leor Zolman
July 18, 1980 (I promise to stop playing with the H19
and put more work into the v1.4 code
optimizer...tomorrow!)
*/
#include "bdscio.h"
#define MAXTHINGS 50 /* Maximum # of objects on the screen at once */
#define INACTIVE 0
struct thing {
char what; /* Either an Ascii value, or INACTIVE */
char rev; /* True if character to be displayed in reverse */
int rowp; /* Row position of thing */
int colp; /* Column position of thing */
int speedd; /* Down speed */
int speeda; /* Across speed (signed to indicate left or right) */
char trail; /* True if displaying trail */
char zigzag; /* True if zigzag-ing */
int zigmag; /* if zigzag-ing, magnitude of zig and zag */
int zigpos; /* Count of how many zigs or zags have been done */
char colour; /* Colour of the thing */
};
char halt; /* goes true when user aborts */
int length,width; /* length and width of the screen */
/*---------------------------------------------------------------------------*/
main(argc,argv)
char **argv;
{
struct thing thingtab[MAXTHINGS], *thingie;
int dspeedt[20], aspeedt[20]; /* Tables of possible speeds */
int i,j,nthings; /* loop variables, and # of active things */
char inrev; /* true if in reverse video */
char trails; /* true if displaying all trails */
char insert_mode; /* true when insert mode is activated */
char point_source; /* true if all things coming from one point */
int source_point; /* if point_source true, the horiz pos */
char nuffink; /* black foreground and background */
initw(dspeedt,"1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5");
initw(aspeedt,"0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7");
point_source = trails = insert_mode = FALSE;
nuffink = 0;
/*---------------------------------------------------------------------------*/
if (fullsize() == TRUE) {
length=25; width=80; }
else {
length=17; width=64;
call(0xe01e); /* set it up for 64 * 16 screen image */
call(0xe02a); } /* copy in correct inverse characters */
start:
nthings = getnum(); /* get number of things to display */
puts(CLEARS); puts(OUTAREV);
outp(8,78); /* set up for colour RAM and guns on full */
for (i=0,j=0xf800; i<2048; i++,j++)
poke(j,nuffink); /* clear the colour byte */
outp(8,0); /* get back to normal inverse PCG RAM */
halt = inrev = FALSE;
for (i=0; i<nthings; i++) /* clear out the table of things */
thingtab[i].what = INACTIVE;
/*---------------------------------------------------------------------------*/
loop:
if (!(rand() % 99)) { /* if point source off, make */
point_source = TRUE; /* it tough to get it turned */
source_point = rand() % (width-1); /* on.. */
} else if (point_source && !(rand() % 50)) /* easier to turn off.. */
point_source = FALSE;
if (trails)
if (!(rand() % 2)) /* if trails on, lean toward */
trails = FALSE; /* toward turning them off */
else trails = TRUE;
else if (!(rand() % (MAXTHINGS - nthings + 20))) /* if trails off */
trails = TRUE; /* lean to keeping 'em off */
if (!(rand() % ((2 * MAXTHINGS + 5) - nthings * 2 )))
puts(CLEARS); /* clear the screen */
if (!(rand() % 200))
insert_mode = !insert_mode;
for (i=0; i<nthings; i++) { /* now process each thing in turn */
thingie = thingtab[i]; /* get pointer to current thing */
if (!thingie -> what) { /* if it is inactive, create it: */
thingie -> what = rand() % 128;
if (!(rand() % 5)) /* sometimes put thing into inverse */
thingie -> what += 128;
thingie -> colour = rand() % 8;
if (rand() % 2) thingie -> colour += 16;
thingie -> trail = rand() % 30 ? trails : !trails;
thingie -> speedd = dspeedt[rand() % 20];
thingie -> speeda = aspeedt[rand() % 20] *
((rand() % 2) * 2 - 1);
if (thingie -> zigzag = !(rand() % 5)) {
thingie -> zigmag = (rand() % 25 + 2)
/ abs(thingie -> speeda);
thingie -> zigpos = thingie -> zigmag / 2;
}
thingie -> rowp = -1;
if (!point_source)
thingie -> colp = thingie -> zigzag ?
thingie->zigzag / 2 + 1 +
rand() % (width - thingie -> zigmag) :
rand() % width;
else
thingie -> colp = source_point;
}
else { /* else move it down one iteration */
if (!thingie -> trail) /* if don't need trails, erase last */
gotoxy(thingie -> rowp, thingie -> colp,
' ', nuffink);
if (thingie -> zigzag /* if in zigzag mode and gone too far*/
&& ++thingie -> zigpos > thingie -> zigmag) {
thingie -> zigpos = 0; /* then reverse direction */
thingie -> speeda = -thingie -> speeda;
}
thingie -> rowp += thingie -> speedd;
thingie -> colp += thingie -> speeda;
if (thingie -> rowp < length
&& thingie -> colp > -1
&& thingie -> colp < width )
gotoxy(thingie -> rowp, thingie -> colp,
thingie -> what, thingie -> colour);
else
thingie -> what = INACTIVE;
}
}
if (!halt)
goto loop;
else goto start;
}
/*---------------------------------------------------------------------------*/
gotoxy(row,column,what,colour)
char what,colour;
{ char c2;
int colorram,screen,work;
if (row < length && column < width) { /* if still on the screen */
work = row * width + column; /* find relative position */
screen = work + 0xf000; /* address in screen RAM */
colorram = work + 0xf800; /* address in colour RAM */
outp(8,78); /* turn on colour RAM */
poke (colorram,colour); /* set the colour byte */
outp(8,14); /* turn off colour RAM */
poke (screen,what); /* put it into screen RAM */
}
if (!bios(2)) return;
if ((c2 = bios(3)) != 0x13)
halt = 1;
if (c2 == 0x13)
while (1) {
while (!bios(2)) rand();
if (bios(3) == 0x11)
break;
}
}
/*---------------------------------------------------------------------------*/
getnum()
{ int i,j,n;
puts(CLEARS);
outp(8,78); /* set up for colour RAM and guns on full */
for (i=0,j=0xf800; i<2048; i++,j++)
poke(j,5); /* set to magenta on black */
outp(8,14); /* get back to normal inverse PCG RAM */
printf("\n\nWelcome to Microbee Fallout!\n\n");
puts(INTOREV);
n=0;
while (n < 1 || n > MAXTHINGS) {
printf("\rHow many things should I display (1-%d,",MAXTHINGS);
srand1(" or q to quit) ? \b\b");
if (!scanf("%d", &n)) {
puts(OUTAREV);
exit();
}
}
return(n);
}
/*---------------------------------------------------------------------------*/
fullsize()
{ char c; /* to hold the character sent by the user */
int i,j;
puts(CLEARS);
outp(8,78); /* set up for colour RAM and guns on full */
for (i=0,j=0xf800; i<2048; i++,j++)
poke(j,5); /* set to magenta on black */
outp(8,14); /* get back to normal inverse PCG RAM */
printf("\n\nWelcome to Microbee Fallout!\n\n");
c=' ';
do { printf("\rDo you want a 64 * 16 screen? y/n ");
c = toupper(getchar()); }
while (c != 'Y' && c != 'N');
if (c == 'Y')
return(FALSE);
else return(TRUE);
}