PLplot
5.10.0
|
00001 // S. Fanchiotti (Using gnusvga.c by Geoffrey Furnish) 00002 // 4 May 1993 00003 // 00004 // This file constitutes the driver for an VGA display under Linux 00005 // using the GNU CC compiler and vgalib 1.2 library by T. Fradsen 00006 // 00007 // Things to note: NEEDS vgalib to compile!!!!! 00008 // 00009 // 00010 #include "plDevs.h" 00011 00012 #ifdef PLD_linuxvga // Only compile for Linux + Vgalib 1.2 00013 00014 #include "plplotP.h" 00015 #include "drivers.h" 00016 #include <vga.h> 00017 00018 // Device info 00019 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_linuxvga = "linuxvga:Linux VGA driver:0:linuxvga:8:vga\n"; 00020 00021 00022 // Function prototypes 00023 00024 void plD_init_vga( PLStream * ); 00025 void plD_line_vga( PLStream *, short, short, short, short ); 00026 void plD_polyline_vga( PLStream *, short *, short *, PLINT ); 00027 void plD_eop_vga( PLStream * ); 00028 void plD_bop_vga( PLStream * ); 00029 void plD_tidy_vga( PLStream * ); 00030 void plD_state_vga( PLStream *, PLINT ); 00031 void plD_esc_vga( PLStream *, PLINT, void * ); 00032 00033 static void lxvga_text( PLStream *pls ); 00034 static void lxvga_graph( PLStream *pls ); 00035 static void lxvga_pause( PLStream *pls ); 00036 00037 static PLINT vgax = 639; 00038 static PLINT vgay = 479; 00039 00040 // A flag to tell us whether we are in text or graphics mode 00041 00042 #define TEXT_MODE 0 00043 #define GRAPHICS_MODE 1 00044 00045 // gmf; should probably query this on start up... Maybe later. 00046 // sf; Will set them dynamically! 00047 00048 static int mode = TEXT_MODE; 00049 static int col = 1; 00050 static int totcol = 16; 00051 00052 #define CLEAN 0 00053 #define DIRTY 1 00054 00055 static page_state; 00056 00057 void plD_dispatch_init_vga( PLDispatchTable *pdt ) 00058 { 00059 #ifndef ENABLE_DYNDRIVERS 00060 pdt->pl_MenuStr = "Linux console VGA Screen"; 00061 pdt->pl_DevName = "vga"; 00062 #endif 00063 pdt->pl_type = plDevType_Interactive; 00064 pdt->pl_seq = 8; 00065 pdt->pl_init = (plD_init_fp) plD_init_vga; 00066 pdt->pl_line = (plD_line_fp) plD_line_vga; 00067 pdt->pl_polyline = (plD_polyline_fp) plD_polyline_vga; 00068 pdt->pl_eop = (plD_eop_fp) plD_eop_vga; 00069 pdt->pl_bop = (plD_bop_fp) plD_bop_vga; 00070 pdt->pl_tidy = (plD_tidy_fp) plD_tidy_vga; 00071 pdt->pl_state = (plD_state_fp) plD_state_vga; 00072 pdt->pl_esc = (plD_esc_fp) plD_esc_vga; 00073 } 00074 00075 //-------------------------------------------------------------------------- 00076 // plD_init_vga() 00077 // 00078 // Initialize device. 00079 //-------------------------------------------------------------------------- 00080 00081 void 00082 plD_init_vga( PLStream *pls ) 00083 { 00084 pls->termin = 1; // Is an interactive terminal 00085 pls->graphx = TEXT_MODE; 00086 00087 if ( !pls->colorset ) 00088 pls->color = 1; 00089 00090 // What kind of VGA mode one wants is set up here. 00091 // It can be easyly made interactive! 00092 00093 mode = G640x480x16; // See <vga.h> for a list 00094 if ( vga_hasmode( mode ) ) 00095 vga_setmode( mode ); 00096 else 00097 { 00098 printf( "Error: Video mode not supported by graphics card\n" ); 00099 exit( -1 ); 00100 } 00101 00102 // If all is fine we get the dimensions and # of colors 00103 00104 vgax = vga_getxdim() - 1; 00105 vgay = vga_getydim() - 1; 00106 00107 totcol = vga_getcolors(); 00108 00109 plP_setpxl( 2.5, 2.5 ); // My best guess. Seems to work okay. 00110 plP_setphy( 0, vgax, 0, vgay ); 00111 } 00112 00113 //-------------------------------------------------------------------------- 00114 // plD_line_vga() 00115 // 00116 // Draw a line in the current color from (x1,y1) to (x2,y2). 00117 //-------------------------------------------------------------------------- 00118 00119 void 00120 plD_line_vga( PLStream *pls, short x1a, short y1a, short x2a, short y2a ) 00121 { 00122 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a; 00123 00124 y1 = vgay - y1; 00125 y2 = vgay - y2; 00126 00127 vga_drawline( x1, y1, x2, y2 ); 00128 00129 page_state = DIRTY; 00130 } 00131 00132 //-------------------------------------------------------------------------- 00133 // plD_polyline_vga() 00134 // 00135 // Draw a polyline in the current color. 00136 //-------------------------------------------------------------------------- 00137 00138 void 00139 plD_polyline_vga( PLStream *pls, short *xa, short *ya, PLINT npts ) 00140 { 00141 PLINT i; 00142 00143 for ( i = 0; i < npts - 1; i++ ) 00144 plD_line_vga( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] ); 00145 } 00146 00147 //-------------------------------------------------------------------------- 00148 // plD_eop_vga() 00149 // 00150 // End of page. 00151 //-------------------------------------------------------------------------- 00152 00153 void 00154 plD_eop_vga( PLStream *pls ) 00155 { 00156 if ( page_state == DIRTY ) 00157 lxvga_pause( pls ); 00158 00159 // vga_setmode(mode); 00160 vga_clear(); // just clean it 00161 00162 page_state = CLEAN; 00163 } 00164 00165 //-------------------------------------------------------------------------- 00166 // plD_bop_vga() 00167 // 00168 // Set up for the next page. 00169 // Advance to next family file if necessary (file output). 00170 //-------------------------------------------------------------------------- 00171 00172 void 00173 plD_bop_vga( PLStream *pls ) 00174 { 00175 pls->page++; 00176 plD_eop_vga( pls ); 00177 } 00178 00179 //-------------------------------------------------------------------------- 00180 // plD_tidy_vga() 00181 // 00182 // Close graphics file or otherwise clean up. 00183 //-------------------------------------------------------------------------- 00184 00185 void 00186 plD_tidy_vga( PLStream *pls ) 00187 { 00188 lxvga_text( pls ); 00189 } 00190 00191 //-------------------------------------------------------------------------- 00192 // plD_state_vga() 00193 // 00194 // Handle change in PLStream state (color, pen width, fill attribute, etc). 00195 //-------------------------------------------------------------------------- 00196 00197 void 00198 plD_state_vga( PLStream *pls, PLINT op ) 00199 { 00200 switch ( op ) 00201 { 00202 case PLSTATE_WIDTH: 00203 break; 00204 00205 case PLSTATE_COLOR0: 00206 if ( pls->color ) 00207 { 00208 // Maybe it would be wiser to use a set of 16 relevant colors only 00209 // and just fix it to black if col is exceeded 16. 00210 00211 col = ( pls->icol0 ) % totcol; // Color modulo # of colors 00212 // avail 00213 vga_setcolor( col ); 00214 } 00215 break; 00216 00217 case PLSTATE_COLOR1: 00218 break; 00219 } 00220 } 00221 00222 //-------------------------------------------------------------------------- 00223 // plD_esc_vga() 00224 // 00225 // Escape function. 00226 //-------------------------------------------------------------------------- 00227 00228 void 00229 plD_esc_vga( PLStream *pls, PLINT op, void *ptr ) 00230 { 00231 switch ( op ) 00232 { 00233 case PLESC_TEXT: 00234 lxvga_text( pls ); 00235 break; 00236 00237 case PLESC_GRAPH: 00238 lxvga_graph( pls ); 00239 break; 00240 } 00241 } 00242 00243 //-------------------------------------------------------------------------- 00244 // lxvga_text() 00245 // 00246 // Switch to text mode. 00247 //-------------------------------------------------------------------------- 00248 00249 static void 00250 lxvga_text( PLStream *pls ) 00251 { 00252 if ( pls->graphx == GRAPHICS_MODE ) 00253 { 00254 if ( page_state == DIRTY ) 00255 lxvga_pause( pls ); 00256 vga_setmode( TEXT ); 00257 pls->graphx = TEXT_MODE; 00258 } 00259 } 00260 00261 //-------------------------------------------------------------------------- 00262 // lxvga_graph() 00263 // 00264 // Switch to graphics mode. 00265 //-------------------------------------------------------------------------- 00266 00267 static void 00268 lxvga_graph( PLStream *pls ) 00269 { 00270 if ( pls->graphx == TEXT_MODE ) 00271 { 00272 vga_setmode( mode ); // mode should be set right or ... 00273 pls->graphx = GRAPHICS_MODE; 00274 page_state = CLEAN; 00275 } 00276 } 00277 00278 //-------------------------------------------------------------------------- 00279 // lxvga_pause() 00280 // 00281 // Wait for a keystroke. 00282 //-------------------------------------------------------------------------- 00283 00284 static void 00285 lxvga_pause( PLStream *pls ) 00286 { 00287 if ( pls->nopause ) 00288 return; 00289 00290 vga_getch(); 00291 } 00292 00293 #else 00294 int 00295 pldummy_vga() 00296 { 00297 return 0; 00298 } 00299 00300 #endif // PLD_linuxvga