1 // ============================================================================================
5 // ============================================================================================
7 // Copyright (C) 2001,2002 the LGPL VGABios developers Team
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 // ============================================================================================
25 // This VGA Bios is specific to the plex86/bochs Emulated VGA card.
26 // You can NOT drive any physical vga card with it.
28 // ============================================================================================
30 // This file contains code ripped from :
31 // - rombios.c of plex86
33 // This VGA Bios contains fonts from :
34 // - fntcol16.zip (c) by Joseph Gil avalable at :
35 // ftp://ftp.simtel.net/pub/simtelnet/msdos/screen/fntcol16.zip
36 // These fonts are public domain
38 // This VGA Bios is based on information taken from :
39 // - Kevin Lawton's vga card emulation for bochs/plex86
40 // - Ralf Brown's interrupts list available at http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html
41 // - Finn Thogersons' VGADOC4b available at http://home.worldonline.dk/~finth/
42 // - Michael Abrash's Graphics Programming Black Book
43 // - Francois Gervais' book "programmation des cartes graphiques cga-ega-vga" edited by sybex
44 // - DOSEMU 1.0.1 source code for several tables values and formulas
46 // Thanks for patches, comments and ideas to :
47 // - techt@pikeonline.net
49 // ============================================================================================
58 static Bit8u
read_byte();
59 static Bit16u
read_word();
60 static void write_byte();
61 static void write_word();
67 static Bit16u
get_SS();
71 static void unimplemented();
72 static void unknown();
74 static Bit8u
find_vga_entry();
76 static void memsetb();
77 static void memsetw();
78 static void memcpyb();
79 static void memcpyw();
81 static void biosfn_set_video_mode();
82 static void biosfn_set_cursor_shape();
83 static void biosfn_set_cursor_pos();
84 static void biosfn_get_cursor_pos();
85 static void biosfn_set_active_page();
86 static void biosfn_scroll();
87 static void biosfn_read_char_attr();
88 static void biosfn_write_char_attr();
89 static void biosfn_write_char_only();
90 static void biosfn_write_pixel();
91 static void biosfn_read_pixel();
92 static void biosfn_write_teletype();
93 static void biosfn_perform_gray_scale_summing();
94 static void biosfn_load_text_user_pat();
95 static void biosfn_load_text_8_14_pat();
96 static void biosfn_load_text_8_8_pat();
97 static void biosfn_load_text_8_16_pat();
98 static void biosfn_load_gfx_8_8_chars();
99 static void biosfn_load_gfx_user_chars();
100 static void biosfn_load_gfx_8_14_chars();
101 static void biosfn_load_gfx_8_8_dd_chars();
102 static void biosfn_load_gfx_8_16_chars();
103 static void biosfn_get_font_info();
104 static void biosfn_get_ega_info();
105 static void biosfn_alternate_prtsc();
106 static void biosfn_select_vert_res();
107 static void biosfn_switch_video_interface();
108 static void biosfn_enable_video_refresh_control();
109 static void biosfn_write_string();
110 static void biosfn_read_state_info();
111 static void biosfn_read_video_state_size();
112 static void biosfn_save_video_state();
113 static void biosfn_restore_video_state();
115 // This is for compiling with gcc2 and gcc3
116 #define ASM_START #asm
117 #define ASM_END #endasm
122 biosmem_initial_mode
= 0x10
123 biosmem_current_mode
= 0x49
124 biosmem_nb_cols
= 0x4a
125 biosmem_current_page
= 0x62
126 biosmem_current_msr
= 0x65
127 biosmem_char_height
= 0x85
128 biosmem_video_ctl
= 0x87
129 biosmem_switches
= 0x88
130 biosmem_modeset_ctl
= 0x89
131 biosmem_dcc_index
= 0x8a
133 vgareg_actl_address
= 0x03c0
134 vgareg_actl_read_data
= 0x03c1
135 vgareg_write_misc_output
= 0x03c2
136 vgareg_sequ_address
= 0x03c4
137 vgareg_pel_mask
= 0x03c6
138 vgareg_dac_read_address
= 0x03c7
139 vgareg_dac_write_address
= 0x03c8
140 vgareg_dac_data
= 0x03c9
141 vgareg_read_misc_output
= 0x03cc
142 vgareg_grdc_address
= 0x03ce
143 vgareg_actl_reset
= 0x03da
166 .byte
0x55, 0xaa /* BIOS signature, required for BIOS extensions */
168 .byte
0x40 /* BIOS extension length in units of 512 bytes */
173 jmp vgabios_init_func
176 .ascii
"Plex86/Bochs VGABios"
180 // Info from Bart Oldeman
199 .ascii
"(C) 2003 the LGPL VGABios developers Team"
204 .ascii
"This VGA/VBE Bios is released under the GNU LGPL"
210 .ascii
"Please visit :"
212 ;;.ascii
" . http://www.plex86.org"
214 .ascii
" . http://bochs.sourceforge.net"
216 .ascii
" . http://www.nongnu.org/vgabios"
222 ;; ============================================================================================
226 ;; ============================================================================================
232 ;; init basic bios vars
236 ;; init vbe functions
241 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
243 ;; display splash screen
244 call _display_splash_screen
246 ;; init video mode
and clear the screen
255 call _vbe_display_info
266 vgabios_int10_handler
:
281 call biosfn_get_video_mode
296 call biosfn_set_text_block_specifier
303 call biosfn_enable_default_palette_loading
308 call biosfn_enable_video_addressing
313 call biosfn_enable_grayscale_summing
318 call biosfn_enable_cursor_emulation
333 ;; We have to set ds to access the right data segment
346 #include "vgatables.h"
347 #include "vgafonts.h"
350 * Boot time harware inits
354 ;; switch to color mode
and enable CPU access
480 lines
359 ;; more than
64k
3C4
/04
367 mov bx
, #msg_vga_init
375 .ascii
"VGABios $Id$"
379 // --------------------------------------------------------------------------------------------
381 * Boot time bios area inits
389 ;; init detected hardware BIOS Area
390 mov bx
, #biosmem_initial_mode
395 ;; Just
for the first int10 find its children
397 ;; the
default char height
398 mov bx
, #biosmem_char_height
403 mov bx
, #biosmem_video_ctl
407 ;; Set the basic screen we have
408 mov bx
, #biosmem_switches
412 ;; Set the basic modeset options
413 mov bx
, #biosmem_modeset_ctl
417 ;; Set the
default MSR
418 mov bx
, #biosmem_current_msr
426 // --------------------------------------------------------------------------------------------
428 * Boot time Splash screen
430 static void display_splash_screen()
434 // --------------------------------------------------------------------------------------------
439 static void display_info()
446 mov si
,#vgabios_version
449 ;;mov si
,#vgabios_copyright
450 ;;call _display_string
452 ;;call _display_string
454 mov si
,#vgabios_license
456 mov si
,#vgabios_website
461 static void display_string()
463 // Get length of string
490 // --------------------------------------------------------------------------------------------
492 static void int10_debugmsg(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
493 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
495 // 0E is write char...
497 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX
,CX
,DX
);
501 // --------------------------------------------------------------------------------------------
503 * int10 main dispatcher
505 static void int10_func(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
506 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
513 biosfn_set_video_mode(GET_AL());
514 switch(GET_AL()&0x7F)
532 biosfn_set_cursor_shape(GET_CH(),GET_CL());
535 biosfn_set_cursor_pos(GET_BH(),DX
);
538 biosfn_get_cursor_pos(GET_BH(),&CX
,&DX
);
541 // Read light pen pos (unimplemented)
551 biosfn_set_active_page(GET_AL());
554 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP
);
557 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN
);
560 biosfn_read_char_attr(GET_BH(),&AX
);
563 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX
);
566 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX
);
569 biosfn_write_pixel(GET_BH(),GET_AL(),CX
,DX
);
572 biosfn_read_pixel(GET_BH(),CX
,DX
,&AX
);
575 // Ralf Brown Interrupt list is WRONG on bh(page)
576 // We do output only on the current page !
577 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR
);
580 // All other functions of group AH=0x10 rewritten in assembler
581 biosfn_perform_gray_scale_summing(BX
,CX
);
588 biosfn_load_text_user_pat(GET_AL(),ES
,BP
,CX
,DX
,GET_BL(),GET_BH());
592 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
596 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
600 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
603 biosfn_load_gfx_8_8_chars(ES
,BP
);
606 biosfn_load_gfx_user_chars(ES
,BP
,CX
,GET_BL(),GET_DL());
609 biosfn_load_gfx_8_14_chars(GET_BL());
612 biosfn_load_gfx_8_8_dd_chars(GET_BL());
615 biosfn_load_gfx_8_16_chars(GET_BL());
618 biosfn_get_font_info(GET_BH(),&ES
,&BP
,&CX
,&DX
);
631 biosfn_get_ega_info(&BX
,&CX
);
634 biosfn_alternate_prtsc();
637 biosfn_select_vert_res(GET_AL());
641 biosfn_switch_video_interface(GET_AL(),ES
,DX
);
645 biosfn_enable_video_refresh_control(GET_AL());
655 biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX
,GET_DH(),GET_DL(),ES
,BP
);
658 biosfn_read_state_info(BX
,ES
,DI
);
665 biosfn_read_video_state_size(CX
,&BX
);
668 biosfn_save_video_state(CX
,ES
,BX
);
671 biosfn_restore_video_state(CX
,ES
,BX
);
683 if (vbe_has_vbe_display()) {
687 vbe_biosfn_return_controller_information(&AX
,ES
,DI
);
690 vbe_biosfn_return_mode_information(&AX
,CX
,ES
,DI
);
693 vbe_biosfn_set_mode(&AX
,BX
,ES
,DI
);
696 vbe_biosfn_return_current_mode(&AX
,&BX
);
707 vbe_biosfn_display_window_control(&AX
,BX
,&DX
);
710 vbe_biosfn_set_get_logical_scan_line_length(&AX
,&BX
,&CX
,&DX
);
713 vbe_biosfn_set_get_display_start(&AX
,BX
,CX
,DX
);
761 // ============================================================================================
765 // ============================================================================================
767 static void biosfn_set_video_mode(mode
) Bit8u mode
;
768 {// mode: Bit 7 is 1 if no clear screen
770 // Should we clear the screen ?
771 Bit8u noclearmem
=mode
&0x80;
772 Bit8u line
,mmask
,*palette
;
773 Bit16u i
,twidth
,theight
,cheight
;
774 Bit8u modeset_ctl
,video_ctl
,vga_switches
;
778 if (vbe_has_vbe_display()) {
779 dispi_set_enable(VBE_DISPI_DISABLED
);
786 // find the entry in the video modes
787 line
=find_vga_entry(mode
);
790 printf("mode search %02x found line %02x\n",mode
,line
);
796 twidth
=vga_modes
[line
].twidth
;
797 theight
=vga_modes
[line
].theight
;
798 cheight
=vga_modes
[line
].cheight
;
800 // Read the bios vga control
801 video_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
803 // Read the bios vga switches
804 vga_switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
806 // Read the bios mode set control
807 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
809 // Then we know the number of lines
812 // if palette loading (bit 3 of modeset ctl = 0)
813 if((modeset_ctl
&0x08)==0)
815 outb(VGAREG_PEL_MASK
,vga_modes
[line
].pelmask
);
817 // Set the whole dac always, from 0
818 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
820 // From which palette
821 switch(vga_modes
[line
].dacmodel
)
835 // Always 256*3 values
836 for(i
=0;i
<0x0100;i
++)
837 {if(i
<=dac_regs
[vga_modes
[line
].dacmodel
])
838 {outb(VGAREG_DAC_DATA
,palette
[(i
*3)+0]);
839 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+1]);
840 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+2]);
843 {outb(VGAREG_DAC_DATA
,0);
844 outb(VGAREG_DAC_DATA
,0);
845 outb(VGAREG_DAC_DATA
,0);
848 if((modeset_ctl
&0x02)==0x02)
850 biosfn_perform_gray_scale_summing(0x00, 0x100);
854 // Reset Attribute Ctl flip-flop
855 inb(VGAREG_ACTL_RESET
);
858 for(i
=0;i
<=ACTL_MAX_REG
;i
++)
859 {outb(VGAREG_ACTL_ADDRESS
,i
);
860 outb(VGAREG_ACTL_WRITE_DATA
,actl_regs
[vga_modes
[line
].actlmodel
][i
]);
864 for(i
=0;i
<=SEQU_MAX_REG
;i
++)
865 {outb(VGAREG_SEQU_ADDRESS
,i
);
866 outb(VGAREG_SEQU_DATA
,sequ_regs
[vga_modes
[line
].sequmodel
][i
]);
870 for(i
=0;i
<=GRDC_MAX_REG
;i
++)
871 {outb(VGAREG_GRDC_ADDRESS
,i
);
872 outb(VGAREG_GRDC_DATA
,grdc_regs
[vga_modes
[line
].grdcmodel
][i
]);
875 // Set CRTC address VGA or MDA
876 crtc_addr
=vga_modes
[line
].memmodel
==MTEXT
?VGAREG_MDA_CRTC_ADDRESS
:VGAREG_VGA_CRTC_ADDRESS
;
879 for(i
=0;i
<=CRTC_MAX_REG
;i
++)
881 outb(crtc_addr
+1,crtc_regs
[vga_modes
[line
].crtcmodel
][i
]);
884 // Set the misc register
885 outb(VGAREG_WRITE_MISC_OUTPUT
,vga_modes
[line
].miscreg
);
888 outb(VGAREG_ACTL_ADDRESS
,0x20);
889 inb(VGAREG_ACTL_RESET
);
893 if(vga_modes
[line
].class==TEXT
)
895 memsetw(vga_modes
[line
].sstart
,0,0x0720,0x4000); // 32k
901 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x4000); // 32k
905 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
906 mmask
= inb( VGAREG_SEQU_DATA
);
907 outb( VGAREG_SEQU_DATA
, 0x0f ); // all planes
908 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x8000); // 64k
909 outb( VGAREG_SEQU_DATA
, mmask
);
915 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
,mode
);
916 write_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
,twidth
);
917 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
,vga_modes
[line
].slength
);
918 write_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
,crtc_addr
);
919 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
,theight
-1);
920 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
,cheight
);
921 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60|noclearmem
));
922 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,0xF9);
923 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
)&0x7f);
925 // FIXME We nearly have the good tables. to be reworked
926 write_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
,0x08); // 8 is VGA should be ok for now
927 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
,0x00);
928 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
+2,0x00);
931 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MSR
,0x00); // Unavailable on vanilla vga, but...
932 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAL
,0x00); // Unavailable on vanilla vga, but...
935 if(vga_modes
[line
].class==TEXT
)
937 biosfn_set_cursor_shape(0x06,0x07);
940 // Set cursor pos for page 0..7
942 biosfn_set_cursor_pos(i
,0x0000);
945 biosfn_set_active_page(0x00);
947 // Write the fonts in memory
948 if(vga_modes
[line
].class==TEXT
)
951 ;; copy
and activate
8x16 font
961 // Set the ints 0x1F and 0x43
963 SET_INT_VECTOR(0x1f, #0xC000, #_vgafont8+128*8)
969 SET_INT_VECTOR(0x43, #0xC000, #_vgafont8)
974 SET_INT_VECTOR(0x43, #0xC000, #_vgafont14)
979 SET_INT_VECTOR(0x43, #0xC000, #_vgafont16)
985 // --------------------------------------------------------------------------------------------
986 static void biosfn_set_cursor_shape (CH
,CL
)
988 {Bit16u cheight
,curs
,crtc_addr
;
995 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
,curs
);
997 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
998 cheight
= read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
);
999 if((modeset_ctl
&0x01) && (cheight
>8) && (CL
<8) && (CH
<0x20))
1003 CH
= ((CH
+1) * cheight
/ 8) -1;
1007 CH
= ((CL
+1) * cheight
/ 8) - 2;
1009 CL
= ((CL
+1) * cheight
/ 8) - 1;
1012 // CTRC regs 0x0a and 0x0b
1013 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1014 outb(crtc_addr
,0x0a);
1015 outb(crtc_addr
+1,CH
);
1016 outb(crtc_addr
,0x0b);
1017 outb(crtc_addr
+1,CL
);
1020 // --------------------------------------------------------------------------------------------
1021 static void biosfn_set_cursor_pos (page
, cursor
)
1022 Bit8u page
;Bit16u cursor
;
1024 Bit8u xcurs
,ycurs
,current
;
1025 Bit16u nbcols
,nbrows
,address
,crtc_addr
;
1027 // Should not happen...
1031 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*page
, cursor
);
1033 // Set the hardware cursor
1034 current
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1037 // Get the dimensions
1038 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1039 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1041 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1043 // Calculate the address knowing nbcols nbrows and page num
1044 address
=SCREEN_IO_START(nbcols
,nbrows
,page
)+xcurs
+ycurs
*nbcols
;
1046 // CRTC regs 0x0e and 0x0f
1047 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1048 outb(crtc_addr
,0x0e);
1049 outb(crtc_addr
+1,(address
&0xff00)>>8);
1050 outb(crtc_addr
,0x0f);
1051 outb(crtc_addr
+1,address
&0x00ff);
1055 // --------------------------------------------------------------------------------------------
1056 static void biosfn_get_cursor_pos (page
,shape
, pos
)
1057 Bit8u page
;Bit16u
*shape
;Bit16u
*pos
;
1062 write_word(ss
, shape
, 0);
1063 write_word(ss
, pos
, 0);
1066 // FIXME should handle VGA 14/16 lines
1067 write_word(ss
,shape
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
));
1068 write_word(ss
,pos
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_POS
+page
*2));
1071 // --------------------------------------------------------------------------------------------
1072 static void biosfn_set_active_page (page
)
1075 Bit16u cursor
,dummy
,crtc_addr
;
1076 Bit16u nbcols
,nbrows
,address
;
1082 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1083 line
=find_vga_entry(mode
);
1084 if(line
==0xFF)return;
1086 // Get pos curs pos for the right page
1087 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1089 if(vga_modes
[line
].class==TEXT
)
1091 // Get the dimensions
1092 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1093 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1095 // Calculate the address knowing nbcols nbrows and page num
1096 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1097 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
,address
);
1100 address
=SCREEN_IO_START(nbcols
,nbrows
,page
);
1104 address
= page
*vga_modes
[line
].slength
;
1107 // CRTC regs 0x0c and 0x0d
1108 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1109 outb(crtc_addr
,0x0c);
1110 outb(crtc_addr
+1,(address
&0xff00)>>8);
1111 outb(crtc_addr
,0x0d);
1112 outb(crtc_addr
+1,address
&0x00ff);
1114 // And change the BIOS page
1115 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
,page
);
1118 printf("Set active page %02x address %04x\n",page
,address
);
1121 // Display the cursor, now the page is active
1122 biosfn_set_cursor_pos(page
,cursor
);
1125 // --------------------------------------------------------------------------------------------
1126 static void biosfn_scroll (nblines
,attr
,rul
,cul
,rlr
,clr
,page
,dir
)
1127 Bit8u nblines
;Bit8u attr
;Bit8u rul
;Bit8u cul
;Bit8u rlr
;Bit8u clr
;Bit8u page
;Bit8u dir
;
1129 // page == 0xFF if current
1132 Bit16u nbcols
,nbrows
,i
;
1139 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1140 line
=find_vga_entry(mode
);
1141 if(line
==0xFF)return;
1143 // Get the dimensions
1144 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1145 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1147 // Get the current page
1149 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1151 if(vga_modes
[line
].class==TEXT
)
1153 // Compute the address
1154 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1156 printf("Scroll, address %04x (%04x %04x %02x)\n",address
,nbrows
,nbcols
,page
);
1159 if(rlr
>=nbrows
)rlr
=nbrows
-1;
1160 if(clr
>=nbcols
)clr
=nbcols
-1;
1161 if(nblines
>nbrows
)nblines
=0;
1163 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1165 memsetw(vga_modes
[line
].sstart
,address
,(Bit16u
)attr
*0x100+' ',nbrows
*nbcols
);
1170 {for(i
=rul
;i
<=rlr
;i
++)
1172 if((i
+nblines
>rlr
)||(nblines
==0))
1173 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1175 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
+nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1179 {for(i
=rlr
;i
>=rul
;i
--)
1181 if((i
<rul
+nblines
)||(nblines
==0))
1182 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1184 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
-nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1193 printf("Scroll in graphics mode ");
1199 // --------------------------------------------------------------------------------------------
1200 static void biosfn_read_char_attr (page
,car
)
1201 Bit8u page
;Bit16u
*car
;
1202 {Bit16u ss
=get_SS();
1203 Bit8u xcurs
,ycurs
,mode
,line
;
1204 Bit16u nbcols
,nbrows
,address
;
1205 Bit16u cursor
,dummy
;
1208 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1209 line
=find_vga_entry(mode
);
1210 if(line
==0xFF)return;
1212 // Get the cursor pos for the page
1213 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1214 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1216 // Get the dimensions
1217 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1218 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1220 if(vga_modes
[line
].class==TEXT
)
1222 // Compute the address
1223 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1225 write_word(ss
,car
,read_word(vga_modes
[line
].sstart
,address
));
1236 // --------------------------------------------------------------------------------------------
1237 static void write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
)
1238 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u cheight
;
1242 Bit16u addr
,dest
,src
;
1254 addr
=xcurs
+ycurs
*cheight
*nbcols
;
1255 src
= car
* cheight
;
1256 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1259 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1261 for(i
=0;i
<cheight
;i
++)
1267 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1268 read_byte(0xa000,dest
);
1269 if(fdata
[src
+i
]&mask
)
1271 write_byte(0xa000,dest
,attr
&0x0f);
1275 write_byte(0xa000,dest
,0x00);
1280 mov dx
, #vgareg_grdc_address
1290 // --------------------------------------------------------------------------------------------
1291 static void write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
)
1292 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u bpp
;
1294 Bit8u i
,j
,mask
,data
;
1296 Bit16u addr
,dest
,src
;
1299 addr
=(xcurs
*bpp
)+ycurs
*320;
1303 dest
=addr
+(i
>>1)*80;
1304 if (i
& 1) dest
+= 0x2000;
1310 data
= read_byte(0xb800,dest
);
1318 if (fdata
[src
+i
] & mask
)
1322 data
^= (attr
& 0x01) << (7-j
);
1326 data
|= (attr
& 0x01) << (7-j
);
1331 write_byte(0xb800,dest
,data
);
1339 data
= read_byte(0xb800,dest
);
1347 if (fdata
[src
+i
] & mask
)
1351 data
^= (attr
& 0x03) << ((3-j
)*2);
1355 data
|= (attr
& 0x03) << ((3-j
)*2);
1360 write_byte(0xb800,dest
,data
);
1367 // --------------------------------------------------------------------------------------------
1368 static void write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
)
1369 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;
1371 Bit8u i
,j
,mask
,data
;
1373 Bit16u addr
,dest
,src
;
1376 addr
=xcurs
*8+ycurs
*nbcols
*64;
1380 dest
=addr
+i
*nbcols
*8;
1385 if (fdata
[src
+i
] & mask
)
1389 write_byte(0xa000,dest
+j
,data
);
1395 // --------------------------------------------------------------------------------------------
1396 static void biosfn_write_char_attr (car
,page
,attr
,count
)
1397 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1399 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1400 Bit16u nbcols
,nbrows
,address
;
1401 Bit16u cursor
,dummy
;
1404 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1405 line
=find_vga_entry(mode
);
1406 if(line
==0xFF)return;
1408 // Get the cursor pos for the page
1409 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1410 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1412 // Get the dimensions
1413 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1414 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1416 if(vga_modes
[line
].class==TEXT
)
1418 // Compute the address
1419 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1421 dummy
=((Bit16u
)attr
<<8)+car
;
1422 memsetw(vga_modes
[line
].sstart
,address
,dummy
,count
);
1426 // FIXME gfx mode not complete
1427 cheight
=vga_modes
[line
].cheight
;
1428 bpp
=vga_modes
[line
].pixbits
;
1429 while((count
-->0) && (xcurs
<nbcols
))
1431 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1433 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1435 else if(vga_modes
[line
].memmodel
==CGA
)
1437 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1439 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1441 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1454 // --------------------------------------------------------------------------------------------
1455 static void biosfn_write_char_only (car
,page
,attr
,count
)
1456 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1458 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1459 Bit16u nbcols
,nbrows
,address
;
1460 Bit16u cursor
,dummy
;
1463 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1464 line
=find_vga_entry(mode
);
1465 if(line
==0xFF)return;
1467 // Get the cursor pos for the page
1468 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1469 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1471 // Get the dimensions
1472 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1473 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1475 if(vga_modes
[line
].class==TEXT
)
1477 // Compute the address
1478 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1481 {write_byte(vga_modes
[line
].sstart
,address
,car
);
1487 // FIXME gfx mode not complete
1488 cheight
=vga_modes
[line
].cheight
;
1489 bpp
=vga_modes
[line
].pixbits
;
1490 while((count
-->0) && (xcurs
<nbcols
))
1492 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1494 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1496 else if(vga_modes
[line
].memmodel
==CGA
)
1498 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1500 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1502 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1515 // --------------------------------------------------------------------------------------------
1519 je biosfn_set_border_color
1521 je biosfn_set_palette
1526 biosfn_set_border_color
:
1531 mov dx
, #vgareg_actl_reset
1533 mov dx
, #vgareg_actl_address
1546 mov dx
, #vgareg_actl_address
1549 mov dx
, #vgareg_actl_read_data
1553 mov dx
, #vgareg_actl_address
1557 jne set_intensity_loop
1570 mov dx
, #vgareg_actl_reset
1574 set_cga_palette_loop
:
1575 mov dx
, #vgareg_actl_address
1578 mov dx
, #vgareg_actl_read_data
1582 mov dx
, #vgareg_actl_address
1586 jne set_cga_palette_loop
1596 // --------------------------------------------------------------------------------------------
1597 static void biosfn_write_pixel (BH
,AL
,CX
,DX
) Bit8u BH
;Bit8u AL
;Bit16u CX
;Bit16u DX
;
1599 Bit8u mode
,line
,mask
,attr
,data
;
1603 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1604 line
=find_vga_entry(mode
);
1605 if(line
==0xFF)return;
1606 if(vga_modes
[line
].class==TEXT
)return;
1608 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1610 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1611 mask
= 0x01 << (7 - (CX
& 0x07));
1612 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1613 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1614 data
= read_byte(0xa000,addr
);
1617 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1619 write_byte(0xa000,addr
,AL
);
1620 outw(VGAREG_GRDC_ADDRESS
, 0xff08);
1621 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1622 outw(VGAREG_GRDC_ADDRESS
, 0x0003);
1624 else if(vga_modes
[line
].memmodel
==CGA
)
1626 if(vga_modes
[line
].pixbits
==2)
1628 addr
=(CX
>>2)+(DX
>>1)*80;
1632 addr
=(CX
>>3)+(DX
>>1)*80;
1634 if (DX
& 1) addr
+= 0x2000;
1635 data
= read_byte(0xb800,addr
);
1636 if(vga_modes
[line
].pixbits
==2)
1638 attr
= (AL
& 0x03) << ((3 - (CX
& 0x03)) * 2);
1639 mask
= 0x03 << ((3 - (CX
& 0x03)) * 2);
1643 attr
= (AL
& 0x01) << (7 - (CX
& 0x07));
1644 mask
= 0x01 << (7 - (CX
& 0x07));
1655 write_byte(0xb800,addr
,data
);
1657 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1659 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1660 write_byte(0xa000,addr
,AL
);
1670 // --------------------------------------------------------------------------------------------
1671 static void biosfn_read_pixel (BH
,CX
,DX
,AX
) Bit8u BH
;Bit16u CX
;Bit16u DX
;Bit16u
*AX
;
1673 Bit8u mode
,line
,mask
,attr
,data
,i
;
1678 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1679 line
=find_vga_entry(mode
);
1680 if(line
==0xFF)return;
1681 if(vga_modes
[line
].class==TEXT
)return;
1683 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1685 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1686 mask
= 0x01 << (7 - (CX
& 0x07));
1690 outw(VGAREG_GRDC_ADDRESS
, (i
<< 8) | 0x04);
1691 data
= read_byte(0xa000,addr
) & mask
;
1692 if (data
> 0) attr
|= (0x01 << i
);
1695 else if(vga_modes
[line
].memmodel
==CGA
)
1697 addr
=(CX
>>2)+(DX
>>1)*80;
1698 if (DX
& 1) addr
+= 0x2000;
1699 data
= read_byte(0xb800,addr
);
1700 if(vga_modes
[line
].pixbits
==2)
1702 attr
= (data
>> ((3 - (CX
& 0x03)) * 2)) & 0x03;
1706 attr
= (data
>> (7 - (CX
& 0x07))) & 0x01;
1709 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1711 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1712 attr
=read_byte(0xa000,addr
);
1721 write_word(ss
,AX
,(read_word(ss
,AX
) & 0xff00) | attr
);
1724 // --------------------------------------------------------------------------------------------
1725 static void biosfn_write_teletype (car
, page
, attr
, flag
)
1726 Bit8u car
;Bit8u page
;Bit8u attr
;Bit8u flag
;
1727 {// flag = WITH_ATTR / NO_ATTR
1729 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1730 Bit16u nbcols
,nbrows
,address
;
1731 Bit16u cursor
,dummy
;
1733 // special case if page is 0xff, use current page
1735 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1740 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1741 line
=find_vga_entry(mode
);
1742 if(line
==0xFF)return;
1744 // Get the cursor pos for the page
1745 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1746 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1748 // Get the dimensions
1749 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1750 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1774 biosfn_write_teletype(' ',page
,attr
,flag
);
1775 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1776 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1782 if(vga_modes
[line
].class==TEXT
)
1784 // Compute the address
1785 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1788 write_byte(vga_modes
[line
].sstart
,address
,car
);
1791 write_byte(vga_modes
[line
].sstart
,address
+1,attr
);
1795 // FIXME gfx mode not complete
1796 cheight
=vga_modes
[line
].cheight
;
1797 bpp
=vga_modes
[line
].pixbits
;
1798 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1800 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1802 else if(vga_modes
[line
].memmodel
==CGA
)
1804 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1806 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1808 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1821 // Do we need to wrap ?
1827 // Do we need to scroll ?
1829 {biosfn_scroll(0x01,0x07,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
1833 // Set the cursor for the page
1834 cursor
=ycurs
; cursor
<<=8; cursor
+=xcurs
;
1835 biosfn_set_cursor_pos(page
,cursor
);
1838 // --------------------------------------------------------------------------------------------
1840 biosfn_get_video_mode
:
1842 mov ax
, #biosmem_seg
1845 mov bx
, #biosmem_current_page
1850 mov bx
, #biosmem_video_ctl
1853 mov bx
, #biosmem_current_mode
1856 mov bx
, #biosmem_nb_cols
1863 // --------------------------------------------------------------------------------------------
1868 jmp biosfn_set_single_palette_reg
1872 jmp biosfn_set_overscan_border_color
1876 jmp biosfn_set_all_palette_reg
1880 jmp biosfn_toggle_intensity
1884 jmp biosfn_get_single_palette_reg
1888 jmp biosfn_read_overscan_border_color
1892 jmp biosfn_get_all_palette_reg
1896 jmp biosfn_set_single_dac_reg
1900 jmp biosfn_set_all_dac_reg
1904 jmp biosfn_select_video_dac_color_page
1908 jmp biosfn_read_single_dac_reg
1912 jmp biosfn_read_all_dac_reg
1916 jmp biosfn_set_pel_mask
1920 jmp biosfn_read_pel_mask
1923 jne int10_group_10_unknown
1924 jmp biosfn_read_video_dac_state
1925 int10_group_10_unknown
:
1931 biosfn_set_single_palette_reg
:
1936 mov dx
, #vgareg_actl_reset
1938 mov dx
, #vgareg_actl_address
1951 // --------------------------------------------------------------------------------------------
1953 biosfn_set_overscan_border_color
:
1956 call biosfn_set_single_palette_reg
1961 // --------------------------------------------------------------------------------------------
1963 biosfn_set_all_palette_reg
:
1969 mov dx
, #vgareg_actl_reset
1972 mov dx
, #vgareg_actl_address
1982 jne set_palette_loop
1997 // --------------------------------------------------------------------------------------------
1999 biosfn_toggle_intensity
:
2003 mov dx
, #vgareg_actl_reset
2005 mov dx
, #vgareg_actl_address
2008 mov dx
, #vgareg_actl_read_data
2014 mov dx
, #vgareg_actl_address
2024 // --------------------------------------------------------------------------------------------
2026 biosfn_get_single_palette_reg
:
2031 mov dx
, #vgareg_actl_reset
2033 mov dx
, #vgareg_actl_address
2036 mov dx
, #vgareg_actl_read_data
2039 mov dx
, #vgareg_actl_reset
2041 mov dx
, #vgareg_actl_address
2050 // --------------------------------------------------------------------------------------------
2052 biosfn_read_overscan_border_color
:
2056 call biosfn_get_single_palette_reg
2064 // --------------------------------------------------------------------------------------------
2066 biosfn_get_all_palette_reg
:
2074 mov dx
, #vgareg_actl_reset
2076 mov dx
, #vgareg_actl_address
2079 mov dx
, #vgareg_actl_read_data
2086 jne get_palette_loop
2087 mov dx
, #vgareg_actl_reset
2089 mov dx
, #vgareg_actl_address
2092 mov dx
, #vgareg_actl_read_data
2096 mov dx
, #vgareg_actl_reset
2098 mov dx
, #vgareg_actl_address
2108 // --------------------------------------------------------------------------------------------
2110 biosfn_set_single_dac_reg
:
2113 mov dx
, #vgareg_dac_write_address
2116 mov dx
, #vgareg_dac_data
2130 // --------------------------------------------------------------------------------------------
2132 biosfn_set_all_dac_reg
:
2137 mov dx
, #vgareg_dac_write_address
2143 mov dx
, #vgareg_dac_data
2166 // --------------------------------------------------------------------------------------------
2168 biosfn_select_video_dac_color_page
:
2172 mov dx
, #vgareg_actl_reset
2174 mov dx
, #vgareg_actl_address
2177 mov dx
, #vgareg_actl_read_data
2184 mov dx
, #vgareg_actl_address
2189 mov dx
, #vgareg_actl_reset
2191 mov dx
, #vgareg_actl_address
2211 // --------------------------------------------------------------------------------------------
2213 biosfn_read_single_dac_reg
:
2216 mov dx
, #vgareg_dac_read_address
2221 mov dx
, #vgareg_dac_data
2234 // --------------------------------------------------------------------------------------------
2236 biosfn_read_all_dac_reg
:
2241 mov dx
, #vgareg_dac_read_address
2247 mov dx
, #vgareg_dac_data
2270 // --------------------------------------------------------------------------------------------
2272 biosfn_set_pel_mask
:
2275 mov dx
, #vgareg_pel_mask
2283 // --------------------------------------------------------------------------------------------
2285 biosfn_read_pel_mask
:
2288 mov dx
, #vgareg_pel_mask
2296 // --------------------------------------------------------------------------------------------
2298 biosfn_read_video_dac_state
:
2301 mov dx
, #vgareg_actl_reset
2303 mov dx
, #vgareg_actl_address
2306 mov dx
, #vgareg_actl_read_data
2310 mov dx
, #vgareg_actl_reset
2312 mov dx
, #vgareg_actl_address
2315 mov dx
, #vgareg_actl_read_data
2323 mov dx
, #vgareg_actl_reset
2325 mov dx
, #vgareg_actl_address
2333 // --------------------------------------------------------------------------------------------
2334 static void biosfn_perform_gray_scale_summing (start
,count
)
2335 Bit16u start
;Bit16u count
;
2340 inb(VGAREG_ACTL_RESET
);
2341 outb(VGAREG_ACTL_ADDRESS
,0x00);
2343 for( index
= 0; index
< count
; index
++ )
2345 // set read address and switch to read mode
2346 outb(VGAREG_DAC_READ_ADDRESS
,start
);
2347 // get 6-bit wide RGB data values
2348 r
=inb( VGAREG_DAC_DATA
);
2349 g
=inb( VGAREG_DAC_DATA
);
2350 b
=inb( VGAREG_DAC_DATA
);
2352 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
2353 i
= ( ( 77*r
+ 151*g
+ 28*b
) + 0x80 ) >> 8;
2357 // set write address and switch to write mode
2358 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
2359 // write new intensity value
2360 outb( VGAREG_DAC_DATA
, i
&0xff );
2361 outb( VGAREG_DAC_DATA
, i
&0xff );
2362 outb( VGAREG_DAC_DATA
, i
&0xff );
2365 inb(VGAREG_ACTL_RESET
);
2366 outb(VGAREG_ACTL_ADDRESS
,0x20);
2369 // --------------------------------------------------------------------------------------------
2370 static void get_font_access()
2373 mov dx
, #vgareg_sequ_address
2382 mov dx
, #vgareg_grdc_address
2392 static void release_font_access()
2395 mov dx
, #vgareg_sequ_address
2404 mov dx
, #vgareg_read_misc_output
2411 mov dx
, #vgareg_grdc_address
2427 static void set_scan_lines(lines
) Bit8u lines
;
2429 Bit16u crtc_addr
,cols
,page
,vde
;
2430 Bit8u crtc_r9
,ovl
,rows
;
2432 crtc_addr
= read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2433 outb(crtc_addr
, 0x09);
2434 crtc_r9
= inb(crtc_addr
+1);
2435 crtc_r9
= (crtc_r9
& 0xe0) | (lines
- 1);
2436 outb(crtc_addr
+1, crtc_r9
);
2439 biosfn_set_cursor_shape(0x06,0x07);
2443 biosfn_set_cursor_shape(lines
-4,lines
-3);
2445 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, lines
);
2446 outb(crtc_addr
, 0x12);
2447 vde
= inb(crtc_addr
+1);
2448 outb(crtc_addr
, 0x07);
2449 ovl
= inb(crtc_addr
+1);
2450 vde
+= (((ovl
& 0x02) << 7) + ((ovl
& 0x40) << 3) + 1);
2452 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, rows
-1);
2453 cols
= read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
2454 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, rows
* cols
* 2);
2457 static void biosfn_load_text_user_pat (AL
,ES
,BP
,CX
,DX
,BL
,BH
) Bit8u AL
;Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit16u DX
;Bit8u BL
;Bit8u BH
;
2459 Bit16u blockaddr
,dest
,i
,src
;
2462 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2466 dest
= blockaddr
+ (DX
+ i
) * 32;
2467 memcpyb(0xA000, dest
, ES
, src
, BH
);
2469 release_font_access();
2476 static void biosfn_load_text_8_14_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2478 Bit16u blockaddr
,dest
,i
,src
;
2481 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2482 for(i
=0;i
<0x100;i
++)
2485 dest
= blockaddr
+ i
* 32;
2486 memcpyb(0xA000, dest
, 0xC000, vgafont14
+src
, 14);
2488 release_font_access();
2495 static void biosfn_load_text_8_8_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2497 Bit16u blockaddr
,dest
,i
,src
;
2500 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2501 for(i
=0;i
<0x100;i
++)
2504 dest
= blockaddr
+ i
* 32;
2505 memcpyb(0xA000, dest
, 0xC000, vgafont8
+src
, 8);
2507 release_font_access();
2514 // --------------------------------------------------------------------------------------------
2516 biosfn_set_text_block_specifier
:
2519 mov dx
, #vgareg_sequ_address
2528 // --------------------------------------------------------------------------------------------
2529 static void biosfn_load_text_8_16_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2531 Bit16u blockaddr
,dest
,i
,src
;
2534 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2535 for(i
=0;i
<0x100;i
++)
2538 dest
= blockaddr
+ i
* 32;
2539 memcpyb(0xA000, dest
, 0xC000, vgafont16
+src
, 16);
2541 release_font_access();
2548 static void biosfn_load_gfx_8_8_chars (ES
,BP
) Bit16u ES
;Bit16u BP
;
2554 static void biosfn_load_gfx_user_chars (ES
,BP
,CX
,BL
,DL
) Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit8u BL
;Bit8u DL
;
2560 static void biosfn_load_gfx_8_14_chars (BL
) Bit8u BL
;
2566 static void biosfn_load_gfx_8_8_dd_chars (BL
) Bit8u BL
;
2572 static void biosfn_load_gfx_8_16_chars (BL
) Bit8u BL
;
2578 // --------------------------------------------------------------------------------------------
2579 static void biosfn_get_font_info (BH
,ES
,BP
,CX
,DX
)
2580 Bit8u BH
;Bit16u
*ES
;Bit16u
*BP
;Bit16u
*CX
;Bit16u
*DX
;
2581 {Bit16u ss
=get_SS();
2585 write_word(ss
,ES
,read_word(0x00,0x1f*4));
2586 write_word(ss
,BP
,read_word(0x00,(0x1f*4)+2));
2589 write_word(ss
,ES
,read_word(0x00,0x43*4));
2590 write_word(ss
,BP
,read_word(0x00,(0x43*4)+2));
2593 write_word(ss
,ES
,0xC000);
2594 write_word(ss
,BP
,vgafont14
);
2597 write_word(ss
,ES
,0xC000);
2598 write_word(ss
,BP
,vgafont8
);
2601 write_word(ss
,ES
,0xC000);
2602 write_word(ss
,BP
,vgafont8
+128*8);
2605 write_word(ss
,ES
,0xC000);
2606 write_word(ss
,BP
,vgafont14alt
);
2609 write_word(ss
,ES
,0xC000);
2610 write_word(ss
,BP
,vgafont16
);
2613 write_word(ss
,ES
,0xC000);
2614 write_word(ss
,BP
,vgafont16alt
);
2618 printf("Get font info BH(%02x) was discarded\n",BH
);
2622 // Set byte/char of on screen font
2623 write_word(ss
,CX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
));
2625 // Set Highest char row
2626 write_word(ss
,DX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
));
2629 // --------------------------------------------------------------------------------------------
2630 static void biosfn_get_ega_info (BX
,CX
)
2631 Bit16u
*BX
;Bit16u
*CX
;
2632 {Bit16u ss
=get_SS();
2636 crtc
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2637 if(crtc
==VGAREG_MDA_CRTC_ADDRESS
)
2638 write_word(ss
,BX
,(1<<8)+0x0003);
2640 write_word(ss
,BX
,0x0003);
2642 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2643 write_word(ss
,CX
,(switches
&0x0f));
2646 // --------------------------------------------------------------------------------------------
2647 static void biosfn_alternate_prtsc()
2654 // --------------------------------------------------------------------------------------------
2655 static void biosfn_select_vert_res (res
)
2657 {// res : 00 200 lines, 01 350 lines, 02 400 lines
2658 Bit8u modeset
,switches
;
2660 modeset
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
2661 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2664 // set modeset ctl bit 7 and reset bit 4
2665 // set switches bit 3-0 to 0x08
2666 modeset
|=0x80;modeset
&=0xef;
2667 switches
&=0xf0;switches
|=0x08;
2670 // reset modeset ctl bit 7 and bit 4
2671 // set switches bit 3-0 to 0x09
2673 switches
&=0xf0;switches
|=0x09;
2676 // reset modeset ctl bit 7 and set bit 4
2677 // set switches bit 3-0 to 0x09
2678 modeset
|=0x10;modeset
&=0x7f;
2679 switches
&=0xf0;switches
|=0x09;
2683 printf("Select vert res (%02x) was discarded\n",res
);
2687 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,modeset
);
2688 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,switches
);
2691 // --------------------------------------------------------------------------------------------
2693 biosfn_enable_default_palette_loading
:
2700 mov ax
, #biosmem_seg
2702 mov bx
, #biosmem_modeset_ctl
2714 // --------------------------------------------------------------------------------------------
2716 biosfn_enable_video_addressing
:
2723 mov dx
, #vgareg_read_misc_output
2727 mov dx
, #vgareg_write_misc_output
2735 // --------------------------------------------------------------------------------------------
2737 biosfn_enable_grayscale_summing
:
2745 mov ax
, #biosmem_seg
2747 mov bx
, #biosmem_modeset_ctl
2759 // --------------------------------------------------------------------------------------------
2761 biosfn_enable_cursor_emulation
:
2768 mov ax
, #biosmem_seg
2770 mov bx
, #biosmem_modeset_ctl
2782 // --------------------------------------------------------------------------------------------
2783 static void biosfn_switch_video_interface (AL
,ES
,DX
) Bit8u AL
;Bit16u ES
;Bit16u DX
;
2789 static void biosfn_enable_video_refresh_control (AL
) Bit8u AL
;
2796 // --------------------------------------------------------------------------------------------
2797 static void biosfn_write_string (flag
,page
,attr
,count
,row
,col
,seg
,offset
)
2798 Bit8u flag
;Bit8u page
;Bit8u attr
;Bit16u count
;Bit8u row
;Bit8u col
;Bit16u seg
;Bit16u offset
;
2800 Bit16u newcurs
,oldcurs
,dummy
;
2803 // Read curs info for the page
2804 biosfn_get_cursor_pos(page
,&dummy
,&oldcurs
);
2806 // if row=0xff special case : use current cursor position
2808 {col
=oldcurs
&0x00ff;
2809 row
=(oldcurs
&0xff00)>>8;
2812 newcurs
=row
; newcurs
<<=8; newcurs
+=col
;
2813 biosfn_set_cursor_pos(page
,newcurs
);
2817 car
=read_byte(seg
,offset
++);
2819 attr
=read_byte(seg
,offset
++);
2821 biosfn_write_teletype(car
,page
,attr
,WITH_ATTR
);
2824 // Set back curs pos
2826 biosfn_set_cursor_pos(page
,oldcurs
);
2829 // --------------------------------------------------------------------------------------------
2833 je biosfn_read_display_code
2835 je biosfn_set_display_code
2840 biosfn_read_display_code
:
2843 mov ax
, #biosmem_seg
2845 mov bx
, #biosmem_dcc_index
2853 biosfn_set_display_code
:
2857 mov ax
, #biosmem_seg
2860 mov bx
, #biosmem_dcc_index
2866 mov bx
, #msg_alt_dcc
2879 .ascii
"Alternate Display code (%02x) was discarded"
2880 .byte
0x0d,0x0a,0x00
2884 // --------------------------------------------------------------------------------------------
2885 static void biosfn_read_state_info (BX
,ES
,DI
)
2886 Bit16u BX
;Bit16u ES
;Bit16u DI
;
2888 // Address of static functionality table
2889 write_word(ES
,DI
+0x00,&static_functionality
);
2890 write_word(ES
,DI
+0x02,0xC000);
2892 // Hard coded copy from BIOS area. Should it be cleaner ?
2893 memcpyb(ES
,DI
+0x04,BIOSMEM_SEG
,0x49,30);
2894 memcpyb(ES
,DI
+0x22,BIOSMEM_SEG
,0x84,3);
2896 write_byte(ES
,DI
+0x25,read_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
));
2897 write_byte(ES
,DI
+0x26,0);
2898 write_byte(ES
,DI
+0x27,16);
2899 write_byte(ES
,DI
+0x28,0);
2900 write_byte(ES
,DI
+0x29,8);
2901 write_byte(ES
,DI
+0x2a,2);
2902 write_byte(ES
,DI
+0x2b,0);
2903 write_byte(ES
,DI
+0x2c,0);
2904 write_byte(ES
,DI
+0x31,3);
2905 write_byte(ES
,DI
+0x32,0);
2907 memsetb(ES
,DI
+0x33,0,13);
2910 // --------------------------------------------------------------------------------------------
2911 static void biosfn_read_video_state_size (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2917 static void biosfn_save_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2923 static void biosfn_restore_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2930 // ============================================================================================
2934 // ============================================================================================
2936 // --------------------------------------------------------------------------------------------
2937 static Bit8u
find_vga_entry(mode
)
2941 for(i
=0;i
<=MODE_MAX
;i
++)
2942 if(vga_modes
[i
].svgamode
==mode
)
2949 /* =========================================================== */
2953 /* =========================================================== */
2955 // --------------------------------------------------------------------------------------------
2956 static void memsetb(seg
,offset
,value
,count
)
2971 mov cx
, 10[bp
] ; count
2974 mov ax
, 4[bp
] ; segment
2976 mov ax
, 6[bp
] ; offset
2978 mov al
, 8[bp
] ; value
2993 // --------------------------------------------------------------------------------------------
2994 static void memsetw(seg
,offset
,value
,count
)
3009 mov cx
, 10[bp
] ; count
3012 mov ax
, 4[bp
] ; segment
3014 mov ax
, 6[bp
] ; offset
3016 mov ax
, 8[bp
] ; value
3031 // --------------------------------------------------------------------------------------------
3032 static void memcpyb(dseg
,doffset
,sseg
,soffset
,count
)
3050 mov cx
, 12[bp
] ; count
3053 mov ax
, 4[bp
] ; dsegment
3055 mov ax
, 6[bp
] ; doffset
3057 mov ax
, 8[bp
] ; ssegment
3059 mov ax
, 10[bp
] ; soffset
3077 // --------------------------------------------------------------------------------------------
3078 static void memcpyw(dseg
,doffset
,sseg
,soffset
,count
)
3096 mov cx
, 12[bp
] ; count
3099 mov ax
, 4[bp
] ; dsegment
3101 mov ax
, 6[bp
] ; doffset
3103 mov ax
, 8[bp
] ; ssegment
3105 mov ax
, 10[bp
] ; soffset
3123 /* =========================================================== */
3125 * These functions where ripped from Kevin's rombios.c
3127 /* =========================================================== */
3129 // --------------------------------------------------------------------------------------------
3131 read_byte(seg
, offset
)
3141 mov ax
, 4[bp
] ; segment
3143 mov bx
, 6[bp
] ; offset
3145 ;; al
= return value (byte
)
3153 // --------------------------------------------------------------------------------------------
3155 read_word(seg
, offset
)
3165 mov ax
, 4[bp
] ; segment
3167 mov bx
, 6[bp
] ; offset
3169 ;; ax
= return value (word
)
3177 // --------------------------------------------------------------------------------------------
3179 write_byte(seg
, offset
, data
)
3191 mov ax
, 4[bp
] ; segment
3193 mov bx
, 6[bp
] ; offset
3194 mov al
, 8[bp
] ; data byte
3195 mov
[bx
], al
; write data byte
3204 // --------------------------------------------------------------------------------------------
3206 write_word(seg
, offset
, data
)
3218 mov ax
, 4[bp
] ; segment
3220 mov bx
, 6[bp
] ; offset
3221 mov ax
, 8[bp
] ; data word
3222 mov
[bx
], ax
; write data word
3231 // --------------------------------------------------------------------------------------------
3266 // --------------------------------------------------------------------------------------------
3288 // --------------------------------------------------------------------------------------------
3318 void unimplemented()
3320 printf("--> Unimplemented\n");
3325 printf("--> Unknown int10\n");
3329 // --------------------------------------------------------------------------------------------
3333 Bit8u c
, format_char
;
3335 unsigned format_width
, i
;
3337 Bit16u arg_seg
, arg
, digit
, nibble
, shift_count
;
3345 while (c
= read_byte(0xc000, s
)) {
3350 else if (in_format
) {
3351 if ( (c
>='0') && (c
<='9') ) {
3352 format_width
= (format_width
* 10) + (c
- '0');
3354 else if (c
== 'x') {
3355 arg_ptr
++; // increment to next arg
3356 arg
= read_word(arg_seg
, arg_ptr
);
3357 if (format_width
== 0)
3360 digit
= format_width
- 1;
3361 for (i
=0; i
<format_width
; i
++) {
3362 nibble
= (arg
>> (4 * digit
)) & 0x000f;
3364 outb(0x0500, nibble
+ '0');
3366 outb(0x0500, (nibble
- 10) + 'A');
3371 //else if (c == 'd') {
3386 // --------------------------------------------------------------------------------------------
3389 ;; DATA_SEG_DEFS_HERE
3393 .ascii
"vgabios ends here"
3397 ;; BLOCK_STRINGS_BEGIN