Subversion Repositories shark

Rev

Rev 74 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
54 pj 1
/* SVGA Lib - Linker module to use the low level driver
2
 * without the vga.c support
3
 *
4
*/
5
 
6
/* variables used to shift between monchrome and color emulation */
7
#include <stdint.h>
8
#include <unistd.h>
9
 
10
#include <ll/i386/hw-data.h>
11
#include <ll/i386/mem.h>
12
#include <ll/i386/cons.h>
13
#include <ll/sys/ll/ll-func.h>
14
 
15
#include "libvga.h"
16
#include "vgaversion.h"
17
#include "vgaio.h"
18
#include "driver.h"
19
 
20
int __svgalib_CRT_I;                    /* current CRT index register address */
21
int __svgalib_CRT_D;                    /* current CRT data register address */
22
int __svgalib_IS1_R;                    /* current input status register address */
23
static int color_text;                  /* true if color text emulation */
24
 
25
uint8_t *BANKED_POINTER=NULL, *LINEAR_POINTER;
26
uint8_t *MMIO_POINTER;
27
uint8_t *SPARSE_MMIO;
28
static int mmio_mapped=0, mem_mapped=0;
29
static uint8_t *B8000_POINTER=NULL;
30
unsigned long __svgalib_banked_mem_base, __svgalib_banked_mem_size;
31
unsigned long __svgalib_mmio_base, __svgalib_mmio_size=0;
32
unsigned long __svgalib_linear_mem_base=0, __svgalib_linear_mem_size=0;
33
 
34
extern int init_vgapci(void);
35
extern int nv3_test(void);
36
extern int savage_test(void);
37
 
38
/* If == 0 then nothing is defined by the user... */
39
int __svgalib_default_mode = 10;
40
 
