home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 350_01 / pcx_comm.c < prev    next >
C/C++ Source or Header  |  1991-12-01  |  6KB  |  200 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  PCX_COMM.C - PCX_LIB Library Common Functions
  5.  *
  6.  *  Version:    1.00C
  7.  *
  8.  *  History:    91/02/14 - Created
  9.  *              91/04/01 - Release 1.00A
  10.  *              91/04/03 - Fixed "segread" call.
  11.  *              91/04/07 - Release 1.00B
  12.  *              91/11/18 - Fixed "pcx_isvga" for large memory model.
  13.  *              91/12/01 - Release 1.00C
  14.  *
  15.  *  Compiler:   Microsoft C V6.0
  16.  *
  17.  *  Author:     Ian Ashdown, P.Eng.
  18.  *              byHeart Software
  19.  *              620 Ballantree Road
  20.  *              West Vancouver, B.C.
  21.  *              Canada V7S 1W3
  22.  *              Tel. (604) 922-6148
  23.  *              Fax. (604) 987-7621
  24.  *
  25.  *  Copyright:  Public Domain
  26.  *
  27.  *************************************************************************
  28.  */
  29.  
  30. /*
  31.  *************************************************************************
  32.  *
  33.  *  PORTABILITY NOTES
  34.  *
  35.  *  1.  While this program is written in ANSI C, it uses a number of 
  36.  *      function calls that are specific to the Microsoft C V6.0 library.
  37.  *      These are documented as follows for the purposes of porting this
  38.  *      program to other compilers and/or processors: 
  39.  *
  40.  *          _ffree      - "free" for small model / far data
  41.  *          _fmalloc    - "malloc" for small model / far data
  42.  *          int86x      - execute 80x86 interrupt routine (far data)
  43.  *
  44.  *************************************************************************
  45.  */
  46.  
  47. /*      INCLUDE FILES                                                   */
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <malloc.h>
  52. #include <dos.h>
  53. #include "pcx_int.h"
  54.  
  55. /*      FORWARD REFERENCES                                              */
  56.  
  57. /*      GLOBALS                                                         */
  58.  
  59. /*      PUBLIC FUNCTIONS                                                */
  60.  
  61. /*
  62.  *************************************************************************
  63.  *
  64.  *  PCX_OPEN - Open PCX Workblock
  65.  *
  66.  *  Purpose:    To allocate and initialize a PCX image file workblock.
  67.  *
  68.  *  Setup:      PCX_WORKBLK *pcx_open
  69.  *              (
  70.  *                char *fname,
  71.  *                BOOL wrt_flag
  72.  *              )
  73.  *
  74.  *  Where:      fname is a PCX image file name.
  75.  *              wrt_flag is a Boolean flag which if TRUE indicates that
  76.  *                the PCX image file is to be opened for writing;
  77.  *                otherwise it is opened for reading.
  78.  *
  79.  *  Return:     A pointer to a PCX image file workblock if successful;
  80.  *              otherwise NULL.
  81.  *
  82.  *************************************************************************
  83.  */
  84.  
  85. PCX_WORKBLK *pcx_open
  86. (
  87.   char *fname,
  88.   BOOL wrt_flag
  89. )
  90. {
  91.   PCX_WORKBLK *wbp;     /* PCX image file workblock pointer             */
  92.  
  93.   /* Allocate a workblock                                               */
  94.  
  95.   if ((wbp = (PCX_WORKBLK *) malloc(sizeof(PCX_WORKBLK))) == NULL)
  96.     return (NULL);
  97.  
  98.   /* Open the PCX image file in binary mode                             */
  99.  
  100.   if (wrt_flag == FALSE)
  101.     wbp->fp = fopen(fname, "rb");       /* Open for reading             */
  102.   else
  103.     wbp->fp = fopen(fname, "wb");       /* Open for writing             */
  104.  
  105.   if (wbp->fp == NULL)  /* Check for successful file opening            */
  106.   {
  107.     free(wbp);          /* Free the workblock memory                    */
  108.     return (NULL);
  109.   }
  110.  
  111.   return (wbp);         /* Return the workblock pointer                 */
  112. }
  113.  
  114. /*
  115.  *************************************************************************
  116.  *
  117.  *  PCX_CLOSE - Close PCX Workblock
  118.  *
  119.  *  Purpose:    To close a PCX image file and release its workblock
  120.  *              memory.
  121.  *
  122.  *  Setup:      BOOL pcx_close
  123.  *              (
  124.  *                PCX_WORKBLK *wbp
  125.  *              )
  126.  *
  127.  *  Where:      wbp is a PCX image file workblock pointer.
  128.  *
  129.  *  Return:     TRUE if successful; otherwise FALSE.
  130.  *
  131.  *************************************************************************
  132.  */
  133.  
  134. BOOL pcx_close
  135. (
  136.   PCX_WORKBLK *wbp
  137. )
  138. {
  139.   free(wbp->palettep);  /* Free the extended palette (if it exists)     */
  140.  
  141.   free(wbp);            /* Free the PCX image file workblock            */
  142.  
  143.   if (fclose(wbp->fp) == EOF)   /* Close the PCX image file             */
  144.     return (FALSE);
  145.  
  146.   return (TRUE);
  147. }
  148.  
  149. /*
  150.  *************************************************************************
  151.  *
  152.  *  PCX_ISVGA - Check For VGA Display Adapter
  153.  *
  154.  *  Purpose:    To determine whether a display adapter supports VGA BIOS
  155.  *              service routines.
  156.  *
  157.  *  Setup:      BOOL pcx_isvga(void)
  158.  *
  159.  *  Return:     TRUE if display adapter is VGA-compatible; otherwise
  160.  *              FALSE.
  161.  *
  162.  *************************************************************************
  163.  */
  164.  
  165. BOOL pcx_isvga(void)
  166. {
  167.   unsigned char _far *vinfop;   /* VGA information buffer pointer       */
  168.   union REGS regs;              /* 80x86 register values                */
  169.   struct SREGS sregs;           /* 80x86 segment register values        */
  170.  
  171.   /* Allocate a VGA functionality/state information buffer              */
  172.  
  173.   if ((vinfop = (unsigned char _far *) _fmalloc(sizeof(unsigned char) *
  174.       64)) == NULL)
  175.     return (FALSE);
  176.  
  177.   /* Attempt to read the VGA information                                */
  178.  
  179.   regs.h.ah = 0x1b;     /* Select "Return VGA Info" BIOS routine        */
  180.   regs.x.bx = 0;        /* Implementation type                          */
  181.  
  182.   /* Get the VGA information buffer segment and offset values           */
  183.  
  184.   sregs.es =  *((unsigned int _far *) &vinfop + 1);
  185.   regs.x.di = *((unsigned int _far *) &vinfop);
  186.  
  187.   int86x(0x10, ®s, ®s, &sregs);   /* Call BIOS video service      */
  188.  
  189.   _ffree(vinfop);       /* Free the VGA information buffer              */
  190.  
  191.   /* The value 0x1b is returned in register AL only if a VGA display    */
  192.   /* adapter is present                                                 */
  193.  
  194.   if (regs.h.al == 0x1b)
  195.     return (TRUE);
  196.   else
  197.     return (FALSE);
  198. }
  199.  
  200.