1 // VGA bios implementation
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
10 // * remove recursion from biosfn_write_teletype()
11 // * review correctness of converted asm by comparing with RBIL
12 // * 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
15 // * verify all funcs static
17 // * convert vbe/clext code
19 #include "bregs.h" // struct bregs
20 #include "biosvar.h" // GET_BDA
21 #include "util.h" // memset
22 #include "vgatables.h" // find_vga_entry
26 #define CONFIG_CIRRUS 0
29 #define DEBUG_VGA_POST 1
30 #define DEBUG_VGA_10 3
32 #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
35 call16_vgaint(u32 eax, u32 ebx)
47 biosfn_perform_gray_scale_summing(u16 start, u16 count)
49 vgahw_screen_disable();
51 for (i = start; i < start+count; i++) {
53 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
55 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
56 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
60 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
62 vgahw_screen_enable();
66 biosfn_set_cursor_shape(u8 CH, u8 CL)
71 u16 curs = (CH << 8) + CL;
72 SET_BDA(cursor_type, curs);
74 u8 modeset_ctl = GET_BDA(modeset_ctl);
75 u16 cheight = GET_BDA(char_height);
76 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
78 CH = ((CH + 1) * cheight / 8) - 1;
80 CH = ((CL + 1) * cheight / 8) - 2;
81 CL = ((CL + 1) * cheight / 8) - 1;
83 vgahw_set_cursor_shape(CH, CL);
87 biosfn_get_cursor_shape(u8 page)
91 // FIXME should handle VGA 14/16 lines
92 return GET_BDA(cursor_type);
96 biosfn_set_cursor_pos(u8 page, u16 cursor)
98 // Should not happen...
103 SET_BDA(cursor_pos[page], cursor);
105 // Set the hardware cursor
106 u8 current = GET_BDA(video_page);
110 // Get the dimensions
111 u16 nbcols = GET_BDA(video_cols);
112 u16 nbrows = GET_BDA(video_rows) + 1;
114 u8 xcurs = cursor & 0x00ff;
115 u8 ycurs = (cursor & 0xff00) >> 8;
117 // Calculate the address knowing nbcols nbrows and page num
118 u16 address = SCREEN_IO_START(nbcols, nbrows, page) + xcurs + ycurs * nbcols;
120 vgahw_set_cursor_pos(address);
124 biosfn_get_cursor_pos(u8 page)
128 // FIXME should handle VGA 14/16 lines
129 return GET_BDA(cursor_pos[page]);
133 biosfn_set_active_page(u8 page)
139 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
143 // Get pos curs pos for the right page
144 u16 cursor = biosfn_get_cursor_pos(page);
147 if (GET_GLOBAL(vmode_g->class) == TEXT) {
148 // Get the dimensions
149 u16 nbcols = GET_BDA(video_cols);
150 u16 nbrows = GET_BDA(video_rows) + 1;
152 // Calculate the address knowing nbcols nbrows and page num
153 address = SCREEN_MEM_START(nbcols, nbrows, page);
154 SET_BDA(video_pagestart, address);
157 address = SCREEN_IO_START(nbcols, nbrows, page);
159 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
160 address = page * GET_GLOBAL(vparam_g->slength);
163 vgahw_set_active_page(address);
165 // And change the BIOS page
166 SET_BDA(video_page, page);
168 dprintf(1, "Set active page %02x address %04x\n", page, address);
170 // Display the cursor, now the page is active
171 biosfn_set_cursor_pos(page, cursor);
175 biosfn_write_teletype(u8 car, u8 page, u8 attr, u8 flag)
176 { // flag = WITH_ATTR / NO_ATTR
177 // special case if page is 0xff, use current page
179 page = GET_BDA(video_page);
182 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
186 // Get the cursor pos for the page
187 u16 cursor = biosfn_get_cursor_pos(page);
188 u8 xcurs = cursor & 0x00ff;
189 u8 ycurs = (cursor & 0xff00) >> 8;
191 // Get the dimensions
192 u16 nbrows = GET_BDA(video_rows) + 1;
193 u16 nbcols = GET_BDA(video_cols);
215 biosfn_write_teletype(' ', page, attr, flag);
216 cursor = biosfn_get_cursor_pos(page);
217 xcurs = cursor & 0x00ff;
218 ycurs = (cursor & 0xff00) >> 8;
219 } while (xcurs % 8 == 0);
223 if (flag == WITH_ATTR)
224 biosfn_write_char_attr(car, page, attr, 1);
226 biosfn_write_char_only(car, page, attr, 1);
230 // Do we need to wrap ?
231 if (xcurs == nbcols) {
235 // Do we need to scroll ?
236 if (ycurs == nbrows) {
237 if (GET_GLOBAL(vmode_g->class) == TEXT)
238 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, page,
241 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, page,
245 // Set the cursor for the page
249 biosfn_set_cursor_pos(page, cursor);
253 biosfn_write_string(u8 flag, u8 page, u8 attr, u16 count, u8 row, u8 col,
254 u16 seg, u8 *offset_far)
256 // Read curs info for the page
257 u16 oldcurs = biosfn_get_cursor_pos(page);
259 // if row=0xff special case : use current cursor position
261 col = oldcurs & 0x00ff;
262 row = (oldcurs & 0xff00) >> 8;
268 biosfn_set_cursor_pos(page, newcurs);
270 while (count-- != 0) {
271 u8 car = GET_FARVAR(seg, *offset_far);
273 if ((flag & 0x02) != 0) {
274 attr = GET_FARVAR(seg, *offset_far);
278 biosfn_write_teletype(car, page, attr, WITH_ATTR);
282 if ((flag & 0x01) == 0)
283 biosfn_set_cursor_pos(page, oldcurs);
287 set_scan_lines(u8 lines)
289 vgahw_set_scan_lines(lines);
291 biosfn_set_cursor_shape(0x06, 0x07);
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);
303 biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
305 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));
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));
321 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
322 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
326 biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
328 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));
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));
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));
351 /****************************************************************
353 ****************************************************************/
357 handle_1000(struct bregs *regs)
359 u8 noclearmem = regs->al & 0x80;
360 u8 mode = regs->al & 0x7f;
380 cirrus_set_video_mode(mode);
383 if (vbe_has_vbe_display())
384 dispi_set_enable(VBE_DISPI_DISABLED);
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);
392 // Read the bios mode set control
393 u8 modeset_ctl = GET_BDA(modeset_ctl);
395 // Then we know the number of lines
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));
402 // From which palette
403 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
404 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
406 // Always 256*3 values
407 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
409 for (i = palsize; i < 0x0100; i++) {
410 static u8 rgb[3] VAR16;
411 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
414 if ((modeset_ctl & 0x02) == 0x02)
415 biosfn_perform_gray_scale_summing(0x00, 0x100);
418 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
419 vgahw_set_mode(vparam_g);
421 if (noclearmem == 0x00)
422 clear_screen(vmode_g);
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;
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);
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());
447 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
448 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
451 if (GET_GLOBAL(vmode_g->class) == TEXT)
452 biosfn_set_cursor_shape(0x06, 0x07);
453 // Set cursor pos for page 0..7
455 for (i = 0; i < 8; i++)
456 biosfn_set_cursor_pos(i, 0x0000);
459 biosfn_set_active_page(0x00);
461 // Write the fonts in memory
462 if (GET_GLOBAL(vmode_g->class) == TEXT) {
463 call16_vgaint(0x1104, 0);
464 call16_vgaint(0x1103, 0);
466 // Set the ints 0x1F and 0x43
467 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
471 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
474 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
477 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
483 handle_1001(struct bregs *regs)
485 biosfn_set_cursor_shape(regs->ch, regs->cl);
489 handle_1002(struct bregs *regs)
491 biosfn_set_cursor_pos(regs->bh, regs->dx);
495 handle_1003(struct bregs *regs)
497 regs->cx = biosfn_get_cursor_shape(regs->bh);
498 regs->dx = biosfn_get_cursor_pos(regs->bh);
501 // Read light pen pos (unimplemented)
503 handle_1004(struct bregs *regs)
506 regs->ax = regs->bx = regs->cx = regs->dx = 0;
510 handle_1005(struct bregs *regs)
512 biosfn_set_active_page(regs->al);
516 handle_1006(struct bregs *regs)
518 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
523 handle_1007(struct bregs *regs)
525 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
526 , 0xFF, SCROLL_DOWN);
530 handle_1008(struct bregs *regs)
533 biosfn_read_char_attr(regs->bh, ®s->ax);
537 handle_1009(struct bregs *regs)
540 biosfn_write_char_attr(regs->al, regs->bh, regs->bl, regs->cx);
544 handle_100a(struct bregs *regs)
547 biosfn_write_char_only(regs->al, regs->bh, regs->bl, regs->cx);
552 handle_100b00(struct bregs *regs)
554 vgahw_set_border_color(regs->bl);
558 handle_100b01(struct bregs *regs)
560 vgahw_set_palette(regs->bl);
564 handle_100bXX(struct bregs *regs)
570 handle_100b(struct bregs *regs)
573 case 0x00: handle_100b00(regs); break;
574 case 0x01: handle_100b01(regs); break;
575 default: handle_100bXX(regs); break;
581 handle_100c(struct bregs *regs)
584 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
588 handle_100d(struct bregs *regs)
591 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, ®s->ax);
595 handle_100e(struct bregs *regs)
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);
603 handle_100f(struct bregs *regs)
605 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);
612 handle_101000(struct bregs *regs)
616 vgahw_set_single_palette_reg(regs->bl, regs->bh);
620 handle_101001(struct bregs *regs)
622 vgahw_set_overscan_border_color(regs->bh);
626 handle_101002(struct bregs *regs)
628 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
632 handle_101003(struct bregs *regs)
634 vgahw_toggle_intensity(regs->bl);
638 handle_101007(struct bregs *regs)
642 regs->bh = vgahw_get_single_palette_reg(regs->bl);
646 handle_101008(struct bregs *regs)
648 regs->bh = vgahw_get_overscan_border_color(regs);
652 handle_101009(struct bregs *regs)
654 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
658 handle_101010(struct bregs *regs)
660 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
661 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
665 handle_101012(struct bregs *regs)
667 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
671 handle_101013(struct bregs *regs)
673 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
677 handle_101015(struct bregs *regs)
680 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
687 handle_101017(struct bregs *regs)
689 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
693 handle_101018(struct bregs *regs)
695 vgahw_set_pel_mask(regs->bl);
699 handle_101019(struct bregs *regs)
701 regs->bl = vgahw_get_pel_mask();
705 handle_10101a(struct bregs *regs)
707 vgahw_read_video_dac_state(®s->bl, ®s->bh);
711 handle_10101b(struct bregs *regs)
713 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
717 handle_1010XX(struct bregs *regs)
723 handle_1010(struct bregs *regs)
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;
748 handle_101100(struct bregs *regs)
750 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
751 , regs->dx, regs->bl, regs->bh);
755 handle_101101(struct bregs *regs)
757 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
761 handle_101102(struct bregs *regs)
763 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
767 handle_101103(struct bregs *regs)
769 vgahw_set_text_block_specifier(regs->bl);
773 handle_101104(struct bregs *regs)
775 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
779 handle_101110(struct bregs *regs)
781 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
782 , regs->dx, regs->bl, regs->bh);
783 set_scan_lines(regs->bh);
787 handle_101111(struct bregs *regs)
789 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
794 handle_101112(struct bregs *regs)
796 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
801 handle_101114(struct bregs *regs)
803 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
808 handle_101130(struct bregs *regs)
812 u32 segoff = GET_IVT(0x1f).segoff;
813 regs->es = segoff >> 16;
818 u32 segoff = GET_IVT(0x43).segoff;
819 regs->es = segoff >> 16;
824 regs->es = get_global_seg();
825 regs->bp = (u32)vgafont14;
828 regs->es = get_global_seg();
829 regs->bp = (u32)vgafont8;
832 regs->es = get_global_seg();
833 regs->bp = (u32)vgafont8 + 128 * 8;
836 regs->es = get_global_seg();
837 regs->bp = (u32)vgafont14alt;
840 regs->es = get_global_seg();
841 regs->bp = (u32)vgafont16;
844 regs->es = get_global_seg();
845 regs->bp = (u32)vgafont16alt;
848 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
851 // Set byte/char of on screen font
852 regs->cx = GET_BDA(char_height) & 0xff;
854 // Set Highest char row
855 regs->dx = GET_BDA(video_rows);
859 handle_1011XX(struct bregs *regs)
865 handle_1011(struct bregs *regs)
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;
884 handle_101210(struct bregs *regs)
886 u16 crtc_addr = GET_BDA(crtc_address);
887 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
891 regs->cx = GET_BDA(video_switches) & 0x0f;
895 handle_101230(struct bregs *regs)
897 u8 mctl = GET_BDA(modeset_ctl);
898 u8 vswt = GET_BDA(video_switches);
902 mctl = (mctl & ~0x10) | 0x80;
903 vswt = (vswt & ~0x0f) | 0x08;
908 vswt = (vswt & ~0x0f) | 0x09;
912 mctl = (mctl & ~0x80) | 0x10;
913 vswt = (vswt & ~0x0f) | 0x09;
916 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
919 SET_BDA(modeset_ctl, mctl);
920 SET_BDA(video_switches, vswt);
925 handle_101231(struct bregs *regs)
927 u8 v = (regs->al & 0x01) << 3;
928 u8 mctl = GET_BDA(video_ctl) & ~0x08;
929 SET_BDA(video_ctl, mctl | v);
934 handle_101232(struct bregs *regs)
936 vgahw_enable_video_addressing(regs->al);
941 handle_101233(struct bregs *regs)
943 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
944 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
945 SET_BDA(modeset_ctl, v | v2);
950 handle_101234(struct bregs *regs)
952 u8 v = (regs->al & 0x01) ^ 0x01;
953 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
954 SET_BDA(modeset_ctl, v | v2);
959 handle_101235(struct bregs *regs)
966 handle_101236(struct bregs *regs)
973 handle_1012XX(struct bregs *regs)
979 handle_1012(struct bregs *regs)
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;
993 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
998 handle_1013(struct bregs *regs)
1001 biosfn_write_string(regs->al, regs->bh, regs->bl, regs->cx
1002 , regs->dh, regs->dl, regs->es, (void*)(regs->bp + 0));
1007 handle_101a00(struct bregs *regs)
1009 regs->bx = GET_BDA(dcc_index);
1014 handle_101a01(struct bregs *regs)
1016 SET_BDA(dcc_index, regs->bl);
1017 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1022 handle_101aXX(struct bregs *regs)
1028 handle_101a(struct bregs *regs)
1031 case 0x00: handle_101a00(regs); break;
1032 case 0x01: handle_101a01(regs); break;
1033 default: handle_101aXX(regs); break;
1039 u16 static_functionality_off;
1040 u16 static_functionality_seg;
1060 handle_101b(struct bregs *regs)
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());
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);
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);
1083 handle_101c00(struct bregs *regs)
1085 u16 flags = regs->cx;
1088 size += sizeof(struct saveVideoHardware);
1090 size += sizeof(struct saveBDAstate);
1092 size += sizeof(struct saveDACcolors);
1098 handle_101c01(struct bregs *regs)
1100 u16 flags = regs->cx;
1102 void *data = (void*)(regs->bx+0);
1104 vgahw_save_state(seg, data);
1105 data += sizeof(struct saveVideoHardware);
1108 biosfn_save_bda_state(seg, data);
1109 data += sizeof(struct saveBDAstate);
1112 vgahw_save_dac_state(seg, data);
1117 handle_101c02(struct bregs *regs)
1119 u16 flags = regs->cx;
1121 void *data = (void*)(regs->bx+0);
1123 vgahw_restore_state(seg, data);
1124 data += sizeof(struct saveVideoHardware);
1127 biosfn_restore_bda_state(seg, data);
1128 data += sizeof(struct saveBDAstate);
1131 vgahw_restore_dac_state(seg, data);
1136 handle_101cXX(struct bregs *regs)
1142 handle_101c(struct bregs *regs)
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;
1154 handle_104f00(struct bregs *regs)
1156 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1157 // XXX - OR cirrus_vesa_00h
1161 handle_104f01(struct bregs *regs)
1163 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1164 // XXX - OR cirrus_vesa_01h
1168 handle_104f02(struct bregs *regs)
1170 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1171 // XXX - OR cirrus_vesa_02h
1175 handle_104f03(struct bregs *regs)
1177 // XXX - vbe_biosfn_return_current_mode
1178 // XXX - OR cirrus_vesa_03h
1182 handle_104f04(struct bregs *regs)
1184 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1188 handle_104f05(struct bregs *regs)
1190 // XXX - vbe_biosfn_display_window_control
1191 // XXX - OR cirrus_vesa_05h
1195 handle_104f06(struct bregs *regs)
1197 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1198 // XXX - OR cirrus_vesa_06h
1202 handle_104f07(struct bregs *regs)
1204 // XXX - vbe_biosfn_set_get_display_start
1205 // XXX - OR cirrus_vesa_07h
1209 handle_104f08(struct bregs *regs)
1211 // XXX - vbe_biosfn_set_get_dac_palette_format
1215 handle_104f0a(struct bregs *regs)
1217 // XXX - vbe_biosfn_return_protected_mode_interface
1221 handle_104fXX(struct bregs *regs)
1228 handle_104f(struct bregs *regs)
1230 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
1231 handle_104fXX(regs);
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;
1252 handle_10XX(struct bregs *regs)
1257 // INT 10h Video Support Service Entry Point
1259 handle_10(struct bregs *regs)
1261 debug_enter(regs, DEBUG_VGA_10);
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;
1292 /****************************************************************
1294 ****************************************************************/
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);
1304 // Just for the first int10 find its children
1306 // the default char height
1307 SET_BDA(char_height, 0x10);
1310 SET_BDA(video_ctl, 0x60);
1312 // Set the basic screen we have
1313 SET_BDA(video_switches, 0xf9);
1315 // Set the basic modeset options
1316 SET_BDA(modeset_ctl, 0x51);
1318 // Set the default MSR
1319 SET_BDA(video_msr, 0x09);
1323 vga_post(struct bregs *regs)
1325 debug_enter(regs, DEBUG_VGA_POST);
1334 extern void entry_10(void);
1335 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
1340 // XXX - clear screen and display info
1343 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
1344 SET_VGA(video_save_pointer_table[1], get_global_seg());
1347 extern u8 _rom_header_size, _rom_header_checksum;
1348 SET_VGA(_rom_header_checksum, 0);
1349 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1350 SET_VGA(_rom_header_checksum, sum);