41
struct info infotable[] =
42
{
43
    {80, 25, 16, 160, 0},       /* VGAlib VGA modes */
44
    {320, 200, 16, 40, 0},
45
    {640, 200, 16, 80, 0},
46
    {640, 350, 16, 80, 0},
47
    {640, 480, 16, 80, 0},
48
    {320, 200, 256, 320, 1},
49
    {320, 240, 256, 80, 0},
50
    {320, 400, 256, 80, 0},
51
    {360, 480, 256, 90, 0},
52
    {640, 480, 2, 80, 0},
53
 
54
    {640, 480, 256, 640, 1},    /* VGAlib SVGA modes */
55
    {800, 600, 256, 800, 1},
56
    {1024, 768, 256, 1024, 1},
57
    {1280, 1024, 256, 1280, 1},
58
 
59
    {320, 200, 1 << 15, 640, 2},        /* Hicolor/truecolor modes */
60
    {320, 200, 1 << 16, 640, 2},
61
    {320, 200, 1 << 24, 320 * 3, 3},
62
    {640, 480, 1 << 15, 640 * 2, 2},
63
    {640, 480, 1 << 16, 640 * 2, 2},
64
    {640, 480, 1 << 24, 640 * 3, 3},
65
    {800, 600, 1 << 15, 800 * 2, 2},
66
    {800, 600, 1 << 16, 800 * 2, 2},
67
    {800, 600, 1 << 24, 800 * 3, 3},
68
    {1024, 768, 1 << 15, 1024 * 2, 2},
69
    {1024, 768, 1 << 16, 1024 * 2, 2},
70
    {1024, 768, 1 << 24, 1024 * 3, 3},
71
    {1280, 1024, 1 << 15, 1280 * 2, 2},
72
    {1280, 1024, 1 << 16, 1280 * 2, 2},
73
    {1280, 1024, 1 << 24, 1280 * 3, 3},
74
 
75
    {800, 600, 16, 100, 0},     /* SVGA 16-color modes */
76
    {1024, 768, 16, 128, 0},
77
    {1280, 1024, 16, 160, 0},
78
 
79
    {720, 348, 2, 90, 0},       /* Hercules emulation mode */
80
 
81
    {320, 200, 1 << 24, 320 * 4, 4},
82
    {640, 480, 1 << 24, 640 * 4, 4},
83
    {800, 600, 1 << 24, 800 * 4, 4},
84
    {1024, 768, 1 << 24, 1024 * 4, 4},
85
    {1280, 1024, 1 << 24, 1280 * 4, 4},
86
 
87
    {1152, 864, 16, 144, 0},
88
    {1152, 864, 256, 1152, 1},
89
    {1152, 864, 1 << 15, 1152 * 2, 2},
90
    {1152, 864, 1 << 16, 1152 * 2, 2},
91
    {1152, 864, 1 << 24, 1152 * 3, 3},
92
    {1152, 864, 1 << 24, 1152 * 4, 4},
93
 
94
    {1600, 1200, 16, 200, 0},
95
    {1600, 1200, 256, 1600, 1},
96
    {1600, 1200, 1 << 15, 1600 * 2, 2},
97
    {1600, 1200, 1 << 16, 1600 * 2, 2},
98
    {1600, 1200, 1 << 24, 1600 * 3, 3},
99
    {1600, 1200, 1 << 24, 1600 * 4, 4},
100
 
101
    {320, 240, 256, 320, 1},   
102
    {320, 240, 1<<15, 320*2, 2},
103
    {320, 240, 1<<16, 320*2, 2},
104
    {320, 240, 1<<24, 320*3, 3},
105
    {320, 240, 1<<24, 320*4, 4},
106
 
107
    {400, 300, 256, 400, 1},
108
    {400, 300, 1<<15, 400*2, 2},
109
    {400, 300, 1<<16, 400*2, 2},
110
    {400, 300, 1<<24, 400*3, 3},
111
    {400, 300, 1<<24, 400*4, 4},
112
 
113
    {512, 384, 256, 512, 1},           
114
    {512, 384, 1<<15, 512*2, 2},
115
    {512, 384, 1<<16, 512*2, 2},
116
    {512, 384, 1<<24, 512*3, 3},
117
    {512, 384, 1<<24, 512*4, 4},
118
 
119
    {960, 720, 256, 960, 1},           
120
    {960, 720, 1<<15, 960*2, 2},
121
    {960, 720, 1<<16, 960*2, 2},
122
    {960, 720, 1<<24, 960*3, 3},
123
    {960, 720, 1<<24, 960*4, 4},
124
 
125
    {1920, 1440, 256, 1920, 1},        
126
    {1920, 1440, 1<<15, 1920*2, 2},
127
    {1920, 1440, 1<<16, 1920*2, 2},
128
    {1920, 1440, 1<<24, 1920*3, 3},
129
    {1920, 1440, 1<<24, 1920*4, 4},
130
 
131
    {320, 400, 1<<8,  320,   1},
132
    {320, 400, 1<<15, 320*2, 2},
133
    {320, 400, 1<<16, 320*2, 2},
134
    {320, 400, 1<<24, 320*3, 3},
135
    {320, 400, 1<<24, 320*4, 4},
136
 
137
    {640, 400, 256, 640, 1},
138
    {640, 400, 1<<15, 640*2, 2},
139
    {640, 400, 1<<16, 640*2, 2},
140
    {640, 400, 1<<24, 640*3, 3},
141
    {640, 400, 1<<24, 640*4, 4},
142
 
143
    {320, 480, 256, 320, 1},
144
    {320, 480, 1<<15, 320*2, 2},
145
    {320, 480, 1<<16, 320*2, 2},
146
    {320, 480, 1<<24, 320*3, 3},
147
    {320, 480, 1<<24, 320*4, 4},
148
 
149
    {720, 540, 256, 720, 1},
150
    {720, 540, 1<<15, 720*2, 2},
151
    {720, 540, 1<<16, 720*2, 2},
152
    {720, 540, 1<<24, 720*3, 3},
153
    {720, 540, 1<<24, 720*4, 4},
154
 
155
    {848, 480, 256, 848, 1},
156
    {848, 480, 1<<15, 848*2, 2},
157
    {848, 480, 1<<16, 848*2, 2},
158
    {848, 480, 1<<24, 848*3, 3},
159
    {848, 480, 1<<24, 848*4, 4},
160
 
161
    {1072, 600, 256, 1072, 1},
162
    {1072, 600, 1<<15, 1072*2, 2},
163
    {1072, 600, 1<<16, 1072*2, 2},
164
    {1072, 600, 1<<24, 1072*3, 3},
165
    {1072, 600, 1<<24, 1072*4, 4},
166
 
167
    {1280, 720, 256, 1280, 1},
168
    {1280, 720, 1<<15, 1280*2, 2},
169
    {1280, 720, 1<<16, 1280*2, 2},
170
    {1280, 720, 1<<24, 1280*3, 3},
171
    {1280, 720, 1<<24, 1280*4, 4},
172
 
173
    {1360, 768, 256, 1360, 1},
174
    {1360, 768, 1<<15, 1360*2, 2},
175
    {1360, 768, 1<<16, 1360*2, 2},
176
    {1360, 768, 1<<24, 1360*3, 3},
177
    {1360, 768, 1<<24, 1360*4, 4},
178
 
179
    {1800, 1012, 256, 1800, 1},
180
    {1800, 1012, 1<<15, 1800*2, 2},
181
    {1800, 1012, 1<<16, 1800*2, 2},
182
    {1800, 1012, 1<<24, 1800*3, 3},
183
    {1800, 1012, 1<<24, 1800*4, 4},
184
 
185
    {1920, 1080, 256, 1920, 1},
186
    {1920, 1080, 1<<15, 1920*2, 2},
187
    {1920, 1080, 1<<16, 1920*2, 2},
188
    {1920, 1080, 1<<24, 1920*3, 3},
189
    {1920, 1080, 1<<24, 1920*4, 4},
190
 
191
    {2048, 1152, 256, 2048, 1},
192
    {2048, 1152, 1<<15, 2048*2, 2},
193
    {2048, 1152, 1<<16, 2048*2, 2},
194
    {2048, 1152, 1<<24, 2048*3, 3},
195
    {2048, 1152, 1<<24, 2048*4, 4},
196
 
197
    {2048, 1536, 256, 2048, 1},
198
    {2048, 1536, 1<<15, 2048*2, 2},
199
    {2048, 1536, 1<<16, 2048*2, 2},
200
    {2048, 1536, 1<<24, 2048*3, 3},
201
    {2048, 1536, 1<<24, 2048*4, 4},
202
 
203
    {512, 480, 256, 512, 1},           
204
    {512, 480, 1<<15, 512*2, 2},
205
    {512, 480, 1<<16, 512*2, 2},
206
    {512, 480, 1<<24, 512*3, 3},
207
    {512, 480, 1<<24, 512*4, 4},
208
 
209
    {400, 600, 256, 400, 1},
210
    {400, 600, 1<<15, 400*2, 2},
211
    {400, 600, 1<<16, 400*2, 2},
212
    {400, 600, 1<<24, 400*3, 3},
213
    {400, 600, 1<<24, 400*4, 4},
214
 
215
    {400, 300, 256, 100, 0},
216
    {320, 200, 256, 320, 1},
217
    {0, 0, 0, 0, 0},
218
    {0, 0, 0, 0, 0},
219
    {0, 0, 0, 0, 0},
220
    {0, 0, 0, 0, 0},
221
    {0, 0, 0, 0, 0},
222
    {0, 0, 0, 0, 0},
223
    {0, 0, 0, 0, 0},
224
    {0, 0, 0, 0, 0},
225
    {0, 0, 0, 0, 0},
226
    {0, 0, 0, 0, 0},
227
    {0, 0, 0, 0, 0},
228
    {0, 0, 0, 0, 0},
229
    {0, 0, 0, 0, 0},
230
    {0, 0, 0, 0, 0},
231
    {0, 0, 0, 0, 0}
232
};
233
 
234
#define MAX_MODES (sizeof(infotable) / sizeof(struct info))
235
 
236
void (*__svgalib_go_to_background) (void) = 0;
237
void (*__svgalib_come_from_background) (void) = 0;
238
static int release_acquire=0;
239
 
240
unsigned long __svgalib_graph_base = GRAPH_BASE;
241
 
242
unsigned char __svgalib_novga = 0;     /* Does not have VGA circuitry on board */
243
unsigned char __svgalib_vesatext = 0;
244
unsigned char __svgalib_textprog = 0;  /* run a program when returning to text mode */
245
unsigned char __svgalib_secondary = 0; /* this is not the main card with VC'S ) */
246
unsigned char __svgalib_emulatepage = 0; /* don't use 0xa0000 memory */
247
unsigned char __svgalib_novccontrol = 0; /* this is not the main card with VC'S  */
248
unsigned char __svgalib_ragedoubleclock = 0;
249
unsigned char __svgalib_simple = 0;
250
 
