-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvbe.c
1456 lines (1320 loc) · 34.3 KB
/
vbe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ============================================================================================
//
// Copyright (C) 2002 Jeroen Janssen
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// ============================================================================================
//
// This VBE is part of the VGA Bios specific to the plex86/bochs Emulated VGA card.
// You can NOT drive any physical vga card with it.
//
// ============================================================================================
//
// This VBE Bios is based on information taken from :
// - VESA BIOS EXTENSION (VBE) Core Functions Standard Version 3.0 located at www.vesa.org
//
// ============================================================================================
// defines available
// disable VESA/VBE2 check in vbe info
//#define VBE2_NO_VESA_CHECK
#include "vbe.h"
#include "vbetables.h"
// The current OEM Software Revision of this VBE Bios
#define VBE_OEM_SOFTWARE_REV 0x0002;
extern char vbebios_copyright;
extern char vbebios_vendor_name;
extern char vbebios_product_name;
extern char vbebios_product_revision;
ASM_START
// FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
_vbebios_copyright:
.ascii "Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/"
.byte 0x00
_vbebios_vendor_name:
.ascii "Bochs/Plex86 Developers"
.byte 0x00
_vbebios_product_name:
.ascii "Bochs/Plex86 VBE Adapter"
.byte 0x00
_vbebios_product_revision:
.ascii "$Id$"
.byte 0x00
_vbebios_info_string:
.ascii "Bochs VBE Display Adapter enabled"
.byte 0x0a,0x0d
.byte 0x0a,0x0d
.byte 0x00
_no_vbebios_info_string:
.ascii "NO Bochs VBE Support available!"
.byte 0x0a,0x0d
.byte 0x0a,0x0d
.byte 0x00
#if defined(USE_BX_INFO) || defined(DEBUG)
msg_vbe_init:
.ascii "VBE Bios $Id$"
.byte 0x0a,0x0d, 0x00
#endif
.align 2
vesa_pm_start:
dw vesa_pm_set_window - vesa_pm_start
dw vesa_pm_set_display_start - vesa_pm_start
dw vesa_pm_unimplemented - vesa_pm_start
dw vesa_pm_io_ports_table - vesa_pm_start
vesa_pm_io_ports_table:
dw VBE_DISPI_IOPORT_INDEX
dw VBE_DISPI_IOPORT_INDEX + 1
dw VBE_DISPI_IOPORT_DATA
dw VBE_DISPI_IOPORT_DATA + 1
dw 0xffff
dw 0xffff
USE32
vesa_pm_set_window:
cmp bx, #0x00
je vesa_pm_set_display_window1
mov ax, #0x0100
ret
vesa_pm_set_display_window1:
mov ax, dx
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BANK
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
in ax, dx
pop dx
cmp dx, ax
jne illegal_window
mov ax, #0x004f
ret
illegal_window:
mov ax, #0x014f
ret
vesa_pm_set_display_start:
cmp bl, #0x80
je vesa_pm_set_display_start1
cmp bl, #0x00
je vesa_pm_set_display_start1
mov ax, #0x0100
ret
vesa_pm_set_display_start1:
; convert offset to (X, Y) coordinate
; (would be simpler to change Bochs VBE API...)
push eax
push ecx
push edx
push esi
push edi
shl edx, #16
and ecx, #0xffff
or ecx, edx
shl ecx, #2
mov eax, ecx
push eax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
movzx ecx, ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BPP
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
movzx esi, ax
pop eax
cmp esi, #4
jz bpp4_mode
add esi, #7
shr esi, #3
imul ecx, esi
xor edx, edx
div ecx
mov edi, eax
mov eax, edx
xor edx, edx
div esi
jmp set_xy_regs
bpp4_mode:
shr ecx, #1
xor edx, edx
div ecx
mov edi, eax
mov eax, edx
shl eax, #1
set_xy_regs:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_X_OFFSET
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
mov ax, di
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_Y_OFFSET
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
pop edi
pop esi
pop edx
pop ecx
pop eax
mov ax, #0x004f
ret
vesa_pm_unimplemented:
mov ax, #0x014f
ret
USE16
vesa_pm_end:
; DISPI ioport functions
dispi_get_id:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_ID
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
dispi_set_id:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_ID
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
ASM_END
static void dispi_set_xres(xres)
Bit16u xres;
{
ASM_START
push bp
mov bp, sp
push ax
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_XRES
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
mov ax, 4[bp] ; xres
out dx, ax
pop dx
pop ax
pop bp
ASM_END
}
static void dispi_set_yres(yres)
Bit16u yres;
{
outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_YRES);
outw(VBE_DISPI_IOPORT_DATA,yres);
}
static void dispi_set_bpp(bpp)
Bit16u bpp;
{
outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_BPP);
outw(VBE_DISPI_IOPORT_DATA,bpp);
}
ASM_START
; AL = bits per pixel / AH = bytes per pixel
dispi_get_bpp:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BPP
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
mov ah, al
shr ah, 3
test al, #0x07
jz get_bpp_noinc
inc ah
get_bpp_noinc:
pop dx
ret
; get display capabilities
_dispi_get_max_xres:
push dx
push bx
call dispi_get_enable
mov bx, ax
or ax, # VBE_DISPI_GETCAPS
call _dispi_set_enable
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_XRES
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
push ax
mov ax, bx
call _dispi_set_enable
pop ax
pop bx
pop dx
ret
_dispi_get_max_bpp:
push dx
push bx
call dispi_get_enable
mov bx, ax
or ax, # VBE_DISPI_GETCAPS
call _dispi_set_enable
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BPP
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
push ax
mov ax, bx
call _dispi_set_enable
pop ax
pop bx
pop dx
ret
_dispi_set_enable:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_ENABLE
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
dispi_get_enable:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_ENABLE
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
_dispi_set_bank:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BANK
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
dispi_get_bank:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BANK
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
ASM_END
static void dispi_set_bank_farcall()
{
ASM_START
cmp bx,#0x0100
je dispi_set_bank_farcall_get
or bx,bx
jnz dispi_set_bank_farcall_error
mov ax,dx
push dx
push ax
mov ax,# VBE_DISPI_INDEX_BANK
mov dx,# VBE_DISPI_IOPORT_INDEX
out dx,ax
pop ax
mov dx,# VBE_DISPI_IOPORT_DATA
out dx,ax
in ax,dx
pop dx
cmp dx,ax
jne dispi_set_bank_farcall_error
mov ax, #0x004f
retf
dispi_set_bank_farcall_get:
mov ax,# VBE_DISPI_INDEX_BANK
mov dx,# VBE_DISPI_IOPORT_INDEX
out dx,ax
mov dx,# VBE_DISPI_IOPORT_DATA
in ax,dx
mov dx,ax
retf
dispi_set_bank_farcall_error:
mov ax,#0x014F
retf
ASM_END
}
ASM_START
dispi_set_x_offset:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_X_OFFSET
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
dispi_get_x_offset:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_X_OFFSET
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
dispi_set_y_offset:
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_Y_OFFSET
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
dispi_get_y_offset:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_Y_OFFSET
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
vga_set_virt_width:
push ax
push bx
push dx
mov bx, ax
call dispi_get_bpp
cmp al, #0x04
ja set_width_svga
shr bx, #1
set_width_svga:
shr bx, #3
mov dx, # VGAREG_VGA_CRTC_ADDRESS
mov ah, bl
mov al, #0x13
out dx, ax
pop dx
pop bx
pop ax
ret
dispi_set_virt_width:
call vga_set_virt_width
push dx
push ax
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
out dx, ax
pop ax
mov dx, # VBE_DISPI_IOPORT_DATA
out dx, ax
pop dx
ret
dispi_get_virt_width:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_VIRT_WIDTH
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
dispi_get_virt_height:
push dx
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_VIRT_HEIGHT
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
pop dx
ret
_vga_compat_setup:
push ax
push dx
; set CRT X resolution
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_XRES
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
push ax
mov dx, # VGAREG_VGA_CRTC_ADDRESS
mov ax, #0x0011
out dx, ax
pop ax
push ax
shr ax, #3
dec ax
mov ah, al
mov al, #0x01
out dx, ax
pop ax
call vga_set_virt_width
; set CRT Y resolution
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_YRES
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
dec ax
push ax
mov dx, # VGAREG_VGA_CRTC_ADDRESS
mov ah, al
mov al, #0x12
out dx, ax
pop ax
mov al, #0x07
out dx, al
inc dx
in al, dx
and al, #0xbd
test ah, #0x01
jz bit8_clear
or al, #0x02
bit8_clear:
test ah, #0x02
jz bit9_clear
or al, #0x40
bit9_clear:
out dx, al
; other settings
mov dx, # VGAREG_VGA_CRTC_ADDRESS
mov ax, #0x0009
out dx, ax
mov al, #0x17
out dx, al
mov dx, # VGAREG_VGA_CRTC_DATA
in al, dx
or al, #0x03
out dx, al
mov dx, # VGAREG_ACTL_RESET
in al, dx
mov dx, # VGAREG_ACTL_ADDRESS
mov al, #0x10
out dx, al
mov dx, # VGAREG_ACTL_READ_DATA
in al, dx
or al, #0x01
mov dx, # VGAREG_ACTL_ADDRESS
out dx, al
mov al, #0x20
out dx, al
mov dx, # VGAREG_GRDC_ADDRESS
mov ax, #0x0506
out dx, ax
mov dx, # VGAREG_SEQU_ADDRESS
mov ax, #0x0f02
out dx, ax
; settings for >= 8bpp
mov dx, # VBE_DISPI_IOPORT_INDEX
mov ax, # VBE_DISPI_INDEX_BPP
out dx, ax
mov dx, # VBE_DISPI_IOPORT_DATA
in ax, dx
cmp al, #0x08
jb vga_compat_end
mov dx, # VGAREG_VGA_CRTC_ADDRESS
mov al, #0x14
out dx, al
mov dx, # VGAREG_VGA_CRTC_DATA
in al, dx
or al, #0x40
out dx, al
mov dx, # VGAREG_ACTL_RESET
in al, dx
mov dx, # VGAREG_ACTL_ADDRESS
mov al, #0x10
out dx, al
mov dx, # VGAREG_ACTL_READ_DATA
in al, dx
or al, #0x40
mov dx, # VGAREG_ACTL_ADDRESS
out dx, al
mov al, #0x20
out dx, al
mov dx, # VGAREG_SEQU_ADDRESS
mov al, #0x04
out dx, al
mov dx, # VGAREG_SEQU_DATA
in al, dx
or al, #0x08
out dx, al
mov dx, # VGAREG_GRDC_ADDRESS
mov al, #0x05
out dx, al
mov dx, # VGAREG_GRDC_DATA
in al, dx
and al, #0x9f
or al, #0x40
out dx, al
vga_compat_end:
pop dx
pop ax
ASM_END
// ModeInfo helper function
static ModeInfoListItem* mode_info_find_mode(mode, using_lfb)
Bit16u mode; Boolean using_lfb;
{
ModeInfoListItem *cur_info=&mode_info_list;
while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST)
{
if (cur_info->mode == mode)
{
if (!using_lfb)
{
return cur_info;
}
else if (cur_info->info.ModeAttributes & VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE)
{
return cur_info;
}
else
{
cur_info++;
}
}
else
{
cur_info++;
}
}
return 0;
}
ASM_START
; Has VBE display - Returns true if VBE display detected
_vbe_has_vbe_display:
push ds
push bx
mov ax, # BIOSMEM_SEG
mov ds, ax
mov bx, # BIOSMEM_VBE_FLAG
mov al, [bx]
and al, #0x01
xor ah, ah
pop bx
pop ds
ret
; VBE Init - Initialise the Vesa Bios Extension Code
; This function does a sanity check on the host side display code interface.
vbe_init:
mov ax, # VBE_DISPI_ID0
call dispi_set_id
call dispi_get_id
cmp ax, # VBE_DISPI_ID0
jne no_vbe_interface
push ds
push bx
mov ax, # BIOSMEM_SEG
mov ds, ax
mov bx, # BIOSMEM_VBE_FLAG
mov al, #0x01
mov [bx], al
pop bx
pop ds
mov ax, # VBE_DISPI_ID5
call dispi_set_id
no_vbe_interface:
#if defined(USE_BX_INFO) || defined(DEBUG)
mov bx, #msg_vbe_init
push bx
call _printf
inc sp
inc sp
#endif
ret
; VBE Display Info - Display information on screen about the VBE
vbe_display_info:
call _vbe_has_vbe_display
test ax, ax
jz no_vbe_flag
mov ax, #0xc000
mov ds, ax
mov si, #_vbebios_info_string
jmp _display_string
no_vbe_flag:
mov ax, #0xc000
mov ds, ax
mov si, #_no_vbebios_info_string
jmp _display_string
; helper function for memory size calculation
lmulul:
and eax, #0x0000FFFF
shl ebx, #16
or eax, ebx
SEG SS
mul eax, dword ptr [di]
mov ebx, eax
shr ebx, #16
ret
ASM_END
/** Function 00h - Return VBE Controller Information
*
* Input:
* AX = 4F00h
* ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
* (VbeSignature should be VBE2 when VBE 2.0 information is desired and
* the info block is 512 bytes in size)
* Output:
* AX = VBE Return Status
*
*/
void vbe_biosfn_return_controller_information(AX, ES, DI)
Bit16u *AX;Bit16u ES;Bit16u DI;
{
Bit16u ss=get_SS();
VbeInfoBlock vbe_info_block;
Bit16u status;
Bit16u result;
Bit16u vbe2_info;
Bit16u cur_mode=0;
Bit16u cur_ptr=34;
Bit16u size_64k;
ModeInfoListItem *cur_info=&mode_info_list;
status = read_word(ss, AX);
#ifdef DEBUG
printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES,DI,status);
#endif
vbe2_info = 0;
#ifdef VBE2_NO_VESA_CHECK
#else
// get vbe_info_block into local variable
memcpyb(ss, &vbe_info_block, ES, DI, sizeof(vbe_info_block));
// check for VBE2 signature
if (((vbe_info_block.VbeSignature[0] == 'V') &&
(vbe_info_block.VbeSignature[1] == 'B') &&
(vbe_info_block.VbeSignature[2] == 'E') &&
(vbe_info_block.VbeSignature[3] == '2')) ||
((vbe_info_block.VbeSignature[0] == 'V') &&
(vbe_info_block.VbeSignature[1] == 'E') &&
(vbe_info_block.VbeSignature[2] == 'S') &&
(vbe_info_block.VbeSignature[3] == 'A')) )
{
vbe2_info = 1;
#ifdef DEBUG
printf("VBE correct VESA/VBE2 signature found\n");
#endif
}
#endif
// VBE Signature
vbe_info_block.VbeSignature[0] = 'V';
vbe_info_block.VbeSignature[1] = 'E';
vbe_info_block.VbeSignature[2] = 'S';
vbe_info_block.VbeSignature[3] = 'A';
// VBE Version supported
vbe_info_block.VbeVersion = 0x0200;
// OEM String
vbe_info_block.OemStringPtr_Seg = 0xc000;
vbe_info_block.OemStringPtr_Off = &vbebios_copyright;
// Capabilities
vbe_info_block.Capabilities[0] = VBE_CAPABILITY_8BIT_DAC;
vbe_info_block.Capabilities[1] = 0;
vbe_info_block.Capabilities[2] = 0;
vbe_info_block.Capabilities[3] = 0;
// VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
vbe_info_block.VideoModePtr_Seg= ES ;
vbe_info_block.VideoModePtr_Off= DI + 34;
// VBE Total Memory (in 64k blocks)
outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIDEO_MEMORY_64K);
vbe_info_block.TotalMemory = inw(VBE_DISPI_IOPORT_DATA);
if (vbe2_info)
{
// OEM Stuff
vbe_info_block.OemSoftwareRev = VBE_OEM_SOFTWARE_REV;
vbe_info_block.OemVendorNamePtr_Seg = 0xc000;
vbe_info_block.OemVendorNamePtr_Off = &vbebios_vendor_name;
vbe_info_block.OemProductNamePtr_Seg = 0xc000;
vbe_info_block.OemProductNamePtr_Off = &vbebios_product_name;
vbe_info_block.OemProductRevPtr_Seg = 0xc000;
vbe_info_block.OemProductRevPtr_Off = &vbebios_product_revision;
// copy updates in vbe_info_block back
memcpyb(ES, DI, ss, &vbe_info_block, sizeof(vbe_info_block));
}
else
{
// copy updates in vbe_info_block back (VBE 1.x compatibility)
memcpyb(ES, DI, ss, &vbe_info_block, 256);
}
do
{
size_64k = (Bit16u)((Bit32u)cur_info->info.XResolution * cur_info->info.XResolution * cur_info->info.BitsPerPixel) >> 19;
if ((cur_info->info.XResolution <= dispi_get_max_xres()) &&
(cur_info->info.BitsPerPixel <= dispi_get_max_bpp()) &&
(size_64k <= vbe_info_block.TotalMemory)) {
#ifdef DEBUG
printf("VBE found mode %x => %x\n", cur_info->mode,cur_mode);
#endif
write_word(ES, DI + cur_ptr, cur_info->mode);
cur_mode++;
cur_ptr+=2;
} else {
#ifdef DEBUG
printf("VBE mode %x (xres=%x / bpp=%02x) not supported \n", cur_info->mode,cur_info->info.XResolution,cur_info->info.BitsPerPixel);
#endif
}
cur_info++;
} while (cur_info->mode != VBE_VESA_MODE_END_OF_LIST);
// Add vesa mode list terminator
write_word(ES, DI + cur_ptr, cur_info->mode);
result = 0x4f;
write_word(ss, AX, result);
}
/** Function 01h - Return VBE Mode Information
*
* Input:
* AX = 4F01h
* CX = Mode Number
* ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
* Output:
* AX = VBE Return Status
*
*/
void vbe_biosfn_return_mode_information(AX, CX, ES, DI)
Bit16u *AX;Bit16u CX; Bit16u ES;Bit16u DI;
{
Bit16u result=0x0100;
Bit16u ss=get_SS();
ModeInfoBlock info;
ModeInfoListItem *cur_info;
Boolean using_lfb;
Bit16u lfb_addr;
#ifdef DEBUG
printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES,DI,CX);
#endif
using_lfb=((CX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
CX = (CX & 0x1ff);
cur_info = mode_info_find_mode(CX, using_lfb, &cur_info);
if (cur_info != 0)
{
#ifdef DEBUG
printf("VBE found mode %x\n",CX);
#endif
memsetb(ss, &info, 0, sizeof(ModeInfoBlock));
memcpyb(ss, &info, 0xc000, &(cur_info->info), sizeof(ModeInfoBlockCompact));
if (using_lfb) {
info.NumberOfBanks = 1;
}
#ifdef PCI_VID
lfb_addr = pci_get_lfb_addr(PCI_VID);
#else
lfb_addr = 0;
#endif
if (lfb_addr > 0) {
info.PhysBasePtr = ((Bit32u)lfb_addr << 16);
}
if (info.WinAAttributes & VBE_WINDOW_ATTRIBUTE_RELOCATABLE) {
info.WinFuncPtr = 0xC0000000UL;
*(Bit16u *)&(info.WinFuncPtr) = (Bit16u)(dispi_set_bank_farcall);
}
result = 0x4f;
}
else
{
#ifdef DEBUG
printf("VBE *NOT* found mode %x\n",CX);
#endif
result = 0x100;
}
if (result == 0x4f)
{
// copy updates in mode_info_block back
memcpyb(ES, DI, ss, &info, sizeof(info));
}
write_word(ss, AX, result);
}
/** Function 02h - Set VBE Mode
*
* Input:
* AX = 4F02h
* BX = Desired Mode to set
* ES:DI = Pointer to CRTCInfoBlock structure
* Output:
* AX = VBE Return Status
*
*/
void vbe_biosfn_set_mode(AX, BX, ES, DI)
Bit16u *AX;Bit16u BX; Bit16u ES;Bit16u DI;
{
Bit16u ss = get_SS();
Bit16u result;
ModeInfoListItem *cur_info;
Boolean using_lfb;
Bit8u no_clear;
Bit8u lfb_flag;
using_lfb=((BX & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER);
lfb_flag=using_lfb?VBE_DISPI_LFB_ENABLED:0;
no_clear=((BX & VBE_MODE_PRESERVE_DISPLAY_MEMORY) == VBE_MODE_PRESERVE_DISPLAY_MEMORY)?VBE_DISPI_NOCLEARMEM:0;
BX = (BX & 0x1ff);
//result=read_word(ss,AX);
// check for non vesa mode
if (BX<VBE_MODE_VESA_DEFINED)
{
Bit8u mode;
dispi_set_enable(VBE_DISPI_DISABLED);
// call the vgabios in order to set the video mode
// this allows for going back to textmode with a VBE call (some applications expect that to work)
mode=(BX & 0xff);
biosfn_set_video_mode(mode);
result = 0x4f;
}