1 // ============================================================================================
3 // Copyright (C) 2002 Jeroen Janssen
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // ============================================================================================
21 // This VBE is part of the VGA Bios specific to the plex86/bochs Emulated VGA card.
22 // You can NOT drive any physical vga card with it.
24 // ============================================================================================
26 // This VBE Bios is based on information taken from :
27 // - VESA BIOS EXTENSION (VBE) Core Functions Standard Version 3.0 located at www.vesa.org
29 // ============================================================================================
36 // disable VESA/VBE2 check in vbe info
37 //#define VBE2_NO_VESA_CHECK
39 // dynamicly generate a mode_info list
44 #include "vbetables.h"
47 // The current OEM Software Revision of this VBE Bios
48 #define VBE_OEM_SOFTWARE_REV 0x0002;
50 extern char vbebios_copyright;
51 extern char vbebios_vendor_name;
52 extern char vbebios_product_name;
53 extern char vbebios_product_revision;
56 extern Bit16u vbebios_mode_list;
60 // FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
62 .ascii "Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/"
66 .ascii "Bochs/Plex86 Developers"
69 _vbebios_product_name:
70 .ascii "Bochs/Plex86 VBE Adapter"
73 _vbebios_product_revision:
74 .ascii "$Id: vbe.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $"
78 .ascii "Bochs VBE Display Adapter enabled"
83 _no_vbebios_info_string:
84 .ascii "NO Bochs VBE Support available!"
89 #if defined(USE_BX_INFO) || defined(DEBUG)
91 .ascii "VBE Bios $Id: vbe.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $"
96 // FIXME: for each new mode add a statement here
97 // at least until dynamic list creation is working
100 .word VBE_VESA_MODE_640X400X8
101 .word VBE_VESA_MODE_640X480X8
102 .word VBE_VESA_MODE_800X600X4
103 .word VBE_VESA_MODE_800X600X8
104 .word VBE_VESA_MODE_1024X768X8
105 .word VBE_VESA_MODE_640X480X1555
106 .word VBE_VESA_MODE_640X480X565
107 .word VBE_VESA_MODE_640X480X888
108 .word VBE_VESA_MODE_800X600X1555
109 .word VBE_VESA_MODE_800X600X565
110 .word VBE_VESA_MODE_800X600X888
111 .word VBE_VESA_MODE_1024X768X1555
112 .word VBE_VESA_MODE_1024X768X565
113 .word VBE_VESA_MODE_1024X768X888
114 .word VBE_OWN_MODE_640X480X8888
115 .word VBE_OWN_MODE_800X600X8888
116 .word VBE_OWN_MODE_1024X768X8888
117 .word VBE_OWN_MODE_320X200X8
118 .word VBE_VESA_MODE_END_OF_LIST
121 ; DISPI ioport functions
125 mov dx, # VBE_DISPI_IOPORT_INDEX
126 mov ax, # VBE_DISPI_INDEX_ID
128 mov dx, # VBE_DISPI_IOPORT_DATA
136 mov dx, # VBE_DISPI_IOPORT_INDEX
137 mov ax, # VBE_DISPI_INDEX_ID
140 mov dx, # VBE_DISPI_IOPORT_DATA
146 static void dispi_set_xres(xres)
155 mov dx, # VBE_DISPI_IOPORT_INDEX
156 mov ax, # VBE_DISPI_INDEX_XRES
158 mov dx, # VBE_DISPI_IOPORT_DATA
174 call vga_set_virt_width
182 static void dispi_set_yres(yres)
185 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_YRES);
186 outw(VBE_DISPI_IOPORT_DATA,yres);
189 static void dispi_set_bpp(bpp)
192 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_BPP);
193 outw(VBE_DISPI_IOPORT_DATA,bpp);
197 ; AL = bits per pixel / AH = bytes per pixel
200 mov dx, # VBE_DISPI_IOPORT_INDEX
201 mov ax, # VBE_DISPI_INDEX_BPP
203 mov dx, # VBE_DISPI_IOPORT_DATA
217 call dispi_get_enable
219 or ax, # VBE_DISPI_GETCAPS
220 call _dispi_set_enable
221 mov dx, # VBE_DISPI_IOPORT_INDEX
222 mov ax, # VBE_DISPI_INDEX_BPP
224 mov dx, # VBE_DISPI_IOPORT_DATA
228 call _dispi_set_enable
237 mov dx, # VBE_DISPI_IOPORT_INDEX
238 mov ax, # VBE_DISPI_INDEX_ENABLE
241 mov dx, # VBE_DISPI_IOPORT_DATA
248 mov dx, # VBE_DISPI_IOPORT_INDEX
249 mov ax, # VBE_DISPI_INDEX_ENABLE
251 mov dx, # VBE_DISPI_IOPORT_DATA
259 mov dx, # VBE_DISPI_IOPORT_INDEX
260 mov ax, # VBE_DISPI_INDEX_BANK
263 mov dx, # VBE_DISPI_IOPORT_DATA
270 mov dx, # VBE_DISPI_IOPORT_INDEX
271 mov ax, # VBE_DISPI_INDEX_BANK
273 mov dx, # VBE_DISPI_IOPORT_DATA
279 static void dispi_set_bank_farcall()
283 je dispi_set_bank_farcall_get
285 jnz dispi_set_bank_farcall_error
287 mov ax,# VBE_DISPI_INDEX_BANK
288 mov dx,# VBE_DISPI_IOPORT_INDEX
291 mov dx,# VBE_DISPI_IOPORT_DATA
294 dispi_set_bank_farcall_get:
295 mov ax,# VBE_DISPI_INDEX_BANK
296 mov dx,# VBE_DISPI_IOPORT_INDEX
298 mov dx,# VBE_DISPI_IOPORT_DATA
302 dispi_set_bank_farcall_error:
312 mov dx, # VBE_DISPI_IOPORT_INDEX
313 mov ax, # VBE_DISPI_INDEX_X_OFFSET
316 mov dx, # VBE_DISPI_IOPORT_DATA
323 mov dx, # VBE_DISPI_IOPORT_INDEX
324 mov ax, # VBE_DISPI_INDEX_X_OFFSET
326 mov dx, # VBE_DISPI_IOPORT_DATA
334 mov dx, # VBE_DISPI_IOPORT_INDEX
335 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
338 mov dx, # VBE_DISPI_IOPORT_DATA
345 mov dx, # VBE_DISPI_IOPORT_INDEX
346 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
348 mov dx, # VBE_DISPI_IOPORT_DATA
373 dispi_set_virt_width:
374 call vga_set_virt_width
377 mov dx, # VBE_DISPI_IOPORT_INDEX
378 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
381 mov dx, # VBE_DISPI_IOPORT_DATA
386 dispi_get_virt_width:
388 mov dx, # VBE_DISPI_IOPORT_INDEX
389 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
391 mov dx, # VBE_DISPI_IOPORT_DATA
396 dispi_get_virt_height:
398 mov dx, # VBE_DISPI_IOPORT_INDEX
399 mov ax, # VBE_DISPI_INDEX_VIRT_HEIGHT
401 mov dx, # VBE_DISPI_IOPORT_DATA
408 // ModeInfo helper function
409 static ModeInfoListItem* mode_info_find_mode(mode, using_lfb)
410 Bit16u mode; Boolean using_lfb;
412 ModeInfoListItem *cur_info=&mode_info_list;
414 while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST)
416 if (cur_info->mode == mode)
422 else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
442 ; Has VBE display - Returns true if VBE display detected
444 _vbe_has_vbe_display:
447 mov ax, # BIOSMEM_SEG
449 mov bx, # BIOSMEM_VBE_FLAG
457 ; VBE Init - Initialise the Vesa Bios Extension Code
458 ; This function does a sanity check on the host side display code interface.
461 mov ax, # VBE_DISPI_ID0
464 cmp ax, # VBE_DISPI_ID0
468 mov ax, # BIOSMEM_SEG
470 mov bx, # BIOSMEM_VBE_FLAG
475 mov ax, # VBE_DISPI_ID3
478 #if defined(USE_BX_INFO) || defined(DEBUG)
479 mov bx, #msg_vbe_init
487 ; VBE Display Info - Display information on screen about the VBE
490 call _vbe_has_vbe_display
495 mov si, #_vbebios_info_string
500 mov si, #_no_vbebios_info_string
504 /** Function 00h - Return VBE Controller Information
508 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
509 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
510 * the info block is 512 bytes in size)
512 * AX = VBE Return Status
515 void vbe_biosfn_return_controller_information(AX, ES, DI)
516 Bit16u *AX;Bit16u ES;Bit16u DI;
519 VbeInfoBlock vbe_info_block;
525 ModeInfoListItem *cur_info=&mode_info_list;
527 status = read_word(ss, AX);
530 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);
534 #ifdef VBE2_NO_VESA_CHECK
536 // get vbe_info_block into local variable
537 memcpyb(ss, &vbe_info_block, ES, DI, sizeof(vbe_info_block));
539 // check for VBE2 signature
540 if (((vbe_info_block.VbeSignature[0] == 'V') &&
541 (vbe_info_block.VbeSignature[1] == 'B') &&
542 (vbe_info_block.VbeSignature[2] == 'E') &&
543 (vbe_info_block.VbeSignature[3] == '2')) ||
545 ((vbe_info_block.VbeSignature[0] == 'V') &&
546 (vbe_info_block.VbeSignature[1] == 'E') &&
547 (vbe_info_block.VbeSignature[2] == 'S') &&
548 (vbe_info_block.VbeSignature[3] == 'A')) )
552 printf("VBE correct VESA/VBE2 signature found\n");
558 vbe_info_block.VbeSignature[0] = 'V';
559 vbe_info_block.VbeSignature[1] = 'E';
560 vbe_info_block.VbeSignature[2] = 'S';
561 vbe_info_block.VbeSignature[3] = 'A';
563 // VBE Version supported
564 vbe_info_block.VbeVersion = 0x0200;
567 vbe_info_block.OemStringPtr_Seg = 0xc000;
568 vbe_info_block.OemStringPtr_Off = &vbebios_copyright;
571 vbe_info_block.Capabilities[0] = VBE_CAPABILITY_8BIT_DAC;
572 vbe_info_block.Capabilities[1] = 0;
573 vbe_info_block.Capabilities[2] = 0;
574 vbe_info_block.Capabilities[3] = 0;
577 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
578 vbe_info_block.VideoModePtr_Seg= ES ;
579 vbe_info_block.VideoModePtr_Off= DI + 34;
581 // VBE Video Mode Pointer (staticly in rom)
582 vbe_info_block.VideoModePtr_Seg = 0xc000;
583 vbe_info_block.VideoModePtr_Off = &vbebios_mode_list;
586 // VBE Total Memory (in 64b blocks)
587 vbe_info_block.TotalMemory = VBE_TOTAL_VIDEO_MEMORY_DIV_64K;
592 vbe_info_block.OemSoftwareRev = VBE_OEM_SOFTWARE_REV;
593 vbe_info_block.OemVendorNamePtr_Seg = 0xc000;
594 vbe_info_block.OemVendorNamePtr_Off = &vbebios_vendor_name;
595 vbe_info_block.OemProductNamePtr_Seg = 0xc000;
596 vbe_info_block.OemProductNamePtr_Off = &vbebios_product_name;
597 vbe_info_block.OemProductRevPtr_Seg = 0xc000;
598 vbe_info_block.OemProductRevPtr_Off = &vbebios_product_revision;
600 // copy updates in vbe_info_block back
601 memcpyb(ES, DI, ss, &vbe_info_block, sizeof(vbe_info_block));
605 // copy updates in vbe_info_block back (VBE 1.x compatibility)
606 memcpyb(ES, DI, ss, &vbe_info_block, 256);
612 if (cur_info->info.BitsPerPixel <= dispi_get_max_bpp()) {
614 printf("VBE found mode %x => %x\n", cur_info->mode,cur_mode);
616 write_word(ES, DI + cur_ptr, cur_info->mode);
621 } while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST);
623 // Add vesa mode list terminator
624 write_word(ES, DI + cur_ptr, cur_info->mode);
629 write_word(ss, AX, result);
633 /** Function 01h - Return VBE Mode Information
638 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
640 * AX = VBE Return Status
643 void vbe_biosfn_return_mode_information(AX, CX, ES, DI)
644 Bit16u *AX;Bit16u CX; Bit16u ES;Bit16u DI;
646 Bit16u result=0x0100;
649 ModeInfoListItem *cur_info;
653 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
656 using_lfb=((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
660 cur_info = mode_info_find_mode(CX, using_lfb, &cur_info);
665 printf("VBE found mode %x\n",CX);
667 memsetb(ss, &info, 0, sizeof(ModeInfoBlock));
668 memcpyb(ss, &info, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
669 if (info.WinAAttributes & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
670 info.WinFuncPtr = 0xC0000000UL;
671 *(Bit16u *)&(info.WinFuncPtr) = (Bit16u)(dispi_set_bank_farcall);
679 printf("VBE *NOT* found mode %x\n",CX);
686 // copy updates in mode_info_block back
687 memcpyb(ES, DI, ss, &info, sizeof(info));
690 write_word(ss, AX, result);
693 /** Function 02h - Set VBE Mode
697 * BX = Desired Mode to set
698 * ES:DI = Pointer to CRTCInfoBlock structure
700 * AX = VBE Return Status
703 void vbe_biosfn_set_mode(AX, BX, ES, DI)
704 Bit16u *AX;Bit16u BX; Bit16u ES;Bit16u DI;
706 Bit16u ss = get_SS();
708 ModeInfoListItem *cur_info;
713 using_lfb=((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
714 lfb_flag=using_lfb?VBE_DISPI_LFB_ENABLED:0;
715 no_clear=((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY)?VBE_DISPI_NOCLEARMEM:0;
719 //result=read_word(ss,AX);
721 // check for non vesa mode
722 if (BX<VBE_MODE_VESA_DEFINED)
726 dispi_set_enable(VBE_DISPI_DISABLED);
727 // call the vgabios in order to set the video mode
728 // this allows for going back to textmode with a VBE call (some applications expect that to work)
731 biosfn_set_video_mode(mode);
735 cur_info = mode_info_find_mode(BX, using_lfb, &cur_info);
740 printf("VBE found mode %x, setting:\n", BX);
741 printf("\txres%x yres%x bpp%x\n",
742 cur_info->info.XResolution,
743 cur_info->info.YResolution,
744 cur_info->info.BitsPerPixel);
747 // first disable current mode (when switching between vesa modi)
748 dispi_set_enable(VBE_DISPI_DISABLED);
750 if (cur_info->mode == VBE_VESA_MODE_800X600X4)
752 biosfn_set_video_mode(0x6a);
755 dispi_set_bpp(cur_info->info.BitsPerPixel);
756 dispi_set_xres(cur_info->info.XResolution);
757 dispi_set_yres(cur_info->info.YResolution);
759 dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag);
761 write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX);
762 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear));
769 printf("VBE *NOT* found mode %x\n" , BX);
773 // FIXME: redirect non VBE modi to normal VGA bios operation
774 // (switch back to VGA mode
779 write_word(ss, AX, result);
782 /** Function 03h - Return Current VBE Mode
787 * AX = VBE Return Status
788 * BX = Current VBE Mode
792 vbe_biosfn_return_current_mode:
794 mov ax, # BIOSMEM_SEG
796 call dispi_get_enable
797 and ax, # VBE_DISPI_ENABLED
799 mov bx, # BIOSMEM_VBE_MODE
804 mov bx, # BIOSMEM_CURRENT_MODE
815 /** Function 04h - Save/Restore State
819 * DL = 00h Return Save/Restore State buffer size
822 * CX = Requested states
823 * ES:BX = Pointer to buffer (if DL <> 00h)
825 * AX = VBE Return Status
826 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
829 void vbe_biosfn_save_restore_state(AX, DL, CX, ES, BX)
834 /** Function 05h - Display Window Control
838 * (16-bit) BH = 00h Set memory window
839 * = 01h Get memory window
843 * DX = Window number in video memory in window
844 * granularity units (Set Memory Window only)
846 * If this function is called while in a linear frame buffer mode,
847 * this function must fail with completion code AH=03h
850 * AX = VBE Return Status
851 * DX = Window number in window granularity units
852 * (Get Memory Window only)
855 vbe_biosfn_display_window_control:
859 je get_display_window
860 jb set_display_window
882 /** Function 06h - Set/Get Logical Scan Line Length
886 * BL = 00h Set Scan Line Length in Pixels
887 * = 01h Get Scan Line Length
888 * = 02h Set Scan Line Length in Bytes
889 * = 03h Get Maximum Scan Line Length
890 * CX = If BL=00h Desired Width in Pixels
891 * If BL=02h Desired Width in Bytes
892 * (Ignored for Get Functions)
895 * AX = VBE Return Status
896 * BX = Bytes Per Scan Line
897 * CX = Actual Pixels Per Scan Line
898 * (truncated to nearest complete pixel)
899 * DX = Maximum Number of Scan Lines
902 vbe_biosfn_set_get_logical_scan_line_length:
905 je get_logical_scan_line_length
907 je set_logical_scan_line_bytes
908 jb set_logical_scan_line_pixels
911 set_logical_scan_line_bytes:
919 set_logical_scan_line_pixels:
920 call dispi_set_virt_width
921 get_logical_scan_line_length:
925 call dispi_get_virt_width
929 call dispi_get_virt_height
936 /** Function 07h - Set/Get Display Start
940 * BH = 00h Reserved and must be 00h
941 * BL = 00h Set Display Start
942 * = 01h Get Display Start
943 * = 02h Schedule Display Start (Alternate)
944 * = 03h Schedule Stereoscopic Display Start
945 * = 04h Get Scheduled Display Start Status
946 * = 05h Enable Stereoscopic Mode
947 * = 06h Disable Stereoscopic Mode
948 * = 80h Set Display Start during Vertical Retrace
949 * = 82h Set Display Start during Vertical Retrace (Alternate)
950 * = 83h Set Stereoscopic Display Start during Vertical Retrace
951 * ECX = If BL=02h/82h Display Start Address in bytes
952 * If BL=03h/83h Left Image Start Address in bytes
953 * EDX = If BL=03h/83h Right Image Start Address in bytes
954 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
955 * DX = If BL=00h/80h First Displayed Scan Line
958 * AX = VBE Return Status
959 * BH = If BL=01h Reserved and will be 0
960 * CX = If BL=01h First Displayed Pixel In Scan Line
961 * If BL=04h 0 if flip has not occurred, not 0 if it has
962 * DX = If BL=01h First Displayed Scan Line
965 * BH = 00h Reserved and must be 00h
966 * BL = 00h Set Display Start
967 * = 80h Set Display Start during Vertical Retrace
968 * CX = Bits 0-15 of display start address
969 * DX = Bits 16-31 of display start address
970 * ES = Selector for memory mapped registers
973 vbe_biosfn_set_get_display_start:
983 call dispi_set_x_offset
985 call dispi_set_y_offset
989 call dispi_get_x_offset
991 call dispi_get_y_offset
999 /** Function 08h - Set/Get Dac Palette Format
1003 * BL = 00h set DAC palette width
1004 * = 01h get DAC palette width
1005 * BH = If BL=00h: desired number of bits per primary color
1007 * AX = VBE Return Status
1008 * BH = current number of bits per primary color (06h = standard VGA)
1011 vbe_biosfn_set_get_dac_palette_format:
1013 je get_dac_palette_format
1014 jb set_dac_palette_format
1017 set_dac_palette_format:
1018 call dispi_get_enable
1022 jne vbe_08_unsupported
1023 or ax, # VBE_DISPI_8BIT_DAC
1026 and ax, #~ VBE_DISPI_8BIT_DAC
1028 call _dispi_set_enable
1029 get_dac_palette_format:
1031 call dispi_get_enable
1032 and ax, # VBE_DISPI_8BIT_DAC
1044 /** Function 09h - Set/Get Palette Data
1049 * AX = VBE Return Status
1051 * FIXME: incomplete API description, Input & Output
1053 void vbe_biosfn_set_get_palette_data(AX)
1057 /** Function 0Ah - Return VBE Protected Mode Interface
1062 * AX = VBE Return Status
1064 * FIXME: incomplete API description, Input & Output
1066 void vbe_biosfn_return_protected_mode_interface(AX)