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 // ============================================================================================
60 static Bit8u
read_byte();
61 static Bit16u
read_word();
62 static void write_byte();
63 static void write_word();
69 static Bit16u
get_SS();
73 static void unimplemented();
74 static void unknown();
76 static Bit8u
find_vga_entry();
78 static void memsetb();
79 static void memsetw();
80 static void memcpyb();
81 static void memcpyw();
83 static void biosfn_set_video_mode();
84 static void biosfn_set_cursor_shape();
85 static void biosfn_set_cursor_pos();
86 static void biosfn_get_cursor_pos();
87 static void biosfn_set_active_page();
88 static void biosfn_scroll();
89 static void biosfn_read_char_attr();
90 static void biosfn_write_char_attr();
91 static void biosfn_write_char_only();
92 static void biosfn_write_pixel();
93 static void biosfn_read_pixel();
94 static void biosfn_write_teletype();
95 static void biosfn_perform_gray_scale_summing();
96 static void biosfn_load_text_user_pat();
97 static void biosfn_load_text_8_14_pat();
98 static void biosfn_load_text_8_8_pat();
99 static void biosfn_load_text_8_16_pat();
100 static void biosfn_load_gfx_8_8_chars();
101 static void biosfn_load_gfx_user_chars();
102 static void biosfn_load_gfx_8_14_chars();
103 static void biosfn_load_gfx_8_8_dd_chars();
104 static void biosfn_load_gfx_8_16_chars();
105 static void biosfn_get_font_info();
106 static void biosfn_alternate_prtsc();
107 static void biosfn_switch_video_interface();
108 static void biosfn_enable_video_refresh_control();
109 static void biosfn_write_string();
110 static void biosfn_read_state_info();
111 static void biosfn_read_video_state_size();
112 static Bit16u
biosfn_save_video_state();
113 static Bit16u
biosfn_restore_video_state();
114 extern Bit8u video_save_pointer_table
[];
116 // This is for compiling with gcc2 and gcc3
117 #define ASM_START #asm
118 #define ASM_END #endasm
143 .byte
0x55, 0xaa /* BIOS signature, required for BIOS extensions */
145 .byte
0x40 /* BIOS extension length in units of 512 bytes */
150 jmp vgabios_init_func
153 .ascii
"Plex86/Bochs VGABios"
157 // Info from Bart Oldeman
176 .ascii
"(C) 2003 the LGPL VGABios developers Team"
181 .ascii
"This VGA/VBE Bios is released under the GNU LGPL"
187 .ascii
"Please visit :"
189 ;;.ascii
" . http://www.plex86.org"
191 .ascii
" . http://bochs.sourceforge.net"
193 .ascii
" . http://www.nongnu.org/vgabios"
199 ;; ============================================================================================
203 ;; ============================================================================================
209 ;; init basic bios vars
213 ;; init vbe functions
218 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
224 ;; display splash screen
225 call _display_splash_screen
227 ;; init video mode
and clear the screen
236 call vbe_display_info
241 call cirrus_display_info
251 vgabios_int10_handler
:
266 call biosfn_get_video_mode
281 call biosfn_set_text_block_specifier
288 call biosfn_get_ega_info
293 call biosfn_select_vert_res
298 call biosfn_enable_default_palette_loading
303 call biosfn_enable_video_addressing
308 call biosfn_enable_grayscale_summing
313 call biosfn_enable_cursor_emulation
331 jne int10_test_vbe_05
332 call vbe_biosfn_return_current_mode
336 jne int10_test_vbe_06
337 call vbe_biosfn_display_window_control
341 jne int10_test_vbe_07
342 call vbe_biosfn_set_get_logical_scan_line_length
346 jne int10_test_vbe_08
347 call vbe_biosfn_set_get_display_start
351 jne int10_test_vbe_0A
352 call vbe_biosfn_set_get_dac_palette_format
357 call vbe_biosfn_return_protected_mode_interface
366 ;; We have to set ds to access the right data segment
379 #include "vgatables.h"
380 #include "vgafonts.h"
383 * Boot time harware inits
387 ;; switch to color mode
and enable CPU access
480 lines
392 ;; more than
64k
3C4
/04
400 #if defined(USE_BX_INFO) || defined(DEBUG)
401 mov bx
, #msg_vga_init
409 #if defined(USE_BX_INFO) || defined(DEBUG)
411 .ascii
"VGABios $Id$"
416 // --------------------------------------------------------------------------------------------
418 * Boot time bios area inits
423 mov ax
, # BIOSMEM_SEG
426 ;; init detected hardware BIOS Area
427 mov bx
, # BIOSMEM_INITIAL_MODE
430 ;; set
80x25
color (not clear from RBIL but usual
)
434 ;; Just
for the first int10 find its children
436 ;; the
default char height
437 mov bx
, # BIOSMEM_CHAR_HEIGHT
442 mov bx
, # BIOSMEM_VIDEO_CTL
446 ;; Set the basic screen we have
447 mov bx
, # BIOSMEM_SWITCHES
451 ;; Set the basic modeset options
452 mov bx
, # BIOSMEM_MODESET_CTL
456 ;; Set the
default MSR
457 mov bx
, # BIOSMEM_CURRENT_MSR
464 _video_save_pointer_table
:
465 .word _video_param_table
468 .word
0 /* XXX: fill it */
471 .word
0 /* XXX: fill it */
474 .word
0 /* XXX: fill it */
477 .word
0 /* XXX: fill it */
480 .word
0 /* XXX: fill it */
483 .word
0 /* XXX: fill it */
488 // --------------------------------------------------------------------------------------------
490 * Boot time Splash screen
492 static void display_splash_screen()
496 // --------------------------------------------------------------------------------------------
501 static void display_info()
508 mov si
,#vgabios_version
511 ;;mov si
,#vgabios_copyright
512 ;;call _display_string
514 ;;call _display_string
516 mov si
,#vgabios_license
518 mov si
,#vgabios_website
523 static void display_string()
525 // Get length of string
552 // --------------------------------------------------------------------------------------------
554 static void int10_debugmsg(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
555 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
557 // 0E is write char...
559 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX
,CX
,DX
);
563 // --------------------------------------------------------------------------------------------
565 * int10 main dispatcher
567 static void int10_func(DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, DS
, ES
, FLAGS
)
568 Bit16u DI
, SI
, BP
, SP
, BX
, DX
, CX
, AX
, ES
, DS
, FLAGS
;
575 biosfn_set_video_mode(GET_AL());
576 switch(GET_AL()&0x7F)
594 biosfn_set_cursor_shape(GET_CH(),GET_CL());
597 biosfn_set_cursor_pos(GET_BH(),DX
);
600 biosfn_get_cursor_pos(GET_BH(),&CX
,&DX
);
603 // Read light pen pos (unimplemented)
613 biosfn_set_active_page(GET_AL());
616 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP
);
619 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN
);
622 biosfn_read_char_attr(GET_BH(),&AX
);
625 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX
);
628 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX
);
631 biosfn_write_pixel(GET_BH(),GET_AL(),CX
,DX
);
634 biosfn_read_pixel(GET_BH(),CX
,DX
,&AX
);
637 // Ralf Brown Interrupt list is WRONG on bh(page)
638 // We do output only on the current page !
639 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR
);
642 // All other functions of group AH=0x10 rewritten in assembler
643 biosfn_perform_gray_scale_summing(BX
,CX
);
650 biosfn_load_text_user_pat(GET_AL(),ES
,BP
,CX
,DX
,GET_BL(),GET_BH());
654 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
658 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
662 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
665 biosfn_load_gfx_8_8_chars(ES
,BP
);
668 biosfn_load_gfx_user_chars(ES
,BP
,CX
,GET_BL(),GET_DL());
671 biosfn_load_gfx_8_14_chars(GET_BL());
674 biosfn_load_gfx_8_8_dd_chars(GET_BL());
677 biosfn_load_gfx_8_16_chars(GET_BL());
680 biosfn_get_font_info(GET_BH(),&ES
,&BP
,&CX
,&DX
);
693 biosfn_alternate_prtsc();
696 biosfn_switch_video_interface(GET_AL(),ES
,DX
);
700 biosfn_enable_video_refresh_control(GET_AL());
710 biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX
,GET_DH(),GET_DL(),ES
,BP
);
713 biosfn_read_state_info(BX
,ES
,DI
);
720 biosfn_read_video_state_size(CX
,&BX
);
723 biosfn_save_video_state(CX
,ES
,BX
);
726 biosfn_restore_video_state(CX
,ES
,BX
);
738 if (vbe_has_vbe_display()) {
742 vbe_biosfn_return_controller_information(&AX
,ES
,DI
);
745 vbe_biosfn_return_mode_information(&AX
,CX
,ES
,DI
);
748 vbe_biosfn_set_mode(&AX
,BX
,ES
,DI
);
751 vbe_biosfn_save_restore_state(&AX
, CX
, DX
, ES
, &BX
);
791 // ============================================================================================
795 // ============================================================================================
797 static void biosfn_set_video_mode(mode
) Bit8u mode
;
798 {// mode: Bit 7 is 1 if no clear screen
800 // Should we clear the screen ?
801 Bit8u noclearmem
=mode
&0x80;
802 Bit8u line
,mmask
,*palette
,vpti
;
803 Bit16u i
,twidth
,theightm1
,cheight
;
804 Bit8u modeset_ctl
,video_ctl
,vga_switches
;
808 if (vbe_has_vbe_display()) {
809 dispi_set_enable(VBE_DISPI_DISABLED
);
816 // find the entry in the video modes
817 line
=find_vga_entry(mode
);
820 printf("mode search %02x found line %02x\n",mode
,line
);
826 vpti
=line_to_vpti
[line
];
827 twidth
=video_param_table
[vpti
].twidth
;
828 theightm1
=video_param_table
[vpti
].theightm1
;
829 cheight
=video_param_table
[vpti
].cheight
;
831 // Read the bios vga control
832 video_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
);
834 // Read the bios vga switches
835 vga_switches
=read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
);
837 // Read the bios mode set control
838 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
840 // Then we know the number of lines
843 // if palette loading (bit 3 of modeset ctl = 0)
844 if((modeset_ctl
&0x08)==0)
846 outb(VGAREG_PEL_MASK
,vga_modes
[line
].pelmask
);
848 // Set the whole dac always, from 0
849 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
851 // From which palette
852 switch(vga_modes
[line
].dacmodel
)
866 // Always 256*3 values
867 for(i
=0;i
<0x0100;i
++)
868 {if(i
<=dac_regs
[vga_modes
[line
].dacmodel
])
869 {outb(VGAREG_DAC_DATA
,palette
[(i
*3)+0]);
870 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+1]);
871 outb(VGAREG_DAC_DATA
,palette
[(i
*3)+2]);
874 {outb(VGAREG_DAC_DATA
,0);
875 outb(VGAREG_DAC_DATA
,0);
876 outb(VGAREG_DAC_DATA
,0);
879 if((modeset_ctl
&0x02)==0x02)
881 biosfn_perform_gray_scale_summing(0x00, 0x100);
885 // Reset Attribute Ctl flip-flop
886 inb(VGAREG_ACTL_RESET
);
890 {outb(VGAREG_ACTL_ADDRESS
,i
);
891 outb(VGAREG_ACTL_WRITE_DATA
,video_param_table
[vpti
].actl_regs
[i
]);
893 outb(VGAREG_ACTL_ADDRESS
,0x14);
894 outb(VGAREG_ACTL_WRITE_DATA
,0x00);
897 outb(VGAREG_SEQU_ADDRESS
,0);
898 outb(VGAREG_SEQU_DATA
,0x03);
900 {outb(VGAREG_SEQU_ADDRESS
,i
);
901 outb(VGAREG_SEQU_DATA
,video_param_table
[vpti
].sequ_regs
[i
- 1]);
906 {outb(VGAREG_GRDC_ADDRESS
,i
);
907 outb(VGAREG_GRDC_DATA
,video_param_table
[vpti
].grdc_regs
[i
]);
910 // Set CRTC address VGA or MDA
911 crtc_addr
=vga_modes
[line
].memmodel
==MTEXT
?VGAREG_MDA_CRTC_ADDRESS
:VGAREG_VGA_CRTC_ADDRESS
;
913 // Disable CRTC write protection
914 outw(crtc_addr
,0x0011);
918 outb(crtc_addr
+1,video_param_table
[vpti
].crtc_regs
[i
]);
921 // Set the misc register
922 outb(VGAREG_WRITE_MISC_OUTPUT
,video_param_table
[vpti
].miscreg
);
925 outb(VGAREG_ACTL_ADDRESS
,0x20);
926 inb(VGAREG_ACTL_RESET
);
930 if(vga_modes
[line
].class==TEXT
)
932 memsetw(vga_modes
[line
].sstart
,0,0x0720,0x4000); // 32k
938 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x4000); // 32k
942 outb( VGAREG_SEQU_ADDRESS
, 0x02 );
943 mmask
= inb( VGAREG_SEQU_DATA
);
944 outb( VGAREG_SEQU_DATA
, 0x0f ); // all planes
945 memsetw(vga_modes
[line
].sstart
,0,0x0000,0x8000); // 64k
946 outb( VGAREG_SEQU_DATA
, mmask
);
952 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
,mode
);
953 write_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
,twidth
);
954 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
,*(Bit16u
*)&video_param_table
[vpti
].slength_l
);
955 write_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
,crtc_addr
);
956 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
,theightm1
);
957 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
,cheight
);
958 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60|noclearmem
));
959 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
,0xF9);
960 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
,read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
)&0x7f);
962 // FIXME We nearly have the good tables. to be reworked
963 write_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
,0x08); // 8 is VGA should be ok for now
964 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
, video_save_pointer_table
);
965 write_word(BIOSMEM_SEG
,BIOSMEM_VS_POINTER
+2, 0xc000);
968 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MSR
,0x00); // Unavailable on vanilla vga, but...
969 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAL
,0x00); // Unavailable on vanilla vga, but...
972 if(vga_modes
[line
].class==TEXT
)
974 biosfn_set_cursor_shape(0x06,0x07);
977 // Set cursor pos for page 0..7
979 biosfn_set_cursor_pos(i
,0x0000);
982 biosfn_set_active_page(0x00);
984 // Write the fonts in memory
985 if(vga_modes
[line
].class==TEXT
)
988 ;; copy
and activate
8x16 font
998 // Set the ints 0x1F and 0x43
1000 SET_INT_VECTOR(0x1f, #0xC000, #_vgafont8+128*8)
1006 SET_INT_VECTOR(0x43, #0xC000, #_vgafont8)
1011 SET_INT_VECTOR(0x43, #0xC000, #_vgafont14)
1016 SET_INT_VECTOR(0x43, #0xC000, #_vgafont16)
1022 // --------------------------------------------------------------------------------------------
1023 static void biosfn_set_cursor_shape (CH
,CL
)
1025 {Bit16u cheight
,curs
,crtc_addr
;
1032 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
,curs
);
1034 modeset_ctl
=read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
);
1035 cheight
= read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
);
1036 if((modeset_ctl
&0x01) && (cheight
>8) && (CL
<8) && (CH
<0x20))
1040 CH
= ((CH
+1) * cheight
/ 8) -1;
1044 CH
= ((CL
+1) * cheight
/ 8) - 2;
1046 CL
= ((CL
+1) * cheight
/ 8) - 1;
1049 // CTRC regs 0x0a and 0x0b
1050 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1051 outb(crtc_addr
,0x0a);
1052 outb(crtc_addr
+1,CH
);
1053 outb(crtc_addr
,0x0b);
1054 outb(crtc_addr
+1,CL
);
1057 // --------------------------------------------------------------------------------------------
1058 static void biosfn_set_cursor_pos (page
, cursor
)
1059 Bit8u page
;Bit16u cursor
;
1061 Bit8u xcurs
,ycurs
,current
;
1062 Bit16u nbcols
,nbrows
,address
,crtc_addr
;
1064 // Should not happen...
1068 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*page
, cursor
);
1070 // Set the hardware cursor
1071 current
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1074 // Get the dimensions
1075 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1076 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1078 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1080 // Calculate the address knowing nbcols nbrows and page num
1081 address
=SCREEN_IO_START(nbcols
,nbrows
,page
)+xcurs
+ycurs
*nbcols
;
1083 // CRTC regs 0x0e and 0x0f
1084 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1085 outb(crtc_addr
,0x0e);
1086 outb(crtc_addr
+1,(address
&0xff00)>>8);
1087 outb(crtc_addr
,0x0f);
1088 outb(crtc_addr
+1,address
&0x00ff);
1092 // --------------------------------------------------------------------------------------------
1093 static void biosfn_get_cursor_pos (page
,shape
, pos
)
1094 Bit8u page
;Bit16u
*shape
;Bit16u
*pos
;
1099 write_word(ss
, shape
, 0);
1100 write_word(ss
, pos
, 0);
1103 // FIXME should handle VGA 14/16 lines
1104 write_word(ss
,shape
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
));
1105 write_word(ss
,pos
,read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_POS
+page
*2));
1108 // --------------------------------------------------------------------------------------------
1109 static void biosfn_set_active_page (page
)
1112 Bit16u cursor
,dummy
,crtc_addr
;
1113 Bit16u nbcols
,nbrows
,address
;
1119 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1120 line
=find_vga_entry(mode
);
1121 if(line
==0xFF)return;
1123 // Get pos curs pos for the right page
1124 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1126 if(vga_modes
[line
].class==TEXT
)
1128 // Get the dimensions
1129 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1130 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1132 // Calculate the address knowing nbcols nbrows and page num
1133 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1134 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
,address
);
1137 address
=SCREEN_IO_START(nbcols
,nbrows
,page
);
1141 address
= page
* (*(Bit16u
*)&video_param_table
[line_to_vpti
[line
]].slength_l
);
1144 // CRTC regs 0x0c and 0x0d
1145 crtc_addr
=read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
1146 outb(crtc_addr
,0x0c);
1147 outb(crtc_addr
+1,(address
&0xff00)>>8);
1148 outb(crtc_addr
,0x0d);
1149 outb(crtc_addr
+1,address
&0x00ff);
1151 // And change the BIOS page
1152 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
,page
);
1155 printf("Set active page %02x address %04x\n",page
,address
);
1158 // Display the cursor, now the page is active
1159 biosfn_set_cursor_pos(page
,cursor
);
1162 // --------------------------------------------------------------------------------------------
1163 static void vgamem_copy_pl4(xstart
,ysrc
,ydest
,cols
,nbcols
,cheight
)
1164 Bit8u xstart
;Bit8u ysrc
;Bit8u ydest
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;
1169 src
=ysrc
*cheight
*nbcols
+xstart
;
1170 dest
=ydest
*cheight
*nbcols
+xstart
;
1171 outw(VGAREG_GRDC_ADDRESS
, 0x0105);
1172 for(i
=0;i
<cheight
;i
++)
1174 memcpyb(0xa000,dest
+i
*nbcols
,0xa000,src
+i
*nbcols
,cols
);
1176 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1179 // --------------------------------------------------------------------------------------------
1180 static void vgamem_fill_pl4(xstart
,ystart
,cols
,nbcols
,cheight
,attr
)
1181 Bit8u xstart
;Bit8u ystart
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;Bit8u attr
;
1186 dest
=ystart
*cheight
*nbcols
+xstart
;
1187 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1188 for(i
=0;i
<cheight
;i
++)
1190 memsetb(0xa000,dest
+i
*nbcols
,attr
,cols
);
1192 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1195 // --------------------------------------------------------------------------------------------
1196 static void vgamem_copy_cga(xstart
,ysrc
,ydest
,cols
,nbcols
,cheight
)
1197 Bit8u xstart
;Bit8u ysrc
;Bit8u ydest
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;
1202 src
=((ysrc
*cheight
*nbcols
)>>1)+xstart
;
1203 dest
=((ydest
*cheight
*nbcols
)>>1)+xstart
;
1204 for(i
=0;i
<cheight
;i
++)
1207 memcpyb(0xb800,0x2000+dest
+(i
>>1)*nbcols
,0xb800,0x2000+src
+(i
>>1)*nbcols
,cols
);
1209 memcpyb(0xb800,dest
+(i
>>1)*nbcols
,0xb800,src
+(i
>>1)*nbcols
,cols
);
1213 // --------------------------------------------------------------------------------------------
1214 static void vgamem_fill_cga(xstart
,ystart
,cols
,nbcols
,cheight
,attr
)
1215 Bit8u xstart
;Bit8u ystart
;Bit8u cols
;Bit8u nbcols
;Bit8u cheight
;Bit8u attr
;
1220 dest
=((ystart
*cheight
*nbcols
)>>1)+xstart
;
1221 for(i
=0;i
<cheight
;i
++)
1224 memsetb(0xb800,0x2000+dest
+(i
>>1)*nbcols
,attr
,cols
);
1226 memsetb(0xb800,dest
+(i
>>1)*nbcols
,attr
,cols
);
1230 // --------------------------------------------------------------------------------------------
1231 static void biosfn_scroll (nblines
,attr
,rul
,cul
,rlr
,clr
,page
,dir
)
1232 Bit8u nblines
;Bit8u attr
;Bit8u rul
;Bit8u cul
;Bit8u rlr
;Bit8u clr
;Bit8u page
;Bit8u dir
;
1234 // page == 0xFF if current
1236 Bit8u mode
,line
,cheight
,bpp
,cols
;
1237 Bit16u nbcols
,nbrows
,i
;
1244 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1245 line
=find_vga_entry(mode
);
1246 if(line
==0xFF)return;
1248 // Get the dimensions
1249 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1250 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1252 // Get the current page
1254 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1256 if(rlr
>=nbrows
)rlr
=nbrows
-1;
1257 if(clr
>=nbcols
)clr
=nbcols
-1;
1258 if(nblines
>nbrows
)nblines
=0;
1261 if(vga_modes
[line
].class==TEXT
)
1263 // Compute the address
1264 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
);
1266 printf("Scroll, address %04x (%04x %04x %02x)\n",address
,nbrows
,nbcols
,page
);
1269 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1271 memsetw(vga_modes
[line
].sstart
,address
,(Bit16u
)attr
*0x100+' ',nbrows
*nbcols
);
1276 {for(i
=rul
;i
<=rlr
;i
++)
1278 if((i
+nblines
>rlr
)||(nblines
==0))
1279 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',cols
);
1281 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
+nblines
)*nbcols
+cul
)*2,cols
);
1285 {for(i
=rlr
;i
>=rul
;i
--)
1287 if((i
<rul
+nblines
)||(nblines
==0))
1288 memsetw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,(Bit16u
)attr
*0x100+' ',cols
);
1290 memcpyw(vga_modes
[line
].sstart
,address
+(i
*nbcols
+cul
)*2,vga_modes
[line
].sstart
,((i
-nblines
)*nbcols
+cul
)*2,cols
);
1297 // FIXME gfx mode not complete
1298 cheight
=video_param_table
[line_to_vpti
[line
]].cheight
;
1299 switch(vga_modes
[line
].memmodel
)
1303 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1305 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1306 memsetb(vga_modes
[line
].sstart
,0,attr
,nbrows
*nbcols
*cheight
);
1307 outw(VGAREG_GRDC_ADDRESS
, 0x0005);
1312 {for(i
=rul
;i
<=rlr
;i
++)
1314 if((i
+nblines
>rlr
)||(nblines
==0))
1315 vgamem_fill_pl4(cul
,i
,cols
,nbcols
,cheight
,attr
);
1317 vgamem_copy_pl4(cul
,i
+nblines
,i
,cols
,nbcols
,cheight
);
1321 {for(i
=rlr
;i
>=rul
;i
--)
1323 if((i
<rul
+nblines
)||(nblines
==0))
1324 vgamem_fill_pl4(cul
,i
,cols
,nbcols
,cheight
,attr
);
1326 vgamem_copy_pl4(cul
,i
,i
-nblines
,cols
,nbcols
,cheight
);
1332 bpp
=vga_modes
[line
].pixbits
;
1333 if(nblines
==0&&rul
==0&&cul
==0&&rlr
==nbrows
-1&&clr
==nbcols
-1)
1335 memsetb(vga_modes
[line
].sstart
,0,attr
,nbrows
*nbcols
*cheight
*bpp
);
1347 {for(i
=rul
;i
<=rlr
;i
++)
1349 if((i
+nblines
>rlr
)||(nblines
==0))
1350 vgamem_fill_cga(cul
,i
,cols
,nbcols
,cheight
,attr
);
1352 vgamem_copy_cga(cul
,i
+nblines
,i
,cols
,nbcols
,cheight
);
1356 {for(i
=rlr
;i
>=rul
;i
--)
1358 if((i
<rul
+nblines
)||(nblines
==0))
1359 vgamem_fill_cga(cul
,i
,cols
,nbcols
,cheight
,attr
);
1361 vgamem_copy_cga(cul
,i
,i
-nblines
,cols
,nbcols
,cheight
);
1368 printf("Scroll in graphics mode ");
1375 // --------------------------------------------------------------------------------------------
1376 static void biosfn_read_char_attr (page
,car
)
1377 Bit8u page
;Bit16u
*car
;
1378 {Bit16u ss
=get_SS();
1379 Bit8u xcurs
,ycurs
,mode
,line
;
1380 Bit16u nbcols
,nbrows
,address
;
1381 Bit16u cursor
,dummy
;
1384 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1385 line
=find_vga_entry(mode
);
1386 if(line
==0xFF)return;
1388 // Get the cursor pos for the page
1389 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1390 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1392 // Get the dimensions
1393 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1394 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1396 if(vga_modes
[line
].class==TEXT
)
1398 // Compute the address
1399 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1401 write_word(ss
,car
,read_word(vga_modes
[line
].sstart
,address
));
1412 // --------------------------------------------------------------------------------------------
1413 static void write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
)
1414 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u cheight
;
1418 Bit16u addr
,dest
,src
;
1430 addr
=xcurs
+ycurs
*cheight
*nbcols
;
1431 src
= car
* cheight
;
1432 outw(VGAREG_SEQU_ADDRESS
, 0x0f02);
1433 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1436 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1440 outw(VGAREG_GRDC_ADDRESS
, 0x0003);
1442 for(i
=0;i
<cheight
;i
++)
1448 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1449 read_byte(0xa000,dest
);
1450 if(fdata
[src
+i
]&mask
)
1452 write_byte(0xa000,dest
,attr
&0x0f);
1456 write_byte(0xa000,dest
,0x00);
1461 mov dx
, # VGAREG_GRDC_ADDRESS
1471 // --------------------------------------------------------------------------------------------
1472 static void write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
)
1473 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;Bit8u bpp
;
1475 Bit8u i
,j
,mask
,data
;
1477 Bit16u addr
,dest
,src
;
1480 addr
=(xcurs
*bpp
)+ycurs
*320;
1484 dest
=addr
+(i
>>1)*80;
1485 if (i
& 1) dest
+= 0x2000;
1491 data
= read_byte(0xb800,dest
);
1499 if (fdata
[src
+i
] & mask
)
1503 data
^= (attr
& 0x01) << (7-j
);
1507 data
|= (attr
& 0x01) << (7-j
);
1512 write_byte(0xb800,dest
,data
);
1520 data
= read_byte(0xb800,dest
);
1528 if (fdata
[src
+i
] & mask
)
1532 data
^= (attr
& 0x03) << ((3-j
)*2);
1536 data
|= (attr
& 0x03) << ((3-j
)*2);
1541 write_byte(0xb800,dest
,data
);
1548 // --------------------------------------------------------------------------------------------
1549 static void write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
)
1550 Bit8u car
;Bit8u attr
;Bit8u xcurs
;Bit8u ycurs
;Bit8u nbcols
;
1552 Bit8u i
,j
,mask
,data
;
1554 Bit16u addr
,dest
,src
;
1557 addr
=xcurs
*8+ycurs
*nbcols
*64;
1561 dest
=addr
+i
*nbcols
*8;
1566 if (fdata
[src
+i
] & mask
)
1570 write_byte(0xa000,dest
+j
,data
);
1576 // --------------------------------------------------------------------------------------------
1577 static void biosfn_write_char_attr (car
,page
,attr
,count
)
1578 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1580 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1581 Bit16u nbcols
,nbrows
,address
;
1582 Bit16u cursor
,dummy
;
1585 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1586 line
=find_vga_entry(mode
);
1587 if(line
==0xFF)return;
1589 // Get the cursor pos for the page
1590 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1591 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1593 // Get the dimensions
1594 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1595 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1597 if(vga_modes
[line
].class==TEXT
)
1599 // Compute the address
1600 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1602 dummy
=((Bit16u
)attr
<<8)+car
;
1603 memsetw(vga_modes
[line
].sstart
,address
,dummy
,count
);
1607 // FIXME gfx mode not complete
1608 cheight
=video_param_table
[line_to_vpti
[line
]].cheight
;
1609 bpp
=vga_modes
[line
].pixbits
;
1610 while((count
-->0) && (xcurs
<nbcols
))
1612 switch(vga_modes
[line
].memmodel
)
1616 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1619 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1622 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1634 // --------------------------------------------------------------------------------------------
1635 static void biosfn_write_char_only (car
,page
,attr
,count
)
1636 Bit8u car
;Bit8u page
;Bit8u attr
;Bit16u count
;
1638 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1639 Bit16u nbcols
,nbrows
,address
;
1640 Bit16u cursor
,dummy
;
1643 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1644 line
=find_vga_entry(mode
);
1645 if(line
==0xFF)return;
1647 // Get the cursor pos for the page
1648 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1649 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1651 // Get the dimensions
1652 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1653 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1655 if(vga_modes
[line
].class==TEXT
)
1657 // Compute the address
1658 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1661 {write_byte(vga_modes
[line
].sstart
,address
,car
);
1667 // FIXME gfx mode not complete
1668 cheight
=video_param_table
[line_to_vpti
[line
]].cheight
;
1669 bpp
=vga_modes
[line
].pixbits
;
1670 while((count
-->0) && (xcurs
<nbcols
))
1672 switch(vga_modes
[line
].memmodel
)
1676 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1679 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1682 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1694 // --------------------------------------------------------------------------------------------
1698 je biosfn_set_border_color
1700 je biosfn_set_palette
1705 biosfn_set_border_color
:
1710 mov dx
, # VGAREG_ACTL_RESET
1712 mov dx
, # VGAREG_ACTL_ADDRESS
1725 mov dx
, # VGAREG_ACTL_ADDRESS
1728 mov dx
, # VGAREG_ACTL_READ_DATA
1732 mov dx
, # VGAREG_ACTL_ADDRESS
1736 jne set_intensity_loop
1749 mov dx
, # VGAREG_ACTL_RESET
1753 set_cga_palette_loop
:
1754 mov dx
, # VGAREG_ACTL_ADDRESS
1757 mov dx
, # VGAREG_ACTL_READ_DATA
1761 mov dx
, # VGAREG_ACTL_ADDRESS
1765 jne set_cga_palette_loop
1775 // --------------------------------------------------------------------------------------------
1776 static void biosfn_write_pixel (BH
,AL
,CX
,DX
) Bit8u BH
;Bit8u AL
;Bit16u CX
;Bit16u DX
;
1778 Bit8u mode
,line
,mask
,attr
,data
;
1782 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1783 line
=find_vga_entry(mode
);
1784 if(line
==0xFF)return;
1785 if(vga_modes
[line
].class==TEXT
)return;
1787 switch(vga_modes
[line
].memmodel
)
1791 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1792 mask
= 0x80 >> (CX
& 0x07);
1793 outw(VGAREG_GRDC_ADDRESS
, (mask
<< 8) | 0x08);
1794 outw(VGAREG_GRDC_ADDRESS
, 0x0205);
1795 data
= read_byte(0xa000,addr
);
1798 outw(VGAREG_GRDC_ADDRESS
, 0x1803);
1800 write_byte(0xa000,addr
,AL
);
1802 mov dx
, # VGAREG_GRDC_ADDRESS
1812 if(vga_modes
[line
].pixbits
==2)
1814 addr
=(CX
>>2)+(DX
>>1)*80;
1818 addr
=(CX
>>3)+(DX
>>1)*80;
1820 if (DX
& 1) addr
+= 0x2000;
1821 data
= read_byte(0xb800,addr
);
1822 if(vga_modes
[line
].pixbits
==2)
1824 attr
= (AL
& 0x03) << ((3 - (CX
& 0x03)) * 2);
1825 mask
= 0x03 << ((3 - (CX
& 0x03)) * 2);
1829 attr
= (AL
& 0x01) << (7 - (CX
& 0x07));
1830 mask
= 0x01 << (7 - (CX
& 0x07));
1841 write_byte(0xb800,addr
,data
);
1844 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1845 write_byte(0xa000,addr
,AL
);
1854 // --------------------------------------------------------------------------------------------
1855 static void biosfn_read_pixel (BH
,CX
,DX
,AX
) Bit8u BH
;Bit16u CX
;Bit16u DX
;Bit16u
*AX
;
1857 Bit8u mode
,line
,mask
,attr
,data
,i
;
1862 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1863 line
=find_vga_entry(mode
);
1864 if(line
==0xFF)return;
1865 if(vga_modes
[line
].class==TEXT
)return;
1867 switch(vga_modes
[line
].memmodel
)
1871 addr
= CX
/8+DX
*read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1872 mask
= 0x80 >> (CX
& 0x07);
1876 outw(VGAREG_GRDC_ADDRESS
, (i
<< 8) | 0x04);
1877 data
= read_byte(0xa000,addr
) & mask
;
1878 if (data
> 0) attr
|= (0x01 << i
);
1882 addr
=(CX
>>2)+(DX
>>1)*80;
1883 if (DX
& 1) addr
+= 0x2000;
1884 data
= read_byte(0xb800,addr
);
1885 if(vga_modes
[line
].pixbits
==2)
1887 attr
= (data
>> ((3 - (CX
& 0x03)) * 2)) & 0x03;
1891 attr
= (data
>> (7 - (CX
& 0x07))) & 0x01;
1895 addr
=CX
+DX
*(read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)*8);
1896 attr
=read_byte(0xa000,addr
);
1904 write_word(ss
,AX
,(read_word(ss
,AX
) & 0xff00) | attr
);
1907 // --------------------------------------------------------------------------------------------
1908 static void biosfn_write_teletype (car
, page
, attr
, flag
)
1909 Bit8u car
;Bit8u page
;Bit8u attr
;Bit8u flag
;
1910 {// flag = WITH_ATTR / NO_ATTR
1912 Bit8u cheight
,xcurs
,ycurs
,mode
,line
,bpp
;
1913 Bit16u nbcols
,nbrows
,address
;
1914 Bit16u cursor
,dummy
;
1916 // special case if page is 0xff, use current page
1918 page
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
);
1921 mode
=read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
);
1922 line
=find_vga_entry(mode
);
1923 if(line
==0xFF)return;
1925 // Get the cursor pos for the page
1926 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1927 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1929 // Get the dimensions
1930 nbrows
=read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)+1;
1931 nbcols
=read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
1954 biosfn_write_teletype(' ',page
,attr
,flag
);
1955 biosfn_get_cursor_pos(page
,&dummy
,&cursor
);
1956 xcurs
=cursor
&0x00ff;ycurs
=(cursor
&0xff00)>>8;
1962 if(vga_modes
[line
].class==TEXT
)
1964 // Compute the address
1965 address
=SCREEN_MEM_START(nbcols
,nbrows
,page
)+(xcurs
+ycurs
*nbcols
)*2;
1968 write_byte(vga_modes
[line
].sstart
,address
,car
);
1971 write_byte(vga_modes
[line
].sstart
,address
+1,attr
);
1975 // FIXME gfx mode not complete
1976 cheight
=video_param_table
[line_to_vpti
[line
]].cheight
;
1977 bpp
=vga_modes
[line
].pixbits
;
1978 switch(vga_modes
[line
].memmodel
)
1982 write_gfx_char_pl4(car
,attr
,xcurs
,ycurs
,nbcols
,cheight
);
1985 write_gfx_char_cga(car
,attr
,xcurs
,ycurs
,nbcols
,bpp
);
1988 write_gfx_char_lin(car
,attr
,xcurs
,ycurs
,nbcols
);
1999 // Do we need to wrap ?
2005 // Do we need to scroll ?
2008 if(vga_modes
[line
].class==TEXT
)
2010 biosfn_scroll(0x01,0x07,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
2014 biosfn_scroll(0x01,0x00,0,0,nbrows
-1,nbcols
-1,page
,SCROLL_UP
);
2019 // Set the cursor for the page
2020 cursor
=ycurs
; cursor
<<=8; cursor
+=xcurs
;
2021 biosfn_set_cursor_pos(page
,cursor
);
2024 // --------------------------------------------------------------------------------------------
2026 biosfn_get_video_mode
:
2028 mov ax
, # BIOSMEM_SEG
2031 mov bx
, # BIOSMEM_CURRENT_PAGE
2036 mov bx
, # BIOSMEM_VIDEO_CTL
2039 mov bx
, # BIOSMEM_CURRENT_MODE
2042 mov bx
, # BIOSMEM_NB_COLS
2049 // --------------------------------------------------------------------------------------------
2054 jmp biosfn_set_single_palette_reg
2058 jmp biosfn_set_overscan_border_color
2062 jmp biosfn_set_all_palette_reg
2066 jmp biosfn_toggle_intensity
2070 jmp biosfn_get_single_palette_reg
2074 jmp biosfn_read_overscan_border_color
2078 jmp biosfn_get_all_palette_reg
2082 jmp biosfn_set_single_dac_reg
2086 jmp biosfn_set_all_dac_reg
2090 jmp biosfn_select_video_dac_color_page
2094 jmp biosfn_read_single_dac_reg
2098 jmp biosfn_read_all_dac_reg
2102 jmp biosfn_set_pel_mask
2106 jmp biosfn_read_pel_mask
2109 jne int10_group_10_unknown
2110 jmp biosfn_read_video_dac_state
2111 int10_group_10_unknown
:
2117 biosfn_set_single_palette_reg
:
2122 mov dx
, # VGAREG_ACTL_RESET
2124 mov dx
, # VGAREG_ACTL_ADDRESS
2137 // --------------------------------------------------------------------------------------------
2139 biosfn_set_overscan_border_color
:
2142 call biosfn_set_single_palette_reg
2147 // --------------------------------------------------------------------------------------------
2149 biosfn_set_all_palette_reg
:
2155 mov dx
, # VGAREG_ACTL_RESET
2158 mov dx
, # VGAREG_ACTL_ADDRESS
2168 jne set_palette_loop
2183 // --------------------------------------------------------------------------------------------
2185 biosfn_toggle_intensity
:
2189 mov dx
, # VGAREG_ACTL_RESET
2191 mov dx
, # VGAREG_ACTL_ADDRESS
2194 mov dx
, # VGAREG_ACTL_READ_DATA
2200 mov dx
, # VGAREG_ACTL_ADDRESS
2210 // --------------------------------------------------------------------------------------------
2212 biosfn_get_single_palette_reg
:
2217 mov dx
, # VGAREG_ACTL_RESET
2219 mov dx
, # VGAREG_ACTL_ADDRESS
2222 mov dx
, # VGAREG_ACTL_READ_DATA
2225 mov dx
, # VGAREG_ACTL_RESET
2227 mov dx
, # VGAREG_ACTL_ADDRESS
2236 // --------------------------------------------------------------------------------------------
2238 biosfn_read_overscan_border_color
:
2242 call biosfn_get_single_palette_reg
2250 // --------------------------------------------------------------------------------------------
2252 biosfn_get_all_palette_reg
:
2260 mov dx
, # VGAREG_ACTL_RESET
2262 mov dx
, # VGAREG_ACTL_ADDRESS
2265 mov dx
, # VGAREG_ACTL_READ_DATA
2272 jne get_palette_loop
2273 mov dx
, # VGAREG_ACTL_RESET
2275 mov dx
, # VGAREG_ACTL_ADDRESS
2278 mov dx
, # VGAREG_ACTL_READ_DATA
2282 mov dx
, # VGAREG_ACTL_RESET
2284 mov dx
, # VGAREG_ACTL_ADDRESS
2294 // --------------------------------------------------------------------------------------------
2296 biosfn_set_single_dac_reg
:
2299 mov dx
, # VGAREG_DAC_WRITE_ADDRESS
2302 mov dx
, # VGAREG_DAC_DATA
2316 // --------------------------------------------------------------------------------------------
2318 biosfn_set_all_dac_reg
:
2323 mov dx
, # VGAREG_DAC_WRITE_ADDRESS
2329 mov dx
, # VGAREG_DAC_DATA
2352 // --------------------------------------------------------------------------------------------
2354 biosfn_select_video_dac_color_page
:
2358 mov dx
, # VGAREG_ACTL_RESET
2360 mov dx
, # VGAREG_ACTL_ADDRESS
2363 mov dx
, # VGAREG_ACTL_READ_DATA
2370 mov dx
, # VGAREG_ACTL_ADDRESS
2375 mov dx
, # VGAREG_ACTL_RESET
2377 mov dx
, # VGAREG_ACTL_ADDRESS
2397 // --------------------------------------------------------------------------------------------
2399 biosfn_read_single_dac_reg
:
2402 mov dx
, # VGAREG_DAC_READ_ADDRESS
2407 mov dx
, # VGAREG_DAC_DATA
2420 // --------------------------------------------------------------------------------------------
2422 biosfn_read_all_dac_reg
:
2427 mov dx
, # VGAREG_DAC_READ_ADDRESS
2433 mov dx
, # VGAREG_DAC_DATA
2456 // --------------------------------------------------------------------------------------------
2458 biosfn_set_pel_mask
:
2461 mov dx
, # VGAREG_PEL_MASK
2469 // --------------------------------------------------------------------------------------------
2471 biosfn_read_pel_mask
:
2474 mov dx
, # VGAREG_PEL_MASK
2482 // --------------------------------------------------------------------------------------------
2484 biosfn_read_video_dac_state
:
2487 mov dx
, # VGAREG_ACTL_RESET
2489 mov dx
, # VGAREG_ACTL_ADDRESS
2492 mov dx
, # VGAREG_ACTL_READ_DATA
2496 mov dx
, # VGAREG_ACTL_RESET
2498 mov dx
, # VGAREG_ACTL_ADDRESS
2501 mov dx
, # VGAREG_ACTL_READ_DATA
2509 mov dx
, # VGAREG_ACTL_RESET
2511 mov dx
, # VGAREG_ACTL_ADDRESS
2519 // --------------------------------------------------------------------------------------------
2520 static void biosfn_perform_gray_scale_summing (start
,count
)
2521 Bit16u start
;Bit16u count
;
2526 inb(VGAREG_ACTL_RESET
);
2527 outb(VGAREG_ACTL_ADDRESS
,0x00);
2529 for( index
= 0; index
< count
; index
++ )
2531 // set read address and switch to read mode
2532 outb(VGAREG_DAC_READ_ADDRESS
,start
);
2533 // get 6-bit wide RGB data values
2534 r
=inb( VGAREG_DAC_DATA
);
2535 g
=inb( VGAREG_DAC_DATA
);
2536 b
=inb( VGAREG_DAC_DATA
);
2538 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
2539 i
= ( ( 77*r
+ 151*g
+ 28*b
) + 0x80 ) >> 8;
2543 // set write address and switch to write mode
2544 outb(VGAREG_DAC_WRITE_ADDRESS
,start
);
2545 // write new intensity value
2546 outb( VGAREG_DAC_DATA
, i
&0xff );
2547 outb( VGAREG_DAC_DATA
, i
&0xff );
2548 outb( VGAREG_DAC_DATA
, i
&0xff );
2551 inb(VGAREG_ACTL_RESET
);
2552 outb(VGAREG_ACTL_ADDRESS
,0x20);
2555 // --------------------------------------------------------------------------------------------
2556 static void get_font_access()
2559 mov dx
, # VGAREG_SEQU_ADDRESS
2568 mov dx
, # VGAREG_GRDC_ADDRESS
2578 static void release_font_access()
2581 mov dx
, # VGAREG_SEQU_ADDRESS
2590 mov dx
, # VGAREG_READ_MISC_OUTPUT
2597 mov dx
, # VGAREG_GRDC_ADDRESS
2613 static void set_scan_lines(lines
) Bit8u lines
;
2615 Bit16u crtc_addr
,cols
,page
,vde
;
2616 Bit8u crtc_r9
,ovl
,rows
;
2618 crtc_addr
= read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
);
2619 outb(crtc_addr
, 0x09);
2620 crtc_r9
= inb(crtc_addr
+1);
2621 crtc_r9
= (crtc_r9
& 0xe0) | (lines
- 1);
2622 outb(crtc_addr
+1, crtc_r9
);
2625 biosfn_set_cursor_shape(0x06,0x07);
2629 biosfn_set_cursor_shape(lines
-4,lines
-3);
2631 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, lines
);
2632 outb(crtc_addr
, 0x12);
2633 vde
= inb(crtc_addr
+1);
2634 outb(crtc_addr
, 0x07);
2635 ovl
= inb(crtc_addr
+1);
2636 vde
+= (((ovl
& 0x02) << 7) + ((ovl
& 0x40) << 3) + 1);
2638 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, rows
-1);
2639 cols
= read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
);
2640 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, rows
* cols
* 2);
2643 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
;
2645 Bit16u blockaddr
,dest
,i
,src
;
2648 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2652 dest
= blockaddr
+ (DX
+ i
) * 32;
2653 memcpyb(0xA000, dest
, ES
, src
, BH
);
2655 release_font_access();
2662 static void biosfn_load_text_8_14_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2664 Bit16u blockaddr
,dest
,i
,src
;
2667 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2668 for(i
=0;i
<0x100;i
++)
2671 dest
= blockaddr
+ i
* 32;
2672 memcpyb(0xA000, dest
, 0xC000, vgafont14
+src
, 14);
2674 release_font_access();
2681 static void biosfn_load_text_8_8_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2683 Bit16u blockaddr
,dest
,i
,src
;
2686 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2687 for(i
=0;i
<0x100;i
++)
2690 dest
= blockaddr
+ i
* 32;
2691 memcpyb(0xA000, dest
, 0xC000, vgafont8
+src
, 8);
2693 release_font_access();
2700 // --------------------------------------------------------------------------------------------
2702 biosfn_set_text_block_specifier
:
2705 mov dx
, # VGAREG_SEQU_ADDRESS
2714 // --------------------------------------------------------------------------------------------
2715 static void biosfn_load_text_8_16_pat (AL
,BL
) Bit8u AL
;Bit8u BL
;
2717 Bit16u blockaddr
,dest
,i
,src
;
2720 blockaddr
= ((BL
& 0x03) << 14) + ((BL
& 0x04) << 11);
2721 for(i
=0;i
<0x100;i
++)
2724 dest
= blockaddr
+ i
* 32;
2725 memcpyb(0xA000, dest
, 0xC000, vgafont16
+src
, 16);
2727 release_font_access();
2734 static void biosfn_load_gfx_8_8_chars (ES
,BP
) Bit16u ES
;Bit16u BP
;
2740 static void biosfn_load_gfx_user_chars (ES
,BP
,CX
,BL
,DL
) Bit16u ES
;Bit16u BP
;Bit16u CX
;Bit8u BL
;Bit8u DL
;
2746 static void biosfn_load_gfx_8_14_chars (BL
) Bit8u BL
;
2752 static void biosfn_load_gfx_8_8_dd_chars (BL
) Bit8u BL
;
2758 static void biosfn_load_gfx_8_16_chars (BL
) Bit8u BL
;
2764 // --------------------------------------------------------------------------------------------
2765 static void biosfn_get_font_info (BH
,ES
,BP
,CX
,DX
)
2766 Bit8u BH
;Bit16u
*ES
;Bit16u
*BP
;Bit16u
*CX
;Bit16u
*DX
;
2767 {Bit16u ss
=get_SS();
2771 write_word(ss
,ES
,read_word(0x00,0x1f*4));
2772 write_word(ss
,BP
,read_word(0x00,(0x1f*4)+2));
2775 write_word(ss
,ES
,read_word(0x00,0x43*4));
2776 write_word(ss
,BP
,read_word(0x00,(0x43*4)+2));
2779 write_word(ss
,ES
,0xC000);
2780 write_word(ss
,BP
,vgafont14
);
2783 write_word(ss
,ES
,0xC000);
2784 write_word(ss
,BP
,vgafont8
);
2787 write_word(ss
,ES
,0xC000);
2788 write_word(ss
,BP
,vgafont8
+128*8);
2791 write_word(ss
,ES
,0xC000);
2792 write_word(ss
,BP
,vgafont14alt
);
2795 write_word(ss
,ES
,0xC000);
2796 write_word(ss
,BP
,vgafont16
);
2799 write_word(ss
,ES
,0xC000);
2800 write_word(ss
,BP
,vgafont16alt
);
2804 printf("Get font info BH(%02x) was discarded\n",BH
);
2808 // Set byte/char of on screen font
2809 write_word(ss
,CX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
));
2811 // Set Highest char row
2812 write_word(ss
,DX
,(Bit16u
)read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
));
2815 // --------------------------------------------------------------------------------------------
2817 biosfn_get_ega_info
:
2820 mov ax
, # BIOSMEM_SEG
2823 mov bx
, # BIOSMEM_SWITCHES
2826 mov bx
, # BIOSMEM_CRTC_ADDRESS
2829 cmp ax
, # VGAREG_MDA_CRTC_ADDRESS
2838 // --------------------------------------------------------------------------------------------
2839 static void biosfn_alternate_prtsc()
2846 // --------------------------------------------------------------------------------------------
2848 biosfn_select_vert_res
:
2850 ; res
: 00 200 lines
, 01 350 lines
, 02 400 lines
2856 mov ax
, # BIOSMEM_SEG
2858 mov bx
, # BIOSMEM_MODESET_CTL
2860 mov bx
, # BIOSMEM_SWITCHES
2871 mov bx
, #msg_vert_res
2879 ; reset modeset ctl bit
7 and set bit
4
2880 ; set switches bit
3-0 to
0x09
2889 ; reset modeset ctl bit
7 and bit
4
2890 ; set switches bit
3-0 to
0x09
2898 ; set modeset ctl bit
7 and reset bit
4
2899 ; set switches bit
3-0 to
0x08
2906 mov bx
, # BIOSMEM_MODESET_CTL
2908 mov bx
, # BIOSMEM_SWITCHES
2919 .ascii
"Select vert res (%02x) was discarded"
2920 .byte
0x0d,0x0a,0x00
2924 biosfn_enable_default_palette_loading
:
2931 mov ax
, # BIOSMEM_SEG
2933 mov bx
, # BIOSMEM_MODESET_CTL
2945 biosfn_enable_video_addressing
:
2952 mov dx
, # VGAREG_READ_MISC_OUTPUT
2956 mov dx
, # VGAREG_WRITE_MISC_OUTPUT
2964 biosfn_enable_grayscale_summing
:
2972 mov ax
, # BIOSMEM_SEG
2974 mov bx
, # BIOSMEM_MODESET_CTL
2986 biosfn_enable_cursor_emulation
:
2993 mov ax
, # BIOSMEM_SEG
2995 mov bx
, # BIOSMEM_MODESET_CTL
3007 // --------------------------------------------------------------------------------------------
3008 static void biosfn_switch_video_interface (AL
,ES
,DX
) Bit8u AL
;Bit16u ES
;Bit16u DX
;
3014 static void biosfn_enable_video_refresh_control (AL
) Bit8u AL
;
3021 // --------------------------------------------------------------------------------------------
3022 static void biosfn_write_string (flag
,page
,attr
,count
,row
,col
,seg
,offset
)
3023 Bit8u flag
;Bit8u page
;Bit8u attr
;Bit16u count
;Bit8u row
;Bit8u col
;Bit16u seg
;Bit16u offset
;
3025 Bit16u newcurs
,oldcurs
,dummy
;
3028 // Read curs info for the page
3029 biosfn_get_cursor_pos(page
,&dummy
,&oldcurs
);
3031 // if row=0xff special case : use current cursor position
3033 {col
=oldcurs
&0x00ff;
3034 row
=(oldcurs
&0xff00)>>8;
3037 newcurs
=row
; newcurs
<<=8; newcurs
+=col
;
3038 biosfn_set_cursor_pos(page
,newcurs
);
3042 car
=read_byte(seg
,offset
++);
3044 attr
=read_byte(seg
,offset
++);
3046 biosfn_write_teletype(car
,page
,attr
,WITH_ATTR
);
3049 // Set back curs pos
3051 biosfn_set_cursor_pos(page
,oldcurs
);
3054 // --------------------------------------------------------------------------------------------
3058 je biosfn_read_display_code
3060 je biosfn_set_display_code
3065 biosfn_read_display_code
:
3068 mov ax
, # BIOSMEM_SEG
3070 mov bx
, # BIOSMEM_DCC_INDEX
3078 biosfn_set_display_code
:
3082 mov ax
, # BIOSMEM_SEG
3085 mov bx
, # BIOSMEM_DCC_INDEX
3091 mov bx
, #msg_alt_dcc
3104 .ascii
"Alternate Display code (%02x) was discarded"
3105 .byte
0x0d,0x0a,0x00
3109 // --------------------------------------------------------------------------------------------
3110 static void biosfn_read_state_info (BX
,ES
,DI
)
3111 Bit16u BX
;Bit16u ES
;Bit16u DI
;
3113 // Address of static functionality table
3114 write_word(ES
,DI
+0x00,&static_functionality
);
3115 write_word(ES
,DI
+0x02,0xC000);
3117 // Hard coded copy from BIOS area. Should it be cleaner ?
3118 memcpyb(ES
,DI
+0x04,BIOSMEM_SEG
,0x49,30);
3119 memcpyb(ES
,DI
+0x22,BIOSMEM_SEG
,0x84,3);
3121 write_byte(ES
,DI
+0x25,read_byte(BIOSMEM_SEG
,BIOSMEM_DCC_INDEX
));
3122 write_byte(ES
,DI
+0x26,0);
3123 write_byte(ES
,DI
+0x27,16);
3124 write_byte(ES
,DI
+0x28,0);
3125 write_byte(ES
,DI
+0x29,8);
3126 write_byte(ES
,DI
+0x2a,2);
3127 write_byte(ES
,DI
+0x2b,0);
3128 write_byte(ES
,DI
+0x2c,0);
3129 write_byte(ES
,DI
+0x31,3);
3130 write_byte(ES
,DI
+0x32,0);
3132 memsetb(ES
,DI
+0x33,0,13);
3135 // --------------------------------------------------------------------------------------------
3136 // --------------------------------------------------------------------------------------------
3137 static Bit16u
biosfn_read_video_state_size2 (CX
)
3146 size
+= (5 + 8 + 5) * 2 + 6;
3149 size
+= 3 + 256 * 3 + 1;
3154 static void biosfn_read_video_state_size (CX
, BX
)
3155 Bit16u CX
; Bit16u
*BX
;
3158 write_word(ss
, BX
, biosfn_read_video_state_size2(CX
));
3161 static Bit16u
biosfn_save_video_state (CX
,ES
,BX
)
3162 Bit16u CX
;Bit16u ES
;Bit16u BX
;
3164 Bit16u i
, v
, crtc_addr
, ar_index
;
3166 crtc_addr
= read_word(BIOSMEM_SEG
, BIOSMEM_CRTC_ADDRESS
);
3168 write_byte(ES
, BX
, inb(VGAREG_SEQU_ADDRESS
)); BX
++;
3169 write_byte(ES
, BX
, inb(crtc_addr
)); BX
++;
3170 write_byte(ES
, BX
, inb(VGAREG_GRDC_ADDRESS
)); BX
++;
3171 inb(VGAREG_ACTL_RESET
);
3172 ar_index
= inb(VGAREG_ACTL_ADDRESS
);
3173 write_byte(ES
, BX
, ar_index
); BX
++;
3174 write_byte(ES
, BX
, inb(VGAREG_READ_FEATURE_CTL
)); BX
++;
3177 outb(VGAREG_SEQU_ADDRESS
, i
);
3178 write_byte(ES
, BX
, inb(VGAREG_SEQU_DATA
)); BX
++;
3180 outb(VGAREG_SEQU_ADDRESS
, 0);
3181 write_byte(ES
, BX
, inb(VGAREG_SEQU_DATA
)); BX
++;
3183 for(i
=0;i
<=0x18;i
++) {
3185 write_byte(ES
, BX
, inb(crtc_addr
+1)); BX
++;
3188 for(i
=0;i
<=0x13;i
++) {
3189 inb(VGAREG_ACTL_RESET
);
3190 outb(VGAREG_ACTL_ADDRESS
, i
| (ar_index
& 0x20));
3191 write_byte(ES
, BX
, inb(VGAREG_ACTL_READ_DATA
)); BX
++;
3193 inb(VGAREG_ACTL_RESET
);
3196 outb(VGAREG_GRDC_ADDRESS
,i
);
3197 write_byte(ES
, BX
, inb(VGAREG_GRDC_DATA
)); BX
++;
3200 write_word(ES
, BX
, crtc_addr
); BX
+= 2;
3202 /* XXX: read plane latches */
3203 write_byte(ES
, BX
, 0); BX
++;
3204 write_byte(ES
, BX
, 0); BX
++;
3205 write_byte(ES
, BX
, 0); BX
++;
3206 write_byte(ES
, BX
, 0); BX
++;
3209 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
)); BX
++;
3210 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
)); BX
+= 2;
3211 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
)); BX
+= 2;
3212 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
)); BX
+= 2;
3213 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
)); BX
++;
3214 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
)); BX
+= 2;
3215 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
)); BX
++;
3216 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
)); BX
++;
3217 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
)); BX
++;
3218 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
)); BX
+= 2;
3220 write_word(ES
, BX
, read_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*i
));
3223 write_word(ES
, BX
, read_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
)); BX
+= 2;
3224 write_byte(ES
, BX
, read_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
)); BX
++;
3226 write_word(ES
, BX
, read_word(0, 0x1f * 4)); BX
+= 2;
3227 write_word(ES
, BX
, read_word(0, 0x1f * 4 + 2)); BX
+= 2;
3228 write_word(ES
, BX
, read_word(0, 0x43 * 4)); BX
+= 2;
3229 write_word(ES
, BX
, read_word(0, 0x43 * 4 + 2)); BX
+= 2;
3232 /* XXX: check this */
3233 write_byte(ES
, BX
, inb(VGAREG_DAC_STATE
)); BX
++; /* read/write mode dac */
3234 write_byte(ES
, BX
, inb(VGAREG_DAC_WRITE_ADDRESS
)); BX
++; /* pix address */
3235 write_byte(ES
, BX
, inb(VGAREG_PEL_MASK
)); BX
++;
3236 // Set the whole dac always, from 0
3237 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
3238 for(i
=0;i
<256*3;i
++) {
3239 write_byte(ES
, BX
, inb(VGAREG_DAC_DATA
)); BX
++;
3241 write_byte(ES
, BX
, 0); BX
++; /* color select register */
3246 static Bit16u
biosfn_restore_video_state (CX
,ES
,BX
)
3247 Bit16u CX
;Bit16u ES
;Bit16u BX
;
3249 Bit16u i
, crtc_addr
, v
, addr1
, ar_index
;
3252 // Reset Attribute Ctl flip-flop
3253 inb(VGAREG_ACTL_RESET
);
3255 crtc_addr
= read_word(ES
, BX
+ 0x40);
3260 outb(VGAREG_SEQU_ADDRESS
, i
);
3261 outb(VGAREG_SEQU_DATA
, read_byte(ES
, BX
)); BX
++;
3263 outb(VGAREG_SEQU_ADDRESS
, 0);
3264 outb(VGAREG_SEQU_DATA
, read_byte(ES
, BX
)); BX
++;
3266 // Disable CRTC write protection
3267 outw(crtc_addr
,0x0011);
3269 for(i
=0;i
<=0x18;i
++) {
3272 outb(crtc_addr
+1, read_byte(ES
, BX
));
3276 // select crtc base address
3277 v
= inb(VGAREG_READ_MISC_OUTPUT
) & ~0x01;
3278 if (crtc_addr
= 0x3d4)
3280 outb(VGAREG_WRITE_MISC_OUTPUT
, v
);
3282 // enable write protection if needed
3283 outb(crtc_addr
, 0x11);
3284 outb(crtc_addr
+1, read_byte(ES
, BX
- 0x18 + 0x11));
3286 // Set Attribute Ctl
3287 ar_index
= read_byte(ES
, addr1
+ 0x03);
3288 inb(VGAREG_ACTL_RESET
);
3289 for(i
=0;i
<=0x13;i
++) {
3290 outb(VGAREG_ACTL_ADDRESS
, i
| (ar_index
& 0x20));
3291 outb(VGAREG_ACTL_WRITE_DATA
, read_byte(ES
, BX
)); BX
++;
3293 outb(VGAREG_ACTL_ADDRESS
, ar_index
);
3294 inb(VGAREG_ACTL_RESET
);
3297 outb(VGAREG_GRDC_ADDRESS
,i
);
3298 outb(VGAREG_GRDC_DATA
, read_byte(ES
, BX
)); BX
++;
3300 BX
+= 2; /* crtc_addr */
3301 BX
+= 4; /* plane latches */
3303 outb(VGAREG_SEQU_ADDRESS
, read_byte(ES
, addr1
)); addr1
++;
3304 outb(crtc_addr
, read_byte(ES
, addr1
)); addr1
++;
3305 outb(VGAREG_GRDC_ADDRESS
, read_byte(ES
, addr1
)); addr1
++;
3307 outb(crtc_addr
- 0x4 + 0xa, read_byte(ES
, addr1
)); addr1
++;
3310 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_MODE
, read_byte(ES
, BX
)); BX
++;
3311 write_word(BIOSMEM_SEG
,BIOSMEM_NB_COLS
, read_word(ES
, BX
)); BX
+= 2;
3312 write_word(BIOSMEM_SEG
,BIOSMEM_PAGE_SIZE
, read_word(ES
, BX
)); BX
+= 2;
3313 write_word(BIOSMEM_SEG
,BIOSMEM_CRTC_ADDRESS
, read_word(ES
, BX
)); BX
+= 2;
3314 write_byte(BIOSMEM_SEG
,BIOSMEM_NB_ROWS
, read_byte(ES
, BX
)); BX
++;
3315 write_word(BIOSMEM_SEG
,BIOSMEM_CHAR_HEIGHT
, read_word(ES
, BX
)); BX
+= 2;
3316 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
, read_byte(ES
, BX
)); BX
++;
3317 write_byte(BIOSMEM_SEG
,BIOSMEM_SWITCHES
, read_byte(ES
, BX
)); BX
++;
3318 write_byte(BIOSMEM_SEG
,BIOSMEM_MODESET_CTL
, read_byte(ES
, BX
)); BX
++;
3319 write_word(BIOSMEM_SEG
,BIOSMEM_CURSOR_TYPE
, read_word(ES
, BX
)); BX
+= 2;
3321 write_word(BIOSMEM_SEG
, BIOSMEM_CURSOR_POS
+2*i
, read_word(ES
, BX
));
3324 write_word(BIOSMEM_SEG
,BIOSMEM_CURRENT_START
, read_word(ES
, BX
)); BX
+= 2;
3325 write_byte(BIOSMEM_SEG
,BIOSMEM_CURRENT_PAGE
, read_byte(ES
, BX
)); BX
++;
3327 write_word(0, 0x1f * 4, read_word(ES
, BX
)); BX
+= 2;
3328 write_word(0, 0x1f * 4 + 2, read_word(ES
, BX
)); BX
+= 2;
3329 write_word(0, 0x43 * 4, read_word(ES
, BX
)); BX
+= 2;
3330 write_word(0, 0x43 * 4 + 2, read_word(ES
, BX
)); BX
+= 2;
3334 v
= read_byte(ES
, BX
); BX
++;
3335 outb(VGAREG_PEL_MASK
, read_byte(ES
, BX
)); BX
++;
3336 // Set the whole dac always, from 0
3337 outb(VGAREG_DAC_WRITE_ADDRESS
,0x00);
3338 for(i
=0;i
<256*3;i
++) {
3339 outb(VGAREG_DAC_DATA
, read_byte(ES
, BX
)); BX
++;
3342 outb(VGAREG_DAC_WRITE_ADDRESS
, v
);
3347 // ============================================================================================
3351 // ============================================================================================
3353 // --------------------------------------------------------------------------------------------
3354 static Bit8u
find_vga_entry(mode
)
3358 for(i
=0;i
<=MODE_MAX
;i
++)
3359 if(vga_modes
[i
].svgamode
==mode
)
3366 /* =========================================================== */
3370 /* =========================================================== */
3372 // --------------------------------------------------------------------------------------------
3373 static void memsetb(seg
,offset
,value
,count
)
3388 mov cx
, 10[bp
] ; count
3391 mov ax
, 4[bp
] ; segment
3393 mov ax
, 6[bp
] ; offset
3395 mov al
, 8[bp
] ; value
3410 // --------------------------------------------------------------------------------------------
3411 static void memsetw(seg
,offset
,value
,count
)
3426 mov cx
, 10[bp
] ; count
3429 mov ax
, 4[bp
] ; segment
3431 mov ax
, 6[bp
] ; offset
3433 mov ax
, 8[bp
] ; value
3448 // --------------------------------------------------------------------------------------------
3449 static void memcpyb(dseg
,doffset
,sseg
,soffset
,count
)
3467 mov cx
, 12[bp
] ; count
3470 mov ax
, 4[bp
] ; dsegment
3472 mov ax
, 6[bp
] ; doffset
3474 mov ax
, 8[bp
] ; ssegment
3476 mov ax
, 10[bp
] ; soffset
3494 // --------------------------------------------------------------------------------------------
3495 static void memcpyw(dseg
,doffset
,sseg
,soffset
,count
)
3513 mov cx
, 12[bp
] ; count
3516 mov ax
, 4[bp
] ; dsegment
3518 mov ax
, 6[bp
] ; doffset
3520 mov ax
, 8[bp
] ; ssegment
3522 mov ax
, 10[bp
] ; soffset
3540 /* =========================================================== */
3542 * These functions where ripped from Kevin's rombios.c
3544 /* =========================================================== */
3546 // --------------------------------------------------------------------------------------------
3548 read_byte(seg
, offset
)
3558 mov ax
, 4[bp
] ; segment
3560 mov bx
, 6[bp
] ; offset
3562 ;; al
= return value (byte
)
3570 // --------------------------------------------------------------------------------------------
3572 read_word(seg
, offset
)
3582 mov ax
, 4[bp
] ; segment
3584 mov bx
, 6[bp
] ; offset
3586 ;; ax
= return value (word
)
3594 // --------------------------------------------------------------------------------------------
3596 write_byte(seg
, offset
, data
)
3608 mov ax
, 4[bp
] ; segment
3610 mov bx
, 6[bp
] ; offset
3611 mov al
, 8[bp
] ; data byte
3612 mov
[bx
], al
; write data byte
3621 // --------------------------------------------------------------------------------------------
3623 write_word(seg
, offset
, data
)
3635 mov ax
, 4[bp
] ; segment
3637 mov bx
, 6[bp
] ; offset
3638 mov ax
, 8[bp
] ; data word
3639 mov
[bx
], ax
; write data word
3648 // --------------------------------------------------------------------------------------------
3683 // --------------------------------------------------------------------------------------------
3705 // --------------------------------------------------------------------------------------------
3735 void unimplemented()
3737 printf("--> Unimplemented\n");
3742 printf("--> Unknown int10\n");
3746 // --------------------------------------------------------------------------------------------
3747 #if defined(USE_BX_INFO) || defined(DEBUG) || defined(CIRRUS_DEBUG)
3751 Bit8u c
, format_char
;
3753 unsigned format_width
, i
;
3755 Bit16u arg_seg
, arg
, digit
, nibble
, shift_count
;
3763 while (c
= read_byte(0xc000, s
)) {
3768 else if (in_format
) {
3769 if ( (c
>='0') && (c
<='9') ) {
3770 format_width
= (format_width
* 10) + (c
- '0');
3772 else if (c
== 'x') {
3773 arg_ptr
++; // increment to next arg
3774 arg
= read_word(arg_seg
, arg_ptr
);
3775 if (format_width
== 0)
3778 digit
= format_width
- 1;
3779 for (i
=0; i
<format_width
; i
++) {
3780 nibble
= (arg
>> (4 * digit
)) & 0x000f;
3782 outb(0x0500, nibble
+ '0');
3784 outb(0x0500, (nibble
- 10) + 'A');
3789 //else if (c == 'd') {
3809 // --------------------------------------------------------------------------------------------
3812 ;; DATA_SEG_DEFS_HERE
3816 .ascii
"vgabios ends here"
3820 ;; BLOCK_STRINGS_BEGIN