]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/fblin2.c
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / fblin2.c
1 /*
2  * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3  *
4  * 2bpp Packed Linear Video Driver for Microwindows
5  *      This driver is written for the Vr41xx Palm PC machines
6  *      The screen is 320x240x4
7  *
8  *      In this driver, psd->linelen is line byte length, not line pixel length
9  */
10 /*#define NDEBUG*/
11 #include <assert.h>
12 #include <string.h>
13 #include "device.h"
14 #include "fb.h"
15
16 static unsigned char notmask[4] = { 0x3f, 0xcf, 0xf3, 0xfc};
17
18 /* Calc linelen and mmap size, return 0 on fail*/
19 static int
20 linear2_init(PSD psd)
21 {
22         if (!psd->size)
23                 psd->size = psd->yres * psd->linelen;
24         /* linelen in bytes for bpp 1, 2, 4, 8 so no change*/
25         return 1;
26 }
27
28 /* Set pixel at x, y, to pixelval c*/
29 static void
30 linear2_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
31 {
32         ADDR8   addr = psd->addr;
33
34         assert (addr != 0);
35         assert (x >= 0 && x < psd->xres);
36         assert (y >= 0 && y < psd->yres);
37         assert (c < psd->ncolors);
38
39         DRAWON;
40         addr += (x>>2) + y * psd->linelen;
41         if(gr_mode == MWMODE_XOR)
42                 *addr ^= c << ((3-(x&3))<<1);
43         else
44                 *addr = (*addr & notmask[x&3]) | (c << ((3-(x&3))<<1));
45         DRAWOFF;
46 }
47
48 /* Read pixel at x, y*/
49 static MWPIXELVAL
50 linear2_readpixel(PSD psd, MWCOORD x, MWCOORD y)
51 {
52         ADDR8   addr = psd->addr;
53
54         assert (addr != 0);
55         assert (x >= 0 && x < psd->xres);
56         assert (y >= 0 && y < psd->yres);
57
58         return (addr[(x>>2) + y * psd->linelen] >> ((3-(x&3))<<1) ) & 0x03;
59 }
60
61 /* Draw horizontal line from x1,y to x2,y including final point*/
62 static void
63 linear2_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
64 {
65         ADDR8   addr = psd->addr;
66
67         assert (addr != 0);
68         assert (x1 >= 0 && x1 < psd->xres);
69         assert (x2 >= 0 && x2 < psd->xres);
70         assert (x2 >= x1);
71         assert (y >= 0 && y < psd->yres);
72         assert (c < psd->ncolors);
73
74         DRAWON;
75         addr += (x1>>2) + y * psd->linelen;
76         if(gr_mode == MWMODE_XOR) {
77                 while(x1 <= x2) {
78                         *addr ^= c << ((3-(x1&3))<<1);
79                         if((++x1 & 3) == 0)
80                                 ++addr;
81                 }
82         } else {
83                 while(x1 <= x2) {
84                         *addr = (*addr & notmask[x1&3]) | (c << ((3-(x1&3))<<1));
85                         if((++x1 & 3) == 0)
86                                 ++addr;
87                 }
88         }
89         DRAWOFF;
90 }
91
92 /* Draw a vertical line from x,y1 to x,y2 including final point*/
93 static void
94 linear2_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
95 {
96         ADDR8   addr = psd->addr;
97         int     linelen = psd->linelen;
98
99         assert (addr != 0);
100         assert (x >= 0 && x < psd->xres);
101         assert (y1 >= 0 && y1 < psd->yres);
102         assert (y2 >= 0 && y2 < psd->yres);
103         assert (y2 >= y1);
104         assert (c < psd->ncolors);
105
106         DRAWON;
107         addr += (x>>2) + y1 * linelen;
108         if(gr_mode == MWMODE_XOR)
109                 while(y1++ <= y2) {
110                         *addr ^= c << ((3-(x&3))<<1);
111                         addr += linelen;
112                 }
113         else
114                 while(y1++ <= y2) {
115                         *addr = (*addr & notmask[x&3]) | (c << ((3-(x&3))<<1));
116                         addr += linelen;
117                 }
118         DRAWOFF;
119 }
120
121 /* srccopy bitblt, opcode is currently ignored*/
122 static void
123 linear2_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
124         PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
125 {
126         ADDR8   dst;
127         ADDR8   src;
128         int     i;
129         int     dlinelen = dstpsd->linelen;
130         int     slinelen = srcpsd->linelen;
131
132         assert (dstpsd->addr != 0);
133         assert (dstx >= 0 && dstx < dstpsd->xres);
134         assert (dsty >= 0 && dsty < dstpsd->yres);
135         assert (w > 0);
136         assert (h > 0);
137         assert (srcpsd->addr != 0);
138         assert (srcx >= 0 && srcx < srcpsd->xres);
139         assert (srcy >= 0 && srcy < srcpsd->yres);
140         assert (dstx+w <= dstpsd->xres);
141         assert (dsty+h <= dstpsd->yres);
142         assert (srcx+w <= srcpsd->xres);
143         assert (srcy+h <= srcpsd->yres);
144
145         DRAWON;
146         dst = dstpsd->addr + (dstx>>2) + dsty * dlinelen;
147         src = srcpsd->addr + (srcx>>2) + srcy * slinelen;
148         while(--h >= 0) {
149                 ADDR8   d = dst;
150                 ADDR8   s = src;
151                 MWCOORD dx = dstx;
152                 MWCOORD sx = srcx;
153                 for(i=0; i<w; ++i) {
154                         *d = (*d & notmask[dx&3]) |
155                            ((*s >> ((3-(sx&3))<<1) & 0x03) << ((3-(dx&3))<<1));
156                         if((++dx & 3) == 0)
157                                 ++d;
158                         if((++sx & 3) == 0)
159                                 ++s;
160                 }
161                 dst += dlinelen;
162                 src += slinelen;
163         }
164         DRAWOFF;
165 }
166
167 SUBDRIVER fblinear2 = {
168         linear2_init,
169         linear2_drawpixel,
170         linear2_readpixel,
171         linear2_drawhorzline,
172         linear2_drawvertline,
173         gen_fillrect,
174         linear2_blit
175 };