home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FGDEMO40.ZIP / SOURCE.COM / COMMON.C < prev    next >
Text File  |  1995-02-12  |  6KB  |  218 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  common.c -- routines common to many FGDEMO modules                  *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #define _commonc_
  8. #include "defs.h"
  9.  
  10. /**********************************************************************\
  11. *                                                                      *
  12. *  abort_program -- called when the program can't be run               *
  13. *                                                                      *
  14. \**********************************************************************/
  15.  
  16. void abort_program(char *abort_string)
  17. {
  18.    /* reset the mode to what it was */
  19.  
  20.    fg_setmode(old_mode);
  21.    fg_reset();
  22.  
  23.    /* print a line that will stay on the screen after the program exits */
  24.  
  25.    printf("\n");
  26.    printf(abort_string);
  27.    exit(0);
  28. }
  29.  
  30. /**********************************************************************\
  31. *                                                                      *
  32. *  exists -- does the file exist?                                      *
  33. *                                                                      *
  34. \**********************************************************************/
  35.  
  36. exists(char *filename)
  37. {
  38.    if (access(filename,0) == 0)
  39.       return(TRUE);
  40.    else
  41.       return(FALSE);
  42. }
  43.  
  44. /**********************************************************************\
  45. *                                                                      *
  46. *  flushkey -- flush out the keystroke buffer and the mouse buttons    *
  47. *                                                                      *
  48. \**********************************************************************/
  49.  
  50. void flushkey()
  51. {
  52.    int dummy;
  53.    unsigned char key, aux;
  54.  
  55.    if (mouse)
  56.    {
  57.       fg_mousebut(1,&dummy,&dummy,&dummy);
  58.       fg_mousebut(2,&dummy,&dummy,&dummy);
  59.    }
  60.  
  61.    do
  62.       fg_intkey(&key,&aux);
  63.    while (key+aux > 0);
  64. }
  65.  
  66.  
  67. /**********************************************************************\
  68. *                                                                      *
  69. *    initialize -- initialize the Fastgraph environment for mode 16    *
  70. *                                                                      *
  71. \**********************************************************************/
  72.  
  73. void initialize()
  74. {
  75.    /* Switch to mode 16 */
  76.  
  77.    fg_setmode(16);
  78.  
  79.    /* Set up visual and hidden pages */
  80.  
  81.    fg_sethpage(1);
  82.    visual = 0;
  83.    hidden = 1;
  84.    background = 0;
  85.  
  86.    /* get screen extents */
  87.  
  88.    xlimit = fg_getmaxx();
  89.    ylimit = fg_getmaxy();
  90.  
  91.    /* initialize the mouse if present */
  92.  
  93.    init_mouse();
  94.    fg_mousevis(OFF);
  95. }
  96.  
  97. /**********************************************************************\
  98. *                                                                      *
  99. *  init_mouse -- initialize the mouse if present                       *
  100. *                                                                      *
  101. \**********************************************************************/
  102.  
  103. void init_mouse()
  104. {
  105.    if (fg_mouseini() > 0)
  106.    {
  107.       mouse = TRUE;
  108.       fg_mouselim(6,xlimit-5,0,ylimit);
  109.       xmouse = xlimit / 2;
  110.       ymouse = ylimit / 2;
  111.       fg_mousemov(xmouse,ymouse);
  112.       fg_mousevis(ON);
  113.    }
  114.    else
  115.       mouse = FALSE;
  116. }
  117.  
  118. /**********************************************************************\
  119. *                                                                      *
  120. *  printer_ready -- is the printer on line?                            *
  121. *                                                                      *
  122. \**********************************************************************/
  123.  
  124. printer_ready()
  125. {
  126.    static union REGS registers;
  127.  
  128.    registers.h.ah = 2;
  129. #ifdef FG32
  130.    registers.x.edx = 0;
  131.    int386(0x17,®isters,®isters);
  132. #else
  133.    registers.x.dx = 0;
  134.    int86(0x17,®isters,®isters);
  135. #endif
  136.    return(registers.h.ah == 0x90);
  137. }
  138.  
  139. /**********************************************************************\
  140. *                                                                      *
  141. *  terminate -- perform necessary cleanup and return control to DOS    *
  142. *                                                                      *
  143. \**********************************************************************/
  144.  
  145. void terminate()
  146. {
  147.    /* restore the original video mode and screen attributes */
  148.  
  149.    fg_setmode(old_mode);
  150.    fg_reset();
  151.  
  152.    /* return control to DOS */
  153.  
  154.    exit(0);
  155. }
  156.  
  157. /**********************************************************************\
  158. *                                                                      *
  159. *  wait_for_keystroke -- wait for a keystroke or mouse button          *
  160. *                                                                      *
  161. \**********************************************************************/
  162.  
  163. void wait_for_keystroke()
  164. {
  165.    int buttons;
  166.    int count;
  167.    int x, y;
  168.    unsigned char key, aux;
  169.  
  170.    flushkey();
  171.  
  172.    /* if the mouse is loaded, must loop and wait for button or keystroke */
  173.  
  174.    if (mouse)
  175.    {
  176.       fg_mousevis(ON);
  177.       for(;;)
  178.       {
  179.          fg_waitfor(1);
  180.          fg_intkey(&key,&aux);
  181.          if (key+aux > 0) break;
  182.          fg_mousebut(1,&count,&x,&y);
  183.          if (count > 0) break;
  184.          fg_mousebut(2,&count,&x,&y);
  185.          if (count > 0) break;
  186.       }
  187.       do
  188.          fg_mousepos(&x,&y,&buttons);
  189.       while (buttons&3);
  190.       fg_mousevis(OFF);
  191.    }
  192.  
  193.    /* if the mouse is not loaded, just wait for a key */
  194.  
  195.    else
  196.       fg_getkey(&key,&aux);
  197. }
  198.  
  199.  
  200. /**********************************************************************\
  201. *                                                                      *
  202. *  wait_for_mouse_buttons -- wait until no mouse buttons are pressed   *
  203. *                                                                      *
  204. \**********************************************************************/
  205.  
  206. void wait_for_mouse_buttons()
  207. {
  208.    int buttons;
  209.    int x, y;
  210.  
  211.    if (mouse)
  212.    {
  213.       do
  214.          fg_mousepos(&x,&y,&buttons);
  215.       while (buttons&3);
  216.    }
  217. }
  218.