1
/* Copyright (C) 2001-2012 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,
8
modified or distributed except as expressly authorized under the terms
9
of the license contained in the file LICENSE in this distribution.
11
Refer to licensing information at http://www.artifex.com or contact
12
Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13
CA 94903, U.S.A., +1(415)492-9861, for further information.
18
* Private Eye display driver
20
* Hacked by Fran Taylor, Reflection Technology Inc.
27
char *getenv(char *name);
29
typedef struct gx_device_pe_s {
34
#define pedev ((gx_device_pe *)dev)
45
#define DEFAULT_ADDRESS ((byte *) 0xb8000000)
46
#define DEFAULT_REGISTERS 0x3d0
48
dev_proc_open_device(pe_open);
49
dev_proc_close_device(pe_close);
50
dev_proc_fill_rectangle(pe_fill_rectangle);
51
dev_proc_copy_mono(pe_copy_mono);
53
static gx_device_procs pe_procs =
55
NULL, /* get_initial_matrix */
56
NULL, /* sync_output */
57
NULL, /* output_page */
59
NULL, /* map_rgb_color */
60
NULL, /* map_color_rgb */
62
NULL, /* tile_rectangle */
67
gx_device_pe far_data gs_pe_device =
68
{ std_device_std_body(gx_device_pe, &pe_procs, "pe",
69
XSIZE, YSIZE, XPPI, YPPI),
70
{ 0 }, /* std_procs */
71
DEFAULT_ADDRESS, DEFAULT_REGISTERS
74
static regval peinit[] = {{0x04, 0x1e}, {0x05, 0x00},
75
{0x04, 0x0c}, {0x05, 0x21},
76
{0x04, 0x0d}, {0x05, 0x98},
77
{0x08, 0x00}, {0x08, 0x1e},
78
{0x04, 0x1e}, {0x05, 0x01}};
80
static regval pedone[] = {{0x04, 0x1e}, {0x05, 0x10},
81
{0x04, 0x0a}, {0x05, 0x00},
82
{0x04, 0x0b}, {0x05, 0x07},
83
{0x04, 0x0c}, {0x05, 0x00},
84
{0x04, 0x0d}, {0x05, 0x00},
85
{0x04, 0x0e}, {0x05, 0x00},
86
{0x04, 0x0f}, {0x05, 0x00},
87
{0x08, 0x00}, {0x08, 0x29}};
89
int pe_open(gx_device *dev)
94
if ((str = getenv("PEFBADDR")) != 0)
96
if (!sscanf(str, "%lx", &(pedev->fbaddr)))
99
"Private Eye: PEFBADDR environment string format error\n");
104
if ((str = getenv("PEREGS")) != 0)
106
if (!sscanf(str, "%x", &(pedev->regs)))
108
emprintf(dev->memory,
109
"Private Eye: PEREGS environment string format error\n");
114
for (i = 0; i < 10; i++)
115
outportb(pedev->regs + peinit[i].reg, peinit[i].val);
120
int pe_close(gx_device *dev)
124
/* restore the screen */
125
for (i = 0; i < 16; i++)
126
outportb(pedev->regs + pedone[i].reg, pedone[i].val);
128
/* clear the frame buffer */
129
memset(pedev->fbaddr, 0, 4000);
134
int pe_fill_rectangle(gx_device *dev, int x1, int y1, int w, int h,
135
gx_color_index color)
143
if ((w <= 0) || (h <= 0) || (x1 > XSIZE) || (y1 > YSIZE))
151
if ((x2 < 0) || (y2 < 0))
157
if (x2 > XSIZE-1) x2 = XSIZE-1;
159
if (y2 > YSIZE-1) y2 = YSIZE-1;
163
xlen = (x2 >> 3) - (x1 >> 3) - 1;
164
led = 0xff >> (x1 & 7);
165
red = 0xff << (7 - (x2 & 7));
167
ptr = pedev->fbaddr + (y1 * BPL) + (x1 >> 3);
171
/* here to set pixels */
175
/* special for rectangles that fit in a byte */
178
for(; h >= 0; h--, ptr += BPL)
185
for(; h >= 0; h--, ptr += BPL)
186
{ register int x = xlen;
187
register byte *p = ptr;
189
while ( x-- ) *p++ = 0xff;
194
/* here to clear pixels */
201
/* special for rectangles that fit in a byte */
204
for(; h >= 0; h--, ptr += BPL)
211
for(; h >= 0; h--, ptr += BPL)
212
{ register int x = xlen;
213
register byte *p = ptr;
215
while ( x-- ) *p++ = 0x00;
221
int pe_copy_mono(gx_device *dev,
222
const byte *base, int sourcex, int raster, gx_bitmap_id id,
223
int x, int y, int w, int h,
224
gx_color_index zero, gx_color_index one)
229
int invert, zmask, omask;
233
#define izero (int)zero
234
#define ione (int)one
236
if ( ione == izero ) /* vacuous case */
237
return pe_fill_rectangle(dev, x, y, w, h, zero);
241
if ((x > XSIZE) || (y > YSIZE) || ((x + w) < 0) || ((y + h) < 0))
245
dest = pedev->fbaddr + (y * BPL) + offset;
246
line = base + (sourcex >> 3);
247
sleft = 8 - (sourcex & 7);
249
mask = 0xff >> (8 - dleft);
253
rmask = 0xff00 >> ((w - dleft) & 7);
255
/* Macros for writing partial bytes. */
256
/* bits has already been inverted by xor'ing with invert. */
258
#define write_byte_masked(ptr, bits, mask)\
259
*ptr = ((bits | ~mask | zmask) & *ptr | (bits & mask & omask))
261
#define write_byte(ptr, bits)\
262
*ptr = ((bits | zmask) & *ptr | (bits & omask))
264
/* if ( dev->invert )
266
if ( izero != (int)gx_no_color_index ) zero ^= 1;
267
if ( ione != (int)gx_no_color_index ) one ^= 1;
269
invert = (izero == 1 || ione == 0 ? -1 : 0);
270
zmask = (izero == 0 || ione == 0 ? 0 : -1);
271
omask = (izero == 1 || ione == 1 ? -1 : 0);
276
if (sleft == dleft) /* optimize the aligned case */
281
register const byte *bptr = line;
283
register byte *optr = dest;
284
register int bits = *bptr ^ invert; /* first partial byte */
286
write_byte_masked(optr, bits, mask);
290
while ((count -= 8) >= 0)
292
bits = *++bptr ^ invert;
294
write_byte(optr, bits);
301
bits = *++bptr ^ invert;
303
write_byte_masked(optr, bits, rmask);
311
int skew = (sleft - dleft) & 7;
312
int cskew = 8 - skew;
316
const byte *bptr = line;
321
/* Do the first partial byte */
325
bits = *bptr >> skew;
327
else /* ( sleft < dleft ) */
329
bits = *bptr++ << cskew;
331
bits += *bptr >> skew;
334
write_byte_masked(optr, bits, mask);
342
bits = *bptr++ << cskew;
343
bits += *bptr >> skew;
345
write_byte(optr, bits);
354
bits = *bptr++ << cskew;
356
bits += *bptr >> skew;
358
write_byte_masked(optr, bits, rmask);