1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevsco.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* 17Jul91 - wb - based on gdevpcfb.c */
16
/* 31Jul91 - Rick Calder rick@rick.att.com - ifdefs for AT&T UNIX 4.0 2.1 */
17
/* 13Sep91 - wb - modify for gs24b2 */
18
/* 9Mar92 - wb - modify for gs24b4 */
19
/* generate SCO Xenix/Unix style memory mapped ioctl output */
28
#include <sys/console.h> /* SCO Xenix and SCO UNIX */
30
#include <sys/machdep.h> /* Xenix needs this also */
33
#include <sys/kd.h> /* AT&T SVR4 */
39
extern char *getenv(const char *);
43
#include <prototypes.h>
46
extern int ioctl(int, int,...);
47
extern int open(const char *, int,...);
50
static int console_fd = -1; /* file descriptor of console */
51
fb_ptr fb_addr; /* address of frame buffer for unix */
52
static int cur_mode = -1; /* current video mode */
54
/* open the console */
55
/* possible files to open:
56
* /dev/console = current system console
57
* /dev/vga = vga monitor
58
* /dev/tty = current terminal
61
static void open_console(void);
70
dev = getenv("GSDEVICE");
71
if (dev == NULL || *dev == '\0')
73
console_fd = open(dev, 0);
74
if (console_fd == -1) {
75
ega_close((gx_device *) NULL);
76
eprintf1("unable to map display '%s'\n", dev);
77
perror("open_console");
83
/* Done with inline assembly in gdevpcfb.h */
85
/* Output to a port */
87
outportb(uint port, byte data)
90
struct port_io_arg pio;
94
pio.args[0].dir = OUT_ON_PORT;
95
pio.args[0].port = port;
96
pio.args[0].data = data;
100
i = ioctl(console_fd, CONSIO, (long)(&pio));
102
ega_close((gx_device *) NULL);
103
eprintf("error setting device register\n");
109
/* Output to 2 consecutive ports */
111
outport2(uint port, byte index, byte data)
114
struct port_io_arg pio;
116
if (console_fd == -1)
118
pio.args[0].dir = OUT_ON_PORT;
119
pio.args[0].port = port;
120
pio.args[0].data = index;
121
pio.args[1].dir = OUT_ON_PORT;
122
pio.args[1].port = port + 1;
123
pio.args[1].data = data;
124
pio.args[2].port = 0;
125
pio.args[3].port = 0;
126
i = ioctl(console_fd, CONSIO, (long)(&pio));
128
ega_close((gx_device *) NULL);
129
eprintf("error setting device register\n");
136
/* interrupt signal handler */
137
/* restore the video mode and exit */
139
ega_int_handler(int sig)
141
ega_close((gx_device *) NULL);
142
eprintf("GS exiting...\n");
147
* FIXME to make this work, the SIGCONT handler must restore the
148
* the video state, including all the registers.
149
* For now, I made the SIGSTOP handler exit just call the SIGINT handler
153
/* user tried to stop us. restore video and stop */
155
ega_tstp_handler(int sig)
158
ega_int_handler(sig);
160
/* Preferable, but sco does not restore the monitor corretly */
161
signal(SIGTSTP, ega_tstp_handler);
162
ega_close((gx_device *) NULL);
163
eprintf("GS stopping...\n");
164
signal(SIGSTOP, SIG_DFL);
165
kill(getpid(), SIGSTOP);
171
/* we were unstopped. reopen video */
173
ega_cont_handler(int sig)
176
ega_int_handler(sig);
178
signal(SIGCONT, ega_cont_handler);
179
ega_set_mode(cur_mode);
184
/* ------ Internal routines ------ */
186
/* Catch signals so we can restore the video mode on exit. */
188
pcfb_set_signals(gx_device * dev)
190
signal(SIGINT, ega_int_handler);
191
signal(SIGTERM, ega_int_handler);
193
signal(SIGTSTP, ega_tstp_handler);
196
signal(SIGCONT, ega_cont_handler);
200
/* Read the device mode */
202
pcfb_get_state(pcfb_bios_state * pbs)
207
mode = ioctl(console_fd, CONS_CURRENT, 0L);
212
ega_close((gx_device *) NULL);
213
eprintf("unable to get current console mode\n");
214
perror("pcfb_get_state");
219
(mode == M_ENH_CG640 || mode == M_CG640x350 ? 0x10 :
221
mode == M_VGA12 ? 0x12 :
226
/* Set the device mode */
228
pcfb_set_mode(int mode)
238
else if (mode == 0x12)
241
else if (mode == 0x03) {
244
mode1 = SW_ENHC80x25;
249
eprintf1("can not set to video mode %d\n", mode);
252
i = ioctl(console_fd, mode, 0L);
253
if (i == -1 && mode1 != -1)
254
i = ioctl(console_fd, mode1, 0L);
256
ega_close((gx_device *) NULL);
257
eprintf("unable to set console mode\n");
258
perror("pcfb_set_mode");
262
if (ioctl(console_fd, VGA_IOPRIVL, 1) == -1) {
263
ega_close((gx_device *) NULL);
264
eprintf("unable to get I/O privilege\n");
265
perror("pcfb_set_mode");
269
i = ioctl(console_fd, MAPCONS, 0L);
271
ega_close((gx_device *) NULL);
272
eprintf("unable to map console adaptor's display memory\n");
273
perror("pcfb_set_mode");
276
fb_addr = (fb_ptr) (i);
279
/* Restore the device state */
281
pcfb_set_state(const pcfb_bios_state * pbs)
283
pcfb_set_mode(pbs->display_mode);