- init 4bpp VBE modes by a temporary switch to VGA mode 0x6A
[vgabios.git] / vbe.c
blob146200922911a8d5d2cc26d849cdf822c3e5bec4
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
34 // disable VESA/VBE2 check in vbe info
35 //#define VBE2_NO_VESA_CHECK
38 #include "vbe.h"
39 #include "vbetables.h"
41 #define VBE_TOTAL_VIDEO_MEMORY_DIV_64K (VBE_DISPI_TOTAL_VIDEO_MEMORY_MB*1024/64)
43 // The current OEM Software Revision of this VBE Bios
44 #define VBE_OEM_SOFTWARE_REV 0x0002;
46 extern char vbebios_copyright;
47 extern char vbebios_vendor_name;
48 extern char vbebios_product_name;
49 extern char vbebios_product_revision;
51 ASM_START
52 // FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
53 _vbebios_copyright:
54 .ascii "Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/"
55 .byte 0x00
57 _vbebios_vendor_name:
58 .ascii "Bochs/Plex86 Developers"
59 .byte 0x00
61 _vbebios_product_name:
62 .ascii "Bochs/Plex86 VBE Adapter"
63 .byte 0x00
65 _vbebios_product_revision:
66 .ascii "$Id$"
67 .byte 0x00
69 _vbebios_info_string:
70 .ascii "Bochs VBE Display Adapter enabled"
71 .byte 0x0a,0x0d
72 .byte 0x0a,0x0d
73 .byte 0x00
75 _no_vbebios_info_string:
76 .ascii "NO Bochs VBE Support available!"
77 .byte 0x0a,0x0d
78 .byte 0x0a,0x0d
79 .byte 0x00
81 #if defined(USE_BX_INFO) || defined(DEBUG)
82 msg_vbe_init:
83 .ascii "VBE Bios $Id$"
84 .byte 0x0a,0x0d, 0x00
85 #endif
87 .align 2
88 vesa_pm_start:
89 dw vesa_pm_set_window - vesa_pm_start
90 dw vesa_pm_set_display_start - vesa_pm_start
91 dw vesa_pm_unimplemented - vesa_pm_start
92 dw vesa_pm_io_ports_table - vesa_pm_start
93 vesa_pm_io_ports_table:
94 dw VBE_DISPI_IOPORT_INDEX
95 dw VBE_DISPI_IOPORT_INDEX + 1
96 dw VBE_DISPI_IOPORT_DATA
97 dw VBE_DISPI_IOPORT_DATA + 1
98 dw 0xffff
99 dw 0xffff
101 USE32
102 vesa_pm_set_window:
103 cmp bx, #0x00
104 je vesa_pm_set_display_window1
105 mov ax, #0x0100
107 vesa_pm_set_display_window1:
108 mov ax, dx
109 push dx
110 push ax
111 mov dx, # VBE_DISPI_IOPORT_INDEX
112 mov ax, # VBE_DISPI_INDEX_BANK
113 out dx, ax
114 pop ax
115 mov dx, # VBE_DISPI_IOPORT_DATA
116 out dx, ax
117 in ax, dx
118 pop dx
119 cmp dx, ax
120 jne illegal_window
121 mov ax, #0x004f
123 illegal_window:
124 mov ax, #0x014f
127 vesa_pm_set_display_start:
128 cmp bl, #0x80
129 je vesa_pm_set_display_start1
130 cmp bl, #0x00
131 je vesa_pm_set_display_start1
132 mov ax, #0x0100
134 vesa_pm_set_display_start1:
135 ; convert offset to (X, Y) coordinate
136 ; (would be simpler to change Bochs VBE API...)
137 push eax
138 push ecx
139 push edx
140 push esi
141 push edi
142 shl edx, #16
143 and ecx, #0xffff
144 or ecx, edx
145 shl ecx, #2
146 mov eax, ecx
148 push eax
149 mov dx, # VBE_DISPI_IOPORT_INDEX
150 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
151 out dx, ax
152 mov dx, # VBE_DISPI_IOPORT_DATA
153 in ax, dx
154 movzx ecx, ax
156 mov dx, # VBE_DISPI_IOPORT_INDEX
157 mov ax, # VBE_DISPI_INDEX_BPP
158 out dx, ax
159 mov dx, # VBE_DISPI_IOPORT_DATA
160 in ax, dx
161 movzx esi, ax
162 pop eax
164 cmp esi, #4
165 jz bpp4_mode
166 add esi, #7
167 shr esi, #3
168 imul ecx, esi
169 xor edx, edx
170 div ecx
171 mov edi, eax
172 mov eax, edx
173 xor edx, edx
174 div esi
175 jmp set_xy_regs
177 bpp4_mode:
178 shr ecx, #1
179 xor edx, edx
180 div ecx
181 mov edi, eax
182 mov eax, edx
183 shl eax, #1
185 set_xy_regs:
186 push dx
187 push ax
188 mov dx, # VBE_DISPI_IOPORT_INDEX
189 mov ax, # VBE_DISPI_INDEX_X_OFFSET
190 out dx, ax
191 pop ax
192 mov dx, # VBE_DISPI_IOPORT_DATA
193 out dx, ax
194 pop dx
196 mov ax, di
197 push dx
198 push ax
199 mov dx, # VBE_DISPI_IOPORT_INDEX
200 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
201 out dx, ax
202 pop ax
203 mov dx, # VBE_DISPI_IOPORT_DATA
204 out dx, ax
205 pop dx
207 pop edi
208 pop esi
209 pop edx
210 pop ecx
211 pop eax
212 mov ax, #0x004f
215 vesa_pm_unimplemented:
216 mov ax, #0x014f
218 USE16
219 vesa_pm_end:
221 ; DISPI ioport functions
223 dispi_get_id:
224 push dx
225 mov dx, # VBE_DISPI_IOPORT_INDEX
226 mov ax, # VBE_DISPI_INDEX_ID
227 out dx, ax
228 mov dx, # VBE_DISPI_IOPORT_DATA
229 in ax, dx
230 pop dx
233 dispi_set_id:
234 push dx
235 push ax
236 mov dx, # VBE_DISPI_IOPORT_INDEX
237 mov ax, # VBE_DISPI_INDEX_ID
238 out dx, ax
239 pop ax
240 mov dx, # VBE_DISPI_IOPORT_DATA
241 out dx, ax
242 pop dx
244 ASM_END
246 static void dispi_set_xres(xres)
247 Bit16u xres;
249 ASM_START
250 push bp
251 mov bp, sp
252 push ax
253 push dx
255 mov dx, # VBE_DISPI_IOPORT_INDEX
256 mov ax, # VBE_DISPI_INDEX_XRES
257 out dx, ax
258 mov dx, # VBE_DISPI_IOPORT_DATA
259 mov ax, 4[bp] ; xres
260 out dx, ax
262 pop dx
263 pop ax
264 pop bp
265 ASM_END
268 static void dispi_set_yres(yres)
269 Bit16u yres;
271 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_YRES);
272 outw(VBE_DISPI_IOPORT_DATA,yres);
275 static void dispi_set_bpp(bpp)
276 Bit16u bpp;
278 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_BPP);
279 outw(VBE_DISPI_IOPORT_DATA,bpp);
282 ASM_START
283 ; AL = bits per pixel / AH = bytes per pixel
284 dispi_get_bpp:
285 push dx
286 mov dx, # VBE_DISPI_IOPORT_INDEX
287 mov ax, # VBE_DISPI_INDEX_BPP
288 out dx, ax
289 mov dx, # VBE_DISPI_IOPORT_DATA
290 in ax, dx
291 mov ah, al
292 shr ah, 3
293 test al, #0x07
294 jz get_bpp_noinc
295 inc ah
296 get_bpp_noinc:
297 pop dx
300 ; get display capabilities
302 _dispi_get_max_xres:
303 push dx
304 push bx
305 call dispi_get_enable
306 mov bx, ax
307 or ax, # VBE_DISPI_GETCAPS
308 call _dispi_set_enable
309 mov dx, # VBE_DISPI_IOPORT_INDEX
310 mov ax, # VBE_DISPI_INDEX_XRES
311 out dx, ax
312 mov dx, # VBE_DISPI_IOPORT_DATA
313 in ax, dx
314 push ax
315 mov ax, bx
316 call _dispi_set_enable
317 pop ax
318 pop bx
319 pop dx
322 _dispi_get_max_bpp:
323 push dx
324 push bx
325 call dispi_get_enable
326 mov bx, ax
327 or ax, # VBE_DISPI_GETCAPS
328 call _dispi_set_enable
329 mov dx, # VBE_DISPI_IOPORT_INDEX
330 mov ax, # VBE_DISPI_INDEX_BPP
331 out dx, ax
332 mov dx, # VBE_DISPI_IOPORT_DATA
333 in ax, dx
334 push ax
335 mov ax, bx
336 call _dispi_set_enable
337 pop ax
338 pop bx
339 pop dx
342 _dispi_set_enable:
343 push dx
344 push ax
345 mov dx, # VBE_DISPI_IOPORT_INDEX
346 mov ax, # VBE_DISPI_INDEX_ENABLE
347 out dx, ax
348 pop ax
349 mov dx, # VBE_DISPI_IOPORT_DATA
350 out dx, ax
351 pop dx
354 dispi_get_enable:
355 push dx
356 mov dx, # VBE_DISPI_IOPORT_INDEX
357 mov ax, # VBE_DISPI_INDEX_ENABLE
358 out dx, ax
359 mov dx, # VBE_DISPI_IOPORT_DATA
360 in ax, dx
361 pop dx
364 _dispi_set_bank:
365 push dx
366 push ax
367 mov dx, # VBE_DISPI_IOPORT_INDEX
368 mov ax, # VBE_DISPI_INDEX_BANK
369 out dx, ax
370 pop ax
371 mov dx, # VBE_DISPI_IOPORT_DATA
372 out dx, ax
373 pop dx
376 dispi_get_bank:
377 push dx
378 mov dx, # VBE_DISPI_IOPORT_INDEX
379 mov ax, # VBE_DISPI_INDEX_BANK
380 out dx, ax
381 mov dx, # VBE_DISPI_IOPORT_DATA
382 in ax, dx
383 pop dx
385 ASM_END
387 static void dispi_set_bank_farcall()
389 ASM_START
390 cmp bx,#0x0100
391 je dispi_set_bank_farcall_get
392 or bx,bx
393 jnz dispi_set_bank_farcall_error
394 mov ax,dx
395 push dx
396 push ax
397 mov ax,# VBE_DISPI_INDEX_BANK
398 mov dx,# VBE_DISPI_IOPORT_INDEX
399 out dx,ax
400 pop ax
401 mov dx,# VBE_DISPI_IOPORT_DATA
402 out dx,ax
403 in ax,dx
404 pop dx
405 cmp dx,ax
406 jne dispi_set_bank_farcall_error
407 mov ax, #0x004f
408 retf
409 dispi_set_bank_farcall_get:
410 mov ax,# VBE_DISPI_INDEX_BANK
411 mov dx,# VBE_DISPI_IOPORT_INDEX
412 out dx,ax
413 mov dx,# VBE_DISPI_IOPORT_DATA
414 in ax,dx
415 mov dx,ax
416 retf
417 dispi_set_bank_farcall_error:
418 mov ax,#0x014F
419 retf
420 ASM_END
423 ASM_START
424 dispi_set_x_offset:
425 push dx
426 push ax
427 mov dx, # VBE_DISPI_IOPORT_INDEX
428 mov ax, # VBE_DISPI_INDEX_X_OFFSET
429 out dx, ax
430 pop ax
431 mov dx, # VBE_DISPI_IOPORT_DATA
432 out dx, ax
433 pop dx
436 dispi_get_x_offset:
437 push dx
438 mov dx, # VBE_DISPI_IOPORT_INDEX
439 mov ax, # VBE_DISPI_INDEX_X_OFFSET
440 out dx, ax
441 mov dx, # VBE_DISPI_IOPORT_DATA
442 in ax, dx
443 pop dx
446 dispi_set_y_offset:
447 push dx
448 push ax
449 mov dx, # VBE_DISPI_IOPORT_INDEX
450 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
451 out dx, ax
452 pop ax
453 mov dx, # VBE_DISPI_IOPORT_DATA
454 out dx, ax
455 pop dx
458 dispi_get_y_offset:
459 push dx
460 mov dx, # VBE_DISPI_IOPORT_INDEX
461 mov ax, # VBE_DISPI_INDEX_Y_OFFSET
462 out dx, ax
463 mov dx, # VBE_DISPI_IOPORT_DATA
464 in ax, dx
465 pop dx
468 vga_set_virt_width:
469 push ax
470 push bx
471 push dx
472 mov bx, ax
473 call dispi_get_bpp
474 cmp al, #0x04
475 ja set_width_svga
476 shr bx, #2
477 set_width_svga:
478 shr bx, #2
479 mov dx, #0x03d4
480 mov ah, bl
481 mov al, #0x13
482 out dx, ax
483 pop dx
484 pop bx
485 pop ax
488 dispi_set_virt_width:
489 call vga_set_virt_width
490 push dx
491 push ax
492 mov dx, # VBE_DISPI_IOPORT_INDEX
493 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
494 out dx, ax
495 pop ax
496 mov dx, # VBE_DISPI_IOPORT_DATA
497 out dx, ax
498 pop dx
501 dispi_get_virt_width:
502 push dx
503 mov dx, # VBE_DISPI_IOPORT_INDEX
504 mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
505 out dx, ax
506 mov dx, # VBE_DISPI_IOPORT_DATA
507 in ax, dx
508 pop dx
511 dispi_get_virt_height:
512 push dx
513 mov dx, # VBE_DISPI_IOPORT_INDEX
514 mov ax, # VBE_DISPI_INDEX_VIRT_HEIGHT
515 out dx, ax
516 mov dx, # VBE_DISPI_IOPORT_DATA
517 in ax, dx
518 pop dx
521 _vga_compat_setup:
522 push ax
523 push dx
525 ; set CRT X resolution
526 mov dx, # VBE_DISPI_IOPORT_INDEX
527 mov ax, # VBE_DISPI_INDEX_XRES
528 out dx, ax
529 mov dx, # VBE_DISPI_IOPORT_DATA
530 in ax, dx
531 push ax
532 mov dx, #0x03d4
533 mov ax, #0x0011
534 out dx, ax
535 mov dx, #0x03d4
536 pop ax
537 push ax
538 shr ax, #3
539 dec ax
540 mov ah, al
541 mov al, #0x01
542 out dx, ax
543 pop ax
544 call vga_set_virt_width
546 ; set CRT Y resolution
547 mov dx, # VBE_DISPI_IOPORT_INDEX
548 mov ax, # VBE_DISPI_INDEX_YRES
549 out dx, ax
550 mov dx, # VBE_DISPI_IOPORT_DATA
551 in ax, dx
552 dec ax
553 push ax
554 mov dx, #0x03d4
555 mov ah, al
556 mov al, #0x12
557 out dx, ax
558 pop ax
559 mov al, #0x07
560 out dx, al
561 inc dx
562 in al, dx
563 and al, #0xbd
564 test ah, #0x01
565 jz bit8_clear
566 or al, #0x02
567 bit8_clear:
568 test ah, #0x02
569 jz bit9_clear
570 or al, #0x40
571 bit9_clear:
572 out dx, al
574 ; other settings
575 mov dx, #0x03d4
576 mov ax, #0x0009
577 out dx, ax
578 mov dx, # VGAREG_ACTL_RESET
579 in al, dx
580 mov dx, # VGAREG_ACTL_ADDRESS
581 mov al, #0x10
582 out dx, al
583 mov dx, # VGAREG_ACTL_READ_DATA
584 in al, dx
585 or al, #0x01
586 mov dx, # VGAREG_ACTL_ADDRESS
587 out dx, al
588 mov al, #0x20
589 out dx, al
590 mov dx, # VGAREG_GRDC_ADDRESS
591 mov ax, #0x0506
592 out dx, ax
593 mov dx, # VGAREG_SEQU_ADDRESS
594 mov ax, #0x0f02
595 out dx, ax
597 ; settings for >= 8bpp
598 mov dx, # VBE_DISPI_IOPORT_INDEX
599 mov ax, # VBE_DISPI_INDEX_BPP
600 out dx, ax
601 mov dx, # VBE_DISPI_IOPORT_DATA
602 in ax, dx
603 cmp al, #0x08
604 jb vga_compat_end
605 mov dx, # VGAREG_ACTL_RESET
606 in al, dx
607 mov dx, # VGAREG_ACTL_ADDRESS
608 mov al, #0x10
609 out dx, al
610 mov dx, # VGAREG_ACTL_READ_DATA
611 in al, dx
612 or al, #0x40
613 mov dx, # VGAREG_ACTL_ADDRESS
614 out dx, al
615 mov al, #0x20
616 out dx, al
617 mov dx, # VGAREG_SEQU_ADDRESS
618 mov al, #0x04
619 out dx, al
620 mov dx, # VGAREG_SEQU_DATA
621 in al, dx
622 or al, #0x08
623 out dx, al
625 vga_compat_end:
626 pop dx
627 pop ax
628 ASM_END
631 // ModeInfo helper function
632 static ModeInfoListItem* mode_info_find_mode(mode, using_lfb)
633 Bit16u mode; Boolean using_lfb;
635 ModeInfoListItem *cur_info=&mode_info_list;
637 while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST)
639 if (cur_info->mode == mode)
641 if (!using_lfb)
643 return cur_info;
645 else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
647 return cur_info;
649 else
651 cur_info++;
654 else
656 cur_info++;
660 return 0;
663 ASM_START
665 ; Has VBE display - Returns true if VBE display detected
667 _vbe_has_vbe_display:
668 push ds
669 push bx
670 mov ax, # BIOSMEM_SEG
671 mov ds, ax
672 mov bx, # BIOSMEM_VBE_FLAG
673 mov al, [bx]
674 and al, #0x01
675 xor ah, ah
676 pop bx
677 pop ds
680 ; VBE Init - Initialise the Vesa Bios Extension Code
681 ; This function does a sanity check on the host side display code interface.
683 vbe_init:
684 mov ax, # VBE_DISPI_ID0
685 call dispi_set_id
686 call dispi_get_id
687 cmp ax, # VBE_DISPI_ID0
688 jne no_vbe_interface
689 push ds
690 push bx
691 mov ax, # BIOSMEM_SEG
692 mov ds, ax
693 mov bx, # BIOSMEM_VBE_FLAG
694 mov al, #0x01
695 mov [bx], al
696 pop bx
697 pop ds
698 mov ax, # VBE_DISPI_ID4
699 call dispi_set_id
700 no_vbe_interface:
701 #if defined(USE_BX_INFO) || defined(DEBUG)
702 mov bx, #msg_vbe_init
703 push bx
704 call _printf
705 inc sp
706 inc sp
707 #endif
710 ; VBE Display Info - Display information on screen about the VBE
712 vbe_display_info:
713 call _vbe_has_vbe_display
714 test ax, ax
715 jz no_vbe_flag
716 mov ax, #0xc000
717 mov ds, ax
718 mov si, #_vbebios_info_string
719 jmp _display_string
720 no_vbe_flag:
721 mov ax, #0xc000
722 mov ds, ax
723 mov si, #_no_vbebios_info_string
724 jmp _display_string
725 ASM_END
727 /** Function 00h - Return VBE Controller Information
729 * Input:
730 * AX = 4F00h
731 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
732 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
733 * the info block is 512 bytes in size)
734 * Output:
735 * AX = VBE Return Status
738 void vbe_biosfn_return_controller_information(AX, ES, DI)
739 Bit16u *AX;Bit16u ES;Bit16u DI;
741 Bit16u ss=get_SS();
742 VbeInfoBlock vbe_info_block;
743 Bit16u status;
744 Bit16u result;
745 Bit16u vbe2_info;
746 Bit16u cur_mode=0;
747 Bit16u cur_ptr=34;
748 ModeInfoListItem *cur_info=&mode_info_list;
750 status = read_word(ss, AX);
752 #ifdef DEBUG
753 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);
754 #endif
756 vbe2_info = 0;
757 #ifdef VBE2_NO_VESA_CHECK
758 #else
759 // get vbe_info_block into local variable
760 memcpyb(ss, &vbe_info_block, ES, DI, sizeof(vbe_info_block));
762 // check for VBE2 signature
763 if (((vbe_info_block.VbeSignature[0] == 'V') &&
764 (vbe_info_block.VbeSignature[1] == 'B') &&
765 (vbe_info_block.VbeSignature[2] == 'E') &&
766 (vbe_info_block.VbeSignature[3] == '2')) ||
768 ((vbe_info_block.VbeSignature[0] == 'V') &&
769 (vbe_info_block.VbeSignature[1] == 'E') &&
770 (vbe_info_block.VbeSignature[2] == 'S') &&
771 (vbe_info_block.VbeSignature[3] == 'A')) )
773 vbe2_info = 1;
774 #ifdef DEBUG
775 printf("VBE correct VESA/VBE2 signature found\n");
776 #endif
778 #endif
780 // VBE Signature
781 vbe_info_block.VbeSignature[0] = 'V';
782 vbe_info_block.VbeSignature[1] = 'E';
783 vbe_info_block.VbeSignature[2] = 'S';
784 vbe_info_block.VbeSignature[3] = 'A';
786 // VBE Version supported
787 vbe_info_block.VbeVersion = 0x0200;
789 // OEM String
790 vbe_info_block.OemStringPtr_Seg = 0xc000;
791 vbe_info_block.OemStringPtr_Off = &vbebios_copyright;
793 // Capabilities
794 vbe_info_block.Capabilities[0] = VBE_CAPABILITY_8BIT_DAC;
795 vbe_info_block.Capabilities[1] = 0;
796 vbe_info_block.Capabilities[2] = 0;
797 vbe_info_block.Capabilities[3] = 0;
799 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
800 vbe_info_block.VideoModePtr_Seg= ES ;
801 vbe_info_block.VideoModePtr_Off= DI + 34;
803 // VBE Total Memory (in 64b blocks)
804 vbe_info_block.TotalMemory = VBE_TOTAL_VIDEO_MEMORY_DIV_64K;
806 if (vbe2_info)
808 // OEM Stuff
809 vbe_info_block.OemSoftwareRev = VBE_OEM_SOFTWARE_REV;
810 vbe_info_block.OemVendorNamePtr_Seg = 0xc000;
811 vbe_info_block.OemVendorNamePtr_Off = &vbebios_vendor_name;
812 vbe_info_block.OemProductNamePtr_Seg = 0xc000;
813 vbe_info_block.OemProductNamePtr_Off = &vbebios_product_name;
814 vbe_info_block.OemProductRevPtr_Seg = 0xc000;
815 vbe_info_block.OemProductRevPtr_Off = &vbebios_product_revision;
817 // copy updates in vbe_info_block back
818 memcpyb(ES, DI, ss, &vbe_info_block, sizeof(vbe_info_block));
820 else
822 // copy updates in vbe_info_block back (VBE 1.x compatibility)
823 memcpyb(ES, DI, ss, &vbe_info_block, 256);
828 if ((cur_info->info.XResolution <= dispi_get_max_xres()) &&
829 (cur_info->info.BitsPerPixel <= dispi_get_max_bpp())) {
830 #ifdef DEBUG
831 printf("VBE found mode %x => %x\n", cur_info->mode,cur_mode);
832 #endif
833 write_word(ES, DI + cur_ptr, cur_info->mode);
834 cur_mode++;
835 cur_ptr+=2;
837 cur_info++;
838 } while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST);
840 // Add vesa mode list terminator
841 write_word(ES, DI + cur_ptr, cur_info->mode);
843 result = 0x4f;
845 write_word(ss, AX, result);
849 /** Function 01h - Return VBE Mode Information
851 * Input:
852 * AX = 4F01h
853 * CX = Mode Number
854 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
855 * Output:
856 * AX = VBE Return Status
859 void vbe_biosfn_return_mode_information(AX, CX, ES, DI)
860 Bit16u *AX;Bit16u CX; Bit16u ES;Bit16u DI;
862 Bit16u result=0x0100;
863 Bit16u ss=get_SS();
864 ModeInfoBlock info;
865 ModeInfoListItem *cur_info;
866 Boolean using_lfb;
868 #ifdef DEBUG
869 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
870 #endif
872 using_lfb=((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
874 CX = (CX & 0x1ff);
876 cur_info = mode_info_find_mode(CX, using_lfb, &cur_info);
878 if (cur_info != 0)
880 #ifdef DEBUG
881 printf("VBE found mode %x\n",CX);
882 #endif
883 memsetb(ss, &info, 0, sizeof(ModeInfoBlock));
884 memcpyb(ss, &info, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
885 if (info.WinAAttributes & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
886 info.WinFuncPtr = 0xC0000000UL;
887 *(Bit16u *)&(info.WinFuncPtr) = (Bit16u)(dispi_set_bank_farcall);
890 result = 0x4f;
892 else
894 #ifdef DEBUG
895 printf("VBE *NOT* found mode %x\n",CX);
896 #endif
897 result = 0x100;
900 if (result == 0x4f)
902 // copy updates in mode_info_block back
903 memcpyb(ES, DI, ss, &info, sizeof(info));
906 write_word(ss, AX, result);
909 /** Function 02h - Set VBE Mode
911 * Input:
912 * AX = 4F02h
913 * BX = Desired Mode to set
914 * ES:DI = Pointer to CRTCInfoBlock structure
915 * Output:
916 * AX = VBE Return Status
919 void vbe_biosfn_set_mode(AX, BX, ES, DI)
920 Bit16u *AX;Bit16u BX; Bit16u ES;Bit16u DI;
922 Bit16u ss = get_SS();
923 Bit16u result;
924 ModeInfoListItem *cur_info;
925 Boolean using_lfb;
926 Bit8u no_clear;
927 Bit8u lfb_flag;
929 using_lfb=((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
930 lfb_flag=using_lfb?VBE_DISPI_LFB_ENABLED:0;
931 no_clear=((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY)?VBE_DISPI_NOCLEARMEM:0;
933 BX = (BX & 0x1ff);
935 //result=read_word(ss,AX);
937 // check for non vesa mode
938 if (BX<VBE_MODE_VESA_DEFINED)
940 Bit8u mode;
942 dispi_set_enable(VBE_DISPI_DISABLED);
943 // call the vgabios in order to set the video mode
944 // this allows for going back to textmode with a VBE call (some applications expect that to work)
946 mode=(BX & 0xff);
947 biosfn_set_video_mode(mode);
948 result = 0x4f;
951 cur_info = mode_info_find_mode(BX, using_lfb, &cur_info);
953 if (cur_info != 0)
955 #ifdef DEBUG
956 printf("VBE found mode %x, setting:\n", BX);
957 printf("\txres%x yres%x bpp%x\n",
958 cur_info->info.XResolution,
959 cur_info->info.YResolution,
960 cur_info->info.BitsPerPixel);
961 #endif
963 // first disable current mode (when switching between vesa modi)
964 dispi_set_enable(VBE_DISPI_DISABLED);
966 if (cur_info->info.BitsPerPixel == 4)
968 biosfn_set_video_mode(0x6a);
971 dispi_set_bpp(cur_info->info.BitsPerPixel);
972 dispi_set_xres(cur_info->info.XResolution);
973 dispi_set_yres(cur_info->info.YResolution);
974 dispi_set_bank(0);
975 dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag);
976 vga_compat_setup();
978 write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX);
979 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear));
981 result = 0x4f;
983 else
985 #ifdef DEBUG
986 printf("VBE *NOT* found mode %x\n" , BX);
987 #endif
988 result = 0x100;
990 // FIXME: redirect non VBE modi to normal VGA bios operation
991 // (switch back to VGA mode
992 if (BX == 3)
993 result = 0x4f;
996 write_word(ss, AX, result);
999 /** Function 03h - Return Current VBE Mode
1001 * Input:
1002 * AX = 4F03h
1003 * Output:
1004 * AX = VBE Return Status
1005 * BX = Current VBE Mode
1008 ASM_START
1009 vbe_biosfn_return_current_mode:
1010 push ds
1011 mov ax, # BIOSMEM_SEG
1012 mov ds, ax
1013 call dispi_get_enable
1014 and ax, # VBE_DISPI_ENABLED
1015 jz no_vbe_mode
1016 mov bx, # BIOSMEM_VBE_MODE
1017 mov ax, [bx]
1018 mov bx, ax
1019 jnz vbe_03_ok
1020 no_vbe_mode:
1021 mov bx, # BIOSMEM_CURRENT_MODE
1022 mov al, [bx]
1023 mov bl, al
1024 xor bh, bh
1025 vbe_03_ok:
1026 mov ax, #0x004f
1027 pop ds
1029 ASM_END
1032 Bit16u vbe_biosfn_read_video_state_size()
1034 return 9 * 2;
1037 void vbe_biosfn_save_video_state(ES, BX)
1038 Bit16u ES; Bit16u BX;
1040 Bit16u enable, i;
1042 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1043 enable = inw(VBE_DISPI_IOPORT_DATA);
1044 write_word(ES, BX, enable);
1045 BX += 2;
1046 if (!(enable & VBE_DISPI_ENABLED))
1047 return;
1048 for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
1049 if (i != VBE_DISPI_INDEX_ENABLE) {
1050 outw(VBE_DISPI_IOPORT_INDEX, i);
1051 write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA));
1052 BX += 2;
1058 void vbe_biosfn_restore_video_state(ES, BX)
1059 Bit16u ES; Bit16u BX;
1061 Bit16u enable, i;
1063 enable = read_word(ES, BX);
1064 BX += 2;
1066 if (!(enable & VBE_DISPI_ENABLED)) {
1067 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1068 outw(VBE_DISPI_IOPORT_DATA, enable);
1069 } else {
1070 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
1071 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1072 BX += 2;
1073 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
1074 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1075 BX += 2;
1076 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
1077 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1078 BX += 2;
1079 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1080 outw(VBE_DISPI_IOPORT_DATA, enable);
1082 for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
1083 outw(VBE_DISPI_IOPORT_INDEX, i);
1084 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1085 BX += 2;
1090 /** Function 04h - Save/Restore State
1092 * Input:
1093 * AX = 4F04h
1094 * DL = 00h Return Save/Restore State buffer size
1095 * 01h Save State
1096 * 02h Restore State
1097 * CX = Requested states
1098 * ES:BX = Pointer to buffer (if DL <> 00h)
1099 * Output:
1100 * AX = VBE Return Status
1101 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
1104 void vbe_biosfn_save_restore_state(AX, CX, DX, ES, BX)
1105 Bit16u *AX; Bit16u CX; Bit16u DX; Bit16u ES; Bit16u *BX;
1107 Bit16u ss=get_SS();
1108 Bit16u result, val;
1110 result = 0x4f;
1111 switch(GET_DL()) {
1112 case 0x00:
1113 val = biosfn_read_video_state_size2(CX);
1114 #ifdef DEBUG
1115 printf("VGA state size=%x\n", val);
1116 #endif
1117 if (CX & 8)
1118 val += vbe_biosfn_read_video_state_size();
1119 write_word(ss, BX, val);
1120 break;
1121 case 0x01:
1122 val = read_word(ss, BX);
1123 val = biosfn_save_video_state(CX, ES, val);
1124 #ifdef DEBUG
1125 printf("VGA save_state offset=%x\n", val);
1126 #endif
1127 if (CX & 8)
1128 vbe_biosfn_save_video_state(ES, val);
1129 break;
1130 case 0x02:
1131 val = read_word(ss, BX);
1132 val = biosfn_restore_video_state(CX, ES, val);
1133 #ifdef DEBUG
1134 printf("VGA restore_state offset=%x\n", val);
1135 #endif
1136 if (CX & 8)
1137 vbe_biosfn_restore_video_state(ES, val);
1138 break;
1139 default:
1140 // function failed
1141 result = 0x100;
1142 break;
1144 write_word(ss, AX, result);
1147 /** Function 05h - Display Window Control
1149 * Input:
1150 * AX = 4F05h
1151 * (16-bit) BH = 00h Set memory window
1152 * = 01h Get memory window
1153 * BL = Window number
1154 * = 00h Window A
1155 * = 01h Window B
1156 * DX = Window number in video memory in window
1157 * granularity units (Set Memory Window only)
1158 * Note:
1159 * If this function is called while in a linear frame buffer mode,
1160 * this function must fail with completion code AH=03h
1162 * Output:
1163 * AX = VBE Return Status
1164 * DX = Window number in window granularity units
1165 * (Get Memory Window only)
1167 ASM_START
1168 vbe_biosfn_display_window_control:
1169 cmp bl, #0x00
1170 jne vbe_05_failed
1171 cmp bh, #0x01
1172 je get_display_window
1173 jb set_display_window
1174 mov ax, #0x0100
1176 set_display_window:
1177 mov ax, dx
1178 call _dispi_set_bank
1179 call dispi_get_bank
1180 cmp ax, dx
1181 jne vbe_05_failed
1182 mov ax, #0x004f
1184 get_display_window:
1185 call dispi_get_bank
1186 mov dx, ax
1187 mov ax, #0x004f
1189 vbe_05_failed:
1190 mov ax, #0x014f
1192 ASM_END
1195 /** Function 06h - Set/Get Logical Scan Line Length
1197 * Input:
1198 * AX = 4F06h
1199 * BL = 00h Set Scan Line Length in Pixels
1200 * = 01h Get Scan Line Length
1201 * = 02h Set Scan Line Length in Bytes
1202 * = 03h Get Maximum Scan Line Length
1203 * CX = If BL=00h Desired Width in Pixels
1204 * If BL=02h Desired Width in Bytes
1205 * (Ignored for Get Functions)
1207 * Output:
1208 * AX = VBE Return Status
1209 * BX = Bytes Per Scan Line
1210 * CX = Actual Pixels Per Scan Line
1211 * (truncated to nearest complete pixel)
1212 * DX = Maximum Number of Scan Lines
1214 ASM_START
1215 vbe_biosfn_set_get_logical_scan_line_length:
1216 mov ax, cx
1217 cmp bl, #0x01
1218 je get_logical_scan_line_length
1219 cmp bl, #0x02
1220 je set_logical_scan_line_bytes
1221 jb set_logical_scan_line_pixels
1222 mov ax, #0x0100
1224 set_logical_scan_line_bytes:
1225 push ax
1226 call dispi_get_bpp
1227 xor bh, bh
1228 mov bl, ah
1229 or bl, bl
1230 jnz no_4bpp_1
1231 shl ax, #3
1232 mov bl, #1
1233 no_4bpp_1:
1234 xor dx, dx
1235 pop ax
1236 div bx
1237 set_logical_scan_line_pixels:
1238 call dispi_set_virt_width
1239 get_logical_scan_line_length:
1240 call dispi_get_bpp
1241 xor bh, bh
1242 mov bl, ah
1243 call dispi_get_virt_width
1244 mov cx, ax
1245 or bl, bl
1246 jnz no_4bpp_2
1247 shr ax, #3
1248 mov bl, #1
1249 no_4bpp_2:
1250 mul bx
1251 mov bx, ax
1252 call dispi_get_virt_height
1253 mov dx, ax
1254 mov ax, #0x004f
1256 ASM_END
1259 /** Function 07h - Set/Get Display Start
1261 * Input(16-bit):
1262 * AX = 4F07h
1263 * BH = 00h Reserved and must be 00h
1264 * BL = 00h Set Display Start
1265 * = 01h Get Display Start
1266 * = 02h Schedule Display Start (Alternate)
1267 * = 03h Schedule Stereoscopic Display Start
1268 * = 04h Get Scheduled Display Start Status
1269 * = 05h Enable Stereoscopic Mode
1270 * = 06h Disable Stereoscopic Mode
1271 * = 80h Set Display Start during Vertical Retrace
1272 * = 82h Set Display Start during Vertical Retrace (Alternate)
1273 * = 83h Set Stereoscopic Display Start during Vertical Retrace
1274 * ECX = If BL=02h/82h Display Start Address in bytes
1275 * If BL=03h/83h Left Image Start Address in bytes
1276 * EDX = If BL=03h/83h Right Image Start Address in bytes
1277 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
1278 * DX = If BL=00h/80h First Displayed Scan Line
1280 * Output:
1281 * AX = VBE Return Status
1282 * BH = If BL=01h Reserved and will be 0
1283 * CX = If BL=01h First Displayed Pixel In Scan Line
1284 * If BL=04h 0 if flip has not occurred, not 0 if it has
1285 * DX = If BL=01h First Displayed Scan Line
1287 * Input(32-bit):
1288 * BH = 00h Reserved and must be 00h
1289 * BL = 00h Set Display Start
1290 * = 80h Set Display Start during Vertical Retrace
1291 * CX = Bits 0-15 of display start address
1292 * DX = Bits 16-31 of display start address
1293 * ES = Selector for memory mapped registers
1295 ASM_START
1296 vbe_biosfn_set_get_display_start:
1297 cmp bl, #0x80
1298 je set_display_start
1299 cmp bl, #0x01
1300 je get_display_start
1301 jb set_display_start
1302 mov ax, #0x0100
1304 set_display_start:
1305 mov ax, cx
1306 call dispi_set_x_offset
1307 mov ax, dx
1308 call dispi_set_y_offset
1309 mov ax, #0x004f
1311 get_display_start:
1312 call dispi_get_x_offset
1313 mov cx, ax
1314 call dispi_get_y_offset
1315 mov dx, ax
1316 xor bh, bh
1317 mov ax, #0x004f
1319 ASM_END
1322 /** Function 08h - Set/Get Dac Palette Format
1324 * Input:
1325 * AX = 4F08h
1326 * BL = 00h set DAC palette width
1327 * = 01h get DAC palette width
1328 * BH = If BL=00h: desired number of bits per primary color
1329 * Output:
1330 * AX = VBE Return Status
1331 * BH = current number of bits per primary color (06h = standard VGA)
1333 ASM_START
1334 vbe_biosfn_set_get_dac_palette_format:
1335 cmp bl, #0x01
1336 je get_dac_palette_format
1337 jb set_dac_palette_format
1338 mov ax, #0x0100
1340 set_dac_palette_format:
1341 call dispi_get_enable
1342 cmp bh, #0x06
1343 je set_normal_dac
1344 cmp bh, #0x08
1345 jne vbe_08_unsupported
1346 or ax, # VBE_DISPI_8BIT_DAC
1347 jnz set_dac_mode
1348 set_normal_dac:
1349 and ax, #~ VBE_DISPI_8BIT_DAC
1350 set_dac_mode:
1351 call _dispi_set_enable
1352 get_dac_palette_format:
1353 mov bh, #0x06
1354 call dispi_get_enable
1355 and ax, # VBE_DISPI_8BIT_DAC
1356 jz vbe_08_ok
1357 mov bh, #0x08
1358 vbe_08_ok:
1359 mov ax, #0x004f
1361 vbe_08_unsupported:
1362 mov ax, #0x014f
1364 ASM_END
1367 /** Function 09h - Set/Get Palette Data
1369 * Input:
1370 * AX = 4F09h
1371 * Output:
1372 * AX = VBE Return Status
1374 * FIXME: incomplete API description, Input & Output
1376 void vbe_biosfn_set_get_palette_data(AX)
1380 /** Function 0Ah - Return VBE Protected Mode Interface
1381 * Input: AX = 4F0Ah VBE 2.0 Protected Mode Interface
1382 * BL = 00h Return protected mode table
1385 * Output: AX = Status
1386 * ES = Real Mode Segment of Table
1387 * DI = Offset of Table
1388 * CX = Length of Table including protected mode code
1389 * (for copying purposes)
1391 ASM_START
1392 vbe_biosfn_return_protected_mode_interface:
1393 test bl, bl
1394 jnz _fail
1395 mov di, #0xc000
1396 mov es, di
1397 mov di, # vesa_pm_start
1398 mov cx, # vesa_pm_end
1399 sub cx, di
1400 mov ax, #0x004f
1402 _fail:
1403 mov ax, #0x014f
1405 ASM_END