--- /dev/null
+/*\r
+ *************************************************************************\r
+ *\r
+ * PCX_COMM.C - PCX_LIB Library Common Functions\r
+ *\r
+ * Version: 1.00B\r
+ *\r
+ * History: 91/02/14 - Created\r
+ * 91/04/01 - Release 1.00A\r
+ * 91/04/03 - fixed "segread" call.\r
+ * 91/04/07 - Release 1.00B\r
+ *\r
+ * Compiler: Microsoft C V6.0\r
+ *\r
+ * Author: Ian Ashdown, P.Eng.\r
+ * byHeart Software\r
+ * 620 Ballantree Road\r
+ * West Vancouver, B.C.\r
+ * Canada V7S 1W3\r
+ * Tel. (604) 922-6148\r
+ * Fax. (604) 987-7621\r
+ *\r
+ * Copyright: Public Domain\r
+ *\r
+ *************************************************************************\r
+ */\r
+\f\r
+/*\r
+ *************************************************************************\r
+ *\r
+ * PORTABILITY NOTES\r
+ *\r
+ * 1. While this program is written in ANSI C, it uses a number of \r
+ * function calls that are specific to the Microsoft C V6.0 library.\r
+ * These are documented as follows for the purposes of porting this\r
+ * program to other compilers and/or processors: \r
+ *\r
+ * int86x - execute 80x86 interrupt routine (far data)\r
+ * segread - get current 80x86 segment register values\r
+ *\r
+ *************************************************************************\r
+ */\r
+\f\r
+/* INCLUDE FILES */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <dos.h>\r
+#include "pcx_int.h"\r
+\f\r
+/* FORWARD REFERENCES */\r
+\f\r
+/* GLOBALS */\r
+\f\r
+/* PUBLIC FUNCTIONS */\r
+\r
+/*\r
+ *************************************************************************\r
+ *\r
+ * PCX_OPEN - Open PCX Workblock\r
+ *\r
+ * Purpose: To allocate and initialize a PCX image file workblock.\r
+ *\r
+ * Setup: PCX_WORKBLK *pcx_open\r
+ * (\r
+ * char *fname,\r
+ * BOOL wrt_flag\r
+ * )\r
+ *\r
+ * Where: fname is a PCX image file name.\r
+ * wrt_flag is a Boolean flag which if TRUE indicates that\r
+ * the PCX image file is to be opened for writing;\r
+ * otherwise it is opened for reading.\r
+ *\r
+ * Return: A pointer to a PCX image file workblock if successful;\r
+ * otherwise NULL.\r
+ *\r
+ *************************************************************************\r
+ */\r
+\r
+PCX_WORKBLK *pcx_open\r
+(\r
+ char *fname,\r
+ BOOL wrt_flag\r
+)\r
+{\r
+ PCX_WORKBLK *wbp; /* PCX image file workblock pointer */\r
+\r
+ /* Allocate a workblock */\r
+\r
+ if ((wbp = (PCX_WORKBLK *) malloc(sizeof(PCX_WORKBLK))) == NULL)\r
+ return (NULL);\r
+\r
+ /* Open the PCX image file in binary mode */\r
+\r
+ if (wrt_flag == FALSE)\r
+ wbp->fp = fopen(fname, "rb"); /* Open for reading */\r
+ else\r
+ wbp->fp = fopen(fname, "wb"); /* Open for writing */\r
+\r
+ if (wbp->fp == NULL) /* Check for successful file opening */\r
+ {\r
+ free(wbp); /* Free the workblock memory */\r
+ return (NULL);\r
+ }\r
+\r
+ return (wbp); /* Return the workblock pointer */\r
+}\r
+\f\r
+/*\r
+ *************************************************************************\r
+ *\r
+ * PCX_CLOSE - Close PCX Workblock\r
+ *\r
+ * Purpose: To close a PCX image file and release its workblock\r
+ * memory.\r
+ *\r
+ * Setup: BOOL pcx_close\r
+ * (\r
+ * PCX_WORKBLK *wbp\r
+ * )\r
+ *\r
+ * Where: wbp is a PCX image file workblock pointer.\r
+ *\r
+ * Return: TRUE if successful; otherwise FALSE.\r
+ *\r
+ *************************************************************************\r
+ */\r
+\r
+BOOL pcx_close\r
+(\r
+ PCX_WORKBLK *wbp\r
+)\r
+{\r
+ free(wbp->palettep); /* Free the extended palette (if it exists) */\r
+\r
+ free(wbp); /* Free the PCX image file workblock */\r
+\r
+ if (fclose(wbp->fp) == EOF) /* Close the PCX image file */\r
+ return (FALSE);\r
+\r
+ return (TRUE);\r
+}\r
+\f\r
+/*\r
+ *************************************************************************\r
+ *\r
+ * PCX_ISVGA - Check For VGA Display Adapter\r
+ *\r
+ * Purpose: To determine whether a display adapter supports VGA BIOS\r
+ * service routines.\r
+ *\r
+ * Setup: BOOL pcx_isvga(void)\r
+ *\r
+ * Return: TRUE if display adapter is VGA-compatible; otherwise\r
+ * FALSE.\r
+ *\r
+ *************************************************************************\r
+ */\r
+\r
+BOOL pcx_isvga(void)\r
+{\r
+ unsigned char *vinfop; /* VGA information buffer pointer */\r
+ union REGS regs; /* 80x86 register values */\r
+ struct SREGS sregs; /* 80x86 segment register values */\r
+\r
+ /* Allocate a VGA functionality/state information buffer */\r
+\r
+ if ((vinfop = (unsigned char *) malloc(sizeof(unsigned char) * 64)) ==\r
+ NULL)\r
+ return (FALSE);\r
+\r
+ /* Attempt to read the VGA information */\r
+\r
+ regs.h.ah = 0x1b; /* Select "Return VGA Info" BIOS routine */\r
+ regs.x.bx = 0; /* Implementation type */\r
+\r
+ /* Get the VGA information buffer offset value */\r
+\r
+ regs.x.di = (unsigned int) vinfop;\r
+\r
+ segread(&sregs); /* Get the current DS segment register value */\r
+\r
+ sregs.es = sregs.ds;\r
+\r
+ int86x(0x10, ®s, ®s, &sregs); /* Call BIOS video service */\r
+\r
+ free(vinfop); /* Free the VGA information buffer */\r
+\r
+ /* The value 0x1b is returned in register AL only if a VGA display */\r
+ /* adapter is present */\r
+\r
+ if (regs.h.al == 0x1b)\r
+ return (TRUE);\r
+ else\r
+ return (FALSE);\r
+}\r
+\r