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_alternate_prtsc();
105 static void biosfn_switch_video_interface();
106 static void biosfn_enable_video_refresh_control();
107 static void biosfn_write_string();
108 static void biosfn_read_state_info();
109 static void biosfn_read_video_state_size();
110 static void biosfn_save_video_state();
111 static void biosfn_restore_video_state();
113 // This is for compiling with gcc2 and gcc3
114 #define ASM_START #asm
115 #define ASM_END #endasm
140 .byte
0x55, 0xaa /* BIOS signature, required for BIOS extensions */
142 .byte
0x40 /* BIOS extension length in units of 512 bytes */
147 jmp vgabios_init_func
150 .ascii
"Plex86/Bochs VGABios"
154 // Info from Bart Oldeman
173 .ascii
"(C) 2003 the LGPL VGABios developers Team"
178 .ascii
"This VGA/VBE Bios is released under the GNU LGPL"
184 .ascii
"Please visit :"
186 ;;.ascii
" . http://www.plex86.org"
188 .ascii
" . http://bochs.sourceforge.net"
190 .ascii
" . http://www.nongnu.org/vgabios"
196 ;; ============================================================================================
200 ;; ============================================================================================
206 ;; init basic bios vars
210 ;; init vbe functions
215 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
221 ;; display splash screen
222 call _display_splash_screen
224 ;; init video mode
and clear the screen
233 call vbe_display_info
238 call cirrus_display_info
248 vgabios_int10_handler
:
263 call biosfn_get_video_mode
278 call biosfn_set_text_block_specifier
285 call biosfn_get_ega_info
290 call biosfn_select_vert_res
295 call biosfn_enable_default_palette_loading
300 call biosfn_enable_video_addressing
305 call biosfn_enable_grayscale_summing
310 call biosfn_enable_cursor_emulation
328 jne int10_test_vbe_05
329 call vbe_biosfn_return_current_mode
333 jne int10_test_vbe_06
334 call vbe_biosfn_display_window_control
338 jne int10_test_vbe_07
339 call vbe_biosfn_set_get_logical_scan_line_length
343 jne int10_test_vbe_08
344 call vbe_biosfn_set_get_display_start
349 call vbe_biosfn_set_get_dac_palette_format
358 ;; We have to set ds to access the right data segment
371 #include "vgatables.h"
372 #include "vgafonts.h"
375 * Boot time harware inits
379 ;; switch to color mode
and enable CPU access
480 lines
384 ;; more than
64k
3C4
/04
392 mov bx
, #msg_vga_init
400 .ascii
"VGABios $Id$"
404 // --------------------------------------------------------------------------------------------
406 * Boot time bios area inits
411 mov ax
, # BIOSMEM_SEG
414 ;; init detected hardware BIOS Area
415 mov bx
, # BIOSMEM_INITIAL_MODE
420 ;; Just
for the first int10 find its children
422 ;; the
default char height
423 mov bx
, # BIOSMEM_CHAR_HEIGHT
428 mov bx
, # BIOSMEM_VIDEO_CTL
432 ;; Set the basic screen we have
433 mov bx
, # BIOSMEM_SWITCHES
437 ;; Set the basic modeset options
438 mov bx
, # BIOSMEM_MODESET_CTL
442 ;; Set the
default MSR
443 mov bx
, # BIOSMEM_CURRENT_MSR
451 // --------------------------------------------------------------------------------------------
453 * Boot time Splash screen
455 static void display_splash_screen()
459 // --------------------------------------------------------------------------------------------
464 static void display_info()
471 mov si
,#vgabios_version
474 ;;mov si
,#vgabios_copyright
475 ;;call _display_string
477 ;;call _display_string
479 mov si
,#vgabios_license
481 mov si
,#vgabios_website
486 static void display_string()
488 // Get length of string
515 // --------------------------------------------------------------------------------------------
517 static void int10_debugmsg(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
518 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
520 // 0E is write char...
522 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX
,CX
,DX
);
526 // --------------------------------------------------------------------------------------------
528 * int10 main dispatcher
530 static void int10_func(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
531 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
538 biosfn_set_video_mode(GET_AL());
539 switch(GET_AL()&0x7F)
557 biosfn_set_cursor_shape(GET_CH(),GET_CL());
560 biosfn_set_cursor_pos(GET_BH(),DX
);
563 biosfn_get_cursor_pos(GET_BH(),&CX
,&DX
);
566 // Read light pen pos (unimplemented)
576 biosfn_set_active_page(GET_AL());
579 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP
);
582 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN
);
585 biosfn_read_char_attr(GET_BH(),&AX
);
588 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX
);
591 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX
);
594 biosfn_write_pixel(GET_BH(),GET_AL(),CX
,DX
);
597 biosfn_read_pixel(GET_BH(),CX
,DX
,&AX
);
600 // Ralf Brown Interrupt list is WRONG on bh(page)
601 // We do output only on the current page !
602 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR
);
605 // All other functions of group AH=0x10 rewritten in assembler
606 biosfn_perform_gray_scale_summing(BX
,CX
);
613 biosfn_load_text_user_pat(GET_AL(),ES
,BP
,CX
,DX
,GET_BL(),GET_BH());
617 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
621 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
625 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
628 biosfn_load_gfx_8_8_chars(ES
,BP
);
631 biosfn_load_gfx_user_chars(ES
,BP
,CX
,GET_BL(),GET_DL());
634 biosfn_load_gfx_8_14_chars(GET_BL());
637 biosfn_load_gfx_8_8_dd_chars(GET_BL());
640 biosfn_load_gfx_8_16_chars(GET_BL());
643 biosfn_get_font_info(GET_BH(),&ES
,&BP
,&CX
,&DX
);
656 biosfn_alternate_prtsc();
659 biosfn_switch_video_interface(GET_AL(),ES
,DX
);
663 biosfn_enable_video_refresh_control(GET_AL());
673 biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX
,GET_DH(),GET_DL(),ES
,BP
);
676 biosfn_read_state_info(BX
,ES
,DI
);
683 biosfn_read_video_state_size(CX
,&BX
);
686 biosfn_save_video_state(CX
,ES
,BX
);
689 biosfn_restore_video_state(CX
,ES
,BX
);
701 if (vbe_has_vbe_display()) {
705 vbe_biosfn_return_controller_information(&AX
,ES
,DI
);
708 vbe_biosfn_return_mode_information(&AX
,CX
,ES
,DI
);
711 vbe_biosfn_set_mode(&AX
,BX
,ES
,DI
);
759 // ============================================================================================
763 // ============================================================================================
765 static void biosfn_set_video_mode(mode
) Bit8u mode
;
766 {// mode: Bit 7 is 1 if no clear screen
768 // Should we clear the screen ?
769 Bit8u noclearmem
=mode
&0x80;
770 Bit8u line
,mmask
,*palette
;
771 Bit16u i
,twidth
,theight
,cheight
;
772 Bit8u modeset_ctl
,video_ctl
,vga_switches
;
776 if (vbe_has_vbe_display()) {
777 dispi_set_enable(VBE_DISPI_DISABLED
);
784 // find the entry in the video modes
785 line
=find_vga_entry(mode
);
788 printf("mode search %02x found line %02x\n",mode
,line
);
794 twidth
=vga_modes
[line
].twidth
;
795 theight
=vga_modes
[line
].theight
;
796 cheight
=vga_modes
[line
].cheight
;
798 // Read the bios vga control
799 video_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
801 // Read the bios vga switches
802 vga_switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
804 // Read the bios mode set control
805 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
807 // Then we know the number of lines
810 // if palette loading (bit 3 of modeset ctl = 0)
811 if((modeset_ctl
&0x08)==0)
813 outb(VGAREG_PEL_MASK
,vga_modes
[line
].pelmask
);
815 // Set the whole dac always, from 0
816 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
818 // From which palette
819 switch(vga_modes
[line
].dacmodel
)
833 // Always 256*3 values
834 for(i
=0;i
<0x0100;i
++)
835 {if(i
<=dac_regs
[vga_modes
[line
].dacmodel
])
836 {outb(VGAREG_DAC_DATA
,palette
[(i
*3)+0]);
837 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+1]);
838 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+2]);
841 {outb(VGAREG_DAC_DATA
,0);
842 outb(VGAREG_DAC_DATA
,0);
843 outb(VGAREG_DAC_DATA
,0);
846 if((modeset_ctl
&0x02)==0x02)
848 biosfn_perform_gray_scale_summing(0x00, 0x100);
852 // Reset Attribute Ctl flip-flop
853 inb(VGAREG_ACTL_RESET
);
856 for(i
=0;i
<=ACTL_MAX_REG
;i
++)
857 {outb(VGAREG_ACTL_ADDRESS
,i
);
858 outb(VGAREG_ACTL_WRITE_DATA
,actl_regs
[vga_modes
[line
].actlmodel
][i
]);
862 for(i
=0;i
<=SEQU_MAX_REG
;i
++)
863 {outb(VGAREG_SEQU_ADDRESS
,i
);
864 outb(VGAREG_SEQU_DATA
,sequ_regs
[vga_modes
[line
].sequmodel
][i
]);
868 for(i
=0;i
<=GRDC_MAX_REG
;i
++)
869 {outb(VGAREG_GRDC_ADDRESS
,i
);
870 outb(VGAREG_GRDC_DATA
,grdc_regs
[vga_modes
[line
].grdcmodel
][i
]);
873 // Set CRTC address VGA or MDA
874 crtc_addr
=vga_modes
[line
].memmodel
==MTEXT
?VGAREG_MDA_CRTC_ADDRESS
:VGAREG_VGA_CRTC_ADDRESS
;
876 // Disable CRTC write protection
877 outw(crtc_addr
,0x0011);
879 for(i
=0;i
<=CRTC_MAX_REG
;i
++)
881 outb(crtc_addr
+1,crtc_regs
[vga_modes
[line
].crtcmodel
][i
]);
884 // Set the misc register
885 outb(VGAREG_WRITE_MISC_OUTPUT
,vga_modes
[line
].miscreg
);
888 outb(VGAREG_ACTL_ADDRESS
,0x20);
889 inb(VGAREG_ACTL_RESET
);
893 if(vga_modes
[line
].class==TEXT
)
895 memsetw(vga_modes
[line
].sstart
,0,0x0720,0x4000); // 32k
901 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x4000); // 32k
905 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
906 mmask
= inb( VGAREG_SEQU_DATA
);
907 outb( VGAREG_SEQU_DATA
, 0x0f ); // all planes
908 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x8000); // 64k
909 outb( VGAREG_SEQU_DATA
, mmask
);
915 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
,mode
);
916 write_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
,twidth
);
917 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
,vga_modes
[line
].slength
);
918 write_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
,crtc_addr
);
919 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
,theight
-1);
920 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
,cheight
);
921 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60|noclearmem
));
922 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,0xF9);
923 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
)&0x7f);
925 // FIXME We nearly have the good tables. to be reworked
926 write_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
,0x08); // 8 is VGA should be ok for now
927 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
,0x00);
928 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
+2,0x00);
931 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MSR
,0x00); // Unavailable on vanilla vga, but...
932 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAL
,0x00); // Unavailable on vanilla vga, but...
935 if(vga_modes
[line
].class==TEXT
)
937 biosfn_set_cursor_shape(0x06,0x07);
940 // Set cursor pos for page 0..7
942 biosfn_set_cursor_pos(i
,0x0000);
945 biosfn_set_active_page(0x00);
947 // Write the fonts in memory
948 if(vga_modes
[line
].class==TEXT
)
951 ;; copy
and activate
8x16 font
961 // Set the ints 0x1F and 0x43
963 SET_INT_VECTOR(0x1f, #0xC000, #_vgafont8+128*8)
969 SET_INT_VECTOR(0x43, #0xC000, #_vgafont8)
974 SET_INT_VECTOR(0x43, #0xC000, #_vgafont14)
979 SET_INT_VECTOR(0x43, #0xC000, #_vgafont16)
985 // --------------------------------------------------------------------------------------------
986 static void biosfn_set_cursor_shape (CH
,CL
)
988 {Bit16u cheight
,curs
,crtc_addr
;
995 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
,curs
);
997 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
998 cheight
= read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
);
999 if((modeset_ctl
&0x01) && (cheight
>8) && (CL
<8) && (CH
<0x20))
1003 CH
= ((CH
+1) * cheight
/ 8) -1;
1007 CH
= ((CL
+1) * cheight
/ 8) - 2;
1009 CL
= ((CL
+1) * cheight
/ 8) - 1;
1012 // CTRC regs 0x0a and 0x0b
1013 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1014 outb(crtc_addr
,0x0a);
1015 outb(crtc_addr
+1,CH
);
1016 outb(crtc_addr
,0x0b);
1017 outb(crtc_addr
+1,CL
);
1020 // --------------------------------------------------------------------------------------------
1021 static void biosfn_set_cursor_pos (page
, cursor
)
1022 Bit8u page
;Bit16u cursor
;
1024 Bit8u xcurs
,ycurs
,current
;
1025 Bit16u nbcols
,nbrows
,address
,crtc_addr
;
1027 // Should not happen...
1031 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*page
, cursor
);
1033 // Set the hardware cursor
1034 current
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1037 // Get the dimensions
1038 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1039 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1041 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1043 // Calculate the address knowing nbcols nbrows and page num
1044 address
=SCREEN_IO_START(nbcols
,nbrows
,page
)+xcurs
+ycurs
*nbcols
;
1046 // CRTC regs 0x0e and 0x0f
1047 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1048 outb(crtc_addr
,0x0e);
1049 outb(crtc_addr
+1,(address
&0xff00)>>8);
1050 outb(crtc_addr
,0x0f);
1051 outb(crtc_addr
+1,address
&0x00ff);
1055 // --------------------------------------------------------------------------------------------
1056 static void biosfn_get_cursor_pos (page
,shape
, pos
)
1057 Bit8u page
;Bit16u
*shape
;Bit16u
*pos
;
1062 write_word(ss
, shape
, 0);
1063 write_word(ss
, pos
, 0);
1066 // FIXME should handle VGA 14/16 lines
1067 write_word(ss
,shape
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
));
1068 write_word(ss
,pos
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_POS
+page
*2));
1071 // --------------------------------------------------------------------------------------------
1072 static void biosfn_set_active_page (page
)
1075 Bit16u cursor
,dummy
,crtc_addr
;
1076 Bit16u nbcols
,nbrows
,address
;
1082 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1083 line
=find_vga_entry(mode
);
1084 if(line
==0xFF)return;
1086 // Get pos curs pos for the right page
1087 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1089 if(vga_modes
[line
].class==TEXT
)
1091 // Get the dimensions
1092 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1093 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1095 // Calculate the address knowing nbcols nbrows and page num
1096 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1097 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
,address
);
1100 address
=SCREEN_IO_START(nbcols
,nbrows
,page
);
1104 address
= page
*vga_modes
[line
].slength
;
1107 // CRTC regs 0x0c and 0x0d
1108 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1109 outb(crtc_addr
,0x0c);
1110 outb(crtc_addr
+1,(address
&0xff00)>>8);
1111 outb(crtc_addr
,0x0d);
1112 outb(crtc_addr
+1,address
&0x00ff);
1114 // And change the BIOS page
1115 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
,page
);
1118 printf("Set active page %02x address %04x\n",page
,address
);
1121 // Display the cursor, now the page is active
1122 biosfn_set_cursor_pos(page
,cursor
);
1125 // --------------------------------------------------------------------------------------------
1126 static void vgamem_copy_pl4(xstart
,ysrc
,ydest
,cols
,nbcols
,cheight
)
1127 Bit8u xstart
;Bit8u ysrc
;Bit8u ydest
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;
1132 src
=ysrc
*cheight
*nbcols
+xstart
;
1133 dest
=ydest
*cheight
*nbcols
+xstart
;
1134 outw(VGAREG_GRDC_ADDRESS
, 0x0105);
1135 for(i
=0;i
<cheight
;i
++)
1137 memcpyb(0xa000,dest
+i
*nbcols
,0xa000,src
+i
*nbcols
,cols
);
1139 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1142 // --------------------------------------------------------------------------------------------
1143 static void vgamem_fill_pl4(xstart
,ystart
,cols
,nbcols
,cheight
,attr
)
1144 Bit8u xstart
;Bit8u ystart
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;Bit8u attr
;
1149 dest
=ystart
*cheight
*nbcols
+xstart
;
1150 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1151 for(i
=0;i
<cheight
;i
++)
1153 memsetb(0xa000,dest
+i
*nbcols
,attr
,cols
);
1155 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1158 // --------------------------------------------------------------------------------------------
1159 static void vgamem_copy_cga(xstart
,ysrc
,ydest
,cols
,nbcols
,cheight
)
1160 Bit8u xstart
;Bit8u ysrc
;Bit8u ydest
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;
1165 src
=((ysrc
*cheight
*nbcols
)>>1)+xstart
;
1166 dest
=((ydest
*cheight
*nbcols
)>>1)+xstart
;
1167 for(i
=0;i
<cheight
;i
++)
1170 memcpyb(0xb800,0x2000+dest
+(i
>>1)*nbcols
,0xb800,0x2000+src
+(i
>>1)*nbcols
,cols
);
1172 memcpyb(0xb800,dest
+(i
>>1)*nbcols
,0xb800,src
+(i
>>1)*nbcols
,cols
);
1176 // --------------------------------------------------------------------------------------------
1177 static void vgamem_fill_cga(xstart
,ystart
,cols
,nbcols
,cheight
,attr
)
1178 Bit8u xstart
;Bit8u ystart
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;Bit8u attr
;
1183 dest
=((ystart
*cheight
*nbcols
)>>1)+xstart
;
1184 for(i
=0;i
<cheight
;i
++)
1187 memsetb(0xb800,0x2000+dest
+(i
>>1)*nbcols
,attr
,cols
);
1189 memsetb(0xb800,dest
+(i
>>1)*nbcols
,attr
,cols
);
1193 // --------------------------------------------------------------------------------------------
1194 static void biosfn_scroll (nblines
,attr
,rul
,cul
,rlr
,clr
,page
,dir
)
1195 Bit8u nblines
;Bit8u attr
;Bit8u rul
;Bit8u cul
;Bit8u rlr
;Bit8u clr
;Bit8u page
;Bit8u dir
;
1197 // page == 0xFF if current
1199 Bit8u mode
,line
,cheight
,bpp
,cols
;
1200 Bit16u nbcols
,nbrows
,i
;
1207 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1208 line
=find_vga_entry(mode
);
1209 if(line
==0xFF)return;
1211 // Get the dimensions
1212 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1213 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1215 // Get the current page
1217 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1219 if(rlr
>=nbrows
)rlr
=nbrows
-1;
1220 if(clr
>=nbcols
)clr
=nbcols
-1;
1221 if(nblines
>nbrows
)nblines
=0;
1224 if(vga_modes
[line
].class==TEXT
)
1226 // Compute the address
1227 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1229 printf("Scroll, address %04x (%04x %04x %02x)\n",address
,nbrows
,nbcols
,page
);
1232 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1234 memsetw(vga_modes
[line
].sstart
,address
,(Bit16u
)attr
*0x100+' ',nbrows
*nbcols
);
1239 {for(i
=rul
;i
<=rlr
;i
++)
1241 if((i
+nblines
>rlr
)||(nblines
==0))
1242 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',cols
);
1244 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
+nblines
)*nbcols
+cul
)*2,cols
);
1248 {for(i
=rlr
;i
>=rul
;i
--)
1250 if((i
<rul
+nblines
)||(nblines
==0))
1251 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',cols
);
1253 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
-nblines
)*nbcols
+cul
)*2,cols
);
1260 // FIXME gfx mode not complete
1261 cheight
=vga_modes
[line
].cheight
;
1262 switch(vga_modes
[line
].memmodel
)
1266 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1268 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1269 memsetb(vga_modes
[line
].sstart
,0,attr
,nbrows
*nbcols
*cheight
);
1270 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1275 {for(i
=rul
;i
<=rlr
;i
++)
1277 if((i
+nblines
>rlr
)||(nblines
==0))
1278 vgamem_fill_pl4(cul
,i
,cols
,nbcols
,cheight
,attr
);
1280 vgamem_copy_pl4(cul
,i
+nblines
,i
,cols
,nbcols
,cheight
);
1284 {for(i
=rlr
;i
>=rul
;i
--)
1286 if((i
<rul
+nblines
)||(nblines
==0))
1287 vgamem_fill_pl4(cul
,i
,cols
,nbcols
,cheight
,attr
);
1289 vgamem_copy_pl4(cul
,i
,i
-nblines
,cols
,nbcols
,cheight
);
1295 bpp
=vga_modes
[line
].pixbits
;
1296 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1298 memsetb(vga_modes
[line
].sstart
,0,attr
,nbrows
*nbcols
*cheight
*bpp
);
1310 {for(i
=rul
;i
<=rlr
;i
++)
1312 if((i
+nblines
>rlr
)||(nblines
==0))
1313 vgamem_fill_cga(cul
,i
,cols
,nbcols
,cheight
,attr
);
1315 vgamem_copy_cga(cul
,i
+nblines
,i
,cols
,nbcols
,cheight
);
1319 {for(i
=rlr
;i
>=rul
;i
--)
1321 if((i
<rul
+nblines
)||(nblines
==0))
1322 vgamem_fill_cga(cul
,i
,cols
,nbcols
,cheight
,attr
);
1324 vgamem_copy_cga(cul
,i
,i
-nblines
,cols
,nbcols
,cheight
);
1331 printf("Scroll in graphics mode ");
1338 // --------------------------------------------------------------------------------------------
1339 static void biosfn_read_char_attr (page
,car
)
1340 Bit8u page
;Bit16u
*car
;
1341 {Bit16u ss
=get_SS();
1342 Bit8u xcurs
,ycurs
,mode
,line
;
1343 Bit16u nbcols
,nbrows
,address
;
1344 Bit16u cursor
,dummy
;
1347 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1348 line
=find_vga_entry(mode
);
1349 if(line
==0xFF)return;
1351 // Get the cursor pos for the page
1352 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1353 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1355 // Get the dimensions
1356 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1357 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1359 if(vga_modes
[line
].class==TEXT
)
1361 // Compute the address
1362 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1364 write_word(ss
,car
,read_word(vga_modes
[line
].sstart
,address
));
1375 // --------------------------------------------------------------------------------------------
1376 static void write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
)
1377 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u cheight
;
1381 Bit16u addr
,dest
,src
;
1393 addr
=xcurs
+ycurs
*cheight
*nbcols
;
1394 src
= car
* cheight
;
1395 outw(VGAREG_SEQU_ADDRESS
, 0x0f02);
1396 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1399 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1403 outw(VGAREG_GRDC_ADDRESS
, 0x0003);
1405 for(i
=0;i
<cheight
;i
++)
1411 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1412 read_byte(0xa000,dest
);
1413 if(fdata
[src
+i
]&mask
)
1415 write_byte(0xa000,dest
,attr
&0x0f);
1419 write_byte(0xa000,dest
,0x00);
1424 mov dx
, # VGAREG_GRDC_ADDRESS
1434 // --------------------------------------------------------------------------------------------
1435 static void write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
)
1436 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u bpp
;
1438 Bit8u i
,j
,mask
,data
;
1440 Bit16u addr
,dest
,src
;
1443 addr
=(xcurs
*bpp
)+ycurs
*320;
1447 dest
=addr
+(i
>>1)*80;
1448 if (i
& 1) dest
+= 0x2000;
1454 data
= read_byte(0xb800,dest
);
1462 if (fdata
[src
+i
] & mask
)
1466 data
^= (attr
& 0x01) << (7-j
);
1470 data
|= (attr
& 0x01) << (7-j
);
1475 write_byte(0xb800,dest
,data
);
1483 data
= read_byte(0xb800,dest
);
1491 if (fdata
[src
+i
] & mask
)
1495 data
^= (attr
& 0x03) << ((3-j
)*2);
1499 data
|= (attr
& 0x03) << ((3-j
)*2);
1504 write_byte(0xb800,dest
,data
);
1511 // --------------------------------------------------------------------------------------------
1512 static void write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
)
1513 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;
1515 Bit8u i
,j
,mask
,data
;
1517 Bit16u addr
,dest
,src
;
1520 addr
=xcurs
*8+ycurs
*nbcols
*64;
1524 dest
=addr
+i
*nbcols
*8;
1529 if (fdata
[src
+i
] & mask
)
1533 write_byte(0xa000,dest
+j
,data
);
1539 // --------------------------------------------------------------------------------------------
1540 static void biosfn_write_char_attr (car
,page
,attr
,count
)
1541 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1543 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1544 Bit16u nbcols
,nbrows
,address
;
1545 Bit16u cursor
,dummy
;
1548 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1549 line
=find_vga_entry(mode
);
1550 if(line
==0xFF)return;
1552 // Get the cursor pos for the page
1553 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1554 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1556 // Get the dimensions
1557 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1558 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1560 if(vga_modes
[line
].class==TEXT
)
1562 // Compute the address
1563 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1565 dummy
=((Bit16u
)attr
<<8)+car
;
1566 memsetw(vga_modes
[line
].sstart
,address
,dummy
,count
);
1570 // FIXME gfx mode not complete
1571 cheight
=vga_modes
[line
].cheight
;
1572 bpp
=vga_modes
[line
].pixbits
;
1573 while((count
-->0) && (xcurs
<nbcols
))
1575 switch(vga_modes
[line
].memmodel
)
1579 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1582 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1585 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1597 // --------------------------------------------------------------------------------------------
1598 static void biosfn_write_char_only (car
,page
,attr
,count
)
1599 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1601 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1602 Bit16u nbcols
,nbrows
,address
;
1603 Bit16u cursor
,dummy
;
1606 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1607 line
=find_vga_entry(mode
);
1608 if(line
==0xFF)return;
1610 // Get the cursor pos for the page
1611 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1612 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1614 // Get the dimensions
1615 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1616 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1618 if(vga_modes
[line
].class==TEXT
)
1620 // Compute the address
1621 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1624 {write_byte(vga_modes
[line
].sstart
,address
,car
);
1630 // FIXME gfx mode not complete
1631 cheight
=vga_modes
[line
].cheight
;
1632 bpp
=vga_modes
[line
].pixbits
;
1633 while((count
-->0) && (xcurs
<nbcols
))
1635 switch(vga_modes
[line
].memmodel
)
1639 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1642 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1645 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1657 // --------------------------------------------------------------------------------------------
1661 je biosfn_set_border_color
1663 je biosfn_set_palette
1668 biosfn_set_border_color
:
1673 mov dx
, # VGAREG_ACTL_RESET
1675 mov dx
, # VGAREG_ACTL_ADDRESS
1688 mov dx
, # VGAREG_ACTL_ADDRESS
1691 mov dx
, # VGAREG_ACTL_READ_DATA
1695 mov dx
, # VGAREG_ACTL_ADDRESS
1699 jne set_intensity_loop
1712 mov dx
, # VGAREG_ACTL_RESET
1716 set_cga_palette_loop
:
1717 mov dx
, # VGAREG_ACTL_ADDRESS
1720 mov dx
, # VGAREG_ACTL_READ_DATA
1724 mov dx
, # VGAREG_ACTL_ADDRESS
1728 jne set_cga_palette_loop
1738 // --------------------------------------------------------------------------------------------
1739 static void biosfn_write_pixel (BH
,AL
,CX
,DX
) Bit8u BH
;Bit8u AL
;Bit16u CX
;Bit16u DX
;
1741 Bit8u mode
,line
,mask
,attr
,data
;
1745 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1746 line
=find_vga_entry(mode
);
1747 if(line
==0xFF)return;
1748 if(vga_modes
[line
].class==TEXT
)return;
1750 switch(vga_modes
[line
].memmodel
)
1754 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1755 mask
= 0x80 >> (CX
& 0x07);
1756 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1757 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1758 data
= read_byte(0xa000,addr
);
1761 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1763 write_byte(0xa000,addr
,AL
);
1765 mov dx
, # VGAREG_GRDC_ADDRESS
1775 if(vga_modes
[line
].pixbits
==2)
1777 addr
=(CX
>>2)+(DX
>>1)*80;
1781 addr
=(CX
>>3)+(DX
>>1)*80;
1783 if (DX
& 1) addr
+= 0x2000;
1784 data
= read_byte(0xb800,addr
);
1785 if(vga_modes
[line
].pixbits
==2)
1787 attr
= (AL
& 0x03) << ((3 - (CX
& 0x03)) * 2);
1788 mask
= 0x03 << ((3 - (CX
& 0x03)) * 2);
1792 attr
= (AL
& 0x01) << (7 - (CX
& 0x07));
1793 mask
= 0x01 << (7 - (CX
& 0x07));
1804 write_byte(0xb800,addr
,data
);
1807 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1808 write_byte(0xa000,addr
,AL
);
1817 // --------------------------------------------------------------------------------------------
1818 static void biosfn_read_pixel (BH
,CX
,DX
,AX
) Bit8u BH
;Bit16u CX
;Bit16u DX
;Bit16u
*AX
;
1820 Bit8u mode
,line
,mask
,attr
,data
,i
;
1825 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1826 line
=find_vga_entry(mode
);
1827 if(line
==0xFF)return;
1828 if(vga_modes
[line
].class==TEXT
)return;
1830 switch(vga_modes
[line
].memmodel
)
1834 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1835 mask
= 0x80 >> (CX
& 0x07);
1839 outw(VGAREG_GRDC_ADDRESS
, (i
<< 8) | 0x04);
1840 data
= read_byte(0xa000,addr
) & mask
;
1841 if (data
> 0) attr
|= (0x01 << i
);
1845 addr
=(CX
>>2)+(DX
>>1)*80;
1846 if (DX
& 1) addr
+= 0x2000;
1847 data
= read_byte(0xb800,addr
);
1848 if(vga_modes
[line
].pixbits
==2)
1850 attr
= (data
>> ((3 - (CX
& 0x03)) * 2)) & 0x03;
1854 attr
= (data
>> (7 - (CX
& 0x07))) & 0x01;
1858 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1859 attr
=read_byte(0xa000,addr
);
1867 write_word(ss
,AX
,(read_word(ss
,AX
) & 0xff00) | attr
);
1870 // --------------------------------------------------------------------------------------------
1871 static void biosfn_write_teletype (car
, page
, attr
, flag
)
1872 Bit8u car
;Bit8u page
;Bit8u attr
;Bit8u flag
;
1873 {// flag = WITH_ATTR / NO_ATTR
1875 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1876 Bit16u nbcols
,nbrows
,address
;
1877 Bit16u cursor
,dummy
;
1879 // special case if page is 0xff, use current page
1881 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1884 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1885 line
=find_vga_entry(mode
);
1886 if(line
==0xFF)return;
1888 // Get the cursor pos for the page
1889 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1890 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1892 // Get the dimensions
1893 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1894 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1918 biosfn_write_teletype(' ',page
,attr
,flag
);
1919 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1920 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1926 if(vga_modes
[line
].class==TEXT
)
1928 // Compute the address
1929 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1932 write_byte(vga_modes
[line
].sstart
,address
,car
);
1935 write_byte(vga_modes
[line
].sstart
,address
+1,attr
);
1939 // FIXME gfx mode not complete
1940 cheight
=vga_modes
[line
].cheight
;
1941 bpp
=vga_modes
[line
].pixbits
;
1942 switch(vga_modes
[line
].memmodel
)
1946 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1949 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1952 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1963 // Do we need to wrap ?
1969 // Do we need to scroll ?
1972 if(vga_modes
[line
].class==TEXT
)
1974 biosfn_scroll(0x01,0x07,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
1978 biosfn_scroll(0x01,0x00,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
1983 // Set the cursor for the page
1984 cursor
=ycurs
; cursor
<<=8; cursor
+=xcurs
;
1985 biosfn_set_cursor_pos(page
,cursor
);
1988 // --------------------------------------------------------------------------------------------
1990 biosfn_get_video_mode
:
1992 mov ax
, # BIOSMEM_SEG
1995 mov bx
, # BIOSMEM_CURRENT_PAGE
2000 mov bx
, # BIOSMEM_VIDEO_CTL
2003 mov bx
, # BIOSMEM_CURRENT_MODE
2006 mov bx
, # BIOSMEM_NB_COLS
2013 // --------------------------------------------------------------------------------------------
2018 jmp biosfn_set_single_palette_reg
2022 jmp biosfn_set_overscan_border_color
2026 jmp biosfn_set_all_palette_reg
2030 jmp biosfn_toggle_intensity
2034 jmp biosfn_get_single_palette_reg
2038 jmp biosfn_read_overscan_border_color
2042 jmp biosfn_get_all_palette_reg
2046 jmp biosfn_set_single_dac_reg
2050 jmp biosfn_set_all_dac_reg
2054 jmp biosfn_select_video_dac_color_page
2058 jmp biosfn_read_single_dac_reg
2062 jmp biosfn_read_all_dac_reg
2066 jmp biosfn_set_pel_mask
2070 jmp biosfn_read_pel_mask
2073 jne int10_group_10_unknown
2074 jmp biosfn_read_video_dac_state
2075 int10_group_10_unknown
:
2081 biosfn_set_single_palette_reg
:
2086 mov dx
, # VGAREG_ACTL_RESET
2088 mov dx
, # VGAREG_ACTL_ADDRESS
2101 // --------------------------------------------------------------------------------------------
2103 biosfn_set_overscan_border_color
:
2106 call biosfn_set_single_palette_reg
2111 // --------------------------------------------------------------------------------------------
2113 biosfn_set_all_palette_reg
:
2119 mov dx
, # VGAREG_ACTL_RESET
2122 mov dx
, # VGAREG_ACTL_ADDRESS
2132 jne set_palette_loop
2147 // --------------------------------------------------------------------------------------------
2149 biosfn_toggle_intensity
:
2153 mov dx
, # VGAREG_ACTL_RESET
2155 mov dx
, # VGAREG_ACTL_ADDRESS
2158 mov dx
, # VGAREG_ACTL_READ_DATA
2164 mov dx
, # VGAREG_ACTL_ADDRESS
2174 // --------------------------------------------------------------------------------------------
2176 biosfn_get_single_palette_reg
:
2181 mov dx
, # VGAREG_ACTL_RESET
2183 mov dx
, # VGAREG_ACTL_ADDRESS
2186 mov dx
, # VGAREG_ACTL_READ_DATA
2189 mov dx
, # VGAREG_ACTL_RESET
2191 mov dx
, # VGAREG_ACTL_ADDRESS
2200 // --------------------------------------------------------------------------------------------
2202 biosfn_read_overscan_border_color
:
2206 call biosfn_get_single_palette_reg
2214 // --------------------------------------------------------------------------------------------
2216 biosfn_get_all_palette_reg
:
2224 mov dx
, # VGAREG_ACTL_RESET
2226 mov dx
, # VGAREG_ACTL_ADDRESS
2229 mov dx
, # VGAREG_ACTL_READ_DATA
2236 jne get_palette_loop
2237 mov dx
, # VGAREG_ACTL_RESET
2239 mov dx
, # VGAREG_ACTL_ADDRESS
2242 mov dx
, # VGAREG_ACTL_READ_DATA
2246 mov dx
, # VGAREG_ACTL_RESET
2248 mov dx
, # VGAREG_ACTL_ADDRESS
2258 // --------------------------------------------------------------------------------------------
2260 biosfn_set_single_dac_reg
:
2263 mov dx
, # VGAREG_DAC_WRITE_ADDRESS
2266 mov dx
, # VGAREG_DAC_DATA
2280 // --------------------------------------------------------------------------------------------
2282 biosfn_set_all_dac_reg
:
2287 mov dx
, # VGAREG_DAC_WRITE_ADDRESS
2293 mov dx
, # VGAREG_DAC_DATA
2316 // --------------------------------------------------------------------------------------------
2318 biosfn_select_video_dac_color_page
:
2322 mov dx
, # VGAREG_ACTL_RESET
2324 mov dx
, # VGAREG_ACTL_ADDRESS
2327 mov dx
, # VGAREG_ACTL_READ_DATA
2334 mov dx
, # VGAREG_ACTL_ADDRESS
2339 mov dx
, # VGAREG_ACTL_RESET
2341 mov dx
, # VGAREG_ACTL_ADDRESS
2361 // --------------------------------------------------------------------------------------------
2363 biosfn_read_single_dac_reg
:
2366 mov dx
, # VGAREG_DAC_READ_ADDRESS
2371 mov dx
, # VGAREG_DAC_DATA
2384 // --------------------------------------------------------------------------------------------
2386 biosfn_read_all_dac_reg
:
2391 mov dx
, # VGAREG_DAC_READ_ADDRESS
2397 mov dx
, # VGAREG_DAC_DATA
2420 // --------------------------------------------------------------------------------------------
2422 biosfn_set_pel_mask
:
2425 mov dx
, # VGAREG_PEL_MASK
2433 // --------------------------------------------------------------------------------------------
2435 biosfn_read_pel_mask
:
2438 mov dx
, # VGAREG_PEL_MASK
2446 // --------------------------------------------------------------------------------------------
2448 biosfn_read_video_dac_state
:
2451 mov dx
, # VGAREG_ACTL_RESET
2453 mov dx
, # VGAREG_ACTL_ADDRESS
2456 mov dx
, # VGAREG_ACTL_READ_DATA
2460 mov dx
, # VGAREG_ACTL_RESET
2462 mov dx
, # VGAREG_ACTL_ADDRESS
2465 mov dx
, # VGAREG_ACTL_READ_DATA
2473 mov dx
, # VGAREG_ACTL_RESET
2475 mov dx
, # VGAREG_ACTL_ADDRESS
2483 // --------------------------------------------------------------------------------------------
2484 static void biosfn_perform_gray_scale_summing (start
,count
)
2485 Bit16u start
;Bit16u count
;
2490 inb(VGAREG_ACTL_RESET
);
2491 outb(VGAREG_ACTL_ADDRESS
,0x00);
2493 for( index
= 0; index
< count
; index
++ )
2495 // set read address and switch to read mode
2496 outb(VGAREG_DAC_READ_ADDRESS
,start
);
2497 // get 6-bit wide RGB data values
2498 r
=inb( VGAREG_DAC_DATA
);
2499 g
=inb( VGAREG_DAC_DATA
);
2500 b
=inb( VGAREG_DAC_DATA
);
2502 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
2503 i
= ( ( 77*r
+ 151*g
+ 28*b
) + 0x80 ) >> 8;
2507 // set write address and switch to write mode
2508 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
2509 // write new intensity value
2510 outb( VGAREG_DAC_DATA
, i
&0xff );
2511 outb( VGAREG_DAC_DATA
, i
&0xff );
2512 outb( VGAREG_DAC_DATA
, i
&0xff );
2515 inb(VGAREG_ACTL_RESET
);
2516 outb(VGAREG_ACTL_ADDRESS
,0x20);
2519 // --------------------------------------------------------------------------------------------
2520 static void get_font_access()
2523 mov dx
, # VGAREG_SEQU_ADDRESS
2532 mov dx
, # VGAREG_GRDC_ADDRESS
2542 static void release_font_access()
2545 mov dx
, # VGAREG_SEQU_ADDRESS
2554 mov dx
, # VGAREG_READ_MISC_OUTPUT
2561 mov dx
, # VGAREG_GRDC_ADDRESS
2577 static void set_scan_lines(lines
) Bit8u lines
;
2579 Bit16u crtc_addr
,cols
,page
,vde
;
2580 Bit8u crtc_r9
,ovl
,rows
;
2582 crtc_addr
= read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2583 outb(crtc_addr
, 0x09);
2584 crtc_r9
= inb(crtc_addr
+1);
2585 crtc_r9
= (crtc_r9
& 0xe0) | (lines
- 1);
2586 outb(crtc_addr
+1, crtc_r9
);
2589 biosfn_set_cursor_shape(0x06,0x07);
2593 biosfn_set_cursor_shape(lines
-4,lines
-3);
2595 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, lines
);
2596 outb(crtc_addr
, 0x12);
2597 vde
= inb(crtc_addr
+1);
2598 outb(crtc_addr
, 0x07);
2599 ovl
= inb(crtc_addr
+1);
2600 vde
+= (((ovl
& 0x02) << 7) + ((ovl
& 0x40) << 3) + 1);
2602 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, rows
-1);
2603 cols
= read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
2604 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, rows
* cols
* 2);
2607 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
;
2609 Bit16u blockaddr
,dest
,i
,src
;
2612 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2616 dest
= blockaddr
+ (DX
+ i
) * 32;
2617 memcpyb(0xA000, dest
, ES
, src
, BH
);
2619 release_font_access();
2626 static void biosfn_load_text_8_14_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2628 Bit16u blockaddr
,dest
,i
,src
;
2631 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2632 for(i
=0;i
<0x100;i
++)
2635 dest
= blockaddr
+ i
* 32;
2636 memcpyb(0xA000, dest
, 0xC000, vgafont14
+src
, 14);
2638 release_font_access();
2645 static void biosfn_load_text_8_8_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2647 Bit16u blockaddr
,dest
,i
,src
;
2650 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2651 for(i
=0;i
<0x100;i
++)
2654 dest
= blockaddr
+ i
* 32;
2655 memcpyb(0xA000, dest
, 0xC000, vgafont8
+src
, 8);
2657 release_font_access();
2664 // --------------------------------------------------------------------------------------------
2666 biosfn_set_text_block_specifier
:
2669 mov dx
, # VGAREG_SEQU_ADDRESS
2678 // --------------------------------------------------------------------------------------------
2679 static void biosfn_load_text_8_16_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2681 Bit16u blockaddr
,dest
,i
,src
;
2684 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2685 for(i
=0;i
<0x100;i
++)
2688 dest
= blockaddr
+ i
* 32;
2689 memcpyb(0xA000, dest
, 0xC000, vgafont16
+src
, 16);
2691 release_font_access();
2698 static void biosfn_load_gfx_8_8_chars (ES
,BP
) Bit16u ES
;Bit16u BP
;
2704 static void biosfn_load_gfx_user_chars (ES
,BP
,CX
,BL
,DL
) Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit8u BL
;Bit8u DL
;
2710 static void biosfn_load_gfx_8_14_chars (BL
) Bit8u BL
;
2716 static void biosfn_load_gfx_8_8_dd_chars (BL
) Bit8u BL
;
2722 static void biosfn_load_gfx_8_16_chars (BL
) Bit8u BL
;
2728 // --------------------------------------------------------------------------------------------
2729 static void biosfn_get_font_info (BH
,ES
,BP
,CX
,DX
)
2730 Bit8u BH
;Bit16u
*ES
;Bit16u
*BP
;Bit16u
*CX
;Bit16u
*DX
;
2731 {Bit16u ss
=get_SS();
2735 write_word(ss
,ES
,read_word(0x00,0x1f*4));
2736 write_word(ss
,BP
,read_word(0x00,(0x1f*4)+2));
2739 write_word(ss
,ES
,read_word(0x00,0x43*4));
2740 write_word(ss
,BP
,read_word(0x00,(0x43*4)+2));
2743 write_word(ss
,ES
,0xC000);
2744 write_word(ss
,BP
,vgafont14
);
2747 write_word(ss
,ES
,0xC000);
2748 write_word(ss
,BP
,vgafont8
);
2751 write_word(ss
,ES
,0xC000);
2752 write_word(ss
,BP
,vgafont8
+128*8);
2755 write_word(ss
,ES
,0xC000);
2756 write_word(ss
,BP
,vgafont14alt
);
2759 write_word(ss
,ES
,0xC000);
2760 write_word(ss
,BP
,vgafont16
);
2763 write_word(ss
,ES
,0xC000);
2764 write_word(ss
,BP
,vgafont16alt
);
2768 printf("Get font info BH(%02x) was discarded\n",BH
);
2772 // Set byte/char of on screen font
2773 write_word(ss
,CX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
));
2775 // Set Highest char row
2776 write_word(ss
,DX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
));
2779 // --------------------------------------------------------------------------------------------
2781 biosfn_get_ega_info
:
2784 mov ax
, # BIOSMEM_SEG
2787 mov bx
, # BIOSMEM_SWITCHES
2790 mov bx
, # BIOSMEM_CRTC_ADDRESS
2793 cmp ax
, # VGAREG_MDA_CRTC_ADDRESS
2802 // --------------------------------------------------------------------------------------------
2803 static void biosfn_alternate_prtsc()
2810 // --------------------------------------------------------------------------------------------
2812 biosfn_select_vert_res
:
2814 ; res
: 00 200 lines
, 01 350 lines
, 02 400 lines
2820 mov ax
, # BIOSMEM_SEG
2822 mov bx
, # BIOSMEM_MODESET_CTL
2824 mov bx
, # BIOSMEM_SWITCHES
2835 mov bx
, #msg_vert_res
2843 ; reset modeset ctl bit
7 and set bit
4
2844 ; set switches bit
3-0 to
0x09
2853 ; reset modeset ctl bit
7 and bit
4
2854 ; set switches bit
3-0 to
0x09
2862 ; set modeset ctl bit
7 and reset bit
4
2863 ; set switches bit
3-0 to
0x08
2870 mov bx
, # BIOSMEM_MODESET_CTL
2872 mov bx
, # BIOSMEM_SWITCHES
2883 .ascii
"Select vert res (%02x) was discarded"
2884 .byte
0x0d,0x0a,0x00
2888 biosfn_enable_default_palette_loading
:
2895 mov ax
, # BIOSMEM_SEG
2897 mov bx
, # BIOSMEM_MODESET_CTL
2909 biosfn_enable_video_addressing
:
2916 mov dx
, # VGAREG_READ_MISC_OUTPUT
2920 mov dx
, # VGAREG_WRITE_MISC_OUTPUT
2928 biosfn_enable_grayscale_summing
:
2936 mov ax
, # BIOSMEM_SEG
2938 mov bx
, # BIOSMEM_MODESET_CTL
2950 biosfn_enable_cursor_emulation
:
2957 mov ax
, # BIOSMEM_SEG
2959 mov bx
, # BIOSMEM_MODESET_CTL
2971 // --------------------------------------------------------------------------------------------
2972 static void biosfn_switch_video_interface (AL
,ES
,DX
) Bit8u AL
;Bit16u ES
;Bit16u DX
;
2978 static void biosfn_enable_video_refresh_control (AL
) Bit8u AL
;
2985 // --------------------------------------------------------------------------------------------
2986 static void biosfn_write_string (flag
,page
,attr
,count
,row
,col
,seg
,offset
)
2987 Bit8u flag
;Bit8u page
;Bit8u attr
;Bit16u count
;Bit8u row
;Bit8u col
;Bit16u seg
;Bit16u offset
;
2989 Bit16u newcurs
,oldcurs
,dummy
;
2992 // Read curs info for the page
2993 biosfn_get_cursor_pos(page
,&dummy
,&oldcurs
);
2995 // if row=0xff special case : use current cursor position
2997 {col
=oldcurs
&0x00ff;
2998 row
=(oldcurs
&0xff00)>>8;
3001 newcurs
=row
; newcurs
<<=8; newcurs
+=col
;
3002 biosfn_set_cursor_pos(page
,newcurs
);
3006 car
=read_byte(seg
,offset
++);
3008 attr
=read_byte(seg
,offset
++);
3010 biosfn_write_teletype(car
,page
,attr
,WITH_ATTR
);
3013 // Set back curs pos
3015 biosfn_set_cursor_pos(page
,oldcurs
);
3018 // --------------------------------------------------------------------------------------------
3022 je biosfn_read_display_code
3024 je biosfn_set_display_code
3029 biosfn_read_display_code
:
3032 mov ax
, # BIOSMEM_SEG
3034 mov bx
, # BIOSMEM_DCC_INDEX
3042 biosfn_set_display_code
:
3046 mov ax
, # BIOSMEM_SEG
3049 mov bx
, # BIOSMEM_DCC_INDEX
3055 mov bx
, #msg_alt_dcc
3068 .ascii
"Alternate Display code (%02x) was discarded"
3069 .byte
0x0d,0x0a,0x00
3073 // --------------------------------------------------------------------------------------------
3074 static void biosfn_read_state_info (BX
,ES
,DI
)
3075 Bit16u BX
;Bit16u ES
;Bit16u DI
;
3077 // Address of static functionality table
3078 write_word(ES
,DI
+0x00,&static_functionality
);
3079 write_word(ES
,DI
+0x02,0xC000);
3081 // Hard coded copy from BIOS area. Should it be cleaner ?
3082 memcpyb(ES
,DI
+0x04,BIOSMEM_SEG
,0x49,30);
3083 memcpyb(ES
,DI
+0x22,BIOSMEM_SEG
,0x84,3);
3085 write_byte(ES
,DI
+0x25,read_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
));
3086 write_byte(ES
,DI
+0x26,0);
3087 write_byte(ES
,DI
+0x27,16);
3088 write_byte(ES
,DI
+0x28,0);
3089 write_byte(ES
,DI
+0x29,8);
3090 write_byte(ES
,DI
+0x2a,2);
3091 write_byte(ES
,DI
+0x2b,0);
3092 write_byte(ES
,DI
+0x2c,0);
3093 write_byte(ES
,DI
+0x31,3);
3094 write_byte(ES
,DI
+0x32,0);
3096 memsetb(ES
,DI
+0x33,0,13);
3099 // --------------------------------------------------------------------------------------------
3100 static void biosfn_read_video_state_size (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
3106 static void biosfn_save_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
3112 static void biosfn_restore_video_state (CX
,ES
,BX
) Bit16u CX
;Bit16u ES
;Bit16u BX
;
3119 // ============================================================================================
3123 // ============================================================================================
3125 // --------------------------------------------------------------------------------------------
3126 static Bit8u
find_vga_entry(mode
)
3130 for(i
=0;i
<=MODE_MAX
;i
++)
3131 if(vga_modes
[i
].svgamode
==mode
)
3138 /* =========================================================== */
3142 /* =========================================================== */
3144 // --------------------------------------------------------------------------------------------
3145 static void memsetb(seg
,offset
,value
,count
)
3160 mov cx
, 10[bp
] ; count
3163 mov ax
, 4[bp
] ; segment
3165 mov ax
, 6[bp
] ; offset
3167 mov al
, 8[bp
] ; value
3182 // --------------------------------------------------------------------------------------------
3183 static void memsetw(seg
,offset
,value
,count
)
3198 mov cx
, 10[bp
] ; count
3201 mov ax
, 4[bp
] ; segment
3203 mov ax
, 6[bp
] ; offset
3205 mov ax
, 8[bp
] ; value
3220 // --------------------------------------------------------------------------------------------
3221 static void memcpyb(dseg
,doffset
,sseg
,soffset
,count
)
3239 mov cx
, 12[bp
] ; count
3242 mov ax
, 4[bp
] ; dsegment
3244 mov ax
, 6[bp
] ; doffset
3246 mov ax
, 8[bp
] ; ssegment
3248 mov ax
, 10[bp
] ; soffset
3266 // --------------------------------------------------------------------------------------------
3267 static void memcpyw(dseg
,doffset
,sseg
,soffset
,count
)
3285 mov cx
, 12[bp
] ; count
3288 mov ax
, 4[bp
] ; dsegment
3290 mov ax
, 6[bp
] ; doffset
3292 mov ax
, 8[bp
] ; ssegment
3294 mov ax
, 10[bp
] ; soffset
3312 /* =========================================================== */
3314 * These functions where ripped from Kevin's rombios.c
3316 /* =========================================================== */
3318 // --------------------------------------------------------------------------------------------
3320 read_byte(seg
, offset
)
3330 mov ax
, 4[bp
] ; segment
3332 mov bx
, 6[bp
] ; offset
3334 ;; al
= return value (byte
)
3342 // --------------------------------------------------------------------------------------------
3344 read_word(seg
, offset
)
3354 mov ax
, 4[bp
] ; segment
3356 mov bx
, 6[bp
] ; offset
3358 ;; ax
= return value (word
)
3366 // --------------------------------------------------------------------------------------------
3368 write_byte(seg
, offset
, data
)
3380 mov ax
, 4[bp
] ; segment
3382 mov bx
, 6[bp
] ; offset
3383 mov al
, 8[bp
] ; data byte
3384 mov
[bx
], al
; write data byte
3393 // --------------------------------------------------------------------------------------------
3395 write_word(seg
, offset
, data
)
3407 mov ax
, 4[bp
] ; segment
3409 mov bx
, 6[bp
] ; offset
3410 mov ax
, 8[bp
] ; data word
3411 mov
[bx
], ax
; write data word
3420 // --------------------------------------------------------------------------------------------
3455 // --------------------------------------------------------------------------------------------
3477 // --------------------------------------------------------------------------------------------
3507 void unimplemented()
3509 printf("--> Unimplemented\n");
3514 printf("--> Unknown int10\n");
3518 // --------------------------------------------------------------------------------------------
3522 Bit8u c
, format_char
;
3524 unsigned format_width
, i
;
3526 Bit16u arg_seg
, arg
, digit
, nibble
, shift_count
;
3534 while (c
= read_byte(0xc000, s
)) {
3539 else if (in_format
) {
3540 if ( (c
>='0') && (c
<='9') ) {
3541 format_width
= (format_width
* 10) + (c
- '0');
3543 else if (c
== 'x') {
3544 arg_ptr
++; // increment to next arg
3545 arg
= read_word(arg_seg
, arg_ptr
);
3546 if (format_width
== 0)
3549 digit
= format_width
- 1;
3550 for (i
=0; i
<format_width
; i
++) {
3551 nibble
= (arg
>> (4 * digit
)) & 0x000f;
3553 outb(0x0500, nibble
+ '0');
3555 outb(0x0500, (nibble
- 10) + 'A');
3560 //else if (c == 'd') {
3579 // --------------------------------------------------------------------------------------------
3582 ;; DATA_SEG_DEFS_HERE
3586 .ascii
"vgabios ends here"
3590 ;; BLOCK_STRINGS_BEGIN