PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
linuxvga.c
Go to the documentation of this file.
1 // $Id: linuxvga.c 11293 2010-11-01 19:54:24Z airwin $
2 //
3 // S. Fanchiotti (Using gnusvga.c by Geoffrey Furnish)
4 // 4 May 1993
5 //
6 // This file constitutes the driver for an VGA display under Linux
7 // using the GNU CC compiler and vgalib 1.2 library by T. Fradsen
8 //
9 // Things to note: NEEDS vgalib to compile!!!!!
10 //
11 //
12 #include "plDevs.h"
13 
14 #ifdef PLD_linuxvga // Only compile for Linux + Vgalib 1.2
15 
16 #include "plplotP.h"
17 #include "drivers.h"
18 #include <vga.h>
19 
20 // Device info
21 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_linuxvga = "linuxvga:Linux VGA driver:0:linuxvga:8:vga\n";
22 
23 
24 // Function prototypes
25 
26 void plD_init_vga( PLStream * );
27 void plD_line_vga( PLStream *, short, short, short, short );
28 void plD_polyline_vga( PLStream *, short *, short *, PLINT );
29 void plD_eop_vga( PLStream * );
30 void plD_bop_vga( PLStream * );
31 void plD_tidy_vga( PLStream * );
32 void plD_state_vga( PLStream *, PLINT );
33 void plD_esc_vga( PLStream *, PLINT, void * );
34 
35 static void lxvga_text( PLStream *pls );
36 static void lxvga_graph( PLStream *pls );
37 static void lxvga_pause( PLStream *pls );
38 
39 static PLINT vgax = 639;
40 static PLINT vgay = 479;
41 
42 // A flag to tell us whether we are in text or graphics mode
43 
44 #define TEXT_MODE 0
45 #define GRAPHICS_MODE 1
46 
47 // gmf; should probably query this on start up... Maybe later.
48 // sf; Will set them dynamically!
49 
50 static int mode = TEXT_MODE;
51 static int col = 1;
52 static int totcol = 16;
53 
54 #define CLEAN 0
55 #define DIRTY 1
56 
57 static page_state;
58 
60 {
61 #ifndef ENABLE_DYNDRIVERS
62  pdt->pl_MenuStr = "Linux console VGA Screen";
63  pdt->pl_DevName = "vga";
64 #endif
66  pdt->pl_seq = 8;
67  pdt->pl_init = (plD_init_fp) plD_init_vga;
68  pdt->pl_line = (plD_line_fp) plD_line_vga;
69  pdt->pl_polyline = (plD_polyline_fp) plD_polyline_vga;
70  pdt->pl_eop = (plD_eop_fp) plD_eop_vga;
71  pdt->pl_bop = (plD_bop_fp) plD_bop_vga;
72  pdt->pl_tidy = (plD_tidy_fp) plD_tidy_vga;
73  pdt->pl_state = (plD_state_fp) plD_state_vga;
74  pdt->pl_esc = (plD_esc_fp) plD_esc_vga;
75 }
76 
77 //--------------------------------------------------------------------------
78 // plD_init_vga()
79 //
80 // Initialize device.
81 //--------------------------------------------------------------------------
82 
83 void
84 plD_init_vga( PLStream *pls )
85 {
86  pls->termin = 1; // Is an interactive terminal
87  pls->graphx = TEXT_MODE;
88 
89  if ( !pls->colorset )
90  pls->color = 1;
91 
92 // What kind of VGA mode one wants is set up here.
93 // It can be easyly made interactive!
94 
95  mode = G640x480x16; // See <vga.h> for a list
96  if ( vga_hasmode( mode ) )
97  vga_setmode( mode );
98  else
99  {
100  printf( "Error: Video mode not supported by graphics card\n" );
101  exit( -1 );
102  }
103 
104 // If all is fine we get the dimensions and # of colors
105 
106  vgax = vga_getxdim() - 1;
107  vgay = vga_getydim() - 1;
108 
109  totcol = vga_getcolors();
110 
111  plP_setpxl( 2.5, 2.5 ); // My best guess. Seems to work okay.
112  plP_setphy( 0, vgax, 0, vgay );
113 }
114 
115 //--------------------------------------------------------------------------
116 // plD_line_vga()
117 //
118 // Draw a line in the current color from (x1,y1) to (x2,y2).
119 //--------------------------------------------------------------------------
120 
121 void
122 plD_line_vga( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
123 {
124  int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
125 
126  y1 = vgay - y1;
127  y2 = vgay - y2;
128 
129  vga_drawline( x1, y1, x2, y2 );
130 
131  page_state = DIRTY;
132 }
133 
134 //--------------------------------------------------------------------------
135 // plD_polyline_vga()
136 //
137 // Draw a polyline in the current color.
138 //--------------------------------------------------------------------------
139 
140 void
141 plD_polyline_vga( PLStream *pls, short *xa, short *ya, PLINT npts )
142 {
143  PLINT i;
144 
145  for ( i = 0; i < npts - 1; i++ )
146  plD_line_vga( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
147 }
148 
149 //--------------------------------------------------------------------------
150 // plD_eop_vga()
151 //
152 // End of page.
153 //--------------------------------------------------------------------------
154 
155 void
156 plD_eop_vga( PLStream *pls )
157 {
158  if ( page_state == DIRTY )
159  lxvga_pause( pls );
160 
161  // vga_setmode(mode);
162  vga_clear(); // just clean it
163 
164  page_state = CLEAN;
165 }
166 
167 //--------------------------------------------------------------------------
168 // plD_bop_vga()
169 //
170 // Set up for the next page.
171 // Advance to next family file if necessary (file output).
172 //--------------------------------------------------------------------------
173 
174 void
175 plD_bop_vga( PLStream *pls )
176 {
177  pls->page++;
178  plD_eop_vga( pls );
179 }
180 
181 //--------------------------------------------------------------------------
182 // plD_tidy_vga()
183 //
184 // Close graphics file or otherwise clean up.
185 //--------------------------------------------------------------------------
186 
187 void
188 plD_tidy_vga( PLStream *pls )
189 {
190  lxvga_text( pls );
191 }
192 
193 //--------------------------------------------------------------------------
194 // plD_state_vga()
195 //
196 // Handle change in PLStream state (color, pen width, fill attribute, etc).
197 //--------------------------------------------------------------------------
198 
199 void
200 plD_state_vga( PLStream *pls, PLINT op )
201 {
202  switch ( op )
203  {
204  case PLSTATE_WIDTH:
205  break;
206 
207  case PLSTATE_COLOR0:
208  if ( pls->color )
209  {
210  // Maybe it would be wiser to use a set of 16 relevant colors only
211  // and just fix it to black if col is exceeded 16.
212 
213  col = ( pls->icol0 ) % totcol; // Color modulo # of colors
214  // avail
215  vga_setcolor( col );
216  }
217  break;
218 
219  case PLSTATE_COLOR1:
220  break;
221  }
222 }
223 
224 //--------------------------------------------------------------------------
225 // plD_esc_vga()
226 //
227 // Escape function.
228 //--------------------------------------------------------------------------
229 
230 void
231 plD_esc_vga( PLStream *pls, PLINT op, void *ptr )
232 {
233  switch ( op )
234  {
235  case PLESC_TEXT:
236  lxvga_text( pls );
237  break;
238 
239  case PLESC_GRAPH:
240  lxvga_graph( pls );
241  break;
242  }
243 }
244 
245 //--------------------------------------------------------------------------
246 // lxvga_text()
247 //
248 // Switch to text mode.
249 //--------------------------------------------------------------------------
250 
251 static void
252 lxvga_text( PLStream *pls )
253 {
254  if ( pls->graphx == GRAPHICS_MODE )
255  {
256  if ( page_state == DIRTY )
257  lxvga_pause( pls );
258  vga_setmode( TEXT );
259  pls->graphx = TEXT_MODE;
260  }
261 }
262 
263 //--------------------------------------------------------------------------
264 // lxvga_graph()
265 //
266 // Switch to graphics mode.
267 //--------------------------------------------------------------------------
268 
269 static void
270 lxvga_graph( PLStream *pls )
271 {
272  if ( pls->graphx == TEXT_MODE )
273  {
274  vga_setmode( mode ); // mode should be set right or ...
275  pls->graphx = GRAPHICS_MODE;
276  page_state = CLEAN;
277  }
278 }
279 
280 //--------------------------------------------------------------------------
281 // lxvga_pause()
282 //
283 // Wait for a keystroke.
284 //--------------------------------------------------------------------------
285 
286 static void
287 lxvga_pause( PLStream *pls )
288 {
289  if ( pls->nopause )
290  return;
291 
292  vga_getch();
293 }
294 
295 #else
296 int
298 {
299  return 0;
300 }
301 
302 #endif // PLD_linuxvga