- improved VGA compatible setup for >=8bpp VBE modes (CRTC doubleword mode and
[vgabios.git] / vbe.c
blob801c67547e58a20cc43207e7e32df35afa3915c1
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, #1
477 set_width_svga:
478 shr bx, #3
479 mov dx, # VGAREG_VGA_CRTC_ADDRESS
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, # VGAREG_VGA_CRTC_ADDRESS
533 mov ax, #0x0011
534 out dx, ax
535 pop ax
536 push ax
537 shr ax, #3
538 dec ax
539 mov ah, al
540 mov al, #0x01
541 out dx, ax
542 pop ax
543 call vga_set_virt_width
545 ; set CRT Y resolution
546 mov dx, # VBE_DISPI_IOPORT_INDEX
547 mov ax, # VBE_DISPI_INDEX_YRES
548 out dx, ax
549 mov dx, # VBE_DISPI_IOPORT_DATA
550 in ax, dx
551 dec ax
552 push ax
553 mov dx, # VGAREG_VGA_CRTC_ADDRESS
554 mov ah, al
555 mov al, #0x12
556 out dx, ax
557 pop ax
558 mov al, #0x07
559 out dx, al
560 inc dx
561 in al, dx
562 and al, #0xbd
563 test ah, #0x01
564 jz bit8_clear
565 or al, #0x02
566 bit8_clear:
567 test ah, #0x02
568 jz bit9_clear
569 or al, #0x40
570 bit9_clear:
571 out dx, al
573 ; other settings
574 mov dx, # VGAREG_VGA_CRTC_ADDRESS
575 mov ax, #0x0009
576 out dx, ax
577 mov dx, # VGAREG_ACTL_RESET
578 in al, dx
579 mov dx, # VGAREG_ACTL_ADDRESS
580 mov al, #0x10
581 out dx, al
582 mov dx, # VGAREG_ACTL_READ_DATA
583 in al, dx
584 or al, #0x01
585 mov dx, # VGAREG_ACTL_ADDRESS
586 out dx, al
587 mov al, #0x20
588 out dx, al
589 mov dx, # VGAREG_GRDC_ADDRESS
590 mov ax, #0x0506
591 out dx, ax
592 mov dx, # VGAREG_SEQU_ADDRESS
593 mov ax, #0x0f02
594 out dx, ax
596 ; settings for >= 8bpp
597 mov dx, # VBE_DISPI_IOPORT_INDEX
598 mov ax, # VBE_DISPI_INDEX_BPP
599 out dx, ax
600 mov dx, # VBE_DISPI_IOPORT_DATA
601 in ax, dx
602 cmp al, #0x08
603 jb vga_compat_end
604 mov dx, # VGAREG_VGA_CRTC_ADDRESS
605 mov al, #0x14
606 out dx, al
607 mov dx, # VGAREG_VGA_CRTC_DATA
608 in al, dx
609 or al, #0x40
610 out dx, al
611 mov dx, # VGAREG_ACTL_RESET
612 in al, dx
613 mov dx, # VGAREG_ACTL_ADDRESS
614 mov al, #0x10
615 out dx, al
616 mov dx, # VGAREG_ACTL_READ_DATA
617 in al, dx
618 or al, #0x40
619 mov dx, # VGAREG_ACTL_ADDRESS
620 out dx, al
621 mov al, #0x20
622 out dx, al
623 mov dx, # VGAREG_SEQU_ADDRESS
624 mov al, #0x04
625 out dx, al
626 mov dx, # VGAREG_SEQU_DATA
627 in al, dx
628 or al, #0x08
629 out dx, al
630 mov dx, # VGAREG_GRDC_ADDRESS
631 mov al, #0x05
632 out dx, al
633 mov dx, # VGAREG_GRDC_DATA
634 in al, dx
635 and al, #0x9f
636 or al, #0x40
637 out dx, al
639 vga_compat_end:
640 pop dx
641 pop ax
642 ASM_END
645 // ModeInfo helper function
646 static ModeInfoListItem* mode_info_find_mode(mode, using_lfb)
647 Bit16u mode; Boolean using_lfb;
649 ModeInfoListItem *cur_info=&mode_info_list;
651 while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST)
653 if (cur_info->mode == mode)
655 if (!using_lfb)
657 return cur_info;
659 else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
661 return cur_info;
663 else
665 cur_info++;
668 else
670 cur_info++;
674 return 0;
677 ASM_START
679 ; Has VBE display - Returns true if VBE display detected
681 _vbe_has_vbe_display:
682 push ds
683 push bx
684 mov ax, # BIOSMEM_SEG
685 mov ds, ax
686 mov bx, # BIOSMEM_VBE_FLAG
687 mov al, [bx]
688 and al, #0x01
689 xor ah, ah
690 pop bx
691 pop ds
694 ; VBE Init - Initialise the Vesa Bios Extension Code
695 ; This function does a sanity check on the host side display code interface.
697 vbe_init:
698 mov ax, # VBE_DISPI_ID0
699 call dispi_set_id
700 call dispi_get_id
701 cmp ax, # VBE_DISPI_ID0
702 jne no_vbe_interface
703 push ds
704 push bx
705 mov ax, # BIOSMEM_SEG
706 mov ds, ax
707 mov bx, # BIOSMEM_VBE_FLAG
708 mov al, #0x01
709 mov [bx], al
710 pop bx
711 pop ds
712 mov ax, # VBE_DISPI_ID4
713 call dispi_set_id
714 no_vbe_interface:
715 #if defined(USE_BX_INFO) || defined(DEBUG)
716 mov bx, #msg_vbe_init
717 push bx
718 call _printf
719 inc sp
720 inc sp
721 #endif
724 ; VBE Display Info - Display information on screen about the VBE
726 vbe_display_info:
727 call _vbe_has_vbe_display
728 test ax, ax
729 jz no_vbe_flag
730 mov ax, #0xc000
731 mov ds, ax
732 mov si, #_vbebios_info_string
733 jmp _display_string
734 no_vbe_flag:
735 mov ax, #0xc000
736 mov ds, ax
737 mov si, #_no_vbebios_info_string
738 jmp _display_string
739 ASM_END
741 /** Function 00h - Return VBE Controller Information
743 * Input:
744 * AX = 4F00h
745 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
746 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
747 * the info block is 512 bytes in size)
748 * Output:
749 * AX = VBE Return Status
752 void vbe_biosfn_return_controller_information(AX, ES, DI)
753 Bit16u *AX;Bit16u ES;Bit16u DI;
755 Bit16u ss=get_SS();
756 VbeInfoBlock vbe_info_block;
757 Bit16u status;
758 Bit16u result;
759 Bit16u vbe2_info;
760 Bit16u cur_mode=0;
761 Bit16u cur_ptr=34;
762 ModeInfoListItem *cur_info=&mode_info_list;
764 status = read_word(ss, AX);
766 #ifdef DEBUG
767 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);
768 #endif
770 vbe2_info = 0;
771 #ifdef VBE2_NO_VESA_CHECK
772 #else
773 // get vbe_info_block into local variable
774 memcpyb(ss, &vbe_info_block, ES, DI, sizeof(vbe_info_block));
776 // check for VBE2 signature
777 if (((vbe_info_block.VbeSignature[0] == 'V') &&
778 (vbe_info_block.VbeSignature[1] == 'B') &&
779 (vbe_info_block.VbeSignature[2] == 'E') &&
780 (vbe_info_block.VbeSignature[3] == '2')) ||
782 ((vbe_info_block.VbeSignature[0] == 'V') &&
783 (vbe_info_block.VbeSignature[1] == 'E') &&
784 (vbe_info_block.VbeSignature[2] == 'S') &&
785 (vbe_info_block.VbeSignature[3] == 'A')) )
787 vbe2_info = 1;
788 #ifdef DEBUG
789 printf("VBE correct VESA/VBE2 signature found\n");
790 #endif
792 #endif
794 // VBE Signature
795 vbe_info_block.VbeSignature[0] = 'V';
796 vbe_info_block.VbeSignature[1] = 'E';
797 vbe_info_block.VbeSignature[2] = 'S';
798 vbe_info_block.VbeSignature[3] = 'A';
800 // VBE Version supported
801 vbe_info_block.VbeVersion = 0x0200;
803 // OEM String
804 vbe_info_block.OemStringPtr_Seg = 0xc000;
805 vbe_info_block.OemStringPtr_Off = &vbebios_copyright;
807 // Capabilities
808 vbe_info_block.Capabilities[0] = VBE_CAPABILITY_8BIT_DAC;
809 vbe_info_block.Capabilities[1] = 0;
810 vbe_info_block.Capabilities[2] = 0;
811 vbe_info_block.Capabilities[3] = 0;
813 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
814 vbe_info_block.VideoModePtr_Seg= ES ;
815 vbe_info_block.VideoModePtr_Off= DI + 34;
817 // VBE Total Memory (in 64b blocks)
818 vbe_info_block.TotalMemory = VBE_TOTAL_VIDEO_MEMORY_DIV_64K;
820 if (vbe2_info)
822 // OEM Stuff
823 vbe_info_block.OemSoftwareRev = VBE_OEM_SOFTWARE_REV;
824 vbe_info_block.OemVendorNamePtr_Seg = 0xc000;
825 vbe_info_block.OemVendorNamePtr_Off = &vbebios_vendor_name;
826 vbe_info_block.OemProductNamePtr_Seg = 0xc000;
827 vbe_info_block.OemProductNamePtr_Off = &vbebios_product_name;
828 vbe_info_block.OemProductRevPtr_Seg = 0xc000;
829 vbe_info_block.OemProductRevPtr_Off = &vbebios_product_revision;
831 // copy updates in vbe_info_block back
832 memcpyb(ES, DI, ss, &vbe_info_block, sizeof(vbe_info_block));
834 else
836 // copy updates in vbe_info_block back (VBE 1.x compatibility)
837 memcpyb(ES, DI, ss, &vbe_info_block, 256);
842 if ((cur_info->info.XResolution <= dispi_get_max_xres()) &&
843 (cur_info->info.BitsPerPixel <= dispi_get_max_bpp())) {
844 #ifdef DEBUG
845 printf("VBE found mode %x => %x\n", cur_info->mode,cur_mode);
846 #endif
847 write_word(ES, DI + cur_ptr, cur_info->mode);
848 cur_mode++;
849 cur_ptr+=2;
851 cur_info++;
852 } while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST);
854 // Add vesa mode list terminator
855 write_word(ES, DI + cur_ptr, cur_info->mode);
857 result = 0x4f;
859 write_word(ss, AX, result);
863 /** Function 01h - Return VBE Mode Information
865 * Input:
866 * AX = 4F01h
867 * CX = Mode Number
868 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
869 * Output:
870 * AX = VBE Return Status
873 void vbe_biosfn_return_mode_information(AX, CX, ES, DI)
874 Bit16u *AX;Bit16u CX; Bit16u ES;Bit16u DI;
876 Bit16u result=0x0100;
877 Bit16u ss=get_SS();
878 ModeInfoBlock info;
879 ModeInfoListItem *cur_info;
880 Boolean using_lfb;
882 #ifdef DEBUG
883 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
884 #endif
886 using_lfb=((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
888 CX = (CX & 0x1ff);
890 cur_info = mode_info_find_mode(CX, using_lfb, &cur_info);
892 if (cur_info != 0)
894 #ifdef DEBUG
895 printf("VBE found mode %x\n",CX);
896 #endif
897 memsetb(ss, &info, 0, sizeof(ModeInfoBlock));
898 memcpyb(ss, &info, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
899 if (info.WinAAttributes & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
900 info.WinFuncPtr = 0xC0000000UL;
901 *(Bit16u *)&(info.WinFuncPtr) = (Bit16u)(dispi_set_bank_farcall);
904 result = 0x4f;
906 else
908 #ifdef DEBUG
909 printf("VBE *NOT* found mode %x\n",CX);
910 #endif
911 result = 0x100;
914 if (result == 0x4f)
916 // copy updates in mode_info_block back
917 memcpyb(ES, DI, ss, &info, sizeof(info));
920 write_word(ss, AX, result);
923 /** Function 02h - Set VBE Mode
925 * Input:
926 * AX = 4F02h
927 * BX = Desired Mode to set
928 * ES:DI = Pointer to CRTCInfoBlock structure
929 * Output:
930 * AX = VBE Return Status
933 void vbe_biosfn_set_mode(AX, BX, ES, DI)
934 Bit16u *AX;Bit16u BX; Bit16u ES;Bit16u DI;
936 Bit16u ss = get_SS();
937 Bit16u result;
938 ModeInfoListItem *cur_info;
939 Boolean using_lfb;
940 Bit8u no_clear;
941 Bit8u lfb_flag;
943 using_lfb=((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
944 lfb_flag=using_lfb?VBE_DISPI_LFB_ENABLED:0;
945 no_clear=((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY)?VBE_DISPI_NOCLEARMEM:0;
947 BX = (BX & 0x1ff);
949 //result=read_word(ss,AX);
951 // check for non vesa mode
952 if (BX<VBE_MODE_VESA_DEFINED)
954 Bit8u mode;
956 dispi_set_enable(VBE_DISPI_DISABLED);
957 // call the vgabios in order to set the video mode
958 // this allows for going back to textmode with a VBE call (some applications expect that to work)
960 mode=(BX & 0xff);
961 biosfn_set_video_mode(mode);
962 result = 0x4f;
965 cur_info = mode_info_find_mode(BX, using_lfb, &cur_info);
967 if (cur_info != 0)
969 #ifdef DEBUG
970 printf("VBE found mode %x, setting:\n", BX);
971 printf("\txres%x yres%x bpp%x\n",
972 cur_info->info.XResolution,
973 cur_info->info.YResolution,
974 cur_info->info.BitsPerPixel);
975 #endif
977 // first disable current mode (when switching between vesa modi)
978 dispi_set_enable(VBE_DISPI_DISABLED);
980 if (cur_info->info.BitsPerPixel == 4)
982 biosfn_set_video_mode(0x6a);
985 dispi_set_bpp(cur_info->info.BitsPerPixel);
986 dispi_set_xres(cur_info->info.XResolution);
987 dispi_set_yres(cur_info->info.YResolution);
988 dispi_set_bank(0);
989 dispi_set_enable(VBE_DISPI_ENABLED | no_clear | lfb_flag);
990 vga_compat_setup();
992 write_word(BIOSMEM_SEG,BIOSMEM_VBE_MODE,BX);
993 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60 | no_clear));
995 result = 0x4f;
997 else
999 #ifdef DEBUG
1000 printf("VBE *NOT* found mode %x\n" , BX);
1001 #endif
1002 result = 0x100;
1004 // FIXME: redirect non VBE modi to normal VGA bios operation
1005 // (switch back to VGA mode
1006 if (BX == 3)
1007 result = 0x4f;
1010 write_word(ss, AX, result);
1013 /** Function 03h - Return Current VBE Mode
1015 * Input:
1016 * AX = 4F03h
1017 * Output:
1018 * AX = VBE Return Status
1019 * BX = Current VBE Mode
1022 ASM_START
1023 vbe_biosfn_return_current_mode:
1024 push ds
1025 mov ax, # BIOSMEM_SEG
1026 mov ds, ax
1027 call dispi_get_enable
1028 and ax, # VBE_DISPI_ENABLED
1029 jz no_vbe_mode
1030 mov bx, # BIOSMEM_VBE_MODE
1031 mov ax, [bx]
1032 mov bx, ax
1033 jnz vbe_03_ok
1034 no_vbe_mode:
1035 mov bx, # BIOSMEM_CURRENT_MODE
1036 mov al, [bx]
1037 mov bl, al
1038 xor bh, bh
1039 vbe_03_ok:
1040 mov ax, #0x004f
1041 pop ds
1043 ASM_END
1046 Bit16u vbe_biosfn_read_video_state_size()
1048 return 9 * 2;
1051 void vbe_biosfn_save_video_state(ES, BX)
1052 Bit16u ES; Bit16u BX;
1054 Bit16u enable, i;
1056 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1057 enable = inw(VBE_DISPI_IOPORT_DATA);
1058 write_word(ES, BX, enable);
1059 BX += 2;
1060 if (!(enable & VBE_DISPI_ENABLED))
1061 return;
1062 for(i = VBE_DISPI_INDEX_XRES; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
1063 if (i != VBE_DISPI_INDEX_ENABLE) {
1064 outw(VBE_DISPI_IOPORT_INDEX, i);
1065 write_word(ES, BX, inw(VBE_DISPI_IOPORT_DATA));
1066 BX += 2;
1072 void vbe_biosfn_restore_video_state(ES, BX)
1073 Bit16u ES; Bit16u BX;
1075 Bit16u enable, i;
1077 enable = read_word(ES, BX);
1078 BX += 2;
1080 if (!(enable & VBE_DISPI_ENABLED)) {
1081 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1082 outw(VBE_DISPI_IOPORT_DATA, enable);
1083 } else {
1084 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
1085 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1086 BX += 2;
1087 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
1088 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1089 BX += 2;
1090 outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
1091 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1092 BX += 2;
1093 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_ENABLE);
1094 outw(VBE_DISPI_IOPORT_DATA, enable);
1096 for(i = VBE_DISPI_INDEX_BANK; i <= VBE_DISPI_INDEX_Y_OFFSET; i++) {
1097 outw(VBE_DISPI_IOPORT_INDEX, i);
1098 outw(VBE_DISPI_IOPORT_DATA, read_word(ES, BX));
1099 BX += 2;
1104 /** Function 04h - Save/Restore State
1106 * Input:
1107 * AX = 4F04h
1108 * DL = 00h Return Save/Restore State buffer size
1109 * 01h Save State
1110 * 02h Restore State
1111 * CX = Requested states
1112 * ES:BX = Pointer to buffer (if DL <> 00h)
1113 * Output:
1114 * AX = VBE Return Status
1115 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
1118 void vbe_biosfn_save_restore_state(AX, CX, DX, ES, BX)
1119 Bit16u *AX; Bit16u CX; Bit16u DX; Bit16u ES; Bit16u *BX;
1121 Bit16u ss=get_SS();
1122 Bit16u result, val;
1124 result = 0x4f;
1125 switch(GET_DL()) {
1126 case 0x00:
1127 val = biosfn_read_video_state_size2(CX);
1128 #ifdef DEBUG
1129 printf("VGA state size=%x\n", val);
1130 #endif
1131 if (CX & 8)
1132 val += vbe_biosfn_read_video_state_size();
1133 write_word(ss, BX, val);
1134 break;
1135 case 0x01:
1136 val = read_word(ss, BX);
1137 val = biosfn_save_video_state(CX, ES, val);
1138 #ifdef DEBUG
1139 printf("VGA save_state offset=%x\n", val);
1140 #endif
1141 if (CX & 8)
1142 vbe_biosfn_save_video_state(ES, val);
1143 break;
1144 case 0x02:
1145 val = read_word(ss, BX);
1146 val = biosfn_restore_video_state(CX, ES, val);
1147 #ifdef DEBUG
1148 printf("VGA restore_state offset=%x\n", val);
1149 #endif
1150 if (CX & 8)
1151 vbe_biosfn_restore_video_state(ES, val);
1152 break;
1153 default:
1154 // function failed
1155 result = 0x100;
1156 break;
1158 write_word(ss, AX, result);
1161 /** Function 05h - Display Window Control
1163 * Input:
1164 * AX = 4F05h
1165 * (16-bit) BH = 00h Set memory window
1166 * = 01h Get memory window
1167 * BL = Window number
1168 * = 00h Window A
1169 * = 01h Window B
1170 * DX = Window number in video memory in window
1171 * granularity units (Set Memory Window only)
1172 * Note:
1173 * If this function is called while in a linear frame buffer mode,
1174 * this function must fail with completion code AH=03h
1176 * Output:
1177 * AX = VBE Return Status
1178 * DX = Window number in window granularity units
1179 * (Get Memory Window only)
1181 ASM_START
1182 vbe_biosfn_display_window_control:
1183 cmp bl, #0x00
1184 jne vbe_05_failed
1185 cmp bh, #0x01
1186 je get_display_window
1187 jb set_display_window
1188 mov ax, #0x0100
1190 set_display_window:
1191 mov ax, dx
1192 call _dispi_set_bank
1193 call dispi_get_bank
1194 cmp ax, dx
1195 jne vbe_05_failed
1196 mov ax, #0x004f
1198 get_display_window:
1199 call dispi_get_bank
1200 mov dx, ax
1201 mov ax, #0x004f
1203 vbe_05_failed:
1204 mov ax, #0x014f
1206 ASM_END
1209 /** Function 06h - Set/Get Logical Scan Line Length
1211 * Input:
1212 * AX = 4F06h
1213 * BL = 00h Set Scan Line Length in Pixels
1214 * = 01h Get Scan Line Length
1215 * = 02h Set Scan Line Length in Bytes
1216 * = 03h Get Maximum Scan Line Length
1217 * CX = If BL=00h Desired Width in Pixels
1218 * If BL=02h Desired Width in Bytes
1219 * (Ignored for Get Functions)
1221 * Output:
1222 * AX = VBE Return Status
1223 * BX = Bytes Per Scan Line
1224 * CX = Actual Pixels Per Scan Line
1225 * (truncated to nearest complete pixel)
1226 * DX = Maximum Number of Scan Lines
1228 ASM_START
1229 vbe_biosfn_set_get_logical_scan_line_length:
1230 mov ax, cx
1231 cmp bl, #0x01
1232 je get_logical_scan_line_length
1233 cmp bl, #0x02
1234 je set_logical_scan_line_bytes
1235 jb set_logical_scan_line_pixels
1236 mov ax, #0x0100
1238 set_logical_scan_line_bytes:
1239 push ax
1240 call dispi_get_bpp
1241 xor bh, bh
1242 mov bl, ah
1243 or bl, bl
1244 jnz no_4bpp_1
1245 shl ax, #3
1246 mov bl, #1
1247 no_4bpp_1:
1248 xor dx, dx
1249 pop ax
1250 div bx
1251 set_logical_scan_line_pixels:
1252 call dispi_set_virt_width
1253 get_logical_scan_line_length:
1254 call dispi_get_bpp
1255 xor bh, bh
1256 mov bl, ah
1257 call dispi_get_virt_width
1258 mov cx, ax
1259 or bl, bl
1260 jnz no_4bpp_2
1261 shr ax, #3
1262 mov bl, #1
1263 no_4bpp_2:
1264 mul bx
1265 mov bx, ax
1266 call dispi_get_virt_height
1267 mov dx, ax
1268 mov ax, #0x004f
1270 ASM_END
1273 /** Function 07h - Set/Get Display Start
1275 * Input(16-bit):
1276 * AX = 4F07h
1277 * BH = 00h Reserved and must be 00h
1278 * BL = 00h Set Display Start
1279 * = 01h Get Display Start
1280 * = 02h Schedule Display Start (Alternate)
1281 * = 03h Schedule Stereoscopic Display Start
1282 * = 04h Get Scheduled Display Start Status
1283 * = 05h Enable Stereoscopic Mode
1284 * = 06h Disable Stereoscopic Mode
1285 * = 80h Set Display Start during Vertical Retrace
1286 * = 82h Set Display Start during Vertical Retrace (Alternate)
1287 * = 83h Set Stereoscopic Display Start during Vertical Retrace
1288 * ECX = If BL=02h/82h Display Start Address in bytes
1289 * If BL=03h/83h Left Image Start Address in bytes
1290 * EDX = If BL=03h/83h Right Image Start Address in bytes
1291 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
1292 * DX = If BL=00h/80h First Displayed Scan Line
1294 * Output:
1295 * AX = VBE Return Status
1296 * BH = If BL=01h Reserved and will be 0
1297 * CX = If BL=01h First Displayed Pixel In Scan Line
1298 * If BL=04h 0 if flip has not occurred, not 0 if it has
1299 * DX = If BL=01h First Displayed Scan Line
1301 * Input(32-bit):
1302 * BH = 00h Reserved and must be 00h
1303 * BL = 00h Set Display Start
1304 * = 80h Set Display Start during Vertical Retrace
1305 * CX = Bits 0-15 of display start address
1306 * DX = Bits 16-31 of display start address
1307 * ES = Selector for memory mapped registers
1309 ASM_START
1310 vbe_biosfn_set_get_display_start:
1311 cmp bl, #0x80
1312 je set_display_start
1313 cmp bl, #0x01
1314 je get_display_start
1315 jb set_display_start
1316 mov ax, #0x0100
1318 set_display_start:
1319 mov ax, cx
1320 call dispi_set_x_offset
1321 mov ax, dx
1322 call dispi_set_y_offset
1323 mov ax, #0x004f
1325 get_display_start:
1326 call dispi_get_x_offset
1327 mov cx, ax
1328 call dispi_get_y_offset
1329 mov dx, ax
1330 xor bh, bh
1331 mov ax, #0x004f
1333 ASM_END
1336 /** Function 08h - Set/Get Dac Palette Format
1338 * Input:
1339 * AX = 4F08h
1340 * BL = 00h set DAC palette width
1341 * = 01h get DAC palette width
1342 * BH = If BL=00h: desired number of bits per primary color
1343 * Output:
1344 * AX = VBE Return Status
1345 * BH = current number of bits per primary color (06h = standard VGA)
1347 ASM_START
1348 vbe_biosfn_set_get_dac_palette_format:
1349 cmp bl, #0x01
1350 je get_dac_palette_format
1351 jb set_dac_palette_format
1352 mov ax, #0x0100
1354 set_dac_palette_format:
1355 call dispi_get_enable
1356 cmp bh, #0x06
1357 je set_normal_dac
1358 cmp bh, #0x08
1359 jne vbe_08_unsupported
1360 or ax, # VBE_DISPI_8BIT_DAC
1361 jnz set_dac_mode
1362 set_normal_dac:
1363 and ax, #~ VBE_DISPI_8BIT_DAC
1364 set_dac_mode:
1365 call _dispi_set_enable
1366 get_dac_palette_format:
1367 mov bh, #0x06
1368 call dispi_get_enable
1369 and ax, # VBE_DISPI_8BIT_DAC
1370 jz vbe_08_ok
1371 mov bh, #0x08
1372 vbe_08_ok:
1373 mov ax, #0x004f
1375 vbe_08_unsupported:
1376 mov ax, #0x014f
1378 ASM_END
1381 /** Function 09h - Set/Get Palette Data
1383 * Input:
1384 * AX = 4F09h
1385 * Output:
1386 * AX = VBE Return Status
1388 * FIXME: incomplete API description, Input & Output
1390 void vbe_biosfn_set_get_palette_data(AX)
1394 /** Function 0Ah - Return VBE Protected Mode Interface
1395 * Input: AX = 4F0Ah VBE 2.0 Protected Mode Interface
1396 * BL = 00h Return protected mode table
1399 * Output: AX = Status
1400 * ES = Real Mode Segment of Table
1401 * DI = Offset of Table
1402 * CX = Length of Table including protected mode code
1403 * (for copying purposes)
1405 ASM_START
1406 vbe_biosfn_return_protected_mode_interface:
1407 test bl, bl
1408 jnz _fail
1409 mov di, #0xc000
1410 mov es, di
1411 mov di, # vesa_pm_start
1412 mov cx, # vesa_pm_end
1413 sub cx, di
1414 mov ax, #0x004f
1416 _fail:
1417 mov ax, #0x014f
1419 ASM_END