251
/* default palette values */
252
static const unsigned char default_red[256]
253
=
254
{0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63,
255
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
256
 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16,
257
 0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63,
258
 63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31,
259
 45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49,
260
 45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28,
261
 28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0,
262
 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17,
263
 14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28,
264
 28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20,
265
 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4,
266
 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16,
267
 16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8,
268
 11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12,
269
 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0};
270
static const unsigned char default_green[256]
271
=
272
{0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63,
273
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
274
 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63,
275
 63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31,
276
 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
277
 45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63,
278
 63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0,
279
 0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7,
280
 14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28,
281
 28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20,
282
 20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
283
 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16,
284
 16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8,
285
 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
286
 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16,
287
 16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0};
288
static const unsigned char default_blue[256]
289
=
290
{0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63,
291
 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
292
 63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0,
293
 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
294
 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63,
295
 63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45,
296
 45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7,
297
 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28,
298
 28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14,
299
 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
300
 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28,
301
 16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0,
302
 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
303
 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16,
304
 16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11,
305
 11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0};
306
 
307
static unsigned char text_regs[MAX_REGS];       /* VGA registers for saved text mode */
308
 
309
char *__svgalib_TextProg_argv[16]; /* should be enough */
310
char *__svgalib_TextProg;
311
 
312
/* saved text mode palette values */
313
static unsigned char text_red[256];
314
static unsigned char text_green[256];
315
static unsigned char text_blue[256];
316
 
317
/* saved graphics mode palette values */
318
static unsigned char graph_red[256];
319
static unsigned char graph_green[256];
320
static unsigned char graph_blue[256];
321
 
322
static int prv_mode = TEXT;     /* previous video mode      */
323
static int flip_mode = TEXT;    /* flipped video mode       */
324
 
325
int CM = TEXT;                  /* current video mode       */
326
struct info CI;                 /* current video parameters */
327
int COL;                        /* current color            */
328
 
329
static int initialized = 0;     /* flag: initialize() called ?  */
330
static int flip = 0;            /* flag: executing vga_flip() ? */
331
static int background_fd = -1;
332
 
333
/* svgalib additions: */
334
int __svgalib_chipset = UNDEFINED;
335
int __svgalib_driver_report = 1;
336
        /* report driver used after chipset detection */
337
int __svgalib_videomemoryused = -1;
338
int __svgalib_modeX = 0;        /* true after vga_setmodeX() */
339
int __svgalib_modeflags = 0;    /* copy of flags for current mode */
340
int __svgalib_critical = 0;     /* indicates blitter is busy */
341
int __svgalib_screenon = 1;     /* screen visible if != 0 */
342
int __svgalib_vgacolormode = 1; /* assume color for now. needs to be
343
                                   config file option */
344
 
345
static int __svgalib_savemem=0;
346
 
347
RefreshRange __svgalib_horizsync =
348
{31500U, 60000U};                       /* horz. refresh (Hz) min, max */
349
RefreshRange __svgalib_vertrefresh =
350
{50U, 70U};                     /* vert. refresh (Hz) min, max */
351
int __svgalib_bandwidth=50000;  /* monitor maximum bandwidth (kHz) */
352
int __svgalib_grayscale = 0;    /* grayscale vs. color mode */
353
int __svgalib_modeinfo_linearset = 0;   /* IS_LINEAR handled via extended vga_modeinfo */
354
const int __svgalib_max_modes = MAX_MODES;      /* Needed for dynamical allocated tables in mach32.c */
355
 
356
static unsigned __svgalib_maxhsync[] =
357
{
358
    31500, 35100, 35500, 37900, 48300, 56000, 60000
359
};
360
 
361
static int lastmodenumber = __GLASTMODE;        /* Last defined mode */
362
static int my_pid = 0;          /* process PID, used with atexit() */
363
static int __svgalib_currentpage;
364
static int vga_page_offset;     /* offset to add to all vga_set*page() calls */
365
static int currentlogicalwidth;
366
static int currentdisplaystart;
367
static int mouse_support = 0;
368
int mouse_open = 0;
369
static int mouse_mode = 0;
370
static int mouse_type = -1;
371
static int mouse_modem_ctl = 0;
372
char *__svgalib_mouse_device = "/dev/mouse";
373
int __svgalib_mouse_flag;
374
static char *mem_device = "/dev/svga";
375
static int __svgalib_oktowrite = 1;
376
static int modeinfo_mask = ~0;
377
 
378
int __svgalib_mem_fd = -1;      /* /dev/svga file descriptor  */
379
int __svgalib_tty_fd = -1;      /* /dev/tty file descriptor */
380
int __svgalib_nosigint = 0;     /* Don't generate SIGINT in graphics mode */
381
int __svgalib_runinbackground = 0;
382
int __svgalib_startup_vc = -1;
383
static int __svgalib_security_revokeallprivs = 1;
384
static unsigned fontbufsize = 8192; /* compatibility */
385
 
386
/* Dummy buffer for mmapping grahics memory; points to 64K VGA framebuffer. */
387
unsigned char *GM;
388
/* Exported variable (read-only) is shadowed from internal variable, for */
389
/* better shared library performance. */
390
unsigned char *graph_mem;
391
 
392
void *__svgalib_physaddr;
393
int __svgalib_linear_memory_size;
394
 
395
static unsigned long graph_buf_size = 0;
396
static unsigned char *graph_buf = NULL;         /* saves graphics data during flip */
397
static int inbackground=0;
398
 
399
static unsigned char *font_buf1;        /* saved font data - plane 2 */
400
static unsigned char *font_buf2;        /* saved font data - plane 3 */
401
static unsigned char *text_buf1=NULL;   /* saved text data - plane 0 */
402
static unsigned char *text_buf2;        /* saved text data - plane 1 */
403
 
404
int __svgalib_flipchar = '\x1b';                /* flip character - initially  ESCAPE */
405
 
406
/* Chipset specific functions */
407
 
408
DriverSpecs *__svgalib_driverspecs = &__svgalib_vga_driverspecs;
409
 
410
static void (*__svgalib_setpage) (int); /* gives little faster vga_setpage() */
411
static void (*__svgalib_setrdpage) (int);
412
static void (*__svgalib_setwrpage) (int);
413
 
