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