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_set_border_color();
91 static void biosfn_set_palette();
92 static void biosfn_write_pixel();
93 static void biosfn_read_pixel();
94 static void biosfn_write_teletype();
95 static void biosfn_set_single_palette_reg();
96 static void biosfn_set_overscan_border_color();
97 static void biosfn_set_all_palette_reg();
98 static void biosfn_toggle_intensity();
99 static void biosfn_get_single_palette_reg();
100 static void biosfn_read_overscan_border_color();
101 static void biosfn_get_all_palette_reg();
102 static void biosfn_set_single_dac_reg();
103 static void biosfn_set_all_dac_reg();
104 static void biosfn_select_video_dac_color_page();
105 static void biosfn_read_single_dac_reg();
106 static void biosfn_read_all_dac_reg();
107 static void biosfn_set_pel_mask();
108 static void biosfn_read_pel_mask();
109 static void biosfn_read_video_dac_state();
110 static void biosfn_perform_gray_scale_summing();
111 static void biosfn_load_text_user_pat();
112 static void biosfn_load_text_8_14_pat();
113 static void biosfn_load_text_8_8_pat();
114 static void biosfn_set_text_block_specifier();
115 static void biosfn_load_text_8_16_pat();
116 static void biosfn_load_gfx_8_8_chars();
117 static void biosfn_load_gfx_user_chars();
118 static void biosfn_load_gfx_8_14_chars();
119 static void biosfn_load_gfx_8_8_dd_chars();
120 static void biosfn_load_gfx_8_16_chars();
121 static void biosfn_get_font_info();
122 static void biosfn_get_ega_info();
123 static void biosfn_alternate_prtsc();
124 static void biosfn_select_vert_res();
125 static void biosfn_enable_default_palette_loading();
126 static void biosfn_enable_video_addressing();
127 static void biosfn_enable_grayscale_summing();
128 static void biosfn_enable_cursor_emulation();
129 static void biosfn_switch_video_interface();
130 static void biosfn_enable_video_refresh_control();
131 static void biosfn_write_string();
132 static void biosfn_read_state_info();
133 static void biosfn_read_video_state_size();
134 static void biosfn_save_video_state();
135 static void biosfn_restore_video_state();
137 // This is for compiling with gcc2 and gcc3
138 #define ASM_START #asm
139 #define ASM_END #endasm
144 biosmem_initial_mode
= 0x10
145 biosmem_current_mode
= 0x49
146 biosmem_nb_cols
= 0x4a
147 biosmem_current_page
= 0x62
148 biosmem_current_msr
= 0x65
149 biosmem_char_height
= 0x85
150 biosmem_video_ctl
= 0x87
151 biosmem_switches
= 0x88
152 biosmem_modeset_ctl
= 0x89
153 biosmem_dcc_index
= 0x8a
176 .byte
0x55, 0xaa /* BIOS signature, required for BIOS extensions */
178 .byte
0x40 /* BIOS extension length in units of 512 bytes */
183 jmp vgabios_init_func
186 .ascii
"Plex86/Bochs VGABios"
190 // Info from Bart Oldeman
209 .ascii
"(C) 2003 the LGPL VGABios developers Team"
214 .ascii
"This VGA/VBE Bios is released under the GNU LGPL"
220 .ascii
"Please visit :"
222 ;;.ascii
" . http://www.plex86.org"
224 .ascii
" . http://bochs.sourceforge.net"
226 .ascii
" . http://www.nongnu.org/vgabios"
232 ;; ============================================================================================
236 ;; ============================================================================================
242 ;; init basic bios vars
246 ;; init vbe functions
251 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
253 ;; display splash screen
254 call _display_splash_screen
256 ;; init video mode
and clear the screen
265 call _vbe_display_info
276 vgabios_int10_handler
:
280 call biosfn_get_video_mode
293 ;; We have to set ds to access the right data segment
306 #include "vgatables.h"
307 #include "vgafonts.h"
310 * Boot time harware inits
314 ;; switch to color mode
and enable CPU access
480 lines
319 ;; more than
64k
3C4
/04
327 mov bx
, #msg_vga_init
335 .ascii
"VGABios $Id$"
339 // --------------------------------------------------------------------------------------------
341 * Boot time bios area inits
349 ;; init detected hardware BIOS Area
350 mov bx
, #biosmem_initial_mode
355 ;; Just
for the first int10 find its children
357 ;; the
default char height
358 mov bx
, #biosmem_char_height
363 mov bx
, #biosmem_video_ctl
367 ;; Set the basic screen we have
368 mov bx
, #biosmem_switches
372 ;; Set the basic modeset options
373 mov bx
, #biosmem_modeset_cl
377 ;; Set the
default MSR
378 mov bx
, #biosmem_current_msr
386 // --------------------------------------------------------------------------------------------
388 * Boot time Splash screen
390 static void display_splash_screen()
394 // --------------------------------------------------------------------------------------------
399 static void display_info()
406 mov si
,#vgabios_version
409 ;;mov si
,#vgabios_copyright
410 ;;call _display_string
412 ;;call _display_string
414 mov si
,#vgabios_license
416 mov si
,#vgabios_website
421 static void display_string()
423 // Get length of string
450 // --------------------------------------------------------------------------------------------
452 // --------------------------------------------------------------------------------------------
454 * int10 main dispatcher
456 static void int10_func(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
457 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
460 // 0E is write char...
462 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX
,CX
,DX
);
469 biosfn_set_video_mode(GET_AL());
470 switch(GET_AL()&0x7F)
488 biosfn_set_cursor_shape(GET_CH(),GET_CL());
491 biosfn_set_cursor_pos(GET_BH(),DX
);
494 biosfn_get_cursor_pos(GET_BH(),&CX
,&DX
);
497 // Read light pen pos (unimplemented)
507 biosfn_set_active_page(GET_AL());
510 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP
);
513 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN
);
516 biosfn_read_char_attr(GET_BH(),&AX
);
519 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX
);
522 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX
);
526 biosfn_set_border_color(GET_BL());
528 biosfn_set_palette(GET_BL());
531 biosfn_write_pixel(GET_BH(),GET_AL(),CX
,DX
);
534 biosfn_read_pixel(GET_BH(),CX
,DX
,&AX
);
537 // Ralf Brown Interrupt list is WRONG on bh(page)
538 // We do output only on the current page !
539 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR
);
545 biosfn_set_single_palette_reg(GET_BL(),GET_BH());
548 biosfn_set_overscan_border_color(GET_BH());
551 biosfn_set_all_palette_reg(ES
,DX
);
554 biosfn_toggle_intensity(GET_BL());
557 biosfn_get_single_palette_reg(GET_BL(),&BX
);
560 biosfn_read_overscan_border_color(&BX
);
563 biosfn_get_all_palette_reg(ES
,DX
);
566 biosfn_set_single_dac_reg(BX
,GET_CH(),GET_CL(),GET_DH());
569 biosfn_set_all_dac_reg(BX
,CX
,ES
,DX
);
572 biosfn_select_video_dac_color_page(GET_BL(),GET_BH());
575 biosfn_read_single_dac_reg(GET_BL(),&DX
,&CX
);
578 biosfn_read_all_dac_reg(BX
,CX
,ES
,DX
);
581 biosfn_set_pel_mask(GET_BL());
584 biosfn_read_pel_mask(&BX
);
587 biosfn_read_video_dac_state(&BX
);
590 biosfn_perform_gray_scale_summing(BX
,CX
);
603 biosfn_load_text_user_pat(GET_AL(),ES
,BP
,CX
,DX
,GET_BL(),GET_BH());
607 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
611 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
614 biosfn_set_text_block_specifier(GET_BL());
618 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
621 biosfn_load_gfx_8_8_chars(ES
,BP
);
624 biosfn_load_gfx_user_chars(ES
,BP
,CX
,GET_BL(),GET_DL());
627 biosfn_load_gfx_8_14_chars(GET_BL());
630 biosfn_load_gfx_8_8_dd_chars(GET_BL());
633 biosfn_load_gfx_8_16_chars(GET_BL());
636 biosfn_get_font_info(GET_BH(),&ES
,&BP
,&CX
,&DX
);
649 biosfn_get_ega_info(&BX
,&CX
);
652 biosfn_alternate_prtsc();
655 biosfn_select_vert_res(GET_AL());
659 biosfn_enable_default_palette_loading(GET_AL());
663 biosfn_enable_video_addressing(GET_AL());
667 biosfn_enable_grayscale_summing(GET_AL());
671 biosfn_enable_cursor_emulation(GET_AL());
675 biosfn_switch_video_interface(GET_AL(),ES
,DX
);
679 biosfn_enable_video_refresh_control(GET_AL());
689 biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX
,GET_DH(),GET_DL(),ES
,BP
);
692 biosfn_read_state_info(BX
,ES
,DI
);
699 biosfn_read_video_state_size(CX
,&BX
);
702 biosfn_save_video_state(CX
,ES
,BX
);
705 biosfn_restore_video_state(CX
,ES
,BX
);
717 if (vbe_has_vbe_display()) {
721 vbe_biosfn_return_controller_information(&AX
,ES
,DI
);
724 vbe_biosfn_return_mode_information(&AX
,CX
,ES
,DI
);
727 vbe_biosfn_set_mode(&AX
,BX
,ES
,DI
);
730 vbe_biosfn_return_current_mode(&AX
,&BX
);
741 vbe_biosfn_display_window_control(&AX
,BX
,&DX
);
744 vbe_biosfn_set_get_logical_scan_line_length(&AX
,&BX
,&CX
,&DX
);
747 vbe_biosfn_set_get_display_start(&AX
,BX
,CX
,DX
);
795 // ============================================================================================
799 // ============================================================================================
801 static void biosfn_set_video_mode(mode
) Bit8u mode
;
802 {// mode: Bit 7 is 1 if no clear screen
804 // Should we clear the screen ?
805 Bit8u noclearmem
=mode
&0x80;
806 Bit8u line
,mmask
,*palette
;
807 Bit16u i
,twidth
,theight
,cheight
;
808 Bit8u modeset_ctl
,video_ctl
,vga_switches
;
812 if (vbe_has_vbe_display()) {
813 dispi_set_enable(VBE_DISPI_DISABLED
);
820 // find the entry in the video modes
821 line
=find_vga_entry(mode
);
824 printf("mode search %02x found line %02x\n",mode
,line
);
830 twidth
=vga_modes
[line
].twidth
;
831 theight
=vga_modes
[line
].theight
;
832 cheight
=vga_modes
[line
].cheight
;
834 // Read the bios vga control
835 video_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
837 // Read the bios vga switches
838 vga_switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
840 // Read the bios mode set control
841 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
843 // Then we know the number of lines
846 // if palette loading (bit 3 of modeset ctl = 0)
847 if((modeset_ctl
&0x08)==0)
849 outb(VGAREG_PEL_MASK
,vga_modes
[line
].pelmask
);
851 // Set the whole dac always, from 0
852 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
854 // From which palette
855 switch(vga_modes
[line
].dacmodel
)
871 // Always 256*3 values
872 for(i
=0;i
<0x0100;i
++)
873 {if(i
<=dac_regs
[vga_modes
[line
].dacmodel
])
874 {outb(VGAREG_DAC_DATA
,palette
[(i
*3)+0]);
875 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+1]);
876 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+2]);
879 {outb(VGAREG_DAC_DATA
,0);
880 outb(VGAREG_DAC_DATA
,0);
881 outb(VGAREG_DAC_DATA
,0);
885 // Reset Attribute Ctl flip-flop
886 inb(VGAREG_ACTL_RESET
);
889 for(i
=0;i
<=ACTL_MAX_REG
;i
++)
890 {outb(VGAREG_ACTL_ADDRESS
,i
);
891 outb(VGAREG_ACTL_WRITE_DATA
,actl_regs
[vga_modes
[line
].actlmodel
][i
]);
895 for(i
=0;i
<=SEQU_MAX_REG
;i
++)
896 {outb(VGAREG_SEQU_ADDRESS
,i
);
897 outb(VGAREG_SEQU_DATA
,sequ_regs
[vga_modes
[line
].sequmodel
][i
]);
901 for(i
=0;i
<=GRDC_MAX_REG
;i
++)
902 {outb(VGAREG_GRDC_ADDRESS
,i
);
903 outb(VGAREG_GRDC_DATA
,grdc_regs
[vga_modes
[line
].grdcmodel
][i
]);
906 // Set CRTC address VGA or MDA
907 crtc_addr
=vga_modes
[line
].memmodel
==MTEXT
?VGAREG_MDA_CRTC_ADDRESS
:VGAREG_VGA_CRTC_ADDRESS
;
910 for(i
=0;i
<=CRTC_MAX_REG
;i
++)
912 outb(crtc_addr
+1,crtc_regs
[vga_modes
[line
].crtcmodel
][i
]);
915 // Set the misc register
916 outb(VGAREG_WRITE_MISC_OUTPUT
,vga_modes
[line
].miscreg
);
919 outb(VGAREG_ACTL_ADDRESS
,0x20);
920 inb(VGAREG_ACTL_RESET
);
924 if(vga_modes
[line
].class==TEXT
)
926 memsetw(vga_modes
[line
].sstart
,0,0x0720,0x4000); // 32k
932 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x4000); // 32k
936 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
937 mmask
= inb( VGAREG_SEQU_DATA
);
938 outb( VGAREG_SEQU_DATA
, 0x0f ); // all planes
939 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x8000); // 64k
940 outb( VGAREG_SEQU_DATA
, mmask
);
946 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
,mode
);
947 write_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
,twidth
);
948 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
,vga_modes
[line
].slength
);
949 write_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
,crtc_addr
);
950 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
,theight
-1);
951 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
,cheight
);
952 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60|noclearmem
));
953 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,0xF9);
954 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
)&0x7f);
956 // FIXME We nearly have the good tables. to be reworked
957 write_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
,0x08); // 8 is VGA should be ok for now
958 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
,0x00);
959 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
+2,0x00);
962 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MSR
,0x00); // Unavailable on vanilla vga, but...
963 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAL
,0x00); // Unavailable on vanilla vga, but...
966 if(vga_modes
[line
].class==TEXT
)
968 biosfn_set_cursor_shape(0x06,0x07);
971 // Set cursor pos for page 0..7
973 biosfn_set_cursor_pos(i
,0x0000);
976 biosfn_set_active_page(0x00);
978 // Write the fonts in memory
979 if(vga_modes
[line
].class==TEXT
)
982 ;; copy
and activate
8x16 font
992 // Set the ints 0x1F and 0x43
994 SET_INT_VECTOR(0x1f, #0xC000, #_vgafont8+128*8)
1000 SET_INT_VECTOR(0x43, #0xC000, #_vgafont8)
1005 SET_INT_VECTOR(0x43, #0xC000, #_vgafont14)
1010 SET_INT_VECTOR(0x43, #0xC000, #_vgafont16)
1016 // --------------------------------------------------------------------------------------------
1017 static void biosfn_set_cursor_shape (CH
,CL
)
1019 {Bit16u cheight
,curs
,crtc_addr
;
1025 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
,curs
);
1027 cheight
= read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
);
1028 if((cheight
>8) && (CL
<8) && (CH
<0x20))
1032 CH
= ((CH
+1) * cheight
/ 8) -1;
1036 CH
= ((CL
+1) * cheight
/ 8) - 2;
1038 CL
= ((CL
+1) * cheight
/ 8) - 1;
1041 // CTRC regs 0x0a and 0x0b
1042 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1043 outb(crtc_addr
,0x0a);
1044 outb(crtc_addr
+1,CH
);
1045 outb(crtc_addr
,0x0b);
1046 outb(crtc_addr
+1,CL
);
1049 // --------------------------------------------------------------------------------------------
1050 static void biosfn_set_cursor_pos (page
, cursor
)
1051 Bit8u page
;Bit16u cursor
;
1053 Bit8u xcurs
,ycurs
,current
;
1054 Bit16u nbcols
,nbrows
,address
,crtc_addr
;
1056 // Should not happen...
1060 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*page
, cursor
);
1062 // Set the hardware cursor
1063 current
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1066 // Get the dimensions
1067 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1068 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1070 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1072 // Calculate the address knowing nbcols nbrows and page num
1073 address
=SCREEN_IO_START(nbcols
,nbrows
,page
)+xcurs
+ycurs
*nbcols
;
1075 // CRTC regs 0x0e and 0x0f
1076 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1077 outb(crtc_addr
,0x0e);
1078 outb(crtc_addr
+1,(address
&0xff00)>>8);
1079 outb(crtc_addr
,0x0f);
1080 outb(crtc_addr
+1,address
&0x00ff);
1084 // --------------------------------------------------------------------------------------------
1085 static void biosfn_get_cursor_pos (page
,shape
, pos
)
1086 Bit8u page
;Bit16u
*shape
;Bit16u
*pos
;
1091 write_word(ss
, shape
, 0);
1092 write_word(ss
, pos
, 0);
1095 // FIXME should handle VGA 14/16 lines
1096 write_word(ss
,shape
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
));
1097 write_word(ss
,pos
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_POS
+page
*2));
1100 // --------------------------------------------------------------------------------------------
1101 static void biosfn_set_active_page (page
)
1104 Bit16u cursor
,dummy
,crtc_addr
;
1105 Bit16u nbcols
,nbrows
,address
;
1111 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1112 line
=find_vga_entry(mode
);
1113 if(line
==0xFF)return;
1115 // Get pos curs pos for the right page
1116 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1118 if(vga_modes
[line
].class==TEXT
)
1120 // Get the dimensions
1121 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1122 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1124 // Calculate the address knowing nbcols nbrows and page num
1125 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1126 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
,address
);
1129 address
=SCREEN_IO_START(nbcols
,nbrows
,page
);
1133 address
= page
*vga_modes
[line
].slength
;
1136 // CRTC regs 0x0c and 0x0d
1137 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1138 outb(crtc_addr
,0x0c);
1139 outb(crtc_addr
+1,(address
&0xff00)>>8);
1140 outb(crtc_addr
,0x0d);
1141 outb(crtc_addr
+1,address
&0x00ff);
1143 // And change the BIOS page
1144 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
,page
);
1147 printf("Set active page %02x address %04x\n",page
,address
);
1150 // Display the cursor, now the page is active
1151 biosfn_set_cursor_pos(page
,cursor
);
1154 // --------------------------------------------------------------------------------------------
1155 static void biosfn_scroll (nblines
,attr
,rul
,cul
,rlr
,clr
,page
,dir
)
1156 Bit8u nblines
;Bit8u attr
;Bit8u rul
;Bit8u cul
;Bit8u rlr
;Bit8u clr
;Bit8u page
;Bit8u dir
;
1158 // page == 0xFF if current
1161 Bit16u nbcols
,nbrows
,i
;
1168 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1169 line
=find_vga_entry(mode
);
1170 if(line
==0xFF)return;
1172 // Get the dimensions
1173 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1174 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1176 // Get the current page
1178 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1180 if(vga_modes
[line
].class==TEXT
)
1182 // Compute the address
1183 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1185 printf("Scroll, address %04x (%04x %04x %02x)\n",address
,nbrows
,nbcols
,page
);
1188 if(rlr
>=nbrows
)rlr
=nbrows
-1;
1189 if(clr
>=nbcols
)clr
=nbcols
-1;
1190 if(nblines
>nbrows
)nblines
=0;
1192 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1194 memsetw(vga_modes
[line
].sstart
,address
,(Bit16u
)attr
*0x100+' ',nbrows
*nbcols
);
1199 {for(i
=rul
;i
<=rlr
;i
++)
1201 if((i
+nblines
>rlr
)||(nblines
==0))
1202 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1204 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
+nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1208 {for(i
=rlr
;i
>=rul
;i
--)
1210 if((i
<rul
+nblines
)||(nblines
==0))
1211 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1213 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
-nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1222 printf("Scroll in graphics mode ");
1228 // --------------------------------------------------------------------------------------------
1229 static void biosfn_read_char_attr (page
,car
)
1230 Bit8u page
;Bit16u
*car
;
1231 {Bit16u ss
=get_SS();
1232 Bit8u xcurs
,ycurs
,mode
,line
;
1233 Bit16u nbcols
,nbrows
,address
;
1234 Bit16u cursor
,dummy
;
1237 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1238 line
=find_vga_entry(mode
);
1239 if(line
==0xFF)return;
1241 // Get the cursor pos for the page
1242 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1243 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1245 // Get the dimensions
1246 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1247 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1249 if(vga_modes
[line
].class==TEXT
)
1251 // Compute the address
1252 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1254 write_word(ss
,car
,read_word(vga_modes
[line
].sstart
,address
));
1265 // --------------------------------------------------------------------------------------------
1266 static void write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
)
1267 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u cheight
;
1271 Bit16u addr
,dest
,src
;
1283 addr
=xcurs
+ycurs
*cheight
*nbcols
;
1284 src
= car
* cheight
;
1285 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
1286 mmask
= inb( VGAREG_SEQU_DATA
);
1287 for(i
=0;i
<cheight
;i
++)
1290 outb( VGAREG_SEQU_DATA
, 0x0f );
1291 write_byte(0xa000,dest
,0x00);
1292 outb( VGAREG_SEQU_DATA
, attr
& 0x0f );
1293 write_byte(0xa000,dest
,fdata
[src
+i
]);
1295 outb( VGAREG_SEQU_DATA
, mmask
);
1298 // --------------------------------------------------------------------------------------------
1299 static void write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
)
1300 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u bpp
;
1302 Bit8u i
,j
,mask
,data
;
1304 Bit16u addr
,dest
,src
;
1307 addr
=(xcurs
*bpp
)+ycurs
*320;
1311 dest
=addr
+(i
>>1)*80;
1312 if (i
& 1) dest
+= 0x2000;
1318 data
= read_byte(0xb800,dest
);
1326 if (fdata
[src
+i
] & mask
)
1330 data
^= (attr
& 0x01) << (7-j
);
1334 data
|= (attr
& 0x01) << (7-j
);
1339 write_byte(0xb800,dest
,data
);
1347 data
= read_byte(0xb800,dest
);
1355 if (fdata
[src
+i
] & mask
)
1359 data
^= (attr
& 0x03) << ((3-j
)*2);
1363 data
|= (attr
& 0x03) << ((3-j
)*2);
1368 write_byte(0xb800,dest
,data
);
1375 // --------------------------------------------------------------------------------------------
1376 static void biosfn_write_char_attr (car
,page
,attr
,count
)
1377 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1379 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1380 Bit16u nbcols
,nbrows
,address
;
1381 Bit16u cursor
,dummy
;
1384 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1385 line
=find_vga_entry(mode
);
1386 if(line
==0xFF)return;
1388 // Get the cursor pos for the page
1389 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1390 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1392 // Get the dimensions
1393 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1394 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1396 if(vga_modes
[line
].class==TEXT
)
1398 // Compute the address
1399 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1401 dummy
=((Bit16u
)attr
<<8)+car
;
1402 memsetw(vga_modes
[line
].sstart
,address
,dummy
,count
);
1406 // FIXME gfx mode not complete
1407 cheight
=vga_modes
[line
].cheight
;
1408 bpp
=vga_modes
[line
].pixbits
;
1409 while((count
-->0) && (xcurs
<nbcols
))
1411 if(vga_modes
[line
].memmodel
==PLANAR4
)
1413 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1415 else if(vga_modes
[line
].memmodel
==CGA
)
1417 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1430 // --------------------------------------------------------------------------------------------
1431 static void biosfn_write_char_only (car
,page
,attr
,count
)
1432 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1434 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1435 Bit16u nbcols
,nbrows
,address
;
1436 Bit16u cursor
,dummy
;
1439 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1440 line
=find_vga_entry(mode
);
1441 if(line
==0xFF)return;
1443 // Get the cursor pos for the page
1444 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1445 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1447 // Get the dimensions
1448 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1449 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1451 if(vga_modes
[line
].class==TEXT
)
1453 // Compute the address
1454 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1457 {write_byte(vga_modes
[line
].sstart
,address
,car
);
1463 // FIXME gfx mode not complete
1464 cheight
=vga_modes
[line
].cheight
;
1465 bpp
=vga_modes
[line
].pixbits
;
1466 while((count
-->0) && (xcurs
<nbcols
))
1468 if(vga_modes
[line
].memmodel
==PLANAR4
)
1470 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1472 else if(vga_modes
[line
].memmodel
==CGA
)
1474 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1487 // --------------------------------------------------------------------------------------------
1488 static void biosfn_set_border_color (BL
) Bit8u BL
;
1489 // FIXME anybody using this function ?
1496 // --------------------------------------------------------------------------------------------
1497 static void biosfn_set_palette (BL
) Bit8u BL
;
1498 // FIXME anybody using this function ?
1505 // --------------------------------------------------------------------------------------------
1506 static void biosfn_write_pixel (BH
,AL
,CX
,DX
) Bit8u BH
;Bit8u AL
;Bit16u CX
;Bit16u DX
;
1508 Bit8u mode
,line
,mask
,attr
;
1512 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1513 line
=find_vga_entry(mode
);
1514 if(line
==0xFF)return;
1515 if(vga_modes
[line
].class==TEXT
)return;
1517 if(vga_modes
[line
].memmodel
==CGA
)
1519 if(vga_modes
[line
].pixbits
==2)
1521 addr
=(CX
>>2)+(DX
>>1)*80;
1525 addr
=(CX
>>3)+(DX
>>1)*80;
1527 if (DX
& 1) addr
+= 0x2000;
1528 data
= read_byte(0xb800,addr
);
1529 if(vga_modes
[line
].pixbits
==2)
1531 attr
= (AL
& 0x03) << ((3 - (CX
& 0x03)) * 2);
1532 mask
= 0x03 << ((3 - (CX
& 0x03)) * 2);
1536 attr
= (AL
& 0x01) << (7 - (CX
& 0x07));
1537 mask
= 0x01 << (7 - (CX
& 0x07));
1548 write_byte(0xb800,addr
,data
);
1550 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1552 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1553 write_byte(0xa000,addr
,AL
);
1563 // --------------------------------------------------------------------------------------------
1564 static void biosfn_read_pixel (BH
,CX
,DX
,AX
) Bit8u BH
;Bit16u CX
;Bit16u DX
;Bit16u
*AX
;
1566 Bit8u mode
,line
,attr
;
1571 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1572 line
=find_vga_entry(mode
);
1573 if(line
==0xFF)return;
1574 if(vga_modes
[line
].class==TEXT
)return;
1576 if(vga_modes
[line
].memmodel
==CGA
)
1578 addr
=(CX
>>2)+(DX
>>1)*80;
1579 if (DX
& 1) addr
+= 0x2000;
1580 data
= read_byte(0xb800,addr
);
1581 if(vga_modes
[line
].pixbits
==2)
1583 attr
= (data
>> ((3 - (CX
& 0x03)) * 2)) & 0x03;
1587 attr
= (data
>> (7 - (CX
& 0x07))) & 0x01;
1590 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1592 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1593 attr
=read_byte(0xa000,addr
);
1602 write_word(ss
,AX
,(read_word(ss
,AX
) & 0xff00) | attr
);
1605 // --------------------------------------------------------------------------------------------
1606 static void biosfn_write_teletype (car
, page
, attr
, flag
)
1607 Bit8u car
;Bit8u page
;Bit8u attr
;Bit8u flag
;
1608 {// flag = WITH_ATTR / NO_ATTR
1610 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1611 Bit16u nbcols
,nbrows
,address
;
1612 Bit16u cursor
,dummy
;
1614 // special case if page is 0xff, use current page
1616 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1621 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1622 line
=find_vga_entry(mode
);
1623 if(line
==0xFF)return;
1625 // Get the cursor pos for the page
1626 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1627 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1629 // Get the dimensions
1630 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1631 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1655 biosfn_write_teletype(' ',page
,attr
,flag
);
1656 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1657 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1663 if(vga_modes
[line
].class==TEXT
)
1665 // Compute the address
1666 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1669 write_byte(vga_modes
[line
].sstart
,address
,car
);
1672 write_byte(vga_modes
[line
].sstart
,address
+1,attr
);
1676 // FIXME gfx mode not complete
1677 cheight
=vga_modes
[line
].cheight
;
1678 bpp
=vga_modes
[line
].pixbits
;
1679 if(vga_modes
[line
].memmodel
==PLANAR4
)
1681 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1683 else if(vga_modes
[line
].memmodel
==CGA
)
1685 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1698 // Do we need to wrap ?
1704 // Do we need to scroll ?
1706 {biosfn_scroll(0x01,0x07,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
1710 // Set the cursor for the page
1711 cursor
=ycurs
; cursor
<<=8; cursor
+=xcurs
;
1712 biosfn_set_cursor_pos(page
,cursor
);
1715 // --------------------------------------------------------------------------------------------
1717 biosfn_get_video_mode
:
1719 mov ax
, #biosmem_seg
1722 mov bx
, #biosmem_current_page
1727 mov bx
, #biosmem_video_ctl
1730 mov bx
, #biosmem_current_mode
1733 mov bx
, #biosmem_nb_cols
1740 // --------------------------------------------------------------------------------------------
1741 static void biosfn_set_single_palette_reg (reg
,value
)
1742 Bit8u reg
;Bit8u value
;
1744 if(reg
<=ACTL_MAX_REG
)
1746 inb(VGAREG_ACTL_RESET
);
1747 outb(VGAREG_ACTL_ADDRESS
,reg
);
1748 outb(VGAREG_ACTL_WRITE_DATA
,value
);
1749 outb(VGAREG_ACTL_ADDRESS
,0x20);
1753 // --------------------------------------------------------------------------------------------
1754 static void biosfn_set_overscan_border_color (value
)
1757 inb(VGAREG_ACTL_RESET
);
1758 outb(VGAREG_ACTL_ADDRESS
,0x11);
1759 outb(VGAREG_ACTL_WRITE_DATA
,value
);
1760 outb(VGAREG_ACTL_ADDRESS
,0x20);
1763 // --------------------------------------------------------------------------------------------
1764 static void biosfn_set_all_palette_reg (seg
,offset
)
1765 Bit16u seg
;Bit16u offset
;
1769 inb(VGAREG_ACTL_RESET
);
1773 outb(VGAREG_ACTL_ADDRESS
,i
);
1774 outb(VGAREG_ACTL_WRITE_DATA
,read_byte(seg
,offset
));
1779 outb(VGAREG_ACTL_ADDRESS
,0x11);
1780 outb(VGAREG_ACTL_WRITE_DATA
,read_byte(seg
,offset
));
1781 outb(VGAREG_ACTL_ADDRESS
,0x20);
1784 // --------------------------------------------------------------------------------------------
1785 static void biosfn_toggle_intensity (state
)
1789 inb(VGAREG_ACTL_RESET
);
1791 outb(VGAREG_ACTL_ADDRESS
,0x10);
1792 value
=inb(VGAREG_ACTL_READ_DATA
);
1795 outb(VGAREG_ACTL_WRITE_DATA
,value
);
1796 outb(VGAREG_ACTL_ADDRESS
,0x20);
1799 // --------------------------------------------------------------------------------------------
1800 static void biosfn_get_single_palette_reg (reg
,value
)
1801 Bit8u reg
;Bit16u
*value
;
1802 {Bit16u ss
=get_SS();
1804 if(reg
<=ACTL_MAX_REG
)
1806 inb(VGAREG_ACTL_RESET
);
1807 outb(VGAREG_ACTL_ADDRESS
,reg
);
1808 write_word(ss
,value
,((Bit16u
)inb(VGAREG_ACTL_READ_DATA
))<<8);
1809 inb(VGAREG_ACTL_RESET
);
1810 outb(VGAREG_ACTL_ADDRESS
,0x20);
1814 // --------------------------------------------------------------------------------------------
1815 static void biosfn_read_overscan_border_color (value
)
1817 {Bit16u ss
=get_SS();
1819 inb(VGAREG_ACTL_RESET
);
1820 outb(VGAREG_ACTL_ADDRESS
,0x11);
1821 write_word(ss
,value
,((Bit16u
)inb(VGAREG_ACTL_READ_DATA
))<<8);
1822 outb(VGAREG_ACTL_ADDRESS
,0x20);
1825 // --------------------------------------------------------------------------------------------
1826 static void biosfn_get_all_palette_reg (seg
,offset
) Bit16u seg
;Bit16u offset
;
1833 inb(VGAREG_ACTL_RESET
);
1834 outb(VGAREG_ACTL_ADDRESS
,i
);
1835 write_byte(seg
,offset
,inb(VGAREG_ACTL_READ_DATA
));
1840 outb(VGAREG_ACTL_ADDRESS
,0x11);
1841 write_byte(seg
,offset
,inb(VGAREG_ACTL_READ_DATA
));
1842 outb(VGAREG_ACTL_ADDRESS
,0x20);
1845 // --------------------------------------------------------------------------------------------
1846 static void biosfn_set_single_dac_reg (reg
,g
,b
,r
)
1847 Bit16u reg
;Bit8u g
;Bit8u b
;Bit8u r
;
1849 outb(VGAREG_DAC_WRITE_ADDRESS
,reg
);
1850 outb(VGAREG_DAC_DATA
,r
);
1851 outb(VGAREG_DAC_DATA
,g
);
1852 outb(VGAREG_DAC_DATA
,b
);
1855 // --------------------------------------------------------------------------------------------
1856 static void biosfn_set_all_dac_reg (start
,count
,seg
,offset
)
1857 Bit16u start
;Bit16u count
;Bit16u seg
;Bit16u offset
;
1859 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
1860 for(i
=0;i
<count
;i
++)
1861 {outb(VGAREG_DAC_DATA
,read_byte(seg
,offset
++));
1862 outb(VGAREG_DAC_DATA
,read_byte(seg
,offset
++));
1863 outb(VGAREG_DAC_DATA
,read_byte(seg
,offset
++));
1867 // --------------------------------------------------------------------------------------------
1868 static void biosfn_select_video_dac_color_page (function
,page
)
1872 inb(VGAREG_ACTL_RESET
);
1873 outb(VGAREG_ACTL_ADDRESS
,0x10);
1875 value
=inb(VGAREG_ACTL_READ_DATA
);
1881 outb(VGAREG_ACTL_WRITE_DATA
,value
);
1885 inb(VGAREG_ACTL_RESET
);
1886 outb(VGAREG_ACTL_ADDRESS
,0x14);
1888 outb(VGAREG_ACTL_WRITE_DATA
,page
&0x0f);
1890 outb(VGAREG_ACTL_WRITE_DATA
,(page
&0x03)<<2);
1892 outb(VGAREG_ACTL_ADDRESS
,0x20);
1895 // --------------------------------------------------------------------------------------------
1896 static void biosfn_read_single_dac_reg (reg
,tor
,togb
)
1897 Bit8u reg
;Bit16u
*tor
;Bit16u
*togb
;
1898 {Bit16u ss
=get_SS();
1901 outb(VGAREG_DAC_READ_ADDRESS
,reg
);
1902 r
=inb(VGAREG_DAC_DATA
);
1903 g
=inb(VGAREG_DAC_DATA
);
1904 b
=inb(VGAREG_DAC_DATA
);
1905 write_word(ss
,tor
,((Bit16u
)r
)<<8);
1906 write_word(ss
,togb
,(((Bit16u
)g
)<<8)+b
);
1909 // --------------------------------------------------------------------------------------------
1910 static void biosfn_read_all_dac_reg (start
,count
,seg
,offset
)
1911 Bit16u start
;Bit16u count
;Bit16u seg
;Bit16u offset
;
1913 outb(VGAREG_DAC_READ_ADDRESS
,start
);
1914 for(i
=0;i
<count
;i
++)
1915 {write_byte(seg
,offset
++,inb(VGAREG_DAC_DATA
));
1916 write_byte(seg
,offset
++,inb(VGAREG_DAC_DATA
));
1917 write_byte(seg
,offset
++,inb(VGAREG_DAC_DATA
));
1921 // --------------------------------------------------------------------------------------------
1922 static void biosfn_set_pel_mask (mask
)
1925 outb(VGAREG_PEL_MASK
,mask
);
1928 // --------------------------------------------------------------------------------------------
1929 static void biosfn_read_pel_mask (mask
)
1931 {Bit16u ss
=get_SS();
1933 write_word(ss
,mask
,inb(VGAREG_PEL_MASK
));
1936 // --------------------------------------------------------------------------------------------
1937 static void biosfn_read_video_dac_state (state
) Bit16u
*state
;
1938 {Bit16u ss
=get_SS();
1941 inb(VGAREG_ACTL_RESET
);
1942 outb(VGAREG_ACTL_ADDRESS
,0x10);
1943 mcr
=(inb(VGAREG_ACTL_READ_DATA
)>>7)&0x01;
1944 inb(VGAREG_ACTL_RESET
);
1945 outb(VGAREG_ACTL_ADDRESS
,0x14);
1946 csr
=inb(VGAREG_ACTL_READ_DATA
)&0x0f;
1947 if(mcr
==0)(csr
>>2)&0x03;
1949 write_word(ss
,state
,(mcr
<<8)+csr
);
1950 outb(VGAREG_ACTL_ADDRESS
,0x20);
1953 // --------------------------------------------------------------------------------------------
1954 static void biosfn_perform_gray_scale_summing (start
,count
)
1955 Bit16u start
;Bit16u count
;
1960 inb(VGAREG_ACTL_RESET
);
1961 outb(VGAREG_ACTL_ADDRESS
,0x10);
1962 d
=(inb(VGAREG_ACTL_READ_DATA
)>>6)&0x01;
1964 // depth is 8 or 6 bits
1969 // We start overwriting at
1970 outb(VGAREG_DAC_READ_ADDRESS
,start
);
1971 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
1973 for( index
= 0; index
< count
; index
++ )
1975 // get 6-bit wide RGB data values
1976 r
=inb( VGAREG_DAC_DATA
);
1977 g
=inb( VGAREG_DAC_DATA
);
1978 b
=inb( VGAREG_DAC_DATA
);
1980 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
1981 i
= ( ( 77*r
+ 151*g
+ 28*b
) + 0x80 ) >> 8;
1985 // write new intensity value
1986 outb( VGAREG_DAC_DATA
, i
&0xff );
1987 outb( VGAREG_DAC_DATA
, i
&0xff );
1988 outb( VGAREG_DAC_DATA
, i
&0xff );
1990 outb(VGAREG_ACTL_ADDRESS
,0x20);
1993 // --------------------------------------------------------------------------------------------
1994 static void get_font_access()
1996 outw( VGAREG_SEQU_ADDRESS
, 0x0100 );
1997 outw( VGAREG_SEQU_ADDRESS
, 0x0402 );
1998 outw( VGAREG_SEQU_ADDRESS
, 0x0704 );
1999 outw( VGAREG_SEQU_ADDRESS
, 0x0300 );
2000 outw( VGAREG_GRDC_ADDRESS
, 0x0204 );
2001 outw( VGAREG_GRDC_ADDRESS
, 0x0005 );
2002 outw( VGAREG_GRDC_ADDRESS
, 0x0406 );
2005 static void release_font_access()
2007 outw( VGAREG_SEQU_ADDRESS
, 0x0100 );
2008 outw( VGAREG_SEQU_ADDRESS
, 0x0302 );
2009 outw( VGAREG_SEQU_ADDRESS
, 0x0304 );
2010 outw( VGAREG_SEQU_ADDRESS
, 0x0300 );
2011 outw( VGAREG_GRDC_ADDRESS
, 0x0004 );
2012 outw( VGAREG_GRDC_ADDRESS
, 0x1005 );
2013 outw( VGAREG_GRDC_ADDRESS
, 0x0e06 );
2023 static void set_scan_lines(lines
) Bit8u lines
;
2025 Bit16u crtc_addr
,cols
,page
,vde
;
2026 Bit8u crtc_r9
,ovl
,rows
;
2028 crtc_addr
= read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2029 outb(crtc_addr
, 0x09);
2030 crtc_r9
= inb(crtc_addr
+1);
2031 crtc_r9
= (crtc_r9
& 0xe0) | (lines
- 1);
2032 outb(crtc_addr
+1, crtc_r9
);
2035 biosfn_set_cursor_shape(0x06,0x07);
2039 biosfn_set_cursor_shape(lines
-4,lines
-3);
2041 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, lines
);
2042 outb(crtc_addr
, 0x12);
2043 vde
= inb(crtc_addr
+1);
2044 outb(crtc_addr
, 0x07);
2045 ovl
= inb(crtc_addr
+1);
2046 vde
+= (((ovl
& 0x02) << 7) + ((ovl
& 0x40) << 3) + 1);
2048 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, rows
-1);
2049 cols
= read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
2050 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, rows
* cols
* 2);
2053 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
;
2055 Bit16u blockaddr
,dest
,i
,src
;
2058 blockaddr
= BL
<< 13;
2062 dest
= blockaddr
+ (DX
+ i
) * 32;
2063 memcpyb(0xA000, dest
, ES
, src
, BH
);
2065 release_font_access();
2072 static void biosfn_load_text_8_14_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2074 Bit16u blockaddr
,dest
,i
,src
;
2077 blockaddr
= BL
<< 13;
2078 for(i
=0;i
<0x100;i
++)
2081 dest
= blockaddr
+ i
* 32;
2082 memcpyb(0xA000, dest
, 0xC000, vgafont14
+src
, 14);
2084 release_font_access();
2091 static void biosfn_load_text_8_8_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2093 Bit16u blockaddr
,dest
,i
,src
;
2096 blockaddr
= BL
<< 13;
2097 for(i
=0;i
<0x100;i
++)
2100 dest
= blockaddr
+ i
* 32;
2101 memcpyb(0xA000, dest
, 0xC000, vgafont8
+src
, 8);
2103 release_font_access();
2110 static void biosfn_set_text_block_specifier (BL
) Bit8u BL
;
2112 outb( VGAREG_SEQU_ADDRESS
, 0x03 );
2113 outb( VGAREG_SEQU_DATA
, BL
);
2116 static void biosfn_load_text_8_16_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2118 Bit16u blockaddr
,dest
,i
,src
;
2121 blockaddr
= BL
<< 13;
2122 for(i
=0;i
<0x100;i
++)
2125 dest
= blockaddr
+ i
* 32;
2126 memcpyb(0xA000, dest
, 0xC000, vgafont16
+src
, 16);
2128 release_font_access();
2135 static void biosfn_load_gfx_8_8_chars (ES
,BP
) Bit16u ES
;Bit16u BP
;
2141 static void biosfn_load_gfx_user_chars (ES
,BP
,CX
,BL
,DL
) Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit8u BL
;Bit8u DL
;
2147 static void biosfn_load_gfx_8_14_chars (BL
) Bit8u BL
;
2153 static void biosfn_load_gfx_8_8_dd_chars (BL
) Bit8u BL
;
2159 static void biosfn_load_gfx_8_16_chars (BL
) Bit8u BL
;
2165 // --------------------------------------------------------------------------------------------
2166 static void biosfn_get_font_info (BH
,ES
,BP
,CX
,DX
)
2167 Bit8u BH
;Bit16u
*ES
;Bit16u
*BP
;Bit16u
*CX
;Bit16u
*DX
;
2168 {Bit16u ss
=get_SS();
2172 write_word(ss
,ES
,read_word(0x00,0x1f*4));
2173 write_word(ss
,BP
,read_word(0x00,(0x1f*4)+2));
2176 write_word(ss
,ES
,read_word(0x00,0x43*4));
2177 write_word(ss
,BP
,read_word(0x00,(0x43*4)+2));
2180 write_word(ss
,ES
,0xC000);
2181 write_word(ss
,BP
,vgafont14
);
2184 write_word(ss
,ES
,0xC000);
2185 write_word(ss
,BP
,vgafont8
);
2188 write_word(ss
,ES
,0xC000);
2189 write_word(ss
,BP
,vgafont8
+128*8);
2192 write_word(ss
,ES
,0xC000);
2193 write_word(ss
,BP
,vgafont14alt
);
2196 write_word(ss
,ES
,0xC000);
2197 write_word(ss
,BP
,vgafont16
);
2200 write_word(ss
,ES
,0xC000);
2201 write_word(ss
,BP
,vgafont16alt
);
2205 printf("Get font info BH(%02x) was discarded\n",BH
);
2209 // Set byte/char of on screen font
2210 write_word(ss
,CX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
));
2212 // Set Highest char row
2213 write_word(ss
,DX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
));
2216 // --------------------------------------------------------------------------------------------
2217 static void biosfn_get_ega_info (BX
,CX
)
2218 Bit16u
*BX
;Bit16u
*CX
;
2219 {Bit16u ss
=get_SS();
2223 crtc
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2224 if(crtc
==VGAREG_MDA_CRTC_ADDRESS
)
2225 write_word(ss
,BX
,(1<<8)+0x0003);
2227 write_word(ss
,BX
,0x0003);
2229 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2230 write_word(ss
,CX
,(switches
&0x0f));
2233 // --------------------------------------------------------------------------------------------
2234 static void biosfn_alternate_prtsc()
2241 // --------------------------------------------------------------------------------------------
2242 static void biosfn_select_vert_res (res
)
2244 {// res : 00 200 lines, 01 350 lines, 02 400 lines
2245 Bit8u modeset
,switches
;
2247 modeset
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
2248 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2251 // set modeset ctl bit 7 and reset bit 4
2252 // set switches bit 3-0 to 0x08
2253 modeset
|=0x80;modeset
&=0xef;
2254 switches
&=0xf0;switches
|=0x08;
2257 // reset modeset ctl bit 7 and bit 4
2258 // set switches bit 3-0 to 0x09
2260 switches
&=0xf0;switches
|=0x09;
2263 // reset modeset ctl bit 7 and set bit 4
2264 // set switches bit 3-0 to 0x09
2265 modeset
|=0x10;modeset
&=0x7f;
2266 switches
&=0xf0;switches
|=0x09;
2270 printf("Select vert res (%02x) was discarded\n",res
);
2274 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,modeset
);
2275 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,switches
);
2278 // --------------------------------------------------------------------------------------------
2279 static void biosfn_enable_default_palette_loading (disable
)
2284 modeset
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
2287 if(disable
!=0x00)modeset
|=0x08;
2290 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,modeset
);
2293 // --------------------------------------------------------------------------------------------
2294 static void biosfn_enable_video_addressing (disable
)
2299 misc
=inb(VGAREG_READ_MISC_OUTPUT
);
2301 if(disable
!=0x00) misc
&=0xfd;
2303 outb(VGAREG_WRITE_MISC_OUTPUT
,misc
);
2306 // --------------------------------------------------------------------------------------------
2307 static void biosfn_enable_grayscale_summing (disable
)
2312 modeset
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
2314 // Bit 1 set if disable=0
2315 if(disable
==0x00)modeset
|=0x02;
2318 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,modeset
);
2321 // --------------------------------------------------------------------------------------------
2322 static void biosfn_enable_cursor_emulation (disable
)
2327 videoctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
2329 // Bit 0 set if disable!=0
2330 if(disable
!=0x00)videoctl
|=0x01;
2331 else videoctl
&=0xfe;
2333 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,videoctl
);
2336 // --------------------------------------------------------------------------------------------
2337 static void biosfn_switch_video_interface (AL
,ES
,DX
) Bit8u AL
;Bit16u ES
;Bit16u DX
;
2343 static void biosfn_enable_video_refresh_control (AL
) Bit8u AL
;
2350 // --------------------------------------------------------------------------------------------
2351 static void biosfn_write_string (flag
,page
,attr
,count
,row
,col
,seg
,offset
)
2352 Bit8u flag
;Bit8u page
;Bit8u attr
;Bit16u count
;Bit8u row
;Bit8u col
;Bit16u seg
;Bit16u offset
;
2354 Bit16u newcurs
,oldcurs
,dummy
;
2357 // Read curs info for the page
2358 biosfn_get_cursor_pos(page
,&dummy
,&oldcurs
);
2360 // if row=0xff special case : use current cursor position
2362 {col
=oldcurs
&0x00ff;
2363 row
=(oldcurs
&0xff00)>>8;
2366 newcurs
=row
; newcurs
<<=8; newcurs
+=col
;
2367 biosfn_set_cursor_pos(page
,newcurs
);
2371 car
=read_byte(seg
,offset
++);
2373 attr
=read_byte(seg
,offset
++);
2375 biosfn_write_teletype(car
,page
,attr
,WITH_ATTR
);
2378 // Set back curs pos
2380 biosfn_set_cursor_pos(page
,oldcurs
);
2383 // --------------------------------------------------------------------------------------------
2387 je biosfn_read_display_code
2389 je biosfn_set_display_code
2394 biosfn_read_display_code
:
2397 mov ax
, #biosmem_seg
2399 mov bx
, #biosmem_dcc_index
2407 biosfn_set_display_code
:
2411 mov ax
, #biosmem_seg
2414 mov bx
, #biosmem_dcc_index
2420 mov bx
, #msg_alt_dcc
2433 .ascii
"Alternate Display code (%02x) was discarded"
2434 .byte
0x0d,0x0a,0x00
2438 // --------------------------------------------------------------------------------------------
2439 static void biosfn_read_state_info (BX
,ES
,DI
)
2440 Bit16u BX
;Bit16u ES
;Bit16u DI
;
2442 // Address of static functionality table
2443 write_word(ES
,DI
+0x00,&static_functionality
);
2444 write_word(ES
,DI
+0x02,0xC000);
2446 // Hard coded copy from BIOS area. Should it be cleaner ?
2447 memcpyb(ES
,DI
+0x04,BIOSMEM_SEG
,0x49,30);
2448 memcpyb(ES
,DI
+0x22,BIOSMEM_SEG
,0x84,3);
2450 write_byte(ES
,DI
+0x25,read_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
));
2451 write_byte(ES
,DI
+0x26,0);
2452 write_byte(ES
,DI
+0x27,16);
2453 write_byte(ES
,DI
+0x28,0);
2454 write_byte(ES
,DI
+0x29,8);
2455 write_byte(ES
,DI
+0x2a,2);
2456 write_byte(ES
,DI
+0x2b,0);
2457 write_byte(ES
,DI
+0x2c,0);
2458 write_byte(ES
,DI
+0x31,3);
2459 write_byte(ES
,DI
+0x32,0);
2461 memsetb(ES
,DI
+0x33,0,13);
2464 // --------------------------------------------------------------------------------------------
2465 static void biosfn_read_video_state_size (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2471 static void biosfn_save_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2477 static void biosfn_restore_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2484 // ============================================================================================
2488 // ============================================================================================
2490 // --------------------------------------------------------------------------------------------
2491 static Bit8u
find_vga_entry(mode
)
2495 for(i
=0;i
<=MODE_MAX
;i
++)
2496 if(vga_modes
[i
].svgamode
==mode
)
2503 /* =========================================================== */
2507 /* =========================================================== */
2509 // --------------------------------------------------------------------------------------------
2510 static void memsetb(seg
,offset
,value
,count
)
2525 mov cx
, 10[bp
] ; count
2528 mov ax
, 4[bp
] ; segment
2530 mov ax
, 6[bp
] ; offset
2532 mov al
, 8[bp
] ; value
2547 // --------------------------------------------------------------------------------------------
2548 static void memsetw(seg
,offset
,value
,count
)
2563 mov cx
, 10[bp
] ; count
2566 mov ax
, 4[bp
] ; segment
2568 mov ax
, 6[bp
] ; offset
2570 mov ax
, 8[bp
] ; value
2585 // --------------------------------------------------------------------------------------------
2586 static void memcpyb(dseg
,doffset
,sseg
,soffset
,count
)
2604 mov cx
, 12[bp
] ; count
2607 mov ax
, 4[bp
] ; dsegment
2609 mov ax
, 6[bp
] ; doffset
2611 mov ax
, 8[bp
] ; ssegment
2613 mov ax
, 10[bp
] ; soffset
2631 // --------------------------------------------------------------------------------------------
2632 static void memcpyw(dseg
,doffset
,sseg
,soffset
,count
)
2650 mov cx
, 12[bp
] ; count
2653 mov ax
, 4[bp
] ; dsegment
2655 mov ax
, 6[bp
] ; doffset
2657 mov ax
, 8[bp
] ; ssegment
2659 mov ax
, 10[bp
] ; soffset
2677 /* =========================================================== */
2679 * These functions where ripped from Kevin's rombios.c
2681 /* =========================================================== */
2683 // --------------------------------------------------------------------------------------------
2685 read_byte(seg
, offset
)
2695 mov ax
, 4[bp
] ; segment
2697 mov bx
, 6[bp
] ; offset
2699 ;; al
= return value (byte
)
2707 // --------------------------------------------------------------------------------------------
2709 read_word(seg
, offset
)
2719 mov ax
, 4[bp
] ; segment
2721 mov bx
, 6[bp
] ; offset
2723 ;; ax
= return value (word
)
2731 // --------------------------------------------------------------------------------------------
2733 write_byte(seg
, offset
, data
)
2745 mov ax
, 4[bp
] ; segment
2747 mov bx
, 6[bp
] ; offset
2748 mov al
, 8[bp
] ; data byte
2749 mov
[bx
], al
; write data byte
2758 // --------------------------------------------------------------------------------------------
2760 write_word(seg
, offset
, data
)
2772 mov ax
, 4[bp
] ; segment
2774 mov bx
, 6[bp
] ; offset
2775 mov ax
, 8[bp
] ; data word
2776 mov
[bx
], ax
; write data word
2785 // --------------------------------------------------------------------------------------------
2820 // --------------------------------------------------------------------------------------------
2842 // --------------------------------------------------------------------------------------------
2872 void unimplemented()
2874 printf("--> Unimplemented\n");
2879 printf("--> Unknown int10\n");
2883 // --------------------------------------------------------------------------------------------
2887 Bit8u c
, format_char
;
2889 unsigned format_width
, i
;
2891 Bit16u arg_seg
, arg
, digit
, nibble
, shift_count
;
2899 while (c
= read_byte(0xc000, s
)) {
2904 else if (in_format
) {
2905 if ( (c
>='0') && (c
<='9') ) {
2906 format_width
= (format_width
* 10) + (c
- '0');
2908 else if (c
== 'x') {
2909 arg_ptr
++; // increment to next arg
2910 arg
= read_word(arg_seg
, arg_ptr
);
2911 if (format_width
== 0)
2914 digit
= format_width
- 1;
2915 for (i
=0; i
<format_width
; i
++) {
2916 nibble
= (arg
>> (4 * digit
)) & 0x000f;
2918 outb(0x0500, nibble
+ '0');
2920 outb(0x0500, (nibble
- 10) + 'A');
2925 //else if (c == 'd') {
2940 // --------------------------------------------------------------------------------------------
2943 ;; DATA_SEG_DEFS_HERE
2947 .ascii
"vgabios ends here"
2951 ;; BLOCK_STRINGS_BEGIN