414
int  (*__svgalib_inmisc)(void);
415
void (*__svgalib_outmisc)(int);
416
int  (*__svgalib_incrtc)(int);
417
void (*__svgalib_outcrtc)(int,int);
418
int  (*__svgalib_inseq)(int);
419
void (*__svgalib_outseq)(int,int);
420
int  (*__svgalib_ingra)(int);
421
void (*__svgalib_outgra)(int,int);
422
int  (*__svgalib_inatt)(int);
423
void (*__svgalib_outatt)(int,int);
424
void (*__svgalib_attscreen)(int);
425
void (*__svgalib_inpal)(int,int*,int*,int*);
426
void (*__svgalib_outpal)(int,int,int,int);
427
int  (*__svgalib_inis1)(void);
428
 
429
void map_banked(void);
430
void map_banked_fix(void);
431
inline void vga_setpage(int p);
432
 
433
DriverSpecs *__svgalib_driverspecslist[] =
434
{
435
    NULL,                       /* chipset undefined */
436
    &__svgalib_vga_driverspecs,
437
#ifdef INCLUDE_ET4000_DRIVER
438
    &__svgalib_et4000_driverspecs,
439
#else
440
    NULL,
441
#endif
442
#ifdef INCLUDE_CIRRUS_DRIVER
443
    &__svgalib_cirrus_driverspecs,
444
#else
445
    NULL,
446
#endif
447
#ifdef INCLUDE_TVGA_DRIVER
448
    &__svgalib_tvga8900_driverspecs,
449
#else
450
    NULL,
451
#endif
452
#ifdef INCLUDE_OAK_DRIVER
453
    &__svgalib_oak_driverspecs,
454
#else
455
    NULL,
456
#endif
457
#ifdef INCLUDE_EGA_DRIVER
458
    &__svgalib_ega_driverspecs,
459
#else
460
    NULL,
461
#endif
462
#ifdef INCLUDE_S3_DRIVER
463
    &__svgalib_s3_driverspecs,
464
#else
465
    NULL,
466
#endif
467
#ifdef INCLUDE_ET3000_DRIVER
468
    &__svgalib_et3000_driverspecs,
469
#else
470
    NULL,
471
#endif
472
#ifdef INCLUDE_MACH32_DRIVER
473
    &__svgalib_mach32_driverspecs,
474
#else
475
    NULL,
476
#endif
477
#ifdef INCLUDE_GVGA6400_DRIVER
478
    &__svgalib_gvga6400_driverspecs,
479
#else
480
    NULL,
481
#endif
482
#ifdef INCLUDE_ARK_DRIVER
483
    &__svgalib_ark_driverspecs,
484
#else
485
    NULL,
486
#endif
487
#ifdef INCLUDE_ATI_DRIVER
488
    &__svgalib_ati_driverspecs,
489
#else
490
    NULL,
491
#endif
492
#ifdef INCLUDE_ALI_DRIVER
493
    &__svgalib_ali_driverspecs,
494
#else
495
    NULL,
496
#endif
497
#ifdef INCLUDE_MACH64_DRIVER
498
    &__svgalib_mach64_driverspecs,
499
#else
500
    NULL,
501
#endif
502
#ifdef INCLUDE_CHIPS_DRIVER
503
    &__svgalib_chips_driverspecs,
504
#else
505
    NULL,
506
#endif
507
#ifdef INCLUDE_APM_DRIVER
508
    &__svgalib_apm_driverspecs,
509
#else
510
    NULL,
511
#endif
512
#ifdef INCLUDE_NV3_DRIVER
513
    &__svgalib_nv3_driverspecs,
514
#else
515
    NULL,
516
#endif
517
#ifdef INCLUDE_ET6000_DRIVER
518
    &__svgalib_et6000_driverspecs,
519
#else
520
    NULL,
521
#endif
522
#ifdef INCLUDE_VESA_DRIVER
523
    &__svgalib_vesa_driverspecs,
524
#else
525
    NULL,
526
#endif
527
#ifdef INCLUDE_MX_DRIVER
528
    &__svgalib_mx_driverspecs,
529
#else
530
    NULL,
531
#endif
532
#ifdef INCLUDE_PARADISE_DRIVER
533
    &__svgalib_paradise_driverspecs,
534
#else
535
    NULL,
536
#endif
537
#ifdef INCLUDE_RAGE_DRIVER
538
    &__svgalib_rage_driverspecs,
539
#else
540
    NULL,
541
#endif
542
#ifdef INCLUDE_BANSHEE_DRIVER
543
    &__svgalib_banshee_driverspecs,
544
#else
545
    NULL,
546
#endif
547
#ifdef INCLUDE_SIS_DRIVER
548
    &__svgalib_sis_driverspecs,
549
#else
550
    NULL,
551
#endif
552
#ifdef INCLUDE_I740_DRIVER
553
    &__svgalib_i740_driverspecs,
554
#else
555
    NULL,
556
#endif
557
#ifdef INCLUDE_NEO_DRIVER
558
    &__svgalib_neo_driverspecs,
559
#else
560
    NULL,
561
#endif
562
#ifdef INCLUDE_LAGUNA_DRIVER
563
    &__svgalib_laguna_driverspecs,
564
#else
565
    NULL,
566
#endif
567
#ifdef INCLUDE_FBDEV_DRIVER
568
     &__svgalib_fbdev_driverspecs,
569
#else
570
     NULL,
571
#endif
572
#ifdef INCLUDE_G400_DRIVER
573
    &__svgalib_g400_driverspecs,
574
#else
575
    NULL,
576
#endif
577
#ifdef INCLUDE_R128_DRIVER
578
    &__svgalib_r128_driverspecs,
579
#else
580
    NULL,
581
#endif
582
#ifdef INCLUDE_SAVAGE_DRIVER
583
    &__svgalib_savage_driverspecs,
584
#else
585
    NULL,
586
#endif
587
#ifdef INCLUDE_MILLENNIUM_DRIVER
588
    &__svgalib_mil_driverspecs,
589
#else
590
    NULL,
591
#endif
592
#ifdef INCLUDE_I810_DRIVER
593
    &__svgalib_i810_driverspecs,
594
#else
595
    NULL,
596
#endif
597
#ifdef INCLUDE_TRIDENT_DRIVER
598
    &__svgalib_trident_driverspecs,
599
#else
600
    NULL,
601
#endif
602
#ifdef INCLUDE_RENDITION_DRIVER
603
    &__svgalib_rendition_driverspecs,
604
#else
605
    NULL,
606
#endif
607
#ifdef INCLUDE_G450C2_DRIVER
608
    &__svgalib_g450c2_driverspecs,
609
#else
610
    NULL,
611
#endif
612
#ifdef INCLUDE_PM2_DRIVER
613
    &__svgalib_pm2_driverspecs,
614
#else
615
    NULL,
616
#endif
617
};
618
 
