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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
/*-
* Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer as
* the first lines of this file unmodified.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: scvidctl.c,v 1.7 1999/01/19 11:31:16 yokota Exp $
*/
#include "sc.h"
#include "opt_syscons.h"
#if NSC > 0
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/tty.h>
#include <sys/kernel.h>
#ifdef __i386__
#include <machine/apm_bios.h>
#endif
#include <machine/console.h>
#include <dev/fb/fbreg.h>
#include <dev/syscons/syscons.h>
/* for compatibility with previous versions */
typedef struct old_video_adapter {
int va_index;
int va_type;
int va_flags;
#define V_ADP_COLOR (1<<0)
#define V_ADP_MODECHANGE (1<<1)
#define V_ADP_STATESAVE (1<<2)
#define V_ADP_STATELOAD (1<<3)
#define V_ADP_FONT (1<<4)
#define V_ADP_PALETTE (1<<5)
#define V_ADP_BORDER (1<<6)
#define V_ADP_VESA (1<<7)
int va_crtc_addr;
u_int va_window; /* virtual address */
size_t va_window_size;
size_t va_window_gran;
u_int va_buffer; /* virtual address */
size_t va_buffer_size;
int va_initial_mode;
int va_initial_bios_mode;
int va_mode;
} old_video_adapter_t;
#define OLD_CONS_ADPINFO _IOWR('c', 101, old_video_adapter_t)
/* variables */
extern scr_stat *cur_console;
extern int fonts_loaded;
extern int sc_history_size;
extern u_char palette[];
int
sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
int fontsize)
{
video_info_t info;
int error;
int s;
int i;
if ((*vidsw[scp->ad]->get_info)(scp->adp, mode, &info))
return ENODEV;
/* adjust argument values */
if (fontsize <= 0)
fontsize = info.vi_cheight;
if (fontsize < 14) {
fontsize = 8;
if (!(fonts_loaded & FONT_8))
return EINVAL;
} else if (fontsize >= 16) {
fontsize = 16;
if (!(fonts_loaded & FONT_16))
return EINVAL;
} else {
fontsize = 14;
if (!(fonts_loaded & FONT_14))
return EINVAL;
}
if ((xsize <= 0) || (xsize > info.vi_width))
xsize = info.vi_width;
if ((ysize <= 0) || (ysize > info.vi_height))
ysize = info.vi_height;
/* stop screen saver, etc */
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
/* set up scp */
if (scp->history != NULL)
i = imax(scp->history_size / scp->xsize
- imax(sc_history_size, scp->ysize), 0);
else
i = 0;
/*
* This is a kludge to fend off scrn_update() while we
* muck around with scp. XXX
*/
scp->status |= UNKNOWN_MODE;
scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
scp->mode = mode;
scp->font_size = fontsize;
scp->xsize = xsize;
scp->ysize = ysize;
scp->xoff = 0;
scp->yoff = 0;
scp->xpixel = scp->xsize*8;
scp->ypixel = scp->ysize*fontsize;
/* allocate buffers */
sc_alloc_scr_buffer(scp, TRUE, TRUE);
if (ISMOUSEAVAIL(scp->adp->va_flags))
sc_alloc_cut_buffer(scp, FALSE);
sc_alloc_history_buffer(scp, sc_history_size, i, FALSE);
splx(s);
if (scp == cur_console)
set_mode(scp);
scp->status &= ~UNKNOWN_MODE;
if (tp == NULL)
return 0;
if (tp->t_winsize.ws_col != scp->xsize
|| tp->t_winsize.ws_row != scp->ysize) {
tp->t_winsize.ws_col = scp->xsize;
tp->t_winsize.ws_row = scp->ysize;
pgsignal(tp->t_pgrp, SIGWINCH, 1);
}
return 0;
}
int
sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
{
video_info_t info;
int error;
int s;
if ((*vidsw[scp->ad]->get_info)(scp->adp, mode, &info))
return ENODEV;
/* stop screen saver, etc */
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
/* set up scp */
scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE);
scp->status &= ~PIXEL_MODE;
scp->mode = mode;
scp->xoff = 0;
scp->yoff = 0;
scp->xpixel = info.vi_width;
scp->ypixel = info.vi_height;
scp->xsize = info.vi_width/8;
scp->ysize = info.vi_height/info.vi_cheight;
scp->font_size = FONT_NONE;
/* move the mouse cursor at the center of the screen */
sc_move_mouse(scp, scp->xpixel / 2, scp->ypixel / 2);
splx(s);
if (scp == cur_console)
set_mode(scp);
/* clear_graphics();*/
scp->status &= ~UNKNOWN_MODE;
if (tp == NULL)
return 0;
if (tp->t_winsize.ws_xpixel != scp->xpixel
|| tp->t_winsize.ws_ypixel != scp->ypixel) {
tp->t_winsize.ws_xpixel = scp->xpixel;
tp->t_winsize.ws_ypixel = scp->ypixel;
pgsignal(tp->t_pgrp, SIGWINCH, 1);
}
return 0;
}
int
sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
int fontsize)
{
video_info_t info;
int error;
int s;
int i;
if ((*vidsw[scp->ad]->get_info)(scp->adp, scp->mode, &info))
return ENODEV; /* this shouldn't happen */
#ifdef SC_VIDEO_DEBUG
if (scp->scr_buf != NULL) {
printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",
scp->mode, xsize, ysize, fontsize);
}
#endif
/* adjust argument values */
if ((fontsize <= 0) || (fontsize == FONT_NONE))
fontsize = info.vi_cheight;
if (fontsize < 14) {
fontsize = 8;
if (!(fonts_loaded & FONT_8))
return EINVAL;
} else if (fontsize >= 16) {
fontsize = 16;
if (!(fonts_loaded & FONT_16))
return EINVAL;
} else {
fontsize = 14;
if (!(fonts_loaded & FONT_14))
return EINVAL;
}
if (xsize <= 0)
xsize = info.vi_width/8;
if (ysize <= 0)
ysize = info.vi_height/fontsize;
#ifdef SC_VIDEO_DEBUG
if (scp->scr_buf != NULL) {
printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",
scp->mode, xsize, ysize, fontsize);
printf("set_pixel_mode(): window:%x, %dx%d, xoff:%d, yoff:%d\n",
scp->adp->va_window, info.vi_width, info.vi_height,
(info.vi_width/8 - xsize)/2,
(info.vi_height/fontsize - ysize)/2);
}
#endif
if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
return EINVAL;
/* only 16 color, 4 plane modes are supported XXX */
if ((info.vi_depth != 4) || (info.vi_planes != 4))
return ENODEV;
/*
* set_pixel_mode() currently does not support video modes whose
* memory size is larger than 64K. Because such modes require
* bank switching to access the entire screen. XXX
*/
if (info.vi_width*info.vi_height/8 > info.vi_window_size)
return ENODEV;
/* stop screen saver, etc */
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
/* set up scp */
if (scp->history != NULL)
i = imax(scp->history_size / scp->xsize
- imax(sc_history_size, scp->ysize), 0);
else
i = 0;
scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
scp->status &= ~(GRAPHICS_MODE | MOUSE_ENABLED);
scp->xsize = xsize;
scp->ysize = ysize;
scp->font_size = fontsize;
scp->xoff = (scp->xpixel/8 - xsize)/2;
scp->yoff = (scp->ypixel/fontsize - ysize)/2;
/* allocate buffers */
sc_alloc_scr_buffer(scp, TRUE, TRUE);
if (ISMOUSEAVAIL(scp->adp->va_flags))
sc_alloc_cut_buffer(scp, FALSE);
sc_alloc_history_buffer(scp, sc_history_size, i, FALSE);
splx(s);
if (scp == cur_console)
set_border(scp, scp->border);
scp->status &= ~UNKNOWN_MODE;
#ifdef SC_VIDEO_DEBUG
printf("set_pixel_mode(): status:%x\n", scp->status);
#endif
if (tp == NULL)
return 0;
if (tp->t_winsize.ws_col != scp->xsize
|| tp->t_winsize.ws_row != scp->ysize) {
tp->t_winsize.ws_col = scp->xsize;
tp->t_winsize.ws_row = scp->ysize;
pgsignal(tp->t_pgrp, SIGWINCH, 1);
}
return 0;
}
int
sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
{
scr_stat *scp;
int error;
int s;
scp = sc_get_scr_stat(tp->t_dev);
switch (cmd) {
case CONS_CURRENT: /* get current adapter type */
if (scp->adp == NULL)
return ENODEV;
*(int *)data = scp->adp->va_type;
return 0;
case CONS_CURRENTADP: /* get current adapter index */
*(int *)data = scp->ad;
return 0;
case OLD_CONS_ADPINFO: /* adapter information */
if (scp->adp == NULL)
return ENODEV;
((old_video_adapter_t *)data)->va_index = scp->adp->va_index;
((old_video_adapter_t *)data)->va_type = scp->adp->va_type;
((old_video_adapter_t *)data)->va_flags = scp->adp->va_flags;
((old_video_adapter_t *)data)->va_crtc_addr = scp->adp->va_crtc_addr;
((old_video_adapter_t *)data)->va_window = scp->adp->va_window;
((old_video_adapter_t *)data)->va_window_size
= scp->adp->va_window_size;
((old_video_adapter_t *)data)->va_window_gran
= scp->adp->va_window_gran;
((old_video_adapter_t *)data)->va_buffer = scp->adp->va_buffer;
((old_video_adapter_t *)data)->va_buffer_size
= scp->adp->va_buffer_size;
((old_video_adapter_t *)data)->va_mode = scp->adp->va_mode;
((old_video_adapter_t *)data)->va_initial_mode
= scp->adp->va_initial_mode;
((old_video_adapter_t *)data)->va_initial_bios_mode
= scp->adp->va_initial_bios_mode;
return 0;
case CONS_ADPINFO: /* adapter information */
if (scp->adp == NULL)
return ENODEV;
((video_adapter_info_t *)data)->va_index = scp->adp->va_index;
((video_adapter_info_t *)data)->va_type = scp->adp->va_type;
bcopy(scp->adp->va_name, ((video_adapter_info_t *)data)->va_name,
imin(strlen(scp->adp->va_name) + 1,
sizeof(((video_adapter_info_t *)data)->va_name)));
((video_adapter_info_t *)data)->va_unit = scp->adp->va_unit;
((video_adapter_info_t *)data)->va_flags = scp->adp->va_flags;
((video_adapter_info_t *)data)->va_io_base = scp->adp->va_io_base;
((video_adapter_info_t *)data)->va_io_size = scp->adp->va_io_size;
((video_adapter_info_t *)data)->va_crtc_addr = scp->adp->va_crtc_addr;
((video_adapter_info_t *)data)->va_mem_base = scp->adp->va_mem_base;
((video_adapter_info_t *)data)->va_mem_size = scp->adp->va_mem_size;
((video_adapter_info_t *)data)->va_window = scp->adp->va_window;
((video_adapter_info_t *)data)->va_window_size
= scp->adp->va_window_size;
((video_adapter_info_t *)data)->va_window_gran
= scp->adp->va_window_gran;
((video_adapter_info_t *)data)->va_buffer = scp->adp->va_buffer;
((video_adapter_info_t *)data)->va_buffer_size
= scp->adp->va_buffer_size;
((video_adapter_info_t *)data)->va_mode = scp->adp->va_mode;
((video_adapter_info_t *)data)->va_initial_mode
= scp->adp->va_initial_mode;
((video_adapter_info_t *)data)->va_initial_bios_mode
= scp->adp->va_initial_bios_mode;
((video_adapter_info_t *)data)->va_line_width = scp->adp->va_line_width;
return 0;
case CONS_GET: /* get current video mode */
*(int *)data = scp->mode;
return 0;
case CONS_MODEINFO: /* get mode information */
return ((*vidsw[scp->ad]->get_info)(scp->adp,
((video_info_t *)data)->vi_mode, (video_info_t *)data)
? ENODEV : 0);
case CONS_FINDMODE: /* find a matching video mode */
return ((*vidsw[scp->ad]->query_mode)(scp->adp, (video_info_t *)data)
? ENODEV : 0);
case CONS_SETWINORG:
return ((*vidsw[scp->ad]->set_win_org)(scp->adp, *(u_int *)data)
? ENODEV : 0);
/* generic text modes */
case SW_TEXT_80x25: case SW_TEXT_80x30:
case SW_TEXT_80x43: case SW_TEXT_80x50:
case SW_TEXT_80x60:
/* FALL THROUGH */
/* VGA TEXT MODES */
case SW_VGA_C40x25:
case SW_VGA_C80x25: case SW_VGA_M80x25:
case SW_VGA_C80x30: case SW_VGA_M80x30:
case SW_VGA_C80x50: case SW_VGA_M80x50:
case SW_VGA_C80x60: case SW_VGA_M80x60:
case SW_B40x25: case SW_C40x25:
case SW_B80x25: case SW_C80x25:
case SW_ENH_B40x25: case SW_ENH_C40x25:
case SW_ENH_B80x25: case SW_ENH_C80x25:
case SW_ENH_B80x43: case SW_ENH_C80x43:
case SW_EGAMONO80x25:
#ifdef PC98
/* PC98 TEXT MODES */
case SW_PC98_80x25:
case SW_PC98_80x30:
#endif
if (!(scp->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
/* GRAPHICS MODES */
case SW_BG320: case SW_BG640:
case SW_CG320: case SW_CG320_D: case SW_CG640_E:
case SW_CG640x350: case SW_ENH_CG640:
case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
case SW_VGA_MODEX:
if (!(scp->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
return sc_set_graphics_mode(scp, tp, cmd & 0xff);
case KDSETMODE: /* set current mode of this (virtual) console */
switch (*(int *)data) {
case KD_TEXT: /* switch to TEXT (known) mode */
/*
* If scp->mode is of graphics modes, we don't know which
* text mode to switch back to...
*/
if (scp->status & GRAPHICS_MODE)
return EINVAL;
/* restore fonts & palette ! */
#if 0
if (ISFONTAVAIL(scp->adp->va_flags)
&& !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
/*
* FONT KLUDGE
* Don't load fonts for now... XXX
*/
if (fonts_loaded & FONT_8)
copy_font(scp, LOAD, 8, font_8);
if (fonts_loaded & FONT_14)
copy_font(scp, LOAD, 14, font_14);
if (fonts_loaded & FONT_16)
copy_font(scp, LOAD, 16, font_16);
}
#endif
load_palette(scp->adp, palette);
/* move hardware cursor out of the way */
(*vidsw[scp->ad]->set_hw_cursor)(scp->adp, -1, -1);
/* FALL THROUGH */
case KD_TEXT1: /* switch to TEXT (known) mode */
/*
* If scp->mode is of graphics modes, we don't know which
* text/pixel mode to switch back to...
*/
if (scp->status & GRAPHICS_MODE)
return EINVAL;
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
#ifndef PC98
scp->status |= UNKNOWN_MODE;
splx(s);
/* no restore fonts & palette */
if (scp == cur_console)
set_mode(scp);
sc_clear_screen(scp);
scp->status &= ~UNKNOWN_MODE;
#else /* PC98 */
scp->status &= ~UNKNOWN_MODE;
/* no restore fonts & palette */
if (scp == cur_console)
set_mode(scp);
sc_clear_screen(scp);
splx(s);
#endif /* PC98 */
return 0;
case KD_PIXEL: /* pixel (raster) display */
if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
return EINVAL;
if (scp->status & GRAPHICS_MODE)
return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
scp->font_size);
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
splx(s);
if (scp == cur_console) {
set_mode(scp);
load_palette(scp->adp, palette);
}
sc_clear_screen(scp);
scp->status &= ~UNKNOWN_MODE;
return 0;
case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
return error;
}
scp->status |= UNKNOWN_MODE;
splx(s);
#ifdef PC98
if (scp == cur_console)
set_mode(scp);
#endif
return 0;
default:
return EINVAL;
}
/* NOT REACHED */
case KDRASTER: /* set pixel (raster) display mode */
if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
return ENODEV;
return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
((int *)data)[2]);
case KDGETMODE: /* get current mode of this (virtual) console */
/*
* From the user program's point of view, KD_PIXEL is the same
* as KD_TEXT...
*/
*data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
return 0;
case KDSBORDER: /* set border color of this (virtual) console */
scp->border = *data;
if (scp == cur_console)
set_border(scp, scp->border);
return 0;
}
return ENOIOCTL;
}
#endif /* NSC > 0 */
|