xref: /plan9/sys/src/cmd/gs/src/gdevevga.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1993, 1994 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gdevevga.c,v 1.4 2002/02/21 22:24:51 giles Exp $ */
18 /* IBM PC EGA and VGA display drivers */
19 /* All of the real code is in gdevpcfb.c. */
20 #include "memory_.h"
21 #include "gx.h"
22 #include "gserrors.h"
23 #include "gxdevice.h"
24 #include "gdevpcfb.h"
25 
26 /* ------ Internal routines ------ */
27 
28 /* We can't catch signals.... */
29 void
pcfb_set_signals(gx_device * dev)30 pcfb_set_signals(gx_device * dev)
31 {
32 }
33 
34 /* Read the device state */
35 void
pcfb_get_state(pcfb_bios_state * pbs)36 pcfb_get_state(pcfb_bios_state * pbs)
37 {
38     registers regs;
39 
40     regs.h.ah = 0xf;
41     int86(0x10, &regs, &regs);
42     pbs->display_mode = regs.h.al;
43     pbs->text_page = regs.h.bh;
44     regs.h.ah = 0x3;
45     int86(0x10, &regs, &regs);
46     pbs->text_cursor_mode = regs.rshort.cx;
47     regs.rshort.ax = 0x1130;
48     regs.h.bh = 0;
49     int86(0x10, &regs, &regs);
50     switch (regs.rshort.cx) {
51 	case 0x08:
52 	    pbs->text_font = 0x1112;
53 	    break;		/* 8 x 8 */
54 	case 0x10:
55 	    pbs->text_font = 0x1114;
56 	    break;		/* 8 x 16 */
57 	default:
58 	    pbs->text_font = 0x1111;	/* 8 x 14 */
59     }
60     regs.h.ah = 0x8;
61     regs.h.bh = pbs->text_page;
62     int86(0x10, &regs, &regs);
63     pbs->text_attribute = regs.h.ah;
64     pbs->border_color = (regs.h.ah >> 4);
65     regs.rshort.ax = 0x1a00;
66     int86(0x10, &regs, &regs);
67     if (regs.h.al == 0x1a && regs.h.bl == 0x8) {
68 	regs.rshort.ax = 0x1008;
69 	int86(0x10, &regs, &regs);
70 	pbs->border_color = regs.h.bh;
71     }
72     if (pbs->display_mode != 3) {
73 	pbs->display_mode = 3;
74 	pbs->text_font = 0x1112;
75 	pbs->text_cursor_mode = 0x0607;
76 	pbs->text_attribute = 7;
77 	pbs->text_page = 0;
78     }
79 }
80 
81 /* Set the device mode */
82 void
pcfb_set_mode(int mode)83 pcfb_set_mode(int mode)
84 {
85     registers regs;
86 
87     regs.h.ah = 0;
88     regs.h.al = mode;
89     int86(0x10, &regs, &regs);
90 }
91 
92 /* Restore the device state */
93 void
pcfb_set_state(const pcfb_bios_state * pbs)94 pcfb_set_state(const pcfb_bios_state * pbs)
95 {
96     registers regs;
97 
98     pcfb_set_mode(pbs->display_mode);
99     regs.rshort.ax = 0x500;	/* force display of page 0 */
100     int86(0x10, &regs, &regs);
101     regs.rshort.ax = pbs->text_font;
102     regs.h.bl = 0;
103     int86(0x10, &regs, &regs);
104     regs.h.ah = 0x3;
105     regs.h.bh = 0;
106     int86(0x10, &regs, &regs);	/* Get cursor to reset MCGA */
107     regs.h.al = pbs->text_page;
108     regs.h.ah = 0x5;
109     int86(0x10, &regs, &regs);
110     regs.rshort.cx = pbs->text_cursor_mode;
111     regs.h.ah = 0x1;
112     int86(0x10, &regs, &regs);
113     regs.rshort.ax = 0x1001;
114     regs.h.bh = pbs->border_color;
115     int86(0x10, &regs, &regs);
116 }
117