619
static char *driver_names[] =
620
{
621
"",
622
"VGA",
623
"ET4000",
624
"Cirrus",
625
"TVGA",
626
"Oak",
627
"EGA",
628
"S3",
629
"ET3000",
630
"Mach32",
631
"GVGA6400",
632
"ARK",
633
"ATI",
634
"ALI",
635
"Mach64",
636
"C&T",
637
"APM",
638
"NV3",
639
"ET6000",
640
"VESA",
641
"MX",
642
"PARADISE",
643
"RAGE",
644
"BANSHEE",
645
"SIS",
646
"I740",
647
"NEOMAGIC",
648
"LAGUNA",
649
"FBDev",
650
"G400",
651
"R128",
652
"SAVAGE",
653
"MILLENNIUM",
654
"I810",
655
"TRIDENT",
656
"RENDITION",
657
"G450C2",
658
"PM2",
659
 NULL};
660
 
661
/* Chipset drivers */
662
 
663
/* vgadrv       Standard VGA (also used by drivers below) */
664
/* et4000       Tseng ET4000 (from original vgalib) */
665
/* cirrus       Cirrus Logic GD542x */
666
/* tvga8900     Trident TVGA 8900/9000 (derived from tvgalib) */
667
/* oak          Oak Technologies 037/067/077 */
668
/* egadrv       IBM EGA (subset of VGA) */
669
/* s3           S3 911 */
670
/* mach32       ATI MACH32 */
671
/* ark          ARK Logic */
672
/* gvga6400     Genoa 6400 (old SVGA) */
673
/* ati          ATI */
674
/* ali          ALI2301 */
675
/* mach64       ATI MACH64 */
676
/* chips        chips & technologies*/
677
/* et6000       Tseng ET6000 */         /* DS */
678
 
679
inline void vga_setpage(int p)
680
{
681
    p += vga_page_offset;
682
    if (p == __svgalib_currentpage)
683
        return;
684
 
685
    __svgalib_currentpage = p;
686
}
687
 
688
int __svgalib_setregs(const unsigned char *regs)
689
{
690
    int i;
691
 
692
    if(__svgalib_novga) return 1;
693
 
694
    if (__svgalib_chipset == EGA) {
695
        /* Enable graphics register modification */
696
        port_out(0x00, GRA_E0);
697
        port_out(0x01, GRA_E1);
698
    }
699
    /* update misc output register */
700
    __svgalib_outmisc(regs[MIS]);
701
 
702
    /* synchronous reset on */
703
    __svgalib_outseq(0x00,0x01);
704
 
705
    /* write sequencer registers */
706
    __svgalib_outseq(0x01,regs[SEQ + 1] | 0x20);
707
    for (i = 2; i < SEQ_C; i++) {
708
       __svgalib_outseq(i,regs[SEQ + i]);
709
    }
710
 
711
    /* synchronous reset off */
712
    __svgalib_outseq(0x00,0x03);
713
 
714
    if (__svgalib_chipset != EGA) {
715
        /* deprotect CRT registers 0-7 */
716
        __svgalib_outcrtc(0x11,__svgalib_incrtc(0x11)&0x7f);
717
    }
718
    /* write CRT registers */
719
    for (i = 0; i < CRT_C; i++) {
720
        __svgalib_outcrtc(i,regs[CRT + i]);
721
    }
722
 
723
    /* write graphics controller registers */
724
    for (i = 0; i < GRA_C; i++) {
725
        __svgalib_outgra(i,regs[GRA+i]);
726
    }
727
 
728
    /* write attribute controller registers */
729
    for (i = 0; i < ATT_C; i++) {
730
        __svgalib_outatt(i,regs[ATT+i]);
731
    }
732
 
733
    return 0;
734
}
735
 
736
int vga_screenon(void)
737
{
738
    int tmp = 0;
739
 
740
    SCREENON = 1;
741
    if(__svgalib_novga) return 0;
742
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenon) {
743
        tmp = __svgalib_driverspecs->emul->screenon();
744
    } else {
745
        /* turn screen back on */
746
        if ((CHIPSET != EGA) && !__svgalib_novga) {
747
            __svgalib_outseq(0x01,__svgalib_inseq(0x01) & 0xdf);
748
        }
749
/* #ifdef DISABLE_VIDEO_OUTPUT */
750
        /* enable video output */
751
        __svgalib_attscreen(0x20);
752
/* #endif */
753
    }
754
 
755
    return 0;
756
}
757
 
758
int vga_claimvideomemory(int m)
759
{
760
    vga_modeinfo *modeinfo;
761
    int cardmemory;
762
 
763
    modeinfo = vga_getmodeinfo(CM);
764
    if (m < VMEM)
765
        return 0;
766
    if (modeinfo->colors == 16)
767
        cardmemory = modeinfo->maxpixels / 2;
768
    else
769
        cardmemory = (modeinfo->maxpixels * modeinfo->bytesperpixel
770
                      + 2) & 0xffff0000;
771
    /* maxpixels * bytesperpixel can be 2 less than video memory in */
772
    /* 3 byte-per-pixel modes; assume memory is multiple of 64K */
773
    if (m > cardmemory)
774
        return -1;
775
    VMEM = m;
776
    return 0;
777
}
778
 
779
void map_banked() {
780
 
781
    if(__svgalib_emulatepage){
782
              BANKED_POINTER=(void *)__svgalib_linear_mem_base;
783
    } else {
784
              BANKED_POINTER=(void *)__svgalib_banked_mem_base;
785
    }
786
 
787
}
788
 
789
void map_mmio() {
790
 
791
    if(mmio_mapped) return;
792
 
793
    if(__svgalib_mmio_size) {
794
        mmio_mapped=1;
795
        MMIO_POINTER=(void *)__svgalib_mmio_base;
796
    } else {
797
        MMIO_POINTER=NULL;
798
        SPARSE_MMIO=NULL;
799
    }
800
}
801
 
802
void map_mem() {
803
 
804
    if(mem_mapped) return;
805
 
806
    if(__svgalib_banked_mem_size==0) __svgalib_banked_mem_size = 0x10000;
807
 
808
    map_banked();
809
 
810
    if(__svgalib_linear_mem_size) {
811
        map_linear(__svgalib_linear_mem_base, __svgalib_linear_mem_size);
812
    };
813
 
814
    B8000_POINTER = (void *)0xb8000;
815
 
816
    mem_mapped = 1;
817
 
818
}
819
 
