1 /* Copyright (C) 1989, 1995 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: gdevpcfb.h,v 1.5 2002/06/16 07:25:26 lpd Exp $ */
18 /* IBM PC frame buffer definitions */
19
20 #ifndef gdevpcfb_INCLUDED
21 # define gdevpcfb_INCLUDED
22
23 #ifdef __MSDOS__
24 # include "dos_.h"
25 typedef union REGS registers;
26
27 #endif
28
29 /* For testing, the 16-color display may be defined as a monochrome, */
30 /* 8-color, or 16-color device. */
31 #define ega_bits_of_color 2 /* 0, 1, or 2 */
32 #define rgb_max ega_bits_of_color
33
34 /* Define the short (integer) version of "transparent" color. */
35 /* ****** Depends on gx_no_color_index being all 1's. ***** */
36 #define no_color ((int)gx_no_color_index)
37
38 /* Procedures */
39
40 /* See gxdevice.h for the definitions of the procedures. */
41
42 dev_proc_open_device(ega_open);
43 dev_proc_close_device(ega_close);
44 dev_proc_fill_rectangle(ega_fill_rectangle);
45 dev_proc_tile_rectangle(ega_tile_rectangle);
46 dev_proc_copy_mono(ega_copy_mono);
47 dev_proc_copy_color(ega_copy_color);
48 dev_proc_get_bits(ega_get_bits);
49
50 /* Structure for saving state of BIOS variables. */
51 typedef struct pcfb_bios_state_s {
52 int display_mode; /* must be first, see pcfb_save_state */
53 /* in gdevpcfb.c */
54 byte text_page;
55 uint text_cursor_mode;
56 uint text_font;
57 byte text_attribute;
58 byte border_color;
59 } pcfb_bios_state;
60
61 /* Procedures used by gdevpcfb.c */
62 void pcfb_set_signals(gx_device *);
63 void pcfb_get_state(pcfb_bios_state *);
64 void pcfb_set_mode(int);
65 void pcfb_set_state(const pcfb_bios_state *);
66
67 /* Types for frame buffer pointers. */
68 typedef byte *fb_ptr;
69 typedef volatile byte *volatile_fb_ptr;
70
71 /* Define the nominal page height in inches. */
72 #ifdef A4
73 # define PAGE_HEIGHT_INCHES 11.69
74 #else
75 # define PAGE_HEIGHT_INCHES 11.0
76 #endif
77
78 /* The device descriptor */
79 typedef struct gx_device_ega_s gx_device_ega;
80 struct gx_device_ega_s {
81 gx_device_common;
82 int raster; /* frame buffer bytes per line */
83 int fb_seg_mult; /* multiplier for segment part */
84 /* of frame buffer pointer */
85 int fb_byte_mult; /* multiplier for word part ditto */
86 #define mk_fb_ptr(x, y)\
87 (fb_dev->fb_byte_mult == 0 ?\
88 (fb_ptr)MK_PTR(regen + (y) * (fb_dev->fb_seg_mult), (x) >> 3) :\
89 (fb_ptr)MK_PTR(regen + ((y) >> 4) * (fb_dev->fb_seg_mult),\
90 (((y) & 15) * fb_dev->fb_byte_mult) + ((x) >> 3)))
91 int video_mode;
92 };
93
94 /* Macro for creating instances */
95 /* The initial parameters map an appropriate fraction of */
96 /* the screen to a full-page coordinate space. */
97 /* This may or may not be what is desired! */
98 #define ega_device(dev_name, procs, fb_raster, screen_height, aspect_ratio, video_mode)\
99 { std_device_dci_body(gx_device_ega, &procs, dev_name,\
100 fb_raster * 8, screen_height,\
101 (screen_height * (aspect_ratio)) / PAGE_HEIGHT_INCHES, /* x dpi */\
102 screen_height / PAGE_HEIGHT_INCHES, /* y dpi */\
103 (rgb_max ? 3 : 1), /* num_components */\
104 4, /* depth */\
105 (rgb_max ? rgb_max : 1), /* max_gray */\
106 rgb_max,\
107 (rgb_max ? rgb_max + 1 : 2), /* dither_grays */\
108 (rgb_max ? rgb_max + 1 : 0) /* dither_colors */\
109 ),\
110 { 0 }, /* std_procs */\
111 fb_raster,\
112 (fb_raster & 15 ? fb_raster : fb_raster >> 4),\
113 (fb_raster & 15 ? fb_raster : 0),\
114 video_mode\
115 }
116
117 /* Define the device port and register numbers, and the regen map base */
118 #define seq_addr 0x3c4
119 #define s_map 2
120 #define set_s_map(mask) outport2(seq_addr, s_map, mask)
121 #define graph_addr 0x3ce
122 #define g_const 0 /* set/reset */
123 #define set_g_const(color) outport2(graph_addr, g_const, color)
124 #define g_const_map 1 /* enable set/reset */
125 #define set_g_const_map(map) outport2(graph_addr, g_const_map, map)
126 #define g_function 3
127 # define gf_WRITE 0
128 # define gf_AND 8
129 # define gf_OR 0x10
130 # define gf_XOR 0x18
131 #define set_g_function(func) outport2(graph_addr, g_function, func)
132 #define g_read_plane 4
133 #define set_g_read_plane(plane) outport2(graph_addr, g_read_plane, plane)
134 #define g_mode 5
135 # define gm_DATA 0
136 # define gm_FILL 2
137 #define set_g_mode(mode) outport2(graph_addr, g_mode, mode)
138 #define g_mask 8
139 #define set_g_mask(mask) outport2(graph_addr, g_mask, mask)
140 #define select_g_mask() outportb(graph_addr, g_mask)
141 #define out_g_mask(mask) outportb(graph_addr+1, mask)
142 #define regen 0xa000
143
144 /* Define access to the frame buffer and the video registers */
145 /* according to whether we are on a DOS system or a Unix system. */
146
147 #if defined(M_UNIX) || defined(M_XENIX) || defined(UNIX) || defined(SYSV) || defined(__linux__)
148
149 /* SCO Unix/Xenix, AT&T SVR4, or Linux. */
150
151 #undef outportb
152
153 #if defined(__GNUC__)
154 /* Inline assembly version for gcc */
155 /* Under SCO, requires installing the gnu assembler as "as" */
156 static inline void
outportb(int port,int data)157 outportb(int port, int data)
158 {
159 __asm__ volatile ("outb %0,%1"::
160 "a" ((unsigned char)data),
161 "d" ((unsigned short)port));
162 }
163 static inline void
outport2(int port,int index,int data)164 outport2(int port, int index, int data)
165 {
166 __asm__ volatile ("movb %0,%%ah; movb %1,%%al; outw %%ax,%2"::
167 "qmi" ((unsigned char)data),
168 "qmi" ((unsigned char)index),
169 "d" ((unsigned short)port):
170 "eax");
171 }
172 #else
173 void outportb(uint, byte);
174 void outport2(uint, byte, byte);
175
176 #endif
177
178 /* Redefine mk_fb_ptr -- no segmented addressing. */
179
180 #undef mk_fb_ptr
181 extern fb_ptr fb_addr;
182
183 #define mk_fb_ptr(x, y) (fb_addr + (y) * (fb_dev->raster) + ((x) >> 3))
184
185 #else
186
187 /* MS-DOS */
188
189 /* outportb is defined in dos_.h */
190 #define outport2(port, index, data)\
191 (outportb(port, index), outportb((port)+1, data))
192
193 #endif
194
195 /* Fetch and discard a byte. Prevent the compiler from */
196 /* optimizing this away. */
197 static unsigned char byte_discard_;
198
199 #define byte_discard(expr) byte_discard_ = (expr)
200
201 #endif /* gdevpcfb_INCLUDED */
202