1 // VGA bios implementation
3 // Copyright (C) 2009-2013 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.
8 #include "biosvar.h" // GET_BDA
9 #include "bregs.h" // struct bregs
10 #include "clext.h" // clext_1012
11 #include "config.h" // CONFIG_*
12 #include "output.h" // dprintf
13 #include "std/vbe.h" // VBE_RETURN_STATUS_FAILED
14 #include "stdvga.h" // stdvga_set_cursor_shape
15 #include "string.h" // memset_far
16 #include "vgabios.h" // calc_page_size
17 #include "vgahw.h" // vgahw_set_mode
20 /****************************************************************
22 ****************************************************************/
24 // Return the bits per pixel in system memory for a given mode.
26 vga_bpp(struct vgamode_s *vmode_g)
28 switch (GET_GLOBAL(vmode_g->memmodel)) {
34 u8 depth = GET_GLOBAL(vmode_g->depth);
36 return ALIGN(depth, 8);
41 calc_page_size(u8 memmodel, u16 width, u16 height)
45 return ALIGN(width * height * 2, 2*1024);
49 return ALIGN(width * height / 8, 8*1024);
53 // Determine cursor shape (taking into account possible cursor scaling)
55 get_cursor_shape(void)
57 u16 cursor_type = GET_BDA(cursor_type);
58 u8 emulate_cursor = (GET_BDA(video_ctl) & 1) == 0;
61 u8 start = (cursor_type >> 8) & 0x3f;
62 u8 end = cursor_type & 0x1f;
63 u16 cheight = GET_BDA(char_height);
64 if (cheight <= 8 || end >= 8 || start >= 0x20)
66 if (end != (start + 1))
67 start = ((start + 1) * cheight / 8) - 1;
69 start = ((end + 1) * cheight / 8) - 2;
70 end = ((end + 1) * cheight / 8) - 1;
71 return (start << 8) | end;
75 set_cursor_shape(u16 cursor_type)
77 vgafb_set_swcursor(0);
78 SET_BDA(cursor_type, cursor_type);
79 if (CONFIG_VGA_STDVGA_PORTS)
80 stdvga_set_cursor_shape(get_cursor_shape());
84 set_cursor_pos(struct cursorpos cp)
86 u8 page = cp.page, x = cp.x, y = cp.y;
88 // Should not happen...
92 vgafb_set_swcursor(0);
95 SET_BDA(cursor_pos[page], (y << 8) | x);
97 if (!CONFIG_VGA_STDVGA_PORTS)
100 // Set the hardware cursor
101 u8 current = GET_BDA(video_page);
102 if (cp.page != current)
105 // Calculate the memory address
106 stdvga_set_cursor_pos((int)text_address(cp));
110 get_cursor_pos(u8 page)
113 // special case - use current page
114 page = GET_BDA(video_page);
116 struct cursorpos cp = { 0, 0, 0xfe };
119 u16 xy = GET_BDA(cursor_pos[page]);
120 struct cursorpos cp = {xy, xy>>8, page};
125 set_active_page(u8 page)
131 struct vgamode_s *vmode_g = get_current_mode();
135 vgafb_set_swcursor(0);
137 // Calculate memory address of start of page
138 struct cursorpos cp = {0, 0, page};
139 int address = (int)text_address(cp);
140 vgahw_set_displaystart(vmode_g, address);
142 // And change the BIOS page
143 SET_BDA(video_pagestart, address);
144 SET_BDA(video_page, page);
146 dprintf(1, "Set active page %02x address %04x\n", page, address);
148 // Display the cursor, now the page is active
149 set_cursor_pos(get_cursor_pos(page));
153 set_scan_lines(u8 lines)
155 stdvga_set_scan_lines(lines);
156 SET_BDA(char_height, lines);
157 u16 vde = stdvga_get_vde();
158 u8 rows = vde / lines;
159 SET_BDA(video_rows, rows - 1);
160 u16 cols = GET_BDA(video_cols);
161 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
163 set_cursor_shape(0x0607);
165 set_cursor_shape(((lines - 3) << 8) | (lines - 2));
169 /****************************************************************
171 ****************************************************************/
173 // Write a character to the screen and calculate new cursor position.
175 write_char(struct cursorpos *pcp, struct carattr ca)
177 vgafb_write_char(*pcp, ca);
179 // Do we need to wrap ?
180 if (pcp->x == GET_BDA(video_cols)) {
186 // Write a character to the screen at a given position. Implement
187 // special characters and scroll the screen if necessary.
189 write_teletype(struct cursorpos *pcp, struct carattr ca)
210 // Do we need to scroll ?
211 u16 nbrows = GET_BDA(video_rows);
212 if (pcp->y > nbrows) {
215 struct cursorpos dest = {0, 0, pcp->page};
216 struct cursorpos src = {0, 1, pcp->page};
217 struct cursorpos size = {GET_BDA(video_cols), nbrows};
218 vgafb_move_chars(dest, src, size);
220 struct cursorpos clr = {0, nbrows, pcp->page};
221 struct carattr attr = {' ', 0, 0};
222 struct cursorpos clrsize = {GET_BDA(video_cols), 1};
223 vgafb_clear_chars(clr, attr, clrsize);
228 /****************************************************************
229 * Save and restore bda state
230 ****************************************************************/
232 struct saveBDAstate {
236 struct segoff_s font0;
237 struct segoff_s font1;
241 bda_save_restore(int cmd, u16 seg, void *data)
245 struct saveBDAstate *info = data;
247 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
248 , sizeof(info->bda_0x49));
249 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
250 , sizeof(info->bda_0x84));
251 SET_FARVAR(seg, info->vbe_mode, GET_BDA_EXT(vbe_mode));
252 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
253 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
255 if (cmd & SR_RESTORE) {
256 memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49
257 , sizeof(info->bda_0x49));
258 memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
259 , sizeof(info->bda_0x84));
260 u16 vbe_mode = GET_FARVAR(seg, info->vbe_mode);
261 SET_BDA_EXT(vbe_mode, vbe_mode);
262 struct vgamode_s *vmode_g = vgahw_find_mode(vbe_mode & ~MF_VBEFLAGS);
263 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
264 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
265 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
267 return sizeof(*info);
271 /****************************************************************
273 ****************************************************************/
276 get_current_mode(void)
278 return (void*)(GET_BDA_EXT(vgamode_offset)+0);
281 // Setup BDA after a mode switch.
283 vga_set_mode(int mode, int flags)
285 dprintf(1, "set VGA mode %x\n", mode);
286 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
288 return VBE_RETURN_STATUS_FAILED;
290 vgafb_set_swcursor(0);
292 int ret = vgahw_set_mode(vmode_g, flags);
297 int width = GET_GLOBAL(vmode_g->width);
298 int height = GET_GLOBAL(vmode_g->height);
299 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
300 int cheight = GET_GLOBAL(vmode_g->cheight);
302 SET_BDA(video_mode, mode);
304 SET_BDA(video_mode, 0xff);
305 SET_BDA_EXT(vbe_mode, mode | (flags & MF_VBEFLAGS));
306 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
307 if (CONFIG_VGA_ALLOCATE_EXTRA_STACK)
308 // Disable extra stack if it appears a modern OS is in use.
309 // This works around bugs in some versions of Windows (Vista
310 // and possibly later) when the stack is in the e-segment.
311 MASK_BDA_EXT(flags, BF_EXTRA_STACK
312 , (flags & MF_LEGACY) ? BF_EXTRA_STACK : 0);
313 if (memmodel == MM_TEXT) {
314 SET_BDA(video_cols, width);
315 SET_BDA(video_rows, height-1);
316 SET_BDA(cursor_type, 0x0607);
318 int cwidth = GET_GLOBAL(vmode_g->cwidth);
319 SET_BDA(video_cols, width / cwidth);
320 SET_BDA(video_rows, (height / cheight) - 1);
321 SET_BDA(cursor_type, vga_emulate_text() ? 0x0607 : 0x0000);
323 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
324 SET_BDA(crtc_address, CONFIG_VGA_STDVGA_PORTS ? stdvga_get_crtc() : 0);
325 SET_BDA(char_height, cheight);
326 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
327 SET_BDA(video_switches, 0xF9);
328 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
331 SET_BDA(cursor_pos[i], 0x0000);
332 SET_BDA(video_pagestart, 0x0000);
333 SET_BDA(video_page, 0x00);
335 // Set the ints 0x1F and 0x43
336 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
340 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
343 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
346 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
354 /****************************************************************
356 ****************************************************************/
359 handle_1000(struct bregs *regs)
361 int mode = regs->al & 0x7f;
371 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
373 flags |= MF_NOCLEARMEM;
375 vga_set_mode(mode, flags);
379 handle_1001(struct bregs *regs)
381 set_cursor_shape(regs->cx);
385 handle_1002(struct bregs *regs)
387 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
392 handle_1003(struct bregs *regs)
394 regs->cx = GET_BDA(cursor_type);
395 struct cursorpos cp = get_cursor_pos(regs->bh);
400 // Read light pen pos (unimplemented)
402 handle_1004(struct bregs *regs)
405 regs->ax = regs->bx = regs->cx = regs->dx = 0;
409 handle_1005(struct bregs *regs)
411 set_active_page(regs->al);
415 verify_scroll(struct bregs *regs, int dir)
417 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
418 u16 nbrows = GET_BDA(video_rows) + 1;
421 u16 nbcols = GET_BDA(video_cols);
424 int wincols = lrx - ulx + 1, winrows = lry - uly + 1;
425 if (wincols <= 0 || winrows <= 0)
428 u8 page = GET_BDA(video_page);
429 int clearlines = regs->al, movelines = winrows - clearlines;
430 if (!clearlines || movelines <= 0) {
432 struct cursorpos clr = {ulx, uly, page};
433 struct carattr attr = {' ', regs->bh, 1};
434 struct cursorpos clrsize = {wincols, winrows};
435 vgafb_clear_chars(clr, attr, clrsize);
441 struct cursorpos dest = {ulx, uly, page};
442 struct cursorpos src = {ulx, uly + clearlines, page};
443 struct cursorpos size = {wincols, movelines};
444 vgafb_move_chars(dest, src, size);
446 struct cursorpos clr = {ulx, uly + movelines, page};
447 struct carattr attr = {' ', regs->bh, 1};
448 struct cursorpos clrsize = {wincols, clearlines};
449 vgafb_clear_chars(clr, attr, clrsize);
452 struct cursorpos dest = {ulx, uly + clearlines, page};
453 struct cursorpos src = {ulx, uly, page};
454 struct cursorpos size = {wincols, movelines};
455 vgafb_move_chars(dest, src, size);
457 struct cursorpos clr = {ulx, uly, page};
458 struct carattr attr = {' ', regs->bh, 1};
459 struct cursorpos clrsize = {wincols, clearlines};
460 vgafb_clear_chars(clr, attr, clrsize);
465 handle_1006(struct bregs *regs)
467 verify_scroll(regs, 1);
471 handle_1007(struct bregs *regs)
473 verify_scroll(regs, -1);
477 handle_1008(struct bregs *regs)
479 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
485 handle_1009(struct bregs *regs)
487 struct carattr ca = {regs->al, regs->bl, 1};
488 struct cursorpos cp = get_cursor_pos(regs->bh);
489 int count = regs->cx;
495 handle_100a(struct bregs *regs)
497 struct carattr ca = {regs->al, regs->bl, 0};
498 struct cursorpos cp = get_cursor_pos(regs->bh);
499 int count = regs->cx;
506 handle_100b00(struct bregs *regs)
508 stdvga_set_border_color(regs->bl);
512 handle_100b01(struct bregs *regs)
514 stdvga_set_palette(regs->bl);
518 handle_100bXX(struct bregs *regs)
524 handle_100b(struct bregs *regs)
526 if (!CONFIG_VGA_STDVGA_PORTS) {
531 case 0x00: handle_100b00(regs); break;
532 case 0x01: handle_100b01(regs); break;
533 default: handle_100bXX(regs); break;
539 handle_100c(struct bregs *regs)
541 // XXX - page (regs->bh) is unused
542 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
546 handle_100d(struct bregs *regs)
548 // XXX - page (regs->bh) is unused
549 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
553 handle_100e(struct bregs *regs)
555 // Ralf Brown Interrupt list is WRONG on bh(page)
556 // We do output only on the current page !
557 struct carattr ca = {regs->al, regs->bl, 0};
558 struct cursorpos cp = get_cursor_pos(0xff);
559 write_teletype(&cp, ca);
564 handle_100f(struct bregs *regs)
566 regs->bh = GET_BDA(video_page);
567 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
568 regs->ah = GET_BDA(video_cols);
573 handle_101000(struct bregs *regs)
577 stdvga_attr_write(regs->bl, regs->bh);
581 handle_101001(struct bregs *regs)
583 stdvga_set_overscan_border_color(regs->bh);
587 handle_101002(struct bregs *regs)
589 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
593 handle_101003(struct bregs *regs)
595 stdvga_toggle_intensity(regs->bl);
599 handle_101007(struct bregs *regs)
603 regs->bh = stdvga_attr_read(regs->bl);
607 handle_101008(struct bregs *regs)
609 regs->bh = stdvga_get_overscan_border_color();
613 handle_101009(struct bregs *regs)
615 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
619 handle_101010(struct bregs *regs)
621 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
622 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
626 handle_101012(struct bregs *regs)
628 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
632 handle_101013(struct bregs *regs)
634 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
638 handle_101015(struct bregs *regs)
641 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
648 handle_101017(struct bregs *regs)
650 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
654 handle_101018(struct bregs *regs)
656 stdvga_pelmask_write(regs->bl);
660 handle_101019(struct bregs *regs)
662 regs->bl = stdvga_pelmask_read();
666 handle_10101a(struct bregs *regs)
668 stdvga_read_video_dac_state(®s->bl, ®s->bh);
672 handle_10101b(struct bregs *regs)
674 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
678 handle_1010XX(struct bregs *regs)
684 handle_1010(struct bregs *regs)
686 if (!CONFIG_VGA_STDVGA_PORTS) {
691 case 0x00: handle_101000(regs); break;
692 case 0x01: handle_101001(regs); break;
693 case 0x02: handle_101002(regs); break;
694 case 0x03: handle_101003(regs); break;
695 case 0x07: handle_101007(regs); break;
696 case 0x08: handle_101008(regs); break;
697 case 0x09: handle_101009(regs); break;
698 case 0x10: handle_101010(regs); break;
699 case 0x12: handle_101012(regs); break;
700 case 0x13: handle_101013(regs); break;
701 case 0x15: handle_101015(regs); break;
702 case 0x17: handle_101017(regs); break;
703 case 0x18: handle_101018(regs); break;
704 case 0x19: handle_101019(regs); break;
705 case 0x1a: handle_10101a(regs); break;
706 case 0x1b: handle_10101b(regs); break;
707 default: handle_1010XX(regs); break;
713 handle_101100(struct bregs *regs)
715 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
716 , regs->dx, regs->bl, regs->bh);
720 handle_101101(struct bregs *regs)
722 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
726 handle_101102(struct bregs *regs)
728 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
732 handle_101103(struct bregs *regs)
734 stdvga_set_text_block_specifier(regs->bl);
738 handle_101104(struct bregs *regs)
740 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
744 handle_101110(struct bregs *regs)
746 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
747 , regs->dx, regs->bl, regs->bh);
748 set_scan_lines(regs->bh);
752 handle_101111(struct bregs *regs)
754 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
759 handle_101112(struct bregs *regs)
761 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
766 handle_101114(struct bregs *regs)
768 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
773 handle_101120(struct bregs *regs)
775 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
779 load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
783 SET_IVT(0x43, SEGOFF(seg, off));
799 SET_BDA(video_rows, rows - 1);
800 SET_BDA(char_height, height);
804 handle_101121(struct bregs *regs)
806 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
810 handle_101122(struct bregs *regs)
812 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
816 handle_101123(struct bregs *regs)
818 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
822 handle_101124(struct bregs *regs)
824 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
828 handle_101130(struct bregs *regs)
832 struct segoff_s so = GET_IVT(0x1f);
834 regs->bp = so.offset;
838 struct segoff_s so = GET_IVT(0x43);
840 regs->bp = so.offset;
844 regs->es = get_global_seg();
845 regs->bp = (u32)vgafont14;
848 regs->es = get_global_seg();
849 regs->bp = (u32)vgafont8;
852 regs->es = get_global_seg();
853 regs->bp = (u32)vgafont8 + 128 * 8;
856 regs->es = get_global_seg();
857 regs->bp = (u32)vgafont14alt;
860 regs->es = get_global_seg();
861 regs->bp = (u32)vgafont16;
864 regs->es = get_global_seg();
865 regs->bp = (u32)vgafont16alt;
868 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
871 // Set byte/char of on screen font
872 regs->cx = GET_BDA(char_height) & 0xff;
874 // Set Highest char row
875 regs->dl = GET_BDA(video_rows);
879 handle_1011XX(struct bregs *regs)
885 handle_1011(struct bregs *regs)
887 if (CONFIG_VGA_STDVGA_PORTS) {
889 case 0x00: handle_101100(regs); return;
890 case 0x01: handle_101101(regs); return;
891 case 0x02: handle_101102(regs); return;
892 case 0x03: handle_101103(regs); return;
893 case 0x04: handle_101104(regs); return;
894 case 0x10: handle_101110(regs); return;
895 case 0x11: handle_101111(regs); return;
896 case 0x12: handle_101112(regs); return;
897 case 0x14: handle_101114(regs); return;
901 case 0x30: handle_101130(regs); break;
902 case 0x20: handle_101120(regs); break;
903 case 0x21: handle_101121(regs); break;
904 case 0x22: handle_101122(regs); break;
905 case 0x23: handle_101123(regs); break;
906 case 0x24: handle_101124(regs); break;
907 default: handle_1011XX(regs); break;
913 handle_101210(struct bregs *regs)
915 u16 crtc_addr = GET_BDA(crtc_address);
916 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
920 regs->cx = GET_BDA(video_switches) & 0x0f;
924 handle_101230(struct bregs *regs)
926 u8 mctl = GET_BDA(modeset_ctl);
927 u8 vswt = GET_BDA(video_switches);
931 mctl = (mctl & ~0x10) | 0x80;
932 vswt = (vswt & ~0x0f) | 0x08;
937 vswt = (vswt & ~0x0f) | 0x09;
941 mctl = (mctl & ~0x80) | 0x10;
942 vswt = (vswt & ~0x0f) | 0x09;
945 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
948 SET_BDA(modeset_ctl, mctl);
949 SET_BDA(video_switches, vswt);
954 handle_101231(struct bregs *regs)
956 u8 v = (regs->al & 0x01) << 3;
957 u8 mctl = GET_BDA(video_ctl) & ~0x08;
958 SET_BDA(video_ctl, mctl | v);
963 handle_101232(struct bregs *regs)
965 if (CONFIG_VGA_STDVGA_PORTS) {
966 stdvga_enable_video_addressing(regs->al);
972 handle_101233(struct bregs *regs)
974 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
975 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
976 SET_BDA(modeset_ctl, v | v2);
981 handle_101234(struct bregs *regs)
983 SET_BDA(video_ctl, (GET_BDA(video_ctl) & ~0x01) | (regs->al & 0x01));
988 handle_101235(struct bregs *regs)
995 handle_101236(struct bregs *regs)
1002 handle_1012XX(struct bregs *regs)
1008 handle_1012(struct bregs *regs)
1010 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
1016 case 0x10: handle_101210(regs); break;
1017 case 0x30: handle_101230(regs); break;
1018 case 0x31: handle_101231(regs); break;
1019 case 0x32: handle_101232(regs); break;
1020 case 0x33: handle_101233(regs); break;
1021 case 0x34: handle_101234(regs); break;
1022 case 0x35: handle_101235(regs); break;
1023 case 0x36: handle_101236(regs); break;
1024 default: handle_1012XX(regs); break;
1030 static void noinline
1031 handle_1013(struct bregs *regs)
1033 struct cursorpos cp;
1034 if (regs->dh == 0xff)
1035 // if row=0xff special case : use current cursor position
1036 cp = get_cursor_pos(regs->bh);
1038 cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh};
1040 u16 count = regs->cx;
1041 u8 *offset_far = (void*)(regs->bp + 0);
1044 u8 car = GET_FARVAR(regs->es, *offset_far);
1047 attr = GET_FARVAR(regs->es, *offset_far);
1051 struct carattr ca = {car, attr, 1};
1052 write_teletype(&cp, ca);
1061 handle_101a00(struct bregs *regs)
1063 regs->bx = GET_BDA(dcc_index);
1068 handle_101a01(struct bregs *regs)
1070 SET_BDA(dcc_index, regs->bl);
1071 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1076 handle_101aXX(struct bregs *regs)
1082 handle_101a(struct bregs *regs)
1085 case 0x00: handle_101a00(regs); break;
1086 case 0x01: handle_101a01(regs); break;
1087 default: handle_101aXX(regs); break;
1092 struct video_func_static static_functionality VAR16 = {
1093 .modes = 0x00, // Filled in by stdvga_build_video_param()
1094 .scanlines = 0x07, // 200, 350, 400 scan lines
1095 .cblocks = 0x02, // mamimum number of visible charsets in text mode
1096 .active_cblocks = 0x08, // total number of charset blocks in text mode
1097 .misc_flags = 0x0ce7,
1101 handle_101b(struct bregs *regs)
1104 struct video_func_info *info = (void*)(regs->di+0);
1105 memset_far(seg, info, 0, sizeof(*info));
1106 // Address of static functionality table
1107 SET_FARVAR(seg, info->static_functionality
1108 , SEGOFF(get_global_seg(), (u32)&static_functionality));
1110 // Hard coded copy from BIOS area. Should it be cleaner ?
1111 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1112 , sizeof(info->bda_0x49));
1113 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1114 , sizeof(info->bda_0x84));
1116 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1117 SET_FARVAR(seg, info->colors, 16);
1118 SET_FARVAR(seg, info->pages, 8);
1119 SET_FARVAR(seg, info->scan_lines, 2);
1120 SET_FARVAR(seg, info->video_mem, 3);
1126 handle_101c(struct bregs *regs)
1129 void *data = (void*)(regs->bx+0);
1130 u16 states = regs->cx;
1132 if (states & ~0x07 || cmd > 2)
1134 int ret = vgahw_save_restore(states | (cmd<<8), seg, data);
1138 regs->bx = ret / 64;
1145 handle_10XX(struct bregs *regs)
1150 // INT 10h Video Support Service Entry Point
1152 handle_10(struct bregs *regs)
1154 debug_enter(regs, DEBUG_VGA_10);
1156 case 0x00: handle_1000(regs); break;
1157 case 0x01: handle_1001(regs); break;
1158 case 0x02: handle_1002(regs); break;
1159 case 0x03: handle_1003(regs); break;
1160 case 0x04: handle_1004(regs); break;
1161 case 0x05: handle_1005(regs); break;
1162 case 0x06: handle_1006(regs); break;
1163 case 0x07: handle_1007(regs); break;
1164 case 0x08: handle_1008(regs); break;
1165 case 0x09: handle_1009(regs); break;
1166 case 0x0a: handle_100a(regs); break;
1167 case 0x0b: handle_100b(regs); break;
1168 case 0x0c: handle_100c(regs); break;
1169 case 0x0d: handle_100d(regs); break;
1170 case 0x0e: handle_100e(regs); break;
1171 case 0x0f: handle_100f(regs); break;
1172 case 0x10: handle_1010(regs); break;
1173 case 0x11: handle_1011(regs); break;
1174 case 0x12: handle_1012(regs); break;
1175 case 0x13: handle_1013(regs); break;
1176 case 0x1a: handle_101a(regs); break;
1177 case 0x1b: handle_101b(regs); break;
1178 case 0x1c: handle_101c(regs); break;
1179 case 0x4f: handle_104f(regs); break;
1180 default: handle_10XX(regs); break;