1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "boot.h"
19#include "video.h"
20#include "vesa.h"
21
22
23
24
25int adapter;
26int force_x, force_y;
27int do_restore;
28int graphic_mode;
29
30
31void probe_cards(int unsafe)
32{
33 struct card_info *card;
34 static u8 probed[2];
35
36 if (probed[unsafe])
37 return;
38
39 probed[unsafe] = 1;
40
41 for (card = video_cards; card < video_cards_end; card++) {
42 if (card->unsafe == unsafe) {
43 if (card->probe)
44 card->nmodes = card->probe();
45 else
46 card->nmodes = 0;
47 }
48 }
49}
50
51
52int mode_defined(u16 mode)
53{
54 struct card_info *card;
55 struct mode_info *mi;
56 int i;
57
58 for (card = video_cards; card < video_cards_end; card++) {
59 mi = card->modes;
60 for (i = 0; i < card->nmodes; i++, mi++) {
61 if (mi->mode == mode)
62 return 1;
63 }
64 }
65
66 return 0;
67}
68
69
70static int raw_set_mode(u16 mode, u16 *real_mode)
71{
72 int nmode, i;
73 struct card_info *card;
74 struct mode_info *mi;
75
76
77 mode &= ~VIDEO_RECALC;
78
79
80 nmode = 0;
81 for (card = video_cards; card < video_cards_end; card++) {
82 mi = card->modes;
83 for (i = 0; i < card->nmodes; i++, mi++) {
84 int visible = mi->x || mi->y;
85
86 if ((mode == nmode && visible) ||
87 mode == mi->mode ||
88 mode == (mi->y << 8)+mi->x) {
89 *real_mode = mi->mode;
90 return card->set_mode(mi);
91 }
92
93 if (visible)
94 nmode++;
95 }
96 }
97
98
99 for (card = video_cards; card < video_cards_end; card++) {
100 if (mode >= card->xmode_first &&
101 mode < card->xmode_first+card->xmode_n) {
102 struct mode_info mix;
103 *real_mode = mix.mode = mode;
104 mix.x = mix.y = 0;
105 return card->set_mode(&mix);
106 }
107 }
108
109
110 return -1;
111}
112
113
114
115
116static void vga_recalc_vertical(void)
117{
118 unsigned int font_size, rows;
119 u16 crtc;
120 u8 pt, ov;
121
122 set_fs(0);
123 font_size = rdfs8(0x485);
124 rows = force_y ? force_y : rdfs8(0x484)+1;
125
126 rows *= font_size;
127 rows--;
128
129 crtc = vga_crtc();
130
131 pt = in_idx(crtc, 0x11);
132 pt &= ~0x80;
133 out_idx(pt, crtc, 0x11);
134
135 out_idx((u8)rows, crtc, 0x12);
136
137 ov = in_idx(crtc, 0x07);
138 ov &= 0xbd;
139 ov |= (rows >> (8-1)) & 0x02;
140 ov |= (rows >> (9-6)) & 0x40;
141 out_idx(ov, crtc, 0x07);
142}
143
144
145int set_mode(u16 mode)
146{
147 int rv;
148 u16 real_mode;
149
150
151 if (mode == VIDEO_CURRENT_MODE)
152 return 0;
153 else if (mode == NORMAL_VGA)
154 mode = VIDEO_80x25;
155 else if (mode == EXTENDED_VGA)
156 mode = VIDEO_8POINT;
157
158 rv = raw_set_mode(mode, &real_mode);
159 if (rv)
160 return rv;
161
162 if (mode & VIDEO_RECALC)
163 vga_recalc_vertical();
164
165
166
167#ifndef _WAKEUP
168 boot_params.hdr.vid_mode = real_mode;
169#endif
170 return 0;
171}
172