blob: 2fa96873143335fcd345951df1cf5b457ead1b66 [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// VGA bios implementation
2//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2001-2008 the LGPL VGABios developers Team
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8
9// TODO:
Kevin O'Connordeb9cb92009-05-25 09:06:50 -040010// * remove recursion from biosfn_write_teletype()
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040011// * review correctness of converted asm by comparing with RBIL
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040012// * refactor redundant code into sub-functions
13// * See if there is a method to the in/out stuff that can be encapsulated.
14// * remove "biosfn" prefixes
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040015// * verify all funcs static
16//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040017// * convert vbe/clext code
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018
19#include "bregs.h" // struct bregs
20#include "biosvar.h" // GET_BDA
21#include "util.h" // memset
Kevin O'Connorc0c7df62009-05-17 18:11:33 -040022#include "vgatables.h" // find_vga_entry
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040023
24// XXX
25#define CONFIG_VBE 0
26#define CONFIG_CIRRUS 0
27
28// XXX
29#define DEBUG_VGA_POST 1
30#define DEBUG_VGA_10 3
31
Kevin O'Connord113a992009-05-16 21:05:02 -040032#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040033
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040034inline void
35call16_vgaint(u32 eax, u32 ebx)
36{
37 asm volatile(
38 "int $0x10\n"
39 "cli\n"
40 "cld"
41 :
42 : "a"(eax), "b"(ebx)
43 : "cc", "memory");
44}
45
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040046static void
47biosfn_perform_gray_scale_summing(u16 start, u16 count)
48{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040049 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040050 int i;
51 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040052 u8 rgb[3];
53 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040054
55 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040056 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040057 if (intensity > 0x3f)
58 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040059
Kevin O'Connora0ecb052009-05-18 23:34:00 -040060 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040061 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040062 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040063}
64
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040065static void
66biosfn_set_cursor_shape(u8 CH, u8 CL)
67{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040068 CH &= 0x3f;
69 CL &= 0x1f;
70
Kevin O'Connordd2be772009-05-16 15:41:23 -040071 u16 curs = (CH << 8) + CL;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072 SET_BDA(cursor_type, curs);
73
Kevin O'Connordd2be772009-05-16 15:41:23 -040074 u8 modeset_ctl = GET_BDA(modeset_ctl);
75 u16 cheight = GET_BDA(char_height);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040076 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -040077 if (CL != (CH + 1))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040078 CH = ((CH + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040079 else
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080 CH = ((CL + 1) * cheight / 8) - 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040081 CL = ((CL + 1) * cheight / 8) - 1;
82 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040083 vgahw_set_cursor_shape(CH, CL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084}
85
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040086static u16
87biosfn_get_cursor_shape(u8 page)
88{
89 if (page > 7)
90 return 0;
91 // FIXME should handle VGA 14/16 lines
92 return GET_BDA(cursor_type);
93}
94
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040095static void
96biosfn_set_cursor_pos(u8 page, u16 cursor)
97{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040098 // Should not happen...
99 if (page > 7)
100 return;
101
102 // Bios cursor pos
103 SET_BDA(cursor_pos[page], cursor);
104
105 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400106 u8 current = GET_BDA(video_page);
107 if (page != current)
108 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400109
Kevin O'Connordd2be772009-05-16 15:41:23 -0400110 // Get the dimensions
111 u16 nbcols = GET_BDA(video_cols);
112 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400113
Kevin O'Connordd2be772009-05-16 15:41:23 -0400114 u8 xcurs = cursor & 0x00ff;
115 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400116
Kevin O'Connordd2be772009-05-16 15:41:23 -0400117 // Calculate the address knowing nbcols nbrows and page num
118 u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols;
119
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400120 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400121}
122
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400123u16
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400124biosfn_get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400125{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400126 if (page > 7)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400127 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400128 // FIXME should handle VGA 14/16 lines
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400129 return GET_BDA(cursor_pos[page]);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130}
131
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400132static void
133biosfn_set_active_page(u8 page)
134{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400135 if (page > 7)
136 return;
137
138 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400139 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
140 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400141 return;
142
143 // Get pos curs pos for the right page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400144 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145
Kevin O'Connordd2be772009-05-16 15:41:23 -0400146 u16 address;
Kevin O'Connor5727c292009-05-16 17:29:32 -0400147 if (GET_GLOBAL(vmode_g->class) == TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400148 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400149 u16 nbcols = GET_BDA(video_cols);
150 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400151
152 // Calculate the address knowing nbcols nbrows and page num
153 address = SCREEN_MEM_START(nbcols, nbrows, page);
154 SET_BDA(video_pagestart, address);
155
156 // Start address
157 address = SCREEN_IO_START(nbcols, nbrows, page);
158 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400159 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
160 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400161 }
162
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400163 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400164
165 // And change the BIOS page
166 SET_BDA(video_page, page);
167
Kevin O'Connora12c2152009-05-13 22:06:16 -0400168 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400169
170 // Display the cursor, now the page is active
171 biosfn_set_cursor_pos(page, cursor);
172}
173
174static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400175biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag)
176{ // flag = WITH_ATTR / NO_ATTR
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400177 // special case if page is 0xff, use current page
178 if (page == 0xff)
179 page = GET_BDA(video_page);
180
181 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400182 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
183 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400184 return;
185
186 // Get the cursor pos for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400187 u16 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400188 u8 xcurs = cursor & 0x00ff;
189 u8 ycurs = (cursor & 0xff00) >> 8;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400190
191 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400192 u16 nbrows = GET_BDA(video_rows) + 1;
193 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400194
195 switch (car) {
196 case 7:
197 //FIXME should beep
198 break;
199
200 case 8:
201 if (xcurs > 0)
202 xcurs--;
203 break;
204
205 case '\r':
206 xcurs = 0;
207 break;
208
209 case '\n':
210 ycurs++;
211 break;
212
213 case '\t':
214 do {
215 biosfn_write_teletype(' ', page, attr, flag);
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400216 cursor = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400217 xcurs = cursor & 0x00ff;
218 ycurs = (cursor & 0xff00) >> 8;
219 } while (xcurs % 8 == 0);
220 break;
221
222 default:
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400223 if (flag == WITH_ATTR)
224 biosfn_write_char_attr(car, page, attr, 1);
225 else
226 biosfn_write_char_only(car, page, attr, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400227 xcurs++;
228 }
229
230 // Do we need to wrap ?
231 if (xcurs == nbcols) {
232 xcurs = 0;
233 ycurs++;
234 }
235 // Do we need to scroll ?
236 if (ycurs == nbrows) {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400237 if (GET_GLOBAL(vmode_g->class) == TEXT)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400238 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
239 SCROLL_UP);
240 else
241 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
242 SCROLL_UP);
243 ycurs -= 1;
244 }
245 // Set the cursor for the page
246 cursor = ycurs;
247 cursor <<= 8;
248 cursor += xcurs;
249 biosfn_set_cursor_pos(page, cursor);
250}
251
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400252static void
253biosfn_write_string(u8 flag, u8 page, u8 attr, u16 count, u8 row, u8 col,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400254 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400255{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400256 // Read curs info for the page
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400257 u16 oldcurs = biosfn_get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400258
259 // if row=0xff special case : use current cursor position
260 if (row == 0xff) {
261 col = oldcurs & 0x00ff;
262 row = (oldcurs & 0xff00) >> 8;
263 }
264
Kevin O'Connordd2be772009-05-16 15:41:23 -0400265 u16 newcurs = row;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400266 newcurs <<= 8;
267 newcurs += col;
268 biosfn_set_cursor_pos(page, newcurs);
269
270 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400271 u8 car = GET_FARVAR(seg, *offset_far);
272 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400273 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400274 attr = GET_FARVAR(seg, *offset_far);
275 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400276 }
277
278 biosfn_write_teletype(car, page, attr, WITH_ATTR);
279 }
280
281 // Set back curs pos
282 if ((flag & 0x01) == 0)
283 biosfn_set_cursor_pos(page, oldcurs);
284}
285
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400286static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400287set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400288{
Kevin O'Connore7132042009-05-25 00:10:35 -0400289 vgahw_set_scan_lines(lines);
290 if (lines == 8)
291 biosfn_set_cursor_shape(0x06, 0x07);
292 else
293 biosfn_set_cursor_shape(lines - 4, lines - 3);
294 SET_BDA(char_height, lines);
295 u16 vde = vgahw_get_vde();
296 u8 rows = vde / lines;
297 SET_BDA(video_rows, rows - 1);
298 u16 cols = GET_BDA(video_cols);
299 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400300}
301
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400302static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400303biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400304{
Kevin O'Connorca668642009-05-21 23:06:08 -0400305 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
306 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
307 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
308 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
309 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
310 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
311 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
312 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
313 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
314 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
315 u16 i;
316 for (i=0; i<8; i++)
317 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
318 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
319 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
320 /* current font */
321 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
322 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400323}
324
Kevin O'Connorca668642009-05-21 23:06:08 -0400325static void
326biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400327{
Kevin O'Connorca668642009-05-21 23:06:08 -0400328 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
329 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
330 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
331 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
332 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
333 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
334 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
335 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
336 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
337 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
338 u16 i;
339 for (i = 0; i < 8; i++)
340 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
341 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
342 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
343 /* current font */
344 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
345 , GET_FARVAR(seg, info->font0_off));
346 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
347 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400348}
349
350
351/****************************************************************
352 * VGA int 10 handler
353 ****************************************************************/
354
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400355// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400356static void
357handle_1000(struct bregs *regs)
358{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400359 u8 noclearmem = regs->al & 0x80;
360 u8 mode = regs->al & 0x7f;
361
362 switch(mode) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400363 case 6:
364 regs->al = 0x3F;
365 break;
366 case 0:
367 case 1:
368 case 2:
369 case 3:
370 case 4:
371 case 5:
372 case 7:
373 regs->al = 0x30;
374 break;
375 default:
376 regs->al = 0x20;
377 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400378
379 if (CONFIG_CIRRUS)
380 cirrus_set_video_mode(mode);
381
382 if (CONFIG_VBE)
383 if (vbe_has_vbe_display())
384 dispi_set_enable(VBE_DISPI_DISABLED);
385
386 // find the entry in the video modes
387 struct vgamode_s *vmode_g = find_vga_entry(mode);
388 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
389 if (!vmode_g)
390 return;
391
392 // Read the bios mode set control
393 u8 modeset_ctl = GET_BDA(modeset_ctl);
394
395 // Then we know the number of lines
396// FIXME
397
398 // if palette loading (bit 3 of modeset ctl = 0)
399 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
400 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
401
402 // From which palette
403 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
404 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
405
406 // Always 256*3 values
407 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
408 u16 i;
409 for (i = palsize; i < 0x0100; i++) {
410 static u8 rgb[3] VAR16;
411 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
412 }
413
414 if ((modeset_ctl & 0x02) == 0x02)
415 biosfn_perform_gray_scale_summing(0x00, 0x100);
416 }
417
418 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
419 vgahw_set_mode(vparam_g);
420
421 if (noclearmem == 0x00)
422 clear_screen(vmode_g);
423
424 // Set CRTC address VGA or MDA
425 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
426 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
427 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
428
429 // Set the BIOS mem
430 u16 cheight = GET_GLOBAL(vparam_g->cheight);
431 SET_BDA(video_mode, mode);
432 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
433 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
434 SET_BDA(crtc_address, crtc_addr);
435 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
436 SET_BDA(char_height, cheight);
437 SET_BDA(video_ctl, (0x60 | noclearmem));
438 SET_BDA(video_switches, 0xF9);
439 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
440
441 // FIXME We nearly have the good tables. to be reworked
442 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
443 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
444 SET_BDA(video_savetable_seg, get_global_seg());
445
446 // FIXME
447 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
448 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
449
450 // Set cursor shape
451 if (GET_GLOBAL(vmode_g->class) == TEXT)
452 biosfn_set_cursor_shape(0x06, 0x07);
453 // Set cursor pos for page 0..7
454 int i;
455 for (i = 0; i < 8; i++)
456 biosfn_set_cursor_pos(i, 0x0000);
457
458 // Set active page 0
459 biosfn_set_active_page(0x00);
460
461 // Write the fonts in memory
462 if (GET_GLOBAL(vmode_g->class) == TEXT) {
463 call16_vgaint(0x1104, 0);
464 call16_vgaint(0x1103, 0);
465 }
466 // Set the ints 0x1F and 0x43
467 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
468
469 switch (cheight) {
470 case 8:
471 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
472 break;
473 case 14:
474 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
475 break;
476 case 16:
477 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
478 break;
479 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400480}
481
482static void
483handle_1001(struct bregs *regs)
484{
485 biosfn_set_cursor_shape(regs->ch, regs->cl);
486}
487
488static void
489handle_1002(struct bregs *regs)
490{
491 biosfn_set_cursor_pos(regs->bh, regs->dx);
492}
493
494static void
495handle_1003(struct bregs *regs)
496{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400497 regs->cx = biosfn_get_cursor_shape(regs->bh);
498 regs->dx = biosfn_get_cursor_pos(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400499}
500
501// Read light pen pos (unimplemented)
502static void
503handle_1004(struct bregs *regs)
504{
505 debug_stub(regs);
506 regs->ax = regs->bx = regs->cx = regs->dx = 0;
507}
508
509static void
510handle_1005(struct bregs *regs)
511{
512 biosfn_set_active_page(regs->al);
513}
514
515static void
516handle_1006(struct bregs *regs)
517{
518 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
519 , 0xFF, SCROLL_UP);
520}
521
522static void
523handle_1007(struct bregs *regs)
524{
525 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
526 , 0xFF, SCROLL_DOWN);
527}
528
529static void
530handle_1008(struct bregs *regs)
531{
532 // XXX - inline
533 biosfn_read_char_attr(regs->bh, &regs->ax);
534}
535
536static void
537handle_1009(struct bregs *regs)
538{
539 // XXX - inline
540 biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx);
541}
542
543static void
544handle_100a(struct bregs *regs)
545{
546 // XXX - inline
547 biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx);
548}
549
550
551static void
552handle_100b00(struct bregs *regs)
553{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400554 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400555}
556
557static void
558handle_100b01(struct bregs *regs)
559{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400560 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400561}
562
563static void
564handle_100bXX(struct bregs *regs)
565{
566 debug_stub(regs);
567}
568
569static void
570handle_100b(struct bregs *regs)
571{
572 switch (regs->bh) {
573 case 0x00: handle_100b00(regs); break;
574 case 0x01: handle_100b01(regs); break;
575 default: handle_100bXX(regs); break;
576 }
577}
578
579
580static void
581handle_100c(struct bregs *regs)
582{
583 // XXX - inline
584 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
585}
586
587static void
588handle_100d(struct bregs *regs)
589{
590 // XXX - inline
591 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
592}
593
594static void
595handle_100e(struct bregs *regs)
596{
597 // Ralf Brown Interrupt list is WRONG on bh(page)
598 // We do output only on the current page !
599 biosfn_write_teletype(regs->al, 0xff, regs->bl, NO_ATTR);
600}
601
602static void
603handle_100f(struct bregs *regs)
604{
Kevin O'Connore7132042009-05-25 00:10:35 -0400605 regs->bh = GET_BDA(video_page);
606 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
607 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400608}
609
610
611static void
612handle_101000(struct bregs *regs)
613{
614 if (regs->bl > 0x14)
615 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400616 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400617}
618
619static void
620handle_101001(struct bregs *regs)
621{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400622 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400623}
624
625static void
626handle_101002(struct bregs *regs)
627{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400628 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400629}
630
631static void
632handle_101003(struct bregs *regs)
633{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400634 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635}
636
637static void
638handle_101007(struct bregs *regs)
639{
640 if (regs->bl > 0x14)
641 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400642 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400643}
644
645static void
646handle_101008(struct bregs *regs)
647{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400648 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400649}
650
651static void
652handle_101009(struct bregs *regs)
653{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400654 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400655}
656
657static void
658handle_101010(struct bregs *regs)
659{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400660 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
661 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400662}
663
664static void
665handle_101012(struct bregs *regs)
666{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400667 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400668}
669
670static void
671handle_101013(struct bregs *regs)
672{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400673 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400674}
675
676static void
677handle_101015(struct bregs *regs)
678{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400679 u8 rgb[3];
680 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
681 regs->dh = rgb[0];
682 regs->ch = rgb[1];
683 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400684}
685
686static void
687handle_101017(struct bregs *regs)
688{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400689 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400690}
691
692static void
693handle_101018(struct bregs *regs)
694{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400695 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400696}
697
698static void
699handle_101019(struct bregs *regs)
700{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400701 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400702}
703
704static void
705handle_10101a(struct bregs *regs)
706{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400707 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400708}
709
710static void
711handle_10101b(struct bregs *regs)
712{
713 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
714}
715
716static void
717handle_1010XX(struct bregs *regs)
718{
719 debug_stub(regs);
720}
721
722static void
723handle_1010(struct bregs *regs)
724{
725 switch (regs->al) {
726 case 0x00: handle_101000(regs); break;
727 case 0x01: handle_101001(regs); break;
728 case 0x02: handle_101002(regs); break;
729 case 0x03: handle_101003(regs); break;
730 case 0x07: handle_101007(regs); break;
731 case 0x08: handle_101008(regs); break;
732 case 0x09: handle_101009(regs); break;
733 case 0x10: handle_101010(regs); break;
734 case 0x12: handle_101012(regs); break;
735 case 0x13: handle_101013(regs); break;
736 case 0x15: handle_101015(regs); break;
737 case 0x17: handle_101017(regs); break;
738 case 0x18: handle_101018(regs); break;
739 case 0x19: handle_101019(regs); break;
740 case 0x1a: handle_10101a(regs); break;
741 case 0x1b: handle_10101b(regs); break;
742 default: handle_1010XX(regs); break;
743 }
744}
745
746
747static void
748handle_101100(struct bregs *regs)
749{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400750 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
751 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400752}
753
754static void
755handle_101101(struct bregs *regs)
756{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400757 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400758}
759
760static void
761handle_101102(struct bregs *regs)
762{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400763 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400764}
765
766static void
767handle_101103(struct bregs *regs)
768{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400769 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400770}
771
772static void
773handle_101104(struct bregs *regs)
774{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400775 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400776}
777
778static void
779handle_101110(struct bregs *regs)
780{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400781 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
782 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400783 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400784}
785
786static void
787handle_101111(struct bregs *regs)
788{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400789 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400790 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400791}
792
793static void
794handle_101112(struct bregs *regs)
795{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400796 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400797 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400798}
799
800static void
801handle_101114(struct bregs *regs)
802{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400803 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400804 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400805}
806
807static void
808handle_101130(struct bregs *regs)
809{
Kevin O'Connore7132042009-05-25 00:10:35 -0400810 switch (regs->bh) {
811 case 0x00: {
812 u32 segoff = GET_IVT(0x1f).segoff;
813 regs->es = segoff >> 16;
814 regs->bp = segoff;
815 break;
816 }
817 case 0x01: {
818 u32 segoff = GET_IVT(0x43).segoff;
819 regs->es = segoff >> 16;
820 regs->bp = segoff;
821 break;
822 }
823 case 0x02:
824 regs->es = get_global_seg();
825 regs->bp = (u32)vgafont14;
826 break;
827 case 0x03:
828 regs->es = get_global_seg();
829 regs->bp = (u32)vgafont8;
830 break;
831 case 0x04:
832 regs->es = get_global_seg();
833 regs->bp = (u32)vgafont8 + 128 * 8;
834 break;
835 case 0x05:
836 regs->es = get_global_seg();
837 regs->bp = (u32)vgafont14alt;
838 break;
839 case 0x06:
840 regs->es = get_global_seg();
841 regs->bp = (u32)vgafont16;
842 break;
843 case 0x07:
844 regs->es = get_global_seg();
845 regs->bp = (u32)vgafont16alt;
846 break;
847 default:
848 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
849 return;
850 }
851 // Set byte/char of on screen font
852 regs->cx = GET_BDA(char_height) & 0xff;
853
854 // Set Highest char row
855 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400856}
857
858static void
859handle_1011XX(struct bregs *regs)
860{
861 debug_stub(regs);
862}
863
864static void
865handle_1011(struct bregs *regs)
866{
867 switch (regs->al) {
868 case 0x00: handle_101100(regs); break;
869 case 0x01: handle_101101(regs); break;
870 case 0x02: handle_101102(regs); break;
871 case 0x03: handle_101103(regs); break;
872 case 0x04: handle_101104(regs); break;
873 case 0x10: handle_101110(regs); break;
874 case 0x11: handle_101111(regs); break;
875 case 0x12: handle_101112(regs); break;
876 case 0x14: handle_101114(regs); break;
877 case 0x30: handle_101130(regs); break;
878 default: handle_1011XX(regs); break;
879 }
880}
881
882
883static void
884handle_101210(struct bregs *regs)
885{
Kevin O'Connore7132042009-05-25 00:10:35 -0400886 u16 crtc_addr = GET_BDA(crtc_address);
887 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
888 regs->bx = 0x0103;
889 else
890 regs->bx = 0x0003;
891 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400892}
893
894static void
895handle_101230(struct bregs *regs)
896{
Kevin O'Connore7132042009-05-25 00:10:35 -0400897 u8 mctl = GET_BDA(modeset_ctl);
898 u8 vswt = GET_BDA(video_switches);
899 switch (regs->al) {
900 case 0x00:
901 // 200 lines
902 mctl = (mctl & ~0x10) | 0x80;
903 vswt = (vswt & ~0x0f) | 0x08;
904 break;
905 case 0x01:
906 // 350 lines
907 mctl &= ~0x90;
908 vswt = (vswt & ~0x0f) | 0x09;
909 break;
910 case 0x02:
911 // 400 lines
912 mctl = (mctl & ~0x80) | 0x10;
913 vswt = (vswt & ~0x0f) | 0x09;
914 break;
915 default:
916 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
917 break;
918 }
919 SET_BDA(modeset_ctl, mctl);
920 SET_BDA(video_switches, vswt);
921 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400922}
923
924static void
925handle_101231(struct bregs *regs)
926{
Kevin O'Connore7132042009-05-25 00:10:35 -0400927 u8 v = (regs->al & 0x01) << 3;
928 u8 mctl = GET_BDA(video_ctl) & ~0x08;
929 SET_BDA(video_ctl, mctl | v);
930 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400931}
932
933static void
934handle_101232(struct bregs *regs)
935{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400936 vgahw_enable_video_addressing(regs->al);
937 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400938}
939
940static void
941handle_101233(struct bregs *regs)
942{
Kevin O'Connore7132042009-05-25 00:10:35 -0400943 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
944 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
945 SET_BDA(modeset_ctl, v | v2);
946 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400947}
948
949static void
950handle_101234(struct bregs *regs)
951{
Kevin O'Connore7132042009-05-25 00:10:35 -0400952 u8 v = (regs->al & 0x01) ^ 0x01;
953 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
954 SET_BDA(modeset_ctl, v | v2);
955 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400956}
957
958static void
959handle_101235(struct bregs *regs)
960{
961 debug_stub(regs);
962 regs->al = 0x12;
963}
964
965static void
966handle_101236(struct bregs *regs)
967{
968 debug_stub(regs);
969 regs->al = 0x12;
970}
971
972static void
973handle_1012XX(struct bregs *regs)
974{
975 debug_stub(regs);
976}
977
978static void
979handle_1012(struct bregs *regs)
980{
981 switch (regs->bl) {
982 case 0x10: handle_101210(regs); break;
983 case 0x30: handle_101230(regs); break;
984 case 0x31: handle_101231(regs); break;
985 case 0x32: handle_101232(regs); break;
986 case 0x33: handle_101233(regs); break;
987 case 0x34: handle_101234(regs); break;
988 case 0x35: handle_101235(regs); break;
989 case 0x36: handle_101236(regs); break;
990 default: handle_1012XX(regs); break;
991 }
992
993 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
994}
995
996
997static void
998handle_1013(struct bregs *regs)
999{
1000 // XXX - inline
1001 biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001002 , regs->dh, regs->dl, regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001003}
1004
1005
1006static void
1007handle_101a00(struct bregs *regs)
1008{
Kevin O'Connore7132042009-05-25 00:10:35 -04001009 regs->bx = GET_BDA(dcc_index);
1010 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001011}
1012
1013static void
1014handle_101a01(struct bregs *regs)
1015{
Kevin O'Connore7132042009-05-25 00:10:35 -04001016 SET_BDA(dcc_index, regs->bl);
1017 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1018 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001019}
1020
1021static void
1022handle_101aXX(struct bregs *regs)
1023{
1024 debug_stub(regs);
1025}
1026
1027static void
1028handle_101a(struct bregs *regs)
1029{
1030 switch (regs->al) {
1031 case 0x00: handle_101a00(regs); break;
1032 case 0x01: handle_101a01(regs); break;
1033 default: handle_101aXX(regs); break;
1034 }
1035}
1036
1037
Kevin O'Connorca668642009-05-21 23:06:08 -04001038struct funcInfo {
1039 u16 static_functionality_off;
1040 u16 static_functionality_seg;
1041 u8 bda_0x49[30];
1042 u8 bda_0x84[3];
1043 u8 dcc_index;
1044 u8 dcc_alt;
1045 u16 colors;
1046 u8 pages;
1047 u8 scan_lines;
1048 u8 primary_char;
1049 u8 secondar_char;
1050 u8 misc;
1051 u8 non_vga_mode;
1052 u8 reserved_2f[2];
1053 u8 video_mem;
1054 u8 save_flags;
1055 u8 disp_info;
1056 u8 reserved_34[12];
1057};
1058
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001059static void
1060handle_101b(struct bregs *regs)
1061{
Kevin O'Connorca668642009-05-21 23:06:08 -04001062 u16 seg = regs->es;
1063 struct funcInfo *info = (void*)(regs->di+0);
1064 memset_far(seg, info, 0, sizeof(*info));
1065 // Address of static functionality table
1066 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1067 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1068
1069 // Hard coded copy from BIOS area. Should it be cleaner ?
1070 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1071 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1072
1073 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1074 SET_FARVAR(seg, info->colors, 16);
1075 SET_FARVAR(seg, info->pages, 8);
1076 SET_FARVAR(seg, info->scan_lines, 2);
1077 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001078 regs->al = 0x1B;
1079}
1080
1081
1082static void
1083handle_101c00(struct bregs *regs)
1084{
Kevin O'Connorca668642009-05-21 23:06:08 -04001085 u16 flags = regs->cx;
1086 u16 size = 0;
1087 if (flags & 1)
1088 size += sizeof(struct saveVideoHardware);
1089 if (flags & 2)
1090 size += sizeof(struct saveBDAstate);
1091 if (flags & 4)
1092 size += sizeof(struct saveDACcolors);
1093 regs->bx = size;
1094 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001095}
1096
1097static void
1098handle_101c01(struct bregs *regs)
1099{
Kevin O'Connorca668642009-05-21 23:06:08 -04001100 u16 flags = regs->cx;
1101 u16 seg = regs->es;
1102 void *data = (void*)(regs->bx+0);
1103 if (flags & 1) {
1104 vgahw_save_state(seg, data);
1105 data += sizeof(struct saveVideoHardware);
1106 }
1107 if (flags & 2) {
1108 biosfn_save_bda_state(seg, data);
1109 data += sizeof(struct saveBDAstate);
1110 }
1111 if (flags & 4)
1112 vgahw_save_dac_state(seg, data);
1113 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001114}
1115
1116static void
1117handle_101c02(struct bregs *regs)
1118{
Kevin O'Connorca668642009-05-21 23:06:08 -04001119 u16 flags = regs->cx;
1120 u16 seg = regs->es;
1121 void *data = (void*)(regs->bx+0);
1122 if (flags & 1) {
1123 vgahw_restore_state(seg, data);
1124 data += sizeof(struct saveVideoHardware);
1125 }
1126 if (flags & 2) {
1127 biosfn_restore_bda_state(seg, data);
1128 data += sizeof(struct saveBDAstate);
1129 }
1130 if (flags & 4)
1131 vgahw_restore_dac_state(seg, data);
1132 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001133}
1134
1135static void
1136handle_101cXX(struct bregs *regs)
1137{
1138 debug_stub(regs);
1139}
1140
1141static void
1142handle_101c(struct bregs *regs)
1143{
1144 switch (regs->al) {
1145 case 0x00: handle_101c00(regs); break;
1146 case 0x01: handle_101c01(regs); break;
1147 case 0x02: handle_101c02(regs); break;
1148 default: handle_101cXX(regs); break;
1149 }
1150}
1151
1152
1153static void
1154handle_104f00(struct bregs *regs)
1155{
1156 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1157 // XXX - OR cirrus_vesa_00h
1158}
1159
1160static void
1161handle_104f01(struct bregs *regs)
1162{
1163 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1164 // XXX - OR cirrus_vesa_01h
1165}
1166
1167static void
1168handle_104f02(struct bregs *regs)
1169{
1170 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1171 // XXX - OR cirrus_vesa_02h
1172}
1173
1174static void
1175handle_104f03(struct bregs *regs)
1176{
1177 // XXX - vbe_biosfn_return_current_mode
1178 // XXX - OR cirrus_vesa_03h
1179}
1180
1181static void
1182handle_104f04(struct bregs *regs)
1183{
1184 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1185}
1186
1187static void
1188handle_104f05(struct bregs *regs)
1189{
1190 // XXX - vbe_biosfn_display_window_control
1191 // XXX - OR cirrus_vesa_05h
1192}
1193
1194static void
1195handle_104f06(struct bregs *regs)
1196{
1197 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1198 // XXX - OR cirrus_vesa_06h
1199}
1200
1201static void
1202handle_104f07(struct bregs *regs)
1203{
1204 // XXX - vbe_biosfn_set_get_display_start
1205 // XXX - OR cirrus_vesa_07h
1206}
1207
1208static void
1209handle_104f08(struct bregs *regs)
1210{
1211 // XXX - vbe_biosfn_set_get_dac_palette_format
1212}
1213
1214static void
1215handle_104f0a(struct bregs *regs)
1216{
1217 // XXX - vbe_biosfn_return_protected_mode_interface
1218}
1219
1220static void
1221handle_104fXX(struct bregs *regs)
1222{
1223 debug_stub(regs);
1224 regs->ax = 0x0100;
1225}
1226
1227static void
1228handle_104f(struct bregs *regs)
1229{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001230 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001231 handle_104fXX(regs);
1232 return;
1233 }
1234
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001235 switch (regs->al) {
1236 case 0x00: handle_104f00(regs); break;
1237 case 0x01: handle_104f01(regs); break;
1238 case 0x02: handle_104f02(regs); break;
1239 case 0x03: handle_104f03(regs); break;
1240 case 0x04: handle_104f04(regs); break;
1241 case 0x05: handle_104f05(regs); break;
1242 case 0x06: handle_104f06(regs); break;
1243 case 0x07: handle_104f07(regs); break;
1244 case 0x08: handle_104f08(regs); break;
1245 case 0x0a: handle_104f0a(regs); break;
1246 default: handle_104fXX(regs); break;
1247 }
1248}
1249
1250
1251static void
1252handle_10XX(struct bregs *regs)
1253{
1254 debug_stub(regs);
1255}
1256
1257// INT 10h Video Support Service Entry Point
1258void VISIBLE16
1259handle_10(struct bregs *regs)
1260{
1261 debug_enter(regs, DEBUG_VGA_10);
1262 switch (regs->ah) {
1263 case 0x00: handle_1000(regs); break;
1264 case 0x01: handle_1001(regs); break;
1265 case 0x02: handle_1002(regs); break;
1266 case 0x03: handle_1003(regs); break;
1267 case 0x04: handle_1004(regs); break;
1268 case 0x05: handle_1005(regs); break;
1269 case 0x06: handle_1006(regs); break;
1270 case 0x07: handle_1007(regs); break;
1271 case 0x08: handle_1008(regs); break;
1272 case 0x09: handle_1009(regs); break;
1273 case 0x0a: handle_100a(regs); break;
1274 case 0x0b: handle_100b(regs); break;
1275 case 0x0c: handle_100c(regs); break;
1276 case 0x0d: handle_100d(regs); break;
1277 case 0x0e: handle_100e(regs); break;
1278 case 0x0f: handle_100f(regs); break;
1279 case 0x10: handle_1010(regs); break;
1280 case 0x11: handle_1011(regs); break;
1281 case 0x12: handle_1012(regs); break;
1282 case 0x13: handle_1013(regs); break;
1283 case 0x1a: handle_101a(regs); break;
1284 case 0x1b: handle_101b(regs); break;
1285 case 0x1c: handle_101c(regs); break;
1286 case 0x4f: handle_104f(regs); break;
1287 default: handle_10XX(regs); break;
1288 }
1289}
1290
1291
1292/****************************************************************
1293 * VGA post
1294 ****************************************************************/
1295
1296static void
1297init_bios_area()
1298{
1299 // init detected hardware BIOS Area
1300 // set 80x25 color (not clear from RBIL but usual)
1301 u16 eqf = GET_BDA(equipment_list_flags);
1302 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1303
1304 // Just for the first int10 find its children
1305
1306 // the default char height
1307 SET_BDA(char_height, 0x10);
1308
1309 // Clear the screen
1310 SET_BDA(video_ctl, 0x60);
1311
1312 // Set the basic screen we have
1313 SET_BDA(video_switches, 0xf9);
1314
1315 // Set the basic modeset options
1316 SET_BDA(modeset_ctl, 0x51);
1317
1318 // Set the default MSR
1319 SET_BDA(video_msr, 0x09);
1320}
1321
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001322void VISIBLE16
1323vga_post(struct bregs *regs)
1324{
1325 debug_enter(regs, DEBUG_VGA_POST);
1326
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001327 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001328
1329 init_bios_area();
1330
Kevin O'Connor21079f42009-05-16 21:30:10 -04001331 if (CONFIG_VBE)
1332 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001333
1334 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001335 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001336
1337 if (CONFIG_CIRRUS)
1338 cirrus_init();
1339
1340 // XXX - clear screen and display info
1341
1342 // XXX: fill it
1343 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001344 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001345
1346 // Fixup checksum
1347 extern u8 _rom_header_size, _rom_header_checksum;
1348 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001349 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001350 SET_VGA(_rom_header_checksum, sum);
1351}