home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
KALEIDS.ZIP
/
KALEIDSQ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-09-08
|
16KB
|
528 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 <graph.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys\timeb.h>
/*
* **************************************************
* * *
* * Function Declarations *
* * *
* **************************************************
*/
extern void main(void);
static void Initialize(void);
static int GetChar(void);
static int KeyPressed(void);
static void ScrClr(void);
static void WriteAt(int row,int col,char *str);
static int Random(int r);
static long TimerTicks(void);
/*
* **************************************************
* * *
* * Defines *
* * *
* **************************************************
*/
#define TRUE 1
#define FALSE 0
#define ESC 27
#define MAXCOLORS 16 /* Color Palette size */
#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, delay = 0;
int wid = 4, hgt = 3;
int CX = 320, CY = 240, M = 240;
long Pcol[MAXCOLORS];
long Red, Green, Blue;
long dummy = 0;
static SCREENTYPE /* Screen pointer */
scr;
static int
arow = 0, /* Absolute row */
acol = 0; /* Absolute column */
static union REGS
cpu; /* CPU registers for int86() */
struct timeb TIME; /* Time structure */
struct videoconfig VC; /* Video configuration structure */
/*
* **************************************************
* * *
* * Main *
* * *
* **************************************************
*/
extern void main()
{
Initialize();
while (TRUE) {
Pcol[0] = 0L;
Pcol[0] = 0L;
for (i = bc; i < MAXCOLORS; i++) {
Red = (long)Random(64);
Green = (long)Random(64);
Blue = (long)Random(64);
Pcol[i] = ((Blue << 8 | Green) << 8 | Red);
}
_remapallpalette((long far *)&Pcol[0]);
_clearscreen(_GCLEARSCREEN);
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;
_moveto( (CX+XA), (CY-Y1) ); _lineto( (CX+XB), (CY-Y2) );
_moveto( (CX-YA), (CY+X1) ); _lineto( (CX-YB), (CY+X2) );
_moveto( (CX-XA), (CY-Y1) ); _lineto( (CX-XB), (CY-Y2) );
_moveto( (CX-YA), (CY-X1) ); _lineto( (CX-YB), (CY-X2) );
_moveto( (CX-XA), (CY+Y1) ); _lineto( (CX-XB), (CY+Y2) );
_moveto( (CX+YA), (CY-X1) ); _lineto( (CX+YB), (CY-X2) );
_moveto( (CX+XA), (CY+Y1) ); _lineto( (CX+XB), (CY+Y2) );
_moveto( (CX+YA), (CY+X1) ); _lineto( (CX+YB), (CY+X2) );
X1 = (X1 + XV1) % M;
Y1 = (Y1 + YV1) % M;
X2 = (X2 + XV2) % M;
Y2 = (Y2 + YV2) % M;
if (delay) {
for (i = 0; i < delay; i++) {
dummy += i * delay;
dummy -= delay;
}
}
}
if (chr = KeyPressed()) {
if (chr == 'P') {
GetChar();
}
else if (chr == ESC) {
_clearscreen(_GCLEARSCREEN);
_setvideomode(_DEFAULTMODE);
exit(0);
}
else if (chr == 'C') {
break;
}
else if (chr == 'B') {
bc = 1 - bc;
break;
}
else if (isdigit(chr)) {
delay = ('9' - chr) * 3000;
}
}
} /* while (line) */
} /* while (screen) */
_setvideomode(_DEFAULTMODE);
exit(0);
}
/*
* **************************************************
* * *
* * Initialize *
* * *
* **************************************************
*/
void Initialize()
{
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 in 80x25 color mode");
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);
}
_getvideoconfig(&VC); /* Save video configuration */
if (! _setvideomode(_VRES16COLOR)) { /* Try VGA 640x480x16 color */
CY = 175;
wid = 9;
hgt = 5;
if (! _setvideomode(_ERESCOLOR)) { /* Try EGA 640x350x16 color */
puts("Display must be EGA or VGA");
_setvideomode(_DEFAULTMODE);
exit(1);
}
}
M = CY - 1;
}
/*
* **************************************************
* * *
* * Keyboard Routines *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Get decoded character from kbd *
* * *
* **************************************************
*/
static 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 *
* * *
* **************************************************
*/
static int KeyPressed(void)
{
if (kbhit())
return(GetChar());
else
return(0);
}
/*
* **************************************************
* * *
* * Screen Routines *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Clear the Screen *
* * *
* **************************************************
*/
static 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 *
* * *
* **************************************************
*/
static 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 *
* * *
* **************************************************
*/
/*
* **************************************************
* * *
* * Generate Random Number 0 to r *
* * *
* **************************************************
*/
static int Random(int r)
{
int s;
long t;
s = rand();
t = (long) s * r / 32768;
return((int) t);
}
/*
* **************************************************
* * *
* * Fetch Timer Ticks since Midnight *
* * *
* **************************************************
*/
static 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);
}