VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/BIOS-new/vberom.asm@ 43116

Last change on this file since 43116 was 43116, checked in by vboxsync, 13 years ago

Devices/Graphics/BIOS-new: adjust licence comments to the default style

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.0 KB
Line 
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.
14;;
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.
23;;
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
28;;
29;; ============================================================================================
30
31
32; Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
33; other than GPL or LGPL is available it will apply instead, Oracle elects to use only
34; the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
35; a choice of LGPL license versions is made available with the language indicating
36; that LGPLv2 or any later version may be used, or where a choice of which version
37; of the LGPL is applied is otherwise unspecified.
38
39include vgadefs.inc
40
41public _vga_compat_setup
42public dispi_set_enable_
43public dispi_set_bank_
44public _dispi_set_bank_farcall
45public _dispi_get_max_bpp
46public _vbe_has_vbe_display
47public _vbe_init
48
49public vbe_biosfn_return_current_mode
50public vbe_biosfn_display_window_control
51public vbe_biosfn_set_get_logical_scan_line_length
52public vbe_biosfn_set_get_display_start
53public vbe_biosfn_set_get_dac_palette_format
54public vbe_biosfn_set_get_palette_data
55public vbe_biosfn_return_protected_mode_interface
56
57VGAROM segment public 'CODE'
58
59.386
60
61;; Bytewise in/out
62ifdef VBE_BYTEWISE_IO
63
64public do_out_dx_ax
65public do_in_ax_dx
66
67do_out_dx_ax:
68 xchg ah, al
69 out dx, al
70 xchg ah, al
71 out dx, al
72 ret
73
74do_in_ax_dx:
75 in al, dx
76 xchg ah, al
77 in al, dx
78 ret
79
80 out_dx_ax EQU call do_out_dx_ax
81 in_ax_dx EQU call do_in_ax_dx
82else
83 out_dx_ax EQU out dx, ax
84 in_ax_dx EQU in ax, dx
85endif
86
87;; Vertical retrace waiting
88wait_vsync:
89 push ax
90 push dx
91 mov dx, 03DAh ; @todo use a symbolic constant!
92wv_loop:
93 in al, dx
94 test al, 8
95 jz wv_loop
96 pop dx
97 pop ax
98 ret
99
100wait_not_vsync:
101 push ax
102 push dx
103 mov dx, 03DAh ; @todo use a symbolic constant!
104wnv_loop:
105 in al, dx
106 test al, 8
107 jnz wnv_loop
108 pop dx
109 pop ax
110 ret
111
112; DISPI ioport functions
113
114dispi_get_id:
115 push dx
116 mov dx, VBE_DISPI_IOPORT_INDEX
117 mov ax, VBE_DISPI_INDEX_ID
118 out_dx_ax
119 mov dx, VBE_DISPI_IOPORT_DATA
120 in_ax_dx
121 pop dx
122 ret
123
124dispi_set_id:
125 push dx
126 push ax
127 mov dx, VBE_DISPI_IOPORT_INDEX
128 mov ax, VBE_DISPI_INDEX_ID
129 out_dx_ax
130 pop ax
131 mov dx, VBE_DISPI_IOPORT_DATA
132 out_dx_ax
133 pop dx
134 ret
135
136; AL = bits per pixel / AH = bytes per pixel
137dispi_get_bpp:
138 push dx
139 mov dx, VBE_DISPI_IOPORT_INDEX
140 mov ax, VBE_DISPI_INDEX_BPP
141 out_dx_ax
142 mov dx, VBE_DISPI_IOPORT_DATA
143 in_ax_dx
144 cmp al, 4
145 jbe get_bpp_noinc
146 mov ah, al
147 shr ah, 3
148 test al, 07
149 jz get_bpp_noinc
150 inc ah
151get_bpp_noinc:
152 pop dx
153 ret
154
155; get display capabilities
156
157_dispi_get_max_bpp:
158 push dx
159 push bx
160 call dispi_get_enable
161 mov bx, ax
162 or ax, VBE_DISPI_GETCAPS
163 call dispi_set_enable_
164 mov dx, VBE_DISPI_IOPORT_INDEX
165 mov ax, VBE_DISPI_INDEX_BPP
166 out_dx_ax
167 mov dx, VBE_DISPI_IOPORT_DATA
168 in_ax_dx
169 push ax
170 mov ax, bx
171 call dispi_set_enable_
172 pop ax
173 pop bx
174 pop dx
175 ret
176
177dispi_set_enable_:
178 push dx
179 push ax
180 mov dx, VBE_DISPI_IOPORT_INDEX
181 mov ax, VBE_DISPI_INDEX_ENABLE
182 out_dx_ax
183 pop ax
184 mov dx, VBE_DISPI_IOPORT_DATA
185 out_dx_ax
186 pop dx
187 ret
188
189dispi_get_enable:
190 push dx
191 mov dx, VBE_DISPI_IOPORT_INDEX
192 mov ax, VBE_DISPI_INDEX_ENABLE
193 out_dx_ax
194 mov dx, VBE_DISPI_IOPORT_DATA
195 in_ax_dx
196 pop dx
197 ret
198
199dispi_set_bank_:
200 push dx
201 push ax
202 mov dx, VBE_DISPI_IOPORT_INDEX
203 mov ax, VBE_DISPI_INDEX_BANK
204 out_dx_ax
205 pop ax
206 mov dx, VBE_DISPI_IOPORT_DATA
207 out_dx_ax
208 pop dx
209 ret
210
211dispi_get_bank:
212 push dx
213 mov dx, VBE_DISPI_IOPORT_INDEX
214 mov ax, VBE_DISPI_INDEX_BANK
215 out_dx_ax
216 mov dx, VBE_DISPI_IOPORT_DATA
217 in_ax_dx
218 pop dx
219 ret
220
221_dispi_set_bank_farcall:
222 cmp bx, 0100h
223 je dispi_set_bank_farcall_get
224 or bx,bx
225 jnz dispi_set_bank_farcall_error
226 mov ax, dx
227 push dx
228 push ax
229 mov ax, VBE_DISPI_INDEX_BANK
230 mov dx, VBE_DISPI_IOPORT_INDEX
231 out_dx_ax
232 pop ax
233 mov dx, VBE_DISPI_IOPORT_DATA
234 out_dx_ax
235 in_ax_dx
236 pop dx
237 cmp dx,ax
238 jne dispi_set_bank_farcall_error
239 mov ax, 004Fh
240 retf
241dispi_set_bank_farcall_get:
242 mov ax, VBE_DISPI_INDEX_BANK
243 mov dx, VBE_DISPI_IOPORT_INDEX
244 out_dx_ax
245 mov dx, VBE_DISPI_IOPORT_DATA
246 in_ax_dx
247 mov dx,ax
248 retf
249dispi_set_bank_farcall_error:
250 mov ax, 014Fh
251 retf
252
253dispi_set_x_offset:
254 push dx
255 push ax
256 mov dx, VBE_DISPI_IOPORT_INDEX
257 mov ax, VBE_DISPI_INDEX_X_OFFSET
258 out_dx_ax
259 pop ax
260 mov dx, VBE_DISPI_IOPORT_DATA
261 out_dx_ax
262 pop dx
263 ret
264
265dispi_get_x_offset:
266 push dx
267 mov dx, VBE_DISPI_IOPORT_INDEX
268 mov ax, VBE_DISPI_INDEX_X_OFFSET
269 out_dx_ax
270 mov dx, VBE_DISPI_IOPORT_DATA
271 in_ax_dx
272 pop dx
273 ret
274
275dispi_set_y_offset:
276 push dx
277 push ax
278 mov dx, VBE_DISPI_IOPORT_INDEX
279 mov ax, VBE_DISPI_INDEX_Y_OFFSET
280 out_dx_ax
281 pop ax
282 mov dx, VBE_DISPI_IOPORT_DATA
283 out_dx_ax
284 pop dx
285 ret
286
287dispi_get_y_offset:
288 push dx
289 mov dx, VBE_DISPI_IOPORT_INDEX
290 mov ax, VBE_DISPI_INDEX_Y_OFFSET
291 out_dx_ax
292 mov dx, VBE_DISPI_IOPORT_DATA
293 in_ax_dx
294 pop dx
295 ret
296
297vga_set_virt_width:
298 push ax
299 push bx
300 push dx
301 mov bx, ax
302 call dispi_get_bpp
303 cmp al, 4
304 ja set_width_svga
305 shr bx, 1
306set_width_svga:
307 shr bx, 3
308 mov dx, VGAREG_VGA_CRTC_ADDRESS
309 mov ah, bl
310 mov al, 13h
311 out dx, ax
312 pop dx
313 pop bx
314 pop ax
315 ret
316
317dispi_set_virt_width:
318 call vga_set_virt_width
319 push dx
320 push ax
321 mov dx, VBE_DISPI_IOPORT_INDEX
322 mov ax, VBE_DISPI_INDEX_VIRT_WIDTH
323 out_dx_ax
324 pop ax
325 mov dx, VBE_DISPI_IOPORT_DATA
326 out_dx_ax
327 pop dx
328 ret
329
330dispi_get_virt_width:
331 push dx
332 mov dx, VBE_DISPI_IOPORT_INDEX
333 mov ax, VBE_DISPI_INDEX_VIRT_WIDTH
334 out_dx_ax
335 mov dx, VBE_DISPI_IOPORT_DATA
336 in_ax_dx
337 pop dx
338 ret
339
340dispi_get_virt_height:
341 push dx
342 mov dx, VBE_DISPI_IOPORT_INDEX
343 mov ax, VBE_DISPI_INDEX_VIRT_HEIGHT
344 out_dx_ax
345 mov dx, VBE_DISPI_IOPORT_DATA
346 in_ax_dx
347 pop dx
348 ret
349
350_vga_compat_setup:
351 push ax
352 push dx
353
354 ; set CRT X resolution
355 mov dx, VBE_DISPI_IOPORT_INDEX
356 mov ax, VBE_DISPI_INDEX_XRES
357 out_dx_ax
358 mov dx, VBE_DISPI_IOPORT_DATA
359 in_ax_dx
360 push ax
361 mov dx, VGAREG_VGA_CRTC_ADDRESS
362 mov ax, 0011h
363 out dx, ax
364 pop ax
365 push ax
366 shr ax, 3
367 dec ax
368 mov ah, al
369 mov al, 01
370 out dx, ax
371 pop ax
372 call vga_set_virt_width
373
374 ; set CRT Y resolution
375 mov dx, VBE_DISPI_IOPORT_INDEX
376 mov ax, VBE_DISPI_INDEX_YRES
377 out_dx_ax
378 mov dx, VBE_DISPI_IOPORT_DATA
379 in_ax_dx
380 dec ax
381 push ax
382 mov dx, VGAREG_VGA_CRTC_ADDRESS
383 mov ah, al
384 mov al, 12h
385 out dx, ax
386 pop ax
387 mov al, 07
388 out dx, al
389 inc dx
390 in al, dx
391 and al, 0BDh
392 test ah, 01
393 jz bit8_clear
394 or al, 02
395bit8_clear:
396 test ah, 02
397 jz bit9_clear
398 or al, 40h
399bit9_clear:
400 out dx, al
401
402 ; other settings
403 mov dx, VGAREG_VGA_CRTC_ADDRESS
404 mov ax, 0009
405 out dx, al
406 mov dx, VGAREG_VGA_CRTC_DATA
407 in al, dx
408 and al, 60h ; clear double scan bit and cell height
409 out dx, al
410 mov dx, VGAREG_VGA_CRTC_ADDRESS
411 mov al, 17h
412 out dx, al
413 mov dx, VGAREG_VGA_CRTC_DATA
414 in al, dx
415 or al, 03
416 out dx, al
417 mov dx, VGAREG_ACTL_RESET
418 in al, dx
419 mov dx, VGAREG_ACTL_ADDRESS
420 mov al, 10h
421 out dx, al
422 mov dx, VGAREG_ACTL_READ_DATA
423 in al, dx
424 or al, 01
425 mov dx, VGAREG_ACTL_ADDRESS
426 out dx, al
427 mov al, 20h
428 out dx, al
429 mov dx, VGAREG_GRDC_ADDRESS
430 mov ax, 0506h
431 out dx, ax
432 mov dx, VGAREG_SEQU_ADDRESS
433 mov ax, 0F02h
434 out dx, ax
435
436 ; settings for >= 8bpp
437 mov dx, VBE_DISPI_IOPORT_INDEX
438 mov ax, VBE_DISPI_INDEX_BPP
439 out_dx_ax
440 mov dx, VBE_DISPI_IOPORT_DATA
441 in_ax_dx
442 cmp al, 08
443 jb vga_compat_end
444 mov dx, VGAREG_VGA_CRTC_ADDRESS
445 mov al, 14h
446 out dx, al
447 mov dx, VGAREG_VGA_CRTC_DATA
448 in al, dx
449 or al, 40h
450 out dx, al
451 mov dx, VGAREG_ACTL_RESET
452 in al, dx
453 mov dx, VGAREG_ACTL_ADDRESS
454 mov al, 10h
455 out dx, al
456 mov dx, VGAREG_ACTL_READ_DATA
457 in al, dx
458 or al, 40h
459 mov dx, VGAREG_ACTL_ADDRESS
460 out dx, al
461 mov al, 20h
462 out dx, al
463 mov dx, VGAREG_SEQU_ADDRESS
464 mov al, 04
465 out dx, al
466 mov dx, VGAREG_SEQU_DATA
467 in al, dx
468 or al, 08
469 out dx, al
470 mov dx, VGAREG_GRDC_ADDRESS
471 mov al, 05
472 out dx, al
473 mov dx, VGAREG_GRDC_DATA
474 in al, dx
475 and al, 9Fh
476 or al, 40h
477 out dx, al
478
479vga_compat_end:
480 pop dx
481 pop ax
482
483
484; Has VBE display - Returns true if VBE display detected
485
486_vbe_has_vbe_display:
487 push ds
488 push bx
489 mov ax, BIOSMEM_SEG
490 mov ds, ax
491 mov bx, BIOSMEM_VBE_FLAG
492 mov al, [bx]
493 and al, 01
494 xor ah, ah
495 pop bx
496 pop ds
497 ret
498
499; VBE Init - Initialise the Vesa Bios Extension Code
500; This function does a sanity check on the host side display code interface.
501
502_vbe_init:
503 mov ax, VBE_DISPI_ID0
504 call dispi_set_id
505 call dispi_get_id
506 cmp ax, VBE_DISPI_ID0
507 jne no_vbe_interface
508 push ds
509 push bx
510 mov ax, BIOSMEM_SEG
511 mov ds, ax
512 mov bx, BIOSMEM_VBE_FLAG
513 mov al, 01
514 mov [bx], al
515 pop bx
516 pop ds
517; mov ax, VBE_DISPI_ID3
518 mov ax, VBE_DISPI_ID4
519 call dispi_set_id
520no_vbe_interface:
521ifdef VGA_DEBUG
522 mov bx, msg_vbe_init
523 push bx
524 call _printf
525 inc sp
526 inc sp
527endif
528 ret
529
530; Function 03h - Return Current VBE Mode
531;
532; Input:
533; AX = 4F03h
534; Output:
535; AX = VBE Return Status
536; BX = Current VBE Mode
537;
538;
539vbe_biosfn_return_current_mode:
540 push ds
541 mov ax, BIOSMEM_SEG
542 mov ds, ax
543 call dispi_get_enable
544 and ax, VBE_DISPI_ENABLED
545 jz no_vbe_mode
546 mov bx, BIOSMEM_VBE_MODE
547 mov ax, [bx]
548 mov bx, ax
549 jnz vbe_03_ok
550no_vbe_mode:
551 mov bx, BIOSMEM_CURRENT_MODE
552 mov al, [bx]
553 mov bl, al
554 xor bh, bh
555vbe_03_ok:
556 mov ax, 004Fh
557 pop ds
558 ret
559
560
561; Function 05h - Display Window Control
562;
563; Input:
564; AX = 4F05h
565; (16-bit) BH = 00h Set memory window
566; = 01h Get memory window
567; BL = Window number
568; = 00h Window A
569; = 01h Window B
570; DX = Window number in video memory in window
571; granularity units (Set Memory Window only)
572; Note:
573; If this function is called while in a linear frame buffer mode,
574; this function must fail with completion code AH=03h
575;
576; Output:
577; AX = VBE Return Status
578; DX = Window number in window granularity units
579; (Get Memory Window only)
580
581vbe_biosfn_display_window_control:
582 cmp bl, 0
583 jne vbe_05_failed
584 cmp bh, 1
585 je get_display_window
586 jb set_display_window
587 mov ax, 0100h
588 ret
589set_display_window:
590 mov ax, dx
591 call dispi_set_bank_
592 call dispi_get_bank
593 cmp ax, dx
594 jne vbe_05_failed
595 mov ax, 004Fh
596 ret
597get_display_window:
598 call dispi_get_bank
599 mov dx, ax
600 mov ax, 004Fh
601 ret
602vbe_05_failed:
603 mov ax, 014Fh
604 ret
605
606
607; Function 06h - Set/Get Logical Scan Line Length
608;
609; Input:
610; AX = 4F06h
611; BL = 00h Set Scan Line Length in Pixels
612; = 01h Get Scan Line Length
613; = 02h Set Scan Line Length in Bytes
614; = 03h Get Maximum Scan Line Length
615; CX = If BL=00h Desired Width in Pixels
616; If BL=02h Desired Width in Bytes
617; (Ignored for Get Functions)
618;
619; Output:
620; AX = VBE Return Status
621; BX = Bytes Per Scan Line
622; CX = Actual Pixels Per Scan Line
623; (truncated to nearest complete pixel)
624; DX = Maximum Number of Scan Lines
625;
626vbe_biosfn_set_get_logical_scan_line_length:
627 mov ax, cx
628 cmp bl, 1
629 je get_logical_scan_line_length
630 cmp bl, 2
631 je set_logical_scan_line_bytes
632 jb set_logical_scan_line_pixels
633 mov ax, 0100h
634 ret
635set_logical_scan_line_bytes:
636 push ax
637 call dispi_get_bpp
638 xor bh, bh
639 mov bl, ah
640 or bl, bl
641 jnz no_4bpp_1
642 shl ax, 3
643 mov bl, 1
644no_4bpp_1:
645 xor dx, dx
646 pop ax
647 div bx
648set_logical_scan_line_pixels:
649 call dispi_set_virt_width
650get_logical_scan_line_length:
651 call dispi_get_bpp
652 xor bh, bh
653 mov bl, ah
654 call dispi_get_virt_width
655 mov cx, ax
656 or bl, bl
657 jnz no_4bpp_2
658 shr ax, 3
659 mov bl, 1
660no_4bpp_2:
661 mul bx
662 mov bx, ax
663 call dispi_get_virt_height
664 mov dx, ax
665 mov ax, 004Fh
666 ret
667
668
669; Function 07h - Set/Get Display Start
670;
671; Input(16-bit):
672; AX = 4F07h
673; BH = 00h Reserved and must be 00h
674; BL = 00h Set Display Start
675; = 01h Get Display Start
676; = 02h Schedule Display Start (Alternate)
677; = 03h Schedule Stereoscopic Display Start
678; = 04h Get Scheduled Display Start Status
679; = 05h Enable Stereoscopic Mode
680; = 06h Disable Stereoscopic Mode
681; = 80h Set Display Start during Vertical Retrace
682; = 82h Set Display Start during Vertical Retrace (Alternate)
683; = 83h Set Stereoscopic Display Start during Vertical Retrace
684; ECX = If BL=02h/82h Display Start Address in bytes
685; If BL=03h/83h Left Image Start Address in bytes
686; EDX = If BL=03h/83h Right Image Start Address in bytes
687; CX = If BL=00h/80h First Displayed Pixel In Scan Line
688; DX = If BL=00h/80h First Displayed Scan Line
689;
690; Output:
691; AX = VBE Return Status
692; BH = If BL=01h Reserved and will be 0
693; CX = If BL=01h First Displayed Pixel In Scan Line
694; If BL=04h 0 if flip has not occurred, not 0 if it has
695; DX = If BL=01h First Displayed Scan Line
696;
697; Input(32-bit):
698; BH = 00h Reserved and must be 00h
699; BL = 00h Set Display Start
700; = 80h Set Display Start during Vertical Retrace
701; CX = Bits 0-15 of display start address
702; DX = Bits 16-31 of display start address
703; ES = Selector for memory mapped registers
704;
705vbe_biosfn_set_get_display_start:
706 cmp bl, 80h
707 je set_display_start_wait
708 cmp bl, 1
709 je get_display_start
710 jb set_display_start
711 mov ax, 0100h
712 ret
713set_display_start_wait:
714 call wait_not_vsync
715 call wait_vsync
716set_display_start:
717 mov ax, cx
718 call dispi_set_x_offset
719 mov ax, dx
720 call dispi_set_y_offset
721 mov ax, 004Fh
722 ret
723get_display_start:
724 call dispi_get_x_offset
725 mov cx, ax
726 call dispi_get_y_offset
727 mov dx, ax
728 xor bh, bh
729 mov ax, 004Fh
730 ret
731
732
733; Function 08h - Set/Get Dac Palette Format
734;
735; Input:
736; AX = 4F08h
737; BL = 00h set DAC palette width
738; = 01h get DAC palette width
739; BH = If BL=00h: desired number of bits per primary color
740; Output:
741; AX = VBE Return Status
742; BH = current number of bits per primary color (06h = standard VGA)
743;
744vbe_biosfn_set_get_dac_palette_format:
745 cmp bl, 1
746 je get_dac_palette_format
747 jb set_dac_palette_format
748 mov ax, 0100h
749 ret
750set_dac_palette_format:
751 call dispi_get_enable
752 cmp bh, 6
753 je set_normal_dac
754 cmp bh, 8
755 jne vbe_08_unsupported
756 or ax, VBE_DISPI_8BIT_DAC
757 jnz set_dac_mode
758set_normal_dac:
759 and ax, NOT VBE_DISPI_8BIT_DAC
760set_dac_mode:
761 call dispi_set_enable_
762get_dac_palette_format:
763 mov bh, 6
764 call dispi_get_enable
765 and ax, VBE_DISPI_8BIT_DAC
766 jz vbe_08_ok
767 mov bh, 8
768vbe_08_ok:
769 mov ax, 004Fh
770 ret
771vbe_08_unsupported:
772 mov ax, 014Fh
773 ret
774
775
776; Function 09h - Set/Get Palette Data
777;
778; Input:
779; AX = 4F09h
780; (16-bit) BL = 00h Set palette data
781; = 01h Get palette data
782; = 02h Set secondary palette data
783; = 03h Get secondary palette data
784; = 80h Set palette data during VRetrace
785; CX = Number of entries to update (<= 256)
786; DX = First entry to update
787; ES:DI = Table of palette values
788; Output:
789; AX = VBE Return Status
790;
791; Notes:
792; Secondary palette support is a "future extension".
793; Attempts to set/get it should return status 02h.
794;
795; In VBE 3.0, reading palette data is optional and
796; subfunctions 01h and 03h may return failure.
797;
798; The format of palette entries is as follows:
799;
800; PaletteEntry struc
801; Blue db ? ; Blue channel value (6 or 8 bits)
802; Green db ? ; Green channel value (6 or 8 bits)
803; Red db ? ; Red channel value (6 or 8 bits)
804; Padding db ? ; DWORD alignment byte (unused)
805; PaletteEntry ends
806;
807; Most applications use VGA DAC registers directly to
808; set/get palette in VBE modes. However, subfn 4F09h is
809; required for NonVGA controllers (eg. XGA).
810;
811vbe_biosfn_set_get_palette_data:
812 test bl, bl
813 jz set_palette_data
814 cmp bl, 01
815 je get_palette_data
816 cmp bl, 03
817 jbe vbe_09_nohw
818 cmp bl, 80h
819 jne vbe_09_unsupported
820if 0
821 ; this is where we could wait for vertical retrace
822endif
823set_palette_data:
824 pushad
825 push ds
826 push es
827 pop ds
828 mov al, dl
829 mov dx, VGAREG_DAC_WRITE_ADDRESS
830 out dx, al
831 inc dx
832 mov si, di
833set_pal_loop:
834 lodsd
835 ror eax, 16
836 out dx, al
837 rol eax, 8
838 out dx, al
839 rol eax, 8
840 out dx, al
841 loop set_pal_loop
842 pop ds
843 popad
844vbe_09_ok:
845 mov ax, 004Fh
846 ret
847
848get_palette_data:
849 pushad
850 mov al, dl
851 mov dx, VGAREG_DAC_READ_ADDRESS
852 out dx, al
853 add dl, 2
854get_pal_loop:
855 xor eax, eax
856 in al, dx
857 shl eax, 8
858 in al, dx
859 shl eax, 8
860 in al, dx
861 stosd
862 loop get_pal_loop
863 popad
864 jmp vbe_09_ok
865
866vbe_09_unsupported:
867 mov ax, 014Fh
868 ret
869vbe_09_nohw:
870 mov ax, 024Fh
871 ret
872
873
874; Function 0Ah - Return VBE Protected Mode Interface
875;
876; Input: AX = 4F0Ah VBE 2.0 Protected Mode Interface
877; BL = 00h Return protected mode table
878; Output: AX = Status
879; ES = Real Mode Segment of Table
880; DI = Offset of Table
881; CX = Length of Table including protected mode code
882; (for copying purposes)
883;
884vbe_biosfn_return_protected_mode_interface:
885 test bl, bl
886 jnz _fail
887 mov di, 0C000h
888 mov es, di
889 mov di, offset vesa_pm_start
890 mov cx, vesa_pm_end - vesa_pm_start
891 sub cx, di
892 mov ax, 004Fh
893 ret
894_fail:
895 mov ax, 014fh
896 ret
897
898VGAROM ends
899
900;;
901;; 32-bit VBE interface
902;;
903
904.386
905
906public vesa_pm_start
907public vesa_pm_end
908
909VBE32 segment public use32 'CODE'
910
911 align 2
912
913vesa_pm_start:
914 dw vesa_pm_set_window - vesa_pm_start
915 dw vesa_pm_set_display_start - vesa_pm_start
916 dw vesa_pm_unimplemented - vesa_pm_start
917 dw vesa_pm_io_ports_table - vesa_pm_start
918vesa_pm_io_ports_table:
919 dw VBE_DISPI_IOPORT_INDEX
920 dw VBE_DISPI_IOPORT_INDEX + 1
921 dw VBE_DISPI_IOPORT_DATA
922 dw VBE_DISPI_IOPORT_DATA + 1
923 dw 3B6h
924 dw 3B7h
925 dw 0FFFFh
926 dw 0FFFFh
927
928vesa_pm_set_window:
929 cmp bx, 0
930 je vesa_pm_set_display_window1
931 mov ax, 0100h
932 ret
933vesa_pm_set_display_window1:
934 mov ax, dx
935 push dx
936 push ax
937 mov dx, VBE_DISPI_IOPORT_INDEX
938 mov ax, VBE_DISPI_INDEX_BANK
939 out dx, ax
940 pop ax
941 mov dx, VBE_DISPI_IOPORT_DATA
942 out dx, ax
943 in ax, dx
944 pop dx
945 cmp dx, ax
946 jne illegal_window
947 mov ax, 004Fh
948 ret
949illegal_window:
950 mov ax, 014Fh
951 ret
952vesa_pm_set_display_start:
953 cmp bl, 80h
954 je vesa_pm_set_display_start1_wait
955 cmp bl, 00
956 je vesa_pm_set_display_start1
957 mov ax, 0100h
958 ret
959vesa_pm_set_display_start1_wait:
960 push edx
961 mov dx, 03DAh ; @todo: use symbolic constant
962wnv_loop_32:
963 in al, dx
964 test al, 8
965 jnz wnv_loop_32
966wv_loop_32:
967 in al, dx
968 test al, 8
969 jz wv_loop_32
970 pop edx
971vesa_pm_set_display_start1:
972; convert offset to (X, Y) coordinate
973; (would be simpler to change Bochs VBE API...)
974 push eax
975 push ecx
976 push edx
977 push esi
978 push edi
979 shl edx, 16
980 and ecx, 0FFFFh
981 or ecx, edx
982 shl ecx, 2
983 mov eax, ecx
984 push eax
985 mov dx, VBE_DISPI_IOPORT_INDEX
986 mov ax, VBE_DISPI_INDEX_VIRT_WIDTH
987 out dx, ax
988 mov dx, VBE_DISPI_IOPORT_DATA
989 in ax, dx
990 movzx ecx, ax
991 mov dx, VBE_DISPI_IOPORT_INDEX
992 mov ax, VBE_DISPI_INDEX_BPP
993 out dx, ax
994 mov dx, VBE_DISPI_IOPORT_DATA
995 in ax, dx
996 movzx esi, ax
997 pop eax
998
999 cmp esi, 4
1000 jz bpp4_mode
1001 add esi, 7
1002 shr esi, 3
1003 imul ecx, esi
1004 xor edx, edx
1005 div ecx
1006 mov edi, eax
1007 mov eax, edx
1008 xor edx, edx
1009 div esi
1010 jmp set_xy_regs
1011
1012bpp4_mode:
1013 shr ecx, 1
1014 xor edx, edx
1015 div ecx
1016 mov edi, eax
1017 mov eax, edx
1018 shl eax, 1
1019
1020set_xy_regs:
1021 push dx
1022 push ax
1023 mov dx, VBE_DISPI_IOPORT_INDEX
1024 mov ax, VBE_DISPI_INDEX_X_OFFSET
1025 out dx, ax
1026 pop ax
1027 mov dx, VBE_DISPI_IOPORT_DATA
1028 out dx, ax
1029 pop dx
1030
1031 mov ax, di
1032 push dx
1033 push ax
1034 mov dx, VBE_DISPI_IOPORT_INDEX
1035 mov ax, VBE_DISPI_INDEX_Y_OFFSET
1036 out dx, ax
1037 pop ax
1038 mov dx, VBE_DISPI_IOPORT_DATA
1039 out dx, ax
1040 pop dx
1041
1042 pop edi
1043 pop esi
1044 pop edx
1045 pop ecx
1046 pop eax
1047 mov ax, 004fh
1048 ret
1049
1050vesa_pm_unimplemented:
1051 mov ax, 014Fh
1052 ret
1053vesa_pm_end:
1054
1055VBE32 ends
1056
1057 end
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette