File: linuxvga.c

package info (click to toggle)
plplot 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,280 kB
  • ctags: 13,512
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,210; makefile: 199; lisp: 75; sed: 25; fortran: 7
file content (302 lines) | stat: -rw-r--r-- 7,514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// $Id: linuxvga.c 11293 2010-11-01 19:54:24Z airwin $
//
//      S. Fanchiotti (Using gnusvga.c by Geoffrey Furnish)
//      4 May 1993
//
//      This file constitutes the driver for an VGA display under Linux
//      using the GNU CC compiler and vgalib 1.2 library by T. Fradsen
//
//      Things to note: NEEDS vgalib to compile!!!!!
//
//
#include "plDevs.h"

#ifdef PLD_linuxvga             // Only compile for Linux + Vgalib 1.2

#include "plplotP.h"
#include "drivers.h"
#include <vga.h>

// Device info
PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_linuxvga = "linuxvga:Linux VGA driver:0:linuxvga:8:vga\n";


// Function prototypes

void plD_init_vga( PLStream * );
void plD_line_vga( PLStream *, short, short, short, short );
void plD_polyline_vga( PLStream *, short *, short *, PLINT );
void plD_eop_vga( PLStream * );
void plD_bop_vga( PLStream * );
void plD_tidy_vga( PLStream * );
void plD_state_vga( PLStream *, PLINT );
void plD_esc_vga( PLStream *, PLINT, void * );

static void lxvga_text( PLStream *pls );
static void lxvga_graph( PLStream *pls );
static void lxvga_pause( PLStream *pls );

static PLINT vgax = 639;
static PLINT vgay = 479;

// A flag to tell us whether we are in text or graphics mode

#define TEXT_MODE        0
#define GRAPHICS_MODE    1

// gmf; should probably query this on start up... Maybe later.
// sf; Will set them dynamically!

static int mode   = TEXT_MODE;
static int col    = 1;
static int totcol = 16;

#define CLEAN    0
#define DIRTY    1

static page_state;

void plD_dispatch_init_vga( PLDispatchTable *pdt )
{
#ifndef ENABLE_DYNDRIVERS
    pdt->pl_MenuStr = "Linux console VGA Screen";
    pdt->pl_DevName = "vga";
#endif
    pdt->pl_type     = plDevType_Interactive;
    pdt->pl_seq      = 8;
    pdt->pl_init     = (plD_init_fp) plD_init_vga;
    pdt->pl_line     = (plD_line_fp) plD_line_vga;
    pdt->pl_polyline = (plD_polyline_fp) plD_polyline_vga;
    pdt->pl_eop      = (plD_eop_fp) plD_eop_vga;
    pdt->pl_bop      = (plD_bop_fp) plD_bop_vga;
    pdt->pl_tidy     = (plD_tidy_fp) plD_tidy_vga;
    pdt->pl_state    = (plD_state_fp) plD_state_vga;
    pdt->pl_esc      = (plD_esc_fp) plD_esc_vga;
}

//--------------------------------------------------------------------------
// plD_init_vga()
//
// Initialize device.
//--------------------------------------------------------------------------

void
plD_init_vga( PLStream *pls )
{
    pls->termin = 1;            // Is an interactive terminal
    pls->graphx = TEXT_MODE;

    if ( !pls->colorset )
        pls->color = 1;

// What kind of VGA mode one wants is set up here.
// It can be easyly made interactive!

    mode = G640x480x16;         // See <vga.h> for a list
    if ( vga_hasmode( mode ) )
        vga_setmode( mode );
    else
    {
        printf( "Error: Video mode not supported by graphics card\n" );
        exit( -1 );
    }

// If all is fine we get the dimensions and # of colors

    vgax = vga_getxdim() - 1;
    vgay = vga_getydim() - 1;

    totcol = vga_getcolors();

    plP_setpxl( 2.5, 2.5 );       // My best guess.  Seems to work okay.
    plP_setphy( 0, vgax, 0, vgay );
}

