home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
FGDEMO40.ZIP
/
SOURCE.COM
/
COMMON.C
< prev
next >
Wrap
Text File
|
1995-02-12
|
6KB
|
218 lines
/**********************************************************************\
* *
* common.c -- routines common to many FGDEMO modules *
* *
\**********************************************************************/
#define _commonc_
#include "defs.h"
/**********************************************************************\
* *
* abort_program -- called when the program can't be run *
* *
\**********************************************************************/
void abort_program(char *abort_string)
{
/* reset the mode to what it was */
fg_setmode(old_mode);
fg_reset();
/* print a line that will stay on the screen after the program exits */
printf("\n");
printf(abort_string);
exit(0);
}
/**********************************************************************\
* *
* exists -- does the file exist? *
* *
\**********************************************************************/
exists(char *filename)
{
if (access(filename,0) == 0)
return(TRUE);
else
return(FALSE);
}
/**********************************************************************\
* *
* flushkey -- flush out the keystroke buffer and the mouse buttons *
* *
\**********************************************************************/
void flushkey()
{
int dummy;
unsigned char key, aux;
if (mouse)
{
fg_mousebut(1,&dummy,&dummy,&dummy);
fg_mousebut(2,&dummy,&dummy,&dummy);
}
do
fg_intkey(&key,&aux);
while (key+aux > 0);
}
/**********************************************************************\
* *
* initialize -- initialize the Fastgraph environment for mode 16 *
* *
\**********************************************************************/
void initialize()
{
/* Switch to mode 16 */
fg_setmode(16);
/* Set up visual and hidden pages */
fg_sethpage(1);
visual = 0;
hidden = 1;
background = 0;
/* get screen extents */
xlimit = fg_getmaxx();
ylimit = fg_getmaxy();
/* initialize the mouse if present */
init_mouse();
fg_mousevis(OFF);
}
/**********************************************************************\
* *
* init_mouse -- initialize the mouse if present *
* *
\**********************************************************************/
void init_mouse()
{
if (fg_mouseini() > 0)
{
mouse = TRUE;
fg_mouselim(6,xlimit-5,0,ylimit);
xmouse = xlimit / 2;
ymouse = ylimit / 2;
fg_mousemov(xmouse,ymouse);
fg_mousevis(ON);
}
else
mouse = FALSE;
}
/**********************************************************************\
* *
* printer_ready -- is the printer on line? *
* *
\**********************************************************************/
printer_ready()
{
static union REGS registers;
registers.h.ah = 2;
#ifdef FG32
registers.x.edx = 0;
int386(0x17,®isters,®isters);
#else
registers.x.dx = 0;
int86(0x17,®isters,®isters);
#endif
return(registers.h.ah == 0x90);
}
/**********************************************************************\
* *
* terminate -- perform necessary cleanup and return control to DOS *
* *
\**********************************************************************/
void terminate()
{
/* restore the original video mode and screen attributes */
fg_setmode(old_mode);
fg_reset();
/* return control to DOS */
exit(0);
}
/**********************************************************************\
* *
* wait_for_keystroke -- wait for a keystroke or mouse button *
* *
\**********************************************************************/
void wait_for_keystroke()
{
int buttons;
int count;
int x, y;
unsigned char key, aux;
flushkey();
/* if the mouse is loaded, must loop and wait for button or keystroke */
if (mouse)
{
fg_mousevis(ON);
for(;;)
{
fg_waitfor(1);
fg_intkey(&key,&aux);
if (key+aux > 0) break;
fg_mousebut(1,&count,&x,&y);
if (count > 0) break;
fg_mousebut(2,&count,&x,&y);
if (count > 0) break;
}
do
fg_mousepos(&x,&y,&buttons);
while (buttons&3);
fg_mousevis(OFF);
}
/* if the mouse is not loaded, just wait for a key */
else
fg_getkey(&key,&aux);
}
/**********************************************************************\
* *
* wait_for_mouse_buttons -- wait until no mouse buttons are pressed *
* *
\**********************************************************************/
void wait_for_mouse_buttons()
{
int buttons;
int x, y;
if (mouse)
{
do
fg_mousepos(&x,&y,&buttons);
while (buttons&3);
}
}