forked from fysnet/i440fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconio.asm
1316 lines (1170 loc) · 41.5 KB
/
conio.asm
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
comment |*******************************************************************
* Copyright (c) 1984-2024 Forever Young Software Benjamin David Lunt *
* *
* i440FX BIOS ROM v1.0 *
* FILE: conio.asm *
* *
* This code is freeware, not public domain. Please use respectfully. *
* *
* You may: *
* - use this code for learning purposes only. *
* - use this code in your own Operating System development. *
* - distribute any code that you produce pertaining to this code *
* as long as it is for learning purposes only, not for profit, *
* and you give credit where credit is due. *
* *
* You may NOT: *
* - distribute this code for any purpose other than listed above. *
* - distribute this code for profit. *
* *
* You MUST: *
* - include this whole comment block at the top of this file. *
* - include contact information to where the original source is located. *
* https://github.com/fysnet/i440fx *
* *
* DESCRIPTION: *
* conio include file *
* *
* BUILT WITH: NewBasic Assembler *
* http://www.fysnet/newbasic.htm *
* NBASM ver 00.27.14 *
* Command line: nbasm i440fx /z<enter> *
* *
* Last Updated: 8 Dec 2024 *
* *
****************************************************************************
* Notes: *
* *
***************************************************************************|
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; display a char to the screen using the VGA BIOS
; On entry:
; al = char to display
; On return:
; nothing
; destroys nothing
display_char proc near uses ax bx
; send to bochs debug ports
.if BX_VIRTUAL_PORTS
cmp al,13
je short @f
push dx
mov dx,BX_INFO_PORT
out dx,al
pop dx
@@:
.endif
.if DO_SERIAL_DEBUG
cmp al,13
je short @f
push ax
push dx
xor dx,dx ; first com port
mov ah,1
call debug_serial_out
pop dx
pop ax
@@:
.endif
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if we are in the graphics mode, call that function
push ax
push ds
call bios_get_ebda
mov ds,ax
mov bl,[EBDA_DATA->video_use_graphic]
pop ds
pop ax
or bl,bl
jz short @f
call vid_display_char
ret
@@: mov ah,0Eh ; print char service
mov bx,0x0007 ;
int 10h ; output the character
ret
display_char endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; display a string to the screen using the VGA BIOS
; On entry:
; ds:si -> asciiz string to display
; On return:
; nothing
; destroys nothing
display_string proc near uses ax si
cld
@@: lodsb
or al,al
jz short @f
call display_char
jmp short @b
@@: ret
display_string endp
; flags used in the bios_printf routine
PRINTF_IN_FORMAT equ 1
PRINTF_IS_LONG equ 2
PRINTF_IS_ZERO equ 4
PRINTF_IS_SPACE equ 8
PRINTF_IS_NEGATIVE equ 16
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; display a formatted string to the screen using the VGA BIOS (or our video 'driver')
; On entry:
; ds:si -> asciiz formatted string to display
; stack holds items to 'insert' (last pushed, first used)
; caller restores stack (cdecl)
; On return:
; nothing
; destroys nothing
;
; we support: i,d,u,x,X,c,s
; flags: l = use 32-bit arg
; 0 = zero pad (left side)
; space = space pad (left side)
; 1->9 = nibbles to print
bios_printf proc near uses all
; get the byte pointer to the first parameter
; it is just after the 'ret' value and before the 'all' above
mov bp,sp
add bp,((8 * 2) + 2) ; size of all registers pushed with 'all', plus the 'ret'
; bp -> first used parameter (if any)
; reset our flags
bios_printf_start:
xor dx,dx ; PRINTF_* flags above
xor bx,bx ; format width
bios_printf_start_1:
lodsb
or al,al
jz short bios_printf_done
cmp al,'%'
jne short @f
or dx,PRINTF_IN_FORMAT
jmp short bios_printf_start_1
@@: test dx,PRINTF_IN_FORMAT
jnz short @f
call display_char
jmp short bios_printf_start_1
; if it is a 0, zero pad to left
@@: cmp al,'0'
jne short @f
or dx,PRINTF_IS_ZERO
jmp short bios_printf_start_1
; if it is a space, space pad to left
@@: cmp al,' '
jne short @f
or dx,PRINTF_IS_SPACE
jmp short bios_printf_start_1
; if it is a 1->9, it is part of a width
@@: cmp al,'1'
jb short @f
cmp al,'9'
ja short @f
imul bx,bx,10
sub al,'0'
xor ah,ah
add bx,ax
jmp short bios_printf_start_1
; if the 'l' char is given, it is a 32-bit arg
@@: cmp al,'l'
jne short @f
or dx,PRINTF_IS_LONG
jmp short bios_printf_start_1
; if the char is 'x' or 'X', then print a hex value
@@: mov ah,al
and ah,0xDF
cmp ah,'X'
jne short @f
put_value: call print_value
jmp short bios_printf_start
; if the char is 'i', then print a dec value
@@: cmp al,'i'
je short put_value
; if the char is 'd', then print a dec value
cmp al,'d'
je short put_value
; if the char is 'u', then print a unsigned dec value
cmp al,'u'
je short put_value
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if the char is 'c', then print a char
cmp al,'c'
jne short @f
call get_arg
call display_char
jmp short bios_printf_start
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if the char is 's', then print a string
@@: cmp al,'s'
jne short @f
call get_arg
push si
mov si,ax
call display_string
pop si
jmp bios_printf_start
@@: ; we should not have gotten here, so we are going to return. done.
bios_printf_done:
ret
bios_printf endp
; gets an arg from [bp], using 'is_long'
; returns in ax or eax
get_arg proc near
test dx,PRINTF_IS_LONG
jnz short @f
mov ax,[bp]
add bp,2
ret
@@: mov eax,[bp]
add bp,4
ret
get_arg endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; display a formatted number
; On entry:
; bp -> current parameter
; al = 'X', 'x', 'd', 'i', 'u'
; bx = format width
; dx = flags
; On return:
; nothing
; destroys nothing
print_value proc near uses bx cx dx si di
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; save flags in di
mov di,dx
; save the token in dl
mov dl,al
xor eax,eax
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; get the arg
push dx
mov dx,di
call get_arg
pop dx
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; is it the 'x' or 'X'
mov dh,dl
and dh,0xDF
cmp dh,'X'
je short do_hexadecimal
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; print a decimal ('u', 'i', 'd')
is_decimal:
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if no width is given, use the default for the given arg
or bx,bx
jnz short @f
mov bx,5
test di,PRINTF_IS_LONG
jz short @f
mov bx,10
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if 'i' or 'd', then eax = signed
@@: cmp dl,'u'
je short is_unsigned
; if is_long, we need to sign extend ax to eax
test di,PRINTF_IS_LONG
jnz short @f
movsx eax,ax
@@: ; if it is negative, set '-' flag and negate eax
test eax,(1<<31)
jz short is_unsigned
or di,PRINTF_IS_NEGATIVE
neg eax
; we now have an unsigned value in eax
is_unsigned:
mov cx,bx
mov ebx,10
xor si,si
@@: xor edx,edx
div ebx
push dx
inc si
or eax,eax
loopnz @b
jmp short need_padding
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; print a hexadecimal ('X', 'x')
do_hexadecimal:
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; if no width is given, use the default for the given arg
or bx,bx
jnz short @f
mov bx,4
test di,PRINTF_IS_LONG
jz short @f
mov bx,8
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; upper case/lower case?
@@: mov dh,('A'-'9'-1)
cmp dl,'X'
je short @f
cmp dl,'x'
jne short is_decimal
mov dh,('a'-'9'-1)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
@@: mov cx,bx
xor si,si
@@: push ax
inc si
shr eax,4
loopnz @b
need_padding:
; are there padding spaces needed
jcxz short not_space
; did the user add the zero or space flag?
test di,PRINTF_IS_ZERO
jz short not_zero
; negative?
test di,PRINTF_IS_NEGATIVE
jz short @f
mov al,'-'
call display_char
and di,(~PRINTF_IS_NEGATIVE)
dec cx
jcxz short not_space
@@: mov al,'0'
@@: call display_char
loop @b
; don't allow the space to happen
jmp short not_space
not_zero: test di,PRINTF_IS_SPACE
jz short not_space
; negative?
test di,PRINTF_IS_NEGATIVE
jz short @f
dec cx
jcxz short neg_char
@@: mov al,' '
@@: call display_char
loop @b
neg_char: test di,PRINTF_IS_NEGATIVE
jz short not_space
mov al,'-'
call display_char
and di,(~PRINTF_IS_NEGATIVE)
; si = count of pushes
not_space: test di,PRINTF_IS_NEGATIVE
jz short @f
mov al,'-'
call display_char
@@: mov cx,si
do_hex: pop ax
and al,0x0F
cmp al,9
jbe short @f
add al,dh
@@: add al,'0'
call display_char
loop do_hex
ret
print_value endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; Bochs VBE Extensions (BGA)
; (https://wiki.osdev.org/Bochs_VBE_Extensions)
;
.enum VBE_DISPI_INDEX_ID, VBE_DISPI_INDEX_XRES, VBE_DISPI_INDEX_YRES, VBE_DISPI_INDEX_BPP, \
VBE_DISPI_INDEX_ENABLE, VBE_DISPI_INDEX_BANK, VBE_DISPI_INDEX_VIRT_WIDTH, VBE_DISPI_INDEX_VIRT_HEIGHT, \
VBE_DISPI_INDEX_X_OFFSET, VBE_DISPI_INDEX_Y_OFFSET
VBE_DISPI_DISABLED equ 0x00
VBE_DISPI_ENABLED equ 0x01
VBE_DISPI_LFB_ENABLED equ 0x40
VBE_DISPI_INDEX_PORT equ 0x1CE
VBE_DISPI_DATA_PORT equ 0x1CF
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; our graphics video stuff starts here
CONIO_CHAR_COLOR equ ((204 << 16) | (203 << 8) | 200) ; rgb
VID_FONT_WIDTH equ 8
VID_FONT_HEIGHT equ 14
VBE_DEFAULT_WIDTH equ ((1024 + 7) & ~0x7) ; in QEMU, must be a multiple of 8
VBE_DEFAULT_HEIGHT equ 768
VBE_DEFAULT_BPP equ 32
banner_res dw VBE_DEFAULT_WIDTH, VBE_DEFAULT_HEIGHT, 32
dw VBE_DEFAULT_WIDTH, VBE_DEFAULT_HEIGHT, 24
dw VBE_DEFAULT_WIDTH, VBE_DEFAULT_HEIGHT, 16
dw VBE_DEFAULT_WIDTH, VBE_DEFAULT_HEIGHT, 15
dw 800, 600, 16
dw 800, 600, 15
dw 800, 600, 8
dw 0
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; read a word from the BGA
; On entry:
; bx = index register
; On return:
; ax = value read
; destroys none
bga_read_word proc near uses dx
mov dx,VBE_DISPI_INDEX_PORT
mov ax,bx
out dx,ax
mov dx,VBE_DISPI_DATA_PORT
in ax,dx
ret
bga_read_word endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; write a word to the BGA
; On entry:
; ax = value to write
; bx = index register
; On return:
; nothing
; destroys none
bga_write_word proc near uses dx
push ax
mov dx,VBE_DISPI_INDEX_PORT
mov ax,bx
out dx,ax
pop ax
mov dx,VBE_DISPI_DATA_PORT
out dx,ax
ret
bga_write_word endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; create and start our banner screen
; On entry:
; ds = 0xE000
; On return:
; nothing
; destroys all general
put_banner proc near uses ds es
call bios_get_ebda
mov ds,ax
mov byte [EBDA_DATA->video_use_graphic],0
mov byte [EBDA_DATA->video_use_bga],0
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; check to see the the BGA is available
mov bx,VBE_DISPI_INDEX_ID
call bga_read_word
cmp ax,0xB0C2
jb short put_banner_no_bga
cmp ax,0xB0C5
ja short put_banner_no_bga
; find the BGA PCI device
mov ax,0xB102 ; find device
mov dx,0x1234 ; vendor id
mov cx,0x1111 ; device id
xor si,si ; first one
int 1Ah
jc short put_banner_no_bga
; get the BAR 0 address
mov dx,bx ; dx = bus/devfunc
mov bx,0x10 ; BAR0
call pci_config_read_dword
and eax,0xFFFFFFF0
mov [EBDA_DATA->video_ram],eax
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; BGA is available, so use it
; disable the BGA
mov ax,VBE_DISPI_DISABLED
mov bx,VBE_DISPI_INDEX_ENABLE
call bga_write_word
; set width to VBE_DEFAULT_WIDTH
mov ax,VBE_DEFAULT_WIDTH
mov bx,VBE_DISPI_INDEX_XRES
call bga_write_word
; set height to VBE_DEFAULT_HEIGHT
mov ax,VBE_DEFAULT_HEIGHT
mov bx,VBE_DISPI_INDEX_YRES
call bga_write_word
; set bpp to VBE_DEFAULT_BPP
mov ax,VBE_DEFAULT_BPP
mov bx,VBE_DISPI_INDEX_BPP
call bga_write_word
; enable the BGA
mov ax,(VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED)
mov bx,VBE_DISPI_INDEX_ENABLE
call bga_write_word
mov word [EBDA_DATA->video_width],VBE_DEFAULT_WIDTH
mov word [EBDA_DATA->video_height],VBE_DEFAULT_HEIGHT
mov byte [EBDA_DATA->video_bpp],VBE_DEFAULT_BPP
mov byte [EBDA_DATA->video_model],4
mov word [EBDA_DATA->video_bpscanline],(VBE_DEFAULT_WIDTH * ((VBE_DEFAULT_BPP + 1) / 8)) ; +1 to catch 15
mov byte [EBDA_DATA->video_use_graphic],1
mov byte [EBDA_DATA->video_use_bga],1
jmp put_banner_have_bga
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we first need to see if we have a VBE 2.0+ video
; adapter installed.
put_banner_no_bga:
mov ax,(EBDA_SEG - 0x20) ; we need 0x200 bytes
mov es,ax
xor di,di
mov dword es:[di],'2EBV'
mov ax,0x4F00
int 10h
cmp ax,0x004F
jne banner_bad_vesa
cmp dword es:[di],'ASEV'
jne banner_bad_vesa
cmp word es:[di+4],0x0200
jb banner_bad_vesa
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; VBE2 is supported, so get the information from the
; screen mode we desire
mov bx,offset banner_res
mov si,es:[di+0x0E+0]
mov ax,es:[di+0x0E+2]
mov es,ax
; loop through all modes trying to
; match a mode we specify
banner_res_loop:
push si
mov cx,64 ; don't do more than 64
@@: mov ax,es:[si]
push word cs:[bx+0] ; width
push word cs:[bx+2] ; height
push word cs:[bx+4] ; bpp
call vbe2_check_mode
add sp,6
or ax,ax ; if ax = 0, mode not accepted
jnz short @f
add si,2
cmp word es:[si],0xFFFF
loopne @b
pop si
add bx,6
cmp word cs:[bx+0],0x0000
jne short banner_res_loop
; we didn't find a mode we liked
jmp banner_bad_vesa
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; we found a mode we like (mode in ax)
; store the information in the EBDA
@@: pop si
; before we destroy es, get the version so we
; can get the correct scanline size
mov cx,es:[di+4]
mov dx,ax ; save mode in dx
; now point to the mode information
mov es,bx ; bx = seg of found mode info
mov eax,es:[0x0028]
mov [EBDA_DATA->video_ram],eax
mov ax,es:[0x0012]
mov [EBDA_DATA->video_width],ax
mov ax,es:[0x0014]
mov [EBDA_DATA->video_height],ax
mov al,es:[0x0019]
mov [EBDA_DATA->video_bpp],al
mov al,es:[0x001B]
mov [EBDA_DATA->video_model],al
; if the VESA mode is 3.00+, we get the
; scan line width from [0x0032], else from [0x0010]
mov ax,es:[0x0010]
cmp cx,0x0300
jb short @f
mov ax,es:[0x0032]
@@: mov [EBDA_DATA->video_bpscanline],ax
; color bitmap
mov al,es:[0x001F]
mov [EBDA_DATA->video_red_mask_sz],al
mov al,es:[0x0020]
mov [EBDA_DATA->video_red_pos],al
mov al,es:[0x0021]
mov [EBDA_DATA->video_grn_mask_sz],al
mov al,es:[0x0022]
mov [EBDA_DATA->video_grn_pos],al
mov al,es:[0x0023]
mov [EBDA_DATA->video_blu_mask_sz],al
mov al,es:[0x0024]
mov [EBDA_DATA->video_blu_pos],al
mov byte [EBDA_DATA->video_use_graphic],1
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; calculate our 'text' screen size
put_banner_have_bga:
push dx
xor dx,dx
mov ax,[EBDA_DATA->video_width]
mov bx,VID_FONT_WIDTH
div bx
mov [EBDA_DATA->vid_char_scrn_width],ax
xor dx,dx
mov ax,[EBDA_DATA->video_height]
mov bx,VID_FONT_HEIGHT
div bx
mov [EBDA_DATA->vid_char_scrn_height],ax
mov word [EBDA_DATA->vid_char_cur_x],0
mov word [EBDA_DATA->vid_char_cur_y],0
pop dx
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; set the function to call to display a pixel
call display_pixel_function
or ax,ax
jz short banner_bad_vesa
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; now switch to that mode
cmp byte [EBDA_DATA->video_use_bga],0
jne short @f
; use the VGA BIOS to switch to the mode
mov ax,0x4F02
mov bx,dx
int 10h
cmp ax,0x004F
jne short banner_bad_vesa
; display the bochs icon
@@: call banner_icon
; display the text banner
mov ax,BIOS_BASE2
mov ds,ax
mov si,offset banner_str
call bios_printf
ret
banner_bad_vesa:
mov ax,BIOS_BASE2
mov ds,ax
mov si,offset banner_str
call bios_printf
mov si,offset banner_no_vesa_str
call display_string
ret
put_banner endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; retrieve the mode information for a given screen mode and check
; to see if it matches our requested resolution
; On entry:
; ax = mode
; [bp+04 + 10] = bpp
; [bp+08 + 10] = height
; [bp+12 + 10] = width
; On return:
; ax = mode if accepted, 0 if not
; bx = segment where accepted mode info is stored
; (bx is preserved *unless* mode is accepted)
; destroys none
vbe2_check_mode proc near uses cx edx di es ; 10 bytes
push bp
mov bp,sp
mov cx,ax ; cx = mode
mov ax,(EBDA_SEG - 0x20 - 0x10) ; we need 0x100 bytes (below the video info we already got)
mov es,ax
xor di,di
mov ax,0x4F01
int 10h
cmp ax,0x004F
jne short bad_vesa_info
; check to see if it matches our requests
mov dx,es:[di+0]
; must be supported by both the card and the screen
; must be a graphics mode
; must have a linear mode
and dx,((1<<7) | (1<<4) | (1<<0))
cmp dx,((1<<7) | (1<<4) | (1<<0))
jne short bad_vesa_info
; linear address must be > 0
cmp dword es:[0x0028],0
je short bad_vesa_info
; memory model must be 4 (packed pixel) or 6 (direct color)
mov dl,es:[0x001B]
cmp dl,0x04
je short @f
cmp dl,0x06
jne short bad_vesa_info
@@: ; we have a valid screen mode, now check to
; see if it matches the requested resolution
movzx dx,byte es:[di+0x0019]
cmp dx,[bp+4+10] ; bpp
jne short bad_vesa_info
mov dx,es:[di+0x0014]
cmp dx,[bp+6+10] ; height
jne short bad_vesa_info
mov dx,es:[di+0x0012]
cmp dx,[bp+8+10] ; width
jne short bad_vesa_info
; we found a mode that matches our request
; return the mode and bx = segment of information
mov ax,cx
mov bx,es
mov sp,bp
pop bp
ret
bad_vesa_info:
xor ax,ax ; mode not accepted
mov sp,bp
pop bp
ret
vbe2_check_mode endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; restore the screen mode to the default bios mode
; on entry:
; nothing
; on return:
; nothing
; destroys nothing
display_restore_default proc near uses ax ds
mov ax,EBDA_SEG
mov ds,ax
; is the BGA active?
cmp byte [EBDA_DATA->video_use_bga],0
je short @f
; if so, disable it
mov ax,VBE_DISPI_DISABLED
mov bx,VBE_DISPI_INDEX_ENABLE
call bga_write_word
mov byte [EBDA_DATA->video_use_bga],0
@@: mov byte [EBDA_DATA->video_use_graphic],0
mov ax,0x0003
int 10h
ret
display_restore_default endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; If the Memory Model field in the Video Information block is returned as 4,
; the Mask and Size fields in the Info Block may be and usually are zero.
; Therefore, the pixels are assumed as follows:
; 8 bits per pixel: rrrgggbb
; 15 bits per pixel: xrrrrrgggggbbbbb
; 16 bits per pixel: rrrrrggggggbbbbb
; 24 bits per pixel: rrrrrrrrggggggggbbbbbbbb
; 32 bits per pixel: xxxxxxxxrrrrrrrrggggggggbbbbbbbb
; If the Memory Model field in the Video Information block is returned as 6,
; the Mask and Size fields in the Info Block should be valid.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; determine the 'display pixel' function and set it in the EBDA
; On entry:
; ds -> EBDA
; On return:
; ax = 0 = didn't find a suitable pixel format
; destroys none
display_pixel_function proc near uses bx cx
mov ah,[EBDA_DATA->video_bpp]
mov al,[EBDA_DATA->video_model]
cmp al,0x04
jne short function_model_06
mov bx,offset display_draw_pixel8
cmp ah,8
je function_model_done
mov bx,offset display_draw_pixel15
cmp ah,15
je function_model_done
mov bx,offset display_draw_pixel16
cmp ah,16
je function_model_done
mov bx,offset display_draw_pixel24
cmp ah,24
je function_model_done
mov bx,offset display_draw_pixel32
cmp ah,32
je function_model_done
function_model_error:
xor ax,ax
ret
function_model_06:
cmp ah,8
jne short @f
mov cx,[EBDA_DATA->video_red_mask_sz]
cmp cx,0x0503
jne short function_model_error
mov cx,[EBDA_DATA->video_grn_mask_sz]
cmp cx,0x0203
jne short function_model_error
mov cx,[EBDA_DATA->video_blu_mask_sz]
cmp cx,0x0002
jne short function_model_error
mov bx,offset display_draw_pixel8
jmp function_model_done
@@: cmp ah,15
jne short @f
mov cx,[EBDA_DATA->video_red_mask_sz]
cmp cx,0x0A05
jne short function_model_error
mov cx,[EBDA_DATA->video_grn_mask_sz]
cmp cx,0x0505
jne short function_model_error
mov cx,[EBDA_DATA->video_blu_mask_sz]
cmp cx,0x0005
jne short function_model_error
mov bx,offset display_draw_pixel15
jmp function_model_done
@@: cmp ah,16
jne short @f
mov cx,[EBDA_DATA->video_red_mask_sz]
cmp cx,0x0B05
jne short function_model_error
mov cx,[EBDA_DATA->video_grn_mask_sz]
cmp cx,0x0506
jne short function_model_error
mov cx,[EBDA_DATA->video_blu_mask_sz]
cmp cx,0x0005
jne short function_model_error
mov bx,offset display_draw_pixel16
jmp short function_model_done
@@: cmp ah,24
jne short @f
mov cx,[EBDA_DATA->video_red_mask_sz]
cmp cx,0x1008
jne function_model_error
mov cx,[EBDA_DATA->video_grn_mask_sz]
cmp cx,0x0808
jne function_model_error
mov cx,[EBDA_DATA->video_blu_mask_sz]
cmp cx,0x0008
jne function_model_error
mov bx,offset display_draw_pixel24
jmp short function_model_done
@@: cmp ah,32
jne short @f
mov cx,[EBDA_DATA->video_red_mask_sz]
cmp cx,0x1008
jne function_model_error
mov cx,[EBDA_DATA->video_grn_mask_sz]
cmp cx,0x0808
jne function_model_error
mov cx,[EBDA_DATA->video_blu_mask_sz]
cmp cx,0x0008
jne function_model_error
mov bx,offset display_draw_pixel32
jmp short function_model_done
@@: jmp function_model_error
function_model_done:
mov [EBDA_DATA->vid_display_pixel],bx
mov word [EBDA_DATA->vid_display_pixel_seg],BIOS_BASE
mov ax,bx
ret
display_pixel_function endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; draw an 8-bit pixel
; rrrgggbb
; on entry:
; eax = 32-bit pixel to draw
; edi = position to draw
; on return
; edi = edi + 1
; * must be a far call *
display_draw_pixel8 proc far uses eax ebx ecx
; convert from 00000000rrrrrrrrggggggggbbbbbbbb
; to rrrgggbb
mov ebx,eax
mov ecx,eax
and eax,0x00E00000 ; red
shr eax,16
and bx,0x0000E000 ; green
shr bx,11
and cx,0x000000C0 ; blue
shr cx,6
or ax,bx
or ax,cx
mov fs:[edi],al
add edi,1
retf
display_draw_pixel8 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; draw an 15-bit pixel
; xrrrrrgggggbbbbb
; on entry:
; eax = 32-bit pixel to draw
; edi = position to draw
; on return
; edi = edi + 2
; * must be a far call *
display_draw_pixel15 proc far uses eax ebx ecx
; convert from 00000000rrrrrrrrggggggggbbbbbbbb
; to xrrrrrgggggbbbbb
mov ebx,eax
mov ecx,eax
and eax,0x00F80000 ; red
shr eax,9
and bx,0x0000F800 ; green
shr bx,6
and cx,0x000000F8 ; blue
shr cx,3
or ax,bx
or ax,cx
mov fs:[edi],ax
add edi,2
retf
display_draw_pixel15 endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; draw an 16-bit pixel
; rrrrrggggggbbbbb
; on entry:
; eax = 32-bit pixel to draw
; edi = position to draw
; on return
; edi = edi + 2
; * must be a far call *
display_draw_pixel16 proc far uses eax ebx ecx
; convert from 00000000rrrrrrrrggggggggbbbbbbbb
; to rrrrrggggggbbbbb
mov ebx,eax
mov ecx,eax
and eax,0x00F80000 ; red
shr eax,8
and bx,0x0000FC00 ; green
shr bx,5
and cx,0x000000F8 ; blue
shr cx,3
or ax,bx