home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
KALEIDS.ZIP
/
KALEIDST.C
< prev
next >
Wrap
Text File
|
1988-09-08
|
15KB
|
503 lines
/*
* **************************************************
* * *
* * KALEDIS.C *
* * *
* * EGA/VGA Kaleidoscope *
* * *
* * Version 3.1 09-08-88 *
* * *
* * Judson D. McClendon *
* * 329 37th Court N.E. *
* * Birmingham, AL 35215 *
* * 205-853-8440 *
* * Compuserve [74415,1003] *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Includes *
* * *
* **************************************************
*/
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\timeb.h>
/*
* **************************************************
* * *
* * Function Declarations *
* * *
* **************************************************
*/
void main(void);
void Initialize(void);
int GetChar(void);
int KeyPressed(void);
void ScrClr(void);
void WriteAt(int row,int col,char *str);
long TimerTicks(void);
/*
* **************************************************
* * *
* * Defines *
* * *
* **************************************************
*/
#define TRUE 1
#define FALSE 0
#define ESC 27
#define COLORSCREEN 0xB8000000L /* Color buffer address */
/*
* **************************************************
* * *
* * Data Types *
* * *
* **************************************************
*/
typedef struct { /* Screen char struct */
char
data,
attr;
} CHTYPE;
typedef struct { /* Screen memory structure */
CHTYPE ch[25][80];
} far *SCREENTYPE;
/*
* **************************************************
* * *
* * Global Variables *
* * *
* **************************************************
*/
int X1, Y1, X2, Y2, XV1, YV1, XV2, YV2, HC, XA, YA, XB, YB, chr;
int i, bc = 1, dely = 0;
int wid = 4, hgt = 3;
int CX = 320, CY = 240, M = 240;
int Red[MAXCOLORS+1], Green[MAXCOLORS+1], Blue[MAXCOLORS+1];
long dummy = 0;
SCREENTYPE /* Screen pointer */
scr;
int
arow = 0, /* Absolute row */
acol = 0; /* Absolute column */
union REGS
cpu; /* CPU registers for int86() */
struct timeb TIME; /* Time structure */
/*
* **************************************************
* * *
* * Main *
* * *
* **************************************************
*/
void main()
{
Initialize();
while (TRUE) {
cleardevice();
if (bc)
setrgbpalette(0, 0, 0, 0);
for (i = bc; i <= MAXCOLORS; i++) {
Red[i] = random(64);
Green[i] = random(64);
Blue[i] = random(64);
setrgbpalette(i, Red[i], Green[i], Blue[i]);
}
X1 = random(M) + 1;
X2 = random(M) + 1;
Y1 = random(X1);
Y2 = random(X2);
while (random(130) > 1) {
XV1 = random(5) - 2;
XV2 = random(5) - 2;
YV1 = random(5) - 2;
YV2 = random(5) - 2;
HC = random(16);
setcolor(HC);
while (random(30) > 1) {
XA = X1 * wid / hgt;
XB = X2 * wid / hgt;
YA = Y1 * wid / hgt;
YB = Y2 * wid / hgt;
line( (CX+XA), (CY-Y1), (CX+XB), (CY-Y2) );
line( (CX-YA), (CY+X1), (CX-YB), (CY+X2) );
line( (CX-XA), (CY-Y1), (CX-XB), (CY-Y2) );
line( (CX-YA), (CY-X1), (CX-YB), (CY-X2) );
line( (CX-XA), (CY+Y1), (CX-XB), (CY+Y2) );
line( (CX+YA), (CY-X1), (CX+YB), (CY-X2) );
line( (CX+XA), (CY+Y1), (CX+XB), (CY+Y2) );
line( (CX+YA), (CY+X1), (CX+YB), (CY+X2) );
X1 = (X1 + XV1) % M;
Y1 = (Y1 + YV1) % M;
X2 = (X2 + XV2) % M;
Y2 = (Y2 + YV2) % M;
if (dely) {
for (i = 1; i < dely; i++) {
dummy += i * dely;
dummy -= dely;
}
}
}
if (chr = KeyPressed()) {
if (chr == 'P') {
GetChar();
}
else if (chr == ESC) {
cleardevice();
closegraph();
exit(0);
}
else if (chr == 'C') {
break;
}
else if (chr == 'B') {
bc = 1 - bc;
break;
}
else if (isdigit(chr)) {
dely = ('9' - chr) * 1000;
}
}
} /* while (line) */
} /* while (screen) */
closegraph();
exit(0);
}
/*
* **************************************************
* * *
* * Initialize *
* * *
* **************************************************
*/
void Initialize()
{
int GraphDriver, GraphMode;
long endtime;
cpu.h.ah = 15; /* Get current video mode */
int86(16, &cpu, &cpu);
if (cpu.h.al != 3) { /* 80x25 color */
puts("Display must be 80x25 color");
exit(1);
}
scr = (SCREENTYPE)((void far *)COLORSCREEN); /* Screen memory pointer */
ftime(&TIME); /* Initialize random number generator */
srand(TIME.millitm);
ScrClr();
WriteAt( 1, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
WriteAt( 2, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
WriteAt( 3, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
WriteAt( 4, 2, "KaledisKaledisKaledisKal┌───────────────────────────┐disKaledisKaledisKaledis");
WriteAt( 5, 2, "KaledisKaledisKaledisKal│ K A L E I D O S C O P E │disKaledisKaledisKaledis");
WriteAt( 6, 2, "KaledisKaledisKaledisKal│ │disKaledisKaledisKaledis");
WriteAt( 7, 2, "KaledisKaledisKaledisKal│ Version 3.1 for EGA/VGA │disKaledisKaledisKaledis");
WriteAt( 8, 2, "KaledisKaledisKaledisKal│ │disKaledisKaledisKaledis");
WriteAt( 9, 2, "KaledisKaledisKaledisKal│ Judson D. McClendon │disKaledisKaledisKaledis");
WriteAt(10, 2, "KaledisKaledisKaledisKal│ 329 37th Court N.E. │disKaledisKaledisKaledis");
WriteAt(11, 2, "KaledisKaledisKaledisKal│ Birmingham, AL 35215 │disKaledisKaledisKaledis");
WriteAt(12, 2, "KaledisKaledisKaledisKal│ 205-853-8440 │disKaledisKaledisKaledis");
WriteAt(13, 2, "KaledisKaledisKaledisKal│ Compuserve [74415,1003] │disKaledisKaledisKaledis");
WriteAt(14, 2, "KaledisKaledisKaledisKal│ │disKaledisKaledisKaledis");
WriteAt(15, 2, "KaledisKaledisKaledisKal│ Press: to: │disKaledisKaledisKaledis");
WriteAt(16, 2, "KaledisKaledisKaledisKal│ 'P' pause │disKaledisKaledisKaledis");
WriteAt(17, 2, "KaledisKaledisKaledisKal│ 'C' clear screen │disKaledisKaledisKaledis");
WriteAt(18, 2, "KaledisKaledisKaledisKal│ 'B' toggle background │disKaledisKaledisKaledis");
WriteAt(19, 2, "KaledisKaledisKaledisKal│ '0'-'9' set speed │disKaledisKaledisKaledis");
WriteAt(20, 2, "KaledisKaledisKaledisKal│ ESCape exit │disKaledisKaledisKaledis");
WriteAt(21, 2, "KaledisKaledisKaledisKal│ any key begin/resume... │disKaledisKaledisKaledis");
WriteAt(22, 2, "KaledisKaledisKaledisKal└───────────────────────────┘disKaledisKaledisKaledis");
WriteAt(23, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
WriteAt(24, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
WriteAt(25, 2, "KaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledisKaledis");
cpu.h.ah = 2; /* Move cursor to row 0, col 0 */
cpu.h.bh = 0;
cpu.x.dx = 0;
int86(16, &cpu, &cpu);
scr->ch[0][0].attr = 0; /* Set cursor color to black on black */
do { /* Kaleidoscope title */
for (arow = 0; arow < 25; arow++)
for (acol = 1; acol < 78; acol++)
if (arow < 6 || arow > 20 || acol < 26 || acol > 52)
if (!(--scr->ch[arow][acol].attr))
scr->ch[arow][acol].attr = 15;
endtime = TimerTicks() + 1; /* Wait one tick */
while (TimerTicks() < endtime)
;
} while (! (chr = KeyPressed()) );
ScrClr();
if (chr == ESC) {
exit(0);
}
registerbgidriver(EGAVGA_driver);
GraphDriver = VGA;
GraphMode = VGAHI;
initgraph(&GraphDriver, &GraphMode, ""); /* Try VGA 640x480x16 color */
if (graphresult()) {
CY = 175;
wid = 9;
hgt = 5;
GraphDriver = EGA;
GraphMode = EGAHI;
initgraph(&GraphDriver, &GraphMode, ""); /* Try EGA 640x350x16 color */
if (graphresult()) {
puts("Display must be EGA or VGA");
closegraph();
exit(1);
}
}
M = CY - 1;
}
/*
* **************************************************
* * *
* * Keyboard Routines *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Get decoded character from kbd *
* * *
* **************************************************
*/
int GetChar(void)
{
int chr;
chr = getch();
if (chr == 0)
chr = 1000 + getch(); /* Non ASCII character */
else
if (isascii(chr) )
chr = toupper(chr);
return(chr);
}
/*
* **************************************************
* * *
* * Return character if key pressed *
* * *
* **************************************************
*/
int KeyPressed(void)
{
if (kbhit())
return(GetChar());
else
return(0);
}
/*
* **************************************************
* * *
* * Screen Routines *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Clear the Screen *
* * *
* **************************************************
*/
void ScrClr(void)
{
CHTYPE byte, far *pos, far *pend;
pos = &scr->ch[0][0];
pend = pos + 2000;
byte.data = ' ';
byte.attr = 7;
while (pos < pend)
*pos++ = byte;
}
/*
* **************************************************
* * *
* * Write String at row, col to Screen *
* * *
* **************************************************
*/
void WriteAt(int row, int col, char *str)
{
int i, n, x, y, color, lst;
arow = row - 1;
acol = col - 1;
while (*str) {
if (arow > 5 && arow < 21 && acol > 25 && acol < 53) {
color = 15;
}
else {
x = abs(39 - acol);
y = abs(12 - arow);
n = x*x + y*y;
lst = n >> 1;
for (i = 1; i < 5; i++) {
if (! lst) {
color = 0;
break;
}
color = (n / lst + lst) >> 1;
lst = color;
}
color = (color % 15) + 1;
}
scr->ch[arow][acol].data = *(str++);
scr->ch[arow][acol].attr = (char)color;
if (++acol > 79) {
arow++;
acol = 0;
}
}
}
/*
* **************************************************
* * *
* * Miscellaneous Routines *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Fetch Timer Ticks since Midnight *
* * *
* **************************************************
*/
long TimerTicks(void)
{
static long ticks;
cpu.h.ah = 0;
int86(0x1A, &cpu, &cpu);
ticks = (((long) cpu.x.cx) << 16) + ((long) cpu.x.dx);
return(ticks);
}