Debian Codegraph @

tools/firmware/vgabios/vgabios.c

raw
1 // ============================================================================================
2 /*
3 * vgabios.c
4 */
5 // ============================================================================================
6 //
7 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
8 //
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.
13 //
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.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; If not, see <http://www.gnu.org/licenses/>.
21 //
22 // ============================================================================================
23 //
24 // This VGA Bios is specific to the plex86/bochs Emulated VGA card.
25 // You can NOT drive any physical vga card with it.
26 //
27 // ============================================================================================
28 //
29 // This file contains code ripped from :
30 // - rombios.c of plex86
31 //
32 // This VGA Bios contains fonts from :
33 // - fntcol16.zip (c) by Joseph Gil avalable at :
34 // ftp://ftp.simtel.net/pub/simtelnet/msdos/screen/fntcol16.zip
35 // These fonts are public domain
36 //
37 // This VGA Bios is based on information taken from :
38 // - Kevin Lawton's vga card emulation for bochs/plex86
39 // - Ralf Brown's interrupts list available at http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html
40 // - Finn Thogersons' VGADOC4b available at http://home.worldonline.dk/~finth/
41 // - Michael Abrash's Graphics Programming Black Book
42 // - Francois Gervais' book "programmation des cartes graphiques cga-ega-vga" edited by sybex
43 // - DOSEMU 1.0.1 source code for several tables values and formulas
44 //
45 // Thanks for patches, comments and ideas to :
46 // - [email protected]
47 //
48 // ============================================================================================
49
50 #include "vgabios.h"
51
52 #ifdef VBE
53 #include "vbe.h"
54 #endif
55
56 #define USE_BX_INFO
57
58 /* Declares */
59 static Bit8u read_byte();
60 static Bit16u read_word();
61 static void write_byte();
62 static void write_word();
63 static Bit8u inb();
64 static Bit16u inw();
65 static void outb();
66 static void outw();
67
68 static Bit16u get_SS();
69
70 // Output
71 static void printf();
72 static void unimplemented();
73 static void unknown();
74
75 static Bit8u find_vga_entry();
76
77 static void memsetb();
78 static void memsetw();
79 static void memcpyb();
80 static void memcpyw();
81
82 static void biosfn_set_video_mode();
83 static void biosfn_set_cursor_shape();
84 static void biosfn_set_cursor_pos();
85 static void biosfn_get_cursor_pos();
86 static void biosfn_set_active_page();
87 static void biosfn_scroll();
88 static void biosfn_read_char_attr();
89 static void biosfn_write_char_attr();
90 static void biosfn_write_char_only();
91 static void biosfn_write_pixel();
92 static void biosfn_read_pixel();
93 static void biosfn_write_teletype();
94 static void biosfn_perform_gray_scale_summing();
95 static void biosfn_load_text_user_pat();
96 static void biosfn_load_text_8_14_pat();
97 static void biosfn_load_text_8_8_pat();
98 static void biosfn_load_text_8_16_pat();
99 static void biosfn_load_gfx_8_8_chars();
100 static void biosfn_load_gfx_user_chars();
101 static void biosfn_load_gfx_8_14_chars();
102 static void biosfn_load_gfx_8_8_dd_chars();
103 static void biosfn_load_gfx_8_16_chars();
104 static void biosfn_get_font_info();
105 static void biosfn_alternate_prtsc();
106 static void biosfn_switch_video_interface();
107 static void biosfn_enable_video_refresh_control();
108 static void biosfn_write_string();
109 static void biosfn_read_state_info();
110 static void biosfn_read_video_state_size();
111 static Bit16u biosfn_save_video_state();
112 static Bit16u biosfn_restore_video_state();
113 extern Bit8u video_save_pointer_table[];
114
115 // This is for compiling with gcc2 and gcc3
116 #define ASM_START #asm
117 #define ASM_END #endasm
118
119 ASM_START
120
121 MACRO SET_INT_VECTOR
122 push ds
123 xor ax, ax
124 mov ds, ax
125 mov ax, ?3
126 mov ?1*4, ax
127 mov ax, ?2
128 mov ?1*4+2, ax
129 pop ds
130 MEND
131
132 ASM_END
133
134 ASM_START
135 .text
136 .rom
137 .org 0
138
139 use16 386
140
141 vgabios_start:
142 .byte 0x55, 0xaa /* BIOS signature, required for BIOS extensions */
143
144 .byte 0x40 /* BIOS extension length in units of 512 bytes */
145
146
147 vgabios_entry_point:
148
149 jmp vgabios_init_func
150
151 #ifdef PCIBIOS
152 .org 0x18
153 .word vgabios_pci_data
154 #endif
155
156 // Info from Bart Oldeman
157 .org 0x1e
158 .ascii "IBM"
159 .byte 0x00
160
161 vgabios_name:
162 .ascii "Plex86/Bochs VGABios"
163 #ifdef PCIBIOS
164 .ascii " (PCI)"
165 #endif
166 .ascii " "
167 .byte 0x00
168
169 vgabios_version:
170 #ifndef VGABIOS_VERS
171 .ascii "current-cvs"
172 #else
173 .ascii VGABIOS_VERS
174 #endif
175 .ascii " "
176
177 vgabios_date:
178 .ascii VGABIOS_DATE
179 .byte 0x0a,0x0d
180 .byte 0x00
181
182 vgabios_copyright:
183 .ascii "(C) 2008 the LGPL VGABios developers Team"
184 .byte 0x0a,0x0d
185 .byte 0x00
186
187 vgabios_license:
188 .ascii "This VGA/VBE Bios is released under the GNU LGPL"
189 .byte 0x0a,0x0d
190 .byte 0x0a,0x0d
191 .byte 0x00
192
193 vgabios_website:
194 .ascii "Please visit :"
195 .byte 0x0a,0x0d
196 ;;.ascii " . http://www.plex86.org"
197 ;;.byte 0x0a,0x0d
198 .ascii " . http://bochs.sourceforge.net"
199 .byte 0x0a,0x0d
200 .ascii " . http://www.nongnu.org/vgabios"
201 .byte 0x0a,0x0d
202 .byte 0x0a,0x0d
203 .byte 0x00
204
205 #ifdef PCIBIOS
206 vgabios_pci_data:
207 .ascii "PCIR"
208 #ifdef CIRRUS
209 .word 0x1013
210 .word 0x00b8 // CLGD5446
211 #else
212 #error "Unknown PCI vendor and device id"
213 #endif
214 .word 0 // reserved
215 .word 0x18 // dlen
216 .byte 0 // revision
217 .byte 0x0 // class,hi: vga display
218 .word 0x300 // class,lo: vga display
219 .word 0x40 // bios size
220 .word 1 // revision
221 .byte 0 // intel x86 data
222 .byte 0x80 // last image
223 .word 0 // reserved
224 #endif
225
226
227 ;; ============================================================================================
228 ;;
229 ;; Init Entry point
230 ;;
231 ;; ============================================================================================
232 vgabios_init_func:
233
234 ;; init vga card
235 call init_vga_card
236
237 ;; init basic bios vars
238 call init_bios_area
239
240 #ifdef VBE
241 ;; init vbe functions
242 call vbe_init
243 #endif
244
245 ;; set int10 vect
246 SET_INT_VECTOR(0x10, #0xC000, #vgabios_int10_handler)
247
248 #ifdef CIRRUS
249 call cirrus_init
250 #endif
251
252 ;; display splash screen
253 call _display_splash_screen
254
255 ;; init video mode and clear the screen
256 mov ax,#0x0003
257 int #0x10
258
259 ;; show info
260 call _display_info
261
262 #ifdef VBE
263 ;; show vbe info
264 call vbe_display_info
265 #endif
266
267 #ifdef CIRRUS
268 ;; show cirrus info
269 call cirrus_display_info
270 #endif
271
272 retf
273 ASM_END
274
275 /*
276 * int10 handled here
277 */
278 ASM_START
279 vgabios_int10_handler:
280 pushf
281 #ifdef DEBUG
282 push es
283 push ds
284 pusha
285 mov bx, #0xc000
286 mov ds, bx
287 call _int10_debugmsg
288 popa
289 pop ds
290 pop es
291 #endif
292 cmp ah, #0x0f
293 jne int10_test_1A
294 call biosfn_get_video_mode
295 jmp int10_end
296 int10_test_1A:
297 cmp ah, #0x1a
298 jne int10_test_0B
299 call biosfn_group_1A
300 jmp int10_end
301 int10_test_0B:
302 cmp ah, #0x0b
303 jne int10_test_1103
304 call biosfn_group_0B
305 jmp int10_end
306 int10_test_1103:
307 cmp ax, #0x1103
308 jne int10_test_12
309 call biosfn_set_text_block_specifier
310 jmp int10_end
311 int10_test_12:
312 cmp ah, #0x12
313 jne int10_test_101B
314 cmp bl, #0x10
315 jne int10_test_BL30
316 call biosfn_get_ega_info
317 jmp int10_end
318 int10_test_BL30:
319 cmp bl, #0x30
320 jne int10_test_BL31
321 call biosfn_select_vert_res
322 jmp int10_end
323 int10_test_BL31:
324 cmp bl, #0x31
325 jne int10_test_BL32
326 call biosfn_enable_default_palette_loading
327 jmp int10_end
328 int10_test_BL32:
329 cmp bl, #0x32
330 jne int10_test_BL33
331 call biosfn_enable_video_addressing
332 jmp int10_end
333 int10_test_BL33:
334 cmp bl, #0x33
335 jne int10_test_BL34
336 call biosfn_enable_grayscale_summing
337 jmp int10_end
338 int10_test_BL34:
339 cmp bl, #0x34
340 jne int10_normal
341 call biosfn_enable_cursor_emulation
342 jmp int10_end
343 int10_test_101B:
344 cmp ax, #0x101b
345 je int10_normal
346 cmp ah, #0x10
347 #ifndef VBE
348 jne int10_normal
349 #else
350 jne int10_test_4F
351 #endif
352 call biosfn_group_10
353 jmp int10_end
354 #ifdef VBE
355 int10_test_4F:
356 cmp ah, #0x4f
357 jne int10_normal
358 cmp al, #0x03
359 jne int10_test_vbe_05
360 call vbe_biosfn_return_current_mode
361 jmp int10_end
362 int10_test_vbe_05:
363 cmp al, #0x05
364 jne int10_test_vbe_06
365 call vbe_biosfn_display_window_control
366 jmp int10_end
367 int10_test_vbe_06:
368 cmp al, #0x06
369 jne int10_test_vbe_07
370 call vbe_biosfn_set_get_logical_scan_line_length
371 jmp int10_end
372 int10_test_vbe_07:
373 cmp al, #0x07
374 jne int10_test_vbe_08
375 call vbe_biosfn_set_get_display_start
376 jmp int10_end
377 int10_test_vbe_08:
378 cmp al, #0x08
379 jne int10_test_vbe_0A
380 call vbe_biosfn_set_get_dac_palette_format
381 jmp int10_end
382 int10_test_vbe_0A:
383 cmp al, #0x0A
384 jne int10_normal
385 call vbe_biosfn_return_protected_mode_interface
386 jmp int10_end
387 #endif
388
389 int10_normal:
390 push es
391 push ds
392 pusha
393
394 ;; We have to set ds to access the right data segment
395 mov bx, #0xc000
396 mov ds, bx
397 call _int10_func
398
399 popa
400 pop ds
401 pop es
402 int10_end:
403 popf
404 iret
405 ASM_END
406
407 #include "vgatables.h"
408 #include "vgafonts.h"
409
410 /*
411 * Boot time harware inits
412 */
413 ASM_START
414 init_vga_card:
415 ;; switch to color mode and enable CPU access 480 lines
416 mov dx, #0x3C2
417 mov al, #0xC3
418 outb dx,al
419
420 ;; more than 64k 3C4/04
421 mov dx, #0x3C4
422 mov al, #0x04
423 outb dx,al
424 mov dx, #0x3C5
425 mov al, #0x02
426 outb dx,al
427
428 #if defined(USE_BX_INFO) || defined(DEBUG)
429 mov bx, #msg_vga_init
430 push bx
431 call _printf
432 #endif
433 inc sp
434 inc sp
435 ret
436
437 #if defined(USE_BX_INFO) || defined(DEBUG)
438 msg_vga_init:
439 .ascii "VGABios $Id: vgabios.c,v 1.67 2008/01/27 09:44:12 vruppert Exp $"
440 .byte 0x0d,0x0a,0x00
441 #endif
442 ASM_END
443
444 // --------------------------------------------------------------------------------------------
445 /*
446 * Boot time bios area inits
447 */
448 ASM_START
449 init_bios_area:
450 push ds
451 mov ax, # BIOSMEM_SEG
452 mov ds, ax
453
454 ;; init detected hardware BIOS Area
455 mov bx, # BIOSMEM_INITIAL_MODE
456 mov ax, [bx]
457 and ax, #0xffcf
458 ;; set 80x25 color (not clear from RBIL but usual)
459 or ax, #0x0020
460 mov [bx], ax
461
462 ;; Just for the first int10 find its children
463
464 ;; the default char height
465 mov bx, # BIOSMEM_CHAR_HEIGHT
466 mov al, #0x10
467 mov [bx], al
468
469 ;; Clear the screen
470 mov bx, # BIOSMEM_VIDEO_CTL
471 mov al, #0x60
472 mov [bx], al
473
474 ;; Set the basic screen we have
475 mov bx, # BIOSMEM_SWITCHES
476 mov al, #0xf9
477 mov [bx], al
478
479 ;; Set the basic modeset options
480 mov bx, # BIOSMEM_MODESET_CTL
481 mov al, #0x51
482 mov [bx], al
483
484 ;; Set the default MSR
485 mov bx, # BIOSMEM_CURRENT_MSR
486 mov al, #0x09
487 mov [bx], al
488
489 pop ds
490 ret
491
492 _video_save_pointer_table:
493 .word _video_param_table
494 .word 0xc000
495
496 .word 0 /* XXX: fill it */
497 .word 0
498
499 .word 0 /* XXX: fill it */
500 .word 0
501
502 .word 0 /* XXX: fill it */
503 .word 0
504
505 .word 0 /* XXX: fill it */
506 .word 0
507
508 .word 0 /* XXX: fill it */
509 .word 0
510
511 .word 0 /* XXX: fill it */
512 .word 0
513
514 ASM_END
515
516 // --------------------------------------------------------------------------------------------
517 /*
518 * Boot time Splash screen
519 */
520 static void display_splash_screen()
521 {
522 }
523
524 // --------------------------------------------------------------------------------------------
525 /*
526 * Tell who we are
527 */
528
529 static void display_info()
530 {
531 ASM_START
532 mov ax,#0xc000
533 mov ds,ax
534 mov si,#vgabios_name
535 call _display_string
536 mov si,#vgabios_version
537 call _display_string
538
539 ;;mov si,#vgabios_copyright
540 ;;call _display_string
541 ;;mov si,#crlf
542 ;;call _display_string
543
544 mov si,#vgabios_license
545 call _display_string
546 mov si,#vgabios_website
547 call _display_string
548 ASM_END
549 }
550
551 static void display_string()
552 {
553 // Get length of string
554 ASM_START
555 mov ax,ds
556 mov es,ax
557 mov di,si
558 xor cx,cx
559 not cx
560 xor al,al
561 cld
562 repne
563 scasb
564 not cx
565 dec cx
566 push cx
567
568 mov ax,#0x0300
569 mov bx,#0x0000
570 int #0x10
571
572 pop cx
573 mov ax,#0x1301
574 mov bx,#0x000b
575 mov bp,si
576 int #0x10
577 ASM_END
578 }
579
580 // --------------------------------------------------------------------------------------------
581 #ifdef DEBUG
582 static void int10_debugmsg(DI, SI, BP, SP, BX, DX, CX, AX, DS, ES, FLAGS)
583 Bit16u DI, SI, BP, SP, BX, DX, CX, AX, ES, DS, FLAGS;
584 {
585 // 0E is write char...
586 if(GET_AH()!=0x0E)
587 printf("vgabios call ah%02x al%02x bx%04x cx%04x dx%04x\n",GET_AH(),GET_AL(),BX,CX,DX);
588 }
589 #endif
590
591 // --------------------------------------------------------------------------------------------
592 /*
593 * int10 main dispatcher
594 */
595 static void int10_func(DI, SI, BP, SP, BX, DX, CX, AX, DS, ES, FLAGS)
596 Bit16u DI, SI, BP, SP, BX, DX, CX, AX, ES, DS, FLAGS;
597 {
598
599 // BIOS functions
600 switch(GET_AH())
601 {
602 case 0x00:
603 biosfn_set_video_mode(GET_AL());
604 switch(GET_AL()&0x7F)
605 {case 6:
606 SET_AL(0x3F);
607 break;
608 case 0:
609 case 1:
610 case 2:
611 case 3:
612 case 4:
613 case 5:
614 case 7:
615 SET_AL(0x30);
616 break;
617 default:
618 SET_AL(0x20);
619 }
620 break;
621 case 0x01:
622 biosfn_set_cursor_shape(GET_CH(),GET_CL());
623 break;
624 case 0x02:
625 biosfn_set_cursor_pos(GET_BH(),DX);
626 break;
627 case 0x03:
628 biosfn_get_cursor_pos(GET_BH(),&CX,&DX);
629 break;
630 case 0x04:
631 // Read light pen pos (unimplemented)
632 #ifdef DEBUG
633 unimplemented();
634 #endif
635 AX=0x00;
636 BX=0x00;
637 CX=0x00;
638 DX=0x00;
639 break;
640 case 0x05:
641 biosfn_set_active_page(GET_AL());
642 break;
643 case 0x06:
644 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_UP);
645 break;
646 case 0x07:
647 biosfn_scroll(GET_AL(),GET_BH(),GET_CH(),GET_CL(),GET_DH(),GET_DL(),0xFF,SCROLL_DOWN);
648 break;
649 case 0x08:
650 biosfn_read_char_attr(GET_BH(),&AX);
651 break;
652 case 0x09:
653 biosfn_write_char_attr(GET_AL(),GET_BH(),GET_BL(),CX);
654 break;
655 case 0x0A:
656 biosfn_write_char_only(GET_AL(),GET_BH(),GET_BL(),CX);
657 break;
658 case 0x0C:
659 biosfn_write_pixel(GET_BH(),GET_AL(),CX,DX);
660 break;
661 case 0x0D:
662 biosfn_read_pixel(GET_BH(),CX,DX,&AX);
663 break;
664 case 0x0E:
665 // Ralf Brown Interrupt list is WRONG on bh(page)
666 // We do output only on the current page !
667 biosfn_write_teletype(GET_AL(),0xff,GET_BL(),NO_ATTR);
668 break;
669 case 0x10:
670 // All other functions of group AH=0x10 rewritten in assembler
671 biosfn_perform_gray_scale_summing(BX,CX);
672 break;
673 case 0x11:
674 switch(GET_AL())
675 {
676 case 0x00:
677 case 0x10:
678 biosfn_load_text_user_pat(GET_AL(),ES,BP,CX,DX,GET_BL(),GET_BH());
679 break;
680 case 0x01:
681 case 0x11:
682 biosfn_load_text_8_14_pat(GET_AL(),GET_BL());
683 break;
684 case 0x02:
685 case 0x12:
686 biosfn_load_text_8_8_pat(GET_AL(),GET_BL());
687 break;
688 case 0x04:
689 case 0x14:
690 biosfn_load_text_8_16_pat(GET_AL(),GET_BL());
691 break;
692 case 0x20:
693 biosfn_load_gfx_8_8_chars(ES,BP);
694 break;
695 case 0x21:
696 biosfn_load_gfx_user_chars(ES,BP,CX,GET_BL(),GET_DL());
697 break;
698 case 0x22:
699 biosfn_load_gfx_8_14_chars(GET_BL());
700 break;
701 case 0x23:
702 biosfn_load_gfx_8_8_dd_chars(GET_BL());
703 break;
704 case 0x24:
705 biosfn_load_gfx_8_16_chars(GET_BL());
706 break;
707 case 0x30:
708 biosfn_get_font_info(GET_BH(),&ES,&BP,&CX,&DX);
709 break;
710 #ifdef DEBUG
711 default:
712 unknown();
713 #endif
714 }
715
716 break;
717 case 0x12:
718 switch(GET_BL())
719 {
720 case 0x20:
721 biosfn_alternate_prtsc();
722 break;
723 case 0x35:
724 biosfn_switch_video_interface(GET_AL(),ES,DX);
725 SET_AL(0x12);
726 break;
727 case 0x36:
728 biosfn_enable_video_refresh_control(GET_AL());
729 SET_AL(0x12);
730 break;
731 #ifdef DEBUG
732 default:
733 unknown();
734 #endif
735 }
736 break;
737 case 0x13:
738 biosfn_write_string(GET_AL(),GET_BH(),GET_BL(),CX,GET_DH(),GET_DL(),ES,BP);
739 break;
740 case 0x1B:
741 biosfn_read_state_info(BX,ES,DI);
742 SET_AL(0x1B);
743 break;
744 case 0x1C:
745 switch(GET_AL())
746 {
747 case 0x00:
748 biosfn_read_video_state_size(CX,&BX);
749 break;
750 case 0x01:
751 biosfn_save_video_state(CX,ES,BX);
752 break;
753 case 0x02:
754 biosfn_restore_video_state(CX,ES,BX);
755 break;
756 #ifdef DEBUG
757 default:
758 unknown();
759 #endif
760 }
761 SET_AL(0x1C);
762 break;
763
764 #ifdef VBE
765 case 0x4f:
766 if (vbe_has_vbe_display()) {
767 switch(GET_AL())
768 {
769 case 0x00:
770 vbe_biosfn_return_controller_information(&AX,ES,DI);
771 break;
772 case 0x01:
773 vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
774 break;
775 case 0x02:
776 vbe_biosfn_set_mode(&AX,BX,ES,DI);
777 break;
778 case 0x04:
779 vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
780 break;
781 case 0x09:
782 //FIXME
783 #ifdef DEBUG
784 unimplemented();
785 #endif
786 // function failed
787 AX=0x100;
788 break;
789 case 0x0A:
790 //FIXME
791 #ifdef DEBUG
792 unimplemented();
793 #endif
794 // function failed
795 AX=0x100;
796 break;
797 default:
798 #ifdef DEBUG
799 unknown();
800 #endif
801 // function failed
802 AX=0x100;
803 }
804 }
805 else {
806 // No VBE display
807 AX=0x0100;
808 }
809 break;
810 #endif
811
812 #ifdef DEBUG
813 default:
814 unknown();
815 #endif
816 }
817 }
818
819 // ============================================================================================
820 //
821 // BIOS functions
822 //
823 // ============================================================================================
824
825 static void biosfn_set_video_mode(mode) Bit8u mode;
826 {// mode: Bit 7 is 1 if no clear screen
827
828 // Should we clear the screen ?
829 Bit8u noclearmem=mode&0x80;
830 Bit8u line,mmask,*palette,vpti;
831 Bit16u i,twidth,theightm1,cheight;
832 Bit8u modeset_ctl,video_ctl,vga_switches;
833 Bit16u crtc_addr;
834
835 #ifdef VBE
836 if (vbe_has_vbe_display()) {
837 dispi_set_enable(VBE_DISPI_DISABLED);
838 }
839 #endif // def VBE
840
841 // The real mode
842 mode=mode&0x7f;
843
844 // find the entry in the video modes
845 line=find_vga_entry(mode);
846
847 #ifdef DEBUG
848 printf("mode search %02x found line %02x\n",mode,line);
849 #endif
850
851 if(line==0xFF)
852 return;
853
854 vpti=line_to_vpti[line];
855 twidth=video_param_table[vpti].twidth;
856 theightm1=video_param_table[vpti].theightm1;
857 cheight=video_param_table[vpti].cheight;
858
859 // Read the bios vga control
860 video_ctl=read_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL);
861
862 // Read the bios vga switches
863 vga_switches=read_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES);
864
865 // Read the bios mode set control
866 modeset_ctl=read_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL);
867
868 // Then we know the number of lines
869 // FIXME
870
871 // if palette loading (bit 3 of modeset ctl = 0)
872 if((modeset_ctl&0x08)==0)
873 {// Set the PEL mask
874 outb(VGAREG_PEL_MASK,vga_modes[line].pelmask);
875
876 // Set the whole dac always, from 0
877 outb(VGAREG_DAC_WRITE_ADDRESS,0x00);
878
879 // From which palette
880 switch(vga_modes[line].dacmodel)
881 {case 0:
882 palette=&palette0;
883 break;
884 case 1:
885 palette=&palette1;
886 break;
887 case 2:
888 palette=&palette2;
889 break;
890 case 3:
891 palette=&palette3;
892 break;
893 }
894 // Always 256*3 values
895 for(i=0;i<0x0100;i++)
896 {if(i<=dac_regs[vga_modes[line].dacmodel])
897 {outb(VGAREG_DAC_DATA,palette[(i*3)+0]);
898 outb(VGAREG_DAC_DATA,palette[(i*3)+1]);
899 outb(VGAREG_DAC_DATA,palette[(i*3)+2]);
900 }
901 else
902 {outb(VGAREG_DAC_DATA,0);
903 outb(VGAREG_DAC_DATA,0);
904 outb(VGAREG_DAC_DATA,0);
905 }
906 }
907 if((modeset_ctl&0x02)==0x02)
908 {
909 biosfn_perform_gray_scale_summing(0x00, 0x100);
910 }
911 }
912
913 // Reset Attribute Ctl flip-flop
914 inb(VGAREG_ACTL_RESET);
915
916 // Set Attribute Ctl
917 for(i=0;i<=0x13;i++)
918 {outb(VGAREG_ACTL_ADDRESS,i);
919 outb(VGAREG_ACTL_WRITE_DATA,video_param_table[vpti].actl_regs[i]);
920 }
921 outb(VGAREG_ACTL_ADDRESS,0x14);
922 outb(VGAREG_ACTL_WRITE_DATA,0x00);
923
924 // Set Sequencer Ctl
925 outb(VGAREG_SEQU_ADDRESS,0);
926 outb(VGAREG_SEQU_DATA,0x03);
927 for(i=1;i<=4;i++)
928 {outb(VGAREG_SEQU_ADDRESS,i);
929 outb(VGAREG_SEQU_DATA,video_param_table[vpti].sequ_regs[i - 1]);
930 }
931
932 // Set Grafx Ctl
933 for(i=0;i<=8;i++)
934 {outb(VGAREG_GRDC_ADDRESS,i);
935 outb(VGAREG_GRDC_DATA,video_param_table[vpti].grdc_regs[i]);
936 }
937
938 // Set CRTC address VGA or MDA
939 crtc_addr=vga_modes[line].memmodel==MTEXT?VGAREG_MDA_CRTC_ADDRESS:VGAREG_VGA_CRTC_ADDRESS;
940
941 // Disable CRTC write protection
942 outw(crtc_addr,0x0011);
943 // Set CRTC regs
944 for(i=0;i<=0x18;i++)
945 {outb(crtc_addr,i);
946 outb(crtc_addr+1,video_param_table[vpti].crtc_regs[i]);
947 }
948
949 // Set the misc register
950 outb(VGAREG_WRITE_MISC_OUTPUT,video_param_table[vpti].miscreg);
951
952 // Enable video
953 outb(VGAREG_ACTL_ADDRESS,0x20);
954 inb(VGAREG_ACTL_RESET);
955
956 if(noclearmem==0x00)
957 {
958 if(vga_modes[line].class==TEXT)
959 {
960 memsetw(vga_modes[line].sstart,0,0x0720,0x4000); // 32k
961 }
962 else
963 {
964 if(mode<0x0d)
965 {
966 memsetw(vga_modes[line].sstart,0,0x0000,0x4000); // 32k
967 }
968 else
969 {
970 outb( VGAREG_SEQU_ADDRESS, 0x02 );
971 mmask = inb( VGAREG_SEQU_DATA );
972 outb( VGAREG_SEQU_DATA, 0x0f ); // all planes
973 memsetw(vga_modes[line].sstart,0,0x0000,0x8000); // 64k
974 outb( VGAREG_SEQU_DATA, mmask );
975 }
976 }
977 }
978
979 // Set the BIOS mem
980 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE,mode);
981 write_word(BIOSMEM_SEG,BIOSMEM_NB_COLS,twidth);
982 write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE,*(Bit16u *)&video_param_table[vpti].slength_l);
983 write_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS,crtc_addr);
984 write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS,theightm1);
985 write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT,cheight);
986 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL,(0x60|noclearmem));
987 write_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES,0xF9);
988 write_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL,read_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL)&0x7f);
989
990 // FIXME We nearly have the good tables. to be reworked
991 write_byte(BIOSMEM_SEG,BIOSMEM_DCC_INDEX,0x08); // 8 is VGA should be ok for now
992 write_word(BIOSMEM_SEG,BIOSMEM_VS_POINTER, video_save_pointer_table);
993 write_word(BIOSMEM_SEG,BIOSMEM_VS_POINTER+2, 0xc000);
994
995 // FIXME
996 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MSR,0x00); // Unavailable on vanilla vga, but...
997 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAL,0x00); // Unavailable on vanilla vga, but...
998
999 // Set cursor shape
1000 if(vga_modes[line].class==TEXT)
1001 {
1002 biosfn_set_cursor_shape(0x06,0x07);
1003 }
1004
1005 // Set cursor pos for page 0..7
1006 for(i=0;i<8;i++)
1007 biosfn_set_cursor_pos(i,0x0000);
1008
1009 // Set active page 0
1010 biosfn_set_active_page(0x00);
1011
1012 // Write the fonts in memory
1013 if(vga_modes[line].class==TEXT)
1014 {
1015 ASM_START
1016 ;; copy and activate 8x16 font
1017 mov ax, #0x1104
1018 mov bl, #0x00
1019 int #0x10
1020 mov ax, #0x1103
1021 mov bl, #0x00
1022 int #0x10
1023 ASM_END
1024 }
1025
1026 // Set the ints 0x1F and 0x43
1027 ASM_START
1028 SET_INT_VECTOR(0x1f, #0xC000, #_vgafont8+128*8)
1029 ASM_END
1030
1031 switch(cheight)
1032 {case 8:
1033 ASM_START
1034 SET_INT_VECTOR(0x43, #0xC000, #_vgafont8)
1035 ASM_END
1036 break;
1037 case 14:
1038 ASM_START
1039 SET_INT_VECTOR(0x43, #0xC000, #_vgafont14)
1040 ASM_END
1041 break;
1042 case 16:
1043 ASM_START
1044 SET_INT_VECTOR(0x43, #0xC000, #_vgafont16)
1045 ASM_END
1046 break;
1047 }
1048 }
1049
1050 // --------------------------------------------------------------------------------------------
1051 static void biosfn_set_cursor_shape (CH,CL)
1052 Bit8u CH;Bit8u CL;
1053 {Bit16u cheight,curs,crtc_addr;
1054 Bit8u modeset_ctl;
1055
1056 CH&=0x3f;
1057 CL&=0x1f;
1058
1059 curs=(CH<<8)+CL;
1060 write_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE,curs);
1061
1062 modeset_ctl=read_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL);
1063 cheight = read_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT);
1064 if((modeset_ctl&0x01) && (cheight>8) && (CL<8) && (CH<0x20))
1065 {
1066 if(CL!=(CH+1))
1067 {
1068 CH = ((CH+1) * cheight / 8) -1;
1069 }
1070 else
1071 {
1072 CH = ((CL+1) * cheight / 8) - 2;
1073 }
1074 CL = ((CL+1) * cheight / 8) - 1;
1075 }
1076
1077 // CTRC regs 0x0a and 0x0b
1078 crtc_addr=read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS);
1079 outb(crtc_addr,0x0a);
1080 outb(crtc_addr+1,CH);
1081 outb(crtc_addr,0x0b);
1082 outb(crtc_addr+1,CL);
1083 }
1084
1085 // --------------------------------------------------------------------------------------------
1086 static void biosfn_set_cursor_pos (page, cursor)
1087 Bit8u page;Bit16u cursor;
1088 {
1089 Bit8u xcurs,ycurs,current;
1090 Bit16u nbcols,nbrows,address,crtc_addr;
1091
1092 // Should not happen...
1093 if(page>7)return;
1094
1095 // Bios cursor pos
1096 write_word(BIOSMEM_SEG, BIOSMEM_CURSOR_POS+2*page, cursor);
1097
1098 // Set the hardware cursor
1099 current=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE);
1100 if(page==current)
1101 {
1102 // Get the dimensions
1103 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1104 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1105
1106 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1107
1108 // Calculate the address knowing nbcols nbrows and page num
1109 address=SCREEN_IO_START(nbcols,nbrows,page)+xcurs+ycurs*nbcols;
1110
1111 // CRTC regs 0x0e and 0x0f
1112 crtc_addr=read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS);
1113 outb(crtc_addr,0x0e);
1114 outb(crtc_addr+1,(address&0xff00)>>8);
1115 outb(crtc_addr,0x0f);
1116 outb(crtc_addr+1,address&0x00ff);
1117 }
1118 }
1119
1120 // --------------------------------------------------------------------------------------------
1121 static void biosfn_get_cursor_pos (page,shape, pos)
1122 Bit8u page;Bit16u *shape;Bit16u *pos;
1123 {
1124 Bit16u ss=get_SS();
1125
1126 // Default
1127 write_word(ss, shape, 0);
1128 write_word(ss, pos, 0);
1129
1130 if(page>7)return;
1131 // FIXME should handle VGA 14/16 lines
1132 write_word(ss,shape,read_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE));
1133 write_word(ss,pos,read_word(BIOSMEM_SEG,BIOSMEM_CURSOR_POS+page*2));
1134 }
1135
1136 // --------------------------------------------------------------------------------------------
1137 static void biosfn_set_active_page (page)
1138 Bit8u page;
1139 {
1140 Bit16u cursor,dummy,crtc_addr;
1141 Bit16u nbcols,nbrows,address;
1142 Bit8u mode,line;
1143
1144 if(page>7)return;
1145
1146 // Get the mode
1147 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1148 line=find_vga_entry(mode);
1149 if(line==0xFF)return;
1150
1151 // Get pos curs pos for the right page
1152 biosfn_get_cursor_pos(page,&dummy,&cursor);
1153
1154 if(vga_modes[line].class==TEXT)
1155 {
1156 // Get the dimensions
1157 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1158 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1159
1160 // Calculate the address knowing nbcols nbrows and page num
1161 address=SCREEN_MEM_START(nbcols,nbrows,page);
1162 write_word(BIOSMEM_SEG,BIOSMEM_CURRENT_START,address);
1163
1164 // Start address
1165 address=SCREEN_IO_START(nbcols,nbrows,page);
1166 }
1167 else
1168 {
1169 address = page * (*(Bit16u *)&video_param_table[line_to_vpti[line]].slength_l);
1170 }
1171
1172 // CRTC regs 0x0c and 0x0d
1173 crtc_addr=read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS);
1174 outb(crtc_addr,0x0c);
1175 outb(crtc_addr+1,(address&0xff00)>>8);
1176 outb(crtc_addr,0x0d);
1177 outb(crtc_addr+1,address&0x00ff);
1178
1179 // And change the BIOS page
1180 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE,page);
1181
1182 #ifdef DEBUG
1183 printf("Set active page %02x address %04x\n",page,address);
1184 #endif
1185
1186 // Display the cursor, now the page is active
1187 biosfn_set_cursor_pos(page,cursor);
1188 }
1189
1190 // --------------------------------------------------------------------------------------------
1191 static void vgamem_copy_pl4(xstart,ysrc,ydest,cols,nbcols,cheight)
1192 Bit8u xstart;Bit8u ysrc;Bit8u ydest;Bit8u cols;Bit8u nbcols;Bit8u cheight;
1193 {
1194 Bit16u src,dest;
1195 Bit8u i;
1196
1197 src=ysrc*cheight*nbcols+xstart;
1198 dest=ydest*cheight*nbcols+xstart;
1199 outw(VGAREG_GRDC_ADDRESS, 0x0105);
1200 for(i=0;i<cheight;i++)
1201 {
1202 memcpyb(0xa000,dest+i*nbcols,0xa000,src+i*nbcols,cols);
1203 }
1204 outw(VGAREG_GRDC_ADDRESS, 0x0005);
1205 }
1206
1207 // --------------------------------------------------------------------------------------------
1208 static void vgamem_fill_pl4(xstart,ystart,cols,nbcols,cheight,attr)
1209 Bit8u xstart;Bit8u ystart;Bit8u cols;Bit8u nbcols;Bit8u cheight;Bit8u attr;
1210 {
1211 Bit16u dest;
1212 Bit8u i;
1213
1214 dest=ystart*cheight*nbcols+xstart;
1215 outw(VGAREG_GRDC_ADDRESS, 0x0205);
1216 for(i=0;i<cheight;i++)
1217 {
1218 memsetb(0xa000,dest+i*nbcols,attr,cols);
1219 }
1220 outw(VGAREG_GRDC_ADDRESS, 0x0005);
1221 }
1222
1223 // --------------------------------------------------------------------------------------------
1224 static void vgamem_copy_cga(xstart,ysrc,ydest,cols,nbcols,cheight)
1225 Bit8u xstart;Bit8u ysrc;Bit8u ydest;Bit8u cols;Bit8u nbcols;Bit8u cheight;
1226 {
1227 Bit16u src,dest;
1228 Bit8u i;
1229
1230 src=((ysrc*cheight*nbcols)>>1)+xstart;
1231 dest=((ydest*cheight*nbcols)>>1)+xstart;
1232 for(i=0;i<cheight;i++)
1233 {
1234 if (i & 1)
1235 memcpyb(0xb800,0x2000+dest+(i>>1)*nbcols,0xb800,0x2000+src+(i>>1)*nbcols,cols);
1236 else
1237 memcpyb(0xb800,dest+(i>>1)*nbcols,0xb800,src+(i>>1)*nbcols,cols);
1238 }
1239 }
1240
1241 // --------------------------------------------------------------------------------------------
1242 static void vgamem_fill_cga(xstart,ystart,cols,nbcols,cheight,attr)
1243 Bit8u xstart;Bit8u ystart;Bit8u cols;Bit8u nbcols;Bit8u cheight;Bit8u attr;
1244 {
1245 Bit16u dest;
1246 Bit8u i;
1247
1248 dest=((ystart*cheight*nbcols)>>1)+xstart;
1249 for(i=0;i<cheight;i++)
1250 {
1251 if (i & 1)
1252 memsetb(0xb800,0x2000+dest+(i>>1)*nbcols,attr,cols);
1253 else
1254 memsetb(0xb800,dest+(i>>1)*nbcols,attr,cols);
1255 }
1256 }
1257
1258 // --------------------------------------------------------------------------------------------
1259 static void biosfn_scroll (nblines,attr,rul,cul,rlr,clr,page,dir)
1260 Bit8u nblines;Bit8u attr;Bit8u rul;Bit8u cul;Bit8u rlr;Bit8u clr;Bit8u page;Bit8u dir;
1261 {
1262 // page == 0xFF if current
1263
1264 Bit8u mode,line,cheight,bpp,cols;
1265 Bit16u nbcols,nbrows,i;
1266 Bit16u address;
1267
1268 if(rul>rlr)return;
1269 if(cul>clr)return;
1270
1271 // Get the mode
1272 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1273 line=find_vga_entry(mode);
1274 if(line==0xFF)return;
1275
1276 // Get the dimensions
1277 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1278 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1279
1280 // Get the current page
1281 if(page==0xFF)
1282 page=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE);
1283
1284 if(rlr>=nbrows)rlr=nbrows-1;
1285 if(clr>=nbcols)clr=nbcols-1;
1286 if(nblines>nbrows)nblines=0;
1287 cols=clr-cul+1;
1288
1289 if(vga_modes[line].class==TEXT)
1290 {
1291 // Compute the address
1292 address=SCREEN_MEM_START(nbcols,nbrows,page);
1293 #ifdef DEBUG
1294 printf("Scroll, address %04x (%04x %04x %02x)\n",address,nbrows,nbcols,page);
1295 #endif
1296
1297 if(nblines==0&&rul==0&&cul==0&&rlr==nbrows-1&&clr==nbcols-1)
1298 {
1299 memsetw(vga_modes[line].sstart,address,(Bit16u)attr*0x100+' ',nbrows*nbcols);
1300 }
1301 else
1302 {// if Scroll up
1303 if(dir==SCROLL_UP)
1304 {for(i=rul;i<=rlr;i++)
1305 {
1306 if((i+nblines>rlr)||(nblines==0))
1307 memsetw(vga_modes[line].sstart,address+(i*nbcols+cul)*2,(Bit16u)attr*0x100+' ',cols);
1308 else
1309 memcpyw(vga_modes[line].sstart,address+(i*nbcols+cul)*2,vga_modes[line].sstart,((i+nblines)*nbcols+cul)*2,cols);
1310 }
1311 }
1312 else
1313 {for(i=rlr;i>=rul;i--)
1314 {
1315 if((i<rul+nblines)||(nblines==0))
1316 memsetw(vga_modes[line].sstart,address+(i*nbcols+cul)*2,(Bit16u)attr*0x100+' ',cols);
1317 else
1318 memcpyw(vga_modes[line].sstart,address+(i*nbcols+cul)*2,vga_modes[line].sstart,((i-nblines)*nbcols+cul)*2,cols);
1319 if (i>rlr) break;
1320 }
1321 }
1322 }
1323 }
1324 else
1325 {
1326 // FIXME gfx mode not complete
1327 cheight=video_param_table[line_to_vpti[line]].cheight;
1328 switch(vga_modes[line].memmodel)
1329 {
1330 case PLANAR4:
1331 case PLANAR1:
1332 if(nblines==0&&rul==0&&cul==0&&rlr==nbrows-1&&clr==nbcols-1)
1333 {
1334 outw(VGAREG_GRDC_ADDRESS, 0x0205);
1335 memsetb(vga_modes[line].sstart,0,attr,nbrows*nbcols*cheight);
1336 outw(VGAREG_GRDC_ADDRESS, 0x0005);
1337 }
1338 else
1339 {// if Scroll up
1340 if(dir==SCROLL_UP)
1341 {for(i=rul;i<=rlr;i++)
1342 {
1343 if((i+nblines>rlr)||(nblines==0))
1344 vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
1345 else
1346 vgamem_copy_pl4(cul,i+nblines,i,cols,nbcols,cheight);
1347 }
1348 }
1349 else
1350 {for(i=rlr;i>=rul;i--)
1351 {
1352 if((i<rul+nblines)||(nblines==0))
1353 vgamem_fill_pl4(cul,i,cols,nbcols,cheight,attr);
1354 else
1355 vgamem_copy_pl4(cul,i,i-nblines,cols,nbcols,cheight);
1356 if (i>rlr) break;
1357 }
1358 }
1359 }
1360 break;
1361 case CGA:
1362 bpp=vga_modes[line].pixbits;
1363 if(nblines==0&&rul==0&&cul==0&&rlr==nbrows-1&&clr==nbcols-1)
1364 {
1365 memsetb(vga_modes[line].sstart,0,attr,nbrows*nbcols*cheight*bpp);
1366 }
1367 else
1368 {
1369 if(bpp==2)
1370 {
1371 cul<<=1;
1372 cols<<=1;
1373 nbcols<<=1;
1374 }
1375 // if Scroll up
1376 if(dir==SCROLL_UP)
1377 {for(i=rul;i<=rlr;i++)
1378 {
1379 if((i+nblines>rlr)||(nblines==0))
1380 vgamem_fill_cga(cul,i,cols,nbcols,cheight,attr);
1381 else
1382 vgamem_copy_cga(cul,i+nblines,i,cols,nbcols,cheight);
1383 }
1384 }
1385 else
1386 {for(i=rlr;i>=rul;i--)
1387 {
1388 if((i<rul+nblines)||(nblines==0))
1389 vgamem_fill_cga(cul,i,cols,nbcols,cheight,attr);
1390 else
1391 vgamem_copy_cga(cul,i,i-nblines,cols,nbcols,cheight);
1392 if (i>rlr) break;
1393 }
1394 }
1395 }
1396 break;
1397 #ifdef DEBUG
1398 default:
1399 printf("Scroll in graphics mode ");
1400 unimplemented();
1401 #endif
1402 }
1403 }
1404 }
1405
1406 // --------------------------------------------------------------------------------------------
1407 static void biosfn_read_char_attr (page,car)
1408 Bit8u page;Bit16u *car;
1409 {Bit16u ss=get_SS();
1410 Bit8u xcurs,ycurs,mode,line;
1411 Bit16u nbcols,nbrows,address;
1412 Bit16u cursor,dummy;
1413
1414 // Get the mode
1415 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1416 line=find_vga_entry(mode);
1417 if(line==0xFF)return;
1418
1419 // Get the cursor pos for the page
1420 biosfn_get_cursor_pos(page,&dummy,&cursor);
1421 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1422
1423 // Get the dimensions
1424 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1425 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1426
1427 if(vga_modes[line].class==TEXT)
1428 {
1429 // Compute the address
1430 address=SCREEN_MEM_START(nbcols,nbrows,page)+(xcurs+ycurs*nbcols)*2;
1431
1432 write_word(ss,car,read_word(vga_modes[line].sstart,address));
1433 }
1434 else
1435 {
1436 // FIXME gfx mode
1437 #ifdef DEBUG
1438 unimplemented();
1439 #endif
1440 }
1441 }
1442
1443 // --------------------------------------------------------------------------------------------
1444 static void write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight)
1445 Bit8u car;Bit8u attr;Bit8u xcurs;Bit8u ycurs;Bit8u nbcols;Bit8u cheight;
1446 {
1447 Bit8u i,j,mask;
1448 Bit8u *fdata;
1449 Bit16u addr,dest,src;
1450
1451 switch(cheight)
1452 {case 14:
1453 fdata = &vgafont14;
1454 break;
1455 case 16:
1456 fdata = &vgafont16;
1457 break;
1458 default:
1459 fdata = &vgafont8;
1460 }
1461 addr=xcurs+ycurs*cheight*nbcols;
1462 src = car * cheight;
1463 outw(VGAREG_SEQU_ADDRESS, 0x0f02);
1464 outw(VGAREG_GRDC_ADDRESS, 0x0205);
1465 if(attr&0x80)
1466 {
1467 outw(VGAREG_GRDC_ADDRESS, 0x1803);
1468 }
1469 else
1470 {
1471 outw(VGAREG_GRDC_ADDRESS, 0x0003);
1472 }
1473 for(i=0;i<cheight;i++)
1474 {
1475 dest=addr+i*nbcols;
1476 for(j=0;j<8;j++)
1477 {
1478 mask=0x80>>j;
1479 outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
1480 read_byte(0xa000,dest);
1481 if(fdata[src+i]&mask)
1482 {
1483 write_byte(0xa000,dest,attr&0x0f);
1484 }
1485 else
1486 {
1487 write_byte(0xa000,dest,0x00);
1488 }
1489 }
1490 }
1491 ASM_START
1492 mov dx, # VGAREG_GRDC_ADDRESS
1493 mov ax, #0xff08
1494 out dx, ax
1495 mov ax, #0x0005
1496 out dx, ax
1497 mov ax, #0x0003
1498 out dx, ax
1499 ASM_END
1500 }
1501
1502 // --------------------------------------------------------------------------------------------
1503 static void write_gfx_char_cga(car,attr,xcurs,ycurs,nbcols,bpp)
1504 Bit8u car;Bit8u attr;Bit8u xcurs;Bit8u ycurs;Bit8u nbcols;Bit8u bpp;
1505 {
1506 Bit8u i,j,mask,data;
1507 Bit8u *fdata;
1508 Bit16u addr,dest,src;
1509
1510 fdata = &vgafont8;
1511 addr=(xcurs*bpp)+ycurs*320;
1512 src = car * 8;
1513 for(i=0;i<8;i++)
1514 {
1515 dest=addr+(i>>1)*80;
1516 if (i & 1) dest += 0x2000;
1517 mask = 0x80;
1518 if (bpp == 1)
1519 {
1520 if (attr & 0x80)
1521 {
1522 data = read_byte(0xb800,dest);
1523 }
1524 else
1525 {
1526 data = 0x00;
1527 }
1528 for(j=0;j<8;j++)
1529 {
1530 if (fdata[src+i] & mask)
1531 {
1532 if (attr & 0x80)
1533 {
1534 data ^= (attr & 0x01) << (7-j);
1535 }
1536 else
1537 {
1538 data |= (attr & 0x01) << (7-j);
1539 }
1540 }
1541 mask >>= 1;
1542 }
1543 write_byte(0xb800,dest,data);
1544 }
1545 else
1546 {
1547 while (mask > 0)
1548 {
1549 if (attr & 0x80)
1550 {
1551 data = read_byte(0xb800,dest);
1552 }
1553 else
1554 {
1555 data = 0x00;
1556 }
1557 for(j=0;j<4;j++)
1558 {
1559 if (fdata[src+i] & mask)
1560 {
1561 if (attr & 0x80)
1562 {
1563 data ^= (attr & 0x03) << ((3-j)*2);
1564 }
1565 else
1566 {
1567 data |= (attr & 0x03) << ((3-j)*2);
1568 }
1569 }
1570 mask >>= 1;
1571 }
1572 write_byte(0xb800,dest,data);
1573 dest += 1;
1574 }
1575 }
1576 }
1577 }
1578
1579 // --------------------------------------------------------------------------------------------
1580 static void write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols)
1581 Bit8u car;Bit8u attr;Bit8u xcurs;Bit8u ycurs;Bit8u nbcols;
1582 {
1583 Bit8u i,j,mask,data;
1584 Bit8u *fdata;
1585 Bit16u addr,dest,src;
1586
1587 fdata = &vgafont8;
1588 addr=xcurs*8+ycurs*nbcols*64;
1589 src = car * 8;
1590 for(i=0;i<8;i++)
1591 {
1592 dest=addr+i*nbcols*8;
1593 mask = 0x80;
1594 for(j=0;j<8;j++)
1595 {
1596 data = 0x00;
1597 if (fdata[src+i] & mask)
1598 {
1599 data = attr;
1600 }
1601 write_byte(0xa000,dest+j,data);
1602 mask >>= 1;
1603 }
1604 }
1605 }
1606
1607 // --------------------------------------------------------------------------------------------
1608 static void biosfn_write_char_attr (car,page,attr,count)
1609 Bit8u car;Bit8u page;Bit8u attr;Bit16u count;
1610 {
1611 Bit8u cheight,xcurs,ycurs,mode,line,bpp;
1612 Bit16u nbcols,nbrows,address;
1613 Bit16u cursor,dummy;
1614
1615 // Get the mode
1616 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1617 line=find_vga_entry(mode);
1618 if(line==0xFF)return;
1619
1620 // Get the cursor pos for the page
1621 biosfn_get_cursor_pos(page,&dummy,&cursor);
1622 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1623
1624 // Get the dimensions
1625 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1626 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1627
1628 if(vga_modes[line].class==TEXT)
1629 {
1630 // Compute the address
1631 address=SCREEN_MEM_START(nbcols,nbrows,page)+(xcurs+ycurs*nbcols)*2;
1632
1633 dummy=((Bit16u)attr<<8)+car;
1634 memsetw(vga_modes[line].sstart,address,dummy,count);
1635 }
1636 else
1637 {
1638 // FIXME gfx mode not complete
1639 cheight=video_param_table[line_to_vpti[line]].cheight;
1640 bpp=vga_modes[line].pixbits;
1641 while((count-->0) && (xcurs<nbcols))
1642 {
1643 switch(vga_modes[line].memmodel)
1644 {
1645 case PLANAR4:
1646 case PLANAR1:
1647 write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
1648 break;
1649 case CGA:
1650 write_gfx_char_cga(car,attr,xcurs,ycurs,nbcols,bpp);
1651 break;
1652 case LINEAR8:
1653 write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
1654 break;
1655 #ifdef DEBUG
1656 default:
1657 unimplemented();
1658 #endif
1659 }
1660 xcurs++;
1661 }
1662 }
1663 }
1664
1665 // --------------------------------------------------------------------------------------------
1666 static void biosfn_write_char_only (car,page,attr,count)
1667 Bit8u car;Bit8u page;Bit8u attr;Bit16u count;
1668 {
1669 Bit8u cheight,xcurs,ycurs,mode,line,bpp;
1670 Bit16u nbcols,nbrows,address;
1671 Bit16u cursor,dummy;
1672
1673 // Get the mode
1674 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1675 line=find_vga_entry(mode);
1676 if(line==0xFF)return;
1677
1678 // Get the cursor pos for the page
1679 biosfn_get_cursor_pos(page,&dummy,&cursor);
1680 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1681
1682 // Get the dimensions
1683 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1684 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1685
1686 if(vga_modes[line].class==TEXT)
1687 {
1688 // Compute the address
1689 address=SCREEN_MEM_START(nbcols,nbrows,page)+(xcurs+ycurs*nbcols)*2;
1690
1691 while(count-->0)
1692 {write_byte(vga_modes[line].sstart,address,car);
1693 address+=2;
1694 }
1695 }
1696 else
1697 {
1698 // FIXME gfx mode not complete
1699 cheight=video_param_table[line_to_vpti[line]].cheight;
1700 bpp=vga_modes[line].pixbits;
1701 while((count-->0) && (xcurs<nbcols))
1702 {
1703 switch(vga_modes[line].memmodel)
1704 {
1705 case PLANAR4:
1706 case PLANAR1:
1707 write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
1708 break;
1709 case CGA:
1710 write_gfx_char_cga(car,attr,xcurs,ycurs,nbcols,bpp);
1711 break;
1712 case LINEAR8:
1713 write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
1714 break;
1715 #ifdef DEBUG
1716 default:
1717 unimplemented();
1718 #endif
1719 }
1720 xcurs++;
1721 }
1722 }
1723 }
1724
1725 // --------------------------------------------------------------------------------------------
1726 ASM_START
1727 biosfn_group_0B:
1728 cmp bh, #0x00
1729 je biosfn_set_border_color
1730 cmp bh, #0x01
1731 je biosfn_set_palette
1732 #ifdef DEBUG
1733 call _unknown
1734 #endif
1735 ret
1736 biosfn_set_border_color:
1737 push ax
1738 push bx
1739 push cx
1740 push dx
1741 mov dx, # VGAREG_ACTL_RESET
1742 in al, dx
1743 mov dx, # VGAREG_ACTL_ADDRESS
1744 mov al, #0x00
1745 out dx, al
1746 mov al, bl
1747 and al, #0x0f
1748 test al, #0x08
1749 jz set_low_border
1750 add al, #0x08
1751 set_low_border:
1752 out dx, al
1753 mov cl, #0x01
1754 and bl, #0x10
1755 set_intensity_loop:
1756 mov dx, # VGAREG_ACTL_ADDRESS
1757 mov al, cl
1758 out dx, al
1759 mov dx, # VGAREG_ACTL_READ_DATA
1760 in al, dx
1761 and al, #0xef
1762 or al, bl
1763 mov dx, # VGAREG_ACTL_ADDRESS
1764 out dx, al
1765 inc cl
1766 cmp cl, #0x04
1767 jne set_intensity_loop
1768 mov al, #0x20
1769 out dx, al
1770 pop dx
1771 pop cx
1772 pop bx
1773 pop ax
1774 ret
1775 biosfn_set_palette:
1776 push ax
1777 push bx
1778 push cx
1779 push dx
1780 mov dx, # VGAREG_ACTL_RESET
1781 in al, dx
1782 mov cl, #0x01
1783 and bl, #0x01
1784 set_cga_palette_loop:
1785 mov dx, # VGAREG_ACTL_ADDRESS
1786 mov al, cl
1787 out dx, al
1788 mov dx, # VGAREG_ACTL_READ_DATA
1789 in al, dx
1790 and al, #0xfe
1791 or al, bl
1792 mov dx, # VGAREG_ACTL_ADDRESS
1793 out dx, al
1794 inc cl
1795 cmp cl, #0x04
1796 jne set_cga_palette_loop
1797 mov al, #0x20
1798 out dx, al
1799 pop dx
1800 pop cx
1801 pop bx
1802 pop ax
1803 ret
1804 ASM_END
1805
1806 // --------------------------------------------------------------------------------------------
1807 static void biosfn_write_pixel (BH,AL,CX,DX) Bit8u BH;Bit8u AL;Bit16u CX;Bit16u DX;
1808 {
1809 Bit8u mode,line,mask,attr,data;
1810 Bit16u addr;
1811
1812 // Get the mode
1813 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1814 line=find_vga_entry(mode);
1815 if(line==0xFF)return;
1816 if(vga_modes[line].class==TEXT)return;
1817
1818 switch(vga_modes[line].memmodel)
1819 {
1820 case PLANAR4:
1821 case PLANAR1:
1822 addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1823 mask = 0x80 >> (CX & 0x07);
1824 outw(VGAREG_GRDC_ADDRESS, (mask << 8) | 0x08);
1825 outw(VGAREG_GRDC_ADDRESS, 0x0205);
1826 data = read_byte(0xa000,addr);
1827 if (AL & 0x80)
1828 {
1829 outw(VGAREG_GRDC_ADDRESS, 0x1803);
1830 }
1831 write_byte(0xa000,addr,AL);
1832 ASM_START
1833 mov dx, # VGAREG_GRDC_ADDRESS
1834 mov ax, #0xff08
1835 out dx, ax
1836 mov ax, #0x0005
1837 out dx, ax
1838 mov ax, #0x0003
1839 out dx, ax
1840 ASM_END
1841 break;
1842 case CGA:
1843 if(vga_modes[line].pixbits==2)
1844 {
1845 addr=(CX>>2)+(DX>>1)*80;
1846 }
1847 else
1848 {
1849 addr=(CX>>3)+(DX>>1)*80;
1850 }
1851 if (DX & 1) addr += 0x2000;
1852 data = read_byte(0xb800,addr);
1853 if(vga_modes[line].pixbits==2)
1854 {
1855 attr = (AL & 0x03) << ((3 - (CX & 0x03)) * 2);
1856 mask = 0x03 << ((3 - (CX & 0x03)) * 2);
1857 }
1858 else
1859 {
1860 attr = (AL & 0x01) << (7 - (CX & 0x07));
1861 mask = 0x01 << (7 - (CX & 0x07));
1862 }
1863 if (AL & 0x80)
1864 {
1865 data ^= attr;
1866 }
1867 else
1868 {
1869 data &= ~mask;
1870 data |= attr;
1871 }
1872 write_byte(0xb800,addr,data);
1873 break;
1874 case LINEAR8:
1875 addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
1876 write_byte(0xa000,addr,AL);
1877 break;
1878 #ifdef DEBUG
1879 default:
1880 unimplemented();
1881 #endif
1882 }
1883 }
1884
1885 // --------------------------------------------------------------------------------------------
1886 static void biosfn_read_pixel (BH,CX,DX,AX) Bit8u BH;Bit16u CX;Bit16u DX;Bit16u *AX;
1887 {
1888 Bit8u mode,line,mask,attr,data,i;
1889 Bit16u addr;
1890 Bit16u ss=get_SS();
1891
1892 // Get the mode
1893 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1894 line=find_vga_entry(mode);
1895 if(line==0xFF)return;
1896 if(vga_modes[line].class==TEXT)return;
1897
1898 switch(vga_modes[line].memmodel)
1899 {
1900 case PLANAR4:
1901 case PLANAR1:
1902 addr = CX/8+DX*read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1903 mask = 0x80 >> (CX & 0x07);
1904 attr = 0x00;
1905 for(i=0;i<4;i++)
1906 {
1907 outw(VGAREG_GRDC_ADDRESS, (i << 8) | 0x04);
1908 data = read_byte(0xa000,addr) & mask;
1909 if (data > 0) attr |= (0x01 << i);
1910 }
1911 break;
1912 case CGA:
1913 addr=(CX>>2)+(DX>>1)*80;
1914 if (DX & 1) addr += 0x2000;
1915 data = read_byte(0xb800,addr);
1916 if(vga_modes[line].pixbits==2)
1917 {
1918 attr = (data >> ((3 - (CX & 0x03)) * 2)) & 0x03;
1919 }
1920 else
1921 {
1922 attr = (data >> (7 - (CX & 0x07))) & 0x01;
1923 }
1924 break;
1925 case LINEAR8:
1926 addr=CX+DX*(read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)*8);
1927 attr=read_byte(0xa000,addr);
1928 break;
1929 default:
1930 #ifdef DEBUG
1931 unimplemented();
1932 #endif
1933 attr = 0;
1934 }
1935 write_word(ss,AX,(read_word(ss,AX) & 0xff00) | attr);
1936 }
1937
1938 // --------------------------------------------------------------------------------------------
1939 static void biosfn_write_teletype (car, page, attr, flag)
1940 Bit8u car;Bit8u page;Bit8u attr;Bit8u flag;
1941 {// flag = WITH_ATTR / NO_ATTR
1942
1943 Bit8u cheight,xcurs,ycurs,mode,line,bpp;
1944 Bit16u nbcols,nbrows,address;
1945 Bit16u cursor,dummy;
1946
1947 // special case if page is 0xff, use current page
1948 if(page==0xff)
1949 page=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE);
1950
1951 // Get the mode
1952 mode=read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE);
1953 line=find_vga_entry(mode);
1954 if(line==0xFF)return;
1955
1956 // Get the cursor pos for the page
1957 biosfn_get_cursor_pos(page,&dummy,&cursor);
1958 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1959
1960 // Get the dimensions
1961 nbrows=read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)+1;
1962 nbcols=read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
1963
1964 switch(car)
1965 {
1966 case 7:
1967 //FIXME should beep
1968 break;
1969
1970 case 8:
1971 if(xcurs>0)xcurs--;
1972 break;
1973
1974 case '\r':
1975 xcurs=0;
1976 break;
1977
1978 case '\n':
1979 ycurs++;
1980 break;
1981
1982 case '\t':
1983 do
1984 {
1985 biosfn_write_teletype(' ',page,attr,flag);
1986 biosfn_get_cursor_pos(page,&dummy,&cursor);
1987 xcurs=cursor&0x00ff;ycurs=(cursor&0xff00)>>8;
1988 }while(xcurs%8==0);
1989 break;
1990
1991 default:
1992
1993 if(vga_modes[line].class==TEXT)
1994 {
1995 // Compute the address
1996 address=SCREEN_MEM_START(nbcols,nbrows,page)+(xcurs+ycurs*nbcols)*2;
1997
1998 // Write the char
1999 write_byte(vga_modes[line].sstart,address,car);
2000
2001 if(flag==WITH_ATTR)
2002 write_byte(vga_modes[line].sstart,address+1,attr);
2003 }
2004 else
2005 {
2006 // FIXME gfx mode not complete
2007 cheight=video_param_table[line_to_vpti[line]].cheight;
2008 bpp=vga_modes[line].pixbits;
2009 switch(vga_modes[line].memmodel)
2010 {
2011 case PLANAR4:
2012 case PLANAR1:
2013 write_gfx_char_pl4(car,attr,xcurs,ycurs,nbcols,cheight);
2014 break;
2015 case CGA:
2016 write_gfx_char_cga(car,attr,xcurs,ycurs,nbcols,bpp);
2017 break;
2018 case LINEAR8:
2019 write_gfx_char_lin(car,attr,xcurs,ycurs,nbcols);
2020 break;
2021 #ifdef DEBUG
2022 default:
2023 unimplemented();
2024 #endif
2025 }
2026 }
2027 xcurs++;
2028 }
2029
2030 // Do we need to wrap ?
2031 if(xcurs==nbcols)
2032 {xcurs=0;
2033 ycurs++;
2034 }
2035
2036 // Do we need to scroll ?
2037 if(ycurs==nbrows)
2038 {
2039 if(vga_modes[line].class==TEXT)
2040 {
2041 biosfn_scroll(0x01,0x07,0,0,nbrows-1,nbcols-1,page,SCROLL_UP);
2042 }
2043 else
2044 {
2045 biosfn_scroll(0x01,0x00,0,0,nbrows-1,nbcols-1,page,SCROLL_UP);
2046 }
2047 ycurs-=1;
2048 }
2049
2050 // Set the cursor for the page
2051 cursor=ycurs; cursor<<=8; cursor+=xcurs;
2052 biosfn_set_cursor_pos(page,cursor);
2053 }
2054
2055 // --------------------------------------------------------------------------------------------
2056 ASM_START
2057 biosfn_get_video_mode:
2058 push ds
2059 mov ax, # BIOSMEM_SEG
2060 mov ds, ax
2061 push bx
2062 mov bx, # BIOSMEM_CURRENT_PAGE
2063 mov al, [bx]
2064 pop bx
2065 mov bh, al
2066 push bx
2067 mov bx, # BIOSMEM_VIDEO_CTL
2068 mov ah, [bx]
2069 and ah, #0x80
2070 mov bx, # BIOSMEM_CURRENT_MODE
2071 mov al, [bx]
2072 or al, ah
2073 mov bx, # BIOSMEM_NB_COLS
2074 mov ah, [bx]
2075 pop bx
2076 pop ds
2077 ret
2078 ASM_END
2079
2080 // --------------------------------------------------------------------------------------------
2081 ASM_START
2082 biosfn_group_10:
2083 cmp al, #0x00
2084 jne int10_test_1001
2085 jmp biosfn_set_single_palette_reg
2086 int10_test_1001:
2087 cmp al, #0x01
2088 jne int10_test_1002
2089 jmp biosfn_set_overscan_border_color
2090 int10_test_1002:
2091 cmp al, #0x02
2092 jne int10_test_1003
2093 jmp biosfn_set_all_palette_reg
2094 int10_test_1003:
2095 cmp al, #0x03
2096 jne int10_test_1007
2097 jmp biosfn_toggle_intensity
2098 int10_test_1007:
2099 cmp al, #0x07
2100 jne int10_test_1008
2101 jmp biosfn_get_single_palette_reg
2102 int10_test_1008:
2103 cmp al, #0x08
2104 jne int10_test_1009
2105 jmp biosfn_read_overscan_border_color
2106 int10_test_1009:
2107 cmp al, #0x09
2108 jne int10_test_1010
2109 jmp biosfn_get_all_palette_reg
2110 int10_test_1010:
2111 cmp al, #0x10
2112 jne int10_test_1012
2113 jmp biosfn_set_single_dac_reg
2114 int10_test_1012:
2115 cmp al, #0x12
2116 jne int10_test_1013
2117 jmp biosfn_set_all_dac_reg
2118 int10_test_1013:
2119 cmp al, #0x13
2120 jne int10_test_1015
2121 jmp biosfn_select_video_dac_color_page
2122 int10_test_1015:
2123 cmp al, #0x15
2124 jne int10_test_1017
2125 jmp biosfn_read_single_dac_reg
2126 int10_test_1017:
2127 cmp al, #0x17
2128 jne int10_test_1018
2129 jmp biosfn_read_all_dac_reg
2130 int10_test_1018:
2131 cmp al, #0x18
2132 jne int10_test_1019
2133 jmp biosfn_set_pel_mask
2134 int10_test_1019:
2135 cmp al, #0x19
2136 jne int10_test_101A
2137 jmp biosfn_read_pel_mask
2138 int10_test_101A:
2139 cmp al, #0x1a
2140 jne int10_group_10_unknown
2141 jmp biosfn_read_video_dac_state
2142 int10_group_10_unknown:
2143 #ifdef DEBUG
2144 call _unknown
2145 #endif
2146 ret
2147
2148 biosfn_set_single_palette_reg:
2149 cmp bl, #0x14
2150 ja no_actl_reg1
2151 push ax
2152 push dx
2153 mov dx, # VGAREG_ACTL_RESET
2154 in al, dx
2155 mov dx, # VGAREG_ACTL_ADDRESS
2156 mov al, bl
2157 out dx, al
2158 mov al, bh
2159 out dx, al
2160 mov al, #0x20
2161 out dx, al
2162 pop dx
2163 pop ax
2164 no_actl_reg1:
2165 ret
2166 ASM_END
2167
2168 // --------------------------------------------------------------------------------------------
2169 ASM_START
2170 biosfn_set_overscan_border_color:
2171 push bx
2172 mov bl, #0x11
2173 call biosfn_set_single_palette_reg
2174 pop bx
2175 ret
2176 ASM_END
2177
2178 // --------------------------------------------------------------------------------------------
2179 ASM_START
2180 biosfn_set_all_palette_reg:
2181 push ax
2182 push bx
2183 push cx
2184 push dx
2185 mov bx, dx
2186 mov dx, # VGAREG_ACTL_RESET
2187 in al, dx
2188 mov cl, #0x00
2189 mov dx, # VGAREG_ACTL_ADDRESS
2190 set_palette_loop:
2191 mov al, cl
2192 out dx, al
2193 seg es
2194 mov al, [bx]
2195 out dx, al
2196 inc bx
2197 inc cl
2198 cmp cl, #0x10
2199 jne set_palette_loop
2200 mov al, #0x11
2201 out dx, al
2202 seg es
2203 mov al, [bx]
2204 out dx, al
2205 mov al, #0x20
2206 out dx, al
2207 pop dx
2208 pop cx
2209 pop bx
2210 pop ax
2211 ret
2212 ASM_END
2213
2214 // --------------------------------------------------------------------------------------------
2215 ASM_START
2216 biosfn_toggle_intensity:
2217 push ax
2218 push bx
2219 push dx
2220 mov dx, # VGAREG_ACTL_RESET
2221 in al, dx
2222 mov dx, # VGAREG_ACTL_ADDRESS
2223 mov al, #0x10
2224 out dx, al
2225 mov dx, # VGAREG_ACTL_READ_DATA
2226 in al, dx
2227 and al, #0xf7
2228 and bl, #0x01
2229 shl bl, 3
2230 or al, bl
2231 mov dx, # VGAREG_ACTL_ADDRESS
2232 out dx, al
2233 mov al, #0x20
2234 out dx, al
2235 pop dx
2236 pop bx
2237 pop ax
2238 ret
2239 ASM_END
2240
2241 // --------------------------------------------------------------------------------------------
2242 ASM_START
2243 biosfn_get_single_palette_reg:
2244 cmp bl, #0x14
2245 ja no_actl_reg2
2246 push ax
2247 push dx
2248 mov dx, # VGAREG_ACTL_RESET
2249 in al, dx
2250 mov dx, # VGAREG_ACTL_ADDRESS
2251 mov al, bl
2252 out dx, al
2253 mov dx, # VGAREG_ACTL_READ_DATA
2254 in al, dx
2255 mov bh, al
2256 mov dx, # VGAREG_ACTL_RESET
2257 in al, dx
2258 mov dx, # VGAREG_ACTL_ADDRESS
2259 mov al, #0x20
2260 out dx, al
2261 pop dx
2262 pop ax
2263 no_actl_reg2:
2264 ret
2265 ASM_END
2266
2267 // --------------------------------------------------------------------------------------------
2268 ASM_START
2269 biosfn_read_overscan_border_color:
2270 push ax
2271 push bx
2272 mov bl, #0x11
2273 call biosfn_get_single_palette_reg
2274 mov al, bh
2275 pop bx
2276 mov bh, al
2277 pop ax
2278 ret
2279 ASM_END
2280
2281 // --------------------------------------------------------------------------------------------
2282 ASM_START
2283 biosfn_get_all_palette_reg:
2284 push ax
2285 push bx
2286 push cx
2287 push dx
2288 mov bx, dx
2289 mov cl, #0x00
2290 get_palette_loop:
2291 mov dx, # VGAREG_ACTL_RESET
2292 in al, dx
2293 mov dx, # VGAREG_ACTL_ADDRESS
2294 mov al, cl
2295 out dx, al
2296 mov dx, # VGAREG_ACTL_READ_DATA
2297 in al, dx
2298 seg es
2299 mov [bx], al
2300 inc bx
2301 inc cl
2302 cmp cl, #0x10
2303 jne get_palette_loop
2304 mov dx, # VGAREG_ACTL_RESET
2305 in al, dx
2306 mov dx, # VGAREG_ACTL_ADDRESS
2307 mov al, #0x11
2308 out dx, al
2309 mov dx, # VGAREG_ACTL_READ_DATA
2310 in al, dx
2311 seg es
2312 mov [bx], al
2313 mov dx, # VGAREG_ACTL_RESET
2314 in al, dx
2315 mov dx, # VGAREG_ACTL_ADDRESS
2316 mov al, #0x20
2317 out dx, al
2318 pop dx
2319 pop cx
2320 pop bx
2321 pop ax
2322 ret
2323 ASM_END
2324
2325 // --------------------------------------------------------------------------------------------
2326 ASM_START
2327 biosfn_set_single_dac_reg:
2328 push ax
2329 push dx
2330 mov dx, # VGAREG_DAC_WRITE_ADDRESS
2331 mov al, bl
2332 out dx, al
2333 mov dx, # VGAREG_DAC_DATA
2334 pop ax
2335 push ax
2336 mov al, ah
2337 out dx, al
2338 mov al, ch
2339 out dx, al
2340 mov al, cl
2341 out dx, al
2342 pop dx
2343 pop ax
2344 ret
2345 ASM_END
2346
2347 // --------------------------------------------------------------------------------------------
2348 ASM_START
2349 biosfn_set_all_dac_reg:
2350 push ax
2351 push bx
2352 push cx
2353 push dx
2354 mov dx, # VGAREG_DAC_WRITE_ADDRESS
2355 mov al, bl
2356 out dx, al
2357 pop dx
2358 push dx
2359 mov bx, dx
2360 mov dx, # VGAREG_DAC_DATA
2361 set_dac_loop:
2362 seg es
2363 mov al, [bx]
2364 out dx, al
2365 inc bx
2366 seg es
2367 mov al, [bx]
2368 out dx, al
2369 inc bx
2370 seg es
2371 mov al, [bx]
2372 out dx, al
2373 inc bx
2374 dec cx
2375 jnz set_dac_loop
2376 pop dx
2377 pop cx
2378 pop bx
2379 pop ax
2380 ret
2381 ASM_END
2382
2383 // --------------------------------------------------------------------------------------------
2384 ASM_START
2385 biosfn_select_video_dac_color_page:
2386 push ax
2387 push bx
2388 push dx
2389 mov dx, # VGAREG_ACTL_RESET
2390 in al, dx
2391 mov dx, # VGAREG_ACTL_ADDRESS
2392 mov al, #0x10
2393 out dx, al
2394 mov dx, # VGAREG_ACTL_READ_DATA
2395 in al, dx
2396 and bl, #0x01
2397 jnz set_dac_page
2398 and al, #0x7f
2399 shl bh, 7
2400 or al, bh
2401 mov dx, # VGAREG_ACTL_ADDRESS
2402 out dx, al
2403 jmp set_actl_normal
2404 set_dac_page:
2405 push ax
2406 mov dx, # VGAREG_ACTL_RESET
2407 in al, dx
2408 mov dx, # VGAREG_ACTL_ADDRESS
2409 mov al, #0x14
2410 out dx, al
2411 pop ax
2412 and al, #0x80
2413 jnz set_dac_16_page
2414 shl bh, 2
2415 set_dac_16_page:
2416 and bh, #0x0f
2417 mov al, bh
2418 out dx, al
2419 set_actl_normal:
2420 mov al, #0x20
2421 out dx, al
2422 pop dx
2423 pop bx
2424 pop ax
2425 ret
2426 ASM_END
2427
2428 // --------------------------------------------------------------------------------------------
2429 ASM_START
2430 biosfn_read_single_dac_reg:
2431 push ax
2432 push dx
2433 mov dx, # VGAREG_DAC_READ_ADDRESS
2434 mov al, bl
2435 out dx, al
2436 pop ax
2437 mov ah, al
2438 mov dx, # VGAREG_DAC_DATA
2439 in al, dx
2440 xchg al, ah
2441 push ax
2442 in al, dx
2443 mov ch, al
2444 in al, dx
2445 mov cl, al
2446 pop dx
2447 pop ax
2448 ret
2449 ASM_END
2450
2451 // --------------------------------------------------------------------------------------------
2452 ASM_START
2453 biosfn_read_all_dac_reg:
2454 push ax
2455 push bx
2456 push cx
2457 push dx
2458 mov dx, # VGAREG_DAC_READ_ADDRESS
2459 mov al, bl
2460 out dx, al
2461 pop dx
2462 push dx
2463 mov bx, dx
2464 mov dx, # VGAREG_DAC_DATA
2465 read_dac_loop:
2466 in al, dx
2467 seg es
2468 mov [bx], al
2469 inc bx
2470 in al, dx
2471 seg es
2472 mov [bx], al
2473 inc bx
2474 in al, dx
2475 seg es
2476 mov [bx], al
2477 inc bx
2478 dec cx
2479 jnz read_dac_loop
2480 pop dx
2481 pop cx
2482 pop bx
2483 pop ax
2484 ret
2485 ASM_END
2486
2487 // --------------------------------------------------------------------------------------------
2488 ASM_START
2489 biosfn_set_pel_mask:
2490 push ax
2491 push dx
2492 mov dx, # VGAREG_PEL_MASK
2493 mov al, bl
2494 out dx, al
2495 pop dx
2496 pop ax
2497 ret
2498 ASM_END
2499
2500 // --------------------------------------------------------------------------------------------
2501 ASM_START
2502 biosfn_read_pel_mask:
2503 push ax
2504 push dx
2505 mov dx, # VGAREG_PEL_MASK
2506 in al, dx
2507 mov bl, al
2508 pop dx
2509 pop ax
2510 ret
2511 ASM_END
2512
2513 // --------------------------------------------------------------------------------------------
2514 ASM_START
2515 biosfn_read_video_dac_state:
2516 push ax
2517 push dx
2518 mov dx, # VGAREG_ACTL_RESET
2519 in al, dx
2520 mov dx, # VGAREG_ACTL_ADDRESS
2521 mov al, #0x10
2522 out dx, al
2523 mov dx, # VGAREG_ACTL_READ_DATA
2524 in al, dx
2525 mov bl, al
2526 shr bl, 7
2527 mov dx, # VGAREG_ACTL_RESET
2528 in al, dx
2529 mov dx, # VGAREG_ACTL_ADDRESS
2530 mov al, #0x14
2531 out dx, al
2532 mov dx, # VGAREG_ACTL_READ_DATA
2533 in al, dx
2534 mov bh, al
2535 and bh, #0x0f
2536 test bl, #0x01
2537 jnz get_dac_16_page
2538 shr bh, 2
2539 get_dac_16_page:
2540 mov dx, # VGAREG_ACTL_RESET
2541 in al, dx
2542 mov dx, # VGAREG_ACTL_ADDRESS
2543 mov al, #0x20
2544 out dx, al
2545 pop dx
2546 pop ax
2547 ret
2548 ASM_END
2549
2550 // --------------------------------------------------------------------------------------------
2551 static void biosfn_perform_gray_scale_summing (start,count)
2552 Bit16u start;Bit16u count;
2553 {Bit8u r,g,b;
2554 Bit16u i;
2555 Bit16u index;
2556
2557 inb(VGAREG_ACTL_RESET);
2558 outb(VGAREG_ACTL_ADDRESS,0x00);
2559
2560 for( index = 0; index < count; index++ )
2561 {
2562 // set read address and switch to read mode
2563 outb(VGAREG_DAC_READ_ADDRESS,start);
2564 // get 6-bit wide RGB data values
2565 r=inb( VGAREG_DAC_DATA );
2566 g=inb( VGAREG_DAC_DATA );
2567 b=inb( VGAREG_DAC_DATA );
2568
2569 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
2570 i = ( ( 77*r + 151*g + 28*b ) + 0x80 ) >> 8;
2571
2572 if(i>0x3f)i=0x3f;
2573
2574 // set write address and switch to write mode
2575 outb(VGAREG_DAC_WRITE_ADDRESS,start);
2576 // write new intensity value
2577 outb( VGAREG_DAC_DATA, i&0xff );
2578 outb( VGAREG_DAC_DATA, i&0xff );
2579 outb( VGAREG_DAC_DATA, i&0xff );
2580 start++;
2581 }
2582 inb(VGAREG_ACTL_RESET);
2583 outb(VGAREG_ACTL_ADDRESS,0x20);
2584 }
2585
2586 // --------------------------------------------------------------------------------------------
2587 static void get_font_access()
2588 {
2589 ASM_START
2590 mov dx, # VGAREG_SEQU_ADDRESS
2591 mov ax, #0x0100
2592 out dx, ax
2593 mov ax, #0x0402
2594 out dx, ax
2595 mov ax, #0x0704
2596 out dx, ax
2597 mov ax, #0x0300
2598 out dx, ax
2599 mov dx, # VGAREG_GRDC_ADDRESS
2600 mov ax, #0x0204
2601 out dx, ax
2602 mov ax, #0x0005
2603 out dx, ax
2604 mov ax, #0x0406
2605 out dx, ax
2606 ASM_END
2607 }
2608
2609 static void release_font_access()
2610 {
2611 ASM_START
2612 mov dx, # VGAREG_SEQU_ADDRESS
2613 mov ax, #0x0100
2614 out dx, ax
2615 mov ax, #0x0302
2616 out dx, ax
2617 mov ax, #0x0304
2618 out dx, ax
2619 mov ax, #0x0300
2620 out dx, ax
2621 mov dx, # VGAREG_READ_MISC_OUTPUT
2622 in al, dx
2623 and al, #0x01
2624 shl al, 2
2625 or al, #0x0a
2626 mov ah, al
2627 mov al, #0x06
2628 mov dx, # VGAREG_GRDC_ADDRESS
2629 out dx, ax
2630 mov ax, #0x0004
2631 out dx, ax
2632 mov ax, #0x1005
2633 out dx, ax
2634 ASM_END
2635 }
2636
2637 ASM_START
2638 idiv_u:
2639 xor dx,dx
2640 div bx
2641 ret
2642 ASM_END
2643
2644 static void set_scan_lines(lines) Bit8u lines;
2645 {
2646 Bit16u crtc_addr,cols,page,vde;
2647 Bit8u crtc_r9,ovl,rows;
2648
2649 crtc_addr = read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS);
2650 outb(crtc_addr, 0x09);
2651 crtc_r9 = inb(crtc_addr+1);
2652 crtc_r9 = (crtc_r9 & 0xe0) | (lines - 1);
2653 outb(crtc_addr+1, crtc_r9);
2654 if(lines==8)
2655 {
2656 biosfn_set_cursor_shape(0x06,0x07);
2657 }
2658 else
2659 {
2660 biosfn_set_cursor_shape(lines-4,lines-3);
2661 }
2662 write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, lines);
2663 outb(crtc_addr, 0x12);
2664 vde = inb(crtc_addr+1);
2665 outb(crtc_addr, 0x07);
2666 ovl = inb(crtc_addr+1);
2667 vde += (((ovl & 0x02) << 7) + ((ovl & 0x40) << 3) + 1);
2668 rows = vde / lines;
2669 write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, rows-1);
2670 cols = read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS);
2671 write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, rows * cols * 2);
2672 }
2673
2674 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;
2675 {
2676 Bit16u blockaddr,dest,i,src;
2677
2678 get_font_access();
2679 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
2680 for(i=0;i<CX;i++)
2681 {
2682 src = BP + i * BH;
2683 dest = blockaddr + (DX + i) * 32;
2684 memcpyb(0xA000, dest, ES, src, BH);
2685 }
2686 release_font_access();
2687 if(AL>=0x10)
2688 {
2689 set_scan_lines(BH);
2690 }
2691 }
2692
2693 static void biosfn_load_text_8_14_pat (AL,BL) Bit8u AL;Bit8u BL;
2694 {
2695 Bit16u blockaddr,dest,i,src;
2696
2697 get_font_access();
2698 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
2699 for(i=0;i<0x100;i++)
2700 {
2701 src = i * 14;
2702 dest = blockaddr + i * 32;
2703 memcpyb(0xA000, dest, 0xC000, vgafont14+src, 14);
2704 }
2705 release_font_access();
2706 if(AL>=0x10)
2707 {
2708 set_scan_lines(14);
2709 }
2710 }
2711
2712 static void biosfn_load_text_8_8_pat (AL,BL) Bit8u AL;Bit8u BL;
2713 {
2714 Bit16u blockaddr,dest,i,src;
2715
2716 get_font_access();
2717 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
2718 for(i=0;i<0x100;i++)
2719 {
2720 src = i * 8;
2721 dest = blockaddr + i * 32;
2722 memcpyb(0xA000, dest, 0xC000, vgafont8+src, 8);
2723 }
2724 release_font_access();
2725 if(AL>=0x10)
2726 {
2727 set_scan_lines(8);
2728 }
2729 }
2730
2731 // --------------------------------------------------------------------------------------------
2732 ASM_START
2733 biosfn_set_text_block_specifier:
2734 push ax
2735 push dx
2736 mov dx, # VGAREG_SEQU_ADDRESS
2737 mov ah, bl
2738 mov al, #0x03
2739 out dx, ax
2740 pop dx
2741 pop ax
2742 ret
2743 ASM_END
2744
2745 // --------------------------------------------------------------------------------------------
2746 static void biosfn_load_text_8_16_pat (AL,BL) Bit8u AL;Bit8u BL;
2747 {
2748 Bit16u blockaddr,dest,i,src;
2749
2750 get_font_access();
2751 blockaddr = ((BL & 0x03) << 14) + ((BL & 0x04) << 11);
2752 for(i=0;i<0x100;i++)
2753 {
2754 src = i * 16;
2755 dest = blockaddr + i * 32;
2756 memcpyb(0xA000, dest, 0xC000, vgafont16+src, 16);
2757 }
2758 release_font_access();
2759 if(AL>=0x10)
2760 {
2761 set_scan_lines(16);
2762 }
2763 }
2764
2765 static void biosfn_load_gfx_8_8_chars (ES,BP) Bit16u ES;Bit16u BP;
2766 {
2767 #ifdef DEBUG
2768 unimplemented();
2769 #endif
2770 }
2771 static void biosfn_load_gfx_user_chars (ES,BP,CX,BL,DL) Bit16u ES;Bit16u BP;Bit16u CX;Bit8u BL;Bit8u DL;
2772 {
2773 #ifdef DEBUG
2774 unimplemented();
2775 #endif
2776 }
2777 static void biosfn_load_gfx_8_14_chars (BL) Bit8u BL;
2778 {
2779 #ifdef DEBUG
2780 unimplemented();
2781 #endif
2782 }
2783 static void biosfn_load_gfx_8_8_dd_chars (BL) Bit8u BL;
2784 {
2785 #ifdef DEBUG
2786 unimplemented();
2787 #endif
2788 }
2789 static void biosfn_load_gfx_8_16_chars (BL) Bit8u BL;
2790 {
2791 #ifdef DEBUG
2792 unimplemented();
2793 #endif
2794 }
2795 // --------------------------------------------------------------------------------------------
2796 static void biosfn_get_font_info (BH,ES,BP,CX,DX)
2797 Bit8u BH;Bit16u *ES;Bit16u *BP;Bit16u *CX;Bit16u *DX;
2798 {Bit16u ss=get_SS();
2799
2800 switch(BH)
2801 {case 0x00:
2802 write_word(ss,ES,read_word(0x00,0x1f*4));
2803 write_word(ss,BP,read_word(0x00,(0x1f*4)+2));
2804 break;
2805 case 0x01:
2806 write_word(ss,ES,read_word(0x00,0x43*4));
2807 write_word(ss,BP,read_word(0x00,(0x43*4)+2));
2808 break;
2809 case 0x02:
2810 write_word(ss,ES,0xC000);
2811 write_word(ss,BP,vgafont14);
2812 break;
2813 case 0x03:
2814 write_word(ss,ES,0xC000);
2815 write_word(ss,BP,vgafont8);
2816 break;
2817 case 0x04:
2818 write_word(ss,ES,0xC000);
2819 write_word(ss,BP,vgafont8+128*8);
2820 break;
2821 case 0x05:
2822 write_word(ss,ES,0xC000);
2823 write_word(ss,BP,vgafont14alt);
2824 break;
2825 case 0x06:
2826 write_word(ss,ES,0xC000);
2827 write_word(ss,BP,vgafont16);
2828 break;
2829 case 0x07:
2830 write_word(ss,ES,0xC000);
2831 write_word(ss,BP,vgafont16alt);
2832 break;
2833 default:
2834 #ifdef DEBUG
2835 printf("Get font info BH(%02x) was discarded\n",BH);
2836 #endif
2837 return;
2838 }
2839 // Set byte/char of on screen font
2840 write_word(ss,CX,(Bit16u)read_byte(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT));
2841
2842 // Set Highest char row
2843 write_word(ss,DX,(Bit16u)read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS));
2844 }
2845
2846 // --------------------------------------------------------------------------------------------
2847 ASM_START
2848 biosfn_get_ega_info:
2849 push ds
2850 push ax
2851 mov ax, # BIOSMEM_SEG
2852 mov ds, ax
2853 xor ch, ch
2854 mov bx, # BIOSMEM_SWITCHES
2855 mov cl, [bx]
2856 and cl, #0x0f
2857 mov bx, # BIOSMEM_CRTC_ADDRESS
2858 mov ax, [bx]
2859 mov bx, #0x0003
2860 cmp ax, # VGAREG_MDA_CRTC_ADDRESS
2861 jne mode_ega_color
2862 mov bh, #0x01
2863 mode_ega_color:
2864 pop ax
2865 pop ds
2866 ret
2867 ASM_END
2868
2869 // --------------------------------------------------------------------------------------------
2870 static void biosfn_alternate_prtsc()
2871 {
2872 #ifdef DEBUG
2873 unimplemented();
2874 #endif
2875 }
2876
2877 // --------------------------------------------------------------------------------------------
2878 ASM_START
2879 biosfn_select_vert_res:
2880
2881 ; res : 00 200 lines, 01 350 lines, 02 400 lines
2882
2883 push ds
2884 push bx
2885 push dx
2886 mov dl, al
2887 mov ax, # BIOSMEM_SEG
2888 mov ds, ax
2889 mov bx, # BIOSMEM_MODESET_CTL
2890 mov al, [bx]
2891 mov bx, # BIOSMEM_SWITCHES
2892 mov ah, [bx]
2893 cmp dl, #0x01
2894 je vert_res_350
2895 jb vert_res_200
2896 cmp dl, #0x02
2897 je vert_res_400
2898 #ifdef DEBUG
2899 mov al, dl
2900 xor ah, ah
2901 push ax
2902 mov bx, #msg_vert_res
2903 push bx
2904 call _printf
2905 add sp, #4
2906 #endif
2907 jmp set_retcode
2908 vert_res_400:
2909
2910 ; reset modeset ctl bit 7 and set bit 4
2911 ; set switches bit 3-0 to 0x09
2912
2913 and al, #0x7f
2914 or al, #0x10
2915 and ah, #0xf0
2916 or ah, #0x09
2917 jnz set_vert_res
2918 vert_res_350:
2919
2920 ; reset modeset ctl bit 7 and bit 4
2921 ; set switches bit 3-0 to 0x09
2922
2923 and al, #0x6f
2924 and ah, #0xf0
2925 or ah, #0x09
2926 jnz set_vert_res
2927 vert_res_200:
2928
2929 ; set modeset ctl bit 7 and reset bit 4
2930 ; set switches bit 3-0 to 0x08
2931
2932 and al, #0xef
2933 or al, #0x80
2934 and ah, #0xf0
2935 or ah, #0x08
2936 set_vert_res:
2937 mov bx, # BIOSMEM_MODESET_CTL
2938 mov [bx], al
2939 mov bx, # BIOSMEM_SWITCHES
2940 mov [bx], ah
2941 set_retcode:
2942 mov ax, #0x1212
2943 pop dx
2944 pop bx
2945 pop ds
2946 ret
2947
2948 #ifdef DEBUG
2949 msg_vert_res:
2950 .ascii "Select vert res (%02x) was discarded"
2951 .byte 0x0d,0x0a,0x00
2952 #endif
2953
2954
2955 biosfn_enable_default_palette_loading:
2956 push ds
2957 push bx
2958 push dx
2959 mov dl, al
2960 and dl, #0x01
2961 shl dl, 3
2962 mov ax, # BIOSMEM_SEG
2963 mov ds, ax
2964 mov bx, # BIOSMEM_MODESET_CTL
2965 mov al, [bx]
2966 and al, #0xf7
2967 or al, dl
2968 mov [bx], al
2969 mov ax, #0x1212
2970 pop dx
2971 pop bx
2972 pop ds
2973 ret
2974
2975
2976 biosfn_enable_video_addressing:
2977 push bx
2978 push dx
2979 mov bl, al
2980 and bl, #0x01
2981 xor bl, #0x01
2982 shl bl, 1
2983 mov dx, # VGAREG_READ_MISC_OUTPUT
2984 in al, dx
2985 and al, #0xfd
2986 or al, bl
2987 mov dx, # VGAREG_WRITE_MISC_OUTPUT
2988 out dx, al
2989 mov ax, #0x1212
2990 pop dx
2991 pop bx
2992 ret
2993
2994
2995 biosfn_enable_grayscale_summing:
2996 push ds
2997 push bx
2998 push dx
2999 mov dl, al
3000 and dl, #0x01
3001 xor dl, #0x01
3002 shl dl, 1
3003 mov ax, # BIOSMEM_SEG
3004 mov ds, ax
3005 mov bx, # BIOSMEM_MODESET_CTL
3006 mov al, [bx]
3007 and al, #0xfd
3008 or al, dl
3009 mov [bx], al
3010 mov ax, #0x1212
3011 pop dx
3012 pop bx
3013 pop ds
3014 ret
3015
3016
3017 biosfn_enable_cursor_emulation:
3018 push ds
3019 push bx
3020 push dx
3021 mov dl, al
3022 and dl, #0x01
3023 xor dl, #0x01
3024 mov ax, # BIOSMEM_SEG
3025 mov ds, ax
3026 mov bx, # BIOSMEM_MODESET_CTL
3027 mov al, [bx]
3028 and al, #0xfe
3029 or al, dl
3030 mov [bx], al
3031 mov ax, #0x1212
3032 pop dx
3033 pop bx
3034 pop ds
3035 ret
3036 ASM_END
3037
3038 // --------------------------------------------------------------------------------------------
3039 static void biosfn_switch_video_interface (AL,ES,DX) Bit8u AL;Bit16u ES;Bit16u DX;
3040 {
3041 #ifdef DEBUG
3042 unimplemented();
3043 #endif
3044 }
3045 static void biosfn_enable_video_refresh_control (AL) Bit8u AL;
3046 {
3047 #ifdef DEBUG
3048 unimplemented();
3049 #endif
3050 }
3051
3052 // --------------------------------------------------------------------------------------------
3053 static void biosfn_write_string (flag,page,attr,count,row,col,seg,offset)
3054 Bit8u flag;Bit8u page;Bit8u attr;Bit16u count;Bit8u row;Bit8u col;Bit16u seg;Bit16u offset;
3055 {
3056 Bit16u newcurs,oldcurs,dummy;
3057 Bit8u car,carattr;
3058
3059 // Read curs info for the page
3060 biosfn_get_cursor_pos(page,&dummy,&oldcurs);
3061
3062 // if row=0xff special case : use current cursor position
3063 if(row==0xff)
3064 {col=oldcurs&0x00ff;
3065 row=(oldcurs&0xff00)>>8;
3066 }
3067
3068 newcurs=row; newcurs<<=8; newcurs+=col;
3069 biosfn_set_cursor_pos(page,newcurs);
3070
3071 while(count--!=0)
3072 {
3073 car=read_byte(seg,offset++);
3074 if((flag&0x02)!=0)
3075 attr=read_byte(seg,offset++);
3076
3077 biosfn_write_teletype(car,page,attr,WITH_ATTR);
3078 }
3079
3080 // Set back curs pos
3081 if((flag&0x01)==0)
3082 biosfn_set_cursor_pos(page,oldcurs);
3083 }
3084
3085 // --------------------------------------------------------------------------------------------
3086 ASM_START
3087 biosfn_group_1A:
3088 cmp al, #0x00
3089 je biosfn_read_display_code
3090 cmp al, #0x01
3091 je biosfn_set_display_code
3092 #ifdef DEBUG
3093 call _unknown
3094 #endif
3095 ret
3096 biosfn_read_display_code:
3097 push ds
3098 push ax
3099 mov ax, # BIOSMEM_SEG
3100 mov ds, ax
3101 mov bx, # BIOSMEM_DCC_INDEX
3102 mov al, [bx]
3103 mov bl, al
3104 xor bh, bh
3105 pop ax
3106 mov al, ah
3107 pop ds
3108 ret
3109 biosfn_set_display_code:
3110 push ds
3111 push ax
3112 push bx
3113 mov ax, # BIOSMEM_SEG
3114 mov ds, ax
3115 mov ax, bx
3116 mov bx, # BIOSMEM_DCC_INDEX
3117 mov [bx], al
3118 #ifdef DEBUG
3119 mov al, ah
3120 xor ah, ah
3121 push ax
3122 mov bx, #msg_alt_dcc
3123 push bx
3124 call _printf
3125 add sp, #4
3126 #endif
3127 pop bx
3128 pop ax
3129 mov al, ah
3130 pop ds
3131 ret
3132
3133 #ifdef DEBUG
3134 msg_alt_dcc:
3135 .ascii "Alternate Display code (%02x) was discarded"
3136 .byte 0x0d,0x0a,0x00
3137 #endif
3138 ASM_END
3139
3140 // --------------------------------------------------------------------------------------------
3141 static void biosfn_read_state_info (BX,ES,DI)
3142 Bit16u BX;Bit16u ES;Bit16u DI;
3143 {
3144 // Address of static functionality table
3145 write_word(ES,DI+0x00,&static_functionality);
3146 write_word(ES,DI+0x02,0xC000);
3147
3148 // Hard coded copy from BIOS area. Should it be cleaner ?
3149 memcpyb(ES,DI+0x04,BIOSMEM_SEG,0x49,30);
3150 memcpyb(ES,DI+0x22,BIOSMEM_SEG,0x84,3);
3151
3152 write_byte(ES,DI+0x25,read_byte(BIOSMEM_SEG,BIOSMEM_DCC_INDEX));
3153 write_byte(ES,DI+0x26,0);
3154 write_byte(ES,DI+0x27,16);
3155 write_byte(ES,DI+0x28,0);
3156 write_byte(ES,DI+0x29,8);
3157 write_byte(ES,DI+0x2a,2);
3158 write_byte(ES,DI+0x2b,0);
3159 write_byte(ES,DI+0x2c,0);
3160 write_byte(ES,DI+0x31,3);
3161 write_byte(ES,DI+0x32,0);
3162
3163 memsetb(ES,DI+0x33,0,13);
3164 }
3165
3166 // --------------------------------------------------------------------------------------------
3167 // --------------------------------------------------------------------------------------------
3168 static Bit16u biosfn_read_video_state_size2 (CX)
3169 Bit16u CX;
3170 {
3171 Bit16u size;
3172 size = 0;
3173 if (CX & 1) {
3174 size += 0x46;
3175 }
3176 if (CX & 2) {
3177 size += (5 + 8 + 5) * 2 + 6;
3178 }
3179 if (CX & 4) {
3180 size += 3 + 256 * 3 + 1;
3181 }
3182 return size;
3183 }
3184
3185 static void biosfn_read_video_state_size (CX, BX)
3186 Bit16u CX; Bit16u *BX;
3187 {
3188 Bit16u ss=get_SS();
3189 write_word(ss, BX, biosfn_read_video_state_size2(CX));
3190 }
3191
3192 static Bit16u biosfn_save_video_state (CX,ES,BX)
3193 Bit16u CX;Bit16u ES;Bit16u BX;
3194 {
3195 Bit16u i, v, crtc_addr, ar_index;
3196
3197 crtc_addr = read_word(BIOSMEM_SEG, BIOSMEM_CRTC_ADDRESS);
3198 if (CX & 1) {
3199 write_byte(ES, BX, inb(VGAREG_SEQU_ADDRESS)); BX++;
3200 write_byte(ES, BX, inb(crtc_addr)); BX++;
3201 write_byte(ES, BX, inb(VGAREG_GRDC_ADDRESS)); BX++;
3202 inb(VGAREG_ACTL_RESET);
3203 ar_index = inb(VGAREG_ACTL_ADDRESS);
3204 write_byte(ES, BX, ar_index); BX++;
3205 write_byte(ES, BX, inb(VGAREG_READ_FEATURE_CTL)); BX++;
3206
3207 for(i=1;i<=4;i++){
3208 outb(VGAREG_SEQU_ADDRESS, i);
3209 write_byte(ES, BX, inb(VGAREG_SEQU_DATA)); BX++;
3210 }
3211 outb(VGAREG_SEQU_ADDRESS, 0);
3212 write_byte(ES, BX, inb(VGAREG_SEQU_DATA)); BX++;
3213
3214 for(i=0;i<=0x18;i++) {
3215 outb(crtc_addr,i);
3216 write_byte(ES, BX, inb(crtc_addr+1)); BX++;
3217 }
3218
3219 for(i=0;i<=0x13;i++) {
3220 inb(VGAREG_ACTL_RESET);
3221 outb(VGAREG_ACTL_ADDRESS, i | (ar_index & 0x20));
3222 write_byte(ES, BX, inb(VGAREG_ACTL_READ_DATA)); BX++;
3223 }
3224 inb(VGAREG_ACTL_RESET);
3225
3226 for(i=0;i<=8;i++) {
3227 outb(VGAREG_GRDC_ADDRESS,i);
3228 write_byte(ES, BX, inb(VGAREG_GRDC_DATA)); BX++;
3229 }
3230
3231 write_word(ES, BX, crtc_addr); BX+= 2;
3232
3233 /* XXX: read plane latches */
3234 write_byte(ES, BX, 0); BX++;
3235 write_byte(ES, BX, 0); BX++;
3236 write_byte(ES, BX, 0); BX++;
3237 write_byte(ES, BX, 0); BX++;
3238 }
3239 if (CX & 2) {
3240 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE)); BX++;
3241 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_NB_COLS)); BX += 2;
3242 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE)); BX += 2;
3243 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS)); BX += 2;
3244 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS)); BX++;
3245 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT)); BX += 2;
3246 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL)); BX++;
3247 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES)); BX++;
3248 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL)); BX++;
3249 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE)); BX += 2;
3250 for(i=0;i<8;i++) {
3251 write_word(ES, BX, read_word(BIOSMEM_SEG, BIOSMEM_CURSOR_POS+2*i));
3252 BX += 2;
3253 }
3254 write_word(ES, BX, read_word(BIOSMEM_SEG,BIOSMEM_CURRENT_START)); BX += 2;
3255 write_byte(ES, BX, read_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE)); BX++;
3256 /* current font */
3257 write_word(ES, BX, read_word(0, 0x1f * 4)); BX += 2;
3258 write_word(ES, BX, read_word(0, 0x1f * 4 + 2)); BX += 2;
3259 write_word(ES, BX, read_word(0, 0x43 * 4)); BX += 2;
3260 write_word(ES, BX, read_word(0, 0x43 * 4 + 2)); BX += 2;
3261 }
3262 if (CX & 4) {
3263 /* XXX: check this */
3264 write_byte(ES, BX, inb(VGAREG_DAC_STATE)); BX++; /* read/write mode dac */
3265 write_byte(ES, BX, inb(VGAREG_DAC_WRITE_ADDRESS)); BX++; /* pix address */
3266 write_byte(ES, BX, inb(VGAREG_PEL_MASK)); BX++;
3267 // Set the whole dac always, from 0
3268 outb(VGAREG_DAC_WRITE_ADDRESS,0x00);
3269 for(i=0;i<256*3;i++) {
3270 write_byte(ES, BX, inb(VGAREG_DAC_DATA)); BX++;
3271 }
3272 write_byte(ES, BX, 0); BX++; /* color select register */
3273 }
3274 return BX;
3275 }
3276
3277 static Bit16u biosfn_restore_video_state (CX,ES,BX)
3278 Bit16u CX;Bit16u ES;Bit16u BX;
3279 {
3280 Bit16u i, crtc_addr, v, addr1, ar_index;
3281
3282 if (CX & 1) {
3283 // Reset Attribute Ctl flip-flop
3284 inb(VGAREG_ACTL_RESET);
3285
3286 crtc_addr = read_word(ES, BX + 0x40);
3287 addr1 = BX;
3288 BX += 5;
3289
3290 for(i=1;i<=4;i++){
3291 outb(VGAREG_SEQU_ADDRESS, i);
3292 outb(VGAREG_SEQU_DATA, read_byte(ES, BX)); BX++;
3293 }
3294 outb(VGAREG_SEQU_ADDRESS, 0);
3295 outb(VGAREG_SEQU_DATA, read_byte(ES, BX)); BX++;
3296
3297 // Disable CRTC write protection
3298 outw(crtc_addr,0x0011);
3299 // Set CRTC regs
3300 for(i=0;i<=0x18;i++) {
3301 if (i != 0x11) {
3302 outb(crtc_addr,i);
3303 outb(crtc_addr+1, read_byte(ES, BX));
3304 }
3305 BX++;
3306 }
3307 // select crtc base address
3308 v = inb(VGAREG_READ_MISC_OUTPUT) & ~0x01;
3309 if (crtc_addr = 0x3d4)
3310 v |= 0x01;
3311 outb(VGAREG_WRITE_MISC_OUTPUT, v);
3312
3313 // enable write protection if needed
3314 outb(crtc_addr, 0x11);
3315 outb(crtc_addr+1, read_byte(ES, BX - 0x18 + 0x11));
3316
3317 // Set Attribute Ctl
3318 ar_index = read_byte(ES, addr1 + 0x03);
3319 inb(VGAREG_ACTL_RESET);
3320 for(i=0;i<=0x13;i++) {
3321 outb(VGAREG_ACTL_ADDRESS, i | (ar_index & 0x20));
3322 outb(VGAREG_ACTL_WRITE_DATA, read_byte(ES, BX)); BX++;
3323 }
3324 outb(VGAREG_ACTL_ADDRESS, ar_index);
3325 inb(VGAREG_ACTL_RESET);
3326
3327 for(i=0;i<=8;i++) {
3328 outb(VGAREG_GRDC_ADDRESS,i);
3329 outb(VGAREG_GRDC_DATA, read_byte(ES, BX)); BX++;
3330 }
3331 BX += 2; /* crtc_addr */
3332 BX += 4; /* plane latches */
3333
3334 outb(VGAREG_SEQU_ADDRESS, read_byte(ES, addr1)); addr1++;
3335 outb(crtc_addr, read_byte(ES, addr1)); addr1++;
3336 outb(VGAREG_GRDC_ADDRESS, read_byte(ES, addr1)); addr1++;
3337 addr1++;
3338 outb(crtc_addr - 0x4 + 0xa, read_byte(ES, addr1)); addr1++;
3339 }
3340 if (CX & 2) {
3341 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_MODE, read_byte(ES, BX)); BX++;
3342 write_word(BIOSMEM_SEG,BIOSMEM_NB_COLS, read_word(ES, BX)); BX += 2;
3343 write_word(BIOSMEM_SEG,BIOSMEM_PAGE_SIZE, read_word(ES, BX)); BX += 2;
3344 write_word(BIOSMEM_SEG,BIOSMEM_CRTC_ADDRESS, read_word(ES, BX)); BX += 2;
3345 write_byte(BIOSMEM_SEG,BIOSMEM_NB_ROWS, read_byte(ES, BX)); BX++;
3346 write_word(BIOSMEM_SEG,BIOSMEM_CHAR_HEIGHT, read_word(ES, BX)); BX += 2;
3347 write_byte(BIOSMEM_SEG,BIOSMEM_VIDEO_CTL, read_byte(ES, BX)); BX++;
3348 write_byte(BIOSMEM_SEG,BIOSMEM_SWITCHES, read_byte(ES, BX)); BX++;
3349 write_byte(BIOSMEM_SEG,BIOSMEM_MODESET_CTL, read_byte(ES, BX)); BX++;
3350 write_word(BIOSMEM_SEG,BIOSMEM_CURSOR_TYPE, read_word(ES, BX)); BX += 2;
3351 for(i=0;i<8;i++) {
3352 write_word(BIOSMEM_SEG, BIOSMEM_CURSOR_POS+2*i, read_word(ES, BX));
3353 BX += 2;
3354 }
3355 write_word(BIOSMEM_SEG,BIOSMEM_CURRENT_START, read_word(ES, BX)); BX += 2;
3356 write_byte(BIOSMEM_SEG,BIOSMEM_CURRENT_PAGE, read_byte(ES, BX)); BX++;
3357 /* current font */
3358 write_word(0, 0x1f * 4, read_word(ES, BX)); BX += 2;
3359 write_word(0, 0x1f * 4 + 2, read_word(ES, BX)); BX += 2;
3360 write_word(0, 0x43 * 4, read_word(ES, BX)); BX += 2;
3361 write_word(0, 0x43 * 4 + 2, read_word(ES, BX)); BX += 2;
3362 }
3363 if (CX & 4) {
3364 BX++;
3365 v = read_byte(ES, BX); BX++;
3366 outb(VGAREG_PEL_MASK, read_byte(ES, BX)); BX++;
3367 // Set the whole dac always, from 0
3368 outb(VGAREG_DAC_WRITE_ADDRESS,0x00);
3369 for(i=0;i<256*3;i++) {
3370 outb(VGAREG_DAC_DATA, read_byte(ES, BX)); BX++;
3371 }
3372 BX++;
3373 outb(VGAREG_DAC_WRITE_ADDRESS, v);
3374 }
3375 return BX;
3376 }
3377
3378 // ============================================================================================
3379 //
3380 // Video Utils
3381 //
3382 // ============================================================================================
3383
3384 // --------------------------------------------------------------------------------------------
3385 static Bit8u find_vga_entry(mode)
3386 Bit8u mode;
3387 {
3388 Bit8u i,line=0xFF;
3389 for(i=0;i<=MODE_MAX;i++)
3390 if(vga_modes[i].svgamode==mode)
3391 {line=i;
3392 break;
3393 }
3394 return line;
3395 }
3396
3397 /* =========================================================== */
3398 /*
3399 * Misc Utils
3400 */
3401 /* =========================================================== */
3402
3403 // --------------------------------------------------------------------------------------------
3404 static void memsetb(seg,offset,value,count)
3405 Bit16u seg;
3406 Bit16u offset;
3407 Bit16u value;
3408 Bit16u count;
3409 {
3410 ASM_START
3411 push bp
3412 mov bp, sp
3413
3414 push ax
3415 push cx
3416 push es
3417 push di
3418
3419 mov cx, 10[bp] ; count
3420 cmp cx, #0x00
3421 je memsetb_end
3422 mov ax, 4[bp] ; segment
3423 mov es, ax
3424 mov ax, 6[bp] ; offset
3425 mov di, ax
3426 mov al, 8[bp] ; value
3427 cld
3428 rep
3429 stosb
3430
3431 memsetb_end:
3432 pop di
3433 pop es
3434 pop cx
3435 pop ax
3436
3437 pop bp
3438 ASM_END
3439 }
3440
3441 // --------------------------------------------------------------------------------------------
3442 static void memsetw(seg,offset,value,count)
3443 Bit16u seg;
3444 Bit16u offset;
3445 Bit16u value;
3446 Bit16u count;
3447 {
3448 ASM_START
3449 push bp
3450 mov bp, sp
3451
3452 push ax
3453 push cx
3454 push es
3455 push di
3456
3457 mov cx, 10[bp] ; count
3458 cmp cx, #0x00
3459 je memsetw_end
3460 mov ax, 4[bp] ; segment
3461 mov es, ax
3462 mov ax, 6[bp] ; offset
3463 mov di, ax
3464 mov ax, 8[bp] ; value
3465 cld
3466 rep
3467 stosw
3468
3469 memsetw_end:
3470 pop di
3471 pop es
3472 pop cx
3473 pop ax
3474
3475 pop bp
3476 ASM_END
3477 }
3478
3479 // --------------------------------------------------------------------------------------------
3480 static void memcpyb(dseg,doffset,sseg,soffset,count)
3481 Bit16u dseg;
3482 Bit16u doffset;
3483 Bit16u sseg;
3484 Bit16u soffset;
3485 Bit16u count;
3486 {
3487 ASM_START
3488 push bp
3489 mov bp, sp
3490
3491 push ax
3492 push cx
3493 push es
3494 push di
3495 push ds
3496 push si
3497
3498 mov cx, 12[bp] ; count
3499 cmp cx, #0x0000
3500 je memcpyb_end
3501 mov ax, 4[bp] ; dsegment
3502 mov es, ax
3503 mov ax, 6[bp] ; doffset
3504 mov di, ax
3505 mov ax, 8[bp] ; ssegment
3506 mov ds, ax
3507 mov ax, 10[bp] ; soffset
3508 mov si, ax
3509 cld
3510 rep
3511 movsb
3512
3513 memcpyb_end:
3514 pop si
3515 pop ds
3516 pop di
3517 pop es
3518 pop cx
3519 pop ax
3520
3521 pop bp
3522 ASM_END
3523 }
3524
3525 // --------------------------------------------------------------------------------------------
3526 static void memcpyw(dseg,doffset,sseg,soffset,count)
3527 Bit16u dseg;
3528 Bit16u doffset;
3529 Bit16u sseg;
3530 Bit16u soffset;
3531 Bit16u count;
3532 {
3533 ASM_START
3534 push bp
3535 mov bp, sp
3536
3537 push ax
3538 push cx
3539 push es
3540 push di
3541 push ds
3542 push si
3543
3544 mov cx, 12[bp] ; count
3545 cmp cx, #0x0000
3546 je memcpyw_end
3547 mov ax, 4[bp] ; dsegment
3548 mov es, ax
3549 mov ax, 6[bp] ; doffset
3550 mov di, ax
3551 mov ax, 8[bp] ; ssegment
3552 mov ds, ax
3553 mov ax, 10[bp] ; soffset
3554 mov si, ax
3555 cld
3556 rep
3557 movsw
3558
3559 memcpyw_end:
3560 pop si
3561 pop ds
3562 pop di
3563 pop es
3564 pop cx
3565 pop ax
3566
3567 pop bp
3568 ASM_END
3569 }
3570
3571 /* =========================================================== */
3572 /*
3573 * These functions where ripped from Kevin's rombios.c
3574 */
3575 /* =========================================================== */
3576
3577 // --------------------------------------------------------------------------------------------
3578 static Bit8u
3579 read_byte(seg, offset)
3580 Bit16u seg;
3581 Bit16u offset;
3582 {
3583 ASM_START
3584 push bp
3585 mov bp, sp
3586
3587 push bx
3588 push ds
3589 mov ax, 4[bp] ; segment
3590 mov ds, ax
3591 mov bx, 6[bp] ; offset
3592 mov al, [bx]
3593 ;; al = return value (byte)
3594 pop ds
3595 pop bx
3596
3597 pop bp
3598 ASM_END
3599 }
3600
3601 // --------------------------------------------------------------------------------------------
3602 static Bit16u
3603 read_word(seg, offset)
3604 Bit16u seg;
3605 Bit16u offset;
3606 {
3607 ASM_START
3608 push bp
3609 mov bp, sp
3610
3611 push bx
3612 push ds
3613 mov ax, 4[bp] ; segment
3614 mov ds, ax
3615 mov bx, 6[bp] ; offset
3616 mov ax, [bx]
3617 ;; ax = return value (word)
3618 pop ds
3619 pop bx
3620
3621 pop bp
3622 ASM_END
3623 }
3624
3625 // --------------------------------------------------------------------------------------------
3626 static void
3627 write_byte(seg, offset, data)
3628 Bit16u seg;
3629 Bit16u offset;
3630 Bit8u data;
3631 {
3632 ASM_START
3633 push bp
3634 mov bp, sp
3635
3636 push ax
3637 push bx
3638 push ds
3639 mov ax, 4[bp] ; segment
3640 mov ds, ax
3641 mov bx, 6[bp] ; offset
3642 mov al, 8[bp] ; data byte
3643 mov [bx], al ; write data byte
3644 pop ds
3645 pop bx
3646 pop ax
3647
3648 pop bp
3649 ASM_END
3650 }
3651
3652 // --------------------------------------------------------------------------------------------
3653 static void
3654 write_word(seg, offset, data)
3655 Bit16u seg;
3656 Bit16u offset;
3657 Bit16u data;
3658 {
3659 ASM_START
3660 push bp
3661 mov bp, sp
3662
3663 push ax
3664 push bx
3665 push ds
3666 mov ax, 4[bp] ; segment
3667 mov ds, ax
3668 mov bx, 6[bp] ; offset
3669 mov ax, 8[bp] ; data word
3670 mov [bx], ax ; write data word
3671 pop ds
3672 pop bx
3673 pop ax
3674
3675 pop bp
3676 ASM_END
3677 }
3678
3679 // --------------------------------------------------------------------------------------------
3680 Bit8u
3681 inb(port)
3682 Bit16u port;
3683 {
3684 ASM_START
3685 push bp
3686 mov bp, sp
3687
3688 push dx
3689 mov dx, 4[bp]
3690 in al, dx
3691 pop dx
3692
3693 pop bp
3694 ASM_END
3695 }
3696
3697 Bit16u
3698 inw(port)
3699 Bit16u port;
3700 {
3701 ASM_START
3702 push bp
3703 mov bp, sp
3704
3705 push dx
3706 mov dx, 4[bp]
3707 in ax, dx
3708 pop dx
3709
3710 pop bp
3711 ASM_END
3712 }
3713
3714 // --------------------------------------------------------------------------------------------
3715 void
3716 outb(port, val)
3717 Bit16u port;
3718 Bit8u val;
3719 {
3720 ASM_START
3721 push bp
3722 mov bp, sp
3723
3724 push ax
3725 push dx
3726 mov dx, 4[bp]
3727 mov al, 6[bp]
3728 out dx, al
3729 pop dx
3730 pop ax
3731
3732 pop bp
3733 ASM_END
3734 }
3735
3736 // --------------------------------------------------------------------------------------------
3737 void
3738 outw(port, val)
3739 Bit16u port;
3740 Bit16u val;
3741 {
3742 ASM_START
3743 push bp
3744 mov bp, sp
3745
3746 push ax
3747 push dx
3748 mov dx, 4[bp]
3749 mov ax, 6[bp]
3750 out dx, ax
3751 pop dx
3752 pop ax
3753
3754 pop bp
3755 ASM_END
3756 }
3757
3758 Bit16u get_SS()
3759 {
3760 ASM_START
3761 mov ax, ss
3762 ASM_END
3763 }
3764
3765 #ifdef DEBUG
3766 void unimplemented()
3767 {
3768 printf("--> Unimplemented\n");
3769 }
3770
3771 void unknown()
3772 {
3773 printf("--> Unknown int10\n");
3774 }
3775 #endif
3776
3777 // --------------------------------------------------------------------------------------------
3778 #if defined(USE_BX_INFO) || defined(DEBUG) || defined(CIRRUS_DEBUG)
3779 void printf(s)
3780 Bit8u *s;
3781 {
3782 Bit8u c, format_char;
3783 Boolean in_format;
3784 unsigned format_width, i;
3785 Bit16u *arg_ptr;
3786 Bit16u arg_seg, arg, digit, nibble, shift_count;
3787
3788 arg_ptr = &s;
3789 arg_seg = get_SS();
3790
3791 in_format = 0;
3792 format_width = 0;
3793
3794 while (c = read_byte(0xc000, s)) {
3795 if ( c == '%' ) {
3796 in_format = 1;
3797 format_width = 0;
3798 }
3799 else if (in_format) {
3800 if ( (c>='0') && (c<='9') ) {
3801 format_width = (format_width * 10) + (c - '0');
3802 }
3803 else if (c == 'x') {
3804 arg_ptr++; // increment to next arg
3805 arg = read_word(arg_seg, arg_ptr);
3806 if (format_width == 0)
3807 format_width = 4;
3808 i = 0;
3809 digit = format_width - 1;
3810 for (i=0; i<format_width; i++) {
3811 nibble = (arg >> (4 * digit)) & 0x000f;
3812 if (nibble <= 9)
3813 outb(0xe9, nibble + '0');
3814 else
3815 outb(0xe9, (nibble - 10) + 'A');
3816 digit--;
3817 }
3818 in_format = 0;
3819 }
3820 //else if (c == 'd') {
3821 // in_format = 0;
3822 // }
3823 }
3824 else {
3825 outb(0xe9, c);
3826 }
3827 s ++;
3828 }
3829 }
3830 #endif
3831
3832 #ifdef VBE
3833 #include "vbe.c"
3834 #endif
3835
3836 #ifdef CIRRUS
3837 #include "clext.c"
3838 #endif
3839
3840 // --------------------------------------------------------------------------------------------
3841
3842 ASM_START
3843 ;; DATA_SEG_DEFS_HERE
3844 ASM_END
3845
3846 ASM_START
3847 .ascii "vgabios ends here"
3848 .byte 0x00
3849 vgabios_end:
3850 .byte 0xCB
3851 ;; BLOCK_STRINGS_BEGIN
3852 ASM_END