- biossums utility now supports VGABIOS sizes up to 64 kBytes
[vgabios.git] / vbe.c
blobd0eb2af6651e882b407a08fac2174ef30fab6f0f
1 // ============================================================================================
2 //
3 // Copyright (C) 2002 Jeroen Janssen
4 //
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.
9 //
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
18 //
19 // ============================================================================================
20 //
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 // ============================================================================================
25 //
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 // ============================================================================================
32 // defines available
33 // enable LFB support
34 #define VBE_HAVE_LFB
36 // disable VESA/VBE2 check in vbe info
37 //#define VBE2_NO_VESA_CHECK
39 // dynamicly generate a mode_info list
40 #define DYN_LIST
43 #include "vbe.h"
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;
55 #ifndef DYN_LIST
56 extern Bit16u vbebios_mode_list;
57 #endif
59 ASM_START
60 // FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
61 _vbebios_copyright:
62 .ascii "Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/"
63 .byte 0x00
65 _vbebios_vendor_name:
66 .ascii "Bochs/Plex86 Developers"
67 .byte 0x00
69 _vbebios_product_name:
70 .ascii "Bochs/Plex86 VBE Adapter"
71 .byte 0x00
73 _vbebios_product_revision:
74 .ascii "$Id$"
75 .byte 0x00
77 _vbebios_info_string:
78 .ascii "Bochs VBE Display Adapter enabled"
79 .byte 0x0a,0x0d
80 .byte 0x0a,0x0d
81 .byte 0x00
83 _no_vbebios_info_string:
84 .ascii "NO Bochs VBE Support available!"
85 .byte 0x0a,0x0d
86 .byte 0x0a,0x0d
87 .byte 0x00
89 #if defined(USE_BX_INFO) || defined(DEBUG)
90 msg_vbe_init:
91 .ascii "VBE Bios $Id$"
92 .byte 0x0a,0x0d, 0x00
93 #endif
95 #ifndef DYN_LIST
96 // FIXME: for each new mode add a statement here
97 // at least until dynamic list creation is working
98 _vbebios_mode_list:
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
119 #endif
121 vesa_pm_start:
122 dw vesa_pm_set_window - vesa_pm_start
123 dw vesa_pm_set_display_strt - vesa_pm_start
124 dw vesa_pm_unimplemented - vesa_pm_start
125 dw 0
127 USE32
128 vesa_pm_set_window:
129 mov ax, #0x4f05
130 int #0x10
133 vesa_pm_set_display_start:
134 mov ax, #0x4f07
135 int #0x10
138 vesa_pm_unimplemented:
139 mov ax, #0x014f
141 USE16
142 vesa_pm_end:
144 ; DISPI ioport functions
146 dispi_get_id:
147 push dx
148 mov dx, # VBE_DISPI_IOPORT_INDEX
149 mov ax, # VBE_DISPI_INDEX_ID
150 out dx, ax
151 mov dx, # VBE_DISPI_IOPORT_DATA
152 in ax, dx
153 pop dx
156 dispi_set_id:
157 push dx
158 push ax
159 mov dx, # VBE_DISPI_IOPORT_INDEX
160 mov ax, # VBE_DISPI_INDEX_ID
161 out dx, ax
162 pop ax
163 mov dx, # VBE_DISPI_IOPORT_DATA
164 out dx, ax
165 pop dx
167 ASM_END
169 static void dispi_set_xres(xres)
170 Bit16u xres;
172 ASM_START
173 push bp
174 mov bp, sp
175 push ax
176 push dx
178 mov dx, # VBE_DISPI_IOPORT_INDEX
179 mov ax, # VBE_DISPI_INDEX_XRES
180 out dx, ax
181 mov dx, # VBE_DISPI_IOPORT_DATA
182 mov ax, 4[bp] ; xres
183 out dx, ax
184 push ax
185 mov dx, #0x03d4
186 mov ax, #0x0011
187 out dx, ax
188 mov dx, #0x03d4
189 pop ax
190 push ax
191 shr ax, #3
192 dec ax
193 mov ah, al
194 mov al, #0x01
195 out dx, ax
196 pop ax
197 call vga_set_virt_width
199 pop dx
200 pop ax
201 pop bp
202 ASM_END
205 static void dispi_set_yres(yres)
206 Bit16u yres;
208 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_YRES);
209 outw(VBE_DISPI_IOPORT_DATA,yres);
212 static void dispi_set_bpp(bpp)
213 Bit16u bpp;
215 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_BPP);
216 outw(VBE_DISPI_IOPORT_DATA,bpp);
219 ASM_START
220 ; AL = bits per pixel / AH = bytes per pixel
221 dispi_get_bpp:
222 push dx
223 mov dx, # VBE_DISPI_IOPORT_INDEX
224 mov ax, # VBE_DISPI_INDEX_BPP
225 out dx, ax
226 mov dx, # VBE_DISPI_IOPORT_DATA
227 in ax, dx
228 mov ah, al
229 shr ah, 3
230 test al, #0x07
231 jz get_bpp_noinc
232 inc ah
233 get_bpp_noinc:
234 pop dx
237 _dispi_get_max_bpp:
238 push dx
239 push bx
240 call dispi_get_enable
241 mov bx, ax
242 or ax, # VBE_DISPI_GETCAPS
243 call _dispi_set_enable
244 mov dx, # VBE_DISPI_IOPORT_INDEX
245 mov ax, # VBE_DISPI_INDEX_BPP
246 out dx, ax
247 mov dx, # VBE_DISPI_IOPORT_DATA
248 in ax, dx
249 push ax
250 mov ax, bx
251 call _dispi_set_enable
252 pop ax
253 pop bx
254 pop dx
257 _dispi_set_enable:
258 push dx
259 push ax
260 mov dx, # VBE_DISPI_IOPORT_INDEX
261 mov ax, # VBE_DISPI_INDEX_ENABLE
262 out dx, ax
263 pop ax
264 mov dx, # VBE_DISPI_IOPORT_DATA
265 out dx, ax
266 pop dx
269 dispi_get_enable:
270 push dx
271 mov dx, # VBE_DISPI_IOPORT_INDEX
272 mov ax, # VBE_DISPI_INDEX_ENABLE
273 out dx, ax
274 mov dx, # VBE_DISPI_IOPORT_DATA
275 in ax, dx
276 pop dx
279 _dispi_set_bank:
280 push dx
281 push ax
282 mov dx, # VBE_DISPI_IOPORT_INDEX
283 mov ax, # VBE_DISPI_INDEX_BANK
284 out dx, ax
285 pop ax
286 mov dx, # VBE_DISPI_IOPORT_DATA
287 out dx, ax
288 pop dx
291 dispi_get_bank:
292 push dx
293 mov dx, # VBE_DISPI_IOPORT_INDEX
294 mov ax, # VBE_DISPI_INDEX_BANK
295 out dx, ax
296 mov dx, # VBE_DISPI_IOPORT_DATA
297 in ax, dx
298 pop dx
300 ASM_END
302 static void dispi_set_bank_farcall()
304 ASM_START
305 cmp bx,#0x0100
306 je dispi_set_bank_farcall_get
307 or bx,bx
308 jnz dispi_set_bank_farcall_error
309 push dx
310 mov ax,# VBE_DISPI_INDEX_BANK
311 mov dx,# VBE_DISPI_IOPORT_INDEX
312 out dx,ax
313 pop ax
314 mov dx,# VBE_DISPI_IOPORT_DATA
315 out dx,ax
316 retf
317 dispi_set_bank_farcall_get:
318 mov ax,# VBE_DISPI_INDEX_BANK
319 mov dx,# VBE_DISPI_IOPORT_INDEX
320 out dx,ax
321 mov dx,# VBE_DISPI_IOPORT_DATA
322 in ax,dx
323 mov dx,ax
324 retf
325 dispi_set_bank_farcall_error:
326 mov ax,#0x014F
327 retf
328 ASM_END
331 ASM_START
332 dispi_set_x_offset:
333 push dx
334 push ax
335 mov dx, # VBE_DISPI_IOPORT_INDEX
336 mov ax, # VBE_DISPI_INDEX_X_OFFSET
337 out dx, ax
338 pop ax
339 mov dx, # VBE_DISPI_IOPORT_DATA
340 out dx, ax
341 pop dx
344 dispi_get_x_offset:
345 push dx
346 mov dx, # VBE_DISPI_IOPORT_INDEX
347 mov ax, # VBE_DISPI_INDEX_X_OFFSET
348 out dx, ax
349 mov dx, # VBE_DISPI_IOPORT_DATA
350 in ax, dx
351 pop dx
354 dispi_set_y_offset:
355 push dx
356 push ax
357 mov dx, # VBE_DISPI_IOPORT_INDEX
358 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
359 out dx, ax
360 pop ax
361 mov dx, # VBE_DISPI_IOPORT_DATA
362 out dx, ax
363 pop dx
366 dispi_get_y_offset:
367 push dx
368 mov dx, # VBE_DISPI_IOPORT_INDEX
369 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
370 out dx, ax
371 mov dx, # VBE_DISPI_IOPORT_DATA
372 in ax, dx
373 pop dx
376 vga_set_virt_width:
377 push ax
378 push bx
379 push dx
380 mov bx, ax
381 call dispi_get_bpp
382 cmp al, #0x04
383 ja set_width_svga
384 shr bx, #2
385 set_width_svga:
386 shr bx, #2
387 mov dx, #0x03d4
388 mov ah, bl
389 mov al, #0x13
390 out dx, ax
391 pop dx
392 pop bx
393 pop ax
396 dispi_set_virt_width:
397 call vga_set_virt_width
398 push dx
399 push ax
400 mov dx, # VBE_DISPI_IOPORT_INDEX
401 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
402 out dx, ax
403 pop ax
404 mov dx, # VBE_DISPI_IOPORT_DATA
405 out dx, ax
406 pop dx
409 dispi_get_virt_width:
410 push dx
411 mov dx, # VBE_DISPI_IOPORT_INDEX
412 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
413 out dx, ax
414 mov dx, # VBE_DISPI_IOPORT_DATA
415 in ax, dx
416 pop dx
419 dispi_get_virt_height:
420 push dx
421 mov dx, # VBE_DISPI_IOPORT_INDEX
422 mov ax, # VBE_DISPI_INDEX_VIRT_HEIGHT
423 out dx, ax
424 mov dx, # VBE_DISPI_IOPORT_DATA
425 in ax, dx
426 pop dx
428 ASM_END
431 // ModeInfo helper function
432 static ModeInfoListItem* mode_info_find_mode(mode, using_lfb)
433 Bit16u mode; Boolean using_lfb;
435 ModeInfoListItem *cur_info=&mode_info_list;
437 while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST)
439 if (cur_info->mode == mode)
441 if (!using_lfb)
443 return cur_info;
445 else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
447 return cur_info;
449 else
451 cur_info++;
454 else
456 cur_info++;
460 return 0;
463 ASM_START
465 ; Has VBE display - Returns true if VBE display detected
467 _vbe_has_vbe_display:
468 push ds
469 push bx
470 mov ax, # BIOSMEM_SEG
471 mov ds, ax
472 mov bx, # BIOSMEM_VBE_FLAG
473 mov al, [bx]
474 and al, #0x01
475 xor ah, ah
476 pop bx
477 pop ds
480 ; VBE Init - Initialise the Vesa Bios Extension Code
481 ; This function does a sanity check on the host side display code interface.
483 vbe_init:
484 mov ax, # VBE_DISPI_ID0
485 call dispi_set_id
486 call dispi_get_id
487 cmp ax, # VBE_DISPI_ID0
488 jne no_vbe_interface
489 push ds
490 push bx
491 mov ax, # BIOSMEM_SEG
492 mov ds, ax
493 mov bx, # BIOSMEM_VBE_FLAG
494 mov al, #0x01
495 mov [bx], al
496 pop bx
497 pop ds
498 mov ax, # VBE_DISPI_ID3
499 call dispi_set_id
500 no_vbe_interface:
501 #if defined(USE_BX_INFO) || defined(DEBUG)
502 mov bx, #msg_vbe_init
503 push bx
504 call _printf
505 inc sp
506 inc sp
507 #endif
510 ; VBE Display Info - Display information on screen about the VBE
512 vbe_display_info:
513 call _vbe_has_vbe_display
514 test ax, ax
515 jz no_vbe_flag
516 mov ax, #0xc000
517 mov ds, ax
518 mov si, #_vbebios_info_string
519 jmp _display_string
520 no_vbe_flag:
521 mov ax, #0xc000
522 mov ds, ax
523 mov si, #_no_vbebios_info_string
524 jmp _display_string
525 ASM_END
527 /** Function 00h - Return VBE Controller Information
529 * Input:
530 * AX = 4F00h
531 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
532 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
533 * the info block is 512 bytes in size)
534 * Output:
535 * AX = VBE Return Status
538 void vbe_biosfn_return_controller_information(AX, ES, DI)
539 Bit16u *AX;Bit16u ES;Bit16u DI;
541 Bit16u ss=get_SS();
542 VbeInfoBlock vbe_info_block;
543 Bit16u status;
544 Bit16u result;
545 Bit16u vbe2_info;
546 Bit16u cur_mode=0;
547 Bit16u cur_ptr=34;
548 ModeInfoListItem *cur_info=&mode_info_list;
550 status = read_word(ss, AX);
552 #ifdef DEBUG
553 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);
554 #endif
556 vbe2_info = 0;
557 #ifdef VBE2_NO_VESA_CHECK
558 #else
559 // get vbe_info_block into local variable
560 memcpyb(ss, &vbe_info_block, ES, DI, sizeof(vbe_info_block));
562 // check for VBE2 signature
563 if (((vbe_info_block.VbeSignature[0] == 'V') &&
564 (vbe_info_block.VbeSignature[1] == 'B') &&
565 (vbe_info_block.VbeSignature[2] == 'E') &&
566 (vbe_info_block.VbeSignature[3] == '2')) ||
568 ((vbe_info_block.VbeSignature[0] == 'V') &&
569 (vbe_info_block.VbeSignature[1] == 'E') &&
570 (vbe_info_block.VbeSignature[2] == 'S') &&
571 (vbe_info_block.VbeSignature[3] == 'A')) )
573 vbe2_info = 1;
574 #ifdef DEBUG
575 printf("VBE correct VESA/VBE2 signature found\n");
576 #endif
578 #endif
580 // VBE Signature
581 vbe_info_block.VbeSignature[0] = 'V';
582 vbe_info_block.VbeSignature[1] = 'E';
583 vbe_info_block.VbeSignature[2] = 'S';
584 vbe_info_block.VbeSignature[3] = 'A';
586 // VBE Version supported
587 vbe_info_block.VbeVersion = 0x0200;
589 // OEM String
590 vbe_info_block.OemStringPtr_Seg = 0xc000;
591 vbe_info_block.OemStringPtr_Off = &vbebios_copyright;
593 // Capabilities
594 vbe_info_block.Capabilities[0] = VBE_CAPABILITY_8BIT_DAC;
595 vbe_info_block.Capabilities[1] = 0;
596 vbe_info_block.Capabilities[2] = 0;
597 vbe_info_block.Capabilities[3] = 0;
599 #ifdef DYN_LIST
600 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
601 vbe_info_block.VideoModePtr_Seg= ES ;
602 vbe_info_block.VideoModePtr_Off= DI + 34;
603 #else
604 // VBE Video Mode Pointer (staticly in rom)
605 vbe_info_block.VideoModePtr_Seg = 0xc000;
606 vbe_info_block.VideoModePtr_Off = &vbebios_mode_list;
607 #endif
609 // VBE Total Memory (in 64b blocks)
610 vbe_info_block.TotalMemory = VBE_TOTAL_VIDEO_MEMORY_DIV_64K;
612 if (vbe2_info)
614 // OEM Stuff
615 vbe_info_block.OemSoftwareRev = VBE_OEM_SOFTWARE_REV;
616 vbe_info_block.OemVendorNamePtr_Seg = 0xc000;
617 vbe_info_block.OemVendorNamePtr_Off = &vbebios_vendor_name;
618 vbe_info_block.OemProductNamePtr_Seg = 0xc000;
619 vbe_info_block.OemProductNamePtr_Off = &vbebios_product_name;
620 vbe_info_block.OemProductRevPtr_Seg = 0xc000;
621 vbe_info_block.OemProductRevPtr_Off = &vbebios_product_revision;
623 // copy updates in vbe_info_block back
624 memcpyb(ES, DI, ss, &vbe_info_block, sizeof(vbe_info_block));
626 else
628 // copy updates in vbe_info_block back (VBE 1.x compatibility)
629 memcpyb(ES, DI, ss, &vbe_info_block, 256);
632 #ifdef DYN_LIST
635 if (cur_info->info.BitsPerPixel <= dispi_get_max_bpp()) {
636 #ifdef DEBUG
637 printf("VBE found mode %x => %x\n", cur_info->mode,cur_mode);
638 #endif
639 write_word(ES, DI + cur_ptr, cur_info->mode);
640 cur_mode++;
641 cur_ptr+=2;
643 cur_info++;
644 } while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST);
646 // Add vesa mode list terminator
647 write_word(ES, DI + cur_ptr, cur_info->mode);
648 #endif
650 result = 0x4f;
652 write_word(ss, AX, result);
656 /** Function 01h - Return VBE Mode Information
658 * Input:
659 * AX = 4F01h
660 * CX = Mode Number
661 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
662 * Output:
663 * AX = VBE Return Status
666 void vbe_biosfn_return_mode_information(AX, CX, ES, DI)
667 Bit16u *AX;Bit16u CX; Bit16u ES;Bit16u DI;
669 Bit16u result=0x0100;
670 Bit16u ss=get_SS();
671 ModeInfoBlock info;
672 ModeInfoListItem *cur_info;
673 Boolean using_lfb;
675 #ifdef DEBUG
676 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
677 #endif
679 using_lfb=((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
681 CX = (CX & 0x1ff);
683 cur_info = mode_info_find_mode(CX, using_lfb, &cur_info);
685 if (cur_info != 0)
687 #ifdef DEBUG
688 printf("VBE found mode %x\n",CX);
689 #endif
690 memsetb(ss, &info, 0, sizeof(ModeInfoBlock));
691 memcpyb(ss, &info, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
692 if (info.WinAAttributes & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
693 info.WinFuncPtr = 0xC0000000UL;
694 *(Bit16u *)&(info.WinFuncPtr) = (Bit16u)(dispi_set_bank_farcall);
697 result = 0x4f;
699 else
701 #ifdef DEBUG
702 printf("VBE *NOT* found mode %x\n",CX);
703 #endif
704 result = 0x100;
707 if (result == 0x4f)
709 // copy updates in mode_info_block back
710 memcpyb(ES, DI, ss, &info, sizeof(info));
713 write_word(ss, AX, result);
716 /** Function 02h - Set VBE Mode
718 * Input:
719 * AX = 4F02h
720 * BX = Desired Mode to set
721 * ES:DI = Pointer to CRTCInfoBlock structure
722 * Output:
723 * AX = VBE Return Status
726 void vbe_biosfn_set_mode(AX, BX, ES, DI)
727 Bit16u *AX;Bit16u BX; Bit16u ES;Bit16u DI;
729 Bit16u ss = get_SS();
730 Bit16u result;
731 ModeInfoListItem *cur_info;
732 Boolean using_lfb;
733 Bit8u no_clear;
734 Bit8u lfb_flag;
736 using_lfb=((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
737 lfb_flag=using_lfb?VBE_DISPI_LFB_ENABLED:0;
738 no_clear=((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY)?VBE_DISPI_NOCLEARMEM:0;
740 BX = (BX & 0x1ff);
742 //result=read_word(ss,AX);
744 // check for non vesa mode
745 if (BX<VBE_MODE_VESA_DEFINED)
747 Bit8u mode;
749 dispi_set_enable(VBE_DISPI_DISABLED);
750 // call the vgabios in order to set the video mode
751 // this allows for going back to textmode with a VBE call (some applications expect that to work)
753 mode=(BX & 0xff);
754 biosfn_set_video_mode(mode);
755 result = 0x4f;
758 cur_info = mode_info_find_mode(BX, using_lfb, &cur_info);
760 if (cur_info != 0)
762 #ifdef DEBUG
763 printf("VBE found mode %x, setting:\n", BX);
764 printf("\txres%x yres%x bpp%x\n",
765 cur_info->info.XResolution,
766 cur_info->info.YResolution,
767 cur_info->info.BitsPerPixel);
768 #endif
770 // first disable current mode (when switching between vesa modi)
771 dispi_set_enable(VBE_DISPI_DISABLED);
773 if (cur_info->mode == VBE_VESA_MODE_800X600X4)
775 biosfn_set_video_mode(0x6a);
778 dispi_set_bpp(cur_info->info.BitsPerPixel);
779 dispi_set_xres(cur_info->info.XResolution);
780 dispi_set_yres(cur_info->info.YResolution);
781 dispi_set_bank(0);
782 dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag);
784 write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX);
785 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear));
787 result = 0x4f;
789 else
791 #ifdef DEBUG
792 printf("VBE *NOT* found mode %x\n" , BX);
793 #endif
794 result = 0x100;
796 // FIXME: redirect non VBE modi to normal VGA bios operation
797 // (switch back to VGA mode
798 if (BX == 3)
799 result = 0x4f;
802 write_word(ss, AX, result);
805 /** Function 03h - Return Current VBE Mode
807 * Input:
808 * AX = 4F03h
809 * Output:
810 * AX = VBE Return Status
811 * BX = Current VBE Mode
814 ASM_START
815 vbe_biosfn_return_current_mode:
816 push ds
817 mov ax, # BIOSMEM_SEG
818 mov ds, ax
819 call dispi_get_enable
820 and ax, # VBE_DISPI_ENABLED
821 jz no_vbe_mode
822 mov bx, # BIOSMEM_VBE_MODE
823 mov ax, [bx]
824 mov bx, ax
825 jnz vbe_03_ok
826 no_vbe_mode:
827 mov bx, # BIOSMEM_CURRENT_MODE
828 mov al, [bx]
829 mov bl, al
830 xor bh, bh
831 vbe_03_ok:
832 mov ax, #0x004f
833 pop ds
835 ASM_END
838 /** Function 04h - Save/Restore State
840 * Input:
841 * AX = 4F04h
842 * DL = 00h Return Save/Restore State buffer size
843 * 01h Save State
844 * 02h Restore State
845 * CX = Requested states
846 * ES:BX = Pointer to buffer (if DL <> 00h)
847 * Output:
848 * AX = VBE Return Status
849 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
852 void vbe_biosfn_save_restore_state(AX, DL, CX, ES, BX)
857 /** Function 05h - Display Window Control
859 * Input:
860 * AX = 4F05h
861 * (16-bit) BH = 00h Set memory window
862 * = 01h Get memory window
863 * BL = Window number
864 * = 00h Window A
865 * = 01h Window B
866 * DX = Window number in video memory in window
867 * granularity units (Set Memory Window only)
868 * Note:
869 * If this function is called while in a linear frame buffer mode,
870 * this function must fail with completion code AH=03h
872 * Output:
873 * AX = VBE Return Status
874 * DX = Window number in window granularity units
875 * (Get Memory Window only)
877 ASM_START
878 vbe_biosfn_display_window_control:
879 cmp bl, #0x00
880 jne vbe_05_failed
881 cmp bh, #0x01
882 je get_display_window
883 jb set_display_window
884 mov ax, #0x0100
886 set_display_window:
887 mov ax, dx
888 call _dispi_set_bank
889 call dispi_get_bank
890 cmp ax, dx
891 jne vbe_05_failed
892 mov ax, #0x004f
894 get_display_window:
895 call dispi_get_bank
896 mov dx, ax
897 mov ax, #0x004f
899 vbe_05_failed:
900 mov ax, #0x014f
902 ASM_END
905 /** Function 06h - Set/Get Logical Scan Line Length
907 * Input:
908 * AX = 4F06h
909 * BL = 00h Set Scan Line Length in Pixels
910 * = 01h Get Scan Line Length
911 * = 02h Set Scan Line Length in Bytes
912 * = 03h Get Maximum Scan Line Length
913 * CX = If BL=00h Desired Width in Pixels
914 * If BL=02h Desired Width in Bytes
915 * (Ignored for Get Functions)
917 * Output:
918 * AX = VBE Return Status
919 * BX = Bytes Per Scan Line
920 * CX = Actual Pixels Per Scan Line
921 * (truncated to nearest complete pixel)
922 * DX = Maximum Number of Scan Lines
924 ASM_START
925 vbe_biosfn_set_get_logical_scan_line_length:
926 mov ax, cx
927 cmp bl, #0x01
928 je get_logical_scan_line_length
929 cmp bl, #0x02
930 je set_logical_scan_line_bytes
931 jb set_logical_scan_line_pixels
932 mov ax, #0x0100
934 set_logical_scan_line_bytes:
935 push ax
936 call dispi_get_bpp
937 xor bh, bh
938 mov bl, ah
939 xor dx, dx
940 pop ax
941 div bx
942 set_logical_scan_line_pixels:
943 call dispi_set_virt_width
944 get_logical_scan_line_length:
945 call dispi_get_bpp
946 xor bh, bh
947 mov bl, ah
948 call dispi_get_virt_width
949 mov cx, ax
950 mul bx
951 mov bx, ax
952 call dispi_get_virt_height
953 mov dx, ax
954 mov ax, #0x004f
956 ASM_END
959 /** Function 07h - Set/Get Display Start
961 * Input(16-bit):
962 * AX = 4F07h
963 * BH = 00h Reserved and must be 00h
964 * BL = 00h Set Display Start
965 * = 01h Get Display Start
966 * = 02h Schedule Display Start (Alternate)
967 * = 03h Schedule Stereoscopic Display Start
968 * = 04h Get Scheduled Display Start Status
969 * = 05h Enable Stereoscopic Mode
970 * = 06h Disable Stereoscopic Mode
971 * = 80h Set Display Start during Vertical Retrace
972 * = 82h Set Display Start during Vertical Retrace (Alternate)
973 * = 83h Set Stereoscopic Display Start during Vertical Retrace
974 * ECX = If BL=02h/82h Display Start Address in bytes
975 * If BL=03h/83h Left Image Start Address in bytes
976 * EDX = If BL=03h/83h Right Image Start Address in bytes
977 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
978 * DX = If BL=00h/80h First Displayed Scan Line
980 * Output:
981 * AX = VBE Return Status
982 * BH = If BL=01h Reserved and will be 0
983 * CX = If BL=01h First Displayed Pixel In Scan Line
984 * If BL=04h 0 if flip has not occurred, not 0 if it has
985 * DX = If BL=01h First Displayed Scan Line
987 * Input(32-bit):
988 * BH = 00h Reserved and must be 00h
989 * BL = 00h Set Display Start
990 * = 80h Set Display Start during Vertical Retrace
991 * CX = Bits 0-15 of display start address
992 * DX = Bits 16-31 of display start address
993 * ES = Selector for memory mapped registers
995 ASM_START
996 vbe_biosfn_set_get_display_start:
997 cmp bl, #0x80
998 je set_display_start
999 cmp bl, #0x01
1000 je get_display_start
1001 jb set_display_start
1002 mov ax, #0x0100
1004 set_display_start:
1005 mov ax, cx
1006 call dispi_set_x_offset
1007 mov ax, dx
1008 call dispi_set_y_offset
1009 mov ax, #0x004f
1011 get_display_start:
1012 call dispi_get_x_offset
1013 mov cx, ax
1014 call dispi_get_y_offset
1015 mov dx, ax
1016 xor bh, bh
1017 mov ax, #0x004f
1019 ASM_END
1022 /** Function 08h - Set/Get Dac Palette Format
1024 * Input:
1025 * AX = 4F08h
1026 * BL = 00h set DAC palette width
1027 * = 01h get DAC palette width
1028 * BH = If BL=00h: desired number of bits per primary color
1029 * Output:
1030 * AX = VBE Return Status
1031 * BH = current number of bits per primary color (06h = standard VGA)
1033 ASM_START
1034 vbe_biosfn_set_get_dac_palette_format:
1035 cmp bl, #0x01
1036 je get_dac_palette_format
1037 jb set_dac_palette_format
1038 mov ax, #0x0100
1040 set_dac_palette_format:
1041 call dispi_get_enable
1042 cmp bh, #0x06
1043 je set_normal_dac
1044 cmp bh, #0x08
1045 jne vbe_08_unsupported
1046 or ax, # VBE_DISPI_8BIT_DAC
1047 jnz set_dac_mode
1048 set_normal_dac:
1049 and ax, #~ VBE_DISPI_8BIT_DAC
1050 set_dac_mode:
1051 call _dispi_set_enable
1052 get_dac_palette_format:
1053 mov bh, #0x06
1054 call dispi_get_enable
1055 and ax, # VBE_DISPI_8BIT_DAC
1056 jz vbe_08_ok
1057 mov bh, #0x08
1058 vbe_08_ok:
1059 mov ax, #0x004f
1061 vbe_08_unsupported:
1062 mov ax, #0x014f
1064 ASM_END
1067 /** Function 09h - Set/Get Palette Data
1069 * Input:
1070 * AX = 4F09h
1071 * Output:
1072 * AX = VBE Return Status
1074 * FIXME: incomplete API description, Input & Output
1076 void vbe_biosfn_set_get_palette_data(AX)
1080 /** Function 0Ah - Return VBE Protected Mode Interface
1081 * Input: AX = 4F0Ah VBE 2.0 Protected Mode Interface
1082 * BL = 00h Return protected mode table
1085 * Output: AX = Status
1086 * ES = Real Mode Segment of Table
1087 * DI = Offset of Table
1088 * CX = Length of Table including protected mode code
1089 * (for copying purposes)
1091 ASM_START
1092 vbe_biosfn_return_protected_mode_interface:
1093 test bx, bx
1094 jnz _fail
1095 mov di, #0xc000
1096 mov es, di
1097 mov di, # vesa_pm_start
1098 mov cx, # vesa_pm_end
1099 sub cx, di
1100 mov ax, #0x004f
1102 _fail:
1103 mov ax, #0x014f
1105 ASM_END