820
static void __vga_map(void)
821
{
822
    GM = (unsigned char *) BANKED_POINTER;
823
    graph_mem = GM;     /* Exported variable. */
824
}
825
 
826
static void map_vgaio(void)
827
{
828
    __svgalib_inmisc=__svgalib_vga_inmisc;
829
    __svgalib_outmisc=__svgalib_vga_outmisc;
830
    __svgalib_incrtc=__svgalib_vga_incrtc;
831
    __svgalib_outcrtc=__svgalib_vga_outcrtc;
832
    __svgalib_inseq=__svgalib_vga_inseq;
833
    __svgalib_outseq=__svgalib_vga_outseq;
834
    __svgalib_ingra=__svgalib_vga_ingra;
835
    __svgalib_outgra=__svgalib_vga_outgra;
836
    __svgalib_inatt=__svgalib_vga_inatt;
837
    __svgalib_outatt=__svgalib_vga_outatt;
838
    __svgalib_attscreen=__svgalib_vga_attscreen;
839
    __svgalib_inpal=__svgalib_vga_inpal;
840
    __svgalib_outpal=__svgalib_vga_outpal;
841
    __svgalib_inis1=__svgalib_vga_inis1;
842
}
843
 
844
int __svgalib_saveregs(unsigned char *regs)
845
{
846
    int i;
847
 
848
    if (__svgalib_chipset == EGA || __svgalib_novga) {
849
        /* Special case: Don't save standard VGA registers. */
850
        return chipset_saveregs(regs);
851
    }
852
    /* save VGA registers */
853
    for (i = 0; i < CRT_C; i++) {
854
        regs[CRT + i] = __svgalib_incrtc(i);
855
    }
856
    for (i = 0; i < ATT_C; i++) {
857
        regs[ATT + i] = __svgalib_inatt(i);
858
    }
859
    for (i = 0; i < GRA_C; i++) {
860
        regs[GRA + i] = __svgalib_ingra(i);
861
    }
862
    for (i = 0; i < SEQ_C; i++) {
863
        regs[SEQ + i] = __svgalib_inseq(i);
864
    }
865
    regs[MIS] = __svgalib_inmisc();
866
 
867
    i = chipset_saveregs(regs); /* save chipset-specific registers */
868
    /* i : additional registers */
869
    if (!SCREENON) {            /* We turned off the screen */
870
        __svgalib_attscreen(0x20);
871
    }
872
    return CRT_C + ATT_C + GRA_C + SEQ_C + 1 + i;
873
}
874
 
875
int vga_setcolor(int color)
876
{
877
    switch (CI.colors) {
878
    case 2:
879
        if (color != 0)
880
            color = 15;
881
    case 16:                    /* update set/reset register */
882
        __svgalib_outgra(0x00,color&0x0f);
883
        break;
884
    default:
885
        COL = color;
886
        break;
887
    }
888
    return 0;
889
}
890
 
891
vga_modeinfo *vga_getmodeinfo(int mode)
892
{
893
    static vga_modeinfo modeinfo;
894
    int is_modeX = (CM == mode) && MODEX;
895
 
896
    printk(KERN_INFO "getmodeinfo %i\n",mode);
897
 
898
    modeinfo.linewidth = infotable[mode].xbytes;
899
    __svgalib_getchipset(CHIPSET);
900
    if (mode > vga_lastmodenumber())
901
        return NULL;
902
    modeinfo.width = infotable[mode].xdim;
903
    modeinfo.height = infotable[mode].ydim;
904
    modeinfo.bytesperpixel = infotable[mode].bytesperpixel;
905
    modeinfo.colors = infotable[mode].colors;
906
    if (is_modeX) {
907
        modeinfo.linewidth = modeinfo.width / 4;
908
        modeinfo.bytesperpixel = 0;
909
    }
910
    if (mode == TEXT) {
911
        modeinfo.flags = HAVE_EXT_SET;
912
        return &modeinfo;
913
    }
914
    modeinfo.flags = 0;
915
    if ((STDVGAMODE(mode) && mode != G320x200x256) || is_modeX)
916
        __svgalib_vga_driverspecs.getmodeinfo(mode, &modeinfo);
917
    else
918
        /* Get chipset specific info for SVGA modes and */
919
        /* 320x200x256 (chipsets may support more pages) */
920
        chipset_getmodeinfo(mode, &modeinfo);
921
 
922
    if (modeinfo.colors == 256 && modeinfo.bytesperpixel == 0)
923
        modeinfo.flags |= IS_MODEX;
924
    if (mode > __GLASTMODE)
925
        modeinfo.flags |= IS_DYNAMICMODE;
926
 
927
    /* Maskout CAPABLE_LINEAR if requested by config file */
928
    modeinfo.flags &= modeinfo_mask;
929
 
930
    /* Many cards have problems with linear 320x200x256 mode */
931
    if(mode==G320x200x256)modeinfo.flags &= (~CAPABLE_LINEAR) & (~IS_LINEAR) ;
932
 
933
    /* If all needed info is here, signal if linear support has been enabled */
934
    if ((modeinfo.flags & (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) ==
935
        (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) {
936
        modeinfo.flags |= __svgalib_modeinfo_linearset;
937
    }
938
 
939
    return &modeinfo;
940
}
941
 
942
char *__svgalib_token(char **ptr)
943
{
944
    char *p;
945
    p=*ptr;
946
    while(*p==' ')p++;
947
 
948
    if(*p != '\0' ) {
949
        char *t;
950
        t=p;
951
        while((*t != '\0') && (*t != ' '))t++;
952
        if(*t==' ') {
953
            *t='\0';
954
            t++;
955
        }
956
        *ptr=t;
957
        return p;
958
    } else {
959
        *ptr=NULL;
960
        return NULL;
961
    }
962
}
963
 
964
int vga_lastmodenumber(void)
965
{
966
    __svgalib_getchipset(CHIPSET);
967
    return lastmodenumber;
968
}
969
 
970
int __svgalib_getchipset(int set_chipset)
971
{
972
 
973
    /* SHARK: Supported Graphics Drivers
974
     *
975
     * NVIDIA
976
     * SAVAGE
977
     *
978
     */
979
 
980
    CHIPSET = set_chipset;
981
 
982
    if(!initialized) {
983
 
984
        map_vgaio();
985
        init_vgapci();
986
 
987
        switch(CHIPSET) {
988
                case NV3:
989
                  nv3_test();
990
                  break;
991
                case SAVAGE:
992
                  savage_test();
993
                  break;
994
        }
995
 
996
    }
997
 
998
    return CHIPSET;
999
 
1000
}
1001
 
1002
void __svgalib_delay(void)
1003
{
1004
    int i;
1005
    for (i = 0; i < 10; i++);
1006
}
1007
 
1008
int vga_screenoff(void)
1009
{
1010
    int tmp = 0;
1011
 
1012
    SCREENON = 0;
1013
 
1014
    if(__svgalib_novga) return 0;
1015
 
1016
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenoff) {
1017
        tmp = __svgalib_driverspecs->emul->screenoff();
1018
    } else {
1019
        /* turn off screen for faster VGA memory acces */
1020
        if ((CHIPSET != EGA) && !__svgalib_novga) {
1021
            __svgalib_outseq(0x01,__svgalib_inseq(0x01) | 0x20);
1022
        }
1023
        /* Disable video output */
1024
#ifdef DISABLE_VIDEO_OUTPUT
1025
        __svgalib_attscreen(0);
1026
#endif
1027
    }
1028
 
1029
    return tmp;
1030
}
1031
 
1032
static void setcoloremulation(void)
1033
{
1034
    /* shift to color emulation */
1035
    __svgalib_CRT_I = CRT_IC;
1036
    __svgalib_CRT_D = CRT_DC;
1037
    __svgalib_IS1_R = IS1_RC;
1038
    __svgalib_vgacolormode=1;
1039
    if (CHIPSET != EGA && !__svgalib_novga)  
1040
        __svgalib_outmisc(__svgalib_inmisc()|0x01);
1041
}
1042
 
1043
void map_linear(unsigned long base, unsigned long size) {
1044
 
1045
    LINEAR_POINTER= (void *)base;
1046
 
1047
}
1048
 
1049
static void savepalette(unsigned char *red, unsigned char *green,
1050
                        unsigned char *blue)
1051
{
1052
    int i;
1053
 
1054
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->savepalette)
1055
        return (__svgalib_driverspecs->emul->savepalette(red, green, blue));
1056
 
1057
    if (CHIPSET == EGA || __svgalib_novga)
1058
        return;
1059
 
1060
    /* save graphics mode palette */
1061
 
1062
    for (i = 0; i < 256; i++) {
1063
        int r,g,b;
1064
        __svgalib_inpal(i,&r,&g,&b);
1065
        *(red++) = r;
1066
        *(green++) = g;
1067
        *(blue++) = b;
1068
    }
1069
}
1070
 
