]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/fblin4sh3.c
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / fblin4sh3.c
1 /*
2  * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3  *
4  * 4bpp Packed Linear SH3 Video Driver for Microwindows
5  *
6  *      In this driver, psd->linelen is line byte length, not line pixel length
7  */
8 /* 
9         This is modified for SH3 LittleEndian system.
10         4bpp linear video driver, 
11         Frame buffer sturcture and LCD Pixel is 
12
13         32                 16 15                0
14         -----------------------------------------    
15         | P0 | P1 | P2 | P3 | P4 | P5 | P6 | P7 |
16         -----------------------------------------    
17
18  */
19
20 /*#define NDEBUG*/
21 #include <assert.h>
22 #include <string.h>
23 #include "device.h"
24 #include "fb.h"
25
26 static unsigned char notmask[2] = { 0x0f, 0xf0}; 
27
28 /* Calc linelen and mmap size, return 0 on fail*/
29 static int
30 linear4_init(PSD psd)
31 {
32         if (!psd->size)
33                 psd->size = psd->yres * psd->linelen;
34         /* linelen in bytes for bpp 1, 2, 4, 8 so no change*/
35         return 1;
36 }
37
38 /* Set pixel at x, y, to pixelval c*/
39 static void
40 linear4_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
41 {
42         ADDR8   addr = psd->addr;
43
44         assert (addr != 0);
45         assert (x >= 0 && x < psd->xres);
46         assert (y >= 0 && y < psd->yres);
47         assert (c < psd->ncolors);
48
49         DRAWON;
50         addr += ((x>>1)^3) + y * psd->linelen;
51         if(gr_mode == MWMODE_XOR)
52                 *addr ^= c << ((1-(x&1))<<2);
53         else
54                 *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
55         DRAWOFF;
56 }
57
58 /* Read pixel at x, y*/
59 static MWPIXELVAL
60 linear4_readpixel(PSD psd, MWCOORD x, MWCOORD y)
61 {
62         ADDR8   addr = psd->addr;
63
64         assert (addr != 0);
65         assert (x >= 0 && x < psd->xres);
66         assert (y >= 0 && y < psd->yres);
67
68         return (addr[((x>>1)^3) + y * psd->linelen] >> ((1-(x&1))<<2) ) & 0x0f;
69 }
70
71 /* Draw horizontal line from x1,y to x2,y including final point*/
72 static void
73 linear4_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
74 {
75         ADDR8   addr = psd->addr;
76
77         assert (addr != 0);
78         assert (x1 >= 0 && x1 < psd->xres);
79         assert (x2 >= 0 && x2 < psd->xres);
80         assert (x2 >= x1);
81         assert (y >= 0 && y < psd->yres);
82         assert (c < psd->ncolors);
83
84         DRAWON;
85         addr += ( (x1>>1)^3 ) + y * psd->linelen;
86         if(gr_mode == MWMODE_XOR) {
87                 while(x1 <= x2) {
88                         *addr ^= c << ((1-(x1&1))<<2);
89                         if((++x1 & 1) == 0) {
90                         /*      ++addr;    */
91                         addr = psd->addr + ( (x1>>1)^3 ) + y * psd->linelen;
92                         }
93                 }
94         } else {
95                 while(x1 <= x2) {
96                         *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
97                         if((++x1 & 1) == 0) {
98                         /*      ++addr;    */
99                         addr = psd->addr + ( (x1>>1)^3 ) + y * psd->linelen;
100                         }
101                 }
102         }
103         DRAWOFF;
104 }
105
106 /* Draw a vertical line from x,y1 to x,y2 including final point*/
107 static void
108 linear4_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
109 {
110         ADDR8   addr = psd->addr;
111         int     linelen = psd->linelen;
112
113         assert (addr != 0);
114         assert (x >= 0 && x < psd->xres);
115         assert (y1 >= 0 && y1 < psd->yres);
116         assert (y2 >= 0 && y2 < psd->yres);
117         assert (y2 >= y1);
118         assert (c < psd->ncolors);
119
120         DRAWON;
121         addr += ( (x>>1)^3 ) + y1 * linelen;
122         if(gr_mode == MWMODE_XOR)
123                 while(y1++ <= y2) {
124                         *addr ^= c << ((1-(x&1))<<2);
125                         addr += linelen;
126                 }
127         else
128                 while(y1++ <= y2) {
129                         *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
130                         addr += linelen;
131                 }
132         DRAWOFF;
133 }
134
135 /* srccopy bitblt, opcode is currently ignored*/
136 static void
137 linear4_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
138         PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
139 {
140         ADDR8   dst;
141         ADDR8   src;
142         int     i;
143         int     dlinelen = dstpsd->linelen;
144         int     slinelen = srcpsd->linelen;
145
146         assert (dstpsd->addr != 0);
147         assert (dstx >= 0 && dstx < dstpsd->xres);
148         assert (dsty >= 0 && dsty < dstpsd->yres);
149         assert (w > 0);
150         assert (h > 0);
151         assert (srcpsd->addr != 0);
152         assert (srcx >= 0 && srcx < srcpsd->xres);
153         assert (srcy >= 0 && srcy < srcpsd->yres);
154         assert (dstx+w <= dstpsd->xres);
155         assert (dsty+h <= dstpsd->yres);
156         assert (srcx+w <= srcpsd->xres);
157         assert (srcy+h <= srcpsd->yres);
158
159         DRAWON;
160 #ifdef SH3_LITTLE_ENDIAN   /* not used */
161         dst = dstpsd->addr + ( (dstx>>1)^3 ) + dsty * dlinelen;
162         src = srcpsd->addr + ( (srcx>>1)^3 ) + srcy * slinelen;
163         while(--h >= 0) {
164                 ADDR8   d = dst;
165                 ADDR8   s = src;
166                 MWCOORD dx = dstx;
167                 MWCOORD sx = srcx;
168                 for(i=0; i<w; ++i) {
169                         *d = (*d & notmask[dx&1]) |
170                            ((*s >> ((1-(sx&1))<<2) & 0x0f) << ((1-(dx&1))<<2));
171                         if((++dx & 1) == 0)
172                                 ++d;
173                         if((++sx & 1) == 0)
174                                 ++s;
175                 }
176                 dst += dlinelen;
177                 src += slinelen;
178         }
179 #else
180         dst = dstpsd->addr + dsty * dlinelen;
181         src = srcpsd->addr + srcy * slinelen;
182         while(--h >= 0) {
183                 ADDR8   d = dst + ( (dstx>>1)^3 );
184                 ADDR8   s = src + ( (srcx>>1)^3 );
185                 MWCOORD dx = dstx;
186                 MWCOORD sx = srcx;
187                 for(i=0; i<w; ++i) {
188                         *d = (*d & notmask[dx&1]) |
189                            ((*s >> ((1-(sx&1))<<2) & 0x0f) << ((1-(dx&1))<<2));
190                         if((++dx & 1) == 0)
191                                 d = dst + ( (dx >> 1)^3 );
192                         if((++sx & 1) == 0)
193                                 s = src + ( (sx >> 1)^3 );
194                 }
195                 dst += dlinelen;
196                 src += slinelen;
197         }
198 #endif
199         DRAWOFF;
200 }
201
202 SUBDRIVER fblinear4 = {
203         linear4_init,
204         linear4_drawpixel,
205         linear4_readpixel,
206         linear4_drawhorzline,
207         linear4_drawvertline,
208         gen_fillrect,
209         linear4_blit
210 };