//--------------------------------------------------------------------------
// plD_line_vga()
//
// Draw a line in the current color from (x1,y1) to (x2,y2).
//--------------------------------------------------------------------------

void
plD_line_vga( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
{
    int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;

    y1 = vgay - y1;
    y2 = vgay - y2;

    vga_drawline( x1, y1, x2, y2 );

    page_state = DIRTY;
}

//--------------------------------------------------------------------------
// plD_polyline_vga()
//
// Draw a polyline in the current color.
//--------------------------------------------------------------------------

void
plD_polyline_vga( PLStream *pls, short *xa, short *ya, PLINT npts )
{
    PLINT i;

    for ( i = 0; i < npts - 1; i++ )
        plD_line_vga( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
}

//--------------------------------------------------------------------------
// plD_eop_vga()
//
// End of page.
//--------------------------------------------------------------------------

void
plD_eop_vga( PLStream *pls )
{
    if ( page_state == DIRTY )
        lxvga_pause( pls );

    // vga_setmode(mode);
    vga_clear();                // just clean it

    page_state = CLEAN;
}

//--------------------------------------------------------------------------
// plD_bop_vga()
//
// Set up for the next page.
// Advance to next family file if necessary (file output).
//--------------------------------------------------------------------------

void
plD_bop_vga( PLStream *pls )
{
    pls->page++;
    plD_eop_vga( pls );
}

//--------------------------------------------------------------------------
// plD_tidy_vga()
//
// Close graphics file or otherwise clean up.
//--------------------------------------------------------------------------

void
plD_tidy_vga( PLStream *pls )
{
    lxvga_text( pls );
}

//--------------------------------------------------------------------------
// plD_state_vga()
//
// Handle change in PLStream state (color, pen width, fill attribute, etc).
//--------------------------------------------------------------------------

void
plD_state_vga( PLStream *pls, PLINT op )
{
    switch ( op )
    {
    case PLSTATE_WIDTH:
        break;

    case PLSTATE_COLOR0:
        if ( pls->color )
        {
            // Maybe it would be wiser to use a set of 16 relevant colors only
            // and just fix it to black if col is exceeded 16.

            col = ( pls->icol0 ) % totcol;        // Color modulo # of colors
                                                  // avail
            vga_setcolor( col );
        }
        break;

    case PLSTATE_COLOR1:
        break;
    }
}

//--------------------------------------------------------------------------
// plD_esc_vga()
//
// Escape function.
//--------------------------------------------------------------------------

void
plD_esc_vga( PLStream *pls, PLINT op, void *ptr )
{
    switch ( op )
    {
    case PLESC_TEXT:
        lxvga_text( pls );
        break;

    case PLESC_GRAPH:
        lxvga_graph( pls );
        break;
    }
}

//--------------------------------------------------------------------------
// lxvga_text()
//
// Switch to text mode.
//--------------------------------------------------------------------------

static void
lxvga_text( PLStream *pls )
{
    if ( pls->graphx == GRAPHICS_MODE )
    {
        if ( page_state == DIRTY )
            lxvga_pause( pls );
        vga_setmode( TEXT );
        pls->graphx = TEXT_MODE;
    }
}

//--------------------------------------------------------------------------
// lxvga_graph()
//
// Switch to graphics mode.
//--------------------------------------------------------------------------

static void
lxvga_graph( PLStream *pls )
{
    if ( pls->graphx == TEXT_MODE )
    {
        vga_setmode( mode );      // mode should be set right or ...
        pls->graphx = GRAPHICS_MODE;
        page_state  = CLEAN;
    }
}

//--------------------------------------------------------------------------
// lxvga_pause()
//
// Wait for a keystroke.
//--------------------------------------------------------------------------

static void
lxvga_pause( PLStream *pls )
{
    if ( pls->nopause )
        return;

    vga_getch();
}

#else
int
pldummy_vga()
{
    return 0;
}

#endif                          // PLD_linuxvga