1071
static void restorepalette(const unsigned char *red,
1072
                   const unsigned char *green, const unsigned char *blue)
1073
{
1074
    int i;
1075
 
1076
    if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->restorepalette)
1077
        return (__svgalib_driverspecs->emul->restorepalette(red, green, blue));
1078
 
1079
    if (CHIPSET == EGA || __svgalib_novga)
1080
        return;
1081
 
1082
    /* restore saved palette */
1083
    /* read RGB components - index is autoincremented */
1084
    for (i = 0; i < 256; i++) {
1085
        __svgalib_outpal(i,*(red++),*(green++),*(blue++));
1086
    }
1087
}
1088
 
1089
int vga_getcurrentmode(void)
1090
{
1091
    return CM;
1092
}
1093
 
1094
 
1095
static void initialize(int set_chipset)
1096
{
1097
    int i;
1098
 
1099
    printk(KERN_INFO "Initialize\n");
1100
 
1101
//    __svgalib_disable_interrupt();    /* Is reenabled later by set_texttermio */
1102
 
1103
    __svgalib_getchipset(set_chipset);
1104
    chipset_unlock();
1105
 
1106
    /* mmap graphics memory */
1107
    map_mem();
1108
    map_mmio();
1109
 
1110
    __vga_map();
1111
 
1112
    /* disable video */
1113
    vga_screenoff();
1114
 
1115
    /* Sanity check: (from painful experience) */
1116
    i = __svgalib_saveregs(text_regs);
1117
    if (i > MAX_REGS) {
1118
        printk(KERN_INFO "svgalib: FATAL internal error:\n");
1119
        printk(KERN_INFO "Set MAX_REGS at least to %d in src/driver.h and recompile everything.\n",
1120
               i);
1121
    }
1122
 
1123
    /* save text mode palette */
1124
    savepalette(text_red, text_green, text_blue);
1125
 
1126
    /* shift to color emulation */
1127
    setcoloremulation();
1128
 
1129
    initialized = 1;
1130
 
1131
    /* vga_unlockvc(); */
1132
 
1133
}
1134
 
1135
void vga_gettextfont(void *font)
1136
{
1137
    unsigned int getsize;
1138
 
1139
    getsize = fontbufsize;
1140
    if (getsize > FONT_SIZE)
1141
        getsize = FONT_SIZE;
1142
    memcpy(font, font_buf1, getsize);
1143
    if (fontbufsize > getsize)
1144
        memset(((char *)font) + getsize, 0, (size_t)(fontbufsize - getsize));
1145
}
1146
 
1147
void vga_puttextfont(void *font)
1148
{
1149
    unsigned int putsize;
1150
 
1151
    putsize = fontbufsize;
1152
    if (putsize > FONT_SIZE)
1153
        putsize = FONT_SIZE;
1154
    memcpy(font_buf1, font, putsize);
1155
    memcpy(font_buf2, font, putsize);
1156
    if (putsize < FONT_SIZE) {
1157
        memset(font_buf1 + putsize, 0, (size_t)(FONT_SIZE - putsize));
1158
        memset(font_buf2 + putsize, 0, (size_t)(FONT_SIZE - putsize));
1159
    }
1160
 
1161
}
1162
 
