]> 4ch.mooo.com Git - 16.git/blob - 16/PCX_LIB/RD_DEMO.C
16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / 16 / PCX_LIB / RD_DEMO.C
1 /*\r
2  *************************************************************************\r
3  *\r
4  *  RD_DEMO.C - PCX_LIB PCX Image File Read Demonstration Program\r
5  *\r
6  *  Version:    1.00B\r
7  *\r
8  *  History:    91/02/14 - Created\r
9  *              91/04/01 - Release 1.00A\r
10  *              91/04/06 - Release 1.00B\r
11  *\r
12  *  Compiler:   Microsoft C V6.0\r
13  *\r
14  *  Author:     Ian Ashdown, P.Eng.\r
15  *              byHeart Software\r
16  *              620 Ballantree Road\r
17  *              West Vancouver, B.C.\r
18  *              Canada V7S 1W3\r
19  *              Tel. (604) 922-6148\r
20  *              Fax. (604) 987-7621\r
21  *\r
22  *  Copyright:  Public Domain\r
23  *\r
24  *************************************************************************\r
25  */\r
26 \f\r
27 /*      INCLUDE FILES                                                   */\r
28 \r
29 #include <stdio.h>\r
30 #include <stdlib.h>\r
31 #include <conio.h>\r
32 #include <graph.h>\r
33 #include "pcx_ext.h"\r
34 \f\r
35 /*      FORWARD REFERENCES                                              */\r
36 \f\r
37 /*      GLOBALS                                                         */\r
38 \r
39 static char *use_msg[] =        /* Program usage message                */\r
40 {\r
41   "  Synopsis:  This public domain program displays a Paintbrush (R) PCX",\r
42   "-format\n             image file.\n\n  Usage:     RD_DEMO filename vi",\r
43   "deo_mode\n\n             where \"filename\" is the name of a PCX-form",\r
44   "at image file and\n             \"video_mode\" is an MS-DOS video mod",\r
45   "e.  Valid values are:\n\n                4   - 320 x 200 4-color CGA",\r
46   "\n                5   - 320 x 200 4-color CGA (color burst off)\n    ",\r
47   "            6   - 640 x 200 2-color CGA\n               13   - 320 x ",\r
48   "200 16-color EGA/VGA\n               14   - 640 x 200 16-color EGA/VG",\r
49   "A\n               15   - 640 x 350 2-color EGA/VGA\n               16",\r
50   "   - 640 x 350 16-color EGA/VGA\n               17   - 640 x 480 2-co",\r
51   "lor VGA\n               18   - 640 x 480 16-color VGA\n              ",\r
52   " 19   - 320 x 200 256-color VGA\n\n             The file must be comp",\r
53   "atible with the indicated video mode.\n",\r
54   (unsigned char *) NULL\r
55 };\r
56 \f\r
57 /*      PUBLIC FUNCTIONS                                                */\r
58 \r
59 /*\r
60  *************************************************************************\r
61  *\r
62  *  MAIN - Executive Function\r
63  *\r
64  *  Purpose:    To read and display a PCX-format image file.\r
65  *\r
66  *  Setup:      int main\r
67  *              (\r
68  *                int argc,\r
69  *                char **argv\r
70  *              )\r
71  *\r
72  *  Where:      argc is the number of command-line arguments.\r
73  *              argv is a pointer to an array of command-line argument\r
74  *                strings.\r
75  *\r
76  *  Return:     0 if successful; otherwise 2.\r
77  *\r
78  *  Note:       Usage is:\r
79  *\r
80  *                RD_DEMO filename video_mode\r
81  *\r
82  *              where:\r
83  *\r
84  *                filename is the name of a PCX-format image file.\r
85  *                video_mode is the MS-DOS video mode.  Valid values are:\r
86  *\r
87  *                    4 -        320 x 200 4-color CGA\r
88  *                    5 -        320 x 200 4-color CGA (color burst off)\r
89  *                    6 -        640 x 200 2-color CGA\r
90  *                   13 -        320 x 200 16-color EGA/VGA\r
91  *                   14 -        640 x 200 16-color EGA/VGA\r
92  *                   15 -        640 x 350 2-color EGA/VGA\r
93  *                   16 -        640 x 350 16-color EGA/VGA\r
94  *                   17 -        640 x 480 2-color VGA\r
95  *                   18 -        640 x 480 16-color VGA\r
96  *                   19 -        320 x 200 256-color VGA\r
97  *\r
98  *************************************************************************\r
99  */\r
100 \r
101 int main\r
102 (\r
103   int argc,\r
104   char **argv\r
105 )\r
106 {\r
107   int i;                /* Scratch counter                              */\r
108   int vmode;            /* Video mode                                   */\r
109   BOOL status = FALSE;  /* Return status                                */\r
110 \r
111   /* Display program title                                              */\r
112 \r
113   puts("\nRD_DEMO - PCX Image File Display Demonstration Program\n");\r
114 \r
115   if (argc == 3)        /* Check for filename and video mode parameters */\r
116   {\r
117     vmode = atoi(argv[2]);      /* Get the video mode                   */\r
118 \r
119     /* Validate the video mode (must be valid MS-DOS graphics mode)     */\r
120 \r
121     if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))\r
122       status = TRUE;\r
123   }\r
124 \r
125   if (status == TRUE)\r
126   {\r
127     if (_setvideomode(vmode) == 0)      /* Set the video mode           */\r
128     {\r
129       /* Report error                                                   */\r
130 \r
131       fprintf(stderr,\r
132           "ERROR: could not set display adapter to mode %d.\n", vmode);\r
133 \r
134       return (2);\r
135     }\r
136 \r
137     /* Read and display the file (assume video page zero)               */\r
138 \r
139     if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)\r
140     {\r
141       while (!kbhit())  /* Wait for a keystroke                         */\r
142         ;\r
143 \r
144       (void) getch();   /* Clear the keyboard buffer                    */\r
145     }\r
146 \r
147     (void) _setvideomode(_DEFAULTMODE);         /* Reset the video mode */\r
148 \r
149     if (status == FALSE)\r
150     {\r
151       /* Report error                                                   */\r
152 \r
153       fprintf(stderr, "\nRD_DEMO - PCX Image File Display Demonstration");\r
154       fprintf(stderr, " Program\n\nERROR: Could not read file %s.\n",\r
155           argv[1]);\r
156     }\r
157   }\r
158   else          /* Display usage information                            */\r
159   {\r
160     while (use_msg[i] != (unsigned char *) NULL)\r
161       fputs(use_msg[i++], stderr);\r
162   }\r
163 \r
164   if (status == TRUE)\r
165     return (0);\r
166   else\r
167     return (2);\r
168 }\r
169 \r