2 *************************************************************************
\r
4 * PCX_COMM.C - PCX_LIB Library Common Functions
\r
8 * History: 91/02/14 - Created
\r
9 * 91/04/01 - Release 1.00A
\r
10 * 91/04/03 - fixed "segread" call.
\r
11 * 91/04/07 - Release 1.00B
\r
13 * Compiler: Microsoft C V6.0
\r
15 * Author: Ian Ashdown, P.Eng.
\r
17 * 620 Ballantree Road
\r
18 * West Vancouver, B.C.
\r
20 * Tel. (604) 922-6148
\r
21 * Fax. (604) 987-7621
\r
23 * Copyright: Public Domain
\r
25 *************************************************************************
\r
29 *************************************************************************
\r
33 * 1. While this program is written in ANSI C, it uses a number of
\r
34 * function calls that are specific to the Microsoft C V6.0 library.
\r
35 * These are documented as follows for the purposes of porting this
\r
36 * program to other compilers and/or processors:
\r
38 * int86x - execute 80x86 interrupt routine (far data)
\r
39 * segread - get current 80x86 segment register values
\r
41 *************************************************************************
\r
49 #include "pcx_int.h"
\r
51 /* FORWARD REFERENCES */
\r
55 /* PUBLIC FUNCTIONS */
\r
58 *************************************************************************
\r
60 * PCX_OPEN - Open PCX Workblock
\r
62 * Purpose: To allocate and initialize a PCX image file workblock.
\r
64 * Setup: PCX_WORKBLK *pcx_open
\r
70 * Where: fname is a PCX image file name.
\r
71 * wrt_flag is a Boolean flag which if TRUE indicates that
\r
72 * the PCX image file is to be opened for writing;
\r
73 * otherwise it is opened for reading.
\r
75 * Return: A pointer to a PCX image file workblock if successful;
\r
78 *************************************************************************
\r
81 PCX_WORKBLK *pcx_open
\r
87 PCX_WORKBLK *wbp; /* PCX image file workblock pointer */
\r
89 /* Allocate a workblock */
\r
91 if ((wbp = (PCX_WORKBLK *) malloc(sizeof(PCX_WORKBLK))) == NULL)
\r
94 /* Open the PCX image file in binary mode */
\r
96 if (wrt_flag == FALSE)
\r
97 wbp->fp = fopen(fname, "rb"); /* Open for reading */
\r
99 wbp->fp = fopen(fname, "wb"); /* Open for writing */
\r
101 if (wbp->fp == NULL) /* Check for successful file opening */
\r
103 free(wbp); /* Free the workblock memory */
\r
107 return (wbp); /* Return the workblock pointer */
\r
111 *************************************************************************
\r
113 * PCX_CLOSE - Close PCX Workblock
\r
115 * Purpose: To close a PCX image file and release its workblock
\r
118 * Setup: BOOL pcx_close
\r
123 * Where: wbp is a PCX image file workblock pointer.
\r
125 * Return: TRUE if successful; otherwise FALSE.
\r
127 *************************************************************************
\r
135 free(wbp->palettep); /* Free the extended palette (if it exists) */
\r
137 free(wbp); /* Free the PCX image file workblock */
\r
139 if (fclose(wbp->fp) == EOF) /* Close the PCX image file */
\r
146 *************************************************************************
\r
148 * PCX_ISVGA - Check For VGA Display Adapter
\r
150 * Purpose: To determine whether a display adapter supports VGA BIOS
\r
151 * service routines.
\r
153 * Setup: BOOL pcx_isvga(void)
\r
155 * Return: TRUE if display adapter is VGA-compatible; otherwise
\r
158 *************************************************************************
\r
161 BOOL pcx_isvga(void)
\r
163 unsigned char *vinfop; /* VGA information buffer pointer */
\r
164 union REGS regs; /* 80x86 register values */
\r
165 struct SREGS sregs; /* 80x86 segment register values */
\r
167 /* Allocate a VGA functionality/state information buffer */
\r
169 if ((vinfop = (unsigned char *) malloc(sizeof(unsigned char) * 64)) ==
\r
173 /* Attempt to read the VGA information */
\r
175 regs.h.ah = 0x1b; /* Select "Return VGA Info" BIOS routine */
\r
176 regs.x.bx = 0; /* Implementation type */
\r
178 /* Get the VGA information buffer offset value */
\r
180 regs.x.di = (unsigned int) vinfop;
\r
182 segread(&sregs); /* Get the current DS segment register value */
\r
184 sregs.es = sregs.ds;
\r
186 int86x(0x10, ®s, ®s, &sregs); /* Call BIOS video service */
\r
188 free(vinfop); /* Free the VGA information buffer */
\r
190 /* The value 0x1b is returned in register AL only if a VGA display */
\r
191 /* adapter is present */
\r
193 if (regs.h.al == 0x1b)
\r