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_enable_cursor_emulation();
108 static void biosfn_switch_video_interface();
109 static void biosfn_enable_video_refresh_control();
110 static void biosfn_write_string();
111 static void biosfn_read_state_info();
112 static void biosfn_read_video_state_size();
113 static void biosfn_save_video_state();
114 static void biosfn_restore_video_state();
116 // This is for compiling with gcc2 and gcc3
117 #define ASM_START #asm
118 #define ASM_END #endasm
123 biosmem_initial_mode
= 0x10
124 biosmem_current_mode
= 0x49
125 biosmem_nb_cols
= 0x4a
126 biosmem_current_page
= 0x62
127 biosmem_current_msr
= 0x65
128 biosmem_char_height
= 0x85
129 biosmem_video_ctl
= 0x87
130 biosmem_switches
= 0x88
131 biosmem_modeset_ctl
= 0x89
132 biosmem_dcc_index
= 0x8a
134 vgareg_actl_address
= 0x03c0
135 vgareg_actl_read_data
= 0x03c1
136 vgareg_write_misc_output
= 0x03c2
137 vgareg_sequ_address
= 0x03c4
138 vgareg_pel_mask
= 0x03c6
139 vgareg_dac_read_address
= 0x03c7
140 vgareg_dac_write_address
= 0x03c8
141 vgareg_dac_data
= 0x03c9
142 vgareg_read_misc_output
= 0x03cc
143 vgareg_grdc_address
= 0x03ce
144 vgareg_actl_reset
= 0x03da
167 .byte
0x55, 0xaa /* BIOS signature, required for BIOS extensions */
169 .byte
0x40 /* BIOS extension length in units of 512 bytes */
174 jmp vgabios_init_func
177 .ascii
"Plex86/Bochs VGABios"
181 // Info from Bart Oldeman
200 .ascii
"(C) 2003 the LGPL VGABios developers Team"
205 .ascii
"This VGA/VBE Bios is released under the GNU LGPL"
211 .ascii
"Please visit :"
213 ;;.ascii
" . http://www.plex86.org"
215 .ascii
" . http://bochs.sourceforge.net"
217 .ascii
" . http://www.nongnu.org/vgabios"
223 ;; ============================================================================================
227 ;; ============================================================================================
233 ;; init basic bios vars
237 ;; init vbe functions
242 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
244 ;; display splash screen
245 call _display_splash_screen
247 ;; init video mode
and clear the screen
256 call _vbe_display_info
267 vgabios_int10_handler
:
282 call biosfn_get_video_mode
297 call biosfn_set_text_block_specifier
304 call biosfn_enable_default_palette_loading
309 call biosfn_enable_video_addressing
314 call biosfn_enable_grayscale_summing
329 ;; We have to set ds to access the right data segment
342 #include "vgatables.h"
343 #include "vgafonts.h"
346 * Boot time harware inits
350 ;; switch to color mode
and enable CPU access
480 lines
355 ;; more than
64k
3C4
/04
363 mov bx
, #msg_vga_init
371 .ascii
"VGABios $Id$"
375 // --------------------------------------------------------------------------------------------
377 * Boot time bios area inits
385 ;; init detected hardware BIOS Area
386 mov bx
, #biosmem_initial_mode
391 ;; Just
for the first int10 find its children
393 ;; the
default char height
394 mov bx
, #biosmem_char_height
399 mov bx
, #biosmem_video_ctl
403 ;; Set the basic screen we have
404 mov bx
, #biosmem_switches
408 ;; Set the basic modeset options
409 mov bx
, #biosmem_modeset_ctl
413 ;; Set the
default MSR
414 mov bx
, #biosmem_current_msr
422 // --------------------------------------------------------------------------------------------
424 * Boot time Splash screen
426 static void display_splash_screen()
430 // --------------------------------------------------------------------------------------------
435 static void display_info()
442 mov si
,#vgabios_version
445 ;;mov si
,#vgabios_copyright
446 ;;call _display_string
448 ;;call _display_string
450 mov si
,#vgabios_license
452 mov si
,#vgabios_website
457 static void display_string()
459 // Get length of string
486 // --------------------------------------------------------------------------------------------
488 static void int10_debugmsg(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
489 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
491 // 0E is write char...
493 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX
,CX
,DX
);
497 // --------------------------------------------------------------------------------------------
499 * int10 main dispatcher
501 static void int10_func(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
502 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
509 biosfn_set_video_mode(GET_AL());
510 switch(GET_AL()&0x7F)
528 biosfn_set_cursor_shape(GET_CH(),GET_CL());
531 biosfn_set_cursor_pos(GET_BH(),DX
);
534 biosfn_get_cursor_pos(GET_BH(),&CX
,&DX
);
537 // Read light pen pos (unimplemented)
547 biosfn_set_active_page(GET_AL());
550 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP
);
553 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN
);
556 biosfn_read_char_attr(GET_BH(),&AX
);
559 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX
);
562 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX
);
565 biosfn_write_pixel(GET_BH(),GET_AL(),CX
,DX
);
568 biosfn_read_pixel(GET_BH(),CX
,DX
,&AX
);
571 // Ralf Brown Interrupt list is WRONG on bh(page)
572 // We do output only on the current page !
573 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR
);
576 // All other functions of group AH=0x10 rewritten in assembler
577 biosfn_perform_gray_scale_summing(BX
,CX
);
584 biosfn_load_text_user_pat(GET_AL(),ES
,BP
,CX
,DX
,GET_BL(),GET_BH());
588 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
592 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
596 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
599 biosfn_load_gfx_8_8_chars(ES
,BP
);
602 biosfn_load_gfx_user_chars(ES
,BP
,CX
,GET_BL(),GET_DL());
605 biosfn_load_gfx_8_14_chars(GET_BL());
608 biosfn_load_gfx_8_8_dd_chars(GET_BL());
611 biosfn_load_gfx_8_16_chars(GET_BL());
614 biosfn_get_font_info(GET_BH(),&ES
,&BP
,&CX
,&DX
);
627 biosfn_get_ega_info(&BX
,&CX
);
630 biosfn_alternate_prtsc();
633 biosfn_select_vert_res(GET_AL());
637 biosfn_enable_cursor_emulation(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
;
994 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
,curs
);
996 cheight
= read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
);
997 if((cheight
>8) && (CL
<8) && (CH
<0x20))
1001 CH
= ((CH
+1) * cheight
/ 8) -1;
1005 CH
= ((CL
+1) * cheight
/ 8) - 2;
1007 CL
= ((CL
+1) * cheight
/ 8) - 1;
1010 // CTRC regs 0x0a and 0x0b
1011 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1012 outb(crtc_addr
,0x0a);
1013 outb(crtc_addr
+1,CH
);
1014 outb(crtc_addr
,0x0b);
1015 outb(crtc_addr
+1,CL
);
1018 // --------------------------------------------------------------------------------------------
1019 static void biosfn_set_cursor_pos (page
, cursor
)
1020 Bit8u page
;Bit16u cursor
;
1022 Bit8u xcurs
,ycurs
,current
;
1023 Bit16u nbcols
,nbrows
,address
,crtc_addr
;
1025 // Should not happen...
1029 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*page
, cursor
);
1031 // Set the hardware cursor
1032 current
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1035 // Get the dimensions
1036 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1037 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1039 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1041 // Calculate the address knowing nbcols nbrows and page num
1042 address
=SCREEN_IO_START(nbcols
,nbrows
,page
)+xcurs
+ycurs
*nbcols
;
1044 // CRTC regs 0x0e and 0x0f
1045 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1046 outb(crtc_addr
,0x0e);
1047 outb(crtc_addr
+1,(address
&0xff00)>>8);
1048 outb(crtc_addr
,0x0f);
1049 outb(crtc_addr
+1,address
&0x00ff);
1053 // --------------------------------------------------------------------------------------------
1054 static void biosfn_get_cursor_pos (page
,shape
, pos
)
1055 Bit8u page
;Bit16u
*shape
;Bit16u
*pos
;
1060 write_word(ss
, shape
, 0);
1061 write_word(ss
, pos
, 0);
1064 // FIXME should handle VGA 14/16 lines
1065 write_word(ss
,shape
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
));
1066 write_word(ss
,pos
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_POS
+page
*2));
1069 // --------------------------------------------------------------------------------------------
1070 static void biosfn_set_active_page (page
)
1073 Bit16u cursor
,dummy
,crtc_addr
;
1074 Bit16u nbcols
,nbrows
,address
;
1080 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1081 line
=find_vga_entry(mode
);
1082 if(line
==0xFF)return;
1084 // Get pos curs pos for the right page
1085 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1087 if(vga_modes
[line
].class==TEXT
)
1089 // Get the dimensions
1090 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1091 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1093 // Calculate the address knowing nbcols nbrows and page num
1094 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1095 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
,address
);
1098 address
=SCREEN_IO_START(nbcols
,nbrows
,page
);
1102 address
= page
*vga_modes
[line
].slength
;
1105 // CRTC regs 0x0c and 0x0d
1106 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1107 outb(crtc_addr
,0x0c);
1108 outb(crtc_addr
+1,(address
&0xff00)>>8);
1109 outb(crtc_addr
,0x0d);
1110 outb(crtc_addr
+1,address
&0x00ff);
1112 // And change the BIOS page
1113 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
,page
);
1116 printf("Set active page %02x address %04x\n",page
,address
);
1119 // Display the cursor, now the page is active
1120 biosfn_set_cursor_pos(page
,cursor
);
1123 // --------------------------------------------------------------------------------------------
1124 static void biosfn_scroll (nblines
,attr
,rul
,cul
,rlr
,clr
,page
,dir
)
1125 Bit8u nblines
;Bit8u attr
;Bit8u rul
;Bit8u cul
;Bit8u rlr
;Bit8u clr
;Bit8u page
;Bit8u dir
;
1127 // page == 0xFF if current
1130 Bit16u nbcols
,nbrows
,i
;
1137 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1138 line
=find_vga_entry(mode
);
1139 if(line
==0xFF)return;
1141 // Get the dimensions
1142 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1143 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1145 // Get the current page
1147 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1149 if(vga_modes
[line
].class==TEXT
)
1151 // Compute the address
1152 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1154 printf("Scroll, address %04x (%04x %04x %02x)\n",address
,nbrows
,nbcols
,page
);
1157 if(rlr
>=nbrows
)rlr
=nbrows
-1;
1158 if(clr
>=nbcols
)clr
=nbcols
-1;
1159 if(nblines
>nbrows
)nblines
=0;
1161 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1163 memsetw(vga_modes
[line
].sstart
,address
,(Bit16u
)attr
*0x100+' ',nbrows
*nbcols
);
1168 {for(i
=rul
;i
<=rlr
;i
++)
1170 if((i
+nblines
>rlr
)||(nblines
==0))
1171 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1173 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
+nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1177 {for(i
=rlr
;i
>=rul
;i
--)
1179 if((i
<rul
+nblines
)||(nblines
==0))
1180 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',clr
-cul
+1);
1182 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
-nblines
)*nbcols
+cul
)*2,clr
-cul
+1);
1191 printf("Scroll in graphics mode ");
1197 // --------------------------------------------------------------------------------------------
1198 static void biosfn_read_char_attr (page
,car
)
1199 Bit8u page
;Bit16u
*car
;
1200 {Bit16u ss
=get_SS();
1201 Bit8u xcurs
,ycurs
,mode
,line
;
1202 Bit16u nbcols
,nbrows
,address
;
1203 Bit16u cursor
,dummy
;
1206 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1207 line
=find_vga_entry(mode
);
1208 if(line
==0xFF)return;
1210 // Get the cursor pos for the page
1211 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1212 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1214 // Get the dimensions
1215 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1216 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1218 if(vga_modes
[line
].class==TEXT
)
1220 // Compute the address
1221 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1223 write_word(ss
,car
,read_word(vga_modes
[line
].sstart
,address
));
1234 // --------------------------------------------------------------------------------------------
1235 static void write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
)
1236 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u cheight
;
1240 Bit16u addr
,dest
,src
;
1252 addr
=xcurs
+ycurs
*cheight
*nbcols
;
1253 src
= car
* cheight
;
1254 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
1255 mmask
= inb( VGAREG_SEQU_DATA
);
1256 for(i
=0;i
<cheight
;i
++)
1259 outb( VGAREG_SEQU_DATA
, 0x0f );
1260 write_byte(0xa000,dest
,0x00);
1261 outb( VGAREG_SEQU_DATA
, attr
& 0x0f );
1262 write_byte(0xa000,dest
,fdata
[src
+i
]);
1264 outb( VGAREG_SEQU_DATA
, mmask
);
1267 // --------------------------------------------------------------------------------------------
1268 static void write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
)
1269 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u bpp
;
1271 Bit8u i
,j
,mask
,data
;
1273 Bit16u addr
,dest
,src
;
1276 addr
=(xcurs
*bpp
)+ycurs
*320;
1280 dest
=addr
+(i
>>1)*80;
1281 if (i
& 1) dest
+= 0x2000;
1287 data
= read_byte(0xb800,dest
);
1295 if (fdata
[src
+i
] & mask
)
1299 data
^= (attr
& 0x01) << (7-j
);
1303 data
|= (attr
& 0x01) << (7-j
);
1308 write_byte(0xb800,dest
,data
);
1316 data
= read_byte(0xb800,dest
);
1324 if (fdata
[src
+i
] & mask
)
1328 data
^= (attr
& 0x03) << ((3-j
)*2);
1332 data
|= (attr
& 0x03) << ((3-j
)*2);
1337 write_byte(0xb800,dest
,data
);
1344 // --------------------------------------------------------------------------------------------
1345 static void write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
)
1346 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;
1348 Bit8u i
,j
,mask
,data
;
1350 Bit16u addr
,dest
,src
;
1353 addr
=xcurs
*8+ycurs
*nbcols
*64;
1357 dest
=addr
+i
*nbcols
*8;
1362 if (fdata
[src
+i
] & mask
)
1366 write_byte(0xa000,dest
+j
,data
);
1372 // --------------------------------------------------------------------------------------------
1373 static void biosfn_write_char_attr (car
,page
,attr
,count
)
1374 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1376 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1377 Bit16u nbcols
,nbrows
,address
;
1378 Bit16u cursor
,dummy
;
1381 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1382 line
=find_vga_entry(mode
);
1383 if(line
==0xFF)return;
1385 // Get the cursor pos for the page
1386 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1387 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1389 // Get the dimensions
1390 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1391 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1393 if(vga_modes
[line
].class==TEXT
)
1395 // Compute the address
1396 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1398 dummy
=((Bit16u
)attr
<<8)+car
;
1399 memsetw(vga_modes
[line
].sstart
,address
,dummy
,count
);
1403 // FIXME gfx mode not complete
1404 cheight
=vga_modes
[line
].cheight
;
1405 bpp
=vga_modes
[line
].pixbits
;
1406 while((count
-->0) && (xcurs
<nbcols
))
1408 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1410 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1412 else if(vga_modes
[line
].memmodel
==CGA
)
1414 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1416 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1418 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1431 // --------------------------------------------------------------------------------------------
1432 static void biosfn_write_char_only (car
,page
,attr
,count
)
1433 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1435 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1436 Bit16u nbcols
,nbrows
,address
;
1437 Bit16u cursor
,dummy
;
1440 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1441 line
=find_vga_entry(mode
);
1442 if(line
==0xFF)return;
1444 // Get the cursor pos for the page
1445 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1446 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1448 // Get the dimensions
1449 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1450 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1452 if(vga_modes
[line
].class==TEXT
)
1454 // Compute the address
1455 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1458 {write_byte(vga_modes
[line
].sstart
,address
,car
);
1464 // FIXME gfx mode not complete
1465 cheight
=vga_modes
[line
].cheight
;
1466 bpp
=vga_modes
[line
].pixbits
;
1467 while((count
-->0) && (xcurs
<nbcols
))
1469 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1471 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1473 else if(vga_modes
[line
].memmodel
==CGA
)
1475 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1477 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1479 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1492 // --------------------------------------------------------------------------------------------
1496 je biosfn_set_border_color
1498 je biosfn_set_palette
1503 biosfn_set_border_color
:
1508 mov dx
, #vgareg_actl_reset
1510 mov dx
, #vgareg_actl_address
1523 mov dx
, #vgareg_actl_address
1526 mov dx
, #vgareg_actl_read_data
1530 mov dx
, #vgareg_actl_address
1534 jne set_intensity_loop
1547 mov dx
, #vgareg_actl_reset
1551 set_cga_palette_loop
:
1552 mov dx
, #vgareg_actl_address
1555 mov dx
, #vgareg_actl_read_data
1559 mov dx
, #vgareg_actl_address
1563 jne set_cga_palette_loop
1573 // --------------------------------------------------------------------------------------------
1574 static void biosfn_write_pixel (BH
,AL
,CX
,DX
) Bit8u BH
;Bit8u AL
;Bit16u CX
;Bit16u DX
;
1576 Bit8u mode
,line
,mask
,attr
,data
;
1580 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1581 line
=find_vga_entry(mode
);
1582 if(line
==0xFF)return;
1583 if(vga_modes
[line
].class==TEXT
)return;
1585 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1587 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1588 mask
= 0x01 << (7 - (CX
& 0x07));
1589 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1590 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1591 data
= read_byte(0xa000,addr
);
1594 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1596 write_byte(0xa000,addr
,AL
);
1597 outw(VGAREG_GRDC_ADDRESS
, 0xff08);
1598 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1599 outw(VGAREG_GRDC_ADDRESS
, 0x0003);
1601 else if(vga_modes
[line
].memmodel
==CGA
)
1603 if(vga_modes
[line
].pixbits
==2)
1605 addr
=(CX
>>2)+(DX
>>1)*80;
1609 addr
=(CX
>>3)+(DX
>>1)*80;
1611 if (DX
& 1) addr
+= 0x2000;
1612 data
= read_byte(0xb800,addr
);
1613 if(vga_modes
[line
].pixbits
==2)
1615 attr
= (AL
& 0x03) << ((3 - (CX
& 0x03)) * 2);
1616 mask
= 0x03 << ((3 - (CX
& 0x03)) * 2);
1620 attr
= (AL
& 0x01) << (7 - (CX
& 0x07));
1621 mask
= 0x01 << (7 - (CX
& 0x07));
1632 write_byte(0xb800,addr
,data
);
1634 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1636 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1637 write_byte(0xa000,addr
,AL
);
1647 // --------------------------------------------------------------------------------------------
1648 static void biosfn_read_pixel (BH
,CX
,DX
,AX
) Bit8u BH
;Bit16u CX
;Bit16u DX
;Bit16u
*AX
;
1650 Bit8u mode
,line
,mask
,attr
,data
,i
;
1655 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1656 line
=find_vga_entry(mode
);
1657 if(line
==0xFF)return;
1658 if(vga_modes
[line
].class==TEXT
)return;
1660 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1662 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1663 mask
= 0x01 << (7 - (CX
& 0x07));
1667 outw(VGAREG_GRDC_ADDRESS
, (i
<< 8) | 0x04);
1668 data
= read_byte(0xa000,addr
) & mask
;
1669 if (data
> 0) attr
|= (0x01 << i
);
1672 else if(vga_modes
[line
].memmodel
==CGA
)
1674 addr
=(CX
>>2)+(DX
>>1)*80;
1675 if (DX
& 1) addr
+= 0x2000;
1676 data
= read_byte(0xb800,addr
);
1677 if(vga_modes
[line
].pixbits
==2)
1679 attr
= (data
>> ((3 - (CX
& 0x03)) * 2)) & 0x03;
1683 attr
= (data
>> (7 - (CX
& 0x07))) & 0x01;
1686 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1688 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1689 attr
=read_byte(0xa000,addr
);
1698 write_word(ss
,AX
,(read_word(ss
,AX
) & 0xff00) | attr
);
1701 // --------------------------------------------------------------------------------------------
1702 static void biosfn_write_teletype (car
, page
, attr
, flag
)
1703 Bit8u car
;Bit8u page
;Bit8u attr
;Bit8u flag
;
1704 {// flag = WITH_ATTR / NO_ATTR
1706 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1707 Bit16u nbcols
,nbrows
,address
;
1708 Bit16u cursor
,dummy
;
1710 // special case if page is 0xff, use current page
1712 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1717 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1718 line
=find_vga_entry(mode
);
1719 if(line
==0xFF)return;
1721 // Get the cursor pos for the page
1722 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1723 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1725 // Get the dimensions
1726 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1727 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1751 biosfn_write_teletype(' ',page
,attr
,flag
);
1752 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1753 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1759 if(vga_modes
[line
].class==TEXT
)
1761 // Compute the address
1762 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1765 write_byte(vga_modes
[line
].sstart
,address
,car
);
1768 write_byte(vga_modes
[line
].sstart
,address
+1,attr
);
1772 // FIXME gfx mode not complete
1773 cheight
=vga_modes
[line
].cheight
;
1774 bpp
=vga_modes
[line
].pixbits
;
1775 if((vga_modes
[line
].memmodel
==PLANAR4
)||(vga_modes
[line
].memmodel
==PLANAR1
))
1777 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1779 else if(vga_modes
[line
].memmodel
==CGA
)
1781 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1783 else if(vga_modes
[line
].memmodel
==LINEAR8
)
1785 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1798 // Do we need to wrap ?
1804 // Do we need to scroll ?
1806 {biosfn_scroll(0x01,0x07,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
1810 // Set the cursor for the page
1811 cursor
=ycurs
; cursor
<<=8; cursor
+=xcurs
;
1812 biosfn_set_cursor_pos(page
,cursor
);
1815 // --------------------------------------------------------------------------------------------
1817 biosfn_get_video_mode
:
1819 mov ax
, #biosmem_seg
1822 mov bx
, #biosmem_current_page
1827 mov bx
, #biosmem_video_ctl
1830 mov bx
, #biosmem_current_mode
1833 mov bx
, #biosmem_nb_cols
1840 // --------------------------------------------------------------------------------------------
1845 jmp biosfn_set_single_palette_reg
1849 jmp biosfn_set_overscan_border_color
1853 jmp biosfn_set_all_palette_reg
1857 jmp biosfn_toggle_intensity
1861 jmp biosfn_get_single_palette_reg
1865 jmp biosfn_read_overscan_border_color
1869 jmp biosfn_get_all_palette_reg
1873 jmp biosfn_set_single_dac_reg
1877 jmp biosfn_set_all_dac_reg
1881 jmp biosfn_select_video_dac_color_page
1885 jmp biosfn_read_single_dac_reg
1889 jmp biosfn_read_all_dac_reg
1893 jmp biosfn_set_pel_mask
1897 jmp biosfn_read_pel_mask
1900 jne int10_group_10_unknown
1901 jmp biosfn_read_video_dac_state
1902 int10_group_10_unknown
:
1908 biosfn_set_single_palette_reg
:
1913 mov dx
, #vgareg_actl_reset
1915 mov dx
, #vgareg_actl_address
1928 // --------------------------------------------------------------------------------------------
1930 biosfn_set_overscan_border_color
:
1933 call biosfn_set_single_palette_reg
1938 // --------------------------------------------------------------------------------------------
1940 biosfn_set_all_palette_reg
:
1946 mov dx
, #vgareg_actl_reset
1949 mov dx
, #vgareg_actl_address
1959 jne set_palette_loop
1974 // --------------------------------------------------------------------------------------------
1976 biosfn_toggle_intensity
:
1980 mov dx
, #vgareg_actl_reset
1982 mov dx
, #vgareg_actl_address
1985 mov dx
, #vgareg_actl_read_data
1991 mov dx
, #vgareg_actl_address
2001 // --------------------------------------------------------------------------------------------
2003 biosfn_get_single_palette_reg
:
2008 mov dx
, #vgareg_actl_reset
2010 mov dx
, #vgareg_actl_address
2013 mov dx
, #vgareg_actl_read_data
2016 mov dx
, #vgareg_actl_reset
2018 mov dx
, #vgareg_actl_address
2027 // --------------------------------------------------------------------------------------------
2029 biosfn_read_overscan_border_color
:
2033 call biosfn_get_single_palette_reg
2041 // --------------------------------------------------------------------------------------------
2043 biosfn_get_all_palette_reg
:
2051 mov dx
, #vgareg_actl_reset
2053 mov dx
, #vgareg_actl_address
2056 mov dx
, #vgareg_actl_read_data
2063 jne get_palette_loop
2064 mov dx
, #vgareg_actl_reset
2066 mov dx
, #vgareg_actl_address
2069 mov dx
, #vgareg_actl_read_data
2073 mov dx
, #vgareg_actl_reset
2075 mov dx
, #vgareg_actl_address
2085 // --------------------------------------------------------------------------------------------
2087 biosfn_set_single_dac_reg
:
2090 mov dx
, #vgareg_dac_write_address
2093 mov dx
, #vgareg_dac_data
2107 // --------------------------------------------------------------------------------------------
2109 biosfn_set_all_dac_reg
:
2114 mov dx
, #vgareg_dac_write_address
2120 mov dx
, #vgareg_dac_data
2143 // --------------------------------------------------------------------------------------------
2145 biosfn_select_video_dac_color_page
:
2149 mov dx
, #vgareg_actl_reset
2151 mov dx
, #vgareg_actl_address
2154 mov dx
, #vgareg_actl_read_data
2161 mov dx
, #vgareg_actl_address
2166 mov dx
, #vgareg_actl_reset
2168 mov dx
, #vgareg_actl_address
2188 // --------------------------------------------------------------------------------------------
2190 biosfn_read_single_dac_reg
:
2193 mov dx
, #vgareg_dac_read_address
2198 mov dx
, #vgareg_dac_data
2211 // --------------------------------------------------------------------------------------------
2213 biosfn_read_all_dac_reg
:
2218 mov dx
, #vgareg_dac_read_address
2224 mov dx
, #vgareg_dac_data
2247 // --------------------------------------------------------------------------------------------
2249 biosfn_set_pel_mask
:
2252 mov dx
, #vgareg_pel_mask
2260 // --------------------------------------------------------------------------------------------
2262 biosfn_read_pel_mask
:
2265 mov dx
, #vgareg_pel_mask
2273 // --------------------------------------------------------------------------------------------
2275 biosfn_read_video_dac_state
:
2278 mov dx
, #vgareg_actl_reset
2280 mov dx
, #vgareg_actl_address
2283 mov dx
, #vgareg_actl_read_data
2287 mov dx
, #vgareg_actl_reset
2289 mov dx
, #vgareg_actl_address
2292 mov dx
, #vgareg_actl_read_data
2300 mov dx
, #vgareg_actl_reset
2302 mov dx
, #vgareg_actl_address
2310 // --------------------------------------------------------------------------------------------
2311 static void biosfn_perform_gray_scale_summing (start
,count
)
2312 Bit16u start
;Bit16u count
;
2317 inb(VGAREG_ACTL_RESET
);
2318 outb(VGAREG_ACTL_ADDRESS
,0x00);
2320 for( index
= 0; index
< count
; index
++ )
2322 // set read address and switch to read mode
2323 outb(VGAREG_DAC_READ_ADDRESS
,start
);
2324 // get 6-bit wide RGB data values
2325 r
=inb( VGAREG_DAC_DATA
);
2326 g
=inb( VGAREG_DAC_DATA
);
2327 b
=inb( VGAREG_DAC_DATA
);
2329 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
2330 i
= ( ( 77*r
+ 151*g
+ 28*b
) + 0x80 ) >> 8;
2334 // set write address and switch to write mode
2335 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
2336 // write new intensity value
2337 outb( VGAREG_DAC_DATA
, i
&0xff );
2338 outb( VGAREG_DAC_DATA
, i
&0xff );
2339 outb( VGAREG_DAC_DATA
, i
&0xff );
2342 inb(VGAREG_ACTL_RESET
);
2343 outb(VGAREG_ACTL_ADDRESS
,0x20);
2346 // --------------------------------------------------------------------------------------------
2347 static void get_font_access()
2350 mov dx
, #vgareg_sequ_address
2359 mov dx
, #vgareg_grdc_address
2369 static void release_font_access()
2372 mov dx
, #vgareg_sequ_address
2381 mov dx
, #vgareg_read_misc_output
2388 mov dx
, #vgareg_grdc_address
2404 static void set_scan_lines(lines
) Bit8u lines
;
2406 Bit16u crtc_addr
,cols
,page
,vde
;
2407 Bit8u crtc_r9
,ovl
,rows
;
2409 crtc_addr
= read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2410 outb(crtc_addr
, 0x09);
2411 crtc_r9
= inb(crtc_addr
+1);
2412 crtc_r9
= (crtc_r9
& 0xe0) | (lines
- 1);
2413 outb(crtc_addr
+1, crtc_r9
);
2416 biosfn_set_cursor_shape(0x06,0x07);
2420 biosfn_set_cursor_shape(lines
-4,lines
-3);
2422 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, lines
);
2423 outb(crtc_addr
, 0x12);
2424 vde
= inb(crtc_addr
+1);
2425 outb(crtc_addr
, 0x07);
2426 ovl
= inb(crtc_addr
+1);
2427 vde
+= (((ovl
& 0x02) << 7) + ((ovl
& 0x40) << 3) + 1);
2429 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, rows
-1);
2430 cols
= read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
2431 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, rows
* cols
* 2);
2434 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
;
2436 Bit16u blockaddr
,dest
,i
,src
;
2439 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2443 dest
= blockaddr
+ (DX
+ i
) * 32;
2444 memcpyb(0xA000, dest
, ES
, src
, BH
);
2446 release_font_access();
2453 static void biosfn_load_text_8_14_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2455 Bit16u blockaddr
,dest
,i
,src
;
2458 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2459 for(i
=0;i
<0x100;i
++)
2462 dest
= blockaddr
+ i
* 32;
2463 memcpyb(0xA000, dest
, 0xC000, vgafont14
+src
, 14);
2465 release_font_access();
2472 static void biosfn_load_text_8_8_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2474 Bit16u blockaddr
,dest
,i
,src
;
2477 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2478 for(i
=0;i
<0x100;i
++)
2481 dest
= blockaddr
+ i
* 32;
2482 memcpyb(0xA000, dest
, 0xC000, vgafont8
+src
, 8);
2484 release_font_access();
2491 // --------------------------------------------------------------------------------------------
2493 biosfn_set_text_block_specifier
:
2496 mov dx
, #vgareg_sequ_address
2505 // --------------------------------------------------------------------------------------------
2506 static void biosfn_load_text_8_16_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2508 Bit16u blockaddr
,dest
,i
,src
;
2511 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2512 for(i
=0;i
<0x100;i
++)
2515 dest
= blockaddr
+ i
* 32;
2516 memcpyb(0xA000, dest
, 0xC000, vgafont16
+src
, 16);
2518 release_font_access();
2525 static void biosfn_load_gfx_8_8_chars (ES
,BP
) Bit16u ES
;Bit16u BP
;
2531 static void biosfn_load_gfx_user_chars (ES
,BP
,CX
,BL
,DL
) Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit8u BL
;Bit8u DL
;
2537 static void biosfn_load_gfx_8_14_chars (BL
) Bit8u BL
;
2543 static void biosfn_load_gfx_8_8_dd_chars (BL
) Bit8u BL
;
2549 static void biosfn_load_gfx_8_16_chars (BL
) Bit8u BL
;
2555 // --------------------------------------------------------------------------------------------
2556 static void biosfn_get_font_info (BH
,ES
,BP
,CX
,DX
)
2557 Bit8u BH
;Bit16u
*ES
;Bit16u
*BP
;Bit16u
*CX
;Bit16u
*DX
;
2558 {Bit16u ss
=get_SS();
2562 write_word(ss
,ES
,read_word(0x00,0x1f*4));
2563 write_word(ss
,BP
,read_word(0x00,(0x1f*4)+2));
2566 write_word(ss
,ES
,read_word(0x00,0x43*4));
2567 write_word(ss
,BP
,read_word(0x00,(0x43*4)+2));
2570 write_word(ss
,ES
,0xC000);
2571 write_word(ss
,BP
,vgafont14
);
2574 write_word(ss
,ES
,0xC000);
2575 write_word(ss
,BP
,vgafont8
);
2578 write_word(ss
,ES
,0xC000);
2579 write_word(ss
,BP
,vgafont8
+128*8);
2582 write_word(ss
,ES
,0xC000);
2583 write_word(ss
,BP
,vgafont14alt
);
2586 write_word(ss
,ES
,0xC000);
2587 write_word(ss
,BP
,vgafont16
);
2590 write_word(ss
,ES
,0xC000);
2591 write_word(ss
,BP
,vgafont16alt
);
2595 printf("Get font info BH(%02x) was discarded\n",BH
);
2599 // Set byte/char of on screen font
2600 write_word(ss
,CX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
));
2602 // Set Highest char row
2603 write_word(ss
,DX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
));
2606 // --------------------------------------------------------------------------------------------
2607 static void biosfn_get_ega_info (BX
,CX
)
2608 Bit16u
*BX
;Bit16u
*CX
;
2609 {Bit16u ss
=get_SS();
2613 crtc
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2614 if(crtc
==VGAREG_MDA_CRTC_ADDRESS
)
2615 write_word(ss
,BX
,(1<<8)+0x0003);
2617 write_word(ss
,BX
,0x0003);
2619 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2620 write_word(ss
,CX
,(switches
&0x0f));
2623 // --------------------------------------------------------------------------------------------
2624 static void biosfn_alternate_prtsc()
2631 // --------------------------------------------------------------------------------------------
2632 static void biosfn_select_vert_res (res
)
2634 {// res : 00 200 lines, 01 350 lines, 02 400 lines
2635 Bit8u modeset
,switches
;
2637 modeset
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
2638 switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
2641 // set modeset ctl bit 7 and reset bit 4
2642 // set switches bit 3-0 to 0x08
2643 modeset
|=0x80;modeset
&=0xef;
2644 switches
&=0xf0;switches
|=0x08;
2647 // reset modeset ctl bit 7 and bit 4
2648 // set switches bit 3-0 to 0x09
2650 switches
&=0xf0;switches
|=0x09;
2653 // reset modeset ctl bit 7 and set bit 4
2654 // set switches bit 3-0 to 0x09
2655 modeset
|=0x10;modeset
&=0x7f;
2656 switches
&=0xf0;switches
|=0x09;
2660 printf("Select vert res (%02x) was discarded\n",res
);
2664 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,modeset
);
2665 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,switches
);
2668 // --------------------------------------------------------------------------------------------
2670 biosfn_enable_default_palette_loading
:
2677 mov ax
, #biosmem_seg
2679 mov bx
, #biosmem_modeset_ctl
2691 // --------------------------------------------------------------------------------------------
2693 biosfn_enable_video_addressing
:
2700 mov dx
, #vgareg_read_misc_output
2704 mov dx
, #vgareg_write_misc_output
2712 // --------------------------------------------------------------------------------------------
2714 biosfn_enable_grayscale_summing
:
2722 mov ax
, #biosmem_seg
2724 mov bx
, #biosmem_modeset_ctl
2736 // --------------------------------------------------------------------------------------------
2737 static void biosfn_enable_cursor_emulation (disable
)
2742 videoctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
2744 // Bit 0 set if disable!=0
2745 if(disable
!=0x00)videoctl
|=0x01;
2746 else videoctl
&=0xfe;
2748 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,videoctl
);
2751 // --------------------------------------------------------------------------------------------
2752 static void biosfn_switch_video_interface (AL
,ES
,DX
) Bit8u AL
;Bit16u ES
;Bit16u DX
;
2758 static void biosfn_enable_video_refresh_control (AL
) Bit8u AL
;
2765 // --------------------------------------------------------------------------------------------
2766 static void biosfn_write_string (flag
,page
,attr
,count
,row
,col
,seg
,offset
)
2767 Bit8u flag
;Bit8u page
;Bit8u attr
;Bit16u count
;Bit8u row
;Bit8u col
;Bit16u seg
;Bit16u offset
;
2769 Bit16u newcurs
,oldcurs
,dummy
;
2772 // Read curs info for the page
2773 biosfn_get_cursor_pos(page
,&dummy
,&oldcurs
);
2775 // if row=0xff special case : use current cursor position
2777 {col
=oldcurs
&0x00ff;
2778 row
=(oldcurs
&0xff00)>>8;
2781 newcurs
=row
; newcurs
<<=8; newcurs
+=col
;
2782 biosfn_set_cursor_pos(page
,newcurs
);
2786 car
=read_byte(seg
,offset
++);
2788 attr
=read_byte(seg
,offset
++);
2790 biosfn_write_teletype(car
,page
,attr
,WITH_ATTR
);
2793 // Set back curs pos
2795 biosfn_set_cursor_pos(page
,oldcurs
);
2798 // --------------------------------------------------------------------------------------------
2802 je biosfn_read_display_code
2804 je biosfn_set_display_code
2809 biosfn_read_display_code
:
2812 mov ax
, #biosmem_seg
2814 mov bx
, #biosmem_dcc_index
2822 biosfn_set_display_code
:
2826 mov ax
, #biosmem_seg
2829 mov bx
, #biosmem_dcc_index
2835 mov bx
, #msg_alt_dcc
2848 .ascii
"Alternate Display code (%02x) was discarded"
2849 .byte
0x0d,0x0a,0x00
2853 // --------------------------------------------------------------------------------------------
2854 static void biosfn_read_state_info (BX
,ES
,DI
)
2855 Bit16u BX
;Bit16u ES
;Bit16u DI
;
2857 // Address of static functionality table
2858 write_word(ES
,DI
+0x00,&static_functionality
);
2859 write_word(ES
,DI
+0x02,0xC000);
2861 // Hard coded copy from BIOS area. Should it be cleaner ?
2862 memcpyb(ES
,DI
+0x04,BIOSMEM_SEG
,0x49,30);
2863 memcpyb(ES
,DI
+0x22,BIOSMEM_SEG
,0x84,3);
2865 write_byte(ES
,DI
+0x25,read_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
));
2866 write_byte(ES
,DI
+0x26,0);
2867 write_byte(ES
,DI
+0x27,16);
2868 write_byte(ES
,DI
+0x28,0);
2869 write_byte(ES
,DI
+0x29,8);
2870 write_byte(ES
,DI
+0x2a,2);
2871 write_byte(ES
,DI
+0x2b,0);
2872 write_byte(ES
,DI
+0x2c,0);
2873 write_byte(ES
,DI
+0x31,3);
2874 write_byte(ES
,DI
+0x32,0);
2876 memsetb(ES
,DI
+0x33,0,13);
2879 // --------------------------------------------------------------------------------------------
2880 static void biosfn_read_video_state_size (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2886 static void biosfn_save_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2892 static void biosfn_restore_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
2899 // ============================================================================================
2903 // ============================================================================================
2905 // --------------------------------------------------------------------------------------------
2906 static Bit8u
find_vga_entry(mode
)
2910 for(i
=0;i
<=MODE_MAX
;i
++)
2911 if(vga_modes
[i
].svgamode
==mode
)
2918 /* =========================================================== */
2922 /* =========================================================== */
2924 // --------------------------------------------------------------------------------------------
2925 static void memsetb(seg
,offset
,value
,count
)
2940 mov cx
, 10[bp
] ; count
2943 mov ax
, 4[bp
] ; segment
2945 mov ax
, 6[bp
] ; offset
2947 mov al
, 8[bp
] ; value
2962 // --------------------------------------------------------------------------------------------
2963 static void memsetw(seg
,offset
,value
,count
)
2978 mov cx
, 10[bp
] ; count
2981 mov ax
, 4[bp
] ; segment
2983 mov ax
, 6[bp
] ; offset
2985 mov ax
, 8[bp
] ; value
3000 // --------------------------------------------------------------------------------------------
3001 static void memcpyb(dseg
,doffset
,sseg
,soffset
,count
)
3019 mov cx
, 12[bp
] ; count
3022 mov ax
, 4[bp
] ; dsegment
3024 mov ax
, 6[bp
] ; doffset
3026 mov ax
, 8[bp
] ; ssegment
3028 mov ax
, 10[bp
] ; soffset
3046 // --------------------------------------------------------------------------------------------
3047 static void memcpyw(dseg
,doffset
,sseg
,soffset
,count
)
3065 mov cx
, 12[bp
] ; count
3068 mov ax
, 4[bp
] ; dsegment
3070 mov ax
, 6[bp
] ; doffset
3072 mov ax
, 8[bp
] ; ssegment
3074 mov ax
, 10[bp
] ; soffset
3092 /* =========================================================== */
3094 * These functions where ripped from Kevin's rombios.c
3096 /* =========================================================== */
3098 // --------------------------------------------------------------------------------------------
3100 read_byte(seg
, offset
)
3110 mov ax
, 4[bp
] ; segment
3112 mov bx
, 6[bp
] ; offset
3114 ;; al
= return value (byte
)
3122 // --------------------------------------------------------------------------------------------
3124 read_word(seg
, offset
)
3134 mov ax
, 4[bp
] ; segment
3136 mov bx
, 6[bp
] ; offset
3138 ;; ax
= return value (word
)
3146 // --------------------------------------------------------------------------------------------
3148 write_byte(seg
, offset
, data
)
3160 mov ax
, 4[bp
] ; segment
3162 mov bx
, 6[bp
] ; offset
3163 mov al
, 8[bp
] ; data byte
3164 mov
[bx
], al
; write data byte
3173 // --------------------------------------------------------------------------------------------
3175 write_word(seg
, offset
, data
)
3187 mov ax
, 4[bp
] ; segment
3189 mov bx
, 6[bp
] ; offset
3190 mov ax
, 8[bp
] ; data word
3191 mov
[bx
], ax
; write data word
3200 // --------------------------------------------------------------------------------------------
3235 // --------------------------------------------------------------------------------------------
3257 // --------------------------------------------------------------------------------------------
3287 void unimplemented()
3289 printf("--> Unimplemented\n");
3294 printf("--> Unknown int10\n");
3298 // --------------------------------------------------------------------------------------------
3302 Bit8u c
, format_char
;
3304 unsigned format_width
, i
;
3306 Bit16u arg_seg
, arg
, digit
, nibble
, shift_count
;
3314 while (c
= read_byte(0xc000, s
)) {
3319 else if (in_format
) {
3320 if ( (c
>='0') && (c
<='9') ) {
3321 format_width
= (format_width
* 10) + (c
- '0');
3323 else if (c
== 'x') {
3324 arg_ptr
++; // increment to next arg
3325 arg
= read_word(arg_seg
, arg_ptr
);
3326 if (format_width
== 0)
3329 digit
= format_width
- 1;
3330 for (i
=0; i
<format_width
; i
++) {
3331 nibble
= (arg
>> (4 * digit
)) & 0x000f;
3333 outb(0x0500, nibble
+ '0');
3335 outb(0x0500, (nibble
- 10) + 'A');
3340 //else if (c == 'd') {
3355 // --------------------------------------------------------------------------------------------
3358 ;; DATA_SEG_DEFS_HERE
3362 .ascii
"vgabios ends here"
3366 ;; BLOCK_STRINGS_BEGIN