OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [drivers/] [fblin1.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.