1163
int vga_setmode(int mode,int set_chipset)
1164
{
1165
    int modeflags=mode&0xfffff000;
1166
#ifndef VM86
1167
    BYTE p1,p2;
1168
#endif
1169
 
1170
    printk(KERN_INFO "Setmode %i from %i\n", mode, CM);
1171
 
1172
    if(mode==-1)return vga_version;
1173
 
1174
    mode&=0xfff;
1175
 
1176
    if (!initialized) {
1177
        if (mode == TEXT) return 0;
1178
        initialize(set_chipset);
1179
    }
1180
 
1181
    if (mode != TEXT && !chipset_modeavailable(mode)) {
1182
        return -1;
1183
    }
1184
 
1185
//    __svgalib_disable_interrupt();
1186
 
1187
    prv_mode = CM;
1188
    CM = mode;
1189
 
1190
    /* disable video */
1191
    vga_screenoff();
1192
 
1193
    if (mode == TEXT) {
1194
        /* Returning to textmode. */
1195
 
1196
        X_REGS16 inregs, outregs;
1197
        X_SREGS16 sregs;
1198
 
1199
        inregs.x.ax = 0x03;
1200
#ifndef VM86
1201
        p1 = inp(0x21);
1202
        p2 = inp(0xA1);
1203
        outp(0x21,0xFF);
1204
        outp(0xA1,0xFF);
1205
        X_callBIOS(0x10, &inregs, &outregs, &sregs);
1206
        outp(0x21,p1);
1207
        outp(0xA1,p2);
1208
#else
1209
        vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
1210
#endif
1211
 
1212
        if (SVGAMODE(prv_mode)) vga_setpage(0);
1213
 
1214
    } else {
1215
        /* Setting a graphics mode. */
1216
 
1217
        if (SVGAMODE(prv_mode)) {
1218
            /* The current mode is an SVGA mode, and we now want to */
1219
            /* set a standard VGA mode. Make sure the extended regs */
1220
            /* are restored. */
1221
            /* Also used when setting another SVGA mode to hopefully */
1222
            /* eliminate lock-ups. */
1223
            vga_setpage(0);
1224
            chipset_setregs(text_regs, mode);
1225
            /* restore old extended regs */
1226
        }
1227
        /* shift to color emulation */
1228
        setcoloremulation();
1229
 
1230
        CI.xdim = infotable[mode].xdim;
1231
        CI.ydim = infotable[mode].ydim;
1232
        CI.colors = infotable[mode].colors;
1233
        CI.xbytes = infotable[mode].xbytes;
1234
        CI.bytesperpixel = infotable[mode].bytesperpixel;
1235
 
1236
        chipset_setmode(mode, prv_mode);
1237
        MODEX = 0;
1238
 
1239
        /* Set default claimed memory (moved here from initialize - Michael.) */
1240
        if (mode == G320x200x256)
1241
            VMEM = 65536;
1242
        else if (STDVGAMODE(mode))
1243
            VMEM = 256 * 1024;  /* Why always 256K ??? - Michael */
1244
        else {
1245
            vga_modeinfo *modeinfo;
1246
 
1247
            modeinfo = vga_getmodeinfo(mode);
1248
            VMEM = modeinfo->linewidth * modeinfo->height;
1249
            CI.xbytes = modeinfo->linewidth;
1250
        }
1251
 
1252
        if (!flip) {
1253
            /* set default palette */
1254
            if (CI.colors <= 256)
1255
                restorepalette(default_red, default_green, default_blue);
1256
 
1257
            /* clear screen (sets current color to 15) */
1258
            __svgalib_currentpage = -1;
1259
            if(!(modeflags&0x8000))vga_clear();
1260
 
1261
            if (SVGAMODE(CM))
1262
                vga_setpage(0);
1263
        }
1264
        __svgalib_currentpage = -1;
1265
        currentlogicalwidth = CI.xbytes;
1266
        currentdisplaystart = 0;
1267
 
1268
        /* enable video */
1269
        if (!flip)
1270
            vga_screenon();
1271
 
1272
        {
1273
            vga_modeinfo *modeinfo;
1274
            modeinfo = vga_getmodeinfo(mode);
1275
            MODEX = ((MODEFLAGS = modeinfo->flags) & IS_MODEX);
1276
        }
1277
 
1278
//      __svgalib_enable_interrupt();
1279
    }
1280
 
1281
    return 0;
1282
 
1283
}
1284
 
1285
inline void copy_videomem_32to16(void *src, void *dst, unsigned long int memdiv2)
1286
{
1287
          __asm__ __volatile__("push %%esi
1288
                                push %%edi
1289
                                movl %1, %%esi
1290
                                movl %2, %%edi
1291
                                1:
1292
                                movl (%%esi), %%edx
1293
                                xorl %%ebx, %%ebx
1294
                                xorw %%ax, %%ax
1295
                                movb %%dl, %%al
1296
                                shrl $0x8, %%edx
1297
                                shrw $0x3, %%ax
1298
                                orw  %%ax, %%bx
1299
                                shll $0x6, %%ebx
1300
                                xorw %%ax, %%ax
1301
                                movb %%dl, %%al
1302
                                shrl $0x8, %%edx
1303
                                shrw $0x2, %%ax
1304
                                orw  %%ax, %%bx
1305
                                shll $0x5, %%ebx
1306
                                xorw %%ax, %%ax
1307
                                movb %%dl, %%al
1308
                                shrw $0x3, %%ax
1309
                                orw  %%ax, %%bx
1310
                                shll $0x5, %%ebx
1311
                                incl %%esi
1312
                                incl %%esi
1313
                                incl %%esi
1314
                                incl %%esi
1315
                                movl (%%esi), %%edx
1316
                                xorw %%ax, %%ax
1317
                                movb %%dl, %%al
1318
                                shrl $0x8,%%edx
1319
                                shrw $0x3, %%ax
1320
                                orw  %%ax, %%bx
1321
                                shll $0x6, %%ebx
1322
                                xorw %%ax, %%ax
1323
                                movb %%dl, %%al
1324
                                shrl $0x8, %%edx
1325
                                shrw $0x2, %%ax
1326
                                orw  %%ax, %%bx
1327
                                shll $0x5, %%ebx
1328
                                xorw %%ax, %%ax
1329
                                movb %%dl, %%al
1330
                                shrw $0x3, %%ax
1331
                                orw  %%ax, %%bx
1332
                                rorl $0x10, %%ebx
1333
                                movl %%ebx, (%%edi)
1334
                                incl %%esi
1335
                                incl %%esi
1336
                                incl %%esi
1337
                                incl %%esi
1338
                                incl %%edi
1339
                                incl %%edi
1340
                                incl %%edi
1341
                                incl %%edi
1342
                                loop 1b
1343
                                pop %%edi
1344
                                pop %%esi"
1345
                                :
1346
                                : "c" (memdiv2), "a" (src), "b" (dst));
1347
 
1348
}