1 /* Copyright (C) 1993, 1994 artofcode LLC. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2 of the License, or (at your
6 option) any later version.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16
17 */
18
19 /*$Id: gdevevga.c,v 1.2.6.1.2.1 2003/01/17 00:49:00 giles Exp $ */
20 /* IBM PC EGA and VGA display drivers */
21 /* All of the real code is in gdevpcfb.c. */
22 #include "memory_.h"
23 #include "gx.h"
24 #include "gserrors.h"
25 #include "gxdevice.h"
26 #include "gdevpcfb.h"
27
28 /* ------ Internal routines ------ */
29
30 /* We can't catch signals.... */
31 void
pcfb_set_signals(gx_device * dev)32 pcfb_set_signals(gx_device * dev)
33 {
34 }
35
36 /* Read the device state */
37 void
pcfb_get_state(pcfb_bios_state * pbs)38 pcfb_get_state(pcfb_bios_state * pbs)
39 {
40 registers regs;
41
42 regs.h.ah = 0xf;
43 int86(0x10, ®s, ®s);
44 pbs->display_mode = regs.h.al;
45 pbs->text_page = regs.h.bh;
46 regs.h.ah = 0x3;
47 int86(0x10, ®s, ®s);
48 pbs->text_cursor_mode = regs.rshort.cx;
49 regs.rshort.ax = 0x1130;
50 regs.h.bh = 0;
51 int86(0x10, ®s, ®s);
52 switch (regs.rshort.cx) {
53 case 0x08:
54 pbs->text_font = 0x1112;
55 break; /* 8 x 8 */
56 case 0x10:
57 pbs->text_font = 0x1114;
58 break; /* 8 x 16 */
59 default:
60 pbs->text_font = 0x1111; /* 8 x 14 */
61 }
62 regs.h.ah = 0x8;
63 regs.h.bh = pbs->text_page;
64 int86(0x10, ®s, ®s);
65 pbs->text_attribute = regs.h.ah;
66 pbs->border_color = (regs.h.ah >> 4);
67 regs.rshort.ax = 0x1a00;
68 int86(0x10, ®s, ®s);
69 if (regs.h.al == 0x1a && regs.h.bl == 0x8) {
70 regs.rshort.ax = 0x1008;
71 int86(0x10, ®s, ®s);
72 pbs->border_color = regs.h.bh;
73 }
74 if (pbs->display_mode != 3) {
75 pbs->display_mode = 3;
76 pbs->text_font = 0x1112;
77 pbs->text_cursor_mode = 0x0607;
78 pbs->text_attribute = 7;
79 pbs->text_page = 0;
80 }
81 }
82
83 /* Set the device mode */
84 void
pcfb_set_mode(int mode)85 pcfb_set_mode(int mode)
86 {
87 registers regs;
88
89 regs.h.ah = 0;
90 regs.h.al = mode;
91 int86(0x10, ®s, ®s);
92 }
93
94 /* Restore the device state */
95 void
pcfb_set_state(const pcfb_bios_state * pbs)96 pcfb_set_state(const pcfb_bios_state * pbs)
97 {
98 registers regs;
99
100 pcfb_set_mode(pbs->display_mode);
101 regs.rshort.ax = 0x500; /* force display of page 0 */
102 int86(0x10, ®s, ®s);
103 regs.rshort.ax = pbs->text_font;
104 regs.h.bl = 0;
105 int86(0x10, ®s, ®s);
106 regs.h.ah = 0x3;
107 regs.h.bh = 0;
108 int86(0x10, ®s, ®s); /* Get cursor to reset MCGA */
109 regs.h.al = pbs->text_page;
110 regs.h.ah = 0x5;
111 int86(0x10, ®s, ®s);
112 regs.rshort.cx = pbs->text_cursor_mode;
113 regs.h.ah = 0x1;
114 int86(0x10, ®s, ®s);
115 regs.rshort.ax = 0x1001;
116 regs.h.bh = pbs->border_color;
117 int86(0x10, ®s, ®s);
118 }
119