• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

linuxvga.c

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

Generated on Wed Oct 12 2011 20:42:21 for PLplot by  doxygen 1.7.1