]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/fblin4sa1100.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / fblin4sa1100.c
1 /*
2  * Copyright (c) 1999 Martin Jolicoeur <martinj@visuaide.com>
3  *
4  * 4bpp Packed Linear Video Driver for Microwindows
5  * Designed for the arm SA1100 lcd controller with 16 bits access
6  * (little endian)
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 short notmask[4] = { 0x0fff, 0xf0ff, 0xff0f, 0xfff0};
17
18 /* Calc linelen and mmap size, return 0 on fail*/
19 static int
20 linear4_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
29 /* Set pixel at x, y, to pixelval c*/
30 static void
31 linear4_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
32 {
33         ADDR8   addr = psd->addr;
34
35         assert (addr != 0);
36         assert (x >= 0 && x < psd->xres);
37         assert (y >= 0 && y < psd->yres);
38         assert (c < psd->ncolors);
39
40         DRAWON;
41         addr += (x>>1) + y * psd->linelen;
42         if(gr_mode == MWMODE_XOR)
43                 *(ADDR16)addr ^= c << ((3-(x&3))<<2);
44         else
45                 *(ADDR16)addr = (*(ADDR16)addr & notmask[x&3]) | (c << ((3-(x&3))<<2));
46         DRAWOFF;
47 }
48
49 /* Read pixel at x, y*/
50 static MWPIXELVAL
51 linear4_readpixel(PSD psd, MWCOORD x, MWCOORD y)
52 {
53         ADDR8   addr = psd->addr;
54
55         assert (addr != 0);
56         assert (x >= 0 && x < psd->xres);
57         assert (y >= 0 && y < psd->yres);
58
59         return (addr[(x>>1) + y * psd->linelen] >> ((1-(x&1))<<2) ) & 0x0f;
60 }
61
62 /* Draw horizontal line from x1,y to x2,y including final point*/
63 static void
64 linear4_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
65 {
66         ADDR8   addr = psd->addr;
67
68         assert (addr != 0);
69         assert (x1 >= 0 && x1 < psd->xres);
70         assert (x2 >= 0 && x2 < psd->xres);
71         assert (x2 >= x1);
72         assert (y >= 0 && y < psd->yres);
73         assert (c < psd->ncolors);
74
75         DRAWON;
76         addr += (x1>>1) + y * psd->linelen;
77         if(gr_mode == MWMODE_XOR) {
78                 while(x1 <= x2) {
79                         *(ADDR16)addr ^= c << ((3-(x1&3))<<2);
80                         if((++x1 & 1) == 0)
81                                 ++addr;
82                 }
83         } else {
84                 while(x1 <= x2) {
85                         *(ADDR16)addr = (*(ADDR16)addr & notmask[x1&3]) | (c << ((3-(x1&3))<<2));
86                         if((++x1 & 1) == 0)
87                                 ++addr;
88                 }
89         }
90         DRAWOFF;
91 }
92
93 /* Draw a vertical line from x,y1 to x,y2 including final point*/
94 static void
95 linear4_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
96 {
97         ADDR8   addr = psd->addr;
98         int     linelen = psd->linelen;
99
100         assert (addr != 0);
101         assert (x >= 0 && x < psd->xres);
102         assert (y1 >= 0 && y1 < psd->yres);
103         assert (y2 >= 0 && y2 < psd->yres);
104         assert (y2 >= y1);
105         assert (c < psd->ncolors);
106
107         DRAWON;
108         addr += (x>>1) + y1 * linelen;
109         if(gr_mode == MWMODE_XOR)
110                 while(y1++ <= y2) {
111                         *(ADDR16)addr ^= c << ((3-(x&3))<<2);
112                         addr += linelen;
113                 }
114         else
115                 while(y1++ <= y2) {
116                         *(ADDR16)addr = (*(ADDR16)addr & notmask[x&3]) | (c << ((3-(x&3))<<2));
117                         addr += linelen;
118                 }
119         DRAWOFF;
120 }
121
122 /* srccopy bitblt, opcode is currently ignored*/
123 static void
124 linear4_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
125         PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
126 {
127         ADDR8   dst;
128         ADDR8   src;
129         int     i;
130         int     dlinelen = dstpsd->linelen;
131         int     slinelen = srcpsd->linelen;
132
133         assert (dstpsd->addr != 0);
134         assert (dstx >= 0 && dstx < dstpsd->xres);
135         assert (dsty >= 0 && dsty < dstpsd->yres);
136         assert (w > 0);
137         assert (h > 0);
138         assert (srcpsd->addr != 0);
139         assert (srcx >= 0 && srcx < srcpsd->xres);
140         assert (srcy >= 0 && srcy < srcpsd->yres);
141         assert (dstx+w <= dstpsd->xres);
142         assert (dsty+h <= dstpsd->yres);
143         assert (srcx+w <= srcpsd->xres);
144         assert (srcy+h <= srcpsd->yres);
145
146         DRAWON;
147         dst = dstpsd->addr + (dstx>>1) + dsty * dlinelen;
148         src = srcpsd->addr + (srcx>>1) + srcy * slinelen;
149         while(--h >= 0) {
150                 ADDR8   d = dst;
151                 ADDR8   s = src;
152                 MWCOORD dx = dstx;
153                 MWCOORD sx = srcx;
154                 for(i=0; i<w; ++i) {
155                         *(ADDR16)d = (*(ADDR16)d & notmask[dx&3]) |
156                            ((*(ADDR16)s >> ((3-(sx&3))<<2) & 0x000f) << ((3-(dx&3))<<2));
157                         if((++dx & 1) == 0)
158                                 ++d;
159                         if((++sx & 1) == 0)
160                                 ++s;
161                 }
162                 dst += dlinelen;
163                 src += slinelen;
164         }
165         DRAWOFF;
166 }
167
168 SUBDRIVER fblinear4 = {
169         linear4_init,
170         linear4_drawpixel,
171         linear4_readpixel,
172         linear4_drawhorzline,
173         linear4_drawvertline,
174         gen_fillrect,
175         linear4_blit
176 };