📄 vbe.c
字号:
// ============================================================================================// // Copyright (C) 2002 Jeroen Janssen//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA// // ============================================================================================// // This VBE is part of the VGA Bios specific to the plex86/bochs Emulated VGA card. // You can NOT drive any physical vga card with it. //// ============================================================================================// // This VBE Bios is based on information taken from :// - VESA BIOS EXTENSION (VBE) Core Functions Standard Version 3.0 located at www.vesa.org//// ============================================================================================// defines available// enable LFB support#define VBE_HAVE_LFB// disable VESA/VBE2 check in vbe info//#define VBE2_NO_VESA_CHECK// dynamicly generate a mode_info list#define DYN_LIST#include "vbe.h"#include "vbetables.h"// The current OEM Software Revision of this VBE Bios#define VBE_OEM_SOFTWARE_REV 0x0002;extern char vbebios_copyright;extern char vbebios_vendor_name;extern char vbebios_product_name;extern char vbebios_product_revision;#ifndef DYN_LISTextern Bit16u vbebios_mode_list;#endifASM_START// FIXME: 'merge' these (c) etc strings with the vgabios.c strings?_vbebios_copyright:.ascii "Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/".byte 0x00_vbebios_vendor_name:.ascii "Bochs/Plex86 Developers".byte 0x00_vbebios_product_name:.ascii "Bochs/Plex86 VBE Adapter".byte 0x00_vbebios_product_revision:.ascii "$Id: vbe.c,v 1.47 2005/05/24 16:50:50 vruppert Exp $".byte 0x00_vbebios_info_string:.ascii "Bochs VBE Display Adapter enabled".byte 0x0a,0x0d.byte 0x0a,0x0d.byte 0x00_no_vbebios_info_string:.ascii "NO Bochs VBE Support available!".byte 0x0a,0x0d.byte 0x0a,0x0d.byte 0x00#if defined(USE_BX_INFO) || defined(DEBUG)msg_vbe_init:.ascii "VBE Bios $Id: vbe.c,v 1.47 2005/05/24 16:50:50 vruppert Exp $".byte 0x0a,0x0d, 0x00#endif#ifndef DYN_LIST// FIXME: for each new mode add a statement here// at least until dynamic list creation is working_vbebios_mode_list:.word VBE_VESA_MODE_640X400X8.word VBE_VESA_MODE_640X480X8.word VBE_VESA_MODE_800X600X4.word VBE_VESA_MODE_800X600X8.word VBE_VESA_MODE_1024X768X8.word VBE_VESA_MODE_640X480X1555.word VBE_VESA_MODE_640X480X565.word VBE_VESA_MODE_640X480X888.word VBE_VESA_MODE_800X600X1555.word VBE_VESA_MODE_800X600X565.word VBE_VESA_MODE_800X600X888.word VBE_VESA_MODE_1024X768X1555.word VBE_VESA_MODE_1024X768X565.word VBE_VESA_MODE_1024X768X888.word VBE_OWN_MODE_640X480X8888.word VBE_OWN_MODE_800X600X8888.word VBE_OWN_MODE_1024X768X8888.word VBE_OWN_MODE_320X200X8.word VBE_VESA_MODE_END_OF_LIST#endif; DISPI ioport functionsdispi_get_id: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_ID out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retdispi_set_id: push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_ID out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retASM_ENDstatic void dispi_set_xres(xres) Bit16u xres;{ASM_START push bp mov bp, sp push ax push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_XRES out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA mov ax, 4[bp] ; xres out dx, ax push ax mov dx, #0x03d4 mov ax, #0x0011 out dx, ax mov dx, #0x03d4 pop ax push ax shr ax, #3 dec ax mov ah, al mov al, #0x01 out dx, ax pop ax call vga_set_virt_width pop dx pop ax pop bpASM_END}static void dispi_set_yres(yres) Bit16u yres;{ outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_YRES); outw(VBE_DISPI_IOPORT_DATA,yres);}static void dispi_set_bpp(bpp) Bit16u bpp;{ outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_BPP); outw(VBE_DISPI_IOPORT_DATA,bpp);}ASM_START; AL = bits per pixel / AH = bytes per pixeldispi_get_bpp: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_BPP out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx mov ah, al shr ah, 3 test al, #0x07 jz get_bpp_noinc inc ahget_bpp_noinc: pop dx ret_dispi_get_max_bpp: push dx push bx call dispi_get_enable mov bx, ax or ax, # VBE_DISPI_GETCAPS call _dispi_set_enable mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_BPP out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx push ax mov ax, bx call _dispi_set_enable pop ax pop bx pop dx ret_dispi_set_enable: push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_ENABLE out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retdispi_get_enable: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_ENABLE out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx ret_dispi_set_bank: push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_BANK out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retdispi_get_bank: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_BANK out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retASM_ENDstatic void dispi_set_bank_farcall(){ASM_START cmp bx,#0x0100 je dispi_set_bank_farcall_get or bx,bx jnz dispi_set_bank_farcall_error push dx mov ax,# VBE_DISPI_INDEX_BANK mov dx,# VBE_DISPI_IOPORT_INDEX out dx,ax pop ax mov dx,# VBE_DISPI_IOPORT_DATA out dx,ax retfdispi_set_bank_farcall_get: mov ax,# VBE_DISPI_INDEX_BANK mov dx,# VBE_DISPI_IOPORT_INDEX out dx,ax mov dx,# VBE_DISPI_IOPORT_DATA in ax,dx mov dx,ax retfdispi_set_bank_farcall_error: mov ax,#0x014F retfASM_END}ASM_STARTdispi_set_x_offset: push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_X_OFFSET out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retdispi_get_x_offset: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_X_OFFSET out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retdispi_set_y_offset: push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_Y_OFFSET out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retdispi_get_y_offset: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_Y_OFFSET out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retvga_set_virt_width: push ax push bx push dx mov bx, ax call dispi_get_bpp cmp al, #0x04 ja set_width_svga shr bx, #2set_width_svga: shr bx, #2 mov dx, #0x03d4 mov ah, bl mov al, #0x13 out dx, ax pop dx pop bx pop ax retdispi_set_virt_width: call vga_set_virt_width push dx push ax mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH out dx, ax pop ax mov dx, # VBE_DISPI_IOPORT_DATA out dx, ax pop dx retdispi_get_virt_width: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retdispi_get_virt_height: push dx mov dx, # VBE_DISPI_IOPORT_INDEX mov ax, # VBE_DISPI_INDEX_VIRT_HEIGHT out dx, ax mov dx, # VBE_DISPI_IOPORT_DATA in ax, dx pop dx retASM_END// ModeInfo helper functionstatic ModeInfoListItem* mode_info_find_mode(mode, using_lfb) Bit16u mode; Boolean using_lfb;{ ModeInfoListItem *cur_info=&mode_info_list; while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST) { if (cur_info->mode == mode) { if (!using_lfb) { return cur_info; } else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE) { return cur_info; } else { cur_info++; } } else { cur_info++; } } return 0;}ASM_START; Has VBE display - Returns true if VBE display detected_vbe_has_vbe_display: push ds push bx mov ax, # BIOSMEM_SEG mov ds, ax mov bx, # BIOSMEM_VBE_FLAG mov al, [bx] and al, #0x01 xor ah, ah pop bx pop ds ret; VBE Init - Initialise the Vesa Bios Extension Code; This function does a sanity check on the host side display code interface.vbe_init: mov ax, # VBE_DISPI_ID0 call dispi_set_id call dispi_get_id cmp ax, # VBE_DISPI_ID0 jne no_vbe_interface push ds push bx mov ax, # BIOSMEM_SEG mov ds, ax mov bx, # BIOSMEM_VBE_FLAG mov al, #0x01 mov [bx], al pop bx pop ds mov ax, # VBE_DISPI_ID3 call dispi_set_idno_vbe_interface:#if defined(USE_BX_INFO) || defined(DEBUG) mov bx, #msg_vbe_init push bx call _printf inc sp inc sp#endif ret; VBE Display Info - Display information on screen about the VBEvbe_display_info: call _vbe_has_vbe_display test ax, ax jz no_vbe_flag mov ax, #0xc000 mov ds, ax mov si, #_vbebios_info_string jmp _display_stringno_vbe_flag: mov ax, #0xc000 mov ds, ax mov si, #_no_vbebios_info_string jmp _display_stringASM_END /** Function 00h - Return VBE Controller Information * * Input: * AX = 4F00h * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure * (VbeSignature should be VBE2 when VBE 2.0 information is desired and * the info block is 512 bytes in size) * Output: * AX = VBE Return Status * */void vbe_biosfn_return_controller_information(AX, ES, DI)Bit16u *AX;Bit16u ES;Bit16u DI;{ Bit16u ss=get_SS(); VbeInfoBlock vbe_info_block; Bit16u status; Bit16u result; Bit16u vbe2_info; Bit16u cur_mode=0; Bit16u cur_ptr=34; ModeInfoListItem *cur_info=&mode_info_list; status = read_word(ss, AX); #ifdef DEBUG printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);#endif vbe2_info = 0;#ifdef VBE2_NO_VESA_CHECK#else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -